Search code examples
c++eigeneigen3alglib

creating `alglib::integer_1d_array` with `Eigen::Matrix`


I keep getting the error error: no matching function for call to 'alglib::integer_1d_array::setcontent(int, Eigen::PlainObjectBase<Eigen::Matrix<int, 3, 1> >::Scalar*)'.

For some reason alglib::integer_1d_array doesn't like to be instantiated in the same way as the alglib::real_1d_array.

For example, inside a function template with template argument size_t num, and parameter Eigen::Matrix<double,num,num> A, this works:

Eigen::Matrix<double,num,num,Eigen::RowMajor> twice_A_rm(A);
real_2d_array a;
a.setcontent(num, num, twice_A_rm.data());

However, it doesn't work as soon as I change to the integer array:

Eigen::Matrix<int,num+1,1> ctEig = Eigen::Matrix<int,num+1,1>::Constant(1.0); // positive for >=
integer_1d_array ct;
ct.setlength(num+1);
ct.setcontent(num+1, ctEig.data());

I can also replace num+1 with static_cast<int>(num+1) in the last line, and it still doesn't work. what am I doing wrong?


Solution

  • Briefly browsing through the source of alglib, it seems like integer_1d_array has data of type ptrdiff_t by default, i.e., your code should work, if you replace int by ptrdiff_t in the line you declare/initialize ctEig:

    Eigen::Matrix<ptrdiff_t,num+1,1> ctEig = Eigen::Matrix<ptrdiff_t,num+1,1>::Constant(1);
    integer_1d_array ct;
    ct.setlength(num+1); // <-- I assume this line is redundant
    ct.setcontent(num+1, ctEig.data());