Skip to content

Commit 3bc7f77

Browse files
MohamedLaghdafHABIBOULLAHdpo
authored andcommitted
Non-allocating rank and nuclear norm prox
1 parent 0aea1f2 commit 3bc7f77

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/shiftedNuclearnorm.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ function prox!(
6565
V1 <: AbstractVector{R},
6666
V2 <: AbstractVector{R},
6767
}
68+
λ = ψ.h.lambda
6869
ψ.sol .= q .+ ψ.xk .+ ψ.sj
6970
ψ.h.A .= reshape_array.sol, size.h.A))
7071
psvd_dd!.h.F, ψ.h.A, full = false)
71-
c = sqrt(2 * ψ.λ * σ)
72-
ψ.h.F.S .= max.(0, ψ.h.F.S .- ψ.λ * σ)
72+
ψ.h.F.S .= max.(0, ψ.h.F.S .- λ * σ)
7373
for i eachindex.h.F.S)
7474
for j = 1:size.h.A, 1)
7575
ψ.h.F.U[j, i] = ψ.h.F.U[j, i] .* ψ.h.F.S[i]

src/shiftedRank.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ function prox!(
6565
V1 <: AbstractVector{R},
6666
V2 <: AbstractVector{R},
6767
}
68+
λ = ψ.h.lambda
6869
ψ.sol .= q .+ ψ.xk .+ ψ.sj
6970
ψ.h.A .= reshape_array.sol, size.h.A))
7071
psvd_dd!.h.F, ψ.h.A, full = false)
71-
c = sqrt(2 * ψ.λ * σ)
72+
c = sqrt(2 * λ * σ)
7273
for i eachindex.h.F.S)
7374
if ψ.h.F.S[i] <= c
7475
ψ.h.F.U[:, i] .= 0

test/test_allocs.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,22 @@ end
8383
@test @wrappedallocs(prox!(y, ψ, y, 1.0)) == 0
8484
@test @wrappedallocs(iprox!(y, ψ, y, d)) == 0
8585
end
86+
87+
for (op, shifted_op) zip((:Rank, :Nuclearnorm), (:ShiftedRank, :ShiftedNuclearnorm))
88+
ShiftedOp = eval(shifted_op)
89+
Op = eval(op)
90+
m = 10
91+
n = 11
92+
λ = 1.0
93+
γ = 5.0
94+
x = vec(reshape(rand(m, n), m * n, 1))
95+
q = vec(reshape(rand(m, n), m * n, 1))
96+
s = vec(reshape(rand(m, n), m * n, 1))
97+
F = psvd_workspace_dd(zeros(m, n), full = false)
98+
h = Op(λ, ones(m, n), F)
99+
f = ShiftedOp(h, x, s, true)
100+
y = zeros(m * n)
101+
@test @wrappedallocs(prox!(y, h, x, γ)) == 0
102+
@test @wrappedallocs(prox!(y, f, q, γ)) == 0
103+
end
86104
end

0 commit comments

Comments
 (0)