partial vector implementation added

This commit is contained in:
Nicolas Kruse 2025-10-23 12:49:30 +02:00
parent 0d1d0a03c9
commit db7216d0b6
2 changed files with 14 additions and 10 deletions

View File

@ -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)

14
src/copapy/_vectors.py Normal file
View File

@ -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)))