|
Prev | Next | a_double_cond_assign_xam.m | Headings |
function ok = a_double_cond_assign_xam()
%
% load the Cppad Swig library
m_cppad
%
% initialize return variable
ok = true;
% -----------------------------------------------------------------------
n_ind = 4;
n_dep = 1;
%
% create ax (value of independent variables does not matter)
x = m_cppad.vec_double(n_ind);
x(0) = 0.0;
x(1) = 1.0;
x(2) = 2.0;
x(3) = 3.0;
ax = m_cppad.independent(x);
%
% arguments to conditional assignment
left = ax(0);
right = ax(1);
if_true = ax(2);
if_false = ax(3);
%
% assignment
target = m_cppad.a_double();
target.cond_assign(
"<",
left,
right,
if_true,
if_false
);
%
% f(x) = taget
ay = m_cppad.vec_a_double(n_dep);
ay(0) = target;
af = m_cppad.a_fun(ax, ay);
%
% assignment with different independent variable values
x(0) = 9.0; % left
x(1) = 8.0; % right
x(2) = 7.0; % if_true
x(3) = 6.0; % if_false
p = 0;
y = af.forward(p, x);
ok = ok && y(0) == 6.0;
%
return;
end