Skip to content

Commit

Permalink
remove unnec loopvar
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Sep 30, 2024
1 parent a3eb9b5 commit 9eb383d
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 60 deletions.
19 changes: 7 additions & 12 deletions axon/looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ func LooperStdPhases(man *looper.Manager, ctx *Context, net *Network, plusStart,
man.AddEventAllModes(etime.Cycle, minusPhase, beta1, beta2, plusPhase)

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[trl].OnStart.Add("NewState", func() {
net.NewState(ctx)
ctx.NewState(mode)
ctx.NewState(m)
})
stack.Loops[trl].OnEnd.Add("PlusPhase:End", func() {
net.PlusPhase(ctx)
Expand Down Expand Up @@ -92,10 +91,9 @@ func LooperSimCycleAndLearn(man *looper.Manager, net *Network, ctx *Context, vie

// Set variables on ss that are referenced elsewhere, such as ApplyInputs.
for m, loops := range man.Stacks {
curMode := m // For closures.
for _, loop := range loops.Loops {
loop.OnStart.Add("SetCtxMode", func() {
ctx.Mode = curMode
ctx.Mode = m
})
}
}
Expand All @@ -107,7 +105,6 @@ func LooperSimCycleAndLearn(man *looper.Manager, net *Network, ctx *Context, vie
// then Epoch does not reset the log below it
func LooperResetLogBelow(man *looper.Manager, logs *elog.Logs, except ...etime.Times) {
for m, stack := range man.Stacks {
curMode := m // For closures.
for t, loop := range stack.Loops {
curTime := t
isExcept := false
Expand All @@ -119,7 +116,7 @@ func LooperResetLogBelow(man *looper.Manager, logs *elog.Logs, except ...etime.T
}
if below := stack.TimeBelow(curTime); !isExcept && below != etime.NoTime {
loop.OnStart.Add("ResetLog"+below.String(), func() {
logs.ResetLog(curMode, below)
logs.ResetLog(m, below)
})
}
}
Expand All @@ -129,7 +126,6 @@ func LooperResetLogBelow(man *looper.Manager, logs *elog.Logs, except ...etime.T
// LooperUpdateNetView adds netview update calls at each time level
func LooperUpdateNetView(man *looper.Manager, viewupdt *netview.ViewUpdate, net *Network, ctrUpdateFunc func(tm etime.Times)) {
for m, stack := range man.Stacks {
curMode := m // For closures.
for t, loop := range stack.Loops {
curTime := t
if curTime != etime.Cycle {
Expand All @@ -139,7 +135,7 @@ func LooperUpdateNetView(man *looper.Manager, viewupdt *netview.ViewUpdate, net
})
}
}
cycLoop := man.GetLoop(curMode, etime.Cycle)
cycLoop := man.GetLoop(m, etime.Cycle)
cycLoop.OnEnd.Add("GUI:UpdateNetView", func() {
cyc := cycLoop.Counter.Cur
ctrUpdateFunc(etime.Cycle)
Expand All @@ -151,18 +147,17 @@ func LooperUpdateNetView(man *looper.Manager, viewupdt *netview.ViewUpdate, net
// LooperUpdatePlots adds plot update calls at each time level
func LooperUpdatePlots(man *looper.Manager, gui *egui.GUI) {
for m, stack := range man.Stacks {
curMode := m // For closures.
for t, loop := range stack.Loops {
curTime := t
curLoop := loop
if curTime == etime.Cycle {
curLoop.OnEnd.Add("GUI:UpdatePlot", func() {
cyc := curLoop.Counter.Cur
gui.GoUpdateCyclePlot(curMode, cyc)
gui.GoUpdateCyclePlot(m, cyc)
})
} else {
curLoop.OnEnd.Add("GUI:UpdatePlot", func() {
gui.GoUpdatePlot(curMode, curTime)
gui.GoUpdatePlot(m, curTime)
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/choose/choose.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/deep_fsa/deep_fsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/deep_move/deep_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/deep_music/deep_music.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/dls/dls.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code
for m := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/hip/hip.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ func (ss *Sim) ConfigLoops() {
ss.Net.ConfigLoopsHip(&ss.Context, man, &ss.Config.Hip, &ss.PretrainMode)

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
6 changes: 2 additions & 4 deletions examples/inhib/inhib.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,15 @@ func (ss *Sim) ConfigLoops() {
})
}
for m, loops := range man.Stacks {
curMode := m // For closures.
for _, loop := range loops.Loops {
loop.OnStart.Add("SetTimeVal", func() {
time.Mode = curMode
time.Mode = m
})
}
}

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/mpi/ra25.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ func (ss *Sim) ConfigLoops() {
})

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
1 change: 0 additions & 1 deletion examples/objrec/objrec.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for mode := range man.Stacks {
mode := mode // For closures
stack := man.Stacks[mode]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
Expand Down
9 changes: 4 additions & 5 deletions examples/pcore_ds/pcore_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,11 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
seq := man.Stacks[mode].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[mode].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(mode, seq, trial)
seq := man.Stacks[m].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[m].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(m, seq, trial)
})
}
// note: auto applies to all
Expand Down
11 changes: 5 additions & 6 deletions examples/pcore_vs/pcore_vs.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,14 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
seq := man.Stacks[mode].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[mode].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(mode, seq, trial)
seq := man.Stacks[m].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[m].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(m, seq, trial)
})
stack.Loops[etime.Trial].OnEnd.Add("GatedAction", func() {
trial := man.Stacks[mode].Loops[etime.Trial].Counter.Cur
trial := man.Stacks[m].Loops[etime.Trial].Counter.Cur
if trial == 1 {
ss.GatedAction()
}
Expand Down
9 changes: 4 additions & 5 deletions examples/pfcmaint/pfcmaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,11 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
seq := man.Stacks[mode].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[mode].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(mode, seq, trial)
seq := man.Stacks[m].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[m].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(m, seq, trial)
})
}

Expand Down
3 changes: 1 addition & 2 deletions examples/pvlv/pvlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/ra25/ra25.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/ra25x/ra25x.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
3 changes: 1 addition & 2 deletions examples/rl/rl.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
ss.ApplyInputs()
})
Expand Down
9 changes: 4 additions & 5 deletions examples/vspatch/vspatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,11 @@ func (ss *Sim) ConfigLoops() {
axon.LooperSimCycleAndLearn(man, ss.Net, &ss.Context, &ss.ViewUpdate) // std algo code

for m, _ := range man.Stacks {
mode := m // For closures
stack := man.Stacks[mode]
stack := man.Stacks[m]
stack.Loops[etime.Trial].OnStart.Add("ApplyInputs", func() {
seq := man.Stacks[mode].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[mode].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(mode, seq, trial)
seq := man.Stacks[m].Loops[etime.Sequence].Counter.Cur
trial := man.Stacks[m].Loops[etime.Trial].Counter.Cur
ss.ApplyInputs(m, seq, trial)
})
}

Expand Down

0 comments on commit 9eb383d

Please sign in to comment.