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

BUG: Do not try sequence repeat unless necessary #7439

Merged
merged 1 commit into from
Mar 25, 2016

Conversation

seberg
Copy link
Member

@seberg seberg commented Mar 20, 2016

Only if the other class actually implements sequence repeat, should
it be tried. Otherwise classes which implement neither will cause
the sequence repeat branch. This branch may fail for two reasons:

  1. The scalar was not integer
  2. The other object raises an error during repeat.

Previously, the first did not happen for floats, etc. and the
second was using a try/except logic. Now both will always error.
An object which claims to support sequence repeat should never
have to fall back to normal multiplication.

Note that all of this is controversial in the final behaviour.
We may actually want [1, 2, 3] * np.float64(3.) to return
an array with [3., 6., 9.] at some point.

It was suggested to create a better error message, this
is not covered here. The major point is fixed though, so:
closing gh-7428

Only if the other class actually implements sequence repeat, should
it be tried. Otherwise classes which implement neither will cause
the sequence repeat branch. This branch may fail for two reasons:
 1. The scalar was not integer
 2. The other object raises an error during repeat.

Previously, the first did not happen for floats, etc. and the
second was using a try/except logic. Now both will always error.
An object which claims to support sequence repeat should never
have to fall back to normal multiplication.

Note that all of this is controversial in the final behaviour.
We may actually want `[1, 2, 3] * np.float64(3.)` to return
an array with `[3., 6., 9.]` at some point.

-

It was suggested to create a better error message, this
is not covered here. The major point is fixed though, so:
closing numpygh-7428
npy_intp repeat;

/*
* If the other object supports sequence repeat and not number multiply
* we should call sequence repeat to support e.g. list repeat by numpy
Copy link
Member

Choose a reason for hiding this comment

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

Note that __repeat__ has been deprecated since 2.7.

@charris
Copy link
Member

charris commented Mar 24, 2016

LGTM modulo that it is doing what we want ;) If current behavior is truly a regression, might want to backport, although that makes me shiver a bit. @njsmith Thoughts?

@charris charris added this to the 1.11.0 release milestone Mar 24, 2016
@seberg
Copy link
Member Author

seberg commented Mar 24, 2016

Current in 1.11 it only has spurrious warnings, which is annoying but not a regression.

On Thu Mar 24 20:28:29 2016 GMT+0100, Charles Harris wrote:

LGTM modulo that it is doing what we want ;) If current behavior is truly a regression, might want to backport, although that makes me shiver a bit. @njsmith Thoughts?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#7439 (comment)

@charris charris removed this from the 1.11.0 release milestone Mar 25, 2016
@charris charris merged commit f2dd0a1 into numpy:master Mar 25, 2016
@charris
Copy link
Member

charris commented Mar 25, 2016

OK, merged. Thanks Sebastian. I assume that this mostly clears things up. Do you think it needs a mention in the release notes?

@njsmith
Copy link
Member

njsmith commented Mar 25, 2016

regarding backport: I guess technically there is a minor regression, because 1.10 gave an invisible warning for certain rare harmless actions, and 1.11 now gives a visible warning in the same case. Definitely too subtle of a fix to be sneaking into 1.11.0-final though :-/. I guess we could try releasing 1.11 as-is in the hopes that not many people will hit the spurious warning, and then if it turns out to be a problem...

@arokem: as a representative of the one project we know of that's actually been affected so far... any thoughts?

@seberg seberg deleted the gh-7428 branch March 25, 2016 07:41
@arokem
Copy link

arokem commented Mar 25, 2016

Not too important that I understand this, Just making sure that I understand what I am looking at, the line of code that raised the error for us (in #7428) is equivalent to test-case number 2 here (assert_array_equal(np.float32(3.) * arr_like, np.full(3, 3.)))? Otherwise, no further thoughts for me. Thanks for checking in.

@njsmith
Copy link
Member

njsmith commented Mar 25, 2016

@arokem: the question is whether it will bother you if 1.11.0 continues to issue a nonsensical warning on your original code

@arokem
Copy link

arokem commented Mar 25, 2016

Gotcha. I'm probably fine with that. We have quite a few warnings raised by our code, and we have generally been pretty lazy about fighting against it.

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.

None yet

4 participants