math icon indicating copy to clipboard operation
math copied to clipboard

Bug: `arena_matrix` traits aren't specialized properly for sparse matrices

Open dpsimpson opened this issue 1 year ago • 3 comments

Description

This is one of those things where I can't tell if it's a bug or a user error, but I'm trying to use an arena_matrix<Eigen::SparseMatrix<double>> type and I'm getting an error related to the setting of the internal Eigen traits. In particular, I'm getting

/home/dan-simpson/Documents/math/stan/math/rev/core/arena_matrix.hpp:490:38: error: ‘PlainObjectTypeInnerSize’ is not a member of ‘Eigen::internal::traits<stan::math::arena_matrix<Eigen::SparseMatrix<double> > >::base’ {aka ‘Eigen::internal::traits<Eigen::Map<Eigen::SparseMatrix<double>, 0, Eigen::Stride<0, 0> > >’}
  490 |     PlainObjectTypeInnerSize = base::PlainObjectTypeInnerSize,
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
/home/dan-simpson/Documents/math/stan/math/rev/core/arena_matrix.hpp:491:38: error: ‘InnerStrideAtCompileTime’ is not a member of ‘Eigen::internal::traits<stan::math::arena_matrix<Eigen::SparseMatrix<double> > >::base’ {aka ‘Eigen::internal::traits<Eigen::Map<Eigen::SparseMatrix<double>, 0, Eigen::Stride<0, 0> > >’}
  491 |     InnerStrideAtCompileTime = base::InnerStrideAtCompileTime,
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
/home/dan-simpson/Documents/math/stan/math/rev/core/arena_matrix.hpp:492:38: error: ‘OuterStrideAtCompileTime’ is not a member of ‘Eigen::internal::traits<stan::math::arena_matrix<Eigen::SparseMatrix<double> > >::base’ {aka ‘Eigen::internal::traits<Eigen::Map<Eigen::SparseMatrix<double>, 0, Eigen::Stride<0, 0> > >’}
  492 |     OuterStrideAtCompileTime = base::OuterStrideAtCompileTime,
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
/home/dan-simpson/Documents/math/stan/math/rev/core/arena_matrix.hpp:493:23: error: ‘Alignment’ is not a member of ‘Eigen::internal::traits<stan::math::arena_matrix<Eigen::SparseMatrix<double> > >::base’ {aka ‘Eigen::internal::traits<Eigen::Map<Eigen::SparseMatrix<double>, 0, Eigen::Stride<0, 0> > >’}
  493 |     Alignment = base::Alignment,

I strongly suspect this is because the traits defined in SpraseCore/SparseMap.h don't line up with those in Core/Map.h, so the template defining them for arena_matrix needs to be specialized.

dpsimpson avatar Dec 26 '24 19:12 dpsimpson

Yes that's a bug 🪲 I'll add that to arena_matrix.hpp

SteveBronder avatar Dec 26 '24 21:12 SteveBronder

It looks like they need to be added here

https://github.com/stan-dev/math/blob/develop/stan/math/rev/core/arena_matrix.hpp#L188

SteveBronder avatar Dec 26 '24 21:12 SteveBronder

Cool! Finally thought to pick up the sparse matrix stuff again today and couldn’t remember why I’d stopped last time. Sadly it’s just a bit too deep in the “how eigen actually works” mines for me to fix it myself.

dpsimpson avatar Dec 27 '24 02:12 dpsimpson