-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[feature request] torch.hypot #22764
Comments
This could be quite fast for real/imaginary being contiguous in memory (for impl one may or may not use the precision-enhancement as found in existing hypot implementations, maybe not such a big deal) |
Probably the same kernel could be used for complex abs and hypot |
@muthuArivoli It would be interesting to know perf for: X = torch.rand(128, 128, 2)
A = X.norm(dim = -1)
B = torch.hypot(X[..., 0], X[..., 1])
C = X.view_as_complex().abs()
D = torch.add(*(X ** 2).unbind(dim = -1)).sqrt() |
@vadimkantorov Using the script
I got consistent results around
When I increased the size of the tensor to something large,
These tests were done on a core i7-6770HQ. I don't have a CUDA enabled computer with me, so I won't be able to benchmark on GPU. |
@mruberry What is the proper way of measuring CPU perf? I'm having troubles to compute wall-clock time in #42959 If torch.hypot is indeed better than other methods (and definitely better than norm), maybe they all could delegate to hypot? I also wonder if hypot makes use of chunked/consecutive data loading for the case when first and second arguments are actually interleaved in memory as in this example @colesbury |
@muthuArivoli The large number for norm may actually be the same reason. Could you please try |
@ngimel has a reference for how we benchmark, I think |
@vadimkantorov With input
With large input
|
@ngimel shouldn't |
torch.stft
returns real and imaginary components as the last dimension. Two very frequent functions to consume it are:abs
andangle
(in NumPy). Abs is similar to regularnp.hypot
, so meanwhile complex tensor support is not developed,hypot
could doabs
's job.NumPy also has a
hypot
, although it accepts two arrays. We may have two versions: one accepting two arrays, another accepting only one array and a dim. Essentially,hypot
is a version ofnorm
, specialized for two element vectors only.The text was updated successfully, but these errors were encountered: