Skip to content

Commit ec68f06

Browse files
committed
SDiagonal: next round of comments
1 parent 1244a2c commit ec68f06

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/SDiagonal.jl

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# Originally contributed by D. Getz (https://github.com/getzdan), M. Schauer
22
# at https://github.com/mschauer/Bridge.jl under MIT License
33

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
65

76
@generated function scalem{M, N}(a::StaticMatrix{M,N}, b::StaticVector{N})
87
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)
109
end
1110
@generated function scalem{M, N}(a::StaticVector{M}, b::StaticMatrix{M, N})
1211
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)
1413
end
1514

1615
struct SDiagonal{N,T} <: StaticMatrix{N, N, T}
@@ -34,13 +33,13 @@ end
3433
convert{N,T}(::Type{SDiagonal{N,T}}, D::SDiagonal{N,T}) = D
3534
convert{N,T}(::Type{SDiagonal{N,T}}, D::SDiagonal{N}) = SDiagonal{N,T}(convert(SVector{N,T}, D.diag))
3635

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)
3837
@boundscheck checkbounds(D, i, j)
3938
@inbounds return ifelse(i == j, D.diag[i], zero(T))
4039
end
4140

4241
# 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)
4443
i, j = ind2sub(size(D), k)
4544
D[i,j]
4645
end
@@ -95,11 +94,9 @@ sqrtm(D::SDiagonal) = SDiagonal(sqrt.(D.diag))
9594

9695

9796
@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)))
10199
end
102-
expr
103100
end
104101

105102
function inv{N,T}(D::SDiagonal{N,T})

src/StaticArrays.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import Base: getindex, setindex!, size, similar, vec, show,
88
length, convert, promote_op, promote_rule, map, map!, reduce, reducedim, mapreducedim,
99
mapreduce, broadcast, broadcast!, conj, transpose, ctranspose,
1010
hcat, vcat, ones, zeros, eye, one, cross, vecdot, reshape, fill,
11-
fill!, det, inv, eig, eigvals, expm, sqrtm, trace, vecnorm, norm, dot, diagm, diag,
12-
lu, svd, svdvals, svdfact,
11+
fill!, det, logdet, inv, eig, eigvals, expm, logm, sqrtm, trace, diag, vecnorm, norm, dot, diagm, diag,
12+
lu, svd, svdvals, svdfact, factorize, ishermitian, issymmetric, isposdef,
1313
sum, diff, prod, count, any, all, minimum,
1414
maximum, extrema, mean, copy, rand, randn, randexp, rand!, randn!,
1515
randexp!, normalize, normalize!, read, read!, write

0 commit comments

Comments
 (0)