TMB Documentation  v1.9.10
tmbutils.hpp
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 Kasper Kristensen
2 // License: GPL-2
3 
17 namespace tmbutils{
18 // Utilities used by the core
19 using namespace Eigen;
20 #include "vector.hpp"
21 #include "array.hpp"
22 
23 template <class Type, class From>
24 vector<Type> asVector(From *px, int n){
25  vector<Type> x(n);
26  for(int i=0;i<n;i++)x[i]=Type(px[i]);
27  return x;
28 }
29 
30 #if defined(R_R_H)
31 template <class Type>
32 array<Type> asArray(SEXP x)
33 {
34  if(!Rf_isArray(x))Rf_error("NOT AN ARRAY!");
35  SEXP dim=Rf_getAttrib(x,R_DimSymbol);
36  vector<int> d=asVector<int,int>(INTEGER(dim), LENGTH(dim));
37  vector<Type> y=asVector<Type,double>(REAL(x), LENGTH(x));
38  return array<Type>(y,d);
39 }
40 
41 #endif
42 
43 } // End namespace
44 
Array class used by TMB.
Definition: tmbutils.hpp:23
vector< Type > asVector(SEXP x)
Construct c++-vector from SEXP object.
Definition: convert.hpp:108
Defines TMB vectors.
Vector class used by TMB.
Definition: tmbutils.hpp:18
Utility functions for TMB (automatically included)
Definition: concat.hpp:5
License: GPL v2