aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-19 00:54:18 +0100
committerNao Pross <np@0hm.ch>2024-03-19 01:09:50 +0100
commit62caef610da3775773fe257bab4a48e9701f7e7e (patch)
tree6f1271bb83786173313bf3f8aa9964192ce22dd8
parentImplement matrix product (diff)
downloadmdpoly-62caef610da3775773fe257bab4a48e9701f7e7e.tar.gz
mdpoly-62caef610da3775773fe257bab4a48e9701f7e7e.zip
Add helper method WithOps.to_sparse to give sparse representation
-rw-r--r--mdpoly/expressions.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/mdpoly/expressions.py b/mdpoly/expressions.py
index 159769e..8836c52 100644
--- a/mdpoly/expressions.py
+++ b/mdpoly/expressions.py
@@ -6,9 +6,10 @@ from dataclasses import dataclass
from functools import wraps
from typing import Type, TypeVar, Iterable, Callable, Sequence, Any, Self, cast
-from .abc import Expr, Var, Const, Param
+from .abc import Expr, Var, Const, Param, Repr
from .index import Shape, MatrixIndex, PolyIndex, PolyVarIndex, Number
from .errors import MissingParameters, AlgebraicError
+from .representations import SparseRepr
from .operations.add import MatAdd, MatSub
from .operations.mul import MatElemMul
@@ -326,7 +327,18 @@ class WithOps:
# TODO: implement vector derivatives
return PolyPartialDiff(expr, wrt=wrt)
-
@wrap_result
def integrate(self, with_respect_to: WithOps) -> Expr:
raise NotImplementedError
+
+ # -- Make representations ---
+
+ def to_sparse(self, state: State) -> tuple[SparseRepr, State]:
+ """ Make a sparse representation.
+
+ See :py:class:`mdpoly.representations.SparseRepr`
+ """
+ return self.unwrap().to_repr(SparseRepr, state)
+
+ def to_dense(self, state: State) -> tuple[Repr, State]:
+ raise NotImplementedError