Skip to content

Commit 317e94c

Browse files
authored
Fix tests for constant complex-valued atoms (#626)
1 parent ac92d4a commit 317e94c

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

src/complex_operate.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function complex_operate(
2222
) where {T}
2323
re = real_operate(+, T, (real(a) for a in args)...)
2424
im = real_operate(+, T, (imag(a) for a in args)...)
25+
if re isa SPARSE_VECTOR
26+
@assert im isa SPARSE_VECTOR
27+
return re .+ Base.im * im
28+
end
2529
return ComplexTape(re, im)
2630
end
2731

src/operate.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function complex_promote(v::AbstractVector{T}) where {T}
1313
return ComplexStructOfVec(v, spzeros(T, length(v)))
1414
end
1515

16+
function complex_promote(v::AbstractVector{<:Complex})
17+
return ComplexStructOfVec(real.(v), imag.(v))
18+
end
19+
1620
# Here we run `complex_promote` and dispatch to either `real_operate`
1721
# or `complex_operate` depending on `sign`. We also check the types
1822
# at this stage, instead of letting them fall to MethodErrors later.

src/real_operate.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,13 @@ end
314314

315315
# Here we have our two complex -> real functions
316316
# These are allowed these inputs:
317-
const ComplexToRealInputs{T} =
318-
Union{ComplexTape{T},SparseTape{T},ComplexStructOfVec{T},Vector{T}}
317+
const ComplexToRealInputs{T} = Union{
318+
ComplexTape{T},
319+
SparseTape{T},
320+
ComplexStructOfVec{T},
321+
SPARSE_VECTOR{T},
322+
SPARSE_VECTOR{Complex{T}},
323+
}
319324

320325
# `real`
321326
function real_operate(

test/test_atoms.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ end
101101
function _test_constant_atom(build_fn; value_type)
102102
context = Convex.Context{value_type}(MOI.Utilities.Model{value_type})
103103
atom = _to_constant(build_fn(context))
104-
if Convex.iscomplex(atom) || any(Convex.iscomplex, atom.children)
105-
return
106-
end
107104
form = Convex.conic_form!(context, atom)
108105
answer = evaluate(atom)
109106
if !(form isa AbstractVector)

0 commit comments

Comments
 (0)