Skip to content

Commit f9c10d2

Browse files
authored
Fix _solve with nonisbits type (#1071)
* fix indents * add BigFloat in solve test * add support for non-isbits type in _solve * bump version to v1.5.3
1 parent 8d88f0c commit f9c10d2

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.5.2"
3+
version = "1.5.3"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/solve.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,40 @@ end
1616
T = typeof((one(Ta)*zero(Tb) + one(Ta)*zero(Tb))/d)
1717
@inbounds return similar_type(b, T)(
1818
((a[2,2]*a[3,3] - a[2,3]*a[3,2])*b[1] +
19-
(a[1,3]*a[3,2] - a[1,2]*a[3,3])*b[2] +
20-
(a[1,2]*a[2,3] - a[1,3]*a[2,2])*b[3]) / d,
19+
(a[1,3]*a[3,2] - a[1,2]*a[3,3])*b[2] +
20+
(a[1,2]*a[2,3] - a[1,3]*a[2,2])*b[3]) / d,
2121
((a[2,3]*a[3,1] - a[2,1]*a[3,3])*b[1] +
22-
(a[1,1]*a[3,3] - a[1,3]*a[3,1])*b[2] +
23-
(a[1,3]*a[2,1] - a[1,1]*a[2,3])*b[3]) / d,
22+
(a[1,1]*a[3,3] - a[1,3]*a[3,1])*b[2] +
23+
(a[1,3]*a[2,1] - a[1,1]*a[2,3])*b[3]) / d,
2424
((a[2,1]*a[3,2] - a[2,2]*a[3,1])*b[1] +
25-
(a[1,2]*a[3,1] - a[1,1]*a[3,2])*b[2] +
26-
(a[1,1]*a[2,2] - a[1,2]*a[2,1])*b[3]) / d )
25+
(a[1,2]*a[3,1] - a[1,1]*a[3,2])*b[2] +
26+
(a[1,1]*a[2,2] - a[1,2]*a[2,1])*b[3]) / d )
2727
end
2828

2929
for Sa in [(2,2), (3,3)] # not needed for Sa = (1, 1);
3030
@eval begin
3131
@inline function _solve(::Size{$Sa}, ::Size{Sb}, a::StaticMatrix{<:Any, <:Any, Ta}, b::StaticMatrix{<:Any, <:Any, Tb}) where {Sb, Ta, Tb}
3232
d = det(a)
3333
T = typeof((one(Ta)*zero(Tb) + one(Ta)*zero(Tb))/d)
34-
c = similar(b, T)
35-
for col = 1:Sb[2]
36-
@inbounds c[:, col] = _solve(Size($Sa), Size($Sa[1],), a, b[:, col])
34+
if isbitstype(T)
35+
# This if block can be removed when https://github.com/JuliaArrays/StaticArrays.jl/pull/749 is merged.
36+
c = similar(b, T)
37+
for col in 1:Sb[2]
38+
@inbounds c[:, col] = _solve(Size($Sa), Size($Sa[1],), a, b[:, col])
39+
end
40+
return similar_type(b, T)(c)
41+
else
42+
return _solve_general($(Size(Sa)), Size(Sb), a, b)
3743
end
38-
return similar_type(b, T)(c)
3944
end
4045
end # @eval
4146
end
4247

48+
@inline function _solve(sa::Size, sb::Size, a::StaticMatrix, b::StaticVecOrMat)
49+
_solve_general(sa, sb, a, b)
50+
end
4351

44-
45-
@generated function _solve(::Size{Sa}, ::Size{Sb}, a::StaticMatrix{<:Any, <:Any, Ta}, b::StaticVecOrMat{Tb}) where {Sa, Sb, Ta, Tb}
52+
@generated function _solve_general(::Size{Sa}, ::Size{Sb}, a::StaticMatrix{<:Any, <:Any, Ta}, b::StaticVecOrMat{Tb}) where {Sa, Sb, Ta, Tb}
4653
if Sa[1] != Sb[1]
4754
return quote
4855
throw(DimensionMismatch("Left and right hand side first dimensions do not match in backdivide (got sizes $Sa and $Sb)"))

test/solve.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using StaticArrays, Test, LinearAlgebra
33
@testset "Solving linear system" begin
44
@testset "Problem size: $n x $n. Matrix type: $m. Element type: $elty, Wrapper: $wrapper" for n in (1,2,3,4,5,8,15),
55
(m, v) in ((SMatrix{n,n}, SVector{n}), (MMatrix{n,n}, MVector{n})),
6-
elty in (Float64, Int), wrapper in (identity, Symmetric, Hermitian)
6+
elty in (Float64, Int, BigFloat), wrapper in (identity, Symmetric, Hermitian)
77

88
A = wrapper(elty.(rand(-99:2:99, n, n)))
99
b = A * elty.(rand(2:5, n))
@@ -33,7 +33,7 @@ end
3333
@testset "Solving linear system (multiple RHS)" begin
3434
@testset "Problem size: $n x $n. Matrix type: $m1. Element type: $elty" for n in (1,2,3,4,5,8,15),
3535
(m1, m2) in ((SMatrix{n,n}, SMatrix{n,2}), (MMatrix{n,n}, MMatrix{n,2})),
36-
elty in (Float64, Int)
36+
elty in (Float64, Int, BigFloat)
3737

3838
A = elty.(rand(-99:2:99, n, n))
3939
b = A * elty.(rand(2:5, n, 2))

0 commit comments

Comments
 (0)