3
3
Indexing in ArrayFire is a powerful but easy to abuse feature. This feature allows you to reference
4
4
or copy subsections of a larger array and perform operations on only a subset of elements.
5
5
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
+
6
16
[ 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 .
10
20
11
21
## Using Seq objects
12
22
@@ -74,7 +84,7 @@ We will use [assign\_gen][13] function to do it.
74
84
{{#include ../../src/core/macros.rs:macro_seq_array_assign}}
75
85
```
76
86
77
- ## Extract or Set rows/coloumns of an Array
87
+ ## Extract or Set rows/columns of an Array
78
88
79
89
Extract a specific set of rows/coloumns from an existing Array.
80
90
@@ -88,8 +98,21 @@ Similarly, [set\_row][7] & [set\_rows][9] can be used to change the values in a
88
98
rows using another Array. [ set\_ col] [ 8 ] & [ set\_ cols] [ 10 ] has same functionality, except that it is
89
99
for coloumns.
90
100
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
+
91
115
[ 1 ] : http://arrayfire.org/arrayfire-rust/arrayfire/struct.Indexer.html
92
- [ 2 ] : http://arrayfire.org/arrayfire-rust/arrayfire/struct.Indexer.html#method.new
93
116
[ 3 ] : http://arrayfire.org/arrayfire-rust/arrayfire/fn.index.html
94
117
[ 4 ] : http://arrayfire.org/arrayfire-rust/arrayfire/fn.assign_seq.html
95
118
[ 5 ] : http://arrayfire.org/arrayfire-rust/arrayfire/fn.rows.html
0 commit comments