当前位置: 首页>>代码示例>>C++>>正文


C++ ADFun::Domain方法代码示例

本文整理汇总了C++中ADFun::Domain方法的典型用法代码示例。如果您正苦于以下问题:C++ ADFun::Domain方法的具体用法?C++ ADFun::Domain怎么用?C++ ADFun::Domain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ADFun的用法示例。


在下文中一共展示了ADFun::Domain方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: JacobianRev

void JacobianRev(ADFun<Base> &f, const Vector &x, Vector &jac)
{	size_t i;
	size_t j;

	size_t n = f.Domain();
	size_t m = f.Range();

	CPPAD_ASSERT_UNKNOWN( size_t(x.size())   == f.Domain() );
	CPPAD_ASSERT_UNKNOWN( size_t(jac.size()) == f.Range() * f.Domain() );

	// argument and result for reverse mode calculations
	Vector u(n);
	Vector v(m);

	// initialize all the components
	for(i = 0; i < m; i++)
		v[i] = Base(0);

	// loop through the different coordinate directions
	for(i = 0; i < m; i++)
	{	if( f.Parameter(i) )
		{	// return zero for this component of f
			for(j = 0; j < n; j++)
				jac[ i * n + j ] = Base(0);
		}
		else
		{
			// set v to the i-th coordinate direction
			v[i] = Base(1);

			// compute the derivative of this component of f
			u = f.Reverse(1, v);

			// reset v to vector of all zeros
			v[i] = Base(0);

			// return the result
			for(j = 0; j < n; j++)
				jac[ i * n + j ] = u[j];
		}
	}
}
开发者ID:iagomosqueira,项目名称:FLasher,代码行数:42,代码来源:jacobian.hpp

示例2: SetUp

    virtual void SetUp() {
        // use a special object for source code generation
        typedef double Base;
        typedef CG<Base> CGD;
        typedef AD<CGD> ADCG;

        x[0] = 0.5;
        x[1] = 1.5;

        // independent variables
        std::vector<ADCG> u(n);
        for (size_t j = 0; j < n; j++)
            u[j] = x[j];

        CppAD::Independent(u);

        // dependent variable vector 
        std::vector<ADCG> Z(m);

        /**
         * create the CppAD tape as usual
         */
        Z[0] = 1.5 * x[0] + 1;
        Z[1] = 1.0 * x[1] + 2;

        // create f: U -> Z and vectors used for derivative calculations
        _fun = new ADFun<CGD>(u, Z);

        /**
         * Create the dynamic library
         * (generate and compile source code)
         */
        ModelCSourceGen<double> compHelp(*_fun, _modelName);

        compHelp.setCreateForwardZero(true);
        compHelp.setCreateForwardOne(true);
        compHelp.setCreateReverseOne(true);
        compHelp.setCreateReverseTwo(true);
        compHelp.setCreateSparseJacobian(true);
        compHelp.setCreateSparseHessian(true);

        GccCompiler<double> compiler;

        ModelLibraryCSourceGen<double> compDynHelp(compHelp);

        DynamicModelLibraryProcessor<double> p(compDynHelp);

        _dynamicLib = p.createDynamicLibrary(compiler);
        _model = _dynamicLib->model(_modelName);

        // dimensions
        ASSERT_EQ(_model->Domain(), _fun->Domain());
        ASSERT_EQ(_model->Range(), _fun->Range());
    }
开发者ID:FreeScienceCommunity,项目名称:CppADCodeGen,代码行数:54,代码来源:dynamic_forward_reverse.cpp

示例3: JacobianFor

void JacobianFor(ADFun<Base> &f, const Vector &x, Vector &jac)
{	size_t i;
	size_t j;

	size_t n = f.Domain();
	size_t m = f.Range();

	// check Vector is Simple Vector class with Base type elements
	CheckSimpleVector<Base, Vector>();

	CPPAD_ASSERT_UNKNOWN( size_t(x.size())   == f.Domain() );
	CPPAD_ASSERT_UNKNOWN( size_t(jac.size()) == f.Range() * f.Domain() );

	// argument and result for forward mode calculations
	Vector u(n);
	Vector v(m);

	// initialize all the components
	for(j = 0; j < n; j++)
		u[j] = Base(0);

	// loop through the different coordinate directions
	for(j = 0; j < n; j++)
	{	// set u to the j-th coordinate direction
		u[j] = Base(1);

		// compute the partial of f w.r.t. this coordinate direction
		v = f.Forward(1, u);

		// reset u to vector of all zeros
		u[j] = Base(0);

		// return the result
		for(i = 0; i < m; i++)
			jac[ i * n + j ] = v[i];
	}
}
开发者ID:iagomosqueira,项目名称:FLasher,代码行数:37,代码来源:jacobian.hpp

示例4: testModel

    void testModel(ADFun<CGD>& f,
                   size_t expectedTmp,
                   size_t expectedArraySize) {
        using CppAD::vector;

        size_t n = f.Domain();
        //size_t m = f.Range();

        CodeHandler<double> handler(10 + n * n);

        vector<CGD> indVars(n);
        handler.makeVariables(indVars);

        vector<CGD> dep = f.Forward(0, indVars);

        LanguageC<double> langC("double");
        LangCDefaultVariableNameGenerator<double> nameGen;

        handler.generateCode(std::cout, langC, dep, nameGen);

        ASSERT_EQ(handler.getTemporaryVariableCount(), expectedTmp);
        ASSERT_EQ(handler.getTemporaryArraySize(), expectedArraySize);
    }
开发者ID:joaoleal,项目名称:CppADCodeGen,代码行数:23,代码来源:temporary.cpp

示例5:

