Skip to content

Interplay between copy and device in asarray()? #254

Closed

Description

@leofang

I feel we might need some clarification, but maybe we can start with a quick discussion.

I could be wrong, but we probably missed this in #96: What happens when we call asarray on an array on device 0 but set copy=False and device=device 1? Do we raise ValueError (as in other copy=False cases where a copy must be done), or do we ignore copy as the user clearly knows in this case a copy among the two devices is inevitable?

Another question: We probably owe it to clarify this in asarray() too, as in other *_like() cases?

If `device` is `None`, the default device must be used, not `x.device`.

Activity

  1. rgommers commented on Sep 6, 2021

    @rgommers
    Member

    Do we raise ValueError (as in other copy=False cases where a copy must be done), or do we ignore copy as the user clearly knows in this case a copy among the two devices is inevitable?

    I'd suggest just raising the exception, because the two keywords provided conflict.

    Another question: We probably owe it to clarify this in asarray() too, as in other *_like() cases?

    Yes indeed. Although we may want to change that default in *_like. But either way asarray should say what its behavior is.

  2. leofang commented on Sep 8, 2021

    @leofang
    ContributorAuthor

    I'd suggest just raising the exception, because the two keywords provided conflict.

    Thanks, Ralf! Sounds good to me. I forgot we had this section that also provides the same answer to my question.

    Although we may want to change that default in *_like.

    Why? I thought the default is fine.

    But either way asarray should say what its behavior is.

    I'll send a PR to address this.

  3. self-assigned this
    on Sep 8, 2021
  4. rgommers commented on Sep 14, 2021

    @rgommers
    Member

    Why? I thought the default is fine.

    If you use _like then it's typically for doing operations within some function, e.g.:

    def func(x):
        y = ones_like(x)
        z = some_other_func(x, y)
        return z

    If by default x and y are not guaranteed to be on the same device, that's a bit of a foot gun. For other creation functions there's no array input, so the default device for the library is reasonable. But if there's an input array, it has a .device attribute, so that seems like a better default.

  5. leofang commented on Sep 15, 2021

    @leofang
    ContributorAuthor

    @rgommers I am glad you are undergoing the same thinking process as I did 😆 Let me direct you to your previous #96 (comment).

  6. added this to the v2021 milestone on Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions