Skip to content

Commit 3ad4aa4

Browse files
authored
More overloads for ambiguity (#41)
* More overloads for ambiguity * Fix #40 * Update runtests.jl * Update runtests.jl * Update ldiv.jl
1 parent 2f2c7ac commit 3ad4aa4

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.4.6"
4+
version = "0.4.7"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/ArrayLayouts.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ for Typ in (:LayoutArray, :(Transpose{<:Any,<:LayoutMatrix}), :(Adjoint{<:Any,<:
158158
end
159159

160160
getindex(A::LayoutVector, kr::AbstractVector) = layout_getindex(A, kr)
161+
getindex(A::LayoutVector, kr::Colon) = layout_getindex(A, kr)
161162

162163
_copyto!(_, _, dest::AbstractArray{T,N}, src::AbstractArray{V,N}) where {T,V,N} =
163164
Base.invoke(copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src)
@@ -177,6 +178,7 @@ copyto!(dest::AbstractArray{<:Any,N}, src::SubArray{<:Any,N,<:LayoutArray}) wher
177178
copyto!(dest::LayoutMatrix, src::AdjOrTrans{<:Any,<:LayoutArray}) = _copyto!(dest, src)
178179
copyto!(dest::LayoutMatrix, src::SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutArray}}) = _copyto!(dest, src)
179180
copyto!(dest::AbstractMatrix, src::AdjOrTrans{<:Any,<:LayoutArray}) = _copyto!(dest, src)
181+
copyto!(dest::SubArray{<:Any,2,<:LayoutMatrix}, src::SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutArray}}) = _copyto!(dest, src)
180182
copyto!(dest::AbstractMatrix, src::SubArray{<:Any,2,<:AdjOrTrans{<:Any,<:LayoutArray}}) = _copyto!(dest, src)
181183
# ambiguity from sparsematrix.jl
182184
if VERSION v"1.5"

src/ldiv.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ getindex(L::Ldiv, k...) = _getindex(indextype(L), L, k)
5050
concretize(L::AbstractArray) = convert(Array,L)
5151
concretize(L::Ldiv) = ldiv(concretize(L.A), concretize(L.B))
5252
_getindex(::Type{Tuple{I}}, L::Ldiv, (k,)::Tuple{I}) where I = concretize(L)[k]
53-
_getindex(::Type{Tuple{I,J}}, L::Ldiv, (k,j)::Tuple{I,J}) where {I,J} = Ldiv(L.A, L.B[:,j])[k]
53+
_getindex(::Type{Tuple{I,J}}, L::Ldiv, (k,j)::Tuple{Colon,J}) where {I,J} = Ldiv(L.A, L.B[:,j])
54+
_getindex(::Type{Tuple{I,J}}, L::Ldiv, (k,j)::Tuple{I,J}) where {I,J} = L[:,j][k]
5455

5556
check_ldiv_axes(A, B) =
5657
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"))

