Skip to content

Commit bcae63b

Browse files
authored
cleanup: delete internal type VectorAffineFunctionAsMatrix (#660)
* delete VectorAffineFunctionAsMatrix * fix
1 parent 958a9ae commit bcae63b

File tree

3 files changed

+36
-61
lines changed

3 files changed

+36
-61
lines changed

src/Convex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ for (root, _, files) in walkdir(joinpath(@__DIR__, "constraints"))
224224
end
225225

226226
include("SparseTape.jl")
227-
include("VectorAffineFunctionAsMatrix.jl")
227+
include("to_MOI.jl")
228228
include("ComplexTape.jl")
229229
include("operate.jl")
230230
include("complex_operate.jl")

src/VectorAffineFunctionAsMatrix.jl

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/to_MOI.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2014: Madeleine Udell and contributors
2+
#
3+
# Use of this source code is governed by a BSD-style license that can be found
4+
# in the LICENSE file or at https://opensource.org/license/bsd-2-clause
5+
6+
# This is a variant of MOI.VectorAffineFunction which represents
7+
# the transformation `matrix * variables + vector` lazily.
8+
to_vaf(tape::SPARSE_VECTOR) = tape
9+
10+
# convert to a usual VAF
11+
function to_vaf(tape::SparseTape{T}) where {T}
12+
I, J, V = SparseArrays.findnz(tape.operation.matrix)
13+
vats = Vector{MOI.VectorAffineTerm{T}}(undef, length(I))
14+
for (idx, n) in enumerate(eachindex(I, J, V))
15+
i = I[n]
16+
j = J[n]
17+
v = V[n]
18+
19+
vats[idx] = MOI.VectorAffineTerm{T}(
20+
i,
21+
MOI.ScalarAffineTerm{T}(v, tape.variables[j]),
22+
)
23+
end
24+
25+
return MOI.VectorAffineFunction{T}(vats, tape.operation.vector)
26+
end
27+
28+
# method for adding constraints and converting to standard VAFs as needed
29+
function MOI_add_constraint(model, f, set)
30+
return MOI.add_constraint(model, f, set)
31+
end
32+
33+
function MOI_add_constraint(model, f::SparseTape, set)
34+
return MOI_add_constraint(model, to_vaf(f), set)
35+
end

0 commit comments

Comments
 (0)