Exemplo n.º 1
0
cppbugs::MCMCObject* createMCMC(SEXP x_, vpArmaMapT& armaMap) {
    SEXP distributed_sexp;
    distributed_sexp = Rf_getAttrib(x_,Rf_install("distributed"));
    SEXP class_sexp = Rf_getAttrib(x_,R_ClassSymbol);
    if(class_sexp == R_NilValue || TYPEOF(class_sexp) != STRSXP || CHAR(STRING_ELT(class_sexp,0))==NULL || strcmp(CHAR(STRING_ELT(class_sexp,0)),"mcmc.object"))  {
        throw std::logic_error("ERROR: class attribute not defined or not equal to 'mcmc.object'.");
    }

    if(distributed_sexp == R_NilValue) {
        throw std::logic_error("ERROR: 'distributed' attribute not defined. Is this an mcmc.object?");
    }

    if(armaMap.count(rawAddress(x_))==0) {
        throw std::logic_error("ArmaContext not found (object should be mapped before call to createMCMC).");
    }

    distT distributed = matchDistibution(std::string(CHAR(STRING_ELT(distributed_sexp,0))));
    cppbugs::MCMCObject* ans;

    switch(distributed) {
    // deterministic types
    case deterministicT:
        ans = createDeterministic(x_,armaMap);
        break;
    case linearDeterministicT:
        ans = createLinearDeterministic(x_,armaMap);
        break;
    case linearGroupedDeterministicT:
        ans = createLinearGroupedDeterministic(x_,armaMap);
        break;
    case logisticDeterministicT:
        ans = createLogisticDeterministic(x_,armaMap);
        break;
    // continuous types
    case normalDistT:
        ans = createNormal(x_,armaMap);
        break;
    case uniformDistT:
        ans = createUniform(x_,armaMap);
        break;
    case gammaDistT:
        ans = createGamma(x_,armaMap);
        break;
    case betaDistT:
        ans = createBeta(x_,armaMap);
        break;
    // discrete types
    case bernoulliDistT:
        ans = createBernoulli(x_,armaMap);
        break;
    case binomialDistT:
        ans = createBinomial(x_,armaMap);
        break;
    default:
        // not implemented
        ans = NULL;
        throw std::logic_error("ERROR: distribution not supported yet.");
    }
    return ans;
}
Exemplo n.º 2
0
	void ShaderObject::doFillVariables()
	{
		for ( auto & uniform : m_source.getUniforms() )
		{
			auto uniformType = doGetUniformType( uniform.second.m_type );

			if ( uniformType != UniformType::eCount )
			{
				createUniform( doGetUniformType( uniform.second.m_type ), uniform.first )->getBaseUniform().setChanged( false );
			}
		}

		for ( auto & sampler : m_source.getSamplers() )
		{
			auto samplerUniform = createUniform< UniformType::eSampler >( sampler.first, sampler.second.m_count );
			std::vector< int > values;
			values.resize( sampler.second.m_count );
			std::iota( values.begin(), values.end(), sampler.second.m_binding );
			samplerUniform->setValues( values );
		}
	}