From bfdc7a6bd3a91371fd3ce2963df0f3dedba398c9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 19 Mar 2024 03:41:09 +0100 Subject: Make stub for determinant --- mdpoly/operations/determinant.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 mdpoly/operations/determinant.py diff --git a/mdpoly/operations/determinant.py b/mdpoly/operations/determinant.py new file mode 100644 index 0000000..63aaf20 --- /dev/null +++ b/mdpoly/operations/determinant.py @@ -0,0 +1,46 @@ +from __future__ import annotations +from typing import TYPE_CHECKING + +from typing import Type +from dataclassabc import dataclassabc + +from ..abc import ReprT +from ..index import Shape +from ..errors import AlgebraicError + +from . import UnaryOp + +if TYPE_CHECKING: + from ..abc import ReprT + from ..state import State + + +@dataclassabc(eq=False) +class Det(UnaryOp): + """ Compute the determinant of a matrix. """ + + @property + def shape(self) -> Shape: + if not self.inner.shape.cols == self.inner.shape.rows: + raise AlgebraicError("Cannot take determinant of non-square matrix " + f"{str(self)} (shape {self.inner.shape}).") + + return Shape.scalar() + + def to_repr(self, repr_type: Type[ReprT], state: State) -> tuple[ReprT, State]: + """ See :py:meth:`mdpoly.abc.Expr.to_repr`. """ + # Make a new empty representation + r = repr_type(self.shape) + + # Compute LU decomposition by Doolittle's method + lower = repr_type(self.inner.shape) + upper = repr_type(self.upper.shape) + + for i in range(self.inner.shape.rows): + raise NotImplementedError + + return r, state + + + def __str__(self): + return "(det {self.inner})" -- cgit v1.2.1