Hello
I am a bit confuse as to how precision is assigned or indicated in Julia.
Consider:
julia> a = Complex(1.0, 0.0)
1.0 + 0.0im
julia> typeof(a)
ComplexF64
So by default a Complex number will be built with Float64 elements.
However depending on how I create a matrix of complex numbers the precision is different.
Case1: starting with an undef matrix
julia> b = Matrix{Complex}(undef, 2,2)
2×2 Matrix{Complex}:
#undef #undef
#undef #undef
julia> b[1,1] = 1.0+0.0im
1.0 + 0.0im
julia> b[1,2] = 0.0+0.0im
0.0 + 0.0im
julia> b[2,1] = 0.0+0.0im
0.0 + 0.0im
julia> b[2,2] = 1.0+0.0im
1.0 + 0.0im
julia> b
2x2 Matrix{Complex}:
1.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
julia> typeof(b)
Matrix{Complex} (alias for Array{Complex, 2})
Case2 : I create the matrix with numbers
julia> a = [Complex(1.0,0.0) Complex(0.0,0.0) ; complex(0.0,0.0) Complex(1.0,0.0) ]
2×2 Matrix{ComplexF64}:
1.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
julia> typeof(a)
Matrix{ComplexF64} (alias for Array{Complex{Float64}, 2})
So, with a scalar Julia will give me a 64 bits version whereas a matrix will be different. Is that not incoherent? Am I missing something?
If I see a function having as argument a Matrix{Complex}
I have to be careful in the way I create the matrix I will be using since it may end up being Matrix{ComplexF64}
and vise versa.
The behavior seems to be different with integers. Int64 is used all the time.
julia> c = Matrix{Int}(undef, 2,2)
2×2 Matrix{Int64}:
1473840714320 1473840714384
1473840714352 1473840714416
BTW, why do I not get #undef
in this case as I got with Matrix{Complex}(undef, 2,2)
?
I am using Julia 1.8.4 on Windows10
Thanks for your help clarifying how types are assigned in Julia.