Quansight-Labs / numpy.net

A port of NumPy to .Net
BSD 3-Clause "New" or "Revised" License
128 stars 14 forks source link

np.frombuffer missing #41

Closed SimonCraenen closed 1 year ago

SimonCraenen commented 1 year ago

The np.frombuffer api appears to be missing.

I can use ndarray.tobytes to get a byte array but I can't find an api to go from a byte array back to an ndarray.

SimonCraenen commented 1 year ago

My current workaround looks like this:

ndarray a = np.ones((3, 3), dtype: np.Float32); var abytes = a.tobytes(NumpyLib.NPY_ORDER.NPY_CORDER); var afloatbytes = new float[abytes.Length / 4]; Buffer.BlockCopy(abytes, 0, afloatbytes, 0, abytes.Length); ndarray c = np.array(afloatbytes, order: NumpyLib.NPY_ORDER.NPY_CORDER, copy: false).reshape((3, 3));

KevinBaselinesw commented 1 year ago

My apologies. I did not get an email on this issue. I am just seeing it today after looking at open issues on this project Is this still an active problem for you?

SimonCraenen commented 1 year ago

My apologies as well for my late reply. The current workaround functions fine but it would be nice if it could be simplified with the np.frombuffer method to function similarly to how it would in python.

KevinBaselinesw commented 1 year ago

Good news. I went and implemented np.frombuffer shortly after that. It is in the latest release of numpydotnet.

thank you,

Kevin