Skip to content

Commit b9c96ff

Browse files
committed
Fix format
1 parent 70fc8f8 commit b9c96ff

File tree

6 files changed

+55
-30
lines changed

6 files changed

+55
-30
lines changed

src/JuMP_wrapper.jl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ struct IteratorInExpr
2222
end
2323

2424
function Base.show(io::IO, i::IteratorInExpr)
25-
print(io, values_at(i.iterators[i.index.iterator_index], i.index.value_index))
25+
print(
26+
io,
27+
values_at(i.iterators[i.index.iterator_index], i.index.value_index),
28+
)
2629
print(io, "[i]")
2730
return
2831
end
@@ -31,7 +34,8 @@ JuMP._is_real(::Union{IteratorInExpr,IteratorIndex}) = true
3134
JuMP.moi_function(i::Union{IteratorInExpr,IteratorIndex}) = i
3235
JuMP.jump_function(_, i::Union{IteratorInExpr,IteratorIndex}) = i
3336

34-
struct ExprGenerator{E,V<:JuMP.AbstractVariableRef} <: AbstractVector{JuMP.GenericNonlinearExpr{V}}
37+
struct ExprGenerator{E,V<:JuMP.AbstractVariableRef} <:
38+
AbstractVector{JuMP.GenericNonlinearExpr{V}}
3539
expr::ExprTemplate{E,V}
3640
end
3741

@@ -47,7 +51,7 @@ function JuMP.jump_function(model, f::FunctionGenerator{F}) where {F}
4751
ExprTemplate{JuMP.jump_function_type(model, F)}(
4852
JuMP.jump_function(model, f.func),
4953
f.iterators,
50-
)
54+
),
5155
)
5256
end
5357

@@ -63,7 +67,7 @@ end
6367
function index_iterators(func::JuMP.GenericNonlinearExpr, index)
6468
return GenericNonlinearExpr(
6569
func.head,
66-
map(Base.Fix2(index_iterators, index), func.args)
70+
map(Base.Fix2(index_iterators, index), func.args),
6771
)
6872
end
6973

@@ -75,8 +79,8 @@ end
7579
Base.length(expr::ExprGenerator) = prod(_size(expr))
7680

7781
struct ParametrizedArray
78-
constraint
79-
iterators
82+
constraint::Any
83+
iterators::Any
8084
end
8185

