-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add tril and triu for special matrices #12574
Changes from all commits
bb98832
cdfe7aa
0434772
5b75f43
8692f66
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 |
---|---|---|
|
@@ -109,6 +109,44 @@ ctranspose(M::Bidiagonal) = Bidiagonal(conj(M.dv), conj(M.ev), !M.isupper) | |
istriu(M::Bidiagonal) = M.isupper || all(M.ev .== 0) | ||
istril(M::Bidiagonal) = !M.isupper || all(M.ev .== 0) | ||
|
||
function tril(M::Bidiagonal, k::Integer=0) | ||
n = length(M.dv) | ||
if abs(k) > n | ||
throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) | ||
elseif M.isupper && k < 0 | ||
return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) | ||
elseif k < -1 | ||
return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) | ||
elseif !M.isupper && k == 0 | ||
return M | ||
elseif M.isupper && k == 0 | ||
return Bidiagonal(M.dv,zeros(M.ev),M.isupper) | ||
elseif !M.isupper && k == -1 | ||
return Bidiagonal(zeros(M.dv),M.ev,M.isupper) | ||
elseif k > 0 | ||
return M | ||
end | ||
end | ||
|
||
function triu(M::Bidiagonal, k::Integer=0) | ||
n = length(M.dv) | ||
if abs(k) > n | ||
throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) | ||
elseif !M.isupper && k > 0 | ||
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. Same as above with |
||
return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) | ||
elseif k > 1 | ||
return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) | ||
elseif M.isupper && k == 0 | ||
return M | ||
elseif !M.isupper && k == 0 | ||
return Bidiagonal(M.dv,zeros(M.ev),M.isupper) | ||
elseif M.isupper && k == 1 | ||
return Bidiagonal(zeros(M.dv),M.ev,M.isupper) | ||
elseif k < 0 | ||
return M | ||
end | ||
end | ||
|
||
function diag{T}(M::Bidiagonal{T}, n::Integer=0) | ||
if n==0 | ||
return M.dv | ||
|
@@ -249,4 +287,3 @@ function eigvecs{T}(M::Bidiagonal{T}) | |
Q #Actually Triangular | ||
end | ||
eigfact(M::Bidiagonal) = Eigen(eigvals(M), eigvecs(M)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,12 @@ end | |
ctranspose(A::Hermitian) = A | ||
trace(A::Hermitian) = real(trace(A.data)) | ||
|
||
#tril/triu | ||
tril(A::Hermitian,k::Integer=0) = tril(A.data,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. I don't think these are right. Aren't half the elements in
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. Wow. K, on it. The lower triangle is garbage. |
||
triu(A::Hermitian,k::Integer=0) = triu(A.data,k) | ||
tril(A::Symmetric,k::Integer=0) = tril(A.data,k) | ||
triu(A::Symmetric,k::Integer=0) = triu(A.data,k) | ||
|
||
## Matvec | ||
A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(y::StridedVector{T}, A::Symmetric{T,S}, x::StridedVector{T}) = BLAS.symv!(A.uplo, one(T), A.data, x, zero(T), y) | ||
A_mul_B!{T<:BlasComplex,S<:StridedMatrix}(y::StridedVector{T}, A::Hermitian{T,S}, x::StridedVector{T}) = BLAS.hemv!(A.uplo, one(T), A.data, x, zero(T), y) | ||
|
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.
Maybe this could be:
This avoids the rechecking of M.isupper and passing it to Bidiagonal.