diff --git a/Project.toml b/Project.toml index d1fc06a..6236264 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ArrayLayouts" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" authors = ["Sheehan Olver "] -version = "1.1.1" +version = "1.2.0" [deps] FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" diff --git a/src/ldiv.jl b/src/ldiv.jl index 87b10b1..1710c23 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 diff --git a/src/lmul.jl b/src/lmul.jl index 37b938f..c6d4eb1 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