Skip to content

Commit 5063429

Browse files
committed
less allocation
1 parent bb88a88 commit 5063429

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/rules.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end
141141
Rprop(η = 1f-3, ℓ = (5f-1, 1.2f0), Γ = (1f-6, 50f0))
142142
143143
Optimizer using the
144-
[Rprop](https://ieeexplore.ieee.org/document/298623) algorithm. An full-batch
144+
[Rprop](https://ieeexplore.ieee.org/document/298623) algorithm. A full-batch
145145
learning algorithm that depends only on the sign of the gradient.
146146
147147
# Parameters
@@ -166,14 +166,11 @@ function apply!(o::Rprop, state, x, dx)
166166
ℓ, Γ = o.ell, o.gamma
167167
g, η = state
168168

169-
signs = broadcast(g, dx) do g, dx
170-
s = sign(g * dx)
171-
s > 0 ? ℓ[2] : s < 0 ? ℓ[1] : one(eltype(dx))
169+
T = eltype(dx)
170+
g, η = broadcast(g, η, dx) do g, η, dx
171+
g * dx > 0 ? (g, min* ℓ[2], Γ[2])) : g * dx < 0 ? (zero(T), max* ℓ[1], Γ[1])) : (g, η)
172172
end
173173

174-
@.. η = clamp* signs, Γ[1], Γ[2])
175-
@.. g = (signs !== ℓ[1]) * dx
176-
177174
dx′ = @lazy η * sign(g)
178175
return (g, η), dx′
179176
end

0 commit comments

Comments
 (0)