Skip to content
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 is not type-stable #6056

Closed
stevengj opened this issue Mar 5, 2014 · 1 comment · Fixed by #6057
Closed

norm is not type-stable #6056

stevengj opened this issue Mar 5, 2014 · 1 comment · Fixed by #6057
Labels
bug Indicates an unexpected problem or unintended behavior linear algebra Linear algebra

Comments

@stevengj
Copy link
Member

stevengj commented Mar 5, 2014

As discussed on the mailing list, I was working on a new vecnorm(x,p) function (generalizing and replacing normfro) which computes a p-norm of any iterable container as if it were a vector. I noticed that it is quite tricky to make it type stable, and that in fact our current norm function is not type-stable

julia> norm(Float32[0,1],0)
1

julia> norm(Float32[0,1],2)
1.0f0

julia> norm(Int32[0,1],2)
1.0

julia> norm(Int32[0,1],1)
1

julia> norm(Int32[0,1],3)
1.0

julia> norm(Int32[0,1],0)
1

Obviously, the "0-norm" needs to be promoted to a floating-point type. Similarly for the 1-norm of integer arrays.

(What's not as obvious to me is whether the norm of a Float32 array should be Float32. I'd much rather accumulate the sum in double precision, and I don't see the point of returning a single-precision result. However, since sum of a Float32 array is also single-precision, I suppose doing the same thing for norm makes a certain amount of sense.)

cc: @toivoh

@stevengj stevengj added bug and removed decision labels Mar 5, 2014
@stevengj
Copy link
Member Author

stevengj commented Mar 5, 2014

Hopefully, I will have a vecnorm PR soon that will fix this issue, among other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior linear algebra Linear algebra
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant