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

[BUG]: How to bind a c array within a class function #5044

Open
3 tasks done
Stoneplay opened this issue Mar 1, 2024 · 0 comments
Open
3 tasks done

[BUG]: How to bind a c array within a class function #5044

Stoneplay opened this issue Mar 1, 2024 · 0 comments
Labels
triage New bug, unverified

Comments

@Stoneplay
Copy link

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.11.1

Problem description

Due to the set_max_vel function of Engine class is not static function, so it will raise an error when I bind the the set_max_vel function like that. How to bind a c array which is in a function within a class?

Reproducible example code

// c++ code
#include <Eigen/Core>

class Engine: {
public:
    Engine();
    void set_max_vel(float *max_vel, int dof){
        max_velocity_.resize(dof);
	for (int i = 0; i < dof; i++){
            max_velocity_[i] = (double)max_vel[i];
	}
    }
private:
    Eigen::VectorXd max_velocity_;
}

// binding code
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>

namespace py = pybind11;

py::class_<Engine>(m, "Engine")
    .def(py::init<>())
    .def("set_max_vel", [](py::array_t<float> buffer, int dof) {
        py::buffer_info info = buffer.request();
	Engine::set_max_vel(static_cast<float*>(info.ptr), dof); });

Is this a regression? Put the last known working version here if it is.

Not a regression

@Stoneplay Stoneplay added the triage New bug, unverified label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

1 participant