-
Notifications
You must be signed in to change notification settings - Fork 41
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
#127 fix: support cones for generic number types. #136
base: master
Are you sure you want to change the base?
Changes from all commits
4e135d8
8607081
75dc3a0
2421625
337a365
3e25ee5
c5b1f70
edfcbe9
ae81709
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 |
---|---|---|
|
@@ -183,7 +183,7 @@ for (syevr, elty) in | |
end #@eval | ||
end #for | ||
|
||
function _project!(X::AbstractMatrix, ws::PsdBlasWorkspace{T}) where{T} | ||
function _project!(X::AbstractMatrix, ws::PsdBlasWorkspace{T}) where{T <: Union{Float32,Float64}} | ||
|
||
#computes the upper triangular part of the projection of X onto the PSD cone | ||
|
||
|
@@ -203,6 +203,23 @@ function _project!(X::AbstractMatrix, ws::PsdBlasWorkspace{T}) where{T} | |
rank_k_update!(X, ws) | ||
end | ||
|
||
function _project!(X::AbstractMatrix{T}, ws::PsdBlasWorkspace{T}) where {T} | ||
w,Z = GenericLinearAlgebra.eigen(GenericLinearAlgebra.Hermitian(X)) | ||
# The follwoing lines uses MutableArithmetics to perform the operation : X .= Z*LinearAlgebra.Diagonal(max.(w,0))*Z' | ||
X = zero(X) | ||
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. Because of this line, you don't modify the input 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. It should be 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. Which gives :
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. Apparently, objects of type 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. Which means that the 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. ping @blegat, if this is still a blocker 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. We should implement |
||
buffer = zero(X) | ||
for i in eachindex(w) | ||
w[i] <= T(0) && continue | ||
z = view(Z, :, i) | ||
MA.mutable_operate_to!(buffer, *, z, z') | ||
for j in eachindex(X) | ||
#The following line should be : X[j] = MA.add_mul!(X[j], w[i], buffer[j]) | ||
# However it does not work for BigFLoats yet, so i keep the allocating working line : | ||
X[j] += w[i]*buffer[j] | ||
end | ||
end | ||
end | ||
|
||
function rank_k_update!(X::AbstractMatrix, ws::COSMO.PsdBlasWorkspace{T}) where {T} | ||
n = size(X, 1) | ||
@. X = zero(T) | ||
|
@@ -274,9 +291,11 @@ function project!(x::AbstractVector{T}, cone::Union{PsdCone{T}, DensePsdCone{T}} | |
symmetrize_upper!(X) | ||
_project!(X, cone.work) | ||
|
||
#fill in the lower triangular part | ||
for j=1:n, i=1:(j-1) | ||
X[j,i] = X[i,j] | ||
#fill in the lower triangular part, only needed when calling BLAS. | ||
if T <: Union{Float32,Float64} | ||
for j=1:n, i=1:(j-1) | ||
X[j,i] = X[i,j] | ||
end | ||
end | ||
end | ||
return nothing | ||
|
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.
This reallocates
w
andZ
at every iteration. Is there a non-allocating version ofGenericAlgebra.eigen
?eigen!
perhaps?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.
There is a function with that name but I do not understand how it works (and where it stores the result). I tried several things and no luck yet :/