Skip to content

Commit ec6cafa

Browse files
authored
use Accessors, not Setfield (#411)
* use Accessors, not Setfield * workaround version * should just go read the docs... * bump lowest version as required by Accessors * aqua * compat bounds
1 parent ac16874 commit ec6cafa

File tree

18 files changed

+150
-140
lines changed

18 files changed

+150
-140
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
version:
18-
- '1.0' # lowest supported version; though possibly with errors
18+
- '1.6' # lowest supported version; though possibly with errors
1919
- '1.6' # LTS support
2020
- '1' # last released version
2121
os:

Project.toml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
name = "Roots"
22
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
3-
version = "2.0.22"
3+
version = "2.1.0"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
77
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
88
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
9-
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
10-
9+
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
1110

1211
[weakdeps]
1312
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
@@ -16,14 +15,25 @@ SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
1615
SymPyPythonCall = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
1716

1817
[compat]
18+
Accessors = "0.1.33"
19+
Aqua = "0.8"
20+
BenchmarkTools = "1.4"
1921
ChainRulesCore = "1"
22+
ChainRulesTestUtils = "1"
2023
CommonSolve = "0.1, 0.2"
2124
ForwardDiff = "0.10"
25+
IntervalRootFinding = "0.5"
26+
JSON = "0.21"
27+
Polynomials = "1,2,3,4"
28+
SpecialFunctions = "1,2"
29+
Statistics = "1"
2230
SymPy = "1,2"
2331
SymPyPythonCall = "0.1, 0.2, 1"
24-
Setfield = "0.7, 0.8, 1"
32+
Unitful = "1"
33+
Zygote = "0.6"
34+
Test = "<0.0.1, 1"
2535
Printf = "<0.0.1, 1"
26-
julia = "1.0"
36+
julia = "1.6"
2737

2838

2939
[extensions]
@@ -37,7 +47,7 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3747
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3848
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
3949
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
40-
#IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
50+
IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
4151
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
4252
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
4353
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

docs/src/roots.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,10 @@ julia> function init_state(::Chandrapatla, F, x₀, x₁, fx₀, fx₁)
11881188
end
11891189
```
11901190

1191-
The main algorithm is implemented in the `update_state` method. The `@set!` macro from `Setfield.jl` is used to modify a state object, which otherwise is immutable.
1191+
The main algorithm is implemented in the `update_state` method. The `@reset` macro from `Accessors.jl` is used to modify a state object, which otherwise is immutable.
11921192

11931193
```julia
1194-
julia> import Roots.Setfield: @set!;
1194+
julia> import Roots.Accessors: @reset;
11951195

11961196
julia> function Roots.update_state(::Chandrapatla, F, o, options, l=NullTracks())
11971197

@@ -1217,12 +1217,12 @@ julia> function Roots.update_state(::Chandrapatla, F, o, options, l=NullTracks()
12171217
fa, fc = fₜ, fa
12181218
end
12191219

1220-
@set! o.xn0 = a
1221-
@set! o.xn1 = b
1222-
@set! o.c = c
1223-
@set! o.fxn0 = fa
1224-
@set! o.fxn1 = fb
1225-
@set! o.fc = fc
1220+
@reset o.xn0 = a
1221+
@reset o.xn1 = b
1222+
@reset o.c = c
1223+
@reset o.fxn0 = fa
1224+
@reset o.fxn1 = fb
1225+
@reset o.fc = fc
12261226

12271227
return (o, false)
12281228
end

src/Bracketing/alefeld_potra_shi.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ function update_state(
113113
fa, fb, fd = ps.fa, ps.fb, ps.fd
114114

115115
if iszero(fa) || iszero(fb) || (b - a) <= tolₑ(a, b, fa, fb, atol, rtol)
116-
@set! o.xn0 = a
117-
@set! o.xn1 = b
118-
@set! o.fxn0 = fa
119-
@set! o.fxn1 = fb
116+
@reset o.xn0 = a
117+
@reset o.xn1 = b
118+
@reset o.fxn0 = fa
119+
@reset o.fxn1 = fb
120120
return o, true
121121
end
122122

@@ -129,10 +129,10 @@ function update_state(
129129
ā, b̄, d, fā, fb̄, fd = bracket(a, b, x, fa, fb, fx)
130130

131131
if iszero(fx) || (b̄ - ā) <= tolₑ(ā, b̄, fā, fb̄, atol, rtol)
132-
@set! o.xn0 =
133-
@set! o.xn1 =
134-
@set! o.fxn0 = fā
135-
@set! o.fxn1 = fb̄
132+
@reset o.xn0 =
133+
@reset o.xn1 =
134+
@reset o.fxn0 = fā
135+
@reset o.fxn1 = fb̄
136136
return o, true
137137
end
138138

@@ -168,14 +168,14 @@ function update_state(
168168
a, b, d, fa, fb, fd = bracket(â, b̂, m, fâ, fb̂, fm)
169169
end
170170

171-
@set! o.xn0 = a
172-
@set! o.xn1 = b
173-
@set! o.d = d
174-
@set! o.ee = ee
175-
@set! o.fxn0 = fa
176-
@set! o.fxn1 = fb
177-
@set! o.fd = fd
178-
@set! o.fee = fee
171+
@reset o.xn0 = a
172+
@reset o.xn1 = b
173+
@reset o.d = d
174+
@reset o.ee = ee
175+
@reset o.fxn0 = fa
176+
@reset o.fxn1 = fb
177+
@reset o.fd = fd
178+
@reset o.fee = fee
179179

180180
return o, false
181181
end
@@ -204,12 +204,12 @@ function calculateΔ(::A2425{K}, F::Callable_Function, c₀::T, ps) where {K,T}
204204
end
205205
end
206206

207-
@set! ps.a = a
208-
@set! ps.fa = fa
209-
@set! ps.b = b
210-
@set! ps.fb = fb
211-
@set! ps.d = d
212-
@set! ps.fd = fd
207+
@reset ps.a = a
208+
@reset ps.fa = fa
209+
@reset ps.b = b
210+
@reset ps.fb = fb
211+
@reset ps.d = d
212+
@reset ps.fd = fd
213213

214214
c₀ - c, ps
215215
end
@@ -261,14 +261,14 @@ function calculateΔ(::A57{K}, F::Callable_Function, c₀::T, ps) where {K,T}
261261
break
262262
end
263263
end
264-
@set! ps.a = a
265-
@set! ps.fa = fa
266-
@set! ps.b = b
267-
@set! ps.fb = fb
268-
@set! ps.d = d
269-
@set! ps.fd = fd
270-
@set! ps.ee = ee
271-
@set! ps.fee = fee
264+
@reset ps.a = a
265+
@reset ps.fa = fa
266+
@reset ps.b = b
267+
@reset ps.fb = fb
268+
@reset ps.d = d
269+
@reset ps.fd = fd
270+
@reset ps.ee = ee
271+
@reset ps.fee = fee
272272

273273
c₀ - c, ps
274274
end

src/Bracketing/bisection.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ function update_state(
160160
a, fa = c, fc
161161
end
162162

163-
@set! o.xn0 = a
164-
@set! o.xn1 = b
165-
@set! o.fxn0 = fa
166-
@set! o.fxn1 = fb
163+
@reset o.xn0 = a
164+
@reset o.xn1 = b
165+
@reset o.fxn0 = fa
166+
@reset o.fxn1 = fb
167167

168168
return o, false
169169
end
@@ -213,10 +213,10 @@ function solve!(
213213
end
214214

215215
## ----
216-
@set! state.xn0 = a
217-
@set! state.xn1 = b
218-
@set! state.fxn0 = fa
219-
@set! state.fxn1 = fb
216+
@reset state.xn0 = a
217+
@reset state.xn1 = b
218+
@reset state.fxn0 = fa
219+
@reset state.fxn1 = fb
220220

221221
log_step(l, M, state)
222222
ctr += 1

src/Bracketing/brent.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ function update_state(
9090
end
9191

9292
state = _set(state, (b, fb), (a, fa))
93-
@set! state.c = c
94-
@set! state.d = d
95-
@set! state.fc = fc
96-
@set! state.mflag = mflag
93+
@reset state.c = c
94+
@reset state.d = d
95+
@reset state.fc = fc
96+
@reset state.mflag = mflag
9797

9898
return state, false
9999
end

src/Bracketing/chandrapatlu.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ function update_state(
5959
end
6060

6161
o = _set(o, (a, fa), (b, fb)) # a is xₙ, b is xₙ₋₁
62-
@set! o.c = c
63-
@set! o.fc = fc
62+
@reset o.c = c
63+
@reset o.fc = fc
6464

6565
return (o, false)
6666
end

src/Bracketing/itp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function update_state(M::ITP, F, o::ITPState{T,S,R}, options, l=NullTracks()) wh
7777
# we need the options to set the ϵ⋅2^n₁₂ part of r.
7878
ϵ = max(options.xabstol, max(abs(a), abs(b)) * options.xreltol)
7979
ϵ2n₁₂ = ϵ * exp2(ceil(Int, log2((b - a) / (2ϵ))) + M.n₀)
80-
@set! o.ϵ2n₁₂ = ϵ2n₁₂
80+
@reset o.ϵ2n₁₂ = ϵ2n₁₂
8181
end
8282

8383
Δ = b - a
@@ -109,7 +109,7 @@ function update_state(M::ITP, F, o::ITPState{T,S,R}, options, l=NullTracks()) wh
109109
end
110110

111111
o = _set(o, (b, fb), (a, fa))
112-
@set! o.j = j + 1
112+
@reset o.j = j + 1
113113

114114
return o, false
115115
end

src/Derivative/halley_like.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ function update_state(
4646
fxn1::S, (r1, r2) = F(xn1)
4747
incfn(l, 3)
4848

49-
@set! o.xn0 = xn
50-
@set! o.xn1 = xn1
51-
@set! o.fxn0 = fxn
52-
@set! o.fxn1 = fxn1
53-
@set! o.Δ = r1
54-
@set! o.ΔΔ = r2
49+
@reset o.xn0 = xn
50+
@reset o.xn1 = xn1
51+
@reset o.fxn0 = fxn
52+
@reset o.fxn1 = fxn1
53+
@reset o.Δ = r1
54+
@reset o.ΔΔ = r2
5555

5656
return o, false
5757
end

0 commit comments

Comments
 (0)