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

allow more generic norms on any array whose element types support norm #11043

Merged
merged 1 commit into from
Apr 28, 2015

Conversation

stevengj
Copy link
Member

As @mauro3 pointed out on the mailing list, we might as well use norm rather than abs when taking the absolute value of individual elements inside some of the generic norm functions, since norm is a more sensible function to define than abs on abstract Banach spaces.

This patch changes the generic Lp norms to use norm(x) instead of abs(x); there should be no performance penalty for numbers, where norm should inline to abs.

@stevengj stevengj added the linear algebra Linear algebra label Apr 28, 2015
@StefanKarpinski
Copy link
Member

Seems reasonable, although it's weird to have minabs = ... norm(...).

@stevengj
Copy link
Member Author

In the context of computing a norm, it would seem weird to write minnorm = ..., too, since which "norm" is being referred to might be confusing. In context, continuing to use minabs as a variable name seemed clear enough to me to be not worth changing.

@StefanKarpinski
Copy link
Member

Yeah, not important – LGTM, but some mathier types should maybe look too.

@mauro3
Copy link
Contributor

mauro3 commented Apr 28, 2015

Thanks Steven, for looking into this so quickly! Would there ever be a case to use another inside-norm apart form p=2? (I have no use-case, just wondering).

@stevengj
Copy link
Member Author

@mauro3, note that the norm function is only the 2-norm for vectors and matrices. (For scalars, all norms are equivalent up to an overall scale factor.) If you have your own type, you can define whatever norm you want.

My feeling is that if you have an x::Vector{Vector{Complex}} or similar and you want some more specialized norm like the L1 norm of the L1 norms, then you have to implement it yourself. It's not practical to pass in a different elementwise norm function into vecnorm (we'd either kill performance for the common case, or require code duplication, and neither is worth it for such an unusual use-case).

@mauro3
Copy link
Contributor

mauro3 commented Apr 28, 2015

Yes, that sounds good.

stevengj added a commit that referenced this pull request Apr 28, 2015
allow more generic norms on any array whose element types support norm
@stevengj stevengj merged commit 7b0871e into JuliaLang:master Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants