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

CWiseBinaryOp to MatrixBase

Tags: None
(comma "," separated)
abrown
Registered Member
Posts
4
Karma
0

CWiseBinaryOp to MatrixBase

Thu Jun 16, 2016 9:16 pm
I will let my code do the talking

Code: Select all
Eigen::Block<Derived> mat = matrix.block(1, dimension, matrix.rows()-1, 1) - matrix.block(0, dimension, matrix.rows()-1, 1);


Code: Select all
/home/adambrown/Development/Fagermans/adam/slio/include/ft/algorithm/eigen.h:27:132:[b] error: conversion from ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<double>, const Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, 3, 1> >, -1, -1, false>, const Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, 3, 1> >, -1, -1, false> >’ to non-scalar type ‘Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<double, -1, 3, 1> > >’ requested[/b]
     Eigen::MatrixBase<Derived> mat = matrix.block(1, dimension, matrix.rows()-1, 1) - matrix.block(0, dimension, matrix.rows()-1, 1);
                                                                                                                                    ^
test/CMakeFiles/slio-tests.dir/build.make:158: recipe for target 'test/CMakeFiles/slio-tests.dir/StationsTest.cpp.o' failed
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: CWiseBinaryOp to MatrixBase

Fri Jun 17, 2016 2:32 pm
What are you trying to achieve?

A Block<T> expression defines a reference to a sub expression of type T. If you want "mat" to represent an abstract expression, then use "auto mat = ...", if you want the actual values use auto 'mat = (....).eval()' or, in your case, "Matrix<double,Dynamic,1> mat = ....".

Finally, since you are taking columns, better let Eigen's know at compile time:

matrix.col(dim).tail(rows-1) - matrix.col(dim).head(rows-1)
abrown
Registered Member
Posts
4
Karma
0

Re: CWiseBinaryOp to MatrixBase

Fri Jun 17, 2016 2:58 pm
I'm just trying to figure out how to return the difference of the columns of a generic matrix. So I would like to take in a MatrixBase<Derived> and return the same (with 1 less row obviously). I am having trouble with converting from Eigen::CwiseBinaryOp to Eigen::MatrixBase or Eigen::Block, whatever it may be.

I'm basically trying to mimic this function http://www.mathworks.com/help/matlab/re ... n_loc_drop
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: CWiseBinaryOp to MatrixBase

Sat Jun 18, 2016 6:43 am
So I guess you want to return an expression and not the evaluated expression. If you can use C++11 (or even better 14) then better use "auto", otherwise the answer is in the error message:

CwiseBinaryOp<internal::scalar_difference_op<double>, const Block<Derived, Dynamic, Dynamic>, const Eigen::Block<Derived, Dynamic, Dynamic> >


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]