Skip to content

Abstract l/rmul and l/rdiv types #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
authors = ["Sheehan Olver <solver@mac.com>"]
version = "1.1.1"
version = "1.2.0"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
24 changes: 13 additions & 11 deletions src/ldiv.jl
Original file line number Diff line number Diff line change
@@ -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

37 changes: 21 additions & 16 deletions src/lmul.jl
Original file line number Diff line number Diff line change
@@ -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