Docstrings
EltypeExtensions._to_basetype — Method_to_basetype(T::Type, S::Type)Convert type S to have the basetype of T.
EltypeExtensions._to_eltype — Method_to_eltype(T, S)Convert type S to have the eltype of T. See also convert_eltype.
EltypeExtensions._to_precisiontype — Method_to_precisiontype(T::Type, S::Type)Convert type S to have the precisiontype of T. An exception is that if T<:Integer, then Rational will also be unwrapped.
Examples
julia> _to_precisiontype(Float64, Complex{Rational{Int}})
ComplexF64 (alias for Complex{Float64})
julia> _to_precisiontype(BigFloat, Matrix{Complex{Bool}})
Matrix{Complex{BigFloat}} (alias for Array{Complex{BigFloat}, 2})
julia> _to_precisiontype(Int, Complex{Rational{BigInt}})
Complex{Rational{Int64}}EltypeExtensions.basetype — Methodbasetype(T::Type)Recursively apply eltype to T until convergence.
Examples
julia> basetype(Matrix{BitArray})
Bool
julia> basetype(Vector{Set{Complex{Float64}}})
ComplexF64 (alias for Complex{Float64})
julia> basetype([1:n for n in 1:10])
Int64EltypeExtensions.convert_basetype — Methodconvert_basetype(T::Type, A)Similar to convert(T, A), but T refers to the basetype.
EltypeExtensions.convert_eltype — Methodconvert_eltype(T, A)Similar to convert(T, A), but T refers to the eltype. See also _to_eltype.
Examples
julia> convert_eltype(Float64, 1:10)
1.0:1.0:10.0
julia> typeof(convert_eltype(Float64, rand(Int, 3, 3)))
Matrix{Float64} (alias for Array{Float64, 2})EltypeExtensions.convert_precisiontype — Methodconvert_precisiontype(T::Type, A, prec)Convert A to have the precisiontype of T. prec is optional.
- When
Thas static precision (e.g.Float64),prechas no effect. - When
Thas dynamic precision (e.g.BigFloat),precspecifies the precision of conversion. Whenprecis not provided, the precision is decided by the external setup fromT. - When
Tis an integer, the conversion will dig intoRationalas well. In contrast, sinceRationalas a whole is more "precise" than an integer,precisiontypedoesn't unwrapRational.
Examples
julia> convert_precisiontype(BigFloat, 1//3+im, 128)
0.3333333333333333333333333333333333333338 + 1.0im
julia> convert_precisiontype(Float16, [[m/n for n in 1:3] for m in 1:3])
3-element Vector{Vector{Float16}}:
[1.0, 0.5, 0.3333]
[2.0, 1.0, 0.6665]
[3.0, 1.5, 1.0]EltypeExtensions.precisiontype — Methodprecisiontype(T::Type)Returns the type that decides the precision of T. The difference from basetype is that precisiontype unwraps composite basetypes such as Complex and that precisiontype is not generalised.
Examples
julia> precisiontype(Complex{Float32})
Float32
julia> precisiontype(Matrix{ComplexF64})
Float64