Opened 6 years ago

Closed 6 years ago

#21808 closed enhancement (fixed)

Change gen.python() to return Python objects

Reported by: Jeroen Demeyer Owned by:
Priority: major Milestone: sage-7.6
Component: interfaces Keywords: atelierpari2017
Cc: Luca De Feo Merged in:
Authors: Vincent Delecroix Reviewers: Luca De Feo
Report Upstream: N/A Work issues:
Branch: ee54f07 (Commits, GitHub, GitLab) Commit: ee54f071a26c63821f475d2832c7bb1fbbdd7e95
Dependencies: #21807 Stopgaps:

Status badges

Description (last modified by Vincent Delecroix)

Currently, gen.python() is the same as gen.sage() which returns Sage objects. There should be a pure Python version, returning Python objects.

We implement the following conversions inside a gen_to_python function

  • t_INT -> int or long
  • t_REAL -> float
  • t_COMPLEX -> complex
  • t_FRAC -> fraction
  • t_INFINITY -> float
  • t_STR -> str
  • t_VEC, t_COL -> list
  • t_MAT -> list of lists

For all other types, the function raises a NotImplementedError.

Change History (32)

comment:1 Changed 6 years ago by Jeroen Demeyer

Dependencies: #21820

comment:2 Changed 6 years ago by Vincent Delecroix

I would like to implement a gentopython function from the current gentoobj however very few types would be supported. Unless we allow third party Python modules such as gmpy, mpmath python-flint, etc

I guess the best solution would be to support only t_INT, t_VEC, t_COL, t_VECSMALL and further extend the capabilities once this is moved as a Python module. What do you think?

comment:3 Changed 6 years ago by Jeroen Demeyer

Why not:

  • t_REAL -> float
  • t_COMPLEX -> complex
  • t_STR -> str
  • t_MAT -> list of lists
  • t_INFINITY -> float

comment:4 Changed 6 years ago by Vincent Delecroix

Dependencies: #21820#21807
Keywords: atelierpari2017 added

comment:5 Changed 6 years ago by Vincent Delecroix

Description: modified (diff)
Milestone: sage-7.5sage-7.6

comment:6 Changed 6 years ago by Luca De Feo

why not t_VEC -> list?

comment:7 in reply to:  6 Changed 6 years ago by Vincent Delecroix

Description: modified (diff)

Replying to defeo:

why not t_VEC -> list?

Indeed. And t_COL.

comment:8 Changed 6 years ago by Vincent Delecroix

Description: modified (diff)

comment:9 Changed 6 years ago by Vincent Delecroix

Authors: Vincent Delecroix
Branch: u/vdelecroix/21808
Commit: 7fbc989969c4498f0184ef3f6144b51f53394d23
Status: newneeds_review

New commits:

8b67f8021807: gentoobj -> gentosage
791c1c221807: t_RAT does not exist (documentation issue)
706b3be21807: remove gen_py.py
29f83ed21807: gentosage -> gen_to_sage
a3624b121807: copyright notice
7fbc98921808: gen_to_python

comment:10 Changed 6 years ago by git

Commit: 7fbc989969c4498f0184ef3f6144b51f53394d23d7ab7f60970a26c7b5881b60d447587a7fbc1433

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

c0ac11b21807: gentosage -> gen_to_sage
d173a7b21807: copyright notice
d7ab7f621808: gen_to_python

comment:11 Changed 6 years ago by Vincent Delecroix

rebased on the correct #21807

comment:12 Changed 6 years ago by git

Commit: d7ab7f60970a26c7b5881b60d447587a7fbc14336bd066764d0cfaab5803a14503ea416778553f21

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

c0ac79221807: gentoobj -> gentosage
6bd066721808: gen_to_python

comment:13 Changed 6 years ago by Vincent Delecroix

rebased on #21807 and all tests pass in libs/pari, libs/cypari2 and structure/.

