es-ude / elastic-ai.creator

elastic ai.creator
MIT License
16 stars 2 forks source link

Implement generic Tensor and Arithmetics protocol #209

Closed julianhoever closed 1 year ago

julianhoever commented 1 year ago

Implement a Tensor protocol and a generic Arithmetics protocol to allow to control what functions are available on a Tensor. To get an idea how it should looks like:

class Tensor:
    pass

T_Tensor = TypeVar("T_Tensor", bound=Tensor)

class Arithmetics(Protocol[T_Tensor]):
    def add(a: T_Tensor, b: T_Tensor) -> T_Tensor:
        ...

class TorchTensorWrapper(Tensor):
    def __init__(self, wrapped: torch.Tensor) -> None:
        ...

class FixedPointTensor(Tensor):
    def __init__(self, wrapped: torch.Tensor) -> None:
        self._wrapped = wrapped
        self.frac_bits = 8
        ...

class FixedPointArithmetics(Arithmetics[FixedPointTensor]):
    ...
julianhoever commented 1 year ago

We decided to drop the idea of an own custom tensor for now. I will close this issue.