ovalhub commented on issue #10665: URL: https://github.com/apache/lucene/issues/10665#issuecomment-1297463120
On Mon, 31 Oct 2022, Benjamin Trent wrote: > @ovalhub `numpy` collections are already native. To use them, I have to > pull them into python collections and then cast them to be native again. > > Example: ``` X = X.tolist() doc.add(KnnVectorField("knn", > JArray('float')(X), fieldType)) ``` The `.toList()` is weird to me as `X` > is already a natively backed float array, just a numpy object. > > Admittedly, I may be misunderstanding how the communication between Python > -> `native` -> Java is done. But it SEEMS that calling `tolist` for numpy > unnecessarily pulls an already native collection into a generic python > list. When you make a JArray with "JArray('float')(X), fieldType))" the JArray<float> code in JCC's JArray.h will iterate 'X' "as a sequence", calling PySequence_GetItem(sequence, i) and fill a Java float array with the values returned. If native numpy collections are exposed to Python as sequences (ie, ordered things that can be accessed with int indexes), then you should not have to call .tolist() on it before using it with PyLucene/JCC. It could also be that numpy's .tolist() just creates a wrapper object around the native array to expose it as a Python sequence ? (I don't know numpy). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org