-
Notifications
You must be signed in to change notification settings - Fork 152
Implement vector indexing for SDiagonal with statically sized indices #926
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,6 +17,10 @@ SDiagonal(a::StaticMatrix{N,N,T}) where {N,T} = Diagonal(diag(a)) | |||
size(::Type{<:SDiagonal{N}}) where {N} = (N,N) | ||||
size(::Type{<:SDiagonal{N}}, d::Int) where {N} = d > 2 ? 1 : N | ||||
|
||||
Base.axes(D::SDiagonal, d) = d <= 2 ? axes(D)[d] : SOneTo(1) | ||||
|
||||
Base.reshape(a::SDiagonal, s::Tuple{SOneTo,Vararg{SOneTo}}) = reshape(a, homogenize_shape(s)) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same as the generic fallback: StaticArrays.jl/src/abstractarray.jl Line 190 in 29a76ec
Do we really need this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than this small point, the PR looks nice 👍 . |
||||
|
||||
# define specific methods to avoid allocating mutable arrays | ||||
\(D::SDiagonal, b::AbstractVector) = D.diag .\ b | ||||
\(D::SDiagonal, b::StaticVector) = D.diag .\ b # catch ambiguity | ||||
|
@@ -56,3 +60,5 @@ function inv(D::SDiagonal) | |||
check_singular(D) | ||||
SDiagonal(inv.(D.diag)) | ||||
end | ||||
|
||||
Base.copy(D::SDiagonal) = Diagonal(copy(diag(D))) |
Uh oh!
There was an error while loading. Please reload this page.