Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This is an example of a basic lab.Browser with the files as the left panel, and the Tabber as the right panel.

You must run this from the command line, to get the interactive interpreter prompt.

## Make some data

```Go
Expand Down
6 changes: 5 additions & 1 deletion examples/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"cogentcore.org/core/events"
"cogentcore.org/core/icons"
"cogentcore.org/core/tree"
"cogentcore.org/core/yaegicore/coresymbols"
"cogentcore.org/lab/goal/interpreter"
"cogentcore.org/lab/lab"
_ "cogentcore.org/lab/lab/labscripts"
"cogentcore.org/lab/tensorfs"
"cogentcore.org/lab/yaegilab/labsymbols"
)
Expand All @@ -29,7 +31,9 @@ func main() {
}

func Interactive(c *interpreter.Config, in *interpreter.Interpreter) error {
b, _ := lab.NewBasicWindow(tensorfs.CurRoot, "Data", in)
b, br := lab.NewBasicWindow(tensorfs.CurRoot, "Data")
br.Interpreter = in
in.Interp.Use(coresymbols.Symbols)
in.Interp.Use(labsymbols.Symbols)
in.Config()
b.AddTopBar(func(bar *core.Frame) {
Expand Down
14 changes: 9 additions & 5 deletions examples/pca/pca.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"cogentcore.org/core/events"
"cogentcore.org/core/icons"
"cogentcore.org/core/tree"
"cogentcore.org/core/yaegicore/coresymbols"
"cogentcore.org/lab/goal/interpreter"
"cogentcore.org/lab/lab"
_ "cogentcore.org/lab/lab/labscripts"
"cogentcore.org/lab/matrix"
"cogentcore.org/lab/stats/metric"
"cogentcore.org/lab/table"
Expand All @@ -33,9 +35,11 @@ func main() {

func Interactive(c *interpreter.Config, in *interpreter.Interpreter) error {
dir := tensorfs.Mkdir("Iris")
b, bs := lab.NewBasicWindow(tensorfs.CurRoot, "Iris", in)
b, br := lab.NewBasicWindow(tensorfs.CurRoot, "Iris")
in.Interp.Use(coresymbols.Symbols)
in.Interp.Use(labsymbols.Symbols)
in.Config()
br.Interpreter = in
b.AddTopBar(func(bar *core.Frame) {
tb := core.NewToolbar(bar)
// tb.Maker(tbv.MakeToolbar)
Expand All @@ -53,7 +57,7 @@ func Interactive(c *interpreter.Config, in *interpreter.Interpreter) error {
if c.Expr != "" {
in.Eval(c.Expr)
}
AnalyzeIris(dir, bs)
AnalyzeIris(dir, br)
in.Interactive()
}()
})
Expand All @@ -63,7 +67,7 @@ func Interactive(c *interpreter.Config, in *interpreter.Interpreter) error {
return nil
}

func AnalyzeIris(dir *tensorfs.Node, bs *lab.Basic) {
func AnalyzeIris(dir *tensorfs.Node, br *lab.Basic) {
dt := table.New("iris")
err := dt.OpenCSV("iris.data", tensor.Comma)
if err != nil {
Expand All @@ -74,7 +78,7 @@ func AnalyzeIris(dir *tensorfs.Node, bs *lab.Basic) {
ddir := dir.Dir("Data")
tensorfs.DirFromTable(ddir, dt)

ped := bs.Tabs.PlotTable("Iris", dt)
ped := br.Tabs.PlotTable("Iris", dt)
_ = ped

cdt := table.New()
Expand All @@ -88,7 +92,7 @@ func AnalyzeIris(dir *tensorfs.Node, bs *lab.Basic) {
data := cdt.Column("data")
covar := tensor.NewFloat64()
err = metric.CovarianceMatrixOut(metric.Correlation, data, covar)
cvg := bs.Tabs.TensorGrid("Covar", covar)
cvg := br.Tabs.TensorGrid("Covar", covar)
_ = cvg

vecs, _ := matrix.EigSym(covar)
Expand Down
5 changes: 4 additions & 1 deletion examples/planets/planets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"cogentcore.org/core/events"
"cogentcore.org/core/icons"
"cogentcore.org/core/tree"
"cogentcore.org/core/yaegicore/coresymbols"
"cogentcore.org/lab/goal/interpreter"
"cogentcore.org/lab/lab"
_ "cogentcore.org/lab/lab/labscripts"
"cogentcore.org/lab/stats/stats"
"cogentcore.org/lab/table"
"cogentcore.org/lab/tensor"
Expand Down Expand Up @@ -94,7 +96,8 @@ func main() {
}

func Interactive(c *interpreter.Config, in *interpreter.Interpreter) error {
b, _ := lab.NewBasicWindow(tensorfs.CurRoot, "Planets", in)
b, _ := lab.NewBasicWindow(tensorfs.CurRoot, "Planets")
in.Interp.Use(coresymbols.Symbols)
in.Interp.Use(labsymbols.Symbols)
in.Config()
b.AddTopBar(func(bar *core.Frame) {
Expand Down
8 changes: 4 additions & 4 deletions examples/simmer/simmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"cogentcore.org/lab/goal"
"cogentcore.org/lab/goal/interpreter"
"cogentcore.org/lab/lab"
"cogentcore.org/lab/lab/labscripts"
_ "cogentcore.org/lab/lab/labscripts"
"cogentcore.org/lab/table"
"cogentcore.org/lab/tensorcore"
"cogentcore.org/lab/yaegilab/labsymbols"
Expand Down Expand Up @@ -134,10 +136,8 @@ func (sr *Simmer) InitSimmer(startDir string) {
sr.StartDir = startDir
ddr := errors.Log1(filepath.Abs("simdata"))
sr.SetDataRoot(ddr)
if sr.Interpreter == nil {
sr.InitInterp()
}
in := sr.Interpreter
labscripts.InitInterpreter(&sr.Browser)
in, _ := labscripts.Interpreter(&sr.Browser)
in.Interp.Use(coresymbols.Symbols) // gui imports
in.Interp.Use(labsymbols.Symbols)
in.Interp.Use(interp.Exports{
Expand Down
2 changes: 1 addition & 1 deletion examples/simstats/sim.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/simstats/sim.goal
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func main() {
ss.ConfigAll()
ss.Run()

b, _ := lab.NewBasicWindow(ss.Root, "Root", nil)
b, _ := lab.NewBasicWindow(ss.Root, "Root")
b.RunWindow()
core.Wait()
}
7 changes: 4 additions & 3 deletions goal/transpile/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"cogentcore.org/core/base/stack"
"cogentcore.org/lab/goal/transpile/mparser"
"cogentcore.org/lab/tensor"
)

Expand All @@ -31,7 +32,7 @@ func (st *State) TranspileMath(toks Tokens, code string, fullLine bool) Tokens {
mp := mathParse{state: st, toks: toks, code: code}
// mp.trace = true

mods := AllErrors // | Trace
mods := mparser.AllErrors // | Trace

if fullLine {
ewords, err := ExecWords(str)
Expand All @@ -48,7 +49,7 @@ func (st *State) TranspileMath(toks Tokens, code string, fullLine bool) Tokens {
}
}

stmts, err := ParseLine(str, mods)
stmts, err := mparser.ParseLine(str, mods)
if err != nil {
fmt.Println("line code:", str)
fmt.Println("parse err:", err)
Expand All @@ -58,7 +59,7 @@ func (st *State) TranspileMath(toks Tokens, code string, fullLine bool) Tokens {
}
mp.stmtList(stmts)
} else {
ex, err := ParseExpr(str, mods)
ex, err := mparser.ParseExpr(str, mods)
if err != nil {
fmt.Println("expr:", str)
fmt.Println("parse err:", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package transpile
package mparser

import (
"fmt"
Expand Down
10 changes: 1 addition & 9 deletions lab/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"cogentcore.org/core/events"
"cogentcore.org/core/styles"
"cogentcore.org/core/tree"
"cogentcore.org/core/yaegicore/coresymbols"
"cogentcore.org/lab/goal/interpreter"
)

// Basic is a basic data browser with the files as the left panel,
Expand Down Expand Up @@ -63,7 +61,7 @@ func (br *Basic) Init() {
// NewBasicWindow returns a new Lab Browser window for given
// file system (nil for os files) and data directory.
// do RunWindow on resulting [core.Body] to open the window.
func NewBasicWindow(fsys fs.FS, dataDir string, in *interpreter.Interpreter) (*core.Body, *Basic) {
func NewBasicWindow(fsys fs.FS, dataDir string) (*core.Body, *Basic) {
startDir, _ := os.Getwd()
startDir = errors.Log1(filepath.Abs(startDir))
b := core.NewBody("Cogent Lab: " + fsx.DirAndFile(startDir))
Expand All @@ -73,18 +71,12 @@ func NewBasicWindow(fsys fs.FS, dataDir string, in *interpreter.Interpreter) (*c
br.Toolbar = tb
tb.Maker(br.MakeToolbar)
})
br.Interpreter = in
br.FS = fsys
ddr := dataDir
if fsys == nil {
ddr = errors.Log1(filepath.Abs(dataDir))
}
br.SetDataRoot(ddr)
if br.Interpreter == nil {
br.InitInterp()
in = br.Interpreter
}
in.Interp.Use(coresymbols.Symbols) // gui imports
br.SetScriptsDir(filepath.Join(ddr, "labscripts"))

LabBrowser = &br.Browser
Expand Down
Loading