Skip to content

Add protocols for array object methods#69

Open
NeilGirdhar wants to merge 8 commits into
data-apis:mainfrom
NeilGirdhar:array-protocols
Open

Add protocols for array object methods#69
NeilGirdhar wants to merge 8 commits into
data-apis:mainfrom
NeilGirdhar:array-protocols

Conversation

@NeilGirdhar

Copy link
Copy Markdown
Contributor

Once you finish #34, could someone take a look this? @jorenham @lucascolley @nstarman

Add protocols for array object methods:

  • DLPack export via HasDLPack
  • Indexing via HasGetItem
  • Indexed assignment via HasSetItem
  • Device transfer via HasToDevice

Also composes these protocols into Array, exports them from the
top-level package, and adds NumPy integration assignments for the new
protocol surfaces.

nstarman and others added 8 commits August 19, 2025 19:22
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
- DLPack export via `HasDLPack`
- Indexing via `HasGetItem`
- Indexed assignment via `HasSetItem`
- Device transfer via `HasToDevice`

Also composes these protocols into `Array`, exports them from the
top-level package, and adds NumPy integration assignments for the new
protocol surfaces.
Comment thread src/array_api_typing/__init__.py Outdated
Comment on lines +17 to +11
from ._array import (
Array,
HasArrayNamespace,
HasDevice,
HasDType,
HasMatrixTranspose,
HasNDim,
HasShape,
HasSize,
HasTranspose,
)
from ._array import Array, HasArrayNamespace, HasDType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you elaborate on the implications of removing these here and composing them into Array instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to expose them for some reason? I thought they were internal details?

And don't you ultimately want Array to imply all of the protocols?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason for exposing HasDType but not HasShape, for example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the state of the line before my change, and I didn't want to change it. But yes, as far as I know, there is no reason to expose it either.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. Could you add a review comment to gh-34 which suggests to stop exposing all of them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a question 😄

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

Successfully merging this pull request may close these issues.

3 participants