Skip to content

dpnp.ndarray ctor returns a view at wrong addr with buffer= has non-zero offset #3067

Description

@abagusetty

Reproducer:

import numpy
import dpnp

for xp, name in [(numpy, "numpy"), (dpnp, "dpnp")]:
    pool = xp.arange(8, dtype=xp.complex64)  # itemsize 8
    tail = pool[4:]  # element offset 4 (complex64 units) = byte offset 32

    view = xp.ndarray((4,), dtype=xp.uint16, buffer=tail)  # itemsize 2

    expect_byte_offset = 32
    got_byte_offset = view.__array_interface__["data"][0] - pool.__array_interface__["data"][0] \
        if xp is numpy else view.data.ptr - pool.data.ptr

    print(f"{name}: byte_offset={got_byte_offset} (expected {expect_byte_offset})")
    assert got_byte_offset == expect_byte_offset, f"{name} FAILED"

print("OK: dpnp matches numpy")

output:

numpy: byte_offset=32 (expected 32)
dpnp: byte_offset=8 (expected 32)
Traceback (most recent call last):
  File "/home/abagusetty/gpu4pyscf-testing/dpnp_sparse/repro_offset_bug.py", line 19, in <module>
    assert got_byte_offset == expect_byte_offset, f"{name} FAILED"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: dpnp FAILED

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions