4 Matrices and arrays

4.1 Relationship to R

In R you can apply both matrix multiplication (%*%) and elementwise multiplication (*) to objects of type “matrix,” i.e. it is the operator that determines the operation. In TMB we instead have two different types of objects, while the multiplication operator (*) is the same:

  • matrix: linear algebra
  • array: elementwise operations; () and [] style indexing.
  • vector: can be used in linear algebra with matrix, but at the same time admits R style element-wise operations.

See the file matrix_arrays.cpp for examples of use.

4.2 Relationship to Eigen

The TMB types matrix and array (in dimension 2) inherits directly from the the Eigen types Matrix and Array. The advanced user of TMB will benefit from familiarity with the Eigen documentation. Note that arrays of dimension 3 or higher are specially implemented in TMB, i.e. are not directly inherited from Eigen.