Skip to content

Commit 0759078

Browse files
authored
Merge pull request #584 from judober/Increase_Matrix_Div_Performance
Increase Performance of \ (and /) for small square matrix
2 parents d3f739e + 9faf9e2 commit 0759078

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/solve.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ end
2626
(a[1,1]*a[2,2] - a[1,2]*a[2,1])*b[3]) / d )
2727
end
2828

29+
for Sa in [(2,2), (3,3)] # not needed for Sa = (1, 1);
30+
@eval begin
31+
@inline function solve(::Size{$Sa}, ::Size{Sb}, a::StaticMatrix{<:Any, <:Any, Ta}, b::StaticMatrix{<:Any, <:Any, Tb}) where {Sb, Ta, Tb}
32+
d = det(a)
33+
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])
37+
end
38+
return similar_type(b, T)(c)
39+
end
40+
end # @eval
41+
end
42+
43+
44+
2945
@generated function solve(::Size{Sa}, ::Size{Sb}, a::StaticMatrix{<:Any, <:Any, Ta}, b::StaticVecOrMat{Tb}) where {Sa, Sb, Ta, Tb}
3046
if Sa[end] != Sb[1]
3147
throw(DimensionMismatch("right hand side B needs first dimension of size $(Sa[end]), has size $Sb"))

0 commit comments

Comments
 (0)