Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
added python usage examples of add, numerator, and matrix_multiply
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvius@gmail.com authored and jayvius@gmail.com committed Jun 27, 2012
1 parent b6f1a9a commit 66b20fe
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doc/extendingufunc.rst
Expand Up @@ -125,4 +125,26 @@ object representing the sum of those two rational numbers::

REGISTER_UFUNC_BINARY_RATIONAL(add)

|
An example of using the add ufunc with the Rational dtype::

In [1]: import numpy as np

In [2]: from rational import rational

In [3]: r1=rational(1,2)

In [4]: r2=rational(3,4)

In [5]: r3=rational(5,6)

In [6]: r4=rational(7,8)

In [7]: a=np.array([r1,r2], dtype=rational)

In [8]: b=np.array([r3,r4], dtype=rational)

In [9]: np.add(a,b)
Out[9]: array([4/3, 13/8], dtype=rational)

34 changes: 34 additions & 0 deletions doc/newgufunc.rst
Expand Up @@ -102,4 +102,38 @@ vectors or matrices and performs a matrix multiply on each pair of matrix elemen

PyModule_AddObject(m,"matrix_multiply",(PyObject*)gufunc);

|
An example of using the add ufunc with the Rational dtype::

In [1]: import numpy as np

In [2]: from rational import rational, matrix_multiply

In [3]: r1=rational(1,2)

In [4]: r2=rational(3,4)

In [5]: r3=rational(5,6)

In [6]: r4=rational(7,8)

In [7]: a=np.array([[[[r1,r2],[r3,r4]],[[r1,r2],[r3,r4]]], [[[r1,r2],[r3,r4]],[[r1,r2],[r3,r4]]]], dtype=rational)

In [8]: b=np.array([[[[r3,r4],[r1,r2]],[[r3,r4],[r1,r2]]], [[[r3,r4],[r1,r2]],[[r3,r4],[r1,r2]]]], dtype=rational)

In [9]: matrix_multiply(a,b)
Out[9]:
array([[[[19/24, 1],
[163/144, 133/96]],

[[19/24, 1],
[163/144, 133/96]]],


[[[19/24, 1],
[163/144, 133/96]],

[[19/24, 1],
[163/144, 133/96]]]], dtype=rational)

20 changes: 20 additions & 0 deletions doc/newufunc.rst
Expand Up @@ -96,4 +96,24 @@ values based rational numbers from the input array.

NEW_UNARY_UFUNC(numerator,NPY_INT64,"rational number numerator");

|
An example of using the numerator ufunc with the Rational dtype::

In [1]: import numpy as np

In [2]: from rational import rational, numerator

In [3]: r1=rational(1,2)

In [4]: r2=rational(3,4)

In [5]: r3=rational(5,6)

In [6]: r4=rational(7,8)

In [7]: a=np.array([r1,r2,r3,r4], dtype=rational)

In [8]: numerator(a)
Out[8]: array([1, 3, 5, 7])

0 comments on commit 66b20fe

Please sign in to comment.