From 675eb2b0c2e9274ed4d06e5362db259b99bfa055 Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Sat, 13 Apr 2024 23:40:09 -0700 Subject: [PATCH] further renaming of core packages --- README.md | 2 +- econfig/README.md | 6 +- econfig/args.go | 8 +-- econfig/include.go | 4 +- econfig/usage.go | 6 +- efuns/gauss.go | 2 +- egui/README.md | 2 +- emer/layer.go | 6 +- emer/network.go | 2 +- evec/README.md | 2 +- evec/gtigen.go | 2 +- evec/vec2i.go | 142 ++++++++++++++++++++-------------------- netview/events.go | 8 +-- netview/laymesh.go | 12 ++-- netview/layraster.go | 24 +++---- netview/netview.go | 16 ++--- params/apply.go | 10 +-- params/applymap.go | 4 +- popcode/popcode2d.go | 42 ++++++------ popcode/popcode_test.go | 8 +-- prjn/circle.go | 20 +++--- prjn/poolrect.go | 14 ++-- prjn/pooltile.go | 74 ++++++++++----------- prjn/pooltilesub.go | 76 ++++++++++----------- prjn/rect.go | 18 ++--- relpos/rel.go | 2 +- relpos/rel_test.go | 6 +- 27 files changed, 259 insertions(+), 259 deletions(-) diff --git a/README.md b/README.md index daf65cd..06d3b00 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ The following all work together to provide a convenient layer of abstraction for * [esg](esg) is the *emergent stochastic / sentence generator* -- parses simple grammars that generate random events (sentences) -- can be a good starting point for generating more complex environments. -* [evec](evec) has `Vec2i` which uses plain `int` X, Y fields, whereas the `math32` package uses `int32` which are needed for graphics but int is more convenient in models. +* [evec](evec) has `Vector2i` which uses plain `int` X, Y fields, whereas the `math32` package uses `int32` which are needed for graphics but int is more convenient in models. * [popcode](popcode) supports the encoding and decoding of population codes -- distributed representations of numeric quantities across a population of neurons. This is the `ScalarVal` functionality from C++ emergent, but now completely independent of any specific algorithm so it can be used anywhere. diff --git a/econfig/README.md b/econfig/README.md index a011b79..3122fa0 100644 --- a/econfig/README.md +++ b/econfig/README.md @@ -59,7 +59,7 @@ Docs: [GoDoc](https://pkg.go.dev/github.com/emer/emergent/econfig) The [Cogent Core](https://cogentcore.org/core) GUI processes `default:"value"` struct tags to highlight values that are not at their defaults. econfig uses these same tags to auto-initialize fields as well, ensuring that the tag and the actual initial value are the same. The value for strings or numbers is just the string representation. For more complex types, here ar some examples: * `struct`: specify using standard Go literal expression as a string, with single-quotes `'` used instead of double-quotes around strings, such as the name of the fields: - + `evec.Vec2i`: `default:"{'X':10,'Y':10}"` + + `evec.Vector2i`: `default:"{'X':10,'Y':10}"` * `slice`: comma-separated list of values in square braces -- use `'` for internal string boundaries: + `[]float32`: `default:"[1, 2.14, 3.14]"` @@ -80,10 +80,10 @@ type ParamConfig struct { Network map[string]any // size of hidden layer -- can use emer.LaySize for 4D layers - Hidden1Size evec.Vec2i `default:"{'X':10,'Y':10}" nest:"+"` + Hidden1Size evec.Vector2i `default:"{'X':10,'Y':10}" nest:"+"` // size of hidden layer -- can use emer.LaySize for 4D layers - Hidden2Size evec.Vec2i `default:"{'X':10,'Y':10}" nest:"+"` + Hidden2Size evec.Vector2i `default:"{'X':10,'Y':10}" nest:"+"` // Extra Param Sheet name(s) to use (space separated if multiple) -- must be valid name as listed in compiled-in params or loaded params Sheet string diff --git a/econfig/args.go b/econfig/args.go index 91f92eb..4b09246 100644 --- a/econfig/args.go +++ b/econfig/args.go @@ -92,7 +92,7 @@ func ParseArg(s string, args []string, allArgs map[string]reflect.Value, errNotF return } - isbool := reflectx.NonPtrValue(fval).Kind() == reflect.Bool + isbool := reflectx.NonPointerValue(fval).Kind() == reflect.Bool var value string switch { @@ -134,7 +134,7 @@ func ParseArg(s string, args []string, allArgs map[string]reflect.Value, errNotF // SetArgValue sets given arg name to given value, into settable reflect.Value func SetArgValue(name string, fval reflect.Value, value string) error { - nptyp := reflectx.NonPtrType(fval.Type()) + nptyp := reflectx.NonPointerType(fval.Type()) vk := nptyp.Kind() switch { // todo: enum @@ -209,12 +209,12 @@ func fieldArgNamesStruct(obj any, path string, nest bool, allArgs map[string]ref if ov.Kind() == reflect.Pointer && ov.IsNil() { return } - val := reflectx.NonPtrValue(ov) + val := reflectx.NonPointerValue(ov) typ := val.Type() for i := 0; i < typ.NumField(); i++ { f := typ.Field(i) fv := val.Field(i) - if reflectx.NonPtrType(f.Type).Kind() == reflect.Struct { + if reflectx.NonPointerType(f.Type).Kind() == reflect.Struct { nwPath := f.Name if path != "" { nwPath = path + "." + nwPath diff --git a/econfig/include.go b/econfig/include.go index 3667625..1d7d959 100644 --- a/econfig/include.go +++ b/econfig/include.go @@ -35,7 +35,7 @@ type Includer interface { // Returns an error if any of the include files cannot be found on IncludePath. // Does not alter cfg. func IncludesStack(cfg Includeser) ([]string, error) { - clone := reflect.New(reflectx.NonPtrType(reflect.TypeOf(cfg))).Interface().(Includeser) + clone := reflect.New(reflectx.NonPointerType(reflect.TypeOf(cfg))).Interface().(Includeser) *clone.IncludesPtr() = *cfg.IncludesPtr() return includesStackImpl(clone, nil) } @@ -73,7 +73,7 @@ func includesStackImpl(clone Includeser, includes []string) ([]string, error) { // Returns an error if any of the include files cannot be found on IncludePath. // Does not alter cfg. func IncludeStack(cfg Includer) ([]string, error) { - clone := reflect.New(reflectx.NonPtrType(reflect.TypeOf(cfg))).Interface().(Includer) + clone := reflect.New(reflectx.NonPointerType(reflect.TypeOf(cfg))).Interface().(Includer) *clone.IncludePtr() = *cfg.IncludePtr() return includeStackImpl(clone, nil) } diff --git a/econfig/usage.go b/econfig/usage.go index decfcaf..4ca13d9 100644 --- a/econfig/usage.go +++ b/econfig/usage.go @@ -28,12 +28,12 @@ func Usage(cfg any) string { // usageStruct adds usage info to given strings.Builder func usageStruct(obj any, path string, b *strings.Builder) { - typ := reflectx.NonPtrType(reflect.TypeOf(obj)) - val := reflectx.NonPtrValue(reflect.ValueOf(obj)) + typ := reflectx.NonPointerType(reflect.TypeOf(obj)) + val := reflectx.NonPointerValue(reflect.ValueOf(obj)) for i := 0; i < typ.NumField(); i++ { f := typ.Field(i) fv := val.Field(i) - if reflectx.NonPtrType(f.Type).Kind() == reflect.Struct { + if reflectx.NonPointerType(f.Type).Kind() == reflect.Struct { nwPath := f.Name if path != "" { nwPath = path + "." + nwPath diff --git a/efuns/gauss.go b/efuns/gauss.go index a7e5da5..bcbb942 100644 --- a/efuns/gauss.go +++ b/efuns/gauss.go @@ -15,7 +15,7 @@ import ( // GaussVecDistNoNorm returns the gaussian of the distance between two 2D vectors // using given sigma standard deviation, without normalizing area under gaussian // (i.e., max value is 1 at dist = 0) -func GaussVecDistNoNorm(a, b math32.Vec2, sigma float32) float32 { +func GaussVecDistNoNorm(a, b math32.Vector2, sigma float32) float32 { dsq := a.DistToSquared(b) return math32.FastExp((-0.5 * dsq) / (sigma * sigma)) } diff --git a/egui/README.md b/egui/README.md index 55f6e4c..5c9a611 100644 --- a/egui/README.md +++ b/egui/README.md @@ -18,7 +18,7 @@ func (ss *Sim) ConfigGUI() *core.Window { // optionally reconfigure the netview: ss.GUI.NetView.Scene().Camera.Pose.Pos.Set(0, 1, 2.75) - ss.GUI.NetView.Scene().Camera.LookAt(math32.V3(0, 0, 0), math32.V3(0, 1, 0)) + ss.GUI.NetView.Scene().Camera.LookAt(math32.Vec3(0, 0, 0), math32.Vec3(0, 1, 0)) ss.GUI.AddPlots(title, &ss.Logs) // automatically adds all configured plots ``` diff --git a/emer/layer.go b/emer/layer.go index 00746f5..2b3a632 100644 --- a/emer/layer.go +++ b/emer/layer.go @@ -87,16 +87,16 @@ type Layer interface { // where the vertical dimension is Y and Z is the depth dimension. However, in the // more "layer-centric" way of thinking about it, it is natural for the width & height // to map onto X and Y, and then Z is left over for stacking vertically. - Pos() math32.Vec3 + Pos() math32.Vector3 // SetPos sets the 3D position of this layer -- will generally be overwritten by // automatic RelPos setting, unless that doesn't specify a valid relative position. - SetPos(pos math32.Vec3) + SetPos(pos math32.Vector3) // Size returns the display size of this layer for the 3D view -- see Pos() for general info. // This is multiplied by the RelPos.Scale factor to rescale layer sizes, and takes // into account 2D and 4D layer structures. - Size() math32.Vec2 + Size() math32.Vector2 // Index returns a 0..n-1 index of the position of the layer within list of layers // in the network. For backprop networks, index position has computational significance. diff --git a/emer/network.go b/emer/network.go index a3f72de..c8780ab 100644 --- a/emer/network.go +++ b/emer/network.go @@ -134,7 +134,7 @@ type Network interface { OpenWtsJSON(filename core.Filename) error // Bounds returns the minimum and maximum display coordinates of the network for 3D display - Bounds() (min, max math32.Vec3) + Bounds() (min, max math32.Vector3) // VarRange returns the min / max values for given variable VarRange(varNm string) (min, max float32, err error) diff --git a/evec/README.md b/evec/README.md index e510d6e..95bc2d9 100644 --- a/evec/README.md +++ b/evec/README.md @@ -1,5 +1,5 @@ Docs: [GoDoc](https://pkg.go.dev/github.com/emer/emergent/evec) -Package `evec` has vector types for emergent, including `Vec2i` which is a 2D vector with int values, using the API based on `math32.Vec2i`. This is distinct from math32.Vec2i because it uses int instead of int32, and the int is significantly easier to deal with for layer sizing params etc. +Package `evec` has vector types for emergent, including `Vector2i` which is a 2D vector with int values, using the API based on `math32.Vector2i`. This is distinct from math32.Vector2i because it uses int instead of int32, and the int is significantly easier to deal with for layer sizing params etc. diff --git a/evec/gtigen.go b/evec/gtigen.go index 38ee014..41897b1 100644 --- a/evec/gtigen.go +++ b/evec/gtigen.go @@ -8,4 +8,4 @@ import ( var _ = gti.AddType(>i.Type{Name: "github.com/emer/emergent/v2/evec.Dims", IDName: "dims", Doc: "Dims is a list of vector dimension (component) names"}) -var _ = gti.AddType(>i.Type{Name: "github.com/emer/emergent/v2/evec.Vec2i", IDName: "vec2i", Doc: "Vec2i is a 2D vector/point with X and Y int components.", Fields: []gti.Field{{Name: "X"}, {Name: "Y"}}}) +var _ = gti.AddType(>i.Type{Name: "github.com/emer/emergent/v2/evec.Vector2i", IDName: "vec2i", Doc: "Vector2i is a 2D vector/point with X and Y int components.", Fields: []gti.Field{{Name: "X"}, {Name: "Y"}}}) diff --git a/evec/vec2i.go b/evec/vec2i.go index 30d14e2..540e0ec 100644 --- a/evec/vec2i.go +++ b/evec/vec2i.go @@ -8,52 +8,52 @@ // license that can be found in the LICENSE file. // with modifications needed to suit Cogent Core functionality. -// Package evec has vector types for emergent, including Vec2i which is a 2D -// vector with int values, using the API based on math32.Vec2i. -// This is distinct from math32.Vec2i because it uses int instead of int32, and +// Package evec has vector types for emergent, including Vector2i which is a 2D +// vector with int values, using the API based on math32.Vector2i. +// This is distinct from math32.Vector2i because it uses int instead of int32, and // the int is significantly easier to deal with for layer sizing params etc. package evec import "cogentcore.org/core/math32" -// Vec2i is a 2D vector/point with X and Y int components. -type Vec2i struct { +// Vector2i is a 2D vector/point with X and Y int components. +type Vector2i struct { X int Y int } -// NewVec2i returns a new Vec2i with the specified x and y components. -func NewVec2i(x, y int) Vec2i { - return Vec2i{X: x, Y: y} +// NewVector2i returns a new Vector2i with the specified x and y components. +func NewVector2i(x, y int) Vector2i { + return Vector2i{X: x, Y: y} } -// NewVec2iScalar returns a new Vec2i with all components set to scalar. -func NewVec2iScalar(s int) Vec2i { - return Vec2i{X: s, Y: s} +// NewVector2iScalar returns a new Vector2i with all components set to scalar. +func NewVector2iScalar(s int) Vector2i { + return Vector2i{X: s, Y: s} } -// NewVec2iFromVec2Round converts from floating point math32.Vec2 vector to int, using rounding -func NewVec2iFromVec2Round(v math32.Vec2) Vec2i { - return Vec2i{int(math32.Round(v.X)), int(math32.Round(v.Y))} +// NewVector2iFromVector2Round converts from floating point math32.Vector2 vector to int, using rounding +func NewVector2iFromVector2Round(v math32.Vector2) Vector2i { + return Vector2i{int(math32.Round(v.X)), int(math32.Round(v.Y))} } -// NewVec2iFromVec2Floor converts from floating point math32.Vec2 vector to int, using floor -func NewVec2iFromVec2Floor(v math32.Vec2) Vec2i { - return Vec2i{int(math32.Floor(v.X)), int(math32.Floor(v.Y))} +// NewVector2iFromVector2Floor converts from floating point math32.Vector2 vector to int, using floor +func NewVector2iFromVector2Floor(v math32.Vector2) Vector2i { + return Vector2i{int(math32.Floor(v.X)), int(math32.Floor(v.Y))} } -// NewVec2iFromVec2Ceil converts from floating point math32.Vec2 vector to int, using ceil -func NewVec2iFromVec2Ceil(v math32.Vec2) Vec2i { - return Vec2i{X: int(math32.Ceil(v.X)), Y: int(math32.Ceil(v.Y))} +// NewVector2iFromVector2Ceil converts from floating point math32.Vector2 vector to int, using ceil +func NewVector2iFromVector2Ceil(v math32.Vector2) Vector2i { + return Vector2i{X: int(math32.Ceil(v.X)), Y: int(math32.Ceil(v.Y))} } -// ToVec2 returns floating point math32.Vec2 from int -func (v Vec2i) ToVec2() math32.Vec2 { - return math32.V2(float32(v.X), float32(v.Y)) +// ToVector2 returns floating point math32.Vector2 from int +func (v Vector2i) ToVector2() math32.Vector2 { + return math32.Vec2(float32(v.X), float32(v.Y)) } // IsNil returns true if all values are 0 (uninitialized). -func (v Vec2i) IsNil() bool { +func (v Vector2i) IsNil() bool { if v.X == 0 && v.Y == 0 { return true } @@ -61,19 +61,19 @@ func (v Vec2i) IsNil() bool { } // Set sets this vector X and Y components. -func (v *Vec2i) Set(x, y int) { +func (v *Vector2i) Set(x, y int) { v.X = x v.Y = y } // SetScalar sets all vector components to same scalar value. -func (v *Vec2i) SetScalar(s int) { +func (v *Vector2i) SetScalar(s int) { v.X = s v.Y = s } // SetDim sets this vector component value by its dimension index -func (v *Vec2i) SetDim(dim Dims, value int) { +func (v *Vector2i) SetDim(dim Dims, value int) { switch dim { case X: v.X = value @@ -85,7 +85,7 @@ func (v *Vec2i) SetDim(dim Dims, value int) { } // Dim returns this vector component -func (v Vec2i) Dim(dim Dims) int { +func (v Vector2i) Dim(dim Dims) int { switch dim { case X: return v.X @@ -97,30 +97,30 @@ func (v Vec2i) Dim(dim Dims) int { } // SetByName sets this vector component value by its case insensitive name: "x" or "y". -func (v *Vec2i) SetByName(name string, value int) { +func (v *Vector2i) SetByName(name string, value int) { switch name { case "x", "X": v.X = value case "y", "Y": v.Y = value default: - panic("Invalid Vec2i component name: " + name) + panic("Invalid Vector2i component name: " + name) } } // SetZero sets this vector X and Y components to be zero. -func (v *Vec2i) SetZero() { +func (v *Vector2i) SetZero() { v.SetScalar(0) } // FromArray sets this vector's components from the specified array and offset. -func (v *Vec2i) FromArray(array []int, offset int) { +func (v *Vector2i) FromArray(array []int, offset int) { v.X = array[offset] v.Y = array[offset+1] } // ToArray copies this vector's components to array starting at offset. -func (v Vec2i) ToArray(array []int, offset int) { +func (v Vector2i) ToArray(array []int, offset int) { array[offset] = v.X array[offset+1] = v.Y } @@ -129,96 +129,96 @@ func (v Vec2i) ToArray(array []int, offset int) { // Basic math operations // Add adds other vector to this one and returns result in a new vector. -func (v Vec2i) Add(other Vec2i) Vec2i { - return Vec2i{v.X + other.X, v.Y + other.Y} +func (v Vector2i) Add(other Vector2i) Vector2i { + return Vector2i{v.X + other.X, v.Y + other.Y} } // AddScalar adds scalar s to each component of this vector and returns new vector. -func (v Vec2i) AddScalar(s int) Vec2i { - return Vec2i{v.X + s, v.Y + s} +func (v Vector2i) AddScalar(s int) Vector2i { + return Vector2i{v.X + s, v.Y + s} } // SetAdd sets this to addition with other vector (i.e., += or plus-equals). -func (v *Vec2i) SetAdd(other Vec2i) { +func (v *Vector2i) SetAdd(other Vector2i) { v.X += other.X v.Y += other.Y } // SetAddScalar sets this to addition with scalar. -func (v *Vec2i) SetAddScalar(s int) { +func (v *Vector2i) SetAddScalar(s int) { v.X += s v.Y += s } // Sub subtracts other vector from this one and returns result in new vector. -func (v Vec2i) Sub(other Vec2i) Vec2i { - return Vec2i{v.X - other.X, v.Y - other.Y} +func (v Vector2i) Sub(other Vector2i) Vector2i { + return Vector2i{v.X - other.X, v.Y - other.Y} } // SubScalar subtracts scalar s from each component of this vector and returns new vector. -func (v Vec2i) SubScalar(s int) Vec2i { - return Vec2i{v.X - s, v.Y - s} +func (v Vector2i) SubScalar(s int) Vector2i { + return Vector2i{v.X - s, v.Y - s} } // SetSub sets this to subtraction with other vector (i.e., -= or minus-equals). -func (v *Vec2i) SetSub(other Vec2i) { +func (v *Vector2i) SetSub(other Vector2i) { v.X -= other.X v.Y -= other.Y } // SetSubScalar sets this to subtraction of scalar. -func (v *Vec2i) SetSubScalar(s int) { +func (v *Vector2i) SetSubScalar(s int) { v.X -= s v.Y -= s } // Mul multiplies each component of this vector by the corresponding one from other // and returns resulting vector. -func (v Vec2i) Mul(other Vec2i) Vec2i { - return Vec2i{v.X * other.X, v.Y * other.Y} +func (v Vector2i) Mul(other Vector2i) Vector2i { + return Vector2i{v.X * other.X, v.Y * other.Y} } // MulScalar multiplies each component of this vector by the scalar s and returns resulting vector. -func (v Vec2i) MulScalar(s int) Vec2i { - return Vec2i{v.X * s, v.Y * s} +func (v Vector2i) MulScalar(s int) Vector2i { + return Vector2i{v.X * s, v.Y * s} } // SetMul sets this to multiplication with other vector (i.e., *= or times-equals). -func (v *Vec2i) SetMul(other Vec2i) { +func (v *Vector2i) SetMul(other Vector2i) { v.X *= other.X v.Y *= other.Y } // SetMulScalar sets this to multiplication by scalar. -func (v *Vec2i) SetMulScalar(s int) { +func (v *Vector2i) SetMulScalar(s int) { v.X *= s v.Y *= s } // Div divides each component of this vector by the corresponding one from other vector // and returns resulting vector. -func (v Vec2i) Div(other Vec2i) Vec2i { - return Vec2i{v.X / other.X, v.Y / other.Y} +func (v Vector2i) Div(other Vector2i) Vector2i { + return Vector2i{v.X / other.X, v.Y / other.Y} } // DivScalar divides each component of this vector by the scalar s and returns resulting vector. // If scalar is zero, returns zero. -func (v Vec2i) DivScalar(scalar int) Vec2i { +func (v Vector2i) DivScalar(scalar int) Vector2i { if scalar != 0 { - return Vec2i{v.X / scalar, v.Y / scalar} + return Vector2i{v.X / scalar, v.Y / scalar} } else { - return Vec2i{} + return Vector2i{} } } // SetDiv sets this to division by other vector (i.e., /= or divide-equals). -func (v *Vec2i) SetDiv(other Vec2i) { +func (v *Vector2i) SetDiv(other Vector2i) { v.X /= other.X v.Y /= other.Y } // SetDivScalar sets this to division by scalar. -func (v *Vec2i) SetDivScalar(s int) { +func (v *Vector2i) SetDivScalar(s int) { if s != 0 { v.SetMulScalar(1 / s) } else { @@ -243,23 +243,23 @@ func Max32i(a, b int) int { } // Min returns min of this vector components vs. other vector. -func (v Vec2i) Min(other Vec2i) Vec2i { - return Vec2i{Min32i(v.X, other.X), Min32i(v.Y, other.Y)} +func (v Vector2i) Min(other Vector2i) Vector2i { + return Vector2i{Min32i(v.X, other.X), Min32i(v.Y, other.Y)} } // SetMin sets this vector components to the minimum values of itself and other vector. -func (v *Vec2i) SetMin(other Vec2i) { +func (v *Vector2i) SetMin(other Vector2i) { v.X = Min32i(v.X, other.X) v.Y = Min32i(v.Y, other.Y) } // Max returns max of this vector components vs. other vector. -func (v Vec2i) Max(other Vec2i) Vec2i { - return Vec2i{Max32i(v.X, other.X), Max32i(v.Y, other.Y)} +func (v Vector2i) Max(other Vector2i) Vector2i { + return Vector2i{Max32i(v.X, other.X), Max32i(v.Y, other.Y)} } // SetMax sets this vector components to the maximum value of itself and other vector. -func (v *Vec2i) SetMax(other Vec2i) { +func (v *Vector2i) SetMax(other Vector2i) { v.X = Max32i(v.X, other.X) v.Y = Max32i(v.Y, other.Y) } @@ -267,7 +267,7 @@ func (v *Vec2i) SetMax(other Vec2i) { // Clamp sets this vector components to be no less than the corresponding components of min // and not greater than the corresponding component of max. // Assumes min < max, if this assumption isn't true it will not operate correctly. -func (v *Vec2i) Clamp(min, max Vec2i) { +func (v *Vector2i) Clamp(min, max Vector2i) { if v.X < min.X { v.X = min.X } else if v.X > max.X { @@ -281,22 +281,22 @@ func (v *Vec2i) Clamp(min, max Vec2i) { } // ClampScalar sets this vector components to be no less than minVal and not greater than maxVal. -func (v *Vec2i) ClampScalar(minVal, maxVal int) { - v.Clamp(NewVec2iScalar(minVal), NewVec2iScalar(maxVal)) +func (v *Vector2i) ClampScalar(minVal, maxVal int) { + v.Clamp(NewVector2iScalar(minVal), NewVector2iScalar(maxVal)) } // Negate returns vector with each component negated. -func (v Vec2i) Negate() Vec2i { - return Vec2i{-v.X, -v.Y} +func (v Vector2i) Negate() Vector2i { + return Vector2i{-v.X, -v.Y} } // SetNegate negates each of this vector's components. -func (v *Vec2i) SetNegate() { +func (v *Vector2i) SetNegate() { v.X = -v.X v.Y = -v.Y } // IsEqual returns if this vector is equal to other. -func (v Vec2i) IsEqual(other Vec2i) bool { +func (v Vector2i) IsEqual(other Vector2i) bool { return (other.X == v.X) && (other.Y == v.Y) } diff --git a/netview/events.go b/netview/events.go index 07984e6..90f901d 100644 --- a/netview/events.go +++ b/netview/events.go @@ -121,10 +121,10 @@ func (sw *Scene) LayerUnitAtPoint(e events.Event) (lay emer.Layer, lx, ly, unInd } nv := sw.NetView nmin, nmax := nv.Net.Bounds() - nsz := nmax.Sub(nmin).Sub(math32.V3(1, 1, 0)).Max(math32.V3(1, 1, 1)) - nsc := math32.V3(1.0/nsz.X, 1.0/nsz.Y, 1.0/nsz.Z) + nsz := nmax.Sub(nmin).Sub(math32.Vec3(1, 1, 0)).Max(math32.Vec3(1, 1, 1)) + nsc := math32.Vec3(1.0/nsz.X, 1.0/nsz.Y, 1.0/nsz.Z) szc := math32.Max(nsc.X, nsc.Y) - poff := math32.V3Scalar(0.5) + poff := math32.Vector3Scalar(0.5) poff.Y = -0.5 for li, lgi := range *laysGp.Children() { lay = nv.Net.Layer(li) @@ -139,7 +139,7 @@ func (sw *Scene) LayerUnitAtPoint(e events.Event) (lay emer.Layer, lx, ly, unInd ray := lo.RayPick(pos) // layer is in XZ plane with norm pointing up in Y axis // offset is 0 in local coordinates - plane := math32.Plane{Norm: math32.V3(0, 1, 0), Off: 0} + plane := math32.Plane{Norm: math32.Vec3(0, 1, 0), Off: 0} pt, ok := ray.IntersectPlane(plane) if !ok || pt.Z > 0 { // Z > 0 means clicked "in front" of plane -- where labels are continue diff --git a/netview/laymesh.go b/netview/laymesh.go index 63f9cd3..8123175 100644 --- a/netview/laymesh.go +++ b/netview/laymesh.go @@ -168,7 +168,7 @@ func (lm *LayMesh) Set2D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA vtxSz, idxSz := vshape.PlaneN(segs, segs) pidx := 0 // plane index - pos := math32.Vec3{} + pos := math32.Vector3{} lm.View.ReadLock() for zi := nz - 1; zi >= 0; zi-- { @@ -178,7 +178,7 @@ func (lm *LayMesh) Set2D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA ioff := pidx * idxSz * 5 x0 := uo + float32(xi) _, scaled, clr, _ := lm.View.UnitValue(lm.Lay, []int{zi, xi}) - v4c := math32.NewVec4Color(clr) + v4c := math32.NewVector4Color(clr) vshape.SetColor(clrAry, poff, 5*vtxSz, v4c) ht := 0.5 * math32.Abs(scaled) if ht < MinUnitHeight { @@ -203,7 +203,7 @@ func (lm *LayMesh) Set2D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA lm.View.ReadUnlock() lm.BBoxMu.Lock() - lm.BBox.SetBounds(math32.V3(0, -0.5, -fnz), math32.V3(fnx, 0.5, 0)) + lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnz), math32.Vec3(fnx, 0.5, 0)) lm.BBoxMu.Unlock() } @@ -233,7 +233,7 @@ func (lm *LayMesh) Set4D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA vtxSz, idxSz := vshape.PlaneN(segs, segs) pidx := 0 // plane index - pos := math32.Vec3{} + pos := math32.Vector3{} lm.View.ReadLock() for zpi := npz - 1; zpi >= 0; zpi-- { @@ -247,7 +247,7 @@ func (lm *LayMesh) Set4D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA ioff := pidx * idxSz * 5 x0 := xp0 + xsc*(uo+float32(xui)) _, scaled, clr, _ := lm.View.UnitValue(lm.Lay, []int{zpi, xpi, zui, xui}) - v4c := math32.NewVec4Color(clr) + v4c := math32.NewVector4Color(clr) vshape.SetColor(clrAry, poff, 5*vtxSz, v4c) ht := 0.5 * math32.Abs(scaled) if ht < MinUnitHeight { @@ -274,6 +274,6 @@ func (lm *LayMesh) Set4D(sc *xyz.Scene, init bool, vtxAry, normAry, texAry, clrA lm.View.ReadUnlock() lm.BBoxMu.Lock() - lm.BBox.SetBounds(math32.V3(0, -0.5, -fnpz*fnuz), math32.V3(fnpx*fnux, 0.5, 0)) + lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnpz*fnuz), math32.Vec3(fnpx*fnux, 0.5, 0)) lm.BBoxMu.Unlock() } diff --git a/netview/layraster.go b/netview/layraster.go index 6631206..0b6fd3c 100644 --- a/netview/layraster.go +++ b/netview/layraster.go @@ -74,7 +74,7 @@ func (lm *LayMesh) RasterSet2DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr vtxSz, idxSz := vshape.PlaneN(segs, segs) pidx := 0 // plane index - pos := math32.Vec3{} + pos := math32.Vector3{} curRast, _ := lm.View.Data.RasterCtr(-1) @@ -96,7 +96,7 @@ func (lm *LayMesh) RasterSet2DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr if xi-1 == curRast { xoff++ } - v4c := math32.NewVec4Color(clr) + v4c := math32.NewVector4Color(clr) vshape.SetColor(clrAry, poff, 5*vtxSz, v4c) ht := htsc * math32.Abs(scaled) if ht < MinUnitHeight { @@ -121,7 +121,7 @@ func (lm *LayMesh) RasterSet2DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr lm.View.ReadUnlock() lm.BBoxMu.Lock() - lm.BBox.SetBounds(math32.V3(0, -0.5, -fnz), math32.V3(fnx, 0.5, 0)) + lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnz), math32.Vec3(fnx, 0.5, 0)) lm.BBoxMu.Unlock() } @@ -157,7 +157,7 @@ func (lm *LayMesh) RasterSet2DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr vtxSz, idxSz := vshape.PlaneN(segs, segs) pidx := 0 // plane index - pos := math32.Vec3{} + pos := math32.Vector3{} curRast, _ := lm.View.Data.RasterCtr(-1) @@ -179,7 +179,7 @@ func (lm *LayMesh) RasterSet2DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr if zi-1 == curRast { zoff = 0 } - v4c := math32.NewVec4Color(clr) + v4c := math32.NewVector4Color(clr) vshape.SetColor(clrAry, poff, 5*vtxSz, v4c) ht := htsc * math32.Abs(scaled) if ht < MinUnitHeight { @@ -204,7 +204,7 @@ func (lm *LayMesh) RasterSet2DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr lm.View.ReadUnlock() lm.BBoxMu.Lock() - lm.BBox.SetBounds(math32.V3(0, -0.5, -fnz), math32.V3(fnx, 0.5, 0)) + lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnz), math32.Vec3(fnx, 0.5, 0)) lm.BBoxMu.Unlock() } @@ -255,7 +255,7 @@ func (lm *LayMesh) RasterSet4DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr vtxSz, idxSz := vshape.PlaneN(segs, segs) pidx := 0 // plane index - pos := math32.Vec3{} + pos := math32.Vector3{} curRast, _ := lm.View.Data.RasterCtr(-1) @@ -281,7 +281,7 @@ func (lm *LayMesh) RasterSet4DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr if xi-1 == curRast { xoff++ } - v4c := math32.NewVec4Color(clr) + v4c := math32.NewVector4Color(clr) vshape.SetColor(clrAry, poff, 5*vtxSz, v4c) ht := htsc * math32.Abs(scaled) if ht < MinUnitHeight { @@ -308,7 +308,7 @@ func (lm *LayMesh) RasterSet4DX(sc *xyz.Scene, init bool, vtxAry, normAry, texAr lm.View.ReadUnlock() lm.BBoxMu.Lock() - lm.BBox.SetBounds(math32.V3(0, -0.5, -fnpoz*fnuz), math32.V3(fnpox*fnux, 0.5, 0)) + lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnpoz*fnuz), math32.Vec3(fnpox*fnux, 0.5, 0)) lm.BBoxMu.Unlock() } @@ -359,7 +359,7 @@ func (lm *LayMesh) RasterSet4DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr vtxSz, idxSz := vshape.PlaneN(segs, segs) pidx := 0 // plane index - pos := math32.Vec3{} + pos := math32.Vector3{} curRast, _ := lm.View.Data.RasterCtr(-1) @@ -385,7 +385,7 @@ func (lm *LayMesh) RasterSet4DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr if zi-1 == curRast { zoff = 0 } - v4c := math32.NewVec4Color(clr) + v4c := math32.NewVector4Color(clr) vshape.SetColor(clrAry, poff, 5*vtxSz, v4c) ht := htsc * math32.Abs(scaled) if ht < MinUnitHeight { @@ -412,6 +412,6 @@ func (lm *LayMesh) RasterSet4DZ(sc *xyz.Scene, init bool, vtxAry, normAry, texAr lm.View.ReadUnlock() lm.BBoxMu.Lock() - lm.BBox.SetBounds(math32.V3(0, -0.5, -fnpoz*fnuz), math32.V3(fnpox*fnux, 0.5, 0)) + lm.BBox.SetBounds(math32.Vec3(0, -0.5, -fnpoz*fnuz), math32.Vec3(fnpox*fnux, 0.5, 0)) lm.BBoxMu.Unlock() } diff --git a/netview/netview.go b/netview/netview.go index e0d62fd..ea4d8c1 100644 --- a/netview/netview.go +++ b/netview/netview.go @@ -645,10 +645,10 @@ func (nv *NetView) ViewConfig() { laysGp.ConfigChildren(layConfig) nmin, nmax := nv.Net.Bounds() - nsz := nmax.Sub(nmin).Sub(math32.V3(1, 1, 0)).Max(math32.V3(1, 1, 1)) - nsc := math32.V3(1.0/nsz.X, 1.0/nsz.Y, 1.0/nsz.Z) + nsz := nmax.Sub(nmin).Sub(math32.Vec3(1, 1, 0)).Max(math32.Vec3(1, 1, 1)) + nsc := math32.Vec3(1.0/nsz.X, 1.0/nsz.Y, 1.0/nsz.Z) szc := math32.Max(nsc.X, nsc.Y) - poff := math32.V3Scalar(0.5) + poff := math32.Vector3Scalar(0.5) poff.Y = -0.5 for li, lgi := range *laysGp.Children() { ly := nv.Net.Layer(li) @@ -678,7 +678,7 @@ func (nv *NetView) ViewConfig() { txt.Defaults() txt.NetView = nv txt.SetText(ly.Name()) - txt.Pose.Scale = math32.V3Scalar(nv.Params.LayNmSize).Div(lg.Pose.Scale) + txt.Pose.Scale = math32.Vector3Scalar(nv.Params.LayNmSize).Div(lg.Pose.Scale) txt.Styles.Background = colors.C(colors.Transparent) txt.Styles.Text.Align = styles.Start txt.Styles.Text.AlignV = styles.Start @@ -694,7 +694,7 @@ func (nv *NetView) ViewDefaults() { se.Camera.Pose.Pos.Set(0, 1.5, 2.5) // more "top down" view shows more of layers // vs.Camera.Pose.Pos.Set(0, 1, 2.75) // more "head on" for larger / deeper networks se.Camera.Near = 0.1 - se.Camera.LookAt(math32.V3(0, 0, 0), math32.V3(0, 1, 0)) + se.Camera.LookAt(math32.Vec3(0, 0, 0), math32.Vec3(0, 1, 0)) // todo: // vs.BgColor = core.Prefs.Colors.Background xyz.NewAmbientLight(se, "ambient", 0.1, xyz.DirectSun) @@ -815,9 +815,9 @@ func (nv *NetView) ConfigLabels(labs []string) bool { // lb.Defaults() lb.SetText(ls) // todo: - // lb.SetProp("text-align", styles.Start) - // lb.SetProp("vertical-align", styles.Start) - // lb.SetProp("white-space", styles.WhiteSpacePre) + // lb.SetProperty("text-align", styles.Start) + // lb.SetProperty("vertical-align", styles.Start) + // lb.SetProperty("white-space", styles.WhiteSpacePre) } return true } diff --git a/params/apply.go b/params/apply.go index ce667a0..75b890a 100644 --- a/params/apply.go +++ b/params/apply.go @@ -175,7 +175,7 @@ func (ps *Sel) TargetTypeMatch(obj any) bool { return true } } - tnm := reflectx.NonPtrType(reflect.TypeOf(obj)).Name() + tnm := reflectx.NonPointerType(reflect.TypeOf(obj)).Name() return tnm == trg || tnm == trgh } @@ -188,7 +188,7 @@ func (ps *Sel) SelMatch(obj any) bool { if styob, has := obj.(StylerObj); has { obj = styob.Object() } - gotyp := reflectx.NonPtrType(reflect.TypeOf(obj)).Name() + gotyp := reflectx.NonPointerType(reflect.TypeOf(obj)).Name() return SelMatch(ps.Sel, stylr.Name(), stylr.Class(), stylr.TypeName(), gotyp) } @@ -285,7 +285,7 @@ func (ps *Sheet) SelNoMatchWarn(setName, objName string) error { // the target type should already have been identified and this should only // be called when there is an expectation of the path working. func FindParam(val reflect.Value, path string) (reflect.Value, error) { - npv := reflectx.NonPtrValue(val) + npv := reflectx.NonPointerValue(val) if npv.Kind() != reflect.Struct { if !npv.IsValid() { err := fmt.Errorf("params.FindParam: object is nil -- must Build *before* applying params! path: %v\n", path) @@ -314,7 +314,7 @@ func FindParam(val reflect.Value, path string) (reflect.Value, error) { // converts the string param val as appropriate for target type. // returns error if path not found or cannot set (always logged). func SetParam(obj any, path string, val string) error { - npv := reflectx.NonPtrValue(reflect.ValueOf(obj)) + npv := reflectx.NonPointerValue(reflect.ValueOf(obj)) if npv.Kind() == reflect.Map { // only for string maps npv.SetMapIndex(reflect.ValueOf(path), reflect.ValueOf(val)) return nil @@ -340,7 +340,7 @@ func GetParam(obj any, path string) (float64, error) { if err != nil { return 0, err } - npf := reflectx.NonPtrValue(fld) + npf := reflectx.NonPointerValue(fld) switch npf.Kind() { case reflect.Float64, reflect.Float32: return npf.Float(), nil diff --git a/params/applymap.go b/params/applymap.go index 404a6bd..cfda74a 100644 --- a/params/applymap.go +++ b/params/applymap.go @@ -21,7 +21,7 @@ import ( // It always prints a message if a parameter fails to be set, and returns an error. func ApplyMap(obj any, vals map[string]any, setMsg bool) error { objv := reflect.ValueOf(obj) - npv := reflectx.NonPtrValue(objv) + npv := reflectx.NonPointerValue(objv) if npv.Kind() == reflect.Map { err := reflectx.CopyMapRobust(obj, vals) if err != nil { @@ -45,7 +45,7 @@ func ApplyMap(obj any, vals map[string]any, setMsg bool) error { errs = append(errs, err) } if setMsg { - log.Printf("ApplyMap: set field: %s = %#v\n", k, reflectx.NonPtrValue(fld).Interface()) + log.Printf("ApplyMap: set field: %s = %#v\n", k, reflectx.NonPointerValue(fld).Interface()) } } return errors.Join(errs...) diff --git a/popcode/popcode2d.go b/popcode/popcode2d.go index 56605a9..7f65ce4 100644 --- a/popcode/popcode2d.go +++ b/popcode/popcode2d.go @@ -23,13 +23,13 @@ type TwoD struct { Code PopCodes // minimum value representable on each dim -- for GaussBump, typically include extra to allow mean with activity on either side to represent the lowest value you want to encode - Min math32.Vec2 + Min math32.Vector2 // maximum value representable on each dim -- for GaussBump, typically include extra to allow mean with activity on either side to represent the lowest value you want to encode - Max math32.Vec2 + Max math32.Vector2 // sigma parameters of a gaussian specifying the tuning width of the coarse-coded units, in normalized 0-1 range - Sigma math32.Vec2 `default:"0.2"` + Sigma math32.Vector2 `default:"0.2"` // ensure that encoded and decoded value remains within specified range -- generally not useful with wrap Clip bool @@ -78,7 +78,7 @@ func (pc *TwoD) SetRange(min, max, sigma float32) { // If add == false (use Set const for clarity), values are set to pattern // else if add == true (Add), then values are added to any existing, // for encoding additional values in same pattern. -func (pc *TwoD) Encode(pat etensor.Tensor, val math32.Vec2, add bool) error { +func (pc *TwoD) Encode(pat etensor.Tensor, val math32.Vector2, add bool) error { if pat.NumDims() != 2 { err := fmt.Errorf("popcode.TwoD Encode: pattern must have 2 dimensions") log.Println(err) @@ -119,17 +119,17 @@ func (pc *TwoD) Encode(pat etensor.Tensor, val math32.Vec2, add bool) error { } // EncodeImpl is the implementation of encoding -- e.g., used twice for Wrap -func (pc *TwoD) EncodeImpl(pat etensor.Tensor, val math32.Vec2, add bool) error { +func (pc *TwoD) EncodeImpl(pat etensor.Tensor, val math32.Vector2, add bool) error { rng := pc.Max.Sub(pc.Min) - gnrm := math32.V2Scalar(1).Div(rng.Mul(pc.Sigma)) + gnrm := math32.Vector2Scalar(1).Div(rng.Mul(pc.Sigma)) ny := pat.Dim(0) nx := pat.Dim(1) - nf := math32.V2(float32(nx-1), float32(ny-1)) + nf := math32.Vec2(float32(nx-1), float32(ny-1)) incr := rng.Div(nf) for yi := 0; yi < ny; yi++ { for xi := 0; xi < nx; xi++ { - fi := math32.V2(float32(xi), float32(yi)) + fi := math32.Vec2(float32(xi), float32(yi)) trg := pc.Min.Add(incr.Mul(fi)) act := float32(0) switch pc.Code { @@ -162,11 +162,11 @@ func (pc *TwoD) EncodeImpl(pat etensor.Tensor, val math32.Vec2, add bool) error // Decode decodes 2D value from a pattern of activation // as the activation-weighted-average of the unit's preferred // tuning values. -func (pc *TwoD) Decode(pat etensor.Tensor) (math32.Vec2, error) { +func (pc *TwoD) Decode(pat etensor.Tensor) (math32.Vector2, error) { if pat.NumDims() != 2 { err := fmt.Errorf("popcode.TwoD Decode: pattern must have 2 dimensions") log.Println(err) - return math32.Vec2{}, err + return math32.Vector2{}, err } if pc.WrapX || pc.WrapY { ny := pat.Dim(0) @@ -186,7 +186,7 @@ func (pc *TwoD) Decode(pat etensor.Tensor) (math32.Vec2, error) { xs[xi] += act * xdiv } } - var val math32.Vec2 + var val math32.Vector2 switch { case pc.WrapX && pc.WrapY: dx := Ring{} @@ -253,12 +253,12 @@ func (pc *TwoD) Decode(pat etensor.Tensor) (math32.Vec2, error) { } // DecodeImpl does direct decoding of x, y simultaneously -- for non-wrap -func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (math32.Vec2, error) { - avg := math32.Vec2{} +func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (math32.Vector2, error) { + avg := math32.Vector2{} rng := pc.Max.Sub(pc.Min) ny := pat.Dim(0) nx := pat.Dim(1) - nf := math32.V2(float32(nx-1), float32(ny-1)) + nf := math32.Vec2(float32(nx-1), float32(ny-1)) incr := rng.Div(nf) sum := float32(0) for yi := 0; yi < ny; yi++ { @@ -268,7 +268,7 @@ func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (math32.Vec2, error) { if act < pc.Thr { act = 0 } - fi := math32.V2(float32(xi), float32(yi)) + fi := math32.Vec2(float32(xi), float32(yi)) trg := pc.Min.Add(incr.Mul(fi)) avg = avg.Add(trg.MulScalar(act)) sum += act @@ -284,7 +284,7 @@ func (pc *TwoD) DecodeImpl(pat etensor.Tensor) (math32.Vec2, error) { // vals slice will be constructed if len != n func (pc *TwoD) Values(valsX, valsY *[]float32, nx, ny int) { rng := pc.Max.Sub(pc.Min) - nf := math32.V2(float32(nx-1), float32(ny-1)) + nf := math32.Vec2(float32(nx-1), float32(ny-1)) incr := rng.Div(nf) // X @@ -312,7 +312,7 @@ func (pc *TwoD) Values(valsX, valsY *[]float32, nx, ny int) { // accumulate (0 = localist, single points, 1 = +/- 1 points on // either side in a square around central point, etc) // Allocates a temporary slice of size pat, and sorts that: relatively expensive -func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]math32.Vec2, error) { +func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]math32.Vector2, error) { if pat.NumDims() != 2 { err := fmt.Errorf("popcode.TwoD DecodeNPeaks: pattern must have 2 dimensions") log.Println(err) @@ -321,7 +321,7 @@ func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]math32.Vec rng := pc.Max.Sub(pc.Min) ny := pat.Dim(0) nx := pat.Dim(1) - nf := math32.V2(float32(nx-1), float32(ny-1)) + nf := math32.Vec2(float32(nx-1), float32(ny-1)) incr := rng.Div(nf) type navg struct { @@ -363,9 +363,9 @@ func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]math32.Vec return avgs[i].avg > avgs[j].avg }) - vals := make([]math32.Vec2, nvals) + vals := make([]math32.Vector2, nvals) for i := range vals { - avg := math32.Vec2{} + avg := math32.Vector2{} sum := float32(0) mxi := avgs[i].x myi := avgs[i].y @@ -384,7 +384,7 @@ func (pc *TwoD) DecodeNPeaks(pat etensor.Tensor, nvals, width int) ([]math32.Vec if act < pc.Thr { act = 0 } - fi := math32.V2(float32(x), float32(y)) + fi := math32.Vec2(float32(x), float32(y)) trg := pc.Min.Add(incr.Mul(fi)) avg = avg.Add(trg.MulScalar(act)) sum += act diff --git a/popcode/popcode_test.go b/popcode/popcode_test.go index 5ad50c8..5e5c979 100644 --- a/popcode/popcode_test.go +++ b/popcode/popcode_test.go @@ -93,7 +93,7 @@ func TestPopCode2D(t *testing.T) { var pat etensor.Float32 pat.SetShape([]int{11, 11}, nil, nil) - pc.Encode(&pat, math32.V2(0.3, 0.9), Set) + pc.Encode(&pat, math32.Vec2(0.3, 0.9), Set) // fmt.Printf("pat for 0.5: %v\n", pat) corPat := []float32{8.7642576e-08, 5.0434767e-07, 1.7603463e-06, 3.7266532e-06, 4.7851167e-06, 3.7266532e-06, 1.7603463e-06, 5.0434767e-07, 8.7642576e-08, 9.237448e-09, 5.905302e-10, 2.2603292e-06, 1.3007299e-05, 4.5399953e-05, 9.611166e-05, 0.0001234098, 9.611166e-05, 4.5399953e-05, 1.3007299e-05, 2.2603292e-06, 2.3823696e-07, 1.5229979e-08, 3.53575e-05, 0.00020346837, 0.0007101748, 0.0015034394, 0.0019304542, 0.0015034394, 0.0007101748, 0.00020346837, 3.53575e-05, 3.7266532e-06, 2.3823696e-07, 0.00033546257, 0.0019304551, 0.0067379503, 0.014264241, 0.018315647, 0.014264241, 0.006737947, 0.001930456, 0.00033546257, 3.53575e-05, 2.2603292e-06, 0.0019304542, 0.011109002, 0.038774215, 0.08208501, 0.10539925, 0.08208501, 0.038774207, 0.011109007, 0.0019304542, 0.00020346837, 1.3007299e-05, 0.006737947, 0.038774207, 0.1353353, 0.28650483, 0.3678795, 0.28650483, 0.13533528, 0.038774226, 0.006737947, 0.0007101748, 4.5399953e-05, 0.014264233, 0.08208501, 0.28650486, 0.6065308, 0.77880096, 0.6065308, 0.2865048, 0.08208503, 0.014264233, 0.0015034394, 9.611166e-05, 0.018315637, 0.10539923, 0.36787945, 0.7788008, 1, 0.7788008, 0.3678794, 0.10539925, 0.018315637, 0.0019304542, 0.0001234098, 0.014264233, 0.08208499, 0.28650478, 0.6065306, 0.77880067, 0.6065306, 0.2865047, 0.08208499, 0.014264233, 0.0015034394, 9.611166e-05, 0.0067379437, 0.03877419, 0.13533522, 0.28650466, 0.36787927, 0.28650466, 0.13533519, 0.038774196, 0.0067379437, 0.0007101744, 4.5399953e-05, 0.0019304542, 0.011109002, 0.038774207, 0.08208499, 0.10539923, 0.08208499, 0.038774196, 0.011109002, 0.0019304542, 0.00020346837, 1.3007299e-05} @@ -120,8 +120,8 @@ func TestPopCode2DMulti(t *testing.T) { var pat etensor.Float32 // note: usually you'd use a larger pattern size for multiple values pat.SetShape([]int{11, 11}, nil, nil) - pc.Encode(&pat, math32.V2(0.1, 0.9), Set) - pc.Encode(&pat, math32.V2(0.9, 0.1), Add) + pc.Encode(&pat, math32.Vec2(0.1, 0.9), Set) + pc.Encode(&pat, math32.Vec2(0.9, 0.1), Add) // fmt.Printf("pat for 0.1, 0.9: %v\n", pat) @@ -206,7 +206,7 @@ func TestTwoDWrap(t *testing.T) { pat.SetShape([]int{21, 21}, nil, nil) tangs := []float32{-179, -90, 0, 90, 179} for _, ang := range tangs { - v := math32.V2(ang, .5) + v := math32.Vec2(ang, .5) pc.Encode(&pat, v, Set) // fmt.Printf("ang: %g\n", ang) // for i := 0; i < 21; i++ { diff --git a/prjn/circle.go b/prjn/circle.go index 39ce862..65445ca 100644 --- a/prjn/circle.go +++ b/prjn/circle.go @@ -24,10 +24,10 @@ type Circle struct { Radius int // starting offset in sending layer, for computing the corresponding sending center relative to given recv unit position - Start evec.Vec2i + Start evec.Vector2i // scaling to apply to receiving unit position to compute sending center as function of recv unit position - Scale math32.Vec2 + Scale math32.Vector2 // auto-scale sending center positions as function of relative sizes of send and recv layers -- if Start is positive then assumes it is a border, subtracted from sending size AutoScale bool @@ -77,21 +77,21 @@ func (cr *Circle) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *e sc := cr.Scale if cr.AutoScale { - ssz := math32.V2(float32(sNx), float32(sNy)) + ssz := math32.Vec2(float32(sNx), float32(sNy)) if cr.Start.X >= 0 && cr.Start.Y >= 0 { ssz.X -= float32(2 * cr.Start.X) ssz.Y -= float32(2 * cr.Start.Y) } - rsz := math32.V2(float32(rNx), float32(rNy)) + rsz := math32.Vec2(float32(rNx), float32(rNy)) sc = ssz.Div(rsz) } for ry := 0; ry < rNy; ry++ { for rx := 0; rx < rNx; rx++ { - sctr := math32.V2(float32(rx)*sc.X+float32(cr.Start.X), float32(ry)*sc.Y+float32(cr.Start.Y)) + sctr := math32.Vec2(float32(rx)*sc.X+float32(cr.Start.X), float32(ry)*sc.Y+float32(cr.Start.Y)) for sy := 0; sy < sNy; sy++ { for sx := 0; sx < sNx; sx++ { - sp := math32.V2(float32(sx), float32(sy)) + sp := math32.Vec2(float32(sx), float32(sy)) if cr.Wrap { sp.X = edge.WrapMinDist(sp.X, float32(sNx), sctr.X) sp.Y = edge.WrapMinDist(sp.Y, float32(sNy), sctr.Y) @@ -131,16 +131,16 @@ func (cr *Circle) GaussWts(si, ri int, send, recv *etensor.Shape) float32 { sc := cr.Scale if cr.AutoScale { - ssz := math32.V2(float32(sNx), float32(sNy)) + ssz := math32.Vec2(float32(sNx), float32(sNy)) if cr.Start.X >= 0 && cr.Start.Y >= 0 { ssz.X -= float32(2 * cr.Start.X) ssz.Y -= float32(2 * cr.Start.Y) } - rsz := math32.V2(float32(rNx), float32(rNy)) + rsz := math32.Vec2(float32(rNx), float32(rNy)) sc = ssz.Div(rsz) } - sctr := math32.V2(float32(rx)*sc.X+float32(cr.Start.X), float32(ry)*sc.Y+float32(cr.Start.Y)) - sp := math32.V2(float32(sx), float32(sy)) + sctr := math32.Vec2(float32(rx)*sc.X+float32(cr.Start.X), float32(ry)*sc.Y+float32(cr.Start.Y)) + sp := math32.Vec2(float32(sx), float32(sy)) if cr.Wrap { sp.X = edge.WrapMinDist(sp.X, float32(sNx), sctr.X) sp.Y = edge.WrapMinDist(sp.Y, float32(sNy), sctr.Y) diff --git a/prjn/poolrect.go b/prjn/poolrect.go index cfc3ce3..b200361 100644 --- a/prjn/poolrect.go +++ b/prjn/poolrect.go @@ -18,13 +18,13 @@ import ( type PoolRect struct { // size of rectangle (of pools) in sending layer that each receiving unit receives from - Size evec.Vec2i + Size evec.Vector2i // starting pool offset in sending layer, for computing the corresponding sending lower-left corner relative to given recv pool position - Start evec.Vec2i + Start evec.Vector2i // scaling to apply to receiving pool osition to compute corresponding position in sending layer of the lower-left corner of rectangle - Scale math32.Vec2 + Scale math32.Vector2 // auto-set the Scale as function of the relative pool sizes of send and recv layers (e.g., if sending layer is 2x larger than receiving, Scale = 2) AutoScale bool @@ -39,10 +39,10 @@ type PoolRect struct { SelfCon bool // starting pool position in receiving layer -- if > 0 then pools below this starting point remain unconnected - RecvStart evec.Vec2i + RecvStart evec.Vector2i // number of pools in receiving layer to connect -- if 0 then all (remaining after RecvStart) are connected -- otherwise if < remaining then those beyond this point remain unconnected - RecvN evec.Vec2i + RecvN evec.Vector2i } func NewPoolRect() *PoolRect { @@ -92,8 +92,8 @@ func (cr *PoolRect) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn sc := cr.Scale if cr.AutoScale { - ssz := math32.V2(float32(sNx), float32(sNy)) - rsz := math32.V2(float32(rNx), float32(rNy)) + ssz := math32.Vec2(float32(sNx), float32(sNy)) + rsz := math32.Vec2(float32(rNx), float32(rNy)) sc = ssz.Div(rsz) } diff --git a/prjn/pooltile.go b/prjn/pooltile.go index 14a745f..e37af53 100644 --- a/prjn/pooltile.go +++ b/prjn/pooltile.go @@ -31,13 +31,13 @@ type PoolTile struct { Recip bool // size of receptive field tile, in terms of pools on the sending layer - Size evec.Vec2i + Size evec.Vector2i // how many pools to skip in tiling over sending layer -- typically 1/2 of Size - Skip evec.Vec2i + Skip evec.Vector2i // starting pool offset for lower-left corner of first receptive field in sending layer - Start evec.Vec2i + Start evec.Vector2i // if true, pool coordinates wrap around sending shape -- otherwise truncated at edges, which can lead to assymmetries in connectivity etc Wrap bool @@ -324,14 +324,14 @@ func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float wshp := []int{rNuY, rNuX, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "szY", "szX"}) - fsz := math32.V2(float32(sNuX-1), float32(sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fsig := pt.GaussFull.Sigma * hfsz.X // full sigma + fsz := math32.Vec2(float32(sNuX-1), float32(sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fsig := pt.GaussFull.Sigma * hfsz.X // full sigma if fsig <= 0 { fsig = pt.GaussFull.Sigma } - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -344,7 +344,7 @@ func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float psig = pt.GaussInPool.Sigma } - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -355,7 +355,7 @@ func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos + rpos := math32.Vec2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos rfpos := rpos.MulScalar(pt.GaussFull.CtrMove) rppos := rpos.MulScalar(pt.GaussInPool.CtrMove) sfctr := rfpos.Mul(hfsz).Add(hfsz) // sending center for full @@ -364,7 +364,7 @@ func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.GaussFull.On { - sf := math32.V2(float32(sux), float32(suy)) + sf := math32.Vec2(float32(sux), float32(suy)) if pt.GaussFull.Wrap { sf.X = edge.WrapMinDist(sf.X, fsz.X, sfctr.X) sf.Y = edge.WrapMinDist(sf.Y, fsz.Y, sfctr.Y) @@ -373,7 +373,7 @@ func (pt *PoolTile) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Float } pwt := float32(1) if pt.GaussInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) if pt.GaussInPool.Wrap { sp.X = edge.WrapMinDist(sp.X, psz.X, spctr.X) sp.Y = edge.WrapMinDist(sp.Y, psz.Y, spctr.Y) @@ -413,14 +413,14 @@ func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float wshp := []int{rNuY, rNuX, pt.Size.Y, pt.Size.X, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "szY", "szX", "sNuY", "sNuX"}) - fsz := math32.V2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fsig := pt.GaussFull.Sigma * hfsz.X // full sigma + fsz := math32.Vec2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fsig := pt.GaussFull.Sigma * hfsz.X // full sigma if fsig <= 0 { fsig = pt.GaussFull.Sigma } - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -433,7 +433,7 @@ func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float psig = pt.GaussInPool.Sigma } - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -443,7 +443,7 @@ func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos + rpos := math32.Vec2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos rfpos := rpos.MulScalar(pt.GaussFull.CtrMove) rppos := rpos.MulScalar(pt.GaussInPool.CtrMove) sfctr := rfpos.Mul(hfsz).Add(hfsz) // sending center for full @@ -454,7 +454,7 @@ func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.GaussFull.On { - sf := math32.V2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) + sf := math32.Vec2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) if pt.GaussFull.Wrap { sf.X = edge.WrapMinDist(sf.X, fsz.X, sfctr.X) sf.Y = edge.WrapMinDist(sf.Y, fsz.Y, sfctr.Y) @@ -463,7 +463,7 @@ func (pt *PoolTile) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Float } pwt := float32(1) if pt.GaussInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) if pt.GaussInPool.Wrap { sp.X = edge.WrapMinDist(sp.X, psz.X, spctr.X) sp.Y = edge.WrapMinDist(sp.Y, psz.Y, spctr.Y) @@ -534,11 +534,11 @@ func (pt *PoolTile) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Flo wshp := []int{rNuY, rNuX, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "sNuY", "sNuX"}) - fsz := math32.V2(float32(sNuX-1), float32(sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fgain := pt.SigFull.Gain * hfsz.X // full gain + fsz := math32.Vec2(float32(sNuX-1), float32(sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fgain := pt.SigFull.Gain * hfsz.X // full gain - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -548,7 +548,7 @@ func (pt *PoolTile) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Flo hpsz := psz.MulScalar(0.5) // half rf pgain := pt.SigInPool.Gain * hpsz.X // pool sigma - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -558,8 +558,8 @@ func (pt *PoolTile) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Flo hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos - sgn := math32.V2(1, 1) + rpos := math32.Vec2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos + sgn := math32.Vec2(1, 1) rfpos := rpos.SubScalar(0.5).MulScalar(pt.SigFull.CtrMove).AddScalar(0.5) rppos := rpos.SubScalar(0.5).MulScalar(pt.SigInPool.CtrMove).AddScalar(0.5) if rpos.X >= 1 { // flip direction half-way through @@ -580,14 +580,14 @@ func (pt *PoolTile) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor.Flo for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.SigFull.On { - sf := math32.V2(float32(sux), float32(suy)) + sf := math32.Vec2(float32(sux), float32(suy)) sigx := efuns.Logistic(sgn.X*sf.X, fgain, sfctr.X) sigy := efuns.Logistic(sgn.Y*sf.Y, fgain, sfctr.Y) fwt = sigx * sigy } pwt := float32(1) if pt.SigInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) sigx := efuns.Logistic(sgn.X*sp.X, pgain, spctr.X) sigy := efuns.Logistic(sgn.Y*sp.Y, pgain, spctr.Y) pwt = sigx * sigy @@ -625,11 +625,11 @@ func (pt *PoolTile) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Flo wshp := []int{rNuY, rNuX, pt.Size.Y, pt.Size.X, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "szY", "szX", "sNuY", "sNuX"}) - fsz := math32.V2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fgain := pt.SigFull.Gain * hfsz.X // full gain + fsz := math32.Vec2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fgain := pt.SigFull.Gain * hfsz.X // full gain - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -639,7 +639,7 @@ func (pt *PoolTile) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Flo hpsz := psz.MulScalar(0.5) // half rf pgain := pt.SigInPool.Gain * hpsz.X // pool sigma - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -649,8 +649,8 @@ func (pt *PoolTile) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Flo hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos - sgn := math32.V2(1, 1) + rpos := math32.Vec2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos + sgn := math32.Vec2(1, 1) rfpos := rpos.SubScalar(0.5).MulScalar(pt.SigFull.CtrMove).AddScalar(0.5) rppos := rpos.SubScalar(0.5).MulScalar(pt.SigInPool.CtrMove).AddScalar(0.5) if rpos.X >= 1 { // flip direction half-way through @@ -673,14 +673,14 @@ func (pt *PoolTile) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor.Flo for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.SigFull.On { - sf := math32.V2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) + sf := math32.Vec2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) sigx := efuns.Logistic(sgn.X*sf.X, fgain, sfctr.X) sigy := efuns.Logistic(sgn.Y*sf.Y, fgain, sfctr.Y) fwt = sigx * sigy } pwt := float32(1) if pt.SigInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) sigx := efuns.Logistic(sgn.X*sp.X, pgain, spctr.X) sigy := efuns.Logistic(sgn.Y*sp.Y, pgain, spctr.Y) pwt = sigx * sigy diff --git a/prjn/pooltilesub.go b/prjn/pooltilesub.go index 0eb32da..83d19c2 100644 --- a/prjn/pooltilesub.go +++ b/prjn/pooltilesub.go @@ -33,16 +33,16 @@ type PoolTileSub struct { Recip bool // size of receptive field tile, in terms of pools on the sending layer - Size evec.Vec2i + Size evec.Vector2i // how many pools to skip in tiling over sending layer -- typically 1/2 of Size - Skip evec.Vec2i + Skip evec.Vector2i // starting pool offset for lower-left corner of first receptive field in sending layer - Start evec.Vec2i + Start evec.Vector2i // number of sub-pools within each pool - Subs evec.Vec2i + Subs evec.Vector2i // sending layer has sub-pools SendSubs bool @@ -307,14 +307,14 @@ func (pt *PoolTileSub) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Fl wshp := []int{rNuY, rNuX, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "szY", "szX"}) - fsz := math32.V2(float32(sNuX-1), float32(sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fsig := pt.GaussFull.Sigma * hfsz.X // full sigma + fsz := math32.Vec2(float32(sNuX-1), float32(sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fsig := pt.GaussFull.Sigma * hfsz.X // full sigma if fsig <= 0 { fsig = pt.GaussFull.Sigma } - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -327,7 +327,7 @@ func (pt *PoolTileSub) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Fl psig = pt.GaussInPool.Sigma } - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -338,7 +338,7 @@ func (pt *PoolTileSub) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Fl hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos + rpos := math32.Vec2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos rfpos := rpos.MulScalar(pt.GaussFull.CtrMove) rppos := rpos.MulScalar(pt.GaussInPool.CtrMove) sfctr := rfpos.Mul(hfsz).Add(hfsz) // sending center for full @@ -347,7 +347,7 @@ func (pt *PoolTileSub) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Fl for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.GaussFull.On { - sf := math32.V2(float32(sux), float32(suy)) + sf := math32.Vec2(float32(sux), float32(suy)) if pt.GaussFull.Wrap { sf.X = edge.WrapMinDist(sf.X, fsz.X, sfctr.X) sf.Y = edge.WrapMinDist(sf.Y, fsz.Y, sfctr.Y) @@ -356,7 +356,7 @@ func (pt *PoolTileSub) TopoWtsGauss2D(send, recv *etensor.Shape, wts *etensor.Fl } pwt := float32(1) if pt.GaussInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) if pt.GaussInPool.Wrap { sp.X = edge.WrapMinDist(sp.X, psz.X, spctr.X) sp.Y = edge.WrapMinDist(sp.Y, psz.Y, spctr.Y) @@ -396,14 +396,14 @@ func (pt *PoolTileSub) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Fl wshp := []int{rNuY, rNuX, pt.Size.Y, pt.Size.X, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "szY", "szX", "sNuY", "sNuX"}) - fsz := math32.V2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fsig := pt.GaussFull.Sigma * hfsz.X // full sigma + fsz := math32.Vec2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fsig := pt.GaussFull.Sigma * hfsz.X // full sigma if fsig <= 0 { fsig = pt.GaussFull.Sigma } - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -416,7 +416,7 @@ func (pt *PoolTileSub) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Fl psig = pt.GaussInPool.Sigma } - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -426,7 +426,7 @@ func (pt *PoolTileSub) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Fl hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos + rpos := math32.Vec2(float32(rux), float32(ruy)).Sub(hrsz).Div(hrsz) // -1..1 normalized r unit pos rfpos := rpos.MulScalar(pt.GaussFull.CtrMove) rppos := rpos.MulScalar(pt.GaussInPool.CtrMove) sfctr := rfpos.Mul(hfsz).Add(hfsz) // sending center for full @@ -437,7 +437,7 @@ func (pt *PoolTileSub) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Fl for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.GaussFull.On { - sf := math32.V2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) + sf := math32.Vec2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) if pt.GaussFull.Wrap { sf.X = edge.WrapMinDist(sf.X, fsz.X, sfctr.X) sf.Y = edge.WrapMinDist(sf.Y, fsz.Y, sfctr.Y) @@ -446,7 +446,7 @@ func (pt *PoolTileSub) TopoWtsGauss4D(send, recv *etensor.Shape, wts *etensor.Fl } pwt := float32(1) if pt.GaussInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) if pt.GaussInPool.Wrap { sp.X = edge.WrapMinDist(sp.X, psz.X, spctr.X) sp.Y = edge.WrapMinDist(sp.Y, psz.Y, spctr.Y) @@ -490,11 +490,11 @@ func (pt *PoolTileSub) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor. wshp := []int{rNuY, rNuX, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "sNuY", "sNuX"}) - fsz := math32.V2(float32(sNuX-1), float32(sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fgain := pt.SigFull.Gain * hfsz.X // full gain + fsz := math32.Vec2(float32(sNuX-1), float32(sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fgain := pt.SigFull.Gain * hfsz.X // full gain - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -504,7 +504,7 @@ func (pt *PoolTileSub) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor. hpsz := psz.MulScalar(0.5) // half rf pgain := pt.SigInPool.Gain * hpsz.X // pool sigma - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -514,8 +514,8 @@ func (pt *PoolTileSub) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor. hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos - sgn := math32.V2(1, 1) + rpos := math32.Vec2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos + sgn := math32.Vec2(1, 1) rfpos := rpos.SubScalar(0.5).MulScalar(pt.SigFull.CtrMove).AddScalar(0.5) rppos := rpos.SubScalar(0.5).MulScalar(pt.SigInPool.CtrMove).AddScalar(0.5) if rpos.X >= 1 { // flip direction half-way through @@ -536,14 +536,14 @@ func (pt *PoolTileSub) TopoWtsSigmoid2D(send, recv *etensor.Shape, wts *etensor. for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.SigFull.On { - sf := math32.V2(float32(sux), float32(suy)) + sf := math32.Vec2(float32(sux), float32(suy)) sigx := efuns.Logistic(sgn.X*sf.X, fgain, sfctr.X) sigy := efuns.Logistic(sgn.Y*sf.Y, fgain, sfctr.Y) fwt = sigx * sigy } pwt := float32(1) if pt.SigInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) sigx := efuns.Logistic(sgn.X*sp.X, pgain, spctr.X) sigy := efuns.Logistic(sgn.Y*sp.Y, pgain, spctr.Y) pwt = sigx * sigy @@ -581,11 +581,11 @@ func (pt *PoolTileSub) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor. wshp := []int{rNuY, rNuX, pt.Size.Y, pt.Size.X, sNuY, sNuX} wts.SetShape(wshp, nil, []string{"rNuY", "rNuX", "szY", "szX", "sNuY", "sNuX"}) - fsz := math32.V2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size - hfsz := fsz.MulScalar(0.5) // half rf - fgain := pt.SigFull.Gain * hfsz.X // full gain + fsz := math32.Vec2(float32(pt.Size.X*sNuX-1), float32(pt.Size.Y*sNuY-1)) // full rf size + hfsz := fsz.MulScalar(0.5) // half rf + fgain := pt.SigFull.Gain * hfsz.X // full gain - psz := math32.V2(float32(sNuX), float32(sNuY)) // within-pool rf size + psz := math32.Vec2(float32(sNuX), float32(sNuY)) // within-pool rf size if sNuX > 1 { psz.X -= 1 } @@ -595,7 +595,7 @@ func (pt *PoolTileSub) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor. hpsz := psz.MulScalar(0.5) // half rf pgain := pt.SigInPool.Gain * hpsz.X // pool sigma - rsz := math32.V2(float32(rNuX), float32(rNuY)) // recv units-in-pool size + rsz := math32.Vec2(float32(rNuX), float32(rNuY)) // recv units-in-pool size if rNuX > 1 { rsz.X -= 1 } @@ -605,8 +605,8 @@ func (pt *PoolTileSub) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor. hrsz := rsz.MulScalar(0.5) for ruy := 0; ruy < rNuY; ruy++ { for rux := 0; rux < rNuX; rux++ { - rpos := math32.V2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos - sgn := math32.V2(1, 1) + rpos := math32.Vec2(float32(rux), float32(ruy)).Div(hrsz) // 0..2 normalized r unit pos + sgn := math32.Vec2(1, 1) rfpos := rpos.SubScalar(0.5).MulScalar(pt.SigFull.CtrMove).AddScalar(0.5) rppos := rpos.SubScalar(0.5).MulScalar(pt.SigInPool.CtrMove).AddScalar(0.5) if rpos.X >= 1 { // flip direction half-way through @@ -629,14 +629,14 @@ func (pt *PoolTileSub) TopoWtsSigmoid4D(send, recv *etensor.Shape, wts *etensor. for sux := 0; sux < sNuX; sux++ { fwt := float32(1) if pt.SigFull.On { - sf := math32.V2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) + sf := math32.Vec2(float32(fx*sNuX+sux), float32(fy*sNuY+suy)) sigx := efuns.Logistic(sgn.X*sf.X, fgain, sfctr.X) sigy := efuns.Logistic(sgn.Y*sf.Y, fgain, sfctr.Y) fwt = sigx * sigy } pwt := float32(1) if pt.SigInPool.On { - sp := math32.V2(float32(sux), float32(suy)) + sp := math32.Vec2(float32(sux), float32(suy)) sigx := efuns.Logistic(sgn.X*sp.X, pgain, spctr.X) sigy := efuns.Logistic(sgn.Y*sp.Y, pgain, spctr.Y) pwt = sigx * sigy diff --git a/prjn/rect.go b/prjn/rect.go index be8d84d..da7ad2b 100644 --- a/prjn/rect.go +++ b/prjn/rect.go @@ -18,13 +18,13 @@ import ( type Rect struct { // size of rectangle in sending layer that each receiving unit receives from - Size evec.Vec2i + Size evec.Vector2i // starting offset in sending layer, for computing the corresponding sending lower-left corner relative to given recv unit position - Start evec.Vec2i + Start evec.Vector2i // scaling to apply to receiving unit position to compute corresponding position in sending layer of the lower-left corner of rectangle - Scale math32.Vec2 + Scale math32.Vector2 // auto-set the Scale as function of the relative sizes of send and recv layers (e.g., if sending layer is 2x larger than receiving, Scale = 2) AutoScale bool @@ -42,10 +42,10 @@ type Rect struct { Recip bool // starting position in receiving layer -- if > 0 then units below this starting point remain unconnected - RecvStart evec.Vec2i + RecvStart evec.Vector2i // number of units in receiving layer to connect -- if 0 then all (remaining after RecvStart) are connected -- otherwise if < remaining then those beyond this point remain unconnected - RecvN evec.Vec2i + RecvN evec.Vector2i } func NewRect() *Rect { @@ -102,8 +102,8 @@ func (cr *Rect) Connect(send, recv *etensor.Shape, same bool) (sendn, recvn *ete sc := cr.Scale if cr.AutoScale { - ssz := math32.V2(float32(sNx), float32(sNy)) - rsz := math32.V2(float32(rNxEff), float32(rNyEff)) + ssz := math32.Vec2(float32(sNx), float32(sNy)) + rsz := math32.Vec2(float32(rNxEff), float32(rNyEff)) sc = ssz.Div(rsz) } @@ -170,8 +170,8 @@ func (cr *Rect) ConnectRecip(send, recv *etensor.Shape, same bool) (sendn, recvn sc := cr.Scale if cr.AutoScale { - ssz := math32.V2(float32(sNx), float32(sNy)) - rsz := math32.V2(float32(rNxEff), float32(rNyEff)) + ssz := math32.Vec2(float32(sNx), float32(sNy)) + rsz := math32.Vec2(float32(rNxEff), float32(rNyEff)) sc = ssz.Div(rsz) } diff --git a/relpos/rel.go b/relpos/rel.go index 8a11cac..a0b2970 100644 --- a/relpos/rel.go +++ b/relpos/rel.go @@ -85,7 +85,7 @@ func NewAbove(other string) Rel { // Pos returns the relative position compared to other position and size, based on settings // osz and sz must both have already been scaled by relevant Scale factor -func (rp *Rel) Pos(op math32.Vec3, osz math32.Vec2, sz math32.Vec2) math32.Vec3 { +func (rp *Rel) Pos(op math32.Vector3, osz math32.Vector2, sz math32.Vector2) math32.Vector3 { if rp.Scale == 0 { rp.Defaults() } diff --git a/relpos/rel_test.go b/relpos/rel_test.go index b970459..d901ff6 100644 --- a/relpos/rel_test.go +++ b/relpos/rel_test.go @@ -16,12 +16,12 @@ func TestRels(t *testing.T) { rp.Defaults() rp.Rel = RightOf rp.YAlign = Center - rs := rp.Pos(math32.Vec3{}, math32.V2(10, 10), math32.V2(4, 4)) + rs := rp.Pos(math32.Vector3{}, math32.Vec2(10, 10), math32.Vec2(4, 4)) fmt.Printf("rp: %v rs: %v\n", rp, rs) rp.YAlign = Front - rs = rp.Pos(math32.Vec3{}, math32.V2(10, 10), math32.V2(4, 4)) + rs = rp.Pos(math32.Vector3{}, math32.Vec2(10, 10), math32.Vec2(4, 4)) fmt.Printf("rp: %v rs: %v\n", rp, rs) rp.YAlign = Back - rs = rp.Pos(math32.Vec3{}, math32.V2(10, 10), math32.V2(4, 4)) + rs = rp.Pos(math32.Vector3{}, math32.Vec2(10, 10), math32.Vec2(4, 4)) fmt.Printf("rp: %v rs: %v\n", rp, rs) }