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

Array class used by TMB. More...

#include <tmbutils.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 tmbutils::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.

Definition at line 23 of file tmbutils.hpp.

Member Function Documentation

§ cols()

template<class Type>
int tmbutils::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 188 of file tmbutils.hpp.

§ matrix()

template<class Type>
tmbutils::matrix<Type> tmbutils::array< Type >::matrix ( void  )
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 311 of file tmbutils.hpp.

§ rotate()

template<class Type>
array<Type> tmbutils::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 291 of file tmbutils.hpp.

§ rows()

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

Number of inner-most dimensions.

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

Definition at line 195 of file tmbutils.hpp.

§ transpose()

template<class Type>
array<Type> tmbutils::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].

Definition at line 277 of file tmbutils.hpp.

Referenced by density::contAR2_t< scalartype_ >::operator()().


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