Skip to content

Commit

Permalink
Deprecate norm_inf, norm_1, norm_fro (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 17, 2024
1 parent 1b898be commit 2d97363
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
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)
2 changes: 0 additions & 2 deletions src/expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,3 @@ Base.lastindex(x::AbstractExpr) = length(x)
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))

@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()

0 comments on commit 2d97363

Please sign in to comment.