Skip to content

Floor division operator // returns incorrect result when left operand is Python int and right operand is dpnp_array #2720

Closed

Description

@abagusetty

python-int // dpnp.array fails where as dpnp.array // python-int works fine!

Reproducer:

import dpnp
import numpy as np

arr_dpnp = dpnp.array([1])
arr_numpy = np.array([1])

result_dpnp = 256 // arr_dpnp[0]
result_numpy = 256 // arr_numpy[0]

print(f"dpnp result:  {int(result_dpnp)}")
print(f"numpy result: {int(result_numpy)}")
print(f"expected:     256")
print(f"Status:       {'✓ PASS' if int(result_dpnp) == 256 else '✗ FAIL'}")

print("\n" + "="*80)
print("Testing reversed operands: array[0] // 2")
print("="*80)

arr_dpnp = dpnp.array([100])
arr_numpy = np.array([100])

result_dpnp_rev = arr_dpnp[0] // 2
result_numpy_rev = arr_numpy[0] // 2

print(f"dpnp result:  {int(result_dpnp_rev)}")
print(f"numpy result: {int(result_numpy_rev)}")
print(f"expected:     50")
print(f"Status:       {'✓ PASS' if int(result_dpnp_rev) == 50 else '✗ FAIL'}")

output:

 $ python3 test_dpnp_operators.py 
dpnp result:  0
numpy result: 256
expected:     256
Status:       ✗ FAIL

================================================================================
Testing reversed operands: array[0] // 2
================================================================================
dpnp result:  50
numpy result: 50
expected:     50
Status:       ✓ PASS

Activity

  1. self-assigned this
    on Jan 13, 2026
  2. antonwolfy commented on Jan 13, 2026

    @antonwolfy
    Contributor

    @abagusetty, thank you for the submitting the issue.
    I notice the same issue recently and contributed the fix as a part of #2674. On the latest commit the tests are passed:

    dpnp result:  256
    numpy result: 256
    expected:     256
    Status:       ✓ PASS
    
    ================================================================================
    Testing reversed operands: array[0] // 2
    ================================================================================
    dpnp result:  50
    numpy result: 50
    expected:     50
    Status:       ✓ PASS
  3. abagusetty commented on Jan 13, 2026

    @abagusetty
    ContributorAuthor

    @antonwolfy Thanks for the info. Updating the repo fixed it. Sorry about the false alarm. Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions