This forum has been archived. All content is frozen. Please use KDE Discuss instead.

AutoDiff and C++11 auto

Tags: None
(comma "," separated)
User avatar
emilf
Registered Member
Posts
29
Karma
0
OS

AutoDiff and C++11 auto

Tue Oct 18, 2016 10:08 am
Hi all,

When reading the Eigen documentation is says to not use the auto keyword for Eigen types, does this apply to AutoDiff as well?
For example, I like to split up my inputs to get a better feel for what it is (when using AutoDiffJacobian):
Code: Select all
  template <typename T1, typename T2>
  void operator()(const T1 &input, T2 *output, const Scalar &dt) const
  {
    T2 &o = *output;

    auto i0 = input(0); /* Bad example of a better name... */
    auto i1 = input(1); /* Bad example of a better name... */

    o(0) = i0 + dt * i1;
    o(1) = i1;
  }

Now this compiles and runs just fine, but I am wondering if I might be laying the ground for problems in the future?
Is there a reason to stay away from auto here?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: AutoDiff and C++11 auto

Thu Nov 03, 2016 9:41 am
As long as you know what is the underlying type of your auto variable and that they don't hide reference to dead objects, then go ahead with auto.

We discourage the use of auto because many users when writing:

auto C = A*B;

expect C to be a Matrix object whereas it is an abstract expression.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]