aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-19 03:41:09 +0100
committerNao Pross <np@0hm.ch>2024-03-19 03:41:09 +0100
commitbfdc7a6bd3a91371fd3ce2963df0f3dedba398c9 (patch)
tree84255b71d17cf71539324dcf8da4311c91f551c1
parentImprove error messages at evaluation time (diff)
downloadmdpoly-bfdc7a6bd3a91371fd3ce2963df0f3dedba398c9.tar.gz
mdpoly-bfdc7a6bd3a91371fd3ce2963df0f3dedba398c9.zip
Make stub for determinant
Diffstat (limited to '')
-rw-r--r--mdpoly/operations/determinant.py46
1 files changed, 46 insertions, 0 deletions
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})"