-
-
Notifications
You must be signed in to change notification settings - Fork 34
diag
with a Val
band index
#1424
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
9ec21a3
dc17e92
09b8bf3
72fff90
daca977
bc371b0
5b0bcec
0827561
4417771
723b66a
7d8085d
b11d345
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 | ||||
---|---|---|---|---|---|---|
|
@@ -577,6 +577,8 @@ _vecadjoint(A::Base.ReshapedArray{<:Any,1,<:AdjointAbsVec}) = adjoint(parent(A)) | |||||
|
||||||
diagview(A::Transpose, k::Integer = 0) = _vectranspose(diagview(parent(A), -k)) | ||||||
diagview(A::Adjoint, k::Integer = 0) = _vecadjoint(diagview(parent(A), -k)) | ||||||
diag(A::Transpose, ::Val{k}) where {k} = _vectranspose(diag(parent(A), Val(-k))) | ||||||
diag(A::Adjoint, ::Val{k}) where {k} = _vecadjoint(diag(parent(A), Val(-k))) | ||||||
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.
Suggested change
|
||||||
|
||||||
# triu and tril | ||||||
triu!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(tril!(parent(A), -k)) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -307,6 +307,22 @@ julia> diag(A,1) | |||||||
""" | ||||||||
diag(A::AbstractMatrix, k::Integer=0) = A[diagind(A, k, IndexStyle(A))] | ||||||||
|
||||||||
""" | ||||||||
diag(M, ::Val{k}) where {k} | ||||||||
|
||||||||
Return the `k`th diagonal of a matrix as a vector. | ||||||||
For banded matrix types such as `Diagonal`, this may return the underlying | ||||||||
band instead of making a copy if `k` lies within the bandwidth of the matrix. | ||||||||
|
||||||||
!!! note | ||||||||
The type of the result may vary depending on the values of `k`. | ||||||||
""" | ||||||||
function diag(A::AbstractMatrix, ::Val{k}) where {k} | ||||||||
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.
Suggested change
|
||||||||
# some types might have a specialized 1-arg `diag` method, | ||||||||
# and we may use this if possible | ||||||||
k == 0 ? diag(A) : diag(A, k) | ||||||||
end | ||||||||
|
||||||||
""" | ||||||||
diagview(M, k::Integer=0) | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -667,3 +667,6 @@ function logdet(F::Hessenberg) | |||||||||||
d,s = logabsdet(F) | ||||||||||||
return d + log(s) | ||||||||||||
end | ||||||||||||
|
||||||||||||
diag(A::UpperHessenberg) = diag(A.data) | ||||||||||||
diag(A::UpperHessenberg, ::Val{k}) where {k} = k >= -1 ? diag(A.data, Val(k)) : diag(A, k) | ||||||||||||
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.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -550,6 +550,12 @@ adjoint!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U' , tr | |||||||||||
|
||||||||||||
diag(A::UpperOrLowerTriangular) = diag(A.data) | ||||||||||||
diag(A::Union{UnitLowerTriangular, UnitUpperTriangular}) = fill(oneunit(eltype(A)), size(A,1)) | ||||||||||||
diag(A::UpperTriangular, ::Val{k}) where {k} = k >= 0 ? diag(A.data, Val(k)) : diag(A, k) | ||||||||||||
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.
Suggested change
|
||||||||||||
diag(A::LowerTriangular, ::Val{k}) where {k} = k <= 0 ? diag(A.data, Val(k)) : diag(A, k) | ||||||||||||
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.
Suggested change
|
||||||||||||
diag(A::UnitUpperTriangular, ::Val{0}) = diag(A) | ||||||||||||
diag(A::UnitLowerTriangular, ::Val{0}) = diag(A) | ||||||||||||
diag(A::UnitUpperTriangular, ::Val{k}) where {k} = k > 0 ? diag(A.data, Val(k)) : diag(A, k) | ||||||||||||
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.
Suggested change
|
||||||||||||
diag(A::UnitLowerTriangular, ::Val{k}) where {k} = k < 0 ? diag(A.data, Val(k)) : diag(A, k) | ||||||||||||
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.
Suggested change
|
||||||||||||
|
||||||||||||
# Unary operations | ||||||||||||
-(A::LowerTriangular) = LowerTriangular(-A.data) | ||||||||||||
|
@@ -2994,8 +3000,8 @@ logdet(A::UnitUpperTriangular{T}) where {T} = zero(T) | |||||||||||
logdet(A::UnitLowerTriangular{T}) where {T} = zero(T) | ||||||||||||
logabsdet(A::UnitUpperTriangular{T}) where {T} = zero(T), one(T) | ||||||||||||
logabsdet(A::UnitLowerTriangular{T}) where {T} = zero(T), one(T) | ||||||||||||
det(A::UpperTriangular) = prod(diag(A.data)) | ||||||||||||
det(A::LowerTriangular) = prod(diag(A.data)) | ||||||||||||
det(A::UpperTriangular) = prod(diag(A.data, Val(0))) | ||||||||||||
det(A::LowerTriangular) = prod(diag(A.data, Val(0))) | ||||||||||||
function logabsdet(A::Union{UpperTriangular{T},LowerTriangular{T}}) where T | ||||||||||||
sgn = one(T) | ||||||||||||
abs_det = zero(real(T)) | ||||||||||||
|
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.