Skip to content
Merged
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 = "0.4.6"
version = "0.4.7"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
2 changes: 2 additions & 0 deletions src/ArrayLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ for Typ in (:LayoutArray, :(Transpose{<:Any,<:LayoutMatrix}), :(Adjoint{<:Any,<:
end

getindex(A::LayoutVector, kr::AbstractVector) = layout_getindex(A, kr)
getindex(A::LayoutVector, kr::Colon) = layout_getindex(A, kr)

_copyto!(_, _, dest::AbstractArray{T,N}, src::AbstractArray{V,N}) where {T,V,N} =
Base.invoke(copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src)
Expand All @@ -177,6 +178,7 @@ copyto!(dest::AbstractArray{<:Any,N}, src::SubArray{<:Any,N,<:LayoutArray}) wher
copyto!(dest::LayoutMatrix, src::AdjOrTrans{<:Any,<:LayoutArray}) = _copyto!(dest, src)
copyto!(dest::LayoutMatrix, src::SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutArray}}) = _copyto!(dest, src)
copyto!(dest::AbstractMatrix, src::AdjOrTrans{<:Any,<:LayoutArray}) = _copyto!(dest, src)
copyto!(dest::SubArray{<:Any,2,<:LayoutMatrix}, src::SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutArray}}) = _copyto!(dest, src)
copyto!(dest::AbstractMatrix, src::SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutArray}}) = _copyto!(dest, src)
# ambiguity from sparsematrix.jl
if VERSION ≥ v"1.5"
Expand Down
3 changes: 2 additions & 1 deletion src/ldiv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ getindex(L::Ldiv, k...) = _getindex(indextype(L), L, k)
concretize(L::AbstractArray) = convert(Array,L)
concretize(L::Ldiv) = ldiv(concretize(L.A), concretize(L.B))
_getindex(::Type{Tuple{I}}, L::Ldiv, (k,)::Tuple{I}) where I = concretize(L)[k]
_getindex(::Type{Tuple{I,J}}, L::Ldiv, (k,j)::Tuple{I,J}) where {I,J} = Ldiv(L.A, L.B[:,j])[k]
_getindex(::Type{Tuple{I,J}}, L::Ldiv, (k,j)::Tuple{Colon,J}) where {I,J} = Ldiv(L.A, L.B[:,j])
_getindex(::Type{Tuple{I,J}}, L::Ldiv, (k,j)::Tuple{I,J}) where {I,J} = L[:,j][k]

