Skip to content

how to write c++ functions that accept numpy arrays with custom numeric types exposed via EigenPy #378

@ofloveandhate

Description

@ofloveandhate

I'm looking for a bit of help.

I have C++ functions that accept Eigen vectors and matrices. And those functions are exposed to Python via Boost.Python, as are my numeric types, and I have exposed Eigen containers of my numeric types via EigenPy. So I think this is an eigenpy question.

But I'm struggling to provide inter-operability between the Eigen vectors for C++ calls and numpy containers with dtype my custom numeric type.

Do you have examples in eigenpy or pinnochio of a C++ function accepting Eigen data, but which when exposed to Python accepts numpy?


super cut-down example code

// in C++
def foo(Eigen::Vector v){
}

foo(Eigen::Vector(blabla))
# in Python

foo(np.array( [N(1), N(2), N(3) ])

where N is my wrapped custom numeric type.

But the call in Python fails because the C++ function expects an Eigen container, but it's getting a numpy container.

My specific error message:

Traceback (most recent call last):
  File "/Users/amethyst/github_repos/b2/python/test/tracking/amptracking_test.py", line 133, in test_tracker_quad
    tracker.track_path(y_end, t_start, t_end, y_start);
Boost.Python.ArgumentError: Python argument types in
    AMPTracker.track_path(AMPTracker, numpy.ndarray, Complex, Complex, numpy.ndarray)
did not match C++ signature:
    track_path(bertini::tracking::AMPTracker {lvalue}, Eigen::Matrix<boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<0u>, (boost::multiprecision::expression_template_option)1>, -1, 1, 0, -1, 1> {lvalue} result, boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<0u>, (boost::multiprecision::expression_template_option)1> start_time, boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<0u>, (boost::multiprecision::expression_template_option)1> end_time, Eigen::Matrix<boost::multiprecision::number<boost::multiprecision::backends::mpc_complex_backend<0u>, (boost::multiprecision::expression_template_option)1>, -1, 1, 0, -1, 1> start_point)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions