Include Eigen::Tensor in TMB model template

151 views
Skip to first unread message

Jeff Eaton

unread,
Mar 3, 2021, 4:16:49 AM3/3/21
to TMB Users
Hello,

I would like to include the `Eigen::Tensor` library in some TMB model code. I am getting compiler errors when I include the header, I believe due to namespace clashes with TMB.

If I include `TMB.hpp` before `Tensor`:
```
#include <TMB.hpp>
#include <unsupported/Eigen/CXX11/Tensor>
```

I get the following error:

```
      explicit specialization of non-template struct 'Rf_eval'
struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
       ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
```

If I include `Tensor` before `TMB`, I get the error:

```
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:106:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
```

Does anyone have experience with this? Is there a correct way to specify this or a workaround?

Below is example code and console output.

Many thanks,
Jeff

-----

```
library(TMB)
library(RcppEigen)

code1 <- '
#include <TMB.hpp>
#include <unsupported/Eigen/CXX11/Tensor>
//
template<class Type>
Type objective_function<Type>::operator() ()
{
  PARAMETER(p);
  Type val(p*p);
  return val;
}
'

f1 <- tempfile(fileext = ".cpp")
writeLines(code1, f1)
TMB::compile(f1, flags = "-w")


code2 <- '
#include <unsupported/Eigen/CXX11/Tensor>
#include <TMB.hpp>
//
template<class Type>
Type objective_function<Type>::operator() ()
{
  PARAMETER(p);
  Type val(p*p);
  return val;
}
'

f2 <- tempfile(fileext = ".cpp")
writeLines(code2, f2)
TMB::compile(f2, flags = "-w")

```

Output:

