Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen sparse matrix support? #237

Closed
osorensen opened this issue Jul 20, 2022 · 1 comment
Closed

Eigen sparse matrix support? #237

osorensen opened this issue Jul 20, 2022 · 1 comment

Comments

@osorensen
Copy link

osorensen commented Jul 20, 2022

I am creating an R package in which the core computation is to minimize a scalar loss function whose evaluation requires a lot of sparse matrix operations, including the solution of sparse linear systems. I'm using autodiff to compute the gradient and potentially the Hessian, both of which are dense.

Made this work by adding this to the top of autodiff/common/eigen.hpp:

#include <Eigen/SparseCore>

and then this

template<typename Scalar, int Options, typename StorageIndex>
struct VectorTraits<Eigen::SparseMatrix<Scalar, Options, StorageIndex>>
{
  using ValueType = Scalar;


  template<typename NewValueType>
  using ReplaceValueType = Eigen::SparseMatrix<NewValueType, Options, StorageIndex>;
};

I can then define sparse matrices with dual values with something like this:

using llt = Eigen::SimplicialLLT<Eigen::SparseMatrix<dual2nd> >;
using dspmat = Eigen::SparseMatrix<dual2nd>;
using ddiag = Eigen::DiagonalMatrix<dual2nd, Eigen::Dynamic>;

Would it be of interest to include something like this in autodiff itself? I realize things might be harder if the results of differentation are also supposed to be sparse, but when these are dense, it seems quite straightforward.

@osorensen
Copy link
Author

Moving to Discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant