Skip to content

Fix Tensor SetItem for Growing Tensor #92

@ntjohnson1

Description

@ntjohnson1

If a tensor of a fixed size is created when using set item it should grow to accommodate provided size. When implementing tendiag I found a few edge cases where this doesn't work properly. Will add examples later.

For a single index:

>>> import pyttb as ttb
>>> import numpy as np
>>> X = ttb.tensor.from_data(np.ones((1,1)))
>>> X[1,1,1] = 1
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<path_to_clone>\pyttb\pyttb\tensor.py", line 1322, in __setitem__
    if (newsiz != self.shape).any():
AttributeError: 'bool' object has no attribute 'any'

For a series of indices:

>>> X = ttb.tensor.from_data(np.ones((2,1)))
>>> X[np.array([[0, 1],[0, 1]])] = 1
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<path_to_clone>\pyttb\pyttb\tensor.py", line 1368, in __setitem__
    newData[idx] = self.data
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
>>> X.data[np.array([[0, 1],[0, 1]])] # works

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdoingActively being worked on

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions