diff options
author | Nao Pross <np@0hm.ch> | 2024-03-19 00:54:18 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-19 01:09:50 +0100 |
commit | 62caef610da3775773fe257bab4a48e9701f7e7e (patch) | |
tree | 6f1271bb83786173313bf3f8aa9964192ce22dd8 | |
parent | Implement matrix product (diff) | |
download | mdpoly-62caef610da3775773fe257bab4a48e9701f7e7e.tar.gz mdpoly-62caef610da3775773fe257bab4a48e9701f7e7e.zip |
Add helper method WithOps.to_sparse to give sparse representation
Diffstat (limited to '')
-rw-r--r-- | mdpoly/expressions.py | 16 |
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 |