Skip to content
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

Deprecate norm_inf, norm_1, norm_fro #567

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/atoms/sdp_cone/OperatorNormAtom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ function LinearAlgebra.opnorm(x::AbstractExpr, p::Real = 2)
end
end

Base.@deprecate operatornorm(x::AbstractExpr) LinearAlgebra.opnorm(x)

function new_conic_form!(context::Context{T}, x::OperatorNormAtom) where {T}
A = x.children[1]
if sign(A) == ComplexSign()
Expand Down
10 changes: 10 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ end
Base.:>(lhs::AbstractExpr, rhs::Value) = >(lhs, constant(rhs))

Base.:>(lhs::Value, rhs::AbstractExpr) = >(constant(lhs), rhs)

@deprecate norm_inf(x::AbstractExpr) norm(x, Inf)

@deprecate norm_1(x::AbstractExpr) norm(x, 1)

@deprecate norm_fro(x::AbstractExpr) norm(x, 2)

@deprecate get_vectorized_size(x::AbstractExpr) length(x)

@deprecate operatornorm(x::AbstractExpr) LinearAlgebra.opnorm(x)
1 change: 0 additions & 1 deletion src/expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,3 @@ Base.axes(x::AbstractExpr) = (Base.OneTo(size(x, 1)), Base.OneTo(size(x, 2)))
Base.axes(x::AbstractExpr, n::Integer) = axes(x)[n]
Base.lastindex(x::AbstractExpr, n::Integer) = last(axes(x, n))

odow marked this conversation as resolved.
Show resolved Hide resolved
@deprecate get_vectorized_size(x::AbstractExpr) length(x)
8 changes: 4 additions & 4 deletions src/problem_depot/problems/lp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ end
::Type{T},
) where {T,test}
x = Variable(3)
p = minimize(norm_inf(x), [-2 <= x, x <= 1]; numeric_type = T)
p = minimize(norm(x, Inf), [-2 <= x, x <= 1]; numeric_type = T)

if test
@test problem_vexity(p) == ConvexVexity()
end
handle_problem!(p)
if test
@test p.optval ≈ 0 atol = atol rtol = rtol
@test evaluate(norm_inf(x)) ≈ 0 atol = atol rtol = rtol
@test evaluate(norm(x, Inf)) ≈ 0 atol = atol rtol = rtol
@test norm(p.constraints[1].dual) ≈ 0 atol = atol rtol = rtol
@test norm(p.constraints[2].dual) ≈ 0 atol = atol rtol = rtol
end
Expand All @@ -371,15 +371,15 @@ end
::Type{T},
) where {T,test}
x = Variable(3)
p = minimize(norm_1(x), [-2 <= x, x <= 1]; numeric_type = T)
p = minimize(norm(x, 1), [-2 <= x, x <= 1]; numeric_type = T)

if test
@test problem_vexity(p) == ConvexVexity()
end
handle_problem!(p)
if test
@test p.optval ≈ 0 atol = atol rtol = rtol
@test evaluate(norm_1(x)) ≈ 0 atol = atol rtol = rtol
@test evaluate(norm(x, 1)) ≈ 0 atol = atol rtol = rtol
@test norm(p.constraints[1].dual) ≈ 0 atol = atol rtol = rtol
@test norm(p.constraints[2].dual) ≈ 0 atol = atol rtol = rtol
end
Expand Down
4 changes: 2 additions & 2 deletions src/problem_depot/problems/socp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
b = [2; 3; 4]
lambda = 1
p = minimize(
norm2(A * x + b) + lambda * norm_1(x),
norm2(A * x + b) + lambda * norm(x, 1),
x >= 1;
numeric_type = T,
)
Expand All @@ -73,7 +73,7 @@
handle_problem!(p)
if test
@test p.optval ≈ 15.4907 atol = atol rtol = rtol
@test evaluate(norm2(A * x + b) + lambda * norm_1(x)) ≈ 15.4907 atol =
@test evaluate(norm2(A * x + b) + lambda * norm(x, 1)) ≈ 15.4907 atol =
atol rtol = rtol
@test p.constraints[1].dual ≈ [4.7062, 5.4475] atol = atol rtol = rtol
end
Expand Down
12 changes: 2 additions & 10 deletions src/reformulations/norm.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# deprecate these soon
norm_inf(x::AbstractExpr) = maximum(abs(x))

norm_1(x::AbstractExpr) = sum(abs(x))

norm_fro(x::AbstractExpr) = LinearAlgebra.norm2(vec(x))

"""
norm(x::AbstractExpr, p::Real=2)

Expand All @@ -22,13 +15,12 @@ function LinearAlgebra.norm(x::AbstractExpr, p::Real = 2)
if size(x, 2) > 1
x = vec(x)
end
# x is a vector
if p == 1
return norm_1(x)
return sum(abs(x))
elseif p == 2
return LinearAlgebra.norm2(x)
elseif p == Inf
return norm_inf(x)
return maximum(abs(x))
elseif p > 1
# TODO: allow tolerance in the rationalize step
return rationalnorm(x, rationalize(Int, float(p)))
Expand Down
12 changes: 10 additions & 2 deletions test/test_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ end

function test_add_constraints!_issue_380()
x = Variable(3, 3)
p = minimize(norm_1(x))
p = minimize(norm(x, 1))
y = randn(3, 3)
c = (norm2(x - y) <= 1)
@test length(p.constraints) == 0
Expand Down Expand Up @@ -936,7 +936,7 @@ function test_write_to_file()
return
end

function test_strict_inequality_deprecation()
function test_deprecation_strict_inequality()
x = Variable()
@test_logs (:warn,) x < 1
@test_logs (:warn,) 1 < x
Expand All @@ -949,6 +949,14 @@ function test_strict_inequality_deprecation()
return
end

function test_deprecation_norm()
x = Variable(2)
@test_deprecated norm_inf(x)
@test_deprecated norm_1(x)
@test_deprecated norm_fro(x)
return
end

end # TestUtilities

TestUtilities.runtests()
Loading