 A high-performance general-purpose compute library
seq Class Reference

seq is used to create sequences for indexing af::array More...

#include <seq.h>

## Public Member Functions

seq (double length=0)
Creates a sequence of size length as [0, 1, 2..., length - 1].

~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 (seq other, bool is_gfor)
Copy constructor.

seq (const af_seq &s_)
Create a seq object from an af_seq struct.

seqoperator= (const af_seq &s)
Assignment operator to create a new sequence from an af_seq.

seq operator- ()
Negation operator creates a sequence with the signs negated.

seq operator+ (double x)
Addition operator offsets the begin and end by x.

seq operator- (double x)
Subtraction operator offsets the begin and end by x.

seq operator* (double x)
Multiplication operator spaces the sequence by a factor x.

operator array () const
Implicit conversion operator from seq to af::array.

## Data Fields

af_seq s
Get the af_seq C-style struct.

size_t size
Get's the length of the sequence.

bool m_gfor
Flag for gfor.

## Friends

seq operator+ (double x, seq y)

seq operator- (double x, seq y)

seq operator* (double x, seq y)

## ◆ seq() [1/4]

 seq ( double length = 0 )

Creates a sequence of size length as [0, 1, 2..., length - 1].

The sequence has begin as 0, end as length - 1 and step as 1.

Note
When doing seq(-n), where n is > 0, then the sequence is generated as 0...-n but step remains +1. This is because when such a sequence is used for indexing af::array, then -n represents n elements from the end. That is, seq(-2) will imply indexing an array 0...dimSize - 2.
// [begin, end, step]
seq a(10); // [0, 9, 1] => 0, 1, 2....9
seq is used to create sequences for indexing af::array
Definition: seq.h:46
Parameters
 [in] length is the size of the seq to be created.

## ◆ ~seq()

 ~seq ( )

Destructor.

## ◆ seq() [2/4]

 seq ( double begin, double end, double step = 1 )

Creates a sequence starting at begin, ending at or before end (inclusive) with increments as step.

The sequence will be [begin, begin + step, begin + 2 * step...., begin + n * step] where the begin + n * step <= end.

// [begin, end, step]
seq a(10, 20); // [10, 20, 1] => 10, 11, 12....20
seq b(10, 20, 2); // [10, 20, 2] => 10, 12, 14....20
seq c(-5, 5); // [-5, 5, 1] => -5, -4, -3....0, 1....5
seq d(-5, -15, -1); // [-5,-15, -1] => -5, -6, -7....-15
seq e(-15, -5, 1); // [-15, -5, 1] => -15, -14, -13....-5
Parameters
 [in] begin is the start of the sequence [in] end is the maximum value a sequence can take (inclusive) [in] step is the increment or decrement size (default is 1)

## ◆ seq() [3/4]

 seq ( seq other, bool is_gfor )

Copy constructor.

Creates a copy seq from another sequence.

Parameters
 [in] other seqence to be copies [in] is_gfor is the gfor flag

## ◆ seq() [4/4]

 seq ( const af_seq & s_ )

Create a seq object from an af_seq struct.

Parameters
 [in] s_ is the af_seq struct

## ◆ operator array()

 operator array ( ) const

Implicit conversion operator from seq to af::array.

Convertes a seq object into an af::array object. The contents of the af:array will be the explicit values from the seq.

Note
Do not use this to create arrays of sequences. Use range.
// [begin, end, step]
seq s(10, 20, 2); // [10, 20, 2] => 10, 12, 14....20
array arr = s;
af_print(arr); // 10 12 14 16 18 20
A multi dimensional data container.
Definition: array.h:37
af_seq s
Get the af_seq C-style struct.
Definition: seq.h:51
#define af_print(...)
Definition: util.h:148

## ◆ operator*()

 seq operator* ( double x )
inline

Multiplication operator spaces the sequence by a factor x.

begin is changed to begin * x end is changed to end * x step is changed to step * x

// [begin, end, step]
seq a(10, 20, 2); // [10, 20, 2] => 10, 12, 14....20
seq b(-5, 5); // [-5, 5, 1] => -5, -4, -3....0, 1....5
seq c = a * 3; // [30, 60, 6] => 30, 36, 42....60
seq d = b * 3; // [-15, 15, 3] => -15, -12, -9....0, 3....15
seq e = a * 0.5; // [5, 10, 1] => 5, 6, 7....10

Definition at line 199 of file seq.h.

199{ return seq(s.begin * x, s.end * x, s.step * x); }
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

## ◆ operator+()

 seq operator+ ( double x )
inline

Addition operator offsets the begin and end by x.

There is no change in step.

begin is changed to begin + x end is changed to end + x

// [begin, end, step]
seq a(2, 20, 2); // [2, 20, 2] => 2, 4, 6....20
seq b = a + 3; // [5, 23, 2] => 5, 7, 9....23

Definition at line 164 of file seq.h.

164{ return seq(s.begin + x, s.end + x, s.step); }

## ◆ operator-() [1/2]

 seq operator- ( )
inline

Negation operator creates a sequence with the signs negated.

begin is changed to -begin end is changed to -end step is changed to -step

// [begin, end, step]
seq a(1, 10); // [ 1, 10, 1] => 1, 2, 3....10
seq b = -a; // [-1,-10,-1] => -1, -2, -3...-10

Definition at line 149 of file seq.h.

149{ return seq(-s.begin, -s.end, -s.step); }

## ◆ operator-() [2/2]

 seq operator- ( double x )
inline

Subtraction operator offsets the begin and end by x.

There is no change in step.

begin is changed to begin - x end is changed to end - x

// [begin, end, step]
seq a(10, 20, 2); // [10, 20, 2] => 10, 12, 14....20
seq b(2, 10); // [ 2, 10, 1] => 2, 3, 4....10
seq c = a - 3; // [ 7, 17, 2] => 7, 9, 11....17
seq d = b - 3; // [-1, 7, 2] => -1, 1, 3....7

Definition at line 181 of file seq.h.

181{ return seq(s.begin - x, s.end - x, s.step); }

## ◆ operator=()

 seq & operator= ( const af_seq & s )

Assignment operator to create a new sequence from an af_seq.

This operator creates a new sequence using the begin, end and step from the input sequence.

Parameters
 [in] s is the input sequence

## ◆ operator*

 seq operator* ( double x, seq y )
friend

Definition at line 205 of file seq.h.

205{ return y * x; }

## ◆ operator+

 seq operator+ ( double x, seq y )
friend

Definition at line 201 of file seq.h.

201{ return y + x; }

## ◆ operator-

 seq operator- ( double x, seq y )
friend

Definition at line 203 of file seq.h.

203{ return -y + x; }

## ◆ m_gfor

 bool m_gfor

Flag for gfor.

Definition at line 61 of file seq.h.

## ◆ s

 af_seq s

Get the af_seq C-style struct.

Definition at line 51 of file seq.h.

## ◆ size

 size_t size

Get's the length of the sequence.

Definition at line 56 of file seq.h.

The documentation for this class was generated from the following file: