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

head, leftCols, and similar cause "expected expression"

Tags: None
(comma "," separated)
davidje13
Registered Member
Posts
13
Karma
0
OS
Hi, I'm switching my code to use Eigen and it's been going OK, but I can't seem to get head and other block-like functions to work. For example, this code:

Code: Select all
typedef double T; // these actually come from a templated class, but this is what they evaluate to
typedef Eigen::Matrix<T,4,1> P;

void calculate_axes(
   const P& l,
   P* const perp,
   P* const front,
   const P& primary = P( 0, 1, 0, 0 )
) noexcept {
   if( perp != NULL ) {
      *perp <<
         l.head<3>( ).cross( primary.head<3>( ) ).normalized( ),
         0
      ;
      if( front != NULL ) {
         *front <<
            l.head<3>( ).cross( perp->head<3>( ) ).normalized( ),
            0
         ;
      }
   } else if( front != NULL ) {
      *front <<
         l.head<3>( ).cross(
            l.head<3>( ).cross( primary.head<3>( ) )
         ).normalized( ),
         0
      ;
   }
}


Gives errors like:

Code: Select all
error: expected expression
                                l.head<3>( ).cross( primary.head<3>( ) ).normalized( ),
                                           ^


For every head call (clang, via Xcode). Whereas replacing the body of the function with this compiles fine:

Code: Select all
*perp <<
   Eigen::Matrix<T,3,1>( l.data( ) ).cross( Eigen::Matrix<T,3,1>( primary.data( ) ) ).normalized( ),
   0
;


I've been able to find fixes for other problems pretty easily online, but this doesn't turn anything up. Am I using it wrong?
davidje13
Registered Member
Posts
13
Karma
0
OS
I've narrowed it down a bit more, and it seems to be related to the templates. This works:

Code: Select all
#include <eigen3/Eigen/Dense>

Eigen::Matrix<double,4,1> foo( void ) noexcept {
   const Eigen::Matrix<double,4,1> eye;
   
   Eigen::Matrix<double,4,1> r;
   r << eye.head<3>( ), 0;
   return r;
}


but this doesn't:

Code: Select all
#include <eigen3/Eigen/Dense>

template< typename T >
Eigen::Matrix<T,4,1> foo( void ) noexcept {
   const Eigen::Matrix<T,4,1> eye;
   
   Eigen::Matrix<T,4,1> r;
   r << eye.head<3>( ), 0;
   return r;
}


foo isn't actually called anywhere, but the second version complains about head<3>() as before. Using head(3) instead compiles fine, but obviously that's not as good. I can only assume this is related to the template-based optimisation Eigen uses, but I'm having trouble debugging further because "typename DenseBase<Derived>::template FixedSegmentReturnType<Size>::Type" isn't syntax which I'm familiar with.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
davidje13
Registered Member
Posts
13
Karma
0
OS
Thanks. Can I suggest mentioning "expected expression" in that reference page to make it turn up in searches?

To have a concise reference for anyone finding this thread, this works:

Code: Select all
myvector.template head<3>( )
jitseniesen
Registered Member
Posts
204
Karma
2
davidje13 wrote:Thanks. Can I suggest mentioning "expected expression" in that reference page to make it turn up in searches?
]
That's a good idea; I'll take care of it.


Bookmarks



Who is online

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