mirror of https://github.com/Nonannet/copapy.git
partial vector implementation added
This commit is contained in:
parent
0d1d0a03c9
commit
db7216d0b6
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
Loading…
Reference in New Issue