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.

Proposal: add APIs for getting and setting elements via a list of indices (i.e., `take`, `put`, etc)

See original GitHub issue

Proposal

Add APIs for getting and setting elements via a list of indices.

Motivation

Currently, the array API specification does not provide a direct means of extracting and setting a list of elements along an axis. Such operations are relatively common in NumPy usage either via “fancy indexing” or via explicit take and put APIs.

Two main arguments come to mind for supporting at least basic take and put APIs:

  1. Indexing does not currently support providing a list of indices to index into an array. The principal reason for not supporting fancy indexing stems from dynamic shapes and compatibility with accelerator libraries. However, use of fancy indexing is relatively common in NumPy and similar libraries where dynamically extracting rows/cols/values is possible and can be readily implemented.

  2. Currently, the output of a subset of APIs currently included in the standard cannot be readily consumed without manual workarounds if a specification-conforming library implemented only the APIs in the standard. For example,

    • argsort returns an array of indices. In NumPy, the output of this function can be consumed by put_along_axis and take_along_axis.
    • unique can return an array of indices if return_index is True.

Background

The following table summarizes library implementations of such APIs:

op NumPy CuPy Dask MXNet Torch TensorFlow
extracting elements along axis take take take take take/gather gather/numpy.take
setting elements along axis put put scatter scatter_nd/tensor_scatter_nd_update
extracting elements over matching 1d slices take_along_axis take_along_axis gather_nd/numpy.take_alongaxis
setting elements over matching 1d slices put_along_axis

While most libraries implement some form of take, fewer implement other complementary APIs.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:22 (20 by maintainers)

github_iconTop GitHub Comments

4reactions
rgommerscommented, Nov 16, 2022

Support for take has been merged, see gh-416.

1reaction
rgommerscommented, Jul 7, 2022

Thanks for the ping on this issue @arogozhnikov - and nice to see the experimental work on indexing in einops. I’d like to see gh-416 finished and merged in the coming days to indeed add take support with 1-D indices.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RESTful Web Services Tutorial: What is REST API with Example
A browser issues a GET verb to instruct the endpoint it wants to get ... to get a list of all employee using...
Read more >
Working with lists and list items with REST | Microsoft Learn
Property Description Type GroupString Group identifier used for drill‑down feature. string Field Specifies a special field that should be included. string FilterData Data specified by a...
Read more >
Content Management API Docs | Contentstack
Content Management API supports GET/POST/PUT/DELETE verbs or methods. URL paths are written in lower case. Query parameters and JSON fields use lower case, ......
Read more >
Indexing API methods - Algolia
List of indexing methods, to add, delete, update, and retrieve index objects (records)
Read more >
Node.js and Express Tutorial: Building and Securing RESTful ...
How to easily develop and build RESTful APIs with Node.js and Express, ... (API) that uses HTTP verbs like GET , PUT ,...
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