Armadillo – no member named i in matrix expression

  armadillo, c++

According to Armadillo docs:

.i()

Member function of any matrix expression

Provides an inverse of the matrix expression
...

However, when I try to compile this snippet:

#include <armadillo>
#include <iostream>

arma::sp_mat linReg(arma::sp_mat X, arma::sp_mat Y) {
    return (X.t() * X).i() * X.t() * Y;
}

int main() {
    arma::sp_mat X = arma::sprandu(1000, 10, 0.3);
    arma::sp_mat y = arma::sprandu(1000, 10, 0.3);
    std::cout << linReg(X,y).t() << std::endl;
}

I get the following error

lreg.cpp: In function ‘arma::sp_mat linReg(arma::sp_mat,
arma::sp_mat)’: lreg.cpp:6:24: error: ‘arma::enable_if2<true, const
arma::SpGluearma::SpOp<arma::SpMat<double, arma::spop_htrans>,
arma::SpMat, arma::spglue_times> >::result’ {aka ‘const class
arma::SpGluearma::SpOp<arma::SpMat<double, arma::spop_htrans>,
arma::SpMat, arma::spglue_times>’} has no member named ‘i’
6 | return (X.t() * X).i() * X.t() * Y;
|

I already tried with mat and it works fine. Any clue why it’s not working with sparse matrix? And if so, how can we calculate the inverse of a sparse matrix?

Source: Windows Questions C++

LEAVE A COMMENT