-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Norm along side axis #697
Comments
I think we are generally moving towards delegating these kinds of computations to |
Ignoring the "wrong" orientation of the resulting array, doing it via using LinearAlgebra, BenchmarkTools
A = rand(100, 100);
@btime map(norm, eachslice($A, dims=2)); # 5.689 μs (105 allocations: 5.64 KiB)
@btime mapslices(norm, $A, dims=1); # 61.642 μs (838 allocations: 24.02 KiB) (The two compute the same despite the different |
The function norm2(A; dims)
B = sum(x -> x^2, A; dims=dims)
B .= sqrt.(B)
end
@btime norm2($A, dims=1); # 1.786 μs (1 allocation: 896 bytes) Even if calling |
It would be nice if the
LinearAlgebra.norm
function have thedims
keyword, like others linear algebra functions and like numpy norm axis parameter (https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html)Just for example:
The text was updated successfully, but these errors were encountered: