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

Implements Python vectorize API test. #2006

Merged
merged 1 commit into from
Apr 15, 2024
Merged

Conversation

dom96
Copy link
Collaborator

@dom96 dom96 commented Apr 11, 2024

No description provided.

@dom96 dom96 requested review from a team as code owners April 11, 2024 09:35
Comment on lines +19 to +23
results = await IDX.query(Float32Array.new(res_array), to_js({
"topK": 3,
"returnValues": True,
"returnMetadata": True,
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
results = await IDX.query(Float32Array.new(res_array), to_js({
"topK": 3,
"returnValues": True,
"returnMetadata": True,
}))
results = await IDX.query(Float32Array.new(res_array),
topK=3,
returnValues=True,
returnMetadata=True)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Float32Array.new(res_array) copies res_array. The method then writes the data to this copy and then we throw away the results. If you wanted to get the results written into a Python-accessible location you have to do something like:

from array import array
from pyodide.ffi import create_proxy

pyarray = array("f", [0]*5)
px = create_proxy(pyarray)
buf = px.getBuffer()
await IDX.query(buf.data, ...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method doesn't write into that array, it's only an input.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting.

@dom96 dom96 merged commit 436b5d7 into main Apr 15, 2024
10 checks passed
@dom96 dom96 deleted the dominik/python-vectorize-test branch April 15, 2024 14:54
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

Successfully merging this pull request may close these issues.

None yet

2 participants