6

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.

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.

Any help would be appreciated.

Regards, Dushyant

Garima Singh
  • 1,410
  • 5
  • 22
  • 46
  • 1
    Armadillo generally uses `umat` and `uvec` to represent matrices and vectors that store logical values. – mtall Apr 02 '14 at 15:38
  • I have the same question and expect an answer to have `vector `, which takes less space then `vector ` – kirill_igum Oct 30 '14 at 07:46

1 Answers1

6

Consider using a matrix uchar_mat which is a typdef for Mat<unsigned char>, it should consume the same amount of memory as a matrix of boolean values.

The Armadillo documentation of version 7.8 states that a matrix Mat<type>, can be of the following types: float, double, std::complex<float>, std::complex<double>, short, int, long, and unsigned versions of short, int, and long. The code on GitHub however contains typedef Mat <unsigned char> uchar_mat; in the file include/armadillo_bits/typedef_mat.hpp so you should also be able to use uchar_mat.

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.

Community
  • 1
  • 1
Svaberg
  • 1,501
  • 1
  • 19
  • 40
  • `vector ` takes a lot less memory then `vector ` – kirill_igum Oct 30 '14 at 07:48
  • @kirill_igum are you referring to `std::vector`? This is a specialized version of `std::vector` which optimizes for space. I do not think a similar mechanism exists in the Armadillo library. So, indeed, depending on what you want to do you could be better off using the `std` namespace vector class. – Svaberg Oct 31 '14 at 13:07
  • 1
    I knwo this aswer is old, but when I knwo look at the armadillo doc, there is no char type available, How can I accomplish it now? – v.tralala Apr 17 '17 at 23:39
  • You are right the documentation does not mention `char` any longer. There still seems to be support for it in the code though. What error did you get when trying to use `Mat`? – Svaberg Apr 18 '17 at 00:42
  • There is even a statement `typedef Mat uchar_mat;` in the file [include/armadillo_bits/typedef_mat.hpp](https://github.com/conradsnicta/armadillo-code/blob/unstable/include/armadillo_bits/typedef_mat.hpp) so you should also be able to use `uchar_mat`. – Svaberg Apr 18 '17 at 00:54