Skip to content

Commit

Permalink
initial renaming of some core packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Apr 14, 2024
1 parent f6fce5a commit 695c419
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The flags are:

Note: any existing `.go` files in the output directory will be removed prior to processing, because the entire directory is built to establish all the types, which might be distributed across multiple files. Any existing `.hlsl` files with the same filenames as those extracted from the `.go` files will be overwritten. Otherwise, you can maintain other custom `.hlsl` files in the `shaders` directory, although it is recommended to treat the entire directory as automatically generated, to avoid any issues.

`gosl` path args can include filenames, directory names, or Go package paths (e.g., `cogentcore.org/core/mat32/fastexp.go` loads just that file from the given package) -- files without any `//gosl:` comment directives will be skipped up front before any expensive processing, so it is not a problem to specify entire directories where only some files are relevant. Also, you can specify a particular file from a directory, then the entire directory, to ensure that a particular file from that directory appears first -- otherwise alphabetical order is used. `gosl` ensures that only one copy of each file is included.
`gosl` path args can include filenames, directory names, or Go package paths (e.g., `cogentcore.org/core/math32/fastexp.go` loads just that file from the given package) -- files without any `//gosl:` comment directives will be skipped up front before any expensive processing, so it is not a problem to specify entire directories where only some files are relevant. Also, you can specify a particular file from a directory, then the entire directory, to ensure that a particular file from that directory appears first -- otherwise alphabetical order is used. `gosl` ensures that only one copy of each file is included.

Any `struct` types encountered will be checked for 16-byte alignment of sub-types and overall sizes as an even multiple of 16 bytes (4 `float32` or `int32` values), which is the alignment used in HLSL and glsl shader languages, and the underlying GPU hardware presumably. Look for error messages on the output from the gosl run. This ensures that direct byte-wise copies of data between CPU and GPU will be successful. The fact that `gosl` operates directly on the original CPU-side Go code uniquely enables it to perform these alignment checks, which are otherwise a major source of difficult-to-diagnose bugs.

Expand Down
2 changes: 1 addition & 1 deletion examples/axon/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
all:
../../gosl -keep -exclude=Update,UpdateParams,Defaults cogentcore.org/core/mat32/fastexp.go minmax chans/chans.go chans kinase time.go neuron.go act.go learn.go layer.go axon.hlsl
../../gosl -keep -exclude=Update,UpdateParams,Defaults cogentcore.org/core/math32/fastexp.go minmax chans/chans.go chans kinase time.go neuron.go act.go learn.go layer.go axon.hlsl

8 changes: 4 additions & 4 deletions examples/axon/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package main

