Ejemplo n.º 1
0
inline void forward_abs_op(
	size_t j           ,
	size_t i_z         ,
	size_t i_x         ,
	size_t nc_taylor   , 
	Base*  taylor      )
{
	size_t k;
	static Base zero(0);

	// check assumptions
	CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
	CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
	CPPAD_ASSERT_UNKNOWN( i_x < i_z );
	CPPAD_ASSERT_UNKNOWN( j < nc_taylor );

	// Taylor coefficients corresponding to argument and result
	Base* x = taylor + i_x * nc_taylor;
	Base* z = taylor + i_z * nc_taylor;

	// order that decides positive, negative or zero
	k = 0;
	while( (k < j) & (x[k] == zero) )
		k++; 

	if( GreaterThanZero(x[k]) )
		z[j]  = x[j];
	else if( LessThanZero(x[k]) )
		z[j] = -x[j]; 
	else	z[j] = zero;
}
Ejemplo n.º 2
0
Archivo: abs_op.hpp Proyecto: cran/RMC
inline void ForAbsOp(size_t j, 
	Base *z, const Base *x)
{	size_t k;

	// order that decides positive, negative or zero
	k = 0;
	while( (k < j) & (x[k] == Base(0)) )
		k++; 

	if( GreaterThanZero(x[k]) )
		z[j]  = x[j];
	else if( LessThanZero(x[k]) )
		z[j] = -x[j]; 
	else	z[j] = Base(0);
}
Ejemplo n.º 3
0
inline void forward_levp_op_0(
	size_t&       count       ,
	const addr_t* arg         ,
	const Base*   parameter   ,
	size_t        cap_order   ,
	Base*         taylor      )
{
	// check assumptions
	CPPAD_ASSERT_UNKNOWN( NumArg(LevpOp) == 2 );
	CPPAD_ASSERT_UNKNOWN( NumRes(LevpOp) == 0 );

	// Taylor coefficients corresponding to arguments and result
	Base* x = taylor + arg[0] * cap_order;
	Base  y = parameter[ arg[1] ];

	count += GreaterThanZero(x[0] - y);
}
Ejemplo n.º 4
0
inline void forward_pri_0(
	std::ostream& s_out       ,
	const addr_t* arg         ,
	size_t        num_text    ,
	const char*   text        ,
	size_t        num_par     ,
	const Base*   parameter   ,
	size_t        cap_order   ,
	const Base*   taylor      )
{	Base pos, var;
	const char* before;
	const char* after;
	CPPAD_ASSERT_NARG_NRES(PriOp, 5, 0);

	// pos
	if( arg[0] & 1 )
	{	pos = taylor[ arg[1] * cap_order + 0 ];
	}
	else
	{	CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
		pos = parameter[ arg[1] ];
	}

	// before
	CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text );
	before = text + arg[2];

	// var
	if( arg[0] & 2 )
	{	var = taylor[ arg[3] * cap_order + 0 ];
	}
	else
	{	CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
		var = parameter[ arg[3] ];
	}

	// after
	CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text );
	after = text + arg[4];

	if( ! GreaterThanZero( pos ) )
		s_out << before << var << after;
}
Ejemplo n.º 5
0
inline void reverse_abs_op(
	size_t      d            ,
	size_t      i_z          ,
	size_t      i_x          ,
	size_t      nc_taylor    , 
	const Base* taylor       ,
	size_t      nc_partial   ,
	Base*       partial      )
{	size_t j, k;	
	static Base zero(0);


	// check assumptions
	CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
	CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
	CPPAD_ASSERT_UNKNOWN( i_x < i_z );
	CPPAD_ASSERT_UNKNOWN( d < nc_taylor );
	CPPAD_ASSERT_UNKNOWN( d < nc_partial );

	// Taylor coefficients and partials corresponding to argument
	const Base* x  = taylor  + i_x * nc_taylor;
	Base* px       = partial + i_x * nc_partial;

	// Taylor coefficients and partials corresponding to result
	Base* pz       = partial +    i_z * nc_partial;

	// order that decides positive, negative or zero
	k = 0;
	while( (k < d) & (x[k] == zero) )
		k++; 

	if( GreaterThanZero(x[k]) )
	{	// partial of z w.r.t y is +1
		for(j = k; j <= d; j++)
			px[j] += pz[j];
	}
	else if( LessThanZero(x[k]) )
	{	// partial of z w.r.t y is -1
		for(j = k; j <= d; j++)
			px[j] -= pz[j];
	}
}
Ejemplo n.º 6
0
Archivo: abs_op.hpp Proyecto: cran/RMC
inline void RevAbsOp(size_t d, 
	const Base  *z, const Base *x,
	      Base *pz,      Base *px)
{	size_t j, k;

	// order that decides positive, negative or zero
	k = 0;
	while( (k < d) & (x[k] == Base(0)) )
		k++; 

	if( GreaterThanZero(x[k]) )
	{	for(j = k; j <= d; j++)
			px[j] += pz[j];
	}
	else if( LessThanZero(x[k]) )
	{	for(j = k; j <= d; j++)
			px[j] -= pz[j];
	}

}
Ejemplo n.º 7
0
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
bool GreaterThanZero(const AD<Base> &x)
{	return GreaterThanZero(x.value_); }
Ejemplo n.º 8
0
void forward_cskip_op_0(
    size_t               i_z            ,
    const addr_t*        arg            ,
    size_t               num_par        ,
    const Base*          parameter      ,
    size_t               cap_order      ,
    Base*                taylor         ,
    bool*                cskip_op       )
{
    CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < size_t(CompareNe) );
    CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );

    Base left, right;
    if( arg[1] & 1 )
    {   // If variable arg[2] <= i_z, it has already been computed,
        // but it will be skipped for higher orders.
        CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) <= i_z );
        left = taylor[ size_t(arg[2]) * cap_order + 0 ];
    }
    else
    {   CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
        left = parameter[ arg[2] ];
    }
    if( arg[1] & 2 )
    {   // If variable arg[3] <= i_z, it has already been computed,
        // but it will be skipped for higher orders.
        CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= i_z );
        right = taylor[ size_t(arg[3]) * cap_order + 0 ];
    }
    else
    {   CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
        right = parameter[ arg[3] ];
    }
    bool ok_to_skip = IdenticalCon(left) & IdenticalCon(right);
    if( ! ok_to_skip )
        return;

    // initialize to avoid compiler warning
    bool true_case = false;
    Base diff      = left - right;
    switch( CompareOp( arg[0] ) )
    {
        case CompareLt:
        true_case = LessThanZero(diff);
        break;

        case CompareLe:
        true_case = LessThanOrZero(diff);
        break;

        case CompareEq:
        true_case = IdenticalZero(diff);
        break;

        case CompareGe:
        true_case = GreaterThanOrZero(diff);
        break;

        case CompareGt:
        true_case = GreaterThanZero(diff);
        break;

        case CompareNe:
        true_case = ! IdenticalZero(diff);
        break;

        default:
        CPPAD_ASSERT_UNKNOWN(false);
    }
    if( true_case )
    {   for(addr_t i = 0; i < arg[4]; i++)
            cskip_op[ arg[6+i] ] = true;
    }
    else
    {   for(addr_t i = 0; i < arg[5]; i++)
            cskip_op[ arg[6+arg[4]+i] ] = true;
    }
    return;
}