Skip to content

Commit 221de73

Browse files
committed
new print of constraints
1 parent fc2ad24 commit 221de73

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/plugins/variational_constraints/variational_constraints_engine.jl

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ function Base.show(io::IO, constraint::FactorizationConstraint{V, F} where {V, F
214214
print(io, join(getconstraint(constraint), ""))
215215
end
216216

217+
function Base.show(io::IO, constraint::FactorizationConstraint{V, F} where {V, F})
218+
print(io, "q(")
219+
print(io, join(getvariables(constraint), ", "))
220+
print(io, ") = ")
221+
print(io, getconstraint(constraint))
222+
end
223+
217224
"""
218225
A `MarginalFormConstraint` represents a single functional form constraint in a variational marginal constraint specification. We use type parametrization
219226
to dispatch on different types of constraints, for example `q(x, y) :: MvNormal` should be treated different from `q(x) :: Normal`.
@@ -263,7 +270,6 @@ end
263270
GeneralSubModelConstraints(fform::Function) = GeneralSubModelConstraints(fform, Constraints())
264271

265272
fform(c::GeneralSubModelConstraints) = c.fform
266-
Base.show(io::IO, constraint::GeneralSubModelConstraints) = print(io, "q(", getsubmodel(constraint), ") :: ", getconstraint(constraint))
267273

268274
getsubmodel(c::GeneralSubModelConstraints) = c.fform
269275
getconstraint(c::GeneralSubModelConstraints) = c.constraints
@@ -282,7 +288,15 @@ end
282288

283289
SpecificSubModelConstraints(submodel::FactorID) = SpecificSubModelConstraints(submodel, Constraints())
284290

285-
Base.show(io::IO, constraint::SpecificSubModelConstraints) = print(io, "q(", getsubmodel(constraint), ") :: ", getconstraint(constraint))
291+
function Base.show(io::IO, constraint::Union{SpecificSubModelConstraints, GeneralSubModelConstraints})
292+
print(
293+
IOContext(io, (:indent => get(io, :indent, 0) + 2), (:head => false)),
294+
"q(",
295+
getsubmodel(constraint),
296+
") = ",
297+
getconstraint(constraint)
298+
)
299+
end
286300

287301
getsubmodel(c::SpecificSubModelConstraints) = c.submodel
288302
getconstraint(c::SpecificSubModelConstraints) = c.constraints
@@ -325,9 +339,15 @@ Constraints(constraints::Vector) = begin
325339
end
326340

327341
function Base.show(io::IO, c::Constraints)
328-
print(io, "Constraints: \n")
342+
indent = get(io, :indent, 1)
343+
head = get(io, :head, true)
344+
if head
345+
print(io, "Constraints: \n")
346+
else
347+
print(io, "\n")
348+
end
329349
for constraint in getconstraints(c)
330-
print(io, " ")
350+
print(io, " "^indent)
331351
print(io, constraint)
332352
print(io, "\n")
333353
end

0 commit comments

Comments
 (0)