Infinite function calls with continue statement
btracey opened this issue · 1 comments
btracey commented
It appears there is some issue with continue
statements in notebook defined functions. In the notebook below, when I call optimalEta
the function enters and goes into the loops correctly, but then the continue statement seems to bring it back to the function call site, where that continues an infinite number of times.
Here is the notebook
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import(\n",
" \"fmt\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Define function for optimizing eta.\n",
"optimalEta := func(x []float64) float64{\n",
" fmt.Println(\"In optimal eta\")\n",
" obj := func(s float64) float64{\n",
" fmt.Println(\"In obj, s =\",s)\n",
" var f float64\n",
" inner := make([]float64, len(x))\n",
" for i, xi := range x {\n",
" for j, xj := range x {\n",
" if j == i{\n",
" inner[j] = 0\n",
" continue\n",
" }\n",
" }\n",
" }\n",
" return f\n",
" }\n",
" fmt.Println(\"calling obj\")\n",
" val := obj(1e-4)\n",
" fmt.Println(\"return from obj\",val)\n",
" return val\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nSamples := 10\n",
"x := make([]float64, nSamples)\n",
"eta := optimalEta(x)\n",
"fmt.Println(eta)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Go",
"language": "go",
"name": "gophernotes"
},
"language_info": {
"codemirror_mode": "",
"file_extension": ".go",
"mimetype": "",
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "devel +a12c1f26e4 Tue Jun 26 20:00:51 2018 +0000"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
When I run the code, I see the following output
In optimal eta
calling obj
In obj, s = 0.0001
In obj, s = 5e-323
In obj, s = 5e-323
In obj, s = 5e-323
In obj, s = 5e-323
In obj, s = 5e-323
In obj, s = 5e-323
In obj, s = 5e-323
(and this printing does not halt).
brendan:~$ go version
go version devel +a12c1f26e4 Tue Jun 26 20:00:51 2018 +0000 darwin/amd64
brendan:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/brendan/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/brendan/Documents/mygo"
GOPROXY=""
GORACE=""
GOROOT="/Users/brendan/gover/go"
GOTMPDIR=""
GOTOOLDIR="/Users/brendan/gover/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l6/mhj4qjrj4437b_lgfz9pm1rw0000gn/T/go-build730485233=/tmp/go-build -gno-record-gcc-switches -fno-common"
VGOMODROOT=""
The go version is the 1.11beta (which I'm using because of #122 ).