Skip to content

Commit

Permalink
docs: correct wrong information about indexing (#1087)
Browse files Browse the repository at this point in the history
* docs: remove incorrect information

* docs: explain R vs torch indexing difference
  • Loading branch information
sebffischer authored Aug 10, 2023
1 parent ab55d4f commit d8d6d28
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions vignettes/indexing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ x
x[1,3]
x[1,-1]
```
Note that if one indexes a multidimensional tensor with
fewer indices than dimensions, one gets an error, unlike in R that would flatten the array. For example:

```{r, error=TRUE}
Note that if one indexes a multidimensional tensor with fewer indices than dimensions, torch's behaviour differs from R,
which flattens the array. In torch, the missing indices are considered complete slices `:`.

```{r}
x[1]
```


## Slicing and striding

It is possible to slice and stride arrays to extract sub-arrays of the same number of dimensions, but of different sizes than the original. This is best illustrated by a few examples:
Expand Down Expand Up @@ -155,7 +157,7 @@ z[..,1]

Vector indexing is also supported but care must be taken regarding performance as, in general its much less performant than slice based indexing.

> Note: Starting from version 0.5.0, vector indexing in torch follows R semantics,
> Note: Starting from version 0.5.0, vector indexing in torch follows R semantics,
prior to that the behavior was similar to [numpy's advanced indexing](https://numpy.org/doc/stable/reference/arrays.indexing.html#advanced-indexing).
To use the old behavior, consider using `?torch_index`, `?torch_index_put` or `torch_index_put_`.

Expand Down

0 comments on commit d8d6d28

Please sign in to comment.