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

fix type stability in all norm variants #6101

Merged
merged 1 commit into from
Mar 11, 2014

Conversation

stevengj
Copy link
Member

Continuing where JuliaLang/LinearAlgebra.jl#91 and #6057 left off, this makes all the norm functions type stable, both internally and externally.

Previously, similar to JuliaLang/LinearAlgebra.jl#91, norm(x, p) was not type stable, in the sense that the norm of an integer matrix or scalar would return different types for different p. It was also not internally type stable, in that the reduction loop would change the type of the accumulator variable if typeof(zero(T)) != typeof(zero(T)+zero(T)), similar to #6069.

Now, all matrix norms return a floating-point result, and accumulations are performed in at least double precision, similar to vecnorm. norm(x::Number, p) returns a value with the same type as real(x) or abs(x), since adding the floating-point conversion there would have complicated the code for no useful purpose.

I also made one or two other code cleanups. The p parameter is consistently declared to be Real, and the dense vector norms override vecnorm1 and vecnorm2 rather than vecnorm to exploit dispatch.

JeffBezanson added a commit that referenced this pull request Mar 11, 2014
fix type stability in all norm variants
@JeffBezanson JeffBezanson merged commit ce21a02 into JuliaLang:master Mar 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants