-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Documentation mynorm
should not divide by n
#29091
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test with: ```julia a = randn(10) abs(norm(a) - mynorm(a)) < 1e10 ``` Tested here: ```julia-repl _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: https://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.6.4 (2018-07-09 19:09 UTC) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ | x86_64-pc-linux-gnu julia> function mynorm(u::Vector) n = length(u) T = eltype(u) s = zero(T) @fastmath @inbounds @simd for i in 1:n s += u[i]^2 end @fastmath @inbounds return sqrt(s) end mynorm (generic function with 1 method) julia> function mynorm_old(u::Vector) n = length(u) T = eltype(u) s = zero(T) @fastmath @inbounds @simd for i in 1:n s += u[i]^2 end @fastmath @inbounds return sqrt(s/n) end mynorm_old (generic function with 1 method) julia> a = randn(10) 10-element Array{Float64,1}: -0.564163 -3.45236 -0.50901 -0.030296 0.114156 0.661961 -1.19972 2.20883 1.74529 0.82515 julia> abs(norm(a)-mynorm(a)) 0.0 julia> abs(norm(a)-mynorm_old(a)) 3.2787896367314344 ```
fredrikekre
added
docs
This change adds or pertains to documentation
backport pending 1.0
labels
Sep 8, 2018
KristofferC
pushed a commit
that referenced
this pull request
Sep 10, 2018
Test with: ```julia a = randn(10) abs(norm(a) - mynorm(a)) < 1e10 ``` Tested here: ```julia-repl _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: https://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.6.4 (2018-07-09 19:09 UTC) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ | x86_64-pc-linux-gnu julia> function mynorm(u::Vector) n = length(u) T = eltype(u) s = zero(T) @fastmath @inbounds @simd for i in 1:n s += u[i]^2 end @fastmath @inbounds return sqrt(s) end mynorm (generic function with 1 method) julia> function mynorm_old(u::Vector) n = length(u) T = eltype(u) s = zero(T) @fastmath @inbounds @simd for i in 1:n s += u[i]^2 end @fastmath @inbounds return sqrt(s/n) end mynorm_old (generic function with 1 method) julia> a = randn(10) 10-element Array{Float64,1}: -0.564163 -3.45236 -0.50901 -0.030296 0.114156 0.661961 -1.19972 2.20883 1.74529 0.82515 julia> abs(norm(a)-mynorm(a)) 0.0 julia> abs(norm(a)-mynorm_old(a)) 3.2787896367314344 ``` (cherry picked from commit a572504)
Merged
KristofferC
pushed a commit
that referenced
this pull request
Feb 11, 2019
Test with: ```julia a = randn(10) abs(norm(a) - mynorm(a)) < 1e10 ``` Tested here: ```julia-repl _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: https://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.6.4 (2018-07-09 19:09 UTC) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ | x86_64-pc-linux-gnu julia> function mynorm(u::Vector) n = length(u) T = eltype(u) s = zero(T) @fastmath @inbounds @simd for i in 1:n s += u[i]^2 end @fastmath @inbounds return sqrt(s) end mynorm (generic function with 1 method) julia> function mynorm_old(u::Vector) n = length(u) T = eltype(u) s = zero(T) @fastmath @inbounds @simd for i in 1:n s += u[i]^2 end @fastmath @inbounds return sqrt(s/n) end mynorm_old (generic function with 1 method) julia> a = randn(10) 10-element Array{Float64,1}: -0.564163 -3.45236 -0.50901 -0.030296 0.114156 0.661961 -1.19972 2.20883 1.74529 0.82515 julia> abs(norm(a)-mynorm(a)) 0.0 julia> abs(norm(a)-mynorm_old(a)) 3.2787896367314344 ``` (cherry picked from commit a572504)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Test with:
Tested here: