-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Val{k} as second argument in diagm #255
Conversation
Codecov Report
@@ Coverage Diff @@
## master #255 +/- ##
==========================================
- Coverage 89% 88.95% -0.06%
==========================================
Files 36 36
Lines 2619 2625 +6
==========================================
+ Hits 2331 2335 +4
- Misses 288 290 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice to me, thanks!
T = eltype(v) | ||
exprs = [i == j ? :(v[$i]) : zero(T) for i = 1:S[1], j = 1:S[1]] | ||
ind = diagind(Snew1, Snew1, D) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I didn't know about diagind
.
test/linalg.jl
Outdated
@@ -40,6 +40,8 @@ using StaticArrays, Base.Test | |||
|
|||
@testset "diagm()" begin | |||
@test @inferred(diagm(SVector(1,2))) === @SMatrix [1 0; 0 2] | |||
@test @inferred(diagm(SVector(1,2,3), Val{2})) == diagm([1,2,3], 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor thing - might be worth adding a type assert here ::SMatrix
on the left hand side outside the @inferred
to assert that these come out as static arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Just made changes accordingly.
This PR implements
diagm(::SVector, ::Type{Val{k}})
, which type-stably creates a matrix with a specifiedk
th super-or sub-diagonal. Previously there was onlydiagm(::SVector)
without the second argument.