import (
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"

Check failure on line 8 in examples/axon/act.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package cogentcore.org/core/math32; to add it:
"github.com/emer/gosl/v2/examples/axon/chans"
"github.com/emer/gosl/v2/examples/axon/minmax"
"github.com/emer/gosl/v2/slbool"
Expand Down Expand Up @@ -365,8 +365,8 @@ type SpikeNoiseParams struct {
}

func (an *SpikeNoiseParams) Update() {
an.GeExpInt = mat32.Exp(-1000.0 / an.GeHz)
an.GiExpInt = mat32.Exp(-1000.0 / an.GiHz)
an.GeExpInt = math32.Exp(-1000.0 / an.GeHz)
an.GiExpInt = math32.Exp(-1000.0 / an.GiHz)
}

func (an *SpikeNoiseParams) Defaults() {
Expand Down Expand Up @@ -878,7 +878,7 @@ func (ac *ActParams) VmFromG(nrn *Neuron) {
if updtVm && slbool.IsTrue(ac.Spike.Exp) { // add spike current if relevant
exVm = 0.5 * (nvm + nrn.Vm) // midpoint for this
expi = ac.Gbar.L * ac.Spike.ExpSlope *
mat32.FastExp((exVm-ac.Spike.Thr)/ac.Spike.ExpSlope)
math32.FastExp((exVm-ac.Spike.Thr)/ac.Spike.ExpSlope)
if expi > ac.Dt.VmTau {
expi = ac.Dt.VmTau
}
Expand Down
12 changes: 6 additions & 6 deletions examples/axon/chans/ak.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package chans

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

// AKParams control an A-type K channel, which is voltage gated with maximal
// activation around -37 mV. It has two state variables, M (v-gated opening)
Expand Down Expand Up @@ -67,22 +67,22 @@ func (ap *AKParams) Proximal() {

// AlphaFromVK returns the Alpha function from vbio (not normalized, must not exceed 0)
func (ap *AKParams) AlphaFromVK(vbio, k float32) float32 {
return mat32.FastExp(0.03707 * k * (vbio - ap.Voff))
return math32.FastExp(0.03707 * k * (vbio - ap.Voff))
}

// BetaFromVK returns the Beta function from vbio (not normalized, must not exceed 0)
func (ap *AKParams) BetaFromVK(vbio, k float32) float32 {
return mat32.FastExp(ap.Beta * k * (vbio - ap.Voff))
return math32.FastExp(ap.Beta * k * (vbio - ap.Voff))
}

// KFromV returns the K value from vbio (not normalized, must not exceed 0)
func (ap *AKParams) KFromV(vbio float32) float32 {
return -ap.Koff - 1.0/(1.0+mat32.FastExp((vbio+40)/5))
return -ap.Koff - 1.0/(1.0+math32.FastExp((vbio+40)/5))
}

// HFromV returns the H gate value from vbio (not normalized, must not exceed 0)
func (ap *AKParams) HFromV(vbio float32) float32 {
return 1.0 / (1.0 + mat32.FastExp(ap.Hf*(vbio+56)))
return 1.0 / (1.0 + math32.FastExp(ap.Hf*(vbio+56)))
}

// HTauFromV returns the HTau rate constant in msec from vbio (not normalized, must not exceed 0)
Expand Down Expand Up @@ -172,7 +172,7 @@ func (ap *AKsParams) MFromV(vbio float32) float32 {
if vbio > ap.Vmax {
vbio = ap.Vmax
}
return ap.Hf / (1.0 + mat32.FastExp(-ap.Mf*(vbio+ap.Voff)))
return ap.Hf / (1.0 + math32.FastExp(-ap.Mf*(vbio+ap.Voff)))
}

// MFromVnorm returns the M gate function from vnorm
Expand Down
10 changes: 5 additions & 5 deletions examples/axon/chans/gabab.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package chans

import (
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
)

//gosl: start axon
Expand Down Expand Up @@ -48,8 +48,8 @@ func (gp *GABABParams) Defaults() {
}

func (gp *GABABParams) Update() {
gp.TauFact = mat32.Pow(gp.DecayTau/gp.RiseTau, gp.RiseTau/(gp.DecayTau-gp.RiseTau))
gp.MaxTime = ((gp.RiseTau * gp.DecayTau) / (gp.DecayTau - gp.RiseTau)) * mat32.Log(gp.DecayTau/gp.RiseTau)
gp.TauFact = math32.Pow(gp.DecayTau/gp.RiseTau, gp.RiseTau/(gp.DecayTau-gp.RiseTau))
gp.MaxTime = ((gp.RiseTau * gp.DecayTau) / (gp.DecayTau - gp.RiseTau)) * math32.Log(gp.DecayTau/gp.RiseTau)
}

// GFromV returns the GABA-B conductance as a function of normalized membrane potential
Expand All @@ -59,7 +59,7 @@ func (gp *GABABParams) GFromV(v float32) float32 {
if vbio < -90 {
vbio = -90
}
return 1.0 / (1.0 + mat32.FastExp(0.1*((vbio+90)+10)))
return 1.0 / (1.0 + math32.FastExp(0.1*((vbio+90)+10)))
}

// GFromS returns the GABA-B conductance as a function of GABA spiking rate,
Expand All @@ -70,7 +70,7 @@ func (gp *GABABParams) GFromS(s float32) float32 {
if ss > 10 {
ss = 10
}
return 1.0 / (1.0 + mat32.FastExp(-(ss-7.1)/1.4))
return 1.0 / (1.0 + math32.FastExp(-(ss-7.1)/1.4))
}

// DG returns dG delta for g
Expand Down
14 changes: 7 additions & 7 deletions examples/axon/chans/mahp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package chans

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

//gosl: start axon

Expand Down Expand Up @@ -43,7 +43,7 @@ func (mp *MahpParams) Defaults() {
mp.Voff = -30
mp.Vslope = 9
mp.TauMax = 1000
mp.Tadj = mat32.Pow(2.3, (37.0-23.0)/10.0) // 3.2 basically
mp.Tadj = math32.Pow(2.3, (37.0-23.0)/10.0) // 3.2 basically
mp.Update()
}

Expand All @@ -53,10 +53,10 @@ func (mp *MahpParams) Update() {

// EFun handles singularities in an elegant way -- from Mainen impl
func (mp *MahpParams) EFun(z float32) float32 {
if mat32.Abs(z) < 1.0e-4 {
if math32.Abs(z) < 1.0e-4 {
return 1.0 - 0.5*z
}
return z / (mat32.FastExp(z) - 1.0)
return z / (math32.FastExp(z) - 1.0)
}

// NinfTauFromV returns the target infinite-time N gate value and
Expand All @@ -66,8 +66,8 @@ func (mp *MahpParams) NinfTauFromV(vbio float32, ninf, tau *float32) {
vo = vbio - mp.Voff

// logical functions, but have signularity at Voff (vo = 0)
// a := mp.DtMax * vo / (1.0 - mat32.FastExp(-vo/mp.Vslope))
// b := -mp.DtMax * vo / (1.0 - mat32.FastExp(vo/mp.Vslope))
// a := mp.DtMax * vo / (1.0 - math32.FastExp(-vo/mp.Vslope))
// b := -mp.DtMax * vo / (1.0 - math32.FastExp(vo/mp.Vslope))

a = mp.DtMax * mp.Vslope * mp.EFun(-vo/mp.Vslope)
b = mp.DtMax * mp.Vslope * mp.EFun(vo/mp.Vslope)
Expand All @@ -86,7 +86,7 @@ func (mp *MahpParams) NinfTauFromVnorm(v float32, ninf, tau *float32) {
func (mp *MahpParams) DNFromV(v, n float32) float32 {
var ninf, tau float32
mp.NinfTauFromVnorm(v, &ninf, &tau)
// dt := 1.0 - mat32.FastExp(-mp.Tadj/tau) // Mainen comments out this form; Poirazi uses
// dt := 1.0 - math32.FastExp(-mp.Tadj/tau) // Mainen comments out this form; Poirazi uses
// dt := mp.Tadj / tau // simple linear fix
return (ninf - n) / tau
}
Expand Down
6 changes: 3 additions & 3 deletions examples/axon/chans/nmda.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package chans

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

//gosl: start axon

Expand Down Expand Up @@ -62,7 +62,7 @@ func (np *NMDAParams) MgGFromVbio(vbio float32) float32 {
if vbio >= 0 {
return 0
}
return 1.0 / (1.0 + np.MgFact*mat32.FastExp(-0.062*vbio))
return 1.0 / (1.0 + np.MgFact*math32.FastExp(-0.062*vbio))
}

// MgGFromV returns the NMDA conductance as a function of normalized membrane potential
Expand All @@ -79,7 +79,7 @@ func (np *NMDAParams) CaFromVbio(vbio float32) float32 {
if vbio > -0.1 && vbio < 0.1 {
return 1.0 / (0.0756 + 0.5*vbio)
}
return -vbio / (1.0 - mat32.FastExp(0.0756*vbio))
return -vbio / (1.0 - math32.FastExp(0.0756*vbio))
}

// CaFromV returns the calcium current factor as a function of normalized membrane
Expand Down
10 changes: 5 additions & 5 deletions examples/axon/chans/sahp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package chans

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

//gosl: start axon

Expand Down Expand Up @@ -58,10 +58,10 @@ func (mp *SahpParams) Update() {

// EFun handles singularities in an elegant way -- from Mainen impl
func (mp *SahpParams) EFun(z float32) float32 {
if mat32.Abs(z) < 1.0e-4 {
if math32.Abs(z) < 1.0e-4 {
return 1.0 - 0.5*z
}
return z / (mat32.FastExp(z) - 1.0)
return z / (math32.FastExp(z) - 1.0)
}

// NinfTauFromCa returns the target infinite-time N gate value and
Expand All @@ -71,8 +71,8 @@ func (mp *SahpParams) NinfTauFromCa(ca float32, ninf, tau *float32) {
co = ca - mp.Off

// logical functions, but have signularity at Voff (vo = 0)
// a := mp.DtMax * vo / (1.0 - mat32.FastExp(-vo/mp.Vslope))
// b := -mp.DtMax * vo / (1.0 - mat32.FastExp(vo/mp.Vslope))
// a := mp.DtMax * vo / (1.0 - math32.FastExp(-vo/mp.Vslope))
// b := -mp.DtMax * vo / (1.0 - math32.FastExp(vo/mp.Vslope))

a = mp.DtMax * mp.Slope * mp.EFun(-co/mp.Slope)
b = mp.DtMax * mp.Slope * mp.EFun(co/mp.Slope)
Expand Down
8 changes: 4 additions & 4 deletions examples/axon/chans/vgcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package chans

import (
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
)

//gosl: start axon
Expand Down Expand Up @@ -37,7 +37,7 @@ func (np *VGCCParams) GFromV(v float32) float32 {
if vbio > -0.1 && vbio < 0.1 {
return 1.0 / (0.0756 + 0.5*vbio)
}
return -vbio / (1.0 - mat32.FastExp(0.0756*vbio))
return -vbio / (1.0 - math32.FastExp(0.0756*vbio))
}

// MFromV returns the M gate function from vbio (not normalized, must not exceed 0)
Expand All @@ -48,7 +48,7 @@ func (np *VGCCParams) MFromV(vbio float32) float32 {
if vbio > -10 {
return 1
}
return 1.0 / (1.0 + mat32.FastExp(-(vbio + 37)))
return 1.0 / (1.0 + math32.FastExp(-(vbio + 37)))
}

// HFromV returns the H gate function from vbio (not normalized, must not exceed 0)
Expand All @@ -59,7 +59,7 @@ func (np *VGCCParams) HFromV(vbio float32) float32 {
if vbio > -10 {
return 0
}
return 1.0 / (1.0 + mat32.FastExp((vbio+41)*2))
return 1.0 / (1.0 + math32.FastExp((vbio+41)*2))
}

// DMHFromV returns the change at msec update scale in M, H factors
Expand Down
8 changes: 4 additions & 4 deletions examples/axon/learn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package main

import (
"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"github.com/emer/gosl/v2/examples/axon/chans"
"github.com/emer/gosl/v2/examples/axon/kinase"
"github.com/emer/gosl/v2/examples/axon/minmax"
Expand Down Expand Up @@ -119,7 +119,7 @@ func (np *CaSpkParams) Defaults() {
func (np *CaSpkParams) Update() {
np.Dt.Update()
np.SynDt = 1 / np.SynTau
np.SynSpkG = mat32.Sqrt(30) / mat32.Sqrt(np.SynTau)
np.SynSpkG = math32.Sqrt(30) / math32.Sqrt(np.SynTau)
}

// CaFromSpike computes CaSpk* and CaSyn calcium signals based on current spike.
Expand Down Expand Up @@ -243,9 +243,9 @@ func (rl *RLRateParams) RLRateDiff(scap, scad float32) float32 {
if slbool.IsFalse(rl.On) || slbool.IsFalse(rl.Diff) {
return 1.0
}
mx := mat32.Max(scap, scad)
mx := math32.Max(scap, scad)
if mx > rl.SpkThr { // avoid div by 0
dif := mat32.Abs(scap - scad)
dif := math32.Abs(scap - scad)
if dif < rl.DiffThr {
return rl.Min
}
Expand Down
8 changes: 4 additions & 4 deletions examples/axon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"log/slog"

"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
"cogentcore.org/core/vgpu"
"github.com/emer/emergent/v2/timer"
"github.com/emer/gosl/v2/sltype"
Expand All @@ -23,7 +23,7 @@ const DiffTol = 1.0e-3

// note: standard one to use is plain "gosl" which should be go install'd

//go:generate ../../gosl -exclude=Update,UpdateParams,Defaults -keep cogentcore.org/core/mat32/fastexp.go minmax chans/chans.go chans kinase time.go neuron.go act.go learn.go layer.go axon.hlsl
//go:generate ../../gosl -exclude=Update,UpdateParams,Defaults -keep cogentcore.org/core/math32/fastexp.go minmax chans/chans.go chans kinase time.go neuron.go act.go learn.go layer.go axon.hlsl

func init() {
// must lock main thread for gpu! this also means that vulkan must be used
Expand All @@ -49,7 +49,7 @@ func main() {
// AMD is 64, NVIDIA, M1 are 32
gpuThreads := 64
cpuThreads := 10
nInt := int(mat32.IntMultiple(float32(n), float32(gpuThreads)))
nInt := int(math32.IntMultiple(float32(n), float32(gpuThreads)))
n = nInt // enforce optimal n's -- otherwise requires range checking
nGps := nInt / gpuThreads // dispatch n

Expand Down Expand Up @@ -201,7 +201,7 @@ func main() {
v1 := d1.VarByIndex(vi)
v2 := d2.VarByIndex(vi)
diff := ""
if mat32.Abs(v1-v2) > DiffTol {
if math32.Abs(v1-v2) > DiffTol {
diff = "*"
anyDiff = true
}
Expand Down
4 changes: 2 additions & 2 deletions examples/axon/neuron.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"reflect"
"unsafe"

"cogentcore.org/core/mat32"
"cogentcore.org/core/math32"
)

//gosl: start axon
Expand Down Expand Up @@ -373,7 +373,7 @@ func (nrn *Neuron) VarByIndex(idx int) float32 {
func (nrn *Neuron) VarByName(varNm string) (float32, error) {
i, err := NeuronVarIndexByName(varNm)
if err != nil {
return mat32.NaN(), err
return math32.NaN(), err
}
return nrn.VarByIndex(i), nil
}
4 changes: 2 additions & 2 deletions examples/basic/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package main

import "cogentcore.org/core/mat32"
import "cogentcore.org/core/math32"

//gosl: hlsl basic
// #include "fastexp.hlsl"
Expand Down Expand Up @@ -43,7 +43,7 @@ type ParamStruct struct {
// IntegFromRaw computes integrated value from current raw value
func (ps *ParamStruct) IntegFromRaw(ds *DataStruct) {
ds.Integ += ps.Dt * (ds.Raw - ds.Integ)
ds.Exp = mat32.FastExp(-ds.Integ)
ds.Exp = math32.FastExp(-ds.Integ)
}

//gosl: end basic
Expand Down
Loading

0 comments on commit 695c419

Please sign in to comment.