Skip to content

Difficulties with isfinite() on Windows machines #347

@cschwarz-stat-sfu-ca

Description

@cschwarz-stat-sfu-ca

Description:

Using the isfinite() function in TMB cases compiler error on Windows but not on Macintosh when using compile() in R

Reproducible Steps:

Here is my simple.cpp file>


#include <TMB.hpp>

template
Type objective_function::operator() ()
{

DATA_VECTOR( left ); // left and right values
PARAMETER( log_shape );

Type test;
Type test2;

test = pow(left(1)-log_shape,2);

test2 = isfinite(test);

ADREPORT (test);
REPORT(test);
return test2;
};

Here is my R code

library(TMB)
compile( "simple.cpp" ) # compile() is a function within the TMB library

dyn.load(dynlib("simple"))

simple.model <- MakeADFun(
data= list(left=10.1),
parameters=list(log_shape=3.1 ),
DLL="simple"
)

simple.model$fn(simple.model$par)

Current Output:

When running the R code on Macintosh

library(TMB)
compile( "simple.cpp" ) # compile() is a function within the TMB library
Note: Using Makevars in /Users/cschwarz/.R/Makevars
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/cschwarz/Rlibs/TMB/include" -I"/Users/cschwarz/Rlibs/RcppEigen/include" -DTMB_SAFEBOUNDS -DLIB_UNLOAD=R_unload_simple -DTMB_LIB_INIT=R_init_simple -I/usr/local/include -fPIC -Wall -g -O2 -c simple.cpp -o simple.o
....
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o simple.so simple.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
[1] 0

i.e. a successful compilation

When running the R code on Windows it terminates with
C:/Rlibs/RCPPEI1/include/Eigen/src/Core/CoreEvaluators.h:960:8: warning: ignoring attributes on template argument 'Eigen::internal::packet_traits::type' {aka '__vector(2) double'} [-Wignored-attributes]
enum {
^
make: *** [C:/PROGRA
1/R/R-41~1.0/etc/x64/Makeconf:245: simple.o] Error 1
Error in compile("simple.cpp") : Compilation failed

If you comment out the isfinite() statement it compiles fine.

TMB Version:

Mac: > packageVersion("TMB")
[1] ‘1.7.20’

Windows

packageVersion("TMB")
[1] ‘1.7.20’

R Version:

Mac: "R version 4.0.5 (2021-03-31)"

Windows: "R version 4.1.0 (2021-05-18)"

Operating System:

Mac: OS 11.3.1

Windows: Windows 8.1 Pro

Thanks
Carl Schwarz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions