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,6 +1,6 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "1.15"
version = "1.15.1"
authors = ["Sheehan Olver <solver@mac.com>"]

[deps]
Expand Down
17 changes: 17 additions & 0 deletions ext/ArrayLayoutsSparseArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using SparseArrays
# Specifying the full namespace is necessary because of https://github.com/JuliaLang/julia/issues/48533
# See https://github.com/JuliaStats/LogExpFunctions.jl/pull/63
import ArrayLayouts.LinearAlgebra
using ArrayLayouts.LinearAlgebra: Adjoint, Transpose, Symmetric, Hermitian, Diagonal, UpperTriangular, UnitUpperTriangular, LowerTriangular, UnitLowerTriangular

import Base: copyto!, ==

Expand All @@ -23,6 +24,22 @@ copyto!(dest::SubArray{<:Any,2,<:LayoutMatrix}, src::SparseArrays.AbstractSparse
ArrayLayouts.dot(a,b)


# ambiguity between \ for sparse matrices and the layout overloads of \ (see @layoutldiv).
# SparseArrays' solvers need strided right-hand sides, so convert to Array.
# Symmetric/Hermitian are included since CHOLMOD does not support ldiv! with other arrays.
const LayoutLdivRHS = Any[:LayoutVector, :LayoutMatrix]
for Tri in (:UpperTriangular, :UnitUpperTriangular, :LowerTriangular, :UnitLowerTriangular),
Par in (:(LayoutMatrix{T}), :(SubArray{T,2,<:LayoutMatrix{T}}), :(Adjoint{T,<:LayoutMatrix{T}}), :(Transpose{T,<:LayoutMatrix{T}}))
push!(LayoutLdivRHS, :($Tri{T,<:$Par} where T))
end
for Sp in (:(SparseArrays.AbstractSparseMatrixCSC),
:(Adjoint{<:Any,<:SparseArrays.AbstractSparseMatrixCSC}), :(Transpose{<:Any,<:SparseArrays.AbstractSparseMatrixCSC}),
:(Symmetric{<:Any,<:SparseArrays.AbstractSparseMatrixCSC}), :(Hermitian{<:Any,<:SparseArrays.AbstractSparseMatrixCSC})),
Typ in LayoutLdivRHS
@eval Base.:\(A::$Sp, B::$Typ) = A \ convert(Array, B)
Typ === :LayoutVector && @eval Base.:\(A::$Sp, B::Diagonal{<:Any,<:LayoutVector}) = A \ Diagonal(convert(Array, B.diag))
end

# ambiguity from SparseArrays.ReadOnly
if isdefined(SparseArrays, :ReadOnly)
==(A::SparseArrays.ReadOnly, B::LayoutVector) = equals_layout(A, B)
Expand Down
12 changes: 12 additions & 0 deletions test/test_layoutarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,18 @@ BroadcastStyle(::Type{<:MyVector2{T}}) where {T} = MyBroadcastStyle{1}()
copyto!(view(M, :, :), S)
@test S == M2
end
@testset "ldiv" begin
S = sparse([4.0 1 0; 1 4 1; 0 1 4])
b = [1.0, 2, 3]
X = [1.0 2 0; 2 3 1; 3 4 2]
for A in (S, S', transpose(S), Symmetric(S), Hermitian(S), Symmetric(S, :L))
for B in (MyVector(b), MyMatrix(X), Diagonal(MyVector(b)),
UpperTriangular(MyMatrix(X)), UnitLowerTriangular(view(MyMatrix(X), :, :)),
LowerTriangular(MyMatrix(X)'), UnitUpperTriangular(transpose(MyMatrix(X))))
@test A \ B ≈ Matrix(A) \ Array(B)
end
end
end
end

@testset "mul! with subarrays" begin
Expand Down
Loading