src/mul.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ macro layoutmul(Typ)
197197
Base.:*(A::$Mod{<:Any,<:$Typ}, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
198198
Base.:*(A::$Mod{<:Any,<:$Typ}, B::AbstractMatrix) = ArrayLayouts.mul(A,B)
199199
Base.:*(A::AbstractMatrix, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
200+
Base.:*(A::LinearAlgebra.AdjointAbsVec, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
201+
Base.:*(A::LinearAlgebra.TransposeAbsVec, B::$Mod{<:Any,<:$Typ}) = ArrayLayouts.mul(A,B)
200202
Base.:*(A::$Mod{<:Any,<:$Typ}, B::AbstractVector) = ArrayLayouts.mul(A,B)
201203
Base.:*(A::$Mod{<:Any,<:$Typ}, B::ArrayLayouts.LayoutVector) = ArrayLayouts.mul(A,B)
202204

@@ -242,6 +244,9 @@ dot(a, b) = materialize(Dot(a, b))
242244
@inline LinearAlgebra.dot(a::LayoutArray, b::LayoutArray) = dot(a,b)
243245
@inline LinearAlgebra.dot(a::LayoutArray, b::AbstractArray) = dot(a,b)
244246
@inline LinearAlgebra.dot(a::AbstractArray, b::LayoutArray) = dot(a,b)
247+
@inline LinearAlgebra.dot(a::LayoutArray{<:Number}, b::SparseArrays.SparseVectorUnion{<:Number}) = dot(a,b)
248+
@inline LinearAlgebra.dot(a::SparseArrays.SparseVectorUnion{<:Number}, b::LayoutArray{<:Number}) = dot(a,b)
249+
245250
@inline LinearAlgebra.dot(a::SubArray{<:Any,N,<:LayoutArray}, b::AbstractArray) where N = dot(a,b)
246251
@inline LinearAlgebra.dot(a::SubArray{<:Any,N,<:LayoutArray}, b::LayoutArray) where N = dot(a,b)
247252
@inline LinearAlgebra.dot(a::AbstractArray, b::SubArray{<:Any,N,<:LayoutArray}) where N = dot(a,b)

test/runtests.jl

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ArrayLayouts, Random, FillArrays, Test, Base64
1+
using ArrayLayouts, Random, FillArrays, Test, SparseArrays, Base64
22
import ArrayLayouts: MemoryLayout, @_layoutlmul, triangulardata
33

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

39-
@test A == A.A == Vector(A)
40-
@test A[1:3] == A.A[1:3]
41-
@test stringmime("text/plain", A) == "3-element MyVector:\n 1.0\n 2.0\n 3.0"
42-
@test B*A B*A.A
43-
@test B'*A B'*A.A
44-
@test transpose(B)*A transpose(B)*A.A
45-
@test b'A transpose(b)A A'b transpose(A)b b'A.A
46-
@test qr(B).Q*A qr(B).Q*A.A
47-
48-
@test A'A == transpose(A)A == dot(A,A) == dot(A,A.A) == dot(A.A,A) == 14
49-
v = view(A,1:3)
50-
@test dot(v,A) == dot(v,A.A) == dot(A,v) == dot(A.A,v) == dot(v,v) == 14
39+
@test a == a.A == Vector(a)
40+
@test a[1:3] == a.A[1:3]
41+
@test a[:] == a
42+
@test stringmime("text/plain", a) == "3-element MyVector:\n 1.0\n 2.0\n 3.0"
43+
@test B*a B*a.A
44+
@test B'*a B'*a.A
45+
@test transpose(B)*a transpose(B)*a.A
46+
@test b'a transpose(b)a a'b transpose(a)b b'a.A
47+
@test qr(B).Q*a qr(B).Q*a.A
48+
49+
@test a'a == transpose(a)a == dot(a,a) == dot(a,a.A) == dot(a.A,a) == 14
50+
v = view(a,1:3)
51+
@test dot(v,a) == dot(v,a.A) == dot(a,v) == dot(a.A,v) == dot(v,v) == 14
52+
53+
s = SparseVector(3, [1], [2])
54+
@test a's == s'a == dot(a,s) == dot(s,a) == dot(s,a.A)
5155
end
5256

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

81+
@test copyto!(view(MyMatrix(Array{Float64}(undef,5,5)),:,:), view(A',:,:)) == A'
82+
7783
@test qr(A).factors qr(A.A).factors
7884
@test qr(A,Val(true)).factors qr(A.A,Val(true)).factors
7985
@test lu(A).factors lu(A.A).factors
@@ -136,6 +142,13 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
136142
b = randn(5)
137143
@test dot(b, A, b) b'*(A*b) b'A*b
138144
end
145+
146+
@testset "dual vector * symmetric (#40)" begin
147+
A = randn(3,3)
148+
x = rand(3)
149+
@test x' * Symmetric(MyMatrix(A)) x'Symmetric(A)
150+
@test transpose(x) * Symmetric(MyMatrix(A)) transpose(x)Symmetric(A)
151+
end
139152
end
140153

141154
@testset "l/rmul!" begin

0 commit comments

Comments
 (0)