|
1 |
| -@inline (\)(a::StaticMatrix{<:Any, <:Any, T}, b::StaticVector{<:Any, T}) where {T} = solve(Size(a), Size(b), a, b) |
2 |
| -@inline (\)(a::Union{UpperTriangular{T, S}, LowerTriangular{T, S}} where {S<:StaticMatrix{<:Any, <:Any, T}}, b::StaticVector{<:Any, T}) where {T} = solve(Size(a.data), Size(b), a, b) |
3 |
| -@inline (\)(a::Union{UpperTriangular{T, S}, LowerTriangular{T, S}} where {S<:StaticMatrix{<:Any, <:Any, T}}, b::StaticMatrix{<:Any, <:Any, T}) where {T} = solve(Size(a.data), Size(b), a, b) |
| 1 | +@inline (\)(a::StaticMatrix, b::StaticVector) = solve(Size(a), Size(b), a, b) |
| 2 | +@inline (\)(a::Union{UpperTriangular{<:Any, <:StaticMatrix}, LowerTriangular{<:Any, <:StaticMatrix}}, b::StaticVecOrMat) = solve(Size(a.data), Size(b), a, b) |
4 | 3 |
|
5 | 4 | # TODO: Ineffecient but requires some infrastructure (e.g. LU or QR) to make efficient so we fall back on inv for now
|
6 | 5 | @inline solve(::Size, ::Size, a, b) = inv(a) * b
|
|
31 | 30 | (a[1,1]*a[2,2] - a[1,2]*a[2,1])*b[3]) / d )
|
32 | 31 | end
|
33 | 32 |
|
34 |
| -@generated function solve(::Size{sa}, ::Size{sb}, a::UpperTriangular{Ta, Sa} where {Sa<:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticVector{<:Any, Tb}) where {sa, sb, Ta, Tb} |
| 33 | +@generated function solve(::Size{sa}, ::Size{sb}, a::UpperTriangular{Ta, <:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticVector{<:Any, Tb}) where {sa, sb, Ta, Tb} |
35 | 34 | if sa[1] != sb[1]
|
36 | 35 | throw(DimensionMismatch("right hand side b needs first dimension of size $(sa[1]), has size $(sb[1])"))
|
37 | 36 | end
|
|
40 | 39 | expr = [:($(x[i]) = $(reduce((ex1, ex2) -> :(-($ex1,$ex2)), [j == i ? :(b[$j]) : :(a[$i, $j]*$(x[j])) for j = i:sa[1]]))/a[$i, $i]) for i = sb[1]:-1:1]
|
41 | 40 |
|
42 | 41 | quote
|
43 |
| - @_inline_meta |
44 |
| - T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
45 |
| - @inbounds $(Expr(:block, expr...)) |
46 |
| - @inbounds return similar_type(b, T)(tuple($(x...))) |
| 42 | + @_inline_meta |
| 43 | + T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
| 44 | + @inbounds $(Expr(:block, expr...)) |
| 45 | + @inbounds return similar_type(b, T)(tuple($(x...))) |
47 | 46 | end
|
48 | 47 | end
|
49 | 48 |
|
50 |
| -@generated function solve(::Size{sa}, ::Size{sb}, a::UpperTriangular{Ta, Sa} where {Sa<:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticMatrix{<:Any, <:Any, Tb}) where {sa, sb, Ta, Tb} |
| 49 | +@generated function solve(::Size{sa}, ::Size{sb}, a::UpperTriangular{Ta, <:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticMatrix{<:Any, <:Any, Tb}) where {sa, sb, Ta, Tb} |
51 | 50 | if sa[1] != sb[1]
|
52 | 51 | throw(DimensionMismatch("right hand side b needs first dimension of size $(sa[1]), has size $(sb[1])"))
|
53 | 52 | end
|
|
56 | 55 | expr = [:($(x[k1, k2]) = $(reduce((ex1, ex2) -> :(-($ex1,$ex2)), [j == k1 ? :(b[$j, $k2]) : :(a[$k1, $j]*$(x[j, k2])) for j = k1:sa[1]]))/a[$k1, $k1]) for k1 = sb[1]:-1:1, k2 = 1:sb[2]]
|
57 | 56 |
|
58 | 57 | quote
|
59 |
| - @_inline_meta |
60 |
| - T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
61 |
| - @inbounds $(Expr(:block, expr...)) |
62 |
| - @inbounds return similar_type(b, T)(tuple($(x...))) |
| 58 | + @_inline_meta |
| 59 | + T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
| 60 | + @inbounds $(Expr(:block, expr...)) |
| 61 | + @inbounds return similar_type(b, T)(tuple($(x...))) |
63 | 62 | end
|
64 | 63 | end
|
65 | 64 |
|
66 |
| -@generated function solve(::Size{sa}, ::Size{sb}, a::LowerTriangular{Ta, Sa} where {Sa<:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticVector{<:Any, Tb}) where {sa, sb, Ta, Tb} |
| 65 | +@generated function solve(::Size{sa}, ::Size{sb}, a::LowerTriangular{Ta, <:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticVector{<:Any, Tb}) where {sa, sb, Ta, Tb} |
67 | 66 | if sa[1] != sb[1]
|
68 | 67 | throw(DimensionMismatch("right hand side b needs first dimension of size $(sa[1]), has size $(sb[1])"))
|
69 | 68 | end
|
|
72 | 71 | expr = [:($(x[i]) = $(reduce((ex1, ex2) -> :(-($ex1,$ex2)), [j == i ? :(b[$j]) : :(a[$i, $j]*$(x[j])) for j = i:-1:1]))/a[$i, $i]) for i = 1:sb[1]]
|
73 | 72 |
|
74 | 73 | quote
|
75 |
| - @_inline_meta |
76 |
| - T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
77 |
| - @inbounds $(Expr(:block, expr...)) |
78 |
| - @inbounds return similar_type(b, T)(tuple($(x...))) |
| 74 | + @_inline_meta |
| 75 | + T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
| 76 | + @inbounds $(Expr(:block, expr...)) |
| 77 | + @inbounds return similar_type(b, T)(tuple($(x...))) |
79 | 78 | end
|
80 | 79 | end
|
81 | 80 |
|
82 |
| -@generated function solve(::Size{sa}, ::Size{sb}, a::LowerTriangular{Ta, Sa} where {Sa<:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticMatrix{<:Any, <:Any, Tb}) where {sa, sb, Ta, Tb} |
| 81 | +@generated function solve(::Size{sa}, ::Size{sb}, a::LowerTriangular{Ta, <:StaticMatrix{<:Any, <:Any, Ta}}, b::StaticMatrix{<:Any, <:Any, Tb}) where {sa, sb, Ta, Tb} |
83 | 82 | if sa[1] != sb[1]
|
84 | 83 | throw(DimensionMismatch("right hand side b needs first dimension of size $(sa[1]), has size $(sb[1])"))
|
85 | 84 | end
|
|
88 | 87 | expr = [:($(x[k1, k2]) = $(reduce((ex1, ex2) -> :(-($ex1,$ex2)), [j == k1 ? :(b[$j, $k2]) : :(a[$k1, $j]*$(x[j, k2])) for j = k1:-1:1]))/a[$k1, $k1]) for k1 = 1:sb[1], k2 = 1:sb[2]]
|
89 | 88 |
|
90 | 89 | quote
|
91 |
| - @_inline_meta |
92 |
| - T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
93 |
| - @inbounds $(Expr(:block, expr...)) |
94 |
| - @inbounds return similar_type(b, T)(tuple($(x...))) |
| 90 | + @_inline_meta |
| 91 | + T = typeof((zero(Ta)*zero(Tb) + zero(Ta)*zero(Tb))/one(Ta)) |
| 92 | + @inbounds $(Expr(:block, expr...)) |
| 93 | + @inbounds return similar_type(b, T)(tuple($(x...))) |
95 | 94 | end
|
96 | 95 | end
|
0 commit comments