Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pytensor/tensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,11 @@ def as_index_variable(idx):
idx = as_tensor_variable(idx)
if idx.type.dtype not in discrete_dtypes:
raise TypeError("index must be integers or a boolean mask")
if idx.type.dtype == "bool" and idx.type.ndim == 0:
raise NotImplementedError(
"Boolean scalar indexing not implemented. "
"Open an issue in https://github.com/pymc-devs/pytensor/issues if you need this behavior."
)
return idx


Expand Down
2 changes: 1 addition & 1 deletion pytensor/tensor/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def is_empty_array(val):

def __setitem__(self, key, value):
raise TypeError(
"TensorVariable does not support item assignment. Use the output of `set` or `add` instead."
"TensorVariable does not support item assignment. Use the output of `x[idx].set` or `x[idx].inc` instead."
)

def take(self, indices, axis=None, mode="raise"):
Expand Down
5 changes: 5 additions & 0 deletions tests/tensor/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,11 @@ def fun(x, y):
mode=self.mode,
)

def test_boolean_scalar_raises(self):
x = vector("x")
with pytest.raises(NotImplementedError):
x[np.array(True)]


class TestInferShape(utt.InferShapeTester):
@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion tests/tensor/test_variable.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from copy import copy

import numpy as np
Expand Down Expand Up @@ -444,7 +445,7 @@ def test_set_inc(self):
def test_set_item_error(self):
x = matrix("x")

msg = "Use the output of `set` or `add` instead."
msg = re.escape("Use the output of `x[idx].set` or `x[idx].inc` instead.")
with pytest.raises(TypeError, match=msg):
x[0] = 5
with pytest.raises(TypeError, match=msg):
Expand Down
Loading