Skip to content

improve ndarray.__getitem__ with rank-typing #557

@jorenham

Description

@jorenham

It's a very complicated method signature, e.g.

  • _[()] returns Self if 1d+, otherwise (if 0d) returns its scalar type
  • _[int] returns Self[DTypeT, ShapeT[1:]] if 1d+, otherwise (if 0d) returns its scalar type
  • _[int, int] returns Self[DTypeT, ShapeT[1:]] if 1d+, otherwise (if 0d) returns its scalar type
  • ...
  • _[None] returns array[DTypeT, (int, *ShapeT)]
  • _[None, None] returns array[DTypeT, (int, int, *ShapeT)]
  • ...
  • _[slice | array-indexer] returns Self for 1d+, otherwise rejects
  • _[slice | array-indexer, slice | array-indexer] returns Self for 2d+, otherwise rejects
  • ...
  • _[...] returns Self for 0d+

almost all possible combinations are also valid 😅

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions