Does the standard library have a function equivalent to the following?
function norm_normalize(v, p = 2)
n = norm(v,p)
return n, v/n
end
If not, is there a reason why such a function does not exist?
And finally, if the function does not exist but you think that it should exist, what should the name be? The name norm_normalize() is modeled after functions like reim() or sincos(), but I think it’s a bit too wordy. Another option would be normunit(), which follows a similar idea and is shorter but which is also more unclear.
I don’t know if it exists. But what is the purpose of this function? It seems trivial enough that I would write it out inline, or define my own local function.
I have a similar feeling about reim, I don’t really see the point of it. Perhaps it’s very commonly used?
sincos is different, since it does something highly non-trivial.
Convenience. It allows you to merge two to three lines into one and avoid introducing some temporary variables. This may sound trivial, but often these things appear in quite complicated mathematical algorithms where squeezing out every bit of conciseness really helps. Also, note that LinearAlgebra already has a normalize() function which is about as trivial as norm_normalize().
By making v the result of some computations (e.g. a matvec A*x) which you do not want to repeat.
For example, norm_normalize() would allow you to reduce
Seems too trivial to merit it’s own name. It’s just x./norm(x), so I’m used to either writing that, or, if I need to pass it along somewhere, making an anonymous function.
I don’t mind it, it just seems like something that could be trimmed away. I see it has a companion, normalize! which does slightly more.
It’s a question, what is the threshold for something to be non-trivial enough or used enough that it is worthwhile. Anyway, normalize and this proposed new function won’t live in Base, so no big deal.
Since normalize / normalize! turns out to be a bit more involved than expected, perhaps the proposed function is a bit more useful than I first thought.