From 87a9b7fc6afdf0e7c50ae6147ae96b316f4a1ccd Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Thu, 14 Mar 2024 12:23:15 +0000 Subject: [PATCH 1/5] using EltypeExtensions: elconvert --- Project.toml | 2 ++ src/FillArrays.jl | 1 + src/fillalgebra.jl | 5 ----- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index d980a8a5..5224d68a 100644 --- a/Project.toml +++ b/Project.toml @@ -3,6 +3,7 @@ uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" version = "1.10.0" [deps] +EltypeExtensions = "583f92f5-06d6-4306-8236-316410defc98" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" @@ -22,6 +23,7 @@ FillArraysStatisticsExt = "Statistics" Aqua = "0.8" Base64 = "1.6" Documenter = "1" +EltypeExtensions = "0.0.4" Infinities = "0.1" LinearAlgebra = "1.6" PDMats = "0.11.17" diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 581e8252..47ee973e 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -15,6 +15,7 @@ import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, import Base.Broadcast: broadcasted, DefaultArrayStyle, broadcast_shape, BroadcastStyle, Broadcasted +import EltypeExtensions: elconvert export Zeros, Ones, Fill, Eye, Trues, Falses, OneElement diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index ea454fdf..64605cd2 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -443,11 +443,6 @@ end a .+ getindex_value(b) end -# following needed since as of Julia v1.8 convert(AbstractArray{T}, ::AbstractRange) might return a Vector -@inline elconvert(::Type{T}, A::AbstractRange) where T = T(first(A)):T(step(A)):T(last(A)) -@inline elconvert(::Type{T}, A::AbstractUnitRange) where T<:Integer = AbstractUnitRange{T}(A) -@inline elconvert(::Type{T}, A::AbstractArray) where T = AbstractArray{T}(A) - #### # norm #### From b11d0d7a7708859107eeec575f4c9d8b39974669 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 22 Dec 2024 13:15:34 +0000 Subject: [PATCH 2/5] EltypeExtensions 0.1.0 --- Project.toml | 2 +- src/fillalgebra.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 589dd1de..c55ca2ae 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,7 @@ FillArraysStatisticsExt = "Statistics" [compat] Aqua = "0.8" Documenter = "1" -EltypeExtensions = "0.0.4" +EltypeExtensions = "0.1.0" Infinities = "0.1" LinearAlgebra = "1.6" PDMats = "0.11.17" diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 37d24ff5..3ade7b8a 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -434,14 +434,14 @@ Base.reduce_first(::typeof(+), x::AbstractOnes) = Fill(Base.reduce_first(+, geti function +(a::AbstractZeros{T}, b::AbstractZeros{V}) where {T, V} # for disambiguity promote_shape(a,b) - return elconvert(promote_op(+,T,V),a) + return convert_eltype(promote_op(+,T,V),a) end # no AbstractArray. Otherwise incompatible with StaticArrays.jl # AbstractFill for disambiguity for TYPE in (:Array, :AbstractFill, :AbstractRange, :Diagonal) @eval function +(a::$TYPE{T}, b::AbstractZeros{V}) where {T, V} promote_shape(a,b) - return elconvert(promote_op(+,T,V),a) + return convert_eltype(promote_op(+,T,V),a) end @eval +(a::AbstractZeros, b::$TYPE) = b + a end From 64146df7155ac6052efa0a367e6dee175ffc00cd Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Sun, 22 Dec 2024 13:36:56 +0000 Subject: [PATCH 3/5] fix --- src/FillArrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 0c69f02f..a49b76e2 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -15,7 +15,7 @@ import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, import Base.Broadcast: broadcasted, DefaultArrayStyle, broadcast_shape, BroadcastStyle, Broadcasted -import EltypeExtensions: elconvert +import EltypeExtensions: convert_eltype export Zeros, Ones, Fill, Eye, Trues, Falses, OneElement From 7415215a36a279e78b33a11fde424c61bdef4e52 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Mon, 23 Dec 2024 22:02:04 +0000 Subject: [PATCH 4/5] fix --- src/FillArrays.jl | 5 ++++- src/fillalgebra.jl | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index a49b76e2..ee875a11 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -15,7 +15,7 @@ import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, import Base.Broadcast: broadcasted, DefaultArrayStyle, broadcast_shape, BroadcastStyle, Broadcasted -import EltypeExtensions: convert_eltype +import EltypeExtensions: convert_eltype, _to_eltype export Zeros, Ones, Fill, Eye, Trues, Falses, OneElement @@ -138,6 +138,8 @@ Fill{T,0}(x, ::Tuple{}) where T = Fill{T,0,Tuple{}}(convert(T, x)::T, ()) # ambi """ `Fill(x, dims)` construct lazy version of `fill(x, dims)` """ @inline Fill(x::T, sz::Tuple{Vararg{Any,N}}) where {T, N} = Fill{T, N}(x, sz) +_to_eltype(::Type{T}, ::Type{Fill{V,N,Axes}}) where {T,V,N,Axes} = Fill{T,N,Axes} + # We restrict to when T is specified to avoid ambiguity with a Fill of a Fill @inline Fill{T}(F::Fill{T}) where T = F @inline Fill{T,N}(F::Fill{T,N}) where {T,N} = F @@ -341,6 +343,7 @@ for (AbsTyp, Typ, funcs, func) in ((:AbstractZeros, :Zeros, :zeros, :zero), (:Ab getindex(F::$AbsTyp{T,0}) where T = getindex_value(F) promote_rule(::Type{$Typ{T, N, Axes}}, ::Type{$Typ{V, N, Axes}}) where {T,V,N,Axes} = $Typ{promote_type(T,V),N,Axes} + _to_eltype(::Type{T}, ::Type{$Typ{V,N,Axes}}) where {T,V,N,Axes} = $Typ{T,N,Axes} function convert(::Type{Typ}, A::$AbsTyp{V,N,Axes}) where {T,V,N,Axes,Typ<:$AbsTyp{T,N,Axes}} convert(T, getindex_value(A)) # checks that the types are convertible Typ(axes(A)) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 3ade7b8a..2f42420c 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -441,7 +441,9 @@ end for TYPE in (:Array, :AbstractFill, :AbstractRange, :Diagonal) @eval function +(a::$TYPE{T}, b::AbstractZeros{V}) where {T, V} promote_shape(a,b) - return convert_eltype(promote_op(+,T,V),a) + ret = convert_eltype(promote_op(+,T,V), a) + ret ≡ a ? copy(ret) : ret # must return a copy + # (_to_eltype(promote_op(+,T,V), typeof(a)))(a) doesn't work for types not supporting such constructors. E.g. https://github.com/JuliaLang/LinearAlgebra.jl/pull/1158 end @eval +(a::AbstractZeros, b::$TYPE) = b + a end From 73373a08589fde2c2437cc794585a084fc258d1a Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Tue, 24 Dec 2024 15:03:05 +0000 Subject: [PATCH 5/5] fix --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c55ca2ae..2b68433d 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,7 @@ FillArraysStatisticsExt = "Statistics" [compat] Aqua = "0.8" Documenter = "1" -EltypeExtensions = "0.1.0" +EltypeExtensions = "0.1.1" Infinities = "0.1" LinearAlgebra = "1.6" PDMats = "0.11.17"