1 #ifndef CPPAD_CG_GENERIC_MODEL_INCLUDED
2 #define CPPAD_CG_GENERIC_MODEL_INCLUDED
30 CGAtomicGenericModel<Base>* _atomic;
32 bool _evalAtomicForwardOne4CppAD;
37 _evalAtomicForwardOne4CppAD(true) {
40 inline virtual ~GenericModel() {
49 virtual const std::string&
getName()
const = 0;
60 virtual std::vector<std::set<size_t> > JacobianSparsitySet() = 0;
61 virtual std::vector<bool> JacobianSparsityBool() = 0;
62 virtual void JacobianSparsity(std::vector<size_t>& equations,
63 std::vector<size_t>& variables) = 0;
81 virtual std::vector<bool> HessianSparsityBool() = 0;
82 virtual void HessianSparsity(std::vector<size_t>& rows,
83 std::vector<size_t>& cols) = 0;
101 virtual std::vector<bool> HessianSparsityBool(
size_t i) = 0;
102 virtual void HessianSparsity(
size_t i,
103 std::vector<size_t>& rows,
104 std::vector<size_t>& cols) = 0;
111 virtual size_t Domain()
const = 0;
118 virtual size_t Range()
const = 0;
165 _evalAtomicForwardOne4CppAD = evalForwardOne4CppAD;
168 inline bool isAtomicEvalForwardOne4CppAD()
const {
169 return _evalAtomicForwardOne4CppAD;
193 template<
typename VectorBase>
195 VectorBase dep(
Range());
215 template<
typename VectorBase>
236 virtual void ForwardZero(
const std::vector<const Base*> &x,
251 template<
typename VectorBase>
252 inline VectorBase Jacobian(
const VectorBase& x) {
259 template<
typename VectorBase>
260 inline void Jacobian(
const VectorBase& x,
263 Jacobian(ArrayView<const Base>(&x[0], x.size()),
264 ArrayView<Base>(&jac[0], jac.size()));
267 virtual void Jacobian(ArrayView<const Base> x,
268 ArrayView<Base> jac) = 0;
283 template<
typename VectorBase>
284 inline VectorBase Hessian(
const VectorBase& x,
285 const VectorBase& w) {
287 this->Hessian(ArrayView<const Base>(&x[0], x.size()),
288 ArrayView<const Base>(&w[0], w.size()),
289 ArrayView<Base>(&hess[0], hess.size()));
293 template<
typename VectorBase>
294 inline void Hessian(
const VectorBase& x,
298 this->Hessian(ArrayView<const Base>(&x[0], x.size()),
299 ArrayView<const Base>(&w[0], w.size()),
300 ArrayView<Base>(&hess[0], hess.size()));
305 template<
typename VectorBase>
306 inline VectorBase
Hessian(
const VectorBase& x,
308 CPPADCG_ASSERT_KNOWN(i <
Range(),
"Invalid equation index")
310 VectorBase w(
Range());
347 template<
typename VectorBase>
351 VectorBase ty((k + 1) * m);
357 for (
size_t i = 0; i < m; i++) {
358 dy[i] = ty[i * (k + 1) + k];
406 size_t tx1Nnz,
const size_t idx[],
const Base tx1[],
429 template<
typename VectorBase>
431 const VectorBase& ty,
432 const VectorBase& py) {
434 VectorBase px((k + 1) *
Domain());
446 template<
typename VectorBase>
448 const VectorBase& ty,
450 const VectorBase& py) {
497 size_t pyNnz,
const size_t idx[],
const Base py[]) = 0;
520 template<
typename VectorBase>
522 const VectorBase& ty,
523 const VectorBase& py) {
525 VectorBase px((k + 1) *
Domain());
538 template<
typename VectorBase>
540 const VectorBase& ty,
542 const VectorBase& py) {
590 size_t tx1Nnz,
const size_t idx[],
const Base tx1[],
615 template<
typename VectorBase>
632 template<
typename VectorBase>
653 std::vector<Base>& jac,
654 std::vector<size_t>& row,
655 std::vector<size_t>& col) = 0;
660 size_t const** col) = 0;
677 size_t const** col) = 0;
692 template<
typename VectorBase>
693 inline VectorBase SparseHessian(
const VectorBase& x,
694 const VectorBase& w) {
702 template<
typename VectorBase>
703 inline void SparseHessian(
const VectorBase& x,
707 SparseHessian(ArrayView<const Base>(&x[0], x.size()),
708 ArrayView<const Base>(&w[0], w.size()),
709 ArrayView<Base>(&hess[0], hess.size()));
712 virtual void SparseHessian(ArrayView<const Base> x,
713 ArrayView<const Base> w,
714 ArrayView<Base> hess) = 0;
716 virtual void SparseHessian(
const std::vector<Base> &x,
717 const std::vector<Base> &w,
718 std::vector<Base>& hess,
719 std::vector<size_t>& row,
720 std::vector<size_t>& col) = 0;
722 virtual void SparseHessian(ArrayView<const Base> x,
723 ArrayView<const Base> w,
724 ArrayView<Base> hess,
726 size_t const** col) = 0;
742 virtual void SparseHessian(
const std::vector<const Base*>& x,
743 ArrayView<const Base> w,
744 ArrayView<Base> hess,
746 size_t const** col) = 0;
756 if (_atomic ==
nullptr) {