lava-nc / lava

A Software Framework for Neuromorphic Computing
https://lava-nc.org
Other
529 stars 136 forks source link

Var.shape and Var.init.shape do not match #838

Open erik-ski opened 4 months ago

erik-ski commented 4 months ago

Describe the bug It is possible to create a Var object whose declared shape and "real shape" (i.e. the shape of the array it holds, passed as the init parameter) differ. To reproduce current behavior Steps to reproduce the behavior:

  1. When I run this code
    def my_code():
    shape = (2,2) # innocent shape declaration
    weights = np.array([[1, -1], [-1, 1]]) # init value, corresponding to the shape
    v = Var(shape=(shape, shape), init=weights) # wrong/strange shape declaration (this is similar to the first block of code from tutorial02_ecxitatory_inhibitory_network.ipynb)
    print(v.shape)
    print(v.init.shape)
    if __name__ == "__main__":
    # the var shape attribute and the init value shape should match?
    my_code()
  2. I get this error ...
    shapes won't match

Expected behavior an AssertionError should have happened impeding me to declare such a Var

Environment (please complete the following information):

Additional context I found this in the first block of code from tutorial02_ecxitatory_inhibitory_network.ipynb, in the line

self.weights = Var(shape=(full_shape, full_shape), init=weights)

The tutorial is from the commit 5ed88f790106e8c508f7dcc44200d05eebcf87e0