Skip to content

WIP, MAINT: restore int64 //= unit64 behavior - #12940

Closed
tylerjereddy wants to merge 1 commit into
numpy:masterfrom
tylerjereddy:issue_12927
Closed

tylerjereddy wants to merge 1 commit into
numpy:masterfrom
tylerjereddy:issue_12927

Conversation

@tylerjereddy

Copy link
Copy Markdown
Contributor

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 of ifloordiv Ufunc registration / type resolution adjustments.

* 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
@eric-wieser

eric-wieser commented Feb 6, 2019 •

Copy link
Copy Markdown
Member

I assume that uint64 //= int64 behavior needs fixing too? (edit: No, it's fine. Even weirder)

@tylerjereddy

tylerjereddy commented Feb 6, 2019 •

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@eric-wieser eric-wieser Feb 6, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@tylerjereddy tylerjereddy changed the title MAINT: restore int64 //= unit64 behavior WIP, MAINT: restore int64 //= unit64 behavior Feb 6, 2019
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

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.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

There was no support for this approach, so I'm closing in favor of the alternative PR which is already open & linked above.

@tylerjereddy
tylerjereddy deleted the issue_12927 branch March 15, 2019 22:46
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.

2 participants