Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py3: Adapt Sage's range-like functions #30121

Open
slel opened this issue Jul 12, 2020 · 34 comments
Open

py3: Adapt Sage's range-like functions #30121

slel opened this issue Jul 12, 2020 · 34 comments

Comments

@slel
Copy link
Member

slel commented Jul 12, 2020

Python 2 had range (returning lists) and xrange (returning iterators).

Python 3 only has range which behaves like the old xrange.

This ticket is to rename or change our range-like functions accordingly.

To go further we could make sure they all follow similar semantics, i.e.:

  • f(a) for the range from 0 included to a excluded
  • f(a, b) for the range from a included to b excluded
  • f(a, b, c) for the range from a included to b excluded, by steps of c

Functions in the global name space:

  • ellipsis_range
  • fibonacci_xrange
  • mrange
  • mrange_iter
  • prime_range
  • randrange
  • range
  • srange
  • sxrange
  • xmrange
  • xmrange_iter
  • xsrange

See also:

CC: @slel @tscrim @fchapoton

Component: python3

Keywords: range

Branch/Commit: public/srange_as_iterator @ 3cee22e

Issue created by migration from https://trac.sagemath.org/ticket/30121

@slel slel added this to the sage-9.2 milestone Jul 12, 2020
@slel
Copy link
Member Author

slel commented Jul 12, 2020

comment:1

Initial list from a look at:

sage: [x for x in dir() if 'range' in x]

@slel

This comment has been minimized.

@slel

This comment has been minimized.

@slel

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-9.2, sage-9.3 Aug 29, 2020
@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 13, 2021

comment:6

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Feb 13, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@fchapoton
Copy link
Contributor

Branch: public/srange_as_iterator

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

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

efc3d67make srange an iterator

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

Commit: efc3d67

@fchapoton
Copy link
Contributor

comment:10

Making srange an iterator almost break every single file. Any volunteer to handle the fixes ?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

Changed commit from efc3d67 to 3653098

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

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

3653098one fix in plot

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

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

02df950one more fix

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 18, 2021

Changed commit from 3653098 to 02df950

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 19, 2021

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

9eb53f6more fixes for srange

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 19, 2021

Changed commit from 02df950 to 9eb53f6

@fchapoton
Copy link
Contributor

comment:14

We meet the following issue:

sage: A = srange(1,4)                                                            
sage: list(A)                                                                   
[1, 2, 3]
sage: list(A)                                                                   
[]
sage: B = range(1,4)                                                              
sage: list(B)                                                                   
[1, 2, 3]
sage: list(B)                                                                   
[1, 2, 3]

@slel
Copy link
Member Author

slel commented Aug 19, 2021

comment:15

According to the Python 3 documentation for range:

Rather than being a
function, range
is actually an immutable sequence type, as documented
in Ranges
and Sequence Types — list, tuple, range.

Could we make srange an immutable sequence type too?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 19, 2021

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

9e33b25make srange an iterator

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 19, 2021

Changed commit from 9eb53f6 to 9e33b25

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 21, 2021

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

b8740a6using Iterable from collections.abc

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 21, 2021

Changed commit from 9e33b25 to b8740a6

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 21, 2021

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

6025e4done more fix for srange

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 21, 2021

Changed commit from b8740a6 to 6025e4d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 21, 2021

Changed commit from 6025e4d to acd32da

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 21, 2021

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

acd32daone more fix

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 22, 2021

comment:20

I agree with comment:14 - this is problematic. srange should really construct an object similar to range objects in python3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 22, 2021

Changed commit from acd32da to 4910cc6

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 22, 2021

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

4910cc6make srange an iterator

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 22, 2021

Changed commit from 4910cc6 to 3cee22e

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 22, 2021

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

3cee22emake srange an iterator

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 14, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 Apr 1, 2022
@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 10, 2022

comment:26

Can we just get rid of all *mrange* and replace its uses by itertools.product?
(I've opened #34337 for this.)

@mkoeppe

This comment has been minimized.

@tscrim
Copy link
Collaborator

tscrim commented Aug 11, 2022

comment:28

Replying to @mkoeppe:

Can we just get rid of all *mrange* and replace its uses by itertools.product?
(I've opened #34337 for this.)

I posted something on #34337 about somet hings to be careful about with doing the replacement.

@kedlaya
Copy link
Contributor

kedlaya commented Feb 7, 2024

I would suggest to add #31544 to the list of related issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants