ivl 679
array< T, OPTS > Class Template Reference

1-dimensional array of type T More...

#include <array_class.hpp>

Inherits array_common_base< array< T, OPTS > >, and vector< T >.

List of all members.

Public Types

typedef ptrdiff_t diff_type
 difference type of iterators
typedef size_t size_type
 parameter of resize, in each class of the hierarchy

Public Member Functions

void reshape (size_t len)
 Reshape is same as resize for 1-d arrays.
 ~array ()
 destructor
init member function
void init ()
 Init is behaves exactly like the constructor. See constructor reference.
void init (size_t count)
 Init is behaves exactly like the constructor. See constructor reference.
void init (int count)
 Init is behaves exactly like the constructor. See constructor reference.
void init (long int count)
 Init is behaves exactly like the constructor. See constructor reference.
void init (size_t count, const T &s)
 Init is behaves exactly like the constructor. See constructor reference.
void init (size_t count, const T *ptr)
 Init is behaves exactly like the constructor. See constructor reference.
template<class J >
void init (const internal::tuple_rvalue< J > &r)
 Init is behaves exactly like the constructor. See constructor reference.
void init (const array &a)
 Init is behaves exactly like the constructor. See constructor reference.
template<class J , class S >
void init (const array< J, S > &a, size_t n)
 Init is behaves exactly like the constructor. See constructor reference.
template<class J , class S >
void init (const array< J, S > &a)
 Init is behaves exactly like the constructor. See constructor reference.
template<class J , class S >
void init (size_t count, const array< J, S > &a)
 Init is behaves exactly like the constructor. See constructor reference.
Size functions
size_t length () const
 Get the length of the element sequence.
size_type size () const
 Get the size of the array. generic-class function.
size_t numel () const
 Get the length of the element sequence.
Element access

Access a unique element by specifying the position

std::vector< T >::const_reference operator[] (size_t offset) const
 Returns the const element found at position offset.
std::vector< T >::reference operator[] (size_t offset)
 Returns the element found at position offset.
Constructors
 array ()
 Default constructor.
 array (size_t count)
 Construnct by defining an initial number of elements.
 array (int count)
 Construnct by defining an initial number of elements.
 array (long int count)
 Construnct by defining an initial number of elements.
 array (size_t count, const T &s)
 Construnct by defining an initial number of elements and a default value.
 array (size_t count, const T *ptr)
 Construct by using a C array.
template<class S , int J>
 array (S(&arr)[J])
 Construct by using a C array.
template<class J >
 array (const internal::tuple_rvalue< J > &r)
 Construct array with rvalue.
 array (const array &a)
 Copy-constructor.
template<class J , class S >
 array (const array< J, S > &a, size_t n)
 construct from classes derived from array, using N elements
template<class J , class S >
 array (const array< J, S > &a)
 construct from an existing array of any type.
template<class J , class S >
 array (size_t count, const array< J, S > &a)
 Construct from array of the same type, using (shape, array)
Assignement Operators
template<class K >
derived_type & operator= (const K &k)
 Copy-Assign another array of identical type.
this_typeoperator= (const this_type &a)

Related Functions

(Note that these are not member functions.)

Array construction by providing element values
template<class T >
array< typename
types::create_new< T >::type,
fixed< 1 > > 
arr (const T &p1)
 Create an array with one element.
template<class T , class T1 >
array< typename
types::create_new< T >::type,
fixed< 2 > > 
arr (const T &p1, const T1 &p2)
 Create an array with two elements.
template<class T , class T1 , class T2 >
array< typename
types::create_new< T >::type,
fixed< 3 > > 
arr (const T &p1, const T1 &p2, const T2 &p3)
 Create an array with three elements.
template<class T , class T1 , class T2 , class T3 >
array< typename
types::create_new< T >::type,
fixed< 4 > > 
arr (const T &p1, const T1 &p2, const T2 &p3, const T3 &p4)
 Create an array with four elements.
template<class T , class T1 , class T2 , class T3 , class T4 >
array< typename
types::create_new< T >::type,
fixed< 5 > > 
arr (const T &p1, const T1 &p2, const T2 &p3, const T3 &p4, const T4 &p5)
 Create an array with five elements.
template<class T , class T1 , class T2 , class T3 , class T4 , class T5 >
array< typename
types::create_new< T >::type,
fixed< 6 > > 
arr (const T &p1, const T1 &p2, const T2 &p3, const T3 &p4, const T4 &p5, const T5 &p6)
 Create an array with six elements.
template<class T , class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
array< typename
types::create_new< T >::type,
fixed< 7 > > 
arr (const T &p1, const T1 &p2, const T2 &p3, const T3 &p4, const T4 &p5, const T5 &p6, const T6 &p7)
 Create an array with seven elements.
Size_array construction by providing element values
array< size_t, fixed< 1 > > idx (size_t p1)
 Create a size_array with one element.
array< size_t, fixed< 2 > > idx (size_t p1, size_t p2)
 Create a size_array with two element.
array< size_t, fixed< 3 > > idx (size_t p1, size_t p2, size_t p3)
 Create a size_array with three elements.
array< size_t, fixed< 4 > > idx (size_t p1, size_t p2, size_t p3, size_t p4)
 Create a size_array with four elements.
array< size_t, fixed< 5 > > idx (size_t p1, size_t p2, size_t p3, size_t p4, size_t p5)
 Create a size_array with five elements.
array< size_t, fixed< 6 > > idx (size_t p1, size_t p2, size_t p3, size_t p4, size_t p5, size_t p6)
 Create a size_array with six elements.
array< size_t, fixed< 7 > > idx (size_t p1, size_t p2, size_t p3, size_t p4, size_t p5, size_t p6, size_t p7)
 Create a size_array with six elements.
Array non-member functions
template<class T , class S >
array< T, S >::create_similar shift (const array< T, S > &in, int count, T val=T())
 return array left shifted
template<class T , class S >
array< T, S >::create_similar cumprod (const array< T, S > &in)
 array of cumulative product of elements
template<class T , class S >
types::promote< T >::type prod (const array< T, S > &in)
 Product of all elements.
template<class S , class D >
size_t sub2ind (const array< size_t, S > &stride, const array< size_t, D > &b)
 converts index vector to single-dim index
template<class T , class S >
types::promote< T >::type sum (const array< T, S > &a)
 Sum of elements of a.
template<class T , class S >
types::to_floating< T >::type mean (const array< T, S > &a)
 Average of all elements of a.
template<class T , class S >
select_k (const array< T, S > &a, size_t k)
 Select the k-th element of an array a with comparable elements.
template<class T , class S >
types::to_floating< T >::type median (const array< T, S > &a)
 Median of array Returns the median value of an array a with comparable elements with divide operation the algorithm used is the quickest based on the algorithm described in "Numerical recipes in C".
template<class T , class S >
median_lower (const array< T, S > &a)
 Lower median of array Returns the lower median value of an array a with comparable elements the algorithm used is the quickest based on the algorithm described in "Numerical recipes in C".
template<class T , class S >
median_upper (const array< T, S > &a)
 Upper median of array Returns the upper median value of an array a with comparable elements the algorithm used is the quickest based on the algorithm described in "Numerical recipes in C".
template<class T , class S >
size_t count (const array< T, S > &in)
 Count all non-zero elements.
template<class T , class S >
types::to_real_floating< T >::type var (const array< T, S > &in)
 Variance of elements.
template<class T , class S >
types::to_real_floating< T >::type std (const array< T, S > &in)
 Standard deviation.
template<class T , class S >
array< T > cat (const array< T > &a) const
 Concatenates two arrays.
const bool isequal (const int &x, const int &y)
 Equality test.
const bool isequal (const short &x, const short &y)
const bool isequal (const unsigned short &x, const unsigned short &y)
const bool isequal (const uint8_t &x, const uint8_t &y)
const bool isequal (const int8_t &x, const int8_t &y)
const bool isequal (const long long &x, const long long &y)
const bool isequal (const unsigned long long &x, const unsigned long long &y)
const bool isequal (const size_t &x, const size_t &y)
const bool isequal (const float &x, const float &y)
const bool isequal (const double &x, const double &y)
template<class T >
const bool isequal (const std::complex< T > &x, const std::complex< T > &y)
template<class T , class S , class D >
const bool isequal (const array< T, S > &a, const array< T, D > &b)
 Equality test.
template<class T >
int compare (const ivl::array< T > &a, const ivl::array< T > &b)
 compare two arrays of indices, returns 0 if equal, 1 if a>b and -1 if a<b
template<class T >
int compare (const T &a, const T &b)
 compare two arrays of indices, returns 0 if equal, 1 if a>b and -1 if a<b
template<class T >
array< T > cross (const array< T > &a, const array< T > &b)
template<class T >
dot (const array< T > &a, const array< T > &b)
template<class T >
array< T > linspace (const T &a, const T &b, size_t n=100)
 returns a linearly spaced vector
template<class T >
array< T > logspace (double a, double b, size_t n=50)
 returns a logarithmically spaced vector
template<class T , class S >
array< T, S >::create_similar cshift (const array< T, S > &in, int count)
 return array transformed by func
template<class T , class S >
array< T, S >::create_similar cumsum (const array< T, S > &in)
 array of cumulative sum of elements
template<class T , class S >
array< T, S >::create_similar diff (const array< T, S > &in)
 difference of consecutive elements
array< int > diff (const index_array &a)
template<class T , class S >
array< T, S >::create_similar flip (const array< T, S > &in)
 flip array
template<class T , class S >
array< T, S >::create_similar sort (const array< T, S > &in, bool descending=false)
 sorts elements in the array using comb sort

Detailed Description

template<class T, class OPTS = data::mem<>>
class array< T, OPTS >

1-dimensional array of type T

This class defines an simple one-dimensional array.


Constructor & Destructor Documentation

template<class T, class OPTS = data::mem<>>
array< T, OPTS >::array ( size_t  count,
const T &  s 
) [inline]

Construnct by defining an initial number of elements and a default value.

Parameters:
countLength of the array
sDefault value for all elements
template<class T, class OPTS = data::mem<>>
array< T, OPTS >::array ( size_t  count,
const T *  ptr 
) [inline]

Construct by using a C array.

Parameters:
countLength of the array
ptrThe C array
template<class T, class OPTS = data::mem<>>
template<class S , int J>
array< T, OPTS >::array ( S(&)  arr[J]) [inline]

Construct by using a C array.

Parameters:
arrThe C array
template<class T, class OPTS = data::mem<>>
template<class J , class S >
array< T, OPTS >::array ( const array< J, S > &  a,
size_t  n 
) [inline]

construct from classes derived from array, using N elements

Developper's note: You cannot remove the defined constructor (above) even though it is a subset of this. This is because the copy constructor has a specific declaration, and should be declared to override the C++ default copy-constructor which is wrong and causes heap corruption.

template<class T, class OPTS = data::mem<>>
template<class J , class S >
array< T, OPTS >::array ( size_t  count,
const array< J, S > &  a 
) [inline]

Construct from array of the same type, using (shape, array)

This constructor has the same functionality as the (array, n) constructor, but fulfills a standard construction template that defines that all kinds of arrays (2d, nd etc) can be constructed with derived.size(), array<..> pair A difference is that this function can also accept zero length Also, if a is T or similar to the element type of the array this constructor fills in the array with count copies of the element a.


Member Function Documentation

template<class T, class OPTS = data::mem<>>
template<class K >
derived_type& array< T, OPTS >::operator= ( const K &  k) [inline]

Copy-Assign another array of identical type.

eg:

 ivl::array<int> a(10, 0);
 ivl::array<int> b;
 b = a; 

Friends And Related Function Documentation

template<class T >
array< T > cross ( const array< T > &  a,
const array< T > &  b 
) [related]

returns cross product of 1-dim arrays (vectors) a and b. length of a and b must be 3.

template<class T , class S >
array< T, S >::create_similar cshift ( const array< T, S > &  in,
int  count 
) [related]

return array transformed by func

return array left rotated

template<class T, class OPTS = data::mem<>>
array< int > diff ( const index_array< T, OPTS > &  a) [related]

specialization of diff for index_array In the case of a SIZE_RANGE array, this returns a two-element array with the values 0 and step instead of the full expanded form

template<class T >
T dot ( const array< T > &  a,
const array< T > &  b 
) [related]

return dot product of a and b a and b must be vectors of same length.

template<class T , class S , class D >
const bool isequal ( const array< T, S > &  a,
const array< T, D > &  b 
) [related]

Equality test.

Test if another object of the same type is equal with this one.

Returns:
True if the two objects are equal
template<class T, class OPTS = data::mem<>>
const bool isequal ( const int &  x,
const int &  y 
) [related]

Equality test.

Test if another object of the same type is equal with this one.

Returns:
True if the two objects are equal
template<class T , class S >
types::to_real_floating< T >::type var ( const array< T, S > &  in) [related]

Variance of elements.

Todo:
when array is removed, fix it

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations