[CppAD] Multiplication of scalar (double) and Vector (AD< AD<double> >)

Brad Bell bradbell at seanet.com
Tue Dec 15 11:28:43 EST 2015


Try the following
     tmp = tmp + AD< AD<double> > (0.5) * tmp
For example, the following program:

# include <cppad/cppad.hpp>
# include <cppad/example/cppad_eigen.hpp>
int main(void)
{   bool ok = true;
     //
     typedef CppAD::AD< CppAD::AD<double> > Scalar;
     typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
     //
     Vector tmp(1);
     tmp[0] = 1.0;
     tmp    = tmp + Scalar(1.0) * tmp;
     //
     ok    &= tmp[0] == 2.0;
     if( ok )
         return 0;
     return 1;
}
~


On 12/15/2015 7:55 AM, Leitz, Thomas wrote:
> Hello,
>
> I'm using CppAD with Eigen. Multiplication of a double with an 
> Eigen-Vector like this:
>
> ---
>
> template<typename Type>
> using Vector = Eigen::Matrix<Type, Eigen::Dynamic, 1>;
>
> Vector< AD< AD<double> > > tmp;
>
> tmp = tmp + 0.5 * tmp;
>
> ---
>
> gives the following error
>
> ***error: **invalid operands to binary expression ('double' and 
> 'Vector<AD<AD<double> > >' (aka 
> 'Eigen::Matrix<CppAD::AD<CppAD::AD<double> >, -1, 1, 0, -1, 1>'))*
>
>     tmp = tmp + 0.5 * tmp;
>
>
>
> The error goes away if I do
>
> ---
> tmp = tmp + AD<double>(0.5) * tmp;
> ---
>
> Is this the right way to do it?
> Btw. an AD< AD<double> > can be multiplied by a double just fine.
>
> Thomas
>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cppad/attachments/20151215/3a575d97/attachment.html>


More information about the CppAD mailing list