fix: ->jvm on object-dtype numpy arrays with np-array bindings#288
Open
jsavyasachi wants to merge 1 commit into
Open
fix: ->jvm on object-dtype numpy arrays with np-array bindings#288jsavyasachi wants to merge 1 commit into
jsavyasachi wants to merge 1 commit into
Conversation
The np-array zero-copy bindings register a pyobject->jvm :ndarray method that always maps the numpy dtype to a native tensor datatype. Object and other non-numeric dtypes have no such mapping, so ->jvm threw "Unable to find datatype: object" once the bindings were loaded. Route non-numeric dtypes to the default element-wise copy conversion instead. Closes clj-python#187
17c00bf to
f68dc36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #187.
With the
libpython-clj2.python.np-arrayzero-copy bindings loaded,->jvmon an object-dtype array threwUnable to find datatype: object:Without the bindings it returns
[](the default sequence conversion).Cause: the
pyobject->jvm :ndarraymethod the bindings register always runsnumpy->desc->obj-dtype->dtype, which only maps numeric dtypes (int/uint/float). Object/str/datetime arrays hold python-object pointers, not a numeric native buffer, so they can't be zero-copied and have no mapping.Fix: only take the tensor path when the dtype is numeric; otherwise fall back to the default element-wise copy conversion (the same path used when the bindings aren't loaded).
Added a regression test to
numpy_test.clj(empty and mixed object arrays).