Skip to content

Commit

Permalink
Merge pull request #14 from putianyi889/version-0.0.4.2
Browse files Browse the repository at this point in the history
use convert instead of constructor
  • Loading branch information
putianyi889 authored Mar 16, 2024
2 parents 9df643f + 83f532d commit bedc869
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/EltypeExtensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ julia> typeof(elconvert(Float64, rand(Int, 3, 3)))
$(repr("text/plain", Matrix{Float64}))
```
"""
elconvert(::Type{T}, A::AbstractArray) where T = AbstractArray{T}(A)
elconvert(::Type{T}, A::AbstractRange) where T = T(first(A)):T(step(A)):T(last(A))
elconvert(::Type{T}, A::AbstractUnitRange) where T<:Integer = AbstractUnitRange{T}(A)
elconvert(::Type{T}, A::AbstractSet) where T = AbstractSet{T}(A)
elconvert(::Type{T}, A::S) where {T,S} = eltype(S) == S ? convert(T, A) : throw(MethodError(elconvert, T, A))
elconvert(::Type{T}, A::AbstractArray) where T = convert(AbstractArray{T}, A)
elconvert(::Type{T}, A::AbstractRange) where T = map(T, A)
elconvert(::Type{T}, A::AbstractUnitRange) where T<:Integer = convert(AbstractUnitRange{T}, A)
elconvert(::Type{T}, A::Set) where T = convert(Set{T}, A)
if !(AbstractQ <: AbstractMatrix) # see https://github.com/JuliaLang/julia/pull/46196
elconvert(::Type{T}, A::AbstractQ) where T = convert(AbstractQ{T}, A)
end
Expand Down

0 comments on commit bedc869

Please sign in to comment.