question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The spec of `to_device()` method is missing

See original GitHub issue

Here we mentioned there’s a to_device() method to enable data copy/movement across devices: https://github.com/data-apis/array-api/blob/09410675703ee275e6e5746db3aded0d37bc4b96/spec/design_topics/device_support.md#L48-L49 But we haven’t defined the signature and semantics yet.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
BvB93commented, Sep 16, 2021

That makes sense to me. The “integer to stream” logic must be implemented anyway to support DLPack, so is not much of an extra burden. The actual union then becomes Union[int, _Stream] with _Stream: Any I guess?

Technically a Union is not the correct type here, as (with protocol arguments being contravariant) that would imply concrete implementation must, at minimum, have support for all union members. Instead, with int- and _Stream-support being optional, you’re in a similar situation to builtin protocols such as __abs__, wherein one of the types is a (somewhat constrained) free variable. Expressing the latter can be done with a typevar (e.g. ~T or ~StreamType), though arguably they don’t look quite as nice as unions.

Examples

from __future__ import annotation
from typing import Union, Protocol, Any, TypeVar

_Stream = Any
_T_contra = TypeVar("_T_contra", bound=Union[None, int, _Stream], contravariant=True)

# Concrete implementations must support all union-members
class SupportsToDevice1(Protocol):
    to_device(self, /, device, *, stream: int | None | _Stream = None): ...

# Concrete implementations must support one or more of the typevar bounds
class SupportsToDevice2(Protocol[_T_contra]):
    to_device(self, /, device, *, stream: None | _T_contra = None): ...

1reaction
rgommerscommented, Sep 15, 2021

Actually, let me ask a question about stream here: is using the DLPack-like integer the right choice here? I think libraries will either have no support for streams, or have custom objects. For DLPack there was little choice, because a custom class instance cannot work. However intra-library it could, similar to how Device itself works, or the dtype objects. Seems like that would be more natural.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.MissingMethodException: Method not found?
The DoThis method is on the same class and it should work. I have a generic handler as such: public class MyHandler: IHttpHandler...
Read more >
"Windows cannot access the specified device, path, or file ...
Method 1: Check the permission of the file or folder · Right-click the file or folder, and then select Properties. · Select the...
Read more >
How to Fix the System Cannot Find the File Specified - EaseUS
If files are missing or not showing up, move to the following tutorial to recover data from your storage device using reliable data...
Read more >
[Solved] PCI Data Acquisition and Signal Processing ...
PCI Data Acquisition and Signal Processing Controller Missing on Windows 11/10 · 1) Go to the support website and then locate the appropriate ......
Read more >
device_info_plus | Flutter Package - Pub.dev
The plugin provides a data method that returns platform-specific device information in a generic way, which can be used for crash-reporting purposes. However, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found