-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Functions for normalizing vectors #226
Comments
I agree that it is a useful function, but it is also very easy to define in a program, so I think I prefer not to include it. I'm aware that we might be deviating from this principle for other functions in |
+1 for adding this to base. The actual implementation should however not look like |
I was imagining the actual implementation would be Out of curiosity, how is an extra temporary involved in @andreasnoack - understood, though I'd argue that normalizing a vector is pretty fundamental to all sorts of numerical linear algebra. In addition, a maximally efficient version of the generalized version |
Ah sorry you are right. In this case its just the one necessary copy being made. |
For the 3D case I don't think anybody would use julia arrays for a single vec3 (or projective vec4). It might come up however to have to project on the sphere a whole bunch of them represented as a big array (say if you want to avoid renormalizing normals on the GPU, even though it's pretty cheap these days) but in general the small vectors in the array will have stride + offset. |
|
Why would this lead to long discussions? Either throw an exception (like we do for sqrt(-1)) or in the lazy implementation simple do nothing. I think we have more exotic functions in base than |
@carnaval - I commonly use julia arrays for a single vec3 - they are a reasonable tool when you want the shortest/simplest code possible and efficiency isn't a concern. |
Agree with @timholy: there's no reason this needs to be in Base. |
One reason is convenience: you can use that function without having to define it somewhere first. The other is consistency: if each project ends up implementing a slightly different version, you'll never know how it exactly behaves, e.g. when the norm is zero. After all, we already have |
Tim - that's great, I didn't know about |
@nalimilan So maybe a bunch of these "convenience" functions belong in a registered package, that would solve both your convenience and consistency issues, IMO, and not keep adding more and more to base. |
I am a big fan of having a shrinked base. But this does not mean that new functions are disallowed. Linear algebra lives in base and one should try to group function together that belong to a functionality. (The function |
I have also used and defined it in some projects, +1 for having it in base. |
I'd also like to have it in base for the reasons already mentioned. |
+1 I use it all the time |
Although it may not seem like a big deal to everyone, for people working in certain areas like graphics or machine learning not having a normalize function in base is quite frankly ridiculous given all the linear algebra functionality already available. In these problem areas normalize's usage is as prevalent as the veritable List class is in other programming tasks. And for those languages that don't have List functionality, you'll always find a buggy or unoptimized homespun class hanging around the code base causing problems. As to the general size of base, Common Lisp showed that any sufficiently developed language will in the end absorb a large number of functions into the basic language, its unavoidable and in my opinion preferable to having a large number of ill conceived or maintained libraries that must nearly always be included or resolving independent homespun implementations whenever a dev team grows past size 1. Ultimately its the quality of functions in base, rather than its size, that Julia should be judged on. And well-written, standardized normalize functions should be a part of the linear algebra base. Joseph |
@josephnunn: I would suggest avoiding words like "ridiculous" when making arguments. It's seldom an effective rhetorical trope. |
Unless there is an obvious package to put it in (and I don't think there is given that it is applicable to several domains), putting in in base seems fine. |
@josephnunn I think a pretty good middle ground to address your concerns would be to place common functions like normalize into a stdlib or base math or stats pkg. This would address your concerns of having multiple "buggy or unoptimized" implementations kicking around while not adding further bloat to base. From what I understand this would also fit with the community's desire to break base out into a stdlib(s). |
Simple helper functions for normalizing vectors Closes #12047
Simple helper functions for normalizing vectors Closes #12047
Simple helper functions for normalizing vectors Closes #12047
@johnmyleswhite Perhaps you are right on my choice of words, but as I mentioned for those used to working in certain problem areas incredulity will be the reaction, as it was for myself. |
Simple helper functions for normalizing vectors Closes #12047
Great, thanks Jiahao. I started implementing this, but got hung up on the details. As your pull request shows, there are several, surprisingly. |
Simple helper functions for normalizing vectors Closes #12047
I find myself commonly writing the trivial utility function
normalize(x) = x/norm(x)
for geometric computing. Julia has the useful utilitycross()
in linalg - maybenormalize()
andnormalize!()
belong there too? I see that ImmutableArrays.jl has definedunit()
for this though that name clashes with a different use in SIUnits.For greater than 1D arrays,
normalize(x, dim)
acting along a dimension would be a useful generalization for me personally. A p-norm version might also be useful.@SimonDanisch - this is very relevant to 3D graphics - maybe you have some thoughts?
The text was updated successfully, but these errors were encountered: