From a8e70cd5d63c80fa0530635f15d98f5fe8e2bf70 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Sat, 20 Dec 2025 22:10:22 +0100 Subject: [PATCH] volatile property from value type removed. --- src/copapy/_basic_types.py | 26 ++++++++++++-------------- src/copapy/_matrices.py | 14 +++++++------- src/copapy/_mixed.py | 2 +- src/copapy/_vectors.py | 30 +++++++++++++++--------------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/copapy/_basic_types.py b/src/copapy/_basic_types.py index 3f551fe..d0f5612 100644 --- a/src/copapy/_basic_types.py +++ b/src/copapy/_basic_types.py @@ -76,7 +76,6 @@ class Net: def __init__(self, dtype: str, source: Node): self.dtype = dtype self.source = source - self.volatile = False def __repr__(self) -> str: names = get_var_name(self) @@ -93,7 +92,7 @@ class value(Generic[TNum], Net): Attributes: dtype (str): Data type of this value. """ - def __init__(self, source: TNum | Node, dtype: str | None = None, volatile: bool = True): + def __init__(self, source: TNum | Node, dtype: str | None = None): """Instance a value. Args: @@ -113,7 +112,6 @@ class value(Generic[TNum], Net): else: self.source = CPConstant(source, False) self.dtype = 'int' - self.volatile = volatile @overload def __add__(self: 'value[TNum]', other: 'value[TNum] | TNum') -> 'value[TNum]': ... @@ -225,32 +223,32 @@ class value(Generic[TNum], Net): def __neg__(self: TCPNum) -> TCPNum: if self.dtype == 'float': - return cast(TCPNum, add_op('sub', [value(0.0, volatile=False), self])) - return cast(TCPNum, add_op('sub', [value(0, volatile=False), self])) + return cast(TCPNum, add_op('sub', [value(0.0), self])) + return cast(TCPNum, add_op('sub', [value(0), self])) def __gt__(self, other: TVarNumb) -> 'value[int]': ret = add_op('gt', [self, other]) - return value(ret.source, dtype='bool', volatile=False) + return value(ret.source, dtype='bool') def __lt__(self, other: TVarNumb) -> 'value[int]': ret = add_op('gt', [other, self]) - return value(ret.source, dtype='bool', volatile=False) + return value(ret.source, dtype='bool') def __ge__(self, other: TVarNumb) -> 'value[int]': ret = add_op('ge', [self, other]) - return value(ret.source, dtype='bool', volatile=False) + return value(ret.source, dtype='bool') def __le__(self, other: TVarNumb) -> 'value[int]': ret = add_op('ge', [other, self]) - return value(ret.source, dtype='bool', volatile=False) + return value(ret.source, dtype='bool') def __eq__(self, other: TVarNumb) -> 'value[int]': # type: ignore ret = add_op('eq', [self, other], True) - return value(ret.source, dtype='bool', volatile=False) + return value(ret.source, dtype='bool') def __ne__(self, other: TVarNumb) -> 'value[int]': # type: ignore ret = add_op('ne', [self, other], True) - return value(ret.source, dtype='bool', volatile=False) + return value(ret.source, dtype='bool') @overload def __mod__(self: 'value[TNum]', other: 'value[TNum] | TNum') -> 'value[TNum]': ... @@ -332,11 +330,11 @@ class value(Generic[TNum], Net): class CPConstant(Node): - def __init__(self, value: int | float, constant: bool = True): + def __init__(self, value: int | float, anonymous: bool = True): self.dtype, self.value = _get_data_and_dtype(value) self.name = 'const_' + self.dtype self.args = tuple() - self.node_hash = hash(value) ^ hash(self.dtype) if constant else id(self) + self.node_hash = hash(value) ^ hash(self.dtype) if anonymous else id(self) class Write(Node): @@ -362,7 +360,7 @@ class Op(Node): def net_from_value(val: Any) -> value[Any]: vi = CPConstant(val) - return value(vi, vi.dtype, False) + return value(vi, vi.dtype) @overload diff --git a/src/copapy/_matrices.py b/src/copapy/_matrices.py index 45ab495..2bfe7ab 100644 --- a/src/copapy/_matrices.py +++ b/src/copapy/_matrices.py @@ -83,7 +83,7 @@ class matrix(Generic[TNum]): tuple(a + other for a in row) for row in self.values ) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return matrix( tuple(a + o if isinstance(a, value) else a + other for a in row) for row in self.values @@ -117,7 +117,7 @@ class matrix(Generic[TNum]): tuple(a - other for a in row) for row in self.values ) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return matrix( tuple(a - o if isinstance(a, value) else a - other for a in row) for row in self.values @@ -140,7 +140,7 @@ class matrix(Generic[TNum]): tuple(other - a for a in row) for row in self.values ) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return matrix( tuple(o - a if isinstance(a, value) else other - a for a in row) for row in self.values @@ -168,7 +168,7 @@ class matrix(Generic[TNum]): tuple(a * other for a in row) for row in self.values ) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return matrix( tuple(a * o if isinstance(a, value) else a * other for a in row) for row in self.values @@ -195,7 +195,7 @@ class matrix(Generic[TNum]): tuple(a / other for a in row) for row in self.values ) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return matrix( tuple(a / o if isinstance(a, value) else a / other for a in row) for row in self.values @@ -214,7 +214,7 @@ class matrix(Generic[TNum]): tuple(other / a for a in row) for row in self.values ) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return matrix( tuple(o / a if isinstance(a, value) else other / a for a in row) for row in self.values @@ -305,7 +305,7 @@ class matrix(Generic[TNum]): """Convert all elements to copapy values if any element is a copapy value.""" if any(isinstance(val, value) for row in self.values for val in row): return matrix( - tuple(value(val, volatile=False) if not isinstance(val, value) else val for val in row) + tuple(value(val) if not isinstance(val, value) else val for val in row) for row in self.values ) else: diff --git a/src/copapy/_mixed.py b/src/copapy/_mixed.py index f8624ed..5b84e93 100644 --- a/src/copapy/_mixed.py +++ b/src/copapy/_mixed.py @@ -19,6 +19,6 @@ def mixed_sum(scalars: Iterable[int | float | value[Any]]) -> Any: def mixed_homogenize(scalars: Iterable[T | value[T]]) -> Iterable[T] | Iterable[value[T]]: if any(isinstance(val, value) for val in scalars): - return (value(val, volatile=False) if not isinstance(val, value) else val for val in scalars) + return (value(val) if not isinstance(val, value) else val for val in scalars) else: return (val for val in scalars if not isinstance(val, value)) diff --git a/src/copapy/_vectors.py b/src/copapy/_vectors.py index 1295e1f..d93eaf9 100644 --- a/src/copapy/_vectors.py +++ b/src/copapy/_vectors.py @@ -59,7 +59,7 @@ class vector(Generic[TNum]): return vector(a + b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a + other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a + o if isinstance(a, value) else a + other for a in self.values) @overload @@ -85,7 +85,7 @@ class vector(Generic[TNum]): return vector(a - b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a - other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a - o if isinstance(a, value) else a - other for a in self.values) @overload @@ -100,7 +100,7 @@ class vector(Generic[TNum]): return vector(b - a for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(other - a for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(o - a if isinstance(a, value) else other - a for a in self.values) @overload @@ -117,7 +117,7 @@ class vector(Generic[TNum]): return vector(a * b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a * other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a * o if isinstance(a, value) else a * other for a in self.values) @overload @@ -143,7 +143,7 @@ class vector(Generic[TNum]): return vector(a ** b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a ** other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a ** o if isinstance(a, value) else a ** other for a in self.values) @overload @@ -158,7 +158,7 @@ class vector(Generic[TNum]): return vector(b ** a for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(other ** a for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(o ** a if isinstance(a, value) else other ** a for a in self.values) def __truediv__(self, other: VecNumLike) -> 'vector[float]': @@ -167,7 +167,7 @@ class vector(Generic[TNum]): return vector(a / b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a / other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a / o if isinstance(a, value) else a / other for a in self.values) def __rtruediv__(self, other: VecNumLike) -> 'vector[float]': @@ -176,7 +176,7 @@ class vector(Generic[TNum]): return vector(b / a for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(other / a for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(o / a if isinstance(a, value) else other / a for a in self.values) @overload @@ -220,7 +220,7 @@ class vector(Generic[TNum]): return vector(a > b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a > other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a > o if isinstance(a, value) else a > other for a in self.values) def __lt__(self, other: VecNumLike) -> 'vector[int]': @@ -229,7 +229,7 @@ class vector(Generic[TNum]): return vector(a < b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a < other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a < o if isinstance(a, value) else a < other for a in self.values) def __ge__(self, other: VecNumLike) -> 'vector[int]': @@ -238,7 +238,7 @@ class vector(Generic[TNum]): return vector(a >= b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a >= other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a >= o if isinstance(a, value) else a >= other for a in self.values) def __le__(self, other: VecNumLike) -> 'vector[int]': @@ -247,7 +247,7 @@ class vector(Generic[TNum]): return vector(a <= b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a <= other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a <= o if isinstance(a, value) else a <= other for a in self.values) def __eq__(self, other: VecNumLike | Sequence[int | float]) -> 'vector[int]': # type: ignore @@ -256,7 +256,7 @@ class vector(Generic[TNum]): return vector(a == b for a, b in zip(self.values, other)) if isinstance(other, value): return vector(a == other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a == o if isinstance(a, value) else a == other for a in self.values) def __ne__(self, other: VecNumLike) -> 'vector[int]': # type: ignore @@ -265,7 +265,7 @@ class vector(Generic[TNum]): return vector(a != b for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(a != other for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(a != o if isinstance(a, value) else a != other for a in self.values) @property @@ -307,7 +307,7 @@ class vector(Generic[TNum]): return vector(func(a, b) for a, b in zip(self.values, other.values)) if isinstance(other, value): return vector(func(a, other) for a in self.values) - o = value(other, volatile=False) # Make sure a single constant is allocated + o = value(other) # Make sure a single constant is allocated return vector(func(a, o) if isinstance(a, value) else a + other for a in self.values)