check_ldiv_axes(A, B) =
axes(A,1) == axes(B,1) || throw(DimensionMismatch("First axis of A, $(axes(A,1)), and first axis of B, $(axes(B,1)) must match"))
Expand Down
5 changes: 5 additions & 0 deletions src/mul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ macro layoutmul(Typ)
Base.:*(A::$Mod{<:Any,<:$Typ}, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
Base.:*(A::$Mod{<:Any,<:$Typ}, B::AbstractMatrix) = ArrayLayouts.mul(A,B)
Base.:*(A::AbstractMatrix, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
Base.:*(A::LinearAlgebra.AdjointAbsVec, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
Base.:*(A::LinearAlgebra.TransposeAbsVec, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
Base.:*(A::$Mod{<:Any,<:$Typ}, B::AbstractVector) = ArrayLayouts.mul(A,B)
Base.:*(A::$Mod{<:Any,<:$Typ}, B::ArrayLayouts.LayoutVector) = ArrayLayouts.mul(A,B)

Expand Down Expand Up @@ -242,6 +244,9 @@ dot(a, b) = materialize(Dot(a, b))
@inline LinearAlgebra.dot(a::LayoutArray, b::LayoutArray) = dot(a,b)
@inline LinearAlgebra.dot(a::LayoutArray, b::AbstractArray) = dot(a,b)
@inline LinearAlgebra.dot(a::AbstractArray, b::LayoutArray) = dot(a,b)
@inline LinearAlgebra.dot(a::LayoutArray{<:Number}, b::SparseArrays.SparseVectorUnion{<:Number}) = dot(a,b)
@inline LinearAlgebra.dot(a::SparseArrays.SparseVectorUnion{<:Number}, b::LayoutArray{<:Number}) = dot(a,b)

@inline LinearAlgebra.dot(a::SubArray{<:Any,N,<:LayoutArray}, b::AbstractArray) where N = dot(a,b)
@inline LinearAlgebra.dot(a::SubArray{<:Any,N,<:LayoutArray}, b::LayoutArray) where N = dot(a,b)
@inline LinearAlgebra.dot(a::AbstractArray, b::SubArray{<:Any,N,<:LayoutArray}) where N = dot(a,b)
Expand Down
41 changes: 27 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ArrayLayouts, Random, FillArrays, Test, Base64
using ArrayLayouts, Random, FillArrays, Test, SparseArrays, Base64
import ArrayLayouts: MemoryLayout, @_layoutlmul, triangulardata

Random.seed!(0)
Expand Down Expand Up @@ -32,22 +32,26 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
# These need to test dispatch reduces to ArrayLayouts.mul, etc.
@testset "LayoutArray" begin
@testset "LayoutVector" begin
A = MyVector([1.,2,3])
a = MyVector([1.,2,3])
B = randn(3,3)
b = randn(3)

@test A == A.A == Vector(A)
@test A[1:3] == A.A[1:3]
@test stringmime("text/plain", A) == "3-element MyVector:\n 1.0\n 2.0\n 3.0"
@test B*A ≈ B*A.A
@test B'*A ≈ B'*A.A
@test transpose(B)*A ≈ transpose(B)*A.A
@test b'A ≈ transpose(b)A ≈ A'b ≈ transpose(A)b ≈ b'A.A
@test qr(B).Q*A ≈ qr(B).Q*A.A

@test A'A == transpose(A)A == dot(A,A) == dot(A,A.A) == dot(A.A,A) == 14
v = view(A,1:3)
@test dot(v,A) == dot(v,A.A) == dot(A,v) == dot(A.A,v) == dot(v,v) == 14
@test a == a.A == Vector(a)
@test a[1:3] == a.A[1:3]
@test a[:] == a
@test stringmime("text/plain", a) == "3-element MyVector:\n 1.0\n 2.0\n 3.0"
@test B*a ≈ B*a.A
@test B'*a ≈ B'*a.A
@test transpose(B)*a ≈ transpose(B)*a.A
@test b'a ≈ transpose(b)a ≈ a'b ≈ transpose(a)b ≈ b'a.A
@test qr(B).Q*a ≈ qr(B).Q*a.A

@test a'a == transpose(a)a == dot(a,a) == dot(a,a.A) == dot(a.A,a) == 14
v = view(a,1:3)
@test dot(v,a) == dot(v,a.A) == dot(a,v) == dot(a.A,v) == dot(v,v) == 14

s = SparseVector(3, [1], [2])
@test a's == s'a == dot(a,s) == dot(s,a) == dot(s,a.A)
end

@testset "LayoutMatrix" begin
Expand All @@ -74,6 +78,8 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
@test copyto!(Array{Float64}(undef,5,5), A') == A'
@test copyto!(Array{Float64}(undef,5,5), view(A',:,:)) == A'

@test copyto!(view(MyMatrix(Array{Float64}(undef,5,5)),:,:), view(A',:,:)) == A'

@test qr(A).factors ≈ qr(A.A).factors
@test qr(A,Val(true)).factors ≈ qr(A.A,Val(true)).factors
@test lu(A).factors ≈ lu(A.A).factors
Expand Down Expand Up @@ -136,6 +142,13 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
b = randn(5)
@test dot(b, A, b) ≈ b'*(A*b) ≈ b'A*b
end

@testset "dual vector * symmetric (#40)" begin
A = randn(3,3)
x = rand(3)
@test x' * Symmetric(MyMatrix(A)) ≈ x'Symmetric(A)
@test transpose(x) * Symmetric(MyMatrix(A)) ≈ transpose(x)Symmetric(A)
end
end

@testset "l/rmul!" begin
Expand Down