You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/index.md
+17-17Lines changed: 17 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,19 @@ We note that this package has some overlap with [TypeUtils.jl](https://github.co
6
6
7
7
## Introduction
8
8
9
-
### `elconvert` and `_to_eltype`
10
-
`elconvert(T, x)` works like `convert(T, x)`, except that `T` refers to the eltype of the result. This can be useful for generic codes.
9
+
### `convert_eltype` and `_to_eltype`
10
+
`convert_eltype(T, x)` works like `convert(T, x)`, except that `T` refers to the eltype of the result. This can be useful for generic codes.
11
11
12
-
It should be always true that `elconvert(T, x) isa _to_eltype(T, typeof(x))`. However, since `elconvert` and `_to_eltype` use different routines, it's possible that the equality doesn't hold for some types. Please submit an issue or PR if that happens.
12
+
It should be always true that `convert_eltype(T, x) isa _to_eltype(T, typeof(x))`. However, since `convert_eltype` and `_to_eltype` use different routines, it's possible that the equality doesn't hold for some types. Please submit an issue or PR if that happens.
13
13
14
-
If `typeof(x)` is not in Base or stdlib, the package who owns the type should implement corresponding `_to_eltype` or `elconvert`. `elconvert` has fallbacks, in which case it could be unnecessary:
15
-
- For a subtype of `AbstractArray`, `elconvert` calls the constructor `AbstractArray{T}` and `_to_eltype` returns `Array`.
16
-
- For a subtype of `AbstractUnitRange`, `elconvert` calls the constructor `AbstractUnitRange{T}`.
17
-
- For a subtype of `AbstractRange`, `elconvert` uses broadcast through `map`.
18
-
- For a `Tuple`, `elconvert` uses dot broadcast.
19
-
- For other types, `elconvert` calls `convert` and `_to_eltype`.
14
+
If `typeof(x)` is not in Base or stdlib, the package who owns the type should implement corresponding `_to_eltype` or `convert_eltype`. `convert_eltype` has fallbacks, in which case it could be unnecessary:
15
+
- For a subtype of `AbstractArray`, `convert_eltype` calls the constructor `AbstractArray{T}` and `_to_eltype` returns `Array`.
16
+
- For a subtype of `AbstractUnitRange`, `convert_eltype` calls the constructor `AbstractUnitRange{T}`.
17
+
- For a subtype of `AbstractRange`, `convert_eltype` uses broadcast through `map`.
18
+
- For a `Tuple`, `convert_eltype` uses dot broadcast.
19
+
- For other types, `convert_eltype` calls `convert` and `_to_eltype`.
20
20
21
-
However, `_to_eltype` must be implemented for each type to support `baseconvert` and `precisionconvert`. The following types from Base and stdlib are explicitly supported by `_to_eltype`:
21
+
However, `_to_eltype` must be implemented for each type to support `convert_basetype` and `convert_precisiontype`. The following types from Base and stdlib are explicitly supported by `_to_eltype`:
-`sometype(x) = sometype(typeof(x))` is also provided for convenience.
39
39
-`_to_sometype(T,S)` converts the type `S` to have the `sometype` of `T`.
40
-
-`someconvert(T,A)` converts `A` to have the `sometype` of `T`.
40
+
-`convert_sometype(T,A)` converts `A` to have the `sometype` of `T`.
41
41
42
42
where `some` can be `el`, `base` and `precision`.
43
43
44
-
### On `precisionconvert`
45
-
`precisionconvert` accepts an optional third argument `prec`.
44
+
### On `convert_precisiontype`
45
+
`convert_precisiontype` accepts an optional third argument `prec`.
46
46
- When `T` has static precision, `prec` has no effect.
47
-
- When `T` has dynamic precision, `prec` specifies the precision of conversion. When `prec` is not provided, the precision is decided by the external setup from `T`. The difference is significant when `precisionconvert` is called by another function:
47
+
- When `T` has dynamic precision, `prec` specifies the precision of conversion. When `prec` is not provided, the precision is decided by the external setup from `T`. The difference is significant when `convert_precisiontype` is called by another function:
48
48
```@repl 1
49
49
precision(BigFloat)
50
-
f(x) = precisionconvert(BigFloat, x, 256)
51
-
g(x) = precisionconvert(BigFloat, x)
50
+
f(x) = convert_precisiontype(BigFloat, x, 256)
51
+
g(x) = convert_precisiontype(BigFloat, x)
52
52
setprecision(128)
53
53
f(π) # static precision
54
54
g(π) # precision varies with the global setting
55
55
```
56
56
- When `T` is an integer, the conversion will dig into `Rational` as well. In contrast, since `Rational` as a whole is more "precise" than an integer, `precisiontype` doesn't unwrap `Rational`.
elconvert(::Type{T}, A::S) where {T,S} =convert(_to_eltype(T, S), A)
42
-
elconvert(::Type{T}, A::AbstractArray) where T =convert(AbstractArray{T}, A)
43
-
elconvert(::Type{T}, A::AbstractRange) where T =map(T, A)
44
-
elconvert(::Type{T}, A::AbstractUnitRange) where T<:Integer=convert(AbstractUnitRange{T}, A)
45
-
elconvert(::Type{T}, A::Tuple) where T =convert.(T, A)
46
-
elconvert(::Type{T}, A::Set{T}) where T = A
47
-
elconvert(::Type{T}, A::Set) where T =Set(convert.(T, A))
41
+
convert_eltype(::Type{T}, A::S) where {T,S} =convert(_to_eltype(T, S), A)
42
+
convert_eltype(::Type{T}, A::AbstractArray) where T =convert(AbstractArray{T}, A)
43
+
convert_eltype(::Type{T}, A::AbstractRange) where T =map(T, A)
44
+
convert_eltype(::Type{T}, A::AbstractUnitRange) where T<:Integer=convert(AbstractUnitRange{T}, A)
45
+
convert_eltype(::Type{T}, A::Tuple) where T =convert.(T, A)
46
+
convert_eltype(::Type{T}, A::Set{T}) where T = A
47
+
convert_eltype(::Type{T}, A::Set) where T =Set(convert.(T, A))
48
48
49
49
"""
50
50
_to_eltype(T, S)
51
51
52
-
Convert type `S` to have the `eltype` of `T`. See also [`elconvert`](@ref).
52
+
Convert type `S` to have the `eltype` of `T`. See also [`convert_eltype`](@ref).
53
53
"""
54
54
_to_eltype(::Type{T}, ::Type{S}) where {T,S} =eltype(S) == S ? T :eltype(S) == T ? S :MethodError(_to_eltype, T, S)
55
55
_to_eltype(::Type{T}, ::Type{<:AbstractArray{S,N}}) where {T,S,N} = AbstractArray{T,N}
@@ -74,7 +74,7 @@ for TYP in (Adjoint, Diagonal, Hermitian, Symmetric, SymTridiagonal, Transpose)
74
74
@eval_to_eltype(::Type{T}, ::Type{$TYP}) where T =$TYP{T}
75
75
@eval_to_eltype(::Type{T}, ::Type{$TYP{S}}) where {T,S} =$TYP{T}
76
76
@eval_to_eltype(::Type{T}, ::Type{$TYP{S,M}}) where {T,S,M} =$TYP{T,_to_eltype(T,M)}
77
-
@evalelconvert(::Type{T}, A::S) where {T,S<:$TYP} =convert(_to_eltype(T, S), A)
77
+
@evalconvert_eltype(::Type{T}, A::S) where {T,S<:$TYP} =convert(_to_eltype(T, S), A)
78
78
end
79
79
80
80
@staticifVERSION>=v"1.6"
@@ -86,7 +86,6 @@ _to_eltype(::Type{T}, ::Type{<:CartesianIndices}) where T = Array{T}
86
86
87
87
@staticifVERSION>=v"1.7"
88
88
_to_eltype(::Type{T}, ::Type{<:StepRangeLen}) where T<:Real= StepRangeLen{T,_to_eltype(T,TwicePrecision),_to_eltype(T,TwicePrecision),Int}
89
-
90
89
else
91
90
_to_eltype(::Type{T}, ::Type{<:StepRangeLen}) where T<:Real= StepRangeLen{T,_to_eltype(T,TwicePrecision),_to_eltype(T,TwicePrecision)}
92
91
end
@@ -124,11 +123,11 @@ Convert type `S` to have the [`basetype`](@ref) of `T`.
124
123
_to_basetype(::Type{T}, ::Type{S}) where {T,S} =eltype(S) == S ? T :_to_eltype(_to_basetype(T, eltype(S)), S)
125
124
126
125
"""
127
-
baseconvert(T::Type, A)
126
+
convert_basetype(T::Type, A)
128
127
129
128
Similar to `convert(T, A)`, but `T` refers to the [`basetype`](@ref).
130
129
"""
131
-
baseconvert(::Type{T}, A::S) where {T,S} =convert(_to_basetype(T,S), A)
130
+
convert_basetype(::Type{T}, A::S) where {T,S} =convert(_to_basetype(T,S), A)
132
131
133
132
"""
134
133
precisiontype(T::Type)
@@ -172,30 +171,32 @@ _to_precisiontype(::Type{T}, ::Type{<:Rational}) where T<:Integer = Rational{T}
172
171
_to_precisiontype(::Type{T}, ::Type{S}) where {T,S} =eltype(S) == S ? T :_to_eltype(_to_precisiontype(T, eltype(S)), S)
173
172
174
173
"""
175
-
precisionconvert(T::Type, A, prec)
174
+
convert_precisiontype(T::Type, A, prec)
176
175
177
176
Convert `A` to have the [`precisiontype`](@ref) of `T`. `prec` is optional.
178
177
- When `T` has static precision (e.g. `Float64`), `prec` has no effect.
179
178
- When `T` has dynamic precision (e.g. `BigFloat`), `prec` specifies the precision of conversion. When `prec` is not provided, the precision is decided by the external setup from `T`.
180
179
- When `T` is an integer, the conversion will dig into `Rational` as well. In contrast, since `Rational` as a whole is more "precise" than an integer, [`precisiontype`](@ref) doesn't unwrap `Rational`.
0 commit comments