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
One of the nice things with making a Python wrapper to (clean) C++ code is that any data that lies evenly spaced contiguous in memory can be hooked into the numpy interface for advanced construction, slicing, dicing and lots of manipulation.
I've completed an interface for it for the Amount class now that I am happy with which then utilizes the protocol both for conversion to and from numpy.
To be able to do this, I needed:
meta-information about the data like type, shape, padding, strides, etc.
a pointer to the first element of the data.
For the most part, (1) is solvable on my end, at least for the structures that I have looked at so far. But (2) requires code changes.
What I need for Amount and proably a few classes is ways to get the pointer to the underlying data.
For the current implementation of Amount in amount.h I've just added:
Capacity* get_data(){
return elems.data();
}
And that is it. I can do my magic.
Does this sound like a reasonable plan?
The text was updated successfully, but these errors were encountered:
It looks like the kind of stuff we can definitely live with if it helps downstream for the python bindings.
If we start adding stuff that is not used internally at all, my only concern is that we loose track of the reason they're here in the first place (and maybe remove them by mistake later on). So maybe we should add comments to this end.
Another option would be to place those behind a compilation flag, pretty much like what we currently do with USE_LIBOSRM. In that case the behavior would be totally unchanged when running make, but you'd get everything you need by running something like make -D PYTHON_BINDINGS.
One of the nice things with making a Python wrapper to (clean) C++ code is that any data that lies evenly spaced contiguous in memory can be hooked into the numpy interface for advanced construction, slicing, dicing and lots of manipulation.
I've completed an interface for it for the
Amount
class now that I am happy with which then utilizes the protocol both for conversion to and from numpy.To be able to do this, I needed:
For the most part, (1) is solvable on my end, at least for the structures that I have looked at so far. But (2) requires code changes.
What I need for
Amount
and proably a few classes is ways to get the pointer to the underlying data.For the current implementation of
Amount
inamount.h
I've just added:And that is it. I can do my magic.
Does this sound like a reasonable plan?
The text was updated successfully, but these errors were encountered: