Skip to content

Commit

Permalink
Add a function to iterate on all of the model's buffers (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Aug 7, 2023
1 parent 121ed3d commit af3c470
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 13 additions & 1 deletion actr/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,19 @@ func (model Model) LookupModule(moduleName string) modules.Interface {
return nil
}

// BufferNames returns a slice of valid buffers.
// Buffers returns a slice of all valid buffers.
func (model Model) Buffers() (list buffer.List) {
for _, module := range model.Modules {
buffers := module.Buffers()
if len(buffers) > 0 {
list = append(list, buffers...)
}
}

return
}

// BufferNames returns a slice of valid buffer names.
func (model Model) BufferNames() (list []string) {
for _, module := range model.Modules {
names := module.Buffers().Names()
Expand Down
10 changes: 5 additions & 5 deletions amod/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ func validateModuleInitialization(model *actr.Model, log *issueLog, init *module
func validateInterModuleInitDependencies(model *actr.Model, log *issueLog, config *moduleConfig) (err error) {
// when max_spread_strength is not set on memory, check for spreading_activation set on any buffer
if model.Memory.MaxSpreadStrength == nil {
bufferNames := model.BufferNames()

for _, name := range bufferNames {
buffer := model.LookupBuffer(name)
for _, buffer := range model.Buffers() {
if buffer.SpreadingActivation() != buffer.DefaultSpreadingActivation() {
log.errorTR(config.Tokens, 0, 1, "spreading_activation set on buffer %q, but max_spread_strength not set on memory module", name)
log.errorTR(config.Tokens, 0, 1,
"spreading_activation set on buffer %q, but max_spread_strength not set on memory module",
buffer.Name(),
)
err = ErrCompile
}
}
Expand Down

0 comments on commit af3c470

Please sign in to comment.