犰狳C ++的线性代数库:如何创建布尔矢量 [英] Armadillo C++ linear algebra library : How to create vector of boolean
问题描述
最近,我开始使用犰狳C ++库。鉴于我的C ++编码技能不是很大,我发现这对线性代数很友好。我也使用了与我一起MATLAB加快工作速度为许多重建算法。
Recently I started using Armadillo C++ library. Given my C++ coding skills are not that great, I found this very friendly for linear algebra. I am also using that along with my matlab to speed things up for many of reconstruction algorithm.
我确实需要创建布尔的一个载体,我会使用这个库,而不是preFER。然而,我无法弄清楚如何做到这一点。我试着用uvec;但是,文件似乎表明它不能与布尔使用。
I do need to create a vector of boolean and I would prefer using this library rather than . However, I could not figure out how to do it. I tried using uvec; but, documentation seems to indicate that it can not be used with boolean.
任何帮助将是AP preciated。
Any help would be appreciated.
问候,
Dushyant
Regards, Dushyant
推荐答案
考虑使用矩阵垫< unsigned char型>
,它通常会消耗内存相同数量的矩阵布尔值。
Consider using a matrix Mat<unsigned char>
, it will normally consume the same amount of memory as a matrix of boolean values.
借助犰狳文档指出,一个矩阵垫&LT;&型GT ;
,可以是以下类型:浮动
,双击
,的std ::复杂&LT;浮动&GT;
,的std ::复杂&LT;双&GT;
,字符
,短
, INT
,长
和上面的签名
版本。所以,你是对的,没有类型的矩阵布尔
。
The Armadillo documentation states that a matrix Mat<type>
, can be of the following types: float
, double
, std::complex<float>
, std::complex<double>
, char
, short
, int
, long
and unsigned
versions of the above. So you are right there is no matrix of type bool
.
您将无法通过创建较 unsigned char型
数值矩阵布尔
值矩阵保存任何记忆(一布尔
消耗型8位)。这是因为,在C ++中的每个数据类型必须寻址;它必须至少1个字节长的,以便它可以创建一个指针指向它
You will not save any memory by creating a matrix of bool
values compared to a matrix of unsigned char
values (a bool
type consumes 8 bits). This is because in C++ every data type must be addressable; it must be at least 1 byte long so that it is possible to create a pointer pointing to it.
这篇关于犰狳C ++的线性代数库:如何创建布尔矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!