Repository navigation
WIP, MAINT: restore int64 //= unit64 behavior - #12940
tylerjereddy wants to merge 1 commit into
Conversation
* add unit test to ensure TypeError is raised for int64 //= unit64; this TypeError only applies for the augmented assignment scenario, regular floordiv is still allowed for these types * adjust inner loop casting rules to restore this behavior, which was lost when mm->q floordiv was added
|
I assume that |
|
Quite possibly. Looks like only Mac / 64-bit Linux and ARMv8 linux CI are passing & I was developing on Mac so probably some fragility I hadn't considered. |
| } | ||
| if (strcmp(self->name, "floor_divide") == 0 && | ||
| PyArray_DESCR(op[0])->type_num == 7 && | ||
| PyArray_DESCR(op[1])->type_num == 8) { |
There was a problem hiding this comment.
Testing on my Windows machine the type_num struct members are 9 and 10, respectively, instead of the values on POSIX used here.
Should I try to avoid i.e., a compiler directive checking for the system platform on these conditionals?
I suppose it may also be the case that we want to enforce the behavior for the spectrum of sized int / unit types such that it would capture both architectures once it is a complete check anyway.
There was a problem hiding this comment.
I'm think this approach is a dead end, and we should try to root cause how we ended up here in the first place. Checking type code is not a good way to go.
There was a problem hiding this comment.
I did a pretty detailed audit of the control flow. The shortest summary I can give is that ufunc->ntypes jumps to 21 in the new behavior vs. 20 in the original case. That was the first point of divergence I found. This seems to empower identification / registration of a floordiv inner loop we don't want to allow in specific cases like int64 //= uint64, but do want to allow for int64 // uint64.
Our docs describe ntypes as:
... how many different 1-d loops (of the builtin data types) are available.
As far as I can tell the machinery is already checking type codes or characters in ufunc_loop_matches. This function checks both operand types and the output type according to the "cancast" machinery. We've registered a new int64 output type (mm->q) for floordiv, but we want to prohibit it in some cases.
There was a problem hiding this comment.
but we want to prohibit it in some cases.
I'm not sure if this is true - see my comment on the issue itself. Allowing int64 //= uint64 is a logical consequence of our casting rules, and is primarily caused by allowing uint64 -> timedelta64 casting (unsigned to signed) but not uint64 -> int64 casting
There was a problem hiding this comment.
I'm happy to make whatever change is desired. We definitely need tests to guard these casting rules though, otherwise they can and will break as we've seen here.
|
I'll label this as WIP until the discussion in the linked issue has reached consensus. It looks like Eric would prefer to block certain types of casting rather than intervene on specific inner loop type signatures. |
|
There was no support for this approach, so I'm closing in favor of the alternative PR which is already open & linked above. |
Fixes #12927.
I'll leave a deceptively short explanation for now -- this patches to restore the in-place floor division behavior change described in the above issue. Regular floor division for those operand types is allowed and already enforced by our unit tests.
I don't know how much thought has been put it in to the possible effects of augmented assignment operations like
//=enforcing unexpected constraints on the output data type or if these warrant some kind ofifloordivUfunc registration / type resolution adjustments.