Skip to content
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

Abstract l/rmul and l/rdiv types #137

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 <[email protected]>"]
version = "1.1.1"
version = "1.2.0"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
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

Check warning on line 4 in src/ldiv.jl

View check run for this annotation

Codecov / codecov/patch

src/ldiv.jl#L3-L4

Added lines #L3 - L4 were not covered by tests

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))

Check warning on line 8 in src/ldiv.jl

View check run for this annotation

Codecov / codecov/patch

src/ldiv.jl#L6-L8

Added lines #L6 - L8 were not covered by tests

@inline copy(M::AbstractLRDiv; kwds...) = copyto!(similar(M), M; kwds...)
@inline materialize(M::AbstractLRDiv; kwds...) = copy(instantiate(M); kwds...)

Check warning on line 11 in src/ldiv.jl

View check run for this annotation

Codecov / codecov/patch

src/ldiv.jl#L10-L11

Added lines #L10 - L11 were not covered by tests

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
Expand All @@ -10,16 +22,6 @@

@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

Expand Down Expand Up @@ -157,7 +159,7 @@
LinearAlgebra.rdiv!(A::AbstractMatrix, B::$Typ; kwds...) = ArrayLayouts.rdiv!(A,B; kwds...)

# Fix ambiguity issue
LinearAlgebra.rdiv!(A::StridedMatrix, B::$Typ; kwds...) = ArrayLayouts.rdiv!(A,B; kwds...)

Check warning on line 162 in src/ldiv.jl

View check run for this annotation

Codecov / codecov/patch

src/ldiv.jl#L162

Added line #L162 was not covered by tests

(\)(A::$Typ, x::AbstractVector; kwds...) = ArrayLayouts.ldiv(A,x; kwds...)
(\)(A::$Typ, x::AbstractMatrix; kwds...) = ArrayLayouts.ldiv(A,x; kwds...)
Expand Down
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

Check warning on line 4 in src/lmul.jl

View check run for this annotation

Codecov / codecov/patch

src/lmul.jl#L3-L4

Added lines #L3 - L4 were not covered by tests

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]

Check warning on line 10 in src/lmul.jl

View check run for this annotation

Codecov / codecov/patch

src/lmul.jl#L6-L10

Added lines #L6 - L10 were not covered by tests

eltype(::AbstractLRMul{A,B}) where {A,B} = promote_type(eltype(A), eltype(B))

Check warning on line 12 in src/lmul.jl

View check run for this annotation

Codecov / codecov/patch

src/lmul.jl#L12

Added line #L12 was not covered by tests

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))

Check warning on line 16 in src/lmul.jl

View check run for this annotation

Codecov / codecov/patch

src/lmul.jl#L14-L16

Added lines #L14 - L16 were not covered by tests

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)

Check warning on line 26 in src/lmul.jl

View check run for this annotation

Codecov / codecov/patch

src/lmul.jl#L25-L26

Added lines #L25 - L26 were not covered by tests
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

Expand Down