@@ -74,6 +74,46 @@ function _test_atom(build_fn, target_string::String; value_type = Float64)
74
74
@test Convex. monotonicity (atom) isa NTuple{N,Convex. Monotonicity}
75
75
@test Convex. curvature (atom) isa Convex. Vexity
76
76
_test_reformulation (build_fn, target_string; value_type)
77
+ _test_constant_atom (build_fn; value_type)
78
+ return
79
+ end
80
+
81
+ function _to_constant (expr:: Convex.AbstractVariable )
82
+ if Convex. iscomplex (expr)
83
+ val = rand (Float64, size (expr)) + im * rand (Float64, size (expr))
84
+ else
85
+ val = rand (Float64, size (expr))
86
+ end
87
+ if size (expr, 1 ) == size (expr, 2 )
88
+ val = val' * val
89
+ end
90
+ return constant (val)
91
+ end
92
+
93
+ _to_constant (x:: Convex.Value ) = x
94
+ _to_constant (x:: Union{Convex.Constant,Convex.ComplexConstant} ) = x
95
+
96
+ function _to_constant (e:: Convex.AbstractExpr )
97
+ e. children = map (_to_constant, e. children)
98
+ return e
99
+ end
100
+
101
+ function _test_constant_atom (build_fn; value_type)
102
+ context = Convex. Context {value_type} (MOI. Utilities. Model{value_type})
103
+ atom = _to_constant (build_fn (context))
104
+ if Convex. iscomplex (atom) || any (Convex. iscomplex, atom. children)
105
+ return
106
+ end
107
+ form = Convex. conic_form! (context, atom)
108
+ answer = evaluate (atom)
109
+ if ! (form isa AbstractVector)
110
+ return # The reformulation is still in terms of MOI variables.
111
+ end
112
+ if answer isa Number
113
+ @test only (form) ≈ answer
114
+ else
115
+ @test form ≈ vec (answer)
116
+ end
77
117
return
78
118
end
79
119
0 commit comments