Skip to content

Commit 4b43e92

Browse files
ntjohnson1dmdunla
andauthored
Fix support for numpy 2.4 (#472)
* Fix support for numpy 2.4 --------- Co-authored-by: Danny Dunlavy <[email protected]>
1 parent 7d0dde2 commit 4b43e92

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010
requires-python = ">=3.10"
1111

1212
dependencies = [
13-
"numpy<2.4,>=1.24",
13+
"numpy<2.5,>=1.24",
1414
"numpy_groupies>0.11",
1515
"scipy<1.17,>1.9",
1616
"matplotlib>3.7",

pyttb/sptensor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,9 @@ def ttv(
20302030
)
20312031
if np.count_nonzero(c) <= 0.5 * newsiz:
20322032
return ttb.sptensor.from_aggregator(
2033-
np.arange(0, newsiz)[:, None], c.reshape((len(c), 1)), tuple(newsiz)
2033+
np.arange(0, newsiz.item())[:, None],
2034+
c.reshape((len(c), 1)),
2035+
tuple(newsiz),
20342036
)
20352037
return ttb.tensor(c, tuple(newsiz), copy=False)
20362038

@@ -2574,7 +2576,7 @@ def _set_subtensor(self, key, value): # noqa: PLR0912, PLR0915
25742576
# Generate appropriately sized ones vectors
25752577
o = []
25762578
for n in range(N):
2577-
o.append(np.ones((int(nssubs[n]), 1)))
2579+
o.append(np.ones((int(nssubs[n].item()), 1)))
25782580

25792581
# Generate each column of the subscripts in turn
25802582
for n in range(N):

pyttb/tensor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,8 @@ def _set_linear(self, key, value):
21722172
idx = np.array(range(prod(self.shape))[key])
21732173
idx = tt_ind2sub(self.shape, idx)
21742174
if idx.shape[0] == 1:
2175+
if isinstance(value, np.ndarray) and value.size == 1:
2176+
value = value.item()
21752177
self.data[tuple(idx[0, :])] = value
21762178
else:
21772179
actualIdx = tuple(idx.transpose())

0 commit comments

Comments
 (0)