Index reading and writing: different compacts between basic slices and advanced indexes
The length index also involves selecting which elements are stored in relation to the return.
Learning objectives and first steps2 objectives 2 first fixes
Try to do it after reading
- Track slice sharing and advanced index results
- Distinguishing reading copies from index attributions
Suggested first
- Python Basic Syntax:
- Thick shape with Index
And then you take out some elements and then you change them to who it affects
The length index also involves selecting which elements are stored in relation to the return. Basic slices can normally be returned to the view; Advanced indexes such as integer arrays or boolean conditions usually return copies when read. The same number cannot be assumed to have the same effect on the original data if the result is modified in situ because both expressions have been selected.
Take x = [10, 20, 30, 40]. (a) Basic slices are selected from one to two and the result is [20,30], which can be read continuously along the original storage; Advanced indexing is also available at [20,30] locations, but reading results are usually newly stored. Replace item 0 of the latter with item 99 and should not be expected to synchronize item 1 of the original x to 99.
The index value is another different operation. Direct indexing values for x are being modified for x; Tied the advanced index results to y and then changed to y, which is not the same thing. Chain-based indexes are particularly easy to misconstrue to readers that they are modifying the original volume, and in fact only intermediate copies are modified. Where the original data need to be updated, the target operation should be clearly defined and aliases validated.
Repeated indexes also introduce conflict. If the index is [1,1] and the value is different, the ordinary value coverage semantic should not be used as an addition; Where cumulative is required, explicit polymerization API should be used and its firm engagement checked. Arithmetic cannot be defined by relying on which value a running happens to leave.
Automatic fractional reading of the index usually returns the output gradient to the selected location, with cumulative repetitions. The index itself is a discrete option and therefore does not have a normal continuous number. For systems that require learning to select a location, a continuous laxity or other method should be defined, rather than just setting an integer index at requires_grad.
For normal intensive loads, advanced indexes read the normal construction of new results; Execute index values directly on the original object and write semantics. Do not extrapolate the original load to read a copy. The minimum returns can be checked simultaneously for both the original, the result and the modified parties, using different integer numbers to make the selection visible at first glance from aliases; Do not test only the final shape.
Can the two selection results be supported by the same number of results?
No, the reading value is different from the alias contract; You need to see the interface definition and confirm it with a clear change test.
Repeat indexing values to replace scatter_add?
Inability, coverage differs from the cumulative definition. Accompaniment is required to select visible aggregations and to check parallel implementation boundaries.
The attribution method should also distinguish between reading advanced index results and indexing values directly on the original volume. The former may change only copies, while the latter takes a specific semantic approach.
Sources and reconciliations
Definitions, methods and interfaces are available.
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.