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

normalize(a) for multidimensional arrays #34234

Closed
jw3126 opened this issue Jan 2, 2020 · 2 comments
Closed

normalize(a) for multidimensional arrays #34234

jw3126 opened this issue Jan 2, 2020 · 2 comments
Labels
domain:linear algebra Linear algebra good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@jw3126
Copy link
Contributor

jw3126 commented Jan 2, 2020

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)?

@stevengj stevengj added domain:linear algebra Linear algebra good first issue Indicates a good issue for first-time contributors to Julia labels Jan 2, 2020
@stevengj
Copy link
Member

stevengj commented Jan 2, 2020

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:

  1. Change the type signatures and documentation from AbstractVector to AbstractArray

  2. Change this line from v[1] to first(v). (This is a bug anyway, since v[1] is wrong for non 1-based arrays.)

  3. Change the documentation to refer to "array" rather than "vector" and use a rather than v.

  4. Add a few tests.

  5. Add a NEWS item.

A PR would be welcome and should be easy even for newcomers.

@stevengj stevengj changed the title More convenient normalize normalize(a) for multidimensional arrays Jan 2, 2020
@StefanKarpinski StefanKarpinski added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Jan 3, 2020
andreasnoack pushed a commit that referenced this issue Jan 7, 2020
* Add support normalize multi dim arrays

* remove trailing whitespace from test

* var name v => a for inner function

* Update normalize tests

Case for OffsetArray where A[1] would fail but
first(A) would not. Also some more test cases to
compare with the vector case

* add NEWS item

* make docstring example w/ array  more julia-thonic

* reduce redundant test cases

* add test for normalize on Int64 array

* add 0 1 and high dim test cases
@dkarrasch
Copy link
Member

Seems like this was closed in 8f9dd5d.

KristofferC pushed a commit that referenced this issue Apr 11, 2020
* Add support normalize multi dim arrays

* remove trailing whitespace from test

* var name v => a for inner function

* Update normalize tests

Case for OffsetArray where A[1] would fail but
first(A) would not. Also some more test cases to
compare with the vector case

* add NEWS item

* make docstring example w/ array  more julia-thonic

* reduce redundant test cases

* add test for normalize on Int64 array

* add 0 1 and high dim test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:linear algebra Linear algebra good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

4 participants