PyCall numpy vdot Vector{Float32} returns Float64

That’s just the automatic conversion, which doesn’t know about numpy scalars. It’s still actually doing the single precision calculation, as you can see if you tell PyCall to not automatically convert the result to a Julia type:

julia> pycall(np.vdot, PyObject, x, y)
PyObject 70.0

julia> pycall(np.vdot, PyObject, x, y).dtype
PyObject dtype('float32')

If you care about the Julia type being Float32, you can do pycall(np.vdot, Float32, x, y).

Alternatively, you can use PythonCall.jl, which never automatically converts the results — you have to convert things to native Julia types manually.

4 Likes