JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
715 stars 61 forks source link

data-type specific Julia scalars with JuliaCall #504

Closed mtsokol closed 3 weeks ago

mtsokol commented 1 month ago

Affects: JuliaCall

Describe the bug

I would like to create Julia scalars by calling appropriate data-types (Int8, Int16, etc.), but instead calling specific dtypes just give python builtins (e.g. int for any integer julia dtype). Or is there another way to instantiate them?

from juliacall import Main as jl
import numpy as np

a1 = jl.Int8(0)
type(a1)  # it's just int

a2 = np.int8(0)
type(a2)  # it's numpy.int8

Your system Please provide detailed information about your system:

In [80]: juliacall.__version__
Out[80]: '0.9.19'
JuliaPkg Status
/Users/.../Library/Caches/pypoetry/virtualenvs/finch-tensor-iqiMydcW-py3.10/julia_env/pyjuliapkg/juliapkg.json
Julia 1.10.0 @ /Users/.../.julia/juliaup/julia-1.10.0+0.x64.apple.darwin14/bin/julia
Packages:
  Finch: {'uuid': '9177782c-1635-4eb9-9bfb-d9dfa25e6bce', 'version': '0.6.30'}
cjdoris commented 1 month ago

This is due to how values are converted between Python and Julia.

You can do juliacall.convert(jl.Int8, 0) to get an int-like value which wraps the underlying Julia Int8 value. Some of this should be a bit slicker in v1 but that won't be out for a while...

mtsokol commented 3 weeks ago

Thank you for the clarification!