I need to have a sparse matrix whose elements are not simple numbers, but objects, e.g. a couple of floating point values and a bunch of integer indices.

I am wondering if Eigen has something similar, beyond its Eigen::SparseMatrix< _Scalar, _Options, _StorageIndex > class template (the only sparse matrix I have found so far), which only accepts a scalar template parameter.

I know I can use a SoA (Structure of Arrays) approach, but in this specific case, for data locality reasons, I am trying with an AoS (Array of Structures) one.


Certainly. There are a few things you have to define for your type that are listed on this page in the documentation:


It basically boils down to defining arithmetic operators appropriately for your type, plus specializing a traits template NumTraits that describes your type. The link above has a few examples that you can follow.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.