```
> library(RcppEigen)
> code1 <- '
+ #include <TMB.hpp>
+ #include <unsupported/Eigen/CXX11/Tensor>
+ //
+ template<class Type>
+ Type objective_function<Type>::operator() ()
+ {
+   PARAMETER(p);
+   Type val(p*p);
+   return val;
+ }
+ '
> f1 <- tempfile(fileext = ".cpp")
> writeLines(code1, f1)
> TMB::compile(f1, flags = "-w")
Note: Using Makevars in /Users/jeff/.R/Makevars 
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include -I/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include  -DTMB_SAFEBOUNDS -DLIB_UNLOAD=R_unload_file11d00690ca7aa  -DTMB_LIB_INIT=R_init_file11d00690ca7aa   -I/usr/local/include   -fPIC  -w -c /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp -o /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.o
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:99:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:122:8: error: 
      explicit specialization of non-template struct 'Rf_eval'
struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
       ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:99:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:128:70: error: 
      template argument for non-type template parameter must be an expression
struct eval<const Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
                                                                     ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:134:72: error: 
      template argument for non-type template parameter must be an expression
struct eval<TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>, Eigen::Dense>
                                                                       ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:140:78: error: 
      template argument for non-type template parameter must be an expression
struct eval<const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>, Eigen::Dense>
                                                                             ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:146:63: error: 
      template argument for non-type template parameter must be an expression
struct eval<TensorMap<PlainObjectType, Options, MakePointer>, Eigen::Dense>
                                                              ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:152:69: error: 
      template argument for non-type template parameter must be an expression
struct eval<const TensorMap<PlainObjectType, Options, MakePointer>, Eigen::Dense>
                                                                    ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:158:41: error: 
      template argument for non-type template parameter must be an expression
struct eval<TensorRef<PlainObjectType>, Eigen::Dense>
                                        ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:164:47: error: 
      template argument for non-type template parameter must be an expression
struct eval<const TensorRef<PlainObjectType>, Eigen::Dense>
                                              ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:95:51: error: 
      template argument for non-type template parameter must be an expression
struct eval<TensorCwiseUnaryOp<UnaryOp, XprType>, Eigen::Dense>
                                                  ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:101:65: error: 
      too few template arguments for class template 'Rf_eval'
struct nested<TensorCwiseUnaryOp<UnaryOp, XprType>, 1, typename eval<TensorCwiseUnaryOp<U...
                                                                ^
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:122:8: note: 
      template is declared here
struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
       ^
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:101:110: error: 
      expected a qualified name after 'typename'
  ...XprType>, 1, typename eval<TensorCwiseUnaryOp<UnaryOp, XprType> >::type>
                                                                        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:101:110: error: 
      unknown type name 'type'
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:171:68: error: 
      template argument for non-type template parameter must be an expression
struct eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, Eigen::Dense>
                                                                   ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:177:82: error: 
      too few template arguments for class template 'Rf_eval'
struct nested<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, 1, typename eval<Ten...
                                                                                 ^
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:122:8: note: 
      template is declared here
struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
       ^
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:177:144: error: 
      expected a qualified name after 'typename'
  ...1, typename eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> >::type>
                                                                               ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:177:144: error: 
      unknown type name 'type'
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:248:85: error: 
      template argument for non-type template parameter must be an expression
struct eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, Eigen::Dense>
                                                                                    ^~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:121:32: note: 
      template parameter is declared here
template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
                               ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:254:99: error: 
      too few template arguments for class template 'Rf_eval'
  ...Arg1XprType, Arg2XprType, Arg3XprType>, 1, typename eval<TensorCwiseTernaryOp<TernaryOp, ...
                                                         ^
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:122:8: note: 
      template is declared here
struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
       ^
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:1555:16: note: expanded from macro
      'eval'
#define eval                    Rf_eval
                                ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/Tensor:108:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/Tensor/TensorExpr.h:254:178: error: 
      expected a qualified name after 'typename'
  ...eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> >::type>
                                                                                    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [/var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d00690ca7aa.o] Error 1
Error in TMB::compile(f1, flags = "-w") : Compilation failed
> code2 <- '
+ #include <unsupported/Eigen/CXX11/Tensor>
+ #include <TMB.hpp>
+ //
+ template<class Type>
+ Type objective_function<Type>::operator() ()
+ {
+   PARAMETER(p);
+   Type val(p*p);
+   return val;
+ }
+ '
> f2 <- tempfile(fileext = ".cpp")
> writeLines(code2, f2)
> TMB::compile(f2, flags = "-w")
Note: Using Makevars in /Users/jeff/.R/Makevars 
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include -I/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include  -DTMB_SAFEBOUNDS -DLIB_UNLOAD=R_unload_file11d0018d3c187  -DTMB_LIB_INIT=R_init_file11d0018d3c187   -I/usr/local/include   -fPIC  -w -c /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp -o /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.o
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:106:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:254:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:296:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:369:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(typename distribution::scalartype);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:489:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:663:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:733:5: error: 
      reference to 'array' is ambiguous
    array<scalartype> y(x,dim);
    ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:822:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(scalartype_);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:950:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(typename distribution::scalartype);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:1009:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(typename distribution::scalartype);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:1096:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(typename distribution1::scalartype);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:106:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/tmbutils_extra.hpp:32:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:1287:3: error: 
      reference to 'array' is ambiguous
  TYPEDEFS(typename distribution::scalartype);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/density.hpp:15:9: note: 
      expanded from macro 'TYPEDEFS'
typedef array<scalartype> arraytype
        ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:107:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/R_inla.hpp:100:3: error: 
      reference to 'array' is ambiguous
  array<Type> Gtmp(n_tri,3,3);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      candidate found by name lookup is 'Eigen::array'
template <typename T, std::size_t N> using array = std::array<T, N>;
                                     ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/array.hpp:22:8: note: 
      candidate found by name lookup is 'tmbutils::array'
struct array:Map< Array<Type,Dynamic,1> >{
       ^
In file included from /var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.cpp:3:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:107:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/tmbutils/R_inla.hpp:100:3: error: 
      too few template arguments for alias template 'array'
  array<Type> Gtmp(n_tri,3,3);
  ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported/Eigen/CXX11/src/util/EmulateArray.h:229:38: note: 
      template is declared here
template <typename T, std::size_t N> using array = std::array<T, N>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
14 errors generated.
make: *** [/var/folders/fy/vmz3dx2x5bg1f8vy3z0yh5fr0000gn/T//RtmpdT8YYZ/file11d0018d3c187.o] Error 1
Error in TMB::compile(f2, flags = "-w") : Compilation failed
```

