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

sage.misc.defaults.variable_names return tuple in all cases #29797

Closed
heluani opened this issue Jun 4, 2020 · 14 comments
Closed

sage.misc.defaults.variable_names return tuple in all cases #29797

heluani opened this issue Jun 4, 2020 · 14 comments

Comments

@heluani
Copy link

heluani commented Jun 4, 2020

sage.misc.defaults.variable_names and latex_variable_names return tuple if the number of variable names requested is bigger than 1 or 0 and a list if it's 1. This ticket fixes that.

Component: misc

Author: Reimundo Heluani

Branch/Commit: 725d4b5

Reviewer: Travis Scrimshaw

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

@heluani heluani added this to the sage-9.2 milestone Jun 4, 2020
@heluani
Copy link
Author

heluani commented Jun 4, 2020

@heluani
Copy link
Author

heluani commented Jun 4, 2020

Commit: 1570469

@heluani

This comment has been minimized.

@heluani
Copy link
Author

heluani commented Jun 4, 2020

Author: Reimundo Heluani

@tscrim
Copy link
Collaborator

tscrim commented Jun 5, 2020

comment:3

For safety:

 def latex_variable_names(n, name=None):
-    """
+    r"""
     Converts a root string into a tuple of variable names by adding 
     numbers in sequence.

Also, minor nitpick with the doc formatting:

-    - ``n`` a non-negative Integer. The number of variable names to 
-       output.
-    - ``names`` a string (Default: ``None``); The root of the variable
-      name. 
+    - ``n`` a non-negative Integer; the number of variable names to 
+       output
+    - ``names`` a string (default: ``None``); the root of the variable
+      name.

Once changed, you can set a positive review on my behalf.

@tscrim
Copy link
Collaborator

tscrim commented Jun 5, 2020

Reviewer: Travis Scrimshaw

@DaveWitteMorris
Copy link
Member

comment:4

Thanks for making the fix, but I think there are space characters at the ends of some lines (and a line with only spaces). Please get rid of those spaces. Also, since you are editing the file, please change tuple([ ... ]) to tuple( ... ) (twice, near the end of both functions), even though this is not your fault.

@tscrim
Copy link
Collaborator

tscrim commented Jun 5, 2020

comment:5

Replying to @DaveWitteMorris:

Also, since you are editing the file, please change tuple([ ... ]) to tuple( ... ) (twice, near the end of both functions), even though this is not your fault.

I am -1 on this change because it is actually slower (surprisingly) to not have the inner list comprehension.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 5, 2020

Changed commit from 1570469 to 725d4b5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 5, 2020

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

725d4b5Changes requested by comments #3 and #4

@heluani
Copy link
Author

heluani commented Jun 5, 2020

comment:7

Replying to @tscrim:

Once changed, you can set a positive review on my behalf.

Was I suppose to make this change to 'positive review'?

@nbruin
Copy link
Contributor

nbruin commented Jun 5, 2020

comment:8

Replying to @tscrim:

I am -1 on this change because it is actually slower (surprisingly) to not have the inner list comprehension.

Indeed! There's no "tuple comprehension" in python; just the possibility to make a tuple from an iterator. You can save the "tuple" by writing

(*[...],)

but as far as I can see this has about the same performance as tuple([...]) has. I guess the tuple constructor misses some of the optimizations of list comprehensions to build a list with beforehand-unknown-length. Passing a list into tuple gives the length beforehand, so it's easier to construct the tuple efficiently.

@DaveWitteMorris
Copy link
Member

comment:9

OK, I stand corrected. I made the suggestion because it was a reviewer comment on one of the patches I wrote, and made sense to me. (I did some quick tests on this case and I am usually not seeing any significant difference in performance, but tuple([...]) does come out faster sometimes, and I can believe that it is a better general practice, even though it is counterintuitive.)

@vbraun
Copy link
Member

vbraun commented Jun 27, 2020

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