void ADFun<Base>::operator=(const ADFun<Base>& f)
{	size_t m = f.Range();
	size_t n = f.Domain();
	size_t i;

	// go through member variables in ad_fun.hpp order
	// 
	// size_t objects
	has_been_optimized_        = f.has_been_optimized_;
	check_for_nan_             = f.check_for_nan_;
	compare_change_count_      = f.compare_change_count_;
	compare_change_number_     = f.compare_change_number_;
	compare_change_op_index_   = f.compare_change_op_index_;
	num_order_taylor_          = f.num_order_taylor_;
	cap_order_taylor_          = f.cap_order_taylor_;
	num_direction_taylor_      = f.num_direction_taylor_;
	num_var_tape_              = f.num_var_tape_;
	//
	// CppAD::vector objects
	ind_taddr_.resize(n);
	ind_taddr_                 = f.ind_taddr_;
	dep_taddr_.resize(m);
	dep_taddr_                 = f.dep_taddr_;
	dep_parameter_.resize(m);
	dep_parameter_             = f.dep_parameter_;
	//
	// pod_vector objects
	taylor_                    = f.taylor_;
	cskip_op_                  = f.cskip_op_;
	load_op_                   = f.load_op_;
	//
	// player
	play_                      = f.play_;
	//
	// sparse_pack
	for_jac_sparse_pack_.resize(0, 0);
	size_t n_set = f.for_jac_sparse_pack_.n_set();
	size_t end   = f.for_jac_sparse_pack_.end();
	if( n_set > 0 )
	{	CPPAD_ASSERT_UNKNOWN( n_set == num_var_tape_  );
		CPPAD_ASSERT_UNKNOWN( f.for_jac_sparse_set_.n_set() == 0 );
		for_jac_sparse_pack_.resize(n_set, end);
		for(i = 0; i < num_var_tape_  ; i++)
		{	for_jac_sparse_pack_.assignment(
				i                       ,
				i                       ,
				f.for_jac_sparse_pack_
			);
		}
	}
	//
	// sparse_set
	for_jac_sparse_set_.resize(0, 0);
	n_set = f.for_jac_sparse_set_.n_set();
	end   = f.for_jac_sparse_set_.end();
	if( n_set > 0 )
	{	CPPAD_ASSERT_UNKNOWN( n_set == num_var_tape_  );
		CPPAD_ASSERT_UNKNOWN( f.for_jac_sparse_pack_.n_set() == 0 );
		for_jac_sparse_set_.resize(n_set, end);
		for(i = 0; i < num_var_tape_; i++)
		{	for_jac_sparse_set_.assignment(
				i                       ,
				i                       ,
				f.for_jac_sparse_set_
			);
		}
	}
}
开发者ID:modsim,项目名称:CADET-semi-analytic,代码行数:68,代码来源:fun_construct.hpp

示例6: for

void ADFun<Base>::operator=(const ADFun<Base>& f)
{   size_t m = f.Range();
    size_t n = f.Domain();

    // go through member variables in order
    // (see ad_fun.hpp for meaning of each variable)
    compare_change_            = 0;
    taylor_per_var_            = 0;
    taylor_col_dim_            = 0;
    total_num_var_             = f.total_num_var_;
    ind_taddr_.resize(n);
    ind_taddr_                 = f.ind_taddr_;
    dep_taddr_.resize(m);
    dep_taddr_                 = f.dep_taddr_;
    dep_parameter_.resize(m);
    dep_parameter_             = f.dep_parameter_;
    play_                      = f.play_;
    if( taylor_ != CPPAD_NULL )
        CPPAD_TRACK_DEL_VEC(taylor_);
    taylor_                    = CPPAD_NULL;
    for_jac_sparse_pack_.resize(0, 0);
    for_jac_sparse_set_.resize(0, 0);

    // allocate and copy the Taylor coefficients
    taylor_per_var_     = f.taylor_per_var_;
    taylor_col_dim_     = f.taylor_col_dim_;
    size_t length       = total_num_var_ * taylor_col_dim_;
    if( length > 0 ) taylor_   = CPPAD_TRACK_NEW_VEC(length, taylor_);
    size_t i, j;
    for(i = 0; i < total_num_var_; i++)
    {   for(j = 0; j < taylor_per_var_; j++)
        {   taylor_[ i * taylor_col_dim_ + j ] =
                f.taylor_[ i * taylor_col_dim_ + j ];
        }
    }

    // allocate and copy the forward sparsity information
    size_t n_set = f.for_jac_sparse_pack_.n_set();
    size_t end   = f.for_jac_sparse_pack_.end();
    if( n_set > 0 )
    {   CPPAD_ASSERT_UNKNOWN( n_set == total_num_var_ );
        CPPAD_ASSERT_UNKNOWN( f.for_jac_sparse_set_.n_set() == 0 );
        for_jac_sparse_pack_.resize(n_set, end);
        for(i = 0; i < total_num_var_ ; i++)
        {   for_jac_sparse_pack_.assignment(
                i                       ,
                i                       ,
                f.for_jac_sparse_pack_
            );
        }
    }
    n_set = f.for_jac_sparse_set_.n_set();
    end   = f.for_jac_sparse_set_.end();
    if( n_set > 0 )
    {   CPPAD_ASSERT_UNKNOWN( n_set == total_num_var_ );
        CPPAD_ASSERT_UNKNOWN( f.for_jac_sparse_pack_.n_set() == 0 );
        for_jac_sparse_set_.resize(n_set, end);
        for(i = 0; i < total_num_var_; i++)
        {   for_jac_sparse_set_.assignment(
                i                       ,
                i                       ,
                f.for_jac_sparse_set_
            );
        }
    }

}
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:67,代码来源:fun_construct.hpp


注:本文中的ADFun::Domain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。