mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
Fix __new__ constructors
This commit is contained in:
parent
62148185b2
commit
8938a7824d
@ -203,29 +203,29 @@ class flatiter[A]:
|
||||
def copy(self):
|
||||
return self.base.flatten()
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _UnaryFunctor:
|
||||
op: F
|
||||
F: type
|
||||
|
||||
def __new__(op: F, F: type) -> _UnaryFunctor[F]:
|
||||
return _UnaryFunctor[F](op)
|
||||
return superf(op)
|
||||
|
||||
def __call__(self, y, x):
|
||||
y[0] = self.op(x[0])
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _InplaceUnaryFunctor:
|
||||
op: F
|
||||
F: type
|
||||
|
||||
def __new__(op: F, F: type) -> _InplaceUnaryFunctor[F]:
|
||||
return _InplaceUnaryFunctor[F](op)
|
||||
return superf(op)
|
||||
|
||||
def __call__(self, x):
|
||||
x[0] = self.op(x[0])
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _BinaryFunctor:
|
||||
op: F
|
||||
F: type
|
||||
@ -233,23 +233,23 @@ class _BinaryFunctor:
|
||||
R2: type
|
||||
|
||||
def __new__(op: F, R1: type, R2: type, F: type) -> _BinaryFunctor[F, R1, R2]:
|
||||
return _BinaryFunctor[F, R1, R2](op)
|
||||
return superf(op)
|
||||
|
||||
def __call__(self, z, x, y):
|
||||
z[0] = self.op(util.cast(x[0], R1), util.cast(y[0], R2))
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _InplaceBinaryFunctor:
|
||||
op: F
|
||||
F: type
|
||||
|
||||
def __new__(op: F, F: type) -> _InplaceBinaryFunctor[F]:
|
||||
return _InplaceBinaryFunctor[F](op)
|
||||
return superf(op)
|
||||
|
||||
def __call__(self, x, y):
|
||||
x[0] = self.op(x[0], util.cast(y[0], type(x[0])))
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _RightBinaryFunctor:
|
||||
op: F
|
||||
F: type
|
||||
@ -257,12 +257,12 @@ class _RightBinaryFunctor:
|
||||
R2: type
|
||||
|
||||
def __new__(op: F, R1: type, R2: type, F: type) -> _RightBinaryFunctor[F, R1, R2]:
|
||||
return _RightBinaryFunctor[F, R1, R2](op)
|
||||
return superf(op)
|
||||
|
||||
def __call__(self, z, x, y):
|
||||
z[0] = self.op(util.cast(y[0], R2), util.cast(x[0], R1))
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _ScalarFunctor:
|
||||
op: F
|
||||
y: Y
|
||||
@ -272,12 +272,12 @@ class _ScalarFunctor:
|
||||
R2: type
|
||||
|
||||
def __new__(op: F, y: Y, R1: type, R2: type, F: type, Y: type) -> _ScalarFunctor[F, Y, R1, R2]:
|
||||
return _ScalarFunctor[F, Y, R1, R2](op, y)
|
||||
return superf(op, y)
|
||||
|
||||
def __call__(self, z, x):
|
||||
z[0] = self.op(util.cast(x[0], R1), util.cast(self.y, R2))
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _InplaceScalarFunctor:
|
||||
op: F
|
||||
y: Y
|
||||
@ -285,13 +285,13 @@ class _InplaceScalarFunctor:
|
||||
Y: type
|
||||
|
||||
def __new__(op: F, y: Y, F: type, Y: type) -> _InplaceScalarFunctor[F, Y]:
|
||||
return _InplaceScalarFunctor[F, Y](op, y)
|
||||
return superf(op, y)
|
||||
|
||||
def __call__(self, x):
|
||||
x[0] = self.op(x[0], util.cast(self.y, type(x[0])))
|
||||
|
||||
|
||||
@tuple(init=False)
|
||||
@tuple
|
||||
class _RightScalarFunctor:
|
||||
op: F
|
||||
y: Y
|
||||
@ -301,7 +301,7 @@ class _RightScalarFunctor:
|
||||
R2: type
|
||||
|
||||
def __new__(op: F, y: Y, R1: type, R2: type, F: type, Y: type) -> _RightScalarFunctor[F, Y, R1, R2]:
|
||||
return _RightScalarFunctor[F, Y, R1, R2](op, y)
|
||||
return superf(op, y)
|
||||
|
||||
def __call__(self, z, x):
|
||||
z[0] = self.op(util.cast(self.y, R2), util.cast(x[0], R1))
|
||||
|
@ -525,7 +525,7 @@ class Converters:
|
||||
|
||||
def __new__(funcs, mask, usecols,
|
||||
dtype: type) -> Converters[dtype, F, M, U]:
|
||||
return Converters[dtype, F, M, U](funcs, mask, usecols)
|
||||
return superf(funcs, mask, usecols)
|
||||
|
||||
def __call__(self, field: str, idx: int):
|
||||
usecols = self.usecols
|
||||
|
@ -352,7 +352,7 @@ class _GradualFunctor:
|
||||
kwargs: KW,
|
||||
R: type,
|
||||
KW: type) -> _GradualFunctor[dtype, conv_to_float, R, KW]:
|
||||
return _GradualFunctor[dtype, conv_to_float, R, KW](redux, k, kwargs)
|
||||
return superf(redux, k, kwargs)
|
||||
|
||||
def __call__(self, q, p):
|
||||
e = _cast_elem(p[0], self.dtype, self.conv_to_float)
|
||||
|
@ -237,7 +237,7 @@ class _UnaryFunctor:
|
||||
UF: type
|
||||
|
||||
def __new__(ufunc: UF, dtype: type, UF: type) -> _UnaryFunctor[dtype, UF]:
|
||||
return _UnaryFunctor[dtype, UF](ufunc)
|
||||
return superf(ufunc)
|
||||
|
||||
def __call__(self, y, x):
|
||||
y[0] = self.ufunc._f(x[0], dtype=self.dtype, dtype_out=type(y[0]))
|
||||
@ -250,7 +250,7 @@ class _UnaryWhereFunctor:
|
||||
|
||||
def __new__(ufunc: UF, dtype: type,
|
||||
UF: type) -> _UnaryWhereFunctor[dtype, UF]:
|
||||
return _UnaryWhereFunctor[dtype, UF](ufunc)
|
||||
return superf(ufunc)
|
||||
|
||||
def __call__(self, y, x, w):
|
||||
if w[0]:
|
||||
@ -262,7 +262,7 @@ class _Unary2Functor:
|
||||
UF: type
|
||||
|
||||
def __new__(ufunc: UF, UF: type) -> _Unary2Functor[UF]:
|
||||
return _Unary2Functor[UF](ufunc)
|
||||
return superf(ufunc)
|
||||
|
||||
def __call__(self, y1, y2, x):
|
||||
e1, e2 = self.ufunc._op(x[0])
|
||||
@ -275,7 +275,7 @@ class _Unary2WhereFunctor:
|
||||
UF: type
|
||||
|
||||
def __new__(ufunc: UF, UF: type) -> _Unary2WhereFunctor[UF]:
|
||||
return _Unary2WhereFunctor[UF](ufunc, )
|
||||
return superf(ufunc)
|
||||
|
||||
def __call__(self, y1, y2, x, w):
|
||||
if w[0]:
|
||||
@ -293,7 +293,7 @@ class _BinaryFunctor:
|
||||
|
||||
def __new__(ufunc: UF, CT1: type, CT2: type, dtype: type,
|
||||
UF: type) -> _BinaryFunctor[CT1, CT2, dtype, UF]:
|
||||
return _BinaryFunctor[CT1, CT2, dtype, UF](ufunc)
|
||||
return superf(ufunc)
|
||||
|
||||
def __call__(self, z, x, y):
|
||||
z[0] = self.ufunc._f(util.cast(x[0], CT1),
|
||||
@ -313,7 +313,7 @@ class _BinaryScalar1Functor:
|
||||
|
||||
def __new__(ufunc: UF, x: X, CT1: type, CT2: type, dtype: type, UF: type,
|
||||
X: type) -> _BinaryScalar1Functor[CT1, CT2, dtype, UF, X]:
|
||||
return _BinaryScalar1Functor[CT1, CT2, dtype, UF, X](ufunc, x)
|
||||
return superf(ufunc, x)
|
||||
|
||||
def __call__(self, z, y):
|
||||
z[0] = self.ufunc._f(util.cast(self.x, CT1),
|
||||
@ -333,7 +333,7 @@ class _BinaryScalar2Functor:
|
||||
|
||||
def __new__(ufunc: UF, y: Y, CT1: type, CT2: type, dtype: type, UF: type,
|
||||
Y: type) -> _BinaryScalar2Functor[CT1, CT2, dtype, UF, Y]:
|
||||
return _BinaryScalar2Functor[CT1, CT2, dtype, UF, Y](ufunc, y)
|
||||
return superf(ufunc, y)
|
||||
|
||||
def __call__(self, z, x):
|
||||
z[0] = self.ufunc._f(util.cast(x[0], CT1),
|
||||
@ -351,7 +351,7 @@ class _BinaryWhereFunctor:
|
||||
|
||||
def __new__(ufunc: UF, CT1: type, CT2: type, dtype: type,
|
||||
UF: type) -> _BinaryWhereFunctor[CT1, CT2, dtype, UF]:
|
||||
return _BinaryWhereFunctor[CT1, CT2, dtype, UF](ufunc)
|
||||
return superf(ufunc)
|
||||
|
||||
def __call__(self, z, x, y, w):
|
||||
if w[0]:
|
||||
@ -367,7 +367,7 @@ class UnaryUFunc:
|
||||
F: type
|
||||
|
||||
def __new__(op: F, name: Static[str], F: type) -> UnaryUFunc[name, F]:
|
||||
return UnaryUFunc[name, F](op)
|
||||
return superf(op)
|
||||
|
||||
@property
|
||||
def nin(self):
|
||||
@ -455,7 +455,7 @@ class UnaryUFunc2:
|
||||
F: type
|
||||
|
||||
def __new__(op: F, name: Static[str], F: type) -> UnaryUFunc2[name, F]:
|
||||
return UnaryUFunc2[name, F](op)
|
||||
return superf(op)
|
||||
|
||||
@property
|
||||
def nin(self):
|
||||
@ -543,7 +543,7 @@ class BinaryUFunc:
|
||||
identity: I = None,
|
||||
F: type,
|
||||
I: type) -> BinaryUFunc[name, F, I]:
|
||||
return BinaryUFunc[name, F, I](op, identity)
|
||||
return superf(op, identity)
|
||||
|
||||
@property
|
||||
def nin(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user