Skip to content

Commit 64d1e21

Browse files
authored
update loop docs and apis (#261)
update loop docs and apis
2 parents f087e9d + 8d70a27 commit 64d1e21

File tree

5 files changed

+158
-147
lines changed

5 files changed

+158
-147
lines changed

brainpy/dyn/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ def __init__(
12891289
for _ in range(v.batch_axis - len(self.index) + 1)])))
12901290
else:
12911291
index = self.index
1292-
self.slice_vars[k] = bm.VariableRef(v, index)
1292+
self.slice_vars[k] = bm.VariableView(v, index)
12931293

12941294
# sub-nodes
12951295
nodes = target.nodes(method='relative', level=1, include_self=False).subset(DynamicalSystem)

brainpy/math/controls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ def _body_fun(op):
785785
if not isinstance(static_vals, (tuple, list)):
786786
static_vals = (static_vals, )
787787
new_vals = body_fun(*static_vals)
788+
if new_vals is None:
789+
new_vals = tuple()
790+
if not isinstance(new_vals, tuple):
791+
new_vals = (new_vals, )
788792
return [v.value for v in dyn_vars], new_vals
789793

790794
def _cond_fun(op):

brainpy/math/jaxarray.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'Variable',
1717
'TrainVar',
1818
'Parameter',
19-
'VariableRef',
19+
'VariableView',
2020
]
2121

2222
# Ways to change values in a zero-dimensional array
@@ -1494,14 +1494,20 @@ def __init__(self, value, dtype=None, batch_axis: int = None):
14941494
lambda aux_data, flat_contents: Parameter(*flat_contents))
14951495

14961496

1497-
class VariableRef(Variable):
1498-
"""A reference of Variable instance."""
1497+
class VariableView(Variable):
1498+
"""A view of a Variable instance.
1499+
1500+
This class is used to create a slice view of ``brainpy.math.Variable``.
1501+
1502+
``VariableView`` can be used to update the subset of the original
1503+
Variable instance, and make operations on this subset of the Variable.
1504+
"""
14991505
def __init__(self, value: Variable, index):
15001506
self.index = index
15011507
if not isinstance(value, Variable):
15021508
raise ValueError('Must be instance of Variable.')
15031509
temp_shape = tuple([1] * len(index))
1504-
super(VariableRef, self).__init__(jnp.zeros(temp_shape), batch_axis=value.batch_axis)
1510+
super(VariableView, self).__init__(jnp.zeros(temp_shape), batch_axis=value.batch_axis)
15051511
self._value = value
15061512

15071513
@property

docs/tutorial_building/build_conductance_neurons.ipynb

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
]
3737
},
3838
{
39-
"cell_type": "code",
40-
"execution_count": null,
41-
"outputs": [],
39+
"cell_type": "markdown",
4240
"source": [
4341
"On the other hand, simplified models do not care about the physiological features of neurons but mainly focus on how to reproduce the exact spike timing. Therefore, they are more simplified and maybe not biologically explicable.\n",
4442
"\n",
@@ -47,21 +45,19 @@
4745
"metadata": {
4846
"collapsed": false,
4947
"pycharm": {
50-
"name": "#%%\n"
48+
"name": "#%% md\n"
5149
}
5250
}
5351
},
5452
{
55-
"cell_type": "code",
56-
"execution_count": null,
57-
"outputs": [],
53+
"cell_type": "markdown",
5854
"source": [
5955
"## Building an ion channel"
6056
],
6157
"metadata": {
6258
"collapsed": false,
6359
"pycharm": {
64-
"name": "#%%\n"
60+
"name": "#%% md\n"
6561
}
6662
}
6763
},
@@ -436,17 +432,6 @@
436432
"source": [
437433
"By combining different ion channels, we can get different types of conductance-based neuron models easily and straightforwardly. To see all predifined channel models in BrainPy, please click [here](../apis/dyn.rst)."
438434
]
439-
},
440-
{
441-
"cell_type": "code",
442-
"execution_count": null,
443-
"metadata": {
444-
"pycharm": {
445-
"name": "#%%\n"
446-
}
447-
},
448-
"outputs": [],
449-
"source": []
450435
}
451436
],
452437
"metadata": {

0 commit comments

Comments
 (0)