TMB Documentation  v1.9.0
Public Member Functions | List of all members
array< Type > Struct Template Reference

Array class used by TMB. More...

#include <array.hpp>

Public Member Functions

 array (vector< int > dim_)
 Construct array from dimension vector and fill with zeros.
 
array< Type > col (int i)
 Extract sub-array with write access Index i refers to the outer-most (i.e. final) dimension.
 
int cols ()
 Number of outer-most dimensions. More...
 
tmbutils::matrix< Type > matrix ()
 Convert TMB array to matrix by keeping the first dimension and collapsing remaining dimensions. More...
 
Type & operator() (int i1)
 Elementwise subsetting 1D array. Also allowed in general to access the underlying vector of n-dim array.
 
Type & operator() (int i1, int i2)
 Elementwise subsetting 2D array.
 
Type & operator() (int i1, int i2, int i3)
 Elementwise subsetting 3D array.
 
Type & operator() (int i1, int i2, int i3, int i4)
 Elementwise subsetting 4D array.
 
Type & operator() (int i1, int i2, int i3, int i4, int i5)
 Elementwise subsetting 5D array.
 
Type & operator() (int i1, int i2, int i3, int i4, int i5, int i6)
 Elementwise subsetting 6D array.
 
Type & operator() (int i1, int i2, int i3, int i4, int i5, int i6, int i7)
 Elementwise subsetting 7D array.
 
array< Type > perm (vector< int > p)
 Array permutation. Permutes array dimensions corresponding to permutation vector p.
 
array< Type > rotate (int n)
 Array rotate (Special case of array permutation) More...
 
int rows ()
 Number of inner-most dimensions. More...
 
void setdim (vector< int > dim_)
 Sets dimension attribute and updates internal stride. Must be used when e.g. collapsing array dimensions.
 
array< Type > transpose ()
 Array transpose (Special case of array permutation) More...
 
tmbutils::vector< Type > vec ()
 Convert TMB array to vector.
 

Detailed Description

template<class Type>
struct array< Type >

Array class used by TMB.

The TMB array class is implemented as an Eigen Array of dynamic length with a dimension attribute. The implementation closely follows the way arrays work in R. Vectorized operations are inherited from the Eigen library.

Warning
Methods that are not documented here are inherited from the Eigen library and applied on the underlying n-by-1 array. In general this will yield surprising results for 2D specific array methods.
Examples:
matrix_arrays.cpp, multivariate_distributions.cpp, sam.cpp, sdv_multi_compact.cpp, and TMBad/sam.cpp.

Definition at line 22 of file array.hpp.

Member Function Documentation

§ cols()

template<class Type>
int array< Type >::cols ( )
inline

Number of outer-most dimensions.

Returns
Last array dimension (Similar to R's ncol in 2D case only)

Definition at line 187 of file array.hpp.

Referenced by array< Type >::col().

§ matrix()

template<class Type>
tmbutils::matrix<Type> array< Type >::matrix ( )
inline

Convert TMB array to matrix by keeping the first dimension and collapsing remaining dimensions.

E.g. if array dimension is (n1,n2,n3) the resulting matrix dimension is (n1, n2*n3).

Definition at line 310 of file array.hpp.

§ rotate()

template<class Type>
array<Type> array< Type >::rotate ( int  n)
inline

Array rotate (Special case of array permutation)

Rotates array dimension with n steps where n can be any (positive or negative) integer. If e.g. x has dimension [3,4,5,6] then x.rotate(1) has dimension [6,3,4,5].

Definition at line 290 of file array.hpp.

§ rows()

template<class Type>
int array< Type >::rows ( )
inline

Number of inner-most dimensions.

Returns
First array dimension (Similar to R's nrow)

Definition at line 194 of file array.hpp.

Referenced by array< Type >::matrix().

§ transpose()

template<class Type>
array<Type> array< Type >::transpose ( )
inline

Array transpose (Special case of array permutation)

If e.g. x has dimension [3,4,5,6] then x.transpose() has dimension [6,5,4,3].

Examples:
matrix_arrays.cpp, and sdv_multi_compact.cpp.

Definition at line 276 of file array.hpp.


The documentation for this struct was generated from the following file:
License: GPL v2