Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ python:
# non python dependencies
before_install:
- sudo apt-get -qq update
- sudo apt-get install libpari-dev pari-gp
- wget http://pari.math.u-bordeaux.fr/pub/pari/unix/pari-2.9.2.tar.gz
- tar xf pari-2.9.2.tar.gz
- cd pari-2.9.2/
- ./Configure --prefix=/usr/
- make gp
- sudo make install
- cd ..
# command to install dependencies
install:
- pip install Cython
- pip install cysignals
- pip install git+https://github.com/defeo/cypari2
- pip install cysignals --verbose
- pip install .
# command to run tests
script:
- python -c "import doctest; import cypari2; doctest.testmod(cypari2, optionflags=doctest.ELLIPSIS|doctest.REPORT_NDIFF)"
- cd tests
- python rundoctest.py

90 changes: 46 additions & 44 deletions cypari2/closure.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ AUTHORS:

- Jeroen Demeyer (2015-04-10): initial version, :trac:`18052`.

EXAMPLES::

sage: def the_answer():
....: return 42
sage: f = pari(the_answer)
sage: f()
42

sage: cube = pari(lambda i: i**3)
sage: cube.apply(range(10))
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
Examples:

>>> def the_answer():
... return 42
>>> import cypari2
>>> pari = cypari2.Pari()
>>> f = pari(the_answer)
>>> f()
42

>>> cube = pari(lambda i: i**3)
>>> cube.apply(range(10))
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
"""

#*****************************************************************************
Expand Down Expand Up @@ -133,39 +135,39 @@ cpdef Gen objtoclosure(f):
be interrupted. Therefore, it is advised to use this only for
simple functions which do not take a long time.

EXAMPLES::

sage: from sage.libs.cypari2.closure import objtoclosure
sage: mul = objtoclosure(lambda i,j: i*j)
sage: mul
(v1,v2,v3,v4,v5)->call_python(v1,v2,v3,v4,v5,...)
sage: mul.type()
't_CLOSURE'
sage: mul(6,9)
54
sage: def printme(x):
....: print(x)
sage: objtoclosure(printme)('matid(2)')
[1, 0; 0, 1]

Test various kinds of errors::

sage: mul(4)
Traceback (most recent call last):
...
TypeError: <lambda>() takes exactly 2 arguments (1 given)
sage: mul(None, None)
Traceback (most recent call last):
...
ValueError: Cannot convert None to pari
sage: mul(*range(100))
Traceback (most recent call last):
...
PariError: call_python: too many parameters in user-defined function call
sage: mul([1], [2])
Traceback (most recent call last):
...
PariError: call_python: forbidden multiplication t_VEC (1 elts) * t_VEC (1 elts)
Examples:

>>> from cypari2.closure import objtoclosure
>>> mul = objtoclosure(lambda i,j: i*j)
>>> mul
(v1,v2,v3,v4,v5)->call_python(v1,v2,v3,v4,v5,...)
>>> mul.type()
't_CLOSURE'
>>> mul(6,9)
54
>>> def printme(x):
... print(x)
>>> objtoclosure(printme)('matid(2)')
[1, 0; 0, 1]

Test various kinds of errors:

>>> mul(4)
Traceback (most recent call last):
...
TypeError: <lambda>() takes exactly 2 arguments (1 given)
>>> mul(None, None)
Traceback (most recent call last):
...
ValueError: Cannot convert None to pari
>>> mul(*range(100))
Traceback (most recent call last):
...
PariError: call_python: too many parameters in user-defined function call
>>> mul([1], [2])
Traceback (most recent call last):
...
PariError: call_python: forbidden multiplication t_VEC (1 elts) * t_VEC (1 elts)
"""
sig_on()
# Convert f to a t_INT containing the address of f
Expand Down
Loading