Session info:

```
> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RcppEigen_0.3.3.9.1 TMB_1.7.18         

loaded via a namespace (and not attached):
[1] compiler_4.0.4  Matrix_1.3-2    tools_4.0.4     Rcpp_1.0.6      grid_4.0.4      lattice_0.20-41
```

Jeff Eaton

unread,
Mar 3, 2021, 1:14:09 PM3/3/21
to TMB Users
Hello,

Further to this -- I have managed a workaround, though not at all sure if it is a correct or optimal fix:

1. Explicitly reference tmbutils::array in the headers include/tmbutils/density.hpp and include/tmbutils/R_inla.hpp to avoid clash with Eigen::array when <Tensor> header is included.  

2. Include the <Tensor> header before the <TMB.hpp> header. The other order throws an error, which I have not attempted to debug:

   >  unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h:122:8: error: 
   >    explicit specialization of non-template struct 'Rf_eval'

3. Add the compiler flag: -Wno-invalid-partial-specialization. Without this, threw an error: class template partial specialization is not more specialized than the primary template. This is apparently a known issue with a previous Eigen release, and maybe resolved by updating the Eigen headers included in TMB (not tried): https://github.com/owlbarn/eigen/issues/2#issuecomment-353763166

Here's a code snippet installing the patch version and confirming compiles model:

code2 <- '
#include <unsupported/Eigen/CXX11/Tensor>  // must include before <TMB.hpp>
#include <TMB.hpp>
//
template<class Type>
Type objective_function<Type>::operator() ()
{
  PARAMETER(p);
  Type val(p*p);
  return val;
}
'

f2 <- tempfile(fileext = ".cpp")
writeLines(code2, f2)
TMB::compile(f2, flags = "-w -Wno-invalid-partial-specialization")

I'm interested to know if this breaks anything else or if there is a better recommended solution.

Many thanks,
Jeff

Hans Skaug

unread,
Mar 4, 2021, 5:26:53 AM3/4/21
to TMB Users
Hi,

Thanks for providing a solution yourself. I cannot really say if it is optimal  or not,
but I was wondering if you could say something about the use of 
Eigen::Tensor versus TMB built in "array" type which also allow multidim arrays.
(I have not used Eigen::Tensor myself).

Best regards, Hans

Eaton, Jeffrey W

unread,
Mar 5, 2021, 3:26:39 AM3/5/21
to Hans Skaug, TMB Users

Hi Hans,

 

Many thanks. Using Eigen::Tensor is a bit exploratory at the moment, but potential interest in Eigen::Tensor vs. tmbutils::array is:

 

1. Interest in access to the higher level contraction, reduction, and geometric operations in Tensor.

 

2. We would like to include a simulation model in a separate header that is also used in other applications doesn’t have any TMB dependency—and so exploring Tensor as a container for that. Elsewhere I’ve used boost::multi_array class for multi-dimensional arrays, but from a bit of testing Tensor is a bit faster, additional operations, and reduces the dependencies a bit.

 

I’m a bit clumsy with all of this, so much welcome any thoughts or advice!

 

Thanks,
Jeff

--
To post to this group, send email to us...@tmb-project.org. Before posting, please check the wiki and issuetracker at https://github.com/kaskr/adcomp/. Please try to create a simple repeatable example to go with your question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
---
You received this message because you are subscribed to the Google Groups "TMB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmb-users/05d6ea97-d06f-4354-a653-824645425ab8n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages