Registered Member
|
Is it possible to specify the Scalar template parameter of a SparseMatrix as an Eigen::Matrix?
For example, I have the following code I'm trying to get to work. ---------------------------------------------------- #include <Eigen/Dense> #include <Eigen/SparseCore> #include <iostream> using namespace Eigen; using namespace std; int main(){ Matrix<double,3,3> dmat; SparseMatrix<Matrix<double,3,3> > smat(2,2); dmat.fill(1.0); smat.insert(0,0) = dmat; return 0; } ---------------------------------------------------- And I get the following error: Matrix.h: In member function ‘typename Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Scalar& Eigen::SparseMatrix<_Scalar, _Flags, _Index>::insertUncompressed(typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Index, typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Index) [with _Scalar = Eigen::Matrix<double, 3, 3, 0, 3, 3>, int _Options = 0, _Index = int]’: /home/flyntbt/Desktop/Other/eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/SparseMatrix.h:228: instantiated from ‘typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Scalar& Eigen::SparseMatrix<_Scalar, _Flags, _Index>::insert(typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Index, typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Index) [with _Scalar = Eigen::Matrix<double, 3, 3, 0, 3, 3>, int _Options = 0, _Index = int]’ test.cpp:42: instantiated from here /home/flyntbt/Desktop/Other/eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/SparseMatrix.h:1146: error: no match for ‘operator=’ in ‘((Eigen::SparseMatrix<Eigen::Matrix<double, 3, 3, 0, 3, 3>, 0, int>*)this)->Eigen::SparseMatrix<Eigen::Matrix<double, 3, 3, 0, 3, 3>, 0, int>::m_data.Eigen::internal::CompressedStorage<_Scalar, _Index>::value [with _Scalar = Eigen::Matrix<double, 3, 3, 0, 3, 3>, _Index = int](((long unsigned int)p)) = 0’ /home/flyntbt/Desktop/Other/eigen-eigen-ffa86ffb5570/Eigen/src/Core/Matrix.h:154: note: candidates are: Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>&) [with _Scalar = double, int _Rows = 3, int _Cols = 3, int _Options = 0, int _MaxRows = 3, int _MaxCols = 3] Any Ideas how to make this work? Thanks. |
Moderator
|
Look at the BlockSparseMatrix class in unsupported/SparseExtra module of the devel branch: http://eigen.tuxfamily.org/dox-devel/un ... atrix.html
Using this class will be much more powerful since it is compatible with products and iterative solvers. |
Moderator
|
btw, using an Array instead of a Matrix should fix your issue: SparseMatrix<Array<double,3,3> >. However, the semantic of operator* will be different.
|
Registered Member
|
Thanks for the help.
I downloaded the latest dev version to get the BlockSparseMatrix and experimented with it. It is a long way from being ready since many of the basic functions (insert, add, matrix product, etc.) do not work. I also tried the SparseMatrix<Array...>> possibility but was really looking for matrix * matrix functionality. A question: What is the problem with adding the ability to use a Matrix as the Scalar parameter to a SparseMatrix? There must be some serious problem since an Array works well yet the developers still chose to create a whole new data type to handle the Matrix situation. Why not just provide some template specializations to handle the cases when the Scalar is a Matrix and the default methods are not what is needed? |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]