Let M be a module like the following, producing the main output as cell view:
module M(i:data, x:data) ... cell view = ... module end
Now we want to instantiate M several times - and i is the index (0,1,2,…) and x the row input for which we’d like to do the instantiation. This is done with:
import circuitarray
import M
private cell rows = [ 1, 2, 3 ]
private cell ca = circuitarray.make((i,x) -> M(i,x), rows)
alias M_views = circuitarray.extract(ca, m -> m.view)
circuitarray.makeCached(Since PR #321.)
This is an alternate way of creating the circuitarray. To be used like:
import circuitarray
import M
private cell rows = [ 1, 2, 3 ]
private cell ca = circuitarray.makeCached(link(ca), (i,x) -> M(i,x), rows)
alias M_views = circuitarray.extract(ca, m -> m.view)
The difference is that the circuitarray is only created again when the contents of the rows change (and not always when new rows are computed). The visible behavior is identical to make.
Note that
makeCached is the link to the defining cellmakeCached must be a cell name, and cannot be an arbitrary expressioncircuitarray.makeOnce(Since PR #282.)
This is an alternate way of creating the circuitarray. To be used like:
import circuitarray
import M
private cell rows = [ 1, 2, 3 ]
private cell ca = circuitarray.makeOnce(link(ca), (i,x) -> M(i,x), rows)
alias M_views = circuitarray.extract(ca, m -> m.view)
The difference is that the circuitarray is only created once, i.e. when the rows change, the array is not updated.
circuitarray.makeWithKeyedRowCache(Since PR #632.)
This version of circuitarray features an internal cache for the component modules. The cache is keyed by a string ID. The user of makeWithKeyedRowCache needs to pass in a projection function that returns the string ID of each input element. If the component module for this element already exists in the cache, it is reused. Normally, no spreadsheet propagation is triggered inside the component module, and the already computed result values are directly available.