-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: add geomspace function #7268
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
Conversation
Please add link to mailing list discussion for future reference. |
Added tests, please review |
-------- | ||
logspace : Similar to geomspace, but with endpoints specified using log | ||
and base. | ||
linspace : Similar to geomspace, but with the samples uniformly distributed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Similar to geomspace
but with arithmetic instead of geometric sequence."
would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok but this was copied from the other functions, should those change too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say let someone else weigh in, preferably a core dev, then make all of them consistent one way or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed only in geomspace
I have a few comments, but overall +1 for this. This is much more intuitive than logspace. |
|
I added support for negative start and stop, but this breaks some complex start and stop, and I'm not sure whether those should be supported anyway. An implementation that doesn't call logspace could support both I guess. |
+1 to two functions. I pretty much agree with the whole explanatory post. |
How about |
Ok I modified it to handle negative and complex arguments. With complex log, it actually works out without any special-casing, but I special-cased negative arguments so the output doesn't have negligible imaginary parts. I could also special-case purely-imaginary arguments so they don't have negligible real parts. Currently: good:
reasonable:
bad:
probably should check if dtype is int and use around() first? |
With regards to your "bad" example, you are not obligated to return an array of the same type as the input, and I would say that you definitely should not. Many |
the bad example explicitly states dtype=int, though. if dtype is not specified, it's either float or complex output, depending on types of start and stop. |
Looks like you will have to do your own rounding then. |
You could also just kill the dtype argument ;). This is unsafe casting, ufuncs will nowadays not allow you to use dtype=int, i.e. for log it will tell you that there is no loop for this type and it will tell you it is not possible for float + float = int, unless you also specify casting=unsafe (though it will use float internally then). |
Killing |
Output dtype argument is very useful for dtype=float32. Making dtype=int
|
I don't understand why I just need to add a line like:
|
Because someone can also ask for |
If someone wants an integer progression of course they can have it -- the question is whether |
(To be clear I'm not dead-set against the |
I modified it so that purely-imaginary sequences are handled better:
I didn't add |
result = out_sign * logspace(log_start, log_stop, num=num, | ||
endpoint=endpoint, base=10.0, dtype=dtype) | ||
|
||
return result.astype(dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed? could probably just return on the above line, since dtype will be handled by logspace and out_sign?
Added a bunch more tests, changed the type promotion according to http://stackoverflow.com/q/2875024/125507 so the PhysicalQuantities test passes. |
☔ The latest upstream changes (presumably #7328) made this pull request unmergeable. Please resolve the merge conflicts. |
I still need to make an example and squash some commits |
Ok I changed the example and squashed some commits, please check it |
43bb2b3
to
cfb4803
Compare
It would be good if the folks involved in this would take it through to completion. EDIT: otherwise I'm going to drop the 1.12.0 milestone. |
Anything else I need to do? I added some more examples that will hopefully pass. |
Might squash the commits. Two commits, implementation and tests, or just one would do. I'm not a big fan of the name but no one else seems bothered by it. |
Like logspace, but specifying start and stop directly, without having to specify the base. Purely imaginary or purely negative real sequences are converted to positive real, computed, and converted back, so there are no negligible real or imaginary parts. Instead of array([ 6.12323400e-17 +1.00000000e+00j, 6.12323400e-16 +1.00000000e+01j, 6.12323400e-15 +1.00000000e+02j, 6.12323400e-14 +1.00000000e+03j]) it outputs array([ 0. +1.j, 0. +10.j, 0. +100.j, 0.+1000.j]) If dtype is complex it does the math in complex so it can leave the real line and follow a spiral. TST: Added tests for geomspace and more tests for logspace, making PhysicalQuantities tests work for all types of functions PEP8: __all__ after imports, line wrapping
@charris Ok I squashed the commits.
Yes I agree now. It would be nice if it output exact integer values when it was mathematically supposed to, though. But that could be added in another PR. I documented it in the Examples for now. |
Need to add an entry in Comment when ready so that github will send out a notification. |
Needs resquash. You can move the update commit and squash it into the initial commit. |
ok I did that but I can't squash the commits right now |
ok resquashed |
Thanks @endolith . |
Also should this be tweaked so that the start and stop points are exactly equal to the function arguments? https://stackoverflow.com/q/44136851/125507 |
Like logspace, but specifying start and stop directly, without having to
specify the base.
Fixes #7255