import unittest from polymatrix.expressionstate.init.initexpressionstate import init_expression_state import polymatrix.expression.initexpressionbase class TestTruncate(unittest.TestCase): def test_1(self): terms = { (0, 0): { ((0, 1),): 1.0, # x1 x1 }, (1, 0): { ((0, 2), (1, 1)): 1.0, # x1 x1 x2 ((0, 3), (1, 1)): 1.0, # x1 x1 x1 x2 }, (0, 1): { ((0, 2), (2, 1),): 1.0, # x1 x1 ((3, 1),): 1.0, }, } variable_terms = { (0, 0): {((0, 1),): 1}, (1, 0): {((1, 1),): 1}, } expr = polymatrix.expression.initexpressionbase.init_truncate_expr( underlying=polymatrix.expression.initexpressionbase.init_from_terms_expr(terms=terms, shape=(2, 2)), variables=polymatrix.expression.initexpressionbase.init_from_terms_expr(terms=variable_terms, shape=(2, 1),), degrees=(1, 2), ) state = init_expression_state(n_param=2) state, val = expr.apply(state) data = val.get_poly(0, 0) self.assertDictEqual({ ((0, 1),): 1.0, }, data) data = val.get_poly(1, 0) self.assertDictEqual( {}, data ) data = val.get_poly(0, 1) self.assertDictEqual({ ((0, 2), (2, 1)): 1.0, # x1 x1 }, data)