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

typed arrays to numpy #104

Open
crackwitz opened this issue Mar 31, 2024 · 2 comments
Open

typed arrays to numpy #104

crackwitz opened this issue Mar 31, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@crackwitz
Copy link

crackwitz commented Mar 31, 2024

I was just trying to generate some numbers, stick them into a new Float64Array(N), and return them to Python.

To my surprise, the returned object wasn't even a list. I can't index into it, result[0] just fails:

ArgumentError: Python argument types in
    JSObject.__getitem__(JSObject, int)
did not match C++ signature:
    __getitem__(class CJavascriptObject {lvalue}, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)

But result["0"] does work... That expression on a normal javascript list fails, rightfully, with TypeError: list indices must be integers.

dir(result) showed me [0, 1, 2, ..., N-1], i.e. the dir() returned a list of numbers, which is extremely odd because dir() on any other python object always returns a bunch of strings, which represent the methods of that object.

Calling np.asarray() on a regular (javascript) list object actually gives me something sensible, but calling it on this object just results in a numpy array of dtype=object, which is not useful. It does not appear to support iter() and next(). The regular javascript list does support those.

I think it'd be great to be able to use typed arrays.

If complete numpy adaptation is too complicated, I'd be happy to get something that presents buffer access at least. The less data to copy, the better.

@buffer buffer self-assigned this Apr 16, 2024
@buffer buffer added the enhancement New feature or request label Apr 16, 2024
@buffer
Copy link
Collaborator

buffer commented Apr 16, 2024

When I started porting PyV8, it did not use to provide support for TypedArrays. And that is reasonably the reason behind this misbehaving. The wrapper is not aware of the existence of such data type(s) and wraps to a generic object. Which is what you are seeing in your tests. Adding this support has always been in my TODO list but never did that for lack of time. I'll try to spend some cycles on that as soon as possible. Thanks for your patience.

@buffer buffer added the help wanted Extra attention is needed label Apr 16, 2024
@crackwitz
Copy link
Author

Oh don't worry. I just thought to mention this. It's a very useful project and served me well already. I did eventually fill a regular list... or several. I had to do my calculations in chunks because too big a list will just crash the Jupyter kernel (no python-level exceptions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants