diff options
author | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2024-02-26 10:03:13 +0100 |
---|---|---|
committer | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2024-02-26 10:03:13 +0100 |
commit | 323ed564cc78cdeef181906d3d78acc739c1e942 (patch) | |
tree | 74c752dd42394a0e166eb6f1feb4e60c4bfd33df | |
parent | clean ups (diff) | |
download | polymatrix-323ed564cc78cdeef181906d3d78acc739c1e942.tar.gz polymatrix-323ed564cc78cdeef181906d3d78acc739c1e942.zip |
update readme
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | examples/main.py | 36 |
2 files changed, 45 insertions, 3 deletions
@@ -61,11 +61,17 @@ state, poly_matrix = f3.apply(state) # PolyMatrixImpl(terms={(0, 0): {((0, 1), (1, 1)): 1, ((0, 1),): 2, ((1, 1),): 1}}, shape=(1, 1)) print(poly_matrix) -state, matrix_repr = polymatrix.to_matrix_repr((f3,), x).apply(state) +state, sympy_repr = polymatrix.to_sympy(f3,).apply(state) + +# prints the sympy representation of the polynomial matrix +# [[x1*x2 + 2*x1 + x2]] +print(sympy_repr) + +state, dense_repr = polymatrix.to_dense((f3,), x).apply(state) # prints the numpy matrix representations of the polynomial matrix # array([[2., 1.]]) # array([[0. , 0.5, 0.5, 0. ]]) -print(matrix_repr.data[0][1]) # numpy array -print(matrix_repr.data[0][2].toarray()) # sparse scipy array +print(dense_repr.data[0][1]) # numpy array +print(dense_repr.data[0][2].toarray()) # sparse scipy array ``` diff --git a/examples/main.py b/examples/main.py new file mode 100644 index 0000000..ff81589 --- /dev/null +++ b/examples/main.py @@ -0,0 +1,36 @@ +import sympy +import polymatrix + +state = polymatrix.init_expression_state() + +x1, x2 = sympy.symbols('x1, x2') +x = polymatrix.from_((x1, x2)) + +f1 = polymatrix.from_(x1 + x2) +f2 = polymatrix.from_(x1 + x1*x2) + +f3 = f1 + f2 + +# prints the data structure of the expression +# AdditionExprImpl(left=FromSympyExprImpl(data=((x1 + x2,),)), right=FromSympyExprImpl(data=((x1*x2 + x1,),))) +print(f3) + +state, poly_matrix = f3.apply(state) + +# prints the data structure of the polynomial matrix +# PolyMatrixImpl(terms={(0, 0): {((0, 1), (1, 1)): 1, ((0, 1),): 2, ((1, 1),): 1}}, shape=(1, 1)) +print(poly_matrix) + +state, sympy_repr = polymatrix.to_sympy(f3,).apply(state) + +# prints the sympy representation of the polynomial matrix +# [[x1*x2 + 2*x1 + x2]] +print(sympy_repr) + +state, dense_repr = polymatrix.to_dense((f3,), x).apply(state) + +# prints the numpy matrix representations of the polynomial matrix +# array([[2., 1.]]) +# array([[0. , 0.5, 0.5, 0. ]]) +print(dense_repr.data[0][1]) # numpy array +print(dense_repr.data[0][2].toarray()) # sparse scipy array
\ No newline at end of file |