Skip to content

Commit

Permalink
rename VariableRef to VariableView
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 committed Sep 14, 2022
1 parent c6ee3e8 commit b51f5e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion brainpy/dyn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ def __init__(
for _ in range(v.batch_axis - len(self.index) + 1)])))
else:
index = self.index
self.slice_vars[k] = bm.VariableRef(v, index)
self.slice_vars[k] = bm.VariableView(v, index)

# sub-nodes
nodes = target.nodes(method='relative', level=1, include_self=False).subset(DynamicalSystem)
Expand Down
14 changes: 10 additions & 4 deletions brainpy/math/jaxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'Variable',
'TrainVar',
'Parameter',
'VariableRef',
'VariableView',
]

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


class VariableRef(Variable):
"""A reference of Variable instance."""
class VariableView(Variable):
"""A view of a Variable instance.
This class is used to create a slice view of ``brainpy.math.Variable``.
``VariableView`` can be used to update the subset of the original
Variable instance, and make operations on this subset of the Variable.
"""
def __init__(self, value: Variable, index):
self.index = index
if not isinstance(value, Variable):
raise ValueError('Must be instance of Variable.')
temp_shape = tuple([1] * len(index))
super(VariableRef, self).__init__(jnp.zeros(temp_shape), batch_axis=value.batch_axis)
super(VariableView, self).__init__(jnp.zeros(temp_shape), batch_axis=value.batch_axis)
self._value = value

@property
Expand Down

0 comments on commit b51f5e8

Please sign in to comment.