Automatic conversion of derived classes from Eigen vector/matrix types to numpy array
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Consider the following class inherited from Eigen::VectorXd that prevents client code to resize it:
class VectorXdConstSize : public VectorXd
{
public:
using VectorXd::VectorXd;
VectorXdConstSize() = delete;
template<typename Derived>
auto operator=(const Eigen::MatrixBase<Derived>& other) -> VectorXdConstSize&
{
Ref<VectorXd> aux(*this);
aux = other;
return *this;
}
auto resize(Index) -> void = delete;
operator Ref<VectorXd>() { return *this; }
operator Ref<const VectorXd>() const { return *this; }
};
How can I get pybind11 to automatically cast this type to numpy array, the same way it already works for Eigen types (e.g., VectorXd, Ref, etc.)?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by locating pybind11's existing Eigen-to-NumPy conversion path and compare how it handles VectorXd and Ref with the shown derived class. Done means the derived Eigen vector or matrix class is automatically cast to a NumPy array without requiring a separate binding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, numpy
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100