pybind / pybind/pybind11

Error when returning Eigen::SparseVector

Open
#2,301 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

While returning sparse matrices works out pretty well, returning sparse vectors causes an error.
The exact error message I get is:

...
.../pybind11/include/pybind11/eigen.h:581:32: fatal error: no member named 'makeCompressed' in 'Eigen::SparseVector<double, 0, int>'
const_cast<Type&>(src).makeCompressed();
...

This seems to be due to the fact that Eigen::SparseVector derives from Eigen::SparseCompressedBase instead of
Eigen::SparseBase, such that the method makeCompressed does not exists.

I don't recall having this issue in the past. On the other hand, the last change to the relevant file (EIGEN_DIR/src/SparseCore/SparseVector.h) has been made almost 2 years ago.

Here is a minimal reproducible example:

#include <Eigen/Sparse>
#include <pybind11/eigen.h>

PYBIND11_MODULE(_returnSparseVector, m)
{
	m.def("returnSparse", []() -> Eigen::SparseVector<double> {
		Eigen::SparseVector<double> vec(10);
		return vec;
	} );
}

Compiler: Apple clang version 11.0.3 (clang-1103.0.32.62)
pybind11: latest (git master branch)
Eigen: latest (git master branch)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the minimal C++ example using Eigen/Sparse and pybind11/eigen.h, then inspect the conversion code around line 581 and the Eigen::SparseVector inheritance described in the report. Done means returning an Eigen::SparseVector compiles and works without the makeCompressed error, while existing sparse-matrix returns continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.