Flax and other libraries support object-oriented (OO) programming by providing variable tracing during computation and transformations. On the contrary, BrainPy is designed to be Pythonic, and its OO interface supports tracing variables before transformations. Now, we are excited that BrainPy also supports tracing variables during transformations.
Particularly, we provide .tracing_variable().
Here is the usage example::
class Example(bm.BrainPyObject):
def fun(self):
# The first time of calling `.fun()`, this line will create a Variable instance.
# If users repeatedly call `.fun()` function, this line will not initialize variables again.
# Instead, it will return the variable has been created.
self.tracing_variable('a', bm.zeros, (10,))
# The created variable can be accessed with self.xxx
self.a.value = bm.ones(10)
# Calling this function again will not reinitialize the
# variable again, Instead, it will return the variable
# that has been created.
a = self.tracing_variable('a', bm.zeros, (10,))
Flax and other libraries support object-oriented (OO) programming by providing variable tracing during computation and transformations. On the contrary, BrainPy is designed to be Pythonic, and its OO interface supports tracing variables before transformations. Now, we are excited that BrainPy also supports tracing variables during transformations.
Particularly, we provide
.tracing_variable()
.Here is the usage example::