Skip to content

Commit 241a4ae

Browse files
authored
Merge pull request #570 from JuliaArrays/teh/mixed
implement solve with mixed StaticArray/DynamicArray types
2 parents 4adc061 + 5445ae0 commit 241a4ae

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/SDiagonal.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ size(::Type{<:SDiagonal{N}}, d::Int) where {N} = d > 2 ? 1 : N
2828
\(Da::SDiagonal, Db::SDiagonal) = SDiagonal(Db.diag ./ Da.diag)
2929
/(Da::SDiagonal, Db::SDiagonal) = SDiagonal(Da.diag ./ Db.diag )
3030

31+
\(D::Diagonal, B::StaticMatrix) = ldiv!(D, Matrix(B))
32+
3133
# override to avoid copying
3234
diag(D::SDiagonal) = D.diag
3335

src/lu.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ end
138138

139139
# Base.lufact() interface is fairly inherently type unstable. Punt on
140140
# implementing that, for now...
141+
142+
\(F::LU, v::AbstractVector) = F.U \ (F.L \ v[F.p])
143+
\(F::LU, B::AbstractMatrix) = F.U \ (F.L \ B[F.p,:])

test/solve.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,21 @@ using StaticArrays, Test, LinearAlgebra
1515
v = @SVector ones(4)
1616
@test_throws DimensionMismatch m1\v
1717
@test_throws DimensionMismatch m1\m2
18+
19+
# Mixed static/dynamic arrays
20+
# \ specializes for Diagonal, LowerTriangular, UpperTriangular, square, and non-square
21+
# So try all of these
22+
@testset "Mixed static/dynamic" begin
23+
v = @SVector([0.2,0.3])
24+
for m in (@SMatrix([1.0 0; 0 1.0]), @SMatrix([1.0 0; 1.0 1.0]),
25+
@SMatrix([1.0 1.0; 0 1.0]), @SMatrix([1.0 0.5; 0.25 1.0]))
26+
# TODO: include @SMatrix([1.0 0.0 0.0; 1.0 2.0 0.5]), need qr methods
27+
@test m \ v Array(m) \ v m \ Array(v) Array(m) \ Array(v)
28+
end
29+
end
1830
end
1931

32+
2033
@testset "Solving linear system (multiple RHS)" begin
2134
@testset "Problem size: $n x $n. Matrix type: $m1. Element type: $elty" for n in (1,2,3,4,5,8,15),
2235
(m1, m2) in ((SMatrix{n,n}, SMatrix{n,2}), (MMatrix{n,n}, MMatrix{n,2})),
@@ -25,5 +38,15 @@ end
2538
A = elty.(rand(-99:2:99, n, n))
2639
b = A * elty.(rand(2:5, n, 2))
2740
@test m1(A)\m2(b) A\b
41+
42+
end
43+
44+
@testset "Mixed static/dynamic" begin
45+
m2 = @SMatrix([0.2 0.3; 0.0 0.1])
46+
for m1 in (@SMatrix([1.0 0; 0 1.0]), @SMatrix([1.0 0; 1.0 1.0]),
47+
@SMatrix([1.0 1.0; 0 1.0]), @SMatrix([1.0 0.5; 0.25 1.0]))
48+
# TODO: include @SMatrix([1.0 0.0 0.0; 1.0 2.0 0.5]), need qr methods
49+
@test m1 \ m2 Array(m1) \ m2 m1 \ Array(m2) Array(m1) \ Array(m2)
50+
end
2851
end
2952
end

0 commit comments

Comments
 (0)