etaler / Etaler

A flexable HTM (Hierarchical Temporal Memory) framework with full GPU support.
BSD 3-Clause "New" or "Revised" License
89 stars 14 forks source link

Support 0D tensors #153

Closed marty1885 closed 4 years ago

marty1885 commented 4 years ago

Related to: etaler/PyEtaler#4

PyEtaler can't convert et.Tensor into np.ndarray using np.array. (NOTE: et.Tensor.numpy() works) This is caused by Elater handles scalars as a 1D, length 1 tensor and have no concept of a 0D tensor. Leading to numpy wrongfully assuming Etaler's tensors are infinite in dimension.

a = et::ones({4, 4});
cout << a[0][0] << endl; // prints 1

// But numpy is not expecting this behavior.
// Caused  by a[0][0] is a 1D tensor. Then indexing into it still returns a 1D tensor.
// NOTE: a[0, 0, 0] will correctly throw an exception
cout << a[0][0][0] << endl; // also prints 1

Numpy is expecting the behavior of:

a = np.ones((4, 4))
print(a[0][0]) # prints 1

# This fails because indexing a 0D array makes no sense
print(a[0][0][0])

Actions: