Skip to content

Commit 2a08cdd

Browse files
committed
Add information about negative indices in tutorial
1 parent 3e9abd1 commit 2a08cdd

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

tutorials-book/src/indexing.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
Indexing in ArrayFire is a powerful but easy to abuse feature. This feature allows you to reference
44
or copy subsections of a larger array and perform operations on only a subset of elements.
55

6+
This chapter is split into the following sections:
7+
- [Index an Array using Seq Objects](#using-seq-objects)
8+
- [Create a view of an existing Array](#create-a-view-of-an-existing-array)
9+
- [Modify a sub region of an existing Array](#modify-a-sub-region-of-an-existing-array)
10+
- [Using Array and Seq combination](#using-array-and-seq-combination)
11+
- [Create a view of an existing Array](#create-a-view-of-an-existing-array)
12+
- [Modify a sub region of an existing Array](#modify-a-sub-region-of-an-existing-array)
13+
- [Extract or Set rows/columns of an Array](#extract-or-set-rowscolumns-of-an-array)
14+
- [Negative Indices](#negative-indices)
15+
616
[Indexer][1] structure is the key element used in Rust wrapper of ArrayFire for creating references
7-
to existing Arrays. Given below are few of such functions and their corresponding use cases. Use
8-
[Indexer::new][2] to create an Indexer object and set either a `Seq` object or `Array` as indexing
9-
object for a given dimension.
17+
to existing Arrays. The above sections illustrate how it can be used in conjunction with `Seq`
18+
and/or `Array`. Apart from that, each section also showcases a macro based equivalent
19+
code(if one exists) that is more terse in syntax but offers the same functionality.
1020

1121
## Using Seq objects
1222

@@ -74,7 +84,7 @@ We will use [assign\_gen][13] function to do it.
7484
{{#include ../../src/core/macros.rs:macro_seq_array_assign}}
7585
```
7686

77-
## Extract or Set rows/coloumns of an Array
87+
## Extract or Set rows/columns of an Array
7888

7989
Extract a specific set of rows/coloumns from an existing Array.
8090

@@ -88,8 +98,21 @@ Similarly, [set\_row][7] & [set\_rows][9] can be used to change the values in a
8898
rows using another Array. [set\_col][8] & [set\_cols][10] has same functionality, except that it is
8999
for coloumns.
90100

101+
## Negative Indices
102+
103+
Negative indices can also be used to refer elements from the end of a given axis. Negative value for
104+
a row/column/slice will fetch corresponding row/column/slice in reverse order. Given below are some
105+
examples that showcase getting row(s)/col(s) from an existing Array.
106+
107+
```rust,noplaypen
108+
{{#include ../../src/core/index.rs:get_row}}
109+
```
110+
111+
```rust,noplaypen
112+
{{#include ../../src/core/index.rs:get_rows}}
113+
```
114+
91115
[1]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Indexer.html
92-
[2]: http://arrayfire.org/arrayfire-rust/arrayfire/struct.Indexer.html#method.new
93116
[3]: http://arrayfire.org/arrayfire-rust/arrayfire/fn.index.html
94117
[4]: http://arrayfire.org/arrayfire-rust/arrayfire/fn.assign_seq.html
95118
[5]: http://arrayfire.org/arrayfire-rust/arrayfire/fn.rows.html

0 commit comments

Comments
 (0)