comment:14 Changed 6 years ago by Vincent Delecroix

Description: modified (diff)

comment:15 Changed 6 years ago by Jeroen Demeyer

(Edit: wrong ticket)

Last edited 6 years ago by Jeroen Demeyer (previous) (diff)

comment:16 Changed 6 years ago by git

Commit: 6bd066764d0cfaab5803a14503ea416778553f212c83d77107071a4659656436ab4b4beb0b634191

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

375658c21807: remove gentoobj (that was just a deprecated alias)
2c83d7721808: gen_to_python

comment:17 Changed 6 years ago by Jeroen Demeyer

Regarding TODO: this should be moved out of cypari, I disagree. There is nothing wrong with a sage() method importing sage.

comment:18 Changed 6 years ago by Jeroen Demeyer

And _eval_ can probably just be removed.

comment:19 Changed 6 years ago by git

Commit: 2c83d77107071a4659656436ab4b4beb0b634191442299f21555dfaa3cab134ae5bf7f4d600c89f5

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

442299f21808: remove the TODO comment

comment:20 Changed 6 years ago by git

Commit: 442299f21555dfaa3cab134ae5bf7f4d600c89f5dade42d2a7e4d56fbde0e00286c6d69ae185b812

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

dade42d21808: remove the _eval_ method

comment:21 Changed 6 years ago by git

Commit: dade42d2a7e4d56fbde0e00286c6d69ae185b8125a0311c9cf7679b42c2077b2fe2a054b835a5527

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

5a0311c21808: remove "locals" + documentation

comment:22 Changed 6 years ago by git

Commit: 5a0311c9cf7679b42c2077b2fe2a054b835a55278fb600090c0ec024e1182504776b00e6d1302a0b

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

8fb600021808: remove "locals" + documentation

comment:23 Changed 6 years ago by git

Commit: 8fb600090c0ec024e1182504776b00e6d1302a0b6ddac6c85ee496004181018e8d5dfa4121f7c424

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

6ddac6c21808: change .python() -> .sage() in sage/matrix/

comment:24 Changed 6 years ago by git

Commit: 6ddac6c85ee496004181018e8d5dfa4121f7c42479397fb81d76e99ca31ca3344a1fc05d710b609a

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

01ad2d821808: .python() -> .sage() in sage/modular/
79397fb21808: some more .python() -> .sage() conversions

comment:25 Changed 6 years ago by git

Commit: 79397fb81d76e99ca31ca3344a1fc05d710b609a183588ea9ef578966fa62bd1a47db3a81fdebc29

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

183588e21808: fix some more .python() .sage()

comment:26 Changed 6 years ago by Vincent Delecroix

Description: modified (diff)

comment:27 Changed 6 years ago by Vincent Delecroix

all tests pass on my computer

comment:28 Changed 6 years ago by Luca De Feo

Branch: u/vdelecroix/21808u/defeo/21808

comment:29 Changed 6 years ago by git

Commit: 183588ea9ef578966fa62bd1a47db3a81fdebc29ee54f071a26c63821f475d2832c7bb1fbbdd7e95

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

8fb600021808: remove "locals" + documentation
6ddac6c21808: change .python() -> .sage() in sage/matrix/
01ad2d821808: .python() -> .sage() in sage/modular/
79397fb21808: some more .python() -> .sage() conversions
183588e21808: fix some more .python() .sage()
87b6ac3Merge branch 't/21807/21807' into HEAD
ee54f07Python 3 compatibility in doctests

comment:30 Changed 6 years ago by Vincent Delecroix

And now patchbot is happy ;-)

comment:31 Changed 6 years ago by Luca De Feo

Reviewers: Luca De Feo
Status: needs_reviewpositive_review

I'm happy, Patchbot's happy, everyone's happy!

comment:32 Changed 6 years ago by Volker Braun

Branch: u/defeo/21808ee54f071a26c63821f475d2832c7bb1fbbdd7e95
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.