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

Creating an invalid matrix

Tags: None
(comma "," separated)
arennuit
Registered Member
Posts
28
Karma
0

Creating an invalid matrix

Fri Mar 04, 2016 6:25 pm
Hello,

I would like to introduce a pre-defined matrix such as Zero() or Identity(). Mine is called Invalid() and is currently generated this way inside MatrixBase_plugin.h:

Code: Select all
/// \brief Generates and invalid matrix.
static Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> Invalid()
{
    static Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> invalidMat;

    invalidMat.fill(std::numeric_limits<Scalar>::max());

    return invalidMat;
}


I am a bit embarrassed with this bit of code because each time I call function Invalid() it refills the matrix.

Anyone has a better than mine?

Thanks,

Antoine.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Creating an invalid matrix

Fri Mar 11, 2016 9:04 pm
You could return a CwiseNullaryOp, here a constant matrix:

ConstantReturnType Invalid() {
return Constant(std::numeric_limits<Scalar>::max());
}
arennuit
Registered Member
Posts
28
Karma
0

Re: Creating an invalid matrix

Mon Mar 14, 2016 11:23 am
Thanks!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft