Skip to content

Commit fab35b9

Browse files
author
Randall C. O'Reilly
committed
major update to unit, synapse variable access (should not affect user code except a couple of cases in hip projects) -- much simpler for extending types. UnitVarIdx and SynVarIdx get index for variable, UnitVal1D, SynVal1D is fast index access used by all routines.
1 parent aa4b7a4 commit fab35b9

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

emer/layer.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,37 +125,33 @@ type Layer interface {
125125
// Note: this is a global list so do not modify!
126126
UnitVarProps() map[string]string
127127

128+
// UnitVarIdx returns the index of given variable within the Neuron,
129+
// according to *this layer's* UnitVarNames() list (using a map to lookup index),
130+
// or -1 and error message if not found.
131+
UnitVarIdx(varNm string) (int, error)
132+
133+
// UnitVal1D returns value of given variable index on given unit, using 1-dimensional index.
134+
// returns NaN on invalid index.
135+
// This is the core unit var access method used by other methods,
136+
// so it is the only one that needs to be updated for derived layer types.
137+
UnitVal1D(varIdx int, idx int) float32
138+
128139
// UnitVals fills in values of given variable name on unit,
129140
// for each unit in the layer, into given float32 slice (only resized if not big enough).
130141
// Returns error on invalid var name.
131-
UnitVals(vals *[]float32, varnm string) error
142+
UnitVals(vals *[]float32, varNm string) error
132143

133144
// UnitValsTensor fills in values of given variable name on unit
134145
// for each unit in the layer, into given tensor.
135146
// If tensor is not already big enough to hold the values, it is
136147
// set to the same shape as the layer.
137148
// Returns error on invalid var name.
138-
UnitValsTensor(tsr etensor.Tensor, varnm string) error
149+
UnitValsTensor(tsr etensor.Tensor, varNm string) error
139150

140151
// UnitVal returns value of given variable name on given unit,
141152
// using shape-based dimensional index.
142-
// returns nil on invalid var name or index -- see Try version for error message.
143-
UnitVal(varnm string, idx []int) float32
144-
145-
// UnitValTry returns value of given variable name on given unit,
146-
// using shape-based dimensional index.
147-
// returns error message if var name not found or invalid index.
148-
UnitValTry(varnm string, idx []int) (float32, error)
149-
150-
// UnitVal1D returns value of given variable name on given unit,
151-
// using 1-dimensional index.
152-
// returns nil on invalid var name or index -- see Try version for error message.
153-
UnitVal1D(varnm string, idx int) float32
154-
155-
// UnitVal1DTry returns value of given variable name on given unit,
156-
// using 1-dimensional index.
157-
// returns error message if var name not found or invalid index.
158-
UnitVal1DTry(varnm string, idx int) (float32, error)
153+
// Returns NaN on invalid var name or index.
154+
UnitVal(varNm string, idx []int) float32
159155

160156
// RecvPrjns returns the full list of receiving projections
161157
RecvPrjns() *Prjns

emer/prjn.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,20 @@ type Prjn interface {
8080

8181
// SynIdx returns the index of the synapse between given send, recv unit indexes
8282
// (1D, flat indexes). Returns -1 if synapse not found between these two neurons.
83-
// This requires searching within connections for receiving unit.
83+
// This requires searching within connections for receiving unit (a bit slow).
8484
SynIdx(sidx, ridx int) int
8585

86+
// SynVarIdx returns the index of given variable within the synapse,
87+
// according to *this prjn's* SynVarNames() list (using a map to lookup index),
88+
// or -1 and error message if not found.
89+
SynVarIdx(varNm string) (int, error)
90+
91+
// SynVal1D returns value of given variable index (from SynVarIdx) on given SynIdx.
92+
// Returns NaN on invalid index.
93+
// This is the core synapse var access method used by other methods,
94+
// so it is the only one that needs to be updated for derived layer types.
95+
SynVal1D(varIdx int, synIdx int) float32
96+
8697
// SynVals sets values of given variable name for each synapse, using the natural ordering
8798
// of the synapses (sender based for Leabra),
8899
// into given float32 slice (only resized if not big enough).
@@ -91,17 +102,14 @@ type Prjn interface {
91102

92103
// SynVal returns value of given variable name on the synapse
93104
// between given send, recv unit indexes (1D, flat indexes).
94-
// Returns math32.NaN() for access errors (see SynValTry for error message)
105+
// Returns math32.NaN() for access errors.
95106
SynVal(varNm string, sidx, ridx int) float32
96107

97-
// SynValTry returns value of given variable name on the synapse
98-
// between given send, recv unit indexes (1D, flat indexes)
99-
// returns error for access errors.
100-
SynValTry(varNm string, sidx, ridx int) (float32, error)
101-
102108
// SetSynVal sets value of given variable name on the synapse
103-
// between given send, recv unit indexes (1D, flat indexes)
104-
// returns error for access errors.
109+
// between given send, recv unit indexes (1D, flat indexes).
110+
// Typically only supports base synapse variables and is not extended
111+
// for derived types.
112+
// Returns error for access errors.
105113
SetSynVal(varNm string, sidx, ridx int, val float32) error
106114

107115
// Defaults sets default parameter values for all Prjn parameters

0 commit comments

Comments
 (0)