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

np.array type returned from np.frombuffer throws incompatible function argument exception #340

Closed
traplordpanda opened this issue Oct 25, 2023 · 2 comments

Comments

@traplordpanda
Copy link

example.

#include <cstdio>
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>

NB_MODULE(py_ext, m) {
    m.def("inspect", [](nb::ndarray<> a) {
    printf("Array data pointer : %p\n", a.data());});
}
import py_ext
import numpy as np
data = b'abc'
data2 = np.frombuffer(data, dtype=np.uint8) #, dtype=np.int8)
py_ext.inspect(data2)
Traceback (most recent call last):
  File "/home/kyle/code/md5bind/test.py", line 5, in <module>
    py_ext.inspect(data2)
TypeError: inspect(): incompatible function arguments. The following argument types are supported:
    1. inspect(arg: ndarray[], /) -> None

Invoked with types: ndarray
@wjakob
Copy link
Owner

wjakob commented Oct 25, 2023

Can you give your nb::ndarray a nb::ro attribute? By default, nanobind wants to make an array with read/write access.

@traplordpanda
Copy link
Author

That fixed the issue, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants