From 1e06d362e0f3429652ff2bfeffc43fc8867ed4e2 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 13 Jun 2023 10:41:53 +0530 Subject: [PATCH 1/3] Abstract l/rmul and l/rdiv types --- src/ldiv.jl | 26 ++++++++++++++------------ src/lmul.jl | 37 +++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/ldiv.jl b/src/ldiv.jl index c1e20f4..c560415 100644 --- a/src/ldiv.jl +++ b/src/ldiv.jl @@ -1,6 +1,18 @@ +abstract type AbstractLRDiv{AType, BType} end + +@inline BroadcastStyle(::Type{<:AbstractLRDiv}) = ApplyBroadcastStyle() +@inline broadcastable(M::AbstractLRDiv) = M + +similar(A::AbstractLRDiv, ::Type{T}, axes) where T = similar(Array{T}, axes) +similar(A::AbstractLRDiv, ::Type{T}) where T = similar(A, T, axes(A)) +similar(A::AbstractLRDiv) = similar(A, eltype(A)) + +@inline copy(M::AbstractLRDiv; kwds...) = copyto!(similar(M), M; kwds...) +@inline materialize(M::AbstractLRDiv; kwds...) = copy(instantiate(M); kwds...) + for Typ in (:Ldiv, :Rdiv) @eval begin - struct $Typ{StyleA, StyleB, AType, BType} + struct $Typ{StyleA, StyleB, AType, BType} <: AbstractLRDiv{AType, BType} A::AType B::BType end @@ -10,16 +22,6 @@ for Typ in (:Ldiv, :Rdiv) @inline $Typ(A::AType, B::BType) where {AType,BType} = $Typ{typeof(MemoryLayout(AType)),typeof(MemoryLayout(BType)),AType,BType}(A, B) - - @inline BroadcastStyle(::Type{<:$Typ}) = ApplyBroadcastStyle() - @inline broadcastable(M::$Typ) = M - - similar(A::$Typ, ::Type{T}, axes) where T = similar(Array{T}, axes) - similar(A::$Typ, ::Type{T}) where T = similar(A, T, axes(A)) - similar(A::$Typ) = similar(A, eltype(A)) - - @inline copy(M::$Typ; kwds...) = copyto!(similar(M), M; kwds...) - @inline materialize(M::$Typ; kwds...) = copy(instantiate(M); kwds...) end end @@ -203,4 +205,4 @@ macro layoutldiv(Typ) end) end -@_layoutldiv LayoutVector \ No newline at end of file +@_layoutldiv LayoutVector diff --git a/src/lmul.jl b/src/lmul.jl index 512c65c..54fe124 100644 --- a/src/lmul.jl +++ b/src/lmul.jl @@ -1,27 +1,32 @@ +abstract type AbstractLRMul{TypeA, TypeB} end + +BroadcastStyle(::Type{<:AbstractLRMul}) = ApplyBroadcastStyle() +broadcastable(M::AbstractLRMul) = M + +size(M::AbstractLRMul) = map(length,axes(M)) +size(M::AbstractLRMul, p::Int) = size(M)[p] +length(M::AbstractLRMul) = prod(size(M)) +axes(M::AbstractLRMul) = (axes(M.A,1),axes(M.B,2)) +axes(M::AbstractLRMul, p::Int) = axes(M)[p] + +eltype(::AbstractLRMul{A,B}) where {A,B} = promote_type(eltype(A), eltype(B)) + +similar(M::AbstractLRMul, ::Type{T}, axes) where {T} = similar(Array{T}, axes) +similar(M::AbstractLRMul, ::Type{T}) where T = similar(M, T, axes(M)) +similar(M::AbstractLRMul) = similar(M, eltype(M)) + for Typ in (:Lmul, :Rmul) @eval begin - struct $Typ{StyleA, StyleB, TypeA, TypeB} + struct $Typ{StyleA, StyleB, TypeA, TypeB} <: AbstractLRMul{TypeA, TypeB} A::TypeA B::TypeB end - $Typ(A::TypeA, B::TypeB) where {TypeA,TypeB} = $Typ{typeof(MemoryLayout(TypeA)),typeof(MemoryLayout(TypeB)),TypeA,TypeB}(A,B) + function $Typ(A::TypeA, B::TypeB) where {TypeA,TypeB} + $Typ{typeof(MemoryLayout(TypeA)),typeof(MemoryLayout(TypeB)),TypeA,TypeB}(A,B) + end $Typ(M::Mul) = $Typ(M.A, M.B) - - BroadcastStyle(::Type{<:$Typ}) = ApplyBroadcastStyle() - broadcastable(M::$Typ) = M - - eltype(::$Typ{<:Any,<:Any,A,B}) where {A,B} = promote_type(eltype(A), eltype(B)) - size(M::$Typ, p::Int) = size(M)[p] - axes(M::$Typ, p::Int) = axes(M)[p] - length(M::$Typ) = prod(size(M)) - size(M::$Typ) = map(length,axes(M)) - axes(M::$Typ) = (axes(M.A,1),axes(M.B,2)) - - similar(M::$Typ, ::Type{T}, axes) where {T} = similar(Array{T}, axes) - similar(M::$Typ, ::Type{T}) where T = similar(M, T, axes(M)) - similar(M::$Typ) = similar(M, eltype(M)) end end From f0dd7f3596c1151229b4501a93740202582a4e51 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 13 Jun 2023 11:22:11 +0530 Subject: [PATCH 2/3] bump version to v1.0.6 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1008177..1b8f50a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ArrayLayouts" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" authors = ["Sheehan Olver "] -version = "1.0.5" +version = "1.0.6" [deps] FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" From 2d158061881f011895dbed84a12163317b4c9d98 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 13 Jun 2023 11:23:03 +0530 Subject: [PATCH 3/3] change version to v1.1.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1b8f50a..794a5c3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ArrayLayouts" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" authors = ["Sheehan Olver "] -version = "1.0.6" +version = "1.1.0" [deps] FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"