Prev Next a_fun_abort_xam.pm Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Perl: Abort Recording a_double Operations: Example and Test
package a_fun_abort_xam;
sub a_fun_abort_xam() {
     # check for standard perl programming conventions
     use strict;
     use warnings;
     #
     # load the Cppad Swig library
     use pm_cppad;
     #
     # initilaize return variable
     my $ok = 1;
     # ---------------------------------------------------------------------
     my $n_ind = 2;
     #
     # create ax
     my $x = new pm_cppad::vec_double($n_ind);
     for(my $i = 0; $i < $n_ind ; $i++) {
          $x->set($i, $i + 1.0);
     }
     my $ax = pm_cppad::independent($x);
     #
     # preform some a_double operations
     my $ax0 = $ax->get(0);
     my $ax1 = $ax->get(1);
     my $ay = $ax0 + $ax1;
     #
     # check that ay is a variable; its value depends on the value of ax
     $ok = $ok && $ay->variable();
     #
     # abort this recording
     pm_cppad::abort_recording();
     #
     # check that ay is now a parameter, no longer a variable.
     $ok = $ok && $ay->parameter();
     #
     # since it is a parameter, we can retrieve its value
     my $y = $ay->value();
     #
     # its value should be x0 + x1
     $ok = $ok && $y  == $x->get(0) + $x->get(1);
     #
     # an abort when not recording has no effect
     pm_cppad::abort_recording();
     #
     return( $ok );
}

Input File: build/lib/example/perl/a_fun_abort_xam.pm