8286
function JuMP.Containers.container(
@@ -85,7 +89,7 @@ function JuMP.Containers.container(
8589
::Type{ParametrizedArray},
8690
)
8791
its = iterators(indices.prod.iterators)
88-
ParametrizedArray(f(its...), its)
92+
return ParametrizedArray(f(its...), its)
8993
end
9094

9195
function JuMP.build_constraint(
@@ -115,7 +119,11 @@ function JuMP.check_belongs_to_model(con::IteratedConstraint, model)
115119
return JuMP.check_belongs_to_model(con.func.expr, model)
116120
end
117121

118-
function JuMP.build_constraint(::Function, expr::ExprGenerator, set::MOI.AbstractVectorSet)
122+
function JuMP.build_constraint(
123+
::Function,
124+
expr::ExprGenerator,
125+
set::MOI.AbstractVectorSet,
126+
)
119127
return IteratedConstraint(expr, set)
120128
end
121129

src/MOI_wrapper.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function num_values(it::Iterator)
2424
end
2525

2626
function values_at(it::Iterator, i)
27-
return it.values[(1 + it.length * (i - 1)):it.length * i]
27+
return it.values[(1+it.length*(i-1)):(it.length*i)]
2828
end
2929

3030
struct IteratorIndex
@@ -39,5 +39,9 @@ struct FunctionGenerator{F} <: MOI.AbstractVectorFunction
3939
iterators::Vector{Iterator}
4040
end
4141

42-
Base.copy(f::FunctionGenerator{F}) where {F} = FunctionGenerator{F}(copy(f.func), f.iterators)
43-
MOI.Utilities.is_canonical(f::FunctionGenerator) = MOI.Utilities.is_canonical(f.func)
42+
function Base.copy(f::FunctionGenerator{F}) where {F}
43+
return FunctionGenerator{F}(copy(f.func), f.iterators)
44+
end
45+
function MOI.Utilities.is_canonical(f::FunctionGenerator)
46+
return MOI.Utilities.is_canonical(f.func)
47+
end

src/operators.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ struct ExprTemplate{E,V<:JuMP.AbstractVariableRef} <: JuMP.AbstractJuMPScalar
1616
iterators::Iterators
1717
end
1818

19-
function ExprTemplate{E}(expr::JuMP.GenericNonlinearExpr{V}, iterators::Iterators) where {E,V}
19+
function ExprTemplate{E}(
20+
expr::JuMP.GenericNonlinearExpr{V},
21+
iterators::Iterators,
22+
) where {E,V}
2023
return ExprTemplate{E,V}(expr, iterators)
2124
end
2225

@@ -126,16 +129,9 @@ function _multivariate(f, op, x, y)
126129
_variable_ref_type(y),
127130
JuMP.VariableRef, # FIXME needed if both are iterators
128131
)
129-
nl = JuMP.GenericNonlinearExpr{V}(
130-
op,
131-
_expr(x),
132-
_expr(y),
133-
)
132+
nl = JuMP.GenericNonlinearExpr{V}(op, _expr(x), _expr(y))
134133
E = JuMP._MA.promote_operation(f, _type(x), _type(y))
135-
return ExprTemplate{E}(
136-
nl,
137-
_check_equal(_iterators(x), _iterators(y))
138-
)
134+
return ExprTemplate{E}(nl, _check_equal(_iterators(x), _iterators(y)))
139135
end
140136

141137
# Multivariate operators

src/print.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ function Base.show(io::IO, f::Union{ExprGenerator,ExprTemplate})
22
return print(io, JuMP.function_string(MIME("text/plain"), f))
33
end
44

5-
function Base.show(io::IO, mime::MIME"text/latex", f::Union{ExprGenerator,ExprTemplate})
5+
function Base.show(
6+
io::IO,
7+
mime::MIME"text/latex",
8+
f::Union{ExprGenerator,ExprTemplate},
9+
)
610
str = JuMP.function_string(mime, f)
711
str = JuMP._wrap_in_inline_math_mode(str)
812
return print(io, str)
913
end
1014

11-
function Base.show(io::IO, mime::MIME"text/plain", f::Union{ExprGenerator,ExprTemplate})
15+
function Base.show(
16+
io::IO,
17+
mime::MIME"text/plain",
18+
f::Union{ExprGenerator,ExprTemplate},
19+
)
1220
str = JuMP.function_string(mime, f)
1321
return print(io, str)
1422
end

test/JuMP_wrapper.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,25 @@ function test_container()
3030

3131
keys = [:a, :b]
3232

33-
con_ref = @constraint(model, [i in keys], x + d1[i] >= d2[i], container = ParametrizedArray)
33+
con_ref = @constraint(
34+
model,
35+
[i in keys],
36+
x + d1[i] >= d2[i],
37+
container = ParametrizedArray
38+
)
3439
con = constraint_object(con_ref.constraint)
3540
@test con isa IteratedConstraint
3641
con_it_expr = jump_function(con)
3742
@test con_it_expr isa ExprGenerator
3843
con_expr = con_it_expr.expr
39-
@test sprint(show, con_ref) == "ParametrizedArray(((x + (IteratorIndex(1, 1))) - (IteratorIndex(2, 2))) - 0.0, Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]), Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]) ∈ MathOptInterface.Nonnegatives(4), (iterator([:a, :b]),))"
40-
@test sprint(show, MIME"text/latex"(), con_ref) == "ParametrizedArray(((x + (IteratorIndex(1, 1))) - (IteratorIndex(2, 2))) - 0.0, Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]), Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]) ∈ MathOptInterface.Nonnegatives(4), (iterator([:a, :b]),))"
41-
@test sprint(show, con_expr) == "((x + (IteratorIndex(1, 1))) - (IteratorIndex(2, 2))) - 0.0"
42-
@test sprint(show, MIME"text/latex"(), con_expr) == "\$ {\\left({\\left({x} + {\\left(IteratorIndex(1, 1)\\right)}\\right)} - {\\left(IteratorIndex(2, 2)\\right)}\\right)} - {0.0} \$"
44+
@test sprint(show, con_ref) ==
45+
"ParametrizedArray(((x + (IteratorIndex(1, 1))) - (IteratorIndex(2, 2))) - 0.0, Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]), Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]) ∈ MathOptInterface.Nonnegatives(4), (iterator([:a, :b]),))"
46+
@test sprint(show, MIME"text/latex"(), con_ref) ==
47+
"ParametrizedArray(((x + (IteratorIndex(1, 1))) - (IteratorIndex(2, 2))) - 0.0, Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]), Iterator(2, [-1.0, 1.0, 3.141592653589793, 0.0]) ∈ MathOptInterface.Nonnegatives(4), (iterator([:a, :b]),))"
48+
@test sprint(show, con_expr) ==
49+
"((x + (IteratorIndex(1, 1))) - (IteratorIndex(2, 2))) - 0.0"
50+
@test sprint(show, MIME"text/latex"(), con_expr) ==
51+
"\$ {\\left({\\left({x} + {\\left(IteratorIndex(1, 1)\\right)}\\right)} - {\\left(IteratorIndex(2, 2)\\right)}\\right)} - {0.0} \$"
4352

4453
i = GenOpt.iterator(keys)
4554
expr = x + d1[i] - d2[i]

test/operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ function test_getindex()
3333
i = GenOpt.iterator([:a, :b])
3434

3535
_test_iterator(d1[i], [-1, 1])
36-
_test_iterator(d2[i], Real[π, 0.0])
36+
return _test_iterator(d2[i], Real[π, 0.0])
3737
end
3838

3939
function test_univariate()
4040
i = GenOpt.iterator([2, -3])
4141
_test_iterator(+i, [2, -3])
42-
_test_iterator(-i, [-2, 3])
42+
return _test_iterator(-i, [-2, 3])
4343
end
4444

4545
function test_multivariate()

0 commit comments

Comments
 (0)