-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathindex.h
More file actions
376 lines (343 loc) · 12 KB
/
index.h
File metadata and controls
376 lines (343 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
#include <af/defines.h>
#include <af/seq.h>
///
/// \brief Struct used to index an af_array
///
/// This struct represents objects which can be used to index into an af_array
/// Object. It contains a union object which can be an \ref af_seq or an
/// \ref af_array. Indexing with an int can be represented using a \ref af_seq
/// object with the same \ref af_seq::begin and \ref af_seq::end with an
/// af_seq::step of 1
typedef struct af_index_t {
union {
af_array arr; ///< The af_array used for indexing
af_seq seq; ///< The af_seq used for indexing
} idx;
bool isSeq; ///< If true the idx value represents a seq
bool isBatch; ///< If true the seq object is a batch parameter
} af_index_t;
#if __cplusplus
namespace af
{
class dim4;
class array;
class seq;
///
/// \brief Wrapper for af_index.
///
/// This class is a wrapper for the af_index struct in the C interface. It
/// allows implicit type conversion from valid indexing types like int,
/// \ref af::seq, \ref af_seq, and \ref af::array.
///
/// \note This is a helper class and does not necessarily need to be created
/// explicitly. It is used in the operator() overloads to simplify the API.
///
/// \ingroup arrayfire_class
class AFAPI index {
af_index_t impl;
public:
///
/// \brief Default constructor. Equivalent to \ref af::span
///
index();
~index();
///
/// \brief Implicit int converter
///
/// Indexes the af::array at index \p idx
///
/// \param[in] idx is the id of the index
///
/// \sa indexing
///
index(const int idx);
///
/// \brief Implicit seq converter
///
/// Indexes the af::array using an \ref af::seq object
///
/// \param[in] s0 is the set of indices to parse
///
/// \sa indexing
///
index(const af::seq& s0);
///
/// \brief Implicit seq converter
///
/// Indexes the af::array using an \ref af_seq object
///
/// \param[in] s0 is the set of indices to parse
///
/// \sa indexing
///
index(const af_seq& s0);
///
/// \brief Implicit int converter
///
/// Indexes the af::array using an \ref af::array object
///
/// \param[in] idx0 is the set of indices to parse
///
/// \sa indexing
///
index(const af::array& idx0);
#if AF_API_VERSION >= 31
///
/// \brief Copy constructor
///
/// \param[in] idx0 is index to copy.
///
/// \sa indexing
///
index(const index& idx0);
#endif
///
/// \brief Returns true if the \ref af::index represents a af::span object
///
/// \returns true if the af::index is an af::span
///
bool isspan() const;
///
/// \brief Gets the underlying af_index_t object
///
/// \returns the af_index_t represented by this object
///
const af_index_t& get() const;
#if AF_API_VERSION >= 31
///
/// \brief Assigns idx0 to this index
///
/// \param[in] idx0 is the index to be assigned to the /ref af::index
/// \returns the reference to this
///
///
index & operator=(const index& idx0);
#if AF_COMPILER_CXX_RVALUE_REFERENCES
///
/// \brief Move constructor
///
/// \param[in] idx0 is index to copy.
///
index(index &&idx0);
///
/// \brief Move assignment operator
///
/// \param[in] idx0 is the index to be assigned to the /ref af::index
/// \returns a reference to this
///
index& operator=(index &&idx0);
#endif
#endif // AF_API_VERSION
};
///
/// Lookup the values of an input array by indexing with another array
///
/// \param[in] in is the input array that will be queried
/// \param[in] idx are the lookup indices
/// \param[in] dim specifies the dimension for indexing
/// \returns an array containing values of \p in at locations specified by \p index
///
/// \ingroup index_func_lookup
///
AFAPI array lookup(const array &in, const array &idx, const int dim = -1);
#if AF_API_VERSION >= 31
///
/// Copy the values of an input array based on index
///
/// \param[out] dst The destination array
/// \param[in] src The source array
/// \param[in] idx0 The first index
/// \param[in] idx1 The second index (defaults to \ref af::span)
/// \param[in] idx2 The third index (defaults to \ref af::span)
/// \param[in] idx3 The fourth index (defaults to \ref af::span)
/// \ingroup index_func_index
///
AFAPI void copy(array &dst, const array &src,
const index &idx0,
const index &idx1 = span,
const index &idx2 = span,
const index &idx3 = span);
#endif
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
///
/// Lookup the values of input array based on sequences
///
/// \param[out] out output array containing values indexed by the
/// sequences
/// \param[in] in is the input array
/// \param[in] ndims is the number of sequences provided
/// \param[in] index is an array of sequences
///
/// \ingroup index_func_index
AFAPI af_err af_index( af_array *out,
const af_array in,
const unsigned ndims, const af_seq* const index);
///
/// Lookup the values of an input array by indexing with another array
///
/// \param[out] out output array containing values of \p in at locations
/// specified by \p indices
/// \param[in] in is the input array that will be queried
/// \param[in] indices are the lookup indices
/// \param[in] dim specifies the dimension for indexing
///
/// \ingroup index_func_lookup
///
AFAPI af_err af_lookup( af_array *out,
const af_array in, const af_array indices,
const unsigned dim);
///
/// Copy and write values in the locations specified by the sequences
///
/// \param[out] out output array with values of \p rhs copied to
/// locations specified by \p index and values from
/// \p lhs in all other locations.
/// \param[in] lhs is array whose values are used for indices NOT
/// specified by \p index
/// \param[in] ndims is the number of sequences provided
/// \param[in] indices is an array of sequences
/// \param[in] rhs is the array whose values are used for indices
/// specified by \p index
///
/// \ingroup index_func_assign
///
AFAPI af_err af_assign_seq( af_array *out,
const af_array lhs,
const unsigned ndims, const af_seq* const indices,
const af_array rhs);
///
/// \brief Indexing an array using \ref af_seq, or \ref af_array
///
/// Generalized indexing function that accepts either af_array or af_seq
/// along a dimension to index the input array and create the corresponding
/// output array
///
/// \param[out] out output array containing values at indexed by
/// the sequences
/// \param[in] in is the input array
/// \param[in] ndims is the number of \ref af_index_t provided
/// \param[in] indices is an array of \ref af_index_t objects
///
/// \ingroup index_func_index
///
AFAPI af_err af_index_gen( af_array *out,
const af_array in,
const dim_t ndims, const af_index_t* indices);
///
/// \brief Assignment of an array using \ref af_seq, or \ref af_array
///
/// Generalized assignment function that accepts either af_array or af_seq
/// along a dimension to assign elements form an input array to an output
/// array
///
/// \param[out] out output array containing values at indexed by
/// the sequences
/// \param[in] lhs is the input array
/// \param[in] ndims is the number of \ref af_index_t provided
/// \param[in] indices is a C array of \ref af_index_t objects
/// \param[in] rhs is the array whose values will be assigned to \p lhs
///
/// \ingroup index_func_assign
///
AFAPI af_err af_assign_gen( af_array *out,
const af_array lhs,
const dim_t ndims, const af_index_t* indices,
const af_array rhs);
#if AF_API_VERSION >= 32
///
/// \brief Create an quadruple of af_index_t array
///
/// \snippet test/index.cpp ex_index_util_0
///
/// \param[out] indexers pointer to location where quadruple af_index_t array is created
/// \returns \ref af_err error code
///
/// \ingroup index_func_index
///
AFAPI af_err af_create_indexers(af_index_t** indexers);
#endif
#if AF_API_VERSION >= 32
///
/// \brief set \p dim to given indexer af_array \p idx
///
/// \snippet test/index.cpp ex_index_util_0
///
/// \param[in] indexer pointer to location where quadruple af_index_t array was created
/// \param[in] idx is the af_array indexer for given dimension \p dim
/// \param[in] dim is the dimension to be indexed
/// \returns \ref af_err error code
///
/// \ingroup index_func_index
///
AFAPI af_err af_set_array_indexer(af_index_t* indexer, const af_array idx, const dim_t dim);
#endif
#if AF_API_VERSION >= 32
///
/// \brief set \p dim to given indexer af_array \p idx
///
/// This function is similar to \ref af_set_array_indexer in terms of functionality except
/// that this version accepts object of type \ref af_seq instead of \ref af_array.
///
/// \snippet test/index.cpp ex_index_util_0
///
/// \param[in] indexer pointer to location where quadruple af_index_t array was created
/// \param[in] idx is the af_seq indexer for given dimension \p dim
/// \param[in] dim is the dimension to be indexed
/// \param[in] is_batch indicates if the sequence based indexing is inside a batch operation
///
/// \ingroup index_func_index
///
AFAPI af_err af_set_seq_indexer(af_index_t* indexer, const af_seq* idx,
const dim_t dim, const bool is_batch);
#endif
#if AF_API_VERSION >= 32
///
/// \brief set \p dim to given indexer af_array \p idx
///
/// This function is alternative to \ref af_set_seq_indexer where instead of passing
/// in an already prepared \ref af_seq object, you pass the arguments necessary for
/// creating an af_seq directly.
///
/// \param[in] indexer pointer to location where quadruple af_index_t array was created
/// \param[in] begin is the beginning index of along dimension \p dim
/// \param[in] end is the beginning index of along dimension \p dim
/// \param[in] step size along dimension \p dim
/// \param[in] dim is the dimension to be indexed
/// \param[in] is_batch indicates if the sequence based indexing is inside a batch operation
/// \returns \ref af_err error code
///
/// \ingroup index_func_index
///
AFAPI af_err af_set_seq_param_indexer(af_index_t* indexer,
const double begin, const double end, const double step,
const dim_t dim, const bool is_batch);
#endif
#if AF_API_VERSION >= 32
///
/// \brief Release's the memory resource used by the quadruple af_index_t array
///
/// \snippet test/index.cpp ex_index_util_0
///
/// \param[in] indexers is pointer to location where quadruple af_index_t array is created
// \returns \ref af_err error code
///
/// \ingroup index_func_index
///
AFAPI af_err af_release_indexers(af_index_t* indexers);
#endif
#ifdef __cplusplus
}
#endif