Currently norm is definined for arbitrary dimension Arrays, while normalize only works on vectors,
arr = collect(reshape(1:6, (2,3)))
norm(arr) # works
normalize!(arr) # throws
normalize(arr) # throws
I find this odd and it bites me every now and then. For instance I often want to normalize before plotting.
Can we have normalize/normalize! methods that works on AbstractArray (or ducktyped method on Any)?
I suspect that this is a relic of the days prior to #27401 when norm only worked on 1d arrays. Now that norm works on multi-dimensional arrays, I agree that normalize should as well.
Should be an easy change to this code:
Change the type signatures and documentation from AbstractVector to AbstractArray
Change this line from v[1] to first(v). (This is a bug anyway, since v[1] is wrong for non 1-based arrays.)
Change the documentation to refer to "array" rather than "vector" and use a rather than v.
Add a few tests.
Add a NEWS item.
A PR would be welcome and should be easy even for newcomers.
Seems like this was closed in 8f9dd5d.
Most helpful comment
I suspect that this is a relic of the days prior to #27401 when
normonly worked on 1d arrays. Now thatnormworks on multi-dimensional arrays, I agree thatnormalizeshould as well.Should be an easy change to this code:
Change the type signatures and documentation from
AbstractVectortoAbstractArrayChange this line from
v[1]tofirst(v). (This is a bug anyway, sincev[1]is wrong for non 1-based arrays.)Change the documentation to refer to "array" rather than "vector" and use
arather thanv.Add a few tests.
Add a NEWS item.
A PR would be welcome and should be easy even for newcomers.