diff options
-rw-r--r-- | polymatrix/polymatrix/impl.py | 2 | ||||
-rw-r--r-- | polymatrix/polymatrix/init.py | 2 | ||||
-rw-r--r-- | polymatrix/polymatrix/mixins.py | 20 |
3 files changed, 11 insertions, 13 deletions
diff --git a/polymatrix/polymatrix/impl.py b/polymatrix/polymatrix/impl.py index 85f56bf..2ac4dc0 100644 --- a/polymatrix/polymatrix/impl.py +++ b/polymatrix/polymatrix/impl.py @@ -19,7 +19,7 @@ class BroadcastPolyMatrixImpl(BroadcastPolyMatrixMixin): @dataclassabc.dataclassabc(frozen=True) class PolyMatrixAsAffineExpressionImpl(PolyMatrixAsAffineExpressionMixin): - data: PolyMatrixAsAffineExpressionMixin.MatrixType + affine_coefficients: PolyMatrixAsAffineExpressionMixin.MatrixType shape: tuple[int, int] slices: dict[MonomialIndex, PolyMatrixAsAffineExpressionMixin.MatrixType] degree: int diff --git a/polymatrix/polymatrix/init.py b/polymatrix/polymatrix/init.py index 6fcdcb1..332977e 100644 --- a/polymatrix/polymatrix/init.py +++ b/polymatrix/polymatrix/init.py @@ -79,4 +79,4 @@ def to_affine_expression(p: PolyMatrixMixin) -> PolyMatrixAsAffineExpressionMixi max_degree = max(m.degree for m in slices.keys()) return PolyMatrixAsAffineExpressionImpl( - data=data, shape=p.shape, slices=slices, degree=max_degree) + affine_coefficients=data, shape=p.shape, slices=slices, degree=max_degree) diff --git a/polymatrix/polymatrix/mixins.py b/polymatrix/polymatrix/mixins.py index ce6d09b..c7a1b00 100644 --- a/polymatrix/polymatrix/mixins.py +++ b/polymatrix/polymatrix/mixins.py @@ -177,6 +177,11 @@ class PolyMatrixAsAffineExpressionMixin( where each matrix :math:`A_\alpha \in \mathbf{R}^{n\times m}`. In the context of this class we will call the :math:`A_\alpha` matrices `affine coefficients`. + + **Note:** In the example above, all monomials powers upt to degree 2 are + present, however in general some monomials may be missing. In that case + this class does not store those as they are all zeros. See also the code of + :py:meth:`affine_coefficient`. """ # Type of matrix that stores affifne coefficients @@ -186,7 +191,7 @@ class PolyMatrixAsAffineExpressionMixin( @property @abc.abstractmethod - def data(self) -> MatrixType: + def affine_coefficients(self) -> MatrixType: r""" The big matrix that store all :math:`A_\alpha` matrices: @@ -197,9 +202,8 @@ class PolyMatrixAsAffineExpressionMixin( \in \mathbf{R}^{n \times mN}, \quad - N = \sum_{k = 0}^d {q + k \choose k} + N \leq \sum_{k = 0}^d {q + k \choose k} """ - ... @property @abc.abstractmethod @@ -344,12 +348,6 @@ class PolyMatrixAsAffineExpressionMixin( # Sort the values by monomial index, which have a total order return dict(sorted(monomial_values.items())) - def affine_coefficients(self) -> MatrixType: - r""" - Get the large matrix - :math:`A = \begin{bmatrix} A_{\alpha_1} & A_{\alpha_2} & \cdots & A_{\alpha_N} \end{bmatrix}` - """ - return self.data def affine_coefficient(self, monomial: MonomialIndex) -> MatrixType: r""" Get the affine coefficient :math:`A_\alpha` associated to :math:`x^\alpha`. """ @@ -358,7 +356,7 @@ class PolyMatrixAsAffineExpressionMixin( return np.zeros((nrows, 1)) columns = range(*self.slices[monomial]) - return self.data[:, columns] + return self.affine_coefficients[:, columns] def affine_coefficients_by_degrees(self) -> Iterable[tuple[int, MatrixType]]: """ @@ -418,7 +416,7 @@ class PolyMatrixAsAffineExpressionMixin( # Evaluate the affine expression _, ncols = self.shape - return self.data @ (np.kron(mvalues, np.eye(ncols)).T) + return self.affine_coefficients @ (np.kron(mvalues, np.eye(ncols)).T) def affine_eval_fn(self) -> Callable[[MatrixType], MatrixType]: r""" |