Skip to content

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

@abagusetty

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

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