Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Armadillo initializer list is not working

I am using the MSVC2013 64bit compiler under Windows 10.

According to:

std::cout << arma::arma_version::as_string() << std::endl;

I have version 6.100.1 (Midnight Blue) of the Armadillio library.

I have C++11 enabled, for example

auto il = { 10, 20, 30 };
for(auto ele : il)
    cout<<ele<<endl;

is working. Also the library is correctly added, as the following code runs:

vec v;
v<<10<<20<<30;
cout<<v;

But trying to use initializer lists for Armadillio fails.

vec v = { 1.0, 2.0, 3.0 };

causes the compile error:

error: C2440: 'initializing' : cannot convert from 'initializer-list' to 'arma::Col' No constructor could take the source type, or constructor overload resolution was ambiguous

like image 665
newandlost Avatar asked Oct 27 '15 11:10

newandlost


2 Answers

In the folder armadillo-6.100.1\include\armadillo_bits there is a config file called config.hpp.

There you find a paragraph saying:

#if !defined(ARMA_USE_CXX11)
// #define ARMA_USE_CXX11
//// Uncomment the above line to forcefully enable use of C++11 features (eg. initialiser lists).
//// Note that ARMA_USE_CXX11 is automatically enabled when a C++11 compiler is detected.
#endif

So it looks like the MSVC2013 64bit is not detected as a C++11 compiler from Armadillio. So uncommenting the line

// #define ARMA_USE_CXX11

Solved my problem. Now this is working like charm:

vec v = { 1.0, 2.0, 3.0 };
cout<<v;
like image 50
newandlost Avatar answered Sep 20 '22 02:09

newandlost


The documentation says that vec is a typedef for Col<double:

For convenience the following typedefs have been defined:
vec = colvec = Col< double >

If we look on the Col constructors, we will find the following constructor that accepts an initializer list:

#if defined(ARMA_USE_CXX11)

  template<typename eT>
  inline
  Col<eT>::Col(const std::initializer_list<eT>& list)
  {
    <...>   
  }

So my guess would be that ARMA_USE_CXX11 is not defined, and thus this constructor is not accessible.

like image 41
SingerOfTheFall Avatar answered Sep 20 '22 02:09

SingerOfTheFall