Skip to content

Commit

Permalink
Deprecate operatornorm in favor of opnorm
Browse files Browse the repository at this point in the history
opnorm will create OperatorNormAtom objects directly for p=2.
  • Loading branch information
ararslan committed Nov 6, 2018
1 parent 205884c commit 942a771
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/atoms/sdp_cone/operatornorm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Please read expressions.jl first.
#############################################################################
import LinearAlgebra: opnorm
export operatornorm, sigmamax
export sigmamax

### Operator norm

Expand All @@ -18,7 +18,7 @@ struct OperatorNormAtom <: AbstractExpr

function OperatorNormAtom(x::AbstractExpr)
children = (x,)
return new(:operatornorm, hash(children), children, (1,1))
return new(:opnorm, hash(children), children, (1,1))
end
end

Expand All @@ -40,7 +40,6 @@ function evaluate(x::OperatorNormAtom)
opnorm(evaluate(x.children[1]), 2)
end

operatornorm(x::AbstractExpr) = OperatorNormAtom(x)
sigmamax(x::AbstractExpr) = OperatorNormAtom(x)

function opnorm(x::AbstractExpr, p::Real=2)
Expand All @@ -50,14 +49,16 @@ function opnorm(x::AbstractExpr, p::Real=2)
if p == 1
return maximum(sum(abs(x), dims=1))
elseif p == 2
return operatornorm(x)
return OperatorNormAtom(x)
elseif p == Inf
return maximum(sum(abs(x), dims=2))
else
throw(ArgumentError("matrix p-norms only defined for p = 1, 2, and Inf"))
end
end

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

# Create the equivalent conic problem:
# minimize t
# subject to
Expand Down
4 changes: 2 additions & 2 deletions test/test_sdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ eye(n) = Matrix(1.0I, n, n)

@testset "operator norm atom" begin
y = Variable((3,3))
p = minimize(operatornorm(y), y[2,1]<=4, y[2,2]>=3, sum(y)>=12)
p = minimize(opnorm(y), y[2,1]<=4, y[2,2]>=3, sum(y)>=12)
@test vexity(p) == ConvexVexity()
solve!(p)
@test p.optval 4 atol=TOL
@test evaluate(operatornorm(y)) 4 atol=TOL
@test evaluate(opnorm(y)) 4 atol=TOL
end

@testset "sigma max atom" begin
Expand Down

0 comments on commit 942a771

Please sign in to comment.