diff --git a/external/apktool/apktool b/external/apktool/apktool deleted file mode 100755 index e99086b91..000000000 --- a/external/apktool/apktool +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2007 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This script is a wrapper for smali.jar, so you can simply call "smali", -# instead of java -jar smali.jar. It is heavily based on the "dx" script -# from the Android SDK - -# Set up prog to be the path of this script, including following symlinks, -# and set up progdir to be the fully-qualified pathname of its directory. -prog="$0" -while [ -h "${prog}" ]; do - newProg=`/bin/ls -ld "${prog}"` - - newProg=`expr "${newProg}" : ".* -> \(.*\)$"` - if expr "x${newProg}" : 'x/' >/dev/null; then - prog="${newProg}" - else - progdir=`dirname "${prog}"` - prog="${progdir}/${newProg}" - fi -done -oldwd=`pwd` -progdir=`dirname "${prog}"` -cd "${progdir}" -progdir=`pwd` -prog="${progdir}"/`basename "${prog}"` -cd "${oldwd}" - -jarfile=apktool.jar -libdir="$progdir" -if [ ! -r "$libdir/$jarfile" ] -then - echo `basename "$prog"`": can't find $jarfile" - exit 1 -fi - -javaOpts="" - -# If you want DX to have more memory when executing, uncomment the following -# line and adjust the value accordingly. Use "java -X" for a list of options -# you can pass here. -# -javaOpts="-Xmx512M -Dfile.encoding=utf-8" - -# Alternatively, this will extract any parameter "-Jxxx" from the command line -# and pass them to Java (instead of to dx). This makes it possible for you to -# add a command-line parameter such as "-JXmx256M" in your ant scripts, for -# example. -while expr "x$1" : 'x-J' >/dev/null; do - opt=`expr "$1" : '-J\(.*\)'` - javaOpts="${javaOpts} -${opt}" - shift -done - -if [ "$OSTYPE" = "cygwin" ] ; then - jarpath=`cygpath -w "$libdir/$jarfile"` -else - jarpath="$libdir/$jarfile" -fi - -# add current location to path for aapt -PATH=$PATH:`pwd`; -export PATH; -exec java $javaOpts -jar "$jarpath" "$@" \ No newline at end of file diff --git a/external/apktool/apktool.jar b/external/apktool/apktool.jar deleted file mode 120000 index 566a437af..000000000 --- a/external/apktool/apktool.jar +++ /dev/null @@ -1 +0,0 @@ -apktool_2.3.0.jar \ No newline at end of file diff --git a/external/apktool/apktool_2.3.0.jar b/external/apktool/apktool_2.3.0.jar deleted file mode 100644 index bb9003ec4..000000000 Binary files a/external/apktool/apktool_2.3.0.jar and /dev/null differ diff --git a/external/cppad/build.txt b/external/cppad/build.txt deleted file mode 100644 index 5e9181b4a..000000000 --- a/external/cppad/build.txt +++ /dev/null @@ -1,7 +0,0 @@ -wget 'http://www.coin-or.org/download/source/CppAD/cppad-20170816.epl.tgz' -tar xvf cppad-20170816.epl.tgz -cd cppad-20170816/ -mkdir build -cd build -cmake -D cppad_prefix="$HOME/one/external/cppad" .. -make install diff --git a/external/cppad/include/cppad/base_require.hpp b/external/cppad/include/cppad/base_require.hpp deleted file mode 100644 index 1c02a9699..000000000 --- a/external/cppad/include/cppad/base_require.hpp +++ /dev/null @@ -1,185 +0,0 @@ -// $Id: base_require.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_BASE_REQUIRE_HPP -# define CPPAD_BASE_REQUIRE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin base_require$$ -$spell - azmul - ostream - alloc - eps - std - Lt - Le - Eq - Ge - Gt - cppad.hpp - namespace - optimizations - bool - const - CppAD - enum - Lt - Le - Eq - Ge - Gt - inline - Op - std - CondExp -$$ - -$section AD Requirements for a CppAD Base Type$$ - -$head Syntax$$ -$code # include $$ - -$head Purpose$$ -This section lists the requirements for the type -$icode Base$$ so that the type $codei%AD<%Base%>%$$ can be used. - -$head API Warning$$ -Defining a CppAD $icode Base$$ type is an advanced use of CppAD. -This part of the CppAD API changes with time. The most common change -is adding more requirements. -Search for $code base_require$$ in the -current $cref whats_new$$ section for these changes. - -$head Standard Base Types$$ -In the case where $icode Base$$ is -$code float$$, -$code double$$, -$code std::complex$$, -$code std::complex$$, -or $codei%AD<%Other%>%$$, -these requirements are provided by including the file -$code cppad/cppad.hpp$$. - -$head Include Order$$ -If you are linking a non-standard base type to CppAD, -you must first include the file $code cppad/base_require.hpp$$, -then provide the specifications below, -and then include the file $code cppad/cppad.hpp$$. - -$head Numeric Type$$ -The type $icode Base$$ must support all the operations for a -$cref NumericType$$. - -$head Output Operator$$ -The type $icode Base$$ must support the syntax -$codei% - %os% << %x% -%$$ -where $icode os$$ is an $code std::ostream&$$ -and $icode x$$ is a $code const base_alloc&$$. -For example, see -$cref/base_alloc/base_alloc.hpp/Output Operator/$$. - -$head Integer$$ -The type $icode Base$$ must support the syntax -$codei% - %i% = CppAD::Integer(%x%) -%$$ -which converts $icode x$$ to an $code int$$. -The argument $icode x$$ has prototype -$codei% - const %Base%& %x% -%$$ -and the return value $icode i$$ has prototype -$codei% - int %i% -%$$ - -$subhead Suggestion$$ -In many cases, the $icode Base$$ version of the $code Integer$$ function -can be defined by -$codei% -namespace CppAD { - inline int Integer(const %Base%& x) - { return static_cast(x); } -} -%$$ -For example, see -$cref/base_float/base_float.hpp/Integer/$$ and -$cref/base_alloc/base_alloc.hpp/Integer/$$. - -$head Absolute Zero, azmul$$ -The type $icode Base$$ must support the syntax -$codei% - %z% = azmul(%x%, %y%) -%$$ -see; $cref azmul$$. -The following preprocessor macro invocation suffices -(for most $icode Base$$ types): -$codei% -namespace CppAD { - CPPAD_AZMUL(%Base%) -} -%$$ -where the macro is defined by -$srccode%cpp% */ -# define CPPAD_AZMUL(Base) \ - inline Base azmul(const Base& x, const Base& y) \ - { Base zero(0.0); \ - if( x == zero ) \ - return zero; \ - return x * y; \ - } -/* %$$ - -$childtable% - omh/base_require/base_member.omh% - cppad/core/base_cond_exp.hpp% - omh/base_require/base_identical.omh% - omh/base_require/base_ordered.omh% - cppad/core/base_std_math.hpp% - cppad/core/base_limits.hpp% - cppad/core/base_to_string.hpp% - cppad/core/base_hash.hpp% - omh/base_require/base_example.omh -%$$ - -$end -*/ - -// definitions that must come before base implementations -# include -# include -# include -# include - -// grouping documentation by feature -# include -# include -# include -# include -# include - -// must define template class numeric_limits before the base cases -# include -# include // deprecated - -// base cases that come with CppAD -# include -# include -# include - -// deprecated base type -# include - -# endif diff --git a/external/cppad/include/cppad/configure.hpp b/external/cppad/include/cppad/configure.hpp deleted file mode 100644 index 26cf15a63..000000000 --- a/external/cppad/include/cppad/configure.hpp +++ /dev/null @@ -1,216 +0,0 @@ -# ifndef CPPAD_CONFIGURE_HPP -# define CPPAD_CONFIGURE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/*! - \file configure.hpp -Replacement for config.h so that all preprocessor symbols begin with CPPAD_ -*/ - -/*! -\def CPPAD_COMPILER_IS_GNUCXX -is the compiler a variant of g++ -*/ -# define CPPAD_COMPILER_IS_GNUCXX 1 - -/*! -\def CPPAD_DISABLE_SOME_MICROSOFT_COMPILER_WARNINGS -This macro is only used to document the pragmas that disables the -follow warnings: - -\li C4100 -unreferenced formal parameter. -\li C4127 -conditional expression is constant. -*/ -# define CPPAD_DISABLE_SOME_MICROSOFT_COMPILER_WARNINGS 1 -# if _MSC_VER -# pragma warning( disable : 4100 ) -# pragma warning( disable : 4127 ) -# endif -# undef CPPAD_DISABLE_SOME_MICROSOFT_COMPILER_WARNINGS - -/*! -\def CPPAD_USE_CPLUSPLUS_2011 -Should CppAD use C++11 features. This will be true if the current -compiler flags request C++11 features and the install procedure -determined that all the necessary features are avaiable. -*/ -# if _MSC_VER -# define CPPAD_USE_CPLUSPLUS_2011 0 -# else // -# if __cplusplus >= 201100 -# define CPPAD_USE_CPLUSPLUS_2011 0 -# else // -# define CPPAD_USE_CPLUSPLUS_2011 0 -# endif // -# endif // - -/*! -\def CPPAD_PACKAGE_STRING -cppad-yyyymmdd as a C string where yyyy is year, mm is month, and dd is day. -*/ -# define CPPAD_PACKAGE_STRING "cppad-20170816" - -/*! -def CPPAD_HAS_ADOLC -Was a adolc_prefix specified on the cmake command line. -*/ -# define CPPAD_HAS_ADOLC 0 - -/*! -def CPPAD_HAS_COLPACK -Was a colpack_prefix specified on the cmake command line. -*/ -# define CPPAD_HAS_COLPACK 0 - -/*! -def CPPAD_HAS_EIGEN -Was a eigen_prefix specified on the cmake command line. -*/ -# define CPPAD_HAS_EIGEN 0 - -/*! -def CPPAD_HAS_IPOPT -Was a ipopt_prefix specified on the cmake command line. -*/ -# define CPPAD_HAS_IPOPT 0 - -/*! -\def CPPAD_DEPRECATED -This symbol is not currently being used. -*/ -# define CPPAD_DEPRECATED 0 - -/*! -\def CPPAD_BOOSTVECTOR -If this symbol is one, and _MSC_VER is not defined, -we are using boost vector for CPPAD_TESTVECTOR. -It this symbol is zero, -we are not using boost vector for CPPAD_TESTVECTOR. -*/ -# define CPPAD_BOOSTVECTOR 0 - -/*! -\def CPPAD_CPPADVECTOR -If this symbol is one, -we are using CppAD vector for CPPAD_TESTVECTOR. -It this symbol is zero, -we are not using CppAD vector for CPPAD_TESTVECTOR. -*/ -# define CPPAD_CPPADVECTOR 1 - -/*! -\def CPPAD_STDVECTOR -If this symbol is one, -we are using standard vector for CPPAD_TESTVECTOR. -It this symbol is zero, -we are not using standard vector for CPPAD_TESTVECTOR. -*/ -# define CPPAD_STDVECTOR 0 - -/*! -\def CPPAD_EIGENVECTOR -If this symbol is one, -we are using Eigen vector for CPPAD_TESTVECTOR. -If this symbol is zero, -we are not using Eigen vector for CPPAD_TESTVECTOR. -*/ -# define CPPAD_EIGENVECTOR 0 - -/*! -\def CPPAD_HAS_GETTIMEOFDAY -If this symbol is one, and _MSC_VER is not defined, -this system supports the gettimeofday funcgtion. -Otherwise, this smybol should be zero. -*/ -# define CPPAD_HAS_GETTIMEOFDAY 1 - -/*! -\def CPPAD_SIZE_T_NOT_UNSIGNED_INT -If this symbol is zero, the type size_t is the same as the type unsigned int, -otherwise this symbol is one. -*/ -# define CPPAD_SIZE_T_NOT_UNSIGNED_INT 1 - -/*! -\def CPPAD_TAPE_ADDR_TYPE -Is the type used to store address on the tape. If not size_t, then -sizeof(CPPAD_TAPE_ADDR_TYPE) <= sizeof( size_t ) -to conserve memory. -This type must support \c std::numeric_limits, -the \c <= operator, -and conversion to \c size_t. -Make sure that the type chosen returns true for is_pod -in pod_vector.hpp. -This type is later defined as \c addr_t in the CppAD namespace. -*/ -# define CPPAD_TAPE_ADDR_TYPE unsigned int - -/*! -\def CPPAD_TAPE_ID_TYPE -Is the type used to store tape identifiers. If not size_t, then -sizeof(CPPAD_TAPE_ID_TYPE) <= sizeof( size_t ) -to conserve memory. -This type must support \c std::numeric_limits, -the \c <= operator, -and conversion to \c size_t. -Make sure that the type chosen returns true for is_pod -in pod_vector.hpp. -This type is later defined as \c tape_id_t in the CppAD namespace. -*/ -# define CPPAD_TAPE_ID_TYPE unsigned int - -/*! -\def CPPAD_MAX_NUM_THREADS -Specifies the maximum number of threads that CppAD can support -(must be greater than or equal four). - -The user may define CPPAD_MAX_NUM_THREADS before including any of the CppAD -header files. If it is not yet defined, -*/ -# ifndef CPPAD_MAX_NUM_THREADS -# define CPPAD_MAX_NUM_THREADS 48 -# endif - -/*! -\def CPPAD_HAS_MKSTEMP -It true, mkstemp works in C++ on this system. -*/ -# define CPPAD_HAS_MKSTEMP 1 - -/*! -\def CPPAD_HAS_TMPNAM_S -It true, tmpnam_s works in C++ on this system. -*/ -# define CPPAD_HAS_TMPNAM_S 0 - -// --------------------------------------------------------------------------- -// defines that only depend on values above -// --------------------------------------------------------------------------- -/*! -\def CPPAD_NULL -This preprocessor symbol is used for a null pointer. - -If it is not yet defined, -it is defined when cppad/core/define.hpp is included. -*/ -# ifndef CPPAD_NULL -# if CPPAD_USE_CPLUSPLUS_2011 -# define CPPAD_NULL nullptr -# else -# define CPPAD_NULL 0 -# endif -# endif - -# endif diff --git a/external/cppad/include/cppad/core/abort_recording.hpp b/external/cppad/include/cppad/core/abort_recording.hpp deleted file mode 100644 index 19938b0c4..000000000 --- a/external/cppad/include/cppad/core/abort_recording.hpp +++ /dev/null @@ -1,60 +0,0 @@ -# ifndef CPPAD_CORE_ABORT_RECORDING_HPP -# define CPPAD_CORE_ABORT_RECORDING_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin abort_recording$$ -$spell -$$ - -$section Abort Recording of an Operation Sequence$$ -$mindex tape$$ - - -$head Syntax$$ -$codei%AD<%Base%>::abort_recording()%$$ - -$head Purpose$$ -Sometimes it is necessary to abort the recording of an operation sequence -that started with a call of the form -$codei% - Independent(%x%) -%$$ -If such a recording is currently in progress, -$code abort_recording$$ will stop the recording and delete the -corresponding information. -Otherwise, $code abort_recording$$ has no effect. - -$children% - example/general/abort_recording.cpp -%$$ -$head Example$$ -The file -$cref abort_recording.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ----------------------------------------------------------------------------- -*/ - - -namespace CppAD { - template - void AD::abort_recording(void) - { local::ADTape* tape = AD::tape_ptr(); - if( tape != CPPAD_NULL ) - AD::tape_manage(tape_manage_delete); - } -} - -# endif diff --git a/external/cppad/include/cppad/core/abs.hpp b/external/cppad/include/cppad/core/abs.hpp deleted file mode 100644 index 11c2e17c2..000000000 --- a/external/cppad/include/cppad/core/abs.hpp +++ /dev/null @@ -1,114 +0,0 @@ -# ifndef CPPAD_CORE_ABS_HPP -# define CPPAD_CORE_ABS_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin abs$$ -$spell - fabs - Vec - std - faq - Taylor - Cpp - namespace - const - abs -$$ - -$section AD Absolute Value Functions: abs, fabs$$ - -$head Syntax$$ -$icode%y% = abs(%x%) -%$$ -$icode%y% = fabs(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -In the case where $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Complex Types$$ -The functions $code abs$$ and $icode fabs$$ -are not defined for the base types -$code std::complex$$ or $code std::complex$$ -because the complex $code abs$$ function is not complex differentiable -(see $cref/complex types faq/Faq/Complex Types/$$). - -$head Derivative$$ -CppAD defines the derivative of the $code abs$$ function is -the $cref sign$$ function; i.e., -$latex \[ -{\rm abs}^{(1)} ( x ) = {\rm sign} (x ) = -\left\{ \begin{array}{rl} - +1 & {\rm if} \; x > 0 \\ - 0 & {\rm if} \; x = 0 \\ - -1 & {\rm if} \; x < 0 -\end{array} \right. -\] $$ -The result for $icode%x% == 0%$$ used to be a directional derivative. - -$head Example$$ -$children% - example/general/fabs.cpp -%$$ -The file -$cref fabs.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD AD::abs_me (void) const -{ - AD result; - result.value_ = abs(value_); - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - if( Variable(*this) ) - { // add this operation to the tape - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AbsOp) == 1 ); - local::ADTape *tape = tape_this(); - - // corresponding operand address - tape->Rec_.PutArg(taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::AbsOp); - // make result a variable - result.tape_id_ = tape->id_; - } - return result; -} - -template -inline AD abs(const AD &x) -{ return x.abs_me(); } - -template -inline AD abs(const VecAD_reference &x) -{ return x.ADBase().abs_me(); } - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/abs_normal_fun.hpp b/external/cppad/include/cppad/core/abs_normal_fun.hpp deleted file mode 100644 index f974046ca..000000000 --- a/external/cppad/include/cppad/core/abs_normal_fun.hpp +++ /dev/null @@ -1,867 +0,0 @@ -# ifndef CPPAD_CORE_ABS_NORMAL_FUN_HPP -# define CPPAD_CORE_ABS_NORMAL_FUN_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin abs_normal_fun$$ -$spell - const -$$ - - -$section Create An Abs-normal Representation of a Function$$ - -$head Syntax$$ -$icode%f%.abs_normal_fun(%g%, %a%)%$$ - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%>& %f% -%$$ -It represents a function $latex f : \B{R}^n \rightarrow \B{R}^m$$. -We assume that the only non-smooth terms in the representation are -absolute value functions and use $latex s \in \B{Z}_+$$ -to represent the number of these terms. -It is effectively $code const$$, except that some internal state -that is not relevant to the user; see -$cref/const ADFun/wish_list/const ADFun/$$. - -$subhead n$$ -We use $icode n$$ to denote the dimension of the domain space for $icode f$$. - -$subhead m$$ -We use $icode m$$ to denote the dimension of the range space for $icode f$$. - -$subhead s$$ -We use $icode s$$ to denote the number of absolute value terms in $icode f$$. - - -$head a$$ -The object $icode a$$ has prototype -$codei% - ADFun<%Base%> %a% -%$$ -The initial function representation in $icode a$$ is lost. -Upon return it represents the result of the absolute terms -$latex a : \B{R}^n \rightarrow \B{R}^s$$; see $latex a(x)$$ defined below. -Note that $icode a$$ is constructed by copying $icode f$$ -and then changing the dependent variables. There may -be many calculations in this representation that are not necessary -and can be removed using -$codei% - %a%.optimize() -%$$ -This optimization is not done automatically by $code abs_normal_fun$$ -because it may take a significant amount of time. - -$subhead zeta$$ -Let $latex \zeta_0 ( x )$$ -denote the argument for the first absolute value term in $latex f(x)$$, -$latex \zeta_1 ( x , |\zeta_0 (x)| )$$ for the second term, and so on. - -$subhead a(x)$$ -For $latex i = 0 , \ldots , {s-1}$$ define -$latex \[ -a_i (x) -= -| \zeta_i ( x , a_0 (x) , \ldots , a_{i-1} (x ) ) | -\] $$ -This defines $latex a : \B{R}^n \rightarrow \B{R}^s$$. - -$head g$$ -The object $icode g$$ has prototype -$codei% - ADFun<%Base%> %g% -%$$ -The initial function representation in $icode g$$ is lost. -Upon return it represents the smooth function -$latex g : \B{R}^{n + s} \rightarrow \B{R}^{m + s}$$ is defined by -$latex \[ -g( x , u ) -= -\left[ \begin{array}{c} y(x, u) \\ z(x, u) \end{array} \right] -\] $$ -were $latex y(x, u)$$ and $latex z(x, u)$$ are defined below. - -$subhead z(x, u)$$ -Define the smooth function -$latex z : \B{R}^{n + s} \rightarrow \B{R}^s$$ by -$latex \[ -z_i ( x , u ) = \zeta_i ( x , u_0 , \ldots , u_{i-1} ) -\] $$ -Note that the partial of $latex z_i$$ with respect to $latex u_j$$ is zero -for $latex j \geq i$$. - -$subhead y(x, u)$$ -There is a smooth function -$latex y : \B{R}^{n + s} \rightarrow \B{R}^m$$ -such that $latex y( x , u ) = f(x)$$ whenever $latex u = a(x)$$. - -$head Affine Approximation$$ -We define the affine approximations -$latex \[ -\begin{array}{rcl} -y[ \hat{x} ]( x , u ) -& = & -y ( \hat{x}, a( \hat{x} ) ) - + \partial_x y ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) - + \partial_u y ( \hat{x}, a( \hat{x} ) ) ( u - a( \hat{x} ) ) -\\ -z[ \hat{x} ]( x , u ) -& = & -z ( \hat{x}, a( \hat{x} ) ) - + \partial_x z ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) - + \partial_u z ( \hat{x}, a( \hat{x} ) ) ( u - a( \hat{x} ) ) -\end{array} -\] $$ -It follows that -$latex \[ -\begin{array}{rcl} -y( x , u ) -& = & -y[ \hat{x} ]( x , u ) + o ( x - \hat{x}, u - a( \hat{x} ) ) -\\ -z( x , u ) -& = & -z[ \hat{x} ]( x , u ) + o ( x - \hat{x}, u - a( \hat{x} ) ) -\end{array} -\] $$ - -$head Abs-normal Approximation$$ - -$subhead Approximating a(x)$$ -The function $latex a(x)$$ is not smooth, but it is equal to -$latex | z(x, u) |$$ when $latex u = a(x)$$. -Furthermore -$latex \[ -z[ \hat{x} ]( x , u ) -= -z ( \hat{x}, a( \hat{x} ) ) - + \partial_x z ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) - + \partial_u z ( \hat{x}, a( \hat{x} ) ) ( u - a( \hat{x} ) ) -\] $$ -The partial of $latex z_i$$ with respect to $latex u_j$$ is zero -for $latex j \geq i$$. It follows that -$latex \[ -z_i [ \hat{x} ]( x , u ) -= -z_i ( \hat{x}, a( \hat{x} ) ) - + \partial_x z_i ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) - + \sum_{j < i} \partial_{u(j)} - z_i ( \hat{x}, a( \hat{x} ) ) ( u_j - a_j ( \hat{x} ) ) -\] $$ -Considering the case $latex i = 0$$ we define -$latex \[ -a_0 [ \hat{x} ]( x ) -= -| z_0 [ \hat{x} ]( x , u ) | -= -\left| - z_0 ( \hat{x}, a( \hat{x} ) ) - + \partial_x z_0 ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) -\right| -\] $$ -It follows that -$latex \[ - a_0 (x) = a_0 [ \hat{x} ]( x ) + o ( x - \hat{x} ) -\] $$ -In general, we define $latex a_i [ \hat{x} ]$$ using -$latex a_j [ \hat{x} ]$$ for $latex j < i$$ as follows: -$latex \[ -a_i [ \hat{x} ]( x ) -= -\left | - z_i ( \hat{x}, a( \hat{x} ) ) - + \partial_x z_i ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) - + \sum_{j < i} \partial_{u(j)} - z_i ( \hat{x}, a( \hat{x} ) ) - ( a_j [ \hat{x} ] ( x ) - a_j ( \hat{x} ) ) -\right| -\] $$ -It follows that -$latex \[ - a (x) = a[ \hat{x} ]( x ) + o ( x - \hat{x} ) -\] $$ -Note that in the case where $latex z(x, u)$$ and $latex y(x, u)$$ are -affine, -$latex \[ - a[ \hat{x} ]( x ) = a( x ) -\] $$ - - -$subhead Approximating f(x)$$ -$latex \[ -f(x) -= -y ( x , a(x ) ) -= -y [ \hat{x} ] ( x , a[ \hat{x} ] ( x ) ) -+ o( \Delta x ) -\] $$ - -$head Correspondence to Literature$$ -Using the notation -$latex Z = \partial_x z(\hat{x}, \hat{u})$$, -$latex L = \partial_u z(\hat{x}, \hat{u})$$, -$latex J = \partial_x y(\hat{x}, \hat{u})$$, -$latex Y = \partial_u y(\hat{x}, \hat{u})$$, -the approximation for $latex z$$ and $latex y$$ are -$latex \[ -\begin{array}{rcl} -z[ \hat{x} ]( x , u ) -& = & -z ( \hat{x}, a( \hat{x} ) ) + Z ( x - \hat{x} ) + L ( u - a( \hat{x} ) ) -\\ -y[ \hat{x} ]( x , u ) -& = & -y ( \hat{x}, a( \hat{x} ) ) + J ( x - \hat{x} ) + Y ( u - a( \hat{x} ) ) -\end{array} -\] $$ -Moving the terms with $latex \hat{x}$$ together, we have -$latex \[ -\begin{array}{rcl} -z[ \hat{x} ]( x , u ) -& = & -z ( \hat{x}, a( \hat{x} ) ) - Z \hat{x} - L a( \hat{x} ) + Z x + L u -\\ -y[ \hat{x} ]( x , u ) -& = & -y ( \hat{x}, a( \hat{x} ) ) - J \hat{x} - Y a( \hat{x} ) + J x + Y u -\end{array} -\] $$ -Using the notation -$latex c = z ( \hat{x}, \hat{u} ) - Z \hat{x} - L \hat{u}$$, -$latex b = y ( \hat{x}, \hat{u} ) - J \hat{x} - Y \hat{u}$$, -we have -$latex \[ -\begin{array}{rcl} -z[ \hat{x} ]( x , u ) & = & c + Z x + L u -\\ -y[ \hat{x} ]( x , u ) & = & b + J x + Y u -\end{array} -\] $$ -Considering the affine case, where the approximations are exact, -and choosing $latex u = a(x) = |z(x, u)|$$, we obtain -$latex \[ -\begin{array}{rcl} -z( x , a(x ) ) & = & c + Z x + L |z( x , a(x ) )| -\\ -y( x , a(x ) ) & = & b + J x + Y |z( x , a(x ) )| -\end{array} -\] $$ -This is Equation (2) of the -$cref/reference/abs_normal/Reference/$$. - -$children%example/abs_normal/get_started.cpp -%$$ -$head Example$$ -The file $cref abs_get_started.cpp$$ contains -an example and test using this operation. - -$end -------------------------------------------------------------------------------- -*/ -/*! -file abs_normal_fun.hpp -Create an abs-normal representation of a function -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -Create an abs-normal representation of an ADFun object. - -\tparam Base -base type for this abs-normal form and for the function beging represented; -i.e., f. - -\param f -is the function that this object will represent in abs-normal form. -This is effectively const except that the play back state play_ -is used. -*/ - -# define NOT_YET_COMPILING 0 - -template -void ADFun::abs_normal_fun(ADFun& g, ADFun& a) -{ using namespace local; - - // ----------------------------------------------------------------------- - // Forward sweep to determine number of absolute value operations in f - // ----------------------------------------------------------------------- - // The argument and result index in f for each absolute value operator - CppAD::vector f_abs_arg; - CppAD::vector f_abs_res; - // - OpCode op; // this operator - const addr_t* arg = CPPAD_NULL; // arguments for this operator - size_t i_op; // index of this operator - size_t i_var; // variable index for this operator - play_.forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); - // - bool more_operators = true; - while( more_operators ) - { - // next op - play_.forward_next(op, arg, i_op, i_var); - switch( op ) - { // absolute value operator - case AbsOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - f_abs_arg.push_back( arg[0] ); - f_abs_res.push_back( i_var ); - break; - - case CSumOp: - // CSumOp has a variable number of arguments - play_.forward_csum(op, arg, i_op, i_var); - break; - - case CSkipOp: - // CSkip has a variable number of arguments - play_.forward_cskip(op, arg, i_op, i_var); - break; - - case EndOp: - more_operators = false; - break; - - default: - break; - } - } - // ------------------------------------------------------------------------ - // Forward sweep to create new recording - // ------------------------------------------------------------------------ - // recorder for new operation sequence - recorder rec; - // - // number of variables in both operation sequences - // (the AbsOp operators are replace by InvOp operators) - const size_t num_var = play_.num_var_rec(); - // - // mapping from old variable index to new variable index - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= num_var - ); - CppAD::vector f2g_var(num_var); - for(i_var = 0; i_var < num_var; i_var++) - f2g_var[i_var] = addr_t( num_var ); // invalid (should not be used) - // - // record the independent variables in f - play_.forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); - more_operators = true; - while( more_operators ) - { switch( op ) - { - // phantom variable - case BeginOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - CPPAD_ASSERT_UNKNOWN( arg[0] == 0 ); - rec.PutArg(0); - f2g_var[i_var] = rec.PutOp(op); - break; - - // independent variables - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - f2g_var[i_var] = rec.PutOp(op); - break; - - // end of independent variables - default: - more_operators = false; - break; - } - if( more_operators ) - play_.forward_next(op, arg, i_op, i_var); - } - // add one for the phantom variable - CPPAD_ASSERT_UNKNOWN( 1 + Domain() == i_var ); - // - // record the independent variables corresponding AbsOp results - size_t index_abs; - for(index_abs = 0; index_abs < f_abs_res.size(); index_abs++) - f2g_var[ f_abs_res[index_abs] ] = rec.PutOp(InvOp); - // - // used to hold new argument vector - addr_t new_arg[6]; - // - // Parameters in recording of f - const Base* f_parameter = play_.GetPar(); - // - // now loop through the rest of the - more_operators = true; - index_abs = 0; - while( more_operators ) - { addr_t mask; // temporary used in some switch cases - switch( op ) - { - // check setting of f_abs_arg and f_abs_res; - case AbsOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - CPPAD_ASSERT_UNKNOWN( f_abs_arg[index_abs] == arg[0] ); - CPPAD_ASSERT_UNKNOWN( f_abs_res[index_abs] == i_var ); - CPPAD_ASSERT_UNKNOWN( f2g_var[i_var] > 0 ); - ++index_abs; - break; - - // These operators come at beginning of take and are handled above - case InvOp: - CPPAD_ASSERT_UNKNOWN(false); - break; - - // --------------------------------------------------------------- - // Unary operators, argument a parameter, one result - case ParOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - new_arg[0] = rec.PutPar( f_parameter[ arg[0] ] ); - rec.PutArg( new_arg[0] ); - f2g_var[i_var] = rec.PutOp(op); - break; - - // -------------------------------------------------------------- - // Unary operators, argument a variable, one result - // (excluding the absolute value operator AbsOp) - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case TanOp: - case TanhOp: - // some of these operators have an auxillary result; e.g., - // sine and cosine are computed togeather. - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 || NumRes(op) == 2 ); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[0] ] ) < num_var ); - new_arg[0] = f2g_var[ arg[0] ]; - rec.PutArg( new_arg[0] ); - f2g_var[i_var] = rec.PutOp( op ); - break; - - case ErfOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 5); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[0] ] ) < num_var ); - // Error function is a special case - // second argument is always the parameter 0 - // third argument is always the parameter 2 / sqrt(pi) - rec.PutArg( rec.PutPar( Base(0.0) ) ); - rec.PutArg( rec.PutPar( - Base( 1.0 / std::sqrt( std::atan(1.0) ) ) - ) ); - f2g_var[i_var] = rec.PutOp(op); - break; - // -------------------------------------------------------------- - // Binary operators, left variable, right parameter, one result - case SubvpOp: - case DivvpOp: - case PowvpOp: - case ZmulvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[0] ] ) < num_var ); - new_arg[0] = f2g_var[ arg[0] ]; - new_arg[1] = rec.PutPar( f_parameter[ arg[1] ] ); - rec.PutArg( new_arg[0], new_arg[1] ); - f2g_var[i_var] = rec.PutOp(op); - break; - // --------------------------------------------------- - // Binary operators, left index, right variable, one result - case DisOp: - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - new_arg[0] = arg[0]; - new_arg[1] = f2g_var[ arg[1] ]; - rec.PutArg( new_arg[0], new_arg[1] ); - f2g_var[i_var] = rec.PutOp(op); - break; - - // -------------------------------------------------------------- - // Binary operators, left parameter, right variable, one result - case AddpvOp: - case SubpvOp: - case MulpvOp: - case DivpvOp: - case PowpvOp: - case ZmulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - new_arg[0] = rec.PutPar( f_parameter[ arg[0] ] ); - new_arg[1] = f2g_var[ arg[1] ]; - rec.PutArg( new_arg[0], new_arg[1] ); - f2g_var[i_var] = rec.PutOp(op); - break; - // -------------------------------------------------------------- - // Binary operators, left and right variables, one result - case AddvvOp: - case SubvvOp: - case MulvvOp: - case DivvvOp: - case ZmulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[0] ] ) < num_var ); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - new_arg[0] = f2g_var[ arg[0] ]; - new_arg[1] = f2g_var[ arg[1] ]; - rec.PutArg( new_arg[0], new_arg[1] ); - f2g_var[i_var] = rec.PutOp(op); - break; - // --------------------------------------------------- - // Conditional expression operators - case CExpOp: - CPPAD_ASSERT_NARG_NRES(op, 6, 1); - new_arg[0] = arg[0]; - new_arg[1] = arg[1]; - mask = 1; - for(size_t i = 2; i < 6; i++) - { if( arg[1] & mask ) - { CPPAD_ASSERT_UNKNOWN( size_t(f2g_var[arg[i]]) < num_var ); - new_arg[i] = f2g_var[ arg[i] ]; - } - else - new_arg[i] = rec.PutPar( f_parameter[ arg[i] ] ); - mask = mask << 1; - } - rec.PutArg( - new_arg[0] , - new_arg[1] , - new_arg[2] , - new_arg[3] , - new_arg[4] , - new_arg[5] - ); - f2g_var[i_var] = rec.PutOp(op); - break; - - // -------------------------------------------------- - // Operators with no arguments and no results - case EndOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - rec.PutOp(op); - more_operators = false; - break; - - // --------------------------------------------------- - // Operations with two arguments and no results - case LepvOp: - case LtpvOp: - case EqpvOp: - case NepvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - new_arg[0] = rec.PutPar( f_parameter[ arg[0] ] ); - new_arg[1] = f2g_var[ arg[1] ]; - rec.PutArg(new_arg[0], new_arg[1]); - rec.PutOp(op); - break; - // - case LevpOp: - case LtvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - new_arg[0] = f2g_var[ arg[0] ]; - new_arg[1] = rec.PutPar( f_parameter[ arg[1] ] ); - rec.PutArg(new_arg[0], new_arg[1]); - rec.PutOp(op); - break; - // - case LevvOp: - case LtvvOp: - case EqvvOp: - case NevvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - new_arg[0] = f2g_var[ arg[0] ]; - new_arg[1] = f2g_var[ arg[1] ]; - rec.PutArg(new_arg[0], new_arg[1]); - rec.PutOp(op); - break; - - // --------------------------------------------------- - // print forward operator - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - // - // arg[0] - new_arg[0] = arg[0]; - // - // arg[1] - if( arg[0] & 1 ) - { - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - new_arg[1] = f2g_var[ arg[1] ]; - } - else - { new_arg[1] = rec.PutPar( f_parameter[ arg[1] ] ); - } - // - // arg[3] - if( arg[0] & 2 ) - { - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[3] ] ) < num_var ); - new_arg[3] = f2g_var[ arg[3] ]; - } - else - { new_arg[3] = rec.PutPar( f_parameter[ arg[3] ] ); - } - new_arg[2] = rec.PutTxt( play_.GetTxt( arg[2] ) ); - new_arg[4] = rec.PutTxt( play_.GetTxt( arg[4] ) ); - // - rec.PutArg( - new_arg[0] , - new_arg[1] , - new_arg[2] , - new_arg[3] , - new_arg[4] - ); - // no result - rec.PutOp(op); - break; - - // --------------------------------------------------- - // VecAD operators - - // Load using a parameter index - case LdpOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 1); - new_arg[0] = arg[0]; - new_arg[1] = arg[1]; - new_arg[2] = arg[2]; - rec.PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - f2g_var[i_var] = rec.PutLoadOp(op); - break; - - // Load using a variable index - case LdvOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 1); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - new_arg[0] = arg[0]; - new_arg[1] = f2g_var[ arg[1] ]; - new_arg[2] = arg[2]; - rec.PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - f2g_var[i_var] = rec.PutLoadOp(op); - break; - - // Store a parameter using a parameter index - case StppOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - new_arg[0] = arg[0]; - new_arg[1] = rec.PutPar( f_parameter[ arg[1] ] ); - new_arg[2] = rec.PutPar( f_parameter[ arg[2] ] ); - rec.PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - rec.PutOp(op); - break; - - // Store a parameter using a variable index - case StvpOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - new_arg[0] = arg[0]; - new_arg[1] = f2g_var[ arg[1] ]; - new_arg[2] = rec.PutPar( f_parameter[ arg[2] ] ); - rec.PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - rec.PutOp(op); - break; - - // Store a variable using a parameter index - case StpvOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[2] ] ) < num_var ); - new_arg[0] = arg[0]; - new_arg[1] = rec.PutPar( f_parameter[ arg[1] ] ); - new_arg[2] = f2g_var[ arg[2] ]; - rec.PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - rec.PutOp(op); - break; - - // Store a variable using a variable index - case StvvOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[1] ] ) < num_var ); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[2] ] ) < num_var ); - new_arg[0] = arg[0]; - new_arg[1] = f2g_var[ arg[1] ]; - new_arg[2] = f2g_var[ arg[2] ]; - rec.PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - break; - - // ----------------------------------------------------------- - // user atomic function call operators - - case UserOp: - CPPAD_ASSERT_NARG_NRES(op, 4, 0); - // atomic_index, user_old, user_n, user_m - rec.PutArg(arg[0], arg[1], arg[2], arg[3]); - rec.PutOp(UserOp); - break; - - case UsrapOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - new_arg[0] = rec.PutPar( f_parameter[ arg[0] ] ); - rec.PutArg(new_arg[0]); - rec.PutOp(UsrapOp); - break; - - case UsravOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[arg[0]] ) < num_var ); - new_arg[0] = f2g_var[ arg[0] ]; - rec.PutArg(new_arg[0]); - rec.PutOp(UsravOp); - break; - - case UsrrpOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - new_arg[0] = rec.PutPar( f_parameter[ arg[0] ] ); - rec.PutArg(new_arg[0]); - rec.PutOp(UsrrpOp); - break; - - case UsrrvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - f2g_var[i_var] = rec.PutOp(UsrrvOp); - break; - // --------------------------------------------------- - - // all cases should be handled above - default: - CPPAD_ASSERT_UNKNOWN(false); - } - if( more_operators ) - play_.forward_next(op, arg, i_op, i_var); - } - // Check a few expected results - CPPAD_ASSERT_UNKNOWN( rec.num_op_rec() == play_.num_op_rec() ); - CPPAD_ASSERT_UNKNOWN( rec.num_var_rec() == play_.num_var_rec() ); - CPPAD_ASSERT_UNKNOWN( rec.num_load_op_rec() == play_.num_load_op_rec() ); - - // ----------------------------------------------------------------------- - // Use rec to create the function g - // ----------------------------------------------------------------------- - - // number of variables in the recording - g.num_var_tape_ = rec.num_var_rec(); - - // dimension cskip_op vector to number of operators - g.cskip_op_.erase(); - g.cskip_op_.extend( rec.num_op_rec() ); - - // independent variables in g: (x, u) - size_t s = f_abs_res.size(); - size_t n = Domain(); - g.ind_taddr_.resize(n + s); - // (x, u) - for(size_t j = 0; j < n; j++) - { g.ind_taddr_[j] = f2g_var[ ind_taddr_[j] ]; - CPPAD_ASSERT_UNKNOWN( g.ind_taddr_[j] == j + 1 ); - } - for(size_t j = 0; j < s; j++) - { g.ind_taddr_[n + j] = f2g_var[ f_abs_res[j] ]; - CPPAD_ASSERT_UNKNOWN( g.ind_taddr_[n + j] == n + j + 1 ); - } - - // dependent variable in g: (y, z) - CPPAD_ASSERT_UNKNOWN( s == f_abs_arg.size() ); - size_t m = Range(); - g.dep_taddr_.resize(m + s); - for(size_t i = 0; i < m; i++) - { g.dep_taddr_[i] = f2g_var[ dep_taddr_[i] ]; - CPPAD_ASSERT_UNKNOWN( g.dep_taddr_[i] < num_var ); - } - for(size_t i = 0; i < s; i++) - { g.dep_taddr_[m + i] = f2g_var[ f_abs_arg[i] ]; - CPPAD_ASSERT_UNKNOWN( g.dep_taddr_[m + i] < num_var ); - } - - // which dependent variables are parameters - g.dep_parameter_.resize(m + s); - for(size_t i = 0; i < m; i++) - g.dep_parameter_[i] = dep_parameter_[i]; - for(size_t i = 0; i < s; i++) - g.dep_parameter_[m + i] = false; - - // free memory allocated for sparse Jacobian calculation - // (the resutls are no longer valid) - g.for_jac_sparse_pack_.resize(0, 0); - g.for_jac_sparse_set_.resize(0, 0); - - // free taylor coefficient memory - g.taylor_.free(); - g.num_order_taylor_ = 0; - g.cap_order_taylor_ = 0; - - // Transferring the recording swaps its vectors so do this last - // replace the recording in g (this ADFun object) - g.play_.get(rec); - - // ------------------------------------------------------------------------ - // Create the function a - // ------------------------------------------------------------------------ - - // start with a copy of f - a = *this; - - // dependent variables in a(x) - CPPAD_ASSERT_UNKNOWN( s == f_abs_arg.size() ); - a.dep_taddr_.resize(s); - for(size_t i = 0; i < s; i++) - { a.dep_taddr_[i] = f_abs_res[i]; - CPPAD_ASSERT_UNKNOWN( a.dep_taddr_[i] < num_var ); - } - - // free memory allocated for sparse Jacobian calculation - // (the resutls are no longer valid) - a.for_jac_sparse_pack_.resize(0, 0); - a.for_jac_sparse_set_.resize(0, 0); - - // free taylor coefficient memory - a.taylor_.free(); - a.num_order_taylor_ = 0; - a.cap_order_taylor_ = 0; -} - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/acosh.hpp b/external/cppad/include/cppad/core/acosh.hpp deleted file mode 100644 index 7763d8a71..000000000 --- a/external/cppad/include/cppad/core/acosh.hpp +++ /dev/null @@ -1,95 +0,0 @@ -# ifndef CPPAD_CORE_ACOSH_HPP -# define CPPAD_CORE_ACOSH_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin acosh$$ -$spell - acosh - const - Vec - std - cmath - CppAD -$$ -$section The Inverse Hyperbolic Cosine Function: acosh$$ - -$head Syntax$$ -$icode%y% = acosh(%x%)%$$ - -$head Description$$ -The inverse hyperbolic cosine function is defined by -$icode%x% == cosh(%y%)%$$. - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head CPPAD_USE_CPLUSPLUS_2011$$ - -$subhead true$$ -If this preprocessor symbol is true ($code 1$$), -and $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$subhead false$$ -If this preprocessor symbol is false ($code 0$$), -CppAD uses the representation -$latex \[ -\R{acosh} (x) = \log \left( x + \sqrt{ x^2 - 1 } \right) -\] $$ -to compute this function. - -$head Example$$ -$children% - example/general/acosh.cpp -%$$ -The file -$cref acosh.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -# include -# if ! CPPAD_USE_CPLUSPLUS_2011 - -// BEGIN CppAD namespace -namespace CppAD { - -template -Type acosh_template(const Type &x) -{ return CppAD::log( x + CppAD::sqrt( x * x - Type(1) ) ); -} - -inline float acosh(const float &x) -{ return acosh_template(x); } - -inline double acosh(const double &x) -{ return acosh_template(x); } - -template -inline AD acosh(const AD &x) -{ return acosh_template(x); } - -template -inline AD acosh(const VecAD_reference &x) -{ return acosh_template( x.ADBase() ); } - - -} // END CppAD namespace - -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_ACOSH_INCLUDED diff --git a/external/cppad/include/cppad/core/ad.hpp b/external/cppad/include/cppad/core/ad.hpp deleted file mode 100644 index 937b7dbb2..000000000 --- a/external/cppad/include/cppad/core/ad.hpp +++ /dev/null @@ -1,291 +0,0 @@ -# ifndef CPPAD_CORE_AD_HPP -# define CPPAD_CORE_AD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// simple AD operations that must be defined for AD as well as base class -# include -# include - -// define the template classes that are used by the AD template class -# include -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -typedef enum { - tape_manage_new, - tape_manage_delete, - tape_manage_clear -} tape_manage_job; - -template -class AD { -private : - // ----------------------------------------------------------------------- - // value_ corresponding to this object - Base value_; - - // Tape identifier corresponding to taddr - tape_id_t tape_id_; - - // taddr_ in tape for this variable - addr_t taddr_; - // ----------------------------------------------------------------------- - - // enable use of AD in parallel mode - template - friend void parallel_ad(void); - - // template friend functions where template parameter is not bound - template - friend void Independent(VectorAD &x, size_t abort_op_index); - - // one argument functions - friend bool Parameter - (const AD &u); - friend bool Parameter - (const VecAD &u); - friend bool Variable - (const AD &u); - friend bool Variable - (const VecAD &u); - friend int Integer - (const AD &u); - friend AD Var2Par - (const AD &u); - - // power function - friend AD pow - (const AD &x, const AD &y); - - // azmul function - friend AD azmul - (const AD &x, const AD &y); - - // order determining functions, see ordered.hpp - friend bool GreaterThanZero (const AD &x); - friend bool GreaterThanOrZero (const AD &x); - friend bool LessThanZero (const AD &x); - friend bool LessThanOrZero (const AD &x); - friend bool abs_geq - (const AD& x, const AD& y); - - // The identical property functions, see identical.hpp - friend bool IdenticalPar (const AD &x); - friend bool IdenticalZero (const AD &x); - friend bool IdenticalOne (const AD &x); - friend bool IdenticalEqualPar - (const AD &x, const AD &y); - - // EqualOpSeq function - friend bool EqualOpSeq - (const AD &u, const AD &v); - - // NearEqual function - friend bool NearEqual ( - const AD &x, const AD &y, const Base &r, const Base &a); - - friend bool NearEqual ( - const Base &x, const AD &y, const Base &r, const Base &a); - - friend bool NearEqual ( - const AD &x, const Base &y, const Base &r, const Base &a); - - // CondExp function - friend AD CondExpOp ( - enum CompareOp cop , - const AD &left , - const AD &right , - const AD &trueCase , - const AD &falseCase - ); - - // classes - friend class local::ADTape; - friend class ADFun; - friend class atomic_base; - friend class discrete; - friend class VecAD; - friend class VecAD_reference; - - // arithematic binary operators - friend AD operator + - (const AD &left, const AD &right); - friend AD operator - - (const AD &left, const AD &right); - friend AD operator * - (const AD &left, const AD &right); - friend AD operator / - (const AD &left, const AD &right); - - // comparison operators - friend bool operator < - (const AD &left, const AD &right); - friend bool operator <= - (const AD &left, const AD &right); - friend bool operator > - (const AD &left, const AD &right); - friend bool operator >= - (const AD &left, const AD &right); - friend bool operator == - (const AD &left, const AD &right); - friend bool operator != - (const AD &left, const AD &right); - - // input operator - friend std::istream& operator >> - (std::istream &is, AD &x); - - // output operations - friend std::ostream& operator << - (std::ostream &os, const AD &x); - friend void PrintFor ( - const AD& flag , - const char* before , - const AD& var , - const char* after - ); -public: - // type of value - typedef Base value_type; - - // implicit default constructor - inline AD(void); - - // use default implicit copy constructor and assignment operator - // inline AD(const AD &x); - // inline AD& operator=(const AD &x); - - // implicit construction and assingment from base type - inline AD(const Base &b); - inline AD& operator=(const Base &b); - - // implicit contructor and assignment from VecAD::reference - inline AD(const VecAD_reference &x); - inline AD& operator=(const VecAD_reference &x); - - // explicit construction from some other type (depricated) - template inline explicit AD(const T &t); - - // assignment from some other type - template inline AD& operator=(const T &right); - - // base type corresponding to an AD object - friend Base Value (const AD &x); - - // compound assignment operators - inline AD& operator += (const AD &right); - inline AD& operator -= (const AD &right); - inline AD& operator *= (const AD &right); - inline AD& operator /= (const AD &right); - - // unary operators - inline AD operator +(void) const; - inline AD operator -(void) const; - - // destructor - ~AD(void) - { } - - // interface so these functions need not be friends - inline AD abs_me(void) const; - inline AD acos_me(void) const; - inline AD asin_me(void) const; - inline AD atan_me(void) const; - inline AD cos_me(void) const; - inline AD cosh_me(void) const; - inline AD exp_me(void) const; - inline AD fabs_me(void) const; - inline AD log_me(void) const; - inline AD sin_me(void) const; - inline AD sign_me(void) const; - inline AD sinh_me(void) const; - inline AD sqrt_me(void) const; - inline AD tan_me(void) const; - inline AD tanh_me(void) const; -# if CPPAD_USE_CPLUSPLUS_2011 - inline AD erf_me(void) const; - inline AD asinh_me(void) const; - inline AD acosh_me(void) const; - inline AD atanh_me(void) const; - inline AD expm1_me(void) const; - inline AD log1p_me(void) const; -# endif - - // ---------------------------------------------------------- - // static public member functions - - // abort current AD recording - static void abort_recording(void); - - // set the maximum number of OpenMP threads (deprecated) - static void omp_max_thread(size_t number); - - // These functions declared public so can be accessed by user through - // a macro interface and are not intended for direct use. - // The macro interface is documented in bool_fun.hpp. - // Developer documentation for these fucntions is in bool_fun.hpp - static inline bool UnaryBool( - bool FunName(const Base &x), - const AD &x - ); - static inline bool BinaryBool( - bool FunName(const Base &x, const Base &y), - const AD &x , const AD &y - ); - -private: - // - // Make this variable a parameter - // - void make_parameter(void) - { CPPAD_ASSERT_UNKNOWN( Variable(*this) ); // currently a var - tape_id_ = 0; - } - // - // Make this parameter a new variable - // - void make_variable(tape_id_t id, addr_t taddr) - { CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); // currently a par - CPPAD_ASSERT_UNKNOWN( taddr > 0 ); // sure valid taddr - - taddr_ = taddr; - tape_id_ = id; - } - // --------------------------------------------------------------- - // tape linking functions - // - // not static - inline local::ADTape* tape_this(void) const; - // - // static - inline static tape_id_t** tape_id_handle(size_t thread); - inline static tape_id_t* tape_id_ptr(size_t thread); - inline static local::ADTape** tape_handle(size_t thread); - static local::ADTape* tape_manage(tape_manage_job job); - inline static local::ADTape* tape_ptr(void); - inline static local::ADTape* tape_ptr(tape_id_t tape_id); -}; -// --------------------------------------------------------------------------- - -} // END_CPPAD_NAMESPACE - -// tape linking private functions -# include - -// operations that expect the AD template class to be defined - - -# endif diff --git a/external/cppad/include/cppad/core/ad_assign.hpp b/external/cppad/include/cppad/core/ad_assign.hpp deleted file mode 100644 index 735706310..000000000 --- a/external/cppad/include/cppad/core/ad_assign.hpp +++ /dev/null @@ -1,140 +0,0 @@ -# ifndef CPPAD_CORE_AD_ASSIGN_HPP -# define CPPAD_CORE_AD_ASSIGN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- - -$begin ad_assign$$ -$spell - Vec - const -$$ - - -$section AD Assignment Operator$$ -$mindex assign Base VecAD$$ - -$head Syntax$$ -$icode%y% = %x%$$ - -$head Purpose$$ -Assigns the value in $icode x$$ to the object $icode y$$. -In either case, - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Type% &%x% -%$$ -where $icode Type$$ is -$codei%VecAD<%Base%>::reference%$$, -$codei%AD<%Base%>%$$, -$icode Base$$, -or any type that has an implicit constructor of the form -$icode%Base%(%x%)%$$. - -$head y$$ -The target $icode y$$ has prototype -$codei% - AD<%Base%> %y% -%$$ - -$head Example$$ -$children% - example/general/ad_assign.cpp -%$$ -The file $cref ad_assign.cpp$$ contain examples and tests of these operations. -It test returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------- -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -\file ad_assign.hpp -AD constructors and and copy operations. -*/ - -/*! -\page AD_default_assign -Use default assignment operator -because they may be optimized better than the code below: -\code -template -inline AD& AD::operator=(const AD &right) -{ value_ = right.value_; - tape_id_ = right.tape_id_; - taddr_ = right.taddr_; - - return *this; -} -\endcode -*/ - -/*! -Assignment to Base type value. - -\tparam Base -Base type for this AD object. - -\param b -is the Base type value being assignment to this AD object. -The tape identifier will be an invalid tape identifier, -so this object is initially a parameter. -*/ -template -inline AD& AD::operator=(const Base &b) -{ value_ = b; - tape_id_ = 0; - - // check that this is a parameter - CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); - - return *this; -} - -/*! -Assignment to an ADVec element drops the vector information. - -\tparam Base -Base type for this AD object. -*/ -template -inline AD& AD::operator=(const VecAD_reference &x) -{ return *this = x.ADBase(); } - -/*! -Assignment from any other type, converts to Base type, and then uses assignment -from Base type. - -\tparam Base -Base type for this AD object. - -\tparam T -is the the type that is being assigned to AD. -There must be an assignment for Base from Type. - -\param t -is the object that is being assigned to an AD object. -*/ -template -template -inline AD& AD::operator=(const T &t) -{ return *this = Base(t); } - - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/ad_binary.hpp b/external/cppad/include/cppad/core/ad_binary.hpp deleted file mode 100644 index 03bbeb809..000000000 --- a/external/cppad/include/cppad/core/ad_binary.hpp +++ /dev/null @@ -1,144 +0,0 @@ -# ifndef CPPAD_CORE_AD_BINARY_HPP -# define CPPAD_CORE_AD_BINARY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin ad_binary$$ -$spell - Op - VecAD - const -$$ - -$section AD Binary Arithmetic Operators$$ -$mindex + add plus - subtract minus * multiply times / divide$$ - - - - - - - -$head Syntax$$ -$icode%z% = %x% %Op% %y%$$ - -$head Purpose$$ -Performs arithmetic operations where either $icode x$$ or $icode y$$ -has type -$codei%AD<%Base%>%$$ or -$cref%VecAD::reference%VecAD%VecAD::reference%$$. - -$head Op$$ -The operator $icode Op$$ is one of the following -$table -$bold Op$$ $cnext $bold Meaning$$ $rnext -$code +$$ $cnext $icode z$$ is $icode x$$ plus $icode y$$ $rnext -$code -$$ $cnext $icode z$$ is $icode x$$ minus $icode y$$ $rnext -$code *$$ $cnext $icode z$$ is $icode x$$ times $icode y$$ $rnext -$code /$$ $cnext $icode z$$ is $icode x$$ divided by $icode y$$ -$tend - -$head Base$$ -The type $icode Base$$ is determined by the operand that -has type $codei%AD<%Base%>%$$ or $codei%VecAD<%Base%>::reference%$$. - -$head x$$ -The operand $icode x$$ has the following prototype -$codei% - const %Type% &%x% -%$$ -where $icode Type$$ is -$codei%VecAD<%Base%>::reference%$$, -$codei%AD<%Base%>%$$, -$icode Base$$, or -$code double$$. - -$head y$$ -The operand $icode y$$ has the following prototype -$codei% - const %Type% &%y% -%$$ -where $icode Type$$ is -$codei%VecAD<%Base%>::reference%$$, -$codei%AD<%Base%>%$$, -$icode Base$$, or -$code double$$. - - -$head z$$ -The result $icode z$$ has the following prototype -$codei% - %Type% %z% -%$$ -where $icode Type$$ is -$codei%AD<%Base%>%$$. - -$head Operation Sequence$$ -This is an $cref/atomic/glossary/Operation/Atomic/$$ -$cref/AD of Base/glossary/AD of Base/$$ operation -and hence it is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$children% - example/general/add.cpp% - example/general/sub.cpp% - example/general/mul.cpp% - example/general/div.cpp -%$$ - -$head Example$$ -The following files contain examples and tests of these functions. -Each test returns true if it succeeds and false otherwise. -$table -$rref add.cpp$$ -$rref sub.cpp$$ -$rref mul.cpp$$ -$rref div.cpp$$ -$tend - -$head Derivative$$ -If $latex f$$ and $latex g$$ are -$cref/Base functions/glossary/Base Function/$$ - -$subhead Addition$$ -$latex \[ - \D{[ f(x) + g(x) ]}{x} = \D{f(x)}{x} + \D{g(x)}{x} -\] $$ - -$subhead Subtraction$$ -$latex \[ - \D{[ f(x) - g(x) ]}{x} = \D{f(x)}{x} - \D{g(x)}{x} -\] $$ - -$subhead Multiplication$$ -$latex \[ - \D{[ f(x) * g(x) ]}{x} = g(x) * \D{f(x)}{x} + f(x) * \D{g(x)}{x} -\] $$ - -$subhead Division$$ -$latex \[ - \D{[ f(x) / g(x) ]}{x} = - [1/g(x)] * \D{f(x)}{x} - [f(x)/g(x)^2] * \D{g(x)}{x} -\] $$ - -$end ------------------------------------------------------------------------------ -*/ -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/ad_ctor.hpp b/external/cppad/include/cppad/core/ad_ctor.hpp deleted file mode 100644 index ab10718d1..000000000 --- a/external/cppad/include/cppad/core/ad_ctor.hpp +++ /dev/null @@ -1,167 +0,0 @@ -# ifndef CPPAD_CORE_AD_CTOR_HPP -# define CPPAD_CORE_AD_CTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- - -$begin ad_ctor$$ -$spell - cppad - ctor - initializes - Vec - const -$$ - - -$section AD Constructors $$ -$mindex convert Base VecAD$$ - -$head Syntax$$ -$codei%AD<%Base%> %y%() -%$$ -$codei%AD<%Base%> %y%(%x%) -%$$ - -$head Purpose$$ -creates a new $codei%AD<%Base%>%$$ object $icode y$$ -and initializes its value as equal to $icode x$$. - -$head x$$ - -$subhead implicit$$ -There is an implicit constructor where $icode x$$ has one of the following -prototypes: -$codei% - const %Base%& %x% - const VecAD<%Base%>& %x% -%$$ - -$subhead explicit$$ -There is an explicit constructor where $icode x$$ has prototype -$codei% - const %Type%& %x% -%$$ -for any type that has an explicit constructor of the form -$icode%Base%(%x%)%$$. - -$head y$$ -The target $icode y$$ has prototype -$codei% - AD<%Base%> %y% -%$$ - -$head Example$$ -$children% - example/general/ad_ctor.cpp -%$$ -The files $cref ad_ctor.cpp$$ contain examples and tests of these operations. -It test returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------- -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -\file ad_ctor.hpp -AD constructors and and copy operations. -*/ - -/*! -\page AD_default_ctor -Use default copy constructor -because they may be optimized better than the code below: -\code -template -inline AD::AD(const AD &x) -{ - value_ = x.value_; - tape_id_ = x.tape_id_; - taddr_ = x.taddr_; - - return; -} -\endcode -*/ - -/*! -Default Constructor. - -\tparam Base -Base type for this AD object. -*/ -template -inline AD::AD(void) -: value_() -, tape_id_(0) -, taddr_(0) -{ } - - -/*! -Constructor from Base type. - -\tparam Base -Base type for this AD object. - -\param b -is the Base type value corresponding to this AD object. -The tape identifier will be an invalid tape identifier, -so this object is initially a parameter. -*/ -template -inline AD::AD(const Base &b) -: value_(b) -, tape_id_(0) -, taddr_(0) -{ // check that this is a parameter - CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); -} - -/*! -Constructor from an ADVec element drops the vector information. - -\tparam Base -Base type for this AD object. -*/ -template -inline AD::AD(const VecAD_reference &x) -{ *this = x.ADBase(); } - -/*! -Constructor from any other type, converts to Base type, and uses constructor -from Base type. - -\tparam Base -Base type for this AD object. - -\tparam T -is the the type that is being converted to AD. -There must be a constructor for Base from Type. - -\param t -is the object that is being converted from T to AD. -*/ -template -template -inline AD::AD(const T &t) -: value_(Base(t)) -, tape_id_(0) -, taddr_(0) -{ } - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/ad_fun.hpp b/external/cppad/include/cppad/core/ad_fun.hpp deleted file mode 100644 index 0388beb5f..000000000 --- a/external/cppad/include/cppad/core/ad_fun.hpp +++ /dev/null @@ -1,712 +0,0 @@ -# ifndef CPPAD_CORE_AD_FUN_HPP -# define CPPAD_CORE_AD_FUN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin ADFun$$ -$spell - xk - Ind - bool - taylor_ - sizeof - const - std - ind_taddr_ - dep_taddr_ -$$ - -$spell -$$ - -$section ADFun Objects$$ - - -$head Purpose$$ -An AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$ -is stored in an $code ADFun$$ object by its $cref FunConstruct$$. -The $code ADFun$$ object can then be used to calculate function values, -derivative values, and other values related to the corresponding function. - -$childtable% - omh/adfun.omh% - cppad/core/optimize.hpp% - example/abs_normal/abs_normal.omh% - cppad/core/fun_check.hpp% - cppad/core/check_for_nan.hpp -%$$ - -$end -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file ad_fun.hpp -File used to define the ADFun class. -*/ - -/*! -Class used to hold function objects - -\tparam Base -A function object has a recording of AD operations. -It does it calculations using \c Base operations. -*/ - -template -class ADFun { -// ------------------------------------------------------------ -// Private member variables -private: - /// Has this ADFun object been optmized - bool has_been_optimized_; - - /// Check for nan's and report message to user (default value is true). - bool check_for_nan_; - - /// If zero, ignoring comparison operators. Otherwise is the - /// compare change count at which to store the operator index. - size_t compare_change_count_; - - /// If compare_change_count_ is zero, compare_change_number_ is also zero. - /// Otherwise, it is set to the number of comparison operations that had a - /// different result during the subsequent zero order forward. - size_t compare_change_number_; - - /// If compare_change_count is zero, compare_change_op_index_ is also - /// zero. Otherwise it is the operator index for the comparison operator - //// that corresponded to the number changing from count-1 to count. - size_t compare_change_op_index_; - - /// number of orders stored in taylor_ - size_t num_order_taylor_; - - /// maximum number of orders that will fit in taylor_ - size_t cap_order_taylor_; - - /// number of directions stored in taylor_ - size_t num_direction_taylor_; - - /// number of variables in the recording (play_) - size_t num_var_tape_; - - /// tape address for the independent variables - CppAD::vector ind_taddr_; - - /// tape address and parameter flag for the dependent variables - CppAD::vector dep_taddr_; - - /// which dependent variables are actually parameters - CppAD::vector dep_parameter_; - - /// results of the forward mode calculations - local::pod_vector taylor_; - - /// which operations can be conditionally skipped - /// Set during forward pass of order zero - local::pod_vector cskip_op_; - - /// Variable on the tape corresponding to each vecad load operation - /// (if zero, the operation corresponds to a parameter). - local::pod_vector load_op_; - - /// the operation sequence corresponding to this object - local::player play_; - - /// Packed results of the forward mode Jacobian sparsity calculations. - /// for_jac_sparse_pack_.n_set() != 0 implies other sparsity results - /// are empty - local::sparse_pack for_jac_sparse_pack_; - - /// Set results of the forward mode Jacobian sparsity calculations - /// for_jac_sparse_set_.n_set() != 0 implies for_sparse_pack_ is empty. - local::sparse_list for_jac_sparse_set_; - -// ------------------------------------------------------------ -// Private member functions - - /// change the operation sequence corresponding to this object - template - void Dependent(local::ADTape *tape, const ADvector &y); - - // ------------------------------------------------------------ - // vector of bool version of ForSparseJac - // (see doxygen in for_sparse_jac.hpp) - template - void ForSparseJacCase( - bool set_type , - bool transpose , - bool dependency, - size_t q , - const VectorSet& r , - VectorSet& s - ); - // vector of std::set version of ForSparseJac - // (see doxygen in for_sparse_jac.hpp) - template - void ForSparseJacCase( - const std::set& set_type , - bool transpose , - bool dependency, - size_t q , - const VectorSet& r , - VectorSet& s - ); - // ------------------------------------------------------------ - // vector of bool version of RevSparseJac - // (see doxygen in rev_sparse_jac.hpp) - template - void RevSparseJacCase( - bool set_type , - bool transpose , - bool dependency, - size_t p , - const VectorSet& s , - VectorSet& r - ); - // vector of std::set version of RevSparseJac - // (see doxygen in rev_sparse_jac.hpp) - template - void RevSparseJacCase( - const std::set& set_type , - bool transpose , - bool dependency, - size_t p , - const VectorSet& s , - VectorSet& r - ); - // ------------------------------------------------------------ - // vector of bool version of ForSparseHes - // (see doxygen in rev_sparse_hes.hpp) - template - void ForSparseHesCase( - bool set_type , - const VectorSet& r , - const VectorSet& s , - VectorSet& h - ); - // vector of std::set version of ForSparseHes - // (see doxygen in rev_sparse_hes.hpp) - template - void ForSparseHesCase( - const std::set& set_type , - const VectorSet& r , - const VectorSet& s , - VectorSet& h - ); - // ------------------------------------------------------------ - // vector of bool version of RevSparseHes - // (see doxygen in rev_sparse_hes.hpp) - template - void RevSparseHesCase( - bool set_type , - bool transpose , - size_t q , - const VectorSet& s , - VectorSet& h - ); - // vector of std::set version of RevSparseHes - // (see doxygen in rev_sparse_hes.hpp) - template - void RevSparseHesCase( - const std::set& set_type , - bool transpose , - size_t q , - const VectorSet& s , - VectorSet& h - ); - // ------------------------------------------------------------ - // Forward mode version of SparseJacobian - // (see doxygen in sparse_jacobian.hpp) - template - size_t SparseJacobianFor( - const VectorBase& x , - VectorSet& p_transpose , - const VectorSize& row , - const VectorSize& col , - VectorBase& jac , - sparse_jacobian_work& work - ); - // Reverse mode version of SparseJacobian - // (see doxygen in sparse_jacobian.hpp) - template - size_t SparseJacobianRev( - const VectorBase& x , - VectorSet& p , - const VectorSize& row , - const VectorSize& col , - VectorBase& jac , - sparse_jacobian_work& work - ); - // ------------------------------------------------------------ - // combined sparse_list and sparse_pack version of - // SparseHessian (see doxygen in sparse_hessian.hpp) - template - size_t SparseHessianCompute( - const VectorBase& x , - const VectorBase& w , - VectorSet& sparsity , - const VectorSize& row , - const VectorSize& col , - VectorBase& hes , - sparse_hessian_work& work - ); -// ------------------------------------------------------------ -public: - /// copy constructor - ADFun(const ADFun& g) - : num_var_tape_(0) - { CppAD::ErrorHandler::Call( - true, - __LINE__, - __FILE__, - "ADFun(const ADFun& g)", - "Attempting to use the ADFun copy constructor.\n" - "Perhaps you are passing an ADFun object " - "by value instead of by reference." - ); - } - - /// default constructor - ADFun(void); - - // assignment operator - // (see doxygen in fun_construct.hpp) - void operator=(const ADFun& f); - - /// sequence constructor - template - ADFun(const ADvector &x, const ADvector &y); - - /// destructor - ~ADFun(void) - { } - - /// set value of check_for_nan_ - void check_for_nan(bool value) - { check_for_nan_ = value; } - bool check_for_nan(void) const - { return check_for_nan_; } - - /// assign a new operation sequence - template - void Dependent(const ADvector &x, const ADvector &y); - - /// forward mode user API, one order multiple directions. - template - VectorBase Forward(size_t q, size_t r, const VectorBase& x); - - /// forward mode user API, multiple directions one order. - template - VectorBase Forward(size_t q, - const VectorBase& x, std::ostream& s = std::cout - ); - - /// reverse mode sweep - template - VectorBase Reverse(size_t p, const VectorBase &v); - - // --------------------------------------------------------------------- - // Jacobian sparsity - template - VectorSet ForSparseJac( - size_t q, const VectorSet &r, bool transpose = false, - bool dependency = false - ); - template - VectorSet RevSparseJac( - size_t q, const VectorSet &s, bool transpose = false, - bool dependency = false - ); - // --------------------------------------------------------------------- - template - size_t sparse_jac_for( - size_t group_max , - const BaseVector& x , - sparse_rcv& subset , - const sparse_rc& pattern , - const std::string& coloring , - sparse_jac_work& work - ); - template - size_t sparse_jac_rev( - const BaseVector& x , - sparse_rcv& subset , - const sparse_rc& pattern , - const std::string& coloring , - sparse_jac_work& work - ); - template - size_t sparse_hes( - const BaseVector& x , - const BaseVector& w , - sparse_rcv& subset , - const sparse_rc& pattern , - const std::string& coloring , - sparse_hes_work& work - ); - // --------------------------------------------------------------------- - template - void for_jac_sparsity( - const sparse_rc& pattern_in , - bool transpose , - bool dependency , - bool internal_bool , - sparse_rc& pattern_out - ); - template - void rev_jac_sparsity( - const sparse_rc& pattern_in , - bool transpose , - bool dependency , - bool internal_bool , - sparse_rc& pattern_out - ); - template - void rev_hes_sparsity( - const BoolVector& select_range , - bool transpose , - bool internal_bool , - sparse_rc& pattern_out - ); - template - void for_hes_sparsity( - const BoolVector& select_domain , - const BoolVector& select_range , - bool internal_bool , - sparse_rc& pattern_out - ); - // --------------------------------------------------------------------- - // forward mode Hessian sparsity - // (see doxygen documentation in rev_sparse_hes.hpp) - template - VectorSet ForSparseHes( - const VectorSet &r, const VectorSet &s - ); - // internal set sparsity version of ForSparseHes - // (used by checkpoint functions only) - void ForSparseHesCheckpoint( - vector& r , - vector& s , - local::sparse_list& h - ); - // reverse mode Hessian sparsity - // (see doxygen documentation in rev_sparse_hes.hpp) - template - VectorSet RevSparseHes( - size_t q, const VectorSet &s, bool transpose = false - ); - // internal set sparsity version of RevSparseHes - // (used by checkpoint functions only) - void RevSparseHesCheckpoint( - size_t q , - vector& s , - bool transpose , - local::sparse_list& h - ); - // internal set sparsity version of RevSparseJac - // (used by checkpoint functions only) - void RevSparseJacCheckpoint( - size_t q , - const local::sparse_list& r , - bool transpose , - bool dependency , - local::sparse_list& s - ); - // internal set sparsity version of RevSparseJac - // (used by checkpoint functions only) - void ForSparseJacCheckpoint( - size_t q , - const local::sparse_list& r , - bool transpose , - bool dependency , - local::sparse_list& s - ); - - /// amount of memory used for boolean Jacobain sparsity pattern - size_t size_forward_bool(void) const - { return for_jac_sparse_pack_.memory(); } - - /// free memory used for Jacobain sparsity pattern - void size_forward_bool(size_t zero) - { CPPAD_ASSERT_KNOWN( - zero == 0, - "size_forward_bool: argument not equal to zero" - ); - for_jac_sparse_pack_.resize(0, 0); - } - - /// amount of memory used for vector of set Jacobain sparsity pattern - size_t size_forward_set(void) const - { return for_jac_sparse_set_.memory(); } - - /// free memory used for Jacobain sparsity pattern - void size_forward_set(size_t zero) - { CPPAD_ASSERT_KNOWN( - zero == 0, - "size_forward_bool: argument not equal to zero" - ); - for_jac_sparse_set_.resize(0, 0); - } - - /// number of operators in the operation sequence - size_t size_op(void) const - { return play_.num_op_rec(); } - - /// number of operator arguments in the operation sequence - size_t size_op_arg(void) const - { return play_.num_op_arg_rec(); } - - /// amount of memory required for the operation sequence - size_t size_op_seq(void) const - { return play_.Memory(); } - - /// number of parameters in the operation sequence - size_t size_par(void) const - { return play_.num_par_rec(); } - - /// number taylor coefficient orders calculated - size_t size_order(void) const - { return num_order_taylor_; } - - /// number taylor coefficient directions calculated - size_t size_direction(void) const - { return num_direction_taylor_; } - - /// number of characters in the operation sequence - size_t size_text(void) const - { return play_.num_text_rec(); } - - /// number of variables in opertion sequence - size_t size_var(void) const - { return num_var_tape_; } - - /// number of VecAD indices in the operation sequence - size_t size_VecAD(void) const - { return play_.num_vec_ind_rec(); } - - /// set number of orders currently allocated (user API) - void capacity_order(size_t c); - - /// set number of orders and directions currently allocated - void capacity_order(size_t c, size_t r); - - /// number of variables in conditional expressions that can be skipped - size_t number_skip(void); - - /// number of independent variables - size_t Domain(void) const - { return ind_taddr_.size(); } - - /// number of dependent variables - size_t Range(void) const - { return dep_taddr_.size(); } - - /// is variable a parameter - bool Parameter(size_t i) - { CPPAD_ASSERT_KNOWN( - i < dep_taddr_.size(), - "Argument to Parameter is >= dimension of range space" - ); - return dep_parameter_[i]; - } - - /// Deprecated: number of comparison operations that changed - /// for the previous zero order forward (than when function was recorded) - size_t CompareChange(void) const - { return compare_change_number_; } - - /// count as which to store operator index - void compare_change_count(size_t count) - { compare_change_count_ = count; - compare_change_number_ = 0; - compare_change_op_index_ = 0; - } - - /// number of comparison operations that changed - size_t compare_change_number(void) const - { return compare_change_number_; } - - /// operator index for the count-th comparison change - size_t compare_change_op_index(void) const - { if( has_been_optimized_ ) - return 0; - return compare_change_op_index_; - } - - /// calculate entire Jacobian - template - VectorBase Jacobian(const VectorBase &x); - - /// calculate Hessian for one component of f - template - VectorBase Hessian(const VectorBase &x, const VectorBase &w); - template - VectorBase Hessian(const VectorBase &x, size_t i); - - /// forward mode calculation of partial w.r.t one domain component - template - VectorBase ForOne( - const VectorBase &x , - size_t j ); - - /// reverse mode calculation of derivative of one range component - template - VectorBase RevOne( - const VectorBase &x , - size_t i ); - - /// forward mode calculation of a subset of second order partials - template - VectorBase ForTwo( - const VectorBase &x , - const VectorSize_t &J , - const VectorSize_t &K ); - - /// reverse mode calculation of a subset of second order partials - template - VectorBase RevTwo( - const VectorBase &x , - const VectorSize_t &I , - const VectorSize_t &J ); - - /// calculate sparse Jacobians - template - VectorBase SparseJacobian( - const VectorBase &x - ); - template - VectorBase SparseJacobian( - const VectorBase &x , - const VectorSet &p - ); - template - size_t SparseJacobianForward( - const VectorBase& x , - const VectorSet& p , - const VectorSize& r , - const VectorSize& c , - VectorBase& jac , - sparse_jacobian_work& work - ); - template - size_t SparseJacobianReverse( - const VectorBase& x , - const VectorSet& p , - const VectorSize& r , - const VectorSize& c , - VectorBase& jac , - sparse_jacobian_work& work - ); - - /// calculate sparse Hessians - template - VectorBase SparseHessian( - const VectorBase& x , - const VectorBase& w - ); - template - VectorBase SparseHessian( - const VectorBase& x , - const VectorBase& w , - const VectorBool& p - ); - template - size_t SparseHessian( - const VectorBase& x , - const VectorBase& w , - const VectorSet& p , - const VectorSize& r , - const VectorSize& c , - VectorBase& hes , - sparse_hessian_work& work - ); - - // Optimize the tape - // (see doxygen documentation in optimize.hpp) - void optimize( const std::string& options = "" ); - - // create abs-normal representation of the function f(x) - void abs_normal_fun( ADFun& g, ADFun& a ); - // ------------------- Deprecated ----------------------------- - - /// deprecated: assign a new operation sequence - template - void Dependent(const ADvector &y); - - /// Deprecated: number of variables in opertion sequence - size_t Size(void) const - { return num_var_tape_; } - - /// Deprecated: # taylor_ coefficients currently stored - /// (per variable,direction) - size_t Order(void) const - { return num_order_taylor_ - 1; } - - /// Deprecated: amount of memory for this object - /// Note that an approximation is used for the std::set memory - size_t Memory(void) const - { size_t pervar = cap_order_taylor_ * sizeof(Base) - + for_jac_sparse_pack_.memory() - + for_jac_sparse_set_.memory(); - size_t total = num_var_tape_ * pervar + play_.Memory(); - return total; - } - - /// Deprecated: # taylor_ coefficient orderss stored - /// (per variable,direction) - size_t taylor_size(void) const - { return num_order_taylor_; } - - /// Deprecated: Does this AD operation sequence use - /// VecAD::reference operands - bool use_VecAD(void) const - { return play_.num_vec_ind_rec() > 0; } - - /// Deprecated: # taylor_ coefficient orders calculated - /// (per variable,direction) - size_t size_taylor(void) const - { return num_order_taylor_; } - - /// Deprecated: set number of orders currently allocated - /// (per variable,direction) - void capacity_taylor(size_t per_var); -}; -// --------------------------------------------------------------------------- - -} // END_CPPAD_NAMESPACE - -// non-user interfaces -# include -# include -# include -# include -# include -# include -# include -# include - -// user interfaces -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/ad_io.hpp b/external/cppad/include/cppad/core/ad_io.hpp deleted file mode 100644 index 7b8a71b6a..000000000 --- a/external/cppad/include/cppad/core/ad_io.hpp +++ /dev/null @@ -1,223 +0,0 @@ -# ifndef CPPAD_CORE_AD_IO_HPP -# define CPPAD_CORE_AD_IO_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ad_input$$ -$spell - VecAD - std - istream - const -$$ - - -$section AD Output Stream Operator$$ -$mindex >> input write$$ - -$head Syntax$$ -$icode%is% >> %x%$$ - - -$head Purpose$$ -Sets $icode x$$ to a $cref/parameter/glossary/Parameter/$$ -with value $icode b$$ corresponding to -$codei% - %is% >> %b% -%$$ -where $icode b$$ is a $icode Base$$ object. -It is assumed that this $icode Base$$ input operation returns -a reference to $icode is$$. - -$head is$$ -The operand $icode is$$ has prototype -$codei% - std::istream& %is% -%$$ - -$head x$$ -The operand $icode x$$ has one of the following prototypes -$codei% - AD<%Base%>& %x% -%$$ - -$head Result$$ -The result of this operation can be used as a reference to $icode is$$. -For example, if the operand $icode y$$ has prototype -$codei% - AD<%Base%> %y% -%$$ -then the syntax -$codei% - %is% >> %x% >> %y% -%$$ -will first read the $icode Base$$ value of $icode x$$ from $icode is$$, -and then read the $icode Base$$ value to $icode y$$. - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/ad_input.cpp -%$$ -The file -$cref ad_input.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------- -$begin ad_output$$ -$spell - VecAD - std - ostream - const -$$ - - -$section AD Output Stream Operator$$ -$mindex <<$$ - -$head Syntax$$ -$icode%os% << %x%$$ - - -$head Purpose$$ -Writes the $icode Base$$ value, corresponding to $icode x$$, -to the output stream $icode os$$. - -$head Assumption$$ -If $icode b$$ is a $icode Base$$ object, -$codei% - %os% << %b% -%$$ -returns a reference to $icode os$$. - -$head os$$ -The operand $icode os$$ has prototype -$codei% - std::ostream& %os% -%$$ - -$head x$$ -The operand $icode x$$ has one of the following prototypes -$codei% - const AD<%Base%>& %x% - const VecAD<%Base%>::reference& %x% -%$$ - -$head Result$$ -The result of this operation can be used as a reference to $icode os$$. -For example, if the operand $icode y$$ has prototype -$codei% - AD<%Base%> %y% -%$$ -then the syntax -$codei% - %os% << %x% << %y% -%$$ -will output the value corresponding to $icode x$$ -followed by the value corresponding to $icode y$$. - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/ad_output.cpp -%$$ -The file -$cref ad_output.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------- -*/ -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file ad_io.hpp -AD input and ouput stream operators. -*/ -// --------------------------------------------------------------------------- -/*! -Read an AD object from an input stream. - -\tparam Base -Base type for the AD object. - -\param is [in,out] -Is the input stream from which that value is read. - -\param x [out] -is the object that is being set to a value. -Upone return, x.value_ is read from the input stream -and x.tape_is_ is zero; i.e., x is a parameter. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -std::istream& operator >> (std::istream& is, AD& x) -{ // like assignment to a base type value - x.tape_id_ = 0; - CPPAD_ASSERT_UNKNOWN( Parameter(x) ); - return (is >> x.value_); -} -// --------------------------------------------------------------------------- -/*! -Write an AD object to an output stream. - -\tparam Base -Base type for the AD object. - -\param os [in,out] -Is the output stream to which that value is written. - -\param x -is the object that is being written to the output stream. -This is equivalent to writing x.value_ to the output stream. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -std::ostream& operator << (std::ostream &os, const AD &x) -{ return (os << x.value_); } -// --------------------------------------------------------------------------- -/*! -Write a VecAD_reference object to an output stream. - -\tparam Base -Base type for the VecAD_reference object. - -\param os [in,out] -Is the output stream to which that value is written. - -\param x -is the element of the VecAD object that is being written to the output stream. -This is equivalent to writing the corresponing Base value to the stream. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -std::ostream& operator << (std::ostream &os, const VecAD_reference &x) -{ return (os << x.ADBase()); } - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/ad_to_string.hpp b/external/cppad/include/cppad/core/ad_to_string.hpp deleted file mode 100644 index dc431b1c0..000000000 --- a/external/cppad/include/cppad/core/ad_to_string.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_AD_TO_STRING_HPP -# define CPPAD_CORE_AD_TO_STRING_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ad_to_string$$ -$spell - const - std -$$ - -$section Convert An AD or Base Type to String$$ - -$head Syntax$$ -$icode%s% = to_string(%value%)%$$. - -$head See Also$$ -$cref to_string$$, $cref base_to_string$$ - -$head value$$ -The argument $icode value$$ has prototype -$codei% - const AD<%Base%>& %value% - const %Base%& %value% -%$$ -where $icode Base$$ is a type that supports the -$cref base_to_string$$ type requirement. - -$head s$$ -The return value has prototype -$codei% - std::string %s% -%$$ -and contains a representation of the specified $icode value$$. -If $icode value$$ is an AD type, -the result has the same precision as for the $icode Base$$ type. - -$head Example$$ -The file $cref to_string.cpp$$ -includes an example and test of $code to_string$$ with AD types. -It returns true if it succeeds and false otherwise. - -$end -*/ -# include -# include - -namespace CppAD { - - // Template definition is in cppad/utility/to_string.hpp. - // Partial specialzation for AD types - template - struct to_string_struct< CppAD::AD > - { std::string operator()(const CppAD::AD& value) - { to_string_struct ts; - return ts( Value( Var2Par( value ) ) ); } - }; - -} - -# endif diff --git a/external/cppad/include/cppad/core/ad_valued.hpp b/external/cppad/include/cppad/core/ad_valued.hpp deleted file mode 100644 index 810703822..000000000 --- a/external/cppad/include/cppad/core/ad_valued.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_AD_VALUED_HPP -# define CPPAD_CORE_AD_VALUED_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ADValued$$ -$spell -$$ - - -$section AD Valued Operations and Functions$$ - -$comment atomic.omh includes atomic_base.omh which atomic_base.hpp$$ -$childtable% - cppad/core/arithmetic.hpp% - cppad/core/standard_math.hpp% - cppad/core/cond_exp.hpp% - cppad/core/discrete.hpp% - cppad/core/numeric_limits.hpp% - omh/atomic.omh -%$$ - -$end -*/ - -// include MathOther.h after CondExp.h because some MathOther.h routines use -// CondExp.h and CondExp.h is not sufficently declared in Declare.h - -# include -# include -# include -# include -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/add.hpp b/external/cppad/include/cppad/core/add.hpp deleted file mode 100644 index ad15e36b1..000000000 --- a/external/cppad/include/cppad/core/add.hpp +++ /dev/null @@ -1,97 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_ADD_HPP -# define CPPAD_CORE_ADD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD operator + (const AD &left , const AD &right) -{ - // compute the Base part of this AD object - AD result; - result.value_ = left.value_ + right.value_; - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return result; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = left.tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // result = variable + variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AddvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AddvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(left.taddr_, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::AddvvOp); - // make result a variable - result.tape_id_ = tape_id; - } - else if( IdenticalZero(right.value_) ) - { // result = variable + 0 - result.make_variable(left.tape_id_, left.taddr_); - } - else - { // result = variable + parameter - // = parameter + variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AddpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AddpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(p, left.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::AddpvOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - else if( var_right ) - { if( IdenticalZero(left.value_) ) - { // result = 0 + variable - result.make_variable(right.tape_id_, right.taddr_); - } - else - { // result = parameter + variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AddpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AddpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left.value_); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::AddpvOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - return result; -} - -// convert other cases into the case above -CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(+) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/add_eq.hpp b/external/cppad/include/cppad/core/add_eq.hpp deleted file mode 100644 index dc22c0969..000000000 --- a/external/cppad/include/cppad/core/add_eq.hpp +++ /dev/null @@ -1,92 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_ADD_EQ_HPP -# define CPPAD_CORE_ADD_EQ_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD& AD::operator += (const AD &right) -{ - // compute the Base part - Base left; - left = value_; - value_ += right.value_; - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return *this; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // this = variable + variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AddvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AddvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(taddr_, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::AddvvOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - else if( ! IdenticalZero( right.value_ ) ) - { // this = variable + parameter - // = parameter + variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AddpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AddpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(p, taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::AddpvOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - } - else if( var_right ) - { if( IdenticalZero(left) ) - { // this = 0 + right - make_variable(right.tape_id_, right.taddr_); - } - else - { // this = parameter + variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::AddpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::AddpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::AddpvOp); - // make this a variable - tape_id_ = tape_id; - } - } - return *this; -} - -CPPAD_FOLD_ASSIGNMENT_OPERATOR(+=) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/arithmetic.hpp b/external/cppad/include/cppad/core/arithmetic.hpp deleted file mode 100644 index e1b3fe3de..000000000 --- a/external/cppad/include/cppad/core/arithmetic.hpp +++ /dev/null @@ -1,42 +0,0 @@ -# ifndef CPPAD_CORE_ARITHMETIC_HPP -# define CPPAD_CORE_ARITHMETIC_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin Arithmetic$$ -$spell - Op - const -$$ - - - -$section AD Arithmetic Operators and Compound Assignments$$ - -$childtable% - cppad/core/unary_plus.hpp% - cppad/core/unary_minus.hpp% - cppad/core/ad_binary.hpp% - cppad/core/compound_assign.hpp -%$$ - -$end -------------------------------------------------------------------------------- -*/ -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/asinh.hpp b/external/cppad/include/cppad/core/asinh.hpp deleted file mode 100644 index fdebe63bd..000000000 --- a/external/cppad/include/cppad/core/asinh.hpp +++ /dev/null @@ -1,96 +0,0 @@ -# ifndef CPPAD_CORE_ASINH_HPP -# define CPPAD_CORE_ASINH_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- - -$begin asinh$$ -$spell - asinh - const - Vec - std - cmath - CppAD -$$ -$section The Inverse Hyperbolic Sine Function: asinh$$ - -$head Syntax$$ -$icode%y% = asinh(%x%)%$$ - -$head Description$$ -The inverse hyperbolic sine function is defined by -$icode%x% == sinh(%y%)%$$. - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head CPPAD_USE_CPLUSPLUS_2011$$ - -$subhead true$$ -If this preprocessor symbol is true ($code 1$$), -and $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$subhead false$$ -If this preprocessor symbol is false ($code 0$$), -CppAD uses the representation -$latex \[ -\R{asinh} (x) = \log \left( x + \sqrt{ 1 + x^2 } \right) -\] $$ -to compute this function. - -$head Example$$ -$children% - example/general/asinh.cpp -%$$ -The file -$cref asinh.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -# include -# if ! CPPAD_USE_CPLUSPLUS_2011 - -// BEGIN CppAD namespace -namespace CppAD { - -template -Type asinh_template(const Type &x) -{ return CppAD::log( x + CppAD::sqrt( Type(1) + x * x ) ); -} - -inline float asinh(const float &x) -{ return asinh_template(x); } - -inline double asinh(const double &x) -{ return asinh_template(x); } - -template -inline AD asinh(const AD &x) -{ return asinh_template(x); } - -template -inline AD asinh(const VecAD_reference &x) -{ return asinh_template( x.ADBase() ); } - - -} // END CppAD namespace - -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_ASINH_INCLUDED diff --git a/external/cppad/include/cppad/core/atan2.hpp b/external/cppad/include/cppad/core/atan2.hpp deleted file mode 100644 index 103e7313c..000000000 --- a/external/cppad/include/cppad/core/atan2.hpp +++ /dev/null @@ -1,141 +0,0 @@ -# ifndef CPPAD_CORE_ATAN2_HPP -# define CPPAD_CORE_ATAN2_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin atan2$$ -$spell - Vec - CppAD - namespace - std - atan - const -$$ - - -$section AD Two Argument Inverse Tangent Function$$ -$mindex tan atan2$$ - -$head Syntax$$ -$icode%theta% = atan2(%y%, %x%)%$$ - - -$head Purpose$$ -Determines an angle $latex \theta \in [ - \pi , + \pi ]$$ -such that -$latex \[ -\begin{array}{rcl} - \sin ( \theta ) & = & y / \sqrt{ x^2 + y^2 } \\ - \cos ( \theta ) & = & x / \sqrt{ x^2 + y^2 } -\end{array} -\] $$ - -$head y$$ -The argument $icode y$$ has one of the following prototypes -$codei% - const AD<%Base%> &%y% - const VecAD<%Base%>::reference &%y% -%$$ - -$head x$$ -The argument $icode x$$ has one of the following prototypes -$codei% - const AD<%Base%> &%x% - const VecAD<%Base%>::reference &%x% -%$$ - -$head theta$$ -The result $icode theta$$ has prototype -$codei% - AD<%Base%> %theta% -%$$ - -$head Operation Sequence$$ -The AD of $icode Base$$ -operation sequence used to calculate $icode theta$$ is -$cref/independent/glossary/Operation/Independent/$$ -of $icode x$$ and $icode y$$. - -$head Example$$ -$children% - example/general/atan2.cpp -%$$ -The file -$cref atan2.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ - -namespace CppAD { // BEGIN CppAD namespace - -inline float atan2(float x, float y) -{ return std::atan2(x, y); } - -inline double atan2(double x, double y) -{ return std::atan2(x, y); } - -// The code below is used as an example by the CondExp documentation. -// BEGIN CondExp -template -AD atan2 (const AD &y, const AD &x) -{ AD alpha; - AD beta; - AD theta; - - AD zero(0.); - AD pi2(2. * atan(1.)); - AD pi(2. * pi2); - - AD ax = fabs(x); - AD ay = fabs(y); - - // if( ax > ay ) - // theta = atan(ay / ax); - // else theta = pi2 - atan(ax / ay); - alpha = atan(ay / ax); - beta = pi2 - atan(ax / ay); - theta = CondExpGt(ax, ay, alpha, beta); // use of CondExp - - // if( x <= 0 ) - // theta = pi - theta; - theta = CondExpLe(x, zero, pi - theta, theta); // use of CondExp - - // if( y <= 0 ) - // theta = - theta; - theta = CondExpLe(y, zero, -theta, theta); // use of CondExp - - return theta; -} -// END CondExp - -template -inline AD atan2 (const VecAD_reference &y, const AD &x) -{ return atan2( y.ADBase() , x ); } - -template -inline AD atan2 (const AD &y, const VecAD_reference &x) -{ return atan2( y , x.ADBase() ); } - -template -inline AD atan2 -(const VecAD_reference &y, const VecAD_reference &x) -{ return atan2( y.ADBase() , x.ADBase() ); } - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/atanh.hpp b/external/cppad/include/cppad/core/atanh.hpp deleted file mode 100644 index 9880c1f23..000000000 --- a/external/cppad/include/cppad/core/atanh.hpp +++ /dev/null @@ -1,96 +0,0 @@ -# ifndef CPPAD_CORE_ATANH_HPP -# define CPPAD_CORE_ATANH_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin atanh$$ -$spell - atanh - const - Vec - std - cmath - CppAD - tanh -$$ -$section The Inverse Hyperbolic Tangent Function: atanh$$ - -$head Syntax$$ -$icode%y% = atanh(%x%)%$$ - -$head Description$$ -The inverse hyperbolic tangent function is defined by -$icode%x% == tanh(%y%)%$$. - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head CPPAD_USE_CPLUSPLUS_2011$$ - -$subhead true$$ -If this preprocessor symbol is true ($code 1$$), -and $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$subhead false$$ -If this preprocessor symbol is false ($code 0$$), -CppAD uses the representation -$latex \[ -\R{atanh} (x) = \frac{1}{2} \log \left( \frac{1 + x}{1 - x} \right) -\] $$ -to compute this function. - -$head Example$$ -$children% - example/general/atanh.cpp -%$$ -The file -$cref atanh.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -# include -# if ! CPPAD_USE_CPLUSPLUS_2011 - -// BEGIN CppAD namespace -namespace CppAD { - -template -Type atanh_template(const Type &x) -{ return CppAD::log( (Type(1) + x) / (Type(1) - x) ) / Type(2); -} - -inline float atanh(const float &x) -{ return atanh_template(x); } - -inline double atanh(const double &x) -{ return atanh_template(x); } - -template -inline AD atanh(const AD &x) -{ return atanh_template(x); } - -template -inline AD atanh(const VecAD_reference &x) -{ return atanh_template( x.ADBase() ); } - - -} // END CppAD namespace - -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_ATANH_INCLUDED diff --git a/external/cppad/include/cppad/core/atomic_base.hpp b/external/cppad/include/cppad/core/atomic_base.hpp deleted file mode 100644 index 4aa8b7021..000000000 --- a/external/cppad/include/cppad/core/atomic_base.hpp +++ /dev/null @@ -1,2423 +0,0 @@ -# ifndef CPPAD_CORE_ATOMIC_BASE_HPP -# define CPPAD_CORE_ATOMIC_BASE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file atomic_base.hpp -Base class for atomic user operations. -*/ - -template -class atomic_base { -// =================================================================== -public: - enum option_enum { - pack_sparsity_enum , - bool_sparsity_enum , - set_sparsity_enum - }; -private: - // ------------------------------------------------------ - // constants - // - /// index of this object in class_object - const size_t index_; - - // ----------------------------------------------------- - // variables - // - /// sparsity pattern this object is currently using - /// (set by constructor and option member functions) - option_enum sparsity_; - - /// temporary work space used by member functions, declared here to avoid - // memory allocation/deallocation for each usage - struct work_struct { - vector vx; - vector vy; - vector tx; - vector ty; - // - vector bool_t; - // - vectorBool pack_h; - vectorBool pack_r; - vectorBool pack_s; - vectorBool pack_u; - // - vector bool_h; - vector bool_r; - vector bool_s; - vector bool_u; - // - vector< std::set > set_h; - vector< std::set > set_r; - vector< std::set > set_s; - vector< std::set > set_u; - }; - // Use pointers, to avoid false sharing between threads. - // Not using: vector work_; - // so that deprecated atomic examples do not result in a memory leak. - work_struct* work_[CPPAD_MAX_NUM_THREADS]; - // ----------------------------------------------------- - // static member functions - // - /// List of all the object in this class - static std::vector& class_object(void) - { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static std::vector list_; - return list_; - } - /// List of names for each object in this class - static std::vector& class_name(void) - { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static std::vector list_; - return list_; - } - // ===================================================================== -public: - // ----------------------------------------------------- - // member functions not in user API - // - /// current sparsity setting - option_enum sparsity(void) const - { return sparsity_; } - - /// Name corresponding to a base_atomic object - const std::string& afun_name(void) const - { return class_name()[index_]; } -/* -$begin atomic_ctor$$ -$spell - enum - sq - std - afun - arg - CppAD - bool - ctor - const - mat_mul_xam.cpp - hpp -$$ - -$section Atomic Function Constructor$$ - -$head Syntax$$ -$icode%atomic_user afun%(%ctor_arg_list%) -%$$ -$codei%atomic_base<%Base%>(%name%, %sparsity%) -%$$ - -$head atomic_user$$ - -$subhead ctor_arg_list$$ -Is a list of arguments for the $icode atomic_user$$ constructor. - -$subhead afun$$ -The object $icode afun$$ must stay in scope for as long -as the corresponding atomic function is used. -This includes use by any $cref/ADFun/ADFun/$$ that -has this $icode atomic_user$$ operation in its -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$subhead Implementation$$ -The user defined $icode atomic_user$$ class is a publicly derived class of -$codei%atomic_base<%Base%>%$$. -It should be declared as follows: -$codei% - class %atomic_user% : public CppAD::atomic_base<%Base%> { - public: - %atomic_user%(%ctor_arg_list%) : atomic_base<%Base%>(%name%, %sparsity%) - %...% - }; -%$$ -where $icode ...$$ -denotes the rest of the implementation of the derived class. -This includes completing the constructor and -all the virtual functions that have their -$code atomic_base$$ implementations replaced by -$icode atomic_user$$ implementations. - -$head atomic_base$$ - -$subhead Restrictions$$ -The $code atomic_base$$ constructor cannot be called in -$cref/parallel/ta_in_parallel/$$ mode. - -$subhead Base$$ -The template parameter determines the -$icode Base$$ type for this $codei%AD<%Base%>%$$ atomic operation. - -$subhead name$$ -This $code atomic_base$$ constructor argument has the following prototype -$codei% - const std::string& %name% -%$$ -It is the name for this atomic function and is used for error reporting. -The suggested value for $icode name$$ is $icode afun$$ or $icode atomic_user$$, -i.e., the name of the corresponding atomic object or class. - -$subhead sparsity$$ -This $code atomic_base$$ constructor argument has prototype -$codei% - atomic_base<%Base%>::option_enum %sparsity% -%$$ -The current $icode sparsity$$ for an $code atomic_base$$ object -determines which type of sparsity patterns it uses -and its value is one of the following: -$table -$icode sparsity$$ $cnext sparsity patterns $rnext -$codei%atomic_base<%Base%>::pack_sparsity_enum%$$ $pre $$ $cnext - $cref/vectorBool/CppAD_vector/vectorBool/$$ -$rnext -$codei%atomic_base<%Base%>::bool_sparsity_enum%$$ $pre $$ $cnext - $cref/vector/CppAD_vector/$$$code $$ -$rnext -$codei%atomic_base<%Base%>::set_sparsity_enum%$$ $pre $$ $cnext - $cref/vector/CppAD_vector/$$$code >$$ -$tend -There is a default value for $icode sparsity$$ if it is not -included in the constructor (which may be either the bool or set option). - -$head Example$$ - -$subhead Define Constructor$$ -The following is an example of a user atomic function constructor definitions: -$cref%get_started.cpp%atomic_get_started.cpp%Constructor%$$. - -$subhead Use Constructor$$ -The following is an example using a user atomic function constructor: -$cref%get_started.cpp%atomic_get_started.cpp%Use Atomic Function%Constructor%$$. - -$end -*/ -/*! -Base class for atomic_user functions. - -\tparam Base -This class is used for defining an AD atomic operation y = f(x). -*/ -/// make sure user does not invoke the default constructor -atomic_base(void) -{ CPPAD_ASSERT_KNOWN(false, - "Attempt to use the atomic_base default constructor" - ); -} -/*! -Constructor - -\param name -name used for error reporting - -\param sparsity [in] -what type of sparsity patterns are computed by this function, -bool_sparsity_enum or set_sparsity_enum. Default value is -bool sparsity patterns. -*/ -atomic_base( - const std::string& name, - option_enum sparsity = bool_sparsity_enum -) : -index_ ( class_object().size() ) , -sparsity_( sparsity ) -{ CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "atomic_base: constructor cannot be called in parallel mode." - ); - class_object().push_back(this); - class_name().push_back(name); - CPPAD_ASSERT_UNKNOWN( class_object().size() == class_name().size() ); - // - // initialize work pointers as null; - for(size_t thread = 0; thread < CPPAD_MAX_NUM_THREADS; thread++) - work_[thread] = CPPAD_NULL; -} -/// destructor informs CppAD that this atomic function with this index -/// has dropped out of scope by setting its pointer to null -virtual ~atomic_base(void) -{ CPPAD_ASSERT_UNKNOWN( class_object().size() > index_ ); - // change object pointer to null, but leave name for error reporting - class_object()[index_] = CPPAD_NULL; - // - // free temporary work memory - for(size_t thread = 0; thread < CPPAD_MAX_NUM_THREADS; thread++) - free_work(thread); -} -/// allocates work_ for a specified thread -void allocate_work(size_t thread) -{ if( work_[thread] == CPPAD_NULL ) - { // allocate the raw memory - size_t min_bytes = sizeof(work_struct); - size_t num_bytes; - void* v_ptr = thread_alloc::get_memory(min_bytes, num_bytes); - // save in work_ - work_[thread] = reinterpret_cast( v_ptr ); - // call constructor - new( work_[thread] ) work_struct; - } - return; -} -/// frees work_ for a specified thread -void free_work(size_t thread) -{ if( work_[thread] != CPPAD_NULL ) - { // call destructor - work_[thread]->~work_struct(); - // return memory to avialable pool for this thread - thread_alloc::return_memory( reinterpret_cast(work_[thread]) ); - // mark this thread as not allocated - work_[thread] = CPPAD_NULL; - } - return; -} -/// atomic_base function object corresponding to a certain index -static atomic_base* class_object(size_t index) -{ CPPAD_ASSERT_UNKNOWN( class_object().size() > index ); - return class_object()[index]; -} -/// atomic_base function name corresponding to a certain index -static const std::string& class_name(size_t index) -{ CPPAD_ASSERT_UNKNOWN( class_name().size() > index ); - return class_name()[index]; -} -/* -$begin atomic_option$$ -$spell - sq - enum - afun - bool - CppAD - std - typedef -$$ - -$section Set Atomic Function Options$$ - -$head Syntax$$ -$icode%afun%.option(%option_value%)%$$ -These settings do not apply to individual $icode afun$$ calls, -but rather all subsequent uses of the corresponding atomic operation -in an $cref ADFun$$ object. - -$head atomic_sparsity$$ -Note that, if you use $cref optimize$$, these sparsity patterns are used -to determine the $cref/dependency/dependency.cpp/$$ relationship between -argument and result variables. - -$subhead pack_sparsity_enum$$ -If $icode option_value$$ is $codei%atomic_base<%Base%>::pack_sparsity_enum%$$, -then the type used by $icode afun$$ for -$cref/sparsity patterns/glossary/Sparsity Pattern/$$, -(after the option is set) will be -$codei% - typedef CppAD::vectorBool %atomic_sparsity% -%$$ -If $icode r$$ is a sparsity pattern -for a matrix $latex R \in B^{p \times q}$$: -$icode%r%.size() == %p% * %q%$$. - -$subhead bool_sparsity_enum$$ -If $icode option_value$$ is $codei%atomic_base<%Base%>::bool_sparsity_enum%$$, -then the type used by $icode afun$$ for -$cref/sparsity patterns/glossary/Sparsity Pattern/$$, -(after the option is set) will be -$codei% - typedef CppAD::vector %atomic_sparsity% -%$$ -If $icode r$$ is a sparsity pattern -for a matrix $latex R \in B^{p \times q}$$: -$icode%r%.size() == %p% * %q%$$. - -$subhead set_sparsity_enum$$ -If $icode option_value$$ is $icode%atomic_base<%Base%>::set_sparsity_enum%$$, -then the type used by $icode afun$$ for -$cref/sparsity patterns/glossary/Sparsity Pattern/$$, -(after the option is set) will be -$codei% - typedef CppAD::vector< std::set > %atomic_sparsity% -%$$ -If $icode r$$ is a sparsity pattern -for a matrix $latex R \in B^{p \times q}$$: -$icode%r%.size() == %p%$$, and for $latex i = 0 , \ldots , p-1$$, -the elements of $icode%r%[%i%]%$$ are between zero and $latex q-1$$ inclusive. - -$end -*/ -void option(enum option_enum option_value) -{ switch( option_value ) - { case pack_sparsity_enum: - case bool_sparsity_enum: - case set_sparsity_enum: - sparsity_ = option_value; - break; - - default: - CPPAD_ASSERT_KNOWN( - false, - "atoic_base::option: option_value is not valid" - ); - } - return; -} -/* ------------------------------------------------------------------------------ -$begin atomic_afun$$ - -$spell - sq - mul - afun - const - CppAD - mat_mul.cpp -$$ - -$section Using AD Version of Atomic Function$$ - -$head Syntax$$ -$icode%afun%(%ax%, %ay%)%$$ - -$head Purpose$$ -Given $icode ax$$, -this call computes the corresponding value of $icode ay$$. -If $codei%AD<%Base%>%$$ operations are being recorded, -it enters the computation as an atomic operation in the recording; -see $cref/start recording/Independent/Start Recording/$$. - -$head ADVector$$ -The type $icode ADVector$$ must be a -$cref/simple vector class/SimpleVector/$$ with elements of type -$codei%AD<%Base%>%$$; see $cref/Base/atomic_ctor/atomic_base/Base/$$. - -$head afun$$ -is a $cref/atomic_user/atomic_ctor/atomic_user/$$ object -and this $icode afun$$ function call is implemented by the -$cref/atomic_base/atomic_ctor/atomic_base/$$ class. - -$head ax$$ -This argument has prototype -$codei% - const %ADVector%& %ax% -%$$ -and size must be equal to $icode n$$. -It specifies vector $latex x \in B^n$$ -at which an $codei%AD<%Base%>%$$ version of -$latex y = f(x)$$ is to be evaluated; see -$cref/Base/atomic_ctor/atomic_base/Base/$$. - -$head ay$$ -This argument has prototype -$codei% - %ADVector%& %ay% -%$$ -and size must be equal to $icode m$$. -The input values of its elements -are not specified (must not matter). -Upon return, it is an $codei%AD<%Base%>%$$ version of -$latex y = f(x)$$. - -$head Examples$$ -The following files contain example uses of -the AD version of atomic functions during recording: -$cref%get_started.cpp%atomic_get_started.cpp%Use Atomic Function%Recording%$$, -$cref%norm_sq.cpp%atomic_norm_sq.cpp%Use Atomic Function%Recording%$$, -$cref%reciprocal.cpp%atomic_reciprocal.cpp%Use Atomic Function%Recording%$$, -$cref%tangent.cpp%atomic_tangent.cpp%Use Atomic Function%Recording%$$, -$cref%mat_mul.cpp%atomic_mat_mul.cpp%Use Atomic Function%Recording%$$. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Implement the user call to afun(ax, ay) and old_atomic call to -afun(ax, ay, id). - -\tparam ADVector -A simple vector class with elements of type AD. - -\param id -optional extra information vector that is just passed through by CppAD, -and used by old_atomic derived class (not other derived classes). -This is an extra parameter to the virtual callbacks for old_atomic; -see the set_old member function. - -\param ax -is the argument vector for this call, -ax.size() determines the number of arguments. - -\param ay -is the result vector for this call, -ay.size() determines the number of results. -*/ -template -void operator()( - const ADVector& ax , - ADVector& ay , - size_t id = 0 ) -{ size_t i, j; - size_t n = ax.size(); - size_t m = ay.size(); -# ifndef NDEBUG - bool ok; - std::string msg = "atomic_base: " + afun_name() + ".eval: "; - if( (n == 0) | (m == 0) ) - { msg += "ax.size() or ay.size() is zero"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - size_t thread = thread_alloc::thread_num(); - allocate_work(thread); - vector & tx = work_[thread]->tx; - vector & ty = work_[thread]->ty; - vector & vx = work_[thread]->vx; - vector & vy = work_[thread]->vy; - // - if( vx.size() != n ) - { vx.resize(n); - tx.resize(n); - } - if( vy.size() != m ) - { vy.resize(m); - ty.resize(m); - } - // - // Determine tape corresponding to variables in ax - tape_id_t tape_id = 0; - local::ADTape* tape = CPPAD_NULL; - for(j = 0; j < n; j++) - { tx[j] = ax[j].value_; - vx[j] = Variable( ax[j] ); - if( vx[j] ) - { - if( tape_id == 0 ) - { tape = ax[j].tape_this(); - tape_id = ax[j].tape_id_; - CPPAD_ASSERT_UNKNOWN( tape != CPPAD_NULL ); - } -# ifndef NDEBUG - if( tape_id != ax[j].tape_id_ ) - { msg += afun_name() + - ": ax contains variables from different threads."; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } -# endif - } - } - // Use zero order forward mode to compute values - size_t p = 0, q = 0; - set_old(id); -# ifdef NDEBUG - forward(p, q, vx, vy, tx, ty); -# else - ok = forward(p, q, vx, vy, tx, ty); - if( ! ok ) - { msg += afun_name() + ": ok is false for " - "zero order forward mode calculation."; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } -# endif - bool record_operation = false; - for(i = 0; i < m; i++) - { - // pass back values - ay[i].value_ = ty[i]; - - // initialize entire vector parameters (not in tape) - ay[i].tape_id_ = 0; - ay[i].taddr_ = 0; - - // we need to record this operation if - // any of the eleemnts of ay are variables, - record_operation |= vy[i]; - } -# ifndef NDEBUG - if( record_operation & (tape == CPPAD_NULL) ) - { msg += - "all elements of vx are false but vy contains a true element"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - // if tape is not null, ay is on the tape - if( record_operation ) - { - // Operator that marks beginning of this atomic operation - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::UserOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::UserOp) == 4 ); - CPPAD_ASSERT_KNOWN( std::numeric_limits::max() >= - std::max( std::max( std::max(index_, id), n), m ), - "atomic_base: cppad_tape_addr_type maximum not large enough" - ); - tape->Rec_.PutArg(addr_t(index_), addr_t(id), addr_t(n), addr_t(m)); - tape->Rec_.PutOp(local::UserOp); - - // Now put n operators, one for each element of argument vector - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::UsravOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::UsrapOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::UsravOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::UsrapOp) == 1 ); - for(j = 0; j < n; j++) - { if( vx[j] ) - { // information for an argument that is a variable - tape->Rec_.PutArg(ax[j].taddr_); - tape->Rec_.PutOp(local::UsravOp); - } - else - { // information for an argument that is parameter - addr_t par = tape->Rec_.PutPar(ax[j].value_); - tape->Rec_.PutArg(par); - tape->Rec_.PutOp(local::UsrapOp); - } - } - - // Now put m operators, one for each element of result vector - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::UsrrpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::UsrrpOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::UsrrvOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::UsrrvOp) == 1 ); - for(i = 0; i < m; i++) - { if( vy[i] ) - { ay[i].taddr_ = tape->Rec_.PutOp(local::UsrrvOp); - ay[i].tape_id_ = tape_id; - } - else - { addr_t par = tape->Rec_.PutPar(ay[i].value_); - tape->Rec_.PutArg(par); - tape->Rec_.PutOp(local::UsrrpOp); - } - } - - // Put a duplicate UserOp at end of UserOp sequence - CPPAD_ASSERT_KNOWN( std::numeric_limits::max() >= - std::max( std::max( std::max(index_, id), n), m ), - "atomic_base: cppad_tape_addr_type maximum not large enough" - ); - tape->Rec_.PutArg(addr_t(index_), addr_t(id), addr_t(n), addr_t(m)); - tape->Rec_.PutOp(local::UserOp); - } - return; -} -/* ------------------------------------------------------------------------------ -$begin atomic_forward$$ -$spell - sq - mul.hpp - hes - afun - vx - vy - ty - Taylor - const - CppAD - bool -$$ - -$section Atomic Forward Mode$$ -$mindex callback virtual$$ - - -$head Syntax$$ -$icode%ok% = %afun%.forward(%p%, %q%, %vx%, %vy%, %tx%, %ty%)%$$ - -$head Purpose$$ -This virtual function is used by $cref atomic_afun$$ -to evaluate function values. -It is also used buy $cref/forward/Forward/$$ -to compute function vales and derivatives. - -$head Implementation$$ -This virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. -It can just return $icode%ok% == false%$$ -(and not compute anything) for values -of $icode%q% > 0%$$ that are greater than those used by your -$cref/forward/Forward/$$ mode calculations. - -$head p$$ -The argument $icode p$$ has prototype -$codei% - size_t %p% -%$$ -It specifies the lowest order Taylor coefficient that we are evaluating. -During calls to $cref atomic_afun$$, $icode%p% == 0%$$. - -$head q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the highest order Taylor coefficient that we are evaluating. -During calls to $cref atomic_afun$$, $icode%q% == 0%$$. - -$head vx$$ -The $code forward$$ argument $icode vx$$ has prototype -$codei% - const CppAD::vector& %vx% -%$$ -The case $icode%vx%.size() > 0%$$ only occurs while evaluating a call to -$cref atomic_afun$$. -In this case, -$icode%p% == %q% == 0%$$, -$icode%vx%.size() == %n%$$, and -for $latex j = 0 , \ldots , n-1$$, -$icode%vx%[%j%]%$$ is true if and only if -$icode%ax%[%j%]%$$ is a $cref/variable/glossary/Variable/$$ -in the corresponding call to -$codei% - %afun%(%ax%, %ay%) -%$$ -If $icode%vx%.size() == 0%$$, -then $icode%vy%.size() == 0%$$ and neither of these vectors -should be used. - -$head vy$$ -The $code forward$$ argument $icode vy$$ has prototype -$codei% - CppAD::vector& %vy% -%$$ -If $icode%vy%.size() == 0%$$, it should not be used. -Otherwise, -$icode%q% == 0%$$ and $icode%vy%.size() == %m%$$. -The input values of the elements of $icode vy$$ -are not specified (must not matter). -Upon return, for $latex j = 0 , \ldots , m-1$$, -$icode%vy%[%i%]%$$ is true if and only if -$icode%ay%[%i%]%$$ is a variable -(CppAD uses $icode vy$$ to reduce the necessary computations). - -$head tx$$ -The argument $icode tx$$ has prototype -$codei% - const CppAD::vector<%Base%>& %tx% -%$$ -and $icode%tx%.size() == (%q%+1)*%n%$$. -For $latex j = 0 , \ldots , n-1$$ and $latex k = 0 , \ldots , q$$, -we use the Taylor coefficient notation -$latex \[ -\begin{array}{rcl} - x_j^k & = & tx [ j * ( q + 1 ) + k ] - \\ - X_j (t) & = & x_j^0 + x_j^1 t^1 + \cdots + x_j^q t^q -\end{array} -\] $$ -Note that superscripts represent an index for $latex x_j^k$$ -and an exponent for $latex t^k$$. -Also note that the Taylor coefficients for $latex X(t)$$ correspond -to the derivatives of $latex X(t)$$ at $latex t = 0$$ in the following way: -$latex \[ - x_j^k = \frac{1}{ k ! } X_j^{(k)} (0) -\] $$ - -$head ty$$ -The argument $icode ty$$ has prototype -$codei% - CppAD::vector<%Base%>& %ty% -%$$ -and $icode%tx%.size() == (%q%+1)*%m%$$. -Upon return, -For $latex i = 0 , \ldots , m-1$$ and $latex k = 0 , \ldots , q$$, -$latex \[ -\begin{array}{rcl} - Y_i (t) & = & f_i [ X(t) ] - \\ - Y_i (t) & = & y_i^0 + y_i^1 t^1 + \cdots + y_i^q t^q + o ( t^q ) - \\ - ty [ i * ( q + 1 ) + k ] & = & y_i^k -\end{array} -\] $$ -where $latex o( t^q ) / t^q \rightarrow 0$$ as $latex t \rightarrow 0$$. -Note that superscripts represent an index for $latex y_j^k$$ -and an exponent for $latex t^k$$. -Also note that the Taylor coefficients for $latex Y(t)$$ correspond -to the derivatives of $latex Y(t)$$ at $latex t = 0$$ in the following way: -$latex \[ - y_j^k = \frac{1}{ k ! } Y_j^{(k)} (0) -\] $$ -If $latex p > 0$$, -for $latex i = 0 , \ldots , m-1$$ and $latex k = 0 , \ldots , p-1$$, -the input of $icode ty$$ satisfies -$latex \[ - ty [ i * ( q + 1 ) + k ] = y_i^k -\]$$ -and hence the corresponding elements need not be recalculated. - -$head ok$$ -If the required results are calculated, $icode ok$$ should be true. -Otherwise, it should be false. - -$head Discussion$$ -For example, suppose that $icode%q% == 2%$$, -and you know how to compute the function $latex f(x)$$, -its first derivative $latex f^{(1)} (x)$$, -and it component wise Hessian $latex f_i^{(2)} (x)$$. -Then you can compute $icode ty$$ using the following formulas: -$latex \[ -\begin{array}{rcl} -y_i^0 & = & Y(0) - = f_i ( x^0 ) -\\ -y_i^1 & = & Y^{(1)} ( 0 ) - = f_i^{(1)} ( x^0 ) X^{(1)} ( 0 ) - = f_i^{(1)} ( x^0 ) x^1 -\\ -y_i^2 -& = & \frac{1}{2 !} Y^{(2)} (0) -\\ -& = & \frac{1}{2} X^{(1)} (0)^\R{T} f_i^{(2)} ( x^0 ) X^{(1)} ( 0 ) - + \frac{1}{2} f_i^{(1)} ( x^0 ) X^{(2)} ( 0 ) -\\ -& = & \frac{1}{2} (x^1)^\R{T} f_i^{(2)} ( x^0 ) x^1 - + f_i^{(1)} ( x^0 ) x^2 -\end{array} -\] $$ -For $latex i = 0 , \ldots , m-1$$, and $latex k = 0 , 1 , 2$$, -$latex \[ - ty [ i * (q + 1) + k ] = y_i^k -\] $$ - -$children% - example/atomic/forward.cpp -%$$ -$head Examples$$ -The file $cref atomic_forward.cpp$$ contains an example and test -that uses this routine. -It returns true if the test passes and false if it fails. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Link from atomic_base to forward mode - -\param p [in] -lowerest order for this forward mode calculation. - -\param q [in] -highest order for this forward mode calculation. - -\param vx [in] -if size not zero, which components of \c x are variables - -\param vy [out] -if size not zero, which components of \c y are variables - -\param tx [in] -Taylor coefficients corresponding to \c x for this calculation. - -\param ty [out] -Taylor coefficient corresponding to \c y for this calculation - -See the forward mode in user's documentation for base_atomic -*/ -virtual bool forward( - size_t p , - size_t q , - const vector& vx , - vector& vy , - const vector& tx , - vector& ty ) -{ return false; } -/* ------------------------------------------------------------------------------ -$begin atomic_reverse$$ -$spell - sq - mul.hpp - afun - ty - px - py - Taylor - const - CppAD -$$ - -$section Atomic Reverse Mode$$ -$spell - bool -$$ - -$head Syntax$$ -$icode%ok% = %afun%.reverse(%q%, %tx%, %ty%, %px%, %py%)%$$ - -$head Purpose$$ -This function is used by $cref/reverse/Reverse/$$ -to compute derivatives. - -$head Implementation$$ -If you are using -$cref/reverse/Reverse/$$ mode, -this virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. -It can just return $icode%ok% == false%$$ -(and not compute anything) for values -of $icode q$$ that are greater than those used by your -$cref/reverse/Reverse/$$ mode calculations. - -$head q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the highest order Taylor coefficient that -computing the derivative of. - -$head tx$$ -The argument $icode tx$$ has prototype -$codei% - const CppAD::vector<%Base%>& %tx% -%$$ -and $icode%tx%.size() == (%q%+1)*%n%$$. -For $latex j = 0 , \ldots , n-1$$ and $latex k = 0 , \ldots , q$$, -we use the Taylor coefficient notation -$latex \[ -\begin{array}{rcl} - x_j^k & = & tx [ j * ( q + 1 ) + k ] - \\ - X_j (t) & = & x_j^0 + x_j^1 t^1 + \cdots + x_j^q t^q -\end{array} -\] $$ -Note that superscripts represent an index for $latex x_j^k$$ -and an exponent for $latex t^k$$. -Also note that the Taylor coefficients for $latex X(t)$$ correspond -to the derivatives of $latex X(t)$$ at $latex t = 0$$ in the following way: -$latex \[ - x_j^k = \frac{1}{ k ! } X_j^{(k)} (0) -\] $$ - -$head ty$$ -The argument $icode ty$$ has prototype -$codei% - const CppAD::vector<%Base%>& %ty% -%$$ -and $icode%tx%.size() == (%q%+1)*%m%$$. -For $latex i = 0 , \ldots , m-1$$ and $latex k = 0 , \ldots , q$$, -we use the Taylor coefficient notation -$latex \[ -\begin{array}{rcl} - Y_i (t) & = & f_i [ X(t) ] - \\ - Y_i (t) & = & y_i^0 + y_i^1 t^1 + \cdots + y_i^q t^q + o ( t^q ) - \\ - y_i^k & = & ty [ i * ( q + 1 ) + k ] -\end{array} -\] $$ -where $latex o( t^q ) / t^q \rightarrow 0$$ as $latex t \rightarrow 0$$. -Note that superscripts represent an index for $latex y_j^k$$ -and an exponent for $latex t^k$$. -Also note that the Taylor coefficients for $latex Y(t)$$ correspond -to the derivatives of $latex Y(t)$$ at $latex t = 0$$ in the following way: -$latex \[ - y_j^k = \frac{1}{ k ! } Y_j^{(k)} (0) -\] $$ - - -$head F$$ -We use the notation $latex \{ x_j^k \} \in B^{n \times (q+1)}$$ for -$latex \[ - \{ x_j^k \W{:} j = 0 , \ldots , n-1, k = 0 , \ldots , q \} -\]$$ -We use the notation $latex \{ y_i^k \} \in B^{m \times (q+1)}$$ for -$latex \[ - \{ y_i^k \W{:} i = 0 , \ldots , m-1, k = 0 , \ldots , q \} -\]$$ -We define the function -$latex F : B^{n \times (q+1)} \rightarrow B^{m \times (q+1)}$$ by -$latex \[ - y_i^k = F_i^k [ \{ x_j^k \} ] -\] $$ -Note that -$latex \[ - F_i^0 ( \{ x_j^k \} ) = f_i ( X(0) ) = f_i ( x^0 ) -\] $$ -We also note that -$latex F_i^\ell ( \{ x_j^k \} )$$ is a function of -$latex x^0 , \ldots , x^\ell$$ -and is determined by the derivatives of $latex f_i (x)$$ -up to order $latex \ell$$. - - -$head G, H$$ -We use $latex G : B^{m \times (q+1)} \rightarrow B$$ -to denote an arbitrary scalar valued function of $latex \{ y_i^k \}$$. -We use $latex H : B^{n \times (q+1)} \rightarrow B$$ -defined by -$latex \[ - H ( \{ x_j^k \} ) = G[ F( \{ x_j^k \} ) ] -\] $$ - -$head py$$ -The argument $icode py$$ has prototype -$codei% - const CppAD::vector<%Base%>& %py% -%$$ -and $icode%py%.size() == m * (%q%+1)%$$. -For $latex i = 0 , \ldots , m-1$$, $latex k = 0 , \ldots , q$$, -$latex \[ - py[ i * (q + 1 ) + k ] = \partial G / \partial y_i^k -\] $$ - -$subhead px$$ -The $icode px$$ has prototype -$codei% - CppAD::vector<%Base%>& %px% -%$$ -and $icode%px%.size() == n * (%q%+1)%$$. -The input values of the elements of $icode px$$ -are not specified (must not matter). -Upon return, -for $latex j = 0 , \ldots , n-1$$ and $latex \ell = 0 , \ldots , q$$, -$latex \[ -\begin{array}{rcl} -px [ j * (q + 1) + \ell ] & = & \partial H / \partial x_j^\ell -\\ -& = & -( \partial G / \partial \{ y_i^k \} ) \cdot - ( \partial \{ y_i^k \} / \partial x_j^\ell ) -\\ -& = & -\sum_{k=0}^q -\sum_{i=0}^{m-1} -( \partial G / \partial y_i^k ) ( \partial y_i^k / \partial x_j^\ell ) -\\ -& = & -\sum_{k=\ell}^q -\sum_{i=0}^{m-1} -py[ i * (q + 1 ) + k ] ( \partial F_i^k / \partial x_j^\ell ) -\end{array} -\] $$ -Note that we have used the fact that for $latex k < \ell$$, -$latex \partial F_i^k / \partial x_j^\ell = 0$$. - -$head ok$$ -The return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -If it is $code true$$, the corresponding evaluation succeeded, -otherwise it failed. - -$children% - example/atomic/reverse.cpp -%$$ -$head Examples$$ -The file $cref atomic_forward.cpp$$ contains an example and test -that uses this routine. -It returns true if the test passes and false if it fails. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Link from reverse mode sweep to users routine. - -\param q [in] -highest order for this reverse mode calculation. - -\param tx [in] -Taylor coefficients corresponding to \c x for this calculation. - -\param ty [in] -Taylor coefficient corresponding to \c y for this calculation - -\param px [out] -Partials w.r.t. the \c x Taylor coefficients. - -\param py [in] -Partials w.r.t. the \c y Taylor coefficients. - -See atomic_reverse mode use documentation -*/ -virtual bool reverse( - size_t q , - const vector& tx , - const vector& ty , - vector& px , - const vector& py ) -{ return false; } -/* --------------------------------------- --------------------------------------- -$begin atomic_for_sparse_jac$$ -$spell - sq - mul.hpp - afun - Jacobian - jac - const - CppAD - std - bool - std -$$ - -$section Atomic Forward Jacobian Sparsity Patterns$$ - -$head Syntax$$ -$icode%ok% = %afun%.for_sparse_jac(%q%, %r%, %s%, %x%) -%$$ - -$head Deprecated 2016-06-27$$ -$icode%ok% = %afun%.for_sparse_jac(%q%, %r%, %s%) -%$$ - -$head Purpose$$ -This function is used by $cref ForSparseJac$$ to compute -Jacobian sparsity patterns. -For a fixed matrix $latex R \in B^{n \times q}$$, -the Jacobian of $latex f( x + R * u)$$ with respect to $latex u \in B^q$$ is -$latex \[ - S(x) = f^{(1)} (x) * R -\] $$ -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex R$$, -$code for_sparse_jac$$ computes a sparsity pattern for $latex S(x)$$. - -$head Implementation$$ -If you are using -$cref ForSparseJac$$, -$cref ForSparseHes$$, or -$cref RevSparseHes$$, -one of the versions of this -virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. - -$subhead q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of columns in -$latex R \in B^{n \times q}$$ and the Jacobian -$latex S(x) \in B^{m \times q}$$. - -$subhead r$$ -This argument has prototype -$codei% - const %atomic_sparsity%& %r% -%$$ -and is a $cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex R \in B^{n \times q}$$. - -$subhead s$$ -This argument has prototype -$codei% - %atomic_sparsity%& %s% -%$$ -The input values of its elements -are not specified (must not matter). -Upon return, $icode s$$ is a -$cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex S(x) \in B^{m \times q}$$. - -$subhead x$$ -$index deprecated$$ -The argument has prototype -$codei% - const CppAD::vector<%Base%>& %x% -%$$ -and size is equal to the $icode n$$. -This is the $cref Value$$ value corresponding to the parameters in the -vector $cref/ax/atomic_afun/ax/$$ (when the atomic function was called). -To be specific, if -$codei% - if( Parameter(%ax%[%i%]) == true ) - %x%[%i%] = Value( %ax%[%i%] ); - else - %x%[%i%] = CppAD::numeric_limits<%Base%>::quiet_NaN(); -%$$ -The version of this function with out the $icode x$$ argument is deprecated; -i.e., you should include the argument even if you do not use it. - -$head ok$$ -The return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -If it is $code true$$, the corresponding evaluation succeeded, -otherwise it failed. - -$children% - example/atomic/for_sparse_jac.cpp -%$$ -$head Examples$$ -The file $cref atomic_for_sparse_jac.cpp$$ contains an example and test -that uses this routine. -It returns true if the test passes and false if it fails. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Link, after case split, from for_jac_sweep to atomic_base. - -\param q -is the column dimension for the Jacobian sparsity partterns. - -\param r -is the Jacobian sparsity pattern for the argument vector x - -\param s -is the Jacobian sparsity pattern for the result vector y - -\param x -is the integer value for x arguments that are parameters. -*/ -virtual bool for_sparse_jac( - size_t q , - const vector< std::set >& r , - vector< std::set >& s , - const vector& x ) -{ return false; } -virtual bool for_sparse_jac( - size_t q , - const vector& r , - vector& s , - const vector& x ) -{ return false; } -virtual bool for_sparse_jac( - size_t q , - const vectorBool& r , - vectorBool& s , - const vector& x ) -{ return false; } -// deprecated versions -virtual bool for_sparse_jac( - size_t q , - const vector< std::set >& r , - vector< std::set >& s ) -{ return false; } -virtual bool for_sparse_jac( - size_t q , - const vector& r , - vector& s ) -{ return false; } -virtual bool for_sparse_jac( - size_t q , - const vectorBool& r , - vectorBool& s ) -{ return false; } - -/*! -Link, before case split, from for_jac_sweep to atomic_base. - -\tparam InternalSparsity -Is the used internaly for sparsity calculations; i.e., -sparse_pack or sparse_list. - -\param x -is parameter arguments to the function, other components are nan. - -\param x_index -is the variable index, on the tape, for the arguments to this function. -This size of x_index is n, the number of arguments to this function. - -\param y_index -is the variable index, on the tape, for the results for this function. -This size of y_index is m, the number of results for this function. - -\param var_sparsity -On input, for j = 0, ... , n-1, the sparsity pattern with index x_index[j], -is the sparsity for the j-th argument to this atomic function. -On input, for i = 0, ... , m-1, the sparsity pattern with index y_index[i], -is empty. On output, it is the sparsity -for the j-th result for this atomic function. -*/ -template -void for_sparse_jac( - const vector& x , - const vector& x_index , - const vector& y_index , - InternalSparsity& var_sparsity ) -{ - // intial results are empty during forward mode - size_t q = var_sparsity.end(); - bool input_empty = true; - bool zero_empty = true; - bool transpose = false; - size_t m = y_index.size(); - bool ok = false; - size_t thread = thread_alloc::thread_num(); - allocate_work(thread); - // - std::string msg = ": atomic_base.for_sparse_jac: returned false"; - if( sparsity_ == pack_sparsity_enum ) - { vectorBool& pack_r ( work_[thread]->pack_r ); - vectorBool& pack_s ( work_[thread]->pack_s ); - local::get_internal_sparsity( - transpose, x_index, var_sparsity, pack_r - ); - // - pack_s.resize(m * q ); - ok = for_sparse_jac(q, pack_r, pack_s, x); - if( ! ok ) - ok = for_sparse_jac(q, pack_r, pack_s); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = pack_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, y_index, var_sparsity, pack_s - ); - } - else if( sparsity_ == bool_sparsity_enum ) - { vector& bool_r ( work_[thread]->bool_r ); - vector& bool_s ( work_[thread]->bool_s ); - local::get_internal_sparsity( - transpose, x_index, var_sparsity, bool_r - ); - bool_s.resize(m * q ); - ok = for_sparse_jac(q, bool_r, bool_s, x); - if( ! ok ) - ok = for_sparse_jac(q, bool_r, bool_s); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = bool_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, y_index, var_sparsity, bool_s - ); - } - else - { CPPAD_ASSERT_UNKNOWN( sparsity_ == set_sparsity_enum ); - vector< std::set >& set_r ( work_[thread]->set_r ); - vector< std::set >& set_s ( work_[thread]->set_s ); - local::get_internal_sparsity( - transpose, x_index, var_sparsity, set_r - ); - // - set_s.resize(m); - ok = for_sparse_jac(q, set_r, set_s, x); - if( ! ok ) - ok = for_sparse_jac(q, set_r, set_s); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = set_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, y_index, var_sparsity, set_s - ); - } - return; -} -/* --------------------------------------- --------------------------------------- -$begin atomic_rev_sparse_jac$$ -$spell - sq - mul.hpp - rt - afun - Jacobian - jac - CppAD - std - bool - const - hes -$$ - -$section Atomic Reverse Jacobian Sparsity Patterns$$ - -$head Syntax$$ -$icode%ok% = %afun%.rev_sparse_jac(%q%, %rt%, %st%, %x%) -%$$ - -$head Deprecated 2016-06-27$$ -$icode%ok% = %afun%.rev_sparse_jac(%q%, %rt%, %st%) -%$$ - -$head Purpose$$ -This function is used by -$cref RevSparseJac$$ to compute -Jacobian sparsity patterns. -If you are using $cref RevSparseJac$$, -one of the versions of this -virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. -$pre - -$$ -For a fixed matrix $latex R \in B^{q \times m}$$, -the Jacobian of $latex R * f( x )$$ with respect to $latex x \in B^n$$ is -$latex \[ - S(x) = R * f^{(1)} (x) -\] $$ -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex R$$, -$code rev_sparse_jac$$ computes a sparsity pattern for $latex S(x)$$. - -$head Implementation$$ -If you are using -$cref RevSparseJac$$ or $cref ForSparseHes$$, -this virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. - -$subhead q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of rows in -$latex R \in B^{q \times m}$$ and the Jacobian -$latex S(x) \in B^{q \times n}$$. - -$subhead rt$$ -This argument has prototype -$codei% - const %atomic_sparsity%& %rt% -%$$ -and is a -$cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex R^\R{T} \in B^{m \times q}$$. - -$subhead st$$ -This argument has prototype -$codei% - %atomic_sparsity%& %st% -%$$ -The input value of its elements -are not specified (must not matter). -Upon return, $icode s$$ is a -$cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex S(x)^\R{T} \in B^{n \times q}$$. - -$subhead x$$ -$index deprecated$$ -The argument has prototype -$codei% - const CppAD::vector<%Base%>& %x% -%$$ -and size is equal to the $icode n$$. -This is the $cref Value$$ corresponding to the parameters in the -vector $cref/ax/atomic_afun/ax/$$ (when the atomic function was called). -To be specific, if -$codei% - if( Parameter(%ax%[%i%]) == true ) - %x%[%i%] = Value( %ax%[%i%] ); - else - %x%[%i%] = CppAD::numeric_limits<%Base%>::quiet_NaN(); -%$$ -The version of this function with out the $icode x$$ argument is deprecated; -i.e., you should include the argument even if you do not use it. - -$head ok$$ -The return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -If it is $code true$$, the corresponding evaluation succeeded, -otherwise it failed. - -$children% - example/atomic/rev_sparse_jac.cpp -%$$ -$head Examples$$ -The file $cref atomic_rev_sparse_jac.cpp$$ contains an example and test -that uses this routine. -It returns true if the test passes and false if it fails. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Link, after case split, from rev_jac_sweep to atomic_base - -\param q [in] -is the row dimension for the Jacobian sparsity partterns - -\param rt [out] -is the tansposed Jacobian sparsity pattern w.r.t to range variables y - -\param st [in] -is the tansposed Jacobian sparsity pattern for the argument variables x - -\param x -is the integer value for x arguments that are parameters. -*/ -virtual bool rev_sparse_jac( - size_t q , - const vector< std::set >& rt , - vector< std::set >& st , - const vector& x ) -{ return false; } -virtual bool rev_sparse_jac( - size_t q , - const vector& rt , - vector& st , - const vector& x ) -{ return false; } -virtual bool rev_sparse_jac( - size_t q , - const vectorBool& rt , - vectorBool& st , - const vector& x ) -{ return false; } -// deprecated versions -virtual bool rev_sparse_jac( - size_t q , - const vector< std::set >& rt , - vector< std::set >& st ) -{ return false; } -virtual bool rev_sparse_jac( - size_t q , - const vector& rt , - vector& st ) -{ return false; } -virtual bool rev_sparse_jac( - size_t q , - const vectorBool& rt , - vectorBool& st ) -{ return false; } - -/*! -Link, before case split, from rev_jac_sweep to atomic_base. - -\tparam InternalSparsity -Is the used internaly for sparsity calculations; i.e., -sparse_pack or sparse_list. - -\param x -is parameter arguments to the function, other components are nan. - -\param x_index -is the variable index, on the tape, for the arguments to this function. -This size of x_index is n, the number of arguments to this function. - -\param y_index -is the variable index, on the tape, for the results for this function. -This size of y_index is m, the number of results for this function. - -\param var_sparsity -On input, for i = 0, ... , m-1, the sparsity pattern with index y_index[i], -is the sparsity for the i-th argument to this atomic function. -On output, for j = 0, ... , n-1, the sparsity pattern with index x_index[j], -the sparsity has been updated to remove y as a function of x. -*/ -template -void rev_sparse_jac( - const vector& x , - const vector& x_index , - const vector& y_index , - InternalSparsity& var_sparsity ) -{ - // initial results may be non-empty during reverse mode - size_t q = var_sparsity.end(); - bool input_empty = false; - bool zero_empty = true; - bool transpose = false; - size_t n = x_index.size(); - bool ok = false; - size_t thread = thread_alloc::thread_num(); - allocate_work(thread); - // - std::string msg = ": atomic_base.rev_sparse_jac: returned false"; - if( sparsity_ == pack_sparsity_enum ) - { vectorBool& pack_rt ( work_[thread]->pack_r ); - vectorBool& pack_st ( work_[thread]->pack_s ); - local::get_internal_sparsity( - transpose, y_index, var_sparsity, pack_rt - ); - // - pack_st.resize(n * q ); - ok = rev_sparse_jac(q, pack_rt, pack_st, x); - if( ! ok ) - ok = rev_sparse_jac(q, pack_rt, pack_st); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = pack_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, x_index, var_sparsity, pack_st - ); - } - else if( sparsity_ == bool_sparsity_enum ) - { vector& bool_rt ( work_[thread]->bool_r ); - vector& bool_st ( work_[thread]->bool_s ); - local::get_internal_sparsity( - transpose, y_index, var_sparsity, bool_rt - ); - bool_st.resize(n * q ); - ok = rev_sparse_jac(q, bool_rt, bool_st, x); - if( ! ok ) - ok = rev_sparse_jac(q, bool_rt, bool_st); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = bool_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, x_index, var_sparsity, bool_st - ); - } - else - { CPPAD_ASSERT_UNKNOWN( sparsity_ == set_sparsity_enum ); - vector< std::set >& set_rt ( work_[thread]->set_r ); - vector< std::set >& set_st ( work_[thread]->set_s ); - local::get_internal_sparsity( - transpose, y_index, var_sparsity, set_rt - ); - set_st.resize(n); - ok = rev_sparse_jac(q, set_rt, set_st, x); - if( ! ok ) - ok = rev_sparse_jac(q, set_rt, set_st); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = set_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, x_index, var_sparsity, set_st - ); - } - return; -} -/* --------------------------------------- --------------------------------------- -$begin atomic_for_sparse_hes$$ -$spell - sq - mul.hpp - vx - afun - Jacobian - jac - CppAD - std - bool - hes - const -$$ - -$section Atomic Forward Hessian Sparsity Patterns$$ - -$head Syntax$$ -$icode%ok% = %afun%.for_sparse_hes(%vx%, %r%, %s%, %h%, %x%)%$$ - -$head Deprecated 2016-06-27$$ -$icode%ok% = %afun%.for_sparse_hes(%vx%, %r%, %s%, %h%)%$$ - -$head Purpose$$ -This function is used by $cref ForSparseHes$$ to compute -Hessian sparsity patterns. -If you are using $cref ForSparseHes$$, -one of the versions of this -virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. -$pre - -$$ -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for -a diagonal matrix $latex R \in B^{n \times n}$$, and -a row vector $latex S \in B^{1 \times m}$$, -this routine computes the sparsity pattern for -$latex \[ - H(x) = R^\R{T} \cdot (S \cdot f)^{(2)}( x ) \cdot R -\] $$ - -$head Implementation$$ -If you are using and $cref ForSparseHes$$, -this virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. - -$subhead vx$$ -The argument $icode vx$$ has prototype -$codei% - const CppAD:vector& %vx% -%$$ -$icode%vx%.size() == %n%$$, and -for $latex j = 0 , \ldots , n-1$$, -$icode%vx%[%j%]%$$ is true if and only if -$icode%ax%[%j%]%$$ is a $cref/variable/glossary/Variable/$$ -in the corresponding call to -$codei% - %afun%(%ax%, %ay%) -%$$ - -$subhead r$$ -This argument has prototype -$codei% - const CppAD:vector& %r% -%$$ -and is a $cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -the diagonal of $latex R \in B^{n \times n}$$. - -$subhead s$$ -The argument $icode s$$ has prototype -$codei% - const CppAD:vector& %s% -%$$ -and its size is $icode m$$. -It is a sparsity pattern for $latex S \in B^{1 \times m}$$. - -$subhead h$$ -This argument has prototype -$codei% - %atomic_sparsity%& %h% -%$$ -The input value of its elements -are not specified (must not matter). -Upon return, $icode h$$ is a -$cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex H(x) \in B^{n \times n}$$ which is defined above. - -$subhead x$$ -$index deprecated$$ -The argument has prototype -$codei% - const CppAD::vector<%Base%>& %x% -%$$ -and size is equal to the $icode n$$. -This is the $cref Value$$ value corresponding to the parameters in the -vector $cref/ax/atomic_afun/ax/$$ (when the atomic function was called). -To be specific, if -$codei% - if( Parameter(%ax%[%i%]) == true ) - %x%[%i%] = Value( %ax%[%i%] ); - else - %x%[%i%] = CppAD::numeric_limits<%Base%>::quiet_NaN(); -%$$ -The version of this function with out the $icode x$$ argument is deprecated; -i.e., you should include the argument even if you do not use it. - -$children% - example/atomic/for_sparse_hes.cpp -%$$ -$head Examples$$ -The file $cref atomic_for_sparse_hes.cpp$$ contains an example and test -that uses this routine. -It returns true if the test passes and false if it fails. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Link, after case split, from for_hes_sweep to atomic_base. - -\param vx [in] -which componens of x are variables. - -\param r [in] -is the forward Jacobian sparsity pattern w.r.t the argument vector x. - -\param s [in] -is the reverse Jacobian sparsity pattern w.r.t the result vector y. - -\param h [out] -is the Hessian sparsity pattern w.r.t the argument vector x. - -\param x -is the integer value of the x arguments that are parameters. -*/ -virtual bool for_sparse_hes( - const vector& vx , - const vector& r , - const vector& s , - vector< std::set >& h , - const vector& x ) -{ return false; } -virtual bool for_sparse_hes( - const vector& vx , - const vector& r , - const vector& s , - vector& h , - const vector& x ) -{ return false; } -virtual bool for_sparse_hes( - const vector& vx , - const vector& r , - const vector& s , - vectorBool& h , - const vector& x ) -// deprecated -{ return false; } -virtual bool for_sparse_hes( - const vector& vx , - const vector& r , - const vector& s , - vector< std::set >& h ) -{ return false; } -// deprecated versions -virtual bool for_sparse_hes( - const vector& vx , - const vector& r , - const vector& s , - vector& h ) -{ return false; } -virtual bool for_sparse_hes( - const vector& vx , - const vector& r , - const vector& s , - vectorBool& h ) -{ return false; } -/*! -Link, before case split, from for_hes_sweep to atomic_base. - -\tparam InternalSparsity -Is the used internaly for sparsity calculations; i.e., -sparse_pack or sparse_list. - -\param x -is parameter arguments to the function, other components are nan. - -\param x_index -is the variable index, on the tape, for the arguments to this function. -This size of x_index is n, the number of arguments to this function. - -\param y_index -is the variable index, on the tape, for the results for this function. -This size of y_index is m, the number of results for this function. - -\param for_jac_sparsity -On input, for j = 0, ... , n-1, the sparsity pattern with index x_index[j], -is the forward Jacobian sparsity for the j-th argument to this atomic function. - -\param rev_jac_sparsity -On input, for i = 0, ... , m-1, the sparsity pattern with index y_index[i], -is the reverse Jacobian sparsity for the i-th result to this atomic function. -This shows which components of the result affect the function we are -computing the Hessian of. - -\param for_hes_sparsity -This is the sparsity pattern for the Hessian. On input, the non-linear -terms in the atomic fuction have not been included. Upon return, they -have been included. -*/ -template -void for_sparse_hes( - const vector& x , - const vector& x_index , - const vector& y_index , - const InternalSparsity& for_jac_sparsity , - const InternalSparsity& rev_jac_sparsity , - InternalSparsity& for_hes_sparsity ) -{ typedef typename InternalSparsity::const_iterator const_iterator; - CPPAD_ASSERT_UNKNOWN( rev_jac_sparsity.end() == 1 ); - size_t n = x_index.size(); - size_t m = y_index.size(); - bool ok = false; - size_t thread = thread_alloc::thread_num(); - allocate_work(thread); - // - // vx - vector vx(n); - for(size_t j = 0; j < n; j++) - vx[j] = x_index[j] != 0; - // - // bool_r - vector& bool_r( work_[thread]->bool_r ); - bool_r.resize(n); - for(size_t j = 0; j < n; j++) - { // check if we must compute row and column j of h - const_iterator itr(for_jac_sparsity, x_index[j]); - size_t i = *itr; - bool_r[j] = i < for_jac_sparsity.end(); - } - // - // bool s - vector& bool_s( work_[thread]->bool_s ); - bool_s.resize(m); - for(size_t i = 0; i < m; i++) - { // check if row i of result is included in h - bool_s[i] = rev_jac_sparsity.is_element(y_index[i], 0); - } - // - // h - vectorBool& pack_h( work_[thread]->pack_h ); - vector& bool_h( work_[thread]->bool_h ); - vector< std::set >& set_h( work_[thread]->set_h ); - // - // call user's version of atomic function - std::string msg = ": atomic_base.for_sparse_hes: returned false"; - if( sparsity_ == pack_sparsity_enum ) - { pack_h.resize(n * n); - ok = for_sparse_hes(vx, bool_r, bool_s, pack_h, x); - if( ! ok ) - ok = for_sparse_hes(vx, bool_r, bool_s, pack_h); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = pack_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - } - else if( sparsity_ == bool_sparsity_enum ) - { bool_h.resize(n * n); - ok = for_sparse_hes(vx, bool_r, bool_s, bool_h, x); - if( ! ok ) - ok = for_sparse_hes(vx, bool_r, bool_s, bool_h); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = bool_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - } - else - { CPPAD_ASSERT_UNKNOWN( sparsity_ == set_sparsity_enum ) - set_h.resize(n); - ok = for_sparse_hes(vx, bool_r, bool_s, set_h, x); - if( ! ok ) - ok = for_sparse_hes(vx, bool_r, bool_s, set_h); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = set_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - } - CPPAD_ASSERT_UNKNOWN( ok ); - // - // modify hessian in calling routine - for(size_t i = 0; i < n; i++) - { for(size_t j = 0; j < n; j++) - { if( (x_index[i] > 0) & (x_index[j] > 0) ) - { bool flag = false; - switch( sparsity_ ) - { case pack_sparsity_enum: - flag = pack_h[i * n + j]; - break; - // - case bool_sparsity_enum: - flag = bool_h[i * n + j]; - break; - // - case set_sparsity_enum: - flag = set_h[i].find(j) != set_h[i].end(); - break; - } - if( flag ) - { const_iterator itr_i(for_jac_sparsity, x_index[i]); - size_t i_x = *itr_i; - while( i_x < for_jac_sparsity.end() ) - { for_hes_sparsity.binary_union( - i_x, i_x, x_index[j], for_jac_sparsity - ); - i_x = *(++itr_i); - } - const_iterator itr_j(for_jac_sparsity, x_index[j]); - size_t j_x = *itr_j; - while( j_x < for_jac_sparsity.end() ) - { for_hes_sparsity.binary_union( - j_x, j_x, x_index[i], for_jac_sparsity - ); - j_x = *(++itr_j); - } - } - } - } - } - return; -} -/* --------------------------------------- --------------------------------------- -$begin atomic_rev_sparse_hes$$ -$spell - sq - mul.hpp - vx - afun - Jacobian - jac - CppAD - std - bool - hes - const -$$ - -$section Atomic Reverse Hessian Sparsity Patterns$$ - -$head Syntax$$ -$icode%ok% = %afun%.rev_sparse_hes(%vx%, %s%, %t%, %q%, %r%, %u%, %v%, %x%)%$$ - -$head Deprecated 2016-06-27$$ -$icode%ok% = %afun%.rev_sparse_hes(%vx%, %s%, %t%, %q%, %r%, %u%, %v%)%$$ - -$head Purpose$$ -This function is used by $cref RevSparseHes$$ to compute -Hessian sparsity patterns. -If you are using $cref RevSparseHes$$ to compute -one of the versions of this -virtual function muse be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. -$pre - -$$ -There is an unspecified scalar valued function -$latex g : B^m \rightarrow B$$. -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for -$latex R \in B^{n \times q}$$, -and information about the function $latex z = g(y)$$, -this routine computes the sparsity pattern for -$latex \[ - V(x) = (g \circ f)^{(2)}( x ) R -\] $$ - -$head Implementation$$ -If you are using and $cref RevSparseHes$$, -this virtual function must be defined by the -$cref/atomic_user/atomic_ctor/atomic_user/$$ class. - -$subhead vx$$ -The argument $icode vx$$ has prototype -$codei% - const CppAD:vector& %vx% -%$$ -$icode%vx%.size() == %n%$$, and -for $latex j = 0 , \ldots , n-1$$, -$icode%vx%[%j%]%$$ is true if and only if -$icode%ax%[%j%]%$$ is a $cref/variable/glossary/Variable/$$ -in the corresponding call to -$codei% - %afun%(%ax%, %ay%) -%$$ - -$subhead s$$ -The argument $icode s$$ has prototype -$codei% - const CppAD:vector& %s% -%$$ -and its size is $icode m$$. -It is a sparsity pattern for -$latex S(x) = g^{(1)} [ f(x) ] \in B^{1 \times m}$$. - -$subhead t$$ -This argument has prototype -$codei% - CppAD:vector& %t% -%$$ -and its size is $icode m$$. -The input values of its elements -are not specified (must not matter). -Upon return, $icode t$$ is a -sparsity pattern for -$latex T(x) \in B^{1 \times n}$$ where -$latex \[ - T(x) = (g \circ f)^{(1)} (x) = S(x) * f^{(1)} (x) -\]$$ - -$subhead q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of columns in -$latex R \in B^{n \times q}$$, -$latex U(x) \in B^{m \times q}$$, and -$latex V(x) \in B^{n \times q}$$. - -$subhead r$$ -This argument has prototype -$codei% - const %atomic_sparsity%& %r% -%$$ -and is a $cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex R \in B^{n \times q}$$. - -$head u$$ -This argument has prototype -$codei% - const %atomic_sparsity%& %u% -%$$ -and is a $cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex U(x) \in B^{m \times q}$$ which is defined by -$latex \[ -\begin{array}{rcl} -U(x) -& = & -\{ \partial_u \{ \partial_y g[ y + f^{(1)} (x) R u ] \}_{y=f(x)} \}_{u=0} -\\ -& = & -\partial_u \{ g^{(1)} [ f(x) + f^{(1)} (x) R u ] \}_{u=0} -\\ -& = & -g^{(2)} [ f(x) ] f^{(1)} (x) R -\end{array} -\] $$ - -$subhead v$$ -This argument has prototype -$codei% - %atomic_sparsity%& %v% -%$$ -The input value of its elements -are not specified (must not matter). -Upon return, $icode v$$ is a -$cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ pattern for -$latex V(x) \in B^{n \times q}$$ which is defined by -$latex \[ -\begin{array}{rcl} -V(x) -& = & -\partial_u [ \partial_x (g \circ f) ( x + R u ) ]_{u=0} -\\ -& = & -\partial_u [ (g \circ f)^{(1)}( x + R u ) ]_{u=0} -\\ -& = & -(g \circ f)^{(2)}( x ) R -\\ -& = & -f^{(1)} (x)^\R{T} g^{(2)} [ f(x) ] f^{(1)} (x) R -+ -\sum_{i=1}^m g_i^{(1)} [ f(x) ] \; f_i^{(2)} (x) R -\\ -& = & -f^{(1)} (x)^\R{T} U(x) -+ -\sum_{i=1}^m S_i (x) \; f_i^{(2)} (x) R -\end{array} -\] $$ - -$subhead x$$ -$index deprecated$$ -The argument has prototype -$codei% - const CppAD::vector<%Base%>& %x% -%$$ -and size is equal to the $icode n$$. -This is the $cref Value$$ value corresponding to the parameters in the -vector $cref/ax/atomic_afun/ax/$$ (when the atomic function was called). -To be specific, if -$codei% - if( Parameter(%ax%[%i%]) == true ) - %x%[%i%] = Value( %ax%[%i%] ); - else - %x%[%i%] = CppAD::numeric_limits<%Base%>::quiet_NaN(); -%$$ -The version of this function with out the $icode x$$ argument is deprecated; -i.e., you should include the argument even if you do not use it. - -$children% - example/atomic/rev_sparse_hes.cpp -%$$ -$head Examples$$ -The file $cref atomic_rev_sparse_hes.cpp$$ contains an example and test -that uses this routine. -It returns true if the test passes and false if it fails. - -$end ------------------------------------------------------------------------------ -*/ -/*! -Link from reverse Hessian sparsity sweep to base_atomic - -\param vx [in] -which componens of x are variables. - -\param s [in] -is the reverse Jacobian sparsity pattern w.r.t the result vector y. - -\param t [out] -is the reverse Jacobian sparsity pattern w.r.t the argument vector x. - -\param q [in] -is the column dimension for the sparsity partterns. - -\param r [in] -is the forward Jacobian sparsity pattern w.r.t the argument vector x - -\param u [in] -is the Hessian sparsity pattern w.r.t the result vector y. - -\param v [out] -is the Hessian sparsity pattern w.r.t the argument vector x. - -\param x [in] -is the integer value of the x arguments that are parameters. -*/ -virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vector< std::set >& r , - const vector< std::set >& u , - vector< std::set >& v , - const vector& x ) -{ return false; } -virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vector& r , - const vector& u , - vector& v , - const vector& x ) -{ return false; } -virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vectorBool& r , - const vectorBool& u , - vectorBool& v , - const vector& x ) -{ return false; } -// deprecated -virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vector< std::set >& r , - const vector< std::set >& u , - vector< std::set >& v ) -{ return false; } -virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vector& r , - const vector& u , - vector& v ) -{ return false; } -virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vectorBool& r , - const vectorBool& u , - vectorBool& v ) -{ return false; } -/*! -Link, before case split, from rev_hes_sweep to atomic_base. - -\tparam InternalSparsity -Is the used internaly for sparsity calculations; i.e., -sparse_pack or sparse_list. - -\param x -is parameter arguments to the function, other components are nan. - -\param x_index -is the variable index, on the tape, for the arguments to this function. -This size of x_index is n, the number of arguments to this function. - -\param y_index -is the variable index, on the tape, for the results for this function. -This size of y_index is m, the number of results for this function. - -\param for_jac_sparsity -On input, for j = 0, ... , n-1, the sparsity pattern with index x_index[j], -is the forward Jacobian sparsity for the j-th argument to this atomic function. - -\param rev_jac_flag -This shows which variables affect the function we are -computing the Hessian of. -On input, for i = 0, ... , m-1, the rev_jac_flag[ y_index[i] ] is true -if the Jacobian of function (we are computing sparsity for) is no-zero. -Upon return, for j = 0, ... , n-1, rev_jac_flag [ x_index[j] ] -as been adjusted to accound removing this atomic function. - -\param rev_hes_sparsity -This is the sparsity pattern for the Hessian. -On input, for i = 0, ... , m-1, row y_index[i] is the reverse Hessian sparsity -with one of the partials with respect to to y_index[i]. -*/ -template -void rev_sparse_hes( - const vector& x , - const vector& x_index , - const vector& y_index , - const InternalSparsity& for_jac_sparsity , - bool* rev_jac_flag , - InternalSparsity& rev_hes_sparsity ) -{ CPPAD_ASSERT_UNKNOWN( for_jac_sparsity.end() == rev_hes_sparsity.end() ); - size_t q = rev_hes_sparsity.end(); - size_t n = x_index.size(); - size_t m = y_index.size(); - bool ok = false; - size_t thread = thread_alloc::thread_num(); - allocate_work(thread); - bool zero_empty = true; - bool input_empty = false; - bool transpose = false; - // - // vx - vector vx(n); - for(size_t j = 0; j < n; j++) - vx[j] = x_index[j] != 0; - // - // note that s and t are vectors so transpose does not matter for bool case - vector bool_s( work_[thread]->bool_s ); - vector bool_t( work_[thread]->bool_t ); - // - bool_s.resize(m); - bool_t.resize(n); - // - for(size_t i = 0; i < m; i++) - { if( y_index[i] > 0 ) - bool_s[i] = rev_jac_flag[ y_index[i] ]; - } - // - std::string msg = ": atomic_base.rev_sparse_hes: returned false"; - if( sparsity_ == pack_sparsity_enum ) - { vectorBool& pack_r( work_[thread]->pack_r ); - vectorBool& pack_u( work_[thread]->pack_u ); - vectorBool& pack_v( work_[thread]->pack_h ); - // - pack_v.resize(n * q); - // - local::get_internal_sparsity( - transpose, x_index, for_jac_sparsity, pack_r - ); - local::get_internal_sparsity( - transpose, y_index, rev_hes_sparsity, pack_u - ); - // - ok = rev_sparse_hes(vx, bool_s, bool_t, q, pack_r, pack_u, pack_v, x); - if( ! ok ) - ok = rev_sparse_hes(vx, bool_s, bool_t, q, pack_r, pack_u, pack_v); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = pack_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, x_index, rev_hes_sparsity, pack_v - ); - } - else if( sparsity_ == bool_sparsity_enum ) - { vector& bool_r( work_[thread]->bool_r ); - vector& bool_u( work_[thread]->bool_u ); - vector& bool_v( work_[thread]->bool_h ); - // - bool_v.resize(n * q); - // - local::get_internal_sparsity( - transpose, x_index, for_jac_sparsity, bool_r - ); - local::get_internal_sparsity( - transpose, y_index, rev_hes_sparsity, bool_u - ); - // - ok = rev_sparse_hes(vx, bool_s, bool_t, q, bool_r, bool_u, bool_v, x); - if( ! ok ) - ok = rev_sparse_hes(vx, bool_s, bool_t, q, bool_r, bool_u, bool_v); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = bool_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, x_index, rev_hes_sparsity, bool_v - ); - } - else - { CPPAD_ASSERT_UNKNOWN( sparsity_ == set_sparsity_enum ); - vector< std::set >& set_r( work_[thread]->set_r ); - vector< std::set >& set_u( work_[thread]->set_u ); - vector< std::set >& set_v( work_[thread]->set_h ); - // - set_v.resize(n); - // - local::get_internal_sparsity( - transpose, x_index, for_jac_sparsity, set_r - ); - local::get_internal_sparsity( - transpose, y_index, rev_hes_sparsity, set_u - ); - // - ok = rev_sparse_hes(vx, bool_s, bool_t, q, set_r, set_u, set_v, x); - if( ! ok ) - ok = rev_sparse_hes(vx, bool_s, bool_t, q, set_r, set_u, set_v); - if( ! ok ) - { msg = afun_name() + msg + " sparsity = set_sparsity_enum"; - CPPAD_ASSERT_KNOWN(false, msg.c_str()); - } - local::set_internal_sparsity(zero_empty, input_empty, - transpose, x_index, rev_hes_sparsity, set_v - ); - } - for(size_t j = 0; j < n; j++) - { if( x_index[j] > 0 ) - rev_jac_flag[ x_index[j] ] |= bool_t[j]; - } - return; -} -/* ------------------------------------------------------------------------------- -$begin atomic_base_clear$$ -$spell - sq - alloc -$$ - -$section Free Static Variables$$ -$mindex clear$$ - -$head Syntax$$ -$codei%atomic_base<%Base%>::clear()%$$ - -$head Purpose$$ -Each $code atomic_base$$ objects holds onto work space in order to -avoid repeated memory allocation calls and thereby increase speed -(until it is deleted). -If an the $code atomic_base$$ object is global or static because, -the it does not get deleted. -This is a problem when using -$code thread_alloc$$ $cref/free_all/ta_free_all/$$ -to check that all allocated memory has been freed. -Calling this $code clear$$ function will free all the -memory currently being held onto by the -$codei%atomic_base<%Base%>%$$ class. - -$head Future Use$$ -If there is future use of an $code atomic_base$$ object, -after a call to $code clear$$, -the work space will be reallocated and held onto. - -$head Restriction$$ -This routine cannot be called -while in $cref/parallel/ta_in_parallel/$$ execution mode. - -$end ------------------------------------------------------------------------------- -*/ -/*! -Free all thread_alloc static memory held by atomic_base (avoids reallocations). -(This does not include class_object() which is an std::vector.) -*/ -/// Free vector memory used by this class (work space) -static void clear(void) -{ CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "cannot use atomic_base clear during parallel execution" - ); - size_t i = class_object().size(); - while(i--) - { atomic_base* op = class_object()[i]; - if( op != CPPAD_NULL ) - { for(size_t thread = 0; thread < CPPAD_MAX_NUM_THREADS; thread++) - op->free_work(thread); - } - } - return; -} -// ------------------------------------------------------------------------- -/*! -Set value of id (used by deprecated old_atomic class) - -This function is called just before calling any of the virtual function -and has the corresponding id of the corresponding virtual call. -*/ -virtual void set_old(size_t id) -{ } -// --------------------------------------------------------------------------- -}; -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/azmul.hpp b/external/cppad/include/cppad/core/azmul.hpp deleted file mode 100644 index cc8b4bf48..000000000 --- a/external/cppad/include/cppad/core/azmul.hpp +++ /dev/null @@ -1,213 +0,0 @@ -# ifndef CPPAD_CORE_AZMUL_HPP -# define CPPAD_CORE_AZMUL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin azmul$$ -$spell - azmul - const - namespace - Vec -$$ - -$section Absolute Zero Multiplication$$ - -$head Syntax$$ -$icode%z% = azmul(%x%, %y%)%$$ - -$head Purpose$$ -Evaluates multiplication with an absolute zero -for any of the possible types listed below. -The result is given by -$latex \[ -z = \left\{ \begin{array}{ll} - 0 & {\rm if} \; x = 0 \\ - x \cdot y & {\rm otherwise} -\end{array} \right. -\] $$ -Note if $icode x$$ is zero and $icode y$$ is infinity, -ieee multiplication would result in not a number whereas -$icode z$$ would be zero. - -$head Base$$ -If $icode Base$$ satisfies the -$cref/base type requirements/base_require/$$ -and arguments $icode x$$, $icode y$$ have prototypes -$codei% - const %Base%& %x% - const %Base%& %y% -%$$ -then the result $icode z$$ has prototype -$codei% - %Base% %z% -%$$ - -$head AD$$ -If the arguments $icode x$$, $icode y$$ have prototype -$codei% - const AD<%Base%>& %x% - const AD<%Base%>& %y% -%$$ -then the result $icode z$$ has prototype -$codei% - AD<%Base%> %z% -%$$ - -$head VecAD$$ -If the arguments $icode x$$, $icode y$$ have prototype -$codei% - const VecAD<%Base%>::reference& %x% - const VecAD<%Base%>::reference& %y% -%$$ -then the result $icode z$$ has prototype -$codei% - AD<%Base%> %z% -%$$ - -$head Example$$ -$children% - example/general/azmul.cpp -%$$ -The file -$cref azmul.cpp$$ -is an examples and tests of this function. -It returns true if it succeeds and false otherwise. - -$end -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -// ========================================================================== - -// case where x and y are AD ------------------------------------------- -template AD -azmul(const AD& x, const AD& y) -{ - // compute the Base part - AD result; - result.value_ = azmul(x.value_, y.value_); - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return result; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_x = x.tape_id_ == tape_id; - bool var_y = y.tape_id_ == tape_id; - - if( var_x ) - { if( var_y ) - { // result = azmul(variable, variable) - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::ZmulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::ZmulvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(x.taddr_, y.taddr_); - - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::ZmulvvOp); - - // make result a variable - result.tape_id_ = tape_id; - } - else if( IdenticalZero( y.value_ ) ) - { // result = variable * 0 - } - else if( IdenticalOne( y.value_ ) ) - { // result = variable * 1 - result.make_variable(x.tape_id_, x.taddr_); - } - else - { // result = zmul(variable, parameter) - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::ZmulvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::ZmulvpOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(y.value_); - tape->Rec_.PutArg(x.taddr_, p); - - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::ZmulvpOp); - - // make result a variable - result.tape_id_ = tape_id; - } - } - else if( var_y ) - { if( IdenticalZero(x.value_) ) - { // result = 0 * variable - } - else if( IdenticalOne( x.value_ ) ) - { // result = 1 * variable - result.make_variable(y.tape_id_, y.taddr_); - } - else - { // result = zmul(parameter, variable) - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::ZmulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::ZmulpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(x.value_); - tape->Rec_.PutArg(p, y.taddr_); - - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::ZmulpvOp); - - // make result a variable - result.tape_id_ = tape_id; - } - } - return result; -} -// ========================================================================= -// Fold operations into case above -// ------------------------------------------------------------------------- -// Operations with VecAD_reference and AD only - -template AD -azmul(const AD& x, const VecAD_reference& y) -{ return azmul(x, y.ADBase()); } - -template AD -azmul(const VecAD_reference& x, const VecAD_reference& y) -{ return azmul(x.ADBase(), y.ADBase()); } - -template AD -azmul(const VecAD_reference& x, const AD& y) -{ return azmul(x.ADBase(), y); } -// ------------------------------------------------------------------------- -// Operations with Base - -template AD -azmul(const Base& x, const AD& y) -{ return azmul(AD(x), y); } - -template AD -azmul(const Base& x, const VecAD_reference& y) -{ return azmul(AD(x), y.ADBase()); } - -template AD -azmul(const AD& x, const Base& y) -{ return azmul(x, AD(y)); } - -template AD -azmul(const VecAD_reference& x, const Base& y) -{ return azmul(x.ADBase(), AD(y)); } - -// ========================================================================== -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/base_complex.hpp b/external/cppad/include/cppad/core/base_complex.hpp deleted file mode 100644 index c4a60d90f..000000000 --- a/external/cppad/include/cppad/core/base_complex.hpp +++ /dev/null @@ -1,384 +0,0 @@ -# ifndef CPPAD_CORE_BASE_COMPLEX_HPP -# define CPPAD_CORE_BASE_COMPLEX_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -/* -$begin base_complex.hpp$$ -$spell - azmul - expm1 - atanh - acosh - asinh - endif - eps - abs_geq - Rel - Lt Le Eq Ge Gt - imag - gcc - isnan - cppad.hpp - sqrt - exp - cos - std - const - CppAD - Op - inline - enum - undef - acos - asin - atan - erf - Cond - namespace - bool -$$ - - -$section Enable use of AD where Base is std::complex$$ - -$children%example/general/complex_poly.cpp -%$$ -$head Example$$ -The file $cref complex_poly.cpp$$ contains an example use of -$code std::complex$$ type for a CppAD $icode Base$$ type. -It returns true if it succeeds and false otherwise. - -$head Include Order$$ -This file is included before $code $$ -so it is necessary to define the error handler -in addition to including -$cref/base_require.hpp/base_require/Include Order/$$ -$srccode%cpp% */ -# include -# include -# include -# include - -/* %$$ - -$head CondExpOp$$ -The type $code std::complex$$ does not supports the -$code <$$, $code <=$$, $code ==$$, $code >=$$, and $code >$$ operators; see -$cref/not ordered/base_cond_exp/CondExpTemplate/Not Ordered/$$. -Hence its $code CondExpOp$$ function is defined by -$srccode%cpp% */ -namespace CppAD { - inline std::complex CondExpOp( - enum CppAD::CompareOp cop , - const std::complex &left , - const std::complex &right , - const std::complex &trueCase , - const std::complex &falseCase ) - { CppAD::ErrorHandler::Call( - true , __LINE__ , __FILE__ , - "std::complex CondExpOp(...)", - "Error: cannot use CondExp with a complex type" - ); - return std::complex(0); - } -} -/* %$$ - -$head CondExpRel$$ -The $cref/CPPAD_COND_EXP_REL/base_cond_exp/CondExpRel/$$ macro invocation -$srccode%cpp% */ -namespace CppAD { - CPPAD_COND_EXP_REL( std::complex ) -} -/* %$$ -used $code CondExpOp$$ above to -define $codei%CondExp%Rel%$$ for $code std::complex$$ arguments -and $icode%Rel%$$ equal to -$code Lt$$, $code Le$$, $code Eq$$, $code Ge$$, and $code Gt$$. - -$head EqualOpSeq$$ -Complex numbers do not carry operation sequence information. -Thus they are equal in this sense if and only if there values are equal. -$srccode%cpp% */ -namespace CppAD { - inline bool EqualOpSeq( - const std::complex &x , - const std::complex &y ) - { return x == y; - } -} -/* %$$ - -$head Identical$$ -Complex numbers do not carry operation sequence information. -Thus they are all parameters so the identical functions just check values. -$srccode%cpp% */ -namespace CppAD { - inline bool IdenticalPar(const std::complex &x) - { return true; } - inline bool IdenticalZero(const std::complex &x) - { return (x == std::complex(0., 0.) ); } - inline bool IdenticalOne(const std::complex &x) - { return (x == std::complex(1., 0.) ); } - inline bool IdenticalEqualPar( - const std::complex &x, const std::complex &y) - { return (x == y); } -} -/* %$$ - -$head Ordered$$ -Complex types do not support comparison operators, -$srccode%cpp% */ -# undef CPPAD_USER_MACRO -# define CPPAD_USER_MACRO(Fun) \ -inline bool Fun(const std::complex& x) \ -{ CppAD::ErrorHandler::Call( \ - true , __LINE__ , __FILE__ , \ - #Fun"(x)", \ - "Error: cannot use " #Fun " with x complex " \ - ); \ - return false; \ -} -namespace CppAD { - CPPAD_USER_MACRO(LessThanZero) - CPPAD_USER_MACRO(LessThanOrZero) - CPPAD_USER_MACRO(GreaterThanOrZero) - CPPAD_USER_MACRO(GreaterThanZero) - inline bool abs_geq( - const std::complex& x , - const std::complex& y ) - { return std::abs(x) >= std::abs(y); } -} -/* %$$ - -$head Integer$$ -The implementation of this function must agree -with the CppAD user specifications for complex arguments to the -$cref/Integer/Integer/x/Complex Types/$$ function: -$srccode%cpp% */ -namespace CppAD { - inline int Integer(const std::complex &x) - { return static_cast( x.real() ); } -} -/* %$$ - -$head azmul$$ -$srccode%cpp% */ -namespace CppAD { - CPPAD_AZMUL( std::complex ) -} -/* %$$ - -$head isnan$$ -The gcc 4.1.1 complier defines the function -$codei% - int std::complex::isnan( std::complex %z% ) -%$$ -(which is not specified in the C++ 1998 standard ISO/IEC 14882). -This causes an ambiguity between the function above and the CppAD -$cref/isnan/nan/$$ template function. -We avoid this ambiguity by defining a non-template version of -this function in the CppAD namespace. -$srccode%cpp% */ -namespace CppAD { - inline bool isnan(const std::complex& z) - { return (z != z); - } -} -/* %$$ - -$head Valid Unary Math$$ -The following macro invocations define the standard unary -math functions that are valid with complex arguments and are -required to use $code AD< std::complex >$$. -$srccode%cpp% */ -namespace CppAD { - CPPAD_STANDARD_MATH_UNARY(std::complex, cos) - CPPAD_STANDARD_MATH_UNARY(std::complex, cosh) - CPPAD_STANDARD_MATH_UNARY(std::complex, exp) - CPPAD_STANDARD_MATH_UNARY(std::complex, log) - CPPAD_STANDARD_MATH_UNARY(std::complex, sin) - CPPAD_STANDARD_MATH_UNARY(std::complex, sinh) - CPPAD_STANDARD_MATH_UNARY(std::complex, sqrt) -} -/* %$$ - -$head Invalid Unary Math$$ -The following macro definition and invocations define the standard unary -math functions that are invalid with complex arguments and are -required to use $code AD< std::complex >$$. -$srccode%cpp% */ -# undef CPPAD_USER_MACRO -# define CPPAD_USER_MACRO(Fun) \ -inline std::complex Fun(const std::complex& x) \ -{ CppAD::ErrorHandler::Call( \ - true , __LINE__ , __FILE__ , \ - #Fun"(x)", \ - "Error: cannot use " #Fun " with x complex " \ - ); \ - return std::complex(0); \ -} -namespace CppAD { - CPPAD_USER_MACRO(abs) - CPPAD_USER_MACRO(fabs) - CPPAD_USER_MACRO(acos) - CPPAD_USER_MACRO(asin) - CPPAD_USER_MACRO(atan) - CPPAD_USER_MACRO(sign) -# if CPPAD_USE_CPLUSPLUS_2011 - CPPAD_USER_MACRO(erf) - CPPAD_USER_MACRO(asinh) - CPPAD_USER_MACRO(acosh) - CPPAD_USER_MACRO(atanh) - CPPAD_USER_MACRO(expm1) - CPPAD_USER_MACRO(log1p) -# endif -} -/* %$$ - -$head pow $$ -The following defines a $code CppAD::pow$$ function that -is required to use $code AD< std::complex >$$: -$srccode%cpp% */ -namespace CppAD { - inline std::complex pow( - const std::complex &x , - const std::complex &y ) - { return std::pow(x, y); } -} -/* %$$ - -$head numeric_limits$$ -The following defines the CppAD $cref numeric_limits$$ -for the type $code std::complex$$: -$srccode%cpp% */ -namespace CppAD { - CPPAD_NUMERIC_LIMITS(double, std::complex) -} -/* %$$ - -$head to_string$$ -The following defines the function CppAD $cref to_string$$ -for the type $code std::complex$$: -$srccode%cpp% */ -namespace CppAD { - CPPAD_TO_STRING(std::complex) -} -/* %$$ -$end -*/ -# undef CPPAD_USER_MACRO_ONE -# define CPPAD_USER_MACRO_ONE(Fun) \ -inline bool Fun(const std::complex& x) \ -{ CppAD::ErrorHandler::Call( \ - true , __LINE__ , __FILE__ , \ - #Fun"(x)", \ - "Error: cannot use " #Fun " with x complex " \ - ); \ - return false; \ -} -# undef CPPAD_USER_MACRO_TWO -# define CPPAD_USER_MACRO_TWO(Fun) \ -inline std::complex Fun(const std::complex& x) \ -{ CppAD::ErrorHandler::Call( \ - true , __LINE__ , __FILE__ , \ - #Fun"(x)", \ - "Error: cannot use " #Fun " with x complex " \ - ); \ - return std::complex(0); \ -} -namespace CppAD { - // CondExpOp ------------------------------------------------------ - inline std::complex CondExpOp( - enum CppAD::CompareOp cop , - const std::complex &left , - const std::complex &right , - const std::complex &trueCase , - const std::complex &falseCase ) - { CppAD::ErrorHandler::Call( - true , __LINE__ , __FILE__ , - "std::complex CondExpOp(...)", - "Error: cannot use CondExp with a complex type" - ); - return std::complex(0); - } - // CondExpRel -------------------------------------------------------- - CPPAD_COND_EXP_REL( std::complex ) - // EqualOpSeq ----------------------------------------------------- - inline bool EqualOpSeq( - const std::complex &x , - const std::complex &y ) - { return x == y; - } - // Identical ------------------------------------------------------ - inline bool IdenticalPar(const std::complex &x) - { return true; } - inline bool IdenticalZero(const std::complex &x) - { return (x == std::complex(0., 0.) ); } - inline bool IdenticalOne(const std::complex &x) - { return (x == std::complex(1., 0.) ); } - inline bool IdenticalEqualPar( - const std::complex &x, const std::complex &y) - { return (x == y); } - // Ordered -------------------------------------------------------- - CPPAD_USER_MACRO_ONE(LessThanZero) - CPPAD_USER_MACRO_ONE(LessThanOrZero) - CPPAD_USER_MACRO_ONE(GreaterThanOrZero) - CPPAD_USER_MACRO_ONE(GreaterThanZero) - inline bool abs_geq( - const std::complex& x , - const std::complex& y ) - { return std::abs(x) >= std::abs(y); } - // Integer ------------------------------------------------------ - inline int Integer(const std::complex &x) - { return static_cast( x.real() ); } - // isnan ------------------------------------------------------------- - inline bool isnan(const std::complex& z) - { return (z != z); - } - // Valid standard math functions -------------------------------- - CPPAD_STANDARD_MATH_UNARY(std::complex, cos) - CPPAD_STANDARD_MATH_UNARY(std::complex, cosh) - CPPAD_STANDARD_MATH_UNARY(std::complex, exp) - CPPAD_STANDARD_MATH_UNARY(std::complex, log) - CPPAD_STANDARD_MATH_UNARY(std::complex, sin) - CPPAD_STANDARD_MATH_UNARY(std::complex, sinh) - CPPAD_STANDARD_MATH_UNARY(std::complex, sqrt) - // Invalid standrd math functions ------------------------------- - CPPAD_USER_MACRO_TWO(abs) - CPPAD_USER_MACRO_TWO(acos) - CPPAD_USER_MACRO_TWO(asin) - CPPAD_USER_MACRO_TWO(atan) - CPPAD_USER_MACRO_TWO(sign) - // The pow function - inline std::complex pow( - const std::complex &x , - const std::complex &y ) - { return std::pow(x, y); } - // numeric_limits ------------------------------------------------- - CPPAD_NUMERIC_LIMITS(float, std::complex) - // to_string ------------------------------------------------- - CPPAD_TO_STRING(std::complex) -} - -// undefine macros only used by this file -# undef CPPAD_USER_MACRO -# undef CPPAD_USER_MACRO_ONE -# undef CPPAD_USER_MACRO_TWO - -# endif diff --git a/external/cppad/include/cppad/core/base_cond_exp.hpp b/external/cppad/include/cppad/core/base_cond_exp.hpp deleted file mode 100644 index c77c0c29b..000000000 --- a/external/cppad/include/cppad/core/base_cond_exp.hpp +++ /dev/null @@ -1,281 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_BASE_COND_EXP_HPP -# define CPPAD_CORE_BASE_COND_EXP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin base_cond_exp$$ -$spell - alloc - Rel - hpp - enum - namespace - Op - Lt - Le - Eq - Ge - Gt - Ne - cond - exp - const - adolc - CppAD - inline -$$ - -$section Base Type Requirements for Conditional Expressions$$ -$mindex CondExp require CPPAD_COND_EXP_REL$$ - -$head Purpose$$ -These definitions are required by the user's code to support the -$codei%AD<%Base%>%$$ type for $cref CondExp$$ operations: - -$head CompareOp$$ -The following $code enum$$ type is used in the specifications below: -$codep -namespace CppAD { - // The conditional expression operator enum type - enum CompareOp - { CompareLt, // less than - CompareLe, // less than or equal - CompareEq, // equal - CompareGe, // greater than or equal - CompareGt, // greater than - CompareNe // not equal - }; -} -$$ - -$head CondExpTemplate$$ -The type $icode Base$$ must support the syntax -$codei% - %result% = CppAD::CondExpOp( - %cop%, %left%, %right%, %exp_if_true%, %exp_if_false% - ) -%$$ -which computes implements the corresponding $cref CondExp$$ -function when the result has prototype -$codei% - %Base% %result% -%$$ -The argument $icode cop$$ has prototype -$codei% - enum CppAD::CompareOp %cop% -%$$ -The other arguments have the prototype -$codei% - const %Base%& %left% - const %Base%& %right% - const %Base%& %exp_if_true% - const %Base%& %exp_if_false% -%$$ - -$subhead Ordered Type$$ -If $icode Base$$ is a relatively simple type -that supports -$code <$$, $code <=$$, $code ==$$, $code >=$$, and $code >$$ operators -its $code CondExpOp$$ function can be defined by -$codei% -namespace CppAD { - inline %Base% CondExpOp( - enum CppAD::CompareOp cop , - const %Base% &left , - const %Base% &right , - const %Base% &exp_if_true , - const %Base% &exp_if_false ) - { return CondExpTemplate( - cop, left, right, trueCase, falseCase); - } -} -%$$ -For example, see -$cref/double CondExpOp/base_alloc.hpp/CondExpOp/$$. -For an example of and implementation of $code CondExpOp$$ with -a more involved $icode Base$$ type see -$cref/adolc CondExpOp/base_adolc.hpp/CondExpOp/$$. - - -$subhead Not Ordered$$ -If the type $icode Base$$ does not support ordering, -the $code CondExpOp$$ function does not make sense. -In this case one might (but need not) define $code CondExpOp$$ as follows: -$codei% -namespace CppAD { - inline %Base% CondExpOp( - enum CompareOp cop , - const %Base% &left , - const %Base% &right , - const %Base% &exp_if_true , - const %Base% &exp_if_false ) - { // attempt to use CondExp with a %Base% argument - assert(0); - return %Base%(0); - } -} -%$$ -For example, see -$cref/complex CondExpOp/base_complex.hpp/CondExpOp/$$. - -$head CondExpRel$$ -The macro invocation -$codei% - CPPAD_COND_EXP_REL(%Base%) -%$$ -uses $code CondExpOp$$ above to define the following functions -$codei% - CondExpLt(%left%, %right%, %exp_if_true%, %exp_if_false%) - CondExpLe(%left%, %right%, %exp_if_true%, %exp_if_false%) - CondExpEq(%left%, %right%, %exp_if_true%, %exp_if_false%) - CondExpGe(%left%, %right%, %exp_if_true%, %exp_if_false%) - CondExpGt(%left%, %right%, %exp_if_true%, %exp_if_false%) -%$$ -where the arguments have type $icode Base$$. -This should be done inside of the CppAD namespace. -For example, see -$cref/base_alloc/base_alloc.hpp/CondExpRel/$$. - -$end -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -\file base_cond_exp.hpp -CondExp operations that aid in meeting Base type requirements. -*/ - -/*! -\def CPPAD_COND_EXP_BASE_REL(Type, Rel, Op) -This macro defines the operation -\verbatim - CondExpRel(left, right, exp_if_true, exp_if_false) -\endverbatim -The argument \c Type is the \c Base type for this base require operation. -The argument \c Rel is one of \c Lt, \c Le, \c Eq, \c Ge, \c Gt. -The argument \c Op is the corresponding \c CompareOp value. -*/ -# define CPPAD_COND_EXP_BASE_REL(Type, Rel, Op) \ - inline Type CondExp##Rel( \ - const Type& left , \ - const Type& right , \ - const Type& exp_if_true , \ - const Type& exp_if_false ) \ - { return CondExpOp(Op, left, right, exp_if_true, exp_if_false); \ - } - -/*! -\def CPPAD_COND_EXP_REL(Type) -The macro defines the operations -\verbatim - CondExpLt(left, right, exp_if_true, exp_if_false) - CondExpLe(left, right, exp_if_true, exp_if_false) - CondExpEq(left, right, exp_if_true, exp_if_false) - CondExpGe(left, right, exp_if_true, exp_if_false) - CondExpGt(left, right, exp_if_true, exp_if_false) -\endverbatim -The argument \c Type is the \c Base type for this base require operation. -*/ -# define CPPAD_COND_EXP_REL(Type) \ - CPPAD_COND_EXP_BASE_REL(Type, Lt, CompareLt) \ - CPPAD_COND_EXP_BASE_REL(Type, Le, CompareLe) \ - CPPAD_COND_EXP_BASE_REL(Type, Eq, CompareEq) \ - CPPAD_COND_EXP_BASE_REL(Type, Ge, CompareGe) \ - CPPAD_COND_EXP_BASE_REL(Type, Gt, CompareGt) - -/*! -Template function to implement Conditional Expressions for simple types -that have comparision operators. - -\tparam CompareType -is the type of the left and right operands to the comparision operator. - -\tparam ResultType -is the type of the result, which is the same as \c CompareType except -during forward and reverse mode sparese calculations. - -\param cop -specifices which comparision to use; i.e., -$code <$$, -$code <=$$, -$code ==$$, -$code >=$$, -$code >$$, or -$code !=$$. - -\param left -is the left operand to the comparision operator. - -\param right -is the right operand to the comparision operator. - -\param exp_if_true -is the return value is the comparision results in true. - -\param exp_if_false -is the return value is the comparision results in false. - -\return -see \c exp_if_true and \c exp_if_false above. -*/ -template -ResultType CondExpTemplate( - enum CompareOp cop , - const CompareType& left , - const CompareType& right , - const ResultType& exp_if_true , - const ResultType& exp_if_false ) -{ ResultType returnValue; - switch( cop ) - { - case CompareLt: - if( left < right ) - returnValue = exp_if_true; - else returnValue = exp_if_false; - break; - - case CompareLe: - if( left <= right ) - returnValue = exp_if_true; - else returnValue = exp_if_false; - break; - - case CompareEq: - if( left == right ) - returnValue = exp_if_true; - else returnValue = exp_if_false; - break; - - case CompareGe: - if( left >= right ) - returnValue = exp_if_true; - else returnValue = exp_if_false; - break; - - case CompareGt: - if( left > right ) - returnValue = exp_if_true; - else returnValue = exp_if_false; - break; - - default: - CPPAD_ASSERT_UNKNOWN(0); - returnValue = exp_if_true; - } - return returnValue; -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/base_double.hpp b/external/cppad/include/cppad/core/base_double.hpp deleted file mode 100644 index 63416fef8..000000000 --- a/external/cppad/include/cppad/core/base_double.hpp +++ /dev/null @@ -1,229 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_BASE_DOUBLE_HPP -# define CPPAD_CORE_BASE_DOUBLE_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -/* -$begin base_double.hpp$$ -$spell - namespaces - cppad - hpp - azmul - expm1 - atanh - acosh - asinh - erf - endif - abs_geq - acos - asin - atan - cos - sqrt - tanh - std - fabs - bool - Lt Le Eq Ge Gt - Rel - CppAD - CondExpOp - namespace - inline - enum - const - exp - const -$$ - - -$section Enable use of AD where Base is double$$ - -$head CondExpOp$$ -The type $code double$$ is a relatively simple type that supports -$code <$$, $code <=$$, $code ==$$, $code >=$$, and $code >$$ operators; see -$cref/ordered type/base_cond_exp/CondExpTemplate/Ordered Type/$$. -Hence its $code CondExpOp$$ function is defined by -$srccode%cpp% */ -namespace CppAD { - inline double CondExpOp( - enum CompareOp cop , - const double& left , - const double& right , - const double& exp_if_true , - const double& exp_if_false ) - { return CondExpTemplate(cop, left, right, exp_if_true, exp_if_false); - } -} -/* %$$ - -$head CondExpRel$$ -The $cref/CPPAD_COND_EXP_REL/base_cond_exp/CondExpRel/$$ macro invocation -$srccode%cpp% */ -namespace CppAD { - CPPAD_COND_EXP_REL(double) -} -/* %$$ -uses $code CondExpOp$$ above to -define $codei%CondExp%Rel%$$ for $code double$$ arguments -and $icode%Rel%$$ equal to -$code Lt$$, $code Le$$, $code Eq$$, $code Ge$$, and $code Gt$$. - -$head EqualOpSeq$$ -The type $code double$$ is simple (in this respect) and so we define -$srccode%cpp% */ -namespace CppAD { - inline bool EqualOpSeq(const double& x, const double& y) - { return x == y; } -} -/* %$$ - -$head Identical$$ -The type $code double$$ is simple (in this respect) and so we define -$srccode%cpp% */ -namespace CppAD { - inline bool IdenticalPar(const double& x) - { return true; } - inline bool IdenticalZero(const double& x) - { return (x == 0.); } - inline bool IdenticalOne(const double& x) - { return (x == 1.); } - inline bool IdenticalEqualPar(const double& x, const double& y) - { return (x == y); } -} -/* %$$ - -$head Integer$$ -$srccode%cpp% */ -namespace CppAD { - inline int Integer(const double& x) - { return static_cast(x); } -} -/* %$$ - -$head azmul$$ -$srccode%cpp% */ -namespace CppAD { - CPPAD_AZMUL( double ) -} -/* %$$ - -$head Ordered$$ -The $code double$$ type supports ordered comparisons -$srccode%cpp% */ -namespace CppAD { - inline bool GreaterThanZero(const double& x) - { return x > 0.; } - inline bool GreaterThanOrZero(const double& x) - { return x >= 0.; } - inline bool LessThanZero(const double& x) - { return x < 0.; } - inline bool LessThanOrZero(const double& x) - { return x <= 0.; } - inline bool abs_geq(const double& x, const double& y) - { return std::fabs(x) >= std::fabs(y); } -} -/* %$$ - -$head Unary Standard Math$$ -The following macro invocations import the $code double$$ versions of -the unary standard math functions into the $code CppAD$$ namespace. -Importing avoids ambiguity errors when using both the -$code CppAD$$ and $code std$$ namespaces. -Note this also defines the $cref/float/base_float.hpp/Unary Standard Math/$$ -versions of these functions. -$srccode%cpp% */ -namespace CppAD { - using std::acos; - using std::asin; - using std::atan; - using std::cos; - using std::cosh; - using std::exp; - using std::fabs; - using std::log; - using std::log10; - using std::sin; - using std::sinh; - using std::sqrt; - using std::tan; - using std::tanh; -# if CPPAD_USE_CPLUSPLUS_2011 - using std::erf; - using std::asinh; - using std::acosh; - using std::atanh; - using std::expm1; - using std::log1p; -# endif -} -/* %$$ -The absolute value function is special because its $code std$$ name is -$code fabs$$ -$srccode%cpp% */ -namespace CppAD { - inline double abs(const double& x) - { return std::fabs(x); } -} -/* %$$ - -$head sign$$ -The following defines the $code CppAD::sign$$ function that -is required to use $code AD$$: -$srccode%cpp% */ -namespace CppAD { - inline double sign(const double& x) - { if( x > 0. ) - return 1.; - if( x == 0. ) - return 0.; - return -1.; - } -} -/* %$$ - -$head pow$$ -The following defines a $code CppAD::pow$$ function that -is required to use $code AD$$. -As with the unary standard math functions, -this has the exact same signature as $code std::pow$$, -so use it instead of defining another function. -$srccode%cpp% */ -namespace CppAD { - using std::pow; -} -/* %$$ - -$head numeric_limits$$ -The following defines the CppAD $cref numeric_limits$$ -for the type $code double$$: -$srccode%cpp% */ -namespace CppAD { - CPPAD_NUMERIC_LIMITS(double, double) -} -/* %$$ - -$head to_string$$ -There is no need to define $code to_string$$ for $code double$$ -because it is defined by including $code cppad/utility/to_string.hpp$$; -see $cref to_string$$. -See $cref/base_complex.hpp/base_complex.hpp/to_string/$$ for an example where -it is necessary to define $code to_string$$ for a $icode Base$$ type. - -$end -*/ - -# endif diff --git a/external/cppad/include/cppad/core/base_float.hpp b/external/cppad/include/cppad/core/base_float.hpp deleted file mode 100644 index eb754bc8a..000000000 --- a/external/cppad/include/cppad/core/base_float.hpp +++ /dev/null @@ -1,230 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_BASE_FLOAT_HPP -# define CPPAD_CORE_BASE_FLOAT_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -/* -$begin base_float.hpp$$ -$spell - namespaces - cppad - hpp - azmul - expm1 - atanh - acosh - asinh - erf - endif - abs_geq - acos - asin - atan - cos - sqrt - tanh - std - fabs - bool - Lt Le Eq Ge Gt - Rel - CppAD - CondExpOp - namespace - inline - enum - const - exp - const -$$ - - -$section Enable use of AD where Base is float$$ - -$head CondExpOp$$ -The type $code float$$ is a relatively simple type that supports -$code <$$, $code <=$$, $code ==$$, $code >=$$, and $code >$$ operators; see -$cref/ordered type/base_cond_exp/CondExpTemplate/Ordered Type/$$. -Hence its $code CondExpOp$$ function is defined by -$srccode%cpp% */ -namespace CppAD { - inline float CondExpOp( - enum CompareOp cop , - const float& left , - const float& right , - const float& exp_if_true , - const float& exp_if_false ) - { return CondExpTemplate(cop, left, right, exp_if_true, exp_if_false); - } -} -/* %$$ - -$head CondExpRel$$ -The $cref/CPPAD_COND_EXP_REL/base_cond_exp/CondExpRel/$$ macro invocation -$srccode%cpp% */ -namespace CppAD { - CPPAD_COND_EXP_REL(float) -} -/* %$$ -uses $code CondExpOp$$ above to -define $codei%CondExp%Rel%$$ for $code float$$ arguments -and $icode%Rel%$$ equal to -$code Lt$$, $code Le$$, $code Eq$$, $code Ge$$, and $code Gt$$. - -$head EqualOpSeq$$ -The type $code float$$ is simple (in this respect) and so we define -$srccode%cpp% */ -namespace CppAD { - inline bool EqualOpSeq(const float& x, const float& y) - { return x == y; } -} -/* %$$ - -$head Identical$$ -The type $code float$$ is simple (in this respect) and so we define -$srccode%cpp% */ -namespace CppAD { - inline bool IdenticalPar(const float& x) - { return true; } - inline bool IdenticalZero(const float& x) - { return (x == 0.f); } - inline bool IdenticalOne(const float& x) - { return (x == 1.f); } - inline bool IdenticalEqualPar(const float& x, const float& y) - { return (x == y); } -} -/* %$$ - -$head Integer$$ -$srccode%cpp% */ -namespace CppAD { - inline int Integer(const float& x) - { return static_cast(x); } -} -/* %$$ - -$head azmul$$ -$srccode%cpp% */ -namespace CppAD { - CPPAD_AZMUL( float ) -} -/* %$$ - -$head Ordered$$ -The $code float$$ type supports ordered comparisons -$srccode%cpp% */ -namespace CppAD { - inline bool GreaterThanZero(const float& x) - { return x > 0.f; } - inline bool GreaterThanOrZero(const float& x) - { return x >= 0.f; } - inline bool LessThanZero(const float& x) - { return x < 0.f; } - inline bool LessThanOrZero(const float& x) - { return x <= 0.f; } - inline bool abs_geq(const float& x, const float& y) - { return std::fabs(x) >= std::fabs(y); } -} -/* %$$ - -$head Unary Standard Math$$ -The following macro invocations import the $code float$$ versions of -the unary standard math functions into the $code CppAD$$ namespace. -Importing avoids ambiguity errors when using both the -$code CppAD$$ and $code std$$ namespaces. -Note this also defines the $cref/double/base_double.hpp/Unary Standard Math/$$ -versions of these functions. -$srccode%cpp% */ -namespace CppAD { - using std::acos; - using std::asin; - using std::atan; - using std::cos; - using std::cosh; - using std::exp; - using std::fabs; - using std::log; - using std::log10; - using std::sin; - using std::sinh; - using std::sqrt; - using std::tan; - using std::tanh; -# if CPPAD_USE_CPLUSPLUS_2011 - using std::erf; - using std::asinh; - using std::acosh; - using std::atanh; - using std::expm1; - using std::log1p; -# endif -} - -/* %$$ -The absolute value function is special because its $code std$$ name is -$code fabs$$ -$srccode%cpp% */ -namespace CppAD { - inline float abs(const float& x) - { return std::fabs(x); } -} -/* %$$ - -$head sign$$ -The following defines the $code CppAD::sign$$ function that -is required to use $code AD$$: -$srccode%cpp% */ -namespace CppAD { - inline float sign(const float& x) - { if( x > 0.f ) - return 1.f; - if( x == 0.f ) - return 0.f; - return -1.f; - } -} -/* %$$ -$head pow$$ -The following defines a $code CppAD::pow$$ function that -is required to use $code AD$$. -As with the unary standard math functions, -this has the exact same signature as $code std::pow$$, -so use it instead of defining another function. -$srccode%cpp% */ -namespace CppAD { - using std::pow; -} -/* %$$ - -$head numeric_limits$$ -The following defines the CppAD $cref numeric_limits$$ -for the type $code float$$: -$srccode%cpp% */ -namespace CppAD { - CPPAD_NUMERIC_LIMITS(float, float) -} -/* %$$ - -$head to_string$$ -There is no need to define $code to_string$$ for $code float$$ -because it is defined by including $code cppad/utility/to_string.hpp$$; -see $cref to_string$$. -See $cref/base_complex.hpp/base_complex.hpp/to_string/$$ for an example where -it is necessary to define $code to_string$$ for a $icode Base$$ type. - -$end -*/ - - -# endif diff --git a/external/cppad/include/cppad/core/base_hash.hpp b/external/cppad/include/cppad/core/base_hash.hpp deleted file mode 100644 index 057a1b769..000000000 --- a/external/cppad/include/cppad/core/base_hash.hpp +++ /dev/null @@ -1,84 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_BASE_HASH_HPP -# define CPPAD_CORE_BASE_HASH_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin base_hash$$ -$spell - alloc - Cpp - adouble - valgrind - const - inline -$$ - -$section Base Type Requirements for Hash Coding Values$$ - -$head Syntax$$ -$icode%code% = hash_code(%x%)%$$ - -$head Purpose$$ -CppAD uses a table of $icode Base$$ type values when recording -$codei%AD<%Base%>%$$ operations. -A hashing function is used to reduce number of values stored in this table; -for example, it is not necessary to store the value 3.0 every -time it is used as a $cref/parameter/parvar/$$. - -$head Default$$ -The default hashing function works with the set of bits that correspond -to a $icode Base$$ value. -In most cases this works well, but in some cases -it does not. For example, in the -$cref base_adolc.hpp$$ case, an $code adouble$$ value can have -fields that are not initialized and $code valgrind$$ reported an error -when these are used to form the hash code. - -$head x$$ -This argument has prototype -$codei% - const %Base%& %x -%$$ -It is the value we are forming a hash code for. - -$head code$$ -The return value $icode code$$ has prototype -$codei% - unsigned short %code% -%$$ -It is the hash code corresponding to $icode x$$. This intention is the -commonly used values will have different hash codes. -The hash code must satisfy -$codei% - %code% < CPPAD_HASH_TABLE_SIZE -%$$ -so that it is a valid index into the hash code table. - -$head inline$$ -If you define this function, it should declare it to be $code inline$$, -so that you do not get multiple definitions from different compilation units. - -$head Example$$ -See the $code base_alloc$$ $cref/hash_code/base_alloc.hpp/hash_code/$$ -and the $code adouble$$ $cref/hash_code/base_adolc.hpp/hash_code/$$. - -$end -*/ - -/*! -\def CPPAD_HASH_TABLE_SIZE -the codes retruned by hash_code are between zero and CPPAD_HASH_TABLE_SIZE -minus one. -*/ -# define CPPAD_HASH_TABLE_SIZE 10000 - -# endif diff --git a/external/cppad/include/cppad/core/base_limits.hpp b/external/cppad/include/cppad/core/base_limits.hpp deleted file mode 100644 index 97b7a1ee6..000000000 --- a/external/cppad/include/cppad/core/base_limits.hpp +++ /dev/null @@ -1,67 +0,0 @@ -# ifndef CPPAD_CORE_BASE_LIMITS_HPP -# define CPPAD_CORE_BASE_LIMITS_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin base_limits$$ -$spell - std - namespace - CppAD -$$ - -$section Base Type Requirements for Numeric Limits$$ - -$head CppAD::numeric_limits$$ -A specialization for -$cref/CppAD::numeric_limits/numeric_limits/$$ -must be defined in order to use the type $codei%AD<%Base%>%$$. -CppAD does not use a specialization of -$codei%std::numeric_limits<%Base%>%$$. -Since C++11, using a specialization of -$codei%std::numeric_limits<%Base%>%$$ -would require that $icode Base$$ be a literal type. - -$head CPPAD_NUMERIC_LIMITS$$ -In most cases, this macro can be used to define the specialization where -the numeric limits for the type $icode Base$$ -are the same as the standard numeric limits for the type $icode Other$$. -For most $icode Base$$ types, -there is a choice of $icode Other$$, -for which the following preprocessor macro invocation suffices: -$codei% - namespace CppAD { - CPPAD_NUMERIC_LIMITS(%Other%, %Base%) - } -%$$ -where the macro is defined by -$srccode%cpp% */ -# define CPPAD_NUMERIC_LIMITS(Other, Base) \ -template <> class numeric_limits\ -{\ - public:\ - static Base min(void) \ - { return static_cast( std::numeric_limits::min() ); }\ - static Base max(void) \ - { return static_cast( std::numeric_limits::max() ); }\ - static Base epsilon(void) \ - { return static_cast( std::numeric_limits::epsilon() ); }\ - static Base quiet_NaN(void) \ - { return static_cast( std::numeric_limits::quiet_NaN() ); }\ - static const int digits10 = std::numeric_limits::digits10;\ -}; -/* %$$ -$end -*/ - -# endif diff --git a/external/cppad/include/cppad/core/base_std_math.hpp b/external/cppad/include/cppad/core/base_std_math.hpp deleted file mode 100644 index 9491c83e6..000000000 --- a/external/cppad/include/cppad/core/base_std_math.hpp +++ /dev/null @@ -1,186 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_BASE_STD_MATH_HPP -# define CPPAD_CORE_BASE_STD_MATH_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin base_std_math$$ -$spell - expm1 - atanh - acosh - asinh - inline - fabs - isnan - alloc - std - acos - asin - atan - cos - exp - sqrt - const - CppAD - namespace - erf -$$ - -$section Base Type Requirements for Standard Math Functions$$ - -$head Purpose$$ -These definitions are required for the user's code to use the type -$codei%AD<%Base%>%$$: - -$head Unary Standard Math$$ -The type $icode Base$$ must support the following functions -unary standard math functions (in the CppAD namespace): -$table -$bold Syntax$$ $cnext $bold Result$$ -$rnext -$icode%y% = abs(%x%)%$$ $cnext absolute value $rnext -$icode%y% = acos(%x%)%$$ $cnext inverse cosine $rnext -$icode%y% = asin(%x%)%$$ $cnext inverse sine $rnext -$icode%y% = atan(%x%)%$$ $cnext inverse tangent $rnext -$icode%y% = cos(%x%)%$$ $cnext cosine $rnext -$icode%y% = cosh(%x%)%$$ $cnext hyperbolic cosine $rnext -$icode%y% = exp(%x%)%$$ $cnext exponential $rnext -$icode%y% = fabs(%x%)%$$ $cnext absolute value $rnext -$icode%y% = log(%x%)%$$ $cnext natural logarithm $rnext -$icode%y% = sin(%x%)%$$ $cnext sine $rnext -$icode%y% = sinh(%x%)%$$ $cnext hyperbolic sine $rnext -$icode%y% = sqrt(%x%)%$$ $cnext square root $rnext -$icode%y% = tan(%x%)%$$ $cnext tangent -$tend -where the arguments and return value have the prototypes -$codei% - const %Base%& %x% - %Base% %y% -%$$ -For example, -$cref/base_alloc/base_alloc.hpp/Unary Standard Math/$$, - - -$head CPPAD_STANDARD_MATH_UNARY$$ -The macro invocation, within the CppAD namespace, -$codei% - CPPAD_STANDARD_MATH_UNARY(%Base%, %Fun%) -%$$ -defines the syntax -$codei% - %y% = CppAD::%Fun%(%x%) -%$$ -This macro uses the functions $codei%std::%Fun%$$ which -must be defined and have the same prototype as $codei%CppAD::%Fun%$$. -For example, -$cref/float/base_float.hpp/Unary Standard Math/$$. - -$head erf, asinh, acosh, atanh, expm1, log1p$$ -If this preprocessor symbol -$code CPPAD_USE_CPLUSPLUS_2011$$ is true ($code 1$$), -when compiling for c++11, the type -$code double$$ is supported for the functions listed below. -In this case, the type $icode Base$$ must also support these functions: -$table -$bold Syntax$$ $cnext $bold Result$$ -$rnext -$icode%y% = erf(%x%)%$$ $cnext error function $rnext -$icode%y% = asinh(%x%)%$$ $cnext inverse hyperbolic sin $rnext -$icode%y% = acosh(%x%)%$$ $cnext inverse hyperbolic cosine $rnext -$icode%y% = atanh(%x%)%$$ $cnext inverse hyperbolic tangent $rnext -$icode%y% = expm1(%x%)%$$ $cnext exponential of x minus one $rnext -$icode%y% = log1p(%x%)%$$ $cnext logarithm of one plus x -$tend -where the arguments and return value have the prototypes -$codei% - const %Base%& %x% - %Base% %y% -%$$ - -$head sign$$ -The type $icode Base$$ must support the syntax -$codei% - %y% = CppAD::sign(%x%) -%$$ -which computes -$latex \[ -y = \left\{ \begin{array}{ll} - +1 & {\rm if} \; x > 0 \\ - 0 & {\rm if} \; x = 0 \\ - -1 & {\rm if} \; x < 0 -\end{array} \right. -\] $$ -where $icode x$$ and $icode y$$ have the same prototype as above. -For example, see -$cref/base_alloc/base_alloc.hpp/sign/$$. -Note that, if ordered comparisons are not defined for the type $icode Base$$, -the $code code sign$$ function should generate an assert if it is used; see -$cref/complex invalid unary math/base_complex.hpp/Invalid Unary Math/$$. - -$head pow$$ -The type $icode Base$$ must support the syntax -$codei% - %z% = CppAD::pow(%x%, %y%) -%$$ -which computes $latex z = x^y$$. -The arguments $icode x$$ and $icode y$$ have prototypes -$codei% - const %Base%& %x% - const %Base%& %y% -%$$ -and the return value $icode z$$ has prototype -$codei% - %Base% %z% -%$$ -For example, see -$cref/base_alloc/base_alloc.hpp/pow/$$. - - -$head isnan$$ -If $icode Base$$ defines the $code isnan$$ function, -you may also have to provide a definition in the CppAD namespace -(to avoid a function ambiguity). -For example, see -$cref/base_complex/base_complex.hpp/isnan/$$. - - -$end -------------------------------------------------------------------------------- -*/ - -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -\file base_std_math.hpp -Defintions that aid meeting Base type requirements for standard math functions. -*/ - -/*! -\def CPPAD_STANDARD_MATH_UNARY(Type, Fun) -This macro defines the function -\verbatim - y = CppAD:Fun(x) -\endverbatim -where the argument \c x and return value \c y have type \c Type -using the corresponding function std::Fun. -*/ -# define CPPAD_STANDARD_MATH_UNARY(Type, Fun) \ - inline Type Fun(const Type& x) \ - { return std::Fun(x); } - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/base_to_string.hpp b/external/cppad/include/cppad/core/base_to_string.hpp deleted file mode 100644 index 8abb3a2b5..000000000 --- a/external/cppad/include/cppad/core/base_to_string.hpp +++ /dev/null @@ -1,65 +0,0 @@ -# ifndef CPPAD_CORE_BASE_TO_STRING_HPP -# define CPPAD_CORE_BASE_TO_STRING_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin base_to_string$$ -$spell - std - namespace - CppAD - struct - const - stringstream - setprecision - str -$$ - -$section Extending to_string To Another Floating Point Type$$ - -$head Base Requirement$$ -If the function $cref to_string$$ is used by an -$cref/AD type above Base/glossary/AD Type Above Base/$$, -A specialization for the template structure -$code CppAD::to_string_struct$$ must be defined. - -$head CPPAD_TO_STRING$$ -For most $icode Base$$ types, -the following can be used to define the specialization: -$codei% - namespace CppAD { - CPPAD_TO_STRING(%Base%) - } -%$$ -Note that the $code CPPAD_TO_STRING$$ macro assumes that the -$cref base_limits$$ and $cref base_std_math$$ have already been defined -for this type. -This macro is defined as follows: -$srccode%cpp% */ -# define CPPAD_TO_STRING(Base) \ -template <> struct to_string_struct\ -{ std::string operator()(const Base& value) \ - { std::stringstream os;\ - int n_digits = 1 + CppAD::numeric_limits::digits10; \ - os << std::setprecision(n_digits);\ - os << value;\ - return os.str();\ - }\ -}; -/* %$$ -$end ------------------------------------------------------------------------------- -*/ -// make sure to_string has been included -# include - -# endif diff --git a/external/cppad/include/cppad/core/bender_quad.hpp b/external/cppad/include/cppad/core/bender_quad.hpp deleted file mode 100644 index 4c725acb1..000000000 --- a/external/cppad/include/cppad/core/bender_quad.hpp +++ /dev/null @@ -1,404 +0,0 @@ -# ifndef CPPAD_CORE_BENDER_QUAD_HPP -# define CPPAD_CORE_BENDER_QUAD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin BenderQuad$$ -$spell - cppad.hpp - BAvector - gx - gxx - CppAD - Fy - dy - Jacobian - ADvector - const - dg - ddg -$$ - - -$section Computing Jacobian and Hessian of Bender's Reduced Objective$$ -$mindex BenderQuad$$ - -$head Syntax$$ -$codei% -# include -BenderQuad(%x%, %y%, %fun%, %g%, %gx%, %gxx%)%$$ - -$head See Also$$ -$cref opt_val_hes$$ - -$head Problem$$ -The type $cref/ADvector/BenderQuad/ADvector/$$ cannot be determined -form the arguments above -(currently the type $icode ADvector$$ must be -$codei%CPPAD_TESTVECTOR(%Base%)%$$.) -This will be corrected in the future by requiring $icode Fun$$ -to define $icode%Fun%::vector_type%$$ which will specify the -type $icode ADvector$$. - -$head Purpose$$ -We are given the optimization problem -$latex \[ -\begin{array}{rcl} -{\rm minimize} & F(x, y) & {\rm w.r.t.} \; (x, y) \in \B{R}^n \times \B{R}^m -\end{array} -\] $$ -that is convex with respect to $latex y$$. -In addition, we are given a set of equations $latex H(x, y)$$ -such that -$latex \[ - H[ x , Y(x) ] = 0 \;\; \Rightarrow \;\; F_y [ x , Y(x) ] = 0 -\] $$ -(In fact, it is often the case that $latex H(x, y) = F_y (x, y)$$.) -Furthermore, it is easy to calculate a Newton step for these equations; i.e., -$latex \[ - dy = - [ \partial_y H(x, y)]^{-1} H(x, y) -\] $$ -The purpose of this routine is to compute the -value, Jacobian, and Hessian of the reduced objective function -$latex \[ - G(x) = F[ x , Y(x) ] -\] $$ -Note that if only the value and Jacobian are needed, they can be -computed more quickly using the relations -$latex \[ - G^{(1)} (x) = \partial_x F [x, Y(x) ] -\] $$ - -$head x$$ -The $code BenderQuad$$ argument $icode x$$ has prototype -$codei% - const %BAvector% &%x% -%$$ -(see $cref/BAvector/BenderQuad/BAvector/$$ below) -and its size must be equal to $icode n$$. -It specifies the point at which we evaluating -the reduced objective function and its derivatives. - - -$head y$$ -The $code BenderQuad$$ argument $icode y$$ has prototype -$codei% - const %BAvector% &%y% -%$$ -and its size must be equal to $icode m$$. -It must be equal to $latex Y(x)$$; i.e., -it must solve the problem in $latex y$$ for this given value of $latex x$$ -$latex \[ -\begin{array}{rcl} - {\rm minimize} & F(x, y) & {\rm w.r.t.} \; y \in \B{R}^m -\end{array} -\] $$ - -$head fun$$ -The $code BenderQuad$$ object $icode fun$$ -must support the member functions listed below. -The $codei%AD<%Base%>%$$ arguments will be variables for -a tape created by a call to $cref Independent$$ from $code BenderQuad$$ -(hence they can not be combined with variables corresponding to a -different tape). - -$subhead fun.f$$ -The $code BenderQuad$$ argument $icode fun$$ supports the syntax -$codei% - %f% = %fun%.f(%x%, %y%) -%$$ -The $icode%fun%.f%$$ argument $icode x$$ has prototype -$codei% - const %ADvector% &%x% -%$$ -(see $cref/ADvector/BenderQuad/ADvector/$$ below) -and its size must be equal to $icode n$$. -The $icode%fun%.f%$$ argument $icode y$$ has prototype -$codei% - const %ADvector% &%y% -%$$ -and its size must be equal to $icode m$$. -The $icode%fun%.f%$$ result $icode f$$ has prototype -$codei% - %ADvector% %f% -%$$ -and its size must be equal to one. -The value of $icode f$$ is -$latex \[ - f = F(x, y) -\] $$. - -$subhead fun.h$$ -The $code BenderQuad$$ argument $icode fun$$ supports the syntax -$codei% - %h% = %fun%.h(%x%, %y%) -%$$ -The $icode%fun%.h%$$ argument $icode x$$ has prototype -$codei% - const %ADvector% &%x% -%$$ -and its size must be equal to $icode n$$. -The $icode%fun%.h%$$ argument $icode y$$ has prototype -$codei% - const %BAvector% &%y% -%$$ -and its size must be equal to $icode m$$. -The $icode%fun%.h%$$ result $icode h$$ has prototype -$codei% - %ADvector% %h% -%$$ -and its size must be equal to $icode m$$. -The value of $icode h$$ is -$latex \[ - h = H(x, y) -\] $$. - -$subhead fun.dy$$ -The $code BenderQuad$$ argument $icode fun$$ supports the syntax -$codei% - %dy% = %fun%.dy(%x%, %y%, %h%) - -%x% -%$$ -The $icode%fun%.dy%$$ argument $icode x$$ has prototype -$codei% - const %BAvector% &%x% -%$$ -and its size must be equal to $icode n$$. -Its value will be exactly equal to the $code BenderQuad$$ argument -$icode x$$ and values depending on it can be stored as private objects -in $icode f$$ and need not be recalculated. -$codei% - -%y% -%$$ -The $icode%fun%.dy%$$ argument $icode y$$ has prototype -$codei% - const %BAvector% &%y% -%$$ -and its size must be equal to $icode m$$. -Its value will be exactly equal to the $code BenderQuad$$ argument -$icode y$$ and values depending on it can be stored as private objects -in $icode f$$ and need not be recalculated. -$codei% - -%h% -%$$ -The $icode%fun%.dy%$$ argument $icode h$$ has prototype -$codei% - const %ADvector% &%h% -%$$ -and its size must be equal to $icode m$$. -$codei% - -%dy% -%$$ -The $icode%fun%.dy%$$ result $icode dy$$ has prototype -$codei% - %ADvector% %dy% -%$$ -and its size must be equal to $icode m$$. -The return value $icode dy$$ is given by -$latex \[ - dy = - [ \partial_y H (x , y) ]^{-1} h -\] $$ -Note that if $icode h$$ is equal to $latex H(x, y)$$, -$latex dy$$ is the Newton step for finding a zero -of $latex H(x, y)$$ with respect to $latex y$$; -i.e., -$latex y + dy$$ is an approximate solution for the equation -$latex H (x, y + dy) = 0$$. - -$head g$$ -The argument $icode g$$ has prototype -$codei% - %BAvector% &%g% -%$$ -and has size one. -The input value of its element does not matter. -On output, -it contains the value of $latex G (x)$$; i.e., -$latex \[ - g[0] = G (x) -\] $$ - -$head gx$$ -The argument $icode gx$$ has prototype -$codei% - %BAvector% &%gx% -%$$ -and has size $latex n $$. -The input values of its elements do not matter. -On output, -it contains the Jacobian of $latex G (x)$$; i.e., -for $latex j = 0 , \ldots , n-1$$, -$latex \[ - gx[ j ] = G^{(1)} (x)_j -\] $$ - -$head gxx$$ -The argument $icode gx$$ has prototype -$codei% - %BAvector% &%gxx% -%$$ -and has size $latex n \times n$$. -The input values of its elements do not matter. -On output, -it contains the Hessian of $latex G (x)$$; i.e., -for $latex i = 0 , \ldots , n-1$$, and -$latex j = 0 , \ldots , n-1$$, -$latex \[ - gxx[ i * n + j ] = G^{(2)} (x)_{i,j} -\] $$ - -$head BAvector$$ -The type $icode BAvector$$ must be a -$cref SimpleVector$$ class. -We use $icode Base$$ to refer to the type of the elements of -$icode BAvector$$; i.e., -$codei% - %BAvector%::value_type -%$$ - -$head ADvector$$ -The type $icode ADvector$$ must be a -$cref SimpleVector$$ class with elements of type -$codei%AD<%Base%>%$$; i.e., -$codei% - %ADvector%::value_type -%$$ -must be the same type as -$codei% - AD< %BAvector%::value_type > -%$$. - - -$head Example$$ -$children% - example/general/bender_quad.cpp -%$$ -The file -$cref bender_quad.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - - -$end ------------------------------------------------------------------------------ -*/ - -namespace CppAD { // BEGIN CppAD namespace - -template -void BenderQuad( - const BAvector &x , - const BAvector &y , - Fun fun , - BAvector &g , - BAvector &gx , - BAvector &gxx ) -{ // determine the base type - typedef typename BAvector::value_type Base; - - // check that BAvector is a SimpleVector class - CheckSimpleVector(); - - // declare the ADvector type - typedef CPPAD_TESTVECTOR(AD) ADvector; - - // size of the x and y spaces - size_t n = size_t(x.size()); - size_t m = size_t(y.size()); - - // check the size of gx and gxx - CPPAD_ASSERT_KNOWN( - g.size() == 1, - "BenderQuad: size of the vector g is not equal to 1" - ); - CPPAD_ASSERT_KNOWN( - size_t(gx.size()) == n, - "BenderQuad: size of the vector gx is not equal to n" - ); - CPPAD_ASSERT_KNOWN( - size_t(gxx.size()) == n * n, - "BenderQuad: size of the vector gxx is not equal to n * n" - ); - - // some temporary indices - size_t i, j; - - // variable versions x - ADvector vx(n); - for(j = 0; j < n; j++) - vx[j] = x[j]; - - // declare the independent variables - Independent(vx); - - // evaluate h = H(x, y) - ADvector h(m); - h = fun.h(vx, y); - - // evaluate dy (x) = Newton step as a function of x through h only - ADvector dy(m); - dy = fun.dy(x, y, h); - - // variable version of y - ADvector vy(m); - for(j = 0; j < m; j++) - vy[j] = y[j] + dy[j]; - - // evaluate G~ (x) = F [ x , y + dy(x) ] - ADvector gtilde(1); - gtilde = fun.f(vx, vy); - - // AD function object that corresponds to G~ (x) - // We will make heavy use of this tape, so optimize it - ADFun Gtilde; - Gtilde.Dependent(vx, gtilde); - Gtilde.optimize(); - - // value of G(x) - g = Gtilde.Forward(0, x); - - // initial forward direction vector as zero - BAvector dx(n); - for(j = 0; j < n; j++) - dx[j] = Base(0.0); - - // weight, first and second order derivative values - BAvector dg(1), w(1), ddw(2 * n); - w[0] = 1.; - - - // Jacobian and Hessian of G(x) is equal Jacobian and Hessian of Gtilde - for(j = 0; j < n; j++) - { // compute partials in x[j] direction - dx[j] = Base(1.0); - dg = Gtilde.Forward(1, dx); - gx[j] = dg[0]; - - // restore the dx vector to zero - dx[j] = Base(0.0); - - // compute second partials w.r.t x[j] and x[l] for l = 1, n - ddw = Gtilde.Reverse(2, w); - for(i = 0; i < n; i++) - gxx[ i * n + j ] = ddw[ i * 2 + 1 ]; - } - - return; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/bool_fun.hpp b/external/cppad/include/cppad/core/bool_fun.hpp deleted file mode 100644 index 03f0a539a..000000000 --- a/external/cppad/include/cppad/core/bool_fun.hpp +++ /dev/null @@ -1,243 +0,0 @@ -# ifndef CPPAD_CORE_BOOL_FUN_HPP -# define CPPAD_CORE_BOOL_FUN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin BoolFun$$ -$spell - namespace - bool - CppAD - const -$$ - - -$section AD Boolean Functions$$ -$mindex bool CPPAD_BOOL_UNARY CPPAD_BOOL_BINARY$$ - -$head Syntax$$ -$codei%CPPAD_BOOL_UNARY(%Base%, %unary_name%) -%$$ -$icode%b% = %unary_name%(%u%) -%$$ -$icode%b% = %unary_name%(%x%) -%$$ -$codei%CPPAD_BOOL_BINARY(%Base%, %binary_name%) -%$$ -$icode%b% = %binary_name%(%u%, %v%) -%$$ -$icode%b% = %binary_name%(%x%, %y%)%$$ - - -$head Purpose$$ -Create a $code bool$$ valued function that has $codei%AD<%Base%>%$$ arguments. - -$head unary_name$$ -This is the name of the $code bool$$ valued function with one argument -(as it is used in the source code). -The user must provide a version of $icode unary_name$$ where -the argument has type $icode Base$$. -CppAD uses this to create a version of $icode unary_name$$ where the -argument has type $codei%AD<%Base%>%$$. - -$head u$$ -The argument $icode u$$ has prototype -$codei% - const %Base% &%u% -%$$ -It is the value at which the user provided version of $icode unary_name$$ -is to be evaluated. -It is also used for the first argument to the -user provided version of $icode binary_name$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &%x% -%$$ -It is the value at which the CppAD provided version of $icode unary_name$$ -is to be evaluated. -It is also used for the first argument to the -CppAD provided version of $icode binary_name$$. - -$head b$$ -The result $icode b$$ has prototype -$codei% - bool %b% -%$$ - -$head Create Unary$$ -The preprocessor macro invocation -$codei% - CPPAD_BOOL_UNARY(%Base%, %unary_name%) -%$$ -defines the version of $icode unary_name$$ with a $codei%AD<%Base%>%$$ -argument. -This can with in a namespace -(not the $code CppAD$$ namespace) -but must be outside of any routine. - -$head binary_name$$ -This is the name of the $code bool$$ valued function with two arguments -(as it is used in the source code). -The user must provide a version of $icode binary_name$$ where -the arguments have type $icode Base$$. -CppAD uses this to create a version of $icode binary_name$$ where the -arguments have type $codei%AD<%Base%>%$$. - -$head v$$ -The argument $icode v$$ has prototype -$codei% - const %Base% &%v% -%$$ -It is the second argument to -the user provided version of $icode binary_name$$. - -$head y$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &%y% -%$$ -It is the second argument to -the CppAD provided version of $icode binary_name$$. - -$head Create Binary$$ -The preprocessor macro invocation -$codei% - CPPAD_BOOL_BINARY(%Base%, %binary_name%) -%$$ -defines the version of $icode binary_name$$ with $codei%AD<%Base%>%$$ -arguments. -This can with in a namespace -(not the $code CppAD$$ namespace) -but must be outside of any routine. - - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/bool_fun.cpp -%$$ -The file -$cref bool_fun.cpp$$ -contains an example and test of these operations. -It returns true if it succeeds and false otherwise. - -$head Deprecated 2007-07-31$$ -The preprocessor symbols $code CppADCreateUnaryBool$$ -and $code CppADCreateBinaryBool$$ are defined to be the same as -$code CPPAD_BOOL_UNARY$$ and $code CPPAD_BOOL_BINARY$$ respectively -(but their use is deprecated). - -$end -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file bool_fun.hpp -Routines and macros that implement functions from AD to bool. -*/ - -/*! -Macro that defines a unary function bool F(AD x) -using bool F(Base x). - -\param Base -base for the AD type of arguments to this unary bool valued function. - -\param unary_name -name of this unary function; i.e., \c F. -*/ -# define CPPAD_BOOL_UNARY(Base, unary_name) \ - inline bool unary_name (const CppAD::AD &x) \ - { \ - return CppAD::AD::UnaryBool(unary_name, x); \ - } - -/*! -Deprecated name for CPPAD_BOOL_UNARY -*/ -# define CppADCreateUnaryBool CPPAD_BOOL_UNARY - -/*! -Link a function name, and AD value pair to function call with base argument -and bool retrun value. - -\param FunName -is the name of the function that we are linking. - -\param x -is the argument where we are evaluating the function. -*/ -template -inline bool AD::UnaryBool( - bool FunName(const Base &x), - const AD &x -) -{ - return FunName(x.value_); -} - -/*! -Macro that defines a binary function bool F(AD x, AD y) -using bool F(Base x, Base y). - -\param Base -base for the AD type of arguments to this binary bool valued function. - -\param binary_name -name of this binary function; i.e., \c F. -*/ - -# define CPPAD_BOOL_BINARY(Base, binary_name) \ - inline bool binary_name ( \ - const CppAD::AD &x, const CppAD::AD &y) \ - { \ - return CppAD::AD::BinaryBool(binary_name, x, y); \ - } -/*! -Deprecated name for CPPAD_BOOL_BINARY -*/ -# define CppADCreateBinaryBool CPPAD_BOOL_BINARY - - -/*! -Link a function name, and two AD values to function call with base arguments -and bool retrun value. - -\param FunName -is the name of the function that we are linking. - -\param x -is the first argument where we are evaluating the function at. - -\param y -is the second argument where we are evaluating the function at. -*/ -template -inline bool AD::BinaryBool( - bool FunName(const Base &x, const Base &y), - const AD &x, const AD &y -) -{ - return FunName(x.value_, y.value_); -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/bool_valued.hpp b/external/cppad/include/cppad/core/bool_valued.hpp deleted file mode 100644 index 2853f36d3..000000000 --- a/external/cppad/include/cppad/core/bool_valued.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_BOOL_VALUED_HPP -# define CPPAD_CORE_BOOL_VALUED_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin BoolValued$$ -$spell - Bool -$$ - - -$section Bool Valued Operations and Functions with AD Arguments$$ - -$children% - cppad/core/compare.hpp% - cppad/core/near_equal_ext.hpp% - cppad/core/bool_fun.hpp% - cppad/core/par_var.hpp% - cppad/core/equal_op_seq.hpp -%$$ -$table -$rref Compare$$ -$rref NearEqualExt$$ -$rref BoolFun$$ -$rref ParVar$$ -$rref EqualOpSeq$$ -$tend - - -$end -*/ - -# include -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/capacity_order.hpp b/external/cppad/include/cppad/core/capacity_order.hpp deleted file mode 100644 index 0f8a43e56..000000000 --- a/external/cppad/include/cppad/core/capacity_order.hpp +++ /dev/null @@ -1,259 +0,0 @@ -# ifndef CPPAD_CORE_CAPACITY_ORDER_HPP -# define CPPAD_CORE_CAPACITY_ORDER_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin capacity_order$$ -$spell - var - taylor_ - xq - yq -$$ - - -$section Controlling Taylor Coefficients Memory Allocation$$ -$mindex Forward capacity_order control$$ - -$head Syntax$$ -$icode%f%.capacity_order(%c%)%$$ - -$subhead See Also$$ -$cref seq_property$$ - -$head Purpose$$ -The Taylor coefficients calculated by $cref Forward$$ mode calculations -are retained in an $cref ADFun$$ object for subsequent use during -$cref Reverse$$ mode and higher order Forward mode calculations. -For example, a call to $cref/Forward/forward_order/$$ with the syntax -$codei% - %yq% = %f%.Forward(%q%, %xq%) -%$$ -where $icode%q% > 0%$$ and $code%xq%.size() == %f%.Domain()%$$, -uses the lower order Taylor coefficients and -computes the $th q$$ order Taylor coefficients for all -the variables in the operation sequence corresponding to $icode f$$. -The $code capacity_order$$ operation allows you to control that -amount of memory that is retained by an AD function object -(to hold $code Forward$$ results for subsequent calculations). - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$head c$$ -The argument $icode c$$ has prototype -$codei% - size_t %c% -%$$ -It specifies the number of Taylor coefficient orders that are allocated -in the AD operation sequence corresponding to $icode f$$. - -$subhead Pre-Allocating Memory$$ -If you plan to make calls to $code Forward$$ with the maximum value of -$icode q$$ equal to $icode Q$$, -it should be faster to pre-allocate memory for these calls using -$codei% - %f%.capacity_order(%c%) -%$$ -with $icode c$$ equal to $latex Q + 1$$. -If you do no do this, $code Forward$$ will automatically allocate memory -and will copy the results to a larger buffer, when necessary. -$pre - -$$ -Note that each call to $cref Dependent$$ frees the old memory -connected to the function object and sets the corresponding -taylor capacity to zero. - -$subhead Freeing Memory$$ -If you no longer need the Taylor coefficients of order $icode q$$ -and higher (that are stored in $icode f$$), -you can reduce the memory allocated to $icode f$$ using -$codei% - %f%.capacity_order(%c%) -%$$ -with $icode c$$ equal to $icode q$$. -Note that, if $cref ta_hold_memory$$ is true, this memory is not actually -returned to the system, but rather held for future use by the same thread. - -$head Original State$$ -If $icode f$$ is $cref/constructed/FunConstruct/$$ with the syntax -$codei% - ADFun<%Base%> %f%(%x%, %y%) -%$$, -there is an implicit call to $cref forward_zero$$ with $icode xq$$ equal to -the value of the -$cref/independent variables/glossary/Tape/Independent Variable/$$ -when the AD operation sequence was recorded. -This corresponds to $icode%c% == 1%$$. - -$children% - example/general/capacity_order.cpp -%$$ -$head Example$$ -The file -$cref capacity_order.cpp$$ -contains an example and test of these operations. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file capacity_order.hpp -Control of number of orders allocated. -\} -*/ - -/*! -Control of number of orders and directions allocated. - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\param c -is the number of orders to allocate memory for. -If c == 0 then \c r must also be zero. -In this case num_order_taylor_, cap_order_taylor_, and num_direction_taylor_ -are all set to zero. -In addition, taylor_.free() is called. - -\param r -is the number of directions to allocate memory for. -If c == 1 then \c r must also be one. -In all cases, it must hold that - - r == num_direction_taylor_ || num_order_taylor <= 1 - -Upon return, num_direction_taylor_ is equal to r. - -\par num_order_taylor_ -The output value of num_order_taylor_ is the mininumum of its input -value and c. This minimum is the number of orders that are copied to the -new taylor coefficient buffer. - -\par num_direction_taylor_ -The output value of num_direction_taylor_ is equal to \c r. -*/ - -template -void ADFun::capacity_order(size_t c, size_t r) -{ // temporary indices - size_t i, k, ell; - - if( (c == cap_order_taylor_) & (r == num_direction_taylor_) ) - return; - - if( c == 0 ) - { CPPAD_ASSERT_UNKNOWN( r == 0 ); - taylor_.free(); - num_order_taylor_ = 0; - cap_order_taylor_ = 0; - num_direction_taylor_ = r; - return; - } - CPPAD_ASSERT_UNKNOWN(r==num_direction_taylor_ || num_order_taylor_<=1); - - // Allocate new taylor with requested number of orders and directions - size_t new_len = ( (c-1)*r + 1 ) * num_var_tape_; - local::pod_vector new_taylor; - new_taylor.extend(new_len); - - // number of orders to copy - size_t p = std::min(num_order_taylor_, c); - if( p > 0 ) - { - // old order capacity - size_t C = cap_order_taylor_; - - // old number of directions - size_t R = num_direction_taylor_; - - // copy the old data into the new matrix - CPPAD_ASSERT_UNKNOWN( p == 1 || r == R ); - for(i = 0; i < num_var_tape_; i++) - { // copy zero order - size_t old_index = ((C-1) * R + 1) * i + 0; - size_t new_index = ((c-1) * r + 1) * i + 0; - new_taylor[ new_index ] = taylor_[ old_index ]; - // copy higher orders - for(k = 1; k < p; k++) - { for(ell = 0; ell < R; ell++) - { old_index = ((C-1) * R + 1) * i + (k-1) * R + ell + 1; - new_index = ((c-1) * r + 1) * i + (k-1) * r + ell + 1; - new_taylor[ new_index ] = taylor_[ old_index ]; - } - } - } - } - - // replace taylor_ by new_taylor - taylor_.swap(new_taylor); - cap_order_taylor_ = c; - num_order_taylor_ = p; - num_direction_taylor_ = r; - - // note that the destructor for new_taylor will free the old taylor memory - return; -} - -/*! -User API control of number of orders allocated. - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\param c -is the number of orders to allocate memory for. -If c == 0, -num_order_taylor_, cap_order_taylor_, and num_direction_taylor_ -are all set to zero. -In addition, taylor_.free() is called. - -\par num_order_taylor_ -The output value of num_order_taylor_ is the mininumum of its input -value and c. This minimum is the number of orders that are copied to the -new taylor coefficient buffer. - -\par num_direction_taylor_ -If \c is zero (one), \c num_direction_taylor_ is set to zero (one). -Otherwise, if \c num_direction_taylor_ is zero, it is set to one. -Othwerwise, \c num_direction_taylor_ is not modified. -*/ - -template -void ADFun::capacity_order(size_t c) -{ size_t r; - if( (c == 0) | (c == 1) ) - { r = c; - capacity_order(c, r); - return; - } - r = num_direction_taylor_; - if( r == 0 ) - r = 1; - capacity_order(c, r); - return; -} - -} // END CppAD namespace - - -# endif diff --git a/external/cppad/include/cppad/core/check_for_nan.hpp b/external/cppad/include/cppad/core/check_for_nan.hpp deleted file mode 100644 index 0cb63bea0..000000000 --- a/external/cppad/include/cppad/core/check_for_nan.hpp +++ /dev/null @@ -1,198 +0,0 @@ -# ifndef CPPAD_CORE_CHECK_FOR_NAN_HPP -# define CPPAD_CORE_CHECK_FOR_NAN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin check_for_nan$$ -$spell - std - vec - Cpp - const - bool - newline -$$ -$section Check an ADFun Object For Nan Results$$ - -$head Syntax$$ -$icode%f%.check_for_nan(%b%) -%$$ -$icode%b% = %f%.check_for_nan() -%$$ -$codei%get_check_for_nan(%vec%, %file%) -%$$ - -$head Debugging$$ -If $code NDEBUG$$ is not defined, and -the result of a $cref/forward/forward_order/$$ or $cref/reverse/reverse_any/$$ -calculation contains a $cref nan$$, -CppAD can halt with an error message. - -$head f$$ -For the syntax where $icode b$$ is an argument, -$icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -(see $codei%ADFun<%Base%>%$$ $cref/constructor/FunConstruct/$$). -For the syntax where $icode b$$ is the result, -$icode f$$ has prototype -$codei% - const ADFun<%Base%> %f% -%$$ - -$head b$$ -This argument or result has prototype -$codei% - bool %b% -%$$ -Future calls to $icode%f%.Forward%$$ will (will not) check for $code nan$$. -depending on if $icode b$$ is true (false). - -$head Default$$ -The value for this setting after construction of $icode f$$) is true. -The value of this setting is not affected by calling -$cref Dependent$$ for this function object. - -$head Error Message$$ -If this error is detected during zero order forward mode, -the values of the independent variables that resulted in the $code nan$$ -are written to a temporary binary file. -This is so that you can run the original source code with those values -to see what is causing the $code nan$$. - -$subhead vector_size$$ -The error message with contain the text -$codei%vector_size = %vector_size%$$ followed the newline character -$code '\n'$$. -The value of $icode vector_size$$ is the number of elements -in the independent vector. - -$subhead file_name$$ -The error message with contain the text -$codei%file_name = %file_name%$$ followed the newline character -$code '\n'$$. -The value of $icode file_name$$ is the name of the temporary file -that contains the dependent variable values. - -$subhead index$$ -The error message will contain the text -$codei%index = %index%$$ followed by the newline character $code '\n'$$. -The value of $icode index$$ is the lowest dependent variable index -that has the value $code nan$$. - -$head get_check_for_nan$$ -This routine can be used to get the independent variable -values that result in a $code nan$$. - -$subhead vec$$ -This argument has prototype -$codei% - CppAD::vector<%Base%>& %vec% -%$$ -It size must be equal to the corresponding value of -$cref/vector_size/check_for_nan/Error Message/vector_size/$$ -in the corresponding error message. -The input value of its elements does not matter. -Upon return, it will contain the values for the independent variables, -in the corresponding call to $cref Independent$$, -that resulted in the $code nan$$. -(Note that the call to $code Independent$$ uses an vector with elements -of type $codei%AD<%Base%>%$$ and $icode vec$$ has elements of type -$icode Base$$.) - -$subhead file$$ -This argument has prototype -$codei% - const std::string& %file% -%$$ -It must be the value of -$cref/file_name/check_for_nan/Error Message/file_name/$$ -in the corresponding error message. - -$head Example$$ -$children% - example/general/check_for_nan.cpp -%$$ -The file -$cref check_for_nan.cpp$$ -contains an example and test of these operations. -It returns true if it succeeds and false otherwise. - -$end -*/ - -# include -# include -# include - -# if CPPAD_HAS_MKSTEMP -# include -# include -# else -# if CPPAD_HAS_TMPNAM_S -# include -# else -# include -# endif -# endif - - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -template -void put_check_for_nan(const CppAD::vector& vec, std::string& file_name) -{ - size_t char_size = sizeof(Base) * vec.size(); - const char* char_ptr = reinterpret_cast( vec.data() ); -# if CPPAD_HAS_MKSTEMP - char pattern[] = "/tmp/fileXXXXXX"; - int fd = mkstemp(pattern); - file_name = pattern; - write(fd, char_ptr, char_size); - close(fd); -# else -# if CPPAD_HAS_TMPNAM_S - std::vector name(L_tmpnam_s); - if( tmpnam_s( name.data(), L_tmpnam_s ) != 0 ) - { CPPAD_ASSERT_KNOWN( - false, - "Cannot create a temporary file name" - ); - } - file_name = name.data(); -# else - file_name = tmpnam( CPPAD_NULL ); -# endif - std::fstream file_out(file_name.c_str(), std::ios::out|std::ios::binary ); - file_out.write(char_ptr, char_size); - file_out.close(); -# endif - return; -} - -template -void get_check_for_nan(CppAD::vector& vec, const std::string& file_name) -{ // - size_t n = vec.size(); - size_t char_size = sizeof(Base) * n; - char* char_ptr = reinterpret_cast( vec.data() ); - // - std::fstream file_in(file_name.c_str(), std::ios::in|std::ios::binary ); - file_in.read(char_ptr, char_size); - // - return; -} - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/checkpoint.hpp b/external/cppad/include/cppad/core/checkpoint.hpp deleted file mode 100644 index d5e74673f..000000000 --- a/external/cppad/include/cppad/core/checkpoint.hpp +++ /dev/null @@ -1,1058 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_CHECKPOINT_HPP -# define CPPAD_CORE_CHECKPOINT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file checkpoint.hpp -defining checkpoint functions. -*/ - -/* -$begin checkpoint$$ -$spell - sv - var - cppad.hpp - CppAD - checkpoint - checkpointing - algo - atom_fun - const - enum - bool - recomputed -$$ - -$section Checkpointing Functions$$ - -$head Syntax$$ -$codei%checkpoint<%Base%> %atom_fun%( - %name%, %algo%, %ax%, %ay%, %sparsity%, %optimize% -) -%sv% = %atom_fun%.size_var() -%atom_fun%.option(%option_value%) -%algo%(%ax%, %ay%) -%atom_fun%(%ax%, %ay%) -checkpoint<%Base%>::clear()%$$ - -$head See Also$$ -$cref reverse_checkpoint.cpp$$ - -$head Purpose$$ - -$subhead Reduce Memory$$ -You can reduce the size of the tape and memory required for AD by -checkpointing functions of the form $latex y = f(x)$$ where -$latex f : B^n \rightarrow B^m$$. - -$subhead Faster Recording$$ -It may also reduce the time to make a recording the same function -for different values of the independent variable. -Note that the operation sequence for a recording that uses $latex f(x)$$ -may depend on its independent variables. - -$subhead Repeating Forward$$ -Normally, CppAD store $cref forward$$ mode results until they freed -using $cref capacity_order$$ or the corresponding $cref ADFun$$ object is -deleted. This is not true for checkpoint functions because a checkpoint -function may be used repeatedly with different arguments in the same tape. -Thus, forward mode results are recomputed each time a checkpoint function -is used during a forward or reverse mode sweep. - -$subhead Restriction$$ -The $cref/operation sequence/glossary/Operation/Sequence/$$ -representing $latex f(x)$$ cannot depend on the value of $latex x$$. -The approach in the $cref reverse_checkpoint.cpp$$ example case be applied -when the operation sequence depends on $latex x$$. - -$subhead Multiple Level AD$$ -If $icode Base$$ is an AD type, it is possible to record $icode Base$$ -operations. -Note that $icode atom_fun$$ will treat $icode algo$$ as an atomic -operation while recording $codei%AD%<%Base%>%$$ operations, but not while -recording $icode Base$$ operations. -See the $cref atomic_mul_level.cpp$$ example. - - -$head Method$$ -The $code checkpoint$$ class is derived from $code atomic_base$$ -and makes this easy. -It implements all the $code atomic_base$$ -$cref/virtual functions/atomic_base/Virtual Functions/$$ -and hence its source code $code cppad/core/checkpoint.hpp$$ -provides an example implementation of $cref atomic_base$$. -The difference is that $code checkpoint.hpp$$ uses AD -instead of user provided derivatives. - -$head constructor$$ -The syntax for the checkpoint constructor is -$codei% - checkpoint<%Base%> %atom_fun%(%name%, %algo%, %ax%, %ay%) -%$$ -$list number$$ -This constructor cannot be called in $cref/parallel/ta_in_parallel/$$ mode. -$lnext -You cannot currently be recording -$codei%AD<%Base%>%$$ operations when the constructor is called. -$lnext -This object $icode atom_fun$$ must not be destructed for as long -as any $codei%ADFun<%Base%>%$$ object uses its atomic operation. -$lnext -This class is implemented as a derived class of -$cref/atomic_base/atomic_ctor/atomic_base/$$ and hence -some of its error message will refer to $code atomic_base$$. -$lend - -$head Base$$ -The type $icode Base$$ specifies the base type for AD operations. - -$head ADVector$$ -The type $icode ADVector$$ must be a -$cref/simple vector class/SimpleVector/$$ with elements of type -$codei%AD<%Base%>%$$. - -$head name$$ -This $icode checkpoint$$ constructor argument has prototype -$codei% - const char* %name% -%$$ -It is the name used for error reporting. -The suggested value for $icode name$$ is $icode atom_fun$$; i.e., -the same name as used for the object being constructed. - -$head ax$$ -This argument has prototype -$codei% - const %ADVector%& %ax% -%$$ -and size must be equal to $icode n$$. -It specifies vector $latex x \in B^n$$ -at which an $codei%AD<%Base%>%$$ version of -$latex y = f(x)$$ is to be evaluated. - -$head ay$$ -This argument has prototype -$codei% - %ADVector%& %ay% -%$$ -Its input size must be equal to $icode m$$ and does not change. -The input values of its elements do not matter. -Upon return, it is an $codei%AD<%Base%>%$$ version of -$latex y = f(x)$$. - -$head sparsity$$ -This argument has prototype -$codei% - atomic_base<%Base%>::option_enum %sparsity% -%$$ -It specifies $cref/sparsity/atomic_ctor/atomic_base/sparsity/$$ -in the $code atomic_base$$ constructor and must be either -$codei%atomic_base<%Base%>::pack_sparsity_enum%$$, -$codei%atomic_base<%Base%>::bool_sparsity_enum%$$, or -$codei%atomic_base<%Base%>::set_sparsity_enum%$$. -This argument is optional and its default value is unspecified. - -$head optimize$$ -This argument has prototype -$codei% - bool %optimize% -%$$ -It specifies if the recording corresponding to the atomic function -should be $cref/optimized/optimize/$$. -One expects to use a checkpoint function many times, so it should -be worth the time to optimize its operation sequence. -For debugging purposes, it may be useful to use the -original operation sequence (before optimization) -because it corresponds more closely to $icode algo$$. -This argument is optional and its default value is true. - - -$head size_var$$ -This $code size_var$$ member function return value has prototype -$codei% - size_t %sv% -%$$ -It is the $cref/size_var/seq_property/size_var/$$ for the -$codei%ADFun<%Base%>%$$ object is used to store the operation sequence -corresponding to $icode algo$$. - -$head option$$ -The $code option$$ syntax can be used to set the type of sparsity -pattern used by $icode atom_fun$$. -This is an $codei%atomic_base<%Base%>%$$ function and its documentation -can be found at $cref atomic_option$$. - -$head algo$$ -The type of $icode algo$$ is arbitrary, except for the fact that -the syntax -$codei% - %algo%(%ax%, %ay%) -%$$ -must evaluate the function $latex y = f(x)$$ using -$codei%AD<%Base%>%$$ operations. -In addition, we assume that the -$cref/operation sequence/glossary/Operation/Sequence/$$ -does not depend on the value of $icode ax$$. - -$head atom_fun$$ -Given $icode ax$$ it computes the corresponding value of $icode ay$$ -using the operation sequence corresponding to $icode algo$$. -If $codei%AD<%Base%>%$$ operations are being recorded, -it enters the computation as single operation in the recording -see $cref/start recording/Independent/Start Recording/$$. -(Currently each use of $icode atom_fun$$ actually corresponds to -$icode%m%+%n%+2%$$ operations and creates $icode m$$ new variables, -but this is not part of the CppAD specifications and my change.) - -$head clear$$ -The $code atomic_base$$ class holds onto static work space in order to -increase speed by avoiding system memory allocation calls. -This call makes to work space $cref/available/ta_available/$$ to -for other uses by the same thread. -This should be called when you are done using the -user atomic functions for a specific value of $icode Base$$. - -$subhead Restriction$$ -The $code clear$$ routine cannot be called -while in $cref/parallel/ta_in_parallel/$$ execution mode. - -$children%example/atomic/checkpoint.cpp - %example/atomic/mul_level.cpp - %example/atomic/ode.cpp - %example/atomic/extended_ode.cpp -%$$ -$head Example$$ -The file $cref checkpoint.cpp$$ contains an example and test -of these operations. -It returns true if it succeeds and false if it fails. - -$end -*/ -template -class checkpoint : public atomic_base { -// --------------------------------------------------------------------------- -private: - /// same as option_enum in base class - typedef typename atomic_base::option_enum option_enum; - // - /// AD function corresponding to this checkpoint object - ADFun f_; - // - /// sparsity for entire Jacobian f(x)^{(1)} does not change so can cache it - local::sparse_list jac_sparse_set_; - vectorBool jac_sparse_bool_; - // - /// sparsity for sum_i f_i(x)^{(2)} does not change so can cache it - local::sparse_list hes_sparse_set_; - vectorBool hes_sparse_bool_; - // ------------------------------------------------------------------------ - option_enum sparsity(void) - { return static_cast< atomic_base* >(this)->sparsity(); } - // ------------------------------------------------------------------------ - /// set jac_sparse_set_ - void set_jac_sparse_set(void) - { CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == 0 ); - bool transpose = false; - bool dependency = true; - size_t n = f_.Domain(); - size_t m = f_.Range(); - // Use the choice for forward / reverse that results in smaller - // size for the sparsity pattern of all variables in the tape. - if( n <= m ) - { local::sparse_list identity; - identity.resize(n, n); - for(size_t j = 0; j < n; j++) - identity.add_element(j, j); - f_.ForSparseJacCheckpoint( - n, identity, transpose, dependency, jac_sparse_set_ - ); - f_.size_forward_set(0); - } - else - { local::sparse_list identity; - identity.resize(m, m); - for(size_t i = 0; i < m; i++) - identity.add_element(i, i); - f_.RevSparseJacCheckpoint( - m, identity, transpose, dependency, jac_sparse_set_ - ); - } - CPPAD_ASSERT_UNKNOWN( f_.size_forward_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( f_.size_forward_bool() == 0 ); - } - /// set jac_sparse_bool_ - void set_jac_sparse_bool(void) - { CPPAD_ASSERT_UNKNOWN( jac_sparse_bool_.size() == 0 ); - bool transpose = false; - bool dependency = true; - size_t n = f_.Domain(); - size_t m = f_.Range(); - // Use the choice for forward / reverse that results in smaller - // size for the sparsity pattern of all variables in the tape. - if( n <= m ) - { vectorBool identity(n * n); - for(size_t j = 0; j < n; j++) - { for(size_t i = 0; i < n; i++) - identity[ i * n + j ] = (i == j); - } - jac_sparse_bool_ = f_.ForSparseJac( - n, identity, transpose, dependency - ); - f_.size_forward_bool(0); - } - else - { vectorBool identity(m * m); - for(size_t j = 0; j < m; j++) - { for(size_t i = 0; i < m; i++) - identity[ i * m + j ] = (i == j); - } - jac_sparse_bool_ = f_.RevSparseJac( - m, identity, transpose, dependency - ); - } - CPPAD_ASSERT_UNKNOWN( f_.size_forward_bool() == 0 ); - CPPAD_ASSERT_UNKNOWN( f_.size_forward_set() == 0 ); - } - // ------------------------------------------------------------------------ - /// set hes_sparse_set_ - void set_hes_sparse_set(void) - { CPPAD_ASSERT_UNKNOWN( hes_sparse_set_.n_set() == 0 ); - size_t n = f_.Domain(); - size_t m = f_.Range(); - // - // set version of sparsity for vector of all ones - vector all_one(m); - for(size_t i = 0; i < m; i++) - all_one[i] = true; - - // set version of sparsity for n by n idendity matrix - local::sparse_list identity; - identity.resize(n, n); - for(size_t j = 0; j < n; j++) - identity.add_element(j, j); - - // compute sparsity pattern for H(x) = sum_i f_i(x)^{(2)} - bool transpose = false; - bool dependency = false; - f_.ForSparseJacCheckpoint( - n, identity, transpose, dependency, jac_sparse_set_ - ); - f_.RevSparseHesCheckpoint( - n, all_one, transpose, hes_sparse_set_ - ); - CPPAD_ASSERT_UNKNOWN( hes_sparse_set_.n_set() == n ); - CPPAD_ASSERT_UNKNOWN( hes_sparse_set_.end() == n ); - // - // drop the forward sparsity results from f_ - f_.size_forward_set(0); - } - /// set hes_sparse_bool_ - void set_hes_sparse_bool(void) - { CPPAD_ASSERT_UNKNOWN( hes_sparse_bool_.size() == 0 ); - size_t n = f_.Domain(); - size_t m = f_.Range(); - // - // set version of sparsity for vector of all ones - vectorBool all_one(m); - for(size_t i = 0; i < m; i++) - all_one[i] = true; - - // set version of sparsity for n by n idendity matrix - vectorBool identity(n * n); - for(size_t j = 0; j < n; j++) - { for(size_t i = 0; i < n; i++) - identity[ i * n + j ] = (i == j); - } - - // compute sparsity pattern for H(x) = sum_i f_i(x)^{(2)} - bool transpose = false; - bool dependency = false; - f_.ForSparseJac(n, identity, transpose, dependency); - hes_sparse_bool_ = f_.RevSparseHes(n, all_one, transpose); - CPPAD_ASSERT_UNKNOWN( hes_sparse_bool_.size() == n * n ); - // - // drop the forward sparsity results from f_ - f_.size_forward_bool(0); - CPPAD_ASSERT_UNKNOWN( f_.size_forward_bool() == 0 ); - CPPAD_ASSERT_UNKNOWN( f_.size_forward_set() == 0 ); - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to forward sparse Jacobian pack and bool - - \copydetails atomic_base::for_sparse_jac - */ - template - bool for_sparse_jac( - size_t q , - const sparsity_type& r , - sparsity_type& s , - const vector& x ) - { // during user sparsity calculations - size_t m = f_.Range(); - size_t n = f_.Domain(); - if( jac_sparse_bool_.size() == 0 ) - set_jac_sparse_bool(); - if( jac_sparse_set_.n_set() != 0 ) - jac_sparse_set_.resize(0, 0); - CPPAD_ASSERT_UNKNOWN( jac_sparse_bool_.size() == m * n ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( r.size() == n * q ); - CPPAD_ASSERT_UNKNOWN( s.size() == m * q ); - // - bool ok = true; - for(size_t i = 0; i < m; i++) - { for(size_t k = 0; k < q; k++) - s[i * q + k] = false; - } - // sparsity for s = jac_sparse_bool_ * r - for(size_t i = 0; i < m; i++) - { for(size_t k = 0; k < q; k++) - { // initialize sparsity for S(i,k) - bool s_ik = false; - // S(i,k) = sum_j J(i,j) * R(j,k) - for(size_t j = 0; j < n; j++) - { bool J_ij = jac_sparse_bool_[ i * n + j]; - bool R_jk = r[j * q + k ]; - s_ik |= ( J_ij & R_jk ); - } - s[i * q + k] = s_ik; - } - } - return ok; - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to reverse sparse Jacobian pack and bool - - \copydetails atomic_base::rev_sparse_jac - */ - template - bool rev_sparse_jac( - size_t q , - const sparsity_type& rt , - sparsity_type& st , - const vector& x ) - { // during user sparsity calculations - size_t m = f_.Range(); - size_t n = f_.Domain(); - if( jac_sparse_bool_.size() == 0 ) - set_jac_sparse_bool(); - if( jac_sparse_set_.n_set() != 0 ) - jac_sparse_set_.resize(0, 0); - CPPAD_ASSERT_UNKNOWN( jac_sparse_bool_.size() == m * n ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( rt.size() == m * q ); - CPPAD_ASSERT_UNKNOWN( st.size() == n * q ); - bool ok = true; - // - // S = R * J where J is jacobian - for(size_t i = 0; i < q; i++) - { for(size_t j = 0; j < n; j++) - { // initialize sparsity for S(i,j) - bool s_ij = false; - // S(i,j) = sum_k R(i,k) * J(k,j) - for(size_t k = 0; k < m; k++) - { // sparsity for R(i, k) - bool R_ik = rt[ k * q + i ]; - bool J_kj = jac_sparse_bool_[ k * n + j ]; - s_ij |= (R_ik & J_kj); - } - // set sparsity for S^T - st[ j * q + i ] = s_ij; - } - } - return ok; - } - /*! - Link from user_atomic to reverse sparse Hessian bools - - \copydetails atomic_base::rev_sparse_hes - */ - template - bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const sparsity_type& r , - const sparsity_type& u , - sparsity_type& v , - const vector& x ) - { size_t n = f_.Domain(); -# ifndef NDEBUG - size_t m = f_.Range(); -# endif - CPPAD_ASSERT_UNKNOWN( vx.size() == n ); - CPPAD_ASSERT_UNKNOWN( s.size() == m ); - CPPAD_ASSERT_UNKNOWN( t.size() == n ); - CPPAD_ASSERT_UNKNOWN( r.size() == n * q ); - CPPAD_ASSERT_UNKNOWN( u.size() == m * q ); - CPPAD_ASSERT_UNKNOWN( v.size() == n * q ); - // - bool ok = true; - - // make sure hes_sparse_bool_ has been set - if( hes_sparse_bool_.size() == 0 ) - set_hes_sparse_bool(); - if( hes_sparse_set_.n_set() != 0 ) - hes_sparse_set_.resize(0, 0); - CPPAD_ASSERT_UNKNOWN( hes_sparse_bool_.size() == n * n ); - CPPAD_ASSERT_UNKNOWN( hes_sparse_set_.n_set() == 0 ); - - - // compute sparsity pattern for T(x) = S(x) * f'(x) - t = f_.RevSparseJac(1, s); -# ifndef NDEBUG - for(size_t j = 0; j < n; j++) - CPPAD_ASSERT_UNKNOWN( vx[j] || ! t[j] ) -# endif - - // V(x) = f'(x)^T * g''(y) * f'(x) * R + g'(y) * f''(x) * R - // U(x) = g''(y) * f'(x) * R - // S(x) = g'(y) - - // compute sparsity pattern for A(x) = f'(x)^T * U(x) - bool transpose = true; - sparsity_type a(n * q); - a = f_.RevSparseJac(q, u, transpose); - - // Need sparsity pattern for H(x) = (S(x) * f(x))''(x) * R, - // but use less efficient sparsity for f(x)''(x) * R so that - // hes_sparse_set_ can be used every time this is needed. - for(size_t i = 0; i < n; i++) - { for(size_t k = 0; k < q; k++) - { // initialize sparsity pattern for H(i,k) - bool h_ik = false; - // H(i,k) = sum_j f''(i,j) * R(j,k) - for(size_t j = 0; j < n; j++) - { bool f_ij = hes_sparse_bool_[i * n + j]; - bool r_jk = r[j * q + k]; - h_ik |= ( f_ij & r_jk ); - } - // sparsity for H(i,k) - v[i * q + k] = h_ik; - } - } - - // compute sparsity pattern for V(x) = A(x) + H(x) - for(size_t i = 0; i < n; i++) - { for(size_t k = 0; k < q; k++) - // v[ i * q + k ] |= a[ i * q + k]; - v[ i * q + k ] = bool(v[ i * q + k]) | bool(a[ i * q + k]); - } - return ok; - } -public: - // ------------------------------------------------------------------------ - /*! - Constructor of a checkpoint object - - \param name [in] - is the user's name for the AD version of this atomic operation. - - \param algo [in/out] - user routine that compute AD function values - (not const because state may change during evaluation). - - \param ax [in] - argument value where algo operation sequence is taped. - - \param ay [out] - function value at specified argument value. - - \param sparsity [in] - what type of sparsity patterns are computed by this function, - pack_sparsity_enum bool_sparsity_enum, or set_sparsity_enum. - The default value is unspecified. - - \param optimize [in] -l should the operation sequence corresponding to the algo be optimized. - The default value is true, but it is - sometimes useful to use false for debugging purposes. - */ - template - checkpoint( - const char* name , - Algo& algo , - const ADVector& ax , - ADVector& ay , - option_enum sparsity = - atomic_base::pack_sparsity_enum , - bool optimize = true - ) : atomic_base(name, sparsity) - { CheckSimpleVector< CppAD::AD , ADVector>(); - - // make a copy of ax because Independent modifies AD information - ADVector x_tmp(ax); - // delcare x_tmp as the independent variables - Independent(x_tmp); - // record mapping from x_tmp to ay - algo(x_tmp, ay); - // create function f_ : x -> y - f_.Dependent(ay); - if( optimize ) - { // suppress checking for nan in f_ results - // (see optimize documentation for atomic functions) - f_.check_for_nan(false); - // - // now optimize - f_.optimize(); - } - // now disable checking of comparison operations - // 2DO: add a debugging mode that checks for changes and aborts - f_.compare_change_count(0); - } - // ------------------------------------------------------------------------ - /*! - Implement the user call to atom_fun.size_var(). - */ - size_t size_var(void) - { return f_.size_var(); } - // ------------------------------------------------------------------------ - /*! - Implement the user call to atom_fun(ax, ay). - - \tparam ADVector - A simple vector class with elements of type AD. - - \param id - optional parameter which must be zero if present. - - \param ax - is the argument vector for this call, - ax.size() determines the number of arguments. - - \param ay - is the result vector for this call, - ay.size() determines the number of results. - */ - template - void operator()(const ADVector& ax, ADVector& ay, size_t id = 0) - { CPPAD_ASSERT_KNOWN( - id == 0, - "checkpoint: id is non-zero in atom_fun(ax, ay, id)" - ); - this->atomic_base::operator()(ax, ay, id); - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to forward mode - - \copydetails atomic_base::forward - */ - virtual bool forward( - size_t p , - size_t q , - const vector& vx , - vector& vy , - const vector& tx , - vector& ty ) - { size_t n = f_.Domain(); - size_t m = f_.Range(); - // - CPPAD_ASSERT_UNKNOWN( f_.size_var() > 0 ); - CPPAD_ASSERT_UNKNOWN( tx.size() % (q+1) == 0 ); - CPPAD_ASSERT_UNKNOWN( ty.size() % (q+1) == 0 ); - CPPAD_ASSERT_UNKNOWN( n == tx.size() / (q+1) ); - CPPAD_ASSERT_UNKNOWN( m == ty.size() / (q+1) ); - bool ok = true; - // - if( vx.size() == 0 ) - { // during user forward mode - if( jac_sparse_set_.n_set() != 0 ) - jac_sparse_set_.resize(0,0); - if( jac_sparse_bool_.size() != 0 ) - jac_sparse_bool_.clear(); - // - if( hes_sparse_set_.n_set() != 0 ) - hes_sparse_set_.resize(0,0); - if( hes_sparse_bool_.size() != 0 ) - hes_sparse_bool_.clear(); - } - if( vx.size() > 0 ) - { // need Jacobian sparsity pattern to determine variable relation - // during user recording using checkpoint functions - if( sparsity() == atomic_base::set_sparsity_enum ) - { if( jac_sparse_set_.n_set() == 0 ) - set_jac_sparse_set(); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == m ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.end() == n ); - // - for(size_t i = 0; i < m; i++) - { vy[i] = false; - local::sparse_list::const_iterator set_itr(jac_sparse_set_, i); - size_t j = *set_itr; - while(j < n ) - { // y[i] depends on the value of x[j] - // cast avoid Microsoft warning (should not be needed) - vy[i] |= static_cast( vx[j] ); - j = *(++set_itr); - } - } - } - else - { if( jac_sparse_set_.n_set() != 0 ) - jac_sparse_set_.resize(0, 0); - if( jac_sparse_bool_.size() == 0 ) - set_jac_sparse_bool(); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_bool_.size() == m * n ); - // - for(size_t i = 0; i < m; i++) - { vy[i] = false; - for(size_t j = 0; j < n; j++) - { if( jac_sparse_bool_[ i * n + j ] ) - { // y[i] depends on the value of x[j] - // cast avoid Microsoft warning - vy[i] |= static_cast( vx[j] ); - } - } - } - } - } - // compute forward results for orders zero through q - ty = f_.Forward(q, tx); - - // no longer need the Taylor coefficients in f_ - // (have to reconstruct them every time) - // Hold onto sparsity pattern because it is always good. - size_t c = 0; - size_t r = 0; - f_.capacity_order(c, r); - return ok; - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to reverse mode - - \copydetails atomic_base::reverse - */ - virtual bool reverse( - size_t q , - const vector& tx , - const vector& ty , - vector& px , - const vector& py ) - { -# ifndef NDEBUG - size_t n = f_.Domain(); - size_t m = f_.Range(); -# endif - CPPAD_ASSERT_UNKNOWN( n == tx.size() / (q+1) ); - CPPAD_ASSERT_UNKNOWN( m == ty.size() / (q+1) ); - CPPAD_ASSERT_UNKNOWN( f_.size_var() > 0 ); - CPPAD_ASSERT_UNKNOWN( tx.size() % (q+1) == 0 ); - CPPAD_ASSERT_UNKNOWN( ty.size() % (q+1) == 0 ); - bool ok = true; - - // put proper forward mode coefficients in f_ -# ifdef NDEBUG - // compute forward results for orders zero through q - f_.Forward(q, tx); -# else - CPPAD_ASSERT_UNKNOWN( px.size() == n * (q+1) ); - CPPAD_ASSERT_UNKNOWN( py.size() == m * (q+1) ); - size_t i, j, k; - // - // compute forward results for orders zero through q - vector check_ty = f_.Forward(q, tx); - for(i = 0; i < m; i++) - { for(k = 0; k <= q; k++) - { j = i * (q+1) + k; - CPPAD_ASSERT_UNKNOWN( check_ty[j] == ty[j] ); - } - } -# endif - // now can run reverse mode - px = f_.Reverse(q+1, py); - - // no longer need the Taylor coefficients in f_ - // (have to reconstruct them every time) - size_t c = 0; - size_t r = 0; - f_.capacity_order(c, r); - return ok; - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to forward sparse Jacobian pack - - \copydetails atomic_base::for_sparse_jac - */ - virtual bool for_sparse_jac( - size_t q , - const vectorBool& r , - vectorBool& s , - const vector& x ) - { return for_sparse_jac< vectorBool >(q, r, s, x); - } - /*! - Link from user_atomic to forward sparse Jacobian bool - - \copydetails atomic_base::for_sparse_jac - */ - virtual bool for_sparse_jac( - size_t q , - const vector& r , - vector& s , - const vector& x ) - { return for_sparse_jac< vector >(q, r, s, x); - } - /*! - Link from user_atomic to forward sparse Jacobian sets - - \copydetails atomic_base::for_sparse_jac - */ - virtual bool for_sparse_jac( - size_t q , - const vector< std::set >& r , - vector< std::set >& s , - const vector& x ) - { // during user sparsity calculations - size_t m = f_.Range(); - size_t n = f_.Domain(); - if( jac_sparse_bool_.size() != 0 ) - jac_sparse_bool_.clear(); - if( jac_sparse_set_.n_set() == 0 ) - set_jac_sparse_set(); - CPPAD_ASSERT_UNKNOWN( jac_sparse_bool_.size() == 0 ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == m ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.end() == n ); - CPPAD_ASSERT_UNKNOWN( r.size() == n ); - CPPAD_ASSERT_UNKNOWN( s.size() == m ); - - bool ok = true; - for(size_t i = 0; i < m; i++) - s[i].clear(); - - // sparsity for s = jac_sparse_set_ * r - for(size_t i = 0; i < m; i++) - { // compute row i of the return pattern - local::sparse_list::const_iterator set_itr(jac_sparse_set_, i); - size_t j = *set_itr; - while(j < n ) - { std::set::const_iterator itr_j; - const std::set& r_j( r[j] ); - for(itr_j = r_j.begin(); itr_j != r_j.end(); itr_j++) - { size_t k = *itr_j; - CPPAD_ASSERT_UNKNOWN( k < q ); - s[i].insert(k); - } - j = *(++set_itr); - } - } - - return ok; - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to reverse sparse Jacobian pack - - \copydetails atomic_base::rev_sparse_jac - */ - virtual bool rev_sparse_jac( - size_t q , - const vectorBool& rt , - vectorBool& st , - const vector& x ) - { return rev_sparse_jac< vectorBool >(q, rt, st, x); - } - /*! - Link from user_atomic to reverse sparse Jacobian bool - - \copydetails atomic_base::rev_sparse_jac - */ - virtual bool rev_sparse_jac( - size_t q , - const vector& rt , - vector& st , - const vector& x ) - { return rev_sparse_jac< vector >(q, rt, st, x); - } - /*! - Link from user_atomic to reverse Jacobian sets - - \copydetails atomic_base::rev_sparse_jac - */ - virtual bool rev_sparse_jac( - size_t q , - const vector< std::set >& rt , - vector< std::set >& st , - const vector& x ) - { // during user sparsity calculations - size_t m = f_.Range(); - size_t n = f_.Domain(); - if( jac_sparse_bool_.size() != 0 ) - jac_sparse_bool_.clear(); - if( jac_sparse_set_.n_set() == 0 ) - set_jac_sparse_set(); - CPPAD_ASSERT_UNKNOWN( jac_sparse_bool_.size() == 0 ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.n_set() == m ); - CPPAD_ASSERT_UNKNOWN( jac_sparse_set_.end() == n ); - CPPAD_ASSERT_UNKNOWN( rt.size() == m ); - CPPAD_ASSERT_UNKNOWN( st.size() == n ); - // - bool ok = true; - // - for(size_t j = 0; j < n; j++) - st[j].clear(); - // - // sparsity for s = r * jac_sparse_set_ - // s^T = jac_sparse_set_^T * r^T - for(size_t i = 0; i < m; i++) - { // i is the row index in r^T - std::set::const_iterator itr_i; - const std::set& r_i( rt[i] ); - for(itr_i = r_i.begin(); itr_i != r_i.end(); itr_i++) - { // k is the column index in r^T - size_t k = *itr_i; - CPPAD_ASSERT_UNKNOWN( k < q ); - // - // i is column index in jac_sparse_set^T - local::sparse_list::const_iterator set_itr(jac_sparse_set_, i); - size_t j = *set_itr; - while( j < n ) - { // j is row index in jac_sparse_set^T - st[j].insert(k); - j = *(++set_itr); - } - } - } - - return ok; - } - // ------------------------------------------------------------------------ - /*! - Link from user_atomic to reverse sparse Hessian pack - - \copydetails atomic_base::rev_sparse_hes - */ - virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vectorBool& r , - const vectorBool& u , - vectorBool& v , - const vector& x ) - { return rev_sparse_hes< vectorBool >(vx, s, t, q, r, u, v, x); - } - /*! - Link from user_atomic to reverse sparse Hessian bool - - \copydetails atomic_base::rev_sparse_hes - */ - virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vector& r , - const vector& u , - vector& v , - const vector& x ) - { return rev_sparse_hes< vector >(vx, s, t, q, r, u, v, x); - } - /*! - Link from user_atomic to reverse sparse Hessian sets - - \copydetails atomic_base::rev_sparse_hes - */ - virtual bool rev_sparse_hes( - const vector& vx , - const vector& s , - vector& t , - size_t q , - const vector< std::set >& r , - const vector< std::set >& u , - vector< std::set >& v , - const vector& x ) - { size_t n = f_.Domain(); -# ifndef NDEBUG - size_t m = f_.Range(); -# endif - CPPAD_ASSERT_UNKNOWN( vx.size() == n ); - CPPAD_ASSERT_UNKNOWN( s.size() == m ); - CPPAD_ASSERT_UNKNOWN( t.size() == n ); - CPPAD_ASSERT_UNKNOWN( r.size() == n ); - CPPAD_ASSERT_UNKNOWN( u.size() == m ); - CPPAD_ASSERT_UNKNOWN( v.size() == n ); - // - bool ok = true; - - // make sure hes_sparse_set_ has been set - if( hes_sparse_bool_.size() != 0 ) - hes_sparse_bool_.clear(); - if( hes_sparse_set_.n_set() == 0 ) - set_hes_sparse_set(); - CPPAD_ASSERT_UNKNOWN( hes_sparse_bool_.size() == 0 ); - CPPAD_ASSERT_UNKNOWN( hes_sparse_set_.n_set() == n ); - CPPAD_ASSERT_UNKNOWN( hes_sparse_set_.end() == n ); - - // compute sparsity pattern for T(x) = S(x) * f'(x) - t = f_.RevSparseJac(1, s); -# ifndef NDEBUG - for(size_t j = 0; j < n; j++) - CPPAD_ASSERT_UNKNOWN( vx[j] || ! t[j] ) -# endif - - // V(x) = f'(x)^T * g''(y) * f'(x) * R + g'(y) * f''(x) * R - // U(x) = g''(y) * f'(x) * R - // S(x) = g'(y) - - // compute sparsity pattern for A(x) = f'(x)^T * U(x) - // 2DO: change a to use INTERNAL_SPARSE_SET - bool transpose = true; - vector< std::set > a(n); - a = f_.RevSparseJac(q, u, transpose); - - // Need sparsity pattern for H(x) = (S(x) * f(x))''(x) * R, - // but use less efficient sparsity for f(x)''(x) * R so that - // hes_sparse_set_ can be used every time this is needed. - for(size_t i = 0; i < n; i++) - { v[i].clear(); - local::sparse_list::const_iterator set_itr(hes_sparse_set_, i); - size_t j = *set_itr; - while( j < n ) - { std::set::const_iterator itr_j; - const std::set& r_j( r[j] ); - for(itr_j = r_j.begin(); itr_j != r_j.end(); itr_j++) - { size_t k = *itr_j; - v[i].insert(k); - } - j = *(++set_itr); - } - } - // compute sparsity pattern for V(x) = A(x) + H(x) - std::set::const_iterator itr; - for(size_t i = 0; i < n; i++) - { for(itr = a[i].begin(); itr != a[i].end(); itr++) - { size_t j = *itr; - CPPAD_ASSERT_UNKNOWN( j < q ); - v[i].insert(j); - } - } - - return ok; - } -}; - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/compare.hpp b/external/cppad/include/cppad/core/compare.hpp deleted file mode 100644 index 69664eb00..000000000 --- a/external/cppad/include/cppad/core/compare.hpp +++ /dev/null @@ -1,415 +0,0 @@ -# ifndef CPPAD_CORE_COMPARE_HPP -# define CPPAD_CORE_COMPARE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin Compare$$ -$spell - cos - Op - bool - const -$$ - - - -$section AD Binary Comparison Operators$$ -$mindex compare < <= > >= == !=$$ - - -$head Syntax$$ - -$icode%b% = %x% %Op% %y%$$ - - -$head Purpose$$ -Compares two operands where one of the operands is an -$codei%AD<%Base%>%$$ object. -The comparison has the same interpretation as for -the $icode Base$$ type. - - -$head Op$$ -The operator $icode Op$$ is one of the following: -$table -$bold Op$$ $pre $$ $cnext $bold Meaning$$ $rnext -$code <$$ $cnext is $icode x$$ less than $icode y$$ $rnext -$code <=$$ $cnext is $icode x$$ less than or equal $icode y$$ $rnext -$code >$$ $cnext is $icode x$$ greater than $icode y$$ $rnext -$code >=$$ $cnext is $icode x$$ greater than or equal $icode y$$ $rnext -$code ==$$ $cnext is $icode x$$ equal to $icode y$$ $rnext -$code !=$$ $cnext is $icode x$$ not equal to $icode y$$ -$tend - -$head x$$ -The operand $icode x$$ has prototype -$codei% - const %Type% &%x% -%$$ -where $icode Type$$ is $codei%AD<%Base%>%$$, $icode Base$$, or $code int$$. - -$head y$$ -The operand $icode y$$ has prototype -$codei% - const %Type% &%y% -%$$ -where $icode Type$$ is $codei%AD<%Base%>%$$, $icode Base$$, or $code int$$. - -$head b$$ -The result $icode b$$ has type -$codei% - bool %b% -%$$ - -$head Operation Sequence$$ -The result of this operation is a $code bool$$ value -(not an $cref/AD of Base/glossary/AD of Base/$$ object). -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. -$pre - -$$ -For example, suppose -$icode x$$ and $icode y$$ are $codei%AD<%Base%>%$$ objects, -the tape corresponding to $codei%AD<%Base%>%$$ is recording, -$icode b$$ is true, -and the subsequent code is -$codei% - if( %b% ) - %y% = cos(%x%); - else %y% = sin(%x%); -%$$ -only the assignment $icode%y% = cos(%x%)%$$ is recorded on the tape -(if $icode x$$ is a $cref/parameter/glossary/Parameter/$$, -nothing is recorded). -The $cref CompareChange$$ function can yield -some information about changes in comparison operation results. -You can use $cref CondExp$$ to obtain comparison operations -that depends on the -$cref/independent variable/glossary/Tape/Independent Variable/$$ -values with out re-taping the AD sequence of operations. - -$head Assumptions$$ -If one of the $icode Op$$ operators listed above -is used with an $codei%AD<%Base%>%$$ object, -it is assumed that the same operator is supported by the base type -$icode Base$$. - -$head Example$$ -$children% - example/general/compare.cpp -%$$ -The file -$cref compare.cpp$$ -contains an example and test of these operations. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -// BEGIN CppAD namespace -namespace CppAD { - -// -------------------------------- < -------------------------- -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool operator < (const AD &left , const AD &right) -{ bool result = (left.value_ < right.value_); - bool var_left = Variable(left); - bool var_right = Variable(right); - - local::ADTape *tape = CPPAD_NULL; - if( var_left ) - { tape = left.tape_this(); - if( var_right ) - { if( result ) - { tape->Rec_.PutOp(local::LtvvOp); - tape->Rec_.PutArg(left.taddr_, right.taddr_); - } - else - { tape->Rec_.PutOp(local::LevvOp); - tape->Rec_.PutArg(right.taddr_, left.taddr_); - } - } - else - { addr_t arg1 = tape->Rec_.PutPar(right.value_); - if( result ) - { tape->Rec_.PutOp(local::LtvpOp); - tape->Rec_.PutArg(left.taddr_, arg1); - } - else - { tape->Rec_.PutOp(local::LepvOp); - tape->Rec_.PutArg(arg1, left.taddr_); - } - } - } - else if ( var_right ) - { tape = right.tape_this(); - addr_t arg0 = tape->Rec_.PutPar(left.value_); - if( result ) - { tape->Rec_.PutOp(local::LtpvOp); - tape->Rec_.PutArg(arg0, right.taddr_); - } - else - { tape->Rec_.PutOp(local::LevpOp); - tape->Rec_.PutArg(right.taddr_, arg0); - } - } - - return result; -} -// convert other cases into the case above -CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(<) - -// -------------------------------- <= ------------------------- -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool operator <= (const AD &left , const AD &right) -{ bool result = (left.value_ <= right.value_); - bool var_left = Variable(left); - bool var_right = Variable(right); - - local::ADTape *tape = CPPAD_NULL; - if( var_left ) - { tape = left.tape_this(); - if( var_right ) - { if( result ) - { tape->Rec_.PutOp(local::LevvOp); - tape->Rec_.PutArg(left.taddr_, right.taddr_); - } - else - { tape->Rec_.PutOp(local::LtvvOp); - tape->Rec_.PutArg(right.taddr_, left.taddr_); - } - } - else - { addr_t arg1 = tape->Rec_.PutPar(right.value_); - if( result ) - { tape->Rec_.PutOp(local::LevpOp); - tape->Rec_.PutArg(left.taddr_, arg1); - } - else - { tape->Rec_.PutOp(local::LtpvOp); - tape->Rec_.PutArg(arg1, left.taddr_); - } - } - } - else if ( var_right ) - { tape = right.tape_this(); - addr_t arg0 = tape->Rec_.PutPar(left.value_); - if( result ) - { tape->Rec_.PutOp(local::LepvOp); - tape->Rec_.PutArg(arg0, right.taddr_); - } - else - { tape->Rec_.PutOp(local::LtvpOp); - tape->Rec_.PutArg(right.taddr_, arg0); - } - } - - return result; -} -// convert other cases into the case above -CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(<=) - -// -------------------------------- > -------------------------- -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool operator > (const AD &left , const AD &right) -{ bool result = (left.value_ > right.value_); - bool var_left = Variable(left); - bool var_right = Variable(right); - - local::ADTape *tape = CPPAD_NULL; - if( var_left ) - { tape = left.tape_this(); - if( var_right ) - { if( result ) - { tape->Rec_.PutOp(local::LtvvOp); - tape->Rec_.PutArg(right.taddr_, left.taddr_); - } - else - { tape->Rec_.PutOp(local::LevvOp); - tape->Rec_.PutArg(left.taddr_, right.taddr_); - } - } - else - { addr_t arg1 = tape->Rec_.PutPar(right.value_); - if( result ) - { tape->Rec_.PutOp(local::LtpvOp); - tape->Rec_.PutArg(arg1, left.taddr_); - } - else - { tape->Rec_.PutOp(local::LevpOp); - tape->Rec_.PutArg(left.taddr_, arg1); - } - } - } - else if ( var_right ) - { tape = right.tape_this(); - addr_t arg0 = tape->Rec_.PutPar(left.value_); - if( result ) - { tape->Rec_.PutOp(local::LtvpOp); - tape->Rec_.PutArg(right.taddr_, arg0); - } - else - { tape->Rec_.PutOp(local::LepvOp); - tape->Rec_.PutArg(arg0, right.taddr_); - } - } - - return result; -} -// convert other cases into the case above -CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(>) - -// -------------------------------- >= ------------------------- -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool operator >= (const AD &left , const AD &right) -{ bool result = (left.value_ >= right.value_); - bool var_left = Variable(left); - bool var_right = Variable(right); - - local::ADTape *tape = CPPAD_NULL; - if( var_left ) - { tape = left.tape_this(); - if( var_right ) - { if( result ) - { tape->Rec_.PutOp(local::LevvOp); - tape->Rec_.PutArg(right.taddr_, left.taddr_); - } - else - { tape->Rec_.PutOp(local::LtvvOp); - tape->Rec_.PutArg(left.taddr_, right.taddr_); - } - } - else - { addr_t arg1 = tape->Rec_.PutPar(right.value_); - if( result ) - { tape->Rec_.PutOp(local::LepvOp); - tape->Rec_.PutArg(arg1, left.taddr_); - } - else - { tape->Rec_.PutOp(local::LtvpOp); - tape->Rec_.PutArg(left.taddr_, arg1); - } - } - } - else if ( var_right ) - { tape = right.tape_this(); - addr_t arg0 = tape->Rec_.PutPar(left.value_); - if( result ) - { tape->Rec_.PutOp(local::LevpOp); - tape->Rec_.PutArg(right.taddr_, arg0); - } - else - { tape->Rec_.PutOp(local::LtpvOp); - tape->Rec_.PutArg(arg0, right.taddr_); - } - } - - return result; -} -// convert other cases into the case above -CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(>=) - -// -------------------------------- == ------------------------- -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool operator == (const AD &left , const AD &right) -{ bool result = (left.value_ == right.value_); - bool var_left = Variable(left); - bool var_right = Variable(right); - - local::ADTape *tape = CPPAD_NULL; - if( var_left ) - { tape = left.tape_this(); - if( var_right ) - { tape->Rec_.PutArg(left.taddr_, right.taddr_); - if( result ) - tape->Rec_.PutOp(local::EqvvOp); - else - tape->Rec_.PutOp(local::NevvOp); - } - else - { addr_t arg1 = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(arg1, left.taddr_); - if( result ) - tape->Rec_.PutOp(local::EqpvOp); - else - tape->Rec_.PutOp(local::NepvOp); - } - } - else if ( var_right ) - { tape = right.tape_this(); - addr_t arg0 = tape->Rec_.PutPar(left.value_); - tape->Rec_.PutArg(arg0, right.taddr_); - if( result ) - tape->Rec_.PutOp(local::EqpvOp); - else - tape->Rec_.PutOp(local::NepvOp); - } - - return result; -} -// convert other cases into the case above -CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(==) - -// -------------------------------- != ------------------------- -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool operator != (const AD &left , const AD &right) -{ bool result = (left.value_ != right.value_); - bool var_left = Variable(left); - bool var_right = Variable(right); - - local::ADTape *tape = CPPAD_NULL; - if( var_left ) - { tape = left.tape_this(); - if( var_right ) - { tape->Rec_.PutArg(left.taddr_, right.taddr_); - if( result ) - tape->Rec_.PutOp(local::NevvOp); - else - tape->Rec_.PutOp(local::EqvvOp); - } - else - { addr_t arg1 = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(arg1, left.taddr_); - if( result ) - tape->Rec_.PutOp(local::NepvOp); - else - tape->Rec_.PutOp(local::EqpvOp); - } - } - else if ( var_right ) - { tape = right.tape_this(); - addr_t arg0 = tape->Rec_.PutPar(left.value_); - tape->Rec_.PutArg(arg0, right.taddr_); - if( result ) - tape->Rec_.PutOp(local::NepvOp); - else - tape->Rec_.PutOp(local::EqpvOp); - } - - return result; -} -// convert other cases into the case above -CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(!=) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/compound_assign.hpp b/external/cppad/include/cppad/core/compound_assign.hpp deleted file mode 100644 index 2f2195cd4..000000000 --- a/external/cppad/include/cppad/core/compound_assign.hpp +++ /dev/null @@ -1,142 +0,0 @@ -# ifndef CPPAD_CORE_COMPOUND_ASSIGN_HPP -# define CPPAD_CORE_COMPOUND_ASSIGN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin compound_assign$$ -$spell - Op - VecAD - const -$$ - -$section AD Compound Assignment Operators$$ -$mindex + add plus - subtract minus * multiply times / divide multiple$$ - - - - - - -$head Syntax$$ -$icode%x% %Op% %y%$$ - -$head Purpose$$ -Performs compound assignment operations -where either $icode x$$ has type -$codei%AD<%Base%>%$$. - -$head Op$$ -The operator $icode Op$$ is one of the following -$table -$bold Op$$ $cnext $bold Meaning$$ $rnext -$code +=$$ $cnext $icode x$$ is assigned $icode x$$ plus $icode y$$ $rnext -$code -=$$ $cnext $icode x$$ is assigned $icode x$$ minus $icode y$$ $rnext -$code *=$$ $cnext $icode x$$ is assigned $icode x$$ times $icode y$$ $rnext -$code /=$$ $cnext $icode x$$ is assigned $icode x$$ divided by $icode y$$ -$tend - -$head Base$$ -The type $icode Base$$ is determined by the operand $icode x$$. - -$head x$$ -The operand $icode x$$ has the following prototype -$codei% - AD<%Base%> &%x% -%$$ - -$head y$$ -The operand $icode y$$ has the following prototype -$codei% - const %Type% &%y% -%$$ -where $icode Type$$ is -$codei%VecAD<%Base%>::reference%$$, -$codei%AD<%Base%>%$$, -$icode Base$$, or -$code double$$. - -$head Result$$ -The result of this assignment -can be used as a reference to $icode x$$. -For example, if $icode z$$ has the following type -$codei% - AD<%Base%> %z% -%$$ -then the syntax -$codei% - %z% = %x% += %y% -%$$ -will compute $icode x$$ plus $icode y$$ -and then assign this value to both $icode x$$ and $icode z$$. - - -$head Operation Sequence$$ -This is an $cref/atomic/glossary/Operation/Atomic/$$ -$cref/AD of Base/glossary/AD of Base/$$ operation -and hence it is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$children% - example/general/add_eq.cpp% - example/general/sub_eq.cpp% - example/general/mul_eq.cpp% - example/general/div_eq.cpp -%$$ - -$head Example$$ -The following files contain examples and tests of these functions. -Each test returns true if it succeeds and false otherwise. -$table -$rref AddEq.cpp$$ -$rref sub_eq.cpp$$ -$rref mul_eq.cpp$$ -$rref div_eq.cpp$$ -$tend - -$head Derivative$$ -If $latex f$$ and $latex g$$ are -$cref/Base functions/glossary/Base Function/$$ - -$subhead Addition$$ -$latex \[ - \D{[ f(x) + g(x) ]}{x} = \D{f(x)}{x} + \D{g(x)}{x} -\] $$ - -$subhead Subtraction$$ -$latex \[ - \D{[ f(x) - g(x) ]}{x} = \D{f(x)}{x} - \D{g(x)}{x} -\] $$ - -$subhead Multiplication$$ -$latex \[ - \D{[ f(x) * g(x) ]}{x} = g(x) * \D{f(x)}{x} + f(x) * \D{g(x)}{x} -\] $$ - -$subhead Division$$ -$latex \[ - \D{[ f(x) / g(x) ]}{x} = - [1/g(x)] * \D{f(x)}{x} - [f(x)/g(x)^2] * \D{g(x)}{x} -\] $$ - -$end ------------------------------------------------------------------------------ -*/ -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/cond_exp.hpp b/external/cppad/include/cppad/core/cond_exp.hpp deleted file mode 100644 index e4b9993c0..000000000 --- a/external/cppad/include/cppad/core/cond_exp.hpp +++ /dev/null @@ -1,354 +0,0 @@ -# ifndef CPPAD_CORE_COND_EXP_HPP -# define CPPAD_CORE_COND_EXP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin CondExp$$ -$spell - Atan2 - CondExp - Taylor - std - Cpp - namespace - inline - const - abs - Rel - bool - Lt - Le - Eq - Ge - Gt -$$ - - -$section AD Conditional Expressions$$ -$mindex assign$$ - -$head Syntax$$ -$icode%result% = CondExp%Rel%(%left%, %right%, %if_true%, %if_false%)%$$ - - -$head Purpose$$ -Record, -as part of an AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$, -the conditional result -$codei% - if( %left% %Cop% %right% ) - %result% = %if_true% - else %result% = %if_false% -%$$ -The relational $icode Rel$$ and comparison operator $icode Cop$$ -above have the following correspondence: -$codei% - %Rel% Lt Le Eq Ge Gt - %Cop% < <= == >= > -%$$ -If $icode f$$ is the $cref ADFun$$ object corresponding to the -AD operation sequence, -the assignment choice for $icode result$$ -in an AD conditional expression is made each time -$cref/f.Forward/Forward/$$ is used to evaluate the zero order Taylor -coefficients with new values for the -$cref/independent variables/glossary/Tape/Independent Variable/$$. -This is in contrast to the $cref/AD comparison operators/Compare/$$ -which are boolean valued and not included in the AD operation sequence. - -$head Rel$$ -In the syntax above, the relation $icode Rel$$ represents one of the following -two characters: $code Lt$$, $code Le$$, $code Eq$$, $code Ge$$, $code Gt$$. -As in the table above, -$icode Rel$$ determines which comparison operator $icode Cop$$ is used -when comparing $icode left$$ and $icode right$$. - -$head Type$$ -These functions are defined in the CppAD namespace for arguments of -$icode Type$$ is $code float$$ , $code double$$, or any type of the form -$codei%AD<%Base%>%$$. -(Note that all four arguments must have the same type.) - -$head left$$ -The argument $icode left$$ has prototype -$codei% - const %Type%& %left% -%$$ -It specifies the value for the left side of the comparison operator. - -$head right$$ -The argument $icode right$$ has prototype -$codei% - const %Type%& %right% -%$$ -It specifies the value for the right side of the comparison operator. - -$head if_true$$ -The argument $icode if_true$$ has prototype -$codei% - const %Type%& %if_true% -%$$ -It specifies the return value if the result of the comparison is true. - -$head if_false$$ -The argument $icode if_false$$ has prototype -$codei% - const %Type%& %if_false% -%$$ -It specifies the return value if the result of the comparison is false. - -$head result$$ -The $icode result$$ has prototype -$codei% - %Type%& %if_false% -%$$ - -$head Optimize$$ -The $cref optimize$$ method will optimize conditional expressions -in the following way: -During $cref/zero order forward mode/forward_zero/$$, -once the value of the $icode left$$ and $icode right$$ have been determined, -it is known if the true or false case is required. -From this point on, values corresponding to the case that is not required -are not computed. -This optimization is done for the rest of zero order forward mode -as well as forward and reverse derivatives calculations. - -$head Deprecate 2005-08-07$$ -Previous versions of CppAD used -$codei% - CondExp(%flag%, %if_true%, %if_false%) -%$$ -for the same meaning as -$codei% - CondExpGt(%flag%, %Type%(0), %if_true%, %if_false%) -%$$ -Use of $code CondExp$$ is deprecated, but continues to be supported. - -$head Operation Sequence$$ -This is an AD of $icode Base$$ -$cref/atomic operation/glossary/Operation/Atomic/$$ -and hence is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - - -$head Example$$ - -$head Test$$ -$children% - example/general/cond_exp.cpp -%$$ -The file -$cref cond_exp.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$head Atan2$$ -The following implementation of the -AD $cref atan2$$ function is a more complex -example of using conditional expressions: -$code -$srcfile%cppad/core/atan2.hpp%0%BEGIN CondExp%// END CondExp%$$ -$$ - - -$end -------------------------------------------------------------------------------- -*/ -// BEGIN CppAD namespace -namespace CppAD { - -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -AD CondExpOp( - enum CompareOp cop , - const AD &left , - const AD &right , - const AD &if_true , - const AD &if_false ) -{ - AD returnValue; - CPPAD_ASSERT_UNKNOWN( Parameter(returnValue) ); - - // check first case where do not need to tape - if( IdenticalPar(left) & IdenticalPar(right) ) - { switch( cop ) - { - case CompareLt: - if( left.value_ < right.value_ ) - returnValue = if_true; - else returnValue = if_false; - break; - - case CompareLe: - if( left.value_ <= right.value_ ) - returnValue = if_true; - else returnValue = if_false; - break; - - case CompareEq: - if( left.value_ == right.value_ ) - returnValue = if_true; - else returnValue = if_false; - break; - - case CompareGe: - if( left.value_ >= right.value_ ) - returnValue = if_true; - else returnValue = if_false; - break; - - case CompareGt: - if( left.value_ > right.value_ ) - returnValue = if_true; - else returnValue = if_false; - break; - - default: - CPPAD_ASSERT_UNKNOWN(0); - returnValue = if_true; - } - return returnValue; - } - - // must use CondExp incase Base is an AD type and recording - returnValue.value_ = CondExpOp(cop, - left.value_, right.value_, if_true.value_, if_false.value_); - - local::ADTape *tape = CPPAD_NULL; - if( Variable(left) ) - tape = left.tape_this(); - if( Variable(right) ) - tape = right.tape_this(); - if( Variable(if_true) ) - tape = if_true.tape_this(); - if( Variable(if_false) ) - tape = if_false.tape_this(); - - // add this operation to the tape - if( tape != CPPAD_NULL ) - tape->RecordCondExp(cop, - returnValue, left, right, if_true, if_false); - - return returnValue; -} - -// --- RecordCondExp(cop, returnValue, left, right, if_true, if_false) ----- - -/// All these operations are done in \c Rec_, so we should move this -/// routine to recorder. -template -void local::ADTape::RecordCondExp( - enum CompareOp cop , - AD &returnValue , - const AD &left , - const AD &right , - const AD &if_true , - const AD &if_false ) -{ addr_t ind0, ind1, ind2, ind3, ind4, ind5; - addr_t returnValue_taddr; - - // taddr_ of this variable - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - returnValue_taddr = Rec_.PutOp(CExpOp); - - // ind[0] = cop - ind0 = addr_t( cop ); - - // ind[1] = base 2 represenation of the value - // [Var(left), Var(right), Var(if_true), Var(if_false)] - ind1 = 0; - - // Make sure returnValue is in the list of variables and set its taddr - if( Parameter(returnValue) ) - returnValue.make_variable(id_, returnValue_taddr ); - else returnValue.taddr_ = returnValue_taddr; - - // ind[2] = left address - if( Parameter(left) ) - ind2 = Rec_.PutPar(left.value_); - else - { ind1 += 1; - ind2 = left.taddr_; - } - - // ind[3] = right address - if( Parameter(right) ) - ind3 = Rec_.PutPar(right.value_); - else - { ind1 += 2; - ind3 = right.taddr_; - } - - // ind[4] = if_true address - if( Parameter(if_true) ) - ind4 = Rec_.PutPar(if_true.value_); - else - { ind1 += 4; - ind4 = if_true.taddr_; - } - - // ind[5] = if_false address - if( Parameter(if_false) ) - ind5 = Rec_.PutPar(if_false.value_); - else - { ind1 += 8; - ind5 = if_false.taddr_; - } - - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( ind1 > 0 ); - Rec_.PutArg(ind0, ind1, ind2, ind3, ind4, ind5); - - // check that returnValue is a dependent variable - CPPAD_ASSERT_UNKNOWN( Variable(returnValue) ); -} - -// ------------ CondExpOp(left, right, if_true, if_false) ---------------- - -# define CPPAD_COND_EXP(Name) \ - template \ - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION \ - AD CondExp##Name( \ - const AD &left , \ - const AD &right , \ - const AD &if_true , \ - const AD &if_false ) \ - { \ - return CondExpOp(Compare##Name, \ - left, right, if_true, if_false); \ - } - -// AD -CPPAD_COND_EXP(Lt) -CPPAD_COND_EXP(Le) -CPPAD_COND_EXP(Eq) -CPPAD_COND_EXP(Ge) -CPPAD_COND_EXP(Gt) -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -AD CondExp( - const AD &flag , - const AD &if_true , - const AD &if_false ) -{ - return CondExpOp(CompareGt, flag, AD(0), if_true, if_false); -} - -# undef CPPAD_COND_EXP -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/convert.hpp b/external/cppad/include/cppad/core/convert.hpp deleted file mode 100644 index 388781152..000000000 --- a/external/cppad/include/cppad/core/convert.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_CONVERT_HPP -# define CPPAD_CORE_CONVERT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Convert$$ -$spell -$$ - - -$section Conversion and I/O of AD Objects$$ -$mindex convert from$$ - -$children% - cppad/core/value.hpp% - cppad/core/integer.hpp% - cppad/core/ad_to_string.hpp% - cppad/core/ad_io.hpp% - cppad/core/print_for.hpp% - cppad/core/var2par.hpp -%$$ -$table -$rref Value$$ -$rref Integer$$ -$rref ad_output$$ -$rref PrintFor$$ -$rref Var2Par$$ -$tend - - -$end -*/ - -# include -# include -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/cppad_assert.hpp b/external/cppad/include/cppad/core/cppad_assert.hpp deleted file mode 100644 index 76ac9801b..000000000 --- a/external/cppad/include/cppad/core/cppad_assert.hpp +++ /dev/null @@ -1,205 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_CPPAD_ASSERT_HPP -# define CPPAD_CORE_CPPAD_ASSERT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/*! -\file cppad_assert.hpp -Define the CppAD error checking macros (all of which begin with CPPAD_ASSERT_) -*/ - -/* -------------------------------------------------------------------------------- -$begin cppad_assert$$ -$spell - CppAD - exp - const - bool -$$ - - -$section CppAD Assertions During Execution$$ -$mindex assert macro CPPAD_ASSERT_KNOWN CPPAD_ASSERT_UNKNOWN$$ - -$head Syntax$$ -$codei%CPPAD_ASSERT_KNOWN(%exp%, %msg%) -%$$ -$codei%CPPAD_ASSERT_UNKNOWN(%exp%)%$$ - - -$head Purpose$$ -These CppAD macros are used to detect and report errors. -They are documented here because they correspond to the C++ -source code that the error is reported at. - -$head NDEBUG$$ -If the preprocessor symbol -$cref/NDEBUG/Faq/Speed/NDEBUG/$$ is defined, -these macros do nothing; i.e., they are optimized out. - -$head Restriction$$ -The CppAD user should not uses these macros. -You can however write your own macros that do not begin with $code CPPAD$$ -and that call the $cref/CppAD error handler/ErrorHandler/$$. - -$head Known$$ -The $code CPPAD_ASSERT_KNOWN$$ macro is used to check for an error -with a known cause. -For example, many CppAD routines uses these macros -to make sure their arguments conform to their specifications. - -$head Unknown$$ -The $code CPPAD_ASSERT_UNKNOWN$$ macro is used to check that the -CppAD internal data structures conform as expected. -If this is not the case, CppAD does not know why the error has -occurred; for example, the user may have written past the end -of an allocated array. - -$head Exp$$ -The argument $icode exp$$ is a C++ source code expression -that results in a $code bool$$ value that should be true. -If it is false, an error has occurred. -This expression may be execute any number of times -(including zero times) so it must have not side effects. - -$head Msg$$ -The argument $icode msg$$ has prototype -$codei% - const char *%msg% -%$$ -and contains a $code '\0'$$ terminated character string. -This string is a description of the error -corresponding to $icode exp$$ being false. - -$head Error Handler$$ -These macros use the -$cref/CppAD error handler/ErrorHandler/$$ to report errors. -This error handler can be replaced by the user. - -$end ------------------------------------------------------------------------------- -*/ - -# include -# include -# include - -/*! -\def CPPAD_ASSERT_KNOWN(exp, msg) -Check that \a exp is true, if not print \a msg and terminate execution. - -The C++ expression \a exp is expected to be true. -If it is false, -the CppAD use has made an error that is described by \a msg. -If the preprocessor symbol \a NDEBUG is not defined, -and \a exp is false, -this macro will report the source code line number at -which this expected result occurred. -In addition, it will print the specified error message \a msg. -*/ -# ifdef NDEBUG -# define CPPAD_ASSERT_KNOWN(exp, msg) // do nothing -# else -# define CPPAD_ASSERT_KNOWN(exp, msg) \ -{ if( ! ( exp ) ) \ - CppAD::ErrorHandler::Call( \ - true , \ - __LINE__ , \ - __FILE__ , \ - #exp , \ - msg ); \ -} -# endif - -/*! -\def CPPAD_ASSERT_UNKNOWN(exp) -Check that \a exp is true, if not terminate execution. - -The C++ expression \a exp is expected to be true. -If it is false, -CppAD has detected an error but does not know the cause of the error. -If the preprocessor symbol \a NDEBUG is not defined, -and \a exp is false, -this macro will report the source code line number at -which this expected result occurred. -*/ -# ifdef NDEBUG -# define CPPAD_ASSERT_UNKNOWN(exp) // do nothing -# else -# define CPPAD_ASSERT_UNKNOWN(exp) \ -{ if( ! ( exp ) ) \ - CppAD::ErrorHandler::Call( \ - false , \ - __LINE__ , \ - __FILE__ , \ - #exp , \ - "" ); \ -} -# endif - -/*! -\def CPPAD_ASSERT_NARG_NRES(op, n_arg, n_res) -Check that operator \a op has the specified number of of arguments and results. - -If \a NDEBUG is not defined and either the number of arguments -or the number of results are not as expected, -execution is terminated and the source code line number is reported. -*/ -# define CPPAD_ASSERT_NARG_NRES(op, n_arg, n_res) \ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == n_arg ) \ - CPPAD_ASSERT_UNKNOWN( NumRes(op) == n_res ) - -/*! -\def CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -Check that the first call to a routine is not during parallel execution mode. - -If \c NDEBUG is defined, this macro has no effect -(not even the definition of (\c assert_first_call). -Otherwise, the variable -\code - static bool assert_first_call -\endcode -is defined and if the first call is executed in parallel mode, -execution is terminated and the source code line number is reported. -*/ -# ifdef NDEBUG -# define CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# else -# define CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL \ - static bool assert_first_call = true; \ - if( assert_first_call ) \ - { CPPAD_ASSERT_KNOWN( \ - ! (CppAD::thread_alloc::in_parallel() ), \ - "In parallel mode and parallel_setup has not been called." \ - ); \ - assert_first_call = false; \ - } -# endif - -/*! -\def CPPAD_ASSERT_ARG_BEFORE_RESULT -Check that operator arguments come before result. - -If \c NDEBUG is defined, this macro has no effect, -otherwise it calls the function assert_arg_before_result. -*/ -# ifdef NDEBUG -# define CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, result) -# else -# define CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, result) \ - assert_arg_before_result(op, arg, result) - -# endif - -# endif diff --git a/external/cppad/include/cppad/core/define.hpp b/external/cppad/include/cppad/core/define.hpp deleted file mode 100644 index faba1c611..000000000 --- a/external/cppad/include/cppad/core/define.hpp +++ /dev/null @@ -1,325 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_DEFINE_HPP -# define CPPAD_CORE_DEFINE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/*! -\file define.hpp -Define processor symbols and macros that are used by CppAD. -*/ - -// ---------------------------------------------------------------------------- -/*! -\def CPPAD_OP_CODE_TYPE -Is the type used to store enum OpCode values. If not the same as OpCode, then -sizeof(CPPAD_OP_CODE_TYPE) <= sizeof( enum OpCode ) -to conserve memory. -This type must support \c std::numeric_limits, -the \c <= operator, -and conversion to \c size_t. -Make sure that the type chosen returns true for is_pod -in pod_vector.hpp. -*/ -# define CPPAD_OP_CODE_TYPE unsigned char - - -// ---------------------------------------------------------------------------- -/*! -\def CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -A version of the inline command that works with MC compiler. - -Microsoft Visual C++ version 9.0 generates a warning if a template -function is declared as a friend -(this was not a problem for version 7.0). -The warning identifier is -\verbatim - warning C4396 -\endverbatim -and it contains the text -\verbatim - the inline specifier cannot be used when a friend declaration refers - to a specialization of a function template -\endverbatim -This happens even if the function is not a specialization. -This macro is defined as empty for Microsoft compilers. -*/ -# ifdef _MSC_VER -# define CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -# else -# define CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION inline -# endif - -// ---------------------------------------------------------------------------- -/*! -\def CPPAD_LIB_EXPORT -Special macro for exporting windows DLL symbols; see -https://cmake.org/Wiki/BuildingWinDLL -*/ -# ifdef _MSC_VER -# ifdef cppad_lib_EXPORTS -# define CPPAD_LIB_EXPORT __declspec(dllexport) -# else -# define CPPAD_LIB_EXPORT __declspec(dllimport) -# endif // cppad_lib_EXPORTS -# else // _MSC_VER -# define CPPAD_LIB_EXPORT -# endif - - -// ============================================================================ -/*! -\def CPPAD_FOLD_ASSIGNMENT_OPERATOR(Op) -Declares automatic coercion for certain AD assignment operations. - -This macro assumes that the operator -\verbatim - left Op right -\endverbatim -is defined for the case where left and right have type AD. -It uses this case to define the cases where -left has type AD and right has type -VecAD_reference, -Base, or -double. -The argument right is const and call by reference. -This macro converts the operands to AD and then -uses the definition of the same operation for that case. -*/ - -# define CPPAD_FOLD_ASSIGNMENT_OPERATOR(Op) \ -/* ----------------------------------------------------------------*/ \ -template \ -inline AD& operator Op \ -(AD &left, double right) \ -{ return left Op AD(right); } \ - \ -template \ -inline AD& operator Op \ -(AD &left, const Base &right) \ -{ return left Op AD(right); } \ - \ -inline AD& operator Op \ -(AD &left, const double &right) \ -{ return left Op AD(right); } \ - \ -template \ -inline AD& operator Op \ -(AD &left, const VecAD_reference &right) \ -{ return left Op right.ADBase(); } - -// ===================================================================== -/*! -\def CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(Op) -Declares automatic coercion for certain binary operations with AD result. - -This macro assumes that the operator -\verbatim - left Op right -\endverbatim -is defined for the case where left and right -and the result of the operation all -have type AD. -It uses this case to define the cases either left -or right has type VecAD_reference or AD -and the type of the other operand is one of the following: -VecAD_reference, AD, Base, double. -All of the arguments are const and call by reference. -This macro converts the operands to AD and then -uses the definition of the same operation for that case. -*/ -# define CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(Op) \ -/* ----------------------------------------------------------------*/ \ -/* Operations with VecAD_reference and AD only*/ \ - \ -template \ -inline AD operator Op \ -(const AD &left, const VecAD_reference &right) \ -{ return left Op right.ADBase(); } \ - \ -template \ -inline AD operator Op \ -(const VecAD_reference &left, const VecAD_reference &right)\ -{ return left.ADBase() Op right.ADBase(); } \ - \ -template \ -inline AD operator Op \ - (const VecAD_reference &left, const AD &right) \ -{ return left.ADBase() Op right; } \ -/* ----------------------------------------------------------------*/ \ -/* Operations Base */ \ - \ -template \ -inline AD operator Op \ - (const Base &left, const AD &right) \ -{ return AD(left) Op right; } \ - \ -template \ -inline AD operator Op \ - (const Base &left, const VecAD_reference &right) \ -{ return AD(left) Op right.ADBase(); } \ - \ -template \ -inline AD operator Op \ - (const AD &left, const Base &right) \ -{ return left Op AD(right); } \ - \ -template \ -inline AD operator Op \ - (const VecAD_reference &left, const Base &right) \ -{ return left.ADBase() Op AD(right); } \ - \ -/* ----------------------------------------------------------------*/ \ -/* Operations double */ \ - \ -template \ -inline AD operator Op \ - (const double &left, const AD &right) \ -{ return AD(left) Op right; } \ - \ -template \ -inline AD operator Op \ - (const double &left, const VecAD_reference &right) \ -{ return AD(left) Op right.ADBase(); } \ - \ -template \ -inline AD operator Op \ - (const AD &left, const double &right) \ -{ return left Op AD(right); } \ - \ -template \ -inline AD operator Op \ - (const VecAD_reference &left, const double &right) \ -{ return left.ADBase() Op AD(right); } \ -/* ----------------------------------------------------------------*/ \ -/* Special case to avoid ambuigity when Base is double */ \ - \ -inline AD operator Op \ - (const double &left, const AD &right) \ -{ return AD(left) Op right; } \ - \ -inline AD operator Op \ - (const double &left, const VecAD_reference &right) \ -{ return AD(left) Op right.ADBase(); } \ - \ -inline AD operator Op \ - (const AD &left, const double &right) \ -{ return left Op AD(right); } \ - \ -inline AD operator Op \ - (const VecAD_reference &left, const double &right) \ -{ return left.ADBase() Op AD(right); } - -// ======================================================================= - -/*! -\def CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(Op) -Declares automatic coercion for certain binary operations with bool result. - -This macro assumes that the operator -\verbatim - left Op right -\endverbatim -is defined for the case where left and right -have type AD and the result has type bool. -It uses this case to define the cases either left -or right has type -VecAD_reference or AD -and the type of the other operand is one of the following: -VecAD_reference, AD, Base, double. -All of the arguments are const and call by reference. -This macro converts the operands to AD and then -uses the definition of the same operation for that case. -*/ -# define CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(Op) \ -/* ----------------------------------------------------------------*/ \ -/* Operations with VecAD_reference and AD only*/ \ - \ -template \ -inline bool operator Op \ -(const AD &left, const VecAD_reference &right) \ -{ return left Op right.ADBase(); } \ - \ -template \ -inline bool operator Op \ -(const VecAD_reference &left, const VecAD_reference &right)\ -{ return left.ADBase() Op right.ADBase(); } \ - \ -template \ -inline bool operator Op \ - (const VecAD_reference &left, const AD &right) \ -{ return left.ADBase() Op right; } \ -/* ----------------------------------------------------------------*/ \ -/* Operations Base */ \ - \ -template \ -inline bool operator Op \ - (const Base &left, const AD &right) \ -{ return AD(left) Op right; } \ - \ -template \ -inline bool operator Op \ - (const Base &left, const VecAD_reference &right) \ -{ return AD(left) Op right.ADBase(); } \ - \ -template \ -inline bool operator Op \ - (const AD &left, const Base &right) \ -{ return left Op AD(right); } \ - \ -template \ -inline bool operator Op \ - (const VecAD_reference &left, const Base &right) \ -{ return left.ADBase() Op AD(right); } \ - \ -/* ----------------------------------------------------------------*/ \ -/* Operations double */ \ - \ -template \ -inline bool operator Op \ - (const double &left, const AD &right) \ -{ return AD(left) Op right; } \ - \ -template \ -inline bool operator Op \ - (const double &left, const VecAD_reference &right) \ -{ return AD(left) Op right.ADBase(); } \ - \ -template \ -inline bool operator Op \ - (const AD &left, const double &right) \ -{ return left Op AD(right); } \ - \ -template \ -inline bool operator Op \ - (const VecAD_reference &left, const double &right) \ -{ return left.ADBase() Op AD(right); } \ -/* ----------------------------------------------------------------*/ \ -/* Special case to avoid ambuigity when Base is double */ \ - \ -inline bool operator Op \ - (const double &left, const AD &right) \ -{ return AD(left) Op right; } \ - \ -inline bool operator Op \ - (const double &left, const VecAD_reference &right) \ -{ return AD(left) Op right.ADBase(); } \ - \ -inline bool operator Op \ - (const AD &left, const double &right) \ -{ return left Op AD(right); } \ - \ -inline bool operator Op \ - (const VecAD_reference &left, const double &right) \ -{ return left.ADBase() Op AD(right); } - -# endif diff --git a/external/cppad/include/cppad/core/dependent.hpp b/external/cppad/include/cppad/core/dependent.hpp deleted file mode 100644 index a6f6775b1..000000000 --- a/external/cppad/include/cppad/core/dependent.hpp +++ /dev/null @@ -1,332 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_DEPENDENT_HPP -# define CPPAD_CORE_DEPENDENT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin Dependent$$ -$spell - alloc - num - taylor_ - ADvector - const -$$ - -$spell -$$ - -$section Stop Recording and Store Operation Sequence$$ -$mindex ADFun tape Dependent$$ - - -$head Syntax$$ -$icode%f%.Dependent(%x%, %y%)%$$ - -$head Purpose$$ -Stop recording and the AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$ -that started with the call -$codei% - Independent(%x%) -%$$ -and store the operation sequence in $icode f$$. -The operation sequence defines an -$cref/AD function/glossary/AD Function/$$ -$latex \[ - F : B^n \rightarrow B^m -\] $$ -where $latex B$$ is the space corresponding to objects of type $icode Base$$. -The value $latex n$$ is the dimension of the -$cref/domain/seq_property/Domain/$$ space for the operation sequence. -The value $latex m$$ is the dimension of the -$cref/range/seq_property/Range/$$ space for the operation sequence -(which is determined by the size of $icode y$$). - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -The AD of $icode Base$$ operation sequence is stored in $icode f$$; i.e., -it becomes the operation sequence corresponding to $icode f$$. -If a previous operation sequence was stored in $icode f$$, -it is deleted. - -$head x$$ -The argument $icode x$$ -must be the vector argument in a previous call to -$cref Independent$$. -Neither its size, or any of its values, are allowed to change -between calling -$codei% - Independent(%x%) -%$$ -and -$codei% - %f%.Dependent(%x%, %y%) -%$$. - -$head y$$ -The vector $icode y$$ has prototype -$codei% - const %ADvector% &%y% -%$$ -(see $cref/ADvector/FunConstruct/$$ below). -The length of $icode y$$ must be greater than zero -and is the dimension of the range space for $icode f$$. - -$head ADvector$$ -The type $icode ADvector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$codei%AD<%Base%>%$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Taping$$ -The tape, -that was created when $codei%Independent(%x%)%$$ was called, -will stop recording. -The AD operation sequence will be transferred from -the tape to the object $icode f$$ and the tape will then be deleted. - -$head Forward$$ -No $cref Forward$$ calculation is preformed during this operation. -Thus, directly after this operation, -$codei% - %f%.size_order() -%$$ -is zero (see $cref size_order$$). - -$head Parallel Mode$$ -The call to $code Independent$$, -and the corresponding call to -$codei% - ADFun<%Base%> %f%( %x%, %y%) -%$$ -or -$codei% - %f%.Dependent( %x%, %y%) -%$$ -or $cref abort_recording$$, -must be preformed by the same thread; i.e., -$cref/thread_alloc::thread_num/ta_thread_num/$$ must be the same. - -$head Example$$ -The file -$cref fun_check.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ----------------------------------------------------------------------------- -*/ - - -// BEGIN CppAD namespace -namespace CppAD { - -/*! -\file dependent.hpp -Different versions of Dependent function. -*/ - -/*! -Determine the \c tape corresponding to this exeuction thread and then use -Dependent(tape, y) to store this tapes recording in a function. - -\param y [in] -The dependent variable vector for the corresponding function. -*/ -template -template -void ADFun::Dependent(const ADvector &y) -{ local::ADTape* tape = AD::tape_ptr(); - CPPAD_ASSERT_KNOWN( - tape != CPPAD_NULL, - "Can't store current operation sequence in this ADFun object" - "\nbecause there is no active tape (for this thread)." - ); - - // code above just determines the tape and checks for errors - Dependent(tape, y); -} - - -/*! -Determine the \c tape corresponding to this exeuction thread and then use -Dependent(tape, y) to store this tapes recording in a function. - -\param x [in] -The independent variable vector for this tape. This informaiton is -also stored in the tape so a check is done to make sure it is correct -(if NDEBUG is not defined). - -\param y [in] -The dependent variable vector for the corresponding function. -*/ -template -template -void ADFun::Dependent(const ADvector &x, const ADvector &y) -{ - CPPAD_ASSERT_KNOWN( - x.size() > 0, - "Dependent: independent variable vector has size zero." - ); - CPPAD_ASSERT_KNOWN( - Variable(x[0]), - "Dependent: independent variable vector has been changed." - ); - local::ADTape *tape = AD::tape_ptr(x[0].tape_id_); - CPPAD_ASSERT_KNOWN( - tape->size_independent_ == size_t( x.size() ), - "Dependent: independent variable vector has been changed." - ); -# ifndef NDEBUG - size_t i, j; - for(j = 0; j < size_t(x.size()); j++) - { CPPAD_ASSERT_KNOWN( - size_t(x[j].taddr_) == (j+1), - "ADFun: independent variable vector has been changed." - ); - CPPAD_ASSERT_KNOWN( - x[j].tape_id_ == x[0].tape_id_, - "ADFun: independent variable vector has been changed." - ); - } - for(i = 0; i < size_t(y.size()); i++) - { CPPAD_ASSERT_KNOWN( - CppAD::Parameter( y[i] ) | (y[i].tape_id_ == x[0].tape_id_) , - "ADFun: dependent vector contains a variable for" - "\na different tape (thread) than the independent variables." - ); - } -# endif - - // code above just determines the tape and checks for errors - Dependent(tape, y); -} - -/*! -Replace the floationg point operations sequence for this function object. - -\param tape -is a tape that contains the new floating point operation sequence -for this function. -After this operation, all memory allocated for this tape is deleted. - -\param y -The dependent variable vector for the function being stored in this object. - -\par -All of the private member data in ad_fun.hpp is set to correspond to the -new tape except for check_for_nan_. -*/ - -template -template -void ADFun::Dependent(local::ADTape *tape, const ADvector &y) -{ - size_t m = y.size(); - size_t n = tape->size_independent_; - size_t i, j; - size_t y_taddr; - - // check ADvector is Simple Vector class with AD elements - CheckSimpleVector< AD, ADvector>(); - - CPPAD_ASSERT_KNOWN( - y.size() > 0, - "ADFun operation sequence dependent variable size is zero size" - ); - // --------------------------------------------------------------------- - // Begin setting ad_fun.hpp private member data - // --------------------------------------------------------------------- - // dep_parameter_, dep_taddr_ - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::ParOp) == 1 ); - dep_parameter_.resize(m); - dep_taddr_.resize(m); - for(i = 0; i < m; i++) - { dep_parameter_[i] = CppAD::Parameter(y[i]); - if( dep_parameter_[i] ) - { // make a tape copy of dependent variables that are parameters, - y_taddr = tape->RecordParOp( y[i].value_ ); - } - else y_taddr = y[i].taddr_; - - CPPAD_ASSERT_UNKNOWN( y_taddr > 0 ); - dep_taddr_[i] = y_taddr; - } - - // put an EndOp at the end of the tape - tape->Rec_.PutOp(local::EndOp); - - // some size_t values in ad_fun.hpp - has_been_optimized_ = false; - compare_change_count_ = 1; - compare_change_number_ = 0; - compare_change_op_index_ = 0; - num_order_taylor_ = 0; - num_direction_taylor_ = 0; - cap_order_taylor_ = 0; - - // num_var_tape_ - // Now that all the variables are in the tape, we can set this value. - num_var_tape_ = tape->Rec_.num_var_rec(); - - // taylor_ - taylor_.erase(); - - // cskip_op_ - cskip_op_.erase(); - cskip_op_.extend( tape->Rec_.num_op_rec() ); - - // load_op_ - load_op_.erase(); - load_op_.extend( tape->Rec_.num_load_op_rec() ); - - // play_ - // Now that each dependent variable has a place in the tape, - // and there is a EndOp at the end of the tape, we can transfer the - // recording to the player and and erase the tape. - play_.get(tape->Rec_); - - // ind_taddr_ - // Note that play_ has been set, we can use it to check operators - ind_taddr_.resize(n); - CPPAD_ASSERT_UNKNOWN( n < num_var_tape_); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( play_.GetOp(j+1) == local::InvOp ); - ind_taddr_[j] = j+1; - } - - // for_jac_sparse_pack_, for_jac_sparse_set_ - for_jac_sparse_pack_.resize(0, 0); - for_jac_sparse_set_.resize(0,0); - // --------------------------------------------------------------------- - // End set ad_fun.hpp private member data - // --------------------------------------------------------------------- - - // now we can delete the tape - AD::tape_manage(tape_manage_delete); - - // total number of varables in this recording - CPPAD_ASSERT_UNKNOWN( num_var_tape_ == play_.num_var_rec() ); - - // used to determine if there is an operation sequence in *this - CPPAD_ASSERT_UNKNOWN( num_var_tape_ > 0 ); - -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/discrete.hpp b/external/cppad/include/cppad/core/discrete.hpp deleted file mode 100644 index 89b3ba0e0..000000000 --- a/external/cppad/include/cppad/core/discrete.hpp +++ /dev/null @@ -1,306 +0,0 @@ -# ifndef CPPAD_CORE_DISCRETE_HPP -# define CPPAD_CORE_DISCRETE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Discrete$$ -$spell - retaping - namespace - std - Eq - Cpp - const - inline - Geq -$$ - -$section Discrete AD Functions$$ -$mindex CPPAD_DISCRETE_FUNCTION$$ - - -$head Syntax$$ -$codei%CPPAD_DISCRETE_FUNCTION(%Base%, %name%) -%$$ -$icode%y% = %name%(%x%) -%$$ -$icode%ay% = %name%(%ax%) -%$$ - - -$head Purpose$$ -Record the evaluation of a discrete function as part -of an $codei%AD<%Base%>%$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. -The value of a discrete function can depend on the -$cref/independent variables/glossary/Tape/Independent Variable/$$, -but its derivative is identically zero. -For example, suppose that the integer part of -a $cref/variable/glossary/Variable/$$ $icode x$$ is the -index into an array of values. - -$head Base$$ -This is the -$cref/base type/base_require/$$ -corresponding to the operations sequence; -i.e., use of the $icode name$$ with arguments of type -$codei%AD<%Base%>%$$ can be recorded in an operation sequence. - -$head name$$ -This is the name of the function (as it is used in the source code). -The user must provide a version of $icode name$$ -where the argument has type $icode Base$$. -CppAD uses this to create a version of $icode name$$ -where the argument has type $codei%AD<%Base%>%$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Base%& %x% -%$$ -It is the value at which the user provided version of $icode name$$ -is to be evaluated. - -$head y$$ -The result $icode y$$ has prototype -$codei% - %Base% %y% -%$$ -It is the return value for the user provided version of $icode name$$. - -$head ax$$ -The argument $icode ax$$ has prototype -$codei% - const AD<%Base%>& %ax% -%$$ -It is the value at which the CppAD provided version of $icode name$$ -is to be evaluated. - -$head ay$$ -The result $icode ay$$ has prototype -$codei% - AD<%Base%> %ay% -%$$ -It is the return value for the CppAD provided version of $icode name$$. - - -$head Create AD Version$$ -The preprocessor macro invocation -$codei% - CPPAD_DISCRETE_FUNCTION(%Base%, %name%) -%$$ -defines the $codei%AD<%Base%>%$$ version of $icode name$$. -This can be with in a namespace (not the $code CppAD$$ namespace) -but must be outside of any routine. - -$head Operation Sequence$$ -This is an AD of $icode Base$$ -$cref/atomic operation/glossary/Operation/Atomic/$$ -and hence is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Derivatives$$ -During a zero order $cref Forward$$ operation, -an $cref ADFun$$ object will compute the value of $icode name$$ -using the user provided $icode Base$$ version of this routine. -All the derivatives of $icode name$$ will be evaluated as zero. - -$head Parallel Mode$$ -The first call to -$codei% - %ay% = %name%(%ax%) -%$$ -must not be in $cref/parallel/ta_in_parallel/$$ execution mode. - - -$head Example$$ -$children% - example/general/tape_index.cpp% - example/general/interp_onetape.cpp% - example/general/interp_retape.cpp -%$$ -The file -$cref tape_index.cpp$$ -contains an example and test that uses a discrete function -to vary an array index during $cref Forward$$ mode calculations. -The file -$cref interp_onetape.cpp$$ -contains an example and test that uses discrete -functions to avoid retaping a calculation that requires interpolation. -(The file -$cref interp_retape.cpp$$ -shows how interpolation can be done with retaping.) - -$head CppADCreateDiscrete Deprecated 2007-07-28$$ -The preprocessor symbol $code CppADCreateDiscrete$$ -is defined to be the same as $code CPPAD_DISCRETE_FUNCTION$$ -but its use is deprecated. - -$end ------------------------------------------------------------------------------- -*/ -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file discrete.hpp -user define discrete functions -*/ - -/*! -\def CPPAD_DISCRETE_FUNCTION(Base, name) -Defines the function name(ax, ay) -where \c ax and \c ay are vectors with AD elements. - -\par Base -is the base type for the discrete function. - -\par name -is the name of the user defined function that corresponding to this operation. -*/ - -# define CPPAD_DISCRETE_FUNCTION(Base, name) \ -inline CppAD::AD name (const CppAD::AD& ax) \ -{ \ - static CppAD::discrete fun(#name, name); \ - \ - return fun.ad(ax); \ -} -# define CppADCreateDiscrete CPPAD_DISCRETE_FUNCTION - - -/* -Class that acutally implemnets the ay = name(ax) call. - -A new discrete function is generated for ech time the user invokes -the CPPAD_DISCRETE_FUNCTION macro; see static object in that macro. -*/ -template -class discrete { - /// parallel_ad needs to call List to initialize static - template - friend void parallel_ad(void); - - /// type for the user routine that computes function values - typedef Base (*F) (const Base& x); -private: - /// name of this user defined function - const std::string name_; - /// user's implementation of the function for Base operations - const F f_; - /// index of this objec in the vector of all objects for this class - const size_t index_; - - /*! - List of all objects in this class. - - If we use CppAD::vector for this vector, it will appear that - there is a memory leak because this list is not distroyed before - thread_alloc::free_available(thread) is called by the testing routines. - */ - static std::vector& List(void) - { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static std::vector list; - return list; - } -public: - /*! - Constructor called for each invocation of CPPAD_DISCRETE_FUNCTION. - - Put this object in the list of all objects for this class and set - the constant private data name_, f_, and index_. - - \param Name - is the user's name for this discrete function. - - \param f - user routine that implements this function for \c Base class. - - \par - This constructor can ont be used in parallel mode because it changes - the static object \c List. - */ - discrete(const char* Name, F f) : - name_(Name) - , f_(f) - , index_( List().size() ) - { - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "discrete: First call the function *Name is in parallel mode." - ); - List().push_back(this); - } - - /*! - Implement the user call to ay = name(ax). - - \param ax - is the argument for this call. - - \return - the return value is called \c ay above. - */ - AD ad(const AD &ax) const - { AD ay; - - ay.value_ = f_(ax.value_); - if( Variable(ax) ) - { local::ADTape *tape = ax.tape_this(); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DisOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DisOp) == 2 ); - - // put operand addresses in the tape - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= index_, - "discrete: cppad_tape_addr_type maximum not large enough" - ); - tape->Rec_.PutArg(addr_t(index_), ax.taddr_); - // put operator in the tape - ay.taddr_ = tape->Rec_.PutOp(local::DisOp); - // make result a variable - ay.tape_id_ = tape->id_; - - CPPAD_ASSERT_UNKNOWN( Variable(ay) ); - } - return ay; - } - - /// Name corresponding to a discrete object - static const char* name(size_t index) - { return List()[index]->name_.c_str(); } - - /*! - Link from forward mode sweep to users routine - - \param index - index for this function in the list of all discrete object - - \param x - argument value at which to evaluate this function - */ - static Base eval(size_t index, const Base& x) - { - CPPAD_ASSERT_UNKNOWN(index < List().size() ); - - return List()[index]->f_(x); - } -}; - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/div.hpp b/external/cppad/include/cppad/core/div.hpp deleted file mode 100644 index 46110425c..000000000 --- a/external/cppad/include/cppad/core/div.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_DIV_HPP -# define CPPAD_CORE_DIV_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD operator / (const AD &left , const AD &right) -{ - // compute the Base part - AD result; - result.value_ = left.value_ / right.value_; - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return result; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = left.tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // result = variable / variable - CPPAD_ASSERT_KNOWN( - left.tape_id_ == right.tape_id_, - "Dividing AD objects that are" - " variables on different tapes." - ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DivvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DivvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(left.taddr_, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::DivvvOp); - // make result a variable - result.tape_id_ = tape_id; - } - else if( IdenticalOne(right.value_) ) - { // result = variable / 1 - result.make_variable(left.tape_id_, left.taddr_); - } - else - { // result = variable / parameter - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DivvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DivvpOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(left.taddr_, p); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::DivvpOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - else if( var_right ) - { if( IdenticalZero(left.value_) ) - { // result = 0 / variable - } - else - { // result = parameter / variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DivpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DivpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left.value_); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::DivpvOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - return result; -} - -// convert other cases into the case above -CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(/) - - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/div_eq.hpp b/external/cppad/include/cppad/core/div_eq.hpp deleted file mode 100644 index 1ec73f9ef..000000000 --- a/external/cppad/include/cppad/core/div_eq.hpp +++ /dev/null @@ -1,93 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_DIV_EQ_HPP -# define CPPAD_CORE_DIV_EQ_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD& AD::operator /= (const AD &right) -{ - // compute the Base part - Base left; - left = value_; - value_ /= right.value_; - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return *this; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // this = variable / variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DivvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DivvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(taddr_, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::DivvvOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - else if( IdenticalOne( right.value_ ) ) - { // this = variable * 1 - } - else - { // this = variable / parameter - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DivvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DivvpOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(taddr_, p); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::DivvpOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - } - else if( var_right ) - { if( IdenticalZero(left) ) - { // this = 0 / variable - } - else - { // this = parameter / variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::DivpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::DivpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::DivpvOp); - // make this a variable - tape_id_ = tape_id; - } - } - return *this; -} - -CPPAD_FOLD_ASSIGNMENT_OPERATOR(/=) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/drivers.hpp b/external/cppad/include/cppad/core/drivers.hpp deleted file mode 100644 index aaec12879..000000000 --- a/external/cppad/include/cppad/core/drivers.hpp +++ /dev/null @@ -1,22 +0,0 @@ -# ifndef CPPAD_CORE_DRIVERS_HPP -# define CPPAD_CORE_DRIVERS_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/epsilon.hpp b/external/cppad/include/cppad/core/epsilon.hpp deleted file mode 100644 index 68c46d64b..000000000 --- a/external/cppad/include/cppad/core/epsilon.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_EPSILON_HPP -# define CPPAD_CORE_EPSILON_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- -$begin epsilon$$ -$spell - std - eps - CppAD - namespace - const -$$ - -$section Machine Epsilon For AD Types$$ - -$head Deprecated 2012-06-17$$ -This routine has been deprecated. -You should use the $cref numeric_limits$$ $code epsilon$$ instead. - -$head Syntax$$ -$icode%eps% = epsilon<%Float%>()%$$ - -$head Purpose$$ -Obtain the value of machine epsilon corresponding -to the type $icode%Float%$$. - -$head Float$$ -this type can either be $codei%AD<%Base%>%$$, -or it can be $icode Base$$ for any $codei%AD<%Base%>%$$ type. - -$head eps$$ -The result $icode eps$$ has prototype -$codei% - %Float% eps -%$$ - -$end ------------------------------------------------------------------------------- -*/ - -namespace CppAD { - - template - inline Type epsilon(void) - { return Type ( numeric_limits::epsilon() ); } - -} -# endif diff --git a/external/cppad/include/cppad/core/equal_op_seq.hpp b/external/cppad/include/cppad/core/equal_op_seq.hpp deleted file mode 100644 index a336b50d9..000000000 --- a/external/cppad/include/cppad/core/equal_op_seq.hpp +++ /dev/null @@ -1,119 +0,0 @@ -# ifndef CPPAD_CORE_EQUAL_OP_SEQ_HPP -# define CPPAD_CORE_EQUAL_OP_SEQ_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- -$begin EqualOpSeq$$ -$spell - Op - const - bool -$$ - - -$section Check if Two Value are Identically Equal$$ -$mindex EqualOpSeq operation sequence$$ - -$head Syntax$$ -$icode%b% = EqualOpSeq(%x%, %y%)%$$ - -$head Purpose$$ -Determine if two $icode x$$ and $icode y$$ are identically equal; i.e., -not only is $icode%x% == %y%$$ true, but -if they are $cref/variables/glossary/Variable/$$, -they correspond have the same -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Motivation$$ -Sometimes it is useful to cache information -and only recalculate when a function's arguments change. -In the case of AD variables, -it may be important not only when the argument values are equal, -but when they are related to the -$cref/independent variables/glossary/Tape/Independent Variable/$$ -by the same operation sequence. -After the assignment -$codei% - %y% = %x% -%$$ -these two AD objects would not only have equal values, -but would also correspond to the same operation sequence. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &%x% -%$$ - -$head y$$ -The argument $icode y$$ has prototype -$codei% - const AD<%Base%> &%y% -%$$ - -$head b$$ -The result $icode b$$ has prototype -$codei% - bool %b% -%$$ -The result is true if and only if one of the following cases holds: - -$list number$$ -Both $icode x$$ and $icode y$$ are variables -and correspond to the same operation sequence. -$lnext -Both $icode x$$ and $icode y$$ are parameters, -$icode Base$$ is an AD type, -and $codei%EqualOpSeq( Value(%x%) , Value(%y%) )%$$ is true. -$lnext -Both $icode x$$ and $icode y$$ are parameters, -$icode Base$$ is not an AD type, -and $icode%x% == %y%%$$ is true. -$lend - - -$head Example$$ -$children% - example/general/equal_op_seq.cpp -%$$ -The file -$cref equal_op_seq.cpp$$ -contains an example and test of $code EqualOpSeq$$. -It returns true if it succeeds and false otherwise. - - -$end ------------------------------------------------------------------------------- -*/ - - -namespace CppAD { - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - bool EqualOpSeq(const AD &x, const AD &y) - { - if( Parameter(x) ) - { if( Parameter(y) ) - return EqualOpSeq(x.value_, y.value_); - else return false; - } - else if( Parameter(y) ) - return false; - - return (x.taddr_ == y.taddr_); - } - -} - -# endif diff --git a/external/cppad/include/cppad/core/erf.hpp b/external/cppad/include/cppad/core/erf.hpp deleted file mode 100644 index f975d1ef0..000000000 --- a/external/cppad/include/cppad/core/erf.hpp +++ /dev/null @@ -1,106 +0,0 @@ -# ifndef CPPAD_CORE_ERF_HPP -# define CPPAD_CORE_ERF_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin erf$$ -$spell - erf - const - Vec - std - cmath - CppAD - Vedder -$$ -$section The Error Function$$ - -$head Syntax$$ -$icode%y% = erf(%x%)%$$ - -$head Description$$ -Returns the value of the error function which is defined by -$latex \[ -{\rm erf} (x) = \frac{2}{ \sqrt{\pi} } \int_0^x \exp( - t * t ) \; {\bf d} t -\] $$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head CPPAD_USE_CPLUSPLUS_2011$$ - -$subhead true$$ -If this preprocessor symbol is true ($code 1$$), -and $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$subhead false$$ -If this preprocessor symbol is false ($code 0$$), -CppAD uses a fast approximation (few numerical operations) -with relative error bound $latex 4 \times 10^{-4}$$; see -Vedder, J.D., -$icode Simple approximations for the error function and its inverse$$, -American Journal of Physics, -v 55, -n 8, -1987, -p 762-3. - -$head Example$$ -$children% - example/general/erf.cpp -%$$ -The file -$cref erf.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -# include -# if ! CPPAD_USE_CPLUSPLUS_2011 - -// BEGIN CppAD namespace -namespace CppAD { - -template -Type erf_template(const Type &x) -{ using CppAD::exp; - const Type a = static_cast(993./880.); - const Type b = static_cast(89./880.); - - return tanh( (a + b * x * x) * x ); -} - -inline float erf(const float &x) -{ return erf_template(x); } - -inline double erf(const double &x) -{ return erf_template(x); } - -template -inline AD erf(const AD &x) -{ return erf_template(x); } - -template -inline AD erf(const VecAD_reference &x) -{ return erf_template( x.ADBase() ); } - - -} // END CppAD namespace - -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_ERF_INCLUDED diff --git a/external/cppad/include/cppad/core/expm1.hpp b/external/cppad/include/cppad/core/expm1.hpp deleted file mode 100644 index 81d080ea1..000000000 --- a/external/cppad/include/cppad/core/expm1.hpp +++ /dev/null @@ -1,96 +0,0 @@ -# ifndef CPPAD_CORE_EXPM1_HPP -# define CPPAD_CORE_EXPM1_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin expm1$$ -$spell - exp - expm1 - const - Vec - std - cmath - CppAD -$$ -$section The Exponential Function Minus One: expm1$$ - -$head Syntax$$ -$icode%y% = expm1(%x%)%$$ - -$head Description$$ -Returns the value of the exponential function minus one which is defined -by $icode%y% == exp(%x%) - 1%$$. - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head CPPAD_USE_CPLUSPLUS_2011$$ - -$subhead true$$ -If this preprocessor symbol is true ($code 1$$), -and $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$subhead false$$ -If this preprocessor symbol is false ($code 0$$), -CppAD uses the representation -$latex \[ -\R{expm1} (x) = \exp(x) - 1 -\] $$ -to compute this function. - -$head Example$$ -$children% - example/general/expm1.cpp -%$$ -The file -$cref expm1.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -# include -# if ! CPPAD_USE_CPLUSPLUS_2011 - -// BEGIN CppAD namespace -namespace CppAD { - -template -Type expm1_template(const Type &x) -{ return CppAD::exp(x) - Type(1); -} - -inline float expm1(const float &x) -{ return expm1_template(x); } - -inline double expm1(const double &x) -{ return expm1_template(x); } - -template -inline AD expm1(const AD &x) -{ return expm1_template(x); } - -template -inline AD expm1(const VecAD_reference &x) -{ return expm1_template( x.ADBase() ); } - - -} // END CppAD namespace - -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_EXPM1_INCLUDED diff --git a/external/cppad/include/cppad/core/for_hes_sparsity.hpp b/external/cppad/include/cppad/core/for_hes_sparsity.hpp deleted file mode 100644 index f95ca54aa..000000000 --- a/external/cppad/include/cppad/core/for_hes_sparsity.hpp +++ /dev/null @@ -1,302 +0,0 @@ -# ifndef CPPAD_CORE_FOR_HES_SPARSITY_HPP -# define CPPAD_CORE_FOR_HES_SPARSITY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin for_hes_sparsity$$ -$spell - Andrea Walther - Jacobian - Hessian - jac - hes - bool - const - rc - cpp -$$ - -$section Forward Mode Hessian Sparsity Patterns$$ - -$head Syntax$$ -$icode%f%.for_hes_sparsity( - %select_domain%, %select_range%, %internal_bool%, %pattern_out% -)%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to -the operation sequence stored in $icode f$$. -Fix a diagonal matrix $latex D \in \B{R}^{n \times n}$$, -a vector $latex s \in \B{R}^m$$ and define the function -$latex \[ - H(x) = D ( s^\R{T} F )^{(2)} ( x ) D -\] $$ -Given the sparsity for $latex D$$ and $latex s$$, -$code for_hes_sparsity$$ computes a sparsity pattern for $latex H(x)$$. - -$head x$$ -Note that the sparsity pattern $latex H(x)$$ corresponds to the -operation sequence stored in $icode f$$ and does not depend on -the argument $icode x$$. - -$head BoolVector$$ -The type $icode BoolVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$. - -$head SizeVector$$ -The type $icode SizeVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$head select_domain$$ -The argument $icode diagonal$$ has prototype -$codei% - const %BoolVector%& %select_domain% -%$$ -It has size $latex n$$ and specifies which components of the diagonal of -$latex D$$ are non-zero; i.e., $icode%select_domain%[%j%]%$$ is true -if and only if $latex D_{j,j}$$ is possibly non-zero. - - -$head select_range$$ -The argument $icode select_range$$ has prototype -$codei% - const %BoolVector%& %select_range% -%$$ -It has size $latex m$$ and specifies which components of the vector -$latex s$$ are non-zero; i.e., $icode%select_range%[%i%]%$$ is true -if and only if $latex s_i$$ is possibly non-zero. - -$head internal_bool$$ -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of sets of integers is used. - -$head pattern_out$$ -This argument has prototype -$codei% - sparse_rc<%SizeVector%>& %pattern_out% -%$$ -This input value of $icode pattern_out$$ does not matter. -Upon return $icode pattern_out$$ is a sparsity pattern for $latex H(x)$$. - -$head Sparsity for Entire Hessian$$ -Suppose that $latex R$$ is the $latex n \times n$$ identity matrix. -In this case, $icode pattern_out$$ is a sparsity pattern for -$latex (s^\R{T} F) F^{(2)} ( x )$$. - -$head Algorithm$$ -See Algorithm II in -$italic Computing sparse Hessians with automatic differentiation$$ -by Andrea Walther. -Note that $icode s$$ provides the information so that -'dead ends' are not included in the sparsity pattern. - -$head Example$$ -$children% - example/sparse/for_hes_sparsity.cpp -%$$ -The file $cref for_hes_sparsity.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -Forward Hessian sparsity patterns. - -\tparam Base -is the base type for this recording. - -\tparam BoolVector -is the simple vector with elements of type bool that is used for -sparsity for the vector s. - -\tparam SizeVector -is the simple vector with elements of type size_t that is used for -row, column index sparsity patterns. - -\param select_domain -is a sparsity pattern for for the diagonal of D. - -\param select_range -is a sparsity pattern for for s. - -\param internal_bool -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of standard sets is used. - -\param pattern_out -The return value is a sparsity pattern for H(x) where -\f[ - H(x) = D * F^{(1)} (x) * D -\f] -Here F is the function corresponding to the operation sequence -and x is any argument value. -*/ -template -template -void ADFun::for_hes_sparsity( - const BoolVector& select_domain , - const BoolVector& select_range , - bool internal_bool , - sparse_rc& pattern_out ) -{ size_t n = Domain(); - size_t m = Range(); - // - CPPAD_ASSERT_KNOWN( - size_t( select_domain.size() ) == n, - "for_hes_sparsity: size of select_domain is not equal to " - "number of independent variables" - ); - CPPAD_ASSERT_KNOWN( - size_t( select_range.size() ) == m, - "for_hes_sparsity: size of select_range is not equal to " - "number of dependent variables" - ); - // do not need transpose or depenency - bool transpose = false; - bool dependency = false; - // - sparse_rc pattern_tmp; - if( internal_bool ) - { // forward Jacobian sparsity pattern for independent variables - local::sparse_pack internal_for_jac; - internal_for_jac.resize(num_var_tape_, n + 1 ); - for(size_t j = 0; j < n; j++) if( select_domain[j] ) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < n + 1 ); - internal_for_jac.add_element( ind_taddr_[j] , ind_taddr_[j] ); - } - // forward Jacobian sparsity for all variables on tape - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - internal_for_jac - ); - // reverse Jacobian sparsity pattern for select_range - local::sparse_pack internal_rev_jac; - internal_rev_jac.resize(num_var_tape_, 1); - for(size_t i = 0; i < m; i++) if( select_range[i] ) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - internal_rev_jac.add_element( dep_taddr_[i] , 0 ); - } - // reverse Jacobian sparsity for all variables on tape - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - internal_rev_jac - ); - // internal vector of sets that will hold Hessian - local::sparse_pack internal_for_hes; - internal_for_hes.resize(n + 1, n + 1); - // - // compute forward Hessian sparsity pattern - local::ForHesSweep( - n, - num_var_tape_, - &play_, - internal_for_jac, - internal_rev_jac, - internal_for_hes - ); - // - // put the result in pattern_tmp - get_internal_sparsity( - transpose, ind_taddr_, internal_for_hes, pattern_tmp - ); - } - else - { // forward Jacobian sparsity pattern for independent variables - // (corresponds to D) - local::sparse_list internal_for_jac; - internal_for_jac.resize(num_var_tape_, n + 1 ); - for(size_t j = 0; j < n; j++) if( select_domain[j] ) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < n + 1 ); - internal_for_jac.add_element( ind_taddr_[j] , ind_taddr_[j] ); - } - // forward Jacobian sparsity for all variables on tape - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - internal_for_jac - ); - // reverse Jacobian sparsity pattern for select_range - // (corresponds to s) - local::sparse_list internal_rev_jac; - internal_rev_jac.resize(num_var_tape_, 1); - for(size_t i = 0; i < m; i++) if( select_range[i] ) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - internal_rev_jac.add_element( dep_taddr_[i] , 0 ); - } - // reverse Jacobian sparsity for all variables on tape - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - internal_rev_jac - ); - // internal vector of sets that will hold Hessian - local::sparse_list internal_for_hes; - internal_for_hes.resize(n + 1, n + 1); - // - // compute forward Hessian sparsity pattern - local::ForHesSweep( - n, - num_var_tape_, - &play_, - internal_for_jac, - internal_rev_jac, - internal_for_hes - ); - // - // put the result in pattern_tmp - get_internal_sparsity( - transpose, ind_taddr_, internal_for_hes, pattern_tmp - ); - } - // subtract 1 from all column values - CPPAD_ASSERT_UNKNOWN( pattern_tmp.nr() == n ); - CPPAD_ASSERT_UNKNOWN( pattern_tmp.nc() == n + 1 ); - const SizeVector& row( pattern_tmp.row() ); - const SizeVector& col( pattern_tmp.col() ); - size_t nr = n; - size_t nc = n; - size_t nnz = pattern_tmp.nnz(); - pattern_out.resize(nr, nc, nnz); - for(size_t k = 0; k < nnz; k++) - { CPPAD_ASSERT_UNKNOWN( 0 < col[k] ); - pattern_out.set(k, row[k], col[k] - 1); - } - return; -} -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/for_jac_sparsity.hpp b/external/cppad/include/cppad/core/for_jac_sparsity.hpp deleted file mode 100644 index 5e8ae1c46..000000000 --- a/external/cppad/include/cppad/core/for_jac_sparsity.hpp +++ /dev/null @@ -1,294 +0,0 @@ -# ifndef CPPAD_CORE_FOR_JAC_SPARSITY_HPP -# define CPPAD_CORE_FOR_JAC_SPARSITY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin for_jac_sparsity$$ -$spell - Jacobian - jac - bool - const - rc - cpp -$$ - -$section Forward Mode Jacobian Sparsity Patterns$$ - -$head Syntax$$ -$icode%f%.for_jac_sparsity( - %pattern_in%, %transpose%, %dependency%, %internal_bool%, %pattern_out% -)%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to -the operation sequence stored in $icode f$$. -Fix $latex R \in \B{R}^{n \times \ell}$$ and define the function -$latex \[ - J(x) = F^{(1)} ( x ) * R -\] $$ -Given the $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex R$$, -$code for_jac_sparsity$$ computes a sparsity pattern for $latex J(x)$$. - -$head x$$ -Note that the sparsity pattern $latex J(x)$$ corresponds to the -operation sequence stored in $icode f$$ and does not depend on -the argument $icode x$$. -(The operation sequence may contain -$cref CondExp$$ and $cref VecAD$$ operations.) - -$head SizeVector$$ -The type $icode SizeVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -The $cref ADFun$$ object $icode f$$ is not $code const$$. -After a call to $code for_jac_sparsity$$, a sparsity pattern -for each of the variables in the operation sequence -is held in $icode f$$ for possible later use during -reverse Hessian sparsity calculations. - -$subhead size_forward_bool$$ -After $code for_jac_sparsity$$, if $icode k$$ is a $code size_t$$ object, -$codei% - %k% = %f%.size_forward_bool() -%$$ -sets $icode k$$ to the amount of memory (in unsigned character units) -used to store the -$cref/boolean vector/glossary/Sparsity Pattern/Boolean Vector/$$ -sparsity patterns. -If $icode internal_bool$$ if false, $icode k$$ will be zero. -Otherwise it will be non-zero. -If you do not need this information for $cref RevSparseHes$$ -calculations, it can be deleted -(and the corresponding memory freed) using -$codei% - %f%.size_forward_bool(0) -%$$ -after which $icode%f%.size_forward_bool()%$$ will return zero. - -$subhead size_forward_set$$ -After $code for_jac_sparsity$$, if $icode k$$ is a $code size_t$$ object, -$codei% - %k% = %f%.size_forward_set() -%$$ -sets $icode k$$ to the amount of memory (in unsigned character units) -used to store the -$cref/vector of sets/glossary/Sparsity Pattern/Vector of Sets/$$ -sparsity patterns. -If $icode internal_bool$$ if true, $icode k$$ will be zero. -Otherwise it will be non-zero. -If you do not need this information for future $cref rev_hes_sparsity$$ -calculations, it can be deleted -(and the corresponding memory freed) using -$codei% - %f%.size_forward_set(0) -%$$ -after which $icode%f%.size_forward_set()%$$ will return zero. - -$head pattern_in$$ -The argument $icode pattern_in$$ has prototype -$codei% - const sparse_rc<%SizeVector%>& %pattern_in% -%$$ -see $cref sparse_rc$$. -If $icode transpose$$ it is false (true), -$icode pattern_in$$ is a sparsity pattern for $latex R$$ ($latex R^\R{T}$$). - -$head transpose$$ -This argument has prototype -$codei% - bool %transpose% -%$$ -See $cref/pattern_in/for_jac_sparsity/pattern_in/$$ above and -$cref/pattern_out/for_jac_sparsity/pattern_out/$$ below. - -$head dependency$$ -This argument has prototype -$codei% - bool %dependency% -%$$ -see $cref/pattern_out/for_jac_sparsity/pattern_out/$$ below. - -$head internal_bool$$ -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of sets of integers is used. - -$head pattern_out$$ -This argument has prototype -$codei% - sparse_rc<%SizeVector%>& %pattern_out% -%$$ -This input value of $icode pattern_out$$ does not matter. -If $icode transpose$$ it is false (true), -upon return $icode pattern_out$$ is a sparsity pattern for -$latex J(x)$$ ($latex J(x)^\R{T}$$). -If $icode dependency$$ is true, $icode pattern_out$$ is a -$cref/dependency pattern/dependency.cpp/Dependency Pattern/$$ -instead of sparsity pattern. - -$head Sparsity for Entire Jacobian$$ -Suppose that -$latex R$$ is the $latex n \times n$$ identity matrix. -In this case, $icode pattern_out$$ is a sparsity pattern for -$latex F^{(1)} ( x )$$ ( $latex F^{(1)} (x)^\R{T}$$ ) -if $icode transpose$$ is false (true). - -$head Example$$ -$children% - example/sparse/for_jac_sparsity.cpp -%$$ -The file -$cref for_jac_sparsity.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -Forward Jacobian sparsity patterns. - -\tparam Base -is the base type for this recording. - -\tparam SizeVector -is the simple vector with elements of type size_t that is used for -row, column index sparsity patterns. - -\param pattern_in -is the sparsity pattern for for R or R^T depending on transpose. - -\param transpose -Is the input and returned sparsity pattern transposed. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param internal_bool -If this is true, calculations are done with sets represented by a vector -of boolean values. Othewise, a vector of standard sets is used. - -\param pattern_out -The value of transpose is false (true), -the return value is a sparsity pattern for J(x) ( J(x)^T ) where -\f[ - J(x) = F^{(1)} (x) * R -\f] -Here F is the function corresponding to the operation sequence -and x is any argument value. -*/ -template -template -void ADFun::for_jac_sparsity( - const sparse_rc& pattern_in , - bool transpose , - bool dependency , - bool internal_bool , - sparse_rc& pattern_out ) -{ // number or rows, columns, and non-zeros in pattern_in - size_t nr_in = pattern_in.nr(); - size_t nc_in = pattern_in.nc(); - // - size_t n = nr_in; - size_t ell = nc_in; - if( transpose ) - std::swap(n, ell); - // - CPPAD_ASSERT_KNOWN( - n == Domain() , - "for_jac_sparsity: number rows in R " - "is not equal number of independent variables." - ); - bool zero_empty = true; - bool input_empty = true; - if( internal_bool ) - { // allocate memory for bool sparsity calculation - // (sparsity pattern is emtpy after a resize) - for_jac_sparse_pack_.resize(num_var_tape_, ell); - for_jac_sparse_set_.resize(0, 0); - // - // set sparsity patttern for independent variables - local::set_internal_sparsity( - zero_empty , - input_empty , - transpose , - ind_taddr_ , - for_jac_sparse_pack_ , - pattern_in - ); - - // compute sparsity for other variables - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_sparse_pack_ - ); - // set the output pattern - local::get_internal_sparsity( - transpose, dep_taddr_, for_jac_sparse_pack_, pattern_out - ); - } - else - { - // allocate memory for set sparsity calculation - // (sparsity pattern is emtpy after a resize) - for_jac_sparse_set_.resize(num_var_tape_, ell); - for_jac_sparse_pack_.resize(0, 0); - // - // set sparsity patttern for independent variables - local::set_internal_sparsity( - zero_empty , - input_empty , - transpose , - ind_taddr_ , - for_jac_sparse_set_ , - pattern_in - ); - - // compute sparsity for other variables - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_sparse_set_ - ); - // get the ouput pattern - local::get_internal_sparsity( - transpose, dep_taddr_, for_jac_sparse_set_, pattern_out - ); - } - return; -} - - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/for_one.hpp b/external/cppad/include/cppad/core/for_one.hpp deleted file mode 100644 index 757c62cee..000000000 --- a/external/cppad/include/cppad/core/for_one.hpp +++ /dev/null @@ -1,164 +0,0 @@ -# ifndef CPPAD_CORE_FOR_ONE_HPP -# define CPPAD_CORE_FOR_ONE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ForOne$$ -$spell - dy - typename - Taylor - const -$$ - - - - -$section First Order Partial Derivative: Driver Routine$$ -$mindex easy$$ - -$head Syntax$$ -$icode%dy% = %f%.ForOne(%x%, %j%)%$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -The syntax above sets $icode dy$$ to the -partial of $latex F$$ with respect to $latex x_j$$; i.e., -$latex \[ -dy -= \D{F}{ x_j } (x) -= \left[ - \D{ F_0 }{ x_j } (x) , \cdots , \D{ F_{m-1} }{ x_j } (x) -\right] -\] $$ - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/ForOne Uses Forward/ForOne/ForOne Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -(see $cref/Vector/ForOne/Vector/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the partial derivative. - -$head j$$ -The argument $icode j$$ has prototype -$codei% - size_t %j% -%$$ -an is less than $icode n$$, -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies the component of $icode F$$ -for which we are computing the partial derivative. - -$head dy$$ -The result $icode dy$$ has prototype -$codei% - %Vector% %dy% -%$$ -(see $cref/Vector/ForOne/Vector/$$ below) -and its size is $latex m$$, the dimension of the -$cref/range/seq_property/Range/$$ space for $icode f$$. -The value of $icode dy$$ is the partial of $latex F$$ with respect to -$latex x_j$$ evaluated at $icode x$$; i.e., -for $latex i = 0 , \ldots , m - 1$$ -$latex \[. - dy[i] = \D{ F_i }{ x_j } ( x ) -\] $$ - - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head ForOne Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code ForOne$$, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0,%x%)%$$ -and the other coefficients are unspecified. - -$head Example$$ -$children% - example/general/for_one.cpp -%$$ -The routine -$cref/ForOne/for_one.cpp/$$ is both an example and test. -It returns $code true$$, if it succeeds and $code false$$ otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -template -Vector ADFun::ForOne(const Vector &x, size_t j) -{ size_t j1; - - size_t n = Domain(); - size_t m = Range(); - - // check Vector is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - x.size() == n, - "ForOne: Length of x not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - j < n, - "ForOne: the index j is not less than domain dimension for f" - ); - - // point at which we are evaluating the second partials - Forward(0, x); - - // direction in which are are taking the derivative - Vector dx(n); - for(j1 = 0; j1 < n; j1++) - dx[j1] = Base(0.0); - dx[j] = Base(1.0); - - // dimension the return value - Vector dy(m); - - // compute the return value - dy = Forward(1, dx); - - return dy; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/for_sparse_hes.hpp b/external/cppad/include/cppad/core/for_sparse_hes.hpp deleted file mode 100644 index cd6cc465f..000000000 --- a/external/cppad/include/cppad/core/for_sparse_hes.hpp +++ /dev/null @@ -1,559 +0,0 @@ -# ifndef CPPAD_CORE_FOR_SPARSE_HES_HPP -# define CPPAD_CORE_FOR_SPARSE_HES_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ForSparseHes$$ -$spell - Andrea Walther - std - VecAD - Jacobian - Jac - Hessian - Hes - const - Bool - Dep - proportional - var - cpp -$$ - -$section Hessian Sparsity Pattern: Forward Mode$$ - -$head Syntax$$ -$icode%h% = %f%.ForSparseHes(%r%, %s%) -%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -we define -$latex \[ -\begin{array}{rcl} -H(x) -& = & \partial_x \left[ \partial_u S \cdot F[ x + R \cdot u ] \right]_{u=0} -\\ -& = & R^\R{T} \cdot (S \cdot F)^{(2)} ( x ) \cdot R -\end{array} -\] $$ -Where $latex R \in \B{R}^{n \times n}$$ is a diagonal matrix -and $latex S \in \B{R}^{1 \times m}$$ is a row vector. -Given a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the diagonal of $latex R$$ and the vector $latex S$$, -$code ForSparseHes$$ returns a sparsity pattern for the $latex H(x)$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - const ADFun<%Base%> %f% -%$$ - -$head x$$ -If the operation sequence in $icode f$$ is -$cref/independent/glossary/Operation/Independent/$$ of -the independent variables in $latex x \in B^n$$, -the sparsity pattern is valid for all values of -(even if it has $cref CondExp$$ or $cref VecAD$$ operations). - -$head r$$ -The argument $icode r$$ has prototype -$codei% - const %VectorSet%& %r% -%$$ -(see $cref/VectorSet/ForSparseHes/VectorSet/$$ below) -If it has elements of type $code bool$$, -its size is $latex n$$. -If it has elements of type $code std::set$$, -its size is one and all the elements of $icode%s%[0]%$$ -are between zero and $latex n - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the diagonal of $latex R$$. -The fewer non-zero elements in this sparsity pattern, -the faster the calculation should be and the more sparse -$latex H(x)$$ should be. - -$head s$$ -The argument $icode s$$ has prototype -$codei% - const %VectorSet%& %s% -%$$ -(see $cref/VectorSet/ForSparseHes/VectorSet/$$ below) -If it has elements of type $code bool$$, -its size is $latex m$$. -If it has elements of type $code std::set$$, -its size is one and all the elements of $icode%s%[0]%$$ -are between zero and $latex m - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the vector $icode S$$. -The fewer non-zero elements in this sparsity pattern, -the faster the calculation should be and the more sparse -$latex H(x)$$ should be. - -$head h$$ -The result $icode h$$ has prototype -$codei% - %VectorSet%& %h% -%$$ -(see $cref/VectorSet/ForSparseHes/VectorSet/$$ below). -If $icode h$$ has elements of type $code bool$$, -its size is $latex n * n$$. -If it has elements of type $code std::set$$, -its size is $latex n$$ and all the set elements are between -zero and $icode%n%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex H(x)$$. - -$head VectorSet$$ -The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$ or $code std::set$$; -see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion -of the difference. -The type of the elements of -$cref/VectorSet/ForSparseHes/VectorSet/$$ must be the -same as the type of the elements of $icode r$$. - -$head Algorithm$$ -See Algorithm II in -$italic Computing sparse Hessians with automatic differentiation$$ -by Andrea Walther. -Note that $icode s$$ provides the information so that -'dead ends' are not included in the sparsity pattern. - -$head Example$$ -$children% - example/sparse/for_sparse_hes.cpp -%$$ -The file -$cref for_sparse_hes.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file for_sparse_hes.hpp -Forward mode Hessian sparsity patterns. -*/ -// =========================================================================== -// ForSparseHesCase -/*! -Private helper function for ForSparseHes(q, s) bool sparsity. - -All of the description in the public member function ForSparseHes(q, s) -applies. - -\param set_type -is a \c bool value. This argument is used to dispatch to the proper source -code depending on the vlaue of \c VectorSet::value_type. - -\param r -See \c ForSparseHes(r, s). - -\param s -See \c ForSparseHes(r, s). - -\param h -is the return value for the corresponging call to \c ForSparseJac(q, s). -*/ -template -template -void ADFun::ForSparseHesCase( - bool set_type , - const VectorSet& r , - const VectorSet& s , - VectorSet& h ) -{ size_t n = Domain(); - size_t m = Range(); - // - // check Vector is Simple VectorSet class with bool elements - CheckSimpleVector(); - // - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == n, - "ForSparseHes: size of r is not equal to\n" - "domain dimension for ADFun object." - ); - CPPAD_ASSERT_KNOWN( - size_t(s.size()) == m, - "ForSparseHes: size of s is not equal to\n" - "range dimension for ADFun object." - ); - // - // sparsity pattern corresponding to r - local::sparse_pack for_jac_pattern; - for_jac_pattern.resize(num_var_tape_, n + 1); - for(size_t i = 0; i < n; i++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] < n + 1 ); - // ind_taddr_[i] is operator taddr for i-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == local::InvOp ); - // - if( r[i] ) - for_jac_pattern.add_element( ind_taddr_[i], ind_taddr_[i] ); - } - // compute forward Jacobiain sparsity pattern - bool dependency = false; - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_pattern - ); - // sparsity pattern correspnding to s - local::sparse_pack rev_jac_pattern; - rev_jac_pattern.resize(num_var_tape_, 1); - for(size_t i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - if( s[i] ) - rev_jac_pattern.add_element( dep_taddr_[i], 0); - } - // compute reverse sparsity pattern for dependency analysis - // (note that we are only want non-zero derivatives not true dependency) - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - rev_jac_pattern - ); - // vector of sets that will hold the forward Hessain values - local::sparse_pack for_hes_pattern; - for_hes_pattern.resize(n+1, n+1); - // - // compute the Hessian sparsity patterns - local::ForHesSweep( - n, - num_var_tape_, - &play_, - for_jac_pattern, - rev_jac_pattern, - for_hes_pattern - ); - // initialize return values corresponding to independent variables - h.resize(n * n); - for(size_t i = 0; i < n; i++) - { for(size_t j = 0; j < n; j++) - h[ i * n + j ] = false; - } - // copy to result pattern - CPPAD_ASSERT_UNKNOWN( for_hes_pattern.end() == n+1 ); - for(size_t i = 0; i < n; i++) - { // ind_taddr_[i] is operator taddr for i-th independent variable - CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] == i + 1 ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == local::InvOp ); - - // extract the result from for_hes_pattern - local::sparse_pack::const_iterator itr(for_hes_pattern, ind_taddr_[i] ); - size_t j = *itr; - while( j < for_hes_pattern.end() ) - { CPPAD_ASSERT_UNKNOWN( 0 < j ) - h[ i * n + (j-1) ] = true; - j = *(++itr); - } - } -} -/*! -Private helper function for ForSparseHes(q, s) set sparsity. - -All of the description in the public member function ForSparseHes(q, s) -applies. - -\param set_type -is a \c std::set value. -This argument is used to dispatch to the proper source -code depending on the vlaue of \c VectorSet::value_type. - -\param r -See \c ForSparseHes(r, s). - -\param s -See \c ForSparseHes(q, s). - -\param h -is the return value for the corresponging call to \c ForSparseJac(q, s). -*/ -template -template -void ADFun::ForSparseHesCase( - const std::set& set_type , - const VectorSet& r , - const VectorSet& s , - VectorSet& h ) -{ size_t n = Domain(); -# ifndef NDEBUG - size_t m = Range(); -# endif - std::set::const_iterator itr_1; - // - // check VectorSet is Simple Vector class with sets for elements - CheckSimpleVector, VectorSet>( - local::one_element_std_set(), local::two_element_std_set() - ); - CPPAD_ASSERT_KNOWN( - r.size() == 1, - "ForSparseHes: size of s is not equal to one." - ); - CPPAD_ASSERT_KNOWN( - s.size() == 1, - "ForSparseHes: size of s is not equal to one." - ); - // - // sparsity pattern corresponding to r - local::sparse_list for_jac_pattern; - for_jac_pattern.resize(num_var_tape_, n + 1); - itr_1 = r[0].begin(); - while( itr_1 != r[0].end() ) - { size_t i = *itr_1++; - CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] < n + 1 ); - // ind_taddr_[i] is operator taddr for i-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == local::InvOp ); - // - for_jac_pattern.add_element( ind_taddr_[i], ind_taddr_[i] ); - } - // compute forward Jacobiain sparsity pattern - bool dependency = false; - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_pattern - ); - // sparsity pattern correspnding to s - local::sparse_list rev_jac_pattern; - rev_jac_pattern.resize(num_var_tape_, 1); - itr_1 = s[0].begin(); - while( itr_1 != s[0].end() ) - { size_t i = *itr_1++; - CPPAD_ASSERT_KNOWN( - i < m, - "ForSparseHes: an element of the set s[0] has value " - "greater than or equal m" - ); - CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - rev_jac_pattern.add_element( dep_taddr_[i], 0); - } - // - // compute reverse sparsity pattern for dependency analysis - // (note that we are only want non-zero derivatives not true dependency) - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - rev_jac_pattern - ); - // - // vector of sets that will hold reverse Hessain values - local::sparse_list for_hes_pattern; - for_hes_pattern.resize(n+1, n+1); - // - // compute the Hessian sparsity patterns - local::ForHesSweep( - n, - num_var_tape_, - &play_, - for_jac_pattern, - rev_jac_pattern, - for_hes_pattern - ); - // return values corresponding to independent variables - // j is index corresponding to reverse mode partial - h.resize(n); - CPPAD_ASSERT_UNKNOWN( for_hes_pattern.end() == n+1 ); - for(size_t i = 0; i < n; i++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] == i + 1 ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == local::InvOp ); - - // extract the result from for_hes_pattern - local::sparse_list::const_iterator itr_2(for_hes_pattern, ind_taddr_[i] ); - size_t j = *itr_2; - while( j < for_hes_pattern.end() ) - { CPPAD_ASSERT_UNKNOWN( 0 < j ) - h[i].insert(j-1); - j = *(++itr_2); - } - } -} - -// =========================================================================== -// ForSparseHes - -/*! -User API for Hessian sparsity patterns using reverse mode. - -The C++ source code corresponding to this operation is -\verbatim - h = f.ForSparseHes(q, r) -\endverbatim - -\tparam Base -is the base type for this recording. - -\tparam VectorSet -is a simple vector with elements of type \c bool -or \c std::set. - -\param r -is a vector with size \c n that specifies the sparsity pattern -for the diagonal of the matrix \f$ R \f$, -where \c n is the number of independent variables -corresponding to the operation sequence stored in \a play. - -\param s -is a vector with size \c m that specifies the sparsity pattern -for the vector \f$ S \f$, -where \c m is the number of dependent variables -corresponding to the operation sequence stored in \a play. - -\return -The return vector is a sparsity pattern for \f$ H(x) \f$ -\f[ - H(x) = R^T ( S * F)^{(2)} (x) R -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \a x is any argument value. -*/ - -template -template -VectorSet ADFun::ForSparseHes( - const VectorSet& r, const VectorSet& s -) -{ VectorSet h; - typedef typename VectorSet::value_type Set_type; - - // Should check to make sure q is same as in previous call to - // forward sparse Jacobian. - ForSparseHesCase( - Set_type() , - r , - s , - h - ); - - return h; -} -// =========================================================================== -// ForSparseHesCheckpoint -/*! -Hessian sparsity patterns calculation used by checkpoint functions. - -\tparam Base -is the base type for this recording. - -\param r -is a vector with size n that specifies the sparsity pattern -for the diagonal of \f$ R \f$, -where n is the number of independent variables -corresponding to the operation sequence stored in play_. - -\param s -is a vector with size m that specifies the sparsity pattern -for the vector \f$ S \f$, -where m is the number of dependent variables -corresponding to the operation sequence stored in play_. - -\param h -The input size and elements of h do not matter. -On output, h is the sparsity pattern for the matrix \f$ H(x) R \f$. - -\par Assumptions -The forward jacobian sparsity pattern must be currently stored -in this ADFUN object. -*/ - -// The checkpoint class is not yet using forward sparse Hessians. -# ifdef CPPAD_NOT_DEFINED -template -void ADFun::ForSparseHesCheckpoint( - vector& r , - vector& s , - local::sparse_list& h ) -{ - size_t n = Domain(); - size_t m = Range(); - - // checkpoint functions should get this right - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( s.size() == m ); - - // Array that holds the reverse Jacobiain dependcy flags. - // Initialize as true for dependent variables, flase for others. - local::pod_vector RevJac; - RevJac.extend(num_var_tape_); - for(size_t i = 0; i < num_var_tape_; i++) - RevJac[i] = false; - for(size_t i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ) - RevJac[ dep_taddr_[i] ] = s[i]; - } - - // holds forward Hessian sparsity pattern for all variables - local::sparse_list for_hes_pattern; - for_hes_pattern.resize(n+1, n+1); - - // compute Hessian sparsity pattern for all variables - local::ForHesSweep( - n, - num_var_tape_, - &play_, - for_jac_sparse_set_, - RevJac.data(), - for_hes_pattern - ); - - // dimension the return value - if( transpose ) - h.resize(n, n); - else - h.resize(n, n); - - // j is index corresponding to reverse mode partial - for(size_t j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j + 1 ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // extract the result from for_hes_pattern - CPPAD_ASSERT_UNKNOWN( for_hes_pattern.end() == q ); - local::sparse_list::const_iterator itr(for_hes_pattern, .j + 1); - size_t i = *itr; - while( i < q ) - { if( transpose ) - h.add_element(j, i); - else h.add_element(i, j); - i = *(++itr); - } - } -} -# endif - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/for_sparse_jac.hpp b/external/cppad/include/cppad/core/for_sparse_jac.hpp deleted file mode 100644 index c777cd39d..000000000 --- a/external/cppad/include/cppad/core/for_sparse_jac.hpp +++ /dev/null @@ -1,729 +0,0 @@ -# ifndef CPPAD_CORE_FOR_SPARSE_JAC_HPP -# define CPPAD_CORE_FOR_SPARSE_JAC_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ForSparseJac$$ -$spell - std - var - Jacobian - Jac - const - Bool - proportional - VecAD - CondExpRel - optimizer - cpp -$$ - -$section Jacobian Sparsity Pattern: Forward Mode$$ - -$head Syntax$$ -$icode%s% = %f%.ForSparseJac(%q%, %r%) -%$$ -$icode%s% = %f%.ForSparseJac(%q%, %r%, %transpose%, %dependency%)%$$ - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -For a fixed $latex n \times q$$ matrix $latex R$$, -the Jacobian of $latex F[ x + R * u ]$$ -with respect to $latex u$$ at $latex u = 0$$ is -$latex \[ - S(x) = F^{(1)} ( x ) * R -\] $$ -Given a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for $latex R$$, -$code ForSparseJac$$ returns a sparsity pattern for the $latex S(x)$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$. -After a call to $code ForSparseJac$$, the sparsity pattern -for each of the variables in the operation sequence -is held in $icode f$$ (for possible later use by $cref RevSparseHes$$). -These sparsity patterns are stored with elements of type $code bool$$ -or elements of type $code std::set$$ -(see $cref/VectorSet/ForSparseJac/VectorSet/$$ below). - -$subhead size_forward_bool$$ -After $code ForSparseJac$$, if $icode k$$ is a $code size_t$$ object, -$codei% - %k% = %f%.size_forward_bool() -%$$ -sets $icode k$$ to the amount of memory (in unsigned character units) -used to store the sparsity pattern with elements of type $code bool$$ -in the function object $icode f$$. -If the sparsity patterns for the previous $code ForSparseJac$$ used -elements of type $code bool$$, -the return value for $code size_forward_bool$$ will be non-zero. -Otherwise, its return value will be zero. -This sparsity pattern is stored for use by $cref RevSparseHes$$ and -when it is not longer needed, it can be deleted -(and the corresponding memory freed) using -$codei% - %f%.size_forward_bool(0) -%$$ -After this call, $icode%f%.size_forward_bool()%$$ will return zero. - -$subhead size_forward_set$$ -After $code ForSparseJac$$, if $icode k$$ is a $code size_t$$ object, -$codei% - %k% = %f%.size_forward_set() -%$$ -sets $icode k$$ to the amount of memory (in unsigned character units) -used to store the -$cref/vector of sets/glossary/Sparsity Pattern/Vector of Sets/$$ -sparsity patterns. -If the sparsity patterns for this operation use elements of type $code bool$$, -the return value for $code size_forward_set$$ will be zero. -Otherwise, its return value will be non-zero. -This sparsity pattern is stored for use by $cref RevSparseHes$$ and -when it is not longer needed, it can be deleted -(and the corresponding memory freed) using -$codei% - %f%.size_forward_set(0) -%$$ -After this call, $icode%f%.size_forward_set()%$$ will return zero. - -$head x$$ -If the operation sequence in $icode f$$ is -$cref/independent/glossary/Operation/Independent/$$ of -the independent variables in $latex x \in B^n$$, -the sparsity pattern is valid for all values of -(even if it has $cref CondExp$$ or $cref VecAD$$ operations). - -$head q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of columns in -$latex R \in B^{n \times q}$$ and the Jacobian -$latex S(x) \in B^{m \times q}$$. - -$head transpose$$ -The argument $icode transpose$$ has prototype -$codei% - bool %transpose% -%$$ -The default value $code false$$ is used when $icode transpose$$ is not present. - -$head dependency$$ -The argument $icode dependency$$ has prototype -$codei% - bool %dependency% -%$$ -If $icode dependency$$ is true, -the $cref/dependency pattern/dependency.cpp/Dependency Pattern/$$ -(instead of sparsity pattern) is computed. - -$head r$$ -The argument $icode r$$ has prototype -$codei% - const %VectorSet%& %r% -%$$ -see $cref/VectorSet/ForSparseJac/VectorSet/$$ below. - -$subhead transpose false$$ -If $icode r$$ has elements of type $code bool$$, -its size is $latex n * q$$. -If it has elements of type $code std::set$$, -its size is $latex n$$ and all the set elements must be between -zero and $icode%q%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex R \in B^{n \times q}$$. - -$subhead transpose true$$ -If $icode r$$ has elements of type $code bool$$, -its size is $latex q * n$$. -If it has elements of type $code std::set$$, -its size is $latex q$$ and all the set elements must be between -zero and $icode%n%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex R^\R{T} \in B^{q \times n}$$. - -$head s$$ -The return value $icode s$$ has prototype -$codei% - %VectorSet% %s% -%$$ -see $cref/VectorSet/ForSparseJac/VectorSet/$$ below. - -$subhead transpose false$$ -If $icode s$$ has elements of type $code bool$$, -its size is $latex m * q$$. -If it has elements of type $code std::set$$, -its size is $latex m$$ and all its set elements are between -zero and $icode%q%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex S(x) \in B^{m \times q}$$. - -$subhead transpose true$$ -If $icode s$$ has elements of type $code bool$$, -its size is $latex q * m$$. -If it has elements of type $code std::set$$, -its size is $latex q$$ and all its set elements are between -zero and $icode%m%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex S(x)^\R{T} \in B^{q \times m}$$. - -$head VectorSet$$ -The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$ or $code std::set$$; -see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion -of the difference. - -$head Entire Sparsity Pattern$$ -Suppose that $latex q = n$$ and -$latex R$$ is the $latex n \times n$$ identity matrix. -In this case, -the corresponding value for $icode s$$ is a -sparsity pattern for the Jacobian $latex S(x) = F^{(1)} ( x )$$. - -$head Example$$ -$children% - example/sparse/for_sparse_jac.cpp -%$$ -The file -$cref for_sparse_jac.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. -The file -$cref/sparsity_sub.cpp/sparsity_sub.cpp/ForSparseJac/$$ -contains an example and test of using $code ForSparseJac$$ -to compute the sparsity pattern for a subset of the Jacobian. - -$end ------------------------------------------------------------------------------ -*/ - -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file for_sparse_jac.hpp -Forward mode Jacobian sparsity patterns. -*/ -// --------------------------------------------------------------------------- -/*! -Private helper function for ForSparseJac(q, r) boolean sparsity patterns. - -All of the description in the public member function ForSparseJac(q, r) -applies. - -\param set_type -is a \c bool value. This argument is used to dispatch to the proper source -code depending on the value of \c VectorSet::value_type. - -\param transpose -See \c ForSparseJac(q, r, transpose, dependency). - -\param dependency -See \c ForSparseJac(q, r, transpose, dependency). - -\param q -See \c ForSparseJac(q, r, transpose, dependency). - -\param r -See \c ForSparseJac(q, r, transpose, dependency). - -\param s -is the return value for the corresponding call to \c ForSparseJac(q, r). -*/ - -template -template -void ADFun::ForSparseJacCase( - bool set_type , - bool transpose , - bool dependency , - size_t q , - const VectorSet& r , - VectorSet& s ) -{ size_t m = Range(); - size_t n = Domain(); - - // check VectorSet is Simple Vector class with bool elements - CheckSimpleVector(); - - // dimension size of result vector - s.resize( m * q ); - - // temporary indices - size_t i, j; - // - CPPAD_ASSERT_KNOWN( - q > 0, - "ForSparseJac: q is not greater than zero" - ); - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == n * q, - "ForSparseJac: size of r is not equal to\n" - "q times domain dimension for ADFun object." - ); - // - // allocate memory for the requested sparsity calculation result - for_jac_sparse_pack_.resize(num_var_tape_, q); - - // set values corresponding to independent variables - for(i = 0; i < n; i++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] < num_var_tape_ ); - // ind_taddr_[i] is operator taddr for i-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == local::InvOp ); - - // set bits that are true - if( transpose ) - { for(j = 0; j < q; j++) if( r[ j * n + i ] ) - for_jac_sparse_pack_.add_element( ind_taddr_[i], j); - } - else - { for(j = 0; j < q; j++) if( r[ i * q + j ] ) - for_jac_sparse_pack_.add_element( ind_taddr_[i], j); - } - } - - // evaluate the sparsity patterns - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_sparse_pack_ - ); - - // return values corresponding to dependent variables - CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m * q ); - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - - // extract the result from for_jac_sparse_pack_ - if( transpose ) - { for(j = 0; j < q; j++) - s[ j * m + i ] = false; - } - else - { for(j = 0; j < q; j++) - s[ i * q + j ] = false; - } - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.end() == q ); - local::sparse_pack::const_iterator itr(for_jac_sparse_pack_, dep_taddr_[i] ); - j = *itr; - while( j < q ) - { if( transpose ) - s[j * m + i] = true; - else s[i * q + j] = true; - j = *(++itr); - } - } -} -// --------------------------------------------------------------------------- -/*! -Private helper function for \c ForSparseJac(q, r) set sparsity. - -All of the description in the public member function \c ForSparseJac(q, r) -applies. - -\param set_type -is a \c std::set object. -This argument is used to dispatch to the proper source -code depending on the value of \c VectorSet::value_type. - -\param transpose -See \c ForSparseJac(q, r, transpose, dependency). - -\param dependency -See \c ForSparseJac(q, r, transpose, dependency). - -\param q -See \c ForSparseJac(q, r, transpose, dependency). - -\param r -See \c ForSparseJac(q, r, transpose, dependency). - -\param s -is the return value for the corresponding call to \c ForSparseJac(q, r). -*/ -template -template -void ADFun::ForSparseJacCase( - const std::set& set_type , - bool transpose , - bool dependency , - size_t q , - const VectorSet& r , - VectorSet& s ) -{ size_t m = Range(); - size_t n = Domain(); - - // check VectorSet is Simple Vector class with sets for elements - CheckSimpleVector, VectorSet>( - local::one_element_std_set(), local::two_element_std_set() - ); - - // dimension size of result vector - if( transpose ) - s.resize(q); - else s.resize( m ); - - // temporary indices - size_t i, j; - std::set::const_iterator itr_1; - // - CPPAD_ASSERT_KNOWN( - q > 0, - "ForSparseJac: q is not greater than zero" - ); - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == n || transpose, - "ForSparseJac: size of r is not equal to n and transpose is false." - ); - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == q || ! transpose, - "ForSparseJac: size of r is not equal to q and transpose is true." - ); - // - // allocate memory for the requested sparsity calculation - for_jac_sparse_set_.resize(num_var_tape_, q); - - // set values corresponding to independent variables - if( transpose ) - { for(i = 0; i < q; i++) - { // add the elements that are present - itr_1 = r[i].begin(); - while( itr_1 != r[i].end() ) - { j = *itr_1++; - CPPAD_ASSERT_KNOWN( - j < n, - "ForSparseJac: transpose is true and element of the set\n" - "r[j] has value greater than or equal n." - ); - CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - // operator for j-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - for_jac_sparse_set_.add_element( ind_taddr_[j], i); - } - } - } - else - { for(i = 0; i < n; i++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] < num_var_tape_ ); - // ind_taddr_[i] is operator taddr for i-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == local::InvOp ); - - // add the elements that are present - itr_1 = r[i].begin(); - while( itr_1 != r[i].end() ) - { j = *itr_1++; - CPPAD_ASSERT_KNOWN( - j < q, - "ForSparseJac: an element of the set r[i] " - "has value greater than or equal q." - ); - for_jac_sparse_set_.add_element( ind_taddr_[i], j); - } - } - } - // evaluate the sparsity patterns - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_sparse_set_ - ); - - // return values corresponding to dependent variables - CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m || transpose ); - CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || ! transpose ); - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - - // extract results from for_jac_sparse_set_ - // and add corresponding elements to sets in s - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.end() == q ); - local::sparse_list::const_iterator itr_2(for_jac_sparse_set_, dep_taddr_[i] ); - j = *itr_2; - while( j < q ) - { if( transpose ) - s[j].insert(i); - else s[i].insert(j); - j = *(++itr_2); - } - } -} -// --------------------------------------------------------------------------- - -/*! -User API for Jacobian sparsity patterns using forward mode. - -The C++ source code corresponding to this operation is -\verbatim - s = f.ForSparseJac(q, r, transpose, dependency) -\endverbatim - -\tparam Base -is the base type for this recording. - -\tparam VectorSet -is a simple vector with elements of type \c bool -or \c std::set. - -\param q -is the number of columns in the matrix \f$ R \f$. - -\param r -is a sparsity pattern for the matrix \f$ R \f$. - -\param transpose -are sparsity patterns for \f$ R \f$ and \f$ S(x) \f$ transposed. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\return -The value of \c transpose is false (true), -the return value is a sparsity pattern for \f$ S(x) \f$ (\f$ S(x)^T \f$) where -\f[ - S(x) = F^{(1)} (x) * R -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \a x is any argument value. -If \c VectorSet::value_type is \c bool, -the return value has size \f$ m * q \f$ (\f$ q * m \f$). -where \c m is the number of dependent variables -corresponding to the operation sequence stored in \c f. -If \c VectorSet::value_type is \c std::set, -the return value has size \f$ m \f$ ( \f$ q \f$ ) -and with all its elements between zero and -\f$ q - 1 \f$ ( \f$ m - 1 \f$). - -\par Side Effects -If \c VectorSet::value_type is \c bool, -the forward sparsity pattern for all of the variables on the -tape is stored in \c for_jac_sparse_pack__. -In this case -\verbatim - for_jac_sparse_pack_.n_set() == num_var_tape_ - for_jac_sparse_pack_.end() == q - for_jac_sparse_set_.n_set() == 0 - for_jac_sparse_set_.end() == 0 -\endverbatim -\n -\n -If \c VectorSet::value_type is \c std::set, -the forward sparsity pattern for all of the variables on the -tape is stored in \c for_jac_sparse_set__. -In this case -\verbatim - for_jac_sparse_set_.n_set() == num_var_tape_ - for_jac_sparse_set_.end() == q - for_jac_sparse_pack_.n_set() == 0 - for_jac_sparse_pack_.end() == 0 -\endverbatim -*/ -template -template -VectorSet ADFun::ForSparseJac( - size_t q , - const VectorSet& r , - bool transpose , - bool dependency ) -{ VectorSet s; - typedef typename VectorSet::value_type Set_type; - - // free all memory currently in sparsity patterns - for_jac_sparse_pack_.resize(0, 0); - for_jac_sparse_set_.resize(0, 0); - - ForSparseJacCase( - Set_type() , - transpose , - dependency , - q , - r , - s - ); - - return s; -} -// =========================================================================== -// ForSparseJacCheckpoint -/*! -Forward mode Jacobian sparsity calculation used by checkpoint functions. - -\tparam Base -is the base type for this recording. - -\param transpose -is true (false) s is equal to \f$ S(x) \f$ (\f$ S(x)^T \f$) -where -\f[ - S(x) = F^{(1)} (x) * R -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \f$ x \f$ is any argument value. - -\param q -is the number of columns in the matrix \f$ R \f$. - -\param r -is a sparsity pattern for the matrix \f$ R \f$. - -\param transpose -are the sparsity patterns for \f$ R \f$ and \f$ S(x) \f$ transposed. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param s -The input size and elements of s do not matter. -On output, s is the sparsity pattern for the matrix \f$ S(x) \f$ -or \f$ S(x)^T \f$ depending on transpose. - -\par Side Effects -If \c VectorSet::value_type is \c bool, -the forward sparsity pattern for all of the variables on the -tape is stored in \c for_jac_sparse_pack__. -In this case -\verbatim - for_jac_sparse_pack_.n_set() == num_var_tape_ - for_jac_sparse_pack_.end() == q - for_jac_sparse_set_.n_set() == 0 - for_jac_sparse_set_.end() == 0 -\endverbatim -\n -\n -If \c VectorSet::value_type is \c std::set, -the forward sparsity pattern for all of the variables on the -tape is stored in \c for_jac_sparse_set__. -In this case -\verbatim - for_jac_sparse_set_.n_set() == num_var_tape_ - for_jac_sparse_set_.end() == q - for_jac_sparse_pack_.n_set() == 0 - for_jac_sparse_pack_.end() == 0 -\endverbatim -*/ -template -void ADFun::ForSparseJacCheckpoint( - size_t q , - const local::sparse_list& r , - bool transpose , - bool dependency , - local::sparse_list& s ) -{ size_t n = Domain(); - size_t m = Range(); - -# ifndef NDEBUG - if( transpose ) - { CPPAD_ASSERT_UNKNOWN( r.n_set() == q ); - CPPAD_ASSERT_UNKNOWN( r.end() == n ); - } - else - { CPPAD_ASSERT_UNKNOWN( r.n_set() == n ); - CPPAD_ASSERT_UNKNOWN( r.end() == q ); - } - for(size_t j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - } -# endif - - // free all memory currently in sparsity patterns - for_jac_sparse_pack_.resize(0, 0); - for_jac_sparse_set_.resize(0, 0); - - // allocate new sparsity pattern - for_jac_sparse_set_.resize(num_var_tape_, q); - - // set sparsity pattern for dependent variables - if( transpose ) - { for(size_t i = 0; i < q; i++) - { local::sparse_list::const_iterator itr(r, i); - size_t j = *itr; - while( j < n ) - { for_jac_sparse_set_.add_element( ind_taddr_[j], i ); - j = *(++itr); - } - } - } - else - { for(size_t j = 0; j < n; j++) - { local::sparse_list::const_iterator itr(r, j); - size_t i = *itr; - while( i < q ) - { for_jac_sparse_set_.add_element( ind_taddr_[j], i ); - i = *(++itr); - } - } - } - - // evaluate the sparsity pattern for all variables - local::ForJacSweep( - dependency, - n, - num_var_tape_, - &play_, - for_jac_sparse_set_ - ); - - // dimension the return value - if( transpose ) - s.resize(q, m); - else - s.resize(m, q); - - // return values corresponding to dependent variables - for(size_t i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - - // extract the result from for_jac_sparse_set_ - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.end() == q ); - local::sparse_list::const_iterator itr(for_jac_sparse_set_, dep_taddr_[i] ); - size_t j = *itr; - while( j < q ) - { if( transpose ) - s.add_element(j, i); - else - s.add_element(i, j); - j = *(++itr); - } - } - -} - - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/for_two.hpp b/external/cppad/include/cppad/core/for_two.hpp deleted file mode 100644 index b4cedec7a..000000000 --- a/external/cppad/include/cppad/core/for_two.hpp +++ /dev/null @@ -1,255 +0,0 @@ -# ifndef CPPAD_CORE_FOR_TWO_HPP -# define CPPAD_CORE_FOR_TWO_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ForTwo$$ -$spell - ddy - typename - Taylor - const -$$ - - - - - -$section Forward Mode Second Partial Derivative Driver$$ -$mindex order easy$$ - -$head Syntax$$ -$icode%ddy% = %f%.ForTwo(%x%, %j%, %k%)%$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -The syntax above sets -$latex \[ - ddy [ i * p + \ell ] - = - \DD{ F_i }{ x_{j[ \ell ]} }{ x_{k[ \ell ]} } (x) -\] $$ -for $latex i = 0 , \ldots , m-1$$ -and $latex \ell = 0 , \ldots , p$$, -where $latex p$$ is the size of the vectors $icode j$$ and $icode k$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/ForTwo Uses Forward/ForTwo/ForTwo Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %VectorBase% &%x% -%$$ -(see $cref/VectorBase/ForTwo/VectorBase/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the partial derivatives listed above. - -$head j$$ -The argument $icode j$$ has prototype -$codei% - const %VectorSize_t% &%j% -%$$ -(see $cref/VectorSize_t/ForTwo/VectorSize_t/$$ below) -We use $icode p$$ to denote the size of the vector $icode j$$. -All of the indices in $icode j$$ -must be less than $icode n$$; i.e., -for $latex \ell = 0 , \ldots , p-1$$, $latex j[ \ell ] < n$$. - -$head k$$ -The argument $icode k$$ has prototype -$codei% - const %VectorSize_t% &%k% -%$$ -(see $cref/VectorSize_t/ForTwo/VectorSize_t/$$ below) -and its size must be equal to $icode p$$, -the size of the vector $icode j$$. -All of the indices in $icode k$$ -must be less than $icode n$$; i.e., -for $latex \ell = 0 , \ldots , p-1$$, $latex k[ \ell ] < n$$. - -$head ddy$$ -The result $icode ddy$$ has prototype -$codei% - %VectorBase% %ddy% -%$$ -(see $cref/VectorBase/ForTwo/VectorBase/$$ below) -and its size is $latex m * p$$. -It contains the requested partial derivatives; to be specific, -for $latex i = 0 , \ldots , m - 1 $$ -and $latex \ell = 0 , \ldots , p - 1$$ -$latex \[ - ddy [ i * p + \ell ] - = - \DD{ F_i }{ x_{j[ \ell ]} }{ x_{k[ \ell ]} } (x) -\] $$ - -$head VectorBase$$ -The type $icode VectorBase$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Base/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head VectorSize_t$$ -The type $icode VectorSize_t$$ must be a $cref SimpleVector$$ class with -$cref/elements of type size_t/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head ForTwo Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code ForTwo$$, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -$head Examples$$ -$children% - example/general/for_two.cpp -%$$ -The routine -$cref/ForTwo/for_two.cpp/$$ is both an example and test. -It returns $code true$$, if it succeeds and $code false$$ otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -template -VectorBase ADFun::ForTwo( - const VectorBase &x, - const VectorSize_t &j, - const VectorSize_t &k) -{ size_t i; - size_t j1; - size_t k1; - size_t l; - - size_t n = Domain(); - size_t m = Range(); - size_t p = j.size(); - - // check VectorBase is Simple Vector class with Base type elements - CheckSimpleVector(); - - // check VectorSize_t is Simple Vector class with size_t elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - x.size() == n, - "ForTwo: Length of x not equal domain dimension for f." - ); - CPPAD_ASSERT_KNOWN( - j.size() == k.size(), - "ForTwo: Lenght of the j and k vectors are not equal." - ); - // point at which we are evaluating the second partials - Forward(0, x); - - - // dimension the return value - VectorBase ddy(m * p); - - // allocate memory to hold all possible diagonal Taylor coefficients - // (for large sparse cases, this is not efficient) - VectorBase D(m * n); - - // boolean flag for which diagonal coefficients are computed - CppAD::vector c(n); - for(j1 = 0; j1 < n; j1++) - c[j1] = false; - - // direction vector in argument space - VectorBase dx(n); - for(j1 = 0; j1 < n; j1++) - dx[j1] = Base(0.0); - - // result vector in range space - VectorBase dy(m); - - // compute the diagonal coefficients that are needed - for(l = 0; l < p; l++) - { j1 = j[l]; - k1 = k[l]; - CPPAD_ASSERT_KNOWN( - j1 < n, - "ForTwo: an element of j not less than domain dimension for f." - ); - CPPAD_ASSERT_KNOWN( - k1 < n, - "ForTwo: an element of k not less than domain dimension for f." - ); - size_t count = 2; - while(count) - { count--; - if( ! c[j1] ) - { // diagonal term in j1 direction - c[j1] = true; - dx[j1] = Base(1.0); - Forward(1, dx); - - dx[j1] = Base(0.0); - dy = Forward(2, dx); - for(i = 0; i < m; i++) - D[i * n + j1 ] = dy[i]; - } - j1 = k1; - } - } - // compute all the requested cross partials - for(l = 0; l < p; l++) - { j1 = j[l]; - k1 = k[l]; - if( j1 == k1 ) - { for(i = 0; i < m; i++) - ddy[i * p + l] = Base(2.0) * D[i * n + j1]; - } - else - { - // cross term in j1 and k1 directions - dx[j1] = Base(1.0); - dx[k1] = Base(1.0); - Forward(1, dx); - - dx[j1] = Base(0.0); - dx[k1] = Base(0.0); - dy = Forward(2, dx); - - // place result in return value - for(i = 0; i < m; i++) - ddy[i * p + l] = dy[i] - D[i*n+j1] - D[i*n+k1]; - - } - } - return ddy; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/forward.hpp b/external/cppad/include/cppad/core/forward.hpp deleted file mode 100644 index 394af03fd..000000000 --- a/external/cppad/include/cppad/core/forward.hpp +++ /dev/null @@ -1,432 +0,0 @@ -# ifndef CPPAD_CORE_FORWARD_HPP -# define CPPAD_CORE_FORWARD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// documened after Forward but included here so easy to see -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file forward.hpp -User interface to forward mode computations. -*/ - -/*! -Multiple orders, one direction, forward mode Taylor coefficieints. - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\tparam VectorBase -is a Simple Vector class with eleements of type Base. - -\param q -is the hightest order for this forward mode computation; i.e., -after this calculation there will be q+1 -Taylor coefficients per variable. - -\param xq -contains Taylor coefficients for the independent variables. -The size of xq must either be n or (q+1)*n, -We define p = q + 1 - xq.size()/n. -For j = 0 , ... , n-1, -k = p, ... , q, are -xq[ (q+1-p)*j + k - p ] -is the k-th order coefficient for the j-th independent variable. - -\param s -Is the stream where output corresponding to PriOp operations will written. - -\return -contains Taylor coefficients for the dependent variables. -The size of the return value y is m*(q+1-p). -For i = 0, ... , m-1, -k = p, ..., q, -y[(q+1-p)*i + (k-p)] -is the k-th order coefficient for the i-th dependent variable. - -\par taylor_ -The Taylor coefficients up to order p-1 are inputs -and the coefficents from order p through q are outputs. -Let N = num_var_tape_, and -C = cap_order_taylor_. -Note that for -i = 1 , ..., N-1, -k = 0 , ..., q, -taylor_[ C*i + k ] -is the k-th order cofficent, -for the i-th varaible on the tape. -(The first independent variable has index one on the tape -and there is no variable with index zero.) -*/ - -template -template -VectorBase ADFun::Forward( - size_t q , - const VectorBase& xq , - std::ostream& s ) -{ // temporary indices - size_t i, j, k; - - // number of independent variables - size_t n = ind_taddr_.size(); - - // number of dependent variables - size_t m = dep_taddr_.size(); - - // check Vector is Simple Vector class with Base type elements - CheckSimpleVector(); - - - CPPAD_ASSERT_KNOWN( - size_t(xq.size()) == n || size_t(xq.size()) == n*(q+1), - "Forward(q, xq): xq.size() is not equal n or n*(q+1)" - ); - - // lowest order we are computing - size_t p = q + 1 - size_t(xq.size()) / n; - CPPAD_ASSERT_UNKNOWN( p == 0 || p == q ); - CPPAD_ASSERT_KNOWN( - q <= num_order_taylor_ || p == 0, - "Forward(q, xq): Number of Taylor coefficient orders stored in this" - " ADFun\nis less than q and xq.size() != n*(q+1)." - ); - CPPAD_ASSERT_KNOWN( - p <= 1 || num_direction_taylor_ == 1, - "Forward(q, xq): computing order q >= 2" - " and number of directions is not one." - "\nMust use Forward(q, r, xq) for this case" - ); - // does taylor_ need more orders or fewer directions - if( (cap_order_taylor_ <= q) | (num_direction_taylor_ != 1) ) - { if( p == 0 ) - { // no need to copy old values during capacity_order - num_order_taylor_ = 0; - } - else num_order_taylor_ = q; - size_t c = std::max(q + 1, cap_order_taylor_); - size_t r = 1; - capacity_order(c, r); - } - CPPAD_ASSERT_UNKNOWN( cap_order_taylor_ > q ); - CPPAD_ASSERT_UNKNOWN( num_direction_taylor_ == 1 ); - - // short hand notation for order capacity - size_t C = cap_order_taylor_; - - // The optimizer may skip a step that does not affect dependent variables. - // Initilaizing zero order coefficients avoids following valgrind warning: - // "Conditional jump or move depends on uninitialised value(s)". - for(j = 0; j < num_var_tape_; j++) - { for(k = p; k <= q; k++) - taylor_[C * j + k] = CppAD::numeric_limits::quiet_NaN(); - } - - // set Taylor coefficients for independent variables - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - if( p == q ) - taylor_[ C * ind_taddr_[j] + q] = xq[j]; - else - { for(k = 0; k <= q; k++) - taylor_[ C * ind_taddr_[j] + k] = xq[ (q+1)*j + k]; - } - } - - // evaluate the derivatives - CPPAD_ASSERT_UNKNOWN( cskip_op_.size() == play_.num_op_rec() ); - CPPAD_ASSERT_UNKNOWN( load_op_.size() == play_.num_load_op_rec() ); - if( q == 0 ) - { local::forward0sweep(s, true, - n, num_var_tape_, &play_, C, - taylor_.data(), cskip_op_.data(), load_op_, - compare_change_count_, - compare_change_number_, - compare_change_op_index_ - ); - } - else - { local::forward1sweep(s, true, p, q, - n, num_var_tape_, &play_, C, - taylor_.data(), cskip_op_.data(), load_op_, - compare_change_count_, - compare_change_number_, - compare_change_op_index_ - ); - } - - // return Taylor coefficients for dependent variables - VectorBase yq; - if( p == q ) - { yq.resize(m); - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - yq[i] = taylor_[ C * dep_taddr_[i] + q]; - } - } - else - { yq.resize(m * (q+1) ); - for(i = 0; i < m; i++) - { for(k = 0; k <= q; k++) - yq[ (q+1) * i + k] = - taylor_[ C * dep_taddr_[i] + k ]; - } - } -# ifndef NDEBUG - if( check_for_nan_ ) - { bool ok = true; - size_t index = m; - if( p == 0 ) - { for(i = 0; i < m; i++) - { // Visual Studio 2012, CppAD required in front of isnan ? - if( CppAD::isnan( yq[ (q+1) * i + 0 ] ) ) - { ok = false; - if( index == m ) - index = i; - } - } - } - if( ! ok ) - { CPPAD_ASSERT_UNKNOWN( index < m ); - // - CppAD::vector x0(n); - for(j = 0; j < n; j++) - x0[j] = taylor_[ C * ind_taddr_[j] + 0 ]; - std::string file_name; - put_check_for_nan(x0, file_name); - std::stringstream ss; - ss << - "yq = f.Forward(q, xq): a zero order Taylor coefficient is nan.\n" - "Corresponding independent variables vector was written " - "to binary a file.\n" - "vector_size = " << n << "\n" << - "file_name = " << file_name << "\n" << - "index = " << index << "\n"; - // ss.str() returns a string object with a copy of the current - // contents in the stream buffer. - std::string msg_str = ss.str(); - // msg_str.c_str() returns a pointer to the c-string - // representation of the string object's value. - const char* msg_char_star = msg_str.c_str(); - ErrorHandler::Call( - true, - __LINE__, - __FILE__, - "if( CppAD::isnan( yq[ (q+1) * index + 0 ] )", - msg_char_star - ); - } - CPPAD_ASSERT_KNOWN(ok, - "with the value nan." - ); - if( 0 < q ) - { for(i = 0; i < m; i++) - { for(k = p; k <= q; k++) - { // Studio 2012, CppAD required in front of isnan ? - ok &= ! CppAD::isnan( yq[ (q+1-p)*i + k-p ] ); - } - } - } - CPPAD_ASSERT_KNOWN(ok, - "yq = f.Forward(q, xq): has a non-zero order Taylor coefficient\n" - "with the value nan (but zero order coefficients are not nan)." - ); - } -# endif - - // now we have q + 1 taylor_ coefficient orders per variable - num_order_taylor_ = q + 1; - - return yq; -} - -/*! -One order, multiple directions, forward mode Taylor coefficieints. - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\tparam VectorBase -is a Simple Vector class with eleements of type Base. - -\param q -is the order for this forward mode computation, -q > 0. -There must be at least q Taylor coefficients -per variable before this call. -After this call there will be q+1 -Taylor coefficients per variable. - -\param r -is the number of directions for this calculation. -If q != 1, \c r must be the same as in the previous -call to Forward where \c q was equal to one. - -\param xq -contains Taylor coefficients for the independent variables. -The size of xq must either be r*n, -For j = 0 , ... , n-1, -ell = 0, ... , r-1, -xq[ ( r*j + ell ] -is the q-th order coefficient for the j-th independent variable -and the ell-th direction. - -\return -contains Taylor coefficients for the dependent variables. -The size of the return value \c y is r*m. -For i = 0, ... , m-1, -ell = 0, ... , r-1, -y[ r*i + ell ] -is the q-th order coefficient for the i-th dependent variable -and the ell-th direction. - -\par taylor_ -The Taylor coefficients up to order q-1 are inputs -and the coefficents of order \c q are outputs. -Let N = num_var_tape_, and -C = cap_order_taylor_. -Note that for -i = 1 , ..., N-1, -taylor_[ (C-1)*r*i + i + 0 ] -is the zero order cofficent, -for the i-th varaible, and all directions. -For i = 1 , ..., N-1, -k = 1 , ..., q, -ell = 0 , ..., r-1, -taylor_[ (C-1)*r*i + i + (k-1)*r + ell + 1 ] -is the k-th order cofficent, -for the i-th varaible, and ell-th direction. -(The first independent variable has index one on the tape -and there is no variable with index zero.) -*/ - -template -template -VectorBase ADFun::Forward( - size_t q , - size_t r , - const VectorBase& xq ) -{ // temporary indices - size_t i, j, ell; - - // number of independent variables - size_t n = ind_taddr_.size(); - - // number of dependent variables - size_t m = dep_taddr_.size(); - - // check Vector is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( q > 0, "Forward(q, r, xq): q == 0" ); - CPPAD_ASSERT_KNOWN( - size_t(xq.size()) == r * n, - "Forward(q, r, xq): xq.size() is not equal r * n" - ); - CPPAD_ASSERT_KNOWN( - q <= num_order_taylor_ , - "Forward(q, r, xq): Number of Taylor coefficient orders stored in" - " this ADFun is less than q" - ); - CPPAD_ASSERT_KNOWN( - q == 1 || num_direction_taylor_ == r , - "Forward(q, r, xq): q > 1 and number of Taylor directions r" - " is not same as previous Forward(1, r, xq)" - ); - - // does taylor_ need more orders or new number of directions - if( cap_order_taylor_ <= q || num_direction_taylor_ != r ) - { if( num_direction_taylor_ != r ) - num_order_taylor_ = 1; - - size_t c = std::max(q + 1, cap_order_taylor_); - capacity_order(c, r); - } - CPPAD_ASSERT_UNKNOWN( cap_order_taylor_ > q ); - CPPAD_ASSERT_UNKNOWN( num_direction_taylor_ == r ) - - // short hand notation for order capacity - size_t c = cap_order_taylor_; - - // set Taylor coefficients for independent variables - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - for(ell = 0; ell < r; ell++) - { size_t index = ((c-1)*r + 1)*ind_taddr_[j] + (q-1)*r + ell + 1; - taylor_[ index ] = xq[ r * j + ell ]; - } - } - - // evaluate the derivatives - CPPAD_ASSERT_UNKNOWN( cskip_op_.size() == play_.num_op_rec() ); - CPPAD_ASSERT_UNKNOWN( load_op_.size() == play_.num_load_op_rec() ); - local::forward2sweep( - q, - r, - n, - num_var_tape_, - &play_, - c, - taylor_.data(), - cskip_op_.data(), - load_op_ - ); - - // return Taylor coefficients for dependent variables - VectorBase yq; - yq.resize(r * m); - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - for(ell = 0; ell < r; ell++) - { size_t index = ((c-1)*r + 1)*dep_taddr_[i] + (q-1)*r + ell + 1; - yq[ r * i + ell ] = taylor_[ index ]; - } - } -# ifndef NDEBUG - if( check_for_nan_ ) - { bool ok = true; - for(i = 0; i < m; i++) - { for(ell = 0; ell < r; ell++) - { // Studio 2012, CppAD required in front of isnan ? - ok &= ! CppAD::isnan( yq[ r * i + ell ] ); - } - } - CPPAD_ASSERT_KNOWN(ok, - "yq = f.Forward(q, r, xq): has a non-zero order Taylor coefficient\n" - "with the value nan (but zero order coefficients are not nan)." - ); - } -# endif - - // now we have q + 1 taylor_ coefficient orders per variable - num_order_taylor_ = q + 1; - - return yq; -} - - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/fun_check.hpp b/external/cppad/include/cppad/core/fun_check.hpp deleted file mode 100644 index 6cc364e9d..000000000 --- a/external/cppad/include/cppad/core/fun_check.hpp +++ /dev/null @@ -1,210 +0,0 @@ -# ifndef CPPAD_CORE_FUN_CHECK_HPP -# define CPPAD_CORE_FUN_CHECK_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin FunCheck$$ -$spell - exp - bool - const - Taylor -$$ - - -$section Check an ADFun Sequence of Operations$$ - -$head Syntax$$ -$icode%ok% = FunCheck(%f%, %g%, %x%, %r%, %a%)%$$ -$pre -$$ -$bold See Also$$ -$cref CompareChange$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -We use $latex G : B^n \rightarrow B^m$$ to denote the -function corresponding to the C++ function object $icode g$$. -This routine check if -$latex \[ - F(x) = G(x) -\]$$ -If $latex F(x) \neq G(x)$$, the -$cref/operation sequence/glossary/Operation/Sequence/$$ -corresponding to $icode f$$ does not represents the algorithm used -by $icode g$$ to calculate values for $latex G$$ -(see $cref/Discussion/FunCheck/Discussion/$$ below). - -$head f$$ -The $code FunCheck$$ argument $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/Forward/FunCheck/FunCheck Uses Forward/$$ below). - -$head g$$ -The $code FunCheck$$ argument $icode g$$ has prototype -$codei% - %Fun% &%g% -%$$ -($icode Fun$$ is defined the properties of $icode g$$). -The C++ function object $icode g$$ supports the syntax -$codei% - %y% = %g%(%x%) -%$$ -which computes $latex y = G(x)$$. - -$subhead x$$ -The $icode g$$ argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -(see $cref/Vector/FunCheck/Vector/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. - -$head y$$ -The $icode g$$ result $icode y$$ has prototype -$codei% - %Vector% %y% -%$$ -and its value is $latex G(x)$$. -The size of $icode y$$ -is equal to $icode m$$, the dimension of the -$cref/range/seq_property/Range/$$ space for $icode f$$. - -$head x$$ -The $code FunCheck$$ argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -This specifies that point at which to compare the values -calculated by $icode f$$ and $icode G$$. - -$head r$$ -The $code FunCheck$$ argument $icode r$$ has prototype -$codei% - const %Base% &%r% -%$$ -It specifies the relative error the element by element -comparison of the value of $latex F(x)$$ and $latex G(x)$$. - -$head a$$ -The $code FunCheck$$ argument $icode a$$ has prototype -$codei% - const %Base% &%a% -%$$ -It specifies the absolute error the element by element -comparison of the value of $latex F(x)$$ and $latex G(x)$$. - -$head ok$$ -The $code FunCheck$$ result $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -It is true, if for $latex i = 0 , \ldots , m-1$$ -either the relative error bound is satisfied -$latex \[ -| F_i (x) - G_i (x) | -\leq -r ( | F_i (x) | + | G_i (x) | ) -\] $$ -or the absolute error bound is satisfied -$latex \[ - | F_i (x) - G_i (x) | \leq a -\] $$ -It is false if for some $latex (i, j)$$ neither -of these bounds is satisfied. - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head FunCheck Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After $code FunCheck$$, -the previous calls to $cref Forward$$ are undefined. - -$head Discussion$$ -Suppose that the algorithm corresponding to $icode g$$ contains -$codei% - if( %x% >= 0 ) - %y% = exp(%x%) - else %y% = exp(-%x%) -%$$ -where $icode x$$ and $icode y$$ are $codei%AD%$$ objects. -It follows that the -AD of $code double$$ $cref/operation sequence/glossary/Operation/Sequence/$$ -depends on the value of $icode x$$. -If the sequence of operations stored in $icode f$$ corresponds to -$icode g$$ with $latex x \geq 0$$, -the function values computed using $icode f$$ when $latex x < 0$$ -will not agree with the function values computed by $latex g$$. -This is because the operation sequence corresponding to $icode g$$ changed -(and hence the object $icode f$$ does not represent the function -$latex G$$ for this value of $icode x$$). -In this case, you probably want to re-tape the calculations -performed by $icode g$$ with the -$cref/independent variables/glossary/Tape/Independent Variable/$$ -equal to the values in $icode x$$ -(so AD operation sequence properly represents the algorithm -for this value of independent variables). - - -$head Example$$ -$children% - example/general/fun_check.cpp -%$$ -The file -$cref fun_check.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end ---------------------------------------------------------------------------- -*/ - -namespace CppAD { - template - bool FunCheck( - ADFun &f , - Fun &g , - const Vector &x , - const Base &r , - const Base &a ) - { bool ok = true; - - size_t m = f.Range(); - Vector yf = f.Forward(0, x); - Vector yg = g(x); - - size_t i; - for(i = 0; i < m; i++) - ok &= NearEqual(yf[i], yg[i], r, a); - return ok; - } -} - -# endif diff --git a/external/cppad/include/cppad/core/fun_construct.hpp b/external/cppad/include/cppad/core/fun_construct.hpp deleted file mode 100644 index d80ad2897..000000000 --- a/external/cppad/include/cppad/core/fun_construct.hpp +++ /dev/null @@ -1,488 +0,0 @@ -# ifndef CPPAD_CORE_FUN_CONSTRUCT_HPP -# define CPPAD_CORE_FUN_CONSTRUCT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin FunConstruct$$ -$spell - alloc - num - Jac - bool - taylor - var - ADvector - const - Jacobian -$$ - -$spell -$$ - -$section Construct an ADFun Object and Stop Recording$$ -$mindex tape$$ - - -$head Syntax$$ -$codei%ADFun<%Base%> %f%, %g% -%$$ -$codei%ADFun<%Base%> %f%(%x%, %y%) -%$$ -$icode%g% = %f% -%$$ - - -$head Purpose$$ -The $codei%AD<%Base%>%$$ object $icode f$$ can -store an AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. -It can then be used to calculate derivatives of the corresponding -$cref/AD function/glossary/AD Function/$$ -$latex \[ - F : B^n \rightarrow B^m -\] $$ -where $latex B$$ is the space corresponding to objects of type $icode Base$$. - -$head x$$ -If the argument $icode x$$ is present, it has prototype -$codei% - const %VectorAD% &%x% -%$$ -It must be the vector argument in the previous call to -$cref Independent$$. -Neither its size, or any of its values, are allowed to change -between calling -$codei% - Independent(%x%) -%$$ -and -$codei% - ADFun<%Base%> %f%(%x%, %y%) -%$$ - -$head y$$ -If the argument $icode y$$ is present, it has prototype -$codei% - const %VectorAD% &%y% -%$$ -The sequence of operations that map $icode x$$ -to $icode y$$ are stored in the ADFun object $icode f$$. - -$head VectorAD$$ -The type $icode VectorAD$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$codei%AD<%Base%>%$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Default Constructor$$ -The default constructor -$codei% - ADFun<%Base%> %f% -%$$ -creates an -$codei%AD<%Base%>%$$ object with no corresponding operation sequence; i.e., -$codei% - %f%.size_var() -%$$ -returns the value zero (see $cref/size_var/seq_property/size_var/$$). - -$head Sequence Constructor$$ -The sequence constructor -$codei% - ADFun<%Base%> %f%(%x%, %y%) -%$$ -creates the $codei%AD<%Base%>%$$ object $icode f$$, -stops the recording of AD of $icode Base$$ operations -corresponding to the call -$codei% - Independent(%x%) -%$$ -and stores the corresponding operation sequence in the object $icode f$$. -It then stores the zero order Taylor coefficients -(corresponding to the value of $icode x$$) in $icode f$$. -This is equivalent to the following steps using the default constructor: - -$list number$$ -Create $icode f$$ with the default constructor -$codei% - ADFun<%Base%> %f%; -%$$ -$lnext -Stop the tape and storing the operation sequence using -$codei% - %f%.Dependent(%x%, %y%); -%$$ -(see $cref Dependent$$). -$lnext -Calculate the zero order Taylor coefficients for all -the variables in the operation sequence using -$codei% - %f%.Forward(%p%, %x_p%) -%$$ -with $icode p$$ equal to zero and the elements of $icode x_p$$ -equal to the corresponding elements of $icode x$$ -(see $cref Forward$$). -$lend - -$head Copy Constructor$$ -It is an error to attempt to use the $codei%ADFun<%Base%>%$$ copy constructor; -i.e., the following syntax is not allowed: -$codei% - ADFun<%Base%> %g%(%f%) -%$$ -where $icode f$$ is an $codei%ADFun<%Base%>%$$ object. -Use its $cref/default constructor/FunConstruct/Default Constructor/$$ instead -and its assignment operator. - -$head Assignment Operator$$ -The $codei%ADFun<%Base%>%$$ assignment operation -$codei% - %g% = %f% -%$$ -makes a copy of the operation sequence currently stored in $icode f$$ -in the object $icode g$$. -The object $icode f$$ is not affected by this operation and -can be $code const$$. -All of information (state) stored in $icode f$$ is copied to $icode g$$ -and any information originally in $icode g$$ is lost. - -$subhead Taylor Coefficients$$ -The Taylor coefficient information currently stored in $icode f$$ -(computed by $cref/f.Forward/Forward/$$) is -copied to $icode g$$. -Hence, directly after this operation -$codei% - %g%.size_order() == %f%.size_order() -%$$ - -$subhead Sparsity Patterns$$ -The forward Jacobian sparsity pattern currently stored in $icode f$$ -(computed by $cref/f.ForSparseJac/ForSparseJac/$$) is -copied to $icode g$$. -Hence, directly after this operation -$codei% - %g%.size_forward_bool() == %f%.size_forward_bool() - %g%.size_forward_set() == %f%.size_forward_set() -%$$ - -$head Parallel Mode$$ -The call to $code Independent$$, -and the corresponding call to -$codei% - ADFun<%Base%> %f%( %x%, %y%) -%$$ -or -$codei% - %f%.Dependent( %x%, %y%) -%$$ -or $cref abort_recording$$, -must be preformed by the same thread; i.e., -$cref/thread_alloc::thread_num/ta_thread_num/$$ must be the same. - -$head Example$$ - -$subhead Sequence Constructor$$ -The file -$cref independent.cpp$$ -contains an example and test of the sequence constructor. -It returns true if it succeeds and false otherwise. - -$subhead Default Constructor$$ -The files -$cref fun_check.cpp$$ -and -$cref hes_lagrangian.cpp$$ -contain an examples and tests using the default constructor. -They return true if they succeed and false otherwise. - -$children% - example/general/fun_assign.cpp -%$$ -$subhead Assignment Operator$$ -The file -$cref fun_assign.cpp$$ -contains an example and test of the $codei%ADFun<%Base%>%$$ -assignment operator. -It returns true if it succeeds and false otherwise. - -$end ----------------------------------------------------------------------------- -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file fun_construct.hpp -ADFun function constructors and assignment operator. -*/ - -/*! -ADFun default constructor - -The C++ syntax for this operation is -\verbatim - ADFun f -\endverbatim -An empty ADFun object is created. -The Dependent member function, -or the ADFun assingment operator, -can then be used to put an operation sequence in this ADFun object. - -\tparam Base -is the base for the recording that can be stored in this ADFun object; -i.e., operation sequences that were recorded using the type \c AD. -*/ -template -ADFun::ADFun(void) : -has_been_optimized_(false), -check_for_nan_(true) , -compare_change_count_(1), -compare_change_number_(0), -compare_change_op_index_(0), -num_var_tape_(0) -{ } - -/*! -ADFun assignment operator - -The C++ syntax for this operation is -\verbatim - g = f -\endverbatim -where \c g and \c f are ADFun ADFun objects. -A copy of the the operation sequence currently stored in \c f -is placed in this ADFun object (called \c g above). -Any information currently stored in this ADFun object is lost. - -\tparam Base -is the base for the recording that can be stored in this ADFun object; -i.e., operation sequences that were recorded using the type \c AD. - -\param f -ADFun object containing the operation sequence to be copied. -*/ -template -void ADFun::operator=(const ADFun& f) -{ size_t m = f.Range(); - size_t n = f.Domain(); - size_t i; - - // go through member variables in ad_fun.hpp order - // - // size_t objects - has_been_optimized_ = f.has_been_optimized_; - check_for_nan_ = f.check_for_nan_; - compare_change_count_ = f.compare_change_count_; - compare_change_number_ = f.compare_change_number_; - compare_change_op_index_ = f.compare_change_op_index_; - num_order_taylor_ = f.num_order_taylor_; - cap_order_taylor_ = f.cap_order_taylor_; - num_direction_taylor_ = f.num_direction_taylor_; - num_var_tape_ = f.num_var_tape_; - // - // CppAD::vector objects - ind_taddr_.resize(n); - ind_taddr_ = f.ind_taddr_; - dep_taddr_.resize(m); - dep_taddr_ = f.dep_taddr_; - dep_parameter_.resize(m); - dep_parameter_ = f.dep_parameter_; - // - // pod_vector objects - taylor_ = f.taylor_; - cskip_op_ = f.cskip_op_; - load_op_ = f.load_op_; - // - // player - play_ = f.play_; - // - // sparse_pack - for_jac_sparse_pack_.resize(0, 0); - size_t n_set = f.for_jac_sparse_pack_.n_set(); - size_t end = f.for_jac_sparse_pack_.end(); - if( n_set > 0 ) - { CPPAD_ASSERT_UNKNOWN( n_set == num_var_tape_ ); - CPPAD_ASSERT_UNKNOWN( f.for_jac_sparse_set_.n_set() == 0 ); - for_jac_sparse_pack_.resize(n_set, end); - for(i = 0; i < num_var_tape_ ; i++) - { for_jac_sparse_pack_.assignment( - i , - i , - f.for_jac_sparse_pack_ - ); - } - } - // - // sparse_set - for_jac_sparse_set_.resize(0, 0); - n_set = f.for_jac_sparse_set_.n_set(); - end = f.for_jac_sparse_set_.end(); - if( n_set > 0 ) - { CPPAD_ASSERT_UNKNOWN( n_set == num_var_tape_ ); - CPPAD_ASSERT_UNKNOWN( f.for_jac_sparse_pack_.n_set() == 0 ); - for_jac_sparse_set_.resize(n_set, end); - for(i = 0; i < num_var_tape_; i++) - { for_jac_sparse_set_.assignment( - i , - i , - f.for_jac_sparse_set_ - ); - } - } -} - -/*! -ADFun constructor from an operation sequence. - -The C++ syntax for this operation is -\verbatim - ADFun f(x, y) -\endverbatim -The operation sequence that started with the previous call -\c Independent(x), and that ends with this operation, is stored -in this \c ADFun object \c f. - -\tparam Base -is the base for the recording that will be stored in the object \c f; -i.e., the operations were recorded using the type \c AD. - -\tparam VectorAD -is a simple vector class with elements of typea \c AD. - -\param x -is the independent variable vector for this ADFun object. -The domain dimension of this object will be the size of \a x. - -\param y -is the dependent variable vector for this ADFun object. -The range dimension of this object will be the size of \a y. - -\par Taylor Coefficients -A zero order forward mode sweep is done, -and if NDEBUG is not defined the resulting values for the -depenedent variables are checked against the values in \a y. -Thus, the zero order Taylor coefficients -corresponding to the value of the \a x vector -are stored in this ADFun object. -*/ -template -template -ADFun::ADFun(const VectorAD &x, const VectorAD &y) -{ - CPPAD_ASSERT_KNOWN( - x.size() > 0, - "ADFun: independent variable vector has size zero." - ); - CPPAD_ASSERT_KNOWN( - Variable(x[0]), - "ADFun: independent variable vector has been changed." - ); - local::ADTape* tape = AD::tape_ptr(x[0].tape_id_); - CPPAD_ASSERT_KNOWN( - tape->size_independent_ == size_t ( x.size() ), - "ADFun: independent variable vector has been changed." - ); - size_t j, n = x.size(); -# ifndef NDEBUG - size_t i, m = y.size(); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_KNOWN( - size_t(x[j].taddr_) == (j+1), - "ADFun: independent variable vector has been changed." - ); - CPPAD_ASSERT_KNOWN( - x[j].tape_id_ == x[0].tape_id_, - "ADFun: independent variable vector has been changed." - ); - } - for(i = 0; i < m; i++) - { CPPAD_ASSERT_KNOWN( - CppAD::Parameter( y[i] ) | (y[i].tape_id_ == x[0].tape_id_) , - "ADFun: dependent vector contains variables for" - "\na different tape than the independent variables." - ); - } -# endif - - // stop the tape and store the operation sequence - Dependent(tape, y); - - - // ad_fun.hpp member values not set by dependent - check_for_nan_ = true; - - // allocate memory for one zero order taylor_ coefficient - CPPAD_ASSERT_UNKNOWN( num_order_taylor_ == 0 ); - CPPAD_ASSERT_UNKNOWN( num_direction_taylor_ == 0 ); - size_t c = 1; - size_t r = 1; - capacity_order(c, r); - CPPAD_ASSERT_UNKNOWN( cap_order_taylor_ == c ); - CPPAD_ASSERT_UNKNOWN( num_direction_taylor_ == r ); - - // set zero order coefficients corresponding to indpendent variables - CPPAD_ASSERT_UNKNOWN( n == ind_taddr_.size() ); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) ); - CPPAD_ASSERT_UNKNOWN( size_t(x[j].taddr_) == (j+1) ); - taylor_[ ind_taddr_[j] ] = x[j].value_; - } - - // use independent variable values to fill in values for others - CPPAD_ASSERT_UNKNOWN( cskip_op_.size() == play_.num_op_rec() ); - CPPAD_ASSERT_UNKNOWN( load_op_.size() == play_.num_load_op_rec() ); - local::forward0sweep(std::cout, false, - n, num_var_tape_, &play_, cap_order_taylor_, taylor_.data(), - cskip_op_.data(), load_op_, - compare_change_count_, - compare_change_number_, - compare_change_op_index_ - ); - CPPAD_ASSERT_UNKNOWN( compare_change_count_ == 1 ); - CPPAD_ASSERT_UNKNOWN( compare_change_number_ == 0 ); - CPPAD_ASSERT_UNKNOWN( compare_change_op_index_ == 0 ); - - // now set the number of orders stored - num_order_taylor_ = 1; - -# ifndef NDEBUG - // on MS Visual Studio 2012, CppAD required in front of isnan ? - for(i = 0; i < m; i++) - if( taylor_[dep_taddr_[i]] != y[i].value_ || CppAD::isnan( y[i].value_ ) ) - { using std::endl; - std::ostringstream buf; - buf << "A dependent variable value is not equal to " - << "its tape evaluation value," << endl - << "perhaps it is nan." << endl - << "Dependent variable value = " - << y[i].value_ << endl - << "Tape evaluation value = " - << taylor_[dep_taddr_[i]] << endl - << "Difference = " - << y[i].value_ - taylor_[dep_taddr_[i]] << endl - ; - // buf.str() returns a string object with a copy of the current - // contents in the stream buffer. - std::string msg_str = buf.str(); - // msg_str.c_str() returns a pointer to the c-string - // representation of the string object's value. - const char* msg_char_star = msg_str.c_str(); - CPPAD_ASSERT_KNOWN( - 0, - msg_char_star - ); - } -# endif -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/fun_eval.hpp b/external/cppad/include/cppad/core/fun_eval.hpp deleted file mode 100644 index cfb8b058e..000000000 --- a/external/cppad/include/cppad/core/fun_eval.hpp +++ /dev/null @@ -1,19 +0,0 @@ -# ifndef CPPAD_CORE_FUN_EVAL_HPP -# define CPPAD_CORE_FUN_EVAL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/hash_code.hpp b/external/cppad/include/cppad/core/hash_code.hpp deleted file mode 100644 index a067b265f..000000000 --- a/external/cppad/include/cppad/core/hash_code.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_HASH_CODE_HPP -# define CPPAD_CORE_HASH_CODE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file core/hash_code.hpp -CppAD hashing utility. -*/ -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -General purpose hash code for an arbitrary value. - -\tparam Value -is the type of the argument being hash coded. -It should be a plain old data class; i.e., -the values included in the equality operator in the object and -not pointed to by the object. - -\param value -the value that we are generating a hash code for. -All of the fields in value should have been set before the hash code -is computed (otherwise undefined values are used). - -\return -is a hash code that is between zero and CPPAD_HASH_TABLE_SIZE - 1. - -\par Checked Assertions -\li \c std::numeric_limits::max() >= CPPAD_HASH_TABLE_SIZE -\li \c sizeof(value) is even -\li \c sizeof(unsigned short) == 2 -*/ -template -unsigned short hash_code(const Value& value) -{ return local::local_hash_code(value); } - -} // END_CPPAD_NAMESPACE - - -# endif diff --git a/external/cppad/include/cppad/core/hessian.hpp b/external/cppad/include/cppad/core/hessian.hpp deleted file mode 100644 index a94f90f0f..000000000 --- a/external/cppad/include/cppad/core/hessian.hpp +++ /dev/null @@ -1,214 +0,0 @@ -# ifndef CPPAD_CORE_HESSIAN_HPP -# define CPPAD_CORE_HESSIAN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Hessian$$ -$spell - hes - typename - Taylor - HesLuDet - const -$$ - - -$section Hessian: Easy Driver$$ -$mindex second derivative$$ - -$head Syntax$$ -$icode%hes% = %f%.Hessian(%x%, %w%) -%$$ -$icode%hes% = %f%.Hessian(%x%, %l%) -%$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -The syntax above sets $icode hes$$ to the Hessian -The syntax above sets $icode h$$ to the Hessian -$latex \[ - hes = \dpow{2}{x} \sum_{i=1}^m w_i F_i (x) -\] $$ -The routine $cref sparse_hessian$$ may be faster in the case -where the Hessian is sparse. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/Hessian Uses Forward/Hessian/Hessian Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -(see $cref/Vector/Hessian/Vector/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the Hessian. - -$head l$$ -If the argument $icode l$$ is present, it has prototype -$codei% - size_t %l% -%$$ -and is less than $icode m$$, the dimension of the -$cref/range/seq_property/Range/$$ space for $icode f$$. -It specifies the component of $icode F$$ -for which we are evaluating the Hessian. -To be specific, in the case where the argument $icode l$$ is present, -$latex \[ - w_i = \left\{ \begin{array}{ll} - 1 & i = l \\ - 0 & {\rm otherwise} - \end{array} \right. -\] $$ - -$head w$$ -If the argument $icode w$$ is present, it has prototype -$codei% - const %Vector% &%w% -%$$ -and size $latex m$$. -It specifies the value of $latex w_i$$ in the expression -for $icode h$$. - -$head hes$$ -The result $icode hes$$ has prototype -$codei% - %Vector% %hes% -%$$ -(see $cref/Vector/Hessian/Vector/$$ below) -and its size is $latex n * n$$. -For $latex j = 0 , \ldots , n - 1 $$ -and $latex \ell = 0 , \ldots , n - 1$$ -$latex \[ - hes [ j * n + \ell ] = \DD{ w^{\rm T} F }{ x_j }{ x_\ell } ( x ) -\] $$ - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Hessian Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code Hessian$$, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -$head Example$$ -$children% - example/general/hessian.cpp% - example/general/hes_lagrangian.cpp -%$$ -The routines -$cref hessian.cpp$$ and -$cref hes_lagrangian.cpp$$ -are examples and tests of $code Hessian$$. -They return $code true$$, if they succeed and $code false$$ otherwise. - - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -template -Vector ADFun::Hessian(const Vector &x, size_t l) -{ size_t i, m = Range(); - CPPAD_ASSERT_KNOWN( - l < m, - "Hessian: index i is not less than range dimension for f" - ); - - Vector w(m); - for(i = 0; i < m; i++) - w[i] = Base(0.0); - w[l] = Base(1.0); - - return Hessian(x, w); -} - - -template -template -Vector ADFun::Hessian(const Vector &x, const Vector &w) -{ size_t j; - size_t k; - - size_t n = Domain(); - - // check Vector is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n, - "Hessian: length of x not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - size_t(w.size()) == Range(), - "Hessian: length of w not equal range dimension for f" - ); - - // point at which we are evaluating the Hessian - Forward(0, x); - - // define the return value - Vector hes(n * n); - - // direction vector for calls to forward - Vector u(n); - for(j = 0; j < n; j++) - u[j] = Base(0.0); - - - // location for return values from Reverse - Vector ddw(n * 2); - - // loop over forward directions - for(j = 0; j < n; j++) - { // evaluate partials of entire function w.r.t. j-th coordinate - u[j] = Base(1.0); - Forward(1, u); - u[j] = Base(0.0); - - // evaluate derivative of partial corresponding to F_i - ddw = Reverse(2, w); - - // return desired components - for(k = 0; k < n; k++) - hes[k * n + j] = ddw[k * 2 + 1]; - } - - return hes; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/identical.hpp b/external/cppad/include/cppad/core/identical.hpp deleted file mode 100644 index 31ed8ea55..000000000 --- a/external/cppad/include/cppad/core/identical.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_IDENTICAL_HPP -# define CPPAD_CORE_IDENTICAL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file identical.hpp -Check if certain properties is true for any possible AD tape play back. -*/ - -// --------------------------------------------------------------------------- -/*! -Determine if an AD object is a parameter, and could never have -a different value during any tape playback. - -An AD object \c x is identically a parameter if and only if -all of the objects in the following chain are parameters: -\code - x , x.value , x.value.value , ... -\endcode -In such a case, the value of the object will always be the same -no matter what the independent variable values are at any level. - -\param x -values that we are checking for identically a pamameter. - -\return -returns true iff \c x is identically a parameter. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool IdenticalPar(const AD &x) -{ return Parameter(x) && IdenticalPar(x.value_); } -// Zero ============================================================== -/*! -Determine if an AD is equal to zero, -and must be equal zero during any tape playback. - -\param x -object that we are checking. - -\return -returns true if and only if -\c x is equals zero and is identically a parameter \ref CppAD::IdenticalPar. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool IdenticalZero(const AD &x) -{ return Parameter(x) && IdenticalZero(x.value_); } -// One ============================================================== -/*! -Determine if an AD is equal to one, -and must be equal one during any tape playback. - -\param x -object that we are checking. - -\return -returns true if and only if -\c x is equals one and is identically a parameter \ref CppAD::IdenticalPar. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool IdenticalOne(const AD &x) -{ return Parameter(x) && IdenticalOne(x.value_); } -// Equal =================================================================== -/*! -Determine if two AD objects are equal, -and must be equal during any tape playback. - -\param x -first of two objects we are checking for equal. - -\param y -second of two objects we are checking for equal. - -\return -returns true if and only if -the arguments are equal and both identically parameters \ref CppAD::IdenticalPar. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool IdenticalEqualPar -(const AD &x, const AD &y) -{ bool parameter; - parameter = ( Parameter(x) & Parameter(y) ); - return parameter && IdenticalEqualPar(x.value_, y.value_); -} -// ========================================================================== - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/independent.hpp b/external/cppad/include/cppad/core/independent.hpp deleted file mode 100644 index 5bfd9cf75..000000000 --- a/external/cppad/include/cppad/core/independent.hpp +++ /dev/null @@ -1,175 +0,0 @@ -# ifndef CPPAD_CORE_INDEPENDENT_HPP -# define CPPAD_CORE_INDEPENDENT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* ---------------------------------------------------------------------------- - -$begin Independent$$ -$spell - op - alloc - num - Cpp - bool - const - var - typename -$$ - -$section Declare Independent Variables and Start Recording$$ - -$head Syntax$$ -$codei%Independent(%x%) -%$$ -$codei%Independent(%x%, %abort_op_index%) -%$$ - -$head Purpose$$ -Start recording -$cref/AD of Base/glossary/AD of Base/$$ operations -with $icode x$$ as the independent variable vector. -Once the -$cref/operation sequence/glossary/Operation/Sequence/$$ is completed, -it must be transferred to a function object; see below. - -$head Start Recording$$ -An operation sequence recording is started by the commands -$codei% - Independent(%x%) - Independent(%x%, %abort_op_index%) -%$$ - -$head Stop Recording$$ -The recording is stopped, -and the operation sequence is transferred to the AD function object $icode f$$, -using either the $cref/function constructor/FunConstruct/$$ -$codei% - ADFun<%Base%> %f%(%x%, %y%) -%$$ -or the $cref/dependent variable specifier/Dependent/$$ -$codei% - %f%.Dependent(%x%, %y%) -%$$ -The only other way to stop a recording is using -$cref abort_recording$$. -Between when the recording is started and when it stopped, -we refer to the elements of $icode x$$, -and the values that depend on the elements of $icode x$$, -as $codei%AD<%Base%>%$$ variables. - -$head x$$ -The vector $icode x$$ has prototype -$codei% - %VectorAD% &%x% -%$$ -(see $icode VectorAD$$ below). -The size of the vector $icode x$$, must be greater than zero, -and is the number of independent variables for this -AD operation sequence. - -$head abort_op_index$$ -It specifies the operator index at which the execution is be aborted -by calling the CppAD $cref/error handler/ErrorHandler/$$. -When this error handler leads to an assert, the user -can inspect the call stack to see the source code corresponding to -this operator index; see -$cref/purpose/compare_change/op_index/Purpose/$$. -No abort will occur if $icode abort_op_index$$ is zero, -of if $cref/NDEBUG/Faq/Speed/NDEBUG/$$ is defined. - -$head VectorAD$$ -The type $icode VectorAD$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$codei%AD<%Base%>%$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Parallel Mode$$ -Each thread can have one, and only one, active recording. -A call to $code Independent$$ starts the recording for the current thread. -The recording must be stopped by a corresponding call to -$codei% - ADFun<%Base%> %f%( %x%, %y%) -%$$ -or -$codei% - %f%.Dependent( %x%, %y%) -%$$ -or $cref abort_recording$$ -preformed by the same thread; i.e., -$cref/thread_alloc::thread_num/ta_thread_num/$$ must be the same. - -$head Example$$ -$children% - example/general/independent.cpp -%$$ -The file -$cref independent.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -/*! -\file core/independent.hpp -Declare the independent variables -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -Declaration of independent variables. - -\tparam VectorAD -This is simple vector type with elements of type AD. - -\param x -Vector of the independent variablerd. - -\param abort_op_index -operator index at which execution will be aborted (during the recording -of operations). The value zero corresponds to not aborting (will not match). -*/ -template -inline void Independent(VectorAD &x, size_t abort_op_index) -{ typedef typename VectorAD::value_type ADBase; - typedef typename ADBase::value_type Base; - CPPAD_ASSERT_KNOWN( - ADBase::tape_ptr() == CPPAD_NULL, - "Independent: cannot create a new tape because\n" - "a previous tape is still active (for this thread).\n" - "AD::abort_recording() would abort this previous recording." - ); - local::ADTape* tape = ADBase::tape_manage(tape_manage_new); - tape->Independent(x, abort_op_index); -} -/*! -Declaration of independent variables without abort option. - -\tparam VectorAD -This is simple vector type with elements of type AD. - -\param x -Vector of the independent variablerd. -*/ -template -inline void Independent(VectorAD &x) -{ size_t abort_op_index = 0; - Independent(x, abort_op_index); -} - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/integer.hpp b/external/cppad/include/cppad/core/integer.hpp deleted file mode 100644 index 0f920b406..000000000 --- a/external/cppad/include/cppad/core/integer.hpp +++ /dev/null @@ -1,112 +0,0 @@ -# ifndef CPPAD_CORE_INTEGER_HPP -# define CPPAD_CORE_INTEGER_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- -$begin Integer$$ -$spell - std - VecAD - CppAD - namespace - const - bool -$$ - - - -$section Convert From AD to Integer$$ - -$head Syntax$$ -$icode%i% = Integer(%x%)%$$ - - -$head Purpose$$ -Converts from an AD type to the corresponding integer value. - -$head i$$ -The result $icode i$$ has prototype -$codei% - int %i% -%$$ - -$head x$$ - -$subhead Real Types$$ -If the argument $icode x$$ has either of the following prototypes: -$codei% - const float %% &%x% - const double %% &%x% -%$$ -the fractional part is dropped to form the integer value. -For example, if $icode x$$ is 1.5, $icode i$$ is 1. -In general, if $latex x \geq 0$$, $icode i$$ is the -greatest integer less than or equal $icode x$$. -If $latex x \leq 0$$, $icode i$$ is the -smallest integer greater than or equal $icode x$$. - -$subhead Complex Types$$ -If the argument $icode x$$ has either of the following prototypes: -$codei% - const std::complex %% &%x% - const std::complex %% &%x% -%$$ -The result $icode i$$ is given by -$codei% - %i% = Integer(%x%.real()) -%$$ - -$subhead AD Types$$ -If the argument $icode x$$ has either of the following prototypes: -$codei% - const AD<%Base%> &%x% - const VecAD<%Base%>::reference &%x% -%$$ -$icode Base$$ must support the $code Integer$$ function and -the conversion has the same meaning as for $icode Base$$. - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/integer.cpp -%$$ -The file -$cref integer.cpp$$ -contains an example and test of this operation. - -$end ------------------------------------------------------------------------------- -*/ - - -namespace CppAD { - - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - int Integer(const AD &x) - { return Integer(x.value_); } - - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - int Integer(const VecAD_reference &x) - { return Integer( x.ADBase() ); } -} -# endif - diff --git a/external/cppad/include/cppad/core/jacobian.hpp b/external/cppad/include/cppad/core/jacobian.hpp deleted file mode 100644 index 75e91d507..000000000 --- a/external/cppad/include/cppad/core/jacobian.hpp +++ /dev/null @@ -1,233 +0,0 @@ -# ifndef CPPAD_CORE_JACOBIAN_HPP -# define CPPAD_CORE_JACOBIAN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Jacobian$$ -$spell - jac - typename - Taylor - Jacobian - DetLu - const -$$ - - -$section Jacobian: Driver Routine$$ -$mindex Jacobian first derivative$$ - -$head Syntax$$ -$icode%jac% = %f%.Jacobian(%x%)%$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -The syntax above sets $icode jac$$ to the -Jacobian of $icode F$$ evaluated at $icode x$$; i.e., -$latex \[ - jac = F^{(1)} (x) -\] $$ - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/Forward or Reverse/Jacobian/Forward or Reverse/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -(see $cref/Vector/Jacobian/Vector/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the Jacobian. - -$head jac$$ -The result $icode jac$$ has prototype -$codei% - %Vector% %jac% -%$$ -(see $cref/Vector/Jacobian/Vector/$$ below) -and its size is $latex m * n$$; i.e., the product of the -$cref/domain/seq_property/Domain/$$ -and -$cref/range/seq_property/Range/$$ -dimensions for $icode f$$. -For $latex i = 0 , \ldots , m - 1 $$ -and $latex j = 0 , \ldots , n - 1$$ -$latex \[. - jac[ i * n + j ] = \D{ F_i }{ x_j } ( x ) -\] $$ - - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Forward or Reverse$$ -This will use order zero Forward mode and either -order one Forward or order one Reverse to compute the Jacobian -(depending on which it estimates will require less work). -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code Jacobian$$, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -$head Example$$ -$children% - example/general/jacobian.cpp -%$$ -The routine -$cref/Jacobian/jacobian.cpp/$$ is both an example and test. -It returns $code true$$, if it succeeds and $code false$$ otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -void JacobianFor(ADFun &f, const Vector &x, Vector &jac) -{ size_t i; - size_t j; - - size_t n = f.Domain(); - size_t m = f.Range(); - - // check Vector is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_UNKNOWN( size_t(x.size()) == f.Domain() ); - CPPAD_ASSERT_UNKNOWN( size_t(jac.size()) == f.Range() * f.Domain() ); - - // argument and result for forward mode calculations - Vector u(n); - Vector v(m); - - // initialize all the components - for(j = 0; j < n; j++) - u[j] = Base(0.0); - - // loop through the different coordinate directions - for(j = 0; j < n; j++) - { // set u to the j-th coordinate direction - u[j] = Base(1.0); - - // compute the partial of f w.r.t. this coordinate direction - v = f.Forward(1, u); - - // reset u to vector of all zeros - u[j] = Base(0.0); - - // return the result - for(i = 0; i < m; i++) - jac[ i * n + j ] = v[i]; - } -} -template -void JacobianRev(ADFun &f, const Vector &x, Vector &jac) -{ size_t i; - size_t j; - - size_t n = f.Domain(); - size_t m = f.Range(); - - CPPAD_ASSERT_UNKNOWN( size_t(x.size()) == f.Domain() ); - CPPAD_ASSERT_UNKNOWN( size_t(jac.size()) == f.Range() * f.Domain() ); - - // argument and result for reverse mode calculations - Vector u(n); - Vector v(m); - - // initialize all the components - for(i = 0; i < m; i++) - v[i] = Base(0.0); - - // loop through the different coordinate directions - for(i = 0; i < m; i++) - { if( f.Parameter(i) ) - { // return zero for this component of f - for(j = 0; j < n; j++) - jac[ i * n + j ] = Base(0.0); - } - else - { - // set v to the i-th coordinate direction - v[i] = Base(1.0); - - // compute the derivative of this component of f - u = f.Reverse(1, v); - - // reset v to vector of all zeros - v[i] = Base(0.0); - - // return the result - for(j = 0; j < n; j++) - jac[ i * n + j ] = u[j]; - } - } -} - -template -template -Vector ADFun::Jacobian(const Vector &x) -{ size_t i; - size_t n = Domain(); - size_t m = Range(); - - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n, - "Jacobian: length of x not equal domain dimension for F" - ); - - // point at which we are evaluating the Jacobian - Forward(0, x); - - // work factor for forward mode - size_t workForward = n; - - // work factor for reverse mode - size_t workReverse = 0; - for(i = 0; i < m; i++) - { if( ! Parameter(i) ) - ++workReverse; - } - - // choose the method with the least work - Vector jac( n * m ); - if( workForward <= workReverse ) - JacobianFor(*this, x, jac); - else JacobianRev(*this, x, jac); - - return jac; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/log1p.hpp b/external/cppad/include/cppad/core/log1p.hpp deleted file mode 100644 index 78ac0a6bf..000000000 --- a/external/cppad/include/cppad/core/log1p.hpp +++ /dev/null @@ -1,91 +0,0 @@ -# ifndef CPPAD_CORE_LOG1P_HPP -# define CPPAD_CORE_LOG1P_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin log1p$$ -$spell - CppAD -$$ - -$section The Logarithm of One Plus Argument: log1p$$ - -$head Syntax$$ -$icode%y% = log1p(%x%)%$$ - -$head Description$$ -Returns the value of the logarithm of one plus argument which is defined -by $icode%y% == log(1 + %x%)%$$. - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head CPPAD_USE_CPLUSPLUS_2011$$ - -$subhead true$$ -If this preprocessor symbol is true ($code 1$$), -and $icode x$$ is an AD type, -this is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$subhead false$$ -If this preprocessor symbol is false ($code 0$$), -CppAD uses the representation -$latex \[ -\R{log1p} (x) = \log(1 + x) -\] $$ -to compute this function. - -$head Example$$ -$children% - example/general/log1p.cpp -%$$ -The file -$cref log1p.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ -# include -# if ! CPPAD_USE_CPLUSPLUS_2011 - -// BEGIN CppAD namespace -namespace CppAD { - -template -Type log1p_template(const Type &x) -{ return CppAD::log(Type(1) + x); -} - -inline float log1p(const float &x) -{ return log1p_template(x); } - -inline double log1p(const double &x) -{ return log1p_template(x); } - -template -inline AD log1p(const AD &x) -{ return log1p_template(x); } - -template -inline AD log1p(const VecAD_reference &x) -{ return log1p_template( x.ADBase() ); } - - -} // END CppAD namespace - -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_LOG1P_INCLUDED diff --git a/external/cppad/include/cppad/core/lu_ratio.hpp b/external/cppad/include/cppad/core/lu_ratio.hpp deleted file mode 100644 index 08cd618fd..000000000 --- a/external/cppad/include/cppad/core/lu_ratio.hpp +++ /dev/null @@ -1,337 +0,0 @@ -# ifndef CPPAD_CORE_LU_RATIO_HPP -# define CPPAD_CORE_LU_RATIO_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin LuRatio$$ -$spell - cppad.hpp - xk - Cpp - Lu - bool - const - ip - jp - std - ADvector -$$ - - -$section LU Factorization of A Square Matrix and Stability Calculation$$ -$mindex LuRatio linear equation solve$$ - -$head Syntax$$ -$code# include $$ -$pre -$$ -$icode%sign% = LuRatio(%ip%, %jp%, %LU%, %ratio%)%$$ - - -$head Description$$ -Computes an LU factorization of the matrix $icode A$$ -where $icode A$$ is a square matrix. -A measure of the numerical stability called $icode ratio$$ is calculated. -This ratio is useful when the results of $code LuRatio$$ are -used as part of an $cref ADFun$$ object. - -$head Include$$ -This routine is designed to be used with AD objects and -requires the $code cppad/cppad.hpp$$ file to be included. - -$head Matrix Storage$$ -All matrices are stored in row major order. -To be specific, if $latex Y$$ is a vector -that contains a $latex p$$ by $latex q$$ matrix, -the size of $latex Y$$ must be equal to $latex p * q $$ and for -$latex i = 0 , \ldots , p-1$$, -$latex j = 0 , \ldots , q-1$$, -$latex \[ - Y_{i,j} = Y[ i * q + j ] -\] $$ - -$head sign$$ -The return value $icode sign$$ has prototype -$codei% - int %sign% -%$$ -If $icode A$$ is invertible, $icode sign$$ is plus or minus one -and is the sign of the permutation corresponding to the row ordering -$icode ip$$ and column ordering $icode jp$$. -If $icode A$$ is not invertible, $icode sign$$ is zero. - -$head ip$$ -The argument $icode ip$$ has prototype -$codei% - %SizeVector% &%ip% -%$$ -(see description of $cref/SizeVector/LuFactor/SizeVector/$$ below). -The size of $icode ip$$ is referred to as $icode n$$ in the -specifications below. -The input value of the elements of $icode ip$$ does not matter. -The output value of the elements of $icode ip$$ determine -the order of the rows in the permuted matrix. - -$head jp$$ -The argument $icode jp$$ has prototype -$codei% - %SizeVector% &%jp% -%$$ -(see description of $cref/SizeVector/LuFactor/SizeVector/$$ below). -The size of $icode jp$$ must be equal to $icode n$$. -The input value of the elements of $icode jp$$ does not matter. -The output value of the elements of $icode jp$$ determine -the order of the columns in the permuted matrix. - -$head LU$$ -The argument $icode LU$$ has the prototype -$codei% - %ADvector% &%LU% -%$$ -and the size of $icode LU$$ must equal $latex n * n$$ -(see description of $cref/ADvector/LuRatio/ADvector/$$ below). - -$subhead A$$ -We define $icode A$$ as the matrix corresponding to the input -value of $icode LU$$. - -$subhead P$$ -We define the permuted matrix $icode P$$ in terms of $icode A$$ by -$codei% - %P%(%i%, %j%) = %A%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ - -$subhead L$$ -We define the lower triangular matrix $icode L$$ in terms of the -output value of $icode LU$$. -The matrix $icode L$$ is zero above the diagonal -and the rest of the elements are defined by -$codei% - %L%(%i%, %j%) = %LU%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -for $latex i = 0 , \ldots , n-1$$ and $latex j = 0 , \ldots , i$$. - -$subhead U$$ -We define the upper triangular matrix $icode U$$ in terms of the -output value of $icode LU$$. -The matrix $icode U$$ is zero below the diagonal, -one on the diagonal, -and the rest of the elements are defined by -$codei% - %U%(%i%, %j%) = %LU%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -for $latex i = 0 , \ldots , n-2$$ and $latex j = i+1 , \ldots , n-1$$. - -$subhead Factor$$ -If the return value $icode sign$$ is non-zero, -$codei% - %L% * %U% = %P% -%$$ -If the return value of $icode sign$$ is zero, -the contents of $icode L$$ and $icode U$$ are not defined. - -$subhead Determinant$$ -If the return value $icode sign$$ is zero, -the determinant of $icode A$$ is zero. -If $icode sign$$ is non-zero, -using the output value of $icode LU$$ -the determinant of the matrix $icode A$$ is equal to -$codei% -%sign% * %LU%[%ip%[0], %jp%[0]] * %...% * %LU%[%ip%[%n%-1], %jp%[%n%-1]] -%$$ - -$head ratio$$ -The argument $icode ratio$$ has prototype -$codei% - AD<%Base%> &%ratio% -%$$ -On input, the value of $icode ratio$$ does not matter. -On output it is a measure of how good the choice of pivots is. -For $latex p = 0 , \ldots , n-1$$, -the $th p$$ pivot element is the element of maximum absolute value of a -$latex (n-p) \times (n-p)$$ sub-matrix. -The ratio of each element of sub-matrix divided by the pivot element -is computed. -The return value of $icode ratio$$ is the maximum absolute value of -such ratios over with respect to all elements and all the pivots. - -$subhead Purpose$$ -Suppose that the execution of a call to $code LuRatio$$ -is recorded in the $codei%ADFun<%Base%>%$$ object $icode F$$. -Then a call to $cref Forward$$ of the form -$codei% - %F%.Forward(%k%, %xk%) -%$$ -with $icode k$$ equal to zero will revaluate this Lu factorization -with the same pivots and a new value for $icode A$$. -In this case, the resulting $icode ratio$$ may not be one. -If $icode ratio$$ is too large (the meaning of too large is up to you), -the current pivots do not yield a stable LU factorization of $icode A$$. -A better choice for the pivots (for this value of $icode A$$) -will be made if you recreate the $code ADFun$$ object -starting with the $cref Independent$$ variable values -that correspond to the vector $icode xk$$. - -$head SizeVector$$ -The type $icode SizeVector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type size_t/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head ADvector$$ -The type $icode ADvector$$ must be a -$cref/simple vector class/SimpleVector/$$ with elements of type -$codei%AD<%Base%>%$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - - -$head Example$$ -$children% - example/general/lu_ratio.cpp -%$$ -The file $cref lu_ratio.cpp$$ -contains an example and test of using $code LuRatio$$. -It returns true if it succeeds and false otherwise. - -$end --------------------------------------------------------------------------- -*/ -namespace CppAD { // BEGIN CppAD namespace - -// Lines different from the code in cppad/lu_factor.hpp end with // -template // -int LuRatio(SizeVector &ip, SizeVector &jp, ADvector &LU, AD &ratio) // -{ - typedef ADvector FloatVector; // - typedef AD Float; // - - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - CheckSimpleVector(); - - size_t i, j; // some temporary indices - const Float zero( 0 ); // the value zero as a Float object - size_t imax; // row index of maximum element - size_t jmax; // column indx of maximum element - Float emax; // maximum absolute value - size_t p; // count pivots - int sign; // sign of the permutation - Float etmp; // temporary element - Float pivot; // pivot element - - // ------------------------------------------------------- - size_t n = size_t(ip.size()); - CPPAD_ASSERT_KNOWN( - size_t(jp.size()) == n, - "Error in LuFactor: jp must have size equal to n" - ); - CPPAD_ASSERT_KNOWN( - size_t(LU.size()) == n * n, - "Error in LuFactor: LU must have size equal to n * m" - ); - // ------------------------------------------------------- - - // initialize row and column order in matrix not yet pivoted - for(i = 0; i < n; i++) - { ip[i] = i; - jp[i] = i; - } - // initialize the sign of the permutation - sign = 1; - // initialize the ratio // - ratio = Float(1); // - // --------------------------------------------------------- - - // Reduce the matrix P to L * U using n pivots - for(p = 0; p < n; p++) - { // determine row and column corresponding to element of - // maximum absolute value in remaining part of P - imax = jmax = n; - emax = zero; - for(i = p; i < n; i++) - { for(j = p; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( - (ip[i] < n) & (jp[j] < n) - ); - etmp = LU[ ip[i] * n + jp[j] ]; - - // check if maximum absolute value so far - if( AbsGeq (etmp, emax) ) - { imax = i; - jmax = j; - emax = etmp; - } - } - } - for(i = p; i < n; i++) // - { for(j = p; j < n; j++) // - { etmp = fabs(LU[ ip[i] * n + jp[j] ] / emax); // - ratio = // - CondExpGt(etmp, ratio, etmp, ratio); // - } // - } // - CPPAD_ASSERT_KNOWN( - (imax < n) & (jmax < n) , - "AbsGeq must return true when second argument is zero" - ); - if( imax != p ) - { // switch rows so max absolute element is in row p - i = ip[p]; - ip[p] = ip[imax]; - ip[imax] = i; - sign = -sign; - } - if( jmax != p ) - { // switch columns so max absolute element is in column p - j = jp[p]; - jp[p] = jp[jmax]; - jp[jmax] = j; - sign = -sign; - } - // pivot using the max absolute element - pivot = LU[ ip[p] * n + jp[p] ]; - - // check for determinant equal to zero - if( pivot == zero ) - { // abort the mission - return 0; - } - - // Reduce U by the elementary transformations that maps - // LU( ip[p], jp[p] ) to one. Only need transform elements - // above the diagonal in U and LU( ip[p] , jp[p] ) is - // corresponding value below diagonal in L. - for(j = p+1; j < n; j++) - LU[ ip[p] * n + jp[j] ] /= pivot; - - // Reduce U by the elementary transformations that maps - // LU( ip[i], jp[p] ) to zero. Only need transform elements - // above the diagonal in U and LU( ip[i], jp[p] ) is - // corresponding value below diagonal in L. - for(i = p+1; i < n; i++ ) - { etmp = LU[ ip[i] * n + jp[p] ]; - for(j = p+1; j < n; j++) - { LU[ ip[i] * n + jp[j] ] -= - etmp * LU[ ip[p] * n + jp[j] ]; - } - } - } - return sign; -} -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/mul.hpp b/external/cppad/include/cppad/core/mul.hpp deleted file mode 100644 index ece04e369..000000000 --- a/external/cppad/include/cppad/core/mul.hpp +++ /dev/null @@ -1,102 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_MUL_HPP -# define CPPAD_CORE_MUL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD operator * (const AD &left , const AD &right) -{ - // compute the Base part - AD result; - result.value_ = left.value_ * right.value_; - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return result; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = left.tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // result = variable * variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::MulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::MulvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(left.taddr_, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::MulvvOp); - // make result a variable - result.tape_id_ = tape_id; - } - else if( IdenticalZero(right.value_) ) - { // result = variable * 0 - } - else if( IdenticalOne(right.value_) ) - { // result = variable * 1 - result.make_variable(left.tape_id_, left.taddr_); - } - else - { // result = variable * parameter - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::MulpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(p, left.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::MulpvOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - else if( var_right ) - { if( IdenticalZero(left.value_) ) - { // result = 0 * variable - } - else if( IdenticalOne(left.value_) ) - { // result = 1 * variable - result.make_variable(right.tape_id_, right.taddr_); - } - else - { // result = parameter * variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::MulpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left.value_); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::MulpvOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - return result; -} - -// convert other cases into the case above -CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(*) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/mul_eq.hpp b/external/cppad/include/cppad/core/mul_eq.hpp deleted file mode 100644 index cd4c9f1de..000000000 --- a/external/cppad/include/cppad/core/mul_eq.hpp +++ /dev/null @@ -1,102 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_MUL_EQ_HPP -# define CPPAD_CORE_MUL_EQ_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD& AD::operator *= (const AD &right) -{ - // compute the Base part - Base left; - left = value_; - value_ *= right.value_; - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return *this; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // this = variable * variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::MulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::MulvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(taddr_, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::MulvvOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - else if( IdenticalOne( right.value_ ) ) - { // this = variable * 1 - } - else if( IdenticalZero( right.value_ ) ) - { // this = variable * 0 - make_parameter(); - } - else - { // this = variable * parameter - // = parameter * variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::MulpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(p, taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::MulpvOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - } - else if( var_right ) - { if( IdenticalZero(left) ) - { // this = 0 * right - } - else if( IdenticalOne(left) ) - { // this = 1 * right - make_variable(right.tape_id_, right.taddr_); - } - else - { // this = parameter * variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::MulpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::MulpvOp); - // make this a variable - tape_id_ = tape_id; - } - } - return *this; -} - -CPPAD_FOLD_ASSIGNMENT_OPERATOR(*=) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/near_equal_ext.hpp b/external/cppad/include/cppad/core/near_equal_ext.hpp deleted file mode 100644 index b6fdbcb46..000000000 --- a/external/cppad/include/cppad/core/near_equal_ext.hpp +++ /dev/null @@ -1,188 +0,0 @@ -# ifndef CPPAD_CORE_NEAR_EQUAL_EXT_HPP -# define CPPAD_CORE_NEAR_EQUAL_EXT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin NearEqualExt$$ -$spell - cout - endl - Microsoft - std - Cpp - namespace - const - bool -$$ - -$section Compare AD and Base Objects for Nearly Equal$$ -$mindex NearEqual with$$ - - -$head Syntax$$ -$icode%b% = NearEqual(%x%, %y%, %r%, %a%)%$$ - - -$head Purpose$$ -The routine $cref NearEqual$$ determines if two objects of -the same type are nearly. -This routine is extended to the case where one object can have type -$icode Type$$ while the other can have type -$codei%AD<%Type%>%$$ or -$codei%AD< std::complex<%Type%> >%$$. - -$head x$$ -The arguments $icode x$$ -has one of the following possible prototypes: -$codei% - const %Type% &%x% - const AD<%Type%> &%x% - const AD< std::complex<%Type%> > &%x% -%$$ - -$head y$$ -The arguments $icode y$$ -has one of the following possible prototypes: -$codei% - const %Type% &%y% - const AD<%Type%> &%y% - const AD< std::complex<%Type%> > &%x% -%$$ - - -$head r$$ -The relative error criteria $icode r$$ has prototype -$codei% - const %Type% &%r% -%$$ -It must be greater than or equal to zero. -The relative error condition is defined as: -$latex \[ - \frac{ | x - y | } { |x| + |y| } \leq r -\] $$ - -$head a$$ -The absolute error criteria $icode a$$ has prototype -$codei% - const %Type% &%a% -%$$ -It must be greater than or equal to zero. -The absolute error condition is defined as: -$latex \[ - | x - y | \leq a -\] $$ - -$head b$$ -The return value $icode b$$ has prototype -$codei% - bool %b% -%$$ -If either $icode x$$ or $icode y$$ is infinite or not a number, -the return value is false. -Otherwise, if either the relative or absolute error -condition (defined above) is satisfied, the return value is true. -Otherwise, the return value is false. - -$head Type$$ -The type $icode Type$$ must be a -$cref NumericType$$. -The routine $cref CheckNumericType$$ will generate -an error message if this is not the case. -If $icode a$$ and $icode b$$ have type $icode Type$$, -the following operation must be defined -$table -$bold Operation$$ $cnext - $bold Description$$ $rnext -$icode%a% <= %b%$$ $cnext - less that or equal operator (returns a $code bool$$ object) -$tend - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/near_equal_ext.cpp -%$$ -The file $cref near_equal_ext.cpp$$ contains an example -and test of this extension of $cref NearEqual$$. -It return true if it succeeds and false otherwise. - -$end - -*/ -// BEGIN CppAD namespace -namespace CppAD { -// ------------------------------------------------------------------------ - -// fold into base type and then use -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual( -const AD &x, const AD &y, const Base &r, const Base &a) -{ return NearEqual(x.value_, y.value_, r, a); -} - -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual( -const Base &x, const AD &y, const Base &r, const Base &a) -{ return NearEqual(x, y.value_, r, a); -} - -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual( -const AD &x, const Base &y, const Base &r, const Base &a) -{ return NearEqual(x.value_, y, r, a); -} - -// fold into AD type and then use cases above -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual( - const VecAD_reference &x, const VecAD_reference &y, - const Base &r, const Base &a) -{ return NearEqual(x.ADBase(), y.ADBase(), r, a); -} -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual(const VecAD_reference &x, const AD &y, - const Base &r, const Base &a) -{ return NearEqual(x.ADBase(), y, r, a); -} -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual(const VecAD_reference &x, const Base &y, - const Base &r, const Base &a) -{ return NearEqual(x.ADBase(), y, r, a); -} -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual(const AD &x, const VecAD_reference &y, - const Base &r, const Base &a) -{ return NearEqual(x, y.ADBase(), r, a); -} -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool NearEqual(const Base &x, const VecAD_reference &y, - const Base &r, const Base &a) -{ return NearEqual(x, y.ADBase(), r, a); -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/num_skip.hpp b/external/cppad/include/cppad/core/num_skip.hpp deleted file mode 100644 index 8c19ead06..000000000 --- a/external/cppad/include/cppad/core/num_skip.hpp +++ /dev/null @@ -1,129 +0,0 @@ -# ifndef CPPAD_CORE_NUM_SKIP_HPP -# define CPPAD_CORE_NUM_SKIP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin number_skip$$ -$spell - optimizer - var - taylor_ -$$ - - -$section Number of Variables that Can be Skipped$$ -$mindex number_skip$$ - -$head Syntax$$ -$icode%n% = %f%.number_skip()%$$ - -$subhead See Also$$ -$cref seq_property$$ - -$head Purpose$$ -The $cref/conditional expressions/CondExp/$$ use either the -$cref/if_true/CondExp/$$ or $cref/if_false/CondExp/$$. -Hence, some terms only need to be evaluated -depending on the value of the comparison in the conditional expression. -The $cref optimize$$ option is capable of detecting some of these -case and determining variables that can be skipped. -This routine returns the number such variables. - -$head n$$ -The return value $icode n$$ has type $code size_t$$ -is the number of variables that the optimizer has determined can be skipped -(given the independent variable values specified by the previous call to -$cref/f.Forward/Forward/$$ for order zero). - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$children% - example/general/number_skip.cpp -%$$ -$head Example$$ -The file $cref number_skip.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -// This routine is not const because it runs through the operations sequence -// 2DO: compute this value during zero order forward operations. -template -size_t ADFun::number_skip(void) -{ // must pass through operation sequence to map operations to variables - local::OpCode op; - size_t i_op; - size_t i_var; - const addr_t* arg; - - // information defined by forward_user - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - local::enum_user_state user_state; - - // number of variables skipped - size_t num_var_skip = 0; - - // start playback - user_state = local::start_user; - play_.forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN(op == local::BeginOp) - while(op != local::EndOp) - { // next op - play_.forward_next(op, arg, i_op, i_var); - // - if( op == local::UserOp ) - { // skip only appears at front or back UserOp of user atomic call - bool skip_call = cskip_op_[i_op]; - CPPAD_ASSERT_UNKNOWN( user_state == local::start_user ); - play_.forward_user( - op, user_state, user_old, user_m, user_n, user_i, user_j - ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - size_t num_op = user_m + user_n + 1; - for(size_t i = 0; i < num_op; i++) - { play_.forward_next(op, arg, i_op, i_var); - play_.forward_user( - op, user_state, user_old, user_m, user_n, user_i, user_j - ); - if( skip_call ) - num_var_skip += NumRes(op); - } - CPPAD_ASSERT_UNKNOWN( user_state == local::start_user ); - } - else - { if( op == local::CSumOp) - play_.forward_csum(op, arg, i_op, i_var); - else if (op == local::CSkipOp) - play_.forward_cskip(op, arg, i_op, i_var); - // - if( cskip_op_[i_op] ) - num_var_skip += NumRes(op); - } - } - return num_var_skip; -} - -} // END CppAD namespace - - -# endif diff --git a/external/cppad/include/cppad/core/numeric_limits.hpp b/external/cppad/include/cppad/core/numeric_limits.hpp deleted file mode 100644 index 19c82f3e5..000000000 --- a/external/cppad/include/cppad/core/numeric_limits.hpp +++ /dev/null @@ -1,214 +0,0 @@ -# ifndef CPPAD_CORE_NUMERIC_LIMITS_HPP -# define CPPAD_CORE_NUMERIC_LIMITS_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- -$begin numeric_limits$$ -$spell - std - eps - CppAD - namespace - const -$$ - -$section Numeric Limits For an AD and Base Types$$ - -$head Syntax$$ -$icode%eps% = numeric_limits<%Float%>::epsilon() -%$$ -$icode%min% = numeric_limits<%Float%>::min() -%$$ -$icode%max% = numeric_limits<%Float%>::max() -%$$ -$icode%nan% = numeric_limits<%Float%>::quiet_NaN() -%$$ -$codei%numeric_limits<%Float%>::digits10%$$ - -$head CppAD::numeric_limits$$ -These functions and have the prototype -$codei% - static %Float% CppAD::numeric_limits<%Float%>::%fun%(%void%) -%$$ -where $icode fun$$ is -$code epsilon$$, $code min$$, $code max$$, and $code quiet_NaN$$. -(Note that $code digits10$$ is member variable and not a function.) - -$head std::numeric_limits$$ -CppAD does not use a specialization of $code std::numeric_limits$$ -because this would be to restrictive. -The C++ standard specifies that Non-fundamental standard -types, such as -$cref/std::complex/base_complex.hpp/$$ shall not have specializations -of $code std::numeric_limits$$; see Section 18.2 of -ISO/IEC 14882:1998(E). -In addition, since C++11, a only literal types can have a specialization -of $code std::numeric_limits$$. - -$head Float$$ -These functions are defined for all $codei%AD<%Base%>%$$, -and for all corresponding $icode Base$$ types; -see $icode Base$$ type $cref base_limits$$. - -$head epsilon$$ -The result $icode eps$$ is equal to machine epsilon and has prototype -$codei% - %Float% %eps% -%$$ -The file $cref num_limits.cpp$$ -tests the value $icode eps$$ by checking that the following are true -$codei% - 1 != 1 + %eps% - 1 == 1 + %eps% / 2 -%$$ -where all the values, and calculations, are done with the precision -corresponding to $icode Float$$. - -$head min$$ -The result $icode min$$ is equal to -the minimum positive normalized value and has prototype -$codei% - %Float% %min% -%$$ -The file $cref num_limits.cpp$$ -tests the value $icode min$$ by checking that the following are true -$codei% - abs( ((%min% / 100) * 100) / %min% - 1 ) > 3 * %eps% - abs( ((%min% * 100) / 100) / %min% - 1 ) < 3 * %eps% -%$$ -where all the values, and calculations, are done with the precision -corresponding to $icode Float$$. - -$head max$$ -The result $icode max$$ is equal to -the maximum finite value and has prototype -$codei% - %Float% %max% -%$$ -The file $cref num_limits.cpp$$ -tests the value $icode max$$ by checking that the following are true -$codei% - abs( ((%max% * 100) / 100) / %max% - 1 ) > 3 * %eps% - abs( ((%max% / 100) * 100) / %max% - 1 ) < 3 * %eps% -%$$ -where all the values, and calculations, are done with the precision -corresponding to $icode Float$$. - -$head quiet_NaN$$ -The result $icode nan$$ is not a number and has prototype -$codei% - %Float% %nan% -%$$ -The file $cref num_limits.cpp$$ -tests the value $icode nan$$ by checking that the following is true -$codei% - %nan% != %nan% -%$$ - -$head digits10$$ -The member variable $code digits10$$ has prototype -$codei% - static const int numeric_limits<%Float%>::digits10 -%$$ -It is the number of decimal digits that can be represented by a -$icode Float$$ value. A number with this many decimal digits can be -converted to $icode Float$$ and back to a string, -without change due to rounding or overflow. - - -$head Example$$ -$children% - example/general/num_limits.cpp -%$$ -The file -$cref num_limits.cpp$$ -contains an example and test of these functions. - -$end ------------------------------------------------------------------------------- -*/ -# include - -# include -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file numeric_limits.hpp -File that defines CppAD numeric_limits for AD types -*/ - -/// All tthese defaults correspond to errors -template -class numeric_limits { -public: - /// machine epsilon - static Float epsilon(void) - { CPPAD_ASSERT_KNOWN( - false, - "numeric_limits::epsilon() is not specialized for this Float" - ); - return Float(0); - } - /// minimum positive normalized value - static Float min(void) - { CPPAD_ASSERT_KNOWN( - false, - "numeric_limits::min() is not specialized for this Float" - ); - return Float(0); - } - /// maximum finite value - static Float max(void) - { CPPAD_ASSERT_KNOWN( - false, - "numeric_limits::max() is not specialized for this Float" - ); - return Float(0); - } - /// not a number - static Float quiet_NaN(void) - { CPPAD_ASSERT_KNOWN( - false, - "numeric_limits::quiet_NaN() is not specialized for this Float" - ); - return Float(0); - } - /// number of decimal digits - static const int digits10 = -1; -}; - -/// Partial specialization that defines limits for for all AD types -template -class numeric_limits< AD > { -public: - /// machine epsilon - static AD epsilon(void) - { return AD( numeric_limits::epsilon() ); } - /// minimum positive normalized value - static AD min(void) - { return AD( numeric_limits::min() ); } - /// maximum finite value - static AD max(void) - { return AD( numeric_limits::max() ); } - /// not a number - static AD quiet_NaN(void) - { return AD( numeric_limits::quiet_NaN() ); } - /// number of decimal digits - static const int digits10 = numeric_limits::digits10; -}; - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/old_atomic.hpp b/external/cppad/include/cppad/core/old_atomic.hpp deleted file mode 100644 index 67c716429..000000000 --- a/external/cppad/include/cppad/core/old_atomic.hpp +++ /dev/null @@ -1,1088 +0,0 @@ -# ifndef CPPAD_CORE_OLD_ATOMIC_HPP -# define CPPAD_CORE_OLD_ATOMIC_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin old_atomic$$ -$spell - hes - std - Jacobian - jac - Tvector - afun - vx - vy - bool - namespace - CppAD - const - Taylor - tx - ty - px - py -$$ - -$section User Defined Atomic AD Functions$$ -$mindex operation old_atomic$$ - -$head Deprecated 2013-05-27$$ -Using $code CPPAD_USER_ATOMIC$$ has been deprecated. -Use $cref atomic_base$$ instead. - -$head Syntax Function$$ -$codei%CPPAD_USER_ATOMIC(%afun%, %Tvector%, %Base%, - %forward%, %reverse%, %for_jac_sparse%, %rev_jac_sparse%, %rev_hes_sparse% -) -%$$ - -$subhead Use Function$$ -$icode%afun%(%id%, %ax%, %ay%) -%$$ - -$subhead Callback Routines$$ -$icode%ok% = %forward%(%id%, %k%, %n%, %m%, %vx%, %vy%, %tx%, %ty%) -%$$ -$icode%ok% = %reverse%(%id%, %k%, %n%, %m%, %tx%, %ty%, %px%, %py%) -%$$ -$icode%ok% = %for_jac_sparse%(%id%, %n%, %m%, %q%, %r%, %s%) -%$$ -$icode%ok% = %rev_jac_sparse%(%id%, %n%, %m%, %q%, %r%, %s%) -%$$ -$icode%ok% = %rev_hes_sparse%(%id%, %n%, %m%, %q%, %r%, %s%, %t%, %u%, %v%) -%$$ - -$subhead Free Static Memory$$ -$codei%user_atomic<%Base%>::clear()%$$ - -$head Purpose$$ -In some cases, the user knows how to compute the derivative -of a function -$latex \[ - y = f(x) \; {\rm where} \; f : B^n \rightarrow B^m -\] $$ -more efficiently than by coding it using $codei%AD<%Base%>%$$ -$cref/atomic/glossary/Operation/Atomic/$$ operations -and letting CppAD do the rest. -In this case, $code CPPAD_USER_ATOMIC$$ can be used -add the user code for $latex f(x)$$, and its derivatives, -to the set of $codei%AD<%Base%>%$$ atomic operations. -$pre - -$$ -Another possible purpose is to reduce the size of the tape; -see $cref/use AD/old_atomic/Example/Use AD/$$ - -$head Partial Implementation$$ -The routines -$cref/forward/old_atomic/forward/$$, -$cref/reverse/old_atomic/reverse/$$, -$cref/for_jac_sparse/old_atomic/for_jac_sparse/$$, -$cref/rev_jac_sparse/old_atomic/rev_jac_sparse/$$, and -$cref/rev_hes_sparse/old_atomic/rev_hes_sparse/$$, -must be defined by the user. -The $icode forward$$ the routine, -for the case $icode%k% = 0%$$, must be implemented. -Functions with the correct prototype, -that just return $code false$$, -can be used for the other cases -(unless they are required by your calculations). -For example, you need not implement -$icode forward$$ for the case $icode%k% == 2%$$ until you require -forward mode calculation of second derivatives. - -$head CPPAD_USER_ATOMIC$$ -The macro -$codei% -CPPAD_USER_ATOMIC(%afun%, %Tvector%, %Base%, - %forward%, %reverse%, %for_jac_sparse%, %rev_jac_sparse%, %rev_hes_sparse% -) -%$$ -defines the $codei%AD<%Base%>%$$ routine $icode afun$$. -This macro can be placed within a namespace -(not the $code CppAD$$ namespace) -but must be outside of any routine. - -$subhead Tvector$$ -The macro argument $icode Tvector$$ must be a -$cref/simple vector template class/SimpleVector/$$. -It determines the type of vectors used as arguments to the routine -$icode afun$$. - -$subhead Base$$ -The macro argument $icode Base$$ specifies the -$cref/base type/base_require/$$ -corresponding to $codei%AD<%Base>%$$ operation sequences. -Calling the routine $icode afun$$ will add the operator defined -by this macro to an $codei%AD<%Base>%$$ operation sequence. - -$head ok$$ -For all routines documented below, -the return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -If it is $code true$$, the corresponding evaluation succeeded, -otherwise it failed. - -$head id$$ -For all routines documented below, -the argument $icode id$$ has prototype -$codei% - size_t %id% -%$$ -Its value in all other calls is the same as in the corresponding -call to $icode afun$$. -It can be used to store and retrieve extra information about -a specific call to $icode afun$$. - -$head k$$ -For all routines documented below, the argument $icode k$$ has prototype -$codei% - size_t %k% -%$$ -The value $icode%k%$$ is the order of the Taylor coefficient that -we are evaluating ($cref/forward/old_atomic/forward/$$) -or taking the derivative of ($cref/reverse/old_atomic/reverse/$$). - -$head n$$ -For all routines documented below, -the argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -It is the size of the vector $icode ax$$ in the corresponding call to -$icode%afun%(%id%, %ax%, %ay%)%$$; i.e., -the dimension of the domain space for $latex y = f(x)$$. - -$head m$$ -For all routines documented below, the argument $icode m$$ has prototype -$codei% - size_t %m% -%$$ -It is the size of the vector $icode ay$$ in the corresponding call to -$icode%afun%(%id%, %ax%, %ay%)%$$; i.e., -the dimension of the range space for $latex y = f(x)$$. - -$head tx$$ -For all routines documented below, -the argument $icode tx$$ has prototype -$codei% - const CppAD::vector<%Base%>& %tx% -%$$ -and $icode%tx%.size() >= (%k% + 1) * %n%$$. -For $latex j = 0 , \ldots , n-1$$ and $latex \ell = 0 , \ldots , k$$, -we use the Taylor coefficient notation -$latex \[ -\begin{array}{rcl} - x_j^\ell & = & tx [ j * ( k + 1 ) + \ell ] - \\ - X_j (t) & = & x_j^0 + x_j^1 t^1 + \cdots + x_j^k t^k -\end{array} -\] $$ -If $icode%tx%.size() > (%k% + 1) * %n%$$, -the other components of $icode tx$$ are not specified and should not be used. -Note that superscripts represent an index for $latex x_j^\ell$$ -and an exponent for $latex t^\ell$$. -Also note that the Taylor coefficients for $latex X(t)$$ correspond -to the derivatives of $latex X(t)$$ at $latex t = 0$$ in the following way: -$latex \[ - x_j^\ell = \frac{1}{ \ell ! } X_j^{(\ell)} (0) -\] $$ - -$head ty$$ -In calls to $cref/forward/old_atomic/forward/$$, -the argument $icode ty$$ has prototype -$codei% - CppAD::vector<%Base%>& %ty% -%$$ -while in calls to $cref/reverse/old_atomic/reverse/$$ it has prototype -$codei% - const CppAD::vector<%Base%>& %ty% -%$$ -For all calls, $icode%tx%.size() >= (%k% + 1) * %m%$$. -For $latex i = 0 , \ldots , m-1$$ and $latex \ell = 0 , \ldots , k$$, -we use the Taylor coefficient notation -$latex \[ -\begin{array}{rcl} - y_i^\ell & = & ty [ i * ( k + 1 ) + \ell ] - \\ - Y_i (t) & = & y_i^0 + y_i^1 t^1 + \cdots + y_i^k t^k + o ( t^k ) -\end{array} -\] $$ -where $latex o( t^k ) / t^k \rightarrow 0$$ as $latex t \rightarrow 0$$. -If $icode%ty%.size() > (%k% + 1) * %m%$$, -the other components of $icode ty$$ are not specified and should not be used. -Note that superscripts represent an index for $latex y_j^\ell$$ -and an exponent for $latex t^\ell$$. -Also note that the Taylor coefficients for $latex Y(t)$$ correspond -to the derivatives of $latex Y(t)$$ at $latex t = 0$$ in the following way: -$latex \[ - y_j^\ell = \frac{1}{ \ell ! } Y_j^{(\ell)} (0) -\] $$ - -$subhead forward$$ -In the case of $icode forward$$, -for $latex i = 0 , \ldots , m-1$$, $latex ty[ i *( k + 1) + k ]$$ is an output -and all the other components of $icode ty$$ are inputs. - -$subhead reverse$$ -In the case of $icode reverse$$, -all the components of $icode ty$$ are inputs. - -$head afun$$ -The macro argument $icode afun$$, -is the name of the AD function corresponding to this atomic -operation (as it is used in the source code). -CppAD uses the other functions, -where the arguments are vectors with elements of type $icode Base$$, -to implement the function -$codei% - %afun%(%id%, %ax%, %ay%) -%$$ -where the argument are vectors with elements of type $codei%AD<%Base%>%$$. - -$subhead ax$$ -The $icode afun$$ argument $icode ax$$ has prototype -$codei% - const %Tvector%< AD<%Base%> >& %ax% -%$$ -It is the argument vector $latex x \in B^n$$ -at which the $codei%AD<%Base%>%$$ version of -$latex y = f(x)$$ is to be evaluated. -The dimension of the domain space for $latex y = f (x)$$ -is specified by $cref/n/old_atomic/n/$$ $codei%= %ax%.size()%$$, -which must be greater than zero. - -$subhead ay$$ -The $icode afun$$ result $icode ay$$ has prototype -$codei% - %Tvector%< AD<%Base%> >& %ay% -%$$ -The input values of its elements -are not specified (must not matter). -Upon return, it is the $codei%AD<%Base%>%$$ version of the -result vector $latex y = f(x)$$. -The dimension of the range space for $latex y = f (x)$$ -is specified by $cref/m/old_atomic/m/$$ $codei%= %ay%.size()%$$, -which must be greater than zero. - -$subhead Parallel Mode$$ -The first call to -$codei% - %afun%(%id%, %ax%, %ay%) -%$$ -must not be in $cref/parallel/ta_in_parallel/$$ mode. -In addition, the -$cref/old_atomic clear/old_atomic/clear/$$ -routine cannot be called while in parallel mode. - -$head forward$$ -The macro argument $icode forward$$ is a -user defined function -$codei% - %ok% = %forward%(%id%, %k%, %n%, %m%, %vx%, %vy%, %tx%, %ty%) -%$$ -that computes results during a $cref/forward/Forward/$$ mode sweep. -For this call, we are given the Taylor coefficients in $icode tx$$ -form order zero through $icode k$$, -and the Taylor coefficients in $icode ty$$ with order less than $icode k$$. -The $icode forward$$ routine computes the -$icode k$$ order Taylor coefficients for $latex y$$ using the definition -$latex Y(t) = f[ X(t) ]$$. -For example, for $latex i = 0 , \ldots , m-1$$, -$latex \[ -\begin{array}{rcl} -y_i^0 & = & Y(0) - = f_i ( x^0 ) -\\ -y_i^1 & = & Y^{(1)} ( 0 ) - = f_i^{(1)} ( x^0 ) X^{(1)} ( 0 ) - = f_i^{(1)} ( x^0 ) x^1 -\\ -y_i^2 -& = & \frac{1}{2 !} Y^{(2)} (0) -\\ -& = & \frac{1}{2} X^{(1)} (0)^\R{T} f_i^{(2)} ( x^0 ) X^{(1)} ( 0 ) - + \frac{1}{2} f_i^{(1)} ( x^0 ) X^{(2)} ( 0 ) -\\ -& = & \frac{1}{2} (x^1)^\R{T} f_i^{(2)} ( x^0 ) x^1 - + f_i^{(1)} ( x^0 ) x^2 -\end{array} -\] $$ -Then, for $latex i = 0 , \ldots , m-1$$, it sets -$latex \[ - ty [ i * (k + 1) + k ] = y_i^k -\] $$ -The other components of $icode ty$$ must be left unchanged. - -$subhead Usage$$ -This routine is used, -with $icode%vx%.size() > 0%$$ and $icode%k% == 0%$$, -by calls to $icode afun$$. -It is used, -with $icode%vx%.size() = 0%$$ and -$icode k$$ equal to the order of the derivative begin computed, -by calls to $cref/forward/forward_order/$$. - -$subhead vx$$ -The $icode forward$$ argument $icode vx$$ has prototype -$codei% - const CppAD::vector& %vx% -%$$ -The case $icode%vx%.size() > 0%$$ occurs -once for each call to $icode afun$$, -during the call, -and before any of the other callbacks corresponding to that call. -Hence such a call can be used to cache information attached to -the corresponding $icode id$$ -(such as the elements of $icode vx$$). -If $icode%vx%.size() > 0%$$ then -$icode%k% == 0%$$, -$icode%vx%.size() >= %n%$$, and -for $latex j = 0 , \ldots , n-1$$, -$icode%vx%[%j%]%$$ is true if and only if -$icode%ax%[%j%]%$$ is a $cref/variable/glossary/Variable/$$. -$pre - -$$ -If $icode%vx%.size() == 0%$$, -then $icode%vy%.size() == 0%$$ and neither of these vectors -should be used. - -$subhead vy$$ -The $icode forward$$ argument $icode vy$$ has prototype -$codei% - CppAD::vector& %vy% -%$$ -If $icode%vy%.size() == 0%$$, it should not be used. -Otherwise, -$icode%k% == 0%$$ and $icode%vy%.size() >= %m%$$. -The input values of the elements of $icode vy$$ -are not specified (must not matter). -Upon return, for $latex j = 0 , \ldots , m-1$$, -$icode%vy%[%i%]%$$ is true if and only if -$icode%ay%[%j%]%$$ is a variable. -(CppAD uses $icode vy$$ to reduce the necessary computations.) - -$head reverse$$ -The macro argument $icode reverse$$ -is a user defined function -$codei% - %ok% = %reverse%(%id%, %k%, %n%, %m%, %tx%, %ty%, %px%, %py%) -%$$ -that computes results during a $cref/reverse/Reverse/$$ mode sweep. -The input value of the vectors $icode tx$$ and $icode ty$$ -contain Taylor coefficient, up to order $icode k$$, -for $latex X(t)$$ and $latex Y(t)$$ respectively. -We use the $latex \{ x_j^\ell \}$$ and $latex \{ y_i^\ell \}$$ -to denote these Taylor coefficients where the implicit range indices are -$latex i = 0 , \ldots , m-1$$, -$latex j = 0 , \ldots , n-1$$, -$latex \ell = 0 , \ldots , k$$. -Using the calculations done by $cref/forward/old_atomic/forward/$$, -the Taylor coefficients $latex \{ y_i^\ell \}$$ are a function of the Taylor -coefficients for $latex \{ x_j^\ell \}$$; i.e., given $latex y = f(x)$$ -we define the function -$latex F : B^{n \times (k+1)} \rightarrow B^{m \times (k+1)}$$ by -$latex \[ -y_i^\ell = F_i^\ell ( \{ x_j^\ell \} ) -\] $$ -We use $latex G : B^{m \times (k+1)} \rightarrow B$$ -to denote an arbitrary scalar valued function of the Taylor coefficients for -$latex Y(t)$$ and write $latex z = G( \{ y_i^\ell \} )$$. -The $code reverse$$ routine -is given the derivative of $latex z$$ with respect to -$latex \{ y_i^\ell \}$$ and computes its derivative with respect -to $latex \{ x_j^\ell \}$$. - -$subhead Usage$$ -This routine is used, -with $icode%k% + 1%$$ equal to the order of the derivative being calculated, -by calls to $cref/reverse/reverse_any/$$. - -$subhead py$$ -The $icode reverse$$ argument $icode py$$ has prototype -$codei% - const CppAD::vector<%Base%>& %py% -%$$ -and $icode%py%.size() >= (%k% + 1) * %m%$$. -For $latex i = 0 , \ldots , m-1$$ and $latex \ell = 0 , \ldots , k$$, -$latex \[ - py[ i * (k + 1 ) + \ell ] = \partial G / \partial y_i^\ell -\] $$ -If $icode%py%.size() > (%k% + 1) * %m%$$, -the other components of $icode py$$ are not specified and should not be used. - -$subhead px$$ -We define the function -$latex \[ -H ( \{ x_j^\ell \} ) = G[ F( \{ x_j^\ell \} ) ] -\] $$ -The $icode reverse$$ argument $icode px$$ has prototype -$codei% - CppAD::vector<%Base%>& %px% -%$$ -and $icode%px%.size() >= (%k% + 1) * %n%$$. -The input values of the elements of $icode px$$ -are not specified (must not matter). -Upon return, -for $latex j = 0 , \ldots , n-1$$ and $latex p = 0 , \ldots , k$$, -$latex \[ -\begin{array}{rcl} -px [ j * (k + 1) + p ] & = & \partial H / \partial x_j^p -\\ -& = & -( \partial G / \partial \{ y_i^\ell \} ) - ( \partial \{ y_i^\ell \} / \partial x_j^p ) -\\ -& = & -\sum_{i=0}^{m-1} \sum_{\ell=0}^k -( \partial G / \partial y_i^\ell ) ( \partial y_i^\ell / \partial x_j^p ) -\\ -& = & -\sum_{i=0}^{m-1} \sum_{\ell=p}^k -py[ i * (k + 1 ) + \ell ] ( \partial F_i^\ell / \partial x_j^p ) -\end{array} -\] $$ -Note that we have used the fact that for $latex \ell < p$$, -$latex \partial F_i^\ell / \partial x_j^p = 0$$. -If $icode%px%.size() > (%k% + 1) * %n%$$, -the other components of $icode px$$ are not specified and should not be used. - -$head for_jac_sparse$$ -The macro argument $icode for_jac_sparse$$ -is a user defined function -$codei% - %ok% = %for_jac_sparse%(%id%, %n%, %m%, %q%, %r%, %s%) -%$$ -that is used to compute results during a forward Jacobian sparsity sweep. -For a fixed $latex n \times q$$ matrix $latex R$$, -the Jacobian of $latex f( x + R * u)$$ with respect to $latex u \in B^q$$ is -$latex \[ - S(x) = f^{(1)} (x) * R -\] $$ -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex R$$, -$icode for_jac_sparse$$ computes a sparsity pattern for $latex S(x)$$. - -$subhead Usage$$ -This routine is used by calls to $cref ForSparseJac$$. - -$subhead q$$ -The $icode for_jac_sparse$$ argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of columns in -$latex R \in B^{n \times q}$$ and the Jacobian -$latex S(x) \in B^{m \times q}$$. - -$subhead r$$ -The $icode for_jac_sparse$$ argument $icode r$$ has prototype -$codei% - const CppAD::vector< std::set >& %r% -%$$ -and $icode%r%.size() >= %n%$$. -For $latex j = 0 , \ldots , n-1$$, -all the elements of $icode%r%[%j%]%$$ are between -zero and $icode%q%-1%$$ inclusive. -This specifies a sparsity pattern for the matrix $latex R$$. - -$subhead s$$ -The $icode for_jac_sparse$$ return value $icode s$$ has prototype -$codei% - CppAD::vector< std::set >& %s% -%$$ -and $icode%s%.size() >= %m%%$$. -The input values of its sets -are not specified (must not matter). Upon return -for $latex i = 0 , \ldots , m-1$$, -all the elements of $icode%s%[%i%]%$$ are between -zero and $icode%q%-1%$$ inclusive. -This represents a sparsity pattern for the matrix $latex S(x)$$. - -$head rev_jac_sparse$$ -The macro argument $icode rev_jac_sparse$$ -is a user defined function -$codei% - %ok% = %rev_jac_sparse%(%id%, %n%, %m%, %q%, %r%, %s%) -%$$ -that is used to compute results during a reverse Jacobian sparsity sweep. -For a fixed $latex q \times m$$ matrix $latex S$$, -the Jacobian of $latex S * f( x )$$ with respect to $latex x \in B^n$$ is -$latex \[ - R(x) = S * f^{(1)} (x) -\] $$ -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex S$$, -$icode rev_jac_sparse$$ computes a sparsity pattern for $latex R(x)$$. - -$subhead Usage$$ -This routine is used by calls to $cref RevSparseJac$$ -and to $cref optimize$$. - - -$subhead q$$ -The $icode rev_jac_sparse$$ argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of rows in -$latex S \in B^{q \times m}$$ and the Jacobian -$latex R(x) \in B^{q \times n}$$. - -$subhead s$$ -The $icode rev_jac_sparse$$ argument $icode s$$ has prototype -$codei% - const CppAD::vector< std::set >& %s% -%$$ -and $icode%s%.size() >= %m%$$. -For $latex i = 0 , \ldots , m-1$$, -all the elements of $icode%s%[%i%]%$$ -are between zero and $icode%q%-1%$$ inclusive. -This specifies a sparsity pattern for the matrix $latex S^\R{T}$$. - -$subhead r$$ -The $icode rev_jac_sparse$$ return value $icode r$$ has prototype -$codei% - CppAD::vector< std::set >& %r% -%$$ -and $icode%r%.size() >= %n%$$. -The input values of its sets -are not specified (must not matter). -Upon return for $latex j = 0 , \ldots , n-1$$, -all the elements of $icode%r%[%j%]%$$ -are between zero and $icode%q%-1%$$ inclusive. -This represents a sparsity pattern for the matrix $latex R(x)^\R{T}$$. - -$head rev_hes_sparse$$ -The macro argument $icode rev_hes_sparse$$ -is a user defined function -$codei% - %ok% = %rev_hes_sparse%(%id%, %n%, %m%, %q%, %r%, %s%, %t%, %u%, %v%) -%$$ -There is an unspecified scalar valued function -$latex g : B^m \rightarrow B$$. -Given a sparsity pattern for $latex R$$ -and information about the function $latex z = g(y)$$, -this routine computes the sparsity pattern for -$latex \[ - V(x) = (g \circ f)^{(2)}( x ) R -\] $$ - -$subhead Usage$$ -This routine is used by calls to $cref RevSparseHes$$. - -$subhead q$$ -The $icode rev_hes_sparse$$ argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of columns in the sparsity patterns. - -$subhead r$$ -The $icode rev_hes_sparse$$ argument $icode r$$ has prototype -$codei% - const CppAD::vector< std::set >& %r% -%$$ -and $icode%r%.size() >= %n%$$. -For $latex j = 0 , \ldots , n-1$$, -all the elements of $icode%r%[%j%]%$$ are between -zero and $icode%q%-1%$$ inclusive. -This specifies a sparsity pattern for the matrix $latex R \in B^{n \times q}$$. - -$subhead s$$ -The $icode rev_hes_sparse$$ argument $icode s$$ has prototype -$codei% - const CppAD::vector& %s% -%$$ -and $icode%s%.size() >= %m%$$. -This specifies a sparsity pattern for the matrix -$latex S(x) = g^{(1)} (y) \in B^{1 \times m}$$. - -$subhead t$$ -The $icode rev_hes_sparse$$ argument $icode t$$ has prototype -$codei% - CppAD::vector& %t% -%$$ -and $icode%t%.size() >= %n%$$. -The input values of its elements -are not specified (must not matter). -Upon return it represents a sparsity pattern for the matrix -$latex T(x) \in B^{1 \times n}$$ defined by -$latex \[ -T(x) = (g \circ f)^{(1)} (x) = S(x) * f^{(1)} (x) -\] $$ - -$subhead u$$ -The $icode rev_hes_sparse$$ argument $icode u$$ has prototype -$codei% - const CppAD::vector< std::set >& %u% -%$$ -and $icode%u%.size() >= %m%$$. -For $latex i = 0 , \ldots , m-1$$, -all the elements of $icode%u%[%i%]%$$ -are between zero and $icode%q%-1%$$ inclusive. -This specifies a sparsity pattern -for the matrix $latex U(x) \in B^{m \times q}$$ defined by -$latex \[ -\begin{array}{rcl} -U(x) -& = & -\partial_u \{ \partial_y g[ y + f^{(1)} (x) R u ] \}_{u=0} -\\ -& = & -\partial_u \{ g^{(1)} [ y + f^{(1)} (x) R u ] \}_{u=0} -\\ -& = & -g^{(2)} (y) f^{(1)} (x) R -\end{array} -\] $$ - -$subhead v$$ -The $icode rev_hes_sparse$$ argument $icode v$$ has prototype -$codei% - CppAD::vector< std::set >& %v% -%$$ -and $icode%v%.size() >= %n%$$. -The input values of its elements -are not specified (must not matter). -Upon return, for $latex j = 0, \ldots , n-1$$, -all the elements of $icode%v%[%j%]%$$ -are between zero and $icode%q%-1%$$ inclusive. -This represents a sparsity pattern for the matrix -$latex V(x) \in B^{n \times q}$$ defined by -$latex \[ -\begin{array}{rcl} -V(x) -& = & -\partial_u [ \partial_x (g \circ f) ( x + R u ) ]_{u=0} -\\ -& = & -\partial_u [ (g \circ f)^{(1)}( x + R u ) ]_{u=0} -\\ -& = & -(g \circ f)^{(2)}( x ) R -\\ -& = & -f^{(1)} (x)^\R{T} g^{(2)} ( y ) f^{(1)} (x) R -+ -\sum_{i=1}^m [ g^{(1)} (y) ]_i \; f_i^{(2)} (x) R -\\ -& = & -f^{(1)} (x)^\R{T} U(x) -+ -\sum_{i=1}^m S(x)_i \; f_i^{(2)} (x) R -\end{array} -\] $$ - -$head clear$$ -User atomic functions hold onto static work space in order to -increase speed by avoiding system memory allocation calls. -The function call $codei% - user_atomic<%Base%>::clear() -%$$ -makes to work space $cref/available/ta_available/$$ to -for other uses by the same thread. -This should be called when you are done using the -user atomic functions for a specific value of $icode Base$$. - -$subhead Restriction$$ -The user atomic $code clear$$ routine cannot be called -while in $cref/parallel/ta_in_parallel/$$ execution mode. - -$children% - example/deprecated/old_reciprocal.cpp% - example/deprecated/old_usead_1.cpp% - example/deprecated/old_usead_2.cpp% - example/deprecated/old_tan.cpp% - example/deprecated/old_mat_mul.cpp -%$$ -$head Example$$ - -$subhead Simple$$ -The file $cref old_reciprocal.cpp$$ contains the simplest example and test -of a user atomic operation. - -$subhead Use AD$$ -The examples -$cref old_usead_1.cpp$$ and $cref old_usead_2.cpp$$ -use AD to compute the derivatives -inside a user defined atomic function. -This may have the advantage of reducing the size of the tape, because -a repeated section of code would only be taped once. - -$subhead Tangent Function$$ -The file $cref old_tan.cpp$$ contains an example and test -implementation of the tangent function as a user atomic operation. - -$subhead Matrix Multiplication$$ -The file $cref old_mat_mul.cpp$$ contains an example and test -implementation of matrix multiplication a a user atomic operation. - -$end ------------------------------------------------------------------------------- -*/ -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file old_atomic.hpp -user defined atomic operations. -*/ - -/*! -\def CPPAD_USER_ATOMIC(afun, Tvector, - forward, reverse, for_jac_sparse, rev_jac_sparse, rev_hes_sparse -) -Defines the function afun(id, ax, ay) -where \c id is \c ax and \c ay are vectors with AD elements. - -\par Tvector -the Simple Vector template class for this function. - -\par Base -the base type for the atomic operation. - -\par afun -name of the CppAD defined function that corresponding to this operation. -Note that \c afun, preceeded by a pound sign, -is a version of \c afun with quotes arround it. - -\par forward -name of the user defined function that computes corresponding -results during forward mode. - -\par reverse -name of the user defined function that computes corresponding -results during reverse mode. - -\par for_jac_sparse -name of the user defined routine that computes corresponding -results during forward mode jacobian sparsity sweeps. - -\par rev_jac_sparse -name of the user defined routine that computes corresponding -results during reverse mode jacobian sparsity sweeps. - -\par rev_hes_sparse -name of the user defined routine that computes corresponding -results during reverse mode Hessian sparsity sweeps. - -\par memory allocation -Note that old_atomic is used as a static object, so its objects -do note get deallocated until the program terminates. -*/ -# define CPPAD_USER_ATOMIC( \ - afun , \ - Tvector , \ - Base , \ - forward , \ - reverse , \ - for_jac_sparse , \ - rev_jac_sparse , \ - rev_hes_sparse \ -) \ -inline void afun ( \ - size_t id , \ - const Tvector< CppAD::AD >& ax , \ - Tvector< CppAD::AD >& ay \ -) \ -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; \ - static CppAD::old_atomic fun( \ - #afun , \ - forward , \ - reverse , \ - for_jac_sparse , \ - rev_jac_sparse , \ - rev_hes_sparse \ - ); \ - fun(id, ax, ay); \ -} - -/// link so that user_atomic::clear() still works -template class user_atomic : public atomic_base { -}; - -/*! -Class that actually implements the afun(id, ax, ay) calls. - -A new old_atomic object is generated each time the user invokes -the CPPAD_USER_ATOMIC macro; see static object in that macro. -*/ -template -class old_atomic : public atomic_base { -public: - /// disable old_atomic::clear(void) - static void clear(void) - { CPPAD_ASSERT_KNOWN( - false, - "Depreacted API uses user_atomic::clear()" - ); - } - /// type for user routine that computes forward mode results - typedef bool (*F) ( - size_t id , - size_t k , - size_t n , - size_t m , - const vector& vx , - vector& vy , - const vector& tx , - vector& ty - ); - /// type for user routine that computes reverse mode results - typedef bool (*R) ( - size_t id , - size_t k , - size_t n , - size_t m , - const vector& tx , - const vector& ty , - vector& px , - const vector& py - ); - /// type for user routine that computes forward mode Jacobian sparsity - typedef bool (*FJS) ( - size_t id , - size_t n , - size_t m , - size_t q , - const vector< std::set >& r , - vector< std::set >& s - ); - /// type for user routine that computes reverse mode Jacobian sparsity - typedef bool (*RJS) ( - size_t id , - size_t n , - size_t m , - size_t q , - vector< std::set >& r , - const vector< std::set >& s - ); - /// type for user routine that computes reverse mode Hessian sparsity - typedef bool (*RHS) ( - size_t id , - size_t n , - size_t m , - size_t q , - const vector< std::set >& r , - const vector& s , - vector& t , - const vector< std::set >& u , - vector< std::set >& v - ); -private: - /// id value corresponding to next virtual callback - size_t id_; - /// user's implementation of forward mode - const F f_; - /// user's implementation of reverse mode - const R r_; - /// user's implementation of forward jacobian sparsity calculations - const FJS fjs_; - /// user's implementation of reverse jacobian sparsity calculations - const RJS rjs_; - /// user's implementation of reverse Hessian sparsity calculations - const RHS rhs_; - -public: - /*! - Constructor called for each invocation of CPPAD_USER_ATOMIC. - - Put this object in the list of all objects for this class and set - the constant private data f_, r_, fjs_, rjs_, rhs_. - - \param afun - is the user's name for the AD version of this atomic operation. - - \param f - user routine that does forward mode calculations for this operation. - - \param r - user routine that does reverse mode calculations for this operation. - - \param fjs - user routine that does forward Jacobian sparsity calculations. - - \param rjs - user routine that does reverse Jacobian sparsity calculations. - - \param rhs - user routine that does reverse Hessian sparsity calculations. - - \par - This constructor can not be used in parallel mode because - atomic_base has this restriction. - */ - old_atomic(const char* afun, F f, R r, FJS fjs, RJS rjs, RHS rhs) : - atomic_base(afun) // name = afun - , f_(f) - , r_(r) - , fjs_(fjs) - , rjs_(rjs) - , rhs_(rhs) - { this->option( atomic_base::set_sparsity_enum ); - } - /*! - Implement the user call to afun(id, ax, ay). - - \tparam ADVector - A simple vector class with elements of type AD. - - \param id - extra information vector that is just passed through by CppAD, - and possibly used by user's routines. - - \param ax - is the argument vector for this call, - ax.size() determines the number of arguments. - - \param ay - is the result vector for this call, - ay.size() determines the number of results. - */ - template - void operator()(size_t id, const ADVector& ax, ADVector& ay) - { // call atomic_base function object - this->atomic_base::operator()(ax, ay, id); - return; - } - /*! - Store id for next virtual function callback - - \param id - id value corresponding to next virtual callback - */ - virtual void set_old(size_t id) - { id_ = id; } - /*! - Link from old_atomic to forward mode - - \copydetails atomic_base::forward - */ - virtual bool forward( - size_t p , - size_t q , - const vector& vx , - vector& vy , - const vector& tx , - vector& ty ) - { CPPAD_ASSERT_UNKNOWN( tx.size() % (q+1) == 0 ); - CPPAD_ASSERT_UNKNOWN( ty.size() % (q+1) == 0 ); - size_t n = tx.size() / (q+1); - size_t m = ty.size() / (q+1); - size_t i, j, k, ell; - - vector x(n * (q+1)); - vector y(m * (q+1)); - vector empty; - - // old_atomic interface can only handel one order at a time - // so must just throuh hoops to get multiple orders at one time. - bool ok = true; - for(k = p; k <= q; k++) - { for(j = 0; j < n; j++) - for(ell = 0; ell <= k; ell++) - x[ j * (k+1) + ell ] = tx[ j * (q+1) + ell ]; - for(i = 0; i < m; i++) - for(ell = 0; ell < k; ell++) - y[ i * (k+1) + ell ] = ty[ i * (q+1) + ell ]; - if( k == 0 ) - ok &= f_(id_, k, n, m, vx, vy, x, y); - else - ok &= f_(id_, k, n, m, empty, empty, x, y); - for(i = 0; i < m; i++) - ty[ i * (q+1) + k ] = y[ i * (k+1) + k]; - } - return ok; - } - /*! - Link from old_atomic to reverse mode - - \copydetails atomic_base::reverse - */ - virtual bool reverse( - size_t q , - const vector& tx , - const vector& ty , - vector& px , - const vector& py ) - { CPPAD_ASSERT_UNKNOWN( tx.size() % (q+1) == 0 ); - CPPAD_ASSERT_UNKNOWN( ty.size() % (q+1) == 0 ); - size_t n = tx.size() / (q+1); - size_t m = ty.size() / (q+1); - bool ok = r_(id_, q, n, m, tx, ty, px, py); - return ok; - } - /*! - Link from forward Jacobian sparsity sweep to old_atomic - - \copydetails atomic_base::for_sparse_jac - */ - virtual bool for_sparse_jac( - size_t q , - const vector< std::set >& r , - vector< std::set >& s , - const vector& x ) - { size_t n = r.size(); - size_t m = s.size(); - bool ok = fjs_(id_, n, m, q, r, s); - return ok; - } - - /*! - Link from reverse Jacobian sparsity sweep to old_atomic. - - \copydetails atomic_base::rev_sparse_jac - */ - virtual bool rev_sparse_jac( - size_t q , - const vector< std::set >& rt , - vector< std::set >& st , - const vector& x ) - { size_t n = st.size(); - size_t m = rt.size(); - bool ok = rjs_(id_, n, m, q, st, rt); - return ok; - } - /*! - Link from reverse Hessian sparsity sweep to old_atomic - - \copydetails atomic_base::rev_sparse_hes - */ - virtual bool rev_sparse_hes( - const vector& vx, - const vector& s , - vector& t , - size_t q , - const vector< std::set >& r , - const vector< std::set >& u , - vector< std::set >& v , - const vector& x ) - { size_t m = u.size(); - size_t n = v.size(); - CPPAD_ASSERT_UNKNOWN( r.size() == n ); - CPPAD_ASSERT_UNKNOWN( s.size() == m ); - CPPAD_ASSERT_UNKNOWN( t.size() == n ); - // - // old interface used id instead of vx - bool ok = rhs_(id_, n, m, q, r, s, t, u, v); - return ok; - } -}; - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/omp_max_thread.hpp b/external/cppad/include/cppad/core/omp_max_thread.hpp deleted file mode 100644 index 134bab745..000000000 --- a/external/cppad/include/cppad/core/omp_max_thread.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_OMP_MAX_THREAD_HPP -# define CPPAD_CORE_OMP_MAX_THREAD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin omp_max_thread$$ -$spell - alloc - num - omp - OpenMp - CppAD -$$ - -$section OpenMP Parallel Setup$$ -$mindex omp_max_thread$$ - -$head Deprecated 2011-06-23$$ -Use $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$ -to set the number of threads. - -$head Syntax$$ -$codei%AD<%Base%>::omp_max_thread(%number%) -%$$ - -$head Purpose$$ -By default, for each $codei%AD<%Base%>%$$ class there is only one -tape that records $cref/AD of Base/glossary/AD of Base/$$ operations. -This tape is a global variable and hence it cannot be used -by multiple OpenMP threads at the same time. -The $code omp_max_thread$$ function is used to set the -maximum number of OpenMP threads that can be active. -In this case, there is a different tape corresponding to each -$codei%AD<%Base%>%$$ class and thread pair. - -$head number$$ -The argument $icode number$$ has prototype -$codei% - size_t %number% -%$$ -It must be greater than zero and specifies the maximum number of -OpenMp threads that will be active at one time. - - -$head Independent$$ -Each call to $cref/Independent(x)/Independent/$$ -creates a new $cref/active/glossary/Tape/Active/$$ tape. -All of the operations with the corresponding variables -must be preformed by the same OpenMP thread. -This includes the corresponding call to -$cref/f.Dependent(x,y)/Dependent/$$ or the -$cref/ADFun f(x, y)/FunConstruct/Sequence Constructor/$$ -during which the tape stops recording and the variables -become parameters. - -$head Restriction$$ -No tapes can be -$cref/active/glossary/Tape/Active/$$ when this function is called. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -void AD::omp_max_thread(size_t number) -{ -# ifdef _OPENMP - thread_alloc::parallel_setup( - number, omp_alloc::in_parallel, omp_alloc::get_thread_num - ); -# else - CPPAD_ASSERT_KNOWN( - number == 1, - "omp_max_thread: number > 1 and _OPENMP is not defined" - ); -# endif - parallel_ad(); -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/opt_val_hes.hpp b/external/cppad/include/cppad/core/opt_val_hes.hpp deleted file mode 100644 index 2c2722adc..000000000 --- a/external/cppad/include/cppad/core/opt_val_hes.hpp +++ /dev/null @@ -1,524 +0,0 @@ -# ifndef CPPAD_CORE_OPT_VAL_HES_HPP -# define CPPAD_CORE_OPT_VAL_HES_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin opt_val_hes$$ -$spell - hes - sy - Jacobian - hes - signdet - jac - Bradley - const - CppAD -$$ - - - -$section Jacobian and Hessian of Optimal Values$$ -$mindex opt_val_hes$$ - -$head Syntax$$ -$icode%signdet% = opt_val_hes(%x%, %y%, %fun%, %jac%, %hes%)%$$ - -$head See Also$$ -$cref BenderQuad$$ - -$head Reference$$ -Algorithmic differentiation of implicit functions and optimal values, -Bradley M. Bell and James V. Burke, Advances in Automatic Differentiation, -2008, Springer. - -$head Purpose$$ -We are given a function -$latex S : \B{R}^n \times \B{R}^m \rightarrow \B{R}^\ell$$ -and we define $latex F : \B{R}^n \times \B{R}^m \rightarrow \B{R}$$ -and $latex V : \B{R}^n \rightarrow \B{R} $$ by -$latex \[ -\begin{array}{rcl} - F(x, y) & = & \sum_{k=0}^{\ell-1} S_k ( x , y) - \\ - V(x) & = & F [ x , Y(x) ] - \\ - 0 & = & \partial_y F [x , Y(x) ] -\end{array} -\] $$ -We wish to compute the Jacobian -and possibly also the Hessian, of $latex V (x)$$. - -$head BaseVector$$ -The type $icode BaseVector$$ must be a -$cref SimpleVector$$ class. -We use $icode Base$$ to refer to the type of the elements of -$icode BaseVector$$; i.e., -$codei% - %BaseVector%::value_type -%$$ - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %BaseVector%& %x% -%$$ -and its size must be equal to $icode n$$. -It specifies the point at which we evaluating -the Jacobian $latex V^{(1)} (x)$$ -(and possibly the Hessian $latex V^{(2)} (x)$$). - - -$head y$$ -The argument $icode y$$ has prototype -$codei% - const %BaseVector%& %y% -%$$ -and its size must be equal to $icode m$$. -It must be equal to $latex Y(x)$$; i.e., -it must solve the implicit equation -$latex \[ - 0 = \partial_y F ( x , y) -\] $$ - -$head Fun$$ -The argument $icode fun$$ is an object of type $icode Fun$$ -which must support the member functions listed below. -CppAD will may be recording operations of the type $codei%AD<%Base%>%$$ -when these member functions are called. -These member functions must not stop such a recording; e.g., -they must not call $cref/AD::abort_recording/abort_recording/$$. - -$subhead Fun::ad_vector$$ -The type $icode%Fun%::ad_vector%$$ must be a -$cref SimpleVector$$ class with elements of type $codei%AD<%Base%>%$$; i.e. -$codei% - %Fun%::ad_vector::value_type -%$$ -is equal to $codei%AD<%Base%>%$$. - -$subhead fun.ell$$ -The type $icode Fun$$ must support the syntax -$codei% - %ell% = %fun%.ell() -%$$ -where $icode ell$$ has prototype -$codei% - size_t %ell% -%$$ -and is the value of $latex \ell$$; i.e., -the number of terms in the summation. -$pre - -$$ -One can choose $icode ell$$ equal to one, and have -$latex S(x,y)$$ the same as $latex F(x, y)$$. -Each of the functions $latex S_k (x , y)$$, -(in the summation defining $latex F(x, y)$$) -is differentiated separately using AD. -For very large problems, breaking $latex F(x, y)$$ into the sum -of separate simpler functions may reduce the amount of memory necessary for -algorithmic differentiation and there by speed up the process. - -$subhead fun.s$$ -The type $icode Fun$$ must support the syntax -$codei% - %s_k% = %fun%.s(%k%, %x%, %y%) -%$$ -The $icode%fun%.s%$$ argument $icode k$$ has prototype -$codei% - size_t %k% -%$$ -and is between zero and $icode%ell% - 1%$$. -The argument $icode x$$ to $icode%fun%.s%$$ has prototype -$codei% - const %Fun%::ad_vector& %x% -%$$ -and its size must be equal to $icode n$$. -The argument $icode y$$ to $icode%fun%.s%$$ has prototype -$codei% - const %Fun%::ad_vector& %y% -%$$ -and its size must be equal to $icode m$$. -The $icode%fun%.s%$$ result $icode s_k$$ has prototype -$codei% - AD<%Base%> %s_k% -%$$ -and its value must be given by $latex s_k = S_k ( x , y )$$. - -$subhead fun.sy$$ -The type $icode Fun$$ must support the syntax -$codei% - %sy_k% = %fun%.sy(%k%, %x%, %y%) -%$$ -The argument $icode k$$ to $icode%fun%.sy%$$ has prototype -$codei% - size_t %k% -%$$ -The argument $icode x$$ to $icode%fun%.sy%$$ has prototype -$codei% - const %Fun%::ad_vector& %x% -%$$ -and its size must be equal to $icode n$$. -The argument $icode y$$ to $icode%fun%.sy%$$ has prototype -$codei% - const %Fun%::ad_vector& %y% -%$$ -and its size must be equal to $icode m$$. -The $icode%fun%.sy%$$ result $icode sy_k$$ has prototype -$codei% - %Fun%::ad_vector %sy_k% -%$$ -its size must be equal to $icode m$$, -and its value must be given by $latex sy_k = \partial_y S_k ( x , y )$$. - -$head jac$$ -The argument $icode jac$$ has prototype -$codei% - %BaseVector%& %jac% -%$$ -and has size $icode n$$ or zero. -The input values of its elements do not matter. -If it has size zero, it is not affected. Otherwise, on output -it contains the Jacobian of $latex V (x)$$; i.e., -for $latex j = 0 , \ldots , n-1$$, -$latex \[ - jac[ j ] = V^{(1)} (x)_j -\] $$ -where $icode x$$ is the first argument to $code opt_val_hes$$. - -$head hes$$ -The argument $icode hes$$ has prototype -$codei% - %BaseVector%& %hes% -%$$ -and has size $icode%n% * %n%$$ or zero. -The input values of its elements do not matter. -If it has size zero, it is not affected. Otherwise, on output -it contains the Hessian of $latex V (x)$$; i.e., -for $latex i = 0 , \ldots , n-1$$, and -$latex j = 0 , \ldots , n-1$$, -$latex \[ - hes[ i * n + j ] = V^{(2)} (x)_{i,j} -\] $$ - - -$head signdet$$ -If $icode%hes%$$ has size zero, $icode signdet$$ is not defined. -Otherwise -the return value $icode signdet$$ is the sign of the determinant for -$latex \partial_{yy}^2 F(x , y) $$. -If it is zero, then the matrix is singular and -the Hessian is not computed ($icode hes$$ is not changed). - -$head Example$$ -$children% - example/general/opt_val_hes.cpp -%$$ -The file -$cref opt_val_hes.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file opt_val_hes.hpp -\brief Computing Jabobians and Hessians of Optimal Values -*/ - -/*! -Computing Jabobians and Hessians of Optimal Values - -We are given a function -\f$ S : {\rm R}^n \times {\rm R}^m \rightarrow {\rm R}^\ell \f$ -and we define \f$ F : {\rm R}^n \times {\rm R}^m \rightarrow {\rm R} \f$ -and \f$ V : {\rm R}^n \rightarrow {\rm R} \f$ by -\f[ -\begin{array}{rcl} - F(x, y) & = & \sum_{k=0}^{\ell-1} S_k ( x , y) - \\ - V(x) & = & F [ x , Y(x) ] - \\ - 0 & = & \partial_y F [x , Y(x) ] -\end{array} -\f] -We wish to compute the Jacobian -and possibly also the Hessian, of \f$ V (x) \f$. - -\tparam BaseVector -The type \c BaseVector must be a SimpleVector class. -We use \c Base to refer to the type of the elements of -\c BaseVector; i.e., -BaseVector::value_type. - -\param x -is a vector with size \c n. -It specifies the point at which we evaluating -the Jacobian \f$ V^{(1)} (x) \f$ -(and possibly the Hessian \f$ V^{(2)} (x) \f$). - - -\param y -is a vector with size \c m. -It must be equal to \f$ Y(x) \f$; i.e., -it must solve the implicit equation -\f[ - 0 = \partial_y F ( x , y) -\f] - -\param fun -The argument \c fun is an object of type \c Fun -wich must support the member functions listed below. -CppAD will may be recording operations of the type \c AD -when these member functions are called. -These member functions must not stop such a recording; e.g., -they must not call \c AD::abort_recording. - -\par Fun::ad_vector -The type Fun::ad_vector must be a -SimpleVector class with elements of type \c AD; i.e. -Fun::ad_vector::value_type -is equal to \c AD. - -\par fun.ell -the type \c Fun must support the syntax -\verbatim - ell = fun.ell() -\endverbatim -where \c ell is a \c size_t value that is set to \f$ \ell \f$; i.e., -the number of terms in the summation. - -\par fun.s -The type \c Fun must support the syntax -\verbatim - s_k = fun.s(k, x, y) -\endverbatim -The argument \c k has prototype size_t k. -The argument \c x has prototype const Fun::ad_vector& x -and its size must be equal to \c n. -The argument \c y has prototype const Fun::ad_vector& y -and its size must be equal to \c m. -The return value \c s_k has prototype \c AD s_k -and its value must be given by \f$ s_k = S_k ( x , y ) \f$. - -\par fun.sy -The type \c Fun must support the syntax -\verbatim - sy_k = fun.sy(k, x, y) -\endverbatim -The argument \c k has prototype size_t k. -The argument \c x has prototype const Fun::ad_vector& x -and its size must be equal to \c n. -The argument \c y has prototype const Fun::ad_vector& y -and its size must be equal to \c m. -The return value \c sy_k has prototype Fun::ad_vector& sy_k, -its size is \c m -and its value must be given by \f$ sy_k = \partial_y S_k ( x , y ) \f$. - -\param jac -is a vector with size \c n or zero. -The input values of its elements do not matter. -If it has size zero, it is not affected. Otherwise, on output -it contains the Jacobian of \f$ V (x) \f$; i.e., -for \f$ j = 0 , \ldots , n-1 \f$, -\f[ - jac[ j ] = V^{(1)} (x)_j -\f] $$ -where \c x is the first argument to \c opt_val_hes. - -\param hes -is a vector with size n * n or zero. -The input values of its elements do not matter. -If it has size zero, it is not affected. Otherwise, on output -it contains the Hessian of \f$ V (x) \f$; i.e., -for \f$ i = 0 , \ldots , n-1 \f$, and -\f$ j = 0 , \ldots , n-1 \f$, -\f[ - hes[ i * n + j ] = V^{(2)} (x)_{i,j} -\f] - -\return -If hes.size() == 0, the return value is not defined. -Otherwise, -the return value is the sign of the determinant for -\f$ \partial_{yy}^2 F(x , y) \f$$. -If it is zero, then the matrix is singular and \c hes is not set -to its specified value. -*/ - - -template -int opt_val_hes( - const BaseVector& x , - const BaseVector& y , - Fun fun , - BaseVector& jac , - BaseVector& hes ) -{ // determine the base type - typedef typename BaseVector::value_type Base; - - // check that BaseVector is a SimpleVector class with Base elements - CheckSimpleVector(); - - // determine the AD vector type - typedef typename Fun::ad_vector ad_vector; - - // check that ad_vector is a SimpleVector class with AD elements - CheckSimpleVector< AD , ad_vector >(); - - // size of the x and y spaces - size_t n = size_t(x.size()); - size_t m = size_t(y.size()); - - // number of terms in the summation - size_t ell = fun.ell(); - - // check size of return values - CPPAD_ASSERT_KNOWN( - size_t(jac.size()) == n || jac.size() == 0, - "opt_val_hes: size of the vector jac is not equal to n or zero" - ); - CPPAD_ASSERT_KNOWN( - size_t(hes.size()) == n * n || hes.size() == 0, - "opt_val_hes: size of the vector hes is not equal to n * n or zero" - ); - - // some temporary indices - size_t i, j, k; - - // AD version of S_k(x, y) - ad_vector s_k(1); - - // ADFun version of S_k(x, y) - ADFun S_k; - - // AD version of x - ad_vector a_x(n); - - // AD version of y - ad_vector a_y(n); - - if( jac.size() > 0 ) - { // this is the easy part, computing the V^{(1)} (x) which is equal - // to \partial_x F (x, y) (see Thoerem 2 of the reference). - - // copy x and y to AD version - for(j = 0; j < n; j++) - a_x[j] = x[j]; - for(j = 0; j < m; j++) - a_y[j] = y[j]; - - // initialize summation - for(j = 0; j < n; j++) - jac[j] = Base(0.); - - // add in \partial_x S_k (x, y) - for(k = 0; k < ell; k++) - { // start recording - Independent(a_x); - // record - s_k[0] = fun.s(k, a_x, a_y); - // stop recording and store in S_k - S_k.Dependent(a_x, s_k); - // compute partial of S_k with respect to x - BaseVector jac_k = S_k.Jacobian(x); - // add \partial_x S_k (x, y) to jac - for(j = 0; j < n; j++) - jac[j] += jac_k[j]; - } - } - // check if we are done - if( hes.size() == 0 ) - return 0; - - /* - In this case, we need to compute the Hessian. Using Theorem 1 of the - reference: - Y^{(1)}(x) = - F_yy (x, y)^{-1} F_yx (x, y) - Using Theorem 2 of the reference: - V^{(2)}(x) = F_xx (x, y) + F_xy (x, y) Y^{(1)}(x) - */ - // Base and AD version of xy - BaseVector xy(n + m); - ad_vector a_xy(n + m); - for(j = 0; j < n; j++) - a_xy[j] = xy[j] = x[j]; - for(j = 0; j < m; j++) - a_xy[n+j] = xy[n+j] = y[j]; - - // Initialization summation for Hessian of F - size_t nm_sq = (n + m) * (n + m); - BaseVector F_hes(nm_sq); - for(j = 0; j < nm_sq; j++) - F_hes[j] = Base(0.); - BaseVector hes_k(nm_sq); - - // add in Hessian of S_k to hes - for(k = 0; k < ell; k++) - { // start recording - Independent(a_xy); - // split out x - for(j = 0; j < n; j++) - a_x[j] = a_xy[j]; - // split out y - for(j = 0; j < m; j++) - a_y[j] = a_xy[n+j]; - // record - s_k[0] = fun.s(k, a_x, a_y); - // stop recording and store in S_k - S_k.Dependent(a_xy, s_k); - // when computing the Hessian it pays to optimize the tape - S_k.optimize(); - // compute Hessian of S_k - hes_k = S_k.Hessian(xy, 0); - // add \partial_x S_k (x, y) to jac - for(j = 0; j < nm_sq; j++) - F_hes[j] += hes_k[j]; - } - // Extract F_yx - BaseVector F_yx(m * n); - for(i = 0; i < m; i++) - { for(j = 0; j < n; j++) - F_yx[i * n + j] = F_hes[ (i+n)*(n+m) + j ]; - } - // Extract F_yy - BaseVector F_yy(n * m); - for(i = 0; i < m; i++) - { for(j = 0; j < m; j++) - F_yy[i * m + j] = F_hes[ (i+n)*(n+m) + j + n ]; - } - - // compute - Y^{(1)}(x) = F_yy (x, y)^{-1} F_yx (x, y) - BaseVector neg_Y_x(m * n); - Base logdet; - int signdet = CppAD::LuSolve(m, n, F_yy, F_yx, neg_Y_x, logdet); - if( signdet == 0 ) - return signdet; - - // compute hes = F_xx (x, y) + F_xy (x, y) Y^{(1)}(x) - for(i = 0; i < n; i++) - { for(j = 0; j < n; j++) - { hes[i * n + j] = F_hes[ i*(n+m) + j ]; - for(k = 0; k < m; k++) - hes[i*n+j] -= F_hes[i*(n+m) + k+n] * neg_Y_x[k*n+j]; - } - } - return signdet; -} - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/optimize.hpp b/external/cppad/include/cppad/core/optimize.hpp deleted file mode 100644 index 872e32aa9..000000000 --- a/external/cppad/include/cppad/core/optimize.hpp +++ /dev/null @@ -1,298 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_OPTIMIZE_HPP -# define CPPAD_CORE_OPTIMIZE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin optimize$$ -$spell - enum - jac - bool - Taylor - CppAD - cppad - std - const - onetape - op -$$ - -$section Optimize an ADFun Object Tape$$ -$mindex sequence operations speed memory NDEBUG$$ - - -$head Syntax$$ -$icode%f%.optimize() -%$$ -$icode%f%.optimize(%options%) -%$$ - -$head Purpose$$ -The operation sequence corresponding to an $cref ADFun$$ object can -be very large and involve many operations; see the -size functions in $cref seq_property$$. -The $icode%f%.optimize%$$ procedure reduces the number of operations, -and thereby the time and the memory, required to -compute function and derivative values. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$head options$$ -This argument has prototype -$codei% - const std::string& %options% -%$$ -The default for $icode options$$ is the empty string. -If it is present, it must consist of one or more of the options below -separated by a single space character. - -$subhead no_conditional_skip$$ -The $code optimize$$ function can create conditional skip operators -to improve the speed of conditional expressions; see -$cref/optimize/CondExp/Optimize/$$. -If the sub-string $code no_conditional_skip$$ appears in $icode options$$, -conditional skip operations are not be generated. -This may make the optimize routine use significantly less memory -and take less time to optimize $icode f$$. -If conditional skip operations are generated, -it may save a significant amount of time when -using $icode f$$ for $cref forward$$ or $cref reverse$$ mode calculations; -see $cref number_skip$$. - -$subhead no_compare_op$$ -If the sub-string $code no_compare_op$$ appears in $icode options$$, -comparison operators will be removed from the optimized function. -These operators are necessary for the -$cref compare_change$$ functions to be meaningful. -On the other hand, they are not necessary, and take extra time, -when the compare_change functions are not used. - -$subhead no_print_for_op$$ -If the sub-string $code no_compare_op$$ appears in $icode options$$, -$cref PrintFor$$ operations will be removed form the optimized function. -These operators are useful for reporting problems evaluating derivatives -at independent variable values different from those used to record a function. - -$head Examples$$ -$children% - example/optimize/forward_active.cpp - %example/optimize/reverse_active.cpp - %example/optimize/compare_op.cpp - %example/optimize/print_for.cpp - %example/optimize/conditional_skip.cpp - %example/optimize/nest_conditional.cpp - %example/optimize/cumulative_sum.cpp -%$$ -$table -$cref/forward_active.cpp/optimize_forward_active.cpp/$$ $cnext - $title optimize_forward_active.cpp$$ -$rnext -$cref/reverse_active.cpp/optimize_reverse_active.cpp/$$ $cnext - $title optimize_reverse_active.cpp$$ -$rnext -$cref/compare_op.cpp/optimize_compare_op.cpp/$$ $cnext - $title optimize_compare_op.cpp$$ -$rnext -$cref/print_for_op.cpp/optimize_print_for.cpp/$$ $cnext - $title optimize_print_for.cpp$$ -$rnext -$cref/conditional_skip.cpp/optimize_conditional_skip.cpp/$$ $cnext - $title optimize_conditional_skip.cpp$$ -$rnext -$cref/nest_conditional.cpp/optimize_nest_conditional.cpp/$$ $cnext - $title optimize_nest_conditional.cpp$$ -$rnext -$cref/cumulative_sum.cpp/optimize_cumulative_sum.cpp/$$ $cnext - $title optimize_cumulative_sum.cpp$$ -$tend - -$head Efficiency$$ -If a $cref/zero order forward/forward_zero/$$ calculation is done during -the construction of $icode f$$, it will require more memory -and time than required after the optimization procedure. -In addition, it will need to be redone. -For this reason, it is more efficient to use -$codei% - ADFun<%Base%> %f%; - %f%.Dependent(%x%, %y%); - %f%.optimize(); -%$$ -instead of -$codei% - ADFun<%Base%> %f%(%x%, %y%) - %f%.optimize(); -%$$ -See the discussion about -$cref/sequence constructors/FunConstruct/Sequence Constructor/$$. - -$head Speed Testing$$ -You can run the CppAD $cref/speed/speed_main/$$ tests and see -the corresponding changes in number of variables and execution time. -Note that there is an interaction between using -$cref/optimize/speed_main/Global Options/optimize/$$ and -$cref/onetape/speed_main/Global Options/onetape/$$. -If $icode onetape$$ is true and $icode optimize$$ is true, -the optimized tape will be reused many times. -If $icode onetape$$ is false and $icode optimize$$ is true, -the tape will be re-optimized for each test. - -$head Atomic Functions$$ -There are some subtitle issue with optimized $cref atomic$$ functions -$latex v = g(u)$$: - -$subhead rev_sparse_jac$$ -The $cref atomic_rev_sparse_jac$$ function is be used to determine -which components of $icode u$$ affect the dependent variables of $icode f$$. -For each atomic operation, the current -$cref/atomic_sparsity/atomic_option/atomic_sparsity/$$ setting is used -to determine if $code pack_sparsity_enum$$, $code bool_sparsity_enum$$, -or $code set_sparsity_enum$$ is used to determine dependency relations -between argument and result variables. - -$subhead nan$$ -If $icode%u%[%i%]%$$ does not affect the value of -the dependent variables for $icode f$$, -the value of $icode%u%[%i%]%$$ is set to $cref nan$$. - -$head Checking Optimization$$ -If $cref/NDEBUG/Faq/Speed/NDEBUG/$$ is not defined, -and $cref/f.size_order()/size_order/$$ is greater than zero, -a $cref forward_zero$$ calculation is done using the optimized version -of $icode f$$ and the results are checked to see that they are -the same as before. -If they are not the same, the -$cref ErrorHandler$$ is called with a known error message -related to $icode%f%.optimize()%$$. - -$end ------------------------------------------------------------------------------ -*/ -# include -/*! -\file optimize.hpp -Optimize a player object operation sequence -*/ -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -Optimize a player object operation sequence - -The operation sequence for this object is replaced by one with fewer operations -but the same funcition and derivative values. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD and computations by this routine are done using type -\a Base. - -\param options -\li -If the sub-string "no_conditional_skip" appears, -conditional skip operations will not be generated. -This may make the optimize routine use significantly less memory -and take significantly less time. -\li -If the sub-string "no_compare_op" appears, -then comparison operators will be removed from the optimized tape. -These operators are necessary for the compare_change function to be -be meaningful in the resulting recording. -On the other hand, they are not necessary and take extra time -when compare_change is not used. -*/ -template -void ADFun::optimize(const std::string& options) -{ // place to store the optimized version of the recording - local::recorder rec; - - // number of independent variables - size_t n = ind_taddr_.size(); - -# ifndef NDEBUG - size_t i, j, m = dep_taddr_.size(); - CppAD::vector x(n), y(m), check(m); - Base max_taylor(0); - bool check_zero_order = num_order_taylor_ > 0; - if( check_zero_order ) - { // zero order coefficients for independent vars - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( play_.GetOp(j+1) == local::InvOp ); - CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j+1 ); - x[j] = taylor_[ ind_taddr_[j] * cap_order_taylor_ + 0]; - } - // zero order coefficients for dependent vars - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - y[i] = taylor_[ dep_taddr_[i] * cap_order_taylor_ + 0]; - } - // maximum zero order coefficient not counting BeginOp at beginning - // (which is correpsonds to uninitialized memory). - for(i = 1; i < num_var_tape_; i++) - { if( abs_geq(taylor_[i*cap_order_taylor_+0] , max_taylor) ) - max_taylor = taylor_[i*cap_order_taylor_+0]; - } - } -# endif - - // create the optimized recording - local::optimize::optimize_run(options, n, dep_taddr_, &play_, &rec); - - // number of variables in the recording - num_var_tape_ = rec.num_var_rec(); - - // now replace the recording - play_.get(rec); - - // set flag so this function knows it has been optimized - has_been_optimized_ = true; - - // free memory allocated for sparse Jacobian calculation - // (the results are no longer valid) - for_jac_sparse_pack_.resize(0, 0); - for_jac_sparse_set_.resize(0,0); - - // free old Taylor coefficient memory - taylor_.free(); - num_order_taylor_ = 0; - cap_order_taylor_ = 0; - - // resize and initilaize conditional skip vector - // (must use player size because it now has the recoreder information) - cskip_op_.erase(); - cskip_op_.extend( play_.num_op_rec() ); - -# ifndef NDEBUG - if( check_zero_order ) - { - // zero order forward calculation using new operation sequence - check = Forward(0, x); - - // check results - Base eps = 10. * CppAD::numeric_limits::epsilon(); - for(i = 0; i < m; i++) CPPAD_ASSERT_KNOWN( - abs_geq( eps * max_taylor , check[i] - y[i] ) , - "Error during check of f.optimize()." - ); - - // Erase memory that this calculation was done so NDEBUG gives - // same final state for this object (from users perspective) - num_order_taylor_ = 0; - } -# endif -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/ordered.hpp b/external/cppad/include/cppad/core/ordered.hpp deleted file mode 100644 index 377ba60bf..000000000 --- a/external/cppad/include/cppad/core/ordered.hpp +++ /dev/null @@ -1,102 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_ORDERED_HPP -# define CPPAD_CORE_ORDERED_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -\file ordered.hpp -Check and AD values ordering properties relative to zero. -*/ - -// GreaterThanZero ============================================================ -/*! -Check if an AD is greater than zero. - -\param x -value we are checking. - -\return -returns true iff the \c x is greater than zero. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool GreaterThanZero(const AD &x) -{ return GreaterThanZero(x.value_); } -// GreaterThanOrZero ========================================================= -/*! -Check if an AD is greater than or equal zero. - -\param x -value we are checking. - -\return -returns true iff the \c x is greater than or equal zero. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool GreaterThanOrZero(const AD &x) -{ return GreaterThanOrZero(x.value_); } -// LessThanZero ============================================================ -/*! -Check if an AD is less than zero. - -\param x -value we are checking. - -\return -returns true iff the \c x is less than zero. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool LessThanZero(const AD &x) -{ return LessThanZero(x.value_); } -// LessThanOrZero ========================================================= -/*! -Check if an AD is less than or equal zero. - -\param x -value we are checking. - -\return -returns true iff the \c x is less than or equal zero. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool LessThanOrZero(const AD &x) -{ return LessThanOrZero(x.value_); } -// abs_geq ========================================================= -/*! -Check if absolute value of one AD is greater or equal another. - -\param x -value we are checking if it is greater than or equal other. - -\param y -value we are checking if it is less than other. - -\return -returns true iff the absolute value of \c x is greater than or equal -absolute value of \c y. -*/ -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -bool abs_geq(const AD& x, const AD& y) -{ return abs_geq(x.value_, y.value_); } -// ============================================================================ -} // END_CPPAD_NAMESPACE -# endif - diff --git a/external/cppad/include/cppad/core/par_var.hpp b/external/cppad/include/cppad/core/par_var.hpp deleted file mode 100644 index 00483afed..000000000 --- a/external/cppad/include/cppad/core/par_var.hpp +++ /dev/null @@ -1,118 +0,0 @@ -# ifndef CPPAD_CORE_PAR_VAR_HPP -# define CPPAD_CORE_PAR_VAR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* ---------------------------------------------------------------------------- - -$begin ParVar$$ -$spell - VecAD - const - bool -$$ - -$section Is an AD Object a Parameter or Variable$$ - -$head Syntax$$ -$icode%b% = Parameter(%x%)%$$ -$pre -$$ -$icode%b% = Variable(%x%)%$$ - - -$head Purpose$$ -Determine if $icode x$$ is a -$cref/parameter/glossary/Parameter/$$ or -$cref/variable/glossary/Variable/$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &%x% - const VecAD<%Base%> &%x% -%$$ - -$head b$$ -The return value $icode b$$ has prototype -$codei% - bool %b% -%$$ -The return value for $code Parameter$$ ($code Variable$$) -is true if and only if $icode x$$ is a parameter (variable). -Note that a $cref/VecAD/VecAD/$$ object -is a variable if any element of the vector depends on the independent -variables. - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/par_var.cpp -%$$ -The file -$cref par_var.cpp$$ -contains an example and test of these functions. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -namespace CppAD { - // Parameter - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - bool Parameter(const AD &x) - { if( x.tape_id_ == 0 ) - return true; - size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS); - return x.tape_id_ != *AD::tape_id_ptr(thread); - } - - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - bool Parameter(const VecAD &x) - { if( x.tape_id_ == 0 ) - return true; - size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS); - return x.tape_id_ != *AD::tape_id_ptr(thread); - } - - // Variable - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - bool Variable(const AD &x) - { if( x.tape_id_ == 0 ) - return false; - size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS); - return x.tape_id_ == *AD::tape_id_ptr(thread); - } - - template - CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION - bool Variable(const VecAD &x) - { if( x.tape_id_ == 0 ) - return false; - size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS); - return x.tape_id_ == *AD::tape_id_ptr(thread); - } -} -// END CppAD namespace - - -# endif diff --git a/external/cppad/include/cppad/core/parallel_ad.hpp b/external/cppad/include/cppad/core/parallel_ad.hpp deleted file mode 100644 index faa430462..000000000 --- a/external/cppad/include/cppad/core/parallel_ad.hpp +++ /dev/null @@ -1,118 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_PARALLEL_AD_HPP -# define CPPAD_CORE_PARALLEL_AD_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin parallel_ad$$ -$spell - CppAD - num - std -$$ - -$section Enable AD Calculations During Parallel Mode$$ - -$head Syntax$$ -$codei%parallel_ad<%Base%>()%$$ - -$head Purpose$$ -The function -$codei%parallel_ad<%Base%>()%$$ -must be called before any $codei%AD<%Base>%$$ objects are used -in $cref/parallel/ta_in_parallel/$$ mode. -In addition, if this routine is called after one is done using -parallel mode, it will free extra memory used to keep track of -the multiple $codei%AD<%Base%>%$$ tapes required for parallel execution. - -$head Discussion$$ -By default, for each $codei%AD<%Base%>%$$ class there is only one -tape that records $cref/AD of Base/glossary/AD of Base/$$ operations. -This tape is a global variable and hence it cannot be used -by multiple threads at the same time. -The $cref/parallel_setup/ta_parallel_setup/$$ function informs CppAD of the -maximum number of threads that can be active in parallel mode. -This routine does extra setup -(and teardown) for the particular $icode Base$$ type. - -$head CheckSimpleVector$$ -This routine has the side effect of calling the routines -$codei% - CheckSimpleVector< %Type%, CppAD::vector<%Type%> >() -%$$ -where $icode Type$$ is $icode Base$$ and $codei%AD<%Base%>%$$. - -$head Example$$ -The files -$cref team_openmp.cpp$$, -$cref team_bthread.cpp$$, and -$cref team_pthread.cpp$$, -contain examples and tests that implement this function. - -$head Restriction$$ -This routine cannot be called in parallel mode or while -there is a tape recording $codei%AD<%Base%>%$$ operations. - -$end ------------------------------------------------------------------------------ -*/ - -# include - -// BEGIN CppAD namespace -namespace CppAD { - -/*! -Enable parallel execution mode with AD by initializing -static variables that my be used. -*/ - -template -void parallel_ad(void) -{ CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "parallel_ad must be called before entering parallel execution mode." - ); - CPPAD_ASSERT_KNOWN( - AD::tape_ptr() == CPPAD_NULL , - "parallel_ad cannot be called while a tape recording is in progress" - ); - - // ensure statics in following functions are initialized - elapsed_seconds(); - ErrorHandler::Current(); - local::NumArg(local::BeginOp); - local::NumRes(local::BeginOp); - local::one_element_std_set(); - local::two_element_std_set(); - - // the sparse_pack class has member functions with static data - local::sparse_pack sp; - sp.resize(1, 1); // so can call add_element - sp.add_element(0, 0); // has static data - sp.clear(0); // has static data - sp.is_element(0, 0); // has static data - local::sparse_pack::const_iterator itr(sp, 0); // has static data - ++itr; // has static data - - // statics that depend on the value of Base - AD::tape_id_handle(0); - AD::tape_handle(0); - AD::tape_manage(tape_manage_clear); - discrete::List(); - CheckSimpleVector< Base, CppAD::vector >(); - CheckSimpleVector< AD, CppAD::vector< AD > >(); - -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/pow.hpp b/external/cppad/include/cppad/core/pow.hpp deleted file mode 100644 index 237da9d78..000000000 --- a/external/cppad/include/cppad/core/pow.hpp +++ /dev/null @@ -1,257 +0,0 @@ -# ifndef CPPAD_CORE_POW_HPP -# define CPPAD_CORE_POW_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin pow$$ -$spell - Vec - std - namespace - CppAD - const -$$ - - -$section The AD Power Function$$ -$mindex pow exponent$$ - -$head Syntax$$ -$icode%z% = pow(%x%, %y%)%$$ - -$head See Also$$ -$cref pow_int$$ - - -$head Purpose$$ -Determines the value of the power function which is defined by -$latex \[ - {\rm pow} (x, y) = x^y -\] $$ -This version of the $code pow$$ function may use -logarithms and exponentiation to compute derivatives. -This will not work if $icode x$$ is less than or equal zero. -If the value of $icode y$$ is an integer, -the $cref pow_int$$ function is used to compute this value -using only multiplication (and division if $icode y$$ is negative). -(This will work even if $icode x$$ is less than or equal zero.) - -$head x$$ -The argument $icode x$$ has one of the following prototypes -$codei% - const %Base%& %x% - const AD<%Base%>& %x% - const VecAD<%Base%>::reference& %x% -%$$ - -$head y$$ -The argument $icode y$$ has one of the following prototypes -$codei% - const %Base%& %y% - const AD<%Base%>& %y% - const VecAD<%Base%>::reference& %y% -%$$ - -$head z$$ -If both $icode x$$ and $icode y$$ are $icode Base$$ objects, -the result $icode z$$ is also a $icode Base$$ object. -Otherwise, it has prototype -$codei% - AD<%Base%> %z% -%$$ - -$head Operation Sequence$$ -This is an AD of $icode Base$$ -$cref/atomic operation/glossary/Operation/Atomic/$$ -and hence is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Example$$ -$children% - example/general/pow.cpp -%$$ -The file -$cref pow.cpp$$ -is an examples and tests of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -// case where x and y are AD ----------------------------------------- -template AD -pow(const AD& x, const AD& y) -{ - // compute the Base part - AD result; - result.value_ = pow(x.value_, y.value_); - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return result; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_x = x.tape_id_ == tape_id; - bool var_y = y.tape_id_ == tape_id; - - if( var_x ) - { if( var_y ) - { // result = variable^variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::PowvvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::PowvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(x.taddr_, y.taddr_); - - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::PowvvOp); - - // make result a variable - result.tape_id_ = tape_id; - } - else if( IdenticalZero( y.value_ ) ) - { // result = variable^0 - } - else - { // result = variable^parameter - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::PowvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::PowvpOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(y.value_); - tape->Rec_.PutArg(x.taddr_, p); - - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::PowvpOp); - - // make result a variable - result.tape_id_ = tape_id; - } - } - else if( var_y ) - { if( IdenticalZero(x.value_) ) - { // result = 0^variable - } - else - { // result = parameter^variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::PowpvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::PowpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(x.value_); - tape->Rec_.PutArg(p, y.taddr_); - - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::PowpvOp); - - // make result a variable - result.tape_id_ = tape_id; - } - } - return result; -} -// ========================================================================= -// Fold operations in same way as CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(Op) -// ------------------------------------------------------------------------- -// Operations with VecAD_reference and AD only - -template AD -pow(const AD& x, const VecAD_reference& y) -{ return pow(x, y.ADBase()); } - -template AD -pow(const VecAD_reference& x, const VecAD_reference& y) -{ return pow(x.ADBase(), y.ADBase()); } - -template AD -pow(const VecAD_reference& x, const AD& y) -{ return pow(x.ADBase(), y); } -// ------------------------------------------------------------------------- -// Operations with Base - -template AD -pow(const Base& x, const AD& y) -{ return pow(AD(x), y); } - -template AD -pow(const Base& x, const VecAD_reference& y) -{ return pow(AD(x), y.ADBase()); } - -template AD -pow(const AD& x, const Base& y) -{ return pow(x, AD(y)); } - -template AD -pow(const VecAD_reference& x, const Base& y) -{ return pow(x.ADBase(), AD(y)); } -// ------------------------------------------------------------------------- -// Operations with double - -template AD -pow(const double& x, const AD& y) -{ return pow(AD(x), y); } - -template AD -pow(const double& x, const VecAD_reference& y) -{ return pow(AD(x), y.ADBase()); } - -template AD -pow(const AD& x, const double& y) -{ return pow(x, AD(y)); } - -template AD -pow(const VecAD_reference& x, const double& y) -{ return pow(x.ADBase(), AD(y)); } -// ------------------------------------------------------------------------- -// Special case to avoid ambuigity when Base is double - -inline AD -pow(const double& x, const AD& y) -{ return pow(AD(x), y); } - -inline AD -pow(const double& x, const VecAD_reference& y) -{ return pow(AD(x), y.ADBase()); } - -inline AD -pow(const AD& x, const double& y) -{ return pow(x, AD(y)); } - -inline AD -pow(const VecAD_reference& x, const double& y) -{ return pow(x.ADBase(), AD(y)); } - -// ========================================================================= -// Fold operations for the cases where x is an int, -// but let cppad/utility/pow_int.hpp handle the cases where y is an int. -// ------------------------------------------------------------------------- -template AD pow -(const int& x, const VecAD_reference& y) -{ return pow(AD(x), y.ADBase()); } - -template AD pow -(const int& x, const AD& y) -{ return pow(AD(x), y); } - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/print_for.hpp b/external/cppad/include/cppad/core/print_for.hpp deleted file mode 100644 index 0ae937e1e..000000000 --- a/external/cppad/include/cppad/core/print_for.hpp +++ /dev/null @@ -1,219 +0,0 @@ -# ifndef CPPAD_CORE_PRINT_FOR_HPP -# define CPPAD_CORE_PRINT_FOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin PrintFor$$ -$spell - pos - var - VecAD - std - cout - const -$$ - - -$section Printing AD Values During Forward Mode$$ -$mindex print text output debug$$ - -$head Syntax$$ -$icode%f%.Forward(0, %x%) -%$$ -$codei%PrintFor(%before%, %var%) -%$$ -$codei%PrintFor(%pos%, %before%, %var%, %after%) -%$$ - -$head Purpose$$ -The $cref/zero order forward/forward_zero/$$ mode command -$codei% - %f%.Forward(0, %x%) -%$$ -assigns the -$cref/independent variable/glossary/Tape/Independent Variable/$$ vector -equal to $icode x$$. -It then computes a value for all of the dependent variables in the -$cref/operation sequence/glossary/Operation/Sequence/$$ corresponding -to $icode f$$. -Putting a $code PrintFor$$ in the operation sequence will -cause the value of $icode var$$, corresponding to $icode x$$, -to be printed during zero order forward operations. - -$head f.Forward(0, x)$$ -The objects $icode f$$, $icode x$$, and the purpose -for this operation, are documented in $cref Forward$$. - -$head pos$$ -If present, the argument $icode pos$$ has one of the following prototypes -$codei% - const AD<%Base%>& %pos% - const VecAD<%Base%>::reference& %pos% -%$$ -In this case -the text and $icode var$$ will be printed if and only if -$icode pos$$ is not greater than zero and a finite number. - -$head before$$ -The argument $icode before$$ has prototype -$codei% - const char* %before% -%$$ -This text is written to $code std::cout$$ before $icode var$$. - -$head var$$ -The argument $icode var$$ has one of the following prototypes -$codei% - const AD<%Base%>& %var% - const VecAD<%Base%>::reference& %var% -%$$ -The value of $icode var$$, that corresponds to $icode x$$, -is written to $code std::cout$$ during the execution of -$codei% - %f%.Forward(0, %x%) -%$$ -Note that $icode var$$ may be a -$cref/variable/glossary/Variable/$$ or -$cref/parameter/glossary/Parameter/$$. -(A parameters value does not depend on the value of -the independent variable vector $icode x$$.) - -$head after$$ -The argument $icode after$$ has prototype -$codei% - const char* %after% -%$$ -This text is written to $code std::cout$$ after $icode var$$. - -$head Redirecting Output$$ -You can redirect this output to any standard output stream; see the -$cref/s/forward_order/s/$$ in the forward mode documentation. - -$head Discussion$$ -This is helpful for understanding why tape evaluations -have trouble. -For example, if one of the operations in $icode f$$ is -$codei%log(%var%)%$$ and $icode%var% <= 0%$$, -the corresponding result will be $cref nan$$. - -$head Alternative$$ -The $cref ad_output$$ section describes the normal -printing of values; i.e., printing when the corresponding -code is executed. - -$head Example$$ -$children% - example/print_for/print_for.cpp% - example/general/print_for.cpp -%$$ -The program -$cref print_for_cout.cpp$$ -is an example and test that prints to standard output. -The output of this program -states the conditions for passing and failing the test. -The function -$cref print_for_string.cpp$$ -is an example and test that prints to an standard string stream. -This function automatically check for correct output. - -$end ------------------------------------------------------------------------------- -*/ - -# include - -namespace CppAD { - template - void PrintFor(const AD& pos, - const char *before, const AD& var, const char* after) - { CPPAD_ASSERT_NARG_NRES(local::PriOp, 5, 0); - - // check for case where we are not recording operations - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return; - - CPPAD_ASSERT_KNOWN( - std::strlen(before) <= 1000 , - "PrintFor: length of before is greater than 1000 characters" - ); - CPPAD_ASSERT_KNOWN( - std::strlen(after) <= 1000 , - "PrintFor: length of after is greater than 1000 characters" - ); - addr_t ind0, ind1, ind2, ind3, ind4; - - // ind[0] = base 2 representation of the value [Var(pos), Var(var)] - ind0 = 0; - - // ind[1] = address for pos - if( Parameter(pos) ) - ind1 = tape->Rec_.PutPar(pos.value_); - else - { ind0 += 1; - ind1 = pos.taddr_; - } - - // ind[2] = address of before - ind2 = tape->Rec_.PutTxt(before); - - // ind[3] = address for var - if( Parameter(var) ) - ind3 = tape->Rec_.PutPar(var.value_); - else - { ind0 += 2; - ind3 = var.taddr_; - } - - // ind[4] = address of after - ind4 = tape->Rec_.PutTxt(after); - - // put the operator in the tape - tape->Rec_.PutArg(ind0, ind1, ind2, ind3, ind4); - tape->Rec_.PutOp(local::PriOp); - } - // Fold all other cases into the case above - template - void PrintFor(const char* before, const AD& var) - { PrintFor(AD(0), before, var, "" ); } - // - template - void PrintFor(const char* before, const VecAD_reference& var) - { PrintFor(AD(0), before, var.ADBase(), "" ); } - // - template - void PrintFor( - const VecAD_reference& pos , - const char *before , - const VecAD_reference& var , - const char *after ) - { PrintFor(pos.ADBase(), before, var.ADBase(), after); } - // - template - void PrintFor( - const VecAD_reference& pos , - const char *before , - const AD& var , - const char *after ) - { PrintFor(pos.ADBase(), before, var, after); } - // - template - void PrintFor( - const AD& pos , - const char *before , - const VecAD_reference& var , - const char *after ) - { PrintFor(pos, before, var.ADBase(), after); } -} - -# endif diff --git a/external/cppad/include/cppad/core/rev_hes_sparsity.hpp b/external/cppad/include/cppad/core/rev_hes_sparsity.hpp deleted file mode 100644 index c1a9c2d68..000000000 --- a/external/cppad/include/cppad/core/rev_hes_sparsity.hpp +++ /dev/null @@ -1,251 +0,0 @@ -# ifndef CPPAD_CORE_REV_HES_SPARSITY_HPP -# define CPPAD_CORE_REV_HES_SPARSITY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin rev_hes_sparsity$$ -$spell - Jacobian - Hessian - jac - hes - bool - const - rc - cpp -$$ - -$section Reverse Mode Hessian Sparsity Patterns$$ - -$head Syntax$$ -$icode%f%.rev_hes_sparsity( - %select_range%, %transpose%, %internal_bool%, %pattern_out% -)%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to -the operation sequence stored in $icode f$$. -Fix $latex R \in \B{R}^{n \times \ell}$$, $latex s \in \B{R}^m$$ -and define the function -$latex \[ - H(x) = ( s^\R{T} F )^{(2)} ( x ) R -\] $$ -Given a $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex R$$ -and for the vector $latex s$$, -$code rev_hes_sparsity$$ computes a sparsity pattern for $latex H(x)$$. - -$head x$$ -Note that the sparsity pattern $latex H(x)$$ corresponds to the -operation sequence stored in $icode f$$ and does not depend on -the argument $icode x$$. - -$head BoolVector$$ -The type $icode BoolVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$. - -$head SizeVector$$ -The type $icode SizeVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$head R$$ -The sparsity pattern for the matrix $latex R$$ is specified by -$cref/pattern_in/for_jac_sparsity/pattern_in/$$ in the previous call -$codei% - %f%.for_jac_sparsity( - %pattern_in%, %transpose%, %dependency%, %internal_bool%, %pattern_out% -)%$$ - -$head select_range$$ -The argument $icode select_range$$ has prototype -$codei% - const %BoolVector%& %select_range% -%$$ -It has size $latex m$$ and specifies which components of the vector -$latex s$$ are non-zero; i.e., $icode%select_range%[%i%]%$$ is true -if and only if $latex s_i$$ is possibly non-zero. - -$head transpose$$ -This argument has prototype -$codei% - bool %transpose% -%$$ -See $cref/pattern_out/rev_hes_sparsity/pattern_out/$$ below. - -$head internal_bool$$ -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of sets of integers is used. -This must be the same as in the previous call to -$icode%f%.for_jac_sparsity%$$. - -$head pattern_out$$ -This argument has prototype -$codei% - sparse_rc<%SizeVector%>& %pattern_out% -%$$ -This input value of $icode pattern_out$$ does not matter. -If $icode transpose$$ it is false (true), -upon return $icode pattern_out$$ is a sparsity pattern for -$latex H(x)$$ ($latex H(x)^\R{T}$$). - -$head Sparsity for Entire Hessian$$ -Suppose that $latex R$$ is the $latex n \times n$$ identity matrix. -In this case, $icode pattern_out$$ is a sparsity pattern for -$latex (s^\R{T} F) F^{(2)} ( x )$$. - -$head Example$$ -$children% - example/sparse/rev_hes_sparsity.cpp -%$$ -The file -$cref rev_hes_sparsity.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -Reverse Hessian sparsity patterns. - -\tparam Base -is the base type for this recording. - -\tparam BoolVector -is the simple vector with elements of type bool that is used for -sparsity for the vector s. - -\tparam SizeVector -is the simple vector with elements of type size_t that is used for -row, column index sparsity patterns. - -\param select_range -is a sparsity pattern for for s. - -\param transpose -Is the returned sparsity pattern transposed. - -\param internal_bool -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of standard sets is used. - -\param pattern_out -The value of transpose is false (true), -the return value is a sparsity pattern for H(x) ( H(x)^T ) where -\f[ - H(x) = R * F^{(1)} (x) -\f] -Here F is the function corresponding to the operation sequence -and x is any argument value. -*/ -template -template -void ADFun::rev_hes_sparsity( - const BoolVector& select_range , - bool transpose , - bool internal_bool , - sparse_rc& pattern_out ) -{ size_t n = Domain(); - size_t m = Range(); - // - CPPAD_ASSERT_KNOWN( - size_t( select_range.size() ) == m, - "rev_hes_sparsity: size of select_range is not equal to " - "number of dependent variables" - ); - // - // vector that holds reverse Jacobian sparsity flag - local::pod_vector rev_jac_pattern; - rev_jac_pattern.extend(num_var_tape_); - for(size_t i = 0; i < num_var_tape_; i++) - rev_jac_pattern[i] = false; - // - // initialize rev_jac_pattern for dependent variables - for(size_t i = 0; i < m; i++) - rev_jac_pattern[ dep_taddr_[i] ] = select_range[i]; - // - // - if( internal_bool ) - { CPPAD_ASSERT_KNOWN( - for_jac_sparse_pack_.n_set() > 0, - "rev_hes_sparsity: previous call to for_jac_sparsity did not " - "use bool for interanl sparsity patterns." - ); - // column dimension of internal sparstiy pattern - size_t ell = for_jac_sparse_pack_.end(); - // - // allocate memory for bool sparsity calculation - // (sparsity pattern is emtpy after a resize) - local::sparse_pack internal_hes; - internal_hes.resize(num_var_tape_, ell); - // - // compute the Hessian sparsity pattern - local::RevHesSweep( - n, - num_var_tape_, - &play_, - for_jac_sparse_pack_, - rev_jac_pattern.data(), - internal_hes - - ); - // get sparstiy pattern for independent variables - local::get_internal_sparsity( - transpose, ind_taddr_, internal_hes, pattern_out - ); - } - else - { CPPAD_ASSERT_KNOWN( - for_jac_sparse_set_.n_set() > 0, - "rev_hes_sparsity: previous call to for_jac_sparsity did not " - "use bool for interanl sparsity patterns." - ); - // column dimension of internal sparstiy pattern - size_t ell = for_jac_sparse_set_.end(); - // - // allocate memory for bool sparsity calculation - // (sparsity pattern is emtpy after a resize) - local::sparse_list internal_hes; - internal_hes.resize(num_var_tape_, ell); - // - // compute the Hessian sparsity pattern - local::RevHesSweep( - n, - num_var_tape_, - &play_, - for_jac_sparse_set_, - rev_jac_pattern.data(), - internal_hes - - ); - // get sparstiy pattern for independent variables - local::get_internal_sparsity( - transpose, ind_taddr_, internal_hes, pattern_out - ); - } - return; -} -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/rev_jac_sparsity.hpp b/external/cppad/include/cppad/core/rev_jac_sparsity.hpp deleted file mode 100644 index b9edb60e3..000000000 --- a/external/cppad/include/cppad/core/rev_jac_sparsity.hpp +++ /dev/null @@ -1,251 +0,0 @@ -# ifndef CPPAD_CORE_REV_JAC_SPARSITY_HPP -# define CPPAD_CORE_REV_JAC_SPARSITY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin rev_jac_sparsity$$ -$spell - Jacobian - jac - bool - const - rc - cpp -$$ - -$section Reverse Mode Jacobian Sparsity Patterns$$ - -$head Syntax$$ -$icode%f%.rev_jac_sparsity( - %pattern_in%, %transpose%, %dependency%, %internal_bool%, %pattern_out% -)%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to -the operation sequence stored in $icode f$$. -Fix $latex R \in \B{R}^{\ell \times m}$$ and define the function -$latex \[ - J(x) = R * F^{(1)} ( x ) -\] $$ -Given the $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for $latex R$$, -$code rev_jac_sparsity$$ computes a sparsity pattern for $latex J(x)$$. - -$head x$$ -Note that the sparsity pattern $latex J(x)$$ corresponds to the -operation sequence stored in $icode f$$ and does not depend on -the argument $icode x$$. -(The operation sequence may contain -$cref CondExp$$ and $cref VecAD$$ operations.) - -$head SizeVector$$ -The type $icode SizeVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$head pattern_in$$ -The argument $icode pattern_in$$ has prototype -$codei% - const sparse_rc<%SizeVector%>& %pattern_in% -%$$ -see $cref sparse_rc$$. -If $icode transpose$$ it is false (true), -$icode pattern_in$$ is a sparsity pattern for $latex R$$ ($latex R^\R{T}$$). - -$head transpose$$ -This argument has prototype -$codei% - bool %transpose% -%$$ -See $cref/pattern_in/rev_jac_sparsity/pattern_in/$$ above and -$cref/pattern_out/rev_jac_sparsity/pattern_out/$$ below. - -$head dependency$$ -This argument has prototype -$codei% - bool %dependency% -%$$ -see $cref/pattern_out/rev_jac_sparsity/pattern_out/$$ below. - -$head internal_bool$$ -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of sets of integers is used. - -$head pattern_out$$ -This argument has prototype -$codei% - sparse_rc<%SizeVector%>& %pattern_out% -%$$ -This input value of $icode pattern_out$$ does not matter. -If $icode transpose$$ it is false (true), -upon return $icode pattern_out$$ is a sparsity pattern for -$latex J(x)$$ ($latex J(x)^\R{T}$$). -If $icode dependency$$ is true, $icode pattern_out$$ is a -$cref/dependency pattern/dependency.cpp/Dependency Pattern/$$ -instead of sparsity pattern. - -$head Sparsity for Entire Jacobian$$ -Suppose that -$latex R$$ is the $latex m \times m$$ identity matrix. -In this case, $icode pattern_out$$ is a sparsity pattern for -$latex F^{(1)} ( x )$$ ( $latex F^{(1)} (x)^\R{T}$$ ) -if $icode transpose$$ is false (true). - -$head Example$$ -$children% - example/sparse/rev_jac_sparsity.cpp -%$$ -The file -$cref rev_jac_sparsity.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -Reverse Jacobian sparsity patterns. - -\tparam Base -is the base type for this recording. - -\tparam SizeVector -is the simple vector with elements of type size_t that is used for -row, column index sparsity patterns. - -\param pattern_in -is the sparsity pattern for for R or R^T depending on transpose. - -\param transpose -Is the input and returned sparsity pattern transposed. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param internal_bool -If this is true, calculations are done with sets represented by a vector -of boolean values. Otherwise, a vector of standard sets is used. - -\param pattern_out -The value of transpose is false (true), -the return value is a sparsity pattern for J(x) ( J(x)^T ) where -\f[ - J(x) = R * F^{(1)} (x) -\f] -Here F is the function corresponding to the operation sequence -and x is any argument value. -*/ -template -template -void ADFun::rev_jac_sparsity( - const sparse_rc& pattern_in , - bool transpose , - bool dependency , - bool internal_bool , - sparse_rc& pattern_out ) -{ // number or rows, columns, and non-zeros in pattern_in - size_t nr_in = pattern_in.nr(); - size_t nc_in = pattern_in.nc(); - // - size_t ell = nr_in; - size_t m = nc_in; - if( transpose ) - std::swap(ell, m); - // - CPPAD_ASSERT_KNOWN( - m == Range() , - "rev_jac_sparsity: number columns in R " - "is not equal number of dependent variables." - ); - // number of independent variables - size_t n = Domain(); - // - bool zero_empty = true; - bool input_empty = true; - if( internal_bool ) - { // allocate memory for bool sparsity calculation - // (sparsity pattern is emtpy after a resize) - local::sparse_pack internal_jac; - internal_jac.resize(num_var_tape_, ell); - // - // set sparsity patttern for dependent variables - local::set_internal_sparsity( - zero_empty , - input_empty , - ! transpose , - dep_taddr_ , - internal_jac , - pattern_in - ); - - // compute sparsity for other variables - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - internal_jac - ); - // get sparstiy pattern for independent variables - local::get_internal_sparsity( - ! transpose, ind_taddr_, internal_jac, pattern_out - ); - } - else - { // allocate memory for bool sparsity calculation - // (sparsity pattern is emtpy after a resize) - local::sparse_list internal_jac; - internal_jac.resize(num_var_tape_, ell); - // - // set sparsity patttern for dependent variables - local::set_internal_sparsity( - zero_empty , - input_empty , - ! transpose , - dep_taddr_ , - internal_jac , - pattern_in - ); - - // compute sparsity for other variables - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - internal_jac - ); - // get sparstiy pattern for independent variables - local::get_internal_sparsity( - ! transpose, ind_taddr_, internal_jac, pattern_out - ); - } - return; -} -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/rev_one.hpp b/external/cppad/include/cppad/core/rev_one.hpp deleted file mode 100644 index 196dc2ba1..000000000 --- a/external/cppad/include/cppad/core/rev_one.hpp +++ /dev/null @@ -1,162 +0,0 @@ -# ifndef CPPAD_CORE_REV_ONE_HPP -# define CPPAD_CORE_REV_ONE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin RevOne$$ -$spell - dw - Taylor - const -$$ - - - - -$section First Order Derivative: Driver Routine$$ -$mindex derivative easy$$ - -$head Syntax$$ -$icode%dw% = %f%.RevOne(%x%, %i%)%$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -The syntax above sets $icode dw$$ to the -derivative of $latex F_i$$ with respect to $latex x$$; i.e., -$latex \[ -dw = -F_i^{(1)} (x) -= \left[ - \D{ F_i }{ x_0 } (x) , \cdots , \D{ F_i }{ x_{n-1} } (x) -\right] -\] $$ - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/RevOne Uses Forward/RevOne/RevOne Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -(see $cref/Vector/RevOne/Vector/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the derivative. - -$head i$$ -The index $icode i$$ has prototype -$codei% - size_t %i% -%$$ -and is less than $latex m$$, the dimension of the -$cref/range/seq_property/Range/$$ space for $icode f$$. -It specifies the -component of $latex F$$ that we are computing the derivative of. - -$head dw$$ -The result $icode dw$$ has prototype -$codei% - %Vector% %dw% -%$$ -(see $cref/Vector/RevOne/Vector/$$ below) -and its size is $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -The value of $icode dw$$ is the derivative of $latex F_i$$ -evaluated at $icode x$$; i.e., -for $latex j = 0 , \ldots , n - 1 $$ -$latex \[. - dw[ j ] = \D{ F_i }{ x_j } ( x ) -\] $$ - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head RevOne Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code RevOne$$, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -$head Example$$ -$children% - example/general/rev_one.cpp -%$$ -The routine -$cref/RevOne/rev_one.cpp/$$ is both an example and test. -It returns $code true$$, if it succeeds and $code false$$ otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -template -Vector ADFun::RevOne(const Vector &x, size_t i) -{ size_t i1; - - size_t n = Domain(); - size_t m = Range(); - - // check Vector is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - x.size() == n, - "RevOne: Length of x not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - i < m, - "RevOne: the index i is not less than range dimension for f" - ); - - // point at which we are evaluating the derivative - Forward(0, x); - - // component which are are taking the derivative of - Vector w(m); - for(i1 = 0; i1 < m; i1++) - w[i1] = 0.; - w[i] = Base(1.0); - - // dimension the return value - Vector dw(n); - - // compute the return value - dw = Reverse(1, w); - - return dw; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/rev_sparse_hes.hpp b/external/cppad/include/cppad/core/rev_sparse_hes.hpp deleted file mode 100644 index 218daad5e..000000000 --- a/external/cppad/include/cppad/core/rev_sparse_hes.hpp +++ /dev/null @@ -1,621 +0,0 @@ -# ifndef CPPAD_CORE_REV_SPARSE_HES_HPP -# define CPPAD_CORE_REV_SPARSE_HES_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin RevSparseHes$$ -$spell - std - VecAD - Jacobian - Jac - Hessian - Hes - const - Bool - Dep - proportional - var - cpp -$$ - -$section Hessian Sparsity Pattern: Reverse Mode$$ - -$head Syntax$$ -$icode%h% = %f%.RevSparseHes(%q%, %s%) -%$$ -$icode%h% = %f%.RevSparseHes(%q%, %s%, %transpose%)%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -For a fixed matrix $latex R \in \B{R}^{n \times q}$$ -and a fixed vector $latex S \in \B{R}^{1 \times m}$$, -we define -$latex \[ -\begin{array}{rcl} -H(x) -& = & \partial_x \left[ \partial_u S * F[ x + R * u ] \right]_{u=0} -\\ -& = & R^\R{T} * (S * F)^{(2)} ( x ) -\\ -H(x)^\R{T} -& = & (S * F)^{(2)} ( x ) * R -\end{array} -\] $$ -Given a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex R$$ and the vector $latex S$$, -$code RevSparseHes$$ returns a sparsity pattern for the $latex H(x)$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - const ADFun<%Base%> %f% -%$$ - -$head x$$ -If the operation sequence in $icode f$$ is -$cref/independent/glossary/Operation/Independent/$$ of -the independent variables in $latex x \in B^n$$, -the sparsity pattern is valid for all values of -(even if it has $cref CondExp$$ or $cref VecAD$$ operations). - -$head q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of columns in $latex R \in \B{R}^{n \times q}$$ -and the number of rows in $latex H(x) \in \B{R}^{q \times n}$$. -It must be the same value as in the previous $cref ForSparseJac$$ call -$codei% - %f%.ForSparseJac(%q%, %r%, %r_transpose%) -%$$ -Note that if $icode r_transpose$$ is true, $icode r$$ in the call above -corresponding to $latex R^\R{T} \in \B{R}^{q \times n}$$ - -$head transpose$$ -The argument $icode transpose$$ has prototype -$codei% - bool %transpose% -%$$ -The default value $code false$$ is used when $icode transpose$$ is not present. - - -$head r$$ -The matrix $latex R$$ is specified by the previous call -$codei% - %f%.ForSparseJac(%q%, %r%, %transpose%) -%$$ -see $cref/r/ForSparseJac/r/$$. -The type of the elements of -$cref/VectorSet/RevSparseHes/VectorSet/$$ must be the -same as the type of the elements of $icode r$$. - -$head s$$ -The argument $icode s$$ has prototype -$codei% - const %VectorSet%& %s% -%$$ -(see $cref/VectorSet/RevSparseHes/VectorSet/$$ below) -If it has elements of type $code bool$$, -its size is $latex m$$. -If it has elements of type $code std::set$$, -its size is one and all the elements of $icode%s%[0]%$$ -are between zero and $latex m - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the vector $icode S$$. - -$head h$$ -The result $icode h$$ has prototype -$codei% - %VectorSet%& %h% -%$$ -(see $cref/VectorSet/RevSparseHes/VectorSet/$$ below). - -$subhead transpose false$$ -If $icode h$$ has elements of type $code bool$$, -its size is $latex q * n$$. -If it has elements of type $code std::set$$, -its size is $latex q$$ and all the set elements are between -zero and $icode%n%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex H(x)$$. - -$subhead transpose true$$ -If $icode h$$ has elements of type $code bool$$, -its size is $latex n * q$$. -If it has elements of type $code std::set$$, -its size is $latex n$$ and all the set elements are between -zero and $icode%q%-1%$$ inclusive. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex H(x)^\R{T}$$. - -$head VectorSet$$ -The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$ or $code std::set$$; -see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion -of the difference. -The type of the elements of -$cref/VectorSet/RevSparseHes/VectorSet/$$ must be the -same as the type of the elements of $icode r$$. - -$head Entire Sparsity Pattern$$ -Suppose that $latex q = n$$ and -$latex R \in \B{R}^{n \times n}$$ is the $latex n \times n$$ identity matrix. -Further suppose that the $latex S$$ is the $th k$$ -$cref/elementary vector/glossary/Elementary Vector/$$; i.e. -$latex \[ -S_j = \left\{ \begin{array}{ll} - 1 & {\rm if} \; j = k - \\ - 0 & {\rm otherwise} -\end{array} \right. -\] $$ -In this case, -the corresponding value $icode h$$ is a -sparsity pattern for the Hessian matrix -$latex F_k^{(2)} (x) \in \B{R}^{n \times n}$$. - -$head Example$$ -$children% - example/sparse/rev_sparse_hes.cpp - %example/sparse/sparsity_sub.cpp -%$$ -The file -$cref rev_sparse_hes.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. -The file -$cref/sparsity_sub.cpp/sparsity_sub.cpp/RevSparseHes/$$ -contains an example and test of using $code RevSparseHes$$ -to compute the sparsity pattern for a subset of the Hessian. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file rev_sparse_hes.hpp -Reverse mode Hessian sparsity patterns. -*/ -// =========================================================================== -// RevSparseHesCase -/*! -Private helper function for RevSparseHes(q, s) bool sparsity. - -All of the description in the public member function RevSparseHes(q, s) -applies. - -\param set_type -is a \c bool value. This argument is used to dispatch to the proper source -code depending on the vlaue of \c VectorSet::value_type. - -\param transpose -See \c RevSparseHes(q, s). - -\param q -See \c RevSparseHes(q, s). - -\param s -See \c RevSparseHes(q, s). - -\param h -is the return value for the corresponging call to \c RevSparseJac(q, s). -*/ -template -template -void ADFun::RevSparseHesCase( - bool set_type , - bool transpose , - size_t q , - const VectorSet& s , - VectorSet& h ) -{ size_t n = Domain(); - size_t m = Range(); - // - h.resize(q * n ); - - CPPAD_ASSERT_KNOWN( - for_jac_sparse_pack_.n_set() > 0, - "RevSparseHes: previous stored call to ForSparseJac did not " - "use bool for the elements of r." - ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == num_var_tape_ ); - // - // temporary indices - size_t i, j; - - // check Vector is Simple VectorSet class with bool elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - q == for_jac_sparse_pack_.end(), - "RevSparseHes: q is not equal to its value\n" - "in the previous call to ForSparseJac with this ADFun object." - ); - CPPAD_ASSERT_KNOWN( - size_t(s.size()) == m, - "RevSparseHes: size of s is not equal to\n" - "range dimension for ADFun object." - ); - - // Array that will hold reverse Jacobian dependency flag. - // Initialize as true for the dependent variables. - local::pod_vector RevJac; - RevJac.extend(num_var_tape_); - for(i = 0; i < num_var_tape_; i++) - RevJac[i] = false; - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - RevJac[ dep_taddr_[i] ] = s[i]; - } - - // vector of sets that will hold reverse Hessain values - local::sparse_pack rev_hes_pattern; - rev_hes_pattern.resize(num_var_tape_, q); - - // compute the Hessian sparsity patterns - local::RevHesSweep( - n, - num_var_tape_, - &play_, - for_jac_sparse_pack_, - RevJac.data(), - rev_hes_pattern - ); - - // return values corresponding to independent variables - CPPAD_ASSERT_UNKNOWN( size_t(h.size()) == n * q ); - for(j = 0; j < n; j++) - { for(i = 0; i < q; i++) - { if( transpose ) - h[ j * q + i ] = false; - else h[ i * n + j ] = false; - } - } - - // j is index corresponding to reverse mode partial - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j + 1 ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // extract the result from rev_hes_pattern - CPPAD_ASSERT_UNKNOWN( rev_hes_pattern.end() == q ); - local::sparse_pack::const_iterator itr(rev_hes_pattern, j + 1); - i = *itr; - while( i < q ) - { if( transpose ) - h[ j * q + i ] = true; - else h[ i * n + j ] = true; - i = *(++itr); - } - } -} -/*! -Private helper function for RevSparseHes(q, s) set sparsity. - -All of the description in the public member function RevSparseHes(q, s) -applies. - -\param set_type -is a \c std::set value. -This argument is used to dispatch to the proper source -code depending on the vlaue of \c VectorSet::value_type. - -\param transpose -See \c RevSparseHes(q, s). - -\param q -See \c RevSparseHes(q, s). - -\param s -See \c RevSparseHes(q, s). - -\param h -is the return value for the corresponging call to \c RevSparseJac(q, s). -*/ -template -template -void ADFun::RevSparseHesCase( - const std::set& set_type , - bool transpose , - size_t q , - const VectorSet& s , - VectorSet& h ) -{ size_t n = Domain(); -# ifndef NDEBUG - size_t m = Range(); -# endif - // - if( transpose ) - h.resize(n); - else h.resize(q); - - CPPAD_ASSERT_KNOWN( - for_jac_sparse_set_.n_set() > 0, - "RevSparseHes: previous stored call to ForSparseJac did not " - "use std::set for the elements of r." - ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == num_var_tape_ ); - // - // temporary indices - size_t i, j; - std::set::const_iterator itr_1; - - // check VectorSet is Simple Vector class with sets for elements - CheckSimpleVector, VectorSet>( - local::one_element_std_set(), local::two_element_std_set() - ); - - CPPAD_ASSERT_KNOWN( - q == for_jac_sparse_set_.end(), - "RevSparseHes: q is not equal to its value\n" - "in the previous call to ForSparseJac with this ADFun object." - ); - CPPAD_ASSERT_KNOWN( - s.size() == 1, - "RevSparseHes: size of s is not equal to one." - ); - - // Array that will hold reverse Jacobian dependency flag. - // Initialize as true for the dependent variables. - local::pod_vector RevJac; - RevJac.extend(num_var_tape_); - for(i = 0; i < num_var_tape_; i++) - RevJac[i] = false; - itr_1 = s[0].begin(); - while( itr_1 != s[0].end() ) - { i = *itr_1++; - CPPAD_ASSERT_KNOWN( - i < m, - "RevSparseHes: an element of the set s[0] has value " - "greater than or equal m" - ); - CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - RevJac[ dep_taddr_[i] ] = true; - } - - - // vector of sets that will hold reverse Hessain values - local::sparse_list rev_hes_pattern; - rev_hes_pattern.resize(num_var_tape_, q); - - // compute the Hessian sparsity patterns - local::RevHesSweep( - n, - num_var_tape_, - &play_, - for_jac_sparse_set_, - RevJac.data(), - rev_hes_pattern - ); - - // return values corresponding to independent variables - // j is index corresponding to reverse mode partial - CPPAD_ASSERT_UNKNOWN( size_t(h.size()) == q || transpose ); - CPPAD_ASSERT_UNKNOWN( size_t(h.size()) == n || ! transpose ); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j + 1 ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // extract the result from rev_hes_pattern - // and add corresponding elements to result sets in h - CPPAD_ASSERT_UNKNOWN( rev_hes_pattern.end() == q ); - local::sparse_list::const_iterator itr_2(rev_hes_pattern, j+1); - i = *itr_2; - while( i < q ) - { if( transpose ) - h[j].insert(i); - else h[i].insert(j); - i = *(++itr_2); - } - } -} - -// =========================================================================== -// RevSparseHes - -/*! -User API for Hessian sparsity patterns using reverse mode. - -The C++ source code corresponding to this operation is -\verbatim - h = f.RevSparseHes(q, r) -\endverbatim - -\tparam Base -is the base type for this recording. - -\tparam VectorSet -is a simple vector with elements of type \c bool -or \c std::set. - -\param transpose -is true (false) if \c is is equal to \f$ H(x) \f$ (\f$ H(x)^T \f$) -where -\f[ - H(x) = R^T (S * F)^{(2)} (x) -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \a x is any argument value. - -\param q -is the value of \a q in the -by the previous call of the form -\verbatim - f.ForSparseJac(q, r, packed) -\endverbatim -The value \c r in this call is a sparsity pattern for the matrix \f$ R \f$. -The type of the element of \c r for the previous call to \c ForSparseJac -must be the same as the type of the elements of \c s. - -\param s -is a vector with size \c m that specifies the sparsity pattern -for the vector \f$ S \f$, -where \c m is the number of dependent variables -corresponding to the operation sequence stored in \a play. - -\return -If \c transpose is false (true), -the return vector is a sparsity pattern for \f$ H(x) \f$ (\f$ H(x)^T \f$). -\f[ - H(x) = R^T ( S * F)^{(2)} (x) -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \a x is any argument value. -*/ - -template -template -VectorSet ADFun::RevSparseHes( - size_t q, const VectorSet& s, bool transpose -) -{ VectorSet h; - typedef typename VectorSet::value_type Set_type; - - // Should check to make sure q is same as in previous call to - // forward sparse Jacobian. - RevSparseHesCase( - Set_type() , - transpose , - q , - s , - h - ); - - return h; -} -// =========================================================================== -// RevSparseHesCheckpoint -/*! -Hessian sparsity patterns calculation used by checkpoint functions. - -\tparam Base -is the base type for this recording. - -\param transpose -is true (false) h is equal to \f$ H(x) \f$ (\f$ H(x)^T \f$) -where -\f[ - H(x) = R^T (S * F)^{(2)} (x) -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \f$ x \f$ is any argument value. - -\param q -is the value of q in the by the previous call of the form -\verbatim - f.ForSparseJac(q, r) -\endverbatim -The value r in this call is a sparsity pattern for the matrix \f$ R \f$. - -\param s -is a vector with size m that specifies the sparsity pattern -for the vector \f$ S \f$, -where m is the number of dependent variables -corresponding to the operation sequence stored in play_. - -\param h -The input size and elements of h do not matter. -On output, h is the sparsity pattern for the matrix \f$ H(x) \f$ -or \f$ H(x)^T \f$ depending on transpose. - -\par Assumptions -The forward jacobian sparsity pattern must be currently stored -in this ADFUN object. -*/ -template -void ADFun::RevSparseHesCheckpoint( - size_t q , - vector& s , - bool transpose , - local::sparse_list& h ) -{ size_t n = Domain(); - size_t m = Range(); - - // checkpoint functions should get this right - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == 0 ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == num_var_tape_ ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.end() == q ); - CPPAD_ASSERT_UNKNOWN( s.size() == m ); - - // Array that holds the reverse Jacobiain dependcy flags. - // Initialize as true for dependent variables, flase for others. - local::pod_vector RevJac; - RevJac.extend(num_var_tape_); - for(size_t i = 0; i < num_var_tape_; i++) - RevJac[i] = false; - for(size_t i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ) - RevJac[ dep_taddr_[i] ] = s[i]; - } - - // holds reverse Hessian sparsity pattern for all variables - local::sparse_list rev_hes_pattern; - rev_hes_pattern.resize(num_var_tape_, q); - - // compute Hessian sparsity pattern for all variables - local::RevHesSweep( - n, - num_var_tape_, - &play_, - for_jac_sparse_set_, - RevJac.data(), - rev_hes_pattern - ); - - // dimension the return value - if( transpose ) - h.resize(n, q); - else - h.resize(q, n); - - // j is index corresponding to reverse mode partial - for(size_t j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j + 1 ); - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // extract the result from rev_hes_pattern - CPPAD_ASSERT_UNKNOWN( rev_hes_pattern.end() == q ); - local::sparse_list::const_iterator itr(rev_hes_pattern, j + 1); - size_t i = *itr; - while( i < q ) - { if( transpose ) - h.add_element(j, i); - else h.add_element(i, j); - i = *(++itr); - } - } -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/rev_sparse_jac.hpp b/external/cppad/include/cppad/core/rev_sparse_jac.hpp deleted file mode 100644 index 16f5c0769..000000000 --- a/external/cppad/include/cppad/core/rev_sparse_jac.hpp +++ /dev/null @@ -1,626 +0,0 @@ -# ifndef CPPAD_CORE_REV_SPARSE_JAC_HPP -# define CPPAD_CORE_REV_SPARSE_JAC_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin RevSparseJac$$ -$spell - optimizer - nz - CondExpRel - std - VecAD - var - Jacobian - Jac - const - Bool - Dep - proportional -$$ - -$section Jacobian Sparsity Pattern: Reverse Mode$$ -$mindex RevSparseJac sparse$$ - -$head Syntax$$ -$icode%s% = %f%.RevSparseJac(%q%, %r%) -%$$ -$icode%s% = %f%.RevSparseJac(%q%, %r%, %transpose%, %dependency%)%$$ - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -For a fixed matrix $latex R \in B^{q \times m}$$, -the Jacobian of $latex R * F( x )$$ -with respect to $latex x$$ is -$latex \[ - S(x) = R * F^{(1)} ( x ) -\] $$ -Given a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for $latex R$$, -$code RevSparseJac$$ returns a sparsity pattern for the $latex S(x)$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ - -$head x$$ -If the operation sequence in $icode f$$ is -$cref/independent/glossary/Operation/Independent/$$ of -the independent variables in $latex x \in B^n$$, -the sparsity pattern is valid for all values of -(even if it has $cref CondExp$$ or $cref VecAD$$ operations). - -$head q$$ -The argument $icode q$$ has prototype -$codei% - size_t %q% -%$$ -It specifies the number of rows in -$latex R \in B^{q \times m}$$ and the -Jacobian $latex S(x) \in B^{q \times n}$$. - -$head transpose$$ -The argument $icode transpose$$ has prototype -$codei% - bool %transpose% -%$$ -The default value $code false$$ is used when $icode transpose$$ is not present. - -$head dependency$$ -The argument $icode dependency$$ has prototype -$codei% - bool %dependency% -%$$ -If $icode dependency$$ is true, -the $cref/dependency pattern/dependency.cpp/Dependency Pattern/$$ -(instead of sparsity pattern) is computed. - -$head r$$ -The argument $icode s$$ has prototype -$codei% - const %VectorSet%& %r% -%$$ -see $cref/VectorSet/RevSparseJac/VectorSet/$$ below. - -$subhead transpose false$$ -If $icode r$$ has elements of type $code bool$$, -its size is $latex q * m$$. -If it has elements of type $code std::set$$, -its size is $icode q$$ and all its set elements are between -zero and $latex m - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex R \in B^{q \times m}$$. - -$subhead transpose true$$ -If $icode r$$ has elements of type $code bool$$, -its size is $latex m * q$$. -If it has elements of type $code std::set$$, -its size is $icode m$$ and all its set elements are between -zero and $latex q - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex R^\R{T} \in B^{m \times q}$$. - -$head s$$ -The return value $icode s$$ has prototype -$codei% - %VectorSet% %s% -%$$ -see $cref/VectorSet/RevSparseJac/VectorSet/$$ below. - -$subhead transpose false$$ -If it has elements of type $code bool$$, -its size is $latex q * n$$. -If it has elements of type $code std::set$$, -its size is $icode q$$ and all its set elements are between -zero and $latex n - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex S(x) \in {q \times n}$$. - -$subhead transpose true$$ -If it has elements of type $code bool$$, -its size is $latex n * q$$. -If it has elements of type $code std::set$$, -its size is $icode n$$ and all its set elements are between -zero and $latex q - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the matrix $latex S(x)^\R{T} \in {n \times q}$$. - -$head VectorSet$$ -The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$ or $code std::set$$; -see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion -of the difference. - -$head Entire Sparsity Pattern$$ -Suppose that $latex q = m$$ and -$latex R$$ is the $latex m \times m$$ identity matrix. -In this case, -the corresponding value for $icode s$$ is a -sparsity pattern for the Jacobian $latex S(x) = F^{(1)} ( x )$$. - -$head Example$$ -$children% - example/sparse/rev_sparse_jac.cpp -%$$ -The file -$cref rev_sparse_jac.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file rev_sparse_jac.hpp -Reverse mode Jacobian sparsity patterns. -*/ -// ========================================================================= -// RevSparseJacCase - -/*! -Private helper function for RevSparseJac(q, r, transpose) boolean sparsity. - -All of the description in the public member function -\c RevSparseJac(q, r, transpose) apply. - -\param set_type -is a \c bool value. -This argument is used to dispatch to the proper source code -depending on the value of \c VectorSet::value_type. - -\param transpose -See \c RevSparseJac(q, r, transpose, dependency) - -\param dependency -See \c RevSparseJac(q, r, transpose, dependency) - -\param q -See \c RevSparseJac(q, r, transpose, dependency) - -\param r -See \c RevSparseJac(q, r, transpose, dependency) - -\param s -is the return value for the corresponding call to -RevSparseJac(q, r, transpose). -*/ - -template -template -void ADFun::RevSparseJacCase( - bool set_type , - bool transpose , - bool dependency , - size_t q , - const VectorSet& r , - VectorSet& s ) -{ size_t n = Domain(); - size_t m = Range(); - - // dimension of the result vector - s.resize( q * n ); - - // temporary indices - size_t i, j; - - // check VectorSet is Simple Vector class with bool elements - CheckSimpleVector(); - // - CPPAD_ASSERT_KNOWN( - q > 0, - "RevSparseJac: q is not greater than zero" - ); - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == q * m, - "RevSparseJac: size of r is not equal to\n" - "q times range dimension for ADFun object." - ); - // - // vector of sets that will hold the results - local::sparse_pack var_sparsity; - var_sparsity.resize(num_var_tape_, q); - - // The sparsity pattern corresponding to the dependent variables - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - if( transpose ) - { for(j = 0; j < q; j++) if( r[ i * q + j ] ) - var_sparsity.add_element( dep_taddr_[i], j ); - } - else - { for(j = 0; j < q; j++) if( r[ j * m + i ] ) - var_sparsity.add_element( dep_taddr_[i], j ); - } - } - - // evaluate the sparsity patterns - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - var_sparsity - ); - - // return values corresponding to dependent variables - CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q * n ); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // extract the result from var_sparsity - if( transpose ) - { for(i = 0; i < q; i++) - s[ j * q + i ] = false; - } - else - { for(i = 0; i < q; i++) - s[ i * n + j ] = false; - } - CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q ); - local::sparse_pack::const_iterator itr(var_sparsity, j+1); - i = *itr; - while( i < q ) - { if( transpose ) - s[ j * q + i ] = true; - else s[ i * n + j ] = true; - i = *(++itr); - } - } -} - -/*! -Private helper function for RevSparseJac(q, r, transpose) set sparsity - -All of the description in the public member function -\c RevSparseJac(q, r, transpose) apply. - -\param set_type -is a \c std::set object. -This argument is used to dispatch to the proper source code -depending on the value of \c VectorSet::value_type. - -\param transpose -See \c RevSparseJac(q, r, transpose, dependency) - -\param dependency -See \c RevSparseJac(q, r, transpose, dependency) - -\param q -See \c RevSparseJac(q, r, transpose, dependency) - -\param r -See \c RevSparseJac(q, r, transpose, dependency) - -\param s -is the return value for the corresponding call to RevSparseJac(q, r, transpose) -*/ - -template -template -void ADFun::RevSparseJacCase( - const std::set& set_type , - bool transpose , - bool dependency , - size_t q , - const VectorSet& r , - VectorSet& s ) -{ // dimension of the result vector - if( transpose ) - s.resize( Domain() ); - else s.resize( q ); - - // temporary indices - size_t i, j; - std::set::const_iterator itr_1; - - // check VectorSet is Simple Vector class with sets for elements - CheckSimpleVector, VectorSet>( - local::one_element_std_set(), local::two_element_std_set() - ); - - // domain dimensions for F - size_t n = ind_taddr_.size(); - size_t m = dep_taddr_.size(); - - CPPAD_ASSERT_KNOWN( - q > 0, - "RevSparseJac: q is not greater than zero" - ); - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == q || transpose, - "RevSparseJac: size of r is not equal to q and transpose is false." - ); - CPPAD_ASSERT_KNOWN( - size_t(r.size()) == m || ! transpose, - "RevSparseJac: size of r is not equal to m and transpose is true." - ); - - // vector of lists that will hold the results - local::sparse_list var_sparsity; - var_sparsity.resize(num_var_tape_, q); - - // The sparsity pattern corresponding to the dependent variables - if( transpose ) - { for(i = 0; i < m; i++) - { itr_1 = r[i].begin(); - while(itr_1 != r[i].end()) - { j = *itr_1++; - CPPAD_ASSERT_KNOWN( - j < q, - "RevSparseJac: transpose is true and element of the set\n" - "r[i] has value greater than or equal q." - ); - CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - var_sparsity.add_element( dep_taddr_[i], j ); - } - } - } - else - { for(i = 0; i < q; i++) - { itr_1 = r[i].begin(); - while(itr_1 != r[i].end()) - { j = *itr_1++; - CPPAD_ASSERT_KNOWN( - j < m, - "RevSparseJac: transpose is false and element of the set\n" - "r[i] has value greater than or equal range dimension." - ); - CPPAD_ASSERT_UNKNOWN( dep_taddr_[j] < num_var_tape_ ); - var_sparsity.add_element( dep_taddr_[j], i ); - } - } - } - // evaluate the sparsity patterns - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - var_sparsity - ); - - // return values corresponding to dependent variables - CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || transpose ); - CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == n || ! transpose ); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q ); - local::sparse_list::const_iterator itr_2(var_sparsity, j+1); - i = *itr_2; - while( i < q ) - { if( transpose ) - s[j].insert(i); - else s[i].insert(j); - i = *(++itr_2); - } - } -} - -// ========================================================================= -// RevSparseJac -/*! -User API for Jacobian sparsity patterns using reverse mode. - -The C++ source code corresponding to this operation is -\verbatim - s = f.RevSparseJac(q, r, transpose, dependency) -\endverbatim - -\tparam Base -is the base type for this recording. - -\tparam VectorSet -is a simple vector with elements of type \c bool. -or \c std::set. - -\param q -is the number of rows in the matrix \f$ R \f$. - -\param r -is a sparsity pattern for the matrix \f$ R \f$. - -\param transpose -are the sparsity patterns for \f$ R \f$ and \f$ S(x) \f$ transposed. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - - -\return -If \c transpose is false (true), the return value is a sparsity pattern -for \f$ S(x) \f$ (\f$ S(x)^T \f$) where -\f[ - S(x) = R * F^{(1)} (x) -\f] -and \f$ F \f$ is the function corresponding to the operation sequence -and \a x is any argument value. -If \c VectorSet::value_type is \c bool, -the return value has size \f$ q * n \f$ ( \f$ n * q \f$). -If \c VectorSet::value_type is \c std::set, -the return value has size \f$ q \f$ ( \f$ n \f$) -and with all its elements between zero and \f$ n - 1 \f$ (\f$ q - 1 \f$). -*/ -template -template -VectorSet ADFun::RevSparseJac( - size_t q , - const VectorSet& r , - bool transpose , - bool dependency ) -{ - VectorSet s; - typedef typename VectorSet::value_type Set_type; - - RevSparseJacCase( - Set_type() , - transpose , - dependency , - q , - r , - s - ); - return s; -} -// =========================================================================== -// RevSparseJacCheckpoint -/*! -Reverse mode Jacobian sparsity calculation used by checkpoint functions. - -\tparam Base -is the base type for this recording. - -\param transpose -is true (false) s is equal to \f$ S(x) \f$ (\f$ S(x)^T \f$) -where -\f[ - S(x) = R * F^{(1)} (x) -\f] -where \f$ F \f$ is the function corresponding to the operation sequence -and \f$ x \f$ is any argument value. - -\param q -is the number of rows in the matrix \f$ R \f$. - -\param r -is a sparsity pattern for the matrix \f$ R \f$. - -\param transpose -are the sparsity patterns for \f$ R \f$ and \f$ S(x) \f$ transposed. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param s -The input size and elements of s do not matter. -On output, s is the sparsity pattern for the matrix \f$ S(x) \f$ -or \f$ S(x)^T \f$ depending on transpose. - -*/ -template -void ADFun::RevSparseJacCheckpoint( - size_t q , - const local::sparse_list& r , - bool transpose , - bool dependency , - local::sparse_list& s ) -{ size_t n = Domain(); - size_t m = Range(); - -# ifndef NDEBUG - if( transpose ) - { CPPAD_ASSERT_UNKNOWN( r.n_set() == m ); - CPPAD_ASSERT_UNKNOWN( r.end() == q ); - } - else - { CPPAD_ASSERT_UNKNOWN( r.n_set() == q ); - CPPAD_ASSERT_UNKNOWN( r.end() == m ); - } - for(size_t i = 0; i < m; i++) - CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); -# endif - - // holds reverse Jacobian sparsity pattern for all variables - local::sparse_list var_sparsity; - var_sparsity.resize(num_var_tape_, q); - - // set sparsity pattern for dependent variables - if( transpose ) - { for(size_t i = 0; i < m; i++) - { local::sparse_list::const_iterator itr(r, i); - size_t j = *itr; - while( j < q ) - { var_sparsity.add_element( dep_taddr_[i], j ); - j = *(++itr); - } - } - } - else - { for(size_t j = 0; j < q; j++) - { local::sparse_list::const_iterator itr(r, j); - size_t i = *itr; - while( i < m ) - { var_sparsity.add_element( dep_taddr_[i], j ); - i = *(++itr); - } - } - } - - // evaluate the sparsity pattern for all variables - local::RevJacSweep( - dependency, - n, - num_var_tape_, - &play_, - var_sparsity - ); - - // dimension the return value - if( transpose ) - s.resize(n, m); - else - s.resize(m, n); - - // return values corresponding to independent variables - for(size_t j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) ); - - // ind_taddr_[j] is operator taddr for j-th independent variable - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // extract the result from var_sparsity - CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q ); - local::sparse_list::const_iterator itr(var_sparsity, j+1); - size_t i = *itr; - while( i < q ) - { if( transpose ) - s.add_element(j, i); - else - s.add_element(i, j); - i = *(++itr); - } - } - -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/rev_two.hpp b/external/cppad/include/cppad/core/rev_two.hpp deleted file mode 100644 index 9afc14441..000000000 --- a/external/cppad/include/cppad/core/rev_two.hpp +++ /dev/null @@ -1,235 +0,0 @@ -# ifndef CPPAD_CORE_REV_TWO_HPP -# define CPPAD_CORE_REV_TWO_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin RevTwo$$ -$spell - ddw - typename - Taylor - const -$$ - - - - - -$section Reverse Mode Second Partial Derivative Driver$$ -$mindex order easy$$ - -$head Syntax$$ -$icode%ddw% = %f%.RevTwo(%x%, %i%, %j%)%$$ - - -$head Purpose$$ -We use $latex F : B^n \rightarrow B^m$$ to denote the -$cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$. -The syntax above sets -$latex \[ - ddw [ k * p + \ell ] - = - \DD{ F_{i[ \ell ]} }{ x_{j[ \ell ]} }{ x_k } (x) -\] $$ -for $latex k = 0 , \ldots , n-1$$ -and $latex \ell = 0 , \ldots , p$$, -where $latex p$$ is the size of the vectors $icode i$$ and $icode j$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/RevTwo Uses Forward/RevTwo/RevTwo Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %VectorBase% &%x% -%$$ -(see $cref/VectorBase/RevTwo/VectorBase/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the partial derivatives listed above. - -$head i$$ -The argument $icode i$$ has prototype -$codei% - const %VectorSize_t% &%i% -%$$ -(see $cref/VectorSize_t/RevTwo/VectorSize_t/$$ below) -We use $icode p$$ to denote the size of the vector $icode i$$. -All of the indices in $icode i$$ -must be less than $icode m$$, the dimension of the -$cref/range/seq_property/Range/$$ space for $icode f$$; i.e., -for $latex \ell = 0 , \ldots , p-1$$, $latex i[ \ell ] < m$$. - -$head j$$ -The argument $icode j$$ has prototype -$codei% - const %VectorSize_t% &%j% -%$$ -(see $cref/VectorSize_t/RevTwo/VectorSize_t/$$ below) -and its size must be equal to $icode p$$, -the size of the vector $icode i$$. -All of the indices in $icode j$$ -must be less than $icode n$$; i.e., -for $latex \ell = 0 , \ldots , p-1$$, $latex j[ \ell ] < n$$. - -$head ddw$$ -The result $icode ddw$$ has prototype -$codei% - %VectorBase% %ddw% -%$$ -(see $cref/VectorBase/RevTwo/VectorBase/$$ below) -and its size is $latex n * p$$. -It contains the requested partial derivatives; to be specific, -for $latex k = 0 , \ldots , n - 1 $$ -and $latex \ell = 0 , \ldots , p - 1$$ -$latex \[ - ddw [ k * p + \ell ] - = - \DD{ F_{i[ \ell ]} }{ x_{j[ \ell ]} }{ x_k } (x) -\] $$ - -$head VectorBase$$ -The type $icode VectorBase$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Base/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head VectorSize_t$$ -The type $icode VectorSize_t$$ must be a $cref SimpleVector$$ class with -$cref/elements of type size_t/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head RevTwo Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code RevTwo$$, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -$head Examples$$ -$children% - example/general/rev_two.cpp -%$$ -The routine -$cref/RevTwo/rev_two.cpp/$$ is both an example and test. -It returns $code true$$, if it succeeds and $code false$$ otherwise. - -$end ------------------------------------------------------------------------------ -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -template -VectorBase ADFun::RevTwo( - const VectorBase &x, - const VectorSize_t &i, - const VectorSize_t &j) -{ size_t i1; - size_t j1; - size_t k; - size_t l; - - size_t n = Domain(); - size_t m = Range(); - size_t p = i.size(); - - // check VectorBase is Simple Vector class with Base elements - CheckSimpleVector(); - - // check VectorSize_t is Simple Vector class with size_t elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - x.size() == n, - "RevTwo: Length of x not equal domain dimension for f." - ); - CPPAD_ASSERT_KNOWN( - i.size() == j.size(), - "RevTwo: Lenght of the i and j vectors are not equal." - ); - // point at which we are evaluating the second partials - Forward(0, x); - - // dimension the return value - VectorBase ddw(n * p); - - // direction vector in argument space - VectorBase dx(n); - for(j1 = 0; j1 < n; j1++) - dx[j1] = Base(0.0); - - // direction vector in range space - VectorBase w(m); - for(i1 = 0; i1 < m; i1++) - w[i1] = Base(0.0); - - // place to hold the results of a reverse calculation - VectorBase r(n * 2); - - // check the indices in i and j - for(l = 0; l < p; l++) - { i1 = i[l]; - j1 = j[l]; - CPPAD_ASSERT_KNOWN( - i1 < m, - "RevTwo: an eleemnt of i not less than range dimension for f." - ); - CPPAD_ASSERT_KNOWN( - j1 < n, - "RevTwo: an element of j not less than domain dimension for f." - ); - } - - // loop over all forward directions - for(j1 = 0; j1 < n; j1++) - { // first order forward mode calculation done - bool first_done = false; - for(l = 0; l < p; l++) if( j[l] == j1 ) - { if( ! first_done ) - { first_done = true; - - // first order forward mode in j1 direction - dx[j1] = Base(1.0); - Forward(1, dx); - dx[j1] = Base(0.0); - } - // execute a reverse in this component direction - i1 = i[l]; - w[i1] = Base(1.0); - r = Reverse(2, w); - w[i1] = Base(0.0); - - // place the reverse result in return value - for(k = 0; k < n; k++) - ddw[k * p + l] = r[k * 2 + 1]; - } - } - return ddw; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/reverse.hpp b/external/cppad/include/cppad/core/reverse.hpp deleted file mode 100644 index 17885456a..000000000 --- a/external/cppad/include/cppad/core/reverse.hpp +++ /dev/null @@ -1,209 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_REVERSE_HPP -# define CPPAD_CORE_REVERSE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file reverse.hpp -Compute derivatives using reverse mode. -*/ - - -/*! -Use reverse mode to compute derivative of forward mode Taylor coefficients. - -The function -\f$ X : {\rm R} \times {\rm R}^{n \times q} \rightarrow {\rm R} \f$ -is defined by -\f[ -X(t , u) = \sum_{k=0}^{q-1} u^{(k)} t^k -\f] -The function -\f$ Y : {\rm R} \times {\rm R}^{n \times q} \rightarrow {\rm R} \f$ -is defined by -\f[ -Y(t , u) = F[ X(t, u) ] -\f] -The function -\f$ W : {\rm R}^{n \times q} \rightarrow {\rm R} \f$ is defined by -\f[ -W(u) = \sum_{k=0}^{q-1} ( w^{(k)} )^{\rm T} -\frac{1}{k !} \frac{ \partial^k } { t^k } Y(0, u) -\f] - -\tparam Base -base type for the operator; i.e., this operation sequence was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\tparam VectorBase -is a Simple Vector class with elements of type \a Base. - -\param q -is the number of the number of Taylor coefficients that are being -differentiated (per variable). - -\param w -is the weighting for each of the Taylor coefficients corresponding -to dependent variables. -If the argument \a w has size m * q , -for \f$ k = 0 , \ldots , q-1 \f$ and \f$ i = 0, \ldots , m-1 \f$, -\f[ - w_i^{(k)} = w [ i * q + k ] -\f] -If the argument \a w has size \c m , -for \f$ k = 0 , \ldots , q-1 \f$ and \f$ i = 0, \ldots , m-1 \f$, -\f[ -w_i^{(k)} = \left\{ \begin{array}{ll} - w [ i ] & {\rm if} \; k = q-1 - \\ - 0 & {\rm otherwise} -\end{array} \right. -\f] - -\return -Is a vector \f$ dw \f$ such that -for \f$ j = 0 , \ldots , n-1 \f$ and -\f$ k = 0 , \ldots , q-1 \f$ -\f[ - dw[ j * q + k ] = W^{(1)} ( x )_{j,k} -\f] -where the matrix \f$ x \f$ is the value for \f$ u \f$ -that corresponding to the forward mode Taylor coefficients -for the independent variables as specified by previous calls to Forward. - -*/ -template -template -VectorBase ADFun::Reverse(size_t q, const VectorBase &w) -{ // constants - const Base zero(0); - - // temporary indices - size_t i, j, k; - - // number of independent variables - size_t n = ind_taddr_.size(); - - // number of dependent variables - size_t m = dep_taddr_.size(); - - local::pod_vector Partial; - Partial.extend(num_var_tape_ * q); - - // update maximum memory requirement - // memoryMax = std::max( memoryMax, - // Memory() + num_var_tape_ * q * sizeof(Base) - // ); - - // check VectorBase is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - size_t(w.size()) == m || size_t(w.size()) == (m * q), - "Argument w to Reverse does not have length equal to\n" - "the dimension of the range for the corresponding ADFun." - ); - CPPAD_ASSERT_KNOWN( - q > 0, - "The first argument to Reverse must be greater than zero." - ); - CPPAD_ASSERT_KNOWN( - num_order_taylor_ >= q, - "Less that q taylor_ coefficients are currently stored" - " in this ADFun object." - ); - // special case where multiple forward directions have been computed, - // but we are only using the one direction zero order results - if( (q == 1) & (num_direction_taylor_ > 1) ) - { num_order_taylor_ = 1; // number of orders to copy - size_t c = cap_order_taylor_; // keep the same capacity setting - size_t r = 1; // only keep one direction - capacity_order(c, r); - } - CPPAD_ASSERT_KNOWN( - num_direction_taylor_ == 1, - "Reverse mode for Forward(q, r, xq) with more than one direction" - "\n(r > 1) is not yet supported for q > 1." - ); - // initialize entire Partial matrix to zero - for(i = 0; i < num_var_tape_; i++) - for(j = 0; j < q; j++) - Partial[i * q + j] = zero; - - // set the dependent variable direction - // (use += because two dependent variables can point to same location) - for(i = 0; i < m; i++) - { CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ ); - if( size_t(w.size()) == m ) - Partial[dep_taddr_[i] * q + q - 1] += w[i]; - else - { for(k = 0; k < q; k++) - // ? should use += here, first make test to demonstrate bug - Partial[ dep_taddr_[i] * q + k ] = w[i * q + k ]; - } - } - - // evaluate the derivatives - CPPAD_ASSERT_UNKNOWN( cskip_op_.size() == play_.num_op_rec() ); - CPPAD_ASSERT_UNKNOWN( load_op_.size() == play_.num_load_op_rec() ); - local::ReverseSweep( - q - 1, - n, - num_var_tape_, - &play_, - cap_order_taylor_, - taylor_.data(), - q, - Partial.data(), - cskip_op_.data(), - load_op_ - ); - - // return the derivative values - VectorBase value(n * q); - for(j = 0; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ ); - - // independent variable taddr equals its operator taddr - CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == local::InvOp ); - - // by the Reverse Identity Theorem - // partial of y^{(k)} w.r.t. u^{(0)} is equal to - // partial of y^{(q-1)} w.r.t. u^{(q - 1 - k)} - if( size_t(w.size()) == m ) - { for(k = 0; k < q; k++) - value[j * q + k ] = - Partial[ind_taddr_[j] * q + q - 1 - k]; - } - else - { for(k = 0; k < q; k++) - value[j * q + k ] = - Partial[ind_taddr_[j] * q + k]; - } - } - CPPAD_ASSERT_KNOWN( ! ( hasnan(value) && check_for_nan_ ) , - "dw = f.Reverse(q, w): has a nan,\n" - "but none of its Taylor coefficents are nan." - ); - - return value; -} - - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/sign.hpp b/external/cppad/include/cppad/core/sign.hpp deleted file mode 100644 index 713d68c66..000000000 --- a/external/cppad/include/cppad/core/sign.hpp +++ /dev/null @@ -1,103 +0,0 @@ -# ifndef CPPAD_CORE_SIGN_HPP -# define CPPAD_CORE_SIGN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin sign$$ -$spell - CppAD - Dirac -$$ -$section The Sign: sign$$ - -$head Syntax$$ -$icode%y% = sign(%x%)%$$ - -$head Description$$ -Evaluates the $code sign$$ function which is defined by -$latex \[ -{\rm sign} (x) = -\left\{ \begin{array}{rl} - +1 & {\rm if} \; x > 0 \\ - 0 & {\rm if} \; x = 0 \\ - -1 & {\rm if} \; x < 0 -\end{array} \right. -\] $$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -CppAD computes the derivative of the $code sign$$ function as zero for all -argument values $icode x$$. -The correct mathematical derivative is different and -is given by -$latex \[ - {\rm sign}^{(1)} (x) = 2 \delta (x) -\] $$ -where $latex \delta (x)$$ is the Dirac Delta function. - -$head Example$$ -$children% - example/general/sign.cpp -%$$ -The file -$cref sign.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD AD::sign_me (void) const -{ - AD result; - result.value_ = sign(value_); - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - if( Variable(*this) ) - { // add this operation to the tape - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SignOp) == 1 ); - local::ADTape *tape = tape_this(); - - // corresponding operand address - tape->Rec_.PutArg(taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::SignOp); - // make result a variable - result.tape_id_ = tape->id_; - } - return result; -} - -template -inline AD sign(const AD &x) -{ return x.sign_me(); } - -template -inline AD sign(const VecAD_reference &x) -{ return x.ADBase().sign_me(); } - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/sparse.hpp b/external/cppad/include/cppad/core/sparse.hpp deleted file mode 100644 index 8f5c37863..000000000 --- a/external/cppad/include/cppad/core/sparse.hpp +++ /dev/null @@ -1,31 +0,0 @@ -# ifndef CPPAD_CORE_SPARSE_HPP -# define CPPAD_CORE_SPARSE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include -# include -// -# include -# include -# include -# include -// -# include -# include -// -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/sparse_hes.hpp b/external/cppad/include/cppad/core/sparse_hes.hpp deleted file mode 100644 index 55b44f2c4..000000000 --- a/external/cppad/include/cppad/core/sparse_hes.hpp +++ /dev/null @@ -1,540 +0,0 @@ -# ifndef CPPAD_CORE_SPARSE_HES_HPP -# define CPPAD_CORE_SPARSE_HES_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin sparse_hes$$ -$spell - const - Taylor - rc - rcv - nr - nc - hes - std - cppad - colpack - cmake - Jacobian -$$ - -$section Computing Sparse Hessians$$ - -$head Syntax$$ -$icode%n_sweep% = %f%.sparse_hes( - %x%, %w%, %subset%, %pattern%, %coloring%, %work% -)%$$ - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -function corresponding to $icode f$$. -Here $icode n$$ is the $cref/domain/seq_property/Domain/$$ size, -and $icode m$$ is the $cref/range/seq_property/Range/$$ size, or $icode f$$. -The syntax above takes advantage of sparsity when computing the Hessian -$latex \[ - H(x) = \dpow{2}{x} \sum_{i=0}^{m-1} w_i F_i (x) -\] $$ -In the sparse case, this should be faster and take less memory than -$cref Hessian$$. -The matrix element $latex H_{i,j} (x)$$ is the second partial of -$latex w^\R{T} F (x)$$ with respect to $latex x_i$$ and $latex x_j$$. - -$head SizeVector$$ -The type $icode SizeVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head BaseVector$$ -The type $icode BaseVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head f$$ -This object has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the Taylor coefficients stored in $icode f$$ are affected -by this operation; see -$cref/uses forward/sparse_hes/Uses Forward/$$ below. - -$head x$$ -This argument has prototype -$codei% - const %BaseVector%& %x% -%$$ -and its size is $icode n$$. -It specifies the point at which to evaluate the Hessian -$latex H(x)$$. - -$head w$$ -This argument has prototype -$codei% - const %BaseVector%& %w% -%$$ -and its size is $icode m$$. -It specifies the weight for each of the components of $latex F(x)$$; -i.e. $latex w_i$$ is the weight for $latex F_i (x)$$. - -$head subset$$ -This argument has prototype -$codei% - sparse_rcv<%SizeVector%, %BaseVector%>& %subset% -%$$ -Its row size and column size is $icode n$$; i.e., -$icode%subset%.nr() == %n%$$ and $icode%subset%.nc() == %n%$$. -It specifies which elements of the Hessian are computed. -$list number$$ -The input value of its value vector -$icode%subset%.val()%$$ does not matter. -Upon return it contains the value of the corresponding elements -of the Hessian. -$lnext -All of the row, column pairs in $icode subset$$ must also appear in -$icode pattern$$; i.e., they must be possibly non-zero. -$lnext -The Hessian is symmetric, so one has a choice as to which off diagonal -elements to put in $icode subset$$. -It will probably be more efficient if one makes this choice so that -the there are more entries in each non-zero column of $icode subset$$; -see $cref/n_sweep/sparse_hes/n_sweep/$$ below. -$lend - -$head pattern$$ -This argument has prototype -$codei% - const sparse_rc<%SizeVector%>& %pattern% -%$$ -Its row size and column size is $icode n$$; i.e., -$icode%pattern%.nr() == %n%$$ and $icode%pattern%.nc() == %n%$$. -It is a sparsity pattern for the Hessian $latex H(x)$$. -If the $th i$$ row ($th j$$ column) does not appear in $icode subset$$, -the $th i$$ row ($th j$$ column) of $icode pattern$$ does not matter -and need not be computed. -This argument is not used (and need not satisfy any conditions), -when $cref/work/sparse_hes/work/$$ is non-empty. - -$subhead subset$$ -If the $th i$$ row and $th i$$ column do not appear in $icode subset$$, -the $th i$$ row and column of $icode pattern$$ do not matter. -In this case the $th i-th$$ row and column may have no entries in -$icode pattern$$ even though they are possibly non-zero in $latex H(x)$$. -(This can be used to reduce the amount of computation required to find -$icode pattern$$.) - -$head coloring$$ -The coloring algorithm determines which rows and columns -can be computed during the same sweep. -This field has prototype -$codei% - const std::string& %coloring% -%$$ -This value only matters when work is empty; i.e., -after the $icode work$$ constructor or $icode%work%.clear()%$$. - -$subhead cppad.symmetric$$ -This coloring takes advantage of the fact that the Hessian matrix -is symmetric when find a coloring that requires fewer -$cref/sweeps/sparse_hes/n_sweep/$$. - -$subhead cppad.general$$ -This is the same as the sparse Jacobian -$cref/cppad/sparse_jac/coloring/cppad/$$ method -which does not take advantage of symmetry. - -$subhead colpack.symmetric$$ -If $cref colpack_prefix$$ was specified on the -$cref/cmake command/cmake/CMake Command/$$ line, -you can set $icode coloring$$ to $code colpack.symmetric$$. -This also takes advantage of the fact that the Hessian matrix is symmetric. - -$subhead colpack.general$$ -If $cref colpack_prefix$$ was specified on the -$cref/cmake command/cmake/CMake Command/$$ line, -you can set $icode coloring$$ to $code colpack.general$$. -This is the same as the sparse Jacobian -$cref/colpack/sparse_jac/coloring/colpack/$$ method -which does not take advantage of symmetry. - -$subhead colpack.star Deprecated 2017-06-01$$ -The $code colpack.star$$ method is deprecated. -It is the same as the $code colpack.symmetric$$ method -which should be used instead. - - -$head work$$ -This argument has prototype -$codei% - sparse_hes_work& %work% -%$$ -We refer to its initial value, -and its value after $icode%work%.clear()%$$, as empty. -If it is empty, information is stored in $icode work$$. -This can be used to reduce computation when -a future call is for the same object $icode f$$, -and the same subset of the Hessian. -If either of these values change, use $icode%work%.clear()%$$ to -empty this structure. - -$head n_sweep$$ -The return value $icode n_sweep$$ has prototype -$codei% - size_t %n_sweep% -%$$ -It is the number of first order forward sweeps -used to compute the requested Hessian values. -Each first forward sweep is followed by a second order reverse sweep -so it is also the number of reverse sweeps. -It is also the number of colors determined by the coloring method -mentioned above. -This is proportional to the total computational work, -not counting the zero order forward sweep, -or combining multiple columns and rows into a single sweep. - -$head Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code sparse_hes$$ -the zero order coefficients correspond to -$codei% - %f%.Forward(0, %x%) -%$$ -All the other forward mode coefficients are unspecified. - -$head Example$$ -$children% - example/sparse/sparse_hes.cpp -%$$ -The files $cref sparse_hes.cpp$$ -is an example and test of $code sparse_hes$$. -It returns $code true$$, if it succeeds, and $code false$$ otherwise. - -$head Subset Hessian$$ -The routine -$cref sparse_sub_hes.cpp$$ -is an example and test that compute a subset of a sparse Hessian. -It returns $code true$$, for success, and $code false$$ otherwise. - -$end -*/ -# include -# include -# include -# include - -/*! -\file sparse_hes.hpp -Sparse Hessian calculation routines. -*/ -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/*! -Class used to hold information used by Sparse Hessian routine in this file, -so it does not need to be recomputed every time. -*/ -class sparse_hes_work { - public: - /// row and column indicies for return values - /// (some may be reflected by symmetric coloring algorithms) - CppAD::vector row; - CppAD::vector col; - /// indices that sort the row and col arrays by color - CppAD::vector order; - /// results of the coloring algorithm - CppAD::vector color; - - /// constructor - sparse_hes_work(void) - { } - /// inform CppAD that this information needs to be recomputed - void clear(void) - { - row.clear(); - col.clear(); - order.clear(); - color.clear(); - } -}; -// ---------------------------------------------------------------------------- -/*! -Calculate sparse Hessians using forward mode - -\tparam Base -the base type for the recording that is stored in the ADFun object. - -\tparam SizeVector -a simple vector class with elements of type size_t. - -\tparam BaseVector -a simple vector class with elements of type Base. - -\param x -a vector of length n, the number of independent variables in f -(this ADFun object). - -\param w -a vector of length m, the number of dependent variables in f -(this ADFun object). - -\param subset -specifices the subset of the sparsity pattern where the Hessian is evaluated. -subset.nr() == n, -subset.nc() == n. - -\param pattern -is a sparsity pattern for the Hessian of w^T * f; -pattern.nr() == n, -pattern.nc() == n, -where m is number of dependent variables in f. - -\param coloring -determines which coloring algorithm is used. -This must be cppad.symmetric, cppad.general, colpack.symmetic, -or colpack.star. - -\param work -this structure must be empty, or contain the information stored -by a previous call to sparse_hes. -The previous call must be for the same ADFun object f -and the same subset. - -\return -This is the number of first order forward -(and second order reverse) sweeps used to compute thhe Hessian. -*/ -template -template -size_t ADFun::sparse_hes( - const BaseVector& x , - const BaseVector& w , - sparse_rcv& subset , - const sparse_rc& pattern , - const std::string& coloring , - sparse_hes_work& work ) -{ size_t n = Domain(); - // - CPPAD_ASSERT_KNOWN( - subset.nr() == n, - "sparse_hes: subset.nr() not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - subset.nc() == n, - "sparse_hes: subset.nc() not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - size_t( x.size() ) == n, - "sparse_hes: x.size() not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - size_t( w.size() ) == Range(), - "sparse_hes: w.size() not equal range dimension for f" - ); - // - // work information - vector& row(work.row); - vector& col(work.col); - vector& color(work.color); - vector& order(work.order); - // - // subset information - const SizeVector& subset_row( subset.row() ); - const SizeVector& subset_col( subset.col() ); - // - // point at which we are evaluationg the Hessian - Forward(0, x); - // - // number of elements in the subset - size_t K = subset.nnz(); - // - // check for case were there is nothing to do - // (except for call to Forward(0, x) - if( K == 0 ) - return 0; - // -# ifndef NDEBUG - if( color.size() != 0 ) - { CPPAD_ASSERT_KNOWN( - color.size() == n, - "sparse_hes: work is non-empty and conditions have changed" - ); - CPPAD_ASSERT_KNOWN( - row.size() == K, - "sparse_hes: work is non-empty and conditions have changed" - ); - CPPAD_ASSERT_KNOWN( - col.size() == K, - "sparse_hes: work is non-empty and conditions have changed" - ); - // - for(size_t k = 0; k < K; k++) - { bool ok = row[k] == subset_row[k] && col[k] == subset_col[k]; - ok |= row[k] == subset_col[k] && col[k] == subset_row[k]; - CPPAD_ASSERT_KNOWN( - ok, - "sparse_hes: work is non-empty and conditions have changed" - ); - } - } -# endif - // - // check for case where input work is empty - if( color.size() == 0 ) - { // compute work color and order vectors - CPPAD_ASSERT_KNOWN( - pattern.nr() == n, - "sparse_hes: pattern.nr() not equal domain dimension for f" - ); - CPPAD_ASSERT_KNOWN( - pattern.nc() == n, - "sparse_hes: pattern.nc() not equal domain dimension for f" - ); - // - // initialize work row, col to be same as subset row, col - row.resize(K); - col.resize(K); - // cannot assign vectors becasue may be of different types - // (SizeVector and CppAD::vector) - for(size_t k = 0; k < K; k++) - { row[k] = subset_row[k]; - col[k] = subset_col[k]; - } - // - // convert pattern to an internal version of its transpose - vector internal_index(n); - for(size_t j = 0; j < n; j++) - internal_index[j] = j; - bool transpose = true; - bool zero_empty = false; - bool input_empty = true; - local::sparse_list internal_pattern; - internal_pattern.resize(n, n); - local::set_internal_sparsity(zero_empty, input_empty, - transpose, internal_index, internal_pattern, pattern - ); - // - // execute coloring algorithm - // (we are using transpose becasue coloring groups rows, not columns) - color.resize(n); - if( coloring == "cppad.general" ) - local::color_general_cppad(internal_pattern, col, row, color); - else if( coloring == "cppad.symmetric" ) - local::color_symmetric_cppad(internal_pattern, col, row, color); - else if( coloring == "colpack.general" ) - { -# if CPPAD_HAS_COLPACK - local::color_general_colpack(internal_pattern, col, row, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "sparse_hes: coloring = colpack.star " - "and colpack_prefix not in cmake command line." - ); -# endif - } - else if( - coloring == "colpack.symmetric" || - coloring == "colpack.star" - ) - { -# if CPPAD_HAS_COLPACK - local::color_symmetric_colpack(internal_pattern, col, row, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "sparse_hes: coloring = colpack.symmetic or colpack.star " - "and colpack_prefix not in cmake command line." - ); -# endif - } - else CPPAD_ASSERT_KNOWN( - false, - "sparse_hes: coloring is not valid." - ); - // - // put sorting indices in color order - SizeVector key(K); - order.resize(K); - for(size_t k = 0; k < K; k++) - key[k] = color[ col[k] ]; - index_sort(key, order); - } - // Base versions of zero and one - Base one(1.0); - Base zero(0.0); - // - size_t n_color = 1; - for(size_t j = 0; j < n; j++) if( color[j] < n ) - n_color = std::max(n_color, color[j] + 1); - // - // initialize the return Hessian values as zero - for(size_t k = 0; k < K; k++) - subset.set(k, zero); - // - // direction vector for calls to first order forward - BaseVector dx(n); - // - // return values for calls to second order reverse - BaseVector ddw(2 * n); - // - // loop over colors - size_t k = 0; - for(size_t ell = 0; ell < n_color; ell++) - if( k == K ) - { // kludge because colpack returns colors that are not used - // (it does not know about the subset corresponding to row, col) - CPPAD_ASSERT_UNKNOWN( - coloring == "colpack.general" || - coloring == "colpack.symmetric" || - coloring == "colpack.star" - ); - } - else if( color[ col[ order[k] ] ] != ell ) - { // kludge because colpack returns colors that are not used - // (it does not know about the subset corresponding to row, col) - CPPAD_ASSERT_UNKNOWN( - coloring == "colpack.general" || - coloring == "colpack.symmetic" || - coloring == "colpack.star" - ); - } - else - { CPPAD_ASSERT_UNKNOWN( color[ col[ order[k] ] ] == ell ); - // - // combine all columns with this color - for(size_t j = 0; j < n; j++) - { dx[j] = zero; - if( color[j] == ell ) - dx[j] = one; - } - // call forward mode for all these rows at once - Forward(1, dx); - // - // evaluate derivative of w^T * F'(x) * dx - ddw = Reverse(2, w); - // - // set the corresponding components of the result - while( k < K && color[ col[order[k]] ] == ell ) - { size_t index = row[ order[k] ] * 2 + 1; - subset.set(order[k], ddw[index] ); - k++; - } - } - // check that all the required entries have been set - CPPAD_ASSERT_UNKNOWN( k == K ); - return n_color; -} - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/core/sparse_hessian.hpp b/external/cppad/include/cppad/core/sparse_hessian.hpp deleted file mode 100644 index 55767ae9c..000000000 --- a/external/cppad/include/cppad/core/sparse_hessian.hpp +++ /dev/null @@ -1,861 +0,0 @@ -# ifndef CPPAD_CORE_SPARSE_HESSIAN_HPP -# define CPPAD_CORE_SPARSE_HESSIAN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin sparse_hessian$$ -$spell - jacobian - recomputed - CppAD - valarray - std - Bool - hes - const - Taylor - cppad - cmake - colpack -$$ - -$section Sparse Hessian$$ - -$head Syntax$$ -$icode%hes% = %f%.SparseHessian(%x%, %w%) -%hes% = %f%.SparseHessian(%x%, %w%, %p%) -%n_sweep% = %f%.SparseHessian(%x%, %w%, %p%, %row%, %col%, %hes%, %work%) -%$$ - -$head Purpose$$ -We use $latex n$$ for the $cref/domain/seq_property/Domain/$$ size, -and $latex m$$ for the $cref/range/seq_property/Range/$$ size of $icode f$$. -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ do denote the -$cref/AD function/glossary/AD Function/$$ -corresponding to $icode f$$. -The syntax above sets $icode hes$$ to the Hessian -$latex \[ - H(x) = \dpow{2}{x} \sum_{i=1}^m w_i F_i (x) -\] $$ -This routine takes advantage of the sparsity of the Hessian -in order to reduce the amount of computation necessary. -If $icode row$$ and $icode col$$ are present, it also takes -advantage of the reduced set of elements of the Hessian that -need to be computed. -One can use speed tests (e.g. $cref speed_test$$) -to verify that results are computed faster -than when using the routine $cref Hessian$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/Uses Forward/sparse_hessian/Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %VectorBase%& %x% -%$$ -(see $cref/VectorBase/sparse_hessian/VectorBase/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the Hessian. - -$head w$$ -The argument $icode w$$ has prototype -$codei% - const %VectorBase%& %w% -%$$ -and size $latex m$$. -It specifies the value of $latex w_i$$ in the expression -for $icode hes$$. -The more components of $latex w$$ that are identically zero, -the more sparse the resulting Hessian may be (and hence the more efficient -the calculation of $icode hes$$ may be). - -$head p$$ -The argument $icode p$$ is optional and has prototype -$codei% - const %VectorSet%& %p% -%$$ -(see $cref/VectorSet/sparse_hessian/VectorSet/$$ below) -If it has elements of type $code bool$$, -its size is $latex n * n$$. -If it has elements of type $code std::set$$, -its size is $latex n$$ and all its set elements are between -zero and $latex n - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the Hessian $latex H(x)$$. - -$subhead Purpose$$ -If this sparsity pattern does not change between calls to -$codei SparseHessian$$, it should be faster to calculate $icode p$$ once and -pass this argument to $codei SparseHessian$$. -If you specify $icode p$$, CppAD will use the same -type of sparsity representation -(vectors of $code bool$$ or vectors of $code std::set$$) -for its internal calculations. -Otherwise, the representation -for the internal calculations is unspecified. - -$subhead work$$ -If you specify $icode work$$ in the calling sequence, -it is not necessary to keep the sparsity pattern; see the heading -$cref/p/sparse_hessian/work/p/$$ under the $icode work$$ description. - -$subhead Column Subset$$ -If the arguments $icode row$$ and $icode col$$ are present, -and $cref/color_method/sparse_hessian/work/color_method/$$ is -$code cppad.general$$ or $code cppad.symmetric$$, -it is not necessary to compute the entire sparsity pattern. -Only the following subset of column values will matter: -$codei% - { %col%[%k%] : %k% = 0 , %...% , %K%-1 } -%$$. - - -$head row, col$$ -The arguments $icode row$$ and $icode col$$ are optional and have prototype -$codei% - const %VectorSize%& %row% - const %VectorSize%& %col% -%$$ -(see $cref/VectorSize/sparse_hessian/VectorSize/$$ below). -They specify which rows and columns of $latex H (x)$$ are -returned and in what order. -We use $latex K$$ to denote the value $icode%hes%.size()%$$ -which must also equal the size of $icode row$$ and $icode col$$. -Furthermore, -for $latex k = 0 , \ldots , K-1$$, it must hold that -$latex row[k] < n$$ and $latex col[k] < n$$. -In addition, -all of the $latex (row[k], col[k])$$ pairs must correspond to a true value -in the sparsity pattern $icode p$$. - -$head hes$$ -The result $icode hes$$ has prototype -$codei% - %VectorBase% %hes% -%$$ -In the case where $icode row$$ and $icode col$$ are not present, -the size of $icode hes$$ is $latex n * n$$ and -its size is $latex n * n$$. -In this case, for $latex i = 0 , \ldots , n - 1 $$ -and $latex ell = 0 , \ldots , n - 1$$ -$latex \[ - hes [ j * n + \ell ] = \DD{ w^{\rm T} F }{ x_j }{ x_\ell } ( x ) -\] $$ -$pre - -$$ -In the case where the arguments $icode row$$ and $icode col$$ are present, -we use $latex K$$ to denote the size of $icode hes$$. -The input value of its elements does not matter. -Upon return, for $latex k = 0 , \ldots , K - 1$$, -$latex \[ - hes [ k ] = \DD{ w^{\rm T} F }{ x_j }{ x_\ell } (x) - \; , \; - \; {\rm where} \; - j = row[k] - \; {\rm and } \; - \ell = col[k] -\] $$ - -$head work$$ -If this argument is present, it has prototype -$codei% - sparse_hessian_work& %work% -%$$ -This object can only be used with the routines $code SparseHessian$$. -During its the first use, information is stored in $icode work$$. -This is used to reduce the work done by future calls to $code SparseHessian$$ -with the same $icode f$$, $icode p$$, $icode row$$, and $icode col$$. -If a future call is made where any of these values have changed, -you must first call $icode%work%.clear()%$$ -to inform CppAD that this information needs to be recomputed. - -$subhead color_method$$ -The coloring algorithm determines which rows and columns -can be computed during the same sweep. -This field has prototype -$codei% - std::string %work%.color_method -%$$ -This value only matters on the first call to $code sparse_hessian$$ that -follows the $icode work$$ constructor or a call to -$icode%work%.clear()%$$. -$codei% - -"cppad.symmetric" -%$$ -This is the default coloring method (after a constructor or $code clear()$$). -It takes advantage of the fact that the Hessian matrix -is symmetric to find a coloring that requires fewer -$cref/sweeps/sparse_hessian/n_sweep/$$. -$codei% - -"cppad.general" -%$$ -This is the same as the $code "cppad"$$ method for the -$cref/sparse_jacobian/sparse_jacobian/work/color_method/$$ calculation. -$codei% - -"colpack.symmetric" -%$$ -This method requires that -$cref colpack_prefix$$ was specified on the -$cref/cmake command/cmake/CMake Command/$$ line. -It also takes advantage of the fact that the Hessian matrix is symmetric. -$codei% - -"colpack.general" -%$$ -This is the same as the $code "colpack"$$ method for the -$cref/sparse_jacobian/sparse_jacobian/work/color_method/$$ calculation. - -$subhead colpack.star Deprecated 2017-06-01$$ -The $code colpack.star$$ method is deprecated. -It is the same as the $code colpack.symmetric$$ -which should be used instead. - -$subhead p$$ -If $icode work$$ is present, and it is not the first call after -its construction or a clear, -the sparsity pattern $icode p$$ is not used. -This enables one to free the sparsity pattern -and still compute corresponding sparse Hessians. - -$head n_sweep$$ -The return value $icode n_sweep$$ has prototype -$codei% - size_t %n_sweep% -%$$ -It is the number of first order forward sweeps -used to compute the requested Hessian values. -Each first forward sweep is followed by a second order reverse sweep -so it is also the number of reverse sweeps. -This is proportional to the total work that $code SparseHessian$$ does, -not counting the zero order forward sweep, -or the work to combine multiple columns into a single -forward-reverse sweep pair. - -$head VectorBase$$ -The type $icode VectorBase$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head VectorSet$$ -The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$ or $code std::set$$; -see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion -of the difference. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$subhead Restrictions$$ -If $icode VectorSet$$ has elements of $code std::set$$, -then $icode%p%[%i%]%$$ must return a reference (not a copy) to the -corresponding set. -According to section 26.3.2.3 of the 1998 C++ standard, -$code std::valarray< std::set >$$ does not satisfy -this condition. - -$head VectorSize$$ -The type $icode VectorSize$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to any of the sparse Hessian routines, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -$children% - example/sparse/sparse_hessian.cpp% - example/sparse/sub_sparse_hes.cpp% - example/sparse/sparse_sub_hes.cpp -%$$ - -$head Example$$ -The routine -$cref sparse_hessian.cpp$$ -is examples and tests of $code sparse_hessian$$. -It return $code true$$, if it succeeds and $code false$$ otherwise. - -$head Subset Hessian$$ -The routine -$cref sub_sparse_hes.cpp$$ -is an example and test that compute a sparse Hessian -for a subset of the variables. -It returns $code true$$, for success, and $code false$$ otherwise. - -$end ------------------------------------------------------------------------------ -*/ -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file sparse_hessian.hpp -Sparse Hessian driver routine and helper functions. -*/ -// =========================================================================== -/*! -class used by SparseHessian to hold information -so it does not need to be recomputed. -*/ -class sparse_hessian_work { - public: - /// Coloring method: "cppad", or "colpack" - /// (this field is set by user) - std::string color_method; - /// row and column indicies for return values - /// (some may be reflected by star coloring algorithm) - CppAD::vector row; - CppAD::vector col; - /// indices that sort the user row and col arrays by color - CppAD::vector order; - /// results of the coloring algorithm - CppAD::vector color; - - /// constructor - sparse_hessian_work(void) : color_method("cppad.symmetric") - { } - /// inform CppAD that this information needs to be recomputed - void clear(void) - { color_method = "cppad.symmetric"; - row.clear(); - col.clear(); - order.clear(); - color.clear(); - } -}; -// =========================================================================== -/*! -Private helper function that does computation for all Sparse Hessian cases. - -\tparam Base -is the base type for the recording that is stored in this ADFun. - -\tparam VectorSize -is sparse_pack or sparse_list. - -\param x [in] -is a vector specifing the point at which to compute the Hessian. - -\param w [in] -is the weighting vector that defines a scalar valued function by -a weighted sum of the components of the vector valued function -$latex F(x)$$. - -\param sparsity [in] -is the sparsity pattern for the Hessian that we are calculating. - -\param user_row [in] -is the vector of row indices for the returned Hessian values. - -\param user_col [in] -is the vector of columns indices for the returned Hessian values. -It must have the same size as user_row. - -\param hes [out] -is the vector of Hessian values. -It must have the same size as user_row. -The return value hes[k] is the second partial of -\f$ w^{\rm T} F(x)\f$ with respect to the -row[k] and col[k] component of \f$ x\f$. - -\param work -This structure contains information that is computed by \c SparseHessianCompute. -If the sparsity pattern, \c row vector, or \c col vectors -are not the same between calls to \c SparseHessianCompute, -\c work.clear() must be called to reinitialize \c work. - -\return -Is the number of first order forward sweeps used to compute the -requested Hessian values. -(This is also equal to the number of second order reverse sweeps.) -The total work, not counting the zero order -forward sweep, or the time to combine computations, is proportional to this -return value. -*/ -template -template -size_t ADFun::SparseHessianCompute( - const VectorBase& x , - const VectorBase& w , - VectorSet& sparsity , - const VectorSize& user_row , - const VectorSize& user_col , - VectorBase& hes , - sparse_hessian_work& work ) -{ - using CppAD::vectorBool; - size_t i, k, ell; - - CppAD::vector& row(work.row); - CppAD::vector& col(work.col); - CppAD::vector& color(work.color); - CppAD::vector& order(work.order); - - size_t n = Domain(); - - // some values - const Base zero(0); - const Base one(1); - - // check VectorBase is Simple Vector class with Base type elements - CheckSimpleVector(); - - // number of components of Hessian that are required - size_t K = hes.size(); - CPPAD_ASSERT_UNKNOWN( size_t( user_row.size() ) == K ); - CPPAD_ASSERT_UNKNOWN( size_t( user_col.size() ) == K ); - - CPPAD_ASSERT_UNKNOWN( size_t(x.size()) == n ); - CPPAD_ASSERT_UNKNOWN( color.size() == 0 || color.size() == n ); - CPPAD_ASSERT_UNKNOWN( row.size() == 0 || row.size() == K ); - CPPAD_ASSERT_UNKNOWN( col.size() == 0 || col.size() == K ); - - - // Point at which we are evaluating the Hessian - Forward(0, x); - - // check for case where nothing (except Forward above) to do - if( K == 0 ) - return 0; - - // Rows of the Hessian (i below) correspond to the forward mode index - // and columns (j below) correspond to the reverse mode index. - if( color.size() == 0 ) - { - CPPAD_ASSERT_UNKNOWN( sparsity.n_set() == n ); - CPPAD_ASSERT_UNKNOWN( sparsity.end() == n ); - - // copy user rwo and col to work space - row.resize(K); - col.resize(K); - for(k = 0; k < K; k++) - { row[k] = user_row[k]; - col[k] = user_col[k]; - } - - // execute coloring algorithm - color.resize(n); - if( work.color_method == "cppad.general" ) - local::color_general_cppad(sparsity, row, col, color); - else if( work.color_method == "cppad.symmetric" ) - local::color_symmetric_cppad(sparsity, row, col, color); - else if( work.color_method == "colpack.general" ) - { -# if CPPAD_HAS_COLPACK - local::color_general_colpack(sparsity, row, col, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "SparseHessian: work.color_method = colpack.general " - "and colpack_prefix missing from cmake command line." - ); -# endif - } - else if( - work.color_method == "colpack.symmetric" || - work.color_method == "colpack.star" - ) - { -# if CPPAD_HAS_COLPACK - local::color_symmetric_colpack(sparsity, row, col, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "SparseHessian: work.color_method is " - "colpack.symmetric or colpack.star\n" - "and colpack_prefix missing from cmake command line." - ); -# endif - } - else - { CPPAD_ASSERT_KNOWN( - false, - "SparseHessian: work.color_method is not valid." - ); - } - - // put sorting indices in color order - VectorSize key(K); - order.resize(K); - for(k = 0; k < K; k++) - key[k] = color[ row[k] ]; - index_sort(key, order); - - } - size_t n_color = 1; - for(ell = 0; ell < n; ell++) if( color[ell] < n ) - n_color = std::max(n_color, color[ell] + 1); - - // direction vector for calls to forward (rows of the Hessian) - VectorBase u(n); - - // location for return values from reverse (columns of the Hessian) - VectorBase ddw(2 * n); - - // initialize the return value - for(k = 0; k < K; k++) - hes[k] = zero; - - // loop over colors -# ifndef NDEBUG - const std::string& coloring = work.color_method; -# endif - k = 0; - for(ell = 0; ell < n_color; ell++) - if( k == K ) - { // kludge because colpack returns colors that are not used - // (it does not know about the subset corresponding to row, col) - CPPAD_ASSERT_UNKNOWN( - coloring == "colpack.general" || - coloring == "colpack.symmetic" || - coloring == "colpack.star" - ); - } - else if( color[ row[ order[k] ] ] != ell ) - { // kludge because colpack returns colors that are not used - // (it does not know about the subset corresponding to row, col) - CPPAD_ASSERT_UNKNOWN( - coloring == "colpack.general" || - coloring == "colpack.symmetic" || - coloring == "colpack.star" - ); - } - else - { CPPAD_ASSERT_UNKNOWN( color[ row[ order[k] ] ] == ell ); - - // combine all rows with this color - for(i = 0; i < n; i++) - { u[i] = zero; - if( color[i] == ell ) - u[i] = one; - } - // call forward mode for all these rows at once - Forward(1, u); - - // evaluate derivative of w^T * F'(x) * u - ddw = Reverse(2, w); - - // set the corresponding components of the result - while( k < K && color[ row[ order[k] ] ] == ell ) - { hes[ order[k] ] = ddw[ col[ order[k] ] * 2 + 1 ]; - k++; - } - } - return n_color; -} -// =========================================================================== -// Public Member Functions -// =========================================================================== -/*! -Compute user specified subset of a sparse Hessian. - -The C++ source code corresponding to this operation is -\verbatim - SparceHessian(x, w, p, row, col, hes, work) -\endverbatim - -\tparam Base -is the base type for the recording that is stored in this ADFun. - -\tparam VectorSize -is a simple vector class with elements of type \c size_t. - -\param x [in] -is a vector specifing the point at which to compute the Hessian. - -\param w [in] -is the weighting vector that defines a scalar valued function by -a weighted sum of the components of the vector valued function -$latex F(x)$$. - -\param p [in] -is the sparsity pattern for the Hessian that we are calculating. - -\param row [in] -is the vector of row indices for the returned Hessian values. - -\param col [in] -is the vector of columns indices for the returned Hessian values. -It must have the same size are r. - -\param hes [out] -is the vector of Hessian values. -It must have the same size are r. -The return value hes[k] is the second partial of -\f$ w^{\rm T} F(x)\f$ with respect to the -row[k] and col[k] component of \f$ x\f$. - -\param work -This structure contains information that is computed by \c SparseHessianCompute. -If the sparsity pattern, \c row vector, or \c col vectors -are not the same between calls to \c SparseHessian, -\c work.clear() must be called to reinitialize \c work. - -\return -Is the number of first order forward sweeps used to compute the -requested Hessian values. -(This is also equal to the number of second order reverse sweeps.) -The total work, not counting the zero order -forward sweep, or the time to combine computations, is proportional to this -return value. -*/ -template -template -size_t ADFun::SparseHessian( - const VectorBase& x , - const VectorBase& w , - const VectorSet& p , - const VectorSize& row , - const VectorSize& col , - VectorBase& hes , - sparse_hessian_work& work ) -{ - size_t n = Domain(); - size_t K = hes.size(); -# ifndef NDEBUG - size_t k; - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n , - "SparseHessian: size of x not equal domain dimension for f." - ); - CPPAD_ASSERT_KNOWN( - size_t(row.size()) == K && size_t(col.size()) == K , - "SparseHessian: either r or c does not have the same size as ehs." - ); - CPPAD_ASSERT_KNOWN( - work.color.size() == 0 || work.color.size() == n, - "SparseHessian: invalid value in work." - ); - for(k = 0; k < K; k++) - { CPPAD_ASSERT_KNOWN( - row[k] < n, - "SparseHessian: invalid value in r." - ); - CPPAD_ASSERT_KNOWN( - col[k] < n, - "SparseHessian: invalid value in c." - ); - } - if( work.color.size() != 0 ) - for(size_t j = 0; j < n; j++) CPPAD_ASSERT_KNOWN( - work.color[j] <= n, - "SparseHessian: invalid value in work." - ); -# endif - // check for case where there is nothing to compute - size_t n_sweep = 0; - if( K == 0 ) - return n_sweep; - - typedef typename VectorSet::value_type Set_type; - typedef typename local::internal_sparsity::pattern_type Pattern_type; - Pattern_type s; - if( work.color.size() == 0 ) - { bool transpose = false; - const char* error_msg = "SparseHessian: sparsity pattern" - " does not have proper row or column dimension"; - sparsity_user2internal(s, p, n, n, transpose, error_msg); - } - n_sweep = SparseHessianCompute(x, w, s, row, col, hes, work); - return n_sweep; -} -/*! -Compute a sparse Hessian. - -The C++ source code coresponding to this operation is -\verbatim - hes = SparseHessian(x, w, p) -\endverbatim - - -\tparam Base -is the base type for the recording that is stored in this -ADFun. - -\param x [in] -is a vector specifing the point at which to compute the Hessian. - -\param w [in] -The Hessian is computed for a weighted sum of the components -of the function corresponding to this ADFun object. -The argument \a w specifies the weights for each component. -It must have size equal to the range dimension for this ADFun object. - -\param p [in] -is a sparsity pattern for the Hessian. - -\return -Will be a vector of size \c n * n containing the Hessian of -at the point specified by \a x -(where \c n is the domain dimension for this ADFun object). -*/ -template -template -VectorBase ADFun::SparseHessian( - const VectorBase& x, const VectorBase& w, const VectorSet& p -) -{ size_t i, j, k; - - size_t n = Domain(); - VectorBase hes(n * n); - - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n, - "SparseHessian: size of x not equal domain size for f." - ); - - typedef typename VectorSet::value_type Set_type; - typedef typename local::internal_sparsity::pattern_type Pattern_type; - - // initialize the return value as zero - Base zero(0); - for(i = 0; i < n; i++) - for(j = 0; j < n; j++) - hes[i * n + j] = zero; - - // arguments to SparseHessianCompute - Pattern_type s; - CppAD::vector row; - CppAD::vector col; - sparse_hessian_work work; - bool transpose = false; - const char* error_msg = "SparseHessian: sparsity pattern" - " does not have proper row or column dimension"; - sparsity_user2internal(s, p, n, n, transpose, error_msg); - k = 0; - for(i = 0; i < n; i++) - { typename Pattern_type::const_iterator itr(s, i); - j = *itr; - while( j != s.end() ) - { row.push_back(i); - col.push_back(j); - k++; - j = *(++itr); - } - } - size_t K = k; - VectorBase H(K); - - // now we have folded this into the following case - SparseHessianCompute(x, w, s, row, col, H, work); - - // now set the non-zero return values - for(k = 0; k < K; k++) - hes[ row[k] * n + col[k] ] = H[k]; - - return hes; -} -/*! -Compute a sparse Hessian - -The C++ source code coresponding to this operation is -\verbatim - hes = SparseHessian(x, w) -\endverbatim - - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. -The argument \a w specifies the weights for each component. -It must have size equal to the range dimension for this ADFun object. - -\return -Will be a vector of size \c n * n containing the Hessian of -at the point specified by \a x -(where \c n is the domain dimension for this ADFun object). -*/ -template -template -VectorBase ADFun::SparseHessian(const VectorBase &x, const VectorBase &w) -{ size_t i, j, k; - typedef CppAD::vectorBool VectorBool; - - size_t m = Range(); - size_t n = Domain(); - - // determine the sparsity pattern p for Hessian of w^T F - VectorBool r(n * n); - for(j = 0; j < n; j++) - { for(k = 0; k < n; k++) - r[j * n + k] = false; - r[j * n + j] = true; - } - ForSparseJac(n, r); - // - VectorBool s(m); - for(i = 0; i < m; i++) - s[i] = w[i] != 0; - VectorBool p = RevSparseHes(n, s); - - // compute sparse Hessian - return SparseHessian(x, w, p); -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/sparse_jac.hpp b/external/cppad/include/cppad/core/sparse_jac.hpp deleted file mode 100644 index da0ec0986..000000000 --- a/external/cppad/include/cppad/core/sparse_jac.hpp +++ /dev/null @@ -1,623 +0,0 @@ -# ifndef CPPAD_CORE_SPARSE_JAC_HPP -# define CPPAD_CORE_SPARSE_JAC_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin sparse_jac$$ -$spell - Jacobian - Jacobians - const - jac - Taylor - rc - rcv - nr - nc - std - Cppad - Colpack - cmake -$$ - -$section Computing Sparse Jacobians$$ - -$head Syntax$$ -$icode%n_sweep% = %f%.sparse_jac_for( - %group_max%, %x%, %subset%, %pattern%, %coloring%, %work% -) -%$$ -$icode%n_sweep% = %f%.sparse_jac_rev( - %x%, %subset%, %pattern%, %coloring%, %work% -)%$$ - - -$head Purpose$$ -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the -function corresponding to $icode f$$. -Here $icode n$$ is the $cref/domain/seq_property/Domain/$$ size, -and $icode m$$ is the $cref/range/seq_property/Range/$$ size, or $icode f$$. -The syntax above takes advantage of sparsity when computing the Jacobian -$latex \[ - J(x) = F^{(1)} (x) -\] $$ -In the sparse case, this should be faster and take less memory than -$cref Jacobian$$. -We use the notation $latex J_{i,j} (x)$$ to denote the partial of -$latex F_i (x)$$ with respect to $latex x_j$$. - -$head SizeVector$$ -The type $icode SizeVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head BaseVector$$ -The type $icode BaseVector$$ is a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. - -$head sparse_jac_for$$ -This function uses first order forward mode sweeps $cref forward_one$$ -to compute multiple columns of the Jacobian at the same time. - -$head sparse_jac_rev$$ -This uses function first order reverse mode sweeps $cref reverse_one$$ -to compute multiple rows of the Jacobian at the same time. - -$head f$$ -This object has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the Taylor coefficients stored in $icode f$$ are affected -by this operation; see -$cref/uses forward/sparse_jac/Uses Forward/$$ below. - -$head group_max$$ -This argument has prototype -$codei% - size_t %group_max% -%$$ -and must be greater than zero. -It specifies the maximum number of colors to group during -a single forward sweep. -If a single color is in a group, -a single direction for of first order forward mode -$cref forward_one$$ is used for each color. -If multiple colors are in a group, -the multiple direction for of first order forward mode -$cref forward_dir$$ is used with one direction for each color. -This uses separate memory for each direction (more memory), -but my be significantly faster. - -$head x$$ -This argument has prototype -$codei% - const %BaseVector%& %x% -%$$ -and its size is $icode n$$. -It specifies the point at which to evaluate the Jacobian -$latex J(x)$$. - -$head subset$$ -This argument has prototype -$codei% - sparse_rcv<%SizeVector%, %BaseVector%>& %subset% -%$$ -Its row size is $icode%subset%.nr() == %m%$$, -and its column size is $icode%subset%.nc() == %n%$$. -It specifies which elements of the Jacobian are computed. -The input value of its value vector -$icode%subset%.val()%$$ does not matter. -Upon return it contains the value of the corresponding elements -of the Jacobian. -All of the row, column pairs in $icode subset$$ must also appear in -$icode pattern$$; i.e., they must be possibly non-zero. - -$head pattern$$ -This argument has prototype -$codei% - const sparse_rc<%SizeVector%>& %pattern% -%$$ -Its row size is $icode%pattern%.nr() == %m%$$, -and its column size is $icode%pattern%.nc() == %n%$$. -It is a sparsity pattern for the Jacobian $latex J(x)$$. -This argument is not used (and need not satisfy any conditions), -when $cref/work/sparse_jac/work/$$ is non-empty. - -$head coloring$$ -The coloring algorithm determines which rows (reverse) or columns (forward) -can be computed during the same sweep. -This field has prototype -$codei% - const std::string& %coloring% -%$$ -This value only matters when work is empty; i.e., -after the $icode work$$ constructor or $icode%work%.clear()%$$. - -$subhead cppad$$ -This uses a general purpose coloring algorithm written for Cppad. - -$subhead colpack$$ -If $cref colpack_prefix$$ is specified on the -$cref/cmake command/cmake/CMake Command/$$ line, -you can set $icode coloring$$ to $code colpack$$. -This uses a general purpose coloring algorithm that is part of Colpack. - -$head work$$ -This argument has prototype -$codei% - sparse_jac_work& %work% -%$$ -We refer to its initial value, -and its value after $icode%work%.clear()%$$, as empty. -If it is empty, information is stored in $icode work$$. -This can be used to reduce computation when -a future call is for the same object $icode f$$, -the same member function $code sparse_jac_for$$ or $code sparse_jac_rev$$, -and the same subset of the Jacobian. -If any of these values change, use $icode%work%.clear()%$$ to -empty this structure. - -$head n_sweep$$ -The return value $icode n_sweep$$ has prototype -$codei% - size_t %n_sweep% -%$$ -If $code sparse_jac_for$$ ($code sparse_jac_rev$$) is used, -$icode n_sweep$$ is the number of first order forward (reverse) sweeps -used to compute the requested Jacobian values. -It is also the number of colors determined by the coloring method -mentioned above. -This is proportional to the total computational work, -not counting the zero order forward sweep, -or combining multiple columns (rows) into a single sweep. - -$head Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to $code sparse_jac_forward$$ or $code sparse_jac_rev$$, -the zero order coefficients correspond to -$codei% - %f%.Forward(0, %x%) -%$$ -All the other forward mode coefficients are unspecified. - -$head Example$$ -$children% - example/sparse/sparse_jac_for.cpp% - example/sparse/sparse_jac_rev.cpp -%$$ -The files $cref sparse_jac_for.cpp$$ and $cref sparse_jac_rev.cpp$$ -are examples and tests of $code sparse_jac_for$$ and $code sparse_jac_rev$$. -They return $code true$$, if they succeed, and $code false$$ otherwise. - -$end -*/ -# include -# include -# include -# include - -/*! -\file sparse_jac.hpp -Sparse Jacobian calculation routines. -*/ -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -Class used to hold information used by Sparse Jacobian routines in this file, -so they do not need to be recomputed every time. -*/ -class sparse_jac_work { - public: - /// indices that sort the user row and col arrays by color - CppAD::vector order; - /// results of the coloring algorithm - CppAD::vector color; - // - /// constructor - sparse_jac_work(void) - { } - /// reset work to empty. - /// This informs CppAD that color and order need to be recomputed - void clear(void) - { order.clear(); - color.clear(); - } -}; -// ---------------------------------------------------------------------------- -/*! -Calculate sparse Jacobains using forward mode - -\tparam Base -the base type for the recording that is stored in the ADFun object. - -\tparam SizeVector -a simple vector class with elements of type size_t. - -\tparam BaseVector -a simple vector class with elements of type Base. - -\param group_max -specifies the maximum number of colors to group during a single forward sweep. -This must be greater than zero and group_max = 1 minimizes memory usage. - -\param x -a vector of length n, the number of independent variables in f -(this ADFun object). - -\param subset -specifices the subset of the sparsity pattern where the Jacobian is evaluated. -subset.nr() == m, -subset.nc() == n. - -\param pattern -is a sparsity pattern for the Jacobian of f; -pattern.nr() == m, -pattern.nc() == n, -where m is number of dependent variables in f. - -\param coloring -determines which coloring algorithm is used. -This must be cppad or colpack. - -\param work -this structure must be empty, or contain the information stored -by a previous call to sparse_jac_for. -The previous call must be for the same ADFun object f -and the same subset. - -\return -This is the number of first order forward sweeps used to compute -the Jacobian. -*/ -template -template -size_t ADFun::sparse_jac_for( - size_t group_max , - const BaseVector& x , - sparse_rcv& subset , - const sparse_rc& pattern , - const std::string& coloring , - sparse_jac_work& work ) -{ size_t m = Range(); - size_t n = Domain(); - // - CPPAD_ASSERT_KNOWN( - subset.nr() == m, - "sparse_jac_for: subset.nr() not equal range dimension for f" - ); - CPPAD_ASSERT_KNOWN( - subset.nc() == n, - "sparse_jac_for: subset.nc() not equal domain dimension for f" - ); - // - // row and column vectors in subset - const SizeVector& row( subset.row() ); - const SizeVector& col( subset.col() ); - // - vector& color(work.color); - vector& order(work.order); - CPPAD_ASSERT_KNOWN( - color.size() == 0 || color.size() == n, - "sparse_jac_for: work is non-empty and conditions have changed" - ); - // - // point at which we are evaluationg the Jacobian - Forward(0, x); - // - // number of elements in the subset - size_t K = subset.nnz(); - // - // check for case were there is nothing to do - // (except for call to Forward(0, x) - if( K == 0 ) - return 0; - // - // check for case where input work is empty - if( color.size() == 0 ) - { // compute work color and order vectors - CPPAD_ASSERT_KNOWN( - pattern.nr() == m, - "sparse_jac_for: pattern.nr() not equal range dimension for f" - ); - CPPAD_ASSERT_KNOWN( - pattern.nc() == n, - "sparse_jac_for: pattern.nc() not equal domain dimension for f" - ); - // - // convert pattern to an internal version of its transpose - vector internal_index(n); - for(size_t j = 0; j < n; j++) - internal_index[j] = j; - bool transpose = true; - bool zero_empty = false; - bool input_empty = true; - local::sparse_list pattern_transpose; - pattern_transpose.resize(n, m); - local::set_internal_sparsity(zero_empty, input_empty, - transpose, internal_index, pattern_transpose, pattern - ); - // - // execute coloring algorithm - // (we are using transpose because coloring groups rows, not columns). - color.resize(n); - if( coloring == "cppad" ) - local::color_general_cppad(pattern_transpose, col, row, color); - else if( coloring == "colpack" ) - { -# if CPPAD_HAS_COLPACK - local::color_general_colpack(pattern_transpose, col, row, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "sparse_jac_for: coloring = colpack " - "and colpack_prefix missing from cmake command line." - ); -# endif - } - else CPPAD_ASSERT_KNOWN( - false, - "sparse_jac_for: coloring is not valid." - ); - // - // put sorting indices in color order - SizeVector key(K); - order.resize(K); - for(size_t k = 0; k < K; k++) - key[k] = color[ col[k] ]; - index_sort(key, order); - } - // Base versions of zero and one - Base one(1.0); - Base zero(0.0); - // - size_t n_color = 1; - for(size_t j = 0; j < n; j++) if( color[j] < n ) - n_color = std::max(n_color, color[j] + 1); - // - // initialize the return Jacobian values as zero - for(size_t k = 0; k < K; k++) - subset.set(k, zero); - // - // index in subset - size_t k = 0; - // number of colors computed so far - size_t color_count = 0; - // - while( color_count < n_color ) - { // number of colors that will be in this group - size_t group_size = std::min(group_max, n_color - color_count); - // - // forward mode values for independent and dependent variables - BaseVector dx(n * group_size), dy(m * group_size); - // - // set dx - for(size_t ell = 0; ell < group_size; ell++) - { // combine all columns with this color - for(size_t j = 0; j < n; j++) - { dx[j * group_size + ell] = zero; - if( color[j] == ell + color_count ) - dx[j * group_size + ell] = one; - } - } - if( group_size == 1 ) - dy = Forward(1, dx); - else - dy = Forward(1, group_size, dx); - // - // store results in subset - for(size_t ell = 0; ell < group_size; ell++) - { // color with index ell + color_count is in this group - while(k < K && color[ col[ order[k] ] ] == ell + color_count ) - { // subset element with index order[k] is included in this color - size_t r = row[ order[k] ]; - subset.set( order[k], dy[ r * group_size + ell ] ); - ++k; - } - } - // advance color count - color_count += group_size; - } - CPPAD_ASSERT_UNKNOWN( color_count == n_color ); - // - return n_color; -} -// ---------------------------------------------------------------------------- -/*! -Calculate sparse Jacobains using reverse mode - -\tparam Base -the base type for the recording that is stored in the ADFun object. - -\tparam SizeVector -a simple vector class with elements of type size_t. - -\tparam BaseVector -a simple vector class with elements of type Base. - -\param x -a vector of length n, the number of independent variables in f -(this ADFun object). - -\param subset -specifices the subset of the sparsity pattern where the Jacobian is evaluated. -subset.nr() == m, -subset.nc() == n. - -\param pattern -is a sparsity pattern for the Jacobian of f; -pattern.nr() == m, -pattern.nc() == n, -where m is number of dependent variables in f. - -\param coloring -determines which coloring algorithm is used. -This must be cppad or colpack. - -\param work -this structure must be empty, or contain the information stored -by a previous call to sparse_jac_rev. -The previous call must be for the same ADFun object f -and the same subset. - -\return -This is the number of first order reverse sweeps used to compute -the Jacobian. -*/ -template -template -size_t ADFun::sparse_jac_rev( - const BaseVector& x , - sparse_rcv& subset , - const sparse_rc& pattern , - const std::string& coloring , - sparse_jac_work& work ) -{ size_t m = Range(); - size_t n = Domain(); - // - CPPAD_ASSERT_KNOWN( - subset.nr() == m, - "sparse_jac_rev: subset.nr() not equal range dimension for f" - ); - CPPAD_ASSERT_KNOWN( - subset.nc() == n, - "sparse_jac_rev: subset.nc() not equal domain dimension for f" - ); - // - // row and column vectors in subset - const SizeVector& row( subset.row() ); - const SizeVector& col( subset.col() ); - // - vector& color(work.color); - vector& order(work.order); - CPPAD_ASSERT_KNOWN( - color.size() == 0 || color.size() == m, - "sparse_jac_rev: work is non-empty and conditions have changed" - ); - // - // point at which we are evaluationg the Jacobian - Forward(0, x); - // - // number of elements in the subset - size_t K = subset.nnz(); - // - // check for case were there is nothing to do - // (except for call to Forward(0, x) - if( K == 0 ) - return 0; - // - // check for case where input work is empty - if( color.size() == 0 ) - { // compute work color and order vectors - CPPAD_ASSERT_KNOWN( - pattern.nr() == m, - "sparse_jac_rev: pattern.nr() not equal range dimension for f" - ); - CPPAD_ASSERT_KNOWN( - pattern.nc() == n, - "sparse_jac_rev: pattern.nc() not equal domain dimension for f" - ); - // - // convert pattern to an internal version - vector internal_index(m); - for(size_t i = 0; i < m; i++) - internal_index[i] = i; - bool transpose = false; - bool zero_empty = false; - bool input_empty = true; - local::sparse_list internal_pattern; - internal_pattern.resize(m, n); - local::set_internal_sparsity(zero_empty, input_empty, - transpose, internal_index, internal_pattern, pattern - ); - // - // execute coloring algorithm - color.resize(m); - if( coloring == "cppad" ) - local::color_general_cppad(internal_pattern, row, col, color); - else if( coloring == "colpack" ) - { -# if CPPAD_HAS_COLPACK - local::color_general_colpack(internal_pattern, row, col, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "sparse_jac_rev: coloring = colpack " - "and colpack_prefix missing from cmake command line." - ); -# endif - } - else CPPAD_ASSERT_KNOWN( - false, - "sparse_jac_rev: coloring is not valid." - ); - // - // put sorting indices in color order - SizeVector key(K); - order.resize(K); - for(size_t k = 0; k < K; k++) - key[k] = color[ row[k] ]; - index_sort(key, order); - } - // Base versions of zero and one - Base one(1.0); - Base zero(0.0); - // - size_t n_color = 1; - for(size_t i = 0; i < m; i++) if( color[i] < m ) - n_color = std::max(n_color, color[i] + 1); - // - // initialize the return Jacobian values as zero - for(size_t k = 0; k < K; k++) - subset.set(k, zero); - // - // weighting vector and return values for calls to Reverse - BaseVector w(m), dw(n); - // - // loop over colors - size_t k = 0; - for(size_t ell = 0; ell < n_color; ell++) - if( k == K ) - { // kludge because colpack returns colors that are not used - // (it does not know about the subset corresponding to row, col) - CPPAD_ASSERT_UNKNOWN( coloring == "colpack" ); - } - else if( color[ row[ order[k] ] ] != ell ) - { // kludge because colpack returns colors that are not used - // (it does not know about the subset corresponding to row, col) - CPPAD_ASSERT_UNKNOWN( coloring == "colpack" ); - } - else - { CPPAD_ASSERT_UNKNOWN( color[ row[ order[k] ] ] == ell ); - // - // combine all rows with this color - for(size_t i = 0; i < m; i++) - { w[i] = zero; - if( color[i] == ell ) - w[i] = one; - } - // call reverse mode for all these rows at once - dw = Reverse(1, w); - // - // set the corresponding components of the result - while( k < K && color[ row[order[k]] ] == ell ) - { subset.set(order[k], dw[col[order[k]]] ); - k++; - } - } - return n_color; -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/sparse_jacobian.hpp b/external/cppad/include/cppad/core/sparse_jacobian.hpp deleted file mode 100644 index 8adc9bd12..000000000 --- a/external/cppad/include/cppad/core/sparse_jacobian.hpp +++ /dev/null @@ -1,1086 +0,0 @@ -# ifndef CPPAD_CORE_SPARSE_JACOBIAN_HPP -# define CPPAD_CORE_SPARSE_JACOBIAN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// maximum number of sparse directions to compute at the same time - -// # define CPPAD_SPARSE_JACOBIAN_MAX_MULTIPLE_DIRECTION 1 -# define CPPAD_SPARSE_JACOBIAN_MAX_MULTIPLE_DIRECTION 64 - -/* -$begin sparse_jacobian$$ -$spell - cppad - colpack - cmake - recomputed - valarray - std - CppAD - Bool - jac - Jacobian - Jacobians - const - Taylor -$$ - -$section Sparse Jacobian$$ - -$head Syntax$$ -$icode%jac% = %f%.SparseJacobian(%x%) -%jac% = %f%.SparseJacobian(%x%, %p%) -%n_sweep% = %f%.SparseJacobianForward(%x%, %p%, %row%, %col%, %jac%, %work%) -%n_sweep% = %f%.SparseJacobianReverse(%x%, %p%, %row%, %col%, %jac%, %work%) -%$$ - -$head Purpose$$ -We use $latex n$$ for the $cref/domain/seq_property/Domain/$$ size, -and $latex m$$ for the $cref/range/seq_property/Range/$$ size of $icode f$$. -We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ do denote the -$cref/AD function/glossary/AD Function/$$ -corresponding to $icode f$$. -The syntax above sets $icode jac$$ to the Jacobian -$latex \[ - jac = F^{(1)} (x) -\] $$ -This routine takes advantage of the sparsity of the Jacobian -in order to reduce the amount of computation necessary. -If $icode row$$ and $icode col$$ are present, it also takes -advantage of the reduced set of elements of the Jacobian that -need to be computed. -One can use speed tests (e.g. $cref speed_test$$) -to verify that results are computed faster -than when using the routine $cref Jacobian$$. - -$head f$$ -The object $icode f$$ has prototype -$codei% - ADFun<%Base%> %f% -%$$ -Note that the $cref ADFun$$ object $icode f$$ is not $code const$$ -(see $cref/Uses Forward/sparse_jacobian/Uses Forward/$$ below). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %VectorBase%& %x% -%$$ -(see $cref/VectorBase/sparse_jacobian/VectorBase/$$ below) -and its size -must be equal to $icode n$$, the dimension of the -$cref/domain/seq_property/Domain/$$ space for $icode f$$. -It specifies -that point at which to evaluate the Jacobian. - -$head p$$ -The argument $icode p$$ is optional and has prototype -$codei% - const %VectorSet%& %p% -%$$ -(see $cref/VectorSet/sparse_jacobian/VectorSet/$$ below). -If it has elements of type $code bool$$, -its size is $latex m * n$$. -If it has elements of type $code std::set$$, -its size is $latex m$$ and all its set elements are between -zero and $latex n - 1$$. -It specifies a -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ -for the Jacobian $latex F^{(1)} (x)$$. -$pre - -$$ -If this sparsity pattern does not change between calls to -$codei SparseJacobian$$, it should be faster to calculate $icode p$$ once -(using $cref ForSparseJac$$ or $cref RevSparseJac$$) -and then pass $icode p$$ to $codei SparseJacobian$$. -Furthermore, if you specify $icode work$$ in the calling sequence, -it is not necessary to keep the sparsity pattern; see the heading -$cref/p/sparse_jacobian/work/p/$$ under the $icode work$$ description. -$pre - -$$ -In addition, -if you specify $icode p$$, CppAD will use the same -type of sparsity representation -(vectors of $code bool$$ or vectors of $code std::set$$) -for its internal calculations. -Otherwise, the representation -for the internal calculations is unspecified. - -$head row, col$$ -The arguments $icode row$$ and $icode col$$ are optional and have prototype -$codei% - const %VectorSize%& %row% - const %VectorSize%& %col% -%$$ -(see $cref/VectorSize/sparse_jacobian/VectorSize/$$ below). -They specify which rows and columns of $latex F^{(1)} (x)$$ are -computes and in what order. -Not all the non-zero entries in $latex F^{(1)} (x)$$ need be computed, -but all the entries specified by $icode row$$ and $icode col$$ -must be possibly non-zero in the sparsity pattern. -We use $latex K$$ to denote the value $icode%jac%.size()%$$ -which must also equal the size of $icode row$$ and $icode col$$. -Furthermore, -for $latex k = 0 , \ldots , K-1$$, it must hold that -$latex row[k] < m$$ and $latex col[k] < n$$. - -$head jac$$ -The result $icode jac$$ has prototype -$codei% - %VectorBase%& %jac% -%$$ -In the case where the arguments $icode row$$ and $icode col$$ are not present, -the size of $icode jac$$ is $latex m * n$$ and -for $latex i = 0 , \ldots , m-1$$, -$latex j = 0 , \ldots , n-1$$, -$latex \[ - jac [ i * n + j ] = \D{ F_i }{ x_j } (x) -\] $$ -$pre - -$$ -In the case where the arguments $icode row$$ and $icode col$$ are present, -we use $latex K$$ to denote the size of $icode jac$$. -The input value of its elements does not matter. -Upon return, for $latex k = 0 , \ldots , K - 1$$, -$latex \[ - jac [ k ] = \D{ F_i }{ x_j } (x) - \; , \; - \; {\rm where} \; - i = row[k] - \; {\rm and } \; - j = col[k] -\] $$ - -$head work$$ -If this argument is present, it has prototype -$codei% - sparse_jacobian_work& %work% -%$$ -This object can only be used with the routines -$code SparseJacobianForward$$ and $code SparseJacobianReverse$$. -During its the first use, information is stored in $icode work$$. -This is used to reduce the work done by future calls to the same mode -(forward or reverse), -the same $icode f$$, $icode p$$, $icode row$$, and $icode col$$. -If a future call is for a different mode, -or any of these values have changed, -you must first call $icode%work%.clear()%$$ -to inform CppAD that this information needs to be recomputed. - -$subhead color_method$$ -The coloring algorithm determines which columns (forward mode) -or rows (reverse mode) can be computed during the same sweep. -This field has prototype -$codei% - std::string %work%.color_method -%$$ -and its default value (after a constructor or $code clear()$$) -is $code "cppad"$$. -If $cref colpack_prefix$$ is specified on the -$cref/cmake command/cmake/CMake Command/$$ line, -you can set this method to $code "colpack"$$. -This value only matters on the first call to $code sparse_jacobian$$ -that follows the $icode work$$ constructor or a call to -$icode%work%.clear()%$$. - -$subhead p$$ -If $icode work$$ is present, and it is not the first call after -its construction or a clear, -the sparsity pattern $icode p$$ is not used. -This enables one to free the sparsity pattern -and still compute corresponding sparse Jacobians. - -$head n_sweep$$ -The return value $icode n_sweep$$ has prototype -$codei% - size_t %n_sweep% -%$$ -If $code SparseJacobianForward$$ ($code SparseJacobianReverse$$) is used, -$icode n_sweep$$ is the number of first order forward (reverse) sweeps -used to compute the requested Jacobian values. -(This is also the number of colors determined by the coloring method -mentioned above). -This is proportional to the total work that $code SparseJacobian$$ does, -not counting the zero order forward sweep, -or the work to combine multiple columns (rows) into a single sweep. - -$head VectorBase$$ -The type $icode VectorBase$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Base$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head VectorSet$$ -The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$ or $code std::set$$; -see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion -of the difference. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$subhead Restrictions$$ -If $icode VectorSet$$ has elements of $code std::set$$, -then $icode%p%[%i%]%$$ must return a reference (not a copy) to the -corresponding set. -According to section 26.3.2.3 of the 1998 C++ standard, -$code std::valarray< std::set >$$ does not satisfy -this condition. - -$head VectorSize$$ -The type $icode VectorSize$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code size_t$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Uses Forward$$ -After each call to $cref Forward$$, -the object $icode f$$ contains the corresponding -$cref/Taylor coefficients/glossary/Taylor Coefficient/$$. -After a call to any of the sparse Jacobian routines, -the zero order Taylor coefficients correspond to -$icode%f%.Forward(0, %x%)%$$ -and the other coefficients are unspecified. - -After $code SparseJacobian$$, -the previous calls to $cref Forward$$ are undefined. - -$head Example$$ -$children% - example/sparse/sparse_jacobian.cpp -%$$ -The routine -$cref sparse_jacobian.cpp$$ -is examples and tests of $code sparse_jacobian$$. -It return $code true$$, if it succeeds and $code false$$ otherwise. - -$end -============================================================================== -*/ -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file sparse_jacobian.hpp -Sparse Jacobian driver routine and helper functions. -*/ -// =========================================================================== -/*! -class used by SparseJacobian to hold information so it does not need to be -recomputed. -*/ -class sparse_jacobian_work { - public: - /// Coloring method: "cppad", or "colpack" - /// (this field is set by user) - std::string color_method; - /// indices that sort the user row and col arrays by color - CppAD::vector order; - /// results of the coloring algorithm - CppAD::vector color; - - /// constructor - sparse_jacobian_work(void) : color_method("cppad") - { } - /// reset coloring method to its default and - /// inform CppAD that color and order need to be recomputed - void clear(void) - { color_method = "cppad"; - order.clear(); - color.clear(); - } -}; -// =========================================================================== -/*! -Private helper function forward mode cases - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. - -\tparam VectorBase -is a simple vector class with elements of type \a Base. - -\tparam VectorSet -is either sparse_pack or sparse_list. - -\tparam VectorSize -is a simple vector class with elements of type \c size_t. - -\param x [in] -is a vector specifing the point at which to compute the Jacobian. - -\param p_transpose [in] -If work.color.size() != 0, -then \c p_transpose is not used. -Otherwise, it is a -sparsity pattern for the transpose of the Jacobian of this ADFun object. -Note that we do not change the values in \c p_transpose, -but is not \c const because we use its iterator facility. - -\param row [in] -is the vector of row indices for the returned Jacobian values. - -\param col [in] -is the vector of columns indices for the returned Jacobian values. -It must have the same size as \c row. - -\param jac [out] -is the vector of Jacobian values. We use \c K to denote the size of \c jac. -The return value jac[k] is the partial of the -row[k] range component of the function with respect -the the col[k] domain component of its argument. - -\param work -work.color_method is an input. The rest of -this structure contains information that is computed by \c SparseJacobainFor. -If the sparsity pattern, \c row vector, or \c col vectors -are not the same between calls to \c SparseJacobianFor, -\c work.clear() must be called to reinitialize \c work. - -\return -Is the number of first order forward sweeps used to compute the -requested Jacobian values. The total work, not counting the zero order -forward sweep, or the time to combine computations, is proportional to this -return value. -*/ -template -template -size_t ADFun::SparseJacobianFor( - const VectorBase& x , - VectorSet& p_transpose , - const VectorSize& row , - const VectorSize& col , - VectorBase& jac , - sparse_jacobian_work& work ) -{ - size_t j, k, ell; - - CppAD::vector& order(work.order); - CppAD::vector& color(work.color); - - size_t m = Range(); - size_t n = Domain(); - - // some values - const Base zero(0); - const Base one(1); - - // check VectorBase is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_UNKNOWN( size_t(x.size()) == n ); - CPPAD_ASSERT_UNKNOWN( color.size() == 0 || color.size() == n ); - - // number of components of Jacobian that are required - size_t K = size_t(jac.size()); - CPPAD_ASSERT_UNKNOWN( size_t( row.size() ) == K ); - CPPAD_ASSERT_UNKNOWN( size_t( col.size() ) == K ); - - // Point at which we are evaluating the Jacobian - Forward(0, x); - - // check for case where nothing (except Forward above) to do - if( K == 0 ) - return 0; - - if( color.size() == 0 ) - { - CPPAD_ASSERT_UNKNOWN( p_transpose.n_set() == n ); - CPPAD_ASSERT_UNKNOWN( p_transpose.end() == m ); - - // execute coloring algorithm - color.resize(n); - if( work.color_method == "cppad" ) - local::color_general_cppad(p_transpose, col, row, color); - else if( work.color_method == "colpack" ) - { -# if CPPAD_HAS_COLPACK - local::color_general_colpack(p_transpose, col, row, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "SparseJacobianForward: work.color_method = colpack " - "and colpack_prefix missing from cmake command line." - ); -# endif - } - else CPPAD_ASSERT_KNOWN( - false, - "SparseJacobianForward: work.color_method is not valid." - ); - - // put sorting indices in color order - VectorSize key(K); - order.resize(K); - for(k = 0; k < K; k++) - key[k] = color[ col[k] ]; - index_sort(key, order); - } - size_t n_color = 1; - for(j = 0; j < n; j++) if( color[j] < n ) - n_color = std::max(n_color, color[j] + 1); - - // initialize the return value - for(k = 0; k < K; k++) - jac[k] = zero; - -# if CPPAD_SPARSE_JACOBIAN_MAX_MULTIPLE_DIRECTION == 1 - // direction vector and return values for calls to forward - VectorBase dx(n), dy(m); - - // loop over colors - k = 0; - for(ell = 0; ell < n_color; ell++) - { CPPAD_ASSERT_UNKNOWN( color[ col[ order[k] ] ] == ell ); - - // combine all columns with this color - for(j = 0; j < n; j++) - { dx[j] = zero; - if( color[j] == ell ) - dx[j] = one; - } - // call forward mode for all these columns at once - dy = Forward(1, dx); - - // set the corresponding components of the result - while( k < K && color[ col[order[k]] ] == ell ) - { jac[ order[k] ] = dy[row[order[k]]]; - k++; - } - } -# else - // abbreviation for this value - size_t max_r = CPPAD_SPARSE_JACOBIAN_MAX_MULTIPLE_DIRECTION; - CPPAD_ASSERT_UNKNOWN( max_r > 1 ); - - // count the number of colors done so far - size_t count_color = 0; - // count the sparse matrix entries done so far - k = 0; - while( count_color < n_color ) - { // number of colors we will do this time - size_t r = std::min(max_r , n_color - count_color); - VectorBase dx(n * r), dy(m * r); - - // loop over colors we will do this tme - for(ell = 0; ell < r; ell++) - { // combine all columns with this color - for(j = 0; j < n; j++) - { dx[j * r + ell] = zero; - if( color[j] == ell + count_color ) - dx[j * r + ell] = one; - } - } - size_t q = 1; - dy = Forward(q, r, dx); - - // store results - for(ell = 0; ell < r; ell++) - { // set the components of the result for this color - while( k < K && color[ col[order[k]] ] == ell + count_color ) - { jac[ order[k] ] = dy[ row[order[k]] * r + ell ]; - k++; - } - } - count_color += r; - } -# endif - return n_color; -} -/*! -Private helper function for reverse mode cases. - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. - -\tparam VectorBase -is a simple vector class with elements of type \a Base. - -\tparam VectorSet -is either sparse_pack or sparse_list. - -\tparam VectorSize -is a simple vector class with elements of type \c size_t. - -\param x [in] -is a vector specifing the point at which to compute the Jacobian. - -\param p [in] -If work.color.size() != 0, then \c p is not used. -Otherwise, it is a -sparsity pattern for the Jacobian of this ADFun object. -Note that we do not change the values in \c p, -but is not \c const because we use its iterator facility. - -\param row [in] -is the vector of row indices for the returned Jacobian values. - -\param col [in] -is the vector of columns indices for the returned Jacobian values. -It must have the same size as \c row. - -\param jac [out] -is the vector of Jacobian values. -It must have the same size as \c row. -The return value jac[k] is the partial of the -row[k] range component of the function with respect -the the col[k] domain component of its argument. - -\param work -work.color_method is an input. The rest of -This structure contains information that is computed by \c SparseJacobainRev. -If the sparsity pattern, \c row vector, or \c col vectors -are not the same between calls to \c SparseJacobianRev, -\c work.clear() must be called to reinitialize \c work. - -\return -Is the number of first order reverse sweeps used to compute the -reverse Jacobian values. The total work, not counting the zero order -forward sweep, or the time to combine computations, is proportional to this -return value. -*/ -template -template -size_t ADFun::SparseJacobianRev( - const VectorBase& x , - VectorSet& p , - const VectorSize& row , - const VectorSize& col , - VectorBase& jac , - sparse_jacobian_work& work ) -{ - size_t i, k, ell; - - CppAD::vector& order(work.order); - CppAD::vector& color(work.color); - - size_t m = Range(); - size_t n = Domain(); - - // some values - const Base zero(0); - const Base one(1); - - // check VectorBase is Simple Vector class with Base type elements - CheckSimpleVector(); - - CPPAD_ASSERT_UNKNOWN( size_t(x.size()) == n ); - CPPAD_ASSERT_UNKNOWN (color.size() == m || color.size() == 0 ); - - // number of components of Jacobian that are required - size_t K = size_t(jac.size()); - CPPAD_ASSERT_UNKNOWN( size_t( size_t( row.size() ) ) == K ); - CPPAD_ASSERT_UNKNOWN( size_t( size_t( col.size() ) ) == K ); - - // Point at which we are evaluating the Jacobian - Forward(0, x); - - // check for case where nothing (except Forward above) to do - if( K == 0 ) - return 0; - - if( color.size() == 0 ) - { - CPPAD_ASSERT_UNKNOWN( p.n_set() == m ); - CPPAD_ASSERT_UNKNOWN( p.end() == n ); - - // execute the coloring algorithm - color.resize(m); - if( work.color_method == "cppad" ) - local::color_general_cppad(p, row, col, color); - else if( work.color_method == "colpack" ) - { -# if CPPAD_HAS_COLPACK - local::color_general_colpack(p, row, col, color); -# else - CPPAD_ASSERT_KNOWN( - false, - "SparseJacobianReverse: work.color_method = colpack " - "and colpack_prefix missing from cmake command line." - ); -# endif - } - else CPPAD_ASSERT_KNOWN( - false, - "SparseJacobianReverse: work.color_method is not valid." - ); - - // put sorting indices in color order - VectorSize key(K); - order.resize(K); - for(k = 0; k < K; k++) - key[k] = color[ row[k] ]; - index_sort(key, order); - } - size_t n_color = 1; - for(i = 0; i < m; i++) if( color[i] < m ) - n_color = std::max(n_color, color[i] + 1); - - // weighting vector for calls to reverse - VectorBase w(m); - - // location for return values from Reverse - VectorBase dw(n); - - // initialize the return value - for(k = 0; k < K; k++) - jac[k] = zero; - - // loop over colors - k = 0; - for(ell = 0; ell < n_color; ell++) - { CPPAD_ASSERT_UNKNOWN( color[ row[ order[k] ] ] == ell ); - - // combine all the rows with this color - for(i = 0; i < m; i++) - { w[i] = zero; - if( color[i] == ell ) - w[i] = one; - } - // call reverse mode for all these rows at once - dw = Reverse(1, w); - - // set the corresponding components of the result - while( k < K && color[ row[order[k]] ] == ell ) - { jac[ order[k] ] = dw[col[order[k]]]; - k++; - } - } - return n_color; -} -// ========================================================================== -// Public Member functions -// ========================================================================== -/*! -Compute user specified subset of a sparse Jacobian using forward mode. - -The C++ source code corresponding to this operation is -\verbatim - SparceJacobianForward(x, p, row, col, jac, work) -\endverbatim - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. - -\tparam VectorBase -is a simple vector class with elements of type \a Base. - -\tparam VectorSet -is a simple vector class with elements of type -\c bool or \c std::set. - -\tparam VectorSize -is a simple vector class with elements of type \c size_t. - -\param x [in] -is a vector specifing the point at which to compute the Jacobian. - -\param p [in] -is the sparsity pattern for the Jacobian that we are calculating. - -\param row [in] -is the vector of row indices for the returned Jacobian values. - -\param col [in] -is the vector of columns indices for the returned Jacobian values. -It must have the same size as \c row. - -\param jac [out] -is the vector of Jacobian values. -It must have the same size as \c row. -The return value jac[k] is the partial of the -row[k] range component of the function with respect -the the col[k] domain component of its argument. - -\param work [in,out] -this structure contains information that depends on the function object, -sparsity pattern, \c row vector, and \c col vector. -If they are not the same between calls to \c SparseJacobianForward, -\c work.clear() must be called to reinitialize them. - -\return -Is the number of first order forward sweeps used to compute the -requested Jacobian values. The total work, not counting the zero order -forward sweep, or the time to combine computations, is proportional to this -return value. -*/ -template -template -size_t ADFun::SparseJacobianForward( - const VectorBase& x , - const VectorSet& p , - const VectorSize& row , - const VectorSize& col , - VectorBase& jac , - sparse_jacobian_work& work ) -{ - size_t n = Domain(); - size_t m = Range(); - size_t K = jac.size(); -# ifndef NDEBUG - size_t k; - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n , - "SparseJacobianForward: size of x not equal domain dimension for f." - ); - CPPAD_ASSERT_KNOWN( - size_t(row.size()) == K && size_t(col.size()) == K , - "SparseJacobianForward: either r or c does not have " - "the same size as jac." - ); - CPPAD_ASSERT_KNOWN( - work.color.size() == 0 || work.color.size() == n, - "SparseJacobianForward: invalid value in work." - ); - for(k = 0; k < K; k++) - { CPPAD_ASSERT_KNOWN( - row[k] < m, - "SparseJacobianForward: invalid value in r." - ); - CPPAD_ASSERT_KNOWN( - col[k] < n, - "SparseJacobianForward: invalid value in c." - ); - } - if( work.color.size() != 0 ) - for(size_t j = 0; j < n; j++) CPPAD_ASSERT_KNOWN( - work.color[j] <= n, - "SparseJacobianForward: invalid value in work." - ); -# endif - // check for case where there is nothing to compute - size_t n_sweep = 0; - if( K == 0 ) - return n_sweep; - - typedef typename VectorSet::value_type Set_type; - typedef typename local::internal_sparsity::pattern_type Pattern_type; - Pattern_type s_transpose; - if( work.color.size() == 0 ) - { bool transpose = true; - const char* error_msg = "SparseJacobianForward: transposed sparsity" - " pattern does not have proper row or column dimension"; - sparsity_user2internal(s_transpose, p, n, m, transpose, error_msg); - } - n_sweep = SparseJacobianFor(x, s_transpose, row, col, jac, work); - return n_sweep; -} -/*! -Compute user specified subset of a sparse Jacobian using forward mode. - -The C++ source code corresponding to this operation is -\verbatim - SparceJacobianReverse(x, p, row, col, jac, work) -\endverbatim - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. - -\tparam VectorBase -is a simple vector class with elements of type \a Base. - -\tparam VectorSet -is a simple vector class with elements of type -\c bool or \c std::set. - -\tparam VectorSize -is a simple vector class with elements of type \c size_t. - -\param x [in] -is a vector specifing the point at which to compute the Jacobian. - -\param p [in] -is the sparsity pattern for the Jacobian that we are calculating. - -\param row [in] -is the vector of row indices for the returned Jacobian values. - -\param col [in] -is the vector of columns indices for the returned Jacobian values. -It must have the same size as \c row. - -\param jac [out] -is the vector of Jacobian values. -It must have the same size as \c row. -The return value jac[k] is the partial of the -row[k] range component of the function with respect -the the col[k] domain component of its argument. - -\param work [in,out] -this structure contains information that depends on the function object, -sparsity pattern, \c row vector, and \c col vector. -If they are not the same between calls to \c SparseJacobianReverse, -\c work.clear() must be called to reinitialize them. - -\return -Is the number of first order reverse sweeps used to compute the -reverse Jacobian values. The total work, not counting the zero order -forward sweep, or the time to combine computations, is proportional to this -return value. -*/ -template -template -size_t ADFun::SparseJacobianReverse( - const VectorBase& x , - const VectorSet& p , - const VectorSize& row , - const VectorSize& col , - VectorBase& jac , - sparse_jacobian_work& work ) -{ - size_t m = Range(); - size_t n = Domain(); - size_t K = jac.size(); -# ifndef NDEBUG - size_t k; - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n , - "SparseJacobianReverse: size of x not equal domain dimension for f." - ); - CPPAD_ASSERT_KNOWN( - size_t(row.size()) == K && size_t(col.size()) == K , - "SparseJacobianReverse: either r or c does not have " - "the same size as jac." - ); - CPPAD_ASSERT_KNOWN( - work.color.size() == 0 || work.color.size() == m, - "SparseJacobianReverse: invalid value in work." - ); - for(k = 0; k < K; k++) - { CPPAD_ASSERT_KNOWN( - row[k] < m, - "SparseJacobianReverse: invalid value in r." - ); - CPPAD_ASSERT_KNOWN( - col[k] < n, - "SparseJacobianReverse: invalid value in c." - ); - } - if( work.color.size() != 0 ) - for(size_t i = 0; i < m; i++) CPPAD_ASSERT_KNOWN( - work.color[i] <= m, - "SparseJacobianReverse: invalid value in work." - ); -# endif - // check for case where there is nothing to compute - size_t n_sweep = 0; - if( K == 0 ) - return n_sweep; - - typedef typename VectorSet::value_type Set_type; - typedef typename local::internal_sparsity::pattern_type Pattern_type; - Pattern_type s; - if( work.color.size() == 0 ) - { bool transpose = false; - const char* error_msg = "SparseJacobianReverse: sparsity" - " pattern does not have proper row or column dimension"; - sparsity_user2internal(s, p, m, n, transpose, error_msg); - } - n_sweep = SparseJacobianRev(x, s, row, col, jac, work); - return n_sweep; -} -/*! -Compute a sparse Jacobian. - -The C++ source code corresponding to this operation is -\verbatim - jac = SparseJacobian(x, p) -\endverbatim - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. - -\tparam VectorBase -is a simple vector class with elements of type \a Base. - -\tparam VectorSet -is a simple vector class with elements of type -\c bool or \c std::set. - -\param x [in] -is a vector specifing the point at which to compute the Jacobian. - -\param p [in] -is the sparsity pattern for the Jacobian that we are calculating. - -\return -Will be a vector if size \c m * n containing the Jacobian at the -specified point (in row major order). -*/ -template -template -VectorBase ADFun::SparseJacobian( - const VectorBase& x, const VectorSet& p -) -{ size_t i, j, k; - - size_t m = Range(); - size_t n = Domain(); - VectorBase jac(m * n); - - CPPAD_ASSERT_KNOWN( - size_t(x.size()) == n, - "SparseJacobian: size of x not equal domain size for f." - ); - CheckSimpleVector(); - - typedef typename VectorSet::value_type Set_type; - typedef typename local::internal_sparsity::pattern_type Pattern_type; - - // initialize the return value as zero - Base zero(0); - for(i = 0; i < m; i++) - for(j = 0; j < n; j++) - jac[i * n + j] = zero; - - sparse_jacobian_work work; - CppAD::vector row; - CppAD::vector col; - if( n <= m ) - { - // need an internal copy of sparsity pattern - Pattern_type s_transpose; - bool transpose = true; - const char* error_msg = "SparseJacobian: transposed sparsity" - " pattern does not have proper row or column dimension"; - sparsity_user2internal(s_transpose, p, n, m, transpose, error_msg); - - k = 0; - for(j = 0; j < n; j++) - { typename Pattern_type::const_iterator itr(s_transpose, j); - i = *itr; - while( i != s_transpose.end() ) - { row.push_back(i); - col.push_back(j); - k++; - i = *(++itr); - } - } - size_t K = k; - VectorBase J(K); - - // now we have folded this into the following case - SparseJacobianFor(x, s_transpose, row, col, J, work); - - // now set the non-zero return values - for(k = 0; k < K; k++) - jac[ row[k] * n + col[k] ] = J[k]; - } - else - { - // need an internal copy of sparsity pattern - Pattern_type s; - bool transpose = false; - const char* error_msg = "SparseJacobian: sparsity" - " pattern does not have proper row or column dimension"; - sparsity_user2internal(s, p, m, n, transpose, error_msg); - - k = 0; - for(i = 0; i < m; i++) - { typename Pattern_type::const_iterator itr(s, i); - j = *itr; - while( j != s.end() ) - { row.push_back(i); - col.push_back(j); - k++; - j = *(++itr); - } - } - size_t K = k; - VectorBase J(K); - - // now we have folded this into the following case - SparseJacobianRev(x, s, row, col, J, work); - - // now set the non-zero return values - for(k = 0; k < K; k++) - jac[ row[k] * n + col[k] ] = J[k]; - } - - return jac; -} - -/*! -Compute a sparse Jacobian. - -The C++ source code corresponding to this operation is -\verbatim - jac = SparseJacobian(x) -\endverbatim - -\tparam Base -is the base type for the recording that is stored in this -ADFun object. - -\tparam VectorBase -is a simple vector class with elements of the \a Base. - -\param x [in] -is a vector specifing the point at which to compute the Jacobian. - -\return -Will be a vector of size \c m * n containing the Jacobian at the -specified point (in row major order). -*/ -template -template -VectorBase ADFun::SparseJacobian( const VectorBase& x ) -{ typedef CppAD::vectorBool VectorBool; - - size_t m = Range(); - size_t n = Domain(); - - // sparsity pattern for Jacobian - VectorBool p(m * n); - - if( n <= m ) - { size_t j, k; - - // use forward mode - VectorBool r(n * n); - for(j = 0; j < n; j++) - { for(k = 0; k < n; k++) - r[j * n + k] = false; - r[j * n + j] = true; - } - p = ForSparseJac(n, r); - } - else - { size_t i, k; - - // use reverse mode - VectorBool s(m * m); - for(i = 0; i < m; i++) - { for(k = 0; k < m; k++) - s[i * m + k] = false; - s[i * m + i] = true; - } - p = RevSparseJac(m, s); - } - return SparseJacobian(x, p); -} - -} // END_CPPAD_NAMESPACE -# undef CPPAD_SPARSE_JACOBIAN_MAX_MULTIPLE_DIRECTION -# endif diff --git a/external/cppad/include/cppad/core/standard_math.hpp b/external/cppad/include/cppad/core/standard_math.hpp deleted file mode 100644 index 7efd7fdd6..000000000 --- a/external/cppad/include/cppad/core/standard_math.hpp +++ /dev/null @@ -1,132 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_STANDARD_MATH_HPP -# define CPPAD_CORE_STANDARD_MATH_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin unary_standard_math$$ -$spell - const - VecAD - fabs -$$ - -$section The Unary Standard Math Functions$$ - -$head Syntax$$ -$icode%y% = %fun%(%x%)%$$ - -$head Purpose$$ -Evaluates the standard math function $icode fun$$. - -$head Possible Types$$ - -$subhead Base$$ -If $icode Base$$ satisfies the -$cref/base type requirements/base_require/$$ -and argument $icode x$$ has prototype -$codei% - const %Base%& %x% -%$$ -then the result $icode y$$ has prototype -$codei% - %Base% %y% -%$$ - -$subhead AD$$ -If the argument $icode x$$ has prototype -$codei% - const AD<%Base%>& %x% -%$$ -then the result $icode y$$ has prototype -$codei% - AD<%Base%> %y% -%$$ - -$subhead VecAD$$ -If the argument $icode x$$ has prototype -$codei% - const VecAD<%Base%>::reference& %x% -%$$ -then the result $icode y$$ has prototype -$codei% - AD<%Base%> %y% -%$$ - -$children%cppad/core/std_math_98.hpp - %cppad/core/abs.hpp - %cppad/core/acosh.hpp - %cppad/core/asinh.hpp - %cppad/core/atanh.hpp - %cppad/core/erf.hpp - %cppad/core/expm1.hpp - %cppad/core/log1p.hpp - %cppad/core/sign.hpp -%$$ - -$head fun$$ -The possible values for $icode fun$$ are -$table -$icode fun$$ $pre $$ $cnext Description $rnext -$cref abs$$ $cnext $title abs$$ $rnext -$cref acos$$ $cnext $title acos$$ $rnext -$cref acosh$$ $cnext $title acosh$$ $rnext -$cref asin$$ $cnext $title asin$$ $rnext -$cref asinh$$ $cnext $title asinh$$ $rnext -$cref atan$$ $cnext $title atan$$ $rnext -$cref atanh$$ $cnext $title atanh$$ $rnext -$cref cos$$ $cnext $title cos$$ $rnext -$cref cosh$$ $cnext $title cosh$$ $rnext -$cref erf$$ $cnext $title erf$$ $rnext -$cref exp$$ $cnext $title exp$$ $rnext -$cref expm1$$ $cnext $title expm1$$ $rnext -$cref/fabs/abs/$$ $cnext $title abs$$ $rnext -$cref log10$$ $cnext $title log10$$ $rnext -$cref log1p$$ $cnext $title log1p$$ $rnext -$cref log$$ $cnext $title log$$ $rnext -$cref sign$$ $cnext $title sign$$ $rnext -$cref sin$$ $cnext $title sin$$ $rnext -$cref sinh$$ $cnext $title sinh$$ $rnext -$cref sqrt$$ $cnext $title sqrt$$ $rnext -$cref tan$$ $cnext $title tan$$ $rnext -$cref tanh$$ $cnext $title tanh$$ -$tend - -$end -*/ -# include -# include -# include -# include -# include -# include -# include -# include -# include - -/* -$begin binary_math$$ - -$section The Binary Math Functions$$ - -$childtable%cppad/core/atan2.hpp - %cppad/core/pow.hpp - %cppad/core/azmul.hpp -%$$ - -$end -*/ -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/std_math_98.hpp b/external/cppad/include/cppad/core/std_math_98.hpp deleted file mode 100644 index 1e6b42188..000000000 --- a/external/cppad/include/cppad/core/std_math_98.hpp +++ /dev/null @@ -1,600 +0,0 @@ -# ifndef CPPAD_CORE_STD_MATH_98_HPP -# define CPPAD_CORE_STD_MATH_98_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------------- -$begin acos$$ -$spell - acos -$$ - -$section Inverse Sine Function: acos$$ - -$head Syntax$$ -$icode%y% = acos(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{acos}^{(1)} (x) & = & - (1 - x * x)^{-1/2} -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/acos.cpp -%$$ -The file -$cref acos.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin asin$$ -$spell - asin -$$ - -$section Inverse Sine Function: asin$$ - -$head Syntax$$ -$icode%y% = asin(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{asin}^{(1)} (x) & = & (1 - x * x)^{-1/2} -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/asin.cpp -%$$ -The file -$cref asin.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin atan$$ -$spell - atan -$$ - -$section Inverse Tangent Function: atan$$ - -$head Syntax$$ -$icode%y% = atan(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{atan}^{(1)} (x) & = & \frac{1}{1 + x^2} -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/atan.cpp -%$$ -The file -$cref atan.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin cos$$ -$spell - cos -$$ - -$section The Cosine Function: cos$$ - -$head Syntax$$ -$icode%y% = cos(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{cos}^{(1)} (x) & = & - \sin(x) -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/cos.cpp -%$$ -The file -$cref cos.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin cosh$$ -$spell - cosh -$$ - -$section The Hyperbolic Cosine Function: cosh$$ - -$head Syntax$$ -$icode%y% = cosh(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{cosh}^{(1)} (x) & = & \sinh(x) -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/cosh.cpp -%$$ -The file -$cref cosh.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin exp$$ -$spell - exp -$$ - -$section The Exponential Function: exp$$ - -$head Syntax$$ -$icode%y% = exp(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{exp}^{(1)} (x) & = & \exp(x) -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/exp.cpp -%$$ -The file -$cref exp.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin log$$ -$spell -$$ - -$section The Exponential Function: log$$ - -$head Syntax$$ -$icode%y% = log(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{log}^{(1)} (x) & = & \frac{1}{x} -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/log.cpp -%$$ -The file -$cref log.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin log10$$ -$spell - CppAD -$$ - -$section The Base 10 Logarithm Function: log10$$ - -$head Syntax$$ -$icode%y% = log10(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Method$$ -CppAD uses the representation -$latex \[ -\begin{array}{lcr} - {\rm log10} (x) & = & \log(x) / \log(10) -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/log10.cpp -%$$ -The file -$cref log10.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin sin$$ -$spell - sin -$$ - -$section The Sine Function: sin$$ - -$head Syntax$$ -$icode%y% = sin(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{sin}^{(1)} (x) & = & \cos(x) -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/sin.cpp -%$$ -The file -$cref sin.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin sinh$$ -$spell - sinh -$$ - -$section The Hyperbolic Sine Function: sinh$$ - -$head Syntax$$ -$icode%y% = sinh(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{sinh}^{(1)} (x) & = & \cosh(x) -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/sinh.cpp -%$$ -The file -$cref sinh.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin sqrt$$ -$spell - sqrt -$$ - -$section The Square Root Function: sqrt$$ - -$head Syntax$$ -$icode%y% = sqrt(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{sqrt}^{(1)} (x) & = & \frac{1}{2 \R{sqrt} (x) } -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/sqrt.cpp -%$$ -The file -$cref sqrt.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin tan$$ -$spell - tan -$$ - -$section The Tangent Function: tan$$ - -$head Syntax$$ -$icode%y% = tan(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{tan}^{(1)} (x) & = & 1 + \tan (x)^2 -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/tan.cpp -%$$ -The file -$cref tan.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -$begin tanh$$ -$spell - tanh -$$ - -$section The Hyperbolic Tangent Function: tanh$$ - -$head Syntax$$ -$icode%y% = tanh(%x%)%$$ - -$head x, y$$ -See the $cref/possible types/unary_standard_math/Possible Types/$$ -for a unary standard math function. - -$head Atomic$$ -This is an $cref/atomic operation/glossary/Operation/Atomic/$$. - -$head Derivative$$ -$latex \[ -\begin{array}{lcr} - \R{tanh}^{(1)} (x) & = & 1 - \tanh (x)^2 -\end{array} -\] $$ - -$head Example$$ -$children% - example/general/tanh.cpp -%$$ -The file -$cref tanh.cpp$$ -contains an example and test of this function. -It returns true if it succeeds and false otherwise. - -$end -------------------------------------------------------------------------------- -*/ - -/*! -\file std_math_98.hpp -Define AD standard math functions (using their Base versions) -*/ - -/*! -\def CPPAD_STANDARD_MATH_UNARY_AD(Name, Op) -Defines function Name with argument type AD and tape operation Op - -The macro defines the function x.Name() where x has type AD. -It then uses this funciton to define Name(x) where x has type -AD or VecAD_reference. - -If x is a variable, the tape unary operator Op is used -to record the operation and the result is identified as correspoding -to this operation; i.e., Name(x).taddr_ idendifies the operation and -Name(x).tape_id_ identifies the tape. - -This macro is used to define AD versions of -acos, asin, atan, cos, cosh, exp, fabs, log, sin, sinh, sqrt, tan, tanh. -*/ - -# define CPPAD_STANDARD_MATH_UNARY_AD(Name, Op) \ - template \ - inline AD Name(const AD &x) \ - { return x.Name##_me(); } \ - template \ - inline AD AD::Name##_me (void) const \ - { \ - AD result; \ - result.value_ = CppAD::Name(value_); \ - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); \ - \ - if( Variable(*this) ) \ - { CPPAD_ASSERT_UNKNOWN( NumArg(Op) == 1 ); \ - local::ADTape *tape = tape_this(); \ - tape->Rec_.PutArg(taddr_); \ - result.taddr_ = tape->Rec_.PutOp(Op); \ - result.tape_id_ = tape->id_; \ - } \ - return result; \ - } \ - template \ - inline AD Name(const VecAD_reference &x) \ - { return x.ADBase().Name##_me(); } - -// BEGIN CppAD namespace -namespace CppAD { - - CPPAD_STANDARD_MATH_UNARY_AD(acos, local::AcosOp) - CPPAD_STANDARD_MATH_UNARY_AD(asin, local::AsinOp) - CPPAD_STANDARD_MATH_UNARY_AD(atan, local::AtanOp) - CPPAD_STANDARD_MATH_UNARY_AD(cos, local::CosOp) - CPPAD_STANDARD_MATH_UNARY_AD(cosh, local::CoshOp) - CPPAD_STANDARD_MATH_UNARY_AD(exp, local::ExpOp) - CPPAD_STANDARD_MATH_UNARY_AD(fabs, local::AbsOp) - CPPAD_STANDARD_MATH_UNARY_AD(log, local::LogOp) - CPPAD_STANDARD_MATH_UNARY_AD(sin, local::SinOp) - CPPAD_STANDARD_MATH_UNARY_AD(sinh, local::SinhOp) - CPPAD_STANDARD_MATH_UNARY_AD(sqrt, local::SqrtOp) - CPPAD_STANDARD_MATH_UNARY_AD(tan, local::TanOp) - CPPAD_STANDARD_MATH_UNARY_AD(tanh, local::TanhOp) - -# if CPPAD_USE_CPLUSPLUS_2011 - CPPAD_STANDARD_MATH_UNARY_AD(asinh, local::AsinhOp) - CPPAD_STANDARD_MATH_UNARY_AD(acosh, local::AcoshOp) - CPPAD_STANDARD_MATH_UNARY_AD(atanh, local::AtanhOp) - CPPAD_STANDARD_MATH_UNARY_AD(expm1, local::Expm1Op) - CPPAD_STANDARD_MATH_UNARY_AD(log1p, local::Log1pOp) -# endif - -# if CPPAD_USE_CPLUSPLUS_2011 - // Error function is a special case - template - inline AD erf(const AD &x) - { return x.erf_me(); } - template - inline AD AD::erf_me (void) const - { - AD result; - result.value_ = CppAD::erf(value_); - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - if( Variable(*this) ) - { CPPAD_ASSERT_UNKNOWN( local::NumArg(local::ErfOp) == 3 ); - local::ADTape *tape = tape_this(); - // arg[0] = argument to erf function - tape->Rec_.PutArg(taddr_); - // arg[1] = zero - addr_t p = tape->Rec_.PutPar( Base(0.0) ); - tape->Rec_.PutArg(p); - // arg[2] = 2 / sqrt(pi) - p = tape->Rec_.PutPar(Base( - 1.0 / std::sqrt( std::atan(1.0) ) - )); - tape->Rec_.PutArg(p); - // - result.taddr_ = tape->Rec_.PutOp(local::ErfOp); - result.tape_id_ = tape->id_; - } - return result; - } - template - inline AD erf(const VecAD_reference &x) - { return x.ADBase().erf_me(); } -# endif - - /*! - Compute the log of base 10 of x where has type AD - - \tparam Base - is the base type (different from base for log) - for this AD type, see base_require. - - \param x - is the argument for the log10 function. - - \result - if the result is y, then \f$ x = 10^y \f$. - */ - template - inline AD log10(const AD &x) - { return CppAD::log(x) / CppAD::log( Base(10) ); } - template - inline AD log10(const VecAD_reference &x) - { return CppAD::log(x.ADBase()) / CppAD::log( Base(10) ); } -} - -# undef CPPAD_STANDARD_MATH_UNARY_AD - -# endif diff --git a/external/cppad/include/cppad/core/sub.hpp b/external/cppad/include/cppad/core/sub.hpp deleted file mode 100644 index 0a0f8503c..000000000 --- a/external/cppad/include/cppad/core/sub.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_SUB_HPP -# define CPPAD_CORE_SUB_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD operator - (const AD &left , const AD &right) -{ - // compute the Base part - AD result; - result.value_ = left.value_ - right.value_; - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return result; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = left.tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // result = variable - variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SubvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SubvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(left.taddr_, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::SubvvOp); - // make result a variable - result.tape_id_ = tape_id; - } - else if( IdenticalZero(right.value_) ) - { // result = variable - 0 - result.make_variable(left.tape_id_, left.taddr_); - } - else - { // result = variable - parameter - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SubvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SubvpOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(left.taddr_, p); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::SubvpOp); - // make result a variable - result.tape_id_ = tape_id; - } - } - else if( var_right ) - { // result = parameter - variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SubpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SubpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left.value_); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - result.taddr_ = tape->Rec_.PutOp(local::SubpvOp); - // make result a variable - result.tape_id_ = tape_id; - } - return result; -} - -// convert other cases into the case above -CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR(-) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/sub_eq.hpp b/external/cppad/include/cppad/core/sub_eq.hpp deleted file mode 100644 index c9319aa77..000000000 --- a/external/cppad/include/cppad/core/sub_eq.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_SUB_EQ_HPP -# define CPPAD_CORE_SUB_EQ_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN CppAD namespace -namespace CppAD { - -template -AD& AD::operator -= (const AD &right) -{ - // compute the Base part - Base left; - left = value_; - value_ -= right.value_; - - // check if there is a recording in progress - local::ADTape* tape = AD::tape_ptr(); - if( tape == CPPAD_NULL ) - return *this; - tape_id_t tape_id = tape->id_; - - // tape_id cannot match the default value for tape_id_; i.e., 0 - CPPAD_ASSERT_UNKNOWN( tape_id > 0 ); - bool var_left = tape_id_ == tape_id; - bool var_right = right.tape_id_ == tape_id; - - if( var_left ) - { if( var_right ) - { // this = variable - variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SubvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SubvvOp) == 2 ); - - // put operand addresses in tape - tape->Rec_.PutArg(taddr_, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::SubvvOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - else if( IdenticalZero( right.value_ ) ) - { // this = variable - 0 - } - else - { // this = variable - parameter - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SubvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SubvpOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(right.value_); - tape->Rec_.PutArg(taddr_, p); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::SubvpOp); - // make this a variable - CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id ); - } - } - else if( var_right ) - { // this = parameter - variable - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::SubpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::SubpvOp) == 2 ); - - // put operand addresses in tape - addr_t p = tape->Rec_.PutPar(left); - tape->Rec_.PutArg(p, right.taddr_); - // put operator in the tape - taddr_ = tape->Rec_.PutOp(local::SubpvOp); - // make this a variable - tape_id_ = tape_id; - } - return *this; -} - -CPPAD_FOLD_ASSIGNMENT_OPERATOR(-=) - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/tape_link.hpp b/external/cppad/include/cppad/core/tape_link.hpp deleted file mode 100644 index 49f43009e..000000000 --- a/external/cppad/include/cppad/core/tape_link.hpp +++ /dev/null @@ -1,344 +0,0 @@ -# ifndef CPPAD_CORE_TAPE_LINK_HPP -# define CPPAD_CORE_TAPE_LINK_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file tape_link.hpp -Routines that Link AD and local::ADTape Objects. - -The routines that connect the AD class to the corresponding tapes -(one for each thread). -*/ - -/*! -Handle to the tape identifier for this AD class and the specific thread. - -\tparam Base -is the base type for this AD class. - -\param thread -is the thread number. The following condition must hold -\code -(! thread_alloc::in_parallel()) || thread == thread_alloc::thread_num() -\endcode - -\return -is a handle to the tape identifier for this thread -and AD class. -*/ -template -inline tape_id_t** AD::tape_id_handle(size_t thread) -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static tape_id_t* tape_id_table[CPPAD_MAX_NUM_THREADS]; - CPPAD_ASSERT_UNKNOWN( - (! thread_alloc::in_parallel()) || thread == thread_alloc::thread_num() - ); - - return tape_id_table + thread; -} - -/*! -Pointer to the tape identifier for this AD class and the specific thread. - -\tparam Base -is the base type for this AD class. - -\param thread -is the thread number; i.e., -\code -thread == thread_alloc::thread_num() -\endcode -If this condition is not satisfied, and \c NDEBUG is not defined, -a CPPAD_ASSERT_UNKNOWN is generated. - -\return -is a pointer to the tape identifier for this thread -and AD class. - -\par Restrictions -This routine should only be called if there was a tape created -for the specified thread (it may no longer be recording). -*/ -template -inline tape_id_t* AD::tape_id_ptr(size_t thread) -{ CPPAD_ASSERT_UNKNOWN( *tape_id_handle(thread) != CPPAD_NULL ) - return *tape_id_handle(thread); -} - -/*! -Handle for the tape for this AD class and the specific thread. - -\tparam Base -is the base type for this AD class. - - -\param thread -is the thread number; i.e., -\code -thread == thread_alloc::thread_num() -\endcode -If this condition is not satisfied, and \c NDEBUG is not defined, -a CPPAD_ASSERT_UNKNOWN is generated. - -\return -is a handle for the AD class and the specified thread. -*/ -template -inline local::ADTape** AD::tape_handle(size_t thread) -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static local::ADTape* tape_table[CPPAD_MAX_NUM_THREADS]; - CPPAD_ASSERT_UNKNOWN( thread == thread_alloc::thread_num() ); - - return tape_table + thread; -} - -/*! -Pointer for the tape for this AD class and the current thread. - -\code -thread == thread_alloc::thread_num() -\endcode - -\tparam Base -is the base type corresponding to AD operations. - -\return -is a pointer to the tape that is currently recording AD operations -for the current thread. -If this value is \c CPPAD_NULL, there is no tape currently -recording AD operations for this thread. -*/ -template -inline local::ADTape* AD::tape_ptr(void) -{ size_t thread = thread_alloc::thread_num(); - return *tape_handle(thread); -} - -/*! -Pointer for the tape for this AD class and the specified tape -identifier. - -\tparam Base -is the base type corresponding to AD operations. - -\param tape_id -is the identifier for the tape that is currently recording -AD operations for the current thread. -It must hold that the current thread is -\code - thread = size_t( tape_id % CPPAD_MAX_NUM_THREADS ) -\endcode -and that there is a tape recording AD operations -for this thread. -If this is not the currently executing thread, -a variable from a different thread is being recorded on the -tape for this thread which is a user error. - -\return -is a pointer to the tape that is currently recording AD operations -for the current thread (and it is not \c CPPAD_NULL). - -\par Restrictions -This routine should only be called if there is a tape recording operaitons -for the specified thread. -*/ -template -inline local::ADTape* AD::tape_ptr(tape_id_t tape_id) -{ size_t thread = size_t( tape_id % CPPAD_MAX_NUM_THREADS ); - CPPAD_ASSERT_KNOWN( - thread == thread_alloc::thread_num(), - "Attempt to use an AD variable with two different threads." - ); - CPPAD_ASSERT_UNKNOWN( tape_id == *tape_id_ptr(thread) ); - CPPAD_ASSERT_UNKNOWN( *tape_handle(thread) != CPPAD_NULL ); - return *tape_handle(thread); -} - -/*! -Create and delete tapes that record AD operations for current thread. - -\par thread -the current thread is given by -\code -thread = thread_alloc::thread_num() -\endcode - -\tparam Base -is the base type corresponding to AD operations. - -\param job -This argument determines if we are creating a new tape, or deleting an -old one. -- \c tape_manage_new : -Creates and a new tape. -It is assumed that there is no tape recording AD operations -for this thread when \c tape_manage is called. -It the input value of *tape_id_handle(thread) is \c CPPAD_NULL, -it will be changed to a non-zero pointer and the corresponding value -of *tape_id_ptr(thread) will be set to -thread + CPPAD_MAX_NUM_THREADS. -- \c tape_manage_delete : -It is assumed that there is a tape recording AD operations -for this thread when \c tape_manage is called. -The value of *tape_id_ptr(thread) will be advanced by -\c CPPAD_MAX_NUM_THREADS. - - -\return -- job == tape_manage_new: a pointer to the new tape is returned. -- job == tape_manage_delete: the value \c CPPAD_NULL is returned. -*/ -template -local::ADTape* AD::tape_manage(tape_manage_job job) -{ // this routine has static variables so first call cannot be in parallel - CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL - - // The tape for the master thread - static local::ADTape tape_zero; - - // Pointer to the tape for each thread - static local::ADTape* tape_table[CPPAD_MAX_NUM_THREADS]; - - // The id current being used for each of the tapes - static tape_id_t tape_id_save[CPPAD_MAX_NUM_THREADS]; - - // Thread corresponding to this call - size_t thread = thread_alloc::thread_num(); - - // tape_manage_clear - if( job == tape_manage_clear ) - { // This operation cannot be done in parallel - CPPAD_ASSERT_UNKNOWN(thread == 0 && (! thread_alloc::in_parallel())); - for(thread = 0; thread < CPPAD_MAX_NUM_THREADS; thread++) - { // if this thread has a tape - if( tape_table[thread] != CPPAD_NULL ) - { // id corresponding to this thread - tape_id_save[thread] = tape_table[thread]->id_; - *tape_id_handle(thread) = &tape_id_save[thread]; - - // delete all but the master thread - if( thread != 0 ) - delete( tape_table[thread] ); - - // set the tape pointer to null - tape_table[thread] = CPPAD_NULL; - } - } - return CPPAD_NULL; - } - - // id and tape fpor this thread - tape_id_t** tape_id = tape_id_handle(thread); - local::ADTape** tape = tape_handle(thread); - - // check if there is no tape currently attached to this thread - if( tape_table[thread] == CPPAD_NULL ) - { // allocate separate memroy to avoid false sharing - if( thread == 0 ) - { // mastert tape is a static in this routine - tape_table[thread] = &tape_zero; - } - else - { // other tapes are allocated - tape_table[thread] = new local::ADTape(); - } - // current id and pointer to this tape - tape_table[thread]->id_ = tape_id_save[thread]; - *tape_id = &tape_table[thread]->id_; - - // if id is zero, initialize it so that - // thread == tape id % CPPAD_MAX_NUM_THREADS - if( **tape_id == 0 ) - { size_t new_tape_id = thread + CPPAD_MAX_NUM_THREADS; - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= new_tape_id, - "cppad_tape_id_type maximum value has been execeeded" - ); - **tape_id = static_cast( new_tape_id ); - } - } - // make sure tape_id_handle(thread) is pointing to the proper place - CPPAD_ASSERT_UNKNOWN( *tape_id == &tape_table[thread]->id_ ); - - // make sure tape_id value is valid for this thread - CPPAD_ASSERT_UNKNOWN( - size_t( **tape_id % CPPAD_MAX_NUM_THREADS ) == thread - ); - - switch(job) - { case tape_manage_new: - // tape for this thread must be null at the start - CPPAD_ASSERT_UNKNOWN( *tape == CPPAD_NULL ); - *tape = tape_table[thread]; - break; - - case tape_manage_delete: - CPPAD_ASSERT_UNKNOWN( *tape == tape_table[thread] ); - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() - - CPPAD_MAX_NUM_THREADS > **tape_id, - "To many different tapes given the type used for " - "CPPAD_TAPE_ID_TYPE" - ); - // advance tape identfier so all AD variables become parameters - **tape_id += CPPAD_MAX_NUM_THREADS; - // free memory corresponding to recording in the old tape - tape_table[thread]->Rec_.free(); - // inform rest of CppAD that no tape recording for this thread - *tape = CPPAD_NULL; - break; - - case tape_manage_clear: - CPPAD_ASSERT_UNKNOWN(false); - } - return *tape; -} - -/*! -Get a pointer to tape that records AD operations for the current thread. - -\tparam Base -is the base type corresponding to AD operations. - -\par thread -The current thread must be given by -\code - thread = this->tape_id_ % CPPAD_MAX_NUM_THREADS -\endcode - -\return -is a pointer to the tape that is currently recording AD operations -for the current thread. -This value must not be \c CPPAD_NULL; i.e., there must be a tape currently -recording AD operations for this thread. -*/ - -template -inline local::ADTape *AD::tape_this(void) const -{ - size_t thread = size_t( tape_id_ % CPPAD_MAX_NUM_THREADS ); - CPPAD_ASSERT_UNKNOWN( tape_id_ == *tape_id_ptr(thread) ); - CPPAD_ASSERT_UNKNOWN( *tape_handle(thread) != CPPAD_NULL ); - return *tape_handle(thread); -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/core/test_vector.hpp b/external/cppad/include/cppad/core/test_vector.hpp deleted file mode 100644 index b95a3e6aa..000000000 --- a/external/cppad/include/cppad/core/test_vector.hpp +++ /dev/null @@ -1,136 +0,0 @@ -# ifndef CPPAD_CORE_TEST_VECTOR_HPP -# define CPPAD_CORE_TEST_VECTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin test_vector$$ -$spell - autotools - ifdef - undef - Microsofts - CppADvector - hpp - std - endif - ublas - Dir - valarray - stdvector -$$ - - -$section Choosing The Vector Testing Template Class$$ -$mindex CPPAD_TEST_VECTOR test$$ - -$head Deprecated 2012-07-03$$ -The $code CPPAD_TEST_VECTOR$$ macro has been deprecated, -use $cref/CPPAD_TESTVECTOR/testvector/$$ instead. - -$head Syntax$$ -$codei%CPPAD_TEST_VECTOR<%Scalar%> -%$$ - -$head Introduction$$ -Many of the CppAD $cref/examples/example/$$ and tests use -the $code CPPAD_TEST_VECTOR$$ template class to pass information. -The default definition for this template class is -$cref/CppAD::vector/CppAD_vector/$$. - -$head MS Windows$$ -The include path for boost is not defined in the Windows project files. -If we are using Microsofts compiler, the following code overrides the setting -of $code CPPAD_BOOSTVECTOR$$: -$srccode%cpp% */ -// The next 7 lines are C++ source code. -# ifdef _MSC_VER -# if CPPAD_BOOSTVECTOR -# undef CPPAD_BOOSTVECTOR -# define CPPAD_BOOSTVECTOR 0 -# undef CPPAD_CPPADVECTOR -# define CPPAD_CPPADVECTOR 1 -# endif -# endif -/* %$$ - -$head CppAD::vector$$ -By default $code CPPAD_CPPADVECTOR$$ is true -and $code CPPAD_TEST_VECTOR$$ is defined by the following source code -$srccode%cpp% */ -// The next 3 line are C++ source code. -# if CPPAD_CPPADVECTOR -# define CPPAD_TEST_VECTOR CppAD::vector -# endif -/* %$$ -If you specify $code --with-eigenvector$$ on the -$cref/configure/autotools/Configure/$$ command line, -$code CPPAD_EIGENVECTOR$$ is true. -This vector type cannot be supported by $code CPPAD_TEST_VECTOR$$ -(use $cref/CPPAD_TESTVECTOR/testvector/$$ for this support) -so $code CppAD::vector$$ is used in this case -$srccode%cpp% */ -// The next 3 line are C++ source code. -# if CPPAD_EIGENVECTOR -# define CPPAD_TEST_VECTOR CppAD::vector -# endif -/* %$$ - - -$head std::vector$$ -If you specify $code --with-stdvector$$ on the -$cref/configure/autotools/Configure/$$ -command line during CppAD installation, -$code CPPAD_STDVECTOR$$ is true -and $code CPPAD_TEST_VECTOR$$ is defined by the following source code -$srccode%cpp% */ -// The next 4 lines are C++ source code. -# if CPPAD_STDVECTOR -# include -# define CPPAD_TEST_VECTOR std::vector -# endif -/* %$$ -In this case CppAD will use $code std::vector$$ for its examples and tests. -Use of $code CppAD::vector$$, $code std::vector$$, -and $code std::valarray$$ with CppAD is always tested to some degree. -Specifying $code --with-stdvector$$ will increase the amount of -$code std::vector$$ testing. - -$head boost::numeric::ublas::vector$$ -If you specify a value for $icode boost_dir$$ on the configure -command line during CppAD installation, -$code CPPAD_BOOSTVECTOR$$ is true -and $code CPPAD_TEST_VECTOR$$ is defined by the following source code -$srccode%cpp% */ -// The next 4 lines are C++ source code. -# if CPPAD_BOOSTVECTOR -# include -# define CPPAD_TEST_VECTOR boost::numeric::ublas::vector -# endif -/* %$$ -In this case CppAD will use Ublas vectors for its examples and tests. -Use of $code CppAD::vector$$, $code std::vector$$, -and $code std::valarray$$ with CppAD is always tested to some degree. -Specifying $icode boost_dir$$ will increase the amount of -Ublas vector testing. - -$head CppADvector Deprecated 2007-07-28$$ -The preprocessor symbol $code CppADvector$$ is defined to -have the same value as $code CPPAD_TEST_VECTOR$$ but its use is deprecated: -$srccode%cpp% */ -# define CppADvector CPPAD_TEST_VECTOR -/* %$$ -$end ------------------------------------------------------------------------- -*/ - -# endif diff --git a/external/cppad/include/cppad/core/testvector.hpp b/external/cppad/include/cppad/core/testvector.hpp deleted file mode 100644 index 5e7348adc..000000000 --- a/external/cppad/include/cppad/core/testvector.hpp +++ /dev/null @@ -1,128 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_TESTVECTOR_HPP -# define CPPAD_CORE_TESTVECTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin testvector$$ -$spell - CppAD - cmake - testvector - cppad - Eigen - ifdef - hpp - std - endif - ublas -$$ - - -$section Using The CppAD Test Vector Template Class$$ -$mindex CPPAD_TESTVECTOR$$ - -$head Syntax$$ -$codei%CPPAD_TESTVECTOR(%Scalar%) -%$$ - -$head Purpose$$ -Many of the CppAD $cref/examples/example/$$ and tests use -the $code CPPAD_TESTVECTOR$$ template class to pass information to CppAD. -This is not a true template class because it's syntax uses -$codei%(%Scalar%)%$$ instead of $codei%<%Scalar%>%$$. -This enables us to use -$codei% - Eigen::Matrix<%Scalar%, Eigen::Dynamic, 1> -%$$ -as one of the possible cases for this 'template class'. - -$head Choice$$ -The user can choose, during the install procedure, -which template class to use in the examples and tests; see below. -This shows that any -$cref/simple vector/SimpleVector/$$ class can be used in place of -$codei% - CPPAD_TESTVECTOR(%Type%) -%$$ -When writing their own code, -users can choose a specific simple vector they prefer; for example, -$codei% - CppAD::vector<%Type%> -%$$ - - -$head CppAD::vector$$ -If in the $cref/cmake command/cmake/CMake Command/$$ -you specify $cref cppad_testvector$$ to be $code cppad$$, -$code CPPAD_CPPADVECTOR$$ will be true. -In this case, -$code CPPAD_TESTVECTOR$$ is defined by the following source code: -$srccode%cpp% */ -# if CPPAD_CPPADVECTOR -# define CPPAD_TESTVECTOR(Scalar) CppAD::vector< Scalar > -# endif -/* %$$ -In this case CppAD will use its own vector for -many of its examples and tests. - -$head std::vector$$ -If in the cmake command -you specify $icode cppad_testvector$$ to be $code std$$, -$code CPPAD_STDVECTOR$$ will be true. -In this case, -$code CPPAD_TESTVECTOR$$ is defined by the following source code: -$srccode%cpp% */ -# if CPPAD_STDVECTOR -# include -# define CPPAD_TESTVECTOR(Scalar) std::vector< Scalar > -# endif -/* %$$ -In this case CppAD will use standard vector for -many of its examples and tests. - -$head boost::numeric::ublas::vector$$ -If in the cmake command -you specify $icode cppad_testvector$$ to be $code boost$$, -$code CPPAD_BOOSTVECTOR$$ will be true. -In this case, -$code CPPAD_TESTVECTOR$$ is defined by the following source code: -$srccode%cpp% */ -# if CPPAD_BOOSTVECTOR -# include -# define CPPAD_TESTVECTOR(Scalar) boost::numeric::ublas::vector< Scalar > -# endif -/* %$$ -In this case CppAD will use this boost vector for -many of its examples and tests. - -$head Eigen Vectors$$ -If in the cmake command -you specify $icode cppad_testvector$$ to be $code eigen$$, -$code CPPAD_EIGENVECTOR$$ will be true. -In this case, -$code CPPAD_TESTVECTOR$$ is defined by the following source code: -$srccode%cpp% */ -# if CPPAD_EIGENVECTOR -# include -# define CPPAD_TESTVECTOR(Scalar) Eigen::Matrix< Scalar , Eigen::Dynamic, 1> -# endif -/* %$$ -In this case CppAD will use the Eigen vector -for many of its examples and tests. - -$end ------------------------------------------------------------------------- -*/ - -# endif diff --git a/external/cppad/include/cppad/core/unary_minus.hpp b/external/cppad/include/cppad/core/unary_minus.hpp deleted file mode 100644 index eeef16c29..000000000 --- a/external/cppad/include/cppad/core/unary_minus.hpp +++ /dev/null @@ -1,103 +0,0 @@ -# ifndef CPPAD_CORE_UNARY_MINUS_HPP -# define CPPAD_CORE_UNARY_MINUS_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin UnaryMinus$$ -$spell - Vec - const - inline -$$ - - -$section AD Unary Minus Operator$$ -$mindex -$$ - -$head Syntax$$ - -$icode%y% = - %x%$$ - - -$head Purpose$$ -Computes the negative of $icode x$$. - -$head Base$$ -The operation in the syntax above must be supported for the case where -the operand is a $code const$$ $icode Base$$ object. - -$head x$$ -The operand $icode x$$ has one of the following prototypes -$codei% - const AD<%Base%> &%x% - const VecAD<%Base%>::reference &%x% -%$$ - -$head y$$ -The result $icode y$$ has type -$codei% - AD<%Base%> %y% -%$$ -It is equal to the negative of the operand $icode x$$. - -$head Operation Sequence$$ -This is an AD of $icode Base$$ -$cref/atomic operation/glossary/Operation/Atomic/$$ -and hence is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Derivative$$ -If $latex f$$ is a -$cref/Base function/glossary/Base Function/$$, -$latex \[ - \D{[ - f(x) ]}{x} = - \D{f(x)}{x} -\] $$ - -$head Example$$ -$children% - example/general/unary_minus.cpp -%$$ -The file -$cref unary_minus.cpp$$ -contains an example and test of this operation. - -$end -------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -// Broken g++ compiler inhibits declaring unary minus a member or friend -template -inline AD AD::operator - (void) const -{ // should make a more efficient version by adding unary minus to - // Operator.h (some day) - AD result(0); - - result -= *this; - - return result; -} - - -template -inline AD operator - (const VecAD_reference &right) -{ return - right.ADBase(); } - -} -// END CppAD namespace - - -# endif diff --git a/external/cppad/include/cppad/core/unary_plus.hpp b/external/cppad/include/cppad/core/unary_plus.hpp deleted file mode 100644 index 0c80dea29..000000000 --- a/external/cppad/include/cppad/core/unary_plus.hpp +++ /dev/null @@ -1,98 +0,0 @@ -# ifndef CPPAD_CORE_UNARY_PLUS_HPP -# define CPPAD_CORE_UNARY_PLUS_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin UnaryPlus$$ -$spell - Vec - const - inline -$$ - - -$section AD Unary Plus Operator$$ -$mindex +$$ - -$head Syntax$$ - -$icode%y% = + %x%$$ - - -$head Purpose$$ -Performs the unary plus operation -(the result $icode y$$ is equal to the operand $icode x$$). - - -$head x$$ -The operand $icode x$$ has one of the following prototypes -$codei% - const AD<%Base%> &%x% - const VecAD<%Base%>::reference &%x% -%$$ - -$head y$$ -The result $icode y$$ has type -$codei% - AD<%Base%> %y% -%$$ -It is equal to the operand $icode x$$. - -$head Operation Sequence$$ -This is an AD of $icode Base$$ -$cref/atomic operation/glossary/Operation/Atomic/$$ -and hence is part of the current -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Derivative$$ -If $latex f$$ is a -$cref/Base function/glossary/Base Function/$$, -$latex \[ - \D{[ + f(x) ]}{x} = \D{f(x)}{x} -\] $$ - - - -$head Example$$ -$children% - example/general/unary_plus.cpp -%$$ -The file -$cref unary_plus.cpp$$ -contains an example and test of this operation. - -$end -------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -inline AD AD::operator + (void) const -{ AD result(*this); - - return result; -} - - -template -inline AD operator + (const VecAD_reference &right) -{ return right.ADBase(); } - -} -// END CppAD namespace - - -# endif diff --git a/external/cppad/include/cppad/core/undef.hpp b/external/cppad/include/cppad/core/undef.hpp deleted file mode 100644 index 3e0a2d29e..000000000 --- a/external/cppad/include/cppad/core/undef.hpp +++ /dev/null @@ -1,97 +0,0 @@ -# ifndef CPPAD_CORE_UNDEF_HPP -# define CPPAD_CORE_UNDEF_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ----------------------------------------------------------------------------- -Preprecessor definitions that presist after cppad/cppad.hpp is included: - -# undef CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL used by CPPAD_USER_ATOMIC -# undef CPPAD_ASSERT_KNOWN used by cppad_ipopt -# undef CPPAD_ASSERT_UNKNOWN used by cppad_ipopt -# undef CPPAD_HASH_TABLE_SIZE used by test_more/optimize.cpp -# undef EIGEN_MATRIXBASE_PLUGIN example use of Eigen with CppAD -# undef CPPAD_HAS_COLPACK used by speed/cppad/sparse_*.cpp - -# undef CPPAD_BOOL_BINARY in user api -# undef CPPAD_BOOL_UNARY in user api -# undef CPPAD_DEBUG_AND_RELEASE in user api -# undef CPPAD_DISCRETE_FUNCTION in user api -# undef CPPAD_EIGENVECTOR in user api -# undef CPPAD_MAX_NUM_THREADS in user api -# undef CPPAD_NUMERIC_LIMITS in user api -# undef CPPAD_NULL in user api -# undef CPPAD_PACKAGE_STRING in user api -# undef CPPAD_STANDARD_MATH_UNARY in user api -# undef CPPAD_TAPE_ADDR_TYPE in user api -# undef CPPAD_TAPE_ID_TYPE in user api -# undef CPPAD_TESTVECTOR in user api -# undef CPPAD_TO_STRING in user api -# undef CPPAD_USE_CPLUSPLUS_2011 in user api - -# undef CPPAD_TRACK_COUNT in deprecated api -# undef CPPAD_TRACK_DEL_VEC in deprecated api -# undef CPPAD_TRACK_EXTEND in deprecated api -# undef CPPAD_TRACK_NEW_VEC in deprecated api -# undef CPPAD_USER_ATOMIC in deprecated api - -# undef CPPAD_TEST_VECTOR deprecated verssion of CPPAD_TESTVECTOR -# undef CppADCreateBinaryBool deprecated version of CPPAD_BOOL_BINARY -# undef CppADCreateDiscrete deprecated version of CPPAD_DISCRETE_FUNCTION -# undef CppADCreateUnaryBool deprecated version of CPPAD_BOOL_UNARY -# undef CppADTrackCount deprecated version of CPPAD_TRACK_COUNT -# undef CppADTrackDelVec deprecated version of CPPAD_TRACK_DEL_VEC -# undef CppADTrackExtend deprecated version of CPPAD_TRACK_EXTEND -# undef CppADTrackNewVec deprecated version of CPPAD_TRACK_NEW_VEC -# undef CppADvector deprecated version of CPPAD_TEST_VECTOR - -// for conditional testing when implicit conversion is not present -# undef CPPAD_DEPRECATED ------------------------------------------------------------------------------ -*/ -// Preprecessor definitions that do not presist -# undef CPPAD_ASSERT_NARG_NRES -# undef CPPAD_ASSERT_ARG_BEFORE_RESULT -# undef CPPAD_AZMUL -# undef CPPAD_BOOSTVECTOR -# undef CPPAD_COND_EXP -# undef CPPAD_COND_EXP_BASE_REL -# undef CPPAD_COND_EXP_REL -# undef CPPAD_CPPADVECTOR -# undef CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR -# undef CPPAD_FOLD_ASSIGNMENT_OPERATOR -# undef CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR -# undef CPPAD_FOR_JAC_SWEEP_TRACE -# undef CPPAD_HAS_GETTIMEOFDAY -# undef CPPAD_HAS_MKSTEMP -# undef CPPAD_HAS_TMPNAM_S -# undef CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -# undef CPPAD_LIB_EXPORT -# undef CPPAD_MAX_NUM_CAPACITY -# undef CPPAD_MIN_DOUBLE_CAPACITY -# undef CPPAD_OP_CODE_TYPE -# undef CPPAD_REVERSE_SWEEP_TRACE -# undef CPPAD_REV_HES_SWEEP_TRACE -# undef CPPAD_REV_JAC_SWEEP_TRACE -# undef CPPAD_SIZE_T_NOT_UNSIGNED_INT -# undef CPPAD_STANDARD_MATH_UNARY_AD -# undef CPPAD_STDVECTOR -# undef CPPAD_TRACE_CAPACITY -# undef CPPAD_TRACE_THREAD -# undef CPPAD_TRACK_DEBUG -# undef CPPAD_USER_MACRO -# undef CPPAD_USER_MACRO_ONE -# undef CPPAD_USER_MACRO_TWO -# undef CPPAD_VEC_AD_COMPUTED_ASSIGNMENT - -# endif diff --git a/external/cppad/include/cppad/core/user_ad.hpp b/external/cppad/include/cppad/core/user_ad.hpp deleted file mode 100644 index d4306bcfb..000000000 --- a/external/cppad/include/cppad/core/user_ad.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// $Id$ -# ifndef CPPAD_CORE_USER_AD_HPP -# define CPPAD_CORE_USER_AD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* ---------------------------------------------------------------------------- - -$begin AD$$ -$spell - std - bool - cos - Cpp -$$ - -$section AD Objects$$ -$mindex require$$ - - -$head Purpose$$ -The sections listed below describe the operations -that are available to $cref/AD of Base/glossary/AD of Base/$$ objects. -These objects are used to $cref/tape/glossary/Tape/$$ -an AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. -This operation sequence can -be transferred to an $cref ADFun$$ object where it -can be used to evaluate the corresponding -function and derivative values. - -$head Base Type Requirements$$ -The $icode Base$$ requirements are provided by the CppAD package -for the following base types: -$code float$$, -$code double$$, -$code std::complex$$, -$code std::complex$$. -Otherwise, see $cref base_require$$. - - -$childtable% - cppad/core/ad_ctor.hpp% - cppad/core/ad_assign.hpp% - cppad/core/convert.hpp% - cppad/core/ad_valued.hpp% - cppad/core/bool_valued.hpp% - cppad/core/vec_ad.hpp% - cppad/base_require.hpp -%$$ - -$end ---------------------------------------------------------------------------- -*/ - -# include -# include -# include -# include -# include -# include -# include - -# endif diff --git a/external/cppad/include/cppad/core/value.hpp b/external/cppad/include/cppad/core/value.hpp deleted file mode 100644 index 4ff3064e9..000000000 --- a/external/cppad/include/cppad/core/value.hpp +++ /dev/null @@ -1,100 +0,0 @@ -# ifndef CPPAD_CORE_VALUE_HPP -# define CPPAD_CORE_VALUE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Value$$ -$spell - const -$$ - - - -$section Convert From an AD Type to its Base Type$$ -$mindex Value$$ - -$head Syntax$$ -$icode%b% = Value(%x%)%$$ - -$head See Also$$ -$cref var2par$$ - - -$head Purpose$$ -Converts from an AD type to the corresponding -$cref/base type/glossary/Base Type/$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &%x% -%$$ - -$head b$$ -The return value $icode b$$ has prototype -$codei% - %Base% %b% -%$$ - -$head Operation Sequence$$ -The result of this operation is not an -$cref/AD of Base/glossary/AD of Base/$$ object. -Thus it will not be recorded as part of an -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$. - -$head Restriction$$ -If the argument $icode x$$ is a -$cref/variable/glossary/Variable/$$ its dependency information -would not be included in the $code Value$$ result (see above). -For this reason, -the argument $icode x$$ must be a $cref/parameter/glossary/Parameter/$$; i.e., -it cannot depend on the current -$cref/independent variables/glossary/Tape/Independent Variable/$$. - -$head Example$$ -$children% - example/general/value.cpp -%$$ -The file -$cref value.cpp$$ -contains an example and test of this operation. - -$end -------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -Base Value(const AD &x) -{ Base result; - - CPPAD_ASSERT_KNOWN( - Parameter(x) , - "Value: argument is a variable (not a parameter)" - ); - - - result = x.value_; - - return result; -} - -} -// END CppAD namespace - - -# endif diff --git a/external/cppad/include/cppad/core/var2par.hpp b/external/cppad/include/cppad/core/var2par.hpp deleted file mode 100644 index 9740198cb..000000000 --- a/external/cppad/include/cppad/core/var2par.hpp +++ /dev/null @@ -1,91 +0,0 @@ -# ifndef CPPAD_CORE_VAR2PAR_HPP -# define CPPAD_CORE_VAR2PAR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* ------------------------------------------------------------------------------- - -$begin Var2Par$$ -$spell - var - const -$$ - - -$section Convert an AD Variable to a Parameter$$ -$mindex Var2Par from value_ obtain during taping$$ - -$head Syntax$$ -$icode%y% = Var2Par(%x%)%$$ - -$head See Also$$ -$cref value$$ - - -$head Purpose$$ -Returns a -$cref/parameter/glossary/Parameter/$$ $icode y$$ -with the same value as the -$cref/variable/glossary/Variable/$$ $icode x$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &x -%$$ -The argument $icode x$$ may be a variable or parameter. - - -$head y$$ -The result $icode y$$ has prototype -$codei% - AD<%Base%> &y -%$$ -The return value $icode y$$ will be a parameter. - - -$head Example$$ -$children% - example/general/var2par.cpp -%$$ -The file -$cref var2par.cpp$$ -contains an example and test of this operation. -It returns true if it succeeds and false otherwise. - -$end ------------------------------------------------------------------------------- -*/ - -// BEGIN CppAD namespace -namespace CppAD { - -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -AD Var2Par(const AD &x) -{ AD y(x.value_); - return y; -} - - -template -CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION -AD Var2Par(const VecAD_reference &x) -{ AD y(x.ADBase()); - y.id_ = 0; -} - - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/core/vec_ad.hpp b/external/cppad/include/cppad/core/vec_ad.hpp deleted file mode 100644 index 8d4b6c657..000000000 --- a/external/cppad/include/cppad/core/vec_ad.hpp +++ /dev/null @@ -1,743 +0,0 @@ -# ifndef CPPAD_CORE_VEC_AD_HPP -# define CPPAD_CORE_VEC_AD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin VecAD$$ -$spell - cppad.hpp - CondExpGt - grep - Ld - vp - Lu - wc - op - Ldp - Ldv - Taylor - VecAD - const - Cpp -$$ - - -$section AD Vectors that Record Index Operations$$ -$mindex VecAD tape reference VecAD$$ - - -$head Syntax$$ -$codei%VecAD<%Base%> %v%(%n%)%$$ -$pre -$$ -$icode%v%.size()%$$ -$pre -$$ -$icode%b% = %v%[%i%]%$$ -$pre -$$ -$icode%r% = %v%[%x%]%$$ - -$head Purpose$$ -If either $icode v$$ or $icode x$$ is a -$cref/variable/glossary/Variable/$$, -the indexing operation -$codei% - %r% = %v%[%x%] -%$$ -is recorded in the corresponding -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$ and -transferred to the corresponding $cref ADFun$$ object $icode f$$. -Such an index can change each time -zero order $cref/f.Forward/Forward/$$ is used; i.e., -$icode f$$ is evaluated with new value for the -$cref/independent variables/glossary/Tape/Independent Variable/$$. -Note that the value of $icode y$$ depends on the value of $icode x$$ -in a discrete fashion and CppAD computes its partial derivative with -respect to $icode x$$ as zero. - -$head Alternatives$$ -If only the values in the vector, -and not the indices, -depend on the independent variables, -the class $icode%Vector%< AD<%Base%> >%$$ is much more efficient for -storing AD values where $icode Vector$$ is any -$cref SimpleVector$$ template class, -If only the indices, -and not the values in the vector, -depend on the independent variables, -The $cref Discrete$$ functions are a much more efficient -way to represent these vectors. - -$head VecAD::reference$$ -The result $icode r$$ has type -$codei% - VecAD<%Base%>::reference -%$$ -which is very much like the $codei%AD<%Base%>%$$ type -with some notable exceptions: - -$subhead Exceptions$$ -$list number$$ -The object $icode r$$ cannot be used with the -$cref Value$$ function to compute the corresponding $icode Base$$ value. -If $icode v$$ and $icode i$$ are not $cref/variables/glossary/Variable/$$ -$codei% - %b% = v[%i%] -%$$ -can be used to compute the corresponding $icode Base$$ value. - -$lnext -The object $icode r$$ cannot be used -with the $cref/compound assignments operators/Arithmetic/$$ -$code +=$$, -$code -=$$, -$code *=$$, or -$code /=$$. -For example, the following syntax is not valid: -$codei% - %v%[%x%] += %z%; -%$$ -no matter what the types of $icode z$$. - -$lnext -Assignment to $icode r$$ returns a $code void$$. -For example, the following syntax is not valid: -$codei% - %z% = %v%[%x%] = %u%; -%$$ -no matter what the types of $icode z$$, and $icode u$$. - -$lnext -The $cref CondExp$$ functions do not accept -$codei%VecAD<%Base%>::reference%$$ arguments. -For example, the following syntax is not valid: -$codei% - CondExpGt(%v%[%x%], %z%, %u%, %v%) -%$$ -no matter what the types of $icode z$$, $icode u$$, and $icode v$$. - -$lnext -The $cref/Parameter and Variable/ParVar/$$ functions cannot be used with -$codei%VecAD<%Base%>::reference%$$ arguments like $icode r$$, -use the entire $codei%VecAD<%Base%>%$$ vector instead; i.e. $icode v$$. - -$lnext -The vectors passed to $cref Independent$$ must have elements -of type $codei%AD<%Base%>%$$; i.e., $cref VecAD$$ vectors -cannot be passed to $code Independent$$. - -$lnext -If one uses this type in a -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$, -$cref/sparsity pattern/glossary/Sparsity Pattern/$$ calculations -($cref sparsity_pattern$$) -are less efficient because the dependence of different -elements of the vector cannot be separated. - -$lend - -$head Constructor$$ - -$subhead v$$ -The syntax -$codei% - VecAD<%Base%> %v%(%n%) -%$$ -creates an $code VecAD$$ object $icode v$$ with -$icode n$$ elements. -The initial value of the elements of $icode v$$ is unspecified. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ - -$head size$$ -The syntax -$codei% - %v%.size() -%$$ -returns the number of elements in the vector $icode v$$; -i.e., the value of $icode n$$ when it was constructed. - -$head size_t Indexing$$ -We refer to the syntax -$codei% - %b% = %v%[%i%] -%$$ -as $code size_t$$ indexing of a $code VecAD$$ object. -This indexing is only valid if the vector $icode v$$ is a -$cref/parameter/ParVar/$$; i.e., -it does not depend on the independent variables. - -$subhead i$$ -The operand $icode i$$ has prototype -$codei% - size_t %i% -%$$ -It must be greater than or equal zero -and less than $icode n$$; i.e., less than -the number of elements in $icode v$$. - -$subhead b$$ -The result $icode b$$ has prototype -$codei% - %Base% %b% -%$$ -and is a reference to the $th i$$ element in the vector $icode v$$. -It can be used to change the element value; -for example, -$codei% - %v%[%i%] = %c% -%$$ -is valid where $icode c$$ is a $icode Base$$ object. -The reference $icode b$$ is no longer valid once the -destructor for $icode v$$ is called; for example, -when $icode v$$ falls out of scope. - -$head AD Indexing$$ -We refer to the syntax -$codei% - %r% = %v%[%x%] -%$$ -as AD indexing of a $code VecAD$$ object. - -$subhead x$$ -The argument $icode x$$ has prototype -$codei% - const AD<%Base%> &%x% -%$$ -The value of $icode x$$ must be greater than or equal zero -and less than $icode n$$; i.e., less than -the number of elements in $icode v$$. - -$subhead r$$ -The result $icode r$$ has prototype -$codei% - VecAD<%Base%>::reference %r% -%$$ -The object $icode r$$ has an AD type and its -operations are recorded as part of the same -AD of $icode Base$$ -$cref/operation sequence/glossary/Operation/Sequence/$$ as -for $codei%AD<%Base%>%$$ objects. -It acts as a reference to the -element with index $latex {\rm floor} (x)$$ in the vector $icode v$$ -($latex {\rm floor} (x)$$ is -the greatest integer less than or equal $icode x$$). -Because it is a reference, it can be used to change the element value; -for example, -$codei% - %v%[%x%] = %z% -%$$ -is valid where $icode z$$ is an -$codei%VecAD<%Base%>::reference%$$ object. -As a reference, $icode r$$ is no longer valid once the -destructor for $icode v$$ is called; for example, -when $icode v$$ falls out of scope. - -$head Example$$ -$children% - example/general/vec_ad.cpp -%$$ -The file -$cref vec_ad.cpp$$ -contains an example and test using $code VecAD$$ vectors. -It returns true if it succeeds and false otherwise. - - -$head Speed and Memory$$ -The $cref VecAD$$ vector type is inefficient because every -time an element of a vector is accessed, a new CppAD -$cref/variable/glossary/Variable/$$ is created on the tape -using either the $code Ldp$$ or $code Ldv$$ operation -(unless all of the elements of the vector are -$cref/parameters/glossary/Parameter/$$). -The effect of this can be seen by executing the following steps: - -$list number$$ -In the file $code cppad/local/forward1sweep.h$$, -change the definition of $code CPPAD_FORWARD1SWEEP_TRACE$$ to -$codep - # define CPPAD_FORWARD1SWEEP_TRACE 1 -$$ -$lnext -In the $code Example$$ directory, execute the command -$codep - ./test_one.sh lu_vec_ad_ok.cpp lu_vec_ad.cpp -DNDEBUG > lu_vec_ad_ok.log -$$ -This will write a trace of all the forward tape operations, -for the test case $cref lu_vec_ad_ok.cpp$$, -to the file $code lu_vec_ad_ok.log$$. -$lnext -In the $code Example$$ directory execute the commands -$codep - grep "op=" lu_vec_ad_ok.log | wc -l - grep "op=Ld[vp]" lu_vec_ad_ok.log | wc -l - grep "op=St[vp][vp]" lu_vec_ad_ok.log | wc -l -$$ -The first command counts the number of operators in the tracing, -the second counts the number of VecAD load operations, -and the third counts the number of VecAD store operations. -(For CppAD version 05-11-20 these counts were 956, 348, and 118 -respectively.) -$lend - -$end ------------------------------------------------------------------------- -*/ -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file vec_ad.hpp -Defines the VecAD class. -*/ - -/*! -\def CPPAD_VEC_AD_COMPUTED_ASSIGNMENT(op, name) -Prints an error message if the correspinding compound assignment is used. - -THis macro is used to print an error message if any of the -compound assignments are used with the VecAD_reference class. -The argument \c op is one of the following: -+= , -= , *= , /=. -The argument \c name, is a string literal with the name of the -compound assignment \c op. -*/ -# define CPPAD_VEC_AD_COMPUTED_ASSIGNMENT(op, name) \ -VecAD_reference& operator op (const VecAD_reference &right) \ -{ CPPAD_ASSERT_KNOWN( \ - false, \ - "Cannot use a ADVec element on left side of" name \ - ); \ - return *this; \ -} \ -VecAD_reference& operator op (const AD &right) \ -{ CPPAD_ASSERT_KNOWN( \ - false, \ - "Cannot use a ADVec element on left side of" name \ - ); \ - return *this; \ -} \ -VecAD_reference& operator op (const Base &right) \ -{ CPPAD_ASSERT_KNOWN( \ - false, \ - "Cannot use a ADVec element on left side of" name \ - ); \ - return *this; \ -} - -/*! -Class used to hold a reference to an element of a VecAD object. - -\tparam Base -Elements of this class act like an AD (in a restricted sense), -in addition they track (on the tape) the index they correspond to. -*/ -template -class VecAD_reference { - friend bool Parameter (const VecAD &vec); - friend bool Variable (const VecAD &vec); - friend class VecAD; - friend class local::ADTape; - -private: - /// pointer to vecad vector that this is a element of - VecAD *vec_; - /// index in vecad vector that this element corresponds to - AD ind_; // index for this element -public: - /*! - consructor - - \param vec - value of vec_ - - \param ind - value of ind_ - */ - VecAD_reference(VecAD *vec, const AD& ind) - : vec_( vec ) , ind_(ind) - { } - - // assignment operators - inline void operator = (const VecAD_reference &right); - void operator = (const AD &right); - void operator = (const Base &right); - void operator = (int right); - - // compound assignments - CPPAD_VEC_AD_COMPUTED_ASSIGNMENT( += , " += " ) - CPPAD_VEC_AD_COMPUTED_ASSIGNMENT( -= , " -= " ) - CPPAD_VEC_AD_COMPUTED_ASSIGNMENT( *= , " *= " ) - CPPAD_VEC_AD_COMPUTED_ASSIGNMENT( /= , " /= " ) - - - /// Conversion from VecAD_reference to AD. - /// puts the correspond vecad load instruction in the tape. - AD ADBase(void) const - { AD result; - - size_t i = static_cast( Integer(ind_) ); - CPPAD_ASSERT_UNKNOWN( i < vec_->length_ ); - - // AD value corresponding to this element - result.value_ = vec_->data_[i]; - - // this address will be recorded in tape and must be - // zero for parameters - CPPAD_ASSERT_UNKNOWN( Parameter(result) ); - result.taddr_ = 0; - - // index corresponding to this element - if( Variable(*vec_) ) - { - local::ADTape* tape = AD::tape_ptr(vec_->tape_id_); - CPPAD_ASSERT_UNKNOWN( tape != CPPAD_NULL ); - CPPAD_ASSERT_UNKNOWN( vec_->offset_ > 0 ); - - size_t load_op_index = tape->Rec_.num_load_op_rec(); - if( IdenticalPar(ind_) ) - { CPPAD_ASSERT_UNKNOWN( local::NumRes(local::LdpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::LdpOp) == 3 ); - - // put operand addresses in tape - tape->Rec_.PutArg( - (addr_t) vec_->offset_, (addr_t) i, (addr_t) load_op_index - ); - // put operator in the tape, ind_ is a parameter - result.taddr_ = tape->Rec_.PutLoadOp(local::LdpOp); - // change result to variable for this load - result.tape_id_ = tape->id_; - } - else - { CPPAD_ASSERT_UNKNOWN( local::NumRes(local::LdvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( local::NumArg(local::LdvOp) == 3 ); - addr_t ind_taddr; - if( Parameter(ind_) ) - { // kludge that should not be needed - // if ind_ instead of i is used for index - // in the tape - ind_taddr = tape->RecordParOp( - ind_.value_ - ); - } - else ind_taddr = ind_.taddr_; - CPPAD_ASSERT_UNKNOWN( ind_taddr > 0 ); - - // put operand addresses in tape - // (value of third arugment does not matter) - tape->Rec_.PutArg( - (addr_t) vec_->offset_, - (addr_t) ind_taddr, - (addr_t) load_op_index - ); - // put operator in the tape, ind_ is a variable - result.taddr_ = tape->Rec_.PutLoadOp(local::LdvOp); - // change result to variable for this load - result.tape_id_ = tape->id_; - } - } - return result; - } -}; - -/*! -Vector of AD objects that tracks indexing operations on the tape. -*/ -template -class VecAD { - friend bool Parameter (const VecAD &vec); - friend bool Variable (const VecAD &vec); - friend class local::ADTape; - friend class VecAD_reference; - - friend std::ostream& operator << - (std::ostream &os, const VecAD &vec_); -private: - /// size of this VecAD vector - const size_t length_; - - /// elements of this vector - local::pod_vector data_; - - /// offset in cummulate vector corresponding to this object - size_t offset_; - - /// tape id corresponding to the offset - tape_id_t tape_id_; -public: - /// declare the user's view of this type here - typedef VecAD_reference reference; - - /// default constructor - /// initialize tape_id_ same as for default constructor; see default.hpp - VecAD(void) - : length_(0) - , offset_(0) - , tape_id_(0) - { CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); } - - /// sizing constructor - /// initialize tape_id_ same as for parameters; see ad_copy.hpp - VecAD(size_t n) - : length_(n) - , offset_(0) - , tape_id_(0) - { if( length_ > 0 ) - { size_t i; - Base zero(0); - data_.extend(length_); - - // Initialize data to zero so all have same value. - // This uses less memory and avoids a valgrind error - // during TapeRec::PutPar - for(i = 0; i < length_; i++) - data_[i] = zero; - } - CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); - } - - /// destructor - ~VecAD(void) - { } - - /// number of elements in the vector - size_t size(void) - { return length_; } - - /// element access (not taped) - /// - /// \param i - /// element index - Base &operator[](size_t i) - { - CPPAD_ASSERT_KNOWN( - Parameter(*this), - "VecAD: cannot use size_t indexing because this" - " VecAD vector is a variable." - ); - CPPAD_ASSERT_KNOWN( - i < length_, - "VecAD: element index is >= vector length" - ); - - return data_[i]; - } - - /*! delayed taped elemement access - - \param x - element index - - \par - This operation may convert this vector from a parameter to a variable - */ - VecAD_reference operator[](const AD &x) - { - CPPAD_ASSERT_KNOWN( - 0 <= Integer(x), - "VecAD: element index is less than zero" - ); - CPPAD_ASSERT_KNOWN( - static_cast( Integer(x) ) < length_, - "VecAD: element index is >= vector length" - ); - - // if no need to track indexing operation, return now - if( Parameter(*this) & Parameter(x) ) - return VecAD_reference(this, x); - - CPPAD_ASSERT_KNOWN( - Parameter(*this) | Parameter(x) | (tape_id_ == x.tape_id_), - "VecAD: vector and index are variables for" - " different tapes." - ); - - if( Parameter(*this) ) - { // must place a copy of vector in tape - offset_ = - AD::tape_ptr(x.tape_id_)->AddVec(length_, data_); - - // Advance pointer by one so starts at first component of this - // vector; i.e., skip lenght at begining (so is always > 0) - offset_++; - - // tape id corresponding to this offest - tape_id_ = x.tape_id_; - } - - return VecAD_reference(this, x); - } - -}; - - -/*! -Taped setting of element to a value. - -\param y -value that element is set to. -*/ -template -void VecAD_reference::operator=(const AD &y) -{ - if( Parameter(y) ) - { // fold into the Base type assignment - *this = y.value_; - return; - } - CPPAD_ASSERT_UNKNOWN( y.taddr_ > 0 ); - - CPPAD_ASSERT_KNOWN( - Parameter(*vec_) | (vec_->tape_id_ == y.tape_id_), - "VecAD assignment: vector and new element value are variables" - "\nfor different tapes." - ); - - local::ADTape* tape = AD::tape_ptr(y.tape_id_); - CPPAD_ASSERT_UNKNOWN( tape != CPPAD_NULL ); - if( Parameter(*vec_) ) - { // must place a copy of vector in tape - vec_->offset_ = tape->AddVec(vec_->length_, vec_->data_); - - // advance offset to be start of vector plus one - (vec_->offset_)++; - - // tape id corresponding to this offest - vec_->tape_id_ = y.tape_id_; - } - CPPAD_ASSERT_UNKNOWN( Variable(*vec_) ); - - - // index in vector for this element - size_t i = static_cast( Integer(ind_) ); - CPPAD_ASSERT_UNKNOWN( i < vec_->length_ ); - - // assign value for this element (as an AD object) - vec_->data_[i] = y.value_; - - // record the setting of this array element - CPPAD_ASSERT_UNKNOWN( vec_->offset_ > 0 ); - if( Parameter(ind_) ) - { CPPAD_ASSERT_UNKNOWN( local::NumArg(local::StpvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::StpvOp) == 0 ); - - // put operand addresses in tape - tape->Rec_.PutArg((addr_t) vec_->offset_, (addr_t) i, y.taddr_); - - // put operator in the tape, ind_ is parameter, y is variable - tape->Rec_.PutOp(local::StpvOp); - } - else - { CPPAD_ASSERT_UNKNOWN( local::NumArg(local::StvvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::StvvOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( ind_.taddr_ > 0 ); - - // put operand addresses in tape - tape->Rec_.PutArg((addr_t) vec_->offset_, ind_.taddr_, y.taddr_); - - // put operator in the tape, ind_ is variable, y is variable - tape->Rec_.PutOp(local::StvvOp); - } -} - - -/*! -Taped setting of element to a value. - -\param y -value that element is set to. -*/ -template -void VecAD_reference::operator=(const Base &y) -{ - size_t i = static_cast( Integer(ind_) ); - CPPAD_ASSERT_UNKNOWN( i < vec_->length_ ); - - // assign value for this element - vec_->data_[i] = y; - - // check if this ADVec object is a parameter - if( Parameter(*vec_) ) - return; - - local::ADTape* tape = AD::tape_ptr(vec_->tape_id_); - CPPAD_ASSERT_UNKNOWN( tape != CPPAD_NULL ); - - // put value of the parameter y in the tape - addr_t p = tape->Rec_.PutPar(y); - - // record the setting of this array element - CPPAD_ASSERT_UNKNOWN( vec_->offset_ > 0 ); - if( Parameter(ind_) ) - { CPPAD_ASSERT_UNKNOWN( local::NumArg(local::StppOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::StppOp) == 0 ); - - // put operand addresses in tape - tape->Rec_.PutArg((addr_t) vec_->offset_, (addr_t) i, p); - - // put operator in the tape, ind_ is parameter, y is parameter - tape->Rec_.PutOp(local::StppOp); - } - else - { CPPAD_ASSERT_UNKNOWN( local::NumArg(local::StvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( local::NumRes(local::StvpOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( ind_.taddr_ > 0 ); - - // put operand addresses in tape - tape->Rec_.PutArg((addr_t) vec_->offset_, ind_.taddr_, p); - - // put operator in the tape, ind_ is variable, y is parameter - tape->Rec_.PutOp(local::StvpOp); - } -} - -/*! -Taped setting of element to a value. - -\param y -value that element is set to. - -\par -this case gets folded into case where value is AD. -*/ -template -inline void VecAD_reference::operator= -(const VecAD_reference &y) -{ *this = y.ADBase(); } - -/*! -Taped setting of element to a value. - -\param y -value that element is set to. - -\par -this case gets folded into case where value is Base. -*/ -template -inline void VecAD_reference::operator=(int y) -{ *this = Base(y); } - - -} // END_CPPAD_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_VEC_AD_COMPUTED_ASSIGNMENT - -# endif diff --git a/external/cppad/include/cppad/core/zdouble.hpp b/external/cppad/include/cppad/core/zdouble.hpp deleted file mode 100644 index dcd101b7e..000000000 --- a/external/cppad/include/cppad/core/zdouble.hpp +++ /dev/null @@ -1,536 +0,0 @@ -# ifndef CPPAD_CORE_ZDOUBLE_HPP -# define CPPAD_CORE_ZDOUBLE_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin zdouble$$ -$spell - zdouble - op - bool - inf - CppAD -$$ -$section zdouble: An AD Base Type With Absolute Zero$$ - -$head Deprecated 2015-09-26$$ -Use the function $cref azmul$$ instead. - -$head Absolute Zero$$ -The $code zdouble$$ class acts like the $code double$$ type -with the added property that zero times any value is zero. -This includes zero time $cref nan$$ and zero times infinity. -In addition, zero divided by any value and any value times zero -are also zero. - -$head Syntax$$ - -$subhead Constructor and Assignment$$ -$codei% zdouble z -%$$ -$codei% zdouble z(x) -%$$ -$icode% z1% %op% %x% -%$$ -where $icode x$$ is a $code double$$ or $code zdouble$$ object -and $icode op$$ is $code =$$, $code +=$$, $code -=$$, $code *=$$ -or $code /=-$$. - -$subhead Comparison Operators$$ -$icode% b% = %z% %op% %x% -%$$ -$icode% b% = %x% %op% %z% -%$$ -where $icode b$$ is a $code bool$$ object, -$icode z$$ is a $code zdouble$$ object, -$icode x$$ is a $code double$$ or $code zdouble$$ object, and -$icode op$$ is $code ==$$, $code !=$$, $code <=$$, $code >=$$, -$code <$$ or $code >$$. - -$subhead Arithmetic Operators$$ -$icode% z2% = %z1% %op% %x% -%$$ -$icode% z2% = %x% %op% %z1% -%$$ -where $icode z1$$, $icode z2$$ are $code zdouble$$ objects, -$icode x$$ is a $code double$$ or $code zdouble$$ object, and -$icode op$$ is $code +$$, $code -$$, $code *$$ or $code /$$. - - -$subhead Standard Math$$ -$icode% z2% = %fun%(%z1%) -%$$ -$icode% z3% = pow(%z1%, %z2%) -%$$ -where $icode z1$$, $icode z2$$, $icode z3$$ are $code zdouble$$ objects and -$icode fun$$ is a $cref unary_standard_math$$ function. - -$subhead Nan$$ -There is a specialization of $cref nan$$ so that -$icode% - z2% = nan(%z1%) -%$$ -returns 'not a number' when $icode z1$$ has type $code zdouble$$. -Note that this template function needs to be specialized because -$codei - zdouble(0.0) == zdouble(0.0) / zdouble(0.0) -$$ - - -$head Motivation$$ - -$subhead General$$ -Often during computing (and more so in parallel computing) alternative -values for an expression are computed and one of the alternatives -is chosen using some boolean variable. -This is often represented by -$codei% - %result% = %flag% * %value_if_true% + (1 - %flag%) * %value_if_false% -%$$ -where $icode flag$$ is one for true and zero for false. -This representation does not work for $code double$$ when the value -being multiplied by zero is $code +inf$$, $code -inf$$, or $code nan$$. - -$subhead CppAD$$ -In CppAD one can use -$cref/conditional expressions/CondExp/$$ to achieve the representation -$codei% - %result% = %flag% * %value_if_true% + (1 - %flag%) * %value_if_false% -%$$ -This works fine except when there are -$cref/multiple levels of AD/mul_level/$$; e.g., -when using $codei%AD< AD >%$$. -In this case the corresponding AD function objects have type -$cref/ADFun< AD >/FunConstruct/$$. -When these AD function objects compute derivatives using -$cref reverse$$ mode, the conditional expressions are represented use -zeros to multiply the expression that is not used. -Using $codei%AD< AD >%$$ instead of $code AD< AD >$$ -makes this representation work and fixes the problem. - -$head Base Type Requirements$$ -The type $code zdouble$$ satisfies all of the CppAD -$cref/base type requirements/base_require/$$. - -$children% - example/deprecated/zdouble.cpp -%$$ -$head Example$$ -The file $cref zdouble.cpp$$ -contains an example and test of this class. -It returns true if it succeeds and false otherwise. - -$end -*/ -# include -# include - -/*! -\file zdouble.hpp -Define a class like double but with an absolute zero. -*/ - -/*! -\def CPPAD_ZDOUBLE_NORMAL_ASSIGN_OPERATOR(op) -Define a compound assignment member operator that functions the same -as corresponding double operator. -*/ -# define CPPAD_ZDOUBLE_NORMAL_ASSIGN_OPERATOR(op) \ - zdouble& operator op (const zdouble& z) \ - { dbl_ op z.dbl_; \ - return *this; \ - } \ - zdouble& operator op (const double& x) \ - { dbl_ op x; \ - return *this; \ - } - -/*! -\def CPPAD_ZDOUBLE_UNARY_OPERATOR(op) -Define a unary compound assignment member operator. -*/ -# define CPPAD_ZDOUBLE_UNARY_OPERATOR(op) \ - zdouble operator op (void) const \ - { return zdouble( op dbl_ ); } - -/*! -# define CPPAD_ZDOUBLE_NORMAL_BINARY_OPERATOR(op) -Define a binary arithmetic member operator that functions the same -as corresponding double operator. -*/ -# define CPPAD_ZDOUBLE_NORMAL_BINARY_OPERATOR(op) \ - zdouble operator op (const zdouble& z) const \ - { return zdouble( dbl_ op z.dbl_ ); } \ - zdouble operator op (const double& x) const \ - { return zdouble( dbl_ op x ); } - -/*! -\def CPPAD_ZDOUBLE_COMPARE_OPERATOR(op) -Define a comparison member operator. -*/ -# define CPPAD_ZDOUBLE_COMPARE_OPERATOR(op) \ - bool operator op (const zdouble& z) const \ - { return dbl_ op z.dbl_; } \ - bool operator op (const double& x) const \ - { return dbl_ op x; } - -/*! -\def CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR(op) -Define a binary arithmetic operator that is not a member because -the double operand is on the left. -*/ -# define CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR(op) \ - inline zdouble operator op(const double& x, const zdouble& z) \ - { return zdouble(x) op z; } - -/*! -\def CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(op, op_switch) -Define a comparison operator that is not a member because -the double operand is on the left. -Convert it to the case where the double operand is on the right by -by using op_switch instead of op. -*/ -# define CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(op, op_switch) \ - inline bool operator op(const double& x, const zdouble& z) \ - { return z op_switch x; } - -/*! -\def CPPAD_ZDOUBLE_STD_MATH_FRIEND(fun) -Declare that a standard math function is a friend. -*/ -# define CPPAD_ZDOUBLE_STD_MATH_FRIEND(fun) \ - friend zdouble fun(const zdouble& z); -/*! -\def CPPAD_ZDOUBLE_STD_MATH(fun) -Define a standard math function. -*/ -# define CPPAD_ZDOUBLE_STD_MATH(fun) \ - inline zdouble fun(const zdouble& z ) \ - { return zdouble( std::fun(z.dbl_) ); } - -namespace CppAD { // CPPAD_BEGIN_NAMESPACDE - - -/*! -Class that is like double, except that it has an absolute zero. -*/ -class zdouble { - /*! - For zdouble objects z1, z2, and std::ostream os, - declare the following friends: - \code - os << z1 - Integer(z1) - fabs(z1) - pow(z1, z2) - fabs_geq(z1, z2) - fun(z1) - \endcode - where fun is any of the standard math unary functions. - */ - friend std::ostream& operator << (std::ostream &os, const zdouble& z); - friend int Integer(const zdouble& z); - friend zdouble pow(const zdouble& x, const zdouble& y); - friend bool abs_geq(const zdouble& x, const zdouble& y); - // - CPPAD_ZDOUBLE_STD_MATH_FRIEND(acos) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(asin) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(atan) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(cos) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(cosh) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(exp) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(fabs) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(log) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(log10) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(sin) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(sinh) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(sqrt) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(tan) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(tanh) - // -# if CPPAD_USE_CPLUSPLUS_2011 - CPPAD_ZDOUBLE_STD_MATH_FRIEND(erf) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(asinh) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(acosh) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(atanh) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(expm1) - CPPAD_ZDOUBLE_STD_MATH_FRIEND(log1p) - // -# endif -private: - /// The value for this object - double dbl_; -public: - /// Default constructor - zdouble(void) - : dbl_() - { } - /// Copy constructor - zdouble(const zdouble& z) - : dbl_(z.dbl_) - { } - /// Constructor from double - zdouble(const double& dbl) - : dbl_(dbl) - { } - // - /// Destructor - ~zdouble(void) - { } - // - /// Assignment from zdouble - zdouble& operator=(const zdouble& z) - { dbl_ = z.dbl_; - return *this; - } - /// Assignment from double - zdouble& operator=(const double& dbl) - { dbl_ = dbl; - return *this; - } - // - /// Normal compound assignment - CPPAD_ZDOUBLE_NORMAL_ASSIGN_OPERATOR(+=) - /// Normal compound assignment - CPPAD_ZDOUBLE_NORMAL_ASSIGN_OPERATOR(-=) - /// Normal unary operator - CPPAD_ZDOUBLE_UNARY_OPERATOR(+) - /// Normal unary operator - CPPAD_ZDOUBLE_UNARY_OPERATOR(-) - /// Normal compare operator - CPPAD_ZDOUBLE_COMPARE_OPERATOR(==) - /// Normal compare operator - CPPAD_ZDOUBLE_COMPARE_OPERATOR(!=) - /// Normal compare operator - CPPAD_ZDOUBLE_COMPARE_OPERATOR(<=) - /// Normal compare operator - CPPAD_ZDOUBLE_COMPARE_OPERATOR(>=) - /// Normal compare operator - CPPAD_ZDOUBLE_COMPARE_OPERATOR(<) - /// Normal compare operator - CPPAD_ZDOUBLE_COMPARE_OPERATOR(>) - // - /// Normal binary arithmetic operator - CPPAD_ZDOUBLE_NORMAL_BINARY_OPERATOR(+) - /// Normal binary arithmetic operator - CPPAD_ZDOUBLE_NORMAL_BINARY_OPERATOR(-) - // - /// Binary arithmetic * with absolute zero - zdouble operator * (const zdouble& z) const - { bool zero = (dbl_ == 0.0) || (z.dbl_ == 0.0); - return zdouble( zero ? 0.0 : (dbl_ * z.dbl_) ); - } - /// Binary arithmetic * with absolute zero - zdouble operator * (const double& x) const - { bool zero = (dbl_ == 0.0) || (x == 0.0); - return zdouble( zero ? 0.0 : (dbl_ * x) ); - } - /// Binary arithmetic / with absolute zero - zdouble operator / (const zdouble& z) const - { bool zero = (dbl_ == 0.0); - return zdouble( zero ? 0.0 : (dbl_ / z.dbl_) ); - } - /// Binary arithmetic / with absolute zero - zdouble operator / (const double& x) const - { bool zero = (dbl_ == 0.0); - return zdouble( zero ? 0.0 : (dbl_ / x) ); - } - // - /// Compute assignmnet *= with absolute zero - zdouble& operator *= (const zdouble& z) - { bool zero = (dbl_ == 0.0) || (z.dbl_ == 0.0); - zero ? (dbl_ = 0.0) : (dbl_ *= z.dbl_); - return *this; - } - /// Compute assignmnet *= with absolute zero - zdouble& operator *= (const double& x) - { bool zero = (dbl_ == 0.0) || (x == 0.0); - zero ? (dbl_ = 0.0) : (dbl_ *= x); - return *this; - } - // - /// Compute assignmnet /= with absolute zero - zdouble& operator /= (const zdouble& z) - { bool zero = (dbl_ == 0.0); - zero ? (dbl_ = 0.0) : (dbl_ /= z.dbl_); - return *this; - } - /// Compute assignmnet /= with absolute zero - zdouble& operator /= (const double& x) - { bool zero = (dbl_ == 0.0); - zero ? (dbl_ = 0.0) : (dbl_ /= x); - return *this; - } -}; -// BEGIN nan -/// Must specialize CppAD::nan because zdouble 0/0 is not nan. -template <> -inline zdouble nan(const zdouble& zero) -{ - return zdouble( std::numeric_limits::quiet_NaN() ); -} -// END nan -// -/// Normal non-member compare operator -CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(==, ==) -/// Normal non-member compare operator -CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(!=, !=) -/// Normal non-member compare operator -CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(<=, >=) -/// Normal non-member compare operator -CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(>=, <=) -/// Normal non-member compare operator -CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(<, >) -/// Normal non-member compare operator -CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR(>, <) -// -/// Normal binary arithmetic operator -CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR(+) -/// Normal binary arithmetic operator -CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR(-) -/// Binary arithmetic operator with absolute zero -CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR(*) -/// Binary arithmetic operator with absolute zero -CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR(/) -// ------------------------------------------------------------------------- -// Base type requirements -// ------------------------------------------------------------------------- - -/// Base type requirement: CondExpOp -inline zdouble CondExpOp( - enum CompareOp cop , - const zdouble& left , - const zdouble& right , - const zdouble& exp_if_true , - const zdouble& exp_if_false ) -{ return CondExpTemplate(cop, left, right, exp_if_true, exp_if_false); -} - -/// Base type requirement: CondExpRel -CPPAD_COND_EXP_REL(zdouble) - -/// Base type requirement: EqualOpSeq -inline bool EqualOpSeq(const zdouble& x, const zdouble& y) -{ return x == y; } - -/// Base type requirement: Identical -inline bool IdenticalPar(const zdouble& x) -{ return true; } -inline bool IdenticalZero(const zdouble& x) -{ return (x == 0.0); } -inline bool IdenticalOne(const zdouble& x) -{ return (x == 1.); } -inline bool IdenticalEqualPar(const zdouble& x, const zdouble& y) -{ return (x == y); } - -/// Base type requirement: output operator -inline std::ostream& operator << (std::ostream &os, const zdouble& z) -{ os << z.dbl_; - return os; -} - -/// Base type requirement: Integer -inline int Integer(const zdouble& x) -{ return static_cast(x.dbl_); } - -/// Base type requirement: azmul -inline zdouble azmul(const zdouble& x, const zdouble& y) -{ return x * y; } - -/// Base type requirement: Ordered -inline bool GreaterThanZero(const zdouble& x) -{ return x > 0.0; } -inline bool GreaterThanOrZero(const zdouble& x) -{ return x >= 0.0; } -inline bool LessThanZero(const zdouble& x) -{ return x < 0.0; } -inline bool LessThanOrZero(const zdouble& x) -{ return x <= 0.0; } -inline bool abs_geq(const zdouble& x, const zdouble& y) -{ return std::fabs(x.dbl_) >= std::fabs(y.dbl_); } - -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(acos) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(asin) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(atan) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(cos) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(cosh) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(exp) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(fabs) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(log) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(log10) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(sin) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(sinh) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(sqrt) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(tan) -/// Normal standard math function -CPPAD_ZDOUBLE_STD_MATH(tanh) -// -# if CPPAD_USE_CPLUSPLUS_2011 -/// C++2011 standard math function -CPPAD_ZDOUBLE_STD_MATH(erf) -/// C++2011 standard math function -CPPAD_ZDOUBLE_STD_MATH(asinh) -/// C++2011 standard math function -CPPAD_ZDOUBLE_STD_MATH(acosh) -/// C++2011 standard math function -CPPAD_ZDOUBLE_STD_MATH(atanh) -/// C++2011 standard math function -CPPAD_ZDOUBLE_STD_MATH(expm1) -/// C++2011 standard math function -CPPAD_ZDOUBLE_STD_MATH(log1p) -# endif - -/// Base type requirement: abs -inline zdouble abs(const zdouble& x) -{ return fabs(x); } - -/// Base type requirement: sign -inline zdouble sign(const zdouble& x) -{ if( x > 0.0 ) - return zdouble(1.); - if( x == 0.0 ) - return zdouble(0.0); - return zdouble(-1.); -} - -/// Base type requirement: pow -inline zdouble pow(const zdouble& x, const zdouble& y) -{ return std::pow(x.dbl_, y.dbl_); } - -/// Base type requirement: limits -CPPAD_NUMERIC_LIMITS(double, zdouble) - -} // CPPAD_END_NAMESPACE - -/// undef all macros defined in this file -# undef CPPAD_ZDOUBLE_NORMAL_ASSIGN_OPERATOR -# undef CPPAD_ZDOUBLE_UNARY_OPERATOR -# undef CPPAD_ZDOUBLE_NORMAL_BINARY_OPERATOR -# undef CPPAD_ZDOUBLE_COMPARE_OPERATOR -# undef CPPAD_ZDOUBLE_OTHER_BINARY_OPERATOR -# undef CPPAD_ZDOUBLE_OTHER_COMPARE_OPERATOR -# undef CPPAD_ZDOUBLE_STD_MATH_FRIEND -# undef CPPAD_ZDOUBLE_STD_MATH - -# endif diff --git a/external/cppad/include/cppad/cppad.hpp b/external/cppad/include/cppad/cppad.hpp deleted file mode 100644 index 828dee1be..000000000 --- a/external/cppad/include/cppad/cppad.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// $Id: cppad.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_CPPAD_HPP -# define CPPAD_CPPAD_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file cppad.hpp -\brief includes the entire CppAD package in the necessary order. - -\namespace CppAD -\brief contains all the variables and functions defined by the CppAD package. -*/ - -# include // all base type requirements -// --------------------------------------------------------------------------- -// CppAD general purpose library routines (can be included separately) -# include -// -------------------------------------------------------------------------- -// System routines that can be used by rest of CppAD with out including - -# include -# include -# include -# include - -// --------------------------------------------------------------------------- -// definitions needed by rest of includes - -// definitions that come from the installation -# include - -// definitions that are local to the CppAD include files -# include - -// vectors used with CppAD -# include - -// deprecated vectors used with CppAD -# include - -// Declare classes and fucntions that are used before defined -# include - -// --------------------------------------------------------------------------- -// declare the AD template class - -# include - -// --------------------------------------------------------------------------- - -# include // AD class methods available to the user -// tape that tape for AD acts as a user of Base operations -// so user_ad.hpp must come before op.hpp -# include // executes taped operations -# include // ADFun objects - -// --------------------------------------------------------------------------- -// library routines that require the rest of CppAD -# include -# include -# include - -// undo definitions in Define.h -# include - -# endif diff --git a/external/cppad/include/cppad/example/base_adolc.hpp b/external/cppad/include/cppad/example/base_adolc.hpp deleted file mode 100644 index 52e4ea806..000000000 --- a/external/cppad/include/cppad/example/base_adolc.hpp +++ /dev/null @@ -1,364 +0,0 @@ -# ifndef CPPAD_EXAMPLE_BASE_ADOLC_HPP -# define CPPAD_EXAMPLE_BASE_ADOLC_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin base_adolc.hpp$$ -$spell - stringstream - struct - string - setprecision - str - valgrind - azmul - expm1 - atanh - acosh - asinh - erf - ifndef - define - endif - Rel - codassign - eps - std - abs_geq - fabs - cppad.hpp - undef - Lt - Le - Eq - Ge - Gt - namespace - cassert - condassign - hpp - bool - const - Adolc - adouble - CondExpOp - inline - enum - CppAD - pow - acos - asin - atan - cos - cosh - exp - sqrt -$$ - - -$section Enable use of AD where Base is Adolc's adouble Type$$ - -$head Syntax$$ -$codei%# include -%$$ -$children% - example/general/mul_level_adolc.cpp -%$$ - -$head Example$$ -The file $cref mul_level_adolc.cpp$$ contains an example use of -Adolc's $code adouble$$ type for a CppAD $icode Base$$ type. -It returns true if it succeeds and false otherwise. -The file $cref mul_level_adolc_ode.cpp$$ contains a more realistic -(and complex) example. - -$head Include Files$$ -This file $code base_adolc.hpp$$ requires $code adouble$$ to be defined. -In addition, it is included before $code $$, -but it needs to include parts of CppAD that are used by this file. -This is done with the following include commands: -$srccode%cpp% */ -# include -# include -/* %$$ - -$head CondExpOp$$ -The type $code adouble$$ supports a conditional assignment function -with the syntax -$codei% - condassign(%a%, %b%, %c%, %d%) -%$$ -which evaluates to -$codei% - %a% = (%b% > 0) ? %c% : %d%; -%$$ -This enables one to include conditionals in the recording of -$code adouble$$ operations and later evaluation for different -values of the independent variables -(in the same spirit as the CppAD $cref CondExp$$ function). -$srccode%cpp% */ -namespace CppAD { - inline adouble CondExpOp( - enum CppAD::CompareOp cop , - const adouble &left , - const adouble &right , - const adouble &trueCase , - const adouble &falseCase ) - { adouble result; - switch( cop ) - { - case CompareLt: // left < right - condassign(result, right - left, trueCase, falseCase); - break; - - case CompareLe: // left <= right - condassign(result, left - right, falseCase, trueCase); - break; - - case CompareEq: // left == right - condassign(result, left - right, falseCase, trueCase); - condassign(result, right - left, falseCase, result); - break; - - case CompareGe: // left >= right - condassign(result, right - left, falseCase, trueCase); - break; - - case CompareGt: // left > right - condassign(result, left - right, trueCase, falseCase); - break; - default: - CppAD::ErrorHandler::Call( - true , __LINE__ , __FILE__ , - "CppAD::CondExp", - "Error: for unknown reason." - ); - result = trueCase; - } - return result; - } -} -/* %$$ - -$head CondExpRel$$ -The $cref/CPPAD_COND_EXP_REL/base_cond_exp/CondExpRel/$$ macro invocation -$srccode%cpp% */ -namespace CppAD { - CPPAD_COND_EXP_REL(adouble) -} -/* %$$ - -$head EqualOpSeq$$ -The Adolc user interface does not specify a way to determine if -two $code adouble$$ variables correspond to the same operations sequence. -Make $code EqualOpSeq$$ an error if it gets used: -$srccode%cpp% */ -namespace CppAD { - inline bool EqualOpSeq(const adouble &x, const adouble &y) - { CppAD::ErrorHandler::Call( - true , __LINE__ , __FILE__ , - "CppAD::EqualOpSeq(x, y)", - "Error: adouble does not support EqualOpSeq." - ); - return false; - } -} -/* %$$ - -$head Identical$$ -The Adolc user interface does not specify a way to determine if an -$code adouble$$ depends on the independent variables. -To be safe (but slow) return $code false$$ in all the cases below. -$srccode%cpp% */ -namespace CppAD { - inline bool IdenticalPar(const adouble &x) - { return false; } - inline bool IdenticalZero(const adouble &x) - { return false; } - inline bool IdenticalOne(const adouble &x) - { return false; } - inline bool IdenticalEqualPar(const adouble &x, const adouble &y) - { return false; } -} -/* %$$ - -$head Integer$$ -$srccode%cpp% */ - inline int Integer(const adouble &x) - { return static_cast( x.getValue() ); } -/* %$$ - -$head azmul$$ -$srccode%cpp% */ -namespace CppAD { - CPPAD_AZMUL( adouble ) -} -/* %$$ - -$head Ordered$$ -$srccode%cpp% */ -namespace CppAD { - inline bool GreaterThanZero(const adouble &x) - { return (x > 0); } - inline bool GreaterThanOrZero(const adouble &x) - { return (x >= 0); } - inline bool LessThanZero(const adouble &x) - { return (x < 0); } - inline bool LessThanOrZero(const adouble &x) - { return (x <= 0); } - inline bool abs_geq(const adouble& x, const adouble& y) - { return fabs(x) >= fabs(y); } -} -/* %$$ - -$head Unary Standard Math$$ -The following $cref/required/base_require/$$ functions -are defined by the Adolc package for the $code adouble$$ base case: -$pre -$$ -$code acos$$, -$code asin$$, -$code atan$$, -$code cos$$, -$code cosh$$, -$code exp$$, -$code fabs$$, -$code log$$, -$code sin$$, -$code sinh$$, -$code sqrt$$, -$code tan$$. - -$head erf, asinh, acosh, atanh, expm1, log1p$$ -If the -$cref/erf, asinh, acosh, atanh, expm1, log1p - /base_std_math - /erf, asinh, acosh, atanh, expm1, log1p -/$$, -functions are supported by the compiler, -they must also be supported by a $icode Base$$ type; -The adolc package does not support these functions so make -their use an error: -$srccode%cpp% */ -namespace CppAD { -# define CPPAD_BASE_ADOLC_NO_SUPPORT(fun) \ - inline adouble fun(const adouble& x) \ - { CPPAD_ASSERT_KNOWN( \ - false, \ - #fun ": adolc does not support this function" \ - ); \ - return 0.0; \ - } -# if CPPAD_USE_CPLUSPLUS_2011 - CPPAD_BASE_ADOLC_NO_SUPPORT(erf) - CPPAD_BASE_ADOLC_NO_SUPPORT(asinh) - CPPAD_BASE_ADOLC_NO_SUPPORT(acosh) - CPPAD_BASE_ADOLC_NO_SUPPORT(atanh) - CPPAD_BASE_ADOLC_NO_SUPPORT(expm1) - CPPAD_BASE_ADOLC_NO_SUPPORT(log1p) -# endif -# undef CPPAD_BASE_ADOLC_NO_SUPPORT -} -/* %$$ - -$head sign$$ -This $cref/required/base_require/$$ function is defined using the -$code codassign$$ function so that its $code adouble$$ operation sequence -does not depend on the value of $icode x$$. -$srccode%cpp% */ -namespace CppAD { - inline adouble sign(const adouble& x) - { adouble s_plus, s_minus, half(.5); - // set s_plus to sign(x)/2, except for case x == 0, s_plus = -.5 - condassign(s_plus, +x, -half, +half); - // set s_minus to -sign(x)/2, except for case x == 0, s_minus = -.5 - condassign(s_minus, -x, -half, +half); - // set s to sign(x) - return s_plus - s_minus; - } -} -/* %$$ - -$head abs$$ -This $cref/required/base_require/$$ function uses the adolc $code fabs$$ -function: -$srccode%cpp% */ -namespace CppAD { - inline adouble abs(const adouble& x) - { return fabs(x); } -} -/* %$$ - -$head pow$$ -This $cref/required/base_require/$$ function -is defined by the Adolc package for the $code adouble$$ base case. - -$head numeric_limits$$ -The following defines the CppAD $cref numeric_limits$$ -for the type $code adouble$$: -$srccode%cpp% */ -namespace CppAD { - CPPAD_NUMERIC_LIMITS(double, adouble) -} -/* %$$ - -$head to_string$$ -The following defines the CppAD $cref to_string$$ function -for the type $code adouble$$: -$srccode%cpp% */ -namespace CppAD { - template <> struct to_string_struct - { std::string operator()(const adouble& x) - { std::stringstream os; - int n_digits = 1 + std::numeric_limits::digits10; - os << std::setprecision(n_digits); - os << x.value(); - return os.str(); - } - }; -} -/* %$$ - -$head hash_code$$ -It appears that an $code adouble$$ object can have fields -that are not initialized. -This results in a $code valgrind$$ error when these fields are used by the -$cref/default/base_hash/Default/$$ hashing function. -For this reason, the $code adouble$$ class overrides the default definition. -$srccode|cpp| */ -namespace CppAD { - inline unsigned short hash_code(const adouble& x) - { unsigned short code = 0; - double value = x.value(); - if( value == 0.0 ) - return code; - double log_x = std::log( fabs( value ) ); - // assume log( std::numeric_limits::max() ) is near 700 - code = static_cast( - (CPPAD_HASH_TABLE_SIZE / 700 + 1) * log_x - ); - code = code % CPPAD_HASH_TABLE_SIZE; - return code; - } -} -/* |$$ -Note that after the hash codes match, the -$cref/Identical/base_adolc.hpp/Identical/$$ function will be used -to make sure two values are the same and one can replace the other. -A more sophisticated implementation of the $code Identical$$ function -would detect which $code adouble$$ values depend on the -$code adouble$$ independent variables (and hence can change). - - -$end -*/ -# endif - diff --git a/external/cppad/include/cppad/example/cppad_eigen.hpp b/external/cppad/include/cppad/example/cppad_eigen.hpp deleted file mode 100644 index f8aec8ff0..000000000 --- a/external/cppad/include/cppad/example/cppad_eigen.hpp +++ /dev/null @@ -1,147 +0,0 @@ -# ifndef CPPAD_EXAMPLE_CPPAD_EIGEN_HPP -# define CPPAD_EXAMPLE_CPPAD_EIGEN_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin cppad_eigen.hpp$$ -$spell - impl - typename - Real Real - inline - neg - eps - atan - Num - acos - asin - CppAD - std::numeric - enum - Mul - Eigen - cppad.hpp - namespace - struct - typedef - const - imag - sqrt - exp - cos -$$ -$section Enable Use of Eigen Linear Algebra Package with CppAD$$ - -$head Syntax$$ -$codei%# include %$$ -$children% - example/general/eigen_array.cpp% - example/general/eigen_det.cpp -%$$ - -$head Purpose$$ -Enables the use of the $cref/eigen/eigen_prefix/$$ -linear algebra package with the type $icode%AD<%Base%>%$$; see -$href% - https://eigen.tuxfamily.org/dox/TopicCustomizing_CustomScalar.html% - custom scalar types -%$$. - -$head Example$$ -The files $cref eigen_array.cpp$$ and $cref eigen_det.cpp$$ -contain an example and test of this include file. -They return true if they succeed and false otherwise. - -$head Include Files$$ -The file $code cppad_eigen.hpp$$ includes both -$code $$ and $code $$. -$srccode%cpp% */ -# include -# include -/* %$$ -$head Eigen NumTraits$$ -Eigen needs the following definitions to work properly -with $codei%AD<%Base%>%$$ scalars: -$srccode%cpp% */ -namespace Eigen { - template struct NumTraits< CppAD::AD > - { // type that corresponds to the real part of an AD value - typedef CppAD::AD Real; - // type for AD operations that result in non-integer values - typedef CppAD::AD NonInteger; - // type to use for numeric literals such as "2" or "0.5". - typedef CppAD::AD Literal; - // type for nested value inside an AD expression tree - typedef CppAD::AD Nested; - - enum { - // does not support complex Base types - IsComplex = 0 , - // does not support integer Base types - IsInteger = 0 , - // only support signed Base types - IsSigned = 1 , - // must initialize an AD object - RequireInitialization = 1 , - // computational cost of the corresponding operations - ReadCost = 1 , - AddCost = 2 , - MulCost = 2 - }; - - // machine epsilon with type of real part of x - // (use assumption that Base is not complex) - static CppAD::AD epsilon(void) - { return CppAD::numeric_limits< CppAD::AD >::epsilon(); } - - // relaxed version of machine epsilon for comparison of different - // operations that should result in the same value - static CppAD::AD dummy_precision(void) - { return 100. * - CppAD::numeric_limits< CppAD::AD >::epsilon(); - } - - // minimum normalized positive value - static CppAD::AD lowest(void) - { return CppAD::numeric_limits< CppAD::AD >::min(); } - - // maximum finite value - static CppAD::AD highest(void) - { return CppAD::numeric_limits< CppAD::AD >::max(); } - - // number of decimal digits that can be represented without change. - static int digits10(void) - { return CppAD::numeric_limits< CppAD::AD >::digits10; } - }; -} -/* %$$ -$head CppAD Namespace$$ -Eigen also needs the following definitions to work properly -with $codei%AD<%Base%>%$$ scalars: -$srccode%cpp% */ -namespace CppAD { - // functions that return references - template const AD& conj(const AD& x) - { return x; } - template const AD& real(const AD& x) - { return x; } - - // functions that return values (note abs is defined by cppad.hpp) - template AD imag(const AD& x) - { return CppAD::AD(0.); } - template AD abs2(const AD& x) - { return x * x; } -} - -/* %$$ -$end -*/ -# endif diff --git a/external/cppad/include/cppad/example/eigen_cholesky.hpp b/external/cppad/include/cppad/example/eigen_cholesky.hpp deleted file mode 100644 index 6255049d0..000000000 --- a/external/cppad/include/cppad/example/eigen_cholesky.hpp +++ /dev/null @@ -1,377 +0,0 @@ -// $Id$ -# ifndef CPPAD_EXAMPLE_EIGEN_CHOLESKY_HPP -# define CPPAD_EXAMPLE_EIGEN_CHOLESKY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin atomic_eigen_cholesky.hpp$$ -$spell - Eigen - Taylor - Cholesky - op -$$ - -$section Atomic Eigen Cholesky Factorization Class$$ - -$head Purpose$$ -Construct an atomic operation that computes a lower triangular matrix -$latex L $$ such that $latex L L^\R{T} = A$$ -for any positive integer $latex p$$ -and symmetric positive definite matrix $latex A \in \B{R}^{p \times p}$$. - -$head Start Class Definition$$ -$srccode%cpp% */ -# include -# include - - -/* %$$ -$head Public$$ - -$subhead Types$$ -$srccode%cpp% */ -namespace { // BEGIN_EMPTY_NAMESPACE - -template -class atomic_eigen_cholesky : public CppAD::atomic_base { -public: - // ----------------------------------------------------------- - // type of elements during calculation of derivatives - typedef Base scalar; - // type of elements during taping - typedef CppAD::AD ad_scalar; - // - // type of matrix during calculation of derivatives - typedef Eigen::Matrix< - scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> matrix; - // type of matrix during taping - typedef Eigen::Matrix< - ad_scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ad_matrix; - // - // lower triangular scalar matrix - typedef Eigen::TriangularView lower_view; -/* %$$ -$subhead Constructor$$ -$srccode%cpp% */ - // constructor - atomic_eigen_cholesky(void) : CppAD::atomic_base( - "atom_eigen_cholesky" , - CppAD::atomic_base::set_sparsity_enum - ) - { } -/* %$$ -$subhead op$$ -$srccode%cpp% */ - // use atomic operation to invert an AD matrix - ad_matrix op(const ad_matrix& arg) - { size_t nr = size_t( arg.rows() ); - size_t ny = ( (nr + 1 ) * nr ) / 2; - size_t nx = 1 + ny; - assert( nr == size_t( arg.cols() ) ); - // ------------------------------------------------------------------- - // packed version of arg - CPPAD_TESTVECTOR(ad_scalar) packed_arg(nx); - size_t index = 0; - packed_arg[index++] = ad_scalar( nr ); - // lower triangle of symmetric matrix A - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j <= i; j++) - packed_arg[index++] = arg(i, j); - } - assert( index == nx ); - // ------------------------------------------------------------------- - // packed version of result = arg^{-1}. - // This is an atomic_base function call that CppAD uses to - // store the atomic operation on the tape. - CPPAD_TESTVECTOR(ad_scalar) packed_result(ny); - (*this)(packed_arg, packed_result); - // ------------------------------------------------------------------- - // unpack result matrix L - ad_matrix result = ad_matrix::Zero(nr, nr); - index = 0; - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j <= i; j++) - result(i, j) = packed_result[index++]; - } - return result; - } - /* %$$ -$head Private$$ - -$subhead Variables$$ -$srccode%cpp% */ -private: - // ------------------------------------------------------------- - // one forward mode vector of matrices for argument and result - CppAD::vector f_arg_, f_result_; - // one reverse mode vector of matrices for argument and result - CppAD::vector r_arg_, r_result_; - // ------------------------------------------------------------- -/* %$$ -$subhead forward$$ -$srccode%cpp% */ - // forward mode routine called by CppAD - virtual bool forward( - // lowest order Taylor coefficient we are evaluating - size_t p , - // highest order Taylor coefficient we are evaluating - size_t q , - // which components of x are variables - const CppAD::vector& vx , - // which components of y are variables - CppAD::vector& vy , - // tx [ j * (q+1) + k ] is x_j^k - const CppAD::vector& tx , - // ty [ i * (q+1) + k ] is y_i^k - CppAD::vector& ty - ) - { size_t n_order = q + 1; - size_t nr = size_t( CppAD::Integer( tx[ 0 * n_order + 0 ] ) ); - size_t ny = ((nr + 1) * nr) / 2; -# ifndef NDEBUG - size_t nx = 1 + ny; -# endif - assert( vx.size() == 0 || nx == vx.size() ); - assert( vx.size() == 0 || ny == vy.size() ); - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - // - // ------------------------------------------------------------------- - // make sure f_arg_ and f_result_ are large enough - assert( f_arg_.size() == f_result_.size() ); - if( f_arg_.size() < n_order ) - { f_arg_.resize(n_order); - f_result_.resize(n_order); - // - for(size_t k = 0; k < n_order; k++) - { f_arg_[k].resize(nr, nr); - f_result_[k].resize(nr, nr); - } - } - // ------------------------------------------------------------------- - // unpack tx into f_arg_ - for(size_t k = 0; k < n_order; k++) - { size_t index = 1; - // unpack arg values for this order - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j <= i; j++) - { f_arg_[k](i, j) = tx[ index * n_order + k ]; - f_arg_[k](j, i) = f_arg_[k](i, j); - index++; - } - } - } - // ------------------------------------------------------------------- - // result for each order - // (we could avoid recalculting f_result_[k] for k=0,...,p-1) - // - Eigen::LLT cholesky(f_arg_[0]); - f_result_[0] = cholesky.matrixL(); - lower_view L_0 = f_result_[0].template triangularView(); - for(size_t k = 1; k < n_order; k++) - { // initialize sum as A_k - matrix f_sum = f_arg_[k]; - // compute A_k - B_k - for(size_t ell = 1; ell < k; ell++) - f_sum -= f_result_[ell] * f_result_[k-ell].transpose(); - // compute L_0^{-1} * (A_k - B_k) * L_0^{-T} - matrix temp = L_0.template solve(f_sum); - temp = L_0.transpose().template solve(temp); - // divide the diagonal by 2 - for(size_t i = 0; i < nr; i++) - temp(i, i) /= scalar(2.0); - // L_k = L_0 * low[ L_0^{-1} * (A_k - B_k) * L_0^{-T} ] - lower_view view = temp.template triangularView(); - f_result_[k] = f_result_[0] * view; - } - // ------------------------------------------------------------------- - // pack result_ into ty - for(size_t k = 0; k < n_order; k++) - { size_t index = 0; - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j <= i; j++) - { ty[ index * n_order + k ] = f_result_[k](i, j); - index++; - } - } - } - // ------------------------------------------------------------------- - // check if we are computing vy - if( vx.size() == 0 ) - return true; - // ------------------------------------------------------------------ - // This is a very dumb algorithm that over estimates which - // elements of the inverse are variables (which is not efficient). - bool var = false; - for(size_t i = 0; i < ny; i++) - var |= vx[1 + i]; - for(size_t i = 0; i < ny; i++) - vy[i] = var; - // - return true; - } -/* %$$ -$subhead reverse$$ -$srccode%cpp% */ - // reverse mode routine called by CppAD - virtual bool reverse( - // highest order Taylor coefficient that we are computing derivative of - size_t q , - // forward mode Taylor coefficients for x variables - const CppAD::vector& tx , - // forward mode Taylor coefficients for y variables - const CppAD::vector& ty , - // upon return, derivative of G[ F[ {x_j^k} ] ] w.r.t {x_j^k} - CppAD::vector& px , - // derivative of G[ {y_i^k} ] w.r.t. {y_i^k} - const CppAD::vector& py - ) - { size_t n_order = q + 1; - size_t nr = size_t( CppAD::Integer( tx[ 0 * n_order + 0 ] ) ); -# ifndef NDEBUG - size_t ny = ( (nr + 1 ) * nr ) / 2; - size_t nx = 1 + ny; -# endif - // - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - assert( px.size() == tx.size() ); - assert( py.size() == ty.size() ); - // ------------------------------------------------------------------- - // make sure f_arg_ is large enough - assert( f_arg_.size() == f_result_.size() ); - // must have previous run forward with order >= n_order - assert( f_arg_.size() >= n_order ); - // ------------------------------------------------------------------- - // make sure r_arg_, r_result_ are large enough - assert( r_arg_.size() == r_result_.size() ); - if( r_arg_.size() < n_order ) - { r_arg_.resize(n_order); - r_result_.resize(n_order); - // - for(size_t k = 0; k < n_order; k++) - { r_arg_[k].resize(nr, nr); - r_result_[k].resize(nr, nr); - } - } - // ------------------------------------------------------------------- - // unpack tx into f_arg_ - for(size_t k = 0; k < n_order; k++) - { size_t index = 1; - // unpack arg values for this order - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j <= i; j++) - { f_arg_[k](i, j) = tx[ index * n_order + k ]; - f_arg_[k](j, i) = f_arg_[k](i, j); - index++; - } - } - } - // ------------------------------------------------------------------- - // unpack py into r_result_ - for(size_t k = 0; k < n_order; k++) - { r_result_[k] = matrix::Zero(nr, nr); - size_t index = 0; - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j <= i; j++) - { r_result_[k](i, j) = py[ index * n_order + k ]; - index++; - } - } - } - // ------------------------------------------------------------------- - // initialize r_arg_ as zero - for(size_t k = 0; k < n_order; k++) - r_arg_[k] = matrix::Zero(nr, nr); - // ------------------------------------------------------------------- - // matrix reverse mode calculation - lower_view L_0 = f_result_[0].template triangularView(); - // - for(size_t k1 = n_order; k1 > 1; k1--) - { size_t k = k1 - 1; - // - // L_0^T * bar{L}_k - matrix tmp1 = L_0.transpose() * r_result_[k]; - // - //low[ L_0^T * bar{L}_k ] - for(size_t i = 0; i < nr; i++) - tmp1(i, i) /= scalar(2.0); - matrix tmp2 = tmp1.template triangularView(); - // - // L_0^{-T} low[ L_0^T * bar{L}_k ] - tmp1 = L_0.transpose().template solve( tmp2 ); - // - // M_k = L_0^{-T} * low[ L_0^T * bar{L}_k ]^{T} L_0^{-1} - matrix M_k = L_0.transpose().template - solve( tmp1.transpose() ); - // - // remove L_k and compute bar{B}_k - matrix barB_k = scalar(0.5) * ( M_k + M_k.transpose() ); - r_arg_[k] += barB_k; - barB_k = scalar(-1.0) * barB_k; - // - // 2.0 * lower( bar{B}_k L_k ) - matrix temp = scalar(2.0) * barB_k * f_result_[k]; - temp = temp.template triangularView(); - // - // remove C_k - r_result_[0] += temp; - // - // remove B_k - for(size_t ell = 1; ell < k; ell++) - { // bar{L}_ell = 2 * lower( \bar{B}_k * L_{k-ell} ) - temp = scalar(2.0) * barB_k * f_result_[k-ell]; - r_result_[ell] += temp.template triangularView(); - } - } - // M_0 = L_0^{-T} * low[ L_0^T * bar{L}_0 ]^{T} L_0^{-1} - matrix M_0 = L_0.transpose() * r_result_[0]; - for(size_t i = 0; i < nr; i++) - M_0(i, i) /= scalar(2.0); - M_0 = M_0.template triangularView(); - M_0 = L_0.template solve( M_0 ); - M_0 = L_0.transpose().template solve( M_0 ); - // remove L_0 - r_arg_[0] += scalar(0.5) * ( M_0 + M_0.transpose() ); - // ------------------------------------------------------------------- - // pack r_arg into px - // note that only the lower triangle of barA_k is stored in px - for(size_t k = 0; k < n_order; k++) - { size_t index = 0; - px[ index * n_order + k ] = 0.0; - index++; - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j < i; j++) - { px[ index * n_order + k ] = 2.0 * r_arg_[k](i, j); - index++; - } - px[ index * n_order + k] = r_arg_[k](i, i); - index++; - } - } - // ------------------------------------------------------------------- - return true; - } -/* %$$ -$head End Class Definition$$ -$srccode%cpp% */ -}; // End of atomic_eigen_cholesky class - -} // END_EMPTY_NAMESPACE -/* %$$ -$end -*/ - - -# endif diff --git a/external/cppad/include/cppad/example/eigen_mat_inv.hpp b/external/cppad/include/cppad/example/eigen_mat_inv.hpp deleted file mode 100644 index eea9e251e..000000000 --- a/external/cppad/include/cppad/example/eigen_mat_inv.hpp +++ /dev/null @@ -1,396 +0,0 @@ -// $Id$ -# ifndef CPPAD_EXAMPLE_EIGEN_MAT_INV_HPP -# define CPPAD_EXAMPLE_EIGEN_MAT_INV_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin atomic_eigen_mat_inv.hpp$$ -$spell - Eigen - Taylor -$$ - -$section Atomic Eigen Matrix Inversion Class$$ - -$head Purpose$$ -Construct an atomic operation that computes the matrix inverse -$latex R = A^{-1}$$ -for any positive integer $latex p$$ -and invertible matrix $latex A \in \B{R}^{p \times p}$$. - -$head Matrix Dimensions$$ -This example puts the matrix dimension $latex p$$ -in the atomic function arguments, -instead of the $cref/constructor/atomic_ctor/$$, -so it can be different for different calls to the atomic function. - -$head Theory$$ - -$subhead Forward$$ -The zero order forward mode Taylor coefficient is give by -$latex \[ - R_0 = A_0^{-1} -\]$$ -For $latex k = 1 , \ldots$$, -the $th k$$ order Taylor coefficient of $latex A R$$ is given by -$latex \[ - 0 = \sum_{\ell=0}^k A_\ell R_{k-\ell} -\] $$ -Solving for $latex R_k$$ in terms of the coefficients -for $latex A$$ and the lower order coefficients for $latex R$$ we have -$latex \[ - R_k = - R_0 \left( \sum_{\ell=1}^k A_\ell R_{k-\ell} \right) -\] $$ -Furthermore, once we have $latex R_k$$ we can compute the sum using -$latex \[ - A_0 R_k = - \left( \sum_{\ell=1}^k A_\ell R_{k-\ell} \right) -\] $$ - - -$subhead Product of Three Matrices$$ -Suppose $latex \bar{E}$$ is the derivative of the -scalar value function $latex s(E)$$ with respect to $latex E$$; i.e., -$latex \[ - \bar{E}_{i,j} = \frac{ \partial s } { \partial E_{i,j} } -\] $$ -Also suppose that $latex t$$ is a scalar valued argument and -$latex \[ - E(t) = B(t) C(t) D(t) -\] $$ -It follows that -$latex \[ - E'(t) = B'(t) C(t) D(t) + B(t) C'(t) D(t) + B(t) C(t) D'(t) -\] $$ - -$latex \[ - (s \circ E)'(t) - = - \R{tr} [ \bar{E}^\R{T} E'(t) ] -\] $$ -$latex \[ - = - \R{tr} [ \bar{E}^\R{T} B'(t) C(t) D(t) ] + - \R{tr} [ \bar{E}^\R{T} B(t) C'(t) D(t) ] + - \R{tr} [ \bar{E}^\R{T} B(t) C(t) D'(t) ] -\] $$ -$latex \[ - = - \R{tr} [ B(t) D(t) \bar{E}^\R{T} B'(t) ] + - \R{tr} [ D(t) \bar{E}^\R{T} B(t) C'(t) ] + - \R{tr} [ \bar{E}^\R{T} B(t) C(t) D'(t) ] -\] $$ -$latex \[ - \bar{B} = \bar{E} (C D)^\R{T} \W{,} - \bar{C} = B^\R{T} \bar{E} D^\R{T} \W{,} - \bar{D} = (B C)^\R{T} \bar{E} -\] $$ - -$subhead Reverse$$ -For $latex k > 0$$, reverse mode -eliminates $latex R_k$$ and expresses the function values -$latex s$$ in terms of the coefficients of $latex A$$ -and the lower order coefficients of $latex R$$. -The effect on $latex \bar{R}_0$$ -(of eliminating $latex R_k$$) is -$latex \[ -\bar{R}_0 -= \bar{R}_0 - \bar{R}_k \left( \sum_{\ell=1}^k A_\ell R_{k-\ell} \right)^\R{T} -= \bar{R}_0 + \bar{R}_k ( A_0 R_k )^\R{T} -\] $$ -For $latex \ell = 1 , \ldots , k$$, -the effect on $latex \bar{R}_{k-\ell}$$ and $latex A_\ell$$ -(of eliminating $latex R_k$$) is -$latex \[ -\bar{A}_\ell = \bar{A}_\ell - R_0^\R{T} \bar{R}_k R_{k-\ell}^\R{T} -\] $$ -$latex \[ -\bar{R}_{k-\ell} = \bar{R}_{k-\ell} - ( R_0 A_\ell )^\R{T} \bar{R}_k -\] $$ -We note that -$latex \[ - R_0 '(t) A_0 (t) + R_0 (t) A_0 '(t) = 0 -\] $$ -$latex \[ - R_0 '(t) = - R_0 (t) A_0 '(t) R_0 (t) -\] $$ -The reverse mode formula that eliminates $latex R_0$$ is -$latex \[ - \bar{A}_0 - = \bar{A}_0 - R_0^\R{T} \bar{R}_0 R_0^\R{T} -\]$$ - -$nospell - -$head Start Class Definition$$ -$srccode%cpp% */ -# include -# include -# include - - - -/* %$$ -$head Public$$ - -$subhead Types$$ -$srccode%cpp% */ -namespace { // BEGIN_EMPTY_NAMESPACE - -template -class atomic_eigen_mat_inv : public CppAD::atomic_base { -public: - // ----------------------------------------------------------- - // type of elements during calculation of derivatives - typedef Base scalar; - // type of elements during taping - typedef CppAD::AD ad_scalar; - // type of matrix during calculation of derivatives - typedef Eigen::Matrix< - scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> matrix; - // type of matrix during taping - typedef Eigen::Matrix< - ad_scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ad_matrix; -/* %$$ -$subhead Constructor$$ -$srccode%cpp% */ - // constructor - atomic_eigen_mat_inv(void) : CppAD::atomic_base( - "atom_eigen_mat_inv" , - CppAD::atomic_base::set_sparsity_enum - ) - { } -/* %$$ -$subhead op$$ -$srccode%cpp% */ - // use atomic operation to invert an AD matrix - ad_matrix op(const ad_matrix& arg) - { size_t nr = size_t( arg.rows() ); - size_t ny = nr * nr; - size_t nx = 1 + ny; - assert( nr == size_t( arg.cols() ) ); - // ------------------------------------------------------------------- - // packed version of arg - CPPAD_TESTVECTOR(ad_scalar) packed_arg(nx); - packed_arg[0] = ad_scalar( nr ); - for(size_t i = 0; i < ny; i++) - packed_arg[1 + i] = arg.data()[i]; - // ------------------------------------------------------------------- - // packed version of result = arg^{-1}. - // This is an atomic_base function call that CppAD uses to - // store the atomic operation on the tape. - CPPAD_TESTVECTOR(ad_scalar) packed_result(ny); - (*this)(packed_arg, packed_result); - // ------------------------------------------------------------------- - // unpack result matrix - ad_matrix result(nr, nr); - for(size_t i = 0; i < ny; i++) - result.data()[i] = packed_result[i]; - return result; - } - /* %$$ -$head Private$$ - -$subhead Variables$$ -$srccode%cpp% */ -private: - // ------------------------------------------------------------- - // one forward mode vector of matrices for argument and result - CppAD::vector f_arg_, f_result_; - // one reverse mode vector of matrices for argument and result - CppAD::vector r_arg_, r_result_; - // ------------------------------------------------------------- -/* %$$ -$subhead forward$$ -$srccode%cpp% */ - // forward mode routine called by CppAD - virtual bool forward( - // lowest order Taylor coefficient we are evaluating - size_t p , - // highest order Taylor coefficient we are evaluating - size_t q , - // which components of x are variables - const CppAD::vector& vx , - // which components of y are variables - CppAD::vector& vy , - // tx [ j * (q+1) + k ] is x_j^k - const CppAD::vector& tx , - // ty [ i * (q+1) + k ] is y_i^k - CppAD::vector& ty - ) - { size_t n_order = q + 1; - size_t nr = size_t( CppAD::Integer( tx[ 0 * n_order + 0 ] ) ); - size_t ny = nr * nr; -# ifndef NDEBUG - size_t nx = 1 + ny; -# endif - assert( vx.size() == 0 || nx == vx.size() ); - assert( vx.size() == 0 || ny == vy.size() ); - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - // - // ------------------------------------------------------------------- - // make sure f_arg_ and f_result_ are large enough - assert( f_arg_.size() == f_result_.size() ); - if( f_arg_.size() < n_order ) - { f_arg_.resize(n_order); - f_result_.resize(n_order); - // - for(size_t k = 0; k < n_order; k++) - { f_arg_[k].resize(nr, nr); - f_result_[k].resize(nr, nr); - } - } - // ------------------------------------------------------------------- - // unpack tx into f_arg_ - for(size_t k = 0; k < n_order; k++) - { // unpack arg values for this order - for(size_t i = 0; i < ny; i++) - f_arg_[k].data()[i] = tx[ (1 + i) * n_order + k ]; - } - // ------------------------------------------------------------------- - // result for each order - // (we could avoid recalculting f_result_[k] for k=0,...,p-1) - // - f_result_[0] = f_arg_[0].inverse(); - for(size_t k = 1; k < n_order; k++) - { // initialize sum - matrix f_sum = matrix::Zero(nr, nr); - // compute sum - for(size_t ell = 1; ell <= k; ell++) - f_sum -= f_arg_[ell] * f_result_[k-ell]; - // result_[k] = arg_[0]^{-1} * sum_ - f_result_[k] = f_result_[0] * f_sum; - } - // ------------------------------------------------------------------- - // pack result_ into ty - for(size_t k = 0; k < n_order; k++) - { for(size_t i = 0; i < ny; i++) - ty[ i * n_order + k ] = f_result_[k].data()[i]; - } - // ------------------------------------------------------------------- - // check if we are computing vy - if( vx.size() == 0 ) - return true; - // ------------------------------------------------------------------ - // This is a very dumb algorithm that over estimates which - // elements of the inverse are variables (which is not efficient). - bool var = false; - for(size_t i = 0; i < ny; i++) - var |= vx[1 + i]; - for(size_t i = 0; i < ny; i++) - vy[i] = var; - return true; - } -/* %$$ -$subhead reverse$$ -$srccode%cpp% */ - // reverse mode routine called by CppAD - virtual bool reverse( - // highest order Taylor coefficient that we are computing derivative of - size_t q , - // forward mode Taylor coefficients for x variables - const CppAD::vector& tx , - // forward mode Taylor coefficients for y variables - const CppAD::vector& ty , - // upon return, derivative of G[ F[ {x_j^k} ] ] w.r.t {x_j^k} - CppAD::vector& px , - // derivative of G[ {y_i^k} ] w.r.t. {y_i^k} - const CppAD::vector& py - ) - { size_t n_order = q + 1; - size_t nr = size_t( CppAD::Integer( tx[ 0 * n_order + 0 ] ) ); - size_t ny = nr * nr; -# ifndef NDEBUG - size_t nx = 1 + ny; -# endif - // - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - assert( px.size() == tx.size() ); - assert( py.size() == ty.size() ); - // ------------------------------------------------------------------- - // make sure f_arg_ is large enough - assert( f_arg_.size() == f_result_.size() ); - // must have previous run forward with order >= n_order - assert( f_arg_.size() >= n_order ); - // ------------------------------------------------------------------- - // make sure r_arg_, r_result_ are large enough - assert( r_arg_.size() == r_result_.size() ); - if( r_arg_.size() < n_order ) - { r_arg_.resize(n_order); - r_result_.resize(n_order); - // - for(size_t k = 0; k < n_order; k++) - { r_arg_[k].resize(nr, nr); - r_result_[k].resize(nr, nr); - } - } - // ------------------------------------------------------------------- - // unpack tx into f_arg_ - for(size_t k = 0; k < n_order; k++) - { // unpack arg values for this order - for(size_t i = 0; i < ny; i++) - f_arg_[k].data()[i] = tx[ (1 + i) * n_order + k ]; - } - // ------------------------------------------------------------------- - // unpack py into r_result_ - for(size_t k = 0; k < n_order; k++) - { for(size_t i = 0; i < ny; i++) - r_result_[k].data()[i] = py[ i * n_order + k ]; - } - // ------------------------------------------------------------------- - // initialize r_arg_ as zero - for(size_t k = 0; k < n_order; k++) - r_arg_[k] = matrix::Zero(nr, nr); - // ------------------------------------------------------------------- - // matrix reverse mode calculation - // - for(size_t k1 = n_order; k1 > 1; k1--) - { size_t k = k1 - 1; - // bar{R}_0 = bar{R}_0 + bar{R}_k (A_0 R_k)^T - r_result_[0] += - r_result_[k] * f_result_[k].transpose() * f_arg_[0].transpose(); - // - for(size_t ell = 1; ell <= k; ell++) - { // bar{A}_l = bar{A}_l - R_0^T bar{R}_k R_{k-l}^T - r_arg_[ell] -= f_result_[0].transpose() - * r_result_[k] * f_result_[k-ell].transpose(); - // bar{R}_{k-l} = bar{R}_{k-1} - (R_0 A_l)^T bar{R}_k - r_result_[k-ell] -= f_arg_[ell].transpose() - * f_result_[0].transpose() * r_result_[k]; - } - } - r_arg_[0] -= - f_result_[0].transpose() * r_result_[0] * f_result_[0].transpose(); - // ------------------------------------------------------------------- - // pack r_arg into px - for(size_t k = 0; k < n_order; k++) - { for(size_t i = 0; i < ny; i++) - px[ (1 + i) * n_order + k ] = r_arg_[k].data()[i]; - } - // - return true; - } -/* %$$ -$head End Class Definition$$ -$srccode%cpp% */ -}; // End of atomic_eigen_mat_inv class - -} // END_EMPTY_NAMESPACE -/* %$$ -$$ $comment end nospell$$ -$end -*/ - - -# endif diff --git a/external/cppad/include/cppad/example/eigen_mat_mul.hpp b/external/cppad/include/cppad/example/eigen_mat_mul.hpp deleted file mode 100644 index 2fa42910d..000000000 --- a/external/cppad/include/cppad/example/eigen_mat_mul.hpp +++ /dev/null @@ -1,656 +0,0 @@ -# ifndef CPPAD_EXAMPLE_EIGEN_MAT_MUL_HPP -# define CPPAD_EXAMPLE_EIGEN_MAT_MUL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin atomic_eigen_mat_mul.hpp$$ -$spell - Eigen - Taylor - nr - nc -$$ - -$section Atomic Eigen Matrix Multiply Class$$ - -$head See Also$$ -$cref atomic_mat_mul.hpp$$ - -$head Purpose$$ -Construct an atomic operation that computes the matrix product, -$latex R = A \times B$$ -for any positive integers $latex r$$, $latex m$$, $latex c$$, -and any $latex A \in \B{R}^{r \times m}$$, -$latex B \in \B{R}^{m \times c}$$. - -$head Matrix Dimensions$$ -This example puts the matrix dimensions in the atomic function arguments, -instead of the $cref/constructor/atomic_ctor/$$, so that they can -be different for different calls to the atomic function. -These dimensions are: -$table -$icode nr_left$$ - $cnext number of rows in the left matrix; i.e, $latex r$$ $rend -$icode n_middle$$ - $cnext rows in the left matrix and columns in right; i.e, $latex m$$ $rend -$icode nc_right$$ - $cnext number of columns in the right matrix; i.e., $latex c$$ -$tend - -$head Theory$$ - -$subhead Forward$$ -For $latex k = 0 , \ldots $$, the $th k$$ order Taylor coefficient -$latex R_k$$ is given by -$latex \[ - R_k = \sum_{\ell = 0}^{k} A_\ell B_{k-\ell} -\] $$ - -$subhead Product of Two Matrices$$ -Suppose $latex \bar{E}$$ is the derivative of the -scalar value function $latex s(E)$$ with respect to $latex E$$; i.e., -$latex \[ - \bar{E}_{i,j} = \frac{ \partial s } { \partial E_{i,j} } -\] $$ -Also suppose that $latex t$$ is a scalar valued argument and -$latex \[ - E(t) = C(t) D(t) -\] $$ -It follows that -$latex \[ - E'(t) = C'(t) D(t) + C(t) D'(t) -\] $$ - -$latex \[ - (s \circ E)'(t) - = - \R{tr} [ \bar{E}^\R{T} E'(t) ] -\] $$ -$latex \[ - = - \R{tr} [ \bar{E}^\R{T} C'(t) D(t) ] + - \R{tr} [ \bar{E}^\R{T} C(t) D'(t) ] -\] $$ -$latex \[ - = - \R{tr} [ D(t) \bar{E}^\R{T} C'(t) ] + - \R{tr} [ \bar{E}^\R{T} C(t) D'(t) ] -\] $$ -$latex \[ - \bar{C} = \bar{E} D^\R{T} \W{,} - \bar{D} = C^\R{T} \bar{E} -\] $$ - -$subhead Reverse$$ -Reverse mode eliminates $latex R_k$$ as follows: -for $latex \ell = 0, \ldots , k-1$$, -$latex \[ -\bar{A}_\ell = \bar{A}_\ell + \bar{R}_k B_{k-\ell}^\R{T} -\] $$ -$latex \[ -\bar{B}_{k-\ell} = \bar{B}_{k-\ell} + A_\ell^\R{T} \bar{R}_k -\] $$ - - -$nospell - -$head Start Class Definition$$ -$srccode%cpp% */ -# include -# include - - -/* %$$ -$head Public$$ - -$subhead Types$$ -$srccode%cpp% */ -namespace { // BEGIN_EMPTY_NAMESPACE - -template -class atomic_eigen_mat_mul : public CppAD::atomic_base { -public: - // ----------------------------------------------------------- - // type of elements during calculation of derivatives - typedef Base scalar; - // type of elements during taping - typedef CppAD::AD ad_scalar; - // type of matrix during calculation of derivatives - typedef Eigen::Matrix< - scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> matrix; - // type of matrix during taping - typedef Eigen::Matrix< - ad_scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ad_matrix; -/* %$$ -$subhead Constructor$$ -$srccode%cpp% */ - // constructor - atomic_eigen_mat_mul(void) : CppAD::atomic_base( - "atom_eigen_mat_mul" , - CppAD::atomic_base::set_sparsity_enum - ) - { } -/* %$$ -$subhead op$$ -$srccode%cpp% */ - // use atomic operation to multiply two AD matrices - ad_matrix op( - const ad_matrix& left , - const ad_matrix& right ) - { size_t nr_left = size_t( left.rows() ); - size_t n_middle = size_t( left.cols() ); - size_t nc_right = size_t( right.cols() ); - assert( n_middle == size_t( right.rows() ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; - size_t n_left = nr_left * n_middle; - size_t n_right = n_middle * nc_right; - size_t n_result = nr_left * nc_right; - // - assert( 3 + n_left + n_right == nx ); - assert( n_result == ny ); - // ----------------------------------------------------------------- - // packed version of left and right - CPPAD_TESTVECTOR(ad_scalar) packed_arg(nx); - // - packed_arg[0] = ad_scalar( nr_left ); - packed_arg[1] = ad_scalar( n_middle ); - packed_arg[2] = ad_scalar( nc_right ); - for(size_t i = 0; i < n_left; i++) - packed_arg[3 + i] = left.data()[i]; - for(size_t i = 0; i < n_right; i++) - packed_arg[ 3 + n_left + i ] = right.data()[i]; - // ------------------------------------------------------------------ - // Packed version of result = left * right. - // This as an atomic_base funciton call that CppAD uses - // to store the atomic operation on the tape. - CPPAD_TESTVECTOR(ad_scalar) packed_result(ny); - (*this)(packed_arg, packed_result); - // ------------------------------------------------------------------ - // unpack result matrix - ad_matrix result(nr_left, nc_right); - for(size_t i = 0; i < n_result; i++) - result.data()[i] = packed_result[ i ]; - // - return result; - } -/* %$$ -$head Private$$ - -$subhead Variables$$ -$srccode%cpp% */ -private: - // ------------------------------------------------------------- - // one forward mode vector of matrices for left, right, and result - CppAD::vector f_left_, f_right_, f_result_; - // one reverse mode vector of matrices for left, right, and result - CppAD::vector r_left_, r_right_, r_result_; - // ------------------------------------------------------------- -/* %$$ -$subhead forward$$ -$srccode%cpp% */ - // forward mode routine called by CppAD - virtual bool forward( - // lowest order Taylor coefficient we are evaluating - size_t p , - // highest order Taylor coefficient we are evaluating - size_t q , - // which components of x are variables - const CppAD::vector& vx , - // which components of y are variables - CppAD::vector& vy , - // tx [ 3 + j * (q+1) + k ] is x_j^k - const CppAD::vector& tx , - // ty [ i * (q+1) + k ] is y_i^k - CppAD::vector& ty - ) - { size_t n_order = q + 1; - size_t nr_left = size_t( CppAD::Integer( tx[ 0 * n_order + 0 ] ) ); - size_t n_middle = size_t( CppAD::Integer( tx[ 1 * n_order + 0 ] ) ); - size_t nc_right = size_t( CppAD::Integer( tx[ 2 * n_order + 0 ] ) ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - // - assert( vx.size() == 0 || nx == vx.size() ); - assert( vx.size() == 0 || ny == vy.size() ); - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - // - size_t n_left = nr_left * n_middle; - size_t n_right = n_middle * nc_right; - size_t n_result = nr_left * nc_right; - assert( 3 + n_left + n_right == nx ); - assert( n_result == ny ); - // - // ------------------------------------------------------------------- - // make sure f_left_, f_right_, and f_result_ are large enough - assert( f_left_.size() == f_right_.size() ); - assert( f_left_.size() == f_result_.size() ); - if( f_left_.size() < n_order ) - { f_left_.resize(n_order); - f_right_.resize(n_order); - f_result_.resize(n_order); - // - for(size_t k = 0; k < n_order; k++) - { f_left_[k].resize(nr_left, n_middle); - f_right_[k].resize(n_middle, nc_right); - f_result_[k].resize(nr_left, nc_right); - } - } - // ------------------------------------------------------------------- - // unpack tx into f_left and f_right - for(size_t k = 0; k < n_order; k++) - { // unpack left values for this order - for(size_t i = 0; i < n_left; i++) - f_left_[k].data()[i] = tx[ (3 + i) * n_order + k ]; - // - // unpack right values for this order - for(size_t i = 0; i < n_right; i++) - f_right_[k].data()[i] = tx[ ( 3 + n_left + i) * n_order + k ]; - } - // ------------------------------------------------------------------- - // result for each order - // (we could avoid recalculting f_result_[k] for k=0,...,p-1) - for(size_t k = 0; k < n_order; k++) - { // result[k] = sum_ell left[ell] * right[k-ell] - f_result_[k] = matrix::Zero(nr_left, nc_right); - for(size_t ell = 0; ell <= k; ell++) - f_result_[k] += f_left_[ell] * f_right_[k-ell]; - } - // ------------------------------------------------------------------- - // pack result_ into ty - for(size_t k = 0; k < n_order; k++) - { for(size_t i = 0; i < n_result; i++) - ty[ i * n_order + k ] = f_result_[k].data()[i]; - } - // ------------------------------------------------------------------ - // check if we are computing vy - if( vx.size() == 0 ) - return true; - // ------------------------------------------------------------------ - // compute variable information for y; i.e., vy - // (note that the constant zero times a variable is a constant) - scalar zero(0.0); - assert( n_order == 1 ); - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { bool var = false; - for(size_t ell = 0; ell < n_middle; ell++) - { // left information - size_t index = 3 + i * n_middle + ell; - bool var_left = vx[index]; - bool nz_left = var_left | (f_left_[0](i, ell) != zero); - // right information - index = 3 + n_left + ell * nc_right + j; - bool var_right = vx[index]; - bool nz_right = var_right | (f_right_[0](ell, j) != zero); - // effect of result - var |= var_left & nz_right; - var |= nz_left & var_right; - } - size_t index = i * nc_right + j; - vy[index] = var; - } - } - return true; - } -/* %$$ -$subhead reverse$$ -$srccode%cpp% */ - // reverse mode routine called by CppAD - virtual bool reverse( - // highest order Taylor coefficient that we are computing derivative of - size_t q , - // forward mode Taylor coefficients for x variables - const CppAD::vector& tx , - // forward mode Taylor coefficients for y variables - const CppAD::vector& ty , - // upon return, derivative of G[ F[ {x_j^k} ] ] w.r.t {x_j^k} - CppAD::vector& px , - // derivative of G[ {y_i^k} ] w.r.t. {y_i^k} - const CppAD::vector& py - ) - { size_t n_order = q + 1; - size_t nr_left = size_t( CppAD::Integer( tx[ 0 * n_order + 0 ] ) ); - size_t n_middle = size_t( CppAD::Integer( tx[ 1 * n_order + 0 ] ) ); - size_t nc_right = size_t( CppAD::Integer( tx[ 2 * n_order + 0 ] ) ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - // - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - assert( px.size() == tx.size() ); - assert( py.size() == ty.size() ); - // - size_t n_left = nr_left * n_middle; - size_t n_right = n_middle * nc_right; - size_t n_result = nr_left * nc_right; - assert( 3 + n_left + n_right == nx ); - assert( n_result == ny ); - // ------------------------------------------------------------------- - // make sure f_left_, f_right_ are large enough - assert( f_left_.size() == f_right_.size() ); - assert( f_left_.size() == f_result_.size() ); - // must have previous run forward with order >= n_order - assert( f_left_.size() >= n_order ); - // ------------------------------------------------------------------- - // make sure r_left_, r_right_, and r_result_ are large enough - assert( r_left_.size() == r_right_.size() ); - assert( r_left_.size() == r_result_.size() ); - if( r_left_.size() < n_order ) - { r_left_.resize(n_order); - r_right_.resize(n_order); - r_result_.resize(n_order); - // - for(size_t k = 0; k < n_order; k++) - { r_left_[k].resize(nr_left, n_middle); - r_right_[k].resize(n_middle, nc_right); - r_result_[k].resize(nr_left, nc_right); - } - } - // ------------------------------------------------------------------- - // unpack tx into f_left and f_right - for(size_t k = 0; k < n_order; k++) - { // unpack left values for this order - for(size_t i = 0; i < n_left; i++) - f_left_[k].data()[i] = tx[ (3 + i) * n_order + k ]; - // - // unpack right values for this order - for(size_t i = 0; i < n_right; i++) - f_right_[k].data()[i] = tx[ (3 + n_left + i) * n_order + k ]; - } - // ------------------------------------------------------------------- - // unpack py into r_result_ - for(size_t k = 0; k < n_order; k++) - { for(size_t i = 0; i < n_result; i++) - r_result_[k].data()[i] = py[ i * n_order + k ]; - } - // ------------------------------------------------------------------- - // initialize r_left_ and r_right_ as zero - for(size_t k = 0; k < n_order; k++) - { r_left_[k] = matrix::Zero(nr_left, n_middle); - r_right_[k] = matrix::Zero(n_middle, nc_right); - } - // ------------------------------------------------------------------- - // matrix reverse mode calculation - for(size_t k1 = n_order; k1 > 0; k1--) - { size_t k = k1 - 1; - for(size_t ell = 0; ell <= k; ell++) - { // nr x nm = nr x nc * nc * nm - r_left_[ell] += r_result_[k] * f_right_[k-ell].transpose(); - // nm x nc = nm x nr * nr * nc - r_right_[k-ell] += f_left_[ell].transpose() * r_result_[k]; - } - } - // ------------------------------------------------------------------- - // pack r_left and r_right int px - for(size_t k = 0; k < n_order; k++) - { // dimensions are integer constants - px[ 0 * n_order + k ] = 0.0; - px[ 1 * n_order + k ] = 0.0; - px[ 2 * n_order + k ] = 0.0; - // - // pack left values for this order - for(size_t i = 0; i < n_left; i++) - px[ (3 + i) * n_order + k ] = r_left_[k].data()[i]; - // - // pack right values for this order - for(size_t i = 0; i < n_right; i++) - px[ (3 + i + n_left) * n_order + k] = r_right_[k].data()[i]; - } - // - return true; - } -/* %$$ -$subhead for_sparse_jac$$ -$srccode%cpp% */ - // forward Jacobian sparsity routine called by CppAD - virtual bool for_sparse_jac( - // number of columns in the matrix R - size_t q , - // sparsity pattern for the matrix R - const CppAD::vector< std::set >& r , - // sparsity pattern for the matrix S = f'(x) * R - CppAD::vector< std::set >& s , - const CppAD::vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - // - assert( nx == r.size() ); - assert( ny == s.size() ); - // - size_t n_left = nr_left * n_middle; - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { // pack index for entry (i, j) in result - size_t i_result = i * nc_right + j; - s[i_result].clear(); - for(size_t ell = 0; ell < n_middle; ell++) - { // pack index for entry (i, ell) in left - size_t i_left = 3 + i * n_middle + ell; - // pack index for entry (ell, j) in right - size_t i_right = 3 + n_left + ell * nc_right + j; - // check if result of for this product is alwasy zero - // note that x is nan for commponents that are variables - bool zero = x[i_left] == Base(0.0) || x[i_right] == Base(0); - if( ! zero ) - { s[i_result] = - CppAD::set_union(s[i_result], r[i_left] ); - s[i_result] = - CppAD::set_union(s[i_result], r[i_right] ); - } - } - } - } - return true; - } -/* %$$ -$subhead rev_sparse_jac$$ -$srccode%cpp% */ - // reverse Jacobian sparsity routine called by CppAD - virtual bool rev_sparse_jac( - // number of columns in the matrix R^T - size_t q , - // sparsity pattern for the matrix R^T - const CppAD::vector< std::set >& rt , - // sparsoity pattern for the matrix S^T = f'(x)^T * R^T - CppAD::vector< std::set >& st , - const CppAD::vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - // - assert( nx == st.size() ); - assert( ny == rt.size() ); - // - // initialize S^T as empty - for(size_t i = 0; i < nx; i++) - st[i].clear(); - - // sparsity for S(x)^T = f'(x)^T * R^T - size_t n_left = nr_left * n_middle; - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { // pack index for entry (i, j) in result - size_t i_result = i * nc_right + j; - st[i_result].clear(); - for(size_t ell = 0; ell < n_middle; ell++) - { // pack index for entry (i, ell) in left - size_t i_left = 3 + i * n_middle + ell; - // pack index for entry (ell, j) in right - size_t i_right = 3 + n_left + ell * nc_right + j; - // - st[i_left] = CppAD::set_union(st[i_left], rt[i_result]); - st[i_right] = CppAD::set_union(st[i_right], rt[i_result]); - } - } - } - return true; - } -/* %$$ -$subhead for_sparse_hes$$ -$srccode%cpp% */ - virtual bool for_sparse_hes( - // which components of x are variables for this call - const CppAD::vector& vx, - // sparsity pattern for the diagonal of R - const CppAD::vector& r , - // sparsity pattern for the vector S - const CppAD::vector& s , - // sparsity patternfor the Hessian H(x) - CppAD::vector< std::set >& h , - const CppAD::vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - // - assert( vx.size() == nx ); - assert( r.size() == nx ); - assert( s.size() == ny ); - assert( h.size() == nx ); - // - // initilize h as empty - for(size_t i = 0; i < nx; i++) - h[i].clear(); - // - size_t n_left = nr_left * n_middle; - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { // pack index for entry (i, j) in result - size_t i_result = i * nc_right + j; - if( s[i_result] ) - { for(size_t ell = 0; ell < n_middle; ell++) - { // pack index for entry (i, ell) in left - size_t i_left = 3 + i * n_middle + ell; - // pack index for entry (ell, j) in right - size_t i_right = 3 + n_left + ell * nc_right + j; - if( r[i_left] & r[i_right] ) - { h[i_left].insert(i_right); - h[i_right].insert(i_left); - } - } - } - } - } - return true; - } -/* %$$ -$subhead rev_sparse_hes$$ -$srccode%cpp% */ - // reverse Hessian sparsity routine called by CppAD - virtual bool rev_sparse_hes( - // which components of x are variables for this call - const CppAD::vector& vx, - // sparsity pattern for S(x) = g'[f(x)] - const CppAD::vector& s , - // sparsity pattern for d/dx g[f(x)] = S(x) * f'(x) - CppAD::vector& t , - // number of columns in R, U(x), and V(x) - size_t q , - // sparsity pattern for R - const CppAD::vector< std::set >& r , - // sparsity pattern for U(x) = g^{(2)} [ f(x) ] * f'(x) * R - const CppAD::vector< std::set >& u , - // sparsity pattern for - // V(x) = f'(x)^T * U(x) + sum_{i=0}^{m-1} S_i(x) f_i^{(2)} (x) * R - CppAD::vector< std::set >& v , - // parameters as integers - const CppAD::vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - // - assert( vx.size() == nx ); - assert( s.size() == ny ); - assert( t.size() == nx ); - assert( r.size() == nx ); - assert( v.size() == nx ); - // - // initilaize return sparsity patterns as false - for(size_t j = 0; j < nx; j++) - { t[j] = false; - v[j].clear(); - } - // - size_t n_left = nr_left * n_middle; - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { // pack index for entry (i, j) in result - size_t i_result = i * nc_right + j; - for(size_t ell = 0; ell < n_middle; ell++) - { // pack index for entry (i, ell) in left - size_t i_left = 3 + i * n_middle + ell; - // pack index for entry (ell, j) in right - size_t i_right = 3 + n_left + ell * nc_right + j; - // - // back propagate T(x) = S(x) * f'(x). - t[i_left] |= bool( s[i_result] ); - t[i_right] |= bool( s[i_result] ); - // - // V(x) = f'(x)^T * U(x) + sum_i S_i(x) * f_i''(x) * R - // U(x) = g''[ f(x) ] * f'(x) * R - // S_i(x) = g_i'[ f(x) ] - // - // back propagate f'(x)^T * U(x) - v[i_left] = CppAD::set_union(v[i_left], u[i_result] ); - v[i_right] = CppAD::set_union(v[i_right], u[i_result] ); - // - // back propagate S_i(x) * f_i''(x) * R - // (here is where we use vx to check for cross terms) - if( s[i_result] & vx[i_left] & vx[i_right] ) - { v[i_left] = CppAD::set_union(v[i_left], r[i_right] ); - v[i_right] = CppAD::set_union(v[i_right], r[i_left] ); - } - } - } - } - return true; - } -/* %$$ -$head End Class Definition$$ -$srccode%cpp% */ -}; // End of atomic_eigen_mat_mul class - -} // END_EMPTY_NAMESPACE -/* %$$ -$$ $comment end nospell$$ -$end -*/ - - -# endif diff --git a/external/cppad/include/cppad/example/mat_mul.hpp b/external/cppad/include/cppad/example/mat_mul.hpp deleted file mode 100644 index e6f50cb59..000000000 --- a/external/cppad/include/cppad/example/mat_mul.hpp +++ /dev/null @@ -1,678 +0,0 @@ -// $Id$ -# ifndef CPPAD_EXAMPLE_MAT_MUL_HPP -# define CPPAD_EXAMPLE_MAT_MUL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin atomic_mat_mul.hpp$$ -$spell - Taylor - ty - px - CppAD - jac - hes - nr - nc -$$ - -$section Matrix Multiply as an Atomic Operation$$ - -$head See Also$$ -$cref atomic_eigen_mat_mul.hpp$$ - -$head Matrix Dimensions$$ -This example puts the matrix dimensions in the atomic function arguments, -instead of the $cref/constructor/atomic_ctor/$$, so that they can -be different for different calls to the atomic function. -These dimensions are: -$table -$icode nr_left$$ $cnext number of rows in the left matrix $rend -$icode n_middle$$ $cnext rows in the left matrix and columns in right $rend -$icode nc_right$$ $cnext number of columns in the right matrix -$tend - -$head Start Class Definition$$ -$srccode%cpp% */ -# include -namespace { // Begin empty namespace -using CppAD::vector; -// -using CppAD::set_union; -// -// matrix result = left * right -class atomic_mat_mul : public CppAD::atomic_base { -/* %$$ -$head Constructor$$ -$srccode%cpp% */ -public: - // --------------------------------------------------------------------- - // constructor - atomic_mat_mul(void) : CppAD::atomic_base("mat_mul") - { } -private: -/* %$$ -$head Left Operand Element Index$$ -Index in the Taylor coefficient matrix $icode tx$$ of a left matrix element. -$srccode%cpp% */ - size_t left( - size_t i , // left matrix row index - size_t j , // left matrix column index - size_t k , // Taylor coeffocient order - size_t nk , // number of Taylor coefficients in tx - size_t nr_left , // rows in left matrix - size_t n_middle , // rows in left and columns in right - size_t nc_right ) // columns in right matrix - { assert( i < nr_left ); - assert( j < n_middle ); - return (3 + i * n_middle + j) * nk + k; - } -/* %$$ -$head Right Operand Element Index$$ -Index in the Taylor coefficient matrix $icode tx$$ of a right matrix element. -$srccode%cpp% */ - size_t right( - size_t i , // right matrix row index - size_t j , // right matrix column index - size_t k , // Taylor coeffocient order - size_t nk , // number of Taylor coefficients in tx - size_t nr_left , // rows in left matrix - size_t n_middle , // rows in left and columns in right - size_t nc_right ) // columns in right matrix - { assert( i < n_middle ); - assert( j < nc_right ); - size_t offset = 3 + nr_left * n_middle; - return (offset + i * nc_right + j) * nk + k; - } -/* %$$ -$head Result Element Index$$ -Index in the Taylor coefficient matrix $icode ty$$ of a result matrix element. -$srccode%cpp% */ - size_t result( - size_t i , // result matrix row index - size_t j , // result matrix column index - size_t k , // Taylor coeffocient order - size_t nk , // number of Taylor coefficients in ty - size_t nr_left , // rows in left matrix - size_t n_middle , // rows in left and columns in right - size_t nc_right ) // columns in right matrix - { assert( i < nr_left ); - assert( j < nc_right ); - return (i * nc_right + j) * nk + k; - } -/* %$$ -$head Forward Matrix Multiply$$ -Forward mode multiply Taylor coefficients in $icode tx$$ and sum into -$icode ty$$ (for one pair of left and right orders) -$srccode%cpp% */ - void forward_multiply( - size_t k_left , // order for left coefficients - size_t k_right , // order for right coefficients - const vector& tx , // domain space Taylor coefficients - vector& ty , // range space Taylor coefficients - size_t nr_left , // rows in left matrix - size_t n_middle , // rows in left and columns in right - size_t nc_right ) // columns in right matrix - { - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t nk = tx.size() / nx; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; - assert( nk == ty.size() / ny ); -# endif - // - size_t k_result = k_left + k_right; - assert( k_result < nk ); - // - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { double sum = 0.0; - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k_left, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k_right, nk, nr_left, n_middle, nc_right - ); - sum += tx[i_left] * tx[i_right]; - } - size_t i_result = result( - i, j, k_result, nk, nr_left, n_middle, nc_right - ); - ty[i_result] += sum; - } - } - } -/* %$$ -$head Reverse Matrix Multiply$$ -Reverse mode partials of Taylor coefficients and sum into $icode px$$ -(for one pair of left and right orders) -$srccode%cpp% */ - void reverse_multiply( - size_t k_left , // order for left coefficients - size_t k_right , // order for right coefficients - const vector& tx , // domain space Taylor coefficients - const vector& ty , // range space Taylor coefficients - vector& px , // partials w.r.t. tx - const vector& py , // partials w.r.t. ty - size_t nr_left , // rows in left matrix - size_t n_middle , // rows in left and columns in right - size_t nc_right ) // columns in right matrix - { - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t nk = tx.size() / nx; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; - assert( nk == ty.size() / ny ); -# endif - assert( tx.size() == px.size() ); - assert( ty.size() == py.size() ); - // - size_t k_result = k_left + k_right; - assert( k_result < nk ); - // - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k_result, nk, nr_left, n_middle, nc_right - ); - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k_left, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k_right, nk, nr_left, n_middle, nc_right - ); - // sum += tx[i_left] * tx[i_right]; - px[i_left] += tx[i_right] * py[i_result]; - px[i_right] += tx[i_left] * py[i_result]; - } - } - } - return; - } -/* %$$ -$head forward$$ -Routine called by CppAD during $cref Forward$$ mode. -$srccode%cpp% */ - virtual bool forward( - size_t q , - size_t p , - const vector& vx , - vector& vy , - const vector& tx , - vector& ty - ) - { size_t n_order = p + 1; - size_t nr_left = size_t( tx[ 0 * n_order + 0 ] ); - size_t n_middle = size_t( tx[ 1 * n_order + 0 ] ); - size_t nc_right = size_t( tx[ 2 * n_order + 0 ] ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - assert( vx.size() == 0 || nx == vx.size() ); - assert( vx.size() == 0 || ny == vy.size() ); - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - size_t i, j, ell; - - // check if we are computing vy information - if( vx.size() > 0 ) - { size_t nk = 1; - size_t k = 0; - for(i = 0; i < nr_left; i++) - { for(j = 0; j < nc_right; j++) - { bool var = false; - for(ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - bool nz_left = vx[i_left] |(tx[i_left] != 0.); - bool nz_right = vx[i_right]|(tx[i_right] != 0.); - // if not multiplying by the constant zero - if( nz_left & nz_right ) - var |= bool(vx[i_left]) | bool(vx[i_right]); - } - size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - vy[i_result] = var; - } - } - } - - // initialize result as zero - size_t k; - for(i = 0; i < nr_left; i++) - { for(j = 0; j < nc_right; j++) - { for(k = q; k <= p; k++) - { size_t i_result = result( - i, j, k, n_order, nr_left, n_middle, nc_right - ); - ty[i_result] = 0.0; - } - } - } - for(k = q; k <= p; k++) - { // sum the produces that result in order k - for(ell = 0; ell <= k; ell++) - forward_multiply( - ell, k - ell, tx, ty, nr_left, n_middle, nc_right - ); - } - - // all orders are implented, so always return true - return true; - } -/* %$$ -$head reverse$$ -Routine called by CppAD during $cref Reverse$$ mode. -$srccode%cpp% */ - virtual bool reverse( - size_t p , - const vector& tx , - const vector& ty , - vector& px , - const vector& py - ) - { size_t n_order = p + 1; - size_t nr_left = size_t( tx[ 0 * n_order + 0 ] ); - size_t n_middle = size_t( tx[ 1 * n_order + 0 ] ); - size_t nc_right = size_t( tx[ 2 * n_order + 0 ] ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - assert( nx * n_order == tx.size() ); - assert( ny * n_order == ty.size() ); - assert( px.size() == tx.size() ); - assert( py.size() == ty.size() ); - - // initialize summation - for(size_t i = 0; i < px.size(); i++) - px[i] = 0.0; - - // number of orders to differentiate - size_t k = n_order; - while(k--) - { // differentiate the produces that result in order k - for(size_t ell = 0; ell <= k; ell++) - reverse_multiply( - ell, k - ell, tx, ty, px, py, nr_left, n_middle, nc_right - ); - } - - // all orders are implented, so always return true - return true; - } -/* %$$ -$head for_sparse_jac$$ -Routines called by CppAD during $cref ForSparseJac$$. -$srccode%cpp% */ - // boolean sparsity patterns - virtual bool for_sparse_jac( - size_t q , - const vector& r , - vector& s , - const vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - assert( nx == x.size() ); - assert( nx * q == r.size() ); - assert( ny * q == s.size() ); - size_t p; - - // sparsity for S(x) = f'(x) * R - size_t nk = 1; - size_t k = 0; - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - for(p = 0; p < q; p++) - s[i_result * q + p] = false; - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - for(p = 0; p < q; p++) - { // cast avoids Microsoft warning (should not be needed) - s[i_result * q + p] |= bool( r[i_left * q + p ] ); - s[i_result * q + p] |= bool( r[i_right * q + p ] ); - } - } - } - } - return true; - } - // set sparsity patterns - virtual bool for_sparse_jac( - size_t q , - const vector< std::set >& r , - vector< std::set >& s , - const vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); -# ifndef NDEBUG - size_t nx = 3 + (nr_left + nc_right) * n_middle; - size_t ny = nr_left * nc_right; -# endif - assert( nx == x.size() ); - assert( nx == r.size() ); - assert( ny == s.size() ); - - // sparsity for S(x) = f'(x) * R - size_t nk = 1; - size_t k = 0; - for(size_t i = 0; i < nr_left; i++) - { for(size_t j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - s[i_result].clear(); - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - // - s[i_result] = set_union(s[i_result], r[i_left] ); - s[i_result] = set_union(s[i_result], r[i_right] ); - } - } - } - return true; - } -/* %$$ -$head rev_sparse_jac$$ -Routines called by CppAD during $cref RevSparseJac$$. -$srccode%cpp% */ - // boolean sparsity patterns - virtual bool rev_sparse_jac( - size_t q , - const vector& rt , - vector& st , - const vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - assert( nx == x.size() ); - assert( nx * q == st.size() ); - assert( ny * q == rt.size() ); - size_t i, j, p; - - // initialize - for(i = 0; i < nx; i++) - { for(p = 0; p < q; p++) - st[ i * q + p ] = false; - } - - // sparsity for S(x)^T = f'(x)^T * R^T - size_t nk = 1; - size_t k = 0; - for(i = 0; i < nr_left; i++) - { for(j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - for(p = 0; p < q; p++) - { st[i_left * q + p] |= bool( rt[i_result * q + p] ); - st[i_right* q + p] |= bool( rt[i_result * q + p] ); - } - } - } - } - return true; - } - // set sparsity patterns - virtual bool rev_sparse_jac( - size_t q , - const vector< std::set >& rt , - vector< std::set >& st , - const vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - assert( nx == x.size() ); - assert( nx == st.size() ); - assert( ny == rt.size() ); - size_t i, j; - - // initialize - for(i = 0; i < nx; i++) - st[i].clear(); - - // sparsity for S(x)^T = f'(x)^T * R^T - size_t nk = 1; - size_t k = 0; - for(i = 0; i < nr_left; i++) - { for(j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - // - st[i_left] = set_union(st[i_left], rt[i_result]); - st[i_right] = set_union(st[i_right], rt[i_result]); - } - } - } - return true; - } -/* %$$ -$head rev_sparse_hes$$ -Routines called by $cref RevSparseHes$$. -$srccode%cpp% */ - // set sparsity patterns - virtual bool rev_sparse_hes( - const vector& vx, - const vector& s , - vector& t , - size_t q , - const vector< std::set >& r , - const vector< std::set >& u , - vector< std::set >& v , - const vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - assert( x.size() == nx ); - assert( vx.size() == nx ); - assert( t.size() == nx ); - assert( r.size() == nx ); - assert( v.size() == nx ); - assert( s.size() == ny ); - assert( u.size() == ny ); - // - size_t i, j; - // - // initilaize sparsity patterns as false - for(j = 0; j < nx; j++) - { t[j] = false; - v[j].clear(); - } - size_t nk = 1; - size_t k = 0; - for(i = 0; i < nr_left; i++) - { for(j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - // - // Compute sparsity for T(x) = S(x) * f'(x). - // We need not use vx with f'(x) back propagation. - t[i_left] |= bool( s[i_result] ); - t[i_right] |= bool( s[i_result] ); - - // V(x) = f'(x)^T * U(x) + S(x) * f''(x) * R - // U(x) = g''(y) * f'(x) * R - // S(x) = g'(y) - - // back propagate f'(x)^T * U(x) - // (no need to use vx with f'(x) propogation) - v[i_left] = set_union(v[i_left], u[i_result] ); - v[i_right] = set_union(v[i_right], u[i_result] ); - - // back propagate S(x) * f''(x) * R - // (here is where we must check for cross terms) - if( s[i_result] & vx[i_left] & vx[i_right] ) - { v[i_left] = set_union(v[i_left], r[i_right] ); - v[i_right] = set_union(v[i_right], r[i_left] ); - } - } - } - } - return true; - } - // bool sparsity - virtual bool rev_sparse_hes( - const vector& vx, - const vector& s , - vector& t , - size_t q , - const vector& r , - const vector& u , - vector& v , - const vector& x ) - { - size_t nr_left = size_t( CppAD::Integer( x[0] ) ); - size_t n_middle = size_t( CppAD::Integer( x[1] ) ); - size_t nc_right = size_t( CppAD::Integer( x[2] ) ); - size_t nx = 3 + (nr_left + nc_right) * n_middle; -# ifndef NDEBUG - size_t ny = nr_left * nc_right; -# endif - assert( x.size() == nx ); - assert( vx.size() == nx ); - assert( t.size() == nx ); - assert( r.size() == nx * q ); - assert( v.size() == nx * q ); - assert( s.size() == ny ); - assert( u.size() == ny * q ); - size_t i, j, p; - // - // initilaize sparsity patterns as false - for(j = 0; j < nx; j++) - { t[j] = false; - for(p = 0; p < q; p++) - v[j * q + p] = false; - } - size_t nk = 1; - size_t k = 0; - for(i = 0; i < nr_left; i++) - { for(j = 0; j < nc_right; j++) - { size_t i_result = result( - i, j, k, nk, nr_left, n_middle, nc_right - ); - for(size_t ell = 0; ell < n_middle; ell++) - { size_t i_left = left( - i, ell, k, nk, nr_left, n_middle, nc_right - ); - size_t i_right = right( - ell, j, k, nk, nr_left, n_middle, nc_right - ); - // - // Compute sparsity for T(x) = S(x) * f'(x). - // We so not need to use vx with f'(x) propagation. - t[i_left] |= bool( s[i_result] ); - t[i_right] |= bool( s[i_result] ); - - // V(x) = f'(x)^T * U(x) + S(x) * f''(x) * R - // U(x) = g''(y) * f'(x) * R - // S(x) = g'(y) - - // back propagate f'(x)^T * U(x) - // (no need to use vx with f'(x) propogation) - for(p = 0; p < q; p++) - { v[ i_left * q + p] |= bool( u[ i_result * q + p] ); - v[ i_right * q + p] |= bool( u[ i_result * q + p] ); - } - - // back propagate S(x) * f''(x) * R - // (here is where we must check for cross terms) - if( s[i_result] & vx[i_left] & vx[i_right] ) - { for(p = 0; p < q; p++) - { v[i_left * q + p] |= bool( r[i_right * q + p] ); - v[i_right * q + p] |= bool( r[i_left * q + p] ); - } - } - } - } - } - return true; - } -/* %$$ -$head End Class Definition$$ -$srccode%cpp% */ -}; // End of mat_mul class -} // End empty namespace -/* %$$ -$comment end nospell$$ -$end -*/ - - -# endif diff --git a/external/cppad/include/cppad/ipopt/solve.hpp b/external/cppad/include/cppad/ipopt/solve.hpp deleted file mode 100644 index fd3a00697..000000000 --- a/external/cppad/include/cppad/ipopt/solve.hpp +++ /dev/null @@ -1,643 +0,0 @@ -// $Id: solve.hpp 3804 2016-03-20 15:08:46Z bradbell $ -# ifndef CPPAD_IPOPT_SOLVE_HPP -# define CPPAD_IPOPT_SOLVE_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin ipopt_solve$$ -$spell - Jacobian - Jacobians - retape - Bvector - bool - infeasibility - const - cpp - cppad - doesn't - ADvector - eval - fg - gl - gu - hpp - inf - ipopt - maxiter - naninf - nf - ng - nx - obj - optimizer - std - xi - xl - xu - zl - zu -$$ - -$section Use Ipopt to Solve a Nonlinear Programming Problem$$ - -$head Syntax$$ -$codei%# include -%$$ -$codei%ipopt::solve( - %options%, %xi%, %xl%, %xu%, %gl%, %gu%, %fg_eval%, %solution% -)%$$ - -$head Purpose$$ -The function $code ipopt::solve$$ solves nonlinear programming -problems of the form -$latex \[ -\begin{array}{rll} -{\rm minimize} & f (x) -\\ -{\rm subject \; to} & gl \leq g(x) \leq gu -\\ - & xl \leq x \leq xu -\end{array} -\] $$ -This is done using -$href% - http://www.coin-or.org/projects/Ipopt.xml% - Ipopt -%$$ -optimizer and CppAD for the derivative and sparsity calculations. - -$head Include File$$ -Currently, this routine -$cref/ipopt::solve/ipopt_solve/$$ is not included by the command -$codei% - # include -%$$ -(Doing so would require the ipopt library to link -the corresponding program (even if $code ipopt::solve$$) was not used.) -For this reason, -if you are using $code ipopt::solve$$ you should use -$codei% - # include -%$$ -which in turn will also include $code $$. - -$head Bvector$$ -The type $icode Bvector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code bool$$. - -$head Dvector$$ -The type $icode DVector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code double$$. - -$head options$$ -The argument $icode options$$ has prototype -$codei% - const std::string %options% -%$$ -It contains a list of options. -Each option, including the last option, -is terminated by the $code '\n'$$ character. -Each line consists of two or three tokens separated by one or more spaces. - -$subhead Retape$$ -You can set the retape flag with the following syntax: -$codei% - Retape %value% -%$$ -If the value is $code true$$, $code ipopt::solve$$ with retape the -$cref/operation sequence/glossary/Operation/Sequence/$$ for each -new value of $icode x$$. -If the value is $code false$$, $code ipopt::solve$$ -will tape the operation sequence at the value -of $icode xi$$ and use that sequence for the entire optimization process. -The default value is $code false$$. - -$subhead Sparse$$ -You can set the sparse Jacobian and Hessian flag with the following syntax: -$codei% - Sparse %value% %direction% -%$$ -If the value is $code true$$, $code ipopt::solve$$ will use a sparse -matrix representation for the computation of Jacobians and Hessians. -Otherwise, it will use a full matrix representation for -these calculations. -The default for $icode value$$ is $code false$$. -If sparse is true, retape must be false. -$pre - -$$ -It is unclear if $cref sparse_jacobian$$ would be faster user -forward or reverse mode so you are able to choose the direction. -If -$codei% - %value% == true && %direction% == forward -%$$ -the Jacobians will be calculated using $code SparseJacobianForward$$. -If -$codei% - %value% == true && %direction% == reverse -%$$ -the Jacobians will be calculated using $code SparseJacobianReverse$$. - -$subhead String$$ -You can set any Ipopt string option using a line with the following syntax: -$codei% - String %name% %value% -%$$ -Here $icode name$$ is any valid Ipopt string option -and $icode value$$ is its setting. - -$subhead Numeric$$ -You can set any Ipopt numeric option using a line with the following syntax: -$codei% - Numeric %name% %value% -%$$ -Here $icode name$$ is any valid Ipopt numeric option -and $icode value$$ is its setting. - -$subhead Integer$$ -You can set any Ipopt integer option using a line with the following syntax: -$codei% - Integer %name% %value% -%$$ -Here $icode name$$ is any valid Ipopt integer option -and $icode value$$ is its setting. - -$head xi$$ -The argument $icode xi$$ has prototype -$codei% - const %Vector%& %xi% -%$$ -and its size is equal to $icode nx$$. -It specifies the initial point where Ipopt starts the optimization process. - -$head xl$$ -The argument $icode xl$$ has prototype -$codei% - const %Vector%& %xl% -%$$ -and its size is equal to $icode nx$$. -It specifies the lower limits for the argument in the optimization problem. - -$head xu$$ -The argument $icode xu$$ has prototype -$codei% - const %Vector%& %xu% -%$$ -and its size is equal to $icode nx$$. -It specifies the upper limits for the argument in the optimization problem. - -$head gl$$ -The argument $icode gl$$ has prototype -$codei% - const %Vector%& %gl% -%$$ -and its size is equal to $icode ng$$. -It specifies the lower limits for the constraints in the optimization problem. - -$head gu$$ -The argument $icode gu$$ has prototype -$codei% - const %Vector%& %gu% -%$$ -and its size is equal to $icode ng$$. -It specifies the upper limits for the constraints in the optimization problem. - -$head fg_eval$$ -The argument $icode fg_eval$$ has prototype -$codei% - %FG_eval% %fg_eval% -%$$ -where the class $icode FG_eval$$ is unspecified except for the fact that -it supports the syntax -$codei% - %FG_eval%::ADvector - %fg_eval%(%fg%, %x%) -%$$ -The type $icode ADvector$$ -and the arguments to $icode fg$$, $icode x$$ have the following meaning: - -$subhead ADvector$$ -The type $icode%FG_eval%::ADvector%$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$code AD$$. - -$subhead x$$ -The $icode fg_eval$$ argument $icode x$$ has prototype -$codei% - const %ADvector%& %x% -%$$ -where $icode%nx% = %x%.size()%$$. - -$subhead fg$$ -The $icode fg_eval$$ argument $icode fg$$ has prototype -$codei% - %ADvector%& %fg% -%$$ -where $codei%1 + %ng% = %fg%.size()%$$. -The input value of the elements of $icode fg$$ does not matter. -Upon return from $icode fg_eval$$, -$codei% - %fg%[0] =%$$ $latex f (x)$$ $codei% -%$$ -and for $latex i = 0, \ldots , ng-1$$, -$codei% - %fg%[1 + %i%] =%$$ $latex g_i (x)$$ - -$head solution$$ -The argument $icode solution$$ has prototype -$codei% - ipopt::solve_result<%Dvector%>& %solution% -%$$ -After the optimization process is completed, $icode solution$$ contains -the following information: - -$subhead status$$ -The $icode status$$ field of $icode solution$$ has prototype -$codei% - ipopt::solve_result<%Dvector%>::status_type %solution%.status -%$$ -It is the final Ipopt status for the optimizer. -Here is a list of the possible values for the status: - -$table -$icode status$$ $cnext Meaning -$rnext -not_defined $cnext -The optimizer did not return a final status for this problem. -$rnext -unknown $cnext -The status returned by the optimizer is not defined in the Ipopt -documentation for $code finalize_solution$$. -$rnext -success $cnext -Algorithm terminated successfully at a point satisfying the convergence -tolerances (see Ipopt options). -$rnext -maxiter_exceeded $cnext -The maximum number of iterations was exceeded (see Ipopt options). -$rnext -stop_at_tiny_step $cnext -Algorithm terminated because progress was very slow. -$rnext -stop_at_acceptable_point $cnext -Algorithm stopped at a point that was converged, -not to the 'desired' tolerances, but to 'acceptable' tolerances -(see Ipopt options). -$rnext -local_infeasibility $cnext -Algorithm converged to a non-feasible point -(problem may have no solution). -$rnext -user_requested_stop $cnext -This return value should not happen. -$rnext -diverging_iterates $cnext -It the iterates are diverging. -$rnext -restoration_failure $cnext -Restoration phase failed, algorithm doesn't know how to proceed. -$rnext -error_in_step_computation $cnext -An unrecoverable error occurred while Ipopt tried to -compute the search direction. -$rnext -invalid_number_detected $cnext -Algorithm received an invalid number (such as $code nan$$ or $code inf$$) -from the users function $icode%fg_info%.eval%$$ or from the CppAD evaluations -of its derivatives -(see the Ipopt option $code check_derivatives_for_naninf$$). -$rnext -internal_error $cnext -An unknown Ipopt internal error occurred. -Contact the Ipopt authors through the mailing list. -$tend - -$subhead x$$ -The $code x$$ field of $icode solution$$ has prototype -$codei% - %Vector% %solution%.x -%$$ -and its size is equal to $icode nx$$. -It is the final $latex x$$ value for the optimizer. - -$subhead zl$$ -The $code zl$$ field of $icode solution$$ has prototype -$codei% - %Vector% %solution%.zl -%$$ -and its size is equal to $icode nx$$. -It is the final Lagrange multipliers for the -lower bounds on $latex x$$. - -$subhead zu$$ -The $code zu$$ field of $icode solution$$ has prototype -$codei% - %Vector% %solution%.zu -%$$ -and its size is equal to $icode nx$$. -It is the final Lagrange multipliers for the -upper bounds on $latex x$$. - -$subhead g$$ -The $code g$$ field of $icode solution$$ has prototype -$codei% - %Vector% %solution%.g -%$$ -and its size is equal to $icode ng$$. -It is the final value for the constraint function $latex g(x)$$. - -$subhead lambda$$ -The $code lambda$$ field of $icode solution$$ has prototype -$codei% - %Vector%> %solution%.lambda -%$$ -and its size is equal to $icode ng$$. -It is the final value for the -Lagrange multipliers corresponding to the constraint function. - -$subhead obj_value$$ -The $code obj_value$$ field of $icode solution$$ has prototype -$codei% - double %solution%.obj_value -%$$ -It is the final value of the objective function $latex f(x)$$. - -$children% - example/ipopt_solve/get_started.cpp% - example/ipopt_solve/retape.cpp% - example/ipopt_solve/ode_inverse.cpp -%$$ -$head Example$$ -All the examples return true if it succeeds and false otherwise. - -$subhead get_started$$ -The file -$cref%example/ipopt_solve/get_started.cpp%ipopt_solve_get_started.cpp%$$ -is an example and test of $code ipopt::solve$$ -taken from the Ipopt manual. - -$subhead retape$$ -The file -$cref%example/ipopt_solve/retape.cpp%ipopt_solve_retape.cpp%$$ -demonstrates when it is necessary to specify -$cref/retape/ipopt_solve/options/Retape/$$ as true. - -$subhead ode_inverse$$ -The file -$cref%example/ipopt_solve/ode_inverse.cpp%ipopt_solve_ode_inverse.cpp%$$ -demonstrates using Ipopt to solve for parameters in an ODE model. - -$end -------------------------------------------------------------------------------- -*/ -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -namespace ipopt { -/*! -\file solve.hpp -\brief Implement the ipopt::solve Nonlinear Programming Solver -*/ - -/*! -Use Ipopt to Solve a Nonlinear Programming Problem - -\tparam Bvector -simple vector class with elements of type bool. - -\tparam Dvector -simple vector class with elements of type double. - -\tparam FG_eval -function object used to evaluate f(x) and g(x); see fg_eval below. -It must also support -\code - FG_eval::ADvector -\endcode -to dentify the type used for the arguments to fg_eval. - -\param options -list of options, one for each line. -Ipopt options (are optional) and have one of the following forms -\code - String name value - Numeric name value - Integer name value -\endcode -The following other possible options are listed below: -\code - Retape value -\endcode - - -\param xi -initial argument value to start optimization procedure at. - -\param xl -lower limit for argument during optimization - -\param xu -upper limit for argument during optimization - -\param gl -lower limit for g(x) during optimization. - -\param gu -upper limit for g(x) during optimization. - -\param fg_eval -function that evaluates the objective and constraints using the syntax -\code - fg_eval(fg, x) -\endcode - -\param solution -structure that holds the solution of the optimization. -*/ -template -void solve( - const std::string& options , - const Dvector& xi , - const Dvector& xl , - const Dvector& xu , - const Dvector& gl , - const Dvector& gu , - FG_eval& fg_eval , - ipopt::solve_result& solution ) -{ bool ok = true; - - typedef typename FG_eval::ADvector ADvector; - - CPPAD_ASSERT_KNOWN( - xi.size() == xl.size() && xi.size() == xu.size() , - "ipopt::solve: size of xi, xl, and xu are not all equal." - ); - CPPAD_ASSERT_KNOWN( - gl.size() == gu.size() , - "ipopt::solve: size of gl and gu are not equal." - ); - size_t nx = xi.size(); - size_t ng = gl.size(); - - // Create an IpoptApplication - using Ipopt::IpoptApplication; - Ipopt::SmartPtr app = new IpoptApplication(); - - // process the options argument - size_t begin_1, end_1, begin_2, end_2, begin_3, end_3; - begin_1 = 0; - bool retape = false; - bool sparse_forward = false; - bool sparse_reverse = false; - while( begin_1 < options.size() ) - { // split this line into tokens - while( options[begin_1] == ' ') - begin_1++; - end_1 = options.find_first_of(" \n", begin_1); - begin_2 = end_1; - while( options[begin_2] == ' ') - begin_2++; - end_2 = options.find_first_of(" \n", begin_2); - begin_3 = end_2; - while( options[begin_3] == ' ') - begin_3++; - end_3 = options.find_first_of(" \n", begin_3); - - // check for errors - CPPAD_ASSERT_KNOWN( - (end_1 != std::string::npos) & - (end_2 != std::string::npos) & - (end_3 != std::string::npos) , - "ipopt::solve: missing '\\n' at end of an option line" - ); - CPPAD_ASSERT_KNOWN( - (end_1 > begin_1) & (end_2 > begin_2) , - "ipopt::solve: an option line does not have two tokens" - ); - - // get first two tokens - std::string tok_1 = options.substr(begin_1, end_1 - begin_1); - std::string tok_2 = options.substr(begin_2, end_2 - begin_2); - - // get third token - std::string tok_3; - bool three_tok = false; - three_tok |= tok_1 == "Sparse"; - three_tok |= tok_1 == "String"; - three_tok |= tok_1 == "Numeric"; - three_tok |= tok_1 == "Integer"; - if( three_tok ) - { CPPAD_ASSERT_KNOWN( - (end_3 > begin_3) , - "ipopt::solve: a Sparse, String, Numeric, or Integer\n" - "option line does not have three tokens." - ); - tok_3 = options.substr(begin_3, end_3 - begin_3); - } - - // switch on option type - if( tok_1 == "Retape" ) - { CPPAD_ASSERT_KNOWN( - (tok_2 == "true") | (tok_2 == "false") , - "ipopt::solve: Retape value is not true or false" - ); - retape = (tok_2 == "true"); - } - else if( tok_1 == "Sparse" ) - { CPPAD_ASSERT_KNOWN( - (tok_2 == "true") | (tok_2 == "false") , - "ipopt::solve: Sparse value is not true or false" - ); - CPPAD_ASSERT_KNOWN( - (tok_3 == "forward") | (tok_3 == "reverse") , - "ipopt::solve: Sparse direction is not forward or reverse" - ); - if( tok_2 == "false" ) - { sparse_forward = false; - sparse_reverse = false; - } - else - { sparse_forward = tok_3 == "forward"; - sparse_reverse = tok_3 == "reverse"; - } - } - else if ( tok_1 == "String" ) - app->Options()->SetStringValue(tok_2.c_str(), tok_3.c_str()); - else if ( tok_1 == "Numeric" ) - { Ipopt::Number value = std::atof( tok_3.c_str() ); - app->Options()->SetNumericValue(tok_2.c_str(), value); - } - else if ( tok_1 == "Integer" ) - { Ipopt::Index value = std::atoi( tok_3.c_str() ); - app->Options()->SetIntegerValue(tok_2.c_str(), value); - } - else CPPAD_ASSERT_KNOWN( - false, - "ipopt::solve: First token is not one of\n" - "Retape, Sparse, String, Numeric, Integer" - ); - - begin_1 = end_3; - while( options[begin_1] == ' ') - begin_1++; - if( options[begin_1] != '\n' ) CPPAD_ASSERT_KNOWN( - false, - "ipopt::solve: either more than three tokens " - "or no '\\n' at end of a line" - ); - begin_1++; - } - CPPAD_ASSERT_KNOWN( - ! ( retape & (sparse_forward | sparse_reverse) ) , - "ipopt::solve: retape and sparse both true is not supported." - ); - - // Initialize the IpoptApplication and process the options - Ipopt::ApplicationReturnStatus status = app->Initialize(); - ok &= status == Ipopt::Solve_Succeeded; - if( ! ok ) - { solution.status = solve_result::unknown; - return; - } - - // Create an interface from Ipopt to this specific problem. - // Note the assumption here that ADvector is same as cppd_ipopt::ADvector - size_t nf = 1; - Ipopt::SmartPtr cppad_nlp = - new CppAD::ipopt::solve_callback( - nf, - nx, - ng, - xi, - xl, - xu, - gl, - gu, - fg_eval, - retape, - sparse_forward, - sparse_reverse, - solution - ); - - // Run the IpoptApplication - app->OptimizeTNLP(cppad_nlp); - - return; -} - -} // end ipopt namespace -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/ipopt/solve_callback.hpp b/external/cppad/include/cppad/ipopt/solve_callback.hpp deleted file mode 100644 index e4c5b5928..000000000 --- a/external/cppad/include/cppad/ipopt/solve_callback.hpp +++ /dev/null @@ -1,1192 +0,0 @@ -// $Id: solve_callback.hpp 3804 2016-03-20 15:08:46Z bradbell $ -# ifndef CPPAD_IPOPT_SOLVE_CALLBACK_HPP -# define CPPAD_IPOPT_SOLVE_CALLBACK_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -namespace ipopt { -/*! -\file solve_callback.hpp -\brief Class that connects ipopt::solve to Ipopt -*/ - -/*! -Class that Ipopt uses for obtaining information about this problem. - - -\section Evaluation_Methods Evaluation Methods -The set of evaluation methods for this class is -\verbatim - { eval_f, eval_grad_f, eval_g, eval_jac_g, eval_h } -\endverbatim -Note that the bool return flag for the evaluations methods -does not appear in the Ipopt documentation. -Looking at the code, it seems to be a flag telling Ipopt to abort -when the flag is false. -*/ -template -class solve_callback : public Ipopt::TNLP -{ -private: - // ------------------------------------------------------------------ - // Types used by this class - // ------------------------------------------------------------------ - /// A Scalar value used by Ipopt - typedef Ipopt::Number Number; - /// An index value used by Ipopt - typedef Ipopt::Index Index; - /// Indexing style used in Ipopt sparsity structure - typedef Ipopt::TNLP::IndexStyleEnum IndexStyleEnum; - // ------------------------------------------------------------------ - // Values directly passed in to constuctor - // ------------------------------------------------------------------ - /// dimension of the range space for f(x). - /// The objective is sum_i f_i (x). - /// Note that, at this point, there is no advantage having nf_ > 1. - const size_t nf_; - /// dimension of the domain space for f(x) and g(x) - const size_t nx_; - /// dimension of the range space for g(x) - const size_t ng_; - /// initial value for x - const Dvector& xi_; - /// lower limit for x - const Dvector& xl_; - /// upper limit for x - const Dvector& xu_; - /// lower limit for g(x) - const Dvector& gl_; - /// upper limit for g(x) - const Dvector& gu_; - /// object that evaluates f(x) and g(x) - FG_eval& fg_eval_; - /// should operation sequence be retaped for each new x. - bool retape_; - /// Should sparse methods be used to compute Jacobians and Hessians - /// with forward mode used for Jacobian. - bool sparse_forward_; - /// Should sparse methods be used to compute Jacobians and Hessians - /// with reverse mode used for Jacobian. - bool sparse_reverse_; - /// final results are returned to this structure - solve_result& solution_; - // ------------------------------------------------------------------ - // Values that are initilaized by the constructor - // ------------------------------------------------------------------ - /// AD function object that evaluates x -> [ f(x) , g(x) ] - /// If retape is false, this object is initialzed by constructor - /// otherwise it is set by cache_new_x each time it is called. - CppAD::ADFun adfun_; - /// value of x corresponding to previous new_x - Dvector x0_; - /// value of fg corresponding to previous new_x - Dvector fg0_; - // ---------------------------------------------------------------------- - // Jacobian information - // ---------------------------------------------------------------------- - /// Sparsity pattern for Jacobian of [f(x), g(x) ]. - /// If sparse is true, this pattern set by constructor and does not change. - /// Otherwise this vector has size zero. - CppAD::vectorBool pattern_jac_; - /// Row indices of [f(x), g(x)] for Jacobian of g(x) in row order. - /// (Set by constructor and not changed.) - CppAD::vector row_jac_; - /// Column indices for Jacobian of g(x), same order as row_jac_. - /// (Set by constructor and not changed.) - CppAD::vector col_jac_; - /// col_order_jac_ sorts row_jac_ and col_jac_ in column order. - /// (Set by constructor and not changed.) - CppAD::vector col_order_jac_; - /// Work vector used by SparseJacobian, stored here to avoid recalculation. - CppAD::sparse_jacobian_work work_jac_; - // ---------------------------------------------------------------------- - // Hessian information - // ---------------------------------------------------------------------- - /// Sparsity pattern for Hessian of Lagragian - /// \f[ L(x) = \sigma \sum_i f_i (x) + \sum_i \lambda_i g_i (x) \f] - /// If sparse is true, this pattern set by constructor and does not change. - /// Otherwise this vector has size zero. - CppAD::vectorBool pattern_hes_; - /// Row indices of Hessian lower left triangle in row order. - /// (Set by constructor and not changed.) - CppAD::vector row_hes_; - /// Column indices of Hessian left triangle in same order as row_hes_. - /// (Set by constructor and not changed.) - CppAD::vector col_hes_; - /// Work vector used by SparseJacobian, stored here to avoid recalculation. - CppAD::sparse_hessian_work work_hes_; - // ------------------------------------------------------------------ - // Private member functions - // ------------------------------------------------------------------ - /*! - Cache information for a new value of x. - - \param x - is the new value for x. - - \par x0_ - the elements of this vector are set to the new value for x. - - \par fg0_ - the elements of this vector are set to the new value for [f(x), g(x)] - - \par adfun_ - If retape is true, the operation sequence for this function - is changes to correspond to the argument x. - If retape is false, the operation sequence is not changed. - The zero order Taylor coefficients for this function are set - so they correspond to the argument x. - */ - void cache_new_x(const Number* x) - { size_t i; - if( retape_ ) - { // make adfun_, as well as x0_ and fg0_ correspond to this x - ADvector a_x(nx_), a_fg(nf_ + ng_); - for(i = 0; i < nx_; i++) - { x0_[i] = x[i]; - a_x[i] = x[i]; - } - CppAD::Independent(a_x); - fg_eval_(a_fg, a_x); - adfun_.Dependent(a_x, a_fg); - } - else - { // make x0_ and fg0_ correspond to this x - for(i = 0; i < nx_; i++) - x0_[i] = x[i]; - } - fg0_ = adfun_.Forward(0, x0_); - } -public: - // ---------------------------------------------------------------------- - /*! - Constructor for the interface between ipopt::solve and Ipopt - - \param nf - dimension of the range space for f(x) - - \param nx - dimension of the domain space for f(x) and g(x). - - \param ng - dimension of the range space for g(x) - - \param xi - initial value of x during the optimization procedure (size nx). - - \param xl - lower limit for x (size nx). - - \param xu - upper limit for x (size nx). - - \param gl - lower limit for g(x) (size ng). - - \param gu - upper limit for g(x) (size ng). - - \param fg_eval - function object that evaluations f(x) and g(x) using fg_eval(fg, x) - - \param retape - should the operation sequence be retaped for each argument value. - - \param sparse_forward - should sparse matrix computations be used for Jacobians and Hessians - with forward mode for Jacobian. - - \param sparse_reverse - should sparse matrix computations be used for Jacobians and Hessians - with reverse mode for Jacobian. - (sparse_forward and sparse_reverse cannot both be true). - - \param solution - object where final results are stored. - */ - solve_callback( - size_t nf , - size_t nx , - size_t ng , - const Dvector& xi , - const Dvector& xl , - const Dvector& xu , - const Dvector& gl , - const Dvector& gu , - FG_eval& fg_eval , - bool retape , - bool sparse_forward , - bool sparse_reverse , - solve_result& solution ) : - nf_ ( nf ), - nx_ ( nx ), - ng_ ( ng ), - xi_ ( xi ), - xl_ ( xl ), - xu_ ( xu ), - gl_ ( gl ), - gu_ ( gu ), - fg_eval_ ( fg_eval ), - retape_ ( retape ), - sparse_forward_ ( sparse_forward ), - sparse_reverse_ ( sparse_reverse ), - solution_ ( solution ) - { CPPAD_ASSERT_UNKNOWN( ! ( sparse_forward_ & sparse_reverse_ ) ); - - size_t i, j; - size_t nfg = nf_ + ng_; - - // initialize x0_ and fg0_ wih proper dimensions and value nan - x0_.resize(nx); - fg0_.resize(nfg); - for(i = 0; i < nx_; i++) - x0_[i] = CppAD::nan(0.0); - for(i = 0; i < nfg; i++) - fg0_[i] = CppAD::nan(0.0); - - if( ! retape_ ) - { // make adfun_ correspond to x -> [ f(x), g(x) ] - ADvector a_x(nx_), a_fg(nfg); - for(i = 0; i < nx_; i++) - a_x[i] = xi_[i]; - CppAD::Independent(a_x); - fg_eval_(a_fg, a_x); - adfun_.Dependent(a_x, a_fg); - // optimize because we will make repeated use of this tape - adfun_.optimize(); - } - if( sparse_forward_ | sparse_reverse_ ) - { CPPAD_ASSERT_UNKNOWN( ! retape ); - size_t m = nf_ + ng_; - // - // ----------------------------------------------------------- - // Jacobian - pattern_jac_.resize( m * nx_ ); - if( nx_ <= m ) - { // use forward mode to compute sparsity - - // number of bits that are packed into one unit in vectorBool - size_t n_column = vectorBool::bit_per_unit(); - - // sparsity patterns for current columns - vectorBool r(nx_ * n_column), s(m * n_column); - - // compute the sparsity pattern n_column columns at a time - size_t n_loop = (nx_ - 1) / n_column + 1; - for(size_t i_loop = 0; i_loop < n_loop; i_loop++) - { // starting column index for this iteration - size_t i_column = i_loop * n_column; - - // pattern that picks out the appropriate columns - for(i = 0; i < nx_; i++) - { for(j = 0; j < n_column; j++) - r[i * n_column + j] = (i == i_column + j); - } - s = adfun_.ForSparseJac(n_column, r); - - // fill in the corresponding columns of total_sparsity - for(i = 0; i < m; i++) - { for(j = 0; j < n_column; j++) - { if( i_column + j < nx_ ) - pattern_jac_[i * nx_ + i_column + j] = - s[i * n_column + j]; - } - } - } - } - else - { // use reverse mode to compute sparsity - - // number of bits that are packed into one unit in vectorBool - size_t n_row = vectorBool::bit_per_unit(); - - // sparsity patterns for current rows - vectorBool r(n_row * m), s(n_row * nx_); - - // compute the sparsity pattern n_row row at a time - size_t n_loop = (m - 1) / n_row + 1; - for(size_t i_loop = 0; i_loop < n_loop; i_loop++) - { // starting row index for this iteration - size_t i_row = i_loop * n_row; - - // pattern that picks out the appropriate rows - for(i = 0; i < n_row; i++) - { for(j = 0; j < m; j++) - r[i * m + j] = (i_row + i == j); - } - s = adfun_.RevSparseJac(n_row, r); - - // fill in correspoding rows of total sparsity - for(i = 0; i < n_row; i++) - { for(j = 0; j < nx_; j++) - if( i_row + i < m ) - pattern_jac_[ (i_row + i) * nx_ + j ] = - s[ i * nx_ + j]; - } - } - } - /* - { // use reverse mode to compute sparsity - CppAD::vectorBool s(m * m); - for(i = 0; i < m; i++) - { for(j = 0; j < m; j++) - s[i * m + j] = (i == j); - } - pattern_jac_ = adfun_.RevSparseJac(m, s); - } - */ - // Set row and column indices in Jacoian of [f(x), g(x)] - // for Jacobian of g(x). These indices are in row major order. - for(i = nf_; i < nfg; i++) - { for(j = 0; j < nx_; j++) - { if( pattern_jac_[ i * nx_ + j ] ) - { row_jac_.push_back(i); - col_jac_.push_back(j); - } - } - } - // Set row and column indices in Jacoian of [f(x), g(x)] - // for Jacobian of g(x). These indices are in row major order. - // ----------------------------------------------------------- - // Hessian - pattern_hes_.resize(nx_ * nx_); - - // number of bits that are packed into one unit in vectorBool - size_t n_column = vectorBool::bit_per_unit(); - - // sparsity patterns for current columns - vectorBool r(nx_ * n_column), h(nx_ * n_column); - - // sparsity pattern for range space of function - vectorBool s(m); - for(i = 0; i < m; i++) - s[i] = true; - - // compute the sparsity pattern n_column columns at a time - size_t n_loop = (nx_ - 1) / n_column + 1; - for(size_t i_loop = 0; i_loop < n_loop; i_loop++) - { // starting column index for this iteration - size_t i_column = i_loop * n_column; - - // pattern that picks out the appropriate columns - for(i = 0; i < nx_; i++) - { for(j = 0; j < n_column; j++) - r[i * n_column + j] = (i == i_column + j); - } - adfun_.ForSparseJac(n_column, r); - - // sparsity pattern corresponding to paritls w.r.t. (theta, u) - // of partial w.r.t. the selected columns - bool transpose = true; - h = adfun_.RevSparseHes(n_column, s, transpose); - - // fill in the corresponding columns of total_sparsity - for(i = 0; i < nx_; i++) - { for(j = 0; j < n_column; j++) - { if( i_column + j < nx_ ) - pattern_hes_[i * nx_ + i_column + j] = - h[i * n_column + j]; - } - } - } - // Set row and column indices for Lower triangle of Hessian - // of Lagragian. These indices are in row major order. - for(i = 0; i < nx_; i++) - { for(j = 0; j < nx_; j++) - { if( pattern_hes_[ i * nx_ + j ] ) - if( j <= i ) - { row_hes_.push_back(i); - col_hes_.push_back(j); - } - } - } - } - else - { // Set row and column indices in Jacoian of [f(x), g(x)] - // for Jacobian of g(x). These indices are in row major order. - for(i = nf_; i < nfg; i++) - { for(j = 0; j < nx_; j++) - { row_jac_.push_back(i); - col_jac_.push_back(j); - } - } - // Set row and column indices for lower triangle of Hessian. - // These indices are in row major order. - for(i = 0; i < nx_; i++) - { for(j = 0; j <= i; j++) - { row_hes_.push_back(i); - col_hes_.push_back(j); - } - } - } - - // Column order indirect sort of the Jacobian indices - col_order_jac_.resize( col_jac_.size() ); - index_sort( col_jac_, col_order_jac_ ); - } - // ----------------------------------------------------------------------- - /*! - Return dimension information about optimization problem. - - \param[out] n - is set to the value nx_. - - \param[out] m - is set to the value ng_. - - \param[out] nnz_jac_g - is set to ng_ * nx_ (sparsity not yet implemented) - - \param[out] nnz_h_lag - is set to nx_*(nx_+1)/2 (sparsity not yet implemented) - - \param[out] index_style - is set to C_STYLE; i.e., zeoro based indexing is used in the - information passed to Ipopt. - */ - virtual bool get_nlp_info( - Index& n , - Index& m , - Index& nnz_jac_g , - Index& nnz_h_lag , - IndexStyleEnum& index_style ) - { - n = static_cast(nx_); - m = static_cast(ng_); - nnz_jac_g = static_cast(row_jac_.size()); - nnz_h_lag = static_cast(row_hes_.size()); - -# ifndef NDEBUG - if( ! (sparse_forward_ | sparse_reverse_) ) - { size_t nnz = static_cast(nnz_jac_g); - CPPAD_ASSERT_UNKNOWN( nnz == ng_ * nx_); - // - nnz = static_cast(nnz_h_lag); - CPPAD_ASSERT_UNKNOWN( nnz == (nx_ * (nx_ + 1)) / 2 ); - } -# endif - - // use the fortran index style for row/col entries - index_style = C_STYLE; - - return true; - } - // ----------------------------------------------------------------------- - /*! - Return bound information about optimization problem. - - \param[in] n - is the dimension of the domain space for f(x) and g(x); i.e., - it must be equal to nx_. - - \param[out] x_l - is a vector of size nx_. - The input value of its elements does not matter. - On output, it is a copy of the lower bound for \f$ x \f$; i.e., - xl_. - - \param[out] x_u - is a vector of size nx_. - The input value of its elements does not matter. - On output, it is a copy of the upper bound for \f$ x \f$; i.e., - xu_. - - \param[in] m - is the dimension of the range space for g(x). i.e., - it must be equal to ng_. - - \param[out] g_l - is a vector of size ng_. - The input value of its elements does not matter. - On output, it is a copy of the lower bound for \f$ g(x) \f$; i.e., gl_. - - \param[out] g_u - is a vector of size ng_. - The input value of its elements does not matter. - On output, it is a copy of the upper bound for \f$ g(x) \f$; i.e, gu_. - */ - virtual bool get_bounds_info( - Index n , - Number* x_l , - Number* x_u , - Index m , - Number* g_l , - Number* g_u ) - { size_t i; - // here, the n and m we gave IPOPT in get_nlp_info are passed back - CPPAD_ASSERT_UNKNOWN(static_cast(n) == nx_); - CPPAD_ASSERT_UNKNOWN(static_cast(m) == ng_); - - // pass back bounds - for(i = 0; i < nx_; i++) - { x_l[i] = xl_[i]; - x_u[i] = xu_[i]; - } - for(i = 0; i < ng_; i++) - { g_l[i] = gl_[i]; - g_u[i] = gu_[i]; - } - - return true; - } - // ----------------------------------------------------------------------- - /*! - Return initial x value where optimiation is started. - - \param[in] n - must be equal to the domain dimension for f(x) and g(x); i.e., - it must be equal to nx_. - - \param[in] init_x - must be equal to true. - - \param[out] x - is a vector of size nx_. - The input value of its elements does not matter. - On output, it is a copy of the initial value for \f$ x \f$; i.e. xi_. - - \param[in] init_z - must be equal to false. - - \param z_L - is not used. - - \param z_U - is not used. - - \param[in] m - must be equal to the domain dimension for f(x) and g(x); i.e., - it must be equal to ng_. - - \param init_lambda - must be equal to false. - - \param lambda - is not used. - */ - virtual bool get_starting_point( - Index n , - bool init_x , - Number* x , - bool init_z , - Number* z_L , - Number* z_U , - Index m , - bool init_lambda , - Number* lambda ) - { size_t j; - - CPPAD_ASSERT_UNKNOWN(static_cast(n) == nx_ ); - CPPAD_ASSERT_UNKNOWN(static_cast(m) == ng_ ); - CPPAD_ASSERT_UNKNOWN(init_x == true); - CPPAD_ASSERT_UNKNOWN(init_z == false); - CPPAD_ASSERT_UNKNOWN(init_lambda == false); - - for(j = 0; j < nx_; j++) - x[j] = xi_[j]; - - return true; - } - // ----------------------------------------------------------------------- - /*! - Evaluate the objective fucntion f(x). - - \param[in] n - is the dimension of the argument space for f(x); i.e., must be equal nx_. - - \param[in] x - is a vector of size nx_ containing the point at which to evaluate - the function sum_i f_i (x). - - \param[in] new_x - is false if the previous call to any one of the - \ref Evaluation_Methods used the same value for x. - - \param[out] obj_value - is the value of the objective sum_i f_i (x) at this value of x. - - \return - The return value is always true; see \ref Evaluation_Methods. - */ - virtual bool eval_f( - Index n , - const Number* x , - bool new_x , - Number& obj_value ) - { size_t i; - if( new_x ) - cache_new_x(x); - // - double sum = 0.0; - for(i = 0; i < nf_; i++) - sum += fg0_[i]; - obj_value = static_cast(sum); - return true; - } - // ----------------------------------------------------------------------- - /*! - Evaluate the gradient of f(x). - - \param[in] n - is the dimension of the argument space for f(x); i.e., must be equal nx_. - - \param[in] x - has a vector of size nx_ containing the point at which to evaluate - the gradient of f(x). - - \param[in] new_x - is false if the previous call to any one of the - \ref Evaluation_Methods used the same value for x. - - \param[out] grad_f - is a vector of size nx_. - The input value of its elements does not matter. - The output value of its elements is the gradient of f(x) - at this value of. - - \return - The return value is always true; see \ref Evaluation_Methods. - */ - virtual bool eval_grad_f( - Index n , - const Number* x , - bool new_x , - Number* grad_f ) - { size_t i; - if( new_x ) - cache_new_x(x); - // - Dvector w(nf_ + ng_), dw(nx_); - for(i = 0; i < nf_; i++) - w[i] = 1.0; - for(i = 0; i < ng_; i++) - w[nf_ + i] = 0.0; - dw = adfun_.Reverse(1, w); - for(i = 0; i < nx_; i++) - grad_f[i] = dw[i]; - return true; - } - // ----------------------------------------------------------------------- - /*! - Evaluate the function g(x). - - \param[in] n - is the dimension of the argument space for g(x); i.e., must be equal nx_. - - \param[in] x - has a vector of size n containing the point at which to evaluate - the gradient of g(x). - - \param[in] new_x - is false if the previous call to any one of the - \ref Evaluation_Methods used the same value for x. - - \param[in] m - is the dimension of the range space for g(x); i.e., must be equal to ng_. - - \param[out] g - is a vector of size ng_. - The input value of its elements does not matter. - The output value of its elements is - the value of the function g(x) at this value of x. - - \return - The return value is always true; see \ref Evaluation_Methods. - */ - virtual bool eval_g( - Index n , - const Number* x , - bool new_x , - Index m , - Number* g ) - { size_t i; - if( new_x ) - cache_new_x(x); - // - for(i = 0; i < ng_; i++) - g[i] = fg0_[nf_ + i]; - return true; - } - // ----------------------------------------------------------------------- - /*! - Evaluate the Jacobian of g(x). - - \param[in] n - is the dimension of the argument space for g(x); - i.e., must be equal nx_. - - \param x - If values is not NULL, - x is a vector of size nx_ containing the point at which to evaluate - the gradient of g(x). - - \param[in] new_x - is false if the previous call to any one of the - \ref Evaluation_Methods used the same value for x. - - \param[in] m - is the dimension of the range space for g(x); - i.e., must be equal to ng_. - - \param[in] nele_jac - is the number of possibly non-zero elements in the Jacobian of g(x); - i.e., must be equal to ng_ * nx_. - - \param iRow - if values is not NULL, iRow is not defined. - if values is NULL, iRow - is a vector with size nele_jac. - The input value of its elements does not matter. - On output, - For k = 0 , ... , nele_jac-1, iRow[k] is the - base zero row index for the - k-th possibly non-zero entry in the Jacobian of g(x). - - \param jCol - if values is not NULL, jCol is not defined. - if values is NULL, jCol - is a vector with size nele_jac. - The input value of its elements does not matter. - On output, - For k = 0 , ... , nele_jac-1, jCol[k] is the - base zero column index for the - k-th possibly non-zero entry in the Jacobian of g(x). - - \param values - if \c values is not \c NULL, \c values - is a vector with size \c nele_jac. - The input value of its elements does not matter. - On output, - For k = 0 , ... , nele_jac-1, values[k] is the - value for the - k-th possibly non-zero entry in the Jacobian of g(x). - - \return - The return value is always true; see \ref Evaluation_Methods. - */ - virtual bool eval_jac_g( - Index n, - const Number* x, - bool new_x, - - Index m, - Index nele_jac, - Index* iRow, - Index *jCol, - - Number* values) - { size_t i, j, k, ell; - CPPAD_ASSERT_UNKNOWN(static_cast(m) == ng_ ); - CPPAD_ASSERT_UNKNOWN(static_cast(n) == nx_ ); - // - size_t nk = row_jac_.size(); - CPPAD_ASSERT_UNKNOWN( static_cast(nele_jac) == nk ); - // - if( new_x ) - cache_new_x(x); - - if( values == NULL ) - { for(k = 0; k < nk; k++) - { i = row_jac_[k]; - j = col_jac_[k]; - CPPAD_ASSERT_UNKNOWN( i >= nf_ ); - iRow[k] = static_cast(i - nf_); - jCol[k] = static_cast(j); - } - return true; - } - // - if( nk == 0 ) - return true; - // - if( sparse_forward_ ) - { Dvector jac(nk); - adfun_.SparseJacobianForward( - x0_ , pattern_jac_, row_jac_, col_jac_, jac, work_jac_ - ); - for(k = 0; k < nk; k++) - values[k] = jac[k]; - } - else if( sparse_reverse_ ) - { Dvector jac(nk); - adfun_.SparseJacobianReverse( - x0_ , pattern_jac_, row_jac_, col_jac_, jac, work_jac_ - ); - for(k = 0; k < nk; k++) - values[k] = jac[k]; - } - else if( nx_ < ng_ ) - { // use forward mode - Dvector x1(nx_), fg1(nf_ + ng_); - for(j = 0; j < nx_; j++) - x1[j] = 0.0; - // index in col_order_jac_ of next entry - ell = 0; - k = col_order_jac_[ell]; - for(j = 0; j < nx_; j++) - { // compute j-th column of Jacobian of g(x) - x1[j] = 1.0; - fg1 = adfun_.Forward(1, x1); - while( ell < nk && col_jac_[k] <= j ) - { CPPAD_ASSERT_UNKNOWN( col_jac_[k] == j ); - i = row_jac_[k]; - CPPAD_ASSERT_UNKNOWN( i >= nf_ ) - values[k] = fg1[i]; - ell++; - if( ell < nk ) - k = col_order_jac_[ell]; - } - x1[j] = 0.0; - } - } - else - { // user reverse mode - size_t nfg = nf_ + ng_; - // user reverse mode - Dvector w(nfg), dw(nx_); - for(i = 0; i < nfg; i++) - w[i] = 0.0; - // index in row_jac_ of next entry - k = 0; - for(i = nf_; i < nfg; i++) - { // compute i-th row of Jacobian of g(x) - w[i] = 1.0; - dw = adfun_.Reverse(1, w); - while( k < nk && row_jac_[k] <= i ) - { CPPAD_ASSERT_UNKNOWN( row_jac_[k] == i ); - j = col_jac_[k]; - values[k] = dw[j]; - k++; - } - w[i] = 0.0; - } - } - return true; - } - // ----------------------------------------------------------------------- - /*! - Evaluate the Hessian of the Lagragian - - \section The_Hessian_of_the_Lagragian The Hessian of the Lagragian - The Hessian of the Lagragian is defined as - \f[ - H(x, \sigma, \lambda ) - = - \sigma \nabla^2 f(x) + \sum_{i=0}^{m-1} \lambda_i \nabla^2 g(x)_i - \f] - - \param[in] n - is the dimension of the argument space for g(x); - i.e., must be equal nx_. - - \param x - if values is not NULL, x - is a vector of size nx_ containing the point at which to evaluate - the Hessian of the Lagragian. - - \param[in] new_x - is false if the previous call to any one of the - \ref Evaluation_Methods used the same value for x. - - \param[in] obj_factor - the value \f$ \sigma \f$ multiplying the Hessian of - f(x) in the expression for \ref The_Hessian_of_the_Lagragian. - - \param[in] m - is the dimension of the range space for g(x); - i.e., must be equal to ng_. - - \param[in] lambda - if values is not NULL, lambda - is a vector of size ng_ specifing the value of \f$ \lambda \f$ - in the expression for \ref The_Hessian_of_the_Lagragian. - - \param[in] new_lambda - is true if the previous call to eval_h had the same value for - lambda and false otherwise. - (Not currently used.) - - \param[in] nele_hess - is the number of possibly non-zero elements in the - Hessian of the Lagragian; - i.e., must be equal to nx_*(nx_+1)/2. - - \param iRow - if values is not NULL, iRow is not defined. - if values is NULL, iRow - is a vector with size nele_hess. - The input value of its elements does not matter. - On output, - For k = 0 , ... , nele_hess-1, iRow[k] is the - base zero row index for the - k-th possibly non-zero entry in the Hessian fo the Lagragian. - - \param jCol - if values is not NULL, jCol is not defined. - if values is NULL, jCol - is a vector with size nele_hess. - The input value of its elements does not matter. - On output, - For k = 0 , ... , nele_hess-1, jCol[k] is the - base zero column index for the - k-th possibly non-zero entry in the Hessian of the Lagragian. - - \param values - if values is not NULL, it - is a vector with size nele_hess. - The input value of its elements does not matter. - On output, - For k = 0 , ... , nele_hess-1, values[k] is the - value for the - k-th possibly non-zero entry in the Hessian of the Lagragian. - - \return - The return value is always true; see \ref Evaluation_Methods. - */ - virtual bool eval_h( - Index n , - const Number* x , - bool new_x , - Number obj_factor , - Index m , - const Number* lambda , - bool new_lambda , - Index nele_hess , - Index* iRow , - Index* jCol , - Number* values ) - { size_t i, j, k; - CPPAD_ASSERT_UNKNOWN(static_cast(m) == ng_ ); - CPPAD_ASSERT_UNKNOWN(static_cast(n) == nx_ ); - // - size_t nk = row_hes_.size(); - CPPAD_ASSERT_UNKNOWN( static_cast(nele_hess) == nk ); - // - if( new_x ) - cache_new_x(x); - // - if( values == NULL ) - { for(k = 0; k < nk; k++) - { i = row_hes_[k]; - j = col_hes_[k]; - iRow[k] = static_cast(i); - jCol[k] = static_cast(j); - } - return true; - } - // - if( nk == 0 ) - return true; - - // weigting vector for Lagragian - Dvector w(nf_ + ng_); - for(i = 0; i < nf_; i++) - w[i] = obj_factor; - for(i = 0; i < ng_; i++) - w[i + nf_] = lambda[i]; - // - if( sparse_forward_ | sparse_reverse_ ) - { Dvector hes(nk); - adfun_.SparseHessian( - x0_, w, pattern_hes_, row_hes_, col_hes_, hes, work_hes_ - ); - for(k = 0; k < nk; k++) - values[k] = hes[k]; - } - else - { Dvector hes(nx_ * nx_); - hes = adfun_.Hessian(x0_, w); - for(k = 0; k < nk; k++) - { i = row_hes_[k]; - j = col_hes_[k]; - values[k] = hes[i * nx_ + j]; - } - } - return true; - } - // ---------------------------------------------------------------------- - /*! - Pass solution information from Ipopt to users solution structure. - - \param[in] status - is value that the Ipopt solution status - which gets mapped to a correponding value for - \n - solution_.status - - \param[in] n - is the dimension of the domain space for f(x) and g(x); i.e., - it must be equal to nx_. - - \param[in] x - is a vector with size nx_ specifing the final solution. - This is the output value for - \n - solution_.x - - \param[in] z_L - is a vector with size nx_ specifing the Lagragian multipliers for the - constraint \f$ x^l \leq x \f$. - This is the output value for - \n - solution_.zl - - \param[in] z_U - is a vector with size nx_ specifing the Lagragian multipliers for the - constraint \f$ x \leq x^u \f$. - This is the output value for - \n - solution_.zu - - \param[in] m - is the dimension of the range space for g(x). i.e., - it must be equal to ng_. - - \param[in] g - is a vector with size ng_ containing the value of the constraint function - g(x) at the final solution x. - This is the output value for - \n - solution_.g - - \param[in] lambda - is a vector with size ng_ specifing the Lagragian multipliers for the - constraints \f$ g^l \leq g(x) \leq g^u \f$. - This is the output value for - \n - solution_.lambda - - \param[in] obj_value - is the value of the objective function f(x) at the final solution x. - This is the output value for - \n - solution_.obj_value - - \param[in] ip_data - is unspecified (by Ipopt) and hence not used. - - \param[in] ip_cq - is unspecified (by Ipopt) and hence not used. - - \par solution_[out] - this is a reference to the solution argument - in the constructor for solve_callback. - The results are stored here - (see documentation above). - */ - virtual void finalize_solution( - Ipopt::SolverReturn status , - Index n , - const Number* x , - const Number* z_L , - const Number* z_U , - Index m , - const Number* g , - const Number* lambda , - Number obj_value , - const Ipopt::IpoptData* ip_data , - Ipopt::IpoptCalculatedQuantities* ip_cq - ) - { size_t i, j; - - CPPAD_ASSERT_UNKNOWN(static_cast(n) == nx_ ); - CPPAD_ASSERT_UNKNOWN(static_cast(m) == ng_ ); - - switch(status) - { // convert status from Ipopt enum to solve_result enum - case Ipopt::SUCCESS: - solution_.status = solve_result::success; - break; - - case Ipopt::MAXITER_EXCEEDED: - solution_.status = - solve_result::maxiter_exceeded; - break; - - case Ipopt::STOP_AT_TINY_STEP: - solution_.status = - solve_result::stop_at_tiny_step; - break; - - case Ipopt::STOP_AT_ACCEPTABLE_POINT: - solution_.status = - solve_result::stop_at_acceptable_point; - break; - - case Ipopt::LOCAL_INFEASIBILITY: - solution_.status = - solve_result::local_infeasibility; - break; - - case Ipopt::USER_REQUESTED_STOP: - solution_.status = - solve_result::user_requested_stop; - break; - - case Ipopt::DIVERGING_ITERATES: - solution_.status = - solve_result::diverging_iterates; - break; - - case Ipopt::RESTORATION_FAILURE: - solution_.status = - solve_result::restoration_failure; - break; - - case Ipopt::ERROR_IN_STEP_COMPUTATION: - solution_.status = - solve_result::error_in_step_computation; - break; - - case Ipopt::INVALID_NUMBER_DETECTED: - solution_.status = - solve_result::invalid_number_detected; - break; - - case Ipopt::INTERNAL_ERROR: - solution_.status = - solve_result::internal_error; - break; - - default: - solution_.status = - solve_result::unknown; - } - - solution_.x.resize(nx_); - solution_.zl.resize(nx_); - solution_.zu.resize(nx_); - for(j = 0; j < nx_; j++) - { solution_.x[j] = x[j]; - solution_.zl[j] = z_L[j]; - solution_.zu[j] = z_U[j]; - } - solution_.g.resize(ng_); - solution_.lambda.resize(ng_); - for(i = 0; i < ng_; i++) - { solution_.g[i] = g[i]; - solution_.lambda[i] = lambda[i]; - } - solution_.obj_value = obj_value; - return; - } -}; - -} // end namespace ipopt -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/ipopt/solve_result.hpp b/external/cppad/include/cppad/ipopt/solve_result.hpp deleted file mode 100644 index c9212cbf7..000000000 --- a/external/cppad/include/cppad/ipopt/solve_result.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// $Id: solve_result.hpp 3804 2016-03-20 15:08:46Z bradbell $ -# ifndef CPPAD_IPOPT_SOLVE_RESULT_HPP -# define CPPAD_IPOPT_SOLVE_RESULT_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -namespace ipopt { -/*! -\file solve_result.hpp -Class that contains information about solve problem result -*/ - -/*! -Class that contains information about solve problem result - -\tparam Dvector -a simple vector with elements of type double -*/ -template -class solve_result -{ -public: - /// possible values for the result status - enum status_type { - not_defined, - success, - maxiter_exceeded, - stop_at_tiny_step, - stop_at_acceptable_point, - local_infeasibility, - user_requested_stop, - feasible_point_found, - diverging_iterates, - restoration_failure, - error_in_step_computation, - invalid_number_detected, - too_few_degrees_of_freedom, - internal_error, - unknown - }; - - /// possible values for solution status - status_type status; - /// the approximation solution - Dvector x; - /// Lagrange multipliers corresponding to lower bounds on x - Dvector zl; - /// Lagrange multipliers corresponding to upper bounds on x - Dvector zu; - /// value of g(x) - Dvector g; - /// Lagrange multipliers correspondiing constraints on g(x) - Dvector lambda; - /// value of f(x) - double obj_value; - /// constructor initializes solution status as not yet defined - solve_result(void) - { status = not_defined; } -}; - -} // end namespace ipopt -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/abs_op.hpp b/external/cppad/include/cppad/local/abs_op.hpp deleted file mode 100644 index 9219fe0dc..000000000 --- a/external/cppad/include/cppad/local/abs_op.hpp +++ /dev/null @@ -1,160 +0,0 @@ -# ifndef CPPAD_LOCAL_ABS_OP_HPP -# define CPPAD_LOCAL_ABS_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file abs_op.hpp -Forward and reverse mode calculations for z = fabs(x). -*/ - -/*! -Compute forward mode Taylor coefficient for result of op = AbsOp. - -The C++ source code corresponding to this operation is -\verbatim - z = fabs(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_abs_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - for(size_t j = p; j <= q; j++) - z[j] = sign(x[0]) * x[j]; -} - -/*! -Multiple directions forward mode Taylor coefficient for op = AbsOp. - -The C++ source code corresponding to this operation is -\verbatim - z = fabs(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_abs_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - z[m + ell] = sign(x[0]) * x[m + ell]; -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = AbsOp. - -The C++ source code corresponding to this operation is -\verbatim - z = fabs(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_abs_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base x0 = *(taylor + i_x * cap_order); - Base* z = taylor + i_z * cap_order; - - z[0] = fabs(x0); -} -/*! -Compute reverse mode partial derivatives for result of op = AbsOp. - -The C++ source code corresponding to this operation is -\verbatim - z = fabs(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_abs_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ size_t j; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to result - Base* pz = partial + i_z * nc_partial; - - // do not need azmul because sign is either +1, -1, or zero - for(j = 0; j <= d; j++) - px[j] += sign(x[0]) * pz[j]; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/acos_op.hpp b/external/cppad/include/cppad/local/acos_op.hpp deleted file mode 100644 index fe19f469f..000000000 --- a/external/cppad/include/cppad/local/acos_op.hpp +++ /dev/null @@ -1,263 +0,0 @@ -# ifndef CPPAD_LOCAL_ACOS_OP_HPP -# define CPPAD_LOCAL_ACOS_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file acos_op.hpp -Forward and reverse mode calculations for z = acos(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = AcosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acos(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(1 - x * x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_acos_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - size_t k; - Base uj; - if( p == 0 ) - { z[0] = acos( x[0] ); - uj = Base(1.0) - x[0] * x[0]; - b[0] = sqrt( uj ); - p++; - } - for(size_t j = p; j <= q; j++) - { uj = Base(0.0); - for(k = 0; k <= j; k++) - uj -= x[k] * x[j-k]; - b[j] = Base(0.0); - z[j] = Base(0.0); - for(k = 1; k < j; k++) - { b[j] -= Base(double(k)) * b[k] * b[j-k]; - z[j] -= Base(double(k)) * z[k] * b[j-k]; - } - b[j] /= Base(double(j)); - z[j] /= Base(double(j)); - // - b[j] += uj / Base(2.0); - z[j] -= x[j]; - // - b[j] /= b[0]; - z[j] /= b[0]; - } -} -/*! -Multiple directions forward mode Taylor coefficient for op = AcosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acos(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(1 - x * x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_acos_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* b = z - num_taylor_per_var; // called y in documentation - - size_t k, ell; - size_t m = (q-1) * r + 1; - for(ell = 0; ell < r; ell ++) - { Base uq = - 2.0 * x[m + ell] * x[0]; - for(k = 1; k < q; k++) - uq -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - b[m+ell] = Base(0.0); - z[m+ell] = Base(0.0); - for(k = 1; k < q; k++) - { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - } - b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0]; - z[m+ell] = -( x[m+ell] + z[m+ell] / Base(double(q)) ) / b[0]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = AcosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acos(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( 1 - x * x ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_acos_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - z[0] = acos( x[0] ); - b[0] = sqrt( Base(1.0) - x[0] * x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = AcosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acos(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( 1 - x * x ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_acos_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* b = z - cap_order; // called y in documentation - Base* pb = pz - nc_partial; - - Base inv_b0 = Base(1.0) / b[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { - // scale partials w.r.t b[j] by 1 / b[0] - pb[j] = azmul(pb[j], inv_b0); - - // scale partials w.r.t z[j] by 1 / b[0] - pz[j] = azmul(pz[j], inv_b0); - - // update partials w.r.t b^0 - pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]); - - // update partial w.r.t. x^0 - px[0] -= azmul(pb[j], x[j]); - - // update partial w.r.t. x^j - px[j] -= pz[j] + azmul(pb[j], x[0]); - - // further scale partial w.r.t. z[j] by 1 / j - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { // update partials w.r.t b^(j-k) - pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]); - - // update partials w.r.t. x^k - px[k] -= azmul(pb[j], x[j-k]); - - // update partials w.r.t. z^k - pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]); - } - --j; - } - - // j == 0 case - px[0] -= azmul( pz[0] + azmul(pb[0], x[0]), inv_b0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/acosh_op.hpp b/external/cppad/include/cppad/local/acosh_op.hpp deleted file mode 100644 index 551e38d71..000000000 --- a/external/cppad/include/cppad/local/acosh_op.hpp +++ /dev/null @@ -1,265 +0,0 @@ -# ifndef CPPAD_LOCAL_ACOSH_OP_HPP -# define CPPAD_LOCAL_ACOSH_OP_HPP -# if CPPAD_USE_CPLUSPLUS_2011 - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file acosh_op.hpp -Forward and reverse mode calculations for z = acosh(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = AcoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(x * x - 1) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_acosh_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - size_t k; - Base uj; - if( p == 0 ) - { z[0] = acosh( x[0] ); - uj = x[0] * x[0] - Base(1.0); - b[0] = sqrt( uj ); - p++; - } - for(size_t j = p; j <= q; j++) - { uj = Base(0.0); - for(k = 0; k <= j; k++) - uj += x[k] * x[j-k]; - b[j] = Base(0.0); - z[j] = Base(0.0); - for(k = 1; k < j; k++) - { b[j] -= Base(double(k)) * b[k] * b[j-k]; - z[j] -= Base(double(k)) * z[k] * b[j-k]; - } - b[j] /= Base(double(j)); - z[j] /= Base(double(j)); - // - b[j] += uj / Base(2.0); - z[j] += x[j]; - // - b[j] /= b[0]; - z[j] /= b[0]; - } -} -/*! -Multiple directions forward mode Taylor coefficient for op = AcoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(x * x - 1) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_acosh_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* b = z - num_taylor_per_var; // called y in documentation - - size_t k, ell; - size_t m = (q-1) * r + 1; - for(ell = 0; ell < r; ell ++) - { Base uq = 2.0 * x[m + ell] * x[0]; - for(k = 1; k < q; k++) - uq += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - b[m+ell] = Base(0.0); - z[m+ell] = Base(0.0); - for(k = 1; k < q; k++) - { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - } - b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0]; - z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = AcoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( x * x - 1 ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_acosh_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - z[0] = acosh( x[0] ); - b[0] = sqrt( x[0] * x[0] - Base(1.0) ); -} -/*! -Compute reverse mode partial derivatives for result of op = AcoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = acosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( x * x - 1 ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_acosh_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* b = z - cap_order; // called y in documentation - Base* pb = pz - nc_partial; - - Base inv_b0 = Base(1.0) / b[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { - // scale partials w.r.t b[j] by 1 / b[0] - pb[j] = azmul(pb[j], inv_b0); - - // scale partials w.r.t z[j] by 1 / b[0] - pz[j] = azmul(pz[j], inv_b0); - - // update partials w.r.t b^0 - pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]); - - // update partial w.r.t. x^0 - px[0] += azmul(pb[j], x[j]); - - // update partial w.r.t. x^j - px[j] += pz[j] + azmul(pb[j], x[0]); - - // further scale partial w.r.t. z[j] by 1 / j - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { // update partials w.r.t b^(j-k) - pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]); - - // update partials w.r.t. x^k - px[k] += azmul(pb[j], x[j-k]); - - // update partials w.r.t. z^k - pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]); - } - --j; - } - - // j == 0 case - px[0] += azmul(pz[0] + azmul(pb[0], x[0]), inv_b0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif -# endif diff --git a/external/cppad/include/cppad/local/ad_tape.hpp b/external/cppad/include/cppad/local/ad_tape.hpp deleted file mode 100644 index a5f46a773..000000000 --- a/external/cppad/include/cppad/local/ad_tape.hpp +++ /dev/null @@ -1,219 +0,0 @@ -# ifndef CPPAD_LOCAL_AD_TAPE_HPP -# define CPPAD_LOCAL_AD_TAPE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL__NAMESPACE - -/*! -Class used to hold tape that records AD operations. - -\tparam Base -An AD object is used to recording AD operations. -*/ - -template -class ADTape { - // Friends ============================================================= - - // classes ------------------------------------------------------------- - friend class AD; - friend class ADFun; - friend class atomic_base; - friend class discrete; - friend class VecAD; - friend class VecAD_reference; - - // functions ----------------------------------------------------------- - // PrintFor - friend void CppAD::PrintFor ( - const AD& flag , - const char* before , - const AD& var , - const char* after - ); - // CondExpOp - friend AD CppAD::CondExpOp ( - enum CompareOp cop , - const AD &left , - const AD &right , - const AD &trueCase , - const AD &falseCase - ); - // pow - friend AD CppAD::pow - (const AD &x, const AD &y); - // azmul - friend AD CppAD::azmul - (const AD &x, const AD &y); - // Parameter - friend bool CppAD::Parameter - (const AD &u); - // Variable - friend bool CppAD::Variable - (const AD &u); - // operators ----------------------------------------------------------- - // arithematic binary operators - friend AD CppAD::operator + - (const AD &left, const AD &right); - friend AD CppAD::operator - - (const AD &left, const AD &right); - friend AD CppAD::operator * - (const AD &left, const AD &right); - friend AD CppAD::operator / - (const AD &left, const AD &right); - - // comparison operators - friend bool CppAD::operator < - (const AD &left, const AD &right); - friend bool CppAD::operator <= - (const AD &left, const AD &right); - friend bool CppAD::operator > - (const AD &left, const AD &right); - friend bool CppAD::operator >= - (const AD &left, const AD &right); - friend bool CppAD::operator == - (const AD &left, const AD &right); - friend bool CppAD::operator != - (const AD &left, const AD &right); - // ====================================================================== - -// -------------------------------------------------------------------------- -private: - // ---------------------------------------------------------------------- - // private data - /*! - Unique identifier for this tape. It is always greater than - CPPAD_MAX_NUM_THREADS, and different for every tape (even ones that have - been deleted). In addition, id_ % CPPAD_MAX_NUM_THREADS is the thread - number for this tape. Set by Independent and effectively const - */ - tape_id_t id_; - /// Number of independent variables in this tapes reconding. - /// Set by Independent and effectively const - size_t size_independent_; - /// This is where the information is recorded. - local::recorder Rec_; - // ---------------------------------------------------------------------- - // private functions - // - // add a parameter to the tape - addr_t RecordParOp(const Base &x); - - // see CondExp.h - void RecordCondExp( - enum CompareOp cop , - AD &returnValue , - const AD &left , - const AD &right , - const AD &trueCase , - const AD &falseCase - ); - - // place a VecAD object in the tape - size_t AddVec( - size_t length, - const pod_vector& data - ); - -public: - // default constructor and destructor - - // public function only used by CppAD::Independent - template - void Independent(VectorADBase &u); - template - void Independent(VectorADBase &u, size_t abort_op_index); - -}; -// --------------------------------------------------------------------------- -// Private functions -// - -/*! -Place a parameter in the tape. - -On rare occations it is necessary to place a parameter in the tape; e.g., -when it is one of the dependent variabes. - -\param z -value of the parameter that we are placing in the tape. - -\return -variable index (for this recording) correpsonding to the parameter. - -\par 2DO -All these operates are preformed in \c Rec_, so we should -move this routine from ADTape to recorder. -*/ -template -addr_t ADTape::RecordParOp(const Base &z) -{ addr_t z_taddr; - addr_t ind; - CPPAD_ASSERT_UNKNOWN( NumRes(ParOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumArg(ParOp) == 1 ); - z_taddr = Rec_.PutOp(ParOp); - ind = Rec_.PutPar(z); - Rec_.PutArg(ind); - - return z_taddr; -} - -/*! -Put initialization for a VecAD object in the tape. - -This routine should be called once for each VecAD object when just -before it changes from a parameter to a variable. - -\param length -size of the VecAD object. - -\param data -initial values for the VecAD object -(values before it becomes a variable). - -\return -index of the start of this vector in the list of vector indices. -The value for this vector index is the length of the vector. -There are \c length indices following for this vector. -The values for these vector indices are the corresponding -parameter indices in the tape for the initial value of the corresponding -vec_ad element. - -\par 2DO -All these operates are preformed in \c Rec_, so we should -move this routine from ADTape to recorder. -*/ -template -size_t ADTape::AddVec(size_t length, const pod_vector& data) -{ CPPAD_ASSERT_UNKNOWN( length > 0 ); - size_t i; - size_t value_index; - - // store the length in VecInd - size_t start = Rec_.PutVecInd(length); - - // store indices of the values in VecInd - for(i = 0; i < length; i++) - { - value_index = Rec_.PutPar( data[i] ); - Rec_.PutVecInd( value_index ); - } - - // return the taddr of the length (where the vector starts) - return start; -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/add_op.hpp b/external/cppad/include/cppad/local/add_op.hpp deleted file mode 100644 index 7a1a8b311..000000000 --- a/external/cppad/include/cppad/local/add_op.hpp +++ /dev/null @@ -1,339 +0,0 @@ -// $Id: add_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_ADD_OP_HPP -# define CPPAD_LOCAL_ADD_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file add_op.hpp -Forward and reverse mode calculations for z = x + y. -*/ - -// --------------------------- Addvv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = AddvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_addvv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - for(size_t j = p; j <= q; j++) - z[j] = x[j] + y[j]; -} -/*! -Multiple directions forward mode Taylor coefficients for op = AddvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_addvv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* y = taylor + arg[1] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t m = (q-1)*r + 1 ; - for(size_t ell = 0; ell < r; ell++) - z[m+ell] = x[m+ell] + y[m+ell]; -} - -/*! -Compute zero order forward mode Taylor coefficients for result of op = AddvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_addvv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x[0] + y[0]; -} - -/*! -Compute reverse mode partial derivatives for result of op = AddvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_addvv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t i = d + 1; - while(i) - { --i; - px[i] += pz[i]; - py[i] += pz[i]; - } -} - -// --------------------------- Addpv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = AddpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op -*/ -template -inline void forward_addpv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - if( p == 0 ) - { // Paraemter value - Base x = parameter[ arg[0] ]; - z[0] = x + y[0]; - p++; - } - for(size_t j = p; j <= q; j++) - z[j] = y[j]; -} -/*! -Multiple directions forward mode Taylor coefficients for op = AddpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_dir -*/ -template -inline void forward_addpv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1) * r + 1; - Base* y = taylor + arg[1] * num_taylor_per_var + m; - Base* z = taylor + i_z * num_taylor_per_var + m; - - for(size_t ell = 0; ell < r; ell++) - z[ell] = y[ell]; -} -/*! -Compute zero order forward mode Taylor coefficient for result of op = AddpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_addpv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 ); - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x + y[0]; -} - -/*! -Compute reverse mode partial derivative for result of op = AddpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x + y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_addpv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Partial derivatives corresponding to arguments and result - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t i = d + 1; - while(i) - { --i; - py[i] += pz[i]; - } -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/asin_op.hpp b/external/cppad/include/cppad/local/asin_op.hpp deleted file mode 100644 index 0b7834637..000000000 --- a/external/cppad/include/cppad/local/asin_op.hpp +++ /dev/null @@ -1,263 +0,0 @@ -# ifndef CPPAD_LOCAL_ASIN_OP_HPP -# define CPPAD_LOCAL_ASIN_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file asin_op.hpp -Forward and reverse mode calculations for z = asin(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = AsinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asin(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(1 - x * x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_asin_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - size_t k; - Base uj; - if( p == 0 ) - { z[0] = asin( x[0] ); - uj = Base(1.0) - x[0] * x[0]; - b[0] = sqrt( uj ); - p++; - } - for(size_t j = p; j <= q; j++) - { uj = Base(0.0); - for(k = 0; k <= j; k++) - uj -= x[k] * x[j-k]; - b[j] = Base(0.0); - z[j] = Base(0.0); - for(k = 1; k < j; k++) - { b[j] -= Base(double(k)) * b[k] * b[j-k]; - z[j] -= Base(double(k)) * z[k] * b[j-k]; - } - b[j] /= Base(double(j)); - z[j] /= Base(double(j)); - // - b[j] += uj / Base(2.0); - z[j] += x[j]; - // - b[j] /= b[0]; - z[j] /= b[0]; - } -} -/*! -Multiple directions forward mode Taylor coefficient for op = AsinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asin(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(1 - x * x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_asin_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* b = z - num_taylor_per_var; // called y in documentation - - size_t k, ell; - size_t m = (q-1) * r + 1; - for(ell = 0; ell < r; ell ++) - { Base uq = - 2.0 * x[m + ell] * x[0]; - for(k = 1; k < q; k++) - uq -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - b[m+ell] = Base(0.0); - z[m+ell] = Base(0.0); - for(k = 1; k < q; k++) - { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - } - b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0]; - z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = AsinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asin(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( 1 - x * x ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_asin_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - z[0] = asin( x[0] ); - b[0] = sqrt( Base(1.0) - x[0] * x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = AsinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asin(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( 1 - x * x ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_asin_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* b = z - cap_order; // called y in documentation - Base* pb = pz - nc_partial; - - Base inv_b0 = Base(1.0) / b[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { - // scale partials w.r.t b[j] by 1 / b[0] - pb[j] = azmul(pb[j], inv_b0); - - // scale partials w.r.t z[j] by 1 / b[0] - pz[j] = azmul(pz[j], inv_b0); - - // update partials w.r.t b^0 - pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]); - - // update partial w.r.t. x^0 - px[0] -= azmul(pb[j], x[j]); - - // update partial w.r.t. x^j - px[j] += pz[j] - azmul(pb[j], x[0]); - - // further scale partial w.r.t. z[j] by 1 / j - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { // update partials w.r.t b^(j-k) - pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]); - - // update partials w.r.t. x^k - px[k] -= azmul(pb[j], x[j-k]); - - // update partials w.r.t. z^k - pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]); - } - --j; - } - - // j == 0 case - px[0] += azmul(pz[0] - azmul(pb[0], x[0]), inv_b0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/asinh_op.hpp b/external/cppad/include/cppad/local/asinh_op.hpp deleted file mode 100644 index 277063ccd..000000000 --- a/external/cppad/include/cppad/local/asinh_op.hpp +++ /dev/null @@ -1,265 +0,0 @@ -# ifndef CPPAD_LOCAL_ASINH_OP_HPP -# define CPPAD_LOCAL_ASINH_OP_HPP -# if CPPAD_USE_CPLUSPLUS_2011 - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file asinh_op.hpp -Forward and reverse mode calculations for z = asinh(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = AsinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asinh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(1 + x * x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_asinh_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - size_t k; - Base uj; - if( p == 0 ) - { z[0] = asinh( x[0] ); - uj = Base(1.0) + x[0] * x[0]; - b[0] = sqrt( uj ); - p++; - } - for(size_t j = p; j <= q; j++) - { uj = Base(0.0); - for(k = 0; k <= j; k++) - uj += x[k] * x[j-k]; - b[j] = Base(0.0); - z[j] = Base(0.0); - for(k = 1; k < j; k++) - { b[j] -= Base(double(k)) * b[k] * b[j-k]; - z[j] -= Base(double(k)) * z[k] * b[j-k]; - } - b[j] /= Base(double(j)); - z[j] /= Base(double(j)); - // - b[j] += uj / Base(2.0); - z[j] += x[j]; - // - b[j] /= b[0]; - z[j] /= b[0]; - } -} -/*! -Multiple directions forward mode Taylor coefficient for op = AsinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asinh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt(1 + x * x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_asinh_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* b = z - num_taylor_per_var; // called y in documentation - - size_t k, ell; - size_t m = (q-1) * r + 1; - for(ell = 0; ell < r; ell ++) - { Base uq = 2.0 * x[m + ell] * x[0]; - for(k = 1; k < q; k++) - uq += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - b[m+ell] = Base(0.0); - z[m+ell] = Base(0.0); - for(k = 1; k < q; k++) - { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - } - b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0]; - z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = AsinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asinh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( 1 + x * x ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_asinh_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - z[0] = asinh( x[0] ); - b[0] = sqrt( Base(1.0) + x[0] * x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = AsinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = asinh(x) -\endverbatim -The auxillary result is -\verbatim - y = sqrt( 1 + x * x ) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_asinh_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* b = z - cap_order; // called y in documentation - Base* pb = pz - nc_partial; - - Base inv_b0 = Base(1.0) / b[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { - // scale partials w.r.t b[j] by 1 / b[0] - pb[j] = azmul(pb[j], inv_b0); - - // scale partials w.r.t z[j] by 1 / b[0] - pz[j] = azmul(pz[j], inv_b0); - - // update partials w.r.t b^0 - pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]); - - // update partial w.r.t. x^0 - px[0] += azmul(pb[j], x[j]); - - // update partial w.r.t. x^j - px[j] += pz[j] + azmul(pb[j], x[0]); - - // further scale partial w.r.t. z[j] by 1 / j - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { // update partials w.r.t b^(j-k) - pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]); - - // update partials w.r.t. x^k - px[k] += azmul(pb[j], x[j-k]); - - // update partials w.r.t. z^k - pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]); - } - --j; - } - - // j == 0 case - px[0] += azmul(pz[0] + azmul(pb[0], x[0]), inv_b0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif -# endif diff --git a/external/cppad/include/cppad/local/atan_op.hpp b/external/cppad/include/cppad/local/atan_op.hpp deleted file mode 100644 index abe10c744..000000000 --- a/external/cppad/include/cppad/local/atan_op.hpp +++ /dev/null @@ -1,235 +0,0 @@ -# ifndef CPPAD_LOCAL_ATAN_OP_HPP -# define CPPAD_LOCAL_ATAN_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file atan_op.hpp -Forward and reverse mode calculations for z = atan(x). -*/ - - -/*! -Forward mode Taylor coefficient for result of op = AtanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atan(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 + x * x -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_atan_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - size_t k; - if( p == 0 ) - { z[0] = atan( x[0] ); - b[0] = Base(1.0) + x[0] * x[0]; - p++; - } - for(size_t j = p; j <= q; j++) - { - b[j] = Base(2.0) * x[0] * x[j]; - z[j] = Base(0.0); - for(k = 1; k < j; k++) - { b[j] += x[k] * x[j-k]; - z[j] -= Base(double(k)) * z[k] * b[j-k]; - } - z[j] /= Base(double(j)); - z[j] += x[j]; - z[j] /= b[0]; - } -} - -/*! -Multiple direction Taylor coefficient for op = AtanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atan(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 + x * x -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_atan_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* b = z - num_taylor_per_var; // called y in documentation - - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { b[m+ell] = Base(2.0) * x[m+ell] * x[0]; - z[m+ell] = Base(double(q)) * x[m+ell]; - for(size_t k = 1; k < q; k++) - { b[m+ell] += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - } - z[m+ell] /= ( Base(double(q)) * b[0] ); - } -} - -/*! -Zero order forward mode Taylor coefficient for result of op = AtanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atan(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 + x * x -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_atan_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - z[0] = atan( x[0] ); - b[0] = Base(1.0) + x[0] * x[0]; -} -/*! -Reverse mode partial derivatives for result of op = AtanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atan(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 + x * x -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_atan_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* b = z - cap_order; // called y in documentation - Base* pb = pz - nc_partial; - - Base inv_b0 = Base(1.0) / b[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { // scale partials w.r.t z[j] and b[j] - pz[j] = azmul(pz[j], inv_b0); - pb[j] *= Base(2.0); - - pb[0] -= azmul(pz[j], z[j]); - px[j] += pz[j] + azmul(pb[j], x[0]); - px[0] += azmul(pb[j], x[j]); - - // more scaling of partials w.r.t z[j] - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]); - pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]); - px[k] += azmul(pb[j], x[j-k]); - } - --j; - } - px[0] += azmul(pz[0], inv_b0) + Base(2.0) * azmul(pb[0], x[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/atanh_op.hpp b/external/cppad/include/cppad/local/atanh_op.hpp deleted file mode 100644 index 9283ea07b..000000000 --- a/external/cppad/include/cppad/local/atanh_op.hpp +++ /dev/null @@ -1,237 +0,0 @@ -# ifndef CPPAD_LOCAL_ATANH_OP_HPP -# define CPPAD_LOCAL_ATANH_OP_HPP -# if CPPAD_USE_CPLUSPLUS_2011 - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file atanh_op.hpp -Forward and reverse mode calculations for z = atanh(x). -*/ - - -/*! -Forward mode Taylor coefficient for result of op = AtanhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atanh(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 - x * x -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_atanh_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - size_t k; - if( p == 0 ) - { z[0] = atanh( x[0] ); - b[0] = Base(1.0) - x[0] * x[0]; - p++; - } - for(size_t j = p; j <= q; j++) - { - b[j] = - Base(2.0) * x[0] * x[j]; - z[j] = Base(0.0); - for(k = 1; k < j; k++) - { b[j] -= x[k] * x[j-k]; - z[j] -= Base(double(k)) * z[k] * b[j-k]; - } - z[j] /= Base(double(j)); - z[j] += x[j]; - z[j] /= b[0]; - } -} - -/*! -Multiple direction Taylor coefficient for op = AtanhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atanh(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 - x * x -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_atanh_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* b = z - num_taylor_per_var; // called y in documentation - - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { b[m+ell] = - Base(2.0) * x[m+ell] * x[0]; - z[m+ell] = Base(double(q)) * x[m+ell]; - for(size_t k = 1; k < q; k++) - { b[m+ell] -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell]; - } - z[m+ell] /= ( Base(double(q)) * b[0] ); - } -} - -/*! -Zero order forward mode Taylor coefficient for result of op = AtanhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atanh(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 - x * x -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_atanh_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* b = z - cap_order; // called y in documentation - - z[0] = atanh( x[0] ); - b[0] = Base(1.0) - x[0] * x[0]; -} -/*! -Reverse mode partial derivatives for result of op = AtanhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = atanh(x) -\endverbatim -The auxillary result is -\verbatim - y = 1 - x * x -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_atanh_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* b = z - cap_order; // called y in documentation - Base* pb = pz - nc_partial; - - Base inv_b0 = Base(1.0) / b[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { // scale partials w.r.t z[j] and b[j] - pz[j] = azmul(pz[j], inv_b0); - pb[j] *= Base(2.0); - - pb[0] -= azmul(pz[j], z[j]); - px[j] += pz[j] - azmul(pb[j], x[0]); - px[0] -= azmul(pb[j], x[j]); - - // more scaling of partials w.r.t z[j] - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]); - pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]); - px[k] -= azmul(pb[j], x[j-k]); - } - --j; - } - px[0] += azmul(pz[0], inv_b0) - Base(2.0) * azmul(pb[0], x[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif -# endif diff --git a/external/cppad/include/cppad/local/color_general.hpp b/external/cppad/include/cppad/local/color_general.hpp deleted file mode 100644 index b5704d128..000000000 --- a/external/cppad/include/cppad/local/color_general.hpp +++ /dev/null @@ -1,295 +0,0 @@ -# ifndef CPPAD_LOCAL_COLOR_GENERAL_HPP -# define CPPAD_LOCAL_COLOR_GENERAL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file color_general.hpp -Coloring algorithm for a general sparse matrix. -*/ -// -------------------------------------------------------------------------- -/*! -Determine which rows of a general sparse matrix can be computed together; -i.e., do not have non-zero entries with the same column index. - -\tparam VectorSize -is a simple vector class with elements of type size_t. - -\tparam VectorSet -is an unspecified type with the exception that it must support the -operations under pattern and the following operations where -p is a VectorSet object: -\n -VectorSet p -Constructs a new vector of sets object. -\n -p.resize(ns, ne) -resizes \c p to \c ns sets with elements between zero \c ne. -All of the \c ns sets are initially empty. -\n -p.add_element(s, e) -add element \c e to set with index \c s. - -\param pattern [in] -Is a representation of the sparsity pattern for the matrix. -\n -m = pattern.n_set() -\n -sets \c m to the number of rows in the sparse matrix. -All of the row indices are less than this value. -\n -n = pattern.end() -\n -sets \c n to the number of columns in the sparse matrix. -All of the column indices are less than this value. -\n -VectorSet::const_iterator itr(pattern, i) -constructs an iterator that starts iterating over -columns in the i-th row of the sparsity pattern. -\n -j = *itr -Sets j to the next possibly non-zero column. -\n -++itr -Advances to the next possibly non-zero column. - -\param row [in] -is a vector specifying which row indices to compute. - -\param col [in] -is a vector, with the same size as row, -that specifies which column indices to compute. -For each valid index k, the index pair -(row[k], col[k]) must be present in the sparsity pattern. -It may be that some entries in the sparsity pattern do not need to be computed; -i.e, do not appear in the set of -(row[k], col[k]) entries. - -\param color [out] -is a vector with size m. -The input value of its elements does not matter. -Upon return, it is a coloring for the rows of the sparse matrix. -\n -\n -If for some i, color[i] == m, then -the i-th row does not appear in the vector row. -Otherwise, color[i] < m. -\n -\n -Suppose two differen rows, i != r have the same color and -column index j is such that both of the pairs -(i, j) and (r, j) appear in the sparsity pattern. -It follows that neither of these pairs appear in the set of -(row[k], col[k]) entries. -\n -\n -This routine tries to minimize, with respect to the choice of colors, -the maximum, with respct to k, of color[ row[k] ] -(not counting the indices k for which row[k] == m). -*/ -template -void color_general_cppad( - const VectorSet& pattern , - const VectorSize& row , - const VectorSize& col , - CppAD::vector& color ) -{ size_t i, j, k, ell, r; - - size_t K = row.size(); - size_t m = pattern.n_set(); - size_t n = pattern.end(); - - CPPAD_ASSERT_UNKNOWN( size_t( col.size() ) == K ); - CPPAD_ASSERT_UNKNOWN( size_t( color.size() ) == m ); - - // We define the set of rows, columns, and pairs that appear - // by the set ( row[k], col[k] ) for k = 0, ... , K-1. - - // initialize rows that appear - CppAD::vector row_appear(m); - for(i = 0; i < m; i++) - row_appear[i] = false; - - // rows and columns that appear - VectorSet c2r_appear, r2c_appear; - c2r_appear.resize(n, m); - r2c_appear.resize(m, n); - for(k = 0; k < K; k++) - { CPPAD_ASSERT_UNKNOWN( pattern.is_element(row[k], col[k]) ); - row_appear[ row[k] ] = true; - c2r_appear.add_element(col[k], row[k]); - r2c_appear.add_element(row[k], col[k]); - } - - // for each column, which rows are non-zero and do not appear - VectorSet not_appear; - not_appear.resize(n, m); - for(i = 0; i < m; i++) - { typename VectorSet::const_iterator pattern_itr(pattern, i); - j = *pattern_itr; - while( j != pattern.end() ) - { if( ! c2r_appear.is_element(j , i) ) - not_appear.add_element(j, i); - j = *(++pattern_itr); - } - } - - // initial coloring - color.resize(m); - ell = 0; - for(i = 0; i < m; i++) - { if( row_appear[i] ) - color[i] = ell++; - else color[i] = m; - } - /* - See GreedyPartialD2Coloring Algorithm Section 3.6.2 of - Graph Coloring in Optimization Revisited by - Assefaw Gebremedhin, Fredrik Maane, Alex Pothen - - The algorithm above was modified (by Brad Bell) to take advantage of the - fact that only the entries (subset of the sparsity pattern) specified by - row and col need to be computed. - */ - CppAD::vector forbidden(m); - for(i = 1; i < m; i++) // for each row that appears - if( color[i] < m ) - { - // initial all colors as ok for this row - // (value of forbidden for ell > initial color[i] does not matter) - for(ell = 0; ell <= color[i]; ell++) - forbidden[ell] = false; - - // ----------------------------------------------------- - // Forbid colors for which this row would destroy results: - // - // for each column that is non-zero for this row - typename VectorSet::const_iterator pattern_itr(pattern, i); - j = *pattern_itr; - while( j != pattern.end() ) - { // for each row that appears with this column - typename VectorSet::const_iterator c2r_itr(c2r_appear, j); - r = *c2r_itr; - while( r != c2r_appear.end() ) - { // if this is not the same row, forbid its color - if( (r < i) & (color[r] < m) ) - forbidden[ color[r] ] = true; - r = *(++c2r_itr); - } - j = *(++pattern_itr); - } - - - // ----------------------------------------------------- - // Forbid colors that destroy results needed for this row. - // - // for each column that appears with this row - typename VectorSet::const_iterator r2c_itr(r2c_appear, i); - j = *r2c_itr; - while( j != r2c_appear.end() ) - { // For each row that is non-zero for this column - // (the appear rows have already been checked above). - typename VectorSet::const_iterator not_itr(not_appear, j); - r = *not_itr; - while( r != not_appear.end() ) - { // if this is not the same row, forbid its color - if( (r < i) & (color[r] < m) ) - forbidden[ color[r] ] = true; - r = *(++not_itr); - } - j = *(++r2c_itr); - } - - // pick the color with smallest index - ell = 0; - while( forbidden[ell] ) - { ell++; - CPPAD_ASSERT_UNKNOWN( ell <= color[i] ); - } - color[i] = ell; - } - return; -} - -# if CPPAD_HAS_COLPACK -/*! -Colpack version of determining which rows of a sparse matrix -can be computed together. - -\copydetails color_general -*/ -template -void color_general_colpack( - const VectorSet& pattern , - const VectorSize& row , - const VectorSize& col , - CppAD::vector& color ) -{ size_t i, j, k; - size_t m = pattern.n_set(); - size_t n = pattern.end(); - - // Determine number of non-zero entries in each row - CppAD::vector n_nonzero(m); - size_t n_nonzero_total = 0; - for(i = 0; i < m; i++) - { n_nonzero[i] = 0; - typename VectorSet::const_iterator pattern_itr(pattern, i); - j = *pattern_itr; - while( j != pattern.end() ) - { n_nonzero[i]++; - j = *(++pattern_itr); - } - n_nonzero_total += n_nonzero[i]; - } - - // Allocate memory and fill in Adolc sparsity pattern - CppAD::vector adolc_pattern(m); - CppAD::vector adolc_memory(m + n_nonzero_total); - size_t i_memory = 0; - for(i = 0; i < m; i++) - { adolc_pattern[i] = adolc_memory.data() + i_memory; - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= n_nonzero[i], - "Matrix is too large for colpack" - ); - adolc_pattern[i][0] = static_cast( n_nonzero[i] ); - typename VectorSet::const_iterator pattern_itr(pattern, i); - j = *pattern_itr; - k = 1; - while(j != pattern.end() ) - { - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= j, - "Matrix is too large for colpack" - ); - adolc_pattern[i][k++] = static_cast( j ); - j = *(++pattern_itr); - } - CPPAD_ASSERT_UNKNOWN( k == 1 + n_nonzero[i] ); - i_memory += k; - } - CPPAD_ASSERT_UNKNOWN( i_memory == m + n_nonzero_total ); - - // Must use an external routine for this part of the calculation because - // ColPack/ColPackHeaders.h has as 'using namespace std' at global level. - cppad_colpack_general(color, m, n, adolc_pattern); - - return; -} -# endif // CPPAD_HAS_COLPACK - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/color_symmetric.hpp b/external/cppad/include/cppad/local/color_symmetric.hpp deleted file mode 100644 index b8dad64da..000000000 --- a/external/cppad/include/cppad/local/color_symmetric.hpp +++ /dev/null @@ -1,344 +0,0 @@ -# ifndef CPPAD_LOCAL_COLOR_SYMMETRIC_HPP -# define CPPAD_LOCAL_COLOR_SYMMETRIC_HPP - -# include -# include - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file color_symmetric.hpp -Coloring algorithm for a symmetric sparse matrix. -*/ -// -------------------------------------------------------------------------- -/*! -CppAD algorithm for determining which rows of a symmetric sparse matrix can be -computed together. - -\tparam VectorSize -is a simple vector class with elements of type size_t. - -\tparam VectorSet -is an unspecified type with the exception that it must support the -operations under pattern and the following operations where -p is a VectorSet object: -\n -VectorSet p -Constructs a new vector of sets object. -\n -p.resize(ns, ne) -resizes \c p to ns sets with elements between zero and \c ne. -All of the sets are initially empty. -\n -p.add_element(s, e) -add element \c e to set with index \c s. - -\param pattern [in] -Is a representation of the sparsity pattern for the matrix. -\n -m = pattern.n_set() -\n -sets m to the number of rows (and columns) in the sparse matrix. -All of the row indices are less than this value. -\n -n = pattern.end() -\n -sets n to the number of columns in the sparse matrix -(which must be equal to the number of rows). -All of the column indices are less than this value. -\n -VectorSet::const_iterator itr(pattern, i) -constructs an iterator that starts iterating over -columns in the i-th row of the sparsity pattern. -\n -j = *itr -Sets j to the next possibly non-zero column. -\n -++itr -Advances to the next possibly non-zero column. -\n - -\param row [in/out] -is a vector specifying which row indices to compute. - -\param col [in/out] -is a vector, with the same size as row, -that specifies which column indices to compute. -\n -\n -Input: -For each valid index \c k, the index pair -(row[k], col[k]) must be present in the sparsity pattern. -It may be that some entries in the sparsity pattern do not need to be computed; -i.e, do not appear in the set of -(row[k], col[k]) entries. -\n -\n -Output: -On output, some of row and column indices may have been swapped -\code - std::swap( row[k], col[k] ) -\endcode -So the the the color for row[k] can be used to compute entry -(row[k], col[k]). - -\param color [out] -is a vector with size m. -The input value of its elements does not matter. -Upon return, it is a coloring for the rows of the sparse matrix. -Note that if color[i] == m, then there is no index k for which -row[k] == i (for the return value of row). -\n -\n -Fix any (i, j) in the sparsity pattern. -Suppose that there is a row index i1 with -i1 != i, color[i1] == color[i] and (i1, j) is in the sparsity pattern. -If follows that for all j1 with -j1 != j and color[j1] == color[j], -(j1, i ) is not in the sparsity pattern. -\n -\n -This routine tries to minimize, with respect to the choice of colors, -the maximum, with respect to k, of color[ row[k] ]. -*/ -template -void color_symmetric_cppad( - const VectorSet& pattern , - CppAD::vector& row , - CppAD::vector& col , - CppAD::vector& color ) -{ size_t o1, o2, i1, i2, j1, j2, k1, c1, c2; - - size_t K = row.size(); - size_t m = pattern.n_set(); - CPPAD_ASSERT_UNKNOWN( m == pattern.end() ); - CPPAD_ASSERT_UNKNOWN( color.size() == m ); - CPPAD_ASSERT_UNKNOWN( col.size() == K ); - - // row, column pairs that appear in ( row[k], col[k] ) - CppAD::vector< std::set > pair_needed(m); - std::set::iterator itr1, itr2; - for(k1 = 0; k1 < K; k1++) - { CPPAD_ASSERT_UNKNOWN( pattern.is_element(row[k1], col[k1]) ); - pair_needed[ row[k1] ].insert( col[k1] ); - pair_needed[ col[k1] ].insert( row[k1] ); - } - - // order the rows decending by number of pairs needed - CppAD::vector key(m), order2row(m); - for(i1 = 0; i1 < m; i1++) - { CPPAD_ASSERT_UNKNOWN( pair_needed[i1].size() <= m ); - key[i1] = m - pair_needed[i1].size(); - } - CppAD::index_sort(key, order2row); - - // mapping from order index to row index - CppAD::vector row2order(m); - for(o1 = 0; o1 < m; o1++) - row2order[ order2row[o1] ] = o1; - - // initial coloring - color.resize(m); - c1 = 0; - for(o1 = 0; o1 < m; o1++) - { i1 = order2row[o1]; - if( pair_needed[i1].empty() ) - color[i1] = m; - else - color[i1] = c1++; - } - - // which colors are forbidden for this row - CppAD::vector forbidden(m); - - // must start with row zero so that we remove results computed for it - for(o1 = 0; o1 < m; o1++) // for each row that appears (in order) - if( color[ order2row[o1] ] < m ) - { i1 = order2row[o1]; - c1 = color[i1]; - - // initial all colors as ok for this row - // (value of forbidden for c > c1 does not matter) - for(c2 = 0; c2 <= c1; c2++) - forbidden[c2] = false; - - // ----------------------------------------------------- - // Forbid grouping with rows that would destroy results that are - // needed for this row. - itr1 = pair_needed[i1].begin(); - while( itr1 != pair_needed[i1].end() ) - { // entry (i1, j1) is needed for this row - j1 = *itr1; - - // Forbid rows i2 != i1 that have non-zero sparsity at (i2, j1). - // Note that this is the same as non-zero sparsity at (j1, i2) - typename VectorSet::const_iterator pattern_itr(pattern, j1); - i2 = *pattern_itr; - while( i2 != pattern.end() ) - { c2 = color[i2]; - if( c2 < c1 ) - forbidden[c2] = true; - i2 = *(++pattern_itr); - } - itr1++; - } - // ----------------------------------------------------- - // Forbid grouping with rows that this row would destroy results for - for(o2 = 0; o2 < o1; o2++) - { i2 = order2row[o2]; - c2 = color[i2]; - itr2 = pair_needed[i2].begin(); - while( itr2 != pair_needed[i2].end() ) - { j2 = *itr2; - // row i2 needs pair (i2, j2). - // Forbid grouping with i1 if (i1, j2) has non-zero sparsity - if( pattern.is_element(i1, j2) ) - forbidden[c2] = true; - itr2++; - } - } - - // pick the color with smallest index - c2 = 0; - while( forbidden[c2] ) - { c2++; - CPPAD_ASSERT_UNKNOWN( c2 <= c1 ); - } - color[i1] = c2; - - // no longer need results that are computed by this row - itr1 = pair_needed[i1].begin(); - while( itr1 != pair_needed[i1].end() ) - { j1 = *itr1; - if( row2order[j1] > o1 ) - { itr2 = pair_needed[j1].find(i1); - if( itr2 != pair_needed[j1].end() ) - { pair_needed[j1].erase(itr2); - if( pair_needed[j1].empty() ) - color[j1] = m; - } - } - itr1++; - } - } - - // determine which sparsity entries need to be reflected - for(k1 = 0; k1 < row.size(); k1++) - { i1 = row[k1]; - j1 = col[k1]; - itr1 = pair_needed[i1].find(j1); - if( itr1 == pair_needed[i1].end() ) - { row[k1] = j1; - col[k1] = i1; -# ifndef NDEBUG - itr1 = pair_needed[j1].find(i1); - CPPAD_ASSERT_UNKNOWN( itr1 != pair_needed[j1].end() ); -# endif - } - } - return; -} - -// -------------------------------------------------------------------------- -/*! -Colpack algorithm for determining which rows of a symmetric sparse matrix -can be computed together. - -\copydetails CppAD::local::color_symmetric_cppad -*/ -template -void color_symmetric_colpack( - const VectorSet& pattern , - CppAD::vector& row , - CppAD::vector& col , - CppAD::vector& color ) -{ -# if ! CPPAD_HAS_COLPACK - CPPAD_ASSERT_UNKNOWN(false); - return; -# else - size_t i, j, k; - size_t m = pattern.n_set(); - CPPAD_ASSERT_UNKNOWN( m == pattern.end() ); - CPPAD_ASSERT_UNKNOWN( row.size() == col.size() ); - - // Determine number of non-zero entries in each row - CppAD::vector n_nonzero(m); - size_t n_nonzero_total = 0; - for(i = 0; i < m; i++) - { n_nonzero[i] = 0; - typename VectorSet::const_iterator pattern_itr(pattern, i); - j = *pattern_itr; - while( j != pattern.end() ) - { n_nonzero[i]++; - j = *(++pattern_itr); - } - n_nonzero_total += n_nonzero[i]; - } - - // Allocate memory and fill in Adolc sparsity pattern - CppAD::vector adolc_pattern(m); - CppAD::vector adolc_memory(m + n_nonzero_total); - size_t i_memory = 0; - for(i = 0; i < m; i++) - { adolc_pattern[i] = adolc_memory.data() + i_memory; - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= n_nonzero[i], - "Matrix is too large for colpack" - ); - adolc_pattern[i][0] = static_cast( n_nonzero[i] ); - typename VectorSet::const_iterator pattern_itr(pattern, i); - j = *pattern_itr; - k = 1; - while(j != pattern.end() ) - { - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= j, - "Matrix is too large for colpack" - ); - adolc_pattern[i][k++] = static_cast( j ); - j = *(++pattern_itr); - } - CPPAD_ASSERT_UNKNOWN( k == 1 + n_nonzero[i] ); - i_memory += k; - } - CPPAD_ASSERT_UNKNOWN( i_memory == m + n_nonzero_total ); - - // Must use an external routine for this part of the calculation because - // ColPack/ColPackHeaders.h has as 'using namespace std' at global level. - cppad_colpack_symmetric(color, m, adolc_pattern); - - // determine which sparsity entries need to be reflected - size_t i1, i2, j1, j2, k1, k2; - for(k1 = 0; k1 < row.size(); k1++) - { i1 = row[k1]; - j1 = col[k1]; - bool reflect = false; - for(i2 = 0; i2 < m; i2++) if( (i1 != i2) & (color[i1]==color[i2]) ) - { for(k2 = 1; k2 <= adolc_pattern[i2][0]; k2++) - { j2 = adolc_pattern[i2][k2]; - reflect |= (j1 == j2); - } - } - if( reflect ) - { row[k1] = j1; - col[k1] = i1; - } - } - return; -# endif // CPPAD_HAS_COLPACK -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/comp_op.hpp b/external/cppad/include/cppad/local/comp_op.hpp deleted file mode 100644 index 5bf83735a..000000000 --- a/external/cppad/include/cppad/local/comp_op.hpp +++ /dev/null @@ -1,305 +0,0 @@ -// $Id: comp_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_COMP_OP_HPP -# define CPPAD_LOCAL_COMP_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file comp_op.hpp -Zero order forward mode check how many comparisons changed. -*/ - -// -------------------------------- <= ----------------------------------- -/*! -Zero order forward mode comparison check that left <= right - -\param count -It the condition is not true, ths counter is incremented by one. - -\param arg -parameter[ arg[0] ] is the left operand and -taylor[ arg[1] * cap_order + 0 ] is the zero order Taylor coefficient -for the right operand. - -\param parameter -vector of parameter values. - -\param cap_order -number of Taylor coefficients allocated for each variable - -\param taylor -vector of taylor coefficients. -*/ -template -inline void forward_lepv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LepvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LepvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base x = parameter[ arg[0] ]; - Base* y = taylor + arg[1] * cap_order; - - count += GreaterThanZero(x - y[0]); -} -/*! -Zero order forward mode comparison check that left <= right - -\param count -It the condition is not true, ths counter is incremented by one. - -\param arg -taylor[ arg[0] * cap_order + 0 ] is the zero order Taylor coefficient -for the left operand and parameter[ arg[1] ] is the right operand - -\param parameter -vector of parameter values. - -\param cap_order -number of Taylor coefficients allocated for each variable - -\param taylor -vector of taylor coefficients. -*/ -template -inline void forward_levp_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LevpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LevpOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base y = parameter[ arg[1] ]; - - count += GreaterThanZero(x[0] - y); -} -/*! -Zero order forward mode comparison check that left <= right - -\param count -It the condition is not true, ths counter is incremented by one. - -\param arg -taylor[ arg[0] * cap_order + 0 ] is the zero order Taylor coefficient -for the left operand and -taylor[ arg[1] * cap_order + 0 ] is the zero order Taylor coefficient -for the right operand. - -\param parameter -vector of parameter values. - -\param cap_order -number of Taylor coefficients allocated for each variable - -\param taylor -vector of taylor coefficients. -*/ -template -inline void forward_levv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LevvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LevvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - - count += GreaterThanZero(x[0] - y[0]); -} -// ------------------------------- < ------------------------------------- -/*! -Zero order forward mode comparison check that left < right - -\copydetails CppAD::local::forward_lepv_op_0 -*/ -template -inline void forward_ltpv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LtpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LtpvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base x = parameter[ arg[0] ]; - Base* y = taylor + arg[1] * cap_order; - - count += GreaterThanOrZero(x - y[0]); -} -/*! -Zero order forward mode comparison check that left < right - -\copydetails CppAD::local::forward_levp_op_0 -*/ -template -inline void forward_ltvp_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LtvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LtvpOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base y = parameter[ arg[1] ]; - - count += GreaterThanOrZero(x[0] - y); -} -/*! -Zero order forward mode comparison check that left < right - -\copydetails CppAD::local::forward_levv_op_0 -*/ -template -inline void forward_ltvv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LtvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LtvvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - - count += GreaterThanOrZero(x[0] - y[0]); -} -// ------------------------------ == ------------------------------------- -/*! -Zero order forward mode comparison check that left == right - -\copydetails CppAD::local::forward_lepv_op_0 -*/ -template -inline void forward_eqpv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(EqpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(EqpvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base x = parameter[ arg[0] ]; - Base* y = taylor + arg[1] * cap_order; - - count += (x != y[0]); -} -/*! -Zero order forward mode comparison check that left == right - -\copydetails CppAD::local::forward_levv_op_0 -*/ -template -inline void forward_eqvv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(EqvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(EqvvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - - count += (x[0] != y[0]); -} -// -------------------------------- != ----------------------------------- -/*! -Zero order forward mode comparison check that left != right - -\copydetails CppAD::local::forward_lepv_op_0 -*/ -template -inline void forward_nepv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(NepvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(NepvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base x = parameter[ arg[0] ]; - Base* y = taylor + arg[1] * cap_order; - - count += (x == y[0]); -} -/*! -Zero order forward mode comparison check that left != right - -\copydetails CppAD::local::forward_levv_op_0 -*/ -template -inline void forward_nevv_op_0( - size_t& count , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(NevvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(NevvOp) == 0 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - - count += (x[0] == y[0]); -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/cond_op.hpp b/external/cppad/include/cppad/local/cond_op.hpp deleted file mode 100644 index 7a5c9d1e9..000000000 --- a/external/cppad/include/cppad/local/cond_op.hpp +++ /dev/null @@ -1,1313 +0,0 @@ -// $Id: cond_op.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_COND_OP_HPP -# define CPPAD_LOCAL_COND_OP_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file cond_op.hpp -Forward, reverse, and sparse operations for conditional expressions. -*/ - -/*! -Shared documentation for conditional expressions (not called). - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\param parameter -For j = 0, 1, 2, 3, -if y_j is a parameter, \a parameter [ arg[2 + j] ] is its value. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - -*/ -template -inline void conditional_exp_op( - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order ) -{ // This routine is only for documentation, it should never be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Shared documentation for conditional expression sparse operations (not called). - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - -*/ -template -inline void sparse_conditional_exp_op( - size_t i_z , - const addr_t* arg , - size_t num_par ) -{ // This routine is only for documentation, it should never be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Compute forward mode Taylor coefficients for op = CExpOp. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\param parameter -For j = 0, 1, 2, 3, -if y_j is a parameter, \a parameter [ arg[2 + j] ] is its value. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - -\param p -is the lowest order of the Taylor coefficient of z that we are computing. - -\param q -is the highest order of the Taylor coefficient of z that we are computing. - -\param taylor -\b Input: -For j = 0, 1, 2, 3 and k = 0 , ... , q, -if y_j is a variable then -taylor [ arg[2+j] * cap_order + k ] -is the k-th order Taylor coefficient corresponding to y_j. -\n -\b Input: taylor [ i_z * cap_order + k ] -for k = 0 , ... , p-1, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Output: taylor [ i_z * cap_order + k ] -for k = p , ... , q, -is the k-th order Taylor coefficient corresponding to z. - -*/ -template -inline void forward_cond_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ Base y_0, y_1, y_2, y_3; - Base zero(0); - Base* z = taylor + i_z * cap_order; - - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); - - if( arg[1] & 1 ) - { - y_0 = taylor[ arg[2] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - y_0 = parameter[ arg[2] ]; - } - if( arg[1] & 2 ) - { - y_1 = taylor[ arg[3] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); - y_1 = parameter[ arg[3] ]; - } - if( p == 0 ) - { if( arg[1] & 4 ) - { - y_2 = taylor[ arg[4] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_par ); - y_2 = parameter[ arg[4] ]; - } - if( arg[1] & 8 ) - { - y_3 = taylor[ arg[5] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < num_par ); - y_3 = parameter[ arg[5] ]; - } - z[0] = CondExpOp( - CompareOp( arg[0] ), - y_0, - y_1, - y_2, - y_3 - ); - p++; - } - for(size_t d = p; d <= q; d++) - { if( arg[1] & 4 ) - { - y_2 = taylor[ arg[4] * cap_order + d]; - } - else y_2 = zero; - if( arg[1] & 8 ) - { - y_3 = taylor[ arg[5] * cap_order + d]; - } - else y_3 = zero; - z[d] = CondExpOp( - CompareOp( arg[0] ), - y_0, - y_1, - y_2, - y_3 - ); - } - return; -} - -/*! -Multiple directions forward mode Taylor coefficients for op = CExpOp. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\param parameter -For j = 0, 1, 2, 3, -if y_j is a parameter, \a parameter [ arg[2 + j] ] is its value. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - -\param q -is order of the Taylor coefficient of z that we are computing. - -\param r -is the number of Taylor coefficient directions that we are computing. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: -For j = 0, 1, 2, 3, k = 1, ..., q, -if y_j is a variable then -taylor [ arg[2+j] * tpv + 0 ] -is the zero order Taylor coefficient corresponding to y_j and -taylor [ arg[2+j] * tpv + (k-1)*r+1+ell is its -k-th order Taylor coefficient in the ell-th direction. -\n -\b Input: -For j = 0, 1, 2, 3, k = 1, ..., q-1, -taylor [ i_z * tpv + 0 ] -is the zero order Taylor coefficient corresponding to z and -taylor [ i_z * tpv + (k-1)*r+1+ell is its -k-th order Taylor coefficient in the ell-th direction. -\n -\b Output: taylor [ i_z * tpv + (q-1)*r+1+ell ] -is the q-th order Taylor coefficient corresponding to z -in the ell-th direction. -*/ -template -inline void forward_cond_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ Base y_0, y_1, y_2, y_3; - Base zero(0); - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* z = taylor + i_z * num_taylor_per_var; - - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - if( arg[1] & 1 ) - { - y_0 = taylor[ arg[2] * num_taylor_per_var + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - y_0 = parameter[ arg[2] ]; - } - if( arg[1] & 2 ) - { - y_1 = taylor[ arg[3] * num_taylor_per_var + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); - y_1 = parameter[ arg[3] ]; - } - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { if( arg[1] & 4 ) - { - y_2 = taylor[ arg[4] * num_taylor_per_var + m + ell]; - } - else y_2 = zero; - if( arg[1] & 8 ) - { - y_3 = taylor[ arg[5] * num_taylor_per_var + m + ell]; - } - else y_3 = zero; - z[m+ell] = CondExpOp( - CompareOp( arg[0] ), - y_0, - y_1, - y_2, - y_3 - ); - } - return; -} - -/*! -Compute zero order forward mode Taylor coefficients for op = CExpOp. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\param parameter -For j = 0, 1, 2, 3, -if y_j is a parameter, \a parameter [ arg[2 + j] ] is its value. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - -\param taylor -\b Input: -For j = 0, 1, 2, 3, -if y_j is a variable then -\a taylor [ \a arg[2+j] * cap_order + 0 ] -is the zero order Taylor coefficient corresponding to y_j. -\n -\b Output: \a taylor [ \a i_z * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z. -*/ -template -inline void forward_cond_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ Base y_0, y_1, y_2, y_3; - Base* z; - - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); - - if( arg[1] & 1 ) - { - y_0 = taylor[ arg[2] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - y_0 = parameter[ arg[2] ]; - } - if( arg[1] & 2 ) - { - y_1 = taylor[ arg[3] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); - y_1 = parameter[ arg[3] ]; - } - if( arg[1] & 4 ) - { - y_2 = taylor[ arg[4] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_par ); - y_2 = parameter[ arg[4] ]; - } - if( arg[1] & 8 ) - { - y_3 = taylor[ arg[5] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < num_par ); - y_3 = parameter[ arg[5] ]; - } - z = taylor + i_z * cap_order; - z[0] = CondExpOp( - CompareOp( arg[0] ), - y_0, - y_1, - y_2, - y_3 - ); - return; -} - -/*! -Compute reverse mode Taylor coefficients for op = CExpOp. - -This routine is given the partial derivatives of a function -G( z , y , x , w , ... ) -and it uses them to compute the partial derivatives of -\verbatim - H( y , x , w , u , ... ) = G[ z(y) , y , x , w , u , ... ] -\endverbatim -where y above represents y_0, y_1, y_2, y_3. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\param parameter -For j = 0, 1, 2, 3, -if y_j is a parameter, \a parameter [ arg[2 + j] ] is its value. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - -\param d -is the order of the Taylor coefficient of z that we are computing. - -\param taylor -\b Input: -For j = 0, 1, 2, 3 and k = 0 , ... , \a d, -if y_j is a variable then -\a taylor [ \a arg[2+j] * cap_order + k ] -is the k-th order Taylor coefficient corresponding to y_j. -\n -\a taylor [ \a i_z * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to z. - -\param nc_partial -number of columns in the matrix containing the Taylor coefficients. - -\param partial -\b Input: -For j = 0, 1, 2, 3 and k = 0 , ... , \a d, -if y_j is a variable then -\a partial [ \a arg[2+j] * nc_partial + k ] -is the partial derivative of G( z , y , x , w , u , ... ) -with respect to the k-th order Taylor coefficient corresponding to y_j. -\n -\b Input: \a partial [ \a i_z * \a cap_order + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , y , x , w , u , ... ) -with respect to the k-th order Taylor coefficient corresponding to z. -\n -\b Output: -For j = 0, 1, 2, 3 and k = 0 , ... , \a d, -if y_j is a variable then -\a partial [ \a arg[2+j] * nc_partial + k ] -is the partial derivative of H( y , x , w , u , ... ) -with respect to the k-th order Taylor coefficient corresponding to y_j. - -*/ -template -inline void reverse_cond_op( - size_t d , - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ Base y_0, y_1; - Base zero(0); - Base* pz; - Base* py_2; - Base* py_3; - - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); - - pz = partial + i_z * nc_partial + 0; - if( arg[1] & 1 ) - { - y_0 = taylor[ arg[2] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - y_0 = parameter[ arg[2] ]; - } - if( arg[1] & 2 ) - { - y_1 = taylor[ arg[3] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); - y_1 = parameter[ arg[3] ]; - } - if( arg[1] & 4 ) - { - py_2 = partial + arg[4] * nc_partial; - size_t j = d + 1; - while(j--) - { py_2[j] += CondExpOp( - CompareOp( arg[0] ), - y_0, - y_1, - pz[j], - zero - ); - } - } - if( arg[1] & 8 ) - { - py_3 = partial + arg[5] * nc_partial; - size_t j = d + 1; - while(j--) - { py_3[j] += CondExpOp( - CompareOp( arg[0] ), - y_0, - y_1, - zero, - pz[j] - ); - } - } - return; -} - -/*! -Compute forward Jacobian sparsity patterns for op = CExpOp. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param sparsity -\b Input: -if y_2 is a variable, the set with index t is -the sparsity pattern corresponding to y_2. -This identifies which of the independent variables the variable y_2 -depends on. -\n -\b Input: -if y_3 is a variable, the set with index t is -the sparsity pattern corresponding to y_3. -This identifies which of the independent variables the variable y_3 -depends on. -\n -\b Output: -The set with index T is -the sparsity pattern corresponding to z. -This identifies which of the independent variables the variable z -depends on. -*/ -template -inline void forward_sparse_jacobian_cond_op( - bool dependency , - size_t i_z , - const addr_t* arg , - size_t num_par , - Vector_set& sparsity ) -{ - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); -# ifndef NDEBUG - size_t k = 1; - for( size_t j = 0; j < 4; j++) - { if( ! ( arg[1] & k ) ) - CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par ); - k *= 2; - } -# endif - sparsity.clear(i_z); - if( dependency ) - { if( arg[1] & 1 ) - sparsity.binary_union(i_z, i_z, arg[2], sparsity); - if( arg[1] & 2 ) - sparsity.binary_union(i_z, i_z, arg[3], sparsity); - } - if( arg[1] & 4 ) - sparsity.binary_union(i_z, i_z, arg[4], sparsity); - if( arg[1] & 8 ) - sparsity.binary_union(i_z, i_z, arg[5], sparsity); - return; -} - -/*! -Compute reverse Jacobian sparsity patterns for op = CExpOp. - -This routine is given the sparsity patterns -for a function G(z, y, x, ... ) -and it uses them to compute the sparsity patterns for -\verbatim - H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ] -\endverbatim -where y represents the combination of y_0, y_1, y_2, and y_3. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - - -\param sparsity -if y_2 is a variable, the set with index t is -the sparsity pattern corresponding to y_2. -This identifies which of the dependent variables depend on the variable y_2. -On input, this pattern corresponds to the function G. -On ouput, it corresponds to the function H. -\n -\n -if y_3 is a variable, the set with index t is -the sparsity pattern corresponding to y_3. -This identifies which of the dependent variables depeond on the variable y_3. -On input, this pattern corresponds to the function G. -On ouput, it corresponds to the function H. -\n -\b Output: -The set with index T is -the sparsity pattern corresponding to z. -This identifies which of the dependent variables depend on the variable z. -On input and output, this pattern corresponds to the function G. -*/ -template -inline void reverse_sparse_jacobian_cond_op( - bool dependency , - size_t i_z , - const addr_t* arg , - size_t num_par , - Vector_set& sparsity ) -{ - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); -# ifndef NDEBUG - size_t k = 1; - for( size_t j = 0; j < 4; j++) - { if( ! ( arg[1] & k ) ) - CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par ); - k *= 2; - } -# endif - if( dependency ) - { if( arg[1] & 1 ) - sparsity.binary_union(arg[2], arg[2], i_z, sparsity); - if( arg[1] & 2 ) - sparsity.binary_union(arg[3], arg[3], i_z, sparsity); - } - // -------------------------------------------------------------------- - if( arg[1] & 4 ) - sparsity.binary_union(arg[4], arg[4], i_z, sparsity); - if( arg[1] & 8 ) - sparsity.binary_union(arg[5], arg[5], i_z, sparsity); - return; -} - -/*! -Compute reverse Hessian sparsity patterns for op = CExpOp. - -This routine is given the sparsity patterns -for a function G(z, y, x, ... ) -and it uses them to compute the sparsity patterns for -\verbatim - H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ] -\endverbatim -where y represents the combination of y_0, y_1, y_2, and y_3. - - -The C++ source code coresponding to this operation is -\verbatim - z = CondExpRel(y_0, y_1, y_2, y_3) -\endverbatim -where Rel is one of the following: Lt, Le, Eq, Ge, Gt. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, y_0 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, y_1 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 4 -\n -If this is zero, y_2 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] & 8 -\n -If this is zero, y_3 is a parameter. Otherwise it is a variable. -\n -\n -\a arg[2 + j ] for j = 0, 1, 2, 3 -\n -is the index corresponding to y_j. - -\param num_par -is the total number of values in the vector \a parameter. - -\par Checked Assertions -\li NumArg(CExpOp) == 6 -\li NumRes(CExpOp) == 1 -\li arg[0] < static_cast ( CompareNe ) -\li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters. -\li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par. - - - -\param jac_reverse -\a jac_reverse[i_z] -is false (true) if the Jacobian of G with respect to z is always zero -(may be non-zero). -\n -\n -\a jac_reverse[ arg[4] ] -If y_2 is a variable, -\a jac_reverse[ arg[4] ] -is false (true) if the Jacobian with respect to y_2 is always zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. -\n -\n -\a jac_reverse[ arg[5] ] -If y_3 is a variable, -\a jac_reverse[ arg[5] ] -is false (true) if the Jacobian with respect to y_3 is always zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. - -\param hes_sparsity -The set with index \a i_z in \a hes_sparsity -is the Hessian sparsity pattern for the function G -where one of the partials is with respect to z. -\n -\n -If y_2 is a variable, -the set with index \a arg[4] in \a hes_sparsity -is the Hessian sparsity pattern -where one of the partials is with respect to y_2. -On input, this pattern corresponds to the function G. -On output, this pattern corresponds to the function H. -\n -\n -If y_3 is a variable, -the set with index \a arg[5] in \a hes_sparsity -is the Hessian sparsity pattern -where one of the partials is with respect to y_3. -On input, this pattern corresponds to the function G. -On output, this pattern corresponds to the function H. -*/ -template -inline void reverse_sparse_hessian_cond_op( - size_t i_z , - const addr_t* arg , - size_t num_par , - bool* jac_reverse , - Vector_set& hes_sparsity ) -{ - - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast (CompareNe) ); - CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); -# ifndef NDEBUG - size_t k = 1; - for( size_t j = 0; j < 4; j++) - { if( ! ( arg[1] & k ) ) - CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par ); - k *= 2; - } -# endif - if( arg[1] & 4 ) - { - hes_sparsity.binary_union(arg[4], arg[4], i_z, hes_sparsity); - jac_reverse[ arg[4] ] |= jac_reverse[i_z]; - } - if( arg[1] & 8 ) - { - hes_sparsity.binary_union(arg[5], arg[5], i_z, hes_sparsity); - jac_reverse[ arg[5] ] |= jac_reverse[i_z]; - } - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/cos_op.hpp b/external/cppad/include/cppad/local/cos_op.hpp deleted file mode 100644 index be93f756e..000000000 --- a/external/cppad/include/cppad/local/cos_op.hpp +++ /dev/null @@ -1,238 +0,0 @@ -# ifndef CPPAD_LOCAL_COS_OP_HPP -# define CPPAD_LOCAL_COS_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file cos_op.hpp -Forward and reverse mode calculations for z = cos(x). -*/ - -/*! -Compute forward mode Taylor coefficient for result of op = CosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cos(x) -\endverbatim -The auxillary result is -\verbatim - y = sin(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_cos_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* c = taylor + i_z * cap_order; - Base* s = c - cap_order; - - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op. - // (except that there is a sign difference for the hyperbolic case). - size_t k; - if( p == 0 ) - { s[0] = sin( x[0] ); - c[0] = cos( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - s[j] = Base(0.0); - c[j] = Base(0.0); - for(k = 1; k <= j; k++) - { s[j] += Base(double(k)) * x[k] * c[j-k]; - c[j] -= Base(double(k)) * x[k] * s[j-k]; - } - s[j] /= Base(double(j)); - c[j] /= Base(double(j)); - } -} -/*! -Compute forward mode Taylor coefficient for result of op = CosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cos(x) -\endverbatim -The auxillary result is -\verbatim - y = sin(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_cos_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* c = taylor + i_z * num_taylor_per_var; - Base* s = c - num_taylor_per_var; - - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op - // (except that there is a sign difference for the hyperbolic case). - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { s[m+ell] = Base(double(q)) * x[m + ell] * c[0]; - c[m+ell] = - Base(double(q)) * x[m + ell] * s[0]; - for(size_t k = 1; k < q; k++) - { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell]; - c[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell]; - } - s[m+ell] /= Base(double(q)); - c[m+ell] /= Base(double(q)); - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = CosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cos(x) -\endverbatim -The auxillary result is -\verbatim - y = sin(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_cos_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* c = taylor + i_z * cap_order; // called z in documentation - Base* s = c - cap_order; // called y in documentation - - c[0] = cos( x[0] ); - s[0] = sin( x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = CosOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cos(x) -\endverbatim -The auxillary result is -\verbatim - y = sin(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_cos_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* c = taylor + i_z * cap_order; // called z in doc - Base* pc = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* s = c - cap_order; // called y in documentation - Base* ps = pc - nc_partial; - - - // rest of this routine is identical for the following cases: - // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op. - size_t j = d; - size_t k; - while(j) - { - ps[j] /= Base(double(j)); - pc[j] /= Base(double(j)); - for(k = 1; k <= j; k++) - { - px[k] += Base(double(k)) * azmul(ps[j], c[j-k]); - px[k] -= Base(double(k)) * azmul(pc[j], s[j-k]); - - ps[j-k] -= Base(double(k)) * azmul(pc[j], x[k]); - pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]); - - } - --j; - } - px[0] += azmul(ps[0], c[0]); - px[0] -= azmul(pc[0], s[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/cosh_op.hpp b/external/cppad/include/cppad/local/cosh_op.hpp deleted file mode 100644 index 38a7ef6a2..000000000 --- a/external/cppad/include/cppad/local/cosh_op.hpp +++ /dev/null @@ -1,238 +0,0 @@ -# ifndef CPPAD_LOCAL_COSH_OP_HPP -# define CPPAD_LOCAL_COSH_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file cosh_op.hpp -Forward and reverse mode calculations for z = cosh(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = CoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sinh(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_cosh_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* c = taylor + i_z * cap_order; - Base* s = c - cap_order; - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op. - // (except that there is a sign difference for hyperbolic case). - size_t k; - if( p == 0 ) - { s[0] = sinh( x[0] ); - c[0] = cosh( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - s[j] = Base(0.0); - c[j] = Base(0.0); - for(k = 1; k <= j; k++) - { s[j] += Base(double(k)) * x[k] * c[j-k]; - c[j] += Base(double(k)) * x[k] * s[j-k]; - } - s[j] /= Base(double(j)); - c[j] /= Base(double(j)); - } -} -/*! -Compute forward mode Taylor coefficient for result of op = CoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sinh(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_cosh_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* s = taylor + i_z * num_taylor_per_var; - Base* c = s - num_taylor_per_var; - - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op - // (except that there is a sign difference for the hyperbolic case). - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { s[m+ell] = Base(double(q)) * x[m + ell] * c[0]; - c[m+ell] = Base(double(q)) * x[m + ell] * s[0]; - for(size_t k = 1; k < q; k++) - { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell]; - c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell]; - } - s[m+ell] /= Base(double(q)); - c[m+ell] /= Base(double(q)); - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = CoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sinh(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_cosh_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* c = taylor + i_z * cap_order; // called z in documentation - Base* s = c - cap_order; // called y in documentation - - c[0] = cosh( x[0] ); - s[0] = sinh( x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = CoshOp. - -The C++ source code corresponding to this operation is -\verbatim - z = cosh(x) -\endverbatim -The auxillary result is -\verbatim - y = sinh(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_cosh_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* c = taylor + i_z * cap_order; // called z in doc - Base* pc = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* s = c - cap_order; // called y in documentation - Base* ps = pc - nc_partial; - - - // rest of this routine is identical for the following cases: - // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op. - size_t j = d; - size_t k; - while(j) - { - ps[j] /= Base(double(j)); - pc[j] /= Base(double(j)); - for(k = 1; k <= j; k++) - { - px[k] += Base(double(k)) * azmul(ps[j], c[j-k]); - px[k] += Base(double(k)) * azmul(pc[j], s[j-k]); - - ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]); - pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]); - - } - --j; - } - px[0] += azmul(ps[0], c[0]); - px[0] += azmul(pc[0], s[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/cppad_colpack.hpp b/external/cppad/include/cppad/local/cppad_colpack.hpp deleted file mode 100644 index 9481ed120..000000000 --- a/external/cppad/include/cppad/local/cppad_colpack.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// $Id: cppad_colpack.hpp 3845 2016-11-19 01:50:47Z bradbell $ -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# ifndef CPPAD_LOCAL_CPPAD_COLPACK_HPP -# define CPPAD_LOCAL_CPPAD_COLPACK_HPP -# if CPPAD_HAS_COLPACK - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file cppad_colpack.hpp -External interface to Colpack routines used by cppad. -*/ -// --------------------------------------------------------------------------- -/*! -Link from CppAD to ColPack used for general sparse matrices. - -This CppAD library routine is necessary because -ColPack/ColPackHeaders.h has a -using namespace std at the global level. - -\param m [in] -is the number of rows in the sparse matrix - -\param n [in] -is the nubmer of columns in the sparse matrix. - -\param adolc_pattern [in] -This vector has size \c m, -adolc_pattern[i][0] is the number of non-zeros in row \c i. -For j = 1 , ... , adolc_sparsity[i], -adolc_pattern[i][j] is the column index (base zero) for the -non-zeros in row \c i. - -\param color [out] -is a vector with size \c m. -The input value of its elements does not matter. -Upon return, it is a coloring for the rows of the sparse matrix. -\n -\n -If for some \c i, color[i] == m, then -adolc_pattern[i][0] == 0. -Otherwise, color[i] < m. -\n -\n -Suppose two differen rows, i != r have the same color. -It follows that for all column indices \c j; -it is not the case that both -(i, j) and (r, j) appear in the sparsity pattern. -\n -\n -This routine tries to minimize, with respect to the choice of colors, -the number of colors. -*/ -extern void cppad_colpack_general( - CppAD::vector& color , - size_t m , - size_t n , - const CppAD::vector& adolc_pattern -); - -/*! -Link from CppAD to ColPack used for symmetric sparse matrices -(not yet used or tested). - -This CppAD library routine is necessary because -ColPack/ColPackHeaders.h has a -using namespace std at the global level. - -\param n [in] -is the nubmer of rows and columns in the symmetric sparse matrix. - -\param adolc_pattern [in] -This vector has size \c n, -adolc_pattern[i][0] is the number of non-zeros in row \c i. -For j = 1 , ... , adolc_sparsity[i], -adolc_pattern[i][j] is the column index (base zero) for the -non-zeros in row \c i. - -\param color [out] -The input value of its elements does not matter. -Upon return, it is a coloring for the rows of the sparse matrix. -The properties of this coloring have not yet been determined; see -Efficient Computation of Sparse Hessians Using Coloring -and Automatic Differentiation (pdf/ad/gebemedhin14.pdf) -*/ -extern void cppad_colpack_symmetric( - CppAD::vector& color , - size_t n , - const CppAD::vector& adolc_pattern -); - -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif -# endif - diff --git a/external/cppad/include/cppad/local/cskip_op.hpp b/external/cppad/include/cppad/local/cskip_op.hpp deleted file mode 100644 index 3e4f82ae2..000000000 --- a/external/cppad/include/cppad/local/cskip_op.hpp +++ /dev/null @@ -1,200 +0,0 @@ -# ifndef CPPAD_LOCAL_CSKIP_OP_HPP -# define CPPAD_LOCAL_CSKIP_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file cskip_op.hpp -Zero order forward mode set which operations to skip. -*/ - -/*! -Zero order forward mode execution of op = CSkipOp. - -\par Parameters and Variables -The terms parameter and variable depend on if we are referring to its -AD or Base value. -We use Base parameter and Base variable to refer to the -correspond Base value. -We use AD parameter and AD variable to refer to the -correspond AD value. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD and computations by this routine are done using type Base. - -\param i_z -variable index corresponding to the result of the previous operation. -This is used for error checking. To be specific, -the left and right operands for the CExpOp operation must have indexes -less than or equal this value. - -\param arg [in] -\n -\a arg[0] -is static cast to size_t from the enum type -\verbatim - enum CompareOp { - CompareLt, - CompareLe, - CompareEq, - CompareGe, - CompareGt, - CompareNe - } -\endverbatim -for this operation. -Note that arg[0] cannot be equal to CompareNe. -\n -\n -\a arg[1] & 1 -\n -If this is zero, left is an AD parameter. -Otherwise it is an AD variable. -\n -\n -\a arg[1] & 2 -\n -If this is zero, right is an AD parameter. -Otherwise it is an AD variable. -\n -\a arg[2] -is the index corresponding to left in comparision. -\n -\a arg[3] -is the index corresponding to right in comparision. -\n -\a arg[4] -is the number of operations to skip if the comparision result is true. -\n -\a arg[5] -is the number of operations to skip if the comparision result is false. -\n -arg[5+i] -for i = 1 , ... , arg[4] are the operations to skip if the -comparision result is true and both left and right are -identically Base parameters. -\n -arg[5+arg[4]+i] -for i = 1 , ... , arg[5] are the operations to skip if the -comparision result is false and both left and right are -identically Base parameters. - -\param num_par [in] -is the total number of values in the vector parameter. - -\param parameter [in] -If left is an AD parameter, -parameter [ arg[2] ] is its value. -If right is an AD parameter, -parameter [ arg[3] ] is its value. - -\param cap_order [in] -number of columns in the matrix containing the Taylor coefficients. - -\param taylor [in] -If left is an AD variable, -taylor [ arg[2] * cap_order + 0 ] -is the zeroth order Taylor coefficient corresponding to left. -If right is an AD variable, -taylor [ arg[3] * cap_order + 0 ] -is the zeroth order Taylor coefficient corresponding to right. - -\param cskip_op [in,out] -is vector specifying which operations are at this point are know to be -unecessary and can be skipped. -This is both an input and an output. -*/ -template -inline void forward_cskip_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor , - bool* cskip_op ) -{ - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < size_t(CompareNe) ); - CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); - - Base left, right; - if( arg[1] & 1 ) - { // If variable arg[2] <= i_z, it has already been computed, - // but it will be skipped for higher orders. - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) <= i_z ); - left = taylor[ arg[2] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - left = parameter[ arg[2] ]; - } - if( arg[1] & 2 ) - { // If variable arg[3] <= i_z, it has already been computed, - // but it will be skipped for higher orders. - CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= i_z ); - right = taylor[ arg[3] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); - right = parameter[ arg[3] ]; - } - bool ok_to_skip = IdenticalPar(left) & IdenticalPar(right); - if( ! ok_to_skip ) - return; - - // initialize to avoid compiler warning - bool true_case = false; - Base diff = left - right; - switch( CompareOp( arg[0] ) ) - { - case CompareLt: - true_case = LessThanZero(diff); - break; - - case CompareLe: - true_case = LessThanOrZero(diff); - break; - - case CompareEq: - true_case = IdenticalZero(diff); - break; - - case CompareGe: - true_case = GreaterThanOrZero(diff); - break; - - case CompareGt: - true_case = GreaterThanZero(diff); - break; - - case CompareNe: - true_case = ! IdenticalZero(diff); - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - if( true_case ) - { for(size_t i = 0; i < size_t(arg[4]); i++) - cskip_op[ arg[6+i] ] = true; - } - else - { for(size_t i = 0; i < size_t(arg[5]); i++) - cskip_op[ arg[6+arg[4]+i] ] = true; - } - return; -} -} } // END_CPPAD_LOCAL_NAMESPACE -# endif - diff --git a/external/cppad/include/cppad/local/csum_op.hpp b/external/cppad/include/cppad/local/csum_op.hpp deleted file mode 100644 index 9ab0bace1..000000000 --- a/external/cppad/include/cppad/local/csum_op.hpp +++ /dev/null @@ -1,623 +0,0 @@ -// $Id: csum_op.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_CSUM_OP_HPP -# define CPPAD_LOCAL_CSUM_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file csum_op.hpp -Forward, reverse and sparsity calculations for cummulative summation. -*/ - -/*! -Compute forward mode Taylor coefficients for result of op = CsumOp. - -This operation is -\verbatim - z = s + x(1) + ... + x(m) - y(1) - ... - y(n). -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param p -lowest order of the Taylor coefficient that we are computing. - -\param q -highest order of the Taylor coefficient that we are computing. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -is the number of addition variables in this cummulative summation; i.e., -m. -\n -\a arg[1] -is the number of subtraction variables in this cummulative summation; i.e., -\c m. -\n -parameter[ arg[2] ] -is the parameter value \c s in this cummunative summation. -\n -arg[2+i] -for i = 1 , ... , m is the variable index of x(i). -\n -arg[2+arg[0]+i] -for i = 1 , ... , n is the variable index of y(i). - -\param num_par -is the number of parameters in \a parameter. - -\param parameter -is the parameter vector for this operation sequence. - -\param cap_order -number of colums in the matrix containing all the Taylor coefficients. - -\param taylor -\b Input: taylor [ arg[2+i] * cap_order + k ] -for i = 1 , ... , m -and k = 0 , ... , q -is the k-th order Taylor coefficient corresponding to x(i) -\n -\b Input: taylor [ arg[2+m+i] * cap_order + k ] -for i = 1 , ... , n -and k = 0 , ... , q -is the k-th order Taylor coefficient corresponding to y(i) -\n -\b Input: taylor [ i_z * cap_order + k ] -for k = 0 , ... , p, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Output: taylor [ i_z * cap_order + k ] -for k = p , ... , q, -is the \a k-th order Taylor coefficient corresponding to z. -*/ -template -inline void forward_csum_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ Base zero(0); - size_t i, j, k; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - CPPAD_ASSERT_UNKNOWN( - arg[0] + arg[1] == arg[ arg[0] + arg[1] + 3 ] - ); - - // Taylor coefficients corresponding to result - Base* z = taylor + i_z * cap_order; - for(k = p; k <= q; k++) - z[k] = zero; - if( p == 0 ) - z[p] = parameter[ arg[2] ]; - Base* x; - i = arg[0]; - j = 2; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - x = taylor + arg[++j] * cap_order; - for(k = p; k <= q; k++) - z[k] += x[k]; - } - i = arg[1]; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - x = taylor + arg[++j] * cap_order; - for(k = p; k <= q; k++) - z[k] -= x[k]; - } -} - -/*! -Multiple direction forward mode Taylor coefficients for op = CsumOp. - -This operation is -\verbatim - z = s + x(1) + ... + x(m) - y(1) - ... - y(n). -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD and computations by this routine are done using type -\a Base. - -\param q -order ot the Taylor coefficients that we are computing. - -\param r -number of directions for Taylor coefficients that we are computing. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -is the number of addition variables in this cummulative summation; i.e., -m. -\n -\a arg[1] -is the number of subtraction variables in this cummulative summation; i.e., -\c m. -\n -parameter[ arg[2] ] -is the parameter value \c s in this cummunative summation. -\n -arg[2+i] -for i = 1 , ... , m is the variable index of x(i). -\n -arg[2+arg[0]+i] -for i = 1 , ... , n is the variable index of y(i). - -\param num_par -is the number of parameters in \a parameter. - -\param parameter -is the parameter vector for this operation sequence. - -\param cap_order -number of colums in the matrix containing all the Taylor coefficients. - -\param taylor -\b Input: taylor [ arg[2+i]*((cap_order-1)*r + 1) + 0 ] -for i = 1 , ... , m -is the 0-th order Taylor coefficient corresponding to x(i) and -taylor [ arg[2+i]*((cap_order-1)*r + 1) + (q-1)*r + ell + 1 ] -for i = 1 , ... , m, -ell = 0 , ... , r-1 -is the q-th order Taylor coefficient corresponding to x(i) -and direction ell. -\n -\b Input: taylor [ arg[2+m+i]*((cap_order-1)*r + 1) + 0 ] -for i = 1 , ... , n -is the 0-th order Taylor coefficient corresponding to y(i) and -taylor [ arg[2+m+i]*((cap_order-1)*r + 1) + (q-1)*r + ell + 1 ] -for i = 1 , ... , n, -ell = 0 , ... , r-1 -is the q-th order Taylor coefficient corresponding to y(i) -and direction ell. -\n -\b Output: taylor [ i_z*((cap_order-1)*r+1) + (q-1)*r + ell + 1 ] -is the \a q-th order Taylor coefficient corresponding to z -for direction ell = 0 , ... , r-1. -*/ -template -inline void forward_csum_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ Base zero(0); - size_t i, j, ell; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - CPPAD_ASSERT_UNKNOWN( - arg[0] + arg[1] == arg[ arg[0] + arg[1] + 3 ] - ); - - // Taylor coefficients corresponding to result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1)*r + 1; - Base* z = taylor + i_z * num_taylor_per_var + m; - for(ell = 0; ell < r; ell++) - z[ell] = zero; - Base* x; - i = arg[0]; - j = 2; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - x = taylor + arg[++j] * num_taylor_per_var + m; - for(ell = 0; ell < r; ell++) - z[ell] += x[ell]; - } - i = arg[1]; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - x = taylor + arg[++j] * num_taylor_per_var + m; - for(ell = 0; ell < r; ell++) - z[ell] -= x[ell]; - } -} - -/*! -Compute reverse mode Taylor coefficients for result of op = CsumOp. - -This operation is -\verbatim - z = q + x(1) + ... + x(m) - y(1) - ... - y(n). - H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ] -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param d -order the highest order Taylor coefficient that we are computing -the partial derivatives with respect to. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -is the number of addition variables in this cummulative summation; i.e., -m. -\n -\a arg[1] -is the number of subtraction variables in this cummulative summation; i.e., -\c m. -\n -parameter[ arg[2] ] -is the parameter value \c q in this cummunative summation. -\n -arg[2+i] -for i = 1 , ... , m is the value x(i). -\n -arg[2+arg[0]+i] -for i = 1 , ... , n is the value y(i). - -\param nc_partial -number of colums in the matrix containing all the partial derivatives. - -\param partial -\b Input: partial [ arg[2+i] * nc_partial + k ] -for i = 1 , ... , m -and k = 0 , ... , d -is the partial derivative of G(z, y, x, w, ...) with respect to the -k-th order Taylor coefficient corresponding to x(i) -\n -\b Input: partial [ arg[2+m+i] * nc_partial + k ] -for i = 1 , ... , n -and k = 0 , ... , d -is the partial derivative of G(z, y, x, w, ...) with respect to the -k-th order Taylor coefficient corresponding to y(i) -\n -\b Input: partial [ i_z * nc_partial + k ] -for i = 1 , ... , n -and k = 0 , ... , d -is the partial derivative of G(z, y, x, w, ...) with respect to the -k-th order Taylor coefficient corresponding to \c z. -\n -\b Output: partial [ arg[2+i] * nc_partial + k ] -for i = 1 , ... , m -and k = 0 , ... , d -is the partial derivative of H(y, x, w, ...) with respect to the -k-th order Taylor coefficient corresponding to x(i) -\n -\b Output: partial [ arg[2+m+i] * nc_partial + k ] -for i = 1 , ... , n -and k = 0 , ... , d -is the partial derivative of H(y, x, w, ...) with respect to the -k-th order Taylor coefficient corresponding to y(i) -*/ - -template -inline void reverse_csum_op( - size_t d , - size_t i_z , - const addr_t* arg , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partial derivative corresponding to result - Base* pz = partial + i_z * nc_partial; - Base* px; - size_t i, j, k; - size_t d1 = d + 1; - i = arg[0]; - j = 2; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - px = partial + arg[++j] * nc_partial; - k = d1; - while(k--) - px[k] += pz[k]; - } - i = arg[1]; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - px = partial + arg[++j] * nc_partial; - k = d1; - while(k--) - px[k] -= pz[k]; - } -} - - -/*! -Forward mode Jacobian sparsity pattern for CSumOp operator. - -This operation is -\verbatim - z = q + x(1) + ... + x(m) - y(1) - ... - y(n). -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the index in \a sparsity corresponding to z. - -\param arg -\a arg[0] -is the number of addition variables in this cummulative summation; i.e., -m + n. -\n -\a arg[1] -is the number of subtraction variables in this cummulative summation; i.e., -\c m. -\n -parameter[ arg[2] ] -is the parameter value \c q in this cummunative summation. -\n -arg[2+i] -for i = 1 , ... , m is the value x(i). -\n -arg[2+arg[1]+i] -for i = 1 , ... , n is the value y(i). - -\param sparsity -\b Input: -For i = 1 , ... , m, -the set with index \a arg[2+i] in \a sparsity -is the sparsity bit pattern for x(i). -This identifies which of the independent variables the variable -x(i) depends on. -\n -\b Input: -For i = 1 , ... , n, -the set with index \a arg[2+arg[0]+i] in \a sparsity -is the sparsity bit pattern for x(i). -This identifies which of the independent variables the variable -y(i) depends on. -\n -\b Output: -The set with index \a i_z in \a sparsity -is the sparsity bit pattern for z. -This identifies which of the independent variables the variable z -depends on. -*/ - -template -inline void forward_sparse_jacobian_csum_op( - size_t i_z , - const addr_t* arg , - Vector_set& sparsity ) -{ sparsity.clear(i_z); - - size_t i, j; - i = arg[0] + arg[1]; - j = 2; - while(i--) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[j+1]) < i_z ); - sparsity.binary_union( - i_z , // index in sparsity for result - i_z , // index in sparsity for left operand - arg[++j] , // index for right operand - sparsity // sparsity vector for right operand - ); - } -} - -/*! -Reverse mode Jacobian sparsity pattern for CSumOp operator. - -This operation is -\verbatim - z = q + x(1) + ... + x(m) - y(1) - ... - y(n). - H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ] -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the index in \a sparsity corresponding to z. - -\param arg -\a arg[0] -is the number of addition variables in this cummulative summation; i.e., -m + n. -\n -\a arg[1] -is the number of subtraction variables in this cummulative summation; i.e., -\c m. -\n -parameter[ arg[2] ] -is the parameter value \c q in this cummunative summation. -\n -arg[2+i] -for i = 1 , ... , m is the value x(i). -\n -arg[2+arg[1]+i] -for i = 1 , ... , n is the value y(i). - -\param sparsity -For i = 1 , ... , m, -the set with index \a arg[2+i] in \a sparsity -is the sparsity bit pattern for x(i). -This identifies which of the dependent variables depend on x(i). -On input, the sparsity patter corresponds to \c G, -and on ouput it corresponds to \c H. -\n -For i = 1 , ... , m, -the set with index \a arg[2+arg[0]+i] in \a sparsity -is the sparsity bit pattern for y(i). -This identifies which of the dependent variables depend on y(i). -On input, the sparsity patter corresponds to \c G, -and on ouput it corresponds to \c H. -\n -\b Input: -The set with index \a i_z in \a sparsity -is the sparsity bit pattern for z. -On input it corresponds to \c G and on output it is undefined. -*/ - -template -inline void reverse_sparse_jacobian_csum_op( - size_t i_z , - const addr_t* arg , - Vector_set& sparsity ) -{ - size_t i, j; - i = arg[0] + arg[1]; - j = 2; - while(i--) - { ++j; - CPPAD_ASSERT_UNKNOWN( size_t(arg[j]) < i_z ); - sparsity.binary_union( - arg[j] , // index in sparsity for result - arg[j] , // index in sparsity for left operand - i_z , // index for right operand - sparsity // sparsity vector for right operand - ); - } -} -/*! -Reverse mode Hessian sparsity pattern for CSumOp operator. - -This operation is -\verbatim - z = q + x(1) + ... + x(m) - y(1) - ... - y(n). - H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ] -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the index in \a sparsity corresponding to z. - -\param arg -\a arg[0] -is the number of addition variables in this cummulative summation; i.e., -m + n. -\n -\a arg[1] -is the number of subtraction variables in this cummulative summation; i.e., -\c m. -\n -parameter[ arg[2] ] -is the parameter value \c q in this cummunative summation. -\n -arg[2+i] -for i = 1 , ... , m is the value x(i). -\n -arg[2+arg[0]+i] -for i = 1 , ... , n is the value y(i). - -\param rev_jacobian -rev_jacobian[i_z] -is all false (true) if the Jabobian of G with respect to z must be zero -(may be non-zero). -\n -\n -For i = 1 , ... , m -rev_jacobian[ arg[2+i] ] -is all false (true) if the Jacobian with respect to x(i) -is zero (may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. -\n -\n -For i = 1 , ... , n -rev_jacobian[ arg[2+arg[0]+i] ] -is all false (true) if the Jacobian with respect to y(i) -is zero (may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. - -\param rev_hes_sparsity -The set with index \a i_z in in \a rev_hes_sparsity -is the Hessian sparsity pattern for the fucntion G -where one of the partials derivative is with respect to z. -\n -\n -For i = 1 , ... , m -The set with index arg[2+i] in \a rev_hes_sparsity -is the Hessian sparsity pattern -where one of the partials derivative is with respect to x(i). -On input, it corresponds to the function G, -and on output it corresponds to the function H. -\n -\n -For i = 1 , ... , n -The set with index arg[2+arg[0]+i] in \a rev_hes_sparsity -is the Hessian sparsity pattern -where one of the partials derivative is with respect to y(i). -On input, it corresponds to the function G, -and on output it corresponds to the function H. -*/ - -template -inline void reverse_sparse_hessian_csum_op( - size_t i_z , - const addr_t* arg , - bool* rev_jacobian , - Vector_set& rev_hes_sparsity ) -{ - size_t i, j; - i = arg[0] + arg[1]; - j = 2; - while(i--) - { ++j; - CPPAD_ASSERT_UNKNOWN( size_t(arg[j]) < i_z ); - rev_hes_sparsity.binary_union( - arg[j] , // index in sparsity for result - arg[j] , // index in sparsity for left operand - i_z , // index for right operand - rev_hes_sparsity // sparsity vector for right operand - ); - rev_jacobian[arg[j]] |= rev_jacobian[i_z]; - } -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/declare_ad.hpp b/external/cppad/include/cppad/local/declare_ad.hpp deleted file mode 100644 index 4f5a798f2..000000000 --- a/external/cppad/include/cppad/local/declare_ad.hpp +++ /dev/null @@ -1,177 +0,0 @@ -# ifndef CPPAD_LOCAL_DECLARE_AD_HPP -# define CPPAD_LOCAL_DECLARE_AD_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# if CPPAD_USE_CPLUSPLUS_2011 -# include -# endif - -/*! -\file declare_ad.hpp CppAD forward declarations; i.e., before definition -*/ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE - -template class ADTape; -template class player; -template class recorder; - -} } // END_CPPAD_LOCAL_NAMESPACE - -namespace CppAD { - // The conditional expression operator enum type - enum CompareOp - { CompareLt, // less than - CompareLe, // less than or equal - CompareEq, // equal - CompareGe, // greater than or equal - CompareGt, // greater than - CompareNe // not equal - }; - - // simple typedefs - typedef CPPAD_TAPE_ADDR_TYPE addr_t; - typedef CPPAD_TAPE_ID_TYPE tape_id_t; - - // classes - class sparse_hes_work; - class sparse_jac_work; - class sparse_jacobian_work; - class sparse_hessian_work; - template class AD; - template class ADFun; - template class atomic_base; - template class discrete; - template class VecAD; - template class VecAD_reference; - - // functions with one VecAD argument - template bool Parameter (const VecAD &u); - template bool Variable (const VecAD &u); - - // functions with one AD argument - template int Integer (const AD &u); - template bool Parameter (const AD &u); - template bool Variable (const AD &u); - template bool IdenticalZero (const AD &u); - template bool IdenticalOne (const AD &u); - template bool IdenticalPar (const AD &u); - template bool LessThanZero (const AD &u); - template bool LessThanOrZero (const AD &u); - template bool GreaterThanZero (const AD &u); - template bool GreaterThanOrZero (const AD &u); - template AD Var2Par (const AD &u); - template AD abs (const AD &u); - template AD acos (const AD &u); - template AD asin (const AD &u); - template AD atan (const AD &u); - template AD cos (const AD &u); - template AD cosh (const AD &u); - template AD exp (const AD &u); - template AD log (const AD &u); - template AD log10 (const AD &u); - template AD sin (const AD &u); - template AD sinh (const AD &u); - template AD sqrt (const AD &u); - template AD tan (const AD &u); - - // arithematic operators - template AD operator + ( - const AD &left, const AD &right); - template AD operator - ( - const AD &left, const AD &right); - template AD operator * ( - const AD &left, const AD &right); - template AD operator / ( - const AD &left, const AD &right); - - // comparison operators - template bool operator < ( - const AD &left, const AD &right); - template bool operator <= ( - const AD &left, const AD &right); - template bool operator > ( - const AD &left, const AD &right); - template bool operator >= ( - const AD &left, const AD &right); - template bool operator == ( - const AD &left, const AD &right); - template bool operator != ( - const AD &left, const AD &right); - - // pow - template AD pow ( - const AD &x, const AD &y); - - // azmul - template AD azmul ( - const AD &x, const AD &y); - - // NearEqual - template bool NearEqual( - const AD &x, const AD &y, const Base &r, const Base &a); - - template bool NearEqual( - const Base &x, const AD &y, const Base &r, const Base &a); - - template bool NearEqual( - const AD &x, const Base &y, const Base &r, const Base &a); - - // CondExpOp - template AD CondExpOp ( - enum CompareOp cop , - const AD &left , - const AD &right , - const AD &trueCase , - const AD &falseCase - ); - - // IdenticalEqualPar - template - bool IdenticalEqualPar (const AD &u, const AD &v); - - // EqualOpSeq - template - bool EqualOpSeq (const AD &u, const AD &v); - - // PrintFor - template - void PrintFor( - const AD& flag , - const char* before , - const AD& var , - const char* after - ); - - // Value - template Base Value(const AD &x); - - // Pow function - template AD pow - (const AD &x, const AD &y); - - // input operator - template std::istream& - operator >> (std::istream &is, AD &x); - - // output operator - template std::ostream& - operator << (std::ostream &os, const AD &x); - template std::ostream& - operator << (std::ostream &os, const VecAD_reference &e); - template std::ostream& - operator << (std::ostream &os, const VecAD &vec); -} - -# endif diff --git a/external/cppad/include/cppad/local/discrete_op.hpp b/external/cppad/include/cppad/local/discrete_op.hpp deleted file mode 100644 index 46ed927f1..000000000 --- a/external/cppad/include/cppad/local/discrete_op.hpp +++ /dev/null @@ -1,121 +0,0 @@ -# ifndef CPPAD_LOCAL_DISCRETE_OP_HPP -# define CPPAD_LOCAL_DISCRETE_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file discrete_op.hpp -Forward mode for z = f(x) where f is piecewise constant. -*/ - - -/*! -forward mode Taylor coefficient for result of op = DisOp. - -The C++ source code corresponding to this operation is -\verbatim - z = f(x) -\endverbatim -where f is a piecewise constant function (and it's derivative is always -calculated as zero). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param p -is the lowest order Taylor coefficient that will be calculated. - -\param q -is the highest order Taylor coefficient that will be calculated. - -\param r -is the number of directions, for each order, -that will be calculated (except for order zero wich only has one direction). - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -\n -is the index, in the order of the discrete functions defined by the user, -for this discrete function. -\n -\n -\a arg[1] -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the taylor array. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: taylor [ arg[1] * tpv + 0 ] -is the zero order Taylor coefficient corresponding to x. -\n -\b Output: if p == 0 -taylor [ i_z * tpv + 0 ] -is the zero order Taylor coefficient corresponding to z. -For k = max(p, 1), ... , q, -taylor [ i_z * tpv + (k-1)*r + 1 + ell ] -is the k-th order Taylor coefficient corresponding to z -(which is zero). - -\par Checked Assertions where op is the unary operator with one result: -\li NumArg(op) == 2 -\li NumRes(op) == 1 -\li q < cap_order -\li 0 < r -*/ -template -inline void forward_dis_op( - size_t p , - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DisOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DisOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < r ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[1] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - if( p == 0 ) - { z[0] = discrete::eval(arg[0], x[0]); - p++; - } - for(size_t ell = 0; ell < r; ell++) - for(size_t k = p; k <= q; k++) - z[ (k-1) * r + 1 + ell ] = Base(0.0); -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/div_op.hpp b/external/cppad/include/cppad/local/div_op.hpp deleted file mode 100644 index f271d7db2..000000000 --- a/external/cppad/include/cppad/local/div_op.hpp +++ /dev/null @@ -1,574 +0,0 @@ -# ifndef CPPAD_LOCAL_DIV_OP_HPP -# define CPPAD_LOCAL_DIV_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file div_op.hpp -Forward and reverse mode calculations for z = x / y. -*/ - -// --------------------------- Divvv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_divvv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - - // Using CondExp, it can make sense to divide by zero, - // so do not make it an error. - size_t k; - for(size_t d = p; d <= q; d++) - { z[d] = x[d]; - for(k = 1; k <= d; k++) - z[d] -= z[d-k] * y[k]; - z[d] /= y[0]; - } -} -/*! -Multiple directions forward mode Taylor coefficients for op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_divvv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* y = taylor + arg[1] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - - // Using CondExp, it can make sense to divide by zero, - // so do not make it an error. - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = x[m+ell] - z[0] * y[m+ell]; - for(size_t k = 1; k < q; k++) - z[m+ell] -= z[(q-k-1)*r+1+ell] * y[(k-1)*r+1+ell]; - z[m+ell] /= y[0]; - } -} - - -/*! -Compute zero order forward mode Taylor coefficients for result of op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_divvv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x[0] / y[0]; -} - -/*! -Compute reverse mode partial derivatives for result of op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_divvv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - const Base* y = taylor + arg[1] * cap_order; - const Base* z = taylor + i_z * cap_order; - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // Using CondExp, it can make sense to divide by zero - // so do not make it an error. - Base inv_y0 = Base(1.0) / y[0]; - - size_t k; - // number of indices to access - size_t j = d + 1; - while(j) - { --j; - // scale partial w.r.t. z[j] - pz[j] = azmul(pz[j], inv_y0); - - px[j] += pz[j]; - for(k = 1; k <= j; k++) - { pz[j-k] -= azmul(pz[j], y[k] ); - py[k] -= azmul(pz[j], z[j-k]); - } - py[0] -= azmul(pz[j], z[j]); - } -} - -// --------------------------- Divpv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = DivpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_divpv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Using CondExp, it can make sense to divide by zero, - // so do not make it an error. - size_t k; - if( p == 0 ) - { z[0] = x / y[0]; - p++; - } - for(size_t d = p; d <= q; d++) - { z[d] = Base(0.0); - for(k = 1; k <= d; k++) - z[d] -= z[d-k] * y[k]; - z[d] /= y[0]; - } -} -/*! -Multiple directions forward mode Taylor coefficients for op = DivpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_divpv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* y = taylor + arg[1] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - // Using CondExp, it can make sense to divide by zero, - // so do not make it an error. - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = - z[0] * y[m+ell]; - for(size_t k = 1; k < q; k++) - z[m+ell] -= z[(q-k-1)*r+1+ell] * y[(k-1)*r+1+ell]; - z[m+ell] /= y[0]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = DivpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_divpv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 ); - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x / y[0]; -} - -/*! -Compute reverse mode partial derivative for result of op = DivpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_divpv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - const Base* y = taylor + arg[1] * cap_order; - const Base* z = taylor + i_z * cap_order; - - // Partial derivatives corresponding to arguments and result - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // Using CondExp, it can make sense to divide by zero so do not - // make it an error. - Base inv_y0 = Base(1.0) / y[0]; - - size_t k; - // number of indices to access - size_t j = d + 1; - while(j) - { --j; - // scale partial w.r.t z[j] - pz[j] = azmul(pz[j], inv_y0); - - for(k = 1; k <= j; k++) - { pz[j-k] -= azmul(pz[j], y[k] ); - py[k] -= azmul(pz[j], z[j-k] ); - } - py[0] -= azmul(pz[j], z[j]); - } -} - - -// --------------------------- Divvp ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_divvp_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Parameter value - Base y = parameter[ arg[1] ]; - - // Using CondExp and multiple levels of AD, it can make sense - // to divide by zero so do not make it an error. - for(size_t d = p; d <= q; d++) - z[d] = x[d] / y; -} -/*! -Multiple direction forward mode Taylor coefficients for op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_divvp_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - // Parameter value - Base y = parameter[ arg[1] ]; - - // Using CondExp and multiple levels of AD, it can make sense - // to divide by zero so do not make it an error. - size_t m = (q-1)*r + 1; - for(size_t ell = 0; ell < r; ell++) - z[m + ell] = x[m + ell] / y; -} - - -/*! -Compute zero order forward mode Taylor coefficients for result of op = DivvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_divvp_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 ); - - // Parameter value - Base y = parameter[ arg[1] ]; - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x[0] / y; -} - -/*! -Compute reverse mode partial derivative for result of op = DivvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x / y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_divvp_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Argument values - Base y = parameter[ arg[1] ]; - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // Using CondExp, it can make sense to divide by zero - // so do not make it an error. - Base inv_y = Base(1.0) / y; - - // number of indices to access - size_t j = d + 1; - while(j) - { --j; - px[j] += azmul(pz[j], inv_y); - } -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/erf_op.hpp b/external/cppad/include/cppad/local/erf_op.hpp deleted file mode 100644 index dee316374..000000000 --- a/external/cppad/include/cppad/local/erf_op.hpp +++ /dev/null @@ -1,564 +0,0 @@ -# ifndef CPPAD_LOCAL_ERF_OP_HPP -# define CPPAD_LOCAL_ERF_OP_HPP -# if CPPAD_USE_CPLUSPLUS_2011 - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file erf_op.hpp -Forward and reverse mode calculations for z = erf(x). -*/ - -/*! -Forward mode Taylor coefficient for result of op = ErfOp. - -The C++ source code corresponding to this operation is -\verbatim - z = erf(x) -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param p -lowest order of the Taylor coefficients that we are computing. - -\param q -highest order of the Taylor coefficients that we are computing. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary results are called y_j have index \a i_z - j. - -\param arg -arg[0]: is the variable index corresponding to x. -\n -arg[1]: is the parameter index corresponding to the value zero. -\n -\arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi). - -\param parameter -parameter[ arg[1] ] is the value zero, -and parameter[ arg[2] ] is the value 2 / sqrt(pi). - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: -taylor [ arg[0] * cap_order + k ] -for k = 0 , ... , q, -is the k-th order Taylor coefficient corresponding to x. -\n -\b Input: -taylor [ i_z * cap_order + k ] -for k = 0 , ... , p - 1, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Input: -taylor [ ( i_z - j) * cap_order + k ] -for k = 0 , ... , p-1, -and j = 0 , ... , 4, -is the k-th order Taylor coefficient corresponding to the j-th result for z. -\n -\b Output: -taylor [ (i_z-j) * cap_order + k ], -for k = p , ... , q, -and j = 0 , ... , 4, -is the k-th order Taylor coefficient corresponding to the j-th result for z. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 5 -\li q < cap_order -\li p <= q -\li std::numeric_limits::max() >= i_z + 2 -*/ -template -inline void forward_erf_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ErfOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ErfOp) == 5 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z + 2 ); - - // array used to pass parameter values for sub-operations - addr_t addr[2]; - - // convert from final result to first result - i_z -= 4; // 4 = NumRes(ErfOp) - 1; - - // z_0 = x * x - addr[0] = arg[0]; // x - addr[1] = arg[0]; // x - forward_mulvv_op(p, q, i_z+0, addr, parameter, cap_order, taylor); - - // z_1 = - x * x - addr[0] = arg[1]; // zero - addr[1] = addr_t( i_z ); // z_0 - forward_subpv_op(p, q, i_z+1, addr, parameter, cap_order, taylor); - - // z_2 = exp( - x * x ) - forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor); - - // z_3 = (2 / sqrt(pi)) * exp( - x * x ) - addr[0] = arg[2]; // 2 / sqrt(pi) - addr[1] = addr_t( i_z + 2 ); // z_2 - forward_mulpv_op(p, q, i_z+3, addr, parameter, cap_order, taylor); - - // pointers to taylor coefficients for x , z_3, and z_4 - Base* x = taylor + arg[0] * cap_order; - Base* z_3 = taylor + (i_z+3) * cap_order; - Base* z_4 = taylor + (i_z+4) * cap_order; - - // calculte z_4 coefficients - if( p == 0 ) - { // z4 (t) = erf[x(t)] - z_4[0] = erf(x[0]); - p++; - } - for(size_t j = p; j <= q; j++) - { // z_4' (t) = erf'[x(t)] * x'(t) = z3(t) * x'(t) - // z_4[1] + 2 * z_4[2] * t + ... = - // (z_3[0] + z_3[1] * t + ...) * (x[1] + 2 * x[2] * t + ...) - Base base_j = static_cast(double(j)); - z_4[j] = static_cast(0); - for(size_t k = 1; k <= j; k++) - z_4[j] += (Base(double(k)) / base_j) * x[k] * z_3[j-k]; - } -} - -/*! -Zero order Forward mode Taylor coefficient for result of op = ErfOp. - -The C++ source code corresponding to this operation is -\verbatim - z = erf(x) -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary results are called y_j have index \a i_z - j. - -\param arg -arg[0]: is the variable index corresponding to x. -\n -arg[1]: is the parameter index corresponding to the value zero. -\n -\arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi). - -\param parameter -parameter[ arg[1] ] is the value zero, -and parameter[ arg[2] ] is the value 2 / sqrt(pi). - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: -taylor [ arg[0] * cap_order + 0 ] -is the zero order Taylor coefficient corresponding to x. -\n -\b Input: -taylor [ i_z * cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z. -\n -\b Output: -taylor [ (i_z-j) * cap_order + 0 ], -for j = 0 , ... , 4, -is the zero order Taylor coefficient for j-th result corresponding to z. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 5 -\li q < cap_order -\li p <= q -\li std::numeric_limits::max() >= i_z + 2 -*/ -template -inline void forward_erf_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ErfOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ErfOp) == 5 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z + 2 ); - - // array used to pass parameter values for sub-operations - addr_t addr[2]; - - // convert from final result to first result - i_z -= 4; // 4 = NumRes(ErfOp) - 1; - - // z_0 = x * x - addr[0] = arg[0]; // x - addr[1] = arg[0]; // x - forward_mulvv_op_0(i_z+0, addr, parameter, cap_order, taylor); - - // z_1 = - x * x - addr[0] = arg[1]; // zero - addr[1] = addr_t(i_z); // z_0 - forward_subpv_op_0(i_z+1, addr, parameter, cap_order, taylor); - - // z_2 = exp( - x * x ) - forward_exp_op_0(i_z+2, i_z+1, cap_order, taylor); - - // z_3 = (2 / sqrt(pi)) * exp( - x * x ) - addr[0] = arg[2]; // 2 / sqrt(pi) - addr[1] = addr_t(i_z + 2); // z_2 - forward_mulpv_op_0(i_z+3, addr, parameter, cap_order, taylor); - - // zero order Taylor coefficient for z_4 - Base* x = taylor + arg[0] * cap_order; - Base* z_4 = taylor + (i_z + 4) * cap_order; - z_4[0] = erf(x[0]); -} -/*! -Forward mode Taylor coefficient for result of op = ErfOp. - -The C++ source code corresponding to this operation is -\verbatim - z = erf(x) -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param q -order of the Taylor coefficients that we are computing. - -\param r -number of directions for the Taylor coefficients that we afre computing. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary results have index i_z - j for j = 0 , ... , 4 -(and include z). - -\param arg -arg[0]: is the variable index corresponding to x. -\n -arg[1]: is the parameter index corresponding to the value zero. -\n -\arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi). - -\param parameter -parameter[ arg[1] ] is the value zero, -and parameter[ arg[2] ] is the value 2 / sqrt(pi). - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: If x is a variable, -taylor [ arg[0] * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to x and the ell-th direction. -\n -\b Input: -taylor [ (i_z - j) * tpv + 0 ] -is the zero order Taylor coefficient for all directions and the -j-th result for z. -for k = 1 , ... , q-1, -ell = 0, ... , r-1, - -taylor[ (i_z - j) * tpv + (k-1)*r + ell + 1] - -is the Taylor coefficient for the k-th order, ell-th direction, -and j-th auzillary result. -\n -\b Output: -taylor [ (i_z-j) * tpv + (q-1)*r + ell + 1 ], -for ell = 0 , ... , r-1, -is the Taylor coefficient for the q-th order, ell-th direction, -and j-th auzillary result. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 5 -\li 0 < q < cap_order -*/ -template -inline void forward_erf_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ErfOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ErfOp) == 5 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z + 2 ); - - // array used to pass parameter values for sub-operations - addr_t addr[2]; - - // convert from final result to first result - i_z -= 4; // 4 = NumRes(ErfOp) - 1; - - // z_0 = x * x - addr[0] = arg[0]; // x - addr[1] = arg[0]; // x - forward_mulvv_op_dir(q, r, i_z+0, addr, parameter, cap_order, taylor); - - // z_1 = - x * x - addr[0] = arg[1]; // zero - addr[1] = addr_t( i_z ); // z_0 - forward_subpv_op_dir(q, r, i_z+1, addr, parameter, cap_order, taylor); - - // z_2 = exp( - x * x ) - forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor); - - // z_3 = (2 / sqrt(pi)) * exp( - x * x ) - addr[0] = arg[2]; // 2 / sqrt(pi) - addr[1] = addr_t( i_z + 2 ); // z_2 - forward_mulpv_op_dir(q, r, i_z+3, addr, parameter, cap_order, taylor); - - // pointers to taylor coefficients for x , z_3, and z_4 - size_t num_taylor_per_var = (cap_order - 1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* z_3 = taylor + (i_z+3) * num_taylor_per_var; - Base* z_4 = taylor + (i_z+4) * num_taylor_per_var; - - // z_4' (t) = erf'[x(t)] * x'(t) = z3(t) * x'(t) - // z_4[1] + 2 * z_4[2] * t + ... = - // (z_3[0] + z_3[1] * t + ...) * (x[1] + 2 * x[2] * t + ...) - Base base_q = static_cast(double(q)); - for(size_t ell = 0; ell < r; ell++) - { // index in z_4 and x for q-th order term - size_t m = (q-1)*r + ell + 1; - // initialize q-th order term summation - z_4[m] = z_3[0] * x[m]; - for(size_t k = 1; k < q; k++) - { size_t x_index = (k-1)*r + ell + 1; - size_t z3_index = (q-k-1)*r + ell + 1; - z_4[m] += (Base(double(k)) / base_q) * x[x_index] * z_3[z3_index]; - } - } -} - -/*! -Compute reverse mode partial derivatives for result of op = ErfOp. - -The C++ source code corresponding to this operation is -\verbatim - z = erf(x) -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param d -highest order Taylor of the Taylor coefficients that we are computing -the partial derivatives with respect to. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary results are called y_j have index \a i_z - j. - -\param arg -arg[0]: is the variable index corresponding to x. -\n -arg[1]: is the parameter index corresponding to the value zero. -\n -\arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi). - -\param parameter -parameter[ arg[1] ] is the value zero, -and parameter[ arg[2] ] is the value 2 / sqrt(pi). - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: -taylor [ arg[0] * cap_order + k ] -for k = 0 , ... , d, -is the k-th order Taylor coefficient corresponding to x. -\n -taylor [ (i_z - j) * cap_order + k ] -for k = 0 , ... , d, -and for j = 0 , ... , 4, -is the k-th order Taylor coefficient corresponding to the j-th result -for this operation. - -\param nc_partial -number of columns in the matrix containing all the partial derivatives - -\param partial -\b Input: -partial [ arg[0] * nc_partial + k ] -for k = 0 , ... , d, -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Input: -partial [ (i_z - j) * nc_partial + k ] -for k = 0 , ... , d, -and for j = 0 , ... , 4, -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for the j-th result of this operation. -\n -\b Output: -partial [ arg[0] * nc_partial + k ] -for k = 0 , ... , d, -is the partial derivative of H( x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Output: -partial [ (i_z-j) * nc_partial + k ] -for k = 0 , ... , d, -and for j = 0 , ... , 4, -may be used as work space; i.e., may change in an unspecified manner. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 5 -\li q < cap_order -\li p <= q -*/ -template -inline void reverse_erf_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ErfOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ErfOp) == 5 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z + 2 ); - - // array used to pass parameter values for sub-operations - addr_t addr[2]; - - // If pz is zero, make sure this operation has no effect - // (zero times infinity or nan would be non-zero). - Base* pz = partial + i_z * nc_partial; - bool skip(true); - for(size_t i_d = 0; i_d <= d; i_d++) - skip &= IdenticalZero(pz[i_d]); - if( skip ) - return; - - // convert from final result to first result - i_z -= 4; // 4 = NumRes(ErfOp) - 1; - - // Taylor coefficients and partials corresponding to x - const Base* x = taylor + arg[0] * cap_order; - Base* px = partial + arg[0] * nc_partial; - - // Taylor coefficients and partials corresponding to z_3 - const Base* z_3 = taylor + (i_z+3) * cap_order; - Base* pz_3 = partial + (i_z+3) * nc_partial; - - // Taylor coefficients and partials corresponding to z_4 - Base* pz_4 = partial + (i_z+4) * nc_partial; - - // Reverse z_4 - size_t j = d; - while(j) - { pz_4[j] /= Base(double(j)); - for(size_t k = 1; k <= j; k++) - { px[k] += azmul(pz_4[j], z_3[j-k]) * Base(double(k)); - pz_3[j-k] += azmul(pz_4[j], x[k]) * Base(double(k)); - } - j--; - } - px[0] += azmul(pz_4[0], z_3[0]); - - // z_3 = (2 / sqrt(pi)) * exp( - x * x ) - addr[0] = arg[2]; // 2 / sqrt(pi) - addr[1] = addr_t( i_z + 2 ); // z_2 - reverse_mulpv_op( - d, i_z+3, addr, parameter, cap_order, taylor, nc_partial, partial - ); - - // z_2 = exp( - x * x ) - reverse_exp_op( - d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial - ); - - // z_1 = - x * x - addr[0] = arg[1]; // zero - addr[1] = addr_t( i_z ); // z_0 - reverse_subpv_op( - d, i_z+1, addr, parameter, cap_order, taylor, nc_partial, partial - ); - - // z_0 = x * x - addr[0] = arg[0]; // x - addr[1] = arg[0]; // x - reverse_mulvv_op( - d, i_z+0, addr, parameter, cap_order, taylor, nc_partial, partial - ); - -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif // CPPAD_USE_CPLUSPLUS_2011 -# endif // CPPAD_ERF_OP_INCLUDED diff --git a/external/cppad/include/cppad/local/exp_op.hpp b/external/cppad/include/cppad/local/exp_op.hpp deleted file mode 100644 index 266aa2d7b..000000000 --- a/external/cppad/include/cppad/local/exp_op.hpp +++ /dev/null @@ -1,194 +0,0 @@ -# ifndef CPPAD_LOCAL_EXP_OP_HPP -# define CPPAD_LOCAL_EXP_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file exp_op.hpp -Forward and reverse mode calculations for z = exp(x). -*/ - - -/*! -Forward mode Taylor coefficient for result of op = ExpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = exp(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_exp_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - size_t k; - if( p == 0 ) - { z[0] = exp( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - z[j] = x[1] * z[j-1]; - for(k = 2; k <= j; k++) - z[j] += Base(double(k)) * x[k] * z[j-k]; - z[j] /= Base(double(j)); - } -} - - -/*! -Multiple direction forward mode Taylor coefficient for op = ExpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = exp(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_exp_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t m = (q-1)*r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(double(q)) * x[m+ell] * z[0]; - for(size_t k = 1; k < q; k++) - z[m+ell] += Base(double(k)) * x[(k-1)*r+ell+1] * z[(q-k-1)*r+ell+1]; - z[m+ell] /= Base(double(q)); - } -} - -/*! -Zero order forward mode Taylor coefficient for result of op = ExpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = exp(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_exp_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = exp( x[0] ); -} -/*! -Reverse mode partial derivatives for result of op = ExpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = exp(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_exp_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // If pz is zero, make sure this operation has no effect - // (zero times infinity or nan would be non-zero). - bool skip(true); - for(size_t i_d = 0; i_d <= d; i_d++) - skip &= IdenticalZero(pz[i_d]); - if( skip ) - return; - - // loop through orders in reverse - size_t j, k; - j = d; - while(j) - { // scale partial w.r.t z[j] - pz[j] /= Base(double(j)); - - for(k = 1; k <= j; k++) - { px[k] += Base(double(k)) * azmul(pz[j], z[j-k]); - pz[j-k] += Base(double(k)) * azmul(pz[j], x[k]); - } - --j; - } - px[0] += azmul(pz[0], z[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/expm1_op.hpp b/external/cppad/include/cppad/local/expm1_op.hpp deleted file mode 100644 index af5ea60c0..000000000 --- a/external/cppad/include/cppad/local/expm1_op.hpp +++ /dev/null @@ -1,200 +0,0 @@ -# ifndef CPPAD_LOCAL_EXPM1_OP_HPP -# define CPPAD_LOCAL_EXPM1_OP_HPP -# if CPPAD_USE_CPLUSPLUS_2011 - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file expm1_op.hpp -Forward and reverse mode calculations for z = expm1(x). -*/ - - -/*! -Forward mode Taylor coefficient for result of op = Expm1Op. - -The C++ source code corresponding to this operation is -\verbatim - z = expm1(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_expm1_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - size_t k; - if( p == 0 ) - { z[0] = expm1( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - z[j] = x[1] * z[j-1]; - for(k = 2; k <= j; k++) - z[j] += Base(double(k)) * x[k] * z[j-k]; - z[j] /= Base(double(j)); - z[j] += x[j]; - } -} - - -/*! -Multiple direction forward mode Taylor coefficient for op = Expm1Op. - -The C++ source code corresponding to this operation is -\verbatim - z = expm1(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_expm1_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t m = (q-1)*r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(double(q)) * x[m+ell] * z[0]; - for(size_t k = 1; k < q; k++) - z[m+ell] += Base(double(k)) * x[(k-1)*r+ell+1] * z[(q-k-1)*r+ell+1]; - z[m+ell] /= Base(double(q)); - z[m+ell] += x[m+ell]; - } -} - -/*! -Zero order forward mode Taylor coefficient for result of op = Expm1Op. - -The C++ source code corresponding to this operation is -\verbatim - z = expm1(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_expm1_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = expm1( x[0] ); -} -/*! -Reverse mode partial derivatives for result of op = Expm1Op. - -The C++ source code corresponding to this operation is -\verbatim - z = expm1(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_expm1_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - // If pz is zero, make sure this operation has no effect - // (zero times infinity or nan would be non-zero). - bool skip(true); - for(size_t i_d = 0; i_d <= d; i_d++) - skip &= IdenticalZero(pz[i_d]); - if( skip ) - return; - - // loop through orders in reverse - size_t j, k; - j = d; - while(j) - { px[j] += pz[j]; - - // scale partial w.r.t z[j] - pz[j] /= Base(double(j)); - - for(k = 1; k <= j; k++) - { px[k] += Base(double(k)) * azmul(pz[j], z[j-k]); - pz[j-k] += Base(double(k)) * azmul(pz[j], x[k]); - } - --j; - } - px[0] += pz[0] + azmul(pz[0], z[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif -# endif diff --git a/external/cppad/include/cppad/local/for_hes_sweep.hpp b/external/cppad/include/cppad/local/for_hes_sweep.hpp deleted file mode 100644 index 01f8a098a..000000000 --- a/external/cppad/include/cppad/local/for_hes_sweep.hpp +++ /dev/null @@ -1,572 +0,0 @@ -# ifndef CPPAD_LOCAL_FOR_HES_SWEEP_HPP -# define CPPAD_LOCAL_FOR_HES_SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file for_hes_sweep.hpp -Compute Forward mode Hessian sparsity patterns. -*/ - -/*! -\def CPPAD_FOR_HES_SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every rev_hes_sweep computation is printed. -*/ -# define CPPAD_FOR_HES_SWEEP_TRACE 0 - -/*! -Given the forward Jacobian sparsity pattern for all the variables, -and the reverse Jacobian sparsity pattern for the dependent variables, -ForHesSweep computes the Hessian sparsity pattern for all the independent -variables. - -\tparam Base -base type for the operator; i.e., this operation sequence was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape; i.e., -\a play->num_var_rec(). -This is also the number of rows in the entire sparsity pattern -\a for_hes_sparse. - -\param play -The information stored in \a play -is a recording of the operations corresponding to a function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables -and \f$ m \f$ is the number of dependent variables. -The object \a play is effectly constant. -It is not declared const because while playing back the tape -the object \a play holds information about the current location -with in the tape and this changes during playback. - -\param for_jac_sparse -For i = 0 , ... , \a numvar - 1, -(for all the variables on the tape), -the forward Jacobian sparsity pattern for the variable with index i -corresponds to the set with index i in \a for_jac_sparse. - -\param rev_jac_sparse -\b Input: -For i = 0, ... , \a numvar - 1 -the if the function we are computing the Hessian for has a non-zero -derivative w.r.t. variable with index i, -the set with index i has element zero. -Otherwise it has no elements. - -\param for_hes_sparse -The forward Hessian sparsity pattern for the variable with index i -corresponds to the set with index i in \a for_hes_sparse. -The number of rows in this sparsity patter is n+1 and the row -with index zero is not used. -\n -\n -\b Input: For i = 1 , ... , \a n -the forward Hessian sparsity pattern for the variable with index i is empty. -\n -\n -\b Output: For j = 1 , ... , \a n, -the forward Hessian sparsity pattern for the independent dependent variable -with index (j-1) is given by the set with index j -in \a for_hes_sparse. -*/ - -template -void ForHesSweep( - size_t n, - size_t numvar, - local::player* play, - const Vector_set& for_jac_sparse, - const Vector_set& rev_jac_sparse, - Vector_set& for_hes_sparse -) -{ - OpCode op; - size_t i_op; - size_t i_var; - - const addr_t* arg = CPPAD_NULL; - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - size_t i, j, k; - - // check numvar argument - size_t limit = n+1; - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse.n_set() == numvar ); - CPPAD_ASSERT_UNKNOWN( for_hes_sparse.n_set() == limit ); - CPPAD_ASSERT_UNKNOWN( numvar > 0 ); - - // upper limit exclusive for set elements - CPPAD_ASSERT_UNKNOWN( for_jac_sparse.end() == limit ); - CPPAD_ASSERT_UNKNOWN( for_hes_sparse.end() == limit ); - - // vecad_sparsity contains a sparsity pattern for each VecAD object. - // vecad_ind maps a VecAD index (beginning of the VecAD object) - // to the index for the corresponding set in vecad_sparsity. - size_t num_vecad_ind = play->num_vec_ind_rec(); - size_t num_vecad_vec = play->num_vecad_vec_rec(); - Vector_set vecad_sparse; - vecad_sparse.resize(num_vecad_vec, limit); - pod_vector vecad_ind; - pod_vector vecad_jac; - if( num_vecad_vec > 0 ) - { size_t length; - vecad_ind.extend(num_vecad_ind); - vecad_jac.extend(num_vecad_vec); - j = 0; - for(i = 0; i < num_vecad_vec; i++) - { // length of this VecAD - length = play->GetVecInd(j); - // set vecad_ind to proper index for this VecAD - vecad_ind[j] = i; - // make all other values for this vector invalid - for(k = 1; k <= length; k++) - vecad_ind[j+k] = num_vecad_vec; - // start of next VecAD - j += length + 1; - // initialize this vector's reverse jacobian value - vecad_jac[i] = false; - } - CPPAD_ASSERT_UNKNOWN( j == play->num_vec_ind_rec() ); - } - // ------------------------------------------------------------------------ - // user's atomic op calculator - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator - // - // work space used by UserOp. - vector user_x; // value of parameter arguments to function - vector user_ix; // variable index (on tape) for each argument - vector user_iy; // variable index (on tape) for each result - // - // information set by forward_user (initialization to avoid warnings) - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - // information set by forward_user (necessary initialization) - enum_user_state user_state = start_user; - // ------------------------------------------------------------------------- - // - // pointer to the beginning of the parameter vector - // (used by user atomic functions) - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - - // Initialize - play->forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); - bool more_operators = true; -# if CPPAD_FOR_HES_SWEEP_TRACE - vector user_usrrp; // parameter index for UsrrpOp operators - std::cout << std::endl; - CppAD::vectorBool zf_value(limit); - CppAD::vectorBool zh_value(limit * limit); -# endif - bool flag; // temporary for use in switch cases below - while(more_operators) - { - // next op - play->forward_next(op, arg, i_op, i_var); -# ifndef NDEBUG - if( i_op <= n ) - { CPPAD_ASSERT_UNKNOWN((op == InvOp) | (op == BeginOp)); - } - else CPPAD_ASSERT_UNKNOWN((op != InvOp) & (op != BeginOp)); -# endif - - // does the Hessian in question have a non-zero derivative - // with respect to this variable - bool include = rev_jac_sparse.is_element(i_var, 0); - // - // operators to include even if derivative is zero - include |= op == EndOp; - include |= op == CSkipOp; - include |= op == CSumOp; - include |= op == UserOp; - include |= op == UsrapOp; - include |= op == UsravOp; - include |= op == UsrrpOp; - include |= op == UsrrvOp; - // - if( include ) switch( op ) - { // operators that should not occurr - // case BeginOp - // ------------------------------------------------- - - // operators that do not affect hessian - case AbsOp: - case AddvvOp: - case AddpvOp: - case CExpOp: - case DisOp: - case DivvpOp: - case InvOp: - case LdpOp: - case LdvOp: - case MulpvOp: - case ParOp: - case PriOp: - case SignOp: - case StppOp: - case StpvOp: - case StvpOp: - case StvvOp: - case SubvvOp: - case SubpvOp: - case SubvpOp: - case ZmulpvOp: - case ZmulvpOp: - break; - // ------------------------------------------------- - - // nonlinear unary operators - case AcosOp: - case AsinOp: - case AtanOp: - case CosOp: - case CoshOp: - case ExpOp: - case LogOp: - case SinOp: - case SinhOp: - case SqrtOp: - case TanOp: - case TanhOp: -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - case AsinhOp: - case AtanhOp: - case Expm1Op: - case Log1pOp: -# endif - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ) - forward_sparse_hessian_nonlinear_unary_op( - arg[0], for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. - play->forward_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. - play->forward_csum(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case DivvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - forward_sparse_hessian_div_op( - arg, for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - forward_sparse_hessian_nonlinear_unary_op( - arg[1], for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case EndOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - more_operators = false; - break; - // ------------------------------------------------- - - case ErfOp: - // arg[1] is always the parameter 0 - // arg[2] is always the parameter 2 / sqrt(pi) - CPPAD_ASSERT_NARG_NRES(op, 3, 5); - forward_sparse_hessian_nonlinear_unary_op( - arg[0], for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - // ------------------------------------------------- - // logical comparision operators - case EqpvOp: - case EqvvOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case LepvOp: - case LevpOp: - case LevvOp: - case NepvOp: - case NevvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - break; - // ------------------------------------------------- - - case MulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - forward_sparse_hessian_mul_op( - arg, for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3) - forward_sparse_hessian_nonlinear_unary_op( - arg[1], for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3) - forward_sparse_hessian_nonlinear_unary_op( - arg[0], for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case PowvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3) - forward_sparse_hessian_pow_op( - arg, for_jac_sparse, for_hes_sparse - ); - break; - // ------------------------------------------------- - - case UserOp: - CPPAD_ASSERT_UNKNOWN( - user_state == start_user || user_state == end_user - ); - flag = user_state == start_user; - user_atom = play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { // start of user atomic operation sequence - user_x.resize( user_n ); - user_ix.resize( user_n ); - user_iy.resize( user_m ); -# if CPPAD_FOR_HES_SWEEP_TRACE - user_usrrp.resize( user_m ); -# endif - } - else - { // end of user atomic operation sequence - user_atom->set_old(user_old); - user_atom->for_sparse_hes( - user_x, user_ix, user_iy, - for_jac_sparse, rev_jac_sparse, for_hes_sparse - ); - } - break; - - case UsrapOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - // argument parameter value - user_x[user_j] = parameter[arg[0]]; - // special variable user for parameters - user_ix[user_j] = 0; - // - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsravOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - // arguemnt varialbes not avaialbe during sparisty calculations - user_x[user_j] = CppAD::numeric_limits::quiet_NaN(); - // varialbe index for this argument - user_ix[user_j] = arg[0]; - // - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - // special variable index user for parameters - user_iy[user_i] = 0; -# if CPPAD_FOR_HES_SWEEP_TRACE - // remember argument for delayed tracing - user_usrrp[user_i] = arg[0]; -# endif - // - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrvOp: - // variable index for this result - user_iy[user_i] = i_var; - // - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - // ------------------------------------------------- - - case ZmulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - forward_sparse_hessian_mul_op( - arg, for_jac_sparse, for_hes_sparse - ); - break; - - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -# if CPPAD_FOR_HES_SWEEP_TRACE - typedef typename Vector_set::const_iterator const_iterator; - if( op == UserOp && user_state == start_user ) - { // print operators that have been delayed - CPPAD_ASSERT_UNKNOWN( user_m == user_iy.size() ); - CPPAD_ASSERT_UNKNOWN( i_op > user_m ); - CPPAD_ASSERT_NARG_NRES(UsrrpOp, 1, 0); - CPPAD_ASSERT_NARG_NRES(UsrrvOp, 0, 1); - addr_t arg_tmp[1]; - for(k = 0; k < user_m; k++) - { size_t k_var = user_iy[k]; - // value for this variable - for(i = 0; i < limit; i++) - { zf_value[i] = false; - for(j = 0; j < limit; j++) - zh_value[i * limit + j] = false; - } - const_iterator itr_1(for_jac_sparse, i_var); - j = *itr_1; - while( j < limit ) - { zf_value[j] = true; - j = *(++itr_1); - } - for(i = 0; i < limit; i++) - { const_iterator itr_2(for_hes_sparse, i); - j = *itr_2; - while( j < limit ) - { zh_value[i * limit + j] = true; - j = *(++itr_2); - } - } - OpCode op_tmp = UsrrvOp; - if( k_var == 0 ) - { op_tmp = UsrrpOp; - arg_tmp[0] = user_usrrp[k]; - } - // k_var is zero when there is no result - printOp( - std::cout, - play, - i_op - user_m + k, - k_var, - op_tmp, - arg_tmp - ); - if( k_var > 0 ) printOpResult( - std::cout, - 1, - &zf_value, - 1, - &zh_value - ); - std::cout << std::endl; - } - } - const addr_t* arg_tmp = arg; - if( op == CSumOp ) - arg_tmp = arg - arg[-1] - 4; - if( op == CSkipOp ) - arg_tmp = arg - arg[-1] - 7; - for(i = 0; i < limit; i++) - { zf_value[i] = false; - for(j = 0; j < limit; j++) - zh_value[i * limit + j] = false; - } - const_iterator itr_1(for_jac_sparse, i_var); - j = *itr_1; - while( j < limit ) - { zf_value[j] = true; - j = *(++itr_1); - } - for(i = 0; i < limit; i++) - { const_iterator itr_2(for_hes_sparse, i); - j = *itr_2; - while( j < limit ) - { zh_value[i * limit + j] = true; - j = *(++itr_2); - } - } - // must delay print for these cases till after atomic user call - bool delay_print = op == UsrrpOp; - delay_print |= op == UsrrvOp; - if( ! delay_print ) - { printOp( - std::cout, - play, - i_op, - i_var, - op, - arg_tmp - ); - if( NumRes(op) > 0 && (! delay_print) ) printOpResult( - std::cout, - 1, - &zf_value, - 1, - &zh_value - ); - std::cout << std::endl; - } - } - std::cout << std::endl; -# else - } -# endif - // value corresponding to EndOp - CPPAD_ASSERT_UNKNOWN( i_var + 1 == play->num_var_rec() ); - - return; -} -} } // END_CPPAD_LOCAL_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_FOR_HES_SWEEP_TRACE - -# endif diff --git a/external/cppad/include/cppad/local/for_jac_sweep.hpp b/external/cppad/include/cppad/local/for_jac_sweep.hpp deleted file mode 100644 index bf6e526ba..000000000 --- a/external/cppad/include/cppad/local/for_jac_sweep.hpp +++ /dev/null @@ -1,815 +0,0 @@ -# ifndef CPPAD_LOCAL_FOR_JAC_SWEEP_HPP -# define CPPAD_LOCAL_FOR_JAC_SWEEP_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file for_jac_sweep.hpp -Compute Forward mode Jacobian sparsity patterns. -*/ - -/*! -\def CPPAD_FOR_JAC_SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every for_jac_sweep computation is printed. -*/ -# define CPPAD_FOR_JAC_SWEEP_TRACE 0 - -/*! -Given the sparsity pattern for the independent variables, -ForJacSweep computes the sparsity pattern for all the other variables. - -\tparam Base -base type for the operator; i.e., this operation sequence was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape; i.e., -\a play->num_var_rec(). - -\param play -The information stored in \a play -is a recording of the operations corresponding to a function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables -and \f$ m \f$ is the number of dependent variables. -The object \a play is effectly constant. -It is not declared const because while playing back the tape -the object \a play holds information about the current location -with in the tape and this changes during playback. - -\param var_sparsity -\b Input: For j = 1 , ... , \a n, -the sparsity pattern for the independent variable with index (j-1) -corresponds to the set with index j in \a var_sparsity. -\n -\n -\b Output: For i = \a n + 1 , ... , \a numvar - 1, -the sparsity pattern for the variable with index i on the tape -corresponds to the set with index i in \a var_sparsity. - -\par Checked Assertions: -\li numvar == var_sparsity.n_set() -\li numvar == play->num_var_rec() -*/ - -template -void ForJacSweep( - bool dependency , - size_t n , - size_t numvar , - local::player* play , - Vector_set& var_sparsity ) -{ - OpCode op; - size_t i_op; - size_t i_var; - - const addr_t* arg = CPPAD_NULL; - - size_t i, j, k; - - // check numvar argument - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - CPPAD_ASSERT_UNKNOWN( var_sparsity.n_set() == numvar ); - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - // cum_sparsity accumulates sparsity pattern a cummulative sum - size_t limit = var_sparsity.end(); - - // vecad_sparsity contains a sparsity pattern from each VecAD object - // to all the other variables. - // vecad_ind maps a VecAD index (the beginning of the - // VecAD object) to its from index in vecad_sparsity - size_t num_vecad_ind = play->num_vec_ind_rec(); - size_t num_vecad_vec = play->num_vecad_vec_rec(); - Vector_set vecad_sparsity; - vecad_sparsity.resize(num_vecad_vec, limit); - pod_vector vecad_ind; - if( num_vecad_vec > 0 ) - { size_t length; - vecad_ind.extend(num_vecad_ind); - j = 0; - for(i = 0; i < num_vecad_vec; i++) - { // length of this VecAD - length = play->GetVecInd(j); - // set to proper index for this VecAD - vecad_ind[j] = i; - for(k = 1; k <= length; k++) - vecad_ind[j+k] = num_vecad_vec; // invalid index - // start of next VecAD - j += length + 1; - } - CPPAD_ASSERT_UNKNOWN( j == play->num_vec_ind_rec() ); - } - - // -------------------------------------------------------------- - // user's atomic op calculator - atomic_base* user_atom = CPPAD_NULL; - // - // work space used by UserOp. - vector user_x; // value of parameter arguments to function - vector user_ix; // variable index (on tape) for each argument - vector user_iy; // variable index (on tape) for each result - // - // information set by forward_user (initialization to avoid warnings) - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - // information set by forward_user (necessary initialization) - enum_user_state user_state = start_user; - // -------------------------------------------------------------- - // - // pointer to the beginning of the parameter vector - // (used by user atomic functions) - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - -# if CPPAD_FOR_JAC_SWEEP_TRACE - vector user_usrrp; // parameter index for UsrrpOp operators - std::cout << std::endl; - CppAD::vectorBool z_value(limit); -# endif - - // skip the BeginOp at the beginning of the recording - play->forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); - bool more_operators = true; - while(more_operators) - { bool flag; // temporary for use in switch cases. - - // this op - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( (i_op > n) | (op == InvOp) ); - CPPAD_ASSERT_UNKNOWN( (i_op <= n) | (op != InvOp) ); - CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, i_var); - - // rest of information depends on the case - switch( op ) - { - case AbsOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case AddvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case CSkipOp: - // CSipOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - play->forward_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - forward_sparse_jacobian_csum_op( - i_var, arg, var_sparsity - ); - play->forward_csum(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CExpOp: - forward_sparse_jacobian_cond_op( - dependency, i_var, arg, num_par, var_sparsity - ); - break; - // -------------------------------------------------- - - case CosOp: - // sin(x), cos(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // --------------------------------------------------- - - case CoshOp: - // sinh(x), cosh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case DisOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - // derivative is identically zero but dependency is not - if( dependency ) forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - else - var_sparsity.clear(i_var); - break; - // ------------------------------------------------- - - case DivvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case EndOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - more_operators = false; - break; - // ------------------------------------------------- - - case ErfOp: - // arg[1] is always the parameter 0 - // arg[0] is always the parameter 2 / sqrt(pi) - CPPAD_ASSERT_NARG_NRES(op, 3, 5); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case ExpOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - // sparsity pattern is already defined - break; - // ------------------------------------------------- - - case LdpOp: - forward_sparse_load_op( - dependency, - op, - i_var, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case LdvOp: - forward_sparse_load_op( - dependency, - op, - i_var, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case EqpvOp: - case EqvvOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case LepvOp: - case LevpOp: - case LevvOp: - case NepvOp: - case NevvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - break; - // ------------------------------------------------- - - case LogOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case MulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case ParOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - var_sparsity.clear(i_var); - break; - // ------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3); - forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case PowvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3); - forward_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - break; - // ------------------------------------------------- - - case SignOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - // derivative is identically zero but dependency is not - if( dependency ) forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - else - var_sparsity.clear(i_var); - break; - // ------------------------------------------------- - - case SinOp: - // cos(x), sin(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case SinhOp: - // cosh(x), sinh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case SqrtOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case StppOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - // if both arguments are parameters does not affect sparsity - // or dependency - break; - // ------------------------------------------------- - - case StpvOp: - forward_sparse_store_op( - dependency, - op, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case StvpOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - forward_sparse_store_op( - dependency, - op, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case StvvOp: - forward_sparse_store_op( - dependency, - op, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case SubvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case TanOp: - // tan(x)^2, tan(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case TanhOp: - // tanh(x)^2, tanh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case UserOp: - CPPAD_ASSERT_UNKNOWN( - user_state == start_user || user_state == end_user - ); - flag = user_state == start_user; - user_atom = play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { // start of user atomic operation sequence - user_x.resize( user_n ); - user_ix.resize( user_n ); - user_iy.resize( user_m ); -# if CPPAD_FOR_JAC_SWEEP_TRACE - user_usrrp.resize( user_m ); -# endif - } - else - { // end of user atomic operation sequence - user_atom->set_old(user_old); - user_atom->for_sparse_jac( - user_x, user_ix, user_iy, var_sparsity - ); - } - break; - - case UsrapOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - // argument parameter value - user_x[user_j] = parameter[arg[0]]; - // special variable index used for parameters - user_ix[user_j] = 0; - // - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsravOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - // argument variables not avaiable during sparsity calculations - user_x[user_j] = CppAD::numeric_limits::quiet_NaN(); - // variable index for this argument - user_ix[user_j] = arg[0]; - // - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrpOp: - // special variable index used for parameters - user_iy[user_i] = 0; -# if CPPAD_FOR_JAC_SWEEP_TRACE - // remember argument for delayed tracing - user_usrrp[user_i] = arg[0]; -# endif - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrvOp: - // variable index for this result - user_iy[user_i] = i_var; - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - // ------------------------------------------------- - - case ZmulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case ZmulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - forward_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -# if CPPAD_FOR_JAC_SWEEP_TRACE - if( op == UserOp && user_state == start_user ) - { // print operators that have been delayed - CPPAD_ASSERT_UNKNOWN( user_m == user_iy.size() ); - CPPAD_ASSERT_UNKNOWN( i_op > user_m ); - CPPAD_ASSERT_NARG_NRES(UsrrpOp, 1, 0); - CPPAD_ASSERT_NARG_NRES(UsrrvOp, 0, 1); - addr_t arg_tmp[1]; - for(i = 0; i < user_m; i++) - { size_t j_var = user_iy[i]; - // value for this variable - for(j = 0; j < limit; j++) - z_value[j] = false; - typename Vector_set::const_iterator itr(var_sparsity, j_var); - j = *itr; - while( j < limit ) - { z_value[j] = true; - j = *(++itr); - } - OpCode op_tmp = UsrrvOp; - if( j_var == 0 ) - { op_tmp = UsrrpOp; - arg_tmp[0] = user_usrrp[i]; - } - // j_var is zero when there is no result. - printOp( - std::cout, - play, - i_op - user_m + i, - j_var, - op_tmp, - arg_tmp - ); - if( j_var > 0 ) printOpResult( - std::cout, - 1, - &z_value, - 0, - (CppAD::vectorBool *) CPPAD_NULL - ); - std::cout << std::endl; - } - } - const addr_t* arg_tmp = arg; - if( op == CSumOp ) - arg_tmp = arg - arg[-1] - 4; - if( op == CSkipOp ) - arg_tmp = arg - arg[-1] - 7; - // - // value for this variable - for(j = 0; j < limit; j++) - z_value[j] = false; - typename Vector_set::const_iterator itr(var_sparsity, i_var); - j = *itr; - while( j < limit ) - { z_value[j] = true; - j = *(++itr); - } - // must delay print for these cases till after atomic user call - bool delay_print = op == UsrrpOp; - delay_print |= op == UsrrvOp; - if( ! delay_print ) - { printOp( - std::cout, - play, - i_op, - i_var, - op, - arg_tmp - ); - if( NumRes(op) > 0 && (! delay_print) ) printOpResult( - std::cout, - 1, - &z_value, - 0, - (CppAD::vectorBool *) CPPAD_NULL - ); - std::cout << std::endl; - } - } - std::cout << std::endl; -# else - } -# endif - CPPAD_ASSERT_UNKNOWN( i_var + 1 == play->num_var_rec() ); - - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_FOR_JAC_SWEEP_TRACE - -# endif diff --git a/external/cppad/include/cppad/local/forward0sweep.hpp b/external/cppad/include/cppad/local/forward0sweep.hpp deleted file mode 100644 index 6e7b6239f..000000000 --- a/external/cppad/include/cppad/local/forward0sweep.hpp +++ /dev/null @@ -1,955 +0,0 @@ -# ifndef CPPAD_LOCAL_FORWARD0SWEEP_HPP -# define CPPAD_LOCAL_FORWARD0SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file forward0sweep.hpp -Compute zero order forward mode Taylor coefficients. -*/ - -/* -\def CPPAD_ATOMIC_CALL -This avoids warnings when NDEBUG is defined and user_ok is not used. -If NDEBUG is defined, this resolves to -\code - user_atom->forward -\endcode -otherwise, it respolves to -\code - user_ok = user_atom->forward -\endcode -This maco is undefined at the end of this file to facillitate is -use with a different definition in other files. -*/ -# ifdef NDEBUG -# define CPPAD_ATOMIC_CALL user_atom->forward -# else -# define CPPAD_ATOMIC_CALL user_ok = user_atom->forward -# endif - -/*! -\def CPPAD_FORWARD0SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every forward0sweep computation is printed. -(Note that forward0sweep is not used if CPPAD_USE_FORWARD0SWEEP is zero). -*/ -# define CPPAD_FORWARD0SWEEP_TRACE 0 - -/*! -Compute zero order forward mode Taylor coefficients. - - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\param s_out -Is the stream where output corresponding to PriOp operations will -be written. - -\param print -If print is false, -suppress the output that is otherwise generated by the c PriOp instructions. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape. -This is also equal to the number of rows in the matrix taylor; i.e., -play->num_var_rec(). - -\param play -The information stored in play -is a recording of the operations corresponding to the function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables and -\f$ m \f$ is the number of dependent variables. -\n -\n -The object play is effectly constant. -The exception to this is that while palying back the tape -the object play holds information about the current location -with in the tape and this changes during palyback. - -\param J -Is the number of columns in the coefficient matrix taylor. -This must be greater than or equal one. - - - -\param taylor -\n -\b Input: -For i = 1 , ... , n, -taylor [i * J + 0] -variable with index j on the tape -(these are the independent variables). -\n -\n -\b Output: -For i = n + 1, ... , numvar - 1, -taylor [i * J + 0] -is the zero order Taylor coefficient for the variable with -index i on the tape. - -\param cskip_op -Is a vector with size play->num_op_rec(). -The input value of the elements does not matter. -Upon return, if cskip_op[i] is true, the operator index i -does not affect any of the dependent variable -(given the value of the independent variables). - -\param var_by_load_op -Is a vector with size play->num_load_op_rec(). -The input value of the elements does not matter. -Upon return, -it is the variable index corresponding the result for each load operator. -In the case where the index is zero, -the load operator results in a parameter (not a variable). -Note that the is no variable with index zero on the tape. - -\param compare_change_count -Is the count value for changing number and op_index during -zero order foward mode. - -\param compare_change_number -If compare_change_count is zero, this value is set to zero. -Otherwise, the return value is the number of comparision operations -that have a different result from when the information in -play was recorded. - -\param compare_change_op_index -If compare_change_count is zero, this value is set to zero. -Otherwise it is the operator index (see forward_next) for the count-th -comparision operation that has a different result from when the information in -play was recorded. -*/ - -template -void forward0sweep( - std::ostream& s_out, - bool print, - size_t n, - size_t numvar, - local::player* play, - size_t J, - Base* taylor, - bool* cskip_op, - pod_vector& var_by_load_op, - size_t compare_change_count, - size_t& compare_change_number, - size_t& compare_change_op_index -) -{ CPPAD_ASSERT_UNKNOWN( J >= 1 ); - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - - // use p, q, r so other forward sweeps can use code defined here - size_t p = 0; - size_t q = 0; - size_t r = 1; - /* - - */ - // op code for current instruction - OpCode op; - - // index for current instruction - size_t i_op; - - // next variables - size_t i_var; - - // operation argument indices - const addr_t* arg = CPPAD_NULL; - - // initialize the comparision operator counter - if( p == 0 ) - { compare_change_number = 0; - compare_change_op_index = 0; - } - - // If this includes a zero calculation, initialize this information - pod_vector isvar_by_ind; - pod_vector index_by_ind; - if( p == 0 ) - { size_t i; - - // this includes order zero calculation, initialize vector indices - size_t num = play->num_vec_ind_rec(); - if( num > 0 ) - { isvar_by_ind.extend(num); - index_by_ind.extend(num); - for(i = 0; i < num; i++) - { index_by_ind[i] = play->GetVecInd(i); - isvar_by_ind[i] = false; - } - } - // includes zero order, so initialize conditional skip flags - num = play->num_op_rec(); - for(i = 0; i < num; i++) - cskip_op[i] = false; - } - - // work space used by UserOp. - vector user_vx; // empty vecotor - vector user_vy; // empty vecotor - vector user_tx; // argument vector Taylor coefficients - vector user_ty; // result vector Taylor coefficients - // - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator -# ifndef NDEBUG - bool user_ok = false; // atomic op return value -# endif - // - // information defined by forward_user - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - enum_user_state user_state = start_user; // proper initialization - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - // pointer to the beginning of the parameter vector - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - - // length of the text vector (used by CppAD assert macros) - const size_t num_text = play->num_text_rec(); - - // pointer to the beginning of the text vector - const char* text = CPPAD_NULL; - if( num_text > 0 ) - text = play->GetTxt(0); - /* - - */ - -# if CPPAD_FORWARD0SWEEP_TRACE - // flag as to when to trace user function values - bool user_trace = false; - - // variable indices for results vector - // (done differently for order zero). - vector user_iy; -# endif - - // skip the BeginOp at the beginning of the recording - play->forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); -# if CPPAD_FORWARD0SWEEP_TRACE - std::cout << std::endl; -# endif - bool flag; // a temporary flag to use in switch cases - bool more_operators = true; - while(more_operators) - { - // this op - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( (i_op > n) | (op == InvOp) ); - CPPAD_ASSERT_UNKNOWN( (i_op <= n) | (op != InvOp) ); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, i_var); - - // check if we are skipping this operation - while( cskip_op[i_op] ) - { switch(op) - { case CSumOp: - // CSumOp has a variable number of arguments - play->forward_csum(op, arg, i_op, i_var); - break; - - case CSkipOp: - // CSkip has a variable number of arguments - play->forward_cskip(op, arg, i_op, i_var); - break; - - case UserOp: - { // skip all operations in this user atomic call - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - size_t n_skip = user_m + user_n + 1; - for(size_t i = 0; i < n_skip; i++) - { play->forward_next(op, arg, i_op, i_var); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - } - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - } - break; - - default: - break; - } - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - } - - // action to take depends on the case - switch( op ) - { - case AbsOp: - forward_abs_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case AddvvOp: - forward_addvv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_addpv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_acos_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_acosh_op_0(i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_asin_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_asinh_op_0(i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_atan_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_atanh_op_0(i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case CExpOp: - // Use the general case with d == 0 - // (could create an optimzied verison for this case) - forward_cond_op_0( - i_var, arg, num_par, parameter, J, taylor - ); - break; - // --------------------------------------------------- - - case CosOp: - // sin(x), cos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_cos_op_0(i_var, arg[0], J, taylor); - break; - // --------------------------------------------------- - - case CoshOp: - // sinh(x), cosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_cosh_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - forward_cskip_op_0( - i_var, arg, num_par, parameter, J, taylor, cskip_op - ); - play->forward_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - forward_csum_op( - 0, 0, i_var, arg, num_par, parameter, J, taylor - ); - play->forward_csum(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case DisOp: - forward_dis_op(p, q, r, i_var, arg, J, taylor); - break; - // ------------------------------------------------- - - case DivvvOp: - forward_divvv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_divpv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_divvp_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case EndOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - more_operators = false; - break; - // ------------------------------------------------- - - case EqpvOp: - if( compare_change_count ) - { forward_eqpv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case EqvvOp: - if( compare_change_count ) - { forward_eqvv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case ErfOp: - forward_erf_op_0(i_var, arg, parameter, J, taylor); - break; -# endif - // ------------------------------------------------- - - case ExpOp: - forward_exp_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - forward_expm1_op_0(i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - break; - // --------------------------------------------------- - - case LdpOp: - forward_load_p_op_0( - play, - i_var, - arg, - parameter, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data(), - var_by_load_op.data() - ); - break; - // ------------------------------------------------- - - case LdvOp: - forward_load_v_op_0( - play, - i_var, - arg, - parameter, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data(), - var_by_load_op.data() - ); - break; - // ------------------------------------------------- - - case LepvOp: - if( compare_change_count ) - { forward_lepv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case LevpOp: - if( compare_change_count ) - { forward_levp_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case LevvOp: - if( compare_change_count ) - { forward_levv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case LogOp: - forward_log_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - forward_log1p_op_0(i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case LtpvOp: - if( compare_change_count ) - { forward_ltpv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case LtvpOp: - if( compare_change_count ) - { forward_ltvp_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case LtvvOp: - if( compare_change_count ) - { forward_ltvv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_mulpv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case MulvvOp: - forward_mulvv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case NepvOp: - if( compare_change_count ) - { forward_nepv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case NevvOp: - if( compare_change_count ) - { forward_nevv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - { if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - } - break; - // ------------------------------------------------- - - case ParOp: - forward_par_op_0( - i_var, arg, num_par, parameter, J, taylor - ); - break; - // ------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_powvp_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_powpv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PowvvOp: - forward_powvv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PriOp: - if( print ) forward_pri_0(s_out, - arg, num_text, text, num_par, parameter, J, taylor - ); - break; - // ------------------------------------------------- - - case SignOp: - // cos(x), sin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sign_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SinOp: - // cos(x), sin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sin_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SinhOp: - // cosh(x), sinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sinh_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SqrtOp: - forward_sqrt_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case StppOp: - forward_store_pp_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - break; - // ------------------------------------------------- - - case StpvOp: - forward_store_pv_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - break; - // ------------------------------------------------- - - case StvpOp: - forward_store_vp_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - break; - // ------------------------------------------------- - - case StvvOp: - forward_store_vv_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - break; - // ------------------------------------------------- - - case SubvvOp: - forward_subvv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_subpv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_subvp_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case TanOp: - // tan(x)^2, tan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_tan_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case TanhOp: - // tanh(x)^2, tanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_tanh_op_0(i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case UserOp: - // start or end an atomic operation sequence - flag = user_state == start_user; - user_atom = play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { user_tx.resize(user_n); - user_ty.resize(user_m); -# if CPPAD_FORWARD0SWEEP_TRACE - user_iy.resize(user_m); -# endif - } - else - { -# ifndef NDEBUG - if( ! user_ok ) - { std::string msg = - user_atom->afun_name() - + ": atomic_base.forward: returned false"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif -# if CPPAD_FORWARD0SWEEP_TRACE - user_trace = true; -# endif - } - break; - - case UsrapOp: - // parameter argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t( arg[0] ) < num_par ); - user_tx[user_j] = parameter[ arg[0] ]; - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( user_j == user_n ) - { // call users function for this operation - user_atom->set_old(user_old); - CPPAD_ATOMIC_CALL(p, q, - user_vx, user_vy, user_tx, user_ty - ); - } - break; - - case UsravOp: - // variable argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - user_tx[user_j] = taylor[ arg[0] * J + 0 ]; - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( user_j == user_n ) - { // call users function for this operation - user_atom->set_old(user_old); - CPPAD_ATOMIC_CALL(p, q, - user_vx, user_vy, user_tx, user_ty - ); - } - break; - - case UsrrpOp: - // parameter result in an atomic operation sequence -# if CPPAD_FORWARD0SWEEP_TRACE - user_iy[user_i] = 0; -# endif - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrvOp: - // variable result in an atomic operation sequence -# if CPPAD_FORWARD0SWEEP_TRACE - user_iy[user_i] = i_var; -# endif - taylor[ i_var * J + 0 ] = user_ty[user_i]; - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - // ------------------------------------------------- - - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_zmulpv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_zmulvp_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ZmulvvOp: - forward_zmulvv_op_0(i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(false); - } -# if CPPAD_FORWARD0SWEEP_TRACE - size_t d = 0; - if( user_trace ) - { user_trace = false; - - CPPAD_ASSERT_UNKNOWN( op == UserOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(UsrrvOp) == 0 ); - for(size_t i = 0; i < user_m; i++) if( user_iy[i] > 0 ) - { size_t i_tmp = (i_op + i) - user_m; - printOp( - std::cout, - play, - i_tmp, - user_iy[i], - UsrrvOp, - CPPAD_NULL - ); - Base* Z_tmp = taylor + user_iy[i] * J; - printOpResult( - std::cout, - d + 1, - Z_tmp, - 0, - (Base *) CPPAD_NULL - ); - std::cout << std::endl; - } - } - Base* Z_tmp = taylor + i_var * J; - const addr_t* arg_tmp = arg; - if( op == CSumOp ) - arg_tmp = arg - arg[-1] - 4; - if( op == CSkipOp ) - arg_tmp = arg - arg[-1] - 7; - if( op != UsrrvOp ) - { - printOp( - std::cout, - play, - i_op, - i_var, - op, - arg_tmp - ); - if( NumRes(op) > 0 ) printOpResult( - std::cout, - d + 1, - Z_tmp, - 0, - (Base *) CPPAD_NULL - ); - std::cout << std::endl; - } - } - std::cout << std::endl; -# else - } -# endif - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - CPPAD_ASSERT_UNKNOWN( i_var + 1 == play->num_var_rec() ); - - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_FORWARD0SWEEP_TRACE -# undef CPPAD_ATOMIC_CALL - -# endif diff --git a/external/cppad/include/cppad/local/forward1sweep.hpp b/external/cppad/include/cppad/local/forward1sweep.hpp deleted file mode 100644 index 5cfde0c7d..000000000 --- a/external/cppad/include/cppad/local/forward1sweep.hpp +++ /dev/null @@ -1,1058 +0,0 @@ -# ifndef CPPAD_LOCAL_FORWARD1SWEEP_HPP -# define CPPAD_LOCAL_FORWARD1SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file forward1sweep.hpp -Compute one Taylor coefficient for each order requested. -*/ - -/* -\def CPPAD_ATOMIC_CALL -This avoids warnings when NDEBUG is defined and user_ok is not used. -If NDEBUG is defined, this resolves to -\code - user_atom->forward -\endcode -otherwise, it respolves to -\code - user_ok = user_atom->forward -\endcode -This macro is undefined at the end of this file to facillitate its -use with a different definition in other files. -*/ -# ifdef NDEBUG -# define CPPAD_ATOMIC_CALL user_atom->forward -# else -# define CPPAD_ATOMIC_CALL user_ok = user_atom->forward -# endif - -/*! -\def CPPAD_FORWARD1SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every forward1sweep computation is printed. -*/ -# define CPPAD_FORWARD1SWEEP_TRACE 0 - -/*! -Compute arbitrary order forward mode Taylor coefficients. - - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\param s_out -Is the stream where output corresponding to PriOp operations will -be written. - -\param print -If print is false, -suppress the output that is otherwise generated by the c PriOp instructions. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape. -This is also equal to the number of rows in the matrix taylor; i.e., -play->num_var_rec(). - -\param play -The information stored in play -is a recording of the operations corresponding to the function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables and -\f$ m \f$ is the number of dependent variables. -\n -\n -The object play is effectly constant. -The exception to this is that while palying back the tape -the object play holds information about the current location -with in the tape and this changes during palyback. - -\param J -Is the number of columns in the coefficient matrix taylor. -This must be greater than or equal one. - - - -\param cskip_op -Is a vector with size play->num_op_rec(). -\n -\n -p = 0 -\n -In this case, -the input value of the elements does not matter. -Upon return, if cskip_op[i] is true, the operator with index i -does not affect any of the dependent variable -(given the value of the independent variables). -\n -\n -p > 0 -\n -In this case cskip_op is not modified and has the same meaning -as its return value above. - -\param var_by_load_op -is a vector with size play->num_load_op_rec(). -\n -\n -p == 0 -\n -In this case, -The input value of the elements does not matter. -Upon return, -it is the variable index corresponding the result for each load operator. -In the case where the index is zero, -the load operator results in a parameter (not a variable). -Note that the is no variable with index zero on the tape. -\n -\n -p > 0 -\n -In this case var_by_load_op is not modified and has the meaning -as its return value above. - -\param p -is the lowest order of the Taylor coefficients -that are computed during this call. - -\param q -is the highest order of the Taylor coefficients -that are computed during this call. - -\param taylor -\n -\b Input: -For i = 1 , ... , numvar-1, -k = 0 , ... , p-1, -taylor[ J*i + k] -is the k-th order Taylor coefficient corresponding to -the i-th variable. -\n -\n -\b Input: -For i = 1 , ... , n, -k = p , ... , q, -taylor[ J*j + k] -is the k-th order Taylor coefficient corresponding to -the i-th variable -(these are the independent varaibles). -\n -\n -\b Output: -For i = n+1 , ... , numvar-1, and -k = 0 , ... , p-1, -taylor[ J*i + k] -is the k-th order Taylor coefficient corresponding to -the i-th variable. - - -\param compare_change_count -Is the count value for changing number and op_index during -zero order foward mode. - -\param compare_change_number -If p is non-zero, this value is not changed, otherwise: -If compare_change_count is zero, this value is set to zero, otherwise: -this value is set to the number of comparision operations -that have a different result from when the information in -play was recorded. - -\param compare_change_op_index -if p is non-zero, this value is not changed, otherwise: -If compare_change_count is zero, this value is set to zero. -Otherwise it is the operator index (see forward_next) for the count-th -comparision operation that has a different result from when the information in -play was recorded. -*/ - -template -void forward1sweep( - std::ostream& s_out, - const bool print, - const size_t p, - const size_t q, - const size_t n, - const size_t numvar, - local::player* play, - const size_t J, - Base* taylor, - bool* cskip_op, - pod_vector& var_by_load_op, - size_t compare_change_count, - size_t& compare_change_number, - size_t& compare_change_op_index -) -{ - // number of directions - const size_t r = 1; - - CPPAD_ASSERT_UNKNOWN( p <= q ); - CPPAD_ASSERT_UNKNOWN( J >= q + 1 ); - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - - /* - - */ - // op code for current instruction - OpCode op; - - // index for current instruction - size_t i_op; - - // next variables - size_t i_var; - - // operation argument indices - const addr_t* arg = CPPAD_NULL; - - // initialize the comparision operator counter - if( p == 0 ) - { compare_change_number = 0; - compare_change_op_index = 0; - } - - // If this includes a zero calculation, initialize this information - pod_vector isvar_by_ind; - pod_vector index_by_ind; - if( p == 0 ) - { size_t i; - - // this includes order zero calculation, initialize vector indices - size_t num = play->num_vec_ind_rec(); - if( num > 0 ) - { isvar_by_ind.extend(num); - index_by_ind.extend(num); - for(i = 0; i < num; i++) - { index_by_ind[i] = play->GetVecInd(i); - isvar_by_ind[i] = false; - } - } - // includes zero order, so initialize conditional skip flags - num = play->num_op_rec(); - for(i = 0; i < num; i++) - cskip_op[i] = false; - } - - // work space used by UserOp. - vector user_vx; // empty vecotor - vector user_vy; // empty vecotor - vector user_tx; // argument vector Taylor coefficients - vector user_ty; // result vector Taylor coefficients - // - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator -# ifndef NDEBUG - bool user_ok = false; // atomic op return value -# endif - // - // information defined by forward_user - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - enum_user_state user_state = start_user; // proper initialization - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - // pointer to the beginning of the parameter vector - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - - // length of the text vector (used by CppAD assert macros) - const size_t num_text = play->num_text_rec(); - - // pointer to the beginning of the text vector - const char* text = CPPAD_NULL; - if( num_text > 0 ) - text = play->GetTxt(0); - /* - - */ - // temporary indices - size_t i, k; - - // number of orders for this user calculation - // (not needed for order zero) - const size_t user_q1 = q+1; - - // variable indices for results vector - // (done differently for order zero). - vector user_iy; - - // skip the BeginOp at the beginning of the recording - play->forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); - // -# if CPPAD_FORWARD1SWEEP_TRACE - bool user_trace = false; - std::cout << std::endl; -# endif - // - bool flag; // a temporary flag to use in switch cases - bool more_operators = true; - while(more_operators) - { - // this op - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( (i_op > n) | (op == InvOp) ); - CPPAD_ASSERT_UNKNOWN( (i_op <= n) | (op != InvOp) ); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, i_var); - - // check if we are skipping this operation - while( cskip_op[i_op] ) - { switch(op) - { case CSumOp: - // CSumOp has a variable number of arguments - play->forward_csum(op, arg, i_op, i_var); - break; - - case CSkipOp: - // CSkip has a variable number of arguments - play->forward_cskip(op, arg, i_op, i_var); - break; - - case UserOp: - { // skip all operations in this user atomic call - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - size_t n_skip = user_m + user_n + 1; - for(i = 0; i < n_skip; i++) - { play->forward_next(op, arg, i_op, i_var); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - } - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - } - break; - - default: - break; - } - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - } - - // action depends on the operator - switch( op ) - { - case AbsOp: - forward_abs_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case AddvvOp: - forward_addvv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_addpv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_acos_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_acosh_op(p, q, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_asin_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_asinh_op(p, q, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_atan_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_atanh_op(p, q, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case CExpOp: - forward_cond_op( - p, q, i_var, arg, num_par, parameter, J, taylor - ); - break; - // --------------------------------------------------- - - case CosOp: - // sin(x), cos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_cos_op(p, q, i_var, arg[0], J, taylor); - break; - // --------------------------------------------------- - - case CoshOp: - // sinh(x), cosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_cosh_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - if( p == 0 ) - { forward_cskip_op_0( - i_var, arg, num_par, parameter, J, taylor, cskip_op - ); - } - play->forward_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - forward_csum_op( - p, q, i_var, arg, num_par, parameter, J, taylor - ); - play->forward_csum(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case DisOp: - forward_dis_op(p, q, r, i_var, arg, J, taylor); - break; - // ------------------------------------------------- - - case DivvvOp: - forward_divvv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_divpv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_divvp_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case EndOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - more_operators = false; - break; - // ------------------------------------------------- - - case EqpvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_eqpv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case EqvvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_eqvv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case ErfOp: - CPPAD_ASSERT_UNKNOWN( CPPAD_USE_CPLUSPLUS_2011 ); - forward_erf_op(p, q, i_var, arg, parameter, J, taylor); - break; -# endif - // ------------------------------------------------- - - case ExpOp: - forward_exp_op(p, q, i_var, arg[0], J, taylor); - break; - // --------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - forward_expm1_op(p, q, i_var, arg[0], J, taylor); - break; -# endif - // --------------------------------------------------- - - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - break; - // ------------------------------------------------- - - case LdpOp: - if( p == 0 ) - { forward_load_p_op_0( - play, - i_var, - arg, - parameter, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data(), - var_by_load_op.data() - ); - if( p < q ) forward_load_op( - play, - op, - p+1, - q, - r, - J, - i_var, - arg, - var_by_load_op.data(), - taylor - ); - } - else forward_load_op( - play, - op, - p, - q, - r, - J, - i_var, - arg, - var_by_load_op.data(), - taylor - ); - break; - // ------------------------------------------------- - - case LdvOp: - if( p == 0 ) - { forward_load_v_op_0( - play, - i_var, - arg, - parameter, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data(), - var_by_load_op.data() - ); - if( p < q ) forward_load_op( - play, - op, - p+1, - q, - r, - J, - i_var, - arg, - var_by_load_op.data(), - taylor - ); - } - else forward_load_op( - play, - op, - p, - q, - r, - J, - i_var, - arg, - var_by_load_op.data(), - taylor - ); - break; - // ------------------------------------------------- - - case LepvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_lepv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - - case LevpOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_levp_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case LevvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_levv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case LogOp: - forward_log_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - forward_log1p_op(p, q, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case LtpvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_ltpv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - - case LtvpOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_ltvp_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case LtvvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_ltvv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_mulpv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case MulvvOp: - forward_mulvv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case NepvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_nepv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case NevvOp: - if( ( p == 0 ) & ( compare_change_count > 0 ) ) - { forward_nevv_op_0( - compare_change_number, arg, parameter, J, taylor - ); - if( compare_change_count == compare_change_number ) - compare_change_op_index = i_op; - } - break; - // ------------------------------------------------- - - case ParOp: - i = p; - if( i == 0 ) - { forward_par_op_0( - i_var, arg, num_par, parameter, J, taylor - ); - i++; - } - while(i <= q) - { taylor[ i_var * J + i] = Base(0.0); - i++; - } - break; - // ------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_powvp_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_powpv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PowvvOp: - forward_powvv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PriOp: - if( (p == 0) & print ) forward_pri_0(s_out, - arg, num_text, text, num_par, parameter, J, taylor - ); - break; - // ------------------------------------------------- - - case SignOp: - // sign(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sign_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SinOp: - // cos(x), sin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sin_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SinhOp: - // cosh(x), sinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sinh_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SqrtOp: - forward_sqrt_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case StppOp: - if( p == 0 ) - { forward_store_pp_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - } - break; - // ------------------------------------------------- - - case StpvOp: - if( p == 0 ) - { forward_store_pv_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - } - break; - // ------------------------------------------------- - - case StvpOp: - if( p == 0 ) - { forward_store_vp_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - } - break; - // ------------------------------------------------- - - case StvvOp: - if( p == 0 ) - { forward_store_vv_op_0( - i_var, - arg, - num_par, - J, - taylor, - isvar_by_ind.data(), - index_by_ind.data() - ); - } - break; - // ------------------------------------------------- - - case SubvvOp: - forward_subvv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_subpv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_subvp_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case TanOp: - // tan(x)^2, tan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_tan_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case TanhOp: - // tanh(x)^2, tanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_tanh_op(p, q, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case UserOp: - // start or end an atomic operation sequence - flag = user_state == start_user; - user_atom = play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { user_tx.resize(user_n * user_q1); - user_ty.resize(user_m * user_q1); - user_iy.resize(user_m); - } - else - { // call users function for this operation - user_atom->set_old(user_old); - CPPAD_ATOMIC_CALL( - p, q, user_vx, user_vy, user_tx, user_ty - ); -# ifndef NDEBUG - if( ! user_ok ) - { std::string msg = - user_atom->afun_name() - + ": atomic_base.forward: returned false"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - for(i = 0; i < user_m; i++) - if( user_iy[i] > 0 ) - for(k = p; k <= q; k++) - taylor[ user_iy[i] * J + k ] = - user_ty[ i * user_q1 + k ]; -# if CPPAD_FORWARD1SWEEP_TRACE - user_trace = true; -# endif - } - break; - - case UsrapOp: - // parameter argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - user_tx[user_j * user_q1 + 0] = parameter[ arg[0]]; - for(k = 1; k < user_q1; k++) - user_tx[user_j * user_q1 + k] = Base(0.0); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsravOp: - // variable argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - for(k = 0; k < user_q1; k++) - user_tx[user_j * user_q1 + k] = taylor[ arg[0] * J + k]; - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrpOp: - // parameter result in an atomic operation sequence - user_iy[user_i] = 0; - user_ty[user_i * user_q1 + 0] = parameter[ arg[0]]; - for(k = 1; k < p; k++) - user_ty[user_i * user_q1 + k] = Base(0.0); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrvOp: - // variable result in an atomic operation sequence - user_iy[user_i] = i_var; - for(k = 0; k < p; k++) - user_ty[user_i * user_q1 + k] = taylor[ i_var * J + k]; - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - // ------------------------------------------------- - - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_zmulpv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_zmulvp_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ZmulvvOp: - forward_zmulvv_op(p, q, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -# if CPPAD_FORWARD1SWEEP_TRACE - if( user_trace ) - { user_trace = false; - - CPPAD_ASSERT_UNKNOWN( op == UserOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(UsrrvOp) == 0 ); - for(i = 0; i < user_m; i++) if( user_iy[i] > 0 ) - { size_t i_tmp = (i_op + i) - user_m; - printOp( - std::cout, - play, - i_tmp, - user_iy[i], - UsrrvOp, - CPPAD_NULL - ); - Base* Z_tmp = taylor + user_iy[i] * J; - printOpResult( - std::cout, - q + 1, - Z_tmp, - 0, - (Base *) CPPAD_NULL - ); - std::cout << std::endl; - } - } - Base* Z_tmp = taylor + J * i_var; - const addr_t* arg_tmp = arg; - if( op == CSumOp ) - arg_tmp = arg - arg[-1] - 4; - if( op == CSkipOp ) - arg_tmp = arg - arg[-1] - 7; - if( op != UsrrvOp ) - { - printOp( - std::cout, - play, - i_op, - i_var, - op, - arg_tmp - ); - if( NumRes(op) > 0 ) printOpResult( - std::cout, - q + 1, - Z_tmp, - 0, - (Base *) CPPAD_NULL - ); - std::cout << std::endl; - } - } - std::cout << std::endl; -# else - } -# endif - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - CPPAD_ASSERT_UNKNOWN( i_var + 1 == play->num_var_rec() ); - - if( (p == 0) & (compare_change_count == 0) ) - compare_change_number = 0; - return; -} - -// preprocessor symbols that are local to this file -# undef CPPAD_FORWARD1SWEEP_TRACE -# undef CPPAD_ATOMIC_CALL - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/forward2sweep.hpp b/external/cppad/include/cppad/local/forward2sweep.hpp deleted file mode 100644 index 0fd6762a9..000000000 --- a/external/cppad/include/cppad/local/forward2sweep.hpp +++ /dev/null @@ -1,795 +0,0 @@ -# ifndef CPPAD_LOCAL_FORWARD2SWEEP_HPP -# define CPPAD_LOCAL_FORWARD2SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file forward2sweep.hpp -Compute one Taylor coefficient for each direction requested. -*/ - -/* -\def CPPAD_ATOMIC_CALL -This avoids warnings when NDEBUG is defined and user_ok is not used. -If NDEBUG is defined, this resolves to -\code - user_atom->forward -\endcode -otherwise, it respolves to -\code - user_ok = user_atom->forward -\endcode -This macro is undefined at the end of this file to facillitate its -use with a different definition in other files. -*/ -# ifdef NDEBUG -# define CPPAD_ATOMIC_CALL user_atom->forward -# else -# define CPPAD_ATOMIC_CALL user_ok = user_atom->forward -# endif - -/*! -\def CPPAD_FORWARD2SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every forward2sweep computation is printed. -*/ -# define CPPAD_FORWARD2SWEEP_TRACE 0 - -/*! -Compute multiple directions forward mode Taylor coefficients. - -\tparam Base -The type used during the forward mode computations; i.e., the corresponding -recording of operations used the type AD. - -\param q -is the order of the Taylor coefficients -that are computed during this call; -q > 0. - -\param r -is the number of Taylor coefficients -that are computed during this call. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape. -This is also equal to the number of rows in the matrix taylor; i.e., -play->num_var_rec(). - -\param play -The information stored in play -is a recording of the operations corresponding to the function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables and -\f$ m \f$ is the number of dependent variables. -\n -\n -The object play is effectly constant. -The exception to this is that while palying back the tape -the object play holds information about the current location -with in the tape and this changes during palyback. - -\param J -Is the number of columns in the coefficient matrix taylor. -This must be greater than or equal one. - -\param taylor -\n -\b Input: -For i = 1 , ... , numvar-1, -taylor[ (J-1)*r*i + i + 0 ] -is the zero order Taylor coefficient corresponding to -the i-th variable and all directions. -For i = 1 , ... , numvar-1, -For k = 1 , ... , q-1, -ell = 0 , ... , r-1, -taylor[ (J-1)*r*i + i + (k-1)*r + ell + 1 ] -is the k-th order Taylor coefficient corresponding to -the i-th variabel and ell-th direction. -\n -\n -\b Input: -For i = 1 , ... , n, -ell = 0 , ... , r-1, -taylor[ (J-1)*r*i + i + (q-1)*r + ell + 1 ] -is the q-th order Taylor coefficient corresponding to -the i-th variable and ell-th direction -(these are the independent varaibles). -\n -\n -\b Output: -For i = n+1 , ... , numvar-1, -ell = 0 , ... , r-1, -taylor[ (J-1)*r*i + i + (q-1)*r + ell + 1 ] -is the q-th order Taylor coefficient corresponding to -the i-th variable and ell-th direction. - -\param cskip_op -Is a vector with size play->num_op_rec(). -If cskip_op[i] is true, the operator with index i -does not affect any of the dependent variable (given the value -of the independent variables). - -\param var_by_load_op -is a vector with size play->num_load_op_rec(). -It is the variable index corresponding to each the -load instruction. -In the case where the index is zero, -the instruction corresponds to a parameter (not variable). - -*/ - -template -void forward2sweep( - const size_t q, - const size_t r, - const size_t n, - const size_t numvar, - local::player* play, - const size_t J, - Base* taylor, - const bool* cskip_op, - const pod_vector& var_by_load_op -) -{ - CPPAD_ASSERT_UNKNOWN( q > 0 ); - CPPAD_ASSERT_UNKNOWN( J >= q + 1 ); - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - - // used to avoid compiler errors until all operators are implemented - size_t p = q; - - // op code for current instruction - OpCode op; - - // index for current instruction - size_t i_op; - - // next variables - size_t i_var; - - // operation argument indices - const addr_t* arg = CPPAD_NULL; - - // work space used by UserOp. - vector user_vx; // empty vecotor - vector user_vy; // empty vecotor - vector user_tx_one; // argument vector Taylor coefficients - vector user_tx_all; - vector user_ty_one; // result vector Taylor coefficients - vector user_ty_all; - // - // information defined by forward_user - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - enum_user_state user_state = start_user; // proper initialization - // - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator -# ifndef NDEBUG - bool user_ok = false; // atomic op return value -# endif - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - // pointer to the beginning of the parameter vector - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - - // temporary indices - size_t i, j, k, ell; - - // number of orders for this user calculation - // (not needed for order zero) - const size_t user_q1 = q+1; - - // variable indices for results vector - // (done differently for order zero). - vector user_iy; - - // skip the BeginOp at the beginning of the recording - play->forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); -# if CPPAD_FORWARD2SWEEP_TRACE - bool user_trace = false; - std::cout << std::endl; - CppAD::vector Z_vec(q+1); -# endif - bool flag; // a temporary flag to use in switch cases - bool more_operators = true; - while(more_operators) - { - // this op - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( (i_op > n) | (op == InvOp) ); - CPPAD_ASSERT_UNKNOWN( (i_op <= n) | (op != InvOp) ); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, i_var); - - // check if we are skipping this operation - while( cskip_op[i_op] ) - { switch(op) - { case CSumOp: - // CSumOp has a variable number of arguments - play->forward_csum(op, arg, i_op, i_var); - break; - - case CSkipOp: - // CSkip has a variable number of arguments - play->forward_cskip(op, arg, i_op, i_var); - break; - - case UserOp: - { // skip all operations in this user atomic call - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - size_t n_skip = user_m + user_n + 1; - for(i = 0; i < n_skip; i++) - { play->forward_next(op, arg, i_op, i_var); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - } - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - } - break; - - default: - break; - } - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - } - - // action depends on the operator - switch( op ) - { - case AbsOp: - forward_abs_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case AddvvOp: - forward_addvv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_addpv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_acos_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_acosh_op_dir(q, r, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_asin_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_asinh_op_dir(q, r, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_atan_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_atanh_op_dir(q, r, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case CExpOp: - forward_cond_op_dir( - q, r, i_var, arg, num_par, parameter, J, taylor - ); - break; - // --------------------------------------------------- - - case CosOp: - // sin(x), cos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_cos_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // --------------------------------------------------- - - case CoshOp: - // sinh(x), cosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_cosh_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - play->forward_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // forward_next thinks it has no arguments. - // we must inform forward_next of this special case. - forward_csum_op_dir( - q, r, i_var, arg, num_par, parameter, J, taylor - ); - play->forward_csum(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case DisOp: - forward_dis_op(p, q, r, i_var, arg, J, taylor); - break; - // ------------------------------------------------- - - case DivvvOp: - forward_divvv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_divpv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_divvp_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case EndOp: - // needed for sparse_jacobian test - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - more_operators = false; - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case ErfOp: - forward_erf_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- -# endif - - case ExpOp: - forward_exp_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - forward_expm1_op_dir(q, r, i_var, arg[0], J, taylor); - break; -# endif - // ------------------------------------------------- - - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - break; - // ------------------------------------------------- - - case LdpOp: - case LdvOp: - forward_load_op( - play, - op, - p, - q, - r, - J, - i_var, - arg, - var_by_load_op.data(), - taylor - ); - break; - // --------------------------------------------------- - - case EqpvOp: - case EqvvOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case LepvOp: - case LevpOp: - case LevvOp: - case NepvOp: - case NevvOp: - CPPAD_ASSERT_UNKNOWN(q > 0 ); - break; - // ------------------------------------------------- - - case LogOp: - forward_log_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // --------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - forward_log1p_op_dir(q, r, i_var, arg[0], J, taylor); - break; -# endif - // --------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_mulpv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case MulvvOp: - forward_mulvv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ParOp: - k = i_var*(J-1)*r + i_var + (q-1)*r + 1; - for(ell = 0; ell < r; ell++) - taylor[k + ell] = Base(0.0); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_powpv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_powvp_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PowvvOp: - forward_powvv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case PriOp: - CPPAD_ASSERT_UNKNOWN(q > 0); - break; - // ------------------------------------------------- - - case SignOp: - // sign(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sign_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SinOp: - // cos(x), sin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sin_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SinhOp: - // cosh(x), sinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_sinh_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case SqrtOp: - forward_sqrt_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case StppOp: - case StpvOp: - case StvpOp: - case StvvOp: - CPPAD_ASSERT_UNKNOWN(q > 0 ); - break; - // ------------------------------------------------- - - case SubvvOp: - forward_subvv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_subpv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_subvp_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case TanOp: - // tan(x)^2, tan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_tan_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case TanhOp: - // tanh(x)^2, tanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - forward_tanh_op_dir(q, r, i_var, arg[0], J, taylor); - break; - // ------------------------------------------------- - - case UserOp: - // start or end an atomic operation sequence - flag = user_state == start_user; - user_atom = play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { user_tx_one.resize(user_n * user_q1); - user_tx_all.resize(user_n * (q * r + 1)); - // - user_ty_one.resize(user_m * user_q1); - user_ty_all.resize(user_m * (q * r + 1)); - // - user_iy.resize(user_m); - } - else - { // call users function for this operation - user_atom->set_old(user_old); - for(ell = 0; ell < r; ell++) - { // set user_tx - for(j = 0; j < user_n; j++) - { size_t j_all = j * (q * r + 1); - size_t j_one = j * user_q1; - user_tx_one[j_one+0] = user_tx_all[j_all+0]; - for(k = 1; k < user_q1; k++) - { size_t k_all = j_all + (k-1)*r+1+ell; - size_t k_one = j_one + k; - user_tx_one[k_one] = user_tx_all[k_all]; - } - } - // set user_ty - for(i = 0; i < user_m; i++) - { size_t i_all = i * (q * r + 1); - size_t i_one = i * user_q1; - user_ty_one[i_one+0] = user_ty_all[i_all+0]; - for(k = 1; k < q; k++) - { size_t k_all = i_all + (k-1)*r+1+ell; - size_t k_one = i_one + k; - user_ty_one[k_one] = user_ty_all[k_all]; - } - } - CPPAD_ATOMIC_CALL( - q, q, user_vx, user_vy, user_tx_one, user_ty_one - ); -# ifndef NDEBUG - if( ! user_ok ) - { std::string msg = - user_atom->afun_name() - + ": atomic_base.forward: returned false"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - for(i = 0; i < user_m; i++) - { if( user_iy[i] > 0 ) - { size_t i_taylor = user_iy[i]*((J-1)*r+1); - size_t q_taylor = i_taylor + (q-1)*r+1+ell; - size_t q_one = i * user_q1 + q; - taylor[q_taylor] = user_ty_one[q_one]; - } - } - } -# if CPPAD_FORWARD2SWEEP_TRACE - user_trace = true; -# endif - } - break; - - case UsrapOp: - // parameter argument in an atomic operation sequence - user_tx_all[user_j*(q*r+1) + 0] = parameter[ arg[0]]; - for(ell = 0; ell < r; ell++) - for(k = 1; k < user_q1; k++) - user_tx_all[user_j*(q*r+1) + (k-1)*r+1+ell] = Base(0.0); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsravOp: - // variable argument in an atomic operation sequence - user_tx_all[user_j*(q*r+1)+0] = taylor[arg[0]*((J-1)*r+1)+0]; - for(ell = 0; ell < r; ell++) - { for(k = 1; k < user_q1; k++) - { user_tx_all[user_j*(q*r+1) + (k-1)*r+1+ell] = - taylor[arg[0]*((J-1)*r+1) + (k-1)*r+1+ell]; - } - } - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrpOp: - // parameter result in an atomic operation sequence - user_iy[user_i] = 0; - user_ty_all[user_i*(q*r+1) + 0] = parameter[ arg[0]]; - for(ell = 0; ell < r; ell++) - for(k = 1; k < user_q1; k++) - user_ty_all[user_i*(q*r+1) + (k-1)*r+1+ell] = Base(0.0); - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case UsrrvOp: - // variable result in an atomic operation sequence - user_iy[user_i] = i_var; - user_ty_all[user_i*(q*r+1)+0] = taylor[i_var*((J-1)*r+1)+0]; - for(ell = 0; ell < r; ell++) - { for(k = 1; k < user_q1; k++) - { user_ty_all[user_i*(q*r+1) + (k-1)*r+1+ell] = - taylor[i_var*((J-1)*r+1) + (k-1)*r+1+ell]; - } - } - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - // ------------------------------------------------- - - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - forward_zmulpv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - forward_zmulvp_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - case ZmulvvOp: - forward_zmulvv_op_dir(q, r, i_var, arg, parameter, J, taylor); - break; - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -# if CPPAD_FORWARD2SWEEP_TRACE - if( user_trace ) - { user_trace = false; - CPPAD_ASSERT_UNKNOWN( op == UserOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(UsrrvOp) == 0 ); - for(i = 0; i < user_m; i++) if( user_iy[i] > 0 ) - { size_t i_tmp = (i_op + i) - user_m; - printOp( - std::cout, - play, - i_tmp, - user_iy[i], - UsrrvOp, - CPPAD_NULL - ); - Base* Z_tmp = taylor + user_iy[i]*((J-1) * r + 1); - { Z_vec[0] = Z_tmp[0]; - for(ell = 0; ell < r; ell++) - { std::cout << std::endl << " "; - for(size_t p_tmp = 1; p_tmp <= q; p_tmp++) - Z_vec[p_tmp] = Z_tmp[(p_tmp-1)*r+ell+1]; - printOpResult( - std::cout, - q + 1, - Z_vec.data(), - 0, - (Base *) CPPAD_NULL - ); - } - } - std::cout << std::endl; - } - } - const addr_t* arg_tmp = arg; - if( op == CSumOp ) - arg_tmp = arg - arg[-1] - 4; - if( op == CSkipOp ) - arg_tmp = arg - arg[-1] - 7; - if( op != UsrrvOp ) - { printOp( - std::cout, - play, - i_op, - i_var, - op, - arg_tmp - ); - Base* Z_tmp = CPPAD_NULL; - if( op == UsravOp ) - Z_tmp = taylor + arg[0]*((J-1) * r + 1); - else if( NumRes(op) > 0 ) - Z_tmp = taylor + i_var*((J-1)*r + 1); - if( Z_tmp != CPPAD_NULL ) - { Z_vec[0] = Z_tmp[0]; - for(ell = 0; ell < r; ell++) - { std::cout << std::endl << " "; - for(size_t p_tmp = 1; p_tmp <= q; p_tmp++) - Z_vec[p_tmp] = Z_tmp[ (p_tmp-1)*r + ell + 1]; - printOpResult( - std::cout, - q + 1, - Z_vec.data(), - 0, - (Base *) CPPAD_NULL - ); - } - } - std::cout << std::endl; - } - } - std::cout << std::endl; -# else - } -# endif - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - CPPAD_ASSERT_UNKNOWN( i_var + 1 == play->num_var_rec() ); - - return; -} - -// preprocessor symbols that are local to this file -# undef CPPAD_FORWARD2SWEEP_TRACE -# undef CPPAD_ATOMIC_CALL - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/hash_code.hpp b/external/cppad/include/cppad/local/hash_code.hpp deleted file mode 100644 index 3cd1bd7b7..000000000 --- a/external/cppad/include/cppad/local/hash_code.hpp +++ /dev/null @@ -1,251 +0,0 @@ -# ifndef CPPAD_LOCAL_HASH_CODE_HPP -# define CPPAD_LOCAL_HASH_CODE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -/*! -\file local/hash_code.hpp -CppAD hashing utility. -*/ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -General purpose hash code for an arbitrary value. - -\tparam Value -is the type of the argument being hash coded. -It should be a plain old data class; i.e., -the values included in the equality operator in the object and -not pointed to by the object. - -\param value -the value that we are generating a hash code for. -All of the fields in value should have been set before the hash code -is computed (otherwise undefined values are used). - -\return -is a hash code that is between zero and CPPAD_HASH_TABLE_SIZE - 1. - -\par Checked Assertions -\li \c std::numeric_limits::max() >= CPPAD_HASH_TABLE_SIZE -\li \c sizeof(value) is even -\li \c sizeof(unsigned short) == 2 -*/ -template -unsigned short local_hash_code(const Value& value) -{ CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() - >= - CPPAD_HASH_TABLE_SIZE - ); - CPPAD_ASSERT_UNKNOWN( sizeof(unsigned short) == 2 ); - CPPAD_ASSERT_UNKNOWN( sizeof(value) % 2 == 0 ); - // - const unsigned short* v - = reinterpret_cast(& value); - // - size_t i = sizeof(value) / 2 - 1; - // - size_t sum = v[i]; - // - while(i--) - sum += v[i]; - // - unsigned short code = static_cast( - sum % CPPAD_HASH_TABLE_SIZE - ); - return code; -} - -/*! -Specialized hash code for a CppAD operator and its arguments. - -\param op -is the operator that we are computing a hash code for. -If it is not one of the following operartors, the operator is not -hash coded and zero is returned: - -\li unary operators: -AbsOp, AcosOp, AcoshOp, AsinOp, AsinhOp, AtanOp, AtanhOp, CosOp, CoshOp -ExpOp, Expm1Op, LogOp, Log1pOp, SinOp, SinhOp, SqrtOp, TanOp, TanhOp - -\li binary operators where first argument is a parameter: -AddpvOp, DivpvOp, MulpvOp, PowpvOp, SubpvOp, ZmulpvOp - -\li binary operators where second argument is a parameter: -DivvpOp, PowvpOp, SubvpOp, Zmulvp - -\li binary operators where first is an index and second is a variable: -DisOp - -\li binary operators where both arguments are variables: -AddvvOp, DivvvOp, MulvvOp, PowvvOp, SubvvOp, ZmulvvOp - -\param arg -is a vector of length \c NumArg(op) or 2 (which ever is smaller), -containing the corresponding argument indices for this operator. - -\param npar -is the number of parameters corresponding to this operation sequence. - -\param par -is a vector of length \a npar containing the parameters -for this operation sequence; i.e., -given a parameter index of \c i, the corresponding parameter value is -\a par[i]. - - -\return -is a hash code that is between zero and CPPAD_HASH_TABLE_SIZE - 1. - -\par Checked Assertions -\c op must be one of the operators specified above. In addition, -\li \c std::numeric_limits::max() >= CPPAD_HASH_TABLE_SIZE -\li \c sizeof(size_t) is even -\li \c sizeof(Base) is even -\li \c sizeof(unsigned short) == 2 -\li \c size_t(op) < size_t(NumberOp) <= CPPAD_HASH_TABLE_SIZE -\li if the j-th argument for this operation is a parameter, arg[j] < npar. -*/ - -template -unsigned short local_hash_code( - OpCode op , - const addr_t* arg , - size_t npar , - const Base* par ) -{ CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() - >= - CPPAD_HASH_TABLE_SIZE - ); - CPPAD_ASSERT_UNKNOWN( size_t (op) < size_t(NumberOp) ); - CPPAD_ASSERT_UNKNOWN( sizeof(unsigned short) == 2 ); - CPPAD_ASSERT_UNKNOWN( sizeof(addr_t) % 2 == 0 ); - CPPAD_ASSERT_UNKNOWN( sizeof(Base) % 2 == 0 ); - unsigned short op_fac = static_cast ( - CPPAD_HASH_TABLE_SIZE / static_cast(NumberOp) - ); - CPPAD_ASSERT_UNKNOWN( op_fac > 0 ); - - // number of shorts per addr_t value - size_t short_addr_t = sizeof(addr_t) / 2; - - // number of shorts per Base value - size_t short_base = sizeof(Base) / 2; - - // initialize with value that separates operators as much as possible - unsigned short code = static_cast( - static_cast(op) * op_fac - ); - - // now code in the operands - size_t i; - const unsigned short* v; - - // first argument - switch(op) - { // Binary operators where first arugment is a parameter. - // Code parameters by value instead of - // by index for two reasons. One, it gives better separation. - // Two, different indices can be same parameter value. - case AddpvOp: - case DivpvOp: - case MulpvOp: - case PowpvOp: - case SubpvOp: - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - v = reinterpret_cast(par + arg[0]); - i = short_base; - while(i--) - code += v[i]; - v = reinterpret_cast(arg + 1); - i = short_addr_t; - while(i--) - code += v[i]; - break; - - // Binary operator where first argument is an index and - // second is a variable (same as both variables). - case DisOp: - - // Binary operators where both arguments are variables - case AddvvOp: - case DivvvOp: - case MulvvOp: - case PowvvOp: - case SubvvOp: - case ZmulvvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - v = reinterpret_cast(arg + 0); - i = 2 * short_addr_t; - while(i--) - code += v[i]; - break; - - // Binary operators where second arugment is a parameter. - case DivvpOp: - case PowvpOp: - case SubvpOp: - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - v = reinterpret_cast(arg + 0); - i = short_addr_t; - while(i--) - code += v[i]; - v = reinterpret_cast(par + arg[1]); - i = short_base; - while(i--) - code += v[i]; - break; - - // Unary operators - case AbsOp: - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case ErfOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case TanOp: - case TanhOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 || op == ErfOp ); - v = reinterpret_cast(arg + 0); - i = short_addr_t; - while(i--) - code += v[i]; - break; - - // should have been one of he cases above - default: - CPPAD_ASSERT_UNKNOWN(false); - } - - return code % CPPAD_HASH_TABLE_SIZE; -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/independent.hpp b/external/cppad/include/cppad/local/independent.hpp deleted file mode 100644 index c8a3d858a..000000000 --- a/external/cppad/include/cppad/local/independent.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// $Id: independent.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_INDEPENDENT_HPP -# define CPPAD_LOCAL_INDEPENDENT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/* -\file local/independent.hpp -Implement the declaration of the independent variables -*/ - -/*! -Implementation of the declaration of independent variables (in local namespace). - -\tparam VectorAD -This is simple vector type with elements of type AD. - -\param x -Vector of the independent variablerd. - -\param abort_op_index -operator index at which execution will be aborted (during the recording -of operations). The value zero corresponds to not aborting (will not match). -*/ -template -template -void ADTape::Independent(VectorAD &x, size_t abort_op_index) -{ - // check VectorAD is Simple Vector class with AD elements - CheckSimpleVector< AD, VectorAD>(); - - // dimension of the domain space - size_t n = x.size(); - CPPAD_ASSERT_KNOWN( - n > 0, - "Indepdendent: the argument vector x has zero size" - ); - CPPAD_ASSERT_UNKNOWN( Rec_.num_var_rec() == 0 ); - - // set the abort index before doing anything else - Rec_.set_abort_op_index(abort_op_index); - - // mark the beginning of the tape and skip the first variable index - // (zero) because parameters use taddr zero - CPPAD_ASSERT_NARG_NRES(BeginOp, 1, 1); - Rec_.PutOp(BeginOp); - Rec_.PutArg(0); - - // place each of the independent variables in the tape - CPPAD_ASSERT_NARG_NRES(InvOp, 0, 1); - size_t j; - for(j = 0; j < n; j++) - { // tape address for this independent variable - x[j].taddr_ = Rec_.PutOp(InvOp); - x[j].tape_id_ = id_; - CPPAD_ASSERT_UNKNOWN( size_t(x[j].taddr_) == j+1 ); - CPPAD_ASSERT_UNKNOWN( Variable(x[j] ) ); - } - - // done specifying all of the independent variables - size_independent_ = n; -} -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/load_op.hpp b/external/cppad/include/cppad/local/load_op.hpp deleted file mode 100644 index 3781ff36b..000000000 --- a/external/cppad/include/cppad/local/load_op.hpp +++ /dev/null @@ -1,689 +0,0 @@ -# ifndef CPPAD_LOCAL_LOAD_OP_HPP -# define CPPAD_LOCAL_LOAD_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file load_op.hpp -Setting a variable so that it corresponds to current value of a VecAD element. -*/ -/* -============================================================================== - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - -============================================================================== -*/ -/*! -Shared documentation for zero order forward mode implementation of -op = LdpOp or LdvOp (not called). - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD and computations by this routine are done using type Base. - -\param play -is the tape that this operation appears in. -This is for error detection and not used when NDEBUG is defined. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\n -arg[0] -is the offset of this VecAD vector relative to the beginning -of the isvar_by_ind and index_by_ind arrays. -\n -\n -arg[1] -\n -If this is the LdpOp operation (if x is a parameter), -i_vec is defined by -\verbatim - i_vec = arg[1] -\endverbatim -If this is the LdvOp operation (if x is a variable), -i_vec is defined by -\verbatim - i_vec = floor( taylor[ arg[1] * cap_order + 0 ] ) -\endverbatim -where floor(c) is the greatest integer less that or equal c. -\n -\n -arg[2] -Is the index of this vecad load instruction in the -var_by_load_op array. - -\param parameter -If v[x] is a parameter, parameter[ i_v_x ] is its value. -This vector has size play->num_par_rec(). - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\param taylor -\n -Input -\n -In LdvOp case, taylor[ arg[1] * cap_order + 0 ] -is used to compute the index in the definition of i_vec above. -If v[x] is a variable, taylor[ i_v_x * cap_order + 0 ] -is the zero order Taylor coefficient for v[x]. -\n -\n -Output -\n -taylor[ i_z * cap_order + 0 ] -is set to the zero order Taylor coefficient for the variable z. - -\param isvar_by_ind -If isvar_by_ind[ arg[0] + i_vec ] is true, -v[x] is a variable. Otherwise it is a parameter. -This vector has size play->num_vec_ind_rec(). - -\param index_by_ind -index_by_ind[ arg[0] - 1 ] -is the number of elements in the user vector containing this element. -index_by_ind[ arg[0] + i_vec ] is the variable or -parameter index for this element, -This array has size play->num_vec_ind_rec(). - -\param var_by_load_op -is a vector with size play->num_load_op_rec(). -The input value of its elements does not matter. -Upon return, it contains the variable index corresponding to each load -instruction. -In the case where the index is zero, -the instruction corresponds to a parameter (not variable). -This array has size play->num_load_op_rec(). - -\par Check User Errors -\li In the LdvOp case check that the index is with in range; i.e. -i_vec < index_by_ind[ arg[0] - 1 ]. -Note that, if x is a parameter, -the corresponding vector index and it does not change. -In this case, the error above should be detected during tape recording. -*/ -template -inline void forward_load_op_0( - local::player* play , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind , - addr_t* var_by_load_op ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -/*! -Shared documentation for sparsity operations corresponding to -op = LdpOp or LdvOp (not called). - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param op -is the code corresponding to this operator; -i.e., LdpOp or LdvOp. - -\param i_z -is the AD variable index corresponding to the variable z; i.e., -the set with index \a i_z in \a var_sparsity is the sparsity pattern -correpsonding to z. - -\param arg -\n -\a arg[0] -is the offset corresponding to this VecAD vector in the VecAD combined array. - -\param num_combined -is the total number of elements in the VecAD combinded array. - -\param combined -is the VecAD combined array. -\n -\n -\a combined[ \a arg[0] - 1 ] -is the index of the set corresponding to the vector v in \a vecad_sparsity. -We use the notation i_v for this value; i.e., -\verbatim - i_v = combined[ \a arg[0] - 1 ] -\endverbatim - -\param var_sparsity -The set with index \a i_z in \a var_sparsity is the sparsity pattern for z. -This is an output for forward mode operations, -and an input for reverse mode operations. - -\param vecad_sparsity -The set with index \a i_v is the sparsity pattern for the vector v. -This is an input for forward mode operations. -For reverse mode operations, -the sparsity pattern for z is added to the sparsity pattern for v. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 1 -\li 0 < \a arg[0] -\li \a arg[0] < \a num_combined -\li i_v < \a vecad_sparsity.n_set() -*/ -template -inline void sparse_load_op( - OpCode op , - size_t i_z , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - - -/*! -Zero order forward mode implementation of op = LdpOp. - -\copydetails CppAD::local::forward_load_op_0 -*/ -template -inline void forward_load_p_op_0( - local::player* play , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind , - addr_t* var_by_load_op ) -{ CPPAD_ASSERT_UNKNOWN( NumArg(LdpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LdpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_load_op_rec() ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // Because the index is a parameter, this indexing error should have been - // caught and reported to the user when the tape is recording. - size_t i_vec = arg[1]; - CPPAD_ASSERT_UNKNOWN( i_vec < index_by_ind[ arg[0] - 1 ] ); - CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < play->num_vec_ind_rec() ); - - size_t i_v_x = index_by_ind[ arg[0] + i_vec ]; - Base* z = taylor + i_z * cap_order; - if( isvar_by_ind[ arg[0] + i_vec ] ) - { CPPAD_ASSERT_UNKNOWN( i_v_x < i_z ); - var_by_load_op[ arg[2] ] = addr_t( i_v_x ); - Base* v_x = taylor + i_v_x * cap_order; - z[0] = v_x[0]; - } - else - { CPPAD_ASSERT_UNKNOWN( i_v_x < play->num_par_rec() ); - var_by_load_op[ arg[2] ] = 0; - Base v_x = parameter[i_v_x]; - z[0] = v_x; - } -} - -/*! -Zero order forward mode implementation of op = LdvOp. - -\copydetails CppAD::local::forward_load_op_0 -*/ -template -inline void forward_load_v_op_0( - local::player* play , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind , - addr_t* var_by_load_op ) -{ CPPAD_ASSERT_UNKNOWN( NumArg(LdvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LdvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_load_op_rec() ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - size_t i_vec = Integer( taylor[ arg[1] * cap_order + 0 ] ); - CPPAD_ASSERT_KNOWN( - i_vec < index_by_ind[ arg[0] - 1 ] , - "VecAD: index during zero order forward sweep is out of range" - ); - CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < play->num_vec_ind_rec() ); - - size_t i_v_x = index_by_ind[ arg[0] + i_vec ]; - Base* z = taylor + i_z * cap_order; - if( isvar_by_ind[ arg[0] + i_vec ] ) - { CPPAD_ASSERT_UNKNOWN( i_v_x < i_z ); - var_by_load_op[ arg[2] ] = addr_t( i_v_x ); - Base* v_x = taylor + i_v_x * cap_order; - z[0] = v_x[0]; - } - else - { CPPAD_ASSERT_UNKNOWN( i_v_x < play->num_par_rec() ); - var_by_load_op[ arg[2] ] = 0; - Base v_x = parameter[i_v_x]; - z[0] = v_x; - } -} - -/*! -Forward mode, except for zero order, for op = LdpOp or op = LdvOp - - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD and computations by this routine are done using type Base. - -\param play -is the tape that this operation appears in. -This is for error detection and not used when NDEBUG is defined. - -\param op -is the code corresponding to this operator; i.e., LdpOp or LdvOp -(only used for error checking). - -\param p -is the lowest order of the Taylor coefficient that we are computing. - -\param q -is the highest order of the Taylor coefficient that we are computing. - -\param r -is the number of directions for the Taylor coefficients that we -are computing. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -arg[2] -Is the index of this vecad load instruction in the var_by_load_op array. - -\param var_by_load_op -is a vector with size play->num_load_op_rec(). -It contains the variable index corresponding to each load instruction. -In the case where the index is zero, -the instruction corresponds to a parameter (not variable). - -\par i_var -We use the notation -\verbatim - i_var = size_t( var_by_load_op[ arg[2] ] ) -\endverbatim - -\param taylor -\n -Input -\n -If i_var > 0, v[x] is a variable and -for k = 1 , ... , q -taylor[ i_var * tpv + (k-1)*r+1+ell ] -is the k-th order coefficient for v[x] in the ell-th direction, -\n -\n -Output -\n -for k = p , ... , q, -taylor[ i_z * tpv + (k-1)*r+1+ell ] -is set to the k-order Taylor coefficient for z in the ell-th direction. -*/ -template -inline void forward_load_op( - const local::player* play , - OpCode op , - size_t p , - size_t q , - size_t r , - size_t cap_order , - size_t i_z , - const addr_t* arg , - const addr_t* var_by_load_op , - Base* taylor ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( 0 < r); - CPPAD_ASSERT_UNKNOWN( 0 < p); - CPPAD_ASSERT_UNKNOWN( p <= q ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_load_op_rec() ); - - size_t i_var = size_t( var_by_load_op[ arg[2] ] ); - CPPAD_ASSERT_UNKNOWN( i_var < i_z ); - - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* z = taylor + i_z * num_taylor_per_var; - if( i_var > 0 ) - { Base* v_x = taylor + i_var * num_taylor_per_var; - for(size_t ell = 0; ell < r; ell++) - { for(size_t k = p; k <= q; k++) - { size_t m = (k-1) * r + 1 + ell; - z[m] = v_x[m]; - } - } - } - else - { for(size_t ell = 0; ell < r; ell++) - { for(size_t k = p; k <= q; k++) - { size_t m = (k-1) * r + 1 + ell; - z[m] = Base(0.0); - } - } - } -} - -/*! -Reverse mode for op = LdpOp or LdvOp. - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -This routine is given the partial derivatives of a function -G(z , y[x] , w , u ... ) -and it uses them to compute the partial derivatives of -\verbatim - H( y[x] , w , u , ... ) = G[ z( y[x] ) , y[x] , w , u , ... ] -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param op -is the code corresponding to this operator; i.e., LdpOp or LdvOp -(only used for error checking). - -\param d -highest order the Taylor coefficient that we are computing the partial -derivative with respect to. - -\param i_z -is the AD variable index corresponding to the variable z. - -\param arg -\a arg[2] -Is the index of this vecad load instruction in the -var_by_load_op array. - -\param cap_order -number of columns in the matrix containing the Taylor coefficients -(not used). - -\param taylor -matrix of Taylor coefficients (not used). - -\param nc_partial -number of colums in the matrix containing all the partial derivatives -(not used if \a arg[2] is zero). - -\param partial -If \a arg[2] is zero, y[x] is a parameter -and no values need to be modified; i.e., \a partial is not used. -Otherwise, y[x] is a variable and: -\n -\n -\a partial [ \a i_z * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G -with respect to the k-th order Taylor coefficient for z. -\n -\n -If \a arg[2] is not zero, -\a partial [ \a arg[2] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative with respect to -the k-th order Taylor coefficient for x. -On input, it corresponds to the function G, -and on output it corresponds to the the function H. - -\param var_by_load_op -is a vector with size play->num_load_op_rec(). -It contains the variable index corresponding to each load instruction. -In the case where the index is zero, -the instruction corresponds to a parameter (not variable). - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 1 -\li d < cap_order -\li size_t(arg[2]) < i_z -*/ -template -inline void reverse_load_op( - OpCode op , - size_t d , - size_t i_z , - const addr_t* arg , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial , - const addr_t* var_by_load_op ) -{ size_t i_load = size_t( var_by_load_op[ arg[2] ] ); - - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( i_load < i_z ); - - if( i_load > 0 ) - { - Base* pz = partial + i_z * nc_partial; - Base* py_x = partial + i_load * nc_partial; - size_t j = d + 1; - while(j--) - py_x[j] += pz[j]; - } -} - - -/*! -Forward mode sparsity operations for LdpOp and LdvOp - -\param dependency -is this a dependency (or sparsity) calculation. - -\copydetails CppAD::local::sparse_load_op -*/ -template -inline void forward_sparse_load_op( - bool dependency , - OpCode op , - size_t i_z , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined ); - size_t i_v = combined[ arg[0] - 1 ]; - CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); - - var_sparsity.assignment(i_z, i_v, vecad_sparsity); - if( dependency & (op == LdvOp) ) - var_sparsity.binary_union(i_z, i_z, arg[1], var_sparsity); - - return; -} - - -/*! -Reverse mode Jacobian sparsity operations for LdpOp and LdvOp - -\param dependency -is this a dependency (or sparsity) calculation. - -\copydetails CppAD::local::sparse_load_op -*/ -template -inline void reverse_sparse_jacobian_load_op( - bool dependency , - OpCode op , - size_t i_z , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined ); - size_t i_v = combined[ arg[0] - 1 ]; - CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); - - vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity); - if( dependency & (op == LdvOp) ) - var_sparsity.binary_union(arg[1], arg[1], i_z, var_sparsity); - - return; -} - - -/*! -Reverse mode Hessian sparsity operations for LdpOp and LdvOp - -\copydetails CppAD::local::sparse_load_op - -\param var_jacobian -\a var_jacobian[i_z] -is false (true) if the Jacobian of G with respect to z is always zero -(many be non-zero). - -\param vecad_jacobian -\a vecad_jacobian[i_v] -is false (true) if the Jacobian with respect to x is always zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. - -*/ -template -inline void reverse_sparse_hessian_load_op( - OpCode op , - size_t i_z , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity , - bool* var_jacobian , - bool* vecad_jacobian ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined ); - size_t i_v = combined[ arg[0] - 1 ]; - CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); - - vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity); - - vecad_jacobian[i_v] |= var_jacobian[i_z]; - - return; -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/log1p_op.hpp b/external/cppad/include/cppad/local/log1p_op.hpp deleted file mode 100644 index 1e81fd788..000000000 --- a/external/cppad/include/cppad/local/log1p_op.hpp +++ /dev/null @@ -1,204 +0,0 @@ -# ifndef CPPAD_LOCAL_LOG1P_OP_HPP -# define CPPAD_LOCAL_LOG1P_OP_HPP -# if CPPAD_USE_CPLUSPLUS_2011 - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file log1p_op.hpp -Forward and reverse mode calculations for z = log1p(x). -*/ - -/*! -Compute forward mode Taylor coefficient for result of op = Log1pOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log1p(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_log1p_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - size_t k; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - if( p == 0 ) - { z[0] = log1p( x[0] ); - p++; - if( q == 0 ) - return; - } - if ( p == 1 ) - { z[1] = x[1] / (Base(1.0) + x[0]); - p++; - } - for(size_t j = p; j <= q; j++) - { - z[j] = -z[1] * x[j-1]; - for(k = 2; k < j; k++) - z[j] -= Base(double(k)) * z[k] * x[j-k]; - z[j] /= Base(double(j)); - z[j] += x[j]; - z[j] /= (Base(1.0) + x[0]); - } -} - -/*! -Muiltiple directions Taylor coefficient for op = Log1pOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log1p(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_log1p_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(double(q)) * x[m+ell]; - for(size_t k = 1; k < q; k++) - z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - z[m+ell] /= (Base(double(q)) + Base(q) * x[0]); - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = Log1pOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log1p(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_log1p_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = log1p( x[0] ); -} - -/*! -Compute reverse mode partial derivatives for result of op = Log1pOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log1p(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_log1p_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ size_t j, k; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - Base inv_1px0 = Base(1.0) / (Base(1) + x[0]); - - j = d; - while(j) - { // scale partial w.r.t z[j] - pz[j] = azmul(pz[j] , inv_1px0); - - px[0] -= azmul(pz[j], z[j]); - px[j] += pz[j]; - - // further scale partial w.r.t. z[j] - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { pz[k] -= Base(double(k)) * azmul(pz[j], x[j-k]); - px[j-k] -= Base(double(k)) * azmul(pz[j], z[k]); - } - --j; - } - px[0] += azmul(pz[0], inv_1px0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif -# endif diff --git a/external/cppad/include/cppad/local/log_op.hpp b/external/cppad/include/cppad/local/log_op.hpp deleted file mode 100644 index e416fbe8c..000000000 --- a/external/cppad/include/cppad/local/log_op.hpp +++ /dev/null @@ -1,202 +0,0 @@ -# ifndef CPPAD_LOCAL_LOG_OP_HPP -# define CPPAD_LOCAL_LOG_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file log_op.hpp -Forward and reverse mode calculations for z = log(x). -*/ - -/*! -Compute forward mode Taylor coefficient for result of op = LogOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_log_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - size_t k; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - if( p == 0 ) - { z[0] = log( x[0] ); - p++; - if( q == 0 ) - return; - } - if ( p == 1 ) - { z[1] = x[1] / x[0]; - p++; - } - for(size_t j = p; j <= q; j++) - { - z[j] = -z[1] * x[j-1]; - for(k = 2; k < j; k++) - z[j] -= Base(double(k)) * z[k] * x[j-k]; - z[j] /= Base(double(j)); - z[j] += x[j]; - z[j] /= x[0]; - } -} - -/*! -Muiltiple directions Taylor coefficient for op = LogOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_log_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(double(q)) * x[m+ell]; - for(size_t k = 1; k < q; k++) - z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell]; - z[m+ell] /= (Base(double(q)) * x[0]); - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = LogOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_log_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = log( x[0] ); -} - -/*! -Compute reverse mode partial derivatives for result of op = LogOp. - -The C++ source code corresponding to this operation is -\verbatim - z = log(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_log_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ size_t j, k; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - Base inv_x0 = Base(1.0) / x[0]; - - j = d; - while(j) - { // scale partial w.r.t z[j] - pz[j] = azmul(pz[j] , inv_x0); - - px[0] -= azmul(pz[j], z[j]); - px[j] += pz[j]; - - // further scale partial w.r.t. z[j] - pz[j] /= Base(double(j)); - - for(k = 1; k < j; k++) - { pz[k] -= Base(double(k)) * azmul(pz[j], x[j-k]); - px[j-k] -= Base(double(k)) * azmul(pz[j], z[k]); - } - --j; - } - px[0] += azmul(pz[0], inv_x0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/mul_op.hpp b/external/cppad/include/cppad/local/mul_op.hpp deleted file mode 100644 index 9aabf0c1e..000000000 --- a/external/cppad/include/cppad/local/mul_op.hpp +++ /dev/null @@ -1,359 +0,0 @@ -# ifndef CPPAD_LOCAL_MUL_OP_HPP -# define CPPAD_LOCAL_MUL_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file mul_op.hpp -Forward and reverse mode calculations for z = x * y. -*/ - -// --------------------------- Mulvv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = MulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_mulvv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - size_t k; - for(size_t d = p; d <= q; d++) - { z[d] = Base(0.0); - for(k = 0; k <= d; k++) - z[d] += x[d-k] * y[k]; - } -} -/*! -Multiple directions forward mode Taylor coefficients for op = MulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_mulvv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* y = taylor + arg[1] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t k, ell, m; - for(ell = 0; ell < r; ell++) - { m = (q-1)*r + ell + 1; - z[m] = x[0] * y[m] + x[m] * y[0]; - for(k = 1; k < q; k++) - z[m] += x[(q-k-1)*r + ell + 1] * y[(k-1)*r + ell + 1]; - } -} - -/*! -Compute zero order forward mode Taylor coefficients for result of op = MulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_mulvv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x[0] * y[0]; -} - -/*! -Compute reverse mode partial derivatives for result of op = MulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_mulvv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - const Base* x = taylor + arg[0] * cap_order; - const Base* y = taylor + arg[1] * cap_order; - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - - // number of indices to access - size_t j = d + 1; - size_t k; - while(j) - { --j; - for(k = 0; k <= j; k++) - { - px[j-k] += azmul(pz[j], y[k]); - py[k] += azmul(pz[j], x[j-k]); - } - } -} -// --------------------------- Mulpv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = MulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_mulpv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Paraemter value - Base x = parameter[ arg[0] ]; - - for(size_t d = p; d <= q; d++) - z[d] = x * y[d]; -} -/*! -Multiple directions forward mode Taylor coefficients for op = MulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_mulpv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1) * r + 1; - Base* y = taylor + arg[1] * num_taylor_per_var + m; - Base* z = taylor + i_z * num_taylor_per_var + m; - - // Paraemter value - Base x = parameter[ arg[0] ]; - - for(size_t ell = 0; ell < r; ell++) - z[ell] = x * y[ell]; -} -/*! -Compute zero order forward mode Taylor coefficient for result of op = MulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_mulpv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 ); - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x * y[0]; -} - -/*! -Compute reverse mode partial derivative for result of op = MulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x * y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_mulpv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - Base x = parameter[ arg[0] ]; - - // Partial derivatives corresponding to arguments and result - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t j = d + 1; - while(j) - { --j; - py[j] += azmul(pz[j], x); - } -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/op.hpp b/external/cppad/include/cppad/local/op.hpp deleted file mode 100644 index 8f509afa2..000000000 --- a/external/cppad/include/cppad/local/op.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// $Id: op.hpp 3876 2017-02-10 12:45:08Z bradbell $ -# ifndef CPPAD_LOCAL_OP_HPP -# define CPPAD_LOCAL_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// used by the sparse operators -# include - -// operations -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - - -# endif diff --git a/external/cppad/include/cppad/local/op_code.hpp b/external/cppad/include/cppad/local/op_code.hpp deleted file mode 100644 index 239538a19..000000000 --- a/external/cppad/include/cppad/local/op_code.hpp +++ /dev/null @@ -1,1069 +0,0 @@ -# ifndef CPPAD_LOCAL_OP_CODE_HPP -# define CPPAD_LOCAL_OP_CODE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include -# include - -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file op_code.hpp -Defines the OpCode enum type and functions related to it. - -*/ - - -/*! -Type used to distinguish different AD< \a Base > atomic operations. - -Each of the operators ends with the characters Op. Ignoring the Op at the end, -the operators appear in alphabetical order. Binary operation where both -operands have type AD< \a Base > use the following convention for thier endings: -\verbatim - Ending Left-Operand Right-Operand - pvOp parameter variable - vpOp variable parameter - vvOp variable variable -\endverbatim -For example, AddpvOp represents the addition operator where the left -operand is a parameter and the right operand is a variable. -*/ -// alphabetical order is checked by bin/check_op_code.sh -enum OpCode { - AbsOp, // fabs(variable) - AcosOp, // acos(variable) - AcoshOp, // acosh(variable) - AddpvOp, // parameter + variable - AddvvOp, // variable + variable - AsinOp, // asin(variable) - AsinhOp, // asinh(variable) - AtanOp, // atan(variable) - AtanhOp, // atanh(variable) - BeginOp, // used to mark the beginning of the tape - CExpOp, // CondExpRel(left, right, trueCase, falseCase) - // arg[0] = the Rel operator: Lt, Le, Eq, Ge, Gt, or Ne - // arg[1] & 1 = is left a variable - // arg[1] & 2 = is right a variable - // arg[1] & 4 = is trueCase a variable - // arg[1] & 8 = is falseCase a variable - // arg[2] = index correspoding to left - // arg[3] = index correspoding to right - // arg[4] = index correspoding to trueCase - // arg[5] = index correspoding to falseCase - CosOp, // cos(variable) - CoshOp, // cosh(variable) - CSkipOp, // Conditional skip - // arg[0] = the Rel operator: Lt, Le, Eq, Ge, Gt, or Ne - // arg[1] & 1 = is left a variable - // arg[1] & 2 = is right a variable - // arg[2] = index correspoding to left - // arg[3] = index correspoding to right - // arg[4] = number of operations to skip if CExpOp comparision is true - // arg[5] = number of operations to skip if CExpOp comparision is false - // arg[6] -> arg[5+arg[4]] = skip operations if true - // arg[6+arg[4]] -> arg[5+arg[4]+arg[5]] = skip operations if false - // arg[6+arg[4]+arg[5]] = arg[4] + arg[5] - CSumOp, // Cummulative summation - // arg[0] = number of addition variables in summation - // arg[1] = number of subtraction variables in summation - // arg[2] = index of parameter that initializes summation - // arg[3] -> arg[2+arg[0]] = index for positive variables - // arg[3+arg[0]] -> arg[2+arg[0]+arg[1]] = index for minus variables - // arg[3+arg[0]+arg[1]] = arg[0] + arg[1] - DisOp, // discrete::eval(index, variable) - DivpvOp, // parameter / variable - DivvpOp, // variable / parameter - DivvvOp, // variable / variable - EndOp, // used to mark the end of the tape - EqpvOp, // parameter == variable - EqvvOp, // variable == variable - ErfOp, // erf(variable) - ExpOp, // exp(variable) - Expm1Op, // expm1(variable) - InvOp, // independent variable - LdpOp, // z[parameter] - LdvOp, // z[variable] - LepvOp, // parameter <= variable - LevpOp, // variable <= parameter - LevvOp, // variable <= variable - LogOp, // log(variable) - Log1pOp, // log1p(variable) - LtpvOp, // parameter < variable - LtvpOp, // variable < parameter - LtvvOp, // variable < variable - MulpvOp, // parameter * variable - MulvvOp, // variable * variable - NepvOp, // parameter != variable - NevvOp, // variable != variable - ParOp, // parameter - PowpvOp, // pow(parameter, variable) - PowvpOp, // pow(variable, parameter) - PowvvOp, // pow(variable, variable) - PriOp, // PrintFor(text, parameter or variable, parameter or variable) - SignOp, // sign(variable) - SinOp, // sin(variable) - SinhOp, // sinh(variable) - SqrtOp, // sqrt(variable) - StppOp, // z[parameter] = parameter - StpvOp, // z[parameter] = variable - StvpOp, // z[variable] = parameter - StvvOp, // z[variable] = variable - SubpvOp, // parameter - variable - SubvpOp, // variable - parameter - SubvvOp, // variable - variable - TanOp, // tan(variable) - TanhOp, // tan(variable) - // user atomic operation codes - UserOp, // start of a user atomic operaiton - // arg[0] = index of the operation if atomic_base class - // arg[1] = extra information passed trough by deprecated old atomic class - // arg[2] = number of arguments to this atomic function - // arg[3] = number of results for this atomic function - UsrapOp, // this user atomic argument is a parameter - UsravOp, // this user atomic argument is a variable - UsrrpOp, // this user atomic result is a parameter - UsrrvOp, // this user atomic result is a variable - ZmulpvOp, // azmul(parameter, variable) - ZmulvpOp, // azmul(variabe, parameter) - ZmulvvOp, // azmul(variable, variable) - NumberOp // number of operator codes (not an operator) -}; -// Note that bin/check_op_code.sh assumes the pattern '^\tNumberOp$' occurs -// at the end of this list and only at the end of this list. - -/*! -Number of arguments for a specified operator. - -\return -Number of arguments corresponding to the specified operator. - -\param op -Operator for which we are fetching the number of arugments. - -\par NumArgTable -this table specifes the number of arguments stored for each -occurance of the operator that is the i-th value in the OpCode enum type. -For example, for the first three OpCode enum values we have -\verbatim -OpCode j NumArgTable[j] Meaning -AbsOp 0 1 index of variable we are taking absolute value of -AcosOp 1 1 index of variable we are taking acos of -AcoshOp 2 1 index of variable we are taking acosh of -\endverbatim -Note that the meaning of the arguments depends on the operator. -*/ -inline size_t NumArg( OpCode op) -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - - // agreement with OpCode is checked by bin/check_op_code.sh - static const size_t NumArgTable[] = { - 1, // AbsOp - 1, // AcosOp - 1, // AcoshOp - 2, // AddpvOp - 2, // AddvvOp - 1, // AsinOp - 1, // AsinhOp - 1, // AtanOp - 1, // AtanhOp - 1, // BeginOp offset first real argument to have index 1 - 6, // CExpOp - 1, // CosOp - 1, // CoshOp - 0, // CSkipOp (actually has a variable number of arguments, not zero) - 0, // CSumOp (actually has a variable number of arguments, not zero) - 2, // DisOp - 2, // DivpvOp - 2, // DivvpOp - 2, // DivvvOp - 0, // EndOp - 2, // EqpvOp - 2, // EqvvOp - 3, // ErfOp - 1, // ExpOp - 1, // Expm1Op - 0, // InvOp - 3, // LdpOp - 3, // LdvOp - 2, // LepvOp - 2, // LevpOp - 2, // LevvOp - 1, // LogOp - 1, // Log1pOp - 2, // LtpvOp - 2, // LtvpOp - 2, // LtvvOp - 2, // MulpvOp - 2, // MulvvOp - 2, // NepvOp - 2, // NevvOp - 1, // ParOp - 2, // PowpvOp - 2, // PowvpOp - 2, // PowvvOp - 5, // PriOp - 1, // SignOp - 1, // SinOp - 1, // SinhOp - 1, // SqrtOp - 3, // StppOp - 3, // StpvOp - 3, // StvpOp - 3, // StvvOp - 2, // SubpvOp - 2, // SubvpOp - 2, // SubvvOp - 1, // TanOp - 1, // TanhOp - 4, // UserOp - 1, // UsrapOp - 1, // UsravOp - 1, // UsrrpOp - 0, // UsrrvOp - 2, // ZmulpvOp - 2, // ZmulvpOp - 2, // ZmulvvOp - 0 // NumberOp not used - }; -# ifndef NDEBUG - // only do these checks once to save time - static bool first = true; - if( first ) - { CPPAD_ASSERT_UNKNOWN( size_t(NumberOp) + 1 == - sizeof(NumArgTable) / sizeof(NumArgTable[0]) - ); - CPPAD_ASSERT_UNKNOWN( size_t(NumberOp) <= - std::numeric_limits::max() - ); - first = false; - } - // do this check every time - CPPAD_ASSERT_UNKNOWN( size_t(op) < size_t(NumberOp) ); -# endif - - return NumArgTable[op]; -} - -/*! -Number of variables resulting from the specified operation. - -\param op -Operator for which we are fecching the number of results. - -\par NumResTable -table specifes the number of varibles that result for each -occurance of the operator that is the i-th value in the OpCode enum type. -For example, for the first three OpCode enum values we have -\verbatim -OpCode j NumResTable[j] Meaning -AbsOp 0 1 variable that is the result of the absolute value -AcosOp 1 2 acos(x) and sqrt(1-x*x) are required for this op -AcoshOp 2 2 acosh(x) and sqrt(x*x-1) are required for this op -\endverbatim -*/ -inline size_t NumRes(OpCode op) -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - - // agreement with OpCode is checked by bin/check_op_code.sh - static const size_t NumResTable[] = { - 1, // AbsOp - 2, // AcosOp - 2, // AcoshOp - 1, // AddpvOp - 1, // AddvvOp - 2, // AsinOp - 2, // AsinhOp - 2, // AtanOp - 2, // AtanhOp - 1, // BeginOp offsets first variable to have index one (not zero) - 1, // CExpOp - 2, // CosOp - 2, // CoshOp - 0, // CSkipOp - 1, // CSumOp - 1, // DisOp - 1, // DivpvOp - 1, // DivvpOp - 1, // DivvvOp - 0, // EndOp - 0, // EqpvOp - 0, // EqvvOp - 5, // ErfOp - 1, // ExpOp - 1, // Expm1Op - 1, // InvOp - 1, // LdpOp - 1, // LdvOp - 0, // LepvOp - 0, // LevpOp - 0, // LevvOp - 1, // LogOp - 1, // Log1pOp - 0, // LtpvOp - 0, // LtvpOp - 0, // LtvvOp - 1, // MulpvOp - 1, // MulvvOp - 0, // NepvOp - 0, // NevvOp - 1, // ParOp - 3, // PowpvOp - 3, // PowvpOp - 3, // PowvvOp - 0, // PriOp - 1, // SignOp - 2, // SinOp - 2, // SinhOp - 1, // SqrtOp - 0, // StppOp - 0, // StpvOp - 0, // StvpOp - 0, // StvvOp - 1, // SubpvOp - 1, // SubvpOp - 1, // SubvvOp - 2, // TanOp - 2, // TanhOp - 0, // UserOp - 0, // UsrapOp - 0, // UsravOp - 0, // UsrrpOp - 1, // UsrrvOp - 1, // ZmulpvOp - 1, // ZmulvpOp - 1, // ZmulvvOp - 0 // NumberOp not used and avoids g++ 4.3.2 warn when pycppad builds - }; - // check ensuring conversion to size_t is as expected - CPPAD_ASSERT_UNKNOWN( size_t(NumberOp) + 1 == - sizeof(NumResTable) / sizeof(NumResTable[0]) - ); - // this test ensures that all indices are within the table - CPPAD_ASSERT_UNKNOWN( size_t(op) < size_t(NumberOp) ); - - return NumResTable[op]; -} - - -/*! -Fetch the name for a specified operation. - -\return -name of the specified operation. - -\param op -Operator for which we are fetching the name -*/ -inline const char* OpName(OpCode op) -{ // agreement with OpCode is checked by bin/check_op_code.sh - static const char *OpNameTable[] = { - "Abs" , - "Acos" , - "Acosh" , - "Addpv" , - "Addvv" , - "Asin" , - "Asinh" , - "Atan" , - "Atanh" , - "Begin" , - "CExp" , - "Cos" , - "Cosh" , - "CSkip" , - "CSum" , - "Dis" , - "Divpv" , - "Divvp" , - "Divvv" , - "End" , - "Eqpv" , - "Eqvv" , - "Erf" , - "Exp" , - "Expm1" , - "Inv" , - "Ldp" , - "Ldv" , - "Lepv" , - "Levp" , - "Levv" , - "Log" , - "Log1p" , - "Ltpv" , - "Ltvp" , - "Ltvv" , - "Mulpv" , - "Mulvv" , - "Nepv" , - "Nevv" , - "Par" , - "Powpv" , - "Powvp" , - "Powvv" , - "Pri" , - "Sign" , - "Sin" , - "Sinh" , - "Sqrt" , - "Stpp" , - "Stpv" , - "Stvp" , - "Stvv" , - "Subpv" , - "Subvp" , - "Subvv" , - "Tan" , - "Tanh" , - "User" , - "Usrap" , - "Usrav" , - "Usrrp" , - "Usrrv" , - "Zmulpv", - "Zmulvp", - "Zmulvv", - "Number" // not used - }; - // check ensuring conversion to size_t is as expected - CPPAD_ASSERT_UNKNOWN( - size_t(NumberOp) + 1 == sizeof(OpNameTable)/sizeof(OpNameTable[0]) - ); - // this test ensures that all indices are within the table - CPPAD_ASSERT_UNKNOWN( size_t(op) < size_t(NumberOp) ); - - return OpNameTable[op]; -} - -/*! -Prints a single field corresponding to an operator. - -A specified leader is printed in front of the value -and then the value is left justified in the following width character. - -\tparam Type -is the type of the value we are printing. - -\param os -is the stream that we are printing to. - -\param leader -are characters printed before the value. - -\param value -is the value being printed. - -\param width -is the number of character to print the value in. -If the value does not fit in the width, the value is replace -by width '*' characters. -*/ -template -void printOpField( - std::ostream &os , - const char * leader , - const Type &value , - size_t width ) -{ - std::ostringstream buffer; - std::string str; - - // first print the leader - os << leader; - - // print the value into an internal buffer - buffer << std::setw(width) << value; - str = buffer.str(); - - // length of the string - size_t len = str.size(); - if( len > width ) - { size_t i; - for(i = 0; i < width-1; i++) - os << str[i]; - os << "*"; - return; - } - - // count number of spaces at begining - size_t nspace = 0; - while(str[nspace] == ' ' && nspace < len) - nspace++; - - // left justify the string - size_t i = nspace; - while( i < len ) - os << str[i++]; - - i = width - len + nspace; - while(i--) - os << " "; -} - -/*! -Prints a single operator and its operands - -\tparam Base -Is the base type for these AD< \a Base > operations. - -\param os -is the output stream that the information is printed on. - -\param play -Is the entire recording for the tape that this operator is in. - -\param i_op -is the index for the operator corresponding to this operation. - -\param i_var -is the index for the variable corresponding to the result of this operation -(if NumRes(op) > 0). - -\param op -The operator code (OpCode) for this operation. - -\param ind -is the vector of argument indices for this operation -(must have NumArg(op) elements). -*/ -template -void printOp( - std::ostream& os , - const local::player* play , - size_t i_op , - size_t i_var , - OpCode op , - const addr_t* ind ) -{ size_t i; - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "cannot print trace of AD operations in parallel mode" - ); - static const char *CompareOpName[] = - { "Lt", "Le", "Eq", "Ge", "Gt", "Ne" }; - - // print operator - printOpField(os, "o=", i_op, 5); - if( NumRes(op) > 0 && op != BeginOp ) - printOpField(os, "v=", i_var, 5); - else printOpField(os, "v=", "", 5); - if( op == CExpOp || op == CSkipOp ) - { printOpField(os, "", OpName(op), 5); - printOpField(os, "", CompareOpName[ ind[0] ], 3); - } - else printOpField(os, "", OpName(op), 8); - - // print other fields - size_t ncol = 5; - switch( op ) - { - case CSkipOp: - /* - ind[0] = the Rel operator: Lt, Le, Eq, Ge, Gt, or Ne - ind[1] & 1 = is left a variable - ind[1] & 2 = is right a variable - ind[2] = index correspoding to left - ind[3] = index correspoding to right - ind[4] = number of operations to skip if CExpOp comparision is true - ind[5] = number of operations to skip if CExpOp comparision is false - ind[6] -> ind[5+ind[4]] = skip operations if true - ind[6+ind[4]] -> ind[5+ind[4]+ind[5]] = skip operations if false - ind[6+ind[4]+ind[5]] = ind[4] + ind[5] - */ - CPPAD_ASSERT_UNKNOWN( ind[6+ind[4]+ind[5]] == ind[4]+ind[5] ); - CPPAD_ASSERT_UNKNOWN(ind[1] != 0); - if( ind[1] & 1 ) - printOpField(os, " vl=", ind[2], ncol); - else printOpField(os, " pl=", play->GetPar(ind[2]), ncol); - if( ind[1] & 2 ) - printOpField(os, " vr=", ind[3], ncol); - else printOpField(os, " pr=", play->GetPar(ind[3]), ncol); - if( size_t(ind[4]) < 3 ) - { for(i = 0; i < size_t(ind[4]); i++) - printOpField(os, " ot=", ind[6+i], ncol); - } - else - { printOpField(os, "\n\tot=", ind[6+0], ncol); - for(i = 1; i < size_t(ind[4]); i++) - printOpField(os, " ot=", ind[6+i], ncol); - } - if( size_t(ind[5]) < 3 ) - { for(i = 0; i < size_t(ind[5]); i++) - printOpField(os, " of=", ind[6+ind[4]+i], ncol); - } - else - { printOpField(os, "\n\tof=", ind[6+ind[4]+0], ncol); - { for(i = 1; i < size_t(ind[5]); i++) - printOpField(os, " of=", ind[6+ind[4]+i], ncol); - } - } - break; - - case CSumOp: - /* - ind[0] = number of addition variables in summation - ind[1] = number of subtraction variables in summation - ind[2] = index of parameter that initializes summation - ind[3], ... , ind[2+ind[0]] = index for positive variables - ind[3+ind[0]], ..., ind[2+ind[0]+ind[1]] = negative variables - ind[3+ind[0]+ind[1]] == ind[0] + ind[1] - */ - CPPAD_ASSERT_UNKNOWN( ind[3+ind[0]+ind[1]] == ind[0]+ind[1] ); - printOpField(os, " pr=", play->GetPar(ind[2]), ncol); - for(i = 0; i < size_t(ind[0]); i++) - printOpField(os, " +v=", ind[3+i], ncol); - for(i = 0; i < size_t(ind[1]); i++) - printOpField(os, " -v=", ind[3+ind[0]+i], ncol); - break; - - case LdpOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - printOpField(os, "off=", ind[0], ncol); - printOpField(os, "idx=", ind[1], ncol); - break; - - case LdvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - printOpField(os, "off=", ind[0], ncol); - printOpField(os, " v=", ind[1], ncol); - break; - - case StppOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - printOpField(os, "off=", ind[0], ncol); - printOpField(os, "idx=", ind[1], ncol); - printOpField(os, " pr=", play->GetPar(ind[2]), ncol); - break; - - case StpvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - printOpField(os, "off=", ind[0], ncol); - printOpField(os, "idx=", ind[1], ncol); - printOpField(os, " vr=", ind[2], ncol); - break; - - case StvpOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - printOpField(os, "off=", ind[0], ncol); - printOpField(os, " vl=", ind[1], ncol); - printOpField(os, " pr=", play->GetPar(ind[2]), ncol); - break; - - case StvvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - printOpField(os, "off=", ind[0], ncol); - printOpField(os, " vl=", ind[1], ncol); - printOpField(os, " vr=", ind[2], ncol); - break; - - case AddvvOp: - case DivvvOp: - case EqvvOp: - case LevvOp: - case LtvvOp: - case NevvOp: - case MulvvOp: - case PowvvOp: - case SubvvOp: - case ZmulvvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - printOpField(os, " vl=", ind[0], ncol); - printOpField(os, " vr=", ind[1], ncol); - break; - - case AddpvOp: - case EqpvOp: - case DivpvOp: - case LepvOp: - case LtpvOp: - case NepvOp: - case SubpvOp: - case MulpvOp: - case PowpvOp: - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - printOpField(os, " pl=", play->GetPar(ind[0]), ncol); - printOpField(os, " vr=", ind[1], ncol); - break; - - case DivvpOp: - case LevpOp: - case LtvpOp: - case PowvpOp: - case SubvpOp: - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - printOpField(os, " vl=", ind[0], ncol); - printOpField(os, " pr=", play->GetPar(ind[1]), ncol); - break; - - case AbsOp: - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case UsravOp: - case TanOp: - case TanhOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - printOpField(os, " v=", ind[0], ncol); - break; - - case ErfOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - // ind[1] points to the parameter 0 - // ind[2] points to the parameter 2 / sqrt(pi) - printOpField(os, " v=", ind[0], ncol); - break; - - case ParOp: - case UsrapOp: - case UsrrpOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - printOpField(os, " p=", play->GetPar(ind[0]), ncol); - break; - - case UserOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 4 ); - { std::string name = atomic_base::class_name(ind[0]); - printOpField(os, " f=", name.c_str(), ncol); - printOpField(os, " i=", ind[1], ncol); - printOpField(os, " n=", ind[2], ncol); - printOpField(os, " m=", ind[3], ncol); - } - break; - - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - if( ind[0] & 1 ) - printOpField(os, " v=", ind[1], ncol); - else printOpField(os, " p=", play->GetPar(ind[1]), ncol); - os << "before=\"" << play->GetTxt(ind[2]) << "\""; - if( ind[0] & 2 ) - printOpField(os, " v=", ind[3], ncol); - else printOpField(os, " p=", play->GetPar(ind[3]), ncol); - os << "after=\"" << play->GetTxt(ind[4]) << "\""; - break; - - case BeginOp: - // argument not used (created by independent) - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - break; - - case EndOp: - case InvOp: - case UsrrvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 ); - break; - - case DisOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - { const char* name = discrete::name(ind[0]); - printOpField(os, " f=", name, ncol); - printOpField(os, " x=", ind[1], ncol); - } - break; - - - case CExpOp: - CPPAD_ASSERT_UNKNOWN(ind[1] != 0); - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 6 ); - if( ind[1] & 1 ) - printOpField(os, " vl=", ind[2], ncol); - else printOpField(os, " pl=", play->GetPar(ind[2]), ncol); - if( ind[1] & 2 ) - printOpField(os, " vr=", ind[3], ncol); - else printOpField(os, " pr=", play->GetPar(ind[3]), ncol); - if( ind[1] & 4 ) - printOpField(os, " vt=", ind[4], ncol); - else printOpField(os, " pt=", play->GetPar(ind[4]), ncol); - if( ind[1] & 8 ) - printOpField(os, " vf=", ind[5], ncol); - else printOpField(os, " pf=", play->GetPar(ind[5]), ncol); - break; - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -} - -/*! -Prints the result values correspnding to an operator. - -\tparam Base -Is the base type for these AD< \a Base > operations. - -\tparam Value -Determines the type of the values that we are printing. - -\param os -is the output stream that the information is printed on. - -\param nfz -is the number of forward sweep calculated values of type Value -that correspond to this operation -(ignored if NumRes(op) == 0). - -\param fz -points to the first forward calculated value -that correspond to this operation -(ignored if NumRes(op) == 0). - -\param nrz -is the number of reverse sweep calculated values of type Value -that correspond to this operation -(ignored if NumRes(op) == 0). - -\param rz -points to the first reverse calculated value -that correspond to this operation -(ignored if NumRes(op) == 0). -*/ -template -void printOpResult( - std::ostream &os , - size_t nfz , - const Value *fz , - size_t nrz , - const Value *rz ) -{ - size_t k; - for(k = 0; k < nfz; k++) - os << "| fz[" << k << "]=" << fz[k]; - for(k = 0; k < nrz; k++) - os << "| rz[" << k << "]=" << rz[k]; -} - -/*! -If NDEBUG is not defined, assert that arguments come before result. - -\param op -Operator for which we are checking order. -All the operators are checked except for those of the form UserOp or Usr..Op. - -\param result -is the variable index for the result. - -\param arg -is a vector of lenght NumArg(op) pointing to the arguments -for this operation. -*/ -inline void assert_arg_before_result( - OpCode op, const addr_t* arg, size_t result -) -{ - switch( op ) - { - - // These cases are not included below - case UserOp: - case UsrapOp: - case UsravOp: - case UsrrpOp: - case UsrrvOp: - break; - // ------------------------------------------------------------------ - - // 0 arguments - case CSkipOp: - case CSumOp: - case EndOp: - case InvOp: - break; - // ------------------------------------------------------------------ - - // 1 argument, but is not used - case BeginOp: - break; - - // 1 argument , 1 result - case AbsOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case ParOp: - case SignOp: - case SqrtOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < result ); - break; - - // 1 argument, 2 results - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case SinOp: - case SinhOp: - case TanOp: - case TanhOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) + 1 < result ); - break; - - // 1 argument, 5 results - case ErfOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) + 4 < result ); - break; - // ------------------------------------------------------------------ - // 2 arguments, no results - case LepvOp: - case LtpvOp: - case EqpvOp: - case NepvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= result ); - break; - // - case LevpOp: - case LtvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= result ); - break; - // - case LevvOp: - case LtvvOp: - case EqvvOp: - case NevvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= result ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= result ); - break; - - // 2 arguments (both variables), 1 results - case AddvvOp: - case DivvvOp: - case MulvvOp: - case SubvvOp: - case ZmulvvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < result ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < result ); - break; - - // 2 arguments (first variables), 1 results - case DivvpOp: - case SubvpOp: - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < result ); - break; - - // 2 arguments (second variables), 1 results - case AddpvOp: - case DisOp: - case DivpvOp: - case MulpvOp: - case SubpvOp: - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < result ); - break; - - // 2 arguments (both variables), 3 results - case PowvvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) + 2 < result ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) + 2 < result ); - break; - - // 2 arguments (first variable), 3 results - case PowvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) + 2 < result ); - break; - - // 2 arguments (second variable), 3 results - case PowpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) + 2 < result ); - break; - // ------------------------------------------------------------------ - - // 3 arguments, none variables - case LdpOp: - case StppOp: - break; - - // 3 arguments, second variable, 1 result - case LdvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < result ); - break; - - // 3 arguments, third variable, no result - case StpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) <= result ); - break; - - // 3 arguments, second variable, no result - case StvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= result ); - break; - - // 3 arguments, second and third variable, no result - case StvvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= result ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) <= result ); - break; - // ------------------------------------------------------------------ - - // 5 arguments, no result - case PriOp: - if( arg[0] & 1 ) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) <= result ); - } - if( arg[0] & 2 ) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= result ); - } - break; - // ------------------------------------------------------------------ - - // 6 arguments, 1 result - case CExpOp: - if( arg[1] & 1 ) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < result ); - } - if( arg[1] & 2 ) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < result ); - } - if( arg[1] & 4 ) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < result ); - } - if( arg[1] & 8 ) - { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < result ); - } - break; - // ------------------------------------------------------------------ - - default: - CPPAD_ASSERT_UNKNOWN(false); - break; - - } - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/optimize/cexp_info.hpp b/external/cppad/include/cppad/local/optimize/cexp_info.hpp deleted file mode 100644 index 7960114e5..000000000 --- a/external/cppad/include/cppad/local/optimize/cexp_info.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_CEXP_INFO_HPP -# define CPPAD_LOCAL_OPTIMIZE_CEXP_INFO_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include // defines CompareOp -# include - -/*! -\file cexp_info.hpp -Information about one conditional expression. -*/ - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Information about one conditional expression. -*/ -struct struct_cexp_info { - /// The operator index for this conditional expression operation - size_t i_op; - - /// (flag & 1) is true if and only if left is a variable - /// (flag & 2) is true if and only if right is a variable - size_t flag; - - /// variable or parameter index for left comparison operand - size_t left; - - /// variable or parameter index for right comparison operand - size_t right; - - /// maximum variable index between left and right (ignoring parameters). - size_t max_left_right; - - /// set of operator that are not used when comparison result is true - /// Note that UsrapOp, UsravOp, UsrrpOp, and UsrrvOp, are not in this - /// vector and should be skipped when the corresponding UserOp are skipped. - CppAD::vector skip_op_true; - - /// set of variables that are not used when comparison result is false - /// Note that UsrapOp, UsravOp, UsrrpOp, and UsrrvOp, are not in this - /// vector and should be skipped when the corresponding UserOp are skipped. - CppAD::vector skip_op_false; - - /// comparision operator for this conditional expression - CompareOp cop; -}; - -// Information about the conditional skip in the new operation sequence -struct struct_cskip_new { - /// new variable or parameter index for left comparison operand - size_t left; - /// new variable or parameter index for right comparison operand - size_t right; - /// maximum variable index between left and right (ignoring parameters). - size_t max_left_right; - /// index where this conditional skips arguments start - size_t i_arg; -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/csum_stacks.hpp b/external/cppad/include/cppad/local/optimize/csum_stacks.hpp deleted file mode 100644 index b7d8a6801..000000000 --- a/external/cppad/include/cppad/local/optimize/csum_stacks.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_CSUM_STACKS_HPP -# define CPPAD_LOCAL_OPTIMIZE_CSUM_STACKS_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -/*! -\file csum_stacks.hpp -Information about one cumulative summation operation. -*/ - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Information about one cumulative summation operation. -*/ -struct struct_csum_stacks { - /// old operator indices for this cummulative summation - std::stack op_stack; - /// old variable indices to be added - std::stack add_stack; - /// old variavle indices to be subtracted - std::stack sub_stack; -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/csum_variable.hpp b/external/cppad/include/cppad/local/optimize/csum_variable.hpp deleted file mode 100644 index fbe21929e..000000000 --- a/external/cppad/include/cppad/local/optimize/csum_variable.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_CSUM_VARIABLE_HPP -# define CPPAD_LOCAL_OPTIMIZE_CSUM_VARIABLE_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include // defines addr_t - -/*! -\file csum_variable.hpp -Information about one old variable that is part of a new CSumOp operation. -*/ - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Information about one old variable that is part of a new CSumOp operation. -*/ -struct struct_csum_variable { - /// Pointer to first argument (child) for this old operator. - /// Set by the reverse sweep at beginning of optimization. - const addr_t* arg; - - /// Was this old variable added to the summation - /// (if not it was subtracted) - bool add; - - /// Operator for which this old variable is the result, NumRes(op) > 0. - OpCode op; -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/get_op_info.hpp b/external/cppad/include/cppad/local/optimize/get_op_info.hpp deleted file mode 100644 index af9ea6094..000000000 --- a/external/cppad/include/cppad/local/optimize/get_op_info.hpp +++ /dev/null @@ -1,1128 +0,0 @@ -# ifndef CPPAD_LOCAL_OPTIMIZE_GET_OP_INFO_HPP -# define CPPAD_LOCAL_OPTIMIZE_GET_OP_INFO_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file op_info.hpp -Create operator information tables -*/ - -# include -# include -# include -# include - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { - -/// Is this an addition or subtraction operator -inline bool add_or_subtract(OpCode op) -{ bool result; - switch(op) - { - case AddpvOp: - case AddvvOp: - case SubpvOp: - case SubvpOp: - case SubvvOp: - result = true; - break; - - default: - result = false; - break; - } - return result; -} - - -/*! -Increarse argument usage and propagate cexp_set from result to argument. - -\param sum_result -is result an addition or subtraction operator (passed for speed so -do not need to call add_or_subtract for result). - -\param i_result -is the operator index for the result operator. - -\param i_arg -is the operator index for the argument to the result operator. - -\param op_info -structure that holds the information for each of the operators. -The output value of op_info[i_arg].usage is increased; to be specific, -If sum_result is true and the input value of op_info[i_arg].usage -is no_usage, its output value is csum_usage. -Otherwise, the output value of op_info[i_arg].usage is yes_usage. - -\param cexp_set -This is a vector of sets with one set for each operator. We denote -the i-th set by set[i]. - -\li -In the special case where cexp_set.n_set() is zero, -cexp_set is not changed. - -\li -If cexp_set.n_set() != 0 and op_info[i_arg].usage == no_usage, -the input value of set[i_arg] must be empty. -In this case the output value if set[i_arg] is equal to set[i_result] -(which may also be empty). - -\li -If cexp_set.n_set() != 0 and op_info[i_arg].usage != no_usage, -the output value of set[i_arg] is the intersection of -its input value and set[i_result]. -*/ -inline void usage_cexp_result2arg( - bool sum_result , - size_t i_result , - size_t i_arg , - vector& op_info , - sparse_list& cexp_set ) -{ - // cexp_set - if( cexp_set.n_set() > 0 ) - { if( op_info[i_arg].usage == no_usage ) - { // set[i_arg] = set[i_result] - cexp_set.assignment(i_arg, i_result, cexp_set); - } - else - { // set[i_arg] = set[i_arg] intersect set[i_result] - cexp_set.binary_intersection(i_arg, i_arg, i_result, cexp_set); - } - } - // usage - bool csum = sum_result && op_info[i_arg].usage == no_usage; - if( csum ) - csum = add_or_subtract( op_info[i_arg].op ); - if( csum ) - op_info[i_arg].usage = csum_usage; - else - op_info[i_arg].usage = yes_usage; - // - return; -} - -/*! -Get variable to operator map and operator basic operator information - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param conditional_skip -If conditional_skip this is true, the conditional expression information -cexp_info will be calculated. -This may be time intensive and may not have much benefit in the optimized -recording. - -\param compare_op -if this is true, arguments are considered used if they appear in compare -operators. This is a side effect because compare operators have boolean -results (and the result is not in the tape; i.e. NumRes(op) is zero -for these operators. (This is an example of a side effect.) - -\param print_for_op -if this is true, arguments are considered used if they appear in -print forward operators; i.e., PriOp. -This is also a side effect; i.e. NumRes(PriOp) is zero. - -\param play -This is the operation sequence. -It is essentially const, except for play back state which -changes while it plays back the operation seqeunce. - -\param dep_taddr -is a vector of variable indices for the dependent variables. - -\param var2op -The input size of this vector must be zero. -Upone return it has size equal to the number of variables -in the operation sequence; i.e., num_var = play->nun_var_rec(). -It maps each variable index to the operator that created the variable. -This is only true for the primary variables. -If the index i_var corresponds to an auxillary variable, var2op[i_var] -is equalt to num_op (which is not a valid operator index). - -\param cexp_info -The input size of this vector must be zero. -If conditional_skip is false, cexp_info is not changed. -Otherwise, -upon return cexp_info has size equal to the number of conditional expressions -in the operation sequence; i.e., the number of CExpOp operators. -The value cexp_info[j] is the information corresponding to the j-th -conditional expression in the operation sequence. -This vector is in the same order as the operation sequence; i.e. -if j1 > j2, cexp_info[j1].i_op > cexp_info[j2].i_op. -Note that skip_op_true and skip_op_false could be part of this structure, -but then we would allocate and deallocate two vectors for each conditonal -expression in the operation sequence. - -\param skip_op_true -This vector of sets is empty on input. -Upon return, the j-th set is the operators that are not used when -comparison result for cexp_info[j] is true. -Note that UsrapOp, UsravOp, UsrrpOp, and UsrrvOp, are not in this -set and should be skipped when the corresponding UserOp are skipped. - -\param skip_op_false -This vector of sets is empty on input. -Upon return, the j-th set is the operators that are not used when -comparison result for cexp_info[j] is false. -Note that UsrapOp, UsravOp, UsrrpOp, and UsrrvOp, are not in this -set and should be skipped when the corresponding UserOp are skipped. - -\param vecad_used -The input size of this vector must be zero. -Upon retun it has size equal to the number of VecAD vectors -in the operations sequences; i.e., play->num_vecad_vec_rec(). -The VecAD vectors are indexed in the order that thier indices apprear -in the one large play->GetVecInd that holds all the VecAD vectors. - -\param op_info -The input size of this vector must be zero. -Upon return it has size equal to the number of operators -in the operation sequence; i.e., num_op = play->nun_var_rec(). -The value op_info[i] -have been set to the values corresponding to the i-th operator -in the operation sequence. -*/ - -template -void get_op_info( - bool conditional_skip , - bool compare_op , - bool print_for_op , - player* play , - const vector& dep_taddr , - vector& var2op , - vector& cexp_info , - sparse_list& skip_op_true , - sparse_list& skip_op_false , - vector& vecad_used , - vector& op_info ) -{ - CPPAD_ASSERT_UNKNOWN( var2op.size() == 0 ); - CPPAD_ASSERT_UNKNOWN( cexp_info.size() == 0 ); - CPPAD_ASSERT_UNKNOWN( vecad_used.size() == 0 ); - CPPAD_ASSERT_UNKNOWN( op_info.size() == 0 ); - - // number of operators in the tape - const size_t num_op = play->num_op_rec(); - op_info.resize( num_op ); - // - // number of variables in the tape - const size_t num_var = play->num_var_rec(); - var2op.resize( num_var ); - // - // initialize mapping from variable index to operator index - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= num_op - ); - for(size_t i = 0; i < num_var; i++) - var2op[i] = addr_t( num_op ); // invalid (used for auxillary variables) - // - // information set by forward_user - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - enum_user_state user_state; - // - // information set by forward_next - OpCode op; // operator - const addr_t* arg; // arguments - size_t i_op; // operator index - size_t i_var; // variable index of first result - // - // ---------------------------------------------------------------------- - // Forward pass to compute op, arg, i_var for each operator and var2op - // ---------------------------------------------------------------------- - play->forward_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == BeginOp ); - CPPAD_ASSERT_UNKNOWN( NumRes(BeginOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( i_op == 0 ); - CPPAD_ASSERT_UNKNOWN( i_var == 0 ); - op_info[i_op].op = op; - op_info[i_op].arg = arg; - op_info[i_op].i_var = addr_t( i_var ); - // - // This variaible index, 0, is automatically created, but it should - // not used because variable index 0 represents a paraemeter during - // the recording process. So we set - var2op[i_var] = addr_t( num_op ); - // - size_t num_cexp_op = 0; - user_state = start_user; - while(op != EndOp) - { // next operator - play->forward_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( - size_t( std::numeric_limits::max() ) > i_var - ); - CPPAD_ASSERT_UNKNOWN( - size_t( std::numeric_limits::max() ) > i_op - ); - // - // information for this operator - op_info[i_op].op = op; - op_info[i_op].arg = arg; - op_info[i_op].i_var = addr_t( i_var ); - // - // mapping from variable index to operator index - if( NumRes(op) > 0 ) - var2op[i_var] = addr_t( i_op ); - // - switch( op ) - { case CSumOp: - // must correct arg before next operator - play->forward_csum(op, arg, i_op, i_var); - break; - - case CSkipOp: - // must correct arg before next operator - play->forward_csum(op, arg, i_op, i_var); - break; - - case UserOp: - case UsrapOp: - case UsravOp: - case UsrrpOp: - case UsrrvOp: - play->forward_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - break; - - case CExpOp: - // Set the operator index for this conditional expression and - // count the number of conditional expressions. - ++num_cexp_op; - break; - - default: - break; - } - } - // vector that maps conditional expression index to operator index - vector cexp2op( num_cexp_op ); - // ---------------------------------------------------------------------- - // Reverse pass to compute usage and cexp_set for each operator - // ---------------------------------------------------------------------- - // work space used by user defined atomic functions - typedef std::set size_set; - vector user_x; // parameters in x as integers - vector user_ix; // variables indices for argument vector - vector user_r_set; // set sparsity pattern for result - vector user_s_set; // set sparisty pattern for argument - vector user_r_bool; // bool sparsity pattern for result - vector user_s_bool; // bool sparisty pattern for argument - vectorBool user_r_pack; // pack sparsity pattern for result - vectorBool user_s_pack; // pack sparisty pattern for argument - // - atomic_base* user_atom = CPPAD_NULL; // current user atomic function - bool user_pack = false; // sparsity pattern type is pack - bool user_bool = false; // sparsity pattern type is bool - bool user_set = false; // sparsity pattern type is set - // ----------------------------------------------------------------------- - // vecad information - size_t num_vecad = play->num_vecad_vec_rec(); - size_t num_vecad_ind = play->num_vec_ind_rec(); - // - vecad_used.resize(num_vecad); - for(size_t i = 0; i < num_vecad; i++) - vecad_used[i] = false; - // - vector arg2vecad(num_vecad_ind); - for(size_t i = 0; i < num_vecad_ind; i++) - arg2vecad[i] = num_vecad; // invalid value - size_t arg_0 = 1; // value of arg[0] for theh first vecad - for(size_t i = 0; i < num_vecad; i++) - { - // mapping from arg[0] value to index for this vecad object. - arg2vecad[arg_0] = i; - // - // length of this vecad object - size_t length = play->GetVecInd(arg_0 - 1); - // - // set to proper index in GetVecInd for next VecAD arg[0] value - arg_0 += length + 1; - } - CPPAD_ASSERT_UNKNOWN( arg_0 == num_vecad_ind + 1 ); - // ----------------------------------------------------------------------- - // parameter information (used by atomic function calls) - size_t num_par = play->num_par_rec(); - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - // ----------------------------------------------------------------------- - // Set of conditional expressions comparisons that usage of each - /// operator depends on. The operator can be skipped if any of the - // comparisons results in the set holds. A set for operator i_op is - // not defined and left empty when op_info[i_op].usage = no_usage. - /// It is also left empty for the result of any VecAD operations. - sparse_list cexp_set; - // - // number of sets - size_t num_set = 0; - if( conditional_skip && num_cexp_op > 0) - num_set = num_op; - // - // conditional expression index = element / 2 - // conditional expression compare = bool ( element % 2) - size_t end_set = 2 * num_cexp_op; - // - cexp_set.resize(num_set, end_set); - // ----------------------------------------------------------------------- - // - // initialize operator usage - for(size_t i = 0; i < num_op; i++) - op_info[i].usage = no_usage; - for(size_t i = 0; i < dep_taddr.size(); i++) - { i_op = var2op[ dep_taddr[i] ]; - op_info[i_op].usage = yes_usage; // dependent variables - } - // - // Initialize reverse pass - size_t last_user_i_op = 0; - size_t cexp_index = num_cexp_op; - user_state = end_user; - i_op = num_op; - while(i_op != 0 ) - { --i_op; - // - // this operator information - op = op_info[i_op].op; - arg = op_info[i_op].arg; - i_var = op_info[i_op].i_var; - // - // Is the result of this operation used. - // (This only makes sense when NumRes(op) > 0.) - enum_usage use_result = op_info[i_op].usage; - // - bool sum_op = false; - switch( op ) - { - // ============================================================= - // normal operators - // ============================================================= - - // Only one variable with index arg[0] - case SubvpOp: - sum_op = true; - // - case AbsOp: - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case DivvpOp: - case ErfOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case PowvpOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case TanOp: - case TanhOp: - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 ); - if( use_result != no_usage ) - { size_t j_op = var2op[ arg[0] ]; - usage_cexp_result2arg(sum_op, i_op, j_op, op_info, cexp_set); - } - break; // -------------------------------------------- - - // Only one variable with index arg[1] - case AddpvOp: - case SubpvOp: - sum_op = true; - // - case DisOp: - case DivpvOp: - case MulpvOp: - case PowpvOp: - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 ); - if( use_result != no_usage ) - { size_t j_op = var2op[ arg[1] ]; - usage_cexp_result2arg(sum_op, i_op, j_op, op_info, cexp_set); - } - break; // -------------------------------------------- - - // arg[0] and arg[1] are the only variables - case AddvvOp: - case SubvvOp: - sum_op = true; - // - case DivvvOp: - case MulvvOp: - case PowvvOp: - case ZmulvvOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 ); - if( use_result != no_usage ) - { for(size_t i = 0; i < 2; i++) - { size_t j_op = var2op[ arg[i] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - } - break; // -------------------------------------------- - - // Conditional expression operators - // arg[2], arg[3], arg[4], arg[5] are parameters or variables - case CExpOp: - --cexp_index; - cexp2op[ cexp_index ] = i_op; - CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 ); - if( use_result != no_usage ) - { CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 ); - // propgate from result to left argument - if( arg[1] & 1 ) - { size_t j_op = var2op[ arg[2] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - // propgate from result to right argument - if( arg[1] & 2 ) - { size_t j_op = var2op[ arg[3] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - // are if_true and if_false cases the same variable - bool same_variable = bool(arg[1] & 4) && bool(arg[1] & 8); - same_variable &= arg[4] == arg[5]; - // - // if_true - if( arg[1] & 4 ) - { size_t j_op = var2op[ arg[4] ]; - bool can_skip = conditional_skip & (! same_variable); - can_skip &= op_info[j_op].usage == no_usage; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - if( can_skip ) - { // j_op corresponds to the value used when the - // comparison result is true. It can be skipped when - // the comparison is false (0). - size_t element = 2 * cexp_index + 0; - cexp_set.add_element(j_op, element); - // - op_info[j_op].usage = yes_usage; - } - } - // - // if_false - if( arg[1] & 8 ) - { size_t j_op = var2op[ arg[5] ]; - bool can_skip = conditional_skip & (! same_variable); - can_skip &= op_info[j_op].usage == no_usage; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - if( can_skip ) - { // j_op corresponds to the value used when the - // comparison result is false. It can be skipped when - // the comparison is true (0). - size_t element = 2 * cexp_index + 1; - cexp_set.add_element(j_op, element); - // - op_info[j_op].usage = yes_usage; - } - } - } - break; // -------------------------------------------- - - // Operations that are never used - // (new CSkip options are generated if conditional_skip is true) - case CSkipOp: - case ParOp: - break; - - // Operators that are always used - case InvOp: - case BeginOp: - case EndOp: - op_info[i_op].usage = yes_usage; - break; // ----------------------------------------------- - - // The print forward operator - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - if( print_for_op ) - { op_info[i_op].usage = yes_usage; - if( arg[0] & 1 ) - { // arg[1] is a variable - size_t j_op = var2op[ arg[1] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - if( arg[0] & 2 ) - { // arg[3] is a variable - size_t j_op = var2op[ arg[3] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - } - break; // ----------------------------------------------------- - - // ============================================================= - // Comparison operators - // ============================================================= - - // Compare operators where arg[1] is only variable - case LepvOp: - case LtpvOp: - case EqpvOp: - case NepvOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - if( compare_op ) - { op_info[i_op].usage = yes_usage; - // - size_t j_op = var2op[ arg[1] ]; - usage_cexp_result2arg(sum_op, i_op, j_op, op_info, cexp_set); - } - break; // ---------------------------------------------- - - // Compare operators where arg[0] is only variable - case LevpOp: - case LtvpOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - if( compare_op ) - { op_info[i_op].usage = yes_usage; - // - size_t j_op = var2op[ arg[0] ]; - usage_cexp_result2arg(sum_op, i_op, j_op, op_info, cexp_set); - } - break; // ---------------------------------------------- - - // Compare operators where arg[0] and arg[1] are variables - case LevvOp: - case LtvvOp: - case EqvvOp: - case NevvOp: - if( compare_op ) - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - if( compare_op ) - { op_info[i_op].usage = yes_usage; - // - for(size_t i = 0; i < 2; i++) - { size_t j_op = var2op[ arg[i] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - } - break; // ---------------------------------------------- - - // ============================================================= - // VecAD operators - // ============================================================= - - // load operator using a parameter index - case LdpOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 ); - if( use_result != no_usage ) - { size_t i_vec = arg2vecad[ arg[0] ]; - vecad_used[i_vec] = true; - } - break; // -------------------------------------------- - - // load operator using a variable index - case LdvOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 ); - if( use_result != no_usage ) - { size_t i_vec = arg2vecad[ arg[0] ]; - vecad_used[i_vec] = true; - // - size_t j_op = var2op[ arg[1] ]; - op_info[j_op].usage = yes_usage; - } - break; // -------------------------------------------- - - // Store a variable using a parameter index - case StpvOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - if( vecad_used[ arg2vecad[ arg[0] ] ] ) - { op_info[i_op].usage = yes_usage; - // - size_t j_op = var2op[ arg[2] ]; - op_info[j_op].usage = yes_usage; - } - break; // -------------------------------------------- - - // Store a variable using a variable index - case StvvOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - if( vecad_used[ arg2vecad[ arg[0] ] ] ) - { op_info[i_op].usage = yes_usage; - // - size_t j_op = var2op[ arg[1] ]; - op_info[j_op].usage = yes_usage; - size_t k_op = var2op[ arg[2] ]; - op_info[k_op].usage = yes_usage; - } - break; // ----------------------------------------------------- - - // ============================================================= - // cumulative summation operator - // ============================================================ - case CSumOp: - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 ); - { - size_t num_add = size_t( arg[0] ); - size_t num_sub = size_t( arg[1] ); - for(size_t i = 0; i < num_add + num_sub; i++) - { size_t j_op = var2op[ arg[3 + i] ]; - usage_cexp_result2arg( - sum_op, i_op, j_op, op_info, cexp_set - ); - } - } - // ============================================================= - // user defined atomic operators - // ============================================================ - - case UserOp: - // start or end atomic operation sequence - if( user_state == end_user ) - { // revese_user using op_info instead of play - size_t user_index = arg[0]; - user_old = arg[1]; - user_n = arg[2]; - user_m = arg[3]; - user_j = user_n; - user_i = user_m; - user_state = ret_user; - user_atom = atomic_base::class_object(user_index); - // ------------------------------------------------------- - last_user_i_op = i_op; - CPPAD_ASSERT_UNKNOWN( i_op > user_n + user_m + 1 ); - CPPAD_ASSERT_UNKNOWN(op_info[last_user_i_op].usage==no_usage); -# ifndef NDEBUG - if( cexp_set.n_set() > 0 ) - { sparse_list_const_iterator itr(cexp_set, last_user_i_op); - CPPAD_ASSERT_UNKNOWN( *itr == cexp_set.end() ); - } -# endif - // - user_x.resize( user_n ); - user_ix.resize( user_n ); - // - user_pack = user_atom->sparsity() == - atomic_base::pack_sparsity_enum; - user_bool = user_atom->sparsity() == - atomic_base::bool_sparsity_enum; - user_set = user_atom->sparsity() == - atomic_base::set_sparsity_enum; - CPPAD_ASSERT_UNKNOWN( user_pack || user_bool || user_set ); - // - // Note that q is one for this call the sparsity calculation - if( user_pack ) - { user_r_pack.resize( user_m ); - user_s_pack.resize( user_n ); - for(size_t i = 0; i < user_m; i++) - user_r_pack[ i ] = false; - } - if( user_bool ) - { user_r_bool.resize( user_m ); - user_s_bool.resize( user_n ); - for(size_t i = 0; i < user_m; i++) - user_r_bool[ i ] = false; - } - if( user_set ) - { user_s_set.resize(user_n); - user_r_set.resize(user_m); - for(size_t i = 0; i < user_m; i++) - user_r_set[i].clear(); - } - } - else - { // reverse_user using op_info instead of play - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - CPPAD_ASSERT_UNKNOWN( user_n == size_t(arg[2]) ); - CPPAD_ASSERT_UNKNOWN( user_m == size_t(arg[3]) ); - CPPAD_ASSERT_UNKNOWN( user_j == 0 ); - CPPAD_ASSERT_UNKNOWN( user_i == 0 ); - user_state = end_user; - // ------------------------------------------------------- - CPPAD_ASSERT_UNKNOWN( - i_op + user_n + user_m + 1 == last_user_i_op - ); - // call users function for this operation - user_atom->set_old(user_old); - bool user_ok = false; - size_t user_q = 1; // as if sum of dependent variables - if( user_pack ) - { user_ok = user_atom->rev_sparse_jac( - user_q, user_r_pack, user_s_pack, user_x - ); - if( ! user_ok ) user_ok = user_atom->rev_sparse_jac( - user_q, user_r_pack, user_s_pack - ); - } - if( user_bool ) - { user_ok = user_atom->rev_sparse_jac( - user_q, user_r_bool, user_s_bool, user_x - ); - if( ! user_ok ) user_ok = user_atom->rev_sparse_jac( - user_q, user_r_bool, user_s_bool - ); - } - if( user_set ) - { user_ok = user_atom->rev_sparse_jac( - user_q, user_r_set, user_s_set, user_x - ); - if( ! user_ok ) user_ok = user_atom->rev_sparse_jac( - user_q, user_r_set, user_s_set - ); - } - if( ! user_ok ) - { std::string s = - "Optimizing an ADFun object" - " that contains the atomic function\n\t"; - s += user_atom->afun_name(); - s += "\nCurrent atomic_sparsity is set to "; - // - if( user_set ) - s += "set_sparsity_enum.\n"; - if( user_bool ) - s += "bool_sparsity_enum.\n"; - if( user_pack ) - s += "pack_sparsity_enum.\n"; - // - s += "This version of rev_sparse_jac returned false"; - CPPAD_ASSERT_KNOWN(false, s.c_str() ); - } - - if( op_info[last_user_i_op].usage != no_usage ) - for(size_t j = 0; j < user_n; j++) - if( user_ix[j] > 0 ) - { // This user argument is a variable - bool use_arg_j = false; - if( user_set ) - { if( ! user_s_set[j].empty() ) - use_arg_j = true; - } - if( user_bool ) - { if( user_s_bool[j] ) - use_arg_j = true; - } - if( user_pack ) - { if( user_s_pack[j] ) - use_arg_j = true; - } - if( use_arg_j ) - { size_t j_op = var2op[ user_ix[j] ]; - usage_cexp_result2arg( - sum_op, last_user_i_op, j_op, op_info, cexp_set - ); - } - } - // copy set infomation from last to first - if( cexp_set.n_set() > 0 ) - cexp_set.assignment(i_op, last_user_i_op, cexp_set); - // copy user information from last to all the user operators - // for this call - for(size_t j = 0; j < user_n + user_m + 1; ++j) - op_info[i_op + j].usage = op_info[last_user_i_op].usage; - } - break; // ------------------------------------------------------- - - case UsrapOp: - // parameter argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - // - // reverse_user using op_info instead of play - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - CPPAD_ASSERT_UNKNOWN( 0 < user_j && user_j < user_n ); - --user_j; - if( user_j == 0 ) - user_state = start_user; - // ------------------------------------------------------------- - user_ix[user_j] = 0; - // - // parameter arguments - user_x[user_j] = parameter[arg[0]]; - // - break; - - case UsravOp: - // variable argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( arg[0] <= op_info[i_op].i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - // - // reverse_user using op_info instead of play - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - CPPAD_ASSERT_UNKNOWN( 0 < user_j && user_j <= user_n ); - --user_j; - if( user_j == 0 ) - user_state = start_user; - // ------------------------------------------------------------- - user_ix[user_j] = arg[0]; - // - // variable arguments as parameters - user_x[user_j] = CppAD::numeric_limits::quiet_NaN(); - // - break; - - case UsrrvOp: - // variable result in an atomic operation sequence - // - // reverse_user using op_info instead of play - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - CPPAD_ASSERT_UNKNOWN( 0 < user_i && user_i <= user_m ); - --user_i; - if( user_i == 0 ) - user_state = arg_user; - // ------------------------------------------------------------- - if( use_result ) - { if( user_set ) - user_r_set[user_i].insert(0); - if( user_bool ) - user_r_bool[user_i] = true; - if( user_pack ) - user_r_pack[user_i] = true; - // - usage_cexp_result2arg( - sum_op, i_op, last_user_i_op, op_info, cexp_set - ); - } - break; // -------------------------------------------------------- - - case UsrrpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - // - // reverse_user using op_info instead of play - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - CPPAD_ASSERT_UNKNOWN( 0 < user_i && user_i < user_m ); - --user_i; - if( user_i == 0 ) - user_state = arg_user; - break; - // ============================================================ - - // all cases should be handled above - default: - CPPAD_ASSERT_UNKNOWN(0); - } - } - // ---------------------------------------------------------------------- - // compute previous in op_info - // ---------------------------------------------------------------------- - sparse_list hash_table_op; - hash_table_op.resize(CPPAD_HASH_TABLE_SIZE, num_op); - // - user_state = start_user; - for(i_op = 0; i_op < num_op; ++i_op) - { op_info[i_op].previous = 0; - - if( op_info[i_op].usage == yes_usage ) switch( op_info[i_op].op ) - { - case NumberOp: - CPPAD_ASSERT_UNKNOWN(false); - break; - - case BeginOp: - case CExpOp: - case CSkipOp: - case CSumOp: - case EndOp: - case InvOp: - case LdpOp: - case LdvOp: - case ParOp: - case PriOp: - case StppOp: - case StpvOp: - case StvpOp: - case StvvOp: - case UserOp: - case UsrapOp: - case UsravOp: - case UsrrpOp: - case UsrrvOp: - // these operators never match pevious operators - break; - - case AbsOp: - case AcosOp: - case AcoshOp: - case AddpvOp: - case AddvvOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case DisOp: - case DivpvOp: - case DivvpOp: - case DivvvOp: - case EqpvOp: - case EqvvOp: - case ErfOp: - case ExpOp: - case Expm1Op: - case LepvOp: - case LevpOp: - case LevvOp: - case LogOp: - case Log1pOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case MulpvOp: - case MulvvOp: - case NepvOp: - case NevvOp: - case PowpvOp: - case PowvpOp: - case PowvvOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case SubpvOp: - case SubvpOp: - case SubvvOp: - case TanOp: - case TanhOp: - case ZmulpvOp: - case ZmulvpOp: - case ZmulvvOp: - // check for a previous match - match_op( var2op, op_info, i_op, hash_table_op ); - if( op_info[i_op].previous != 0 ) - { // like a unary operator that assigns i_op equal to previous. - size_t previous = op_info[i_op].previous; - bool sum_op = false; - CPPAD_ASSERT_UNKNOWN( previous < i_op ); - usage_cexp_result2arg( - sum_op, i_op, previous, op_info, cexp_set - ); - } - break; - } - } - // ---------------------------------------------------------------------- - // compute cexp_info - // ---------------------------------------------------------------------- - if( cexp_set.n_set() == 0 ) - return; - // - // initialize information for each conditional expression - cexp_info.resize(num_cexp_op); - skip_op_true.resize(num_cexp_op, num_op); - skip_op_false.resize(num_cexp_op, num_op); - // - for(size_t i = 0; i < num_cexp_op; i++) - { CPPAD_ASSERT_UNKNOWN( - op_info[i].previous == 0 || op_info[i].usage == yes_usage - ); - i_op = cexp2op[i]; - arg = op_info[i_op].arg; - CPPAD_ASSERT_UNKNOWN( op_info[i_op].op == CExpOp ); - // - struct_cexp_info info; - info.i_op = i_op; - info.cop = CompareOp( arg[0] ); - info.flag = arg[1]; - info.left = arg[2]; - info.right = arg[3]; - // - // max_left_right - size_t index = 0; - if( arg[1] & 1 ) - index = std::max(index, info.left); - if( arg[1] & 2 ) - index = std::max(index, info.right); - CPPAD_ASSERT_UNKNOWN( index > 0 ); - info.max_left_right = index; - // - cexp_info[i] = info; - }; - // Determine which operators can be conditionally skipped - i_op = 0; - while(i_op < num_op) - { size_t j_op = i_op; - bool keep = op_info[i_op].usage != no_usage; - keep &= op_info[i_op].usage != csum_usage; - keep &= op_info[i_op].previous == 0; - if( keep ) - { sparse_list_const_iterator itr(cexp_set, i_op); - if( *itr != cexp_set.end() ) - { if( op_info[i_op].op == UserOp ) - { // i_op is the first operations in this user atomic call. - // Find the last operation in this call. - ++j_op; - while( op_info[j_op].op != UserOp ) - { switch( op_info[j_op].op ) - { case UsrapOp: - case UsravOp: - case UsrrpOp: - case UsrrvOp: - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - ++j_op; - } - } - } - while( *itr != cexp_set.end() ) - { size_t element = *itr; - size_t index = element / 2; - bool compare = bool( element % 2 ); - if( compare == false ) - { // cexp_info[index].skip_op_false.push_back(i_op); - skip_op_false.add_element(index, i_op); - if( j_op != i_op ) - { // cexp_info[index].skip_op_false.push_back(j_op); - skip_op_false.add_element(index, j_op); - } - } - else - { // cexp_info[index].skip_op_true.push_back(i_op); - skip_op_true.add_element(index, i_op); - if( j_op != i_op ) - { // cexp_info[index].skip_op_true.push_back(j_op); - skip_op_true.add_element(index, j_op); - } - } - ++itr; - } - } - CPPAD_ASSERT_UNKNOWN( i_op <= j_op ); - i_op += (1 + j_op) - i_op; - } - return; -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/hash_code.hpp b/external/cppad/include/cppad/local/optimize/hash_code.hpp deleted file mode 100644 index 8d9ef79c2..000000000 --- a/external/cppad/include/cppad/local/optimize/hash_code.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_HASH_CODE_HPP -# define CPPAD_LOCAL_OPTIMIZE_HASH_CODE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file local/optimize/hash_code.hpp -CppAD hashing utility. -*/ - - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Specialized hash code for a CppAD operator and its arguments -(used during optimization). - -\param op -is the operator that we are computing a hash code for. - -\param num_arg -number of elements of arg to include in the hash code -(num_arg <= 2). - -\param arg -is a vector of length num_arg -containing the corresponding argument indices for this operator. - -\return -is a hash code that is between zero and CPPAD_HASH_TABLE_SIZE - 1. -*/ - -inline size_t optimize_hash_code( - OpCode op , - size_t num_arg , - const addr_t* arg ) -{ - // - CPPAD_ASSERT_UNKNOWN(num_arg <= 2 ); - size_t sum = size_t(arg[0]) + size_t(op); - if( 1 < num_arg ) - sum += size_t(arg[1]); - // - return sum % CPPAD_HASH_TABLE_SIZE; -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/match_op.hpp b/external/cppad/include/cppad/local/optimize/match_op.hpp deleted file mode 100644 index 8865c7551..000000000 --- a/external/cppad/include/cppad/local/optimize/match_op.hpp +++ /dev/null @@ -1,269 +0,0 @@ -# ifndef CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP -# define CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -/*! -\file match_op.hpp -Check if current operator matches a previous operator. -*/ -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Search for a previous operator that matches the current one. - -If an argument for the current operator is a variable, -and the argument has previous match, -the previous match for the argument is used when checking for a match -for the current operator. - -\param var2op -mapping from variable index to operator index. - -\param op_info -Mapping from operator index to operator information. -The input value of op_info[current].previous is assumed to be zero. -If a match if found, -the output value of op_info[current].previous is set to the -matching operator index, otherwise it is left as is. -Note that op_info[current].previous < current. - -\param current -is the index of the current operator which must be an unary -or binary operator. Note that NumArg(ErfOp) == 3 but it is effectivey -a unary operator and is allowed otherwise NumArg( op_info[current].op) < 3. -It is assumed that hash_table_op is initialized as a vector of emtpy -sets. After this initialization, the value of current inceases with -each call to match_op. - -\li -This must be a unary or binary -operator; hence, NumArg( op_info[current].op ) is one or two. -There is one exception, NumRes( ErfOp ) == 3, but arg[0] -is the only true arguments (the others are always the same). - -\li -This must not be a VecAD load or store operation; i.e., -LtpvOp, LtvpOp, LtvvOp, StppOp, StpvOp, StvpOp, StvvOp. -It also must not be an independent variable operator InvOp. - -\param hash_table_op -is a vector of sets, -hash_table_op.n_set() == CPPAD_HASH_TABLE_SIZE and -hash_table_op.end() == op_info.size(). -If i_op is an element of set[j], -then the operation op_info[i_op] has hash code j, -and op_info[i_op] does not match any other element of set[j]. -An entry will be added each time match_op is called -and a match for the current operator is not found. -*/ - -inline void match_op( - const vector& var2op , - vector& op_info , - size_t current , - sparse_list& hash_table_op ) -{ size_t num_op = op_info.size(); - // - CPPAD_ASSERT_UNKNOWN( op_info[current].previous == 0 ); - CPPAD_ASSERT_UNKNOWN( - hash_table_op.n_set() == CPPAD_HASH_TABLE_SIZE - ); - CPPAD_ASSERT_UNKNOWN( hash_table_op.end() == num_op ); - CPPAD_ASSERT_UNKNOWN( current < num_op ); - // - // current operator - OpCode op = op_info[current].op; - const addr_t* arg = op_info[current].arg; - // - // which arguments are variable - size_t num_arg = NumArg(op); - // - bool variable[2]; - variable[0] = false; - variable[1] = false; - switch(op) - { // - case ErfOp: - num_arg = 1; // other arugments are always the same - // - case AbsOp: - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case TanOp: - case TanhOp: - CPPAD_ASSERT_UNKNOWN( num_arg == 1 ); - variable[0] = true; - break; - - - case AddpvOp: - case DisOp: - case DivpvOp: - case EqpvOp: - case LepvOp: - case LtpvOp: - case MulpvOp: - case NepvOp: - case PowpvOp: - case SubpvOp: - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( num_arg == 2 ); - variable[1] = true; - break; - - case DivvpOp: - case LevpOp: - case LtvpOp: - case PowvpOp: - case SubvpOp: - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( num_arg == 2 ); - variable[0] = true; - break; - - case AddvvOp: - case DivvvOp: - case EqvvOp: - case LevvOp: - case LtvvOp: - case MulvvOp: - case NevvOp: - case PowvvOp: - case SubvvOp: - case ZmulvvOp: - CPPAD_ASSERT_UNKNOWN( num_arg == 2 ); - variable[0] = true; - variable[1] = true; - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - // - // If i-th argument to current operator has a previous operator, - // this is the i-th argument for previous operator. - // Otherwise, it is the i-th argument for the current operator - // (if a previous variable exists) - addr_t arg_match[2]; - for(size_t j = 0; j < num_arg; ++j) - { arg_match[j] = arg[j]; - if( variable[j] ) - { size_t previous = op_info[ var2op[arg[j]] ].previous; - if( previous != 0 ) - { CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 ); - // - arg_match[j] = op_info[previous].i_var; - } - } - } - size_t code = optimize_hash_code(op, num_arg, arg_match); - // - // iterator for the set with this hash code - sparse_list_const_iterator itr(hash_table_op, code); - // - // check for a match - size_t count = 0; - while( *itr != num_op ) - { ++count; - // - // candidate previous for current operator - size_t candidate = *itr; - CPPAD_ASSERT_UNKNOWN( candidate < current ); - CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 ); - // - // check for a match - bool match = op == op_info[candidate].op; - if( match ) - { for(size_t j = 0; j < num_arg; j++) - { if( variable[j] ) - { size_t previous = - op_info[ var2op[op_info[candidate].arg[j]] ].previous; - if( previous != 0 ) - { CPPAD_ASSERT_UNKNOWN(op_info[previous].previous == 0); - // - match &= - arg_match[j] == addr_t( op_info[previous].i_var ); - } - else - match &= arg_match[j] == op_info[candidate].arg[j]; - } - } - } - if( match ) - { op_info[current].previous = static_cast( candidate ); - return; - } - ++itr; - } - - // special case where operator is commutative - if( (op == AddvvOp) | (op == MulvvOp ) ) - { CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 ); - std::swap( arg_match[0], arg_match[1] ); - // - code = optimize_hash_code(op, num_arg, arg_match); - sparse_list_const_iterator itr_swap(hash_table_op, code); - while( *itr_swap != num_op ) - { - size_t candidate = *itr_swap; - CPPAD_ASSERT_UNKNOWN( candidate < current ); - CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 ); - // - bool match = op == op_info[candidate].op; - if( match ) - { for(size_t j = 0; j < num_arg; j++) - { CPPAD_ASSERT_UNKNOWN( variable[j] ) - size_t previous = - op_info[ var2op[op_info[candidate].arg[j]] ].previous; - if( previous != 0 ) - { CPPAD_ASSERT_UNKNOWN(op_info[previous].previous == 0); - // - match &= - arg_match[j] == addr_t( op_info[previous].i_var ); - } - else - match &= arg_match[j] == op_info[candidate].arg[j]; - } - } - if( match ) - { op_info[current].previous = static_cast( candidate ); - return; - } - ++itr_swap; - } - } - CPPAD_ASSERT_UNKNOWN( count < 11 ); - if( count == 10 ) - { // restart the list - hash_table_op.clear(code); - } - // no match was found, add this operator the the set for this hash code - hash_table_op.add_element(code, current); -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/old2new.hpp b/external/cppad/include/cppad/local/optimize/old2new.hpp deleted file mode 100644 index 850f84869..000000000 --- a/external/cppad/include/cppad/local/optimize/old2new.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_OLD2NEW_HPP -# define CPPAD_LOCAL_OPTIMIZE_OLD2NEW_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file old2new.hpp -Information that maps old an old operator to a new opeator and new variable. -*/ - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Information that maps old an old operator to a new opeator and new variable. -*/ -struct struct_old2new { - /// New operator index for this old operator. - addr_t new_op; - - /// New varaible index for this old operator. - addr_t new_var; -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/op_info.hpp b/external/cppad/include/cppad/local/optimize/op_info.hpp deleted file mode 100644 index 45820e9a3..000000000 --- a/external/cppad/include/cppad/local/optimize/op_info.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_OP_INFO_HPP -# define CPPAD_LOCAL_OPTIMIZE_OP_INFO_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { - -/// information for one operator -struct struct_op_info { - /// arguments - const addr_t* arg; - - /// Primary (not auxillary) variable index for this operator. If the - // operator has not results, this is num_var (an invalid variable index). - addr_t i_var; - - /*! - previous operator that can be used in place of this operator. - \li - If previous == 0, no such operator was found. - \li - If previous != 0, - op_info[pevious].previous == 0 and - op_info[previous].usage == yes_usage. - */ - addr_t previous; - - /// op code - OpCode op; - - /// How is this operator used to compute the dependent variables. - /// If usage = csum_usage or usage = no_usage, previous = 0. - enum_usage usage; - -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/optimize/optimize_run.hpp b/external/cppad/include/cppad/local/optimize/optimize_run.hpp deleted file mode 100644 index abffe74d1..000000000 --- a/external/cppad/include/cppad/local/optimize/optimize_run.hpp +++ /dev/null @@ -1,922 +0,0 @@ - -# ifndef CPPAD_LOCAL_OPTIMIZE_OPTIMIZE_RUN_HPP -# define CPPAD_LOCAL_OPTIMIZE_OPTIMIZE_RUN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -/*! -\file optimize_run.hpp -Convert a player object to an optimized recorder object -*/ -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Convert a player object to an optimized recorder object - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - - -\param options -\li -If the sub-string "no_conditional_skip" appears, -conditional skip operations will not be generated. -This may make the optimize routine use significantly less memory -and take significantly less time. -\li -If the sub-string "no_compare_op" appears, -then comparison operators will be removed from the optimized tape. -These operators are necessary for the compare_change function to be -be meaningful in the resulting recording. -On the other hand, they are not necessary and take extra time -when compare_change is not used. -\li -If the sub-string "no_print_for" appears, -then print forward (PriOp) operators will be removed from the optimized tape. -These operators are useful for reporting problems evaluating derivatives -at independent variable values different from those used to record a function. - -\param n -is the number of independent variables on the tape. - -\param dep_taddr -On input this vector contains the indices for each of the dependent -variable values in the operation sequence corresponding to \a play. -Upon return it contains the indices for the same variables but in -the operation sequence corresponding to \a rec. - -\param play -This is the operation sequence that we are optimizing. -It is essentially const, except for play back state which -changes while it plays back the operation seqeunce. - -\param rec -The input contents of this recording does not matter. -Upon return, it contains an optimized verison of the -operation sequence corresponding to \a play. -*/ - -template -void optimize_run( - const std::string& options , - size_t n , - CppAD::vector& dep_taddr , - player* play , - recorder* rec ) -{ - bool conditional_skip = true; - bool compare_op = true; - bool print_for_op = true; - size_t index = 0; - while( index < options.size() ) - { while( index < options.size() && options[index] == ' ' ) - ++index; - std::string option; - while( index < options.size() && options[index] != ' ' ) - option += options[index++]; - if( option != "" ) - { if( option == "no_conditional_skip" ) - conditional_skip = false; - else if( option == "no_compare_op" ) - compare_op = false; - else if( option == "no_print_for_op" ) - print_for_op = false; - else - { option += " is not a valid optimize option"; - CPPAD_ASSERT_KNOWN( false , option.c_str() ); - } - } - } - // number of operators in the player - const size_t num_op = play->num_op_rec(); - CPPAD_ASSERT_UNKNOWN( - num_op < size_t( std::numeric_limits::max() ) - ); - - // number of variables in the player - const size_t num_var = play->num_var_rec(); - - // number of VecAD indices - size_t num_vecad_ind = play->num_vec_ind_rec(); - - // number of VecAD vectors - size_t num_vecad_vec = play->num_vecad_vec_rec(); - - // operator information - vector var2op; - vector cexp_info; - sparse_list skip_op_true; - sparse_list skip_op_false; - vector vecad_used; - vector op_info; - get_op_info( - conditional_skip, - compare_op, - print_for_op, - play, - dep_taddr, - var2op, - cexp_info, - skip_op_true, - skip_op_false, - vecad_used, - op_info - ); - - // nan with type Base - Base base_nan = Base( std::numeric_limits::quiet_NaN() ); - - // ------------------------------------------------------------- - // information for current operator - size_t i_op; // index - OpCode op; // operator - const addr_t* arg; // arguments - size_t i_var; // variable index of primary (last) result - - enum_user_state user_state; - // ------------------------------------------------------------- - // conditional expression information - // - // Size of the conditional expression information structure. - // This is equal to the number of conditional expressions when - // conditional_skip is true, otherwise it is zero. - size_t num_cexp = cexp_info.size(); - CPPAD_ASSERT_UNKNOWN( conditional_skip || num_cexp == 0 ); - // - // sort the conditional expression information by max_left_right - // this is the conditional skip order - vector cskip_order(num_cexp); - if( num_cexp > 0 ) - { CppAD::vector keys(num_cexp); - for(size_t i = 0; i < num_cexp; i++) - keys[i] = cexp_info[i].max_left_right; - CppAD::index_sort(keys, cskip_order); - } - // initial index in conditional skip order - size_t cskip_order_next = 0; - // - // initialize index in conditional expression order - size_t cexp_next = 0; - - // mapping from conditional expression index to conditional skip - // information on new tape - vector cskip_new(num_cexp); - // - // flag used to indicate that there is no conditional skip - // for this conditional expression - for(size_t i = 0; i < num_cexp; i++) - cskip_new[i].i_arg = 0; - // ------------------------------------------------------------- - - // Erase all information in the old recording - rec->free(); - - // initialize mapping from old VecAD index to new VecAD index - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= num_vecad_ind - ); - CppAD::vector new_vecad_ind(num_vecad_ind); - for(size_t i = 0; i < num_vecad_ind; i++) - new_vecad_ind[i] = addr_t( num_vecad_ind ); // invalid index - { - size_t j = 0; // index into the old set of indices - for(size_t i = 0; i < num_vecad_vec; i++) - { // length of this VecAD - size_t length = play->GetVecInd(j); - if( vecad_used[i] ) - { // Put this VecAD vector in new recording - CPPAD_ASSERT_UNKNOWN(length < num_vecad_ind); - new_vecad_ind[j] = rec->PutVecInd(length); - for(size_t k = 1; k <= length; k++) new_vecad_ind[j+k] = - rec->PutVecInd( - rec->PutPar( - play->GetPar( - play->GetVecInd(j+k) - ) ) ); - } - // start of next VecAD - j += length + 1; - } - CPPAD_ASSERT_UNKNOWN( j == num_vecad_ind ); - } - // - // Mapping from old operator index to new operator information - // (zero is invalid except for old2new[0].new_op and old2new[0].i_var) - vector old2new(num_op); - for(size_t i = 0; i < num_op; i++) - { old2new[i].new_op = 0; - old2new[i].new_var = 0; - } - - - // temporary buffer for new argument values - addr_t new_arg[6]; - - // temporary work space used by record_csum - // (decalared here to avoid realloaction of memory) - struct_csum_stacks csum_work; - - // tempory used to hold a size_pair - struct_size_pair size_pair; - - user_state = start_user; - for(i_op = 0; i_op < num_op; ++i_op) - { addr_t mask; // temporary used in some switch cases - // - // this operator information - op = op_info[i_op].op; - arg = op_info[i_op].arg; - i_var = op_info[i_op].i_var; - // - // determine if we should insert a conditional skip here - bool skip = conditional_skip; - skip &= cskip_order_next < num_cexp; - skip &= op != BeginOp; - skip &= op != InvOp; - skip &= user_state == start_user; - if( skip ) - { size_t j = cskip_order[cskip_order_next]; - if( NumRes(op) > 0 ) - skip &= cexp_info[j].max_left_right < i_var; - else - skip &= cexp_info[j].max_left_right <= i_var; - } - if( skip ) - { size_t j = cskip_order[cskip_order_next]; - cskip_order_next++; - size_t n_true = skip_op_true.number_elements(j); - size_t n_false = skip_op_false.number_elements(j); - skip &= n_true > 0 || n_false > 0; - if( skip ) - { CPPAD_ASSERT_UNKNOWN( NumRes(CSkipOp) == 0 ); - size_t n_arg = 7 + n_true + n_false; - // reserve space for the arguments to this operator but - // delay setting them until we have all the new addresses - cskip_new[j].i_arg = rec->ReserveArg(n_arg); - // i_arg == 0 is used to check if conditional expression - // has been skipped. - CPPAD_ASSERT_UNKNOWN( cskip_new[j].i_arg > 0 ); - // There is no corresponding old operator in this case - rec->PutOp(CSkipOp); - } - } - if( op == UserOp ) - { if( user_state == start_user ) - user_state = end_user; - else - { CPPAD_ASSERT_UNKNOWN( user_state == end_user ); - user_state = start_user; - } - } - size_t previous; - // - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= rec->num_op_rec() - ); - // - if( op_info[i_op].usage != yes_usage ) - { if( op == CExpOp ) - ++cexp_next; - } - else switch( op ) - { - case BeginOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - // Put BeginOp at beginning of recording - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(BeginOp); - rec->PutArg(arg[0]); - break; - - // -------------------------------------------------------------- - // Unary operators, argument a variable, one result - case AbsOp: - case AcosOp: - case AcoshOp: - case AsinOp: - case AsinhOp: - case AtanOp: - case AtanhOp: - case CosOp: - case CoshOp: - case ErfOp: - case ExpOp: - case Expm1Op: - case LogOp: - case Log1pOp: - case SignOp: - case SinOp: - case SinhOp: - case SqrtOp: - case TanOp: - case TanhOp: - previous = op_info[i_op].previous; - if( previous > 0 ) - { size_t j_op = previous; - old2new[i_op].new_var = old2new[j_op].new_var; - } - else - { // - new_arg[0] = old2new[ var2op[arg[0]] ].new_var; - rec->PutArg( new_arg[0] ); - // - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(op); - CPPAD_ASSERT_UNKNOWN( - new_arg[0] < old2new[var2op[i_var]].new_var - ); - if( op == ErfOp ) - { CPPAD_ASSERT_NARG_NRES(op, 3, 5); - // Error function is a special case - // second argument is always the parameter 0 - // third argument is always the parameter 2 / sqrt(pi) - CPPAD_ASSERT_UNKNOWN( NumArg(ErfOp) == 3 ); - rec->PutArg( rec->PutPar( Base(0.0) ) ); - rec->PutArg( rec->PutPar( - Base( 1.0 / std::sqrt( std::atan(1.0) ) ) - ) ); - } - else - { // some of these operators have an auxillary result; - // e.g. sine and cosine are computed together. - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) ==1 || NumRes(op) == 2 ); - } - } - break; - // --------------------------------------------------- - // Binary operators, left variable, right parameter, one result - case SubvpOp: - // check if this is the top of a csum connection - if( op_info[i_op].usage == csum_usage ) - break; - if( op_info[ var2op[arg[0]] ].usage == csum_usage ) - { - // convert to a sequence of summation operators - size_pair = record_csum( - var2op , - op_info , - old2new , - i_var , - play->num_par_rec() , - play->GetPar() , - rec , - csum_work - ); - old2new[i_op].new_op = addr_t( size_pair.i_op ); - old2new[i_op].new_var = addr_t( size_pair.i_var ); - // abort rest of this case - break; - } - case DivvpOp: - case PowvpOp: - case ZmulvpOp: - previous = op_info[i_op].previous; - if( previous > 0 ) - { size_t j_op = previous; - old2new[i_op].new_var = old2new[j_op].new_var; - } - else - { // - size_pair = record_vp( - var2op , - op_info , - old2new , - i_var , - play->num_par_rec() , - play->GetPar() , - rec , - op , - arg - ); - old2new[i_op].new_op = addr_t( size_pair.i_op ); - old2new[i_op].new_var = addr_t( size_pair.i_var ); - } - break; - // --------------------------------------------------- - // Binary operators, left index, right variable, one result - case DisOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - previous = op_info[i_op].previous; - if( previous > 0 ) - { size_t j_op = previous; - old2new[i_op].new_var = old2new[j_op].new_var; - } - else - { // - new_arg[0] = arg[0]; - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - rec->PutArg( new_arg[0], new_arg[1] ); - // - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(op); - CPPAD_ASSERT_UNKNOWN( - new_arg[1] < old2new[var2op[i_var]].new_var - ); - } - break; - - // --------------------------------------------------- - // Binary operators, left parameter, right variable, one result - case SubpvOp: - case AddpvOp: - // check if this is the top of a csum connection - if( op_info[i_op].usage == csum_usage ) - break; - if( op_info[ var2op[arg[1]] ].usage == csum_usage ) - { - // convert to a sequence of summation operators - size_pair = record_csum( - var2op , - op_info , - old2new , - i_var , - play->num_par_rec() , - play->GetPar() , - rec , - csum_work - ); - old2new[i_op].new_op = addr_t( size_pair.i_op ); - old2new[i_op].new_var = addr_t( size_pair.i_var ); - // abort rest of this case - break; - } - case DivpvOp: - case MulpvOp: - case PowpvOp: - case ZmulpvOp: - previous = op_info[i_op].previous; - if( previous > 0 ) - { size_t j_op = previous; - old2new[i_op].new_var = old2new[j_op].new_var; - } - else - { // - size_pair = record_pv( - var2op , - op_info , - old2new , - i_var , - play->num_par_rec() , - play->GetPar() , - rec , - op , - arg - ); - old2new[i_op].new_op = addr_t( size_pair.i_op ); - old2new[i_op].new_var = addr_t( size_pair.i_var ); - } - break; - // --------------------------------------------------- - // Binary operator, left and right variables, one result - case AddvvOp: - case SubvvOp: - // check if this is the top of a csum connection - if( op_info[i_op].usage == csum_usage ) - break; - if( - op_info[ var2op[arg[0]] ].usage == csum_usage || - op_info[ var2op[arg[1]] ].usage == csum_usage - ) - { - // convert to a sequence of summation operators - size_pair = record_csum( - var2op , - op_info , - old2new , - i_var , - play->num_par_rec() , - play->GetPar() , - rec , - csum_work - ); - old2new[i_op].new_op = addr_t( size_pair.i_op ); - old2new[i_op].new_var = addr_t( size_pair.i_var ); - // abort rest of this case - break; - } - case DivvvOp: - case MulvvOp: - case PowvvOp: - case ZmulvvOp: - previous = op_info[i_op].previous; - if( previous > 0 ) - { size_t j_op = previous; - old2new[i_op].new_var = old2new[j_op].new_var; - } - else - { // - size_pair = record_vv( - var2op , - op_info , - old2new , - i_var , - play->num_par_rec() , - play->GetPar() , - rec , - op , - arg - ); - old2new[i_op].new_op = addr_t( size_pair.i_op ); - old2new[i_op].new_var = addr_t( size_pair.i_var ); - } - break; - // --------------------------------------------------- - // Conditional expression operators - case CExpOp: - CPPAD_ASSERT_NARG_NRES(op, 6, 1); - new_arg[0] = arg[0]; - new_arg[1] = arg[1]; - mask = 1; - for(size_t i = 2; i < 6; i++) - { if( arg[1] & mask ) - { new_arg[i] = old2new[ var2op[arg[i]] ].new_var; - CPPAD_ASSERT_UNKNOWN( - size_t(new_arg[i]) < num_var - ); - } - else new_arg[i] = rec->PutPar( - play->GetPar( arg[i] ) - ); - mask = mask << 1; - } - rec->PutArg( - new_arg[0] , - new_arg[1] , - new_arg[2] , - new_arg[3] , - new_arg[4] , - new_arg[5] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(op); - // - // The new addresses for left and right are used during - // fill in the arguments for the CSkip operations. This does not - // affect max_left_right which is used during this sweep. - if( conditional_skip ) - { CPPAD_ASSERT_UNKNOWN( cexp_next < num_cexp ); - CPPAD_ASSERT_UNKNOWN( cexp_info[cexp_next].i_op == i_op ); - cskip_new[ cexp_next ].left = new_arg[2]; - cskip_new[ cexp_next ].right = new_arg[3]; - ++cexp_next; - } - break; - // --------------------------------------------------- - // Operations with no arguments and no results - case EndOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 0); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - // --------------------------------------------------- - // Operations with two arguments and no results - case LepvOp: - case LtpvOp: - case EqpvOp: - case NepvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - new_arg[0] = rec->PutPar( play->GetPar(arg[0]) ); - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - rec->PutArg(new_arg[0], new_arg[1]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - // - case LevpOp: - case LtvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - new_arg[0] = old2new[ var2op[arg[0]] ].new_var; - new_arg[1] = rec->PutPar( play->GetPar(arg[1]) ); - rec->PutArg(new_arg[0], new_arg[1]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - // - case LevvOp: - case LtvvOp: - case EqvvOp: - case NevvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - new_arg[0] = old2new[ var2op[arg[0]] ].new_var; - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - rec->PutArg(new_arg[0], new_arg[1]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - - // --------------------------------------------------- - // Operations with no arguments and one result - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(op); - break; - - // --------------------------------------------------- - // Unary operators, argument a parameter, one result - case ParOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - new_arg[0] = rec->PutPar( play->GetPar(arg[0] ) ); - rec->PutArg( new_arg[0] ); - // - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(op); - break; - - // --------------------------------------------------- - // print forward operator - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - // arg[0] - new_arg[0] = arg[0]; - // - // arg[1] - if( arg[0] & 1 ) - { new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[1]) < num_var ); - } - else - { new_arg[1] = rec->PutPar( play->GetPar( arg[1] ) ); - } - // - // arg[3] - if( arg[0] & 2 ) - { new_arg[3] = old2new[ var2op[arg[3]] ].new_var; - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[3]) < num_var ); - } - else - { new_arg[3] = rec->PutPar( play->GetPar( arg[3] ) ); - } - new_arg[2] = rec->PutTxt( play->GetTxt(arg[2]) ); - new_arg[4] = rec->PutTxt( play->GetTxt(arg[4]) ); - // - rec->PutArg( - new_arg[0] , - new_arg[1] , - new_arg[2] , - new_arg[3] , - new_arg[4] - ); - // new operator - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - // no new variable - rec->PutOp(op); - break; - - // --------------------------------------------------- - // VecAD operators - - // Load using a parameter index - case LdpOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 1); - new_arg[0] = new_vecad_ind[ arg[0] ]; - new_arg[1] = arg[1]; - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= rec->num_load_op_rec() - ); - new_arg[2] = addr_t( rec->num_load_op_rec() ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[0]) < num_vecad_ind ); - rec->PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutLoadOp(op); - break; - - // Load using a variable index - case LdvOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 1); - new_arg[0] = new_vecad_ind[ arg[0] ]; - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= rec->num_load_op_rec() - ); - new_arg[2] = addr_t( rec->num_load_op_rec() ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[0]) < num_vecad_ind ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[1]) < num_var ); - rec->PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutLoadOp(op); - break; - - // Store a parameter using a parameter index - case StppOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - new_arg[0] = new_vecad_ind[ arg[0] ]; - new_arg[1] = rec->PutPar( play->GetPar(arg[1]) ); - new_arg[2] = rec->PutPar( play->GetPar(arg[2]) ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[0]) < num_vecad_ind ); - rec->PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - - // Store a parameter using a variable index - case StvpOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - new_arg[0] = new_vecad_ind[ arg[0] ]; - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - new_arg[2] = rec->PutPar( play->GetPar(arg[2]) ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[0]) < num_vecad_ind ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[1]) < num_var ); - rec->PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - - // Store a variable using a parameter index - case StpvOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - new_arg[0] = new_vecad_ind[ arg[0] ]; - new_arg[1] = rec->PutPar( play->GetPar(arg[1]) ); - new_arg[2] = old2new[ var2op[arg[2]] ].new_var; - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[0]) < num_vecad_ind ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[2]) < num_var ); - rec->PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - - // Store a variable using a variable index - case StvvOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - new_arg[0] = new_vecad_ind[ arg[0] ]; - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - new_arg[2] = old2new[ var2op[arg[2]] ].new_var; - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[0]) < num_vecad_ind ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[1]) < num_var ); - CPPAD_ASSERT_UNKNOWN( size_t(new_arg[2]) < num_var ); - rec->PutArg( - new_arg[0], - new_arg[1], - new_arg[2] - ); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(op); - break; - - // ----------------------------------------------------------- - // user atomic function call operators - - case UserOp: - CPPAD_ASSERT_NARG_NRES(op, 4, 0); - // user_old, user_n, user_m - rec->PutArg(arg[0], arg[1], arg[2], arg[3]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(UserOp); - break; - - case UsrapOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - new_arg[0] = rec->PutPar( play->GetPar(arg[0]) ); - rec->PutArg(new_arg[0]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(UsrapOp); - break; - - case UsravOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - new_arg[0] = old2new[ var2op[arg[0]] ].new_var; - if( size_t(new_arg[0]) < num_var ) - { rec->PutArg(new_arg[0]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(UsravOp); - } - else - { // This argument does not affect the result and - // has been optimized out so use nan in its place. - new_arg[0] = rec->PutPar( base_nan ); - rec->PutArg(new_arg[0]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(UsrapOp); - } - break; - - case UsrrpOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 0); - new_arg[0] = rec->PutPar( play->GetPar(arg[0]) ); - rec->PutArg(new_arg[0]); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - rec->PutOp(UsrrpOp); - break; - - case UsrrvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - old2new[i_op].new_op = addr_t( rec->num_op_rec() ); - old2new[i_op].new_var = rec->PutOp(UsrrvOp); - break; - // --------------------------------------------------- - - // all cases should be handled above - default: - CPPAD_ASSERT_UNKNOWN(false); - - } - } - // modify the dependent variable vector to new indices - for(size_t i = 0; i < dep_taddr.size(); i++ ) - { dep_taddr[i] = old2new[ var2op[dep_taddr[i]] ].new_var; - CPPAD_ASSERT_UNKNOWN( size_t(dep_taddr[i]) < num_var ); - } - -# ifndef NDEBUG - for(i_op = 0; i_op < num_op; i_op++) - if( NumRes( op_info[i_op].op ) > 0 ) - CPPAD_ASSERT_UNKNOWN( - size_t(old2new[i_op].new_op) < rec->num_op_rec() - ); -# endif - // make sure that all the conditional expressions have been - // checked to see if they are still present - CPPAD_ASSERT_UNKNOWN( cskip_order_next == num_cexp ); - // fill in the arguments for the CSkip operations - for(size_t i = 0; i < num_cexp; i++) - { // if cskip_new[i].i_arg == 0, this conditional expression was skipped - if( cskip_new[i].i_arg > 0 ) - { struct_cexp_info info = cexp_info[i]; - size_t n_true = skip_op_true.number_elements(i); - size_t n_false = skip_op_false.number_elements(i); - size_t i_arg = cskip_new[i].i_arg; - size_t left = cskip_new[i].left; - size_t right = cskip_new[i].right; - rec->ReplaceArg(i_arg++, info.cop ); - rec->ReplaceArg(i_arg++, info.flag ); - rec->ReplaceArg(i_arg++, left ); - rec->ReplaceArg(i_arg++, right ); - rec->ReplaceArg(i_arg++, n_true ); - rec->ReplaceArg(i_arg++, n_false ); - sparse_list::const_iterator itr_true(skip_op_true, i); - while( *itr_true != skip_op_true.end() ) - { i_op = *itr_true; - // op_info[i_op].usage == yes_usage - CPPAD_ASSERT_UNKNOWN( old2new[i_op].new_op != 0 ); - rec->ReplaceArg(i_arg++, old2new[i_op].new_op ); - // - ++itr_true; - } - sparse_list::const_iterator itr_false(skip_op_false, i); - while( *itr_false != skip_op_false.end() ) - { i_op = *itr_false; - // op_info[i_op].usage == yes_usage - CPPAD_ASSERT_UNKNOWN( old2new[i_op].new_op != 0 ); - rec->ReplaceArg(i_arg++, old2new[i_op].new_op ); - // - ++itr_false; - } - rec->ReplaceArg(i_arg++, n_true + n_false); -# ifndef NDEBUG - size_t n_arg = 7 + n_true + n_false; - CPPAD_ASSERT_UNKNOWN( cskip_new[i].i_arg + n_arg == i_arg ); -# endif - } - } -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/record_csum.hpp b/external/cppad/include/cppad/local/optimize/record_csum.hpp deleted file mode 100644 index b76b3353f..000000000 --- a/external/cppad/include/cppad/local/optimize/record_csum.hpp +++ /dev/null @@ -1,259 +0,0 @@ -# ifndef CPPAD_LOCAL_OPTIMIZE_RECORD_CSUM_HPP -# define CPPAD_LOCAL_OPTIMIZE_RECORD_CSUM_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file record_csum.hpp -Recording a cummulative cummulative summation. -*/ -# include - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Recording a cummulative cummulative summation. - -\param var2op -mapping from old variable index to old operator index. - -\param op_info -mapping from old index to operator index to operator information - -\param old2new -mapping from old operator index to information about the new recording. - -\param current -is the index in the old operation sequence for -the variable corresponding to the result for the current operator. -We use the notation i_op = var2op[current]. -It follows that NumRes( op_info[i_op].op ) > 0. -If 0 < j_op < i_op, either op_info[j_op].usage == csum_usage, -op_info[j_op].usage = no_usage, or old2new[j_op].new_var != 0. - -\param npar -is the number of parameters corresponding to the old operation sequence. - -\param par -is a vector of length npar containing the parameters -the old operation sequence; i.e., -given a parameter index i < npar, the corresponding parameter value is par[i]. - -\param rec -is the object that will record the new operations. - -\return -is the operator and variable indices in the new operation sequence. - -\param work -Is temporary work space. On input and output, -work.op_stack, work.add_stack, and work.sub_stack, are all empty. -These stacks are passed in so that they are created once -and then be reused with calls to record_csum. - -\par Assumptions -op_info[i_o].op -must be one of AddpvOp, AddvvOp, SubpvOp, SubvpOp, SubvvOp. -op_info[i_op].usage != no_usage and ! op_info[i_op].usage == csum_usage. -Furthermore op_info[j_op].usage == csum_usage is true from some -j_op that corresponds to a variable that is an argument to -op_info[i_op]. -*/ - -template -struct_size_pair record_csum( - const vector& var2op , - const vector& op_info , - const CppAD::vector& old2new , - size_t current , - size_t npar , - const Base* par , - recorder* rec , - // local information passed so stacks need not be allocated for every call - struct_csum_stacks& work ) -{ - // check assumption about work space - CPPAD_ASSERT_UNKNOWN( work.op_stack.empty() ); - CPPAD_ASSERT_UNKNOWN( work.add_stack.empty() ); - CPPAD_ASSERT_UNKNOWN( work.sub_stack.empty() ); - // - size_t i_op = var2op[current]; - CPPAD_ASSERT_UNKNOWN( ! ( op_info[i_op].usage == csum_usage ) ); - // - size_t i; - OpCode op; - const addr_t* arg; - bool add; - struct struct_csum_variable var; - // - // information corresponding to the root node in the cummulative summation - var.op = op_info[i_op].op; // this operator - var.arg = op_info[i_op].arg; // arguments for this operator - var.add = true; // was parrent operator positive or negative - // - // initialize stack as containing this one operator - work.op_stack.push( var ); - // - // initialize sum of parameter values as zero - Base sum_par(0); - // -# ifndef NDEBUG - bool ok = false; - struct_op_info info = op_info[i_op]; - if( var.op == SubvpOp ) - ok = op_info[ var2op[info.arg[0]] ].usage == csum_usage; - if( var.op == AddpvOp || var.op == SubpvOp ) - ok = op_info[ var2op[info.arg[1]] ].usage == csum_usage; - if( var.op == AddvvOp || var.op == SubvvOp ) - { ok = op_info[ var2op[info.arg[0]] ].usage == csum_usage; - ok |= op_info[ var2op[info.arg[1]] ].usage == csum_usage; - } - CPPAD_ASSERT_UNKNOWN( ok ); -# endif - // - // while there are operators left on the stack - while( ! work.op_stack.empty() ) - { // get this summation operator - var = work.op_stack.top(); - work.op_stack.pop(); - op = var.op; - arg = var.arg; - add = var.add; - // - // process first argument to this operator - switch(op) - { // cases where first argument is a parameter - case AddpvOp: - case SubpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < npar ); - // first argument has same sign as parent node - if( add ) - sum_par += par[arg[0]]; - else sum_par -= par[arg[0]]; - break; - - // cases where first argument is a variable - case AddvvOp: - case SubvpOp: - case SubvvOp: - // - // check if the first argument has csum usage - if( op_info[var2op[arg[0]]].usage == csum_usage ) - { CPPAD_ASSERT_UNKNOWN( - size_t( old2new[ var2op[arg[0]] ].new_var) == 0 - ); - // push the operator corresponding to the first argument - var.op = op_info[ var2op[arg[0]] ].op; - var.arg = op_info[ var2op[arg[0]] ].arg; - // first argument has same sign as parent node - var.add = add; - work.op_stack.push( var ); - } - else - { // there are no nodes below this one - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < current ); - if( add ) - work.add_stack.push(arg[0]); - else work.sub_stack.push(arg[0]); - } - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - // process second argument to this operator - switch(op) - { // cases where second argument is a parameter - case SubvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < npar ); - // second argument has opposite sign of parent node - if( add ) - sum_par -= par[arg[1]]; - else sum_par += par[arg[1]]; - break; - - // cases where second argument is a variable and has opposite sign - case SubvvOp: - case SubpvOp: - add = ! add; - - // cases where second argument is a variable and has same sign - case AddvvOp: - case AddpvOp: - // check if the second argument has csum usage - if( op_info[var2op[arg[1]]].usage == csum_usage ) - { CPPAD_ASSERT_UNKNOWN( - size_t( old2new[ var2op[arg[1]] ].new_var) == 0 - ); - // push the operator corresoponding to the second arugment - var.op = op_info[ var2op[arg[1]] ].op; - var.arg = op_info[ var2op[arg[1]] ].arg; - var.add = add; - work.op_stack.push( var ); - } - else - { // there are no nodes below this one - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < current ); - if( add ) - work.add_stack.push(arg[1]); - else work.sub_stack.push(arg[1]); - } - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - } - // number of variables to add in this cummulative sum operator - size_t n_add = work.add_stack.size(); - // number of variables to subtract in this cummulative sum operator - size_t n_sub = work.sub_stack.size(); - // - CPPAD_ASSERT_UNKNOWN( - std::numeric_limits::max() >= n_add + n_sub - ); - // - rec->PutArg( addr_t(n_add) ); // arg[0] - rec->PutArg( addr_t(n_sub) ); // arg[1] - addr_t new_arg = rec->PutPar(sum_par); - rec->PutArg(new_arg); // arg[2] - // addition arguments - for(i = 0; i < n_add; i++) - { CPPAD_ASSERT_UNKNOWN( ! work.add_stack.empty() ); - size_t old_arg = work.add_stack.top(); - new_arg = old2new[ var2op[old_arg] ].new_var; - CPPAD_ASSERT_UNKNOWN( 0 < new_arg && size_t(new_arg) < current ); - rec->PutArg(new_arg); // arg[3+i] - work.add_stack.pop(); - } - // subtraction arguments - for(i = 0; i < n_sub; i++) - { CPPAD_ASSERT_UNKNOWN( ! work.sub_stack.empty() ); - size_t old_arg = work.sub_stack.top(); - new_arg = old2new[ var2op[old_arg] ].new_var; - CPPAD_ASSERT_UNKNOWN( 0 < new_arg && size_t(new_arg) < current ); - rec->PutArg(new_arg); // arg[3 + arg[0] + i] - work.sub_stack.pop(); - } - // number of additions plus number of subtractions - rec->PutArg( addr_t(n_add + n_sub) ); // arg[3 + arg[0] + arg[1]] - // - // return value - struct_size_pair ret; - ret.i_op = rec->num_op_rec(); - ret.i_var = rec->PutOp(CSumOp); - // - return ret; -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - - -# endif diff --git a/external/cppad/include/cppad/local/optimize/record_pv.hpp b/external/cppad/include/cppad/local/optimize/record_pv.hpp deleted file mode 100644 index 77aab4874..000000000 --- a/external/cppad/include/cppad/local/optimize/record_pv.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_RECORD_PV_HPP -# define CPPAD_LOCAL_OPTIMIZE_RECORD_PV_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file record_pv.hpp -Record an operation of the form (parameter op variable). -*/ -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { - -/*! -Record an operation of the form (parameter op variable). - -\param var2op -mapping from old variable index to old operator index. - -\param op_info -mapping from old index to operator index to operator information - -\param old2new -mapping from old operator index to information about the new recording. - -\param current -is the index in the old operation sequence for -the variable corresponding to the result for the current operator. -We use the notation i_op = var2op[current]. -It follows that NumRes( op_info[i_op].op ) > 0. -If 0 < j_op < i_op, either op_info[j_op].csum_connected, -op_info[j_op].usage = 0, or old2new[j_op].new_var != 0. - -\param npar -is the number of parameters corresponding to the old operation sequence. - -\param par -is a vector of length npar containing the parameters -the old operation sequence; i.e., -given a parameter index i < npar, the corresponding parameter value is par[i]. - -\param rec -is the object that will record the new operations. - -\return -is the operator and variable indices in the new operation sequence. - -\param op -is the operator that we are recording which must be one of the following: -AddpvOp, DivpvOp, MulpvOp, PowpvOp, SubpvOp, ZmulpvOp. - -\param arg -is the vector of arguments for this operator. -*/ -template -struct_size_pair record_pv( - const vector& var2op , - const vector& op_info , - const CppAD::vector& old2new , - size_t current , - size_t npar , - const Base* par , - recorder* rec , - OpCode op , - const addr_t* arg ) -{ -# ifndef NDEBUG - switch(op) - { case AddpvOp: - case DivpvOp: - case MulpvOp: - case PowpvOp: - case SubpvOp: - case ZmulpvOp: - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } -# endif - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < npar ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < current ); - addr_t new_arg[2]; - new_arg[0] = rec->PutPar( par[arg[0]] ); - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - rec->PutArg( new_arg[0], new_arg[1] ); - - struct_size_pair ret; - ret.i_op = rec->num_op_rec(); - ret.i_var = rec->PutOp(op); - CPPAD_ASSERT_UNKNOWN( 0 < new_arg[1] && size_t(new_arg[1]) < ret.i_var ); - return ret; -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - - -# endif diff --git a/external/cppad/include/cppad/local/optimize/record_vp.hpp b/external/cppad/include/cppad/local/optimize/record_vp.hpp deleted file mode 100644 index 42e6ffd6b..000000000 --- a/external/cppad/include/cppad/local/optimize/record_vp.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_RECORD_VP_HPP -# define CPPAD_LOCAL_OPTIMIZE_RECORD_VP_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file record_vp.hpp -Record an operation of the form (variable op parameter). -*/ -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { - - -/*! -Record an operation of the form (variable op parameter). - -\param var2op -mapping from old variable index to old operator index. - -\param op_info -mapping from old index to operator index to operator information - -\param old2new -mapping from old operator index to information about the new recording. - -\param current -is the index in the old operation sequence for -the variable corresponding to the result for the current operator. -We use the notation i_op = var2op[current]. -It follows that NumRes( op_info[i_op].op ) > 0. -If 0 < j_op < i_op, either op_info[j_op].csum_connected, -op_info[j_op].usage = 0, or old2new[j_op].new_var != 0. - -\param npar -is the number of parameters corresponding to the old operation sequence. - -\param par -is a vector of length npar containing the parameters -the old operation sequence; i.e., -given a parameter index i < npar, the corresponding parameter value is par[i]. - -\param rec -is the object that will record the new operations. - -\return -is the operator and variable indices in the new operation sequence. - -\param op -is the operator that we are recording which must be one of the following: -DivvpOp, PowvpOp, SubvpOp, ZmulvpOp. - -\param arg -is the vector of arguments for this operator. -*/ -template -struct_size_pair record_vp( - const vector& var2op , - const vector& op_info , - const CppAD::vector& old2new , - size_t current , - size_t npar , - const Base* par , - recorder* rec , - OpCode op , - const addr_t* arg ) -{ -# ifndef NDEBUG - switch(op) - { case DivvpOp: - case PowvpOp: - case SubvpOp: - case ZmulvpOp: - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } -# endif - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < current ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < npar ); - addr_t new_arg[2]; - new_arg[0] = old2new[ var2op[arg[0]] ].new_var; - new_arg[1] = rec->PutPar( par[arg[1]] ); - rec->PutArg( new_arg[0], new_arg[1] ); - - struct_size_pair ret; - ret.i_op = rec->num_op_rec(); - ret.i_var = rec->PutOp(op); - CPPAD_ASSERT_UNKNOWN( 0 < new_arg[0] && size_t(new_arg[0]) < ret.i_var ); - return ret; -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - - -# endif diff --git a/external/cppad/include/cppad/local/optimize/record_vv.hpp b/external/cppad/include/cppad/local/optimize/record_vv.hpp deleted file mode 100644 index 521cb9bd3..000000000 --- a/external/cppad/include/cppad/local/optimize/record_vv.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_RECORD_VV_HPP -# define CPPAD_LOCAL_OPTIMIZE_RECORD_VV_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file record_vv.hpp -Record an operation of the form (variable op variable). -*/ -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { -/*! -Record an operation of the form (variable op variable). - -\param var2op -mapping from old variable index to old operator index. - -\param op_info -mapping from old index to operator index to operator information - -\param old2new -mapping from old operator index to information about the new recording. - -\param current -is the index in the old operation sequence for -the variable corresponding to the result for the current operator. -We use the notation i_op = var2op[current]. -It follows that NumRes( op_info[i_op].op ) > 0. -If 0 < j_op < i_op, either op_info[j_op].csum_connected, -op_info[j_op].usage = 0, or old2new[j_op].new_var != 0. - -\param npar -is the number of parameters corresponding to the old operation sequence. - -\param par -is a vector of length npar containing the parameters -the old operation sequence; i.e., -given a parameter index i < npar, the corresponding parameter value is par[i]. - -\param rec -is the object that will record the new operations. - -\return -is the operator and variable indices in the new operation sequence. - -\param op -is the operator that we are recording which must be one of the following: -AddvvOp, DivvvOp, MulvvOp, PowvvOp, SubvvOp, ZmulvvOp. - -\param arg -is the vector of arguments for this operator. -*/ -template -struct_size_pair record_vv( - const vector& var2op , - const vector& op_info , - const CppAD::vector& old2new , - size_t current , - size_t npar , - const Base* par , - recorder* rec , - OpCode op , - const addr_t* arg ) -{ -# ifndef NDEBUG - switch(op) - { case AddvvOp: - case DivvvOp: - case MulvvOp: - case PowvvOp: - case SubvvOp: - case ZmulvvOp: - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } -# endif - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < current ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < current ); - addr_t new_arg[2]; - new_arg[0] = old2new[ var2op[arg[0]] ].new_var; - new_arg[1] = old2new[ var2op[arg[1]] ].new_var; - rec->PutArg( new_arg[0], new_arg[1] ); - - struct_size_pair ret; - ret.i_op = rec->num_op_rec(); - ret.i_var = rec->PutOp(op); - CPPAD_ASSERT_UNKNOWN( 0 < new_arg[0] && size_t(new_arg[0]) < ret.i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < new_arg[1] && size_t(new_arg[1]) < ret.i_var ); - return ret; -} - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - - -# endif diff --git a/external/cppad/include/cppad/local/optimize/size_pair.hpp b/external/cppad/include/cppad/local/optimize/size_pair.hpp deleted file mode 100644 index b97964ab2..000000000 --- a/external/cppad/include/cppad/local/optimize/size_pair.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_SIZE_PAIR_HPP -# define CPPAD_LOCAL_OPTIMIZE_SIZE_PAIR_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/*! -\file size_pair.hpp -Information for one variable and one operation sequence. -*/ -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { - -/*! -\file size_pair.hpp -Information for one variable in one operation sequence. -*/ -struct struct_size_pair { - size_t i_op; /// operator index for this variable - size_t i_var; /// variable index for this variable -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/optimize/usage.hpp b/external/cppad/include/cppad/local/optimize/usage.hpp deleted file mode 100644 index 6fc569718..000000000 --- a/external/cppad/include/cppad/local/optimize/usage.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_OPTIMIZE_USAGE_HPP -# define CPPAD_LOCAL_OPTIMIZE_USAGE_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -namespace CppAD { namespace local { namespace optimize { - -enum enum_usage { - /// This operator is not used. - no_usage, - - /// This operator is used one or more times. - yes_usage, - - /*! - This operator is only used once, it is a summation operator, - and its parrent is a summation operator. Furthermore, its result is not - a dependent variable. Hence case it can be removed as part of a - cumulative summation starting at its parent or above. - */ - csum_usage -}; - -} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/parameter_op.hpp b/external/cppad/include/cppad/local/parameter_op.hpp deleted file mode 100644 index d7c9778e8..000000000 --- a/external/cppad/include/cppad/local/parameter_op.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// $Id: parameter_op.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_PARAMETER_OP_HPP -# define CPPAD_LOCAL_PARAMETER_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file parameter_op.hpp -Zero order forward mode for ParOp -*/ - - -/*! -Compute zero order forward mode Taylor coefficient for result of op = ParOp. - -The C++ source code corresponding to this operation is one of the following -\verbatim - ADFun f(x, y) - f.Dependent(x, y) -\endverbatim -where some of the components of the vector y are parameters. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to the component of y -that is a parameter. - -\param arg -\a arg[0] -\n -index corresponding to the parameter value for this operator. - -\param num_par -is the number of parameters in \a parameter. - -\param parameter -\b Input: \a parameter[ \a arg[0] ] is the value of a component -of y that is a parameter. - -\param cap_order -number of colums in the matrix containing all the Taylor coefficients. - -\param taylor -\b Output: \a taylor [ \a i_z * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z. - -\par Checked Assertions where op is the unary operator with one result: -\li NumArg(op) == 1 -\li NumRes(op) == 1 -\li \a size_t(arg[0]) < num_par -\li \a 0 < \a cap_order -*/ -template -inline void forward_par_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ParOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ParOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - Base* z = taylor + i_z * cap_order; - - z[0] = parameter[ arg[0] ]; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/player.hpp b/external/cppad/include/cppad/local/player.hpp deleted file mode 100644 index f269b211e..000000000 --- a/external/cppad/include/cppad/local/player.hpp +++ /dev/null @@ -1,1027 +0,0 @@ -// $Id: player.hpp 3941 2017-06-02 05:36:10Z bradbell $ -# ifndef CPPAD_LOCAL_PLAYER_HPP -# define CPPAD_LOCAL_PLAYER_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file player.hpp -File used to define the player class. -*/ - - -/*! -Class used to store and play back an operation sequence recording. - -\tparam Base -These were AD< Base > operations when recorded. Operations during playback -are done using the type Base . -*/ -template -class player { -private: - // ---------------------------------------------------------------------- - // Variables that define the recording - // ---------------------------------------------------------------------- - /// Number of variables in the recording. - size_t num_var_rec_; - - /// number of vecad load opeations in the reconding - size_t num_load_op_rec_; - - /// Number of VecAD vectors in the recording - size_t num_vecad_vec_rec_; - - /// The operators in the recording. - pod_vector op_rec_; - - /// The VecAD indices in the recording. - pod_vector vecad_ind_rec_; - - /// The operation argument indices in the recording - pod_vector op_arg_rec_; - - /// The parameters in the recording. - /// Note that Base may not be plain old data, so use false in consructor. - pod_vector par_rec_; - - /// Character strings ('\\0' terminated) in the recording. - pod_vector text_rec_; - - // ---------------------------------------------------------------------- - // Variables used for iterating thorough operators in the recording - // ---------------------------------------------------------------------- - /// Current operator - OpCode op_; - - /// Index in recording corresponding to current operator - size_t op_index_; - - /// Current offset of the argument indices in op_arg_rec_ - const addr_t* op_arg_; - - /// Index for primary (last) variable corresponding to current operator - size_t var_index_; - - /// index for the current user atomic function - size_t user_index_; - - /// Flag indicating that a special function must be called before next - /// This flags is not used when NDEBUG is defined, but kept in this case - /// so that debug and release versions of CppAD can be mixed. - bool special_before_next_; - -public: - // ================================================================= - /// constructor - player(void) : - num_var_rec_(0) , - num_load_op_rec_(0) , - op_rec_( std::numeric_limits::max() ) , - vecad_ind_rec_( std::numeric_limits::max() ) , - op_arg_rec_( std::numeric_limits::max() ) , - par_rec_( std::numeric_limits::max() ) , - text_rec_( std::numeric_limits::max() ) - { } - - // ================================================================= - /// destructor - ~player(void) - { } - - // =============================================================== - /*! - Moving an operation sequence from a recorder to this player - - \param rec - the object that was used to record the operation sequence. After this - operation, the state of the recording is no longer defined. For example, - the pod_vector member variables in this have been swapped with - rec . - */ - void get(recorder& rec) - { size_t i; - - // just set size_t values - num_var_rec_ = rec.num_var_rec_; - num_load_op_rec_ = rec.num_load_op_rec_; - - // op_rec_ - op_rec_.swap(rec.op_rec_); - - // vec_ind_rec_ - vecad_ind_rec_.swap(rec.vecad_ind_rec_); - - // op_arg_rec_ - op_arg_rec_.swap(rec.op_arg_rec_); - - // par_rec_ - par_rec_.swap(rec.par_rec_); - - // text_rec_ - text_rec_.swap(rec.text_rec_); - - // set the number of VecAD vectors - num_vecad_vec_rec_ = 0; - for(i = 0; i < vecad_ind_rec_.size(); i += vecad_ind_rec_[i] + 1) - num_vecad_vec_rec_++; - - // vecad_ind_rec_ contains size of each VecAD followed by - // the parameter indices used to iniialize it. - CPPAD_ASSERT_UNKNOWN( i == vecad_ind_rec_.size() ); - } - // =============================================================== - /*! - Copying an operation sequence from another player to this one - - \param play - the object that contains the operatoion sequence to copy. - */ - void operator=(const player& play) - { - num_var_rec_ = play.num_var_rec_; - num_load_op_rec_ = play.num_load_op_rec_; - op_rec_ = play.op_rec_; - num_vecad_vec_rec_ = play.num_vecad_vec_rec_; - vecad_ind_rec_ = play.vecad_ind_rec_; - op_arg_rec_ = play.op_arg_rec_; - par_rec_ = play.par_rec_; - text_rec_ = play.text_rec_; - } - // =============================================================== - /// Erase the recording stored in the player - void Erase(void) - { - num_var_rec_ = 0; - num_load_op_rec_ = 0; - num_vecad_vec_rec_ = 0; - - op_rec_.erase(); - vecad_ind_rec_.erase(); - op_arg_rec_.erase(); - par_rec_.erase(); - text_rec_.erase(); - } - // ================================================================ - // const functions that retrieve infromation from this player - // ================================================================ - /*! - \brief - fetch an operator from the recording. - - \return - the i-th operator in the recording. - - \param i - the index of the operator in recording - */ - OpCode GetOp (size_t i) const - { return OpCode(op_rec_[i]); } - - /*! - \brief - Fetch a VecAD index from the recording. - - \return - the i-th VecAD index in the recording. - - \param i - the index of the VecAD index in recording - */ - size_t GetVecInd (size_t i) const - { return vecad_ind_rec_[i]; } - - /*! - \brief - Fetch a parameter from the recording. - - \return - the i-th parameter in the recording. - - \param i - the index of the parameter in recording - */ - Base GetPar(size_t i) const - { return par_rec_[i]; } - - /*! - \brief - Fetch entire parameter vector from the recording. - - \return - the entire parameter vector. - - */ - const Base* GetPar(void) const - { return par_rec_.data(); } - - /*! - \brief - Fetch a '\\0' terminated string from the recording. - - \return - the beginning of the string. - - \param i - the index where the string begins. - */ - const char *GetTxt(size_t i) const - { CPPAD_ASSERT_UNKNOWN(i < text_rec_.size() ); - return text_rec_.data() + i; - } - - /// Fetch number of variables in the recording. - size_t num_var_rec(void) const - { return num_var_rec_; } - - /// Fetch number of vecad load operations - size_t num_load_op_rec(void) const - { return num_load_op_rec_; } - - /// Fetch number of operators in the recording. - size_t num_op_rec(void) const - { return op_rec_.size(); } - - /// Fetch number of VecAD indices in the recording. - size_t num_vec_ind_rec(void) const - { return vecad_ind_rec_.size(); } - - /// Fetch number of VecAD vectors in the recording - size_t num_vecad_vec_rec(void) const - { return num_vecad_vec_rec_; } - - /// Fetch number of argument indices in the recording. - size_t num_op_arg_rec(void) const - { return op_arg_rec_.size(); } - - /// Fetch number of parameters in the recording. - size_t num_par_rec(void) const - { return par_rec_.size(); } - - /// Fetch number of characters (representing strings) in the recording. - size_t num_text_rec(void) const - { return text_rec_.size(); } - - /// Fetch a rough measure of amount of memory used to store recording - /// (just lengths, not capacities). - size_t Memory(void) const - { return op_rec_.size() * sizeof(OpCode) - + op_arg_rec_.size() * sizeof(addr_t) - + par_rec_.size() * sizeof(Base) - + text_rec_.size() * sizeof(char) - + vecad_ind_rec_.size() * sizeof(addr_t) - ; - } - // ===================================================================== - // Forward iteration over operations in this player - // ===================================================================== - /*! - Start a play back of the recording during a forward sweep. - - Use repeated calls to forward_next to play back one operator at a time. - - \param op [out] - The input value of op does not matter. Its output value is the - first operator in the recording; i.e., BeginOp. - - \param op_arg [out] - The input value of op_arg does not matter. Its output value is the - beginning of the vector of argument indices for the first operation; - i.e., 0 - - \param op_index [out] - The input value of op_index does not matter. Its output value - is the index of the next first operator in the recording; i.e., 0. - - \param var_index [out] - The input value of var_index does not matter. Its output value is the - index of the primary (last) result corresponding to the the first - operator (which must be a BeginOp); i.e., 0. - */ - void forward_start( - OpCode& op , - const addr_t*& op_arg , - size_t& op_index , - size_t& var_index ) - { - op = op_ = OpCode( op_rec_[0] ); - op_arg = op_arg_ = op_arg_rec_.data(); - op_index = op_index_ = 0; - var_index = var_index_ = 0; -# ifndef NDEBUG - special_before_next_ = false; - CPPAD_ASSERT_UNKNOWN( op_ == BeginOp ); - CPPAD_ASSERT_NARG_NRES(op_, 1, 1); -# endif - return; - } - - /*! - Fetch the next operator during a forward sweep. - - Use forward_start to initialize forward play back to the first operator; - i.e., the BeginOp at the beginning of the recording. - We use the notation forward_routine to denote the set - forward_start, forward_next, forward_csum, forward_cskip, forward_user. - - \param op [in,out] - The input value of op must be its output value from the - previous call to a forward_routine. - Its output value is the next operator in the recording. - For speed, forward_next does not check for the special cases - where op == CSumOp (op == CSkipOp). In this case - some of the return values from forward_next must be corrected by a call - to forward_csum (forward_cskip). - In addition, for speed, extra information that is only used by the - UserOp, UsrapOp, UsravOp, UsrrpOp, UsrrvOp operations is not returned - for all operations. If this information is needed, then forward_user - should be called after each call to forward_next. - - \param op_arg [in,out] - The input value of op_arg must be its output value form the - previous call to a forward routine. - Its output value is the - beginning of the vector of argument indices for this operation. - - \param op_index [in,out] - The input value of op_index must be its output value form the - previous call to a forward routine. - Its output value is the index of this operator in the recording. - Thus the ouput value following the previous call to forward_start is one. - In addition, - the output value increases by one with each call to forward_next. - - \param var_index [in,out] - The input value of var_index must be its output value form the - previous call to a forward routine. - Its output value is the - index of the primary (last) result corresponding to the operator op. - */ - void forward_next( - OpCode& op , - const addr_t*& op_arg , - size_t& op_index , - size_t& var_index ) - { - CPPAD_ASSERT_UNKNOWN( ! special_before_next_ ); - CPPAD_ASSERT_UNKNOWN( op_ == op ); - CPPAD_ASSERT_UNKNOWN( op_arg == op_arg_ ); - CPPAD_ASSERT_UNKNOWN( op_index == op_index_ ); - CPPAD_ASSERT_UNKNOWN( var_index == var_index_ ); - - // index for the next operator - op_index = ++op_index_; - - // first argument for next operator - op_arg = op_arg_ += NumArg(op_); - - // next operator - op = op_ = OpCode( op_rec_[ op_index_ ] ); - - // index for last result for next operator - var_index = var_index_ += NumRes(op); - -# ifndef NDEBUG - special_before_next_ = (op == CSumOp) | (op == CSkipOp); - // - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.data() <= op_arg_ ); - CPPAD_ASSERT_UNKNOWN( - op_arg_ + NumArg(op) <= op_arg_rec_.data() + op_arg_rec_.size() - ); - CPPAD_ASSERT_UNKNOWN( var_index_ < num_var_rec_ ); -# endif - } - /*! - Correct forward_next return values when op == CSumOp. - - \param op [in] - The input value of op must be the return value from the previous - call to forward_next and must be CSumOp. It is not modified. - - \param op_arg [in,out] - The input value of op_arg must be the return value from the - previous call to forward_next. Its output value is the - beginning of the vector of argument indices for the next operation. - - \param op_index [in] - The input value of op_index must be the return value from the - previous call to forward_next. Its is not modified. - - \param var_index [in] - The input value of var_index must be the return value from the - previous call to forward_next. It is not modified. - */ - void forward_csum( - const OpCode& op , - const addr_t*& op_arg , - const size_t& op_index , - const size_t& var_index ) - { - CPPAD_ASSERT_UNKNOWN( op_ == op ); - CPPAD_ASSERT_UNKNOWN( op_arg == op_arg_ ); - CPPAD_ASSERT_UNKNOWN( op_index == op_index_ ); - CPPAD_ASSERT_UNKNOWN( var_index == var_index_ ); - - CPPAD_ASSERT_UNKNOWN( op == CSumOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(CSumOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( - op_arg[0] + op_arg[1] == op_arg[ 3 + op_arg[0] + op_arg[1] ] - ); - /* - The only thing that really needs fixing is op_arg_. - Actual number of arugments for this operator is - op_arg[0] + op_arg[1] + 4. - We must change op_arg_ so that when you add NumArg(CSumOp) - you get first argument for next operator in sequence. - */ - op_arg = op_arg_ += op_arg[0] + op_arg[1] + 4; - -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( special_before_next_ ); - special_before_next_ = false; - // - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.data() <= op_arg_ ); - CPPAD_ASSERT_UNKNOWN( - op_arg_ + NumArg(op) <= op_arg_rec_.data() + op_arg_rec_.size() - ); - CPPAD_ASSERT_UNKNOWN( var_index_ < num_var_rec_ ); -# endif - } - /*! - Correct forward_next return values when op == CSkipOp. - - \param op [in] - The input value of op must be the return value from the previous - call to forward_next and must be CSkipOp. It is not modified. - - \param op_arg [in,out] - The input value of op_arg must be the return value from the - previous call to forward_next. Its output value is the - beginning of the vector of argument indices for the next operation. - - \param op_index [in] - The input value of op_index must be the return value from the - previous call to forward_next. Its is not modified. - - \param var_index [in] - The input value of var_index must be the return value from the - previous call to forward_next. It is not modified. - */ - void forward_cskip( - const OpCode& op , - const addr_t*& op_arg , - const size_t& op_index , - const size_t& var_index ) - { - CPPAD_ASSERT_UNKNOWN( op_ == op ); - CPPAD_ASSERT_UNKNOWN( op_arg == op_arg_ ); - CPPAD_ASSERT_UNKNOWN( op_index == op_index_ ); - CPPAD_ASSERT_UNKNOWN( var_index == var_index_ ); - - CPPAD_ASSERT_UNKNOWN( op == CSkipOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(CSkipOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( - op_arg[4] + op_arg[5] == op_arg[ 6 + op_arg[4] + op_arg[5] ] - ); - /* - The only thing that really needs fixing is op_arg_. - Actual number of arugments for this operator is - 7 + op_arg[4] + op_arg[5] - We must change op_arg_ so that when you add NumArg(CSkipOp) - you get first argument for next operator in sequence. - */ - op_arg = op_arg_ += 7 + op_arg[4] + op_arg[5]; - -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( special_before_next_ ); - special_before_next_ = false; - // - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.data() <= op_arg_ ); - CPPAD_ASSERT_UNKNOWN( - op_arg_ + NumArg(op) <= op_arg_rec_.data() + op_arg_rec_.size() - ); - CPPAD_ASSERT_UNKNOWN( var_index_ < num_var_rec_ ); -# endif - } - /*! - Extra information when forward_next returns one of the following op values: - UserOp, UsrapOp, UsravOp, UsrrpOp, UsrrvOp. - - \param op [in] - The value of op must be the return value from the previous - call to forward_next and one of those listed above. - - \param user_state [in,out] - This should be initialized to start_user before each call to - forward_start and not otherwise changed by the calling program. - Upon return it is the state of the user atomic call as follows: - \li start_user next user operator will be UserOp at beginning of a call - \li arg_user next operator will be UsrapOp or UsravOp. - \li ret_user next operator will be UsrrpOp or UsrrvOp. - \li end_user next operator will be UserOp at end of a call - - \param user_old [in,out] - This should not be changed by the calling program. - Upon return it is the extra information used by the old_atomic interface. - - \param user_m [in,out] - This should not be changed by the calling program. - Upon return it is the number of results for this user atomic function. - - \param user_n [in,out] - This should not be changed by the calling program. - Upon return it is the number of arguments to this user atomic function. - - \param user_i [in,out] - This should not be changed by the calling program. - Upon return it is the index for the next result for this - user atomic function; i.e., the next UsrrpOp or UsrrvOp. - If there are no more results, the return value is user_m. - - \param user_j [in,out] - This should not be changed by the calling program. - Upon return it is the index for the next argument for this - user atomic function; i.e., the next UsrapOp or UsravOp. - If there are no more arguments, the return value is user_n. - - \return - the return value is a pointer to the atomic_base object - for the correspnding function. If the corresponding user function - has been deleted, an CPPAD_ASSERT_KNOWN is generated and a null pointer - is returned. - - \par Initialization - The initial value of user_old, user_m, user_n, user_i, user_j - do not matter. They may be initialized to avoid compiler warnings. - */ - atomic_base* forward_user( - const OpCode& op , - enum_user_state& user_state , - size_t& user_old , - size_t& user_m , - size_t& user_n , - size_t& user_i , - size_t& user_j ) - { atomic_base* user_atom; - switch(op) - { - case UserOp: - CPPAD_ASSERT_NARG_NRES(op, 4, 0); - if( user_state == start_user ) - { - // forward_user arguments determined by values in UserOp - user_index_ = op_arg_[0]; - user_old = op_arg_[1]; - user_n = op_arg_[2]; - user_m = op_arg_[3]; - CPPAD_ASSERT_UNKNOWN( user_n > 0 ); - - // other forward_user arguments - user_j = 0; - user_i = 0; - user_state = arg_user; - -# ifndef NDEBUG - user_atom = atomic_base::class_object(user_index_); - if( user_atom == CPPAD_NULL ) - { // user_atom is null so cannot use user_atom->afun_name() - std::string msg = - atomic_base::class_name(user_index_) - + ": atomic_base function has been deleted"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - } - else - { // copy of UsrOp at end of this atomic sequence - CPPAD_ASSERT_UNKNOWN( user_state == end_user ); - CPPAD_ASSERT_UNKNOWN( user_index_ == size_t(op_arg_[0]) ); - CPPAD_ASSERT_UNKNOWN( user_old == size_t(op_arg_[1]) ); - CPPAD_ASSERT_UNKNOWN( user_n == size_t(op_arg_[2]) ); - CPPAD_ASSERT_UNKNOWN( user_m == size_t(op_arg_[3]) ); - CPPAD_ASSERT_UNKNOWN( user_j == user_n ); - CPPAD_ASSERT_UNKNOWN( user_i == user_m ); - user_state = start_user; - } - break; - - case UsrapOp: - case UsravOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( user_state == arg_user ); - CPPAD_ASSERT_UNKNOWN( user_i == 0 ); - CPPAD_ASSERT_UNKNOWN( user_j < user_n ); - ++user_j; - if( user_j == user_n ) - user_state = ret_user; - break; - - case UsrrpOp: - case UsrrvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 || op == UsrrvOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 || op == UsrrpOp ); - CPPAD_ASSERT_UNKNOWN( user_state == ret_user ); - CPPAD_ASSERT_UNKNOWN( user_i < user_m ); - CPPAD_ASSERT_UNKNOWN( user_j == user_n ); - ++user_i; - if( user_i == user_m ) - user_state = end_user; - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - // the atomic_base object corresponding to this user function - user_atom = atomic_base::class_object(user_index_); - CPPAD_ASSERT_UNKNOWN( user_atom != CPPAD_NULL ); - return user_atom; - } - // ===================================================================== - // Reverse iteration over operations in this player - // ===================================================================== - /*! - Start a play back of the recording during a reverse sweep. - - Use repeated calls to reverse_next to play back one operator at a time. - - \param op [out] - The input value of op does not matter. Its output value is the - last operator in the recording; i.e., EndOp. - - \param op_arg [out] - The input value of op_arg does not matter. Its output value is the - beginning of the vector of argument indices for the last operation; - (there are no arguments for the last operation so op_arg is invalid). - - \param op_index [out[ - The input value of op_index does not matter. Its output value - is the index of the last operator in the recording. - - \param var_index [out] - The input value of var_index does not matter. Its output value is the - index of the primary (last) result corresponding to the the last - operator (which must be a EndOp). - (there are no results for the last operation so var_index is invalid). - */ - - void reverse_start( - OpCode& op , - const addr_t*& op_arg , - size_t& op_index , - size_t& var_index ) - { - op_arg = op_arg_ = op_arg_rec_.data() + op_arg_rec_.size(); - op_index = op_index_ = op_rec_.size() - 1; - var_index = var_index_ = num_var_rec_ - 1; - op = op_ = OpCode( op_rec_[ op_index_ ] ); -# ifndef NDEBUG - special_before_next_ = false; - CPPAD_ASSERT_UNKNOWN( op_ == EndOp ); - CPPAD_ASSERT_NARG_NRES(op, 0, 0); -# endif - return; - } - - /*! - Fetch the next operator during a reverse sweep. - - Use reverse_start to initialize reverse play back to the last operator; - i.e., the EndOp at the end of the recording. - We use the notation reverse_routine to denote the set - reverse_start, reverse_next, reverse_csum, reverse_cskip, reverse_user. - - \param op [in,out] - The input value of op must be its output value from the - previous call to a reverse_routine. - Its output value is the next operator in the recording (in reverse order). - For speed, reverse_next does not check for the special cases - where op == CSumOp (op == CSkipOp). In this case - some of the return values from reverse_next must be corrected by a call - to reverse_csum (reverse_cskip). - In addition, for speed, extra information that is only used by the - UserOp, UsrapOp, UsravOp, UsrrpOp, UsrrvOp operations is not returned - for all operations. If this information is needed, then reverse_user - should be called after each call to reverse_next. - - \param op_arg [in,out] - The input value of op_arg must be its output value from the - previous call to a reverse_routine. - Its output value is the - beginning of the vector of argument indices for this operation. - - \param op_index [in,out] - The input value of op_index must be its output value from the - previous call to a reverse_routine. - Its output value - is the index of this operator in the recording. Thus the output - value following the previous call to reverse_start is equal to - the number of operators in the recording minus one. - In addition, the output value decreases by one with each call to - reverse_next. - The last operator, BeginOp, sets op_index equal to 0. - - \param var_index [in,out] - The input value of var_index must be its output value from the - previous call to a reverse_routine. - Its output value is the - index of the primary (last) result corresponding to the operator op. - The last operator sets var_index equal to 0 (corresponding to BeginOp - at beginning of operation sequence). - */ - void reverse_next( - OpCode& op , - const addr_t*& op_arg , - size_t& op_index , - size_t& var_index ) - { - CPPAD_ASSERT_UNKNOWN( ! special_before_next_ ); - CPPAD_ASSERT_UNKNOWN( op_ == op ); - CPPAD_ASSERT_UNKNOWN( op_arg == op_arg_ ); - CPPAD_ASSERT_UNKNOWN( op_index == op_index_ ); - CPPAD_ASSERT_UNKNOWN( var_index == var_index_ ); - - // index of the last result for the next operator - CPPAD_ASSERT_UNKNOWN( var_index_ >= NumRes(op_) ); - var_index = var_index_ -= NumRes(op_); - - // next operator - CPPAD_ASSERT_UNKNOWN( op_index_ > 0 ); - op_index = --op_index_; // index - op = op_ = OpCode( op_rec_[ op_index_ ] ); // value - - // first argument for next operator - op_arg = op_arg_ -= NumArg(op); - -# ifndef NDEBUG - special_before_next_ = (op == CSumOp) | (op == CSkipOp); - // - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.data() <= op_arg_ ); - CPPAD_ASSERT_UNKNOWN( - op_arg_ + NumArg(op) <= op_arg_rec_.data() + op_arg_rec_.size() - ); -# endif - } - /*! - Correct reverse_next return values when op == CSumOp. - - \param op [in] - The input value of op must be the return value from the previous - call to reverse_next and must be CSumOp. It is not modified. - - \param op_arg [in,out] - The input value of op_arg must be the return value from the - previous call to reverse_next. Its output value is the - beginning of the vector of argument indices for this operation. - - \param op_index [in] - The input value of op_index must be the return value from the - previous call to reverse_next. It is not modified. - - \param var_index [in] - The input value of var_index must be the return value from the - previous call to reverse_next. It is not modified. - */ - - void reverse_csum( - const OpCode& op , - const addr_t*& op_arg , - const size_t& op_index , - const size_t& var_index ) - { - CPPAD_ASSERT_UNKNOWN( op_ == op ); - CPPAD_ASSERT_UNKNOWN( op_arg == op_arg_ ); - CPPAD_ASSERT_UNKNOWN( op_index == op_index_ ); - CPPAD_ASSERT_UNKNOWN( var_index == var_index_ ); - - CPPAD_ASSERT_UNKNOWN( op == CSumOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(CSumOp) == 0 ); - /* - The variables that need fixing are op_arg_ and op_arg. Currently, - op_arg points to the last argument for the previous operator. - */ - // last argument for this csum operation - --op_arg; - // first argument for this csum operation - op_arg = op_arg_ -= (op_arg[0] + 4); - // now op_arg points to the first argument for this csum operator - - CPPAD_ASSERT_UNKNOWN( - op_arg[0] + op_arg[1] == op_arg[ 3 + op_arg[0] + op_arg[1] ] - ); -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( special_before_next_ ); - special_before_next_ = false; - // - CPPAD_ASSERT_UNKNOWN( op_index_ < op_rec_.size() ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.data() <= op_arg_ ); - CPPAD_ASSERT_UNKNOWN( var_index_ < num_var_rec_ ); -# endif - } - /*! - Correct reverse_next return values when op == CSkipOp. - - \param op [int] - The input value of op must be the return value from the previous - call to reverse_next and must be CSkipOp. It is not modified. - - \param op_arg [in,out] - The input value of op_arg must be the return value from the - previous call to reverse_next. Its output value is the - beginning of the vector of argument indices for this operation. - - \param op_index [in] - The input value of op_index must be the return value from the - previous call to reverse_next. It is not modified. - - \param var_index [in] - The input value of var_index must be the return value from the - previous call to reverse_next. It is not modified. - */ - - void reverse_cskip( - const OpCode& op , - const addr_t*& op_arg , - const size_t& op_index , - const size_t& var_index ) - { - CPPAD_ASSERT_UNKNOWN( op_ == op ); - CPPAD_ASSERT_UNKNOWN( op_arg == op_arg_ ); - CPPAD_ASSERT_UNKNOWN( op_index == op_index_ ); - CPPAD_ASSERT_UNKNOWN( var_index == var_index_ ); - - CPPAD_ASSERT_UNKNOWN( op == CSkipOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(CSkipOp) == 0 ); - /* - The variables that need fixing are op_arg_ and op_arg. Currently, - op_arg points to the last arugment for the previous operator. - */ - // last argument for this cskip operation - --op_arg; - // first argument for this cskip operation - op_arg = op_arg_ -= (op_arg[0] + 7); - - CPPAD_ASSERT_UNKNOWN( - op_arg[4] + op_arg[5] == op_arg[ 6 + op_arg[4] + op_arg[5] ] - ); -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( special_before_next_ ); - special_before_next_ = false; - // - CPPAD_ASSERT_UNKNOWN( op_index_ < op_rec_.size() ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.data() <= op_arg_ ); - CPPAD_ASSERT_UNKNOWN( var_index_ < num_var_rec_ ); -# endif - } - /*! - Extra information when reverse_next returns one of the following op values: - UserOp, UsrapOp, UsravOp, UsrrpOp, UsrrvOp. - - \param op [in] - The value of op must be the return value from the previous - call to reverse_next and one of those listed above. - - \param user_state [in,out] - This should be initialized to end_user before each call to - reverse_start and not otherwise changed by the calling program. - Upon return it is the state of the user atomic call as follows: - \li end_user next user operator will be UserOp at end of a call - \li ret_user next operator will be UsrrpOp or UsrrvOp. - \li arg_user next operator will be UsrapOp or UsravOp. - \li start_user next operator will be UserOp at beginning of a call - - \param user_old [in,out] - This should not be changed by the calling program. - Upon return it is the extra information used by the old_atomic interface. - - \param user_m [in,out] - This should not be changed by the calling program. - Upon return it is the number of results for this user atomic function. - - \param user_n [in,out] - This should not be changed by the calling program. - Upon return it is the number of arguments to this user atomic function. - - \param user_i [in,out] - This should not be changed by the calling program. - Upon return it is the index for this result for this - user atomic function; i.e., this UsrrpOp or UsrrvOp. - If the input value of user_state is end_user, the return value is user_m. - - \param user_j [in,out] - This should not be changed by the calling program. - Upon return it is the index for this argument for this - user atomic function; i.e., this UsrapOp or UsravOp. - If the input value of user_state is end_user, the return value is user_n. - - \return - the return value is a pointer to the atomic_base object - for the correspnding function. If the corresponding user function - has been deleted, an CPPAD_ASSERT_KNOWN is generated and a null pointer - is returned. - - \par Initialization - The initial value of user_old, user_m, user_n, user_i, user_j - do not matter. They may be initialized to avoid compiler warnings. - */ - atomic_base* reverse_user( - const OpCode& op , - enum_user_state& user_state , - size_t& user_old , - size_t& user_m , - size_t& user_n , - size_t& user_i , - size_t& user_j ) - { atomic_base* user_atom; - switch(op) - { - case UserOp: - CPPAD_ASSERT_NARG_NRES(op, 4, 0); - if( user_state == end_user ) - { - // reverse_user arguments determined by values in UserOp - user_index_ = op_arg_[0]; - user_old = op_arg_[1]; - user_n = op_arg_[2]; - user_m = op_arg_[3]; - CPPAD_ASSERT_UNKNOWN( user_n > 0 ); - - // other reverse_user arguments - user_j = user_n; - user_i = user_m; - user_state = ret_user; - - // the atomic_base object corresponding to this user function -# ifndef NDEBUG - user_atom = atomic_base::class_object(user_index_); - if( user_atom == CPPAD_NULL ) - { // user_atom is null so cannot use user_atom->afun_name() - std::string msg = - atomic_base::class_name(user_index_) - + ": atomic_base function has been deleted"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - } - else - { // copy of UsrOp at end of this atomic sequence - CPPAD_ASSERT_UNKNOWN( user_state == start_user ); - CPPAD_ASSERT_UNKNOWN( user_index_ == size_t(op_arg_[0]) ); - CPPAD_ASSERT_UNKNOWN( user_old == size_t(op_arg_[1]) ); - CPPAD_ASSERT_UNKNOWN( user_n == size_t(op_arg_[2]) ); - CPPAD_ASSERT_UNKNOWN( user_m == size_t(op_arg_[3]) ); - CPPAD_ASSERT_UNKNOWN( user_j == 0 ); - CPPAD_ASSERT_UNKNOWN( user_i == 0 ); - user_state = end_user; - } - break; - - case UsrapOp: - case UsravOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 ); - CPPAD_ASSERT_UNKNOWN( user_state == arg_user ); - CPPAD_ASSERT_UNKNOWN( user_i == 0 ); - CPPAD_ASSERT_UNKNOWN( user_j <= user_n ); - CPPAD_ASSERT_UNKNOWN( 0 < user_j ); - --user_j; - if( user_j == 0 ) - user_state = start_user; - break; - - case UsrrpOp: - case UsrrvOp: - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 || op == UsrrvOp ); - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 || op == UsrrpOp ); - CPPAD_ASSERT_UNKNOWN( user_state == ret_user ); - CPPAD_ASSERT_UNKNOWN( user_i <= user_m ); - CPPAD_ASSERT_UNKNOWN( user_j == user_n ); - CPPAD_ASSERT_UNKNOWN( 0 < user_i ); - --user_i; - if( user_i == 0 ) - user_state = arg_user; - break; - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - // the atomic_base object corresponding to this user function - user_atom = atomic_base::class_object(user_index_); - CPPAD_ASSERT_UNKNOWN( user_atom != CPPAD_NULL ); - return user_atom; - } - -}; - -} } // END_CPPAD_lOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/pod_vector.hpp b/external/cppad/include/cppad/local/pod_vector.hpp deleted file mode 100644 index d70974074..000000000 --- a/external/cppad/include/cppad/local/pod_vector.hpp +++ /dev/null @@ -1,293 +0,0 @@ -// $Id: pod_vector.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_POD_VECTOR_HPP -# define CPPAD_LOCAL_POD_VECTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# if CPPAD_CSTDINT_HAS_8_TO_64 -# include -# endif -# include -# include -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file pod_vector.hpp -File used to define pod_vector class -*/ - -/* -A list of which Types pod_vector consideres to be plain old data -*/ -/// default value is false -template inline bool is_pod(void) { return false; } -/// system pod types so far: -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -# if CPPAD_CSTDINT_HAS_8_TO_64 -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -// -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -# else // CPPAD_CSTDINT_HAS_8_TO_64 -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -// -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -template <> inline bool is_pod(void) { return true; } -# if CPPAD_SIZE_T_NOT_UNSIGNED_INT -template <> inline bool is_pod(void) { return true; } -# endif -# endif // CPPAD_CSTDINT_HAS_8_TO_64 - -/// CppAD pod types so far: -template <> inline bool is_pod(void) { return true; } - -// --------------------------------------------------------------------------- -/*! -A vector class with Type element that does not use element constructors -or destructors when Type is Plain Old Data (pod). -*/ -template -class pod_vector { -private: - /// maximum number of elements that should ever be in this vector - size_t max_length_; - /// number of elements currently in this vector - size_t length_; - /// maximum number of Type elements current allocation can hold - size_t capacity_; - /// pointer to the first type elements - /// (not defined and should not be used when capacity_ = 0) - Type *data_; - /// do not use the copy constructor - explicit pod_vector(const pod_vector& ) - { CPPAD_ASSERT_UNKNOWN(false); } -public: - /// Constructors set capacity, length, and data to zero. - /// - /// \param max_length - /// value for maximum number of elements in this vector. - inline pod_vector( - size_t max_length = std::numeric_limits::max() - ) - : max_length_(max_length), length_(0), capacity_(0), data_(CPPAD_NULL) - { } - // ---------------------------------------------------------------------- - /// Destructor: returns allocated memory to \c thread_alloc; - /// see \c extend. If this is not plain old data, - /// the destructor for each element is called. - ~pod_vector(void) - { if( capacity_ > 0 ) - { void* v_ptr = reinterpret_cast( data_ ); - if( ! is_pod() ) - { // call destructor for each element - size_t i; - for(i = 0; i < capacity_; i++) - (data_ + i)->~Type(); - } - thread_alloc::return_memory(v_ptr); - } - } - // ---------------------------------------------------------------------- - /// current number of elements in this vector. - inline size_t size(void) const - { return length_; } - /// current capacity (amount of allocated storage) for this vector. - inline size_t capacity(void) const - { return capacity_; } - /// current data pointer, no longer valid after any of the following: - /// extend, erase, operator=, and ~pod_vector. - /// Take extreem care when using this function. - inline Type* data(void) - { return data_; } - /// const version of \c data pointer - inline const Type* data(void) const - { return data_; } - // ---------------------------------------------------------------------- - /*! - Increase the number of elements the end of this vector. - - \param n - is the number of elements to add to end of this vector. - - \return - is the number of elements in the vector before \c extend was extended. - - - If \c Type is plain old data, new elements are not initialized; - i.e., their constructor is not called. Otherwise, the constructor - is called for each new element. - - - This is the only routine that allocates memory for \c pod_vector. - and it uses thread_alloc for this allocation, hence this determines - which thread corresponds to this vector (when in parallel mode). - - - If the resulting length of the vector would be more than \c max_length_, - and \c NDEBUG is not defined, a CPPAD_ASSERT is generated. - */ - inline size_t extend(size_t n) - { size_t old_length = length_; - length_ += n; - CPPAD_ASSERT_KNOWN( - length_ <= max_length_ , - "pod_vector.hpp: attempt to create to large a vector.\n" - "If Type is CPPAD_TYPE_ADDR_TYPE, tape is too long for Type." - ); - // check if we can use current memory - if( capacity_ >= length_ ) - return old_length; - - // save more old information - size_t old_capacity = capacity_; - Type* old_data = data_; - - // get new memory and set capacity - size_t length_bytes = length_ * sizeof(Type); - size_t capacity_bytes; - void* v_ptr = thread_alloc::get_memory(length_bytes, capacity_bytes); - capacity_ = capacity_bytes / sizeof(Type); - data_ = reinterpret_cast(v_ptr); - CPPAD_ASSERT_UNKNOWN( length_ <= capacity_ ); - - size_t i; - if( ! is_pod() ) - { // call constructor for each new element - for(i = 0; i < capacity_; i++) - new(data_ + i) Type(); - } - - // copy old data to new data - for(i = 0; i < old_length; i++) - data_[i] = old_data[i]; - - // return old memory to available pool - if( old_capacity > 0 ) - { v_ptr = reinterpret_cast( old_data ); - if( ! is_pod() ) - { for(i = 0; i < old_capacity; i++) - (old_data + i)->~Type(); - } - thread_alloc::return_memory(v_ptr); - } - - // return value for extend(n) is the old length - return old_length; - } - // ---------------------------------------------------------------------- - /// non-constant element access; i.e., we can change this element value - Type& operator[]( - /// element index, must be less than length - size_t i - ) - { CPPAD_ASSERT_UNKNOWN( i < length_ ); - return data_[i]; - } - // ---------------------------------------------------------------------- - /// constant element access; i.e., we cannot change this element value - const Type& operator[]( - /// element index, must be less than length - size_t i - ) const - { CPPAD_ASSERT_UNKNOWN( i < length_ ); - return data_[i]; - } - // ---------------------------------------------------------------------- - /*! - Remove all the elements from this vector but leave the capacity - and data pointer as is. - - */ - void erase(void) - { length_ = 0; - return; - } - // ---------------------------------------------------------------------- - /*! - Remove all the elements from this vector and delete its memory. - */ - void free(void) - { if( capacity_ > 0 ) - { void* v_ptr = reinterpret_cast( data_ ); - if( ! is_pod() ) - { // call destructor for each element - size_t i; - for(i = 0; i < capacity_; i++) - (data_ + i)->~Type(); - } - thread_alloc::return_memory(v_ptr); - } - data_ = CPPAD_NULL; - capacity_ = 0; - length_ = 0; - } - /// vector assignment operator - /// If the resulting length of the vector would be more than - /// \c max_length_, and \c NDEBUG is not defined, - /// a CPPAD_ASSERT is generated. - void operator=( - /// right hand size of the assingment operation - const pod_vector& x - ) - { size_t i; - - if( x.length_ <= capacity_ ) - { // use existing allocation for this vector - length_ = x.length_; - CPPAD_ASSERT_KNOWN( - length_ <= max_length_ , - "pod_vector.hpp: attempt to create to large a vector.\n" - "If Type is CPPAD_TYPE_ADDR_TYPE, tape long for Type." - ); - } - else - { // free old memory and get new memory of sufficient length - if( capacity_ > 0 ) - { void* v_ptr = reinterpret_cast( data_ ); - if( ! is_pod() ) - { // call destructor for each element - for(i = 0; i < capacity_; i++) - (data_ + i)->~Type(); - } - thread_alloc::return_memory(v_ptr); - } - length_ = capacity_ = 0; - extend( x.length_ ); - } - CPPAD_ASSERT_UNKNOWN( length_ == x.length_ ); - for(i = 0; i < length_; i++) - { data_[i] = x.data_[i]; } - } - /*! - Swap all properties of this vector with another. - - \param other - is the other vector that we are swapping this vector with. - */ - void swap(pod_vector& other) - { std::swap(capacity_, other.capacity_); - std::swap(length_, other.length_); - std::swap(data_, other.data_); - } -}; - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/pow_op.hpp b/external/cppad/include/cppad/local/pow_op.hpp deleted file mode 100644 index 993763b29..000000000 --- a/external/cppad/include/cppad/local/pow_op.hpp +++ /dev/null @@ -1,659 +0,0 @@ -# ifndef CPPAD_LOCAL_POW_OP_HPP -# define CPPAD_LOCAL_POW_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file pow_op.hpp -Forward and reverse mode calculations for z = pow(x, y). -*/ - -// --------------------------- Powvv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = PowvvOp. - -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_pow_op -*/ - -template -inline void forward_powvv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // 2 = NumRes(PowvvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // z_0 = log(x) - forward_log_op(p, q, i_z, arg[0], cap_order, taylor); - - // z_1 = z_0 * y - addr_t adr[2]; - adr[0] = addr_t( i_z ); - adr[1] = arg[1]; - forward_mulvv_op(p, q, i_z+1, adr, parameter, cap_order, taylor); - - // z_2 = exp(z_1) - // final result for zero order case is exactly the same as for Base - if( p == 0 ) - { // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z_2 = taylor + (i_z+2) * cap_order; - - z_2[0] = pow(x[0], y[0]); - p++; - } - if( p <= q ) - forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor); -} -/*! -Multiple directions forward mode Taylor coefficients for op = PowvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_pow_op_dir -*/ - -template -inline void forward_powvv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // 2 = NumRes(PowvvOp) - 1 - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // z_0 = log(x) - forward_log_op_dir(q, r, i_z, arg[0], cap_order, taylor); - - // z_1 = y * z_0 - addr_t adr[2]; - adr[0] = addr_t( i_z ); - adr[1] = arg[1]; - forward_mulvv_op_dir(q, r, i_z+1, adr, parameter, cap_order, taylor); - - // z_2 = exp(z_1) - forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor); -} -/*! -Compute zero order forward mode Taylor coefficients for result of op = PowvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_pow_op_0 -*/ - -template -inline void forward_powvv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // NumRes(PowvvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z_0 = taylor + i_z * cap_order; - Base* z_1 = z_0 + cap_order; - Base* z_2 = z_1 + cap_order; - - z_0[0] = log( x[0] ); - z_1[0] = z_0[0] * y[0]; - z_2[0] = pow(x[0], y[0]); - -} - -/*! -Compute reverse mode partial derivatives for result of op = PowvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::reverse_pow_op -*/ - -template -inline void reverse_powvv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // convert from final result to first result - i_z -= 2; // NumRes(PowvvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // z_2 = exp(z_1) - reverse_exp_op( - d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial - ); - - // z_1 = z_0 * y - addr_t adr[2]; - adr[0] = addr_t( i_z ); - adr[1] = arg[1]; - reverse_mulvv_op( - d, i_z+1, adr, parameter, cap_order, taylor, nc_partial, partial - ); - - // z_0 = log(x) - reverse_log_op( - d, i_z, arg[0], cap_order, taylor, nc_partial, partial - ); -} - -// --------------------------- Powpv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = PowpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_pow_op -*/ - -template -inline void forward_powpv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // 2 = NumRes(PowpvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* z_0 = taylor + i_z * cap_order; - - // z_0 = log(x) - Base x = parameter[ arg[0] ]; - size_t d; - for(d = p; d <= q; d++) - { if( d == 0 ) - z_0[d] = log(x); - else z_0[d] = Base(0.0); - } - - // 2DO: remove requirement that i_z * cap_order <= max addr_t value - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= i_z * cap_order, - "cppad_tape_addr_type maximum value has been exceeded\n" - "This is due to a kludge in the pow operation and should be fixed." - ); - - // z_1 = z_0 * y - addr_t adr[2]; - // offset of z_i in taylor (as if it were a parameter); i.e., log(x) - adr[0] = addr_t( i_z * cap_order ); - // offset of y in taylor (as a variable) - adr[1] = arg[1]; - - // Trick: use taylor both for the parameter vector and variable values - forward_mulpv_op(p, q, i_z+1, adr, taylor, cap_order, taylor); - - // z_2 = exp(z_1) - // zero order case exactly same as Base type operation - if( p == 0 ) - { Base* y = taylor + arg[1] * cap_order; - Base* z_2 = taylor + (i_z+2) * cap_order; - z_2[0] = pow(x, y[0]); - p++; - } - if( p <= q ) - forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor); -} -/*! -Multiple directions forward mode Taylor coefficients for op = PowpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_pow_op_dir -*/ - -template -inline void forward_powpv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // 2 = NumRes(PowpvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* z_0 = taylor + i_z * num_taylor_per_var; - - // z_0 = log(x) - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - z_0[m+ell] = Base(0.0); - - // 2DO: remove requirement i_z * num_taylor_per_var <= max addr_t value - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= i_z * num_taylor_per_var, - "cppad_tape_addr_type maximum value has been exceeded\n" - "This is due to a kludge in the pow operation and should be fixed." - ); - - // z_1 = z_0 * y - addr_t adr[2]; - // offset of z_0 in taylor (as if it were a parameter); i.e., log(x) - adr[0] = addr_t( i_z * num_taylor_per_var ); - // ofset of y in taylor (as a variable) - adr[1] = arg[1]; - - // Trick: use taylor both for the parameter vector and variable values - forward_mulpv_op_dir(q, r, i_z+1, adr, taylor, cap_order, taylor); - - // z_2 = exp(z_1) - forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor); -} -/*! -Compute zero order forward mode Taylor coefficient for result of op = PowpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_pow_op_0 -*/ - -template -inline void forward_powpv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // NumRes(PowpvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 ); - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z_0 = taylor + i_z * cap_order; - Base* z_1 = z_0 + cap_order; - Base* z_2 = z_1 + cap_order; - - // z_0 = log(x) - z_0[0] = log(x); - - // z_1 = z_0 * y - z_1[0] = z_0[0] * y[0]; - - // z_2 = exp(z_1) - // zero order case exactly same as Base type operation - z_2[0] = pow(x, y[0]); -} - -/*! -Compute reverse mode partial derivative for result of op = PowpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_pow_op -*/ - -template -inline void reverse_powpv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // convert from final result to first result - i_z -= 2; // NumRes(PowpvOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // z_2 = exp(z_1) - reverse_exp_op( - d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial - ); - - // 2DO: remove requirement that i_z * cap_order <= max addr_t value - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= i_z * cap_order, - "cppad_tape_addr_type maximum value has been exceeded\n" - "This is due to a kludge in the pow operation and should be fixed." - ); - - // z_1 = z_0 * y - addr_t adr[2]; - adr[0] = addr_t( i_z * cap_order ); // offset of z_0[0] in taylor - adr[1] = arg[1]; // index of y in taylor and partial - // use taylor both for parameter and variable values - reverse_mulpv_op( - d, i_z+1, adr, taylor, cap_order, taylor, nc_partial, partial - ); - - // z_0 = log(x) - // x is a parameter -} - -// --------------------------- Powvp ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = PowvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_pow_op -*/ - -template -inline void forward_powvp_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // 2 = NumRes(PowvpOp) - 1 - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // z_0 = log(x) - forward_log_op(p, q, i_z, arg[0], cap_order, taylor); - - // z_1 = y * z_0 - addr_t adr[2]; - adr[0] = arg[1]; - adr[1] = addr_t( i_z ); - forward_mulpv_op(p, q, i_z+1, adr, parameter, cap_order, taylor); - - // z_2 = exp(z_1) - // zero order case exactly same as Base type operation - if( p == 0 ) - { Base* z_2 = taylor + (i_z+2) * cap_order; - Base* x = taylor + arg[0] * cap_order; - Base y = parameter[ arg[1] ]; - z_2[0] = pow(x[0], y); - p++; - } - if( p <= q ) - forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor); -} -/*! -Multiple directions forward mode Taylor coefficients for op = PowvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_pow_op_dir -*/ - -template -inline void forward_powvp_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // 2 = NumRes(PowvpOp) - 1 - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // z_0 = log(x) - forward_log_op_dir(q, r, i_z, arg[0], cap_order, taylor); - - // z_1 = y * z_0 - addr_t adr[2]; - adr[0] = arg[1]; - adr[1] = addr_t( i_z ); - forward_mulpv_op_dir(q, r, i_z+1, adr, parameter, cap_order, taylor); - - // z_2 = exp(z_1) - forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor); -} - -/*! -Compute zero order forward mode Taylor coefficients for result of op = PowvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_pow_op_0 -*/ - -template -inline void forward_powvp_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // convert from final result to first result - i_z -= 2; // NumRes(PowvpOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 ); - - // Paraemter value - Base y = parameter[ arg[1] ]; - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z_0 = taylor + i_z * cap_order; - Base* z_1 = z_0 + cap_order; - Base* z_2 = z_1 + cap_order; - - // z_0 = log(x) - z_0[0] = log(x[0]); - - // z_1 = z_0 * y - z_1[0] = z_0[0] * y; - - // z_2 = exp(z_1) - // zero order case exactly same as Base type operation - z_2[0] = pow(x[0], y); -} - -/*! -Compute reverse mode partial derivative for result of op = PowvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = pow(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::reverse_pow_op -*/ - -template -inline void reverse_powvp_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // convert from final result to first result - i_z -= 2; // NumRes(PowvpOp) - 1; - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= i_z ); - - // z_2 = exp(z_1) - reverse_exp_op( - d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial - ); - - // z_1 = y * z_0 - addr_t adr[2]; - adr[0] = arg[1]; - adr[1] = addr_t( i_z ); - reverse_mulpv_op( - d, i_z+1, adr, parameter, cap_order, taylor, nc_partial, partial - ); - - // z_0 = log(x) - reverse_log_op( - d, i_z, arg[0], cap_order, taylor, nc_partial, partial - ); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/print_op.hpp b/external/cppad/include/cppad/local/print_op.hpp deleted file mode 100644 index d31040087..000000000 --- a/external/cppad/include/cppad/local/print_op.hpp +++ /dev/null @@ -1,148 +0,0 @@ -// $Id: print_op.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_PRINT_OP_HPP -# define CPPAD_LOCAL_PRINT_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -Print operation for parameters; i.e., op = PriOp. - -The C++ source code corresponding to this operation is -\verbatim - f.Forward(0, x) - PrintFor(before, var) - PrintFor(pos, before, var, after) -\endverbatim -The PrintFor call puts the print operation on the tape -and the print occurs during the zero order forward mode computation. - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param s_out -the results are printed on this output stream. - -\param arg -\a arg[0] & 1 -\n -If this is zero, \a pos is a parameter. Otherwise it is a variable. -\n -\a arg[0] & 2 -\n -If this is zero, \a var is a parameter. Otherwise it is a variable. -\n -\n -\a arg[1] -\n -If \a pos is a parameter, parameter[arg[1]] is its value. -Othwise taylor[ arg[1] * cap_order + 0 ] is the zero -order Taylor coefficient for \a pos. -\n -\n -\a arg[2] -\n -index of the text to be printed before \a var -if \a pos is not a positive value. -\n -\n -\a arg[3] -\n -If \a var is a parameter, parameter[arg[3]] is its value. -Othwise taylor[ arg[3] * cap_order + 0 ] is the zero -order Taylor coefficient for \a var. -\n -\n -\a arg[4] -\n -index of the text to be printed after \a var -if \a pos is not a positive value. - -\param num_text -is the total number of text characters on the tape -(only used for error checking). - -\param text -\b Input: text[arg[1]] is the first character of the text -that will be printed. All the characters from there to (but not including) -the first '\\0' are printed. - -\param num_par -is the total number of values in the \a parameter vector - -\param parameter -Contains the value of parameters. - -\param cap_order -number of colums in the matrix containing all the Taylor coefficients. - -\param taylor -Contains the value of variables. - -\par Checked Assertions: -\li NumArg(PriOp) == 5 -\li NumRes(PriOp) == 0 -\li text != CPPAD_NULL -\li arg[1] < num_text -\li if \a pos is a parameter, arg[1] < num_par -\li if \a var is a parameter, arg[3] < num_par -*/ -template -inline void forward_pri_0( - std::ostream& s_out , - const addr_t* arg , - size_t num_text , - const char* text , - size_t num_par , - const Base* parameter , - size_t cap_order , - const Base* taylor ) -{ Base pos, var; - const char* before; - const char* after; - CPPAD_ASSERT_NARG_NRES(PriOp, 5, 0); - - // pos - if( arg[0] & 1 ) - { pos = taylor[ arg[1] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - pos = parameter[ arg[1] ]; - } - - // before - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text ); - before = text + arg[2]; - - // var - if( arg[0] & 2 ) - { var = taylor[ arg[3] * cap_order + 0 ]; - } - else - { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); - var = parameter[ arg[3] ]; - } - - // after - CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text ); - after = text + arg[4]; - - if( ! GreaterThanZero( pos ) ) - s_out << before << var << after; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/prototype_op.hpp b/external/cppad/include/cppad/local/prototype_op.hpp deleted file mode 100644 index 11b734325..000000000 --- a/external/cppad/include/cppad/local/prototype_op.hpp +++ /dev/null @@ -1,1459 +0,0 @@ -// $Id: prototype_op.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_PROTOTYPE_OP_HPP -# define CPPAD_LOCAL_PROTOTYPE_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file prototype_op.hpp -Documentation for generic cases (these generic cases are never used). -*/ - -// ==================== Unary operators with one result ==================== - - -/*! -Prototype for forward mode unary operator with one result (not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param p -lowest order of the Taylor coefficient that we are computing. - -\param q -highest order of the Taylor coefficient that we are computing. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: taylor [ i_x * cap_order + k ], -for k = 0 , ... , q, -is the k-th order Taylor coefficient corresponding to x. -\n -\b Input: taylor [ i_z * cap_order + k ], -for k = 0 , ... , p-1, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Output: taylor [ i_z * cap_order + k ], -for k = p , ... , q, -is the k-th order Taylor coefficient corresponding to z. - -\par Checked Assertions -\li NumArg(op) == 1 -\li NumRes(op) == 1 -\li q < cap_order -\li p <= q -*/ -template -inline void forward_unary1_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for multiple direction forward mode unary operator with one result -(not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param q -order of the Taylor coefficients that we are computing. - -\param r -number of directions for Taylor coefficients that we are computing. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: If x is a variable, -taylor [ arg[0] * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to x and the ell-th direction. -\n -\b Input: taylor [ i_z * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ i_z * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q-1, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to z and the ell-th direction. -\n -\b Output: -taylor [ i_z * tpv + (q-1)*r + ell + 1], -ell = 0, ..., r-1, -is the q-th order Taylor coefficient -corresponding to z and the ell-th direction. - -\par Checked Assertions -\li NumArg(op) == 1 -\li NumRes(op) == 2 -\li i_x < i_z -\li 0 < q -\li q < cap_order -*/ -template -inline void forward_unary1_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for zero order forward mode unary operator with one result (not used). -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: \a taylor [ \a i_x * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to x. -\n -\b Output: \a taylor [ \a i_z * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z. - -\par Checked Assertions -\li NumArg(op) == 1 -\li NumRes(op) == 1 -\li \a i_x < \a i_z -\li \a 0 < \a cap_order -*/ -template -inline void forward_unary1_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for reverse mode unary operator with one result (not used). - -This routine is given the partial derivatives of a function -G(z , x , w, u ... ) -and it uses them to compute the partial derivatives of -\verbatim - H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ] -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param d -highest order Taylor coefficient that -we are computing the partial derivatives with respect to. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor to z. - -\param i_x -variable index corresponding to the argument for this operation; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\a taylor [ \a i_x * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to x. -\n -\a taylor [ \a i_z * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to z. - -\param nc_partial -number of colums in the matrix containing all the partial derivatives. - -\param partial -\b Input: \a partial [ \a i_x * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Input: \a partial [ \a i_z * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for z. -\n -\b Output: \a partial [ \a i_x * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of H( x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Output: \a partial [ \a i_z * \a nc_partial + k ] -for k = 0 , ... , \a d -may be used as work space; i.e., may change in an unspecified manner. - - -\par Checked Assumptions -\li NumArg(op) == 1 -\li NumRes(op) == 1 -\li \a i_x < \a i_z -\li \a d < \a cap_order -\li \a d < \a nc_partial -*/ -template -inline void reverse_unary1_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -// ==================== Unary operators with two results ==================== - -/*! -Prototype for forward mode unary operator with two results (not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param p -lowest order of the Taylor coefficients that we are computing. - -\param q -highest order of the Taylor coefficients that we are computing. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary result is called y has index \a i_z - 1. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: taylor [ i_x * cap_order + k ] -for k = 0 , ... , q, -is the k-th order Taylor coefficient corresponding to x. -\n -\b Input: taylor [ i_z * cap_order + k ] -for k = 0 , ... , p - 1, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Input: taylor [ ( i_z - 1) * cap_order + k ] -for k = 0 , ... , p-1, -is the k-th order Taylor coefficient corresponding to the auxillary result y. -\n -\b Output: taylor [ i_z * cap_order + k ], -for k = p , ... , q, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Output: taylor [ ( i_z - 1 ) * cap_order + k ], -for k = p , ... , q, -is the k-th order Taylor coefficient corresponding to -the autillary result y. - -\par Checked Assertions -\li NumArg(op) == 1 -\li NumRes(op) == 2 -\li i_x + 1 < i_z -\li q < cap_order -\li p <= q -*/ -template -inline void forward_unary2_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for multiple direction forward mode unary operator with two results -(not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param q -order of the Taylor coefficients that we are computing. - -\param r -number of directions for Taylor coefficients that we are computing. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary result is called y has index \a i_z - 1. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: taylor [ i_x * tpv + 0 ] -is the zero order Taylor coefficient for all directions and -taylor [ i_x * tpv + (k-1)*r + ell + 1 -for k = 1 , ... , q, -ell = 0 , ..., r-1, -is the k-th order Taylor coefficient -corresponding to x and the ell-th direction. -\n -\b Input: taylor [ i_z * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ i_z * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q-1, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to z and the ell-th direction. -\n -\b Input: taylor [ (i_z-1) * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ (i_z-1) * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q-1, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to the auxillary result y and the ell-th direction. -\n -\b Output: -taylor [ i_z * tpv + (q-1)*r + ell + 1], -ell = 0, ..., r-1, -is the q-th order Taylor coefficient -corresponding to z and the ell-th direction. - -\par Checked Assertions -\li NumArg(op) == 1 -\li NumRes(op) == 2 -\li i_x + 1 < i_z -\li 0 < q -\li q < cap_order -*/ -template -inline void forward_unary2_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for zero order forward mode unary operator with two results (not used). -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -The auxillary result is called y and has index \a i_z - 1. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: \a taylor [ \a i_x * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to x. -\n -\b Output: \a taylor [ \a i_z * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z. -\n -\b Output: \a taylor [ ( \a i_z - 1 ) * \a cap_order + j ] -is the j-th order Taylor coefficient corresponding to -the autillary result y. - -\par Checked Assertions -\li NumArg(op) == 1 -\li NumRes(op) == 2 -\li \a i_x + 1 < \a i_z -\li \a j < \a cap_order -*/ -template -inline void forward_unary2_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for reverse mode unary operator with two results (not used). - -This routine is given the partial derivatives of a function -G( z , y , x , w , ... ) -and it uses them to compute the partial derivatives of -\verbatim - H( x , w , u , ... ) = G[ z(x) , y(x), x , w , u , ... ] -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param d -highest order Taylor coefficient that -we are computing the partial derivatives with respect to. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor to z. -The auxillary result is called y and has index \a i_z - 1. - -\param i_x -variable index corresponding to the argument for this operation; -i.e. the row index in \a taylor corresponding to x. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\a taylor [ \a i_x * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to x. -\n -\a taylor [ \a i_z * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to z. -\n -\a taylor [ ( \a i_z - 1) * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to -the auxillary variable y. - -\param nc_partial -number of colums in the matrix containing all the partial derivatives. - -\param partial -\b Input: \a partial [ \a i_x * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of -G( z , y , x , w , u , ... ) -with respect to the k-th order Taylor coefficient for x. -\n -\b Input: \a partial [ \a i_z * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for z. -\n -\b Input: \a partial [ ( \a i_z - 1) * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for the auxillary variable y. -\n -\b Output: \a partial [ \a i_x * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of H( x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Output: \a partial [ \a ( i_z - j ) * \a nc_partial + k ] -for j = 0 , 1 , and for k = 0 , ... , \a d -may be used as work space; i.e., may change in an unspecified manner. - - -\par Checked Assumptions -\li NumArg(op) == 1 -\li NumRes(op) == 2 -\li \a i_x + 1 < \a i_z -\li \a d < \a cap_order -\li \a d < \a nc_partial -*/ -template -inline void reverse_unary2_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -// =================== Binary operators with one result ==================== - -/*! -Prototype forward mode x op y (not used) - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param p -lowest order of the Taylor coefficient that we are computing. - -\param q -highest order of the Taylor coefficient that we are computing. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: If x is a variable, -taylor [ arg[0] * cap_order + k ], -for k = 0 , ... , q, -is the k-th order Taylor coefficient corresponding to x. -\n -\b Input: If y is a variable, -taylor [ arg[1] * cap_order + k ], -for k = 0 , ... , q, -is the k-th order Taylor coefficient corresponding to y. -\n -\b Input: taylor [ i_z * cap_order + k ], -for k = 0 , ... , p-1, -is the k-th order Taylor coefficient corresponding to z. -\n -\b Output: taylor [ i_z * cap_order + k ], -for k = p, ... , q, -is the k-th order Taylor coefficient corresponding to z. - -\par Checked Assertions -\li NumArg(op) == 2 -\li NumRes(op) == 1 -\li q < cap_order -\li p <= q -*/ -template -inline void forward_binary_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype multiple direction forward mode x op y (not used) - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param q -is the order of the Taylor coefficients that we are computing. - -\param r -number of directions for Taylor coefficients that we are computing - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: If x is a variable, -taylor [ arg[0] * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to x and the ell-th direction. -\n -\b Input: If y is a variable, -taylor [ arg[1] * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ arg[1] * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to y and the ell-th direction. -\n -\b Input: taylor [ i_z * tpv + 0 ], -is the zero order Taylor coefficient for all directions and -taylor [ i_z * tpv + (k-1)*r + ell + 1 ], -for k = 1 , ... , q-1, -ell = 0, ..., r-1, -is the k-th order Taylor coefficient -corresponding to z and the ell-th direction. -\n -\b Output: -taylor [ i_z * tpv + (q-1)*r + ell + 1], -ell = 0, ..., r-1, -is the q-th order Taylor coefficient -corresponding to z and the ell-th direction. - -\par Checked Assertions -\li NumArg(op) == 2 -\li NumRes(op) == 1 -\li 0 < q < cap_order -*/ -template -inline void forward_binary_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - - -/*! -Prototype zero order forward mode x op y (not used) - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: If x is a variable, \a taylor [ \a arg[0] * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to x. -\n -\b Input: If y is a variable, \a taylor [ \a arg[1] * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to y. -\n -\b Output: \a taylor [ \a i_z * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z. - -\par Checked Assertions -\li NumArg(op) == 2 -\li NumRes(op) == 1 -*/ -template -inline void forward_binary_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for reverse mode binary operator x op y (not used). - -This routine is given the partial derivatives of a function -G( z , y , x , w , ... ) -and it uses them to compute the partial derivatives of -\verbatim - H( y , x , w , u , ... ) = G[ z(x , y) , y , x , w , u , ... ] -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param d -highest order Taylor coefficient that -we are computing the partial derivatives with respect to. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in \a taylor corresponding to z. - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\a taylor [ \a i_z * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to z. -\n -If x is a variable, \a taylor [ \a arg[0] * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to x. -\n -If y is a variable, \a taylor [ \a arg[1] * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to y. - -\param nc_partial -number of colums in the matrix containing all the partial derivatives. - -\param partial -\b Input: \a partial [ \a i_z * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of -G( z , y , x , w , u , ... ) -with respect to the k-th order Taylor coefficient for z. -\n -\b Input: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Input: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for the auxillary variable y. -\n -\b Output: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of H( y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Output: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of H( y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for y. -\n -\b Output: \a partial [ \a i_z * \a nc_partial + k ] -for k = 0 , ... , \a d -may be used as work space; i.e., may change in an unspecified manner. - -\par Checked Assumptions -\li NumArg(op) == 2 -\li NumRes(op) == 1 -\li \a If x is a variable, arg[0] < \a i_z -\li \a If y is a variable, arg[1] < \a i_z -\li \a d < \a cap_order -\li \a d < \a nc_partial -*/ -template -inline void reverse_binary_op( - size_t d , - size_t i_z , - addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -// ======================= Pow Function =================================== -/*! -Prototype for forward mode z = pow(x, y) (not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param p -lowest order of the Taylor coefficient that we are computing. - -\param q -highest order of the Taylor coefficient that we are computing. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -Note that there are three results for this operation, -below they are referred to as z_0, z_1, z_2 and correspond to -\verbatim - z_0 = log(x) - z_1 = z0 * y - z_2 = exp(z1) -\endverbatim -It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y). - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: If x is a variable, -taylor [ arg[0] * cap_order + k ] -for k = 0 , ... , q, -is the k-th order Taylor coefficient corresponding to x. -\n -\b Input: If y is a variable, -taylor [ arg[1] * cap_order + k ] -for k = 0 , ... , q -is the k-th order Taylor coefficient corresponding to y. -\n -\b Input: taylor [ (i_z-2+j) * cap_order + k ], -for j = 0, 1, 2 , for k = 0 , ... , p-1, -is the k-th order Taylor coefficient corresponding to z_j. -\n -\b Output: taylor [ (i_z-2+j) * cap_order + k ], -is the k-th order Taylor coefficient corresponding to z_j. - -\par Checked Assertions -\li NumArg(op) == 2 -\li NumRes(op) == 3 -\li If x is a variable, arg[0] < i_z - 2 -\li If y is a variable, arg[1] < i_z - 2 -\li q < cap_order -\li p <= q -*/ -template -inline void forward_pow_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -/*! -Prototype for multiple direction forward mode z = pow(x, y) (not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param q -order of the Taylor coefficient that we are computing. - -\param r -is the number of Taylor coefficient directions that we are computing - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -Note that there are three results for this operation, -below they are referred to as z_0, z_1, z_2 and correspond to -\verbatim - z_0 = log(x) - z_1 = z0 * y - z_2 = exp(z1) -\endverbatim -It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y). - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\par tpv -We use the notation -tpv = (cap_order-1) * r + 1 -which is the number of Taylor coefficients per variable - -\param taylor -\b Input: If x is a variable, -taylor [ arg[0] * tpv + 0 ] -is the zero order coefficient corresponding to x and -taylor [ arg[0] * tpv + (k-1)*r+1+ell ] -for k = 1 , ... , q, -ell = 0 , ... , r-1, -is the k-th order Taylor coefficient corresponding to x -for the ell-th direction. -\n -\n -\b Input: If y is a variable, -taylor [ arg[1] * tpv + 0 ] -is the zero order coefficient corresponding to y and -taylor [ arg[1] * tpv + (k-1)*r+1+ell ] -for k = 1 , ... , q, -ell = 0 , ... , r-1, -is the k-th order Taylor coefficient corresponding to y -for the ell-th direction. -\n -\n -\b Input: -taylor [ (i_z-2+j) * tpv + 0 ], -is the zero order coefficient corresponding to z_j and -taylor [ (i_z-2+j) * tpv + (k-1)*r+1+ell ], -for j = 0, 1, 2 , k = 0 , ... , q-1, ell = 0, ... , r-1, -is the k-th order Taylor coefficient corresponding to z_j -for the ell-th direction. -\n -\n -\b Output: -taylor [ (i_z-2+j) * tpv + (q-1)*r+1+ell ], -for j = 0, 1, 2 , ell = 0, ... , r-1, -is the q-th order Taylor coefficient corresponding to z_j -for the ell-th direction. - -\par Checked Assertions -\li NumArg(op) == 2 -\li NumRes(op) == 3 -\li If x is a variable, arg[0] < i_z - 2 -\li If y is a variable, arg[1] < i_z - 2 -\li 0 < q -\li q < cap_order -*/ -template -inline void forward_pow_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -/*! -Prototype for zero order forward mode z = pow(x, y) (not used). - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -Note that there are three results for this operation, -below they are referred to as z_0, z_1, z_2 and correspond to -\verbatim - z_0 = log(x) - z_1 = z0 * y - z_2 = exp(z1) -\endverbatim -It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y). - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\b Input: If x is a variable, \a taylor [ \a arg[0] * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to x. -\n -\b Input: If y is a variable, \a taylor [ \a arg[1] * \a cap_order + 0 ] -is the k-th order Taylor coefficient corresponding to y. -\n -\b Output: \a taylor [ \a (i_z - 2 + j) * \a cap_order + 0 ] -is the zero order Taylor coefficient corresponding to z_j. - -\par Checked Assertions -\li NumArg(op) == 2 -\li NumRes(op) == 3 -\li If x is a variable, \a arg[0] < \a i_z - 2 -\li If y is a variable, \a arg[1] < \a i_z - 2 -*/ -template -inline void forward_pow_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -/*! -Prototype for reverse mode z = pow(x, y) (not used). - -This routine is given the partial derivatives of a function -G( z , y , x , w , ... ) -and it uses them to compute the partial derivatives of -\verbatim - H( y , x , w , u , ... ) = G[ pow(x , y) , y , x , w , u , ... ] -\endverbatim - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base . - -\param d -highest order Taylor coefficient that -we are computing the partial derivatives with respect to. - -\param i_z -variable index corresponding to the last (primary) result for this operation; -i.e. the row index in \a taylor corresponding to z. -Note that there are three results for this operation, -below they are referred to as z_0, z_1, z_2 and correspond to -\verbatim - z_0 = log(x) - z_1 = z0 * y - z_2 = exp(z1) -\endverbatim -It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y). - -\param arg -\a arg[0] -index corresponding to the left operand for this operator; -i.e. the index corresponding to x. -\n -\a arg[1] -index corresponding to the right operand for this operator; -i.e. the index corresponding to y. - -\param parameter -If x is a parameter, \a parameter [ \a arg[0] ] -is the value corresponding to x. -\n -If y is a parameter, \a parameter [ \a arg[1] ] -is the value corresponding to y. - -\param cap_order -maximum number of orders that will fit in the \c taylor array. - -\param taylor -\a taylor [ \a (i_z - 2 + j) * \a cap_order + k ] -for j = 0, 1, 2 and k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to z_j. -\n -If x is a variable, \a taylor [ \a arg[0] * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to x. -\n -If y is a variable, \a taylor [ \a arg[1] * \a cap_order + k ] -for k = 0 , ... , \a d -is the k-th order Taylor coefficient corresponding to y. - -\param nc_partial -number of colums in the matrix containing all the partial derivatives. - -\param partial -\b Input: \a partial [ \a (i_z - 2 + j) * \a nc_partial + k ] -for j = 0, 1, 2, and k = 0 , ... , \a d -is the partial derivative of -G( z , y , x , w , u , ... ) -with respect to the k-th order Taylor coefficient for z_j. -\n -\b Input: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Input: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of G( z , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for the auxillary variable y. -\n -\b Output: If x is a variable, \a partial [ \a arg[0] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of H( y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for x. -\n -\b Output: If y is a variable, \a partial [ \a arg[1] * \a nc_partial + k ] -for k = 0 , ... , \a d -is the partial derivative of H( y , x , w , u , ... ) with respect to -the k-th order Taylor coefficient for y. -\n -\b Output: \a partial [ \a ( i_z - j ) * \a nc_partial + k ] -for j = 0 , 1 , 2 and for k = 0 , ... , \a d -may be used as work space; i.e., may change in an unspecified manner. - -\par Checked Assumptions -\li NumArg(op) == 2 -\li NumRes(op) == 3 -\li \a If x is a variable, arg[0] < \a i_z - 2 -\li \a If y is a variable, arg[1] < \a i_z - 2 -\li \a d < \a cap_order -\li \a d < \a nc_partial -*/ -template -inline void reverse_pow_op( - size_t d , - size_t i_z , - addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -// ==================== Sparsity Calculations ============================== -/*! -Prototype for reverse mode Hessian sparsity unary operators. - -This routine is given the forward mode Jacobian sparsity patterns for x. -It is also given the reverse mode dependence of G on z. -In addition, it is given the revese mode Hessian sparsity -for the quanity of interest G(z , y , ... ) -and it uses them to compute the sparsity patterns for -\verbatim - H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ] -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in sparsity corresponding to z. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in sparsity corresponding to x. - -\param rev_jacobian -\a rev_jacobian[i_z] -is all false (true) if the Jacobian of G with respect to z must be zero -(may be non-zero). -\n -\n -\a rev_jacobian[i_x] -is all false (true) if the Jacobian with respect to x must be zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. - -\param for_jac_sparsity -The set with index \a i_x in for_jac_sparsity -is the forward mode Jacobian sparsity pattern for the variable x. - -\param rev_hes_sparsity -The set with index \a i_z in in \a rev_hes_sparsity -is the Hessian sparsity pattern for the fucntion G -where one of the partials derivative is with respect to z. -\n -\n -The set with index \a i_x in \a rev_hes_sparsity -is the Hessian sparsity pattern -where one of the partials derivative is with respect to x. -On input, it corresponds to the function G, -and on output it corresponds to the function H. - -\par Checked Assertions: -\li \a i_x < \a i_z -*/ - -template -inline void reverse_sparse_hessian_unary_op( - size_t i_z , - size_t i_x , - bool* rev_jacobian , - Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - -/*! -Prototype for reverse mode Hessian sparsity binary operators. - -This routine is given the sparsity patterns the Hessian -of a function G(z, y, x, ... ) -and it uses them to compute the sparsity patterns for the Hessian of -\verbatim - H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ] -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in sparsity corresponding to z. - -\param arg -\a arg[0] -variable index corresponding to the left operand for this operator; -i.e. the set with index \a arg[0] in \a var_sparsity -is the spasity pattern correspoding to x. -\n -\n arg[1] -variable index corresponding to the right operand for this operator; -i.e. the row index in sparsity patterns corresponding to y. - -\param jac_reverse -\a jac_reverse[i_z] -is false (true) if the Jacobian of G with respect to z is always zero -(may be non-zero). -\n -\n -\a jac_reverse[ \a arg[0] ] -is false (true) if the Jacobian with respect to x is always zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. -\n -\n -\a jac_reverse[ \a arg[1] ] -is false (true) if the Jacobian with respect to y is always zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. - -\param for_jac_sparsity -The set with index \a arg[0] in \a for_jac_sparsity for the -is the forward Jacobian sparsity pattern for x. -\n -\n -The set with index \a arg[1] in \a for_jac_sparsity -is the forward sparsity pattern for y. - -\param rev_hes_sparsity -The set wiht index \a i_x in \a rev_hes_sparsity -is the Hessian sparsity pattern for the function G -where one of the partial derivatives is with respect to z. -\n -\n -The set with index \a arg[0] in \a rev_hes_sparsity -is the Hessian sparsity pattern where one of the -partial derivatives is with respect to x. -On input, it corresponds to the function G, -and on output it correspondst to H. -\n -\n -The set with index \a arg[1] in \a rev_hes_sparsity -is the Hessian sparsity pattern where one of the -partial derivatives is with respect to y. -On input, it corresponds to the function G, -and on output it correspondst to H. - -\par Checked Assertions: -\li \a arg[0] < \a i_z -\li \a arg[1] < \a i_z -*/ -template -inline void reverse_sparse_hessian_binary_op( - size_t i_z , - const addr_t* arg , - bool* jac_reverse , - Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/recorder.hpp b/external/cppad/include/cppad/local/recorder.hpp deleted file mode 100644 index 3e6465061..000000000 --- a/external/cppad/include/cppad/local/recorder.hpp +++ /dev/null @@ -1,618 +0,0 @@ -# ifndef CPPAD_LOCAL_RECORDER_HPP -# define CPPAD_LOCAL_RECORDER_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file recorder.hpp -File used to define the recorder class. -*/ - -/*! -Class used to store an operation sequence while it is being recorded -(the operation sequence is copied to the player class for playback). - -\tparam Base -This is an AD< \a Base > operation sequence recording; i.e., -it records operations of type AD< \a Base >. -*/ -template -class recorder { - friend class player; - -private: - /// operator index at which to abort recording with an error - /// (do not abort when zero) - size_t abort_op_index_; - - /// offset for this thread in the static hash table - const size_t thread_offset_; - - /// Number of variables in the recording. - size_t num_var_rec_; - - /// Number vecad load operations (LdpOp or LdvOp) currently in recording. - size_t num_load_op_rec_; - - /// The operators in the recording. - pod_vector op_rec_; - - /// The VecAD indices in the recording. - pod_vector vecad_ind_rec_; - - /// The argument indices in the recording - pod_vector op_arg_rec_; - - /// The parameters in the recording. - /// Note that Base may not be plain old data, so use false in consructor. - pod_vector par_rec_; - - /// Character strings ('\\0' terminated) in the recording. - pod_vector text_rec_; -// ---------------------- Public Functions ----------------------------------- -public: - /// Default constructor - recorder(void) : - thread_offset_( thread_alloc::thread_num() * CPPAD_HASH_TABLE_SIZE ) , - num_var_rec_(0) , - num_load_op_rec_(0) , - op_rec_( std::numeric_limits::max() ) , - vecad_ind_rec_( std::numeric_limits::max() ) , - op_arg_rec_( std::numeric_limits::max() ) , - par_rec_( std::numeric_limits::max() ) , - text_rec_( std::numeric_limits::max() ) - { - abort_op_index_ = 0; - } - - /// Set the abort index - void set_abort_op_index(size_t abort_op_index) - { abort_op_index_ = abort_op_index; } - - /// Get the abort index - size_t get_abort_op_index(void) - { return abort_op_index_; } - - /// Destructor - ~recorder(void) - { } - - /*! - Frees all information in recording. - - Frees the operation sequence store in this recording - (the operation sequence is empty after this operation). - The buffers used to store the current recording are returned - to the system (so as to conserve on memory). - */ - void free(void) - { num_var_rec_ = 0; - num_load_op_rec_ = 0; - op_rec_.free(); - vecad_ind_rec_.free(); - op_arg_rec_.free(); - par_rec_.free(); - text_rec_.free(); - } - /// Put next operator in the operation sequence. - inline addr_t PutOp(OpCode op); - /// Put a vecad load operator in the operation sequence (special case) - inline addr_t PutLoadOp(OpCode op); - /// Add a value to the end of the current vector of VecAD indices. - inline addr_t PutVecInd(size_t vec_ind); - /// Find or add a parameter to the current vector of parameters. - inline addr_t PutPar(const Base &par); - /// Put one operation argument index in the recording - inline void PutArg(addr_t arg0); - /// Put two operation argument index in the recording - inline void PutArg(addr_t arg0, addr_t arg1); - /// Put three operation argument index in the recording - inline void PutArg(addr_t arg0, addr_t arg1, addr_t arg2); - /// Put four operation argument index in the recording - inline void PutArg(addr_t arg0, addr_t arg1, addr_t arg2, addr_t arg3); - /// Put five operation argument index in the recording - inline void PutArg(addr_t arg0, addr_t arg1, addr_t arg2, addr_t arg3, - addr_t arg4); - /// Put six operation argument index in the recording - inline void PutArg(addr_t arg0, addr_t arg1, addr_t arg2, addr_t arg3, - addr_t arg4, addr_t arg5); - - // Reserve space for a specified number of arguments - inline size_t ReserveArg(size_t n_arg); - - // Replace an argument value - void ReplaceArg(size_t i_arg, size_t value); - - /// Put a character string in the text for this recording. - inline addr_t PutTxt(const char *text); - - /// Number of variables currently stored in the recording. - size_t num_var_rec(void) const - { return num_var_rec_; } - - /// Number of LdpOp and LdvOp operations currently in the recording. - size_t num_load_op_rec(void) const - { return num_load_op_rec_; } - - /// Number of operators currently stored in the recording. - size_t num_op_rec(void) const - { return op_rec_.size(); } - - /// Approximate amount of memory used by the recording - size_t Memory(void) const - { return op_rec_.capacity() * sizeof(CPPAD_OP_CODE_TYPE) - + vecad_ind_rec_.capacity() * sizeof(size_t) - + op_arg_rec_.capacity() * sizeof(addr_t) - + par_rec_.capacity() * sizeof(Base) - + text_rec_.capacity() * sizeof(char); - } -}; - -/*! -Put next operator in the operation sequence. - -This sets the op code for the next operation in this recording. -This call must be followed by putting the corresponding -\verbatim - NumArg(op) -\endverbatim -argument indices in the recording. - -\param op -Is the op code corresponding to the the operation that is being -recorded (which must not be LdpOp or LdvOp). - -\return -The return value is the index of the primary (last) variable -corresponding to the result of this operation. -The number of variables corresponding to the operation is given by -\verbatim - NumRes(op) -\endverbatim -With each call to PutOp or PutLoadOp, -the return index increases by the number of variables corresponding -to the call. -This index starts at zero after the default constructor -and after each call to Erase. -*/ -template -inline addr_t recorder::PutOp(OpCode op) -{ size_t i = op_rec_.extend(1); - CPPAD_ASSERT_KNOWN( - (abort_op_index_ == 0) || (abort_op_index_ != i), - "Operator index equals abort_op_index in Independent" - ); - op_rec_[i] = static_cast(op); - CPPAD_ASSERT_UNKNOWN( op_rec_.size() == i + 1 ); - CPPAD_ASSERT_UNKNOWN( (op != LdpOp) & (op != LdvOp) ); - - // first operator should be a BeginOp and NumRes( BeginOp ) > 0 - num_var_rec_ += NumRes(op); - CPPAD_ASSERT_UNKNOWN( num_var_rec_ > 0 ); - - // index of last variable corresponding to this operation - // (if NumRes(op) > 0) - CPPAD_ASSERT_KNOWN( - (size_t) std::numeric_limits::max() >= num_var_rec_ - 1, - "cppad_tape_addr_type maximum value has been exceeded" - ) - - return static_cast( num_var_rec_ - 1 ); -} - -/*! -Put next LdpOp or LdvOp operator in operation sequence (special cases). - -This sets the op code for the next operation in this recording. -This call must be followed by putting the corresponding -\verbatim - NumArg(op) -\endverbatim -argument indices in the recording. - -\param op -Is the op code corresponding to the the operation that is being -recorded (which must be LdpOp or LdvOp). - -\return -The return value is the index of the primary (last) variable -corresponding to the result of this operation. -The number of variables corresponding to the operation is given by -\verbatim - NumRes(op) -\endverbatim -which must be one for this operation. -With each call to PutLoadOp or PutOp, -the return index increases by the number of variables corresponding -to this call to the call. -This index starts at zero after the default constructor -and after each call to Erase. - -\par num_load_op_rec() -The return value for num_load_op_rec() -increases by one after each call to this function -(and starts at zero after the default constructor or Erase). -*/ -template -inline addr_t recorder::PutLoadOp(OpCode op) -{ size_t i = op_rec_.extend(1); - CPPAD_ASSERT_KNOWN( - (abort_op_index_ == 0) || (abort_op_index_ != i), - "This is the abort operator index specified by " - "Independent(x, abort_op_index)." - ); - op_rec_[i] = static_cast(op); - CPPAD_ASSERT_UNKNOWN( op_rec_.size() == i + 1 ); - CPPAD_ASSERT_UNKNOWN( (op == LdpOp) | (op == LdvOp) ); - - // first operator should be a BeginOp and NumRes( BeginOp ) > 0 - num_var_rec_ += NumRes(op); - CPPAD_ASSERT_UNKNOWN( num_var_rec_ > 0 ); - - // count this vecad load operation - num_load_op_rec_++; - - // index of last variable corresponding to this operation - // (if NumRes(op) > 0) - CPPAD_ASSERT_KNOWN( - (size_t) std::numeric_limits::max() >= num_var_rec_ - 1, - "cppad_tape_addr_type maximum value has been exceeded" - ) - return static_cast( num_var_rec_ - 1 ); -} - -/*! -Add a value to the end of the current vector of VecAD indices. - -For each VecAD vector, this routine is used to store the length -of the vector followed by the parameter index corresponding to each -value in the vector. -This value for the elements of the VecAD vector corresponds to the -beginning of the operation sequence. - -\param vec_ind -is the index to be palced at the end of the vector of VecAD indices. - -\return -is the index in the vector of VecAD indices corresponding to this value. -This index starts at zero after the recorder default constructor -and after each call to Erase. -It increments by one for each call to PutVecInd.. -*/ -template -inline addr_t recorder::PutVecInd(size_t vec_ind) -{ size_t i = vecad_ind_rec_.extend(1); - CPPAD_ASSERT_UNKNOWN( std::numeric_limits::max() >= vec_ind ); - vecad_ind_rec_[i] = addr_t( vec_ind ); - CPPAD_ASSERT_UNKNOWN( vecad_ind_rec_.size() == i + 1 ); - - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= i, - "cppad_tape_addr_type maximum value has been exceeded" - ); - return static_cast( i ); -} - -/*! -Find or add a parameter to the current vector of parameters. - -\param par -is the parameter to be found or placed in the vector of parameters. - -\return -is the index in the parameter vector corresponding to this parameter value. -This value is not necessarily placed at the end of the vector -(because values that are identically equal may be reused). -*/ -template -addr_t recorder::PutPar(const Base &par) -{ static size_t hash_table[CPPAD_HASH_TABLE_SIZE * CPPAD_MAX_NUM_THREADS]; - size_t i; - size_t code; - - CPPAD_ASSERT_UNKNOWN( - thread_offset_ / CPPAD_HASH_TABLE_SIZE - == - thread_alloc::thread_num() - ); - - // get hash code for this value - code = static_cast( hash_code(par) ); - CPPAD_ASSERT_UNKNOWN( code < CPPAD_HASH_TABLE_SIZE ); - - // If we have a match, return the parameter index - i = hash_table[code + thread_offset_]; - if( i < par_rec_.size() && IdenticalEqualPar(par_rec_[i], par) ) - { CPPAD_ASSERT_KNOWN( - static_cast( std::numeric_limits::max() ) >= i, - "cppad_tape_addr_type maximum value has been exceeded" - ) - return static_cast( i ); - } - - // place a new value in the table - i = par_rec_.extend(1); - par_rec_[i] = par; - CPPAD_ASSERT_UNKNOWN( par_rec_.size() == i + 1 ); - - // make the hash code point to this new value - hash_table[code + thread_offset_] = i; - - // return the parameter index - CPPAD_ASSERT_KNOWN( - static_cast( std::numeric_limits::max() ) >= i, - "cppad_tape_addr_type maximum value has been exceeded" - ) - return static_cast( i ); -} -// -------------------------- PutArg -------------------------------------- -/*! -Prototype for putting operation argument indices in the recording. - -The following syntax -\verbatim - rec.PutArg(arg0) - rec.PutArg(arg0, arg1) - . - . - . - rec.PutArg(arg0, arg1, ..., arg5) -\endverbatim -places the values passed to PutArg at the current end of the -operation argument indices for the recording. -\a arg0 comes before \a arg1, etc. -The proper number of operation argument indices -corresponding to the operation code op is given by -\verbatim - NumArg(op) -\endverbatim -The number of the operation argument indices starts at zero -after the default constructor and each call to Erase. -It increases by the number of indices placed by each call to PutArg. -*/ -inline void prototype_put_arg(void) -{ // This routine should not be called - CPPAD_ASSERT_UNKNOWN(false); -} -/*! -Put one operation argument index in the recording - -\param arg0 -The operation argument index - -\copydetails prototype_put_arg -*/ -template -inline void recorder::PutArg(addr_t arg0) -{ - size_t i = op_arg_rec_.extend(1); - op_arg_rec_[i] = static_cast( arg0 ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + 1 ); -} -/*! -Put two operation argument index in the recording - -\param arg0 -First operation argument index. - -\param arg1 -Second operation argument index. - -\copydetails prototype_put_arg -*/ -template -inline void recorder::PutArg(addr_t arg0, addr_t arg1) -{ - size_t i = op_arg_rec_.extend(2); - op_arg_rec_[i++] = static_cast( arg0 ); - op_arg_rec_[i] = static_cast( arg1 ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + 1 ); -} -/*! -Put three operation argument index in the recording - -\param arg0 -First operation argument index. - -\param arg1 -Second operation argument index. - -\param arg2 -Third operation argument index. - -\copydetails prototype_put_arg -*/ -template -inline void recorder::PutArg(addr_t arg0, addr_t arg1, addr_t arg2) -{ - size_t i = op_arg_rec_.extend(3); - op_arg_rec_[i++] = static_cast( arg0 ); - op_arg_rec_[i++] = static_cast( arg1 ); - op_arg_rec_[i] = static_cast( arg2 ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + 1 ); -} -/*! -Put four operation argument index in the recording - -\param arg0 -First operation argument index. - -\param arg1 -Second operation argument index. - -\param arg2 -Third operation argument index. - -\param arg3 -Fourth operation argument index. - -\copydetails prototype_put_arg -*/ -template -inline void recorder::PutArg(addr_t arg0, addr_t arg1, addr_t arg2, - addr_t arg3) -{ - size_t i = op_arg_rec_.extend(4); - op_arg_rec_[i++] = static_cast( arg0 ); - op_arg_rec_[i++] = static_cast( arg1 ); - op_arg_rec_[i++] = static_cast( arg2 ); - op_arg_rec_[i] = static_cast( arg3 ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + 1 ); - -} -/*! -Put five operation argument index in the recording - -\param arg0 -First operation argument index. - -\param arg1 -Second operation argument index. - -\param arg2 -Third operation argument index. - -\param arg3 -Fourth operation argument index. - -\param arg4 -Fifth operation argument index. - -\copydetails prototype_put_arg -*/ -template -inline void recorder::PutArg(addr_t arg0, addr_t arg1, addr_t arg2, - addr_t arg3, addr_t arg4) -{ - size_t i = op_arg_rec_.extend(5); - op_arg_rec_[i++] = static_cast( arg0 ); - op_arg_rec_[i++] = static_cast( arg1 ); - op_arg_rec_[i++] = static_cast( arg2 ); - op_arg_rec_[i++] = static_cast( arg3 ); - op_arg_rec_[i] = static_cast( arg4 ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + 1 ); - -} -/*! -Put six operation argument index in the recording - -\param arg0 -First operation argument index. - -\param arg1 -Second operation argument index. - -\param arg2 -Third operation argument index. - -\param arg3 -Fourth operation argument index. - -\param arg4 -Fifth operation argument index. - -\param arg5 -Sixth operation argument index. - -\copydetails prototype_put_arg -*/ -template -inline void recorder::PutArg(addr_t arg0, addr_t arg1, addr_t arg2, - addr_t arg3, addr_t arg4, addr_t arg5) -{ - size_t i = op_arg_rec_.extend(6); - op_arg_rec_[i++] = static_cast( arg0 ); - op_arg_rec_[i++] = static_cast( arg1 ); - op_arg_rec_[i++] = static_cast( arg2 ); - op_arg_rec_[i++] = static_cast( arg3 ); - op_arg_rec_[i++] = static_cast( arg4 ); - op_arg_rec_[i] = static_cast( arg5 ); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + 1 ); -} -// -------------------------------------------------------------------------- -/*! -Reserve space for arguments, but delay placing values there. - -\param n_arg -number of arguements to reserve space for - -\return -is the index in the argument vector corresponding to the -first of the arguments being reserved. -*/ -template -inline size_t recorder::ReserveArg(size_t n_arg) -{ - size_t i = op_arg_rec_.extend(n_arg); - CPPAD_ASSERT_UNKNOWN( op_arg_rec_.size() == i + n_arg ); - return i; -} - -/*! -\brief -Replace an argument value in the recording -(intended to fill in reserved values). - -\param i_arg -is the index, in argument vector, for the value that is replaced. - -\param value -is the new value for the argument with the specified index. -*/ -template -inline void recorder::ReplaceArg(size_t i_arg, size_t value) -{ op_arg_rec_[i_arg] = static_cast( value ); } -// -------------------------------------------------------------------------- -/*! -Put a character string in the text for this recording. - -\param text -is a '\\0' terminated character string that is to be put in the -vector of characters corresponding to this recording. -The terminator '\\0' will be included. - -\return -is the offset with in the text vector for this recording at which -the character string starts. -*/ -template -inline addr_t recorder::PutTxt(const char *text) -{ - // determine length of the text including terminating '\0' - size_t n = 0; - while( text[n] != '\0' ) - n++; - CPPAD_ASSERT_UNKNOWN( n <= 1000 ); - n++; - CPPAD_ASSERT_UNKNOWN( text[n-1] == '\0' ); - - // copy text including terminating '\0' - size_t i = text_rec_.extend(n); - size_t j; - for(j = 0; j < n; j++) - text_rec_[i + j] = text[j]; - CPPAD_ASSERT_UNKNOWN( text_rec_.size() == i + n ); - - CPPAD_ASSERT_KNOWN( - std::numeric_limits::max() >= i, - "cppad_tape_addr_type maximum value has been exceeded" - ); - // - return static_cast( i ); -} -// ------------------------------------------------------------------------- - - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/rev_hes_sweep.hpp b/external/cppad/include/cppad/local/rev_hes_sweep.hpp deleted file mode 100644 index ee072154e..000000000 --- a/external/cppad/include/cppad/local/rev_hes_sweep.hpp +++ /dev/null @@ -1,783 +0,0 @@ -# ifndef CPPAD_LOCAL_REV_HES_SWEEP_HPP -# define CPPAD_LOCAL_REV_HES_SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file rev_hes_sweep.hpp -Compute Reverse mode Hessian sparsity patterns. -*/ - -/*! -\def CPPAD_REV_HES_SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every rev_hes_sweep computation is printed. -*/ -# define CPPAD_REV_HES_SWEEP_TRACE 0 - -/*! -Given the forward Jacobian sparsity pattern for all the variables, -and the reverse Jacobian sparsity pattern for the dependent variables, -RevHesSweep computes the Hessian sparsity pattern for all the independent -variables. - -\tparam Base -base type for the operator; i.e., this operation sequence was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape; i.e., -\a play->num_var_rec(). -This is also the number of rows in the entire sparsity pattern -\a rev_hes_sparse. - -\param play -The information stored in \a play -is a recording of the operations corresponding to a function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables -and \f$ m \f$ is the number of dependent variables. -The object \a play is effectly constant. -It is not declared const because while playing back the tape -the object \a play holds information about the current location -with in the tape and this changes during playback. - -\param for_jac_sparse -For i = 0 , ... , \a numvar - 1, -(for all the variables on the tape), -the forward Jacobian sparsity pattern for the variable with index i -corresponds to the set with index i in \a for_jac_sparse. - -\param RevJac -\b Input: -For i = 0, ... , \a numvar - 1 -the if the variable with index i on the tape is an dependent variable and -included in the Hessian, \a RevJac[ i ] is equal to true, -otherwise it is equal to false. -\n -\n -\b Output: The values in \a RevJac upon return are not specified; i.e., -it is used for temporary work space. - -\param rev_hes_sparse -The reverse Hessian sparsity pattern for the variable with index i -corresponds to the set with index i in \a rev_hes_sparse. -\n -\n -\b Input: For i = 0 , ... , \a numvar - 1 -the reverse Hessian sparsity pattern for the variable with index i is empty. -\n -\n -\b Output: For j = 1 , ... , \a n, -the reverse Hessian sparsity pattern for the independent dependent variable -with index (j-1) is given by the set with index j -in \a rev_hes_sparse. -The values in the rest of \a rev_hes_sparse are not specified; i.e., -they are used for temporary work space. -*/ - -template -void RevHesSweep( - size_t n, - size_t numvar, - local::player* play, - const Vector_set& for_jac_sparse, - bool* RevJac, - Vector_set& rev_hes_sparse -) -{ - OpCode op; - size_t i_op; - size_t i_var; - - const addr_t* arg = CPPAD_NULL; - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - size_t i, j, k; - - // check numvar argument - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse.n_set() == numvar ); - CPPAD_ASSERT_UNKNOWN( rev_hes_sparse.n_set() == numvar ); - CPPAD_ASSERT_UNKNOWN( numvar > 0 ); - - // upper limit exclusive for set elements - size_t limit = rev_hes_sparse.end(); - CPPAD_ASSERT_UNKNOWN( for_jac_sparse.end() == limit ); - - // check number of sets match - CPPAD_ASSERT_UNKNOWN( - for_jac_sparse.n_set() == rev_hes_sparse.n_set() - ); - - // vecad_sparsity contains a sparsity pattern for each VecAD object. - // vecad_ind maps a VecAD index (beginning of the VecAD object) - // to the index for the corresponding set in vecad_sparsity. - size_t num_vecad_ind = play->num_vec_ind_rec(); - size_t num_vecad_vec = play->num_vecad_vec_rec(); - Vector_set vecad_sparse; - vecad_sparse.resize(num_vecad_vec, limit); - pod_vector vecad_ind; - pod_vector vecad_jac; - if( num_vecad_vec > 0 ) - { size_t length; - vecad_ind.extend(num_vecad_ind); - vecad_jac.extend(num_vecad_vec); - j = 0; - for(i = 0; i < num_vecad_vec; i++) - { // length of this VecAD - length = play->GetVecInd(j); - // set vecad_ind to proper index for this VecAD - vecad_ind[j] = i; - // make all other values for this vector invalid - for(k = 1; k <= length; k++) - vecad_ind[j+k] = num_vecad_vec; - // start of next VecAD - j += length + 1; - // initialize this vector's reverse jacobian value - vecad_jac[i] = false; - } - CPPAD_ASSERT_UNKNOWN( j == play->num_vec_ind_rec() ); - } - - // ---------------------------------------------------------------------- - // user's atomic op calculator - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator - // - // work space used by UserOp. - vector user_x; // parameters in x as integers - vector user_ix; // variable indices for argument vector - vector user_iy; // variable indices for result vector - // - // information set by forward_user (initialization to avoid warnings) - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - // information set by forward_user (necessary initialization) - enum_user_state user_state = end_user; // proper initialization - // ---------------------------------------------------------------------- - // - // pointer to the beginning of the parameter vector - // (used by atomic functions - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - // - // Initialize - play->reverse_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == EndOp ); -# if CPPAD_REV_HES_SWEEP_TRACE - std::cout << std::endl; - CppAD::vectorBool zf_value(limit); - CppAD::vectorBool zh_value(limit); -# endif - bool more_operators = true; - while(more_operators) - { bool flag; // temporary for use in switch cases - // - // next op - play->reverse_next(op, arg, i_op, i_var); -# ifndef NDEBUG - if( i_op <= n ) - { CPPAD_ASSERT_UNKNOWN((op == InvOp) | (op == BeginOp)); - } - else CPPAD_ASSERT_UNKNOWN((op != InvOp) & (op != BeginOp)); -# endif - - // rest of information depends on the case - switch( op ) - { - case AbsOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case AddvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_addsub_op( - i_var, arg, RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[1], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; -# endif - // ------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; -# endif - // ------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; -# endif - // ------------------------------------------------- - - case BeginOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - more_operators = false; - break; - // ------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. - play->reverse_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. - play->reverse_csum(op, arg, i_op, i_var); - reverse_sparse_hessian_csum_op( - i_var, arg, RevJac, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case CExpOp: - reverse_sparse_hessian_cond_op( - i_var, arg, num_par, RevJac, rev_hes_sparse - ); - break; - // --------------------------------------------------- - - case CosOp: - // sin(x), cos(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // --------------------------------------------------- - - case CoshOp: - // sinh(x), cosh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case DisOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - // derivativve is identically zero - break; - // ------------------------------------------------- - - case DivvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_div_op( - i_var, arg, RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[1], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case ErfOp: - // arg[1] is always the parameter 0 - // arg[2] is always the parameter 2 / sqrt(pi) - CPPAD_ASSERT_NARG_NRES(op, 3, 5); - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case ExpOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; -# endif - // ------------------------------------------------- - - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1) - // Z is already defined - break; - // ------------------------------------------------- - - case LdpOp: - reverse_sparse_hessian_load_op( - op, - i_var, - arg, - num_vecad_ind, - vecad_ind.data(), - rev_hes_sparse, - vecad_sparse, - RevJac, - vecad_jac.data() - ); - break; - // ------------------------------------------------- - - case LdvOp: - reverse_sparse_hessian_load_op( - op, - i_var, - arg, - num_vecad_ind, - vecad_ind.data(), - rev_hes_sparse, - vecad_sparse, - RevJac, - vecad_jac.data() - ); - break; - // ------------------------------------------------- - - case EqpvOp: - case EqvvOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case LepvOp: - case LevpOp: - case LevvOp: - case NepvOp: - case NevvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - break; - // ------------------------------------------------- - - case LogOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; -# endif - // ------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[1], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case MulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_mul_op( - i_var, arg, RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case ParOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[1], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case PowvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3) - reverse_sparse_hessian_pow_op( - i_var, arg, RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - break; - // ------------------------------------------------- - - case SignOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - // Derivative is identiaclly zero - break; - // ------------------------------------------------- - - case SinOp: - // cos(x), sin(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case SinhOp: - // cosh(x), sinh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case SqrtOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case StppOp: - // sparsity cannot propagate through a parameter - CPPAD_ASSERT_NARG_NRES(op, 3, 0) - break; - // ------------------------------------------------- - - case StpvOp: - reverse_sparse_hessian_store_op( - op, - arg, - num_vecad_ind, - vecad_ind.data(), - rev_hes_sparse, - vecad_sparse, - RevJac, - vecad_jac.data() - ); - break; - // ------------------------------------------------- - - case StvpOp: - // sparsity cannot propagate through a parameter - CPPAD_ASSERT_NARG_NRES(op, 3, 0) - break; - // ------------------------------------------------- - - case StvvOp: - reverse_sparse_hessian_store_op( - op, - arg, - num_vecad_ind, - vecad_ind.data(), - rev_hes_sparse, - vecad_sparse, - RevJac, - vecad_jac.data() - ); - break; - // ------------------------------------------------- - - case SubvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_addsub_op( - i_var, arg, RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[1], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case TanOp: - // tan(x)^2, tan(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case TanhOp: - // tanh(x)^2, tanh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2) - reverse_sparse_hessian_nonlinear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case UserOp: - CPPAD_ASSERT_UNKNOWN( - user_state == start_user || user_state == end_user - ); - flag = user_state == end_user; - user_atom = play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { user_x.resize(user_n); - user_ix.resize(user_n); - user_iy.resize(user_m); - } - else - { // call users function for this operation - user_atom->set_old(user_old); - user_atom->rev_sparse_hes( - user_x, user_ix, user_iy, - for_jac_sparse, RevJac, rev_hes_sparse - ); - } - break; - - case UsrapOp: - // parameter argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // argument parameter value - user_x[user_j] = parameter[arg[0]]; - // special variable index used for parameters - user_ix[user_j] = 0; - break; - - case UsravOp: - // variable argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // argument variables not available during sparsity calculations - user_x[user_j] = CppAD::numeric_limits::quiet_NaN(); - // variable index for this argument - user_ix[user_j] = arg[0]; - break; - - case UsrrpOp: - // parameter result in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // special variable index used for parameters - user_iy[user_i] = 0; - break; - - case UsrrvOp: - // variable result in an atomic operation sequence - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // variable index for this result - user_iy[user_i] = i_var; - break; - // ------------------------------------------------- - - case ZmulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[1], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_linear_unary_op( - i_var, arg[0], RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - // ------------------------------------------------- - - case ZmulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1) - reverse_sparse_hessian_mul_op( - i_var, arg, RevJac, for_jac_sparse, rev_hes_sparse - ); - break; - - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -# if CPPAD_REV_HES_SWEEP_TRACE - for(j = 0; j < limit; j++) - { zf_value[j] = false; - zh_value[j] = false; - } - typename Vector_set::const_iterator itr_jac(for_jac_sparse, i_var); - j = *itr_jac; - while( j < limit ) - { zf_value[j] = true; - j = *(++itr_jac); - } - typename Vector_set::const_iterator itr_hes(rev_hes_sparse, i_var); - j = *itr_hes; - while( j < limit ) - { zh_value[j] = true; - j = *(++itr_hes); - } - printOp( - std::cout, - play, - i_op, - i_var, - op, - arg - ); - // should also print RevJac[i_var], but printOpResult does not - // yet allow for this - if( NumRes(op) > 0 && op != BeginOp ) printOpResult( - std::cout, - 1, - &zf_value, - 1, - &zh_value - ); - std::cout << std::endl; - } - std::cout << std::endl; -# else - } -# endif - // values corresponding to BeginOp - CPPAD_ASSERT_UNKNOWN( i_op == 0 ); - CPPAD_ASSERT_UNKNOWN( i_var == 0 ); - - return; -} -} } // END_CPPAD_LOCAL_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_REV_HES_SWEEP_TRACE - -# endif diff --git a/external/cppad/include/cppad/local/rev_jac_sweep.hpp b/external/cppad/include/cppad/local/rev_jac_sweep.hpp deleted file mode 100644 index 983976946..000000000 --- a/external/cppad/include/cppad/local/rev_jac_sweep.hpp +++ /dev/null @@ -1,758 +0,0 @@ -# ifndef CPPAD_LOCAL_REV_JAC_SWEEP_HPP -# define CPPAD_LOCAL_REV_JAC_SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file rev_jac_sweep.hpp -Compute Reverse mode Jacobian sparsity patterns. -*/ - -/*! -\def CPPAD_REV_JAC_SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every rev_jac_sweep computation is printed. -*/ -# define CPPAD_REV_JAC_SWEEP_TRACE 0 - -/*! -Given the sparsity pattern for the dependent variables, -RevJacSweep computes the sparsity pattern for all the independent variables. - -\tparam Base -base type for the operator; i.e., this operation sequence was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param dependency -Are the derivatives with respect to left and right of the expression below -considered to be non-zero: -\code - CondExpRel(left, right, if_true, if_false) -\endcode -This is used by the optimizer to obtain the correct dependency relations. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape; i.e., -\a play->num_var_rec(). -This is also the number of rows in the entire sparsity pattern \a RevJac. - -\param play -The information stored in \a play -is a recording of the operations corresponding to a function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables -and \f$ m \f$ is the number of dependent variables. -The object \a play is effectly constant. -It is not declared const because while playing back the tape -the object \a play holds information about the current location -with in the tape and this changes during playback. - -\param var_sparsity -For i = 0 , ... , \a numvar - 1, -(all the variables on the tape) -the forward Jacobian sparsity pattern for variable i -corresponds to the set with index i in \a var_sparsity. -\b -\b -\b Input: -For i = 0 , ... , \a numvar - 1, -the forward Jacobian sparsity pattern for variable i is an input -if i corresponds to a dependent variable. -Otherwise the sparsity patten is empty. -\n -\n -\b Output: For j = 1 , ... , \a n, -the sparsity pattern for the dependent variable with index (j-1) -is given by the set with index index j in \a var_sparsity. -*/ - -template -void RevJacSweep( - bool dependency, - size_t n, - size_t numvar, - local::player* play, - Vector_set& var_sparsity -) -{ - OpCode op; - size_t i_op; - size_t i_var; - - const addr_t* arg = CPPAD_NULL; - - size_t i, j, k; - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - // check numvar argument - CPPAD_ASSERT_UNKNOWN( numvar > 0 ); - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - CPPAD_ASSERT_UNKNOWN( var_sparsity.n_set() == numvar ); - - // upper limit (exclusive) for elements in the set - size_t limit = var_sparsity.end(); - - // vecad_sparsity contains a sparsity pattern for each VecAD object. - // vecad_ind maps a VecAD index (beginning of the VecAD object) - // to the index of the corresponding set in vecad_sparsity. - size_t num_vecad_ind = play->num_vec_ind_rec(); - size_t num_vecad_vec = play->num_vecad_vec_rec(); - Vector_set vecad_sparsity; - vecad_sparsity.resize(num_vecad_vec, limit); - pod_vector vecad_ind; - if( num_vecad_vec > 0 ) - { size_t length; - vecad_ind.extend(num_vecad_ind); - j = 0; - for(i = 0; i < num_vecad_vec; i++) - { // length of this VecAD - length = play->GetVecInd(j); - // set to proper index for this VecAD - vecad_ind[j] = i; - for(k = 1; k <= length; k++) - vecad_ind[j+k] = num_vecad_vec; // invalid index - // start of next VecAD - j += length + 1; - } - CPPAD_ASSERT_UNKNOWN( j == play->num_vec_ind_rec() ); - } - - // ---------------------------------------------------------------------- - // user's atomic op calculator - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator - // - // work space used by UserOp. - vector user_x; // parameters in x as integers - vector user_ix; // variable indices for argument vector - vector user_iy; // variable indices for result vector - // - // information set by forward_user (initialization to avoid warnings) - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - // information set by forward_user (necessary initialization) - enum_user_state user_state = end_user; // proper initialization - // ---------------------------------------------------------------------- - // - // pointer to the beginning of the parameter vector - // (used by atomic functions - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - // - // Initialize - play->reverse_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == EndOp ); -# if CPPAD_REV_JAC_SWEEP_TRACE - std::cout << std::endl; - CppAD::vectorBool z_value(limit); -# endif - bool more_operators = true; - while(more_operators) - { bool flag; // temporary for use in switch cases - // - // next op - play->reverse_next(op, arg, i_op, i_var); -# ifndef NDEBUG - if( i_op <= n ) - { CPPAD_ASSERT_UNKNOWN((op == InvOp) | (op == BeginOp)); - } - else CPPAD_ASSERT_UNKNOWN((op != InvOp) & (op != BeginOp)); -# endif - - // rest of information depends on the case - switch( op ) - { - case AbsOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case AddvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case BeginOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - more_operators = false; - break; - // ------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. - play->reverse_cskip(op, arg, i_op, i_var); - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. - play->reverse_csum(op, arg, i_op, i_var); - reverse_sparse_jacobian_csum_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case CExpOp: - reverse_sparse_jacobian_cond_op( - dependency, i_var, arg, num_par, var_sparsity - ); - break; - // --------------------------------------------------- - - case CosOp: - // sin(x), cos(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // --------------------------------------------------- - - case CoshOp: - // sinh(x), cosh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case DisOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - // derivative is identically zero but dependency is not - if( dependency ) reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case DivvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case ErfOp: - // arg[1] is always the parameter 0 - // arg[0] is always the parameter 2 / sqrt(pi) - CPPAD_ASSERT_NARG_NRES(op, 3, 5); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case ExpOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case InvOp: - CPPAD_ASSERT_NARG_NRES(op, 0, 1); - break; - // ------------------------------------------------- - - case LdpOp: - reverse_sparse_jacobian_load_op( - dependency, - op, - i_var, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case LdvOp: - reverse_sparse_jacobian_load_op( - dependency, - op, - i_var, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case EqpvOp: - case EqvvOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case LepvOp: - case LevpOp: - case LevvOp: - case NepvOp: - case NevvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 0); - break; - // ------------------------------------------------- - - case LogOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; -# endif - // ------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case MulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case ParOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - - break; - // ------------------------------------------------- - - case PowvpOp: - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3); - reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case PowvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 3); - reverse_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case PriOp: - CPPAD_ASSERT_NARG_NRES(op, 5, 0); - break; - // ------------------------------------------------- - - case SignOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - // derivative is identically zero but dependency is not - if( dependency ) reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case SinOp: - // cos(x), sin(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case SinhOp: - // cosh(x), sinh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case SqrtOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case StppOp: - // does not affect sparsity or dependency when both are parameters - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - break; - // ------------------------------------------------- - - case StpvOp: - reverse_sparse_jacobian_store_op( - dependency, - op, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case StvpOp: - CPPAD_ASSERT_NARG_NRES(op, 3, 0); - // storing a parameter only affects dependency - reverse_sparse_jacobian_store_op( - dependency, - op, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case StvvOp: - reverse_sparse_jacobian_store_op( - dependency, - op, - arg, - num_vecad_ind, - vecad_ind.data(), - var_sparsity, - vecad_sparsity - ); - break; - // ------------------------------------------------- - - case SubvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case TanOp: - // tan(x)^2, tan(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case TanhOp: - // tanh(x)^2, tanh(x) - CPPAD_ASSERT_NARG_NRES(op, 1, 2); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case UserOp: - CPPAD_ASSERT_UNKNOWN( - user_state == start_user || user_state == end_user - ); - flag = user_state == end_user; - user_atom = play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { // start of user atomic operation sequence - user_x.resize( user_n ); - user_ix.resize( user_n ); - user_iy.resize( user_m ); - } - else - { // end of users atomic operation sequence - user_atom->set_old(user_old); - user_atom->rev_sparse_jac( - user_x, user_ix, user_iy, var_sparsity - ); - } - break; - - case UsrapOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // argument parameter value - user_x[user_j] = parameter[arg[0]]; - // special variable index used for parameters - user_ix[user_j] = 0; - // - break; - - case UsravOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // argument variables not available during sparsity calculations - user_x[user_j] = CppAD::numeric_limits::quiet_NaN(); - // variable index for this argument - user_ix[user_j] = arg[0]; - break; - - case UsrrpOp: - // parameter result in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // special variable index used for parameters - user_iy[user_i] = 0; - break; - - case UsrrvOp: - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - // variable index for this result - user_iy[user_i] = i_var; - break; - // ------------------------------------------------- - - case ZmulpvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[1], var_sparsity - ); - break; - // ------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_unary_op( - i_var, arg[0], var_sparsity - ); - break; - // ------------------------------------------------- - - case ZmulvvOp: - CPPAD_ASSERT_NARG_NRES(op, 2, 1); - reverse_sparse_jacobian_binary_op( - i_var, arg, var_sparsity - ); - break; - // ------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(0); - } -# if CPPAD_REV_JAC_SWEEP_TRACE - for(j = 0; j < limit; j++) - z_value[j] = false; - typename Vector_set::const_iterator itr(var_sparsity, i_var); - j = *itr; - while( j < limit ) - { z_value[j] = true; - j = *(++itr); - } - printOp( - std::cout, - play, - i_op, - i_var, - op, - arg - ); - // Note that sparsity for UsrrvOp are computed before call to - // atomic function so no need to delay printing (as in forward mode) - if( NumRes(op) > 0 && op != BeginOp ) printOpResult( - std::cout, - 0, - (CppAD::vectorBool *) CPPAD_NULL, - 1, - &z_value - ); - std::cout << std::endl; - } - std::cout << std::endl; -# else - } -# endif - // values corresponding to BeginOp - CPPAD_ASSERT_UNKNOWN( i_op == 0 ); - CPPAD_ASSERT_UNKNOWN( i_var == 0 ); - - return; -} -} } // END_CPPAD_LOCAL_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_REV_JAC_SWEEP_TRACE -# undef CPPAD_ATOMIC_CALL - -# endif diff --git a/external/cppad/include/cppad/local/reverse_sweep.hpp b/external/cppad/include/cppad/local/reverse_sweep.hpp deleted file mode 100644 index 0c519d5ad..000000000 --- a/external/cppad/include/cppad/local/reverse_sweep.hpp +++ /dev/null @@ -1,824 +0,0 @@ -// $Id: reverse_sweep.hpp 3853 2016-12-14 14:40:11Z bradbell $ -# ifndef CPPAD_LOCAL_REVERSE_SWEEP_HPP -# define CPPAD_LOCAL_REVERSE_SWEEP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file reverse_sweep.hpp -Compute derivatives of arbitrary order Taylor coefficients. -*/ - -/* -\def CPPAD_ATOMIC_CALL -This avoids warnings when NDEBUG is defined and user_ok is not used. -If \c NDEBUG is defined, this resolves to -\code - user_atom->reverse -\endcode -otherwise, it respolves to -\code - user_ok = user_atom->reverse -\endcode -This maco is undefined at the end of this file to facillitate is -use with a different definition in other files. -*/ -# ifdef NDEBUG -# define CPPAD_ATOMIC_CALL user_atom->reverse -# else -# define CPPAD_ATOMIC_CALL user_ok = user_atom->reverse -# endif - -/*! -\def CPPAD_REVERSE_SWEEP_TRACE -This value is either zero or one. -Zero is the normal operational value. -If it is one, a trace of every reverse_sweep computation is printed. -*/ -# define CPPAD_REVERSE_SWEEP_TRACE 0 - -/*! -Compute derivative of arbitrary order forward mode Taylor coefficients. - -\tparam Base -base type for the operator; i.e., this operation sequence was recorded -using AD< \a Base > and computations by this routine are done using type -\a Base. - -\param d -is the highest order Taylor coefficients that -we are computing the derivative of. - -\param n -is the number of independent variables on the tape. - -\param numvar -is the total number of variables on the tape. -This is also equal to the number of rows in the matrix \a Taylor; i.e., -play->num_var_rec(). - -\param play -The information stored in \a play -is a recording of the operations corresponding to the function -\f[ - F : {\bf R}^n \rightarrow {\bf R}^m -\f] -where \f$ n \f$ is the number of independent variables and -\f$ m \f$ is the number of dependent variables. -We define \f$ u^{(k)} \f$ as the value of x_k in the previous call -of the form - - f.Forward(k, x_k) - -We define -\f$ X : {\bf R}^{n \times d} \rightarrow {\bf R}^n \f$ by -\f[ - X(t, u) = u^{(0)} + u^{(1)} t + \cdots + u^{(d)} t^d -\f] -We define -\f$ Y : {\bf R}^{n \times d} \rightarrow {\bf R}^m \f$ by -\f[ - Y(t, u) = F[ X(t, u) ] -\f] -We define the function -\f$ W : {\bf R}^{n \times d} \rightarrow {\bf R} \f$ by -\f[ -W(u) -= -\sum_{k=0}^{d} ( w^{(k)} )^{\rm T} - \frac{1}{k !} \frac{\partial^k}{\partial t^k} Y(0, u) -\f] -(The matrix \f$ w \in {\bf R}^m \f$, -is defined below under the heading Partial.) -Note that the scale factor 1 / k converts -the k-th partial derivative to the k-th order Taylor coefficient. -This routine computes the derivative of \f$ W(u) \f$ -with respect to all the Taylor coefficients -\f$ u^{(k)} \f$ for \f$ k = 0 , ... , d \f$. -\n -\n -The object \a play is effectly constant. -There is an exception to this, -while palying back the tape -the object \a play holds information about the current location -with in the tape and this changes during palyback. - -\param J -Is the number of columns in the coefficient matrix \a Taylor. -This must be greater than or equal \a d + 1. - -\param Taylor -For i = 1 , ... , \a numvar, and for k = 0 , ... , \a d, -\a Taylor [ i * J + k ] -is the k-th order Taylor coefficient corresponding to -variable with index i on the tape. -The value \f$ u \in {\bf R}^{n \times d} \f$, -at which the derivative is computed, -is defined by -\f$ u_j^{(k)} \f$ = \a Taylor [ j * J + k ] -for j = 1 , ... , \a n, and for k = 0 , ... , \a d. - -\param K -Is the number of columns in the partial derivative matrix \a Partial. -It must be greater than or equal \a d + 1. - -\param Partial -\b Input: -The last \f$ m \f$ rows of \a Partial are inputs. -The matrix \f$ w \f$, used to define \f$ W(u) \f$, -is specified by these rows. -For i = 0 , ... , m - 1, -for k = 0 , ... , d, -Partial [ (numvar - m + i ) * K + k ] = w[i,k]. -\n -\n -\b Temporary: -For i = n+1 , ... , \a numvar - 1 and for k = 0 , ... , d, -the value of \a Partial [ i * K + k ] is used for temporary work space -and its output value is not defined. -\n -\n -\b Output: -For j = 1 , ... , n and for k = 0 , ... , d, -\a Partial [ j * K + k ] -is the partial derivative of \f$ W( u ) \f$ with -respect to \f$ u_j^{(k)} \f$. - -\param cskip_op -Is a vector with size play->num_op_rec(). -If cskip_op[i] is true, the operator index i in the recording -does not affect any of the dependent variable (given the value -of the independent variables). -Note that all the operators in an atomic function call are skipped as a block, -so only the last UserOp fore each call needs to have cskip_op[i] true. - -\param var_by_load_op -is a vector with size play->num_load_op_rec(). -Is the variable index corresponding to each load instruction. -In the case where the index is zero, -the instruction corresponds to a parameter (not variable). - -\par Assumptions -The first operator on the tape is a BeginOp, -and the next \a n operators are InvOp operations for the -corresponding independent variables. -*/ -template -void ReverseSweep( - size_t d, - size_t n, - size_t numvar, - local::player* play, - size_t J, - const Base* Taylor, - size_t K, - Base* Partial, - bool* cskip_op, - const pod_vector& var_by_load_op -) -{ - OpCode op; - size_t i_op; - size_t i_var; - - const addr_t* arg = CPPAD_NULL; - - // check numvar argument - CPPAD_ASSERT_UNKNOWN( play->num_var_rec() == numvar ); - CPPAD_ASSERT_UNKNOWN( numvar > 0 ); - - // length of the parameter vector (used by CppAD assert macros) - const size_t num_par = play->num_par_rec(); - - // pointer to the beginning of the parameter vector - const Base* parameter = CPPAD_NULL; - if( num_par > 0 ) - parameter = play->GetPar(); - - // work space used by UserOp. - const size_t user_k = d; // highest order we are differentiating - const size_t user_k1 = d+1; // number of orders for this calculation - vector user_ix; // variable indices for argument vector - vector user_tx; // argument vector Taylor coefficients - vector user_ty; // result vector Taylor coefficients - vector user_px; // partials w.r.t argument vector - vector user_py; // partials w.r.t. result vector - // - atomic_base* user_atom = CPPAD_NULL; // user's atomic op calculator -# ifndef NDEBUG - bool user_ok = false; // atomic op return value -# endif - // - // information defined by forward_user - size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0; - enum_user_state user_state = end_user; // proper initialization - - // temporary indices - size_t j, ell; - - // Initialize - play->reverse_start(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( op == EndOp ); -# if CPPAD_REVERSE_SWEEP_TRACE - std::cout << std::endl; -# endif - bool more_operators = true; - while(more_operators) - { bool flag; // temporary for use in switch cases - // - // next op - play->reverse_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN((i_op > n) | (op == InvOp) | (op == BeginOp)); - CPPAD_ASSERT_UNKNOWN((i_op <= n) | (op != InvOp) | (op != BeginOp)); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - - // check if we are skipping this operation - while( cskip_op[i_op] ) - { switch(op) - { case CSumOp: - // CSumOp has a variable number of arguments - play->reverse_csum(op, arg, i_op, i_var); - break; - - case CSkipOp: - // CSkip has a variable number of arguments - play->reverse_cskip(op, arg, i_op, i_var); - break; - - case UserOp: - { // skip all operations in this user atomic call - CPPAD_ASSERT_UNKNOWN( user_state == end_user ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - size_t n_skip = user_m + user_n + 1; - for(size_t i = 0; i < n_skip; i++) - { play->reverse_next(op, arg, i_op, i_var); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - } - CPPAD_ASSERT_UNKNOWN( user_state == end_user ); - } - break; - - default: - break; - } - play->reverse_next(op, arg, i_op, i_var); - CPPAD_ASSERT_UNKNOWN( i_op < play->num_op_rec() ); - } - - // rest of informaiton depends on the case -# if CPPAD_REVERSE_SWEEP_TRACE - if( op == CSumOp ) - { // CSumOp has a variable number of arguments - play->reverse_csum(op, arg, i_op, i_var); - } - if( op == CSkipOp ) - { // CSkip has a variable number of arguments - play->reverse_cskip(op, arg, i_op, i_var); - } - size_t i_tmp = i_var; - const Base* Z_tmp = Taylor + i_var * J; - const Base* pZ_tmp = Partial + i_var * K; - printOp( - std::cout, - play, - i_op, - i_tmp, - op, - arg - ); - if( NumRes(op) > 0 && op != BeginOp ) printOpResult( - std::cout, - d + 1, - Z_tmp, - d + 1, - pZ_tmp - ); - std::cout << std::endl; -# endif - switch( op ) - { - - case AbsOp: - reverse_abs_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case AcosOp: - // sqrt(1 - x * x), acos(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_acos_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AcoshOp: - // sqrt(x * x - 1), acosh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_acosh_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; -# endif - // -------------------------------------------------- - - case AddvvOp: - reverse_addvv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case AddpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - reverse_addpv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case AsinOp: - // sqrt(1 - x * x), asin(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_asin_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AsinhOp: - // sqrt(1 + x * x), asinh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_asinh_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; -# endif - // -------------------------------------------------- - - case AtanOp: - // 1 + x * x, atan(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_atan_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case AtanhOp: - // 1 - x * x, atanh(x) - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_atanh_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; -# endif - // ------------------------------------------------- - - case BeginOp: - CPPAD_ASSERT_NARG_NRES(op, 1, 1); - more_operators = false; - break; - // -------------------------------------------------- - - case CSkipOp: - // CSkipOp has a variable number of arguments and - // forward_next thinks it one has one argument. - // we must inform reverse_next of this special case. -# if ! CPPAD_REVERSE_SWEEP_TRACE - play->reverse_cskip(op, arg, i_op, i_var); -# endif - break; - // ------------------------------------------------- - - case CSumOp: - // CSumOp has a variable number of arguments and - // reverse_next thinks it one has one argument. - // We must inform reverse_next of this special case. -# if ! CPPAD_REVERSE_SWEEP_TRACE - play->reverse_csum(op, arg, i_op, i_var); -# endif - reverse_csum_op( - d, i_var, arg, K, Partial - ); - // end of a cummulative summation - break; - // ------------------------------------------------- - - case CExpOp: - reverse_cond_op( - d, - i_var, - arg, - num_par, - parameter, - J, - Taylor, - K, - Partial - ); - break; - // -------------------------------------------------- - - case CosOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_cos_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case CoshOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_cosh_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case DisOp: - // Derivative of discrete operation is zero so no - // contribution passes through this operation. - break; - // -------------------------------------------------- - - case DivvvOp: - reverse_divvv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case DivpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - reverse_divpv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case DivvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - reverse_divvp_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case ErfOp: - reverse_erf_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; -# endif - // -------------------------------------------------- - - case ExpOp: - reverse_exp_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Expm1Op: - reverse_expm1_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; -# endif - // -------------------------------------------------- - - case InvOp: - break; - // -------------------------------------------------- - - case LdpOp: - reverse_load_op( - op, d, i_var, arg, J, Taylor, K, Partial, var_by_load_op.data() - ); - break; - // ------------------------------------------------- - - case LdvOp: - reverse_load_op( - op, d, i_var, arg, J, Taylor, K, Partial, var_by_load_op.data() - ); - break; - // -------------------------------------------------- - - case EqpvOp: - case EqvvOp: - case LtpvOp: - case LtvpOp: - case LtvvOp: - case LepvOp: - case LevpOp: - case LevvOp: - case NepvOp: - case NevvOp: - break; - // ------------------------------------------------- - - case LogOp: - reverse_log_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - -# if CPPAD_USE_CPLUSPLUS_2011 - case Log1pOp: - reverse_log1p_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; -# endif - // -------------------------------------------------- - - case MulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - reverse_mulpv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case MulvvOp: - reverse_mulvv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case ParOp: - break; - // -------------------------------------------------- - - case PowvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - reverse_powvp_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - - case PowpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - reverse_powpv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - - case PowvvOp: - reverse_powvv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case PriOp: - // no result so nothing to do - break; - // -------------------------------------------------- - - case SignOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_sign_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - - case SinOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_sin_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - - case SinhOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_sinh_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case SqrtOp: - reverse_sqrt_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case StppOp: - break; - // -------------------------------------------------- - - case StpvOp: - break; - // ------------------------------------------------- - - case StvpOp: - break; - // ------------------------------------------------- - - case StvvOp: - break; - // -------------------------------------------------- - - case SubvvOp: - reverse_subvv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case SubpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - reverse_subpv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case SubvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - reverse_subvp_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - - case TanOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_tan_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // ------------------------------------------------- - - case TanhOp: - CPPAD_ASSERT_UNKNOWN( i_var < numvar ); - reverse_tanh_op( - d, i_var, arg[0], J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case UserOp: - // start or end an atomic operation sequence - flag = user_state == end_user; - user_atom = play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - if( flag ) - { user_ix.resize(user_n); - if(user_tx.size() != user_n * user_k1) - { user_tx.resize(user_n * user_k1); - user_px.resize(user_n * user_k1); - } - if(user_ty.size() != user_m * user_k1) - { user_ty.resize(user_m * user_k1); - user_py.resize(user_m * user_k1); - } - } - else - { // call users function for this operation - user_atom->set_old(user_old); - CPPAD_ATOMIC_CALL( - user_k, user_tx, user_ty, user_px, user_py - ); -# ifndef NDEBUG - if( ! user_ok ) - { std::string msg = - user_atom->afun_name() - + ": atomic_base.reverse: returned false"; - CPPAD_ASSERT_KNOWN(false, msg.c_str() ); - } -# endif - for(j = 0; j < user_n; j++) if( user_ix[j] > 0 ) - { for(ell = 0; ell < user_k1; ell++) - Partial[user_ix[j] * K + ell] += - user_px[j * user_k1 + ell]; - } - } - break; - - case UsrapOp: - // parameter argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - user_ix[user_j] = 0; - user_tx[user_j * user_k1 + 0] = parameter[ arg[0]]; - for(ell = 1; ell < user_k1; ell++) - user_tx[user_j * user_k1 + ell] = Base(0.); - break; - - case UsravOp: - // variable argument in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) <= i_var ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - user_ix[user_j] = arg[0]; - for(ell = 0; ell < user_k1; ell++) - user_tx[user_j*user_k1 + ell] = Taylor[ arg[0] * J + ell]; - break; - - case UsrrpOp: - // parameter result in an atomic operation sequence - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - for(ell = 0; ell < user_k1; ell++) - { user_py[user_i * user_k1 + ell] = Base(0.); - user_ty[user_i * user_k1 + ell] = Base(0.); - } - user_ty[user_i * user_k1 + 0] = parameter[ arg[0] ]; - break; - - case UsrrvOp: - // variable result in an atomic operation sequence - play->reverse_user(op, user_state, - user_old, user_m, user_n, user_i, user_j - ); - for(ell = 0; ell < user_k1; ell++) - { user_py[user_i * user_k1 + ell] = - Partial[i_var * K + ell]; - user_ty[user_i * user_k1 + ell] = - Taylor[i_var * J + ell]; - } - break; - // ------------------------------------------------------------ - - case ZmulpvOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par ); - reverse_zmulpv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case ZmulvpOp: - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par ); - reverse_zmulvp_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - case ZmulvvOp: - reverse_zmulvv_op( - d, i_var, arg, parameter, J, Taylor, K, Partial - ); - break; - // -------------------------------------------------- - - default: - CPPAD_ASSERT_UNKNOWN(false); - } - } -# if CPPAD_REVERSE_SWEEP_TRACE - std::cout << std::endl; -# endif - // values corresponding to BeginOp - CPPAD_ASSERT_UNKNOWN( i_op == 0 ); - CPPAD_ASSERT_UNKNOWN( i_var == 0 ); -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -// preprocessor symbols that are local to this file -# undef CPPAD_REVERSE_SWEEP_TRACE -# undef CPPAD_ATOMIC_CALL - -# endif diff --git a/external/cppad/include/cppad/local/set_get_in_parallel.hpp b/external/cppad/include/cppad/local/set_get_in_parallel.hpp deleted file mode 100644 index f0a24ccbd..000000000 --- a/external/cppad/include/cppad/local/set_get_in_parallel.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_SET_GET_IN_PARALLEL_HPP -# define CPPAD_LOCAL_SET_GET_IN_PARALLEL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE - -/*! -\file set_get_in_parallel.hpp -File used to set and get user in_parallel routine. -*/ -/*! -Set and call the routine that determine if we are in parallel execution mode. - -\return -value retuned by most recent setting for in_parallel_new. -If set is true, -or the most recent setting is CPPAD_NULL (its initial value), -the return value is false. -Otherwise the function corresponding to the most recent setting -is called and its value returned by set_get_in_parallel. - -\param in_parallel_new [in] -If set is false, in_parallel_new it is not used. -Otherwise, the current value of in_parallel_new becomes the -most recent setting for in_parallel_user. - -\param set -If set is true, then parallel_new is becomes the most -recent setting for this set_get_in_parallel. -In this case, it is assumed that we are currently in sequential execution mode. -*/ -static bool set_get_in_parallel( - bool (*in_parallel_new)(void) , - bool set = false ) -{ static bool (*in_parallel_user)(void) = CPPAD_NULL; - - if( set ) - { in_parallel_user = in_parallel_new; - // Doing a raw assert in this case because set_get_in_parallel is used - // by ErrorHandler and hence cannot use ErrorHandler. - // CPPAD_ASSERT_UNKNOWN( in_parallel_user() == false ) - assert(in_parallel_user == CPPAD_NULL || in_parallel_user() == false); - return false; - } - // - if( in_parallel_user == CPPAD_NULL ) - return false; - // - return in_parallel_user(); -} - -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/sign_op.hpp b/external/cppad/include/cppad/local/sign_op.hpp deleted file mode 100644 index 5d1c1ad5e..000000000 --- a/external/cppad/include/cppad/local/sign_op.hpp +++ /dev/null @@ -1,154 +0,0 @@ -// $Id: sign_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_SIGN_OP_HPP -# define CPPAD_LOCAL_SIGN_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sign_op.hpp -Forward and reverse mode calculations for z = sign(x). -*/ - -/*! -Compute forward mode Taylor coefficient for result of op = SignOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sign(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_sign_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - if( p == 0 ) - { z[0] = sign(x[0]); - p++; - } - for(size_t j = p; j <= q; j++) - z[j] = Base(0.); -} -/*! -Multiple direction forward mode Taylor coefficient for op = SignOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sign(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_sign_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q - 1) * r + 1; - Base* z = taylor + i_z * num_taylor_per_var; - - for(size_t ell = 0; ell < r; ell++) - z[m+ell] = Base(0.); -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = SignOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sign(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_sign_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base x0 = *(taylor + i_x * cap_order); - Base* z = taylor + i_z * cap_order; - - z[0] = sign(x0); -} -/*! -Compute reverse mode partial derivatives for result of op = SignOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sign(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_sign_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // nothing to do because partials of sign are zero - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sin_op.hpp b/external/cppad/include/cppad/local/sin_op.hpp deleted file mode 100644 index 42d484e6a..000000000 --- a/external/cppad/include/cppad/local/sin_op.hpp +++ /dev/null @@ -1,240 +0,0 @@ -# ifndef CPPAD_LOCAL_SIN_OP_HPP -# define CPPAD_LOCAL_SIN_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sin_op.hpp -Forward and reverse mode calculations for z = sin(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = SinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sin(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_sin_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* s = taylor + i_z * cap_order; - Base* c = s - cap_order; - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op. - // (except that there is a sign difference for the hyperbolic case). - size_t k; - if( p == 0 ) - { s[0] = sin( x[0] ); - c[0] = cos( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - s[j] = Base(0.0); - c[j] = Base(0.0); - for(k = 1; k <= j; k++) - { s[j] += Base(double(k)) * x[k] * c[j-k]; - c[j] -= Base(double(k)) * x[k] * s[j-k]; - } - s[j] /= Base(double(j)); - c[j] /= Base(double(j)); - } -} -/*! -Compute forward mode Taylor coefficient for result of op = SinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sin(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_sin_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* s = taylor + i_z * num_taylor_per_var; - Base* c = s - num_taylor_per_var; - - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op - // (except that there is a sign difference for the hyperbolic case). - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { s[m+ell] = Base(double(q)) * x[m + ell] * c[0]; - c[m+ell] = - Base(double(q)) * x[m + ell] * s[0]; - for(size_t k = 1; k < q; k++) - { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell]; - c[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell]; - } - s[m+ell] /= Base(double(q)); - c[m+ell] /= Base(double(q)); - } -} - - -/*! -Compute zero order forward mode Taylor coefficient for result of op = SinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sin(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_sin_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* s = taylor + i_z * cap_order; // called z in documentation - Base* c = s - cap_order; // called y in documentation - - s[0] = sin( x[0] ); - c[0] = cos( x[0] ); -} - -/*! -Compute reverse mode partial derivatives for result of op = SinOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sin(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_sin_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* s = taylor + i_z * cap_order; // called z in doc - Base* ps = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* c = s - cap_order; // called y in documentation - Base* pc = ps - nc_partial; - - - // rest of this routine is identical for the following cases: - // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op. - size_t j = d; - size_t k; - while(j) - { - ps[j] /= Base(double(j)); - pc[j] /= Base(double(j)); - for(k = 1; k <= j; k++) - { - px[k] += Base(double(k)) * azmul(ps[j], c[j-k]); - px[k] -= Base(double(k)) * azmul(pc[j], s[j-k]); - - ps[j-k] -= Base(double(k)) * azmul(pc[j], x[k]); - pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]); - - } - --j; - } - px[0] += azmul(ps[0], c[0]); - px[0] -= azmul(pc[0], s[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sinh_op.hpp b/external/cppad/include/cppad/local/sinh_op.hpp deleted file mode 100644 index d524eb7d6..000000000 --- a/external/cppad/include/cppad/local/sinh_op.hpp +++ /dev/null @@ -1,239 +0,0 @@ -# ifndef CPPAD_LOCAL_SINH_OP_HPP -# define CPPAD_LOCAL_SINH_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sinh_op.hpp -Forward and reverse mode calculations for z = sinh(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = SinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sinh(x) -\endverbatim -The auxillary result is -\verbatim - y = cosh(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_sinh_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* s = taylor + i_z * cap_order; - Base* c = s - cap_order; - - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op - // (except that there is a sign difference for hyperbolic case). - size_t k; - if( p == 0 ) - { s[0] = sinh( x[0] ); - c[0] = cosh( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - s[j] = Base(0.0); - c[j] = Base(0.0); - for(k = 1; k <= j; k++) - { s[j] += Base(double(k)) * x[k] * c[j-k]; - c[j] += Base(double(k)) * x[k] * s[j-k]; - } - s[j] /= Base(double(j)); - c[j] /= Base(double(j)); - } -} -/*! -Compute forward mode Taylor coefficient for result of op = SinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sinh(x) -\endverbatim -The auxillary result is -\verbatim - y = cosh(x) -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_sinh_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* s = taylor + i_z * num_taylor_per_var; - Base* c = s - num_taylor_per_var; - - - // rest of this routine is identical for the following cases: - // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op - // (except that there is a sign difference for the hyperbolic case). - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { s[m+ell] = Base(double(q)) * x[m + ell] * c[0]; - c[m+ell] = Base(double(q)) * x[m + ell] * s[0]; - for(size_t k = 1; k < q; k++) - { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell]; - c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell]; - } - s[m+ell] /= Base(double(q)); - c[m+ell] /= Base(double(q)); - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = SinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sinh(x) -\endverbatim -The auxillary result is -\verbatim - y = cosh(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_sinh_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* s = taylor + i_z * cap_order; // called z in documentation - Base* c = s - cap_order; // called y in documentation - - s[0] = sinh( x[0] ); - c[0] = cosh( x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = SinhOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sinh(x) -\endverbatim -The auxillary result is -\verbatim - y = cosh(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_sinh_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* s = taylor + i_z * cap_order; // called z in doc - Base* ps = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* c = s - cap_order; // called y in documentation - Base* pc = ps - nc_partial; - - - // rest of this routine is identical for the following cases: - // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op. - size_t j = d; - size_t k; - while(j) - { - ps[j] /= Base(double(j)); - pc[j] /= Base(double(j)); - for(k = 1; k <= j; k++) - { - px[k] += Base(double(k)) * azmul(ps[j], c[j-k]); - px[k] += Base(double(k)) * azmul(pc[j], s[j-k]); - - ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]); - pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]); - - } - --j; - } - px[0] += azmul(ps[0], c[0]); - px[0] += azmul(pc[0], s[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sparse_binary_op.hpp b/external/cppad/include/cppad/local/sparse_binary_op.hpp deleted file mode 100644 index a8978124d..000000000 --- a/external/cppad/include/cppad/local/sparse_binary_op.hpp +++ /dev/null @@ -1,485 +0,0 @@ -// $Id: sparse_binary_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_SPARSE_BINARY_OP_HPP -# define CPPAD_LOCAL_SPARSE_BINARY_OP_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sparse_binary_op.hpp -Forward and reverse mode sparsity patterns for binary operators. -*/ - - -/*! -Forward mode Jacobian sparsity pattern for all binary operators. - -The C++ source code corresponding to a binary operation has the form -\verbatim - z = fun(x, y) -\endverbatim -where fun is a C++ binary function and both x and y are variables, -or it has the form -\verbatim - z = x op y -\endverbatim -where op is a C++ binary unary operator and both x and y are variables. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e., z. - -\param arg -\a arg[0] -variable index corresponding to the left operand for this operator; -i.e., x. -\n -\n arg[1] -variable index corresponding to the right operand for this operator; -i.e., y. - -\param sparsity -\b Input: -The set with index \a arg[0] in \a sparsity -is the sparsity bit pattern for x. -This identifies which of the independent variables the variable x -depends on. -\n -\n -\b Input: -The set with index \a arg[1] in \a sparsity -is the sparsity bit pattern for y. -This identifies which of the independent variables the variable y -depends on. -\n -\n -\b Output: -The set with index \a i_z in \a sparsity -is the sparsity bit pattern for z. -This identifies which of the independent variables the variable z -depends on. - -\par Checked Assertions: -\li \a arg[0] < \a i_z -\li \a arg[1] < \a i_z -*/ - -template -inline void forward_sparse_jacobian_binary_op( - size_t i_z , - const addr_t* arg , - Vector_set& sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_z ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z ); - - sparsity.binary_union(i_z, arg[0], arg[1], sparsity); - - return; -} - -/*! -Reverse mode Jacobian sparsity pattern for all binary operators. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = fun(x, y) -\endverbatim -where fun is a C++ unary function and x and y are variables, -or it has the form -\verbatim - z = x op y -\endverbatim -where op is a C++ bianry operator and x and y are variables. - -This routine is given the sparsity patterns -for a function G(z, y, x, ... ) -and it uses them to compute the sparsity patterns for -\verbatim - H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ] -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e., z. - -\param arg -\a arg[0] -variable index corresponding to the left operand for this operator; -i.e., x. - -\n -\n arg[1] -variable index corresponding to the right operand for this operator; -i.e., y. - -\param sparsity -The set with index \a i_z in \a sparsity -is the sparsity pattern for z corresponding ot the function G. -\n -\n -The set with index \a arg[0] in \a sparsity -is the sparsity pattern for x. -On input, it corresponds to the function G, -and on output it corresponds to H. -\n -\n -The set with index \a arg[1] in \a sparsity -is the sparsity pattern for y. -On input, it corresponds to the function G, -and on output it corresponds to H. -\n -\n - -\par Checked Assertions: -\li \a arg[0] < \a i_z -\li \a arg[1] < \a i_z -*/ -template -inline void reverse_sparse_jacobian_binary_op( - size_t i_z , - const addr_t* arg , - Vector_set& sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_z ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z ); - - sparsity.binary_union(arg[0], arg[0], i_z, sparsity); - sparsity.binary_union(arg[1], arg[1], i_z, sparsity); - - return; -} -// --------------------------------------------------------------------------- -/*! -Reverse mode Hessian sparsity pattern for add and subtract operators. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = x op y -\endverbatim -where op is + or - and x, y are variables. - -\copydetails CppAD::local::reverse_sparse_hessian_binary_op -*/ -template -inline void reverse_sparse_hessian_addsub_op( - size_t i_z , - const addr_t* arg , - bool* jac_reverse , - const Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_z ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z ); - - rev_hes_sparsity.binary_union(arg[0], arg[0], i_z, rev_hes_sparsity); - rev_hes_sparsity.binary_union(arg[1], arg[1], i_z, rev_hes_sparsity); - - jac_reverse[arg[0]] |= jac_reverse[i_z]; - jac_reverse[arg[1]] |= jac_reverse[i_z]; - - return; -} - -/*! -Reverse mode Hessian sparsity pattern for multiplication operator. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = x * y -\endverbatim -where x and y are variables. - -\copydetails CppAD::local::reverse_sparse_hessian_binary_op -*/ -template -inline void reverse_sparse_hessian_mul_op( - size_t i_z , - const addr_t* arg , - bool* jac_reverse , - const Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_z ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z ); - - rev_hes_sparsity.binary_union(arg[0], arg[0], i_z, rev_hes_sparsity); - rev_hes_sparsity.binary_union(arg[1], arg[1], i_z, rev_hes_sparsity); - - if( jac_reverse[i_z] ) - { rev_hes_sparsity.binary_union( - arg[0], arg[0], arg[1], for_jac_sparsity); - rev_hes_sparsity.binary_union( - arg[1], arg[1], arg[0], for_jac_sparsity); - } - - jac_reverse[arg[0]] |= jac_reverse[i_z]; - jac_reverse[arg[1]] |= jac_reverse[i_z]; - return; -} - -/*! -Reverse mode Hessian sparsity pattern for division operator. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = x / y -\endverbatim -where x and y are variables. - -\copydetails CppAD::local::reverse_sparse_hessian_binary_op -*/ -template -inline void reverse_sparse_hessian_div_op( - size_t i_z , - const addr_t* arg , - bool* jac_reverse , - const Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_z ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z ); - - rev_hes_sparsity.binary_union(arg[0], arg[0], i_z, rev_hes_sparsity); - rev_hes_sparsity.binary_union(arg[1], arg[1], i_z, rev_hes_sparsity); - - if( jac_reverse[i_z] ) - { rev_hes_sparsity.binary_union( - arg[0], arg[0], arg[1], for_jac_sparsity); - rev_hes_sparsity.binary_union( - arg[1], arg[1], arg[0], for_jac_sparsity); - rev_hes_sparsity.binary_union( - arg[1], arg[1], arg[1], for_jac_sparsity); - } - - jac_reverse[arg[0]] |= jac_reverse[i_z]; - jac_reverse[arg[1]] |= jac_reverse[i_z]; - return; -} - -/*! -Reverse mode Hessian sparsity pattern for power function. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = pow(x, y) -\endverbatim -where x and y are variables. - -\copydetails CppAD::local::reverse_sparse_hessian_binary_op -*/ -template -inline void reverse_sparse_hessian_pow_op( - size_t i_z , - const addr_t* arg , - bool* jac_reverse , - const Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_z ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z ); - - rev_hes_sparsity.binary_union(arg[0], arg[0], i_z, rev_hes_sparsity); - rev_hes_sparsity.binary_union(arg[1], arg[1], i_z, rev_hes_sparsity); - - if( jac_reverse[i_z] ) - { - rev_hes_sparsity.binary_union( - arg[0], arg[0], arg[0], for_jac_sparsity); - rev_hes_sparsity.binary_union( - arg[0], arg[0], arg[1], for_jac_sparsity); - - rev_hes_sparsity.binary_union( - arg[1], arg[1], arg[0], for_jac_sparsity); - rev_hes_sparsity.binary_union( - arg[1], arg[1], arg[1], for_jac_sparsity); - } - - // I cannot think of a case where this is necessary, but it including - // it makes it like the other cases. - jac_reverse[arg[0]] |= jac_reverse[i_z]; - jac_reverse[arg[1]] |= jac_reverse[i_z]; - return; -} -// --------------------------------------------------------------------------- -/*! -Forward mode Hessian sparsity pattern for multiplication operator. - -The C++ source code corresponding to this operation is -\verbatim - w(x) = v0(x) * v1(x) -\endverbatim - -\param arg -is the index of the argument vector for the multiplication operation; i.e., -arg[0], arg[1] are the left and right operands. - -\param for_jac_sparsity -for_jac_sparsity(arg[0]) constains the Jacobian sparsity for v0(x), -for_jac_sparsity(arg[1]) constains the Jacobian sparsity for v1(x). - -\param for_hes_sparsity -On input, for_hes_sparsity includes the Hessian sparsity for v0(x) -and v1(x); i.e., the sparsity can be a super set. -Upon return it includes the Hessian sparsity for w(x) -*/ -template -inline void forward_sparse_hessian_mul_op( - const addr_t* arg , - const Vector_set& for_jac_sparsity , - Vector_set& for_hes_sparsity ) -{ // -------------------------------------------------- - // set of independent variables that v0 depends on - typename Vector_set::const_iterator itr_0(for_jac_sparsity, arg[0]); - - // loop over dependent variables with non-zero partial - size_t i_x = *itr_0; - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(v1) - for_hes_sparsity.binary_union(i_x, i_x, arg[1], for_jac_sparsity); - i_x = *(++itr_0); - } - // -------------------------------------------------- - // set of independent variables that v1 depends on - typename Vector_set::const_iterator itr_1(for_jac_sparsity, arg[1]); - - // loop over dependent variables with non-zero partial - i_x = *itr_1; - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(v0) - for_hes_sparsity.binary_union(i_x, i_x, arg[0], for_jac_sparsity); - i_x = *(++itr_1); - } - return; -} -/*! -Forward mode Hessian sparsity pattern for division operator. - -The C++ source code corresponding to this operation is -\verbatim - w(x) = v0(x) / v1(x) -\endverbatim - -\param arg -is the index of the argument vector for the division operation; i.e., -arg[0], arg[1] are the left and right operands. - -\param for_jac_sparsity -for_jac_sparsity(arg[0]) constains the Jacobian sparsity for v0(x), -for_jac_sparsity(arg[1]) constains the Jacobian sparsity for v1(x). - -\param for_hes_sparsity -On input, for_hes_sparsity includes the Hessian sparsity for v0(x) -and v1(x); i.e., the sparsity can be a super set. -Upon return it includes the Hessian sparsity for w(x) -*/ -template -inline void forward_sparse_hessian_div_op( - const addr_t* arg , - const Vector_set& for_jac_sparsity , - Vector_set& for_hes_sparsity ) -{ // -------------------------------------------------- - // set of independent variables that v0 depends on - typename Vector_set::const_iterator itr_0(for_jac_sparsity, arg[0]); - - // loop over dependent variables with non-zero partial - size_t i_x = *itr_0; - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(v1) - for_hes_sparsity.binary_union(i_x, i_x, arg[1], for_jac_sparsity); - i_x = *(++itr_0); - } - // -------------------------------------------------- - // set of independent variables that v1 depends on - typename Vector_set::const_iterator itr_1(for_jac_sparsity, arg[1]); - - // loop over dependent variables with non-zero partial - i_x = *itr_1; - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(v0) - for_hes_sparsity.binary_union(i_x, i_x, arg[0], for_jac_sparsity); - // N(i_x) = N(i_x) union L(v1) - for_hes_sparsity.binary_union(i_x, i_x, arg[1], for_jac_sparsity); - i_x = *(++itr_1); - } - return; -} -/*! -Forward mode Hessian sparsity pattern for power operator. - -The C++ source code corresponding to this operation is -\verbatim - w(x) = pow( v0(x) , v1(x) ) -\endverbatim - -\param arg -is the index of the argument vector for the power operation; i.e., -arg[0], arg[1] are the left and right operands. - -\param for_jac_sparsity -for_jac_sparsity(arg[0]) constains the Jacobian sparsity for v0(x), -for_jac_sparsity(arg[1]) constains the Jacobian sparsity for v1(x). - -\param for_hes_sparsity -On input, for_hes_sparsity includes the Hessian sparsity for v0(x) -and v1(x); i.e., the sparsity can be a super set. -Upon return it includes the Hessian sparsity for w(x) -*/ -template -inline void forward_sparse_hessian_pow_op( - const addr_t* arg , - const Vector_set& for_jac_sparsity , - Vector_set& for_hes_sparsity ) -{ // -------------------------------------------------- - // set of independent variables that v0 depends on - typename Vector_set::const_iterator itr_0(for_jac_sparsity, arg[0]); - - // loop over dependent variables with non-zero partial - size_t i_x = *itr_0; - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(v0) - for_hes_sparsity.binary_union(i_x, i_x, arg[0], for_jac_sparsity); - // N(i_x) = N(i_x) union L(v1) - for_hes_sparsity.binary_union(i_x, i_x, arg[1], for_jac_sparsity); - i_x = *(++itr_0); - } - // -------------------------------------------------- - // set of independent variables that v1 depends on - typename Vector_set::const_iterator itr_1(for_jac_sparsity, arg[1]); - - // loop over dependent variables with non-zero partial - i_x = *itr_1; - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(v0) - for_hes_sparsity.binary_union(i_x, i_x, arg[0], for_jac_sparsity); - // N(i_x) = N(i_x) union L(v1) - for_hes_sparsity.binary_union(i_x, i_x, arg[1], for_jac_sparsity); - i_x = *(++itr_1); - } - return; -} -// --------------------------------------------------------------------------- -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sparse_internal.hpp b/external/cppad/include/cppad/local/sparse_internal.hpp deleted file mode 100644 index 218affde1..000000000 --- a/external/cppad/include/cppad/local/sparse_internal.hpp +++ /dev/null @@ -1,440 +0,0 @@ -# ifndef CPPAD_LOCAL_SPARSE_INTERNAL_HPP -# define CPPAD_LOCAL_SPARSE_INTERNAL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -// necessary definitions -# include -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sparse_internal.hpp -Routines that enable code to be independent of which internal spasity pattern -is used. -*/ -// --------------------------------------------------------------------------- -/*! -Template structure used obtain the internal sparsity pattern type -form the corresponding element type. -The general form is not valid, must use a specialization. - -\tparam Element_type -type of an element in the sparsity structrue. - -\par internal_sparsity::pattern_type -is the type of the corresponding internal sparsity pattern. -*/ -template struct internal_sparsity; -/// Specilization for \c bool elements. -template <> -struct internal_sparsity -{ - typedef sparse_pack pattern_type; -}; -/// Specilization for std::set elements. -template <> -struct internal_sparsity< std::set > -{ - typedef sparse_list pattern_type; -}; -// --------------------------------------------------------------------------- -/*! -Update the internal sparsity pattern for a sub-set of rows - -\tparam SizeVector -The type used for index sparsity patterns. This is a simple vector -with elements of type size_t. - -\tparam InternalSparsitiy -The type used for intenal sparsity patterns. This can be either -sparse_pack or sparse_list. - -\param zero_empty -If this is true, the internal sparstity pattern corresponds to row zero -must be empty on input and will be emtpy output; i.e., any corresponding -values in pattern_in will be ignored. - -\param input_empty -If this is true, the initial sparsity pattern for row -internal_index[i] is empty for all i. -In this case, one is setting the sparsity patterns; i.e., -the output pattern in row internal_index[i] is the corresponding -entries in pattern. - -\param transpose -If this is true, pattern_in is transposed. - -\param internal_index -This specifies the sub-set of rows in internal_sparsity that we are updating. -If traspose is false (true), -this is the mapping from row (column) index in pattern_in to the corresponding -row index in the internal_pattern. - -\param internal_pattern -On input, the number of sets internal_pattern.n_set(), -and possible elements internal_pattern.end(), have been set. -If input_empty is true, and all of the sets -in internal_index are empty on input. -On output, the entries in pattern_in are added to internal_pattern. -To be specific, suppose transpose is false, and (i, j) is a possibly -non-zero entry in pattern_in, the entry (internal_index[i], j) is added -to internal_pattern. -On the other hand, if transpose is true, -the entry (internal_index[j], i) is added to internal_pattern. - -\param pattern_in -This is the sparsity pattern for variables, -or its transpose, depending on the value of transpose. -*/ -template -void set_internal_sparsity( - bool zero_empty , - bool input_empty , - bool transpose , - const vector& internal_index , - InternalSparsity& internal_pattern , - const sparse_rc& pattern_in ) -{ -# ifndef NDEBUG - size_t nr = internal_index.size(); - size_t nc = internal_pattern.end(); - if( transpose ) - { CPPAD_ASSERT_UNKNOWN( pattern_in.nr() == nc ); - CPPAD_ASSERT_UNKNOWN( pattern_in.nc() == nr ); - } - else - { CPPAD_ASSERT_UNKNOWN( pattern_in.nr() == nr ); - CPPAD_ASSERT_UNKNOWN( pattern_in.nc() == nc ); - } - if( input_empty ) for(size_t i = 0; i < nr; i++) - { size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( internal_pattern.number_elements(i_var) == 0 ); - } -# endif - const SizeVector& row( pattern_in.row() ); - const SizeVector& col( pattern_in.col() ); - size_t nnz = row.size(); - for(size_t k = 0; k < nnz; k++) - { size_t r = row[k]; - size_t c = col[k]; - if( transpose ) - std::swap(r, c); - // - size_t i_var = internal_index[r]; - CPPAD_ASSERT_UNKNOWN( i_var < internal_pattern.n_set() ); - CPPAD_ASSERT_UNKNOWN( c < nc ); - bool ignore = zero_empty && i_var == 0; - if( ! ignore ) - internal_pattern.add_element( internal_index[r], c ); - } -} -template -void set_internal_sparsity( - bool zero_empty , - bool input_empty , - bool transpose , - const vector& internal_index , - InternalSparsity& internal_pattern , - const vectorBool& pattern_in ) -{ size_t nr = internal_index.size(); - size_t nc = internal_pattern.end(); -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( pattern_in.size() == nr * nc ); - if( input_empty ) for(size_t i = 0; i < nr; i++) - { size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( internal_pattern.number_elements(i_var) == 0 ); - } -# endif - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j < nc; j++) - { bool flag = pattern_in[i * nc + j]; - if( transpose ) - flag = pattern_in[j * nr + i]; - if( flag ) - { size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( i_var < internal_pattern.n_set() ); - CPPAD_ASSERT_UNKNOWN( j < nc ); - bool ignore = zero_empty && i_var == 0; - if( ! ignore ) - internal_pattern.add_element( i_var, j); - } - } - } - return; -} -template -void set_internal_sparsity( - bool zero_empty , - bool input_empty , - bool transpose , - const vector& internal_index , - InternalSparsity& internal_pattern , - const vector& pattern_in ) -{ size_t nr = internal_index.size(); - size_t nc = internal_pattern.end(); -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( pattern_in.size() == nr * nc ); - if( input_empty ) for(size_t i = 0; i < nr; i++) - { size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( internal_pattern.number_elements(i_var) == 0 ); - } -# endif - for(size_t i = 0; i < nr; i++) - { for(size_t j = 0; j < nc; j++) - { bool flag = pattern_in[i * nc + j]; - if( transpose ) - flag = pattern_in[j * nr + i]; - if( flag ) - { size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( i_var < internal_pattern.n_set() ); - CPPAD_ASSERT_UNKNOWN( j < nc ); - bool ignore = zero_empty && i_var == 0; - if( ! ignore ) - internal_pattern.add_element( i_var, j); - } - } - } - return; -} -template -void set_internal_sparsity( - bool zero_empty , - bool input_empty , - bool transpose , - const vector& internal_index , - InternalSparsity& internal_pattern , - const vector< std::set >& pattern_in ) -{ size_t nr = internal_index.size(); - size_t nc = internal_pattern.end(); -# ifndef NDEBUG - if( input_empty ) for(size_t i = 0; i < nr; i++) - { size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( internal_pattern.number_elements(i_var) == 0 ); - } -# endif - if( transpose ) - { CPPAD_ASSERT_UNKNOWN( pattern_in.size() == nc ); - for(size_t j = 0; j < nc; j++) - { std::set::const_iterator itr( pattern_in[j].begin() ); - while( itr != pattern_in[j].end() ) - { size_t i = *itr; - size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( i_var < internal_pattern.n_set() ); - CPPAD_ASSERT_UNKNOWN( j < nc ); - bool ignore = zero_empty && i_var == 0; - if( ! ignore ) - internal_pattern.add_element( i_var, j); - ++itr; - } - } - } - else - { CPPAD_ASSERT_UNKNOWN( pattern_in.size() == nr ); - for(size_t i = 0; i < nr; i++) - { std::set::const_iterator itr( pattern_in[i].begin() ); - while( itr != pattern_in[i].end() ) - { size_t j = *itr; - size_t i_var = internal_index[i]; - CPPAD_ASSERT_UNKNOWN( i_var < internal_pattern.n_set() ); - CPPAD_ASSERT_UNKNOWN( j < nc ); - bool ignore = zero_empty && i_var == 0; - if( ! ignore ) - internal_pattern.add_element( i_var, j); - ++itr; - } - } - } - return; -} -// --------------------------------------------------------------------------- -/*! -Get sparsity pattern for a sub-set of variables - -\tparam SizeVector -The type used for index sparsity patterns. This is a simple vector -with elements of type size_t. - -\tparam InternalSparsitiy -The type used for intenal sparsity patterns. This can be either -sparse_pack or sparse_list. - -\param transpose -If this is true, pattern_out is transposed. - -\param internal_index -If transpose is false (true) -this is the mapping from row (column) an index in pattern_out -to the corresponding row index in internal_pattern. - -\param internal_pattern -This is the internal sparsity pattern. - -\param pattern_out -The input value of pattern_out does not matter. -Upon return it is an index sparsity pattern for each of the variables -in internal_index, or its transpose, depending on the value of transpose. -*/ -template -void get_internal_sparsity( - bool transpose , - const vector& internal_index , - const InternalSparsity& internal_pattern , - sparse_rc& pattern_out ) -{ typedef typename InternalSparsity::const_iterator iterator; - // number variables - size_t nr = internal_index.size(); - // column size of interanl sparstiy pattern - size_t nc = internal_pattern.end(); - // determine nnz, the number of possibly non-zero index pairs - size_t nnz = 0; - for(size_t i = 0; i < nr; i++) - { CPPAD_ASSERT_UNKNOWN( internal_index[i] < internal_pattern.n_set() ); - iterator itr(internal_pattern, internal_index[i]); - size_t j = *itr; - while( j < nc ) - { ++nnz; - j = *(++itr); - } - } - // transposed - if( transpose ) - { pattern_out.resize(nc, nr, nnz); - // - size_t k = 0; - for(size_t i = 0; i < nr; i++) - { iterator itr(internal_pattern, internal_index[i]); - size_t j = *itr; - while( j < nc ) - { pattern_out.set(k++, j, i); - j = *(++itr); - } - } - return; - } - // not transposed - pattern_out.resize(nr, nc, nnz); - // - size_t k = 0; - for(size_t i = 0; i < nr; i++) - { iterator itr(internal_pattern, internal_index[i]); - size_t j = *itr; - while( j < nc ) - { pattern_out.set(k++, i, j); - j = *(++itr); - } - } - return; -} -template -void get_internal_sparsity( - bool transpose , - const vector& internal_index , - const InternalSparsity& internal_pattern , - vectorBool& pattern_out ) -{ typedef typename InternalSparsity::const_iterator iterator; - // number variables - size_t nr = internal_index.size(); - // - // column size of interanl sparstiy pattern - size_t nc = internal_pattern.end(); - // - pattern_out.resize(nr * nc); - for(size_t ij = 0; ij < nr * nc; ij++) - pattern_out[ij] = false; - // - for(size_t i = 0; i < nr; i++) - { CPPAD_ASSERT_UNKNOWN( internal_index[i] < internal_pattern.n_set() ); - iterator itr(internal_pattern, internal_index[i]); - size_t j = *itr; - while( j < nc ) - { if( transpose ) - pattern_out[j * nr + i] = true; - else - pattern_out[i * nc + j] = true; - j = *(++itr); - } - } - return; -} -template -void get_internal_sparsity( - bool transpose , - const vector& internal_index , - const InternalSparsity& internal_pattern , - vector& pattern_out ) -{ typedef typename InternalSparsity::const_iterator iterator; - // number variables - size_t nr = internal_index.size(); - // - // column size of interanl sparstiy pattern - size_t nc = internal_pattern.end(); - // - pattern_out.resize(nr * nc); - for(size_t ij = 0; ij < nr * nc; ij++) - pattern_out[ij] = false; - // - for(size_t i = 0; i < nr; i++) - { CPPAD_ASSERT_UNKNOWN( internal_index[i] < internal_pattern.n_set() ); - iterator itr(internal_pattern, internal_index[i]); - size_t j = *itr; - while( j < nc ) - { if( transpose ) - pattern_out[j * nr + i] = true; - else - pattern_out[i * nc + j] = true; - j = *(++itr); - } - } - return; -} -template -void get_internal_sparsity( - bool transpose , - const vector& internal_index , - const InternalSparsity& internal_pattern , - vector< std::set >& pattern_out ) -{ typedef typename InternalSparsity::const_iterator iterator; - // number variables - size_t nr = internal_index.size(); - // - // column size of interanl sparstiy pattern - size_t nc = internal_pattern.end(); - // - if( transpose ) - pattern_out.resize(nc); - else - pattern_out.resize(nr); - for(size_t k = 0; k < pattern_out.size(); k++) - pattern_out[k].clear(); - // - for(size_t i = 0; i < nr; i++) - { CPPAD_ASSERT_UNKNOWN( internal_index[i] < internal_pattern.n_set() ); - iterator itr(internal_pattern, internal_index[i]); - size_t j = *itr; - while( j < nc ) - { if( transpose ) - pattern_out[j].insert(i); - else - pattern_out[i].insert(j); - j = *(++itr); - } - } - return; -} - - - -} } // END_CPPAD_LOCAL_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/local/sparse_list.hpp b/external/cppad/include/cppad/local/sparse_list.hpp deleted file mode 100644 index e6e631800..000000000 --- a/external/cppad/include/cppad/local/sparse_list.hpp +++ /dev/null @@ -1,1102 +0,0 @@ -# ifndef CPPAD_LOCAL_SPARSE_LIST_HPP -# define CPPAD_LOCAL_SPARSE_LIST_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sparse_list.hpp -Vector of sets of positive integers stored as singly linked lists -in with the element values strictly increasing. -*/ - -// ========================================================================= -/*! -Vector of sets of positive integers, each set stored as a singly -linked list. -*/ -class sparse_list_const_iterator; -class sparse_list { - friend class sparse_list_const_iterator; -public: - /// declare a const iterator - typedef sparse_list_const_iterator const_iterator; - - /// type used for each entry in a singly linked list. - struct pair_size_t { - /// For the first entry in each list, this is the reference count. - /// For the other entries in the list this is an element of the set. - size_t value; - - /// This is the index in data_ of the next entry in the list. - /// If there are no more entries in the list, this value is zero. - /// (The first entry in data_ is not used.) - size_t next; - }; -private: - // ----------------------------------------------------------------- - /// Possible elements in each set are 0, 1, ..., end_ - 1; - size_t end_; - - /// number of elements in data_ that have been allocated - /// and are no longer being used. - size_t data_not_used_; - - /*! - The number of elements in this vector is the number of sets, - which is also the number of singly linked lists. - - \li - If the i-th set has no elements, start_[i] is zero. - - \li - If the i-th set is non-empty, start_[i] is the index in data_ - for the first entry in the i-th singly linked list for this set. - In this case and data_[ start_[i] ].value is the reference count - for this list and data_[ start_[i] ].next is not zero because there - is at least one entry in this list. - */ - pod_vector start_; - - /// The data for all the singly linked lists. - pod_vector data_; - - // ----------------------------------------------------------------- - /*! - Private member functiont that counts references to sets. - - \param index - is the index of the set that we are counting the references to. - - \return - if the set is empty, the return value is empty. - Otherwise it is the number of sets that share the same linked list - */ - size_t reference_count(size_t index) const - { size_t ret = start_[index]; - if( ret != 0 ) - { CPPAD_ASSERT_UNKNOWN( data_[ret].value != 0 ); - CPPAD_ASSERT_UNKNOWN( data_[ret].next != 0 ); - ret = data_[ret].value; - } - return ret; - } - // ----------------------------------------------------------------- - /*! - Member function that checks the number of data elements not used - (effectively const, but modifies and restores values) - */ - void check_data_not_used(void) - { // number of sets - size_t n_set = start_.size(); - // - // save the reference counters - pod_vector ref_count; - ref_count.extend(n_set); - for(size_t i = 0; i < n_set; i++) - ref_count[i] = reference_count(i); - - // count the number of entries in the singly linked lists - size_t number_list_entries = 0; - for(size_t i = 0; i < start_.size(); i++) - { size_t start = start_[i]; - if( start != 0 ) - { CPPAD_ASSERT_UNKNOWN( data_[start].value > 0 ); - // decrement the reference counter - data_[start].value--; - // copy the list when we hit zero - if( data_[start].value == 0 ) - { // This should be the last reference to this linked list. - // Restore reference count - data_[start].value = ref_count[i]; - // count number of entries in this list - // (is one more than number in set) - number_list_entries += number_elements(i) + 1; - } - } - } - CPPAD_ASSERT_UNKNOWN( - number_list_entries + data_not_used_ == data_.size() - ); - return; - } - // ----------------------------------------------------------------- - /*! - Check if one of two sets is a subset of the other set - - \param one_this - is the index in this sparse_list object of the first set. - - \param two_other - is the index in other sparse_list object of the second set. - - \param other - is the other sparse_list object (which may be the same as this - sparse_list object). - - \return - If zero, niether set is a subset of the other. - If one, then the two sets are equal. - If two, then set one is a subset of set two and not equal set two. - If three, then set two is a subset of set one and not equal set one.. - */ - size_t is_subset( - size_t one_this , - size_t two_other , - const sparse_list& other ) const - { - CPPAD_ASSERT_UNKNOWN( one_this < start_.size() ); - CPPAD_ASSERT_UNKNOWN( two_other < other.start_.size() ); - CPPAD_ASSERT_UNKNOWN( end_ == other.end_ ); - // - // start - size_t start_one = start_[one_this]; - size_t start_two = other.start_[two_other]; - // - if( start_one == 0 ) - { // set one is empty - if( start_two == 0 ) - { // set two is empty - return 1; - } - return 2; - } - if( start_two == 0 ) - { // set two is empty and one is not empty - return 3; - } - // - // next - size_t next_one = data_[start_one].next; - size_t next_two = other.data_[start_two].next; - // - // value - size_t value_one = data_[next_one].value; - size_t value_two = other.data_[next_two].value; - // - bool one_subset = true; - bool two_subset = true; - // - size_t value_union = std::min(value_one, value_two); - while( (one_subset | two_subset) & (value_union < end_) ) - { if( value_one > value_union ) - two_subset = false; - else - { next_one = data_[next_one].next; - if( next_one == 0 ) - value_one = end_; - else - value_one = data_[next_one].value; - } - if( value_two > value_union ) - one_subset = false; - else - { next_two = other.data_[next_two].next; - if( next_two == 0 ) - value_two = end_; - else - value_two = other.data_[next_two].value; - } - value_union = std::min(value_one, value_two); - } - if( one_subset ) - { if( two_subset ) - { // sets are equal - return 1; - } - // one is a subset of two - return 2; - } - if( two_subset ) - { // two is a subset of on - return 3; - } - // - // neither is a subset - return 0; - } - // ----------------------------------------------------------------- - /*! - Private member functions that does garbage collection. - - This routine should be called when the number entries in data_ - that are not being used is greater that data_.size() / 2. - - Note that the size of data_ should equal the number of entries - in the singly linked lists plust the number of entries in data_ - that are not being used. (Note that data_[0] never gets used.) - */ - void collect_garbage(void) - { CPPAD_ASSERT_UNKNOWN( data_not_used_ > data_.size() / 2 ); -# ifndef NDEBUG - check_data_not_used(); -# endif - // - // number of sets including empty ones - size_t n_set = start_.size(); - // - // copy the sets to a temporary data vector - pod_vector data_tmp; - data_tmp.extend(1); // data_tmp[0] will not be used - // - pod_vector start_tmp; - start_tmp.extend(n_set); - for(size_t i = 0; i < n_set; i++) - { size_t start = start_[i]; - if( start == 0 ) - start_tmp[i] = 0; - else - { // check if this linked list has already been copied - if( data_[start].next == 0 ) - { // starting address in data_tmp has been stored here - start_tmp[i] = data_[start].value; - } - else - { size_t count = data_[start].value; - size_t next = data_[start].next; - // - size_t tmp_start = data_tmp.extend(2); - size_t next_tmp = tmp_start + 1; - start_tmp[i] = tmp_start; - data_tmp[tmp_start].value = count; - data_tmp[tmp_start].next = next_tmp; - // - CPPAD_ASSERT_UNKNOWN( next != 0 ); - while( next != 0 ) - { CPPAD_ASSERT_UNKNOWN( data_[next].value < end_ ); - data_tmp[next_tmp].value = data_[next].value; - // - next = data_[next].next; - if( next == 0 ) - data_tmp[next_tmp].next = 0; - else - { // data_tmp[next_tmp].next = data_tmp.extend(1); - // does not seem to work ? - size_t tmp = data_tmp.extend(1); - data_tmp[next_tmp].next = tmp; - next_tmp = tmp; - } - } - // store the starting address here - data_[start].value = tmp_start; - // flag that indicates this link list already copied - data_[start].next = 0; - } - } - } - - // swap the tmp and old data vectors - start_.swap(start_tmp); - data_.swap(data_tmp); - - // all of the elements, except the first, are used - data_not_used_ = 1; - } - // ----------------------------------------------------------------- - /*! - Make a separate copy of the shared list - - \param index - is the index, in the vector of sets, for this list. - */ - void separate_copy(size_t index) - { size_t ref_count = reference_count(index); - if( ref_count <= 1 ) - return; - // - size_t start = start_[index]; - size_t next = data_[start].next; - size_t value = data_[next].value; - // - size_t copy_cur = data_.extend(2); - size_t copy_next = copy_cur + 1; - start_[index] = copy_cur; - data_[copy_cur].value = 1; - data_[copy_cur].next = copy_next; - copy_cur = copy_next; - // - CPPAD_ASSERT_UNKNOWN( value < end_ ); - while( value < end_ ) - { data_[copy_cur].value = value; - // - next = data_[next].next; - if( next == 0 ) - { value = end_; - data_[copy_cur].next = 0; - } - else - { value = data_[next].value; - data_[copy_cur].next = data_.extend(1); - } - } - CPPAD_ASSERT_UNKNOWN( next == 0 ); - // - // decrement reference count - CPPAD_ASSERT_UNKNOWN( data_[start].value == ref_count ); - data_[start].value--; - // - } - // ----------------------------------------------------------------- - /*! Using copy constructor is a programing (not user) error - - \param v - vector of sets that we are attempting to make a copy of. - */ - sparse_list(const sparse_list& v) - { // Error: Probably a sparse_list argument has been passed by value - CPPAD_ASSERT_UNKNOWN(false); - } -public: - // ----------------------------------------------------------------- - /*! Default constructor (no sets) - */ - sparse_list(void) : - end_(0) , - data_not_used_(0) - { } - // ----------------------------------------------------------------- - /// Destructor - ~sparse_list(void) - { -# ifndef NDEBUG - check_data_not_used(); -# endif - } - // ----------------------------------------------------------------- - /*! - Start a new vector of sets. - - \param n_set_in - is the number of sets in this vector of sets. - \li - If n_set_in is zero, any memory currently allocated for this object - is freed. Otherwise, new memory may be allocated for the sets (if needed). - \li - If n_set_in is non-zero, a vector of n_set_in is created and all - the sets are initilaized as empty. - - \param end_in - is the maximum element plus one (the minimum element is 0). - */ - void resize(size_t n_set_in, size_t end_in) - { -# ifndef NDEBUG - check_data_not_used(); -# endif - if( n_set_in == 0 ) - { // restore object to start after constructor - // (no memory allocated for this object) - data_.free(); - start_.free(); - data_not_used_ = 0; - end_ = 0; - // - return; - } - end_ = end_in; - // - start_.erase(); - start_.extend(n_set_in); - for(size_t i = 0; i < n_set_in; i++) - start_[i] = 0; - // - data_.erase(); - data_.extend(1); // first element is not used - data_not_used_ = 1; - } - // ----------------------------------------------------------------- - /*! - Count number of elements in a set. - - \param index - is the index of the set we are counting the elements of. - */ - size_t number_elements(size_t index) const - { CPPAD_ASSERT_UNKNOWN(index < start_.size() ); - - size_t count = 0; - size_t start = start_[index]; - - // check if the set is empty - if( start == 0 ) - return count; - CPPAD_ASSERT_UNKNOWN( reference_count(index) > 0 ); - - // advance to the first element in the set - size_t next = data_[start].next; - while( next != 0 ) - { CPPAD_ASSERT_UNKNOWN( data_[next].value < end_ ); - count++; - next = data_[next].next; - } - CPPAD_ASSERT_UNKNOWN( count > 0 ); - return count; - } - // ----------------------------------------------------------------- - /*! - check an element is in a set. - - \param index - is the index for this set in the vector of sets. - - \param element - is the element we are checking to see if it is in the set. - */ - bool is_element(size_t index, size_t element) const - { CPPAD_ASSERT_UNKNOWN( index < start_.size() ); - CPPAD_ASSERT_UNKNOWN( element < end_ ); - // - size_t start = start_[index]; - if( start == 0 ) - return false; - // - CPPAD_ASSERT_UNKNOWN( data_[start].value > 0 ); - CPPAD_ASSERT_UNKNOWN( data_[start].next > 0 ); - // - size_t next = data_[start].next; - size_t value = data_[next].value; - while( value < element ) - { next = data_[next].next; - if( next == 0 ) - value = end_; - else - value = data_[next].value; - } - return element == value; - } - // ----------------------------------------------------------------- - /*! - Add one element to a set. - - \param index - is the index for this set in the vector of sets. - - \param element - is the element we are adding to the set. - */ - void add_element(size_t index, size_t element) - { CPPAD_ASSERT_UNKNOWN( index < start_.size() ); - CPPAD_ASSERT_UNKNOWN( element < end_ ); - - // check if element is already in the set - if( is_element(index, element) ) - return; - - // check for case where starting set is empty - size_t start = start_[index]; - if( start == 0 ) - { start = data_.extend(2); - start_[index] = start; - size_t next = start + 1; - data_[start].value = 1; // reference count - data_[start].next = next; - data_[next].value = element; - data_[next].next = 0; - return; - } - // make sure that we have a separate copy of this set - separate_copy(index); - // - // start of list with this index (after separate_copy) - size_t previous = start_[index]; - // check reference count for this list - CPPAD_ASSERT_UNKNOWN( data_[previous].value == 1 ); - // first entry in this list (which starts out non-empty) - size_t next = data_[previous].next; - size_t value = data_[next].value; - CPPAD_ASSERT_UNKNOWN( value < end_ ); - // locate place to insert this element - while( value < element ) - { previous = next; - next = data_[next].next; - if( next == 0 ) - value = end_; - else - value = data_[next].value; - } - CPPAD_ASSERT_UNKNOWN( element < value ) - // - size_t insert = data_.extend(1); - data_[insert].next = next; - data_[previous].next = insert; - data_[insert].value = element; - } - // ----------------------------------------------------------------- - /*! Assign the empty set to one of the sets. - - \param target - is the index of the set we are setting to the empty set. - - \par data_not_used_ - increments this value by number of data_ elements that are lost - (unlinked) by this operation. - */ - void clear(size_t target) - { CPPAD_ASSERT_UNKNOWN( target < start_.size() ); - - // number of references to this set - size_t ref_count = reference_count(target); - - // case by reference count - if( ref_count > 1 ) - { // just remove this reference - size_t start = start_[target]; - start_[target] = 0; - CPPAD_ASSERT_UNKNOWN( data_[start].value == ref_count ); - data_[start].value--; - } - else if( ref_count == 1 ) - { - // number of data_ elements that will be lost by this operation - size_t number_delete = number_elements(target) + 1; - - // delete the elements from the set - start_[target] = 0; - - // adjust data_not_used_ - data_not_used_ += number_delete; - - if( data_not_used_ > data_.size() / 2 + 100 ) - collect_garbage(); - } - // - } - // ----------------------------------------------------------------- - /*! Assign one set equal to another set. - - \param this_target - is the index in this sparse_list object of the set being assinged. - - \param other_source - is the index in the other \c sparse_list object of the - set that we are using as the value to assign to the target set. - - \param other - is the other sparse_list object (which may be the same as this - sparse_list object). This must have the same value for end_. - - \par data_not_used_ - increments this value by number of elements lost. - */ - void assignment( - size_t this_target , - size_t other_source , - const sparse_list& other ) - { CPPAD_ASSERT_UNKNOWN( this_target < start_.size() ); - CPPAD_ASSERT_UNKNOWN( other_source < other.start_.size() ); - CPPAD_ASSERT_UNKNOWN( end_ == other.end_ ); - - // check if we are assigning a set to itself - if( (this == &other) & (this_target == other_source) ) - return; - - // number of list elements that will be deleted by this operation - size_t number_delete = 0; - size_t ref_count = reference_count(this_target); - size_t start = start_[this_target]; - if( ref_count == 1 ) - number_delete = number_elements(this_target) + 1; - else if (ref_count > 1 ) - { // decrement reference counter - CPPAD_ASSERT_UNKNOWN( data_[start].value > 1 ) - data_[start].value--; - } - - // If this and other are the same, use another reference to same list - size_t other_start = other.start_[other_source]; - if( this == &other ) - { start_[this_target] = other_start; - if( other_start != 0 ) - { data_[other_start].value++; // increment reference count - CPPAD_ASSERT_UNKNOWN( data_[other_start].value > 1 ); - } - } - else if( other_start == 0 ) - { // the target list is empty - start_[this_target] = 0; - } - else - { // make a copy of the other list in this sparse_list - size_t this_start = data_.extend(2); - size_t this_next = this_start + 1; - start_[this_target] = this_start; - data_[this_start].value = 1; // reference count - data_[this_start].next = this_next; - // - size_t next = other.data_[other_start].next; - CPPAD_ASSERT_UNKNOWN( next != 0 ); - while( next != 0 ) - { data_[this_next].value = other.data_[next].value; - next = other.data_[next].next; - if( next == 0 ) - data_[this_next].next = 0; - else - { size_t tmp = data_.extend(1); - data_[this_next].next = tmp; - this_next = tmp; - } - } - } - - // adjust data_not_used_ - data_not_used_ += number_delete; - - // check if time for garbage collection - if( data_not_used_ > data_.size() / 2 + 100 ) - collect_garbage(); - } - // ----------------------------------------------------------------- - /*! Assign a set equal to the union of two other sets. - - \param this_target - is the index in this sparse_list object of the set being assinged. - - \param this_left - is the index in this sparse_list object of the - left operand for the union operation. - It is OK for this_target and this_left to be the same value. - - \param other_right - is the index in the other sparse_list object of the - right operand for the union operation. - It is OK for this_target and other_right to be the same value. - - \param other - is the other sparse_list object (which may be the same as this - sparse_list object). - */ - void binary_union( - size_t this_target , - size_t this_left , - size_t other_right , - const sparse_list& other ) - { - CPPAD_ASSERT_UNKNOWN( this_target < start_.size() ); - CPPAD_ASSERT_UNKNOWN( this_left < start_.size() ); - CPPAD_ASSERT_UNKNOWN( other_right < other.start_.size() ); - CPPAD_ASSERT_UNKNOWN( end_ == other.end_ ); - - // check if one of the two operands is a subset of the the other - size_t subset = is_subset(this_left, other_right, other); - - // case where right is a subset of left or right and left are equal - if( subset == 1 || subset == 3 ) - { assignment(this_target, this_left, *this); - return; - } - // case where the left is a subset of right and they are not equal - if( subset == 2 ) - { assignment(this_target, other_right, other); - return; - } - // if niether case holds, then both left and right are non-empty - CPPAD_ASSERT_UNKNOWN( reference_count(this_left) > 0 ); - CPPAD_ASSERT_UNKNOWN( other.reference_count(other_right) > 0 ); - - // must get all the start indices before modify start_this - // (incase start_this is the same as start_left or start_right) - size_t start_target = start_[this_target]; - size_t start_left = start_[this_left]; - size_t start_right = other.start_[other_right]; - - - // number of list elements that will be deleted by this operation - size_t number_delete = 0; - size_t ref_count = reference_count(this_target); - if( ref_count == 1 ) - number_delete = number_elements(this_target) + 1; - else if (ref_count > 1 ) - { // decrement reference counter - CPPAD_ASSERT_UNKNOWN( data_[start_target].value > 1 ) - data_[start_target].value--; - } - - // start the new list - size_t start = data_.extend(1); - size_t next = start; - start_[this_target] = start; - data_[start].value = 1; // reference count - - // next for left and right lists - size_t next_left = data_[start_left].next; - size_t next_right = other.data_[start_right].next; - - // value for left and right sets - size_t value_left = data_[next_left].value; - size_t value_right = other.data_[next_right].value; - - CPPAD_ASSERT_UNKNOWN( value_left < end_ && value_right < end_ ); - while( (value_left < end_) | (value_right < end_) ) - { if( value_left == value_right ) - { // advance right so left and right are no longer equal - next_right = other.data_[next_right].next; - if( next_right == 0 ) - value_right = end_; - else - value_right = other.data_[next_right].value; - } - if( value_left < value_right ) - { size_t tmp = data_.extend(1); - data_[next].next = tmp; - next = tmp; - data_[next].value = value_left; - // advance left to its next element - next_left = data_[next_left].next; - if( next_left == 0 ) - value_left = end_; - else - value_left = data_[next_left].value; - } - else - { CPPAD_ASSERT_UNKNOWN( value_right < value_left ) - size_t tmp = data_.extend(1); - data_[next].next = tmp; - next = tmp; - data_[next].value = value_right; - // advance right to its next element - next_right = other.data_[next_right].next; - if( next_right == 0 ) - value_right = end_; - else - value_right = other.data_[next_right].value; - } - } - data_[next].next = 0; - - // adjust data_not_used_ - data_not_used_ += number_delete; - - if( data_not_used_ > data_.size() / 2 + 100 ) - collect_garbage(); - } - // ----------------------------------------------------------------- - /*! Assign a set equal to the intersection of two other sets. - - \param this_target - is the index in this sparse_list object of the set being assinged. - - \param this_left - is the index in this sparse_list object of the - left operand for the intersection operation. - It is OK for this_target and this_left to be the same value. - - \param other_right - is the index in the other sparse_list object of the - right operand for the intersection operation. - It is OK for this_target and other_right to be the same value. - - \param other - is the other sparse_list object (which may be the same as this - sparse_list object). - */ - void binary_intersection( - size_t this_target , - size_t this_left , - size_t other_right , - const sparse_list& other ) - { - CPPAD_ASSERT_UNKNOWN( this_target < start_.size() ); - CPPAD_ASSERT_UNKNOWN( this_left < start_.size() ); - CPPAD_ASSERT_UNKNOWN( other_right < other.start_.size() ); - CPPAD_ASSERT_UNKNOWN( end_ == other.end_ ); - // - // check if one of the two operands is a subset of the the other - size_t subset = is_subset(this_left, other_right, other); - - // case where left is a subset of right or left and right are equal - if( subset == 1 || subset == 2 ) - { assignment(this_target, this_left, *this); - return; - } - // case where the right is a subset of left and they are not equal - if( subset == 3 ) - { assignment(this_target, other_right, other); - return; - } - // if niether case holds, then both left and right are non-empty - CPPAD_ASSERT_UNKNOWN( reference_count(this_left) > 0 ); - CPPAD_ASSERT_UNKNOWN( other.reference_count(other_right) > 0 ); - - // must get all the start indices before modify start_this - // (incase start_this is the same as start_left or start_right) - size_t start_target = start_[this_target]; - size_t start_left = start_[this_left]; - size_t start_right = other.start_[other_right]; - - - // number of list elements that will be deleted by this operation - size_t number_delete = 0; - size_t ref_count = reference_count(this_target); - if( ref_count == 1 ) - number_delete = number_elements(this_target) + 1; - else if (ref_count > 1 ) - { // decrement reference counter - CPPAD_ASSERT_UNKNOWN( data_[start_target].value > 1 ) - data_[start_target].value--; - } - - // start the new list as emptyh - size_t start = 0; - size_t next = start; - start_[this_target] = start; - - // next for left and right lists - size_t next_left = data_[start_left].next; - size_t next_right = other.data_[start_right].next; - - // value for left and right sets - size_t value_left = data_[next_left].value; - size_t value_right = other.data_[next_right].value; - - CPPAD_ASSERT_UNKNOWN( value_left < end_ && value_right < end_ ); - while( (value_left < end_) & (value_right < end_) ) - { if( value_left == value_right ) - { if( start == 0 ) - { // this is the first element in the intersection - start = data_.extend(1); - next = start; - start_[this_target] = start; - data_[start].value = 1; // reference count - CPPAD_ASSERT_UNKNOWN( start > 0 ); - } - size_t tmp = data_.extend(1); - data_[next].next = tmp; - next = tmp; - data_[next].value = value_left; - // - // advance left to its next element - next_left = data_[next_left].next; - if( next_left == 0 ) - value_left = end_; - else - value_left = data_[next_left].value; - // - } - if( value_left > value_right ) - { // advance right - next_right = other.data_[next_right].next; - if( next_right == 0 ) - value_right = end_; - else - value_right = other.data_[next_right].value; - } - if( value_right > value_left ) - { // advance left - next_left = data_[next_left].next; - if( next_left == 0 ) - value_left = end_; - else - value_left = data_[next_left].value; - } - } - if( start != 0 ) - { CPPAD_ASSERT_UNKNOWN( next != 0 ); - data_[next].next = 0; - } - - // adjust data_not_used_ - data_not_used_ += number_delete; - // - if( data_not_used_ > data_.size() / 2 + 100 ) - collect_garbage(); - } - // ----------------------------------------------------------------- - /*! Fetch n_set for vector of sets object. - - \return - Number of from sets for this vector of sets object - */ - size_t n_set(void) const - { return start_.size(); } - // ----------------------------------------------------------------- - /*! Fetch end for this vector of sets object. - - \return - is the maximum element value plus one (the minimum element value is 0). - */ - size_t end(void) const - { return end_; } - // ----------------------------------------------------------------- - /*! Amount of memory used by this vector of sets - - \return - The amount of memory in units of type unsigned char memory. - */ - size_t memory(void) const - { return data_.capacity() * sizeof(pair_size_t); - } - /*! - Print the vector of sets (used for debugging) - */ - void print(void) const; -}; -// ========================================================================= -/*! -cons_iterator for one set of positive integers in a sparse_list object. -*/ -class sparse_list_const_iterator { -private: - /// type used by sparse_list to represent one element of the list - typedef sparse_list::pair_size_t pair_size_t; - - /// data for the entire vector of sets - const pod_vector& data_; - - /// Possible elements in a list are 0, 1, ..., end_ - 1; - const size_t end_; - - /// next element in the singly linked list - /// (next_pair_.value == end_ for past end of list) - pair_size_t next_pair_; -public: - /// construct a const_iterator for a list in a sparse_list object - sparse_list_const_iterator (const sparse_list& list, size_t index) - : - data_( list.data_ ) , - end_ ( list.end_ ) - { CPPAD_ASSERT_UNKNOWN( index < list.start_.size() ); - size_t start = list.start_[index]; - if( start == 0 ) - { next_pair_.next = 0; - next_pair_.value = end_; - } - else - { // value for this entry is reference count for list - CPPAD_ASSERT_UNKNOWN( data_[start].value > 0 ); - - // index where list truely starts - size_t next = data_[start].next; - CPPAD_ASSERT_UNKNOWN( next != 0 ); - - // true first entry in the list - next_pair_ = data_[next]; - CPPAD_ASSERT_UNKNOWN( next_pair_.value < end_ ); - } - } - - /// advance to next element in this list - sparse_list_const_iterator& operator++(void) - { if( next_pair_.next == 0 ) - next_pair_.value = end_; - else - { next_pair_ = data_[next_pair_.next]; - CPPAD_ASSERT_UNKNOWN( next_pair_.value < end_ ); - } - return *this; - } - - /// obtain value of this element of the set of positive integers - /// (end_ for no such element) - size_t operator*(void) - { return next_pair_.value; } -}; -// ========================================================================= -/*! -Print the vector of sets (used for debugging) -*/ -inline void sparse_list::print(void) const -{ std::cout << "sparse_list:\n"; - for(size_t i = 0; i < n_set(); i++) - { std::cout << "set[" << i << "] = {"; - const_iterator itr(*this, i); - while( *itr != end() ) - { std::cout << *itr; - if( *(++itr) != end() ) - std::cout << ","; - } - std::cout << "}\n"; - } - return; -} -// ========================================================================= -// Tell pod_vector class that each pair_size_t is plain old data and hence -// the corresponding constructor need not be called. -template <> inline bool is_pod(void) -{ return true; } - -/*! -Copy a user vector of sets sparsity pattern to an internal sparse_list object. - -\tparam VectorSet -is a simple vector with elements of type std::set. - -\param internal -The input value of sparisty does not matter. -Upon return it contains the same sparsity pattern as \c user -(or the transposed sparsity pattern). - -\param user -sparsity pattern that we are placing internal. - -\param n_set -number of sets (rows) in the internal sparsity pattern. - -\param end -end of set value (number of columns) in the interanl sparsity pattern. - -\param transpose -if true, the user sparsity patter is the transposed. - -\param error_msg -is the error message to display if some values in the user sparstiy -pattern are not valid. -*/ -template -void sparsity_user2internal( - sparse_list& internal , - const VectorSet& user , - size_t n_set , - size_t end , - bool transpose , - const char* error_msg ) -{ -# ifndef NDEBUG - if( transpose ) - CPPAD_ASSERT_KNOWN( end == size_t( user.size() ), error_msg); - if( ! transpose ) - CPPAD_ASSERT_KNOWN( n_set == size_t( user.size() ), error_msg); -# endif - - // iterator for user set - std::set::const_iterator itr; - - // size of internal sparsity pattern - internal.resize(n_set, end); - - if( transpose ) - { // transposed pattern case - for(size_t j = 0; j < end; j++) - { itr = user[j].begin(); - while(itr != user[j].end()) - { size_t i = *itr++; - CPPAD_ASSERT_KNOWN(i < n_set, error_msg); - internal.add_element(i, j); - } - } - } - else - { for(size_t i = 0; i < n_set; i++) - { itr = user[i].begin(); - while(itr != user[i].end()) - { size_t j = *itr++; - CPPAD_ASSERT_KNOWN( j < end, error_msg); - internal.add_element(i, j); - } - } - } - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sparse_pack.hpp b/external/cppad/include/cppad/local/sparse_pack.hpp deleted file mode 100644 index 2fb5ba1db..000000000 --- a/external/cppad/include/cppad/local/sparse_pack.hpp +++ /dev/null @@ -1,544 +0,0 @@ -# ifndef CPPAD_LOCAL_SPARSE_PACK_HPP -# define CPPAD_LOCAL_SPARSE_PACK_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sparse_pack.hpp -Vector of sets of positive integers stored as a packed array of bools. -*/ - -// ========================================================================== -/*! -Vector of sets of postivie integers, each set stored as a packed boolean array. -*/ - -class sparse_pack_const_iterator; -class sparse_pack { - friend class sparse_pack_const_iterator; -private: - /// Type used to pack elements (should be the same as corresponding - /// typedef in multiple_n_bit() in test_more/sparse_hacobian.cpp) - typedef size_t Pack; - /// Number of bits per Pack value - const size_t n_bit_; - /// Number of sets that we are representing - /// (set by constructor and resize). - size_t n_set_; - /// Possible elements in each set are 0, 1, ..., end_ - 1 - /// (set by constructor and resize). - size_t end_; - /// Number of \c Pack values necessary to represent \c end_ bits. - /// (set by constructor and resize). - size_t n_pack_; - /// Data for all the sets. - pod_vector data_; -public: - /// declare a const iterator - typedef sparse_pack_const_iterator const_iterator; - - // ----------------------------------------------------------------- - /*! Default constructor (no sets) - */ - sparse_pack(void) : - n_bit_( std::numeric_limits::digits ), - n_set_(0) , - end_(0) , - n_pack_(0) - { } - // ----------------------------------------------------------------- - /*! Make use of copy constructor an error - - \param v - vector that we are attempting to make a copy of. - */ - sparse_pack(const sparse_pack& v) : - n_bit_( std::numeric_limits::digits ) - { // Error: - // Probably a sparse_pack argument has been passed by value - CPPAD_ASSERT_UNKNOWN(0); - } - // ----------------------------------------------------------------- - /*! Destructor - */ - ~sparse_pack(void) - { } - // ----------------------------------------------------------------- - /*! Change number of sets, set end, and initialize all sets as empty - - If \c n_set_in is zero, any memory currently allocated for this object - is freed. Otherwise, new memory may be allocated for the sets (if needed). - - \param n_set_in - is the number of sets in this vector of sets. - - \param end_in - is the maximum element plus one. The minimum element is 0 and - end must be greater than zero (unless n_set is also zero). - */ - void resize(size_t n_set_in, size_t end_in) - { CPPAD_ASSERT_UNKNOWN( n_set_in == 0 || 0 < end_in ); - n_set_ = n_set_in; - end_ = end_in; - if( n_set_ == 0 ) - { data_.free(); - return; - } - // now start a new vector with empty sets - Pack zero(0); - data_.erase(); - - n_pack_ = ( 1 + (end_ - 1) / n_bit_ ); - size_t i = n_set_ * n_pack_; - - if( i > 0 ) - { data_.extend(i); - while(i--) - data_[i] = zero; - } - } - // ----------------------------------------------------------------- - /*! - Count number of elements in a set. - - \param index - is the index in of the set we are counting the elements of. - */ - size_t number_elements(size_t index) const - { static Pack one(1); - CPPAD_ASSERT_UNKNOWN( index < n_set_ ); - size_t count = 0; - for(size_t k = 0; k < n_pack_; k++) - { Pack unit = data_[ index * n_pack_ + k ]; - Pack mask = one; - size_t n = std::min(n_bit_, end_ - n_bit_ * k); - for(size_t bit = 0; bit < n; bit++) - { CPPAD_ASSERT_UNKNOWN( mask > one || bit == 0); - if( mask & unit ) - ++count; - mask = mask << 1; - } - } - return count; - } - // ----------------------------------------------------------------- - /*! Add one element to a set. - - \param index - is the index for this set in the vector of sets. - - \param element - is the element we are adding to the set. - - \par Checked Assertions - \li index < n_set_ - \li element < end_ - */ - void add_element(size_t index, size_t element) - { static Pack one(1); - CPPAD_ASSERT_UNKNOWN( index < n_set_ ); - CPPAD_ASSERT_UNKNOWN( element < end_ ); - size_t j = element / n_bit_; - size_t k = element - j * n_bit_; - Pack mask = one << k; - data_[ index * n_pack_ + j] |= mask; - } - // ----------------------------------------------------------------- - /*! Is an element of a set. - - \param index - is the index for this set in the vector of sets. - - \param element - is the element we are checking to see if it is in the set. - - \par Checked Assertions - \li index < n_set_ - \li element < end_ - */ - bool is_element(size_t index, size_t element) const - { static Pack one(1); - static Pack zero(0); - CPPAD_ASSERT_UNKNOWN( index < n_set_ ); - CPPAD_ASSERT_UNKNOWN( element < end_ ); - size_t j = element / n_bit_; - size_t k = element - j * n_bit_; - Pack mask = one << k; - return (data_[ index * n_pack_ + j] & mask) != zero; - } - // ----------------------------------------------------------------- - /*! Assign the empty set to one of the sets. - - \param target - is the index of the set we are setting to the empty set. - - \par Checked Assertions - \li target < n_set_ - */ - void clear(size_t target) - { // value with all its bits set to false - static Pack zero(0); - CPPAD_ASSERT_UNKNOWN( target < n_set_ ); - size_t t = target * n_pack_; - - size_t j = n_pack_; - while(j--) - data_[t++] = zero; - } - // ----------------------------------------------------------------- - /*! Assign one set equal to another set. - - \param this_target - is the index (in this \c sparse_pack object) of the set being assinged. - - \param other_value - is the index (in the other \c sparse_pack object) of the - that we are using as the value to assign to the target set. - - \param other - is the other \c sparse_pack object (which may be the same as this - \c sparse_pack object). - - \par Checked Assertions - \li this_target < n_set_ - \li other_value < other.n_set_ - \li n_pack_ == other.n_pack_ - */ - void assignment( - size_t this_target , - size_t other_value , - const sparse_pack& other ) - { CPPAD_ASSERT_UNKNOWN( this_target < n_set_ ); - CPPAD_ASSERT_UNKNOWN( other_value < other.n_set_ ); - CPPAD_ASSERT_UNKNOWN( n_pack_ == other.n_pack_ ); - size_t t = this_target * n_pack_; - size_t v = other_value * n_pack_; - - size_t j = n_pack_; - while(j--) - data_[t++] = other.data_[v++]; - } - - // ----------------------------------------------------------------- - /*! Assing a set equal to the union of two other sets. - - \param this_target - is the index (in this \c sparse_pack object) of the set being assinged. - - \param this_left - is the index (in this \c sparse_pack object) of the - left operand for the union operation. - It is OK for \a this_target and \a this_left to be the same value. - - \param other_right - is the index (in the other \c sparse_pack object) of the - right operand for the union operation. - It is OK for \a this_target and \a other_right to be the same value. - - \param other - is the other \c sparse_pack object (which may be the same as this - \c sparse_pack object). - - \par Checked Assertions - \li this_target < n_set_ - \li this_left < n_set_ - \li other_right < other.n_set_ - \li n_pack_ == other.n_pack_ - */ - void binary_union( - size_t this_target , - size_t this_left , - size_t other_right , - const sparse_pack& other ) - { CPPAD_ASSERT_UNKNOWN( this_target < n_set_ ); - CPPAD_ASSERT_UNKNOWN( this_left < n_set_ ); - CPPAD_ASSERT_UNKNOWN( other_right < other.n_set_ ); - CPPAD_ASSERT_UNKNOWN( n_pack_ == other.n_pack_ ); - - size_t t = this_target * n_pack_; - size_t l = this_left * n_pack_; - size_t r = other_right * n_pack_; - - size_t j = n_pack_; - while(j--) - data_[t++] = ( data_[l++] | other.data_[r++] ); - } - // ----------------------------------------------------------------- - /*! Assing a set equal to the intersection of two other sets. - - \param this_target - is the index (in this \c sparse_pack object) of the set being assinged. - - \param this_left - is the index (in this \c sparse_pack object) of the - left operand for the intersection operation. - It is OK for \a this_target and \a this_left to be the same value. - - \param other_right - is the index (in the other \c sparse_pack object) of the - right operand for the intersection operation. - It is OK for \a this_target and \a other_right to be the same value. - - \param other - is the other \c sparse_pack object (which may be the same as this - \c sparse_pack object). - - \par Checked Assertions - \li this_target < n_set_ - \li this_left < n_set_ - \li other_right < other.n_set_ - \li n_pack_ == other.n_pack_ - */ - void binary_intersection( - size_t this_target , - size_t this_left , - size_t other_right , - const sparse_pack& other ) - { CPPAD_ASSERT_UNKNOWN( this_target < n_set_ ); - CPPAD_ASSERT_UNKNOWN( this_left < n_set_ ); - CPPAD_ASSERT_UNKNOWN( other_right < other.n_set_ ); - CPPAD_ASSERT_UNKNOWN( n_pack_ == other.n_pack_ ); - - size_t t = this_target * n_pack_; - size_t l = this_left * n_pack_; - size_t r = other_right * n_pack_; - - size_t j = n_pack_; - while(j--) - data_[t++] = ( data_[l++] & other.data_[r++] ); - } - // ----------------------------------------------------------------- - /*! Fetch n_set for vector of sets object. - - \return - Number of from sets for this vector of sets object - */ - size_t n_set(void) const - { return n_set_; } - // ----------------------------------------------------------------- - /*! Fetch end for this vector of sets object. - - \return - is the maximum element value plus one (the minimum element value is 0). - */ - size_t end(void) const - { return end_; } - // ----------------------------------------------------------------- - /*! Amount of memory used by this vector of sets - - \return - The amount of memory in units of type unsigned char memory. - */ - size_t memory(void) const - { return data_.capacity() * sizeof(Pack); - } - /*! - Print the vector of sets (used for debugging) - */ - void print(void) const; -}; -// ========================================================================== -/*! -cons_iterator for one set of positive integers in a sparse_pack object. -*/ -class sparse_pack_const_iterator { -private: - /// Type used to pack elements in sparse_pack - typedef sparse_pack::Pack Pack; - - /// data for the entire vector of sets - const pod_vector& data_; - - /// Number of bits per Pack value - const size_t n_bit_; - - /// Number of Pack values necessary to represent end_ bits. - const size_t n_pack_; - - /// Possible elements in each set are 0, 1, ..., end_ - 1; - const size_t end_; - - /// index of this set in the vector of sets; - const size_t index_; - - /// value of the next element in this set - /// (use end_ for no such element exists; i.e., past end of the set). - size_t next_element_; -public: - /// construct a const_iterator for a set in a sparse_pack object - sparse_pack_const_iterator (const sparse_pack& pack, size_t index) - : - data_ ( pack.data_ ) , - n_bit_ ( pack.n_bit_ ) , - n_pack_ ( pack.n_pack_ ) , - end_ ( pack.end_ ) , - index_ ( index ) - { static Pack one(1); - CPPAD_ASSERT_UNKNOWN( index < pack.n_set_ ); - // - next_element_ = 0; - if( next_element_ < end_ ) - { Pack check = data_[ index_ * n_pack_ + 0 ]; - if( check & one ) - return; - } - // element with index zero is not in this set of integers, - // advance to first element or end - ++(*this); - } - - /// advance to next element in this set - sparse_pack_const_iterator& operator++(void) - { static Pack one(1); - CPPAD_ASSERT_UNKNOWN( next_element_ <= end_ ); - if( next_element_ == end_ ) - return *this; - // - ++next_element_; - if( next_element_ == end_ ) - return *this; - // - // initialize packed data index - size_t j = next_element_ / n_bit_; - - // initialize bit index - size_t k = next_element_ - j * n_bit_; - - // initialize mask - size_t mask = one << k; - - // start search at this packed value - Pack check = data_[ index_ * n_pack_ + j ]; - // - while( true ) - { // check if this element is in the set - if( check & mask ) - return *this; - - // increment next element before checking this one - next_element_++; - if( next_element_ == end_ ) - return *this; - - // shift mask to left one bit so corresponds to next_element_ - // (use mask <<= 1. not one << k, so compiler knows value) - k++; - mask <<= 1; - CPPAD_ASSERT_UNKNOWN( k <= n_bit_ ); - - // check if we must go to next packed data index - if( k == n_bit_ ) - { // get next packed value - k = 0; - mask = one; - j++; - CPPAD_ASSERT_UNKNOWN( j < n_pack_ ); - check = data_[ index_ * n_pack_ + j ]; - } - } - // should never get here - CPPAD_ASSERT_UNKNOWN(false); - return *this; - } - - /// obtain value of this element of the set of positive integers - /// (end_ for no such element) - size_t operator*(void) const - { return next_element_; } -}; -// ========================================================================= -/*! -Print the vector of sets (used for debugging) -*/ -inline void sparse_pack::print(void) const -{ std::cout << "sparse_pack:\n"; - for(size_t i = 0; i < n_set(); i++) - { std::cout << "set[" << i << "] = {"; - const_iterator itr(*this, i); - while( *itr != end() ) - { std::cout << *itr; - if( *(++itr) != end() ) - std::cout << ","; - } - std::cout << "}\n"; - } - return; -} - -// ========================================================================== - -/*! -Copy a user vector of sets sparsity pattern to an internal sparse_pack object. - -\tparam VectorSet -is a simple vector with elements of type std::set. - -\param internal -The input value of sparisty does not matter. -Upon return it contains the same sparsity pattern as \c user -(or the transposed sparsity pattern). - -\param user -sparsity pattern that we are placing internal. - -\param n_set -number of sets (rows) in the internal sparsity pattern. - -\param end -end of set value (number of columns) in the interanl sparsity pattern. - -\param transpose -if true, the user sparsity patter is the transposed. - -\param error_msg -is the error message to display if some values in the user sparstiy -pattern are not valid. -*/ -template -void sparsity_user2internal( - sparse_pack& internal , - const VectorSet& user , - size_t n_set , - size_t end , - bool transpose , - const char* error_msg ) -{ CPPAD_ASSERT_KNOWN(size_t( user.size() ) == n_set * end, error_msg ); - - // size of internal sparsity pattern - internal.resize(n_set, end); - - if( transpose ) - { // transposed pattern case - for(size_t j = 0; j < end; j++) - { for(size_t i = 0; i < n_set; i++) - { if( user[ j * n_set + i ] ) - internal.add_element(i, j); - } - } - return; - } - else - { for(size_t i = 0; i < n_set; i++) - { for(size_t j = 0; j < end; j++) - { if( user[ i * end + j ] ) - internal.add_element(i, j); - } - } - } - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sparse_unary_op.hpp b/external/cppad/include/cppad/local/sparse_unary_op.hpp deleted file mode 100644 index e2e7fa702..000000000 --- a/external/cppad/include/cppad/local/sparse_unary_op.hpp +++ /dev/null @@ -1,250 +0,0 @@ -// $Id: sparse_unary_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_SPARSE_UNARY_OP_HPP -# define CPPAD_LOCAL_SPARSE_UNARY_OP_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sparse_unary_op.hpp -Forward and reverse mode sparsity patterns for unary operators. -*/ - - -/*! -Forward mode Jacobian sparsity pattern for all unary operators. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = fun(x) -\endverbatim -where fun is a C++ unary function, or it has the form -\verbatim - z = x op q -\endverbatim -where op is a C++ binary unary operator and q is a parameter. - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param i_z -variable index corresponding to the result for this operation; -i.e., z. - -\param i_x -variable index corresponding to the argument for this operator; -i.e., x. - - -\param sparsity -\b Input: The set with index \a arg[0] in \a sparsity -is the sparsity bit pattern for x. -This identifies which of the independent variables the variable x -depends on. -\n -\n -\b Output: The set with index \a i_z in \a sparsity -is the sparsity bit pattern for z. -This identifies which of the independent variables the variable z -depends on. -\n - -\par Checked Assertions: -\li \a i_x < \a i_z -*/ - -template -inline void forward_sparse_jacobian_unary_op( - size_t i_z , - size_t i_x , - Vector_set& sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( i_x < i_z ); - - sparsity.assignment(i_z, i_x, sparsity); -} -/*! -Reverse mode Jacobian sparsity pattern for all unary operators. - -The C++ source code corresponding to a unary operation has the form -\verbatim - z = fun(x) -\endverbatim -where fun is a C++ unary function, or it has the form -\verbatim - z = x op q -\endverbatim -where op is a C++ bianry operator and q is a parameter. - -This routine is given the sparsity patterns -for a function G(z, y, ... ) -and it uses them to compute the sparsity patterns for -\verbatim - H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ] -\endverbatim - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - - -\param i_z -variable index corresponding to the result for this operation; -i.e. the row index in sparsity corresponding to z. - -\param i_x -variable index corresponding to the argument for this operator; -i.e. the row index in sparsity corresponding to x. - -\param sparsity -\b Input: -The set with index \a i_z in \a sparsity -is the sparsity bit pattern for G with respect to the variable z. -\n -\b Input: -The set with index \a i_x in \a sparsity -is the sparsity bit pattern for G with respect to the variable x. -\n -\b Output: -The set with index \a i_x in \a sparsity -is the sparsity bit pattern for H with respect to the variable x. - -\par Checked Assertions: -\li \a i_x < \a i_z -*/ - -template -inline void reverse_sparse_jacobian_unary_op( - size_t i_z , - size_t i_x , - Vector_set& sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( i_x < i_z ); - - sparsity.binary_union(i_x, i_x, i_z, sparsity); - - return; -} -// --------------------------------------------------------------------------- -/*! -Reverse mode Hessian sparsity pattern for linear unary operators. - -The C++ source code corresponding to this operation is -\verbatim - z = fun(x) -\endverbatim -where fun is a linear functions; e.g. abs, or -\verbatim - z = x op q -\endverbatim -where op is a C++ binary operator and q is a parameter. - -\copydetails CppAD::local::reverse_sparse_hessian_unary_op -*/ -template -inline void reverse_sparse_hessian_linear_unary_op( - size_t i_z , - size_t i_x , - bool* rev_jacobian , - const Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( i_x < i_z ); - - rev_hes_sparsity.binary_union(i_x, i_x, i_z, rev_hes_sparsity); - - rev_jacobian[i_x] |= rev_jacobian[i_z]; - return; -} - -/*! -Reverse mode Hessian sparsity pattern for non-linear unary operators. - -The C++ source code corresponding to this operation is -\verbatim - z = fun(x) -\endverbatim -where fun is a non-linear functions; e.g. sin. or -\verbatim - z = q / x -\endverbatim -where q is a parameter. - - -\copydetails CppAD::local::reverse_sparse_hessian_unary_op -*/ -template -inline void reverse_sparse_hessian_nonlinear_unary_op( - size_t i_z , - size_t i_x , - bool* rev_jacobian , - const Vector_set& for_jac_sparsity , - Vector_set& rev_hes_sparsity ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( i_x < i_z ); - - rev_hes_sparsity.binary_union(i_x, i_x, i_z, rev_hes_sparsity); - if( rev_jacobian[i_z] ) - rev_hes_sparsity.binary_union(i_x, i_x, i_x, for_jac_sparsity); - - rev_jacobian[i_x] |= rev_jacobian[i_z]; - return; -} - -// --------------------------------------------------------------------------- -/*! -Forward mode Hessian sparsity pattern for non-linear unary operators. - -The C++ source code corresponding to this operation is -\verbatim - w(x) = fun( v(x) ) -\endverbatim -where fun is a non-linear function. - -\param i_v -is the index of the argument variable v - -\param for_jac_sparsity -for_jac_sparsity(i_v) constains the Jacobian sparsity for v(x). - -\param for_hes_sparsity -On input, for_hes_sparsity includes the Hessian sparsity for v(x); i.e., -the sparsity can be a super set. -Upon return it includes the Hessian sparsity for w(x) -*/ -template -inline void forward_sparse_hessian_nonlinear_unary_op( - size_t i_v , - const Vector_set& for_jac_sparsity , - Vector_set& for_hes_sparsity ) -{ - // set of independent variables that v depends on - typename Vector_set::const_iterator itr(for_jac_sparsity, i_v); - - // next independent variables that v depends on - size_t i_x = *itr; - - // loop over dependent variables with non-zero partial - while( i_x < for_jac_sparsity.end() ) - { // N(i_x) = N(i_x) union L(i_v) - for_hes_sparsity.binary_union(i_x, i_x, i_v, for_jac_sparsity); - i_x = *(++itr); - } - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sqrt_op.hpp b/external/cppad/include/cppad/local/sqrt_op.hpp deleted file mode 100644 index d437d9654..000000000 --- a/external/cppad/include/cppad/local/sqrt_op.hpp +++ /dev/null @@ -1,193 +0,0 @@ -# ifndef CPPAD_LOCAL_SQRT_OP_HPP -# define CPPAD_LOCAL_SQRT_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sqrt_op.hpp -Forward and reverse mode calculations for z = sqrt(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = SqrtOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sqrt(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op -*/ -template -inline void forward_sqrt_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - size_t k; - if( p == 0 ) - { z[0] = sqrt( x[0] ); - p++; - } - for(size_t j = p; j <= q; j++) - { - z[j] = Base(0.0); - for(k = 1; k < j; k++) - z[j] -= Base(double(k)) * z[k] * z[j-k]; - z[j] /= Base(double(j)); - z[j] += x[j] / Base(2.0); - z[j] /= z[0]; - } -} - -/*! -Multiple direction forward mode Taylor coefficient for op = SqrtOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sqrt(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_dir -*/ -template -inline void forward_sqrt_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* z = taylor + i_z * num_taylor_per_var; - Base* x = taylor + i_x * num_taylor_per_var; - - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(0.0); - for(size_t k = 1; k < q; k++) - z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell]; - z[m+ell] /= Base(double(q)); - z[m+ell] += x[m+ell] / Base(2.0); - z[m+ell] /= z[0]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = SqrtOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sqrt(x) -\endverbatim - -\copydetails CppAD::local::forward_unary1_op_0 -*/ -template -inline void forward_sqrt_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = sqrt( x[0] ); -} -/*! -Compute reverse mode partial derivatives for result of op = SqrtOp. - -The C++ source code corresponding to this operation is -\verbatim - z = sqrt(x) -\endverbatim - -\copydetails CppAD::local::reverse_unary1_op -*/ - -template -inline void reverse_sqrt_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to result - const Base* z = taylor + i_z * cap_order; - Base* pz = partial + i_z * nc_partial; - - - Base inv_z0 = Base(1.0) / z[0]; - - // number of indices to access - size_t j = d; - size_t k; - while(j) - { - - // scale partial w.r.t. z[j] - pz[j] = azmul(pz[j], inv_z0); - - pz[0] -= azmul(pz[j], z[j]); - px[j] += pz[j] / Base(2.0); - for(k = 1; k < j; k++) - pz[k] -= azmul(pz[j], z[j-k]); - --j; - } - px[0] += azmul(pz[0], inv_z0) / Base(2.0); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/std_set.hpp b/external/cppad/include/cppad/local/std_set.hpp deleted file mode 100644 index a4c70df74..000000000 --- a/external/cppad/include/cppad/local/std_set.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// $Id: std_set.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_LOCAL_STD_SET_HPP -# define CPPAD_LOCAL_STD_SET_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file std_set.hpp -Two constant standard sets (currently used for concept checking). -*/ - -/*! -A standard set with one element. -*/ -template -const std::set& one_element_std_set(void) -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static std::set one; - if( one.empty() ) - one.insert(1); - return one; -} -/*! -A standard set with a two elements. -*/ -template -const std::set& two_element_std_set(void) -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static std::set two; - if( two.empty() ) - { two.insert(1); - two.insert(2); - } - return two; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/store_op.hpp b/external/cppad/include/cppad/local/store_op.hpp deleted file mode 100644 index 214c43525..000000000 --- a/external/cppad/include/cppad/local/store_op.hpp +++ /dev/null @@ -1,498 +0,0 @@ -// $Id: store_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_STORE_OP_HPP -# define CPPAD_LOCAL_STORE_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file store_op.hpp -Changing the current value of a VecAD element. -*/ -/* -============================================================================== - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - -============================================================================== -*/ -/*! -Shared documentation for zero order forward implementation of -op = StppOp, StpvOp, StvpOp, or StvvOp (not called). - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -\tparam Base -base type for the operator; i.e., this operation was recorded -using AD and computations by this routine are done using type Base. - -\param i_z -is the index corresponding to the previous variable on the tape -(only used for error checking). - -\param arg -\n -arg[0] -\n -is the offset of this VecAD vector relative to the beginning -of the isvar_by_ind and index_by_ind arrays. -\n -\n -arg[1] -\n -If this is a StppOp or StpvOp operation (if x is a parameter), -i_vec is defined by -\verbatim - i_vec = arg[1] -\endverbatim -If this is a StvpOp or StvvOp operation (if x is a variable), -i_vec is defined by -\verbatim - i_vec = floor( taylor[ arg[1] * cap_order + 0 ] ) -\endverbatim -where floor(c) is the greatest integer less that or equal c. -\n -\n -arg[2] -\n -index corresponding to the third operand for this operator; -i.e. the index corresponding to y. - -\param num_par -is the total number of parameters on the tape -(only used for error checking). - -\param cap_order -number of columns in the matrix containing the Taylor coefficients. - -\param taylor -In StvpOp and StvvOp cases, -is used to compute the index in the definition of i_vec above. - -\param isvar_by_ind -If y is a varable (StpvOp and StvvOp cases), -isvar_by_ind[ arg[0] + i_vec ] is set to true. -Otherwise y is a paraemter (StppOp and StvpOp cases) and -isvar_by_ind[ arg[0] + i_vec ] is set to false. - -\param index_by_ind -index_by_ind[ arg[0] - 1 ] -is the number of elements in the user vector containing this element. -The value index_by_ind[ arg[0] + i_vec] -is set equal to arg[2]. - -\par Check User Errors -\li Check that the index is with in range; i.e. -i_vec < index_by_ind[ arg[0] - 1 ] -Note that, if x is a parameter, -the corresponding vector index and it does not change. -In this case, the error above should be detected during tape recording. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 0 -\li 0 < arg[0] -\li if y is a parameter, arg[2] < num_par -*/ -template -inline void forward_store_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} -/*! -Shared documnetation for sparsity operations corresponding to -op = StpvOp or StvvOp (not called). - -\tparam Vector_set -is the type used for vectors of sets. It can be either -sparse_pack or sparse_list. - -\param op -is the code corresponding to this operator; -i.e., StpvOp, StvpOp, or StvvOp. - -\param arg -\n -\a arg[0] -is the offset corresponding to this VecAD vector in the combined array. -\n -\n -\a arg[2] -\n -The set with index \a arg[2] in \a var_sparsity -is the sparsity pattern corresponding to y. -(Note that \a arg[2] > 0 because y is a variable.) - -\param num_combined -is the total number of elements in the VecAD address array. - -\param combined -\a combined [ arg[0] - 1 ] -is the index of the set in \a vecad_sparsity corresponding -to the sparsity pattern for the vector v. -We use the notation i_v below which is defined by -\verbatim - i_v = combined[ \a arg[0] - 1 ] -\endverbatim - -\param var_sparsity -The set with index \a arg[2] in \a var_sparsity -is the sparsity pattern for y. -This is an input for forward mode operations. -For reverse mode operations: -The sparsity pattern for v is added to the spartisy pattern for y. - -\param vecad_sparsity -The set with index \a i_v in \a vecad_sparsity -is the sparsity pattern for v. -This is an input for reverse mode operations. -For forward mode operations, the sparsity pattern for y is added -to the sparsity pattern for the vector v. - -\par Checked Assertions -\li NumArg(op) == 3 -\li NumRes(op) == 0 -\li 0 < \a arg[0] -\li \a arg[0] < \a num_combined -\li \a arg[2] < \a var_sparsity.n_set() -\li i_v < \a vecad_sparsity.n_set() -*/ -template -inline void sparse_store_op( - OpCode op , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity ) -{ - // This routine is only for documentaiton, it should not be used - CPPAD_ASSERT_UNKNOWN( false ); -} - - -/*! -Zero order forward mode implementation of op = StppOp. - -\copydetails CppAD::local::forward_store_op_0 -*/ -template -inline void forward_store_pp_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind ) -{ size_t i_vec = arg[1]; - - // Because the index is a parameter, this indexing error should be - // caught and reported to the user when the tape is recording. - CPPAD_ASSERT_UNKNOWN( i_vec < index_by_ind[ arg[0] - 1 ] ); - - CPPAD_ASSERT_UNKNOWN( NumArg(StppOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(StppOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - - isvar_by_ind[ arg[0] + i_vec ] = false; - index_by_ind[ arg[0] + i_vec ] = arg[2]; -} - -/*! -Zero order forward mode implementation of op = StpvOp. - -\copydetails CppAD::local::forward_store_op_0 -*/ -template -inline void forward_store_pv_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind ) -{ size_t i_vec = arg[1]; - - // Because the index is a parameter, this indexing error should be - // caught and reported to the user when the tape is recording. - CPPAD_ASSERT_UNKNOWN( i_vec < index_by_ind[ arg[0] - 1 ] ); - - CPPAD_ASSERT_UNKNOWN( NumArg(StpvOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(StpvOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - - isvar_by_ind[ arg[0] + i_vec ] = true; - index_by_ind[ arg[0] + i_vec ] = arg[2]; -} - -/*! -Zero order forward mode implementation of op = StvpOp. - -\copydetails CppAD::local::forward_store_op_0 -*/ -template -inline void forward_store_vp_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind ) -{ - size_t i_vec = Integer( taylor[ arg[1] * cap_order + 0 ] ); - CPPAD_ASSERT_KNOWN( - i_vec < index_by_ind[ arg[0] - 1 ] , - "VecAD: index during zero order forward sweep is out of range" - ); - - CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); - - isvar_by_ind[ arg[0] + i_vec ] = false; - index_by_ind[ arg[0] + i_vec ] = arg[2]; -} - -/*! -Zero order forward mode implementation of op = StvvOp. - -\copydetails CppAD::local::forward_store_op_0 -*/ -template -inline void forward_store_vv_op_0( - size_t i_z , - const addr_t* arg , - size_t num_par , - size_t cap_order , - Base* taylor , - bool* isvar_by_ind , - size_t* index_by_ind ) -{ - size_t i_vec = Integer( taylor[ arg[1] * cap_order + 0 ] ); - CPPAD_ASSERT_KNOWN( - i_vec < index_by_ind[ arg[0] - 1 ] , - "VecAD: index during zero order forward sweep is out of range" - ); - - CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - - isvar_by_ind[ arg[0] + i_vec ] = true; - index_by_ind[ arg[0] + i_vec ] = arg[2]; -} - -/*! -Forward mode sparsity operations for StpvOp and StvvOp - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -\param dependency -is this a dependency (or sparsity) calculation. - -\copydetails CppAD::local::sparse_store_op -*/ -template -inline void forward_sparse_store_op( - bool dependency , - OpCode op , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined ); - size_t i_v = combined[ arg[0] - 1 ]; - CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() ); - - if( dependency & ( (op == StvvOp) | (op == StvpOp) ) ) - vecad_sparsity.binary_union(i_v, i_v, arg[1], var_sparsity); - - if( (op == StpvOp) | (op == StvvOp ) ) - vecad_sparsity.binary_union(i_v, i_v, arg[2], var_sparsity); - - return; -} - -/*! -Reverse mode sparsity operations for StpvOp, StvpOp, and StvvOp - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -This routine is given the sparsity patterns for -G(v[x], y , w , u ... ) and it uses them to compute the -sparsity patterns for -\verbatim - H(y , w , u , ... ) = G[ v[x], y , w , u , ... ] -\endverbatim - -\param dependency -is this a dependency (or sparsity) calculation. - -\copydetails CppAD::local::sparse_store_op -*/ -template -inline void reverse_sparse_jacobian_store_op( - bool dependency , - OpCode op , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined ); - size_t i_v = combined[ arg[0] - 1 ]; - CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() ); - - if( dependency & ( (op == StvpOp) | (op == StvvOp) ) ) - var_sparsity.binary_union(arg[1], arg[1], i_v, vecad_sparsity); - if( (op == StpvOp) | (op == StvvOp) ) - var_sparsity.binary_union(arg[2], arg[2], i_v, vecad_sparsity); - - return; -} - -/*! -Reverse mode sparsity operations for StpvOp and StvvOp - - -The C++ source code corresponding to this operation is -\verbatim - v[x] = y -\endverbatim -where v is a VecAD vector, x is an AD object, -and y is AD or Base objects. -We define the index corresponding to v[x] by -\verbatim - i_v_x = index_by_ind[ arg[0] + i_vec ] -\endverbatim -where i_vec is defined under the heading arg[1] below: - - -This routine is given the sparsity patterns for -G(v[x], y , w , u ... ) -and it uses them to compute the sparsity patterns for -\verbatim - H(y , w , u , ... ) = G[ v[x], y , w , u , ... ] -\endverbatim - -\copydetails CppAD::local::sparse_store_op - -\param var_jacobian -\a var_jacobian[ \a arg[2] ] -is false (true) if the Jacobian of G with respect to y is always zero -(may be non-zero). - -\param vecad_jacobian -\a vecad_jacobian[i_v] -is false (true) if the Jacobian with respect to x is always zero -(may be non-zero). -On input, it corresponds to the function G, -and on output it corresponds to the function H. -*/ -template -inline void reverse_sparse_hessian_store_op( - OpCode op , - const addr_t* arg , - size_t num_combined , - const size_t* combined , - Vector_set& var_sparsity , - Vector_set& vecad_sparsity , - bool* var_jacobian , - bool* vecad_jacobian ) -{ - CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); - CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); - CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined ); - size_t i_v = combined[ arg[0] - 1 ]; - CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); - CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() ); - - var_sparsity.binary_union(arg[2], arg[2], i_v, vecad_sparsity); - - var_jacobian[ arg[2] ] |= vecad_jacobian[i_v]; - - return; -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/sub_op.hpp b/external/cppad/include/cppad/local/sub_op.hpp deleted file mode 100644 index dc66f8e18..000000000 --- a/external/cppad/include/cppad/local/sub_op.hpp +++ /dev/null @@ -1,501 +0,0 @@ -// $Id: sub_op.hpp 3865 2017-01-19 01:57:55Z bradbell $ -# ifndef CPPAD_LOCAL_SUB_OP_HPP -# define CPPAD_LOCAL_SUB_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file sub_op.hpp -Forward and reverse mode calculations for z = x - y. -*/ - -// --------------------------- Subvv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_subvv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - for(size_t d = p; d <= q; d++) - z[d] = x[d] - y[d]; -} -/*! -Multiple directions forward mode Taylor coefficients for op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_subvv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var + m; - Base* y = taylor + arg[1] * num_taylor_per_var + m; - Base* z = taylor + i_z * num_taylor_per_var + m; - - for(size_t ell = 0; ell < r; ell++) - z[ell] = x[ell] - y[ell]; -} - -/*! -Compute zero order forward mode Taylor coefficients for result of op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_subvv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x[0] - y[0]; -} - -/*! -Compute reverse mode partial derivatives for result of op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_subvv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t i = d + 1; - while(i) - { --i; - px[i] += pz[i]; - py[i] -= pz[i]; - } -} - -// --------------------------- Subpv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = SubpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_subpv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Paraemter value - Base x = parameter[ arg[0] ]; - if( p == 0 ) - { z[0] = x - y[0]; - p++; - } - for(size_t d = p; d <= q; d++) - z[d] = - y[d]; -} -/*! -Multiple directions forward mode Taylor coefficients for op = SubpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_subpv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1) * r + 1; - Base* y = taylor + arg[1] * num_taylor_per_var + m; - Base* z = taylor + i_z * num_taylor_per_var + m; - - // Paraemter value - for(size_t ell = 0; ell < r; ell++) - z[ell] = - y[ell]; -} -/*! -Compute zero order forward mode Taylor coefficient for result of op = SubpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_subpv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 ); - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x - y[0]; -} - -/*! -Compute reverse mode partial derivative for result of op = SubpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_subpv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Partial derivatives corresponding to arguments and result - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t i = d + 1; - while(i) - { --i; - py[i] -= pz[i]; - } -} - -// --------------------------- Subvp ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_subvp_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Parameter value - Base y = parameter[ arg[1] ]; - if( p == 0 ) - { z[0] = x[0] - y; - p++; - } - for(size_t d = p; d <= q; d++) - z[d] = x[d]; -} -/*! -Multiple directions forward mode Taylor coefficients for op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_subvp_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - // Parameter value - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - z[m+ell] = x[m+ell]; -} - -/*! -Compute zero order forward mode Taylor coefficients for result of op = SubvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_subvp_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 ); - - // Parameter value - Base y = parameter[ arg[1] ]; - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = x[0] - y; -} - -/*! -Compute reverse mode partial derivative for result of op = SubvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = x - y -\endverbatim -In the documentation below, -this operations is for the case where x is a variable and y is a parameter. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_subvp_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t i = d + 1; - while(i) - { --i; - px[i] += pz[i]; - } -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/tan_op.hpp b/external/cppad/include/cppad/local/tan_op.hpp deleted file mode 100644 index 15a28b68e..000000000 --- a/external/cppad/include/cppad/local/tan_op.hpp +++ /dev/null @@ -1,231 +0,0 @@ -# ifndef CPPAD_LOCAL_TAN_OP_HPP -# define CPPAD_LOCAL_TAN_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file tan_op.hpp -Forward and reverse mode calculations for z = tan(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tan(x) -\endverbatim -The auxillary result is -\verbatim - y = tan(x)^2 -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_tan_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* y = z - cap_order; - - size_t k; - if( p == 0 ) - { z[0] = tan( x[0] ); - y[0] = z[0] * z[0]; - p++; - } - for(size_t j = p; j <= q; j++) - { Base base_j = static_cast(double(j)); - - z[j] = x[j]; - for(k = 1; k <= j; k++) - z[j] += Base(double(k)) * x[k] * y[j-k] / base_j; - - y[j] = z[0] * z[j]; - for(k = 1; k <= j; k++) - y[j] += z[k] * z[j-k]; - } -} - -/*! -Multiple directions forward mode Taylor coefficient for op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tan(x) -\endverbatim -The auxillary result is -\verbatim - y = tan(x)^2 -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_tan_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* y = z - num_taylor_per_var; - - size_t k; - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(double(q)) * ( x[m+ell] + x[m+ell] * y[0]); - for(k = 1; k < q; k++) - z[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * y[(q-k-1)*r+1+ell]; - z[m+ell] /= Base(double(q)); - // - y[m+ell] = Base(2.0) * z[m+ell] * z[0]; - for(k = 1; k < q; k++) - y[m+ell] += z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell]; - } -} - - -/*! -Compute zero order forward mode Taylor coefficient for result of op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tan(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_tan_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; // called z in documentation - Base* y = z - cap_order; // called y in documentation - - z[0] = tan( x[0] ); - y[0] = z[0] * z[0]; -} - -/*! -Compute reverse mode partial derivatives for result of op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tan(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_tan_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; // called z in doc - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* y = z - cap_order; // called y in documentation - Base* py = pz - nc_partial; - - - size_t j = d; - size_t k; - Base base_two(2); - while(j) - { - px[j] += pz[j]; - pz[j] /= Base(double(j)); - for(k = 1; k <= j; k++) - { px[k] += azmul(pz[j], y[j-k]) * Base(double(k)); - py[j-k] += azmul(pz[j], x[k]) * Base(double(k)); - } - for(k = 0; k < j; k++) - pz[k] += azmul(py[j-1], z[j-k-1]) * base_two; - - --j; - } - px[0] += azmul(pz[0], Base(1.0) + y[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/tanh_op.hpp b/external/cppad/include/cppad/local/tanh_op.hpp deleted file mode 100644 index 74ece717d..000000000 --- a/external/cppad/include/cppad/local/tanh_op.hpp +++ /dev/null @@ -1,230 +0,0 @@ -# ifndef CPPAD_LOCAL_TANH_OP_HPP -# define CPPAD_LOCAL_TANH_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file tanh_op.hpp -Forward and reverse mode calculations for z = tanh(x). -*/ - - -/*! -Compute forward mode Taylor coefficient for result of op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tanh(x) -\endverbatim -The auxillary result is -\verbatim - y = tanh(x)^2 -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op -*/ -template -inline void forward_tanh_op( - size_t p , - size_t q , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; - Base* y = z - cap_order; - - size_t k; - if( p == 0 ) - { z[0] = tanh( x[0] ); - y[0] = z[0] * z[0]; - p++; - } - for(size_t j = p; j <= q; j++) - { Base base_j = static_cast(double(j)); - - z[j] = x[j]; - for(k = 1; k <= j; k++) - z[j] -= Base(double(k)) * x[k] * y[j-k] / base_j; - - y[j] = z[0] * z[j]; - for(k = 1; k <= j; k++) - y[j] += z[k] * z[j-k]; - } -} - -/*! -Multiple directions forward mode Taylor coefficient for op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tanh(x) -\endverbatim -The auxillary result is -\verbatim - y = tanh(x)^2 -\endverbatim -The value of y, and its derivatives, are computed along with the value -and derivatives of z. - -\copydetails CppAD::local::forward_unary2_op_dir -*/ -template -inline void forward_tanh_op_dir( - size_t q , - size_t r , - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to argument and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + i_x * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - Base* y = z - num_taylor_per_var; - - size_t k; - size_t m = (q-1) * r + 1; - for(size_t ell = 0; ell < r; ell++) - { z[m+ell] = Base(double(q)) * ( x[m+ell] - x[m+ell] * y[0] ); - for(k = 1; k < q; k++) - z[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * y[(q-k-1)*r+1+ell]; - z[m+ell] /= Base(double(q)); - // - y[m+ell] = Base(2.0) * z[m+ell] * z[0]; - for(k = 1; k < q; k++) - y[m+ell] += z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell]; - } -} - -/*! -Compute zero order forward mode Taylor coefficient for result of op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tanh(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::forward_unary2_op_0 -*/ -template -inline void forward_tanh_op_0( - size_t i_z , - size_t i_x , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( 0 < cap_order ); - - // Taylor coefficients corresponding to argument and result - Base* x = taylor + i_x * cap_order; - Base* z = taylor + i_z * cap_order; // called z in documentation - Base* y = z - cap_order; // called y in documentation - - z[0] = tanh( x[0] ); - y[0] = z[0] * z[0]; -} - -/*! -Compute reverse mode partial derivatives for result of op = TanOp. - -The C++ source code corresponding to this operation is -\verbatim - z = tanh(x) -\endverbatim -The auxillary result is -\verbatim - y = cos(x) -\endverbatim -The value of y is computed along with the value of z. - -\copydetails CppAD::local::reverse_unary2_op -*/ - -template -inline void reverse_tanh_op( - size_t d , - size_t i_z , - size_t i_x , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Taylor coefficients and partials corresponding to argument - const Base* x = taylor + i_x * cap_order; - Base* px = partial + i_x * nc_partial; - - // Taylor coefficients and partials corresponding to first result - const Base* z = taylor + i_z * cap_order; // called z in doc - Base* pz = partial + i_z * nc_partial; - - // Taylor coefficients and partials corresponding to auxillary result - const Base* y = z - cap_order; // called y in documentation - Base* py = pz - nc_partial; - - - size_t j = d; - size_t k; - Base base_two(2); - while(j) - { - px[j] += pz[j]; - pz[j] /= Base(double(j)); - for(k = 1; k <= j; k++) - { px[k] -= azmul(pz[j], y[j-k]) * Base(double(k)); - py[j-k] -= azmul(pz[j], x[k]) * Base(double(k)); - } - for(k = 0; k < j; k++) - pz[k] += azmul(py[j-1], z[j-k-1]) * base_two; - - --j; - } - px[0] += azmul(pz[0], Base(1.0) - y[0]); -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/user_state.hpp b/external/cppad/include/cppad/local/user_state.hpp deleted file mode 100644 index e1900f95a..000000000 --- a/external/cppad/include/cppad/local/user_state.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// $Id$ -# ifndef CPPAD_LOCAL_USER_STATE_HPP -# define CPPAD_LOCAL_USER_STATE_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE - -enum enum_user_state { - /// next UserOp marks beginning of a user atomic call - start_user, - - /// next UsrapOp (UsravOp) is a parameter (variable) argument - arg_user, - - /// next UsrrpOp (UsrrvOp) is a parameter (variable) result - ret_user, - - /// next UserOp marks end of a user atomic call - end_user -}; - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/local/zmul_op.hpp b/external/cppad/include/cppad/local/zmul_op.hpp deleted file mode 100644 index 55bac42c0..000000000 --- a/external/cppad/include/cppad/local/zmul_op.hpp +++ /dev/null @@ -1,517 +0,0 @@ -# ifndef CPPAD_LOCAL_ZMUL_OP_HPP -# define CPPAD_LOCAL_ZMUL_OP_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE -/*! -\file mul_op.hpp -Forward and reverse mode calculations for z = azmul(x, y). -*/ - -// --------------------------- Zmulvv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = ZmulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_zmulvv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - size_t k; - for(size_t d = p; d <= q; d++) - { z[d] = Base(0.0); - for(k = 0; k <= d; k++) - z[d] += azmul(x[d-k], y[k]); - } -} -/*! -Multiple directions forward mode Taylor coefficients for op = ZmulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_zmulvv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var; - Base* y = taylor + arg[1] * num_taylor_per_var; - Base* z = taylor + i_z * num_taylor_per_var; - - size_t k, ell, m; - for(ell = 0; ell < r; ell++) - { m = (q-1)*r + ell + 1; - z[m] = azmul(x[0], y[m]) + azmul(x[m], y[0]); - for(k = 1; k < q; k++) - z[m] += azmul(x[(q-k-1)*r + ell + 1], y[(k-1)*r + ell + 1]); - } -} - -/*! -Compute zero order forward mode Taylor coefficients for result of op = ZmulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_zmulvv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = azmul(x[0], y[0]); -} - -/*! -Compute reverse mode partial derivatives for result of op = ZmulvvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where both x and y are variables -and the argument \a parameter is not used. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_zmulvv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - const Base* x = taylor + arg[0] * cap_order; - const Base* y = taylor + arg[1] * cap_order; - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t j = d + 1; - size_t k; - while(j) - { --j; - for(k = 0; k <= j; k++) - { - px[j-k] += azmul(pz[j], y[k]); - py[k] += azmul(pz[j], x[j-k]); - } - } -} -// --------------------------- Zmulpv ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = ZmulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_zmulpv_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Paraemter value - Base x = parameter[ arg[0] ]; - - for(size_t d = p; d <= q; d++) - z[d] = azmul(x, y[d]); -} -/*! -Multiple directions forward mode Taylor coefficients for op = ZmulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_zmulpv_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1) * r + 1; - Base* y = taylor + arg[1] * num_taylor_per_var + m; - Base* z = taylor + i_z * num_taylor_per_var + m; - - // Paraemter value - Base x = parameter[ arg[0] ]; - - for(size_t ell = 0; ell < r; ell++) - z[ell] = azmul(x, y[ell]); -} -/*! -Compute zero order forward mode Taylor coefficient for result of op = ZmulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_zmulpv_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 ); - - // Paraemter value - Base x = parameter[ arg[0] ]; - - // Taylor coefficients corresponding to arguments and result - Base* y = taylor + arg[1] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = azmul(x, y[0]); -} - -/*! -Compute reverse mode partial derivative for result of op = ZmulpvOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_zmulpv_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - Base x = parameter[ arg[0] ]; - - // Partial derivatives corresponding to arguments and result - Base* py = partial + arg[1] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t j = d + 1; - while(j) - { --j; - py[j] += azmul(pz[j], x); - } -} -// --------------------------- Zmulvp ----------------------------------------- -/*! -Compute forward mode Taylor coefficients for result of op = ZmulvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op -*/ - -template -inline void forward_zmulvp_op( - size_t p , - size_t q , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - CPPAD_ASSERT_UNKNOWN( p <= q ); - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z = taylor + i_z * cap_order; - - // Paraemter value - Base y = parameter[ arg[1] ]; - - for(size_t d = p; d <= q; d++) - z[d] = azmul(x[d], y); -} -/*! -Multiple directions forward mode Taylor coefficients for op = ZmulvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_dir -*/ - -template -inline void forward_zmulvp_op_dir( - size_t q , - size_t r , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( 0 < q ); - CPPAD_ASSERT_UNKNOWN( q < cap_order ); - - // Taylor coefficients corresponding to arguments and result - size_t num_taylor_per_var = (cap_order-1) * r + 1; - size_t m = (q-1) * r + 1; - Base* x = taylor + arg[0] * num_taylor_per_var + m; - Base* z = taylor + i_z * num_taylor_per_var + m; - - // Paraemter value - Base y = parameter[ arg[1] ]; - - for(size_t ell = 0; ell < r; ell++) - z[ell] = azmul(x[ell], y); -} -/*! -Compute zero order forward mode Taylor coefficient for result of op = ZmulvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::forward_binary_op_0 -*/ - -template -inline void forward_zmulvp_op_0( - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - Base* taylor ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 ); - - // Paraemter value - Base y = parameter[ arg[1] ]; - - // Taylor coefficients corresponding to arguments and result - Base* x = taylor + arg[0] * cap_order; - Base* z = taylor + i_z * cap_order; - - z[0] = azmul(x[0], y); -} - -/*! -Compute reverse mode partial derivative for result of op = ZmulvpOp. - -The C++ source code corresponding to this operation is -\verbatim - z = azmul(x, y) -\endverbatim -In the documentation below, -this operations is for the case where x is a parameter and y is a variable. - -\copydetails CppAD::local::reverse_binary_op -*/ - -template -inline void reverse_zmulvp_op( - size_t d , - size_t i_z , - const addr_t* arg , - const Base* parameter , - size_t cap_order , - const Base* taylor , - size_t nc_partial , - Base* partial ) -{ - // check assumptions - CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 ); - CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 ); - CPPAD_ASSERT_UNKNOWN( d < cap_order ); - CPPAD_ASSERT_UNKNOWN( d < nc_partial ); - - // Arguments - Base y = parameter[ arg[1] ]; - - // Partial derivatives corresponding to arguments and result - Base* px = partial + arg[0] * nc_partial; - Base* pz = partial + i_z * nc_partial; - - // number of indices to access - size_t j = d + 1; - while(j) - { --j; - px[j] += azmul(pz[j], y); - } -} - -} } // END_CPPAD_LOCAL_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/speed/det_33.hpp b/external/cppad/include/cppad/speed/det_33.hpp deleted file mode 100644 index 9c26567c1..000000000 --- a/external/cppad/include/cppad/speed/det_33.hpp +++ /dev/null @@ -1,114 +0,0 @@ -# ifndef CPPAD_SPEED_DET_33_HPP -# define CPPAD_SPEED_DET_33_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin det_33$$ -$spell - cppad - CppAD - det - namespace - const - bool - hpp -$$ - -$section Check Determinant of 3 by 3 matrix$$ -$mindex det_33 correct$$ - - -$head Syntax$$ -$codei%# include -%$$ -$icode%ok% = det_33(%x%, %d%)%$$ - -$head Purpose$$ -This routine can be used to check a method for computing -the determinant of a matrix. - -$head Inclusion$$ -The template function $code det_33$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/det_33.hpp$$ -(relative to the CppAD distribution directory). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$. -It contains the elements of the matrix $latex X$$ in row major order; i.e., -$latex \[ - X_{i,j} = x [ i * 3 + j ] -\] $$ - -$head d$$ -The argument $icode d$$ has prototype -$codei% - const %Vector% &%d% -%$$. -It is tested to see if $icode%d%[0]%$$ it is equal to $latex \det ( X )$$. - -$head Vector$$ -If $icode y$$ is a $icode Vector$$ object, -it must support the syntax -$codei% - %y%[%i%] -%$$ -where $icode i$$ has type $code size_t$$ with value less than 9. -This must return a $code double$$ value corresponding to the $th i$$ -element of the vector $icode y$$. -This is the only requirement of the type $icode Vector$$. -(Note that only the first element of the vector $icode d$$ is used.) - -$head ok$$ -The return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -It is true, if the determinant $icode%d%[0]%$$ -passes the test and false otherwise. - -$children% - omh/det_33_hpp.omh -%$$ - -$head Source Code$$ -The file -$cref det_33.hpp$$ -contains the source code for this template function. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -namespace CppAD { -template - bool det_33(const Vector &x, const Vector &d) - { bool ok = true; - double eps99 = 99.0 * std::numeric_limits::epsilon(); - - // use expansion by minors to compute the determinant by hand - double check = 0.; - check += x[0] * ( x[4] * x[8] - x[5] * x[7] ); - check -= x[1] * ( x[3] * x[8] - x[5] * x[6] ); - check += x[2] * ( x[3] * x[7] - x[4] * x[6] ); - - ok &= CppAD::NearEqual(check, d[0], eps99, eps99); - - return ok; - } -} -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/det_by_lu.hpp b/external/cppad/include/cppad/speed/det_by_lu.hpp deleted file mode 100644 index 751380ef6..000000000 --- a/external/cppad/include/cppad/speed/det_by_lu.hpp +++ /dev/null @@ -1,183 +0,0 @@ -# ifndef CPPAD_SPEED_DET_BY_LU_HPP -# define CPPAD_SPEED_DET_BY_LU_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin det_by_lu$$ -$spell - CppAD - cppad - lu - hpp - typedef - const - hpp - Det - CPPAD_TESTVECTOR - namespace -$$ - -$section Determinant Using Expansion by Lu Factorization$$ -$mindex det_by_lu factor$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%det_by_lu<%Scalar%> %det%(%n%) -%$$ -$icode%d% = %det%(%a%) -%$$ - -$head Inclusion$$ -The template class $code det_by_lu$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/det_by_lu.hpp$$ -(relative to the CppAD distribution directory). - -$head Constructor$$ -The syntax -$codei% - det_by_lu<%Scalar%> %det%(%n%) -%$$ -constructs the object $icode det$$ which can be used for -evaluating the determinant of $icode n$$ by $icode n$$ matrices -using LU factorization. - -$head Scalar$$ -The type $icode Scalar$$ can be any -$cref NumericType$$ - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ - -$head det$$ -The syntax -$codei% - %d% = %det%(%a%) -%$$ -returns the determinant of the matrix $latex A$$ using LU factorization. - -$subhead a$$ -The argument $icode a$$ has prototype -$codei% - const %Vector% &%a% -%$$ -It must be a $icode Vector$$ with length $latex n * n$$ and with -It must be a $icode Vector$$ with length $latex n * n$$ and with -elements of type $icode Scalar$$. -The elements of the $latex n \times n$$ matrix $latex A$$ are defined, -for $latex i = 0 , \ldots , n-1$$ and $latex j = 0 , \ldots , n-1$$, by -$latex \[ - A_{i,j} = a[ i * m + j] -\] $$ - -$subhead d$$ -The return value $icode d$$ has prototype -$codei% - %Scalar% %d% -%$$ - -$head Vector$$ -If $icode y$$ is a $icode Vector$$ object, -it must support the syntax -$codei% - %y%[%i%] -%$$ -where $icode i$$ has type $code size_t$$ with value less than $latex n * n$$. -This must return a $icode Scalar$$ value corresponding to the $th i$$ -element of the vector $icode y$$. -This is the only requirement of the type $icode Vector$$. - -$children% - speed/example/det_by_lu.cpp% - omh/det_by_lu_hpp.omh -%$$ - - -$head Example$$ -The file -$cref det_by_lu.cpp$$ -contains an example and test of $code det_by_lu.hpp$$. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The file -$cref det_by_lu.hpp$$ -contains the source for this template function. - - -$end ---------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include - -// BEGIN CppAD namespace -namespace CppAD { - -template -class det_by_lu { -private: - const size_t m_; - const size_t n_; - CppAD::vector A_; - CppAD::vector B_; - CppAD::vector X_; -public: - det_by_lu(size_t n) : m_(0), n_(n), A_(n * n) - { } - - template - inline Scalar operator()(const Vector &x) - { - - Scalar logdet; - Scalar det; - int signdet; - size_t i; - - // copy matrix so it is not overwritten - for(i = 0; i < n_ * n_; i++) - A_[i] = x[i]; - - // comput log determinant - signdet = CppAD::LuSolve( - n_, m_, A_, B_, X_, logdet); - -/* - // Do not do this for speed test because it makes floating - // point operation sequence very simple. - if( signdet == 0 ) - det = 0; - else det = Scalar( signdet ) * exp( logdet ); -*/ - - // convert to determinant - det = Scalar( signdet ) * exp( logdet ); - -# ifdef FADBAD - // Fadbad requires tempories to be set to constants - for(i = 0; i < n_ * n_; i++) - A_[i] = 0; -# endif - - return det; - } -}; -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/det_by_minor.hpp b/external/cppad/include/cppad/speed/det_by_minor.hpp deleted file mode 100644 index 7c53143c4..000000000 --- a/external/cppad/include/cppad/speed/det_by_minor.hpp +++ /dev/null @@ -1,166 +0,0 @@ -# ifndef CPPAD_SPEED_DET_BY_MINOR_HPP -# define CPPAD_SPEED_DET_BY_MINOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin det_by_minor$$ -$spell - CppAD - cppad - typedef - const - hpp - Det - namespace -$$ - -$section Determinant Using Expansion by Minors$$ - - - -$head Syntax$$ -$codei%# include -%$$ -$codei%det_by_minor<%Scalar%> %det%(%n%) -%$$ -$icode%d% = %det%(%a%) -%$$ - -$head Inclusion$$ -The template class $code det_by_minor$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/det_by_minor.hpp$$ -(relative to the CppAD distribution directory). - -$head Constructor$$ -The syntax -$codei% - det_by_minor<%Scalar%> %det%(%n%) -%$$ -constructs the object $icode det$$ which can be used for -evaluating the determinant of $icode n$$ by $icode n$$ matrices -using expansion by minors. - -$head Scalar$$ -The type $icode Scalar$$ must satisfy the same conditions -as in the function $cref/det_of_minor/det_of_minor/Scalar/$$. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ - -$head det$$ -The syntax -$codei% - %d% = %det%(%a%) -%$$ -returns the determinant of the matrix $icode A$$ using expansion by minors. - -$subhead a$$ -The argument $icode a$$ has prototype -$codei% - const %Vector% &%a% -%$$ -It must be a $icode Vector$$ with length $latex n * n$$ and with -elements of type $icode Scalar$$. -The elements of the $latex n \times n$$ matrix $latex A$$ are defined, -for $latex i = 0 , \ldots , n-1$$ and $latex j = 0 , \ldots , n-1$$, by -$latex \[ - A_{i,j} = a[ i * m + j] -\] $$ - -$subhead d$$ -The return value $icode d$$ has prototype -$codei% - %Scalar% %d% -%$$ -It is equal to the determinant of $latex A$$. - -$head Vector$$ -If $icode y$$ is a $icode Vector$$ object, -it must support the syntax -$codei% - %y%[%i%] -%$$ -where $icode i$$ has type $code size_t$$ with value less than $latex n * n$$. -This must return a $icode Scalar$$ value corresponding to the $th i$$ -element of the vector $icode y$$. -This is the only requirement of the type $icode Vector$$. - -$children% - speed/example/det_by_minor.cpp% - omh/det_by_minor_hpp.omh -%$$ - - -$head Example$$ -The file -$cref det_by_minor.cpp$$ -contains an example and test of $code det_by_minor.hpp$$. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The file -$cref det_by_minor.hpp$$ -contains the source for this template function. - - -$end ---------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include - -// BEGIN CppAD namespace -namespace CppAD { - -template -class det_by_minor { -private: - size_t m_; - - // made mutable because modified and then restored - mutable std::vector r_; - mutable std::vector c_; - - // make mutable because its value does not matter - mutable std::vector a_; -public: - det_by_minor(size_t m) : m_(m) , r_(m + 1) , c_(m + 1), a_(m * m) - { - size_t i; - - // values for r and c that correspond to entire matrix - for(i = 0; i < m; i++) - { r_[i] = i+1; - c_[i] = i+1; - } - r_[m] = 0; - c_[m] = 0; - } - - template - inline Scalar operator()(const Vector &x) const - { size_t i = m_ * m_; - while(i--) - a_[i] = x[i]; - return det_of_minor(a_, m_, m_, r_, c_); - } - -}; - -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/det_grad_33.hpp b/external/cppad/include/cppad/speed/det_grad_33.hpp deleted file mode 100644 index 3a10b5d9b..000000000 --- a/external/cppad/include/cppad/speed/det_grad_33.hpp +++ /dev/null @@ -1,128 +0,0 @@ -# ifndef CPPAD_SPEED_DET_GRAD_33_HPP -# define CPPAD_SPEED_DET_GRAD_33_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin det_grad_33$$ -$spell - cppad - CppAD - det - namespace - const - bool - hpp -$$ - -$section Check Gradient of Determinant of 3 by 3 matrix$$ -$mindex det_grad_33 correct$$ - - -$head Syntax$$ -$codei%# include -%$$ -$icode%ok% = det_grad_33(%x%, %g%)%$$ - -$head Purpose$$ -This routine can be used to check a method for computing the -gradient of the determinant of a matrix. - -$head Inclusion$$ -The template function $code det_grad_33$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/det_grad_33.hpp$$ -(relative to the CppAD distribution directory). - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$. -It contains the elements of the matrix $latex X$$ in row major order; i.e., -$latex \[ - X_{i,j} = x [ i * 3 + j ] -\] $$ - -$head g$$ -The argument $icode g$$ has prototype -$codei% - const %Vector% &%g% -%$$. -It contains the elements of the gradient of -$latex \det ( X )$$ in row major order; i.e., -$latex \[ - \D{\det (X)}{X(i,j)} = g [ i * 3 + j ] -\] $$ - -$head Vector$$ -If $icode y$$ is a $icode Vector$$ object, -it must support the syntax -$codei% - %y%[%i%] -%$$ -where $icode i$$ has type $code size_t$$ with value less than 9. -This must return a $code double$$ value corresponding to the $th i$$ -element of the vector $icode y$$. -This is the only requirement of the type $icode Vector$$. - -$head ok$$ -The return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -It is true, if the gradient $icode g$$ -passes the test and false otherwise. - -$children% - omh/det_grad_33_hpp.omh -%$$ - -$head Source Code$$ -The file -$cref det_grad_33.hpp$$ -contains the source code for this template function. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include -namespace CppAD { -template - bool det_grad_33(const Vector &x, const Vector &g) - { bool ok = true; - typedef typename Vector::value_type Float; - Float eps = 10. * Float( std::numeric_limits::epsilon() ); - - // use expansion by minors to compute the derivative by hand - double check[9]; - check[0] = + ( x[4] * x[8] - x[5] * x[7] ); - check[1] = - ( x[3] * x[8] - x[5] * x[6] ); - check[2] = + ( x[3] * x[7] - x[4] * x[6] ); - // - check[3] = - ( x[1] * x[8] - x[2] * x[7] ); - check[4] = + ( x[0] * x[8] - x[2] * x[6] ); - check[5] = - ( x[0] * x[7] - x[1] * x[6] ); - // - check[6] = + ( x[1] * x[5] - x[2] * x[4] ); - check[7] = - ( x[0] * x[5] - x[2] * x[3] ); - check[8] = + ( x[0] * x[4] - x[1] * x[3] ); - // - for(size_t i = 0; i < 3 * 3; i++) - ok &= CppAD::NearEqual(check[i], g[i], eps, eps); - - return ok; - } -} -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/det_of_minor.hpp b/external/cppad/include/cppad/speed/det_of_minor.hpp deleted file mode 100644 index 663e1f3b5..000000000 --- a/external/cppad/include/cppad/speed/det_of_minor.hpp +++ /dev/null @@ -1,275 +0,0 @@ -# ifndef CPPAD_SPEED_DET_OF_MINOR_HPP -# define CPPAD_SPEED_DET_OF_MINOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin det_of_minor$$ -$spell - CppAD - hpp - std - Det - const - namespace - cppad -$$ - - -$section Determinant of a Minor$$ -$mindex det_of_minor matrix$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%d% = det_of_minor(%a%, %m%, %n%, %r%, %c%)%$$ - - -$head Inclusion$$ -The template function $code det_of_minor$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/det_of_minor.hpp$$ -(relative to the CppAD distribution directory). - -$head Purpose$$ -This template function -returns the determinant of a minor of the matrix $latex A$$ -using expansion by minors. -The elements of the $latex n \times n$$ minor $latex M$$ -of the matrix $latex A$$ are defined, -for $latex i = 0 , \ldots , n-1$$ and $latex j = 0 , \ldots , n-1$$, by -$latex \[ - M_{i,j} = A_{R(i), C(j)} -\]$$ -where the functions -$latex R(i)$$ is defined by the $cref/argument r/det_of_minor/r/$$ and -$latex C(j)$$ is defined by the $cref/argument c/det_of_minor/c/$$. -$pre - -$$ -This template function -is for example and testing purposes only. -Expansion by minors is chosen as an example because it uses -a lot of floating point operations yet does not require much source code -(on the order of $icode m$$ factorial floating point operations and -about 70 lines of source code including comments). -This is not an efficient method for computing a determinant; -for example, using an LU factorization would be better. - -$head Determinant of A$$ -If the following conditions hold, the minor is the -entire matrix $latex A$$ and hence $code det_of_minor$$ -will return the determinant of $latex A$$: - -$list number$$ -$latex n = m$$. -$lnext -for $latex i = 0 , \ldots , m-1$$, $latex r[i] = i+1$$, -and $latex r[m] = 0$$. -$lnext -for $latex j = 0 , \ldots , m-1$$, $latex c[j] = j+1$$, -and $latex c[m] = 0$$. -$lend - -$head a$$ -The argument $icode a$$ has prototype -$codei% - const std::vector<%Scalar%>& %a% -%$$ -and is a vector with size $latex m * m$$ -(see description of $cref/Scalar/det_of_minor/Scalar/$$ below). -The elements of the $latex m \times m$$ matrix $latex A$$ are defined, -for $latex i = 0 , \ldots , m-1$$ and $latex j = 0 , \ldots , m-1$$, by -$latex \[ - A_{i,j} = a[ i * m + j] -\] $$ - -$head m$$ -The argument $icode m$$ has prototype -$codei% - size_t %m% -%$$ -and is the number of rows (and columns) in the square matrix $latex A$$. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -and is the number of rows (and columns) in the square minor $latex M$$. - -$head r$$ -The argument $icode r$$ has prototype -$codei% - std::vector& %r% -%$$ -and is a vector with $latex m + 1$$ elements. -This vector defines the function $latex R(i)$$ -which specifies the rows of the minor $latex M$$. -To be specific, the function $latex R(i)$$ -for $latex i = 0, \ldots , n-1$$ is defined by -$latex \[ -\begin{array}{rcl} - R(0) & = & r[m] - \\ - R(i+1) & = & r[ R(i) ] -\end{array} -\] $$ -All the elements of $icode r$$ must have value -less than or equal $icode m$$. -The elements of vector $icode r$$ are modified during the computation, -and restored to their original value before the return from -$code det_of_minor$$. - -$head c$$ -The argument $icode c$$ has prototype -$codei% - std::vector& %c% -%$$ -and is a vector with $latex m + 1$$ elements -This vector defines the function $latex C(i)$$ -which specifies the rows of the minor $latex M$$. -To be specific, the function $latex C(i)$$ -for $latex j = 0, \ldots , n-1$$ is defined by -$latex \[ -\begin{array}{rcl} - C(0) & = & c[m] - \\ - C(j+1) & = & c[ C(j) ] -\end{array} -\] $$ -All the elements of $icode c$$ must have value -less than or equal $icode m$$. -The elements of vector $icode c$$ are modified during the computation, -and restored to their original value before the return from -$code det_of_minor$$. - -$head d$$ -The result $icode d$$ has prototype -$codei% - %Scalar% %d% -%$$ -and is equal to the determinant of the minor $latex M$$. - -$head Scalar$$ -If $icode x$$ and $icode y$$ are objects of type $icode Scalar$$ -and $icode i$$ is an object of type $code int$$, -the $icode Scalar$$ must support the following operations: -$table -$bold Syntax$$ - $cnext $bold Description$$ - $cnext $bold Result Type$$ -$rnext -$icode%Scalar% %x%$$ - $cnext default constructor for $icode Scalar$$ object. -$rnext -$icode%x% = %i%$$ - $cnext set value of $icode x$$ to current value of $icode i$$ -$rnext -$icode%x% = %y%$$ - $cnext set value of $icode x$$ to current value of $icode y$$ -$rnext -$icode%x% + %y%$$ - $cnext value of $icode x$$ plus $icode y$$ - $cnext $icode Scalar$$ -$rnext -$icode%x% - %y%$$ - $cnext value of $icode x$$ minus $icode y$$ - $cnext $icode Scalar$$ -$rnext -$icode%x% * %y%$$ - $cnext value of $icode x$$ times value of $icode y$$ - $cnext $icode Scalar$$ -$tend - -$children% - speed/example/det_of_minor.cpp% - omh/det_of_minor_hpp.omh -%$$ - -$head Example$$ -The file -$cref det_of_minor.cpp$$ -contains an example and test of $code det_of_minor.hpp$$. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The file -$cref det_of_minor.hpp$$ -contains the source for this template function. - - -$end ---------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include - -namespace CppAD { // BEGIN CppAD namespace -template -Scalar det_of_minor( - const std::vector& a , - size_t m , - size_t n , - std::vector& r , - std::vector& c ) -{ - const size_t R0 = r[m]; // R(0) - size_t Cj = c[m]; // C(j) (case j = 0) - size_t Cj1 = m; // C(j-1) (case j = 0) - - // check for 1 by 1 case - if( n == 1 ) return a[ R0 * m + Cj ]; - - // initialize determinant of the minor M - Scalar detM = Scalar(0); - - // initialize sign of factor for next sub-minor - int s = 1; - - // remove row with index 0 in M from all the sub-minors of M - r[m] = r[R0]; - - // for each column of M - for(size_t j = 0; j < n; j++) - { // element with index (0,j) in the minor M - Scalar M0j = a[ R0 * m + Cj ]; - - // remove column with index j in M to form next sub-minor S of M - c[Cj1] = c[Cj]; - - // compute determinant of the current sub-minor S - Scalar detS = det_of_minor(a, m, n - 1, r, c); - - // restore column Cj to represenation of M as a minor of A - c[Cj1] = Cj; - - // include this sub-minor term in the summation - if( s > 0 ) - detM = detM + M0j * detS; - else detM = detM - M0j * detS; - - // advance to next column of M - Cj1 = Cj; - Cj = c[Cj]; - s = - s; - } - - // restore row zero to the minor representation for M - r[m] = R0; - - // return the determinant of the minor M - return detM; -} -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/mat_sum_sq.hpp b/external/cppad/include/cppad/speed/mat_sum_sq.hpp deleted file mode 100644 index 8aa0a9880..000000000 --- a/external/cppad/include/cppad/speed/mat_sum_sq.hpp +++ /dev/null @@ -1,154 +0,0 @@ -# ifndef CPPAD_SPEED_MAT_SUM_SQ_HPP -# define CPPAD_SPEED_MAT_SUM_SQ_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin mat_sum_sq$$ -$spell - sq - namespace - const - CppAD - sq - cppad - hpp -$$ - -$section Sum Elements of a Matrix Times Itself$$ -$mindex mat_sum_sq multiply speed test$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%mat_sum_sq(%n%, %x%, %y%, %z%)%$$ - -$head Purpose$$ -This routine is intended for use with the matrix multiply speed tests; -to be specific, it computes -$latex \[ -\begin{array}{rcl} - y_{i,j} & = & \sum_{k=0}^{n-1} x_{i,k} x_{k,j} - \\ - z_0 & = & \sum_{i=0}^{n-1} \sum_{j=0}^{n-1} y_{i,j} -\end{array} -\] $$ -see $cref link_mat_mul$$. - -$head Inclusion$$ -The template function $code mat_sum_sq$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/mat_sum_sq.hpp$$ -(relative to the CppAD distribution directory). - -$head n$$ -This argument has prototype -$codei% - size_t %n% -%$$ -It specifies the size of the matrices. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -and $icode%x%.size() == %n% * %n%$$. -It contains the elements of $latex x$$ in row major order; i.e., -$latex \[ - x_{i,j} = x [ i * n + j ] -\] $$ - -$head y$$ -The argument $icode y$$ has prototype -$codei% - %Vector%& %y% -%$$ -and $icode%y%.size() == %n% * %n%$$. -The input value of its elements does not matter. -Upon return, -$latex \[ -\begin{array}{rcl} - y_{i,j} & = & \sum_{k=0}^{n-1} x_{i,k} x_{k,j} - \\ - y[ i * n + j ] & = & y_{i,j} -\end{array} -\] $$ - - -$head z$$ -The argument $icode d$$ has prototype -$codei% - %Vector%& %z% -%$$. -The input value of its element does not matter. -Upon return -$latex \[ -\begin{array}{rcl} - z_0 & = & \sum_{i=0}^{n-1} \sum_{j=0}^n y_{i,j} - \\ - z[0] & = & z_0 -\end{array} -\] $$ - -$head Vector$$ -The type $icode Vector$$ is any -$cref SimpleVector$$, or it can be a raw pointer to the vector elements. -The element type must support -addition, multiplication, and assignment to both its own type -and to a double value. - -$children% - speed/example/mat_sum_sq.cpp% - omh/mat_sum_sq_hpp.omh -%$$ - - -$head Example$$ -The file -$cref mat_sum_sq.cpp$$ -contains an example and test of $code mat_sum_sq.hpp$$. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The file -$cref mat_sum_sq.hpp$$ -contains the source for this template function. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -// -namespace CppAD { - template - void mat_sum_sq(size_t n, Vector& x , Vector& y , Vector& z) - { size_t i, j, k; - // Very simple computation of y = x * x for speed comparison - for(i = 0; i < n; i++) - { for(j = 0; j < n; j++) - { y[i * n + j] = 0.; - for(k = 0; k < n; k++) - y[i * n + j] += x[i * n + k] * x[k * n + j]; - } - } - z[0] = 0.; - for(i = 0; i < n; i++) - { for(j = 0; j < n; j++) - z[0] += y[i * n + j]; - } - return; - } - -} -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/ode_evaluate.hpp b/external/cppad/include/cppad/speed/ode_evaluate.hpp deleted file mode 100644 index 4e7671753..000000000 --- a/external/cppad/include/cppad/speed/ode_evaluate.hpp +++ /dev/null @@ -1,238 +0,0 @@ -# ifndef CPPAD_SPEED_ODE_EVALUATE_HPP -# define CPPAD_SPEED_ODE_EVALUATE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ode_evaluate$$ -$spell - Runge - fabs - retaped - Jacobian - const - Cpp - cppad - hpp - fp - namespace - exp -$$ - -$section Evaluate a Function Defined in Terms of an ODE$$ -$mindex ode_evaluate$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%ode_evaluate(%x%, %p%, %fp%)%$$ - -$head Purpose$$ -This routine evaluates a function $latex f : \B{R}^n \rightarrow \B{R}^n$$ -defined by -$latex \[ - f(x) = y(x, 1) -\] $$ -where $latex y(x, t)$$ solves the ordinary differential equation -$latex \[ -\begin{array}{rcl} - y(x, 0) & = & x - \\ - \partial_t y (x, t ) & = & g[ y(x,t) , t ] -\end{array} -\] $$ -where $latex g : \B{R}^n \times \B{R} \rightarrow \B{R}^n$$ -is an unspecified function. - -$head Inclusion$$ -The template function $code ode_evaluate$$ -is defined in the $code CppAD$$ namespace by including -the file $code cppad/speed/ode_evaluate.hpp$$ -(relative to the CppAD distribution directory). - -$head Float$$ - -$subhead Operation Sequence$$ -The type $icode Float$$ must be a $cref NumericType$$. -The $icode Float$$ -$cref/operation sequence/glossary/Operation/Sequence/$$ -for this routine does not depend on the value of the argument $icode x$$, -hence it does not need to be retaped for each value of $latex x$$. - -$subhead fabs$$ -If $icode y$$ and $icode z$$ are $icode Float$$ objects, the syntax -$codei% - %y% = fabs(%z%) -%$$ -must be supported. Note that it does not matter if the operation -sequence for $code fabs$$ depends on $icode z$$ because the -corresponding results are not actually used by $code ode_evaluate$$; -see $code fabs$$ in $cref/Runge45/Runge45/Scalar/fabs/$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const CppAD::vector<%Float%>& %x% -%$$ -It contains he argument value for which the function, -or its derivative, is being evaluated. -The value $latex n$$ is determined by the size of the vector $icode x$$. - -$head p$$ -The argument $icode p$$ has prototype -$codei% - size_t %p% -%$$ - -$subhead p == 0$$ -In this case a numerical method is used to solve the ode -and obtain an accurate approximation for $latex y(x, 1)$$. -This numerical method has a fixed -that does not depend on $icode x$$. - -$subhead p = 1$$ -In this case an analytic solution for the partial derivative -$latex \partial_x y(x, 1)$$ is returned. - -$head fp$$ -The argument $icode fp$$ has prototype -$codei% - CppAD::vector<%Float%>& %fp% -%$$ -The input value of the elements of $icode fp$$ does not matter. - -$subhead Function$$ -If $icode p$$ is zero, $icode fp$$ has size equal to $latex n$$ -and contains the value of $latex y(x, 1)$$. - -$subhead Gradient$$ -If $icode p$$ is one, $icode fp$$ has size equal to $icode n^2$$ -and for $latex i = 0 , \ldots 1$$, $latex j = 0 , \ldots , n-1$$ -$latex \[ - \D{y[i]}{x[j]} (x, 1) = fp [ i \cdot n + j ] -\] $$ - -$children% - speed/example/ode_evaluate.cpp% - omh/ode_evaluate.omh -%$$ - -$head Example$$ -The file -$cref ode_evaluate.cpp$$ -contains an example and test of $code ode_evaluate.hpp$$. -It returns true if it succeeds and false otherwise. - - -$head Source Code$$ -The file -$cref ode_evaluate.hpp$$ -contains the source code for this template function. - -$end -*/ -// BEGIN C++ -# include -# include -# include - -namespace CppAD { - - template - class ode_evaluate_fun { - public: - // Given that y_i (0) = x_i, - // the following y_i (t) satisfy the ODE below: - // y_0 (t) = x[0] - // y_1 (t) = x[1] + x[0] * t - // y_2 (t) = x[2] + x[1] * t + x[0] * t^2/2 - // y_3 (t) = x[3] + x[2] * t + x[1] * t^2/2 + x[0] * t^3 / 3! - // ... - void Ode( - const Float& t, - const CppAD::vector& y, - CppAD::vector& f) - { size_t n = y.size(); - f[0] = 0.; - for(size_t k = 1; k < n; k++) - f[k] = y[k-1]; - } - }; - // - template - void ode_evaluate( - const CppAD::vector& x , - size_t p , - CppAD::vector& fp ) - { using CppAD::vector; - typedef vector VectorFloat; - - size_t n = x.size(); - CPPAD_ASSERT_KNOWN( p == 0 || p == 1, - "ode_evaluate: p is not zero or one" - ); - CPPAD_ASSERT_KNOWN( - ((p==0) & (fp.size()==n)) || ((p==1) & (fp.size()==n*n)), - "ode_evaluate: the size of fp is not correct" - ); - if( p == 0 ) - { // function that defines the ode - ode_evaluate_fun F; - - // number of Runge45 steps to use - size_t M = 10; - - // initial and final time - Float ti = 0.0; - Float tf = 1.0; - - // initial value for y(x, t); i.e. y(x, 0) - // (is a reference to x) - const VectorFloat& yi = x; - - // final value for y(x, t); i.e., y(x, 1) - // (is a reference to fp) - VectorFloat& yf = fp; - - // Use fourth order Runge-Kutta to solve ODE - yf = CppAD::Runge45(F, M, ti, tf, yi); - - return; - } - /* Compute derivaitve of y(x, 1) w.r.t x - y_0 (x, t) = x[0] - y_1 (x, t) = x[1] + x[0] * t - y_2 (x, t) = x[2] + x[1] * t + x[0] * t^2/2 - y_3 (x, t) = x[3] + x[2] * t + x[1] * t^2/2 + x[0] * t^3 / 3! - ... - */ - size_t i, j, k; - for(i = 0; i < n; i++) - { for(j = 0; j < n; j++) - fp[ i * n + j ] = 0.0; - } - size_t factorial = 1; - for(k = 0; k < n; k++) - { if( k > 1 ) - factorial *= k; - for(i = k; i < n; i++) - { // partial w.r.t x[i-k] of x[i-k] * t^k / k! - j = i - k; - fp[ i * n + j ] += 1.0 / Float(factorial); - } - } - } -} -// END C++ - -# endif diff --git a/external/cppad/include/cppad/speed/sparse_hes_fun.hpp b/external/cppad/include/cppad/speed/sparse_hes_fun.hpp deleted file mode 100644 index 4db23635e..000000000 --- a/external/cppad/include/cppad/speed/sparse_hes_fun.hpp +++ /dev/null @@ -1,264 +0,0 @@ -# ifndef CPPAD_SPEED_SPARSE_HES_FUN_HPP -# define CPPAD_SPEED_SPARSE_HES_FUN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin sparse_hes_fun$$ -$spell - hes - cppad - hpp - fp - CppAD - namespace - const - bool - exp - arg -$$ - -$section Evaluate a Function That Has a Sparse Hessian$$ -$mindex sparse_hes_fun$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%sparse_hes_fun(%n%, %x%, %row%, %col%, %p%, %fp%)%$$ - -$head Purpose$$ -This routine evaluates -$latex f(x)$$, $latex f^{(1)} (x)$$, or $latex f^{(2)} (x)$$ -where the Hessian $latex f^{(2)} (x)$$ is sparse. -The function $latex f : \B{R}^n \rightarrow \B{R}$$ only depends on the -size and contents of the index vectors $icode row$$ and $icode col$$. -The non-zero entries in the Hessian of this function have -one of the following forms: -$latex \[ - \DD{f}{x[row[k]]}{x[row[k]]} - \; , \; - \DD{f}{x[row[k]]}{x[col[k]]} - \; , \; - \DD{f}{x[col[k]]}{x[row[k]]} - \; , \; - \DD{f}{x[col[k]]}{x[col[k]]} -\] $$ -for some $latex k $$ between zero and $latex K-1 $$. -All the other terms of the Hessian are zero. - -$head Inclusion$$ -The template function $code sparse_hes_fun$$ -is defined in the $code CppAD$$ namespace by including -the file $code cppad/speed/sparse_hes_fun.hpp$$ -(relative to the CppAD distribution directory). - -$head Float$$ -The type $icode Float$$ must be a $cref NumericType$$. -In addition, if $icode y$$ and $icode z$$ are $icode Float$$ objects, -$codei% - %y% = exp(%z%) -%$$ -must set the $icode y$$ equal the exponential of $icode z$$, i.e., -the derivative of $icode y$$ with respect to $icode z$$ is equal to $icode y$$. - -$head FloatVector$$ -The type $icode FloatVector$$ is any -$cref SimpleVector$$, or it can be a raw pointer, -with elements of type $icode Float$$. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -It specifies the dimension for the domain space for $latex f(x)$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %FloatVector%& %x% -%$$ -It contains the argument value for which the function, -or its derivative, is being evaluated. -We use $latex n$$ to denote the size of the vector $icode x$$. - -$head row$$ -The argument $icode row$$ has prototype -$codei% - const CppAD::vector& %row% -%$$ -It specifies one of the first -index of $latex x$$ for each non-zero Hessian term -(see $cref/purpose/sparse_hes_fun/Purpose/$$ above). -All the elements of $icode row$$ must be between zero and $icode%n%-1%$$. -The value $latex K$$ is defined by $icode%K% = %row%.size()%$$. - -$head col$$ -The argument $icode col$$ has prototype -$codei% - const CppAD::vector& %col% -%$$ -and its size must be $latex K$$; i.e., the same as for $icode col$$. -It specifies the second -index of $latex x$$ for the non-zero Hessian terms. -All the elements of $icode col$$ must be between zero and $icode%n%-1%$$. -There are no duplicated entries requested, to be specific, -if $icode%k1% != %k2%$$ then -$codei% - ( %row%[%k1%] , %col%[%k1%] ) != ( %row%[%k2%] , %col%[%k2%] ) -%$$ - -$head p$$ -The argument $icode p$$ has prototype -$codei% - size_t %p% -%$$ -It is either zero or two and -specifies the order of the derivative of $latex f$$ -that is being evaluated, i.e., $latex f^{(p)} (x)$$ is evaluated. - -$head fp$$ -The argument $icode fp$$ has prototype -$codei% - %FloatVector%& %fp% -%$$ -The input value of the elements of $icode fp$$ does not matter. - -$subhead Function$$ -If $icode p$$ is zero, $icode fp$$ has size one and -$icode%fp%[0]%$$ is the value of $latex f(x)$$. - -$subhead Hessian$$ -If $icode p$$ is two, $icode fp$$ has size $icode K$$ and -for $latex k = 0 , \ldots , K-1$$, -$latex \[ - \DD{f}{ x[ \R{row}[k] ] }{ x[ \R{col}[k] ]} = fp [k] -\] $$ - -$children% - speed/example/sparse_hes_fun.cpp% - omh/sparse_hes_fun.omh -%$$ - -$head Example$$ -The file -$cref sparse_hes_fun.cpp$$ -contains an example and test of $code sparse_hes_fun.hpp$$. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The file -$cref sparse_hes_fun.hpp$$ -contains the source code for this template function. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include -# include - -// following needed by gcc under fedora 17 so that exp(double) is defined -# include - -namespace CppAD { - template - void sparse_hes_fun( - size_t n , - const FloatVector& x , - const CppAD::vector& row , - const CppAD::vector& col , - size_t p , - FloatVector& fp ) - { - // check numeric type specifications - CheckNumericType(); - - // check value of p - CPPAD_ASSERT_KNOWN( - p == 0 || p == 2, - "sparse_hes_fun: p != 0 and p != 2" - ); - - size_t K = row.size(); - size_t i, j, k; - if( p == 0 ) - fp[0] = Float(0); - else - { for(k = 0; k < K; k++) - fp[k] = Float(0); - } - - // determine which diagonal entries are present in row[k], col[k] - CppAD::vector diagonal(n); - for(i = 0; i < n; i++) - diagonal[i] = K; // no diagonal entry for this row - for(k = 0; k < K; k++) - { if( row[k] == col[k] ) - { CPPAD_ASSERT_UNKNOWN( diagonal[row[k]] == K ); - // index of the diagonal entry - diagonal[ row[k] ] = k; - } - } - - // determine which entries must be multiplied by a factor of two - CppAD::vector factor(K); - for(k = 0; k < K; k++) - { factor[k] = Float(1); - for(size_t k1 = 0; k1 < K; k1++) - { bool reflected = true; - reflected &= k != k1; - reflected &= row[k] != col[k]; - reflected &= row[k] == col[k1]; - reflected &= col[k] == row[k1]; - if( reflected ) - factor[k] = Float(2); - } - } - - Float t; - for(k = 0; k < K; k++) - { i = row[k]; - j = col[k]; - t = exp( x[i] * x[j] ); - switch(p) - { - case 0: - fp[0] += t; - break; - - case 2: - if( i == j ) - { // dt_dxi = 2.0 * xi * t - fp[k] += ( Float(2) + Float(4) * x[i] * x[i] ) * t; - } - else - { // dt_dxi = xj * t - fp[k] += factor[k] * ( Float(1) + x[i] * x[j] ) * t; - if( diagonal[i] != K ) - { size_t ki = diagonal[i]; - fp[ki] += x[j] * x[j] * t; - } - if( diagonal[j] != K ) - { size_t kj = diagonal[j]; - fp[kj] += x[i] * x[i] * t; - } - } - break; - } - } - - } -} -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/sparse_jac_fun.hpp b/external/cppad/include/cppad/speed/sparse_jac_fun.hpp deleted file mode 100644 index f05383e61..000000000 --- a/external/cppad/include/cppad/speed/sparse_jac_fun.hpp +++ /dev/null @@ -1,221 +0,0 @@ -# ifndef CPPAD_SPEED_SPARSE_JAC_FUN_HPP -# define CPPAD_SPEED_SPARSE_JAC_FUN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin sparse_jac_fun$$ -$spell - Jacobian - jac - cppad - hpp - fp - CppAD - namespace - const - bool - exp - arg -$$ - -$section Evaluate a Function That Has a Sparse Jacobian$$ -$mindex sparse_jac_fun$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%sparse_jac_fun(%m%, %n%, %x%, %row%, %col%, %p%, %fp%)%$$ - -$head Purpose$$ -This routine evaluates -$latex f(x)$$ and $latex f^{(1)} (x)$$ -where the Jacobian $latex f^{(1)} (x)$$ is sparse. -The function $latex f : \B{R}^n \rightarrow \B{R}^m$$ only depends on the -size and contents of the index vectors $icode row$$ and $icode col$$. -The non-zero entries in the Jacobian of this function have -one of the following forms: -$latex \[ - \D{ f[row[k]]}{x[col[k]]} -\] $$ -for some $latex k $$ between zero and $latex K-1$$. -All the other terms of the Jacobian are zero. - -$head Inclusion$$ -The template function $code sparse_jac_fun$$ -is defined in the $code CppAD$$ namespace by including -the file $code cppad/speed/sparse_jac_fun.hpp$$ -(relative to the CppAD distribution directory). - -$head Float$$ -The type $icode Float$$ must be a $cref NumericType$$. -In addition, if $icode y$$ and $icode z$$ are $icode Float$$ objects, -$codei% - %y% = exp(%z%) -%$$ -must set the $icode y$$ equal the exponential of $icode z$$, i.e., -the derivative of $icode y$$ with respect to $icode z$$ is equal to $icode y$$. - -$head FloatVector$$ -The type $icode FloatVector$$ is any -$cref SimpleVector$$, or it can be a raw pointer, -with elements of type $icode Float$$. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -It specifies the dimension for the domain space for $latex f(x)$$. - -$head m$$ -The argument $icode m$$ has prototype -$codei% - size_t %m% -%$$ -It specifies the dimension for the range space for $latex f(x)$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %FloatVector%& %x% -%$$ -It contains the argument value for which the function, -or its derivative, is being evaluated. -We use $latex n$$ to denote the size of the vector $icode x$$. - -$head row$$ -The argument $icode row$$ has prototype -$codei% - const CppAD::vector& %row% -%$$ -It specifies indices in the range of $latex f(x)$$ for non-zero components -of the Jacobian -(see $cref/purpose/sparse_hes_fun/Purpose/$$ above). -The value $latex K$$ is defined by $icode%K% = %row%.size()%$$. -All the elements of $icode row$$ must be between zero and $icode%m%-1%$$. - -$head col$$ -The argument $icode col$$ has prototype -$codei% - const CppAD::vector& %col% -%$$ -and its size must be $latex K$$; i.e., the same as $icode row$$. -It specifies the component of $latex x$$ for -the non-zero Jacobian terms. -All the elements of $icode col$$ must be between zero and $icode%n%-1%$$. - -$head p$$ -The argument $icode p$$ has prototype -$codei% - size_t %p% -%$$ -It is either zero or one and -specifies the order of the derivative of $latex f$$ -that is being evaluated, i.e., $latex f^{(p)} (x)$$ is evaluated. - -$head fp$$ -The argument $icode fp$$ has prototype -$codei% - %FloatVector%& %fp% -%$$ -If $icode%p% = 0%$$, it size is $icode m$$ -otherwise its size is $icode K$$. -The input value of the elements of $icode fp$$ does not matter. - -$subhead Function$$ -If $icode p$$ is zero, $icode fp$$ has size $latex m$$ and -$codei%(%fp%[0]%, ... , %fp%[%m%-1])%$$ is the value of $latex f(x)$$. - -$subhead Jacobian$$ -If $icode p$$ is one, $icode fp$$ has size $icode K$$ and -for $latex k = 0 , \ldots , K-1$$, -$latex \[ - \D{f[ \R{row}[i] ]}{x[ \R{col}[j] ]} = fp [k] -\] $$ - -$children% - speed/example/sparse_jac_fun.cpp% - omh/sparse_jac_fun.omh -%$$ - -$head Example$$ -The file -$cref sparse_jac_fun.cpp$$ -contains an example and test of $code sparse_jac_fun.hpp$$. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The file -$cref sparse_jac_fun.hpp$$ -contains the source code for this template function. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include -# include - -// following needed by gcc under fedora 17 so that exp(double) is defined -# include - -namespace CppAD { - template - void sparse_jac_fun( - size_t m , - size_t n , - const FloatVector& x , - const CppAD::vector& row , - const CppAD::vector& col , - size_t p , - FloatVector& fp ) - { - // check numeric type specifications - CheckNumericType(); - // check value of p - CPPAD_ASSERT_KNOWN( - p == 0 || p == 1, - "sparse_jac_fun: p != 0 and p != 1" - ); - size_t K = row.size(); - CPPAD_ASSERT_KNOWN( - K >= m, - "sparse_jac_fun: row.size() < m" - ); - size_t i, j, k; - - if( p == 0 ) - for(i = 0; i < m; i++) - fp[i] = Float(0); - - Float t; - for(k = 0; k < K; k++) - { i = row[k]; - j = col[k]; - t = exp( x[j] * x[j] / 2.0 ); - switch(p) - { - case 0: - fp[i] += t; - break; - - case 1: - fp[k] = t * x[j]; - break; - } - } - } -} -// END C++ -# endif diff --git a/external/cppad/include/cppad/speed/uniform_01.hpp b/external/cppad/include/cppad/speed/uniform_01.hpp deleted file mode 100644 index 76dd954ca..000000000 --- a/external/cppad/include/cppad/speed/uniform_01.hpp +++ /dev/null @@ -1,104 +0,0 @@ -# ifndef CPPAD_SPEED_UNIFORM_01_HPP -# define CPPAD_SPEED_UNIFORM_01_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin uniform_01$$ -$spell - CppAD - namespace - cppad - hpp -$$ - -$section Simulate a [0,1] Uniform Random Variate$$ -$mindex uniform_01$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%uniform_01(%seed%) -%$$ -$codei%uniform_01(%n%, %x%)%$$ - -$head Purpose$$ -This routine is used to create random values for speed testing purposes. - -$head Inclusion$$ -The template function $code uniform_01$$ is defined in the $code CppAD$$ -namespace by including -the file $code cppad/speed/uniform_01.hpp$$ -(relative to the CppAD distribution directory). - -$head seed$$ -The argument $icode seed$$ has prototype -$codei% - size_t %seed% -%$$ -It specifies a seed -for the uniform random number generator. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -It specifies the number of elements in the random vector $icode x$$. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - %Vector% &%x% -%$$. -The input value of the elements of $icode x$$ does not matter. -Upon return, the elements of $icode x$$ are set to values -randomly sampled over the interval [0,1]. - -$head Vector$$ -If $icode y$$ is a $code double$$ value, -the object $icode x$$ must support the syntax -$codei% - %x%[%i%] = %y% -%$$ -where $icode i$$ has type $code size_t$$ with value less than -or equal $latex n-1$$. -This is the only requirement of the type $icode Vector$$. - -$children% - omh/uniform_01_hpp.omh -%$$ - -$head Source Code$$ -The file -$cref uniform_01.hpp$$ -constraints the source code for this template function. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include - -namespace CppAD { - inline void uniform_01(size_t seed) - { std::srand( (unsigned int) seed); } - - template - void uniform_01(size_t n, Vector &x) - { static double factor = 1. / double(RAND_MAX); - while(n--) - x[n] = std::rand() * factor; - } -} -// END C++ -# endif diff --git a/external/cppad/include/cppad/utility.hpp b/external/cppad/include/cppad/utility.hpp deleted file mode 100644 index ebf224dc6..000000000 --- a/external/cppad/include/cppad/utility.hpp +++ /dev/null @@ -1,44 +0,0 @@ -# ifndef CPPAD_UTILITY_HPP -# define CPPAD_UTILITY_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# endif diff --git a/external/cppad/include/cppad/utility/check_numeric_type.hpp b/external/cppad/include/cppad/utility/check_numeric_type.hpp deleted file mode 100644 index 8e2b2b2fd..000000000 --- a/external/cppad/include/cppad/utility/check_numeric_type.hpp +++ /dev/null @@ -1,175 +0,0 @@ -# ifndef CPPAD_UTILITY_CHECK_NUMERIC_TYPE_HPP -# define CPPAD_UTILITY_CHECK_NUMERIC_TYPE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin CheckNumericType$$ -$spell - alloc - cppad.hpp - CppAD -$$ - -$section Check NumericType Class Concept$$ -$mindex numeric CheckNumericType$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%CheckNumericType<%NumericType%>()%$$ - - -$head Purpose$$ -The syntax -$codei% - CheckNumericType<%NumericType%>() -%$$ -preforms compile and run time checks that the type specified -by $icode NumericType$$ satisfies all the requirements for -a $cref NumericType$$ class. -If a requirement is not satisfied, -a an error message makes it clear what condition is not satisfied. - -$head Include$$ -The file $code cppad/check_numeric_type.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest -if the CppAD include files. - -$head Parallel Mode$$ -The routine $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$ -must be called before it -can be used in $cref/parallel/ta_in_parallel/$$ mode. - -$head Example$$ -$children% - example/utility/check_numeric_type.cpp -%$$ -The file $cref check_numeric_type.cpp$$ -contains an example and test of this function. -It returns true, if it succeeds an false otherwise. -The comments in this example suggest a way to change the example -so an error message occurs. - -$end ---------------------------------------------------------------------------- -*/ - -# include -# include - -namespace CppAD { - -# ifdef NDEBUG - template - void CheckNumericType(void) - { } -# else - template - NumericType CheckNumericType(void) - { // Section 3.6.2 of ISO/IEC 14882:1998(E) states: "The storage for - // objects with static storage duration (3.7.1) shall be zero- - // initialized (8.5) before any other initialization takes place." - static size_t count[CPPAD_MAX_NUM_THREADS]; - size_t thread = thread_alloc::thread_num(); - if( count[thread] > 0 ) - return NumericType(0); - count[thread]++; - /* - contructors - */ - NumericType check_NumericType_default_constructor; - NumericType check_NumericType_constructor_from_int(1); - - const NumericType x(1); - - NumericType check_NumericType_copy_constructor(x); - - // assignment - NumericType check_NumericType_assignment; - check_NumericType_assignment = x; - - /* - unary operators - */ - const NumericType check_NumericType_unary_plus(1); - NumericType check_NumericType_unary_plus_result = - + check_NumericType_unary_plus; - - const NumericType check_NumericType_unary_minus(1); - NumericType check_NumericType_unary_minus_result = - - check_NumericType_unary_minus; - - /* - binary operators - */ - const NumericType check_NumericType_binary_addition(1); - NumericType check_NumericType_binary_addition_result = - check_NumericType_binary_addition + x; - - const NumericType check_NumericType_binary_subtraction(1); - NumericType check_NumericType_binary_subtraction_result = - check_NumericType_binary_subtraction - x; - - const NumericType check_NumericType_binary_multiplication(1); - NumericType check_NumericType_binary_multiplication_result = - check_NumericType_binary_multiplication * x; - - const NumericType check_NumericType_binary_division(1); - NumericType check_NumericType_binary_division_result = - check_NumericType_binary_division / x; - - /* - compound assignment operators - */ - NumericType - check_NumericType_computed_assignment_addition(1); - check_NumericType_computed_assignment_addition += x; - - NumericType - check_NumericType_computed_assignment_subtraction(1); - check_NumericType_computed_assignment_subtraction -= x; - - NumericType - check_NumericType_computed_assignment_multiplication(1); - check_NumericType_computed_assignment_multiplication *= x; - - NumericType - check_NumericType_computed_assignment_division(1); - check_NumericType_computed_assignment_division /= x; - - /* - use all values so as to avoid warnings - */ - check_NumericType_default_constructor = x; - return - + check_NumericType_default_constructor - + check_NumericType_constructor_from_int - + check_NumericType_copy_constructor - + check_NumericType_assignment - + check_NumericType_unary_plus_result - + check_NumericType_unary_minus_result - + check_NumericType_binary_addition_result - + check_NumericType_binary_subtraction_result - + check_NumericType_binary_multiplication_result - + check_NumericType_binary_division_result - + check_NumericType_computed_assignment_addition - + check_NumericType_computed_assignment_subtraction - + check_NumericType_computed_assignment_multiplication - + check_NumericType_computed_assignment_division - ; - } -# endif - -} // end namespace CppAD - -# endif diff --git a/external/cppad/include/cppad/utility/check_simple_vector.hpp b/external/cppad/include/cppad/utility/check_simple_vector.hpp deleted file mode 100644 index 4732d1448..000000000 --- a/external/cppad/include/cppad/utility/check_simple_vector.hpp +++ /dev/null @@ -1,200 +0,0 @@ -# ifndef CPPAD_UTILITY_CHECK_SIMPLE_VECTOR_HPP -# define CPPAD_UTILITY_CHECK_SIMPLE_VECTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin CheckSimpleVector$$ -$spell - alloc - const - cppad.hpp - CppAD -$$ - -$section Check Simple Vector Concept$$ -$mindex CheckSimpleVector$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%CheckSimpleVector<%Scalar%, %Vector%>()%$$ -$pre -$$ -$codei%CheckSimpleVector<%Scalar%, %Vector%>(%x%, %y%)%$$ - - -$head Purpose$$ -Preforms compile and run time checks that the type specified -by $icode Vector$$ satisfies all the requirements for -a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Scalar$$. -If a requirement is not satisfied, -a an error message makes it clear what condition is not satisfied. - -$head x, y$$ -If the arguments $icode x$$ and $icode y$$ are present, -they have prototype -$codei% - const %Scalar%& %x% - const %Scalar%& %y% -%$$ -In addition, the check -$codei% - %x% == %x% -%$$ -will return the boolean value $code true$$, and -$codei% - %x% == %y% -%$$ -will return $code false$$. - -$head Restrictions$$ -If the arguments $icode x$$ and $icode y$$ are not present, -the following extra assumption is made by $code CheckSimpleVector$$: -If $icode x$$ is a $icode Scalar$$ object -$codei% - %x% = 0 - %y% = 1 -%$$ -assigns values to the objects $icode x$$ and $icode y$$. -In addition, -$icode%x% == %x%$$ would return the boolean value $code true$$ and -$icode%x% == %y%$$ would return $code false$$. - -$head Include$$ -The file $code cppad/check_simple_vector.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest -if the CppAD include files. - -$head Parallel Mode$$ -The routine $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$ -must be called before it -can be used in $cref/parallel/ta_in_parallel/$$ mode. - -$head Example$$ -$children% - example/utility/check_simple_vector.cpp -%$$ -The file $cref check_simple_vector.cpp$$ -contains an example and test of this function where $icode S$$ -is the same as $icode T$$. -It returns true, if it succeeds an false otherwise. -The comments in this example suggest a way to change the example -so $icode S$$ is not the same as $icode T$$. - -$end ---------------------------------------------------------------------------- -*/ - -# include -# include -# include -# include - -namespace CppAD { - -# ifdef NDEBUG - template - inline void CheckSimpleVector(const Scalar& x, const Scalar& y) - { } - template - inline void CheckSimpleVector(void) - { } -# else - template - struct ok_if_S_same_as_T { }; - - template - struct ok_if_S_same_as_T { T value; }; - - template - void CheckSimpleVector(const Scalar& x, const Scalar& y) - { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL - static size_t count; - if( count > 0 ) - return; - count++; - - // value_type must be type of elements of Vector - typedef typename Vector::value_type value_type; - - // check that elements of Vector have type Scalar - struct ok_if_S_same_as_T x_copy; - x_copy.value = x; - - // check default constructor - Vector d; - - // size member function - CPPAD_ASSERT_KNOWN( - d.size() == 0, - "default construtor result does not have size zero" - ); - - // resize to same size as other vectors in test - d.resize(1); - - // check sizing constructor - Vector s(1); - - // check element assignment - s[0] = y; - CPPAD_ASSERT_KNOWN( - s[0] == y, - "element assignment failed" - ); - - // check copy constructor - s[0] = x_copy.value; - const Vector c(s); - s[0] = y; - CPPAD_ASSERT_KNOWN( - c[0] == x, - "copy constructor is shallow" - ); - - // vector assignment operator - d[0] = x; - s = d; - s[0] = y; - CPPAD_ASSERT_KNOWN( - d[0] == x, - "assignment operator is shallow" - ); - - // element access, right side const - // element assignment, left side not const - d[0] = c[0]; - CPPAD_ASSERT_KNOWN( - d[0] == x, - "element assignment from const failed" - ); - } - template - void CheckSimpleVector(void) - { Scalar x; - Scalar y; - - // use assignment and not constructor - x = 0; - y = 1; - - CheckSimpleVector(x, y); - } - -# endif - -} // end namespace CppAD - -# endif diff --git a/external/cppad/include/cppad/utility/elapsed_seconds.hpp b/external/cppad/include/cppad/utility/elapsed_seconds.hpp deleted file mode 100644 index 882c0882e..000000000 --- a/external/cppad/include/cppad/utility/elapsed_seconds.hpp +++ /dev/null @@ -1,175 +0,0 @@ -// $Id: elapsed_seconds.hpp 3845 2016-11-19 01:50:47Z bradbell $ -# ifndef CPPAD_UTILITY_ELAPSED_SECONDS_HPP -# define CPPAD_UTILITY_ELAPSED_SECONDS_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin elapsed_seconds$$ -$spell - cppad.hpp - Microsoft - gettimeofday - std - chrono -$$ - -$section Returns Elapsed Number of Seconds$$ -$mindex elapsed_seconds time$$ - - -$head Syntax$$ -$codei%# include -%$$ -$icode%s% = elapsed_seconds()%$$ - -$head Purpose$$ -This routine is accurate to within .02 seconds -(see $cref elapsed_seconds.cpp$$). -It does not necessary work for time intervals that are greater than a day. -$list number$$ -If the C++11 $code std::chrono::steady_clock$$ is available, -it will be used for timing. -$lnext -Otherwise, if running under the Microsoft compiler, -$code ::GetSystemTime$$ will be used for timing. -$lnext -Otherwise, if $code gettimeofday$$ is available, it is used for timing. -$lnext -Otherwise, $code std::clock()$$ will be used for timing. -$lend - -$head s$$ -is a $code double$$ equal to the -number of seconds since the first call to $code elapsed_seconds$$. - -$head Microsoft Systems$$ -It you are using $code ::GetSystemTime$$, -you will need to link in the external routine -called $cref microsoft_timer$$. - -$children% - speed/example/elapsed_seconds.cpp -%$$ -$head Example$$ -The routine $cref elapsed_seconds.cpp$$ is -an example and test of this routine. - - -$end ------------------------------------------------------------------------ -*/ - -// For some unknown reason under Fedora (which needs to be understood), -// if you move this include for cppad_assert.hpp below include for define.hpp, -// cd work/speed/example -// make test.sh -// fails with the error message 'gettimeofday' not defined. -# include - -// define CPPAD_NULL -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -# if CPPAD_USE_CPLUSPLUS_2011 -# include -# elif _MSC_VER -extern double microsoft_timer(void); -# elif CPPAD_HAS_GETTIMEOFDAY -# include -# else -# include -# endif - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file elapsed_seconds.hpp -\brief Function that returns the elapsed seconds from first call. -*/ - -/*! -Returns the elapsed number since the first call to this function. - -This routine tries is accurate to within .02 seconds. -It does not necessary work for time intervals that are less than a day. -\li -If running under the Microsoft system, it uses \c ::%GetSystemTime for timing. -\li -Otherwise, if \c gettimeofday is available, it is used. -\li -Otherwise, \c std::clock() is used. - -\return -The number of seconds since the first call to \c elapsed_seconds. -*/ -inline double elapsed_seconds(void) -// -------------------------------------------------------------------------- -# if CPPAD_USE_CPLUSPLUS_2011 -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static bool first_ = true; - static std::chrono::time_point start_; - if( first_ ) - { start_ = std::chrono::steady_clock::now(); - first_ = false; - return 0.0; - } - std::chrono::time_point now; - now = std::chrono::steady_clock::now(); - std::chrono::duration difference = now - start_; - return difference.count(); -} -// -------------------------------------------------------------------------- -# elif _MSC_VER -{ return microsoft_timer(); } -// -------------------------------------------------------------------------- -# elif CPPAD_HAS_GETTIMEOFDAY -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static bool first_ = true; - static struct timeval tv_; - struct timeval tv; - if( first_ ) - { gettimeofday(&tv_, CPPAD_NULL); - first_ = false; - return 0.; - } - gettimeofday(&tv, CPPAD_NULL); - assert( tv.tv_sec >= tv_.tv_sec ); - - double sec = double(tv.tv_sec - tv_.tv_sec); - double usec = double(tv.tv_usec) - double(tv_.tv_usec); - double diff = sec + 1e-6*usec; - - return diff; -} -// -------------------------------------------------------------------------- -# else // Not CPPAD_USE_CPLUSPLUS_2011 or CPPAD_HAS_GETTIMEOFDAY -{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static bool first_ = true; - static double tic_; - double tic; - if( first_ ) - { tic_ = double(std::clock()); - first_ = false; - return 0.; - } - tic = double( std::clock() ); - - double diff = (tic - tic_) / double(CLOCKS_PER_SEC); - - return diff; -} -# endif -// -------------------------------------------------------------------------- -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/utility/error_handler.hpp b/external/cppad/include/cppad/utility/error_handler.hpp deleted file mode 100644 index 0d1a9d7fd..000000000 --- a/external/cppad/include/cppad/utility/error_handler.hpp +++ /dev/null @@ -1,235 +0,0 @@ -# ifndef CPPAD_UTILITY_ERROR_HANDLER_HPP -# define CPPAD_UTILITY_ERROR_HANDLER_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin ErrorHandler$$ -$spell - cppad.hpp - CppAD - exp - bool - const -$$ - -$section Replacing the CppAD Error Handler$$ -$mindex replace assert exception ErrorHandler$$ - -$head Syntax$$ -$codei%# include -%$$ -$codei%ErrorHandler %info%(%handler%) -%$$ -$codei%ErrorHandler::Call(%known%, %line%, %file%, %exp%, %msg%) -%$$ - -$head Constructor$$ -When you construct a $code ErrorHandler$$ object, -the current CppAD error handler is replaced by $icode handler$$. -When the object is destructed, the previous CppAD error handler is restored. - -$subhead Parallel Mode$$ -The $code ErrorHandler$$ constructor and destructor cannot be called in -$cref/parallel/ta_in_parallel/$$ execution mode. -Furthermore, this rule is not abided by, a raw C++ $code assert$$, -instead of one that uses this error handler, will be generated. - -$head Call$$ -When $code ErrorHandler::Call$$ is called, -the current CppAD error handler is used to report an error. -This starts out as a default error handler and can be replaced -using the $code ErrorHandler$$ constructor. - -$head info$$ -The object $icode info$$ is used to store information -that is necessary to restore the previous CppAD error handler. -This is done when the destructor for $icode info$$ is called. - - -$head handler$$ -The argument $icode handler$$ has prototype -$codei% - void (*%handler%) - (bool, int, const char *, const char *, const char *); -%$$ -When an error is detected, -it is called with the syntax -$codei% - %handler% (%known%, %line%, %file%, %exp%, %msg%) -%$$ -This routine should not return; i.e., upon detection of the error, -the routine calling $icode handler$$ does not know how to proceed. - -$head known$$ -The $icode handler$$ argument $icode known$$ has prototype -$codei% - bool %known% -%$$ -If it is true, the error being reported is from a know problem. - -$head line$$ -The $icode handler$$ argument $icode line$$ has prototype -$codei% - int %line% -%$$ -It reports the source code line number where the error is detected. - -$head file$$ -The $icode handler$$ argument $icode file$$ has prototype -$codei% - const char *%file% -%$$ -and is a $code '\0'$$ terminated character vector. -It reports the source code file where the error is detected. - -$head exp$$ -The $icode handler$$ argument $icode exp$$ has prototype -$codei% - const char *%exp% -%$$ -and is a $code '\0'$$ terminated character vector. -It is a source code boolean expression that should have been true, -but is false, -and thereby causes this call to $icode handler$$. - -$head msg$$ -The $icode handler$$ argument $icode msg$$ has prototype -$codei% - const char *%msg% -%$$ -and is a $code '\0'$$ terminated character vector. -It reports the meaning of the error from the C++ programmers point of view. - -$children% - example/utility/error_handler.cpp% - cppad/core/cppad_assert.hpp -%$$ -$head Example$$ -The file -$cref error_handler.cpp$$ -contains an example and test a test of using this routine. -It returns true if it succeeds and false otherwise. - -$end ---------------------------------------------------------------------------- -*/ - -# include - -# include -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -class ErrorHandler { - template - friend void parallel_ad(void); -public: - typedef void (*Handler) - (bool, int, const char *, const char *, const char *); - - // construct a new handler - ErrorHandler(Handler handler) : previous( Current() ) - { if( local::set_get_in_parallel(0) ) - { bool known = true; - int line = __LINE__; - const char* file = __FILE__; - const char* exp = "! local::set_get_in_parallel(0)"; - const char* msg = - "Using ErrorHandler constructor in parallel mode."; - Call(known, line, file, exp, msg); - } - Current() = handler; - } - - // destructor for an error handler - ~ErrorHandler(void) - { if( local::set_get_in_parallel(0) ) - { bool known = true; - int line = __LINE__; - const char* file = __FILE__; - const char* exp = "! local::set_get_in_parallel(0)"; - const char* msg = - "Using ErrorHandler destructor in parallel mode."; - Call(known, line, file, exp, msg); - } - Current() = previous; - } - - // report an error - static void Call( - bool known, - int line , - const char *file , - const char *exp , - const char *msg ) - { Handler handler = Current(); - handler(known, line, file, exp, msg); - } - -private: - const Handler previous; - - // The default error handler - static void Default( - bool known, - int line , - const char *file , - const char *exp , - const char *msg ) - { using std::cerr; - using std::endl; - - cerr << CPPAD_PACKAGE_STRING; - if( known ) - cerr << " error from a known source:" << endl; - else cerr << " error from unknown source" << endl; - if( msg[0] != '\0' ) - cerr << msg << endl; - cerr << "Error detected by false result for" << endl; - cerr << " " << exp << endl; - cerr << "at line " << line << " in the file " << endl; - cerr << " " << file << endl; - - // terminate program execution - assert(false); - - // termination when NDEBUG is defined - std::exit(1); - } - - // current error handler - static Handler &Current(void) - { static bool first_call = true; - static Handler current = Default; - if( first_call ) - { if( local::set_get_in_parallel(0) ) - { bool known = false; - int line = __LINE__; - const char* file = __FILE__; - const char* exp = ""; - const char* msg = ""; - Call(known, line, file, exp, msg); - } - first_call = false; - } - return current; - } -}; - -} // END CppAD namespace - - - -# endif diff --git a/external/cppad/include/cppad/utility/index_sort.hpp b/external/cppad/include/cppad/utility/index_sort.hpp deleted file mode 100644 index d40c56127..000000000 --- a/external/cppad/include/cppad/utility/index_sort.hpp +++ /dev/null @@ -1,178 +0,0 @@ -# ifndef CPPAD_UTILITY_INDEX_SORT_HPP -# define CPPAD_UTILITY_INDEX_SORT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin index_sort$$ -$spell - cppad.hpp - ind - const -$$ - -$section Returns Indices that Sort a Vector$$ -$mindex index_sort$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%index_sort(%keys%, %ind%)%$$ - -$head keys$$ -The argument $icode keys$$ has prototype -$codei% - const %VectorKey%& %keys% -%$$ -where $icode VectorKey$$ is -a $cref SimpleVector$$ class with elements that support the $code <$$ -operation. - -$head ind$$ -The argument $icode ind$$ has prototype -$codei% - %VectorSize%& %ind% -%$$ -where $icode VectorSize$$ is -a $cref SimpleVector$$ class with elements of type $code size_t$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$subhead Input$$ -The size of $icode ind$$ must be the same as the size of $icode keys$$ -and the value of its input elements does not matter. - -$subhead Return$$ -Upon return, $icode ind$$ is a permutation of the set of indices -that yields increasing order for $icode keys$$. -In other words, for all $icode%i% != %j%$$, -$codei% - %ind%[%i%] != %ind%[%j%] -%$$ -and for $icode%i% = 0 , %...% , %size%-2%$$, -$codei% - ( %keys%[ %ind%[%i%+1] ] < %keys%[ %ind%[%i%] ] ) == false -%$$ - - -$head Example$$ -$children% - example/utility/index_sort.cpp -%$$ -The file $cref index_sort.cpp$$ contains an example -and test of this routine. -It return true if it succeeds and false otherwise. - -$end -*/ -# include -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file index_sort.hpp -File used to implement the CppAD index sort utility -*/ - -/*! -Helper class used by index_sort -*/ -template -class index_sort_element { -private: - /// key used to determine position of this element - Compare key_; - /// index vlaue corresponding to this key - size_t index_; -public: - /// operator requried by std::sort - bool operator<(const index_sort_element& other) const - { return key_ < other.key_; } - /// set the key for this element - void set_key(const Compare& value) - { key_ = value; } - /// set the index for this element - void set_index(const size_t& index) - { index_ = index; } - /// get the key for this element - Compare get_key(void) const - { return key_; } - /// get the index for this element - size_t get_index(void) const - { return index_; } -}; - -/*! -Compute the indices that sort a vector of keys - -\tparam VectorKey -Simple vector type that deterimene the sorting order by \c < operator -on its elements. - -\tparam VectorSize -Simple vector type with elements of \c size_t -that is used to return index values. - -\param keys [in] -values that determine the sorting order. - -\param ind [out] -must have the same size as \c keys. -The input value of its elements does not matter. -The output value of its elements satisfy -\code -( keys[ ind[i] ] < keys[ ind[i+1] ] ) == false -\endcode -*/ -template -void index_sort(const VectorKey& keys, VectorSize& ind) -{ typedef typename VectorKey::value_type Compare; - CheckSimpleVector(); - - typedef index_sort_element element; - - CPPAD_ASSERT_KNOWN( - size_t(keys.size()) == size_t(ind.size()), - "index_sort: vector sizes do not match" - ); - - size_t size_work = size_t(keys.size()); - size_t size_out; - element* work = - thread_alloc::create_array(size_work, size_out); - - // copy initial order into work - size_t i; - for(i = 0; i < size_work; i++) - { work[i].set_key( keys[i] ); - work[i].set_index( i ); - } - - // sort the work array - std::sort(work, work+size_work); - - // copy the indices to the output vector - for(i = 0; i < size_work; i++) - ind[i] = work[i].get_index(); - - // we are done with this work array - thread_alloc::delete_array(work); - - return; -} - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/utility/lu_factor.hpp b/external/cppad/include/cppad/utility/lu_factor.hpp deleted file mode 100644 index a4704023b..000000000 --- a/external/cppad/include/cppad/utility/lu_factor.hpp +++ /dev/null @@ -1,393 +0,0 @@ -# ifndef CPPAD_UTILITY_LU_FACTOR_HPP -# define CPPAD_UTILITY_LU_FACTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin LuFactor$$ -$escape #$$ -$spell - cppad.hpp - Cpp - Geq - Lu - bool - const - ip - jp - namespace - std - typename -$$ - - -$section LU Factorization of A Square Matrix$$ -$mindex LuFactor linear equation solve$$ - -$pre -$$ - -$head Syntax$$ $codei%# include -%$$ -$icode%sign% = LuFactor(%ip%, %jp%, %LU%)%$$ - - -$head Description$$ -Computes an LU factorization of the matrix $icode A$$ -where $icode A$$ is a square matrix. - -$head Include$$ -The file $code cppad/lu_factor.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Matrix Storage$$ -All matrices are stored in row major order. -To be specific, if $latex Y$$ is a vector -that contains a $latex p$$ by $latex q$$ matrix, -the size of $latex Y$$ must be equal to $latex p * q $$ and for -$latex i = 0 , \ldots , p-1$$, -$latex j = 0 , \ldots , q-1$$, -$latex \[ - Y_{i,j} = Y[ i * q + j ] -\] $$ - -$head sign$$ -The return value $icode sign$$ has prototype -$codei% - int %sign% -%$$ -If $icode A$$ is invertible, $icode sign$$ is plus or minus one -and is the sign of the permutation corresponding to the row ordering -$icode ip$$ and column ordering $icode jp$$. -If $icode A$$ is not invertible, $icode sign$$ is zero. - -$head ip$$ -The argument $icode ip$$ has prototype -$codei% - %SizeVector% &%ip% -%$$ -(see description of $cref/SizeVector/LuFactor/SizeVector/$$ below). -The size of $icode ip$$ is referred to as $icode n$$ in the -specifications below. -The input value of the elements of $icode ip$$ does not matter. -The output value of the elements of $icode ip$$ determine -the order of the rows in the permuted matrix. - -$head jp$$ -The argument $icode jp$$ has prototype -$codei% - %SizeVector% &%jp% -%$$ -(see description of $cref/SizeVector/LuFactor/SizeVector/$$ below). -The size of $icode jp$$ must be equal to $icode n$$. -The input value of the elements of $icode jp$$ does not matter. -The output value of the elements of $icode jp$$ determine -the order of the columns in the permuted matrix. - -$head LU$$ -The argument $icode LU$$ has the prototype -$codei% - %FloatVector% &%LU% -%$$ -and the size of $icode LU$$ must equal $latex n * n$$ -(see description of $cref/FloatVector/LuFactor/FloatVector/$$ below). - -$subhead A$$ -We define $icode A$$ as the matrix corresponding to the input -value of $icode LU$$. - -$subhead P$$ -We define the permuted matrix $icode P$$ in terms of $icode A$$ by -$codei% - %P%(%i%, %j%) = %A%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ - -$subhead L$$ -We define the lower triangular matrix $icode L$$ in terms of the -output value of $icode LU$$. -The matrix $icode L$$ is zero above the diagonal -and the rest of the elements are defined by -$codei% - %L%(%i%, %j%) = %LU%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -for $latex i = 0 , \ldots , n-1$$ and $latex j = 0 , \ldots , i$$. - -$subhead U$$ -We define the upper triangular matrix $icode U$$ in terms of the -output value of $icode LU$$. -The matrix $icode U$$ is zero below the diagonal, -one on the diagonal, -and the rest of the elements are defined by -$codei% - %U%(%i%, %j%) = %LU%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -for $latex i = 0 , \ldots , n-2$$ and $latex j = i+1 , \ldots , n-1$$. - -$subhead Factor$$ -If the return value $icode sign$$ is non-zero, -$codei% - %L% * %U% = %P% -%$$ -If the return value of $icode sign$$ is zero, -the contents of $icode L$$ and $icode U$$ are not defined. - -$subhead Determinant$$ -If the return value $icode sign$$ is zero, -the determinant of $icode A$$ is zero. -If $icode sign$$ is non-zero, -using the output value of $icode LU$$ -the determinant of the matrix $icode A$$ is equal to -$codei% -%sign% * %LU%[%ip%[0], %jp%[0]] * %...% * %LU%[%ip%[%n%-1], %jp%[%n%-1]] -%$$ - -$head SizeVector$$ -The type $icode SizeVector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type size_t/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head FloatVector$$ -The type $icode FloatVector$$ must be a -$cref/simple vector class/SimpleVector/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Float$$ -This notation is used to denote the type corresponding -to the elements of a $icode FloatVector$$. -The type $icode Float$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, the following operations must be defined for any pair -of $icode Float$$ objects $icode x$$ and $icode y$$: - -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$codei%log(%x%)%$$ $cnext - returns the logarithm of $icode x$$ as a $icode Float$$ object -$tend - -$head AbsGeq$$ -Including the file $code lu_factor.hpp$$ defines the template function -$codei% - template - bool AbsGeq<%Float%>(const %Float% &%x%, const %Float% &%y%) -%$$ -in the $code CppAD$$ namespace. -This function returns true if the absolute value of -$icode x$$ is greater than or equal the absolute value of $icode y$$. -It is used by $code LuFactor$$ to choose the pivot elements. -This template function definition uses the operator -$code <=$$ to obtain the absolute value for $icode Float$$ objects. -If this operator is not defined for your use of $icode Float$$, -you will need to specialize this template so that it works for your -use of $code LuFactor$$. -$pre - -$$ -Complex numbers do not have the operation $code <=$$ defined. -The specializations -$codei% -bool AbsGeq< std::complex > - (const std::complex &%x%, const std::complex &%y%) -bool AbsGeq< std::complex > - (const std::complex &%x%, const std::complex &%y%) -%$$ -are define by including $code lu_factor.hpp$$ -These return true if the sum of the square of the real and imaginary parts -of $icode x$$ is greater than or equal the -sum of the square of the real and imaginary parts of $icode y$$. - -$children% - example/utility/lu_factor.cpp% - omh/lu_factor_hpp.omh -%$$ -$head Example$$ -The file -$cref lu_factor.cpp$$ -contains an example and test of using $code LuFactor$$ by itself. -It returns true if it succeeds and false otherwise. -$pre - -$$ -The file $cref lu_solve.hpp$$ provides a useful example usage of -$code LuFactor$$ with $code LuInvert$$. - -$head Source$$ -The file $cref lu_factor.hpp$$ contains the -current source code that implements these specifications. - -$end --------------------------------------------------------------------------- -*/ -// BEGIN C++ - -# include -# include - -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -// AbsGeq -template -inline bool AbsGeq(const Float &x, const Float &y) -{ Float xabs = x; - if( xabs <= Float(0) ) - xabs = - xabs; - Float yabs = y; - if( yabs <= Float(0) ) - yabs = - yabs; - return xabs >= yabs; -} -inline bool AbsGeq( - const std::complex &x, - const std::complex &y) -{ double xsq = x.real() * x.real() + x.imag() * x.imag(); - double ysq = y.real() * y.real() + y.imag() * y.imag(); - - return xsq >= ysq; -} -inline bool AbsGeq( - const std::complex &x, - const std::complex &y) -{ float xsq = x.real() * x.real() + x.imag() * x.imag(); - float ysq = y.real() * y.real() + y.imag() * y.imag(); - - return xsq >= ysq; -} - -// Lines that are different from code in cppad/core/lu_ratio.hpp end with // -template // -int LuFactor(SizeVector &ip, SizeVector &jp, FloatVector &LU) // -{ - // type of the elements of LU // - typedef typename FloatVector::value_type Float; // - - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - CheckSimpleVector(); - - size_t i, j; // some temporary indices - const Float zero( 0 ); // the value zero as a Float object - size_t imax; // row index of maximum element - size_t jmax; // column indx of maximum element - Float emax; // maximum absolute value - size_t p; // count pivots - int sign; // sign of the permutation - Float etmp; // temporary element - Float pivot; // pivot element - - // ------------------------------------------------------- - size_t n = ip.size(); - CPPAD_ASSERT_KNOWN( - size_t(jp.size()) == n, - "Error in LuFactor: jp must have size equal to n" - ); - CPPAD_ASSERT_KNOWN( - size_t(LU.size()) == n * n, - "Error in LuFactor: LU must have size equal to n * m" - ); - // ------------------------------------------------------- - - // initialize row and column order in matrix not yet pivoted - for(i = 0; i < n; i++) - { ip[i] = i; - jp[i] = i; - } - // initialize the sign of the permutation - sign = 1; - // --------------------------------------------------------- - - // Reduce the matrix P to L * U using n pivots - for(p = 0; p < n; p++) - { // determine row and column corresponding to element of - // maximum absolute value in remaining part of P - imax = jmax = n; - emax = zero; - for(i = p; i < n; i++) - { for(j = p; j < n; j++) - { CPPAD_ASSERT_UNKNOWN( - (ip[i] < n) & (jp[j] < n) - ); - etmp = LU[ ip[i] * n + jp[j] ]; - - // check if maximum absolute value so far - if( AbsGeq (etmp, emax) ) - { imax = i; - jmax = j; - emax = etmp; - } - } - } - CPPAD_ASSERT_KNOWN( - (imax < n) & (jmax < n) , - "LuFactor can't determine an element with " - "maximum absolute value.\n" - "Perhaps original matrix contains not a number or infinity.\n" - "Perhaps your specialization of AbsGeq is not correct." - ); - if( imax != p ) - { // switch rows so max absolute element is in row p - i = ip[p]; - ip[p] = ip[imax]; - ip[imax] = i; - sign = -sign; - } - if( jmax != p ) - { // switch columns so max absolute element is in column p - j = jp[p]; - jp[p] = jp[jmax]; - jp[jmax] = j; - sign = -sign; - } - // pivot using the max absolute element - pivot = LU[ ip[p] * n + jp[p] ]; - - // check for determinant equal to zero - if( pivot == zero ) - { // abort the mission - return 0; - } - - // Reduce U by the elementary transformations that maps - // LU( ip[p], jp[p] ) to one. Only need transform elements - // above the diagonal in U and LU( ip[p] , jp[p] ) is - // corresponding value below diagonal in L. - for(j = p+1; j < n; j++) - LU[ ip[p] * n + jp[j] ] /= pivot; - - // Reduce U by the elementary transformations that maps - // LU( ip[i], jp[p] ) to zero. Only need transform elements - // above the diagonal in U and LU( ip[i], jp[p] ) is - // corresponding value below diagonal in L. - for(i = p+1; i < n; i++ ) - { etmp = LU[ ip[i] * n + jp[p] ]; - for(j = p+1; j < n; j++) - { LU[ ip[i] * n + jp[j] ] -= - etmp * LU[ ip[p] * n + jp[j] ]; - } - } - } - return sign; -} -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/utility/lu_invert.hpp b/external/cppad/include/cppad/utility/lu_invert.hpp deleted file mode 100644 index fd3f23de9..000000000 --- a/external/cppad/include/cppad/utility/lu_invert.hpp +++ /dev/null @@ -1,239 +0,0 @@ -# ifndef CPPAD_UTILITY_LU_INVERT_HPP -# define CPPAD_UTILITY_LU_INVERT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin LuInvert$$ -$escape #$$ -$spell - cppad.hpp - Lu - Cpp - jp - ip - const - namespace - typename - etmp -$$ - - -$section Invert an LU Factored Equation$$ -$mindex LuInvert linear$$ - -$pre -$$ - -$head Syntax$$ $codei%# include -%$$ -$codei%LuInvert(%ip%, %jp%, %LU%, %X%)%$$ - - -$head Description$$ -Solves the matrix equation $icode%A% * %X% = %B%$$ -using an LU factorization computed by $cref LuFactor$$. - -$head Include$$ -The file $code cppad/lu_invert.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Matrix Storage$$ -All matrices are stored in row major order. -To be specific, if $latex Y$$ is a vector -that contains a $latex p$$ by $latex q$$ matrix, -the size of $latex Y$$ must be equal to $latex p * q $$ and for -$latex i = 0 , \ldots , p-1$$, -$latex j = 0 , \ldots , q-1$$, -$latex \[ - Y_{i,j} = Y[ i * q + j ] -\] $$ - -$head ip$$ -The argument $icode ip$$ has prototype -$codei% - const %SizeVector% &%ip% -%$$ -(see description for $icode SizeVector$$ in -$cref/LuFactor/LuFactor/SizeVector/$$ specifications). -The size of $icode ip$$ is referred to as $icode n$$ in the -specifications below. -The elements of $icode ip$$ determine -the order of the rows in the permuted matrix. - -$head jp$$ -The argument $icode jp$$ has prototype -$codei% - const %SizeVector% &%jp% -%$$ -(see description for $icode SizeVector$$ in -$cref/LuFactor/LuFactor/SizeVector/$$ specifications). -The size of $icode jp$$ must be equal to $icode n$$. -The elements of $icode jp$$ determine -the order of the columns in the permuted matrix. - -$head LU$$ -The argument $icode LU$$ has the prototype -$codei% - const %FloatVector% &%LU% -%$$ -and the size of $icode LU$$ must equal $latex n * n$$ -(see description for $icode FloatVector$$ in -$cref/LuFactor/LuFactor/FloatVector/$$ specifications). - -$subhead L$$ -We define the lower triangular matrix $icode L$$ in terms of $icode LU$$. -The matrix $icode L$$ is zero above the diagonal -and the rest of the elements are defined by -$codei% - %L%(%i%, %j%) = %LU%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -for $latex i = 0 , \ldots , n-1$$ and $latex j = 0 , \ldots , i$$. - -$subhead U$$ -We define the upper triangular matrix $icode U$$ in terms of $icode LU$$. -The matrix $icode U$$ is zero below the diagonal, -one on the diagonal, -and the rest of the elements are defined by -$codei% - %U%(%i%, %j%) = %LU%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -for $latex i = 0 , \ldots , n-2$$ and $latex j = i+1 , \ldots , n-1$$. - -$subhead P$$ -We define the permuted matrix $icode P$$ in terms of -the matrix $icode L$$ and the matrix $icode U$$ -by $icode%P% = %L% * %U%$$. - -$subhead A$$ -The matrix $icode A$$, -which defines the linear equations that we are solving, is given by -$codei% - %P%(%i%, %j%) = %A%[ %ip%[%i%] * %n% + %jp%[%j%] ] -%$$ -(Hence -$icode LU$$ contains a permuted factorization of the matrix $icode A$$.) - - -$head X$$ -The argument $icode X$$ has prototype -$codei% - %FloatVector% &%X% -%$$ -(see description for $icode FloatVector$$ in -$cref/LuFactor/LuFactor/FloatVector/$$ specifications). -The matrix $icode X$$ -must have the same number of rows as the matrix $icode A$$. -The input value of $icode X$$ is the matrix $icode B$$ and the -output value solves the matrix equation $icode%A% * %X% = %B%$$. - - -$children% - example/utility/lu_invert.cpp% - omh/lu_invert_hpp.omh -%$$ -$head Example$$ -The file $cref lu_solve.hpp$$ is a good example usage of -$code LuFactor$$ with $code LuInvert$$. -The file -$cref lu_invert.cpp$$ -contains an example and test of using $code LuInvert$$ by itself. -It returns true if it succeeds and false otherwise. - -$head Source$$ -The file $cref lu_invert.hpp$$ contains the -current source code that implements these specifications. - -$end --------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -// LuInvert -template -void LuInvert( - const SizeVector &ip, - const SizeVector &jp, - const FloatVector &LU, - FloatVector &B ) -{ size_t k; // column index in X - size_t p; // index along diagonal in LU - size_t i; // row index in LU and X - - typedef typename FloatVector::value_type Float; - - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - CheckSimpleVector(); - - Float etmp; - - size_t n = ip.size(); - CPPAD_ASSERT_KNOWN( - size_t(jp.size()) == n, - "Error in LuInvert: jp must have size equal to n * n" - ); - CPPAD_ASSERT_KNOWN( - size_t(LU.size()) == n * n, - "Error in LuInvert: Lu must have size equal to n * m" - ); - size_t m = size_t(B.size()) / n; - CPPAD_ASSERT_KNOWN( - size_t(B.size()) == n * m, - "Error in LuSolve: B must have size equal to a multiple of n" - ); - - // temporary storage for reordered solution - FloatVector x(n); - - // loop over equations - for(k = 0; k < m; k++) - { // invert the equation c = L * b - for(p = 0; p < n; p++) - { // solve for c[p] - etmp = B[ ip[p] * m + k ] / LU[ ip[p] * n + jp[p] ]; - B[ ip[p] * m + k ] = etmp; - // subtract off effect on other variables - for(i = p+1; i < n; i++) - B[ ip[i] * m + k ] -= - etmp * LU[ ip[i] * n + jp[p] ]; - } - - // invert the equation x = U * c - p = n; - while( p > 0 ) - { --p; - etmp = B[ ip[p] * m + k ]; - x[ jp[p] ] = etmp; - for(i = 0; i < p; i++ ) - B[ ip[i] * m + k ] -= - etmp * LU[ ip[i] * n + jp[p] ]; - } - - // copy reordered solution into B - for(i = 0; i < n; i++) - B[i * m + k] = x[i]; - } - return; -} -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/utility/lu_solve.hpp b/external/cppad/include/cppad/utility/lu_solve.hpp deleted file mode 100644 index 965d28cf8..000000000 --- a/external/cppad/include/cppad/utility/lu_solve.hpp +++ /dev/null @@ -1,345 +0,0 @@ -# ifndef CPPAD_UTILITY_LU_SOLVE_HPP -# define CPPAD_UTILITY_LU_SOLVE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin LuSolve$$ -$escape #$$ -$spell - cppad.hpp - det - exp - Leq - typename - bool - const - namespace - std - Geq - Lu - CppAD - signdet - logdet -$$ - - -$section Compute Determinant and Solve Linear Equations$$ -$mindex LuSolve Lu$$ - -$pre -$$ - -$head Syntax$$ $codei%# include -%$$ -$icode%signdet% = LuSolve(%n%, %m%, %A%, %B%, %X%, %logdet%)%$$ - - -$head Description$$ -Use an LU factorization of the matrix $icode A$$ to -compute its determinant -and solve for $icode X$$ in the linear of equation -$latex \[ - A * X = B -\] $$ -where $icode A$$ is an -$icode n$$ by $icode n$$ matrix, -$icode X$$ is an -$icode n$$ by $icode m$$ matrix, and -$icode B$$ is an $latex n x m$$ matrix. - -$head Include$$ -The file $code cppad/lu_solve.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Factor and Invert$$ -This routine is an easy to user interface to -$cref LuFactor$$ and $cref LuInvert$$ for computing determinants and -solutions of linear equations. -These separate routines should be used if -one right hand side $icode B$$ -depends on the solution corresponding to another -right hand side (with the same value of $icode A$$). -In this case only one call to $code LuFactor$$ is required -but there will be multiple calls to $code LuInvert$$. - - -$head Matrix Storage$$ -All matrices are stored in row major order. -To be specific, if $latex Y$$ is a vector -that contains a $latex p$$ by $latex q$$ matrix, -the size of $latex Y$$ must be equal to $latex p * q $$ and for -$latex i = 0 , \ldots , p-1$$, -$latex j = 0 , \ldots , q-1$$, -$latex \[ - Y_{i,j} = Y[ i * q + j ] -\] $$ - -$head signdet$$ -The return value $icode signdet$$ is a $code int$$ value -that specifies the sign factor for the determinant of $icode A$$. -This determinant of $icode A$$ is zero if and only if $icode signdet$$ -is zero. - -$head n$$ -The argument $icode n$$ has type $code size_t$$ -and specifies the number of rows in the matrices -$icode A$$, -$icode X$$, -and $icode B$$. -The number of columns in $icode A$$ is also equal to $icode n$$. - -$head m$$ -The argument $icode m$$ has type $code size_t$$ -and specifies the number of columns in the matrices -$icode X$$ -and $icode B$$. -If $icode m$$ is zero, -only the determinant of $icode A$$ is computed and -the matrices $icode X$$ and $icode B$$ are not used. - -$head A$$ -The argument $icode A$$ has the prototype -$codei% - const %FloatVector% &%A% -%$$ -and the size of $icode A$$ must equal $latex n * n$$ -(see description of $cref/FloatVector/LuSolve/FloatVector/$$ below). -This is the $latex n$$ by $icode n$$ matrix that -we are computing the determinant of -and that defines the linear equation. - -$head B$$ -The argument $icode B$$ has the prototype -$codei% - const %FloatVector% &%B% -%$$ -and the size of $icode B$$ must equal $latex n * m$$ -(see description of $cref/FloatVector/LuSolve/FloatVector/$$ below). -This is the $latex n$$ by $icode m$$ matrix that -defines the right hand side of the linear equations. -If $icode m$$ is zero, $icode B$$ is not used. - -$head X$$ -The argument $icode X$$ has the prototype -$codei% - %FloatVector% &%X% -%$$ -and the size of $icode X$$ must equal $latex n * m$$ -(see description of $cref/FloatVector/LuSolve/FloatVector/$$ below). -The input value of $icode X$$ does not matter. -On output, the elements of $icode X$$ contain the solution -of the equation we wish to solve -(unless $icode signdet$$ is equal to zero). -If $icode m$$ is zero, $icode X$$ is not used. - -$head logdet$$ -The argument $icode logdet$$ has prototype -$codei% - %Float% &%logdet% -%$$ -On input, the value of $icode logdet$$ does not matter. -On output, it has been set to the -log of the determinant of $icode A$$ -(but not quite). -To be more specific, -the determinant of $icode A$$ is given by the formula -$codei% - %det% = %signdet% * exp( %logdet% ) -%$$ -This enables $code LuSolve$$ to use logs of absolute values -in the case where $icode Float$$ corresponds to a real number. - -$head Float$$ -The type $icode Float$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, the following operations must be defined for any pair -of $icode Float$$ objects $icode x$$ and $icode y$$: - -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$codei%log(%x%)%$$ $cnext - returns the logarithm of $icode x$$ as a $icode Float$$ object -$tend - -$head FloatVector$$ -The type $icode FloatVector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Float/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head LeqZero$$ -Including the file $code lu_solve.hpp$$ defines the template function -$codei% - template - bool LeqZero<%Float%>(const %Float% &%x%) -%$$ -in the $code CppAD$$ namespace. -This function returns true if $icode x$$ is less than or equal to zero -and false otherwise. -It is used by $code LuSolve$$ to avoid taking the log of -zero (or a negative number if $icode Float$$ corresponds to real numbers). -This template function definition assumes that the operator -$code <=$$ is defined for $icode Float$$ objects. -If this operator is not defined for your use of $icode Float$$, -you will need to specialize this template so that it works for your -use of $code LuSolve$$. -$pre - -$$ -Complex numbers do not have the operation or $code <=$$ defined. -In addition, in the complex case, -one can take the log of a negative number. -The specializations -$codei% - bool LeqZero< std::complex > (const std::complex &%x%) - bool LeqZero< std::complex >(const std::complex &%x%) -%$$ -are defined by including $code lu_solve.hpp$$. -These return true if $icode x$$ is zero and false otherwise. - -$head AbsGeq$$ -Including the file $code lu_solve.hpp$$ defines the template function -$codei% - template - bool AbsGeq<%Float%>(const %Float% &%x%, const %Float% &%y%) -%$$ -If the type $icode Float$$ does not support the $code <=$$ operation -and it is not $code std::complex$$ or $code std::complex$$, -see the documentation for $code AbsGeq$$ in $cref/LuFactor/LuFactor/AbsGeq/$$. - -$children% - example/utility/lu_solve.cpp% - omh/lu_solve_hpp.omh -%$$ -$head Example$$ -The file -$cref lu_solve.cpp$$ -contains an example and test of using this routine. -It returns true if it succeeds and false otherwise. - -$head Source$$ -The file $cref lu_solve.hpp$$ contains the -current source code that implements these specifications. - -$end --------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include -# include - -// link exp for float and double cases -# include - -# include -# include -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -// LeqZero -template -inline bool LeqZero(const Float &x) -{ return x <= Float(0); } -inline bool LeqZero( const std::complex &x ) -{ return x == std::complex(0); } -inline bool LeqZero( const std::complex &x ) -{ return x == std::complex(0); } - -// LuSolve -template -int LuSolve( - size_t n , - size_t m , - const FloatVector &A , - const FloatVector &B , - FloatVector &X , - Float &logdet ) -{ - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - - size_t p; // index of pivot element (diagonal of L) - int signdet; // sign of the determinant - Float pivot; // pivot element - - // the value zero - const Float zero(0); - - // pivot row and column order in the matrix - std::vector ip(n); - std::vector jp(n); - - // ------------------------------------------------------- - CPPAD_ASSERT_KNOWN( - size_t(A.size()) == n * n, - "Error in LuSolve: A must have size equal to n * n" - ); - CPPAD_ASSERT_KNOWN( - size_t(B.size()) == n * m, - "Error in LuSolve: B must have size equal to n * m" - ); - CPPAD_ASSERT_KNOWN( - size_t(X.size()) == n * m, - "Error in LuSolve: X must have size equal to n * m" - ); - // ------------------------------------------------------- - - // copy A so that it does not change - FloatVector Lu(A); - - // copy B so that it does not change - X = B; - - // Lu factor the matrix A - signdet = LuFactor(ip, jp, Lu); - - // compute the log of the determinant - logdet = Float(0); - for(p = 0; p < n; p++) - { // pivot using the max absolute element - pivot = Lu[ ip[p] * n + jp[p] ]; - - // check for determinant equal to zero - if( pivot == zero ) - { // abort the mission - logdet = Float(0); - return 0; - } - - // update the determinant - if( LeqZero ( pivot ) ) - { logdet += log( - pivot ); - signdet = - signdet; - } - else logdet += log( pivot ); - - } - - // solve the linear equations - LuInvert(ip, jp, Lu, X); - - // return the sign factor for the determinant - return signdet; -} -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/utility/memory_leak.hpp b/external/cppad/include/cppad/utility/memory_leak.hpp deleted file mode 100644 index bd058e0a8..000000000 --- a/external/cppad/include/cppad/utility/memory_leak.hpp +++ /dev/null @@ -1,214 +0,0 @@ -# ifndef CPPAD_UTILITY_MEMORY_LEAK_HPP -# define CPPAD_UTILITY_MEMORY_LEAK_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin memory_leak$$ -$spell - cppad - num - alloc - hpp - bool - inuse -$$ - -$section Memory Leak Detection$$ -$mindex memory_leak check static$$ - -$head Deprecated 2012-04-06$$ -This routine has been deprecated. -You should instead use the routine $cref ta_free_all$$. - -$head Syntax$$ -$codei%# include -%$$ -$icode%flag% = %memory_leak() -%$$ -$icode%flag% = %memory_leak%(%add_static%)%$$ - -$head Purpose$$ -This routine checks that the are no memory leaks -caused by improper use of $cref thread_alloc$$ memory allocator. -The deprecated memory allocator $cref TrackNewDel$$ is also checked. -Memory errors in the deprecated $cref omp_alloc$$ allocator are -reported as being in $code thread_alloc$$. - -$head thread$$ -It is assumed that $cref/in_parallel()/ta_in_parallel/$$ is false -and $cref/thread_num/ta_thread_num/$$ is zero when -$code memory_leak$$ is called. - -$head add_static$$ -This argument has prototype -$codei% - size_t %add_static% -%$$ -and its default value is zero. -Static variables hold onto memory forever. -If the argument $icode add_static$$ is present (and non-zero), -$code memory_leak$$ adds this amount of memory to the -$cref/inuse/ta_inuse/$$ sum that corresponds to -static variables in the program. -A call with $icode add_static$$ should be make after -a routine that has static variables which -use $cref/get_memory/ta_get_memory/$$ to allocate memory. -The value of $icode add_static$$ should be the difference of -$codei% - thread_alloc::inuse(0) -%$$ -before and after the call. -Since multiple statics may be allocated in different places in the program, -it is expected that there will be multiple calls -that use this option. - -$head flag$$ -The return value $icode flag$$ has prototype -$codei% - bool %flag% -%$$ -If $icode add_static$$ is non-zero, -the return value for $code memory_leak$$ is false. -Otherwise, the return value for $code memory_leak$$ should be false -(indicating that the only allocated memory corresponds to static variables). - -$head inuse$$ -It is assumed that, when $code memory_leak$$ is called, -there should not be any memory -$cref/inuse/ta_inuse/$$ or $cref omp_inuse$$ for any thread -(except for inuse memory corresponding to static variables). -If there is, a message is printed and $code memory_leak$$ returns false. - -$head available$$ -It is assumed that, when $code memory_leak$$ is called, -there should not be any memory -$cref/available/ta_available/$$ or $cref omp_available$$ for any thread; -i.e., it all has been returned to the system. -If there is memory still available for any thread, -$code memory_leak$$ returns false. - -$head TRACK_COUNT$$ -It is assumed that, when $code memory_leak$$ is called, -$cref/TrackCount/TrackNewDel/TrackCount/$$ will return a zero value. -If it returns a non-zero value, -$code memory_leak$$ returns false. - -$head Error Message$$ -If this is the first call to $code memory_leak$$, no message is printed. -Otherwise, if it returns true, an error message is printed -to standard output describing the memory leak that was detected. - -$end -*/ -# include -# include -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file memory_leak.hpp -File that implements a memory check at end of a CppAD program -*/ - -/*! -Function that checks -allocator \c thread_alloc for misuse that results in memory leaks. -Deprecated routines in track_new_del.hpp and omp_alloc.hpp are also checked. - -\param add_static [in] -The amount specified by \c add_static is added to the amount -of memory that is expected to be used by thread zero for static variables. - -\return -If \c add_static is non-zero, the return value is \c false. -Otherwise, if one of the following errors is detected, -the return value is \c true: - -\li -Thread zero does not have the expected amount of inuse memory -(for static variables). -\li -A thread, other than thread zero, has any inuse memory. -\li -Any thread has available memory. - -\par -If an error is detected, diagnostic information is printed to standard -output. -*/ -inline bool memory_leak(size_t add_static = 0) -{ // CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL not necessary given asserts below - static size_t thread_zero_static_inuse = 0; - using std::cout; - using std::endl; - using CppAD::thread_alloc; - using CppAD::omp_alloc; - // -------------------------------------------------------------------- - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel(), - "memory_leak: in_parallel() is true." - ); - CPPAD_ASSERT_KNOWN( - thread_alloc::thread_num() == 0, - "memory_leak: thread_num() is not zero." - ); - if( add_static != 0 ) - { thread_zero_static_inuse += add_static; - return false; - } - bool leak = false; - size_t thread = 0; - - // check that memory in use for thread zero corresponds to statics - size_t num_bytes = thread_alloc::inuse(thread); - if( num_bytes != thread_zero_static_inuse ) - { leak = true; - cout << "thread zero: static inuse = " << thread_zero_static_inuse; - cout << ", current inuse(0)= " << num_bytes << endl; - } - // check that no memory is currently available for this thread - num_bytes = thread_alloc::available(thread); - if( num_bytes != 0 ) - { leak = true; - cout << "thread zero: available = "; - cout << num_bytes << endl; - } - for(thread = 1; thread < CPPAD_MAX_NUM_THREADS; thread++) - { - // check that no memory is currently in use for this thread - num_bytes = thread_alloc::inuse(thread); - if( num_bytes != 0 ) - { leak = true; - cout << "thread " << thread << ": inuse(thread) = "; - cout << num_bytes << endl; - } - // check that no memory is currently available for this thread - num_bytes = thread_alloc::available(thread); - if( num_bytes != 0 ) - { leak = true; - cout << "thread " << thread << ": available(thread) = "; - cout << num_bytes << endl; - } - } - // ---------------------------------------------------------------------- - // check track_new_del - if( CPPAD_TRACK_COUNT() != 0 ) - { leak = true; - CppAD::TrackElement::Print(); - } - return leak; -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/utility/nan.hpp b/external/cppad/include/cppad/utility/nan.hpp deleted file mode 100644 index 9c1f54220..000000000 --- a/external/cppad/include/cppad/utility/nan.hpp +++ /dev/null @@ -1,193 +0,0 @@ -# ifndef CPPAD_UTILITY_NAN_HPP -# define CPPAD_UTILITY_NAN_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin nan$$ -$spell - hasnan - cppad - hpp - CppAD - isnan - bool - const -$$ - -$section Obtain Nan or Determine if a Value is Nan$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%b% = isnan(%s%) -%$$ -$icode%b% = hasnan(%v%)%$$ - -$head Purpose$$ -It obtain and check for the value not a number $code nan$$. -The IEEE standard specifies that a floating point value $icode a$$ -is $code nan$$ if and only if the following returns true -$codei% - %a% != %a% -%$$ - -$head Include$$ -The file $code cppad/nan.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$subhead Macros$$ -Some C++ compilers use preprocessor symbols called $code nan$$ -and $code isnan$$. -These preprocessor symbols will no longer be defined after -this file is included. - -$head isnan$$ -This routine determines if a scalar value is $code nan$$. - -$subhead s$$ -The argument $icode s$$ has prototype -$codei% - const %Scalar% %s% -%$$ - -$subhead b$$ -The return value $icode b$$ has prototype -$codei% - bool %b% -%$$ -It is true if the value $icode s$$ is $code nan$$. - -$head hasnan$$ -This routine determines if a -$cref SimpleVector$$ has an element that is $code nan$$. - -$subhead v$$ -The argument $icode v$$ has prototype -$codei% - const %Vector% &%v% -%$$ -(see $cref/Vector/nan/Vector/$$ for the definition of $icode Vector$$). - -$subhead b$$ -The return value $icode b$$ has prototype -$codei% - bool %b% -%$$ -It is true if the vector $icode v$$ has a $code nan$$. - - -$head nan(zero)$$ - -$subhead Deprecated 2015-10-04$$ -This routine has been deprecated, use CppAD numeric limits -$cref/quiet_NaN/numeric_limits/quiet_NaN/$$ in its place. - -$subhead Syntax$$ -$icode%s% = nan(%z%) -%$$ - -$subhead z$$ -The argument $icode z$$ has prototype -$codei% - const %Scalar% &%z% -%$$ -and its value is zero -(see $cref/Scalar/nan/Scalar/$$ for the definition of $icode Scalar$$). - -$subhead s$$ -The return value $icode s$$ has prototype -$codei% - %Scalar% %s% -%$$ -It is the value $code nan$$ for this floating point type. - -$head Scalar$$ -The type $icode Scalar$$ must support the following operations; -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$icode%a% / %b%$$ $cnext - division operator (returns a $icode Scalar$$ object) -$rnext -$icode%a% == %b%$$ $cnext - equality operator (returns a $code bool$$ object) -$rnext -$icode%a% != %b%$$ $cnext - not equality operator (returns a $code bool$$ object) -$tend -Note that the division operator will be used with $icode a$$ and $icode b$$ -equal to zero. For some types (e.g. $code int$$) this may generate -an exception. No attempt is made to catch any such exception. - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -elements of type $icode Scalar$$. - -$children% - example/utility/nan.cpp -%$$ -$head Example$$ -The file $cref nan.cpp$$ -contains an example and test of this routine. -It returns true if it succeeds and false otherwise. - -$end -*/ - -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -/* -# define nan There must be a define for every CppAD undef -*/ -# ifdef nan -# undef nan -# endif - -/* -# define isnan There must be a define for every CppAD undef -*/ -# ifdef isnan -# undef isnan -# endif - -namespace CppAD { // BEGIN CppAD namespace - -template -inline bool isnan(const Scalar &s) -{ return (s != s); -} - -template -bool hasnan(const Vector &v) -{ - bool found_nan; - size_t i; - i = v.size(); - found_nan = false; - // on MS Visual Studio 2012, CppAD required in front of isnan ? - while(i--) - found_nan |= CppAD::isnan(v[i]); - return found_nan; -} - -template -inline Scalar nan(const Scalar &zero) -{ return zero / zero; -} - -} // End CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/near_equal.hpp b/external/cppad/include/cppad/utility/near_equal.hpp deleted file mode 100644 index 21cd93cc6..000000000 --- a/external/cppad/include/cppad/utility/near_equal.hpp +++ /dev/null @@ -1,270 +0,0 @@ -# ifndef CPPAD_UTILITY_NEAR_EQUAL_HPP -# define CPPAD_UTILITY_NEAR_EQUAL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin NearEqual$$ -$spell - cppad.hpp - sqrt - cout - endl - Microsoft - std - Cpp - namespace - const - bool -$$ - -$section Determine if Two Values Are Nearly Equal$$ -$mindex NearEqual near absolute difference relative$$ - - -$head Syntax$$ - -$codei%# include -%$$ -$icode%b% = NearEqual(%x%, %y%, %r%, %a%)%$$ - - -$head Purpose$$ -Returns true, -if $icode x$$ and $icode y$$ are nearly equal, -and false otherwise. - -$head x$$ -The argument $icode x$$ -has one of the following possible prototypes -$codei% - const %Type% &%x%, - const std::complex<%Type%> &%x%, -%$$ - -$head y$$ -The argument $icode y$$ -has one of the following possible prototypes -$codei% - const %Type% &%y%, - const std::complex<%Type%> &%y%, -%$$ - -$head r$$ -The relative error criteria $icode r$$ has prototype -$codei% - const %Type% &%r% -%$$ -It must be greater than or equal to zero. -The relative error condition is defined as: -$latex \[ - | x - y | \leq r ( |x| + |y| ) -\] $$ - -$head a$$ -The absolute error criteria $icode a$$ has prototype -$codei% - const %Type% &%a% -%$$ -It must be greater than or equal to zero. -The absolute error condition is defined as: -$latex \[ - | x - y | \leq a -\] $$ - -$head b$$ -The return value $icode b$$ has prototype -$codei% - bool %b% -%$$ -If either $icode x$$ or $icode y$$ is infinite or not a number, -the return value is false. -Otherwise, if either the relative or absolute error -condition (defined above) is satisfied, the return value is true. -Otherwise, the return value is false. - -$head Type$$ -The type $icode Type$$ must be a -$cref NumericType$$. -The routine $cref CheckNumericType$$ will generate -an error message if this is not the case. -In addition, the following operations must be defined objects -$icode a$$ and $icode b$$ of type $icode Type$$: -$table -$bold Operation$$ $cnext - $bold Description$$ $rnext -$icode%a% <= %b%$$ $cnext - less that or equal operator (returns a $code bool$$ object) -$tend - -$head Include Files$$ -The file $code cppad/near_equal.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Example$$ -$children% - example/utility/near_equal.cpp -%$$ -The file $cref near_equal.cpp$$ contains an example -and test of $code NearEqual$$. -It return true if it succeeds and false otherwise. - -$head Exercise$$ -Create and run a program that contains the following code: -$codep - using std::complex; - using std::cout; - using std::endl; - - complex one(1., 0), i(0., 1); - complex x = one / i; - complex y = - i; - double r = 1e-12; - double a = 0; - bool ok = CppAD::NearEqual(x, y, r, a); - if( ok ) - cout << "Ok" << endl; - else cout << "Error" << endl; -$$ - -$end - -*/ - -# include -# include -# include -# include - -namespace CppAD { // Begin CppAD namespace - -// determine if both x and y are finite values -template -bool near_equal_isfinite(const Type &x , const Type &y) -{ Type infinity = Type( std::numeric_limits::infinity() ); - - // handle bug where some compilers return true for nan == nan - bool xNan = x != x; - bool yNan = y != y; - - // infinite cases - bool xInf = (x == infinity || x == - infinity); - bool yInf = (x == infinity || x == - infinity); - - return ! (xNan | yNan | xInf | yInf); -} - -template -bool NearEqual(const Type &x, const Type &y, const Type &r, const Type &a) -{ - CheckNumericType(); - Type zero(0); - - CPPAD_ASSERT_KNOWN( - zero <= r, - "Error in NearEqual: relative error is less than zero" - ); - CPPAD_ASSERT_KNOWN( - zero <= a, - "Error in NearEqual: absolute error is less than zero" - ); - - // check for special cases - if( ! CppAD::near_equal_isfinite(x, y) ) - return false; - - Type ax = x; - if( ax <= zero ) - ax = - ax; - - Type ay = y; - if( ay <= zero ) - ay = - ay; - - Type ad = x - y; - if( ad <= zero ) - ad = - ad; - - if( ad <= a ) - return true; - - if( ad <= r * (ax + ay) ) - return true; - - return false; -} - -template -bool NearEqual( - const std::complex &x , - const std::complex &y , - const Type &r , - const Type & a ) -{ - CheckNumericType(); -# ifndef NDEBUG - Type zero(0); -# endif - - CPPAD_ASSERT_KNOWN( - zero <= r, - "Error in NearEqual: relative error is less than zero" - ); - CPPAD_ASSERT_KNOWN( - zero <= a, - "Error in NearEqual: absolute error is less than zero" - ); - - // check for special cases - if( ! CppAD::near_equal_isfinite(x.real(), x.imag()) ) - return false; - if( ! CppAD::near_equal_isfinite(y.real(), y.imag()) ) - return false; - - std::complex d = x - y; - - Type ad = std::abs(d); - if( ad <= a ) - return true; - - Type ax = std::abs(x); - Type ay = std::abs(y); - if( ad <= r * (ax + ay) ) - return true; - - return false; -} - -template -bool NearEqual( - const std::complex &x , - const Type &y , - const Type &r , - const Type & a ) -{ - return NearEqual(x, std::complex(y, Type(0)), r, a); -} - -template -bool NearEqual( - const Type &x , - const std::complex &y , - const Type &r , - const Type & a ) -{ - return NearEqual(std::complex(x, Type(0)), y, r, a); -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/ode_err_control.hpp b/external/cppad/include/cppad/utility/ode_err_control.hpp deleted file mode 100644 index 2b2eb46e1..000000000 --- a/external/cppad/include/cppad/utility/ode_err_control.hpp +++ /dev/null @@ -1,595 +0,0 @@ -# ifndef CPPAD_UTILITY_ODE_ERR_CONTROL_HPP -# define CPPAD_UTILITY_ODE_ERR_CONTROL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin OdeErrControl$$ -$spell - cppad.hpp - nstep - maxabs - exp - scur - CppAD - xf - tf - xi - smin - smax - eabs - erel - ef - ta - tb - xa - xb - const - eb -$$ - - - -$section An Error Controller for ODE Solvers$$ -$mindex OdeErrControl differential equation$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%xf% = OdeErrControl(%method%, %ti%, %tf%, %xi%, - %smin%, %smax%, %scur%, %eabs%, %erel%, %ef% , %maxabs%, %nstep% )%$$ - - -$head Description$$ -Let $latex \B{R}$$ denote the real numbers -and let $latex F : \B{R} \times \B{R}^n \rightarrow \B{R}^n$$ be a smooth function. -We define $latex X : [ti , tf] \rightarrow \B{R}^n$$ by -the following initial value problem: -$latex \[ -\begin{array}{rcl} - X(ti) & = & xi \\ - X'(t) & = & F[t , X(t)] -\end{array} -\] $$ -The routine $code OdeErrControl$$ can be used to adjust the step size -used an arbitrary integration methods in order to be as fast as possible -and still with in a requested error bound. - -$head Include$$ -The file $code cppad/ode_err_control.hpp$$ is included by -$code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Notation$$ -The template parameter types $cref/Scalar/OdeErrControl/Scalar/$$ and -$cref/Vector/OdeErrControl/Vector/$$ are documented below. - -$head xf$$ -The return value $icode xf$$ has the prototype -$codei% - %Vector% %xf% -%$$ -(see description of $cref/Vector/OdeErrControl/Vector/$$ below). -and the size of $icode xf$$ is equal to $icode n$$. -If $icode xf$$ contains not a number $cref nan$$, -see the discussion of $cref/step/OdeErrControl/Method/Nan/$$. - -$head Method$$ -The class $icode Method$$ -and the object $icode method$$ satisfy the following syntax -$codei% - %Method% &%method% -%$$ -The object $icode method$$ must support $code step$$ and -$code order$$ member functions defined below: - -$subhead step$$ -The syntax -$codei% - %method%.step(%ta%, %tb%, %xa%, %xb%, %eb%) -%$$ -executes one step of the integration method. -$codei% - -%ta% -%$$ -The argument $icode ta$$ has prototype -$codei% - const %Scalar% &%ta% -%$$ -It specifies the initial time for this step in the -ODE integration. -(see description of $cref/Scalar/OdeErrControl/Scalar/$$ below). -$codei% - -%tb% -%$$ -The argument $icode tb$$ has prototype -$codei% - const %Scalar% &%tb% -%$$ -It specifies the final time for this step in the -ODE integration. -$codei% - -%xa% -%$$ -The argument $icode xa$$ has prototype -$codei% - const %Vector% &%xa% -%$$ -and size $icode n$$. -It specifies the value of $latex X(ta)$$. -(see description of $cref/Vector/OdeErrControl/Vector/$$ below). -$codei% - -%xb% -%$$ -The argument value $icode xb$$ has prototype -$codei% - %Vector% &%xb% -%$$ -and size $icode n$$. -The input value of its elements does not matter. -On output, -it contains the approximation for $latex X(tb)$$ that the method obtains. -$codei% - -%eb% -%$$ -The argument value $icode eb$$ has prototype -$codei% - %Vector% &%eb% -%$$ -and size $icode n$$. -The input value of its elements does not matter. -On output, -it contains an estimate for the error in the approximation $icode xb$$. -It is assumed (locally) that the error bound in this approximation -nearly equal to $latex K (tb - ta)^m$$ -where $icode K$$ is a fixed constant and $icode m$$ -is the corresponding argument to $code CodeControl$$. - -$subhead Nan$$ -If any element of the vector $icode eb$$ or $icode xb$$ are -not a number $code nan$$, -the current step is considered to large. -If this happens with the current step size equal to $icode smin$$, -$code OdeErrControl$$ returns with $icode xf$$ and $icode ef$$ as vectors -of $code nan$$. - -$subhead order$$ -If $icode m$$ is $code size_t$$, -the object $icode method$$ must also support the following syntax -$codei% - %m% = %method%.order() -%$$ -The return value $icode m$$ is the order of the error estimate; -i.e., there is a constant K such that if $latex ti \leq ta \leq tb \leq tf$$, -$latex \[ - | eb(tb) | \leq K | tb - ta |^m -\] $$ -where $icode ta$$, $icode tb$$, and $icode eb$$ are as in -$icode%method%.step(%ta%, %tb%, %xa%, %xb%, %eb%)%$$ - - -$head ti$$ -The argument $icode ti$$ has prototype -$codei% - const %Scalar% &%ti% -%$$ -It specifies the initial time for the integration of -the differential equation. - - -$head tf$$ -The argument $icode tf$$ has prototype -$codei% - const %Scalar% &%tf% -%$$ -It specifies the final time for the integration of -the differential equation. - -$head xi$$ -The argument $icode xi$$ has prototype -$codei% - const %Vector% &%xi% -%$$ -and size $icode n$$. -It specifies value of $latex X(ti)$$. - -$head smin$$ -The argument $icode smin$$ has prototype -$codei% - const %Scalar% &%smin% -%$$ -The step size during a call to $icode method$$ is defined as -the corresponding value of $latex tb - ta$$. -If $latex tf - ti \leq smin$$, -the integration will be done in one step of size $icode tf - ti$$. -Otherwise, -the minimum value of $icode tb - ta$$ will be $latex smin$$ -except for the last two calls to $icode method$$ where it may be -as small as $latex smin / 2$$. - -$head smax$$ -The argument $icode smax$$ has prototype -$codei% - const %Scalar% &%smax% -%$$ -It specifies the maximum step size to use during the integration; -i.e., the maximum value for $latex tb - ta$$ in a call to $icode method$$. -The value of $icode smax$$ must be greater than or equal $icode smin$$. - -$head scur$$ -The argument $icode scur$$ has prototype -$codei% - %Scalar% &%scur% -%$$ -The value of $icode scur$$ is the suggested next step size, -based on error criteria, to try in the next call to $icode method$$. -On input it corresponds to the first call to $icode method$$, -in this call to $code OdeErrControl$$ (where $latex ta = ti$$). -On output it corresponds to the next call to $icode method$$, -in a subsequent call to $code OdeErrControl$$ (where $icode ta = tf$$). - -$head eabs$$ -The argument $icode eabs$$ has prototype -$codei% - const %Vector% &%eabs% -%$$ -and size $icode n$$. -Each of the elements of $icode eabs$$ must be -greater than or equal zero. -It specifies a bound for the absolute -error in the return value $icode xf$$ as an approximation for $latex X(tf)$$. -(see the -$cref/error criteria discussion/OdeErrControl/Error Criteria Discussion/$$ -below). - -$head erel$$ -The argument $icode erel$$ has prototype -$codei% - const %Scalar% &%erel% -%$$ -and is greater than or equal zero. -It specifies a bound for the relative -error in the return value $icode xf$$ as an approximation for $latex X(tf)$$ -(see the -$cref/error criteria discussion/OdeErrControl/Error Criteria Discussion/$$ -below). - -$head ef$$ -The argument value $icode ef$$ has prototype -$codei% - %Vector% &%ef% -%$$ -and size $icode n$$. -The input value of its elements does not matter. -On output, -it contains an estimated bound for the -absolute error in the approximation $icode xf$$; i.e., -$latex \[ - ef_i > | X( tf )_i - xf_i | -\] $$ -If on output $icode ef$$ contains not a number $code nan$$, -see the discussion of $cref/step/OdeErrControl/Method/Nan/$$. - -$head maxabs$$ -The argument $icode maxabs$$ is optional in the call to $code OdeErrControl$$. -If it is present, it has the prototype -$codei% - %Vector% &%maxabs% -%$$ -and size $icode n$$. -The input value of its elements does not matter. -On output, -it contains an estimate for the -maximum absolute value of $latex X(t)$$; i.e., -$latex \[ - maxabs[i] \approx \max \left\{ - | X( t )_i | \; : \; t \in [ti, tf] - \right\} -\] $$ - -$head nstep$$ -The argument $icode nstep$$ is optional in the call to $code OdeErrControl$$. -If it is present, it has the prototype -$codei% - %size_t% &%nstep% -%$$ -Its input value does not matter and its output value -is the number of calls to $icode%method%.step%$$ -used by $code OdeErrControl$$. - -$head Error Criteria Discussion$$ -The relative error criteria $icode erel$$ and -absolute error criteria $icode eabs$$ are enforced during each step of the -integration of the ordinary differential equations. -In addition, they are inversely scaled by the step size so that -the total error bound is less than the sum of the error bounds. -To be specific, if $latex \tilde{X} (t)$$ is the approximate solution -at time $latex t$$, -$icode ta$$ is the initial step time, -and $icode tb$$ is the final step time, -$latex \[ -\left| \tilde{X} (tb)_j - X (tb)_j \right| -\leq -\frac{tf - ti}{tb - ta} -\left[ eabs[j] + erel \; | \tilde{X} (tb)_j | \right] -\] $$ -If $latex X(tb)_j$$ is near zero for some $latex tb \in [ti , tf]$$, -and one uses an absolute error criteria $latex eabs[j]$$ of zero, -the error criteria above will force $code OdeErrControl$$ -to use step sizes equal to -$cref/smin/OdeErrControl/smin/$$ -for steps ending near $latex tb$$. -In this case, the error relative to $icode maxabs$$ can be judged after -$code OdeErrControl$$ returns. -If $icode ef$$ is to large relative to $icode maxabs$$, -$code OdeErrControl$$ can be called again -with a smaller value of $icode smin$$. - -$head Scalar$$ -The type $icode Scalar$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, the following operations must be defined for -$icode Scalar$$ objects $icode a$$ and $icode b$$: - -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$icode%a% <= %b%$$ $cnext - returns true (false) if $icode a$$ is less than or equal - (greater than) $icode b$$. -$rnext -$icode%a% == %b%$$ $cnext - returns true (false) if $icode a$$ is equal to $icode b$$. -$rnext -$codei%log(%a%)%$$ $cnext - returns a $icode Scalar$$ equal to the logarithm of $icode a$$ -$rnext -$codei%exp(%a%)%$$ $cnext - returns a $icode Scalar$$ equal to the exponential of $icode a$$ -$tend - - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Scalar/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Example$$ -$children% - example/utility/ode_err_control.cpp% - example/utility/ode_err_maxabs.cpp -%$$ -The files -$cref ode_err_control.cpp$$ -and -$cref ode_err_maxabs.cpp$$ -contain examples and tests of using this routine. -They return true if they succeed and false otherwise. - -$head Theory$$ -Let $latex e(s)$$ be the error as a function of the -step size $latex s$$ and suppose that there is a constant -$latex K$$ such that $latex e(s) = K s^m$$. -Let $latex a$$ be our error bound. -Given the value of $latex e(s)$$, a step of size $latex \lambda s$$ -would be ok provided that -$latex \[ -\begin{array}{rcl} - a & \geq & e( \lambda s ) (tf - ti) / ( \lambda s ) \\ - a & \geq & K \lambda^m s^m (tf - ti) / ( \lambda s ) \\ - a & \geq & \lambda^{m-1} s^{m-1} (tf - ti) e(s) / s^m \\ - a & \geq & \lambda^{m-1} (tf - ti) e(s) / s \\ - \lambda^{m-1} & \leq & \frac{a}{e(s)} \frac{s}{tf - ti} -\end{array} -\] $$ -Thus if the right hand side of the last inequality is greater -than or equal to one, the step of size $latex s$$ is ok. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/ode_err_control.hpp$$. - -$end --------------------------------------------------------------------------- -*/ - -// link exp and log for float and double -# include - -# include -# include -# include - -namespace CppAD { // Begin CppAD namespace - -template -Vector OdeErrControl( - Method &method, - const Scalar &ti , - const Scalar &tf , - const Vector &xi , - const Scalar &smin , - const Scalar &smax , - Scalar &scur , - const Vector &eabs , - const Scalar &erel , - Vector &ef , - Vector &maxabs, - size_t &nstep ) -{ - // check simple vector class specifications - CheckSimpleVector(); - - size_t n = size_t(xi.size()); - - CPPAD_ASSERT_KNOWN( - smin <= smax, - "Error in OdeErrControl: smin > smax" - ); - CPPAD_ASSERT_KNOWN( - size_t(eabs.size()) == n, - "Error in OdeErrControl: size of eabs is not equal to n" - ); - CPPAD_ASSERT_KNOWN( - size_t(maxabs.size()) == n, - "Error in OdeErrControl: size of maxabs is not equal to n" - ); - size_t m = method.order(); - CPPAD_ASSERT_KNOWN( - m > 1, - "Error in OdeErrControl: m is less than or equal one" - ); - - bool ok; - bool minimum_step; - size_t i; - Vector xa(n), xb(n), eb(n), nan_vec(n); - - // initialization - Scalar zero(0.0); - Scalar one(1.0); - Scalar two(2.0); - Scalar three(3.0); - Scalar m1(double(m-1)); - Scalar ta = ti; - for(i = 0; i < n; i++) - { nan_vec[i] = nan(zero); - ef[i] = zero; - xa[i] = xi[i]; - if( zero <= xi[i] ) - maxabs[i] = xi[i]; - else maxabs[i] = - xi[i]; - - } - nstep = 0; - - Scalar tb, step, lambda, axbi, a, r, root; - while( ! (ta == tf) ) - { // start with value suggested by error criteria - step = scur; - - // check maximum - if( smax <= step ) - step = smax; - - // check minimum - minimum_step = step <= smin; - if( minimum_step ) - step = smin; - - // check if near the end - if( tf <= ta + step * three / two ) - tb = tf; - else tb = ta + step; - - // try using this step size - nstep++; - method.step(ta, tb, xa, xb, eb); - step = tb - ta; - - // check if this steps error estimate is ok - ok = ! (hasnan(xb) || hasnan(eb)); - if( (! ok) && minimum_step ) - { ef = nan_vec; - return nan_vec; - } - - // compute value of lambda for this step - lambda = Scalar(10) * scur / step; - for(i = 0; i < n; i++) - { if( zero <= xb[i] ) - axbi = xb[i]; - else axbi = - xb[i]; - a = eabs[i] + erel * axbi; - if( ! (eb[i] == zero) ) - { r = ( a / eb[i] ) * step / (tf - ti); - root = exp( log(r) / m1 ); - if( root <= lambda ) - lambda = root; - } - } - if( ok && ( one <= lambda || step <= smin * three / two) ) - { // this step is within error limits or - // close to the minimum size - ta = tb; - for(i = 0; i < n; i++) - { xa[i] = xb[i]; - ef[i] = ef[i] + eb[i]; - if( zero <= xb[i] ) - axbi = xb[i]; - else axbi = - xb[i]; - if( axbi > maxabs[i] ) - maxabs[i] = axbi; - } - } - if( ! ok ) - { // decrease step an see if method will work this time - scur = step / two; - } - else if( ! (ta == tf) ) - { // step suggested by the error criteria is not used - // on the last step because it may be very small. - scur = lambda * step / two; - } - } - return xa; -} - -template -Vector OdeErrControl( - Method &method, - const Scalar &ti , - const Scalar &tf , - const Vector &xi , - const Scalar &smin , - const Scalar &smax , - Scalar &scur , - const Vector &eabs , - const Scalar &erel , - Vector &ef ) -{ Vector maxabs(xi.size()); - size_t nstep; - return OdeErrControl( - method, ti, tf, xi, smin, smax, scur, eabs, erel, ef, maxabs, nstep - ); -} - -template -Vector OdeErrControl( - Method &method, - const Scalar &ti , - const Scalar &tf , - const Vector &xi , - const Scalar &smin , - const Scalar &smax , - Scalar &scur , - const Vector &eabs , - const Scalar &erel , - Vector &ef , - Vector &maxabs) -{ size_t nstep; - return OdeErrControl( - method, ti, tf, xi, smin, smax, scur, eabs, erel, ef, maxabs, nstep - ); -} - -} // End CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/ode_gear.hpp b/external/cppad/include/cppad/utility/ode_gear.hpp deleted file mode 100644 index 1ef3a98c0..000000000 --- a/external/cppad/include/cppad/utility/ode_gear.hpp +++ /dev/null @@ -1,522 +0,0 @@ -# ifndef CPPAD_UTILITY_ODE_GEAR_HPP -# define CPPAD_UTILITY_ODE_GEAR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin OdeGear$$ -$spell - cppad.hpp - Jan - bool - const - CppAD - dep -$$ - - -$section An Arbitrary Order Gear Method$$ -$mindex OdeGear Ode stiff differential equation$$ - -$head Syntax$$ -$codei%# include -%$$ -$codei%OdeGear(%F%, %m%, %n%, %T%, %X%, %e%)%$$ - - -$head Purpose$$ -This routine applies -$cref/Gear's Method/OdeGear/Gear's Method/$$ -to solve an explicit set of ordinary differential equations. -We are given -$latex f : \B{R} \times \B{R}^n \rightarrow \B{R}^n$$ be a smooth function. -This routine solves the following initial value problem -$latex \[ -\begin{array}{rcl} - x( t_{m-1} ) & = & x^0 \\ - x^\prime (t) & = & f[t , x(t)] -\end{array} -\] $$ -for the value of $latex x( t_m )$$. -If your set of ordinary differential equations are not stiff -an explicit method may be better (perhaps $cref Runge45$$.) - -$head Include$$ -The file $code cppad/ode_gear.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Fun$$ -The class $icode Fun$$ -and the object $icode F$$ satisfy the prototype -$codei% - %Fun% &%F% -%$$ -This must support the following set of calls -$codei% - %F%.Ode(%t%, %x%, %f%) - %F%.Ode_dep(%t%, %x%, %f_x%) -%$$ - -$subhead t$$ -The argument $icode t$$ has prototype -$codei% - const %Scalar% &%t% -%$$ -(see description of $cref/Scalar/OdeGear/Scalar/$$ below). - -$subhead x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -and has size $icode n$$ -(see description of $cref/Vector/OdeGear/Vector/$$ below). - -$subhead f$$ -The argument $icode f$$ to $icode%F%.Ode%$$ has prototype -$codei% - %Vector% &%f% -%$$ -On input and output, $icode f$$ is a vector of size $icode n$$ -and the input values of the elements of $icode f$$ do not matter. -On output, -$icode f$$ is set equal to $latex f(t, x)$$ -(see $icode f(t, x)$$ in $cref/Purpose/OdeGear/Purpose/$$). - -$subhead f_x$$ -The argument $icode f_x$$ has prototype -$codei% - %Vector% &%f_x% -%$$ -On input and output, $icode f_x$$ is a vector of size $latex n * n$$ -and the input values of the elements of $icode f_x$$ do not matter. -On output, -$latex \[ - f\_x [i * n + j] = \partial_{x(j)} f_i ( t , x ) -\] $$ - -$subhead Warning$$ -The arguments $icode f$$, and $icode f_x$$ -must have a call by reference in their prototypes; i.e., -do not forget the $code &$$ in the prototype for -$icode f$$ and $icode f_x$$. - -$head m$$ -The argument $icode m$$ has prototype -$codei% - size_t %m% -%$$ -It specifies the order (highest power of $latex t$$) -used to represent the function $latex x(t)$$ in the multi-step method. -Upon return from $code OdeGear$$, -the $th i$$ component of the polynomial is defined by -$latex \[ - p_i ( t_j ) = X[ j * n + i ] -\] $$ -for $latex j = 0 , \ldots , m$$ (where $latex 0 \leq i < n$$). -The value of $latex m$$ must be greater than or equal one. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -It specifies the range space dimension of the -vector valued function $latex x(t)$$. - -$head T$$ -The argument $icode T$$ has prototype -$codei% - const %Vector% &%T% -%$$ -and size greater than or equal to $latex m+1$$. -For $latex j = 0 , \ldots m$$, $latex T[j]$$ is the time -corresponding to time corresponding -to a previous point in the multi-step method. -The value $latex T[m]$$ is the time -of the next point in the multi-step method. -The array $latex T$$ must be monotone increasing; i.e., -$latex T[j] < T[j+1]$$. -Above and below we often use the shorthand $latex t_j$$ for $latex T[j]$$. - - -$head X$$ -The argument $icode X$$ has the prototype -$codei% - %Vector% &%X% -%$$ -and size greater than or equal to $latex (m+1) * n$$. -On input to $code OdeGear$$, -for $latex j = 0 , \ldots , m-1$$, and -$latex i = 0 , \ldots , n-1$$ -$latex \[ - X[ j * n + i ] = x_i ( t_j ) -\] $$ -Upon return from $code OdeGear$$, -for $latex i = 0 , \ldots , n-1$$ -$latex \[ - X[ m * n + i ] \approx x_i ( t_m ) -\] $$ - -$head e$$ -The vector $icode e$$ is an approximate error bound for the result; i.e., -$latex \[ - e[i] \geq | X[ m * n + i ] - x_i ( t_m ) | -\] $$ -The order of this approximation is one less than the order of -the solution; i.e., -$latex \[ - e = O ( h^m ) -\] $$ -where $latex h$$ is the maximum of $latex t_{j+1} - t_j$$. - -$head Scalar$$ -The type $icode Scalar$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, the following operations must be defined for -$icode Scalar$$ objects $icode a$$ and $icode b$$: - -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$icode%a% < %b%$$ $cnext - less than operator (returns a $code bool$$ object) -$tend - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Scalar/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Example$$ -$children% - example/utility/ode_gear.cpp -%$$ -The file -$cref ode_gear.cpp$$ -contains an example and test a test of using this routine. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/ode_gear.hpp$$. - -$head Theory$$ -For this discussion we use the shorthand $latex x_j$$ -for the value $latex x ( t_j ) \in \B{R}^n$$ which is not to be confused -with $latex x_i (t) \in \B{R}$$ in the notation above. -The interpolating polynomial $latex p(t)$$ is given by -$latex \[ -p(t) = -\sum_{j=0}^m -x_j -\frac{ - \prod_{i \neq j} ( t - t_i ) -}{ - \prod_{i \neq j} ( t_j - t_i ) -} -\] $$ -The derivative $latex p^\prime (t)$$ is given by -$latex \[ -p^\prime (t) = -\sum_{j=0}^m -x_j -\frac{ - \sum_{i \neq j} \prod_{k \neq i,j} ( t - t_k ) -}{ - \prod_{k \neq j} ( t_j - t_k ) -} -\] $$ -Evaluating the derivative at the point $latex t_\ell$$ we have -$latex \[ -\begin{array}{rcl} -p^\prime ( t_\ell ) & = & -x_\ell -\frac{ - \sum_{i \neq \ell} \prod_{k \neq i,\ell} ( t_\ell - t_k ) -}{ - \prod_{k \neq \ell} ( t_\ell - t_k ) -} -+ -\sum_{j \neq \ell} -x_j -\frac{ - \sum_{i \neq j} \prod_{k \neq i,j} ( t_\ell - t_k ) -}{ - \prod_{k \neq j} ( t_j - t_k ) -} -\\ -& = & -x_\ell -\sum_{i \neq \ell} -\frac{ 1 }{ t_\ell - t_i } -+ -\sum_{j \neq \ell} -x_j -\frac{ - \prod_{k \neq \ell,j} ( t_\ell - t_k ) -}{ - \prod_{k \neq j} ( t_j - t_k ) -} -\\ -& = & -x_\ell -\sum_{k \neq \ell} ( t_\ell - t_k )^{-1} -+ -\sum_{j \neq \ell} -x_j -( t_j - t_\ell )^{-1} -\prod_{k \neq \ell ,j} ( t_\ell - t_k ) / ( t_j - t_k ) -\end{array} -\] $$ -We define the vector $latex \alpha \in \B{R}^{m+1}$$ by -$latex \[ -\alpha_j = \left\{ \begin{array}{ll} -\sum_{k \neq m} ( t_m - t_k )^{-1} - & {\rm if} \; j = m -\\ -( t_j - t_m )^{-1} -\prod_{k \neq m,j} ( t_m - t_k ) / ( t_j - t_k ) - & {\rm otherwise} -\end{array} \right. -\] $$ -It follows that -$latex \[ - p^\prime ( t_m ) = \alpha_0 x_0 + \cdots + \alpha_m x_m -\] $$ -Gear's method determines $latex x_m$$ by solving the following -nonlinear equation -$latex \[ - f( t_m , x_m ) = \alpha_0 x_0 + \cdots + \alpha_m x_m -\] $$ -Newton's method for solving this equation determines iterates, -which we denote by $latex x_m^k$$, by solving the following affine -approximation of the equation above -$latex \[ -\begin{array}{rcl} -f( t_m , x_m^{k-1} ) + \partial_x f( t_m , x_m^{k-1} ) ( x_m^k - x_m^{k-1} ) -& = & -\alpha_0 x_0^k + \alpha_1 x_1 + \cdots + \alpha_m x_m -\\ -\left[ \alpha_m I - \partial_x f( t_m , x_m^{k-1} ) \right] x_m -& = & -\left[ -f( t_m , x_m^{k-1} ) - \partial_x f( t_m , x_m^{k-1} ) x_m^{k-1} -- \alpha_0 x_0 - \cdots - \alpha_{m-1} x_{m-1} -\right] -\end{array} -\] $$ -In order to initialize Newton's method; i.e. choose $latex x_m^0$$ -we define the vector $latex \beta \in \B{R}^{m+1}$$ by -$latex \[ -\beta_j = \left\{ \begin{array}{ll} -\sum_{k \neq m-1} ( t_{m-1} - t_k )^{-1} - & {\rm if} \; j = m-1 -\\ -( t_j - t_{m-1} )^{-1} -\prod_{k \neq m-1,j} ( t_{m-1} - t_k ) / ( t_j - t_k ) - & {\rm otherwise} -\end{array} \right. -\] $$ -It follows that -$latex \[ - p^\prime ( t_{m-1} ) = \beta_0 x_0 + \cdots + \beta_m x_m -\] $$ -We solve the following approximation of the equation above to determine -$latex x_m^0$$: -$latex \[ - f( t_{m-1} , x_{m-1} ) = - \beta_0 x_0 + \cdots + \beta_{m-1} x_{m-1} + \beta_m x_m^0 -\] $$ - - -$head Gear's Method$$ -C. W. Gear, -``Simultaneous Numerical Solution of Differential-Algebraic Equations,'' -IEEE Transactions on Circuit Theory, -vol. 18, no. 1, pp. 89-95, Jan. 1971. - - -$end --------------------------------------------------------------------------- -*/ - -# include -# include -# include -# include -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -template -void OdeGear( - Fun &F , - size_t m , - size_t n , - const Vector &T , - Vector &X , - Vector &e ) -{ - // temporary indices - size_t i, j, k; - - typedef typename Vector::value_type Scalar; - - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - - CPPAD_ASSERT_KNOWN( - m >= 1, - "OdeGear: m is less than one" - ); - CPPAD_ASSERT_KNOWN( - n > 0, - "OdeGear: n is equal to zero" - ); - CPPAD_ASSERT_KNOWN( - size_t(T.size()) >= (m+1), - "OdeGear: size of T is not greater than or equal (m+1)" - ); - CPPAD_ASSERT_KNOWN( - size_t(X.size()) >= (m+1) * n, - "OdeGear: size of X is not greater than or equal (m+1) * n" - ); - for(j = 0; j < m; j++) CPPAD_ASSERT_KNOWN( - T[j] < T[j+1], - "OdeGear: the array T is not monotone increasing" - ); - - // some constants - Scalar zero(0); - Scalar one(1); - - // vectors required by method - Vector alpha(m + 1); - Vector beta(m + 1); - Vector f(n); - Vector f_x(n * n); - Vector x_m0(n); - Vector x_m(n); - Vector b(n); - Vector A(n * n); - - // compute alpha[m] - alpha[m] = zero; - for(k = 0; k < m; k++) - alpha[m] += one / (T[m] - T[k]); - - // compute beta[m-1] - beta[m-1] = one / (T[m-1] - T[m]); - for(k = 0; k < m-1; k++) - beta[m-1] += one / (T[m-1] - T[k]); - - - // compute other components of alpha - for(j = 0; j < m; j++) - { // compute alpha[j] - alpha[j] = one / (T[j] - T[m]); - for(k = 0; k < m; k++) - { if( k != j ) - { alpha[j] *= (T[m] - T[k]); - alpha[j] /= (T[j] - T[k]); - } - } - } - - // compute other components of beta - for(j = 0; j <= m; j++) - { if( j != m-1 ) - { // compute beta[j] - beta[j] = one / (T[j] - T[m-1]); - for(k = 0; k <= m; k++) - { if( k != j && k != m-1 ) - { beta[j] *= (T[m-1] - T[k]); - beta[j] /= (T[j] - T[k]); - } - } - } - } - - // evaluate f(T[m-1], x_{m-1} ) - for(i = 0; i < n; i++) - x_m[i] = X[(m-1) * n + i]; - F.Ode(T[m-1], x_m, f); - - // solve for x_m^0 - for(i = 0; i < n; i++) - { x_m[i] = f[i]; - for(j = 0; j < m; j++) - x_m[i] -= beta[j] * X[j * n + i]; - x_m[i] /= beta[m]; - } - x_m0 = x_m; - - // evaluate partial w.r.t x of f(T[m], x_m^0) - F.Ode_dep(T[m], x_m, f_x); - - // compute the matrix A = ( alpha[m] * I - f_x ) - for(i = 0; i < n; i++) - { for(j = 0; j < n; j++) - A[i * n + j] = - f_x[i * n + j]; - A[i * n + i] += alpha[m]; - } - - // LU factor (and overwrite) the matrix A - CppAD::vector ip(n) , jp(n); -# ifndef NDEBUG - int sign = -# endif - LuFactor(ip, jp, A); - CPPAD_ASSERT_KNOWN( - sign != 0, - "OdeGear: step size is to large" - ); - - // Iterations of Newton's method - for(k = 0; k < 3; k++) - { - // only evaluate f( T[m] , x_m ) keep f_x during iteration - F.Ode(T[m], x_m, f); - - // b = f + f_x x_m - alpha[0] x_0 - ... - alpha[m-1] x_{m-1} - for(i = 0; i < n; i++) - { b[i] = f[i]; - for(j = 0; j < n; j++) - b[i] -= f_x[i * n + j] * x_m[j]; - for(j = 0; j < m; j++) - b[i] -= alpha[j] * X[ j * n + i ]; - } - LuInvert(ip, jp, A, b); - x_m = b; - } - - // return estimate for x( t[k] ) and the estimated error bound - for(i = 0; i < n; i++) - { X[m * n + i] = x_m[i]; - e[i] = x_m[i] - x_m0[i]; - if( e[i] < zero ) - e[i] = - e[i]; - } -} - -} // End CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/ode_gear_control.hpp b/external/cppad/include/cppad/utility/ode_gear_control.hpp deleted file mode 100644 index 59735f3bf..000000000 --- a/external/cppad/include/cppad/utility/ode_gear_control.hpp +++ /dev/null @@ -1,542 +0,0 @@ -# ifndef CPPAD_UTILITY_ODE_GEAR_CONTROL_HPP -# define CPPAD_UTILITY_ODE_GEAR_CONTROL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin OdeGearControl$$ -$spell - cppad.hpp - CppAD - xf - xi - smin - smax - eabs - ef - maxabs - nstep - tf - sini - erel - dep - const - tb - ta - exp -$$ - - - -$section An Error Controller for Gear's Ode Solvers$$ -$mindex OdeGearControl Gear differential equation$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%xf% = OdeGearControl(%F%, %M%, %ti%, %tf%, %xi%, - %smin%, %smax%, %sini%, %eabs%, %erel%, %ef% , %maxabs%, %nstep% )%$$ - - -$head Purpose$$ -Let $latex \B{R}$$ denote the real numbers -and let $latex f : \B{R} \times \B{R}^n \rightarrow \B{R}^n$$ be a smooth function. -We define $latex X : [ti , tf] \rightarrow \B{R}^n$$ by -the following initial value problem: -$latex \[ -\begin{array}{rcl} - X(ti) & = & xi \\ - X'(t) & = & f[t , X(t)] -\end{array} -\] $$ -The routine $cref OdeGear$$ is a stiff multi-step method that -can be used to approximate the solution to this equation. -The routine $code OdeGearControl$$ sets up this multi-step method -and controls the error during such an approximation. - -$head Include$$ -The file $code cppad/ode_gear_control.hpp$$ -is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Notation$$ -The template parameter types $cref/Scalar/OdeGearControl/Scalar/$$ and -$cref/Vector/OdeGearControl/Vector/$$ are documented below. - -$head xf$$ -The return value $icode xf$$ has the prototype -$codei% - %Vector% %xf% -%$$ -and the size of $icode xf$$ is equal to $icode n$$ -(see description of $cref/Vector/OdeGear/Vector/$$ below). -It is the approximation for $latex X(tf)$$. - -$head Fun$$ -The class $icode Fun$$ -and the object $icode F$$ satisfy the prototype -$codei% - %Fun% &%F% -%$$ -This must support the following set of calls -$codei% - %F%.Ode(%t%, %x%, %f%) - %F%.Ode_dep(%t%, %x%, %f_x%) -%$$ - -$subhead t$$ -The argument $icode t$$ has prototype -$codei% - const %Scalar% &%t% -%$$ -(see description of $cref/Scalar/OdeGear/Scalar/$$ below). - -$subhead x$$ -The argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -and has size $icode N$$ -(see description of $cref/Vector/OdeGear/Vector/$$ below). - -$subhead f$$ -The argument $icode f$$ to $icode%F%.Ode%$$ has prototype -$codei% - %Vector% &%f% -%$$ -On input and output, $icode f$$ is a vector of size $icode N$$ -and the input values of the elements of $icode f$$ do not matter. -On output, -$icode f$$ is set equal to $latex f(t, x)$$ -(see $icode f(t, x)$$ in $cref/Purpose/OdeGear/Purpose/$$). - -$subhead f_x$$ -The argument $icode f_x$$ has prototype -$codei% - %Vector% &%f_x% -%$$ -On input and output, $icode f_x$$ is a vector of size $latex N * N$$ -and the input values of the elements of $icode f_x$$ do not matter. -On output, -$latex \[ - f\_x [i * n + j] = \partial_{x(j)} f_i ( t , x ) -\] $$ - -$subhead Warning$$ -The arguments $icode f$$, and $icode f_x$$ -must have a call by reference in their prototypes; i.e., -do not forget the $code &$$ in the prototype for -$icode f$$ and $icode f_x$$. - -$head M$$ -The argument $icode M$$ has prototype -$codei% - size_t %M% -%$$ -It specifies the order of the multi-step method; i.e., -the order of the approximating polynomial -(after the initialization process). -The argument $icode M$$ must greater than or equal one. - -$head ti$$ -The argument $icode ti$$ has prototype -$codei% - const %Scalar% &%ti% -%$$ -It specifies the initial time for the integration of -the differential equation. - -$head tf$$ -The argument $icode tf$$ has prototype -$codei% - const %Scalar% &%tf% -%$$ -It specifies the final time for the integration of -the differential equation. - -$head xi$$ -The argument $icode xi$$ has prototype -$codei% - const %Vector% &%xi% -%$$ -and size $icode n$$. -It specifies value of $latex X(ti)$$. - -$head smin$$ -The argument $icode smin$$ has prototype -$codei% - const %Scalar% &%smin% -%$$ -The minimum value of $latex T[M] - T[M-1]$$ in a call to $code OdeGear$$ -will be $latex smin$$ except for the last two calls where it may be -as small as $latex smin / 2$$. -The value of $icode smin$$ must be less than or equal $icode smax$$. - -$head smax$$ -The argument $icode smax$$ has prototype -$codei% - const %Scalar% &%smax% -%$$ -It specifies the maximum step size to use during the integration; -i.e., the maximum value for $latex T[M] - T[M-1]$$ -in a call to $code OdeGear$$. - -$head sini$$ -The argument $icode sini$$ has prototype -$codei% - %Scalar% &%sini% -%$$ -The value of $icode sini$$ is the minimum -step size to use during initialization of the multi-step method; i.e., -for calls to $code OdeGear$$ where $latex m < M$$. -The value of $icode sini$$ must be less than or equal $icode smax$$ -(and can also be less than $icode smin$$). - -$head eabs$$ -The argument $icode eabs$$ has prototype -$codei% - const %Vector% &%eabs% -%$$ -and size $icode n$$. -Each of the elements of $icode eabs$$ must be -greater than or equal zero. -It specifies a bound for the absolute -error in the return value $icode xf$$ as an approximation for $latex X(tf)$$. -(see the -$cref/error criteria discussion/OdeGearControl/Error Criteria Discussion/$$ -below). - -$head erel$$ -The argument $icode erel$$ has prototype -$codei% - const %Scalar% &%erel% -%$$ -and is greater than or equal zero. -It specifies a bound for the relative -error in the return value $icode xf$$ as an approximation for $latex X(tf)$$ -(see the -$cref/error criteria discussion/OdeGearControl/Error Criteria Discussion/$$ -below). - -$head ef$$ -The argument value $icode ef$$ has prototype -$codei% - %Vector% &%ef% -%$$ -and size $icode n$$. -The input value of its elements does not matter. -On output, -it contains an estimated bound for the -absolute error in the approximation $icode xf$$; i.e., -$latex \[ - ef_i > | X( tf )_i - xf_i | -\] $$ - -$head maxabs$$ -The argument $icode maxabs$$ is optional in the call to $code OdeGearControl$$. -If it is present, it has the prototype -$codei% - %Vector% &%maxabs% -%$$ -and size $icode n$$. -The input value of its elements does not matter. -On output, -it contains an estimate for the -maximum absolute value of $latex X(t)$$; i.e., -$latex \[ - maxabs[i] \approx \max \left\{ - | X( t )_i | \; : \; t \in [ti, tf] - \right\} -\] $$ - -$head nstep$$ -The argument $icode nstep$$ has the prototype -$codei% - %size_t% &%nstep% -%$$ -Its input value does not matter and its output value -is the number of calls to $cref OdeGear$$ -used by $code OdeGearControl$$. - -$head Error Criteria Discussion$$ -The relative error criteria $icode erel$$ and -absolute error criteria $icode eabs$$ are enforced during each step of the -integration of the ordinary differential equations. -In addition, they are inversely scaled by the step size so that -the total error bound is less than the sum of the error bounds. -To be specific, if $latex \tilde{X} (t)$$ is the approximate solution -at time $latex t$$, -$icode ta$$ is the initial step time, -and $icode tb$$ is the final step time, -$latex \[ -\left| \tilde{X} (tb)_j - X (tb)_j \right| -\leq -\frac{tf - ti}{tb - ta} -\left[ eabs[j] + erel \; | \tilde{X} (tb)_j | \right] -\] $$ -If $latex X(tb)_j$$ is near zero for some $latex tb \in [ti , tf]$$, -and one uses an absolute error criteria $latex eabs[j]$$ of zero, -the error criteria above will force $code OdeGearControl$$ -to use step sizes equal to -$cref/smin/OdeGearControl/smin/$$ -for steps ending near $latex tb$$. -In this case, the error relative to $icode maxabs$$ can be judged after -$code OdeGearControl$$ returns. -If $icode ef$$ is to large relative to $icode maxabs$$, -$code OdeGearControl$$ can be called again -with a smaller value of $icode smin$$. - -$head Scalar$$ -The type $icode Scalar$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, the following operations must be defined for -$icode Scalar$$ objects $icode a$$ and $icode b$$: - -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$icode%a% <= %b%$$ $cnext - returns true (false) if $icode a$$ is less than or equal - (greater than) $icode b$$. -$rnext -$icode%a% == %b%$$ $cnext - returns true (false) if $icode a$$ is equal to $icode b$$. -$rnext -$codei%log(%a%)%$$ $cnext - returns a $icode Scalar$$ equal to the logarithm of $icode a$$ -$rnext -$codei%exp(%a%)%$$ $cnext - returns a $icode Scalar$$ equal to the exponential of $icode a$$ -$tend - - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Scalar/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Example$$ -$children% - example/utility/ode_gear_control.cpp -%$$ -The file -$cref ode_gear_control.cpp$$ -contains an example and test a test of using this routine. -It returns true if it succeeds and false otherwise. - -$head Theory$$ -Let $latex e(s)$$ be the error as a function of the -step size $latex s$$ and suppose that there is a constant -$latex K$$ such that $latex e(s) = K s^m$$. -Let $latex a$$ be our error bound. -Given the value of $latex e(s)$$, a step of size $latex \lambda s$$ -would be ok provided that -$latex \[ -\begin{array}{rcl} - a & \geq & e( \lambda s ) (tf - ti) / ( \lambda s ) \\ - a & \geq & K \lambda^m s^m (tf - ti) / ( \lambda s ) \\ - a & \geq & \lambda^{m-1} s^{m-1} (tf - ti) e(s) / s^m \\ - a & \geq & \lambda^{m-1} (tf - ti) e(s) / s \\ - \lambda^{m-1} & \leq & \frac{a}{e(s)} \frac{s}{tf - ti} -\end{array} -\] $$ -Thus if the right hand side of the last inequality is greater -than or equal to one, the step of size $latex s$$ is ok. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/ode_gear_control.hpp$$. - -$end --------------------------------------------------------------------------- -*/ - -// link exp and log for float and double -# include - -# include - -namespace CppAD { // Begin CppAD namespace - -template -Vector OdeGearControl( - Fun &F , - size_t M , - const Scalar &ti , - const Scalar &tf , - const Vector &xi , - const Scalar &smin , - const Scalar &smax , - Scalar &sini , - const Vector &eabs , - const Scalar &erel , - Vector &ef , - Vector &maxabs, - size_t &nstep ) -{ - // check simple vector class specifications - CheckSimpleVector(); - - // dimension of the state space - size_t n = size_t(xi.size()); - - CPPAD_ASSERT_KNOWN( - M >= 1, - "Error in OdeGearControl: M is less than one" - ); - CPPAD_ASSERT_KNOWN( - smin <= smax, - "Error in OdeGearControl: smin is greater than smax" - ); - CPPAD_ASSERT_KNOWN( - sini <= smax, - "Error in OdeGearControl: sini is greater than smax" - ); - CPPAD_ASSERT_KNOWN( - size_t(eabs.size()) == n, - "Error in OdeGearControl: size of eabs is not equal to n" - ); - CPPAD_ASSERT_KNOWN( - size_t(maxabs.size()) == n, - "Error in OdeGearControl: size of maxabs is not equal to n" - ); - - // some constants - const Scalar zero(0); - const Scalar one(1); - const Scalar one_plus( Scalar(3) / Scalar(2) ); - const Scalar two(2); - const Scalar ten(10); - - // temporary indices - size_t i, k; - - // temporary Scalars - Scalar step, sprevious, lambda, axi, a, root, r; - - // vectors of Scalars - Vector T (M + 1); - Vector X( (M + 1) * n ); - Vector e(n); - Vector xf(n); - - // initial integer values - size_t m = 1; - nstep = 0; - - // initialize T - T[0] = ti; - - // initialize X, ef, maxabs - for(i = 0; i < n; i++) - for(i = 0; i < n; i++) - { X[i] = xi[i]; - ef[i] = zero; - X[i] = xi[i]; - if( zero <= xi[i] ) - maxabs[i] = xi[i]; - else maxabs[i] = - xi[i]; - - } - - // initial step size - step = smin; - - while( T[m-1] < tf ) - { sprevious = step; - - // check maximum - if( smax <= step ) - step = smax; - - // check minimum - if( m < M ) - { if( step <= sini ) - step = sini; - } - else if( step <= smin ) - step = smin; - - // check if near the end - if( tf <= T[m-1] + one_plus * step ) - T[m] = tf; - else T[m] = T[m-1] + step; - - // try using this step size - nstep++; - OdeGear(F, m, n, T, X, e); - step = T[m] - T[m-1]; - - // compute value of lambda for this step - lambda = Scalar(10) * sprevious / step; - for(i = 0; i < n; i++) - { axi = X[m * n + i]; - if( axi <= zero ) - axi = - axi; - a = eabs[i] + erel * axi; - if( e[i] > zero ) - { if( m == 1 ) - root = (a / e[i]) / ten; - else - { r = ( a / e[i] ) * step / (tf - ti); - root = exp( log(r) / Scalar(m-1) ); - } - if( root <= lambda ) - lambda = root; - } - } - - bool advance; - if( m == M ) - advance = one <= lambda || step <= one_plus * smin; - else advance = one <= lambda || step <= one_plus * sini; - - - if( advance ) - { // accept the results of this time step - CPPAD_ASSERT_UNKNOWN( m <= M ); - if( m == M ) - { // shift for next step - for(k = 0; k < m; k++) - { T[k] = T[k+1]; - for(i = 0; i < n; i++) - X[k*n + i] = X[(k+1)*n + i]; - } - } - // update ef and maxabs - for(i = 0; i < n; i++) - { ef[i] = ef[i] + e[i]; - axi = X[m * n + i]; - if( axi <= zero ) - axi = - axi; - if( axi > maxabs[i] ) - maxabs[i] = axi; - } - if( m != M ) - m++; // all we need do in this case - } - - // new step suggested by error criteria - step = std::min(lambda , ten) * step / two; - } - for(i = 0; i < n; i++) - xf[i] = X[(m-1) * n + i]; - - return xf; -} - -} // End CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/omp_alloc.hpp b/external/cppad/include/cppad/utility/omp_alloc.hpp deleted file mode 100644 index 5487bfcdc..000000000 --- a/external/cppad/include/cppad/utility/omp_alloc.hpp +++ /dev/null @@ -1,783 +0,0 @@ -// $Id: omp_alloc.hpp 3804 2016-03-20 15:08:46Z bradbell $ -# ifndef CPPAD_UTILITY_OMP_ALLOC_HPP -# define CPPAD_UTILITY_OMP_ALLOC_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -# include -# ifdef _OPENMP -# include -# endif - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -class omp_alloc{ -// ============================================================================ -public: -/* -$begin omp_max_num_threads$$ -$spell - cppad.hpp - inv - CppAD - num - omp_alloc -$$ -$section Set and Get Maximum Number of Threads for omp_alloc Allocator$$ - -$head Deprecated 2011-08-31$$ -Use the functions $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$ -and $cref/thread_alloc:num_threads/ta_num_threads/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$codei%omp_alloc::set_max_num_threads(%number%) -%$$ -$icode%number% = omp_alloc::get_max_num_threads() -%$$ - -$head Purpose$$ -By default there is only one thread and all execution is in sequential mode -(not $cref/parallel/omp_in_parallel/$$). - -$head number$$ -The argument and return value $icode number$$ has prototype -$codei% - size_t %number% -%$$ -and must be greater than zero. - -$head set_max_num_threads$$ -Informs $cref omp_alloc$$ of the maximum number of OpenMP threads. - -$head get_max_num_threads$$ -Returns the valued used in the previous call to $code set_max_num_threads$$. -If there was no such previous call, the value one is returned -(and only thread number zero can use $cref omp_alloc$$). - -$head Restrictions$$ -The function $code set_max_num_threads$$ must be called before -the program enters $cref/parallel/omp_in_parallel/$$ execution mode. -In addition, this function cannot be called while in parallel mode. - -$end -*/ - /*! - Inform omp_alloc of the maximum number of OpenMP threads and enable - parallel execution mode by initializing all statics in this file. - - \param number [in] - maximum number of OpenMP threads. - */ - static void set_max_num_threads(size_t number) - { thread_alloc::parallel_setup( - number, omp_alloc::in_parallel, omp_alloc::get_thread_num - ); - thread_alloc::hold_memory(number > 1); - } - /*! - Get the current maximum number of OpenMP threads that omp_alloc can use. - - \return - maximum number of OpenMP threads. - */ - static size_t get_max_num_threads(void) - { return thread_alloc::num_threads(); } - -/* ----------------------------------------------------------------------- -$begin omp_in_parallel$$ - -$section Is The Current Execution in OpenMP Parallel Mode$$ -$mindex in_parallel$$ -$spell - cppad.hpp - omp_alloc - bool -$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::in_parallel/ta_in_parallel/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$icode%flag% = omp_alloc::in_parallel()%$$ - -$head Purpose$$ -Some of the $cref omp_alloc$$ allocation routines have different -specifications for parallel (not sequential) execution mode. -This routine enables you to determine if the current execution mode -is sequential or parallel. - -$head flag$$ -The return value has prototype -$codei% - bool %flag% -%$$ -It is true if the current execution is in parallel mode -(possibly multi-threaded) and false otherwise (sequential mode). - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /// Are we in a parallel execution state; i.e., is it possible that - /// other threads are currently executing. - static bool in_parallel(void) - { -# ifdef _OPENMP - return omp_in_parallel() != 0; -# else - return false; -# endif - } - -/* ----------------------------------------------------------------------- -$begin omp_get_thread_num$$ -$spell - cppad.hpp - CppAD - num - omp_alloc - cppad.hpp -$$ - -$section Get the Current OpenMP Thread Number$$ -$mindex get_thread_num$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::thread_num/ta_thread_num/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$icode%thread% = omp_alloc::get_thread_num()%$$ - -$head Purpose$$ -Some of the $cref omp_alloc$$ allocation routines have a thread number. -This routine enables you to determine the current thread. - -$head thread$$ -The return value $icode thread$$ has prototype -$codei% - size_t %thread% -%$$ -and is the currently executing thread number. -If $code _OPENMP$$ is not defined, $icode thread$$ is zero. - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /// Get current OpenMP thread number (zero if _OpenMP not defined). - static size_t get_thread_num(void) - { -# ifdef _OPENMP - size_t thread = static_cast( omp_get_thread_num() ); - return thread; -# else - return 0; -# endif - } -/* ----------------------------------------------------------------------- -$begin omp_get_memory$$ -$spell - cppad.hpp - num - ptr - omp_alloc -$$ - -$section Get At Least A Specified Amount of Memory$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::get_memory/ta_get_memory/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$icode%v_ptr% = omp_alloc::get_memory(%min_bytes%, %cap_bytes%)%$$ - -$head Purpose$$ -Use $cref omp_alloc$$ to obtain a minimum number of bytes of memory -(for use by the $cref/current thread/omp_get_thread_num/$$). - -$head min_bytes$$ -This argument has prototype -$codei% - size_t %min_bytes% -%$$ -It specifies the minimum number of bytes to allocate. - -$head cap_bytes$$ -This argument has prototype -$codei% - size_t& %cap_bytes% -%$$ -It's input value does not matter. -Upon return, it is the actual number of bytes (capacity) -that have been allocated for use, -$codei% - %min_bytes% <= %cap_bytes% -%$$ - -$head v_ptr$$ -The return value $icode v_ptr$$ has prototype -$codei% - void* %v_ptr% -%$$ -It is the location where the $icode cap_bytes$$ of memory -that have been allocated for use begins. - -$head Allocation Speed$$ -This allocation should be faster if the following conditions hold: -$list number$$ -The memory allocated by a previous call to $code get_memory$$ -is currently available for use. -$lnext -The current $icode min_bytes$$ is between -the previous $icode min_bytes$$ and previous $icode cap_bytes$$. -$lend - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Use omp_alloc to get a specified amount of memory. - - If the memory allocated by a previous call to \c get_memory is now - avaialable, and \c min_bytes is between its previous value - and the previous \c cap_bytes, this memory allocation will have - optimal speed. Otherwise, the memory allocation is more complicated and - may have to wait for other threads to complete an allocation. - - \param min_bytes [in] - The minimum number of bytes of memory to be obtained for use. - - \param cap_bytes [out] - The actual number of bytes of memory obtained for use. - - \return - pointer to the beginning of the memory allocted for use. - */ - static void* get_memory(size_t min_bytes, size_t& cap_bytes) - { return thread_alloc::get_memory(min_bytes, cap_bytes); } - -/* ----------------------------------------------------------------------- -$begin omp_return_memory$$ -$spell - cppad.hpp - ptr - omp_alloc -$$ - -$section Return Memory to omp_alloc$$ -$mindex return_memory$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::return_memory/ta_return_memory/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$codei%omp_alloc::return_memory(%v_ptr%)%$$ - -$head Purpose$$ -If $cref omp_max_num_threads$$ is one, -the memory is returned to the system. -Otherwise, the memory is retained by $cref omp_alloc$$ for quick future use -by the thread that allocated to memory. - -$head v_ptr$$ -This argument has prototype -$codei% - void* %v_ptr% -%$$. -It must be a pointer to memory that is currently in use; i.e. -obtained by a previous call to $cref omp_get_memory$$ and not yet returned. - -$head Thread$$ -Either the $cref/current thread/omp_get_thread_num/$$ must be the same as during -the corresponding call to $cref omp_get_memory$$, -or the current execution mode must be sequential -(not $cref/parallel/omp_in_parallel/$$). - -$head NDEBUG$$ -If $code NDEBUG$$ is defined, $icode v_ptr$$ is not checked (this is faster). -Otherwise, a list of in use pointers is searched to make sure -that $icode v_ptr$$ is in the list. - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Return memory that was obtained by \c get_memory. - If max_num_threads(0) == 1, - the memory is returned to the system. - Otherwise, it is retained by \c omp_alloc and available for use by - \c get_memory for this thread. - - \param v_ptr [in] - Value of the pointer returned by \c get_memory and still in use. - After this call, this pointer will available (and not in use). - - \par - We must either be in sequential (not parallel) execution mode, - or the current thread must be the same as for the corresponding call - to \c get_memory. - */ - static void return_memory(void* v_ptr) - { thread_alloc::return_memory(v_ptr); } -/* ----------------------------------------------------------------------- -$begin omp_free_available$$ -$spell - cppad.hpp - omp_alloc -$$ - -$section Free Memory Currently Available for Quick Use by a Thread$$ -$mindex free_available$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::free_available/ta_free_available/$$ -instead. - -$head Syntax$$ -$codei%# include -%$$ -$codei%omp_alloc::free_available(%thread%)%$$ - -$head Purpose$$ -Free memory, currently available for quick use by a specific thread, -for general future use. - -$head thread$$ -This argument has prototype -$codei% - size_t %thread% -%$$ -Either $cref omp_get_thread_num$$ must be the same as $icode thread$$, -or the current execution mode must be sequential -(not $cref/parallel/omp_in_parallel/$$). - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Return all the memory being held as available for a thread to the system. - - \param thread [in] - this thread that will no longer have any available memory after this call. - This must either be the thread currently executing, or we must be - in sequential (not parallel) execution mode. - */ - static void free_available(size_t thread) - { thread_alloc::free_available(thread); } -/* ----------------------------------------------------------------------- -$begin omp_inuse$$ -$spell - cppad.hpp - num - inuse - omp_alloc -$$ - -$section Amount of Memory a Thread is Currently Using$$ -$mindex inuse$$ - -$head Deprecated 2011-08-31$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%num_bytes% = omp_alloc::inuse(%thread%)%$$ -Use the function $cref/thread_alloc::inuse/ta_inuse/$$ instead. - -$head Purpose$$ -Memory being managed by $cref omp_alloc$$ has two states, -currently in use by the specified thread, -and quickly available for future use by the specified thread. -This function informs the program how much memory is in use. - -$head thread$$ -This argument has prototype -$codei% - size_t %thread% -%$$ -Either $cref omp_get_thread_num$$ must be the same as $icode thread$$, -or the current execution mode must be sequential -(not $cref/parallel/omp_in_parallel/$$). - -$head num_bytes$$ -The return value has prototype -$codei% - size_t %num_bytes% -%$$ -It is the number of bytes currently in use by the specified thread. - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Determine the amount of memory that is currently inuse. - - \param thread [in] - Thread for which we are determining the amount of memory - (must be < CPPAD_MAX_NUM_THREADS). - Durring parallel execution, this must be the thread - that is currently executing. - - \return - The amount of memory in bytes. - */ - static size_t inuse(size_t thread) - { return thread_alloc::inuse(thread); } -/* ----------------------------------------------------------------------- -$begin omp_available$$ -$spell - cppad.hpp - num - omp_alloc -$$ - -$section Amount of Memory Available for Quick Use by a Thread$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::available/ta_available/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$icode%num_bytes% = omp_alloc::available(%thread%)%$$ - -$head Purpose$$ -Memory being managed by $cref omp_alloc$$ has two states, -currently in use by the specified thread, -and quickly available for future use by the specified thread. -This function informs the program how much memory is available. - -$head thread$$ -This argument has prototype -$codei% - size_t %thread% -%$$ -Either $cref omp_get_thread_num$$ must be the same as $icode thread$$, -or the current execution mode must be sequential -(not $cref/parallel/omp_in_parallel/$$). - -$head num_bytes$$ -The return value has prototype -$codei% - size_t %num_bytes% -%$$ -It is the number of bytes currently available for use by the specified thread. - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Determine the amount of memory that is currently available for use. - - \copydetails inuse - */ - static size_t available(size_t thread) - { return thread_alloc::available(thread); } -/* ----------------------------------------------------------------------- -$begin omp_create_array$$ -$spell - cppad.hpp - omp_alloc - sizeof -$$ - -$section Allocate Memory and Create A Raw Array$$ -$mindex create_array$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::create_array/ta_create_array/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$icode%array% = omp_alloc::create_array<%Type%>(%size_min%, %size_out%)%$$. - -$head Purpose$$ -Create a new raw array using $cref omp_alloc$$ a fast memory allocator -that works well in a multi-threading OpenMP environment. - -$head Type$$ -The type of the elements of the array. - -$head size_min$$ -This argument has prototype -$codei% - size_t %size_min% -%$$ -This is the minimum number of elements that there can be -in the resulting $icode array$$. - -$head size_out$$ -This argument has prototype -$codei% - size_t& %size_out% -%$$ -The input value of this argument does not matter. -Upon return, it is the actual number of elements -in $icode array$$ -($icode% size_min %<=% size_out%$$). - -$head array$$ -The return value $icode array$$ has prototype -$codei% - %Type%* %array% -%$$ -It is array with $icode size_out$$ elements. -The default constructor for $icode Type$$ is used to initialize the -elements of $icode array$$. -Note that $cref omp_delete_array$$ -should be used to destroy the array when it is no longer needed. - -$head Delta$$ -The amount of memory $cref omp_inuse$$ by the current thread, -will increase $icode delta$$ where -$codei% - sizeof(%Type%) * (%size_out% + 1) > %delta% >= sizeof(%Type%) * %size_out% -%$$ -The $cref omp_available$$ memory will decrease by $icode delta$$, -(and the allocation will be faster) -if a previous allocation with $icode size_min$$ between its current value -and $icode size_out$$ is available. - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Use omp_alloc to Create a Raw Array. - - \tparam Type - The type of the elements of the array. - - \param size_min [in] - The minimum number of elements in the array. - - \param size_out [out] - The actual number of elements in the array. - - \return - pointer to the first element of the array. - The default constructor is used to initialize - all the elements of the array. - - \par - The \c extra_ field, in the \c omp_alloc node before the return value, - is set to size_out. - */ - template - static Type* create_array(size_t size_min, size_t& size_out) - { return thread_alloc::create_array(size_min, size_out); } -/* ----------------------------------------------------------------------- -$begin omp_delete_array$$ -$spell - cppad.hpp - omp_alloc - sizeof -$$ - -$section Return A Raw Array to The Available Memory for a Thread$$ -$mindex delete_array$$ - -$head Deprecated 2011-08-31$$ -Use the function $cref/thread_alloc::delete_array/ta_delete_array/$$ instead. - -$head Syntax$$ -$codei%# include -%$$ -$codei%omp_alloc::delete_array(%array%)%$$. - -$head Purpose$$ -Returns memory corresponding to a raw array -(create by $cref omp_create_array$$) to the -$cref omp_available$$ memory pool for the current thread. - -$head Type$$ -The type of the elements of the array. - -$head array$$ -The argument $icode array$$ has prototype -$codei% - %Type%* %array% -%$$ -It is a value returned by $cref omp_create_array$$ and not yet deleted. -The $icode Type$$ destructor is called for each element in the array. - -$head Thread$$ -The $cref/current thread/omp_get_thread_num/$$ must be the -same as when $cref omp_create_array$$ returned the value $icode array$$. -There is an exception to this rule: -when the current execution mode is sequential -(not $cref/parallel/omp_in_parallel/$$) the current thread number does not matter. - -$head Delta$$ -The amount of memory $cref omp_inuse$$ will decrease by $icode delta$$, -and the $cref omp_available$$ memory will increase by $icode delta$$, -where $cref/delta/omp_create_array/Delta/$$ -is the same as for the corresponding call to $code create_array$$. - -$head Example$$ -$cref omp_alloc.cpp$$ - -$end -*/ - /*! - Return Memory Used for a Raw Array to the Available Pool. - - \tparam Type - The type of the elements of the array. - - \param array [in] - A value returned by \c create_array that has not yet been deleted. - The \c Type destructor is used to destroy each of the elements - of the array. - - \par - Durring parallel execution, the current thread must be the same - as during the corresponding call to \c create_array. - */ - template - static void delete_array(Type* array) - { thread_alloc::delete_array(array); } -}; -/* -------------------------------------------------------------------------- -$begin omp_efficient$$ -$spell - cppad.hpp - omp_alloc - ptr - num - bool - const -$$ - -$section Check If A Memory Allocation is Efficient for Another Use$$ - -$head Removed$$ -This function has been removed because speed tests seem to indicate -it is just as fast, or faster, to free and then reallocate the memory. - -$head Syntax$$ -$codei%# include -%$$ -$icode%flag% = omp_alloc::efficient(%v_ptr%, %num_bytes%)%$$ - -$head Purpose$$ -Check if memory that is currently in use is an efficient -allocation for a specified number of bytes. - -$head v_ptr$$ -This argument has prototype -$codei% - const void* %v_ptr% -%$$. -It must be a pointer to memory that is currently in use; i.e. -obtained by a previous call to $cref omp_get_memory$$ and not yet returned. - -$head num_bytes$$ -This argument has prototype -$codei% - size_t %num_bytes% -%$$ -It specifies the number of bytes of the memory allocated by $icode v_ptr$$ -that we want to use. - -$head flag$$ -The return value has prototype -$codei% - bool %flag% -%$$ -It is true, -a call to $code get_memory$$ with -$cref/min_bytes/omp_get_memory/min_bytes/$$ -equal to $icode num_bytes$$ would result in a value for -$cref/cap_bytes/omp_get_memory/cap_bytes/$$ that is the same as when $code v_ptr$$ -was returned by $code get_memory$$; i.e., -$icode v_ptr$$ is an efficient memory block for $icode num_bytes$$ -bytes of information. - -$head Thread$$ -Either the $cref/current thread/omp_get_thread_num/$$ must be the same as during -the corresponding call to $cref omp_get_memory$$, -or the current execution mode must be sequential -(not $cref/parallel/omp_in_parallel/$$). - -$head NDEBUG$$ -If $code NDEBUG$$ is defined, $icode v_ptr$$ is not checked (this is faster). -Otherwise, a list of in use pointers is searched to make sure -that $icode v_ptr$$ is in the list. - -$end ---------------------------------------------------------------------------- -$begin old_max_num_threads$$ -$spell - cppad.hpp - inv - CppAD - num - omp_alloc -$$ -$section Set Maximum Number of Threads for omp_alloc Allocator$$ -$mindex max_num_threads$$ - -$head Removed$$ -This function has been removed from the CppAD API. -Use the function $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$ -in its place. - -$head Syntax$$ -$codei%# include -%$$ -$codei%omp_alloc::max_num_threads(%number%)%$$ - -$head Purpose$$ -By default there is only one thread and all execution is in sequential mode -(not $cref/parallel/omp_in_parallel/$$). - -$head number$$ -The argument $icode number$$ has prototype -$codei% - size_t %number% -%$$ -It must be greater than zero and specifies the maximum number of -OpenMP threads that will be active at one time. - -$head Restrictions$$ -This function must be called before the program enters -$cref/parallel/omp_in_parallel/$$ execution mode. - -$end -------------------------------------------------------------------------------- -*/ -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/utility/poly.hpp b/external/cppad/include/cppad/utility/poly.hpp deleted file mode 100644 index abcf5d759..000000000 --- a/external/cppad/include/cppad/utility/poly.hpp +++ /dev/null @@ -1,193 +0,0 @@ -# ifndef CPPAD_UTILITY_POLY_HPP -# define CPPAD_UTILITY_POLY_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin Poly$$ -$spell - cppad.hpp - CppAD - namespace - cstddef - ifndef - endif - deg - const - std - da -$$ - - -$section Evaluate a Polynomial or its Derivative$$ -$mindex Poly template$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%p% = Poly(%k%, %a%, %z%)%$$ - - -$head Description$$ -Computes the $th k$$ derivative of the polynomial -$latex \[ - P(z) = a_0 + a_1 z^1 + \cdots + a_d z^d -\] $$ -If $icode k$$ is equal to zero, the return value is $latex P(z)$$. - -$head Include$$ -The file $code cppad/poly.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. -Including this file defines -$code Poly$$ within the $code CppAD$$ namespace. - -$head k$$ -The argument $icode k$$ has prototype -$codei% - size_t %k% -%$$ -It specifies the order of the derivative to calculate. - -$head a$$ -The argument $icode a$$ has prototype -$codei% - const %Vector% &%a% -%$$ -(see $cref/Vector/Poly/Vector/$$ below). -It specifies the vector corresponding to the polynomial $latex P(z)$$. - -$head z$$ -The argument $icode z$$ has prototype -$codei% - const %Type% &%z% -%$$ -(see $icode Type$$ below). -It specifies the point at which to evaluate the polynomial - -$head p$$ -The result $icode p$$ has prototype -$codei% - %Type% %p% -%$$ -(see $cref/Type/Poly/Type/$$ below) -and it is equal to the $th k$$ derivative of $latex P(z)$$; i.e., -$latex \[ -p = \frac{k !}{0 !} a_k - + \frac{(k+1) !}{1 !} a_{k+1} z^1 - + \ldots - + \frac{d !}{(d - k) !} a_d z^{d - k} -\] -$$ -If $latex k > d$$, $icode%p% = %Type%(0)%$$. - -$head Type$$ -The type $icode Type$$ is determined by the argument $icode z$$. -It is assumed that -multiplication and addition of $icode Type$$ objects -are commutative. - -$subhead Operations$$ -The following operations must be supported where -$icode x$$ and $icode y$$ are objects of type $icode Type$$ -and $icode i$$ is an $code int$$: -$table -$icode%x% = %i%$$ $cnext assignment $rnext -$icode%x% = %y%$$ $cnext assignment $rnext -$icode%x% *= %y%$$ $cnext multiplication compound assignment $rnext -$icode%x% += %y%$$ $cnext addition compound assignment - -$tend - - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type/SimpleVector/Elements of Specified Type/$$ -$icode Type$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Operation Sequence$$ -The $icode Type$$ operation sequence used to calculate $icode p$$ is -$cref/independent/glossary/Operation/Independent/$$ -of $icode z$$ and the elements of $icode a$$ -(it does depend on the size of the vector $icode a$$). - - -$children% - example/general/poly.cpp% - omh/poly_hpp.omh -%$$ - -$head Example$$ -The file -$cref poly.cpp$$ -contains an example and test of this routine. -It returns true if it succeeds and false otherwise. - -$head Source$$ -The file $cref poly.hpp$$ contains the -current source code that implements these specifications. - -$end ------------------------------------------------------------------------------- -*/ -// BEGIN C++ -# include // used to defined size_t -# include - -namespace CppAD { // BEGIN CppAD namespace - -template -Type Poly(size_t k, const Vector &a, const Type &z) -{ size_t i; - size_t d = a.size() - 1; - - Type tmp; - - // check Vector is Simple Vector class with Type elements - CheckSimpleVector(); - - // case where derivative order greater than degree of polynomial - if( k > d ) - { tmp = 0; - return tmp; - } - // case where we are evaluating a derivative - if( k > 0 ) - { // initialize factor as (k-1) ! - size_t factor = 1; - for(i = 2; i < k; i++) - factor *= i; - - // set b to coefficient vector corresponding to derivative - Vector b(d - k + 1); - for(i = k; i <= d; i++) - { factor *= i; - tmp = double( factor ); - b[i - k] = a[i] * tmp; - factor /= (i - k + 1); - } - // value of derivative polynomial - return Poly(0, b, z); - } - // case where we are evaluating the original polynomial - Type sum = a[d]; - i = d; - while(i > 0) - { sum *= z; - sum += a[--i]; - } - return sum; -} -} // END CppAD namespace -// END C++ -# endif diff --git a/external/cppad/include/cppad/utility/pow_int.hpp b/external/cppad/include/cppad/utility/pow_int.hpp deleted file mode 100644 index 6d3db0925..000000000 --- a/external/cppad/include/cppad/utility/pow_int.hpp +++ /dev/null @@ -1,141 +0,0 @@ -# ifndef CPPAD_UTILITY_POW_INT_HPP -# define CPPAD_UTILITY_POW_INT_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------------- -$begin pow_int$$ -$spell - cppad.hpp - CppAD - namespace - const -$$ - - -$section The Integer Power Function$$ -$mindex pow exponent$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%z% = pow(%x%, %y%)%$$ - -$head See Also$$ -$cref pow$$ - -$head Purpose$$ -Determines the value of the power function -$latex \[ - {\rm pow} (x, y) = x^y -\] $$ -for integer exponents $icode n$$ -using multiplication and possibly division to compute the value. -The other CppAD $cref pow$$ function may use logarithms and exponentiation -to compute derivatives of the same value -(which will not work if $icode x$$ is less than or equal zero). - -$head Include$$ -The file $code cppad/pow_int.h$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. -Including this file defines -this version of the $code pow$$ within the $code CppAD$$ namespace. - -$head x$$ -The argument $icode x$$ has prototype -$codei% - const %Type%& %x% -%$$ - -$head y$$ -The argument $icode y$$ has prototype -$codei% - const int& %y% -%$$ - -$head z$$ -The result $icode z$$ has prototype -$codei% - %Type% %z% -%$$ - -$head Type$$ -The type $icode Type$$ must support the following operations -where $icode a$$ and $icode b$$ are $icode Type$$ objects -and $icode i$$ is an $code int$$: -$table -$bold Operation$$ $pre $$ - $cnext $bold Description$$ - $cnext $bold Result Type$$ -$rnext -$icode%Type% %a%(%i%)%$$ - $cnext construction of a $icode Type$$ object from an $code int$$ - $cnext $icode Type$$ -$rnext -$icode%a% * %b%$$ - $cnext binary multiplication of $icode Type$$ objects - $cnext $icode Type$$ -$rnext -$icode%a% / %b%$$ - $cnext binary division of $icode Type$$ objects - $cnext $icode Type$$ -$tend - -$head Operation Sequence$$ -The $icode Type$$ operation sequence used to calculate $icode z$$ is -$cref/independent/glossary/Operation/Independent/$$ -of $icode x$$. - -$head Example$$ -$children% - example/general/pow_int.cpp -%$$ -The file $cref pow_int.cpp$$ -is an example and test of this function. -It returns true if it succeeds and false otherwise. - - -$end -------------------------------------------------------------------------------- -*/ - -namespace CppAD { - - template - inline Type pow (const Type& x, const int& n) - { - Type p(1); - int n2 = n / 2; - - if( n == 0 ) - return p; - if( n < 0 ) - return p / pow(x, -n); - if( n == 1 ) - return x; - - // p = (x^2)^(n/2) - p = pow( x * x , n2 ); - - // n is even case - if( n % 2 == 0 ) - return p; - - // n is odd case - return p * x; - } - -} - -# endif diff --git a/external/cppad/include/cppad/utility/romberg_mul.hpp b/external/cppad/include/cppad/utility/romberg_mul.hpp deleted file mode 100644 index a0335fa00..000000000 --- a/external/cppad/include/cppad/utility/romberg_mul.hpp +++ /dev/null @@ -1,326 +0,0 @@ -# ifndef CPPAD_UTILITY_ROMBERG_MUL_HPP -# define CPPAD_UTILITY_ROMBERG_MUL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin RombergMul$$ -$spell - cppad.hpp - bool - const - Cpp - RombergMulMul -$$ - -$section Multi-dimensional Romberg Integration$$ -$mindex integrate multi dimensional dimension$$ - - -$head Syntax$$ -$codei%# include -%$$ -$codei%RombergMul<%Fun%, %SizeVector%, %FloatVector%, %m%> %R%$$ -$pre -$$ -$icode%r% = %R%(%F%, %a%, %b%, %n%, %p%, %e%)%$$ - - -$head Description$$ -Returns the Romberg integration estimate -$latex r$$ for the multi-dimensional integral -$latex \[ -r = -\int_{a[0]}^{b[0]} \cdots \int_{a[m-1]}^{b[m-1]} -\; F(x) \; -{\bf d} x_0 \cdots {\bf d} x_{m-1} -\; + \; -\sum_{i=0}^{m-1} -O \left[ ( b[i] - a[i] ) / 2^{n[i]-1} \right]^{2(p[i]+1)} -\] $$ - -$head Include$$ -The file $code cppad/romberg_mul.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head m$$ -The template parameter $icode m$$ must be convertible to a $code size_t$$ -object with a value that can be determined at compile time; for example -$code 2$$. -It determines the dimension of the domain space for the integration. - -$head r$$ -The return value $icode r$$ has prototype -$codei% - %Float% %r% -%$$ -It is the estimate computed by $code RombergMul$$ for the integral above -(see description of $cref/Float/RombergMul/Float/$$ below). - -$head F$$ -The object $icode F$$ has the prototype -$codei% - %Fun% &%F% -%$$ -It must support the operation -$codei% - %F%(%x%) -%$$ -The argument $icode x$$ to $icode F$$ has prototype -$codei% - const %Float% &%x% -%$$ -The return value of $icode F$$ is a $icode Float$$ object - -$head a$$ -The argument $icode a$$ has prototype -$codei% - const %FloatVector% &%a% -%$$ -It specifies the lower limit for the integration -(see description of $cref/FloatVector/RombergMul/FloatVector/$$ below). - -$head b$$ -The argument $icode b$$ has prototype -$codei% - const %FloatVector% &%b% -%$$ -It specifies the upper limit for the integration. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - const %SizeVector% &%n% -%$$ -A total number of $latex 2^{n[i]-1} + 1$$ -evaluations of $icode%F%(%x%)%$$ are used to estimate the integral -with respect to $latex {\bf d} x_i$$. - -$head p$$ -The argument $icode p$$ has prototype -$codei% - const %SizeVector% &%p% -%$$ -For $latex i = 0 , \ldots , m-1$$, -$latex n[i]$$ determines the accuracy order in the -approximation for the integral -that is returned by $code RombergMul$$. -The values in $icode p$$ must be less than or equal $icode n$$; i.e., -$icode%p%[%i%] <= %n%[%i%]%$$. - -$head e$$ -The argument $icode e$$ has prototype -$codei% - %Float% &%e% -%$$ -The input value of $icode e$$ does not matter -and its output value is an approximation for the absolute error in -the integral estimate. - -$head Float$$ -The type $icode Float$$ is defined as the type of the elements of -$cref/FloatVector/RombergMul/FloatVector/$$. -The type $icode Float$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, if $icode x$$ and $icode y$$ are $icode Float$$ objects, -$codei% - %x% < %y% -%$$ -returns the $code bool$$ value true if $icode x$$ is less than -$icode y$$ and false otherwise. - -$head FloatVector$$ -The type $icode FloatVector$$ must be a $cref SimpleVector$$ class. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - - -$children% - example/utility/romberg_mul.cpp -%$$ -$head Example$$ -$comment% - example/utility/romberg_mul.cpp -%$$ -The file -$cref Rombergmul.cpp$$ -contains an example and test a test of using this routine. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/romberg_mul.hpp$$. - -$end -*/ - -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -template -class SliceLast { - typedef typename FloatVector::value_type Float; -private: - Fun *F; - size_t last; - FloatVector x; -public: - SliceLast( Fun *F_, size_t last_, const FloatVector &x_ ) - : F(F_) , last(last_), x(last + 1) - { size_t i; - for(i = 0; i < last; i++) - x[i] = x_[i]; - } - double operator()(const Float &xlast) - { x[last] = xlast; - return (*F)(x); - } -}; - -template -class IntegrateLast { -private: - Fun *F; - const size_t last; - const FloatVector a; - const FloatVector b; - const SizeVector n; - const SizeVector p; - Float esum; - size_t ecount; - -public: - IntegrateLast( - Fun *F_ , - size_t last_ , - const FloatVector &a_ , - const FloatVector &b_ , - const SizeVector &n_ , - const SizeVector &p_ ) - : F(F_) , last(last_), a(a_) , b(b_) , n(n_) , p(p_) - { } - Float operator()(const FloatVector &x) - { Float r, e; - SliceLast S(F, last, x); - r = CppAD::RombergOne( - S, a[last], b[last], n[last], p[last], e - ); - esum = esum + e; - ecount++; - return r; - } - void ClearEsum(void) - { esum = 0.; } - Float GetEsum(void) - { return esum; } - - void ClearEcount(void) - { ecount = 0; } - size_t GetEcount(void) - { return ecount; } -}; - -template -class RombergMul { - typedef typename FloatVector::value_type Float; -public: - RombergMul(void) - { } - Float operator() ( - Fun &F , - const FloatVector &a , - const FloatVector &b , - const SizeVector &n , - const SizeVector &p , - Float &e ) - { Float r; - - typedef IntegrateLast< - Fun , - SizeVector , - FloatVector , - Float > IntegrateOne; - - IntegrateOne Fm1(&F, m-1, a, b, n, p); - RombergMul< - IntegrateOne, - SizeVector , - FloatVector , - m-1 > RombergMulM1; - - Fm1.ClearEsum(); - Fm1.ClearEcount(); - - r = RombergMulM1(Fm1, a, b, n, p, e); - - size_t i, j; - Float prod = 1; - size_t pow2 = 1; - for(i = 0; i < m-1; i++) - { prod *= (b[i] - a[i]); - for(j = 0; j < (n[i] - 1); j++) - pow2 *= 2; - } - assert( Fm1.GetEcount() == (pow2+1) ); - - e = e + Fm1.GetEsum() * prod / Float( double(Fm1.GetEcount()) ); - - return r; - } -}; - -template -class RombergMul { - typedef typename FloatVector::value_type Float; -public: - Float operator() ( - Fun &F , - const FloatVector &a , - const FloatVector &b , - const SizeVector &n , - const SizeVector &p , - Float &e ) - { Float r; - typedef IntegrateLast< - Fun , - SizeVector , - FloatVector , - Float > IntegrateOne; - - // check simple vector class specifications - CheckSimpleVector(); - - // check numeric type specifications - CheckNumericType(); - - IntegrateOne F0(&F, 0, a, b, n, p); - - F0.ClearEsum(); - F0.ClearEcount(); - - r = F0(a); - - assert( F0.GetEcount() == 1 ); - e = F0.GetEsum(); - - return r; - } -}; - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/romberg_one.hpp b/external/cppad/include/cppad/utility/romberg_one.hpp deleted file mode 100644 index 47e7f5776..000000000 --- a/external/cppad/include/cppad/utility/romberg_one.hpp +++ /dev/null @@ -1,214 +0,0 @@ -# ifndef CPPAD_UTILITY_ROMBERG_ONE_HPP -# define CPPAD_UTILITY_ROMBERG_ONE_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin RombergOne$$ -$spell - cppad.hpp - bool - const - Cpp - RombergOne -$$ - -$section One DimensionalRomberg Integration$$ -$mindex integrate Romberg$$ - - -$head Syntax$$ -$codei%# include -%$$ -$icode%r% = RombergOne(%F%, %a%, %b%, %n%, %e%)%$$ - - -$head Description$$ -Returns the Romberg integration estimate -$latex r$$ for a one dimensional integral -$latex \[ -r = \int_a^b F(x) {\bf d} x + O \left[ (b - a) / 2^{n-1} \right]^{2(p+1)} -\] $$ - -$head Include$$ -The file $code cppad/romberg_one.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head r$$ -The return value $icode r$$ has prototype -$codei% - %Float% %r% -%$$ -It is the estimate computed by $code RombergOne$$ for the integral above. - -$head F$$ -The object $icode F$$ can be of any type, but it must support -the operation -$codei% - %F%(%x%) -%$$ -The argument $icode x$$ to $icode F$$ has prototype -$codei% - const %Float% &%x% -%$$ -The return value of $icode F$$ is a $icode Float$$ object -(see description of $cref/Float/RombergOne/Float/$$ below). - -$head a$$ -The argument $icode a$$ has prototype -$codei% - const %Float% &%a% -%$$ -It specifies the lower limit for the integration. - -$head b$$ -The argument $icode b$$ has prototype -$codei% - const %Float% &%b% -%$$ -It specifies the upper limit for the integration. - -$head n$$ -The argument $icode n$$ has prototype -$codei% - size_t %n% -%$$ -A total number of $latex 2^{n-1} + 1$$ evaluations of $icode%F%(%x%)%$$ -are used to estimate the integral. - -$head p$$ -The argument $icode p$$ has prototype -$codei% - size_t %p% -%$$ -It must be less than or equal $latex n$$ -and determines the accuracy order in the approximation for the integral -that is returned by $code RombergOne$$. -To be specific -$latex \[ -r = \int_a^b F(x) {\bf d} x + O \left[ (b - a) / 2^{n-1} \right]^{2(p+1)} -\] $$ - - -$head e$$ -The argument $icode e$$ has prototype -$codei% - %Float% &%e% -%$$ -The input value of $icode e$$ does not matter -and its output value is an approximation for the error in -the integral estimates; i.e., -$latex \[ - e \approx \left| r - \int_a^b F(x) {\bf d} x \right| -\] $$ - -$head Float$$ -The type $icode Float$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, if $icode x$$ and $icode y$$ are $icode Float$$ objects, -$codei% - %x% < %y% -%$$ -returns the $code bool$$ value true if $icode x$$ is less than -$icode y$$ and false otherwise. - -$children% - example/utility/romberg_one.cpp -%$$ -$head Example$$ -$comment% - example/utility/romberg_one.cpp -%$$ -The file -$cref romberg_one.cpp$$ -contains an example and test a test of using this routine. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/romberg_one.hpp$$. - -$end -*/ - -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -template -Float RombergOne( - Fun &F , - const Float &a , - const Float &b , - size_t n , - size_t p , - Float &e ) -{ - size_t ipow2 = 1; - size_t k, i; - Float pow2, sum, x; - - Float zero = Float(0); - Float two = Float(2); - - // check specifications for a NumericType - CheckNumericType(); - - CPPAD_ASSERT_KNOWN( - n >= 2, - "RombergOne: n must be greater than or equal 2" - ); - CppAD::vector r(n); - - // set r[i] = trapazoidal rule with 2^i intervals in [a, b] - r[0] = ( F(a) + F(b) ) * (b - a) / two; - for(i = 1; i < n; i++) - { ipow2 *= 2; - // there must be a conversion from int to any numeric type - pow2 = Float(int(ipow2)); - sum = zero; - for(k = 1; k < ipow2; k += 2) - { // start = a + (b-a)/pow2, increment = 2*(b-a)/pow2 - x = ( (pow2 - Float(double(k))) * a + double(k) * b ) / pow2; - sum = sum + F(x); - } - // combine function evaluations in sum with those in T[i-1] - r[i] = r[i-1] / two + sum * (b - a) / pow2; - } - - // now compute the higher order estimates - size_t ipow4 = 1; // order of accuract for previous estimate - Float pow4, pow4minus; - for(i = 0; i < p; i++) - { // compute estimate accurate to O[ step^(2*(i+1)) ] - // put resutls in r[n-1], r[n-2], ... , r[n-i+1] - ipow4 *= 4; - pow4 = Float(int(ipow4)); - pow4minus = Float(ipow4-1); - for(k = n-1; k > i; k--) - r[k] = ( pow4 * r[k] - r[k-1] ) / pow4minus; - } - - // error estimate for r[n] - e = r[n-1] - r[n-2]; - if( e < zero ) - e = - e; - return r[n-1]; -} - -} // END CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/rosen_34.hpp b/external/cppad/include/cppad/utility/rosen_34.hpp deleted file mode 100644 index 2729273d7..000000000 --- a/external/cppad/include/cppad/utility/rosen_34.hpp +++ /dev/null @@ -1,497 +0,0 @@ -# ifndef CPPAD_UTILITY_ROSEN_34_HPP -# define CPPAD_UTILITY_ROSEN_34_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Rosen34$$ -$spell - cppad.hpp - bool - xf - templated - const - Rosenbrock - CppAD - xi - ti - tf - Karp - Rosen - Shampine - ind - dep -$$ - - -$section A 3rd and 4th Order Rosenbrock ODE Solver$$ -$mindex Rosen34 solve stiff differential equation$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%xf% = Rosen34(%F%, %M%, %ti%, %tf%, %xi%) -%$$ -$icode%xf% = Rosen34(%F%, %M%, %ti%, %tf%, %xi%, %e%) -%$$ - - -$head Description$$ -This is an embedded 3rd and 4th order Rosenbrock ODE solver -(see Section 16.6 of $cref/Numerical Recipes/Bib/Numerical Recipes/$$ -for a description of Rosenbrock ODE solvers). -In particular, we use the formulas taken from page 100 of -$cref/Shampine, L.F./Bib/Shampine, L.F./$$ -(except that the fraction 98/108 has been correction to be 97/108). -$pre - -$$ -We use $latex n$$ for the size of the vector $icode xi$$. -Let $latex \B{R}$$ denote the real numbers -and let $latex F : \B{R} \times \B{R}^n \rightarrow \B{R}^n$$ be a smooth function. -The return value $icode xf$$ contains a 5th order -approximation for the value $latex X(tf)$$ where -$latex X : [ti , tf] \rightarrow \B{R}^n$$ is defined by -the following initial value problem: -$latex \[ -\begin{array}{rcl} - X(ti) & = & xi \\ - X'(t) & = & F[t , X(t)] -\end{array} -\] $$ -If your set of ordinary differential equations are not stiff -an explicit method may be better (perhaps $cref Runge45$$.) - -$head Include$$ -The file $code cppad/rosen_34.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head xf$$ -The return value $icode xf$$ has the prototype -$codei% - %Vector% %xf% -%$$ -and the size of $icode xf$$ is equal to $icode n$$ -(see description of $cref/Vector/Rosen34/Vector/$$ below). -$latex \[ - X(tf) = xf + O( h^5 ) -\] $$ -where $latex h = (tf - ti) / M$$ is the step size. -If $icode xf$$ contains not a number $cref nan$$, -see the discussion of $cref/f/Rosen34/Fun/Nan/$$. - -$head Fun$$ -The class $icode Fun$$ -and the object $icode F$$ satisfy the prototype -$codei% - %Fun% &%F% -%$$ -This must support the following set of calls -$codei% - %F%.Ode(%t%, %x%, %f%) - %F%.Ode_ind(%t%, %x%, %f_t%) - %F%.Ode_dep(%t%, %x%, %f_x%) -%$$ - -$subhead t$$ -In all three cases, -the argument $icode t$$ has prototype -$codei% - const %Scalar% &%t% -%$$ -(see description of $cref/Scalar/Rosen34/Scalar/$$ below). - -$subhead x$$ -In all three cases, -the argument $icode x$$ has prototype -$codei% - const %Vector% &%x% -%$$ -and has size $icode n$$ -(see description of $cref/Vector/Rosen34/Vector/$$ below). - -$subhead f$$ -The argument $icode f$$ to $icode%F%.Ode%$$ has prototype -$codei% - %Vector% &%f% -%$$ -On input and output, $icode f$$ is a vector of size $icode n$$ -and the input values of the elements of $icode f$$ do not matter. -On output, -$icode f$$ is set equal to $latex F(t, x)$$ -(see $icode F(t, x)$$ in $cref/Description/Rosen34/Description/$$). - -$subhead f_t$$ -The argument $icode f_t$$ to $icode%F%.Ode_ind%$$ has prototype -$codei% - %Vector% &%f_t% -%$$ -On input and output, $icode f_t$$ is a vector of size $icode n$$ -and the input values of the elements of $icode f_t$$ do not matter. -On output, the $th i$$ element of -$icode f_t$$ is set equal to $latex \partial_t F_i (t, x)$$ -(see $icode F(t, x)$$ in $cref/Description/Rosen34/Description/$$). - -$subhead f_x$$ -The argument $icode f_x$$ to $icode%F%.Ode_dep%$$ has prototype -$codei% - %Vector% &%f_x% -%$$ -On input and output, $icode f_x$$ is a vector of size $icode%n%*%n%$$ -and the input values of the elements of $icode f_x$$ do not matter. -On output, the [$icode%i%*%n%+%j%$$] element of -$icode f_x$$ is set equal to $latex \partial_{x(j)} F_i (t, x)$$ -(see $icode F(t, x)$$ in $cref/Description/Rosen34/Description/$$). - -$subhead Nan$$ -If any of the elements of $icode f$$, $icode f_t$$, or $icode f_x$$ -have the value not a number $code nan$$, -the routine $code Rosen34$$ returns with all the -elements of $icode xf$$ and $icode e$$ equal to $code nan$$. - -$subhead Warning$$ -The arguments $icode f$$, $icode f_t$$, and $icode f_x$$ -must have a call by reference in their prototypes; i.e., -do not forget the $code &$$ in the prototype for -$icode f$$, $icode f_t$$ and $icode f_x$$. - -$subhead Optimization$$ -Every call of the form -$codei% - %F%.Ode_ind(%t%, %x%, %f_t%) -%$$ -is directly followed by a call of the form -$codei% - %F%.Ode_dep(%t%, %x%, %f_x%) -%$$ -where the arguments $icode t$$ and $icode x$$ have not changed between calls. -In many cases it is faster to compute the values of $icode f_t$$ -and $icode f_x$$ together and then pass them back one at a time. - -$head M$$ -The argument $icode M$$ has prototype -$codei% - size_t %M% -%$$ -It specifies the number of steps -to use when solving the differential equation. -This must be greater than or equal one. -The step size is given by $latex h = (tf - ti) / M$$, thus -the larger $icode M$$, the more accurate the -return value $icode xf$$ is as an approximation -for $latex X(tf)$$. - -$head ti$$ -The argument $icode ti$$ has prototype -$codei% - const %Scalar% &%ti% -%$$ -(see description of $cref/Scalar/Rosen34/Scalar/$$ below). -It specifies the initial time for $icode t$$ in the -differential equation; i.e., -the time corresponding to the value $icode xi$$. - -$head tf$$ -The argument $icode tf$$ has prototype -$codei% - const %Scalar% &%tf% -%$$ -It specifies the final time for $icode t$$ in the -differential equation; i.e., -the time corresponding to the value $icode xf$$. - -$head xi$$ -The argument $icode xi$$ has the prototype -$codei% - const %Vector% &%xi% -%$$ -and the size of $icode xi$$ is equal to $icode n$$. -It specifies the value of $latex X(ti)$$ - -$head e$$ -The argument $icode e$$ is optional and has the prototype -$codei% - %Vector% &%e% -%$$ -If $icode e$$ is present, -the size of $icode e$$ must be equal to $icode n$$. -The input value of the elements of $icode e$$ does not matter. -On output -it contains an element by element -estimated bound for the absolute value of the error in $icode xf$$ -$latex \[ - e = O( h^4 ) -\] $$ -where $latex h = (tf - ti) / M$$ is the step size. - -$head Scalar$$ -The type $icode Scalar$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. -In addition, the following operations must be defined for -$icode Scalar$$ objects $icode a$$ and $icode b$$: - -$table -$bold Operation$$ $cnext $bold Description$$ $rnext -$icode%a% < %b%$$ $cnext - less than operator (returns a $code bool$$ object) -$tend - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Scalar/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Parallel Mode$$ -For each set of types -$cref/Scalar/Rosen34/Scalar/$$, -$cref/Vector/Rosen34/Vector/$$, and -$cref/Fun/Rosen34/Fun/$$, -the first call to $code Rosen34$$ -must not be $cref/parallel/ta_in_parallel/$$ execution mode. - -$head Example$$ -$children% - example/general/rosen_34.cpp -%$$ -The file -$cref rosen_34.cpp$$ -contains an example and test a test of using this routine. -It returns true if it succeeds and false otherwise. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/rosen_34.hpp$$. - -$end --------------------------------------------------------------------------- -*/ - -# include -# include -# include -# include -# include -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { // BEGIN CppAD namespace - -template -Vector Rosen34( - Fun &F , - size_t M , - const Scalar &ti , - const Scalar &tf , - const Vector &xi ) -{ Vector e( xi.size() ); - return Rosen34(F, M, ti, tf, xi, e); -} - -template -Vector Rosen34( - Fun &F , - size_t M , - const Scalar &ti , - const Scalar &tf , - const Vector &xi , - Vector &e ) -{ - CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - - // Parameters for Shampine's Rosenbrock method - // are static to avoid recalculation on each call and - // do not use Vector to avoid possible memory leak - static Scalar a[3] = { - Scalar(0), - Scalar(1), - Scalar(3) / Scalar(5) - }; - static Scalar b[2 * 2] = { - Scalar(1), - Scalar(0), - Scalar(24) / Scalar(25), - Scalar(3) / Scalar(25) - }; - static Scalar ct[4] = { - Scalar(1) / Scalar(2), - - Scalar(3) / Scalar(2), - Scalar(121) / Scalar(50), - Scalar(29) / Scalar(250) - }; - static Scalar cg[3 * 3] = { - - Scalar(4), - Scalar(0), - Scalar(0), - Scalar(186) / Scalar(25), - Scalar(6) / Scalar(5), - Scalar(0), - - Scalar(56) / Scalar(125), - - Scalar(27) / Scalar(125), - - Scalar(1) / Scalar(5) - }; - static Scalar d3[3] = { - Scalar(97) / Scalar(108), - Scalar(11) / Scalar(72), - Scalar(25) / Scalar(216) - }; - static Scalar d4[4] = { - Scalar(19) / Scalar(18), - Scalar(1) / Scalar(4), - Scalar(25) / Scalar(216), - Scalar(125) / Scalar(216) - }; - CPPAD_ASSERT_KNOWN( - M >= 1, - "Error in Rosen34: the number of steps is less than one" - ); - CPPAD_ASSERT_KNOWN( - e.size() == xi.size(), - "Error in Rosen34: size of e not equal to size of xi" - ); - size_t i, j, k, l, m; // indices - - size_t n = xi.size(); // number of components in X(t) - Scalar ns = Scalar(double(M)); // number of steps as Scalar object - Scalar h = (tf - ti) / ns; // step size - Scalar zero = Scalar(0); // some constants - Scalar one = Scalar(1); - Scalar two = Scalar(2); - - // permutation vectors needed for LU factorization routine - CppAD::vector ip(n), jp(n); - - // vectors used to store values returned by F - Vector E(n * n), Eg(n), f_t(n); - Vector g(n * 3), x3(n), x4(n), xf(n), ftmp(n), xtmp(n), nan_vec(n); - - // initialize e = 0, nan_vec = nan - for(i = 0; i < n; i++) - { e[i] = zero; - nan_vec[i] = nan(zero); - } - - xf = xi; // initialize solution - for(m = 0; m < M; m++) - { // time at beginning of this interval - Scalar t = ti * (Scalar(int(M - m)) / ns) - + tf * (Scalar(int(m)) / ns); - - // value of x at beginning of this interval - x3 = x4 = xf; - - // evaluate partial derivatives at beginning of this interval - F.Ode_ind(t, xf, f_t); - F.Ode_dep(t, xf, E); // E = f_x - if( hasnan(f_t) || hasnan(E) ) - { e = nan_vec; - return nan_vec; - } - - // E = I - f_x * h / 2 - for(i = 0; i < n; i++) - { for(j = 0; j < n; j++) - E[i * n + j] = - E[i * n + j] * h / two; - E[i * n + i] += one; - } - - // LU factor the matrix E -# ifndef NDEBUG - int sign = LuFactor(ip, jp, E); -# else - LuFactor(ip, jp, E); -# endif - CPPAD_ASSERT_KNOWN( - sign != 0, - "Error in Rosen34: I - f_x * h / 2 not invertible" - ); - - // loop over integration steps - for(k = 0; k < 3; k++) - { // set location for next function evaluation - xtmp = xf; - for(l = 0; l < k; l++) - { // loop over previous function evaluations - Scalar bkl = b[(k-1)*2 + l]; - for(i = 0; i < n; i++) - { // loop over elements of x - xtmp[i] += bkl * g[i*3 + l] * h; - } - } - // ftmp = F(t + a[k] * h, xtmp) - F.Ode(t + a[k] * h, xtmp, ftmp); - if( hasnan(ftmp) ) - { e = nan_vec; - return nan_vec; - } - - // Form Eg for this integration step - for(i = 0; i < n; i++) - Eg[i] = ftmp[i] + ct[k] * f_t[i] * h; - for(l = 0; l < k; l++) - { for(i = 0; i < n; i++) - Eg[i] += cg[(k-1)*3 + l] * g[i*3 + l]; - } - - // Solve the equation E * g = Eg - LuInvert(ip, jp, E, Eg); - - // save solution and advance x3, x4 - for(i = 0; i < n; i++) - { g[i*3 + k] = Eg[i]; - x3[i] += h * d3[k] * Eg[i]; - x4[i] += h * d4[k] * Eg[i]; - } - } - // Form Eg for last update to x4 only - for(i = 0; i < n; i++) - Eg[i] = ftmp[i] + ct[3] * f_t[i] * h; - for(l = 0; l < 3; l++) - { for(i = 0; i < n; i++) - Eg[i] += cg[2*3 + l] * g[i*3 + l]; - } - - // Solve the equation E * g = Eg - LuInvert(ip, jp, E, Eg); - - // advance x4 and accumulate error bound - for(i = 0; i < n; i++) - { x4[i] += h * d4[3] * Eg[i]; - - // cant use abs because cppad.hpp may not be included - Scalar diff = x4[i] - x3[i]; - if( diff < zero ) - e[i] -= diff; - else e[i] += diff; - } - - // advance xf for this step using x4 - xf = x4; - } - return xf; -} - -} // End CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/runge_45.hpp b/external/cppad/include/cppad/utility/runge_45.hpp deleted file mode 100644 index 97bffda07..000000000 --- a/external/cppad/include/cppad/utility/runge_45.hpp +++ /dev/null @@ -1,428 +0,0 @@ -# ifndef CPPAD_UTILITY_RUNGE_45_HPP -# define CPPAD_UTILITY_RUNGE_45_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin Runge45$$ -$spell - std - fabs - cppad.hpp - bool - xf - templated - const - Runge-Kutta - CppAD - xi - ti - tf - Karp -$$ - - -$section An Embedded 4th and 5th Order Runge-Kutta ODE Solver$$ -$mindex Runge45 Runge Kutta solve differential equation$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%xf% = Runge45(%F%, %M%, %ti%, %tf%, %xi%) -%$$ -$icode%xf% = Runge45(%F%, %M%, %ti%, %tf%, %xi%, %e%) -%$$ - - -$head Purpose$$ -This is an implementation of the -Cash-Karp embedded 4th and 5th order Runge-Kutta ODE solver -described in Section 16.2 of $cref/Numerical Recipes/Bib/Numerical Recipes/$$. -We use $latex n$$ for the size of the vector $icode xi$$. -Let $latex \B{R}$$ denote the real numbers -and let $latex F : \B{R} \times \B{R}^n \rightarrow \B{R}^n$$ -be a smooth function. -The return value $icode xf$$ contains a 5th order -approximation for the value $latex X(tf)$$ where -$latex X : [ti , tf] \rightarrow \B{R}^n$$ is defined by -the following initial value problem: -$latex \[ -\begin{array}{rcl} - X(ti) & = & xi \\ - X'(t) & = & F[t , X(t)] -\end{array} -\] $$ -If your set of ordinary differential equations -are stiff, an implicit method may be better -(perhaps $cref Rosen34$$.) - -$head Operation Sequence$$ -The $cref/operation sequence/glossary/Operation/Sequence/$$ for $icode Runge$$ -does not depend on any of its $icode Scalar$$ input values provided that -the operation sequence for -$codei% - %F%.Ode(%t%, %x%, %f%) -%$$ -does not on any of its $icode Scalar$$ inputs (see below). - -$head Include$$ -The file $code cppad/runge_45.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head xf$$ -The return value $icode xf$$ has the prototype -$codei% - %Vector% %xf% -%$$ -and the size of $icode xf$$ is equal to $icode n$$ -(see description of $cref/Vector/Runge45/Vector/$$ below). -$latex \[ - X(tf) = xf + O( h^6 ) -\] $$ -where $latex h = (tf - ti) / M$$ is the step size. -If $icode xf$$ contains not a number $cref nan$$, -see the discussion for $cref/f/Runge45/Fun/f/$$. - -$head Fun$$ -The class $icode Fun$$ -and the object $icode F$$ satisfy the prototype -$codei% - %Fun% &%F% -%$$ -The object $icode F$$ (and the class $icode Fun$$) -must have a member function named $code Ode$$ -that supports the syntax -$codei% - %F%.Ode(%t%, %x%, %f%) -%$$ - -$subhead t$$ -The argument $icode t$$ to $icode%F%.Ode%$$ has prototype -$codei% - const %Scalar% &%t% -%$$ -(see description of $cref/Scalar/Runge45/Scalar/$$ below). - -$subhead x$$ -The argument $icode x$$ to $icode%F%.Ode%$$ has prototype -$codei% - const %Vector% &%x% -%$$ -and has size $icode n$$ -(see description of $cref/Vector/Runge45/Vector/$$ below). - -$subhead f$$ -The argument $icode f$$ to $icode%F%.Ode%$$ has prototype -$codei% - %Vector% &%f% -%$$ -On input and output, $icode f$$ is a vector of size $icode n$$ -and the input values of the elements of $icode f$$ do not matter. -On output, -$icode f$$ is set equal to $latex F(t, x)$$ in the differential equation. -If any of the elements of $icode f$$ have the value not a number $code nan$$ -the routine $code Runge45$$ returns with all the -elements of $icode xf$$ and $icode e$$ equal to $code nan$$. - -$subhead Warning$$ -The argument $icode f$$ to $icode%F%.Ode%$$ -must have a call by reference in its prototype; i.e., -do not forget the $code &$$ in the prototype for $icode f$$. - -$head M$$ -The argument $icode M$$ has prototype -$codei% - size_t %M% -%$$ -It specifies the number of steps -to use when solving the differential equation. -This must be greater than or equal one. -The step size is given by $latex h = (tf - ti) / M$$, thus -the larger $icode M$$, the more accurate the -return value $icode xf$$ is as an approximation -for $latex X(tf)$$. - -$head ti$$ -The argument $icode ti$$ has prototype -$codei% - const %Scalar% &%ti% -%$$ -(see description of $cref/Scalar/Runge45/Scalar/$$ below). -It specifies the initial time for $icode t$$ in the -differential equation; i.e., -the time corresponding to the value $icode xi$$. - -$head tf$$ -The argument $icode tf$$ has prototype -$codei% - const %Scalar% &%tf% -%$$ -It specifies the final time for $icode t$$ in the -differential equation; i.e., -the time corresponding to the value $icode xf$$. - -$head xi$$ -The argument $icode xi$$ has the prototype -$codei% - const %Vector% &%xi% -%$$ -and the size of $icode xi$$ is equal to $icode n$$. -It specifies the value of $latex X(ti)$$ - -$head e$$ -The argument $icode e$$ is optional and has the prototype -$codei% - %Vector% &%e% -%$$ -If $icode e$$ is present, -the size of $icode e$$ must be equal to $icode n$$. -The input value of the elements of $icode e$$ does not matter. -On output -it contains an element by element -estimated bound for the absolute value of the error in $icode xf$$ -$latex \[ - e = O( h^5 ) -\] $$ -where $latex h = (tf - ti) / M$$ is the step size. -If on output, $icode e$$ contains not a number $code nan$$, -see the discussion for $cref/f/Runge45/Fun/f/$$. - -$head Scalar$$ -The type $icode Scalar$$ must satisfy the conditions -for a $cref NumericType$$ type. -The routine $cref CheckNumericType$$ will generate an error message -if this is not the case. - -$subhead fabs$$ -In addition, the following function must be defined for -$icode Scalar$$ objects $icode a$$ and $icode b$$ -$codei% - %a% = fabs(%b%) -%$$ -Note that this operation is only used for computing $icode e$$; hence -the operation sequence for $icode xf$$ can still be independent of -the arguments to $code Runge45$$ even if -$codei% - fabs(%b%) = std::max(-%b%, %b%) -%$$. - -$head Vector$$ -The type $icode Vector$$ must be a $cref SimpleVector$$ class with -$cref/elements of type Scalar/SimpleVector/Elements of Specified Type/$$. -The routine $cref CheckSimpleVector$$ will generate an error message -if this is not the case. - -$head Parallel Mode$$ -For each set of types -$cref/Scalar/Runge45/Scalar/$$, -$cref/Vector/Runge45/Vector/$$, and -$cref/Fun/Runge45/Fun/$$, -the first call to $code Runge45$$ -must not be $cref/parallel/ta_in_parallel/$$ execution mode. - - -$head Example$$ -$children% - example/utility/runge45_1.cpp% - example/general/runge45_2.cpp -%$$ -The file -$cref runge45_1.cpp$$ -contains a simple example and test of $code Runge45$$. -It returns true if it succeeds and false otherwise. -$pre - -$$ -The file -$cref runge45_2.cpp$$ contains an example using $code Runge45$$ -in the context of algorithmic differentiation. -It also returns true if it succeeds and false otherwise. - -$head Source Code$$ -The source code for this routine is in the file -$code cppad/runge_45.hpp$$. - -$end --------------------------------------------------------------------------- -*/ -# include -# include -# include -# include -# include - -// needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL -# include - -namespace CppAD { // BEGIN CppAD namespace - -template -Vector Runge45( - Fun &F , - size_t M , - const Scalar &ti , - const Scalar &tf , - const Vector &xi ) -{ Vector e( xi.size() ); - return Runge45(F, M, ti, tf, xi, e); -} - -template -Vector Runge45( - Fun &F , - size_t M , - const Scalar &ti , - const Scalar &tf , - const Vector &xi , - Vector &e ) -{ - CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - - // check numeric type specifications - CheckNumericType(); - - // check simple vector class specifications - CheckSimpleVector(); - - // Cash-Karp parameters for embedded Runge-Kutta method - // are static to avoid recalculation on each call and - // do not use Vector to avoid possible memory leak - static Scalar a[6] = { - Scalar(0), - Scalar(1) / Scalar(5), - Scalar(3) / Scalar(10), - Scalar(3) / Scalar(5), - Scalar(1), - Scalar(7) / Scalar(8) - }; - static Scalar b[5 * 5] = { - Scalar(1) / Scalar(5), - Scalar(0), - Scalar(0), - Scalar(0), - Scalar(0), - - Scalar(3) / Scalar(40), - Scalar(9) / Scalar(40), - Scalar(0), - Scalar(0), - Scalar(0), - - Scalar(3) / Scalar(10), - -Scalar(9) / Scalar(10), - Scalar(6) / Scalar(5), - Scalar(0), - Scalar(0), - - -Scalar(11) / Scalar(54), - Scalar(5) / Scalar(2), - -Scalar(70) / Scalar(27), - Scalar(35) / Scalar(27), - Scalar(0), - - Scalar(1631) / Scalar(55296), - Scalar(175) / Scalar(512), - Scalar(575) / Scalar(13824), - Scalar(44275) / Scalar(110592), - Scalar(253) / Scalar(4096) - }; - static Scalar c4[6] = { - Scalar(2825) / Scalar(27648), - Scalar(0), - Scalar(18575) / Scalar(48384), - Scalar(13525) / Scalar(55296), - Scalar(277) / Scalar(14336), - Scalar(1) / Scalar(4), - }; - static Scalar c5[6] = { - Scalar(37) / Scalar(378), - Scalar(0), - Scalar(250) / Scalar(621), - Scalar(125) / Scalar(594), - Scalar(0), - Scalar(512) / Scalar(1771) - }; - - CPPAD_ASSERT_KNOWN( - M >= 1, - "Error in Runge45: the number of steps is less than one" - ); - CPPAD_ASSERT_KNOWN( - e.size() == xi.size(), - "Error in Runge45: size of e not equal to size of xi" - ); - size_t i, j, k, m; // indices - - size_t n = xi.size(); // number of components in X(t) - Scalar ns = Scalar(int(M)); // number of steps as Scalar object - Scalar h = (tf - ti) / ns; // step size - Scalar zero_or_nan = Scalar(0); // zero (nan if Ode returns has a nan) - for(i = 0; i < n; i++) // initialize e = 0 - e[i] = zero_or_nan; - - // vectors used to store values returned by F - Vector fh(6 * n), xtmp(n), ftmp(n), x4(n), x5(n), xf(n); - - xf = xi; // initialize solution - for(m = 0; m < M; m++) - { // time at beginning of this interval - // (convert to int to avoid MS compiler warning) - Scalar t = ti * (Scalar(int(M - m)) / ns) - + tf * (Scalar(int(m)) / ns); - - // loop over integration steps - x4 = x5 = xf; // start x4 and x5 at same point for each step - for(j = 0; j < 6; j++) - { // loop over function evaluations for this step - xtmp = xf; // location for next function evaluation - for(k = 0; k < j; k++) - { // loop over previous function evaluations - Scalar bjk = b[ (j-1) * 5 + k ]; - for(i = 0; i < n; i++) - { // loop over elements of x - xtmp[i] += bjk * fh[i * 6 + k]; - } - } - // ftmp = F(t + a[j] * h, xtmp) - F.Ode(t + a[j] * h, xtmp, ftmp); - - // if ftmp has a nan, set zero_or_nan to nan - for(i = 0; i < n; i++) - zero_or_nan *= ftmp[i]; - - for(i = 0; i < n; i++) - { // loop over elements of x - Scalar fhi = ftmp[i] * h; - fh[i * 6 + j] = fhi; - x4[i] += c4[j] * fhi; - x5[i] += c5[j] * fhi; - x5[i] += zero_or_nan; - } - } - // accumulate error bound - for(i = 0; i < n; i++) - { // cant use abs because cppad.hpp may not be included - Scalar diff = x5[i] - x4[i]; - e[i] += fabs(diff); - e[i] += zero_or_nan; - } - - // advance xf for this step using x5 - xf = x5; - } - return xf; -} - -} // End CppAD namespace - -# endif diff --git a/external/cppad/include/cppad/utility/set_union.hpp b/external/cppad/include/cppad/utility/set_union.hpp deleted file mode 100644 index d62de355b..000000000 --- a/external/cppad/include/cppad/utility/set_union.hpp +++ /dev/null @@ -1,88 +0,0 @@ -# ifndef CPPAD_UTILITY_SET_UNION_HPP -# define CPPAD_UTILITY_SET_UNION_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin set_union$$ -$spell - set - const - std -$$ - -$section Union of Standard Sets$$ - -$head Syntax$$ -$icode%result% = set_union(%left%, %right%)%$$ - -$head Purpose$$ -This is a simplified (and restricted) interface to -the $code std::union$$ operation. - -$head Element$$ -This is the type of the elements of the sets. - -$head left$$ -This argument has prototype -$codei% - const std::set<%Element%>& %left% -%$$ - -$head right$$ -This argument has prototype -$codei% - const std::set<%Element%>& %right% -%$$ - -$head result$$ -The return value has prototype -$codei% - std::set<%Element%>& %result% -%$$ -It contains the union of $icode left$$ and $icode right$$. -Note that C++11 detects that the return value is a temporary -and uses it for the result instead of making a separate copy. - -$children% - example/utility/set_union.cpp -%$$ -$head Example$$ -The file $cref set_union.cpp$$ contains an example and test of this -operation. It returns true if the test passes and false otherwise. - - -$end -*/ - -# include -# include -# include - -namespace CppAD { - template - std::set set_union( - const std::set& left , - const std::set& right ) - { std::set result; - std::set_union( - left.begin() , - left.end() , - right.begin() , - right.end() , - std::inserter(result, result.begin()) - ); - return result; - } -} - -# endif diff --git a/external/cppad/include/cppad/utility/sparse_rc.hpp b/external/cppad/include/cppad/utility/sparse_rc.hpp deleted file mode 100644 index 3ccaaee19..000000000 --- a/external/cppad/include/cppad/utility/sparse_rc.hpp +++ /dev/null @@ -1,348 +0,0 @@ -# ifndef CPPAD_UTILITY_SPARSE_RC_HPP -# define CPPAD_UTILITY_SPARSE_RC_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin sparse_rc$$ -$spell - CppAD - const - nnz - cppad - hpp - rc - nr - nc - resize -$$ -$section Row and Column Index Sparsity Patterns$$ - -$head Syntax$$ -$codei%# include -%$$ -$codei%sparse_rc<%SizeVector%> %empty% -%$$ -$codei%sparse_rc<%SizeVector%> %pattern%(%nr%, %nc%, %nnz%) -%$$ -$codei%target% = %pattern% -%$$ -$icode%resize%(%nr%, %nc%, %nnz%) -%$$ -$icode%pattern%.set(%k%, %r%, %c%) -%$$ -$icode%pattern%.nr() -%$$ -$icode%pattern%.nc() -%$$ -$icode%pattern%.nnz() -%$$ -$codei%const %SizeVector%& %row%( %pattern%.row() ) -%$$ -$codei%const %SizeVector%& %col%( %pattern%.col() ) -%$$ -$icode%row_major% = %pattern%.row_major() -%$$ -$icode%col_major% = %pattern%.col_major() -%$$ - -$head SizeVector$$ -We use $icode SizeVector$$ to denote $cref SimpleVector$$ class -$cref/with elements of type/SimpleVector/Elements of Specified Type/$$ -$code size$$. - -$head empty$$ -This is an empty sparsity pattern. To be specific, -the corresponding number of rows $icode nr$$, -number of columns $icode nc$$, -and number of possibly non-zero values $icode nnz$$, -are all zero. - -$head pattern$$ -This object is used to hold a sparsity pattern for a matrix. -The sparsity $icode pattern$$ is $code const$$ -except during its constructor, $code resize$$, and $code set$$. - -$head target$$ -The target of the assignment statement must have prototype -$codei% - sparse_rc<%SizeVector%> %target% -%$$ -After this assignment statement, $icode target$$ is an independent copy -of $icode pattern$$; i.e. it has all the same values as $icode pattern$$ -and changes to $icode target$$ do not affect $icode pattern$$. - -$head nr$$ -This argument has prototype -$codei% - size_t %nr% -%$$ -It specifies the number of rows in the sparsity pattern. -The function call $code nr()$$ returns the value of $icode nr$$. - -$head nc$$ -This argument has prototype -$codei% - size_t %nc% -%$$ -It specifies the number of columns in the sparsity pattern. -The function call $code nc()$$ returns the value of $icode nc$$. - -$head nnz$$ -This argument has prototype -$codei% - size_t %nnz% -%$$ -It specifies the number of possibly non-zero -index pairs in the sparsity pattern. -The function call $code nnz()$$ returns the value of $icode nnz$$. - -$head resize$$ -The current sparsity pattern is lost and a new one is started -with the specified parameters. The elements in the $icode row$$ -and $icode col$$ vectors should be assigned using $code set$$. - -$head set$$ -This function sets the values -$codei% - %row%[%k%] = %r% - %col%[%k%] = %c% -%$$ - -$subhead k$$ -This argument has type -$codei% - size_t %k% -%$$ -and must be less than $icode nnz$$. - -$subhead r$$ -This argument has type -$codei% - size_t %r% -%$$ -It specifies the value assigned to $icode%row%[%k%]%$$ and must -be less than $icode nr$$. - -$subhead c$$ -This argument has type -$codei% - size_t %c% -%$$ -It specifies the value assigned to $icode%col%[%k%]%$$ and must -be less than $icode nc$$. - -$head row$$ -This vector has size $icode nnz$$ and -$icode%row%[%k%]%$$ -is the row index of the $th k$$ possibly non-zero -index pair in the sparsity pattern. - -$head col$$ -This vector has size $icode nnz$$ and -$icode%col%[%k%]%$$ is the column index of the $th k$$ possibly non-zero -index pair in the sparsity pattern. - -$head row_major$$ -This vector has prototype -$codei% - %SizeVector% %row_major% -%$$ -and its size $icode nnz$$. -It sorts the sparsity pattern in row-major order. -To be specific, -$codei% - %col%[ %row_major%[%k%] ] <= %col%[ %row_major%[%k%+1] ] -%$$ -and if $icode%col%[ %row_major%[%k%] ] == %col%[ %row_major%[%k%+1] ]%$$, -$codei% - %row%[ %row_major%[%k%] ] < %row%[ %row_major%[%k%+1] ] -%$$ -This routine generates an assert if there are two entries with the same -row and column values (if $code NDEBUG$$ is not defined). - -$head col_major$$ -This vector has prototype -$codei% - %SizeVector% %col_major% -%$$ -and its size $icode nnz$$. -It sorts the sparsity pattern in column-major order. -To be specific, -$codei% - %row%[ %col_major%[%k%] ] <= %row%[ %col_major%[%k%+1] ] -%$$ -and if $icode%row%[ %col_major%[%k%] ] == %row%[ %col_major%[%k%+1] ]%$$, -$codei% - %col%[ %col_major%[%k%] ] < %col%[ %col_major%[%k%+1] ] -%$$ -This routine generates an assert if there are two entries with the same -row and column values (if $code NDEBUG$$ is not defined). - -$children% - example/utility/sparse_rc.cpp -%$$ -$head Example$$ -The file $cref sparse_rc.cpp$$ -contains an example and test of this class. -It returns true if it succeeds and false otherwise. - -$end -*/ -/*! -\file sparse_rc.hpp -A Matrix sparsity pattern class. -*/ -# include // for size_t -# include // for CPPAD_ASSERT -# include // for row and column major ordering - -namespace CppAD { // BEGIN CPPAD_NAMESPACE - -/// sparsity pattern for a matrix with indices of type size_t -template -class sparse_rc { -private: - /// number of rows in the sparsity pattern - size_t nr_; - /// number of columns in the sparsity pattern - size_t nc_; - /// number of possibly non-zero index pairs - size_t nnz_; - /// row_[k] is the row index for the k-th possibly non-zero entry - SizeVector row_; - /// col_[k] is the column index for the k-th possibly non-zero entry - SizeVector col_; -public: - /// default constructor - /// Eigen vector is ambiguous for row_(0), col_(0) so use default ctor - sparse_rc(void) - : nr_(0), nc_(0), nnz_(0) - { } - /// sizing constructor - /// Eigen vector is ambiguous for row_(0), col_(0) so use default ctor - sparse_rc(size_t nr, size_t nc, size_t nnz) - : nr_(nr), nc_(nc), nnz_(nnz) - { row_.resize(nnz); - col_.resize(nnz); - } - /// copy constructor - sparse_rc(const sparse_rc& other) - : - nr_(other.nr_) , - nc_(other.nc_) , - nnz_(other.nnz_) , - row_(other.row_) , - col_(other.col_) - { } - /// assignment - void operator=(const sparse_rc& pattern) - { nr_ = pattern.nr_; - nc_ = pattern.nc_; - nnz_ = pattern.nnz_; - // simple vector assignment requires vectors to have same size - row_.resize(nnz_); - col_.resize(nnz_); - row_ = pattern.row_; - col_ = pattern.col_; - } - /// resize - void resize(size_t nr, size_t nc, size_t nnz) - { nr_ = nr; - nc_ = nc; - nnz_ = nnz; - row_.resize(nnz); - col_.resize(nnz); - } - /// set row and column for a possibly non-zero element - void set(size_t k, size_t r, size_t c) - { CPPAD_ASSERT_KNOWN( - k < nnz_, - "The index k is not less than nnz in sparse_rc::set" - ); - CPPAD_ASSERT_KNOWN( - r < nr_, - "The index r is not less than nr in sparse_rc::set" - ); - CPPAD_ASSERT_KNOWN( - c < nc_, - "The index c is to not less than nc in sparse_rc::set" - ); - row_[k] = r; - col_[k] = c; - // - } - /// number of rows in matrix - size_t nr(void) const - { return nr_; } - /// number of columns in matrix - size_t nc(void) const - { return nc_; } - /// number of possibly non-zero elements in matrix - size_t nnz(void) const - { return nnz_; } - /// row indices - const SizeVector& row(void) const - { return row_; } - /// column indices - const SizeVector& col(void) const - { return col_; } - /// row-major order - SizeVector row_major(void) const - { SizeVector keys(nnz_), row_major(nnz_); - for(size_t k = 0; k < nnz_; k++) - { CPPAD_ASSERT_UNKNOWN( row_[k] < nr_ ); - keys[k] = row_[k] * nc_ + col_[k]; - } - index_sort(keys, row_major); -# ifndef NDEBUG - for(size_t ell = 0; ell + 1 < nnz_; ell++) - { size_t k = row_major[ ell ]; - size_t kp = row_major[ ell + 1 ]; - CPPAD_ASSERT_KNOWN( - row_[k] != row_[kp] || col_[k] != col_[kp], - "sparse_rc: row_major: duplicate entry in this pattern" - ); - CPPAD_ASSERT_UNKNOWN( - row_[k] -%$$ -$codei%sparse_rcv<%SizeVector%, %ValueVector%> %empty% -%$$ -$codei%sparse_rcv<%SizeVector%, %ValueVector%> %matrix%(%pattern%) -%$$ -$codei%target% = %matrix% -%$$ -$icode%matrix%.set(%k%, %v%) -%$$ -$icode%nr% = %matrix%.nr() -%$$ -$icode%nc% = %matrix%.nc() -%$$ -$icode%nnz% = %matrix%.nnz() -%$$ -$codei%const %SizeVector%& %row%( %matrix%.row() ) -%$$ -$codei%const %SizeVector%& %col%( %matrix%.col() ) -%$$ -$codei%const %ValueVector%& %val%( %matrix%.val() ) -%$$ -$icode%row_major% = %matrix%.row_major() -%$$ -$icode%col_major% = %matrix%.col_major() -%$$ - -$head SizeVector$$ -We use $cref/SizeVector/sparse_rc/SizeVector/$$ to denote the -$cref SimpleVector$$ class corresponding to $icode pattern$$. - -$head ValueVector$$ -We use $icode ValueVector$$ to denote the -$cref SimpleVector$$ class corresponding to $icode val$$. - -$head empty$$ -This is an empty sparse matrix object. To be specific, -the corresponding number of rows $icode nr$$, -number of columns $icode nc$$, -and number of possibly non-zero values $icode nnz$$, -are all zero. - - -$head pattern$$ -This argument has prototype -$codei% - const sparse_rc<%SizeVector%>& %pattern% -%$$ -It specifies the number of rows, number of columns and -the possibly non-zero entries in the $icode matrix$$. - -$head matrix$$ -This is a sparse matrix object with the sparsity specified by $icode pattern$$. -Only the $icode val$$ vector can be changed. All other values returned by -$icode matrix$$ are fixed during the constructor and constant there after. -The $icode val$$ vector is only changed by the constructor -and the $code set$$ function. -There is one exception to the rule, where $icode matrix$$ corresponds -to $icode target$$ for an assignment statement. - -$head target$$ -The target of the assignment statement must have prototype -$codei% - sparse_rcv<%SizeVector%, %ValueVector%> %target% -%$$ -After this assignment statement, $icode target$$ is an independent copy -of $icode matrix$$; i.e. it has all the same values as $icode matrix$$ -and changes to $icode target$$ do not affect $icode matrix$$. - -$head nr$$ -This return value has prototype -$codei% - size_t %nr% -%$$ -and is the number of rows in $icode matrix$$. - -$head nc$$ -This argument and return value has prototype -$codei% - size_t %nc% -%$$ -and is the number of columns in $icode matrix$$. - -$head nnz$$ -We use the notation $icode nnz$$ to denote the number of -possibly non-zero entries in $icode matrix$$. - -$head set$$ -This function sets the value -$codei% - %val%[%k%] = %v% -%$$ - -$subhead k$$ -This argument has type -$codei% - size_t %k% -%$$ -and must be less than $icode nnz$$. - -$subhead v$$ -This argument has type -$codei% - const %ValueVector%::value_type& %v% -%$$ -It specifies the value assigned to $icode%val%[%k%]%$$. - - -$head row$$ -This vector has size $icode nnz$$ and -$icode%row%[%k%]%$$ -is the row index of the $th k$$ possibly non-zero -element in $icode matrix$$. - -$head col$$ -This vector has size $icode nnz$$ and -$icode%col[%k%]%$$ is the column index of the $th k$$ possibly non-zero -element in $icode matrix$$ - -$head val$$ -This vector has size $icode nnz$$ and -$icode%val[%k%]%$$ is value of the $th k$$ possibly non-zero entry -in the sparse matrix (the value may be zero). - -$head row_major$$ -This vector has prototype -$codei% - %SizeVector% %row_major% -%$$ -and its size $icode nnz$$. -It sorts the sparsity pattern in row-major order. -To be specific, -$codei% - %col%[ %row_major%[%k%] ] <= %col%[ %row_major%[%k%+1] ] -%$$ -and if $icode%col%[ %row_major%[%k%] ] == %col%[ %row_major%[%k%+1] ]%$$, -$codei% - %row%[ %row_major%[%k%] ] < %row%[ %row_major%[%k%+1] ] -%$$ -This routine generates an assert if there are two entries with the same -row and column values (if $code NDEBUG$$ is not defined). - -$head col_major$$ -This vector has prototype -$codei% - %SizeVector% %col_major% -%$$ -and its size $icode nnz$$. -It sorts the sparsity pattern in column-major order. -To be specific, -$codei% - %row%[ %col_major%[%k%] ] <= %row%[ %col_major%[%k%+1] ] -%$$ -and if $icode%row%[ %col_major%[%k%] ] == %row%[ %col_major%[%k%+1] ]%$$, -$codei% - %col%[ %col_major%[%k%] ] < %col%[ %col_major%[%k%+1] ] -%$$ -This routine generates an assert if there are two entries with the same -row and column values (if $code NDEBUG$$ is not defined). - -$children% - example/utility/sparse_rcv.cpp -%$$ -$head Example$$ -The file $cref sparse_rcv.cpp$$ -contains an example and test of this class. -It returns true if it succeeds and false otherwise. - -$end -*/ -/*! -\file sparse_rcv.hpp -A sparse matrix class. -*/ -# include - -namespace CppAD { // BEGIN CPPAD_NAMESPACE - -/// Sparse matrices with elements of type Scalar -template -class sparse_rcv { -private: - /// sparsity pattern - sparse_rc pattern_; - /// value_type - typedef typename ValueVector::value_type value_type; - /// val_[k] is the value for the k-th possibly non-zero entry in the matrix - ValueVector val_; -public: - // ------------------------------------------------------------------------ - /// default constructor - sparse_rcv(void) - : pattern_(0, 0, 0), val_(0) - { } - /// constructor - sparse_rcv(const sparse_rc& pattern ) - : - pattern_(pattern) , - val_(pattern_.nnz()) - { } - /// assignment - void operator=(const sparse_rcv& matrix) - { pattern_ = matrix.pattern_; - // simple vector assignment requires vectors to have same size - val_.resize( matrix.nnz() ); - val_ = matrix.val(); - } - // ------------------------------------------------------------------------ - void set(size_t k, const value_type& v) - { CPPAD_ASSERT_KNOWN( - pattern_.nnz(), - "The index k is not less than nnz in sparse_rcv::set" - ); - val_[k] = v; - } - /// number of rows in matrix - size_t nr(void) const - { return pattern_.nr(); } - /// number of columns in matrix - size_t nc(void) const - { return pattern_.nc(); } - /// number of possibly non-zero elements in matrix - size_t nnz(void) const - { return pattern_.nnz(); } - /// row indices - const SizeVector& row(void) const - { return pattern_.row(); } - /// column indices - const SizeVector& col(void) const - { return pattern_.col(); } - /// value for possibly non-zero elements - const ValueVector& val(void) const - { return val_; } - /// row-major order - SizeVector row_major(void) const - { return pattern_.row_major(); } - /// column-major indices - SizeVector col_major(void) const - { return pattern_.col_major(); } -}; - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/utility/speed_test.hpp b/external/cppad/include/cppad/utility/speed_test.hpp deleted file mode 100644 index 97b2a9b11..000000000 --- a/external/cppad/include/cppad/utility/speed_test.hpp +++ /dev/null @@ -1,472 +0,0 @@ -# ifndef CPPAD_UTILITY_SPEED_TEST_HPP -# define CPPAD_UTILITY_SPEED_TEST_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin speed_test$$ -$spell - gettimeofday - vec - cppad.hpp - Microsoft - namespace - std - const - cout - ctime - ifdef - const - endif - cpp -$$ - - -$section Run One Speed Test and Return Results$$ -$mindex speed_test$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%rate_vec% = speed_test(%test%, %size_vec%, %time_min%)%$$ - -$head Purpose$$ -The $code speed_test$$ function executes a speed test -for various sized problems -and reports the rate of execution. - -$head Motivation$$ -It is important to separate small calculation units -and test them individually. -This way individual changes can be tested in the context of the -routine that they are in. -On many machines, accurate timing of a very short execution -sequences is not possible. -In addition, -there may be set up and tear down time for a test that -we do not really want included in the timing. -For this reason $code speed_test$$ -automatically determines how many times to -repeat the section of the test that we wish to time. - - -$head Include$$ -The file $code cppad/speed_test.hpp$$ defines the -$code speed_test$$ function. -This file is included by $code cppad/cppad.hpp$$ -and it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Vector$$ -We use $icode Vector$$ to denote a -$cref/simple vector class/SimpleVector/$$ with elements -of type $code size_t$$. - -$head test$$ -The $code speed_test$$ argument $icode test$$ is a function with the syntax -$codei% - %test%(%size%, %repeat%) -%$$ -and its return value is $code void$$. - -$subhead size$$ -The $icode test$$ argument $icode size$$ has prototype -$codei% - size_t %size% -%$$ -It specifies the size for this test. - -$subhead repeat$$ -The $icode test$$ argument $icode repeat$$ has prototype -$codei% - size_t %repeat% -%$$ -It specifies the number of times to repeat the test. - -$head size_vec$$ -The $code speed_test$$ argument $icode size_vec$$ has prototype -$codei% - const %Vector%& %size_vec% -%$$ -This vector determines the size for each of the tests problems. - -$head time_min$$ -The argument $icode time_min$$ has prototype -$codei% - double %time_min% -%$$ -It specifies the minimum amount of time in seconds -that the $icode test$$ routine should take. -The $icode repeat$$ argument to $icode test$$ is increased -until this amount of execution time is reached. - -$head rate_vec$$ -The return value $icode rate_vec$$ has prototype -$codei% - %Vector%& %rate_vec% -%$$ -We use $latex n$$ to denote its size which is the same as -the vector $icode size_vec$$. -For $latex i = 0 , \ldots , n-1$$, -$codei% - %rate_vec%[%i%] -%$$ -is the ratio of $icode repeat$$ divided by time in seconds -for the problem with size $icode%size_vec%[%i%]%$$. - -$head Timing$$ -If your system supports the unix $code gettimeofday$$ function, -it will be used to measure time. -Otherwise, -time is measured by the difference in -$codep - (double) clock() / (double) CLOCKS_PER_SEC -$$ -in the context of the standard $code $$ definitions. - -$children% - speed/example/speed_test.cpp -%$$ -$head Example$$ -The routine $cref speed_test.cpp$$ is an example and test -of $code speed_test$$. - -$end ------------------------------------------------------------------------ -*/ - -# include -# include - -# include -# include - - -namespace CppAD { // BEGIN CppAD namespace - -// implemented as an inline so that can include in multiple link modules -// with this same file -template -inline Vector speed_test( - void test(size_t size, size_t repeat), - const Vector& size_vec , - double time_min ) -{ - // check that size_vec is a simple vector with size_t elements - CheckSimpleVector(); - - size_t n = size_vec.size(); - Vector rate_vec(n); - size_t i; - for(i = 0; i < n; i++) - { size_t size = size_vec[i]; - size_t repeat = 1; - double s0 = elapsed_seconds(); - double s1 = elapsed_seconds(); - while( s1 - s0 < time_min ) - { repeat = 2 * repeat; - s0 = elapsed_seconds(); - test(size, repeat); - s1 = elapsed_seconds(); - } - double rate = .5 + double(repeat) / (s1 - s0); - // first convert to float to avoid warning with g++ -Wconversion - rate_vec[i] = static_cast( static_cast(rate) ); - } - return rate_vec; -} - -} // END CppAD namespace - -/* -$begin SpeedTest$$ -$spell - cppad.hpp - Microsoft - namespace - std - const - cout - ctime - ifdef - const - endif - cpp -$$ - - -$section Run One Speed Test and Print Results$$ -$mindex SpeedTest$$ - -$head Syntax$$ - -$codei%# include -%$$ -$codei%SpeedTest(%Test%, %first%, %inc%, %last%)%$$ - - -$head Purpose$$ -The $code SpeedTest$$ function executes a speed test -for various sized problems -and reports the results on standard output; i.e. $code std::cout$$. -The size of each test problem is included in its report -(unless $icode first$$ is equal to $icode last$$). - -$head Motivation$$ -It is important to separate small calculation units -and test them individually. -This way individual changes can be tested in the context of the -routine that they are in. -On many machines, accurate timing of a very short execution -sequences is not possible. -In addition, -there may be set up time for a test that -we do not really want included in the timing. -For this reason $code SpeedTest$$ -automatically determines how many times to -repeat the section of the test that we wish to time. - - -$head Include$$ -The file $code speed_test.hpp$$ contains the -$code SpeedTest$$ function. -This file is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head Test$$ -The $code SpeedTest$$ argument $icode Test$$ is a function with the syntax -$codei% - %name% = %Test%(%size%, %repeat%) -%$$ - -$subhead size$$ -The $icode Test$$ argument $icode size$$ has prototype -$codei% - size_t %size% -%$$ -It specifies the size for this test. - -$subhead repeat$$ -The $icode Test$$ argument $icode repeat$$ has prototype -$codei% - size_t %repeat% -%$$ -It specifies the number of times to repeat the test. - -$subhead name$$ -The $icode Test$$ result $icode name$$ has prototype -$codei% - std::string %name% -%$$ -The results for this test are reported on $code std::cout$$ -with $icode name$$ as an identifier for the test. -It is assumed that, -for the duration of this call to $code SpeedTest$$, -$icode Test$$ will always return -the same value for $icode name$$. -If $icode name$$ is the empty string, -no test name is reported by $code SpeedTest$$. - -$head first$$ -The $code SpeedTest$$ argument $icode first$$ has prototype -$codei% - size_t %first% -%$$ -It specifies the size of the first test problem reported by this call to -$code SpeedTest$$. - -$head last$$ -The $code SpeedTest$$ argument $icode last$$ has prototype -$codei% - size_t %last% -%$$ -It specifies the size of the last test problem reported by this call to -$code SpeedTest$$. - -$head inc$$ -The $code SpeedTest$$ argument $icode inc$$ has prototype -$codei% - int %inc% -%$$ -It specifies the increment between problem sizes; i.e., -all values of $icode size$$ in calls to $icode Test$$ are given by -$codei% - %size% = %first% + %j% * %inc% -%$$ -where $icode j$$ is a positive integer. -The increment can be positive or negative but it cannot be zero. -The values $icode first$$, $icode last$$ and $icode inc$$ must -satisfy the relation -$latex \[ - inc * ( last - first ) \geq 0 -\] $$ - -$head rate$$ -The value displayed in the $code rate$$ column on $code std::cout$$ -is defined as the value of $icode repeat$$ divided by the -corresponding elapsed execution time in seconds. -The elapsed execution time is measured by the difference in -$codep - (double) clock() / (double) CLOCKS_PER_SEC -$$ -in the context of the standard $code $$ definitions. - - -$head Errors$$ -If one of the restrictions above is violated, -the CppAD error handler is used to report the error. -You can redefine this action using the instructions in -$cref ErrorHandler$$ - -$head Example$$ -$children% - speed/example/speed_program.cpp -%$$ -The program $cref speed_program.cpp$$ is an example usage -of $code SpeedTest$$. - -$end ------------------------------------------------------------------------ -*/ -// BEGIN C++ - - -# include -# include -# include -# include - -namespace CppAD { // BEGIN CppAD namespace - -inline void SpeedTestNdigit(size_t value, size_t &ndigit, size_t &pow10) -{ pow10 = 10; - ndigit = 1; - while( pow10 <= value ) - { pow10 *= 10; - ndigit += 1; - } -} - -// implemented as an inline so that can include in multiple link modules -// with this same file -inline void SpeedTest( - std::string Test(size_t size, size_t repeat), - size_t first, - int inc, - size_t last -) -{ - - using std::cout; - using std::endl; - - size_t size; - size_t repeat; - size_t rate; - size_t digit; - size_t ndigit; - size_t pow10; - size_t maxSize; - size_t maxSizeDigit; - - double s0; - double s1; - - std::string name; - - CPPAD_ASSERT_KNOWN( - inc != 0 && first != 0 && last != 0, - "inc, first, or last is zero in call to SpeedTest" - ); - CPPAD_ASSERT_KNOWN( - (inc > 0 && first <= last) || (inc < 0 && first >= last), - "SpeedTest: increment is positive and first > last or " - "increment is negative and first < last" - ); - - // compute maxSize - maxSize = size = first; - while( (inc > 0 && size <= last) || (inc < 0 && size >= last) ) - { - if( size > maxSize ) - maxSize = size; - - // next size - if( ((int) size) + inc > 0 ) - size += inc; - else size = 0; - } - SpeedTestNdigit(maxSize, maxSizeDigit, pow10); - - size = first; - while( (inc > 0 && size <= last) || (inc < 0 && size >= last) ) - { - repeat = 1; - s0 = elapsed_seconds(); - s1 = elapsed_seconds(); - while( s1 - s0 < 1. ) - { repeat = 2 * repeat; - s0 = elapsed_seconds(); - name = Test(size, repeat); - s1 = elapsed_seconds(); - } - double r = .5 + double(repeat) / (s1 - s0); - // first convert to float to avoid warning with g++ -Wconversion - rate = static_cast( static_cast( r ) ); - - if( size == first && name != "" ) - cout << name << endl; - - if( first != last ) - { - // convert int(size_t) to avoid warning on _MSC_VER sys - std::cout << "size = " << int(size); - - SpeedTestNdigit(size, ndigit, pow10); - while( ndigit < maxSizeDigit ) - { cout << " "; - ndigit++; - } - cout << " "; - } - - cout << "rate = "; - SpeedTestNdigit(rate, ndigit, pow10); - while( ndigit > 0 ) - { - pow10 /= 10; - digit = rate / pow10; - - // convert int(size_t) to avoid warning on _MSC_VER sys - std::cout << int(digit); - - rate = rate % pow10; - ndigit -= 1; - - if( (ndigit > 0) && (ndigit % 3 == 0) ) - cout << ","; - } - cout << endl; - - // next size - if( ((int) size) + inc > 0 ) - size += inc; - else size = 0; - } - return; -} - -} // END CppAD namespace - -// END C++ -# endif diff --git a/external/cppad/include/cppad/utility/test_boolofvoid.hpp b/external/cppad/include/cppad/utility/test_boolofvoid.hpp deleted file mode 100644 index eb45a908f..000000000 --- a/external/cppad/include/cppad/utility/test_boolofvoid.hpp +++ /dev/null @@ -1,166 +0,0 @@ -# ifndef CPPAD_UTILITY_TEST_BOOLOFVOID_HPP -# define CPPAD_UTILITY_TEST_BOOLOFVOID_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin test_boolofvoid$$ -$spell - boolofvoid - const - std - bool - ipopt - cpp -$$ - -$section Object that Runs a Group of Tests$$ - -$head Syntax$$ -$codei%test_boolofvoid %Run%(%group%, %width%) -%$$ -$icode%Run%(%test%, %name%) -%$$ -$icode%ok% = %Run%.summary(%memory_ok%)%$$ - -$head Purpose$$ -The object $icode Run$$ is used to run a group of tests functions -and report the results on standard output. - -$head group$$ -The argument has prototype -$codei% - const std::string& %group% -%$$ -It is the name for this group of tests. - -$head width$$ -The argument has prototype -$codei% - size_t %width% -%$$ -It is the number of columns used to display the name of each test. -It must be greater than the maximum number of characters in a test name. - -$head test$$ -The argument has prototype -$codei% - bool %test%(void) -%$$ -It is a function that returns true (when the test passes) and false -otherwise. - -$head name$$ -The argument has prototype -$codei% - const std::string& %name% -%$$ -It is the name for the corresponding $icode test$$. - -$head memory_ok$$ -The argument has prototype -$codei% - bool %memory_ok% -%$$ -It is false if a memory leak is detected (and true otherwise). - -$head ok$$ -This is true if all of the tests pass (including the memory leak test), -otherwise it is false. - -$head Example$$ -See any of the main programs in the example directory; e.g., -$code example/ipopt_solve.cpp$$. - -$end -*/ - -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE - -/// One class object is used to run a group of tests -class test_boolofvoid { -private: - /// name for the group of test this object will run - const std::string group_; - /// number of characters used to display the name for each indiviual test - /// (must be larger than the number of characters in name for each test) - const size_t width_; - /// number of tests that have passed - size_t n_ok_; - /// number of tests that have failed - size_t n_error_; - -public: - /// ctor - test_boolofvoid(const std::string& group, size_t width) : - group_(group) , - width_(width) , - n_ok_(0) , - n_error_(0) - { std::cout << "Begin test group " << group_ << std::endl; } - /// destructor - ~test_boolofvoid(void) - { std::cout << "End test group " << group_ << std::endl; } - /// run one test - bool operator()(bool test(void), const std::string& name) - { CPPAD_ASSERT_KNOWN( - name.size() < width_ , - "test_boolofvoid: name does not have less characters than width" - ); - std::cout.width( width_ ); - std::cout.setf( std::ios_base::left ); - std::cout << name; - // - bool ok = test(); - if( ok ) - { std::cout << "OK" << std::endl; - n_ok_++; - } - else - { std::cout << "Error" << std::endl; - n_error_++; - } - return ok; - } - /// nuber of tests that passed - size_t n_ok(void) const - { return n_ok_; } - /// nuber of tests that failed - size_t n_error(void) const - { return n_error_; } - /// summary - bool summary(bool memory_ok ) - { - std::cout.width( width_ ); - std::cout.setf( std::ios_base::left ); - std::cout << "memory_leak"; - // - if( memory_ok ) - { std::cout << "OK" << std::endl; - n_ok_++; - } - else - { std::cout << "Error" << std::endl; - n_error_++; - } - if( n_error_ == 0 ) - std::cout << "All " << n_ok_ << " tests passed." << std::endl; - else - std::cout << n_error_ << " tests failed." << std::endl; - // - return n_error_ == 0; - } -}; - -} // END_CPPAD_NAMESPACE - -# endif diff --git a/external/cppad/include/cppad/utility/thread_alloc.hpp b/external/cppad/include/cppad/utility/thread_alloc.hpp deleted file mode 100644 index 45b2fc348..000000000 --- a/external/cppad/include/cppad/utility/thread_alloc.hpp +++ /dev/null @@ -1,1524 +0,0 @@ -# ifndef CPPAD_UTILITY_THREAD_ALLOC_HPP -# define CPPAD_UTILITY_THREAD_ALLOC_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -# include -# include -# include - - -# ifdef _MSC_VER -// Supress warning that Microsoft compiler changed its behavior and is now -// doing the correct thing at the statement: -// new(array + i) Type(); -# pragma warning(disable:4345) -# endif - -# include -# include -# include -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file thread_alloc.hpp -File used to define the CppAD multi-threading allocator class -*/ - -/*! -\def CPPAD_MAX_NUM_CAPACITY -Maximum number of different capacities the allocator will attempt. -This must be larger than the log base two of numeric_limit::max(). -*/ -# define CPPAD_MAX_NUM_CAPACITY 100 - -/*! -\def CPPAD_MIN_DOUBLE_CAPACITY -Minimum number of double values that will fit in an allocation. -*/ -# define CPPAD_MIN_DOUBLE_CAPACITY 16 - -/*! -\def CPPAD_TRACE_CAPACITY -If NDEBUG is not defined, print all calls to \c get_memory and \c return_memory -that correspond to this capacity and thread CPPAD_TRACE_THREAD. -(Note that if CPPAD_TRACE_CAPACITY is zero, or any other value not in the list -of capacities, no tracing will be done.) -*/ -# define CPPAD_TRACE_CAPACITY 0 - -/*! -\def CPPAD_TRACE_THREAD -If NDEBUG is not defined, print all calls to \c get_memory and \c return_memory -that correspond to this thead and capacity CPPAD_TRACE_CAPACITY. -*/ -# define CPPAD_TRACE_THREAD 0 - -/* -Note that Section 3.6.2 of ISO/IEC 14882:1998(E) states: "The storage for -objects with static storage duration (3.7.1) shall be zero-initialized -(8.5) before any other initialization takes place." -*/ - -/*! -Capacity vector for memory allocation block sizes. - -Only one of these objects should be created and used as a -static variable inside of the \c thread_alloc::capacity_info function. -*/ - -/*! -Allocator class that works well with an multi-threading environment. -*/ -class thread_alloc{ -// ============================================================================ -private: - - class capacity_t { - public: - /// number of capacity values actually used - size_t number; - /// the different capacity values - size_t value[CPPAD_MAX_NUM_CAPACITY]; - /// ctor - capacity_t(void) - { // Cannot figure out how to call thread_alloc::in_parallel here. - // CPPAD_ASSERT_UNKNOWN( - // ! thread_alloc::in_parallel() , "thread_alloc: " - // "parallel mode and parallel_setup not yet called." - // ); - number = 0; - size_t capacity = CPPAD_MIN_DOUBLE_CAPACITY * sizeof(double); - while( capacity < std::numeric_limits::max() / 2 ) - { CPPAD_ASSERT_UNKNOWN( number < CPPAD_MAX_NUM_CAPACITY ); - value[number++] = capacity; - // next capactiy is 3/2 times the current one - capacity = 3 * ( (capacity + 1) / 2 ); - } - CPPAD_ASSERT_UNKNOWN( number > 0 ); - } - }; - - class block_t { - public: - /// extra information (currently used by create and delete array) - size_t extra_; - /// an index that uniquely idenfifies both thread and capacity - size_t tc_index_; - /// pointer to the next memory allocation with the same tc_index_ - void* next_; - // ----------------------------------------------------------------- - /// make default constructor private. It is only used by constructor - /// for `root arrays below. - block_t(void) : extra_(0), tc_index_(0), next_(CPPAD_NULL) - { } - }; - - // --------------------------------------------------------------------- - /// Vector of fixed capacity values for this allocator - static const capacity_t* capacity_info(void) - { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - static const capacity_t capacity; - return &capacity; - } - // --------------------------------------------------------------------- - /// Structure of information for each thread - struct thread_alloc_info { - /// count of available bytes for this thread - size_t count_inuse_; - /// count of inuse bytes for this thread - size_t count_available_; - /// root of available list for this thread and each capacity - block_t root_available_[CPPAD_MAX_NUM_CAPACITY]; - /*! - root of inuse list for this thread and each capacity - If NDEBUG or CPPAD_DEBUG_AND_RELEASE is defined, this memory is not - used, but it still helps to separate this structure from the structure - for the next thread. - */ - block_t root_inuse_[CPPAD_MAX_NUM_CAPACITY]; - }; - // --------------------------------------------------------------------- - /*! - Set and Get hold available memory flag. - - \param set [in] - if true, the value returned by this return is changed. - - \param new_value [in] - if \a set is true, this is the new value returned by this routine. - Otherwise, \c new_value is ignored. - - \return - the current setting for this routine (which is initially false). - */ - static bool set_get_hold_memory(bool set, bool new_value = false) - { static bool value = false; - if( set ) - value = new_value; - return value; - } - // --------------------------------------------------------------------- - /*! - Get pointer to the information for this thread. - - \param thread [in] - Is the thread number for this information pointer. - - \param clear - If \a clear is true, then the information pointer for this thread - is deleted and the \c CPPAD_NULL pointer is returned. - There must be no memory currently in either the inuse or avaialble - lists when this routine is called. - - \return - is the current informaiton pointer for this thread. - If \a clear is false, and the current pointer is CPPAD_NULL, - a new infromation record is allocated and its pointer returned. - In this case, if \c info is the retured pointer, - info->count_inuse == 0 and - info->count_available == 0. - In addition, - for c = 0 , ... , CPPAD_MAX_NUM_CAPACITY-1 - info->root_inuse_[c].next_ == CPPAD_NULL and - info->root_available_[c].next_ == CPPAD_NULL. - */ - static thread_alloc_info* thread_info( - size_t thread , - bool clear = false ) - { static thread_alloc_info* all_info[CPPAD_MAX_NUM_THREADS]; - static thread_alloc_info zero_info; - - CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - - CPPAD_ASSERT_UNKNOWN( thread < CPPAD_MAX_NUM_THREADS ); - - thread_alloc_info* info = all_info[thread]; - if( clear ) - { if( info != CPPAD_NULL ) - { -# ifndef NDEBUG - CPPAD_ASSERT_UNKNOWN( - info->count_inuse_ == 0 && - info->count_available_ == 0 - ); - for(size_t c = 0; c < CPPAD_MAX_NUM_CAPACITY; c++) - { CPPAD_ASSERT_UNKNOWN( - info->root_inuse_[c].next_ == CPPAD_NULL && - info->root_available_[c].next_ == CPPAD_NULL - ); - } -# endif - if( thread != 0 ) - ::operator delete( reinterpret_cast(info) ); - info = CPPAD_NULL; - all_info[thread] = info; - } - } - else if( info == CPPAD_NULL ) - { if( thread == 0 ) - info = &zero_info; - else - { size_t size = sizeof(thread_alloc_info); - void* v_ptr = ::operator new(size); - info = reinterpret_cast(v_ptr); - } - all_info[thread] = info; - - // initialize the information record - for(size_t c = 0; c < CPPAD_MAX_NUM_CAPACITY; c++) - { info->root_inuse_[c].next_ = CPPAD_NULL; - info->root_available_[c].next_ = CPPAD_NULL; - } - info->count_inuse_ = 0; - info->count_available_ = 0; - } - return info; - } - // ----------------------------------------------------------------------- - /*! - Increase the number of bytes of memory that are currently in use; i.e., - that been obtained with \c get_memory and not yet returned. - - \param inc [in] - amount to increase memory in use. - - \param thread [in] - Thread for which we are increasing the number of bytes in use - (must be less than \c num_threads). - Durring parallel execution, this must be the thread - that is currently executing. - */ - static void inc_inuse(size_t inc, size_t thread) - { - CPPAD_ASSERT_UNKNOWN( thread < num_threads() ); - CPPAD_ASSERT_UNKNOWN( - thread == thread_num() || (! in_parallel()) - ); - thread_alloc_info* info = thread_info(thread); - - // do the addition - size_t result = info->count_inuse_ + inc; - CPPAD_ASSERT_UNKNOWN( result >= info->count_inuse_ ); - - info->count_inuse_ = result; - } - // ----------------------------------------------------------------------- - /*! - Increase the number of bytes of memory that are currently avaialble; i.e., - have been obtained obtained from the system and are being held future use. - - \copydetails inc_inuse - */ - static void inc_available(size_t inc, size_t thread) - { - CPPAD_ASSERT_UNKNOWN( thread < CPPAD_MAX_NUM_THREADS); - CPPAD_ASSERT_UNKNOWN( - thread == thread_num() || (! in_parallel()) - ); - thread_alloc_info* info = thread_info(thread); - // do the addition - size_t result = info->count_available_ + inc; - CPPAD_ASSERT_UNKNOWN( result >= info->count_available_ ); - - info->count_available_ = result; - } - // ----------------------------------------------------------------------- - /*! - Decrease the number of bytes of memory that are currently in use; i.e., - that been obtained with \c get_memory and not yet returned. - - \param dec [in] - amount to decrease number of bytes in use. - - \param thread [in] - Thread for which we are decreasing the number of bytes in use - (must be less than \c num_threads). - Durring parallel execution, this must be the thread - that is currently executing. - */ - static void dec_inuse(size_t dec, size_t thread) - { - CPPAD_ASSERT_UNKNOWN( - thread < num_threads() || (! in_parallel()) - ); - CPPAD_ASSERT_UNKNOWN( - thread == thread_num() || (! in_parallel()) - ); - thread_alloc_info* info = thread_info(thread); - - // do the subtraction - CPPAD_ASSERT_UNKNOWN( info->count_inuse_ >= dec ); - info->count_inuse_ = info->count_inuse_ - dec; - } - // ----------------------------------------------------------------------- - /*! - Decrease the number of bytes of memory that are currently avaialble; i.e., - have been obtained obtained from the system and are being held future use. - - \copydetails dec_inuse - */ - static void dec_available(size_t dec, size_t thread) - { - CPPAD_ASSERT_UNKNOWN( thread < CPPAD_MAX_NUM_THREADS); - CPPAD_ASSERT_UNKNOWN( - thread == thread_num() || (! in_parallel()) - ); - thread_alloc_info* info = thread_info(thread); - // do the subtraction - CPPAD_ASSERT_UNKNOWN( info->count_available_ >= dec ); - info->count_available_ = info->count_available_ - dec; - } - - // ---------------------------------------------------------------------- - /*! - Set and get the number of threads that are sharing memory. - - \param number_new - If \c number is zero, we are only retreiving the current maximum - number of threads. Otherwise, we are setting and retreiving - maximum number of threads. - - \return - the number of threads that are sharing memory. - If \c number_new is non-zero, the return value is equal to - \c number_new. - */ - static size_t set_get_num_threads(size_t number_new) - { static size_t number_user = 1; - - CPPAD_ASSERT_UNKNOWN( number_new <= CPPAD_MAX_NUM_THREADS ); - CPPAD_ASSERT_UNKNOWN( ! in_parallel() || (number_new == 0) ); - - // case where we are changing the number of threads - if( number_new != 0 ) - number_user = number_new; - - return number_user; - } - /*! - Set and call the routine that determine the current thread number. - - \return - returns value for the most recent setting for \a thread_num_new. - If \a set is true, - or the most recent setting is \c CPPAD_NULL (its initial value), - the return value is zero. - Otherwise the routine corresponding to the most recent setting - is called and its value returned by \c set_get_thread_num. - - \param thread_num_new [in] - If \a set is false, \a thread_num_new it is not used. - Otherwise, the current value of \c thread_num_new becomes the - most recent setting for thread_num. - - \param set - If \a set is true, then \a thread_num_new is becomes the most - recent setting for this \c set_get_thread_num. - */ - static size_t set_get_thread_num( - size_t (*thread_num_new)(void) , - bool set = false ) - { static size_t (*thread_num_user)(void) = CPPAD_NULL; - - if( set ) - { thread_num_user = thread_num_new; - return 0; - } - - if( thread_num_user == CPPAD_NULL ) - return 0; - - size_t thread = thread_num_user(); - CPPAD_ASSERT_KNOWN( - thread < set_get_num_threads(0) , - "parallel_setup: thread_num() >= num_threads" - ); - return thread; - } -// ============================================================================ -public: -/* -$begin ta_parallel_setup$$ -$spell - alloc - num - bool -$$ -$section Setup thread_alloc For Use in Multi-Threading Environment$$ -$mindex parallel initialize$$ - - - - -$head Syntax$$ -$codei%thread_alloc::parallel_setup(%num_threads%, %in_parallel%, %thread_num%) -%$$ - -$head Purpose$$ -By default there is only one thread and all execution is in sequential mode, -i.e., multiple threads are not sharing the same memory; i.e. -not in parallel mode. - -$head Speed$$ -It should be faster, even when $icode num_thread$$ is equal to one, -for $code thread_alloc$$ to hold onto memory. -This can be accomplished using the function call -$codei% - thread_alloc::hold_memory(true) -%$$ -see $cref/hold_memory/ta_hold_memory/$$. - -$head num_threads$$ -This argument has prototype -$codei% - size_t %num_threads% -%$$ -and must be greater than zero. -It specifies the number of threads that are sharing memory. -The case $icode%num_threads% == 1%$$ is a special case that is -used to terminate a multi-threading environment. - -$head in_parallel$$ -This function has prototype -$codei% - bool %in_parallel%(void) -%$$ -It must return $code true$$ if there is more than one thread -currently executing. -Otherwise it can return false. -$pre - -$$ -In the special case where $icode%num_threads% == 1%$$, -the routine $icode in_parallel$$ is not used. - -$head thread_num$$ -This function has prototype -$codei% - size_t %thread_num%(void) -%$$ -It must return a thread number that uniquely identifies the -currently executing thread. -Furthermore -$codei% - 0 <= %thread_num%() < %num_threads% -%$$. -In the special case where $icode%num_threads% == 1%$$, -the routine $icode thread_num$$ is not used. -$pre - -$$ -Note that this function is called by other routines so, -as soon as a new thread is executing, -one must be certain that $icode thread_num()$$ will -work for that thread. - -$head Restrictions$$ -The function $code parallel_setup$$ must be called before -the program enters $cref/parallel/ta_in_parallel/$$ execution mode. -In addition, this function cannot be called while in parallel mode. - -$head Example$$ -The files -$cref simple_ad_openmp.cpp$$, -$cref simple_ad_bthread.cpp$$, and -$cref simple_ad_pthread.cpp$$, -contain examples and tests that use this function. - -$end -*/ - /*! - Set thread_alloc up for parallel mode usage. - - \param num_threads [in] - Is the number of thread that may be executing at the same time. - - \param in_parallel [in] - Is the routine that determines if we are in parallel mode or not. - - \param thread_num [in] - Is the routine that determines the current thread number - (between zero and num_threads minus one). - */ - static void parallel_setup( - size_t num_threads , - bool (*in_parallel)(void) , - size_t (*thread_num)(void) ) - { - // Special case where we go back to single thread mode right away - // (previous settings may no longer be valid) - if( num_threads == 1 ) - { bool set = true; - set_get_num_threads(num_threads); - // emphasize that this routine is outside thread_alloc class - CppAD::local::set_get_in_parallel(CPPAD_NULL, set); - set_get_thread_num(CPPAD_NULL, set); - return; - } - - CPPAD_ASSERT_KNOWN( - num_threads <= CPPAD_MAX_NUM_THREADS , - "parallel_setup: num_threads is too large" - ); - CPPAD_ASSERT_KNOWN( - num_threads != 0 , - "parallel_setup: num_threads == zero" - ); - CPPAD_ASSERT_KNOWN( - in_parallel != CPPAD_NULL , - "parallel_setup: num_threads != 1 and in_parallel == CPPAD_NULL" - ); - CPPAD_ASSERT_KNOWN( - thread_num != CPPAD_NULL , - "parallel_setup: num_threads != 1 and thread_num == CPPAD_NULL" - ); - - // Make sure that constructors for all static variables in this file - // are called in sequential mode. - for(size_t thread = 0; thread < num_threads; thread++) - thread_info(thread); - capacity_info(); - size_t cap_bytes; - void* v_ptr = get_memory(0, cap_bytes); - - // free memory allocated by call to get_memory above - return_memory(v_ptr); - free_available( set_get_thread_num(CPPAD_NULL) ); - - // delay this so thread_num() call above is in previous mode - // (current setings may not yet be valid) - if( num_threads > 1 ) - { bool set = true; - set_get_num_threads(num_threads); - // emphasize that this routine is outside thread_alloc class - CppAD::local::set_get_in_parallel(in_parallel, set); - set_get_thread_num(thread_num, set); - } - } -/* -$begin ta_num_threads$$ -$spell - inv - CppAD - num - alloc -$$ -$section Get Number of Threads$$ - - -$head Syntax$$ -$icode%number% = thread_alloc::num_threads()%$$ - -$head Purpose$$ -Determine the number of threads as set during $cref/parallel_setup/ta_parallel_setup/$$. - -$head number$$ -The return value $icode number$$ has prototype -$codei% - size_t %number% -%$$ -and is equal to the value of -$cref/num_threads/ta_parallel_setup/num_threads/$$ -in the previous call to $icode parallel_setup$$. -If there was no such previous call, the value one is returned. - -$head Example$$ -The example and test $cref thread_alloc.cpp$$ uses this routine. - -$end -*/ - /*! - Get the current number of threads that thread_alloc can use. - */ - static size_t num_threads(void) - { return set_get_num_threads(0); } -/* ----------------------------------------------------------------------- -$begin ta_in_parallel$$ - -$section Is The Current Execution in Parallel Mode$$ -$mindex sequential$$ -$spell - thread_alloc - bool -$$ - - -$head Syntax$$ -$icode%flag% = thread_alloc::in_parallel()%$$ - -$head Purpose$$ -Some of the $cref thread_alloc$$ allocation routines have different -specifications for parallel (not sequential) execution mode. -This routine enables you to determine if the current execution mode -is sequential or parallel. - -$head flag$$ -The return value has prototype -$codei% - bool %flag% -%$$ -It is true if the current execution is in parallel mode -(possibly multi-threaded) and false otherwise (sequential mode). - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /// Are we in a parallel execution state; i.e., is it possible that - /// other threads are currently executing. - static bool in_parallel(void) - { // emphasize that this routine is outside thread_alloc class - return CppAD::local::set_get_in_parallel(0); - } -/* ----------------------------------------------------------------------- -$begin ta_thread_num$$ -$spell - CppAD - num - thread_alloc - cppad.hpp -$$ - -$section Get the Current Thread Number$$ - - -$head Syntax$$ -$icode%thread% = thread_alloc::thread_num()%$$ - -$head Purpose$$ -Some of the $cref thread_alloc$$ allocation routines have a thread number. -This routine enables you to determine the current thread. - -$head thread$$ -The return value $icode thread$$ has prototype -$codei% - size_t %thread% -%$$ -and is the currently executing thread number. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /// Get current thread number - static size_t thread_num(void) - { return set_get_thread_num(CPPAD_NULL); } -/* ----------------------------------------------------------------------- -$begin ta_get_memory$$ -$spell - std - num - ptr - thread_alloc -$$ - -$section Get At Least A Specified Amount of Memory$$ -$mindex allocate$$ - - -$head Syntax$$ -$icode%v_ptr% = thread_alloc::get_memory(%min_bytes%, %cap_bytes%)%$$ - -$head Purpose$$ -Use $cref thread_alloc$$ to obtain a minimum number of bytes of memory -(for use by the $cref/current thread/ta_thread_num/$$). - -$head min_bytes$$ -This argument has prototype -$codei% - size_t %min_bytes% -%$$ -It specifies the minimum number of bytes to allocate. -This value must be less than -$codep - std::numeric_limits::max() / 2 -$$ - -$head cap_bytes$$ -This argument has prototype -$codei% - size_t& %cap_bytes% -%$$ -It's input value does not matter. -Upon return, it is the actual number of bytes (capacity) -that have been allocated for use, -$codei% - %min_bytes% <= %cap_bytes% -%$$ - -$head v_ptr$$ -The return value $icode v_ptr$$ has prototype -$codei% - void* %v_ptr% -%$$ -It is the location where the $icode cap_bytes$$ of memory -that have been allocated for use begins. - -$head Allocation Speed$$ -This allocation should be faster if the following conditions hold: -$list number$$ -The memory allocated by a previous call to $code get_memory$$ -is currently available for use. -$lnext -The current $icode min_bytes$$ is between -the previous $icode min_bytes$$ and previous $icode cap_bytes$$. -$lend - -$head Alignment$$ -We call a memory allocation aligned if the address is a multiple -of the number of bytes in a $code size_t$$ value. -If the system $code new$$ allocator is aligned, then $icode v_ptr$$ -pointer is also aligned. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Use thread_alloc to get a specified amount of memory. - - If the memory allocated by a previous call to \c get_memory is now - avaialable, and \c min_bytes is between its previous value - and the previous \c cap_bytes, this memory allocation will have - optimal speed. Otherwise, the memory allocation is more complicated and - may have to wait for other threads to complete an allocation. - - \param min_bytes [in] - The minimum number of bytes of memory to be obtained for use. - - \param cap_bytes [out] - The actual number of bytes of memory obtained for use. - - \return - pointer to the beginning of the memory allocated for use. - */ - static void* get_memory(size_t min_bytes, size_t& cap_bytes) - { // see first_trace below - CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; - - // check that number of requested bytes is not to large - CPPAD_ASSERT_KNOWN( - min_bytes < std::numeric_limits::max() / 2 , - "get_memory(min_bytes, cap_bytes): min_bytes is too large" - ); - - size_t num_cap = capacity_info()->number; - using std::cout; - using std::endl; - - // determine the capacity for this request - size_t c_index = 0; - const size_t* capacity_vec = capacity_info()->value; - while( capacity_vec[c_index] < min_bytes ) - { ++c_index; - CPPAD_ASSERT_UNKNOWN(c_index < num_cap ); - } - cap_bytes = capacity_vec[c_index]; - - // determine the thread, capacity, and info for this thread - size_t thread = thread_num(); - size_t tc_index = thread * num_cap + c_index; - thread_alloc_info* info = thread_info(thread); - -# ifndef NDEBUG - // trace allocation - static bool first_trace = true; - if( cap_bytes == CPPAD_TRACE_CAPACITY && - thread == CPPAD_TRACE_THREAD && first_trace ) - { cout << endl; - cout << "thread_alloc: Trace for Thread = " << thread; - cout << " and capacity = " << cap_bytes << endl; - if( first_trace ) - first_trace = false; - } - -# ifndef CPPAD_DEBUG_AND_RELEASE - // Root nodes for both lists. Note these are different for different - // threads because tc_index is different for different threads. - block_t* inuse_root = info->root_inuse_ + c_index; -# endif -# endif - block_t* available_root = info->root_available_ + c_index; - - // check if we already have a node we can use - void* v_node = available_root->next_; - block_t* node = reinterpret_cast(v_node); - if( node != CPPAD_NULL ) - { CPPAD_ASSERT_UNKNOWN( node->tc_index_ == tc_index ); - - // remove node from available list - available_root->next_ = node->next_; - - // return value for get_memory - void* v_ptr = reinterpret_cast(node + 1); -# ifndef NDEBUG -# ifndef CPPAD_DEBUG_AND_RELEASE - // add node to inuse list - node->next_ = inuse_root->next_; - inuse_root->next_ = v_node; -# endif - - // trace allocation - if( cap_bytes == CPPAD_TRACE_CAPACITY && - thread == CPPAD_TRACE_THREAD ) - { cout << "get_memory: v_ptr = " << v_ptr << endl; } -# endif - - // adjust counts - inc_inuse(cap_bytes, thread); - dec_available(cap_bytes, thread); - - // return pointer to memory, do not inclue thread_alloc information - return v_ptr; - } - - // Create a new node with thread_alloc information at front. - // This uses the system allocator, which is thread safe, but slower, - // because the thread might wait for a lock on the allocator. - v_node = ::operator new(sizeof(block_t) + cap_bytes); - node = reinterpret_cast(v_node); - node->tc_index_ = tc_index; - void* v_ptr = reinterpret_cast(node + 1); - -# ifndef NDEBUG -# ifndef CPPAD_DEBUG_AND_RELEASE - // add node to inuse list - node->next_ = inuse_root->next_; - inuse_root->next_ = v_node; -# endif - - // trace allocation - if( cap_bytes == CPPAD_TRACE_CAPACITY && - thread == CPPAD_TRACE_THREAD ) - { cout << "get_memory: v_ptr = " << v_ptr << endl; } -# endif - - // adjust counts - inc_inuse(cap_bytes, thread); - - return v_ptr; - } - -/* ----------------------------------------------------------------------- -$begin ta_return_memory$$ -$spell - num - ptr - thread_alloc -$$ - -$section Return Memory to thread_alloc$$ -$mindex return_memory available$$ - - -$head Syntax$$ -$codei%thread_alloc::return_memory(%v_ptr%)%$$ - -$head Purpose$$ -If $cref/hold_memory/ta_hold_memory/$$ is false, -the memory is returned to the system. -Otherwise, the memory is retained by $cref thread_alloc$$ for quick future use -by the thread that allocated to memory. - -$head v_ptr$$ -This argument has prototype -$codei% - void* %v_ptr% -%$$. -It must be a pointer to memory that is currently in use; i.e. -obtained by a previous call to -$cref/get_memory/ta_get_memory/$$ and not yet returned. - -$head Thread$$ -Either the $cref/current thread/ta_thread_num/$$ must be the same as during -the corresponding call to $cref/get_memory/ta_get_memory/$$, -or the current execution mode must be sequential -(not $cref/parallel/ta_in_parallel/$$). - -$head NDEBUG$$ -If $code NDEBUG$$ is defined, $icode v_ptr$$ is not checked (this is faster). -Otherwise, a list of in use pointers is searched to make sure -that $icode v_ptr$$ is in the list. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Return memory that was obtained by \c get_memory. - If num_threads() == 1, - the memory is returned to the system. - Otherwise, it is retained by \c thread_alloc and available for use by - \c get_memory for this thread. - - \param v_ptr [in] - Value of the pointer returned by \c get_memory and still in use. - After this call, this pointer will available (and not in use). - - \par - We must either be in sequential (not parallel) execution mode, - or the current thread must be the same as for the corresponding call - to \c get_memory. - */ - static void return_memory(void* v_ptr) - { size_t num_cap = capacity_info()->number; - - block_t* node = reinterpret_cast(v_ptr) - 1; - size_t tc_index = node->tc_index_; - size_t thread = tc_index / num_cap; - size_t c_index = tc_index % num_cap; - size_t capacity = capacity_info()->value[c_index]; - - CPPAD_ASSERT_UNKNOWN( thread < CPPAD_MAX_NUM_THREADS ); - CPPAD_ASSERT_KNOWN( - thread == thread_num() || (! in_parallel()), - "Attempt to return memory for a different thread " - "while in parallel mode" - ); - - thread_alloc_info* info = thread_info(thread); -# ifndef NDEBUG -# ifndef CPPAD_DEBUG_AND_RELEASE - // remove node from inuse list - void* v_node = reinterpret_cast(node); - block_t* inuse_root = info->root_inuse_ + c_index; - block_t* previous = inuse_root; - while( (previous->next_ != CPPAD_NULL) & (previous->next_ != v_node) ) - previous = reinterpret_cast(previous->next_); - - // check that v_ptr is valid - if( previous->next_ != v_node ) - { using std::endl; - std::ostringstream oss; - oss << "return_memory: attempt to return memory not in use"; - oss << endl; - oss << "v_ptr = " << v_ptr << endl; - oss << "thread = " << thread << endl; - oss << "capacity = " << capacity << endl; - oss << "See CPPAD_TRACE_THREAD & CPPAD_TRACE_CAPACITY in"; - oss << endl << "%# include " << endl; - // oss.str() returns a string object with a copy of the current - // contents in the stream buffer. - std::string msg_str = oss.str(); - // msg_str.c_str() returns a pointer to the c-string - // representation of the string object's value. - const char* msg_char_star = msg_str.c_str(); - CPPAD_ASSERT_KNOWN(false, msg_char_star ); - } - // remove v_ptr from inuse list - previous->next_ = node->next_; -# endif - // trace option - if( capacity==CPPAD_TRACE_CAPACITY && thread==CPPAD_TRACE_THREAD ) - { std::cout << "return_memory: v_ptr = " << v_ptr << std::endl; } - -# endif - // capacity bytes are removed from the inuse pool - dec_inuse(capacity, thread); - - // check for case where we just return the memory to the system - if( ! set_get_hold_memory(false) ) - { ::operator delete( reinterpret_cast(node) ); - return; - } - - // add this node to available list for this thread and capacity - block_t* available_root = info->root_available_ + c_index; - node->next_ = available_root->next_; - available_root->next_ = reinterpret_cast(node); - - // capacity bytes are added to the available pool - inc_available(capacity, thread); - } -/* ----------------------------------------------------------------------- -$begin ta_free_available$$ -$spell - num - thread_alloc -$$ - -$section Free Memory Currently Available for Quick Use by a Thread$$ -$mindex free_available$$ -$spell - inuse -$$ - - -$head Syntax$$ -$codei%thread_alloc::free_available(%thread%)%$$ - -$head Purpose$$ -Return to the system all the memory that is currently being -$cref/held/ta_hold_memory/$$ for quick use by the specified thread. - -$subhead Extra Memory$$ -In the case where $icode%thread% > 0%$$, -some extra memory is used to track allocations by the specified thread. -If -$codei% - thread_alloc::inuse(%thread%) == 0 -%$$ -the extra memory is also returned to the system. - -$head thread$$ -This argument has prototype -$codei% - size_t %thread% -%$$ -Either $cref/thread_num/ta_thread_num/$$ must be the same as $icode thread$$, -or the current execution mode must be sequential -(not $cref/parallel/ta_in_parallel/$$). - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Return all the memory being held as available for a thread to the system. - - \param thread [in] - this thread that will no longer have any available memory after this call. - This must either be the thread currently executing, or we must be - in sequential (not parallel) execution mode. - */ - static void free_available(size_t thread) - { CPPAD_ASSERT_KNOWN( - thread < CPPAD_MAX_NUM_THREADS, - "Attempt to free memory for a thread >= CPPAD_MAX_NUM_THREADS" - ); - CPPAD_ASSERT_KNOWN( - thread == thread_num() || (! in_parallel()), - "Attempt to free memory for a different thread " - "while in parallel mode" - ); - - size_t num_cap = capacity_info()->number; - if( num_cap == 0 ) - return; - const size_t* capacity_vec = capacity_info()->value; - size_t c_index; - thread_alloc_info* info = thread_info(thread); - for(c_index = 0; c_index < num_cap; c_index++) - { size_t capacity = capacity_vec[c_index]; - block_t* available_root = info->root_available_ + c_index; - void* v_ptr = available_root->next_; - while( v_ptr != CPPAD_NULL ) - { block_t* node = reinterpret_cast(v_ptr); - void* next = node->next_; - ::operator delete(v_ptr); - v_ptr = next; - - dec_available(capacity, thread); - } - available_root->next_ = CPPAD_NULL; - } - CPPAD_ASSERT_UNKNOWN( available(thread) == 0 ); - if( inuse(thread) == 0 ) - { // clear the information for this thread - thread_info(thread, true); - } - } -/* ----------------------------------------------------------------------- -$begin ta_hold_memory$$ -$spell - alloc - num -$$ - -$section Control When Thread Alloc Retains Memory For Future Use$$ -$mindex hold$$ - -$head Syntax$$ -$codei%thread_alloc::hold_memory(%value%)%$$ - -$head Purpose$$ -It should be faster, even when $icode num_thread$$ is equal to one, -for $code thread_alloc$$ to hold onto memory. -Calling $icode hold_memory$$ with $icode value$$ equal to true, -instructs $code thread_alloc$$ to hold onto memory, -and put it in the $cref/available/ta_available/$$ pool, -after each call to $cref/return_memory/ta_return_memory/$$. - -$head value$$ -If $icode value$$ is true, -$code thread_alloc$$ with hold onto memory for future quick use. -If it is false, future calls to $cref/return_memory/ta_return_memory/$$ -will return the corresponding memory to the system. -By default (when $code hold_memory$$ has not been called) -$code thread_alloc$$ does not hold onto memory. - -$head free_available$$ -Memory that is being held by $code thread_alloc$$ can be returned -to the system using $cref/free_available/ta_free_available/$$. - -$end -*/ - /*! - Change the thread_alloc hold memory setting. - - \param value [in] - New value for the thread_alloc hold memory setting. - */ - static void hold_memory(bool value) - { bool set = true; - set_get_hold_memory(set, value); - } - -/* ----------------------------------------------------------------------- -$begin ta_inuse$$ -$spell - num - inuse - thread_alloc -$$ - -$section Amount of Memory a Thread is Currently Using$$ -$mindex inuse$$ - - -$head Syntax$$ -$icode%num_bytes% = thread_alloc::inuse(%thread%)%$$ - -$head Purpose$$ -Memory being managed by $cref thread_alloc$$ has two states, -currently in use by the specified thread, -and quickly available for future use by the specified thread. -This function informs the program how much memory is in use. - -$head thread$$ -This argument has prototype -$codei% - size_t %thread% -%$$ -Either $cref/thread_num/ta_thread_num/$$ must be the same as $icode thread$$, -or the current execution mode must be sequential -(not $cref/parallel/ta_in_parallel/$$). - -$head num_bytes$$ -The return value has prototype -$codei% - size_t %num_bytes% -%$$ -It is the number of bytes currently in use by the specified thread. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Determine the amount of memory that is currently inuse. - - \param thread [in] - Thread for which we are determining the amount of memory - (must be < CPPAD_MAX_NUM_THREADS). - Durring parallel execution, this must be the thread - that is currently executing. - - \return - The amount of memory in bytes. - */ - static size_t inuse(size_t thread) - { - CPPAD_ASSERT_UNKNOWN( thread < CPPAD_MAX_NUM_THREADS); - CPPAD_ASSERT_UNKNOWN( - thread == thread_num() || (! in_parallel()) - ); - thread_alloc_info* info = thread_info(thread); - return info->count_inuse_; - } -/* ----------------------------------------------------------------------- -$begin ta_available$$ -$spell - num - thread_alloc -$$ - -$section Amount of Memory Available for Quick Use by a Thread$$ - - -$head Syntax$$ -$icode%num_bytes% = thread_alloc::available(%thread%)%$$ - -$head Purpose$$ -Memory being managed by $cref thread_alloc$$ has two states, -currently in use by the specified thread, -and quickly available for future use by the specified thread. -This function informs the program how much memory is available. - -$head thread$$ -This argument has prototype -$codei% - size_t %thread% -%$$ -Either $cref/thread_num/ta_thread_num/$$ must be the same as $icode thread$$, -or the current execution mode must be sequential -(not $cref/parallel/ta_in_parallel/$$). - -$head num_bytes$$ -The return value has prototype -$codei% - size_t %num_bytes% -%$$ -It is the number of bytes currently available for use by the specified thread. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Determine the amount of memory that is currently available for use. - - \copydetails inuse - */ - static size_t available(size_t thread) - { - CPPAD_ASSERT_UNKNOWN( thread < CPPAD_MAX_NUM_THREADS); - CPPAD_ASSERT_UNKNOWN( - thread == thread_num() || (! in_parallel()) - ); - thread_alloc_info* info = thread_info(thread); - return info->count_available_; - } -/* ----------------------------------------------------------------------- -$begin ta_create_array$$ -$spell - inuse - thread_alloc - sizeof -$$ - -$section Allocate An Array and Call Default Constructor for its Elements$$ -$mindex create_array$$ - - -$head Syntax$$ -$icode%array% = thread_alloc::create_array<%Type%>(%size_min%, %size_out%)%$$. - -$head Purpose$$ -Create a new raw array using $cref thread_alloc$$ memory allocator -(works well in a multi-threading environment) -and call default constructor for each element. - -$head Type$$ -The type of the elements of the array. - -$head size_min$$ -This argument has prototype -$codei% - size_t %size_min% -%$$ -This is the minimum number of elements that there can be -in the resulting $icode array$$. - -$head size_out$$ -This argument has prototype -$codei% - size_t& %size_out% -%$$ -The input value of this argument does not matter. -Upon return, it is the actual number of elements -in $icode array$$ -($icode% size_min %<=% size_out%$$). - -$head array$$ -The return value $icode array$$ has prototype -$codei% - %Type%* %array% -%$$ -It is array with $icode size_out$$ elements. -The default constructor for $icode Type$$ is used to initialize the -elements of $icode array$$. -Note that $cref/delete_array/ta_delete_array/$$ -should be used to destroy the array when it is no longer needed. - -$head Delta$$ -The amount of memory $cref/inuse/ta_inuse/$$ by the current thread, -will increase $icode delta$$ where -$codei% - sizeof(%Type%) * (%size_out% + 1) > %delta% >= sizeof(%Type%) * %size_out% -%$$ -The $cref/available/ta_available/$$ memory will decrease by $icode delta$$, -(and the allocation will be faster) -if a previous allocation with $icode size_min$$ between its current value -and $icode size_out$$ is available. - -$head Alignment$$ -We call a memory allocation aligned if the address is a multiple -of the number of bytes in a $code size_t$$ value. -If the system $code new$$ allocator is aligned, then $icode array$$ -pointer is also aligned. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Use thread_alloc to allocate an array, then call default construtor - for each element. - - \tparam Type - The type of the elements of the array. - - \param size_min [in] - The minimum number of elements in the array. - - \param size_out [out] - The actual number of elements in the array. - - \return - pointer to the first element of the array. - The default constructor is used to initialize - all the elements of the array. - - \par - The \c extra_ field, in the \c thread_alloc node before the return value, - is set to size_out. - */ - template - static Type* create_array(size_t size_min, size_t& size_out) - { // minimum number of bytes to allocate - size_t min_bytes = size_min * sizeof(Type); - // do the allocation - size_t num_bytes; - void* v_ptr = get_memory(min_bytes, num_bytes); - // This is where the array starts - Type* array = reinterpret_cast(v_ptr); - // number of Type values in the allocation - size_out = num_bytes / sizeof(Type); - // store this number in the extra field - block_t* node = reinterpret_cast(v_ptr) - 1; - node->extra_ = size_out; - - // call default constructor for each element - size_t i; - for(i = 0; i < size_out; i++) - new(array + i) Type(); - - return array; - } -/* ----------------------------------------------------------------------- -$begin ta_delete_array$$ -$spell - inuse - thread_alloc - sizeof - deallocate -$$ - -$section Deallocate An Array and Call Destructor for its Elements$$ -$mindex delete_array$$ - - -$head Syntax$$ -$codei%thread_alloc::delete_array(%array%)%$$. - -$head Purpose$$ -Returns memory corresponding to an array created by -(create by $cref/create_array/ta_create_array/$$) to the -$cref/available/ta_available/$$ memory pool for the current thread. - -$head Type$$ -The type of the elements of the array. - -$head array$$ -The argument $icode array$$ has prototype -$codei% - %Type%* %array% -%$$ -It is a value returned by $cref/create_array/ta_create_array/$$ and not yet deleted. -The $icode Type$$ destructor is called for each element in the array. - -$head Thread$$ -The $cref/current thread/ta_thread_num/$$ must be the -same as when $cref/create_array/ta_create_array/$$ returned the value $icode array$$. -There is an exception to this rule: -when the current execution mode is sequential -(not $cref/parallel/ta_in_parallel/$$) the current thread number does not matter. - -$head Delta$$ -The amount of memory $cref/inuse/ta_inuse/$$ will decrease by $icode delta$$, -and the $cref/available/ta_available/$$ memory will increase by $icode delta$$, -where $cref/delta/ta_create_array/Delta/$$ -is the same as for the corresponding call to $code create_array$$. - -$head Example$$ -$cref thread_alloc.cpp$$ - -$end -*/ - /*! - Return Memory Used for an Array to the Available Pool - (include destructor call for each element). - - \tparam Type - The type of the elements of the array. - - \param array [in] - A value returned by \c create_array that has not yet been deleted. - The \c Type destructor is used to destroy each of the elements - of the array. - - \par - Durring parallel execution, the current thread must be the same - as during the corresponding call to \c create_array. - */ - template - static void delete_array(Type* array) - { // determine the number of values in the array - block_t* node = reinterpret_cast(array) - 1; - size_t size = node->extra_; - - // call destructor for each element - size_t i; - for(i = 0; i < size; i++) - (array + i)->~Type(); - - // return the memory to the available pool for this thread - thread_alloc::return_memory( reinterpret_cast(array) ); - } -/* ----------------------------------------------------------------------- -$begin ta_free_all$$ -$spell - alloc - bool - inuse -$$ - -$section Free All Memory That Was Allocated for Use by thread_alloc$$ - - -$head Syntax$$ -$icode%ok% = thread_alloc::free_all()%$$. - -$head Purpose$$ -Returns all memory that was used by $code thread_alloc$$ to the system. - -$head ok$$ -The return value $icode ok$$ has prototype -$codei% - bool %ok% -%$$ -Its value will be $code true$$ if all the memory can be freed. -This requires that for all $icode thread$$ indices, there is no memory -$cref/inuse/ta_inuse/$$; i.e., -$codei% - 0 == thread_alloc::inuse(%thread%) -%$$ -Otherwise, the return value will be false. - -$head Restrictions$$ -This function cannot be called while in parallel mode. - -$head Example$$ -$cref thread_alloc.cpp$$ -$end -*/ - /*! - Return to the system all thread_alloc memory that is not currently inuse. - - \return - If no \c thread_alloc memory is currently inuse, - all memory is returned to the system and the return value is true. - Otherwise the return value is false. - */ - static bool free_all(void) - { CPPAD_ASSERT_KNOWN( - ! in_parallel(), - "free_all cannot be used while in parallel execution" - ); - bool ok = true; - size_t thread = CPPAD_MAX_NUM_THREADS; - while(thread--) - { ok &= inuse(thread) == 0; - free_available(thread); - } - return ok; - } -}; - - -} // END_CPPAD_NAMESPACE - -// preprocessor symbols local to this file -# undef CPPAD_MAX_NUM_CAPACITY -# undef CPPAD_MIN_DOUBLE_CAPACITY -# undef CPPAD_TRACE_CAPACITY -# undef CPPAD_TRACE_THREAD -# endif diff --git a/external/cppad/include/cppad/utility/time_test.hpp b/external/cppad/include/cppad/utility/time_test.hpp deleted file mode 100644 index 97e6b970b..000000000 --- a/external/cppad/include/cppad/utility/time_test.hpp +++ /dev/null @@ -1,234 +0,0 @@ -// $Id: time_test.hpp 3855 2016-12-19 00:30:54Z bradbell $ -# ifndef CPPAD_UTILITY_TIME_TEST_HPP -# define CPPAD_UTILITY_TIME_TEST_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin time_test$$ -$spell - gettimeofday - vec - cppad.hpp - Microsoft - namespace - std - const - cout - ctime - ifdef - const - endif - cpp -$$ - - -$section Determine Amount of Time to Execute a Test$$ -$mindex time_test speed$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%time% = time_test(%test%, %time_min%) -%$$ -$icode%time% = time_test(%test%, %time_min%, %test_size%)%$$ - -$head Purpose$$ -The $code time_test$$ function executes a timing test -and reports the amount of wall clock time for execution. - -$head Motivation$$ -It is important to separate small calculation units -and test them individually. -This way individual changes can be tested in the context of the -routine that they are in. -On many machines, accurate timing of a very short execution -sequences is not possible. -In addition, -there may be set up and tear down time for a test that -we do not really want included in the timing. -For this reason $code time_test$$ -automatically determines how many times to -repeat the section of the test that we wish to time. - -$head Include$$ -The file $code cppad/time_test.hpp$$ defines the -$code time_test$$ function. -This file is included by $code cppad/cppad.hpp$$ -and it can also be included separately with out the rest of -the $code CppAD$$ routines. - -$head test$$ -The $code time_test$$ argument $icode test$$ is a function, -or function object. -In the case where $icode test_size$$ is not present, -$icode test$$ supports the syntax -$codei% - %test%(%repeat%) -%$$ -In the case where $icode test_size$$ is present, -$icode test$$ supports the syntax -$codei% - %test%(%size%, %repeat%) -%$$ -In either case, the return value for $icode test$$ is $code void$$. - -$subhead size$$ -If the argument $icode size$$ is present, -it has prototype -$codei% - size_t %size% -%$$ -and is equal to the $icode test_size$$ argument to $code time_test$$. - -$subhead repeat$$ -The $icode test$$ argument $icode repeat$$ has prototype -$codei% - size_t %repeat% -%$$ -It will be equal to the $icode size$$ argument to $code time_test$$. - -$head time_min$$ -The argument $icode time_min$$ has prototype -$codei% - double %time_min% -%$$ -It specifies the minimum amount of time in seconds -that the $icode test$$ routine should take. -The $icode repeat$$ argument to $icode test$$ is increased -until this amount of execution time (or more) is reached. - -$head test_size$$ -This argument has prototype -$codei% - size_t %test_size% -%$$ -It specifies the $icode size$$ argument to $icode test$$. - -$head time$$ -The return value $icode time$$ has prototype -$codei% - double %time% -%$$ -and is the number of wall clock seconds that it took -to execute $icode test$$ divided by the value used for $icode repeat$$. - -$head Timing$$ -The routine $cref elapsed_seconds$$ will be used to determine the -amount of time it took to execute the test. - -$children% - cppad/utility/elapsed_seconds.hpp% - speed/example/time_test.cpp -%$$ -$head Example$$ -The routine $cref time_test.cpp$$ is an example and test -of $code time_test$$. - -$end ------------------------------------------------------------------------ -*/ - -# include -# include -# include -# include -# include - -# define CPPAD_EXTRA_RUN_BEFORE_TIMING 0 - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file time_test.hpp -\brief Function that preforms one timing test (for speed of execution). -*/ - -/*! -Preform one wall clock execution timing test. - -\tparam Test -Either the type void (*)(size_t) or a function object -type that supports the same syntax. - -\param test -The function, or function object, that supports the operation -test(repeat) where \c repeat is the number of times -to repeat the tests operaiton that is being timed. - -\param time_min -is the minimum amount of time that \c test should take to preform -the repetitions of the operation being timed. -*/ -template -double time_test(Test test, double time_min ) -{ -# if CPPAD_EXTRA_RUN_BEFORE_TIMING - test(1); -# endif - size_t repeat = 0; - double s0 = elapsed_seconds(); - double s1 = s0; - while( s1 - s0 < time_min ) - { repeat = std::max(size_t(1), 2 * repeat); - s0 = elapsed_seconds(); - test(repeat); - s1 = elapsed_seconds(); - } - double time = (s1 - s0) / double(repeat); - return time; -} - -/*! -Preform one wall clock execution timing test. - -\tparam Test -Either the type void (*)(size_t, size_t) or a function object -type that supports the same syntax. - -\param test -The function, or function object, that supports the operation -test(size, repeat) where -\c is the size for this test and -\c repeat is the number of times -to repeat the tests operaiton that is being timed. - -\param time_min -is the minimum amount of time that \c test should take to preform -the repetitions of the operation being timed. - -\param test_size -will be used for the value of \c size in the call to \c test. -*/ -template -double time_test(Test test, double time_min, size_t test_size) -{ -# if CPPAD_EXTRA_RUN_BEFORE_TIMING - test(test_size, 1); -# endif - size_t repeat = 0; - double s0 = elapsed_seconds(); - double s1 = s0; - while( s1 - s0 < time_min ) - { repeat = std::max(size_t(1), 2 * repeat); - s0 = elapsed_seconds(); - test(test_size, repeat); - s1 = elapsed_seconds(); - } - double time = (s1 - s0) / double(repeat); - return time; -} - -} // END_CPPAD_NAMESPACE - -# undef CPPAD_EXTRA_RUN_BEFORE_TIMING -// END PROGRAM -# endif diff --git a/external/cppad/include/cppad/utility/to_string.hpp b/external/cppad/include/cppad/utility/to_string.hpp deleted file mode 100644 index 0e332275d..000000000 --- a/external/cppad/include/cppad/utility/to_string.hpp +++ /dev/null @@ -1,174 +0,0 @@ -# ifndef CPPAD_UTILITY_TO_STRING_HPP -# define CPPAD_UTILITY_TO_STRING_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin to_string$$ -$spell - cppad.hpp - long long - std - const - ostringstream -$$ - -$section Convert Certain Types to a String$$ - -$head Syntax$$ -$codei%# include -%$$ -$icode%s% = to_string(%value%)%$$. - -$head See Also$$ -$cref base_to_string$$, $cref ad_to_string$$ - -$head Purpose$$ -This routine is similar to the C++11 routine $code std::to_string$$ -with the following differences: -$list number$$ -It works with C++98. -$lnext -It has been extended to the fundamental floating point types. -$lnext -It has specifications for extending to an arbitrary type; see -$cref base_to_string$$. -$lnext -If $code $$ is included, -and it has been extended to a $icode Base$$ type, -it automatically extends to the -$cref/AD types above Base/glossary/AD Type Above Base/$$. -$lnext -For integer types, conversion to a string is exact. -For floating point types, conversion to a string yields a value -that has relative error within machine epsilon. -$lend - -$head value$$ - -$subhead Integer$$ -The argument $icode value$$ can have the following prototype -$codei% - const %Integer%& %value% -%$$ -where $icode Integer$$ is any of the fundamental integer types; e.g., -$code short int$$ and $code unsigned long$$. -Note that if C++11 is supported by this compilation, -$code unsigned long long$$ is also a fundamental integer type. - -$subhead Float$$ -The argument $icode value$$ can have the following prototype -$codei% - const %Float%& %value% -%$$ -where $icode Float$$ is any of the fundamental floating point types; i.e., -$code float$$, $code double$$, and $code long double$$. - -$head s$$ -The return value has prototype -$codei% - std::string %s% -%$$ -and contains a representation of the specified $icode value$$. - -$subhead Integer$$ -If $icode value$$ is an $codei Integer$$, -the representation is equivalent to $codei%os% << %value%$$ -where $icode os$$ is an $code std::ostringstream$$. - -$subhead Float$$ -If $icode value$$ is a $codei Float$$, -enough digits are used in the representation so that -the result is accurate to withing round off error. - -$children% - example/utility/to_string.cpp -%$$ -$head Example$$ -The file $cref to_string.cpp$$ -contains an example and test of this routine. -It returns true if it succeeds and false otherwise. - -$end -*/ -# include -# include -# include -# include -# include - -# define CPPAD_SPECIALIZE_TO_STRING_INTEGER(Type) \ -template <> struct to_string_struct\ -{ std::string operator()(const Type& value) \ - { std::stringstream os;\ - os << value;\ - return os.str();\ - }\ -}; - -# define CPPAD_SPECIALIZE_TO_STRING_FLOAT(Float) \ -template <> struct to_string_struct\ -{ std::string operator()(const Float& value) \ - { std::stringstream os;\ - int n_digits = 1 + std::numeric_limits::digits10;\ - os << std::setprecision(n_digits);\ - os << value;\ - return os.str();\ - }\ -}; - -namespace CppAD { - - // Default implementation, - // each type must define its own specilization. - template - struct to_string_struct - { std::string operator()(const Type& value) - { CPPAD_ASSERT_KNOWN( - false, - "to_string is not implemented for this type" - ); - // return empty string - return std::string(""); - } - }; - - // specialization for the fundamental integer types - CPPAD_SPECIALIZE_TO_STRING_INTEGER(signed short) - CPPAD_SPECIALIZE_TO_STRING_INTEGER(unsigned short) - // - CPPAD_SPECIALIZE_TO_STRING_INTEGER(signed int) - CPPAD_SPECIALIZE_TO_STRING_INTEGER(unsigned int) - // - CPPAD_SPECIALIZE_TO_STRING_INTEGER(signed long) - CPPAD_SPECIALIZE_TO_STRING_INTEGER(unsigned long) - // -# if CPPAD_USE_CPLUSPLUS_2011 - CPPAD_SPECIALIZE_TO_STRING_INTEGER(signed long long) - CPPAD_SPECIALIZE_TO_STRING_INTEGER(unsigned long long) -# endif - - // specialization for the fundamental floating point types - CPPAD_SPECIALIZE_TO_STRING_FLOAT(float) - CPPAD_SPECIALIZE_TO_STRING_FLOAT(double) - CPPAD_SPECIALIZE_TO_STRING_FLOAT(long double) - - // link from function to function object in structure - template - std::string to_string(const Type& value) - { to_string_struct to_str; - return to_str(value); - } -} - -# undef CPPAD_SPECIALIZE_TO_STRING_FLOAT -# undef CPPAD_SPECIALIZE_TO_STRING_INTEGER -# endif diff --git a/external/cppad/include/cppad/utility/track_new_del.hpp b/external/cppad/include/cppad/utility/track_new_del.hpp deleted file mode 100644 index 91b60325a..000000000 --- a/external/cppad/include/cppad/utility/track_new_del.hpp +++ /dev/null @@ -1,542 +0,0 @@ -# ifndef CPPAD_UTILITY_TRACK_NEW_DEL_HPP -# define CPPAD_UTILITY_TRACK_NEW_DEL_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ -/* -$begin TrackNewDel$$ -$spell - cppad.hpp - Cpp - newptr - Vec - oldptr - newlen - ncopy - const -$$ - -$section Routines That Track Use of New and Delete$$ -$mindex memory NDEBUG CPPAD_TRACK_NEW_VEC CppADTrackNewVec CPPAD_TRACK_DEL_VEC CppADTrackDelVec CPPAD_TRACK_EXTEND CppADTrackExtend CPPAD_TRACK_COUNT thread multi$$ - -$head Deprecated 2007-07-23$$ -All these routines have been deprecated. -You should use the $cref thread_alloc$$ memory allocator instead -(which works better in both a single thread and -properly in multi-threading environment). - -$head Syntax$$ -$codei%# include -%$$ -$icode%newptr% = TrackNewVec(%file%, %line%, %newlen%, %oldptr%) -%$$ -$codei%TrackDelVec(%file%, %line%, %oldptr%) -%$$ -$icode%newptr% = TrackExtend(%file%, %line%, %newlen%, %ncopy%, %oldptr%) -%$$ -$icode%count% = TrackCount(%file%, %line%)%$$ - - -$head Purpose$$ -These routines -aid in the use of $code new[]$$ and $code delete[]$$ -during the execution of a C++ program. - -$head Include$$ -The file $code cppad/track_new_del.hpp$$ is included by -$code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of the -CppAD include files. - - -$head file$$ -The argument $icode file$$ has prototype -$codei% - const char *%file% -%$$ -It should be the source code file name -where the call to $code TrackNew$$ is located. -The best way to accomplish this is the use the preprocessor symbol -$code __FILE__$$ for this argument. - -$head line$$ -The argument $icode line$$ has prototype -$codei% - int %line% -%$$ -It should be the source code file line number -where the call to $code TrackNew$$ is located. -The best way to accomplish this is the use the preprocessor symbol -$code __LINE__$$ for this argument. - -$head oldptr$$ -The argument $icode oldptr$$ has prototype -$codei% - %Type% *%oldptr% -%$$ -This argument is used to identify the type $icode Type$$. - -$head newlen$$ -The argument $icode newlen$$ has prototype -$codei% - size_t %newlen% -%$$ - -$head head newptr$$ -The return value $icode newptr$$ has prototype -$codei% - %Type% *%newptr% -%$$ -It points to the newly allocated vector of objects -that were allocated using -$codei% - new Type[%newlen%] -%$$ - -$head ncopy$$ -The argument $icode ncopy$$ has prototype -$codei% - size_t %ncopy% -%$$ -This specifies the number of elements that are copied from -the old array to the new array. -The value of $icode ncopy$$ -must be less than or equal $icode newlen$$. - -$head TrackNewVec$$ -If $code NDEBUG$$ is defined, this routine only sets -$codei% - %newptr% = %Type% new[%newlen%] -%$$ -The value of $icode oldptr$$ does not matter -(except that it is used to identify $icode Type$$). -If $code NDEBUG$$ is not defined, $code TrackNewVec$$ also -tracks the this memory allocation. -In this case, if memory cannot be allocated -$cref ErrorHandler$$ is used to generate a message -stating that there was not sufficient memory. - -$subhead Macro$$ -The preprocessor macro call -$codei% - CPPAD_TRACK_NEW_VEC(%newlen%, %oldptr%) -%$$ -expands to -$codei% - CppAD::TrackNewVec(__FILE__, __LINE__, %newlen%, %oldptr%) -%$$ - -$subhead Previously Deprecated$$ -The preprocessor macro $code CppADTrackNewVec$$ is the -same as $code CPPAD_TRACK_NEW_VEC$$ and was previously deprecated. - -$head TrackDelVec$$ -This routine is used to a vector of objects -that have been allocated using $code TrackNew$$ or $code TrackExtend$$. -If $code NDEBUG$$ is defined, this routine only frees memory with -$codei% - delete [] %oldptr% -%$$ -If $code NDEBUG$$ is not defined, $code TrackDelete$$ also checks that -$icode oldptr$$ was allocated by $code TrackNew$$ or $code TrackExtend$$ -and has not yet been freed. -If this is not the case, -$cref ErrorHandler$$ is used to generate an error message. - -$subhead Macro$$ -The preprocessor macro call -$codei% - CPPAD_TRACK_DEL_VEC(%oldptr%) -%$$ -expands to -$codei% - CppAD::TrackDelVec(__FILE__, __LINE__, %oldptr%) -%$$ - -$subhead Previously Deprecated$$ -The preprocessor macro $code CppADTrackDelVec$$ is the -same as $code CPPAD_TRACK_DEL_VEC$$ was previously deprecated. - -$head TrackExtend$$ -This routine is used to -allocate a new vector (using $code TrackNewVec$$), -copy $icode ncopy$$ elements from the old vector to the new vector. -If $icode ncopy$$ is greater than zero, $icode oldptr$$ -must have been allocated using $code TrackNewVec$$ or $code TrackExtend$$. -In this case, the vector pointed to by $icode oldptr$$ -must be have at least $icode ncopy$$ elements -and it will be deleted (using $code TrackDelVec$$). -Note that the dependence of $code TrackExtend$$ on $code NDEBUG$$ -is indirectly through the routines $code TrackNewVec$$ and -$code TrackDelVec$$. - -$subhead Macro$$ -The preprocessor macro call -$codei% - CPPAD_TRACK_EXTEND(%newlen%, %ncopy%, %oldptr%) -%$$ -expands to -$codei% - CppAD::TrackExtend(__FILE__, __LINE__, %newlen%, %ncopy%, %oldptr%) -%$$ - -$subhead Previously Deprecated$$ -The preprocessor macro $code CppADTrackExtend$$ is the -same as $code CPPAD_TRACK_EXTEND$$ and was previously deprecated. - -$head TrackCount$$ -The return value $icode count$$ has prototype -$codei% - size_t %count% -%$$ -If $code NDEBUG$$ is defined, $icode count$$ will be zero. -Otherwise, it will be -the number of vectors that -have been allocated -(by $code TrackNewVec$$ or $code TrackExtend$$) -and not yet freed -(by $code TrackDelete$$). - -$subhead Macro$$ -The preprocessor macro call -$codei% - CPPAD_TRACK_COUNT() -%$$ -expands to -$codei% - CppAD::TrackCount(__FILE__, __LINE__) -%$$ - -$subhead Previously Deprecated$$ -The preprocessor macro $code CppADTrackCount$$ is the -same as $code CPPAD_TRACK_COUNT$$ and was previously deprecated. - -$head Multi-Threading$$ -These routines cannot be used $cref/in_parallel/ta_in_parallel/$$ -execution mode. -Use the $cref thread_alloc$$ routines instead. - -$head Example$$ -$children% - example/deprecated/track_new_del.cpp -%$$ -The file $cref TrackNewDel.cpp$$ -contains an example and test of these functions. -It returns true, if it succeeds, and false otherwise. - -$end ------------------------------------------------------------------------------- -*/ -# include -# include -# include -# include -# include - -# ifndef CPPAD_TRACK_DEBUG -# define CPPAD_TRACK_DEBUG 0 -# endif - -// ------------------------------------------------------------------------- -# define CPPAD_TRACK_NEW_VEC(newlen, oldptr) \ - CppAD::TrackNewVec(__FILE__, __LINE__, newlen, oldptr) - -# define CPPAD_TRACK_DEL_VEC(oldptr) \ - CppAD::TrackDelVec(__FILE__, __LINE__, oldptr) - -# define CPPAD_TRACK_EXTEND(newlen, ncopy, oldptr) \ - CppAD::TrackExtend(__FILE__, __LINE__, newlen, ncopy, oldptr) - -# define CPPAD_TRACK_COUNT() \ - CppAD::TrackCount(__FILE__, __LINE__) -// ------------------------------------------------------------------------- -# define CppADTrackNewVec CPPAD_TRACK_NEW_VEC -# define CppADTrackDelVec CPPAD_TRACK_DEL_VEC -# define CppADTrackExtend CPPAD_TRACK_EXTEND -# define CppADTrackCount CPPAD_TRACK_COUNT -// ------------------------------------------------------------------------- -namespace CppAD { // Begin CppAD namespace - -// TrackElement ------------------------------------------------------------ -class TrackElement { - -public: - std::string file; // corresponding file name - int line; // corresponding line number - void *ptr; // value returned by TrackNew - TrackElement *next; // next element in linked list - - // default contructor (used to initialize root) - TrackElement(void) - : file(""), line(0), ptr(CPPAD_NULL), next(CPPAD_NULL) - { } - - TrackElement(const char *f, int l, void *p) - : file(f), line(l), ptr(p), next(CPPAD_NULL) - { CPPAD_ASSERT_UNKNOWN( p != CPPAD_NULL); - } - - // There is only one tracking list and it starts it here - static TrackElement *Root(void) - { CPPAD_ASSERT_UNKNOWN( ! thread_alloc::in_parallel() ); - static TrackElement root; - return &root; - } - - // Print one tracking element - static void Print(TrackElement* E) - { - CPPAD_ASSERT_UNKNOWN( ! thread_alloc::in_parallel() ); - using std::cout; - cout << "E = " << E; - cout << ", E->next = " << E->next; - cout << ", E->ptr = " << E->ptr; - cout << ", E->line = " << E->line; - cout << ", E->file = " << E->file; - cout << std::endl; - } - - // Print the linked list for a thread - static void Print(void) - { - CPPAD_ASSERT_UNKNOWN( ! thread_alloc::in_parallel() ); - using std::cout; - using std::endl; - TrackElement *E = Root(); - // convert int(size_t) to avoid warning on _MSC_VER systems - cout << "Begin Track List" << endl; - while( E->next != CPPAD_NULL ) - { E = E->next; - Print(E); - } - cout << "End Track List:" << endl; - cout << endl; - } -}; - - -// TrackError ---------------------------------------------------------------- -inline void TrackError( - const char *routine, - const char *file, - int line, - const char *msg ) -{ - CPPAD_ASSERT_UNKNOWN( ! thread_alloc::in_parallel() ); - std::ostringstream buf; - buf << routine - << ": at line " - << line - << " in file " - << file - << std::endl - << msg; - std::string str = buf.str(); - size_t n = str.size(); - size_t i; - char *message = new char[n + 1]; - for(i = 0; i < n; i++) - message[i] = str[i]; - message[n] = '\0'; - CPPAD_ASSERT_KNOWN( false , message); -} - -// TrackNewVec --------------------------------------------------------------- -# ifdef NDEBUG -template -inline Type *TrackNewVec( - const char *file, int line, size_t len, Type * /* oldptr */ ) -{ -# if CPPAD_TRACK_DEBUG - static bool first = true; - if( first ) - { std::cout << "NDEBUG is defined for TrackNewVec" << std::endl; - first = false; - } -# endif - return (new Type[len]); -} - -# else - -template -Type *TrackNewVec( - const char *file , - int line , - size_t len , - Type * /* oldptr */ ) -{ - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "attempt to use TrackNewVec in parallel execution mode." - ); - // try to allocate the new memrory - Type *newptr = CPPAD_NULL; - try - { newptr = new Type[len]; - } - catch(...) - { TrackError("TrackNewVec", file, line, - "Cannot allocate sufficient memory" - ); - } - // create tracking element - void *vptr = static_cast(newptr); - TrackElement *E = new TrackElement(file, line, vptr); - - // get the root - TrackElement *root = TrackElement::Root(); - - // put this elemenent at the front of linked list - E->next = root->next; - root->next = E; - -# if CPPAD_TRACK_DEBUG - std::cout << "TrackNewVec: "; - TrackElement::Print(E); -# endif - - return newptr; -} - -# endif - -// TrackDelVec -------------------------------------------------------------- -# ifdef NDEBUG -template -inline void TrackDelVec(const char *file, int line, Type *oldptr) -{ -# if CPPAD_TRACK_DEBUG - static bool first = true; - if( first ) - { std::cout << "NDEBUG is defined in TrackDelVec" << std::endl; - first = false; - } -# endif - delete [] oldptr; -} - -# else - -template -void TrackDelVec( - const char *file , - int line , - Type *oldptr ) -{ - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "attempt to use TrackDelVec in parallel execution mode." - ); - TrackElement *P; - TrackElement *E; - - // search list for pointer - P = TrackElement::Root(); - E = P->next; - void *vptr = static_cast(oldptr); - while(E != CPPAD_NULL && E->ptr != vptr) - { P = E; - E = E->next; - } - - // check if pointer was not in list - if( E == CPPAD_NULL || E->ptr != vptr ) TrackError( - "TrackDelVec", file, line, - "Invalid value for the argument oldptr.\n" - "Possible linking of debug and NDEBUG compilations of CppAD." - ); - -# if CPPAD_TRACK_DEBUG - std::cout << "TrackDelVec: "; - TrackElement::Print(E); -# endif - - // remove tracking element from list - P->next = E->next; - - // delete allocated pointer - delete [] oldptr; - - // delete tracking element - delete E; - - return; -} - -# endif - -// TrackExtend -------------------------------------------------------------- -template -Type *TrackExtend( - const char *file , - int line , - size_t newlen , - size_t ncopy , - Type *oldptr ) -{ - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "attempt to use TrackExtend in parallel execution mode." - ); - -# if CPPAD_TRACK_DEBUG - using std::cout; - cout << "TrackExtend: file = " << file; - cout << ", line = " << line; - cout << ", newlen = " << newlen; - cout << ", ncopy = " << ncopy; - cout << ", oldptr = " << oldptr; - cout << std::endl; -# endif - CPPAD_ASSERT_KNOWN( - ncopy <= newlen, - "TrackExtend: ncopy is greater than newlen." - ); - - // allocate the new memrory - Type *newptr = TrackNewVec(file, line, newlen, oldptr); - - // copy the data - size_t i; - for(i = 0; i < ncopy; i++) - newptr[i] = oldptr[i]; - - // delete the old vector - if( ncopy > 0 ) - TrackDelVec(file, line, oldptr); - - return newptr; -} - -// TrackCount -------------------------------------------------------------- -inline size_t TrackCount(const char *file, int line) -{ - CPPAD_ASSERT_KNOWN( - ! thread_alloc::in_parallel() , - "attempt to use TrackCount in parallel execution mode." - ); - size_t count = 0; - TrackElement *E = TrackElement::Root(); - while( E->next != CPPAD_NULL ) - { ++count; - E = E->next; - } - return count; -} -// --------------------------------------------------------------------------- - -} // End CppAD namespace - -// preprocessor symbols local to this file -# undef CPPAD_TRACK_DEBUG - -# endif diff --git a/external/cppad/include/cppad/utility/vector.hpp b/external/cppad/include/cppad/utility/vector.hpp deleted file mode 100644 index 20b4b5f8a..000000000 --- a/external/cppad/include/cppad/utility/vector.hpp +++ /dev/null @@ -1,914 +0,0 @@ -# ifndef CPPAD_UTILITY_VECTOR_HPP -# define CPPAD_UTILITY_VECTOR_HPP - -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin CppAD_vector$$ -$spell - rvalues - thread_alloc - cppad.hpp - Bool - resize - cout - endl - std - Cpp - const - vec - ostream - elem -$$ - - -$section The CppAD::vector Template Class$$ -$mindex vector CppAD [] push thread_alloc$$ - -$head Syntax$$ -$code%# include $$ - -$head Description$$ -The include file $code cppad/vector.hpp$$ defines the -vector template class $code CppAD::vector$$. -This is a $cref SimpleVector$$ template class and in addition -it has the features listed below: - -$head Include$$ -The file $code cppad/vector.hpp$$ is included by $code cppad/cppad.hpp$$ -but it can also be included separately with out the rest of the -CppAD include files. - -$head capacity$$ -If $icode x$$ is a $codei%CppAD::vector<%Scalar%>%$$, -and $icode cap$$ is a $code size_t$$ object, -$codei% - %cap% = %x%.capacity() -%$$ -set $icode cap$$ to the number of $icode Scalar$$ objects that -could fit in the memory currently allocated for $icode x$$. -Note that -$codei% - %x%.size() <= %x%.capacity() -%$$ - -$head Assignment$$ -If $icode x$$ and $icode y$$ are -$codei%CppAD::vector<%Scalar%>%$$ objects, -$codei% - %y% = %x% -%$$ -has all the properties listed for a -$cref/simple vector assignment/SimpleVector/Assignment/$$ -plus the following: - -$subhead Check Size$$ -The $code CppAD::vector$$ template class will check that -the size of $icode x$$ is either zero or the size of $icode y$$ -before doing the assignment. -If this is not the case, $code CppAD::vector$$ will use -$cref ErrorHandler$$ -to generate an appropriate error report. -Allowing for assignment to a vector with size zero makes the following -code work: -$codei% - CppAD::vector<%Scalar%> %y%; - %y% = %x%; -%$$ - -$subhead Return Reference$$ -A reference to the vector $icode y$$ is returned. -An example use of this reference is in multiple assignments of the form -$codei% - %z% = %y% = %x% -%$$ - -$subhead Move Semantics$$ -If the C++ compiler supports move semantic rvalues using the $code &&$$ -syntax, then it will be used during the vector assignment statement. -This means that return values and other temporaries are not be copied, -but rather pointers are transferred. - -$head Element Access$$ -If $icode x$$ is a $codei%CppAD::vector<%Scalar%>%$$ object -and $icode i$$ has type $code size_t$$, -$codei% - %x%[%i%] -%$$ -has all the properties listed for a -$cref/simple vector element access/SimpleVector/Element Access/$$ -plus the following: -$pre - -$$ -The object $icode%x%[%i%]%$$ has type $icode Scalar$$ -(is not possibly a different type that can be converted to $icode Scalar$$). -$pre - -$$ -If $icode i$$ is not less than the size of the $icode x$$, -$code CppAD::vector$$ will use -$cref ErrorHandler$$ -to generate an appropriate error report. - -$head push_back$$ -If $icode x$$ is a $codei%CppAD::vector<%Scalar%>%$$ object -with size equal to $icode n$$ and -$icode s$$ has type $icode Scalar$$, -$codei% - %x%.push_back(%s%) -%$$ -extends the vector $icode x$$ so that its new size is $icode n$$ plus one -and $icode%x%[%n%]%$$ is equal to $icode s$$ -(equal in the sense of the $icode Scalar$$ assignment operator). - -$head push_vector$$ -If $icode x$$ is a $codei%CppAD::vector<%Scalar%>%$$ object -with size equal to $icode n$$ and -$icode v$$ is a $cref/simple vector/SimpleVector/$$ -with elements of type $icode Scalar$$ and size $icode m$$, -$codei% - %x%.push_vector(%v%) -%$$ -extends the vector $icode x$$ so that its new size is $icode%n%+%m%$$ -and $icode%x%[%n% + %i%]%$$ is equal to $icode%v%[%i%]%$$ -for $icode%i = 1 , ... , m-1%$$ -(equal in the sense of the $icode Scalar$$ assignment operator). - -$head Output$$ -If $icode x$$ is a $codei%CppAD::vector<%Scalar%>%$$ object -and $icode os$$ is an $code std::ostream$$, -and the operation -$codei% - %os% << %x% -%$$ -will output the vector $icode x$$ to the standard -output stream $icode os$$. -The elements of $icode x$$ are enclosed at the beginning by a -$code {$$ character, -they are separated by $code ,$$ characters, -and they are enclosed at the end by $code }$$ character. -It is assumed by this operation that if $icode e$$ -is an object with type $icode Scalar$$, -$codei% - %os% << %e% -%$$ -will output the value $icode e$$ to the standard -output stream $icode os$$. - -$head resize$$ -The call $icode%x%.resize(%n%)%$$ set the size of $icode x$$ equal to -$icode n$$. -If $icode%n% <= %x%.capacity()%$$, -no memory is freed or allocated, the capacity of $icode x$$ does not change, -and the data in $icode x$$ is preserved. -If $icode%n% > %x%.capacity()%$$, -new memory is allocated and the data in $icode x$$ is lost -(not copied to the new memory location). - -$head clear$$ -All memory allocated for the vector is freed -and both its size and capacity are set to zero. -This can be useful when using very large vectors -and when checking for memory leaks (and there are global vectors) -see the $cref/memory/CppAD_vector/Memory and Parallel Mode/$$ discussion. - -$head data$$ -If $icode x$$ is a $codei%CppAD::vector<%Scalar%>%$$ object -$codei% - %x%.data() -%$$ -returns a pointer to a $icode Scalar$$ object such that for -$codei%0 <= %i% < %x%.size()%$$, -$icode%x%[%i%]%$$ and $icode%x%.data()[%i%]%$$ -are the same $icode Scalar$$ object. -If $icode x$$ is $code const$$, the pointer is $code const$$. -If $icode%x%.capacity()%$$ is zero, the value of the pointer is not defined. -The pointer may no longer be valid after the following operations on -$icode x$$: -its destructor, -$code clear$$, -$code resize$$, -$code push_back$$, -$code push_vector$$, -assignment to another vector when original size of $icode x$$ is zero. - -$head vectorBool$$ -The file $code $$ also defines the class -$code CppAD::vectorBool$$. -This has the same specifications as $code CppAD::vector$$ -with the following exceptions: - -$subhead Memory$$ -The class $code vectorBool$$ conserves on memory -(on the other hand, $code CppAD::vector$$ is expected to be faster -than $code vectorBool$$). - -$subhead bit_per_unit$$ -The static function call -$codei% - %s% = vectorBool::bit_per_unit() -%$$ -returns the $code size_t$$ value $icode s$$ -which is equal to the number of boolean values (bits) that are -packed into one operational unit. -For example, a logical $code or$$ -acts on this many boolean values with one operation. - -$subhead data$$ -The $cref/data/CppAD_vector/data/$$ function is not supported by -$code vectorBool$$. - -$subhead Output$$ -The $code CppAD::vectorBool$$ output operator -prints each boolean value as -a $code 0$$ for false, -a $code 1$$ for true, -and does not print any other output; i.e., -the vector is written a long sequence of zeros and ones with no -surrounding $code {$$, $code }$$ and with no separating commas or spaces. - -$subhead Element Type$$ -If $icode x$$ has type $code vectorBool$$ -and $icode i$$ has type $code size_t$$, -the element access value $icode%x%[%i%]%$$ has an unspecified type, -referred to here as $icode elementType$$, that supports the following -operations: - -$list number$$ -$icode elementType$$ can be converted to $code bool$$; e.g. -the following syntax is supported: -$codei% - static_cast( %x%[%i%] ) -%$$ - -$lnext -$icode elementType$$ supports the assignment operator $code =$$ where the -right hand side is a $code bool$$ or an $icode elementType$$ object; e.g., -if $icode y$$ has type $code bool$$, the following syntax is supported: -$codei% - %x%[%i%] = %y% -%$$ - -$lnext -The result of an assignment to an $icode elementType$$ -also has type $icode elementType$$. -Thus, if $icode z$$ has type $code bool$$, the following syntax is supported: -$codei% - %z% = %x%[%i%] = %y% -%$$ -$lend - -$head Memory and Parallel Mode$$ -These vectors use the multi-threaded fast memory allocator -$cref thread_alloc$$: - -$list number$$ -The routine $cref/parallel_setup/ta_parallel_setup/$$ must -be called before these vectors can be used -$cref/in parallel/ta_in_parallel/$$. -$lnext -Using these vectors affects the amount of memory -$cref/in_use/ta_inuse/$$ and $cref/available/ta_available/$$. -$lnext -Calling $cref/clear/CppAD_vector/clear/$$, -makes the corresponding memory available (though $code thread_alloc$$) -to the current thread. -$lnext -Available memory -can then be completely freed using $cref/free_available/ta_free_available/$$. -$lend - -$head Example$$ -$children% - example/utility/cppad_vector.cpp% - example/utility/vector_bool.cpp -%$$ -The files -$cref cppad_vector.cpp$$ and -$cref vector_bool.cpp$$ each -contain an example and test of this template class. -They return true if they succeed and false otherwise. - -$head Exercise$$ -Create and run a program that contains the following code: -$codep - CppAD::vector x(3); - size_t i; - for(i = 0; i < 3; i++) - x[i] = 4. - i; - std::cout << "x = " << x << std::endl; -$$ - -$end - - -$end - ------------------------------------------------------------------------- -*/ - -# include -# include -# include -# include -# include -# include - -namespace CppAD { // BEGIN_CPPAD_NAMESPACE -/*! -\file vector.hpp -File used to define CppAD::vector and CppAD::vectorBool -*/ - -// --------------------------------------------------------------------------- -/*! -The CppAD Simple Vector template class. -*/ -template -class vector { -private: - /// maximum number of Type elements current allocation can hold - size_t capacity_; - /// number of Type elements currently in this vector - size_t length_; - /// pointer to the first type elements - /// (not defined and should not be used when capacity_ = 0) - Type* data_; - /// delete data pointer - void delete_data(Type* data_ptr) - { thread_alloc::delete_array(data_ptr); } -public: - /// type of the elements in the vector - typedef Type value_type; - - /// default constructor sets capacity_ = length_ = data_ = 0 - inline vector(void) - : capacity_(0), length_(0), data_(CPPAD_NULL) - { } - /// sizing constructor - inline vector( - /// number of elements in this vector - size_t n - ) : capacity_(0), length_(0), data_(CPPAD_NULL) - { resize(n); } - - /// copy constructor - inline vector( - /// the *this vector will be a copy of \c x - const vector& x - ) : capacity_(0), length_(0), data_(CPPAD_NULL) - { resize(x.length_); - - // copy the data - for(size_t i = 0; i < length_; i++) - data_[i] = x.data_[i]; - } - /// destructor - ~vector(void) - { if( capacity_ > 0 ) - delete_data(data_); - } - - /// maximum number of elements current allocation can store - inline size_t capacity(void) const - { return capacity_; } - - /// number of elements currently in this vector. - inline size_t size(void) const - { return length_; } - - /// raw pointer to the data - inline Type* data(void) - { return data_; } - - /// const raw pointer to the data - inline const Type* data(void) const - { return data_; } - - /// change the number of elements in this vector. - inline void resize( - /// new number of elements for this vector - size_t n - ) - { length_ = n; - - // check if we must allocate new memory - if( capacity_ < length_ ) - { - // check if there is old memory to be freed - if( capacity_ > 0 ) - delete_data(data_); - - // get new memory and set capacity - data_ = thread_alloc::create_array(length_, capacity_); - } - } - - /// free memory and set number of elements to zero - inline void clear(void) - { length_ = 0; - // check if there is old memory to be freed - if( capacity_ > 0 ) - delete_data(data_); - capacity_ = 0; - } - - /// vector assignment operator - inline vector& operator=( - /// right hand size of the assingment operation - const vector& x - ) - { size_t i; - // If original lenght is zero, then resize it. - // Otherwise a length mismatch is an error. - if( length_ == 0 ) - resize( x.length_ ); - CPPAD_ASSERT_KNOWN( - length_ == x.length_ , - "vector: size miss match in assignment operation" - ); - for(i = 0; i < length_; i++) - data_[i] = x.data_[i]; - return *this; - } -# if CPPAD_USE_CPLUSPLUS_2011 - /// vector assignment operator with move semantics - inline vector& operator=( - /// right hand size of the assingment operation - vector&& x - ) - { CPPAD_ASSERT_KNOWN( - length_ == x.length_ || (length_ == 0), - "vector: size miss match in assignment operation" - ); - if( this != &x ) - { clear(); - // - length_ = x.length_; - capacity_ = x.capacity_; - data_ = x.data_; - // - x.length_ = 0; - x.capacity_ = 0; - x.data_ = CPPAD_NULL; - } - return *this; - } -# endif - /// non-constant element access; i.e., we can change this element value - Type& operator[]( - /// element index, must be less than length - size_t i - ) - { CPPAD_ASSERT_KNOWN( - i < length_, - "vector: index greater than or equal vector size" - ); - return data_[i]; - } - /// constant element access; i.e., we cannot change this element value - const Type& operator[]( - /// element index, must be less than length - size_t i - ) const - { CPPAD_ASSERT_KNOWN( - i < length_, - "vector: index greater than or equal vector size" - ); - return data_[i]; - } - /// add an element to the back of this vector - void push_back( - /// value of the element - const Type& s - ) - { // case where no allocation is necessary - if( length_ + 1 <= capacity_ ) - { data_[length_++] = s; - return; - } - CPPAD_ASSERT_UNKNOWN( length_ == capacity_ ); - - // store old length, capacity and data - size_t old_length = length_; - size_t old_capacity = capacity_; - Type* old_data = data_; - - // set the new length, capacity and data - length_ = 0; - capacity_ = 0; - resize(old_length + 1); - - // copy old data values - for(size_t i = 0; i < old_length; i++) - data_[i] = old_data[i]; - - // put the new element in the vector - CPPAD_ASSERT_UNKNOWN( old_length + 1 <= capacity_ ); - data_[old_length] = s; - - // free old data - if( old_capacity > 0 ) - delete_data(old_data); - - CPPAD_ASSERT_UNKNOWN( old_length + 1 == length_ ); - CPPAD_ASSERT_UNKNOWN( length_ <= capacity_ ); - } - - /*! add vector to the back of this vector - (we could not use push_back because MS V++ 7.1 did not resolve - to non-template member function when scalar is used.) - */ - template - void push_vector( - /// value of the vector that we are adding - const Vector& v - ) - { CheckSimpleVector(); - size_t m = v.size(); - - // case where no allcoation is necessary - if( length_ + m <= capacity_ ) - { for(size_t i = 0; i < m; i++) - data_[length_++] = v[i]; - return; - } - - // store old length, capacity and data - size_t old_length = length_; - size_t old_capacity = capacity_; - Type* old_data = data_; - - // set new length, capacity and data - length_ = 0; - capacity_ = 0; - resize(old_length + m); - - // copy old data values - for(size_t i = 0; i < old_length; i++) - data_[i] = old_data[i]; - - // put the new elements in the vector - CPPAD_ASSERT_UNKNOWN( old_length + m <= capacity_ ); - for(size_t i = 0; i < m; i++) - data_[old_length + i] = v[i]; - - // free old data - if( old_capacity > 0 ) - delete_data(old_data); - - CPPAD_ASSERT_UNKNOWN( old_length + m == length_ ); - CPPAD_ASSERT_UNKNOWN( length_ <= capacity_ ); - } -}; - -/// output a vector -template -inline std::ostream& operator << ( - /// stream to write the vector to - std::ostream& os , - /// vector that is output - const CppAD::vector& vec ) -{ size_t i = 0; - size_t n = vec.size(); - - os << "{ "; - while(i < n) - { os << vec[i++]; - if( i < n ) - os << ", "; - } - os << " }"; - return os; -} - -// --------------------------------------------------------------------------- -/*! -Class that is used to hold a non-constant element of a vector. -*/ -class vectorBoolElement { - /// the boolean data is packed with sizeof(UnitType) bits per value - typedef size_t UnitType; -private: - /// pointer to the UnitType value holding this eleemnt - UnitType* unit_; - /// mask for the bit corresponding to this element - /// (all zero except for bit that corresponds to this element) - UnitType mask_; -public: - /// constructor from member values - vectorBoolElement( - /// unit for this element - UnitType* unit , - /// mask for this element - UnitType mask ) - : unit_(unit) , mask_(mask) - { } - /// constuctor from another element - vectorBoolElement( - /// other element - const vectorBoolElement& e ) - : unit_(e.unit_) , mask_(e.mask_) - { } - /// conversion to a boolean value - operator bool() const - { return (*unit_ & mask_) != 0; } - /// assignment of this element to a bool - vectorBoolElement& operator=( - /// right hand side for assignment - bool bit - ) - { if(bit) - *unit_ |= mask_; - else *unit_ &= ~mask_; - return *this; - } - /// assignment of this element to another element - vectorBoolElement& operator=(const vectorBoolElement& e) - { if( *(e.unit_) & e.mask_ ) - *unit_ |= mask_; - else *unit_ &= ~mask_; - return *this; - } -}; - -class vectorBool { - /// the boolean data is packed with sizeof(UnitType) bits per value - typedef size_t UnitType; -private: - /// number of bits packed into each UnitType value in data_ - static const size_t bit_per_unit_ - = std::numeric_limits::digits; - /// number of UnitType values in data_ - size_t n_unit_; - /// number of bits currently stored in this vector - size_t length_; - /// pointer to where the bits are stored - UnitType *data_; - - /// minimum number of UnitType values that can store length_ bits - /// (note that this is really a function of length_) - size_t unit_min(void) - { if( length_ == 0 ) - return 0; - return (length_ - 1) / bit_per_unit_ + 1; - } -public: - /// type corresponding to the elements of this vector - /// (note that non-const elements actually use vectorBoolElement) - typedef bool value_type; - - // static member function - static size_t bit_per_unit(void) - { return bit_per_unit_; } - - /// default constructor (sets all member data to zero) - inline vectorBool(void) : n_unit_(0), length_(0), data_(CPPAD_NULL) - { } - /// sizing constructor - inline vectorBool( - /// number of bits in this vector - size_t n - ) : n_unit_(0), length_(n), data_(CPPAD_NULL) - { if( length_ > 0 ) - { // set n_unit and data - size_t min_unit = unit_min(); - data_ = thread_alloc::create_array(min_unit, n_unit_); - } - } - /// copy constructor - inline vectorBool( - /// the *this vector will be a copy of \c v - const vectorBool& v - ) : n_unit_(0), length_(v.length_), data_(CPPAD_NULL) - { if( length_ > 0 ) - { // set n_unit and data - size_t min_unit = unit_min(); - data_ = thread_alloc::create_array(min_unit, n_unit_); - - // copy values using UnitType assignment operator - CPPAD_ASSERT_UNKNOWN( min_unit <= v.n_unit_ ); - size_t i; - for(i = 0; i < min_unit; i++) - data_[i] = v.data_[i]; - } - } - /// destructor - ~vectorBool(void) - { if( n_unit_ > 0 ) - thread_alloc::delete_array(data_); - } - - /// number of elements in this vector - inline size_t size(void) const - { return length_; } - - /// maximum number of elements current allocation can store - inline size_t capacity(void) const - { return n_unit_ * bit_per_unit_; } - - /// change number of elements in this vector - inline void resize( - /// new number of elements for this vector - size_t n - ) - { length_ = n; - // check if we can use the current memory - size_t min_unit = unit_min(); - if( n_unit_ >= min_unit ) - return; - // check if there is old memory to be freed - if( n_unit_ > 0 ) - thread_alloc::delete_array(data_); - // get new memory and set n_unit - data_ = thread_alloc::create_array(min_unit, n_unit_); - } - - /// free memory and set number of elements to zero - inline void clear(void) - { length_ = 0; - // check if there is old memory to be freed - if( n_unit_ > 0 ) - thread_alloc::delete_array(data_); - n_unit_ = 0; - } - - /// vector assignment operator - inline vectorBool& operator=( - /// right hand size of the assingment operation - const vectorBool& v - ) - { size_t i; - // If original lenght is zero, then resize it. - // Otherwise a length mismatch is an error. - if( length_ == 0 ) - resize( v.length_ ); - CPPAD_ASSERT_KNOWN( - length_ == v.length_ , - "vectorBool: size miss match in assignment operation" - ); - size_t min_unit = unit_min(); - CPPAD_ASSERT_UNKNOWN( min_unit <= n_unit_ ); - CPPAD_ASSERT_UNKNOWN( min_unit <= v.n_unit_ ); - for(i = 0; i < min_unit; i++) - data_[i] = v.data_[i]; - return *this; - } -# if CPPAD_USE_CPLUSPLUS_2011 - /// vector assignment operator with move semantics - inline vectorBool& operator=( - /// right hand size of the assingment operation - vectorBool&& x - ) - { CPPAD_ASSERT_KNOWN( - length_ == x.length_ || (length_ == 0), - "vectorBool: size miss match in assignment operation" - ); - if( this != &x ) - { clear(); - // - length_ = x.length_; - n_unit_ = x.n_unit_; - data_ = x.data_; - // - x.length_ = 0; - x.n_unit_ = 0; - x.data_ = CPPAD_NULL; - } - return *this; - } -# endif - - - /// non-constant element access; i.e., we can change this element value - vectorBoolElement operator[]( - /// element index, must be less than length - size_t k - ) - { size_t i, j; - CPPAD_ASSERT_KNOWN( - k < length_, - "vectorBool: index greater than or equal vector size" - ); - i = k / bit_per_unit_; - j = k - i * bit_per_unit_; - return vectorBoolElement(data_ + i , UnitType(1) << j ); - } - /// constant element access; i.e., we cannot change this element value - bool operator[](size_t k) const - { size_t i, j; - UnitType unit, mask; - CPPAD_ASSERT_KNOWN( - k < length_, - "vectorBool: index greater than or equal vector size" - ); - i = k / bit_per_unit_; - j = k - i * bit_per_unit_; - unit = data_[i]; - mask = UnitType(1) << j; - return (unit & mask) != 0; - } - /// add an element to the back of this vector - void push_back( - /// value of the element - bool bit - ) - { CPPAD_ASSERT_UNKNOWN( unit_min() <= n_unit_ ); - size_t i, j; - UnitType mask; - if( length_ + 1 > n_unit_ * bit_per_unit_ ) - { CPPAD_ASSERT_UNKNOWN( unit_min() == n_unit_ ); - // store old n_unit and data values - size_t old_n_unit = n_unit_; - UnitType* old_data = data_; - // set new n_unit and data values - data_ = thread_alloc::create_array(n_unit_+1, n_unit_); - // copy old data values - for(i = 0; i < old_n_unit; i++) - data_[i] = old_data[i]; - // free old data - if( old_n_unit > 0 ) - thread_alloc::delete_array(old_data); - } - i = length_ / bit_per_unit_; - j = length_ - i * bit_per_unit_; - mask = UnitType(1) << j; - if( bit ) - data_[i] |= mask; - else data_[i] &= ~mask; - length_++; - } - /// add vector to the back of this vector - template - void push_vector( - /// value of the vector that we are adding - const Vector& v - ) - { CheckSimpleVector(); - size_t min_unit = unit_min(); - CPPAD_ASSERT_UNKNOWN( length_ <= n_unit_ * bit_per_unit_ ); - // some temporaries - size_t i, j, k, ell; - UnitType mask; - bool bit; - // store old length - size_t old_length = length_; - // new length and minium number of units; - length_ = length_ + v.size(); - min_unit = unit_min(); - if( length_ >= n_unit_ * bit_per_unit_ ) - { // store old n_unit and data value - size_t old_n_unit = n_unit_; - UnitType* old_data = data_; - // set new n_unit and data values - data_ = thread_alloc::create_array(min_unit, n_unit_); - // copy old data values - for(i = 0; i < old_n_unit; i++) - data_[i] = old_data[i]; - // free old data - if( old_n_unit > 0 ) - thread_alloc::delete_array(old_data); - } - ell = old_length; - for(k = 0; k < v.size(); k++) - { - i = ell / bit_per_unit_; - j = ell - i * bit_per_unit_; - bit = v[k]; - mask = UnitType(1) << j; - if( bit ) - data_[i] |= mask; - else data_[i] &= ~mask; - ell++; - } - CPPAD_ASSERT_UNKNOWN( length_ == ell ); - CPPAD_ASSERT_UNKNOWN( length_ <= n_unit_ * bit_per_unit_ ); - } -}; - -/// output a vector -inline std::ostream& operator << ( - /// steam to write the vector to - std::ostream& os , - /// vector that is output - const vectorBool& v ) -{ size_t i = 0; - size_t n = v.size(); - - while(i < n) - os << v[i++]; - return os; -} - -} // END_CPPAD_NAMESPACE -# endif diff --git a/external/cppad/include/cppad/wno_conversion.hpp b/external/cppad/include/cppad/wno_conversion.hpp deleted file mode 100644 index 9361d28eb..000000000 --- a/external/cppad/include/cppad/wno_conversion.hpp +++ /dev/null @@ -1,44 +0,0 @@ -# ifndef CPPAD_WNO_CONVERSION_HPP -# define CPPAD_WNO_CONVERSION_HPP -/* -------------------------------------------------------------------------- -CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell - -CppAD is distributed under multiple licenses. This distribution is under -the terms of the - Eclipse Public License Version 1.0. - -A copy of this license is included in the COPYING file of this distribution. -Please visit http://www.coin-or.org/CppAD/ for information on other licenses. --------------------------------------------------------------------------- */ - -/* -$begin wno_conversion$$ -$spell - cppad - wno - cpp - hpp -$$ - -$section Suppress Suspect Implicit Conversion Warnings$$ - -$head Syntax$$ -$codei%# include %$$ - -$head Purpose$$ -In many cases it is good to have warnings for implicit conversions -that may loose range or precision. -The include command above, before any other includes, suppresses -these warning for a particular compilation unit (which usually corresponds -to a $icode%*%.cpp%$$ file). - -$end -*/ - -# include -# if CPPAD_COMPILER_IS_GNUCXX -# pragma GCC diagnostic ignored "-Wfloat-conversion" -# pragma GCC diagnostic ignored "-Wconversion" -# endif - -# endif diff --git a/external/cppad/share/pkgconfig/cppad.pc b/external/cppad/share/pkgconfig/cppad.pc deleted file mode 100644 index 811c7b1d6..000000000 --- a/external/cppad/share/pkgconfig/cppad.pc +++ /dev/null @@ -1,29 +0,0 @@ -# $Id: cppad.pc.in 3760 2015-12-01 04:12:28Z bradbell $ -# ----------------------------------------------------------------------------- -# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell -# -# CppAD is distributed under multiple licenses. This distribution is under -# the terms of the -# Eclipse Public License Version 1.0. -# -# A copy of this license is included in the COPYING file of this distribution. -# Please visit http://www.coin-or.org/CppAD/ for information on other licenses. -# ----------------------------------------------------------------------------- -# This file is used with pkg-config to include CppAD after it is installed - -# ------------------------------------------------------------------------- -# HACK: With no specifications as to what will work in the future, set the -# values 'includedir' and 'prefix' so cppad.pc works with the 2015-01-21 -# verison of https://build.opensuse.org/package/view_file/ -# windows:mingw:win32/mingw32-filesystem/mingw32-install-post.sh?expand=1 -prefix=/home/batman/one/external/cppad -includedir=/home/batman/one/external/cppad/include -# ------------------------------------------------------------------------- - -Name: cppad -Description: Differentiation of C++ Algorithms -Version: 20170816 -URL: http://www.coin-or.org/CppAD -Cflags: -I/home/batman/one/external/cppad/include -Libs: -Requires: diff --git a/external/gpac/bin/MP4Box b/external/gpac/bin/MP4Box deleted file mode 100755 index b29392502..000000000 Binary files a/external/gpac/bin/MP4Box and /dev/null differ diff --git a/external/gpac/build.sh b/external/gpac/build.sh deleted file mode 100644 index e1f909e1f..000000000 --- a/external/gpac/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -git clone https://github.com/gpac/gpac.git -b v0.6.1 -cd gpac -./configure --static-mp4box --use-zlib=no -cp bin/gcc/MP4Box ../bin/ - diff --git a/external/ipfs/build.txt b/external/ipfs/build.txt deleted file mode 100644 index 9021e6f1d..000000000 --- a/external/ipfs/build.txt +++ /dev/null @@ -1,3 +0,0 @@ -wget https://dist.ipfs.io/go-ipfs/v0.4.10/go-ipfs_v0.4.10_linux-amd64.tar.gz -tar xvf go-ipfs_v0.4.10_linux-amd64.tar.gz -mv go-ipfs/ipfs . diff --git a/external/ipfs/ipfs b/external/ipfs/ipfs deleted file mode 100755 index 20c349c3c..000000000 Binary files a/external/ipfs/ipfs and /dev/null differ diff --git a/external/ipopt/bin/ipopt b/external/ipopt/bin/ipopt deleted file mode 100755 index 1648d93dc..000000000 Binary files a/external/ipopt/bin/ipopt and /dev/null differ diff --git a/external/ipopt/build.txt b/external/ipopt/build.txt deleted file mode 100644 index 32fb05849..000000000 --- a/external/ipopt/build.txt +++ /dev/null @@ -1,25 +0,0 @@ -wget 'https://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.8.zip' -7z x Ipopt-3.12.8.zip -cd Ipopt-3.12.8/ - -pushd ThirdParty/Blas -./get.Blas -mkdir build && cd build -../configure --prefix="$HOME/one/external/ipopt" --disable-shared --with-pic -make install -popd - -pushd ThirdParty/Lapack -./get.Lapack -mkdir build && cd build -../configure --prefix="$HOME/one/external/ipopt" --disable-shared --with-pic --with-blas="$HOME/one/external/ipopt/lib/libcoinblas.a -lgfortran" -make install -popd - -(cd ThirdParty/ASL && ./get.ASL) -(cd ThirdParty/Mumps && ./get.Mumps) - -./configure --prefix="$HOME/one/external/ipopt" coin_skip_warn_cxxflags=yes --with-blas="$HOME/one/external/ipopt/lib/libcoinblas.a -lgfortran" --with-lapack="$HOME/one/external/ipopt/lib/libcoinlapack.a" --disable-shared --with-pic -make -make test -make -j1 install diff --git a/external/ipopt/include/coin/AmplTNLP.hpp b/external/ipopt/include/coin/AmplTNLP.hpp deleted file mode 100644 index a8c823ae0..000000000 --- a/external/ipopt/include/coin/AmplTNLP.hpp +++ /dev/null @@ -1,569 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: AmplTNLP.hpp 2242 2013-04-24 19:26:30Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPAMPLTNLP_HPP__ -#define __IPAMPLTNLP_HPP__ - -#include "IpUtils.hpp" -#include "IpTNLP.hpp" -#include "IpJournalist.hpp" -#include "IpOptionsList.hpp" - -#include -#include - -/* non Ipopt forward declaration */ -struct ASL_pfgh; -struct SufDecl; -struct SufDesc; - -namespace Ipopt -{ - class AmplSuffixHandler : public ReferencedObject - { - public: - AmplSuffixHandler(); - - ~AmplSuffixHandler(); - - enum Suffix_Type - { - Index_Type, - Number_Type - }; - - enum Suffix_Source - { - Variable_Source, - Constraint_Source, - Objective_Source, - Problem_Source - }; - - void AddAvailableSuffix(std::string suffix_string, Suffix_Source source, Suffix_Type type) - { - suffix_ids_.push_back(suffix_string); - suffix_types_.push_back(type); - suffix_sources_.push_back(source); - // suffix_values_.push_back(); - } - - const Index* GetIntegerSuffixValues(std::string suffix_string, Suffix_Source source) const; - - const Number* GetNumberSuffixValues(std::string suffix_string, Suffix_Source source) const; - - std::vector GetIntegerSuffixValues(Index n, std::string suffix_string, Suffix_Source source) const; - - std::vector GetNumberSuffixValues(Index n, std::string suffix_string, Suffix_Source source) const; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - //AmplSuffixHandler(); - - /** Copy Constructor */ - AmplSuffixHandler(const AmplSuffixHandler&); - - /** Overloaded Equals Operator */ - void operator=(const AmplSuffixHandler&); - //@} - - mutable ASL_pfgh* asl_; - - SufDecl* suftab_; - - std::vector suffix_ids_; - std::vector suffix_types_; - std::vector suffix_sources_; - - /** Method called by AmplTNLP to prepare the asl for the suffixes */ - void PrepareAmplForSuffixes(ASL_pfgh* asl); - - /** Method called by AmplTNLP to retrieve the suffixes from asl */ - // void RetrieveSuffixesFromAmpl(ASL_pfgh* asl); - - friend class AmplTNLP; - }; - - /** Class for storing a number of AMPL options that should be - * registered to the AMPL Solver library interface */ - class AmplOptionsList : public ReferencedObject - { - public: - enum AmplOptionType { - String_Option, - Number_Option, - Integer_Option, - WS_Option, /* this is for AMPL's internal wantsol callback */ - HaltOnError_Option /* this is for our setting of the nerror_ member */ - }; - - /** Ampl Option class, contains name, type and description for an - * AMPL option */ - class AmplOption : public ReferencedObject - { - public: - AmplOption(const std::string ipopt_option_name, - AmplOptionType type, - const std::string description); - - ~AmplOption() - { - delete [] description_; - } - - const std::string& IpoptOptionName() const - { - return ipopt_option_name_; - } - AmplOptionType Type() const - { - return type_; - } - char* Description() const - { - return description_; - } - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - AmplOption(); - - /** Copy Constructor */ - AmplOption(const AmplOption&); - - /** Overloaded Equals Operator */ - void operator=(const AmplOption&); - //@} - - const std::string ipopt_option_name_; - const AmplOptionType type_; - char* description_; - }; - - class PrivatInfo - { - public: - PrivatInfo(const std::string ipopt_name, - SmartPtr options, - SmartPtr jnlst, - void** nerror = NULL) - : - ipopt_name_(ipopt_name), - options_(options), - jnlst_(jnlst), - nerror_(nerror) - {} - const std::string& IpoptName() const - { - return ipopt_name_; - } - const SmartPtr& Options() const - { - return options_; - } - const SmartPtr& Jnlst() const - { - return jnlst_; - } - void** NError() - { - return nerror_; - } - private: - const std::string ipopt_name_; - const SmartPtr options_; - const SmartPtr jnlst_; - void** nerror_; - }; - - public: - /** Default Constructor */ - AmplOptionsList() - : - keywds_(NULL), - nkeywds_(0) - {} - - /** Destructor */ - ~AmplOptionsList(); - - /** Adding a new AMPL Option */ - void AddAmplOption(const std::string ampl_option_name, - const std::string ipopt_option_name, - AmplOptionsList::AmplOptionType type, - const std::string description) - { - SmartPtr new_option = - new AmplOption(ipopt_option_name, type, description); - ampl_options_map_[ampl_option_name] = ConstPtr(new_option); - } - - /** Number of AMPL Options */ - Index NumberOfAmplOptions() - { - return (Index)ampl_options_map_.size(); - } - - /** ASL keywords list for the stored options. */ - void* Keywords(const SmartPtr& options, - SmartPtr jnlst, - void** nerror); - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - //AmplOptionsList(); - - /** Copy Constructor */ - AmplOptionsList(const AmplOptionsList&); - - /** Overloaded Equals Operator */ - void operator=(const AmplOptionsList&); - //@} - - void MakeValidLatexString(std::string source, std::string& dest) const; - - void PrintLatex(SmartPtr jnlst); - - /** map for storing registered AMPL options */ - std::map > ampl_options_map_; - // AW: I think it should be with const like in the following line - // but with const the AIX compiler fails - // std::map > ampl_options_map_; - - /** pointer to the keywords */ - void* keywds_; - - /** Number of entries stored in keywds_ */ - Index nkeywds_; - }; - - /** Ampl Interface. - * Ampl Interface, implemented as a TNLP. - */ - class AmplTNLP : public TNLP - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor. */ - AmplTNLP(const SmartPtr& jnlst, - const SmartPtr options, - char**& argv, SmartPtr - suffix_handler = NULL, bool allow_discrete = false, - SmartPtr ampl_options_list = NULL, - const char* ampl_option_string = NULL, - const char* ampl_invokation_string = NULL, - const char* ampl_banner_string = NULL, - std::string* nl_file_content = NULL); - - /** Default destructor */ - virtual ~AmplTNLP(); - //@} - - /** Exceptions */ - DECLARE_STD_EXCEPTION(NONPOSITIVE_SCALING_FACTOR); - - /**@name methods to gather information about the NLP. These - * methods are overloaded from TNLP. See TNLP for their more - * detailed documentation. */ - //@{ - /** returns dimensions of the nlp. Overloaded from TNLP */ - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style); - - /** returns names and other meta data for the variables and constraints - * Overloaded from TNLP */ - virtual bool get_var_con_metadata(Index n, - StringMetaDataMapType& var_string_md, - IntegerMetaDataMapType& var_integer_md, - NumericMetaDataMapType& var_numeric_md, - Index m, - StringMetaDataMapType& con_string_md, - IntegerMetaDataMapType& con_integer_md, - NumericMetaDataMapType& con_numeric_md); - - /** returns bounds of the nlp. Overloaded from TNLP */ - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u); - - /** Returns the constraint linearity. - * array will be alocated with length n. (default implementation - * just return false and does not fill the array). */ - virtual bool get_constraints_linearity(Index m, - LinearityType* const_types); - - /** provides a starting point for the nlp variables. Overloaded - from TNLP */ - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, Number* lambda); - - /** evaluates the objective value for the nlp. Overloaded from TNLP */ - virtual bool eval_f(Index n, const Number* x, bool new_x, - Number& obj_value); - - /** evaluates the gradient of the objective for the - nlp. Overloaded from TNLP */ - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, - Number* grad_f); - - /** evaluates the constraint residuals for the nlp. Overloaded from TNLP */ - virtual bool eval_g(Index n, const Number* x, bool new_x, - Index m, Number* g); - - /** specifies the jacobian structure (if values is NULL) and - * evaluates the jacobian values (if values is not NULL) for the - * nlp. Overloaded from TNLP */ - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, - Index *jCol, Number* values); - - /** specifies the structure of the hessian of the lagrangian (if - * values is NULL) and evaluates the values (if values is not - * NULL). Overloaded from TNLP */ - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, Index* iRow, - Index* jCol, Number* values); - - /** retrieve the scaling parameters for the variables, objective - * function, and constraints. */ - virtual bool get_scaling_parameters(Number& obj_scaling, - bool& use_x_scaling, Index n, - Number* x_scaling, - bool& use_g_scaling, Index m, - Number* g_scaling); - //@} - - /** @name Solution Methods */ - //@{ - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); - //@} - - /** @name Method for quasi-Newton approximation information. */ - //@{ - virtual Index get_number_of_nonlinear_variables(); - virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, - Index* pos_nonlin_vars); - //@} - - - /**@name Ampl specific methods */ - //@{ - /** Return the ampl solver object (ASL*) */ - ASL_pfgh* AmplSolverObject() - { - return asl_; - } - - /** Write the solution file. This is a wrapper for AMPL's - * write_sol. TODO Maybe this should be at a different place, or - * collect the numbers itself? */ - void write_solution_file(const std::string& message) const; - - /** ampl orders the variables like (continuous, binary, integer). - * This method gives the number of binary and integer variables. - * For details, see Tables 3 and 4 in "Hooking Your Solver to - * AMPL" - */ - void get_discrete_info(Index& nlvb_, - Index& nlvbi_, - Index& nlvc_, - Index& nlvci_, - Index& nlvo_, - Index& nlvoi_, - Index& nbv_, - Index& niv_) const; - //@} - - /** A method for setting the index of the objective function to be - * considered. This method must be called after the constructor, - * and before anything else is called. It can only be called - * once, and if there is more than one objective function in the - * AMPL model, it MUST be called. */ - void set_active_objective(Index obj_no); - - /**@name Methods to set meta data for the variables - * and constraints. These values will be passed on - * to the TNLP in get_var_con_meta_data - */ - //@{ - void set_string_metadata_for_var(std::string tag, std::vector meta_data) - { - var_string_md_[tag] = meta_data; - } - - void set_integer_metadata_for_var(std::string tag, std::vector meta_data) - { - var_integer_md_[tag] = meta_data; - } - - void set_numeric_metadata_for_var(std::string tag, std::vector meta_data) - { - var_numeric_md_[tag] = meta_data; - } - - void set_string_metadata_for_con(std::string tag, std::vector meta_data) - { - con_string_md_[tag] = meta_data; - } - - void set_integer_metadata_for_con(std::string tag, std::vector meta_data) - { - con_integer_md_[tag] = meta_data; - } - - void set_numeric_metadata_for_con(std::string tag, std::vector meta_data) - { - con_numeric_md_[tag] = meta_data; - } - //@} - - /** Method for returning the suffix handler */ - SmartPtr get_suffix_handler() - { - return suffix_handler_; - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - AmplTNLP(); - - /** Copy Constructor */ - AmplTNLP(const AmplTNLP&); - - /** Overloaded Equals Operator */ - void operator=(const AmplTNLP&); - //@} - - /** Journlist */ - SmartPtr jnlst_; - - /** pointer to the main ASL structure */ - ASL_pfgh* asl_; - - /** Sign of the objective fn (1 for min, -1 for max) */ - double obj_sign_; - - /**@name Problem Size Data*/ - //@{ - Index nz_h_full_; // number of nonzeros in the full_x hessian - /* the rest of the problem size data is available easily through the ampl variables */ - //@} - - /**@name Internal copies of data */ - //@{ - /** Solution Vectors */ - Number* x_sol_; - Number* z_L_sol_; - Number* z_U_sol_; - Number* g_sol_; - Number* lambda_sol_; - Number obj_sol_; - //@} - - /**@name Flags to track internal state */ - //@{ - /** true when the objective value has been calculated with the - * current x, set to false in apply_new_x, and set to true in - * internal_objval */ - bool objval_called_with_current_x_; - /** true when the constraint values have been calculated with the - * current x, set to false in apply_new_x, and set to true in - * internal_conval */ - bool conval_called_with_current_x_; - /** true when we have called hesset */ - bool hesset_called_; - /** true when set_active_objective has been called */ - bool set_active_objective_called_; - //@} - - /** Pointer to the Oinfo structure */ - void* Oinfo_ptr_; - - /** nerror flag passed to ampl calls - set to NULL to halt on error */ - void* nerror_; - - /** Suffix Handler */ - SmartPtr suffix_handler_; - - /** Make the objective call to ampl */ - bool internal_objval(const Number* x, Number& obj_val); - - /** Make the constraint call to ampl*/ - bool internal_conval(const Number* x, Index m, Number* g=NULL); - - /** Internal function to update the internal and ampl state if the - * x value changes */ - bool apply_new_x(bool new_x, Index n, const Number* x); - - /** Method for obtaining the name of the NL file and the options - * set from AMPL. Returns a pointer to a char* with the name of - * the stub */ - char* get_options(const SmartPtr& options, - SmartPtr& ampl_options_list, - const char* ampl_option_string, - const char* ampl_invokation_string, - const char* ampl_banner_string, char**& argv); - - /** returns true if the ampl nerror code is ok */ - bool nerror_ok(void* nerror); - - /** calls hesset ASL function */ - void call_hesset(); - - /** meta data to pass on to TNLP */ - StringMetaDataMapType var_string_md_; - IntegerMetaDataMapType var_integer_md_; - NumericMetaDataMapType var_numeric_md_; - StringMetaDataMapType con_string_md_; - IntegerMetaDataMapType con_integer_md_; - NumericMetaDataMapType con_numeric_md_; - }; - - - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/HSLLoader.h b/external/ipopt/include/coin/HSLLoader.h deleted file mode 100644 index c38915cbd..000000000 --- a/external/ipopt/include/coin/HSLLoader.h +++ /dev/null @@ -1,378 +0,0 @@ -/* Copyright (C) 2008, 2011 GAMS Development and others - All Rights Reserved. - This code is published under the Eclipse Public License. - - $Id: HSLLoader.h 2317 2013-06-01 13:16:07Z stefan $ - - Author: Stefan Vigerske -*/ - -#ifndef HSLLOADER_H_ -#define HSLLOADER_H_ - -#include "IpoptConfig.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef ma77_default_control -#define ma77_control ma77_control_d -#define ma77_info ma77_info_d -#define ma77_default_control ma77_default_control_d -#define ma77_open_nelt ma77_open_nelt_d -#define ma77_open ma77_open_d -#define ma77_input_vars ma77_input_vars_d -#define ma77_input_reals ma77_input_reals_d -#define ma77_analyse ma77_analyse_d -#define ma77_factor ma77_factor_d -#define ma77_factor_solve ma77_factor_solve_d -#define ma77_solve ma77_solve_d -#define ma77_resid ma77_resid_d -#define ma77_scale ma77_scale_d -#define ma77_enquire_posdef ma77_enquire_posdef_d -#define ma77_enquire_indef ma77_enquire_indef_d -#define ma77_alter ma77_alter_d -#define ma77_restart ma77_restart_d -#define ma77_finalise ma77_finalise_d -#endif - -struct ma77_control; -struct ma77_info; -typedef double ma77pkgtype_d_; - - -#ifndef ma86_default_control -#define ma86_control ma86_control_d -#define ma86_info ma86_info_d -#define ma86_default_control ma86_default_control_d -#define ma86_analyse ma86_analyse_d -#define ma86_factor ma86_factor_d -#define ma86_factor_solve ma86_factor_solve_d -#define ma86_solve ma86_solve_d -#define ma86_finalise ma86_finalise_d -#endif - -struct ma86_control; -struct ma86_info; -typedef double ma86pkgtype_d_; -typedef double ma86realtype_d_; - -#ifndef ma97_default_control -#define ma97_control ma97_control_d -#define ma97_info ma97_info_d -#define ma97_default_control ma97_default_control_d -#define ma97_analyse ma97_analyse_d -#define ma97_factor ma97_factor_d -#define ma97_factor_solve ma97_factor_solve_d -#define ma97_solve ma97_solve_d -#define ma97_finalise ma97_finalise_d -#define ma97_free_akeep ma97_free_akeep_d -#endif - -struct ma97_control; -struct ma97_info; -typedef double ma97pkgtype_d_; -typedef double ma97realtype_d_; - -struct mc68_control_i; -struct mc68_info_i; - -#ifndef __IPTYPES_HPP__ -/* Type of Fortran integer translated into C */ -typedef FORTRAN_INTEGER_TYPE ipfint; -#endif - -typedef void (*ma27ad_t)(ipfint *N, ipfint *NZ, const ipfint *IRN, const ipfint* ICN, - ipfint *IW, ipfint* LIW, ipfint* IKEEP, ipfint *IW1, - ipfint* NSTEPS, ipfint* IFLAG, ipfint* ICNTL, - double* CNTL, ipfint *INFO, double* OPS); -typedef void (*ma27bd_t)(ipfint *N, ipfint *NZ, const ipfint *IRN, const ipfint* ICN, - double* A, ipfint* LA, ipfint* IW, ipfint* LIW, - ipfint* IKEEP, ipfint* NSTEPS, ipfint* MAXFRT, - ipfint* IW1, ipfint* ICNTL, double* CNTL, - ipfint* INFO); -typedef void (*ma27cd_t)(ipfint *N, double* A, ipfint* LA, ipfint* IW, - ipfint* LIW, double* W, ipfint* MAXFRT, - double* RHS, ipfint* IW1, ipfint* NSTEPS, - ipfint* ICNTL, double* CNTL); -typedef void (*ma27id_t)(ipfint* ICNTL, double* CNTL); - -typedef void (*ma28ad_t)(void* nsize, void* nz, void* rw, void* licn, void* iw, - void* lirn, void* iw2, void* pivtol, void* iw3, void* iw4, void* rw2, void* iflag); - -typedef void (*ma57ad_t) ( - ipfint *n, /* Order of matrix. */ - ipfint *ne, /* Number of entries. */ - const ipfint *irn, /* Matrix nonzero row structure */ - const ipfint *jcn, /* Matrix nonzero column structure */ - ipfint *lkeep, /* Workspace for the pivot order of lenght 3*n */ - ipfint *keep, /* Workspace for the pivot order of lenght 3*n */ - /* Automatically iflag = 0; ikeep pivot order iflag = 1 */ - ipfint *iwork, /* Integer work space. */ - ipfint *icntl, /* Integer Control parameter of length 30*/ - ipfint *info, /* Statistical Information; Integer array of length 20 */ - double *rinfo); /* Double Control parameter of length 5 */ - -typedef void (*ma57bd_t) ( - ipfint *n, /* Order of matrix. */ - ipfint *ne, /* Number of entries. */ - double *a, /* Numerical values. */ - double *fact, /* Entries of factors. */ - ipfint *lfact, /* Length of array `fact'. */ - ipfint *ifact, /* Indexing info for factors. */ - ipfint *lifact, /* Length of array `ifact'. */ - ipfint *lkeep, /* Length of array `keep'. */ - ipfint *keep, /* Integer array. */ - ipfint *iwork, /* Workspace of length `n'. */ - ipfint *icntl, /* Integer Control parameter of length 20. */ - double *cntl, /* Double Control parameter of length 5. */ - ipfint *info, /* Statistical Information; Integer array of length 40. */ - double *rinfo); /* Statistical Information; Real array of length 20. */ - -typedef void (*ma57cd_t) ( - ipfint *job, /* Solution job. Solve for... */ - ipfint *n, /* Order of matrix. */ - double *fact, /* Entries of factors. */ - ipfint *lfact, /* Length of array `fact'. */ - ipfint *ifact, /* Indexing info for factors. */ - ipfint *lifact, /* Length of array `ifact'. */ - ipfint *nrhs, /* Number of right hand sides. */ - double *rhs, /* Numerical Values. */ - ipfint *lrhs, /* Leading dimensions of `rhs'. */ - double *work, /* Real workspace. */ - ipfint *lwork, /* Length of `work', >= N*NRHS. */ - ipfint *iwork, /* Integer array of length `n'. */ - ipfint *icntl, /* Integer Control parameter array of length 20. */ - ipfint *info); /* Statistical Information; Integer array of length 40. */ - -typedef void (*ma57ed_t) ( - ipfint *n, - ipfint *ic, /* 0: copy real array. >=1: copy integer array. */ - ipfint *keep, - double *fact, - ipfint *lfact, - double *newfac, - ipfint *lnew, - ipfint *ifact, - ipfint *lifact, - ipfint *newifc, - ipfint *linew, - ipfint *info); - -typedef void (*ma57id_t) (double *cntl, ipfint *icntl); - -typedef void (*ma77_default_control_t)(struct ma77_control_d *control); -typedef void (*ma77_open_nelt_t)(const int n, const char* fname1, const char* fname2, - const char *fname3, const char *fname4, void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info, - const int nelt); -typedef void (*ma77_open_t)(const int n, const char* fname1, const char* fname2, - const char *fname3, const char *fname4, void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_input_vars_t)(const int idx, const int nvar, const int list[], - void **keep, const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_input_reals_t)(const int idx, const int length, - const double reals[], void **keep, const struct ma77_control_d *control, - struct ma77_info_d *info); -typedef void (*ma77_analyse_t)(const int order[], void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_factor_t)(const int posdef, void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info, - const double *scale); -typedef void (*ma77_factor_solve_t)(const int posdef, void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info, - const double *scale, const int nrhs, const int lx, - double rhs[]); -typedef void (*ma77_solve_t)(const int job, const int nrhs, const int lx, double x[], - void **keep, const struct ma77_control_d *control, struct ma77_info_d *info, - const double *scale); -typedef void (*ma77_resid_t)(const int nrhs, const int lx, const double x[], - const int lresid, double resid[], void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info, - double *anorm_bnd); -typedef void (*ma77_scale_t)(double scale[], void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info, - double *anorm); -typedef void (*ma77_enquire_posdef_t)(double d[], void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_enquire_indef_t)(int piv_order[], double d[], void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_alter_t)(const double d[], void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_restart_t)(const char *restart_file, const char *fname1, - const char *fname2, const char *fname3, const char *fname4, void **keep, - const struct ma77_control_d *control, struct ma77_info_d *info); -typedef void (*ma77_finalise_t)(void **keep, const struct ma77_control_d *control, - struct ma77_info_d *info); - -typedef void (*ma86_default_control_t)(struct ma86_control *control); -typedef void (*ma86_analyse_t)(const int n, const int ptr[], const int row[], - int order[], void **keep, const struct ma86_control *control, - struct ma86_info *info); -typedef void (*ma86_factor_t)(const int n, const int ptr[], const int row[], - const ma86pkgtype_d_ val[], const int order[], void **keep, - const struct ma86_control *control, struct ma86_info *info, - const ma86pkgtype_d_ scale[]); -typedef void (*ma86_factor_solve_t)(const int n, const int ptr[], - const int row[], const ma86pkgtype_d_ val[], const int order[], void **keep, - const struct ma86_control *control, struct ma86_info *info, const int nrhs, - const int ldx, ma86pkgtype_d_ x[], const ma86pkgtype_d_ scale[]); -typedef void (*ma86_solve_t)(const int job, const int nrhs, const int ldx, - ma86pkgtype_d_ *x, const int order[], void **keep, - const struct ma86_control *control, struct ma86_info *info, - const ma86pkgtype_d_ scale[]); -typedef void (*ma86_finalise_t)(void **keep, - const struct ma86_control *control); - -typedef void (*ma97_default_control_t)(struct ma97_control *control); -typedef void (*ma97_analyse_t)(const int check, const int n, const int ptr[], - const int row[], ma97pkgtype_d_ val[], void **akeep, - const struct ma97_control *control, struct ma97_info *info, int order[]); -typedef void (*ma97_factor_t)(const int matrix_type, const int ptr[], - const int row[], const ma97pkgtype_d_ val[], void **akeep, void **fkeep, - const struct ma97_control *control, struct ma97_info *info, - const ma97pkgtype_d_ scale[]); -typedef void (*ma97_factor_solve_t)(const int matrix_type, const int ptr[], - const int row[], const ma97pkgtype_d_ val[], const int nrhs, - ma97pkgtype_d_ x[], const int ldx, void **akeep, void **fkeep, - const struct ma97_control *control, struct ma97_info *info, - const ma97pkgtype_d_ scale[]); -typedef void (*ma97_solve_t)(const int job, const int nrhs, ma97pkgtype_d_ *x, - const int ldx, void **akeep, void **fkeep, - const struct ma97_control *control, struct ma97_info *info); -typedef void (*ma97_finalise_t)(void **akeep, void **fkeep); -typedef void (*ma97_free_akeep_t)(void **akeep); - -typedef void (*mc19ad_t)(ipfint *N, ipfint *NZ, double* A, ipfint *IRN, ipfint* ICN, float* R, float* C, float* W); - -typedef void (*mc68_default_control_t)(struct mc68_control_i *control); -typedef void (*mc68_order_t)(int ord, int n, const int ptr[], - const int row[], int perm[], const struct mc68_control_i *control, - struct mc68_info_i *info); - - /** Tries to load a dynamically linked library with HSL routines. - * Also tries to load symbols for those HSL routines that are not linked into Ipopt, i.e., HAVE_... is not defined. - * Return a failure if the library cannot be loaded, but not if a symbol is not found. - * @see LSL_isMA27available - * @see LSL_isMA28available - * @see LSL_isMA57available - * @see LSL_isMA77available - * @see LSL_isMA86available - * @see LSL_isMA97available - * @see LSL_isMC19available - * @param libname The name under which the HSL lib can be found, or NULL to use a default name (libhsl.SHAREDLIBEXT). - * @param msgbuf A buffer where we can store a failure message. Assumed to be NOT NULL! - * @param msglen Length of the message buffer. - * @return Zero on success, nonzero on failure. - */ - int LSL_loadHSL(const char* libname, char* msgbuf, int msglen); - - /** Unloads a loaded HSL library. - * @return Zero on success, nonzero on failure. - */ - int LSL_unloadHSL(); - - /** Indicates whether a HSL library has been loaded. - * @return Zero if not loaded, nonzero if handle is loaded - */ - int LSL_isHSLLoaded(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use MA27 have been found. - * @return Zero if not available, nonzero if MA27 is available in the loaded library. - */ - int LSL_isMA27available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use MA28 have been found. - * @return Zero if not available, nonzero if MA28 is available in the loaded library. - */ - int LSL_isMA28available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use MA57 have been found. - * @return Zero if not available, nonzero if MA57 is available in the loaded library. - */ - int LSL_isMA57available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use MA77 have been found. - * @return Zero if not available, nonzero if HSL_MA77 is available in the loaded library. - */ - int LSL_isMA77available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use HSL_MA86 have been found. - * @return Zero if not available, nonzero if HSL_MA86 is available in the loaded library. - */ - int LSL_isMA86available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use HSL_MA97 have been found. - * @return Zero if not available, nonzero if HSL_MA97 is available in the loaded library. - */ - int LSL_isMA97available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use MA57 have been found. - * @return Zero if not available, nonzero if MC19 is available in the loaded library. - */ - int LSL_isMC19available(); - - /** Indicates whether a HSL library is loaded and all symbols necessary to use HSL_MC68 have been found. - * @return Zero if not available, nonzero if MC68 is available in the loaded library. - */ - int LSL_isMC68available(); - - /** Returns name of the shared library that should contain HSL */ - char* LSL_HSLLibraryName(); - - /** sets pointers to MA27 functions */ - void LSL_setMA27(ma27ad_t ma27ad, ma27bd_t ma27bd, ma27cd_t ma27cd, ma27id_t ma27id); - - /** sets pointers to MA28 functions */ - void LSL_setMA28(ma28ad_t ma28ad); - - /** sets pointers to MA57 functions */ - void LSL_setMA57(ma57ad_t ma57ad, ma57bd_t ma57bd, ma57cd_t ma57cd, ma57ed_t ma57ed, ma57id_t ma57id); - - /** sets pointers to MA77 functions */ - void LSL_setMA77(ma77_default_control_t ma77_default_control, - ma77_open_nelt_t ma77_open_nelt, - ma77_open_t ma77_open, - ma77_input_vars_t ma77_input_vars, - ma77_input_reals_t ma77_input_reals, - ma77_analyse_t ma77_analyse, - ma77_factor_t ma77_factor, - ma77_factor_solve_t ma77_factor_solve, - ma77_solve_t ma77_solve, - ma77_resid_t ma77_resid, - ma77_scale_t ma77_scale, - ma77_enquire_posdef_t ma77_enquire_posdef, - ma77_enquire_indef_t ma77_enquire_indef, - ma77_alter_t ma77_alter, - ma77_restart_t ma77_restart, - ma77_finalise_t ma77_finalise); - - /** sets pointers to MA86 functions */ - void LSL_setMA86(ma86_default_control_t ma86_default_control, - ma86_analyse_t ma86_analyse, - ma86_factor_t ma86_factor, - ma86_factor_solve_t ma86_factor_solve, - ma86_solve_t ma86_solve, - ma86_finalise_t ma86_finalise); - - /** sets pointers to MA97 functions */ - void LSL_setMA97(ma97_default_control_t ma97_default_control, - ma97_analyse_t ma97_analyse, - ma97_factor_t ma97_factor, - ma97_factor_solve_t ma97_factor_solve, - ma97_solve_t ma97_solve, - ma97_finalise_t ma97_finalise, - ma97_free_akeep_t ma97_free_akeep); - - /** sets pointer to MC19 function */ - void LSL_setMC19(mc19ad_t mc19ad); - - /** sets pointers to MC68 functions */ - void LSL_setMC68(mc68_default_control_t mc68_default_control, mc68_order_t mc68_order); - -#ifdef __cplusplus -} -#endif - -#endif /*HSLLOADER_H_*/ diff --git a/external/ipopt/include/coin/IpAlgBuilder.hpp b/external/ipopt/include/coin/IpAlgBuilder.hpp deleted file mode 100644 index 05692bbc6..000000000 --- a/external/ipopt/include/coin/IpAlgBuilder.hpp +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright (C) 2004, 2007 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpAlgBuilder.hpp 2666 2016-07-20 16:02:55Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-09-29 - -#ifndef __IPALGBUILDER_HPP__ -#define __IPALGBUILDER_HPP__ - -#include "IpIpoptAlg.hpp" -#include "IpReferenced.hpp" -#include "IpAugSystemSolver.hpp" -#include "IpPDSystemSolver.hpp" - -namespace Ipopt -{ - - // forward declarations - class IterationOutput; - class HessianUpdater; - class ConvergenceCheck; - class SearchDirectionCalculator; - class EqMultiplierCalculator; - class IterateInitializer; - class LineSearch; - class MuUpdate; - - /** Builder for creating a complete IpoptAlg object. This object - * contains all subelements (such as line search objects etc). How - * the resulting IpoptAlg object is built can be influenced by the - * options. - * - * More advanced customization can be achieved by subclassing this - * class and overloading the virtual methods that build the - * individual parts. The advantage of doing this is that it allows - * one to reuse the extensive amount of options processing that - * takes place, for instance, when generating the symmetric linear - * system solver. Another method for customizing the algorithm is - * using the optional custom_solver argument, which allows the - * expert user to provide a specialized linear solver for the - * augmented system (e.g., type GenAugSystemSolver), possibly for - * user-defined matrix objects. The optional custom_solver constructor - * argument is likely obsolete, however, as more control over this - * this process can be achieved by implementing a subclass of this - * AlgBuilder (e.g., by overloading the AugSystemSolverFactory method). - */ - class AlgorithmBuilder : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor */ - AlgorithmBuilder(SmartPtr custom_solver=NULL); - - /** Destructor */ - virtual ~AlgorithmBuilder() - {} - - //@} - - /** Methods for IpoptTypeInfo */ - //@{ - /** register the options used by the algorithm builder */ - static void RegisterOptions(SmartPtr roptions); - //@} - - /** @name Convenience methods for building solvers without having - * to duplicate the significant amount of preprocessor flag and - * option checking that takes place. These solvers are used to - * create a number of core algorithm components across the - * different Build* methods, but depending on what options are - * chosen, the first method requiring the solver to be used can - * vary. Therefore, each of the Factory methods below is paired - * with a Getter method, which is called by all parts of this - * algorithm builder to ensure the Factory is only called once. */ - //@{ - - /** Create a solver that can be used to solve a symmetric linear - * system. - * Dependencies: None - */ - virtual SmartPtr - SymLinearSolverFactory(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Get the symmetric linear system solver for this - * algorithm. This method will call the SymLinearSolverFactory - * exactly once (the first time it is used), and store its - * instance on SymSolver_ for use in subsequent calls. - */ - SmartPtr GetSymLinearSolver(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Create a solver that can be used to solve an - * augmented system. - * Dependencies: - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr - AugSystemSolverFactory(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Get the augmented system solver for this algorithm. This - * method will call the AugSystemSolverFactory exactly once (the - * first time it is used), and store its instance on AugSolver_ - * for use in subsequent calls. - */ - SmartPtr GetAugSystemSolver(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Create a solver that can be used to solve a - * primal-dual system. - * Dependencies: - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr - PDSystemSolverFactory(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Get the primal-dual system solver for this algorithm. This - * method will call the PDSystemSolverFactory exactly once (the - * first time it is used), and store its instance on PDSolver_ - * for use in subsequent calls. - */ - SmartPtr GetPDSystemSolver(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - //@} - - /** @name Methods to build parts of the algorithm */ - //@{ - /** Allocates memory for the IpoptNLP, IpoptData, and - * IpoptCalculatedQuanties arguments. - * Dependencies: None - */ - virtual void BuildIpoptObjects(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix, - const SmartPtr& nlp, - SmartPtr& ip_nlp, - SmartPtr& ip_data, - SmartPtr& ip_cq); - - /** Creates an instance of the IpoptAlgorithm class by building - * each of its required constructor arguments piece-by-piece. The - * default algorithm can be customized by overloading this method - * or by overloading one or more of the Build* methods called in - * this method's default implementation. Additional control can - * be achieved by overloading any of the *SolverFactory methods. - * This method will call (in this order): - * -> BuildIterationOutput() - * -> BuildHessianUpdater() - * -> BuildConvergenceCheck() - * -> BuildSearchDirectionCalculator() - * -> BuildEqMultiplierCalculator() - * -> BuildIterateInitializer() - * -> BuildLineSearch() - * -> BuildMuUpdate() - */ - virtual SmartPtr BuildBasicAlgorithm(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the IterationOutput class. This method - * is called in the default implementation of - * BuildBasicAlgorithm. It can be overloaded to customize that - * portion the default algorithm. - * Dependencies: None - */ - virtual SmartPtr - BuildIterationOutput(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the HessianUpdater class. This method - * is called in the default implementation of - * BuildBasicAlgorithm. It can be overloaded to customize that - * portion the default algorithm. - * Dependencies: None - */ - virtual SmartPtr - BuildHessianUpdater(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the ConvergenceCheck class. This method - * is called in the default implementation of - * BuildBasicAlgorithm. It can be overloaded to customize that - * portion the default algorithm. - * Dependencies: None - */ - virtual SmartPtr - BuildConvergenceCheck(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the SearchDirectionCalculator - * class. This method is called in the default implementation of - * BuildBasicAlgorithm. It can be overloaded to customize that - * portion the default algorithm. - * Dependencies: - * -> GetPDSystemSolver() - * -> PDSystemSolverFactory() - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr - BuildSearchDirectionCalculator(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the EqMultiplierCalculator class. This - * method is called in the default implementation of - * BuildBasicAlgorithm. It can be overloaded to customize that - * portion the default algorithm. - * Dependencies: - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr - BuildEqMultiplierCalculator(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the IterateInitializer class. This - * method is called in the default implementation of - * BuildBasicAlgorithm. It can be overloaded to customize that - * portion the default algorithm. - * Dependencies: - * -> EqMultCalculator_ - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr - BuildIterateInitializer(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the LineSearch class. This method is - * called in the default implementation of BuildBasicAlgorithm. - * It can be overloaded to customize that portion the default - * algorithm. - * Dependencies: - * -> EqMultCalculator_ - * -> ConvCheck_ - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - * -> GetPDSystemSolver() - * -> PDSystemSolverFactory() - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr BuildLineSearch(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Creates an instance of the MuUpdate class. This method is - * called in the default implementation of BuildBasicAlgorithm. - * It can be overloaded to customize that portion the default - * algorithm. - * Dependencies: - * -> LineSearch_ - * -> EqMultCalculator_ - * -> ConvCheck_ - * -> GetPDSystemSolver() - * -> PDSystemSolverFactory() - * -> GetAugSystemSolver() - * -> AugSystemSolverFactory() - * -> GetSymLinearSolver() - * -> SymLinearSolverFactory() - * -> custom_solver_ - */ - virtual SmartPtr BuildMuUpdate(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - //AlgorithmBuilder(); - - /** Copy Constructor */ - AlgorithmBuilder(const AlgorithmBuilder&); - - /** Overloaded Equals Operator */ - void operator=(const AlgorithmBuilder&); - //@} - - /** @name IpoptAlgorithm constructor arguments. - * These components are built in separate Build - * methods in the order defined by BuildBasicAlgorithm. - * A single core component may require one or more - * other core components in its constructor, so the - * this class holds pointers to each component for use - * between the separate Build methods. */ - //@{ - SmartPtr IterOutput_; - SmartPtr HessUpdater_; - SmartPtr ConvCheck_; - SmartPtr SearchDirCalc_; - SmartPtr EqMultCalculator_; - SmartPtr IterInitializer_; - SmartPtr LineSearch_; - SmartPtr MuUpdate_; - //@} - - /** @name Commonly used solver components - * for building core algorithm components. Each - * of these members is paired with a Factory/Getter - * method. */ - //@{ - SmartPtr SymSolver_; - SmartPtr AugSolver_; - SmartPtr PDSolver_; - //@} - - /** Optional pointer to AugSystemSolver. If this is set in the - * contructor, we will use this to solve the linear systems. */ - SmartPtr custom_solver_; - - }; -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpAlgStrategy.hpp b/external/ipopt/include/coin/IpAlgStrategy.hpp deleted file mode 100644 index 746a96844..000000000 --- a/external/ipopt/include/coin/IpAlgStrategy.hpp +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpAlgStrategy.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPALGSTRATEGY_HPP__ -#define __IPALGSTRATEGY_HPP__ - -#include "IpOptionsList.hpp" -#include "IpJournalist.hpp" -#include "IpIpoptCalculatedQuantities.hpp" -#include "IpIpoptNLP.hpp" -#include "IpIpoptData.hpp" - -namespace Ipopt -{ - - /** This is the base class for all algorithm strategy objects. The - * AlgorithmStrategyObject base class implements a common interface - * for all algorithm strategy objects. A strategy object is a - * component of the algorithm for which different alternatives or - * implementations exists. It allows to compose the algorithm - * before execution for a particular configuration, without the - * need to call alternatives based on enums. For example, the - * LineSearch object is a strategy object, since different line - * search options might be used for different runs. - * - * This interface is used for - * things that are done to all strategy objects, like - * initialization and setting options. - */ - class AlgorithmStrategyObject : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - AlgorithmStrategyObject() - : - initialize_called_(false) - {} - - /** Default Destructor */ - virtual ~AlgorithmStrategyObject() - {} - //@} - - /** This method is called every time the algorithm starts again - - * it is used to reset any internal state. The pointers to the - * Journalist, as well as to the IpoptNLP, IpoptData, and - * IpoptCalculatedQuantities objects should be stored in the - * instanciation of this base class. This method is also used to - * get all required user options from the OptionsList. Here, if - * prefix is given, each tag (identifying the options) is first - * looked for with the prefix in front, and if not found, without - * the prefix. Note: you should not cue off of the iteration - * count to indicate the "start" of an algorithm! - * - * Do not overload this method, since it does some general - * initialization that is common for all strategy objects. - * Overload the protected InitializeImpl method instead. - */ - bool Initialize(const Journalist& jnlst, - IpoptNLP& ip_nlp, - IpoptData& ip_data, - IpoptCalculatedQuantities& ip_cq, - const OptionsList& options, - const std::string& prefix) - { - initialize_called_ = true; - // Copy the pointers for the problem defining objects - jnlst_ = &jnlst; - ip_nlp_ = &ip_nlp; - ip_data_ = &ip_data; - ip_cq_ = &ip_cq; - - bool retval = InitializeImpl(options, prefix); - if (!retval) { - initialize_called_ = false; - } - - return retval; - } - - /** Reduced version of the Initialize method, which does not - * require special Ipopt information. This is useful for - * algorithm objects that could be used outside Ipopt, such as - * linear solvers. */ - bool ReducedInitialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix) - { - initialize_called_ = true; - // Copy the pointers for the problem defining objects - jnlst_ = &jnlst; - ip_nlp_ = NULL; - ip_data_ = NULL; - ip_cq_ = NULL; - - bool retval = InitializeImpl(options, prefix); - if (!retval) { - initialize_called_ = false; - } - - return retval; - } - - protected: - /** Implementation of the initialization method that has to be - * overloaded by for each derived class. */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix)=0; - - /** @name Accessor methods for the problem defining objects. - * Those should be used by the derived classes. */ - //@{ - const Journalist& Jnlst() const - { - DBG_ASSERT(initialize_called_); - return *jnlst_; - } - IpoptNLP& IpNLP() const - { - DBG_ASSERT(initialize_called_); - DBG_ASSERT(IsValid(ip_nlp_)); - return *ip_nlp_; - } - IpoptData& IpData() const - { - DBG_ASSERT(initialize_called_); - DBG_ASSERT(IsValid(ip_data_)); - return *ip_data_; - } - IpoptCalculatedQuantities& IpCq() const - { - DBG_ASSERT(initialize_called_); - DBG_ASSERT(IsValid(ip_cq_)); - return *ip_cq_; - } - bool HaveIpData() const - { - return IsValid(ip_data_); - } - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - //AlgorithmStrategyObject(); - - - /** Copy Constructor */ - AlgorithmStrategyObject(const AlgorithmStrategyObject&); - - /** Overloaded Equals Operator */ - void operator=(const AlgorithmStrategyObject&); - //@} - - /** @name Pointers to objects defining a particular optimization - * problem */ - //@{ - SmartPtr jnlst_; - SmartPtr ip_nlp_; - SmartPtr ip_data_; - SmartPtr ip_cq_; - //@} - - /** flag indicating if Initialize method has been called (for - * debugging) */ - bool initialize_called_; - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpAlgTypes.hpp b/external/ipopt/include/coin/IpAlgTypes.hpp deleted file mode 100644 index 53e8ea54d..000000000 --- a/external/ipopt/include/coin/IpAlgTypes.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2005, 2010 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpAlgTypes.hpp 2551 2015-02-13 02:51:47Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2005-07-19 - -#ifndef __IPALGTYPES_HPP__ -#define __IPALGTYPES_HPP__ - -#include "IpTypes.hpp" -#include "IpException.hpp" - -namespace Ipopt -{ - - /**@name Enumerations */ - //@{ - /** enum for the return from the optimize algorithm - * (obviously we need to add more) */ - enum SolverReturn { - SUCCESS, - MAXITER_EXCEEDED, - CPUTIME_EXCEEDED, - STOP_AT_TINY_STEP, - STOP_AT_ACCEPTABLE_POINT, - LOCAL_INFEASIBILITY, - USER_REQUESTED_STOP, - FEASIBLE_POINT_FOUND, - DIVERGING_ITERATES, - RESTORATION_FAILURE, - ERROR_IN_STEP_COMPUTATION, - INVALID_NUMBER_DETECTED, - TOO_FEW_DEGREES_OF_FREEDOM, - INVALID_OPTION, - OUT_OF_MEMORY, - INTERNAL_ERROR, - UNASSIGNED - }; - //@} - - /** @name Some exceptions used in multiple places */ - //@{ - DECLARE_STD_EXCEPTION(LOCALLY_INFEASIBLE); - DECLARE_STD_EXCEPTION(TOO_FEW_DOF); - DECLARE_STD_EXCEPTION(TINY_STEP_DETECTED); - DECLARE_STD_EXCEPTION(ACCEPTABLE_POINT_REACHED); - DECLARE_STD_EXCEPTION(FEASIBILITY_PROBLEM_SOLVED); - DECLARE_STD_EXCEPTION(INVALID_WARMSTART); - DECLARE_STD_EXCEPTION(INTERNAL_ABORT); - DECLARE_STD_EXCEPTION(NO_FREE_VARIABLES_BUT_FEASIBLE); - DECLARE_STD_EXCEPTION(NO_FREE_VARIABLES_AND_INFEASIBLE); - DECLARE_STD_EXCEPTION(INCONSISTENT_BOUNDS); - /** Exception FAILED_INITIALIZATION for problem during - * initialization of a strategy object (or other problems). This - * is thrown by a strategy object, if a problem arises during - * initialization, such as a value out of a feasible range. - */ - DECLARE_STD_EXCEPTION(FAILED_INITIALIZATION); - //@} - - -} - -#endif diff --git a/external/ipopt/include/coin/IpAugSystemSolver.hpp b/external/ipopt/include/coin/IpAugSystemSolver.hpp deleted file mode 100644 index 1396ce441..000000000 --- a/external/ipopt/include/coin/IpAugSystemSolver.hpp +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpAugSystemSolver.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IP_AUGSYSTEMSOLVER_HPP__ -#define __IP_AUGSYSTEMSOLVER_HPP__ - -#include "IpSymMatrix.hpp" -#include "IpSymLinearSolver.hpp" -#include "IpAlgStrategy.hpp" - -namespace Ipopt -{ - DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER); - - /** Base class for Solver for the augmented system. This is the - * base class for linear solvers that solve the augmented system, - * which is defined as - * - * \f$\left[\begin{array}{cccc} - * W + D_x + \delta_xI & 0 & J_c^T & J_d^T\\ - * 0 & D_s + \delta_sI & 0 & -I \\ - * J_c & 0 & D_c - \delta_cI & 0\\ - * J_d & -I & 0 & D_d - \delta_dI - * \end{array}\right] - * \left(\begin{array}{c}sol_x\\sol_s\\sol_c\\sol_d\end{array}\right)= - * \left(\begin{array}{c}rhs_x\\rhs_s\\rhs_c\\rhs_d\end{array}\right)\f$ - * - * Since this system might be solved repeatedly for different right - * hand sides, it is desirable to step the factorization of a - * direct linear solver if possible. - */ - class AugSystemSolver: public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor. */ - AugSystemSolver() - {} - /** Default destructor */ - virtual ~AugSystemSolver() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Set up the augmented system and solve it for a given right hand - * side. If desired (i.e. if check_NegEVals is true), then the - * solution is only computed if the number of negative eigenvalues - * matches numberOfNegEVals. - * - * The return value is the return value of the linear solver object. - */ - virtual ESymSolverStatus Solve( - const SymMatrix* W, - double W_factor, - const Vector* D_x, - double delta_x, - const Vector* D_s, - double delta_s, - const Matrix* J_c, - const Vector* D_c, - double delta_c, - const Matrix* J_d, - const Vector* D_d, - double delta_d, - const Vector& rhs_x, - const Vector& rhs_s, - const Vector& rhs_c, - const Vector& rhs_d, - Vector& sol_x, - Vector& sol_s, - Vector& sol_c, - Vector& sol_d, - bool check_NegEVals, - Index numberOfNegEVals) - { - std::vector > rhs_xV(1); - rhs_xV[0] = &rhs_x; - std::vector > rhs_sV(1); - rhs_sV[0] = &rhs_s; - std::vector > rhs_cV(1); - rhs_cV[0] = &rhs_c; - std::vector > rhs_dV(1); - rhs_dV[0] = &rhs_d; - std::vector > sol_xV(1); - sol_xV[0] = &sol_x; - std::vector > sol_sV(1); - sol_sV[0] = &sol_s; - std::vector > sol_cV(1); - sol_cV[0] = &sol_c; - std::vector > sol_dV(1); - sol_dV[0] = &sol_d; - return MultiSolve(W, W_factor, D_x, delta_x, D_s, delta_s, J_c, D_c, delta_c, - J_d, D_d, delta_d, rhs_xV, rhs_sV, rhs_cV, rhs_dV, - sol_xV, sol_sV, sol_cV, sol_dV, check_NegEVals, - numberOfNegEVals); - } - - /** Like Solve, but for multiple right hand sides. The inheriting - * class has to be overload at least one of Solve and - * MultiSolve. */ - virtual ESymSolverStatus MultiSolve( - const SymMatrix* W, - double W_factor, - const Vector* D_x, - double delta_x, - const Vector* D_s, - double delta_s, - const Matrix* J_c, - const Vector* D_c, - double delta_c, - const Matrix* J_d, - const Vector* D_d, - double delta_d, - std::vector >& rhs_xV, - std::vector >& rhs_sV, - std::vector >& rhs_cV, - std::vector >& rhs_dV, - std::vector >& sol_xV, - std::vector >& sol_sV, - std::vector >& sol_cV, - std::vector >& sol_dV, - bool check_NegEVals, - Index numberOfNegEVals) - { - // Solve for one right hand side after the other - Index nrhs = (Index)rhs_xV.size(); - DBG_ASSERT(nrhs>0); - DBG_ASSERT(nrhs==(Index)rhs_sV.size()); - DBG_ASSERT(nrhs==(Index)rhs_cV.size()); - DBG_ASSERT(nrhs==(Index)rhs_dV.size()); - DBG_ASSERT(nrhs==(Index)sol_xV.size()); - DBG_ASSERT(nrhs==(Index)sol_sV.size()); - DBG_ASSERT(nrhs==(Index)sol_cV.size()); - DBG_ASSERT(nrhs==(Index)sol_dV.size()); - - ESymSolverStatus retval=SYMSOLVER_SUCCESS; - for (Index i=0; i -#include -#include - -namespace Ipopt -{ - -#if COIN_IPOPT_CHECKLEVEL > 2 -# define IP_DEBUG_CACHE -#endif -#ifdef IP_DEBUG_CACHE -# include "IpDebug.hpp" -#endif - - // Forward Declarations - - template - class DependentResult; - - // AW: I'm taking this out, since this is by far the most used - // class. We should keep it as simple as possible. - // /** Cache Priority Enum */ - // enum CachePriority - // { - // CP_Lowest, - // CP_Standard, - // CP_Trial, - // CP_Iterate - // }; - - /** Templated class for Cached Results. This class stores up to a - * given number of "results", entities that are stored here - * together with identifiers, that can be used to later retrieve the - * information again. - * - * Typically, T is a SmartPtr for some calculated quantity that - * should be stored (such as a Vector). The identifiers (or - * dependencies) are a (possibly varying) number of Tags from - * TaggedObjects, and a number of Numbers. Results are added to - * the cache using the AddCachedResults methods, and the can be - * retrieved with the GetCachedResults methods. The second set of - * methods checks whether a result has been cached for the given - * identifiers. If a corresponding result is found, a copy of it - * is returned and the method evaluates to true, otherwise it - * evaluates to false. - * - * Note that cached results can become "stale", namely when a - * TaggedObject that is used to identify this CachedResult is - * changed. When this happens, the cached result can never be - * asked for again, so that there is no point in storing it any - * longer. For this purpose, a cached result, which is stored as a - * DependentResult, inherits off an Observer. This Observer - * retrieves notification whenever a TaggedObject dependency has - * changed. Stale results are later removed from the cache. - */ - template - class CachedResults - { - public: -#ifdef IP_DEBUG_CACHE - /** (Only if compiled in DEBUG mode): debug verbosity level */ - static const Index dbg_verbosity; -#endif - - /** @name Constructors and Destructors. */ - //@{ - /** Constructor, where max_cache_size is the maximal number of - * results that should be cached. If max_cache_size is negative, - * we allow an infinite amount of cache. - */ - CachedResults(Int max_cache_size); - - /** Destructor */ - virtual ~CachedResults(); - //@} - - /** @name Generic methods for adding and retrieving cached results. */ - //@{ - /** Generic method for adding a result to the cache, given a - * std::vector of TaggesObjects and a std::vector of Numbers. - */ - void AddCachedResult(const T& result, - const std::vector& dependents, - const std::vector& scalar_dependents); - - /** Generic method for retrieving a cached results, given the - * dependencies as a std::vector of TaggesObjects and a - * std::vector of Numbers. - */ - bool GetCachedResult(T& retResult, - const std::vector& dependents, - const std::vector& scalar_dependents) const; - - /** Method for adding a result, providing only a std::vector of - * TaggedObjects. - */ - void AddCachedResult(const T& result, - const std::vector& dependents); - - /** Method for retrieving a cached result, providing only a - * std::vector of TaggedObjects. - */ - bool GetCachedResult(T& retResult, - const std::vector& dependents) const; - //@} - - /** @name Pointer-based methods for adding and retrieving cached - * results, providing dependencies explicitly. - */ - //@{ - /** Method for adding a result to the cache, proving one - * dependency as a TaggedObject explicitly. - */ - void AddCachedResult1Dep(const T& result, - const TaggedObject* dependent1); - - /** Method for retrieving a cached result, proving one dependency - * as a TaggedObject explicitly. - */ - bool GetCachedResult1Dep(T& retResult, const TaggedObject* dependent1); - - /** Method for adding a result to the cache, proving two - * dependencies as a TaggedObject explicitly. - */ - void AddCachedResult2Dep(const T& result, - const TaggedObject* dependent1, - const TaggedObject* dependent2); - - /** Method for retrieving a cached result, proving two - * dependencies as a TaggedObject explicitly. - */ - bool GetCachedResult2Dep(T& retResult, - const TaggedObject* dependent1, - const TaggedObject* dependent2); - - /** Method for adding a result to the cache, proving three - * dependencies as a TaggedObject explicitly. - */ - void AddCachedResult3Dep(const T& result, - const TaggedObject* dependent1, - const TaggedObject* dependent2, - const TaggedObject* dependent3); - - /** Method for retrieving a cached result, proving three - * dependencies as a TaggedObject explicitly. - */ - bool GetCachedResult3Dep(T& retResult, - const TaggedObject* dependent1, - const TaggedObject* dependent2, - const TaggedObject* dependent3); - - /** @name Pointer-free version of the Add and Get methods */ - //@{ - bool GetCachedResult1Dep(T& retResult, const TaggedObject& dependent1) - { - return GetCachedResult1Dep(retResult, &dependent1); - } - bool GetCachedResult2Dep(T& retResult, - const TaggedObject& dependent1, - const TaggedObject& dependent2) - { - return GetCachedResult2Dep(retResult, &dependent1, &dependent2); - } - bool GetCachedResult3Dep(T& retResult, - const TaggedObject& dependent1, - const TaggedObject& dependent2, - const TaggedObject& dependent3) - { - return GetCachedResult3Dep(retResult, &dependent1, &dependent2, &dependent3); - } - void AddCachedResult1Dep(const T& result, - const TaggedObject& dependent1) - { - AddCachedResult1Dep(result, &dependent1); - } - void AddCachedResult2Dep(const T& result, - const TaggedObject& dependent1, - const TaggedObject& dependent2) - { - AddCachedResult2Dep(result, &dependent1, &dependent2); - } - void AddCachedResult3Dep(const T& result, - const TaggedObject& dependent1, - const TaggedObject& dependent2, - const TaggedObject& dependent3) - { - AddCachedResult3Dep(result, &dependent1, &dependent2, &dependent3); - } - //@} - - /** Invalidates the result for given dependencies. Sets the stale - * flag for the corresponding cached result to true if it is - * found. Returns true, if the result was found. */ - bool InvalidateResult(const std::vector& dependents, - const std::vector& scalar_dependents); - - /** Invalidates all cached results */ - void Clear(); - - /** Invalidate all cached results and changes max_cache_size */ - void Clear(Int max_cache_size); - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - CachedResults(); - - /** Copy Constructor */ - CachedResults(const CachedResults&); - - /** Overloaded Equals Operator */ - void operator=(const CachedResults&); - //@} - - /** maximum number of cached results */ - Int max_cache_size_; - - /** list of currently cached results. */ - mutable std::list*>* cached_results_; - - /** internal method for removing stale DependentResults from the - * list. It is called at the beginning of every - * GetDependentResult method. - */ - void CleanupInvalidatedResults() const; - - /** Print list of currently cached results */ - void DebugPrintCachedResults() const; - }; - - /** Templated class which stores one entry for the CachedResult - * class. It stores the result (of type T), together with its - * dependencies (vector of TaggedObjects and vector of Numbers). - * It also stores a priority. - */ - template - class DependentResult : public Observer - { - public: - -#ifdef IP_DEBUG_CACHE - static const Index dbg_verbosity; -#endif - - /** @name Constructor, Destructors */ - //@{ - /** Constructor, given all information about the result. */ - DependentResult(const T& result, const std::vector& dependents, - const std::vector& scalar_dependents); - - /** Destructor. */ - ~DependentResult(); - //@} - - /** @name Accessor method. */ - //@{ - /** This returns true, if the DependentResult is no longer valid. */ - bool IsStale() const; - - /** Invalidates the cached result. */ - void Invalidate(); - - /** Returns the cached result. */ - const T& GetResult() const; - //@} - - /** This method returns true if the dependencies provided to this - * function are identical to the ones stored with the - * DependentResult. - */ - bool DependentsIdentical(const std::vector& dependents, - const std::vector& scalar_dependents) const; - - /** Print information about this DependentResults. */ - void DebugPrint() const; - - protected: - /** This method is overloading the pure virtual method from the - * Observer base class. This method is called when a Subject - * registered for this Observer sends a notification. In this - * particular case, if this method is called with - * notify_type==NT_Changed or NT_BeingDeleted, then this results - * is marked as stale. - */ - virtual void RecieveNotification(NotifyType notify_type, const Subject* subject); - - private: - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - DependentResult(); - - /** Copy Constructor */ - DependentResult(const DependentResult&); - - /** Overloaded Equals Operator */ - void operator=(const DependentResult&); - //@} - - /** Flag indicating, if the cached result is still valid. A - result becomes invalid, if the RecieveNotification method is - called with NT_Changed */ - bool stale_; - /** The value of the dependent results */ - const T result_; - /** Dependencies in form of TaggedObjects */ - std::vector dependent_tags_; - /** Dependencies in form a Numbers */ - std::vector scalar_dependents_; - }; - -#ifdef IP_DEBUG_CACHE - template - const Index CachedResults::dbg_verbosity = 0; - - template - const Index DependentResult::dbg_verbosity = 0; -#endif - - template - DependentResult::DependentResult( - const T& result, - const std::vector& dependents, - const std::vector& scalar_dependents) - : - stale_(false), - result_(result), - dependent_tags_(dependents.size()), - scalar_dependents_(scalar_dependents) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("DependentResult::DependentResult()", dbg_verbosity); -#endif - - for (Index i=0; i<(Index)dependents.size(); i++) { - if (dependents[i]) { - // Call the RequestAttach method of the Observer base class. - // This will add this dependent result in the Observer list - // for the Subject dependents[i]. As a consequence, the - // RecieveNotification method of this DependentResult will be - // called with notify_type=NT_Changed, whenever the - // TaggedResult dependents[i] is changed (i.e. its HasChanged - // method is called). - RequestAttach(NT_Changed, dependents[i]); - dependent_tags_[i] = dependents[i]->GetTag(); - } - else { - dependent_tags_[i] = 0; - } - } - } - - template - DependentResult::~DependentResult() - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("DependentResult::~DependentResult()", dbg_verbosity); - //DBG_ASSERT(stale_ == true); -#endif - // Nothing to be done here, destructor - // of T should sufficiently remove - // any memory, etc. - } - - template - bool DependentResult::IsStale() const - { - return stale_; - } - - template - void DependentResult::Invalidate() - { - stale_ = true; - } - - template - void DependentResult::RecieveNotification(NotifyType notify_type, const Subject* subject) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("DependentResult::RecieveNotification", dbg_verbosity); -#endif - - if (notify_type == NT_Changed || notify_type==NT_BeingDestroyed) { - stale_ = true; - // technically, I could unregister the notifications here, but they - // aren't really hurting anything - } - } - - template - bool DependentResult::DependentsIdentical(const std::vector& dependents, - const std::vector& scalar_dependents) const - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("DependentResult::DependentsIdentical", dbg_verbosity); - DBG_ASSERT(stale_ == false); - DBG_ASSERT(dependents.size() == dependent_tags_.size()); -#endif - - bool retVal = true; - - if (dependents.size() != dependent_tags_.size() - || scalar_dependents.size() != scalar_dependents_.size()) { - retVal = false; - } - else { - for (Index i=0; i<(Index)dependents.size(); i++) { - if ( (dependents[i] && dependents[i]->GetTag() != dependent_tags_[i]) - || (!dependents[i] && dependent_tags_[i] != 0) ) { - retVal = false; - break; - } - } - if (retVal) { - for (Index i=0; i<(Index)scalar_dependents.size(); i++) { - if (scalar_dependents[i] != scalar_dependents_[i]) { - retVal = false; - break; - } - } - } - } - - return retVal; - } - - template - const T& DependentResult::GetResult() const - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("DependentResult::GetResult()", dbg_verbosity); - DBG_ASSERT(stale_ == false); -#endif - - return result_; - } - - template - void DependentResult::DebugPrint() const - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("DependentResult::DebugPrint", dbg_verbosity); -#endif - - } - - template - CachedResults::CachedResults(Int max_cache_size) - : - max_cache_size_(max_cache_size), - cached_results_(NULL) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::CachedResults", dbg_verbosity); -#endif - - } - - template - CachedResults::~CachedResults() - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::!CachedResults()", dbg_verbosity); -#endif - - if (cached_results_) { - for (typename std::list< DependentResult* >::iterator iter = cached_results_-> - begin(); - iter != cached_results_->end(); - iter++) { - delete *iter; - } - delete cached_results_; - } - /* - while (!cached_results_.empty()) { - DependentResult* result = cached_results_.back(); - cached_results_.pop_back(); - delete result; - } - */ - } - - template - void CachedResults::AddCachedResult(const T& result, - const std::vector& dependents, - const std::vector& scalar_dependents) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::AddCachedResult", dbg_verbosity); -#endif - - CleanupInvalidatedResults(); - - // insert the new one here - DependentResult* newResult = new DependentResult(result, dependents, scalar_dependents); - if (!cached_results_) { - cached_results_ = new std::list*>; - } - cached_results_->push_front(newResult); - - // keep the list small enough - if (max_cache_size_ >= 0) { // if negative, allow infinite cache - // non-negative - limit size of list to max_cache_size - DBG_ASSERT((Int)cached_results_->size()<=max_cache_size_+1); - if ((Int)cached_results_->size() > max_cache_size_) { - delete cached_results_->back(); - cached_results_->pop_back(); - } - } - -#ifdef IP_DEBUG_CACHE - DBG_EXEC(2, DebugPrintCachedResults()); -#endif - - } - - template - void CachedResults::AddCachedResult(const T& result, - const std::vector& dependents) - { - std::vector scalar_dependents; - AddCachedResult(result, dependents, scalar_dependents); - } - - template - bool CachedResults::GetCachedResult(T& retResult, const std::vector& dependents, - const std::vector& scalar_dependents) const - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::GetCachedResult", dbg_verbosity); -#endif - - if (!cached_results_) - return false; - - CleanupInvalidatedResults(); - - bool retValue = false; - typename std::list< DependentResult* >::const_iterator iter; - for (iter = cached_results_->begin(); iter != cached_results_->end(); iter++) { - if ((*iter)->DependentsIdentical(dependents, scalar_dependents)) { - retResult = (*iter)->GetResult(); - retValue = true; - break; - } - } - -#ifdef IP_DEBUG_CACHE - DBG_EXEC(2, DebugPrintCachedResults()); -#endif - - return retValue; - } - - template - bool CachedResults::GetCachedResult( - T& retResult, const std::vector& dependents) const - { - std::vector scalar_dependents; - return GetCachedResult(retResult, dependents, scalar_dependents); - } - - template - void CachedResults::AddCachedResult1Dep(const T& result, - const TaggedObject* dependent1) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::AddCachedResult1Dep", dbg_verbosity); -#endif - - std::vector dependents(1); - dependents[0] = dependent1; - - AddCachedResult(result, dependents); - } - - template - bool CachedResults::GetCachedResult1Dep(T& retResult, const TaggedObject* dependent1) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::GetCachedResult1Dep", dbg_verbosity); -#endif - - std::vector dependents(1); - dependents[0] = dependent1; - - return GetCachedResult(retResult, dependents); - } - - template - void CachedResults::AddCachedResult2Dep(const T& result, const TaggedObject* dependent1, - const TaggedObject* dependent2) - - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::AddCachedResult2dDep", dbg_verbosity); -#endif - - std::vector dependents(2); - dependents[0] = dependent1; - dependents[1] = dependent2; - - AddCachedResult(result, dependents); - } - - template - bool CachedResults::GetCachedResult2Dep(T& retResult, const TaggedObject* dependent1, const TaggedObject* dependent2) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::GetCachedResult2Dep", dbg_verbosity); -#endif - - std::vector dependents(2); - dependents[0] = dependent1; - dependents[1] = dependent2; - - return GetCachedResult(retResult, dependents); - } - - template - void CachedResults::AddCachedResult3Dep(const T& result, const TaggedObject* dependent1, - const TaggedObject* dependent2, - const TaggedObject* dependent3) - - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::AddCachedResult2dDep", dbg_verbosity); -#endif - - std::vector dependents(3); - dependents[0] = dependent1; - dependents[1] = dependent2; - dependents[2] = dependent3; - - AddCachedResult(result, dependents); - } - - template - bool CachedResults::GetCachedResult3Dep(T& retResult, const TaggedObject* dependent1, - const TaggedObject* dependent2, - const TaggedObject* dependent3) - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::GetCachedResult2Dep", dbg_verbosity); -#endif - - std::vector dependents(3); - dependents[0] = dependent1; - dependents[1] = dependent2; - dependents[2] = dependent3; - - return GetCachedResult(retResult, dependents); - } - - template - bool CachedResults::InvalidateResult(const std::vector& dependents, - const std::vector& scalar_dependents) - { - if (!cached_results_) - return false; - - CleanupInvalidatedResults(); - - bool retValue = false; - typename std::list< DependentResult* >::const_iterator iter; - for (iter = cached_results_->begin(); iter != cached_results_->end(); - iter++) { - if ((*iter)->DependentsIdentical(dependents, scalar_dependents)) { - (*iter)->Invalidate(); - retValue = true; - break; - } - } - - return retValue; - } - - template - void CachedResults::Clear() - { - if (!cached_results_) - return; - - typename std::list< DependentResult* >::const_iterator iter; - for (iter = cached_results_->begin(); iter != cached_results_->end(); - iter++) { - (*iter)->Invalidate(); - } - - CleanupInvalidatedResults(); - } - - template - void CachedResults::Clear(Int max_cache_size) - { - Clear(); - max_cache_size_ = max_cache_size; - } - - template - void CachedResults::CleanupInvalidatedResults() const - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::CleanupInvalidatedResults", dbg_verbosity); -#endif - - if (!cached_results_) - return; - - typename std::list< DependentResult* >::iterator iter; - iter = cached_results_->begin(); - while (iter != cached_results_->end()) { - if ((*iter)->IsStale()) { - typename std::list< DependentResult* >::iterator - iter_to_remove = iter; - iter++; - DependentResult* result_to_delete = (*iter_to_remove); - cached_results_->erase(iter_to_remove); - delete result_to_delete; - } - else { - iter++; - } - } - } - - template - void CachedResults::DebugPrintCachedResults() const - { -#ifdef IP_DEBUG_CACHE - DBG_START_METH("CachedResults::DebugPrintCachedResults", dbg_verbosity); - if (DBG_VERBOSITY()>=2 ) { - if (!cached_results_) { - DBG_PRINT((2,"Currentlt no cached results:\n")); - } - else { - typename std::list< DependentResult* >::const_iterator iter; - DBG_PRINT((2,"Current set of cached results:\n")); - for (iter = cached_results_->begin(); iter != cached_results_->end(); iter++) { - DBG_PRINT((2," DependentResult:0x%x\n", (*iter))); - } - } - } -#endif - - } - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpCompoundMatrix.hpp b/external/ipopt/include/coin/IpCompoundMatrix.hpp deleted file mode 100644 index 03e2e2a4c..000000000 --- a/external/ipopt/include/coin/IpCompoundMatrix.hpp +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpCompoundMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPCOMPOUNDMATRIX_HPP__ -#define __IPCOMPOUNDMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class CompoundMatrixSpace; - - /** Class for Matrices consisting of other matrices. This matrix is - * a matrix that consists of zero, one or more Matrices's which are - * arranged like this: \f$ M_{\rm compound} = - * \left(\begin{array}{cccc}M_{00} & M_{01} & \ldots & M_{0,{\rm - * ncomp\_cols}-1} \\ \dots &&&\dots \\ M_{{\rm ncomp\_rows}-1,0} & - * M_{{\rm ncomp\_rows}-1,1} & \dots & M_{{\rm ncomp\_rows}-1,{\rm - * ncomp\_cols}-1}\end{array}\right)\f$. The individual components - * can be associated to different MatrixSpaces. The individual - * components can also be const and non-const Matrices. If a - * component is not set (i.e., it's pointer is NULL), then this - * components is treated like a zero-matrix of appropriate - * dimensions. - */ - class CompoundMatrix : public Matrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the owner_space. The owner_space has to - * be defined, so that at each block row and column contain at - * least one non-NULL component. The individual components can - * be set afterwards with the SeteComp and SetCompNonConst - * methods. - */ - CompoundMatrix(const CompoundMatrixSpace* owner_space); - - /** Destructor */ - virtual ~CompoundMatrix(); - //@} - - /** Method for setting an individual component at position (irow, - * icol) in the compound matrix. The counting of indices starts - * at 0. */ - void SetComp(Index irow, Index jcol, const Matrix& matrix); - - /** Method to set a non-const Matrix entry */ - void SetCompNonConst(Index irow, Index jcol, Matrix& matrix); - - /** Method to create a new matrix from the space for this block */ - void CreateBlockFromSpace(Index irow, Index jcol); - - /** Method for retrieving one block from the compound matrix as a - * const Matrix. - */ - SmartPtr GetComp(Index irow, Index jcol) const - { - return ConstComp(irow, jcol); - } - - /** Method for retrieving one block from the compound matrix as a - * non-const Matrix. Note that calling this method with mark the - * CompoundMatrix as changed. Therefore, only use this method if - * you are intending to change the Matrix that you receive. */ - SmartPtr GetCompNonConst(Index irow, Index jcol) - { - ObjectChanged(); - return Comp(irow, jcol); - } - - /** Number of block rows of this compound matrix. */ - inline Index NComps_Rows() const; - /** Number of block colmuns of this compound matrix. */ - inline Index NComps_Cols() const; - - protected: - /**@name Methods overloaded from Matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - virtual void TransMultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** X = beta*X + alpha*(Matrix S^{-1} Z). Specialized implementation. - */ - virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z, - Vector& X) const; - - /** X = S^{-1} (r + alpha*Z*M^Td). Specialized implementation. - */ - virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S, - const Vector& R, const Vector& Z, - const Vector& D, Vector& X) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - CompoundMatrix(); - - /** Copy Constructor */ - CompoundMatrix(const CompoundMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const CompoundMatrix&); - //@} - - /** Matrix of matrix's containing the components */ - std::vector > > comps_; - - /** Matrix of const matrix's containing the components */ - std::vector > > const_comps_; - - /** Copy of the owner_space ptr as a CompoundMatrixSpace instead - * of MatrixSpace */ - const CompoundMatrixSpace* owner_space_; - - /** boolean indicating if the compound matrix is in a "valid" state */ - mutable bool matrices_valid_; - - /** Method to check whether or not the matrices are valid */ - bool MatricesValid() const; - - inline const Matrix* ConstComp(Index irow, Index jcol) const; - - inline Matrix* Comp(Index irow, Index jcol); - }; - - /** This is the matrix space for CompoundMatrix. Before a CompoundMatrix - * can be created, at least one MatrixSpace has to be set per block - * row and column. Individual component MatrixSpace's can be set - * with the SetComp method. - */ - class CompoundMatrixSpace : public MatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of row and columns blocks, as - * well as the totel number of rows and columns. - */ - CompoundMatrixSpace(Index ncomps_rows, - Index ncomps_cols, - Index total_nRows, - Index total_nCols); - - /** Destructor */ - ~CompoundMatrixSpace() - {} - //@} - - /** @name Methods for setting information about the components. */ - //@{ - /** Set the number nrows of rows in row-block number irow. */ - void SetBlockRows(Index irow, Index nrows); - - /** Set the number ncols of columns in column-block number jcol. */ - void SetBlockCols(Index jcol, Index ncols); - - /** Get the number nrows of rows in row-block number irow. */ - Index GetBlockRows(Index irow) const; - - /** Set the number ncols of columns in column-block number jcol. */ - Index GetBlockCols(Index jcol) const; - - /** Set the component MatrixSpace. If auto_allocate is true, then - * a new CompoundMatrix created later with MakeNew will have this - * component automatically created with the Matrix's MakeNew. - * Otherwise, the corresponding component will be NULL and has to - * be set with the SetComp methods of the CompoundMatrix. - */ - void SetCompSpace(Index irow, Index jcol, - const MatrixSpace& mat_space, - bool auto_allocate = false); - //@} - - /** Obtain the component MatrixSpace in block row irow and block - * column jcol. - */ - SmartPtr GetCompSpace(Index irow, Index jcol) const - { - DBG_ASSERT(irow > > comp_spaces_; - - /** 2-dim std::vector of booleans deciding whether to - * allocate a new matrix for the blocks automagically */ - std::vector > allocate_block_; - - /** Vector of the number of rows in each comp column */ - std::vector block_rows_; - - /** Vector of the number of cols in each comp row */ - std::vector block_cols_; - - /** true if the CompoundMatrixSpace only has Matrix spaces along the diagonal. - * this means that the CompoundMatrix will only have matrices along the - * diagonal and it could make some operations more efficient - */ - bool diagonal_; - - /** Auxilliary function for debugging to set if all block - * dimensions have been set. */ - bool DimensionsSet() const; - }; - - /* inline methods */ - inline - Index CompoundMatrix::NComps_Rows() const - { - return owner_space_->NComps_Rows(); - } - - inline - Index CompoundMatrix::NComps_Cols() const - { - return owner_space_->NComps_Cols(); - } - - inline - const Matrix* CompoundMatrix::ConstComp(Index irow, Index jcol) const - { - DBG_ASSERT(irow < NComps_Rows()); - DBG_ASSERT(jcol < NComps_Cols()); - if (IsValid(comps_[irow][jcol])) { - return GetRawPtr(comps_[irow][jcol]); - } - else if (IsValid(const_comps_[irow][jcol])) { - return GetRawPtr(const_comps_[irow][jcol]); - } - - return NULL; - } - - inline - Matrix* CompoundMatrix::Comp(Index irow, Index jcol) - { - DBG_ASSERT(irow < NComps_Rows()); - DBG_ASSERT(jcol < NComps_Cols()); - return GetRawPtr(comps_[irow][jcol]); - } - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpCompoundSymMatrix.hpp b/external/ipopt/include/coin/IpCompoundSymMatrix.hpp deleted file mode 100644 index 4ca18fe96..000000000 --- a/external/ipopt/include/coin/IpCompoundSymMatrix.hpp +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpCompoundSymMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPCOMPOUNDSYMMATRIX_HPP__ -#define __IPCOMPOUNDSYMMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class CompoundSymMatrixSpace; - - /** Class for symmetric matrices consisting of other matrices. - * Here, the lower left block of the matrix is stored. - */ - class CompoundSymMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking only the number for block components into the - * row and column direction. The owner_space has to be defined, so - * that at each block row and column contain at least one non-NULL - * component. - */ - CompoundSymMatrix(const CompoundSymMatrixSpace* owner_space); - - /** Destructor */ - ~CompoundSymMatrix(); - //@} - - /** Method for setting an individual component at position (irow, - * icol) in the compound matrix. The counting of indices starts - * at 0. Since this only the lower left components are stored, we need - * to have jcol<=irow, and if irow==jcol, the matrix must be a SymMatrix */ - void SetComp(Index irow, Index jcol, const Matrix& matrix); - - /** Non const version of the same method */ - void SetCompNonConst(Index irow, Index jcol, Matrix& matrix); - - /** Method for retrieving one block from the compound matrix. - * Since this only the lower left components are stored, we need - * to have jcol<=irow */ - SmartPtr GetComp(Index irow, Index jcol) const - { - return ConstComp(irow,jcol); - } - - /** Non const version of GetComp. You should only use this method - * if you are intending to change the matrix you receive, since - * this CompoundSymMatrix will be marked as changed. */ - SmartPtr GetCompNonConst(Index irow, Index jcol) - { - ObjectChanged(); - return Comp(irow,jcol); - } - - /** Method for creating a new matrix of this specific type. */ - SmartPtr MakeNewCompoundSymMatrix() const; - - // The following don't seem to be necessary - /* Number of block rows of this compound matrix. */ - // Index NComps_NRows() const { return NComps_Dim(); } - - /* Number of block colmuns of this compound matrix. */ - // Index NComps_NCols() const { return NComps_Dim(); } - - /** Number of block rows and columns */ - Index NComps_Dim() const; - - protected: - /**@name Methods overloaded from matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - CompoundSymMatrix(); - - /** Copy Constructor */ - CompoundSymMatrix(const CompoundSymMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const CompoundSymMatrix&); - //@} - - /** Vector of vectors containing the components */ - std::vector > > comps_; - - /** Vector of vectors containing the const components */ - std::vector > > const_comps_; - - /** Copy of the owner_space ptr as a CompoundSymMatrixSpace */ - const CompoundSymMatrixSpace* owner_space_; - - /** boolean indicating if the compound matrix is in a "valid" state */ - mutable bool matrices_valid_; - - /** method to check wether or not the matrices are valid */ - bool MatricesValid() const; - - /** Internal method to return a const pointer to one of the comps */ - const Matrix* ConstComp(Index irow, Index jcol) const - { - DBG_ASSERT(irow < NComps_Dim()); - DBG_ASSERT(jcol <= irow); - if (IsValid(comps_[irow][jcol])) { - return GetRawPtr(comps_[irow][jcol]); - } - else if (IsValid(const_comps_[irow][jcol])) { - return GetRawPtr(const_comps_[irow][jcol]); - } - - return NULL; - } - - /** Internal method to return a non-const pointer to one of the comps */ - Matrix* Comp(Index irow, Index jcol) - { - DBG_ASSERT(irow < NComps_Dim()); - DBG_ASSERT(jcol <= irow); - // We shouldn't be asking for a non-const if this entry holds a - // const one... - DBG_ASSERT(IsNull(const_comps_[irow][jcol])); - if (IsValid(comps_[irow][jcol])) { - return GetRawPtr(comps_[irow][jcol]); - } - - return NULL; - } - }; - - /** This is the matrix space for CompoundSymMatrix. Before a - * CompoundSymMatrix can be created, at least one SymMatrixSpace has - * to be set per block row and column. Individual component - * SymMatrixSpace's can be set with the SetComp method. - */ - class CompoundSymMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of blocks (same for rows and - * columns), as well as the total dimension of the matrix. - */ - CompoundSymMatrixSpace(Index ncomp_spaces, Index total_dim); - - /** Destructor */ - ~CompoundSymMatrixSpace() - {} - //@} - - /** @name Methods for setting information about the components. */ - //@{ - /** Set the dimension dim for block row (or column) irow_jcol */ - void SetBlockDim(Index irow_jcol, Index dim); - - /** Get the dimension dim for block row (or column) irow_jcol */ - Index GetBlockDim(Index irow_jcol) const; - - /** Set the component SymMatrixSpace. If auto_allocate is true, then - * a new CompoundSymMatrix created later with MakeNew will have this - * component automatically created with the SymMatrix's MakeNew. - * Otherwise, the corresponding component will be NULL and has to - * be set with the SetComp methods of the CompoundSymMatrix. - */ - void SetCompSpace(Index irow, Index jcol, - const MatrixSpace& mat_space, - bool auto_allocate = false); - //@} - - /** Obtain the component MatrixSpace in block row irow and block - * column jcol. - */ - SmartPtr GetCompSpace(Index irow, Index jcol) const - { - DBG_ASSERT(irow block_dim_; - - /** 2-dim std::vector of matrix spaces for the components. Only - * the lower right part is stored. */ - std::vector > > comp_spaces_; - - /** 2-dim std::vector of booleans deciding whether to - * allocate a new matrix for the blocks automagically */ - std::vector > allocate_block_; - - /** boolean indicating if the compound matrix space is in a "valid" state */ - mutable bool dimensions_set_; - - /** Method to check whether or not the spaces are valid */ - bool DimensionsSet() const; - }; - - inline - SmartPtr CompoundSymMatrix::MakeNewCompoundSymMatrix() const - { - return owner_space_->MakeNewCompoundSymMatrix(); - } - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpCompoundVector.hpp b/external/ipopt/include/coin/IpCompoundVector.hpp deleted file mode 100644 index a4c52abdb..000000000 --- a/external/ipopt/include/coin/IpCompoundVector.hpp +++ /dev/null @@ -1,339 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpCompoundVector.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPCOMPOUNDVECTOR_HPP__ -#define __IPCOMPOUNDVECTOR_HPP__ - -#include "IpUtils.hpp" -#include "IpVector.hpp" -#include - -namespace Ipopt -{ - - /* forward declarations */ - class CompoundVectorSpace; - - /** Class of Vectors consisting of other vectors. This vector is a - * vector that consists of zero, one or more Vector's which are - * stacked on each others: \f$ x_{\rm compound} = - * \left(\begin{array}{c}x_0\\\dots\\x_{{\rm - * ncomps} - 1}\end{array}\right)\f$. The individual components can be - * associated to different VectorSpaces. The individual components - * can also be const and non-const Vectors. - */ - class CompoundVector : public Vector - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor, given the corresponding CompoundVectorSpace. - * Before this constructor can be called, all components of the - * CompoundVectorSpace have to be set, so that the constructors - * for the individual components can be called. If the flag - * create_new is true, then the individual components of the new - * CompoundVector are initialized with the MakeNew methods of - * each VectorSpace (and are non-const). Otherwise, the - * individual components can later be set using the SetComp and - * SetCompNonConst method. - */ - CompoundVector(const CompoundVectorSpace* owner_space, bool create_new); - - /** Default destructor */ - virtual ~CompoundVector(); - //@} - - /** Method for setting the pointer for a component that is a const - * Vector - */ - void SetComp(Index icomp, const Vector& vec); - - /** Method for setting the pointer for a component that is a - * non-const Vector - */ - void SetCompNonConst(Index icomp, Vector& vec); - - /** Number of components of this compound vector */ - inline Index NComps() const; - - /** Check if a particular component is const or not */ - bool IsCompConst(Index i) const - { - DBG_ASSERT(i > 0 && i < NComps()); - DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i])); - if (IsValid(const_comps_[i])) { - return true; - } - return false; - } - - /** Check if a particular component is null or not */ - bool IsCompNull(Index i) const - { - DBG_ASSERT(i >= 0 && i < NComps()); - if (IsValid(comps_[i]) || IsValid(const_comps_[i])) { - return false; - } - return true; - } - - /** Return a particular component (const version) */ - SmartPtr GetComp(Index i) const - { - return ConstComp(i); - } - - /** Return a particular component (non-const version). Note that - * calling this method with mark the CompoundVector as changed. - * Therefore, only use this method if you are intending to change - * the Vector that you receive. - */ - SmartPtr GetCompNonConst(Index i) - { - ObjectChanged(); - return Comp(i); - } - - protected: - /** @name Overloaded methods from Vector base class */ - //@{ - /** Copy the data of the vector x into this vector (DCOPY). */ - virtual void CopyImpl(const Vector& x); - - /** Scales the vector by scalar alpha (DSCAL) */ - virtual void ScalImpl(Number alpha); - - /** Add the multiple alpha of vector x to this vector (DAXPY) */ - virtual void AxpyImpl(Number alpha, const Vector &x); - - /** Computes inner product of vector x with this (DDOT) */ - virtual Number DotImpl(const Vector &x) const; - - /** Computes the 2-norm of this vector (DNRM2) */ - virtual Number Nrm2Impl() const; - - /** Computes the 1-norm of this vector (DASUM) */ - virtual Number AsumImpl() const; - - /** Computes the max-norm of this vector (based on IDAMAX) */ - virtual Number AmaxImpl() const; - - /** Set each element in the vector to the scalar alpha. */ - virtual void SetImpl(Number value); - - /** Element-wise division \f$y_i \gets y_i/x_i\f$.*/ - virtual void ElementWiseDivideImpl(const Vector& x); - - /** Element-wise multiplication \f$y_i \gets y_i*x_i\f$.*/ - virtual void ElementWiseMultiplyImpl(const Vector& x); - - /** Element-wise max against entries in x */ - virtual void ElementWiseMaxImpl(const Vector& x); - - /** Element-wise min against entries in x */ - virtual void ElementWiseMinImpl(const Vector& x); - - /** Element-wise reciprocal */ - virtual void ElementWiseReciprocalImpl(); - - /** Element-wise absolute values */ - virtual void ElementWiseAbsImpl(); - - /** Element-wise square-root */ - virtual void ElementWiseSqrtImpl(); - - /** Replaces entries with sgn of the entry */ - virtual void ElementWiseSgnImpl(); - - /** Add scalar to every component of the vector.*/ - virtual void AddScalarImpl(Number scalar); - - /** Max value in the vector */ - virtual Number MaxImpl() const; - - /** Min value in the vector */ - virtual Number MinImpl() const; - - /** Computes the sum of the lements of vector */ - virtual Number SumImpl() const; - - /** Computes the sum of the logs of the elements of vector */ - virtual Number SumLogsImpl() const; - - /** @name Implemented specialized functions */ - //@{ - /** Add two vectors (a * v1 + b * v2). Result is stored in this - vector. */ - void AddTwoVectorsImpl(Number a, const Vector& v1, - Number b, const Vector& v2, Number c); - /** Fraction to the boundary parameter. */ - Number FracToBoundImpl(const Vector& delta, Number tau) const; - /** Add the quotient of two vectors, y = a * z/s + c * y. */ - void AddVectorQuotientImpl(Number a, const Vector& z, const Vector& s, - Number c); - //@} - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - /** @name Output methods */ - //@{ - /* Print the entire vector with padding */ - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. - */ - //@{ - /** Default Constructor */ - CompoundVector(); - - /** Copy Constructor */ - CompoundVector(const CompoundVector&); - - /** Overloaded Equals Operator */ - void operator=(const CompoundVector&); - //@} - - /** Components of the compound vector. The components - * are stored by SmartPtrs in a std::vector - */ - std::vector< SmartPtr > comps_; - std::vector< SmartPtr > const_comps_; - - const CompoundVectorSpace* owner_space_; - - bool vectors_valid_; - - bool VectorsValid(); - - inline const Vector* ConstComp(Index i) const; - - inline Vector* Comp(Index i); - }; - - /** This vectors space is the vector space for CompoundVector. - * Before a CompoundVector can be created, all components of this - * CompoundVectorSpace have to be set. When calling the constructor, - * the number of component has to be specified. The individual - * VectorSpaces can be set with the SetComp method. - */ - class CompoundVectorSpace : public VectorSpace - { - public: - /** @name Constructors/Destructors. */ - //@{ - /** Constructor, has to be given the number of components and the - * total dimension of all components combined. */ - CompoundVectorSpace(Index ncomp_spaces, Index total_dim); - - /** Destructor */ - ~CompoundVectorSpace() - {} - //@} - - /** Method for setting the individual component VectorSpaces */ - virtual void SetCompSpace(Index icomp /** Number of the component to be set */ , - const VectorSpace& vec_space /** VectorSpace for component icomp */ - ); - - /** Method for obtaining an individual component VectorSpace */ - SmartPtr GetCompSpace(Index icomp) const; - - /** Accessor method to obtain the number of components */ - Index NCompSpaces() const - { - return ncomp_spaces_; - } - - /** Method for creating a new vector of this specific type. */ - virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const - { - return new CompoundVector(this, create_new); - } - - /** Overloaded MakeNew method for the VectorSpace base class. - */ - virtual Vector* MakeNew() const - { - return MakeNewCompoundVector(); - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default constructor */ - CompoundVectorSpace(); - - /** Copy Constructor */ - CompoundVectorSpace(const CompoundVectorSpace&); - - /** Overloaded Equals Operator */ - CompoundVectorSpace& operator=(const CompoundVectorSpace&); - //@} - - /** Number of components */ - const Index ncomp_spaces_; - - /** std::vector of vector spaces for the components */ - std::vector< SmartPtr > comp_spaces_; - }; - - /* inline methods */ - inline - Index CompoundVector::NComps() const - { - return owner_space_->NCompSpaces(); - } - - inline - const Vector* CompoundVector::ConstComp(Index i) const - { - DBG_ASSERT(i < NComps()); - DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i])); - if (IsValid(comps_[i])) { - return GetRawPtr(comps_[i]); - } - else if (IsValid(const_comps_[i])) { - return GetRawPtr(const_comps_[i]); - } - - DBG_ASSERT(false && "shouldn't be here"); - return NULL; - } - - inline - Vector* CompoundVector::Comp(Index i) - { - DBG_ASSERT(i < NComps()); - DBG_ASSERT(IsValid(comps_[i])); - return GetRawPtr(comps_[i]); - } - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpConvCheck.hpp b/external/ipopt/include/coin/IpConvCheck.hpp deleted file mode 100644 index 033fce4a2..000000000 --- a/external/ipopt/include/coin/IpConvCheck.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpConvCheck.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPCONVCHECK_HPP__ -#define __IPCONVCHECK_HPP__ - -#include "IpAlgStrategy.hpp" - -namespace Ipopt -{ - - /** Base class for checking the algorithm - * termination criteria. - */ - class ConvergenceCheck : public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor */ - ConvergenceCheck() - {} - - /** Default destructor */ - virtual ~ConvergenceCheck() - {} - //@} - - /** Convergence return enum */ - enum ConvergenceStatus { - CONTINUE, - CONVERGED, - CONVERGED_TO_ACCEPTABLE_POINT, - MAXITER_EXCEEDED, - CPUTIME_EXCEEDED, - DIVERGING, - USER_STOP, - FAILED - }; - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Pure virtual method for performing the convergence test. If - * call_intermediate_callback is true, the user callback method - * in the NLP should be called in order to see if the user - * requests an early termination. */ - virtual ConvergenceStatus - CheckConvergence(bool call_intermediate_callback = true) = 0; - - /** Method for testing if the current iterate is considered to - * satisfy the "accptable level" of accuracy. The idea is that - * if the desired convergence tolerance cannot be achieved, the - * algorithm might stop after a number of acceptable points have - * been encountered. */ - virtual bool CurrentIsAcceptable()=0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - // ConvergenceCheck(); - - /** Copy Constructor */ - ConvergenceCheck(const ConvergenceCheck&); - - /** Overloaded Equals Operator */ - void operator=(const ConvergenceCheck&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpDebug.hpp b/external/ipopt/include/coin/IpDebug.hpp deleted file mode 100644 index b8aae13c9..000000000 --- a/external/ipopt/include/coin/IpDebug.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2004, 2007 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpDebug.hpp 2005 2011-06-06 12:55:16Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPDEBUG_HPP__ -#define __IPDEBUG_HPP__ - -#include "IpoptConfig.h" -#include "IpTypes.hpp" - -#ifdef COIN_IPOPT_CHECKLEVEL -#ifdef HAVE_CASSERT -# include -#else -# ifdef HAVE_ASSERT_H -# include -# else -# error "don't have header file for assert" -# endif -#endif -#else -#define COIN_IPOPT_CHECKLEVEL 0 -#endif - -#if COIN_IPOPT_CHECKLEVEL > 0 -# ifdef NDEBUG -# undef NDEBUG -# endif -# define DBG_ASSERT(test) assert(test) -# define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg) \ - ASSERT_EXCEPTION( (__condition), __except_type, __msg); -# define DBG_DO(__cmd) __cmd -#else -# define DBG_ASSERT(test) -# define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg) -# define DBG_DO(__cmd) -#endif - -#ifndef COIN_IPOPT_VERBOSITY -#define COIN_IPOPT_VERBOSITY 0 -#endif - -#if COIN_IPOPT_VERBOSITY < 1 -# define DBG_START_FUN(__func_name, __verbose_level) -# define DBG_START_METH(__func_name, __verbose_level) -# define DBG_PRINT(__printf_args) -# define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec) -# define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) -# define DBG_EXEC(__verbosity, __cmd) -# define DBG_VERBOSITY() 0 -#else -#include - -namespace Ipopt -{ - // forward definition - class Journalist; - - /** Class that lives throughout the execution of a method or - * function for which debug output is to be generated. The output - * is sent to the unique debug journalist that is set with - * SetJournalist at the beginning of program execution. */ - class DebugJournalistWrapper - { - public: - /** @name Constructors/Destructors. */ - //@{ - DebugJournalistWrapper(std::string func_name, Index verbose_level); - DebugJournalistWrapper(std::string func_name, Index verbose_level, - const void* const method_owner); - ~DebugJournalistWrapper(); - //@} - - /** @name accessor methods */ - //@{ - Index Verbosity() - { - return verbose_level_; - } - const Journalist* Jnlst() - { - return jrnl_; - } - Index IndentationLevel() - { - return indentation_level_; - } - //@} - - /** Printing */ - void DebugPrintf(Index verbosity, const char* pformat, ...); - - /* Method for initialization of the static GLOBAL journalist, - * through with all debug printout is to be written. This needs - * to be set before any debug printout can be done. */ - static void SetJournalist(Journalist* jrnl); - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** default constructor */ - DebugJournalistWrapper(); - - /** copy contructor */ - DebugJournalistWrapper(const DebugJournalistWrapper&); - - /** Overloaded Equals Operator */ - DebugJournalistWrapper& operator=(const DebugJournalistWrapper&); - //@} - - static Index indentation_level_; - std::string func_name_; - Index verbose_level_; - const void* method_owner_; - - static Journalist* jrnl_; - }; -} - -# define DBG_START_FUN(__func_name, __verbose_level) \ - DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level)); \ - -# define DBG_START_METH(__func_name, __verbose_level) \ - DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level), this); - -# define DBG_PRINT(__args) \ - dbg_jrnl.DebugPrintf __args; - -# define DBG_EXEC(__verbose_level, __cmd) \ - if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \ - (__cmd); \ - } - -# define DBG_VERBOSITY() \ - dbg_jrnl.Verbosity() - -#endif - - -#endif diff --git a/external/ipopt/include/coin/IpDenseVector.hpp b/external/ipopt/include/coin/IpDenseVector.hpp deleted file mode 100644 index 380a06c03..000000000 --- a/external/ipopt/include/coin/IpDenseVector.hpp +++ /dev/null @@ -1,550 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpDenseVector.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPDENSEVECTOR_HPP__ -#define __IPDENSEVECTOR_HPP__ - -#include "IpUtils.hpp" -#include "IpVector.hpp" -#include - -namespace Ipopt -{ - - /* forward declarations */ - class DenseVectorSpace; - - /** @name Exceptions */ - //@{ - DECLARE_STD_EXCEPTION(METADATA_ERROR); - //@} - - /** Dense Vector Implementation. This is the default Vector class - * in Ipopt. It stores vectors in contiguous Number arrays, unless - * the vector has the same value in all entires. In the latter - * case, we call the vector "homogeneous", and we store only the - * values that is repeated in all elements. If you want to obtain - * the values of vector, use the IsHomogeneous() method to find out - * what status the vector is in, and then use either Values() const - * or Scalar() const methods to get the values. To set the values - * of a homogeneous method, use the Set method. To set the values - * of a non-homogeneous vector, use the SetValues method, or use - * the non-const Values method to get an array that you can - * overwrite. In the latter case, storage is ensured. - */ - class DenseVector : public Vector - { - public: - - /**@name Constructors / Destructors */ - //@{ - /** Default Constructor - */ - DenseVector(const DenseVectorSpace* owner_space); - - /** Destructor - */ - virtual ~DenseVector(); - //@} - - /** @name Additional public methods not in Vector base class. */ - //@{ - /** Create a new DenseVector from same VectorSpace */ - SmartPtr MakeNewDenseVector() const; - - /** Set elements in the vector to the Number array x. */ - void SetValues(const Number *x); - - /** Obtain pointer to the internal Number array with vector - * elements with the indention to change the vector data (USE - * WITH CARE!). This does not produce a copy, and lifetime is not - * guaranteed!. - */ - inline Number* Values(); - - /** Obtain pointer to the internal Number array with vector - * elements without the intention to change the vector data (USE - * WITH CARE!). This does not produce a copy, and lifetime is not - * guaranteed! IMPORTANT: If this method is currently - * homogeneous (i.e. IsHomogeneous returns true), then you cannot - * call this method. Instead, you need to use the Scalar() - * method. - */ - inline const Number* Values() const; - - /** The same as the const version of Values, but we ensure that we - * always return a valid array, even if IsHomogeneous returns - * true. */ - const Number* ExpandedValues() const; - - /** This is the same as Values, but we add it here so that - * ExpandedValues can also be used for the non-const case. */ - inline Number* ExpandedValues() - { - return Values(); - } - - /** Indicates if the vector is homogeneous (i.e., all entries have - * the value Scalar() */ - bool IsHomogeneous() const - { - return homogeneous_; - } - - /** Scalar value of all entries in a homogeneous vector */ - Number Scalar() const - { - DBG_ASSERT(homogeneous_); - return scalar_; - } - //@} - - /** @name Modifying subranges of the vector. */ - //@{ - /** Copy the data in x into the subrange of this vector starting - * at position Pos in this vector. Position count starts at 0. - */ - void CopyToPos(Index Pos, const Vector& x); - /** Copy a subrange of x, starting at Pos, into the full data of - * this vector. Position count starts at 0. - */ - void CopyFromPos(Index Pos, const Vector& x); - //@} - - protected: - /** @name Overloaded methods from Vector base class */ - //@{ - /** Copy the data of the vector x into this vector (DCOPY). */ - virtual void CopyImpl(const Vector& x); - - /** Scales the vector by scalar alpha (DSCAL) */ - virtual void ScalImpl(Number alpha); - - /** Add the multiple alpha of vector x to this vector (DAXPY) */ - virtual void AxpyImpl(Number alpha, const Vector &x); - - /** Computes inner product of vector x with this (DDOT) */ - virtual Number DotImpl(const Vector &x) const; - - /** Computes the 2-norm of this vector (DNRM2) */ - virtual Number Nrm2Impl() const; - - /** Computes the 1-norm of this vector (DASUM) */ - virtual Number AsumImpl() const; - - /** Computes the max-norm of this vector (based on IDAMAX) */ - virtual Number AmaxImpl() const; - - /** Set each element in the vector to the scalar alpha. */ - virtual void SetImpl(Number value); - - /** Element-wise division \f$y_i \gets y_i/x_i\f$.*/ - virtual void ElementWiseDivideImpl(const Vector& x); - - /** Element-wise multiplication \f$y_i \gets y_i*x_i\f$.*/ - virtual void ElementWiseMultiplyImpl(const Vector& x); - - /** Set entry to max of itself and the corresponding element in x */ - virtual void ElementWiseMaxImpl(const Vector& x); - - /** Set entry to min of itself and the corresponding element in x */ - virtual void ElementWiseMinImpl(const Vector& x); - - /** reciprocates the elements of the vector */ - virtual void ElementWiseReciprocalImpl(); - - /** take abs of the elements of the vector */ - virtual void ElementWiseAbsImpl(); - - /** take square-root of the elements of the vector */ - virtual void ElementWiseSqrtImpl(); - - /** Changes each entry in the vector to its sgn value */ - virtual void ElementWiseSgnImpl(); - - /** Add scalar to every component of the vector.*/ - virtual void AddScalarImpl(Number scalar); - - /** Max value in the vector */ - virtual Number MaxImpl() const; - - /** Min value in the vector */ - virtual Number MinImpl() const; - - /** Computes the sum of the lements of vector */ - virtual Number SumImpl() const; - - /** Computes the sum of the logs of the elements of vector */ - virtual Number SumLogsImpl() const; - - /** @name Implemented specialized functions */ - //@{ - /** Add two vectors (a * v1 + b * v2). Result is stored in this - vector. */ - void AddTwoVectorsImpl(Number a, const Vector& v1, - Number b, const Vector& v2, Number c); - /** Fraction to the boundary parameter. */ - Number FracToBoundImpl(const Vector& delta, Number tau) const; - /** Add the quotient of two vectors, y = a * z/s + c * y. */ - void AddVectorQuotientImpl(Number a, const Vector& z, const Vector& s, - Number c); - //@} - - /** @name Output methods */ - //@{ - /* Print the entire vector with padding */ - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const - { - PrintImplOffset(jnlst, level, category, name, indent, prefix, 1); - } - /* Print the entire vector with padding, and start counting with - an offset. */ - void PrintImplOffset(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix, - Index offset) const; - //@} - friend class ParVector; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - DenseVector(); - - /** Copy Constructor */ - DenseVector(const DenseVector&); - - /** Overloaded Equals Operator */ - void operator=(const DenseVector&); - //@} - - /** Copy of the owner_space ptr as a DenseVectorSpace instead - * of a VectorSpace - */ - const DenseVectorSpace* owner_space_; - - /** Dense Number array of vector values. */ - Number* values_; - - /** Dense Number array pointer that is used for ExpandedValues */ - mutable Number* expanded_values_; - - /** Method of getting the internal values array, making sure that - * memory has been allocated */ - inline - Number* values_allocated(); - - /** Flag for Initialization. This flag is false, if the data has - not yet been initialized. */ - bool initialized_; - - /** Flag indicating whether the vector is currently homogeneous - * (that is, all elements have the same value). This flag is used - * to determine whether the elements of the vector are stored in - * values_ or in scalar_ */ - bool homogeneous_; - - /** Homogeneous value of all elements if the vector is currently - * homogenous */ - Number scalar_; - - /** Auxilliary method for setting explicitly all elements in - * values_ to the current scalar value. */ - void set_values_from_scalar(); - }; - - /** typedefs for the map variables that define meta data for the - * DenseVectorSpace - */ - typedef std::map > StringMetaDataMapType; - typedef std::map > IntegerMetaDataMapType; - typedef std::map > NumericMetaDataMapType; - - /** This vectors space is the vector space for DenseVector. - */ - class DenseVectorSpace : public VectorSpace - { - public: - /** @name Constructors/Destructors. */ - //@{ - /** Constructor, requires dimension of all vector for this - * VectorSpace - */ - DenseVectorSpace(Index dim) - : - VectorSpace(dim) - {} - - /** Destructor */ - ~DenseVectorSpace() - {} - //@} - - /** Method for creating a new vector of this specific type. */ - inline - DenseVector* MakeNewDenseVector() const - { - return new DenseVector(this); - } - - /** Instantiation of the generate MakeNew method for the - * VectorSpace base class. - */ - virtual Vector* MakeNew() const - { - return MakeNewDenseVector(); - } - - /**@name Methods called by DenseVector for memory management. - * This could allow to have sophisticated memory management in the - * VectorSpace. - */ - //@{ - /** Allocate internal storage for the DenseVector */ - inline - Number* AllocateInternalStorage() const; - - /** Deallocate internal storage for the DenseVector */ - inline - void FreeInternalStorage(Number* values) const; - //@} - - /**@name Methods for dealing with meta data on the vector - */ - //@{ - /** Check if string meta exists for tag */ - inline - bool HasStringMetaData(const std::string tag) const; - - /** Check if Integer meta exists for tag */ - inline - bool HasIntegerMetaData(const std::string tag) const; - - /** Check if Numeric meta exists for tag */ - inline - bool HasNumericMetaData(const std::string tag) const; - - /** Get meta data of type std::string by tag */ - inline - const std::vector& GetStringMetaData(const std::string& tag) const; - - /** Get meta data of type Index by tag */ - inline - const std::vector& GetIntegerMetaData(const std::string& tag) const; - - /** Get meta data of type Number by tag */ - inline - const std::vector& GetNumericMetaData(const std::string& tag) const; - - /** Set meta data of type std::string by tag */ - inline - void SetStringMetaData(std::string tag, std::vector meta_data); - - /** Set meta data of type Index by tag */ - inline - void SetIntegerMetaData(std::string tag, std::vector meta_data); - - /** Set meta data of type Number by tag */ - inline - void SetNumericMetaData(std::string tag, std::vector meta_data); - - /** Get map of meta data of type Number */ - inline - const StringMetaDataMapType& GetStringMetaData() const; - - /** Get map of meta data of type Number */ - inline - const IntegerMetaDataMapType& GetIntegerMetaData() const; - - /** Get map of meta data of type Number */ - inline - const NumericMetaDataMapType& GetNumericMetaData() const; - //@} - - private: - // variables to store vector meta data - StringMetaDataMapType string_meta_data_; - IntegerMetaDataMapType integer_meta_data_; - NumericMetaDataMapType numeric_meta_data_; - - }; - - // inline functions - inline Number* DenseVector::Values() - { - // Here we assume that every time someone requests this direct raw - // pointer, the data is going to change and the Tag for this - // vector has to be updated. - - if (initialized_ && homogeneous_) { - // If currently the vector is a homogeneous vector, set all elements - // explicitly to this value - set_values_from_scalar(); - } - ObjectChanged(); - initialized_= true; - homogeneous_ = false; - return values_allocated(); - } - - inline const Number* DenseVector::Values() const - { - DBG_ASSERT(initialized_ && (Dim()==0 || values_)); - return values_; - } - - inline Number* DenseVector::values_allocated() - { - if (values_==NULL) { - values_ = owner_space_->AllocateInternalStorage(); - } - return values_; - } - - inline - Number* DenseVectorSpace::AllocateInternalStorage() const - { - if (Dim()>0) { - return new Number[Dim()]; - } - else { - return NULL; - } - } - - inline - void DenseVectorSpace::FreeInternalStorage(Number* values) const - { - delete [] values; - } - - inline - SmartPtr DenseVector::MakeNewDenseVector() const - { - return owner_space_->MakeNewDenseVector(); - } - - inline - bool DenseVectorSpace::HasStringMetaData(const std::string tag) const - { - StringMetaDataMapType::const_iterator iter; - iter = string_meta_data_.find(tag); - - if (iter != string_meta_data_.end()) { - return true; - } - - return false; - } - - inline - bool DenseVectorSpace::HasIntegerMetaData(const std::string tag) const - { - IntegerMetaDataMapType::const_iterator iter; - iter = integer_meta_data_.find(tag); - - if (iter != integer_meta_data_.end()) { - return true; - } - - return false; - } - - inline - bool DenseVectorSpace::HasNumericMetaData(const std::string tag) const - { - NumericMetaDataMapType::const_iterator iter; - iter = numeric_meta_data_.find(tag); - - if (iter != numeric_meta_data_.end()) { - return true; - } - - return false; - } - - inline - const std::vector& DenseVectorSpace::GetStringMetaData(const std::string& tag) const - { - DBG_ASSERT(HasStringMetaData(tag)); - StringMetaDataMapType::const_iterator iter; - iter = string_meta_data_.find(tag); - return iter->second; - } - - inline - const std::vector& DenseVectorSpace::GetIntegerMetaData(const std::string& tag) const - { - DBG_ASSERT(HasIntegerMetaData(tag)); - IntegerMetaDataMapType::const_iterator iter; - iter = integer_meta_data_.find(tag); - return iter->second; - } - - inline - const std::vector& DenseVectorSpace::GetNumericMetaData(const std::string& tag) const - { - DBG_ASSERT(HasNumericMetaData(tag)); - NumericMetaDataMapType::const_iterator iter; - iter = numeric_meta_data_.find(tag); - return iter->second; - } - - inline - void DenseVectorSpace::SetStringMetaData(std::string tag, std::vector meta_data) - { - string_meta_data_[tag] = meta_data; - } - - inline - void DenseVectorSpace::SetIntegerMetaData(std::string tag, std::vector meta_data) - { - integer_meta_data_[tag] = meta_data; - } - - inline - void DenseVectorSpace::SetNumericMetaData(std::string tag, std::vector meta_data) - { - numeric_meta_data_[tag] = meta_data; - } - - inline - const StringMetaDataMapType& DenseVectorSpace::GetStringMetaData() const - { - return string_meta_data_; - } - - inline - const IntegerMetaDataMapType& DenseVectorSpace::GetIntegerMetaData() const - { - return integer_meta_data_; - } - - inline - const NumericMetaDataMapType& DenseVectorSpace::GetNumericMetaData() const - { - return numeric_meta_data_; - } - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpDiagMatrix.hpp b/external/ipopt/include/coin/IpDiagMatrix.hpp deleted file mode 100644 index d912e7728..000000000 --- a/external/ipopt/include/coin/IpDiagMatrix.hpp +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpDiagMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPDIAGMATRIX_HPP__ -#define __IPDIAGMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /** Class for diagonal matrices. The diagonal is stored as a - * Vector. */ - class DiagMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, given the corresponding matrix space. */ - DiagMatrix(const SymMatrixSpace* owner_space); - - /** Destructor */ - ~DiagMatrix(); - //@} - - /** Method for setting the diagonal elements (as a Vector). */ - void SetDiag(const Vector& diag) - { - diag_ = &diag; - } - - /** Method for setting the diagonal elements. */ - SmartPtr GetDiag() const - { - return diag_; - } - - protected: - /**@name Methods overloaded from matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - DiagMatrix(); - - /** Copy Constructor */ - DiagMatrix(const DiagMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const DiagMatrix&); - //@} - - /** Vector storing the diagonal elements */ - SmartPtr diag_; - }; - - /** This is the matrix space for DiagMatrix. */ - class DiagMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the dimension of the matrix. */ - DiagMatrixSpace(Index dim) - : - SymMatrixSpace(dim) - {} - - /** Destructor */ - virtual ~DiagMatrixSpace() - {} - //@} - - /** Overloaded MakeNew method for the SymMatrixSpace base class. - */ - virtual SymMatrix* MakeNewSymMatrix() const - { - return MakeNewDiagMatrix(); - } - - /** Method for creating a new matrix of this specific type. */ - DiagMatrix* MakeNewDiagMatrix() const - { - return new DiagMatrix(this); - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - DiagMatrixSpace(); - - /** Copy Constructor */ - DiagMatrixSpace(const DiagMatrixSpace&); - - /** Overloaded Equals Operator */ - void operator=(const DiagMatrixSpace&); - //@} - - }; - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpEqMultCalculator.hpp b/external/ipopt/include/coin/IpEqMultCalculator.hpp deleted file mode 100644 index 7c3cb200b..000000000 --- a/external/ipopt/include/coin/IpEqMultCalculator.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpEqMultCalculator.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-09-23 - -#ifndef __IPEQMULTCALCULATOR_HPP__ -#define __IPEQMULTCALCULATOR_HPP__ - -#include "IpUtils.hpp" -#include "IpAlgStrategy.hpp" - -namespace Ipopt -{ - /** Base Class for objects that compute estimates for the equality - * constraint multipliers y_c and y_d. For example, this is the - * base class for objects for computing least square multipliers or - * coordinate multipliers. */ - class EqMultiplierCalculator: public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor. */ - EqMultiplierCalculator() - {} - /** Default destructor */ - virtual ~EqMultiplierCalculator() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** This method computes the estimates for y_c and y_d at the - * current point. If the estimates cannot be computed (e.g. some - * linear system is singular), the return value of this method is - * false. */ - virtual bool CalculateMultipliers(Vector& y_c, - Vector& y_d) = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - EqMultiplierCalculator(const EqMultiplierCalculator&); - - /** Overloaded Equals Operator */ - void operator=(const EqMultiplierCalculator&); - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpException.hpp b/external/ipopt/include/coin/IpException.hpp deleted file mode 100644 index e64226f34..000000000 --- a/external/ipopt/include/coin/IpException.hpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpException.hpp 2023 2011-06-18 18:49:49Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPEXCEPTION_HPP__ -#define __IPEXCEPTION_HPP__ - -#include "IpUtils.hpp" -#include "IpJournalist.hpp" - -/* This file contains a base class for all exceptions - * and a set of macros to help with exceptions - */ - -namespace Ipopt -{ - - /** This is the base class for all exceptions. The easiest way to - * use this class is by means of the following macros: - * - * \verbatim - - DECLARE_STD_EXCEPTION(ExceptionType); - \endverbatim - * - * This macro defines a new class with the name ExceptionType, - * inherited from the base class IpoptException. After this, - * exceptions of this type can be thrown using - * - * \verbatim - - THROW_EXCEPTION(ExceptionType, Message); - \endverbatim - * - * where Message is a std::string with a message that gives an - * indication of what caused the exception. Exceptions can also be - * thrown using the macro - * - * \verbatim - - ASSERT_EXCEPTION(Condition, ExceptionType, Message); - \endverbatim - * - * where Conditions is an expression. If Condition evaluates to - * false, then the exception of the type ExceptionType is thrown - * with Message. - * - * When an exception is caught, the method ReportException can be - * used to write the information about the exception to the - * Journalist, using the level J_ERROR and the category J_MAIN. - * - */ - class IpoptException - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor */ - IpoptException(std::string msg, std::string file_name, Index line_number, std::string type="IpoptException") - : - msg_(msg), - file_name_(file_name), - line_number_(line_number), - type_(type) - {} - - /** Copy Constructor */ - IpoptException(const IpoptException& copy) - : - msg_(copy.msg_), - file_name_(copy.file_name_), - line_number_(copy.line_number_), - type_(copy.type_) - {} - - /** Default destructor */ - virtual ~IpoptException() - {} - //@} - - /** Method to report the exception to a journalist */ - void ReportException(const Journalist& jnlst, - EJournalLevel level = J_ERROR) const - { - jnlst.Printf(level, J_MAIN, - "Exception of type: %s in file \"%s\" at line %d:\n Exception message: %s\n", - type_.c_str(), file_name_.c_str(), line_number_, msg_.c_str()); - } - - const std::string& Message() const - { - return msg_; - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - IpoptException(); - - /** Overloaded Equals Operator */ - void operator=(const IpoptException&); - //@} - - std::string msg_; - std::string file_name_; - Index line_number_; - std::string type_; - }; - -} // namespace Ipopt - -#define THROW_EXCEPTION(__except_type, __msg) \ - throw __except_type( (__msg), (__FILE__), (__LINE__) ); - -#define ASSERT_EXCEPTION(__condition, __except_type, __msg) \ - if (! (__condition) ) { \ - std::string newmsg = #__condition; \ - newmsg += " evaluated false: "; \ - newmsg += __msg; \ - throw __except_type( (newmsg), (__FILE__), (__LINE__) ); \ - } - -#define DECLARE_STD_EXCEPTION(__except_type) \ - class __except_type : public Ipopt::IpoptException \ - { \ - public: \ - __except_type(std::string msg, std::string fname, Ipopt::Index line) \ - : Ipopt::IpoptException(msg,fname,line, #__except_type) {} \ - __except_type(const __except_type& copy) \ - : Ipopt::IpoptException(copy) {} \ - private: \ - __except_type(); \ - void operator=(const __except_type&); \ - } - -#endif diff --git a/external/ipopt/include/coin/IpExpansionMatrix.hpp b/external/ipopt/include/coin/IpExpansionMatrix.hpp deleted file mode 100644 index cbb9a99c0..000000000 --- a/external/ipopt/include/coin/IpExpansionMatrix.hpp +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpExpansionMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPEXPANSIONMATRIX_HPP__ -#define __IPEXPANSIONMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpMatrix.hpp" - -namespace Ipopt -{ - - /** forward declarations */ - class ExpansionMatrixSpace; - - /** Class for expansion/projection matrices. These matrices allow - * to lift a vector to a vector with larger dimension, keeping - * some elements of the larger vector zero. This operation is achieved - * by the MultVector operation. The transpose operation then - * filters some elements from a large vector into a smaller vector. - */ - class ExpansionMatrix : public Matrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the owner_space. - */ - ExpansionMatrix(const ExpansionMatrixSpace* owner_space); - - /** Destructor */ - ~ExpansionMatrix(); - //@} - - /** Return the vector of indices marking the expanded position. - * The result is the Index array (of length NSmallVec=NCols()) - * that stores the mapping from the small vector to the large - * vector. For each element i=0,..,NSmallVec in the small - * vector, ExpandedPosIndices()[i] give the corresponding index - * in the large vector. - */ - const Index* ExpandedPosIndices() const; - - /** Return the vector of indices marking the compressed position. - * The result is the Index array (of length NLargeVec=NRows()) - * that stores the mapping from the large vector to the small - * vector. For each element i=0,..,NLargeVec in the large - * vector, CompressedPosIndices()[i] gives the corresponding - * index in the small vector, unless CompressedPosIndices()[i] is - * negative. - */ - const Index* CompressedPosIndices() const; - - protected: - /**@name Overloaded methods from Matrix base class*/ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, - Vector &y) const; - - virtual void TransMultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** X = beta*X + alpha*(Matrix S^{-1} Z). Specialized implementation. - */ - virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z, - Vector& X) const; - - /** X = S^{-1} (r + alpha*Z*M^Td). Specialized implementation. - */ - virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S, - const Vector& R, const Vector& Z, - const Vector& D, Vector& X) const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const - { - PrintImplOffset(jnlst, level, category, name, indent, prefix, 1, 1); - } - //@} - - void PrintImplOffset(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix, - Index row_offset, - Index col_offset) const; - - friend class ParExpansionMatrix; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - ExpansionMatrix(); - - /** Copy Constructor */ - ExpansionMatrix(const ExpansionMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const ExpansionMatrix&); - //@} - - const ExpansionMatrixSpace* owner_space_; - - }; - - /** This is the matrix space for ExpansionMatrix. - */ - class ExpansionMatrixSpace : public MatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the list of elements of the large vector - * (of size NLargeVec) to be filtered into the small vector (of - * size NSmallVec). For each i=0..NSmallVec-1 the i-th element - * of the small vector will be put into the ExpPos[i] position of - * the large vector. The position counting in the vector is - * assumed to start at 0 (C-like array notation). - */ - ExpansionMatrixSpace(Index NLargeVec, - Index NSmallVec, - const Index *ExpPos, - const int offset = 0); - - /** Destructor */ - ~ExpansionMatrixSpace() - { - delete [] compressed_pos_; - delete [] expanded_pos_; - } - //@} - - /** Method for creating a new matrix of this specific type. */ - ExpansionMatrix* MakeNewExpansionMatrix() const - { - return new ExpansionMatrix(this); - } - - /** Overloaded MakeNew method for the MatrixSpace base class. - */ - virtual Matrix* MakeNew() const - { - return MakeNewExpansionMatrix(); - } - - /** Accessor Method to obtain the Index array (of length - * NSmallVec=NCols()) that stores the mapping from the small - * vector to the large vector. For each element i=0,..,NSmallVec - * in the small vector, ExpandedPosIndices()[i] give the - * corresponding index in the large vector. - */ - const Index* ExpandedPosIndices() const - { - return expanded_pos_; - } - - /** Accessor Method to obtain the Index array (of length - * NLargeVec=NRows()) that stores the mapping from the large - * vector to the small vector. For each element i=0,..,NLargeVec - * in the large vector, CompressedPosIndices()[i] gives the - * corresponding index in the small vector, unless - * CompressedPosIndices()[i] is negative. - */ - const Index* CompressedPosIndices() const - { - return compressed_pos_; - } - - private: - Index *expanded_pos_; - Index *compressed_pos_; - }; - - /* inline methods */ - inline - const Index* ExpansionMatrix::ExpandedPosIndices() const - { - return owner_space_->ExpandedPosIndices(); - } - - inline - const Index* ExpansionMatrix::CompressedPosIndices() const - { - return owner_space_->CompressedPosIndices(); - } - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpGenTMatrix.hpp b/external/ipopt/include/coin/IpGenTMatrix.hpp deleted file mode 100644 index 059bfea5c..000000000 --- a/external/ipopt/include/coin/IpGenTMatrix.hpp +++ /dev/null @@ -1,264 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpGenTMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPGENTMATRIX_HPP__ -#define __IPGENTMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class GenTMatrixSpace; - - /** Class for general matrices stored in triplet format. In the - * triplet format, the nonzeros elements of a general matrix is - * stored in three arrays, Irow, Jcol, and Values, all of length - * Nonzeros. The first two arrays indicate the location of a - * non-zero element (row and column indices), and the last array - * stores the value at that location. If nonzero elements are - * listed more than once, their values are added. - * - * The structure of the nonzeros (i.e. the arrays Irow and Jcol) - * cannot be changed after the matrix can been initialized. Only - * the values of the nonzero elements can be modified. - * - * Note that the first row and column of a matrix has index 1, not - * 0. - */ - class GenTMatrix : public Matrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the owner_space. - */ - GenTMatrix(const GenTMatrixSpace* owner_space); - - /** Destructor */ - ~GenTMatrix(); - //@} - - /**@name Changing the Values.*/ - //@{ - /** Set values of nonzero elements. The values of the nonzero - * elements are copied from the incoming Number array. Important: - * It is assume that the order of the values in Values - * corresponds to the one of Irn and Jcn given to one of the - * constructors above. */ - void SetValues(const Number* Values); - //@} - - /** @name Accessor Methods */ - //@{ - /** Number of nonzero entries */ - Index Nonzeros() const; - - /** Array with Row indices (counting starts at 1) */ - const Index* Irows() const; - - /** Array with Column indices (counting starts at 1) */ - const Index* Jcols() const; - - /** Array with nonzero values (const version). */ - const Number* Values() const - { - return values_; - } - - /** Array with the nonzero values of this matrix (non-const - * version). Use this method only if you are intending to change - * the values, because the GenTMatrix will be marked as changed. - */ - Number* Values() - { - ObjectChanged(); - initialized_ = true; - return values_; - } - //@} - - protected: - /**@name Overloaded methods from Matrix base class*/ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta, - Vector &y) const; - - virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, - Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const - { - PrintImplOffset(jnlst, level, category, name, indent, prefix, 0); - } - //@} - - void PrintImplOffset(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix, - Index offset) const; - - friend class ParGenMatrix; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - GenTMatrix(); - - /** Copy Constructor */ - GenTMatrix(const GenTMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const GenTMatrix&); - //@} - - /** Copy of the owner space as a GenTMatrixSpace instead of - * a MatrixSpace - */ - const GenTMatrixSpace* owner_space_; - - /** Values of nonzeros */ - Number* values_; - - /** Flag for Initialization */ - bool initialized_; - - }; - - /** This is the matrix space for a GenTMatrix with fixed sparsity - * structure. The sparsity structure is stored here in the matrix - * space. - */ - class GenTMatrixSpace : public MatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of rows and columns, as well as - * the number of nonzeros and the position of the nonzero - * elements. Note that the counting of the nonzeros starts a 1, - * i.e., iRows[i]==1 and jCols[i]==1 refers to the first element - * in the first row. This is in accordance with the HSL data - * structure. - */ - GenTMatrixSpace(Index nRows, Index nCols, - Index nonZeros, - const Index* iRows, const Index* jCols); - - /** Destructor */ - ~GenTMatrixSpace() - { - delete [] iRows_; - delete [] jCols_; - } - //@} - - /** Method for creating a new matrix of this specific type. */ - GenTMatrix* MakeNewGenTMatrix() const - { - return new GenTMatrix(this); - } - - /** Overloaded MakeNew method for the MatrixSpace base class. - */ - virtual Matrix* MakeNew() const - { - return MakeNewGenTMatrix(); - } - - /**@name Methods describing Matrix structure */ - //@{ - /** Number of non-zeros in the sparse matrix */ - Index Nonzeros() const - { - return nonZeros_; - } - - /** Row index of each non-zero element (counting starts at 1) */ - const Index* Irows() const - { - return iRows_; - } - - /** Column index of each non-zero element (counting starts at 1) */ - const Index* Jcols() const - { - return jCols_; - } - //@} - - private: - /** @name Sparsity structure of matrices generated by this matrix - * space. - */ - //@{ - const Index nonZeros_; - Index* jCols_; - Index* iRows_; - //@} - - /** This method is only for the GenTMatrix to call in order - * to allocate internal storage */ - Number* AllocateInternalStorage() const; - - /** This method is only for the GenTMatrix to call in order - * to de-allocate internal storage */ - void FreeInternalStorage(Number* values) const; - - friend class GenTMatrix; - }; - - /* inline methods */ - inline - Index GenTMatrix::Nonzeros() const - { - return owner_space_->Nonzeros(); - } - - inline - const Index* GenTMatrix::Irows() const - { - return owner_space_->Irows(); - } - - inline - const Index* GenTMatrix::Jcols() const - { - return owner_space_->Jcols(); - } - - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpHessianUpdater.hpp b/external/ipopt/include/coin/IpHessianUpdater.hpp deleted file mode 100644 index a3912d61d..000000000 --- a/external/ipopt/include/coin/IpHessianUpdater.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2005, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpHessianUpdater.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Andreas Waechter IBM 2005-12-26 - -#ifndef __IPHESSIANUPDATER_HPP__ -#define __IPHESSIANUPDATER_HPP__ - -#include "IpAlgStrategy.hpp" - -namespace Ipopt -{ - - /** Abstract base class for objects responsible for updating the - * Hessian information. This can be done using exact second - * derivatives from the NLP, or by a quasi-Newton Option. The - * result is put into the W field in IpData. - */ - class HessianUpdater : public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - HessianUpdater() - {} - - /** Default destructor */ - virtual ~HessianUpdater() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Update the Hessian based on the current information in IpData, - * and possibly on information from previous calls. - */ - virtual void UpdateHessian() = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - HessianUpdater(const HessianUpdater&); - - /** Overloaded Equals Operator */ - void operator=(const HessianUpdater&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIdentityMatrix.hpp b/external/ipopt/include/coin/IpIdentityMatrix.hpp deleted file mode 100644 index 803230640..000000000 --- a/external/ipopt/include/coin/IpIdentityMatrix.hpp +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIdentityMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPIDENTITYMATRIX_HPP__ -#define __IPIDENTITYMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /** Class for Matrices which are multiples of the identity matrix. - * - */ - class IdentityMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, initializing with dimensions of the matrix - * (true identity matrix). - */ - IdentityMatrix(const SymMatrixSpace* owner_space); - - /** Destructor */ - ~IdentityMatrix(); - //@} - - /** Method for setting the factor for the identity matrix. */ - void SetFactor(Number factor) - { - factor_ = factor; - } - - /** Method for getting the factor for the identity matrix. */ - Number GetFactor() const - { - return factor_; - } - - /** Method for obtaining the dimention of the matrix. */ - Index Dim() const; - - protected: - /**@name Methods overloaded from matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - virtual void AddMSinvZImpl(Number alpha, const Vector& S, - const Vector& Z, Vector& X) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - IdentityMatrix(); - - /** Copy Constructor */ - IdentityMatrix(const IdentityMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const IdentityMatrix&); - //@} - - /** Scaling factor for this identity matrix */ - Number factor_; - }; - - /** This is the matrix space for IdentityMatrix. */ - class IdentityMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the dimension of the matrix. */ - IdentityMatrixSpace(Index dim) - : - SymMatrixSpace(dim) - {} - - /** Destructor */ - virtual ~IdentityMatrixSpace() - {} - //@} - - /** Overloaded MakeNew method for the SymMatrixSpace base class. - */ - virtual SymMatrix* MakeNewSymMatrix() const - { - return MakeNewIdentityMatrix(); - } - - /** Method for creating a new matrix of this specific type. */ - IdentityMatrix* MakeNewIdentityMatrix() const - { - return new IdentityMatrix(this); - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - IdentityMatrixSpace(); - - /** Copy Constructor */ - IdentityMatrixSpace(const IdentityMatrixSpace&); - - /** Overloaded Equals Operator */ - void operator=(const IdentityMatrixSpace&); - //@} - }; - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpIpoptAlg.hpp b/external/ipopt/include/coin/IpIpoptAlg.hpp deleted file mode 100644 index 60e314752..000000000 --- a/external/ipopt/include/coin/IpIpoptAlg.hpp +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright (C) 2004, 2010 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIpoptAlg.hpp 2167 2013-03-08 11:15:38Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPIPOPTALG_HPP__ -#define __IPIPOPTALG_HPP__ - -#include "IpIpoptNLP.hpp" -#include "IpAlgStrategy.hpp" -#include "IpSearchDirCalculator.hpp" -#include "IpLineSearch.hpp" -#include "IpMuUpdate.hpp" -#include "IpConvCheck.hpp" -#include "IpOptionsList.hpp" -#include "IpIterateInitializer.hpp" -#include "IpIterationOutput.hpp" -#include "IpAlgTypes.hpp" -#include "IpHessianUpdater.hpp" -#include "IpEqMultCalculator.hpp" - -namespace Ipopt -{ - - /** @name Exceptions */ - //@{ - DECLARE_STD_EXCEPTION(STEP_COMPUTATION_FAILED); - //@} - - /** The main ipopt algorithm class. - * Main Ipopt algorithm class, contains the main optimize method, - * handles the execution of the optimization. - * The constructor initializes the data structures through the nlp, - * and the Optimize method then assumes that everything is - * initialized and ready to go. - * After an optimization is complete, the user can access the - * solution through the passed in ip_data structure. - * Multiple calls to the Optimize method are allowed as long as the - * structure of the problem remains the same (i.e. starting point - * or nlp parameter changes only). - */ - class IpoptAlgorithm : public AlgorithmStrategyObject - { - public: - - /**@name Constructors/Destructors */ - //@{ - /** Constructor. (The IpoptAlgorithm uses smart pointers for these - * passed-in pieces to make sure that a user of IpoptAlgoroithm - * cannot pass in an object created on the stack!) - */ - IpoptAlgorithm(const SmartPtr& search_dir_calculator, - const SmartPtr& line_search, - const SmartPtr& mu_update, - const SmartPtr& conv_check, - const SmartPtr& iterate_initializer, - const SmartPtr& iter_output, - const SmartPtr& hessian_updater, - const SmartPtr& eq_multiplier_calculator = NULL); - - /** Default destructor */ - virtual ~IpoptAlgorithm(); - //@} - - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix); - - /** Main solve method. */ - SolverReturn Optimize(bool isResto = false); - - /** Methods for IpoptType */ - //@{ - static void RegisterOptions(SmartPtr roptions); - //@} - - /**@name Access to internal strategy objects */ - //@{ - SmartPtr SearchDirCalc() - { - return search_dir_calculator_; - } - //@} - - static void print_copyright_message(const Journalist& jnlst); - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - IpoptAlgorithm(); - - /** Copy Constructor */ - IpoptAlgorithm(const IpoptAlgorithm&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptAlgorithm&); - //@} - - /** @name Strategy objects */ - //@{ - SmartPtr search_dir_calculator_; - SmartPtr line_search_; - SmartPtr mu_update_; - SmartPtr conv_check_; - SmartPtr iterate_initializer_; - SmartPtr iter_output_; - SmartPtr hessian_updater_; - /** The multipler calculator (for y_c and y_d) has to be set only - * if option recalc_y is set to true */ - SmartPtr eq_multiplier_calculator_; - //@} - - /** @name Main steps of the algorthim */ - //@{ - /** Method for updating the current Hessian. This can either just - * evaluate the exact Hessian (based on the current iterate), or - * perform a quasi-Newton update. - */ - void UpdateHessian(); - - /** Method to update the barrier parameter. Returns false, if the - * algorithm can't continue with the regular procedure and needs - * to revert to a fallback mechanism in the line search (such as - * restoration phase) */ - bool UpdateBarrierParameter(); - - /** Method to setup the call to the PDSystemSolver. Returns - * false, if the algorithm can't continue with the regular - * procedure and needs to revert to a fallback mechanism in the - * line search (such as restoration phase) */ - bool ComputeSearchDirection(); - - /** Method computing the new iterate (usually vialine search). - * The acceptable point is the one in trial after return. - */ - void ComputeAcceptableTrialPoint(); - - /** Method for accepting the trial point as the new iteration, - * possibly after adjusting the variable bounds in the NLP. */ - void AcceptTrialPoint(); - - /** Do all the output for one iteration */ - void OutputIteration(); - - /** Sets up initial values for the iterates, - * Corrects the initial values for x and s (force in bounds) - */ - void InitializeIterates(); - - /** Print the problem size statistics */ - void PrintProblemStatistics(); - - /** Compute the Lagrangian multipliers for a feasibility problem*/ - void ComputeFeasibilityMultipliers(); - //@} - - /** @name internal flags */ - //@{ - /** Flag indicating if the statistic should not be printed */ - bool skip_print_problem_stats_; - //@} - - /** @name Algorithmic parameters */ - //@{ - /** safeguard factor for bound multipliers. If value >= 1, then - * the dual variables will never deviate from the primal estimate - * by more than the factors kappa_sigma and 1./kappa_sigma. - */ - Number kappa_sigma_; - /** Flag indicating whether the y multipliers should be - * recalculated with the eq_mutliplier_calculator object for each - * new point. */ - bool recalc_y_; - /** Feasibility threshold for recalc_y */ - Number recalc_y_feas_tol_; - /** Flag indicating if we want to do Mehrotras's algorithm. This - * means that a number of options are ignored, or have to be set - * (or are automatically set) to certain values. */ - bool mehrotra_algorithm_; - /** String specifying linear solver */ - std::string linear_solver_; - //@} - - /** @name auxiliary functions */ - //@{ - void calc_number_of_bounds( - const Vector& x, - const Vector& x_L, - const Vector& x_U, - const Matrix& Px_L, - const Matrix& Px_U, - Index& n_tot, - Index& n_only_lower, - Index& n_both, - Index& n_only_upper); - - /** Method for ensuring that the trial multipliers are not too far - * from the primal estime. If a correction is made, new_trial_z - * is a pointer to the corrected multiplier, and the return value - * of this method give the magnitutde of the largest correction - * that we done. If no correction was made, new_trial_z is just - * a pointer to trial_z, and the return value is zero. - */ - Number correct_bound_multiplier(const Vector& trial_z, - const Vector& trial_slack, - const Vector& trial_compl, - SmartPtr& new_trial_z); - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIpoptApplication.hpp b/external/ipopt/include/coin/IpIpoptApplication.hpp deleted file mode 100644 index ea18c899e..000000000 --- a/external/ipopt/include/coin/IpIpoptApplication.hpp +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright (C) 2004, 2010 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIpoptApplication.hpp 2690 2017-06-12 10:28:36Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPIPOPTAPPLICATION_HPP__ -#define __IPIPOPTAPPLICATION_HPP__ - -#ifndef IPOPT_EXPORT -#ifdef _MSC_VER -#ifdef IPOPT_DLL -#define IPOPT_EXPORT(type) __declspec(dllexport) type __cdecl -#else -#define IPOPT_EXPORT(type) type __cdecl -#endif -#else -#define IPOPT_EXPORT(type) type -#endif -#endif - -#include - -#include "IpJournalist.hpp" -#include "IpTNLP.hpp" -#include "IpNLP.hpp" -/* Return codes for the Optimize call for an application */ -#include "IpReturnCodes.hpp" - -namespace Ipopt -{ - DECLARE_STD_EXCEPTION(IPOPT_APPLICATION_ERROR); - - /* forward declarations */ - class IpoptAlgorithm; - class IpoptNLP; - class IpoptData; - class IpoptCalculatedQuantities; - class AlgorithmBuilder; - class RegisteredOptions; - class OptionsList; - class SolveStatistics; - - /** This is the main application class for making calls to Ipopt. */ - class IpoptApplication : public ReferencedObject - { - public: - IpoptApplication(bool create_console_out = true, - bool create_empty = false); - - /** Another constructor that assumes that the code in the - * (default) constructor has already been executed */ - IpoptApplication(SmartPtr reg_options, - SmartPtr options, - SmartPtr jnlst); - - virtual ~IpoptApplication(); - - /** Method for creating a new IpoptApplication that uses the same - * journalist and registered options, and a copy of the options - list. */ - virtual SmartPtr clone(); - - /** Initialization method. This method reads options from the - * input stream and initializes the journalists. It returns - * something other than Solve_Succeeded if there was a - * problem in the initialization (such as an invalid option). - * You should call one of the initialization methods at some - * point before the first optimize call. - * Set @par allow_clobber to true if you want to allow - * overwriting options that are set by the input stream. - */ - virtual ApplicationReturnStatus Initialize(std::istream& is, bool allow_clobber = false); - /** Initialization method. This method reads options from the - * params file and initializes the journalists. It returns - * something other than Solve_Succeeded if there was a - * problem in the initialization (such as an invalid option). - * You should call one of the initialization methods at some - * point before the first optimize call. - * Note: You can skip the processing of a params file by - * setting params_file to "". - * Set @par allow_clobber to true if you want to allow - * overwriting options that are set by the params file. - */ - virtual ApplicationReturnStatus Initialize(std::string params_file, bool allow_clobber = false); - /** Initialization method. This method reads options from the - * params file and initializes the journalists. It returns - * something other than Solve_Succeeded if there was a - * problem in the initialization (such as an invalid option). - * You should call one of the initialization methods at some - * point before the first optimize call. - * Note: You can skip the processing of a params file by - * setting params_file to "". - * Set @par allow_clobber to true if you want to allow - * overwriting options that are set by the params file. - */ - virtual ApplicationReturnStatus Initialize(const char* params_file, bool allow_clobber = false) - { - return Initialize(std::string(params_file), allow_clobber); - } - /** Initialize method. This method reads the options file specified - * by the option_file_name option and initializes the journalists. - * You should call this method at some point before the first optimize - * call. - * It returns something other than Solve_Succeeded if there was a - * problem in the initialization (such as an invalid option). - * Set @par allow_clobber to true if you want to allow - * overwriting options that are set by the options file. - */ - virtual ApplicationReturnStatus Initialize(bool allow_clobber = false); - - /**@name Solve methods */ - //@{ - /** Solve a problem that inherits from TNLP */ - virtual ApplicationReturnStatus OptimizeTNLP(const SmartPtr& tnlp); - - /** Solve a problem that inherits from NLP */ - virtual ApplicationReturnStatus OptimizeNLP(const SmartPtr& nlp); - - /** Solve a problem that inherits from NLP */ - virtual ApplicationReturnStatus OptimizeNLP(const SmartPtr& nlp, SmartPtr& alg_builder); - - /** Solve a problem (that inherits from TNLP) for a repeated time. - * The OptimizeTNLP method must have been called before. The - * TNLP must be the same object, and the structure (number of - * variables and constraints and position of nonzeros in Jacobian - * and Hessian must be the same). */ - virtual ApplicationReturnStatus ReOptimizeTNLP(const SmartPtr& tnlp); - - /** Solve a problem (that inherits from NLP) for a repeated time. - * The OptimizeNLP method must have been called before. The - * NLP must be the same object, and the structure (number of - * variables and constraints and position of nonzeros in Jacobian - * and Hessian must be the same). */ - virtual ApplicationReturnStatus ReOptimizeNLP(const SmartPtr& nlp); - //@} - - /** Method for opening an output file with given print_level. - * Returns false if there was a problem. */ - virtual bool OpenOutputFile(std::string file_name, EJournalLevel print_level); - - /**@name Accessor methods */ - //@{ - /** Get the Journalist for printing output */ - virtual SmartPtr Jnlst() - { - return jnlst_; - } - - /** Get a pointer to RegisteredOptions object to - * add new options */ - virtual SmartPtr RegOptions() - { - return reg_options_; - } - - /** Get the options list for setting options */ - virtual SmartPtr Options() - { - return options_; - } - - /** Get the options list for setting options (const version) */ - virtual SmartPtr Options() const - { - return ConstPtr(options_); - } - - /** Get the object with the statistics about the most recent - * optimization run. */ - virtual SmartPtr Statistics(); - - /** Get the IpoptNLP Object */ - virtual SmartPtr IpoptNLPObject(); - - /** Get the IpoptData Object */ - SmartPtr IpoptDataObject(); - - /** Get the IpoptCQ Object */ - virtual SmartPtr IpoptCQObject(); - - /** Get the Algorithm Object */ - SmartPtr AlgorithmObject(); - //@} - - /** Method for printing Ipopt copyright message now instead of - * just before the optimization. If you want to have the copy - * right message printed earlier than by default, call this - * method at the convenient time. */ - void PrintCopyrightMessage(); - - /** Method to set whether non-ipopt non-bad_alloc exceptions - * are rethrown by Ipopt. - * By default, non-Ipopt and non-std::bad_alloc exceptions are - * caught by Ipopts initialization and optimization methods - * and the status NonIpopt_Exception_Thrown is returned. - * This function allows to enable rethrowing of such exceptions. - * - * @return Returns whether non-ipopt exceptions were rethrown before. - */ - bool RethrowNonIpoptException(bool dorethrow) - { - bool oldval = rethrow_nonipoptexception_; - rethrow_nonipoptexception_ = dorethrow; - return oldval; - } - - /** @name Methods for IpoptTypeInfo */ - //@{ - static void RegisterOptions(SmartPtr roptions); - //@} - - /** Method to registering all Ipopt options. */ - static void - RegisterAllIpoptOptions(const SmartPtr& roptions); - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - // IpoptApplication(); - - /** Copy Constructor */ - IpoptApplication(const IpoptApplication&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptApplication&); - //@} - - /** Method for the actual optimize call of the Ipopt algorithm. - * This is used both for Optimize and ReOptimize */ - ApplicationReturnStatus call_optimize(); - - /**@name Variables that customize the application behavior */ - //@{ - /** Decide whether or not the ipopt.opt file should be read */ - bool read_params_dat_; - - /** Decide whether non-ipopt non-bad_alloc exceptions should be rethrown */ - bool rethrow_nonipoptexception_; - //@} - - /** Journalist for reporting output */ - SmartPtr jnlst_; - - /** RegisteredOptions */ - SmartPtr reg_options_; - - /** OptionsList used for the application */ - SmartPtr options_; - - /** Object for storing statistics about the most recent - * optimization run. */ - SmartPtr statistics_; - - /** Object with the algorithm sceleton. - */ - SmartPtr alg_; - - /** IpoptNLP Object for the NLP. We keep this around for a - * ReOptimize warm start. */ - SmartPtr ip_nlp_; - - /** IpoptData Object for the NLP. We keep this around for a - * ReOptimize warm start. - */ - SmartPtr ip_data_; - - /** IpoptCalculatedQuantities Object for the NLP. We keep this - * around for a ReOptimize warm start. - */ - SmartPtr ip_cq_; - - /** Pointer to the TNLPAdapter used to convert the TNLP to an NLP. - * We keep this around for the ReOptimizerTNLP call. */ - SmartPtr nlp_adapter_; - - /** @name Algorithmic parameters */ - //@{ - /** Flag indicating if we are to use the inexact linear solver option */ - bool inexact_algorithm_; - /** Flag indicating if all bounds should be replaced by inequality - * constraints. This is necessary for the inexact algorithm. */ - bool replace_bounds_; - //@} - }; - -} // namespace Ipopt - -extern "C" IPOPT_EXPORT(class Ipopt::IpoptApplication *) IpoptApplicationFactory(); - -#endif diff --git a/external/ipopt/include/coin/IpIpoptCalculatedQuantities.hpp b/external/ipopt/include/coin/IpIpoptCalculatedQuantities.hpp deleted file mode 100644 index 3b60b165c..000000000 --- a/external/ipopt/include/coin/IpIpoptCalculatedQuantities.hpp +++ /dev/null @@ -1,751 +0,0 @@ -// Copyright (C) 2004, 2011 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIpoptCalculatedQuantities.hpp 2020 2011-06-16 20:46:16Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPIPOPTCALCULATEDQUANTITIES_HPP__ -#define __IPIPOPTCALCULATEDQUANTITIES_HPP__ - -#include "IpSmartPtr.hpp" -#include "IpCachedResults.hpp" - -#include - -namespace Ipopt -{ - class IpoptNLP; - class IpoptData; - class Vector; - class Matrix; - class SymMatrix; - class Journalist; - class OptionsList; - class RegisteredOptions; - - /** Norm types */ - enum ENormType { - NORM_1=0, - NORM_2, - NORM_MAX - }; - - /** Base class for additional calculated quantities that is special - * to a particular type of algorithm, such as the CG penalty - * function, or using iterative linear solvers. The regular - * IpoptCalculatedQuantities object should be given a derivation of - * this base class when it is created. */ - class IpoptAdditionalCq : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - IpoptAdditionalCq() - {} - - /** Default destructor */ - virtual ~IpoptAdditionalCq() - {} - //@} - - /** This method is called to initialize the global algorithmic - * parameters. The parameters are taken from the OptionsList - * object. */ - virtual bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix) = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - IpoptAdditionalCq(const IpoptAdditionalCq&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptAdditionalCq&); - //@} - }; - - /** Class for all IPOPT specific calculated quantities. - * - */ - class IpoptCalculatedQuantities : public ReferencedObject - { - public: - - /**@name Constructors/Destructors */ - //@{ - /** Constructor */ - IpoptCalculatedQuantities(const SmartPtr& ip_nlp, - const SmartPtr& ip_data); - /** Default destructor */ - virtual ~IpoptCalculatedQuantities(); - //@} - - /** Method for setting pointer for additional calculated - * quantities. This needs to be called before Initialized. */ - void SetAddCq(SmartPtr add_cq) - { - DBG_ASSERT(!HaveAddCq()); - add_cq_ = add_cq; - } - - /** Method detecting if additional object for calculated - * quantities has already been set */ - bool HaveAddCq() - { - return IsValid(add_cq_); - } - - /** This method must be called to initialize the global - * algorithmic parameters. The parameters are taken from the - * OptionsList object. */ - bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** @name Slacks */ - //@{ - /** Slacks for x_L (at current iterate) */ - SmartPtr curr_slack_x_L(); - /** Slacks for x_U (at current iterate) */ - SmartPtr curr_slack_x_U(); - /** Slacks for s_L (at current iterate) */ - SmartPtr curr_slack_s_L(); - /** Slacks for s_U (at current iterate) */ - SmartPtr curr_slack_s_U(); - /** Slacks for x_L (at trial point) */ - SmartPtr trial_slack_x_L(); - /** Slacks for x_U (at trial point) */ - SmartPtr trial_slack_x_U(); - /** Slacks for s_L (at trial point) */ - SmartPtr trial_slack_s_L(); - /** Slacks for s_U (at trial point) */ - SmartPtr trial_slack_s_U(); - /** Indicating whether or not we "fudged" the slacks */ - Index AdjustedTrialSlacks(); - /** Reset the flags for "fudged" slacks */ - void ResetAdjustedTrialSlacks(); - //@} - - /** @name Objective function */ - //@{ - /** Value of objective function (at current point) */ - virtual Number curr_f(); - /** Unscaled value of the objective function (at the current point) */ - virtual Number unscaled_curr_f(); - /** Value of objective function (at trial point) */ - virtual Number trial_f(); - /** Unscaled value of the objective function (at the trial point) */ - virtual Number unscaled_trial_f(); - /** Gradient of objective function (at current point) */ - SmartPtr curr_grad_f(); - /** Gradient of objective function (at trial point) */ - SmartPtr trial_grad_f(); - //@} - - /** @name Barrier Objective Function */ - //@{ - /** Barrier Objective Function Value - * (at current iterate with current mu) - */ - virtual Number curr_barrier_obj(); - /** Barrier Objective Function Value - * (at trial point with current mu) - */ - virtual Number trial_barrier_obj(); - - /** Gradient of barrier objective function with respect to x - * (at current point with current mu) */ - SmartPtr curr_grad_barrier_obj_x(); - /** Gradient of barrier objective function with respect to s - * (at current point with current mu) */ - SmartPtr curr_grad_barrier_obj_s(); - - /** Gradient of the damping term with respect to x (times - * kappa_d) */ - SmartPtr grad_kappa_times_damping_x(); - /** Gradient of the damping term with respect to s (times - * kappa_d) */ - SmartPtr grad_kappa_times_damping_s(); - //@} - - /** @name Constraints */ - //@{ - /** c(x) (at current point) */ - SmartPtr curr_c(); - /** unscaled c(x) (at current point) */ - SmartPtr unscaled_curr_c(); - /** c(x) (at trial point) */ - SmartPtr trial_c(); - /** unscaled c(x) (at trial point) */ - SmartPtr unscaled_trial_c(); - /** d(x) (at current point) */ - SmartPtr curr_d(); - /** unscaled d(x) (at current point) */ - SmartPtr unscaled_curr_d(); - /** d(x) (at trial point) */ - SmartPtr trial_d(); - /** d(x) - s (at current point) */ - SmartPtr curr_d_minus_s(); - /** d(x) - s (at trial point) */ - SmartPtr trial_d_minus_s(); - /** Jacobian of c (at current point) */ - SmartPtr curr_jac_c(); - /** Jacobian of c (at trial point) */ - SmartPtr trial_jac_c(); - /** Jacobian of d (at current point) */ - SmartPtr curr_jac_d(); - /** Jacobian of d (at trial point) */ - SmartPtr trial_jac_d(); - /** Product of Jacobian (evaluated at current point) of C - * transpose with general vector */ - SmartPtr curr_jac_cT_times_vec(const Vector& vec); - /** Product of Jacobian (evaluated at trial point) of C - * transpose with general vector */ - SmartPtr trial_jac_cT_times_vec(const Vector& vec); - /** Product of Jacobian (evaluated at current point) of D - * transpose with general vector */ - SmartPtr curr_jac_dT_times_vec(const Vector& vec); - /** Product of Jacobian (evaluated at trial point) of D - * transpose with general vector */ - SmartPtr trial_jac_dT_times_vec(const Vector& vec); - /** Product of Jacobian (evaluated at current point) of C - * transpose with current y_c */ - SmartPtr curr_jac_cT_times_curr_y_c(); - /** Product of Jacobian (evaluated at trial point) of C - * transpose with trial y_c */ - SmartPtr trial_jac_cT_times_trial_y_c(); - /** Product of Jacobian (evaluated at current point) of D - * transpose with current y_d */ - SmartPtr curr_jac_dT_times_curr_y_d(); - /** Product of Jacobian (evaluated at trial point) of D - * transpose with trial y_d */ - SmartPtr trial_jac_dT_times_trial_y_d(); - /** Product of Jacobian (evaluated at current point) of C - * with general vector */ - SmartPtr curr_jac_c_times_vec(const Vector& vec); - /** Product of Jacobian (evaluated at current point) of D - * with general vector */ - SmartPtr curr_jac_d_times_vec(const Vector& vec); - /** Constraint Violation (at current iterate). This value should - * be used in the line search, and not curr_primal_infeasibility(). - * What type of norm is used depends on constr_viol_normtype */ - virtual Number curr_constraint_violation(); - /** Constraint Violation (at trial point). This value should - * be used in the line search, and not curr_primal_infeasibility(). - * What type of norm is used depends on constr_viol_normtype */ - virtual Number trial_constraint_violation(); - /** Real constraint violation in a given norm (at current - * iterate). This considers the inequality constraints without - * slacks. */ - virtual Number curr_nlp_constraint_violation(ENormType NormType); - /** Unscaled real constraint violation in a given norm (at current - * iterate). This considers the inequality constraints without - * slacks. */ - virtual Number unscaled_curr_nlp_constraint_violation(ENormType NormType); - /** Unscaled real constraint violation in a given norm (at trial - * iterate). This considers the inequality constraints without - * slacks. */ - virtual Number unscaled_trial_nlp_constraint_violation(ENormType NormType); - //@} - - /** @name Hessian matrices */ - //@{ - /** exact Hessian at current iterate (uncached) */ - SmartPtr curr_exact_hessian(); - //@} - - /** @name primal-dual error and its components */ - //@{ - /** x-part of gradient of Lagrangian function (at current point) */ - SmartPtr curr_grad_lag_x(); - /** x-part of gradient of Lagrangian function (at trial point) */ - SmartPtr trial_grad_lag_x(); - /** s-part of gradient of Lagrangian function (at current point) */ - SmartPtr curr_grad_lag_s(); - /** s-part of gradient of Lagrangian function (at trial point) */ - SmartPtr trial_grad_lag_s(); - /** x-part of gradient of Lagrangian function (at current point) - including linear damping term */ - SmartPtr curr_grad_lag_with_damping_x(); - /** s-part of gradient of Lagrangian function (at current point) - including linear damping term */ - SmartPtr curr_grad_lag_with_damping_s(); - /** Complementarity for x_L (for current iterate) */ - SmartPtr curr_compl_x_L(); - /** Complementarity for x_U (for current iterate) */ - SmartPtr curr_compl_x_U(); - /** Complementarity for s_L (for current iterate) */ - SmartPtr curr_compl_s_L(); - /** Complementarity for s_U (for current iterate) */ - SmartPtr curr_compl_s_U(); - /** Complementarity for x_L (for trial iterate) */ - SmartPtr trial_compl_x_L(); - /** Complementarity for x_U (for trial iterate) */ - SmartPtr trial_compl_x_U(); - /** Complementarity for s_L (for trial iterate) */ - SmartPtr trial_compl_s_L(); - /** Complementarity for s_U (for trial iterate) */ - SmartPtr trial_compl_s_U(); - /** Relaxed complementarity for x_L (for current iterate and current mu) */ - SmartPtr curr_relaxed_compl_x_L(); - /** Relaxed complementarity for x_U (for current iterate and current mu) */ - SmartPtr curr_relaxed_compl_x_U(); - /** Relaxed complementarity for s_L (for current iterate and current mu) */ - SmartPtr curr_relaxed_compl_s_L(); - /** Relaxed complementarity for s_U (for current iterate and current mu) */ - SmartPtr curr_relaxed_compl_s_U(); - - /** Primal infeasibility in a given norm (at current iterate). */ - virtual Number curr_primal_infeasibility(ENormType NormType); - /** Primal infeasibility in a given norm (at trial point) */ - virtual Number trial_primal_infeasibility(ENormType NormType); - - /** Dual infeasibility in a given norm (at current iterate) */ - virtual Number curr_dual_infeasibility(ENormType NormType); - /** Dual infeasibility in a given norm (at trial iterate) */ - virtual Number trial_dual_infeasibility(ENormType NormType); - /** Unscaled dual infeasibility in a given norm (at current iterate) */ - virtual Number unscaled_curr_dual_infeasibility(ENormType NormType); - - /** Complementarity (for all complementarity conditions together) - * in a given norm (at current iterate) */ - virtual Number curr_complementarity(Number mu, ENormType NormType); - /** Complementarity (for all complementarity conditions together) - * in a given norm (at trial iterate) */ - virtual Number trial_complementarity(Number mu, ENormType NormType); - /** Complementarity (for all complementarity conditions together) - * in a given norm (at current iterate) without NLP scaling. */ - virtual Number unscaled_curr_complementarity(Number mu, ENormType NormType); - - /** Centrality measure (in spirit of the -infinity-neighborhood. */ - Number CalcCentralityMeasure(const Vector& compl_x_L, - const Vector& compl_x_U, - const Vector& compl_s_L, - const Vector& compl_s_U); - /** Centrality measure at current point */ - virtual Number curr_centrality_measure(); - - /** Total optimality error for the original NLP at the current - * iterate, using scaling factors based on multipliers. Note - * that here the constraint violation is measured without slacks - * (nlp_constraint_violation) */ - virtual Number curr_nlp_error(); - /** Total optimality error for the original NLP at the current - * iterate, but using no scaling based on multipliers, and no - * scaling for the NLP. Note that here the constraint violation - * is measured without slacks (nlp_constraint_violation) */ - virtual Number unscaled_curr_nlp_error(); - - /** Total optimality error for the barrier problem at the - * current iterate, using scaling factors based on multipliers. */ - virtual Number curr_barrier_error(); - - /** Norm of the primal-dual system for a given mu (at current - * iterate). The norm is defined as the sum of the 1-norms of - * dual infeasibiliy, primal infeasibility, and complementarity, - * all divided by the number of elements of the vectors of which - * the norm is taken. - */ - virtual Number curr_primal_dual_system_error(Number mu); - /** Norm of the primal-dual system for a given mu (at trial - * iterate). The norm is defined as the sum of the 1-norms of - * dual infeasibiliy, primal infeasibility, and complementarity, - * all divided by the number of elements of the vectors of which - * the norm is taken. - */ - virtual Number trial_primal_dual_system_error(Number mu); - //@} - - /** @name Computing fraction-to-the-boundary step sizes */ - //@{ - /** Fraction to the boundary from (current) primal variables x and s - * for a given step */ - Number primal_frac_to_the_bound(Number tau, - const Vector& delta_x, - const Vector& delta_s); - /** Fraction to the boundary from (current) primal variables x and s - * for internal (current) step */ - Number curr_primal_frac_to_the_bound(Number tau); - /** Fraction to the boundary from (current) dual variables z and v - * for a given step */ - Number dual_frac_to_the_bound(Number tau, - const Vector& delta_z_L, - const Vector& delta_z_U, - const Vector& delta_v_L, - const Vector& delta_v_U); - /** Fraction to the boundary from (current) dual variables z and v - * for a given step, without caching */ - Number uncached_dual_frac_to_the_bound(Number tau, - const Vector& delta_z_L, - const Vector& delta_z_U, - const Vector& delta_v_L, - const Vector& delta_v_U); - /** Fraction to the boundary from (current) dual variables z and v - * for internal (current) step */ - Number curr_dual_frac_to_the_bound(Number tau); - /** Fraction to the boundary from (current) slacks for a given - * step in the slacks. Usually, one will use the - * primal_frac_to_the_bound method to compute the primal fraction - * to the boundary step size, but if it is cheaper to provide the - * steps in the slacks directly (e.g. when the primal step sizes - * are only temporary), the this method is more efficient. This - * method does not cache computations. */ - Number uncached_slack_frac_to_the_bound(Number tau, - const Vector& delta_x_L, - const Vector& delta_x_U, - const Vector& delta_s_L, - const Vector& delta_s_U); - //@} - - /** @name Sigma matrices */ - //@{ - SmartPtr curr_sigma_x(); - SmartPtr curr_sigma_s(); - //@} - - /** average of current values of the complementarities */ - Number curr_avrg_compl(); - /** average of trial values of the complementarities */ - Number trial_avrg_compl(); - - /** inner_product of current barrier obj. fn. gradient with - * current search direction */ - Number curr_gradBarrTDelta(); - - /** Compute the norm of a specific type of a set of vectors (uncached) */ - Number - CalcNormOfType(ENormType NormType, - std::vector > vecs); - - /** Compute the norm of a specific type of two vectors (uncached) */ - Number - CalcNormOfType(ENormType NormType, - const Vector& vec1, const Vector& vec2); - - /** Norm type used for calculating constraint violation */ - ENormType constr_viol_normtype() const - { - return constr_viol_normtype_; - } - - /** Method returning true if this is a square problem */ - bool IsSquareProblem() const; - - /** Method returning the IpoptNLP object. This should only be - * used with care! */ - SmartPtr& GetIpoptNLP() - { - return ip_nlp_; - } - - IpoptAdditionalCq& AdditionalCq() - { - DBG_ASSERT(IsValid(add_cq_)); - return *add_cq_; - } - - /** Methods for IpoptType */ - //@{ - /** Called by IpoptType to register the options */ - static void RegisterOptions(SmartPtr roptions); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - IpoptCalculatedQuantities(); - - /** Copy Constructor */ - IpoptCalculatedQuantities(const IpoptCalculatedQuantities&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptCalculatedQuantities&); - //@} - - /** @name Pointers for easy access to data and NLP information */ - //@{ - /** Ipopt NLP object */ - SmartPtr ip_nlp_; - /** Ipopt Data object */ - SmartPtr ip_data_; - /** Chen-Goldfarb specific calculated quantities */ - SmartPtr add_cq_; - //@} - - /** @name Algorithmic Parameters that can be set throught the - * options list. Those parameters are initialize by calling the - * Initialize method.*/ - //@{ - /** Parameter in formula for computing overall primal-dual - * optimality error */ - Number s_max_; - /** Weighting factor for the linear damping term added to the - * barrier objective funciton. */ - Number kappa_d_; - /** fractional movement allowed in bounds */ - Number slack_move_; - /** Norm type to be used when calculating the constraint violation */ - ENormType constr_viol_normtype_; - /** Flag indicating whether the TNLP with identical structure has - * already been solved before. */ - bool warm_start_same_structure_; - /** Desired value of the barrier parameter */ - Number mu_target_; - //@} - - /** @name Caches for slacks */ - //@{ - CachedResults< SmartPtr > curr_slack_x_L_cache_; - CachedResults< SmartPtr > curr_slack_x_U_cache_; - CachedResults< SmartPtr > curr_slack_s_L_cache_; - CachedResults< SmartPtr > curr_slack_s_U_cache_; - CachedResults< SmartPtr > trial_slack_x_L_cache_; - CachedResults< SmartPtr > trial_slack_x_U_cache_; - CachedResults< SmartPtr > trial_slack_s_L_cache_; - CachedResults< SmartPtr > trial_slack_s_U_cache_; - Index num_adjusted_slack_x_L_; - Index num_adjusted_slack_x_U_; - Index num_adjusted_slack_s_L_; - Index num_adjusted_slack_s_U_; - //@} - - /** @name Cached for objective function stuff */ - //@{ - CachedResults curr_f_cache_; - CachedResults trial_f_cache_; - CachedResults< SmartPtr > curr_grad_f_cache_; - CachedResults< SmartPtr > trial_grad_f_cache_; - //@} - - /** @name Caches for barrier function stuff */ - //@{ - CachedResults curr_barrier_obj_cache_; - CachedResults trial_barrier_obj_cache_; - CachedResults< SmartPtr > curr_grad_barrier_obj_x_cache_; - CachedResults< SmartPtr > curr_grad_barrier_obj_s_cache_; - CachedResults< SmartPtr > grad_kappa_times_damping_x_cache_; - CachedResults< SmartPtr > grad_kappa_times_damping_s_cache_; - //@} - - /** @name Caches for constraint stuff */ - //@{ - CachedResults< SmartPtr > curr_c_cache_; - CachedResults< SmartPtr > trial_c_cache_; - CachedResults< SmartPtr > curr_d_cache_; - CachedResults< SmartPtr > trial_d_cache_; - CachedResults< SmartPtr > curr_d_minus_s_cache_; - CachedResults< SmartPtr > trial_d_minus_s_cache_; - CachedResults< SmartPtr > curr_jac_c_cache_; - CachedResults< SmartPtr > trial_jac_c_cache_; - CachedResults< SmartPtr > curr_jac_d_cache_; - CachedResults< SmartPtr > trial_jac_d_cache_; - CachedResults< SmartPtr > curr_jac_cT_times_vec_cache_; - CachedResults< SmartPtr > trial_jac_cT_times_vec_cache_; - CachedResults< SmartPtr > curr_jac_dT_times_vec_cache_; - CachedResults< SmartPtr > trial_jac_dT_times_vec_cache_; - CachedResults< SmartPtr > curr_jac_c_times_vec_cache_; - CachedResults< SmartPtr > curr_jac_d_times_vec_cache_; - CachedResults curr_constraint_violation_cache_; - CachedResults trial_constraint_violation_cache_; - CachedResults curr_nlp_constraint_violation_cache_; - CachedResults unscaled_curr_nlp_constraint_violation_cache_; - CachedResults unscaled_trial_nlp_constraint_violation_cache_; - //@} - - /** Cache for the exact Hessian */ - CachedResults< SmartPtr > curr_exact_hessian_cache_; - - /** @name Components of primal-dual error */ - //@{ - CachedResults< SmartPtr > curr_grad_lag_x_cache_; - CachedResults< SmartPtr > trial_grad_lag_x_cache_; - CachedResults< SmartPtr > curr_grad_lag_s_cache_; - CachedResults< SmartPtr > trial_grad_lag_s_cache_; - CachedResults< SmartPtr > curr_grad_lag_with_damping_x_cache_; - CachedResults< SmartPtr > curr_grad_lag_with_damping_s_cache_; - CachedResults< SmartPtr > curr_compl_x_L_cache_; - CachedResults< SmartPtr > curr_compl_x_U_cache_; - CachedResults< SmartPtr > curr_compl_s_L_cache_; - CachedResults< SmartPtr > curr_compl_s_U_cache_; - CachedResults< SmartPtr > trial_compl_x_L_cache_; - CachedResults< SmartPtr > trial_compl_x_U_cache_; - CachedResults< SmartPtr > trial_compl_s_L_cache_; - CachedResults< SmartPtr > trial_compl_s_U_cache_; - CachedResults< SmartPtr > curr_relaxed_compl_x_L_cache_; - CachedResults< SmartPtr > curr_relaxed_compl_x_U_cache_; - CachedResults< SmartPtr > curr_relaxed_compl_s_L_cache_; - CachedResults< SmartPtr > curr_relaxed_compl_s_U_cache_; - CachedResults curr_primal_infeasibility_cache_; - CachedResults trial_primal_infeasibility_cache_; - CachedResults curr_dual_infeasibility_cache_; - CachedResults trial_dual_infeasibility_cache_; - CachedResults unscaled_curr_dual_infeasibility_cache_; - CachedResults curr_complementarity_cache_; - CachedResults trial_complementarity_cache_; - CachedResults curr_centrality_measure_cache_; - CachedResults curr_nlp_error_cache_; - CachedResults unscaled_curr_nlp_error_cache_; - CachedResults curr_barrier_error_cache_; - CachedResults curr_primal_dual_system_error_cache_; - CachedResults trial_primal_dual_system_error_cache_; - //@} - - /** @name Caches for fraction to the boundary step sizes */ - //@{ - CachedResults primal_frac_to_the_bound_cache_; - CachedResults dual_frac_to_the_bound_cache_; - //@} - - /** @name Caches for sigma matrices */ - //@{ - CachedResults< SmartPtr > curr_sigma_x_cache_; - CachedResults< SmartPtr > curr_sigma_s_cache_; - //@} - - /** Cache for average of current complementarity */ - CachedResults curr_avrg_compl_cache_; - /** Cache for average of trial complementarity */ - CachedResults trial_avrg_compl_cache_; - - /** Cache for grad barrier obj. fn inner product with step */ - CachedResults curr_gradBarrTDelta_cache_; - - /** @name Indicator vectors required for the linear damping terms - * to handle unbounded solution sets. */ - //@{ - /** Indicator vector for selecting the elements in x that have - * only lower bounds. */ - SmartPtr dampind_x_L_; - /** Indicator vector for selecting the elements in x that have - * only upper bounds. */ - SmartPtr dampind_x_U_; - /** Indicator vector for selecting the elements in s that have - * only lower bounds. */ - SmartPtr dampind_s_L_; - /** Indicator vector for selecting the elements in s that have - * only upper bounds. */ - SmartPtr dampind_s_U_; - //@} - - /** @name Temporary vectors for intermediate calcuations. We keep - * these around to avoid unnecessarily many new allocations of - * Vectors. */ - //@{ - SmartPtr tmp_x_; - SmartPtr tmp_s_; - SmartPtr tmp_c_; - SmartPtr tmp_d_; - SmartPtr tmp_x_L_; - SmartPtr tmp_x_U_; - SmartPtr tmp_s_L_; - SmartPtr tmp_s_U_; - - /** Accessor methods for the temporary vectors */ - Vector& Tmp_x(); - Vector& Tmp_s(); - Vector& Tmp_c(); - Vector& Tmp_d(); - Vector& Tmp_x_L(); - Vector& Tmp_x_U(); - Vector& Tmp_s_L(); - Vector& Tmp_s_U(); - //@} - - /** flag indicating if Initialize method has been called (for - * debugging) */ - bool initialize_called_; - - /** @name Auxiliary functions */ - //@{ - /** Compute new vector containing the slack to a lower bound - * (uncached) - */ - SmartPtr CalcSlack_L(const Matrix& P, - const Vector& x, - const Vector& x_bound); - /** Compute new vector containing the slack to a upper bound - * (uncached) - */ - SmartPtr CalcSlack_U(const Matrix& P, - const Vector& x, - const Vector& x_bound); - /** Compute barrier term at given point - * (uncached) - */ - Number CalcBarrierTerm(Number mu, - const Vector& slack_x_L, - const Vector& slack_x_U, - const Vector& slack_s_L, - const Vector& slack_s_U); - - /** Compute complementarity for slack / multiplier pair */ - SmartPtr CalcCompl(const Vector& slack, - const Vector& mult); - - /** Compute fraction to the boundary parameter for lower and upper bounds */ - Number CalcFracToBound(const Vector& slack_L, - Vector& tmp_L, - const Matrix& P_L, - const Vector& slack_U, - Vector& tmp_U, - const Matrix& P_U, - const Vector& delta, - Number tau); - - /** Compute the scaling factors for the optimality error. */ - void ComputeOptimalityErrorScaling(const Vector& y_c, const Vector& y_d, - const Vector& z_L, const Vector& z_U, - const Vector& v_L, const Vector& v_U, - Number s_max, - Number& s_d, Number& s_c); - - /** Check if slacks are becoming too small. If slacks are - * becoming too small, they are change. The return value is the - * number of corrected slacks. */ - Index CalculateSafeSlack(SmartPtr& slack, - const SmartPtr& bound, - const SmartPtr& curr_point, - const SmartPtr& multiplier); - - /** Computes the indicator vectors that can be used to filter out - * those entries in the slack_... variables, that correspond to - * variables with only lower and upper bounds. This is required - * for the linear damping term in the barrier objective function - * to handle unbounded solution sets. */ - void ComputeDampingIndicators(SmartPtr& dampind_x_L, - SmartPtr& dampind_x_U, - SmartPtr& dampind_s_L, - SmartPtr& dampind_s_U); - - /** Check if we are in the restoration phase. Returns true, if the - * ip_nlp is of the type RestoIpoptNLP. ToDo: We probably want to - * handle this more elegant and don't have an explicit dependency - * here. Now I added this because otherwise the caching doesn't - * work properly since the restoration phase objective function - * depends on the current barrier parameter. */ - bool in_restoration_phase(); - - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIpoptData.hpp b/external/ipopt/include/coin/IpIpoptData.hpp deleted file mode 100644 index 6973bab6b..000000000 --- a/external/ipopt/include/coin/IpIpoptData.hpp +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIpoptData.hpp 2472 2014-04-05 17:47:20Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPIPOPTDATA_HPP__ -#define __IPIPOPTDATA_HPP__ - -#include "IpSymMatrix.hpp" -#include "IpOptionsList.hpp" -#include "IpIteratesVector.hpp" -#include "IpRegOptions.hpp" -#include "IpTimingStatistics.hpp" - -namespace Ipopt -{ - - /* Forward declaration */ - class IpoptNLP; - - /** Base class for additional data that is special to a particular - * type of algorithm, such as the CG penalty function, or using - * iterative linear solvers. The regular IpoptData object should - * be given a derivation of this base class when it is created. */ - class IpoptAdditionalData : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - IpoptAdditionalData() - {} - - /** Default destructor */ - virtual ~IpoptAdditionalData() - {} - //@} - - /** This method is called to initialize the global algorithmic - * parameters. The parameters are taken from the OptionsList - * object. */ - virtual bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix) = 0; - - /** Initialize Data Structures at the beginning. */ - virtual bool InitializeDataStructures() = 0; - - /** Do whatever is necessary to accept a trial point as current - * iterate. This is also used to finish an iteration, i.e., to - * release memory, and to reset any flags for a new iteration. */ - virtual void AcceptTrialPoint() = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - IpoptAdditionalData(const IpoptAdditionalData&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptAdditionalData&); - //@} - }; - - /** Class to organize all the data required by the algorithm. - * Internally, once this Data object has been initialized, all - * internal curr_ vectors must always be set (so that prototyes are - * available). The current values can only be set from the trial - * values. The trial values can be set by copying from a vector or - * by adding some fraction of a step to the current values. This - * object also stores steps, which allows to easily communicate the - * step from the step computation object to the line search object. - */ - class IpoptData : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor */ - IpoptData(SmartPtr add_data = NULL, - Number cpu_time_start = -1.); - - /** Default destructor */ - virtual ~IpoptData(); - //@} - - /** Initialize Data Structures */ - bool InitializeDataStructures(IpoptNLP& ip_nlp, - bool want_x, - bool want_y_c, - bool want_y_d, - bool want_z_L, - bool want_z_U); - - /** This method must be called to initialize the global - * algorithmic parameters. The parameters are taken from the - * OptionsList object. */ - bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** @name Get Methods for Iterates */ - //@{ - /** Current point */ - inline - SmartPtr curr() const; - - /** Get the current point in a copied container that is non-const. - The entries in the container cannot be modified, but - the container can be modified to point to new entries. - */ - // SmartPtr curr_container() const; - - /** Get Trial point */ - inline - SmartPtr trial() const; - - /** Get Trial point in a copied container that is non-const. - * The entries in the container can not be modified, but - * the container can be modified to point to new entries. - */ - //SmartPtr trial_container() const; - - /** Set the trial point - this method copies the pointer for - * efficiency (no copy and to keep cache tags the same) so - * after you call set you cannot modify the data again - */ - inline - void set_trial(SmartPtr& trial); - - /** Set the values of the primal trial variables (x and s) from - * provided Step with step length alpha. - */ - void SetTrialPrimalVariablesFromStep(Number alpha, - const Vector& delta_x, - const Vector& delta_s); - /** Set the values of the trial values for the equality constraint - * multipliers (y_c and y_d) from provided step with step length - * alpha. - */ - void SetTrialEqMultipliersFromStep(Number alpha, - const Vector& delta_y_c, - const Vector& delta_y_d); - /** Set the value of the trial values for the bound multipliers - * (z_L, z_U, v_L, v_U) from provided step with step length - * alpha. - */ - void SetTrialBoundMultipliersFromStep(Number alpha, - const Vector& delta_z_L, - const Vector& delta_z_U, - const Vector& delta_v_L, - const Vector& delta_v_U); - - /** ToDo: I may need to add versions of set_trial like the - * following, but I am not sure - */ - // void set_trial(const SmartPtr& trial_iterates); - // void set_trial(SmartPtr& trial_iterates); - - /** get the current delta */ - inline - SmartPtr delta() const; - - /** Set the current delta - like the trial point, this method copies - * the pointer for efficiency (no copy and to keep cache tags the - * same) so after you call set, you cannot modify the data - */ - inline - void set_delta(SmartPtr& delta); - - /** Set the current delta - like the trial point, this method - * copies the pointer for efficiency (no copy and to keep cache - * tags the same) so after you call set, you cannot modify the - * data. This is the version that is happy with a pointer to - * const IteratesVector. - */ - inline - void set_delta(SmartPtr& delta); - - /** Affine Delta */ - inline - SmartPtr delta_aff() const; - - /** Set the affine delta - like the trial point, this method copies - * the pointer for efficiency (no copy and to keep cache tags the - * same) so after you call set, you cannot modify the data - */ - inline - void set_delta_aff(SmartPtr& delta_aff); - - /** Hessian or Hessian approximation (do not hold on to it, it might be changed) */ - SmartPtr W() - { - DBG_ASSERT(IsValid(W_)); - return W_; - } - - /** Set Hessian approximation */ - void Set_W(SmartPtr W) - { - W_ = W; - } - - /** @name ("Main") Primal-dual search direction. Those fields are - * used to store the search directions computed from solving the - * primal-dual system, and can be used in the line search. They - * are overwritten in every iteration, so do not hold on to the - * pointers (make copies instead) */ - //@{ - - /** Returns true, if the primal-dual step have been already - * computed for the current iteration. This flag is reset after - * every call of AcceptTrialPoint(). If the search direction is - * computed during the computation of the barrier parameter, the - * method computing the barrier parameter should call - * SetHaveDeltas(true) to tell the IpoptAlgorithm object that it - * doesn't need to recompute the primal-dual step. */ - bool HaveDeltas() const - { - return have_deltas_; - } - - /** Method for setting the HaveDeltas flag. This method should be - * called if some method computes the primal-dual step (and - * stores it in the delta_ fields of IpoptData) at an early part - * of the iteration. If that flag is set to true, the - * IpoptAlgorithm object will not recompute the step. */ - void SetHaveDeltas(bool have_deltas) - { - have_deltas_ = have_deltas; - } - //@} - - /** @name Affine-scaling step. Those fields can be used to store - * the affine scaling step. For example, if the method for - * computing the current barrier parameter computes the affine - * scaling steps, then the corrector step in the line search does - * not have to recompute those solutions of the linear system. */ - //@{ - - /** Returns true, if the affine-scaling step have been already - * computed for the current iteration. This flag is reset after - * every call of AcceptTrialPoint(). If the search direction is - * computed during the computation of the barrier parameter, the - * method computing the barrier parameter should call - * SetHaveDeltas(true) to tell the line search does not have to - * recompute them in case it wants to do a corrector step. */ - bool HaveAffineDeltas() const - { - return have_affine_deltas_; - } - - /** Method for setting the HaveDeltas flag. This method should be - * called if some method computes the primal-dual step (and - * stores it in the delta_ fields of IpoptData) at an early part - * of the iteration. If that flag is set to true, the - * IpoptAlgorithm object will not recompute the step. */ - void SetHaveAffineDeltas(bool have_affine_deltas) - { - have_affine_deltas_ = have_affine_deltas; - } - //@} - - /** @name Public Methods for updating iterates */ - //@{ - /** Copy the trial values to the current values */ - inline - void CopyTrialToCurrent(); - - /** Set the current iterate values from the - * trial values. */ - void AcceptTrialPoint(); - //@} - - /** @name General algorithmic data */ - //@{ - Index iter_count() const - { - return iter_count_; - } - void Set_iter_count(Index iter_count) - { - iter_count_ = iter_count; - } - - Number curr_mu() const - { - DBG_ASSERT(mu_initialized_); - return curr_mu_; - } - void Set_mu(Number mu) - { - curr_mu_ = mu; - mu_initialized_ = true; - } - bool MuInitialized() const - { - return mu_initialized_; - } - - Number curr_tau() const - { - DBG_ASSERT(tau_initialized_); - return curr_tau_; - } - void Set_tau(Number tau) - { - curr_tau_ = tau; - tau_initialized_ = true; - } - bool TauInitialized() const - { - return tau_initialized_; - } - - void SetFreeMuMode(bool free_mu_mode) - { - free_mu_mode_ = free_mu_mode; - } - bool FreeMuMode() const - { - return free_mu_mode_; - } - - /** Setting the flag that indicates if a tiny step (below machine - * precision) has been detected */ - void Set_tiny_step_flag(bool flag) - { - tiny_step_flag_ = flag; - } - bool tiny_step_flag() - { - return tiny_step_flag_; - } - //@} - - /** Overall convergence tolerance. It is used in the convergence - * test, but also in some other parts of the algorithm that - * depend on the specified tolerance, such as the minimum value - * for the barrier parameter. */ - //@{ - /** Obtain the tolerance. */ - Number tol() const - { - DBG_ASSERT(initialize_called_); - return tol_; - } - /** Set a new value for the tolerance. One should be very careful - * when using this, since changing the predefined tolerance might - * have unexpected consequences. This method is for example used - * in the restoration convergence checker to tighten the - * restoration phase convergence tolerance, if the restoration - * phase converged to a point that has not a large value for the - * constraint violation. */ - void Set_tol(Number tol) - { - tol_ = tol; - } - //@} - - /** Cpu time counter at the beginning of the optimization. This - * is useful to see how much CPU time has been spent in this - * optimization run. */ - Number cpu_time_start() const - { - return cpu_time_start_; - } - - /** @name Information gathered for iteration output */ - //@{ - Number info_regu_x() const - { - return info_regu_x_; - } - void Set_info_regu_x(Number regu_x) - { - info_regu_x_ = regu_x; - } - Number info_alpha_primal() const - { - return info_alpha_primal_; - } - void Set_info_alpha_primal(Number alpha_primal) - { - info_alpha_primal_ = alpha_primal; - } - char info_alpha_primal_char() const - { - return info_alpha_primal_char_; - } - void Set_info_alpha_primal_char(char info_alpha_primal_char) - { - info_alpha_primal_char_ = info_alpha_primal_char; - } - Number info_alpha_dual() const - { - return info_alpha_dual_; - } - void Set_info_alpha_dual(Number alpha_dual) - { - info_alpha_dual_ = alpha_dual; - } - Index info_ls_count() const - { - return info_ls_count_; - } - void Set_info_ls_count(Index ls_count) - { - info_ls_count_ = ls_count; - } - bool info_skip_output() const - { - return info_skip_output_; - } - void Append_info_string(const std::string& add_str) - { - info_string_ += add_str; - } - const std::string& info_string() const - { - return info_string_; - } - /** Set this to true, if the next time when output is written, the - * summary line should not be printed. */ - void Set_info_skip_output(bool info_skip_output) - { - info_skip_output_ = info_skip_output; - } - - /** gives time when the last summary output line was printed */ - Number info_last_output() - { - return info_last_output_; - } - /** sets time when the last summary output line was printed */ - void Set_info_last_output(Number info_last_output) - { - info_last_output_ = info_last_output; - } - - /** gives number of iteration summaries actually printed - * since last summary header was printed */ - int info_iters_since_header() - { - return info_iters_since_header_; - } - /** increases number of iteration summaries actually printed - * since last summary header was printed */ - void Inc_info_iters_since_header() - { - info_iters_since_header_++; - } - /** sets number of iteration summaries actually printed - * since last summary header was printed */ - void Set_info_iters_since_header(int info_iters_since_header) - { - info_iters_since_header_ = info_iters_since_header; - } - - /** Reset all info fields */ - void ResetInfo() - { - info_regu_x_ = 0; - info_alpha_primal_ = 0; - info_alpha_dual_ = 0.; - info_alpha_primal_char_ = ' '; - info_skip_output_ = false; - info_string_.erase(); - } - //@} - - /** Return Timing Statistics Object */ - TimingStatistics& TimingStats() - { - return timing_statistics_; - } - - /** Check if additional data has been set */ - bool HaveAddData() - { - return IsValid(add_data_); - } - - /** Get access to additional data object */ - IpoptAdditionalData& AdditionalData() - { - return *add_data_; - } - - /** Set a new pointer for additional Ipopt data */ - void SetAddData(SmartPtr add_data) - { - DBG_ASSERT(!HaveAddData()); - add_data_ = add_data; - } - - /** Set the perturbation of the primal-dual system */ - void setPDPert(Number pd_pert_x, Number pd_pert_s, - Number pd_pert_c, Number pd_pert_d) - { - pd_pert_x_ = pd_pert_x; - pd_pert_s_ = pd_pert_s; - pd_pert_c_ = pd_pert_c; - pd_pert_d_ = pd_pert_d; - } - - /** Get the current perturbation of the primal-dual system */ - void getPDPert(Number& pd_pert_x, Number& pd_pert_s, - Number& pd_pert_c, Number& pd_pert_d) - { - pd_pert_x = pd_pert_x_; - pd_pert_s = pd_pert_s_; - pd_pert_c = pd_pert_c_; - pd_pert_d = pd_pert_d_; - } - - /** Methods for IpoptType */ - //@{ - static void RegisterOptions(const SmartPtr& roptions); - //@} - - private: - /** @name Iterates */ - //@{ - /** Main iteration variables - * (current iteration) */ - SmartPtr curr_; - - /** Main iteration variables - * (trial calculations) */ - SmartPtr trial_; - - /** Hessian (approximation) - might be changed elsewhere! */ - SmartPtr W_; - - /** @name Primal-dual Step */ - //@{ - SmartPtr delta_; - /** The following flag is set to true, if some other part of the - * algorithm (like the method for computing the barrier - * parameter) has already computed the primal-dual search - * direction. This flag is reset when the AcceptTrialPoint - * method is called. - * ToDo: we could cue off of a null delta_; - */ - bool have_deltas_; - //@} - - /** @name Affine-scaling step. This used to transfer the - * information about the affine-scaling step from the computation - * of the barrier parameter to the corrector (in the line - * search). */ - //@{ - SmartPtr delta_aff_; - /** The following flag is set to true, if some other part of the - * algorithm (like the method for computing the barrier - * parameter) has already computed the affine-scaling step. This - * flag is reset when the AcceptTrialPoint method is called. - * ToDo: we could cue off of a null delta_aff_; - */ - bool have_affine_deltas_; - //@} - - /** iteration count */ - Index iter_count_; - - /** current barrier parameter */ - Number curr_mu_; - bool mu_initialized_; - - /** current fraction to the boundary parameter */ - Number curr_tau_; - bool tau_initialized_; - - /** flag indicating if Initialize method has been called (for - * debugging) */ - bool initialize_called_; - - /** flag for debugging whether we have already curr_ values - * available (from which new Vectors can be generated */ - bool have_prototypes_; - - /** @name Global algorithm parameters. Those are options that can - * be modified by the user and appear at different places in the - * algorithm. They are set using an OptionsList object in the - * Initialize method. */ - //@{ - /** Overall convergence tolerance */ - Number tol_; - //@} - - /** @name Status data **/ - //@{ - /** flag indicating whether the algorithm is in the free mu mode */ - bool free_mu_mode_; - /** flag indicating if a tiny step has been detected */ - bool tiny_step_flag_; - //@} - - /** @name Gathered information for iteration output */ - //@{ - /** Size of regularization for the Hessian */ - Number info_regu_x_; - /** Primal step size */ - Number info_alpha_primal_; - /** Info character for primal step size */ - char info_alpha_primal_char_; - /** Dual step size */ - Number info_alpha_dual_; - /** Number of backtracking trial steps */ - Index info_ls_count_; - /** true, if next summary output line should not be printed (eg - * after restoration phase. */ - bool info_skip_output_; - /** any string of characters for the end of the output line */ - std::string info_string_; - /** time when the last summary output line was printed */ - Number info_last_output_; - /** number of iteration summaries actually printed since last - * summary header was printed */ - int info_iters_since_header_; - //@} - - /** VectorSpace for all the iterates */ - SmartPtr iterates_space_; - - /** TimingStatistics object collecting all Ipopt timing - * statistics */ - TimingStatistics timing_statistics_; - - /** CPU time counter at initialization. */ - Number cpu_time_start_; - - /** Object for the data specific for the Chen-Goldfarb penalty - * method algorithm */ - SmartPtr add_data_; - - /** @name Information about the perturbation of the primal-dual - * system */ - //@{ - Number pd_pert_x_; - Number pd_pert_s_; - Number pd_pert_c_; - Number pd_pert_d_; - //@} - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - IpoptData(const IpoptData&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptData&); - //@} - -#if COIN_IPOPT_CHECKLEVEL > 0 - /** Some debug flags to make sure vectors are not changed - * behind the IpoptData's back - */ - //@{ - TaggedObject::Tag debug_curr_tag_; - TaggedObject::Tag debug_trial_tag_; - TaggedObject::Tag debug_delta_tag_; - TaggedObject::Tag debug_delta_aff_tag_; - TaggedObject::Tag debug_curr_tag_sum_; - TaggedObject::Tag debug_trial_tag_sum_; - TaggedObject::Tag debug_delta_tag_sum_; - TaggedObject::Tag debug_delta_aff_tag_sum_; - //@} -#endif - - }; - - inline - SmartPtr IpoptData::curr() const - { - DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) ); - - return curr_; - } - - inline - SmartPtr IpoptData::trial() const - { - DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) ); - - return trial_; - } - - inline - SmartPtr IpoptData::delta() const - { - DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) ); - - return delta_; - } - - inline - SmartPtr IpoptData::delta_aff() const - { - DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) ); - - return delta_aff_; - } - - inline - void IpoptData::CopyTrialToCurrent() - { - curr_ = trial_; -#if COIN_IPOPT_CHECKLEVEL > 0 - - if (IsValid(curr_)) { - debug_curr_tag_ = curr_->GetTag(); - debug_curr_tag_sum_ = curr_->GetTagSum(); - } - else { - debug_curr_tag_ = 0; - debug_curr_tag_sum_ = 0; - } -#endif - - } - - inline - void IpoptData::set_trial(SmartPtr& trial) - { - trial_ = ConstPtr(trial); - -#if COIN_IPOPT_CHECKLEVEL > 0 - // verify the correct space - DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_)); - if (IsValid(trial)) { - debug_trial_tag_ = trial->GetTag(); - debug_trial_tag_sum_ = trial->GetTagSum(); - } - else { - debug_trial_tag_ = 0; - debug_trial_tag_sum_ = 0; - } -#endif - - trial = NULL; - } - - inline - void IpoptData::set_delta(SmartPtr& delta) - { - delta_ = ConstPtr(delta); -#if COIN_IPOPT_CHECKLEVEL > 0 - - if (IsValid(delta)) { - debug_delta_tag_ = delta->GetTag(); - debug_delta_tag_sum_ = delta->GetTagSum(); - } - else { - debug_delta_tag_ = 0; - debug_delta_tag_sum_ = 0; - } -#endif - - delta = NULL; - } - - inline - void IpoptData::set_delta(SmartPtr& delta) - { - delta_ = delta; -#if COIN_IPOPT_CHECKLEVEL > 0 - - if (IsValid(delta)) { - debug_delta_tag_ = delta->GetTag(); - debug_delta_tag_sum_ = delta->GetTagSum(); - } - else { - debug_delta_tag_ = 0; - debug_delta_tag_sum_ = 0; - } -#endif - - delta = NULL; - } - - inline - void IpoptData::set_delta_aff(SmartPtr& delta_aff) - { - delta_aff_ = ConstPtr(delta_aff); -#if COIN_IPOPT_CHECKLEVEL > 0 - - if (IsValid(delta_aff)) { - debug_delta_aff_tag_ = delta_aff->GetTag(); - debug_delta_aff_tag_sum_ = delta_aff->GetTagSum(); - } - else { - debug_delta_aff_tag_ = 0; - debug_delta_aff_tag_sum_ = delta_aff->GetTagSum(); - } -#endif - - delta_aff = NULL; - } - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIpoptNLP.hpp b/external/ipopt/include/coin/IpIpoptNLP.hpp deleted file mode 100644 index 21951c351..000000000 --- a/external/ipopt/include/coin/IpIpoptNLP.hpp +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIpoptNLP.hpp 2594 2015-08-09 14:31:05Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPIPOPTNLP_HPP__ -#define __IPIPOPTNLP_HPP__ - -#include "IpNLP.hpp" -#include "IpJournalist.hpp" -#include "IpNLPScaling.hpp" - -namespace Ipopt -{ - // forward declarations - class IteratesVector; - - /** This is the abstract base class for classes that map - * the traditional NLP into - * something that is more useful by Ipopt. - * This class takes care of storing the - * calculated model results, handles cacheing, - * and (some day) takes care of addition of slacks. - */ - class IpoptNLP : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - IpoptNLP(const SmartPtr nlp_scaling) - : - nlp_scaling_(nlp_scaling) - {} - - /** Default destructor */ - virtual ~IpoptNLP() - {} - //@} - - /** Initialization method. Set the internal options and - * initialize internal data structures. */ - virtual bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix) - { - bool ret = true; - if (IsValid(nlp_scaling_)) { - ret = nlp_scaling_->Initialize(jnlst, options, prefix); - } - return ret; - } - - /**@name Possible Exceptions */ - //@{ - /** thrown if there is any error evaluating values from the nlp */ - DECLARE_STD_EXCEPTION(Eval_Error); - //@} - /** Initialize (create) structures for - * the iteration data */ - virtual bool InitializeStructures(SmartPtr& x, - bool init_x, - SmartPtr& y_c, - bool init_y_c, - SmartPtr& y_d, - bool init_y_d, - SmartPtr& z_L, - bool init_z_L, - SmartPtr& z_U, - bool init_z_U, - SmartPtr& v_L, - SmartPtr& v_U - ) = 0; - - /** Method accessing the GetWarmStartIterate of the NLP */ - virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate)=0; - - /** Accessor methods for model data */ - //@{ - /** Objective value */ - virtual Number f(const Vector& x) = 0; - - /** Gradient of the objective */ - virtual SmartPtr grad_f(const Vector& x) = 0; - - /** Equality constraint residual */ - virtual SmartPtr c(const Vector& x) = 0; - - /** Jacobian Matrix for equality constraints */ - virtual SmartPtr jac_c(const Vector& x) = 0; - - /** Inequality constraint residual (reformulated - * as equalities with slacks */ - virtual SmartPtr d(const Vector& x) = 0; - - /** Jacobian Matrix for inequality constraints */ - virtual SmartPtr jac_d(const Vector& x) = 0; - - /** Hessian of the Lagrangian */ - virtual SmartPtr h(const Vector& x, - Number obj_factor, - const Vector& yc, - const Vector& yd - ) = 0; - - /** Lower bounds on x */ - virtual SmartPtr x_L() const = 0; - - /** Permutation matrix (x_L_ -> x) */ - virtual SmartPtr Px_L() const = 0; - - /** Upper bounds on x */ - virtual SmartPtr x_U() const = 0; - - /** Permutation matrix (x_U_ -> x */ - virtual SmartPtr Px_U() const = 0; - - /** Lower bounds on d */ - virtual SmartPtr d_L() const = 0; - - /** Permutation matrix (d_L_ -> d) */ - virtual SmartPtr Pd_L() const = 0; - - /** Upper bounds on d */ - virtual SmartPtr d_U() const = 0; - - /** Permutation matrix (d_U_ -> d */ - virtual SmartPtr Pd_U() const = 0; - - /** x_space */ - virtual SmartPtr x_space() const = 0; - - /** Accessor method to obtain the MatrixSpace for the Hessian - * matrix (or it's approximation) */ - virtual SmartPtr HessianMatrixSpace() const = 0; - //@} - - /** Accessor method for vector/matrix spaces pointers. */ - virtual void GetSpaces(SmartPtr& x_space, - SmartPtr& c_space, - SmartPtr& d_space, - SmartPtr& x_l_space, - SmartPtr& px_l_space, - SmartPtr& x_u_space, - SmartPtr& px_u_space, - SmartPtr& d_l_space, - SmartPtr& pd_l_space, - SmartPtr& d_u_space, - SmartPtr& pd_u_space, - SmartPtr& Jac_c_space, - SmartPtr& Jac_d_space, - SmartPtr& Hess_lagrangian_space) = 0; - - /** Method for adapting the variable bounds. This is called if - * slacks are becoming too small */ - virtual void AdjustVariableBounds(const Vector& new_x_L, - const Vector& new_x_U, - const Vector& new_d_L, - const Vector& new_d_U)=0; - - /** @name Counters for the number of function evaluations. */ - //@{ - virtual Index f_evals() const = 0; - virtual Index grad_f_evals() const = 0; - virtual Index c_evals() const = 0; - virtual Index jac_c_evals() const = 0; - virtual Index d_evals() const = 0; - virtual Index jac_d_evals() const = 0; - virtual Index h_evals() const = 0; - //@} - - /** @name Special method for dealing with the fact that the - * restoration phase objective function depends on the barrier - * parameter */ - //@{ - /** Method for telling the IpoptCalculatedQuantities class whether - * the objective function depends on the barrier function. This - * is only used for the restoration phase NLP - * formulation. Probably only RestoIpoptNLP should overwrite - * this. */ - virtual bool objective_depends_on_mu() const - { - return false; - } - - /** Replacement for the default objective function method which - * knows about the barrier parameter */ - virtual Number f(const Vector& x, Number mu) = 0; - - /** Replacement for the default objective gradient method which - * knows about the barrier parameter */ - virtual SmartPtr grad_f(const Vector& x, Number mu) = 0; - - /** Replacement for the default Lagrangian Hessian method which - * knows about the barrier parameter */ - virtual SmartPtr h(const Vector& x, - Number obj_factor, - const Vector& yc, - const Vector& yd, - Number mu) = 0; - - /** Provides a Hessian matrix from the correct matrix space with - * uninitialized values. This can be used in LeastSquareMults to - * obtain a "zero Hessian". */ - virtual SmartPtr uninitialized_h() = 0; - //@} - - /**@name solution routines */ - //@{ - virtual void FinalizeSolution(SolverReturn status, - const Vector& x, const Vector& z_L, const Vector& z_U, - const Vector& c, const Vector& d, - const Vector& y_c, const Vector& y_d, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq)=0; - - virtual bool IntermediateCallBack(AlgorithmMode mode, - Index iter, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, - SmartPtr ip_data, - SmartPtr ip_cq)=0; - //@} - - /** Returns the scaling strategy object */ - SmartPtr NLP_scaling() const - { - DBG_ASSERT(IsValid(nlp_scaling_)); - return nlp_scaling_; - } - - private: - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - - /** Copy Constructor */ - IpoptNLP(const IpoptNLP&); - - /** Overloaded Equals Operator */ - void operator=(const IpoptNLP&); - //@} - - SmartPtr nlp_scaling_; - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIterateInitializer.hpp b/external/ipopt/include/coin/IpIterateInitializer.hpp deleted file mode 100644 index d17965169..000000000 --- a/external/ipopt/include/coin/IpIterateInitializer.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIterateInitializer.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-09-24 - -#ifndef __IPITERATEINITIALIZER_HPP__ -#define __IPITERATEINITIALIZER_HPP__ - -#include "IpAlgStrategy.hpp" -#include "IpIpoptNLP.hpp" -#include "IpIpoptData.hpp" -#include "IpIpoptCalculatedQuantities.hpp" - -namespace Ipopt -{ - - /** Base class for all methods for initializing the iterates. - */ - class IterateInitializer: public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - IterateInitializer() - {} - - /** Default destructor */ - virtual ~IterateInitializer() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Compute the initial iterates and set the into the curr field - * of the ip_data object. */ - virtual bool SetInitialIterates() = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - IterateInitializer(const IterateInitializer&); - - /** Overloaded Equals Operator */ - void operator=(const IterateInitializer&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIteratesVector.hpp b/external/ipopt/include/coin/IpIteratesVector.hpp deleted file mode 100644 index 2ed75802c..000000000 --- a/external/ipopt/include/coin/IpIteratesVector.hpp +++ /dev/null @@ -1,689 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIteratesVector.hpp 2472 2014-04-05 17:47:20Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-06-06 - -#ifndef __IPITERATESVECTOR_HPP__ -#define __IPITERATESVECTOR_HPP__ - -#include "IpCompoundVector.hpp" - -namespace Ipopt -{ - /* forward declarations */ - class IteratesVectorSpace; - - /** Specialized CompoundVector class specifically for the algorithm - * iterates. This class inherits from CompoundVector and is a - * specialized class for handling the iterates of the Ipopt - * Algorithm, that is, x, s, y_c, y_d, z_L, z_U, v_L, and v_U. It - * inherits from CompoundVector so it can behave like a CV in most - * calculations, but it has fixed dimensions and cannot be - * customized - */ - class IteratesVector : public CompoundVector - { - public: - /** Constructors / Destructors */ - //@{ - IteratesVector(const IteratesVectorSpace* owner_space, bool create_new); - - virtual ~IteratesVector(); - //@} - - /** Make New methods */ - //@{ - /** Use this method to create a new iterates vector. The MakeNew - * method on the Vector class also works, but it does not give - * the create_new option. - */ - SmartPtr MakeNewIteratesVector(bool create_new = true) const; - - /** Use this method to create a new iterates vector with a copy of - * all the data. - */ - SmartPtr MakeNewIteratesVectorCopy() const - { - SmartPtr ret = MakeNewIteratesVector(true); - ret->Copy(*this); - return ret; - } - - /** Use this method to create a new iterates vector - * container. This creates a new NonConst container, but the - * elements inside the iterates vector may be const. Therefore, - * the container can be modified to point to new entries, but the - * existing entries may or may not be modifiable. - */ - SmartPtr MakeNewContainer() const; - //@} - - /** Iterates Set/Get Methods */ - //@{ - /** Get the x iterate (const) */ - SmartPtr x() const - { - return GetIterateFromComp(0); - } - - /** Get the x iterate (non-const) - this can only be called if the - * vector was created intenally, or the Set_x_NonConst method was - * used. */ - SmartPtr x_NonConst() - { - return GetNonConstIterateFromComp(0); - } - - /** Create a new vector in the x entry */ - inline - SmartPtr create_new_x(); - - /** Create a new vector in the x entry and copy the current values - * into it. */ - SmartPtr create_new_x_copy() - { - SmartPtr curr_x = GetComp(0); - Set_x_NonConst(*curr_x->MakeNew()); - x_NonConst()->Copy(*curr_x); - return x_NonConst(); - } - - /** Set the x iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_x(const Vector& vec) - { - SetComp(0, vec); - } - - /** Set the x iterate (non-const). Sets the pointer, does NOT copy - * data. */ - void Set_x_NonConst(Vector& vec) - { - SetCompNonConst(0, vec); - } - - /** Get the s iterate (const) */ - SmartPtr s() const - { - return GetIterateFromComp(1); - } - - /** Get the s iterate (non-const) - this can only be called if the - * vector was created intenally, or the Set_s_NonConst method was - * used. */ - SmartPtr s_NonConst() - { - return GetNonConstIterateFromComp(1); - } - - /** Create a new vector in the s entry */ - inline - SmartPtr create_new_s(); - - /** Create a new vector in the s entry and copy the current values - * into it. */ - SmartPtr create_new_s_copy() - { - SmartPtr curr_s = GetComp(1); - Set_s_NonConst(*curr_s->MakeNew()); - s_NonConst()->Copy(*curr_s); - return s_NonConst(); - } - - /** Set the s iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_s(const Vector& vec) - { - SetComp(1, vec); - } - - /** Set the s iterate (non-const). Sets the pointer, does NOT copy - * data. */ - void Set_s_NonConst(Vector& vec) - { - SetCompNonConst(1, vec); - } - - /** Get the y_c iterate (const) */ - SmartPtr y_c() const - { - return GetIterateFromComp(2); - } - - /** Get the y_c iterate (non-const) - this can only be called if - * the vector was created intenally, or the Set_y_c_NonConst - * method was used. */ - SmartPtr y_c_NonConst() - { - return GetNonConstIterateFromComp(2); - } - - /** Create a new vector in the y_c entry */ - inline - SmartPtr create_new_y_c(); - - /** Create a new vector in the y_c entry and copy the current - * values into it. */ - SmartPtr create_new_y_c_copy() - { - SmartPtr curr_y_c = GetComp(2); - Set_y_c_NonConst(*curr_y_c->MakeNew()); - y_c_NonConst()->Copy(*curr_y_c); - return y_c_NonConst(); - } - - /** Set the y_c iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_y_c(const Vector& vec) - { - SetComp(2, vec); - } - - /** Set the y_c iterate (non-const). Sets the pointer, does NOT - * copy data. */ - void Set_y_c_NonConst(Vector& vec) - { - SetCompNonConst(2, vec); - } - - /** Get the y_d iterate (const) */ - SmartPtr y_d() const - { - return GetIterateFromComp(3); - } - - /** Get the y_d iterate (non-const) - this can only be called if - * the vector was created intenally, or the Set_y_d_NonConst - * method was used. */ - SmartPtr y_d_NonConst() - { - return GetNonConstIterateFromComp(3); - } - - /** Create a new vector in the y_d entry */ - inline - SmartPtr create_new_y_d(); - - /** Create a new vector in the y_d entry and copy the current - * values into it. */ - SmartPtr create_new_y_d_copy() - { - SmartPtr curr_y_d = GetComp(3); - Set_y_d_NonConst(*curr_y_d->MakeNew()); - y_d_NonConst()->Copy(*curr_y_d); - return y_d_NonConst(); - } - - /** Set the y_d iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_y_d(const Vector& vec) - { - SetComp(3, vec); - } - - /** Set the y_d iterate (non-const). Sets the pointer, does NOT - * copy data. */ - void Set_y_d_NonConst(Vector& vec) - { - SetCompNonConst(3, vec); - } - - /** Get the z_L iterate (const) */ - SmartPtr z_L() const - { - return GetIterateFromComp(4); - } - - /** Get the z_L iterate (non-const) - this can only be called if - * the vector was created intenally, or the Set_z_L_NonConst - * method was used. */ - SmartPtr z_L_NonConst() - { - return GetNonConstIterateFromComp(4); - } - - /** Create a new vector in the z_L entry */ - inline - SmartPtr create_new_z_L(); - - /** Create a new vector in the z_L entry and copy the current - * values into it. */ - SmartPtr create_new_z_L_copy() - { - SmartPtr curr_z_L = GetComp(4); - Set_z_L_NonConst(*curr_z_L->MakeNew()); - z_L_NonConst()->Copy(*curr_z_L); - return z_L_NonConst(); - } - - /** Set the z_L iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_z_L(const Vector& vec) - { - SetComp(4, vec); - } - - /** Set the z_L iterate (non-const). Sets the pointer, does NOT - * copy data. */ - void Set_z_L_NonConst(Vector& vec) - { - SetCompNonConst(4, vec); - } - - /** Get the z_U iterate (const) */ - SmartPtr z_U() const - { - return GetIterateFromComp(5); - } - - /** Get the z_U iterate (non-const) - this can only be called if - * the vector was created intenally, or the Set_z_U_NonConst - * method was used. */ - SmartPtr z_U_NonConst() - { - return GetNonConstIterateFromComp(5); - } - - /** Create a new vector in the z_U entry */ - inline - SmartPtr create_new_z_U(); - - /** Create a new vector in the z_U entry and copy the current - * values into it. */ - SmartPtr create_new_z_U_copy() - { - SmartPtr curr_z_U = GetComp(5); - Set_z_U_NonConst(*curr_z_U->MakeNew()); - z_U_NonConst()->Copy(*curr_z_U); - return z_U_NonConst(); - } - - /** Set the z_U iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_z_U(const Vector& vec) - { - SetComp(5, vec); - } - - /** Set the z_U iterate (non-const). Sets the pointer, does NOT - * copy data. */ - void Set_z_U_NonConst(Vector& vec) - { - SetCompNonConst(5, vec); - } - - /** Get the v_L iterate (const) */ - SmartPtr v_L() const - { - return GetIterateFromComp(6); - } - - /** Get the v_L iterate (non-const) - this can only be called if - * the vector was created intenally, or the Set_v_L_NonConst - * method was used. */ - SmartPtr v_L_NonConst() - { - return GetNonConstIterateFromComp(6); - } - - /** Create a new vector in the v_L entry */ - inline - SmartPtr create_new_v_L(); - - /** Create a new vector in the v_L entry and copy the current - * values into it. */ - SmartPtr create_new_v_L_copy() - { - SmartPtr curr_v_L = GetComp(6); - Set_v_L_NonConst(*curr_v_L->MakeNew()); - v_L_NonConst()->Copy(*curr_v_L); - return v_L_NonConst(); - } - - /** Set the v_L iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_v_L(const Vector& vec) - { - SetComp(6, vec); - } - - /** Set the v_L iterate (non-const). Sets the pointer, does NOT - * copy data. */ - void Set_v_L_NonConst(Vector& vec) - { - SetCompNonConst(6, vec); - } - - /** Get the v_U iterate (const) */ - SmartPtr v_U() const - { - return GetIterateFromComp(7); - } - - /** Get the v_U iterate (non-const) - this can only be called if - * the vector was created intenally, or the Set_v_U_NonConst - * method was used. */ - SmartPtr v_U_NonConst() - { - return GetNonConstIterateFromComp(7); - } - - /** Create a new vector in the v_U entry */ - inline - SmartPtr create_new_v_U(); - - /** Create a new vector in the v_U entry and copy the current - * values into it. */ - SmartPtr create_new_v_U_copy() - { - SmartPtr curr_v_U = GetComp(7); - Set_v_U_NonConst(*curr_v_U->MakeNew()); - v_U_NonConst()->Copy(*curr_v_U); - return v_U_NonConst(); - } - - /** Set the v_U iterate (const). Sets the pointer, does NOT copy - * data. */ - void Set_v_U(const Vector& vec) - { - SetComp(7, vec); - } - - /** Set the v_U iterate (non-const). Sets the pointer, does NOT - * copy data. */ - void Set_v_U_NonConst(Vector& vec) - { - SetCompNonConst(7, vec); - } - - /** Set the primal variables all in one shot. Sets the pointers, - * does NOT copy data */ - void Set_primal(const Vector& x, const Vector& s) - { - SetComp(0, x); - SetComp(1, s); - } - void Set_primal_NonConst(Vector& x, Vector& s) - { - SetCompNonConst(0, x); - SetCompNonConst(1, s); - } - - /** Set the eq multipliers all in one shot. Sets the pointers, - * does not copy data. */ - void Set_eq_mult(const Vector& y_c, const Vector& y_d) - { - SetComp(2, y_c); - SetComp(3, y_d); - } - void Set_eq_mult_NonConst(Vector& y_c, Vector& y_d) - { - SetCompNonConst(2, y_c); - SetCompNonConst(3, y_d); - } - - /** Set the bound multipliers all in one shot. Sets the pointers, - * does not copy data. */ - void Set_bound_mult(const Vector& z_L, const Vector& z_U, const Vector& v_L, const Vector& v_U) - { - SetComp(4, z_L); - SetComp(5, z_U); - SetComp(6, v_L); - SetComp(7, v_U); - } - void Set_bound_mult_NonConst(Vector& z_L, Vector& z_U, Vector& v_L, Vector& v_U) - { - SetCompNonConst(4, z_L); - SetCompNonConst(5, z_U); - SetCompNonConst(6, v_L); - SetCompNonConst(7, v_U); - } - - /** Get a sum of the tags of the contained items. There is no - * guarantee that this is unique, but there is a high chance it - * is unique and it can be used for debug checks relatively - * reliably. - */ - TaggedObject::Tag GetTagSum() const - { - TaggedObject::Tag tag = 0; - - if (IsValid(x())) { - tag += x()->GetTag(); - } - if (IsValid(s())) { - tag += s()->GetTag(); - } - if (IsValid(y_c())) { - tag += y_c()->GetTag(); - } - if (IsValid(y_d())) { - tag += y_d()->GetTag(); - } - if (IsValid(z_L())) { - tag += z_L()->GetTag(); - } - if (IsValid(z_U())) { - tag += z_U()->GetTag(); - } - if (IsValid(v_L())) { - tag += v_L()->GetTag(); - } - if (IsValid(v_U())) { - tag += v_U()->GetTag(); - } - - return tag; - } - //@} - - private: - /**@name Default Compiler Generated Methods (Hidden to avoid - * implicit creation/calling). These methods are not implemented - * and we do not want the compiler to implement them for us, so we - * declare them private and do not define them. This ensures that - * they will not be implicitly created/called. - */ - //@{ - /** Default Constructor */ - IteratesVector(); - - /** Copy Constructor */ - IteratesVector(const IteratesVector&); - - /** Overloaded Equals Operator */ - void operator=(const IteratesVector&); - //@} - - const IteratesVectorSpace* owner_space_; - - /** private method to return the const element from the compound - * vector. This method will return NULL if none is currently - * set. - */ - SmartPtr GetIterateFromComp(Index i) const - { - if (IsCompNull(i)) { - return NULL; - } - return GetComp(i); - } - - /** private method to return the non-const element from the - * compound vector. This method will return NULL if none is - * currently set. - */ - SmartPtr GetNonConstIterateFromComp(Index i) - { - if (IsCompNull(i)) { - return NULL; - } - return GetCompNonConst(i); - } - - }; - - /** Vector Space for the IteratesVector class. This is a - * specialized vector space for the IteratesVector class. - */ - class IteratesVectorSpace : public CompoundVectorSpace - { - public: - /** @name Constructors/Destructors. */ - //@{ - /** Constructor that takes the spaces for each of the iterates. - * Warning! None of these can be NULL ! - */ - IteratesVectorSpace(const VectorSpace& x_space, const VectorSpace& s_space, - const VectorSpace& y_c_space, const VectorSpace& y_d_space, - const VectorSpace& z_L_space, const VectorSpace& z_U_space, - const VectorSpace& v_L_space, const VectorSpace& v_U_space - ); - - virtual ~IteratesVectorSpace(); - //@} - - /** Method for creating vectors . */ - //@{ - /** Use this to create a new IteratesVector. You can pass-in - * create_new = false if you only want a container and do not - * want vectors allocated. - */ - virtual IteratesVector* MakeNewIteratesVector(bool create_new = true) const - { - return new IteratesVector(this, create_new); - } - - /** Use this method to create a new const IteratesVector. You must pass in - * valid pointers for all of the entries. - */ - const SmartPtr MakeNewIteratesVector(const Vector& x, const Vector& s, - const Vector& y_c, const Vector& y_d, - const Vector& z_L, const Vector& z_U, - const Vector& v_L, const Vector& v_U) - { - SmartPtr newvec = MakeNewIteratesVector(false); - newvec->Set_x(x); - newvec->Set_s(s); - newvec->Set_y_c(y_c); - newvec->Set_y_d(y_d); - newvec->Set_z_L(z_L); - newvec->Set_z_U(z_U); - newvec->Set_v_L(v_L); - newvec->Set_v_U(v_U); - return ConstPtr(newvec); - } - - - /** This method overloads - * ComooundVectorSpace::MakeNewCompoundVector to make sure that - * we get a vector of the correct type - */ - virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const - { - return MakeNewIteratesVector(create_new); - } - - /** This method creates a new vector (and allocates space in all - * the contained vectors. This is really only used for code that - * does not know what type of vector it is dealing with - for - * example, this method is called from Vector::MakeNew() - */ - virtual Vector* MakeNew() const - { - return MakeNewIteratesVector(); - } - //@} - - /** This method hides the CompoundVectorSpace::SetCompSpace method - * since the components of the Iterates are fixed at - * construction. - */ - virtual void SetCompSpace(Index icomp, const VectorSpace& vec_space) - { - DBG_ASSERT(false && "This is an IteratesVectorSpace - a special compound vector for Ipopt iterates. The contained spaces should not be modified."); - } - - private: - /**@name Default Compiler Generated Methods (Hidden to avoid - * implicit creation/calling). These methods are not implemented - * and we do not want the compiler to implement them for us, so we - * declare them private and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default constructor */ - IteratesVectorSpace(); - - /** Copy Constructor */ - IteratesVectorSpace(const IteratesVectorSpace&); - - /** Overloaded Equals Operator */ - IteratesVectorSpace& operator=(const IteratesVectorSpace&); - //@} - - /** Contained Spaces */ - SmartPtr x_space_; - SmartPtr s_space_; - SmartPtr y_c_space_; - SmartPtr y_d_space_; - SmartPtr z_L_space_; - SmartPtr z_U_space_; - SmartPtr v_L_space_; - SmartPtr v_U_space_; - }; - - - inline - SmartPtr IteratesVector::create_new_x() - { - Set_x_NonConst(*owner_space_->GetCompSpace(0)->MakeNew()); - return x_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_s() - { - Set_s_NonConst(*owner_space_->GetCompSpace(1)->MakeNew()); - return s_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_y_c() - { - Set_y_c_NonConst(*owner_space_->GetCompSpace(2)->MakeNew()); - return y_c_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_y_d() - { - Set_y_d_NonConst(*owner_space_->GetCompSpace(3)->MakeNew()); - return y_d_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_z_L() - { - Set_z_L_NonConst(*owner_space_->GetCompSpace(4)->MakeNew()); - return z_L_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_z_U() - { - Set_z_U_NonConst(*owner_space_->GetCompSpace(5)->MakeNew()); - return z_U_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_v_L() - { - Set_v_L_NonConst(*owner_space_->GetCompSpace(6)->MakeNew()); - return v_L_NonConst(); - } - inline - SmartPtr IteratesVector::create_new_v_U() - { - Set_v_U_NonConst(*owner_space_->GetCompSpace(7)->MakeNew()); - return v_U_NonConst(); - } -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpIterationOutput.hpp b/external/ipopt/include/coin/IpIterationOutput.hpp deleted file mode 100644 index 95fd6508a..000000000 --- a/external/ipopt/include/coin/IpIterationOutput.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2004, 2011 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpIterationOutput.hpp 2020 2011-06-16 20:46:16Z andreasw $ -// -// Authors: Andreas Waechter, Carl Laird IBM 2004-09-27 - -#ifndef __IPITERATIONOUTPUT_HPP__ -#define __IPITERATIONOUTPUT_HPP__ - -#include "IpAlgStrategy.hpp" -#include "IpIpoptNLP.hpp" -#include "IpIpoptData.hpp" -#include "IpIpoptCalculatedQuantities.hpp" - -namespace Ipopt -{ - - /** Base class for objects that do the output summary per iteration. - */ - class IterationOutput: public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - IterationOutput() - {} - - /** Default destructor */ - virtual ~IterationOutput() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Method to do all the summary output per iteration. This - * include the one-line summary output as well as writing the - * details about the iterates if desired */ - virtual void WriteOutput() = 0; - - protected: - /** enumeration for different inf_pr output options */ - enum InfPrOutput - { - INTERNAL=0, - ORIGINAL - }; - - private: - /**@name Default Compiler Generated Methods (Hidden to avoid - * implicit creation/calling). These methods are not implemented - * and we do not want the compiler to implement them for us, so we - * declare them private and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - IterationOutput(const IterationOutput&); - - /** Overloaded Equals Operator */ - void operator=(const IterationOutput&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpJournalist.hpp b/external/ipopt/include/coin/IpJournalist.hpp deleted file mode 100644 index 266130a01..000000000 --- a/external/ipopt/include/coin/IpJournalist.hpp +++ /dev/null @@ -1,497 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpJournalist.hpp 2204 2013-04-13 13:49:26Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPJOURNALIST_HPP__ -#define __IPJOURNALIST_HPP__ - -#include "IpoptConfig.h" -#include "IpTypes.hpp" -#include "IpReferenced.hpp" -#include "IpSmartPtr.hpp" - -#ifdef HAVE_CSTDARG -# include -#else -# ifdef HAVE_STDARG_H -# include -# else -# include // if this header is included by someone who does not define HAVE_CSTDARG or HAVE_STDARG, let's hope that cstdarg is available -# endif -#endif - -#ifdef HAVE_CSTDIO -# include -#else -# ifdef HAVE_STDIO_H -# include -# else -# include // if this header is included by someone who does not define HAVE_CSTDIO or HAVE_STDIO, let's hope that cstdio is available -# endif -#endif - -#include -#include -#include - -namespace Ipopt -{ - - // forward declarations - class Journal; - class FileJournal; - - /**@name Journalist Enumerations. */ - //@{ - /** Print Level Enum. */ - enum EJournalLevel { - J_INSUPPRESSIBLE=-1, - J_NONE=0, - J_ERROR, - J_STRONGWARNING, - J_SUMMARY, - J_WARNING, - J_ITERSUMMARY, - J_DETAILED, - J_MOREDETAILED, - J_VECTOR, - J_MOREVECTOR, - J_MATRIX, - J_MOREMATRIX, - J_ALL, - J_LAST_LEVEL - }; - - /** Category Selection Enum. */ - enum EJournalCategory { - J_DBG=0, - J_STATISTICS, - J_MAIN, - J_INITIALIZATION, - J_BARRIER_UPDATE, - J_SOLVE_PD_SYSTEM, - J_FRAC_TO_BOUND, - J_LINEAR_ALGEBRA, - J_LINE_SEARCH, - J_HESSIAN_APPROXIMATION, - J_SOLUTION, - J_DOCUMENTATION, - J_NLP, - J_TIMING_STATISTICS, - J_USER_APPLICATION /** This can be used by the user's application*/ , - J_USER1 /** This can be used by the user's application*/ , - J_USER2 /** This can be used by the user's application*/ , - J_USER3 /** This can be used by the user's application*/ , - J_USER4 /** This can be used by the user's application*/ , - J_USER5 /** This can be used by the user's application*/ , - J_USER6 /** This can be used by the user's application*/ , - J_USER7 /** This can be used by the user's application*/ , - J_USER8 /** This can be used by the user's application*/ , - J_USER9 /** This can be used by the user's application*/ , - J_USER10 /** This can be used by the user's application*/ , - J_USER11 /** This can be used by the user's application*/ , - J_USER12 /** This can be used by the user's application*/ , - J_USER13 /** This can be used by the user's application*/ , - J_USER14 /** This can be used by the user's application*/ , - J_USER15 /** This can be used by the user's application*/ , - J_USER16 /** This can be used by the user's application*/ , - J_USER17 /** This can be used by the user's application*/ , - J_LAST_CATEGORY - }; - //@} - - /** Class responsible for all message output. - * This class is responsible for all messaging and output. - * The "printing" code or "author" should send ALL messages to the - * Journalist, indicating an appropriate category and print level. - * The journalist then decides, based on reader specified - * acceptance criteria, which message is actually printed in which - * journals. - * This allows the printing code to send everything, while the - * "reader" can decide what they really want to see. - * - * Authors: - * Authors use the - * Journals: You can add as many Journals as you like to the - * Journalist with the AddJournal or the AddFileJournal methods. - * Each one represents a different printing location (or file). - * Then, you can call the "print" methods of the Journalist to output - * information to each of the journals. - * - * Acceptance Criteria: Each print message should be flagged - * appropriately with an EJournalCategory and EJournalLevel. - * - * The AddFileJournal - * method returns a pointer to the newly created Journal object - * (if successful) so you can set Acceptance criteria for that - * particular location. - * - */ - class Journalist : public ReferencedObject - { - public: - /**@name Constructor / Desructor. */ - //@{ - /** Constructor. */ - Journalist(); - - /** Destructor... */ - virtual ~Journalist(); - //@} - - /**@name Author Methods. - * These methods are used by authoring code, or code that wants - * to report some information. - */ - //@{ - /** Method to print a formatted string */ - virtual void Printf(EJournalLevel level, EJournalCategory category, - const char* format, ...) const; - - /** Method to print a long string including indentation. The - * string is printed starting at the current position. If the - * position (counting started at the current position) exceeds - * max_length, a new line is inserted, and indent_spaces many - * spaces are printed before the string is continued. This is - * for example used during the printing of the option - * documentation. */ - virtual void PrintStringOverLines(EJournalLevel level, EJournalCategory category, - Index indent_spaces, Index max_length, - const std::string& line) const; - - /** Method to print a formatted string with indentation */ - virtual void PrintfIndented(EJournalLevel level, - EJournalCategory category, - Index indent_level, - const char* format, ...) const; - - /** Method to print a formatted string - * using the va_list argument. */ - virtual void VPrintf(EJournalLevel level, - EJournalCategory category, - const char* pformat, - va_list ap) const; - - /** Method to print a formatted string with indentation, - * using the va_list argument. */ - virtual void VPrintfIndented(EJournalLevel level, - EJournalCategory category, - Index indent_level, - const char* pformat, - va_list ap) const; - - /** Method that returns true if there is a Journal that would - * write output for the given JournalLevel and JournalCategory. - * This is useful if expensive computation would be required for - * a particular output. The author code can check with this - * method if the computations are indeed required. - */ - virtual bool ProduceOutput(EJournalLevel level, - EJournalCategory category) const; - - - /** Method that flushes the current buffer for all Journalists. - Calling this method after one optimization run helps to avoid - cluttering output with that produced by other parts of the - program (e.g. written in Fortran) */ - virtual void FlushBuffer() const; - //@} - - /**@name Reader Methods. - * These methods are used by the reader. The reader will setup the - * journalist with each output file and the acceptance - * criteria for that file. - * - * Use these methods to setup the journals (files or other output). - * These are the internal objects that keep track of the print levels - * for each category. Then use the internal Journal objects to - * set specific print levels for each category (or keep defaults). - * - */ - //@{ - /** Add a new journal. The location_name is a string identifier, - * which can be used to obtain the pointer to the new Journal at - * a later point using the GetJournal method. - * The default_level is - * used to initialize the * printing level for all categories. - */ - virtual bool AddJournal(const SmartPtr jrnl); - - /** Add a new FileJournal. fname is the name - * of the * file to which this Journal corresponds. Use - * fname="stdout" * for stdout, and use fname="stderr" for - * stderr. This method * returns the Journal pointer so you can - * set specific acceptance criteria. It returns NULL if there - * was a problem creating a new Journal. - */ - virtual SmartPtr AddFileJournal( - const std::string& location_name, /**< journal identifier */ - const std::string& fname, /**< file name */ - EJournalLevel default_level = J_WARNING /**< default journal level */ - ); - - /** Get an existing journal. You can use this method to change - * the acceptance criteria at runtime. - */ - virtual SmartPtr GetJournal(const std::string& location_name); - - /** Delete all journals curently known by the journalist. */ - virtual void DeleteAllJournals(); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - Journalist(const Journalist&); - - /** Overloaded Equals Operator */ - void operator=(const Journalist&); - //@} - - //** Private Data Members. */ - //@{ - std::vector< SmartPtr > journals_; - //@} - }; - - /** Journal class (part of the Journalist implementation.). This - * class is the base class for all Journals. It controls the - * acceptance criteria for print statements etc. Derived classes - * like the FileJournal - output those messages to specific locations - */ - class Journal : public ReferencedObject - { - public: - /** Constructor. */ - Journal(const std::string& name, EJournalLevel default_level); - - /** Destructor. */ - virtual ~Journal(); - - /** Get the name of the Journal */ - virtual std::string Name(); - - /** Set the print level for a particular category. */ - virtual void SetPrintLevel( - EJournalCategory category, EJournalLevel level - ); - - /** Set the print level for all category. */ - virtual void SetAllPrintLevels( - EJournalLevel level - ); - - /**@name Journal Output Methods. These methods are called by the - * Journalist who first checks if the output print level and category - * are acceptable. - * Calling the Print methods explicitly (instead of through the - * Journalist will output the message regardless of print level - * and category. You should use the Journalist to print & flush instead - */ - //@{ - /** Ask if a particular print level/category is accepted by the - * journal. - */ - virtual bool IsAccepted( - EJournalCategory category, EJournalLevel level - ) const; - - /** Print to the designated output location */ - virtual void Print(EJournalCategory category, EJournalLevel level, - const char* str) - { - PrintImpl(category, level, str); - } - - /** Printf to the designated output location */ - virtual void Printf(EJournalCategory category, EJournalLevel level, - const char* pformat, va_list ap) - { - PrintfImpl(category, level, pformat, ap); - } - - /** Flush output buffer.*/ - virtual void FlushBuffer() - { - FlushBufferImpl(); - } - //@} - - protected: - /**@name Implementation version of Print methods. Derived classes - * should overload the Impl methods. - */ - //@{ - /** Print to the designated output location */ - virtual void PrintImpl(EJournalCategory category, EJournalLevel level, - const char* str)=0; - - /** Printf to the designated output location */ - virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, - const char* pformat, va_list ap)=0; - - /** Flush output buffer.*/ - virtual void FlushBufferImpl()=0; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - Journal(); - - /** Copy Constructor */ - Journal(const Journal&); - - /** Overloaded Equals Operator */ - void operator=(const Journal&); - //@} - - /** Name of the output location */ - std::string name_; - - /** vector of integers indicating the level for each category */ - Index print_levels_[J_LAST_CATEGORY]; - }; - - - /** FileJournal class. This is a particular Journal implementation that - * writes to a file for output. It can write to (stdout, stderr, or disk) - * by using "stdout" and "stderr" as filenames. - */ - class FileJournal : public Journal - { - public: - /** Constructor. */ - FileJournal(const std::string& name, EJournalLevel default_level); - - /** Destructor. */ - virtual ~FileJournal(); - - /** Open a new file for the output location. - * Special Names: stdout means stdout, - * : stderr means stderr. - * - * Return code is false only if the file with the given name - * could not be opened. - */ - virtual bool Open(const char* fname); - - protected: - /**@name Implementation version of Print methods - Overloaded from - * Journal base class. - */ - //@{ - /** Print to the designated output location */ - virtual void PrintImpl(EJournalCategory category, EJournalLevel level, - const char* str); - - /** Printf to the designated output location */ - virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, - const char* pformat, va_list ap); - - /** Flush output buffer.*/ - virtual void FlushBufferImpl(); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - FileJournal(); - - /** Copy Constructor */ - FileJournal(const FileJournal&); - - /** Overloaded Equals Operator */ - void operator=(const FileJournal&); - //@} - - /** FILE pointer for the output destination */ - FILE* file_; - }; - - /** StreamJournal class. This is a particular Journal implementation that - * writes to a stream for output. - */ - class StreamJournal : public Journal - { - public: - /** Constructor. */ - StreamJournal(const std::string& name, EJournalLevel default_level); - - /** Destructor. */ - virtual ~StreamJournal() - {} - - /** Setting the output stream pointer */ - void SetOutputStream(std::ostream* os); - - protected: - /**@name Implementation version of Print methods - Overloaded from - * Journal base class. - */ - //@{ - /** Print to the designated output location */ - virtual void PrintImpl(EJournalCategory category, EJournalLevel level, - const char* str); - - /** Printf to the designated output location */ - virtual void PrintfImpl(EJournalCategory category, EJournalLevel level, - const char* pformat, va_list ap); - - /** Flush output buffer.*/ - virtual void FlushBufferImpl(); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - StreamJournal(); - - /** Copy Constructor */ - StreamJournal(const StreamJournal&); - - /** Overloaded Equals Operator */ - void operator=(const StreamJournal&); - //@} - - /** pointer to output stream for the output destination */ - std::ostream* os_; - - /** buffer for sprintf. Being generous in size here... */ - char buffer_[32768]; - }; -} - -#endif diff --git a/external/ipopt/include/coin/IpLapack.hpp b/external/ipopt/include/coin/IpLapack.hpp deleted file mode 100644 index ef8883cc2..000000000 --- a/external/ipopt/include/coin/IpLapack.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2005, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpLapack.hpp 2449 2013-12-16 00:25:42Z ghackebeil $ -// -// Authors: Andreas Waechter IBM 2005-12-25 - -#ifndef __IPLAPACK_HPP__ -#define __IPLAPACK_HPP__ - -#include "IpUtils.hpp" -#include "IpException.hpp" - -namespace Ipopt -{ - DECLARE_STD_EXCEPTION(LAPACK_NOT_INCLUDED); - - /** Wrapper for LAPACK subroutine DPOTRS. Solving a linear system - * given a Cholesky factorization. We assume that the Cholesky - * factor is lower traiangular. */ - void IpLapackDpotrs(Index ndim, Index nrhs, const Number *a, Index lda, - Number *b, Index ldb); - - /** Wrapper for LAPACK subroutine DPOTRF. Compute Cholesky - * factorization (lower triangular factor). info is the return - * value from the LAPACK routine. */ - void IpLapackDpotrf(Index ndim, Number *a, Index lda, Index& info); - - /** Wrapper for LAPACK subroutine DSYEV. Compute the Eigenvalue - * decomposition for a given matrix. If compute_eigenvectors is - * true, a will contain the eigenvectors in its columns on - * return. */ - void IpLapackDsyev(bool compute_eigenvectors, Index ndim, Number *a, - Index lda, Number *w, Index& info); - - /** Wrapper for LAPACK subroutine DGETRF. Compute LU factorization. - * info is the return value from the LAPACK routine. */ - void IpLapackDgetrf(Index ndim, Number *a, Index* pivot, Index lda, - Index& info); - - /** Wrapper for LAPACK subroutine DGETRS. Solving a linear system - * given a LU factorization. */ - void IpLapackDgetrs(Index ndim, Index nrhs, const Number *a, Index lda, - Index* ipiv, Number *b, Index ldb); - - /** Wrapper for LAPACK subroutine DPPSV. Solves a symmetric positive - * definite linear system in packed storage format (upper triangular). - * info is the return value from the LAPACK routine. */ - void IpLapackDppsv(Index ndim, Index nrhs, const Number *a, - Number *b, Index ldb, Index& info); - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpLineSearch.hpp b/external/ipopt/include/coin/IpLineSearch.hpp deleted file mode 100644 index 70c11f162..000000000 --- a/external/ipopt/include/coin/IpLineSearch.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpLineSearch.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPLINESEARCH_HPP__ -#define __IPLINESEARCH_HPP__ - -#include "IpAlgStrategy.hpp" -#include "IpIpoptCalculatedQuantities.hpp" - -namespace Ipopt -{ - - /** Base class for line search objects. - */ - class LineSearch : public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - LineSearch() - {} - - /** Default destructor */ - virtual ~LineSearch() - {} - //@} - - /** Perform the line search. As search direction the delta - * in the data object is used - */ - virtual void FindAcceptableTrialPoint() = 0; - - /** Reset the line search. - * This function should be called if all previous information - * should be discarded when the line search is performed the - * next time. For example, this method should be called after - * the barrier parameter is changed. - */ - virtual void Reset() = 0; - - /** Set flag indicating whether a very rigorous line search should - * be performed. If this flag is set to true, the line search - * algorithm might decide to abort the line search and not to - * accept a new iterate. If the line search decided not to - * accept a new iterate, the return value of - * CheckSkippedLineSearch() is true at the next call. For - * example, in the non-monotone barrier parameter update - * procedure, the filter algorithm should not switch to the - * restoration phase in the free mode; instead, the algorithm - * should swtich to the fixed mode. - */ - virtual void SetRigorousLineSearch(bool rigorous) = 0; - - /** Check if the line search procedure didn't accept a new iterate - * during the last call of FindAcceptableTrialPoint(). - * - */ - virtual bool CheckSkippedLineSearch() = 0; - - /** This method should be called if the optimization process - * requires the line search object to switch to some fallback - * mechanism (like the restoration phase), when the regular - * optimization procedure cannot be continued (for example, - * because the search direction could not be computed). This - * will cause the line search object to immediately proceed with - * this mechanism when FindAcceptableTrialPoint() is call. This - * method returns false if no fallback mechanism is available. */ - virtual bool ActivateFallbackMechanism() = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - LineSearch(const LineSearch&); - - /** Overloaded Equals Operator */ - void operator=(const LineSearch&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpMatrix.hpp b/external/ipopt/include/coin/IpMatrix.hpp deleted file mode 100644 index 79018da8e..000000000 --- a/external/ipopt/include/coin/IpMatrix.hpp +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpMatrix.hpp 2472 2014-04-05 17:47:20Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPMATRIX_HPP__ -#define __IPMATRIX_HPP__ - -#include "IpVector.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class MatrixSpace; - - /** Matrix Base Class. This is the base class for all derived matrix - * types. All Matrices, such as Jacobian and Hessian matrices, as - * well as possibly the iteration matrices needed for the step - * computation, are of this type. - * - * Deriving from Matrix: Overload the protected XXX_Impl method. - */ - class Matrix : public TaggedObject - { - public: - /** @name Constructor/Destructor */ - //@{ - /** Constructor. It has to be given a pointer to the - * corresponding MatrixSpace. - */ - Matrix(const MatrixSpace* owner_space) - : - TaggedObject(), - owner_space_(owner_space), - valid_cache_tag_(0) - {} - - /** Destructor */ - virtual ~Matrix() - {} - //@} - - /**@name Operations of the Matrix on a Vector */ - //@{ - /** Matrix-vector multiply. Computes y = alpha * Matrix * x + - * beta * y. Do not overload. Overload MultVectorImpl instead. - */ - void MultVector(Number alpha, const Vector& x, Number beta, - Vector& y) const - { - MultVectorImpl(alpha, x, beta, y); - } - - /** Matrix(transpose) vector multiply. Computes y = alpha * - * Matrix^T * x + beta * y. Do not overload. Overload - * TransMultVectorImpl instead. - */ - void TransMultVector(Number alpha, const Vector& x, Number beta, - Vector& y) const - { - TransMultVectorImpl(alpha, x, beta, y); - } - //@} - - /** @name Methods for specialized operations. A prototype - * implementation is provided, but for efficient implementation - * those should be specially implemented. - */ - //@{ - /** X = X + alpha*(Matrix S^{-1} Z). Should be implemented - * efficiently for the ExansionMatrix - */ - void AddMSinvZ(Number alpha, const Vector& S, const Vector& Z, - Vector& X) const; - - /** X = S^{-1} (r + alpha*Z*M^Td). Should be implemented - * efficiently for the ExansionMatrix - */ - void SinvBlrmZMTdBr(Number alpha, const Vector& S, - const Vector& R, const Vector& Z, - const Vector& D, Vector& X) const; - //@} - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - bool HasValidNumbers() const; - - /** @name Information about the size of the matrix */ - //@{ - /** Number of rows */ - inline - Index NRows() const; - - /** Number of columns */ - inline - Index NCols() const; - //@} - - /** @name Norms of the individual rows and columns */ - //@{ - /** Compute the max-norm of the rows in the matrix. The result is - * stored in rows_norms. The vector is assumed to be initialized - * of init is false. */ - void ComputeRowAMax(Vector& rows_norms, bool init=true) const - { - DBG_ASSERT(NRows() == rows_norms.Dim()); - if (init) rows_norms.Set(0.); - ComputeRowAMaxImpl(rows_norms, init); - } - /** Compute the max-norm of the columns in the matrix. The result - * is stored in cols_norms The vector is assumed to be initialized - * of init is false. */ - void ComputeColAMax(Vector& cols_norms, bool init=true) const - { - DBG_ASSERT(NCols() == cols_norms.Dim()); - if (init) cols_norms.Set(0.); - ComputeColAMaxImpl(cols_norms, init); - } - //@} - - /** Print detailed information about the matrix. Do not overload. - * Overload PrintImpl instead. - */ - //@{ - virtual void Print(SmartPtr jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent=0, - const std::string& prefix="") const; - virtual void Print(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent=0, - const std::string& prefix="") const; - //@} - - /** Return the owner MatrixSpace*/ - inline - SmartPtr OwnerSpace() const; - - protected: - /** @name implementation methods (derived classes MUST - * overload these pure virtual protected methods. - */ - //@{ - /** Matrix-vector multiply. Computes y = alpha * Matrix * x + - * beta * y - */ - virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0; - - /** Matrix(transpose) vector multiply. - * Computes y = alpha * Matrix^T * x + beta * y - */ - virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, Vector& y) const =0; - - /** X = X + alpha*(Matrix S^{-1} Z). Prototype for this - * specialize method is provided, but for efficient - * implementation it should be overloaded for the expansion matrix. - */ - virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z, - Vector& X) const; - - /** X = S^{-1} (r + alpha*Z*M^Td). Should be implemented - * efficiently for the ExpansionMatrix. - */ - virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S, - const Vector& R, const Vector& Z, - const Vector& D, Vector& X) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). A default implementation always returning true - * is provided, but if possible it should be implemented. */ - virtual bool HasValidNumbersImpl() const - { - return true; - } - - /** Compute the max-norm of the rows in the matrix. The result is - * stored in rows_norms. The vector is assumed to be - * initialized. */ - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const = 0; - /** Compute the max-norm of the columns in the matrix. The result - * is stored in cols_norms. The vector is assumed to be - * initialized. */ - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const = 0; - - /** Print detailed information about the matrix. */ - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const =0; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** default constructor */ - Matrix(); - - /** Copy constructor */ - Matrix(const Matrix&); - - /** Overloaded Equals Operator */ - Matrix& operator=(const Matrix&); - //@} - - const SmartPtr owner_space_; - - /**@name CachedResults data members */ - //@{ - mutable TaggedObject::Tag valid_cache_tag_; - mutable bool cached_valid_; - //@} - }; - - - /** MatrixSpace base class, corresponding to the Matrix base class. - * For each Matrix implementation, a corresponding MatrixSpace has - * to be implemented. A MatrixSpace is able to create new Matrices - * of a specific type. The MatrixSpace should also store - * information that is common to all Matrices of that type. For - * example, the dimensions of a Matrix is stored in the MatrixSpace - * base class. - */ - class MatrixSpace : public ReferencedObject - { - public: - /** @name Constructors/Destructors */ - //@{ - /** Constructor, given the number rows and columns of all matrices - * generated by this MatrixSpace. - */ - MatrixSpace(Index nRows, Index nCols) - : - nRows_(nRows), - nCols_(nCols) - {} - - /** Destructor */ - virtual ~MatrixSpace() - {} - //@} - - /** Pure virtual method for creating a new Matrix of the - * corresponding type. - */ - virtual Matrix* MakeNew() const=0; - - /** Accessor function for the number of rows. */ - Index NRows() const - { - return nRows_; - } - /** Accessor function for the number of columns. */ - Index NCols() const - { - return nCols_; - } - - /** Method to test if a given matrix belongs to a particular - * matrix space. - */ - bool IsMatrixFromSpace(const Matrix& matrix) const - { - return (matrix.OwnerSpace() == this); - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** default constructor */ - MatrixSpace(); - - /** Copy constructor */ - MatrixSpace(const MatrixSpace&); - - /** Overloaded Equals Operator */ - MatrixSpace& operator=(const MatrixSpace&); - //@} - - /** Number of rows for all matrices of this type. */ - const Index nRows_; - /** Number of columns for all matrices of this type. */ - const Index nCols_; - }; - - - /* Inline Methods */ - inline - Index Matrix::NRows() const - { - return owner_space_->NRows(); - } - - inline - Index Matrix::NCols() const - { - return owner_space_->NCols(); - } - - inline - SmartPtr Matrix::OwnerSpace() const - { - return owner_space_; - } - -} // namespace Ipopt - -// Macro definitions for debugging matrices -#if COIN_IPOPT_VERBOSITY == 0 -# define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) -#else -# define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat) \ - if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \ - if (dbg_jrnl.Jnlst()!=NULL) { \ - (__mat).Print(dbg_jrnl.Jnlst(), \ - J_ERROR, J_DBG, \ - __mat_name, \ - dbg_jrnl.IndentationLevel()*2, \ - "# "); \ - } \ - } -#endif // #if COIN_IPOPT_VERBOSITY == 0 - -#endif diff --git a/external/ipopt/include/coin/IpMuUpdate.hpp b/external/ipopt/include/coin/IpMuUpdate.hpp deleted file mode 100644 index b6c1d9c1c..000000000 --- a/external/ipopt/include/coin/IpMuUpdate.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpMuUpdate.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPMUUPDATE_HPP__ -#define __IPMUUPDATE_HPP__ - -#include "IpAlgStrategy.hpp" - -namespace Ipopt -{ - /** Abstract Base Class for classes that implement methods for computing - * the barrier and fraction-to-the-boundary rule parameter for the - * current iteration. - */ - class MuUpdate : public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - MuUpdate() - {} - - /** Default destructor */ - virtual ~MuUpdate() - {} - //@} - - /** Initialize method - overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Method for determining the barrier parameter for the next - * iteration. A LineSearch object is passed, so that this method - * can call the Reset method in the LineSearch object, for - * example when then barrier parameter is changed. This method is - * also responsible for setting the fraction-to-the-boundary - * parameter tau. This method returns false if the update could - * not be performed and the algorithm should revert to an - * emergency fallback mechanism. */ - virtual bool UpdateBarrierParameter() = 0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - - /** Copy Constructor */ - MuUpdate(const MuUpdate&); - - /** Overloaded Equals Operator */ - void operator=(const MuUpdate&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpNLP.hpp b/external/ipopt/include/coin/IpNLP.hpp deleted file mode 100644 index 1063c01b8..000000000 --- a/external/ipopt/include/coin/IpNLP.hpp +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpNLP.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPNLP_HPP__ -#define __IPNLP_HPP__ - -#include "IpUtils.hpp" -#include "IpVector.hpp" -#include "IpSmartPtr.hpp" -#include "IpMatrix.hpp" -#include "IpSymMatrix.hpp" -#include "IpOptionsList.hpp" -#include "IpAlgTypes.hpp" -#include "IpReturnCodes.hpp" - -namespace Ipopt -{ - // forward declarations - class IpoptData; - class IpoptCalculatedQuantities; - class IteratesVector; - - /** Brief Class Description. - * Detailed Class Description. - */ - class NLP : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor */ - NLP() - {} - - /** Default destructor */ - virtual ~NLP() - {} - //@} - - /** Exceptions */ - //@{ - DECLARE_STD_EXCEPTION(USER_SCALING_NOT_IMPLEMENTED); - DECLARE_STD_EXCEPTION(INVALID_NLP); - //@} - - /** @name NLP Initialization (overload in - * derived classes).*/ - //@{ - /** Overload if you want the chance to process options or parameters that - * may be specific to the NLP */ - virtual bool ProcessOptions(const OptionsList& options, - const std::string& prefix) - { - return true; - } - - /** Method for creating the derived vector / matrix types. The - * Hess_lagrangian_space pointer can be NULL if a quasi-Newton - * options is chosen. */ - virtual bool GetSpaces(SmartPtr& x_space, - SmartPtr& c_space, - SmartPtr& d_space, - SmartPtr& x_l_space, - SmartPtr& px_l_space, - SmartPtr& x_u_space, - SmartPtr& px_u_space, - SmartPtr& d_l_space, - SmartPtr& pd_l_space, - SmartPtr& d_u_space, - SmartPtr& pd_u_space, - SmartPtr& Jac_c_space, - SmartPtr& Jac_d_space, - SmartPtr& Hess_lagrangian_space)=0; - - /** Method for obtaining the bounds information */ - virtual bool GetBoundsInformation(const Matrix& Px_L, - Vector& x_L, - const Matrix& Px_U, - Vector& x_U, - const Matrix& Pd_L, - Vector& d_L, - const Matrix& Pd_U, - Vector& d_U)=0; - - /** Method for obtaining the starting point for all the - * iterates. ToDo it might not make sense to ask for initial - * values for v_L and v_U? */ - virtual bool GetStartingPoint( - SmartPtr x, - bool need_x, - SmartPtr y_c, - bool need_y_c, - SmartPtr y_d, - bool need_y_d, - SmartPtr z_L, - bool need_z_L, - SmartPtr z_U, - bool need_z_U - )=0; - - /** Method for obtaining an entire iterate as a warmstart point. - * The incoming IteratesVector has to be filled. The default - * dummy implementation returns false. */ - virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate) - { - return false; - } - //@} - - /** @name NLP evaluation routines (overload - * in derived classes. */ - //@{ - virtual bool Eval_f(const Vector& x, Number& f) = 0; - - virtual bool Eval_grad_f(const Vector& x, Vector& g_f) = 0; - - virtual bool Eval_c(const Vector& x, Vector& c) = 0; - - virtual bool Eval_jac_c(const Vector& x, Matrix& jac_c) = 0; - - virtual bool Eval_d(const Vector& x, Vector& d) = 0; - - virtual bool Eval_jac_d(const Vector& x, Matrix& jac_d) = 0; - - virtual bool Eval_h(const Vector& x, - Number obj_factor, - const Vector& yc, - const Vector& yd, - SymMatrix& h) = 0; - //@} - - /** @name NLP solution routines. Have default dummy - * implementations that can be overloaded. */ - //@{ - /** This method is called at the very end of the optimization. It - * provides the final iterate to the user, so that it can be - * stored as the solution. The status flag indicates the outcome - * of the optimization, where SolverReturn is defined in - * IpAlgTypes.hpp. */ - virtual void FinalizeSolution(SolverReturn status, - const Vector& x, const Vector& z_L, - const Vector& z_U, - const Vector& c, const Vector& d, - const Vector& y_c, const Vector& y_d, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq) - {} - - /** This method is called once per iteration, after the iteration - * summary output has been printed. It provides the current - * information to the user to do with it anything she wants. It - * also allows the user to ask for a premature termination of the - * optimization by returning false, in which case Ipopt will - * terminate with a corresponding return status. The basic - * information provided in the argument list has the quantities - * values printed in the iteration summary line. If more - * information is required, a user can obtain it from the IpData - * and IpCalculatedQuantities objects. However, note that the - * provided quantities are all for the problem that Ipopt sees, - * i.e., the quantities might be scaled, fixed variables might be - * sorted out, etc. The status indicates things like whether the - * algorithm is in the restoration phase... In the restoration - * phase, the dual variables are probably not not changing. */ - virtual bool IntermediateCallBack(AlgorithmMode mode, - Index iter, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq) - { - return true; - } - //@} - - /** Routines to get the scaling parameters. These do not need to - * be overloaded unless the options are set for User scaling - */ - //@{ - virtual void GetScalingParameters( - const SmartPtr x_space, - const SmartPtr c_space, - const SmartPtr d_space, - Number& obj_scaling, - SmartPtr& x_scaling, - SmartPtr& c_scaling, - SmartPtr& d_scaling) const - { - THROW_EXCEPTION(USER_SCALING_NOT_IMPLEMENTED, - "You have set options for user provided scaling, but have" - " not implemented GetScalingParameters in the NLP interface"); - } - //@} - - /** Method for obtaining the subspace in which the limited-memory - * Hessian approximation should be done. This is only called if - * the limited-memory Hessian approximation is chosen. Since the - * Hessian is zero in the space of all variables that appear in - * the problem functions only linearly, this allows the user to - * provide a VectorSpace for all nonlinear variables, and an - * ExpansionMatrix to lift from this VectorSpace to the - * VectorSpace of the primal variables x. If the returned values - * are NULL, it is assumed that the Hessian is to be approximated - * in the space of all x variables. The default instantiation of - * this method returns NULL, and a user only has to overwrite - * this method if the approximation is to be done only in a - * subspace. */ - virtual void - GetQuasiNewtonApproximationSpaces(SmartPtr& approx_space, - SmartPtr& P_approx) - { - approx_space = NULL; - P_approx = NULL; - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - NLP(const NLP&); - - /** Overloaded Equals Operator */ - void operator=(const NLP&); - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpNLPScaling.hpp b/external/ipopt/include/coin/IpNLPScaling.hpp deleted file mode 100644 index be5f13d4e..000000000 --- a/external/ipopt/include/coin/IpNLPScaling.hpp +++ /dev/null @@ -1,451 +0,0 @@ -// Copyright (C) 2004, 2007 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpNLPScaling.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPNLPSCALING_HPP__ -#define __IPNLPSCALING_HPP__ - -#include "IpOptionsList.hpp" -#include "IpRegOptions.hpp" - -namespace Ipopt -{ - // forward declarations - class Vector; - class VectorSpace; - class Matrix; - class MatrixSpace; - class SymMatrix; - class SymMatrixSpace; - class ScaledMatrixSpace; - class SymScaledMatrixSpace; - - /** This is the abstract base class for problem scaling. - * It is repsonsible for determining the scaling factors - * and mapping quantities in and out of scaled and unscaled - * versions - */ - class NLPScalingObject : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - NLPScalingObject(); - - /** Default destructor */ - virtual ~NLPScalingObject(); - //@} - - /** Method to initialize the options */ - bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix) - { - jnlst_ = &jnlst; - return InitializeImpl(options, prefix); - } - - /** Methods to map scaled and unscaled matrices */ - //@{ - /** Returns an obj-scaled version of the given scalar */ - virtual Number apply_obj_scaling(const Number& f)=0; - /** Returns an obj-unscaled version of the given scalar */ - virtual Number unapply_obj_scaling(const Number& f)=0; - /** Returns an x-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_x_NonConst(const SmartPtr& v)=0; - /** Returns an x-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_x(const SmartPtr& v)=0; - /** Returns an x-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_x_NonConst(const SmartPtr& v)=0; - /** Returns an x-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_x(const SmartPtr& v)=0; - /** Returns an c-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_c(const SmartPtr& v)=0; - /** Returns an c-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_c(const SmartPtr& v)=0; - /** Returns an c-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_c_NonConst(const SmartPtr& v)=0; - /** Returns an c-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_c_NonConst(const SmartPtr& v)=0; - /** Returns an d-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_d(const SmartPtr& v)=0; - /** Returns an d-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_d(const SmartPtr& v)=0; - /** Returns an d-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_d_NonConst(const SmartPtr& v)=0; - /** Returns an d-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_d_NonConst(const SmartPtr& v)=0; - /** Returns a scaled version of the jacobian for c. If the - * overloaded method does not make a new matrix, make sure to set - * the matrix ptr passed in to NULL. - */ - virtual SmartPtr - apply_jac_c_scaling(SmartPtr matrix)=0; - /** Returns a scaled version of the jacobian for d If the - * overloaded method does not create a new matrix, make sure to - * set the matrix ptr passed in to NULL. - */ - virtual SmartPtr - apply_jac_d_scaling(SmartPtr matrix)=0; - /** Returns a scaled version of the hessian of the lagrangian If - * the overloaded method does not create a new matrix, make sure - * to set the matrix ptr passed in to NULL. - */ - virtual SmartPtr - apply_hessian_scaling(SmartPtr matrix)=0; - //@} - - /** Methods for scaling bounds - these wrap those above */ - //@{ - /** Returns an x-scaled vector in the x_L or x_U space */ - SmartPtr apply_vector_scaling_x_LU_NonConst( - const Matrix& Px_LU, - const SmartPtr& lu, - const VectorSpace& x_space); - /** Returns an x-scaled vector in the x_L or x_U space */ - SmartPtr apply_vector_scaling_x_LU( - const Matrix& Px_LU, - const SmartPtr& lu, - const VectorSpace& x_space); - /** Returns an d-scaled vector in the d_L or d_U space */ - SmartPtr apply_vector_scaling_d_LU_NonConst( - const Matrix& Pd_LU, - const SmartPtr& lu, - const VectorSpace& d_space); - /** Returns an d-scaled vector in the d_L or d_U space */ - SmartPtr apply_vector_scaling_d_LU( - const Matrix& Pd_LU, - const SmartPtr& lu, - const VectorSpace& d_space); - /** Returns an d-unscaled vector in the d_L or d_U space */ - SmartPtr unapply_vector_scaling_d_LU_NonConst( - const Matrix& Pd_LU, - const SmartPtr& lu, - const VectorSpace& d_space); - /** Returns an d-unscaled vector in the d_L or d_U space */ - SmartPtr unapply_vector_scaling_d_LU( - const Matrix& Pd_LU, - const SmartPtr& lu, - const VectorSpace& d_space); - //@} - - /** Methods for scaling the gradient of the objective - wraps the - * virtual methods above - */ - //@{ - /** Returns a grad_f scaled version (d_f * D_x^{-1}) of the given vector */ - virtual SmartPtr - apply_grad_obj_scaling_NonConst(const SmartPtr& v); - /** Returns a grad_f scaled version (d_f * D_x^{-1}) of the given vector */ - virtual SmartPtr - apply_grad_obj_scaling(const SmartPtr& v); - /** Returns a grad_f unscaled version (d_f * D_x^{-1}) of the - * given vector */ - virtual SmartPtr - unapply_grad_obj_scaling_NonConst(const SmartPtr& v); - /** Returns a grad_f unscaled version (d_f * D_x^{-1}) of the - * given vector */ - virtual SmartPtr - unapply_grad_obj_scaling(const SmartPtr& v); - //@} - - /** @name Methods for determining whether scaling for entities is - * done */ - //@{ - /** Returns true if the primal x variables are scaled. */ - virtual bool have_x_scaling()=0; - /** Returns true if the equality constraints are scaled. */ - virtual bool have_c_scaling()=0; - /** Returns true if the inequality constraints are scaled. */ - virtual bool have_d_scaling()=0; - //@} - - /** This method is called by the IpoptNLP's at a convenient time to - * compute and/or read scaling factors - */ - virtual void DetermineScaling(const SmartPtr x_space, - const SmartPtr c_space, - const SmartPtr d_space, - const SmartPtr jac_c_space, - const SmartPtr jac_d_space, - const SmartPtr h_space, - SmartPtr& new_jac_c_space, - SmartPtr& new_jac_d_space, - SmartPtr& new_h_space, - const Matrix& Px_L, const Vector& x_L, - const Matrix& Px_U, const Vector& x_U)=0; - protected: - /** Implementation of the initialization method that has to be - * overloaded by for each derived class. */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix)=0; - - /** Accessor method for the journalist */ - const Journalist& Jnlst() const - { - return *jnlst_; - } - private: - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - - /** Copy Constructor */ - NLPScalingObject(const NLPScalingObject&); - - /** Overloaded Equals Operator */ - void operator=(const NLPScalingObject&); - //@} - - SmartPtr jnlst_; - }; - - /** This is a base class for many standard scaling - * techniques. The overloaded classes only need to - * provide the scaling parameters - */ - class StandardScalingBase : public NLPScalingObject - { - public: - /**@name Constructors/Destructors */ - //@{ - StandardScalingBase(); - - /** Default destructor */ - virtual ~StandardScalingBase(); - //@} - - /** Methods to map scaled and unscaled matrices */ - //@{ - /** Returns an obj-scaled version of the given scalar */ - virtual Number apply_obj_scaling(const Number& f); - /** Returns an obj-unscaled version of the given scalar */ - virtual Number unapply_obj_scaling(const Number& f); - /** Returns an x-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_x_NonConst(const SmartPtr& v); - /** Returns an x-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_x(const SmartPtr& v); - /** Returns an x-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_x_NonConst(const SmartPtr& v); - /** Returns an x-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_x(const SmartPtr& v); - /** Returns an c-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_c(const SmartPtr& v); - /** Returns an c-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_c(const SmartPtr& v); - /** Returns an c-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_c_NonConst(const SmartPtr& v); - /** Returns an c-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_c_NonConst(const SmartPtr& v); - /** Returns an d-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_d(const SmartPtr& v); - /** Returns an d-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_d(const SmartPtr& v); - /** Returns an d-scaled version of the given vector */ - virtual SmartPtr - apply_vector_scaling_d_NonConst(const SmartPtr& v); - /** Returns an d-unscaled version of the given vector */ - virtual SmartPtr - unapply_vector_scaling_d_NonConst(const SmartPtr& v); - /** Returns a scaled version of the jacobian for c. If the - * overloaded method does not make a new matrix, make sure to set - * the matrix ptr passed in to NULL. - */ - virtual SmartPtr - apply_jac_c_scaling(SmartPtr matrix); - /** Returns a scaled version of the jacobian for d If the - * overloaded method does not create a new matrix, make sure to - * set the matrix ptr passed in to NULL. - */ - virtual SmartPtr - apply_jac_d_scaling(SmartPtr matrix); - /** Returns a scaled version of the hessian of the lagrangian If - * the overloaded method does not create a new matrix, make sure - * to set the matrix ptr passed in to NULL. - */ - virtual SmartPtr - apply_hessian_scaling(SmartPtr matrix); - //@} - - /** @name Methods for determining whether scaling for entities is - * done */ - //@{ - virtual bool have_x_scaling(); - virtual bool have_c_scaling(); - virtual bool have_d_scaling(); - //@} - - /** This method is called by the IpoptNLP's at a convenient time to - * compute and/or read scaling factors - */ - virtual void DetermineScaling(const SmartPtr x_space, - const SmartPtr c_space, - const SmartPtr d_space, - const SmartPtr jac_c_space, - const SmartPtr jac_d_space, - const SmartPtr h_space, - SmartPtr& new_jac_c_space, - SmartPtr& new_jac_d_space, - SmartPtr& new_h_space, - const Matrix& Px_L, const Vector& x_L, - const Matrix& Px_U, const Vector& x_U); - - /** Methods for IpoptType */ - //@{ - static void RegisterOptions(SmartPtr roptions); - //@} - - protected: - /** Overloaded initialization method */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix); - - /** This is the method that has to be overloaded by a particular - * scaling method that somehow computes the scaling vectors dx, - * dc, and dd. The pointers to those vectors can be NULL, in - * which case no scaling for that item will be done later. */ - virtual void DetermineScalingParametersImpl( - const SmartPtr x_space, - const SmartPtr c_space, - const SmartPtr d_space, - const SmartPtr jac_c_space, - const SmartPtr jac_d_space, - const SmartPtr h_space, - const Matrix& Px_L, const Vector& x_L, - const Matrix& Px_U, const Vector& x_U, - Number& df, - SmartPtr& dx, - SmartPtr& dc, - SmartPtr& dd)=0; - - private: - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - - /** Copy Constructor */ - StandardScalingBase(const StandardScalingBase&); - - /** Overloaded Equals Operator */ - void operator=(const StandardScalingBase&); - //@} - - /** Scaling parameters - we only need to keep copies of - * the objective scaling and the x scaling - the others we can - * get from the scaled matrix spaces. - */ - //@{ - /** objective scaling parameter */ - Number df_; - /** x scaling */ - SmartPtr dx_; - //@} - - /** Scaled Matrix Spaces */ - //@{ - /** Scaled jacobian of c space */ - SmartPtr scaled_jac_c_space_; - /** Scaled jacobian of d space */ - SmartPtr scaled_jac_d_space_; - /** Scaled hessian of lagrangian spacea */ - SmartPtr scaled_h_space_; - //@} - - /** @name Algorithmic parameters */ - //@{ - /** Additional scaling value for the objective function */ - Number obj_scaling_factor_; - //@} - }; - - /** Class implementing the scaling object that doesn't to any scaling */ - class NoNLPScalingObject : public StandardScalingBase - { - public: - /**@name Constructors/Destructors */ - //@{ - NoNLPScalingObject() - {} - - /** Default destructor */ - virtual ~NoNLPScalingObject() - {} - //@} - - - protected: - /** Overloaded from StandardScalingBase */ - virtual void DetermineScalingParametersImpl( - const SmartPtr x_space, - const SmartPtr c_space, - const SmartPtr d_space, - const SmartPtr jac_c_space, - const SmartPtr jac_d_space, - const SmartPtr h_space, - const Matrix& Px_L, const Vector& x_L, - const Matrix& Px_U, const Vector& x_U, - Number& df, - SmartPtr& dx, - SmartPtr& dc, - SmartPtr& dd); - - private: - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - - /** Copy Constructor */ - NoNLPScalingObject(const NoNLPScalingObject&); - - /** Overloaded Equals Operator */ - void operator=(const NoNLPScalingObject&); - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpObserver.hpp b/external/ipopt/include/coin/IpObserver.hpp deleted file mode 100644 index b16f59945..000000000 --- a/external/ipopt/include/coin/IpObserver.hpp +++ /dev/null @@ -1,366 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpObserver.hpp 2161 2013-01-01 20:39:05Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPOBSERVER_HPP__ -#define __IPOBSERVER_HPP__ - -#include "IpUtils.hpp" -#include -#include - -//#define IP_DEBUG_OBSERVER -#if COIN_IPOPT_CHECKLEVEL > 2 -# define IP_DEBUG_OBSERVER -#endif -#ifdef IP_DEBUG_OBSERVER -# include "IpDebug.hpp" -#endif - -namespace Ipopt -{ - /** Forward declarations */ - class Subject; - - /** Slight Variation of the Observer Design Pattern. - * This class implements the Observer class of the - * Observer Design Pattern. An Observer "Attach"es - * to a Subject, indicating that it would like to - * be notified of changes in the Subject. - * Any derived class wishing to recieve notifications - * from a Subject should inherit off of - * Observer and overload the protected method, - * RecieveNotification_(...). - */ - class Observer - { - public: -#ifdef IP_DEBUG_OBSERVER - - static const Index dbg_verbosity; -#endif - - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - Observer() - {} - - /** Default destructor */ - inline - virtual ~Observer(); - //@} - - /** Enumeration specifying the type of notification */ - enum NotifyType - { - NT_All, - NT_BeingDestroyed, - NT_Changed - }; - - protected: - /** Derived classes should call this method - * to request an "Attach" to a Subject. Do - * not call "Attach" explicitly on the Subject - * since further processing is done here - */ - inline - void RequestAttach(NotifyType notify_type, const Subject* subject); - - /** Derived classes should call this method - * to request a "Detach" to a Subject. Do - * not call "Detach" explicitly on the Subject - * since further processing is done here - */ - inline - void RequestDetach(NotifyType notify_type, const Subject* subject); - - /** Derived classes should overload this method to - * recieve the requested notification from - * attached Subjects - */ - virtual void RecieveNotification(NotifyType notify_type, const Subject* subject)=0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - Observer(const Observer&); - - /** Overloaded Equals Operator */ - void operator=(const Observer&); - //@} - - /** A list of the subjects currently being - * observed. */ - std::vector subjects_; - - /** Private Method for Recieving Notification - * should only be called by the friend class - * Subject. This method will, in turn, call - * the overloaded RecieveNotification method - * for the derived class to process. - */ - inline - void ProcessNotification(NotifyType notify_type, const Subject* subject); - - friend class Subject; - }; - - /** Slight Variation of the Observer Design Pattern (Subject part). - * This class implements the Subject class of the Observer Design - * Pattern. An Observer "Attach"es to a Subject, indicating that it - * would like to be notified of changes in the Subject. Any - * derived class that is to be observed has to inherit off the - * Subject base class. If the subject needs to notify the - * Observer, it calls the Notify method. - */ - class Subject - { - public: -#ifdef IP_DEBUG_OBSERVER - - static const Index dbg_verbosity; -#endif - - /**@name Constructors/Destructors */ - //@{ - /** Default Constructor */ - Subject() - {} - - /** Default destructor */ - inline - virtual ~Subject(); - //@} - - /**@name Methods to Add and Remove Observers. - * Currently, the notify_type flags are not used, - * and Observers are attached in general and will - * recieve all notifications (of the type requested - * and possibly of types not requested). It is - * up to the observer to ignore the types they - * are not interested in. The NotifyType in the - * parameter list is so a more efficient mechanism - * depending on type could be implemented later if - * necessary.*/ - //@{ - - /** Attach the specified observer - * (i.e., begin recieving notifications). */ - inline - void AttachObserver(Observer::NotifyType notify_type, Observer* observer) const; - - /** Detach the specified observer - * (i.e., no longer recieve notifications). */ - inline - void DetachObserver(Observer::NotifyType notify_type, Observer* observer) const; - //@} - - protected: - - inline - void Notify(Observer::NotifyType notify_type) const; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - Subject(const Subject&); - - /** Overloaded Equals Operator */ - void operator=(const Subject&); - //@} - - mutable std::vector observers_; - - }; - - /* inline methods */ - inline - Observer::~Observer() - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Observer::~Observer", dbg_verbosity); - if (DBG_VERBOSITY()>=1) { - for (Index i=0; i<(Index)subjects_.size(); i++) { - DBG_PRINT((1,"subjects_[%d] = 0x%x\n", i, subjects_[i])); - } - } -#endif - // Detach all subjects - for (Int i=(Int)(subjects_.size()-1); i>=0; i--) { -#ifdef IP_DEBUG_OBSERVER - DBG_PRINT((1,"About to detach subjects_[%d] = 0x%x\n", i, subjects_[i])); -#endif - - RequestDetach(NT_All, subjects_[i]); - } - } - - inline - void Observer::RequestAttach(NotifyType notify_type, const Subject* subject) - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Observer::RequestAttach", dbg_verbosity); - - // Add the subject to the list if it does not already exist - std::vector::iterator attached_subject; - attached_subject = std::find(subjects_.begin(), subjects_.end(), subject); - DBG_ASSERT(attached_subject == subjects_.end()); - DBG_ASSERT(subject); -#endif - - // add the subject to the list - subjects_.push_back(subject); - // Attach the observer to the subject - subject->AttachObserver(notify_type, this); - } - - inline - void Observer::RequestDetach(NotifyType notify_type, const Subject* subject) - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Observer::RequestDetach", dbg_verbosity); - DBG_PRINT((1, "Requesting detach of subject: 0x%x\n", subject)); - DBG_ASSERT(subject); -#endif - - if (subject) { - std::vector::iterator attached_subject; - attached_subject = std::find(subjects_.begin(), subjects_.end(), subject); -#ifdef IP_DEBUG_OBSERVER - - DBG_ASSERT(attached_subject != subjects_.end()); -#endif - - if (attached_subject != subjects_.end()) { -#ifdef IP_DEBUG_OBSERVER - DBG_PRINT((1, "Removing subject: 0x%x from the list\n", subject)); -#endif - - subjects_.erase(attached_subject); - } - - // Detach the observer from the subject - subject->DetachObserver(notify_type, this); - } - } - - inline - void Observer::ProcessNotification(NotifyType notify_type, const Subject* subject) - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Observer::ProcessNotification", dbg_verbosity); - DBG_ASSERT(subject); -#endif - - if (subject) { - std::vector::iterator attached_subject; - attached_subject = std::find(subjects_.begin(), subjects_.end(), subject); - - // We must be processing a notification for a - // subject that was previously attached. -#ifdef IP_DEBUG_OBSERVER - - DBG_ASSERT(attached_subject != subjects_.end()); -#endif - - this->RecieveNotification(notify_type, subject); - - if (notify_type == NT_BeingDestroyed) { - // the subject is going away, remove it from our list - subjects_.erase(attached_subject); - } - } - } - - inline - Subject::~Subject() - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Subject::~Subject", dbg_verbosity); -#endif - - std::vector::iterator iter; - for (iter = observers_.begin(); iter != observers_.end(); iter++) { - (*iter)->ProcessNotification(Observer::NT_BeingDestroyed, this); - } - } - - inline - void Subject::AttachObserver(Observer::NotifyType notify_type, Observer* observer) const - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Subject::AttachObserver", dbg_verbosity); - // current implementation notifies all observers of everything - // they must filter the notifications that they are not interested - // in (i.e. a hub, not a router) - DBG_ASSERT(observer); - - std::vector::iterator attached_observer; - attached_observer = std::find(observers_.begin(), observers_.end(), observer); - DBG_ASSERT(attached_observer == observers_.end()); - - DBG_ASSERT(observer); -#endif - - observers_.push_back(observer); - } - - inline - void Subject::DetachObserver(Observer::NotifyType notify_type, Observer* observer) const - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Subject::DetachObserver", dbg_verbosity); - DBG_ASSERT(observer); -#endif - - if (observer) { - std::vector::iterator attached_observer; - attached_observer = std::find(observers_.begin(), observers_.end(), observer); -#ifdef IP_DEBUG_OBSERVER - - DBG_ASSERT(attached_observer != observers_.end()); -#endif - - if (attached_observer != observers_.end()) { - observers_.erase(attached_observer); - } - } - } - - inline - void Subject::Notify(Observer::NotifyType notify_type) const - { -#ifdef IP_DEBUG_OBSERVER - DBG_START_METH("Subject::Notify", dbg_verbosity); -#endif - - std::vector::iterator iter; - for (iter = observers_.begin(); iter != observers_.end(); iter++) { - (*iter)->ProcessNotification(notify_type, this); - } - } - - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpOptionsList.hpp b/external/ipopt/include/coin/IpOptionsList.hpp deleted file mode 100644 index a17863f70..000000000 --- a/external/ipopt/include/coin/IpOptionsList.hpp +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpOptionsList.hpp 2613 2015-11-04 14:42:02Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPOPTLIST_HPP__ -#define __IPOPTLIST_HPP__ - -#include "IpUtils.hpp" -#include "IpReferenced.hpp" -#include "IpException.hpp" -#include "IpRegOptions.hpp" - -#include -#include - -namespace Ipopt -{ - /** Exception that can be used to indicate errors with options */ - DECLARE_STD_EXCEPTION(OPTION_INVALID); - - /** This class stores a list of user set options. Each options is - * identified by a case-insensitive keyword (tag). Its value is - * stored internally as a string (always lower case), but for - * convenience set and get methods are provided to obtain Index and - * Number type values. For each keyword we also keep track of how - * often the value of an option has been requested by a get method. - */ - class OptionsList : public ReferencedObject - { - /** Class for storing the value and counter for each option in - * OptionsList. */ - class OptionValue - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor (needed for the map) */ - OptionValue() - : - initialized_(false) - {} - - /** Constructor given the value */ - OptionValue(std::string value, bool allow_clobber, bool dont_print) - : - value_(value), - counter_(0), - initialized_(true), - allow_clobber_(allow_clobber), - dont_print_(dont_print) - {} - - /** Copy Constructor */ - OptionValue(const OptionValue& copy) - : - value_(copy.value_), - counter_(copy.counter_), - initialized_(copy.initialized_), - allow_clobber_(copy.allow_clobber_), - dont_print_(copy.dont_print_) - {} - - /** Equals operator */ - void operator=(const OptionValue& copy) - { - value_=copy.value_; - counter_=copy.counter_; - initialized_=copy.initialized_; - allow_clobber_=copy.allow_clobber_; - dont_print_=copy.dont_print_; - } - - /** Default Destructor */ - ~OptionValue() - {} - //@} - - /** Method for retrieving the value of an option. Calling this - * method will increase the counter by one. */ - std::string GetValue() const - { - DBG_ASSERT(initialized_); - counter_++; - return value_; - } - - /** Method for retrieving the value without increasing the - * counter */ - std::string Value() const - { - DBG_ASSERT(initialized_); - return value_; - } - - /** Method for accessing current value of the request counter */ - Index Counter() const - { - DBG_ASSERT(initialized_); - return counter_; - } - - /** True if the option can be overwritten */ - bool AllowClobber() const - { - DBG_ASSERT(initialized_); - return allow_clobber_; - } - - /** True if this option is not to show up in the - * print_user_options output */ - bool DontPrint() const - { - DBG_ASSERT(initialized_); - return dont_print_; - } - - private: - /** Value for this option */ - std::string value_; - - /** Counter for requests */ - mutable Index counter_; - - /** for debugging */ - bool initialized_; - - /** True if the option can be overwritten */ - bool allow_clobber_; - - /** True if this option is not to show up in the - * print_user_options output */ - bool dont_print_; - }; - - public: - /**@name Constructors/Destructors */ - //@{ - OptionsList(SmartPtr reg_options, SmartPtr jnlst) - : reg_options_(reg_options), jnlst_(jnlst) - {} - - OptionsList() - {} - - /** Copy Constructor */ - OptionsList(const OptionsList& copy) - { - // copy all the option strings and values - options_ = copy.options_; - // copy the registered options pointer - reg_options_ = copy.reg_options_; - } - - /** Default destructor */ - virtual ~OptionsList() - {} - - /** Overloaded Equals Operator */ - virtual void operator=(const OptionsList& source) - { - options_ = source.options_; - reg_options_ = source.reg_options_; - jnlst_ = source.jnlst_; - } - //@} - - /** Method for clearing all previously set options */ - virtual void clear() - { - options_.clear(); - } - - /** @name Get / Set Methods */ - //@{ - virtual void SetRegisteredOptions(const SmartPtr reg_options) - { - reg_options_ = reg_options; - } - virtual void SetJournalist(const SmartPtr jnlst) - { - jnlst_ = jnlst; - } - //@} - /** @name Methods for setting options */ - //@{ - virtual bool SetStringValue(const std::string& tag, const std::string& value, - bool allow_clobber = true, bool dont_print = false); - virtual bool SetNumericValue(const std::string& tag, Number value, - bool allow_clobber = true, bool dont_print = false); - virtual bool SetIntegerValue(const std::string& tag, Index value, - bool allow_clobber = true, bool dont_print = false); - //@} - - /** @name Methods for setting options only if they have not been - * set before*/ - //@{ - virtual bool SetStringValueIfUnset(const std::string& tag, const std::string& value, - bool allow_clobber = true, bool dont_print = false); - virtual bool SetNumericValueIfUnset(const std::string& tag, Number value, - bool allow_clobber = true, bool dont_print = false); - virtual bool SetIntegerValueIfUnset(const std::string& tag, Index value, - bool allow_clobber = true, bool dont_print = false); - //@} - - /** @name Methods for retrieving values from the options list. If - * a tag is not found, the methods return false, and value is set - * to the default value defined in the registered options. */ - //@{ - virtual bool GetStringValue(const std::string& tag, std::string& value, - const std::string& prefix) const; - virtual bool GetEnumValue(const std::string& tag, Index& value, - const std::string& prefix) const; - virtual bool GetBoolValue(const std::string& tag, bool& value, - const std::string& prefix) const; - virtual bool GetNumericValue(const std::string& tag, Number& value, - const std::string& prefix) const; - virtual bool GetIntegerValue(const std::string& tag, Index& value, - const std::string& prefix) const; - //@} - - /** Get a string with the list of all options (tag, value, counter) */ - virtual void PrintList(std::string& list) const; - - /** Get a string with the list of all options set by the user - * (tag, value, use/notused). Here, options with dont_print flag - * set to true are not printed. */ - virtual void PrintUserOptions(std::string& list) const; - - /** Read options from the stream is. Returns false if - * an error was encountered. */ - virtual bool ReadFromStream(const Journalist& jnlst, std::istream& is, bool allow_clobber = false); - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - // OptionsList(); - - //@} - - /** map for storing the options */ - std::map< std::string, OptionValue > options_; - - /** list of all the registered options to validate against */ - SmartPtr reg_options_; - - /** Journalist for writing error messages, etc. */ - SmartPtr jnlst_; - - /** auxilliary method for converting sting to all lower-case - * letters */ - const std::string& lowercase(const std::string tag) const; - - /** auxilliary method for finding the value for a tag in the - * options list. This method first looks for the concatenated - * string prefix+tag (if prefix is not ""), and if this is not - * found, it looks for tag. The return value is true iff - * prefix+tag or tag is found. In that case, the corresponding - * string value is copied into value. */ - bool find_tag(const std::string& tag, const std::string& prefix, - std::string& value) const; - - /** tells whether or not we can clobber a particular option. - * returns true if the option does not already exist, or if - * the option exists but is set to allow_clobber - */ - bool will_allow_clobber(const std::string& tag) const; - - /** read the next token from stream is. Returns false, if EOF was - * reached before a tokens was ecountered. */ - bool readnexttoken(std::istream& is, std::string& token); - - /** auxilliary string set by lowercase method */ - mutable std::string lowercase_buffer_; - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpOrigIpoptNLP.hpp b/external/ipopt/include/coin/IpOrigIpoptNLP.hpp deleted file mode 100644 index 41b10fa2a..000000000 --- a/external/ipopt/include/coin/IpOrigIpoptNLP.hpp +++ /dev/null @@ -1,488 +0,0 @@ -// Copyright (C) 2004, 2010 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpOrigIpoptNLP.hpp 2594 2015-08-09 14:31:05Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPORIGIPOPTNLP_HPP__ -#define __IPORIGIPOPTNLP_HPP__ - -#include "IpIpoptNLP.hpp" -#include "IpException.hpp" -#include "IpTimingStatistics.hpp" - -namespace Ipopt -{ - - /** enumeration for the Hessian information type. */ - enum HessianApproximationType { - EXACT=0, - LIMITED_MEMORY - }; - - /** enumeration for the Hessian approximation space. */ - enum HessianApproximationSpace { - NONLINEAR_VARS=0, - ALL_VARS - }; - - /** This class maps the traditional NLP into - * something that is more useful by Ipopt. - * This class takes care of storing the - * calculated model results, handles caching, - * and (some day) takes care of addition of slacks. - */ - class OrigIpoptNLP : public IpoptNLP - { - public: - /**@name Constructors/Destructors */ - //@{ - OrigIpoptNLP(const SmartPtr& jnlst, - const SmartPtr& nlp, - const SmartPtr& nlp_scaling); - - /** Default destructor */ - virtual ~OrigIpoptNLP(); - //@} - - /** Initialize - overloaded from IpoptNLP */ - virtual bool Initialize(const Journalist& jnlst, - const OptionsList& options, - const std::string& prefix); - - /** Initialize (create) structures for - * the iteration data */ - virtual bool InitializeStructures(SmartPtr& x, - bool init_x, - SmartPtr& y_c, - bool init_y_c, - SmartPtr& y_d, - bool init_y_d, - SmartPtr& z_L, - bool init_z_L, - SmartPtr& z_U, - bool init_z_U, - SmartPtr& v_L, - SmartPtr& v_U - ); - - /** Method accessing the GetWarmStartIterate of the NLP */ - virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate) - { - return nlp_->GetWarmStartIterate(warm_start_iterate); - } - /** Accessor methods for model data */ - //@{ - /** Objective value */ - virtual Number f(const Vector& x); - - /** Objective value (depending in mu) - incorrect version for - * OrigIpoptNLP */ - virtual Number f(const Vector& x, Number mu); - - /** Gradient of the objective */ - virtual SmartPtr grad_f(const Vector& x); - - /** Gradient of the objective (depending in mu) - incorrect - * version for OrigIpoptNLP */ - virtual SmartPtr grad_f(const Vector& x, Number mu); - - /** Equality constraint residual */ - virtual SmartPtr c(const Vector& x); - - /** Jacobian Matrix for equality constraints */ - virtual SmartPtr jac_c(const Vector& x); - - /** Inequality constraint residual (reformulated - * as equalities with slacks */ - virtual SmartPtr d(const Vector& x); - - /** Jacobian Matrix for inequality constraints*/ - virtual SmartPtr jac_d(const Vector& x); - - /** Hessian of the Lagrangian */ - virtual SmartPtr h(const Vector& x, - Number obj_factor, - const Vector& yc, - const Vector& yd - ); - - /** Hessian of the Lagrangian (depending in mu) - incorrect - * version for OrigIpoptNLP */ - virtual SmartPtr h(const Vector& x, - Number obj_factor, - const Vector& yc, - const Vector& yd, - Number mu); - - /** Provides a Hessian matrix from the correct matrix space with - * uninitialized values. This can be used in LeastSquareMults to - * obtain a "zero Hessian". */ - virtual SmartPtr uninitialized_h(); - - /** Lower bounds on x */ - virtual SmartPtr x_L() const - { - return x_L_; - } - - /** Permutation matrix (x_L_ -> x) */ - virtual SmartPtr Px_L() const - { - return Px_L_; - } - - /** Upper bounds on x */ - virtual SmartPtr x_U() const - { - return x_U_; - } - - /** Permutation matrix (x_U_ -> x */ - virtual SmartPtr Px_U() const - { - return Px_U_; - } - - /** Lower bounds on d */ - virtual SmartPtr d_L() const - { - return d_L_; - } - - /** Permutation matrix (d_L_ -> d) */ - virtual SmartPtr Pd_L() const - { - return Pd_L_; - } - - /** Upper bounds on d */ - virtual SmartPtr d_U() const - { - return d_U_; - } - - /** Permutation matrix (d_U_ -> d */ - virtual SmartPtr Pd_U() const - { - return Pd_U_; - } - - virtual SmartPtr HessianMatrixSpace() const - { - return h_space_; - } - - virtual SmartPtr x_space() const - { - return x_space_; - } - //@} - - /** Accessor method for vector/matrix spaces pointers */ - virtual void GetSpaces(SmartPtr& x_space, - SmartPtr& c_space, - SmartPtr& d_space, - SmartPtr& x_l_space, - SmartPtr& px_l_space, - SmartPtr& x_u_space, - SmartPtr& px_u_space, - SmartPtr& d_l_space, - SmartPtr& pd_l_space, - SmartPtr& d_u_space, - SmartPtr& pd_u_space, - SmartPtr& Jac_c_space, - SmartPtr& Jac_d_space, - SmartPtr& Hess_lagrangian_space); - - /** Method for adapting the variable bounds. This is called if - * slacks are becoming too small */ - virtual void AdjustVariableBounds(const Vector& new_x_L, - const Vector& new_x_U, - const Vector& new_d_L, - const Vector& new_d_U); - - /** @name Counters for the number of function evaluations. */ - //@{ - virtual Index f_evals() const - { - return f_evals_; - } - virtual Index grad_f_evals() const - { - return grad_f_evals_; - } - virtual Index c_evals() const - { - return c_evals_; - } - virtual Index jac_c_evals() const - { - return jac_c_evals_; - } - virtual Index d_evals() const - { - return d_evals_; - } - virtual Index jac_d_evals() const - { - return jac_d_evals_; - } - virtual Index h_evals() const - { - return h_evals_; - } - //@} - - /** Solution Routines - overloaded from IpoptNLP*/ - //@{ - void FinalizeSolution(SolverReturn status, - const Vector& x, const Vector& z_L, const Vector& z_U, - const Vector& c, const Vector& d, - const Vector& y_c, const Vector& y_d, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); - bool IntermediateCallBack(AlgorithmMode mode, - Index iter, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, - SmartPtr ip_data, - SmartPtr ip_cq); - //@} - - /** @name Methods for IpoptType */ - //@{ - /** Called by IpoptType to register the options */ - static void RegisterOptions(SmartPtr roptions); - //@} - - /** Accessor method to the underlying NLP */ - SmartPtr nlp() - { - return nlp_; - } - - /**@name Methods related to function evaluation timing. */ - //@{ - - /** Reset the timing statistics */ - void ResetTimes(); - - void PrintTimingStatistics(Journalist& jnlst, - EJournalLevel level, - EJournalCategory category) const; - - const TimedTask& f_eval_time() const - { - return f_eval_time_; - } - const TimedTask& grad_f_eval_time() const - { - return grad_f_eval_time_; - } - const TimedTask& c_eval_time() const - { - return c_eval_time_; - } - const TimedTask& jac_c_eval_time() const - { - return jac_c_eval_time_; - } - const TimedTask& d_eval_time() const - { - return d_eval_time_; - } - const TimedTask& jac_d_eval_time() const - { - return jac_d_eval_time_; - } - const TimedTask& h_eval_time() const - { - return h_eval_time_; - } - - Number TotalFunctionEvaluationCpuTime() const; - Number TotalFunctionEvaluationSysTime() const; - Number TotalFunctionEvaluationWallclockTime() const; - //@} - - private: - /** journalist */ - SmartPtr jnlst_; - - /** Pointer to the NLP */ - SmartPtr nlp_; - - /** Necessary Vector/Matrix spaces */ - //@{ - SmartPtr x_space_; - SmartPtr c_space_; - SmartPtr d_space_; - SmartPtr x_l_space_; - SmartPtr px_l_space_; - SmartPtr x_u_space_; - SmartPtr px_u_space_; - SmartPtr d_l_space_; - SmartPtr pd_l_space_; - SmartPtr d_u_space_; - SmartPtr pd_u_space_; - SmartPtr jac_c_space_; - SmartPtr jac_d_space_; - SmartPtr h_space_; - - SmartPtr scaled_jac_c_space_; - SmartPtr scaled_jac_d_space_; - SmartPtr scaled_h_space_; - //@} - /**@name Storage for Model Quantities */ - //@{ - /** Objective function */ - CachedResults f_cache_; - - /** Gradient of the objective function */ - CachedResults > grad_f_cache_; - - /** Equality constraint residuals */ - CachedResults > c_cache_; - - /** Jacobian Matrix for equality constraints - * (current iteration) */ - CachedResults > jac_c_cache_; - - /** Inequality constraint residual (reformulated - * as equalities with slacks */ - CachedResults > d_cache_; - - /** Jacobian Matrix for inequality constraints - * (current iteration) */ - CachedResults > jac_d_cache_; - - /** Hessian of the lagrangian - * (current iteration) */ - CachedResults > h_cache_; - - /** Unscaled version of x vector */ - CachedResults > unscaled_x_cache_; - - /** Lower bounds on x */ - SmartPtr x_L_; - - /** Permutation matrix (x_L_ -> x) */ - SmartPtr Px_L_; - - /** Upper bounds on x */ - SmartPtr x_U_; - - /** Permutation matrix (x_U_ -> x */ - SmartPtr Px_U_; - - /** Lower bounds on d */ - SmartPtr d_L_; - - /** Permutation matrix (d_L_ -> d) */ - SmartPtr Pd_L_; - - /** Upper bounds on d */ - SmartPtr d_U_; - - /** Permutation matrix (d_U_ -> d */ - SmartPtr Pd_U_; - - /** Original unmodified lower bounds on x */ - SmartPtr orig_x_L_; - - /** Original unmodified upper bounds on x */ - SmartPtr orig_x_U_; - //@} - - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - OrigIpoptNLP(); - - /** Copy Constructor */ - OrigIpoptNLP(const OrigIpoptNLP&); - - /** Overloaded Equals Operator */ - void operator=(const OrigIpoptNLP&); - //@} - - /** @name auxilliary functions */ - //@{ - /** relax the bounds by a relative move of relax_bound_factor. - * Here, relax_bound_factor should be negative (or zero) for - * lower bounds, and positive (or zero) for upper bounds. - */ - void relax_bounds(Number bound_relax_factor, Vector& bounds); - /** Method for getting the unscaled version of the x vector */ - SmartPtr get_unscaled_x(const Vector& x); - //@} - - /** @name Algorithmic parameters */ - //@{ - /** relaxation factor for the bounds */ - Number bound_relax_factor_; - /** Flag indicating whether the primal variables should be - * projected back into original bounds are optimization. */ - bool honor_original_bounds_; - /** Flag indicating whether the TNLP with identical structure has - * already been solved before. */ - bool warm_start_same_structure_; - /** Flag indicating what Hessian information is to be used. */ - HessianApproximationType hessian_approximation_; - /** Flag indicating in which space Hessian is to be approximated. */ - HessianApproximationSpace hessian_approximation_space_; - /** Flag indicating whether it is desired to check if there are - * Nan or Inf entries in first and second derivative matrices. */ - bool check_derivatives_for_naninf_; - /** Flag indicating if we need to ask for equality constraint - * Jacobians only once */ - bool jac_c_constant_; - /** Flag indicating if we need to ask for inequality constraint - * Jacobians only once */ - bool jac_d_constant_; - /** Flag indicating if we need to ask for Hessian only once */ - bool hessian_constant_; - //@} - - /** @name Counters for the function evaluations */ - //@{ - Index f_evals_; - Index grad_f_evals_; - Index c_evals_; - Index jac_c_evals_; - Index d_evals_; - Index jac_d_evals_; - Index h_evals_; - //@} - - /** Flag indicating if initialization method has been called */ - bool initialized_; - - /**@name Timing statistics for the function evaluations. */ - //@{ - TimedTask f_eval_time_; - TimedTask grad_f_eval_time_; - TimedTask c_eval_time_; - TimedTask jac_c_eval_time_; - TimedTask d_eval_time_; - TimedTask jac_d_eval_time_; - TimedTask h_eval_time_; - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpPDSystemSolver.hpp b/external/ipopt/include/coin/IpPDSystemSolver.hpp deleted file mode 100644 index b436e6783..000000000 --- a/external/ipopt/include/coin/IpPDSystemSolver.hpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpPDSystemSolver.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPPDSYSTEMSOLVER_HPP__ -#define __IPPDSYSTEMSOLVER_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" -#include "IpAlgStrategy.hpp" -#include "IpIteratesVector.hpp" - -namespace Ipopt -{ - - /** Pure Primal Dual System Solver Base Class. - * This is the base class for all derived Primal-Dual System Solver Types. - * - * Here, we understand the primal-dual system as the following linear - * system: - * - * \f$ - * \left[\begin{array}{cccccccc} - * W & 0 & J_c^T & J_d^T & -P^x_L & P^x_U & 0 & 0 \\ - * 0 & 0 & 0 & -I & 0 & 0 & -P_L^d & P_U^d \\ - * J_c & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ - * J_d & -I & 0 & 0 & 0 & 0 & 0 & 0\\ - * Z_L(P_L^x)^T & 0 & 0 & 0 & Sl^x_L & 0 & 0 & 0\\ - * -Z_U(P_U^x)^T & 0 & 0 & 0 & 0 & Sl^x_U & 0 & 0\\ - * 0 & V_L(P_L^d)^T & 0 & 0 & 0 & 0 & Sl^s_L & 0 \\ - * 0 & -V_U(P_U^d)^T & 0 & 0 & 0 & 0 & 0 & Sl^s_U \\ - * \end{array}\right] - * \left(\begin{array}{c} - * sol_x\\ sol_s\\ sol_c\\ sol_d\\ sol^z_L\\ sol^z_U\\ sol^v_L\\ - * sol^v_U - * \end{array}\right) = - * \left(\begin{array}{c} - * rhs_x\\ rhs_s\\ rhs_c\\ rhs_d\\ rhs^z_L\\ rhs^z_U\\ rhs^v_L\\ - * rhs^v_U - * \end{array}\right) - * \f$ - * - * Here, \f$Sl^x_L = (P^x_L)^T x - x_L\f$, - * \f$Sl^x_U = x_U - (P^x_U)^T x\f$, \f$Sl^d_L = (P^d_L)^T d(x) - d_L\f$, - * \f$Sl^d_U = d_U - (P^d_U)^T d(x)\f$. The results returned to the - * caller is \f$res = \alpha * sol + \beta * res\f$. - * - * The solution of this linear system (in order to compute the search - * direction of the algorthim) usually requires a considerable amount of - * computation time. Therefore, it is important to tailor the solution - * of this system to the characteristics of the problem. The purpose of - * this base class is to provide a generic interface to the algorithm - * that it can use whenever it requires a solution of the above system. - * Particular implementation can then be written to provide the methods - * defined here. - * - * It is implicitly assumed here, that the upper left 2 by 2 block - * is possibly modified (implicitly or explicitly) so that its - * projection onto the null space of the overall constraint - * Jacobian \f$\left[\begin{array}{cc}J_c & 0\\J_d & - * -I\end{array}\right]\f$ is positive definite. This is necessary - * to guarantee certain descent properties of the resulting search - * direction. For example, in the full space implementation, a - * multiple of the identity might be added to the upper left 2 by 2 - * block. - * - * Note that the Solve method might be called several times for different - * right hand sides, but with identical data. Therefore, if possible, - * an implemetation of PDSystem should check whether the incoming data has - * changed, and not redo factorization etc. unless necessary. - */ - class PDSystemSolver: public AlgorithmStrategyObject - { - public: - /** @name /Destructor */ - //@{ - /** Default Constructor */ - PDSystemSolver() - {} - - /** Default destructor */ - virtual ~PDSystemSolver() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Solve the primal dual system, given one right hand side. If - * the flag allow_inexact is set to true, it is not necessary to - * solve the system to best accuracy; for example, we don't want - * iterative refinement during the computation of the second - * order correction. On the other hand, if improve_solution is - * true, the solution given in res should be improved (here beta - * has to be zero, and res is assume to be the solution for the - * system using rhs, without the factor alpha...). THe return - * value is false, if a solution could not be computed (for - * example, when the Hessian regularization parameter becomes too - * large.) - */ - virtual bool Solve(Number alpha, - Number beta, - const IteratesVector& rhs, - IteratesVector& res, - bool allow_inexact=false, - bool improve_solution=false) =0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Overloaded Equals Operator */ - PDSystemSolver& operator=(const PDSystemSolver&); - //@} - }; - - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpReferenced.hpp b/external/ipopt/include/coin/IpReferenced.hpp deleted file mode 100644 index 996beda94..000000000 --- a/external/ipopt/include/coin/IpReferenced.hpp +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpReferenced.hpp 2182 2013-03-30 20:02:18Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPREFERENCED_HPP__ -#define __IPREFERENCED_HPP__ - -#include "IpTypes.hpp" -#include "IpDebug.hpp" - -#include - -#if COIN_IPOPT_CHECKLEVEL > 3 - #define IP_DEBUG_REFERENCED -#endif - -namespace Ipopt -{ - - /** Psydo-class, from which everything has to inherit that wants to - * use be registered as a Referencer for a ReferencedObject. - */ - class Referencer - {} - ; - - /** ReferencedObject class. - * This is part of the implementation of an intrusive smart pointer - * design. This class stores the reference count of all the smart - * pointers that currently reference it. See the documentation for - * the SmartPtr class for more details. - * - * A SmartPtr behaves much like a raw pointer, but manages the lifetime - * of an object, deleting the object automatically. This class implements - * a reference-counting, intrusive smart pointer design, where all - * objects pointed to must inherit off of ReferencedObject, which - * stores the reference count. Although this is intrusive (native types - * and externally authored classes require wrappers to be referenced - * by smart pointers), it is a safer design. A more detailed discussion of - * these issues follows after the usage information. - * - * Usage Example: - * Note: to use the SmartPtr, all objects to which you point MUST - * inherit off of ReferencedObject. - * - * \verbatim - * - * In MyClass.hpp... - * - * #include "IpReferenced.hpp" - - * namespace Ipopt { - * - * class MyClass : public ReferencedObject // must derive from ReferencedObject - * { - * ... - * } - * } // namespace Ipopt - * - * - * In my_usage.cpp... - * - * #include "IpSmartPtr.hpp" - * #include "MyClass.hpp" - * - * void func(AnyObject& obj) - * { - * SmartPtr ptr_to_myclass = new MyClass(...); - * // ptr_to_myclass now points to a new MyClass, - * // and the reference count is 1 - * - * ... - * - * obj.SetMyClass(ptr_to_myclass); - * // Here, let's assume that AnyObject uses a - * // SmartPtr internally here. - * // Now, both ptr_to_myclass and the internal - * // SmartPtr in obj point to the same MyClass object - * // and its reference count is 2. - * - * ... - * - * // No need to delete ptr_to_myclass, this - * // will be done automatically when the - * // reference count drops to zero. - * - * } - * - * \endverbatim - * - * Other Notes: - * The SmartPtr implements both dereference operators -> & *. - * The SmartPtr does NOT implement a conversion operator to - * the raw pointer. Use the GetRawPtr() method when this - * is necessary. Make sure that the raw pointer is NOT - * deleted. - * The SmartPtr implements the comparison operators == & != - * for a variety of types. Use these instead of - * \verbatim - * if (GetRawPtr(smrt_ptr) == ptr) // Don't use this - * \endverbatim - * SmartPtr's, as currently implemented, do NOT handle circular references. - * For example: consider a higher level object using SmartPtrs to point to - * A and B, but A and B also point to each other (i.e. A has a SmartPtr - * to B and B has a SmartPtr to A). In this scenario, when the higher - * level object is finished with A and B, their reference counts will - * never drop to zero (since they reference each other) and they - * will not be deleted. This can be detected by memory leak tools like - * valgrind. If the circular reference is necessary, the problem can be - * overcome by a number of techniques: - * - * 1) A and B can have a method that "releases" each other, that is - * they set their internal SmartPtrs to NULL. - * \verbatim - * void AClass::ReleaseCircularReferences() - * { - * smart_ptr_to_B = NULL; - * } - * \endverbatim - * Then, the higher level class can call these methods before - * it is done using A & B. - * - * 2) Raw pointers can be used in A and B to reference each other. - * Here, an implicit assumption is made that the lifetime is - * controlled by the higher level object and that A and B will - * both exist in a controlled manner. Although this seems - * dangerous, in many situations, this type of referencing - * is very controlled and this is reasonably safe. - * - * 3) This SmartPtr class could be redesigned with the Weak/Strong - * design concept. Here, the SmartPtr is identified as being - * Strong (controls lifetime of the object) or Weak (merely - * referencing the object). The Strong SmartPtr increments - * (and decrements) the reference count in ReferencedObject - * but the Weak SmartPtr does not. In the example above, - * the higher level object would have Strong SmartPtrs to - * A and B, but A and B would have Weak SmartPtrs to each - * other. Then, when the higher level object was done with - * A and B, they would be deleted. The Weak SmartPtrs in A - * and B would not decrement the reference count and would, - * of course, not delete the object. This idea is very similar - * to item (2), where it is implied that the sequence of events - * is controlled such that A and B will not call anything using - * their pointers following the higher level delete (i.e. in - * their destructors!). This is somehow safer, however, because - * code can be written (however expensive) to perform run-time - * detection of this situation. For example, the ReferencedObject - * could store pointers to all Weak SmartPtrs that are referencing - * it and, in its destructor, tell these pointers that it is - * dying. They could then set themselves to NULL, or set an - * internal flag to detect usage past this point. - * - * For every most derived object only one ReferencedObject may exist, - * that is multiple inheritance requires virtual inheritance, see also - * the 2nd point in ticket #162. - * - * Comments on Non-Intrusive Design: - * In a non-intrusive design, the reference count is stored somewhere other - * than the object being referenced. This means, unless the reference - * counting pointer is the first referencer, it must get a pointer to the - * referenced object from another smart pointer (so it has access to the - * reference count location). In this non-intrusive design, if we are - * pointing to an object with a smart pointer (or a number of smart - * pointers), and we then give another smart pointer the address through - * a RAW pointer, we will have two independent, AND INCORRECT, reference - * counts. To avoid this pitfall, we use an intrusive reference counting - * technique where the reference count is stored in the object being - * referenced. - */ - class ReferencedObject - { - public: - ReferencedObject() - : - reference_count_(0) - {} - - virtual ~ReferencedObject() - { - DBG_ASSERT(reference_count_ == 0); - } - - inline - Index ReferenceCount() const; - - inline - void AddRef(const Referencer* referencer) const; - - inline - void ReleaseRef(const Referencer* referencer) const; - - private: - mutable Index reference_count_; - -# ifdef IP_DEBUG_REFERENCED - mutable std::list referencers_; -# endif - - }; - - /* inline methods */ - inline - Index ReferencedObject::ReferenceCount() const - { - // DBG_START_METH("ReferencedObject::ReferenceCount()", 0); - // DBG_PRINT((1,"Returning reference_count_ = %d\n", reference_count_)); - return reference_count_; - } - - inline - void ReferencedObject::AddRef(const Referencer* referencer) const - { - // DBG_START_METH("ReferencedObject::AddRef(const Referencer* referencer)", 0); - reference_count_++; - // DBG_PRINT((1, "New reference_count_ = %d\n", reference_count_)); -# ifdef IP_DEBUG_REFERENCED - referencers_.push_back(referencer); -# endif - - } - - inline - void ReferencedObject::ReleaseRef(const Referencer* referencer) const - { - // DBG_START_METH("ReferencedObject::ReleaseRef(const Referencer* referencer)", - // 0); - reference_count_--; - // DBG_PRINT((1, "New reference_count_ = %d\n", reference_count_)); - -# ifdef IP_DEBUG_REFERENCED - - bool found = false; - std::list::iterator iter; - for (iter = referencers_.begin(); iter != referencers_.end(); iter++) { - if ((*iter) == referencer) { - found = true; - break; - } - } - - // cannot call release on a reference that was never added... - DBG_ASSERT(found); - - if (found) { - referencers_.erase(iter); - } -# endif - - } - - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpRegOptions.hpp b/external/ipopt/include/coin/IpRegOptions.hpp deleted file mode 100644 index 5859493e5..000000000 --- a/external/ipopt/include/coin/IpRegOptions.hpp +++ /dev/null @@ -1,658 +0,0 @@ -// Copyright (C) 2004, 2007 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpRegOptions.hpp 2189 2013-03-31 15:06:11Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2005-06-18 - -#ifndef __IPREGOPTIONS_HPP__ -#define __IPREGOPTIONS_HPP__ - -#include "IpUtils.hpp" -#include "IpReferenced.hpp" -#include "IpException.hpp" -#include "IpSmartPtr.hpp" - -#include - -namespace Ipopt -{ - - enum RegisteredOptionType - { - OT_Number, - OT_Integer, - OT_String, - OT_Unknown - }; - - /** Base class for registered options. The derived types are more - * specific to a string option or a Number (real) option, etc. - */ - class RegisteredOption : public ReferencedObject - { - public: - /** class to hold the valid string settings for a string option */ - class string_entry - { - public: - string_entry(const std::string& value, const std::string& description) - : value_(value), description_(description) - {} - std::string value_; - std::string description_; - }; - - /** Constructors / Destructors */ - //@{ - RegisteredOption(Index counter) - : - type_(OT_Unknown), - has_lower_(false), - has_upper_(false), - counter_(counter) - {} - - RegisteredOption(const std::string& name, - const std::string& short_description, - const std::string& long_description, - const std::string& registering_category, - Index counter) - : - name_(name), - short_description_(short_description), - long_description_(long_description), - registering_category_(registering_category), - type_(OT_Unknown), - has_lower_(false), - has_upper_(false), - counter_(counter) - {} - - RegisteredOption(const RegisteredOption& copy) - : - name_(copy.name_), - short_description_(copy.short_description_), - long_description_(copy.long_description_), - registering_category_(copy.registering_category_), - type_(copy.type_), - has_lower_(copy.has_lower_), - lower_(copy.lower_), - has_upper_(copy.has_upper_), - upper_(copy.upper_), - valid_strings_(copy.valid_strings_), - counter_(copy.counter_) - {} - - virtual ~RegisteredOption() - {} - //@} - - DECLARE_STD_EXCEPTION(ERROR_CONVERTING_STRING_TO_ENUM); - - /** Standard Get / Set Methods */ - //@{ - /** Get the option's name (tag in the input file) */ - virtual const std::string& Name() const - { - return name_; - } - /** Set the option's name (tag in the input file) */ - virtual void SetName(const std::string& name) - { - name_ = name; - } - /** Get the short description */ - virtual const std::string& ShortDescription() const - { - return short_description_; - } - /** Get the long description */ - virtual const std::string& LongDescription() const - { - return long_description_; - } - /** Set the short description */ - virtual void SetShortDescription(const std::string& short_description) - { - short_description_ = short_description; - } - /** Set the long description */ - virtual void SetLongDescription(const std::string& long_description) - { - long_description_ = long_description; - } - /** Get the registering class */ - virtual const std::string& RegisteringCategory() const - { - return registering_category_; - } - /** Set the registering class */ - virtual void SetRegisteringCategory(const std::string& registering_category) - { - registering_category_ = registering_category; - } - /** Get the Option's type */ - virtual const RegisteredOptionType& Type() const - { - return type_; - } - /** Get the Option's type */ - virtual void SetType(const RegisteredOptionType& type) - { - type_ = type; - } - /** Counter */ - virtual Index Counter() const - { - return counter_; - } - //@} - - /** @name Get / Set methods valid for specific types - NOTE: the Type - * must be set before calling these methods. - */ - //@{ - /** check if the option has a lower bound - can be called for - * OT_Number & OT_Integer*/ - virtual const bool& HasLower() const - { - DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer); - return has_lower_; - } - /** check if the lower bound is strict - can be called for - OT_Number */ - virtual const bool& LowerStrict() const - { - DBG_ASSERT(type_ == OT_Number && has_lower_ == true); - return lower_strict_; - } - /** get the Number version of the lower bound - can be called for - * OT_Number */ - virtual Number LowerNumber() const - { - DBG_ASSERT(has_lower_ == true && type_ == OT_Number); - return lower_; - } - /** set the Number version of the lower bound - can be called for - * OT_Number */ - virtual void SetLowerNumber(const Number& lower, const bool& strict) - { - DBG_ASSERT(type_ == OT_Number); - lower_ = lower; - lower_strict_ = strict, has_lower_ = true; - } - /** get the Integer version of the lower bound can be called for - * OT_Integer*/ - virtual Index LowerInteger() const - { - DBG_ASSERT(has_lower_ == true && type_ == OT_Integer); - return (Index)lower_; - } - /** set the Integer version of the lower bound - can be called for - * OT_Integer */ - virtual void SetLowerInteger(const Index& lower) - { - DBG_ASSERT(type_ == OT_Integer); - lower_ = (Number)lower; - has_lower_ = true; - } - /** check if the option has an upper bound - can be called for - * OT_Number & OT_Integer*/ - virtual const bool& HasUpper() const - { - DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer); - return has_upper_; - } - /** check if the upper bound is strict - can be called for - * OT_Number */ - virtual const bool& UpperStrict() const - { - DBG_ASSERT(type_ == OT_Number && has_upper_ == true); - return upper_strict_; - } - /** get the Number version of the upper bound - can be called for - * OT_Number */ - virtual Number UpperNumber() const - { - DBG_ASSERT(has_upper_ == true && type_ == OT_Number); - return upper_; - } - /** set the Number version of the upper bound - can be called for - * OT_Number */ - virtual void SetUpperNumber(const Number& upper, const bool& strict) - { - DBG_ASSERT(type_ == OT_Number); - upper_ = upper; - upper_strict_ = strict; - has_upper_ = true; - } - /** get the Integer version of the upper bound - can be called for - * OT_Integer*/ - virtual Index UpperInteger() const - { - DBG_ASSERT(has_upper_ == true && type_ == OT_Integer); - return (Index)upper_; - } - /** set the Integer version of the upper bound - can be called for - * OT_Integer */ - virtual void SetUpperInteger(const Index& upper) - { - DBG_ASSERT(type_ == OT_Integer); - upper_ = (Number)upper; - has_upper_ = true; - } - /** method to add valid string entries - can be called for - * OT_String */ - virtual void AddValidStringSetting(const std::string value, - const std::string description) - { - DBG_ASSERT(type_ == OT_String); - valid_strings_.push_back(string_entry(value, description)); - } - /** get the default as a Number - can be called for OT_Number */ - virtual Number DefaultNumber() const - { - DBG_ASSERT(type_ == OT_Number); - return default_number_; - } - /** Set the default as a Number - can be called for OT_Number */ - virtual void SetDefaultNumber(const Number& default_value) - { - DBG_ASSERT(type_ == OT_Number); - default_number_ = default_value; - } - /** get the default as an Integer - can be called for OT_Integer*/ - virtual Index DefaultInteger() const - { - DBG_ASSERT(type_ == OT_Integer); - return (Index)default_number_; - } - /** Set the default as an Integer - can be called for - OT_Integer */ - virtual void SetDefaultInteger(const Index& default_value) - { - DBG_ASSERT(type_ == OT_Integer); - default_number_ = (Number)default_value; - } - /** get the default as a string - can be called for OT_String */ - virtual std::string DefaultString() const - { - DBG_ASSERT(type_ == OT_String); - return default_string_; - } - /** get the default as a string, but as the index of the string in - * the list - helps map from a string to an enum- can be called - * for OT_String */ - virtual Index DefaultStringAsEnum() const - { - DBG_ASSERT(type_ == OT_String); - return MapStringSettingToEnum(default_string_); - } - /** Set the default as a string - can be called for OT_String */ - virtual void SetDefaultString(const std::string& default_value) - { - DBG_ASSERT(type_ == OT_String); - default_string_ = default_value; - } - /** get the valid string settings - can be called for OT_String */ - virtual std::vector GetValidStrings() const - { - DBG_ASSERT(type_ == OT_String); - return valid_strings_; - } - /** Check if the Number value is a valid setting - can be called - * for OT_Number */ - virtual bool IsValidNumberSetting(const Number& value) const - { - DBG_ASSERT(type_ == OT_Number); - if (has_lower_ && ((lower_strict_ == true && value <= lower_) || - (lower_strict_ == false && value < lower_))) { - return false; - } - if (has_upper_ && ((upper_strict_ == true && value >= upper_) || - (upper_strict_ == false && value > upper_))) { - return false; - } - return true; - } - /** Check if the Integer value is a valid setting - can be called - * for OT_Integer */ - virtual bool IsValidIntegerSetting(const Index& value) const - { - DBG_ASSERT(type_ == OT_Integer); - if (has_lower_ && value < lower_) { - return false; - } - if (has_upper_ && value > upper_) { - return false; - } - return true; - } - /** Check if the String value is a valid setting - can be called - * for OT_String */ - virtual bool IsValidStringSetting(const std::string& value) const; - - /** Map a user setting (allowing any case) to the case used when - * the setting was registered. - */ - virtual std::string MapStringSetting(const std::string& value) const; - - /** Map a user setting (allowing any case) to the index of the - * matched setting in the list of string settings. Helps map a - * string setting to an enumeration. - */ - virtual Index MapStringSettingToEnum(const std::string& value) const; - //@} - - /** output a description of the option */ - virtual void OutputDescription(const Journalist& jnlst) const; - /** output a more concise version */ - virtual void OutputShortDescription(const Journalist& jnlst) const; - /** output a latex version */ - virtual void OutputLatexDescription(const Journalist& jnlst) const; - - private: - std::string name_; - std::string short_description_; - std::string long_description_; - std::string registering_category_; - RegisteredOptionType type_; - - bool has_lower_; - bool lower_strict_; - Number lower_; - bool has_upper_; - bool upper_strict_; - Number upper_; - Number default_number_; - - void MakeValidLatexString(std::string source, std::string& dest) const; - std::string MakeValidLatexNumber(Number value) const; - - /** Compare two strings and return true if they are equal (case - insensitive comparison) */ - bool string_equal_insensitive(const std::string& s1, - const std::string& s2) const; - - std::vector valid_strings_; - std::string default_string_; - - /** Has the information as how many-th option this one was - * registered. */ - const Index counter_; - }; - - /** Class for storing registered options. Used for validation and - * documentation. - */ - class RegisteredOptions : public ReferencedObject - { - public: - /** Constructors / Destructors */ - //@{ - /** Standard Constructor */ - RegisteredOptions() - : - next_counter_(0), - current_registering_category_("Uncategorized") - {} - - /** Standard Destructor */ - virtual ~RegisteredOptions() - {} - //@} - - DECLARE_STD_EXCEPTION(OPTION_ALREADY_REGISTERED); - - /** Methods to interact with registered options */ - //@{ - /** set the registering class. All subsequent options will be - * added with the registered class */ - virtual void SetRegisteringCategory(const std::string& registering_category) - { - current_registering_category_ = registering_category; - } - - /** retrieve the value of the current registering category */ - virtual std::string RegisteringCategory() - { - return current_registering_category_; - } - - /** Add a Number option (with no restrictions) */ - virtual void AddNumberOption(const std::string& name, - const std::string& short_description, - Number default_value, - const std::string& long_description=""); - /** Add a Number option (with a lower bound) */ - virtual void AddLowerBoundedNumberOption(const std::string& name, - const std::string& short_description, - Number lower, bool strict, - Number default_value, - const std::string& long_description=""); - /** Add a Number option (with a upper bound) */ - virtual void AddUpperBoundedNumberOption(const std::string& name, - const std::string& short_description, - Number upper, bool strict, - Number default_value, - const std::string& long_description=""); - /** Add a Number option (with a both bounds) */ - virtual void AddBoundedNumberOption(const std::string& name, - const std::string& short_description, - Number lower, bool lower_strict, - Number upper, bool upper_strict, - Number default_value, - const std::string& long_description=""); - /** Add a Integer option (with no restrictions) */ - virtual void AddIntegerOption(const std::string& name, - const std::string& short_description, - Index default_value, - const std::string& long_description=""); - /** Add a Integer option (with a lower bound) */ - virtual void AddLowerBoundedIntegerOption(const std::string& name, - const std::string& short_description, - Index lower, Index default_value, - const std::string& long_description=""); - /** Add a Integer option (with a upper bound) */ - virtual void AddUpperBoundedIntegerOption(const std::string& name, - const std::string& short_description, - Index upper, Index default_value, - const std::string& long_description=""); - /** Add a Integer option (with a both bounds) */ - virtual void AddBoundedIntegerOption(const std::string& name, - const std::string& short_description, - Index lower, Index upper, - Index default_value, - const std::string& long_description=""); - - /** Add a String option (with no restrictions) */ - virtual void AddStringOption(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::vector& settings, - const std::vector& descriptions, - const std::string& long_description=""); - /** Methods that make adding string options with only a few - * entries easier */ - virtual void AddStringOption1(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& long_description=""); - virtual void AddStringOption2(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& long_description=""); - virtual void AddStringOption3(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& long_description=""); - virtual void AddStringOption4(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& long_description=""); - virtual void AddStringOption5(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& setting5, - const std::string& description5, - const std::string& long_description=""); - virtual void AddStringOption6(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& setting5, - const std::string& description5, - const std::string& setting6, - const std::string& description6, - const std::string& long_description=""); - virtual void AddStringOption7(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& setting5, - const std::string& description5, - const std::string& setting6, - const std::string& description6, - const std::string& setting7, - const std::string& description7, - const std::string& long_description=""); - virtual void AddStringOption8(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& setting5, - const std::string& description5, - const std::string& setting6, - const std::string& description6, - const std::string& setting7, - const std::string& description7, - const std::string& setting8, - const std::string& description8, - const std::string& long_description=""); - virtual void AddStringOption9(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& setting5, - const std::string& description5, - const std::string& setting6, - const std::string& description6, - const std::string& setting7, - const std::string& description7, - const std::string& setting8, - const std::string& description8, - const std::string& setting9, - const std::string& description9, - const std::string& long_description=""); - virtual void AddStringOption10(const std::string& name, - const std::string& short_description, - const std::string& default_value, - const std::string& setting1, - const std::string& description1, - const std::string& setting2, - const std::string& description2, - const std::string& setting3, - const std::string& description3, - const std::string& setting4, - const std::string& description4, - const std::string& setting5, - const std::string& description5, - const std::string& setting6, - const std::string& description6, - const std::string& setting7, - const std::string& description7, - const std::string& setting8, - const std::string& description8, - const std::string& setting9, - const std::string& description9, - const std::string& setting10, - const std::string& description10, - const std::string& long_description=""); - - /** Get a registered option - this will return NULL if the option - * does not exist */ - virtual SmartPtr GetOption(const std::string& name); - - /** Output documentation for the options - gives a description, - * etc. */ - virtual void OutputOptionDocumentation(const Journalist& jnlst, std::list& categories); - - /** Output documentation in Latex format to include in a latex file */ - virtual void OutputLatexOptionDocumentation(const Journalist& jnlst, std::list& categories); - //@} - - typedef std::map > RegOptionsList; - - /** Giving access to iteratable representation of the registered - * options */ - virtual const RegOptionsList& RegisteredOptionsList () const - { - return registered_options_; - } - - private: - Index next_counter_; - std::string current_registering_category_; - std::map > registered_options_; - }; -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpReturnCodes.h b/external/ipopt/include/coin/IpReturnCodes.h deleted file mode 100644 index b16d2c631..000000000 --- a/external/ipopt/include/coin/IpReturnCodes.h +++ /dev/null @@ -1,18 +0,0 @@ -/*********************************************************************** -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpReturnCodes.h 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 -************************************************************************/ - -#ifndef __IPRETURNCODES_H__ -#define __IPRETURNCODES_H__ - -/* include from a common include file */ - -#include "IpReturnCodes_inc.h" - -#endif diff --git a/external/ipopt/include/coin/IpReturnCodes.hpp b/external/ipopt/include/coin/IpReturnCodes.hpp deleted file mode 100644 index 36dd7d701..000000000 --- a/external/ipopt/include/coin/IpReturnCodes.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/*********************************************************************** -// Copyright (C) 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpReturnCodes.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Andreas Waechter IBM 2006-03-01 -************************************************************************/ - -#ifndef __IPRETURNCODES_HPP__ -#define __IPRETURNCODES_HPP__ - -/* include from a common include file */ - -namespace Ipopt -{ -#include "IpReturnCodes_inc.h" -} - -#endif diff --git a/external/ipopt/include/coin/IpReturnCodes.inc b/external/ipopt/include/coin/IpReturnCodes.inc deleted file mode 100644 index c6bf70a45..000000000 --- a/external/ipopt/include/coin/IpReturnCodes.inc +++ /dev/null @@ -1,70 +0,0 @@ -C Copyright (C) 2005, 2009 International Business Machines and others. -C All Rights Reserved. -C This code is published under the Eclipse Public License. -C -C $Id: IpReturnCodes.inc 1861 2010-12-21 21:34:47Z andreasw $ -C -C Author: Andreas Waechter IBM 2005-08-11 -C - INTEGER IP_SOLVE_SUCCEEDED - PARAMETER( IP_SOLVE_SUCCEEDED = 0 ) - - INTEGER IP_ACCEPTABLE_LEVEL - PARAMETER( IP_ACCEPTABLE_LEVEL = 1 ) - - INTEGER IP_INFEASIBLE_PROBLEM - PARAMETER( IP_INFEASIBLE_PROBLEM = 2 ) - - INTEGER IP_SEARCH_DIRECTION_TOO_SMALL - PARAMETER( IP_SEARCH_DIRECTION_TOO_SMALL = 3 ) - - INTEGER IP_DIVERGING_ITERATES - PARAMETER( IP_DIVERGING_ITERATES = 4 ) - - INTEGER IP_USER_REQUESTED_STOP - PARAMETER( IP_USER_REQUESTED_STOP = 5 ) - - INTEGER IP_FEASIBLE_POINT_FOUND - PARAMETER( IP_FEASIBLE_POINT_FOUND = 6 ) - - INTEGER IP_ITERATION_EXCEEDED - PARAMETER( IP_ITERATION_EXCEEDED = -1 ) - - INTEGER IP_RESTORATION_FAILED - PARAMETER( IP_RESTORATION_FAILED = -2 ) - - INTEGER IP_ERROR_IN_STEP_COMPUTATION - PARAMETER( IP_ERROR_IN_STEP_COMPUTATION = -3 ) - - INTEGER IP_CPUTIME_EXCEEDED - PARAMETER( IP_CPUTIME_EXCEEDED = -4 ) - - INTEGER IP_NOT_ENOUGH_DEGREES_OF_FRE - PARAMETER( IP_NOT_ENOUGH_DEGREES_OF_FRE = -10 ) - - INTEGER IP_INVALID_PROBLEM_DEFINITION - PARAMETER( IP_INVALID_PROBLEM_DEFINITION = -11) - - INTEGER IP_INVALID_OPTION - PARAMETER( IP_INVALID_OPTION = -12 ) - - INTEGER IP_INVALID_NUMBER_DETECTED - PARAMETER( IP_INVALID_NUMBER_DETECTED = -13 ) - - INTEGER IP_UNRECOVERABLE_EXCEPTION - PARAMETER( IP_UNRECOVERABLE_EXCEPTION = -100 ) - - INTEGER IP_NON_IPOPT_EXCEPTION - PARAMETER( IP_NON_IPOPT_EXCEPTION = -101 ) - - INTEGER IP_INSUFFICIENT_MEMORY - PARAMETER( IP_INSUFFICIENT_MEMORY = -102 ) - - INTEGER IP_INTERNAL_ERROR - PARAMETER( IP_INTERNAL_ERROR = -199 ) - - INTEGER IP_REGULAR_MODE - PARAMETER( IP_REGULAR_MODE = 0 ) - - INTEGER IP_RESTORATION_PHASE_MODE - PARAMETER( IP_RESTORATION_PHASE_MODE = 1 ) diff --git a/external/ipopt/include/coin/IpReturnCodes_inc.h b/external/ipopt/include/coin/IpReturnCodes_inc.h deleted file mode 100644 index 80190ed1e..000000000 --- a/external/ipopt/include/coin/IpReturnCodes_inc.h +++ /dev/null @@ -1,46 +0,0 @@ -/*********************************************************************** -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpReturnCodes_inc.h 2216 2013-04-14 17:06:00Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 -************************************************************************/ - -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -/* !!!!!!!!! REMEMBER TO UPDATE IpReturnCodes.inc and Ipopt.java !!!!!!!! */ -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ - -/** Return codes for the Optimize call for an application */ -enum ApplicationReturnStatus - { - Solve_Succeeded=0, - Solved_To_Acceptable_Level=1, - Infeasible_Problem_Detected=2, - Search_Direction_Becomes_Too_Small=3, - Diverging_Iterates=4, - User_Requested_Stop=5, - Feasible_Point_Found=6, - - Maximum_Iterations_Exceeded=-1, - Restoration_Failed=-2, - Error_In_Step_Computation=-3, - Maximum_CpuTime_Exceeded=-4, - Not_Enough_Degrees_Of_Freedom=-10, - Invalid_Problem_Definition=-11, - Invalid_Option=-12, - Invalid_Number_Detected=-13, - - Unrecoverable_Exception=-100, - NonIpopt_Exception_Thrown=-101, - Insufficient_Memory=-102, - Internal_Error=-199 - }; - -/** enum to indicate the mode in which the algorithm is */ -enum AlgorithmMode - { - RegularMode=0, - RestorationPhaseMode=1 - }; diff --git a/external/ipopt/include/coin/IpScaledMatrix.hpp b/external/ipopt/include/coin/IpScaledMatrix.hpp deleted file mode 100644 index c182a0547..000000000 --- a/external/ipopt/include/coin/IpScaledMatrix.hpp +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpScaledMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSCALEDMATRIX_HPP__ -#define __IPSCALEDMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class ScaledMatrixSpace; - - /** Class for a Matrix in conjunction with its scaling factors for - * row and column scaling. Operations on the matrix are performed using - * the scaled matrix. You can pull out the pointer to the - * unscaled matrix for unscaled calculations. - */ - class ScaledMatrix : public Matrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the owner_space. - */ - ScaledMatrix(const ScaledMatrixSpace* owner_space); - - /** Destructor */ - ~ScaledMatrix(); - //@} - - /** Set the unscaled matrix */ - void SetUnscaledMatrix(const SmartPtr unscaled_matrix); - - /** Set the unscaled matrix in a non-const version */ - void SetUnscaledMatrixNonConst(const SmartPtr& unscaled_matrix); - - /** Return the unscaled matrix in const form */ - SmartPtr GetUnscaledMatrix() const; - - /** Return the unscaled matrix in non-const form */ - SmartPtr GetUnscaledMatrixNonConst(); - - /** return the vector for the row scaling */ - SmartPtr RowScaling() const; - - /** return the vector for the column scaling */ - SmartPtr ColumnScaling() const; - - protected: - /**@name Methods overloaded from Matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - virtual void TransMultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). It is assumed that the scaling factors are - * valid. */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - - /** X = beta*X + alpha*(Matrix S^{-1} Z). Specialized - * implementation missing so far! - */ - virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z, - Vector& X) const; - - /** X = S^{-1} (r + alpha*Z*M^Td). Specialized implementation - * missing so far! - */ - virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S, - const Vector& R, const Vector& Z, - const Vector& D, Vector& X) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - ScaledMatrix(); - - /** Copy Constructor */ - ScaledMatrix(const ScaledMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const ScaledMatrix&); - //@} - - /** const version of the unscaled matrix */ - SmartPtr matrix_; - /** non-const version of the unscaled matrix */ - SmartPtr nonconst_matrix_; - - /** Matrix space stored as a ScaledMatrixSpace */ - SmartPtr owner_space_; - }; - - /** This is the matrix space for ScaledMatrix. - */ - class ScaledMatrixSpace : public MatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of row and columns blocks, as - * well as the totel number of rows and columns. - */ - ScaledMatrixSpace(const SmartPtr& row_scaling, - bool row_scaling_reciprocal, - const SmartPtr& unscaled_matrix_space, - const SmartPtr& column_scaling, - bool column_scaling_reciprocal); - - /** Destructor */ - ~ScaledMatrixSpace() - {} - //@} - - /** Method for creating a new matrix of this specific type. */ - ScaledMatrix* MakeNewScaledMatrix(bool allocate_unscaled_matrix = false) const - { - ScaledMatrix* ret = new ScaledMatrix(this); - if (allocate_unscaled_matrix) { - SmartPtr unscaled_matrix = unscaled_matrix_space_->MakeNew(); - ret->SetUnscaledMatrixNonConst(unscaled_matrix); - } - return ret; - } - - /** Overloaded MakeNew method for the MatrixSpace base class. - */ - virtual Matrix* MakeNew() const - { - return MakeNewScaledMatrix(); - } - - /** return the vector for the row scaling */ - SmartPtr RowScaling() const - { - return ConstPtr(row_scaling_); - } - - /** return the matrix space for the unscaled matrix */ - SmartPtr UnscaledMatrixSpace() const - { - return unscaled_matrix_space_; - } - - /** return the vector for the column scaling */ - SmartPtr ColumnScaling() const - { - return ConstPtr(column_scaling_); - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default constructor */ - ScaledMatrixSpace(); - - /** Copy Constructor */ - ScaledMatrixSpace(const ScaledMatrixSpace&); - - /** Overloaded Equals Operator */ - ScaledMatrixSpace& operator=(const ScaledMatrixSpace&); - //@} - - /** Row scaling vector */ - SmartPtr row_scaling_; - /** unscaled matrix space */ - SmartPtr unscaled_matrix_space_; - /** column scaling vector */ - SmartPtr column_scaling_; - }; - - inline - void ScaledMatrix::SetUnscaledMatrix(const SmartPtr unscaled_matrix) - { - matrix_ = unscaled_matrix; - nonconst_matrix_ = NULL; - ObjectChanged(); - } - - inline - void ScaledMatrix::SetUnscaledMatrixNonConst(const SmartPtr& unscaled_matrix) - { - nonconst_matrix_ = unscaled_matrix; - matrix_ = GetRawPtr(unscaled_matrix); - ObjectChanged(); - } - - inline - SmartPtr ScaledMatrix::GetUnscaledMatrix() const - { - return matrix_; - } - - inline - SmartPtr ScaledMatrix::GetUnscaledMatrixNonConst() - { - DBG_ASSERT(IsValid(nonconst_matrix_)); - ObjectChanged(); - return nonconst_matrix_; - } - - inline - SmartPtr ScaledMatrix::RowScaling() const - { - return ConstPtr(owner_space_->RowScaling()); - } - - inline - SmartPtr ScaledMatrix::ColumnScaling() const - { - return ConstPtr(owner_space_->ColumnScaling()); - } - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpSearchDirCalculator.hpp b/external/ipopt/include/coin/IpSearchDirCalculator.hpp deleted file mode 100644 index 3425c43c6..000000000 --- a/external/ipopt/include/coin/IpSearchDirCalculator.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2005, 2007 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSearchDirCalculator.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Andreas Waechter IBM 2005-10-13 - -#ifndef __IPSEARCHDIRCALCULATOR_HPP__ -#define __IPSEARCHDIRCALCULATOR_HPP__ - -#include "IpAlgStrategy.hpp" - -namespace Ipopt -{ - - /** Base class for computing the search direction for the line - * search. - */ - class SearchDirectionCalculator : public AlgorithmStrategyObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor */ - SearchDirectionCalculator() - {} - - /** Default destructor */ - virtual ~SearchDirectionCalculator() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** Pure virtual method for computing the search direction. The - * computed direction is stored in IpData().delta().*/ - virtual bool ComputeSearchDirection()=0; - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - // SearchDirectionCalculator(); - - /** Copy Constructor */ - SearchDirectionCalculator(const SearchDirectionCalculator&); - - /** Overloaded Equals Operator */ - void operator=(const SearchDirectionCalculator&); - //@} - - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpSmartPtr.hpp b/external/ipopt/include/coin/IpSmartPtr.hpp deleted file mode 100644 index dec0ab56c..000000000 --- a/external/ipopt/include/coin/IpSmartPtr.hpp +++ /dev/null @@ -1,734 +0,0 @@ -// Copyright (C) 2004, 2011 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSmartPtr.hpp 2182 2013-03-30 20:02:18Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSMARTPTR_HPP__ -#define __IPSMARTPTR_HPP__ - -#include "IpReferenced.hpp" - -#include "IpDebug.hpp" -#if COIN_IPOPT_CHECKLEVEL > 2 -# define IP_DEBUG_SMARTPTR -#endif -#ifndef IPOPT_UNUSED -# if defined(__GNUC__) -# define IPOPT_UNUSED __attribute__((unused)) -# else -# define IPOPT_UNUSED -# endif -#endif - -namespace Ipopt -{ - - /** Template class for Smart Pointers. - * A SmartPtr behaves much like a raw pointer, but manages the lifetime - * of an object, deleting the object automatically. This class implements - * a reference-counting, intrusive smart pointer design, where all - * objects pointed to must inherit off of ReferencedObject, which - * stores the reference count. Although this is intrusive (native types - * and externally authored classes require wrappers to be referenced - * by smart pointers), it is a safer design. A more detailed discussion of - * these issues follows after the usage information. - * - * Usage Example: - * Note: to use the SmartPtr, all objects to which you point MUST - * inherit off of ReferencedObject. - * - * \verbatim - * - * In MyClass.hpp... - * - * #include "IpReferenced.hpp" - - * namespace Ipopt { - * - * class MyClass : public ReferencedObject // must derive from ReferencedObject - * { - * ... - * } - * } // namespace Ipopt - * - * - * In my_usage.cpp... - * - * #include "IpSmartPtr.hpp" - * #include "MyClass.hpp" - * - * void func(AnyObject& obj) - * { - * SmartPtr ptr_to_myclass = new MyClass(...); - * // ptr_to_myclass now points to a new MyClass, - * // and the reference count is 1 - * - * ... - * - * obj.SetMyClass(ptr_to_myclass); - * // Here, let's assume that AnyObject uses a - * // SmartPtr internally here. - * // Now, both ptr_to_myclass and the internal - * // SmartPtr in obj point to the same MyClass object - * // and its reference count is 2. - * - * ... - * - * // No need to delete ptr_to_myclass, this - * // will be done automatically when the - * // reference count drops to zero. - * - * } - * - * \endverbatim - * - * It is not necessary to use SmartPtr's in all cases where an - * object is used that has been allocated "into" a SmartPtr. It is - * possible to just pass objects by reference or regular pointers, - * even if lower down in the stack a SmartPtr is to be held on to. - * Everything should work fine as long as a pointer created by "new" - * is immediately passed into a SmartPtr, and if SmartPtr's are used - * to hold on to objects. - * - * Other Notes: - * The SmartPtr implements both dereference operators -> & *. - * The SmartPtr does NOT implement a conversion operator to - * the raw pointer. Use the GetRawPtr() method when this - * is necessary. Make sure that the raw pointer is NOT - * deleted. - * The SmartPtr implements the comparison operators == & != - * for a variety of types. Use these instead of - * \verbatim - * if (GetRawPtr(smrt_ptr) == ptr) // Don't use this - * \endverbatim - * SmartPtr's, as currently implemented, do NOT handle circular references. - * For example: consider a higher level object using SmartPtrs to point to - * A and B, but A and B also point to each other (i.e. A has a SmartPtr - * to B and B has a SmartPtr to A). In this scenario, when the higher - * level object is finished with A and B, their reference counts will - * never drop to zero (since they reference each other) and they - * will not be deleted. This can be detected by memory leak tools like - * valgrind. If the circular reference is necessary, the problem can be - * overcome by a number of techniques: - * - * 1) A and B can have a method that "releases" each other, that is - * they set their internal SmartPtrs to NULL. - * \verbatim - * void AClass::ReleaseCircularReferences() - * { - * smart_ptr_to_B = NULL; - * } - * \endverbatim - * Then, the higher level class can call these methods before - * it is done using A & B. - * - * 2) Raw pointers can be used in A and B to reference each other. - * Here, an implicit assumption is made that the lifetime is - * controlled by the higher level object and that A and B will - * both exist in a controlled manner. Although this seems - * dangerous, in many situations, this type of referencing - * is very controlled and this is reasonably safe. - * - * 3) This SmartPtr class could be redesigned with the Weak/Strong - * design concept. Here, the SmartPtr is identified as being - * Strong (controls lifetime of the object) or Weak (merely - * referencing the object). The Strong SmartPtr increments - * (and decrements) the reference count in ReferencedObject - * but the Weak SmartPtr does not. In the example above, - * the higher level object would have Strong SmartPtrs to - * A and B, but A and B would have Weak SmartPtrs to each - * other. Then, when the higher level object was done with - * A and B, they would be deleted. The Weak SmartPtrs in A - * and B would not decrement the reference count and would, - * of course, not delete the object. This idea is very similar - * to item (2), where it is implied that the sequence of events - * is controlled such that A and B will not call anything using - * their pointers following the higher level delete (i.e. in - * their destructors!). This is somehow safer, however, because - * code can be written (however expensive) to perform run-time - * detection of this situation. For example, the ReferencedObject - * could store pointers to all Weak SmartPtrs that are referencing - * it and, in its destructor, tell these pointers that it is - * dying. They could then set themselves to NULL, or set an - * internal flag to detect usage past this point. - * - * Comments on Non-Intrusive Design: - * In a non-intrusive design, the reference count is stored somewhere other - * than the object being referenced. This means, unless the reference - * counting pointer is the first referencer, it must get a pointer to the - * referenced object from another smart pointer (so it has access to the - * reference count location). In this non-intrusive design, if we are - * pointing to an object with a smart pointer (or a number of smart - * pointers), and we then give another smart pointer the address through - * a RAW pointer, we will have two independent, AND INCORRECT, reference - * counts. To avoid this pitfall, we use an intrusive reference counting - * technique where the reference count is stored in the object being - * referenced. - */ - template - class SmartPtr : public Referencer - { - public: -#define ipopt_dbg_smartptr_verbosity 0 - - /**@name Constructors/Destructors */ - //@{ - /** Default constructor, initialized to NULL */ - SmartPtr(); - - /** Copy constructor, initialized from copy of type T */ - SmartPtr(const SmartPtr& copy); - - /** Copy constructor, initialized from copy of type U */ - template - SmartPtr(const SmartPtr& copy); - - /** Constructor, initialized from T* ptr */ - SmartPtr(T* ptr); - - /** Destructor, automatically decrements the - * reference count, deletes the object if - * necessary.*/ - ~SmartPtr(); - //@} - - /**@name Overloaded operators. */ - //@{ - /** Overloaded arrow operator, allows the user to call - * methods using the contained pointer. */ - T* operator->() const; - - /** Overloaded dereference operator, allows the user - * to dereference the contained pointer. */ - T& operator*() const; - - /** Overloaded equals operator, allows the user to - * set the value of the SmartPtr from a raw pointer */ - SmartPtr& operator=(T* rhs); - - /** Overloaded equals operator, allows the user to - * set the value of the SmartPtr from another - * SmartPtr */ - SmartPtr& operator=(const SmartPtr& rhs); - - /** Overloaded equals operator, allows the user to - * set the value of the SmartPtr from another - * SmartPtr of a different type */ - template - SmartPtr& operator=(const SmartPtr& rhs); - - /** Overloaded equality comparison operator, allows the - * user to compare the value of two SmartPtrs */ - template - friend - bool operator==(const SmartPtr& lhs, const SmartPtr& rhs); - - /** Overloaded equality comparison operator, allows the - * user to compare the value of a SmartPtr with a raw pointer. */ - template - friend - bool operator==(const SmartPtr& lhs, U2* raw_rhs); - - /** Overloaded equality comparison operator, allows the - * user to compare the value of a raw pointer with a SmartPtr. */ - template - friend - bool operator==(U1* lhs, const SmartPtr& raw_rhs); - - /** Overloaded in-equality comparison operator, allows the - * user to compare the value of two SmartPtrs */ - template - friend - bool operator!=(const SmartPtr& lhs, const SmartPtr& rhs); - - /** Overloaded in-equality comparison operator, allows the - * user to compare the value of a SmartPtr with a raw pointer. */ - template - friend - bool operator!=(const SmartPtr& lhs, U2* raw_rhs); - - /** Overloaded in-equality comparison operator, allows the - * user to compare the value of a SmartPtr with a raw pointer. */ - template - friend - bool operator!=(U1* lhs, const SmartPtr& raw_rhs); - - /** Overloaded less-than comparison operator, allows the - * user to compare the value of two SmartPtrs */ - template - friend - bool operator<(const SmartPtr& lhs, const SmartPtr& rhs); - //@} - - /**@name friend method declarations. */ - //@{ - /** Returns the raw pointer contained. - * Use to get the value of - * the raw ptr (i.e. to pass to other - * methods/functions, etc.) - * Note: This method does NOT copy, - * therefore, modifications using this - * value modify the underlying object - * contained by the SmartPtr, - * NEVER delete this returned value. - */ - template - friend - U* GetRawPtr(const SmartPtr& smart_ptr); - - /** Returns a const pointer */ - template - friend - SmartPtr ConstPtr(const SmartPtr& smart_ptr); - - /** Returns true if the SmartPtr is NOT NULL. - * Use this to check if the SmartPtr is not null - * This is preferred to if(GetRawPtr(sp) != NULL) - */ - template - friend - bool IsValid(const SmartPtr& smart_ptr); - - /** Returns true if the SmartPtr is NULL. - * Use this to check if the SmartPtr IsNull. - * This is preferred to if(GetRawPtr(sp) == NULL) - */ - template - friend - bool IsNull(const SmartPtr& smart_ptr); - //@} - - private: - /**@name Private Data/Methods */ - //@{ - /** Actual raw pointer to the object. */ - T* ptr_; - - /** Set the value of the internal raw pointer - * from another raw pointer, releasing the - * previously referenced object if necessary. */ - SmartPtr& SetFromRawPtr_(T* rhs); - - /** Set the value of the internal raw pointer - * from a SmartPtr, releasing the previously referenced - * object if necessary. */ - SmartPtr& SetFromSmartPtr_(const SmartPtr& rhs); - - /** Release the currently referenced object. */ - void ReleasePointer_(); - //@} - }; - - /**@name SmartPtr friend function declarations.*/ - //@{ - template - U* GetRawPtr(const SmartPtr& smart_ptr); - - template - SmartPtr ConstPtr(const SmartPtr& smart_ptr); - - template - bool IsNull(const SmartPtr& smart_ptr); - - template - bool IsValid(const SmartPtr& smart_ptr); - - template - bool operator==(const SmartPtr& lhs, const SmartPtr& rhs); - - template - bool operator==(const SmartPtr& lhs, U2* raw_rhs); - - template - bool operator==(U1* lhs, const SmartPtr& raw_rhs); - - template - bool operator!=(const SmartPtr& lhs, const SmartPtr& rhs); - - template - bool operator!=(const SmartPtr& lhs, U2* raw_rhs); - - template - bool operator!=(U1* lhs, const SmartPtr& raw_rhs); - - //@} - - - template - SmartPtr::SmartPtr() - : - ptr_(0) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("SmartPtr::SmartPtr()", ipopt_dbg_smartptr_verbosity); -#endif - -#ifndef NDEBUG - const ReferencedObject* IPOPT_UNUSED trying_to_use_SmartPtr_with_an_object_that_does_not_inherit_from_ReferencedObject_ = ptr_; -#endif - - } - - - template - SmartPtr::SmartPtr(const SmartPtr& copy) - : - ptr_(0) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("SmartPtr::SmartPtr(const SmartPtr& copy)", ipopt_dbg_smartptr_verbosity); -#endif - -#ifndef NDEBUG - const ReferencedObject* IPOPT_UNUSED trying_to_use_SmartPtr_with_an_object_that_does_not_inherit_from_ReferencedObject_ = ptr_; -#endif - - (void) SetFromSmartPtr_(copy); - } - - - template - template - SmartPtr::SmartPtr(const SmartPtr& copy) - : - ptr_(0) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("SmartPtr::SmartPtr(const SmartPtr& copy)", ipopt_dbg_smartptr_verbosity); -#endif - -#ifndef NDEBUG - const ReferencedObject* IPOPT_UNUSED trying_to_use_SmartPtr_with_an_object_that_does_not_inherit_from_ReferencedObject_ = ptr_; -#endif - - (void) SetFromSmartPtr_(GetRawPtr(copy)); - } - - - template - SmartPtr::SmartPtr(T* ptr) - : - ptr_(0) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("SmartPtr::SmartPtr(T* ptr)", ipopt_dbg_smartptr_verbosity); -#endif - -#ifndef NDEBUG - const ReferencedObject* IPOPT_UNUSED trying_to_use_SmartPtr_with_an_object_that_does_not_inherit_from_ReferencedObject_ = ptr_; -#endif - - (void) SetFromRawPtr_(ptr); - } - - template - SmartPtr::~SmartPtr() - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("SmartPtr::~SmartPtr(T* ptr)", ipopt_dbg_smartptr_verbosity); -#endif - - ReleasePointer_(); - } - - - template - T* SmartPtr::operator->() const - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("T* SmartPtr::operator->()", ipopt_dbg_smartptr_verbosity); -#endif - - // cannot deref a null pointer -#if COIN_IPOPT_CHECKLEVEL > 0 - assert(ptr_); -#endif - - return ptr_; - } - - - template - T& SmartPtr::operator*() const - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("T& SmartPtr::operator*()", ipopt_dbg_smartptr_verbosity); -#endif - - // cannot dereference a null pointer -#if COIN_IPOPT_CHECKLEVEL > 0 - assert(ptr_); -#endif - - return *ptr_; - } - - - template - SmartPtr& SmartPtr::operator=(T* rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH("SmartPtr& SmartPtr::operator=(T* rhs)", ipopt_dbg_smartptr_verbosity); -#endif - - return SetFromRawPtr_(rhs); - } - - - template - SmartPtr& SmartPtr::operator=(const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH( - "SmartPtr& SmartPtr::operator=(const SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - return SetFromSmartPtr_(rhs); - } - - - template - template - SmartPtr& SmartPtr::operator=(const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH( - "SmartPtr& SmartPtr::operator=(const SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - return SetFromSmartPtr_(GetRawPtr(rhs)); - } - - - template - SmartPtr& SmartPtr::SetFromRawPtr_(T* rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH( - "SmartPtr& SmartPtr::SetFromRawPtr_(T* rhs)", ipopt_dbg_smartptr_verbosity); -#endif - - if (rhs != 0) - rhs->AddRef(this); - - // Release any old pointer - ReleasePointer_(); - - ptr_ = rhs; - - return *this; - } - - template - SmartPtr& SmartPtr::SetFromSmartPtr_(const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH( - "SmartPtr& SmartPtr::SetFromSmartPtr_(const SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - SetFromRawPtr_(GetRawPtr(rhs)); - - return (*this); - } - - - template - void SmartPtr::ReleasePointer_() - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_METH( - "void SmartPtr::ReleasePointer()", - ipopt_dbg_smartptr_verbosity); -#endif - - if (ptr_) { - ptr_->ReleaseRef(this); - if (ptr_->ReferenceCount() == 0) - delete ptr_; - } - } - - - template - U* GetRawPtr(const SmartPtr& smart_ptr) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "T* GetRawPtr(const SmartPtr& smart_ptr)", - 0); -#endif - - return smart_ptr.ptr_; - } - - template - SmartPtr ConstPtr(const SmartPtr& smart_ptr) - { - // compiler should implicitly cast - return GetRawPtr(smart_ptr); - } - - template - bool IsValid(const SmartPtr& smart_ptr) - { - return !IsNull(smart_ptr); - } - - template - bool IsNull(const SmartPtr& smart_ptr) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool IsNull(const SmartPtr& smart_ptr)", - 0); -#endif - - return (smart_ptr.ptr_ == 0); - } - - - template - bool ComparePointers(const U1* lhs, const U2* rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool ComparePtrs(const U1* lhs, const U2* rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - // Even if lhs and rhs point to the same object - // with different interfaces U1 and U2, we cannot guarantee that - // the value of the pointers will be equivalent. We can - // guarantee this if we convert to ReferencedObject* (see also #162) - const ReferencedObject* v_lhs = lhs; - const ReferencedObject* v_rhs = rhs; - - return v_lhs == v_rhs; - } - - template - bool operator==(const SmartPtr& lhs, const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool operator==(const SmartPtr& lhs, const SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - U1* raw_lhs = GetRawPtr(lhs); - U2* raw_rhs = GetRawPtr(rhs); - return ComparePointers(raw_lhs, raw_rhs); - } - - template - bool operator==(const SmartPtr& lhs, U2* raw_rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool operator==(SmartPtr& lhs, U2* rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - U1* raw_lhs = GetRawPtr(lhs); - return ComparePointers(raw_lhs, raw_rhs); - } - - template - bool operator==(U1* raw_lhs, const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool operator==(U1* raw_lhs, SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - const U2* raw_rhs = GetRawPtr(rhs); - return ComparePointers(raw_lhs, raw_rhs); - } - - template - bool operator!=(const SmartPtr& lhs, const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool operator!=(const SmartPtr& lhs, const SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - bool retValue = operator==(lhs, rhs); - return !retValue; - } - - template - bool operator!=(const SmartPtr& lhs, U2* raw_rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool operator!=(SmartPtr& lhs, U2* rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - bool retValue = operator==(lhs, raw_rhs); - return !retValue; - } - - template - bool operator!=(U1* raw_lhs, const SmartPtr& rhs) - { -#ifdef IP_DEBUG_SMARTPTR - DBG_START_FUN( - "bool operator!=(U1* raw_lhs, SmartPtr& rhs)", - ipopt_dbg_smartptr_verbosity); -#endif - - bool retValue = operator==(raw_lhs, rhs); - return !retValue; - } - - template - void swap(SmartPtr& a, SmartPtr& b) - { -#ifdef IP_DEBUG_REFERENCED - SmartPtr tmp(a); - a = b; - b = tmp; -#else - std::swap(a.prt_, b.ptr_); -#endif - } - - template - bool operator<(const SmartPtr& lhs, const SmartPtr& rhs) - { - return lhs.ptr_ < rhs.ptr_; - } - - template - bool operator> (const SmartPtr& lhs, const SmartPtr& rhs) - { - return rhs < lhs; - } - - template bool - operator<=(const SmartPtr& lhs, const SmartPtr& rhs) - { - return !( rhs < lhs ); - } - - template bool - operator>=(const SmartPtr& lhs, const SmartPtr& rhs) - { - return !( lhs < rhs ); - } -} // namespace Ipopt - -#undef ipopt_dbg_smartptr_verbosity - -#endif diff --git a/external/ipopt/include/coin/IpSolveStatistics.hpp b/external/ipopt/include/coin/IpSolveStatistics.hpp deleted file mode 100644 index 625ddfbf1..000000000 --- a/external/ipopt/include/coin/IpSolveStatistics.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2005, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSolveStatistics.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2005-08-15 - -#ifndef __IPSOLVESTATISTICS_HPP__ -#define __IPSOLVESTATISTICS_HPP__ - -#include "IpReferenced.hpp" -#include "IpSmartPtr.hpp" - -namespace Ipopt -{ - // forward declaration (to avoid inclusion of too many header files) - class IpoptNLP; - class IpoptData; - class IpoptCalculatedQuantities; - - /** This class collects statistics about an optimziation run, such - * as iteration count, final infeasibilities etc. It is meant to - * provide such information to a user of Ipopt during the - * finalize_solution call. - */ - class SolveStatistics : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor. It takes in those collecting Ipopt - * objects that can provide the statistics information. Those - * statistics are retrieved at the time of the constructor - * call. */ - SolveStatistics(const SmartPtr& ip_nlp, - const SmartPtr& ip_data, - const SmartPtr& ip_cq); - - /** Default destructor */ - virtual ~SolveStatistics() - {} - //@} - - /** @name Accessor methods for retrieving different kind of solver - * statistics information */ - //@{ - /** Iteration counts. */ - virtual Index IterationCount() const; - /** Total CPU time, including function evaluations. */ - virtual Number TotalCpuTime() const; - /** Total CPU time, including function evaluations. Included for - * backward compatibility. */ - Number TotalCPUTime() const - { - return TotalCpuTime(); - } - /** Total System time, including function evaluations. */ - virtual Number TotalSysTime() const; - /** Total wall clock time, including function evaluations. */ - virtual Number TotalWallclockTime() const; - /** Number of NLP function evaluations. */ - virtual void NumberOfEvaluations(Index& num_obj_evals, - Index& num_constr_evals, - Index& num_obj_grad_evals, - Index& num_constr_jac_evals, - Index& num_hess_evals) const; - /** Unscaled solution infeasibilities */ - virtual void Infeasibilities(Number& dual_inf, - Number& constr_viol, - Number& complementarity, - Number& kkt_error) const; - /** Scaled solution infeasibilities */ - virtual void ScaledInfeasibilities(Number& scaled_dual_inf, - Number& scaled_constr_viol, - Number& scaled_complementarity, - Number& scaled_kkt_error) const; - /** Final value of objective function */ - virtual Number FinalObjective() const; - /** Final scaled value of objective function */ - virtual Number FinalScaledObjective() const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - SolveStatistics(); - - /** Copy Constructor */ - SolveStatistics(const SolveStatistics&); - - /** Overloaded Equals Operator */ - void operator=(const SolveStatistics&); - //@} - - /** @name Fields for storing the statistics data */ - //@{ - /** Number of iterations. */ - Index num_iters_; - /* Total CPU time */ - Number total_cpu_time_; - /* Total system time */ - Number total_sys_time_; - /* Total wall clock time */ - Number total_wallclock_time_; - /** Number of objective function evaluations. */ - Index num_obj_evals_; - /** Number of constraints evaluations (max of equality and - * inequality) */ - Index num_constr_evals_; - /** Number of objective gradient evaluations. */ - Index num_obj_grad_evals_; - /** Number of constraint Jacobian evaluations. */ - Index num_constr_jac_evals_; - /** Number of Lagrangian Hessian evaluations. */ - Index num_hess_evals_; - - /** Final scaled value of objective function */ - Number scaled_obj_val_; - /** Final unscaled value of objective function */ - Number obj_val_; - /** Final scaled dual infeasibility (max-norm) */ - Number scaled_dual_inf_; - /** Final unscaled dual infeasibility (max-norm) */ - Number dual_inf_; - /** Final scaled constraint violation (max-norm) */ - Number scaled_constr_viol_; - /** Final unscaled constraint violation (max-norm) */ - Number constr_viol_; - /** Final scaled complementarity error (max-norm) */ - Number scaled_compl_; - /** Final unscaled complementarity error (max-norm) */ - Number compl_; - /** Final overall scaled KKT error (max-norm) */ - Number scaled_kkt_error_; - /** Final overall unscaled KKT error (max-norm) */ - Number kkt_error_; - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpStdCInterface.h b/external/ipopt/include/coin/IpStdCInterface.h deleted file mode 100644 index 4f1133671..000000000 --- a/external/ipopt/include/coin/IpStdCInterface.h +++ /dev/null @@ -1,271 +0,0 @@ -/************************************************************************* - Copyright (C) 2004, 2010 International Business Machines and others. - All Rights Reserved. - This code is published under the Eclipse Public License. - - $Id: IpStdCInterface.h 2082 2012-02-16 03:00:34Z andreasw $ - - Authors: Carl Laird, Andreas Waechter IBM 2004-09-02 - *************************************************************************/ - -#ifndef __IPSTDCINTERFACE_H__ -#define __IPSTDCINTERFACE_H__ - -#ifndef IPOPT_EXPORT -#ifdef _MSC_VER -#ifdef IPOPT_DLL -#define IPOPT_EXPORT(type) __declspec(dllexport) type __cdecl -#else -#define IPOPT_EXPORT(type) type __cdecl -#endif -#else -#define IPOPT_EXPORT(type) type -#endif -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** Type for all number. We need to make sure that this is - identical with what is defined in Common/IpTypes.hpp */ - typedef double Number; - - /** Type for all incides. We need to make sure that this is - identical with what is defined in Common/IpTypes.hpp */ - typedef int Index; - - /** Type for all integers. We need to make sure that this is - identical with what is defined in Common/IpTypes.hpp */ - typedef int Int; - - /* This includes the SolverReturn enum type */ -#include "IpReturnCodes.h" - - /** Structure collecting all information about the problem - * definition and solve statistics etc. This is defined in the - * source file. */ - struct IpoptProblemInfo; - - /** Pointer to a Ipopt Problem. */ - typedef struct IpoptProblemInfo* IpoptProblem; - - /** define a boolean type for C */ - typedef int Bool; -#ifndef TRUE -# define TRUE (1) -#endif -#ifndef FALSE -# define FALSE (0) -#endif - - /** A pointer for anything that is to be passed between the called - * and individual callback function */ - typedef void * UserDataPtr; - - /** Type defining the callback function for evaluating the value of - * the objective function. Return value should be set to false if - * there was a problem doing the evaluation. */ - typedef Bool (*Eval_F_CB)(Index n, Number* x, Bool new_x, - Number* obj_value, UserDataPtr user_data); - - /** Type defining the callback function for evaluating the gradient of - * the objective function. Return value should be set to false if - * there was a problem doing the evaluation. */ - typedef Bool (*Eval_Grad_F_CB)(Index n, Number* x, Bool new_x, - Number* grad_f, UserDataPtr user_data); - - /** Type defining the callback function for evaluating the value of - * the constraint functions. Return value should be set to false if - * there was a problem doing the evaluation. */ - typedef Bool (*Eval_G_CB)(Index n, Number* x, Bool new_x, - Index m, Number* g, UserDataPtr user_data); - - /** Type defining the callback function for evaluating the Jacobian of - * the constrant functions. Return value should be set to false if - * there was a problem doing the evaluation. */ - typedef Bool (*Eval_Jac_G_CB)(Index n, Number *x, Bool new_x, - Index m, Index nele_jac, - Index *iRow, Index *jCol, Number *values, - UserDataPtr user_data); - - /** Type defining the callback function for evaluating the Hessian of - * the Lagrangian function. Return value should be set to false if - * there was a problem doing the evaluation. */ - typedef Bool (*Eval_H_CB)(Index n, Number *x, Bool new_x, Number obj_factor, - Index m, Number *lambda, Bool new_lambda, - Index nele_hess, Index *iRow, Index *jCol, - Number *values, UserDataPtr user_data); - - /** Type defining the callback function for giving intermediate - * execution control to the user. If set, it is called once per - * iteration, providing the user with some information on the state - * of the optimization. This can be used to print some - * user-defined output. It also gives the user a way to terminate - * the optimization prematurely. If this method returns false, - * Ipopt will terminate the optimization. */ - typedef Bool (*Intermediate_CB)(Index alg_mod, /* 0 is regular, 1 is resto */ - Index iter_count, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, UserDataPtr user_data); - - /** Function for creating a new Ipopt Problem object. This function - * returns an object that can be passed to the IpoptSolve call. It - * contains the basic definition of the optimization problem, such - * as number of variables and constraints, bounds on variables and - * constraints, information about the derivatives, and the callback - * function for the computation of the optimization problem - * functions and derivatives. During this call, the options file - * PARAMS.DAT is read as well. - * - * If NULL is returned, there was a problem with one of the inputs - * or reading the options file. */ - IPOPT_EXPORT(IpoptProblem) CreateIpoptProblem( - Index n /** Number of optimization variables */ - , Number* x_L /** Lower bounds on variables. This array of - size n is copied internally, so that the - caller can change the incoming data after - return without that IpoptProblem is - modified. Any value less or equal than - the number specified by option - 'nlp_lower_bound_inf' is interpreted to - be minus infinity. */ - , Number* x_U /** Upper bounds on variables. This array of - size n is copied internally, so that the - caller can change the incoming data after - return without that IpoptProblem is - modified. Any value greater or equal - than the number specified by option - 'nlp_upper_bound_inf' is interpreted to - be plus infinity. */ - , Index m /** Number of constraints. */ - , Number* g_L /** Lower bounds on constraints. This array of - size m is copied internally, so that the - caller can change the incoming data after - return without that IpoptProblem is - modified. Any value less or equal than - the number specified by option - 'nlp_lower_bound_inf' is interpreted to - be minus infinity. */ - , Number* g_U /** Upper bounds on constraints. This array of - size m is copied internally, so that the - caller can change the incoming data after - return without that IpoptProblem is - modified. Any value greater or equal - than the number specified by option - 'nlp_upper_bound_inf' is interpreted to - be plus infinity. */ - , Index nele_jac /** Number of non-zero elements in constraint - Jacobian. */ - , Index nele_hess /** Number of non-zero elements in Hessian of - Lagrangian. */ - , Index index_style /** indexing style for iRow & jCol, - 0 for C style, 1 for Fortran style */ - , Eval_F_CB eval_f /** Callback function for evaluating - objective function */ - , Eval_G_CB eval_g /** Callback function for evaluating - constraint functions */ - , Eval_Grad_F_CB eval_grad_f - /** Callback function for evaluating gradient - of objective function */ - , Eval_Jac_G_CB eval_jac_g - /** Callback function for evaluating Jacobian - of constraint functions */ - , Eval_H_CB eval_h /** Callback function for evaluating Hessian - of Lagrangian function */ - ); - - /** Method for freeing a previously created IpoptProblem. After - freeing an IpoptProblem, it cannot be used anymore. */ - IPOPT_EXPORT(void) FreeIpoptProblem(IpoptProblem ipopt_problem); - - - /** Function for adding a string option. Returns FALSE the option - * could not be set (e.g., if keyword is unknown) */ - IPOPT_EXPORT(Bool) AddIpoptStrOption(IpoptProblem ipopt_problem, char* keyword, char* val); - - /** Function for adding a Number option. Returns FALSE the option - * could not be set (e.g., if keyword is unknown) */ - IPOPT_EXPORT(Bool) AddIpoptNumOption(IpoptProblem ipopt_problem, char* keyword, Number val); - - /** Function for adding an Int option. Returns FALSE the option - * could not be set (e.g., if keyword is unknown) */ - IPOPT_EXPORT(Bool) AddIpoptIntOption(IpoptProblem ipopt_problem, char* keyword, Int val); - - /** Function for opening an output file for a given name with given - * printlevel. Returns false, if there was a problem opening the - * file. */ - IPOPT_EXPORT(Bool) OpenIpoptOutputFile(IpoptProblem ipopt_problem, char* file_name, - Int print_level); - - /** Optional function for setting scaling parameter for the NLP. - * This corresponds to the get_scaling_parameters method in TNLP. - * If the pointers x_scaling or g_scaling are NULL, then no scaling - * for x resp. g is done. */ - IPOPT_EXPORT(Bool) SetIpoptProblemScaling(IpoptProblem ipopt_problem, - Number obj_scaling, - Number* x_scaling, - Number* g_scaling); - - /** Setting a callback function for the "intermediate callback" - * method in the TNLP. This gives control back to the user once - * per iteration. If set, it provides the user with some - * information on the state of the optimization. This can be used - * to print some user-defined output. It also gives the user a way - * to terminate the optimization prematurely. If the callback - * method returns false, Ipopt will terminate the optimization. - * Calling this set method to set the CB pointer to NULL disables - * the intermediate callback functionality. */ - IPOPT_EXPORT(Bool) SetIntermediateCallback(IpoptProblem ipopt_problem, - Intermediate_CB intermediate_cb); - - /** Function calling the Ipopt optimization algorithm for a problem - previously defined with CreateIpoptProblem. The return - specified outcome of the optimization procedure (e.g., success, - failure etc). - */ - IPOPT_EXPORT(enum ApplicationReturnStatus) IpoptSolve( - IpoptProblem ipopt_problem - /** Problem that is to be optimized. Ipopt - will use the options previously specified with - AddIpoptOption (etc) for this problem. */ - , Number* x /** Input: Starting point - Output: Optimal solution */ - , Number* g /** Values of constraint at final point - (output only - ignored if set to NULL) */ - , Number* obj_val /** Final value of objective function - (output only - ignored if set to NULL) */ - , Number* mult_g /** Input: Initial values for the constraint - multipliers (only if warm start option - is chosen) - Output: Final multipliers for constraints - (ignored if set to NULL) */ - , Number* mult_x_L /** Input: Initial values for the multipliers for - lower variable bounds (only if warm start - option is chosen) - Output: Final multipliers for lower variable - bounds (ignored if set to NULL) */ - , Number* mult_x_U /** Input: Initial values for the multipliers for - upper variable bounds (only if warm start - option is chosen) - Output: Final multipliers for upper variable - bounds (ignored if set to NULL) */ - , UserDataPtr user_data - /** Pointer to user data. This will be - passed unmodified to the callback - functions. */ - ); - - /** - void IpoptStatisticsCounts; - - void IpoptStatisticsInfeasibilities; */ -#ifdef __cplusplus -} /* extern "C" { */ -#endif - -#endif diff --git a/external/ipopt/include/coin/IpSumSymMatrix.hpp b/external/ipopt/include/coin/IpSumSymMatrix.hpp deleted file mode 100644 index 42b11686b..000000000 --- a/external/ipopt/include/coin/IpSumSymMatrix.hpp +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSumSymMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSUMSYMMATRIX_HPP__ -#define __IPSUMSYMMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class SumSymMatrixSpace; - - /** Class for Matrices which are sum of symmetric matrices. - * For each term in the we store the matrix and a factor. - */ - class SumSymMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, initializing with dimensions of the matrix and - * the number of terms in the sum. - */ - SumSymMatrix(const SumSymMatrixSpace* owner_space); - - /** Destructor */ - ~SumSymMatrix(); - //@} - - /** Method for setting term iterm for the sum. Note that counting - * of terms starts at 0. */ - void SetTerm(Index iterm, Number factor, const SymMatrix& matrix); - - /** Method for getting term iterm for the sum. Note that counting - * of terms starts at 0. */ - void GetTerm(Index iterm, Number& factor, SmartPtr& matrix) const; - - /** Return the number of terms */ - Index NTerms() const; - - protected: - /**@name Methods overloaded from matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - SumSymMatrix(); - - /** Copy Constructor */ - SumSymMatrix(const SumSymMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const SumSymMatrix&); - //@} - - /** std::vector storing the factors for each term. */ - std::vector factors_; - - /** std::vector storing the matrices for each term. */ - std::vector > matrices_; - - /** Copy of the owner_space as a SumSymMatrixSpace */ - const SumSymMatrixSpace* owner_space_; - }; - - /** Class for matrix space for SumSymMatrix */ - class SumSymMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the dimension of the matrix and the number - * of terms in the sum. */ - SumSymMatrixSpace(Index ndim, Index nterms) - : - SymMatrixSpace(ndim), - nterms_(nterms) - {} - - /** Destructor */ - ~SumSymMatrixSpace() - {} - //@} - - /** @name Accessor functions */ - //@{ - /** Number of terms in the sum. */ - Index NTerms() const - { - return nterms_; - } - //@} - - /** Use this method to set the matrix spaces for the various terms. - * You will not be able to create a matrix until all these spaces - * are set. */ - void SetTermSpace(Index term_idx, const SymMatrixSpace& space); - - /** Get the matix space for a particular term */ - SmartPtr GetTermSpace(Index term_idx) const; - - /** Method for creating a new matrix of this specific type. */ - SumSymMatrix* MakeNewSumSymMatrix() const; - - /** Overloaded MakeNew method for the SymMatrixSpace base class. - */ - virtual SymMatrix* MakeNewSymMatrix() const; - - private: - Index nterms_; - - std::vector< SmartPtr > term_spaces_; - }; - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpSymLinearSolver.hpp b/external/ipopt/include/coin/IpSymLinearSolver.hpp deleted file mode 100644 index 82e7dd4bf..000000000 --- a/external/ipopt/include/coin/IpSymLinearSolver.hpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSymLinearSolver.hpp 2322 2013-06-12 17:45:57Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSYMLINEARSOLVER_HPP__ -#define __IPSYMLINEARSOLVER_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" -#include "IpAlgStrategy.hpp" -#include - -namespace Ipopt -{ - - /** Enum to report outcome of a linear solve */ - enum ESymSolverStatus { - /** Successful solve */ - SYMSOLVER_SUCCESS, - /** Matrix seems to be singular; solve was aborted */ - SYMSOLVER_SINGULAR, - /** The number of negative eigenvalues is not correct */ - SYMSOLVER_WRONG_INERTIA, - /** Call the solver interface again after the matrix values have - * been restored */ - SYMSOLVER_CALL_AGAIN, - /** Unrecoverable error in linear solver occurred. The - * optimization will be aborted. */ - SYMSOLVER_FATAL_ERROR - }; - - /** Base class for all derived symmetric linear - * solvers. In the full space version of Ipopt a large linear - * system has to be solved for the augmented system. This case is - * meant to be the base class for all derived linear solvers for - * symmetric matrices (of type SymMatrix). - * - * A linear solver can be used repeatedly for matrices with - * identical structure of nonzero elements. The nonzero structure - * of those matrices must not be changed between calls. - * - * The called might ask the solver to only solve the linear system - * if the system is nonsingular, and if the number of negative - * eigenvalues matches a given number. - */ - class SymLinearSolver: public AlgorithmStrategyObject - { - public: - /** @name Constructor/Destructor */ - //@{ - SymLinearSolver() - {} - - virtual ~SymLinearSolver() - {} - //@} - - /** overloaded from AlgorithmStrategyObject */ - virtual bool InitializeImpl(const OptionsList& options, - const std::string& prefix) = 0; - - /** @name Methods for requesting solution of the linear system. */ - //@{ - /** Solve operation for multiple right hand sides. Solves the - * linear system A * Sol = Rhs with multiple right hand sides. If - * necessary, A is factorized. Correct solutions are only - * guaranteed if the return values is SYMSOLVER_SUCCESS. The - * solver will return SYMSOLVER_SINGULAR if the linear system is - * singular, and it will return SYMSOLVER_WRONG_INERTIA if - * check_NegEVals is true and the number of negative eigenvalues - * in the matrix does not match numberOfNegEVals. - * - * check_NegEVals cannot be chosen true, if ProvidesInertia() - * returns false. - */ - virtual ESymSolverStatus MultiSolve(const SymMatrix &A, - std::vector >& rhsV, - std::vector >& solV, - bool check_NegEVals, - Index numberOfNegEVals)=0; - - /** Solve operation for a single right hand side. Solves the - * linear system A * Sol = Rhs. See MultiSolve for more - * details. */ - ESymSolverStatus Solve(const SymMatrix &A, - const Vector& rhs, Vector& sol, - bool check_NegEVals, - Index numberOfNegEVals) - { - std::vector > rhsV(1); - rhsV[0] = &rhs; - std::vector > solV(1); - solV[0] = / - return MultiSolve(A, rhsV, solV, check_NegEVals, - numberOfNegEVals); - } - - /** Number of negative eigenvalues detected during last - * factorization. Returns the number of negative eigenvalues of - * the most recent factorized matrix. This must not be called if - * the linear solver does not compute this quantities (see - * ProvidesInertia). - */ - virtual Index NumberOfNegEVals() const =0; - //@} - - //* @name Options of Linear solver */ - //@{ - /** Request to increase quality of solution for next solve. - * Ask linear solver to increase quality of solution for the next - * solve (e.g. increase pivot tolerance). Returns false, if this - * is not possible (e.g. maximal pivot tolerance already used.) - */ - virtual bool IncreaseQuality() =0; - - /** Query whether inertia is computed by linear solver. - * Returns true, if linear solver provides inertia. - */ - virtual bool ProvidesInertia() const =0; - //@} - }; - - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpSymMatrix.hpp b/external/ipopt/include/coin/IpSymMatrix.hpp deleted file mode 100644 index 4a0137bac..000000000 --- a/external/ipopt/include/coin/IpSymMatrix.hpp +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSymMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSYMMATRIX_HPP__ -#define __IPSYMMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class SymMatrixSpace; - - /** This is the base class for all derived symmetric matrix types. - */ - class SymMatrix : public Matrix - { - public: - /** @name Constructor/Destructor */ - //@{ - /** Constructor, taking the owner_space. - */ - inline - SymMatrix(const SymMatrixSpace* owner_space); - - /** Destructor */ - virtual ~SymMatrix() - {} - //@} - - /** @name Information about the size of the matrix */ - //@{ - /** Dimension of the matrix (number of rows and columns) */ - inline - Index Dim() const; - //@} - - inline - SmartPtr OwnerSymMatrixSpace() const; - - protected: - /** @name Overloaded methods from Matrix. */ - //@{ - /** Since the matrix is - * symmetric, it is only necessary to implement the - * MultVectorImpl method in a class that inherits from this base - * class. If the TransMultVectorImpl is called, this base class - * automatically calls MultVectorImpl instead. */ - virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta, - Vector& y) const - { - // Since this matrix is symetric, this is the same operation as - // MultVector - MultVector(alpha, x, beta, y); - } - /** Since the matrix is symmetric, the row and column max norms - * are identical */ - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const - { - ComputeRowAMaxImpl(cols_norms, init); - } - //@} - - private: - /** Copy of the owner space ptr as a SymMatrixSpace instead - * of a MatrixSpace - */ - const SymMatrixSpace* owner_space_; - }; - - - /** SymMatrixSpace base class, corresponding to the SymMatrix base - * class. */ - class SymMatrixSpace : public MatrixSpace - { - public: - /** @name Constructors/Destructors */ - //@{ - /** Constructor, given the dimension (identical to the number of - * rows and columns). - */ - SymMatrixSpace(Index dim) - : - MatrixSpace(dim,dim) - {} - - /** Destructor */ - virtual ~SymMatrixSpace() - {} - //@} - - /** Pure virtual method for creating a new matrix of this specific - * type. */ - virtual SymMatrix* MakeNewSymMatrix() const=0; - - /** Overloaded MakeNew method for the MatrixSpace base class. - */ - virtual Matrix* MakeNew() const - { - return MakeNewSymMatrix(); - } - - /** Accessor method for the dimension of the matrices in this - * matrix space. - */ - Index Dim() const - { - DBG_ASSERT(NRows() == NCols()); - return NRows(); - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** default constructor */ - SymMatrixSpace(); - - /* Copy constructor */ - SymMatrixSpace(const SymMatrixSpace&); - - /** Overloaded Equals Operator */ - SymMatrixSpace& operator=(const SymMatrixSpace&); - //@} - - }; - - /* inline methods */ - inline - SymMatrix::SymMatrix(const SymMatrixSpace* owner_space) - : - Matrix(owner_space), - owner_space_(owner_space) - {} - - inline - Index SymMatrix::Dim() const - { - return owner_space_->Dim(); - } - - inline - SmartPtr SymMatrix::OwnerSymMatrixSpace() const - { - return owner_space_; - } - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpSymScaledMatrix.hpp b/external/ipopt/include/coin/IpSymScaledMatrix.hpp deleted file mode 100644 index d58742f99..000000000 --- a/external/ipopt/include/coin/IpSymScaledMatrix.hpp +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSymScaledMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSYMSCALEDMATRIX_HPP__ -#define __IPSYMSCALEDMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class SymScaledMatrixSpace; - - /** Class for a Matrix in conjunction with its scaling factors for - * row and column scaling. Operations on the matrix are performed using - * the scaled matrix. You can pull out the pointer to the - * unscaled matrix for unscaled calculations. - */ - class SymScaledMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the owner_space. - */ - SymScaledMatrix(const SymScaledMatrixSpace* owner_space); - - /** Destructor */ - ~SymScaledMatrix(); - //@} - - /** Set the unscaled matrix */ - void SetUnscaledMatrix(const SmartPtr unscaled_matrix); - - /** Set the unscaled matrix in a non-const version */ - void SetUnscaledMatrixNonConst(const SmartPtr& unscaled_matrix); - - /** Return the unscaled matrix in const form */ - SmartPtr GetUnscaledMatrix() const; - - /** Return the unscaled matrix in non-const form */ - SmartPtr GetUnscaledMatrixNonConst(); - - /** return the vector for the row and column scaling */ - SmartPtr RowColScaling() const; - - protected: - /**@name Methods overloaded from Matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). It is assumed here that the scaling factors - * are always valid numbers. */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - SymScaledMatrix(); - - /** Copy Constructor */ - SymScaledMatrix(const SymScaledMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const SymScaledMatrix&); - //@} - - /** const version of the unscaled matrix */ - SmartPtr matrix_; - /** non-const version of the unscaled matrix */ - SmartPtr nonconst_matrix_; - - /** Matrix space stored as a SymScaledMatrixSpace */ - SmartPtr owner_space_; - }; - - /** This is the matrix space for SymScaledMatrix. - */ - class SymScaledMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of row and columns blocks, as - * well as the totel number of rows and columns. - */ - SymScaledMatrixSpace(const SmartPtr& row_col_scaling, - bool row_col_scaling_reciprocal, - const SmartPtr& unscaled_matrix_space) - : - SymMatrixSpace(unscaled_matrix_space->Dim()), - unscaled_matrix_space_(unscaled_matrix_space) - { - scaling_ = row_col_scaling->MakeNewCopy(); - if (row_col_scaling_reciprocal) { - scaling_->ElementWiseReciprocal(); - } - } - - /** Destructor */ - ~SymScaledMatrixSpace() - {} - //@} - - /** Method for creating a new matrix of this specific type. */ - SymScaledMatrix* MakeNewSymScaledMatrix(bool allocate_unscaled_matrix = false) const - { - SymScaledMatrix* ret = new SymScaledMatrix(this); - if (allocate_unscaled_matrix) { - SmartPtr unscaled_matrix = unscaled_matrix_space_->MakeNewSymMatrix(); - ret->SetUnscaledMatrixNonConst(unscaled_matrix); - } - return ret; - } - - /** Overloaded method from SymMatrixSpace */ - virtual SymMatrix* MakeNewSymMatrix() const - { - return MakeNewSymScaledMatrix(); - } - /** Overloaded MakeNew method for the MatrixSpace base class. - */ - virtual Matrix* MakeNew() const - { - return MakeNewSymScaledMatrix(); - } - - /** return the vector for the row and column scaling */ - SmartPtr RowColScaling() const - { - return ConstPtr(scaling_); - } - - /** return the matrix space for the unscaled matrix */ - SmartPtr UnscaledMatrixSpace() const - { - return unscaled_matrix_space_; - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default constructor */ - SymScaledMatrixSpace(); - - /** Copy Constructor */ - SymScaledMatrixSpace(const SymScaledMatrixSpace&); - - /** Overloaded Equals Operator */ - SymScaledMatrixSpace& operator=(const SymScaledMatrixSpace&); - //@} - - /** Row scaling vector */ - SmartPtr scaling_; - /** unscaled matrix space */ - SmartPtr unscaled_matrix_space_; - }; - - inline - void SymScaledMatrix::SetUnscaledMatrix(const SmartPtr unscaled_matrix) - { - matrix_ = unscaled_matrix; - nonconst_matrix_ = NULL; - ObjectChanged(); - } - - inline - void SymScaledMatrix::SetUnscaledMatrixNonConst(const SmartPtr& unscaled_matrix) - { - nonconst_matrix_ = unscaled_matrix; - matrix_ = GetRawPtr(unscaled_matrix); - ObjectChanged(); - } - - inline - SmartPtr SymScaledMatrix::GetUnscaledMatrix() const - { - return matrix_; - } - - inline - SmartPtr SymScaledMatrix::GetUnscaledMatrixNonConst() - { - DBG_ASSERT(IsValid(nonconst_matrix_)); - ObjectChanged(); - return nonconst_matrix_; - } - - inline SmartPtr SymScaledMatrix::RowColScaling() const - { - return ConstPtr(owner_space_->RowColScaling()); - } - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpSymTMatrix.hpp b/external/ipopt/include/coin/IpSymTMatrix.hpp deleted file mode 100644 index ead2d85f5..000000000 --- a/external/ipopt/include/coin/IpSymTMatrix.hpp +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpSymTMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPSYMTMATRIX_HPP__ -#define __IPSYMTMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /* forward declarations */ - class SymTMatrixSpace; - - /** Class for symmetric matrices stored in triplet format. In the - * triplet format, the nonzeros elements of a symmetric matrix is - * stored in three arrays, Irn, Jcn, and Values, all of length - * Nonzeros. The first two arrays indicate the location of a - * non-zero element (as the row and column indices), and the last - * array stores the value at that location. Off-diagonal elements - * need to be stored only once since the matrix is symmetric. For - * example, the element \f$a_{1,2}=a_{2,1}\f$ would be stored only - * once, either with Irn[i]=1 and Jcn[i]=2, or with Irn[i]=2 and - * Jcn[i]=1. Both representations are identical. If nonzero - * elements (or their symmetric counter part) are listed more than - * once, their values are added. - * - * The structure of the nonzeros (i.e. the arrays Irn and Jcn) - * cannot be changed after the matrix can been initialized. Only - * the values of the nonzero elements can be modified. - * - * Note that the first row and column of a matrix has index 1, not - * 0. - * - */ - class SymTMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the corresponding matrix space. - */ - SymTMatrix(const SymTMatrixSpace* owner_space); - - /** Destructor */ - ~SymTMatrix(); - //@} - - /**@name Changing the Values.*/ - //@{ - /** Set values of nonzero elements. The values of the nonzero - * elements is copied from the incoming Number array. Important: - * It is assume that the order of the values in Values - * corresponds to the one of Irn and Jcn given to the matrix - * space. */ - void SetValues(const Number* Values); - //@} - - /** @name Accessor Methods */ - //@{ - /** Number of nonzero entries */ - Index Nonzeros() const; - - /** Obtain pointer to the internal Index array irn_ without the - * intention to change the matrix data (USE WITH CARE!). This - * does not produce a copy, and lifetime is not guaranteed! - */ - const Index* Irows() const; - - /** Obtain pointer to the internal Index array jcn_ without the - * intention to change the matrix data (USE WITH CARE!). This - * does not produce a copy, and lifetime is not guaranteed! - */ - const Index* Jcols() const; - - /** Obtain pointer to the internal Number array values_ with the - * intention to change the matrix data (USE WITH CARE!). This - * does not produce a copy, and lifetime is not guaranteed! - */ - Number* Values(); - /** Obtain pointer to the internal Number array values_ without the - * intention to change the matrix data (USE WITH CARE!). This - * does not produce a copy, and lifetime is not guaranteed! - */ - const Number* Values() const; - //@} - - /**@name Methods for providing copy of the matrix data */ - //@{ - /** Copy the nonzero structure into provided space */ - void FillStruct(ipfint* Irn, ipfint* Jcn) const; - - /** Copy the value data into provided space */ - void FillValues(Number* Values) const; - //@} - - protected: - /**@name Methods overloaded from matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, Number beta, - Vector& y) const; - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - virtual bool HasValidNumbersImpl() const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const; - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - SymTMatrix(); - - /** Copy Constructor */ - SymTMatrix(const SymTMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const SymTMatrix&); - //@} - - /** Copy of the owner_space ptr as a SymTMatrixSpace insteaqd - * of a MatrixSpace - */ - const SymTMatrixSpace* owner_space_; - - /** Values of nonzeros */ - Number* values_; - - /** Flag for Initialization */ - bool initialized_; - - }; - - /** This is the matrix space for a SymTMatrix with fixed sparsity - * structure. The sparsity structure is stored here in the matrix - * space. - */ - class SymTMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of rows and columns (both as - * dim), as well as the number of nonzeros and the position of - * the nonzero elements. Note that the counting of the nonzeros - * starts a 1, i.e., iRows[i]==1 and jCols[i]==1 refers to the - * first element in the first row. This is in accordance with - * the HSL data structure. Off-diagonal elements are stored only - * once. - */ - SymTMatrixSpace(Index dim, Index nonZeros, const Index* iRows, - const Index* jCols); - - /** Destructor */ - ~SymTMatrixSpace(); - //@} - - /** Overloaded MakeNew method for the sYMMatrixSpace base class. - */ - virtual SymMatrix* MakeNewSymMatrix() const - { - return MakeNewSymTMatrix(); - } - - /** Method for creating a new matrix of this specific type. */ - SymTMatrix* MakeNewSymTMatrix() const - { - return new SymTMatrix(this); - } - - /**@name Methods describing Matrix structure */ - //@{ - /** Number of non-zeros in the sparse matrix */ - Index Nonzeros() const - { - return nonZeros_; - } - - /** Row index of each non-zero element */ - const Index* Irows() const - { - return iRows_; - } - - /** Column index of each non-zero element */ - const Index* Jcols() const - { - return jCols_; - } - //@} - - private: - /**@name Methods called by SymTMatrix for memory management */ - //@{ - /** Allocate internal storage for the SymTMatrix values */ - Number* AllocateInternalStorage() const; - - /** Deallocate internal storage for the SymTMatrix values */ - void FreeInternalStorage(Number* values) const; - //@} - - const Index nonZeros_; - Index* iRows_; - Index* jCols_; - - friend class SymTMatrix; - }; - - /* Inline Methods */ - inline - Index SymTMatrix::Nonzeros() const - { - return owner_space_->Nonzeros(); - } - - inline - const Index* SymTMatrix::Irows() const - { - return owner_space_->Irows(); - } - - inline - const Index* SymTMatrix::Jcols() const - { - return owner_space_->Jcols(); - } - - -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpTNLP.hpp b/external/ipopt/include/coin/IpTNLP.hpp deleted file mode 100644 index 998d38e84..000000000 --- a/external/ipopt/include/coin/IpTNLP.hpp +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTNLP.hpp 2212 2013-04-14 14:51:52Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPTNLP_HPP__ -#define __IPTNLP_HPP__ - -#include "IpUtils.hpp" -#include "IpReferenced.hpp" -#include "IpException.hpp" -#include "IpAlgTypes.hpp" -#include "IpReturnCodes.hpp" - -#include - -namespace Ipopt -{ - // forward declarations - class IpoptData; - class IpoptCalculatedQuantities; - class IteratesVector; - - /** Base class for all NLP's that use standard triplet matrix form - * and dense vectors. This is the standard base class for all - * NLP's that use the standard triplet matrix form (as for Harwell - * routines) and dense vectors. The class TNLPAdapter then converts - * this interface to an interface that can be used directly by - * ipopt. - * - * This interface presents the problem form: - * - * min f(x) - * - * s.t. gL <= g(x) <= gU - * - * xL <= x <= xU - * - * In order to specify an equality constraint, set gL_i = gU_i = - * rhs. The value that indicates "infinity" for the bounds - * (i.e. the variable or constraint has no lower bound (-infinity) - * or upper bound (+infinity)) is set through the option - * nlp_lower_bound_inf and nlp_upper_bound_inf. To indicate that a - * variable has no upper or lower bound, set the bound to - * -ipopt_inf or +ipopt_inf respectively - */ - class TNLP : public ReferencedObject - { - public: - /** Type of the constraints*/ - enum LinearityType - { - LINEAR/** Constraint/Variable is linear.*/, - NON_LINEAR/**Constraint/Varaible is non-linear.*/ - }; - - /**@name Constructors/Destructors */ - //@{ - TNLP() - {} - - /** Default destructor */ - virtual ~TNLP() - {} - //@} - - DECLARE_STD_EXCEPTION(INVALID_TNLP); - - /**@name methods to gather information about the NLP */ - //@{ - /** overload this method to return the number of variables - * and constraints, and the number of non-zeros in the jacobian and - * the hessian. The index_style parameter lets you specify C or Fortran - * style indexing for the sparse matrix iRow and jCol parameters. - * C_STYLE is 0-based, and FORTRAN_STYLE is 1-based. - */ - enum IndexStyleEnum { C_STYLE=0, FORTRAN_STYLE=1 }; - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style)=0; - - typedef std::map > StringMetaDataMapType; - typedef std::map > IntegerMetaDataMapType; - typedef std::map > NumericMetaDataMapType; - - /** overload this method to return any meta data for - * the variables and the constraints */ - virtual bool get_var_con_metadata(Index n, - StringMetaDataMapType& var_string_md, - IntegerMetaDataMapType& var_integer_md, - NumericMetaDataMapType& var_numeric_md, - Index m, - StringMetaDataMapType& con_string_md, - IntegerMetaDataMapType& con_integer_md, - NumericMetaDataMapType& con_numeric_md) - - { - return false; - } - - /** overload this method to return the information about the bound - * on the variables and constraints. The value that indicates - * that a bound does not exist is specified in the parameters - * nlp_lower_bound_inf and nlp_upper_bound_inf. By default, - * nlp_lower_bound_inf is -1e19 and nlp_upper_bound_inf is - * 1e19. (see TNLPAdapter) */ - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u)=0; - - /** overload this method to return scaling parameters. This is - * only called if the options are set to retrieve user scaling. - * There, use_x_scaling (or use_g_scaling) should get set to true - * only if the variables (or constraints) are to be scaled. This - * method should return true only if the scaling parameters could - * be provided. - */ - virtual bool get_scaling_parameters(Number& obj_scaling, - bool& use_x_scaling, Index n, - Number* x_scaling, - bool& use_g_scaling, Index m, - Number* g_scaling) - { - return false; - } - - /** overload this method to return the variables linearity - * (TNLP::LINEAR or TNLP::NON_LINEAR). The var_types - * array has been allocated with length at least n. (default implementation - * just return false and does not fill the array).*/ - virtual bool get_variables_linearity(Index n, LinearityType* var_types) - { - return false; - } - - /** overload this method to return the constraint linearity. - * array has been allocated with length at least n. (default implementation - * just return false and does not fill the array).*/ - virtual bool get_constraints_linearity(Index m, LinearityType* const_types) - { - return false; - } - - /** overload this method to return the starting point. The bool - * variables indicate whether the algorithm wants you to - * initialize x, z_L/z_u, and lambda, respectively. If, for some - * reason, the algorithm wants you to initialize these and you - * cannot, return false, which will cause Ipopt to stop. You - * will have to run Ipopt with different options then. - */ - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, - Number* lambda)=0; - - /** overload this method to provide an Ipopt iterate (already in - * the form Ipopt requires it internally) for a warm start. - * Since this is only for expert users, a default dummy - * implementation is provided and returns false. */ - virtual bool get_warm_start_iterate(IteratesVector& warm_start_iterate) - { - return false; - } - - /** overload this method to return the value of the objective function */ - virtual bool eval_f(Index n, const Number* x, bool new_x, - Number& obj_value)=0; - - /** overload this method to return the vector of the gradient of - * the objective w.r.t. x */ - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, - Number* grad_f)=0; - - /** overload this method to return the vector of constraint values */ - virtual bool eval_g(Index n, const Number* x, bool new_x, - Index m, Number* g)=0; - /** overload this method to return the jacobian of the - * constraints. The vectors iRow and jCol only need to be set - * once. The first call is used to set the structure only (iRow - * and jCol will be non-NULL, and values will be NULL) For - * subsequent calls, iRow and jCol will be NULL. */ - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, - Index *jCol, Number* values)=0; - - /** overload this method to return the hessian of the - * lagrangian. The vectors iRow and jCol only need to be set once - * (during the first call). The first call is used to set the - * structure only (iRow and jCol will be non-NULL, and values - * will be NULL) For subsequent calls, iRow and jCol will be - * NULL. This matrix is symmetric - specify the lower diagonal - * only. A default implementation is provided, in case the user - * wants to se quasi-Newton approximations to estimate the second - * derivatives and doesn't not neet to implement this method. */ - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, - Index* iRow, Index* jCol, Number* values) - { - return false; - } - //@} - - /** @name Solution Methods */ - //@{ - /** This method is called when the algorithm is complete so the TNLP can store/write the solution */ - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq)=0; - /** This method is called just before finalize_solution. With - * this method, the algorithm returns any metadata collected - * during its run, including the metadata provided by the user - * with the above get_var_con_metadata. Each metadata can be of - * type string, integer, and numeric. It can be associated to - * either the variables or the constraints. The metadata that - * was associated with the primal variable vector is stored in - * var_..._md. The metadata associated with the constraint - * multipliers is stored in con_..._md. The metadata associated - * with the bound multipliers is stored in var_..._md, with the - * suffixes "_z_L", and "_z_U", denoting lower and upper - * bounds. */ - virtual void finalize_metadata(Index n, - const StringMetaDataMapType& var_string_md, - const IntegerMetaDataMapType& var_integer_md, - const NumericMetaDataMapType& var_numeric_md, - Index m, - const StringMetaDataMapType& con_string_md, - const IntegerMetaDataMapType& con_integer_md, - const NumericMetaDataMapType& con_numeric_md) - {} - - - /** Intermediate Callback method for the user. Providing dummy - * default implementation. For details see IntermediateCallBack - * in IpNLP.hpp. */ - virtual bool intermediate_callback(AlgorithmMode mode, - Index iter, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq) - { - return true; - } - //@} - - /** @name Methods for quasi-Newton approximation. If the second - * derivatives are approximated by Ipopt, it is better to do this - * only in the space of nonlinear variables. The following - * methods are call by Ipopt if the quasi-Newton approximation is - * selected. If -1 is returned as number of nonlinear variables, - * Ipopt assumes that all variables are nonlinear. Otherwise, it - * calls get_list_of_nonlinear_variables with an array into which - * the indices of the nonlinear variables should be written - the - * array has the lengths num_nonlin_vars, which is identical with - * the return value of get_number_of_nonlinear_variables(). It - * is assumed that the indices are counted starting with 1 in the - * FORTRAN_STYLE, and 0 for the C_STYLE. */ - //@{ - virtual Index get_number_of_nonlinear_variables() - { - return -1; - } - - virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, - Index* pos_nonlin_vars) - { - return false; - } - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - //TNLP(); - - /** Copy Constructor */ - TNLP(const TNLP&); - - /** Overloaded Equals Operator */ - void operator=(const TNLP&); - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpTNLPAdapter.hpp b/external/ipopt/include/coin/IpTNLPAdapter.hpp deleted file mode 100644 index 6eea8e3b8..000000000 --- a/external/ipopt/include/coin/IpTNLPAdapter.hpp +++ /dev/null @@ -1,427 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTNLPAdapter.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPTNLPADAPTER_HPP__ -#define __IPTNLPADAPTER_HPP__ - -#include "IpNLP.hpp" -#include "IpTNLP.hpp" -#include "IpOrigIpoptNLP.hpp" -#include - -namespace Ipopt -{ - - // forward declarations - class ExpansionMatrix; - class ExpansionMatrixSpace; - class IteratesVector; - class TDependencyDetector; - - /** This class Adapts the TNLP interface so it looks like an NLP interface. - * This is an Adapter class (Design Patterns) that converts a TNLP to an - * NLP. This allows users to write to the "more convenient" TNLP interface. - */ - class TNLPAdapter : public NLP - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor */ - TNLPAdapter(const SmartPtr tnlp, - const SmartPtr jnlst = NULL); - - /** Default destructor */ - virtual ~TNLPAdapter(); - //@} - - /**@name Exceptions */ - //@{ - DECLARE_STD_EXCEPTION(INVALID_TNLP); - DECLARE_STD_EXCEPTION(ERROR_IN_TNLP_DERIVATIVE_TEST); - //@} - - /** @name TNLPAdapter Initialization. */ - //@{ - virtual bool ProcessOptions(const OptionsList& options, - const std::string& prefix); - - /** Method for creating the derived vector / matrix types - * (Do not delete these, the ). */ - virtual bool GetSpaces(SmartPtr& x_space, - SmartPtr& c_space, - SmartPtr& d_space, - SmartPtr& x_l_space, - SmartPtr& px_l_space, - SmartPtr& x_u_space, - SmartPtr& px_u_space, - SmartPtr& d_l_space, - SmartPtr& pd_l_space, - SmartPtr& d_u_space, - SmartPtr& pd_u_space, - SmartPtr& Jac_c_space, - SmartPtr& Jac_d_space, - SmartPtr& Hess_lagrangian_space); - - /** Method for obtaining the bounds information */ - virtual bool GetBoundsInformation(const Matrix& Px_L, - Vector& x_L, - const Matrix& Px_U, - Vector& x_U, - const Matrix& Pd_L, - Vector& d_L, - const Matrix& Pd_U, - Vector& d_U); - - /** Method for obtaining the starting point - * for all the iterates. */ - virtual bool GetStartingPoint( - SmartPtr x, - bool need_x, - SmartPtr y_c, - bool need_y_c, - SmartPtr y_d, - bool need_y_d, - SmartPtr z_L, - bool need_z_L, - SmartPtr z_U, - bool need_z_U - ); - - /** Method for obtaining an entire iterate as a warmstart point. - * The incoming IteratesVector has to be filled. */ - virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate); - //@} - - /** @name TNLPAdapter evaluation routines. */ - //@{ - virtual bool Eval_f(const Vector& x, Number& f); - - virtual bool Eval_grad_f(const Vector& x, Vector& g_f); - - virtual bool Eval_c(const Vector& x, Vector& c); - - virtual bool Eval_jac_c(const Vector& x, Matrix& jac_c); - - virtual bool Eval_d(const Vector& x, Vector& d); - - virtual bool Eval_jac_d(const Vector& x, Matrix& jac_d); - - virtual bool Eval_h(const Vector& x, - Number obj_factor, - const Vector& yc, - const Vector& yd, - SymMatrix& h); - - virtual void GetScalingParameters( - const SmartPtr x_space, - const SmartPtr c_space, - const SmartPtr d_space, - Number& obj_scaling, - SmartPtr& x_scaling, - SmartPtr& c_scaling, - SmartPtr& d_scaling) const; - //@} - - /** @name Solution Reporting Methods */ - //@{ - virtual void FinalizeSolution(SolverReturn status, - const Vector& x, - const Vector& z_L, const Vector& z_U, - const Vector& c, const Vector& d, - const Vector& y_c, const Vector& y_d, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); - - virtual bool IntermediateCallBack(AlgorithmMode mode, - Index iter, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); - //@} - - /** Method returning information on quasi-Newton approximation. */ - virtual void - GetQuasiNewtonApproximationSpaces(SmartPtr& approx_space, - SmartPtr& P_approx); - - /** Enum for treatment of fixed variables option */ - enum FixedVariableTreatmentEnum - { - MAKE_PARAMETER=0, - MAKE_CONSTRAINT, - RELAX_BOUNDS - }; - - /** Enum for specifying which derivative test is to be performed. */ - enum DerivativeTestEnum - { - NO_TEST=0, - FIRST_ORDER_TEST, - SECOND_ORDER_TEST, - ONLY_SECOND_ORDER_TEST - }; - - /** Enum for specifying technique for computing Jacobian */ - enum JacobianApproxEnum - { - JAC_EXACT=0, - JAC_FINDIFF_VALUES - }; - - /** Method for performing the derivative test */ - bool CheckDerivatives(DerivativeTestEnum deriv_test, - Index deriv_test_start_index); - - /** @name Methods for IpoptType */ - //@{ - static void RegisterOptions(SmartPtr roptions); - //@} - - /** Accessor method for the underlying TNLP. */ - SmartPtr tnlp() const - { - return tnlp_; - } - - /** @name Methods for translating data for IpoptNLP into the TNLP - * data. These methods are used to obtain the current (or - * final) data for the TNLP formulation from the IpoptNLP - * structure. */ - //@{ - /** Sort the primal variables, and add the fixed values in x */ - void ResortX(const Vector& x, Number* x_orig); - void ResortG(const Vector& c, const Vector& d, Number *g_orig); - void ResortBnds(const Vector& x_L, Number* x_L_orig, - const Vector& x_U, Number* x_U_orig); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - TNLPAdapter(const TNLPAdapter&); - - /** Overloaded Equals Operator */ - void operator=(const TNLPAdapter&); - //@} - - /** @name Method implementing the detection of linearly dependent - equality constraints */ - bool DetermineDependentConstraints(Index n_x_var, - const Index* x_not_fixed_map, - const Number* x_l, const Number* x_u, - const Number* g_l, const Number* g_u, - Index n_c, const Index* c_map, - std::list& c_deps); - - /** Pointer to the TNLP class (class specific to Number* vectors and - * harwell triplet matrices) */ - SmartPtr tnlp_; - - /** Journalist */ - SmartPtr jnlst_; - - /** Object that can be used to detect linearly dependent rows in - * the equality constraint Jacobian */ - SmartPtr dependency_detector_; - - /**@name Algorithmic parameters */ - //@{ - /** Value for a lower bound that denotes -infinity */ - Number nlp_lower_bound_inf_; - /** Value for a upper bound that denotes infinity */ - Number nlp_upper_bound_inf_; - /** Flag indicating how fixed variables should be handled */ - FixedVariableTreatmentEnum fixed_variable_treatment_; - /* Determines relaxation of fixing bound for RELAX_BOUNDS. */ - Number bound_relax_factor_; - /* Maximal slack for one-sidedly bounded variables. If a - * variable has only one bound, say a lower bound xL, then an - * upper bound xL + max_onesided_bound_slack_. If this value is - * zero, no upper bound is added. */ - /* Took this out: Number max_onesided_bound_slack_; */ - /** Enum indicating whether and which derivative test should be - * performed at starting point. */ - DerivativeTestEnum derivative_test_; - /** Size of the perturbation for the derivative test */ - Number derivative_test_perturbation_; - /** Relative threshold for marking deviation from finite - * difference test */ - Number derivative_test_tol_; - /** Flag indicating if all test values should be printed, or only - * those violating the threshold. */ - bool derivative_test_print_all_; - /** Index of first quantity to be checked. */ - Index derivative_test_first_index_; - /** Flag indicating whether the TNLP with identical structure has - * already been solved before. */ - bool warm_start_same_structure_; - /** Flag indicating what Hessian information is to be used. */ - HessianApproximationType hessian_approximation_; - /** Number of linear variables. */ - Index num_linear_variables_; - /** Flag indicating how Jacobian is computed. */ - JacobianApproxEnum jacobian_approximation_; - /** Size of the perturbation for the derivative approximation */ - Number findiff_perturbation_; - /** Maximal perturbation of the initial point */ - Number point_perturbation_radius_; - /** Flag indicating if rhs should be considered during dependency - * detection */ - bool dependency_detection_with_rhs_; - - /** Overall convergence tolerance */ - Number tol_; - //@} - - /**@name Problem Size Data */ - //@{ - /** full dimension of x (fixed + non-fixed) */ - Index n_full_x_; - /** full dimension of g (c + d) */ - Index n_full_g_; - /** non-zeros of the jacobian of c */ - Index nz_jac_c_; - /** non-zeros of the jacobian of c without added constraints for - * fixed variables. */ - Index nz_jac_c_no_extra_; - /** non-zeros of the jacobian of d */ - Index nz_jac_d_; - /** number of non-zeros in full-size Jacobian of g */ - Index nz_full_jac_g_; - /** number of non-zeros in full-size Hessian */ - Index nz_full_h_; - /** number of non-zeros in the non-fixed-size Hessian */ - Index nz_h_; - /** Number of fixed variables */ - Index n_x_fixed_; - //@} - - /** Numbering style of variables and constraints */ - TNLP::IndexStyleEnum index_style_; - - /** @name Local copy of spaces (for warm start) */ - //@{ - SmartPtr x_space_; - SmartPtr c_space_; - SmartPtr d_space_; - SmartPtr x_l_space_; - SmartPtr px_l_space_; - SmartPtr x_u_space_; - SmartPtr px_u_space_; - SmartPtr d_l_space_; - SmartPtr pd_l_space_; - SmartPtr d_u_space_; - SmartPtr pd_u_space_; - SmartPtr Jac_c_space_; - SmartPtr Jac_d_space_; - SmartPtr Hess_lagrangian_space_; - //@} - - /**@name Local Copy of the Data */ - //@{ - Number* full_x_; /** copy of the full x vector (fixed & non-fixed) */ - Number* full_lambda_; /** copy of lambda (yc & yd) */ - Number* full_g_; /** copy of g (c & d) */ - Number* jac_g_; /** the values for the full jacobian of g */ - Number* c_rhs_; /** the rhs values of c */ - //@} - - /**@name Tags for deciding when to update internal copies of vectors */ - //@{ - TaggedObject::Tag x_tag_for_iterates_; - TaggedObject::Tag y_c_tag_for_iterates_; - TaggedObject::Tag y_d_tag_for_iterates_; - TaggedObject::Tag x_tag_for_g_; - TaggedObject::Tag x_tag_for_jac_g_; - //@} - - /**@name Methods to update the values in the local copies of vectors */ - //@{ - bool update_local_x(const Vector& x); - bool update_local_lambda(const Vector& y_c, const Vector& y_d); - //@} - - /**@name Internal routines for evaluating g and jac_g (values stored since - * they are used in both c and d routines */ - //@{ - bool internal_eval_g(bool new_x); - bool internal_eval_jac_g(bool new_x); - //@} - - /** @name Internal methods for dealing with finite difference - approxation */ - //@{ - /** Initialize sparsity structure for finite difference Jacobian */ - void initialize_findiff_jac(const Index* iRow, const Index* jCol); - //@} - - /**@name Internal Permutation Spaces and matrices - */ - //@{ - /** Expansion from fixed x (ipopt) to full x */ - SmartPtr P_x_full_x_; - SmartPtr P_x_full_x_space_; - - /** Expansion from fixed x_L (ipopt) to full x */ - SmartPtr P_x_x_L_; - SmartPtr P_x_x_L_space_; - - /** Expansion from fixed x_U (ipopt) to full x */ - SmartPtr P_x_x_U_; - SmartPtr P_x_x_U_space_; - - /** Expansion from c only (ipopt) to full ampl c */ - SmartPtr P_c_g_space_; - SmartPtr P_c_g_; - - /** Expansion from d only (ipopt) to full ampl d */ - SmartPtr P_d_g_space_; - SmartPtr P_d_g_; - - Index* jac_idx_map_; - Index* h_idx_map_; - - /** Position of fixed variables. This is required for a warm start */ - Index* x_fixed_map_; - //@} - - /** @name Data for finite difference approximations of derivatives */ - //@{ - /** Number of unique nonzeros in constraint Jacobian */ - Index findiff_jac_nnz_; - /** Start position for nonzero indices in ja for each column of - Jacobian */ - Index* findiff_jac_ia_; - /** Ordered by columns, for each column the row indices in - Jacobian */ - Index* findiff_jac_ja_; - /** Position of entry in original triplet matrix */ - Index* findiff_jac_postriplet_; - /** Copy of the lower bounds */ - Number* findiff_x_l_; - /** Copy of the upper bounds */ - Number* findiff_x_u_; - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpTNLPReducer.hpp b/external/ipopt/include/coin/IpTNLPReducer.hpp deleted file mode 100644 index bce1478e1..000000000 --- a/external/ipopt/include/coin/IpTNLPReducer.hpp +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (C) 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTNLPReducer.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Andreas Waechter IBM 2008-08-10 - -#ifndef __IPTNLPREDUCER_HPP__ -#define __IPTNLPREDUCER_HPP__ - -#include "IpTNLP.hpp" - -namespace Ipopt -{ - /** This is a wrapper around a given TNLP class that takes out a - * list of constraints that are given to the constructor. It is - * provided for convenience, if one wants to experiment with - * problems that consist of only a subset of the constraints. But - * keep in mind that this is not efficient, since behind the scenes - * we are still evaluation all functions and derivatives, and are - * making copies of the original data. */ - class TNLPReducer : public TNLP - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Constructor is given the indices of the constraints that - * should be taken out of the problem statement, as well as the - * original TNLP. */ - TNLPReducer(TNLP& tnlp, Index n_g_skip, const Index* index_g_skip, - Index n_xL_skip, const Index* index_xL_skip, - Index n_xU_skip, const Index* index_xU_skip, - Index n_x_fix, const Index* index_f_fix); - - /** Default destructor */ - virtual ~TNLPReducer(); - //@} - - /** @name Overloaded methods from TNLP */ - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style); - - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u); - - virtual bool get_scaling_parameters(Number& obj_scaling, - bool& use_x_scaling, Index n, - Number* x_scaling, - bool& use_g_scaling, Index m, - Number* g_scaling); - - virtual bool get_variables_linearity(Index n, LinearityType* var_types); - - virtual bool get_constraints_linearity(Index m, LinearityType* const_types); - - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, - Number* lambda); - - virtual bool get_warm_start_iterate(IteratesVector& warm_start_iterate); - - virtual bool eval_f(Index n, const Number* x, bool new_x, - Number& obj_value); - - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, - Number* grad_f); - - virtual bool eval_g(Index n, const Number* x, bool new_x, - Index m, Number* g); - - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, - Index *jCol, Number* values); - - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, - Index* iRow, Index* jCol, Number* values); - - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); - - virtual bool intermediate_callback(AlgorithmMode mode, - Index iter, Number obj_value, - Number inf_pr, Number inf_du, - Number mu, Number d_norm, - Number regularization_size, - Number alpha_du, Number alpha_pr, - Index ls_trials, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); - - virtual Index get_number_of_nonlinear_variables(); - - virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, - Index* pos_nonlin_vars); - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - TNLPReducer(); - - /** Copy Constructor */ - TNLPReducer(const TNLPReducer&); - - /** Overloaded Equals Operator */ - void operator=(const TNLPReducer&); - //@} - - /** @name original TNLP */ - //@{ - SmartPtr tnlp_; - Index m_orig_; - Index nnz_jac_g_orig_; - //@} - - /** Number of constraints to be skipped */ - Index n_g_skip_; - - /** Array of indices of the constraints that are to be skipped. - * This is provided at the beginning in the constructor. */ - Index* index_g_skip_; - - /** Index style for original problem. Internally, we use C-Style - * now. */ - IndexStyleEnum index_style_orig_; - - /** Map from original constraints to new constraints. A -1 means - * that a constraint is skipped. */ - Index* g_keep_map_; - - /** Number of constraints in reduced NLP */ - Index m_reduced_; - - /** Number of Jacobian nonzeros in the reduced NLP */ - Index nnz_jac_g_reduced_; - - /** Number of Jacobian nonzeros that are skipped */ - Index nnz_jac_g_skipped_; - - /** Array of Jacobian elements that are to be skipped. This is in - * increasing order. */ - Index* jac_g_skipped_; - - /** Number of lower variable bounds to be skipped. */ - Index n_xL_skip_; - - /** Array of indices of the lower variable bounds to be skipped. */ - Index* index_xL_skip_; - - /** Number of upper variable bounds to be skipped. */ - Index n_xU_skip_; - - /** Array of indices of the upper variable bounds to be skipped. */ - Index* index_xU_skip_; - - /** Number of variables that are to be fixed to initial value. */ - Index n_x_fix_; - - /** Array of indices of the variables that are to be fixed. */ - Index* index_x_fix_; - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpTaggedObject.hpp b/external/ipopt/include/coin/IpTaggedObject.hpp deleted file mode 100644 index 7262c43be..000000000 --- a/external/ipopt/include/coin/IpTaggedObject.hpp +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTaggedObject.hpp 2613 2015-11-04 14:42:02Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPTAGGEDOBJECT_HPP__ -#define __IPTAGGEDOBJECT_HPP__ - -#include "IpUtils.hpp" -#include "IpDebug.hpp" -#include "IpReferenced.hpp" -#include "IpObserver.hpp" -#include - -/* keyword to declare a thread-local variable according to http://en.wikipedia.org/wiki/Thread-local_storage - * GCC < 4.5 on MacOS X does not support TLS - * With Intel compiler on MacOS X, problems with TLS were reported. - */ -#ifndef IPOPT_THREAD_LOCAL - -#if defined(_MSC_VER) -#define IPOPT_THREAD_LOCAL __declspec(thread) -#elif defined(__APPLE__) && ((defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 405)) || defined(__INTEL_COMPILER)) -#define IPOPT_THREAD_LOCAL -#else -#define IPOPT_THREAD_LOCAL __thread -#endif - -#endif - -namespace Ipopt -{ - - /** TaggedObject class. - * Often, certain calculations or operations are expensive, - * and it can be very inefficient to perform these calculations - * again if the input to the calculation has not changed - * since the result was last stored. - * This base class provides an efficient mechanism to update - * a tag, indicating that the object has changed. - * Users of a TaggedObject class, need their own Tag data - * member to keep track of the state of the TaggedObject, the - * last time they performed a calculation. A basic use case for - * users of a class inheriting from TaggedObject follows like - * this: - * - * 1. Initialize your own Tag to zero in constructor. - * - * 2. Before an expensive calculation, - * check if the TaggedObject has changed, passing in - * your own Tag, indicating the last time you used - * the object for the calculation. If it has changed, - * perform the calculation again, and store the result. - * If it has not changed, simply return the stored result. - * - * Here is a simple example: - \verbatim - if (vector.HasChanged(my_vector_tag_)) { - my_vector_tag_ = vector.GetTag(); - result = PerformExpensiveCalculation(vector); - return result; - } - else { - return result; - } - \endverbatim - * - * Objects derived from TaggedObject must indicate that they have changed to - * the base class using the protected member function ObjectChanged(). For - * example, a Vector class, inside its own set method, MUST call - * ObjectChanged() to update the internally stored tag for comparison. - */ - class TaggedObject : public ReferencedObject, public Subject - { - public: - /** Type for the Tag values */ - typedef unsigned int Tag; - - /** Constructor. */ - TaggedObject() - : - Subject() - { - ObjectChanged(); - } - - /** Destructor. */ - virtual ~TaggedObject() - {} - - /** Users of TaggedObjects call this to - * update their own internal tags every time - * they perform the expensive operation. - */ - Tag GetTag() const - { - return tag_; - } - - /** Users of TaggedObjects call this to - * check if the object HasChanged since - * they last updated their own internal - * tag. - */ - bool HasChanged(const Tag comparison_tag) const - { - return (comparison_tag == tag_) ? false : true; - } - protected: - /** Objects derived from TaggedObject MUST call this - * method every time their internal state changes to - * update the internal tag for comparison - */ - void ObjectChanged() - { - DBG_START_METH("TaggedObject::ObjectChanged()", 0); - tag_ = unique_tag_; - unique_tag_++; - DBG_ASSERT(unique_tag_ < std::numeric_limits::max()); - // The Notify method from the Subject base class notifies all - // registered Observers that this subject has changed. - Notify(Observer::NT_Changed); - } - private: - /**@name Default Compiler Generated Methods (Hidden to avoid - * implicit creation/calling). These methods are not implemented - * and we do not want the compiler to implement them for us, so we - * declare them private and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - TaggedObject(const TaggedObject&); - - /** Overloaded Equals Operator */ - void operator=(const TaggedObject&); - //@} - - /** static data member that is incremented every - * time ANY TaggedObject changes. This allows us - * to obtain a unique Tag when the object changes - */ - static IPOPT_THREAD_LOCAL Tag unique_tag_; - - /** The tag indicating the current state of the object. - * We use this to compare against the comparison_tag - * in the HasChanged method. This member is updated - * from the unique_tag_ every time the object changes. - */ - Tag tag_; - - /** The index indicating the cache priority for this - * TaggedObject. If a result that depended on this - * TaggedObject is cached, it will be cached with this - * priority - */ - Index cache_priority_; - }; -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpTimedTask.hpp b/external/ipopt/include/coin/IpTimedTask.hpp deleted file mode 100644 index a1c5bac75..000000000 --- a/external/ipopt/include/coin/IpTimedTask.hpp +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (C) 2006, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTimedTask.hpp 1861 2010-12-21 21:34:47Z andreasw $ -// -// Authors: Andreas Waechter IBM 2005-09-19 - -#ifndef __IPTIMEDTASK_HPP__ -#define __IPTIMEDTASK_HPP__ - -#include "IpUtils.hpp" - -namespace Ipopt -{ - /** This class is used to collect timing information for a - * particular task. */ - class TimedTask - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor. */ - TimedTask() - : - total_cputime_(0.), - total_systime_(0.), - total_walltime_(0.), - start_called_(false), - end_called_(true) - {} - - /** Default destructor */ - ~TimedTask() - {} - //@} - - /** Method for resetting time to zero. */ - void Reset() - { - total_cputime_ = 0.; - total_systime_ = 0.; - total_walltime_ = 0.; - start_called_ = false; - end_called_ = true; - } - - /** Method that is called before execution of the task. */ - void Start() - { - DBG_ASSERT(end_called_); - DBG_ASSERT(!start_called_); - end_called_ = false; - start_called_ = true; - start_cputime_ = CpuTime(); - start_systime_ = SysTime(); - start_walltime_ = WallclockTime(); - } - - /** Method that is called after execution of the task. */ - void End() - { - DBG_ASSERT(!end_called_); - DBG_ASSERT(start_called_); - end_called_ = true; - start_called_ = false; - total_cputime_ += CpuTime() - start_cputime_; - total_systime_ += SysTime() - start_systime_; - total_walltime_ += WallclockTime() - start_walltime_; - } - - /** Method that is called after execution of the task for which - * timing might have been started. This only updates the timing - * if the timing has indeed been conducted. This is useful to - * stop timing after catching exceptions. */ - void EndIfStarted() - { - if (start_called_) { - end_called_ = true; - start_called_ = false; - total_cputime_ += CpuTime() - start_cputime_; - total_systime_ += SysTime() - start_systime_; - total_walltime_ += WallclockTime() - start_walltime_; - } - DBG_ASSERT(end_called_); - } - - /** Method returning total CPU time spend for task so far. */ - Number TotalCpuTime() const - { - DBG_ASSERT(end_called_); - return total_cputime_; - } - - /** Method returning total system time spend for task so far. */ - Number TotalSysTime() const - { - DBG_ASSERT(end_called_); - return total_systime_; - } - - /** Method returning total wall clock time spend for task so far. */ - Number TotalWallclockTime() const - { - DBG_ASSERT(end_called_); - return total_walltime_; - } - - private: - /**@name Default Compiler Generated Methods (Hidden to avoid - * implicit creation/calling). These methods are not - * implemented and we do not want the compiler to implement them - * for us, so we declare them private and do not define - * them. This ensures that they will not be implicitly - * created/called. */ - //@{ - /** Copy Constructor */ - TimedTask(const TimedTask&); - - /** Overloaded Equals Operator */ - void operator=(const TimedTask&); - //@} - - /** CPU time at beginning of task. */ - Number start_cputime_; - /** Total CPU time for task measured so far. */ - Number total_cputime_; - /** System time at beginning of task. */ - Number start_systime_; - /** Total system time for task measured so far. */ - Number total_systime_; - /** Wall clock time at beginning of task. */ - Number start_walltime_; - /** Total wall clock time for task measured so far. */ - Number total_walltime_; - - /** @name fields for debugging */ - //@{ - bool start_called_; - bool end_called_; - //@} - - }; -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpTimingStatistics.hpp b/external/ipopt/include/coin/IpTimingStatistics.hpp deleted file mode 100644 index 850ed1b8e..000000000 --- a/external/ipopt/include/coin/IpTimingStatistics.hpp +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright (C) 2005, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTimingStatistics.hpp 2005 2011-06-06 12:55:16Z stefan $ -// -// Authors: Andreas Waechter IBM 2005-09-19 - -#ifndef __IPTIMINGSTATISTICS_HPP__ -#define __IPTIMINGSTATISTICS_HPP__ - -#include "IpReferenced.hpp" -#include "IpJournalist.hpp" -#include "IpTimedTask.hpp" - -namespace Ipopt -{ - /** This class collects all timing statistics for Ipopt. - */ - class TimingStatistics : public ReferencedObject - { - public: - /**@name Constructors/Destructors */ - //@{ - /** Default constructor. */ - TimingStatistics() - {} - - /** Default destructor */ - virtual ~TimingStatistics() - {} - //@} - - /** Method for resetting all times. */ - void ResetTimes(); - - /** Method for printing all timing information */ - void PrintAllTimingStatistics(Journalist& jnlst, - EJournalLevel level, - EJournalCategory category) const; - - /**@name Accessor methods to all timed tasks. */ - //@{ - TimedTask& OverallAlgorithm() - { - return OverallAlgorithm_; - } - TimedTask& PrintProblemStatistics() - { - return PrintProblemStatistics_; - } - TimedTask& InitializeIterates() - { - return InitializeIterates_; - } - TimedTask& UpdateHessian() - { - return UpdateHessian_; - } - TimedTask& OutputIteration() - { - return OutputIteration_; - } - TimedTask& UpdateBarrierParameter() - { - return UpdateBarrierParameter_; - } - TimedTask& ComputeSearchDirection() - { - return ComputeSearchDirection_; - } - TimedTask& ComputeAcceptableTrialPoint() - { - return ComputeAcceptableTrialPoint_; - } - TimedTask& AcceptTrialPoint() - { - return AcceptTrialPoint_; - } - TimedTask& CheckConvergence() - { - return CheckConvergence_; - } - - TimedTask& PDSystemSolverTotal() - { - return PDSystemSolverTotal_; - } - TimedTask& PDSystemSolverSolveOnce() - { - return PDSystemSolverSolveOnce_; - } - TimedTask& ComputeResiduals() - { - return ComputeResiduals_; - } - TimedTask& StdAugSystemSolverMultiSolve() - { - return StdAugSystemSolverMultiSolve_; - } - TimedTask& LinearSystemScaling() - { - return LinearSystemScaling_; - } - TimedTask& LinearSystemSymbolicFactorization() - { - return LinearSystemSymbolicFactorization_; - } - TimedTask& LinearSystemFactorization() - { - return LinearSystemFactorization_; - } - TimedTask& LinearSystemBackSolve() - { - return LinearSystemBackSolve_; - } - TimedTask& LinearSystemStructureConverter() - { - return LinearSystemStructureConverter_; - } - TimedTask& LinearSystemStructureConverterInit() - { - return LinearSystemStructureConverterInit_; - } - TimedTask& QualityFunctionSearch() - { - return QualityFunctionSearch_; - } - TimedTask& TryCorrector() - { - return TryCorrector_; - } - - TimedTask& Task1() - { - return Task1_; - } - TimedTask& Task2() - { - return Task2_; - } - TimedTask& Task3() - { - return Task3_; - } - TimedTask& Task4() - { - return Task4_; - } - TimedTask& Task5() - { - return Task5_; - } - TimedTask& Task6() - { - return Task6_; - } - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Copy Constructor */ - TimingStatistics(const TimingStatistics&); - - /** Overloaded Equals Operator */ - void operator=(const TimingStatistics&); - //@} - - /**@name All timed tasks. */ - //@{ - TimedTask OverallAlgorithm_; - TimedTask PrintProblemStatistics_; - TimedTask InitializeIterates_; - TimedTask UpdateHessian_; - TimedTask OutputIteration_; - TimedTask UpdateBarrierParameter_; - TimedTask ComputeSearchDirection_; - TimedTask ComputeAcceptableTrialPoint_; - TimedTask AcceptTrialPoint_; - TimedTask CheckConvergence_; - - TimedTask PDSystemSolverTotal_; - TimedTask PDSystemSolverSolveOnce_; - TimedTask ComputeResiduals_; - TimedTask StdAugSystemSolverMultiSolve_; - TimedTask LinearSystemScaling_; - TimedTask LinearSystemSymbolicFactorization_; - TimedTask LinearSystemFactorization_; - TimedTask LinearSystemBackSolve_; - TimedTask LinearSystemStructureConverter_; - TimedTask LinearSystemStructureConverterInit_; - TimedTask QualityFunctionSearch_; - TimedTask TryCorrector_; - - TimedTask Task1_; - TimedTask Task2_; - TimedTask Task3_; - TimedTask Task4_; - TimedTask Task5_; - TimedTask Task6_; - //@} - }; - -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpTripletHelper.hpp b/external/ipopt/include/coin/IpTripletHelper.hpp deleted file mode 100644 index 35424c03e..000000000 --- a/external/ipopt/include/coin/IpTripletHelper.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTripletHelper.hpp 2380 2013-09-06 22:57:49Z ghackebeil $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPTRIPLETHELPER_HPP__ -#define __IPTRIPLETHELPER_HPP__ - -#include "IpTypes.hpp" -#include "IpException.hpp" - -namespace Ipopt -{ - - DECLARE_STD_EXCEPTION(UNKNOWN_MATRIX_TYPE); - DECLARE_STD_EXCEPTION(UNKNOWN_VECTOR_TYPE); - - /** forward declarations */ - class Matrix; - class GenTMatrix; - class SymTMatrix; - class DiagMatrix; - class IdentityMatrix; - class ExpansionMatrix; - class ScaledMatrix; - class SymScaledMatrix; - class SumMatrix; - class SumSymMatrix; - class ZeroMatrix; - class ZeroSymMatrix; - class CompoundMatrix; - class CompoundSymMatrix; - class TransposeMatrix; - class ExpandedMultiVectorMatrix; - class Vector; - - class TripletHelper - { - public: - /**@name A set of recursive routines that help with the Triplet format. */ - //@{ - /** find the total number of triplet entries of a Matrix */ - static Index GetNumberEntries(const Matrix& matrix); - - /** fill the irows, jcols structure for the triplet format from the matrix */ - static void FillRowCol(Index n_entries, const Matrix& matrix, Index* iRow, Index* jCol, Index row_offset=0, Index col_offset=0); - - /** fill the values for the triplet format from the matrix */ - static void FillValues(Index n_entries, const Matrix& matrix, Number* values); - - /** fill the values from the vector into a dense double* structure */ - static void FillValuesFromVector(Index dim, const Vector& vector, Number* values); - - /** put the values from the double* back into the vector */ - static void PutValuesInVector(Index dim, const double* values, Vector& vector); - //@} - - private: - /** find the total number of triplet entries for the SumMatrix */ - static Index GetNumberEntries_(const SumMatrix& matrix); - - /** find the total number of triplet entries for the SumSymMatrix */ - static Index GetNumberEntries_(const SumSymMatrix& matrix); - - /** find the total number of triplet entries for the CompoundMatrix */ - static Index GetNumberEntries_(const CompoundMatrix& matrix); - - /** find the total number of triplet entries for the CompoundSymMatrix */ - static Index GetNumberEntries_(const CompoundSymMatrix& matrix); - - /** find the total number of triplet entries for the TransposeMatrix */ - static Index GetNumberEntries_(const TransposeMatrix& matrix); - - /** find the total number of triplet entries for the TransposeMatrix */ - static Index GetNumberEntries_(const ExpandedMultiVectorMatrix& matrix); - - static void FillRowCol_(Index n_entries, const GenTMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const GenTMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const SymTMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const SymTMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const DiagMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const DiagMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const IdentityMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const IdentityMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const ExpansionMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const ExpansionMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const SumMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const SumMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const SumSymMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const SumSymMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const CompoundMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const CompoundMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const CompoundSymMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const CompoundSymMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const ScaledMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const ScaledMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const SymScaledMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const SymScaledMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const TransposeMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const TransposeMatrix& matrix, Number* values); - - static void FillRowCol_(Index n_entries, const ExpandedMultiVectorMatrix& matrix, Index row_offset, Index col_offset, Index* iRow, Index* jCol); - - static void FillValues_(Index n_entries, const ExpandedMultiVectorMatrix& matrix, Number* values); - - }; -} // namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpTypes.hpp b/external/ipopt/include/coin/IpTypes.hpp deleted file mode 100644 index 9c41b8f13..000000000 --- a/external/ipopt/include/coin/IpTypes.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2004, 2006 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpTypes.hpp 2005 2011-06-06 12:55:16Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPTYPES_HPP__ -#define __IPTYPES_HPP__ - -#include "IpoptConfig.h" - -namespace Ipopt -{ - /** Type of all numbers */ - typedef double Number; - /** Type of all indices of vectors, matrices etc */ - typedef int Index; - /** Type of default integer */ - typedef int Int; - -} // namespace Ipopt - -/* Type of Fortran integer translated into C */ -typedef FORTRAN_INTEGER_TYPE ipfint; - -#endif diff --git a/external/ipopt/include/coin/IpUtils.hpp b/external/ipopt/include/coin/IpUtils.hpp deleted file mode 100644 index 4e5f04557..000000000 --- a/external/ipopt/include/coin/IpUtils.hpp +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2004, 2009 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpUtils.hpp 2167 2013-03-08 11:15:38Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPUTILS_HPP__ -#define __IPUTILS_HPP__ - -// Standard Ip Include Files -#include "IpTypes.hpp" -#include "IpDebug.hpp" - -namespace Ipopt -{ - - inline Index Max(Index a, Index b) - { - return ((a) > (b) ? (a) : (b)); - } - - inline Index Max(Index a, Index b, Index c) - { - Index max = Max(a,b); - max = Max(max, c); - return max; - } - - inline Index Max(Index a, Index b, Index c, Index d) - { - Index max = Max(a, b, c); - max = Max(max, d); - return max; - } - - inline Index Min(Index a, Index b) - { - return ((a) < (b) ? (a) : (b)); - } - - inline Index Min(Index a, Index b, Index c) - { - Index min = Min(a,b); - min = Min(min, c); - return min; - } - - inline Index Min(Index a, Index b, Index c, Index d) - { - Index min = Min(a, b, c); - min = Min(min, d); - return min; - } - - /////////////////////////////////////////// - - inline Number Max(Number a, Number b) - { - return ((a) > (b) ? (a) : (b)); - } - - inline Number Max(Number a, Number b, Number c) - { - Number max = Max(a,b); - max = Max(max, c); - return max; - } - - inline Number Max(Number a, Number b, Number c, Number d) - { - Number max = Max(a, b, c); - max = Max(max, d); - return max; - } - - inline Number Min(Number a, Number b) - { - return ((a) < (b) ? (a) : (b)); - } - - inline Number Min(Number a, Number b, Number c) - { - Number min = Min(a,b); - min = Min(min, c); - return min; - } - - inline Number Min(Number a, Number b, Number c, Number d) - { - Number min = Min(a, b, c); - min = Min(min, d); - return min; - } - - /** Function returning true iff the argument is a valid double number - * (not NaN or Inf). */ - bool IsFiniteNumber(Number val); - - /** Function returning a random number between 0 and 1 */ - Number IpRandom01(); - - /** Function resetting the random number generator */ - void IpResetRandom01(); - - /** method determining CPU time */ - Number CpuTime(); - - /** method determining system time */ - Number SysTime(); - - /** method determining wallclock time since first call */ - Number WallclockTime(); - - /** Method for comparing two numbers within machine precision. The - * return value is true if lhs is less or equal the rhs, relaxing - * this inequality by something a little larger than machine - * precision relative to the absolute value of BasVal. */ - bool Compare_le(Number lhs, Number rhs, Number BasVal); - - /** Method for printing a formatted output to a string with given size. - */ - int Snprintf(char* str, long size, const char* format, ...); - -} //namespace Ipopt - -#endif diff --git a/external/ipopt/include/coin/IpVector.hpp b/external/ipopt/include/coin/IpVector.hpp deleted file mode 100644 index a90355888..000000000 --- a/external/ipopt/include/coin/IpVector.hpp +++ /dev/null @@ -1,774 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpVector.hpp 2472 2014-04-05 17:47:20Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPVECTOR_HPP__ -#define __IPVECTOR_HPP__ - -#include "IpTypes.hpp" -#include "IpTaggedObject.hpp" -#include "IpCachedResults.hpp" -#include "IpSmartPtr.hpp" -#include "IpJournalist.hpp" -#include "IpException.hpp" - -#include - -namespace Ipopt -{ - /** Exception that can be used to flag unimplemented linear algebra - * methods */ - DECLARE_STD_EXCEPTION(UNIMPLEMENTED_LINALG_METHOD_CALLED); - - /* forward declarations */ - class VectorSpace; - - /** Vector Base Class. - * This is the base class for all derived vector types. Those vectors - * are meant to store entities like iterates, Lagrangian multipliers, - * constraint values etc. The implementation of a vector type depends - * on the computational environment (e.g. just a double array on a shared - * memory machine, or distributed double arrays for a distributed - * memory machine.) - * - * Deriving from Vector: This class inherits from tagged object to - * implement an advanced caching scheme. Because of this, the - * TaggedObject method ObjectChanged() must be called each time the - * Vector changes. If you overload the XXXX_Impl protected methods, - * this taken care of (along with caching if possible) for you. If - * you have additional methods in your derived class that change the - * underlying data (vector values), you MUST remember to call - * ObjectChanged() AFTER making the change! - */ - class Vector : public TaggedObject - { - public: - /** @name Constructor/Destructor */ - //@{ - /** Constructor. It has to be given a pointer to the - * corresponding VectorSpace. - */ - inline - Vector(const VectorSpace* owner_space); - - /** Destructor */ - inline - virtual ~Vector(); - //@} - - /** Create new Vector of the same type with uninitialized data */ - inline - Vector* MakeNew() const; - - /** Create new Vector of the same type and copy the data over */ - inline - Vector* MakeNewCopy() const; - - /**@name Standard BLAS-1 Operations - * (derived classes do NOT overload these - * methods, instead, overload the - * protected versions of these methods). */ - //@{ - /** Copy the data of the vector x into this vector (DCOPY). */ - inline - void Copy(const Vector& x); - - /** Scales the vector by scalar alpha (DSCAL) */ - void Scal(Number alpha); - - /** Add the multiple alpha of vector x to this vector (DAXPY) */ - inline - void Axpy(Number alpha, const Vector &x); - - /** Computes inner product of vector x with this (DDOT) */ - inline - Number Dot(const Vector &x) const; - - /** Computes the 2-norm of this vector (DNRM2) */ - inline - Number Nrm2() const; - - /** Computes the 1-norm of this vector (DASUM) */ - inline - Number Asum() const; - - /** Computes the max-norm of this vector (based on IDAMAX) */ - inline - Number Amax() const; - //@} - - /** @name Additional (Non-BLAS) Vector Methods - * (derived classes do NOT overload these - * methods, instead, overload the - * protected versions of these methods). */ - //@{ - /** Set each element in the vector to the scalar alpha. */ - inline - void Set(Number alpha); - - /** Element-wise division \f$y_i \gets y_i/x_i\f$*/ - inline - void ElementWiseDivide(const Vector& x); - - /** Element-wise multiplication \f$y_i \gets y_i*x_i\f$ */ - inline - void ElementWiseMultiply(const Vector& x); - - /** Element-wise max against entries in x */ - inline - void ElementWiseMax(const Vector& x); - - /** Element-wise min against entries in x */ - inline - void ElementWiseMin(const Vector& x); - - /** Reciprocates the entries in the vector */ - inline - void ElementWiseReciprocal(); - - /** Absolute values of the entries in the vector */ - inline - void ElementWiseAbs(); - - /** Element-wise square root of the entries in the vector */ - inline - void ElementWiseSqrt(); - - /** Replaces the vector values with their sgn values - ( -1 if x_i < 0, 0 if x_i == 0, and 1 if x_i > 0) - */ - inline - void ElementWiseSgn(); - - /** Add scalar to every vector component */ - inline - void AddScalar(Number scalar); - - /** Returns the maximum value in the vector */ - inline - Number Max() const; - - /** Returns the minimum value in the vector */ - inline - Number Min() const; - - /** Returns the sum of the vector entries */ - inline - Number Sum() const; - - /** Returns the sum of the logs of each vector entry */ - inline - Number SumLogs() const; - //@} - - /** @name Methods for specialized operations. A prototype - * implementation is provided, but for efficient implementation - * those should be specially implemented. - */ - //@{ - /** Add one vector, y = a * v1 + c * y. This is automatically - * reduced to call AddTwoVectors. */ - inline - void AddOneVector(Number a, const Vector& v1, Number c); - - /** Add two vectors, y = a * v1 + b * v2 + c * y. Here, this - * vector is y */ - inline void AddTwoVectors(Number a, const Vector& v1, - Number b, const Vector& v2, Number c); - /** Fraction to the boundary parameter. Computes \f$\alpha = - * \max\{\bar\alpha\in(0,1] : x + \bar\alpha \Delta \geq (1-\tau)x\}\f$ - */ - inline - Number FracToBound(const Vector& delta, Number tau) const; - /** Add the quotient of two vectors, y = a * z/s + c * y. */ - inline - void AddVectorQuotient(Number a, const Vector& z, const Vector& s, - Number c); - //@} - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). */ - inline - bool HasValidNumbers() const; - - /** @name Accessor methods */ - //@{ - /** Dimension of the Vector */ - inline - Index Dim() const; - - /** Return the owner VectorSpace*/ - inline - SmartPtr OwnerSpace() const; - //@} - - /** @name Output methods - * (derived classes do NOT overload these - * methods, instead, overload the - * protected versions of these methods). */ - //@{ - /** Print the entire vector */ - void Print(SmartPtr jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent=0, - const std::string& prefix="") const; - void Print(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent=0, - const std::string& prefix="") const; - //@} - - protected: - /** @name implementation methods (derived classes MUST - * overload these pure virtual protected methods.) - */ - //@{ - /** Copy the data of the vector x into this vector (DCOPY). */ - virtual void CopyImpl(const Vector& x)=0; - - /** Scales the vector by scalar alpha (DSCAL) */ - virtual void ScalImpl(Number alpha)=0; - - /** Add the multiple alpha of vector x to this vector (DAXPY) */ - virtual void AxpyImpl(Number alpha, const Vector &x)=0; - - /** Computes inner product of vector x with this (DDOT) */ - virtual Number DotImpl(const Vector &x) const =0; - - /** Computes the 2-norm of this vector (DNRM2) */ - virtual Number Nrm2Impl() const =0; - - /** Computes the 1-norm of this vector (DASUM) */ - virtual Number AsumImpl() const =0; - - /** Computes the max-norm of this vector (based on IDAMAX) */ - virtual Number AmaxImpl() const =0; - - /** Set each element in the vector to the scalar alpha. */ - virtual void SetImpl(Number alpha)=0; - - /** Element-wise division \f$y_i \gets y_i/x_i\f$*/ - virtual void ElementWiseDivideImpl(const Vector& x)=0; - - /** Element-wise multiplication \f$y_i \gets y_i*x_i\f$ */ - virtual void ElementWiseMultiplyImpl(const Vector& x)=0; - - /** Element-wise max against entries in x */ - virtual void ElementWiseMaxImpl(const Vector& x)=0; - - /** Element-wise min against entries in x */ - virtual void ElementWiseMinImpl(const Vector& x)=0; - - /** Reciprocates the elements of the vector */ - virtual void ElementWiseReciprocalImpl()=0; - - /** Take elementwise absolute values of the elements of the vector */ - virtual void ElementWiseAbsImpl()=0; - - /** Take elementwise square-root of the elements of the vector */ - virtual void ElementWiseSqrtImpl()=0; - - /** Replaces entries with sgn of the entry */ - virtual void ElementWiseSgnImpl()=0; - - /** Add scalar to every component of vector */ - virtual void AddScalarImpl(Number scalar)=0; - - /** Max value in the vector */ - virtual Number MaxImpl() const=0; - - /** Min number in the vector */ - virtual Number MinImpl() const=0; - - /** Sum of entries in the vector */ - virtual Number SumImpl() const=0; - - /** Sum of logs of entries in the vector */ - virtual Number SumLogsImpl() const=0; - - /** Add two vectors (a * v1 + b * v2). Result is stored in this - vector. */ - virtual void AddTwoVectorsImpl(Number a, const Vector& v1, - Number b, const Vector& v2, Number c); - - /** Fraction to boundary parameter. */ - virtual Number FracToBoundImpl(const Vector& delta, Number tau) const; - - /** Add the quotient of two vectors */ - virtual void AddVectorQuotientImpl(Number a, const Vector& z, - const Vector& s, Number c); - - /** Method for determining if all stored numbers are valid (i.e., - * no Inf or Nan). A default implementation using Asum is - * provided. */ - virtual bool HasValidNumbersImpl() const; - - /** Print the entire vector */ - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const =0; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default constructor */ - Vector(); - - /** Copy constructor */ - Vector(const Vector&); - - /** Overloaded Equals Operator */ - Vector& operator=(const Vector&); - //@} - - /** Vector Space */ - const SmartPtr owner_space_; - - /**@name CachedResults data members */ - //@{ - /** Cache for dot products */ - mutable CachedResults dot_cache_; - - mutable TaggedObject::Tag nrm2_cache_tag_; - mutable Number cached_nrm2_; - - mutable TaggedObject::Tag asum_cache_tag_; - mutable Number cached_asum_; - - mutable TaggedObject::Tag amax_cache_tag_; - mutable Number cached_amax_; - - mutable TaggedObject::Tag max_cache_tag_; - mutable Number cached_max_; - - mutable TaggedObject::Tag min_cache_tag_; - mutable Number cached_min_; - - mutable TaggedObject::Tag sum_cache_tag_; - mutable Number cached_sum_; - - mutable TaggedObject::Tag sumlogs_cache_tag_; - mutable Number cached_sumlogs_; - - mutable TaggedObject::Tag valid_cache_tag_; - mutable bool cached_valid_; - - // AW: I removed this cache since it gets in the way for the - // quality function search - // /** Cache for FracToBound */ - // mutable CachedResults frac_to_bound_cache_; - //@} - - }; - - /** VectorSpace base class, corresponding to the Vector base class. - * For each Vector implementation, a corresponding VectorSpace has - * to be implemented. A VectorSpace is able to create new Vectors - * of a specific type. The VectorSpace should also store - * information that is common to all Vectors of that type. For - * example, the dimension of a Vector is stored in the VectorSpace - * base class. - */ - class VectorSpace : public ReferencedObject - { - public: - /** @name Constructors/Destructors */ - //@{ - /** Constructor, given the dimension of all vectors generated by - * this VectorSpace. - */ - VectorSpace(Index dim); - - /** Destructor */ - virtual ~VectorSpace() - {} - //@} - - /** Pure virtual method for creating a new Vector of the - * corresponding type. - */ - virtual Vector* MakeNew() const=0; - - /** Accessor function for the dimension of the vectors of this type.*/ - Index Dim() const - { - return dim_; - } - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** default constructor */ - VectorSpace(); - - /** Copy constructor */ - VectorSpace(const VectorSpace&); - - /** Overloaded Equals Operator */ - VectorSpace& operator=(const VectorSpace&); - //@} - - /** Dimension of the vectors in this vector space. */ - const Index dim_; - }; - - /* inline methods */ - inline - Vector::~Vector() - {} - - inline - Vector::Vector(const VectorSpace* owner_space) - : - TaggedObject(), - owner_space_(owner_space), - dot_cache_(10), - nrm2_cache_tag_(0), - asum_cache_tag_(0), - amax_cache_tag_(0), - max_cache_tag_(0), - min_cache_tag_(0), - sum_cache_tag_(0), - sumlogs_cache_tag_(0), - cached_valid_(0) - { - DBG_ASSERT(IsValid(owner_space_)); - } - - inline - Vector* Vector::MakeNew() const - { - return owner_space_->MakeNew(); - } - - inline - Vector* Vector::MakeNewCopy() const - { - // ToDo: We can probably copy also the cached values for Norms etc here - Vector* copy = MakeNew(); - copy->Copy(*this); - return copy; - } - - inline - void Vector::Copy(const Vector& x) - { - CopyImpl(x); - ObjectChanged(); - // Also copy any cached scalar values from the original vector - // ToDo: Check if that is too much overhead - TaggedObject::Tag x_tag = x.GetTag(); - if (x_tag == x.nrm2_cache_tag_) { - nrm2_cache_tag_ = GetTag(); - cached_nrm2_ = x.cached_nrm2_; - } - if (x_tag == x.asum_cache_tag_) { - asum_cache_tag_ = GetTag(); - cached_asum_ = x.cached_asum_; - } - if (x_tag == x.amax_cache_tag_) { - amax_cache_tag_ = GetTag(); - cached_amax_ = x.cached_amax_; - } - if (x_tag == x.max_cache_tag_) { - max_cache_tag_ = GetTag(); - cached_max_ = x.cached_max_; - } - if (x_tag == x.min_cache_tag_) { - min_cache_tag_ = GetTag(); - cached_min_ = x.cached_min_; - } - if (x_tag == x.sum_cache_tag_) { - sum_cache_tag_ = GetTag(); - cached_sum_ = x.cached_sum_; - } - if (x_tag == x.sumlogs_cache_tag_) { - sumlogs_cache_tag_ = GetTag(); - cached_sumlogs_ = x.cached_sumlogs_; - } - } - - inline - void Vector::Axpy(Number alpha, const Vector &x) - { - AxpyImpl(alpha, x); - ObjectChanged(); - } - - inline - Number Vector::Dot(const Vector &x) const - { - // The current implementation of the caching doesn't allow to have - // a dependency of something with itself. Therefore, we use the - // Nrm2 method if the dot product is to be taken with the vector - // itself. Might be more efficient anyway. - if (this==&x) { - Number nrm2 = Nrm2(); - return nrm2*nrm2; - } - Number retValue; - if (!dot_cache_.GetCachedResult2Dep(retValue, this, &x)) { - retValue = DotImpl(x); - dot_cache_.AddCachedResult2Dep(retValue, this, &x); - } - return retValue; - } - - inline - Number Vector::Nrm2() const - { - if (nrm2_cache_tag_ != GetTag()) { - cached_nrm2_ = Nrm2Impl(); - nrm2_cache_tag_ = GetTag(); - } - return cached_nrm2_; - } - - inline - Number Vector::Asum() const - { - if (asum_cache_tag_ != GetTag()) { - cached_asum_ = AsumImpl(); - asum_cache_tag_ = GetTag(); - } - return cached_asum_; - } - - inline - Number Vector::Amax() const - { - if (amax_cache_tag_ != GetTag()) { - cached_amax_ = AmaxImpl(); - amax_cache_tag_ = GetTag(); - } - return cached_amax_; - } - - inline - Number Vector::Sum() const - { - if (sum_cache_tag_ != GetTag()) { - cached_sum_ = SumImpl(); - sum_cache_tag_ = GetTag(); - } - return cached_sum_; - } - - inline - Number Vector::SumLogs() const - { - if (sumlogs_cache_tag_ != GetTag()) { - cached_sumlogs_ = SumLogsImpl(); - sumlogs_cache_tag_ = GetTag(); - } - return cached_sumlogs_; - } - - inline - void Vector::ElementWiseSgn() - { - ElementWiseSgnImpl(); - ObjectChanged(); - } - - inline - void Vector::Set(Number alpha) - { - // Could initialize caches here - SetImpl(alpha); - ObjectChanged(); - } - - inline - void Vector::ElementWiseDivide(const Vector& x) - { - ElementWiseDivideImpl(x); - ObjectChanged(); - } - - inline - void Vector::ElementWiseMultiply(const Vector& x) - { - ElementWiseMultiplyImpl(x); - ObjectChanged(); - } - - inline - void Vector::ElementWiseReciprocal() - { - ElementWiseReciprocalImpl(); - ObjectChanged(); - } - - inline - void Vector::ElementWiseMax(const Vector& x) - { - // Could initialize some caches here - ElementWiseMaxImpl(x); - ObjectChanged(); - } - - inline - void Vector::ElementWiseMin(const Vector& x) - { - // Could initialize some caches here - ElementWiseMinImpl(x); - ObjectChanged(); - } - - inline - void Vector::ElementWiseAbs() - { - // Could initialize some caches here - ElementWiseAbsImpl(); - ObjectChanged(); - } - - inline - void Vector::ElementWiseSqrt() - { - ElementWiseSqrtImpl(); - ObjectChanged(); - } - - inline - void Vector::AddScalar(Number scalar) - { - // Could initialize some caches here - AddScalarImpl(scalar); - ObjectChanged(); - } - - inline - Number Vector::Max() const - { - if (max_cache_tag_ != GetTag()) { - cached_max_ = MaxImpl(); - max_cache_tag_ = GetTag(); - } - return cached_max_; - } - - inline - Number Vector::Min() const - { - if (min_cache_tag_ != GetTag()) { - cached_min_ = MinImpl(); - min_cache_tag_ = GetTag(); - } - return cached_min_; - } - - inline - void Vector::AddOneVector(Number a, const Vector& v1, Number c) - { - AddTwoVectors(a, v1, 0., v1, c); - } - - inline - void Vector::AddTwoVectors(Number a, const Vector& v1, - Number b, const Vector& v2, Number c) - { - AddTwoVectorsImpl(a, v1, b, v2, c); - ObjectChanged(); - } - - inline - Number Vector::FracToBound(const Vector& delta, Number tau) const - { - /* AW: I avoid the caching here, since it leads to overhead in the - quality function search. Caches for this are in - CalculatedQuantities. - Number retValue; - std::vector tdeps(1); - tdeps[0] = δ - std::vector sdeps(1); - sdeps[0] = tau; - if (!frac_to_bound_cache_.GetCachedResult(retValue, tdeps, sdeps)) { - retValue = FracToBoundImpl(delta, tau); - frac_to_bound_cache_.AddCachedResult(retValue, tdeps, sdeps); - } - return retValue; - */ - return FracToBoundImpl(delta, tau); - } - - inline - void Vector::AddVectorQuotient(Number a, const Vector& z, - const Vector& s, Number c) - { - AddVectorQuotientImpl(a, z, s, c); - ObjectChanged(); - } - - inline - bool Vector::HasValidNumbers() const - { - if (valid_cache_tag_ != GetTag()) { - cached_valid_ = HasValidNumbersImpl(); - valid_cache_tag_ = GetTag(); - } - return cached_valid_; - } - - inline - Index Vector::Dim() const - { - return owner_space_->Dim(); - } - - inline - SmartPtr Vector::OwnerSpace() const - { - return owner_space_; - } - - inline - VectorSpace::VectorSpace(Index dim) - : - dim_(dim) - {} - -} // namespace Ipopt - -// Macro definitions for debugging vectors -#if COIN_IPOPT_VERBOSITY == 0 -# define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec) -#else -# define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec) \ - if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \ - if (dbg_jrnl.Jnlst()!=NULL) { \ - (__vec).Print(dbg_jrnl.Jnlst(), \ - J_ERROR, J_DBG, \ - __vec_name, \ - dbg_jrnl.IndentationLevel()*2, \ - "# "); \ - } \ - } -#endif //if COIN_IPOPT_VERBOSITY == 0 - -#endif diff --git a/external/ipopt/include/coin/IpZeroSymMatrix.hpp b/external/ipopt/include/coin/IpZeroSymMatrix.hpp deleted file mode 100644 index 35ad95e7a..000000000 --- a/external/ipopt/include/coin/IpZeroSymMatrix.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2004, 2008 International Business Machines and others. -// All Rights Reserved. -// This code is published under the Eclipse Public License. -// -// $Id: IpZeroSymMatrix.hpp 2269 2013-05-05 11:32:40Z stefan $ -// -// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 - -#ifndef __IPZEROSYMMATRIX_HPP__ -#define __IPZEROSYMMATRIX_HPP__ - -#include "IpUtils.hpp" -#include "IpSymMatrix.hpp" - -namespace Ipopt -{ - - /** Class for Symmetric Matrices with only zero entries. - */ - class ZeroSymMatrix : public SymMatrix - { - public: - - /**@name Constructors / Destructors */ - //@{ - - /** Constructor, taking the corresponding matrix space. - */ - ZeroSymMatrix(const SymMatrixSpace* owner_space); - - /** Destructor */ - ~ZeroSymMatrix(); - //@} - - protected: - /**@name Methods overloaded from matrix */ - //@{ - virtual void MultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - virtual void TransMultVectorImpl(Number alpha, const Vector& x, - Number beta, Vector& y) const; - - virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const - {} - - virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const - {} - - virtual void PrintImpl(const Journalist& jnlst, - EJournalLevel level, - EJournalCategory category, - const std::string& name, - Index indent, - const std::string& prefix) const; - //@} - - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - ZeroSymMatrix(); - - /** Copy Constructor */ - ZeroSymMatrix(const ZeroSymMatrix&); - - /** Overloaded Equals Operator */ - void operator=(const ZeroSymMatrix&); - //@} - }; - - /** Class for matrix space for ZeroSymMatrix. */ - class ZeroSymMatrixSpace : public SymMatrixSpace - { - public: - /** @name Constructors / Destructors */ - //@{ - /** Constructor, given the number of row and columns. - */ - ZeroSymMatrixSpace(Index dim) - : - SymMatrixSpace(dim) - {} - - /** Destructor */ - virtual ~ZeroSymMatrixSpace() - {} - //@} - - /** Overloaded MakeNew method for the MatrixSpace base class. - */ - virtual Matrix* MakeNew() const - { - return MakeNewZeroSymMatrix(); - } - - /** Overloaded method from SymMatrixSpace base class - */ - virtual SymMatrix* MakeNewSymMatrix() const - { - return MakeNewZeroSymMatrix(); - } - - /** Method for creating a new matrix of this specific type. */ - ZeroSymMatrix* MakeNewZeroSymMatrix() const - { - return new ZeroSymMatrix(this); - } - private: - /**@name Default Compiler Generated Methods - * (Hidden to avoid implicit creation/calling). - * These methods are not implemented and - * we do not want the compiler to implement - * them for us, so we declare them private - * and do not define them. This ensures that - * they will not be implicitly created/called. */ - //@{ - /** Default Constructor */ - ZeroSymMatrixSpace(); - - /** Copy Constructor */ - ZeroSymMatrixSpace(const ZeroSymMatrixSpace&); - - /** Overloaded Equals Operator */ - void operator=(const ZeroSymMatrixSpace&); - //@} - }; -} // namespace Ipopt -#endif diff --git a/external/ipopt/include/coin/IpoptConfig.h b/external/ipopt/include/coin/IpoptConfig.h deleted file mode 100644 index 8d3ab335b..000000000 --- a/external/ipopt/include/coin/IpoptConfig.h +++ /dev/null @@ -1,22 +0,0 @@ -/* src/Common/config_ipopt.h. Generated by configure. */ -/* src/Common/config_ipopt.h.in. */ - -#ifndef __CONFIG_IPOPT_H__ -#define __CONFIG_IPOPT_H__ - -/* Version number of project */ -#define IPOPT_VERSION "3.12.8" - -/* Major Version number of project */ -#define IPOPT_VERSION_MAJOR 3 - -/* Minor Version number of project */ -#define IPOPT_VERSION_MINOR 12 - -/* Release Version number of project */ -#define IPOPT_VERSION_RELEASE 8 - -/* Define to the C type corresponding to Fortran INTEGER */ -#define FORTRAN_INTEGER_TYPE int - -#endif diff --git a/external/ipopt/include/coin/PardisoLoader.h b/external/ipopt/include/coin/PardisoLoader.h deleted file mode 100644 index 0942521a7..000000000 --- a/external/ipopt/include/coin/PardisoLoader.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2008 GAMS Development and others - All Rights Reserved. - This code is published under the Eclipse Public License. - - $Id: PardisoLoader.h 2204 2013-04-13 13:49:26Z stefan $ - - Author: Stefan Vigerske -*/ - -#ifndef PARDISOLOADER_H_ -#define PARDISOLOADER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - /** Tries to load a dynamically linked library with Pardiso. - * Return a failure if the library cannot be loaded or not all Pardiso symbols are found. - * @param libname The name under which the Pardiso lib can be found, or NULL to use a default name (libpardiso.SHAREDLIBEXT). - * @param msgbuf A buffer where we can store a failure message. Assumed to be NOT NULL! - * @param msglen Length of the message buffer. - * @return Zero on success, nonzero on failure. - */ - int LSL_loadPardisoLib(const char* libname, char* msgbuf, int msglen); - - /** Unloads a loaded Pardiso library. - * @return Zero on success, nonzero on failure. - */ - int LSL_unloadPardisoLib(); - - /** Indicates whether a Pardiso library has been successfully loaded. - * @return Zero if not loaded, nonzero if handle is loaded - */ - int LSL_isPardisoLoaded(); - - /** Returns name of the shared library that should contain Pardiso */ - char* LSL_PardisoLibraryName(); -#ifdef __cplusplus -} -#endif - -#endif /*PARADISOLOADER_H_*/ diff --git a/external/ipopt/include/coin/ThirdParty/arith.h b/external/ipopt/include/coin/ThirdParty/arith.h deleted file mode 100644 index 356d34f5b..000000000 --- a/external/ipopt/include/coin/ThirdParty/arith.h +++ /dev/null @@ -1,8 +0,0 @@ -#define IEEE_8087 -#define Arith_Kind_ASL 1 -#define Long int -#define Intcast (int)(long) -#define Double_Align -#define X64_bit_pointers -#define QNaN0 0x0 -#define QNaN1 0xfff80000 diff --git a/external/ipopt/include/coin/ThirdParty/asl.h b/external/ipopt/include/coin/ThirdParty/asl.h deleted file mode 100644 index ec8a37952..000000000 --- a/external/ipopt/include/coin/ThirdParty/asl.h +++ /dev/null @@ -1,1199 +0,0 @@ -/**************************************************************** -Copyright (C) 1997-2001 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#ifndef ASL_included -#define ASL_included - -#include "arith.h" /* for Long and Double_Align */ -#include "math.h" -#include "stdio1.h" -#include "string.h" - -#ifdef KR_headers -#define Const /* */ -#define VOID /*void*/ -extern char *malloc(), *realloc(); -extern double strtod(); -#else -#define Const const -#define VOID void -#include "stdlib.h" -#endif -#include "errno.h" - -#ifdef __cplusplus -#define Cextern extern "C" -extern "C" { -#else -#define Cextern extern -#endif - -#ifndef Stderr -extern FILE *Stderr; -#endif - -#ifndef real -#define real double -#endif - -#ifndef Long -#define Long long -#endif -#ifndef F2C_INCLUDE -typedef Long fint; -typedef Long ftnlen; -#endif -#ifndef Intcast -#define Intcast (size_t) -#endif - -#ifndef Not_Used -#define Not_Used(x) x = x /* silence non-use warnings */ -#endif - -#define Malloc(x) mymalloc((size_t)(x)) -#define Realloc(x,y) myralloc(x,(size_t)(y)) -#define Sizeof(x) sizeof(x) -/* prior to 20110912, Sizeof(x) was (fint)sizeof(x) */ - - /* Place qsortv declaration ahead of funcadd.h in case Permit_AE_redefs is #defined. */ - extern void qsortv(void*, size_t, size_t, int(*)(const void*,const void*,void*), void*); - -#ifndef FUNCADD_H_INCLUDED -#ifndef Permit_AE_redefs -#define No_AE_redefs -#endif -#include "funcadd.h" -#endif -#include "setjmp.h" - - typedef size_t (*Fwrite)(const void*, size_t, size_t, FILE*); - typedef int (*Add_Indicator)(void*, int, int, int, int, int*, real*, real); - typedef struct {jmp_buf jb;} Jmp_buf; - typedef struct ASL ASL; - typedef struct MPEC_Adjust MPEC_Adjust; - typedef struct Objrep Objrep; - typedef struct Option_Info Option_Info; - typedef struct cgrad cgrad; - typedef struct cplist cplist; - typedef struct derp derp; - typedef struct expr_n expr_n; - typedef struct func_info func_info; - typedef struct linpart linpart; - typedef struct ograd ograd; - typedef struct plterm plterm; - typedef struct relo relo; - - typedef struct -SputInfo { - fint *hcolstarts; - fint *hrownos; - size_t *hcs[2]; - fint *hrn[2]; - ssize_t *ulinc; - ssize_t *ulcopy; - ssize_t *ulinc0; - ssize_t *ulcopy0; - ssize_t *ulcend; - ssize_t nod; - int nobj; /* from sphsetup() */ - int ow; /* from sphsetup() */ - int y; /* from sphsetup() */ - int khinfo; /* mblk size in sphes_setup */ - int khinfob; - int uptri; /* from sphsetup() */ - int *uptolow; - size_t *hcolstartsZ; - } SputInfo; - - typedef union -uirp { - int i; - real *rp; - void *vp; - } uirp; - -#ifdef ASL_big_goff /*{{ for jacval() with nzc >= 2^31 */ - struct -cgrad { - real coef; - cgrad *next; - ssize_t varno; - size_t goff; - }; - - struct -ograd { - real coef; - ograd *next; - ssize_t varno; - }; -typedef ssize_t varno_t; -#else /*}{ less memory */ - struct -cgrad { - real coef; - cgrad *next; - int varno; - int goff; - }; - - struct -ograd { - real coef; - ograd *next; - int varno; - }; -typedef int varno_t; -#endif /*}}*/ - - struct -cplist { - cplist *next; - uirp ca; - real *cfa; - }; - - struct -derp { - derp *next; - uirp a, b, c; - }; - -typedef real efunc_n(expr_n*); - - struct -expr_n { - efunc_n *op; - real v; - }; - - struct -func_info { - func_info *next, *fnext; - Const char *name; - ufunc *funcp; - int ftype; - int nargs; - void *funcinfo; - int findex; /* for fg_write */ - }; - - struct -linpart { - uirp v; - real fac; - }; - - struct -plterm { - int n; /* number of slopes */ - int z; /* bs[z] == slope at 0 */ - real bs[1]; /* slope 1, bkpt 1, slope 2, bkpt 2, ..., slope n */ - }; - - struct -relo { - relo *next, *next2; - derp *D, *Dnext, *Dcond; - }; - - typedef struct -EdRead_ASL { - ASL *asl; - FILE *nl; - void *S; /* Static */ - Long Line; - int lineinc; - int can_end; - char rl_buf[80]; - void (*iadjfcn)(void*, size_t); - void (*dadjfcn)(void*, size_t); - } EdRead_ASL; -#define EdRead EdRead_ASL - - typedef struct ASLhead ASLhead; struct -ASLhead { ASLhead *next, *prev; }; - -#define NFHASH 23 - - typedef struct -Edagpars { - ASLhead h; - /* stuff initialized to nonzero values */ - real hffactor; - int FUNNEL_MIN_; - int maxfwd_; - int need_funcadd_; - int vrefGulp_; - int want_derivs_; - int ihd_limit_; - int solve_code_; - real (*Objval) (ASL*, int nobj, real *X, fint *nerror); - real (*Objval_nomap) (ASL*, int nobj, real *X, fint *nerror); - void (*Objgrd) (ASL*, int nobj, real *X, real *G, fint *nerror); - void (*Objgrd_nomap) (ASL*, int nobj, real *X, real *G, fint *nerror); - void (*Conval) (ASL*, real *X, real *R, fint *nerror); - void (*Jacval) (ASL*, real *X, real *J, fint *nerror); - real (*Conival) (ASL*, int ncon, real *X, fint *nerror); - real (*Conival_nomap) (ASL*, int ncon, real *X, fint *nerror); - void (*Congrd) (ASL*, int nc, real *X, real *G, fint *nerror); - void (*Congrd_nomap) (ASL*, int nc, real *X, real *G, fint *nerror); - void (*Hvcomp) (ASL*, real *hv, real *p, int no, real *ow, real *y); - void (*Hvcomp_nomap) (ASL*, real *hv, real *p, int no, real *ow, real *y); - void (*Hvcompd) (ASL*, real *hv, real *p, int co); - varno_t (*Hvcomps) (ASL*, real *hv, real *p, int co, varno_t nz, varno_t *z); - void (*Hvinit) (ASL*, int hid_limit, int nobj, real *ow, real *y); - void (*Hvinit_nomap) (ASL*, int hid_limit, int nobj, real *ow, real *y); - void (*Hesset) (ASL*, int flags, int no, int nno, int nc, int nnc); - int (*Lconval) (ASL*, int ncon, real *X, fint *nerror); - void (*Xknown) (ASL*, real*, fint*); - void (*Duthes) (ASL*, real *H, int nobj, real *ow, real *y); - void (*Duthes_nomap) (ASL*, real *H, int nobj, real *ow, real *y); - void (*Fulhes) (ASL*, real *H, fint LH, int no, real *ow, real *y); - void (*Fulhes_nomap) (ASL*, real *H, fint LH, int no, real *ow, real *y); - void (*Sphes) (ASL*, SputInfo**, real *H, int nobj, real *ow, real *y); - void (*Sphes_nomap) (ASL*, SputInfo**, real *H, int nobj, real *ow, real *y); - fint (*Sphset) (ASL*, SputInfo**, int nobj, int ow, int y, int uptri); - fint (*Sphset_nomap) (ASL*, SputInfo**, int nobj, int ow, int y, int uptri); - } Edagpars; - - extern Edagpars edagpars_ASL; - -#define objval(np,x,ne) (*((ASL*)asl)->p.Objval)((ASL*)asl,np,x,ne) -#define objgrd(np,x,g,ne) (*((ASL*)asl)->p.Objgrd)((ASL*)asl,np,x,g,ne) -#define conval(x,r,ne) (*((ASL*)asl)->p.Conval)((ASL*)asl,x,r,ne) -#define jacval(x,j,ne) (*((ASL*)asl)->p.Jacval)((ASL*)asl,x,j,ne) -#define conival(i,x,ne) (*((ASL*)asl)->p.Conival)((ASL*)asl,i,x,ne) -#define congrd(i,x,g,ne) (*((ASL*)asl)->p.Congrd)((ASL*)asl,i,x,g,ne) -#define hvcomp(hv,P,no,ow,y) (*((ASL*)asl)->p.Hvcomp)((ASL*)asl,hv,P,no,ow,y) -#define hvcompd(hv,P,co) (*((ASL*)asl)->p.Hvcompd)((ASL*)asl,hv,P,co) -#define hvcomps(hv,P,co,nz,z) (*((ASL*)asl)->p.Hvcomps)((ASL*)asl,hv,P,co,nz,z) -#define hvinit(no,ow,y) (*((ASL*)asl)->p.Hvinit)((ASL*)asl,ihd_limit,no,ow,y) -#define hesset(f,o,n,c,nc) (*((ASL*)asl)->p.Hesset)((ASL*)asl,f,o,n,c,nc) -#define duthes(h,n,ow,y) (*((ASL*)asl)->p.Duthes)((ASL*)asl,h,n,ow,y) -#define fullhes(h,lh,n,ow,y) (*((ASL*)asl)->p.Fulhes)((ASL*)asl,h,lh,n,ow,y) -#define lconval(i,x,ne) (*((ASL*)asl)->p.Lconval)((ASL*)asl,i,x,ne) -#define sphes(h,no,ow,y) (*((ASL*)asl)->p.Sphes)( (ASL*)asl,0,h,no,ow,y) -#define sphsetup(no,ow,y,b) (*((ASL*)asl)->p.Sphset)((ASL*)asl,0,no,ow,y,b) -#define xknown(x) (*((ASL*)asl)->p.Xknown)((ASL*)asl,x,0) -#define xknowne(x,ne) (*((ASL*)asl)->p.Xknown)((ASL*)asl,x,ne) -#define xunknown() (asl->i.x_known = 0) - -#define FUNNEL_MIN asl->p.FUNNEL_MIN_ -#define ihd_limit asl->p.ihd_limit_ -#define maxfwd asl->p.maxfwd_ -#define need_funcadd asl->p.need_funcadd_ -#define solve_code asl->p.solve_code_ -#define solve_result_num asl->p.solve_code_ -#define vrefGulp asl->p.vrefGulp_ -#define want_derivs asl->p.want_derivs_ - - typedef struct -SufDesc { /* suffix description */ - char *sufname; /* suffix name */ - char *table; /* for return to AMPL, suffix_table value */ - int kind; - int nextra; /* extra entries to allocate in u.i or u.r */ - struct { /* was union, but this made debugging harder */ - int *i; - real *r; - } u; - struct SufDesc *next; - /* The number of entries in u.i or u.r is */ - /* (&asl->i.n_var_)[kind & ASL_Sufkind_mask] . */ - } SufDesc; - - enum { /* kind bits for SufDesc */ - ASL_Sufkind_var = 0, - ASL_Sufkind_con = 1, - ASL_Sufkind_obj = 2, - ASL_Sufkind_prob = 3, - ASL_Sufkind_mask = 3, /* mask for getting one of the above */ - /* values from SufDesc.kind */ - ASL_Sufkind_real = 4, /* use SufDesc.u.r rather than .i */ - ASL_Sufkind_iodcl = 8, /* tell AMPL to make this an INOUT suffix */ - ASL_Sufkind_output = 16,/* return this suffix to AMPL */ - ASL_Sufkind_input = 32, /* input values were received from AMPL */ - ASL_Sufkind_outonly = 64/* reject as an input value */ - }; - - typedef struct -SufDecl { /* Pass array of SufDecl's to suf_declare(). */ - char *name; - char *table; - int kind; - int nextra; - } SufDecl; - - typedef struct Exitcall Exitcall; struct -Exitcall { - Exitcall *prev; - Exitfunc *ef; - void *v; - }; - - typedef struct DerivErrInfo DerivErrInfo; - - typedef struct -Edaginfo { - int ASLtype; - /* stuff initialized to zero values */ - int amplflag_; - int need_nl_; - int nlmode; - func_info **funcs_, *funcsfirst_, *funcslast_; - int (*xscanf_)(EdRead*, const char*, ...); - - func_info *fhash_[NFHASH]; - - real *adjoints_; /* partials of result w.r.t. current oper. */ - real *adjoints_nv1_; /* internal use: start of portion to zero */ - real *LUrhs_, /* constraint lower (and, if Urhsx == 0, */ - /* upper) bounds */ - *Urhsx_, /* constraint upper bounds (if nonzero) */ - *X0_, /* initial guess (if nonzero) */ - *LUv_, /* variable lower (and, if Uvx == 0, upper) */ - /* bounds */ - *Uvx_, /* variable upper bounds (if nonzero) */ - *Lastx_, /* internal use: copy of X */ - *pi0_; /* dual initial guess */ - - char *objtype_; /* object type array: 0 == min, 1 == max */ - char *havex0_; /* if nonzero, havex0_[i] != 0 ==> */ - /* X0_[i] was specified: this lets you */ - /* tell explicit 0's from default 0's */ - char *havepi0_; /* analogous to havex0_, but for dual values */ - real *A_vals_; /* If nonzero, store constant Jacobian values */ - /* (possibly 0 when nonlinearities are involved) */ - /* in A_vals, A_rownos, and A_colstarts, */ - /* rather than in Cgrad_. */ - int *A_rownos_, /* row numbers corresponding to A_vals_ */ - *A_colstarts_; /* offsets of columns in A_vals_ */ - size_t *A_colstartsZ_; /* for huge problems -- 2^31 or more nonzeros */ - - cgrad **Cgrad_; /* constraint gradient info. (linear part) */ - ograd **Ograd_; /* objective gradient info. (linear part) */ - cgrad **Cgrad0; /* unmapped */ - - int Fortran_; /* adjustment to A_rownos, A_colstarts, */ - /* ccind1, and ccind2 */ - int amax_; /* number of adjoint cells */ - - /* stuff for common expressions (from "defined" vars) */ - int c_vars_; - int comb_; - int combc_; - int comc1_; - int comc_; - int como1_; - int como_; - - int lnc_; /* no. of linear network constraints */ - int nbv_; /* no. of linear binary variables */ - int niv_; /* no. of linear non-binary integer variables */ - int nlc_; /* total no. of nonlinear constraints */ - int n_eqn_; /* number of equality constraints or -1 */ - /* if unknown (ampl prior to 19970627) */ - int n_cc_; /* total complementarity conditions */ - int nlcc_; /* nonlinear complementarity conditions */ - int ndcc_; /* number of complementarities involving */ - /* double inequalities (for ASL_cc_simplify) */ - int nzlb_; /* number of complemented variables with a */ - /* nonzero lower bound (for ASL_cc_simplify) */ - int nlnc_; /* no. of nonlinear network constraints */ - int nlo_; /* no. of nonlinear objectives */ - int nlvb_; /* no. of nonlinear variables in both */ - /* constraints and objectives */ - int nlvc_; /* no. of nonlinear variables in constraints */ - int nlvo_; /* no. of nonlinear variables in objectives */ - /* nlvc_ and nlvo_ include nlvb_ */ - int nlvbi_; /* integer nonlinear variables in both */ - /* constraints and objectives */ - int nlvci_; /* integer nonlinear vars just in constraints */ - int nlvoi_; /* integer nonlinear vars just in objectives */ - int nwv_; /* no. of (linear) network variables (arcs) */ - int nzc_; /* no. of nonzeros in constraints' Jacobian */ - int nzo_; /* no. of nonzeros in all objective gradients */ - int n_var_; /* total no. of variables */ - int n_con_; /* total no. of constraints */ - int n_obj_; /* total no. of objectives */ - int n_prob; /* 1 (for use with SufDesc): SufDesc.u has */ - /* (&asl->i.n_var_)[SufDesc.kind & ASL_Sufkind_mask] entries */ - int n_lcon_; /* no. of logical constraints */ - int flags; /* 1 = want output suffixes */ - int n_conjac_[2]; /* Conval and Jacval operate on constraint i */ - /* for n_conjac_[0] <= i < n_conjac_[1]. */ - /* Initialized by jac0dim to 0 and n_con. */ - /* The .nl reader may adjust these values when */ - /* processing ASL_cc_simplify or ASL_obj_replace. */ - - - /* internal stuff */ - - int nclcon_; /* n_con + n_lcon */ - int ncom0_; - int ncom1_; - int nderps_; - int nfunc_; - int o_vars_; - int want_deriv_; - int x0kind_; - int rflags; /* flags given to the .nl reader */ - size_t nzjac_; - size_t x0len_; - size_t nZc_; /* no. of nonzeros in constraints' Jacobian */ - size_t nZo_; /* no. of nonzeros in all objective gradients */ - - char *filename_; /* stub + current extension */ - char *stub_end_; /* copy new extension (starting with ".") */ - /* here to adjust filename */ - void *archan_; /* channel for reading from AMPL */ - void *awchan_; /* channel from writing to AMPL */ - int binary_nl_; /* 0 = ASCII format, 1 = binary */ - int return_nofile_; /* 0 ==> jacdim0 should exit if stub.nl */ - /* does not exist; 1 ==> return 0 */ - int plterms_; /* no. of piecewise-linear terms */ - int maxrownamelen_; /* length of longest constraint name */ - /* (if stub.row exists) */ - int maxcolnamelen_; /* length of longest constraint name */ - /* (if stub.col exists) */ - int co_index_; /* set this to (constraint number - 1) or */ - /* -(objective number) to identify the */ - /* constraint or objective being evaluated */ - /* (used in report_where()) */ - int cv_index_; /* used internally */ - Jmp_buf *err_jmp_; /* If nonzero when an error is detected, */ - /* longjmp here (without printing an error */ - /* message). */ - Jmp_buf *err_jmp1_; /* If nonzero when an error is detected */ - /* (and err_jmp_ == 0), longjmp here after */ - /* printing an error message. */ - fint ampl_options_[10]; - fint obj_no_; /* objective number (for write_sol and */ - /* read_sol) */ - int nranges_; /* no. of ranges (constraints with */ - /* negInfinity < lhs < rhs < Infinity) */ - int want_xpi0_; /* & 1 ==> allocate X0_ if an */ - /* initial guess is available */ - /* & 2 ==> allocate pi0_ if a dual */ - /* initial guess is available */ - - /* starting subscripts for cexp1's: request by */ - /* assigning these pointers before invoking edagread */ - - int *c_cexp1st_; /* cexp1 starts for constraints */ - int *o_cexp1st_; /* cexp1 starts for objectives */ - - /* for complementarity constraints */ - - int *cvar_; /* cvar[i] > 0 means constraint i complements */ - /* variable cvar[i] - 1 */ - - int *ccind1, *ccind2; /* populated when ASL_cc_simplify is */ - /* "on" in the flags argument to the .nl reader */ - - unsigned size_expr_n_; /* size for struct expr_n, for nlc */ - - /* extra info for write_sol */ - real ampl_vbtol_; - - /* relocated adjoints for common expressions */ - /* (used by nlc; request by allocating) */ - - int **zaC_; /* for common expressions */ - int **zac_; /* for constraints */ - int **zao_; /* for objectives */ - - /* for nlc */ - - int skip_int_derivs_; - - /* for suffixes */ - - int nsuffixes; - int nsufext[4]; - int nsuff[4]; - SufDesc *suffixes[4]; - - /* for sparse gradients */ - - int **zerograds_; - int congrd_mode; /* How to treat arg G to Congrd: */ - /* 0 == expand to n_var vector (default) */ - /* 1 == compact storage in G */ - /* 2 == use goff fields of struct cgrad */ - int x_known; /* used by xknown(), xunknown() */ - Long xknown_ignore; /* for debugging: ignore xknown */ - size_t zap_J; /* used by dense_j */ - int nxval; /* used by conival and objval */ - int nlvog; /* objgrd(np,x,g,ne) sets g[i] = 0 */ - /* if the objective does not depend on x[i] */ - /* and i < nlvog (or i < max(c_vars, o_vars) */ - /* if nlvog is left at 0); nlvog must be set */ - /* before the .nl reader is called. */ - int *ncxval; /* for conival */ - int *noxval; /* for objval */ - SputInfo *sputinfo_; /* used by sputhes() */ - - /* for ASL_free */ - void **Mbnext, **Mblast, *Mb; - /* for mem */ - char *memNext, *memLast; - - /* for user-defined functions */ - AmplExports *ae; - - /* for con_name(), obj_name(), var_name() */ - - char **connames; - char **lconnames; - char **objnames; - char **varnames; - int vcochecked; - - /* for possible user-specific use */ - void *uinfo; - - /* for reading alternate binary formats */ - void (*iadjfcn)(void*, size_t); - void (*dadjfcn)(void*, size_t); - const char *opfmt; /* format of opcodes */ - - /* for scaling */ - real *cscale; /* constraints */ - real *vscale; /* variables */ - real *lscale; /* Lagrange-multiplier scale */ - - /* for at_reset() */ - - Exitcall *arlast; - Exitcall *arnext; - Exitcall *arprev; - - /* for suf_sos() */ - - SufDesc *csd; - SufDesc *rsd; - int n_var0; /* number of variables before suf_sos() */ - int n_con0; /* number of constraints before suf_sos() */ - int n_var1; /* index of next variable to be added */ - int n_con1; /* index of next constraint to be added */ - int *vmap; /* for mapping variables, length n_var */ - int *cmap; /* for mapping constraints, length n_con */ - int *vzap; /* for zeroing primal variables in eliminated suf_sos */ - /* constraints: vzmap[i] for 1 <= i <= vzmap[0] */ - int *czap; /* for zeroing dual variables of eliminated suf_sos */ - /* constraints: czap[i] for 1 <= i <= czmap[0] */ - int *vminv; /* inverse of vmap; allocated on demand */ - - /* for modifying objectives */ - Objrep **Or; - real *orscratch; /* scratch (if needed) */ - - /* for simplifying complementarities */ - MPEC_Adjust *mpa; - - /* for derivative errors */ - DerivErrInfo *Derrs, *Derrs0; - - /* bounds and solution filenames */ - char *boundsfile; - char *solfile; - } Edaginfo; - - struct -ASL { - Edagpars p; - Edaginfo i; - }; - - typedef struct -NewVCO { - int nnv; /* number of new variables */ - int nnc; /* number of new constraints */ - int nno; /* number of new objectives */ - ograd **newc; /* new constraint nonzeros */ - ograd **newo; /* new objective nonzeros */ - real *LUnv; /* nnv variable lower bounds or, if Unv is null, */ - /* nnv (lower,upper) bound pairs */ - real *Unv; /* null or nnv variable upper bounds */ - real *LUnc; /* nnc constraint lower bounds or, if Unc is null, */ - /* nnc (lower,upper) bound pairs */ - real *Unc; /* null or nnc constraint upper bounds */ - real *oc; /* null or nno objective constants */ - char *ot; /* objective types (1 = max, 0 = min) */ - /* taken to be all zeros (min) if null */ - real *x0; /* null or nnv primal initial guesses */ - real *d0; /* null or nnc dual initial guesses */ - } NewVCO; - - struct -TMInfo { - union { - TMInfo *prev; - double align; - } u; - }; - -#define A_colstarts asl->i.A_colstarts_ -#define A_colstartsZ asl->i.A_colstartsZ_ -#define A_rownos asl->i.A_rownos_ -#define A_vals asl->i.A_vals_ -#define Cgrad asl->i.Cgrad_ -#define CgradZ asl->i.CgradZ_ -#define Fortran asl->i.Fortran_ -#define LUrhs asl->i.LUrhs_ -#define LUv asl->i.LUv_ -#define Lastx asl->i.Lastx_ -#define Ograd asl->i.Ograd_ -#define Urhsx asl->i.Urhsx_ -#define Uvx asl->i.Uvx_ -#define X0 asl->i.X0_ -#define adjoints asl->i.adjoints_ -#define adjoints_nv1 asl->i.adjoints_nv1_ -#define amax asl->i.amax_ -#define ampl_options asl->i.ampl_options_ -#define ampl_vbtol asl->i.ampl_vbtol_ -#define amplflag asl->i.amplflag_ -#define archan asl->i.archan_ -#define awchan asl->i.awchan_ -#define binary_nl asl->i.binary_nl_ -#define c_cexp1st asl->i.c_cexp1st_ -#define c_vars asl->i.c_vars_ -#define co_index asl->i.co_index_ -#define comb asl->i.comb_ -#define combc asl->i.combc_ -#define comc asl->i.comc_ -#define comc1 asl->i.comc1_ -#define como asl->i.como_ -#define como1 asl->i.como1_ -#define cv_index asl->i.cv_index_ -#define cvar asl->i.cvar_ -#define err_jmp asl->i.err_jmp_ -#define err_jmp1 asl->i.err_jmp1_ -#define fhash asl->i.fhash_ -#define filename asl->i.filename_ -#define funcs asl->i.funcs_ -#define funcsfirst asl->i.funcsfirst_ -#define funcslast asl->i.funcslast_ -#define havepi0 asl->i.havepi0_ -#define havex0 asl->i.havex0_ -#define lnc asl->i.lnc_ -#define maxcolnamelen asl->i.maxcolnamelen_ -#define maxrownamelen asl->i.maxrownamelen_ -#define nZc asl->i.nZc_ -#define nZo asl->i.nZo_ -#define n_cc asl->i.n_cc_ -#define n_con asl->i.n_con_ -#define n_conjac asl->i.n_conjac_ -#define n_eqn asl->i.n_eqn_ -#define n_lcon asl->i.n_lcon_ -#define n_obj asl->i.n_obj_ -#define n_var asl->i.n_var_ -#define nbv asl->i.nbv_ -#define nclcon asl->i.nclcon_ -#define ncom0 asl->i.ncom0_ -#define ncom1 asl->i.ncom1_ -#define nderps asl->i.nderps_ -#define need_nl asl->i.need_nl_ -#define nfunc asl->i.nfunc_ -#define niv asl->i.niv_ -#define nlc asl->i.nlc_ -#define nlcc asl->i.nlcc_ -#define nlnc asl->i.nlnc_ -#define nlo asl->i.nlo_ -#define nlogv asl->i.nbv_ /* nbv used to be called nlogv */ -#define nlvb asl->i.nlvb_ -#define nlvbi asl->i.nlvbi_ -#define nlvc asl->i.nlvc_ -#define nlvci asl->i.nlvci_ -#define nlvo asl->i.nlvo_ -#define nlvoi asl->i.nlvoi_ -#define nranges asl->i.nranges_ -#define nwv asl->i.nwv_ -#define nzc asl->i.nzc_ -#define nzjac asl->i.nzjac_ -#define nzo asl->i.nzo_ -#define o_cexp1st asl->i.o_cexp1st_ -#define o_vars asl->i.o_vars_ -#define obj_no asl->i.obj_no_ -#define objtype asl->i.objtype_ -#define pi0 asl->i.pi0_ -#define plterms asl->i.plterms_ -#define return_nofile asl->i.return_nofile_ -#define size_expr_n asl->i.size_expr_n_ -#define skip_int_derivs asl->i.skip_int_derivs_ -#define sputinfo asl->i.sputinfo_ -#define stub_end asl->i.stub_end_ -#define want_deriv asl->i.want_deriv_ -#define want_xpi0 asl->i.want_xpi0_ -#define x0kind asl->i.x0kind_ -#define x0len asl->i.x0len_ -#define xscanf asl->i.xscanf_ -#define zaC asl->i.zaC_ -#define zac asl->i.zac_ -#define zao asl->i.zao_ -#define zerograds asl->i.zerograds_ - -#define M1alloc(n) M1alloc_ASL(&asl->i,n) -#define M1free M1free_ASL -#define M1record(n) M1record_ASL(&asl->i,n) -#define M1zapalloc(n) M1zapalloc_ASL(&asl->i,n) -#define Mach Mach_ASL -#define ascanf ascanf_ASL -#define badline badline_ASL -#define badread badread_ASL -#define bscanf bscanf_ASL -#define derprop derprop_ASL -#define dynlink dynlink_ASL -#define edag_peek edag_peek_ASL -#define edagread_one edag_one_ASL -#define fpecatch fpecatch_ASL -#define fpe_jmpbuf fpe_jmpbuf_ASL -#define func_add func_add_ASL -#define func_lookup func_lookup_ASL -#define g_fmt g_fmt_ASL -#define g_fmtp g_fmtp_ASL -#define g_fmtop g_fmtop_ASL -#define g_fmt_E gfmt_E_ASL -#define g_fmt_decpt gfmt_decpt_ASL -#define hscanf hscanf_ASL -#define htcl htcl_ASL -#define mem(n) mem_ASL((ASL*)asl,n) -#define mymalloc mymalloc_ASL -#define mypow mypow_ASL -#define myralloc myralloc_ASL -#define obj_prec obj_prec_ASL -#define optype op_type_ASL -#define optypeb op_typeb_ASL -#define pr_unknown pr_unknown_ASL -#define read_line read_line_ASL -#define report_where report_where_ASL -#define scream scream_ASL -#define what_prog what_prog_ASL - - extern real Infinity, edagread_one, negInfinity; - extern char g_fmt_E, *progname; - extern int g_fmt_decpt; - extern ASL *cur_ASL; - -enum { /* mode bits for ASLtype */ - ASL_read_f = 1, - ASL_read_fg = 2, - ASL_read_fgh = 3, - ASL_read_pfg = 4, - ASL_read_pfgh = 5 - }; - -enum { /* bits for x0kind */ - ASL_have_conval = 1, - ASL_have_objcom = 2, - ASL_first_x = 4, - ASL_have_funnel = 8, /* in con[12]ival */ - ASL_need_funnel = 16, /* in pshvprod */ - ASL_have_concom = 32 - }; - -enum ASL_reader_flag_bits { /* bits in flags arg */ - /* values just relevant to pfg_read and pfgh_read: */ - /* If you do not need the sparsity pattern, */ - /* you can omit linear coefficients of zero. */ - ASL_J_zerodrop = 1, /* Omit 0 linear terms in constraint derivs. */ - ASL_G_zerodrop = 2, /* Omit 0 linear terms in objective derivs. */ - ASL_GJ_zerodrop = 3, /* Omit both kinds of zero linear terms. */ - ASL_findOgroups = 4, /* Find objective group structure. */ - ASL_findCgroups = 8, /* Find constraint group structure. */ - ASL_findgroups = 12, /* Find both group structures; you want this */ - /* unless you're a solver like LANCELOT that */ - /* deals explicitly with group structure. */ - ASL_find_c_class = 32, /* Find c_class and c_class_max: see nlp.h */ - ASL_find_o_class = 64, /* Find o_class and o_class_max: or nlp2.h */ - ASL_find_co_class = 96, /* Find all four */ - - /* applicable to all .nl file readers: */ - ASL_return_read_err = 16, - ASL_keep_all_suffixes = 0x80, - ASL_allow_CLP = 0x1000, /* permit CLP extensions */ - ASL_find_default_no_groups = 0x2000, /* Assume ASL_findgroups */ - /* when this bit is off. */ - /* When ASL_find_default_no_groups is on, pfg_read and pfgh_read */ - /* only honor explicit specification of the ASL_findgroups bits. */ - - /* Stuff for fg_wread: */ - - ASL_omit_all_suffixes = 0x100, - ASL_keep_derivs = 0x200, - ASL_allow_missing_funcs = 0x400, - ASL_forbid_missing_funcs = 0x800, - - /* problem adjustments */ - - ASL_no_linear_cc_rhs_adjust = 0x4000, /* Omit constant term adjustment */ - /* of linear complementarities. */ - - ASL_cc_simplify = 0x8000, /* Provide arrays ccind1 and ccind2 and */ - /* modify complementarities (possibly */ - /* increasing n_cc) so the complementarity */ - /* constraints have the form */ - /* _svar[i] >= 0 complements _svar[j] >= 0 */ - /* for i = ccind1[k] - Fortran */ - /* and j = ccind2[k] - Fortran, */ - /* 0 <= k < n_cc. */ - - ASL_obj_replace_ineq = 0x10000, /* Whether to replace an objective of the */ - /* form minimize or maximize const*var and */ - /* a corresponding constraint of the form */ - /* var relop expr with const*expr, where */ - /* relop is either >= or <=, depending */ - /* on the sense of optimization, and var */ - /* does not appear elsewhere. */ - - ASL_obj_replace_eq = 0x20000, /* Similar to ASL_obj_replace, but where */ - /* relop is == . */ - - ASL_rowwise_jac = 0x40000, /* Whether Jacobian nonzeros should be stored */ - /* row-wise rather than column-wise, in which */ - /* case the A_colstarts array provides offsets */ - /* of rows rather than columns. */ - - ASL_want_A_vals = 0x80000, /* Allocate and use A_vals (if NULL), allowing */ - /* space needed for ASL_cc_simplify. */ - - ASL_sep_U_arrays = 0x100000, /* Allocate and use Uvx and Urhsx */ - - ASL_allow_Z = 0x200000, /* Accept problems with nZc >= 2^31, populating */ - /* A_colstarsZ rather than A_colstarts. */ - ASL_use_Z = 0x400000, /* Use A_colstartsZ rather than A_colstarts, */ - /* regardless of problem size. */ - ASL_opified = 0x800000 /* internal use: qp_opify called */ - }; - -enum ASL_reader_error_codes { - /* return codes from .nl readers with flag ASL_ret_read_err */ - ASL_readerr_none = 0, /* all went well */ - ASL_readerr_nofile = 1, /* cannot open .nl file */ - ASL_readerr_nonlin = 2, /* model involves nonlinearities (ed0read) */ - ASL_readerr_argerr = 3, /* user-defined function with bad args */ - ASL_readerr_unavail= 4, /* user-defined function not available */ - ASL_readerr_corrupt= 5, /* corrupt .nl file */ - ASL_readerr_bug = 6, /* bug in .nl reader */ - ASL_readerr_CLP = 7 /* solver cannot handle CLP extensions */ - }; - -enum ASL_suf_sos_flags { /* bits in flags parameter of suf_sos() */ - ASL_suf_sos_explict_free = 1, /* caller will explicitly free */ - /* returned arrays */ - ASL_suf_sos_ignore_sosno = 2, /* ignore .sosno */ - ASL_suf_sos_ignore_amplsos = 4 /* ignore SOS information from */ - /* transformations of piecewise- */ - /* linear terms (etc.) by AMPL */ - }; - -enum ASL_write_flags { - ASL_write_ASCII = 1, - ASL_write_CR = 2 - }; - -enum ASL_writer_error_codes { - ASL_writeerr_openfail = 1, - ASL_writeerr_badrops = 2, - ASL_writeerr_badcexp1st = 3, - ASL_writeerr_badNewVCO = 4 - }; - -#define f_OPNUM f_OPNUM_ASL -#undef basename -#define basename basename_ASL -#ifndef Sig_ret_type -#define Sig_ret_type void -#endif - - typedef struct -QPinfo { - int nc; /* number of nonempty columns */ - int nz; /* number of nonzeros */ - int *colno; /* column numbers of nonempty columns */ - size_t *colbeg; /* nonzeros for column colno[i]: (rowno[j], delsq[j]) */ - int *rowno; /* for colbeg[i] <= j < colbeg[i+1], except that values */ - real *delsq; /* in colno, colbeg, and rowno are incremented by Fortran */ - } QPinfo; - - extern ASL *ASL_alloc(int); - extern void ASL_free(ASL**); - extern long ASLdate_ASL; - extern void Del_mblk_ASL(ASL*, int, void*); - extern EdRead *EdReadInit_ASL(EdRead*, ASL*, FILE*, void*); - extern void LUcopy_ASL(int, real*, real*, real*); - extern void *M1alloc_ASL(Edaginfo*, size_t); - extern void M1free(Edaginfo*, void**, void**); - extern void **M1record_ASL(Edaginfo*, void*); - extern void *M1zapalloc_ASL(Edaginfo*, size_t); - extern void MAIN__(VOID); - extern void Mach_ASL(VOID); - extern void No_derivs_ASL(const char*); - extern int Sprintf(char*, const char*, ...); - extern void Stderr_init_ASL(void); - extern void Suf_read_ASL(EdRead*, int); - extern void adjust_zerograds_ASL(ASL*, int); - extern int already_ASL(const char*); - extern int ascanf(EdRead*, const char*, ...); - extern void auxinfo_ASL(AmplExports*); - extern void *b_search_ASL(void *ow, int owsize, int n, char **sp, char **peq); - extern void badasl_ASL(ASL*,int,const char*); - extern void badline(EdRead*); - extern void badread(EdRead*); - extern char *basename(const char*); - extern int bscanf(EdRead*, const char*, ...); - extern char *con_name_ASL(ASL*,int); - extern char *con_name_nomap_ASL(ASL*,int,int*); - extern int conadj_ASL(ASL*,int*,int); - extern void congrd_(fint *N, fint *I, real *X, real *G, fint *nerror); - extern real cnival_(fint *N, fint *I, real *X, fint *nerror); - extern void colstart_inc_ASL(ASL*); - extern void conscale_ASL(ASL*, int, real, fint*); - extern void conval_(fint *M, fint *N, real *X, real *F, fint *nerror); - extern void delprb_(VOID); - extern void dense_j_ASL(ASL*); - extern void densej_(VOID); - extern void deriv_errchk_ASL(ASL*, fint*, int coi, int n); - extern void deriv_errclear_ASL(Edaginfo*); - extern void derprop(derp *); - extern char *dtoa(double, int, int, int*, int*, char **); - extern ufunc *dynlink_ASL(const char*); - extern int edag_peek(EdRead*); - extern void equ_adjust_ASL(ASL*, int*, int*); - extern void exit_ASL(EdRead*,int); - extern real f_OPNUM(expr_n*); - extern int f_read_ASL(ASL*, FILE*, int); - extern int fg_read_ASL(ASL*, FILE*, int); - extern int fg_wread_ASL(ASL*, FILE*, int); - extern int fgh_read_ASL(ASL*, FILE*, int); - extern int fg_write_ASL(ASL*, const char*, NewVCO*, int); - extern void fintrouble_ASL(ASL*, func_info*, const char*, TMInfo*); - extern void flagsave_ASL(ASL*, int); - extern void freedtoa(char*); - extern func_info *func_lookup(ASL*, const char*, int add); - extern void func_add(ASL*); - extern int g_fmt(char*, double); - extern int g_fmtop(char*, double); - extern int g_fmtp(char*, double, int); - extern void gen_rownos_ASL(ASL*); - extern ASL *get_cur_ASL(VOID); - extern int *get_vcmap_ASL(ASL*, int); - extern int *get_vminv_ASL(ASL*); - extern char *getenv_ASL(const char*); - extern void goff_comp_ASL(ASL*); - extern int hscanf(EdRead*, const char*, ...); - extern int htcl_ASL(unsigned int); - extern void hvcomp_(real *hv, real *p, fint *nobj, real *ow, real *y); - extern void hvinit_(fint *nobj, real *ow, real *y); - extern int indicator_constrs_ASL(ASL*, void*, Add_Indicator, int errinfo[2]); - extern void intcatch_ASL(ASL*, void (*)(int,void*), void*); - extern void introuble_ASL(ASL*, const char *who, real a, int jv); - extern void introuble2_ASL(ASL*, const char *who, real a, real b, int jv); - extern FILE *jac0dim_ASL(ASL*, const char *stub, ftnlen stub_len); - extern int jac1dim_ASL(ASL*, const char *stub, fint *M, fint *N, fint *NO, - fint *NZ, fint *MXROW, fint *MXCOL, ftnlen stub_len); - extern int jac2dim_ASL (ASL*, const char *stub, fint *M, fint *N, fint *NO, - fint *NZ, fint *MXROW, fint *MXCOL, ftnlen stub_len); - extern FILE *jac_dim_ASL(ASL*, const char *stub, fint *M, fint *N, fint *NO, - fint *NZ, fint *MXROW, fint *MXCOL, ftnlen stub_len); - extern int jacdim_(const char *stub, fint *M, fint *N, fint *NO, fint *NZ, - fint *MXROW, fint *MXCOL, ftnlen stub_len); - extern void jacinc_(fint *M, fint *N, fint *NZ, - fint *JP, short *JI, real *X, real *L, real *U, - real *Lrhs, real *Urhs, real *Inf); - extern int jacpdim_ASL(ASL*, const char *stub, fint *M, fint *N, fint *NO, - fint *NZ, fint *MXROW, fint *MXCOL, ftnlen stub_len); - extern void jacval_(fint *M, fint *N, fint *NZ, real *X, - real *JAC, fint *nerror); - extern Sig_ret_type fpecatch(int); - extern jmp_buf fpe_jmpbuf_ASL; - extern int ka_read_ASL(ASL *, EdRead *, int, int**, size_t**); - extern void lagscale_ASL(ASL*, real, fint*); - extern char *lcon_name_ASL(ASL*,int); - extern void mainexit_ASL(int); - extern void *mem_ASL(ASL*, unsigned int); - extern int mip_pri_ASL(ASL*,int**startp,int**nump,int**prip,fint pmax); - extern void mnnzchk_ASL(ASL*asl,fint*M,fint*N,size_t NZ,const char*who); - extern void mpec_adjust_ASL(ASL*); - extern void mpec_auxvars_ASL(ASL*, real *c, real *x); - extern fint mqpcheck_ASL(ASL*, int co, fint **rowqp, fint **colqp, real **delsqp); - extern ssize_t mqpcheckZ_ASL(ASL*, int co, fint **rowqp, size_t **colqp, real **delsqp); - extern ssize_t mqpcheckv_ASL(ASL*, int co, QPinfo **QPIp, void **vp); - extern void mqpcheckv_free_ASL(ASL*, void **vp); - extern void *mymalloc(size_t); - extern real mypow(real,real); - extern void *myralloc(void *, size_t); - extern void *new_mblk_ASL(ASL*, int k); - extern int nl_obj_ASL(ASL*,int); - extern fint nqpcheck_ASL(ASL*, int co, fint **rowqp, fint **colqp, real **delsqp); - extern ssize_t nqpcheckZ_ASL(ASL*, int co, fint **rowqp, size_t **colqp, real **delsqp); - extern char *obj_name_ASL(ASL*,int); - extern int obj_prec(VOID); - extern void obj_adj_ASL(ASL*); - extern void obj_adj_xy_ASL(ASL *asl, real *x, real *x0, real *y); - extern real objconst_ASL(ASL*,int); - extern void objgrd_(fint *N, real *X, fint *NOBJ, real *G, fint *nerror); - extern real objval_(fint *N, real *X, fint *NOBJ, fint *nerror); - extern char optype[], optypeb[]; - extern int pfg_read_ASL(ASL*, FILE*, int flags); - extern int pfgh_read_ASL(ASL*, FILE*, int flags); - extern char *pr_unknown(FILE*, char*); - extern int prob_adj_ASL(ASL*); - extern void qp_opify_ASL(ASL*); - extern int qp_read_ASL(ASL*, FILE*, int); - extern fint qpcheck_ASL(ASL*, fint **rowqp, fint **colqp, real **delsqp); - extern ssize_t qpcheckZ_ASL(ASL*, fint **rowqp, size_t **colqp, real **delsqp); - extern char *read_line(EdRead*); - extern char *read_sol_ASL(ASL*, real**xp, real **yp); - extern void report_where(ASL*); - extern void scream(EdRead*, int rc, const char *fmt, ...); - extern ASL *set_cur_ASL(ASL*); /* returns previous value */ - extern real set_randseed_ASL(real nseed); /* returns new seed, usually nseed, but */ - /* automaticaally chosen if nseed == 0. */ - extern void show_funcs_ASL(ASL*); - extern void sigcatch_ASL(VOID); - extern void* sos_add_ASL(ASL*, FILE*, int); - extern int sos_finish_ASL(ASL*,void**,int,int*,int**,int*,int**,int**,real**); - extern void student_check_ASL(ASL*); - extern void suf_declare_ASL(ASL*, SufDecl*, int); - extern SufDesc *suf_get_ASL(ASL*, const char*, int); - extern SufDesc *suf_iput_ASL(ASL*, const char*, int, int*); - extern SufDesc *suf_rput_ASL(ASL*, const char*, int, real*); - extern int suf_sos_ASL(ASL*,int,int*,char**,int**,int*,int**,int**,real**); - extern char *var_name_ASL(ASL*,int); - extern char *var_name_nomap_ASL(ASL*,int,int*); - extern void varscale_ASL(ASL*, int, real, fint*); - extern void what_prog(VOID); - extern void write_sol_ASL(ASL*, const char *msg, double *x, double *y, Option_Info*); - extern int write_solf_ASL(ASL*, const char *msg, double *x, double *y, Option_Info *, - const char*); - extern int write_solfx_ASL(ASL*, const char *msg, double *x, double *y, Option_Info *, - Fwrite, Fwrite, Fwrite, const char*); - extern void wrsolw_(char *msg, fint *nmsg, real *x, real *y, fint *wantsol, - ftnlen msg_len); - extern void wrtsol_(char *msg, fint *nmsg, real *x, real *y, - ftnlen msg_len); - extern real xectim_(VOID); - extern void xknowe_(real *x, fint *nerror); - extern void xknown_(real *x); - extern void xunkno_(VOID); - extern void zero_div_ASL(ASL*, real, const char*); - -#ifndef No_dtoa - extern double strtod_ASL(Const char*, char**); -#ifndef strtod /* if not set by previous funcadd.h */ -#define strtod strtod_ASL -#endif -#endif - -#ifdef __cplusplus - } -#endif - -#define con_name(n) con_name_ASL((ASL*)asl,n) -#define conadj(cv) conadj_ASL((ASL*)asl,cv,1) -#define conscale(i,s,ie) conscale_ASL((ASL*)asl,i,s,ie) -#define dense_j() dense_j_ASL((ASL*)asl) -#define edagread(f) fg_read_ASL((ASL*)asl,f,0) /* dreg */ -#define equ_adjust(x,y) equ_adjust_ASL((ASL*)asl,x,y) -#define f_read(a,b) f_read_ASL((ASL*)asl,a,b) -#define fg_read(a,b) fg_read_ASL((ASL*)asl,a,b) -#define fg_wread(a,b) fg_wread_ASL((ASL*)asl,a,b) -#define fg_write(a,b,c) fg_write_ASL((ASL*)asl,a,b,c) -#define fgh_read(a,b) fgh_read_ASL((ASL*)asl,a,b) -#define gen_rownos() gen_rownos_ASL((ASL*)asl) -#undef getenv -#define getenv getenv_ASL -#define int_catch(f,v) intcatch_ASL((ASL*)asl,f,v) -#define jac0dim(stub,len) jac0dim_ASL((ASL*)asl,stub,len) -#define jac1dim(s,m,n,no,nz,mxr,mxc,L) jac1dim_ASL((ASL*)asl,s,m,n,no,nz,mxr,mxc,L) -#define jac2dim(s,m,n,no,nz,mxr,mxc,L) jac2dim_ASL((ASL*)asl,s,m,n,no,nz,mxr,mxc,L) -#define jacdim(stub,M,N,NO,NZ,MXR,MXC,len) jac_dim_ASL((ASL*)asl,stub,M,N,NO,NZ,MXR,MXC,len) -#define jacdim0(stub,len) jac0dim_ASL((ASL*)asl,stub,len) -#define jacpdim(s,m,n,no,nz,mxr,mxc,L) jacpdim_ASL((ASL*)asl,s,m,n,no,nz,mxr,mxc,L) -#define lagscale(s,ie) lagscale_ASL((ASL*)asl,s,ie) -#define lcon_name(n) lcon_name_ASL((ASL*)asl,n) -#define mip_pri(a,b,c,d) mip_pri_ASL((ASL*)asl,a,b,c,d) -#define mqpcheck(a,b,c,d) mqpcheck_ASL((ASL*)asl,a,b,c,d) -#define mqpcheckv(a,b,c) mqpcheckv_ASL((ASL*)asl,a,b,c) -#define mqpcheckv_free(a) mqpcheckv_free_ASL((ASL*)asl,a) -#define nl_obj(n) nl_obj_ASL((ASL*)asl,n) -#define nqpcheck(a,b,c,d) nqpcheck_ASL((ASL*)asl,a,b,c,d) -#define obj_name(n) obj_name_ASL((ASL*)asl,n) -#define objconst(n) objconst_ASL((ASL*)asl,n) -#define pfg_read(a,b) pfg_read_ASL((ASL*)asl,a,b) -#define pfgh_read(a,b) pfgh_read_ASL((ASL*)asl,a,b) -#define qp_opify() qp_opify_ASL((ASL*)asl) -#define qp_read(a,b) qp_read_ASL((ASL*)asl,a,b) -#define qpcheck(a,b,c) qpcheck_ASL((ASL*)asl,a,b,c) -#define read_soln(x,y) read_sol_ASL((ASL*)asl,x,y) -#define show_funcs() show_funcs_ASL((ASL*)asl) -#define sos_add(a,b) sos_add_ASL((ASL*)asl,a,b) -#define sos_finish(a,b,c,d,e,f,g,h) sos_finish_ASL((ASL*)asl,a,b,c,d,e,f,g,h) -#define suf_declare(x,n) suf_declare_ASL((ASL*)asl,x,(int)(n)) -#define suf_get(s,i) suf_get_ASL((ASL*)asl,s,i) -#define suf_iput(n,i,x) suf_iput_ASL((ASL*)asl,n,i,x) -#define suf_rput(n,i,x) suf_rput_ASL((ASL*)asl,n,i,x) -#define suf_sos(a,b,c,d,e,f,g,h) suf_sos_ASL((ASL*)asl,a,b,c,d,e,f,g,h) -#define var_name(n) var_name_ASL((ASL*)asl,n) -#define varscale(i,s,ie) varscale_ASL((ASL*)asl,i,s,ie) -#define write_sol(m,x,y,oi) write_sol_ASL((ASL*)asl,m,x,y,oi) -#define write_soln(m,x,y) write_sol_ASL((ASL*)asl,m,x,y,0) -#ifdef KR_headers -#define del_mblk(a,b) Del_mblk_ASL((ASL*)asl, a, (void*)(b)) -#else -#define del_mblk(a,b) Del_mblk_ASL((ASL*)asl,a,b) -#endif -#define new_mblk(n) new_mblk_ASL((ASL*)asl,n) - -#define exit mainexit_ASL - -#ifdef MULTIPLE_THREADS -#define A_ASL , ASL *asl -#define C_ASL , (ASL*)asl -#define D_ASL ASL *asl; -#define K_ASL , asl -#ifndef MEM_LOCK -#define MEM_LOCK 3 -#endif -#ifndef MBLK_LOCK -#define MBLK_LOCK 4 -#endif -#ifndef HESOPROD_LOCK -#define HESOPROD_LOCK 5 -#endif -#else /* MULTIPLE_THREADS */ -#define A_ASL /*nothing*/ -#define C_ASL /*nothing*/ -#define D_ASL /*nothing*/ -#define K_ASL /*nothing*/ -#define ACQUIRE_DTOA_LOCK(n) /*nothing*/ -#define FREE_DTOA_LOCK(n) /*nothing*/ -#endif /* MULTIPLE_THREADS */ - -#define ASL_CHECK(a,n,w) if(!a||a->i.ASLtype!=n)badasl_ASL(a,n,w);cur_ASL=a; -#endif /* ASL_included */ diff --git a/external/ipopt/include/coin/ThirdParty/asl_pfg.h b/external/ipopt/include/coin/ThirdParty/asl_pfg.h deleted file mode 100644 index e3d26be5d..000000000 --- a/external/ipopt/include/coin/ThirdParty/asl_pfg.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************** -Copyright (C) 1997 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#undef PSHVREAD -#ifndef ASL_PFG_included -#define ASL_PFG_included -#include "psinfo.h" -#endif /* ASL_PFG_included */ diff --git a/external/ipopt/include/coin/ThirdParty/asl_pfgh.h b/external/ipopt/include/coin/ThirdParty/asl_pfgh.h deleted file mode 100644 index fc3e71c59..000000000 --- a/external/ipopt/include/coin/ThirdParty/asl_pfgh.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************** -Copyright (C) 1997 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#undef PSHVREAD -#define PSHVREAD -#ifndef ASL_PFGH_included -#define ASL_PFGH_included -#include "psinfo.h" -#endif /* ASL_PFGH_included */ diff --git a/external/ipopt/include/coin/ThirdParty/dmumps_c.h b/external/ipopt/include/coin/ThirdParty/dmumps_c.h deleted file mode 100644 index 1d5c2c918..000000000 --- a/external/ipopt/include/coin/ThirdParty/dmumps_c.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * - * This file is part of MUMPS 4.10.0, built on Tue May 10 12:56:32 UTC 2011 - * - * - * This version of MUMPS is provided to you free of charge. It is public - * domain, based on public domain software developed during the Esprit IV - * European project PARASOL (1996-1999). Since this first public domain - * version in 1999, research and developments have been supported by the - * following institutions: CERFACS, CNRS, ENS Lyon, INPT(ENSEEIHT)-IRIT, - * INRIA, and University of Bordeaux. - * - * The MUMPS team at the moment of releasing this version includes - * Patrick Amestoy, Maurice Bremond, Alfredo Buttari, Abdou Guermouche, - * Guillaume Joslin, Jean-Yves L'Excellent, Francois-Henry Rouet, Bora - * Ucar and Clement Weisbecker. - * - * We are also grateful to Emmanuel Agullo, Caroline Bousquet, Indranil - * Chowdhury, Philippe Combes, Christophe Daniel, Iain Duff, Vincent Espirat, - * Aurelia Fevre, Jacko Koster, Stephane Pralet, Chiara Puglisi, Gregoire - * Richard, Tzvetomila Slavova, Miroslav Tuma and Christophe Voemel who - * have been contributing to this project. - * - * Up-to-date copies of the MUMPS package can be obtained - * from the Web pages: - * http://mumps.enseeiht.fr/ or http://graal.ens-lyon.fr/MUMPS - * - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * - * User documentation of any code that uses this software can - * include this complete notice. You can acknowledge (using - * references [1] and [2]) the contribution of this package - * in any scientific publication dependent upon the use of the - * package. You shall use reasonable endeavours to notify - * the authors of the package of this publication. - * - * [1] P. R. Amestoy, I. S. Duff, J. Koster and J.-Y. L'Excellent, - * A fully asynchronous multifrontal solver using distributed dynamic - * scheduling, SIAM Journal of Matrix Analysis and Applications, - * Vol 23, No 1, pp 15-41 (2001). - * - * [2] P. R. Amestoy and A. Guermouche and J.-Y. L'Excellent and - * S. Pralet, Hybrid scheduling for the parallel solution of linear - * systems. Parallel Computing Vol 32 (2), pp 136-156 (2006). - * - */ - -/* Mostly written in march 2002 (JYL) */ - -#ifndef DMUMPS_C_H -#define DMUMPS_C_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "mumps_compat.h" -/* Next line defines MUMPS_INT, DMUMPS_COMPLEX and DMUMPS_REAL */ -#include "mumps_c_types.h" - -#ifndef MUMPS_VERSION -/* Protected in case headers of other arithmetics are included */ -#define MUMPS_VERSION "4.10.0" -#endif -#ifndef MUMPS_VERSION_MAX_LEN -#define MUMPS_VERSION_MAX_LEN 14 -#endif - -/* - * Definition of the (simplified) MUMPS C structure. - * NB: DMUMPS_COMPLEX are REAL types in s and d arithmetics. - */ -typedef struct { - - MUMPS_INT sym, par, job; - MUMPS_INT comm_fortran; /* Fortran communicator */ - MUMPS_INT icntl[40]; - DMUMPS_REAL cntl[15]; - MUMPS_INT n; - - MUMPS_INT nz_alloc; /* used in matlab interface to decide if we - free + malloc when we have large variation */ - - /* Assembled entry */ - MUMPS_INT nz; - MUMPS_INT *irn; - MUMPS_INT *jcn; - DMUMPS_COMPLEX *a; - - /* Distributed entry */ - MUMPS_INT nz_loc; - MUMPS_INT *irn_loc; - MUMPS_INT *jcn_loc; - DMUMPS_COMPLEX *a_loc; - - /* Element entry */ - MUMPS_INT nelt; - MUMPS_INT *eltptr; - MUMPS_INT *eltvar; - DMUMPS_COMPLEX *a_elt; - - /* Ordering, if given by user */ - MUMPS_INT *perm_in; - - /* Orderings returned to user */ - MUMPS_INT *sym_perm; /* symmetric permutation */ - MUMPS_INT *uns_perm; /* column permutation */ - - /* Scaling (input only in this version) */ - DMUMPS_REAL *colsca; - DMUMPS_REAL *rowsca; - - /* RHS, solution, ouptput data and statistics */ - DMUMPS_COMPLEX *rhs, *redrhs, *rhs_sparse, *sol_loc; - MUMPS_INT *irhs_sparse, *irhs_ptr, *isol_loc; - MUMPS_INT nrhs, lrhs, lredrhs, nz_rhs, lsol_loc; - MUMPS_INT schur_mloc, schur_nloc, schur_lld; - MUMPS_INT mblock, nblock, nprow, npcol; - MUMPS_INT info[40],infog[40]; - DMUMPS_REAL rinfo[40], rinfog[40]; - - /* Null space */ - MUMPS_INT deficiency; - MUMPS_INT *pivnul_list; - MUMPS_INT *mapping; - - /* Schur */ - MUMPS_INT size_schur; - MUMPS_INT *listvar_schur; - DMUMPS_COMPLEX *schur; - - /* Internal parameters */ - MUMPS_INT instance_number; - DMUMPS_COMPLEX *wk_user; - - /* Version number: length=14 in FORTRAN + 1 for final \0 + 1 for alignment */ - char version_number[MUMPS_VERSION_MAX_LEN + 1 + 1]; - /* For out-of-core */ - char ooc_tmpdir[256]; - char ooc_prefix[64]; - /* To save the matrix in matrix market format */ - char write_problem[256]; - MUMPS_INT lwk_user; - -} DMUMPS_STRUC_C; - - -void MUMPS_CALL -dmumps_c( DMUMPS_STRUC_C * dmumps_par ); - -#ifdef __cplusplus -} -#endif - -#endif /* DMUMPS_C_H */ - diff --git a/external/ipopt/include/coin/ThirdParty/funcadd.h b/external/ipopt/include/coin/ThirdParty/funcadd.h deleted file mode 100644 index ec30d9792..000000000 --- a/external/ipopt/include/coin/ThirdParty/funcadd.h +++ /dev/null @@ -1,487 +0,0 @@ -/**************************************************************** -Copyright (C) 1997-2001 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#ifndef FUNCADD_H_INCLUDED -#define FUNCADD_H_INCLUDED -#include "stdio1.h" /* for ANSI and any printing */ - -#ifndef VA_LIST -#define VA_LIST va_list -#endif - -#ifdef _WIN32 -#define Stdio_redefs -#endif - - typedef struct cryptblock cryptblock; - -#ifdef __cplusplus -#undef KR_headers -extern "C" { -#endif - -#ifndef real -typedef double real; -#endif -typedef struct arglist arglist; -typedef struct function function; -typedef struct TVA TVA; -typedef struct AmplExports AmplExports; -typedef struct AuxInfo AuxInfo; -typedef struct TableInfo TableInfo; -typedef struct TMInfo TMInfo; - -#ifndef No_arglist_def - -#undef Const -#ifdef KR_headers -#define Const /* nothing */ -#else -#define Const const -#endif - - struct -arglist { /* Information sent to user-defined functions */ - int n; /* number of args */ - int nr; /* number of real input args */ - int *at; /* argument types -- see DISCUSSION below */ - real *ra; /* pure real args (IN, OUT, and INOUT) */ - Const char **sa; /* symbolic IN args */ - real *derivs; /* for partial derivatives (if nonzero) */ - real *hes; /* for second partials (if nonzero) */ - char *dig; /* if (dig && dig[i]) { partials w.r.t. */ - /* ra[i] will not be used } */ - Char *funcinfo; /* for use by the function (if desired) */ - AmplExports *AE; /* functions made visible (via #defines below) */ - function *f; /* for internal use by AMPL */ - TVA *tva; /* for internal use by AMPL */ - char *Errmsg; /* To indicate an error, set this to a */ - /* description of the error. When derivs */ - /* is nonzero and the error is that first */ - /* derivatives cannot or are not computed, */ - /* a single quote character (') should be */ - /* the first character in the text assigned */ - /* to Errmsg, followed by the actual error */ - /* message. Similarly, if hes is nonzero */ - /* and the error is that second derivatives */ - /* are not or cannot be computed, a double */ - /* quote character (") should be the first */ - /* character in Errmsg, followed by the */ - /* actual error message text. */ - TMInfo *TMI; /* used in Tempmem calls */ - Char *Private; - /* The following fields are relevant */ - /* only when imported functions are called */ - /* by AMPL commands (not declarations). */ - - int nin; /* number of input (IN and INOUT) args */ - int nout; /* number of output (OUT and INOUT) args */ - int nsin; /* number of symbolic input arguments */ - int nsout; /* number of symbolic OUT and INOUT args */ - }; - -typedef real (*rfunc) ANSI((arglist *)); -typedef real (ufunc) ANSI((arglist *)); - -#endif /* No_arglist_def */ - - enum AMPLFUNC_AT_BITS { /* Intrepretation of at[i] when the type */ - /* arg to addfunc has the */ - /* FUNCADD_OUTPUT_ARGS bit on.*/ - AMPLFUNC_INARG = 1, /* IN or INOUT */ - AMPLFUNC_OUTARG = 2, /* OUT or INOUT */ - AMPLFUNC_STRING = 4, /* Input value is a string (sa[i]) */ - AMPLFUNC_STROUT = 8 /* String output value allowed */ - }; - - enum FUNCADD_TYPE { /* bits in "type" arg to addfunc */ - - /* The type arg to addfunc should consist of one of the */ - /* following values ... */ - - FUNCADD_REAL_VALUED = 0, /* real (double) valued function */ - FUNCADD_STRING_VALUED = 2, /* char* valued function (AMPL only) */ - FUNCADD_RANDOM_VALUED = 4, /* real random valued */ - FUNCADD_012ARGS = 6, /* Special case: real random valued */ - /* with 0 <= nargs <= 2 arguments */ - /* passed directly, rather than in */ - /* an arglist structure (AMPL only). */ - - /* possibly or-ed with the following... */ - - FUNCADD_STRING_ARGS = 1, /* allow string args */ - FUNCADD_OUTPUT_ARGS = 16, /* allow output args (AMPL only) */ - FUNCADD_TUPLE_VALUED = 32, /* not yet allowed */ - - /* internal use */ - FUNCADD_NO_ARGLIST = 8, - FUNCADD_NO_DUPWARN = 64, /* no complaint if already defined */ - FUNCADD_NONRAND_BUILTIN = 128 /* mean, variance, moment, etc. */ - }; - -/* If a constraint involves an imported function and presolve fixes all - * the arguments of the function, AMPL may later need to ask the - * function for its partial derivatives -- even though the solver had - * no reason to call the function. If so, it will pass an arglist *al - * with al->derivs nonzero, and it will expect the function to set - * al->derivs[i] to the partial derivative of the function with respect - * to al->ra[i]. Solvers that need to evaluate an imported function - * work the same way -- they set al->derivs to a nonzero value if they - * require both the function value and its first derivatives. Solvers - * that expect Hessians to be supplied to them also set al->hes to a - * nonzero value if they require second derivatives at the current - * argument. In this case, the function should set - * al->hes[i + j*(j+1)/2] to the partial derivative of the function with - * respect to al->ra[i] and al->ra[j] for all 0 <= i <= j < al->nr. - */ - -typedef void AddFunc ANSI(( - const char *name, - rfunc f, /* cast f to (rfunc) if it returns char* */ - int type, /* see FUNCADD_TYPE above */ - int nargs, /* >= 0 ==> exactly that many args - * <= -1 ==> at least -(nargs+1) args - */ - void *funcinfo, /* for use by the function (if desired) */ - AmplExports *ae - )); - -typedef void AddRand ANSI(( - const char *name, - rfunc f, /* assumed to be a random function */ - rfunc icdf, /* inverse CDF */ - int type, /* FUNCADD_STRING_ARGS or 0 */ - int nargs, /* >= 0 ==> exactly that many args - * <= -1 ==> at least -(nargs+1) args - */ - void *funcinfo, /* for use by the function (if desired) */ - AmplExports *ae - )); - -typedef void (*RandSeedSetter) ANSI((void*, unsigned long)); -typedef void AddRandInit ANSI((AmplExports *ae, RandSeedSetter, void*)); -typedef void Exitfunc ANSI((void*)); - - struct -AuxInfo { - AuxInfo *next; - char *auxname; - void *v; - void (*f) ANSI((AmplExports*, void*, ...)); - }; - - struct -AmplExports { - FILE *StdErr; - AddFunc *Addfunc; - long ASLdate; - int (*FprintF) ANSI((FILE*, const char*, ...)); - int (*PrintF) ANSI((const char*, ...)); - int (*SprintF) ANSI((char*, const char*, ...)); - int (*VfprintF) ANSI((FILE*, const char*, VA_LIST)); - int (*VsprintF) ANSI((char*, const char*, VA_LIST)); - double (*Strtod) ANSI((const char*, char**)); - cryptblock *(*Crypto) ANSI((char *key, size_t scrbytes)); - Char *asl; - void (*AtExit) ANSI((AmplExports *ae, Exitfunc*, void*)); - void (*AtReset) ANSI((AmplExports *ae, Exitfunc*, void*)); - Char *(*Tempmem) ANSI((TMInfo*, size_t)); - void (*Add_table_handler) ANSI(( - int (*DbRead) (AmplExports *ae, TableInfo *TI), - int (*DbWrite)(AmplExports *ae, TableInfo *TI), - char *handler_info, - int flags, - void *Vinfo - )); - Char *Private; - void (*Qsortv) ANSI((void*, size_t, size_t, int(*)(const void*,const void*,void*), void*)); - - /* More stuff for stdio in DLLs... */ - - FILE *StdIn; - FILE *StdOut; - void (*Clearerr) ANSI((FILE*)); - int (*Fclose) ANSI((FILE*)); - FILE* (*Fdopen) ANSI((int, const char*)); - int (*Feof) ANSI((FILE*)); - int (*Ferror) ANSI((FILE*)); - int (*Fflush) ANSI((FILE*)); - int (*Fgetc) ANSI((FILE*)); - char* (*Fgets) ANSI((char*, int, FILE*)); - int (*Fileno) ANSI((FILE*)); - FILE* (*Fopen) ANSI((const char*, const char*)); - int (*Fputc) ANSI((int, FILE*)); - int (*Fputs) ANSI((const char*, FILE*)); - size_t (*Fread) ANSI((void*, size_t, size_t, FILE*)); - FILE* (*Freopen) ANSI((const char*, const char*, FILE*)); - int (*Fscanf) ANSI((FILE*, const char*, ...)); - int (*Fseek) ANSI((FILE*, long, int)); - long (*Ftell) ANSI((FILE*)); - size_t (*Fwrite) ANSI((const void*, size_t, size_t, FILE*)); - int (*Pclose) ANSI((FILE*)); - void (*Perror) ANSI((const char*)); - FILE* (*Popen) ANSI((const char*, const char*)); - int (*Puts) ANSI((const char*)); - void (*Rewind) ANSI((FILE*)); - int (*Scanf) ANSI((const char*, ...)); - void (*Setbuf) ANSI((FILE*, char*)); - int (*Setvbuf) ANSI((FILE*, char*, int, size_t)); - int (*Sscanf) ANSI((const char*, const char*, ...)); - char* (*Tempnam) ANSI((const char*, const char*)); - FILE* (*Tmpfile) ANSI((void)); - char* (*Tmpnam) ANSI((char*)); - int (*Ungetc) ANSI((int, FILE*)); - AuxInfo *AI; - char* (*Getenv) ANSI((const char*)); - void (*Breakfunc) ANSI((int,void*)); - Char *Breakarg; - /* Items available with ASLdate >= 20020501 start here. */ - int (*SnprintF) ANSI((char*, size_t, const char*, ...)); - int (*VsnprintF) ANSI((char*, size_t, const char*, VA_LIST)); - - AddRand *Addrand; /* for random function/inverse CDF pairs */ - AddRandInit *Addrandinit; /* for adding a function to receive a new random seed */ - }; - -extern const char *i_option_ASL, *ix_details_ASL[]; - -#define funcadd funcadd_ASL - -#if defined(_WIN32) && !defined(__MINGW32__) -__declspec(dllexport) -#endif -extern void funcadd ANSI((AmplExports*)); /* dynamically linked */ -extern void af_libnamesave_ASL ANSI((AmplExports*, const char *fullname, const char *name, int nlen)); -extern void note_libuse_ASL ANSI((void)); /* If funcadd() does not provide any imported */ - /* functions, it can call note_libuse_ASL() to */ - /* keep the library loaded; note_libuse_ASL() is */ - /* called, e.g., by the tableproxy table handler. */ - -#ifdef __cplusplus - } -#endif - - typedef struct -DbCol { - real *dval; - char **sval; - } DbCol; - - struct -TableInfo { - int (*AddRows) ANSI((TableInfo *TI, DbCol *cols, long nrows)); - char *tname; /* name of this table */ - char **strings; - char **colnames; - DbCol *cols; - char *Missing; - char *Errmsg; - void *Vinfo; - TMInfo *TMI; - int nstrings; - int arity; - int ncols; - int flags; - long nrows; - void *Private; - int (*Lookup) ANSI((real*, char**, TableInfo*)); - long (*AdjustMaxrows) ANSI((TableInfo*, long new_maxrows)); - void *(*ColAlloc) ANSI((TableInfo*, int ncol, int sval)); - long maxrows; - }; - -enum { /* return values from (*DbRead)(...) and (*DbWrite)(...) */ - DB_Done = 0, /* Table read or written. */ - DB_Refuse = 1, /* Refuse to handle this table. */ - DB_Error = 2 /* Error reading or writing table. */ - }; - -enum { /* bits in flags field of TableInfo */ - DBTI_flags_IN = 1, /* table has IN or INOUT entities */ - DBTI_flags_OUT = 2, /* table has OUT or INOUT entities */ - DBTI_flags_INSET = 4 /* table has "in set" phrase: */ - /* DbRead could omit rows for */ - /* which Lookup(...) == -1; AMPL */ - /* will ignore such rows if DbRead */ - /* offers them. */ - }; - -#endif /* FUNCADD_H_INCLUDED */ - -#ifndef No_AE_redefs -/* Assume "{extern|static} AmplExports *ae;" is given elsewhere. */ -#undef Stderr -#undef addfunc -#undef fprintf -#undef getenv -#undef printf -#undef sprintf -#undef snprintf -#undef strtod -#undef vfprintf -#undef vsprintf -#undef vsnprintf -#define Stderr (ae->StdErr) -#define addfunc(a,b,c,d,e) (*ae->Addfunc)(a,b,c,d,e,ae) -#define addrand(a,b,c,d,e,f) (*ae->Addrand)(a,b,c,d,e,f,ae) -#define addrandinit(a,b) (*ae->Addrandinit)(ae,a,b) -#define printf (*ae->PrintF) -#define fprintf (*ae->FprintF) -#define snprintf (*ae->SnprintF) -#define sprintf (*ae->SprintF) -#define strtod (*ae->Strtod) -#define vfprintf (*ae->VfprintF) -#define vsprintf (*ae->VsprintF) -#define vsnprintf (*ae->VsnprintF) -#define TempMem(x,y) (*ae->Tempmem)(x,y) -#define at_exit(x,y) (*ae->AtExit)(ae,x,y) -#define at_reset(x,y) (*ae->AtReset)(ae,x,y) -#define add_table_handler(a,b,c,d,e) (*ae->Add_table_handler)(a,b,c,d,e) -#define qsortv(a,b,c,d,e) (*ae->Qsortv)(a,b,c,d,e) -#define getenv(x) (*ae->Getenv)(x) -#ifdef Stdio_redefs -#undef clearerr -#undef fclose -#undef fdopen -#undef feof -#undef ferror -#undef fflush -#undef fgetc -#undef fgets -#undef fileno -#undef fopen -#undef fputc -#undef fputs -#undef fread -#undef freopen -#undef fscanf -#undef fseek -#undef ftell -#undef fwrite -#undef getc -#undef getchar -#undef gets -#undef pclose -#undef perror -#undef popen -#undef putc -#undef putchar -#undef puts -#undef rewind -#undef scanf -#undef setbuf -#undef setvbuf -#undef sscanf -#undef tempnam -#undef tmpfile -#undef tmpnam -#undef ungetc -#undef vprintf -#define clearerr (*ae->Clearerr) -#define fclose (*ae->Fclose) -#define fdopen (*ae->Fdopen) -#define feof (*ae->Feof) -#define ferror (*ae->Ferror) -#define fflush (*ae->Fflush) -#define fgetc (*ae->Fgetc) -#define fgets (*ae->Fgets) -#define fileno (*ae->Fileno) -#define fopen (*ae->Fopen) -#define fputc (*ae->Fputc) -#define fputs (*ae->Fputs) -#define fread (*ae->Fread) -#define freopen (*ae->Freopen) -#define fscanf (*ae->Fscanf) -#define fseek (*ae->Fseek) -#define ftell (*ae->Ftell) -#define fwrite (*ae->Fwrite) -#define getc (*ae->Fgetc) -#define getchar() (*ae->Getc)(ae->StdIn) -#define gets Error - use "fgets" rather than "gets" -#define pclose (*ae->Pclose) -#define perror (*ae->Perror) -#define popen (*ae->Popen) -#define putc (*ae->Fputc) -#define putchar(x) (*ae->Fputc)(ae->StdOut,(x)) -#define puts (*ae->Puts) -#define rewind (*ae->Rewind) -#define scanf (*ae->Scanf) -#define setbuf (*ae->Setbuf) -#define setvbuf (*ae->Setvbuf) -#define sscanf (*ae->Sscanf) -#define tempnam (*ae->Tempnam) -#define tmpfile (*ae->Tmpfile) -#define tmpnam (*ae->Tmpnam) -#define ungetc (*ae->Ungetc) -#define vprintf(x,y) (*ae->VfprintF)(ae->StdOut,(x),(y)) -#define Stdin (ae->StdIn) -#define Stdout (ae->StdOut) -#ifndef No_std_FILE_redefs /* may elicit compiler warnings */ -#undef stdin -#undef stdout -#undef stderr -#define stdin (ae->StdIn) -#define stdout (ae->StdOut) -#define stderr (ae->StdErr) -#endif /* No_std_FILE_redefs */ -#endif /* Stdio_redefs */ -#endif /* ifndef No_AE_redefs */ - -/* DISCUSSION: the "at" field of an arglist... - * - * OUT and INOUT arguments are only permitted in AMPL commands, - * such as "let" and "call" commands (and not in declarations, e.g., - * of constraints and variables). - * - * When addfunc was called with type <= 6 (so there can be no OUT or - * INOUT arguments), for 0 <= i < n, - * at[i] >= 0 ==> arg i is ra[at[i]] - * at[i] < 0 ==> arg i is sa[-(at[i]+1)]. - * - * When addfunc was called with type & FUNCADD_OUTPUT_ARGS on (permitting - * OUT and INOUT arguments), arg i is in ra[i] or sa[i] (as explained - * below), derivs and hes are both null, and at[i] is the union of bits - * that describe arg i: - * AMPLFUNC_INARG = 1 ==> input arg; - * AMPLFUNC_OUTARG = 2 ==> output arg; - * AMPLFUNC_STROUT = 4 ==> can be assigned a string value. - * - * INOUT args have both the AMPLFUNC_INARG and the AMPLFUNC_OUTARG bits - * are on, i.e., (at[i] & 3) == 3. - * - * Symbolic OUT and INOUT arguments are a bit complicated. They can only - * correspond to symbolic parameters in AMPL, which may have either a - * string or a numeric value. Thus there is provision for specifying - * output values to be either numbers or strings. For simplicity, when - * the function accepts output arguments, ra[i] and sa[i] together describe - * argument i. In general (whentype & FUNCADD_OUTPUT_ARGS is nonzero in - * the addfunc call), the incoming value of argument i is ra[i] - * (a numeric value) if sa[i] is null and is otherwise sa[i]. - * To assign a value to argument i, either assign a numeric value to - * ra[i] and set sa[i] = 0, or assign a non-null value to sa[i] - * (in which case ra[i] will be ignored). A value assigned to argument - * i is ignored unless at[i] & AMPLFUNC_OUTARG is nonzero; if so - * and if (at[i] & AMPLFUNC_STROUT) == 0, string values cause an error - * message. - */ diff --git a/external/ipopt/include/coin/ThirdParty/getstub.h b/external/ipopt/include/coin/ThirdParty/getstub.h deleted file mode 100644 index a5d76316b..000000000 --- a/external/ipopt/include/coin/ThirdParty/getstub.h +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************** -Copyright (C) 1997-1998, 2000-2001 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#ifndef GETSTUB_H_included -#define GETSTUB_H_included -#ifndef ASL_included -#include "asl.h" -#endif - - typedef struct keyword keyword; - - typedef char * -Kwfunc(Option_Info *oi, keyword *kw, char *value); - - struct -keyword { - char *name; - Kwfunc *kf; - void *info; - char *desc; - }; - -#define KW(a,b,c,d) {a,b,(void*)(c),d} -#define nkeywds (int)(sizeof(keywds)/sizeof(keyword)) - - typedef fint Solver_KW_func(char*, fint); - typedef fint Fileeq_func(fint*, char*, fint); - - struct -Option_Info { - char *sname; /* invocation name of solver */ - char *bsname; /* solver name in startup "banner" */ - char *opname; /* name of solver_options environment var */ - keyword *keywds; /* key words */ - int n_keywds; /* number of key words */ - int flags; /* whether funcadd will be called, etc.: */ - /* see the first enum below */ - char *version; /* for -v and Ver_key_ASL() */ - char **usage; /* solver-specific usage message */ - Solver_KW_func *kwf; /* solver-specific keyword function */ - Fileeq_func *feq; /* for nnn=filename */ - keyword *options; /* command-line options (with -) before stub */ - int n_options; /* number of options */ - long driver_date; /* YYYYMMDD for driver */ - - /* For write_sol: */ - - int wantsol; /* write .sol file without -AMPL */ - int nS; /* transmit S[i], 0 <= i < nS */ - SufDesc *S; - - /* For possible use by "nonstandard" Kwfunc's: */ - - char *uinfo; - - /* Stuff provided/used by getopts (and getstops): */ - - ASL *asl; - char *eqsign; - int n_badopts; /* number of bad options: bail out if != 0*/ - int option_echo;/* whether to echo: see the second enum below. */ - /* Kwfunc's may set option_echo &= ~ASL_OI_echo to turn off all */ - /* keyword echoing or option_echo &= ~ASL_OI_echothis to turn */ - /* off echoing of the present keyword. If they detect but do */ - /* not themselves report a bad value, they should set */ - /* option_echo |= ASL_OI_badvalue. During command-line option */ - /* processing (for -... args), (option_echo & ASL_OI_clopt) is */ - /* nonzero. */ - - int nnl; /* internal use: copied to asl->i.need_nl_ */ - }; - - enum { /* bits for Option_Info.flags */ - ASL_OI_want_funcadd = 1, - ASL_OI_keep_underscores = 2, - ASL_OI_show_version = 4 - } ; - - enum { /* bits for Option_Info.option_echo */ - ASL_OI_echo = 1, - ASL_OI_echothis = 2, - ASL_OI_clopt = 4, - ASL_OI_badvalue = 8, - ASL_OI_never_echo = 16, - ASL_OI_tabexpand = 32, /* have shownames() expand tabs */ - ASL_OI_addnewline = 64, /* have shownames() add a newline */ - /* after each keyword description */ - ASL_OI_showname_bits = 96, - ASL_OI_defer_bsname = 128 /* print "bsname: " only if there */ - /* are options to echo */ - } ; - -#ifdef __cplusplus - extern "C" { -#endif - -/* Kwfuncs should invoke badopt_ASL() if they complain. */ -extern void badopt_ASL (Option_Info*); -extern char *badval_ASL (Option_Info*, keyword*, char *value, char *badc); -extern char* get_opt_ASL (Option_Info*, char*); -extern int getopts_ASL (ASL*, char **argv, Option_Info*); -extern char* getstops_ASL (ASL*, char **argv, Option_Info*); -extern char* getstub_ASL (ASL*, char ***pargv, Option_Info*); -extern void show_version_ASL(Option_Info*); -extern char sysdetails_ASL[]; -extern void usage_ASL(Option_Info*, int exit_code); -extern void usage_noexit_ASL(Option_Info*, int exit_code); - -#define getstub(a,b) getstub_ASL((ASL*)asl,a,b) -#define getstops(a,b) getstops_ASL((ASL*)asl,a,b) -#define getopts(a,b) getopts_ASL((ASL*)asl,a,b) - -#define CK_val CK_val_ASL /* known character value in known place */ -#define C_val C_val_ASL /* character value in known place */ -#define DA_val DA_val_ASL /* real (double) value in asl */ -#define DK_val DK_val_ASL /* known real (double) value in known place */ -#define DU_val DU_val_ASL /* real (double) value: offset from uinfo */ -#define D_val D_val_ASL /* real (double) value in known place */ -#define FI_val FI_val_ASL /* fint value in known place */ -#define IA_val IA_val_ASL /* int value in asl */ -#define IK0_val IK0_val_ASL /* int value 0 in known place */ -#define IK1_val IK1_val_ASL /* int value 1 in known place */ -#define IK_val IK_val_ASL /* known int value in known place */ -#define IU_val IU_val_ASL /* int value: offset from uinfo */ -#define I_val I_val_ASL /* int value in known place */ -#define LK_val LK_val_ASL /* known Long value in known place */ -#define LU_val LU_val_ASL /* Long value: offset from uinfo */ -#define L_val L_val_ASL /* Long value in known place */ -#define SU_val SU_val_ASL /* short value: offset from uinfo */ -#define Ver_val Ver_val_ASL /* report version */ -#define WS_val WS_val_ASL /* set wantsol in Option_Info */ - -extern char *Lic_info_add_ASL; /* for show_version_ASL() */ -extern char WS_desc_ASL[]; /* desc for WS_val, constrained problems */ -extern char WSu_desc_ASL[]; /* desc for WS_val, unconstrained problems */ - -extern Kwfunc C_val, CK_val, DA_val, DK_val, DU_val, D_val, FI_val, IA_val; -extern Kwfunc IK0_val, IK1_val, IK_val, IU_val, I_val, LK_val, LU_val; -extern Kwfunc L_val, Ver_val, WS_val; -extern Kwfunc SU_val; - -/* Routines for converting Double (real), Long, and int values: */ - -extern char *Dval_ASL (Option_Info*, keyword*, char*, real*); -extern char *Ival_ASL (Option_Info*, keyword*, char*, int*); -extern char *Lval_ASL (Option_Info*, keyword*, char*, Long*); - -#define voffset_of(t,c) ((void *)&((t*)0)->c) - -/* Structs whose address can be the info field for known values... */ - -#define C_Known C_Known_ASL /* char* value for CK_val */ -#define D_Known D_Known_ASL /* real (double) value for DK_val */ -#define I_Known I_Known_ASL /* int value for IK_val */ -#define L_Known L_Known_ASL /* Long value for LK_val */ - - typedef struct -C_Known { - char *val; - char **valp; - } C_Known; - - typedef struct -D_Known { - real val; - real *valp; - } D_Known; - - typedef struct -I_Known { - int val; - int *valp; - } I_Known; - - typedef struct -L_Known { - Long val; - Long *valp; - } L_Known; - -#ifdef __cplusplus - } -#endif - -#endif /* GETSTUB_H_included */ diff --git a/external/ipopt/include/coin/ThirdParty/mumps_c_types.h b/external/ipopt/include/coin/ThirdParty/mumps_c_types.h deleted file mode 100644 index aef621281..000000000 --- a/external/ipopt/include/coin/ThirdParty/mumps_c_types.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * This file is part of MUMPS 4.10.0, built on Tue May 10 12:56:32 UTC 2011 - * - * - * This version of MUMPS is provided to you free of charge. It is public - * domain, based on public domain software developed during the Esprit IV - * European project PARASOL (1996-1999). Since this first public domain - * version in 1999, research and developments have been supported by the - * following institutions: CERFACS, CNRS, ENS Lyon, INPT(ENSEEIHT)-IRIT, - * INRIA, and University of Bordeaux. - * - * The MUMPS team at the moment of releasing this version includes - * Patrick Amestoy, Maurice Bremond, Alfredo Buttari, Abdou Guermouche, - * Guillaume Joslin, Jean-Yves L'Excellent, Francois-Henry Rouet, Bora - * Ucar and Clement Weisbecker. - * - * We are also grateful to Emmanuel Agullo, Caroline Bousquet, Indranil - * Chowdhury, Philippe Combes, Christophe Daniel, Iain Duff, Vincent Espirat, - * Aurelia Fevre, Jacko Koster, Stephane Pralet, Chiara Puglisi, Gregoire - * Richard, Tzvetomila Slavova, Miroslav Tuma and Christophe Voemel who - * have been contributing to this project. - * - * Up-to-date copies of the MUMPS package can be obtained - * from the Web pages: - * http://mumps.enseeiht.fr/ or http://graal.ens-lyon.fr/MUMPS - * - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * - * User documentation of any code that uses this software can - * include this complete notice. You can acknowledge (using - * references [1] and [2]) the contribution of this package - * in any scientific publication dependent upon the use of the - * package. You shall use reasonable endeavours to notify - * the authors of the package of this publication. - * - * [1] P. R. Amestoy, I. S. Duff, J. Koster and J.-Y. L'Excellent, - * A fully asynchronous multifrontal solver using distributed dynamic - * scheduling, SIAM Journal of Matrix Analysis and Applications, - * Vol 23, No 1, pp 15-41 (2001). - * - * [2] P. R. Amestoy and A. Guermouche and J.-Y. L'Excellent and - * S. Pralet, Hybrid scheduling for the parallel solution of linear - * systems. Parallel Computing Vol 32 (2), pp 136-156 (2006). - * - */ - - -#ifndef MUMPS_C_TYPES_H -#define MUMPS_C_TYPES_H - -#define MUMPS_INT int - -#define SMUMPS_COMPLEX float -#define SMUMPS_REAL float - -#define DMUMPS_COMPLEX double -#define DMUMPS_REAL double - -/* Complex datatypes */ -typedef struct {float r,i;} mumps_complex; -typedef struct {double r,i;} mumps_double_complex; - -#define CMUMPS_COMPLEX mumps_complex -#define CMUMPS_REAL float - -#define ZMUMPS_COMPLEX mumps_double_complex -#define ZMUMPS_REAL double - - -#ifndef mumps_ftnlen -/* When passing a string, what is the type of the extra argument - * passed by value ? */ -# define mumps_ftnlen int -#endif - - -#define MUMPS_ARITH_s 1 -#define MUMPS_ARITH_d 2 -#define MUMPS_ARITH_c 4 -#define MUMPS_ARITH_z 8 - -#define MUMPS_ARITH_REAL ( MUMPS_ARITH_s | MUMPS_ARITH_d ) -#define MUMPS_ARITH_CMPLX ( MUMPS_ARITH_c | MUMPS_ARITH_z ) -#define MUMPS_ARITH_SINGLE ( MUMPS_ARITH_s | MUMPS_ARITH_c ) -#define MUMPS_ARITH_DBL ( MUMPS_ARITH_d | MUMPS_ARITH_z ) - - -#endif /* MUMPS_C_TYPES_H */ diff --git a/external/ipopt/include/coin/ThirdParty/mumps_compat.h b/external/ipopt/include/coin/ThirdParty/mumps_compat.h deleted file mode 100644 index d63120eb6..000000000 --- a/external/ipopt/include/coin/ThirdParty/mumps_compat.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * This file is part of MUMPS 4.10.0, built on Tue May 10 12:56:32 UTC 2011 - * - * - * This version of MUMPS is provided to you free of charge. It is public - * domain, based on public domain software developed during the Esprit IV - * European project PARASOL (1996-1999). Since this first public domain - * version in 1999, research and developments have been supported by the - * following institutions: CERFACS, CNRS, ENS Lyon, INPT(ENSEEIHT)-IRIT, - * INRIA, and University of Bordeaux. - * - * The MUMPS team at the moment of releasing this version includes - * Patrick Amestoy, Maurice Bremond, Alfredo Buttari, Abdou Guermouche, - * Guillaume Joslin, Jean-Yves L'Excellent, Francois-Henry Rouet, Bora - * Ucar and Clement Weisbecker. - * - * We are also grateful to Emmanuel Agullo, Caroline Bousquet, Indranil - * Chowdhury, Philippe Combes, Christophe Daniel, Iain Duff, Vincent Espirat, - * Aurelia Fevre, Jacko Koster, Stephane Pralet, Chiara Puglisi, Gregoire - * Richard, Tzvetomila Slavova, Miroslav Tuma and Christophe Voemel who - * have been contributing to this project. - * - * Up-to-date copies of the MUMPS package can be obtained - * from the Web pages: - * http://mumps.enseeiht.fr/ or http://graal.ens-lyon.fr/MUMPS - * - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * - * User documentation of any code that uses this software can - * include this complete notice. You can acknowledge (using - * references [1] and [2]) the contribution of this package - * in any scientific publication dependent upon the use of the - * package. You shall use reasonable endeavours to notify - * the authors of the package of this publication. - * - * [1] P. R. Amestoy, I. S. Duff, J. Koster and J.-Y. L'Excellent, - * A fully asynchronous multifrontal solver using distributed dynamic - * scheduling, SIAM Journal of Matrix Analysis and Applications, - * Vol 23, No 1, pp 15-41 (2001). - * - * [2] P. R. Amestoy and A. Guermouche and J.-Y. L'Excellent and - * S. Pralet, Hybrid scheduling for the parallel solution of linear - * systems. Parallel Computing Vol 32 (2), pp 136-156 (2006). - * - */ - -/* Compatibility issues between various Windows versions */ -#ifndef MUMPS_COMPAT_H -#define MUMPS_COMPAT_H - - -#if defined(_WIN32) && ! defined(__MINGW32__) -# define MUMPS_WIN32 1 -#endif - -#ifndef MUMPS_CALL -# ifdef MUMPS_WIN32 -/* Modify/choose between next 2 lines depending - * on your Windows calling conventions */ -/* # define MUMPS_CALL __stdcall */ -# define MUMPS_CALL -# else -# define MUMPS_CALL -# endif -#endif - -#if (__STDC_VERSION__ >= 199901L) -# define MUMPS_INLINE static inline -#else -# define MUMPS_INLINE -#endif - - -#endif /* MUMPS_COMPAT_H */ diff --git a/external/ipopt/include/coin/ThirdParty/mumps_mpi.h b/external/ipopt/include/coin/ThirdParty/mumps_mpi.h deleted file mode 100644 index 7ab0c3738..000000000 --- a/external/ipopt/include/coin/ThirdParty/mumps_mpi.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * This file is part of MUMPS 4.10.0, built on Tue May 10 12:56:32 UTC 2011 - * - * - * This version of MUMPS is provided to you free of charge. It is public - * domain, based on public domain software developed during the Esprit IV - * European project PARASOL (1996-1999). Since this first public domain - * version in 1999, research and developments have been supported by the - * following institutions: CERFACS, CNRS, ENS Lyon, INPT(ENSEEIHT)-IRIT, - * INRIA, and University of Bordeaux. - * - * The MUMPS team at the moment of releasing this version includes - * Patrick Amestoy, Maurice Bremond, Alfredo Buttari, Abdou Guermouche, - * Guillaume Joslin, Jean-Yves L'Excellent, Francois-Henry Rouet, Bora - * Ucar and Clement Weisbecker. - * - * We are also grateful to Emmanuel Agullo, Caroline Bousquet, Indranil - * Chowdhury, Philippe Combes, Christophe Daniel, Iain Duff, Vincent Espirat, - * Aurelia Fevre, Jacko Koster, Stephane Pralet, Chiara Puglisi, Gregoire - * Richard, Tzvetomila Slavova, Miroslav Tuma and Christophe Voemel who - * have been contributing to this project. - * - * Up-to-date copies of the MUMPS package can be obtained - * from the Web pages: - * http://mumps.enseeiht.fr/ or http://graal.ens-lyon.fr/MUMPS - * - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY - * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * - * User documentation of any code that uses this software can - * include this complete notice. You can acknowledge (using - * references [1] and [2]) the contribution of this package - * in any scientific publication dependent upon the use of the - * package. You shall use reasonable endeavours to notify - * the authors of the package of this publication. - * - * [1] P. R. Amestoy, I. S. Duff, J. Koster and J.-Y. L'Excellent, - * A fully asynchronous multifrontal solver using distributed dynamic - * scheduling, SIAM Journal of Matrix Analysis and Applications, - * Vol 23, No 1, pp 15-41 (2001). - * - * [2] P. R. Amestoy and A. Guermouche and J.-Y. L'Excellent and - * S. Pralet, Hybrid scheduling for the parallel solution of linear - * systems. Parallel Computing Vol 32 (2), pp 136-156 (2006). - * - */ - -#ifndef MUMPS_MPI_H -#define MUMPS_MPI_H - -/* We define all symbols as extern "C" for users who call MUMPS with its - libseq from a C++ driver. */ -#ifdef __cplusplus -extern "C" { -#endif - -/* This is the minimum to have the C interface of MUMPS work. - * Most of the time, users who need this file have no call to MPI functions in - * their own code. Hence it is not worth declaring all MPI functions here. - * However if some users come to request some more stub functions of the MPI - * standards, we may add them. But it is not worth doing it until then. */ - -typedef int MPI_Comm; /* Simple type for MPI communicator */ -static MPI_Comm MPI_COMM_WORLD=(MPI_Comm)0; - -int MPI_Init(int *pargc, char ***pargv); -int MPI_Comm_rank(int comm, int *rank); -int MPI_Finalize(void); - -#ifdef __cplusplus -} -#endif - -#endif /* MUMPS_MPI_H */ diff --git a/external/ipopt/include/coin/ThirdParty/nlp.h b/external/ipopt/include/coin/ThirdParty/nlp.h deleted file mode 100644 index 67d00c405..000000000 --- a/external/ipopt/include/coin/ThirdParty/nlp.h +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************** -Copyright (C) 1997-1998, 2001 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#ifndef NLP_H_included -#define NLP_H_included - -#ifndef ASL_included -#include "asl.h" -#endif - -typedef struct argpair argpair; -typedef struct cde cde; -typedef struct cexp cexp; -typedef struct cexp1 cexp1; -typedef struct de de; -typedef union ei ei; -typedef struct expr expr; -typedef struct expr_f expr_f; -typedef struct expr_h expr_h; -typedef struct expr_if expr_if; -typedef struct expr_v expr_v; -typedef struct expr_va expr_va; -typedef struct funnel funnel; -typedef struct list list; - -typedef real efunc ANSI((expr * A_ASL)); - -#define r_ops r_ops_ASL -#define obj1val obj1val_ASL -#define obj1grd obj1grd_ASL -#define con1val con1val_ASL -#define jac1val jac1val_ASL -#define con1ival con1ival_ASL -#define con1grd con1grd_ASL -#define lcon1val lcon1val_ASL -#define x1known x1known_ASL - - union -ei { - expr *e; - expr **ep; - expr_if *eif; - expr_n *en; - int i; - plterm *p; - de *d; - real *rp; - derp *D; - cexp *ce; - }; - - struct -expr { - efunc *op; - int a; - real dL; - ei L, R; - real dR; - }; - - struct -expr_v { - efunc *op; - int a; - real v; - }; - - struct -expr_if { - efunc *op; - int a; - expr *e, *T, *F; - derp *D, *dT, *dF, *d0; - ei Tv, Fv; - expr_if *next, *next2; - }; - - struct -expr_va { - efunc *op; - int a; - ei L, R; - expr_va *next, *next2; - derp *d0; - }; - - struct -cde { - expr *e; - derp *d; - int zaplen; - }; - - struct -de { - expr *e; - derp *d; - ei dv; - }; - - struct -list { - list *next; - ei item; - }; - - struct -cexp1 { - expr *e; - int nlin; - linpart *L; - }; - - struct -cexp { - expr *e; - int nlin; - linpart *L; - funnel *funneled; - list *cref; - ei z; - int zlen; - derp *d; - int *vref; - }; - - struct -funnel { - funnel *next; - cexp *ce; - derp *fulld; - cplist *cl; - cde fcde; - }; - - struct -argpair { - expr *e; - union { - char **s; - real *v; - } u; - }; - - struct -expr_f { - efunc *op; - int a; - func_info *fi; - arglist *al; - argpair *ap, *ape, *sap, *sape; - expr *args[1]; - }; - - struct -expr_h { - efunc *op; - int a; - char sym[1]; - }; - - typedef struct -Edag1info { - cde *con_de_; /* constraint deriv. and expr. info */ - cde *lcon_de_; /* logical constraints */ - cde *obj_de_; /* objective deriv. and expr. info */ - expr_v *var_e_; /* variable values (and related items) */ - - /* stuff for "defined" variables */ - funnel *f_b_; - funnel *f_c_; - funnel *f_o_; - expr_v *var_ex_, - *var_ex1_; - cexp *cexps_; - cexp1 *cexps1_; - efunc **r_ops_; - char *c_class; /* class of each constraint: */ - /* 0 = constant */ - /* 1 = linear */ - /* 2 = quadratic */ - /* 3 = general nonlinear */ - char *o_class; /* class of each objective */ - char *v_class; /* class of each defined variable */ - int c_class_max; /* max of c_class values */ - int o_class_max; /* max of o_class values */ - /* The above are only computed if requested */ - /* by the ASL_find_c_class and */ - /* ASL_find_o_class bits of the flags arg */ - /* to pfgh_read() and pfg_read() */ - } Edag1info; - - typedef struct -ASL_fg { - Edagpars p; - Edaginfo i; - Edag1info I; - } ASL_fg; - -#ifdef __cplusplus - extern "C" { -#endif - extern efunc *r_ops_ASL[]; - extern void com1eval_ASL ANSI((ASL_fg*, int, int)); - extern void comeval_ASL ANSI((ASL_fg*, int, int)); - extern void funnelset_ASL ANSI((ASL_fg*, funnel *)); - extern real obj1val ANSI((ASL*, int nobj, real *X, fint *nerror)); - extern void obj1grd ANSI((ASL*, int nobj, real *X, real *G, fint *nerror)); - extern void con1val ANSI((ASL*, real *X, real *F, fint *nerror)); - extern void jac1val ANSI((ASL*, real *X, real *JAC, fint *nerror)); - extern real con1ival ANSI((ASL*,int nc, real *X, fint *ne)); - extern void con1grd ANSI((ASL*, int nc, real *X, real *G, fint *nerror)); - extern int lcon1val ANSI((ASL*,int nc, real *X, fint *ne)); - extern int x0_check_ASL ANSI((ASL_fg*, real *)); - extern void x1known ANSI((ASL*, real*, fint*)); -#ifdef __cplusplus - } -#endif - -#define comeval(a,b) comeval_ASL((ASL_fg*)asl,a,b) -#define com1eval(a,b) com1eval_ASL((ASL_fg*)asl,a,b) -#define funnelset(a) funnelset_ASL((ASL_fg*)asl,a) - -#define cexps asl->I.cexps_ -#define cexps1 asl->I.cexps1_ -#define con_de asl->I.con_de_ -#define f_b asl->I.f_b_ -#define f_c asl->I.f_c_ -#define f_o asl->I.f_o_ -#define lcon_de asl->I.lcon_de_ -#define obj_de asl->I.obj_de_ -#define var_e asl->I.var_e_ -#define var_ex asl->I.var_ex_ -#define var_ex1 asl->I.var_ex1_ - -#undef f_OPNUM -#define f_OPNUM (efunc*)f_OPNUM_ASL - -#endif /* NLP_H_included */ diff --git a/external/ipopt/include/coin/ThirdParty/nlp2.h b/external/ipopt/include/coin/ThirdParty/nlp2.h deleted file mode 100644 index ceefe2b95..000000000 --- a/external/ipopt/include/coin/ThirdParty/nlp2.h +++ /dev/null @@ -1,342 +0,0 @@ -/**************************************************************** -Copyright (C) 1997-1998, 2000-2001 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -/* Variant of nlp.h for Hessian times vector computations. */ - -#ifndef NLP_H2_included -#define NLP_H2_included - -#ifndef ASL_included -#include "asl.h" -#endif - -#ifdef __cplusplus - extern "C" { -#endif - -typedef struct argpair2 argpair2; -typedef struct cde2 cde2; -typedef struct cexp2 cexp2; -typedef struct cexp21 cexp21; -typedef struct de2 de2; -typedef union ei2 ei2; -typedef struct expr2 expr2; -typedef struct expr2_f expr2_f; -typedef struct expr2_h expr2_h; -typedef struct expr2_if expr2_if; -typedef struct expr2_v expr2_v; -typedef struct expr2_va expr2_va; -typedef struct funnel2 funnel2; -typedef struct hes_fun hes_fun; -typedef struct list2 list2; -typedef union uir uir; - -typedef real efunc2 ANSI((expr2* A_ASL)); -typedef char *sfunc ANSI((expr2* A_ASL)); - - union -uir { - int i; - real r; - }; - - union -ei2 { - expr2 *e; - expr2 **ep; - expr2_if*eif; - expr_n *en; - expr2_v *ev; - int i; - plterm *p; - de2 *d; - real *rp; - derp *D; - cexp2 *ce; - }; - - struct -expr2 { - efunc2 *op; - int a; /* adjoint index (for gradient computation) */ - expr2 *fwd, *bak; - uir dO; /* deriv of op w.r.t. t in x + t*p */ - real aO; /* adjoint (in Hv computation) of op */ - real adO; /* adjoint (in Hv computation) of dO */ - real dL; /* deriv of op w.r.t. left operand */ - ei2 L, R; /* left and right operands */ - real dR; /* deriv of op w.r.t. right operand */ - real dL2; /* second partial w.r.t. L, L */ - real dLR; /* second partial w.r.t. L, R */ - real dR2; /* second partial w.r.t. R, R */ - }; - - struct -expr2_v { - efunc2 *op; - int a; - expr2 *fwd, *bak; - uir dO; - real aO, adO; - real v; - }; - - struct -expr2_if { - efunc2 *op; - int a; - expr2 *fwd, *bak; - uir dO; - real aO, adO; - expr2 *val, *vale, *valf, *e, *T, *Te, *Tf, *F, *Fe, *Ff; - derp *D, *dT, *dF, *d0; - ei2 Tv, Fv; - expr2_if *next, *next2; - derp *dTlast; - }; - - struct -expr2_va { - efunc2 *op; - int a; - expr2 *fwd, *bak; - uir dO; - real aO, adO; - expr2 *val, *vale, *valf; - ei2 L, R; - expr2_va *next, *next2; - derp *d0; - }; - - struct -cde2 { - expr2 *e, *ee, *ef; - derp *d; - int zaplen; - int com11, n_com1; - }; - - struct -de2 { /* for varargs */ - expr2 *e, *ee, *ef; - derp *d; - ei2 dv; - derp *dlast; /* for sputhes setup */ - }; - - struct -list2 { - list2 *next; - ei2 item; - }; - - struct -cexp21 { - expr2 *e, *ee, *ef; - linpart *L; - int nlin; - }; - - struct -cexp2 { - expr2 *e, *ee, *ef; - linpart *L; - int nlin; - funnel2 *funneled; - list2 *cref; - ei2 z; - int zlen; - derp *d; - int *vref; - hes_fun *hfun; - }; - - struct -funnel2 { - funnel2 *next; - cexp2 *ce; - cde2 fcde; - derp *fulld; - cplist *cl; - }; - - struct -argpair2 { - expr2 *e; - union { - char **s; - real *v; - } u; - }; - - struct -expr2_f { - efunc2 *op; - int a; - expr2 *fwd, *bak; - uir dO; - real aO, adO; - func_info *fi; - arglist *al; - argpair2 *ap, *ape, *sap, *sape; - argpair2 *da; /* differentiable args -- nonconstant */ - argpair2 *dae; - real **fh; /* Hessian info */ - expr2 *args[1]; - }; - - struct -expr2_h { - efunc2 *op; - int a; - char sym[1]; - }; - - typedef struct -Edag2info { - cde2 *con2_de_; /* constraint deriv. and expr. info */ - cde2 *lcon2_de_; /* logical constraints */ - cde2 *obj2_de_; /* objective deriv. and expr. info */ - expr2_v *var2_e_; /* variable values (and related items) */ - - /* stuff for "defined" variables */ - funnel2 *f2_b_; - funnel2 *f2_c_; - funnel2 *f2_o_; - expr2_v *var2_ex_, - *var2_ex1_; - cexp2 *cexps2_, *cexpsc_, *cexpso_, *cexpse_; - cexp21 *cexps21_; - hes_fun *hesthread; - char *c_class; /* class of each constraint: */ - /* 0 = constant */ - /* 1 = linear */ - /* 2 = quadratic */ - /* 3 = general nonlinear */ - char *o_class; /* class of each objective */ - char *v_class; /* class of each defined variable */ - int c_class_max; /* max of c_class values */ - int o_class_max; /* max of o_class values */ - /* The above are only computed if requested */ - /* by the ASL_find_c_class and */ - /* ASL_find_o_class bits of the flags arg */ - /* to pfgh_read() and pfg_read() */ - int x0kind_init; - } Edag2info; - - typedef struct -ASL_fgh { - Edagpars p; - Edaginfo i; - Edag2info I; - } ASL_fgh; - - extern efunc2 *r2_ops_ASL[]; - extern void com21eval_ASL ANSI((ASL_fgh*, int, int)); - extern void com2eval_ASL ANSI((ASL_fgh*, int, int)); - extern void fun2set_ASL ANSI((ASL_fgh*, funnel2 *)); -#ifdef __cplusplus - } -#endif - -#ifndef SKIP_NL2_DEFINES -extern efunc2 f2_OPVARVAL_ASL; - -#define cexpsc asl->I.cexpsc_ -#define cexpse asl->I.cexpse_ -#define cexpso asl->I.cexpso_ -#define cexps1 asl->I.cexps21_ -#define cexps asl->I.cexps2_ -#define con_de asl->I.con2_de_ -#define f_b asl->I.f2_b_ -#define f_c asl->I.f2_c_ -#define f_o asl->I.f2_o_ -#define lcon_de asl->I.lcon2_de_ -#define obj_de asl->I.obj2_de_ -#define var_e asl->I.var2_e_ -#define var_ex1 asl->I.var2_ex1_ -#define var_ex asl->I.var2_ex_ - -#define argpair argpair2 -#define cde cde2 -#define cexp cexp2 -#define cexp1 cexp21 -#define de de2 -#define ei ei2 -#define expr expr2 -#define expr_f expr2_f -#define expr_h expr2_h -#define expr_if expr2_if -#define expr_v expr2_v -#define expr_va expr2_va -#define funnel funnel2 -#define list list2 - -#define com1eval com21eval_ASL -#define comeval com2eval_ASL -#define funnelset fun2set_ASL -#undef r_ops -#define r_ops r2_ops_ASL - -#ifndef PSHVREAD -#define f_OPIFSYM f2_IFSYM_ASL -#define f_OPPLTERM f2_PLTERM_ASL -#define f_OPFUNCALL f2_FUNCALL_ASL -#define f_OP1POW f2_1POW_ASL -#define f_OP2POW f2_2POW_ASL -#define f_OPCPOW f2_CPOW_ASL -#define f_OPPLUS f2_PLUS_ASL -#define f_OPSUMLIST f2_SUMLIST_ASL -#define f_OPHOL f2_HOL_ASL -#define f_OPPOW f2_POW_ASL -#define f_OPVARVAL f2_VARVAL_ASL -#endif - -/* operation classes (for H*v computation) */ - -#define Hv_binaryR 0 -#define Hv_binaryLR 1 -#define Hv_unary 2 -#define Hv_vararg 3 -#define Hv_if 4 -#define Hv_plterm 5 -#define Hv_sumlist 6 -#define Hv_func 7 -#define Hv_negate 8 -#define Hv_plusR 9 -#define Hv_plusL 10 -#define Hv_plusLR 11 -#define Hv_minusR 12 -#define Hv_minusLR 13 -#define Hv_timesR 14 -#define Hv_timesL 15 -#define Hv_timesLR 16 - -/* treat if as vararg, minusL as plusL, binaryL as unary */ - -#endif /* SKIP_NL2_DEFINES */ - -#undef f_OPNUM -#define f_OPNUM (efunc2*)f_OPNUM_ASL -#endif /* NLP_H2_included */ diff --git a/external/ipopt/include/coin/ThirdParty/opcode.hd b/external/ipopt/include/coin/ThirdParty/opcode.hd deleted file mode 100644 index 899972c9b..000000000 --- a/external/ipopt/include/coin/ThirdParty/opcode.hd +++ /dev/null @@ -1,70 +0,0 @@ -#define OPPLUS 0 -#define OPMINUS 1 -#define OPMULT 2 -#define OPDIV 3 -#define OPREM 4 -#define OPPOW 5 -#define OPLESS 6 -#define MINLIST 11 -#define MAXLIST 12 -#define FLOOR 13 -#define CEIL 14 -#define ABS 15 -#define OPUMINUS 16 -#define OPOR 20 -#define OPAND 21 -#define LT 22 -#define LE 23 -#define EQ 24 -#define GE 28 -#define GT 29 -#define NE 30 -#define OPNOT 34 -#define OPIFnl 35 -#define OP_tanh 37 -#define OP_tan 38 -#define OP_sqrt 39 -#define OP_sinh 40 -#define OP_sin 41 -#define OP_log10 42 -#define OP_log 43 -#define OP_exp 44 -#define OP_cosh 45 -#define OP_cos 46 -#define OP_atanh 47 -#define OP_atan2 48 -#define OP_atan 49 -#define OP_asinh 50 -#define OP_asin 51 -#define OP_acosh 52 -#define OP_acos 53 -#define OPSUMLIST 54 -#define OPintDIV 55 -#define OPprecision 56 -#define OPround 57 -#define OPtrunc 58 -#define OPCOUNT 59 -#define OPNUMBEROF 60 -#define OPNUMBEROFs 61 -#define OPATLEAST 62 -#define OPATMOST 63 -#define OPPLTERM 64 -#define OPIFSYM 65 -#define OPEXACTLY 66 -#define OPNOTATLEAST 67 -#define OPNOTATMOST 68 -#define OPNOTEXACTLY 69 -#define ANDLIST 70 -#define ORLIST 71 -#define OPIMPELSE 72 -#define OP_IFF 73 -#define OPALLDIFF 74 -#define OPSOMESAME 75 -#define OP1POW 76 -#define OP2POW 77 -#define OPCPOW 78 -#define OPFUNCALL 79 -#define OPNUM 80 -#define OPHOL 81 -#define OPVARVAL 82 -#define N_OPS 83 diff --git a/external/ipopt/include/coin/ThirdParty/psinfo.h b/external/ipopt/include/coin/ThirdParty/psinfo.h deleted file mode 100644 index e91eda1f0..000000000 --- a/external/ipopt/include/coin/ThirdParty/psinfo.h +++ /dev/null @@ -1,337 +0,0 @@ -/**************************************************************** -Copyright (C) 1997, 1998, 2001 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -#ifdef PSHVREAD -#ifndef PSINFO_H2_included -#define PSINFO_H2_included -#undef PSINFO_H_included -#ifndef NLP_H2_included -#include "nlp2.h" -#endif -#define cde cde2 -#define la_ref la_ref2 -#define linarg linarg2 -#define range range2 -#define rhead rhead2 -#define psb_elem psb_elem2 -#define psg_elem psg_elem2 -#define ps_func ps_func2 -#define dv_info dv_info2 -#define split_ce split_ce2 -#define ps_info ps_info2 -#define psinfo psinfo2 -#endif /* PSINFO_H2_included */ -#else /* PSHVREAD */ -#ifndef PSINFO_H1_included -#define PSINFO_H1_included -#undef PSINFO_H_included -#ifndef NLP_H_included -#include "nlp.h" -#endif -#endif -#endif /* PSHVREAD */ -#ifndef PSINFO_H_included -#define PSINFO_H_included - - typedef struct la_ref la_ref; - typedef struct linarg linarg; - typedef struct range range; - - struct -la_ref { - la_ref *next; - expr **ep; - real c; - real scale; - }; - - struct -linarg { - linarg *hnext; /* for hashing */ - linarg *tnext; /* next linear argument to this term */ - linarg *lnext; /* for adjusting v->op */ - la_ref *refs; /* references */ - expr_v *v; /* variable that evaluates this linear term */ - ograd *nz; /* the nonzeros */ - int nnz; /* number of nonzeros (to help hashing) */ - int termno; /* helps tell whether new to this term */ - }; - - typedef struct -rhead { - range *next, *prev; - } rhead; - -#ifndef PSINFO_H0_included -#define MBLK_KMAX 30 -#endif /* PSINFO_H0_included */ - - typedef struct psb_elem psb_elem; - - struct -range { - rhead rlist; /* list of all ranges */ - range *hnext; /* for hashing U */ - range *hunext; /* for hashing unit vectors */ - int n; /* rows in U */ - int nv; /* variables involved in U */ - int nintv; /* number of internal variables (non-unit */ - /* rows in U) */ - int lasttermno; /* termno of prev. use in this term */ - /* -1 ==> not yet used in this constr or obj. */ - /* Set to least variable (1st = 0) in this */ - /* range at the end of psedread. */ - int lastgroupno; /* groupno at last use of this term */ - unsigned int chksum; /* for hashing */ - psb_elem *refs; /* constraints and objectives with this range */ - int *ui; /* unit vectors defining this range */ - /* (for n >= nv) */ - linarg **lap; /* nonzeros in U */ - int *cei; /* common expressions: union over refs */ - real *hest; /* nonzero ==> internal Hessian triangle */ - /* computed by hvpinit */ - }; - - struct -psb_elem { /* basic element of partially-separable func */ - psb_elem *next; /* for range.refs */ - range *U; - int *ce; /* common exprs if nonzero: ce[i], 1 <= i <= ce[0] */ - cde D; /* derivative and expr info */ - int conno; /* constraint no. (if >= 0) or -2 - obj no. */ - int termno; - int groupno; - }; - - typedef struct -psg_elem { /* group element details of partially-separable func */ - real g0; /* constant term */ - real g1; /* first deriv of g */ - real g2; /* 2nd deriv of g */ - real scale; /* temporary(?!!) until we introduce unary OPSCALE */ - expr_n esum; /* esum.v = result of summing g0, E and L */ - expr *g; /* unary operator */ - expr *ge; /* "last" unary operator */ - ograd *og; /* first deriv = g1 times og */ - int nlin; /* number of linear terms */ - int ns; /* number of nonlinear terms */ - linpart *L; /* the linear terms */ - psb_elem *E; /* the nonlinear terms */ - } psg_elem; - - typedef struct -ps_func { - int nb; /* number of basic terms */ - int ng; /* number of group terms */ - int nxval; /* for psgcomp */ - psb_elem *b; /* the basic terms */ - psg_elem *g; /* the group terms */ - } ps_func; - - typedef struct -dv_info { /* defined variable info */ - ograd *ll; /* list of linear defined vars referenced */ - linarg **nl; /* nonlinear part, followed by 0 */ - real scale; /* scale factor for linear term */ - linarg *lt; /* linear term of nonlinear defined var */ - } dv_info; - - typedef struct -split_ce { - range *r; - int *ce; /* common expressions */ - } split_ce; - -#ifdef PSHVREAD - - struct -hes_fun { - hes_fun *hfthread; - cexp2 *c; - real *grdhes; - ograd *og; - expr_v **vp; - int n; - }; - - typedef struct Hesoprod Hesoprod; - struct -Hesoprod { - Hesoprod *next; - ograd *left, *right; - real coef; - }; - - typedef struct uHeswork uHeswork; - struct -uHeswork { - uHeswork *next; - int k; - range *r; - int *ui, *uie; - ograd *ogp[1]; /* scratch of length r->n */ - }; - - typedef struct Umultinfo Umultinfo; - struct -Umultinfo { - Umultinfo *next; - ograd *og, *og0; - expr_v *v; - int i; - }; - - typedef struct Ihinfo Ihinfo; - struct -Ihinfo { - Ihinfo *next; /* for chaining ihinfo's with positive count */ - range *r; /* list, on prev, of ranges with this ihd */ - real *hest; /* hest memory to free */ - int ihd; /* internal Hessian dimension, min(n,nv) */ - int k; /* htcl(nr*(ihd*(ihd+1)/2)*sizeof(real)) */ - int nr; /* number of ranges with this ihd */ - }; - -#endif /* PSHVREAD */ - - typedef struct -ps_info { - Long merge; /* for noadjust = 1 */ - ps_func *cps; - ps_func *ops; - dv_info *dv; - expr_v **vp; /* for values of common variables */ - rhead rlist; - linarg *lalist; /* all linargs */ - int *dvsp0; /* dvsp0[i] = subscript of first var into which */ - /* cexp i was split, 0 <= i <= ncom */ - int nc1; /* common expressions for just this function */ - int ns0; /* initial number of elements */ - int ncom; /* number of common expressions before splitting */ - int ndupdt; /* duplicate linear terms in different terms */ - int ndupst; /* duplicate linear terms in the same term */ - int nlttot; /* total number of distinct linear terms */ - int ndvspcand; /* # of defined variable candidates for splitting */ - int ndvsplit; /* number of defined variables actually split */ - int ndvspin; /* number of incoming terms from split defined vars */ - int ndvspout; /* number of terms from split defined variables */ - int max_var1_; /* used in psedread and pshvread */ - int nv0_; /* used in psedread and pshvread */ - -#ifdef PSHVREAD - /* Stuff for partially separable Hessian computations... */ - /* These arrays are allocated and zero-initialized by hes_setup, */ - /* which also supplies the cei field to ranges. */ - - range **rtodo; /* rtodo[i] = ranges first incident on col i */ - uHeswork **utodo; /* unit ranges affecting this col */ - Hesoprod **otodo;/* otodo[i] = contributions to col i dispatched */ - /* by previous rtodo entries */ - Hesoprod *hop_free; - real *dOscratch;/* length = nmax (below) */ - int *iOscratch; /* length = nmax */ - Ihinfo *ihi; - Ihinfo *ihi1; /* first with positive count */ - int hes_setup_called; - int nmax; /* max{r in ranges} r->n */ - int ihdcur; /* Current max internal Hessian dimension, */ - /* set by hvpinit. */ - int ihdmax; /* max possible ihd */ - int ihdmin; /* min possible ihd > 0 and <= ihdmax, or 0 */ - int khesoprod; /* used in new_Hesoprod in sputhes.c */ - int pshv_g1; /* whether pshv_prod should multiply by g1 */ - int linmultr; /* linear common terms used in more than one range */ - int linhesfun; /* linear common terms in Hessian funnels */ - int nlmultr; /* nonlin common terms used in more than one range */ - int nlhesfun; /* nonlin common terms in Hessian funnels */ - int ncongroups; /* # of groups in constraints */ - int nobjgroups; /* # of groups in objectives */ - int nhvprod; /* # of Hessian-vector products at this Hessian */ - int npsgcomp; /* Has psgcomp been called? For sphes_setup. */ - expr_va *valist; /* for sphes_setup */ - expr_if *iflist; /* for sphes_setup */ - int *zlsave; /* for S->_zl */ - real *oyow; /* for xpsg_check */ - int onobj; /* for xpsg_check */ - int onxval; /* for xpsg_check */ - int nynz; /* for xpsg_check */ - int ndhmax; /* set by hvpinit_ASL */ -#endif /* PSHVREAD */ - split_ce *Split_ce; /* for sphes_setup */ - } ps_info; - -#ifdef PSHVREAD - - typedef struct -ASL_pfgh { - Edagpars p; - Edaginfo i; - Char *mblk_free[MBLK_KMAX]; - Edag2info I; - ps_info2 P; - } ASL_pfgh; - -#else - - typedef struct -ASL_pfg { - Edagpars p; - Edaginfo i; - Char *mblk_free[MBLK_KMAX]; - Edag1info I; - ps_info P; - } ASL_pfg; - -#endif /* PSHVREAD */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef PSINFO_H0_included -#define PSINFO_H0_included -typedef unsigned Long Ulong; - -#endif /* PSINFO_H0_included */ -#ifdef PSHVREAD - extern void duthes_ASL(ASL*, real *H, int nobj, real *ow, real *y); - extern void fullhes_ASL(ASL*, real*H, fint LH, int nobj, real*ow, real*y); - extern void hvpinit_ASL(ASL*, int ndhmax, int nobj, real *ow, real *y); - extern void ihd_clear_ASL(ASL_pfgh*); - extern ASL_pfgh *pscheck_ASL(ASL*, const char*); - extern void pshv_prod_ASL(ASL_pfgh*, range*r, int nobj, real*ow, real*y); - extern fint sphes_setup_ASL(ASL*, SputInfo**, int nobj, int ow, int y, int ul); - extern void sphes_ASL(ASL*, SputInfo**, real *H, int nobj, real*ow, real *y); - extern void xpsg_check_ASL(ASL_pfgh*, int nobj, real *ow, real *y); -#else /* PSHVREAD */ - extern void xp1known_ASL(ASL*, real*, fint*); -#endif /* PSHVREAD */ - -#ifdef __cplusplus - } -#endif - -#define pshv_prod(r,no,ow,y) pshv_prod_ASL(asl,r,no,ow,y) - -#endif /* PSINFO_H_included */ diff --git a/external/ipopt/include/coin/ThirdParty/r_opn.hd b/external/ipopt/include/coin/ThirdParty/r_opn.hd deleted file mode 100644 index 4c4f45668..000000000 --- a/external/ipopt/include/coin/ThirdParty/r_opn.hd +++ /dev/null @@ -1,16 +0,0 @@ -#undef f_OPNUM -#define f_OPMULT r_ops[2] -#define f_OPPOW r_ops[5] -#define f_MINLIST r_ops[11] -#define f_MAXLIST r_ops[12] -#define f_ABS r_ops[15] -#define f_OPPLTERM r_ops[64] -#define f_OPIFSYM r_ops[65] -#define f_OP1POW r_ops[76] -#define f_OP2POW r_ops[77] -#define f_OPCPOW r_ops[78] -#define f_OPFUNCALL r_ops[79] -#define f_OPNUM r_ops[80] -#define f_OPHOL r_ops[81] -#define f_OPVARVAL r_ops[82] -#define N_OPS 83 diff --git a/external/ipopt/include/coin/ThirdParty/stdio1.h b/external/ipopt/include/coin/ThirdParty/stdio1.h deleted file mode 100644 index ef2bb6344..000000000 --- a/external/ipopt/include/coin/ThirdParty/stdio1.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************** -Copyright (C) 1997-1999 Lucent Technologies -All Rights Reserved - -Permission to use, copy, modify, and distribute this software and -its documentation for any purpose and without fee is hereby -granted, provided that the above copyright notice appear in all -copies and that both that the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -****************************************************************/ - -/* stdio1.h -- for using Printf, Fprintf, Sprintf while - * retaining the system-supplied printf, fprintf, sprintf. - */ - -#ifndef STDIO1_H_included -#define STDIO1_H_included -#ifndef STDIO_H_included /* allow suppressing stdio.h */ -#include /* in case it's already included, */ -#endif /* e.g., by cplex.h */ - -#ifdef KR_headers -#ifndef _SIZE_T -#define _SIZE_T -typedef unsigned int size_t; -#endif -#define ANSI(x) () -#include "varargs.h" -#ifndef Char -#define Char char -#endif -#else -#define ANSI(x) x -#include "stdarg.h" -#ifndef Char -#define Char void -#endif -#endif - -#ifndef NO_STDIO1 - -#ifdef __cplusplus -extern "C" { -#endif - -extern int Fprintf ANSI((FILE*, const char*, ...)); -extern int Printf ANSI((const char*, ...)); -extern int Sprintf ANSI((char*, const char*, ...)); -extern int Snprintf ANSI((char*, size_t, const char*, ...)); -extern void Perror ANSI((const char*)); -extern int Vfprintf ANSI((FILE*, const char*, va_list)); -extern int Vsprintf ANSI((char*, const char*, va_list)); -extern int Vsnprintf ANSI((char*, size_t, const char*, va_list)); - -#ifdef PF_BUF -extern FILE *stderr_ASL; -extern void (*pfbuf_print_ASL) ANSI((char*)); -extern char *pfbuf_ASL; -extern void fflush_ASL ANSI((FILE*)); -#ifdef fflush -#define old_fflush_ASL fflush -#undef fflush -#endif -#define fflush fflush_ASL -#endif - -#ifdef __cplusplus - } -#endif - -#undef printf -#undef fprintf -#undef sprintf -#undef perror -#undef vfprintf -#undef vsprintf -#define printf Printf -#define fprintf Fprintf -#undef snprintf /* for MacOSX */ -#undef vsnprintf /* for MacOSX */ -#define snprintf Snprintf -#define sprintf Sprintf -#define perror Perror -#define vfprintf Vfprintf -#define vsnprintf Vsnprintf -#define vsprintf Vsprintf - -#endif /* NO_STDIO1 */ - -#endif /* STDIO1_H_included */ diff --git a/external/ipopt/lib/libcoinasl.a b/external/ipopt/lib/libcoinasl.a deleted file mode 100644 index 6020ca615..000000000 Binary files a/external/ipopt/lib/libcoinasl.a and /dev/null differ diff --git a/external/ipopt/lib/libcoinasl.la b/external/ipopt/lib/libcoinasl.la deleted file mode 100755 index 86a4d8391..000000000 --- a/external/ipopt/lib/libcoinasl.la +++ /dev/null @@ -1,35 +0,0 @@ -# libcoinasl.la - a libtool library file -# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06) -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='' - -# Names of this library. -library_names='' - -# The name of the static archive. -old_library='libcoinasl.a' - -# Libraries that this one depends upon. -dependency_libs=' -lm -ldl' - -# Version information for libcoinasl. -current=4 -age=3 -revision=6 - -# Is this an already installed library? -installed=yes - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/home/batman/one/external/ipopt/lib' diff --git a/external/ipopt/lib/libcoinblas.a b/external/ipopt/lib/libcoinblas.a deleted file mode 100644 index 6da34d448..000000000 Binary files a/external/ipopt/lib/libcoinblas.a and /dev/null differ diff --git a/external/ipopt/lib/libcoinblas.la b/external/ipopt/lib/libcoinblas.la deleted file mode 100755 index fe88c2a40..000000000 --- a/external/ipopt/lib/libcoinblas.la +++ /dev/null @@ -1,35 +0,0 @@ -# libcoinblas.la - a libtool library file -# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06) -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='' - -# Names of this library. -library_names='' - -# The name of the static archive. -old_library='libcoinblas.a' - -# Libraries that this one depends upon. -dependency_libs='' - -# Version information for libcoinblas. -current=5 -age=4 -revision=6 - -# Is this an already installed library? -installed=yes - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/home/batman/one/external/ipopt/lib' diff --git a/external/ipopt/lib/libcoinlapack.a b/external/ipopt/lib/libcoinlapack.a deleted file mode 100644 index f13ac6005..000000000 Binary files a/external/ipopt/lib/libcoinlapack.a and /dev/null differ diff --git a/external/ipopt/lib/libcoinlapack.la b/external/ipopt/lib/libcoinlapack.la deleted file mode 100755 index 179f768fc..000000000 --- a/external/ipopt/lib/libcoinlapack.la +++ /dev/null @@ -1,35 +0,0 @@ -# libcoinlapack.la - a libtool library file -# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06) -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='' - -# Names of this library. -library_names='' - -# The name of the static archive. -old_library='libcoinlapack.a' - -# Libraries that this one depends upon. -dependency_libs=' -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath' - -# Version information for libcoinlapack. -current=6 -age=5 -revision=6 - -# Is this an already installed library? -installed=yes - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/home/batman/one/external/ipopt/lib' diff --git a/external/ipopt/lib/libcoinmumps.a b/external/ipopt/lib/libcoinmumps.a deleted file mode 100644 index 33f27a8ac..000000000 Binary files a/external/ipopt/lib/libcoinmumps.a and /dev/null differ diff --git a/external/ipopt/lib/libcoinmumps.la b/external/ipopt/lib/libcoinmumps.la deleted file mode 100755 index 2077e9fec..000000000 --- a/external/ipopt/lib/libcoinmumps.la +++ /dev/null @@ -1,35 +0,0 @@ -# libcoinmumps.la - a libtool library file -# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06) -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='' - -# Names of this library. -library_names='' - -# The name of the static archive. -old_library='libcoinmumps.a' - -# Libraries that this one depends upon. -dependency_libs=' -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath' - -# Version information for libcoinmumps. -current=7 -age=6 -revision=0 - -# Is this an already installed library? -installed=yes - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/home/batman/one/external/ipopt/lib' diff --git a/external/ipopt/lib/libipopt.a b/external/ipopt/lib/libipopt.a deleted file mode 100644 index ac395579b..000000000 Binary files a/external/ipopt/lib/libipopt.a and /dev/null differ diff --git a/external/ipopt/lib/libipopt.la b/external/ipopt/lib/libipopt.la deleted file mode 100755 index 082328ec9..000000000 --- a/external/ipopt/lib/libipopt.la +++ /dev/null @@ -1,35 +0,0 @@ -# libipopt.la - a libtool library file -# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06) -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='' - -# Names of this library. -library_names='' - -# The name of the static archive. -old_library='libipopt.a' - -# Libraries that this one depends upon. -dependency_libs=' /home/batman/one/external/ipopt/lib/libcoinmumps.la -lgfortran -lquadmath -ldl' - -# Version information for libipopt. -current=11 -age=10 -revision=8 - -# Is this an already installed library? -installed=yes - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/home/batman/one/external/ipopt/lib' diff --git a/external/ipopt/lib/libipoptamplinterface.a b/external/ipopt/lib/libipoptamplinterface.a deleted file mode 100644 index 245e4c1ed..000000000 Binary files a/external/ipopt/lib/libipoptamplinterface.a and /dev/null differ diff --git a/external/ipopt/lib/libipoptamplinterface.la b/external/ipopt/lib/libipoptamplinterface.la deleted file mode 100755 index 6204a7b8d..000000000 --- a/external/ipopt/lib/libipoptamplinterface.la +++ /dev/null @@ -1,35 +0,0 @@ -# libipoptamplinterface.la - a libtool library file -# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06) -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='' - -# Names of this library. -library_names='' - -# The name of the static archive. -old_library='libipoptamplinterface.a' - -# Libraries that this one depends upon. -dependency_libs=' /home/batman/one/external/ipopt/lib/libipopt.la /home/batman/one/external/ipopt/lib/libcoinmumps.la -lgfortran -lquadmath /home/batman/one/external/ipopt/lib/libcoinasl.la -ldl' - -# Version information for libipoptamplinterface. -current=11 -age=10 -revision=8 - -# Is this an already installed library? -installed=yes - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/home/batman/one/external/ipopt/lib' diff --git a/external/ipopt/lib/pkgconfig/coinasl.pc b/external/ipopt/lib/pkgconfig/coinasl.pc deleted file mode 100644 index de4cb7811..000000000 --- a/external/ipopt/lib/pkgconfig/coinasl.pc +++ /dev/null @@ -1,11 +0,0 @@ -prefix=/home/batman/one/external/ipopt -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include/coin/ThirdParty - -Name: ASL -Description: AMPL Solver Library -URL: https://projects.coin-or.org/BuildTools -Version: 1.3.6 -Libs: -L${libdir} -lcoinasl -lm -ldl -Cflags: -I${includedir} diff --git a/external/ipopt/lib/pkgconfig/coinblas.pc b/external/ipopt/lib/pkgconfig/coinblas.pc deleted file mode 100644 index 7c4017519..000000000 --- a/external/ipopt/lib/pkgconfig/coinblas.pc +++ /dev/null @@ -1,10 +0,0 @@ -prefix=/home/batman/one/external/ipopt -exec_prefix=${prefix} -libdir=${exec_prefix}/lib - -Name: Blas -Description: Basic linear algebra package -URL: https://projects.coin-or.org/BuildTools -Version: 1.4.6 -Libs: -L${libdir} -lcoinblas -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath -Cflags: diff --git a/external/ipopt/lib/pkgconfig/coinlapack.pc b/external/ipopt/lib/pkgconfig/coinlapack.pc deleted file mode 100644 index 81f7f8957..000000000 --- a/external/ipopt/lib/pkgconfig/coinlapack.pc +++ /dev/null @@ -1,11 +0,0 @@ -prefix=/home/batman/one/external/ipopt -exec_prefix=${prefix} -libdir=${exec_prefix}/lib - -Name: Lapack -Description: Linear algebra package -URL: https://projects.coin-or.org/BuildTools -Version: 1.5.6 -Libs: -L${libdir} -lcoinlapack /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath -Cflags: -Requires: diff --git a/external/ipopt/lib/pkgconfig/coinmumps.pc b/external/ipopt/lib/pkgconfig/coinmumps.pc deleted file mode 100644 index 8505155a4..000000000 --- a/external/ipopt/lib/pkgconfig/coinmumps.pc +++ /dev/null @@ -1,12 +0,0 @@ -prefix=/home/batman/one/external/ipopt -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include/coin/ThirdParty - -Name: Mumps -Description: Multifrontal Massively Parallel sparse direct Solver -URL: https://projects.coin-or.org/BuildTools -Version: 1.6.0 -Libs: -L${libdir} -lcoinmumps /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath -Cflags: -I${includedir} -DCOIN_USE_MUMPS_MPI_H -Requires: diff --git a/external/ipopt/lib/pkgconfig/ipopt.pc b/external/ipopt/lib/pkgconfig/ipopt.pc deleted file mode 100644 index 18ea78a09..000000000 --- a/external/ipopt/lib/pkgconfig/ipopt.pc +++ /dev/null @@ -1,12 +0,0 @@ -prefix=/home/batman/one/external/ipopt -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include/coin - -Name: IPOPT -Description: Interior Point Optimizer -URL: https://projects.coin-or.org/Ipopt -Version: 3.12.8 -Libs: -L${libdir} -lipopt /home/batman/one/external/ipopt/lib/libcoinlapack.a /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lgfortran -lm -lquadmath -lm -ldl -Cflags: -I${includedir} -Requires: coinmumps diff --git a/external/ipopt/lib/pkgconfig/ipoptamplinterface.pc b/external/ipopt/lib/pkgconfig/ipoptamplinterface.pc deleted file mode 100644 index d760a552c..000000000 --- a/external/ipopt/lib/pkgconfig/ipoptamplinterface.pc +++ /dev/null @@ -1,12 +0,0 @@ -prefix=/home/batman/one/external/ipopt -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include/coin - -Name: IPOPT -Description: Ampl Interface TNLP to Ipopt -URL: https://projects.coin-or.org/Ipopt -Version: 3.12.8 -Libs: -L${libdir} -lipoptamplinterface -Cflags: -I${includedir} -Requires: ipopt coinasl diff --git a/external/ipopt/share/coin/doc/Ipopt/AUTHORS b/external/ipopt/share/coin/doc/Ipopt/AUTHORS deleted file mode 100644 index daeaab327..000000000 --- a/external/ipopt/share/coin/doc/Ipopt/AUTHORS +++ /dev/null @@ -1,133 +0,0 @@ -Main authors: - -Andreas Waechter, project leader (IBM) -Carl Laird (IBM, Carnegie Mellon University) - - -Contributors: - -- Yoshiaki Kawajiri (Carnegie Mellon Univeristy): - First version of Latex documentation file - - Docs/documentation.tex - -- Olaf Schenk (University of Basel): - Modifications to the PARDISO interface in the files - - Algorithm/LinearSolvers/IpPardisoSolverInterface.cpp - Algorithm/LinearSolvers/IpPardisoSolverInterface.hpp - -- Michael Hagemann (University of Basel): - MA57 interface - - Algorithm/LinearSolvers/IpMa57SolverInterface.cpp - Algorithm/LinearSolvers/IpMa57SolverInterface.hpp - -- Damien Hocking (KBC Advanced Technologies) - MUMPS interface - - Algorithm/LinearSolvers/IpMumpsSolverInterface.cpp - Algorithm/LinearSolvers/IpMumpsSolverInterface.hpp - -- Jon Lee (IBM Research) - example nl file (writting by hand) for unitTest - - Test/mytoy.nl - -- Peter Carbonetto (University of British Columbia) - Matlab interface files in directory (and subdirectories of) - - contrib/MatlabInterface - -- Rafael de Pelegrini Soares (VRTech Industrial Technologies) - and Tong Kewei (Beihang University, Beijing) - Java interface files in directory (and subdirectories of) - - contrib/JavaInterface - -- Lifeng Chen/Zaiwen Wen (Columbia University) - Changes and additions to the implementation of the Chen-Goldfarb - penalty function algorithm - - src/contrib/CGPenalty/IpCGPenaltyCq.cpp - src/contrib/CGPenalty/IpCGPenaltyCq.hpp - src/contrib/CGPenalty/IpCGPenaltyData.cpp - src/contrib/CGPenalty/IpCGPenaltyData.hpp - src/contrib/CGPenalty/IpCGPenaltyLSAcceptor.cpp - src/contrib/CGPenalty/IpCGPenaltyLSAcceptor.hpp - src/contrib/CGPenalty/IpCGPenaltyRegOp.cpp - src/contrib/CGPenalty/IpCGPenaltyRegOp.hpp - src/contrib/CGPenalty/IpCGPerturbationHandler.cpp - src/contrib/CGPenalty/IpCGPerturbationHandler.hpp - src/contrib/CGPenalty/IpCGSearchDirCalc.cpp - src/contrib/CGPenalty/IpCGSearchDirCalc.hpp - src/contrib/CGPenalty/IpPiecewisePenalty.cpp - src/contrib/CGPenalty/IpPiecewisePenalty.hpp - -- Stefan Vigerske (GAMS) - Dynamic loading of linear solver shared libraries - - src/contrib/LinearSolverLoader/HSLLoader.c - src/contrib/LinearSolverLoader/HSLLoader.h - src/contrib/LinearSolverLoader/LibraryHandler.c - src/contrib/LinearSolverLoader/LibraryHandler.h - src/contrib/LinearSolverLoader/PardisoLoader.c - src/contrib/LinearSolverLoader/PardisoLoader.h - -- Marcel Roelofs (AIMMS) - MSVC project files for Intel Fortran compiler, creating a DLL - - MSVisualStudio/v8-ifort - -- Jonathan Hogg (STFC Rutherford Appleton Laboratory) - MA77 interface - - src/Algorithm/LinearSolvers/hsl_ma77d.h - src/Algorithm/LinearSolvers/IpMa77SolverInterface.hpp - src/Algorithm/LinearSolvers/IpMa77SolverInterface.cpp - - MA86 interface - - src/Algorithm/LinearSolvers/hsl_ma86d.h - src/Algorithm/LinearSolvers/hsl_mc68i.h - src/Algorithm/LinearSolvers/IpMa86SolverInterface.hpp - src/Algorithm/LinearSolvers/IpMa86SolverInterface.cpp - - MA97 interface - - src/Algorithm/LinearSolvers/hsl_ma97d.h - src/Algorithm/LinearSolvers/IpMa97SolverInterface.hpp - src/Algorithm/LinearSolvers/IpMa97SolverInterface.cpp - -- Hans Pirnay (RWTH Aachen) - Rodrigo Lopez-Negrete (Carnegie Mellon University) - - Sensitivity Based on IPOPT - - contrib/sIPOPT (formerly called contrib/AsNMPC) - -- Jelmer Ypma (University College London) - R interface with examples, all files in directory (and subdirectory of) - - contrib/RInterface - -- Tony Kelman (Berkeley) - improvements to Matlab interface - - Ipopt/contrib/MatlabInterface - -- Gabriel Hackebeil - improved use compound component spaces - -- Nai-Yuan Chiang and Victor M. Zavala Tejeda (Argonne National Laboratory) - inertia free curvature test in solution of primal-dual system (full approach) - -Contributors of code that is no longer included in Ipopt distribution: - -- Yifan Hu (Wolfram): Contributed TAUCS interface, implemented in the files - - PDSystemImpl/PDFullSpace/IpTAUCSSolverInterface.hpp - PDSystemImpl/PDFullSpace/IpTAUCSSolverInterface.cpp - - [These files have been removed, since TAUCS is not supported] - diff --git a/external/ipopt/share/coin/doc/Ipopt/LICENSE b/external/ipopt/share/coin/doc/Ipopt/LICENSE deleted file mode 100644 index 16cc69a52..000000000 --- a/external/ipopt/share/coin/doc/Ipopt/LICENSE +++ /dev/null @@ -1,87 +0,0 @@ -Eclipse Public License - v 1.0 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - -a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and - -b) in the case of each subsequent Contributor: - -i) changes to the Program, and - -ii) additions to the Program; - -where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. - -"Contributor" means any person or entity that distributes the Program. - -"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. - -"Program" means the Contributions distributed in accordance with this Agreement. - -"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. - -2. GRANT OF RIGHTS - -a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. - -b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. - -c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. - -d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. - -3. REQUIREMENTS - -A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: - -a) it complies with the terms and conditions of this Agreement; and - -b) its license agreement: - -i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; - -ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; - -iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and - -iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. - -When the Program is made available in source code form: - -a) it must be made available under this Agreement; and - -b) a copy of this Agreement must be included with each copy of the Program. - -Contributors may not remove or alter any copyright notices contained within the Program. - -Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. - -For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. GENERAL - -If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. diff --git a/external/ipopt/share/coin/doc/Ipopt/README b/external/ipopt/share/coin/doc/Ipopt/README deleted file mode 100644 index 26d8bd0fd..000000000 --- a/external/ipopt/share/coin/doc/Ipopt/README +++ /dev/null @@ -1,14 +0,0 @@ -These directories contain the C++ reimplementation of the interior -point NLP solver Ipopt. - -For more inforamation, see - -Docs/documentation.pdf - -or see the online version of it at - -http://www.coin-or.org/Ipopt/documentation/ - -The project's website is at - -http://projects.coin-or.org/Ipopt diff --git a/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_c.txt b/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_c.txt deleted file mode 100644 index bffe36081..000000000 --- a/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_c.txt +++ /dev/null @@ -1 +0,0 @@ --L/home/batman/one/external/ipopt/lib -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/home/batman/one/external/ipopt/lib -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lipopt /home/batman/one/external/ipopt/lib/libcoinlapack.a /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -lm -lquadmath /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -lm -lquadmath -lm -ldl -lcoinmumps /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -lm -lquadmath -lgfortran -lm -lquadmath -lstdc++ -lm diff --git a/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_cpp.txt b/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_cpp.txt deleted file mode 100644 index 17f2c2bd7..000000000 --- a/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_cpp.txt +++ /dev/null @@ -1 +0,0 @@ --L/home/batman/one/external/ipopt/lib -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/home/batman/one/external/ipopt/lib -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lipopt /home/batman/one/external/ipopt/lib/libcoinlapack.a /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -lm -lquadmath /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -lm -lquadmath -lm -ldl -lcoinmumps /home/batman/one/external/ipopt/lib/libcoinblas.a -lgfortran -lm -lquadmath -lgfortran -lm -lquadmath diff --git a/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_f.txt b/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_f.txt deleted file mode 100644 index 5cafdf9ca..000000000 --- a/external/ipopt/share/coin/doc/Ipopt/ipopt_addlibs_f.txt +++ /dev/null @@ -1 +0,0 @@ - -L/home/batman/one/external/ipopt/lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/home/batman/one/external/ipopt/lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lipopt /home/batman/one/external/ipopt/lib/libcoinlapack.a /home/batman/one/external/ipopt/lib/libcoinblas.a /home/batman/one/external/ipopt/lib/libcoinblas.a -ldl -lcoinmumps /home/batman/one/external/ipopt/lib/libcoinblas.a -lquadmath -lstdc++ -lm