Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_api gives unexpected result for Array._new(x) when x is an Array. #3754

Open
ajpotts opened this issue Sep 9, 2024 · 1 comment
Open
Assignees

Comments

@ajpotts
Copy link
Contributor

ajpotts commented Sep 9, 2024

Describe the bug
Array creation in array_api gives unexpected result for Array._new(x) when x is an Array.

To Reproduce

In [13]: x
Out[13]: Arkouda Array ((10,), int64)[0 1 2 3 4 5 6 7 8 9]

In [14]: y = xp.Array._new(x)

In [15]: type(y)
Out[15]: arkouda.array_api.array_object.Array

In [16]: type(y._array)
Out[16]: arkouda.array_api.array_object.Array

@ajpotts ajpotts self-assigned this Sep 9, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 10, 2024
@ajpotts
Copy link
Contributor Author

ajpotts commented Sep 10, 2024

I investigated this a bit. It seems like the best solution might be to have an array_like type variable, something like this:

array_like =  Union[numeric_scalars, pdarray, Sequence[pdarray]]

and restrict the Array._array object to the array_like type.

However, this would require a refactor of a number of functions that call the attributes of _array. For example:


def empty_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array:
    """
    Return a new array whose shape and dtype match the input array, without initializing entries.
    """
    from .array_object import Array

    if device not in ["cpu", None]:
        raise ValueError(f"Unsupported device {device!r}")

    t = x.dtype if dtype is None else akdtype(dtype)

    return Array._new(
        pdarray(
            "__empty__",
            t,
            x._array.size,
            x._array.ndim,
            x._array.shape,
            x._array.itemsize,
            x._array.max_bits,
        ),
        empty=True,
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant