You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the function takes a default value in its arguments, it needs to be specified with py::arg. For example of Vector constructor,
// Constructor
.def(py::init([](py::array_t<double> vec, bool distributed, bool copy_data = true) {
py::buffer_info buf_info = vec.request();
int dim = buf_info.shape[0];
double* data = static_cast<double*>(buf_info.ptr);
return new Vector(data, dim, distributed, copy_data);
}), py::arg("vec"), py::arg("distributed"), py::arg("copy_data") = true) // default value needs to be defined here.
Note the last line.
Vector::getData not returning an array object
In c++, getData function returns the memory address of the data array. In python, this should return the reference of the data array. Currently, Vector::getData does not do any special care, returning a float value as a result.
.def("getData", &Vector::getData)
Vector::get_data naming
Compared to the function above, this function can cause a confusion. Based on its action, it needs to be renamed as copy_data or something.
(Enhancement) Vector and Matrix as a buffer protocol
Vector and Matrix should support buffer view, to handler large-size arrays without copying them in memory. Useful references are:
Default values not properly declaredIf the function takes a default value in its arguments, it needs to be specified with
py::arg
. For example ofVector
constructor,Note the last line.
Vector::getData
not returning an array objectIn c++,
getData
function returns the memory address of the data array. In python, this should return the reference of the data array. Currently,Vector::getData
does not do any special care, returning afloat
value as a result.Vector::get_data
namingCompared to the function above, this function can cause a confusion. Based on its action, it needs to be renamed as
copy_data
or something.(Enhancement)Vector
andMatrix
as a buffer protocolVector
andMatrix
should support buffer view, to handler large-size arrays without copying them in memory. Useful references are:Based on pybind11 numpy instruction, an example of
Matrix
definition should be:Similar definition is possible for
Vector
as well.(Enhancement) Supporting slice view of
Vector
andMatrix
Vector
andMatrix
must support slice view of its data.The text was updated successfully, but these errors were encountered: