Skip to content

operations

Model operations Currently only multiplications for probablities

MatMul

Bases: CompositeArgsExpr

matmul composite callable

arguments must have .shape attribute and shape must be compatible with matrix multiplication

Source code in slimfit/operations.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class MatMul(CompositeArgsExpr):

    """
    matmul composite callable

    arguments must have .shape attribute and shape must be compatible with matrix multiplication

    """

    def __init__(self, *args):
        if len(args) != 2:
            raise ValueError("MatMul takes exactly two arguments")
        super().__init__(*args)

    def __call__(self, **kwargs):
        result = self._call(**kwargs)
        return result[0] @ result[1]

    @property
    def shape(self) -> Shape:
        raise NotImplementedError()

    def __repr__(self) -> str:
        args = ", ".join([arg.__repr__() for arg in self.values()])
        return f"MatMul({args})"

Mul

Bases: CompositeArgsExpr

Mul elementwise lazily

Source code in slimfit/operations.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Mul(CompositeArgsExpr):
    # might be subject to renaming
    """Mul elementwise lazily"""

    def __init__(self, *args):
        super().__init__(*args)

    def __call__(self, **kwargs) -> npt.ArrayLike:
        result = self._call(**kwargs)

        return reduce(mul, result.values())

    def __repr__(self) -> str:
        args = ", ".join([arg.__repr__() for arg in self.values()])
        return f"Mul({args})"