[issue33089] Add multi-dimensional Euclidean distance function to the math module

2019-02-16 Thread miss-islington
miss-islington added the comment: New changeset 3ff5962d2e9af2c35d09d39465397c6fa6e9965c by Miss Islington (bot) (Raymond Hettinger) in branch 'master': bpo-33089: Add math.dist() and math.hypot() to Whatsnew (GH-11896)

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2019-02-16 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +11923 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-31 Thread Mark Dickinson
Mark Dickinson added the comment: For the record, let me register my objection here. I'm not convinced by adding math.dist, and am surprised that this was committed. Almost all the discussion in this issue was about adding multi-argument hypot, which seems like an obviously useful building

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-31 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 9c18b1ae527346bc178250ad1ca07bffdacde5dd by Raymond Hettinger in branch 'master': bpo-33089: Add math.dist() for computing the Euclidean distance between two points (GH-8561)

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +8075 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: I really don't want to introduce something slower than O(n) behavior here, particularly because some of my use cases have a large n and because this will be called many times. Tim has already opined the even using a variant of Kahan summation would

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-28 Thread Stefan Behnel
Stefan Behnel added the comment: >> Commutativity guarantees can be delivered by sorting arguments before >> summation. > No thanks -- that's too expensive for such a small payoff. Since I don't really see people use this on vectors with hundreds of dimensions, let me still suggest using

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset c6dabe37e3c4d449562182b044184d1756bea037 by Raymond Hettinger in branch 'master': bpo-33089: Multidimensional math.hypot() (GH-8474) https://github.com/python/cpython/commit/c6dabe37e3c4d449562182b044184d1756bea037 --

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Commutativity guarantees can be delivered by sorting arguments before > summation. No thanks -- that too expensive for such a small payoff. -- ___ Python tracker

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Commutativity guarantees can be delivered by sorting arguments before > summation. No thanks -- that's too expensive for such a small payoff. -- ___ Python tracker

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg322453 ___ Python tracker ___ ___ Python-bugs-list

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Commutativity guarantees can be delivered by sorting arguments before summation. In any case the sorting is needed for more accurate summation (from smaller to larger). -- ___ Python tracker

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't want to make any guarantees beyond what the doc patch says. Commutativity guarantees are difficult to deliver without exact summation. A switchover to C's hypot() creates an external dependency such that we can't make any more guarantees than

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: 6. hypot(x) == abs(x) 7. hypot(x, y) should return the same result as in previous Python version, e.g. should call C lib implementation. 8. hypot(x, y, 0, ...) == hypot(x, y) -- ___ Python tracker

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I think we should guarantee some properties: 1. The result of hypot(x, y, z, ...) shouldn't depend on the order of arguments. 2. It should be monotonic for all arguments: hypot(..., x, ...) <= hypot(..., y, ...) for abs(x) < abs(y). 3. hypot(..., inf,

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-07-25 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +7997 stage: -> patch review ___ Python tracker ___ ___

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-06-24 Thread Tim Peters
Tim Peters added the comment: Raymond, I'd say scaling is vital (to prevent spurious infinities), but complications beyond that are questionable, slowing things down for an improvement in accuracy that may be of no actual benefit. Note that your original "simple homework problems for kids

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-06-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: Would it be reasonable for me to get started with a "mostly good enough" version using scaling and Kahan summation? from operator import sub from math import sqrt, fabs def kahan_summation(seq): #

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Tim Peters
Tim Peters added the comment: Mark, how about writing a clever single-rounding dot product that merely _detects_ when it encounters troublesome cases? If so, it can fall back to a (presumably) much slower method. For example, like this for the latter: def srdp(xs, ys):

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Tim Peters
Tim Peters added the comment: Mark, thanks! I'm happy with that resolution: if any argument is infinite, return +inf; else if any argument is a NaN, return a NaN; else do something useful ;-) Serhiy, yes, the scaling that prevents catastrophic overflow/underflow due to

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Mark Dickinson
Mark Dickinson added the comment: Okay, that cut and paste didn't work so well. Just imagine an infinity symbol in those missing spaces. Trying again: > For the hypot function, hypot(±0, ±0) is +0, hypot(±∞, qNaN) is +∞, and > hypot(qNaN, ±∞) is +∞. --

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Mark Dickinson
Mark Dickinson added the comment: > By the same logic, if there's an infinite argument to hypot(), it doesn't > matter what any other argument is - the result is +inf regardless. Yep, that's what IEEE 754-2008 says for the two-argument case, so I think that's the logic

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Tim Peters
Tim Peters added the comment: Some notes on the hypot() code I pasted in: first, it has to special case infinities too - it works fine if there's only one of 'em, but returns a NaN if there's more than one (it ends up computing inf/inf, and the resulting NaN propagates).

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Mark Dickinson
Mark Dickinson added the comment: +1 for a single-rounded dot product. If we're allowed to assume IEEE 754, it's straightforward to code up something that's not too inefficient and gives correctly rounded results for "normal" cases, using a combination of Veltkamp

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Uncle Timmy] > I doubt `fsum()` would add much value here: all the addends have the > same sign, so cancellation is impossible fsum() may be overkill for this problem. I mentioned it because the math module already had the

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: With this implementation >>> hypot(*range(15), 3) 32.01 The exact result is 32. -- nosy: +serhiy.storchaka ___ Python tracker

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-18 Thread Tim Peters
Tim Peters added the comment: I'd be +1 on generalizing math.hypot to accept an arbitrary number of arguments. It's the natural building block for computing distance, but the reverse is strained. Both are useful. Here's scaling code translated from the Fortran

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-16 Thread Steven D'Aprano
Steven D'Aprano added the comment: Ah wait, I appear to have misunderstood Raymond's request. Sorry Raymond! (I've been spending too much time teaching Pythagoras' theorem and my mind was primed to go directly from Euclidean distance to hypotenuse.) Not

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-16 Thread Steven D'Aprano
Steven D'Aprano added the comment: The obvious work-around of calling hypot multiple times is not only tedious, but it loses precision. For example, the body diagonal through a 1x1x1 cube should be √3 exactly: py> from math import hypot, sqrt py> hypot(hypot(1,

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-16 Thread Steven D'Aprano
Steven D'Aprano added the comment: This was requested once before, but rejected. I would like to see that decision re-considered. https://bugs.python.org/issue1880 Some months ago, there was a very brief discussion started by Lawrence D’Oliveiro about this on the

[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-16 Thread Raymond Hettinger
New submission from Raymond Hettinger : A need for a distance-between-two-points function arises frequently enough to warrant consideration for inclusion in the math module. It shows-up throughout mathematics -- everywhere from simple homework problems for kids