cpplib00.gms : Test build of CPP library

Description

Test that the CPP library is buildable and that, once built, it
passes some simple tests.

Contributor: Steve

  if BUILDLIB not set, take a hint from quality.gms

     GHOST not set

  At this point, BUILDLIB is either NO or YES


Small Model of Type : GAMS


Category : GAMS Test library


Main file : cpplib00.gms

$Title Test build of CPP library (CPPLIB00,SEQ=657)

$ontext
Test that the CPP library is buildable and that, once built, it
passes some simple tests.

Contributor: Steve
$offtext
$ondollar

$ifthen NOT set BUILDLIB
* if BUILDLIB not set, take a hint from quality.gms
$  if set noComp  $set BUILDLIB NO
$endif

$ifthen NOT set BUILDLIB
$  escape &
$  ifthen.xx %sysenv.GHOST% == %&sysenv.GHOST%&
*    GHOST not set
$    set BUILDLIB NO
$  else.xx
$    set BUILDLIB YES
$  endif.xx
$  escape %
$endif
$if NOT %BUILDLIB% == NO  $set BUILDLIB YES

* At this point, BUILDLIB is either NO or YES
$ifthen.bld  %BUILDLIB% == YES

$  ifthen.unzip exist cppcclib.cpp
$    log File cppcclib.cpp exists already: not unzipping cppsource.zip
$  else.unzip
$    call gmsunzip -o cppsource.zip
$  endif.unzip

$  ifthen %system.buildcode% == DEG
$    call rm -f libexample64.dylib
$    log Building CPP library for platform DEG
$    call g++ -fPIC -fvisibility=hidden -dynamiclib -shared -Wall -o libexample64.dylib cppcclib.cpp cppcclibql.c -lm -ldl -lstdc++
$    ifthen.DEG NOT exist libexample64.dylib
$      log Example shared library libexample64.dylib not found: the build failed
$      abort Could not create example shared library for DEG
$    endif.DEG
$    funclibin myLib ./libexample64.dylib

$  elseif %system.buildcode% == DAC
$    call rm -f libexample64.dylib
$    log Building CPP library for platform DAC
$    call clang++ -fPIC -fvisibility=hidden -dynamiclib -shared -Wall -Wno-deprecated -Wno-deprecated-declarations -o libexample64.dylib cppcclib.cpp cppcclibql.c -lm -ldl
$    ifthen.DAC NOT exist libexample64.dylib
$      log Example shared library libexample64.dylib not found: the build failed
$      abort Could not create example shared library for DAC
$    endif.DAC
$    funclibin myLib ./libexample64.dylib

$  elseif %system.buildcode% == LEG
$    call rm -f libexample64.so
$    log Building CPP library for platform LEG
$    call g++ -fPIC -nostartfiles -shared -Wl,-Bsymbolic -pthread -Wall -o libexample64.so cppcclib.cpp cppcclibql.c -m64 -lm -ldl -lstdc++
$    ifthen.LEG NOT exist libexample64.so
$      log Example shared library libexample64.so not found: the build failed
$      abort Could not create example shared library for LEG
$    endif.LEG
$    funclibin myLib ./libexample64.so

$  elseif %system.buildcode% == WEI
$    call rm -f example64.dll
$    log Building CPP library for platform WEI
$    call icl.exe -nologo -O3 -D_CRT_DISABLE_PERFCRIT_LOCKS -D_CRT_SECURE_NO_WARNINGS -LD -Feexample64.dll cppcclib.cpp cppcclibql.c -link -nodefaultlib:libc.lib
$    ifthen.WEI NOT exist example64.dll
$      log Example shared library example64.dll not found: the build failed
$      abort Could not create example shared library for WEI
$    endif.WEI
$    funclibin myLib ./example64.dll

$  else
$    log No branch taken: test implementation is incomplete
$    abort No build commands found for platform %system.buildcode%: aborting

$  endif

$else.bld

$  if %system.platform% == DEX    $funclibin myLib  libcppcclib64.dylib
$  if %system.platform% == DAX    $funclibin myLib  libcppcclib64.dylib
$  if %system.platform% == LEX    $funclibin myLib  libcppcclib64.so
$  if %system.platform% == WEX    $funclibin myLib  cppcclib64.dll

$endif.bld

$if not errorfree $abort Error initializing extrinsic library myLib: aborting

function cdf1  'CDF of univariate normal' / myLib.cdfUVN /;

sets
  i / i1 * i5 /
  k / want, got /
  ;
parameter
  x(i) /
   i1  -50
   i2  -1
   i3  eps
   i4  1
   i5  50
  /,
  f_(i) /
   i1  eps
   i2  .1586552539314570
   i3  .5
   i4  .8413447460685429
   i5  1.0
  /,
  g_(i) /
   i1  eps
   i2  .2419707245191433
   i3  .3989422804014327
   i4  .2419707245191433
   i5  eps
  /,
  h_(i) /
   i1  eps
   i2   0.241970724519143
   i3  0
   i4  -0.241970724519143
   i5  eps
  /,
  v(i), d(i);

v(i) = cdf1(x(i)) + eps;
d(i) = abs(v(i)-f_(i));
abort$[smax{i, d(i)} > 1e-14] 'bad function values', d, v, f_;

v(i) = cdf1.grad(x(i)) + eps;
d(i) = abs(v(i)-g_(i));
abort$[smax{i, d(i)} > 1e-14] 'bad gradient values', d, v, g_;

v(i) = cdf1.hess(x(i)) + eps;
d(i) = abs(v(i)-h_(i));
abort$[smax{i, d(i)} > 1e-13] 'bad Hessian values', d, v, h_;

$log CPP Library test passed for platform %system.buildcode%