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
.
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.baseconvert
— Methodbaseconvert(T::Type, A)
Similar to convert(T, A)
, but T
refers to the basetype
.
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])
Int64
EltypeExtensions.elconvert
— Methodelconvert(T, A)
Similar to convert(T, A)
, but T
refers to the eltype.
Examples
julia> elconvert(Float64, 1:10)
1.0:1.0:10.0
julia> typeof(elconvert(Float64, rand(Int, 3, 3)))
Matrix{Float64} (alias for Array{Float64, 2})
EltypeExtensions.precisionconvert
— Methodprecisionconvert(T::Type, A, prec)
Convert A
to have the precisiontype
of T
. prec
is optional.
- When
T
has static precision (e.g.Float64
),prec
has no effect. - When
T
has dynamic precision (e.g.BigFloat
),prec
specifies the precision of conversion. Whenprec
is not provided, the precision is decided by the external setup fromT
. - When
T
is an integer, the conversion will dig intoRational
as well. In contrast, sinceRational
as a whole is more "precise" than an integer,precisiontype
doesn't unwrapRational
.
Examples
julia> precisionconvert(BigFloat, 1//3+im, 128)
0.3333333333333333333333333333333333333338 + 1.0im
julia> precisionconvert(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