|
1 | 1 | @inline det(A::StaticMatrix) = _det(Size(A), A)
|
| 2 | +@inline logdet(A::StaticMatrix) = _logdet(Size(A), A) |
2 | 3 |
|
3 | 4 | @inline _det(::Size{(1,1)}, A::StaticMatrix) = @inbounds return A[1]
|
4 | 5 |
|
|
24 | 25 | return vecdot(x0, cross(x1, x2))
|
25 | 26 | end
|
26 | 27 |
|
27 |
| -@generated function _det{S}(::Size{S}, A::StaticMatrix) |
28 |
| - if S[1] != S[2] |
29 |
| - throw(DimensionMismatch("matrix is not square")) |
30 |
| - end |
31 |
| - return quote # Implementation from Base |
32 |
| - @_inline_meta |
33 |
| - T = eltype(A) |
34 |
| - T2 = typeof((one(T)*zero(T) + zero(T))/one(T)) |
35 |
| - if istriu(A) || istril(A) |
36 |
| - return convert(T2, det(UpperTriangular(A))) # Is this a Julia bug that a convert is not type stable?? |
| 28 | +@inline _logdet(S::Union{Size{(1,1)},Size{(2,2)},Size{(3,3)}}, A::StaticMatrix) = log(_det(S, A)) |
| 29 | + |
| 30 | +for (symb, f) in [(:_det, :det), (:_logdet, :logdet)] |
| 31 | + eval(quote |
| 32 | + @generated function $symb{S}(::Size{S}, A::StaticMatrix) |
| 33 | + if S[1] != S[2] |
| 34 | + throw(DimensionMismatch("matrix is not square")) |
| 35 | + end |
| 36 | + return quote # Implementation from Base |
| 37 | + @_inline_meta |
| 38 | + T = eltype(A) |
| 39 | + T2 = typeof((one(T)*zero(T) + zero(T))/one(T)) |
| 40 | + if istriu(A) || istril(A) |
| 41 | + return convert(T2, $($f)(UpperTriangular(A))) # Is this a Julia bug that a convert is not type stable?? |
| 42 | + end |
| 43 | + AA = convert(Array{T2}, A) |
| 44 | + return $($f)(lufact(AA)) |
| 45 | + end |
37 | 46 | end
|
38 |
| - AA = convert(Array{T2}, A) |
39 |
| - return det(lufact(AA)) |
40 |
| - end |
| 47 | + end) |
41 | 48 | end
|
| 49 | + |
0 commit comments