|
1 | 1 | # Originally contributed by D. Getz (https://github.com/getzdan), M. Schauer
|
2 | 2 | # at https://github.com/mschauer/Bridge.jl under MIT License
|
3 | 3 |
|
4 |
| -import Base: getindex,setindex!,==,-,+,*,/,\,transpose,ctranspose,convert, size, abs, real, imag, conj, eye, inv |
5 |
| -import Base.LinAlg: ishermitian, issymmetric, isposdef, factorize, diag, trace, det, logdet, expm, logm, sqrtm |
| 4 | +import Base: ==, -, +, *, /, \, abs, real, imag, conj |
6 | 5 |
|
7 | 6 | @generated function scalem{M, N}(a::StaticMatrix{M,N}, b::StaticVector{N})
|
8 | 7 | expr = vec([:(a[$j,$i]*b[$i]) for j=1:M, i=1:N])
|
9 |
| - :(let val1 = ($(expr[1])); similar_type(SMatrix{M,N},typeof(val1))(val1, $(expr[2:end]...)); end) |
| 8 | + :(@_inline_meta; let val1 = ($(expr[1])); similar_type(SMatrix{M,N},typeof(val1))(val1, $(expr[2:end]...)); end) |
10 | 9 | end
|
11 | 10 | @generated function scalem{M, N}(a::StaticVector{M}, b::StaticMatrix{M, N})
|
12 | 11 | expr = vec([:(b[$j,$i]*a[$j]) for j=1:M, i=1:N])
|
13 |
| - :(let val1 = ($(expr[1])); similar_type(SMatrix{M,N},typeof(val1))(val1, $(expr[2:end]...)); end) |
| 12 | + :(@_inline_meta; let val1 = ($(expr[1])); similar_type(SMatrix{M,N},typeof(val1))(val1, $(expr[2:end]...)); end) |
14 | 13 | end
|
15 | 14 |
|
16 | 15 | struct SDiagonal{N,T} <: StaticMatrix{N, N, T}
|
|
34 | 33 | convert{N,T}(::Type{SDiagonal{N,T}}, D::SDiagonal{N,T}) = D
|
35 | 34 | convert{N,T}(::Type{SDiagonal{N,T}}, D::SDiagonal{N}) = SDiagonal{N,T}(convert(SVector{N,T}, D.diag))
|
36 | 35 |
|
37 |
| -Base.@propagate_inbounds function getindex{N,T}(D::SDiagonal{N,T}, i::Int, j::Int) |
| 36 | +function getindex{N,T}(D::SDiagonal{N,T}, i::Int, j::Int) |
38 | 37 | @boundscheck checkbounds(D, i, j)
|
39 | 38 | @inbounds return ifelse(i == j, D.diag[i], zero(T))
|
40 | 39 | end
|
41 | 40 |
|
42 | 41 | # avoid linear indexing?
|
43 |
| -Base.@propagate_inbounds function getindex{N,T}(D::SDiagonal{N,T}, k::Int) |
| 42 | +@propagate_inbounds function getindex{N,T}(D::SDiagonal{N,T}, k::Int) |
44 | 43 | i, j = ind2sub(size(D), k)
|
45 | 44 | D[i,j]
|
46 | 45 | end
|
@@ -95,11 +94,9 @@ sqrtm(D::SDiagonal) = SDiagonal(sqrt.(D.diag))
|
95 | 94 |
|
96 | 95 |
|
97 | 96 | @generated function check_singular{N,T}(D::SDiagonal{N,T})
|
98 |
| - expr = Expr(:block) |
99 |
| - for i=1:N |
100 |
| - push!(expr.args, :(@inbounds iszero(D.diag[$i]) && throw(Base.LinAlg.SingularException($i)))) |
| 97 | + quote |
| 98 | + Base.Cartesian.@nexprs $N i->(@inbounds iszero(D.diag[i]) && throw(Base.LinAlg.SingularException(i))) |
101 | 99 | end
|
102 |
| - expr |
103 | 100 | end
|
104 | 101 |
|
105 | 102 | function inv{N,T}(D::SDiagonal{N,T})
|
|
0 commit comments