From 62caef610da3775773fe257bab4a48e9701f7e7e Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 19 Mar 2024 00:54:18 +0100 Subject: Add helper method WithOps.to_sparse to give sparse representation --- mdpoly/expressions.py | 16 ++++++++++++++-- 1 file 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 -- cgit v1.2.1