本文整理汇总了C++中AD类的典型用法代码示例。如果您正苦于以下问题:C++ AD类的具体用法?C++ AD怎么用?C++ AD使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AD类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bug_1222
double bug_1222() {
typedef Eigen::AutoDiffScalar<Eigen::Vector3d> AD;
const double _cv1_3 = 1.0;
const AD chi_3 = 1.0;
// this line did not work, because operator+ returns ADS<DerType&>, which then cannot be converted to ADS<DerType>
const AD denom = chi_3 + _cv1_3;
return denom.value();
}
示例2: test_autodiff_scalar
void test_autodiff_scalar()
{
Vector2f p = Vector2f::Random();
typedef AutoDiffScalar<Vector2f> AD;
AD ax(p.x(),Vector2f::UnitX());
AD ay(p.y(),Vector2f::UnitY());
AD res = foo<AD>(ax,ay);
VERIFY_IS_APPROX(res.value(), foo(p.x(),p.y()));
}
示例3: bug_1261
// check a compilation issue with numext::max
double bug_1261() {
typedef AutoDiffScalar<Matrix2d> AD;
typedef Matrix<AD,2,1> VectorAD;
VectorAD v(0.,0.);
const AD maxVal = v.maxCoeff();
const AD minVal = v.minCoeff();
return maxVal.value() + minVal.value();
}
示例4: test_autodiff_scalar
void test_autodiff_scalar()
{
std::cerr << foo<float>(1,2) << "\n";
typedef AutoDiffScalar<Vector2f> AD;
AD ax(1,Vector2f::UnitX());
AD ay(2,Vector2f::UnitY());
AD res = foo<AD>(ax,ay);
std::cerr << res.value() << " <> "
<< res.derivatives().transpose() << "\n\n";
}
示例5: test_autodiff_vector
void test_autodiff_vector()
{
Vector2f p = Vector2f::Random();
typedef AutoDiffScalar<Vector2f> AD;
typedef Matrix<AD,2,1> VectorAD;
VectorAD ap = p.cast<AD>();
ap.x().derivatives() = Vector2f::UnitX();
ap.y().derivatives() = Vector2f::UnitY();
AD res = foo<VectorAD>(ap);
VERIFY_IS_APPROX(res.value(), foo(p));
}
示例6: test_autodiff_vector
void test_autodiff_vector()
{
std::cerr << foo<Vector2f>(Vector2f(1,2)) << "\n";
typedef AutoDiffScalar<Vector2f> AD;
typedef Matrix<AD,2,1> VectorAD;
VectorAD p(AD(1),AD(-1));
p.x().derivatives() = Vector2f::UnitX();
p.y().derivatives() = Vector2f::UnitY();
AD res = foo<VectorAD>(p);
std::cerr << res.value() << " <> "
<< res.derivatives().transpose() << "\n\n";
}
示例7: if
CPPAD_INLINE bool operator != (const AD<Base> &left , const AD<Base> &right)
{ bool result = (left.value_ != right.value_);
ADTape<Base> *tape = CPPAD_NULL;
if( Variable(left) )
tape = left.tape_this();
else if ( Variable(right) )
tape = right.tape_this();
if( tape != CPPAD_NULL )
tape->RecordCompare(CompareNe, result, left, right);
return result;
}
示例8: collectData
UINT RandomWalk::collectData(LPVOID lparam){
AD obj;
while(TRUE){
obj.readData();
obj.getDistance(arrayDistance, 8);
for(int i=0; i< 8; i++){
if(arrayDistance[i] <= 5.0){
SetEvent(hSysStatus);
continue;
}
}
obj.getVoltage(arrayVoltage, 2);
}
return 0;
}
示例9: check_atan2
template<typename Scalar> void check_atan2()
{
typedef Matrix<Scalar, 1, 1> Deriv1;
typedef AutoDiffScalar<Deriv1> AD;
AD x(internal::random<Scalar>(-3.0, 3.0), Deriv1::UnitX());
using std::exp;
Scalar r = exp(internal::random<Scalar>(-10, 10));
AD s = sin(x), c = cos(x);
AD res = atan2(r*s, r*c);
VERIFY_IS_APPROX(res.value(), x.value());
VERIFY_IS_APPROX(res.derivatives(), x.derivatives());
}
示例10: bug_1223
double bug_1223() {
using std::min;
typedef Eigen::AutoDiffScalar<Eigen::Vector3d> AD;
const double _cv1_3 = 1.0;
const AD chi_3 = 1.0;
const AD denom = 1.0;
// failed because implementation of min attempts to construct ADS<DerType&> via constructor AutoDiffScalar(const Real& value)
// without initializing m_derivatives (which is a reference in this case)
#define EIGEN_TEST_SPACE
const AD t = min EIGEN_TEST_SPACE (denom / chi_3, 1.0);
const AD t2 = min EIGEN_TEST_SPACE (denom / (chi_3 * _cv1_3), 1.0);
return t.value() + t2.value();
}
示例11: Variable
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
bool operator >= (const AD<Base> &left , const AD<Base> &right)
{ bool result = (left.value_ >= right.value_);
bool var_left = Variable(left);
bool var_right = Variable(right);
ADTape<Base> *tape = CPPAD_NULL;
if( var_left )
{ tape = left.tape_this();
if( var_right )
{ if( result )
{ tape->Rec_.PutOp(LevvOp);
tape->Rec_.PutArg(right.taddr_, left.taddr_);
}
else
{ tape->Rec_.PutOp(LtvvOp);
tape->Rec_.PutArg(left.taddr_, right.taddr_);
}
}
else
{ addr_t arg1 = tape->Rec_.PutPar(right.value_);
if( result )
{ tape->Rec_.PutOp(LepvOp);
tape->Rec_.PutArg(arg1, left.taddr_);
}
else
{ tape->Rec_.PutOp(LtvpOp);
tape->Rec_.PutArg(left.taddr_, arg1);
}
}
}
else if ( var_right )
{ tape = right.tape_this();
addr_t arg0 = tape->Rec_.PutPar(left.value_);
if( result )
{ tape->Rec_.PutOp(LevpOp);
tape->Rec_.PutArg(right.taddr_, arg0);
}
else
{ tape->Rec_.PutOp(LtpvOp);
tape->Rec_.PutArg(arg0, right.taddr_);
}
}
return result;
}
示例12: Eval
// used during the recording process
AD<Base> Eval(const AD<Base> &x) const
{ AD<Base> z;
z.value_ = f(x.value_);
if( Variable(x) )
{ x.tape_this()->RecordDisOp(
z,
x.taddr_,
y_taddr
);
}
return z;
}
示例13: Variable
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
bool operator != (const AD<Base> &left , const AD<Base> &right)
{ bool result = (left.value_ != right.value_);
bool var_left = Variable(left);
bool var_right = Variable(right);
local::ADTape<Base> *tape = CPPAD_NULL;
if( var_left )
{ tape = left.tape_this();
if( var_right )
{ tape->Rec_.PutArg(left.taddr_, right.taddr_);
if( result )
tape->Rec_.PutOp(local::NevvOp);
else
tape->Rec_.PutOp(local::EqvvOp);
}
else
{ addr_t arg1 = tape->Rec_.PutPar(right.value_);
tape->Rec_.PutArg(arg1, left.taddr_);
if( result )
tape->Rec_.PutOp(local::NepvOp);
else
tape->Rec_.PutOp(local::EqpvOp);
}
}
else if ( var_right )
{ tape = right.tape_this();
addr_t arg0 = tape->Rec_.PutPar(left.value_);
tape->Rec_.PutArg(arg0, right.taddr_);
if( result )
tape->Rec_.PutOp(local::NepvOp);
else
tape->Rec_.PutOp(local::EqpvOp);
}
return result;
}
示例14: audioCallBack
// DO NOT MODIFY THE AUDIO CALLBACK FUNCTION
void audioCallBack(AudioIOData& io)
{
while(io())
{
if(tmr()) env.reset(); // Reset AD envelope
input = white() * env(); // Apply envelope to white noise
roomReverb(input, output, decayTime); // Apply reverb
for (int i = 0; i < channelsOut; i++)
{
io.out(i) = ( (1.0 - dryWet) * input + dryWet * output ) * level;
}
}
}
示例15: log
AD<T> log(const AD<T>& x){
AD<T> newAD;
ADnode<T>* orx = x.getRoot();
newAD.setRoot(new ADlog<T>(orx));
return newAD;
}