Skip to content

Commit bbe64e4

Browse files
author
Randall C. O'Reilly
committed
printf stuff heuristically good..
1 parent 3c6a762 commit bbe64e4

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@ We have modified the `printer` code in the `pyprint` package to instead print ou
1212

1313
* class comments -> """
1414

15-
* basic repl is done -- need to repl % thing..
16-
* fmt.Sprintf -> "...." % (params, ...)
17-
* fmt.Printf -> print "..." % (params, ...)
18-
1915
* switch -> ifs.. -- grab switch expr and put into each if

pymove.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ func pyMove(src []byte) []byte {
3535
class := []byte("class ")
3636
pymark := []byte("<<<<")
3737
pyend := []byte(">>>>")
38-
fmts := []byte("fmt.")
3938
fmtPrintf := []byte("fmt.Printf")
40-
fmtSprintf := []byte("fmt.Sprintf")
39+
fmtSprintf := []byte("fmt.Sprintf(")
4140
prints := []byte("print")
4241
endclass := "EndClass: "
4342
method := "Method: "
@@ -115,10 +114,18 @@ func pyMove(src []byte) []byte {
115114
li -= 2
116115
}
117116
}
118-
case bytes.Contains(ln, fmts):
119-
ln = bytes.Replace(ln, fmtPrintf, prints, -1)
117+
case bytes.Contains(ln, fmtSprintf):
118+
if bytes.Contains(ln, []byte("%")) {
119+
ln = bytes.Replace(ln, []byte(`", `), []byte(`" % (`), -1)
120+
}
120121
ln = bytes.Replace(ln, fmtSprintf, []byte{}, -1)
121122
lines[li] = ln
123+
case bytes.Contains(ln, fmtPrintf):
124+
if bytes.Contains(ln, []byte("%")) {
125+
ln = bytes.Replace(ln, []byte(`", `), []byte(`" % `), -1)
126+
}
127+
ln = bytes.Replace(ln, fmtPrintf, prints, -1)
128+
lines[li] = ln
122129
}
123130
li++
124131
}

testdata/ra25.golden

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ class Sim:
320320
and add a few tabs at the end to allow for expansion..
321321
"""
322322
if train:
323-
return ("Run:\t%d\tEpoch:\t%d\tTrial:\t%d\tCycle:\t%d\tName:\t%v\t\t\t", ss.TrainEnv.Run.Cur, ss.TrainEnv.Epoch.Cur, ss.TrainEnv.Trial.Cur, ss.Time.Cycle, ss.TrainEnv.TrialName)
323+
return "Run:\t%d\tEpoch:\t%d\tTrial:\t%d\tCycle:\t%d\tName:\t%v\t\t\t" % (ss.TrainEnv.Run.Cur, ss.TrainEnv.Epoch.Cur, ss.TrainEnv.Trial.Cur, ss.Time.Cycle, ss.TrainEnv.TrialName)
324324
else:
325-
return ("Run:\t%d\tEpoch:\t%d\tTrial:\t%d\tCycle:\t%d\tName:\t%v\t\t\t", ss.TrainEnv.Run.Cur, ss.TrainEnv.Epoch.Cur, ss.TestEnv.Trial.Cur, ss.Time.Cycle, ss.TestEnv.TrialName)
325+
return "Run:\t%d\tEpoch:\t%d\tTrial:\t%d\tCycle:\t%d\tName:\t%v\t\t\t" % (ss.TrainEnv.Run.Cur, ss.TrainEnv.Epoch.Cur, ss.TestEnv.Trial.Cur, ss.Time.Cycle, ss.TestEnv.TrialName)
326326

327327
def UpdateView(ss, train):
328328
if ss.NetView != nil and ss.NetView.IsVisible():
@@ -440,7 +440,7 @@ class Sim:
440440
ss.LogRun(ss.RunLog)
441441
if ss.SaveWts:
442442
fnm = ss.WeightsFileName()
443-
print("Saving Weights to: %v\n", fnm)
443+
print("Saving Weights to: %v\n" % fnm)
444444
ss.Net.SaveWtsJSON(gi.FileName(fnm))
445445

446446
def NewRun(ss):
@@ -705,7 +705,7 @@ class Sim:
705705
RunEpochName returns a string with the run and epoch numbers with leading zeros, suitable
706706
for using in weights file names. Uses 3, 5 digits for each.
707707
"""
708-
return ("%03d_%05d", run, epc)
708+
return "%03d_%05d" % (run, epc)
709709

710710
def WeightsFileName(ss):
711711
"""
@@ -1206,7 +1206,7 @@ class Sim:
12061206
else:
12071207
if notss.IsRunning:
12081208
ss.IsRunning = True
1209-
print("testing index: %v\n", idxs[0])
1209+
print("testing index: %v\n" % idxs[0])
12101210
ss.TestItem(idxs[0])
12111211
ss.IsRunning = False
12121212
vp.SetNeedsFullRender()))
@@ -1316,9 +1316,9 @@ class Sim:
13161316
ss.Init()
13171317

13181318
if note != "":
1319-
print("note: %s\n", note)
1319+
print("note: %s\n" % note)
13201320
if ss.ParamSet != "":
1321-
print("Using ParamSet: %s\n", ss.ParamSet)
1321+
print("Using ParamSet: %s\n" % ss.ParamSet)
13221322

13231323
if saveEpcLog:
13241324
err
@@ -1328,7 +1328,7 @@ class Sim:
13281328
log.Println(err)
13291329
ss.TrnEpcFile = nil
13301330
else:
1331-
print("Saving epoch log to: %v\n", fnm)
1331+
print("Saving epoch log to: %v\n" % fnm)
13321332
defer ss.TrnEpcFile.Close()
13331333
if saveRunLog:
13341334
err
@@ -1338,11 +1338,11 @@ class Sim:
13381338
log.Println(err)
13391339
ss.RunFile = nil
13401340
else:
1341-
print("Saving run log to: %v\n", fnm)
1341+
print("Saving run log to: %v\n" % fnm)
13421342
defer ss.RunFile.Close()
13431343
if ss.SaveWts:
13441344
print("Saving final weights per run\n")
1345-
print("Running %d Runs\n", ss.MaxRuns)
1345+
print("Running %d Runs\n" % ss.MaxRuns)
13461346
ss.Train()
13471347

13481348

0 commit comments

Comments
 (0)