Open hameerabbasi opened 5 months ago
The same change already happens in
tensor.py::638
:if dtype == np.bool_: # Fails with: Finch currently only supports isbits defaults dtype = bool
np.bool_
isn't accepted by Finch, only builtinbool
is fine.
Bool is certainly supported by Finch, it's fairly easy to confirm. If you're getting an error like Finch currently only supports isbits defaults
, that means that you are trying to construct a finch tensor full of heap-allocated objects. This points to a conversion from np.bool_ into something Julia or Finch isn't recognizing as a julia Bool.
One observation is that julia does seem to recognize a numpy array of bools.
>>> jl.println(jl.typeof(numpy.full((1,), numpy.True_)))
PyArray{Bool, 1, true, true, Bool}
some further investigation:
>>> jl.println(builtins.bool)
<class 'bool'>
>>> jl.println(numpy.bool_)
<class 'numpy.bool_'>
>>> jl.println(builtins.int)
<class 'int'>
>>> jl.println(numpy.int_)
<class 'numpy.int64'>
I don't spot the difference. I just think this is probably an artifact of PythonCall or a discrepancy between Python and Julia handling of Bool. Somewhere, the wrapper layer might not be converting a bool properly, or might not be able to.
Ah, here it is:
>>> jl.println(np.int_(1))
1
>>> jl.println(int(1))
1
>>> jl.println(np.True_)
fill(true)
>>> jl.println(True)
true
I am not sure why, but np.True_
converts to a scalar julia array containing true
, but True
converts to a julia Boolean true
. This appears to be the only case where this occurs.
>>> jl.println(jl.typeof(np.True_))
PyArray{Bool, 0, true, true, Bool}
I don't know why this conversion occurs, but it's related to the python/julia wrapper. Finch is just complaining because it doesn't like heap-allocated objects.
Can we report this upstream (perhaps to JuliaCall
)?
yeah, maybe we should report it.
@hameerabbasi @mtsokol They fixed it!
_Originally posted by @hameerabbasi in https://github.com/willow-ahrens/finch-tensor/pull/48#discussion_r1603510065_