![]() |
Prev | Next | quadratic_ok.hpp | Headings |
# ifndef CPPAD_SPARSE_QUAD_INCLUDED
# define CPPAD_SPARSE_QUAD_INCLUDED
# include <cppad/near_equal.hpp>
namespace CppAD {
inline bool quadratic_ok(
const size_t n ,
const CppAD::vector<size_t> &i ,
const CppAD::vector<size_t> &j ,
const CppAD::vector<double> &x ,
const size_t m ,
const CppAD::vector<double> &fm )
{ bool ok = true;
using CppAD::NearEqual;
size_t k, size = 1;
for(k = 0; k < m; k++)
size *= n;
CppAD::vector<double> check(size);
for(k = 0; k < size; k++)
check[k] = 0.;
size_t ell = i.size();
for(k = 0; k < ell; k++)
{
switch(m)
{ case 0:
check[0] += x[i[k]] * x[j[k]];
break;
case 1:
check[i[k]] += x[j[k]];
check[j[k]] += x[i[k]];
break;
case 2:
check[i[k] * n + j[k]] += 1.;
check[j[k] * n + i[k]] += 1.;
break;
}
}
for(k = 0; k < size; k++)
ok &= NearEqual(fm[k], check[k], 1e-10, 1e-10);
return ok;
}
}
# endif