Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MANT: refactor unravel_index for code repetition #13446

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

Merged
merged 3 commits into from
May 1, 2019

Conversation

mattip
Copy link
Member

@mattip mattip commented May 1, 2019

Replaces #6219 which opened with the comment
"Adding a little bit of extra accounting in the inner loop allows joining the two specialized branches into a single one. The performance loss, if any, is within the measurement error."

Additional comments were integrated into this PR, including a nice little compiler optimization for getting the quotient and remainder with a single divide (thanks godbolt )

@seberg asked for a better error to be raised, which was already implemented.

I made a new PR since I could not push the rebase to @jaimefrio 's repo. Of course we only need one of these, @jaimefrio if you wish to move forward on it feel free to close this one.

npy_intp tmp = val / unravel_dims[idx];
coords[idx] = val % unravel_dims[idx];
val = tmp;
idx += idx_step;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bit @charris pointed out could be optimized nicely by putting the divide first and using a temporary variable

@seberg seberg self-assigned this May 1, 2019
@mattip mattip requested a review from seberg May 1, 2019 10:32
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff looks a big, but the actual changes really seem very small. Just checked and the tests seem OK here, can only find some style nitpicks right now.

Would merge in a bit, unless someone wants to have another glance or wants me to look closer again.

@mattip
Copy link
Member Author

mattip commented May 1, 2019

I used the "accept suggested changes" feature but now the PR has 3 commits, some with strange messages. Probably need to squash-merge

@seberg
Copy link
Member

seberg commented May 1, 2019

Hmmm, so the feature is not perfect ;) (but there is not much it can do I guess, except possibly auto-squash multiple suggestions)... Will have another quick pass after lunch and wait a bit for the tests, but Jaime de-facto reviewed this as well I guess.

@seberg seberg self-requested a review May 1, 2019 18:33
@seberg seberg removed their assignment May 1, 2019
@seberg
Copy link
Member

seberg commented May 1, 2019

Thanks Matti, and of course also Jaime!

@seberg seberg merged commit 1694f0f into numpy:master May 1, 2019
lijunzh added a commit to lijunzh/numpy that referenced this pull request May 2, 2019
* master: (25 commits)
  BUG: fix unravel_index when dimension is greater than 'intp'
  MANT: refactor unravel_index for code repetition (numpy#13446)
  BLD, TST: implicit func errors
  DOC: document existance of linalg backends
  BLD: streamlined library names in site.cfg sections (numpy#13157)
  MAINT: fixed typo 'wtihout' from numpy/core/shape_base.py
  BUG: fixing bugs in AVX exp/log while handling special value floats (numpy#13415)
  update sequence
  Add analysis check
  BUG: blindly add TypeError to accepted exceptions
  MAINT: fixed several PYTHONOPTIMIZE=2 failures
  BUG: fixed PYTHONOPTIMIZE run
  MAINT: fixed typo 'Mismacth' from numpy.core.setup_common.py
  MAINT: fixed last issues and questions according to numpy#13132
  MAINT: improve efficiency of pad by avoiding use of apply_along_axis
  DOC: dimension sizes are non-negative, not positive
  BUILD, BUG: fix from review, fix bug in git_version
  MAINT: mention 'make dist' in error messsage
  BUILD: allow version-check to pass if GITVER is Unknown (sdist build)
  BUILD: fail documentation build if numpy version does not match
  ...
@mattip mattip deleted the unravel_index branch May 20, 2019 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants