A high-performance general-purpose compute library
seq.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11#include <af/defines.h>
12
20typedef struct af_seq {
22 double begin;
23
25 double end;
26
28 double step;
30
31static const af_seq af_span = {1, 1, 0};
32
33#ifdef __cplusplus
34namespace af
35{
36class array;
37
46{
47public:
52
56 size_t size;
57
61 bool m_gfor;
62
80 seq(double length = 0);
81
86
107 seq(double begin, double end, double step = 1);
108
117 seq(seq other, bool is_gfor);
118
124 seq(const af_seq& s_);
125
134 seq& operator=(const af_seq& s);
135
149 inline seq operator-() { return seq(-s.begin, -s.end, -s.step); }
150
164 inline seq operator+(double x) { return seq(s.begin + x, s.end + x, s.step); }
165
181 inline seq operator-(double x) { return seq(s.begin - x, s.end - x, s.step); }
182
199 inline seq operator*(double x) { return seq(s.begin * x, s.end * x, s.step * x); }
200
201 friend inline seq operator+(double x, seq y) { return y + x; }
202
203 friend inline seq operator-(double x, seq y) { return -y + x; }
204
205 friend inline seq operator*(double x, seq y) { return y * x; }
206
222 operator array() const;
223
224 private:
225 void init(double begin, double end, double step);
226};
227
229extern AFAPI int end;
230
232extern AFAPI seq span;
233
234}
235#endif
236
237#ifdef __cplusplus
238extern "C" {
239#endif
240
242AFAPI af_seq af_make_seq(double begin, double end, double step);
243
244#ifdef __cplusplus
245}
246#endif
A multi dimensional data container.
Definition: array.h:37
seq is used to create sequences for indexing af::array
Definition: seq.h:46
bool m_gfor
Flag for gfor.
Definition: seq.h:61
seq(seq other, bool is_gfor)
Copy constructor.
friend seq operator+(double x, seq y)
Definition: seq.h:201
seq operator-()
Negation operator creates a sequence with the signs negated.
Definition: seq.h:149
seq(double length=0)
Creates a sequence of size length as [0, 1, 2..., length - 1].
af_seq s
Get the af_seq C-style struct.
Definition: seq.h:51
~seq()
Destructor.
seq(double begin, double end, double step=1)
Creates a sequence starting at begin, ending at or before end (inclusive) with increments as step.
seq operator+(double x)
Addition operator offsets the begin and end by x.
Definition: seq.h:164
friend seq operator*(double x, seq y)
Definition: seq.h:205
size_t size
Get's the length of the sequence.
Definition: seq.h:56
seq operator*(double x)
Multiplication operator spaces the sequence by a factor x.
Definition: seq.h:199
seq(const af_seq &s_)
Create a seq object from an af_seq struct.
seq & operator=(const af_seq &s)
Assignment operator to create a new sequence from an af_seq.
seq operator-(double x)
Subtraction operator offsets the begin and end by x.
Definition: seq.h:181
friend seq operator-(double x, seq y)
Definition: seq.h:203
#define AFAPI
Definition: defines.h:38
Definition: algorithm.h:15
AFAPI int end
A special value representing the last value of an axis.
AFAPI seq span
A special value representing the entire axis of an af::array.
static const af_seq af_span
Definition: seq.h:31
AFAPI af_seq af_make_seq(double begin, double end, double step)
Create a new af_seq object.
C-style struct to creating sequences for indexing.
Definition: seq.h:20
double end
End position of the sequence (inclusive)
Definition: seq.h:25
double step
Step size between sequence values.
Definition: seq.h:28
double begin
Start position of the sequence.
Definition: seq.h:22