From db7216d0b6679bb9d5b28e9a28a324c891f310d1 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Thu, 23 Oct 2025 12:49:30 +0200 Subject: [PATCH] partial vector implementation added --- src/copapy/_basic_types.py | 10 ---------- src/copapy/_vectors.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 src/copapy/_vectors.py diff --git a/src/copapy/_basic_types.py b/src/copapy/_basic_types.py index edf630b..0419517 100644 --- a/src/copapy/_basic_types.py +++ b/src/copapy/_basic_types.py @@ -311,16 +311,6 @@ class cpbool(cpint): self.dtype = 'bool' -class cpvector: - def __init__(self, *value: NumLike): - self.value = value - - def __add__(self, other: 'cpvector') -> 'cpvector': - assert len(self.value) == len(other.value) - tup = (a + b for a, b in zip(self.value, other.value)) - return cpvector(*(v for v in tup if isinstance(v, CPNumber))) - - class InitVar(Node): def __init__(self, value: int | float): self.dtype, self.value = _get_data_and_dtype(value) diff --git a/src/copapy/_vectors.py b/src/copapy/_vectors.py new file mode 100644 index 0000000..d9519bf --- /dev/null +++ b/src/copapy/_vectors.py @@ -0,0 +1,14 @@ +from copapy import NumLike, CPNumber, cpint, cpfloat, cpbool +from typing import Generic, TypeVar, Iterable, Any + +T = TypeVar("T", bound=CPNumber) +T2 = TypeVar("T2", bound=CPNumber) + +class cpvector(Generic[T]): + def __init__(self, value: Iterable[T]): + self.value = tuple(value) + + def __add__(self, other: 'cpvector[Any]') -> 'cpvector[CPNumber]': + assert len(self.value) == len(other.value) + tup = (a + b for a, b in zip(self.value, other.value)) + return cpvector(*(v for v in tup if isinstance(v, CPNumber))) \ No newline at end of file