Opened 8 years ago

Closed 7 years ago

#18623 closed defect (fixed)

Allow calling variadic PARI closures

Reported by: Peter Bruin Owned by:
Priority: minor Milestone: sage-6.8
Component: interfaces Keywords: pari closure
Cc: Jeroen Demeyer Merged in:
Authors: Peter Bruin Reviewers: Jeroen Demeyer
Report Upstream: N/A Work issues:
Branch: 26f1d87 (Commits, GitHub, GitLab) Commit: 26f1d87a7cd4277ed0cfe26fb0e9e423fc339b41
Dependencies: #18052 Stopgaps:

Status badges

Description (last modified by Peter Bruin)

Calling a PARI closure with variadic arguments is not possible:

sage: f = pari("(v[..])->length(v)")  # returns the number of its arguments
sage: f()
Traceback (most recent call last):
TypeError: PARI closure takes at most -9223372036854775807 arguments (0 given)

This is because variadic PARI closures are not recognised by Sage and have a somewhat different calling convention.

We also remove a check for the arity of a closure, since this is handled by PARI since recent versions.

Change History (7)

comment:1 Changed 7 years ago by Peter Bruin

Branch: u/pbruin/18623-variadic_pari_closure
Commit: b0d0400a69a3e3f3eb540f40ba223d41b281ce5b
Description: modified (diff)
Status: newneeds_review

comment:2 Changed 7 years ago by git

Commit: b0d0400a69a3e3f3eb540f40ba223d41b281ce5b08ac2b8e0a91e85b922b2dadb4a0bbe8d58d8185

Branch pushed to git repo; I updated commit sha1. New commits:

08ac2b8Trac 18623: also allow combining normal and variadic arguments

comment:3 Changed 7 years ago by Jeroen Demeyer

Reviewers: Jeroen Demeyer
Status: needs_reviewpositive_review

comment:4 Changed 7 years ago by Volker Braun

Status: positive_reviewneeds_work
sage -t --long src/sage/libs/pari/closure.pyx
File "src/sage/libs/pari/closure.pyx", line 158, in sage.libs.pari.closure.objtoclosure
Failed example:
    Traceback (most recent call last):
    TypeError: PARI closure takes at most 5 arguments (100 given)
    Traceback (most recent call last):
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python2.7/site-packages/sage/doctest/", line 496, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/buildslave-sage/slave/sage_git/build/local/lib/python2.7/site-packages/sage/doctest/", line 858, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.libs.pari.closure.objtoclosure[9]>", line 1, in <module>
      File "sage/libs/pari/gen.pyx", line 7956, in sage.libs.pari.gen.gen.__call__ (build/cythonized/sage/libs/pari/gen.c:130162)
        return self.eval(*args, **kwds)
      File "sage/libs/pari/gen.pyx", line 7864, in sage.libs.pari.gen.gen.eval (build/cythonized/sage/libs/pari/gen.c:129597)
      File "sage/libs/pari/handle_error.pyx", line 177, in sage.libs.pari.handle_error._pari_err_handle (build/cythonized/sage/libs/pari/handle_error.c:2823)
        raise PariError(errnum, pari_error_string, pari_instance.new_gen_noclear(E))
    PariError: call_python: too many parameters in user-defined function call
1 item had failures:
   1 of  12 in sage.libs.pari.closure.objtoclosure

comment:5 Changed 7 years ago by git

Commit: 08ac2b8e0a91e85b922b2dadb4a0bbe8d58d818526f1d87a7cd4277ed0cfe26fb0e9e423fc339b41

Branch pushed to git repo; I updated commit sha1. New commits:

3fe2918Wrap Python functions in PARI closures
54a322aImprove documentation
9089808Merge tag '6.7.beta4' into t/18052/wrap_python_functions_in_a_pari_entree_and_t_closure
8bd8218Merge remote-tracking branch 'origin/develop' into t/18052/wrap_python_functions_in_a_pari_entree_and_t_closure
c14da15Allow functions returning None
06ddc48Merge branch 'ticket/18052-pari_wrap_python_functions' into ticket/18623-variadic_pari_closure
26f1d87Trac 18623: fix doctest from #18052

comment:6 Changed 7 years ago by Peter Bruin

Dependencies: #18052
Status: needs_workpositive_review

comment:7 Changed 7 years ago by Volker Braun

Branch: u/pbruin/18623-variadic_pari_closure26f1d87a7cd4277ed0cfe26fb0e9e423fc339b41
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.