Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eigen Initialize Boolean Array

How do you initialize a boolean array in the Eigen library (C++) to a specific truth value? There are initializers for numeric matrices but I can't find an example for a boolean array (Eigen::Array).

like image 321
Armin Meisterhirn Avatar asked Nov 13 '14 04:11

Armin Meisterhirn


1 Answers

The other answer are correct, but for completeness let me add:

#include <Eigen/Dense>
using namespace Eigen;

typedef Array<bool,Dynamic,1> ArrayXb;
ArrayXb a = ArrayXb::Constant(5,true);
ArrayXb b(5);
b.setConstant(true);         // no-resizing
b.fill(true);                // alias for setConstant
b.setConstant(10,true);      // resize and initialize
Array<bool, 5, 1> c(true);

In the last case, because here the size is known at compile time, the argument is interpreted as the initializing value.

like image 193
ggael Avatar answered Sep 21 '22 18:09

ggael