Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ackley_mc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Torda, Prof. Dr. Andrew Ernest
ackley_mc
Commits
9e54ee7a
Commit
9e54ee7a
authored
Jan 27, 2022
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Got rid of no-op Close function and the complicated types. Now use a type assertion.
parent
20a32ab9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mc_work/dorun.go
+12
-15
12 additions, 15 deletions
mc_work/dorun.go
with
12 additions
and
15 deletions
mc_work/dorun.go
+
12
−
15
View file @
9e54ee7a
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
"sync"
"sync"
"example.com/ackley_mc/ackley"
"example.com/ackley_mc/ackley"
"example.com/ackley_mc/ui"
//
"example.com/ackley_mc/ui"
)
)
const
(
const
(
...
@@ -33,9 +33,9 @@ func getSeed() int64 {
...
@@ -33,9 +33,9 @@ func getSeed() int64 {
return
r
return
r
}
}
type
with
Closer
struct
{
io
.
Writer
}
// We have to promote him to have a Close()
type
with
Bytes
interface
{
func
(
withCloser
)
Close
()
error
{
return
nil
}
Bytes
()
[]
byte
func
addClose
(
b
io
.
Writer
)
withCloser
{
return
withCloser
{
b
}
}
}
type
cprm
struct
{
// parameters calculated from input
type
cprm
struct
{
// parameters calculated from input
rand
*
rand
.
Rand
rand
*
rand
.
Rand
...
@@ -48,8 +48,7 @@ type cprm struct { // parameters calculated from input
...
@@ -48,8 +48,7 @@ type cprm struct { // parameters calculated from input
plotTmprtr
[]
float64
// Temperature values for plotting
plotTmprtr
[]
float64
// Temperature values for plotting
plotXtrj
[]
float32
// for plotting trajectories
plotXtrj
[]
float32
// for plotting trajectories
coolme
bool
// Cooling ? or just constant temperature ?
coolme
bool
// Cooling ? or just constant temperature ?
fplotWrt
io
.
WriteCloser
// Where to write the plot of function values
fplotWrt
io
.
Writer
// Where to write the plot of function values
fplotbuf
*
bytes
.
Buffer
// The buffer possibly behind fplotWrt
xplotme
bool
// Are we plotting X trajectories
xplotme
bool
// Are we plotting X trajectories
}
}
...
@@ -110,8 +109,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
...
@@ -110,8 +109,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
}
}
}
else
{
// Must be writing to a screen
}
else
{
// Must be writing to a screen
var
w
bytes
.
Buffer
// could be fancy, preallocate and use bytes.Newbuffer
var
w
bytes
.
Buffer
// could be fancy, preallocate and use bytes.Newbuffer
cprm
.
fplotWrt
=
addClose
(
&
w
)
// Fix this, effectively two copies
cprm
.
fplotWrt
=
&
w
cprm
.
fplotbuf
=
&
w
// of the pointer
}
}
n_alloc
:=
mcPrm
.
nStep
/
5
// About a fifth of the number of steps
n_alloc
:=
mcPrm
.
nStep
/
5
// About a fifth of the number of steps
cprm
.
plotnstp
=
make
([]
float64
,
0
,
n_alloc
)
cprm
.
plotnstp
=
make
([]
float64
,
0
,
n_alloc
)
...
@@ -199,7 +197,7 @@ func nRunAdj(mcPrm *mcPrm, nstep uint32, runAcc float64, xDlta float32) float32
...
@@ -199,7 +197,7 @@ func nRunAdj(mcPrm *mcPrm, nstep uint32, runAcc float64, xDlta float32) float32
}
}
return
xDlta
return
xDlta
}
}
func
breaker
()
{}
func
breaker
(
...
interface
{}
)
{}
// doRun does a Monte Carlo run. Although single precision is fine for the
// doRun does a Monte Carlo run. Although single precision is fine for the
// coordinates and function, we use double precision for the temperature.
// coordinates and function, we use double precision for the temperature.
...
@@ -215,8 +213,8 @@ func doRun(mcPrm *mcPrm) error {
...
@@ -215,8 +213,8 @@ func doRun(mcPrm *mcPrm) error {
defer
cprm
.
fOut
.
Flush
()
defer
cprm
.
fOut
.
Flush
()
}
}
if
cprm
.
fplotWrt
!=
nil
{
if
c
,
ok
:=
cprm
.
fplotWrt
.
(
io
.
Closer
);
ok
==
true
{
// will also have to do for X values
defer
c
prm
.
fplotWrt
.
Close
()
defer
c
.
Close
()
}
}
var
nAcc
int
// Counter, number of accepted moves
var
nAcc
int
// Counter, number of accepted moves
...
@@ -273,9 +271,8 @@ func doRun(mcPrm *mcPrm) error {
...
@@ -273,9 +271,8 @@ func doRun(mcPrm *mcPrm) error {
return
err
return
err
}
}
if
cprm
.
fplotbuf
!=
nil
{
if
bBuf
,
ok
:=
cprm
.
fplotWrt
.
(
withBytes
);
ok
==
true
{
fmt
.
Println
(
"len"
,
cprm
.
fplotbuf
.
Len
())
fmt
.
Println
(
"bBuf for plotting is this big"
,
len
(
bBuf
.
Bytes
()))
ui
.
Scrnplt
(
cprm
.
fplotbuf
.
Bytes
())
}
}
if
err
:=
plotxWrt
(
&
cprm
,
mcPrm
.
xPltName
,
len
(
mcPrm
.
xIni
));
err
!=
nil
{
if
err
:=
plotxWrt
(
&
cprm
,
mcPrm
.
xPltName
,
len
(
mcPrm
.
xIni
));
err
!=
nil
{
return
err
return
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment