Skip to content

Commit eb71f89

Browse files
arnavk23tmigot
andauthored
Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
1 parent 04c8ad1 commit eb71f89

File tree

5 files changed

+9
-17
lines changed

5 files changed

+9
-17
lines changed

src/ADNLPProblems/toint.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export toint
22

33
function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
function f(x; n = length(x))
5-
n_local = n
65
s = zero(T)
76
for i = 1:n_local
87
xi = x[i]
@@ -30,6 +29,6 @@ function toint(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) wher
3029
return s / T(n_local)
3130
end
3231

33-
x0 = fill(1, n)
32+
x0 = fill(one(T), n)
3433
return ADNLPModels.ADNLPModel(f, x0, name = "toint"; kwargs...)
3534
end

src/ADNLPProblems/trig.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ export trig
22

33
function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
function f(x; n = length(x))
5-
n_local = n
65
s = zero(T)
76
for i = 1:n_local
8-
xi = x[i]
97
term = i * (1 - cos(xi))
108

11-
jlo = max(1, i - 2)
12-
jhi = min(n_local, i + 2)
13-
for j = jlo:jhi
9+
for j = max(1, i - 2):min(n, i + 2)
1410
aij = 5 * (1 + mod(i, 5) + mod(j, 5))
1511
bij = (i + j) / 10
1612
term += aij * sin(x[j]) + bij * cos(x[j])
@@ -27,9 +23,9 @@ function trig(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where
2723

2824
s += term
2925
end
30-
return s / T(n_local)
26+
return s / n
3127
end
3228

33-
x0 = fill(1 / n, n)
29+
x0 = fill(one(T) / n, n)
3430
return ADNLPModels.ADNLPModel(f, x0, name = "trig"; kwargs...)
3531
end

src/ADNLPProblems/trigb.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ export trigb
22

33
function trigb(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
function f(x; n = length(x))
5-
n_local = n
65
s = zero(T)
76
for i = 1:n_local
8-
xi = x[i]
9-
left = (i == 1) ? zero(T) : x[i - 1]
10-
right = (i == n_local) ? zero(T) : x[i + 1]
7+
xim = (i == 1) ? zero(T) : x[i - 1]
8+
xip = (i == n_local) ? zero(T) : x[i + 1]
119
term = i * (1 - cos(xi) + sin(left) - sin(right))
1210
s += term
1311
end
1412
return s
1513
end
1614

17-
x0 = fill(1, n)
15+
x0 = fill(one(T), n)
1816
return ADNLPModels.ADNLPModel(f, x0, name = "trigb"; kwargs...)
1917
end

src/Meta/trigb.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ get_trigb_nlin(; n::Integer = default_nvar, kwargs...) = 0
2424
get_trigb_nnln(; n::Integer = default_nvar, kwargs...) = 0
2525
get_trigb_nequ(; n::Integer = default_nvar, kwargs...) = 0
2626
get_trigb_nineq(; n::Integer = default_nvar, kwargs...) = 0
27-
get_trigb_nls_nequ(; n::Integer = default_nvar, kwargs...) = 2 * n

src/PureJuMP/trigb.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function trigb(args...; n::Int = default_nvar, kwargs...)
2020
Min,
2121
sum(
2222
i * (
23-
(1 - cos(x[i])) + ((i == 1) ? sin(0.0) : sin(x[i - 1])) -
24-
((i == n) ? sin(0.0) : sin(x[i + 1]))
23+
(1 - cos(x[i])) + ((i == 1) ? sin(0) : sin(x[i - 1])) -
24+
((i == n) ? sin(0) : sin(x[i + 1]))
2525
) for i = 1:n
2626
)
2727
)

0 commit comments

Comments
 (0)