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.

Implement `at` method for `_IndexUpdateRef`

See original GitHub issue

Currently the following does not work

from jax import numpy as jnp

a = jnp.arange(3)
a = a.at[1:].at[:-1].set(0)

though IMHO the desired instruction is clear. The equivalent numpy expression a[1:][:-1] = 0 works according to one’s intuition and sets the second element to 0.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
shoyercommented, Apr 19, 2022

The ndindex library can do these sort of calculations with as_subindex: https://quansight-labs.github.io/ndindex/api.html#ndindex.ndindex.NDIndex.as_subindex

1reaction
jakevdpcommented, Apr 19, 2022

And even for numpy, this kind of composability doesn’t always work as you might expect. For example:

In [1]: import numpy as np

In [2]: idx = np.array([2, 4, 5])

In [3]: x = np.arange(10)

In [4]: x[idx][:3] = 999

In [5]: print(x)
[0 1 2 3 4 5 6 7 8 9]

The reason is that while x[idx] = 999 calls x.__setitem__, x[idx] without an associated assignment calls __getitem__, which in this case returns a copy rather than a view, and the second index expression modifies that copy instead of the original array. So if we were to add such composition, we’d have to think carefully about when and where to mimic / diverge from numpy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

git-update-ref Documentation - Git
This command may create a new empty transaction when the current one has been committed or aborted already. prepare. Prepare to commit the...
Read more >
Create and update an index - Microsoft Support
Click where you want to add the index. On the References tab, in the Index group, click Insert Index. In the Index dialog...
Read more >
Writing an update conditional on both ref and index value - Help
Hi, I'm trying to write a query which will only update a record if both the ref and the user's email address match...
Read more >
Update index settings API | Elasticsearch Guide [8.5] | Elastic
Update index analysisedit ... You can only define new analyzers on closed indices. To add an analyzer, you must close the index, define...
Read more >
The Complete Guide to useRef() and Refs in React
Updating a reference doesn't trigger a component re-rendering. Now, let's see how to use useRef() in practice. 1.1 Use case: logging button ...
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