Skip to content

Commit af9116c

Browse files
committed
Revert "st" (i.e. remove State struct)
This reverts commit 1771bd9.
1 parent 1771bd9 commit af9116c

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/interface.jl

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
2-
struct State{T} backing::T end
3-
State(st::State) = st
4-
backing(st::State) = getfield(st, :backing)
5-
function Base.show(io::IO, st::State)
6-
print(io, "State(")
7-
show(IOContext(io, :compact => true), backing(st))
8-
print(io, ")")
9-
end
10-
111
patch(x, x̄) = x .-
122

133
function state(o, x)
@@ -17,30 +7,28 @@ function state(o, x)
177
return nothing
188
else
199
x, _ = functor(x)
20-
return State(map(x -> state(o, x), x))
10+
return map(x -> state(o, x), x)
2111
end
2212
end
2313

24-
function update(o, st, x, x̄s...)
14+
function _update(o, st, x, x̄s...)
2515
st, x̄ = apply(o, st, x, x̄s...)
2616
return st, patch(x, x̄)
2717
end
2818

29-
function update(o, state::State, x::T, x̄s...) where T
19+
function update(o, state, x::T, x̄s...) where T
3020
if all(isnothing, x̄s)
3121
return state, x
3222
elseif isnumeric(x)
33-
return update(o, backing(state), x, x̄s...)
23+
return _update(o, state, x, x̄s...)
3424
else
3525
x̄s = map(x̄ -> functor(typeof(x), x̄)[1], x̄s)
3626
x, restructure = functor(typeof(x), x)
37-
xstate = map((state, x, x̄s...) -> update(o, State(state), x, x̄s...), backing(state), x, x̄s...)
38-
return State(map(first, xstate)), restructure(map(last, xstate))
27+
xstate = map((state, x, x̄s...) -> update(o, state, x, x̄s...), state, x, x̄s...)
28+
return map(first, xstate), restructure(map(last, xstate))
3929
end
4030
end
4131

42-
update(::State, args...) = throw(ArgumentError("the optimiser state must be the 2nd argument"))
43-
4432
# default all rules to first order calls
4533
apply(o, state, x, dx, dxs...) = apply(o, state, x, dx)
4634

0 commit comments

Comments
 (0)