Skip to content

Remove value getter method from Constant #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions doc/library/compile/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ To show some examples of these access methods...
>>> fn = function([a, b, ((c, c+a+b), 10.0)], [])

>>> # the value associated with c is accessible in 3 ways
>>> fn['s'] is fn.value[c]
>>> fn['s'] is fn.data[c]
True
>>> fn['s'] is fn.container[c].value
>>> fn['s'] is fn.container[c].data
True

>>> fn['s']
Expand All @@ -205,14 +205,14 @@ array(13.0)
[]
>>> fn['s']
array(100.0)
>>> fn.value[c] = 99.0
>>> fn.data[c] = 99.0
>>> fn(1,0)
[]
>>> fn['s']
array(100.0)
>>> fn['s'] == fn.value[c]
>>> fn['s'] == fn.data[c]
True
>>> fn['s'] == fn.container[c].value
>>> fn['s'] == fn.container[c].data
True


Expand Down
4 changes: 2 additions & 2 deletions doc/library/tensor/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ precise) is by calling :func:`pytensor.shared`

x = pytensor.shared(np.random.standard_normal((3, 4)))

This will return a :term:`shared variable <shared variable>` whose ``.value`` is
This will return a :term:`shared variable <shared variable>` whose ``.data`` is
a NumPy `ndarray`. The number of dimensions and dtype of the `Variable` are
inferred from the `ndarray` argument. The argument to `shared` *will not be
copied*, and subsequent changes will be reflected in ``x.value``.
copied*, and subsequent changes will be reflected in ``x.data``.

For additional information, see the :func:`shared() <shared.shared>` documentation.

Expand Down
18 changes: 9 additions & 9 deletions pytensor/compile/function/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def __init__(
# there is no need to refeed the default value.
assert not refeed
else:
c.value = value
c.data = value
c.required = required
c.implicit = input.implicit
# this is a count of how many times the input has been
Expand All @@ -531,7 +531,7 @@ def __init__(
self.inv_finder = inv_finder

# this class is important in overriding the square-bracket notation:
# fn.value[x]
# fn.data[x]
# self reference is available via the closure on the class
class ValueAttribute:
def __getitem__(self, item):
Expand All @@ -546,7 +546,7 @@ def __getitem__(self, item):
"for duplicates."
)
if isinstance(s, Container):
return s.value
return s.data
else:
raise NotImplementedError

Expand All @@ -564,7 +564,7 @@ def __setitem__(self, item, value):
"for duplicates."
)
if isinstance(s, Container):
s.value = value
s.data = value
s.provided += 1
else:
s(value)
Expand Down Expand Up @@ -1624,11 +1624,11 @@ def __init__(
self.name = name
self.trust_input = trust_input

self.required = [(i.value is None) for i in self.inputs]
self.required = [(i.data is None) for i in self.inputs]
self.refeed = [
(
i.value is not None
and not isinstance(i.value, Container)
i.data is not None
and not isinstance(i.data, Container)
and i.update is None
)
for i in self.inputs
Expand Down Expand Up @@ -1898,10 +1898,10 @@ def convert_function_input(input):
if len(input) == 1:
return input[0]
elif len(input) == 2:
input, value = input
input, data = input
if name is not None:
input.name = name
input.value = value
input.data = data
return input
else:
raise TypeError(f"The input specification is not valid: {input}")
Expand Down
4 changes: 0 additions & 4 deletions pytensor/graph/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,6 @@ def owner(self, value) -> None:
if value is not None:
raise ValueError("Constant instances cannot have an owner.")

@property
def value(self):
return self.data


def walk(
nodes: Iterable[T],
Expand Down
8 changes: 4 additions & 4 deletions pytensor/link/numba/dispatch/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def unbox_matrix(typ, obj, c):
indptr = c.pyapi.object_getattr_string(obj, "indptr")
shape = c.pyapi.object_getattr_string(obj, "shape")

struct_ptr.data = c.unbox(typ.data, data).value
struct_ptr.indices = c.unbox(typ.indices, indices).value
struct_ptr.indptr = c.unbox(typ.indptr, indptr).value
struct_ptr.shape = c.unbox(typ.shape, shape).value
struct_ptr.data = c.unbox(typ.data, data).data
struct_ptr.indices = c.unbox(typ.indices, indices).data
struct_ptr.indptr = c.unbox(typ.indptr, indptr).data
struct_ptr.shape = c.unbox(typ.shape, shape).data

c.pyapi.decref(data)
c.pyapi.decref(indices)
Expand Down
4 changes: 2 additions & 2 deletions pytensor/scan/rewriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ def scan_save_mem(fgraph, node):
if (
i <= op.info.n_mit_mot
and isinstance(this_slice[0], ScalarConstant)
and this_slice[0].value == -1
and this_slice[0].data == -1
):
start = nw_steps - 1
else:
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def scan_save_mem(fgraph, node):
# Special case when only last value is requested
if (
isinstance(old_slices[0], ScalarConstant)
and old_slices[0].value == -1
and old_slices[0].data == -1
):
position = old_slices[0]
else:
Expand Down
4 changes: 2 additions & 2 deletions pytensor/tensor/extra_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ def broadcast_shape_iter(
(one,) * (max_dims - len(a))
+ tuple(
one
if sh == 1 or isinstance(sh, Constant) and sh.value == 1
if sh == 1 or isinstance(sh, Constant) and sh.data == 1
else (ps.as_scalar(sh) if not isinstance(sh, Variable) else sh)
for sh in a
)
Expand Down Expand Up @@ -1603,7 +1603,7 @@ def broadcast_shape_iter(
const_nb_shapes: set[Variable] = set()
for shape in non_bcast_shapes:
if isinstance(shape, Constant):
const_nb_shapes.add(shape.value.item())
const_nb_shapes.add(shape.data.item())
else:
nonconst_nb_shapes.add(shape)

Expand Down
2 changes: 1 addition & 1 deletion pytensor/tensor/rewriting/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ def local_mul_to_sqr(fgraph, node):
@node_rewriter([int_div])
def local_intdiv_by_one(fgraph, node):
"""x // 1 -> x"""
if isinstance(node.inputs[1], TensorConstant) and np.all(node.inputs[1].value == 1):
if isinstance(node.inputs[1], TensorConstant) and np.all(node.inputs[1].data == 1):
return [node.inputs[0].astype(node.outputs[0].dtype)]


Expand Down
Loading