Codebase list cppad / 2ddf424
New upstream version 2022.00.00.4 Barak A. Pearlmutter 1 year, 9 months ago
332 changed file(s) with 17944 addition(s) and 15646 deletion(s). Raw diff Collapse all Expand all
298298 <!-- appear. These must *NOT* be uncommented unless -->
299299 <!-- needed. -->
300300
301 <stableVersionNumber>20210000</stableVersionNumber>
302 <releaseNumber>20210000.0</releaseNumber>
301 <stableVersionNumber>20220000</stableVersionNumber>
302 <releaseNumber>20220000.0</releaseNumber>
303303
304304 </developmentStatus>
305305
0 name: Linux Github Actions
1 on:
2 pull_request:
3 push:
4 branches:
5 - master
6 jobs:
7 learn-actions:
8 runs-on: ${{ matrix.os }}
9 strategy:
10 matrix:
11 os: [ ubuntu-latest, macos-latest ]
12 steps:
13 - name: Check out repository code
14 uses: actions/checkout@v2
15 - name: set debug_which
16 run: |
17 mkdir build
18 cd build
19 set +e
20 random_03=$(expr $RANDOM % 4)
21 set -e
22 case $random_03 in
23 0) debug_which='debug_all'
24 ;;
25 1) debug_which='debug_even'
26 ;;
27 2) debug_which='debug_odd'
28 ;;
29 3) debug_which='debug_none'
30 ;;
31 esac
32 echo "$debug_which" > debug_which
33 - name: run cmake
34 run: |
35 cd build
36 debug_which=$(cat debug_which)
37 echo "cmake -D cppad_debug_which=$debug_which" ..
38 cmake -D cppad_debug_which=$debug_which ..
39 - name: run make check
40 run: |
41 cd build
42 if which nproc >& /dev/null
43 then
44 n_job=$(nproc)
45 else
46 n_job=$(sysctl -n hw.ncpu)
47 fi
48 echo "make -j $n_job check"
49 make -j $(nproc) check
50 - run: echo "job.status = ${{ job.status }}"
2727 # vim swap files in any directory
2828 *.swp
2929 # ----------------------------------------------------------------------------
30 # junk and temp files in any directory
31 junk
32 junk.*
30 # temp files in any directory
3331 temp
3432 temp.*
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1111 # =============================================================================
1212 # Some constants
1313 # =============================================================================
14 # Suppress warnging that WIN32 not defined on cygwin
15 SET(CMAKE_LEGACY_CYGWIN_WIN32 0) # remove when version below >= 2.8.4
1614 #
1715 # Set the minimum required version of cmake for this project.
1816 # see http://www.cmake.org/pipermail/cmake/2013-January/053213.html
19 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4)
20 #
21 # https://gitlab.kitware.com/cmake/cmake/issues/17292
22 if(POLICY CMP0054)
23 cmake_policy(SET CMP0054 NEW)
24 endif()
17 CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
18 #
19 # Only interpret if() arguments as variables or keywords when unquoted.
20 IF( POLICY CMP0054 )
21 CMAKE_POLICY(SET CMP0054 NEW)
22 ENDIF( POLICY CMP0054 )
2523 #
2624 # cppad_version is used by version.sh to get the version number.
27 SET(cppad_version "20210000.8")
25 SET(cppad_version "20220000.4")
2826 SET(cppad_url "https://coin-or.github.io/CppAD" )
2927 SET(cppad_description "Differentiation of C++ Algorithms" )
3028 #
4644 # return zero status. You can set
4745 # CMAKE_REQUIRED_LIBRARIES, CMAKE_REQUIRED_FLAGS and CMAKE_REQUIRED_INCLUDES
4846 # accordingly if additional libraries or compiler flags are required.
49 INCLUDE(CheckCXXSourceRuns)
50
47 INCLUDE(CheckCXXSourceCompiles)
5148 # ============================================================================
5249 # Some local cmake language
5350 # ============================================================================
6663 # optional_package(package description)
6764 INCLUDE(cmake/optional_package.cmake)
6865 #
69 # run_source_test(source variable)
70 INCLUDE(cmake/run_source_test.cmake)
66 # compile_source_test(source variable)
67 INCLUDE(cmake/compile_source_test.cmake)
7168 #
7269 # assert(variable)
7370 INCLUDE(cmake/assert.cmake)
8178 # pkgconfig_info(name, system)
8279 INCLUDE(cmake/pkgconfig_info.cmake)
8380 # ============================================================================
84 # Check for c++11
81 # Ensure c++11 support
82 SET(CMAKE_REQUIRED_DEFINITIONS "")
83 SET(CMAKE_REQUIRED_FLAGS "")
84 SET(CMAKE_REQUIRED_INCLUDES "")
85 SET(CMAKE_REQUIRED_LIBRARIES "")
8586 SET(source "
8687 int main(void)
87 { if( __cplusplus < 201103 )
88 return 1;
88 { static_assert( __cplusplus >= 201103 , \"c++11 or higher required\" );
8989 return 0;
9090 }"
9191 )
92 run_source_test("${source}" cppad_cplusplus_201100_ok )
93 IF( NOT cppad_cplusplus_201100_ok )
92 compile_source_test("${source}" cplusplus_201100_ok )
93 IF( NOT cplusplus_201100_ok )
9494 SET(CMAKE_CXX_STANDARD 11)
9595 SET(CMAKE_CXX_STANDARD_REQUIRED ON)
96 ENDIF( NOT cppad_cplusplus_201100_ok )
96 ENDIF( NOT cplusplus_201100_ok )
9797 # =============================================================================
9898 # command line arguments
9999 # =============================================================================
181181 command_line_arg(cppad_max_num_threads 48 STRING
182182 "maximum number of threads that CppAD can use use"
183183 )
184 IF( "${cppad_max_num_threads}" LESS "4" )
185 MESSAGE(FATAL_ERROR
186 "cppad_max_num_threads is not an integer greater than or equal 4"
187 )
188 ENDIF( "${cppad_max_num_threads}" LESS "4" )
184189 #
185190 # cppad_tape_id_type
186191 command_line_arg(cppad_tape_id_type "unsigned int" STRING
193198 )
194199 #
195200 # cppad_debug_which
196 command_line_arg(cppad_debug_which "debug_all" STRING
197 "debug_even, debug_odd, debug_all, or debug_none"
198 )
199 assert_value_in_set(cppad_debug_which debug_even debug_odd debug_all debug_none)
201 # CMAKE_BUILD_TYPE
202 IF( NOT debug_which )
203 SET(debug_which "" CACHE STRING
204 "debug_even, debug_odd, debug_all, debug_none, or empty string"
205 )
206 ENDIF( NOT debug_which )
207 IF( NOT ${cppad_debug_which} STREQUAL "" )
208 assert_value_in_set(
209 cppad_debug_which debug_even debug_odd debug_all debug_none
210 )
211 ENDIF( NOT ${cppad_debug_which} STREQUAL "" )
212 IF( CMAKE_BUILD_TYPE )
213 IF( NOT ${cppad_debug_which} STREQUAL "" )
214 print_variable(CMAKE_BUILD_TYPE)
215 print_variable(cppad_debug_which)
216 MESSAGE(FATAL_ERROR
217 "Both CMAKE_BUILD_TYPE and cppad_debug_which specified"
218 )
219 ENDIF( NOT ${cppad_debug_which} STREQUAL "" )
220 ELSE( CMAKE_BUILD_TYPE )
221 IF( "${cppad_debug_which}" STREQUAL debug_all)
222 SET(CMAKE_BUILD_TYPE Debug)
223 ELSEIF( "${cppad_debug_which}" STREQUAL debug_none)
224 SET(CMAKE_BUILD_TYPE Release)
225 ELSEIF( "${cppad_debug_which}" STREQUAL debug_odd)
226 SET(CMAKE_BUILD_TYPE Debug)
227 ELSEIF( "${cppad_debug_which}" STREQUAL debug_even)
228 SET(CMAKE_BUILD_TYPE Release)
229 ENDIF( "${cppad_debug_which}" STREQUAL debug_all)
230 ENDIF( CMAKE_BUILD_TYPE )
231 print_variable(cppad_debug_which)
232 print_variable(CMAKE_BUILD_TYPE)
200233 #
201234 # include_eigen
202235 # include_adolc
215248 # -----------------------------------------------------------------------------
216249 # External package information
217250 SET(system_include TRUE)
251 SET(remove_coin_or FALSE)
218252 #
219253 # eigen
220254 IF( include_eigen )
221 pkgconfig_info(eigen3 ${system_include})
255 pkgconfig_info(eigen3 ${system_include} ${remove_coin_or})
222256 SET(eigen_LIBRARIES "${eigen3_LIBRARIES}")
223257 SET(cppad_has_eigen 1)
224258 ELSE( include_eigen )
227261 #
228262 # adolc
229263 IF( include_adolc )
230 pkgconfig_info(adolc ${system_include})
264 pkgconfig_info(adolc ${system_include} ${remove_coin_or})
231265 SET(cppad_has_adolc 1)
232266 ELSE( include_adolc )
233267 SET(cppad_has_adolc 0)
235269 #
236270 # ipopt
237271 IF( include_ipopt )
238 pkgconfig_info(ipopt ${system_include})
272 SET(remove_coin_or TRUE)
273 pkgconfig_info(ipopt ${system_include} ${remove_coin_or})
239274 SET(cppad_has_ipopt 1)
275 SET(remove_coin_or FALSE)
240276 ELSE( include_ipopt )
241277 SET(cppad_has_ipopt 0)
242278 ENDIF( include_ipopt )
243279 #
244280 # cppadcg
245281 IF( include_cppadcg )
282 # Assume bin/get_cppadcg.sh puts include files in this directory
283 SET(cppadcg_include_dir "${CMAKE_BINARY_DIR}/prefix/include" )
284 print_variable(cppadcg_include_dir)
285 INCLUDE_DIRECTORIES( SYSTEM ${cppadcg_include_dir})
246286 SET(cppad_has_cppadcg 1)
247287 ELSE( include_cppadcg )
248288 SET(cppad_has_cppadcg 0)
257297 # fadbad_prefix
258298 optional_package(fadbad ${system_include} "fadbad install prefix")
259299 #
260 # xpackage_prefix is an example package prefix that is not really used
261 SET(xpackage_prefix "/usr")
262 # -----------------------------------------------------------------------------
263300 # =============================================================================
264301 # cppad_lib
265302 # Perhaps in the future cppad_lib will depend on cmake header only flag ?
277314 # automated system configuration
278315 # =============================================================================
279316 # CMAKE_CXX_FLAGS
280 IF( "${debug_which}" STREQUAL "debug_all" )
317 IF( "${cppad_debug_which}" STREQUAL "debug_all" )
281318 print_variable(CMAKE_CXX_FLAGS_DEBUG)
282 ELSEIF( "${debug_which}" STREQUAL "debug_none" )
319 ELSEIF( "${cppad_debug_which}" STREQUAL "debug_none" )
283320 print_variable(CMAKE_CXX_FLAGS_RELEASE)
284 ELSE( "${debug_which}" )
321 ELSE( "${cppad_debug_which}" )
285322 print_variable(CMAKE_CXX_FLAGS_DEBUG)
286323 print_variable(CMAKE_CXX_FLAGS_RELEASE)
287 ENDIF( "${debug_which}" STREQUAL "debug_all" )
324 ENDIF( "${cppad_debug_which}" STREQUAL "debug_all" )
288325 # -----------------------------------------------------------------------------
289326 # cppad_abs_includedir, cppad_abs_libdir, cppad_abs_datadir, cppad_abs_docdir
290327 #
435472 # During install copy all the cppad include files to
436473 # ${cppad_abs_includedir}/cppad
437474 INSTALL(
438 DIRECTORY "${CMAKE_SOURCE_DIR}/include/cppad/"
475 DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/cppad/"
439476 DESTINATION ${cppad_abs_includedir}/cppad
440477 FILES_MATCHING PATTERN "*.hpp" PATTERN "omh" EXCLUDE
441478 )
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1212 # build platform, i.e. x86, x64, Any CPU. This setting is optional.
1313 platform:
1414 - x64
15
16 # branches to build on push
17 branches:
18 only:
19 - master
1520
1621 # msys2 environment
1722 environment:
1616 # '
1717 # list of files and or directories that are moved to new names
1818 # move_paths='
19 # cppad_lib/compiled_fun.cpp
20 # example/compiled_fun
21 # include/cppad/example/compiled_fun.hpp
19 # example/atomic_three/vector_math.cpp
2220 # '
2321 # list of sed commands that map old file and directory names to new names.
2422 # The characters @s, @d, @n get converted to a space, dollar sign, new line.
2523 # move_seds='
26 # s|compiled_fun|code_gen_fun|g
24 # s|vector_math|vector_op|
2725 # '
2826 # list of files that get edited by the extra_seds command
2927 # extra_files='
3533 # '
3634 # ----------------------------------------------------------------------------
3735 # Put other sed commands below here and without # at start of line
38 s|compiled_fun|code_gen_fun|g
39 s|COMPILED_FUN|CODE_GEN_FUN|g
36 s|vector_math, |vector_op, |
37 s|vector_math" |vector_op" |
38 s|vector_math|vector_op|
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
1616 fi
1717 if [ "$1" != 'make' ] && [ "$1" != 'test_one' ]
1818 then
19 echo 'usage: bin/travis.sh (make|test_one) target1 target2 ...'
19 echo 'usage: bin/appveyor.sh (make|test_one) target1 target2 ...'
2020 echo 'target: if make specified, is one of the available make commands'
2121 echo if test_one, specified, is the path to a test file.
2222 exit 1
4242 -D CMAKE_CXX_COMPILER=g++ \
4343 ..
4444 # -----------------------------------------------------------------------------
45 # Microsoft DLLs must be in current directory or execution path
46 PATH="$PATH:$(pwd)/cppad_lib"
47 # -----------------------------------------------------------------------------
48 # build target1, target2, ...
4549 if [ "$cmd" == 'make' ]
4650 then
4751 shift
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
1111 # -----------------------------------------------------------------------------
1212 if [ "$0" != 'bin/check_addon.sh' ]
1313 then
14 echo "bin/check_addon: must be executed from its parent directory"
14 echo "bin/check_addon.sh: must be executed from its parent directory"
1515 exit 1
1616 fi
1717 # -----------------------------------------------------------------------------
7171 exit 1
7272 fi
7373 check_all_warn
74 # ignore CMake Warning about old CMAKE_MINIMUM_REQUIRED
75 count=$( sed -e '/^CMake Deprecation Warning/d' -e '/^ *$/d' \
76 $top_srcdir/check_all.warn | \
77 wc -l | sed -e 's|^\([0-9]*\) .*|\1|'
78 )
74 count=`wc -l $top_srcdir/check_all.warn | sed -e 's|^\([0-9]*\) .*|\1|'`
7975 if [ "$count" != '0' ]
8076 then
8177 head "$top_srcdir/check_all.warn"
205201 fi
206202 # ---------------------------------------------------------------------------
207203 # Run automated checks for the form bin/check_*.sh with a few exceptions.
208 list=`ls bin/check_* | sed \
204 list=$(
205 ls bin/check_* | sed \
209206 -e '/check_all.sh/d' \
210207 -e '/check_jenkins.sh/d' \
211 -e '/check_doxygen.sh/d'`
208 -e '/check_doxygen.sh/d' \
209 -e '/check_install.sh/d'
210 )
212211 # ~/devel/check_copyright.sh not included in batch_edit branch
213212 for check in $list
214213 do
223222 echo_log_eval rm -rf cppad-$version
224223 echo_log_eval tar -xzf $tarball
225224 echo_log_eval cd cppad-$version
226 # -----------------------------------------------------------------------------
227 # run_cmake.sh with proper prefix
228 echo_log "sed -i bin/get_optional.sh -e 's|^prefix=.*|prefix=$prefix|'"
229 sed -i bin/get_optional.sh -e "s|^prefix=.*|prefix=$prefix|"
225 mkdir build
226 echo_log_eval cp -r ../prefix build/prefix
227 # -----------------------------------------------------------------------------
228 # run_cmake.sh
229 # prefix is extracted from bin/get_optional
230230 echo_log_eval bin/run_cmake.sh \
231231 --profile_speed \
232232 $compiler \
325325 exit 1
326326 fi
327327 #
328 # ---------------------------------------------------------------------------
329 # check install
328330 echo_log_eval make install
331 echo_log_eval cd ..
332 echo_log_eval bin/check_install.sh
333 # ---------------------------------------------------------------------------
329334 #
330335 echo "date >> check_all.log"
331336 date | sed -e 's|^|date: |' >> $top_srcdir/check_all.log
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
1111 # -----------------------------------------------------------------------------
1212 if [ "$0" != 'bin/check_if.sh' ]
1313 then
14 echo "bin/check_if: must be executed from its parent directory"
14 echo "bin/check_if.sh: must be executed from its parent directory"
1515 exit 1
1616 fi
1717 # -----------------------------------------------------------------------------
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
5050 sed \
5151 -e '1,1s|^|include/cppad/configure.hpp\n|' \
5252 -e '1,1s|^|include/cppad/local/is_pod.hpp\n|' \
53 -e '/include\/cppad\/local\/prototype_op.hpp/d' \
54 -e '/include\/cppad\/local\/optimize\/define_prototype.hpp/d' \
53 -e '/include\/cppad\/local\/op\/prototype_op.hpp/d' \
5554 -e '/include\/cppad\/example\/eigen_plugin.hpp/d' | \
5655 sed -e 's|^include/||' | \
5756 sort -u > check_include_file.3.$$
0 #! /bin/bash -e
1 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
3 #
4 # CppAD is distributed under the terms of the
5 # Eclipse Public License Version 2.0.
6 #
7 # This Source Code may also be made available under the following
8 # Secondary License when the conditions for such availability set forth
9 # in the Eclipse Public License, Version 2.0 are satisfied:
10 # GNU General Public License, Version 2.0 or later.
11 # -----------------------------------------------------------------------------
12 if [ $0 != 'bin/check_install.sh' ]
13 then
14 echo 'bin/check_install.sh: must be executed from its parent directory'
15 exit 1
16 fi
17 # -----------------------------------------------------------------------------
18 # bash function that echos and executes a command
19 echo_eval() {
20 echo $*
21 eval $*
22 }
23 # -----------------------------------------------------------------------------
24 # prefix
25 eval `grep '^prefix=' bin/get_optional.sh`
26 if [[ "$prefix" =~ ^[^/] ]]
27 then
28 prefix="$(pwd)/$prefix"
29 fi
30 # -----------------------------------------------------------------------------
31 PKG_CONFIG_PATH="$prefix/share/pkgconfig"
32 LD_LIBRARY_PATH=""
33 for dir in lib lib64
34 do
35 PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$prefix/$dir/pkgconfig"
36 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$prefix/$dir"
37 done
38 # dir=$(pkg-config cppad --variable pcfiledir)
39 # cat $dir/cppad.pc
40 # -----------------------------------------------------------------------------
41 # cflags
42 # libs
43 cflags=$(pkg-config cppad --cflags)
44 libs=$(pkg-config cppad --libs)
45 # -----------------------------------------------------------------------------
46 if [ ! -e build/check_install ]
47 then
48 mkdir build/check_install
49 fi
50 cd build/check_install
51 # -----------------------------------------------------------------------------
52 # CppAD get_started
53 cp ../../example/get_started/get_started.cpp get_started.cpp
54 echo_eval g++ $cflags $libs get_started.cpp -o get_started
55 echo 'CppAD: ./get_started'
56 if ! ./get_started
57 then
58 echo "check_install.sh: $(pwd)/get_started test failed."
59 exit 1
60 fi
61 # -----------------------------------------------------------------------------
62 # ipopt_solve get_started
63 cp ../../example/ipopt_solve/get_started.cpp get_started.cpp
64 cat << EOF >> get_started.cpp
65 int main(void)
66 { if( ! get_started() )
67 return 1;
68 return 0;
69 }
70 EOF
71 echo_eval g++ $cflags $libs get_started.cpp -o get_started
72 echo 'ipopt_solve: ./get_started'
73 if ! ./get_started
74 then
75 echo "check_install.sh: $(pwd)/get_started test failed."
76 exit 1
77 fi
78 # -----------------------------------------------------------------------------
79 echo 'check_install.sh: OK'
80 exit 0
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
1111 # -----------------------------------------------------------------------------
1212 if [ "$0" != 'bin/check_tab.sh' ]
1313 then
14 echo "bin/check_tab: must be executed from its parent directory"
14 echo "bin/check_tab.sh: must be executed from its parent directory"
1515 exit 1
1616 fi
1717 echo "-------------------------------------------------------"
2222 # Names that begin with a / are relative to top source directroy.
2323 # All other names are relavie paths somewhere below the top source directory.
2424 ignore_files='
25 /.github/workflows/
2526 /.gitignore
2627 /.coin-or/projDesc.xml
2728
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
7878 web_page='https://github.com/coin-or/ADOL-C.git'
7979 cppad_dir=`pwd`
8080 # -----------------------------------------------------------------------------
81 # n_job
82 if which nproc > /dev/null
83 then
84 n_job=$(nproc)
85 else
86 n_job=$(sysctl -n hw.ncpu)
87 fi
88 # ----------------------------------------------------------------------------
8189 # prefix
8290 eval `grep '^prefix=' bin/get_optional.sh`
8391 if [[ "$prefix" =~ ^[^/] ]]
92100 then
93101 echo "Skipping configuration because $configured_flag exits"
94102 echo_eval cd external/$package.git/build
95 echo_eval make install
103 echo_eval make -j $n_job install
96104 echo "get_$package.sh: OK"
97105 exit 0
98106 fi
135143 flags="$flags --enable-static --enable-shared --enable-atrig-erf"
136144 #
137145 echo_eval ../configure $flags
138 echo_eval make install
146 echo_eval make -j $n_job install
139147 # -----------------------------------------------------------------------------
140148 echo_eval touch $cppad_dir/$configured_flag
141149 echo "get_$package: OK"
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
7171 web_page='https://github.com/CSCsw/ColPack.git'
7272 cppad_dir=`pwd`
7373 # -----------------------------------------------------------------------------
74 # libtoolize is brain dead and puts these files in cppad_dir
75 for file in ltmain.sh test-driver
76 do
77 if [ -e $cppad_dir/$file ]
78 then
79 echo "get_colpack.sh: did not expect $file in $cppad_dir"
80 exit 1
81 fi
82 done
83 # -----------------------------------------------------------------------------
84 # n_job
85 if which nproc > /dev/null
86 then
87 n_job=$(nproc)
88 else
89 n_job=$(sysctl -n hw.ncpu)
90 fi
91 # ----------------------------------------------------------------------------
7492 # prefix
7593 eval `grep '^prefix=' bin/get_optional.sh`
7694 if [[ "$prefix" =~ ^[^/] ]]
85103 then
86104 echo "Skipping configuration because $configured_flag exits"
87105 echo_eval cd external/$package.git
88 echo_eval make install
106 echo_eval make -j $n_job install
89107 echo "get_$package.sh: OK"
90108 exit 0
91109 fi
132150 $lib_type
133151 #
134152 echo_eval touch $cppad_dir/$configured_flag
135 echo_eval make install
153 echo_eval make -j $n_job install
154 # -----------------------------------------------------------------------------
155 # libtoolize is brain dead and puts these files in cppad_dir
156 for file in ltmain.sh test-driver
157 do
158 if [ ! -e $cppad_dir/$file ]
159 then
160 echo "get_colpack.sh: expected libtooize to create $cppad_dir/$file"
161 exit 1
162 fi
163 rm $cppad_dir/$file
164 done
136165 # -----------------------------------------------------------------------------
137166 echo "get_$package: OK"
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
8686 web_page='https://github.com/joaoleal/CppADCodeGen.git'
8787 cppad_repo=$(pwd)
8888 # -----------------------------------------------------------------------------
89 # n_job
90 if which nproc > /dev/null
91 then
92 n_job=$(nproc)
93 else
94 n_job=$(sysctl -n hw.ncpu)
95 fi
96 # ----------------------------------------------------------------------------
8997 # prefix
9098 eval `grep '^prefix=' bin/get_optional.sh`
9199 if [[ "$prefix" =~ ^[^/] ]]
100108 then
101109 echo "Skipping configuration because $configured_flag exits"
102110 echo_eval cd external/$package.git/build
103 echo_eval make install
111 echo_eval make -j $n_job install
104112 echo "get_$package.sh: OK"
105113 exit 0
106114 fi
133141 fi
134142 echo_eval cd $package.git
135143 # -----------------------------------------------------------------------------
136 # 2DO: get following code into CppADCodeGen
137 # Must modify FindCppAD.cmake so can used git repository
144 # Modify FindCppAD.cmake so can use git repository
138145 # version of CppAD (not yet installed).
139146 cat << EOF > get_cppadcg.sed
140147 s|IF *( *DEFINED *CPPAD_HOME *)|IF (DEFINED CPPAD_GIT_REPO)\\
194201 -D GOOGLETEST_GIT=ON \
195202 -D CREATE_DOXYGEN_DOC=OFF \
196203 ..
197 echo_eval make install
204 echo_eval make -j $n_job install
198205 # -----------------------------------------------------------------------------
199206 echo_eval touch $cppad_repo/$configured_flag
200207 echo "get_$package.sh: OK"
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
6969 web_page='https://gitlab.com/libeigen/$package.git'
7070 cppad_dir=`pwd`
7171 # -----------------------------------------------------------------------------
72 # n_job
73 if which nproc > /dev/null
74 then
75 n_job=$(nproc)
76 else
77 n_job=$(sysctl -n hw.ncpu)
78 fi
79 # ----------------------------------------------------------------------------
7280 # prefix
7381 eval `grep '^prefix=' bin/get_optional.sh`
7482 if [[ "$prefix" =~ ^[^/] ]]
8391 then
8492 echo "Skipping configuration because $configured_flag exits"
8593 echo_eval cd external/$package.git/build
86 echo_eval make install
94 echo_eval make -j $n_job install
8795 if [ -e $prefix/include/Eigen ]
8896 then
8997 echo_eval rm $prefix/include/Eigen
113121 fi
114122 echo_eval cd build
115123 echo_eval cmake .. -DCMAKE_INSTALL_PREFIX=$prefix
116 echo_eval make install
124 echo_eval make -j $n_job install
117125 if [ -e $prefix/include/Eigen ]
118126 then
119127 echo_eval rm $prefix/include/Eigen
1414 name='highlight'
1515 if [ "$0" != "bin/get_$name.sh" ]
1616 then
17 echo "get_$name.sh should be in the ./bin directory and executed using"
17 echo "get_$name.sh should be in the ./bin directory and executed using"
1818 echo "bin/get_$name.sh"
1919 exit 1
20 fi
21 # -----------------------------------------------------------------------------
22 # n_proc
23 if which nproc >& /dev/null
24 then
25 n_job=$(nproc)
26 else
27 n_job=$(sysctl -n hw.ncpu)
2028 fi
2129 # -----------------------------------------------------------------------------
2230 if [ ! -e build ]
4149 echo_eval cd build
4250 #
4351 echo_eval ../configure --prefix="$start_dir/build/prefix"
44 echo_eval make install
52 echo_eval make -j $n_job install
4553 # -----------------------------------------------------------------------------
4654 echo "get_$name.sh: OK"
4755 exit 1
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
7676 coinbrew='https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew'
7777 cppad_dir=`pwd`
7878 # -----------------------------------------------------------------------------
79 # n_proc
80 if which nproc >& /dev/null
81 then
82 n_job=$(nproc)
83 else
84 n_job=$(sysctl -n hw.ncpu)
85 fi
86 # -----------------------------------------------------------------------------
7987 # prefix
8088 eval `grep '^prefix=' bin/get_optional.sh`
8189 if [[ "$prefix" =~ ^[^/] ]]
9098 then
9199 echo "Skipping configuration because $configured_flag exits"
92100 echo_eval cd external
93 ./coinbrew install Ipopt --no-prompt
101 ./coinbrew -j $n_job install Ipopt --no-prompt
94102 echo "get_$package.sh: OK"
95103 exit 0
96104 fi
125133 ADD_FCFLAGS=''
126134 fi
127135 # -----------------------------------------------------------------------------
128 echo_eval ./coinbrew build Ipopt@$version \
136 echo_eval ./coinbrew -j $n_job build Ipopt@$version \
129137 --prefix=$prefix --test --no-prompt --verbosity=3 $ADD_FCFLAGS
130 echo_eval ./coinbrew install Ipopt@$version \
138 echo_eval ./coinbrew -j $n_job install Ipopt@$version \
131139 --no-prompt
132140 # -----------------------------------------------------------------------------
133141 echo_eval touch $cppad_dir/$configured_flag
1414 name='omhelp'
1515 if [ "$0" != "bin/get_$name.sh" ]
1616 then
17 echo "get_$name.sh should be in the ./bin directory and executed using"
17 echo "get_$name.sh should be in the ./bin directory and executed using"
1818 echo "bin/get_$name.sh"
1919 exit 1
20 fi
21 # -----------------------------------------------------------------------------
22 # n_proc
23 if which nproc >& /dev/null
24 then
25 n_job=$(nproc)
26 else
27 n_job=$(sysctl -n hw.ncpu)
2028 fi
2129 # -----------------------------------------------------------------------------
2230 if [ ! -e build ]
5159 echo "get_$name.sh: aborting due to cmake command warnings"
5260 exit 1
5361 fi
54 echo_eval make install
62 echo_eval make -j $n_job install
5563 # -----------------------------------------------------------------------------
5664 echo "get_$name.sh: OK"
5765 exit 1
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
7373 web_page='https://github.com/trilinos/Trilinos.git'
7474 cppad_dir=`pwd`
7575 # -----------------------------------------------------------------------------
76 # n_job
77 if which nproc > /dev/null
78 then
79 n_job=$(nproc)
80 else
81 n_job=$(sysctl -n hw.ncpu)
82 fi
83 # ----------------------------------------------------------------------------
7684 # prefix
7785 eval `grep '^prefix=' bin/get_optional.sh`
7886 if [[ "$prefix" =~ ^[^/] ]]
8795 then
8896 echo "Skipping configuration because $configured_flag exits"
8997 echo_eval cd external/trilinos.git/build
90 echo_eval make install
98 echo_eval make -j $n_job install
9199 echo "get_$package.sh: OK"
92100 exit 0
93101 fi
131139 -D CMAKE_INSTALL_PREFIX:PATH=$prefix \
132140 -D Trilinos_INSTALL_LIB_DIR=$prefix/$libdir \
133141 ..
134 echo_eval make install
142 echo_eval make -j $n_job install
135143 # -----------------------------------------------------------------------------
136144 echo_eval touch $cppad_dir/$configured_flag
137145 echo "get_$package.sh: OK"
0 #! /bin/bash -e
1 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
3 #
4 # CppAD is distributed under the terms of the
5 # Eclipse Public License Version 2.0.
6 #
7 # This Source Code may also be made available under the following
8 # Secondary License when the conditions for such availability set forth
9 # in the Eclipse Public License, Version 2.0 are satisfied:
10 # GNU General Public License, Version 2.0 or later.
11 # -----------------------------------------------------------------------------
12 if [ "$0" != 'bin/master_revert.sh' ]
13 then
14 echo "bin/master_revert.sh: must be executed from its parent directory"
15 exit 1
16 fi
17 # -----------------------------------------------------------------------------
18 branch=$(git branch | sed -n '/^[*]/p' | sed -e 's/[*] *//')
19 list=$(
20 git diff master $branch | \
21 sed -n -e '/^diff --git/p' | \
22 sed -e 's|^diff --git a/||' -e 's| b/|@|'
23 )
24 for pair in $list
25 do
26 master_file=$(echo $pair | sed -e 's|@.*||')
27 branch_file=$(echo $pair | sed -e 's|[^@]*@||')
28 if [ "$master_file" == "$branch_file" ]
29 then
30 echo "reverting $master_file"
31 git show master:$master_file > $branch_file
32 else
33 echo 'skipping move of'
34 echo "$master_file -> $branch_file"
35 fi
36 done
37 echo 'master_revert.sh: OK'
38 exit 0
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
99 # in the Eclipse Public License, Version 2.0 are satisfied:
1010 # GNU General Public License, Version 2.0 or later.
1111 # -----------------------------------------------------------------------------
12 stable_version='20210000' # date at which this stable branch started
13 release='1' # first release for each stable version is 0
12 stable_version='20220000' # date at which this stable branch started
13 release='0' # first release for each stable version is 0
1414 # -----------------------------------------------------------------------------
1515 # bash function that echos and executes a command
1616 echo_eval() {
144144 then
145145 cat << EOF
146146 bin/new_release.sh: version number is not correct in $stable_branch.
147 Use the following commands in $stable_branch to fix it ?
147 Currently in $stable_branch branch, use following to fix it ?
148148 git fetch
149149 version.sh set $stable_version.$release
150150 version.sh copy
151151 version.sh check
152 bin/autotools.sh automake
153152 Then check the chages to the $stable_branch branch and commit
154153 EOF
155154 exit 1
1414 echo "bin/run_cmake.sh: must be executed from its parent directory"
1515 exit 1
1616 fi
17 # prefix
1817 # -----------------------------------------------------------------------------
1918 # bash function that echos and executes a command
2019 echo_eval() {
2120 echo $*
2221 eval $*
2322 }
24 #
23 # -----------------------------------------------------------------------------
2524 # prefix
2625 eval `grep '^prefix=' bin/get_optional.sh`
2726 if [[ "$prefix" =~ ^[^/] ]]
2928 prefix="$(pwd)/$prefix"
3029 fi
3130 echo "prefix=$prefix"
32 #
31 # -----------------------------------------------------------------------------
3332 # PKG_CONFIG_PATH
3433 PKG_CONFIG_PATH="$prefix/lib64/pkgconfig:$prefix/lib/pkgconfig"
3534 PKG_CONFIG_PATH="$prefix/share/pkgconfig:$PKG_CONFIG_PATH"
7069 [--no_fadbad] \\
7170 [--no_cppadcg] \\
7271 [--no_sacado] \\
72 [--no_optional] \\
7373 [--no_documentation] \\
7474 [--<package>_vector] \\
7575 [--debug_<which>]
132132
133133 --no_sacado)
134134 yes_sacado='no'
135 ;;
136
137 --no_optional)
138 yes_adolc='no'
139 yes_colpack='no'
140 yes_eigen='no'
141 yes_ipopt='no'
142 yes_cppadcg='no'
143 yes_fadbad='no'
144 yes_sacado='no'
145 testvector='cppad'
135146 ;;
136147
137148 --no_documentation)
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
247247 then
248248 cat test_one.warn
249249 echo 'test_one.sh: unexpected warnings: see test_one.warn, test_one.err'
250 echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
250251 exit 1
251252 fi
252253 # --------------------------------------------------------------------------
253254 echo 'test_one.sh: OK'
255 echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
254256 exit 0
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
1414 echo "bin/trace.sh: must be executed from its parent directory"
1515 exit 1
1616 fi
17 name="$1"
17 file="include/cppad/local/sweep/$1"
1818 option="$2"
19 file="include/cppad/local/sweep/$name.hpp"
2019 #
2120 ok='yes'
2221 if [ "$option" != '0' ] && [ "$option" != '1' ]
2322 then
2423 ok='no'
2524 fi
26 echo "grep '_TRACE [01]' $file"
27 if ! grep '_TRACE [01]' $file > /dev/null
25 if [ "$ok" == 'yes' ]
2826 then
29 ok='no'
27 if ! grep '_TRACE [01]' $file > /dev/null
28 then
29 ok='no'
30 fi
3031 fi
3132 if [ "$ok" == 'no' ]
3233 then
33 echo 'usage: bin/trace.sh name (0|1)'
34 echo 'name: include/cppad/local/sweep/name.hpp defined *_TRACE as 0 or 1'
34 echo 'usage: bin/trace.sh file (0|1)'
35 echo 'Sets trace in file to off (0) or on (1) where the file is one of:'
36 grep -l '_TRACE [01]' include/cppad/local/sweep/*.hpp | \
37 sed -e 's|^include/cppad/local/sweep/||'
3538 exit 1
3639 fi
3740 old=`grep '_TRACE [01]' $file`
0 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2 #
3 # CppAD is distributed under the terms of the
4 # Eclipse Public License Version 2.0.
5 #
6 # This Source Code may also be made available under the following
7 # Secondary License when the conditions for such availability set forth
8 # in the Eclipse Public License, Version 2.0 are satisfied:
9 # GNU General Public License, Version 2.0 or later.
10 # -----------------------------------------------------------------------------
11 # compile_source_test(source variable)
12 #
13 # source: (in)
14 # contains the source for the program that will be compiled and linked.
15 #
16 # variable: (out)
17 # This variable must not be defined when this macro is called.
18 # Upon return, the value of this variable is 1 (0) if the program compiles
19 # and links (does not compile and link).
20 #
21 # CMAKE_REQUIRED_name (in)
22 # For name equal to DEFINITIONS, INCLUDES, LIBRARIES, FLAGS, the variable
23 # CMAKE_REQUIRED_name is an input to routine; see CHECK_CXX_SOURCE_COMPILES
24 # documentation.
25 #
26 MACRO(compile_source_test source variable)
27 #
28 # check that variable is not yet defined
29 IF( DEFINED ${variable} )
30 MESSAGE(FATAL_ERROR
31 "compile_source_test: ${variable} is defined before expected"
32 )
33 ENDIF( DEFINED ${variable} )
34 #
35 IF( DEFINED compiles_source_test_result)
36 UNSET(compiles_source_test_result)
37 ENDIF( DEFINED compiles_source_test_result )
38 #
39 # check that source codee compiles
40 CHECK_CXX_SOURCE_COMPILES("${source}" compiles_source_test_result )
41 #
42 # change result varialbe to 0 (1) for fail (succeed).
43 IF( compiles_source_test_result )
44 SET(${variable} 1)
45 ELSE( compiles_source_test_result )
46 SET(${variable} 0)
47 ENDIF( compiles_source_test_result )
48 #
49 # check that varialbe is defined
50 IF( NOT DEFINED ${variable} )
51 MESSAGE(FATAL_ERROR
52 "compile_source_test: error in CMake script."
53 )
54 ENDIF( NOT DEFINED ${variable} )
55 #
56 MESSAGE(STATUS "${variable} = ${${variable}}" )
57 ENDMACRO( compile_source_test )
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
88 # in the Eclipse Public License, Version 2.0 are satisfied:
99 # GNU General Public License, Version 2.0 or later.
1010 # -----------------------------------------------------------------------------
11 # pkgconfig_info(name system)
11 # pkgconfig_info(name system coin_or)
1212 #
1313 # Inputs:
14 # name: is the name of the package config file without the .pc extension
15 # system: if true (false) include directory will (will not) be
16 # treated like a system directory; i.e., no warnings.
14 # name: is the name of the package config file without the .pc extension
15 # system: if true (false) include directories will (will not) be
16 # treated like a system directory; i.e., no warnings.
17 # coin_or: if true (false) the string '/coin-or' at the end of an include
18 # include directory is (is not) removed because CppAD explicitly
19 # includes it in include commands.
1720 #
1821 # Outputs:
1922 # ${name}_LIBRARIES: list of libraries necessary to use this package.
2629 # Assumptions:
2730 # FIND_PACKAGE(PkgConfig) was successful
2831 # It is a fatal error if ${name}.pc is not in PKG_CONFIG_PATH
29 MACRO(pkgconfig_info name system)
32 MACRO(pkgconfig_info name system coin_or)
3033 IF( NOT PKG_CONFIG_FOUND )
3134 FIND_PACKAGE(PkgConfig REQUIRED)
3235 ENDIF( NOT PKG_CONFIG_FOUND )
4043 )
4144 ENDIF( ${name}_FOUND )
4245 #
46 IF( ${coin_or} )
47 STRING(REPLACE "/coin-or" "" include_dirs "${${name}_INCLUDE_DIRS}" )
48 SET(${name}_INCLUDE_DIRS "${include_dirs}")
49 ENDIF( ${coin_or} )
50 #
4351 # INLCUDE_DIRECTORIES
4452 IF( ${system} )
45 INCLUDE_DIRECTORIES( SYSTEM ${${name}_INCLUDE_DIRS} )
53 INCLUDE_DIRECTORIES( SYSTEM ${include_dirs} )
4654 ELSE( ${system} )
47 INCLUDE_DIRECTORIES( ${${name}_INCLUDE_DIRS} )
55 INCLUDE_DIRECTORIES( ${include_dirs} )
4856 ENDIF( ${system} )
4957 #
5058 # LINK_DIRECTORIES
3333 SET(CMAKE_REQUIRED_INCLUDES "" )
3434 SET(CMAKE_REQUIRED_LIBRARIES "" )
3535 IF( cppad_cxx_flags )
36 SET(CMAKE_REQUIRED_FLAGS "${cppad_cxx_flags}" )
36 SET(CMAKE_REQUIRED_FLAGS "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS}" )
3737 ELSE( cppad_cxx_flags )
3838 SET(CMAKE_REQUIRED_FLAGS "" )
3939 ENDIF( cppad_cxx_flags )
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2525 # The files with an odd (even) index in source_list have debug (release) flags.
2626 # In addition the compiler flag -DCPPAD_DEBUG_AND_RELEASE is added.
2727 #
28 # Case debug_all:
29 # All the files have debug flags.
30 #
31 # Case debug_none:
32 # All the the files have release flags.
28 # Case debug_all, debug_none, or empty string:
29 # The debug and release flags are not set by this routine.
3330 #
3431 # source_list: (in)
3532 # is a list of source files that get set to have debug or release
4946 ELSEIF( "${debug_which}" STREQUAL "debug_odd" )
5047 SET(alternate TRUE)
5148 SET(count_mod_2 1)
52 ELSEIF( "${debug_which}" STREQUAL "debug_all" )
49 ELSE( "${debug_which}" )
5350 SET(alternate FALSE)
54 SET_SOURCE_FILES_PROPERTIES(
55 ${source_list} PROPERTIES COMPILE_FLAGS "${debug_flags}"
56 )
57 ELSEIF( "${debug_which}" STREQUAL "debug_none" )
58 SET(alternate FALSE)
59 SET_SOURCE_FILES_PROPERTIES(
60 ${source_list} PROPERTIES COMPILE_FLAGS "${release_flags}"
61 )
62 ELSE( "${debug_which}" )
63 MESSAGE(FATAL_ERROR "cmake error: debug_which = ${debug_which}")
51 IF( NOT "${cppad_cxx_flags}" STREQUAL "" )
52 SET(alternate FALSE)
53 SET_SOURCE_FILES_PROPERTIES(
54 ${source_list} PROPERTIES COMPILE_FLAGS "${cppad_cxx_flags}"
55 )
56 ENDIF( NOT "${cppad_cxx_flags}" STREQUAL "" )
6457 ENDIF( "${debug_which}" STREQUAL "debug_even" )
6558 #
6659 IF( alternate )
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for cppad 20210000.8.
2 # Generated by GNU Autoconf 2.69 for cppad 20220000.4.
33 #
44 # Report bugs to <cppad@list.coin-or.org>.
55 #
578578 # Identity of this package.
579579 PACKAGE_NAME='cppad'
580580 PACKAGE_TARNAME='cppad'
581 PACKAGE_VERSION='20210000.8'
582 PACKAGE_STRING='cppad 20210000.8'
581 PACKAGE_VERSION='20220000.4'
582 PACKAGE_STRING='cppad 20220000.4'
583583 PACKAGE_BUGREPORT='cppad@list.coin-or.org'
584584 PACKAGE_URL=''
585585
628628 cppad_has_gettimeofday
629629 cppad_cppadvector
630630 compiler_has_conversion_warn
631 cppad_cplusplus_201100_ok
632631 cppad_has_tmpnam_s
633632 cppad_has_mkstemp
634633 cppad_has_colpack
754753 docdir
755754 oldincludedir
756755 includedir
756 runstatedir
757757 localstatedir
758758 sharedstatedir
759759 sysconfdir
849849 sysconfdir='${prefix}/etc'
850850 sharedstatedir='${prefix}/com'
851851 localstatedir='${prefix}/var'
852 runstatedir='${localstatedir}/run'
852853 includedir='${prefix}/include'
853854 oldincludedir='/usr/include'
854855 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
11011102 | -silent | --silent | --silen | --sile | --sil)
11021103 silent=yes ;;
11031104
1105 -runstatedir | --runstatedir | --runstatedi | --runstated \
1106 | --runstate | --runstat | --runsta | --runst | --runs \
1107 | --run | --ru | --r)
1108 ac_prev=runstatedir ;;
1109 -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
1110 | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
1111 | --run=* | --ru=* | --r=*)
1112 runstatedir=$ac_optarg ;;
1113
11041114 -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
11051115 ac_prev=sbindir ;;
11061116 -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
12381248 for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
12391249 datadir sysconfdir sharedstatedir localstatedir includedir \
12401250 oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
1241 libdir localedir mandir
1251 libdir localedir mandir runstatedir
12421252 do
12431253 eval ac_val=\$$ac_var
12441254 # Remove trailing slashes.
13511361 # Omit some internal or obsolete options to make the list less imposing.
13521362 # This message is too long to be a string in the A/UX 3.1 sh.
13531363 cat <<_ACEOF
1354 \`configure' configures cppad 20210000.8 to adapt to many kinds of systems.
1364 \`configure' configures cppad 20220000.4 to adapt to many kinds of systems.
13551365
13561366 Usage: $0 [OPTION]... [VAR=VALUE]...
13571367
13911401 --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
13921402 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
13931403 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
1404 --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
13941405 --libdir=DIR object code libraries [EPREFIX/lib]
13951406 --includedir=DIR C header files [PREFIX/include]
13961407 --oldincludedir=DIR C header files for non-gcc [/usr/include]
14211432
14221433 if test -n "$ac_init_help"; then
14231434 case $ac_init_help in
1424 short | recursive ) echo "Configuration of cppad 20210000.8:";;
1435 short | recursive ) echo "Configuration of cppad 20220000.4:";;
14251436 esac
14261437 cat <<\_ACEOF
14271438
15431554 test -n "$ac_init_help" && exit $ac_status
15441555 if $ac_init_version; then
15451556 cat <<\_ACEOF
1546 cppad configure 20210000.8
1557 cppad configure 20220000.4
15471558 generated by GNU Autoconf 2.69
15481559
15491560 Copyright (C) 2012 Free Software Foundation, Inc.
19161927 This file contains any messages produced by compilers while
19171928 running configure, to aid debugging if configure makes a mistake.
19181929
1919 It was created by cppad $as_me 20210000.8, which was
1930 It was created by cppad $as_me 20220000.4, which was
19201931 generated by GNU Autoconf 2.69. Invocation command line was
19211932
19221933 $ $0 $@
28062817
28072818 # Define the identity of the package.
28082819 PACKAGE='cppad'
2809 VERSION='20210000.8'
2820 VERSION='20220000.4'
28102821
28112822
28122823 cat >>confdefs.h <<_ACEOF
57615772
57625773 cppad_has_tmpnam_s=0
57635774
5764 cppad_cplusplus_201100_ok=0
5765
57665775 compiler_has_conversion_warn=0
57675776
57685777
70087017
70097018 ipopt_prefix=${IPOPT_DIR}
70107019
7011 ac_config_files="$ac_config_files include/cppad/configure.hpp cppad_ipopt/example/test.sh cppad_ipopt/speed/test.sh cppad_ipopt/test/test.sh example/ipopt_solve/test.sh pkgconfig/cppad.pc pkgconfig/cppad-uninstalled.pc makefile cppad_ipopt/src/makefile cppad_ipopt/example/makefile cppad_ipopt/speed/makefile cppad_ipopt/test/makefile cppad_lib/makefile example/general/makefile example/abs_normal/makefile example/atomic_two/makefile example/atomic_three/makefile example/chkpoint_two/makefile example/ipopt_solve/makefile example/optimize/makefile example/sparse/makefile example/utility/makefile example/get_started/makefile include/makefile introduction/makefile example/multi_thread/makefile example/print_for/makefile speed/adolc/makefile speed/cppad/makefile speed/double/makefile speed/example/makefile speed/fadbad/makefile speed/sacado/makefile speed/src/makefile test_more/compare_c/makefile test_more/general/makefile test_more/deprecated/makefile test_more/deprecated/atomic_two/makefile test_more/deprecated/chkpoint_one/makefile"
7020 ac_config_files="$ac_config_files include/cppad/configure.hpp cppad_ipopt/example/test.sh cppad_ipopt/speed/test.sh cppad_ipopt/test/test.sh example/ipopt_solve/test.sh pkgconfig/cppad.pc pkgconfig/cppad-uninstalled.pc makefile cppad_ipopt/src/makefile cppad_ipopt/example/makefile cppad_ipopt/speed/makefile cppad_ipopt/test/makefile cppad_lib/makefile example/general/makefile example/abs_normal/makefile example/atomic_two/makefile example/atomic_three/makefile example/chkpoint_two/makefile example/ipopt_solve/makefile example/optimize/makefile example/sparse/makefile example/utility/makefile example/get_started/makefile include/makefile introduction/makefile example/multi_thread/makefile example/print_for/makefile speed/adolc/makefile speed/cppad/makefile speed/double/makefile speed/example/makefile speed/fadbad/makefile speed/sacado/makefile speed/src/makefile speed/xpackage/makefile test_more/compare_c/makefile test_more/general/makefile test_more/deprecated/makefile test_more/deprecated/atomic_two/makefile test_more/deprecated/chkpoint_one/makefile"
70127021
70137022
70147023 ac_config_commands="$ac_config_commands configure.hpp"
76487657 # report actual input values of CONFIG_FILES etc. instead of their
76497658 # values after options handling.
76507659 ac_log="
7651 This file was extended by cppad $as_me 20210000.8, which was
7660 This file was extended by cppad $as_me 20220000.4, which was
76527661 generated by GNU Autoconf 2.69. Invocation command line was
76537662
76547663 CONFIG_FILES = $CONFIG_FILES
77057714 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
77067715 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
77077716 ac_cs_version="\\
7708 cppad config.status 20210000.8
7717 cppad config.status 20220000.4
77097718 configured by $0, generated by GNU Autoconf 2.69,
77107719 with options \\"\$ac_cs_config\\"
77117720
78687877 "speed/fadbad/makefile") CONFIG_FILES="$CONFIG_FILES speed/fadbad/makefile" ;;
78697878 "speed/sacado/makefile") CONFIG_FILES="$CONFIG_FILES speed/sacado/makefile" ;;
78707879 "speed/src/makefile") CONFIG_FILES="$CONFIG_FILES speed/src/makefile" ;;
7880 "speed/xpackage/makefile") CONFIG_FILES="$CONFIG_FILES speed/xpackage/makefile" ;;
78717881 "test_more/compare_c/makefile") CONFIG_FILES="$CONFIG_FILES test_more/compare_c/makefile" ;;
78727882 "test_more/general/makefile") CONFIG_FILES="$CONFIG_FILES test_more/general/makefile" ;;
78737883 "test_more/deprecated/makefile") CONFIG_FILES="$CONFIG_FILES test_more/deprecated/makefile" ;;
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1010 # -----------------------------------------------------------------------------
1111 dnl Process this file with autoconf to produce a configure script.
1212 dnl package version bug-report
13 AC_INIT([cppad], [20210000.8], [cppad@list.coin-or.org])
13 AC_INIT([cppad], [20220000.4], [cppad@list.coin-or.org])
1414 AM_SILENT_RULES([no])
1515
1616 dnl By defalut disable maintainer mode when running configure;
360360 AC_SUBST(cppad_has_colpack, 0)
361361 AC_SUBST(cppad_has_mkstemp, 0)
362362 AC_SUBST(cppad_has_tmpnam_s, 0)
363 AC_SUBST(cppad_cplusplus_201100_ok, 0)
364363 AC_SUBST(compiler_has_conversion_warn, 0)
365364
366365 dnl -------------------------------------------------------------------------
697696 speed/fadbad/makefile
698697 speed/sacado/makefile
699698 speed/src/makefile
699 speed/xpackage/makefile
700700 test_more/compare_c/makefile
701701 test_more/general/makefile
702702 test_more/deprecated/makefile
288288 builddir = @builddir@
289289 compiler_has_conversion_warn = @compiler_has_conversion_warn@
290290 cppad_boostvector = @cppad_boostvector@
291 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
292291 cppad_cppadvector = @cppad_cppadvector@
293292 cppad_cxx_flags = @cppad_cxx_flags@
294293 cppad_description = @cppad_description@
343342 prefix = @prefix@
344343 program_transform_name = @program_transform_name@
345344 psdir = @psdir@
345 runstatedir = @runstatedir@
346346 sbindir = @sbindir@
347347 sharedstatedir = @sharedstatedir@
348348 srcdir = @srcdir@
00 # ifndef CPPAD_CPPAD_IPOPT_EXAMPLE_ODE_RUN_HPP
11 # define CPPAD_CPPAD_IPOPT_EXAMPLE_ODE_RUN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3535 bool retape ,
3636 const SizeVector& N ,
3737 NumberVector& x )
38 { bool ok = true;
38 {
3939 size_t i, j;
4040
4141 // compute the partial sums of the number of grid points
102102 app->Options()-> SetStringValue( "derivative_test", "second-order");
103103 app->Options()-> SetNumericValue( "point_perturbation_radius", 0.);
104104
105 # ifndef NDEBUG
106 bool ok = true;
107 //
105108 // Initialize the application and process the options
106109 Ipopt::ApplicationReturnStatus status = app->Initialize();
107110 ok &= status == Ipopt::Solve_Succeeded;
108
111 //
109112 // Run the application
110113 status = app->OptimizeTNLP(cppad_nlp);
111114 ok &= status == Ipopt::Solve_Succeeded;
115 //
116 assert(ok);
117 # else
118 app->Initialize();
119 app->OptimizeTNLP(cppad_nlp);
120 # endif
112121
113122 // return the solution
114123 x.resize( solution.x.size() );
292292 builddir = @builddir@
293293 compiler_has_conversion_warn = @compiler_has_conversion_warn@
294294 cppad_boostvector = @cppad_boostvector@
295 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
296295 cppad_cppadvector = @cppad_cppadvector@
297296 cppad_cxx_flags = @cppad_cxx_flags@
298297 cppad_description = @cppad_description@
347346 prefix = @prefix@
348347 program_transform_name = @program_transform_name@
349348 psdir = @psdir@
349 runstatedir = @runstatedir@
350350 sbindir = @sbindir@
351351 sharedstatedir = @sharedstatedir@
352352 srcdir = @srcdir@
325325 builddir = @builddir@
326326 compiler_has_conversion_warn = @compiler_has_conversion_warn@
327327 cppad_boostvector = @cppad_boostvector@
328 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
329328 cppad_cppadvector = @cppad_cppadvector@
330329 cppad_cxx_flags = @cppad_cxx_flags@
331330 cppad_description = @cppad_description@
380379 prefix = @prefix@
381380 program_transform_name = @program_transform_name@
382381 psdir = @psdir@
382 runstatedir = @runstatedir@
383383 sbindir = @sbindir@
384384 sharedstatedir = @sharedstatedir@
385385 srcdir = @srcdir@
276276 builddir = @builddir@
277277 compiler_has_conversion_warn = @compiler_has_conversion_warn@
278278 cppad_boostvector = @cppad_boostvector@
279 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
280279 cppad_cppadvector = @cppad_cppadvector@
281280 cppad_cxx_flags = @cppad_cxx_flags@
282281 cppad_description = @cppad_description@
331330 prefix = @prefix@
332331 program_transform_name = @program_transform_name@
333332 psdir = @psdir@
333 runstatedir = @runstatedir@
334334 sbindir = @sbindir@
335335 sharedstatedir = @sharedstatedir@
336336 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
4646 #
4747 set_compile_flags(cppad_lib "${cppad_debug_which}" "${source_list}" )
4848 #
49 IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
49 # is_windows
50 STRING( REGEX MATCH "^MSYS" is_msys "${CMAKE_SYSTEM_NAME}" )
51 STRING( REGEX MATCH "^CYGWIN" is_cygwin "${CMAKE_SYSTEM_NAME}" )
52 STRING( REGEX MATCH "^Windows" is_windows "${CMAKE_SYSTEM_NAME}" )
53 IF( is_msys OR is_cygwin OR is_windows )
5054 MESSAGE( STATUS "Windows system so building static cppad_lib")
5155 ADD_LIBRARY( cppad_lib STATIC ${source_list} )
52 ELSE( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
56 ELSE( )
5357 MESSAGE( STATUS "Not Windows system so building shared cppad_lib")
5458 ADD_LIBRARY( cppad_lib SHARED ${source_list} )
5559 SET_TARGET_PROPERTIES( cppad_lib PROPERTIES SOVERSION ${soversion} )
5862 IF( dl_LIBRARY )
5963 TARGET_LINK_LIBRARIES(cppad_lib ${dl_LIBRARY})
6064 ENDIF( dl_LIBRARY )
61 ENDIF( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
65 ENDIF( )
6266 #
6367 # install(TARGETS myExe mySharedLib myStaticLib
6468 # RUNTIME DESTINATION bin
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2626 // map from operator enum to n_arg (when fixed number of arguments)
2727 size_t op_enum2fixed_n_arg[n_graph_op];
2828
29 // This routine is called by the first use of the cpp_graph constructor
30 // see cpp_grpah.hpp.
2931 void set_operator_info(void)
30 { typedef std::pair<std::string, graph_op_enum> pair;
32 { // This routine cannot be called in parallel mode
33 CPPAD_ASSERT_UNKNOWN( ! ( CppAD::thread_alloc::in_parallel() ));
34 //
35 typedef std::pair<std::string, graph_op_enum> pair;
3136 struct op_info {
3237 graph_op_enum code;
3338 const char* name;
3439 size_t n_arg;
3540 };
41 /*
42 If n_arg is zero in the table below, the table contains a comment as to
43 the heading in graph_op_enum.hpp below which you can find the
44 specifications for n_arg, n_result for the corresponding operator.
45 */
3646 // BEGIN_SORT_THIS_LINE_PLUS_2
3747 op_info op_info_vec[] = {
3848 { abs_graph_op, "abs", 1 }, // 1 result
4353 { asinh_graph_op, "asinh", 1 }, // 1 result
4454 { atan_graph_op, "atan", 1 }, // 1 result
4555 { atanh_graph_op, "atanh", 1 }, // 1 result
46 { atom_graph_op, "atom", 0 }, // n_result, n_arg in Json usage
56 { atom_graph_op, "atom", 0 }, // See Atomic Function
4757 { azmul_graph_op, "azmul", 2 }, // 1 result
4858 { cexp_eq_graph_op, "cexp_eq", 4 }, // 1 result
4959 { cexp_le_graph_op, "cexp_le", 4 }, // 1 result
5060 { cexp_lt_graph_op, "cexp_lt", 4 }, // 1 result
51 { comp_eq_graph_op, "comp_eq", 0 }, // n_result, n_arg in Json usage
61 { comp_eq_graph_op, "comp_eq", 0 }, // See Comparisons
5262 { comp_le_graph_op, "comp_le", 0 }, // ...
5363 { comp_lt_graph_op, "comp_lt", 0 }, // ...
5464 { comp_ne_graph_op, "comp_ne", 0 }, // ...
5565 { cos_graph_op, "cos", 1 }, // 1 result
5666 { cosh_graph_op, "cosh", 1 }, // 1 result
57 { discrete_graph_op, "discrete", 0 }, // n_result, n_arg in Json usage
67 { discrete_graph_op, "discrete", 0 }, // See Discrete Function
5868 { div_graph_op, "div", 2 }, // 1 result
5969 { erf_graph_op, "erf", 1 }, // 1 result
6070 { erfc_graph_op, "erfc", 1 }, // 1 result
6272 { expm1_graph_op, "expm1", 1 }, // 1 result
6373 { log1p_graph_op, "log1p", 1 }, // 1 result
6474 { log_graph_op, "log", 1 }, // 1 result
75 { neg_graph_op, "neg", 1 }, // 1 result
6576 { mul_graph_op, "mul", 2 }, // 1 result
6677 { pow_graph_op, "pow", 2 }, // 1 result
67 { print_graph_op, "print", 0 }, // n_result, n_arg in Json usage
78 { print_graph_op, "print", 0 }, // See Print
6879 { sign_graph_op, "sign", 1 }, // 1 result
6980 { sin_graph_op, "sin", 1 }, // 1 result
7081 { sinh_graph_op, "sinh", 1 }, // 1 result
7182 { sqrt_graph_op, "sqrt", 1 }, // 1 result
7283 { sub_graph_op, "sub", 2 }, // 1 result
73 { sum_graph_op, "sum", 0 }, // n_result, n_arg in Json usage
84 { sum_graph_op, "sum", 0 }, // See Summation
7485 { tan_graph_op, "tan", 1 }, // 1 result
7586 { tanh_graph_op, "tanh", 1 } // 1 result
7687 };
7878 char_number_(1),
7979 token_(""),
8080 function_name_("")
81 { // make sure op_name2enum has been initialized
82 if( op_name2enum.size() == 0 )
83 { CPPAD_ASSERT_KNOWN( ! thread_alloc::in_parallel() ,
84 "call to set_operator_info in parallel mode"
85 );
86 set_operator_info();
87 }
88
81 {
8982 skip_white_space();
9083 if( index_ < json_.size() )
9184 token_ = json_[index_];
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2020 std::string& json ,
2121 const cpp_graph& graph_obj )
2222 { using std::string;
23 // --------------------------------------------------------------------
24 if( local::graph::op_name2enum.size() == 0 )
25 { CPPAD_ASSERT_KNOWN( ! thread_alloc::in_parallel() ,
26 "call to set_operator_info in parallel mode"
27 );
28 local::graph::set_operator_info();
29 }
3023 // --------------------------------------------------------------------
3124 const string& function_name( graph_obj.function_name_get() );
3225 const size_t& n_dynamic_ind( graph_obj.n_dynamic_ind_get() );
307307 builddir = @builddir@
308308 compiler_has_conversion_warn = @compiler_has_conversion_warn@
309309 cppad_boostvector = @cppad_boostvector@
310 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
311310 cppad_cppadvector = @cppad_cppadvector@
312311 cppad_cxx_flags = @cppad_cxx_flags@
313312 cppad_description = @cppad_description@
362361 prefix = @prefix@
363362 program_transform_name = @program_transform_name@
364363 psdir = @psdir@
364 runstatedir = @runstatedir@
365365 sbindir = @sbindir@
366366 sharedstatedir = @sharedstatedir@
367367 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1111 # Build the example directory tests
1212 # Inherit environment from ../CMakeList.txt
1313
14 # initialize check_depends
14 # initialize check_example_depends
1515 SET(check_example_depends "")
1616
1717 # abs_normal examples
290290 builddir = @builddir@
291291 compiler_has_conversion_warn = @compiler_has_conversion_warn@
292292 cppad_boostvector = @cppad_boostvector@
293 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
294293 cppad_cppadvector = @cppad_cppadvector@
295294 cppad_cxx_flags = @cppad_cxx_flags@
296295 cppad_description = @cppad_description@
345344 prefix = @prefix@
346345 program_transform_name = @program_transform_name@
347346 psdir = @psdir@
347 runstatedir = @runstatedir@
348348 sbindir = @sbindir@
349349 sharedstatedir = @sharedstatedir@
350350 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2424 rev_depend.cpp
2525 reverse.cpp
2626 tangent.cpp
27 vector_op.cpp
2728 )
2829 # END_SORT_THIS_LINE_MINUS_2
2930
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2424 // test runner
2525 # include <cppad/utility/test_boolofvoid.hpp>
2626
27 // external compiled tests
28 extern bool mat_mul(void);
29 extern bool norm_sq(void);
30 extern bool tangent(void);
27 // BEGIN_SORT_THIS_LINE_PLUS_1
3128 extern bool base2ad(void);
32 extern bool reciprocal(void);
3329 extern bool dynamic(void);
3430 extern bool forward(void);
3531 extern bool get_started(void);
3632 extern bool hes_sparsity(void);
3733 extern bool jac_sparsity(void);
34 extern bool mat_mul(void);
35 extern bool norm_sq(void);
36 extern bool reciprocal(void);
37 extern bool rev_depend(void);
3838 extern bool reverse(void);
39 extern bool rev_depend(void);
39 extern bool tangent(void);
40 extern bool vector_op(void);
41 // END_SORT_THIS_LINE_MINUS_1
4042
4143 // main program that runs all the tests
4244 int main(void)
4648
4749 // This line is used by test_one.sh
4850
49 // external compiled tests
50 Run( mat_mul, "mat_mul" );
51 Run( norm_sq, "norm_sq" );
52 Run( tangent, "tangent" );
53 Run( base2ad, "base2ad" );
54 Run( reciprocal, "reciprocal" );
51 // BEGIN_SORT_THIS_LINE_PLUS_1
52 Run( base2ad, "base2ad" );
5553 Run( dynamic, "dynamic" );
5654 Run( forward, "forward" );
5755 Run( get_started, "get_started" );
5856 Run( hes_sparsity, "hes_sparsity" );
5957 Run( jac_sparsity, "jac_sparsity" );
58 Run( mat_mul, "mat_mul" );
59 Run( norm_sq, "norm_sq" );
60 Run( reciprocal, "reciprocal" );
61 Run( rev_depend, "rev_depend" );
6062 Run( reverse, "reverse" );
61 Run( rev_depend, "rev_depend" );
63 Run( tangent, "tangent" );
64 Run( vector_op, "vector_op" );
65 // END_SORT_THIS_LINE_MINUS_1
6266
6367 // check for memory leak
6468 bool memory_ok = CppAD::thread_alloc::free_all();
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3636 private:
3737 // ------------------------------------------------------------------------
3838 // type
39 virtual bool for_type(
39 bool for_type(
4040 const vector<double>& parameter_x ,
4141 const vector<CppAD::ad_type_enum>& type_x ,
42 vector<CppAD::ad_type_enum>& type_y )
42 vector<CppAD::ad_type_enum>& type_y ) override
4343 { assert( parameter_x.size() == type_x.size() );
4444 bool ok = type_x.size() == 1; // n
4545 ok &= type_y.size() == 1; // m
7979 return ok;
8080 }
8181 // forward mode routines called by ADFun<Base> objects
82 virtual bool forward(
82 bool forward(
8383 const vector<double>& parameter_x ,
8484 const vector<CppAD::ad_type_enum>& type_x ,
8585 size_t need_y ,
8686 size_t p ,
8787 size_t q ,
8888 const vector<double>& tx ,
89 vector<double>& ty )
89 vector<double>& ty ) override
9090 { return template_forward(p, q, tx, ty);
9191 }
9292 // forward mode routines called by ADFun< AD<Base> , Base> objects
93 virtual bool forward(
93 bool forward(
9494 const vector< AD<double> >& aparameter_x ,
9595 const vector<CppAD::ad_type_enum>& type_x ,
9696 size_t need_y ,
9797 size_t p ,
9898 size_t q ,
9999 const vector< AD<double> >& atx ,
100 vector< AD<double> >& aty )
100 vector< AD<double> >& aty ) override
101101 { return template_forward(p, q, atx, aty);
102102 }
103103 // ----------------------------------------------------------------------
130130 return ok;
131131 }
132132 // reverse mode routines called by ADFun<Base> objects
133 virtual bool reverse(
133 bool reverse(
134134 const vector<double>& parameter_x ,
135135 const vector<CppAD::ad_type_enum>& type_x ,
136136 size_t q ,
137137 const vector<double>& tx ,
138138 const vector<double>& ty ,
139139 vector<double>& px ,
140 const vector<double>& py )
140 const vector<double>& py ) override
141141 { return template_reverse(q, tx, ty, px, py);
142142 }
143143 // reverse mode routines called by ADFun<Base> objects
144 virtual bool reverse(
144 bool reverse(
145145 const vector< AD<double> >& aparameter_x ,
146146 const vector<CppAD::ad_type_enum>& type_x ,
147147 size_t q ,
148148 const vector< AD<double> >& atx ,
149149 const vector< AD<double> >& aty ,
150150 vector< AD<double> >& apx ,
151 const vector< AD<double> >& apy )
151 const vector< AD<double> >& apy ) override
152152 { return template_reverse(q, atx, aty, apx, apy);
153153 }
154154 }; // End of atomic_base2ad class
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
4848 $head for_type$$
4949 $srccode%cpp% */
5050 // calculate type_y
51 virtual bool for_type(
51 bool for_type(
5252 const vector<double>& parameter_x ,
5353 const vector<CppAD::ad_type_enum>& type_x ,
54 vector<CppAD::ad_type_enum>& type_y )
54 vector<CppAD::ad_type_enum>& type_y ) override
5555 { assert( parameter_x.size() == type_x.size() );
5656 bool ok = type_x.size() == 3; // n
5757 ok &= type_y.size() == 3; // m
6666 $head forward$$
6767 $srccode%cpp% */
6868 // forward mode routine called by CppAD
69 virtual bool forward(
69 bool forward(
7070 const vector<double>& parameter_x ,
7171 const vector<CppAD::ad_type_enum>& type_x ,
7272 size_t need_y ,
7373 size_t order_low ,
7474 size_t order_up ,
7575 const vector<double>& taylor_x ,
76 vector<double>& taylor_y )
76 vector<double>& taylor_y ) override
7777 {
7878 # ifndef NDEBUG
7979 size_t n = taylor_x.size() / (order_up + 1);
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
7676 $head for_type$$
7777 $srccode%cpp% */
7878 // calculate type_y
79 virtual bool for_type(
79 bool for_type(
8080 const vector<double>& parameter_x ,
8181 const vector<CppAD::ad_type_enum>& type_x ,
82 vector<CppAD::ad_type_enum>& type_y )
82 vector<CppAD::ad_type_enum>& type_y ) override
8383 { assert( parameter_x.size() == type_x.size() );
8484 bool ok = type_x.size() == 3; // n
8585 ok &= type_y.size() == 2; // m
9393 $head forward$$
9494 $srccode%cpp% */
9595 // forward mode routine called by CppAD
96 virtual bool forward(
96 bool forward(
9797 const vector<double>& parameter_x ,
9898 const vector<CppAD::ad_type_enum>& type_x ,
9999 size_t need_y ,
100100 size_t order_low ,
101101 size_t order_up ,
102102 const vector<double>& taylor_x ,
103 vector<double>& taylor_y )
103 vector<double>& taylor_y ) override
104104 {
105105 size_t q1 = order_up + 1;
106106 # ifndef NDEBUG
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
4141 $head for_type$$
4242 $srccode%cpp% */
4343 // calculate type_y
44 virtual bool for_type(
44 bool for_type(
4545 const vector<double>& parameter_x ,
4646 const vector<CppAD::ad_type_enum>& type_x ,
47 vector<CppAD::ad_type_enum>& type_y )
47 vector<CppAD::ad_type_enum>& type_y ) override
4848 { assert( parameter_x.size() == type_x.size() );
4949 bool ok = type_x.size() == 1; // n
5050 ok &= type_y.size() == 1; // m
5757 $head forward$$
5858 $srccode%cpp% */
5959 // forward mode routine called by CppAD
60 virtual bool forward(
60 bool forward(
6161 const vector<double>& parameter_x ,
6262 const vector<CppAD::ad_type_enum>& type_x ,
6363 size_t need_y ,
6464 size_t order_low ,
6565 size_t order_up ,
6666 const vector<double>& taylor_x ,
67 vector<double>& taylor_y )
67 vector<double>& taylor_y ) override
6868 {
6969 # ifndef NDEBUG
7070 size_t n = taylor_x.size() / (order_up + 1);
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
7676 $head for_type$$
7777 $srccode%cpp% */
7878 // calculate type_y
79 virtual bool for_type(
79 bool for_type(
8080 const vector<double>& parameter_x ,
8181 const vector<CppAD::ad_type_enum>& type_x ,
82 vector<CppAD::ad_type_enum>& type_y )
82 vector<CppAD::ad_type_enum>& type_y ) override
8383 { assert( parameter_x.size() == type_x.size() );
8484 bool ok = type_x.size() == 3; // n
8585 ok &= type_y.size() == 2; // m
9494 $head forward$$
9595 $srccode%cpp% */
9696 // forward mode routine called by CppAD
97 virtual bool forward(
97 bool forward(
9898 const vector<double>& parameter_x ,
9999 const vector<CppAD::ad_type_enum>& type_x ,
100100 size_t need_y ,
101101 size_t order_low ,
102102 size_t order_up ,
103103 const vector<double>& taylor_x ,
104 vector<double>& taylor_y )
104 vector<double>& taylor_y ) override
105105 {
106106 # ifndef NDEBUG
107107 size_t n = taylor_x.size() / (order_up + 1);
126126 $head jac_sparsity$$
127127 $srccode%cpp% */
128128 // Jacobian sparsity routine called by CppAD
129 virtual bool jac_sparsity(
129 bool jac_sparsity(
130130 const vector<double>& parameter_x ,
131131 const vector<CppAD::ad_type_enum>& type_x ,
132132 bool dependency ,
133133 const vector<bool>& select_x ,
134134 const vector<bool>& select_y ,
135 CppAD::sparse_rc< vector<size_t> >& pattern_out )
135 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
136136 {
137137 size_t n = select_x.size();
138138 size_t m = select_y.size();
182182 $head hes_sparsity$$
183183 $srccode%cpp% */
184184 // Hessian sparsity routine called by CppAD
185 virtual bool hes_sparsity(
185 bool hes_sparsity(
186186 const vector<double>& parameter_x ,
187187 const vector<CppAD::ad_type_enum>& type_x ,
188188 const vector<bool>& select_x ,
189189 const vector<bool>& select_y ,
190 CppAD::sparse_rc< vector<size_t> >& pattern_out )
190 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
191191 { assert( parameter_x.size() == select_x.size() );
192192 assert( select_y.size() == 2 );
193193 size_t n = select_x.size();
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
6060 $head for_type$$
6161 $srccode%cpp% */
6262 // calculate type_y
63 virtual bool for_type(
63 bool for_type(
6464 const vector<double>& parameter_x ,
6565 const vector<CppAD::ad_type_enum>& type_x ,
66 vector<CppAD::ad_type_enum>& type_y )
66 vector<CppAD::ad_type_enum>& type_y ) override
6767 { assert( parameter_x.size() == type_x.size() );
6868 bool ok = type_x.size() == 3; // n
6969 ok &= type_y.size() == 2; // m
7878 $head forward$$
7979 $srccode%cpp% */
8080 // forward mode routine called by CppAD
81 virtual bool forward(
81 bool forward(
8282 const vector<double>& parameter_x ,
8383 const vector<CppAD::ad_type_enum>& type_x ,
8484 size_t need_y ,
8585 size_t order_low ,
8686 size_t order_up ,
8787 const vector<double>& taylor_x ,
88 vector<double>& taylor_y )
88 vector<double>& taylor_y ) override
8989 {
9090 # ifndef NDEBUG
9191 size_t n = taylor_x.size() / (order_up + 1);
110110 $head jac_sparsity$$
111111 $srccode%cpp% */
112112 // Jacobian sparsity routine called by CppAD
113 virtual bool jac_sparsity(
113 bool jac_sparsity(
114114 const vector<double>& parameter_x ,
115115 const vector<CppAD::ad_type_enum>& type_x ,
116116 bool dependency ,
117117 const vector<bool>& select_x ,
118118 const vector<bool>& select_y ,
119 CppAD::sparse_rc< vector<size_t> >& pattern_out )
119 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
120120 {
121121 size_t n = select_x.size();
122122 size_t m = select_y.size();
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
3636 hes_sparsity.cpp \
3737 jac_sparsity.cpp \
3838 reverse.cpp \
39 rev_depend.cpp
39 rev_depend.cpp \
40 vector_op.cpp
4041
4142 test: check
4243 ./atomic
100100 norm_sq.$(OBJEXT) tangent.$(OBJEXT) base2ad.$(OBJEXT) \
101101 reciprocal.$(OBJEXT) dynamic.$(OBJEXT) forward.$(OBJEXT) \
102102 get_started.$(OBJEXT) hes_sparsity.$(OBJEXT) \
103 jac_sparsity.$(OBJEXT) reverse.$(OBJEXT) rev_depend.$(OBJEXT)
103 jac_sparsity.$(OBJEXT) reverse.$(OBJEXT) rev_depend.$(OBJEXT) \
104 vector_op.$(OBJEXT)
104105 atomic_OBJECTS = $(am_atomic_OBJECTS)
105106 atomic_LDADD = $(LDADD)
106107 AM_V_P = $(am__v_P_@AM_V@)
124125 ./$(DEPDIR)/hes_sparsity.Po ./$(DEPDIR)/jac_sparsity.Po \
125126 ./$(DEPDIR)/mat_mul.Po ./$(DEPDIR)/norm_sq.Po \
126127 ./$(DEPDIR)/reciprocal.Po ./$(DEPDIR)/rev_depend.Po \
127 ./$(DEPDIR)/reverse.Po ./$(DEPDIR)/tangent.Po
128 ./$(DEPDIR)/reverse.Po ./$(DEPDIR)/tangent.Po \
129 ./$(DEPDIR)/vector_op.Po
128130 am__mv = mv -f
129131 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
130132 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
195197 CYGPATH_W = @CYGPATH_W@
196198
197199 # -----------------------------------------------------------------------------
198 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
200 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
199201 #
200202 # CppAD is distributed under the terms of the
201203 # Eclipse Public License Version 2.0.
278280 builddir = @builddir@
279281 compiler_has_conversion_warn = @compiler_has_conversion_warn@
280282 cppad_boostvector = @cppad_boostvector@
281 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
282283 cppad_cppadvector = @cppad_cppadvector@
283284 cppad_cxx_flags = @cppad_cxx_flags@
284285 cppad_description = @cppad_description@
333334 prefix = @prefix@
334335 program_transform_name = @program_transform_name@
335336 psdir = @psdir@
337 runstatedir = @runstatedir@
336338 sbindir = @sbindir@
337339 sharedstatedir = @sharedstatedir@
338340 srcdir = @srcdir@
364366 hes_sparsity.cpp \
365367 jac_sparsity.cpp \
366368 reverse.cpp \
367 rev_depend.cpp
369 rev_depend.cpp \
370 vector_op.cpp
368371
369372 all: all-am
370373
426429 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rev_depend.Po@am__quote@ # am--include-marker
427430 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reverse.Po@am__quote@ # am--include-marker
428431 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tangent.Po@am__quote@ # am--include-marker
432 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector_op.Po@am__quote@ # am--include-marker
429433
430434 $(am__depfiles_remade):
431435 @$(MKDIR_P) $(@D)
587591 -rm -f ./$(DEPDIR)/rev_depend.Po
588592 -rm -f ./$(DEPDIR)/reverse.Po
589593 -rm -f ./$(DEPDIR)/tangent.Po
594 -rm -f ./$(DEPDIR)/vector_op.Po
590595 -rm -f makefile
591596 distclean-am: clean-am distclean-compile distclean-generic \
592597 distclean-tags
645650 -rm -f ./$(DEPDIR)/rev_depend.Po
646651 -rm -f ./$(DEPDIR)/reverse.Po
647652 -rm -f ./$(DEPDIR)/tangent.Po
653 -rm -f ./$(DEPDIR)/vector_op.Po
648654 -rm -f makefile
649655 maintainer-clean-am: distclean-am maintainer-clean-generic
650656
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
4949 $head for_type$$
5050 $srccode%cpp% */
5151 // calculate type_y
52 virtual bool for_type(
52 bool for_type(
5353 const vector<double>& parameter_x ,
5454 const vector<CppAD::ad_type_enum>& type_x ,
55 vector<CppAD::ad_type_enum>& type_y )
55 vector<CppAD::ad_type_enum>& type_y ) override
5656 { assert( parameter_x.size() == type_x.size() );
5757 bool ok = type_x.size() == 2; // n
5858 ok &= type_y.size() == 1; // m
6565 $head forward$$
6666 $srccode%cpp% */
6767 // forward mode routine called by CppAD
68 virtual bool forward(
68 bool forward(
6969 const vector<double>& parameter_x ,
7070 const vector<CppAD::ad_type_enum>& type_x ,
7171 size_t need_y ,
7272 size_t p ,
7373 size_t q ,
7474 const vector<double>& tx ,
75 vector<double>& ty )
75 vector<double>& ty ) override
7676 {
7777 # ifndef NDEBUG
7878 size_t n = tx.size() / (q+1);
116116 $head reverse$$
117117 $srccode%cpp% */
118118 // reverse mode routine called by CppAD
119 virtual bool reverse(
119 bool reverse(
120120 const vector<double>& parameter_x ,
121121 const vector<CppAD::ad_type_enum>& type_x ,
122122 size_t q ,
123123 const vector<double>& tx ,
124124 const vector<double>& ty ,
125125 vector<double>& px ,
126 const vector<double>& py )
126 const vector<double>& py ) override
127127 {
128128 # ifndef NDEBUG
129129 size_t n = tx.size() / (q+1);
157157 $head jac_sparsity$$
158158 $srccode%cpp% */
159159 // Jacobian sparsity routine called by CppAD
160 virtual bool jac_sparsity(
160 bool jac_sparsity(
161161 const vector<double>& parameter_x ,
162162 const vector<CppAD::ad_type_enum>& type_x ,
163163 bool dependency ,
164164 const vector<bool>& select_x ,
165165 const vector<bool>& select_y ,
166 CppAD::sparse_rc< vector<size_t> >& pattern_out )
166 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
167167 { size_t n = select_x.size();
168168 size_t m = select_y.size();
169169 assert( n == 2 );
193193 $head hes_sparsity$$
194194 $srccode%cpp% */
195195 // Hessian sparsity routine called by CppAD
196 virtual bool hes_sparsity(
196 bool hes_sparsity(
197197 const vector<double>& parameter_x ,
198198 const vector<CppAD::ad_type_enum>& type_x ,
199199 const vector<bool>& select_x ,
200200 const vector<bool>& select_y ,
201 CppAD::sparse_rc< vector<size_t> >& pattern_out )
201 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
202202 { size_t n = select_x.size();
203203 assert( n == 2 );
204204 assert( select_y.size() == 1 ); // m
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
4444 $head for_type$$
4545 $srccode%cpp% */
4646 // calculate type_y
47 virtual bool for_type(
47 bool for_type(
4848 const vector<double>& parameter_x ,
4949 const vector<CppAD::ad_type_enum>& type_x ,
50 vector<CppAD::ad_type_enum>& type_y )
50 vector<CppAD::ad_type_enum>& type_y ) override
5151 { assert( parameter_x.size() == type_x.size() );
5252 bool ok = type_x.size() == 1; // n
5353 ok &= type_y.size() == 1; // m
6060 $head forward$$
6161 $srccode%cpp% */
6262 // forward mode routine called by CppAD
63 virtual bool forward(
63 bool forward(
6464 const vector<double>& parameter_x ,
6565 const vector<CppAD::ad_type_enum>& type_x ,
6666 size_t need_y ,
6767 size_t p ,
6868 size_t q ,
6969 const vector<double>& tx ,
70 vector<double>& ty )
70 vector<double>& ty ) override
7171 {
7272 # ifndef NDEBUG
7373 size_t n = tx.size() / (q + 1);
116116 $head reverse$$
117117 $srccode%cpp% */
118118 // reverse mode routine called by CppAD
119 virtual bool reverse(
119 bool reverse(
120120 const vector<double>& parameter_x ,
121121 const vector<CppAD::ad_type_enum>& type_x ,
122122 size_t q ,
123123 const vector<double>& tx ,
124124 const vector<double>& ty ,
125125 vector<double>& px ,
126 const vector<double>& py )
126 const vector<double>& py ) override
127127 {
128128 # ifndef NDEBUG
129129 size_t n = tx.size() / (q + 1);
187187 $head jac_sparsity$$
188188 $srccode%cpp% */
189189 // Jacobian sparsity routine called by CppAD
190 virtual bool jac_sparsity(
190 bool jac_sparsity(
191191 const vector<double>& parameter_x ,
192192 const vector<CppAD::ad_type_enum>& type_x ,
193193 bool dependency ,
194194 const vector<bool>& select_x ,
195195 const vector<bool>& select_y ,
196 CppAD::sparse_rc< vector<size_t> >& pattern_out )
196 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
197197 {
198198 size_t n = select_x.size();
199199 size_t m = select_y.size();
221221 $head hes_sparsity$$
222222 $srccode%cpp% */
223223 // Hessian sparsity routine called by CppAD
224 virtual bool hes_sparsity(
224 bool hes_sparsity(
225225 const vector<double>& parameter_x ,
226226 const vector<CppAD::ad_type_enum>& type_x ,
227227 const vector<bool>& select_x ,
228228 const vector<bool>& select_y ,
229 CppAD::sparse_rc< vector<size_t> >& pattern_out )
229 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
230230 {
231231 assert( parameter_x.size() == select_x.size() );
232232 assert( select_y.size() == 1 );
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
4848 $head for_type$$
4949 $srccode%cpp% */
5050 // calculate type_y
51 virtual bool for_type(
51 bool for_type(
5252 const vector<double>& parameter_x ,
5353 const vector<CppAD::ad_type_enum>& type_x ,
54 vector<CppAD::ad_type_enum>& type_y )
54 vector<CppAD::ad_type_enum>& type_y ) override
5555 { assert( parameter_x.size() == type_x.size() );
5656 bool ok = type_x.size() == 3; // n
5757 ok &= type_y.size() == 3; // m
6666 $head rev_depend$$
6767 $srccode%cpp% */
6868 // calculate depend_x
69 virtual bool rev_depend(
69 bool rev_depend(
7070 const vector<double>& parameter_x ,
7171 const vector<CppAD::ad_type_enum>& type_x ,
7272 vector<bool>& depend_x ,
73 const vector<bool>& depend_y )
73 const vector<bool>& depend_y ) override
7474 { assert( parameter_x.size() == depend_x.size() );
7575 bool ok = depend_x.size() == 3; // n
7676 ok &= depend_y.size() == 3; // m
8585 $head forward$$
8686 $srccode%cpp% */
8787 // forward mode routine called by CppAD
88 virtual bool forward(
88 bool forward(
8989 const vector<double>& parameter_x ,
9090 const vector<CppAD::ad_type_enum>& type_x ,
9191 size_t need_y ,
9393 size_t order_up ,
9494 const vector<double>& taylor_x ,
9595 vector<double>& taylor_y
96 )
96 ) override
9797 {
9898 # ifndef NDEBUG
9999 size_t n = taylor_x.size() / (order_up + 1);
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
7676 $head for_type$$
7777 $srccode%cpp% */
7878 // calculate type_y
79 virtual bool for_type(
79 bool for_type(
8080 const vector<double>& parameter_x ,
8181 const vector<CppAD::ad_type_enum>& type_x ,
82 vector<CppAD::ad_type_enum>& type_y )
82 vector<CppAD::ad_type_enum>& type_y ) override
8383 { assert( parameter_x.size() == type_x.size() );
8484 bool ok = type_x.size() == 3; // n
8585 ok &= type_y.size() == 2; // m
9393 $head forward$$
9494 $srccode%cpp% */
9595 // forward mode routine called by CppAD
96 virtual bool forward(
96 bool forward(
9797 const vector<double>& parameter_x ,
9898 const vector<CppAD::ad_type_enum>& type_x ,
9999 size_t need_y ,
100100 size_t order_low ,
101101 size_t order_up ,
102102 const vector<double>& taylor_x ,
103 vector<double>& taylor_y )
103 vector<double>& taylor_y ) override
104104 {
105105 size_t q1 = order_up + 1;
106106 # ifndef NDEBUG
150150 $head reverse$$
151151 $srccode%cpp% */
152152 // reverse mode routine called by CppAD
153 virtual bool reverse(
153 bool reverse(
154154 const vector<double>& parameter_x ,
155155 const vector<CppAD::ad_type_enum>& type_x ,
156156 size_t order_up ,
157157 const vector<double>& taylor_x ,
158158 const vector<double>& taylor_y ,
159159 vector<double>& partial_x ,
160 const vector<double>& partial_y )
160 const vector<double>& partial_y ) override
161161 {
162162 size_t q1 = order_up + 1;
163163 size_t n = taylor_x.size() / q1;
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
5151 $head for_type$$
5252 $srccode%cpp% */
5353 // calculate type_y
54 virtual bool for_type(
54 bool for_type(
5555 const vector<float>& parameter_x ,
5656 const vector<CppAD::ad_type_enum>& type_x ,
57 vector<CppAD::ad_type_enum>& type_y )
57 vector<CppAD::ad_type_enum>& type_y ) override
5858 { assert( parameter_x.size() == type_x.size() );
5959 bool ok = type_x.size() == 1; // n
6060 ok &= type_y.size() == 2; // m
6868 $head forward$$
6969 $srccode%cpp% */
7070 // forward mode routine called by CppAD
71 virtual bool forward(
71 bool forward(
7272 const vector<float>& parameter_x ,
7373 const vector<CppAD::ad_type_enum>& type_x ,
7474 size_t need_y ,
7575 size_t p ,
7676 size_t q ,
7777 const vector<float>& tx ,
78 vector<float>& tzy )
78 vector<float>& tzy ) override
7979 { size_t q1 = q + 1;
8080 # ifndef NDEBUG
8181 size_t n = tx.size() / q1;
122122 $head reverse$$
123123 $srccode%cpp% */
124124 // reverse mode routine called by CppAD
125 virtual bool reverse(
125 bool reverse(
126126 const vector<float>& parameter_x ,
127127 const vector<CppAD::ad_type_enum>& type_x ,
128128 size_t q ,
129129 const vector<float>& tx ,
130130 const vector<float>& tzy ,
131131 vector<float>& px ,
132 const vector<float>& pzy )
132 const vector<float>& pzy ) override
133133 { size_t q1 = q + 1;
134134 # ifndef NDEBUG
135135 size_t n = tx.size() / q1;
181181 $head jac_sparsity$$
182182 $srccode%cpp% */
183183 // Jacobian sparsity routine called by CppAD
184 virtual bool jac_sparsity(
184 bool jac_sparsity(
185185 const vector<float>& parameter_x ,
186186 const vector<CppAD::ad_type_enum>& type_x ,
187187 bool dependency ,
188188 const vector<bool>& select_x ,
189189 const vector<bool>& select_y ,
190 CppAD::sparse_rc< vector<size_t> >& pattern_out )
190 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
191191 {
192192 size_t n = select_x.size();
193193 size_t m = select_y.size();
221221 $head hes_sparsity$$
222222 $srccode%cpp% */
223223 // Hessian sparsity routine called by CppAD
224 virtual bool hes_sparsity(
224 bool hes_sparsity(
225225 const vector<float>& parameter_x ,
226226 const vector<CppAD::ad_type_enum>& type_x ,
227227 const vector<bool>& select_x ,
228228 const vector<bool>& select_y ,
229 CppAD::sparse_rc< vector<size_t> >& pattern_out )
229 CppAD::sparse_rc< vector<size_t> >& pattern_out ) override
230230 {
231231 assert( parameter_x.size() == select_x.size() );
232232 assert( select_y.size() == 2 );
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11
12 /*
13 $begin atomic_three_vector_op.cpp$$
14 $spell
15 op
16 enum
17 mul
18 div
19 vec_op
20 $$
21
22 $section Atomic Vector Element-wise Operators: Example and Test$$
23
24 $head Syntax$$
25 $codei%atomic_vector_op %vec_op%(%name%)
26 %$$
27 $icode%vec_op%(%x%, %y%)
28 %$$
29
30 $head Purpose$$
31
32 $subhead Vector Operations$$
33 This atomic function implements
34 $codei%
35 %y% = %u% %op% %v%
36 %$$
37 where $icode op$$, $icode u$$ and $icode v$$ are defined below.
38
39 $subhead base2ad$$
40 This also serves as an example for how one can
41 define $codei%AD<%Base%>%$$ atomic operations use
42 atomic operators (instead of element-wise operators).
43 This avoids expanding the atomic operator to may operations when
44 recording derivative calculations.
45 For example, notice the difference between $code forward_add$$
46 for the $code double$$ and the $code AD<double>$$ cases:
47 $srcthisfile%0%// BEGIN forward_add%// END forward_add%1%$$.
48
49 $head x$$
50 We use $icode x$$ to denote the argument to the atomic function.
51 The length of $icode x$$ is denoted by $icode n$$ and must be odd.
52 We use the notation $icode%m% = (%n% - 1) / 2%$$.
53
54 $head op$$
55 The value $icode%x%[0]%$$
56 is a constant parameter with the following possible values:
57 $srcthisfile%0%// BEGIN op_enum_t%// END op_enum_t%1%$$
58 We use $icode op$$ for the corresponding operator.
59
60 $head u$$
61 We use $icode u$$ to denote the following sub-vector of $icode x$$:
62 $codei%
63 %u% = ( %x%[1] , %...% , %x%[%m%] )
64 %$$
65
66 $head v$$
67 We use $icode v$$ to denote the following sub-vector of $icode x$$:
68 $codei%
69 %v% = ( %x%[%m% + 1] , %...% , %x%[2 * %m%] )
70 %$$
71
72 $head y$$
73 We use $icode y$$ to denote the atomic function return value.
74 The length of $icode y$$ is equal to $icode m$$.
75
76 $head AD<double>$$
77 During $code AD<double>$$ operations, copying variables
78 from one vector to another does not add any operations to the
79 resulting tape.
80
81
82 $head Source Code$$
83 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
84
85 $end
86 */
87 // BEGIN C++
88 # include <cppad/cppad.hpp>
89 namespace { // isolate items below to this file
90 //
91 // abbreviations
92 using CppAD::AD;
93 using CppAD::vector;
94 // ===========================================================================
95 class atomic_vector_op : public CppAD::atomic_three<double> {
96 //
97 public:
98 // BEGIN op_enum_t
99 // atomic_vector_op::op_enum_t
100 typedef enum {
101 add_enum,
102 sub_enum,
103 mul_enum,
104 div_enum,
105 num_op,
106 } op_enum_t;
107 // END op_enum_t
108 //
109 // ctor
110 atomic_vector_op(const std::string& name) :
111 CppAD::atomic_three<double>(name)
112 { }
113 private:
114 // ------------------------------------------------------------------------
115 // copy routines
116 // ------------------------------------------------------------------------
117 static void copy_atx_to_ax(
118 size_t n,
119 size_t m,
120 size_t q,
121 size_t k_u,
122 size_t k_v,
123 const vector< AD<double> >& atx,
124 vector< AD<double> >& ax)
125 { assert( atx.size() == n * (q+1) );
126 assert( ax.size() == n );
127 for(size_t i = 0; i < m; ++i)
128 { size_t u_index = (1 + i) * (q+1) + k_u;
129 size_t v_index = (1 + m + i) * (q+1) + k_v;
130 ax[1 + i] = atx[u_index];
131 ax[1 + m +i] = atx[v_index];
132 }
133 }
134 static void copy_ay_to_aty(
135 size_t n,
136 size_t m,
137 size_t q,
138 size_t k,
139 const vector< AD<double> >& ay,
140 vector< AD<double> >& aty)
141 { assert( aty.size() == m * (q+1) );
142 assert( ay.size() == m );
143 for(size_t i = 0; i < m; ++i)
144 { size_t y_index = i * (q+1) + k;
145 aty[y_index] = ay[i];
146 }
147 }
148 static void copy_aty_to_au(
149 size_t n,
150 size_t m,
151 size_t q,
152 size_t k,
153 const vector< AD<double> >& aty,
154 vector< AD<double> >& ax)
155 { assert( aty.size() == m * (q+1) );
156 assert( ax.size() == n );
157 for(size_t i = 0; i < m; ++i)
158 { size_t y_index = i * (q+1) + k;
159 ax[1 + i] = aty[y_index];
160 }
161 }
162 static void copy_atx_to_av(
163 size_t n,
164 size_t m,
165 size_t q,
166 size_t k,
167 const vector< AD<double> >& atx,
168 vector< AD<double> >& ax)
169 { assert( atx.size() == n * (q+1) );
170 assert( ax.size() == n );
171 for(size_t i = 0; i < m; ++i)
172 { size_t v_index = (1 + m + i) * (q+1) + k;
173 ax[1 + m + i] = atx[v_index];
174 }
175 }
176 static void copy_atx_to_au(
177 size_t n,
178 size_t m,
179 size_t q,
180 size_t k,
181 const vector< AD<double> >& atx,
182 vector< AD<double> >& ax)
183 { assert( atx.size() == n * (q+1) );
184 assert( ax.size() == n );
185 for(size_t i = 0; i < m; ++i)
186 { size_t u_index = (1 + i) * (q+1) + k;
187 ax[1 + i] = atx[u_index];
188 }
189 }
190 // ------------------------------------------------------------------------
191 // for_type
192 // ------------------------------------------------------------------------
193 bool for_type(
194 const vector<double>& parameter_x ,
195 const vector<CppAD::ad_type_enum>& type_x ,
196 vector<CppAD::ad_type_enum>& type_y ) override
197 { // n, m
198 size_t n = parameter_x.size();
199 size_t m = (n - 1) / 2;
200 //
201 // ok
202 bool ok = type_x.size() == n;
203 ok &= type_y.size() == m;
204 if( ! ok )
205 return false;
206 //
207 // type_y
208 for(size_t i = 0; i < m; ++i)
209 type_y[i] = std::max( type_x[1 + i] , type_x[1 + m + i] );
210 //
211 return true;
212 }
213 // ----------------------------------------------------------------------
214 // forward_add
215 // ----------------------------------------------------------------------
216 // BEGIN forward_add
217 void forward_add(
218 size_t n ,
219 size_t m ,
220 size_t p ,
221 size_t q ,
222 const vector<double>& tx ,
223 vector<double>& ty )
224 {
225 for(size_t k = p; k <= q; ++k)
226 { for(size_t i = 0; i < m; ++i)
227 { size_t u_index = (1 + i) * (q+1) + k;
228 size_t v_index = (1 + m + i) * (q+1) + k;
229 size_t y_index = i * (q+1) + k;
230 // y_i^k = u_i^k + v_i^k
231 ty[y_index] = tx[u_index] + tx[v_index];
232 }
233 }
234 }
235 void forward_add(
236 size_t n ,
237 size_t m ,
238 size_t p ,
239 size_t q ,
240 const vector< AD<double> >& atx ,
241 vector< AD<double> >& aty )
242 { vector< AD<double> > ax(n), ay(m);
243 ax[0] = AD<double>( add_enum );
244 for(size_t k = p; k <= q; ++k)
245 { // ax = (op, u^k, v^k)
246 copy_atx_to_ax(n, m, q, k, k, atx, ax);
247 // ay = u^k + v^k
248 (*this)(ax, ay); // atomic vector add
249 // y^k = ay
250 copy_ay_to_aty(n, m, q, k, ay, aty);
251 }
252 }
253 // END forward_add
254 // ----------------------------------------------------------------------
255 // forward_sub
256 // ----------------------------------------------------------------------
257 void forward_sub(
258 size_t n ,
259 size_t m ,
260 size_t p ,
261 size_t q ,
262 const vector<double>& tx ,
263 vector<double>& ty )
264 {
265 for(size_t i = 0; i < m; ++i)
266 { for(size_t k = p; k <= q; ++k)
267 { size_t u_index = (1 + i) * (q+1) + k;
268 size_t v_index = (1 + m + i) * (q+1) + k;
269 size_t y_index = i * (q+1) + k;
270 // y_i^k = u_i^k - v_i^k
271 ty[y_index] = tx[u_index] - tx[v_index];
272 }
273 }
274 }
275 void forward_sub(
276 size_t n ,
277 size_t m ,
278 size_t p ,
279 size_t q ,
280 const vector< AD<double> >& atx ,
281 vector< AD<double> >& aty )
282 { vector< AD<double> > ax(n), ay(m);
283 ax[0] = AD<double>( sub_enum );
284 for(size_t k = p; k <= q; ++k)
285 { // ax = (op, u^k, v^k)
286 copy_atx_to_ax(n, m, q, k, k, atx, ax);
287 // ay = u^k - v^k
288 (*this)(ax, ay); // atomic vector subtract
289 // y^k = ay
290 copy_ay_to_aty(n, m, q, k, ay, aty);
291 }
292 }
293 // ----------------------------------------------------------------------
294 // forward_mul
295 // ----------------------------------------------------------------------
296 void forward_mul(
297 size_t n ,
298 size_t m ,
299 size_t p ,
300 size_t q ,
301 const vector<double>& tx ,
302 vector<double>& ty )
303 {
304 for(size_t i = 0; i < m; ++i)
305 { for(size_t k = p; k <= q; ++k)
306 { size_t y_index = i * (q+1) + k;
307 // y^k = 0
308 ty[y_index] = 0.0;
309 for(size_t d = 0; d <= k; d++)
310 { size_t u_index = (1 + i) * (q+1) + (k-d);
311 size_t v_index = (1 + m + i) * (q+1) + d;
312 // y^k += u^{k-d} * v^d
313 ty[y_index] += tx[u_index] * tx[v_index];
314 }
315 }
316 }
317 }
318 void forward_mul(
319 size_t n ,
320 size_t m ,
321 size_t p ,
322 size_t q ,
323 const vector< AD<double> >& atx ,
324 vector< AD<double> >& aty )
325 { vector< AD<double> > ax_mul(n), ax_add(n), ay(m);
326 ax_mul[0] = AD<double>( mul_enum );
327 ax_add[0] = AD<double>( add_enum );
328 for(size_t k = p; k <= q; ++k)
329 { // ay = 0
330 for(size_t i = 0; i < m; ++i)
331 ay[i] = 0.0;
332 for(size_t d = 0; d <= k; d++)
333 { // u_add = ay
334 for(size_t i = 0; i < m; ++i)
335 ax_add[1 + i] = ay[i];
336 //
337 // ax_mul = (op, u^{k-d}, v^d)
338 copy_atx_to_ax(n, m, q, k-d, d, atx, ax_mul);
339 //
340 // ay = u^{k-d} * v^d
341 (*this)(ax_mul, ay); // atomic vector multiply
342 //
343 // v_add = ay
344 for(size_t i = 0; i < m; ++i)
345 ax_add[1 + m + i] = ay[i];
346 //
347 // ay = u_add + v_add
348 (*this)(ax_add, ay); // atomic vector add
349 }
350 // y^k = ay
351 copy_ay_to_aty(n, m, q, k, ay, aty);
352 }
353 }
354 // ----------------------------------------------------------------------
355 // forward_div
356 // ----------------------------------------------------------------------
357 void forward_div(
358 size_t n ,
359 size_t m ,
360 size_t p ,
361 size_t q ,
362 const vector<double>& tx ,
363 vector<double>& ty )
364 {
365 for(size_t i = 0; i < m; ++i)
366 { for(size_t k = p; k <= q; ++k)
367 { size_t y_index = i * (q+1) + k;
368 size_t u_index = (1 + i) * (q+1) + k;
369 // y^k = u^k
370 ty[y_index] = tx[u_index];
371 for(size_t d = 1; d <= k; d++)
372 { size_t y_other = i * (q+1) + (k-d);
373 size_t v_index = (1 + m + i) * (q+1) + d;
374 // y^k -= y^{k-d} * v^d
375 ty[y_index] -= ty[y_other] * tx[v_index];
376 }
377 size_t v_index = (1 + m + i ) * (q+1) + 0;
378 // y^k /= v^0
379 ty[y_index] /= tx[v_index];
380 }
381 }
382 }
383 void forward_div(
384 size_t n ,
385 size_t m ,
386 size_t p ,
387 size_t q ,
388 const vector< AD<double> >& atx ,
389 vector< AD<double> >& aty )
390 { vector< AD<double> > ax_div(n), ax_mul(n), ax_sub(n), ay(m);
391 ax_div[0] = AD<double>( div_enum );
392 ax_mul[0] = AD<double>( mul_enum );
393 ax_sub[0] = AD<double>( sub_enum );
394 for(size_t k = p; k <= q; ++k)
395 { // u_sub = u^k
396 copy_atx_to_au(n, m, q, k, atx, ax_sub);
397 for(size_t d = 1; d <= k; d++)
398 { // u_mul = y^{k-d}
399 copy_aty_to_au(n, m, q, k-d, aty, ax_mul);
400 // v_mul = v^d
401 copy_atx_to_av(n, m, q, d, atx, ax_mul);
402 // ay = y^{k-d} * v^d
403 (*this)(ax_mul, ay); // atomic vector multiply
404 // v_sub = ay
405 for(size_t i = 0; i < m; ++i)
406 ax_sub[1 + m + i] = ay[i];
407 // ay = u_sub - v_sub
408 (*this)(ax_sub, ay); // atomic vector subtract
409 // u_sub = ay
410 for(size_t i = 0; i < m; ++i)
411 ax_sub[1 + i] = ay[i];
412 }
413 // u_div = u_sub
414 for(size_t i = 0; i < m; ++i)
415 ax_div[1 + i] = ax_sub[1 + i];
416 // v_div = v^0
417 copy_atx_to_av(n, m, q, 0, atx, ax_div);
418 // ay = u_div / v_div
419 (*this)(ax_div, ay); // atomic vector divide
420 // y^k = ay
421 copy_ay_to_aty(n, m, q, k, ay, aty);
422 }
423 }
424 // ----------------------------------------------------------------------
425 // forward
426 // forward mode routines called by ADFun<Base> objects
427 // ----------------------------------------------------------------------
428 bool forward(
429 const vector<double>& parameter_x ,
430 const vector<CppAD::ad_type_enum>& type_x ,
431 size_t need_y ,
432 size_t p ,
433 size_t q ,
434 const vector<double>& tx ,
435 vector<double>& ty ) override
436 {
437 // op, n, m
438 op_enum_t op = op_enum_t( parameter_x[0] );
439 size_t n = parameter_x.size();
440 size_t m = (n - 1) / 2;
441 //
442 assert( tx.size() == (q+1) * n );
443 assert( ty.size() == (q+1) * m );
444 //
445 switch(op)
446 {
447 // addition
448 case add_enum:
449 forward_add(n, m, q, p, tx, ty);
450 break;
451
452 // subtraction
453 case sub_enum:
454 forward_sub(n, m, q, p, tx, ty);
455 break;
456
457 // multiplication
458 case mul_enum:
459 forward_mul(n, m, q, p, tx, ty);
460 break;
461
462 // division
463 case div_enum:
464 forward_div(n, m, q, p, tx, ty);
465 break;
466
467 // error
468 case num_op:
469 assert(false);
470 break;
471 }
472 return true;
473 }
474 // ----------------------------------------------------------------------
475 // forward
476 // forward mode routines called by ADFun< AD<Base> , Base> objects
477 // ----------------------------------------------------------------------
478 bool forward(
479 const vector< AD<double> >& aparameter_x ,
480 const vector<CppAD::ad_type_enum>& type_x ,
481 size_t need_y ,
482 size_t p ,
483 size_t q ,
484 const vector< AD<double> >& atx ,
485 vector< AD<double> >& aty ) override
486 { //
487 // op, n, m
488 op_enum_t op = op_enum_t( Value( aparameter_x[0] ) );
489 size_t n = aparameter_x.size();
490 size_t m = (n - 1) / 2;
491 //
492 assert( atx.size() == (q+1) * n );
493 assert( aty.size() == (q+1) * m );
494 //
495 bool ok;
496 switch(op)
497 {
498 // addition
499 case add_enum:
500 forward_add(n, m, q, p, atx, aty);
501 ok = true;
502 break;
503
504 // subtraction
505 case sub_enum:
506 forward_sub(n, m, q, p, atx, aty);
507 ok = true;
508 break;
509
510 // multiplication
511 case mul_enum:
512 forward_mul(n, m, q, p, atx, aty);
513 ok = true;
514 break;
515
516 // division
517 case div_enum:
518 forward_div(n, m, q, p, atx, aty);
519 ok = true;
520 break;
521
522 // error
523 case num_op:
524 assert(false);
525 ok = false;
526 break;
527 }
528 return ok;
529 }
530
531 }; // End of atomic_vector_op class
532 // ============================================================================
533 bool test_atom_double(void)
534 { bool ok = true;
535 using CppAD::NearEqual;
536 double eps99 = 99.0 * CppAD::numeric_limits<double>::epsilon();
537 //
538 // vec_op
539 // atomic vector_op object
540 atomic_vector_op vec_op("atomic_vector_op");
541 //
542 // m, n
543 // size of x and y
544 size_t m = 2;
545 size_t n = 1 + 2 * m;
546 //
547 // op_enum_t
548 typedef atomic_vector_op::op_enum_t op_enum_t;
549 //
550 // num_op
551 size_t num_op = size_t( atomic_vector_op::num_op );
552 //
553 // i_op
554 for(size_t i_op = 0; i_op < num_op; ++i_op)
555 { //
556 // op
557 op_enum_t op = op_enum_t(i_op);
558 //
559 // Create the function f(x) = u op v
560 CPPAD_TESTVECTOR( AD<double> ) auv(2 * m);
561 for(size_t i = 0; i < m; i++)
562 { auv[i] = double(i+1); // u[i]
563 auv[m + i] = double(i+2); // v[i]
564 }
565 // declare independent variables and start tape recording
566 CppAD::Independent(auv);
567 //
568 // ax, ay
569 CPPAD_TESTVECTOR( AD<double> ) ax(n), ay(m);
570 ax[0] = AD<double>(op); // code for this operator
571 for(size_t i = 0; i < m; ++i)
572 { ax[1 + i] = auv[i];
573 ax[1 + m + i] = auv[m + i];
574 }
575 //
576 // ay = u op v
577 vec_op(ax, ay);
578 //
579 // create f: x -> y and stop tape recording
580 CppAD::ADFun<double> f;
581 f.Dependent (auv, ay);
582 //
583 // uv, y
584 CPPAD_TESTVECTOR(double) uv(2*m), duv(2*m), y(m), dy(m);
585 for(size_t j = 0; j < 2*m; ++j)
586 { uv[j] = double(1 + j);
587 duv[j] = double(1);
588 }
589 y = f.Forward(0, uv);
590 dy = f.Forward(1, duv);
591 //
592 for(size_t i = 0; i < m; ++i)
593 { double check_y, check_dy, den_sq;
594 switch(op)
595 {
596 case atomic_vector_op::add_enum:
597 check_y = uv[i] + uv[m + i];
598 check_dy = duv[i] + duv[m + i];
599 break;
600
601 case atomic_vector_op::sub_enum:
602 check_y = uv[i] - uv[m + i];
603 check_dy = duv[i] - duv[m + i];
604 break;
605
606 case atomic_vector_op::mul_enum:
607 check_y = uv[i] * uv[m + i];
608 check_dy = duv[i + 1] * uv[m + i]
609 + uv[i] * duv[m + i];
610 break;
611
612 case atomic_vector_op::div_enum:
613 den_sq = uv[m + i] * uv[m + i];
614 check_y = uv[i] / uv[m + i];
615 check_dy = duv[i] / uv[m + i]
616 - uv[i] * duv[m + i] / den_sq;
617 break;
618
619 case atomic_vector_op::num_op:
620 assert( false );
621 break;
622 }
623 ok &= NearEqual( y[i] , check_y, eps99, eps99);
624 ok &= NearEqual( dy[i] , check_dy, eps99, eps99);
625 }
626 }
627 return ok;
628 }
629 // ============================================================================
630 bool test_atom_ad_double(void)
631 { bool ok = true;
632 using CppAD::NearEqual;
633 double eps99 = 99.0 * CppAD::numeric_limits<double>::epsilon();
634 //
635 // vec_op
636 // atomic vector_op object
637 atomic_vector_op vec_op("atomic_vector_op");
638 //
639 // m, n
640 // size of x and y
641 size_t m = 2;
642 size_t n = 1 + 2 * m;
643 //
644 // op_enum_t
645 typedef atomic_vector_op::op_enum_t op_enum_t;
646 //
647 // num_op
648 size_t num_op = size_t( atomic_vector_op::num_op );
649 //
650 // i_op
651 for(size_t i_op = 0; i_op < num_op - 1; ++i_op)
652 { //
653 // op
654 op_enum_t op = op_enum_t(i_op);
655 //
656 // Create the function f(x) = u op v
657 CPPAD_TESTVECTOR( AD<double> ) auv(2 * m);
658 for(size_t j = 0; j < 2 * m; ++j)
659 auv[j] = double(1 + j);
660 //
661 // declare independent variables and start tape recording
662 CppAD::Independent(auv);
663 //
664 // ax, ay
665 CPPAD_TESTVECTOR( AD<double> ) ax(n), ay(m);
666 ax[0] = AD<double>(op); // code for this operator
667 for(size_t i = 0; i < m; ++i)
668 { ax[1 + i] = auv[i];
669 ax[1 + m + i] = auv[m + i];
670 }
671 //
672 // ay = u op v
673 vec_op(ax, ay);
674 //
675 // create f: x -> y and stop tape recording
676 CppAD::ADFun<double> f(auv, ay);
677 //
678 // af
679 CppAD::ADFun< AD<double>, double> af = f.base2ad();
680 //
681 // Create the function g(x) where g_i(x) = d/dv[i] f_i(x) using the
682 // fact that d/dv[j] f_i (x) is zero when i is not equal to j
683 CppAD::Independent(auv);
684 CPPAD_TESTVECTOR( AD<double> ) aduv(2 * m), az(m);
685 for(size_t i = 0; i < m; ++i)
686 { aduv[i] = 0.0; // du[i]
687 aduv[m + i] = 1.0; // dv[i]
688 }
689 af.Forward(0, auv);
690 az = af.Forward(1, aduv);
691 CppAD::ADFun<double> g(auv, az);
692 //
693 // uv, y
694 CPPAD_TESTVECTOR(double) uv(2 * m), z(m);
695 for(size_t j = 0; j < 2 * m; ++j)
696 uv[j] = double(1 + j);
697 z = g.Forward(0, uv);
698 //
699 for(size_t i = 0; i < m; ++i)
700 { double check_z;
701 switch(op)
702 {
703 case atomic_vector_op::add_enum:
704 check_z = 1.0;
705 break;
706
707 case atomic_vector_op::sub_enum:
708 check_z = - 1.0;
709 break;
710
711 case atomic_vector_op::mul_enum:
712 check_z = uv[i];
713 break;
714
715 case atomic_vector_op::div_enum:
716 check_z = - uv[i] / (uv[m + i] * uv[m + i]);
717 break;
718
719 case atomic_vector_op::num_op:
720 assert( false );
721 break;
722 }
723 ok &= NearEqual( z[i] , check_z, eps99, eps99);
724 }
725 }
726 return ok;
727 }
728 } // End empty namespace
729
730 bool vector_op(void)
731 { bool ok = true;
732 ok &= test_atom_double();
733 ok &= test_atom_ad_double();
734 return ok;
735 }
736 // END C++
275275 builddir = @builddir@
276276 compiler_has_conversion_warn = @compiler_has_conversion_warn@
277277 cppad_boostvector = @cppad_boostvector@
278 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
279278 cppad_cppadvector = @cppad_cppadvector@
280279 cppad_cxx_flags = @cppad_cxx_flags@
281280 cppad_description = @cppad_description@
330329 prefix = @prefix@
331330 program_transform_name = @program_transform_name@
332331 psdir = @psdir@
332 runstatedir = @runstatedir@
333333 sbindir = @sbindir@
334334 sharedstatedir = @sharedstatedir@
335335 srcdir = @srcdir@
273273 builddir = @builddir@
274274 compiler_has_conversion_warn = @compiler_has_conversion_warn@
275275 cppad_boostvector = @cppad_boostvector@
276 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
277276 cppad_cppadvector = @cppad_cppadvector@
278277 cppad_cxx_flags = @cppad_cxx_flags@
279278 cppad_description = @cppad_description@
328327 prefix = @prefix@
329328 program_transform_name = @program_transform_name@
330329 psdir = @psdir@
330 runstatedir = @runstatedir@
331331 sbindir = @sbindir@
332332 sharedstatedir = @sharedstatedir@
333333 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
7575 forward_order.cpp
7676 fun_assign.cpp
7777 fun_check.cpp
78 fun_property.cpp
79 function_name.cpp
7880 general.cpp
7981 hes_lagrangian.cpp
8082 hes_lu_det.cpp
108110 ode_stiff.cpp
109111 opt_val_hes.cpp
110112 pow.cpp
113 pow_nan.cpp
111114 print_for.cpp
115 rev_checkpoint.cpp
112116 rev_one.cpp
113117 rev_two.cpp
114 rev_checkpoint.cpp
115118 reverse_one.cpp
116119 reverse_three.cpp
117120 reverse_two.cpp
118 seq_property.cpp
119121 sign.cpp
120122 sin.cpp
121123 sinh.cpp
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2626 // BEGIN C++
2727
2828 # include <cppad/cppad.hpp>
29 # define N_THETA 20
2930
3031 bool atan2(void)
3132 { bool ok = true;
32
33 //
3334 using CppAD::AD;
3435 using CppAD::NearEqual;
3536 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
36
37 // domain space vector
38 size_t n = 1;
39 double x0 = 0.5;
40 CPPAD_TESTVECTOR(AD<double>) x(n);
41 x[0] = x0;
42
43 // declare independent variables and start tape recording
44 CppAD::Independent(x);
45
46 // a temporary value
47 AD<double> sin_of_x0 = CppAD::sin(x[0]);
48 AD<double> cos_of_x0 = CppAD::cos(x[0]);
49
50 // range space vector
51 size_t m = 1;
52 CPPAD_TESTVECTOR(AD<double>) y(m);
53 y[0] = CppAD::atan2(sin_of_x0, cos_of_x0);
54
55 // create f: x -> y and stop tape recording
56 CppAD::ADFun<double> f(x, y);
57
58 // check value
59 ok &= NearEqual(y[0] , x0, eps99, eps99);
60
61 // forward computation of first partial w.r.t. x[0]
62 CPPAD_TESTVECTOR(double) dx(n);
63 CPPAD_TESTVECTOR(double) dy(m);
64 dx[0] = 1.;
65 dy = f.Forward(1, dx);
66 ok &= NearEqual(dy[0], 1., eps99, eps99);
67
68 // reverse computation of derivative of y[0]
69 CPPAD_TESTVECTOR(double) w(m);
70 CPPAD_TESTVECTOR(double) dw(n);
71 w[0] = 1.;
72 dw = f.Reverse(1, w);
73 ok &= NearEqual(dw[0], 1., eps99, eps99);
74
75 // use a VecAD<Base>::reference object with atan2
76 CppAD::VecAD<double> v(2);
77 AD<double> zero(0);
78 AD<double> one(1);
79 v[zero] = sin_of_x0;
80 v[one] = cos_of_x0;
81 AD<double> result = CppAD::atan2(v[zero], v[one]);
82 ok &= NearEqual(result, x0, eps99, eps99);
83
37 double pi = 2.0 * std::atan(1.0);
38 //
39 for(size_t k = 0; k < N_THETA; ++k)
40 { // theta
41 double theta = 2.0 * pi * double(k+1) / double(N_THETA) - pi;
42 //
43 // radius
44 double radius = 1.0 + double(k) / double(N_THETA);
45 //
46 // x, y
47 double x = radius * std::cos(theta);
48 double y = radius * std::sin(theta);
49 //
50 // au
51 CPPAD_TESTVECTOR(AD<double>) au(2);
52 au[0] = x;
53 au[1] = y;
54 CppAD::Independent(au);
55 //
56 // av
57 CPPAD_TESTVECTOR(AD<double>) av(1);
58 av[0] = CppAD::atan2(au[1], au[0]);
59 //
60 // f(x, y) = atan2(y, x)
61 CppAD::ADFun<double> f(au, av);
62 //
63 // check value
64 ok &= NearEqual(av[0] , theta, eps99, eps99);
65 //
66 // partial_x, partial_y
67 // see https://en.wikipedia.org/wiki/Atan2#Derivative
68 double partial_x = - y / (radius * radius);
69 double partial_y = x / (radius * radius);
70 //
71 // check forward mode
72 CPPAD_TESTVECTOR(double) du(2), dv(1);
73 du[0] = 1.0;
74 du[1] = 0.0;
75 dv = f.Forward(1, du);
76 ok &= NearEqual(dv[0], partial_x, eps99, eps99);
77 du[0] = 0.0;
78 du[1] = 1.0;
79 dv = f.Forward(1, du);
80 ok &= NearEqual(dv[0], partial_y, eps99, eps99);
81 //
82 // check reverse mode
83 CPPAD_TESTVECTOR(double) w(1);
84 CPPAD_TESTVECTOR(double) dw(2);
85 w[0] = 1.;
86 dw = f.Reverse(1, w);
87 ok &= NearEqual(dw[0], partial_x, eps99, eps99);
88 ok &= NearEqual(dw[1], partial_y, eps99, eps99);
89 //
90 }
8491 return ok;
8592 }
8693
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3535 Note that $latex x_j \log ( x_j ) \rightarrow 0 $$
3636 as $latex x_j \downarrow 0$$ and
3737 we need to handle the case $latex x_j = 0$$
38 in a special way to avoid multiplying zero by infinity.
38 in a special way to avoid returning zero times minus infinity.
3939
4040 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
4141
106106 // a case where x[3] is equal to zero
107107 check -= x[3] * log( x[3] );
108108 x[3] = 0.;
109 ok &= std::isnan( x[3] * log( x[3] ) );
109110
110111 // function value
111112 y = f.Forward(0, x);
112113 ok &= NearEqual(y[0], check, eps, eps);
113114
114115 // check derivative of y[0]
115 f.check_for_nan(false);
116116 w[0] = 1.;
117117 dw = f.Reverse(1, w);
118118 for(j = 0; j < n; j++)
119119 { if( x[j] > 0 )
120120 ok &= NearEqual(dw[j], log(x[j]) + 1., eps, eps);
121121 else
122 { // Note that in case where dw has type AD<double> and is a variable
123 // this dw[j] can be nan (zero times nan is not zero).
124122 ok &= NearEqual(dw[j], 0.0, eps, eps);
125 }
126123 }
127124
128125 return ok;
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3232
3333 using CppAD::AD;
3434 using CppAD::NearEqual;
35 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
3635
3736 // domain space vector
3837 size_t n = 1;
39 CPPAD_TESTVECTOR(AD<double>) x(n);
40 x[0] = 0.;
38 CPPAD_TESTVECTOR(AD<double>) ax(n);
39 ax[0] = 0.;
4140
4241 // declare independent variables and start tape recording
43 CppAD::Independent(x);
42 CppAD::Independent(ax);
4443
4544 // range space vector
46 size_t m = 6;
47 CPPAD_TESTVECTOR(AD<double>) y(m);
48 y[0] = fabs(x[0] - 1.);
49 y[1] = fabs(x[0]);
50 y[2] = fabs(x[0] + 1.);
45 size_t m = 3;
46 CPPAD_TESTVECTOR(AD<double>) ay(m);
47 ay[0] = fabs(ax[0] - 1.);
48 ay[1] = fabs(ax[0]);
49 ay[2] = fabs(ax[0] + 1.);
5150 //
52 y[3] = fabs(x[0] - 1.);
53 y[4] = fabs(x[0]);
54 y[5] = fabs(x[0] + 1.);
55
5651 // create f: x -> y and stop tape recording
57 CppAD::ADFun<double> f(x, y);
52 CppAD::ADFun<double> f(ax, ay);
5853
5954 // check values
60 ok &= (y[0] == 1.);
61 ok &= (y[1] == 0.);
62 ok &= (y[2] == 1.);
55 ok &= (ay[0] == 1.);
56 ok &= (ay[1] == 0.);
57 ok &= (ay[2] == 1.);
6358 //
64 ok &= (y[3] == 1.);
65 ok &= (y[4] == 0.);
66 ok &= (y[5] == 1.);
67
6859 // forward computation of partials w.r.t. a positive x[0] direction
6960 size_t p = 1;
7061 CPPAD_TESTVECTOR(double) dx(n), dy(m);
7162 dx[0] = 1.;
7263 dy = f.Forward(p, dx);
7364 ok &= (dy[0] == - dx[0]);
74 ok &= (dy[1] == 0. ); // used to be (dy[1] == + dx[0]);
65 ok &= (dy[1] == 0. );
7566 ok &= (dy[2] == + dx[0]);
7667 //
77 ok &= (dy[3] == - dx[0]);
78 ok &= (dy[4] == 0. ); // used to be (dy[1] == + dx[0]);
79 ok &= (dy[5] == + dx[0]);
80
8168 // forward computation of partials w.r.t. a negative x[0] direction
8269 dx[0] = -1.;
8370 dy = f.Forward(p, dx);
8471 ok &= (dy[0] == - dx[0]);
85 ok &= (dy[1] == 0. ); // used to be (dy[1] == - dx[0]);
72 ok &= (dy[1] == 0. );
8673 ok &= (dy[2] == + dx[0]);
8774 //
88 ok &= (dy[3] == - dx[0]);
89 ok &= (dy[4] == 0. ); // used to be (dy[1] == - dx[0]);
90 ok &= (dy[5] == + dx[0]);
91
9275 // reverse computation of derivative of y[0]
9376 p = 1;
9477 CPPAD_TESTVECTOR(double) w(m), dw(n);
95 w[0] = 1.; w[1] = 0.; w[2] = 0.; w[3] = 0.; w[4] = 0.; w[5] = 0.;
78 w[0] = 1.; w[1] = 0.; w[2] = 0;
9679 dw = f.Reverse(p, w);
9780 ok &= (dw[0] == -1.);
9881
9982 // reverse computation of derivative of y[1]
100 w[0] = 0.; w[1] = 1.;
83 w[0] = 0.; w[1] = 1.; w[2] = 0;
10184 dw = f.Reverse(p, w);
10285 ok &= (dw[0] == 0.);
10386
104 // reverse computation of derivative of y[5]
105 w[1] = 0.; w[5] = 1.;
87 // reverse computation of derivative of y[3]
88 w[0] = 0.; w[1] = 0.; w[2] = 1;
10689 dw = f.Reverse(p, w);
10790 ok &= (dw[0] == 1.);
10891
109 // use a VecAD<Base>::reference object with abs and fabs
110 CppAD::VecAD<double> v(1);
111 AD<double> zero(0);
112 v[zero] = -1;
113 AD<double> result = fabs(v[zero]);
114 ok &= NearEqual(result, 1., eps99, eps99);
115 result = fabs(v[zero]);
116 ok &= NearEqual(result, 1., eps99, eps99);
92 // use a VecAD<Base>::reference object with fabs
93 CppAD::VecAD<double> av(1);
94 AD<double> az(0);
95 av[az] = -1;
96 AD<double> a_result = fabs(av[az]);
97 ok &= a_result == 1.0;
11798
11899 return ok;
119100 }
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11
12 /*
13 $begin fun_property.cpp$$
14 $spell
15 op
16 arg
17 abs
18 var
19 VecAD
20 $$
21
22 $section ADFun Function Properties: Example and Test$$
23
24 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
25
26 $end
27 */
28 // BEGIN C++
29
30 # include <cppad/cppad.hpp>
31
32 // Note that CPPAD_VEC_ENUM_TYPE is not part of CppAD API and may change
33 # define CPPAD_VEC_ENUM_TYPE unsigned char
34
35 bool fun_property(void)
36 { bool ok = true;
37 using CppAD::AD;
38
39 // Use nvar to track the number of variables in the operation sequence.
40 // Start with one for the phantom variable at tape address zero.
41 size_t nvar = 1;
42
43 // Use npar to track the number of parameters in the operation sequence.
44 // Start with one for the phantom parameter at index zero.
45 size_t npar = 1;
46
47 // Use ndyn to track the number of dynamic parameters.
48 size_t ndyn = 0;
49
50 // Use ndyn to track number of arguments to dynamic parameter operators.
51 size_t ndyn_arg = 0;
52
53 // Start with one for operator corresponding to phantom variable
54 size_t nop = 1;
55
56 // Start with one for operator corresponding to phantom argument
57 size_t narg = 1;
58
59 // Use ntext to track the number of characters used to label
60 // output generated using PrintFor commands.
61 size_t ntext = 0;
62
63 // Use nvecad to track the number of VecAD vectors, plus the number
64 // of VecAD vector elements, in the operation sequence.
65 size_t nvecad = 0;
66
67 // a VecAD vector
68 CppAD::VecAD<double> v(2);
69 v[0] = 0; // requires the parameter 0, when becomes a variable
70 v[1] = 1; // requires the parameter 1, when becomes a variable
71
72 // domain space vector
73 size_t n = 2;
74 CPPAD_TESTVECTOR(AD<double>) x(n);
75 x[0] = 0.;
76 x[1] = 1.;
77
78 // dynamic parameter vector
79 CPPAD_TESTVECTOR(AD<double>) dynamic(1);
80 dynamic[0] = 1.;
81
82
83 // declare independent variables and start tape recording
84 size_t abort_op_index = 0;
85 bool record_compare = true;
86 CppAD::Independent(x, abort_op_index, record_compare, dynamic);
87 nvar += n;
88 nop += n;
89 ndyn += dynamic.size();
90 npar += ndyn;
91
92 // a computation that adds to the operation sequence
93 AD<double> I = 0;
94 v[I] = x[0];
95 nvecad += 3; // one for vector, two for its elements
96 npar += 2; // need parameters 0 and 1 for initial v
97 nop += 1; // operator for storing in a VecAD object
98 narg += 3; // the three arguments are v, I, and x[0]
99
100 // some operations that do not add to the operation sequence
101 AD<double> u = x[0]; // use same variable as x[0]
102 AD<double> w = x[1]; // use same variable as x[1]
103
104 // a computation that adds to the operation sequence
105 w = w * (u + w);
106 nop += 2; // requires two new operators, an add and a multiply
107 nvar += 2; // each operator results in its own variable
108 narg += 4; // each operator has two arguments
109
110 // range space vector
111 size_t m = 3;
112 CPPAD_TESTVECTOR(AD<double>) y(m);
113
114 // operations that do not add to the operation sequence
115 y[0] = 1.; // re-use the parameter 1
116 y[1] = u; // use same variable as u
117
118 // a computation that adds to the operation sequence
119 y[2] = w + 2.;
120 nop += 1; // requires a new add operator
121 npar += 1; // new parameter 2 is new, so it must be included
122 nvar += 1; // variable corresponding to the result
123 narg += 2; // operator has two arguments
124
125 // create f: x -> y and stop tape recording
126 CppAD::ADFun<double> f(x, y);
127 nop += 1; // special operator for y[0] because it is a parameter
128 nvar += 1; // special variable for y[0] because it is a parameter
129 narg += 1; // identifies which parameter corresponds to y[0]
130 nop += 1; // special operator at the end of operation sequence
131
132 // check the sequence property functions
133 ok &= f.Domain() == n;
134 ok &= f.Range() == m;
135 ok &= f.Parameter(0) == true;
136 ok &= f.Parameter(1) == false;
137 ok &= f.Parameter(2) == false;
138 ok &= f.size_var() == nvar;
139 ok &= f.size_op() == nop;
140 ok &= f.size_op_arg() == narg;
141 ok &= f.size_par() == npar;
142 ok &= f.size_text() == ntext;
143 ok &= f.size_VecAD() == nvecad;
144 ok &= f.size_dyn_ind() == ndyn;
145 ok &= f.size_dyn_par() == ndyn;
146 ok &= f.size_dyn_arg() == ndyn_arg;
147
148 //
149 size_t sum = 0;
150 sum += nop * sizeof(CPPAD_VEC_ENUM_TYPE);
151 sum += narg * sizeof(CPPAD_TAPE_ADDR_TYPE);
152 sum += npar * sizeof(double);
153 sum += npar * sizeof(bool);
154 sum += ndyn * sizeof(CPPAD_VEC_ENUM_TYPE);
155 sum += ndyn * sizeof(CPPAD_TAPE_ADDR_TYPE);
156 sum += ndyn_arg * sizeof(CPPAD_TAPE_ADDR_TYPE);
157 sum += ntext * sizeof(char);
158 sum += nvecad * sizeof(CPPAD_TAPE_ADDR_TYPE);
159 ok &= f.size_op_seq() == sum;
160
161 return ok;
162 }
163
164 // END C++
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11
12 /*
13 $begin function_name.cpp$$
14 $spell
15 $$
16
17 $section ADFun Function Name: Example and Test$$
18
19 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
20
21 $end
22 */
23 // BEGIN C++
24
25 # include <cppad/cppad.hpp>
26
27 bool function_name(void)
28 { bool ok = true;
29 using CppAD::AD;
30
31 // create empty function
32 CppAD::ADFun<double> f;
33
34 // check its name
35 ok &= f.function_name_get() == "";
36
37 // set and check a new name
38 f.function_name_set("empty_function");
39 ok &= f.function_name_get() == "empty_function";
40
41 // store an operation sequence in f
42 size_t nx = 1;
43 size_t ny = 1;
44 CPPAD_TESTVECTOR( AD<double> ) ax(nx), ay(ny);
45 ax[0] = 1.0;
46 CppAD::Independent(ax);
47 ay[0] = sin(ax[0]);
48 f.Dependent(ax, ay);
49
50 // check fucntion name has not changed
51 ok &= f.function_name_get() == "empty_function";
52
53 // now set a better name for this function
54 f.function_name_set("sin");
55 ok &= f.function_name_get() == "sin";
56
57 return ok;
58 }
59
60 // END C++
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
125125 extern bool forward_dir(void);
126126 extern bool forward_order(void);
127127 extern bool fun_assign(void);
128 extern bool fun_property(void);
129 extern bool function_name(void);
128130 extern bool interp_onetape(void);
129131 extern bool interp_retape(void);
130132 extern bool log(void);
140142 extern bool number_skip(void);
141143 extern bool opt_val_hes(void);
142144 extern bool pow(void);
145 extern bool pow_nan(void);
143146 extern bool print_for(void);
144147 extern bool rev_checkpoint(void);
145148 extern bool reverse_one(void);
146149 extern bool reverse_three(void);
147150 extern bool reverse_two(void);
148 extern bool seq_property(void);
149151 extern bool sign(void);
150152 extern bool taylor_ode(void);
151153 extern bool vec_ad(void);
237239 Run( forward_dir, "forward_dir" );
238240 Run( forward_order, "forward_order" );
239241 Run( fun_assign, "fun_assign" );
242 Run( fun_property, "fun_property" );
243 Run( function_name, "function_name" );
240244 Run( interp_onetape, "interp_onetape" );
241245 Run( interp_retape, "interp_retape" );
242246 Run( log, "log" );
250254 Run( number_skip, "number_skip" );
251255 Run( opt_val_hes, "opt_val_hes" );
252256 Run( pow, "pow" );
257 Run( pow_nan, "pow_nan" );
253258 Run( rev_checkpoint, "rev_checkpoint" );
254259 Run( reverse_one, "reverse_one" );
255260 Run( reverse_three, "reverse_three" );
256261 Run( reverse_two, "reverse_two" );
257 Run( seq_property, "seq_property" );
258262 Run( sign, "sign" );
259263 Run( taylor_ode, "ode_taylor" );
260264 Run( vec_ad, "vec_ad" );
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
4747 #
4848 LDADD = $(ADOLC_LIB)
4949 #
50 # BEGIN_SORT_THIS_LINE_PLUS_5
5051 general_SOURCES = \
5152 $(ADOLC_SRC_FILES) \
5253 $(EIGEN_SRC_FILES) \
5354 \
5455 abort_recording.cpp \
55 base2ad.cpp \
56 fabs.cpp \
5756 acos.cpp \
5857 acosh.cpp \
5958 ad_assign.cpp \
6059 ad_ctor.cpp \
61 add.cpp \
62 add_eq.cpp \
6360 ad_fun.cpp \
6461 ad_in_c.cpp \
6562 ad_input.cpp \
6663 ad_output.cpp \
64 add.cpp \
65 add_eq.cpp \
6766 asin.cpp \
6867 asinh.cpp \
68 atan.cpp \
6969 atan2.cpp \
70 atan.cpp \
7170 atanh.cpp \
7271 azmul.cpp \
72 base2ad.cpp \
7373 base_alloc.hpp \
7474 base_require.cpp \
7575 bender_quad.cpp \
7777 capacity_order.cpp \
7878 change_param.cpp \
7979 check_for_nan.cpp \
80 compare.cpp \
8081 compare_change.cpp \
81 compare.cpp \
8282 complex_poly.cpp \
83 con_dyn_var.cpp \
8384 cond_exp.cpp \
8485 cos.cpp \
8586 cosh.cpp \
8889 equal_op_seq.cpp \
8990 erf.cpp \
9091 erfc.cpp \
91 general.cpp \
9292 exp.cpp \
9393 expm1.cpp \
94 fabs.cpp \
9495 for_one.cpp \
9596 for_two.cpp \
9697 forward.cpp \
9899 forward_order.cpp \
99100 fun_assign.cpp \
100101 fun_check.cpp \
102 fun_property.cpp \
103 function_name.cpp \
104 general.cpp \
101105 hes_lagrangian.cpp \
102106 hes_lu_det.cpp \
103107 hes_minor_det.cpp \
108 hes_times_dir.cpp \
104109 hessian.cpp \
105 hes_times_dir.cpp \
106110 independent.cpp \
107111 integer.cpp \
108112 interface2c.cpp\
111115 jac_lu_det.cpp \
112116 jac_minor_det.cpp \
113117 jacobian.cpp \
118 log.cpp \
114119 log10.cpp \
115120 log1p.cpp \
116 log.cpp \
117121 lu_ratio.cpp \
118122 lu_vec_ad.cpp \
119123 lu_vec_ad.hpp \
124128 mul_level_ode.cpp \
125129 near_equal_ext.cpp \
126130 new_dynamic.cpp \
131 num_limits.cpp \
127132 number_skip.cpp \
128133 numeric_type.cpp \
129 num_limits.cpp \
130134 ode_stiff.cpp \
131 taylor_ode.cpp \
132135 opt_val_hes.cpp \
133 con_dyn_var.cpp \
134136 pow.cpp \
137 pow_nan.cpp \
135138 print_for.cpp \
136139 rev_checkpoint.cpp \
140 rev_one.cpp \
141 rev_two.cpp \
137142 reverse_one.cpp \
138143 reverse_three.cpp \
139144 reverse_two.cpp \
140 rev_one.cpp \
141 rev_two.cpp \
142 seq_property.cpp \
143145 sign.cpp \
144146 sin.cpp \
145147 sinh.cpp \
150152 tan.cpp \
151153 tanh.cpp \
152154 tape_index.cpp \
155 taylor_ode.cpp \
153156 unary_minus.cpp \
154157 unary_plus.cpp \
155158 value.cpp \
156159 var2par.cpp \
157160 vec_ad.cpp
161 # END_SORT_THIS_LINE_MINUS_2
158162
159163 test: check
160164 ./general
9797 CONFIG_CLEAN_FILES =
9898 CONFIG_CLEAN_VPATH_FILES =
9999 am__general_SOURCES_DIST = mul_level_adolc.cpp mul_level_adolc_ode.cpp \
100 eigen_det.cpp eigen_array.cpp abort_recording.cpp base2ad.cpp \
101 fabs.cpp acos.cpp acosh.cpp ad_assign.cpp ad_ctor.cpp add.cpp \
102 add_eq.cpp ad_fun.cpp ad_in_c.cpp ad_input.cpp ad_output.cpp \
103 asin.cpp asinh.cpp atan2.cpp atan.cpp atanh.cpp azmul.cpp \
100 eigen_det.cpp eigen_array.cpp abort_recording.cpp acos.cpp \
101 acosh.cpp ad_assign.cpp ad_ctor.cpp ad_fun.cpp ad_in_c.cpp \
102 ad_input.cpp ad_output.cpp add.cpp add_eq.cpp asin.cpp \
103 asinh.cpp atan.cpp atan2.cpp atanh.cpp azmul.cpp base2ad.cpp \
104104 base_alloc.hpp base_require.cpp bender_quad.cpp bool_fun.cpp \
105105 capacity_order.cpp change_param.cpp check_for_nan.cpp \
106 compare_change.cpp compare.cpp complex_poly.cpp cond_exp.cpp \
107 cos.cpp cosh.cpp div.cpp div_eq.cpp equal_op_seq.cpp erf.cpp \
108 erfc.cpp general.cpp exp.cpp expm1.cpp for_one.cpp for_two.cpp \
109 forward.cpp forward_dir.cpp forward_order.cpp fun_assign.cpp \
110 fun_check.cpp hes_lagrangian.cpp hes_lu_det.cpp \
111 hes_minor_det.cpp hessian.cpp hes_times_dir.cpp \
112 independent.cpp integer.cpp interface2c.cpp interp_onetape.cpp \
113 interp_retape.cpp jac_lu_det.cpp jac_minor_det.cpp \
114 jacobian.cpp log10.cpp log1p.cpp log.cpp lu_ratio.cpp \
115 lu_vec_ad.cpp lu_vec_ad.hpp lu_vec_ad_ok.cpp mul.cpp \
116 mul_eq.cpp mul_level.cpp mul_level_ode.cpp near_equal_ext.cpp \
117 new_dynamic.cpp number_skip.cpp numeric_type.cpp \
118 num_limits.cpp ode_stiff.cpp taylor_ode.cpp opt_val_hes.cpp \
119 con_dyn_var.cpp pow.cpp print_for.cpp rev_checkpoint.cpp \
120 reverse_one.cpp reverse_three.cpp reverse_two.cpp rev_one.cpp \
121 rev_two.cpp seq_property.cpp sign.cpp sin.cpp sinh.cpp \
106 compare.cpp compare_change.cpp complex_poly.cpp \
107 con_dyn_var.cpp cond_exp.cpp cos.cpp cosh.cpp div.cpp \
108 div_eq.cpp equal_op_seq.cpp erf.cpp erfc.cpp exp.cpp expm1.cpp \
109 fabs.cpp for_one.cpp for_two.cpp forward.cpp forward_dir.cpp \
110 forward_order.cpp fun_assign.cpp fun_check.cpp \
111 fun_property.cpp function_name.cpp general.cpp \
112 hes_lagrangian.cpp hes_lu_det.cpp hes_minor_det.cpp \
113 hes_times_dir.cpp hessian.cpp independent.cpp integer.cpp \
114 interface2c.cpp interp_onetape.cpp interp_retape.cpp \
115 jac_lu_det.cpp jac_minor_det.cpp jacobian.cpp log.cpp \
116 log10.cpp log1p.cpp lu_ratio.cpp lu_vec_ad.cpp lu_vec_ad.hpp \
117 lu_vec_ad_ok.cpp mul.cpp mul_eq.cpp mul_level.cpp \
118 mul_level_ode.cpp near_equal_ext.cpp new_dynamic.cpp \
119 num_limits.cpp number_skip.cpp numeric_type.cpp ode_stiff.cpp \
120 opt_val_hes.cpp pow.cpp pow_nan.cpp print_for.cpp \
121 rev_checkpoint.cpp rev_one.cpp rev_two.cpp reverse_one.cpp \
122 reverse_three.cpp reverse_two.cpp sign.cpp sin.cpp sinh.cpp \
122123 sqrt.cpp stack_machine.cpp sub.cpp sub_eq.cpp tan.cpp tanh.cpp \
123 tape_index.cpp unary_minus.cpp unary_plus.cpp value.cpp \
124 var2par.cpp vec_ad.cpp
124 tape_index.cpp taylor_ode.cpp unary_minus.cpp unary_plus.cpp \
125 value.cpp var2par.cpp vec_ad.cpp
125126 @CppAD_ADOLC_TRUE@am__objects_1 = mul_level_adolc.$(OBJEXT) \
126127 @CppAD_ADOLC_TRUE@ mul_level_adolc_ode.$(OBJEXT)
127128 @CppAD_EIGEN_TRUE@am__objects_2 = eigen_det.$(OBJEXT) \
128129 @CppAD_EIGEN_TRUE@ eigen_array.$(OBJEXT)
129130 am_general_OBJECTS = $(am__objects_1) $(am__objects_2) \
130 abort_recording.$(OBJEXT) base2ad.$(OBJEXT) fabs.$(OBJEXT) \
131 acos.$(OBJEXT) acosh.$(OBJEXT) ad_assign.$(OBJEXT) \
132 ad_ctor.$(OBJEXT) add.$(OBJEXT) add_eq.$(OBJEXT) \
133 ad_fun.$(OBJEXT) ad_in_c.$(OBJEXT) ad_input.$(OBJEXT) \
134 ad_output.$(OBJEXT) asin.$(OBJEXT) asinh.$(OBJEXT) \
135 atan2.$(OBJEXT) atan.$(OBJEXT) atanh.$(OBJEXT) azmul.$(OBJEXT) \
136 base_require.$(OBJEXT) bender_quad.$(OBJEXT) \
131 abort_recording.$(OBJEXT) acos.$(OBJEXT) acosh.$(OBJEXT) \
132 ad_assign.$(OBJEXT) ad_ctor.$(OBJEXT) ad_fun.$(OBJEXT) \
133 ad_in_c.$(OBJEXT) ad_input.$(OBJEXT) ad_output.$(OBJEXT) \
134 add.$(OBJEXT) add_eq.$(OBJEXT) asin.$(OBJEXT) asinh.$(OBJEXT) \
135 atan.$(OBJEXT) atan2.$(OBJEXT) atanh.$(OBJEXT) azmul.$(OBJEXT) \
136 base2ad.$(OBJEXT) base_require.$(OBJEXT) bender_quad.$(OBJEXT) \
137137 bool_fun.$(OBJEXT) capacity_order.$(OBJEXT) \
138138 change_param.$(OBJEXT) check_for_nan.$(OBJEXT) \
139 compare_change.$(OBJEXT) compare.$(OBJEXT) \
140 complex_poly.$(OBJEXT) cond_exp.$(OBJEXT) cos.$(OBJEXT) \
141 cosh.$(OBJEXT) div.$(OBJEXT) div_eq.$(OBJEXT) \
142 equal_op_seq.$(OBJEXT) erf.$(OBJEXT) erfc.$(OBJEXT) \
143 general.$(OBJEXT) exp.$(OBJEXT) expm1.$(OBJEXT) \
139 compare.$(OBJEXT) compare_change.$(OBJEXT) \
140 complex_poly.$(OBJEXT) con_dyn_var.$(OBJEXT) \
141 cond_exp.$(OBJEXT) cos.$(OBJEXT) cosh.$(OBJEXT) div.$(OBJEXT) \
142 div_eq.$(OBJEXT) equal_op_seq.$(OBJEXT) erf.$(OBJEXT) \
143 erfc.$(OBJEXT) exp.$(OBJEXT) expm1.$(OBJEXT) fabs.$(OBJEXT) \
144144 for_one.$(OBJEXT) for_two.$(OBJEXT) forward.$(OBJEXT) \
145145 forward_dir.$(OBJEXT) forward_order.$(OBJEXT) \
146146 fun_assign.$(OBJEXT) fun_check.$(OBJEXT) \
147 hes_lagrangian.$(OBJEXT) hes_lu_det.$(OBJEXT) \
148 hes_minor_det.$(OBJEXT) hessian.$(OBJEXT) \
149 hes_times_dir.$(OBJEXT) independent.$(OBJEXT) \
150 integer.$(OBJEXT) interface2c.$(OBJEXT) \
147 fun_property.$(OBJEXT) function_name.$(OBJEXT) \
148 general.$(OBJEXT) hes_lagrangian.$(OBJEXT) \
149 hes_lu_det.$(OBJEXT) hes_minor_det.$(OBJEXT) \
150 hes_times_dir.$(OBJEXT) hessian.$(OBJEXT) \
151 independent.$(OBJEXT) integer.$(OBJEXT) interface2c.$(OBJEXT) \
151152 interp_onetape.$(OBJEXT) interp_retape.$(OBJEXT) \
152153 jac_lu_det.$(OBJEXT) jac_minor_det.$(OBJEXT) \
153 jacobian.$(OBJEXT) log10.$(OBJEXT) log1p.$(OBJEXT) \
154 log.$(OBJEXT) lu_ratio.$(OBJEXT) lu_vec_ad.$(OBJEXT) \
154 jacobian.$(OBJEXT) log.$(OBJEXT) log10.$(OBJEXT) \
155 log1p.$(OBJEXT) lu_ratio.$(OBJEXT) lu_vec_ad.$(OBJEXT) \
155156 lu_vec_ad_ok.$(OBJEXT) mul.$(OBJEXT) mul_eq.$(OBJEXT) \
156157 mul_level.$(OBJEXT) mul_level_ode.$(OBJEXT) \
157158 near_equal_ext.$(OBJEXT) new_dynamic.$(OBJEXT) \
158 number_skip.$(OBJEXT) numeric_type.$(OBJEXT) \
159 num_limits.$(OBJEXT) ode_stiff.$(OBJEXT) taylor_ode.$(OBJEXT) \
160 opt_val_hes.$(OBJEXT) con_dyn_var.$(OBJEXT) pow.$(OBJEXT) \
161 print_for.$(OBJEXT) rev_checkpoint.$(OBJEXT) \
162 reverse_one.$(OBJEXT) reverse_three.$(OBJEXT) \
163 reverse_two.$(OBJEXT) rev_one.$(OBJEXT) rev_two.$(OBJEXT) \
164 seq_property.$(OBJEXT) sign.$(OBJEXT) sin.$(OBJEXT) \
165 sinh.$(OBJEXT) sqrt.$(OBJEXT) stack_machine.$(OBJEXT) \
166 sub.$(OBJEXT) sub_eq.$(OBJEXT) tan.$(OBJEXT) tanh.$(OBJEXT) \
167 tape_index.$(OBJEXT) unary_minus.$(OBJEXT) \
159 num_limits.$(OBJEXT) number_skip.$(OBJEXT) \
160 numeric_type.$(OBJEXT) ode_stiff.$(OBJEXT) \
161 opt_val_hes.$(OBJEXT) pow.$(OBJEXT) pow_nan.$(OBJEXT) \
162 print_for.$(OBJEXT) rev_checkpoint.$(OBJEXT) rev_one.$(OBJEXT) \
163 rev_two.$(OBJEXT) reverse_one.$(OBJEXT) \
164 reverse_three.$(OBJEXT) reverse_two.$(OBJEXT) sign.$(OBJEXT) \
165 sin.$(OBJEXT) sinh.$(OBJEXT) sqrt.$(OBJEXT) \
166 stack_machine.$(OBJEXT) sub.$(OBJEXT) sub_eq.$(OBJEXT) \
167 tan.$(OBJEXT) tanh.$(OBJEXT) tape_index.$(OBJEXT) \
168 taylor_ode.$(OBJEXT) unary_minus.$(OBJEXT) \
168169 unary_plus.$(OBJEXT) value.$(OBJEXT) var2par.$(OBJEXT) \
169170 vec_ad.$(OBJEXT)
170171 general_OBJECTS = $(am_general_OBJECTS)
208209 ./$(DEPDIR)/for_one.Po ./$(DEPDIR)/for_two.Po \
209210 ./$(DEPDIR)/forward.Po ./$(DEPDIR)/forward_dir.Po \
210211 ./$(DEPDIR)/forward_order.Po ./$(DEPDIR)/fun_assign.Po \
211 ./$(DEPDIR)/fun_check.Po ./$(DEPDIR)/general.Po \
212 ./$(DEPDIR)/fun_check.Po ./$(DEPDIR)/fun_property.Po \
213 ./$(DEPDIR)/function_name.Po ./$(DEPDIR)/general.Po \
212214 ./$(DEPDIR)/hes_lagrangian.Po ./$(DEPDIR)/hes_lu_det.Po \
213215 ./$(DEPDIR)/hes_minor_det.Po ./$(DEPDIR)/hes_times_dir.Po \
214216 ./$(DEPDIR)/hessian.Po ./$(DEPDIR)/independent.Po \
226228 ./$(DEPDIR)/new_dynamic.Po ./$(DEPDIR)/num_limits.Po \
227229 ./$(DEPDIR)/number_skip.Po ./$(DEPDIR)/numeric_type.Po \
228230 ./$(DEPDIR)/ode_stiff.Po ./$(DEPDIR)/opt_val_hes.Po \
229 ./$(DEPDIR)/pow.Po ./$(DEPDIR)/print_for.Po \
230 ./$(DEPDIR)/rev_checkpoint.Po ./$(DEPDIR)/rev_one.Po \
231 ./$(DEPDIR)/rev_two.Po ./$(DEPDIR)/reverse_one.Po \
232 ./$(DEPDIR)/reverse_three.Po ./$(DEPDIR)/reverse_two.Po \
233 ./$(DEPDIR)/seq_property.Po ./$(DEPDIR)/sign.Po \
231 ./$(DEPDIR)/pow.Po ./$(DEPDIR)/pow_nan.Po \
232 ./$(DEPDIR)/print_for.Po ./$(DEPDIR)/rev_checkpoint.Po \
233 ./$(DEPDIR)/rev_one.Po ./$(DEPDIR)/rev_two.Po \
234 ./$(DEPDIR)/reverse_one.Po ./$(DEPDIR)/reverse_three.Po \
235 ./$(DEPDIR)/reverse_two.Po ./$(DEPDIR)/sign.Po \
234236 ./$(DEPDIR)/sin.Po ./$(DEPDIR)/sinh.Po ./$(DEPDIR)/sqrt.Po \
235237 ./$(DEPDIR)/stack_machine.Po ./$(DEPDIR)/sub.Po \
236238 ./$(DEPDIR)/sub_eq.Po ./$(DEPDIR)/tan.Po ./$(DEPDIR)/tanh.Po \
320322 CYGPATH_W = @CYGPATH_W@
321323
322324 # -----------------------------------------------------------------------------
323 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
325 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
324326 #
325327 # CppAD is distributed under the terms of the
326328 # Eclipse Public License Version 2.0.
403405 builddir = @builddir@
404406 compiler_has_conversion_warn = @compiler_has_conversion_warn@
405407 cppad_boostvector = @cppad_boostvector@
406 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
407408 cppad_cppadvector = @cppad_cppadvector@
408409 cppad_cxx_flags = @cppad_cxx_flags@
409410 cppad_description = @cppad_description@
458459 prefix = @prefix@
459460 program_transform_name = @program_transform_name@
460461 psdir = @psdir@
462 runstatedir = @runstatedir@
461463 sbindir = @sbindir@
462464 sharedstatedir = @sharedstatedir@
463465 srcdir = @srcdir@
492494 #
493495 LDADD = $(ADOLC_LIB)
494496 #
497 # BEGIN_SORT_THIS_LINE_PLUS_5
495498 general_SOURCES = \
496499 $(ADOLC_SRC_FILES) \
497500 $(EIGEN_SRC_FILES) \
498501 \
499502 abort_recording.cpp \
500 base2ad.cpp \
501 fabs.cpp \
502503 acos.cpp \
503504 acosh.cpp \
504505 ad_assign.cpp \
505506 ad_ctor.cpp \
506 add.cpp \
507 add_eq.cpp \
508507 ad_fun.cpp \
509508 ad_in_c.cpp \
510509 ad_input.cpp \
511510 ad_output.cpp \
511 add.cpp \
512 add_eq.cpp \
512513 asin.cpp \
513514 asinh.cpp \
515 atan.cpp \
514516 atan2.cpp \
515 atan.cpp \
516517 atanh.cpp \
517518 azmul.cpp \
519 base2ad.cpp \
518520 base_alloc.hpp \
519521 base_require.cpp \
520522 bender_quad.cpp \
522524 capacity_order.cpp \
523525 change_param.cpp \
524526 check_for_nan.cpp \
527 compare.cpp \
525528 compare_change.cpp \
526 compare.cpp \
527529 complex_poly.cpp \
530 con_dyn_var.cpp \
528531 cond_exp.cpp \
529532 cos.cpp \
530533 cosh.cpp \
533536 equal_op_seq.cpp \
534537 erf.cpp \
535538 erfc.cpp \
536 general.cpp \
537539 exp.cpp \
538540 expm1.cpp \
541 fabs.cpp \
539542 for_one.cpp \
540543 for_two.cpp \
541544 forward.cpp \
543546 forward_order.cpp \
544547 fun_assign.cpp \
545548 fun_check.cpp \
549 fun_property.cpp \
550 function_name.cpp \
551 general.cpp \
546552 hes_lagrangian.cpp \
547553 hes_lu_det.cpp \
548554 hes_minor_det.cpp \
555 hes_times_dir.cpp \
549556 hessian.cpp \
550 hes_times_dir.cpp \
551557 independent.cpp \
552558 integer.cpp \
553559 interface2c.cpp\
556562 jac_lu_det.cpp \
557563 jac_minor_det.cpp \
558564 jacobian.cpp \
565 log.cpp \
559566 log10.cpp \
560567 log1p.cpp \
561 log.cpp \
562568 lu_ratio.cpp \
563569 lu_vec_ad.cpp \
564570 lu_vec_ad.hpp \
569575 mul_level_ode.cpp \
570576 near_equal_ext.cpp \
571577 new_dynamic.cpp \
578 num_limits.cpp \
572579 number_skip.cpp \
573580 numeric_type.cpp \
574 num_limits.cpp \
575581 ode_stiff.cpp \
576 taylor_ode.cpp \
577582 opt_val_hes.cpp \
578 con_dyn_var.cpp \
579583 pow.cpp \
584 pow_nan.cpp \
580585 print_for.cpp \
581586 rev_checkpoint.cpp \
587 rev_one.cpp \
588 rev_two.cpp \
582589 reverse_one.cpp \
583590 reverse_three.cpp \
584591 reverse_two.cpp \
585 rev_one.cpp \
586 rev_two.cpp \
587 seq_property.cpp \
588592 sign.cpp \
589593 sin.cpp \
590594 sinh.cpp \
595599 tan.cpp \
596600 tanh.cpp \
597601 tape_index.cpp \
602 taylor_ode.cpp \
598603 unary_minus.cpp \
599604 unary_plus.cpp \
600605 value.cpp \
696701 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/forward_order.Po@am__quote@ # am--include-marker
697702 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fun_assign.Po@am__quote@ # am--include-marker
698703 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fun_check.Po@am__quote@ # am--include-marker
704 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fun_property.Po@am__quote@ # am--include-marker
705 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/function_name.Po@am__quote@ # am--include-marker
699706 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/general.Po@am__quote@ # am--include-marker
700707 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hes_lagrangian.Po@am__quote@ # am--include-marker
701708 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hes_lu_det.Po@am__quote@ # am--include-marker
730737 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ode_stiff.Po@am__quote@ # am--include-marker
731738 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opt_val_hes.Po@am__quote@ # am--include-marker
732739 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pow.Po@am__quote@ # am--include-marker
740 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pow_nan.Po@am__quote@ # am--include-marker
733741 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print_for.Po@am__quote@ # am--include-marker
734742 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rev_checkpoint.Po@am__quote@ # am--include-marker
735743 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rev_one.Po@am__quote@ # am--include-marker
737745 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reverse_one.Po@am__quote@ # am--include-marker
738746 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reverse_three.Po@am__quote@ # am--include-marker
739747 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reverse_two.Po@am__quote@ # am--include-marker
740 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/seq_property.Po@am__quote@ # am--include-marker
741748 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sign.Po@am__quote@ # am--include-marker
742749 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sin.Po@am__quote@ # am--include-marker
743750 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinh.Po@am__quote@ # am--include-marker
950957 -rm -f ./$(DEPDIR)/forward_order.Po
951958 -rm -f ./$(DEPDIR)/fun_assign.Po
952959 -rm -f ./$(DEPDIR)/fun_check.Po
960 -rm -f ./$(DEPDIR)/fun_property.Po
961 -rm -f ./$(DEPDIR)/function_name.Po
953962 -rm -f ./$(DEPDIR)/general.Po
954963 -rm -f ./$(DEPDIR)/hes_lagrangian.Po
955964 -rm -f ./$(DEPDIR)/hes_lu_det.Po
984993 -rm -f ./$(DEPDIR)/ode_stiff.Po
985994 -rm -f ./$(DEPDIR)/opt_val_hes.Po
986995 -rm -f ./$(DEPDIR)/pow.Po
996 -rm -f ./$(DEPDIR)/pow_nan.Po
987997 -rm -f ./$(DEPDIR)/print_for.Po
988998 -rm -f ./$(DEPDIR)/rev_checkpoint.Po
989999 -rm -f ./$(DEPDIR)/rev_one.Po
9911001 -rm -f ./$(DEPDIR)/reverse_one.Po
9921002 -rm -f ./$(DEPDIR)/reverse_three.Po
9931003 -rm -f ./$(DEPDIR)/reverse_two.Po
994 -rm -f ./$(DEPDIR)/seq_property.Po
9951004 -rm -f ./$(DEPDIR)/sign.Po
9961005 -rm -f ./$(DEPDIR)/sin.Po
9971006 -rm -f ./$(DEPDIR)/sinh.Po
11011110 -rm -f ./$(DEPDIR)/forward_order.Po
11021111 -rm -f ./$(DEPDIR)/fun_assign.Po
11031112 -rm -f ./$(DEPDIR)/fun_check.Po
1113 -rm -f ./$(DEPDIR)/fun_property.Po
1114 -rm -f ./$(DEPDIR)/function_name.Po
11041115 -rm -f ./$(DEPDIR)/general.Po
11051116 -rm -f ./$(DEPDIR)/hes_lagrangian.Po
11061117 -rm -f ./$(DEPDIR)/hes_lu_det.Po
11351146 -rm -f ./$(DEPDIR)/ode_stiff.Po
11361147 -rm -f ./$(DEPDIR)/opt_val_hes.Po
11371148 -rm -f ./$(DEPDIR)/pow.Po
1149 -rm -f ./$(DEPDIR)/pow_nan.Po
11381150 -rm -f ./$(DEPDIR)/print_for.Po
11391151 -rm -f ./$(DEPDIR)/rev_checkpoint.Po
11401152 -rm -f ./$(DEPDIR)/rev_one.Po
11421154 -rm -f ./$(DEPDIR)/reverse_one.Po
11431155 -rm -f ./$(DEPDIR)/reverse_three.Po
11441156 -rm -f ./$(DEPDIR)/reverse_two.Po
1145 -rm -f ./$(DEPDIR)/seq_property.Po
11461157 -rm -f ./$(DEPDIR)/sign.Po
11471158 -rm -f ./$(DEPDIR)/sin.Po
11481159 -rm -f ./$(DEPDIR)/sinh.Po
11931204
11941205 .PRECIOUS: makefile
11951206
1207 # END_SORT_THIS_LINE_MINUS_2
11961208
11971209 test: check
11981210 ./general
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11
12 /*
13 $begin pow_nan.cpp$$
14 $spell
15 $$
16
17 $section pow: Nan in Result of Pow Function: Example and Test$$
18
19 $head Purpose$$
20 The $cref%pow(x, y)%pow%$$ function will work when $latex x < 0$$ and
21 $latex y$$ is a parameter. It will often generate nan or infinity when
22 $latex x < 0$$ and one tries to compute a derivatives
23 (even if $latex y$$ is a positive integer).
24 This is because the derivative of the log is $latex 1 / x$$
25 and the power function uses the representation
26 $latex \[
27 \R{pow}(x, y) = \exp [ y \cdot \log(x) ]
28 \] $$
29
30 $head Problem$$
31 There is a problem with this representation when $latex y$$ is a parameter
32 and $latex x = 0$$. For example,
33 when $latex x = 0$$ and $latex y = 1$$, it returns zero for the derivative,
34 but the actual derivative w.r.t $latex x$$ is one.
35
36 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
37
38 $end
39 */
40 // BEGIN C++
41 # include <cppad/cppad.hpp>
42 # include <cmath>
43
44 bool pow_nan(void)
45 { bool ok = true;
46
47 using std::cout;
48 using CppAD::AD;
49 using CppAD::vector;
50 //
51 vector<double> x(2), y(2), dx(2), dy(2), ddx(2), ddy(2);
52 vector< AD<double> > ax(2), ay(2);
53 //
54 // variable vector
55 ax[0] = x[0] = -1.0;
56 ax[1] = x[1] = 2.0;
57 //
58 CppAD::Independent(ax);
59 //
60 ay[0] = pow( ax[0], ax[1] );
61 ay[1] = pow( ax[0], 2.0 );
62 //
63 CppAD::ADFun<double> f(ax, ay);
64 //
65 // check_for_nan is set false so it does not generate an assert
66 // when compiling with debugging
67 f.check_for_nan(false);
68 //
69 // Zero order forward does not generate nan
70 y = f.Forward(0, x);
71 ok &= y[0] == 1.0;
72 ok &= y[1] == 1.0;
73 //
74 // First order forward generates a nan
75 dx[0] = 1.0;
76 dx[1] = 1.0;
77 dy = f.Forward(1, dx);
78 ok &= std::isnan( dy[0] );
79 ok &= dy[1] == -2.0;
80 //
81 // Second order Taylor coefficient is 1/2 times second derivative
82 ddx[0] = 0.0;
83 ddx[1] = 0.0;
84 ddy = f.Forward(2, ddx);
85 ok &= std::isnan( ddy[0] );
86 ok &= ddy[1] == 1.0;
87 //
88 return ok;
89 }
90 // END C++
+0
-165
example/general/seq_property.cpp less more
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11
12 /*
13 $begin seq_property.cpp$$
14 $spell
15 op
16 arg
17 abs
18 var
19 VecAD
20 $$
21
22 $section ADFun Sequence Properties: Example and Test$$
23
24 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
25
26 $end
27 */
28 // BEGIN C++
29
30 # include <cppad/cppad.hpp>
31
32 // Note that CPPAD_VEC_ENUM_TYPE is not part of CppAD API and may change
33 # define CPPAD_VEC_ENUM_TYPE unsigned char
34
35 bool seq_property(void)
36 { bool ok = true;
37 using CppAD::AD;
38
39 // Use nvar to track the number of variables in the operation sequence.
40 // Start with one for the phantom variable at tape address zero.
41 size_t nvar = 1;
42
43 // Use npar to track the number of parameters in the operation sequence.
44 // Start with one for the phantom parameter at index zero.
45 size_t npar = 1;
46
47 // Use ndyn to track the number of dynamic parameters.
48 size_t ndyn = 0;
49
50 // Use ndyn to track number of arguments to dynamic parameter operators.
51 size_t ndyn_arg = 0;
52
53 // Start with one for operator corresponding to phantom variable
54 size_t nop = 1;
55
56 // Start with one for operator corresponding to phantom argument
57 size_t narg = 1;
58
59 // Use ntext to track the number of characters used to label
60 // output generated using PrintFor commands.
61 size_t ntext = 0;
62
63 // Use nvecad to track the number of VecAD vectors, plus the number
64 // of VecAD vector elements, in the operation sequence.
65 size_t nvecad = 0;
66
67 // a VecAD vector
68 CppAD::VecAD<double> v(2);
69 v[0] = 0; // requires the parameter 0, when becomes a variable
70 v[1] = 1; // requires the parameter 1, when becomes a variable
71
72 // domain space vector
73 size_t n = 2;
74 CPPAD_TESTVECTOR(AD<double>) x(n);
75 x[0] = 0.;
76 x[1] = 1.;
77
78 // dynamic parameter vector
79 CPPAD_TESTVECTOR(AD<double>) dynamic(1);
80 dynamic[0] = 1.;
81
82
83 // declare independent variables and start tape recording
84 size_t abort_op_index = 0;
85 bool record_compare = true;
86 CppAD::Independent(x, abort_op_index, record_compare, dynamic);
87 nvar += n;
88 nop += n;
89 ndyn += dynamic.size();
90 npar += ndyn;
91
92 // a computation that adds to the operation sequence
93 AD<double> I = 0;
94 v[I] = x[0];
95 nvecad += 3; // one for vector, two for its elements
96 npar += 2; // need parameters 0 and 1 for initial v
97 nop += 1; // operator for storing in a VecAD object
98 narg += 3; // the three arguments are v, I, and x[0]
99
100 // some operations that do not add to the operation sequence
101 AD<double> u = x[0]; // use same variable as x[0]
102 AD<double> w = x[1]; // use same variable as x[1]
103
104 // a computation that adds to the operation sequence
105 w = w * (u + w);
106 nop += 2; // requires two new operators, an add and a multiply
107 nvar += 2; // each operator results in its own variable
108 narg += 4; // each operator has two arguments
109
110 // range space vector
111 size_t m = 3;
112 CPPAD_TESTVECTOR(AD<double>) y(m);
113
114 // operations that do not add to the operation sequence
115 y[0] = 1.; // re-use the parameter 1
116 y[1] = u; // use same variable as u
117
118 // a computation that adds to the operation sequence
119 y[2] = w + 2.;
120 nop += 1; // requires a new add operator
121 npar += 1; // new parameter 2 is new, so it must be included
122 nvar += 1; // variable corresponding to the result
123 narg += 2; // operator has two arguments
124
125 // create f: x -> y and stop tape recording
126 CppAD::ADFun<double> f(x, y);
127 nop += 1; // special operator for y[0] because it is a parameter
128 nvar += 1; // special variable for y[0] because it is a parameter
129 narg += 1; // identifies which parameter corresponds to y[0]
130 nop += 1; // special operator at the end of operation sequence
131
132 // check the sequence property functions
133 ok &= f.Domain() == n;
134 ok &= f.Range() == m;
135 ok &= f.Parameter(0) == true;
136 ok &= f.Parameter(1) == false;
137 ok &= f.Parameter(2) == false;
138 ok &= f.size_var() == nvar;
139 ok &= f.size_op() == nop;
140 ok &= f.size_op_arg() == narg;
141 ok &= f.size_par() == npar;
142 ok &= f.size_text() == ntext;
143 ok &= f.size_VecAD() == nvecad;
144 ok &= f.size_dyn_ind() == ndyn;
145 ok &= f.size_dyn_par() == ndyn;
146 ok &= f.size_dyn_arg() == ndyn_arg;
147
148 //
149 size_t sum = 0;
150 sum += nop * sizeof(CPPAD_VEC_ENUM_TYPE);
151 sum += narg * sizeof(CPPAD_TAPE_ADDR_TYPE);
152 sum += npar * sizeof(double);
153 sum += npar * sizeof(bool);
154 sum += ndyn * sizeof(CPPAD_VEC_ENUM_TYPE);
155 sum += ndyn * sizeof(CPPAD_TAPE_ADDR_TYPE);
156 sum += ndyn_arg * sizeof(CPPAD_TAPE_ADDR_TYPE);
157 sum += ntext * sizeof(char);
158 sum += nvecad * sizeof(CPPAD_TAPE_ADDR_TYPE);
159 ok &= f.size_op_seq() == sum;
160
161 return ok;
162 }
163
164 // END C++
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1616 Cpp
1717 $$
1818
19 $section Convert an AD Variable to a Parameter: Example and Test$$
19 $section Convert a Variable or Dynamic Parameter a Constant: Example and Test$$
2020
2121
2222 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
3434 using CppAD::Value;
3535 using CppAD::Var2Par;
3636
37 // domain space vector
38 size_t n = 2;
39 CPPAD_TESTVECTOR(AD<double>) x(n);
40 x[0] = 3.;
41 x[1] = 4.;
37 // independent variables
38 size_t nx = 2;
39 CPPAD_TESTVECTOR(AD<double>) ax(nx);
40 ax[0] = 3.;
41 ax[1] = 4.;
4242
43 // declare independent variables and start tape recording
44 CppAD::Independent(x);
43 // independent dynamic paramers
44 size_t np = 1;
45 CPPAD_TESTVECTOR(AD<double>) ap(np);
46 ap[0] = 5.;
47
48 // declare independent variables and dynamic parameters
49 CppAD::Independent(ax, ap);
4550
4651 // range space vector
47 size_t m = 1;
48 CPPAD_TESTVECTOR(AD<double>) y(m);
49 y[0] = - x[1] * Var2Par(x[0]); // same as y[0] = -x[1] * 3.;
52 size_t ny = 2;
53 CPPAD_TESTVECTOR(AD<double>) ay(ny);
54 ay[0] = - ax[1] * Var2Par(ax[0]); // same as ay[0] = -ax[1] * 3.;
55 ay[1] = - ax[1] * Var2Par(ap[0]); // same as ay[1] = -ax[1] * 5.;
5056
51 // cannot call Value(x[j]) or Value(y[0]) here (currently variables)
52 ok &= ( Value( Var2Par(x[0]) ) == 3. );
53 ok &= ( Value( Var2Par(x[1]) ) == 4. );
54 ok &= ( Value( Var2Par(y[0]) ) == -12. );
57 // Must convert these objects to constants before calling Value
58 ok &= ( Value( Var2Par(ax[0]) ) == 3. );
59 ok &= ( Value( Var2Par(ax[1]) ) == 4. );
60 ok &= ( Value( Var2Par(ap[0]) ) == 5. );
61 ok &= ( Value( Var2Par(ay[0]) ) == -12. );
62 ok &= ( Value( Var2Par(ay[1]) ) == -20. );
5563
5664 // create f: x -> y and stop tape recording
57 CppAD::ADFun<double> f(x, y);
65 CppAD::ADFun<double> f(ax, ay);
5866
59 // can call Value(x[j]) or Value(y[0]) here (currently parameters)
60 ok &= (Value(x[0]) == 3.);
61 ok &= (Value(x[1]) == 4.);
62 ok &= (Value(y[0]) == -12.);
67 // All AD object are currently constants
68 ok &= (Value(ax[0]) == 3.);
69 ok &= (Value(ax[1]) == 4.);
70 ok &= (Value(ap[0]) == 5.);
71 ok &= (Value(ay[0]) == -12.);
72 ok &= (Value(ay[1]) == -20.);
6373
64 // evaluate derivative of y w.r.t x
65 CPPAD_TESTVECTOR(double) w(m);
66 CPPAD_TESTVECTOR(double) dw(n);
67 w[0] = 1.;
68 dw = f.Reverse(1, w);
69 ok &= (dw[0] == 0.); // derivative of y[0] w.r.t x[0] is zero
70 ok &= (dw[1] == -3.); // derivative of y[0] w.r.t x[1] is 3
74 // evaluate zero order forward mode
75 // (note that the only real variable in this recording is x[1])
76 CPPAD_TESTVECTOR(double) x(nx), p(np), y(ny);
77 x[0] = 6.;
78 x[1] = 7.;
79 p[0] = 8.;
80 f.new_dynamic(p);
81 y = f.Forward(0, x);
82 ok &= y[0] == - x[1] * 3.0;
83 ok &= y[1] == - x[1] * 5.0;
7184
7285 return ok;
7386 }
269269 builddir = @builddir@
270270 compiler_has_conversion_warn = @compiler_has_conversion_warn@
271271 cppad_boostvector = @cppad_boostvector@
272 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
273272 cppad_cppadvector = @cppad_cppadvector@
274273 cppad_cxx_flags = @cppad_cxx_flags@
275274 cppad_description = @cppad_description@
324323 prefix = @prefix@
325324 program_transform_name = @program_transform_name@
326325 psdir = @psdir@
326 runstatedir = @runstatedir@
327327 sbindir = @sbindir@
328328 sharedstatedir = @sharedstatedir@
329329 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2121 graph.cpp
2222 mul_op.cpp
2323 pow_op.cpp
24 print_graph.cpp
2425 print_op.cpp
2526 sub_op.cpp
2627 sum_op.cpp
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3535 extern bool div_op(void);
3636 extern bool mul_op(void);
3737 extern bool pow_op(void);
38 extern bool print_graph(void);
3839 extern bool print_op(void);
3940 extern bool sub_op(void);
4041 extern bool sum_op(void);
4445
4546 // main program that runs all the tests
4647 int main(void)
47 { std::string group = "test_more/graph";
48 { std::string group = "example/graph";
4849 size_t width = 20;
4950 CppAD::test_boolofvoid Run(group, width);
5051
6162 Run( discrete_op, "discrete_op" );
6263 Run( mul_op, "mul_op" );
6364 Run( pow_op, "pow_op" );
65 Run( print_graph, "print_graph" );
6466 Run( print_op, "print_op" );
6567 Run( sub_op, "sub_op" );
6668 Run( sum_op, "sum_op" );
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 /*
12 $begin print_graph.cpp$$
13 $spell
14 Json
15 $$
16
17 $section Print a C++ AD Graph: Example and Test$$
18
19 $head Source Code$$
20 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
21
22 $end
23 */
24 // BEGIN C++
25 # include <cppad/cppad.hpp>
26
27 bool print_graph(void)
28 { bool ok = true;
29 using std::string;
30 //
31 // AD graph example
32 // node_1 : p[0]
33 // node_2 : p[1]
34 // node_3 : x[0]
35 // node_4 : p[0] + p[1]
36 // node_5 : x[0] + ( p[0] + p[1] )
37 // y[0] = x[0] + ( p[0] + p[1] )
38 //
39 // C++ graph object
40 CppAD::cpp_graph graph_obj;
41 //
42 // operator being used
43 CppAD::graph::graph_op_enum op_enum;
44 //
45 // set scalars
46 graph_obj.function_name_set("print_graph example");
47 size_t n_dynamic_ind = 2;
48 graph_obj.n_dynamic_ind_set(n_dynamic_ind);
49 size_t n_variable_ind = 1;
50 graph_obj.n_variable_ind_set(n_variable_ind);
51 //
52 // node_4 : p[0] + p[1]
53 op_enum = CppAD::graph::add_graph_op;
54 graph_obj.operator_vec_push_back(op_enum);
55 graph_obj.operator_arg_push_back(1);
56 graph_obj.operator_arg_push_back(2);
57 //
58 // node_5 : x[0] + ( p[0] + p[1] )
59 graph_obj.operator_vec_push_back(op_enum);
60 graph_obj.operator_arg_push_back(3);
61 graph_obj.operator_arg_push_back(4);
62 //
63 // y[0] = x[0] + ( p[0] + p[1] )
64 graph_obj.dependent_vec_push_back(5);
65 //
66 // get output of print command
67 std::stringstream os;
68 graph_obj.print(os);
69 //
70 std::string check =
71 "print_graph example\n"
72 " 1 p[0]\n"
73 " 2 p[1]\n"
74 " 3 x[0]\n"
75 " 4 add 1 2\n"
76 " 5 add 3 4\n"
77 "y nodes = 5\n"
78 ;
79 std::string str = os.str();
80 ok &= str == check;
81 //
82 return ok;
83 }
84 // END C++
275275 builddir = @builddir@
276276 compiler_has_conversion_warn = @compiler_has_conversion_warn@
277277 cppad_boostvector = @cppad_boostvector@
278 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
279278 cppad_cppadvector = @cppad_cppadvector@
280279 cppad_cxx_flags = @cppad_cxx_flags@
281280 cppad_description = @cppad_description@
330329 prefix = @prefix@
331330 program_transform_name = @program_transform_name@
332331 psdir = @psdir@
332 runstatedir = @runstatedir@
333333 sbindir = @sbindir@
334334 sharedstatedir = @sharedstatedir@
335335 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
5454 return 0;
5555 }"
5656 )
57 IF( DEFINED boost_multi_thread_ok )
58 MESSAGE( ERROR "boost_multi_thread_ok is defined before expected" )
59 ENDIF( DEFINED boost_multi_thread_ok )
60 CHECK_CXX_SOURCE_RUNS("${source}" boost_multi_thread_ok )
57 compile_source_test("${source}" boost_multi_thread_ok )
6158 #
6259 IF( boost_multi_thread_ok )
6360 ADD_SUBDIRECTORY(bthread)
7572 MESSAGE(STATUS "make check_example_multi_thread: available")
7673 #
7774 # Change check depends in parent environment
78 add_to_list(check_depends check_example_multi_thread)
79 SET(check_depends "${check_depends}" PARENT_SCOPE)
75 add_to_list(check_example_depends check_example_multi_thread)
76 SET(check_example_depends "${check_example_depends}" PARENT_SCOPE)
8077 #
8178 ENDIF( NOT( "${check_example_multi_thread_depends}" STREQUAL "" ) )
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1818 # source1 source2 ... sourceN
1919 # )
2020 SET(source_list ../thread_test.cpp
21 ${CMAKE_SOURCE_DIR}/speed/src/microsoft_timer.cpp
2221 ../team_example.cpp
2322 ../harmonic.cpp
2423 ../multi_atomic_two.cpp
325325 builddir = @builddir@
326326 compiler_has_conversion_warn = @compiler_has_conversion_warn@
327327 cppad_boostvector = @cppad_boostvector@
328 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
329328 cppad_cppadvector = @cppad_cppadvector@
330329 cppad_cxx_flags = @cppad_cxx_flags@
331330 cppad_description = @cppad_description@
380379 prefix = @prefix@
381380 program_transform_name = @program_transform_name@
382381 psdir = @psdir@
382 runstatedir = @runstatedir@
383383 sbindir = @sbindir@
384384 sharedstatedir = @sharedstatedir@
385385 srcdir = @srcdir@
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
101101 { }
102102 private:
103103 // for_type
104 virtual bool for_type(
104 bool for_type(
105105 const vector<double>& parameter_u ,
106106 const vector<ad_type_enum>& type_u ,
107 vector<ad_type_enum>& type_y )
107 vector<ad_type_enum>& type_y ) override
108108 { bool ok = parameter_u.size() == 3;
109109 ok &= type_u.size() == 3;
110110 ok &= type_y.size() == 1;
119119 return true;
120120 }
121121 // forward
122 virtual bool forward(
122 bool forward(
123123 const vector<double>& parameter_u ,
124124 const vector<ad_type_enum>& type_u ,
125125 size_t need_y ,
126126 size_t order_low ,
127127 size_t order_up ,
128128 const vector<double>& taylor_u ,
129 vector<double>& taylor_y )
129 vector<double>& taylor_y ) override
130130 {
131131 # ifndef NDEBUG
132132 size_t n = taylor_u.size() / (order_up + 1);
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
100100 { }
101101 private:
102102 // forward mode routine called by CppAD
103 virtual bool forward(
103 bool forward(
104104 size_t p ,
105105 size_t q ,
106106 const vector<bool>& vu ,
107107 vector<bool>& vy ,
108108 const vector<double>& tu ,
109 vector<double>& ty )
109 vector<double>& ty ) override
110110 {
111111 # ifndef NDEBUG
112112 size_t n = tu.size() / (q + 1);
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2222 # source1 source2 ... sourceN
2323 # )
2424 SET(source_list ../thread_test.cpp
25 ${CMAKE_SOURCE_DIR}/speed/src/microsoft_timer.cpp
2625 ../team_example.cpp
2726 ../harmonic.cpp
2827 ../multi_atomic_two.cpp
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1818 # source1 source2 ... sourceN
1919 # )
2020 SET(source_list ../thread_test.cpp
21 ${CMAKE_SOURCE_DIR}/speed/src/microsoft_timer.cpp
2221 ../team_example.cpp
2322 ../harmonic.cpp
2423 ../multi_atomic_two.cpp
276276 builddir = @builddir@
277277 compiler_has_conversion_warn = @compiler_has_conversion_warn@
278278 cppad_boostvector = @cppad_boostvector@
279 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
280279 cppad_cppadvector = @cppad_cppadvector@
281280 cppad_cxx_flags = @cppad_cxx_flags@
282281 cppad_description = @cppad_description@
331330 prefix = @prefix@
332331 program_transform_name = @program_transform_name@
333332 psdir = @psdir@
333 runstatedir = @runstatedir@
334334 sbindir = @sbindir@
335335 sharedstatedir = @sharedstatedir@
336336 srcdir = @srcdir@
268268 builddir = @builddir@
269269 compiler_has_conversion_warn = @compiler_has_conversion_warn@
270270 cppad_boostvector = @cppad_boostvector@
271 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
272271 cppad_cppadvector = @cppad_cppadvector@
273272 cppad_cxx_flags = @cppad_cxx_flags@
274273 cppad_description = @cppad_description@
323322 prefix = @prefix@
324323 program_transform_name = @program_transform_name@
325324 psdir = @psdir@
325 runstatedir = @runstatedir@
326326 sbindir = @sbindir@
327327 sharedstatedir = @sharedstatedir@
328328 srcdir = @srcdir@
309309 builddir = @builddir@
310310 compiler_has_conversion_warn = @compiler_has_conversion_warn@
311311 cppad_boostvector = @cppad_boostvector@
312 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
313312 cppad_cppadvector = @cppad_cppadvector@
314313 cppad_cxx_flags = @cppad_cxx_flags@
315314 cppad_description = @cppad_description@
364363 prefix = @prefix@
365364 program_transform_name = @program_transform_name@
366365 psdir = @psdir@
366 runstatedir = @runstatedir@
367367 sbindir = @sbindir@
368368 sharedstatedir = @sharedstatedir@
369369 srcdir = @srcdir@
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
114114 for(size_t i = 0; i < n; i++)
115115 ok &= vec[i] == Scalar(n - i);
116116
117 // vector assignment OK when target has size zero
118 other.resize(0);
119 other = vec;
117 // vector assignment OK no matter what target size was before assignment
118 other[0] = vec[0] + 1;
119 ok &= other.size() < vec.size();
120 other = vec;
121 ok &= other.size() == vec.size();
122 for(size_t i = 0; i < vec.size(); i++)
123 ok &= other[i] == vec[i];
120124
121125 // create a const vector equal to vec
122126 const vector<Scalar> cvec = vec;
123127
124128 // sort of vec (will reverse order of elements for this case)
129 # ifndef _MSC_VER
130 // 2DO: Determine why this test fails with Visual Studio 2019
125131 std::sort(vec.begin(), vec.end());
126132 for(size_t i = 0; i < n ; ++i)
127133 ok &= vec[i] == Scalar(i + 1);
130136 std::sort(other.data(), other.data() + other.size());
131137 for(size_t i = 0; i < n ; ++i)
132138 ok &= other[i] == Scalar(i + 1);
139 # else
140 for(size_t i = 0; i < n ; ++i)
141 vec[i] = Scalar(i + 1);
142 # endif
133143
134144 // test direct use of iterator and const_iterator
135145 typedef vector<Scalar>::iterator iterator;
151161
152162 # ifndef NDEBUG
153163 // -----------------------------------------------------------------------
154 // check that size mismatch throws an exception when NDEBUG not defined
155 other.resize(0);
156 bool detected_error = false;
157 try
158 { another = other; }
159 catch(const std::string& file)
160 { // This location for the error is not part of user API and may change
161 size_t pos = file.find("/vector.hpp");
162 ok &= pos != std::string::npos;
163 detected_error = true;
164 }
165 ok &= detected_error;
166 // -----------------------------------------------------------------------
167164 // check that iterator access out of range generates an error
168165 itr = vec.begin();
169166 ok &= *itr == Scalar(1); // this access OK
170 detected_error = false;
167 bool detected_error = false;
171168 try
172169 { vec.clear();
173170 // The iterator knows that the vector has changed and that
294294 builddir = @builddir@
295295 compiler_has_conversion_warn = @compiler_has_conversion_warn@
296296 cppad_boostvector = @cppad_boostvector@
297 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
298297 cppad_cppadvector = @cppad_cppadvector@
299298 cppad_cxx_flags = @cppad_cxx_flags@
300299 cppad_description = @cppad_description@
349348 prefix = @prefix@
350349 program_transform_name = @program_transform_name@
351350 psdir = @psdir@
351 runstatedir = @runstatedir@
352352 sbindir = @sbindir@
353353 sharedstatedir = @sharedstatedir@
354354 srcdir = @srcdir@
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
101101 ok &= matrix.col()[k] == other.col()[k];
102102 ok &= matrix.val()[k] == other.val()[k];
103103 }
104
105 // now use the copy constructor
106 CppAD::sparse_rcv<SizeVector, ValueVector> copy(matrix);
107 ok &= copy.nr() == matrix.nr();
108 ok &= copy.nc() == matrix.nc();
109 ok &= copy.nnz() == matrix.nnz();
110 for(size_t k = 0; k < nnz; k++)
111 { ok &= matrix.row()[k] == copy.row()[k];
112 ok &= matrix.col()[k] == copy.col()[k];
113 ok &= matrix.val()[k] == copy.val()[k];
114 }
104115 return ok;
105116 }
106117
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2121 print_variable(${output_variable})
2222 ENDMACRO(check_match)
2323 # -----------------------------------------------------------------------------
24 # CMAKE_REQUIRED_name
25 SET(CMAKE_REQUIRED_DEFINITIONS "")
26 SET(CMAKE_REQUIRED_FLAGS "")
27 SET(CMAKE_REQUIRED_INCLUDES "")
28 SET(CMAKE_REQUIRED_LIBRARIES "")
29 # -----------------------------------------------------------------------------
2430 # compiler_has_conversion_warn
2531 SET( clang_or_gnu 0 )
2632 IF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
3036 SET(clang_or_gnu 1)
3137 ENDIF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
3238 IF( clang_or_gnu )
33 SET(backup "${cppad_cxx_flags}")
34 SET(cppad_cxx_flags "${backup} -Wfloat-conversion -Wconversion -Werror")
39 SET(CMAKE_REQUIRED_FLAGS
40 "${cppad_cxx_flags} -Wfloat-conversion -Wconversion -Werror"
41 )
3542 #
3643 SET(source "int main(void) { return 0; }")
37 run_source_test("${source}" compiler_has_conversion_warn )
44 compile_source_test("${source}" compiler_has_conversion_warn )
3845 #
39 SET(cppad_cxx_flags "${backup}")
46 SET(CMAKE_REQUIRED_FLAGS "")
4047 ELSE( clang_or_gnu )
4148 SET( compiler_has_conversion_warn 0 )
4249 ENDIF( clang_or_gnu )
5966 ENDIF( NOT cppad_eigenvector )
6067 ENDIF( NOT cppad_cppadvector )
6168 ENDIF( NOT cppad_boostvector )
62
69 #
6370 IF( cppad_boostvector )
6471 # FIND_PACKAGE(Boost) done by ../CMakeLists.txt
6572 IF( NOT Boost_FOUND )
7683 )
7784 ENDIF( NOT include_eigen )
7885 ENDIF( cppad_eigenvector )
79 #
80 print_variable(cppad_cplusplus_201100_ok)
8186 # -----------------------------------------------------------------------------
8287 # cppad_has_gettimeofday
8388 #
8994 return 0;
9095 }"
9196 )
92 run_source_test("${source}" cppad_has_gettimeofday)
97 compile_source_test("${source}" cppad_has_gettimeofday)
9398 # -----------------------------------------------------------------------------
94 # cppad_tape_addr_type, cppad_tape_id_type
95 #
99 # Warn user of the following types are signed:
100 # cppad_tape_addr_type, cppad_tape_id_type
96101 FOREACH(cmake_var cppad_tape_id_type cppad_tape_addr_type )
97102 SET(source "
98103 # include <limits>
104 # include <cstddef>
99105 int main(void)
100 { bool is_unsigned = ! std::numeric_limits<${${cmake_var}}>::is_signed;
101 return int(! is_unsigned);
106 { static_assert(
107 ! std::numeric_limits<${${cmake_var}}>::is_signed ,
108 \"${cmake_var} is a signed type\"
109 );
110 return 0;
102111 }
103112 "
104113 )
105 run_source_test("${source}" ${cmake_var}_is_unsigned)
106 IF( ${cmake_var}_is_unsigned STREQUAL 0 )
114 compile_source_test("${source}" ${cmake_var}_is_unsigned)
115 IF( NOT ${${cmake_var}_is_unsigned} )
107116 MESSAGE(STATUS
108 "Warning: using a signed ${cmake_var} is for CppAD developers only !"
109 )
110 ENDIF( ${cmake_var}_is_unsigned STREQUAL 0 )
117 "Warning: using a signed type for ${cmake_var} is for CppAD developers only !"
118 )
119 ENDIF( NOT ${${cmake_var}_is_unsigned} )
111120 ENDFOREACH( cmake_var )
112 # -----------------------------------------------------------------------------
113 # check that cppad_max_num_threads is >= 4
114 #
115 SET(CMAKE_REQUIRED_DERINITIONS "")
116 SET(CMAKE_REQUIRED_INCLUDES "")
117 SET(CMAKE_REQUIRED_LIBRARIES "")
118 SET(CMAKE_REQUIRED_FLAGS "")
119 SET(source "
120 int main(void)
121 { const char* number = \"${cppad_max_num_threads}\";
122 int value = 0;
123 while( *number == ' ' )
124 number++;
125 while( '0' <= *number && *number <= '9' )
126 { value = 10 * value + (int)(*number - '0');
127 number++;
128 }
129 while( *number == ' ' )
130 number++;
131 if( *number != char(0) )
132 return 1;
133 if( value < 4 )
134 return 1;
135 return 0;
136 }
137 " )
138 # Using CHECK_CXX_SOURCE_RUNS directly (instead of run_source_test).
139 IF( DEFINED cppad_max_num_threads_is_integer_ge_4 )
140 MESSAGE( ERROR
141 "cppad_max_num_threads_is_integer_ge_4 is defined before expected"
142 )
143 ENDIF( DEFINED cppad_max_num_threads_is_integer_ge_4 )
144 CHECK_CXX_SOURCE_RUNS("${source}" cppad_max_num_threads_is_integer_ge_4 )
145 IF( NOT cppad_max_num_threads_is_integer_ge_4 )
146 MESSAGE(FATAL_ERROR
147 "cppad_max_num_threads is not an integer greater than or equal 4"
148 )
149 ENDIF( NOT cppad_max_num_threads_is_integer_ge_4 )
150121 # -----------------------------------------------------------------------------
151122 # cppad_has_mkstemp
152123 #
160131 return 0;
161132 }
162133 " )
163 run_source_test("${source}" cppad_has_mkstemp )
134 compile_source_test("${source}" cppad_has_mkstemp )
164135 # -----------------------------------------------------------------------------
165136 # cppad_has_tmpname_s
166137 #
173144 return 0;
174145 }
175146 " )
176 run_source_test("${source}" cppad_has_tmpnam_s )
147 compile_source_test("${source}" cppad_has_tmpnam_s )
177148 # -----------------------------------------------------------------------------
178149 # configure.hpp
179150 CONFIGURE_FILE(
506506 case Expm1Op:
507507 case LogOp:
508508 case Log1pOp:
509 case NegOp:
509510 case SignOp:
510511 case SinOp:
511512 case SinhOp:
539540 case DivvpOp:
540541 case PowvpOp:
541542 case ZmulvpOp:
542 # ifndef NDEBUG
543 if( op == PowvpOp )
544 { CPPAD_ASSERT_NARG_NRES(op, 2, 3);
545 }
546 else
547 { CPPAD_ASSERT_NARG_NRES(op, 2, 1);
548 }
549 # endif
543 CPPAD_ASSERT_NARG_NRES(op, 2, 1);
550544 CPPAD_ASSERT_UNKNOWN( size_t( f2g_var[ arg[0] ] ) < num_var );
551545 new_arg[0] = f2g_var[ arg[0] ];
552546 new_arg[1] = arg[1]; // parameter
00 # ifndef CPPAD_CORE_AD_CTOR_HPP
11 # define CPPAD_CORE_AD_CTOR_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
188188 template <class Base>
189189 template <class T>
190190 AD<Base>::AD(const T &t)
191 : value_(Base(t))
191 : value_( Base( double(t) ) )
192192 , tape_id_(0)
193193 , taddr_(0)
194194 , ad_type_(constant_enum)
00 # ifndef CPPAD_CORE_AD_FUN_HPP
11 # define CPPAD_CORE_AD_FUN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3838 derivative values, and other values related to the corresponding function.
3939
4040 $childtable%
41 omh/adfun.omh%
41 include/cppad/core/ad_fun.omh%
4242 include/cppad/core/optimize.hpp%
4343 include/cppad/core/fun_check.hpp%
4444 include/cppad/core/check_for_nan.hpp
663663 /// number of dependent variables
664664 size_t Range(void) const
665665 { return dep_taddr_.size(); }
666
667 /// set and get function name
668 void function_name_set(const std::string& function_name)
669 { function_name_ = function_name; }
670 std::string function_name_get(void)
671 { return function_name_; }
666672
667673 /// is variable a parameter
668674 bool Parameter(size_t i)
0 -------------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------------
11 $begin record_adfun$$
12 $spell
13 $$
14
15 $section Create an ADFun Object by Recording an Operation Sequence$$
16
17 $childtable%
18 include/cppad/core/independent/user.omh%
19 include/cppad/core/fun_construct.hpp%
20 include/cppad/core/dependent.hpp%
21 include/cppad/core/abort_recording.hpp%
22 include/cppad/core/fun_property.omh%
23 include/cppad/core/function_name.omh
24 %$$
25
26 $end
27 -------------------------------------------------------------------------------
28 $begin other_adfun$$
29 $spell
30 $$
31
32 $section Other Ways to Create an ADFun Object$$
33
34
35 $childtable%
36 include/cppad/core/base2ad.hpp%
37 include/cppad/core/graph/json_ad_graph.omh%
38 include/cppad/core/graph/cpp_ad_graph.omh%
39 include/cppad/core/abs_normal_fun.hpp
40 %$$
41
42 $head See Also$$
43 $table
44 $rref switch_var_dyn.cpp$$
45 $tend
46
47 $end
48 -------------------------------------------------------------------------------
49 $begin drivers$$
50 $spell
51 $$
52
53
54 $section First and Second Order Derivatives: Easy Drivers$$
55
56
57 $childtable%
58 include/cppad/core/jacobian.hpp%
59 include/cppad/core/hessian.hpp%
60 include/cppad/core/for_one.hpp%
61 include/cppad/core/rev_one.hpp%
62 include/cppad/core/for_two.hpp%
63 include/cppad/core/rev_two.hpp
64 %$$
65
66 $end
67 -------------------------------------------------------------------------------
68 $begin Forward$$
69
70 $section Forward Mode$$
71
72 $childtable%
73 include/cppad/core/new_dynamic.hpp%
74 include/cppad/core/forward/forward_zero.omh%
75 include/cppad/core/forward/forward_one.omh%
76 include/cppad/core/forward/forward_two.omh%
77 include/cppad/core/forward/forward_order.omh%
78 include/cppad/core/forward/forward_dir.omh%
79 include/cppad/core/forward/size_order.omh%
80 include/cppad/core/forward/compare_change.omh%
81 include/cppad/core/capacity_order.hpp%
82 include/cppad/core/num_skip.hpp
83 %$$
84
85 $end
86 -------------------------------------------------------------------------------
87 $begin Reverse$$
88 $spell
89 xq
90 $$
91
92 $section Reverse Mode$$
93
94 $head Multiple Directions$$
95 Reverse mode after $cref/Forward(q, r, xq)/forward_dir/$$
96 with number of directions $icode%r% != 1%$$ is not yet supported.
97 There is one exception, $cref reverse_one$$ is allowed
98 because there is only one zero order forward direction.
99 After such an operation, only the zero order forward
100 results are retained (the higher order forward results are lost).
101
102 $childtable%
103 omh/reverse/reverse_one.omh%
104 omh/reverse/reverse_two.omh%
105 omh/reverse/reverse_any.omh%
106 include/cppad/core/subgraph_reverse.hpp
107 %$$
108
109 $end
110 -------------------------------------------------------------------------------
111 $begin sparsity_pattern$$
112 $spell
113 $$
114
115
116 $section Calculating Sparsity Patterns$$
117
118 $children%
119 include/cppad/core/for_jac_sparsity.hpp%
120 include/cppad/core/rev_jac_sparsity.hpp%
121 include/cppad/core/for_hes_sparsity.hpp%
122 include/cppad/core/rev_hes_sparsity.hpp%
123 include/cppad/core/subgraph_sparsity.hpp%
124
125 example/sparse/dependency.cpp%
126 example/sparse/rc_sparsity.cpp%
127
128 include/cppad/core/for_sparse_jac.hpp%
129 include/cppad/core/rev_sparse_jac.hpp%
130 include/cppad/core/rev_sparse_hes.hpp%
131 include/cppad/core/for_sparse_hes.hpp
132
133 %$$
134
135 $head Preferred Sparsity Pattern Calculations$$
136 $table
137 $rref for_jac_sparsity$$
138 $rref rev_jac_sparsity$$
139 $rref for_hes_sparsity$$
140 $rref rev_hes_sparsity$$
141 $rref subgraph_sparsity$$
142 $tend
143
144 $head Old Sparsity Pattern Calculations$$
145 $table
146 $rref ForSparseJac$$
147 $rref RevSparseJac$$
148 $rref ForSparseHes$$
149 $rref RevSparseHes$$
150 $tend
151
152
153 $end
154 -------------------------------------------------------------------------------
155 $begin sparse_derivative$$
156 $spell
157 $$
158
159
160 $section Calculating Sparse Derivatives$$
161
162 $children%
163 include/cppad/core/sparse_jac.hpp%
164 include/cppad/core/sparse_jacobian.hpp%
165
166 include/cppad/core/sparse_hes.hpp%
167 include/cppad/core/sparse_hessian.hpp%
168
169 include/cppad/core/subgraph_jac_rev.hpp
170 %$$
171
172 $head Preferred Sparsity Patterns$$
173 $table
174 $rref sparse_jac$$
175 $rref sparse_hes$$
176 $rref subgraph_jac_rev$$
177 $tend
178
179 $head Old Sparsity Patterns$$
180 $table
181 $rref sparse_jacobian$$
182 $rref sparse_hessian$$
183 $tend
184
185
186 $end
187 -------------------------------------------------------------------------------
00 # ifndef CPPAD_CORE_ATOMIC_ATOMIC_THREE_HPP
11 # define CPPAD_CORE_ATOMIC_ATOMIC_THREE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
200200 %example/atomic_three/base2ad.cpp
201201 %example/atomic_three/reciprocal.cpp
202202 %example/atomic_three/mat_mul.cpp
203 %example/atomic_three/vector_op.cpp
203204 %$$
204205
205206 $end
00 # ifndef CPPAD_CORE_ATOMIC_THREE_REVERSE_HPP
11 # define CPPAD_CORE_ATOMIC_THREE_REVERSE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
2929 af
3030 aparameter
3131 enum
32 $$
33
34 $section Atomic Function Reverse Mode$$
35 $spell
32 azmul
3633 ataylor
3734 apartial
3835 $$
36
37 $section Atomic Function Reverse Mode$$
3938
4039 $head Base$$
4140 This syntax is used by $icode%f%.Reverse%$$ where $icode f$$ has prototype
140139
141140 $head taylor_y$$
142141 The size of $icode taylor_y$$ is $codei%(%q%+1)*%m%$$.
143 Upon return,
144142 For $latex i = 0 , \ldots , m-1$$ and $latex k = 0 , \ldots , q$$,
145143 we use the Taylor coefficient notation
146144 $latex \[
246244 in a similar way to $cref/need_y/atomic_three_forward/need_y/$$,
247245 to avoid unnecessary operations.
248246
247 $subhead azmul$$
248 An $cref/optimized/optimize/$$ function will use zero
249 for values in $icode taylor_x$$ and $icode taylor_y$$ that are
250 not necessary in the current context.
251 If you divide by these values when computing
252 $latex ( \partial F_i^k / \partial x_j^\ell )$$ you could get an nan
253 if the corresponding value in $icode partial_y$$ is zero.
254 To be careful, if you do divide by
255 $icode taylor_x$$ or $icode taylor_y$$, use $cref azmul$$
256 for to avoid zero over zero calculations.
257
258
249259 $head apartial_x$$
250260 The specifications for $icode apartial_x$$ is the same as for
251261 $icode partial_x$$ (only the type of $icode apartial_x$$ is different).
00 # ifndef CPPAD_CORE_BASE_LIMITS_HPP
11 # define CPPAD_CORE_BASE_LIMITS_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5757 { return static_cast<Base>( std::numeric_limits<Other>::epsilon() ); }\
5858 static Base quiet_NaN(void) \
5959 { return static_cast<Base>( std::numeric_limits<Other>::quiet_NaN() ); }\
60 static Base infinity(void) \
61 { return static_cast<Base>( std::numeric_limits<Other>::infinity() ); }\
6062 static const int digits10 = std::numeric_limits<Other>::digits10;\
6163 };
6264 /* %$$
00 # ifndef CPPAD_CORE_CAPACITY_ORDER_HPP
11 # define CPPAD_CORE_CAPACITY_ORDER_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
2727 $icode%f%.capacity_order(%c%)%$$
2828
2929 $subhead See Also$$
30 $cref seq_property$$
30 $cref fun_property$$
3131
3232 $head Purpose$$
3333 The Taylor coefficients calculated by $cref Forward$$ mode calculations
00 # ifndef CPPAD_CORE_CHKPOINT_ONE_CHKPOINT_ONE_HPP
11 # define CPPAD_CORE_CHKPOINT_ONE_CHKPOINT_ONE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
193193 $codei%
194194 size_t %sv%
195195 %$$
196 It is the $cref/size_var/seq_property/size_var/$$ for the
196 It is the $cref/size_var/fun_property/size_var/$$ for the
197197 $codei%ADFun<%Base%>%$$ object is used to store the operation sequence
198198 corresponding to $icode algo$$.
199199
00 # ifndef CPPAD_CORE_CHKPOINT_TWO_DYNAMIC_HPP
11 # define CPPAD_CORE_CHKPOINT_TWO_DYNAMIC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
4747 This is a vector with new values for the dynamic parameters
4848 in the function $icode fun$$.
4949 Is size must be equal to
50 $cref/fun.size_dyn_ind()/seq_property/size_dyn_par/$$.
50 $cref/fun.size_dyn_ind()/fun_property/size_dyn_par/$$.
5151 This only affects the copy of $icode fun$$ used by $icode chk_fun$$.
5252
5353 $head Multi-Threading$$
00 # ifndef CPPAD_CORE_DEPENDENT_HPP
11 # define CPPAD_CORE_DEPENDENT_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
4444 \] $$
4545 where $latex B$$ is the space corresponding to objects of type $icode Base$$.
4646 The value $latex n$$ is the dimension of the
47 $cref/domain/seq_property/Domain/$$ space for the operation sequence.
47 $cref/domain/fun_property/Domain/$$ space for the operation sequence.
4848 The value $latex m$$ is the dimension of the
49 $cref/range/seq_property/Range/$$ space for the operation sequence
49 $cref/range/fun_property/Range/$$ space for the operation sequence
5050 (which is determined by the size of $icode y$$).
5151
5252 $head f$$
00 # ifndef CPPAD_CORE_FOR_ONE_HPP
11 # define CPPAD_CORE_FOR_ONE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5858 (see $cref/Vector/ForOne/Vector/$$ below)
5959 and its size
6060 must be equal to $icode n$$, the dimension of the
61 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
61 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
6262 It specifies
6363 that point at which to evaluate the partial derivative.
6464
6868 size_t %j%
6969 %$$
7070 an is less than $icode n$$,
71 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
71 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
7272 It specifies the component of $icode F$$
7373 for which we are computing the partial derivative.
7474
7979 %$$
8080 (see $cref/Vector/ForOne/Vector/$$ below)
8181 and its size is $latex m$$, the dimension of the
82 $cref/range/seq_property/Range/$$ space for $icode f$$.
82 $cref/range/fun_property/Range/$$ space for $icode f$$.
8383 The value of $icode dy$$ is the partial of $latex F$$ with respect to
8484 $latex x_j$$ evaluated at $icode x$$; i.e.,
8585 for $latex i = 0 , \ldots , m - 1$$
00 # ifndef CPPAD_CORE_FOR_TWO_HPP
11 # define CPPAD_CORE_FOR_TWO_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5959 (see $cref/BaseVector/ForTwo/BaseVector/$$ below)
6060 and its size
6161 must be equal to $icode n$$, the dimension of the
62 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
62 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
6363 It specifies
6464 that point at which to evaluate the partial derivatives listed above.
6565
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
5252
5353 $subhead n$$
5454 We use $icode n$$ to denote the dimension of the
55 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
55 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
5656
5757 $subhead m$$
5858 We use $icode m$$ to denote the dimension of the
59 $cref/range/seq_property/Range/$$ space for $icode f$$.
59 $cref/range/fun_property/Range/$$ space for $icode f$$.
6060
6161 $head f$$
6262 The $cref ADFun$$ object $icode f$$ has prototype
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
6666 %$$
6767 (see $cref/Vector/forward_one/Vector/$$ below)
6868 and its size must be equal to $icode n$$, the dimension of the
69 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
69 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
7070
7171 $head Vector$$
7272 The type $icode Vector$$ must be a $cref SimpleVector$$ class with
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
5959
6060 $subhead n$$
6161 We use $icode n$$ to denote the dimension of the
62 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
62 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
6363
6464 $subhead m$$
6565 We use $icode m$$ to denote the dimension of the
66 $cref/range/seq_property/Range/$$ space for $icode f$$.
66 $cref/range/fun_property/Range/$$ space for $icode f$$.
6767
6868 $head f$$
6969 The $cref ADFun$$ object $icode f$$ has prototype
101101 %$$
102102 (see $cref/BaseVector/forward_order/BaseVector/$$ below).
103103 As above, we use $icode n$$ to denote the dimension of the
104 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
104 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
105105 The size of $icode xq$$ must be either $icode n$$ or
106106 $icode%n%*(%q%+1)%$$.
107107 After this call we will have
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
7777 %$$
7878 (see $cref/Vector/forward_two/Vector/$$ below)
7979 and its size must be equal to $icode n$$, the dimension of the
80 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
80 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
8181
8282 $head y2$$
8383 The result $icode y2$$ has prototype
8686 %$$
8787 (see $cref/Vector/forward_two/Vector/$$ below)
8888 The size of $icode y1$$ is equal to $icode m$$, the dimension of the
89 $cref/range/seq_property/Range/$$ space for $icode f$$.
89 $cref/range/fun_property/Range/$$ space for $icode f$$.
9090 Its value is given element-wise by the formula in the
9191 $cref/purpose/forward_two/Purpose/$$ above.
9292
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
5555 %$$
5656 (see $cref/Vector/forward_zero/Vector/$$ below)
5757 and its size must be equal to $icode n$$, the dimension of the
58 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
58 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
5959
6060 $head s$$
6161 If the argument $icode s$$ is not present, $code std::cout$$
7575 (see $cref/Vector/forward_zero/Vector/$$ below)
7676 and its value is $latex F(x)$$ at $icode%x% = %x0%$$.
7777 The size of $icode y0$$ is equal to $icode m$$, the dimension of the
78 $cref/range/seq_property/Range/$$ space for $icode f$$.
78 $cref/range/fun_property/Range/$$ space for $icode f$$.
7979
8080 $head Vector$$
8181 The type $icode Vector$$ must be a $cref SimpleVector$$ class with
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2121 $icode%s% = %f%.size_order()%$$
2222
2323 $subhead See Also$$
24 $cref seq_property$$
24 $cref fun_property$$
2525
2626 $head Purpose$$
2727 Determine the number of Taylor coefficient orders, per variable,direction,
7272 Thus there are $latex q + 1$$ (order zero through $icode q$$)
7373 Taylor coefficients per variable,direction.
7474 (You can determine the number of variables in the operation sequence
75 using the $cref/size_var/seq_property/size_var/$$ function.)
75 using the $cref/size_var/fun_property/size_var/$$ function.)
7676
7777 $head capacity_order$$
7878 If the number of Taylor coefficient orders
00 # ifndef CPPAD_CORE_FUN_CHECK_HPP
11 # define CPPAD_CORE_FUN_CHECK_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
7474 (see $cref/Vector/FunCheck/Vector/$$ below)
7575 and its size
7676 must be equal to $icode n$$, the dimension of the
77 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
77 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
7878
7979 $head y$$
8080 The $icode g$$ result $icode y$$ has prototype
8484 and its value is $latex G(x)$$.
8585 The size of $icode y$$
8686 is equal to $icode m$$, the dimension of the
87 $cref/range/seq_property/Range/$$ space for $icode f$$.
87 $cref/range/fun_property/Range/$$ space for $icode f$$.
8888
8989 $head x$$
9090 The $code FunCheck$$ argument $icode x$$ has prototype
9393 %$$
9494 and its size
9595 must be equal to $icode n$$, the dimension of the
96 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
96 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
9797 This specifies that point at which to compare the values
9898 calculated by $icode f$$ and $icode G$$.
9999
00 # ifndef CPPAD_CORE_FUN_CONSTRUCT_HPP
11 # define CPPAD_CORE_FUN_CONSTRUCT_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
9393 $codei%
9494 %g%.size_var()
9595 %$$
96 returns the value zero (see $cref/size_var/seq_property/size_var/$$).
96 returns the value zero (see $cref/size_var/fun_property/size_var/$$).
9797
9898 $head Sequence Constructor$$
9999 The sequence constructor
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------- */
11
12 $begin fun_property$$
13 $spell
14 inuse
15 Addr
16 CppAD
17 sizeof
18 op
19 arg
20 enum
21 Taylor
22 const
23 bool
24 var
25 VecAD
26 subgraph
27 dyn
28 ind
29 $$
30
31 $section ADFun Function Properties$$
32
33 $head Syntax$$
34 $icode%n% = %f%.Domain()
35 %$$
36 $icode%m% = %f%.Range()
37 %$$
38 $icode%p% = %f%.Parameter(%i%)
39 %$$
40 $icode%s% = %f%.size_var()
41 %$$
42 $icode%s% = %f%.size_par()
43 %$$
44 $icode%s% = %f%.size_op()
45 %$$
46 $icode%s% = %f%.size_op_arg()
47 %$$
48 $icode%s% = %f%.size_text()
49 %$$
50 $icode%s% = %f%.size_VecAD()
51 %$$
52 $icode%s% = %f%.size_random()
53 %$$
54 $icode%s% = %f%.size_dyn_ind()
55 %$$
56 $icode%s% = %f%.size_dyn_par()
57 %$$
58 $icode%s% = %f%.size_dyn_arg()
59 %$$
60 $icode%s% = %f%.size_op_seq()
61 %$$
62
63 $subhead See Also$$
64 $cref function_name$$,
65 $cref size_order$$,
66 $cref capacity_order$$,
67 $cref number_skip$$.
68
69 $head Purpose$$
70 The operations above return properties of the
71 AD of $icode Base$$
72 $cref/operation sequence/glossary/Operation/Sequence/$$
73 stored in the ADFun object $icode f$$.
74 (If there is no operation sequence stored in $icode f$$,
75 $code size_var$$ returns zero.)
76
77 $head f$$
78 The object $icode f$$ has prototype
79 $codei%
80 const ADFun<%Base%> %f%
81 %$$
82 (see $codei%ADFun<%Base%>%$$ $cref/constructor/FunConstruct/$$).
83
84 $head Domain$$
85 The result $icode n$$ has prototype
86 $codei%
87 size_t %n%
88 %$$
89 and is the dimension of the domain space corresponding to $icode f$$.
90 This is equal to the size of the vector $icode x$$ in the call
91 $codei%
92 Independent(%x%)
93 %$$
94 that starting recording the operation sequence
95 currently stored in $icode f$$
96 (see $cref FunConstruct$$ and $cref Dependent$$).
97
98 $head Range$$
99 The result $icode m$$ has prototype
100 $codei%
101 size_t %m%
102 %$$
103 and is the dimension of the range space corresponding to $icode f$$.
104 This is equal to the size of the vector $icode y$$ in syntax
105 $codei%
106 ADFun<%Base> %f%(%x%, %y%)
107 %$$
108 or
109 $codei%
110 %f%.Dependent(%y%)
111 %$$
112 depending on which stored the operation sequence currently in $icode f$$
113 (see $cref FunConstruct$$ and $cref Dependent$$).
114
115 $head Parameter$$
116 The argument $icode i$$ has prototype
117 $codei%
118 size_t %i%
119 %$$
120 and $latex 0 \leq i < m$$.
121 The result $icode p$$ has prototype
122 $codei%
123 bool %p%
124 %$$
125 It is true if the $th i$$ component of range space for $latex F$$
126 corresponds to a
127 $cref/parameter/glossary/Parameter/$$ in the operation sequence.
128 In this case,
129 the $th i$$ component of $latex F$$ is constant and
130 $latex \[
131 \D{F_i}{x_j} (x) = 0
132 \] $$
133 for $latex j = 0 , \ldots , n-1$$ and all $latex x \in \B{R}^n$$.
134
135 $head size_var$$
136 The result $icode s$$ has prototype
137 $codei%
138 size_t %s%
139 %$$
140 and is the number of variables in the operation sequence plus the following:
141 one for a phantom variable with tape address zero,
142 one for each component of the range that is a parameter.
143 The amount of work and memory necessary for computing function values
144 and derivatives using $icode f$$ is roughly proportional to $icode s$$.
145 (The function call $cref/f.size_order()/size_order/$$
146 returns the number of Taylor coefficient orders, per variable,direction,
147 currently stored in $icode f$$.)
148 $pre
149
150 $$
151 If there is no operation sequence stored in $icode f$$,
152 $code size_var$$ returns zero
153 (see $cref/default constructor/FunConstruct/Default Constructor/$$).
154
155 $head size_par$$
156 The result $icode s$$ has prototype
157 $codei%
158 size_t %s%
159 %$$
160 and is the number of parameters in the operation sequence
161 (include a phantom parameter at index zero that is not used).
162 Parameters differ from variables in that only values
163 (and not derivatives) need to be stored for each parameter.
164 These parameters are considered part of the operation
165 sequence, as opposed to the Taylor coefficients which are
166 considered extra data in the function object $icode f$$.
167 Note that one $icode Base$$ value is required for each parameter.
168
169 $head size_op$$
170 The result $icode s$$ has prototype
171 $codei%
172 size_t %s%
173 %$$
174 and is the number of operations in the operation sequence.
175 Some operators, like comparison operators,
176 do not correspond to a variable.
177 Other operators, like the sine operator,
178 correspond to two variables.
179 Thus, this value will be different from
180 $cref/size_var/fun_property/size_var/$$.
181 Note that one $code enum$$ value is required for each operator.
182
183 $head size_op_arg$$
184 The result $icode s$$ has prototype
185 $codei%
186 size_t %s%
187 %$$
188 and is the total number of operator arguments in the operation sequence.
189 For example, Binary operators (e.g. addition) have two arguments.
190 Note that one integer index is stored in the operation sequence
191 for each argument.
192 Also note that, as of 2013-10-20, there is an extra
193 phantom argument with index 0 that is not used.
194
195 $head size_text$$
196 The result $icode s$$ has prototype
197 $codei%
198 size_t %s%
199 %$$
200 and is the total characters used in the $cref PrintFor$$ commands
201 in this operation sequence.
202
203 $head size_VecAD$$
204 The result $icode s$$ has prototype
205 $codei%
206 size_t %s%
207 %$$
208 and is the number of $cref VecAD$$ vectors,
209 plus the number of elements in the vectors.
210 Only $code VecAD$$ vectors that depend on the
211 independent variables are stored in the operation sequence.
212
213 $head size_random$$
214 The result $icode s$$ has prototype
215 $codei%
216 size_t %s%
217 %$$
218 and is the amount of memory currently holding information
219 for randomly access the operator sequence.
220 Random access is only used by the following routines
221 $cref subgraph_sparsity$$,
222 $cref subgraph_reverse$$, and
223 $cref optimize$$.
224 The optimize routine replaces the operation sequence, so the extra
225 memory is automatically dropped.
226 The subgraph routines hold onto this information
227 so that it does not need to be recalculated between calls.
228 The routine
229 $cref/clear_subgraph/subgraph_reverse/clear_subgraph/$$
230 will free this extra memory.
231
232 $head size_dyn_ind$$
233 The result $icode s$$ has prototype
234 $codei%
235 size_t %s%
236 %$$
237 and is the number of independent
238 $cref/dynamic/glossary/Parameter/Dynamic/$$ parameters
239 in the operation sequence.
240 This is the size of the
241 $cref/dynamic/Independent/dynamic/$$ parameter in the
242 corresponding call to $code Independent$$.
243
244 $head size_dyn_par$$
245 The result $icode s$$ has prototype
246 $codei%
247 size_t %s%
248 %$$
249 and is the number of
250 $cref/dynamic/glossary/Parameter/Dynamic/$$ parameters.
251 The dynamic parameters depend on the value of
252 the independent dynamic parameters but not on the value of the variables.
253 This includes the independent dynamic parameters.
254
255 $head size_dyn_arg$$
256 The result $icode s$$ has prototype
257 $codei%
258 size_t %s%
259 %$$
260 and is the total number of dynamic parameter operator arguments
261 in the operation sequence.
262 For example, Binary operators (e.g. addition) have two arguments.
263 Note that one integer index is stored in the operation sequence
264 for each argument.
265
266
267 $head size_op_seq$$
268 The result $icode s$$ has prototype
269 $codei%
270 size_t %s%
271 %$$
272 and is the amount of memory required to store the operation sequence
273 (not counting a small amount of memory required for every operation sequence).
274 For the current version of CppAD, this is given by
275 $comment see size_t player::Memory(void)$$
276 $codei%
277 %s% = %f%.size_op() * sizeof(CPPAD_VEC_ENUM_TYPE)
278 + %f%.size_op_arg() * sizeof(%tape_addr_type%)
279 + %f%.size_par() * sizeof(%Base%)
280 + %f%.size_par() * sizeof(bool)
281 + %f%.size_dyn_par() * sizeof(CPPAD_VEC_ENUM_TYPE)
282 + %f%.size_dyn_par() * sizeof(%tape_addr_type%)
283 + %f%.size_dyn_arg() * sizeof(%tape_addr_type%)
284 + %f%.size_text() * sizeof(char)
285 + %f%.size_VecAD() * sizeof(%tape_addr_type%)
286 %$$
287 see $cref/tape_addr_type/cmake/cppad_tape_addr_type/$$.
288 Note that this is the minimal amount of memory that can hold
289 the information corresponding to an operation sequence.
290 The actual amount of memory allocated ($cref/inuse/ta_inuse/$$)
291 for the operations sequence may be larger.
292 Also note that $code CPPAD_VEC_ENUM_TYPE$$ is not part
293 of the CppAD API and may change.
294
295 $head Example$$
296 $children%
297 example/general/fun_property.cpp
298 %$$
299 The file
300 $cref fun_property.cpp$$
301 contains an example and test of these operations.
302
303
304 $end
0 -------------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------------
11 $begin function_name$$
12 $spell
13 const
14 std
15 $$
16
17 $section Setting and Getting a Function's Name$$
18
19 $head Syntax$$
20 $icode%f%.function_name_set(%function_name%)
21 %$$
22 $icode%function_name% = %f%.function_name_get()
23 %$$
24
25 $head See Also$$
26 $cref fun_property$$
27
28 $head f$$
29 In the set operation, $icode f$$ has prototype
30 $codei%
31 ADFun<%Base%> %f%
32 %$$
33 In the get operation, $icode f$$ has prototype
34 $codei%
35 const ADFun<%Base%> %f%
36 %$$
37 (see $codei%ADFun<%Base%>%$$ $cref/constructor/FunConstruct/$$).
38
39 $head function_name$$
40 is the name of the function.
41 In the set operation, $icode function_name$$ has prototype
42 $codei%
43 const std::string& %function_name%
44 %$$
45 In the get operation, $icode function_name$$ has prototype
46 $codei%
47 std::string %function_name%
48 %$$
49
50 $children%
51 example/general/function_name.cpp
52 %$$
53 $head Example$$
54 The file $cref function_name.cpp$$ contains an example and test
55 of these operations.
56
57 $end
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2828 enum
2929 cpp
3030 Heaviside
31 notpos
3132 $$
3233
3334 $section C++ Representation of an AD Graph$$
9596 is always zero; e.g., the Heaviside function.
9697 Calls by this function to discrete functions use the index in this
9798 vector to identify the discrete functions; see
98 $cref/dis_graph_op/cpp_ad_graph/operator_arg/dis_graph_op/$$ below.
99 $cref/discrete_graph_op/cpp_ad_graph/operator_arg/discrete_graph_op/$$ below.
99100 If there are no calls to discrete functions, this vector can be empty.
100101
101102 $head atomic_name_vec$$
137138 $icode%operator_vec%[%i%]%$$ contains the instructions
138139 for computing the result vector $icode r_i$$.
139140
140 $subhead C++11$$
141 If the c++ compiler being used does not support c++11,
142 it is assumed that operators that
143 $cref/require c++11/graph_op_enum/Unary/Require C++11/$$
144 are $bold not$$ used.
145
146141 $head operator_arg$$
147142 is a vector with size equal to the sum of the size of each
148143 of its sub-vectors (which are described below).
156151 $codei%
157152 %operator_arg%[ %first_node%[%i%] + %j% ]
158153 %$$
159 Except for the
160 $code dis_graph_op$$, $code atom_graph_op$$, and $code sum_graph_op$$ cases,
161 the $icode operator_arg$$ sub-vector for the $th i$$ operator starts are
162 $icode%first_node%[%i%]%$$ and has $icode%n_node_arg%[%i%]%$$ elements.
163
164 $subhead dis_graph_op$$
165 In the case where $icode%operator_vec%[%i%].op_enum%$$ is
166 $code dis_graph_op$$:
154 The $icode operator_arg$$ sub-vector for the $th i$$ operator starts are
155 $icode%first_node%[%i%]%$$ and has $icode%n_node_arg%[%i%]%$$ elements
156 except for the following operators:
157 $code sum_graph_op$$,
158 $code discrete_graph_op$$,
159 $code atom_graph_op$$,
160 $code print_graph_op$$.
161
162 $subhead print_graph_op$$
163 In the case where $icode%operator_vec%[%i%].op_enum%$$ is
164 $code print_graph_op$$:
165 $codei%
166 %before%[%i%] = %operator_arg%[ %first_node%[%i%] - 2 ]
167 %$$
168 is the index in $cref/print_text_vec/cpp_ad_graph/print_text_vec/$$
169 of the text that is printed before the value and
170 $codei%
171 %after%[%i%] = %operator_arg%[ %first_node%[%i%] - 2 ]
172 %$$
173 is the index in $cref/print_text_vec/cpp_ad_graph/print_text_vec/$$
174 of the text that is printed after the value.
175 The $icode operator_arg$$ sub-vector for the $th i$$ operator
176 starts at index $icode%first_node%[%i%]-2%$$
177 and has $codei%4 = %n_node_arg%[%i%]+2%$$ elements.
178 The node with index
179 $codei%
180 %notpos%[%i%] = %operator_arg%[ %first_node%[%i%] ]
181 %$$
182 is checked and if it is positive, nothing is printed by this operator.
183 Otherwise, the value corresponding to the following node is printed:
184 $codei%
185 %value%[%i%] = %operator_arg%[ %first_node%[%i%] + 1 ]
186 %$$
187
188 $subhead discrete_graph_op$$
189 In the case where $icode%operator_vec%[%i%].op_enum%$$ is
190 $code discrete_graph_op$$:
167191 $codei%
168192 %name_index%[%i%] = %operator_arg%[ %first_node%[%i%] - 1 ]
169193 %$$
00 # ifndef CPPAD_CORE_GRAPH_CPP_GRAPH_HPP
11 # define CPPAD_CORE_GRAPH_CPP_GRAPH_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
1010 in the Eclipse Public License, Version 2.0 are satisfied:
1111 GNU General Public License, Version 2.0 or later.
1212 ---------------------------------------------------------------------------- */
13 # include <iomanip>
1314 # include <string>
1415 # include <cppad/utility/vector.hpp>
1516 # include <cppad/local/graph/cpp_graph_op.hpp>
8384
8485 $head dependent_vec$$
8586 $cref/dependent_vec/cpp_ad_graph/dependent_vec/$$ is initialized as empty.
87
88 $head Parallel Mode$$
89 The first use of the $code cpp_graph$$ constructor
90 cannot be in $cref/parallel/ta_in_parallel/$$ execution mode.
8691
8792 $end
8893 --------------------------------------------------------------------------------
102107 return;
103108 }
104109 cpp_graph(void)
105 { initialize(); }
110 { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL
111 static bool first = true;
112 if( first )
113 { first = false;
114 CPPAD_ASSERT_UNKNOWN( local::graph::op_name2enum.size() == 0 );
115 // initialize cpp_graph global variables in cpp_graph_op.cpp
116 local::graph::set_operator_info();
117 }
118 initialize();
119 }
106120 /*
107121 ---------------------------------------------------------------------------------
108122 $begin cpp_graph_scalar$$
233247 %$$
234248 $icode%graph_obj%.operator_arg_push_back(%argument%)
235249 %$$
236 $icode%graph_obj%.dependent_vec_get(%node_index%)
250 $icode%graph_obj%.dependent_vec_push_back(%node_index%)
237251 %$$
238252
239253 $subhead Find$$
395409 { return dependent_vec_.size(); }
396410 void dependent_vec_push_back(const size_t node_index)
397411 { dependent_vec_.push_back(node_index); }
412 /*
413 $begin cpp_graph_print$$
414 $spell
415 obj
416 const
417 std::ostream
418 cpp
419 $$
420
421 $section Print A C++ AD Graph$$
422
423 $head Syntax$$
424 $icode%graph_obj%.print(%os%)
425 %$$
426
427 $head graph_obj$$
428 is an const $code cpp_graph$$ object.
429
430 $head os$$
431 Is the $code std::ostream$$ where the graph is printed.
432
433 $head Discussion$$
434 This function is included to help with using the $code cpp_graph$$ class.
435 The formatting of it's output is not part of the API; i.e.,
436 it may change in the future.
437
438 $children%
439 example/graph/print_graph.cpp
440 %$$
441 $head Example$$
442 The file $cref print_graph.cpp$$ contains an example and test of this operation.
443
444 $end
445 */
446 void print(std::ostream& os) const
447 { using std::setw;
448 using std::string;
449 //
450 // function name
451 if( function_name_ != "" )
452 os << function_name_ << "\n";
453 //
454 // initialize node index
455 size_t node_index = 1;
456 //
457 // text vector
458 size_t n_text = print_text_vec_.size();
459 for(size_t i = 0; i < n_text; ++i)
460 { string s_i = "c[" + std::to_string(i) + "]";
461 //
462 os << setw(11) << "";
463 os << setw(10) << s_i;
464 os << "'" << print_text_vec_[i] << "'";
465 os << "\n";
466 }
467 //
468 // parameter vector
469 for(size_t i = 0; i < n_dynamic_ind_; i++)
470 { string p_i = "p[" + std::to_string(i) + "]";
471 //
472 os << setw(11) << node_index;
473 os << setw(10) << p_i;
474 os << "\n";
475 ++node_index;
476 }
477 //
478 // variable vector
479 for(size_t i = 0; i < n_variable_ind_; i++)
480 { string x_i = "x[" + std::to_string(i) + "]";
481 //
482 os << setw(11) << node_index;
483 os << setw(10) << x_i;
484 os << "\n";
485 ++node_index;
486 }
487 //
488 // constant vector
489 size_t n_constant = constant_vec_.size();
490 for(size_t i = 0; i < n_constant; i++)
491 { string c_i = "c[" + std::to_string(i) + "]";
492 //
493 os << setw(11) << node_index;
494 os << setw(10) << c_i;
495 os << setw(20) << constant_vec_[i];
496 os << "\n";
497 ++node_index;
498 }
499
500 size_t n_op = operator_vec_.size();
501 cpp_graph::const_iterator itr;
502 for(size_t op_index = 0; op_index < n_op; ++op_index)
503 { if( op_index == 0 )
504 itr = begin();
505 else
506 ++itr;
507 cpp_graph::const_iterator::value_type itr_value = *itr;
508 //
509 const vector<size_t>& str_index( *itr_value.str_index_ptr );
510 const vector<size_t>& arg( *itr_value.arg_node_ptr );
511 graph_op_enum op_enum = itr_value.op_enum;
512 size_t n_result = itr_value.n_result;
513 size_t n_arg = arg.size();
514 CPPAD_ASSERT_UNKNOWN( n_arg > 0 );
515 //
516 string op_name = local::graph::op_enum2name[ op_enum ];
517 //
518 if( n_result == 0 )
519 os << setw(11) << "";
520 else if( n_result == 1 )
521 os << setw(11) << node_index;
522 else
523 { string first = std::to_string(node_index);
524 string last = std::to_string(node_index + n_result - 1);
525 os << setw(11) << first + "-" + last;
526 }
527 os << setw(10) << op_name;
528 for(size_t i = 0; i < n_arg; ++i)
529 os << setw(5) << arg[i];
530
531 switch( op_enum )
532 {
533 case graph::discrete_graph_op:
534 CPPAD_ASSERT_UNKNOWN( str_index.size() == 1 );
535 os << discrete_name_vec_get( str_index[0] );
536 break;
537
538 case graph::atom_graph_op:
539 CPPAD_ASSERT_UNKNOWN( str_index.size() == 1 );
540 os << atomic_name_vec_get( str_index[0] );
541 break;
542
543 case graph::print_graph_op:
544 CPPAD_ASSERT_UNKNOWN( str_index.size() == 2 );
545 os << print_text_vec_get( str_index[0] ) << ",";
546 os << print_text_vec_get( str_index[1] );
547 break;
548
549 default:
550 CPPAD_ASSERT_UNKNOWN( str_index.size() == 0 );
551 break;
552 }
553 os << "\n";
554 node_index += n_result;
555 }
556 //
557 // dependent vector
558 size_t n_dependent = dependent_vec_.size();
559 os << "y nodes = ";
560 for(size_t i = 0; i < n_dependent; i++)
561 { os << dependent_vec_[i];
562 if( i + 1 < n_dependent )
563 os << ", ";
564 }
565 os << "\n";
566 }
398567
399568 }; // END CPP_GRAPH_CLASS
400569
00 # ifndef CPPAD_CORE_GRAPH_FROM_GRAPH_HPP
11 # define CPPAD_CORE_GRAPH_FROM_GRAPH_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3232
3333 $head Syntax$$
3434 $codei%
35 cpp_graph %graph_obj%
3536 ADFun<%Base%> %fun%
3637 %fun%.from_graph(%graph_obj%)
3738 %fun%.from_graph(%graph_obj%, %dyn2var%, %var2dyn%)
154155 }
155156 //
156157 // Start of node indices
158 # ifndef NDEBUG
157159 size_t start_dynamic_ind = 1;
158160 size_t start_independent = start_dynamic_ind + n_dynamic_ind;
159161 size_t start_constant = start_independent + n_variable_ind;
160162 size_t start_operator = start_constant + n_constant;
163 # endif
161164 //
162165 // initialize mappings from node index as empty
163166 // (there is no node zero)
336339 cpp_graph::const_iterator graph_itr;
337340 //
338341 // loop over operators in the recording
342 # ifndef NDEBUG
339343 size_t start_result = start_operator;
344 # endif
340345 for(size_t op_index = 0; op_index < n_usage; ++op_index)
341346 { // op_enum, str_index, n_result, arg_node
342347 if( op_index == 0 )
873878 CPPAD_ASSERT_UNKNOWN( NumArg(local::LogOp) == 1 );
874879 break;
875880
881 case neg_graph_op:
882 i_result = rec.PutOp(local::NegOp);
883 rec.PutArg( arg[0] );
884 CPPAD_ASSERT_UNKNOWN( NumArg(local::NegOp) == 1 );
885 break;
886
876887 case sign_graph_op:
877888 i_result = rec.PutOp(local::SignOp);
878889 rec.PutArg( arg[0] );
9901001 CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) );
9911002 break;
9921003
1004 case neg_graph_op:
1005 i_result = rec.put_dyn_par(nan, local::neg_dyn, arg[0] );
1006 CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) );
1007 break;
1008
9931009 case sign_graph_op:
9941010 i_result = rec.put_dyn_par(nan, local::sign_dyn, arg[0] );
9951011 CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) );
11121128
11131129 case log_graph_op:
11141130 result = CppAD::log( parameter[ arg[0] ] );
1131 i_result = rec.put_con_par(result);
1132 CPPAD_ASSERT_UNKNOWN( parameter[i_result] == result );
1133 break;
1134
1135 case neg_graph_op:
1136 result = - parameter[ arg[0] ];
11151137 i_result = rec.put_con_par(result);
11161138 CPPAD_ASSERT_UNKNOWN( parameter[i_result] == result );
11171139 break;
13931415 node2fun.push_back(i_result);
13941416 }
13951417 //
1418 # ifndef NDEBUG
13961419 start_result += n_result;
1420 # endif
13971421 CPPAD_ASSERT_UNKNOWN( node2fun.size() == start_result );
13981422 CPPAD_ASSERT_UNKNOWN( node_type.size() == start_result );
13991423 }
00 # ifndef CPPAD_CORE_GRAPH_GRAPH_OP_ENUM_HPP
11 # define CPPAD_CORE_GRAPH_GRAPH_OP_ENUM_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3838
3939 $section C++ AD Graph Operator Enum Type$$
4040
41 $comment
42 The following headings are referenced by comments in cpp_graph_op.cpp:
43 Atomic Fucntion, Comparison, Discrete Function, Print, Summation
44 $$
45
4146 $head Unary$$
4247 The unary operators have one argument and one result node.
4348 The argument is a node index and the result is the next node.
44
45 $subhead Require C++11$$
46 The following unary operators require a compiler that supports c++11:
47 $code asinh$$, $code acosh$$, $code atanh$$,
48 $code erf$$, $code erfc$$,
49 $code expm1$$, $code log1p$$.
5049
5150 $head Binary$$
5251 The binary operators have two arguments and one result node.
217216 expm1_graph_op, // unary: exponential minus one
218217 log1p_graph_op, // unary: logarithm of one plus argument
219218 log_graph_op, // unary: logarithm
219 neg_graph_op, // unary: minus
220220 mul_graph_op, // binary: multiplication
221221 pow_graph_op, // binary: first argument raised to second argument
222222 print_graph_op, // print during zero order forward
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3939 div
4040 chkpoint
4141 CppAD
42 neg
4243 $$
4344
4445 $section Json AD Graph Operator Definitions$$
7172 %$$
7273 The possible values for the string $icode name$$ are listed
7374 in the table below.
74 The result is the node value as a function of the
75 argument value.
76 If c++11 is yes (no),
77 then c++11 or higher is required to use the operator with CppAD.
78
75 The corresponding result is the node value as a function of the argument value.
76
77 $comment BEGIN_SORT_THIS_LINE_PLUS_3$$
7978 $table
80 $icode name$$ $cnext result $cnext c++11 $rnext
81 $code abs$$ $cnext absolute value $cnext no $rnext
82 $code acos$$ $cnext inverse cosine $cnext no $rnext
83 $code asin$$ $cnext inverse sine $cnext no $rnext
84 $code atan$$ $cnext inverse tangent $cnext no $rnext
85 $code cosh$$ $cnext hyperbolic cosine $cnext no $rnext
86 $code cos$$ $cnext cosine $cnext no $rnext
87 $code exp$$ $cnext exponential $cnext no $rnext
88 $code log$$ $cnext logarithm $cnext no $rnext
89 $code sign$$ $cnext sign function $cnext no $rnext
90 $code sinh$$ $cnext hyperbolic sine $cnext no $rnext
91 $code sin$$ $cnext sine $cnext no $rnext
92 $code sqrt$$ $cnext square root $cnext no $rnext
93 $code tanh$$ $cnext hyperbolic tangent $cnext no $rnext
94 $code tan$$ $cnext tangent $cnext no $rnext
95 $code asinh$$ $cnext inverse hyperbolic sine $cnext yes $rnext
96 $code atanh$$ $cnext inverse hyperbolic sine $cnext yes $rnext
97 $code erf$$ $cnext error functions $cnext yes $rnext
98 $code erfc$$ $cnext complementary error function $cnext yes $rnext
99 $code expm1$$ $cnext minus one plus the exponential $cnext yes $rnext
100 $code log1p$$ $cnext log plus one $cnext yes $rnext
101 $code acosh$$ $cnext inverse hyperbolic cosine $cnext yes
79 $icode name$$ $cnext result $rnext
80 $code abs$$ $cnext absolute value $rnext
81 $code acos$$ $cnext inverse cosine $rnext
82 $code acosh$$ $cnext inverse hyperbolic cosine $rnext
83 $code asin$$ $cnext inverse sine $rnext
84 $code asinh$$ $cnext inverse hyperbolic sine $rnext
85 $code atan$$ $cnext inverse tangent $rnext
86 $code atanh$$ $cnext inverse hyperbolic sine $rnext
87 $code cos$$ $cnext cosine $rnext
88 $code cosh$$ $cnext hyperbolic cosine $rnext
89 $code erf$$ $cnext error functions $rnext
90 $code erfc$$ $cnext complementary error function $rnext
91 $code exp$$ $cnext exponential $rnext
92 $code expm1$$ $cnext minus one plus the exponential $rnext
93 $code log$$ $cnext logarithm $rnext
94 $code log1p$$ $cnext log plus one $rnext
95 $code neg$$ $cnext negative $rnext
96 $code sign$$ $cnext sign function $rnext
97 $code sin$$ $cnext sine $rnext
98 $code sinh$$ $cnext hyperbolic sine $rnext
99 $code sqrt$$ $cnext square root $rnext
100 $code tan$$ $cnext tangent $rnext
101 $code tanh$$ $cnext hyperbolic tangent
102102 $tend
103 $comment END_SORT_THIS_LINE_MINUS_2$$
103104
104105 $subhead Example$$
105106 The file $cref json_unary_op.cpp$$ is an example and test
3333
3434 $head Syntax$$
3535 $codei%
36 cpp_graph %graph_obj%
3637 ADFun<%Base%> %fun%
3738 %fun%.to_graph(%graph_obj%)
3839 %$$
7273 { using local::pod_vector;
7374 using local::opcode_t;
7475 using namespace CppAD::graph;
75 // --------------------------------------------------------------------
76 if( local::graph::op_name2enum.size() == 0 )
77 { CPPAD_ASSERT_KNOWN( ! thread_alloc::in_parallel() ,
78 "call to set_operator_info in parallel mode"
79 );
80 local::graph::set_operator_info();
81 }
8276 //
8377 # ifndef NDEBUG
8478 # endif
263257 graph_op = log_graph_op;
264258 break;
265259
260 case local::neg_dyn:
261 graph_op = neg_graph_op;
262 break;
263
266264 case local::sign_dyn:
267265 graph_op = sign_graph_op;
268266 break;
492490 // operator is not ignored.
493491 // -------------------------------------------------------------------
494492 switch( var_op )
495 {
493 { // 2DO: some of these cases can be joined
494
496495 // -------------------------------------------------------------
497496 // unary operators
498497 case local::AbsOp:
566565 break;
567566
568567 case local::LogOp:
568 fixed_n_arg = 1;
569 is_var[0] = true;
570 break;
571
572 case local::NegOp:
569573 fixed_n_arg = 1;
570574 is_var[0] = true;
571575 break;
707711
708712 case local::LogOp:
709713 graph_op = log_graph_op;
714 break;
715
716 case local::NegOp:
717 graph_op = neg_graph_op;
710718 break;
711719
712720 case local::SignOp:
11 # define CPPAD_CORE_GRAPH_TO_JSON_HPP
22
33 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
55
66 CppAD is distributed under the terms of the
77 Eclipse Public License Version 2.0.
7171 // END_PROTOTYPE
7272 { using local::pod_vector;
7373 using local::opcode_t;
74 // --------------------------------------------------------------------
75 if( local::graph::op_name2enum.size() == 0 )
76 { CPPAD_ASSERT_KNOWN( ! thread_alloc::in_parallel() ,
77 "call to set_operator_info in parallel mode"
78 );
79 local::graph::set_operator_info();
80 }
8174 //
8275 // to_graph return values
8376 cpp_graph graph_obj;
00 # ifndef CPPAD_CORE_HESSIAN_HPP
11 # define CPPAD_CORE_HESSIAN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5858 (see $cref/Vector/Hessian/Vector/$$ below)
5959 and its size
6060 must be equal to $icode n$$, the dimension of the
61 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
61 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
6262 It specifies
6363 that point at which to evaluate the Hessian.
6464
6868 size_t %l%
6969 %$$
7070 and is less than $icode m$$, the dimension of the
71 $cref/range/seq_property/Range/$$ space for $icode f$$.
71 $cref/range/fun_property/Range/$$ space for $icode f$$.
7272 It specifies the component of $icode F$$
7373 for which we are evaluating the Hessian.
7474 To be specific, in the case where the argument $icode l$$ is present,
00 # ifndef CPPAD_CORE_JACOBIAN_HPP
11 # define CPPAD_CORE_JACOBIAN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5454 (see $cref/Vector/Jacobian/Vector/$$ below)
5555 and its size
5656 must be equal to $icode n$$, the dimension of the
57 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
57 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
5858 It specifies
5959 that point at which to evaluate the Jacobian.
6060
6565 %$$
6666 (see $cref/Vector/Jacobian/Vector/$$ below)
6767 and its size is $latex m * n$$; i.e., the product of the
68 $cref/domain/seq_property/Domain/$$
68 $cref/domain/fun_property/Domain/$$
6969 and
70 $cref/range/seq_property/Range/$$
70 $cref/range/fun_property/Range/$$
7171 dimensions for $icode f$$.
7272 For $latex i = 0 , \ldots , m - 1 $$
7373 and $latex j = 0 , \ldots , n - 1$$
00 # ifndef CPPAD_CORE_NEW_DYNAMIC_HPP
11 # define CPPAD_CORE_NEW_DYNAMIC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5858 $cref/dynamic/Independent/dynamic/$$ parameter vector
5959 in the call to $code Independent$$ that started
6060 the recording for $icode f$$; see
61 $cref/size_dyn_ind/seq_property/size_dyn_ind/$$.
61 $cref/size_dyn_ind/fun_property/size_dyn_ind/$$.
6262
6363 $head BaseVector$$
6464 The type $icode BaseVector$$ must be a $cref SimpleVector$$ class with
00 # ifndef CPPAD_CORE_NUM_SKIP_HPP
11 # define CPPAD_CORE_NUM_SKIP_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
2626 $icode%n% = %f%.number_skip()%$$
2727
2828 $subhead See Also$$
29 $cref seq_property$$
29 $cref fun_property$$
3030
3131 $head Purpose$$
3232 The $cref/conditional expressions/CondExp/$$ use either the
00 # ifndef CPPAD_CORE_NUMERIC_LIMITS_HPP
11 # define CPPAD_CORE_NUMERIC_LIMITS_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
2020 CppAD
2121 namespace
2222 const
23 inf
24 isnan
2325 $$
2426
2527 $section Numeric Limits For an AD and Base Types$$
3335 %$$
3436 $icode%nan% = numeric_limits<%Float%>::quiet_NaN()
3537 %$$
38 $icode%inf% = numeric_limits<%Float%>::infinity()
39 %$$
3640 $codei%numeric_limits<%Float%>::digits10%$$
3741
3842 $head CppAD::numeric_limits$$
4145 static %Float% CppAD::numeric_limits<%Float%>::%fun%(%void%)
4246 %$$
4347 where $icode fun$$ is
44 $code epsilon$$, $code min$$, $code max$$, and $code quiet_NaN$$.
48 $code epsilon$$, $code min$$, $code max$$, $code quiet_NaN$$,
49 and $code infinity$$.
4550 (Note that $code digits10$$ is member variable and not a function.)
4651
4752 $head std::numeric_limits$$
115120 %nan% != %nan%
116121 %$$
117122
123 $head infinity$$
124 The result $icode inf$$ is equal to the
125 positive infinite value and has prototype
126 $codei%
127 %Float% %inf%
128 %$$
129 The file $cref num_limits.cpp$$
130 tests the value $icode inf$$ by checking that the following are true
131 $codei%
132 %inf% + 100 == %inf%
133 isnan(%inf% - %inf%)
134 %$$
135
118136 $head digits10$$
119137 The member variable $code digits10$$ has prototype
120138 $codei%
183201 { CPPAD_ASSERT_KNOWN(
184202 false,
185203 "numeric_limits<Float>::quiet_NaN() is not specialized for this Float"
204 );
205 return Float(0);
206 }
207 /// positive infinite value
208 static Float infinity(void)
209 { CPPAD_ASSERT_KNOWN(
210 false,
211 "numeric_limits<Float>::infinity() is not specialized for this Float"
186212 );
187213 return Float(0);
188214 }
206232 /// not a number
207233 static AD<Base> quiet_NaN(void)
208234 { return AD<Base>( numeric_limits<Base>::quiet_NaN() ); }
235 /// positive infinite value
236 static AD<Base> infinity(void)
237 { return AD<Base>( numeric_limits<Base>::infinity() ); }
209238 /// number of decimal digits
210239 static const int digits10 = numeric_limits<Base>::digits10;
211240 };
00 # ifndef CPPAD_CORE_OPTIMIZE_HPP
11 # define CPPAD_CORE_OPTIMIZE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
4343 $head Purpose$$
4444 The operation sequence corresponding to an $cref ADFun$$ object can
4545 be very large and involve many operations; see the
46 size functions in $cref seq_property$$.
46 size functions in $cref fun_property$$.
4747 The $icode%f%.optimize%$$ procedure reduces the number of operations,
4848 and thereby the time and the memory, required to
4949 compute function and derivative values.
00 # ifndef CPPAD_CORE_POW_HPP
11 # define CPPAD_CORE_POW_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3636 $latex \[
3737 {\rm pow} (x, y) = x^y
3838 \] $$
39 This version of the $code pow$$ function may use
39
40 $subhead If y is a Variable$$
41 If $icode y$$ is a variable,
42 the $code pow$$ function may use
4043 logarithms and exponentiation to compute derivatives.
4144 This will not work if $icode x$$ is less than or equal zero.
45
46 $subhead If y is a Parameter$$
47 If $icode y$$ is a parameter, a different method is used to
48 compute the derivatives; see $cref pow_forward$$.
49 In the special case where $icode x$$ is zero,
50 zero is returned as the derivative.
51 This is correct when $icode y$$ minus the order of the derivative
52 is greater than zero.
53 If $icode y$$ minus the order of the derivative is zero,
54 then $icode y$$ is an integer.
55 If $icode y$$ minus the order of the derivative is less than zero,
56 the actual derivative is infinite.
57
58 $subhead If y is an Integer$$
4259 If the value of $icode y$$ is an integer,
43 the $cref pow_int$$ function is used to compute this value
60 the $cref pow_int$$ function can be used to compute this value
4461 using only multiplication (and division if $icode y$$ is negative).
45 (This will work even if $icode x$$ is less than or equal zero.)
62 This will work even if $icode x$$ is less than or equal zero.
63
4664
4765 $head x$$
4866 The argument $icode x$$ has one of the following prototypes
7896 $head Example$$
7997 $children%
8098 example/general/pow.cpp
99 %example/general/pow_nan.cpp
81100 %$$
82 The file
83 $cref pow.cpp$$
84 is an examples and tests of this function.
101 The files
102 $cref pow.cpp$$ and $cref pow_nan.cpp$$
103 are examples tests of this function.
85104
86105 $end
87106 -------------------------------------------------------------------------------
144163 }
145164 else
146165 { // result = variable^parameter
147 CPPAD_ASSERT_UNKNOWN( local::NumRes(local::PowvpOp) == 3 );
166 CPPAD_ASSERT_UNKNOWN( local::NumRes(local::PowvpOp) == 1 );
148167 CPPAD_ASSERT_UNKNOWN( local::NumArg(local::PowvpOp) == 2 );
149168
150169 // put operand addresses in tape
00 # ifndef CPPAD_CORE_REV_ONE_HPP
11 # define CPPAD_CORE_REV_ONE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5757 (see $cref/Vector/RevOne/Vector/$$ below)
5858 and its size
5959 must be equal to $icode n$$, the dimension of the
60 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
60 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
6161 It specifies
6262 that point at which to evaluate the derivative.
6363
6767 size_t %i%
6868 %$$
6969 and is less than $latex m$$, the dimension of the
70 $cref/range/seq_property/Range/$$ space for $icode f$$.
70 $cref/range/fun_property/Range/$$ space for $icode f$$.
7171 It specifies the
7272 component of $latex F$$ that we are computing the derivative of.
7373
7878 %$$
7979 (see $cref/Vector/RevOne/Vector/$$ below)
8080 and its size is $icode n$$, the dimension of the
81 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
81 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
8282 The value of $icode dw$$ is the derivative of $latex F_i$$
8383 evaluated at $icode x$$; i.e.,
8484 for $latex j = 0 , \ldots , n - 1 $$
00 # ifndef CPPAD_CORE_REV_TWO_HPP
11 # define CPPAD_CORE_REV_TWO_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5959 (see $cref/BaseVector/RevTwo/BaseVector/$$ below)
6060 and its size
6161 must be equal to $icode n$$, the dimension of the
62 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
62 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
6363 It specifies
6464 that point at which to evaluate the partial derivatives listed above.
6565
7272 We use $icode p$$ to denote the size of the vector $icode i$$.
7373 All of the indices in $icode i$$
7474 must be less than $icode m$$, the dimension of the
75 $cref/range/seq_property/Range/$$ space for $icode f$$; i.e.,
75 $cref/range/fun_property/Range/$$ space for $icode f$$; i.e.,
7676 for $latex \ell = 0 , \ldots , p-1$$, $latex i[ \ell ] < m$$.
7777
7878 $head j$$
00 # ifndef CPPAD_CORE_SPARSE_HES_HPP
11 # define CPPAD_CORE_SPARSE_HES_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3838 $head Purpose$$
3939 We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the
4040 function corresponding to $icode f$$.
41 Here $icode n$$ is the $cref/domain/seq_property/Domain/$$ size,
42 and $icode m$$ is the $cref/range/seq_property/Range/$$ size, or $icode f$$.
41 Here $icode n$$ is the $cref/domain/fun_property/Domain/$$ size,
42 and $icode m$$ is the $cref/range/fun_property/Range/$$ size, or $icode f$$.
4343 The syntax above takes advantage of sparsity when computing the Hessian
4444 $latex \[
4545 H(x) = \dpow{2}{x} \sum_{i=0}^{m-1} w_i F_i (x)
00 # ifndef CPPAD_CORE_SPARSE_HESSIAN_HPP
11 # define CPPAD_CORE_SPARSE_HESSIAN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3737 %$$
3838
3939 $head Purpose$$
40 We use $latex n$$ for the $cref/domain/seq_property/Domain/$$ size,
41 and $latex m$$ for the $cref/range/seq_property/Range/$$ size of $icode f$$.
40 We use $latex n$$ for the $cref/domain/fun_property/Domain/$$ size,
41 and $latex m$$ for the $cref/range/fun_property/Range/$$ size of $icode f$$.
4242 We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ do denote the
4343 $cref/AD function/glossary/AD Function/$$
4444 corresponding to $icode f$$.
7171 (see $cref/BaseVector/sparse_hessian/BaseVector/$$ below)
7272 and its size
7373 must be equal to $icode n$$, the dimension of the
74 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
74 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
7575 It specifies
7676 that point at which to evaluate the Hessian.
7777
00 # ifndef CPPAD_CORE_SPARSE_JAC_HPP
11 # define CPPAD_CORE_SPARSE_JAC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
4343 $head Purpose$$
4444 We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the
4545 function corresponding to $icode f$$.
46 Here $icode n$$ is the $cref/domain/seq_property/Domain/$$ size,
47 and $icode m$$ is the $cref/range/seq_property/Range/$$ size, or $icode f$$.
46 Here $icode n$$ is the $cref/domain/fun_property/Domain/$$ size,
47 and $icode m$$ is the $cref/range/fun_property/Range/$$ size, or $icode f$$.
4848 The syntax above takes advantage of sparsity when computing the Jacobian
4949 $latex \[
5050 J(x) = F^{(1)} (x)
00 # ifndef CPPAD_CORE_SPARSE_JACOBIAN_HPP
11 # define CPPAD_CORE_SPARSE_JACOBIAN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
4444 %$$
4545
4646 $head Purpose$$
47 We use $latex n$$ for the $cref/domain/seq_property/Domain/$$ size,
48 and $latex m$$ for the $cref/range/seq_property/Range/$$ size of $icode f$$.
47 We use $latex n$$ for the $cref/domain/fun_property/Domain/$$ size,
48 and $latex m$$ for the $cref/range/fun_property/Range/$$ size of $icode f$$.
4949 We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ do denote the
5050 $cref/AD function/glossary/AD Function/$$
5151 corresponding to $icode f$$.
7878 (see $cref/BaseVector/sparse_jacobian/BaseVector/$$ below)
7979 and its size
8080 must be equal to $icode n$$, the dimension of the
81 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
81 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
8282 It specifies
8383 that point at which to evaluate the Jacobian.
8484
00 # ifndef CPPAD_CORE_SUBGRAPH_JAC_REV_HPP
11 # define CPPAD_CORE_SUBGRAPH_JAC_REV_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
4343 $head Purpose$$
4444 We use $latex F : \B{R}^n \rightarrow \B{R}^m$$ to denote the
4545 function corresponding to $icode f$$.
46 Here $icode n$$ is the $cref/domain/seq_property/Domain/$$ size,
47 and $icode m$$ is the $cref/range/seq_property/Range/$$ size, or $icode f$$.
46 Here $icode n$$ is the $cref/domain/fun_property/Domain/$$ size,
47 and $icode m$$ is the $cref/range/fun_property/Range/$$ size, or $icode f$$.
4848 The syntax above takes advantage of sparsity when computing the Jacobian
4949 $latex \[
5050 J(x) = F^{(1)} (x)
00 # ifndef CPPAD_CORE_UNARY_MINUS_HPP
11 # define CPPAD_CORE_UNARY_MINUS_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
7676
7777 // BEGIN CppAD namespace
7878 namespace CppAD {
79
80 // Broken g++ compiler inhibits declaring unary minus a member or friend
79 //
8180 template <class Base>
8281 AD<Base> AD<Base>::operator - (void) const
83 { // 2DO: make a more efficient by adding unary minus to op_code.h (some day)
82 {
83 // compute the Base part of this AD object
84 AD<Base> result;
85 result.value_ = - value_;
86 CPPAD_ASSERT_UNKNOWN( Parameter(result) );
87
88 // check if there is a recording in progress
89 local::ADTape<Base>* tape = AD<Base>::tape_ptr();
90 if( tape == nullptr )
91 return result;
92 // tape_id cannot match the default value for tape_id; i.e., 0
93 CPPAD_ASSERT_UNKNOWN( tape->id_ > 0 );
8494 //
85 AD<Base> result(0);
86 result -= *this;
95 if( tape->id_ != tape_id_ )
96 return result;
97 //
98 if( ad_type_ == variable_enum )
99 { // result is a variable
100 CPPAD_ASSERT_UNKNOWN( local::NumRes(local::NegOp) == 1 );
101 CPPAD_ASSERT_UNKNOWN( local::NumRes(local::NegOp) == 1 );
102 //
103 // put operand address in the tape
104 tape->Rec_.PutArg(taddr_);
105 // put operator in the tape
106 result.taddr_ = tape->Rec_.PutOp(local::NegOp);
107 // make result a variable
108 result.tape_id_ = tape_id_;
109 result.ad_type_ = variable_enum;
110 }
111 else
112 { CPPAD_ASSERT_UNKNOWN( ad_type_ == dynamic_enum );
113 addr_t arg0 = taddr_;
114 result.taddr_ = tape->Rec_.put_dyn_par(
115 result.value_, local::neg_dyn, arg0
116 );
117 result.tape_id_ = tape_id_;
118 result.ad_type_ = dynamic_enum;
119 }
87120 return result;
88121 }
89
90
122 //
91123 template <class Base>
92124 AD<Base> operator - (const VecAD_reference<Base> &right)
93125 { return - right.ADBase(); }
00 # ifndef CPPAD_CORE_VAR2PAR_HPP
11 # define CPPAD_CORE_VAR2PAR_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
2121 $$
2222
2323
24 $section Convert an AD Variable to a Parameter$$
24 $section Convert an AD Variable or Dynamic Parameter to a Constant$$
2525
2626 $head Syntax$$
2727 $icode%y% = Var2Par(%x%)%$$
3131
3232 $head Purpose$$
3333 Returns a
34 $cref/parameter/glossary/Parameter/$$ $icode y$$
35 with the same value as the
36 $cref/variable/glossary/Variable/$$ $icode x$$.
34 $cref/constant parameter/glossary/Parameter/Constant/$$ $icode y$$
35 with the same value as $icode x$$.
3736
3837 $head x$$
3938 The argument $icode x$$ has prototype
4039 $codei%
4140 const AD<%Base%> &x
4241 %$$
43 The argument $icode x$$ may be a variable, parameter, or dynamic parameter.
44
42 The argument $icode x$$ may be a
43 variable, dynamic parameter, or constant parameter.
4544
4645 $head y$$
4746 The result $icode y$$ has prototype
4847 $codei%
4948 AD<%Base%> &y
5049 %$$
51 The return value $icode y$$ will be a parameter.
52
50 and is a constant parameter.
5351
5452 $head Example$$
5553 $children%
00 # ifndef CPPAD_EXAMPLE_CODE_GEN_FUN_HPP
11 # define CPPAD_EXAMPLE_CODE_GEN_FUN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
1313 // BEGIN C++
1414 # include <cppad/cg/cppadcg.hpp>
1515
16 class code_gen_fun {
16 // See https://docs.microsoft.com/en-us/cpp/cpp/
17 // using-dllimport-and-dllexport-in-cpp-classes?view=msvc-160
18 // Also see define.hpp where CPPAD_LIB_EXPORTS is also defined and
19 // undef.hpp where it gets undefined.
20 # ifdef _MSC_VER
21 # ifdef cppad_lib_EXPORTS
22 # define CPPAD_LIB_EXPORT __declspec(dllexport)
23 # else
24 # define CPPAD_LIB_EXPORT __declspec(dllimport)
25 # endif // cppad_lib_EXPORTS
26 # else // _MSC_VER
27 # define CPPAD_LIB_EXPORT
28 # endif
29
30 class CPPAD_LIB_EXPORT code_gen_fun {
1731 public:
1832 // type of evaluation for Jacobians (possibly Hessians in the future)
1933 enum evaluation_enum { none_enum, dense_enum, sparse_enum };
00 # ifndef CPPAD_EXAMPLE_CPPAD_EIGEN_HPP
11 # define CPPAD_EXAMPLE_CPPAD_EIGEN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
1010 in the Eclipse Public License, Version 2.0 are satisfied:
1111 GNU General Public License, Version 2.0 or later.
1212 ---------------------------------------------------------------------------- */
13 // cppad.hpp gets included at the end
14 # define EIGEN_MATRIXBASE_PLUGIN <cppad/example/eigen_plugin.hpp>
15 # include <Eigen/Core>
1613
1714 /*
1815 $begin cppad_eigen.hpp$$
4138 sqrt
4239 exp
4340 cos
41 plugin
4442 $$
4543 $section Enable Use of Eigen Linear Algebra Package with CppAD$$
4644
6664 contain an example and test of this include file.
6765 They return true if they succeed and false otherwise.
6866
69 $head Include Files$$
70 The file $code <Eigen/Core>$$ is included before
71 these definitions and $code <cppad/cppad.hpp>$$ is included after.
72
7367 $head CppAD Declarations$$
7468 First declare some items that are defined by cppad.hpp:
7569 $srccode%cpp% */
8074 template <class Float> class numeric_limits;
8175 }
8276 /* %$$
77
78 $head std Declarations$$
79 Next declare some template specializations in std namespace:
80 $srccode%cpp% */
81 namespace std {
82 template <class Base> bool isinf(const CppAD::AD<Base> &x);
83 template <class Base> bool isfinite(const CppAD::AD<Base> &x);
84 template <class Base> bool isnan(const CppAD::AD<Base> &x);
85 }
86 /* %$$
87
88 $head Include Eigen/Core$$
89 Next define the eigen plugin and then include Eigen/Core:
90 $srccode%cpp% */
91
92 # define EIGEN_MATRIXBASE_PLUGIN <cppad/example/eigen_plugin.hpp>
93 # include <Eigen/Core>
94 /* %$$
95
8396 $head Eigen NumTraits$$
84 Eigen needs the following definitions to work properly
85 with $codei%AD<%Base%>%$$ scalars:
97 Eigen needs the following definitions, in the Eigen namespace,
98 to work properly with $codei%AD<%Base%>%$$ scalars:
8699 $srccode%cpp% */
87100 namespace Eigen {
88101 template <class Base> struct NumTraits< CppAD::AD<Base> >
133146 // number of decimal digits that can be represented without change.
134147 static int digits10(void)
135148 { return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
149
150 // not a number
151 static CppAD::AD<Base> quiet_NaN(void)
152 { return CppAD::numeric_limits< CppAD::AD<Base> >::quiet_NaN(); }
153
154 // positive infinite value
155 static CppAD::AD<Base> infinity(void)
156 { return CppAD::numeric_limits< CppAD::AD<Base> >::infinity(); }
136157 };
137158 }
138159 /* %$$
160
139161 $head CppAD Namespace$$
140 Eigen also needs the following definitions to work properly
141 with $codei%AD<%Base%>%$$ scalars:
162 Eigen needs the following definitions, in the CppAD namespace,
163 to work properly with $codei%AD<%Base%>%$$ scalars:
142164 $srccode%cpp% */
143165 namespace CppAD {
144166 // functions that return references
153175 template <class Base> AD<Base> abs2(const AD<Base>& x)
154176 { return x * x; }
155177 }
156
157 /* %$$
178 /* %$$
179
158180 $head eigen_vector$$
159181 The class $code CppAD::eigen_vector$$ is a wrapper for Eigen column vectors
160182 so that they are $cref/simple vectors/SimpleVector/$$.
186208 { base_class::resize( Eigen::Index(n) ); }
187209 };
188210 }
189 //
211 /* %$$
212
213 $head Include cppad.hpp$$
214 $srccode%cpp% */
190215 # include <cppad/cppad.hpp>
216 /* %$$
217
218 $head std Definitions$$
219 The definitions below use cppad.hpp.
220 Note that $cref Value$$ function can only be used with a
221 $cref/constant parameter/glossary/Parameter/Constant/$$ argument.
222 $srccode%cpp% */
223 namespace std {
224 template <class Base> bool isinf(const CppAD::AD<Base> &x)
225 { return isinf(CppAD::Value( CppAD::Var2Par(x) ) ); }
226
227 template <class Base> bool isfinite(const CppAD::AD<Base> &x)
228 { return isfinite(CppAD::Value( CppAD::Var2Par(x) ) ); }
229
230 template <class Base> bool isnan(const CppAD::AD<Base> &x)
231 { return isnan(CppAD::Value( CppAD::Var2Par(x) ) ); }
232 }
191233 /* %$$
192234 $end
193235 */
00 # ifndef CPPAD_IPOPT_SOLVE_CALLBACK_HPP
11 # define CPPAD_IPOPT_SOLVE_CALLBACK_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
253253 x0_.resize(nx);
254254 fg0_.resize(nfg);
255255 for(i = 0; i < nx_; i++)
256 x0_[i] = CppAD::nan(0.0);
256 x0_[i] = std::numeric_limits<double>::quiet_NaN();
257257 for(i = 0; i < nfg; i++)
258 fg0_[i] = CppAD::nan(0.0);
258 fg0_[i] = std::numeric_limits<double>::quiet_NaN();
259259
260260 if( ! retape_ )
261261 { // make adfun_ correspond to x -> [ f(x), g(x) ]
+0
-160
include/cppad/local/abs_op.hpp less more
0 # ifndef CPPAD_LOCAL_ABS_OP_HPP
1 # define CPPAD_LOCAL_ABS_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file abs_op.hpp
18 Forward and reverse mode calculations for z = fabs(x).
19 */
20
21 /*!
22 Compute forward mode Taylor coefficient for result of op = AbsOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = fabs(x)
27 \endverbatim
28
29 \copydetails CppAD::local::forward_unary1_op
30 */
31 template <class Base>
32 void forward_abs_op(
33 size_t p ,
34 size_t q ,
35 size_t i_z ,
36 size_t i_x ,
37 size_t cap_order ,
38 Base* taylor )
39 {
40 // check assumptions
41 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
42 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
43 CPPAD_ASSERT_UNKNOWN( q < cap_order );
44 CPPAD_ASSERT_UNKNOWN( p <= q );
45
46 // Taylor coefficients corresponding to argument and result
47 Base* x = taylor + i_x * cap_order;
48 Base* z = taylor + i_z * cap_order;
49
50 for(size_t j = p; j <= q; j++)
51 z[j] = sign(x[0]) * x[j];
52 }
53
54 /*!
55 Multiple directions forward mode Taylor coefficient for op = AbsOp.
56
57 The C++ source code corresponding to this operation is
58 \verbatim
59 z = fabs(x)
60 \endverbatim
61
62 \copydetails CppAD::local::forward_unary1_op_dir
63 */
64 template <class Base>
65 void forward_abs_op_dir(
66 size_t q ,
67 size_t r ,
68 size_t i_z ,
69 size_t i_x ,
70 size_t cap_order ,
71 Base* taylor )
72 {
73 // check assumptions
74 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
75 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
76 CPPAD_ASSERT_UNKNOWN( 0 < q );
77 CPPAD_ASSERT_UNKNOWN( q < cap_order );
78
79 // Taylor coefficients corresponding to argument and result
80 size_t num_taylor_per_var = (cap_order-1) * r + 1;
81 Base* x = taylor + i_x * num_taylor_per_var;
82 Base* z = taylor + i_z * num_taylor_per_var;
83
84 size_t m = (q-1) * r + 1;
85 for(size_t ell = 0; ell < r; ell++)
86 z[m + ell] = sign(x[0]) * x[m + ell];
87 }
88
89 /*!
90 Compute zero order forward mode Taylor coefficient for result of op = AbsOp.
91
92 The C++ source code corresponding to this operation is
93 \verbatim
94 z = fabs(x)
95 \endverbatim
96
97 \copydetails CppAD::local::forward_unary1_op_0
98 */
99 template <class Base>
100 void forward_abs_op_0(
101 size_t i_z ,
102 size_t i_x ,
103 size_t cap_order ,
104 Base* taylor )
105 {
106
107 // check assumptions
108 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
109 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
110 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
111
112 // Taylor coefficients corresponding to argument and result
113 Base x0 = *(taylor + i_x * cap_order);
114 Base* z = taylor + i_z * cap_order;
115
116 z[0] = fabs(x0);
117 }
118 /*!
119 Compute reverse mode partial derivatives for result of op = AbsOp.
120
121 The C++ source code corresponding to this operation is
122 \verbatim
123 z = fabs(x)
124 \endverbatim
125
126 \copydetails CppAD::local::reverse_unary1_op
127 */
128
129 template <class Base>
130 void reverse_abs_op(
131 size_t d ,
132 size_t i_z ,
133 size_t i_x ,
134 size_t cap_order ,
135 const Base* taylor ,
136 size_t nc_partial ,
137 Base* partial )
138 { size_t j;
139
140 // check assumptions
141 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
142 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
143 CPPAD_ASSERT_UNKNOWN( d < cap_order );
144 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
145
146 // Taylor coefficients and partials corresponding to argument
147 const Base* x = taylor + i_x * cap_order;
148 Base* px = partial + i_x * nc_partial;
149
150 // Taylor coefficients and partials corresponding to result
151 Base* pz = partial + i_z * nc_partial;
152
153 // do not need azmul because sign is either +1, -1, or zero
154 for(j = 0; j <= d; j++)
155 px[j] += sign(x[0]) * pz[j];
156 }
157
158 } } // END_CPPAD_LOCAL_NAMESPACE
159 # endif
+0
-263
include/cppad/local/acos_op.hpp less more
0 # ifndef CPPAD_LOCAL_ACOS_OP_HPP
1 # define CPPAD_LOCAL_ACOS_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file acos_op.hpp
18 Forward and reverse mode calculations for z = acos(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = AcosOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = acos(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = sqrt(1 - x * x)
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_acos_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* z = taylor + i_z * cap_order;
56 Base* b = z - cap_order; // called y in documentation
57
58 size_t k;
59 Base uj;
60 if( p == 0 )
61 { z[0] = acos( x[0] );
62 uj = Base(1.0) - x[0] * x[0];
63 b[0] = sqrt( uj );
64 p++;
65 }
66 for(size_t j = p; j <= q; j++)
67 { uj = Base(0.0);
68 for(k = 0; k <= j; k++)
69 uj -= x[k] * x[j-k];
70 b[j] = Base(0.0);
71 z[j] = Base(0.0);
72 for(k = 1; k < j; k++)
73 { b[j] -= Base(double(k)) * b[k] * b[j-k];
74 z[j] -= Base(double(k)) * z[k] * b[j-k];
75 }
76 b[j] /= Base(double(j));
77 z[j] /= Base(double(j));
78 //
79 b[j] += uj / Base(2.0);
80 z[j] -= x[j];
81 //
82 b[j] /= b[0];
83 z[j] /= b[0];
84 }
85 }
86 /*!
87 Multiple directions forward mode Taylor coefficient for op = AcosOp.
88
89 The C++ source code corresponding to this operation is
90 \verbatim
91 z = acos(x)
92 \endverbatim
93 The auxillary result is
94 \verbatim
95 y = sqrt(1 - x * x)
96 \endverbatim
97 The value of y, and its derivatives, are computed along with the value
98 and derivatives of z.
99
100 \copydetails CppAD::local::forward_unary2_op_dir
101 */
102 template <class Base>
103 void forward_acos_op_dir(
104 size_t q ,
105 size_t r ,
106 size_t i_z ,
107 size_t i_x ,
108 size_t cap_order ,
109 Base* taylor )
110 {
111 // check assumptions
112 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
113 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
114 CPPAD_ASSERT_UNKNOWN( 0 < q );
115 CPPAD_ASSERT_UNKNOWN( q < cap_order );
116
117 // Taylor coefficients corresponding to argument and result
118 size_t num_taylor_per_var = (cap_order-1) * r + 1;
119 Base* x = taylor + i_x * num_taylor_per_var;
120 Base* z = taylor + i_z * num_taylor_per_var;
121 Base* b = z - num_taylor_per_var; // called y in documentation
122
123 size_t k, ell;
124 size_t m = (q-1) * r + 1;
125 for(ell = 0; ell < r; ell ++)
126 { Base uq = - 2.0 * x[m + ell] * x[0];
127 for(k = 1; k < q; k++)
128 uq -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
129 b[m+ell] = Base(0.0);
130 z[m+ell] = Base(0.0);
131 for(k = 1; k < q; k++)
132 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
133 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
134 }
135 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
136 z[m+ell] = -( x[m+ell] + z[m+ell] / Base(double(q)) ) / b[0];
137 }
138 }
139
140 /*!
141 Compute zero order forward mode Taylor coefficient for result of op = AcosOp.
142
143 The C++ source code corresponding to this operation is
144 \verbatim
145 z = acos(x)
146 \endverbatim
147 The auxillary result is
148 \verbatim
149 y = sqrt( 1 - x * x )
150 \endverbatim
151 The value of y is computed along with the value of z.
152
153 \copydetails CppAD::local::forward_unary2_op_0
154 */
155 template <class Base>
156 void forward_acos_op_0(
157 size_t i_z ,
158 size_t i_x ,
159 size_t cap_order ,
160 Base* taylor )
161 {
162 // check assumptions
163 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
164 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
165 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
166
167 // Taylor coefficients corresponding to argument and result
168 Base* x = taylor + i_x * cap_order;
169 Base* z = taylor + i_z * cap_order;
170 Base* b = z - cap_order; // called y in documentation
171
172 z[0] = acos( x[0] );
173 b[0] = sqrt( Base(1.0) - x[0] * x[0] );
174 }
175 /*!
176 Compute reverse mode partial derivatives for result of op = AcosOp.
177
178 The C++ source code corresponding to this operation is
179 \verbatim
180 z = acos(x)
181 \endverbatim
182 The auxillary result is
183 \verbatim
184 y = sqrt( 1 - x * x )
185 \endverbatim
186 The value of y is computed along with the value of z.
187
188 \copydetails CppAD::local::reverse_unary2_op
189 */
190
191 template <class Base>
192 void reverse_acos_op(
193 size_t d ,
194 size_t i_z ,
195 size_t i_x ,
196 size_t cap_order ,
197 const Base* taylor ,
198 size_t nc_partial ,
199 Base* partial )
200 {
201 // check assumptions
202 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
203 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
204 CPPAD_ASSERT_UNKNOWN( d < cap_order );
205 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
206
207 // Taylor coefficients and partials corresponding to argument
208 const Base* x = taylor + i_x * cap_order;
209 Base* px = partial + i_x * nc_partial;
210
211 // Taylor coefficients and partials corresponding to first result
212 const Base* z = taylor + i_z * cap_order;
213 Base* pz = partial + i_z * nc_partial;
214
215 // Taylor coefficients and partials corresponding to auxillary result
216 const Base* b = z - cap_order; // called y in documentation
217 Base* pb = pz - nc_partial;
218
219 Base inv_b0 = Base(1.0) / b[0];
220
221 // number of indices to access
222 size_t j = d;
223 size_t k;
224 while(j)
225 {
226 // scale partials w.r.t b[j] by 1 / b[0]
227 pb[j] = azmul(pb[j], inv_b0);
228
229 // scale partials w.r.t z[j] by 1 / b[0]
230 pz[j] = azmul(pz[j], inv_b0);
231
232 // update partials w.r.t b^0
233 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
234
235 // update partial w.r.t. x^0
236 px[0] -= azmul(pb[j], x[j]);
237
238 // update partial w.r.t. x^j
239 px[j] -= pz[j] + azmul(pb[j], x[0]);
240
241 // further scale partial w.r.t. z[j] by 1 / j
242 pz[j] /= Base(double(j));
243
244 for(k = 1; k < j; k++)
245 { // update partials w.r.t b^(j-k)
246 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
247
248 // update partials w.r.t. x^k
249 px[k] -= azmul(pb[j], x[j-k]);
250
251 // update partials w.r.t. z^k
252 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
253 }
254 --j;
255 }
256
257 // j == 0 case
258 px[0] -= azmul( pz[0] + azmul(pb[0], x[0]), inv_b0);
259 }
260
261 } } // END_CPPAD_LOCAL_NAMESPACE
262 # endif
+0
-264
include/cppad/local/acosh_op.hpp less more
0 # ifndef CPPAD_LOCAL_ACOSH_OP_HPP
1 # define CPPAD_LOCAL_ACOSH_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17 /*!
18 \file acosh_op.hpp
19 Forward and reverse mode calculations for z = acosh(x).
20 */
21
22
23 /*!
24 Compute forward mode Taylor coefficient for result of op = AcoshOp.
25
26 The C++ source code corresponding to this operation is
27 \verbatim
28 z = acosh(x)
29 \endverbatim
30 The auxillary result is
31 \verbatim
32 y = sqrt(x * x - 1)
33 \endverbatim
34 The value of y, and its derivatives, are computed along with the value
35 and derivatives of z.
36
37 \copydetails CppAD::local::forward_unary2_op
38 */
39 template <class Base>
40 void forward_acosh_op(
41 size_t p ,
42 size_t q ,
43 size_t i_z ,
44 size_t i_x ,
45 size_t cap_order ,
46 Base* taylor )
47 {
48 // check assumptions
49 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
50 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
51 CPPAD_ASSERT_UNKNOWN( q < cap_order );
52 CPPAD_ASSERT_UNKNOWN( p <= q );
53
54 // Taylor coefficients corresponding to argument and result
55 Base* x = taylor + i_x * cap_order;
56 Base* z = taylor + i_z * cap_order;
57 Base* b = z - cap_order; // called y in documentation
58
59 size_t k;
60 Base uj;
61 if( p == 0 )
62 { z[0] = acosh( x[0] );
63 uj = x[0] * x[0] - Base(1.0);
64 b[0] = sqrt( uj );
65 p++;
66 }
67 for(size_t j = p; j <= q; j++)
68 { uj = Base(0.0);
69 for(k = 0; k <= j; k++)
70 uj += x[k] * x[j-k];
71 b[j] = Base(0.0);
72 z[j] = Base(0.0);
73 for(k = 1; k < j; k++)
74 { b[j] -= Base(double(k)) * b[k] * b[j-k];
75 z[j] -= Base(double(k)) * z[k] * b[j-k];
76 }
77 b[j] /= Base(double(j));
78 z[j] /= Base(double(j));
79 //
80 b[j] += uj / Base(2.0);
81 z[j] += x[j];
82 //
83 b[j] /= b[0];
84 z[j] /= b[0];
85 }
86 }
87 /*!
88 Multiple directions forward mode Taylor coefficient for op = AcoshOp.
89
90 The C++ source code corresponding to this operation is
91 \verbatim
92 z = acosh(x)
93 \endverbatim
94 The auxillary result is
95 \verbatim
96 y = sqrt(x * x - 1)
97 \endverbatim
98 The value of y, and its derivatives, are computed along with the value
99 and derivatives of z.
100
101 \copydetails CppAD::local::forward_unary2_op_dir
102 */
103 template <class Base>
104 void forward_acosh_op_dir(
105 size_t q ,
106 size_t r ,
107 size_t i_z ,
108 size_t i_x ,
109 size_t cap_order ,
110 Base* taylor )
111 {
112 // check assumptions
113 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
114 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
115 CPPAD_ASSERT_UNKNOWN( 0 < q );
116 CPPAD_ASSERT_UNKNOWN( q < cap_order );
117
118 // Taylor coefficients corresponding to argument and result
119 size_t num_taylor_per_var = (cap_order-1) * r + 1;
120 Base* x = taylor + i_x * num_taylor_per_var;
121 Base* z = taylor + i_z * num_taylor_per_var;
122 Base* b = z - num_taylor_per_var; // called y in documentation
123
124 size_t k, ell;
125 size_t m = (q-1) * r + 1;
126 for(ell = 0; ell < r; ell ++)
127 { Base uq = 2.0 * x[m + ell] * x[0];
128 for(k = 1; k < q; k++)
129 uq += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
130 b[m+ell] = Base(0.0);
131 z[m+ell] = Base(0.0);
132 for(k = 1; k < q; k++)
133 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
134 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
135 }
136 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
137 z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0];
138 }
139 }
140
141 /*!
142 Compute zero order forward mode Taylor coefficient for result of op = AcoshOp.
143
144 The C++ source code corresponding to this operation is
145 \verbatim
146 z = acosh(x)
147 \endverbatim
148 The auxillary result is
149 \verbatim
150 y = sqrt( x * x - 1 )
151 \endverbatim
152 The value of y is computed along with the value of z.
153
154 \copydetails CppAD::local::forward_unary2_op_0
155 */
156 template <class Base>
157 void forward_acosh_op_0(
158 size_t i_z ,
159 size_t i_x ,
160 size_t cap_order ,
161 Base* taylor )
162 {
163 // check assumptions
164 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
165 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
166 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
167
168 // Taylor coefficients corresponding to argument and result
169 Base* x = taylor + i_x * cap_order;
170 Base* z = taylor + i_z * cap_order;
171 Base* b = z - cap_order; // called y in documentation
172
173 z[0] = acosh( x[0] );
174 b[0] = sqrt( x[0] * x[0] - Base(1.0) );
175 }
176 /*!
177 Compute reverse mode partial derivatives for result of op = AcoshOp.
178
179 The C++ source code corresponding to this operation is
180 \verbatim
181 z = acosh(x)
182 \endverbatim
183 The auxillary result is
184 \verbatim
185 y = sqrt( x * x - 1 )
186 \endverbatim
187 The value of y is computed along with the value of z.
188
189 \copydetails CppAD::local::reverse_unary2_op
190 */
191
192 template <class Base>
193 void reverse_acosh_op(
194 size_t d ,
195 size_t i_z ,
196 size_t i_x ,
197 size_t cap_order ,
198 const Base* taylor ,
199 size_t nc_partial ,
200 Base* partial )
201 {
202 // check assumptions
203 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
204 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
205 CPPAD_ASSERT_UNKNOWN( d < cap_order );
206 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
207
208 // Taylor coefficients and partials corresponding to argument
209 const Base* x = taylor + i_x * cap_order;
210 Base* px = partial + i_x * nc_partial;
211
212 // Taylor coefficients and partials corresponding to first result
213 const Base* z = taylor + i_z * cap_order;
214 Base* pz = partial + i_z * nc_partial;
215
216 // Taylor coefficients and partials corresponding to auxillary result
217 const Base* b = z - cap_order; // called y in documentation
218 Base* pb = pz - nc_partial;
219
220 Base inv_b0 = Base(1.0) / b[0];
221
222 // number of indices to access
223 size_t j = d;
224 size_t k;
225 while(j)
226 {
227 // scale partials w.r.t b[j] by 1 / b[0]
228 pb[j] = azmul(pb[j], inv_b0);
229
230 // scale partials w.r.t z[j] by 1 / b[0]
231 pz[j] = azmul(pz[j], inv_b0);
232
233 // update partials w.r.t b^0
234 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
235
236 // update partial w.r.t. x^0
237 px[0] += azmul(pb[j], x[j]);
238
239 // update partial w.r.t. x^j
240 px[j] += pz[j] + azmul(pb[j], x[0]);
241
242 // further scale partial w.r.t. z[j] by 1 / j
243 pz[j] /= Base(double(j));
244
245 for(k = 1; k < j; k++)
246 { // update partials w.r.t b^(j-k)
247 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
248
249 // update partials w.r.t. x^k
250 px[k] += azmul(pb[j], x[j-k]);
251
252 // update partials w.r.t. z^k
253 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
254 }
255 --j;
256 }
257
258 // j == 0 case
259 px[0] += azmul(pz[0] + azmul(pb[0], x[0]), inv_b0);
260 }
261
262 } } // END_CPPAD_LOCAL_NAMESPACE
263 # endif
6464 (const AD<Base> &u);
6565 // operators -----------------------------------------------------------
6666 // arithematic binary operators
67 # if _MSC_VER
67 # if _MSC_VER && !defined(__clang__)
6868 // see https://stackoverflow.com/questions/63288453
6969 template <class Type> friend AD<Type> CppAD::operator * <Type>
7070 (const AD<Type> &left, const AD<Type> &right);
8080 (const AD<Base> &left, const AD<Base> &right);
8181
8282 // comparison operators
83 # if _MSC_VER
83 # if _MSC_VER && !defined(__clang__)
8484 template <class Type> friend bool CppAD::operator == <Type>
8585 (const AD<Type> &left, const AD<Type> &right);
8686 template <class Type> friend bool CppAD::operator != <Type>
+0
-338
include/cppad/local/add_op.hpp less more
0 # ifndef CPPAD_LOCAL_ADD_OP_HPP
1 # define CPPAD_LOCAL_ADD_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file add_op.hpp
17 Forward and reverse mode calculations for z = x + y.
18 */
19
20 // --------------------------- Addvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = AddvvOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = x + y
27 \endverbatim
28 In the documentation below,
29 this operations is for the case where both x and y are variables
30 and the argument parameter is not used.
31
32 \copydetails CppAD::local::forward_binary_op
33 */
34
35 template <class Base>
36 void forward_addvv_op(
37 size_t p ,
38 size_t q ,
39 size_t i_z ,
40 const addr_t* arg ,
41 const Base* parameter ,
42 size_t cap_order ,
43 Base* taylor )
44 {
45 // check assumptions
46 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
47 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
48 CPPAD_ASSERT_UNKNOWN( q < cap_order );
49 CPPAD_ASSERT_UNKNOWN( p <= q );
50
51 // Taylor coefficients corresponding to arguments and result
52 Base* x = taylor + size_t(arg[0]) * cap_order;
53 Base* y = taylor + size_t(arg[1]) * cap_order;
54 Base* z = taylor + i_z * cap_order;
55
56 for(size_t j = p; j <= q; j++)
57 z[j] = x[j] + y[j];
58 }
59 /*!
60 Multiple directions forward mode Taylor coefficients for op = AddvvOp.
61
62 The C++ source code corresponding to this operation is
63 \verbatim
64 z = x + y
65 \endverbatim
66 In the documentation below,
67 this operations is for the case where both x and y are variables
68 and the argument parameter is not used.
69
70 \copydetails CppAD::local::forward_binary_op_dir
71 */
72
73 template <class Base>
74 void forward_addvv_op_dir(
75 size_t q ,
76 size_t r ,
77 size_t i_z ,
78 const addr_t* arg ,
79 const Base* parameter ,
80 size_t cap_order ,
81 Base* taylor )
82 {
83 // check assumptions
84 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
85 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
86 CPPAD_ASSERT_UNKNOWN( q < cap_order );
87 CPPAD_ASSERT_UNKNOWN( 0 < q );
88
89 // Taylor coefficients corresponding to arguments and result
90 size_t num_taylor_per_var = (cap_order-1) * r + 1;
91 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
92 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
93 Base* z = taylor + i_z * num_taylor_per_var;
94
95 size_t m = (q-1)*r + 1 ;
96 for(size_t ell = 0; ell < r; ell++)
97 z[m+ell] = x[m+ell] + y[m+ell];
98 }
99
100 /*!
101 Compute zero order forward mode Taylor coefficients for result of op = AddvvOp.
102
103 The C++ source code corresponding to this operation is
104 \verbatim
105 z = x + y
106 \endverbatim
107 In the documentation below,
108 this operations is for the case where both x and y are variables
109 and the argument parameter is not used.
110
111 \copydetails CppAD::local::forward_binary_op_0
112 */
113
114 template <class Base>
115 void forward_addvv_op_0(
116 size_t i_z ,
117 const addr_t* arg ,
118 const Base* parameter ,
119 size_t cap_order ,
120 Base* taylor )
121 {
122 // check assumptions
123 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
124 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
125
126 // Taylor coefficients corresponding to arguments and result
127 Base* x = taylor + size_t(arg[0]) * cap_order;
128 Base* y = taylor + size_t(arg[1]) * cap_order;
129 Base* z = taylor + i_z * cap_order;
130
131 z[0] = x[0] + y[0];
132 }
133
134 /*!
135 Compute reverse mode partial derivatives for result of op = AddvvOp.
136
137 The C++ source code corresponding to this operation is
138 \verbatim
139 z = x + y
140 \endverbatim
141 In the documentation below,
142 this operations is for the case where both x and y are variables
143 and the argument parameter is not used.
144
145 \copydetails CppAD::local::reverse_binary_op
146 */
147
148 template <class Base>
149 void reverse_addvv_op(
150 size_t d ,
151 size_t i_z ,
152 const addr_t* arg ,
153 const Base* parameter ,
154 size_t cap_order ,
155 const Base* taylor ,
156 size_t nc_partial ,
157 Base* partial )
158 {
159 // check assumptions
160 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
161 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
162 CPPAD_ASSERT_UNKNOWN( d < cap_order );
163 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
164
165 // Partial derivatives corresponding to arguments and result
166 Base* px = partial + size_t(arg[0]) * nc_partial;
167 Base* py = partial + size_t(arg[1]) * nc_partial;
168 Base* pz = partial + i_z * nc_partial;
169
170 // number of indices to access
171 size_t i = d + 1;
172 while(i)
173 { --i;
174 px[i] += pz[i];
175 py[i] += pz[i];
176 }
177 }
178
179 // --------------------------- Addpv -----------------------------------------
180 /*!
181 Compute forward mode Taylor coefficients for result of op = AddpvOp.
182
183 The C++ source code corresponding to this operation is
184 \verbatim
185 z = x + y
186 \endverbatim
187 In the documentation below,
188 this operations is for the case where x is a parameter and y is a variable.
189
190 \copydetails CppAD::local::forward_binary_op
191 */
192 template <class Base>
193 void forward_addpv_op(
194 size_t p ,
195 size_t q ,
196 size_t i_z ,
197 const addr_t* arg ,
198 const Base* parameter ,
199 size_t cap_order ,
200 Base* taylor )
201 {
202 // check assumptions
203 CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 );
204 CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 );
205 CPPAD_ASSERT_UNKNOWN( q < cap_order );
206 CPPAD_ASSERT_UNKNOWN( p <= q );
207
208 // Taylor coefficients corresponding to arguments and result
209 Base* y = taylor + size_t(arg[1]) * cap_order;
210 Base* z = taylor + i_z * cap_order;
211
212 if( p == 0 )
213 { // Paraemter value
214 Base x = parameter[ arg[0] ];
215 z[0] = x + y[0];
216 p++;
217 }
218 for(size_t j = p; j <= q; j++)
219 z[j] = y[j];
220 }
221 /*!
222 Multiple directions forward mode Taylor coefficients for op = AddpvOp.
223
224 The C++ source code corresponding to this operation is
225 \verbatim
226 z = x + y
227 \endverbatim
228 In the documentation below,
229 this operations is for the case where x is a parameter and y is a variable.
230
231 \copydetails CppAD::local::forward_binary_op_dir
232 */
233 template <class Base>
234 void forward_addpv_op_dir(
235 size_t q ,
236 size_t r ,
237 size_t i_z ,
238 const addr_t* arg ,
239 const Base* parameter ,
240 size_t cap_order ,
241 Base* taylor )
242 {
243 // check assumptions
244 CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 );
245 CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 );
246 CPPAD_ASSERT_UNKNOWN( 0 < q );
247 CPPAD_ASSERT_UNKNOWN( q < cap_order );
248
249 // Taylor coefficients corresponding to arguments and result
250 size_t num_taylor_per_var = (cap_order-1) * r + 1;
251 size_t m = (q-1) * r + 1;
252 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
253 Base* z = taylor + i_z * num_taylor_per_var + m;
254
255 for(size_t ell = 0; ell < r; ell++)
256 z[ell] = y[ell];
257 }
258 /*!
259 Compute zero order forward mode Taylor coefficient for result of op = AddpvOp.
260
261 The C++ source code corresponding to this operation is
262 \verbatim
263 z = x + y
264 \endverbatim
265 In the documentation below,
266 this operations is for the case where x is a parameter and y is a variable.
267
268 \copydetails CppAD::local::forward_binary_op_0
269 */
270
271 template <class Base>
272 void forward_addpv_op_0(
273 size_t i_z ,
274 const addr_t* arg ,
275 const Base* parameter ,
276 size_t cap_order ,
277 Base* taylor )
278 {
279 // check assumptions
280 CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 );
281 CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 );
282
283 // Paraemter value
284 Base x = parameter[ arg[0] ];
285
286 // Taylor coefficients corresponding to arguments and result
287 Base* y = taylor + size_t(arg[1]) * cap_order;
288 Base* z = taylor + i_z * cap_order;
289
290 z[0] = x + y[0];
291 }
292
293 /*!
294 Compute reverse mode partial derivative for result of op = AddpvOp.
295
296 The C++ source code corresponding to this operation is
297 \verbatim
298 z = x + y
299 \endverbatim
300 In the documentation below,
301 this operations is for the case where x is a parameter and y is a variable.
302
303 \copydetails CppAD::local::reverse_binary_op
304 */
305
306 template <class Base>
307 void reverse_addpv_op(
308 size_t d ,
309 size_t i_z ,
310 const addr_t* arg ,
311 const Base* parameter ,
312 size_t cap_order ,
313 const Base* taylor ,
314 size_t nc_partial ,
315 Base* partial )
316 {
317 // check assumptions
318 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
319 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
320 CPPAD_ASSERT_UNKNOWN( d < cap_order );
321 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
322
323 // Partial derivatives corresponding to arguments and result
324 Base* py = partial + size_t(arg[1]) * nc_partial;
325 Base* pz = partial + i_z * nc_partial;
326
327 // number of indices to access
328 size_t i = d + 1;
329 while(i)
330 { --i;
331 py[i] += pz[i];
332 }
333 }
334
335
336 } } // END_CPPAD_LOCAL_NAMESPACE
337 # endif
+0
-263
include/cppad/local/asin_op.hpp less more
0 # ifndef CPPAD_LOCAL_ASIN_OP_HPP
1 # define CPPAD_LOCAL_ASIN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file asin_op.hpp
18 Forward and reverse mode calculations for z = asin(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = AsinOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = asin(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = sqrt(1 - x * x)
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_asin_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* z = taylor + i_z * cap_order;
56 Base* b = z - cap_order; // called y in documentation
57
58 size_t k;
59 Base uj;
60 if( p == 0 )
61 { z[0] = asin( x[0] );
62 uj = Base(1.0) - x[0] * x[0];
63 b[0] = sqrt( uj );
64 p++;
65 }
66 for(size_t j = p; j <= q; j++)
67 { uj = Base(0.0);
68 for(k = 0; k <= j; k++)
69 uj -= x[k] * x[j-k];
70 b[j] = Base(0.0);
71 z[j] = Base(0.0);
72 for(k = 1; k < j; k++)
73 { b[j] -= Base(double(k)) * b[k] * b[j-k];
74 z[j] -= Base(double(k)) * z[k] * b[j-k];
75 }
76 b[j] /= Base(double(j));
77 z[j] /= Base(double(j));
78 //
79 b[j] += uj / Base(2.0);
80 z[j] += x[j];
81 //
82 b[j] /= b[0];
83 z[j] /= b[0];
84 }
85 }
86 /*!
87 Multiple directions forward mode Taylor coefficient for op = AsinOp.
88
89 The C++ source code corresponding to this operation is
90 \verbatim
91 z = asin(x)
92 \endverbatim
93 The auxillary result is
94 \verbatim
95 y = sqrt(1 - x * x)
96 \endverbatim
97 The value of y, and its derivatives, are computed along with the value
98 and derivatives of z.
99
100 \copydetails CppAD::local::forward_unary2_op_dir
101 */
102 template <class Base>
103 void forward_asin_op_dir(
104 size_t q ,
105 size_t r ,
106 size_t i_z ,
107 size_t i_x ,
108 size_t cap_order ,
109 Base* taylor )
110 {
111 // check assumptions
112 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
113 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
114 CPPAD_ASSERT_UNKNOWN( 0 < q );
115 CPPAD_ASSERT_UNKNOWN( q < cap_order );
116
117 // Taylor coefficients corresponding to argument and result
118 size_t num_taylor_per_var = (cap_order-1) * r + 1;
119 Base* x = taylor + i_x * num_taylor_per_var;
120 Base* z = taylor + i_z * num_taylor_per_var;
121 Base* b = z - num_taylor_per_var; // called y in documentation
122
123 size_t k, ell;
124 size_t m = (q-1) * r + 1;
125 for(ell = 0; ell < r; ell ++)
126 { Base uq = - 2.0 * x[m + ell] * x[0];
127 for(k = 1; k < q; k++)
128 uq -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
129 b[m+ell] = Base(0.0);
130 z[m+ell] = Base(0.0);
131 for(k = 1; k < q; k++)
132 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
133 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
134 }
135 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
136 z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0];
137 }
138 }
139
140 /*!
141 Compute zero order forward mode Taylor coefficient for result of op = AsinOp.
142
143 The C++ source code corresponding to this operation is
144 \verbatim
145 z = asin(x)
146 \endverbatim
147 The auxillary result is
148 \verbatim
149 y = sqrt( 1 - x * x )
150 \endverbatim
151 The value of y is computed along with the value of z.
152
153 \copydetails CppAD::local::forward_unary2_op_0
154 */
155 template <class Base>
156 void forward_asin_op_0(
157 size_t i_z ,
158 size_t i_x ,
159 size_t cap_order ,
160 Base* taylor )
161 {
162 // check assumptions
163 CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
164 CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
165 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
166
167 // Taylor coefficients corresponding to argument and result
168 Base* x = taylor + i_x * cap_order;
169 Base* z = taylor + i_z * cap_order;
170 Base* b = z - cap_order; // called y in documentation
171
172 z[0] = asin( x[0] );
173 b[0] = sqrt( Base(1.0) - x[0] * x[0] );
174 }
175 /*!
176 Compute reverse mode partial derivatives for result of op = AsinOp.
177
178 The C++ source code corresponding to this operation is
179 \verbatim
180 z = asin(x)
181 \endverbatim
182 The auxillary result is
183 \verbatim
184 y = sqrt( 1 - x * x )
185 \endverbatim
186 The value of y is computed along with the value of z.
187
188 \copydetails CppAD::local::reverse_unary2_op
189 */
190
191 template <class Base>
192 void reverse_asin_op(
193 size_t d ,
194 size_t i_z ,
195 size_t i_x ,
196 size_t cap_order ,
197 const Base* taylor ,
198 size_t nc_partial ,
199 Base* partial )
200 {
201 // check assumptions
202 CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
203 CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
204 CPPAD_ASSERT_UNKNOWN( d < cap_order );
205 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
206
207 // Taylor coefficients and partials corresponding to argument
208 const Base* x = taylor + i_x * cap_order;
209 Base* px = partial + i_x * nc_partial;
210
211 // Taylor coefficients and partials corresponding to first result
212 const Base* z = taylor + i_z * cap_order;
213 Base* pz = partial + i_z * nc_partial;
214
215 // Taylor coefficients and partials corresponding to auxillary result
216 const Base* b = z - cap_order; // called y in documentation
217 Base* pb = pz - nc_partial;
218
219 Base inv_b0 = Base(1.0) / b[0];
220
221 // number of indices to access
222 size_t j = d;
223 size_t k;
224 while(j)
225 {
226 // scale partials w.r.t b[j] by 1 / b[0]
227 pb[j] = azmul(pb[j], inv_b0);
228
229 // scale partials w.r.t z[j] by 1 / b[0]
230 pz[j] = azmul(pz[j], inv_b0);
231
232 // update partials w.r.t b^0
233 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
234
235 // update partial w.r.t. x^0
236 px[0] -= azmul(pb[j], x[j]);
237
238 // update partial w.r.t. x^j
239 px[j] += pz[j] - azmul(pb[j], x[0]);
240
241 // further scale partial w.r.t. z[j] by 1 / j
242 pz[j] /= Base(double(j));
243
244 for(k = 1; k < j; k++)
245 { // update partials w.r.t b^(j-k)
246 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
247
248 // update partials w.r.t. x^k
249 px[k] -= azmul(pb[j], x[j-k]);
250
251 // update partials w.r.t. z^k
252 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
253 }
254 --j;
255 }
256
257 // j == 0 case
258 px[0] += azmul(pz[0] - azmul(pb[0], x[0]), inv_b0);
259 }
260
261 } } // END_CPPAD_LOCAL_NAMESPACE
262 # endif
+0
-264
include/cppad/local/asinh_op.hpp less more
0 # ifndef CPPAD_LOCAL_ASINH_OP_HPP
1 # define CPPAD_LOCAL_ASINH_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17 /*!
18 \file asinh_op.hpp
19 Forward and reverse mode calculations for z = asinh(x).
20 */
21
22
23 /*!
24 Compute forward mode Taylor coefficient for result of op = AsinhOp.
25
26 The C++ source code corresponding to this operation is
27 \verbatim
28 z = asinh(x)
29 \endverbatim
30 The auxillary result is
31 \verbatim
32 y = sqrt(1 + x * x)
33 \endverbatim
34 The value of y, and its derivatives, are computed along with the value
35 and derivatives of z.
36
37 \copydetails CppAD::local::forward_unary2_op
38 */
39 template <class Base>
40 void forward_asinh_op(
41 size_t p ,
42 size_t q ,
43 size_t i_z ,
44 size_t i_x ,
45 size_t cap_order ,
46 Base* taylor )
47 {
48 // check assumptions
49 CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 );
50 CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 );
51 CPPAD_ASSERT_UNKNOWN( q < cap_order );
52 CPPAD_ASSERT_UNKNOWN( p <= q );
53
54 // Taylor coefficients corresponding to argument and result
55 Base* x = taylor + i_x * cap_order;
56 Base* z = taylor + i_z * cap_order;
57 Base* b = z - cap_order; // called y in documentation
58
59 size_t k;
60 Base uj;
61 if( p == 0 )
62 { z[0] = asinh( x[0] );
63 uj = Base(1.0) + x[0] * x[0];
64 b[0] = sqrt( uj );
65 p++;
66 }
67 for(size_t j = p; j <= q; j++)
68 { uj = Base(0.0);
69 for(k = 0; k <= j; k++)
70 uj += x[k] * x[j-k];
71 b[j] = Base(0.0);
72 z[j] = Base(0.0);
73 for(k = 1; k < j; k++)
74 { b[j] -= Base(double(k)) * b[k] * b[j-k];
75 z[j] -= Base(double(k)) * z[k] * b[j-k];
76 }
77 b[j] /= Base(double(j));
78 z[j] /= Base(double(j));
79 //
80 b[j] += uj / Base(2.0);
81 z[j] += x[j];
82 //
83 b[j] /= b[0];
84 z[j] /= b[0];
85 }
86 }
87 /*!
88 Multiple directions forward mode Taylor coefficient for op = AsinhOp.
89
90 The C++ source code corresponding to this operation is
91 \verbatim
92 z = asinh(x)
93 \endverbatim
94 The auxillary result is
95 \verbatim
96 y = sqrt(1 + x * x)
97 \endverbatim
98 The value of y, and its derivatives, are computed along with the value
99 and derivatives of z.
100
101 \copydetails CppAD::local::forward_unary2_op_dir
102 */
103 template <class Base>
104 void forward_asinh_op_dir(
105 size_t q ,
106 size_t r ,
107 size_t i_z ,
108 size_t i_x ,
109 size_t cap_order ,
110 Base* taylor )
111 {
112 // check assumptions
113 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
114 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
115 CPPAD_ASSERT_UNKNOWN( 0 < q );
116 CPPAD_ASSERT_UNKNOWN( q < cap_order );
117
118 // Taylor coefficients corresponding to argument and result
119 size_t num_taylor_per_var = (cap_order-1) * r + 1;
120 Base* x = taylor + i_x * num_taylor_per_var;
121 Base* z = taylor + i_z * num_taylor_per_var;
122 Base* b = z - num_taylor_per_var; // called y in documentation
123
124 size_t k, ell;
125 size_t m = (q-1) * r + 1;
126 for(ell = 0; ell < r; ell ++)
127 { Base uq = 2.0 * x[m + ell] * x[0];
128 for(k = 1; k < q; k++)
129 uq += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
130 b[m+ell] = Base(0.0);
131 z[m+ell] = Base(0.0);
132 for(k = 1; k < q; k++)
133 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
134 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
135 }
136 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
137 z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0];
138 }
139 }
140
141 /*!
142 Compute zero order forward mode Taylor coefficient for result of op = AsinhOp.
143
144 The C++ source code corresponding to this operation is
145 \verbatim
146 z = asinh(x)
147 \endverbatim
148 The auxillary result is
149 \verbatim
150 y = sqrt( 1 + x * x )
151 \endverbatim
152 The value of y is computed along with the value of z.
153
154 \copydetails CppAD::local::forward_unary2_op_0
155 */
156 template <class Base>
157 void forward_asinh_op_0(
158 size_t i_z ,
159 size_t i_x ,
160 size_t cap_order ,
161 Base* taylor )
162 {
163 // check assumptions
164 CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 );
165 CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 );
166 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
167
168 // Taylor coefficients corresponding to argument and result
169 Base* x = taylor + i_x * cap_order;
170 Base* z = taylor + i_z * cap_order;
171 Base* b = z - cap_order; // called y in documentation
172
173 z[0] = asinh( x[0] );
174 b[0] = sqrt( Base(1.0) + x[0] * x[0] );
175 }
176 /*!
177 Compute reverse mode partial derivatives for result of op = AsinhOp.
178
179 The C++ source code corresponding to this operation is
180 \verbatim
181 z = asinh(x)
182 \endverbatim
183 The auxillary result is
184 \verbatim
185 y = sqrt( 1 + x * x )
186 \endverbatim
187 The value of y is computed along with the value of z.
188
189 \copydetails CppAD::local::reverse_unary2_op
190 */
191
192 template <class Base>
193 void reverse_asinh_op(
194 size_t d ,
195 size_t i_z ,
196 size_t i_x ,
197 size_t cap_order ,
198 const Base* taylor ,
199 size_t nc_partial ,
200 Base* partial )
201 {
202 // check assumptions
203 CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 );
204 CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 );
205 CPPAD_ASSERT_UNKNOWN( d < cap_order );
206 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
207
208 // Taylor coefficients and partials corresponding to argument
209 const Base* x = taylor + i_x * cap_order;
210 Base* px = partial + i_x * nc_partial;
211
212 // Taylor coefficients and partials corresponding to first result
213 const Base* z = taylor + i_z * cap_order;
214 Base* pz = partial + i_z * nc_partial;
215
216 // Taylor coefficients and partials corresponding to auxillary result
217 const Base* b = z - cap_order; // called y in documentation
218 Base* pb = pz - nc_partial;
219
220 Base inv_b0 = Base(1.0) / b[0];
221
222 // number of indices to access
223 size_t j = d;
224 size_t k;
225 while(j)
226 {
227 // scale partials w.r.t b[j] by 1 / b[0]
228 pb[j] = azmul(pb[j], inv_b0);
229
230 // scale partials w.r.t z[j] by 1 / b[0]
231 pz[j] = azmul(pz[j], inv_b0);
232
233 // update partials w.r.t b^0
234 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
235
236 // update partial w.r.t. x^0
237 px[0] += azmul(pb[j], x[j]);
238
239 // update partial w.r.t. x^j
240 px[j] += pz[j] + azmul(pb[j], x[0]);
241
242 // further scale partial w.r.t. z[j] by 1 / j
243 pz[j] /= Base(double(j));
244
245 for(k = 1; k < j; k++)
246 { // update partials w.r.t b^(j-k)
247 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
248
249 // update partials w.r.t. x^k
250 px[k] += azmul(pb[j], x[j-k]);
251
252 // update partials w.r.t. z^k
253 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
254 }
255 --j;
256 }
257
258 // j == 0 case
259 px[0] += azmul(pz[0] + azmul(pb[0], x[0]), inv_b0);
260 }
261
262 } } // END_CPPAD_LOCAL_NAMESPACE
263 # endif
+0
-235
include/cppad/local/atan_op.hpp less more
0 # ifndef CPPAD_LOCAL_ATAN_OP_HPP
1 # define CPPAD_LOCAL_ATAN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file atan_op.hpp
18 Forward and reverse mode calculations for z = atan(x).
19 */
20
21
22 /*!
23 Forward mode Taylor coefficient for result of op = AtanOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = atan(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = 1 + x * x
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_atan_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* z = taylor + i_z * cap_order;
56 Base* b = z - cap_order; // called y in documentation
57
58 size_t k;
59 if( p == 0 )
60 { z[0] = atan( x[0] );
61 b[0] = Base(1.0) + x[0] * x[0];
62 p++;
63 }
64 for(size_t j = p; j <= q; j++)
65 {
66 b[j] = Base(2.0) * x[0] * x[j];
67 z[j] = Base(0.0);
68 for(k = 1; k < j; k++)
69 { b[j] += x[k] * x[j-k];
70 z[j] -= Base(double(k)) * z[k] * b[j-k];
71 }
72 z[j] /= Base(double(j));
73 z[j] += x[j];
74 z[j] /= b[0];
75 }
76 }
77
78 /*!
79 Multiple direction Taylor coefficient for op = AtanOp.
80
81 The C++ source code corresponding to this operation is
82 \verbatim
83 z = atan(x)
84 \endverbatim
85 The auxillary result is
86 \verbatim
87 y = 1 + x * x
88 \endverbatim
89 The value of y, and its derivatives, are computed along with the value
90 and derivatives of z.
91
92 \copydetails CppAD::local::forward_unary2_op_dir
93 */
94 template <class Base>
95 void forward_atan_op_dir(
96 size_t q ,
97 size_t r ,
98 size_t i_z ,
99 size_t i_x ,
100 size_t cap_order ,
101 Base* taylor )
102 {
103 // check assumptions
104 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
105 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
106 CPPAD_ASSERT_UNKNOWN( 0 < q );
107 CPPAD_ASSERT_UNKNOWN( q < cap_order );
108
109 // Taylor coefficients corresponding to argument and result
110 size_t num_taylor_per_var = (cap_order-1) * r + 1;
111 Base* x = taylor + i_x * num_taylor_per_var;
112 Base* z = taylor + i_z * num_taylor_per_var;
113 Base* b = z - num_taylor_per_var; // called y in documentation
114
115 size_t m = (q-1) * r + 1;
116 for(size_t ell = 0; ell < r; ell++)
117 { b[m+ell] = Base(2.0) * x[m+ell] * x[0];
118 z[m+ell] = Base(double(q)) * x[m+ell];
119 for(size_t k = 1; k < q; k++)
120 { b[m+ell] += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
121 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
122 }
123 z[m+ell] /= ( Base(double(q)) * b[0] );
124 }
125 }
126
127 /*!
128 Zero order forward mode Taylor coefficient for result of op = AtanOp.
129
130 The C++ source code corresponding to this operation is
131 \verbatim
132 z = atan(x)
133 \endverbatim
134 The auxillary result is
135 \verbatim
136 y = 1 + x * x
137 \endverbatim
138 The value of y is computed along with the value of z.
139
140 \copydetails CppAD::local::forward_unary2_op_0
141 */
142 template <class Base>
143 void forward_atan_op_0(
144 size_t i_z ,
145 size_t i_x ,
146 size_t cap_order ,
147 Base* taylor )
148 {
149 // check assumptions
150 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
151 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
152 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
153
154 // Taylor coefficients corresponding to argument and result
155 Base* x = taylor + i_x * cap_order;
156 Base* z = taylor + i_z * cap_order;
157 Base* b = z - cap_order; // called y in documentation
158
159 z[0] = atan( x[0] );
160 b[0] = Base(1.0) + x[0] * x[0];
161 }
162 /*!
163 Reverse mode partial derivatives for result of op = AtanOp.
164
165 The C++ source code corresponding to this operation is
166 \verbatim
167 z = atan(x)
168 \endverbatim
169 The auxillary result is
170 \verbatim
171 y = 1 + x * x
172 \endverbatim
173 The value of y is computed along with the value of z.
174
175 \copydetails CppAD::local::reverse_unary2_op
176 */
177
178 template <class Base>
179 void reverse_atan_op(
180 size_t d ,
181 size_t i_z ,
182 size_t i_x ,
183 size_t cap_order ,
184 const Base* taylor ,
185 size_t nc_partial ,
186 Base* partial )
187 {
188 // check assumptions
189 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
190 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
191 CPPAD_ASSERT_UNKNOWN( d < cap_order );
192 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
193
194 // Taylor coefficients and partials corresponding to argument
195 const Base* x = taylor + i_x * cap_order;
196 Base* px = partial + i_x * nc_partial;
197
198 // Taylor coefficients and partials corresponding to first result
199 const Base* z = taylor + i_z * cap_order;
200 Base* pz = partial + i_z * nc_partial;
201
202 // Taylor coefficients and partials corresponding to auxillary result
203 const Base* b = z - cap_order; // called y in documentation
204 Base* pb = pz - nc_partial;
205
206 Base inv_b0 = Base(1.0) / b[0];
207
208 // number of indices to access
209 size_t j = d;
210 size_t k;
211 while(j)
212 { // scale partials w.r.t z[j] and b[j]
213 pz[j] = azmul(pz[j], inv_b0);
214 pb[j] *= Base(2.0);
215
216 pb[0] -= azmul(pz[j], z[j]);
217 px[j] += pz[j] + azmul(pb[j], x[0]);
218 px[0] += azmul(pb[j], x[j]);
219
220 // more scaling of partials w.r.t z[j]
221 pz[j] /= Base(double(j));
222
223 for(k = 1; k < j; k++)
224 { pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
225 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
226 px[k] += azmul(pb[j], x[j-k]);
227 }
228 --j;
229 }
230 px[0] += azmul(pz[0], inv_b0) + Base(2.0) * azmul(pb[0], x[0]);
231 }
232
233 } } // END_CPPAD_LOCAL_NAMESPACE
234 # endif
+0
-236
include/cppad/local/atanh_op.hpp less more
0 # ifndef CPPAD_LOCAL_ATANH_OP_HPP
1 # define CPPAD_LOCAL_ATANH_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17 /*!
18 \file atanh_op.hpp
19 Forward and reverse mode calculations for z = atanh(x).
20 */
21
22
23 /*!
24 Forward mode Taylor coefficient for result of op = AtanhOp.
25
26 The C++ source code corresponding to this operation is
27 \verbatim
28 z = atanh(x)
29 \endverbatim
30 The auxillary result is
31 \verbatim
32 y = 1 - x * x
33 \endverbatim
34 The value of y, and its derivatives, are computed along with the value
35 and derivatives of z.
36
37 \copydetails CppAD::local::forward_unary2_op
38 */
39 template <class Base>
40 void forward_atanh_op(
41 size_t p ,
42 size_t q ,
43 size_t i_z ,
44 size_t i_x ,
45 size_t cap_order ,
46 Base* taylor )
47 {
48 // check assumptions
49 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
50 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
51 CPPAD_ASSERT_UNKNOWN( q < cap_order );
52 CPPAD_ASSERT_UNKNOWN( p <= q );
53
54 // Taylor coefficients corresponding to argument and result
55 Base* x = taylor + i_x * cap_order;
56 Base* z = taylor + i_z * cap_order;
57 Base* b = z - cap_order; // called y in documentation
58
59 size_t k;
60 if( p == 0 )
61 { z[0] = atanh( x[0] );
62 b[0] = Base(1.0) - x[0] * x[0];
63 p++;
64 }
65 for(size_t j = p; j <= q; j++)
66 {
67 b[j] = - Base(2.0) * x[0] * x[j];
68 z[j] = Base(0.0);
69 for(k = 1; k < j; k++)
70 { b[j] -= x[k] * x[j-k];
71 z[j] -= Base(double(k)) * z[k] * b[j-k];
72 }
73 z[j] /= Base(double(j));
74 z[j] += x[j];
75 z[j] /= b[0];
76 }
77 }
78
79 /*!
80 Multiple direction Taylor coefficient for op = AtanhOp.
81
82 The C++ source code corresponding to this operation is
83 \verbatim
84 z = atanh(x)
85 \endverbatim
86 The auxillary result is
87 \verbatim
88 y = 1 - x * x
89 \endverbatim
90 The value of y, and its derivatives, are computed along with the value
91 and derivatives of z.
92
93 \copydetails CppAD::local::forward_unary2_op_dir
94 */
95 template <class Base>
96 void forward_atanh_op_dir(
97 size_t q ,
98 size_t r ,
99 size_t i_z ,
100 size_t i_x ,
101 size_t cap_order ,
102 Base* taylor )
103 {
104 // check assumptions
105 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
106 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
107 CPPAD_ASSERT_UNKNOWN( 0 < q );
108 CPPAD_ASSERT_UNKNOWN( q < cap_order );
109
110 // Taylor coefficients corresponding to argument and result
111 size_t num_taylor_per_var = (cap_order-1) * r + 1;
112 Base* x = taylor + i_x * num_taylor_per_var;
113 Base* z = taylor + i_z * num_taylor_per_var;
114 Base* b = z - num_taylor_per_var; // called y in documentation
115
116 size_t m = (q-1) * r + 1;
117 for(size_t ell = 0; ell < r; ell++)
118 { b[m+ell] = - Base(2.0) * x[m+ell] * x[0];
119 z[m+ell] = Base(double(q)) * x[m+ell];
120 for(size_t k = 1; k < q; k++)
121 { b[m+ell] -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
122 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
123 }
124 z[m+ell] /= ( Base(double(q)) * b[0] );
125 }
126 }
127
128 /*!
129 Zero order forward mode Taylor coefficient for result of op = AtanhOp.
130
131 The C++ source code corresponding to this operation is
132 \verbatim
133 z = atanh(x)
134 \endverbatim
135 The auxillary result is
136 \verbatim
137 y = 1 - x * x
138 \endverbatim
139 The value of y is computed along with the value of z.
140
141 \copydetails CppAD::local::forward_unary2_op_0
142 */
143 template <class Base>
144 void forward_atanh_op_0(
145 size_t i_z ,
146 size_t i_x ,
147 size_t cap_order ,
148 Base* taylor )
149 {
150 // check assumptions
151 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
152 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
153 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
154
155 // Taylor coefficients corresponding to argument and result
156 Base* x = taylor + i_x * cap_order;
157 Base* z = taylor + i_z * cap_order;
158 Base* b = z - cap_order; // called y in documentation
159
160 z[0] = atanh( x[0] );
161 b[0] = Base(1.0) - x[0] * x[0];
162 }
163 /*!
164 Reverse mode partial derivatives for result of op = AtanhOp.
165
166 The C++ source code corresponding to this operation is
167 \verbatim
168 z = atanh(x)
169 \endverbatim
170 The auxillary result is
171 \verbatim
172 y = 1 - x * x
173 \endverbatim
174 The value of y is computed along with the value of z.
175
176 \copydetails CppAD::local::reverse_unary2_op
177 */
178
179 template <class Base>
180 void reverse_atanh_op(
181 size_t d ,
182 size_t i_z ,
183 size_t i_x ,
184 size_t cap_order ,
185 const Base* taylor ,
186 size_t nc_partial ,
187 Base* partial )
188 {
189 // check assumptions
190 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
191 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
192 CPPAD_ASSERT_UNKNOWN( d < cap_order );
193 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
194
195 // Taylor coefficients and partials corresponding to argument
196 const Base* x = taylor + i_x * cap_order;
197 Base* px = partial + i_x * nc_partial;
198
199 // Taylor coefficients and partials corresponding to first result
200 const Base* z = taylor + i_z * cap_order;
201 Base* pz = partial + i_z * nc_partial;
202
203 // Taylor coefficients and partials corresponding to auxillary result
204 const Base* b = z - cap_order; // called y in documentation
205 Base* pb = pz - nc_partial;
206
207 Base inv_b0 = Base(1.0) / b[0];
208
209 // number of indices to access
210 size_t j = d;
211 size_t k;
212 while(j)
213 { // scale partials w.r.t z[j] and b[j]
214 pz[j] = azmul(pz[j], inv_b0);
215 pb[j] *= Base(2.0);
216
217 pb[0] -= azmul(pz[j], z[j]);
218 px[j] += pz[j] - azmul(pb[j], x[0]);
219 px[0] -= azmul(pb[j], x[j]);
220
221 // more scaling of partials w.r.t z[j]
222 pz[j] /= Base(double(j));
223
224 for(k = 1; k < j; k++)
225 { pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
226 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
227 px[k] -= azmul(pb[j], x[j-k]);
228 }
229 --j;
230 }
231 px[0] += azmul(pz[0], inv_b0) - Base(2.0) * azmul(pb[0], x[0]);
232 }
233
234 } } // END_CPPAD_LOCAL_NAMESPACE
235 # endif
+0
-420
include/cppad/local/comp_op.hpp less more
0 # ifndef CPPAD_LOCAL_COMP_OP_HPP
1 # define CPPAD_LOCAL_COMP_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file comp_op.hpp
18 Zero order forward mode check how many comparisons changed.
19 */
20
21 // -------------------------------- <= -----------------------------------
22 /*!
23 Zero order forward mode comparison check that left <= right
24
25 \param count
26 It the condition is not true, ths counter is incremented by one.
27
28 \param arg
29 parameter[ arg[0] ] is the left operand and
30 parameter[ arg[1] ] is the right operand.
31
32 \param parameter
33 vector of parameter values.
34 */
35 template <class Base>
36 void forward_lepp_op_0(
37 size_t& count ,
38 const addr_t* arg ,
39 const Base* parameter )
40 {
41 // check assumptions
42 CPPAD_ASSERT_UNKNOWN( NumArg(LeppOp) == 2 );
43 CPPAD_ASSERT_UNKNOWN( NumRes(LeppOp) == 0 );
44
45 // Taylor coefficients corresponding to arguments and result
46 Base x = parameter[ arg[0] ];
47 Base y = parameter[ arg[1] ];
48
49 count += size_t( GreaterThanZero(x - y) );
50 }
51 /*!
52 Zero order forward mode comparison check that left <= right
53
54 \param count
55 It the condition is not true, ths counter is incremented by one.
56
57 \param arg
58 parameter[ arg[0] ] is the left operand and
59 taylor[ size_t(arg[1]) * cap_order + 0 ] is the zero order Taylor coefficient
60 for the right operand.
61
62 \param parameter
63 vector of parameter values.
64
65 \param cap_order
66 number of Taylor coefficients allocated for each variable
67
68 \param taylor
69 vector of taylor coefficients.
70 */
71 template <class Base>
72 void forward_lepv_op_0(
73 size_t& count ,
74 const addr_t* arg ,
75 const Base* parameter ,
76 size_t cap_order ,
77 Base* taylor )
78 {
79 // check assumptions
80 CPPAD_ASSERT_UNKNOWN( NumArg(LepvOp) == 2 );
81 CPPAD_ASSERT_UNKNOWN( NumRes(LepvOp) == 0 );
82
83 // Taylor coefficients corresponding to arguments and result
84 Base x = parameter[ arg[0] ];
85 Base* y = taylor + size_t(arg[1]) * cap_order;
86
87 count += GreaterThanZero(x - y[0]);
88 }
89 /*!
90 Zero order forward mode comparison check that left <= right
91
92 \param count
93 It the condition is not true, ths counter is incremented by one.
94
95 \param arg
96 taylor[ size_t(arg[0]) * cap_order + 0 ] is the zero order Taylor coefficient
97 for the left operand and parameter[ arg[1] ] is the right operand
98
99 \param parameter
100 vector of parameter values.
101
102 \param cap_order
103 number of Taylor coefficients allocated for each variable
104
105 \param taylor
106 vector of taylor coefficients.
107 */
108 template <class Base>
109 void forward_levp_op_0(
110 size_t& count ,
111 const addr_t* arg ,
112 const Base* parameter ,
113 size_t cap_order ,
114 Base* taylor )
115 {
116 // check assumptions
117 CPPAD_ASSERT_UNKNOWN( NumArg(LevpOp) == 2 );
118 CPPAD_ASSERT_UNKNOWN( NumRes(LevpOp) == 0 );
119
120 // Taylor coefficients corresponding to arguments and result
121 Base* x = taylor + size_t(arg[0]) * cap_order;
122 Base y = parameter[ arg[1] ];
123
124 count += GreaterThanZero(x[0] - y);
125 }
126 /*!
127 Zero order forward mode comparison check that left <= right
128
129 \param count
130 It the condition is not true, ths counter is incremented by one.
131
132 \param arg
133 taylor[ size_t(arg[0]) * cap_order + 0 ] is the zero order Taylor coefficient
134 for the left operand and
135 taylor[ size_t(arg[1]) * cap_order + 0 ] is the zero order Taylor coefficient
136 for the right operand.
137
138 \param parameter
139 vector of parameter values.
140
141 \param cap_order
142 number of Taylor coefficients allocated for each variable
143
144 \param taylor
145 vector of taylor coefficients.
146 */
147 template <class Base>
148 void forward_levv_op_0(
149 size_t& count ,
150 const addr_t* arg ,
151 const Base* parameter ,
152 size_t cap_order ,
153 Base* taylor )
154 {
155 // check assumptions
156 CPPAD_ASSERT_UNKNOWN( NumArg(LevvOp) == 2 );
157 CPPAD_ASSERT_UNKNOWN( NumRes(LevvOp) == 0 );
158
159 // Taylor coefficients corresponding to arguments and result
160 Base* x = taylor + size_t(arg[0]) * cap_order;
161 Base* y = taylor + size_t(arg[1]) * cap_order;
162
163 count += GreaterThanZero(x[0] - y[0]);
164 }
165 // ------------------------------- < -------------------------------------
166 /*!
167 Zero order forward mode comparison check that left < right
168
169 \param count
170 It the condition is not true, ths counter is incremented by one.
171
172 \param arg
173 parameter[ arg[0] ] is the left operand and
174 parameter[ arg[1] ] is the right operand.
175
176 \param parameter
177 vector of parameter values.
178 */
179 template <class Base>
180 void forward_ltpp_op_0(
181 size_t& count ,
182 const addr_t* arg ,
183 const Base* parameter )
184 {
185 // check assumptions
186 CPPAD_ASSERT_UNKNOWN( NumArg(LtppOp) == 2 );
187 CPPAD_ASSERT_UNKNOWN( NumRes(LtppOp) == 0 );
188
189 // Taylor coefficients corresponding to arguments and result
190 Base x = parameter[ arg[0] ];
191 Base y = parameter[ arg[1] ];
192
193 count += GreaterThanOrZero(x - y);
194 }
195 /*!
196 Zero order forward mode comparison check that left < right
197
198 \copydetails CppAD::local::forward_lepv_op_0
199 */
200 template <class Base>
201 void forward_ltpv_op_0(
202 size_t& count ,
203 const addr_t* arg ,
204 const Base* parameter ,
205 size_t cap_order ,
206 Base* taylor )
207 {
208 // check assumptions
209 CPPAD_ASSERT_UNKNOWN( NumArg(LtpvOp) == 2 );
210 CPPAD_ASSERT_UNKNOWN( NumRes(LtpvOp) == 0 );
211
212 // Taylor coefficients corresponding to arguments and result
213 Base x = parameter[ arg[0] ];
214 Base* y = taylor + size_t(arg[1]) * cap_order;
215
216 count += GreaterThanOrZero(x - y[0]);
217 }
218 /*!
219 Zero order forward mode comparison check that left < right
220
221 \copydetails CppAD::local::forward_levp_op_0
222 */
223 template <class Base>
224 void forward_ltvp_op_0(
225 size_t& count ,
226 const addr_t* arg ,
227 const Base* parameter ,
228 size_t cap_order ,
229 Base* taylor )
230 {
231 // check assumptions
232 CPPAD_ASSERT_UNKNOWN( NumArg(LtvpOp) == 2 );
233 CPPAD_ASSERT_UNKNOWN( NumRes(LtvpOp) == 0 );
234
235 // Taylor coefficients corresponding to arguments and result
236 Base* x = taylor + size_t(arg[0]) * cap_order;
237 Base y = parameter[ arg[1] ];
238
239 count += GreaterThanOrZero(x[0] - y);
240 }
241 /*!
242 Zero order forward mode comparison check that left < right
243
244 \copydetails CppAD::local::forward_levv_op_0
245 */
246 template <class Base>
247 void forward_ltvv_op_0(
248 size_t& count ,
249 const addr_t* arg ,
250 const Base* parameter ,
251 size_t cap_order ,
252 Base* taylor )
253 {
254 // check assumptions
255 CPPAD_ASSERT_UNKNOWN( NumArg(LtvvOp) == 2 );
256 CPPAD_ASSERT_UNKNOWN( NumRes(LtvvOp) == 0 );
257
258 // Taylor coefficients corresponding to arguments and result
259 Base* x = taylor + size_t(arg[0]) * cap_order;
260 Base* y = taylor + size_t(arg[1]) * cap_order;
261
262 count += GreaterThanOrZero(x[0] - y[0]);
263 }
264 // ------------------------------ == -------------------------------------
265 /*!
266 Zero order forward mode comparison check that left == right
267
268 \param count
269 It the condition is not true, ths counter is incremented by one.
270
271 \param arg
272 parameter[ arg[0] ] is the left operand and
273 parameter[ arg[1] ] is the right operand.
274
275 \param parameter
276 vector of parameter values.
277 */
278 template <class Base>
279 void forward_eqpp_op_0(
280 size_t& count ,
281 const addr_t* arg ,
282 const Base* parameter )
283 {
284 // check assumptions
285 CPPAD_ASSERT_UNKNOWN( NumArg(EqppOp) == 2 );
286 CPPAD_ASSERT_UNKNOWN( NumRes(EqppOp) == 0 );
287
288 // Taylor coefficients corresponding to arguments and result
289 Base x = parameter[ arg[0] ];
290 Base y = parameter[ arg[1] ];
291
292 count += size_t(x != y);
293 }
294 /*!
295 Zero order forward mode comparison check that left == right
296
297 \copydetails CppAD::local::forward_lepv_op_0
298 */
299 template <class Base>
300 void forward_eqpv_op_0(
301 size_t& count ,
302 const addr_t* arg ,
303 const Base* parameter ,
304 size_t cap_order ,
305 Base* taylor )
306 {
307 // check assumptions
308 CPPAD_ASSERT_UNKNOWN( NumArg(EqpvOp) == 2 );
309 CPPAD_ASSERT_UNKNOWN( NumRes(EqpvOp) == 0 );
310
311 // Taylor coefficients corresponding to arguments and result
312 Base x = parameter[ arg[0] ];
313 Base* y = taylor + size_t(arg[1]) * cap_order;
314
315 count += size_t(x != y[0]);
316 }
317 /*!
318 Zero order forward mode comparison check that left == right
319
320 \copydetails CppAD::local::forward_levv_op_0
321 */
322 template <class Base>
323 void forward_eqvv_op_0(
324 size_t& count ,
325 const addr_t* arg ,
326 const Base* parameter ,
327 size_t cap_order ,
328 Base* taylor )
329 {
330 // check assumptions
331 CPPAD_ASSERT_UNKNOWN( NumArg(EqvvOp) == 2 );
332 CPPAD_ASSERT_UNKNOWN( NumRes(EqvvOp) == 0 );
333
334 // Taylor coefficients corresponding to arguments and result
335 Base* x = taylor + size_t(arg[0]) * cap_order;
336 Base* y = taylor + size_t(arg[1]) * cap_order;
337
338 count += size_t(x[0] != y[0]);
339 }
340 // -------------------------------- != -----------------------------------
341 /*!
342 Zero order forward mode comparison check that left != right
343
344 \param count
345 It the condition is not true, ths counter is incremented by one.
346
347 \param arg
348 parameter[ arg[0] ] is the left operand and
349 parameter[ arg[1] ] is the right operand.
350
351 \param parameter
352 vector of parameter values.
353 */
354 template <class Base>
355 void forward_nepp_op_0(
356 size_t& count ,
357 const addr_t* arg ,
358 const Base* parameter )
359 {
360 // check assumptions
361 CPPAD_ASSERT_UNKNOWN( NumArg(NeppOp) == 2 );
362 CPPAD_ASSERT_UNKNOWN( NumRes(NeppOp) == 0 );
363
364 // Taylor coefficients corresponding to arguments and result
365 Base x = parameter[ arg[0] ];
366 Base y = parameter[ arg[1] ];
367
368 count += size_t(x == y);
369 }
370 /*!
371 Zero order forward mode comparison check that left != right
372
373 \copydetails CppAD::local::forward_lepv_op_0
374 */
375 template <class Base>
376 void forward_nepv_op_0(
377 size_t& count ,
378 const addr_t* arg ,
379 const Base* parameter ,
380 size_t cap_order ,
381 Base* taylor )
382 {
383 // check assumptions
384 CPPAD_ASSERT_UNKNOWN( NumArg(NepvOp) == 2 );
385 CPPAD_ASSERT_UNKNOWN( NumRes(NepvOp) == 0 );
386
387 // Taylor coefficients corresponding to arguments and result
388 Base x = parameter[ arg[0] ];
389 Base* y = taylor + size_t(arg[1]) * cap_order;
390
391 count += size_t(x == y[0]);
392 }
393 /*!
394 Zero order forward mode comparison check that left != right
395
396 \copydetails CppAD::local::forward_levv_op_0
397 */
398 template <class Base>
399 void forward_nevv_op_0(
400 size_t& count ,
401 const addr_t* arg ,
402 const Base* parameter ,
403 size_t cap_order ,
404 Base* taylor )
405 {
406 // check assumptions
407 CPPAD_ASSERT_UNKNOWN( NumArg(NevvOp) == 2 );
408 CPPAD_ASSERT_UNKNOWN( NumRes(NevvOp) == 0 );
409
410 // Taylor coefficients corresponding to arguments and result
411 Base* x = taylor + size_t(arg[0]) * cap_order;
412 Base* y = taylor + size_t(arg[1]) * cap_order;
413
414 count += size_t(x[0] == y[0]);
415 }
416
417
418 } } // END_CPPAD_LOCAL_NAMESPACE
419 # endif
+0
-1317
include/cppad/local/cond_op.hpp less more
0 # ifndef CPPAD_LOCAL_COND_OP_HPP
1 # define CPPAD_LOCAL_COND_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file cond_op.hpp
17 Forward, reverse, and sparse operations for conditional expressions.
18 */
19
20 /*!
21 Shared documentation for conditional expressions (not called).
22
23 <!-- define conditional_exp_op -->
24 The C++ source code coresponding to this operation is
25 \verbatim
26 z = CondExpRel(y_0, y_1, y_2, y_3)
27 \endverbatim
28 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
29
30 \tparam Base
31 base type for the operator; i.e., this operation was recorded
32 using AD< Base > and computations by this routine are done using type
33 Base.
34
35 \param i_z
36 is the AD variable index corresponding to the variable z.
37
38 \param arg
39 \n
40 arg[0]
41 is static cast to size_t from the enum type
42 \verbatim
43 enum CompareOp {
44 CompareLt,
45 CompareLe,
46 CompareEq,
47 CompareGe,
48 CompareGt,
49 CompareNe
50 }
51 \endverbatim
52 for this operation.
53 Note that arg[0] cannot be equal to CompareNe.
54 \n
55 \n
56 arg[1] & 1
57 \n
58 If this is zero, y_0 is a parameter. Otherwise it is a variable.
59 \n
60 \n
61 arg[1] & 2
62 \n
63 If this is zero, y_1 is a parameter. Otherwise it is a variable.
64 \n
65 \n
66 arg[1] & 4
67 \n
68 If this is zero, y_2 is a parameter. Otherwise it is a variable.
69 \n
70 \n
71 arg[1] & 8
72 \n
73 If this is zero, y_3 is a parameter. Otherwise it is a variable.
74 \n
75 \n
76 arg[2 + j ] for j = 0, 1, 2, 3
77 \n
78 is the index corresponding to y_j.
79
80 \param num_par
81 is the total number of values in the vector parameter.
82
83 \param parameter
84 For j = 0, 1, 2, 3,
85 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
86
87 \param cap_order
88 number of columns in the matrix containing the Taylor coefficients.
89
90 \par Checked Assertions
91 \li NumArg(CExpOp) == 6
92 \li NumRes(CExpOp) == 1
93 \li arg[0] < static_cast<size_t> ( CompareNe )
94 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
95 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
96 <!-- end conditional_exp_op -->
97 */
98 template <class Base>
99 void conditional_exp_op(
100 size_t i_z ,
101 const addr_t* arg ,
102 size_t num_par ,
103 const Base* parameter ,
104 size_t cap_order )
105 { // This routine is only for documentation, it should never be used
106 CPPAD_ASSERT_UNKNOWN( false );
107 }
108
109 /*!
110 Shared documentation for conditional expression sparse operations (not called).
111
112 <!-- define sparse_conditional_exp_op -->
113 The C++ source code coresponding to this operation is
114 \verbatim
115 z = CondExpRel(y_0, y_1, y_2, y_3)
116 \endverbatim
117 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
118
119 \tparam Vector_set
120 is the type used for vectors of sets. It can be either
121 sparse::pack_setvec or sparse::list_setvec.
122
123 \param i_z
124 is the AD variable index corresponding to the variable z.
125
126 \param arg
127 \n
128 arg[0]
129 is static cast to size_t from the enum type
130 \verbatim
131 enum CompareOp {
132 CompareLt,
133 CompareLe,
134 CompareEq,
135 CompareGe,
136 CompareGt,
137 CompareNe
138 }
139 \endverbatim
140 for this operation.
141 Note that arg[0] cannot be equal to CompareNe.
142 \n
143 \n
144 arg[1] & 1
145 \n
146 If this is zero, y_0 is a parameter. Otherwise it is a variable.
147 \n
148 \n
149 arg[1] & 2
150 \n
151 If this is zero, y_1 is a parameter. Otherwise it is a variable.
152 \n
153 \n
154 arg[1] & 4
155 \n
156 If this is zero, y_2 is a parameter. Otherwise it is a variable.
157 \n
158 \n
159 arg[1] & 8
160 \n
161 If this is zero, y_3 is a parameter. Otherwise it is a variable.
162 \n
163 \n
164 arg[2 + j ] for j = 0, 1, 2, 3
165 \n
166 is the index corresponding to y_j.
167
168 \param num_par
169 is the total number of values in the vector parameter.
170
171 \par Checked Assertions
172 \li NumArg(CExpOp) == 6
173 \li NumRes(CExpOp) == 1
174 \li arg[0] < static_cast<size_t> ( CompareNe )
175 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
176 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
177 <!-- end sparse_conditional_exp_op -->
178 */
179 template <class Vector_set>
180 void sparse_conditional_exp_op(
181 size_t i_z ,
182 const addr_t* arg ,
183 size_t num_par )
184 { // This routine is only for documentation, it should never be used
185 CPPAD_ASSERT_UNKNOWN( false );
186 }
187
188 /*!
189 Compute forward mode Taylor coefficients for op = CExpOp.
190
191 <!-- replace conditional_exp_op -->
192 The C++ source code coresponding to this operation is
193 \verbatim
194 z = CondExpRel(y_0, y_1, y_2, y_3)
195 \endverbatim
196 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
197
198 \tparam Base
199 base type for the operator; i.e., this operation was recorded
200 using AD< Base > and computations by this routine are done using type
201 Base.
202
203 \param i_z
204 is the AD variable index corresponding to the variable z.
205
206 \param arg
207 \n
208 arg[0]
209 is static cast to size_t from the enum type
210 \verbatim
211 enum CompareOp {
212 CompareLt,
213 CompareLe,
214 CompareEq,
215 CompareGe,
216 CompareGt,
217 CompareNe
218 }
219 \endverbatim
220 for this operation.
221 Note that arg[0] cannot be equal to CompareNe.
222 \n
223 \n
224 arg[1] & 1
225 \n
226 If this is zero, y_0 is a parameter. Otherwise it is a variable.
227 \n
228 \n
229 arg[1] & 2
230 \n
231 If this is zero, y_1 is a parameter. Otherwise it is a variable.
232 \n
233 \n
234 arg[1] & 4
235 \n
236 If this is zero, y_2 is a parameter. Otherwise it is a variable.
237 \n
238 \n
239 arg[1] & 8
240 \n
241 If this is zero, y_3 is a parameter. Otherwise it is a variable.
242 \n
243 \n
244 arg[2 + j ] for j = 0, 1, 2, 3
245 \n
246 is the index corresponding to y_j.
247
248 \param num_par
249 is the total number of values in the vector parameter.
250
251 \param parameter
252 For j = 0, 1, 2, 3,
253 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
254
255 \param cap_order
256 number of columns in the matrix containing the Taylor coefficients.
257
258 \par Checked Assertions
259 \li NumArg(CExpOp) == 6
260 \li NumRes(CExpOp) == 1
261 \li arg[0] < static_cast<size_t> ( CompareNe )
262 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
263 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
264 <!-- end conditional_exp_op -->
265
266 \param p
267 is the lowest order of the Taylor coefficient of z that we are computing.
268
269 \param q
270 is the highest order of the Taylor coefficient of z that we are computing.
271
272 \param taylor
273 \b Input:
274 For j = 0, 1, 2, 3 and k = 0 , ... , q,
275 if y_j is a variable then
276 <code>taylor [ arg[2+j] * cap_order + k ]</code>
277 is the k-th order Taylor coefficient corresponding to y_j.
278 \n
279 \b Input: <code>taylor [ i_z * cap_order + k ]</code>
280 for k = 0 , ... , p-1,
281 is the k-th order Taylor coefficient corresponding to z.
282 \n
283 \b Output: <code>taylor [ i_z * cap_order + k ]</code>
284 for k = p , ... , q,
285 is the k-th order Taylor coefficient corresponding to z.
286
287 */
288 template <class Base>
289 void forward_cond_op(
290 size_t p ,
291 size_t q ,
292 size_t i_z ,
293 const addr_t* arg ,
294 size_t num_par ,
295 const Base* parameter ,
296 size_t cap_order ,
297 Base* taylor )
298 { Base y_0, y_1, y_2, y_3;
299 Base zero(0);
300 Base* z = taylor + i_z * cap_order;
301
302 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
303 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
304 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
305 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
306
307 if( arg[1] & 1 )
308 {
309 y_0 = taylor[ size_t(arg[2]) * cap_order + 0 ];
310 }
311 else
312 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
313 y_0 = parameter[ arg[2] ];
314 }
315 if( arg[1] & 2 )
316 {
317 y_1 = taylor[ size_t(arg[3]) * cap_order + 0 ];
318 }
319 else
320 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
321 y_1 = parameter[ arg[3] ];
322 }
323 if( p == 0 )
324 { if( arg[1] & 4 )
325 {
326 y_2 = taylor[ size_t(arg[4]) * cap_order + 0 ];
327 }
328 else
329 { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_par );
330 y_2 = parameter[ arg[4] ];
331 }
332 if( arg[1] & 8 )
333 {
334 y_3 = taylor[ size_t(arg[5]) * cap_order + 0 ];
335 }
336 else
337 { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < num_par );
338 y_3 = parameter[ arg[5] ];
339 }
340 z[0] = CondExpOp(
341 CompareOp( arg[0] ),
342 y_0,
343 y_1,
344 y_2,
345 y_3
346 );
347 p++;
348 }
349 for(size_t d = p; d <= q; d++)
350 { if( arg[1] & 4 )
351 {
352 y_2 = taylor[ size_t(arg[4]) * cap_order + d];
353 }
354 else
355 y_2 = zero;
356 if( arg[1] & 8 )
357 {
358 y_3 = taylor[ size_t(arg[5]) * cap_order + d];
359 }
360 else
361 y_3 = zero;
362 z[d] = CondExpOp(
363 CompareOp( arg[0] ),
364 y_0,
365 y_1,
366 y_2,
367 y_3
368 );
369 }
370 return;
371 }
372
373 /*!
374 Multiple directions forward mode Taylor coefficients for op = CExpOp.
375
376 <!-- replace conditional_exp_op -->
377 The C++ source code coresponding to this operation is
378 \verbatim
379 z = CondExpRel(y_0, y_1, y_2, y_3)
380 \endverbatim
381 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
382
383 \tparam Base
384 base type for the operator; i.e., this operation was recorded
385 using AD< Base > and computations by this routine are done using type
386 Base.
387
388 \param i_z
389 is the AD variable index corresponding to the variable z.
390
391 \param arg
392 \n
393 arg[0]
394 is static cast to size_t from the enum type
395 \verbatim
396 enum CompareOp {
397 CompareLt,
398 CompareLe,
399 CompareEq,
400 CompareGe,
401 CompareGt,
402 CompareNe
403 }
404 \endverbatim
405 for this operation.
406 Note that arg[0] cannot be equal to CompareNe.
407 \n
408 \n
409 arg[1] & 1
410 \n
411 If this is zero, y_0 is a parameter. Otherwise it is a variable.
412 \n
413 \n
414 arg[1] & 2
415 \n
416 If this is zero, y_1 is a parameter. Otherwise it is a variable.
417 \n
418 \n
419 arg[1] & 4
420 \n
421 If this is zero, y_2 is a parameter. Otherwise it is a variable.
422 \n
423 \n
424 arg[1] & 8
425 \n
426 If this is zero, y_3 is a parameter. Otherwise it is a variable.
427 \n
428 \n
429 arg[2 + j ] for j = 0, 1, 2, 3
430 \n
431 is the index corresponding to y_j.
432
433 \param num_par
434 is the total number of values in the vector parameter.
435
436 \param parameter
437 For j = 0, 1, 2, 3,
438 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
439
440 \param cap_order
441 number of columns in the matrix containing the Taylor coefficients.
442
443 \par Checked Assertions
444 \li NumArg(CExpOp) == 6
445 \li NumRes(CExpOp) == 1
446 \li arg[0] < static_cast<size_t> ( CompareNe )
447 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
448 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
449 <!-- end conditional_exp_op -->
450
451 \param q
452 is order of the Taylor coefficient of z that we are computing.
453
454 \param r
455 is the number of Taylor coefficient directions that we are computing.
456
457 \par tpv
458 We use the notation
459 <code>tpv = (cap_order-1) * r + 1</code>
460 which is the number of Taylor coefficients per variable
461
462 \param taylor
463 \b Input:
464 For j = 0, 1, 2, 3, k = 1, ..., q,
465 if y_j is a variable then
466 <code>taylor [ arg[2+j] * tpv + 0 ]</code>
467 is the zero order Taylor coefficient corresponding to y_j and
468 <code>taylor [ arg[2+j] * tpv + (k-1)*r+1+ell</code> is its
469 k-th order Taylor coefficient in the ell-th direction.
470 \n
471 \b Input:
472 For j = 0, 1, 2, 3, k = 1, ..., q-1,
473 <code>taylor [ i_z * tpv + 0 ]</code>
474 is the zero order Taylor coefficient corresponding to z and
475 <code>taylor [ i_z * tpv + (k-1)*r+1+ell</code> is its
476 k-th order Taylor coefficient in the ell-th direction.
477 \n
478 \b Output: <code>taylor [ i_z * tpv + (q-1)*r+1+ell ]</code>
479 is the q-th order Taylor coefficient corresponding to z
480 in the ell-th direction.
481 */
482 template <class Base>
483 void forward_cond_op_dir(
484 size_t q ,
485 size_t r ,
486 size_t i_z ,
487 const addr_t* arg ,
488 size_t num_par ,
489 const Base* parameter ,
490 size_t cap_order ,
491 Base* taylor )
492 { Base y_0, y_1, y_2, y_3;
493 Base zero(0);
494 size_t num_taylor_per_var = (cap_order-1) * r + 1;
495 Base* z = taylor + i_z * num_taylor_per_var;
496
497 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
498 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
499 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
500 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
501 CPPAD_ASSERT_UNKNOWN( 0 < q );
502 CPPAD_ASSERT_UNKNOWN( q < cap_order );
503
504 if( arg[1] & 1 )
505 {
506 y_0 = taylor[ size_t(arg[2]) * num_taylor_per_var + 0 ];
507 }
508 else
509 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
510 y_0 = parameter[ arg[2] ];
511 }
512 if( arg[1] & 2 )
513 {
514 y_1 = taylor[ size_t(arg[3]) * num_taylor_per_var + 0 ];
515 }
516 else
517 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
518 y_1 = parameter[ arg[3] ];
519 }
520 size_t m = (q-1) * r + 1;
521 for(size_t ell = 0; ell < r; ell++)
522 { if( arg[1] & 4 )
523 {
524 y_2 = taylor[ size_t(arg[4]) * num_taylor_per_var + m + ell];
525 }
526 else
527 y_2 = zero;
528 if( arg[1] & 8 )
529 {
530 y_3 = taylor[ size_t(arg[5]) * num_taylor_per_var + m + ell];
531 }
532 else
533 y_3 = zero;
534 z[m+ell] = CondExpOp(
535 CompareOp( arg[0] ),
536 y_0,
537 y_1,
538 y_2,
539 y_3
540 );
541 }
542 return;
543 }
544
545 /*!
546 Compute zero order forward mode Taylor coefficients for op = CExpOp.
547
548 <!-- replace conditional_exp_op -->
549 The C++ source code coresponding to this operation is
550 \verbatim
551 z = CondExpRel(y_0, y_1, y_2, y_3)
552 \endverbatim
553 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
554
555 \tparam Base
556 base type for the operator; i.e., this operation was recorded
557 using AD< Base > and computations by this routine are done using type
558 Base.
559
560 \param i_z
561 is the AD variable index corresponding to the variable z.
562
563 \param arg
564 \n
565 arg[0]
566 is static cast to size_t from the enum type
567 \verbatim
568 enum CompareOp {
569 CompareLt,
570 CompareLe,
571 CompareEq,
572 CompareGe,
573 CompareGt,
574 CompareNe
575 }
576 \endverbatim
577 for this operation.
578 Note that arg[0] cannot be equal to CompareNe.
579 \n
580 \n
581 arg[1] & 1
582 \n
583 If this is zero, y_0 is a parameter. Otherwise it is a variable.
584 \n
585 \n
586 arg[1] & 2
587 \n
588 If this is zero, y_1 is a parameter. Otherwise it is a variable.
589 \n
590 \n
591 arg[1] & 4
592 \n
593 If this is zero, y_2 is a parameter. Otherwise it is a variable.
594 \n
595 \n
596 arg[1] & 8
597 \n
598 If this is zero, y_3 is a parameter. Otherwise it is a variable.
599 \n
600 \n
601 arg[2 + j ] for j = 0, 1, 2, 3
602 \n
603 is the index corresponding to y_j.
604
605 \param num_par
606 is the total number of values in the vector parameter.
607
608 \param parameter
609 For j = 0, 1, 2, 3,
610 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
611
612 \param cap_order
613 number of columns in the matrix containing the Taylor coefficients.
614
615 \par Checked Assertions
616 \li NumArg(CExpOp) == 6
617 \li NumRes(CExpOp) == 1
618 \li arg[0] < static_cast<size_t> ( CompareNe )
619 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
620 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
621 <!-- end conditional_exp_op -->
622
623 \param taylor
624 \b Input:
625 For j = 0, 1, 2, 3,
626 if y_j is a variable then
627 taylor [ arg[2+j] * cap_order + 0 ]
628 is the zero order Taylor coefficient corresponding to y_j.
629 \n
630 \b Output: taylor [ i_z * cap_order + 0 ]
631 is the zero order Taylor coefficient corresponding to z.
632 */
633 template <class Base>
634 void forward_cond_op_0(
635 size_t i_z ,
636 const addr_t* arg ,
637 size_t num_par ,
638 const Base* parameter ,
639 size_t cap_order ,
640 Base* taylor )
641 { Base y_0, y_1, y_2, y_3;
642 Base* z;
643
644 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
645 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
646 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
647 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
648
649 if( arg[1] & 1 )
650 {
651 y_0 = taylor[ size_t(arg[2]) * cap_order + 0 ];
652 }
653 else
654 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
655 y_0 = parameter[ arg[2] ];
656 }
657 if( arg[1] & 2 )
658 {
659 y_1 = taylor[ size_t(arg[3]) * cap_order + 0 ];
660 }
661 else
662 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
663 y_1 = parameter[ arg[3] ];
664 }
665 if( arg[1] & 4 )
666 {
667 y_2 = taylor[ size_t(arg[4]) * cap_order + 0 ];
668 }
669 else
670 { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_par );
671 y_2 = parameter[ arg[4] ];
672 }
673 if( arg[1] & 8 )
674 {
675 y_3 = taylor[ size_t(arg[5]) * cap_order + 0 ];
676 }
677 else
678 { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < num_par );
679 y_3 = parameter[ arg[5] ];
680 }
681 z = taylor + i_z * cap_order;
682 z[0] = CondExpOp(
683 CompareOp( arg[0] ),
684 y_0,
685 y_1,
686 y_2,
687 y_3
688 );
689 return;
690 }
691
692 /*!
693 Compute reverse mode Taylor coefficients for op = CExpOp.
694
695 This routine is given the partial derivatives of a function
696 G( z , y , x , w , ... )
697 and it uses them to compute the partial derivatives of
698 \verbatim
699 H( y , x , w , u , ... ) = G[ z(y) , y , x , w , u , ... ]
700 \endverbatim
701 where y above represents y_0, y_1, y_2, y_3.
702
703 <!-- replace conditional_exp_op -->
704 The C++ source code coresponding to this operation is
705 \verbatim
706 z = CondExpRel(y_0, y_1, y_2, y_3)
707 \endverbatim
708 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
709
710 \tparam Base
711 base type for the operator; i.e., this operation was recorded
712 using AD< Base > and computations by this routine are done using type
713 Base.
714
715 \param i_z
716 is the AD variable index corresponding to the variable z.
717
718 \param arg
719 \n
720 arg[0]
721 is static cast to size_t from the enum type
722 \verbatim
723 enum CompareOp {
724 CompareLt,
725 CompareLe,
726 CompareEq,
727 CompareGe,
728 CompareGt,
729 CompareNe
730 }
731 \endverbatim
732 for this operation.
733 Note that arg[0] cannot be equal to CompareNe.
734 \n
735 \n
736 arg[1] & 1
737 \n
738 If this is zero, y_0 is a parameter. Otherwise it is a variable.
739 \n
740 \n
741 arg[1] & 2
742 \n
743 If this is zero, y_1 is a parameter. Otherwise it is a variable.
744 \n
745 \n
746 arg[1] & 4
747 \n
748 If this is zero, y_2 is a parameter. Otherwise it is a variable.
749 \n
750 \n
751 arg[1] & 8
752 \n
753 If this is zero, y_3 is a parameter. Otherwise it is a variable.
754 \n
755 \n
756 arg[2 + j ] for j = 0, 1, 2, 3
757 \n
758 is the index corresponding to y_j.
759
760 \param num_par
761 is the total number of values in the vector parameter.
762
763 \param parameter
764 For j = 0, 1, 2, 3,
765 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
766
767 \param cap_order
768 number of columns in the matrix containing the Taylor coefficients.
769
770 \par Checked Assertions
771 \li NumArg(CExpOp) == 6
772 \li NumRes(CExpOp) == 1
773 \li arg[0] < static_cast<size_t> ( CompareNe )
774 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
775 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
776 <!-- end conditional_exp_op -->
777
778 \param d
779 is the order of the Taylor coefficient of z that we are computing.
780
781 \param taylor
782 \b Input:
783 For j = 0, 1, 2, 3 and k = 0 , ... , d,
784 if y_j is a variable then
785 taylor [ arg[2+j] * cap_order + k ]
786 is the k-th order Taylor coefficient corresponding to y_j.
787 \n
788 taylor [ i_z * cap_order + k ]
789 for k = 0 , ... , d
790 is the k-th order Taylor coefficient corresponding to z.
791
792 \param nc_partial
793 number of columns in the matrix containing the Taylor coefficients.
794
795 \param partial
796 \b Input:
797 For j = 0, 1, 2, 3 and k = 0 , ... , d,
798 if y_j is a variable then
799 partial [ arg[2+j] * nc_partial + k ]
800 is the partial derivative of G( z , y , x , w , u , ... )
801 with respect to the k-th order Taylor coefficient corresponding to y_j.
802 \n
803 \b Input: partial [ i_z * cap_order + k ]
804 for k = 0 , ... , d
805 is the partial derivative of G( z , y , x , w , u , ... )
806 with respect to the k-th order Taylor coefficient corresponding to z.
807 \n
808 \b Output:
809 For j = 0, 1, 2, 3 and k = 0 , ... , d,
810 if y_j is a variable then
811 partial [ arg[2+j] * nc_partial + k ]
812 is the partial derivative of H( y , x , w , u , ... )
813 with respect to the k-th order Taylor coefficient corresponding to y_j.
814
815 */
816 template <class Base>
817 void reverse_cond_op(
818 size_t d ,
819 size_t i_z ,
820 const addr_t* arg ,
821 size_t num_par ,
822 const Base* parameter ,
823 size_t cap_order ,
824 const Base* taylor ,
825 size_t nc_partial ,
826 Base* partial )
827 { Base y_0, y_1;
828 Base zero(0);
829 Base* pz;
830 Base* py_2;
831 Base* py_3;
832
833 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
834 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
835 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
836 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
837
838 pz = partial + i_z * nc_partial + 0;
839 if( arg[1] & 1 )
840 {
841 y_0 = taylor[ size_t(arg[2]) * cap_order + 0 ];
842 }
843 else
844 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
845 y_0 = parameter[ arg[2] ];
846 }
847 if( arg[1] & 2 )
848 {
849 y_1 = taylor[ size_t(arg[3]) * cap_order + 0 ];
850 }
851 else
852 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
853 y_1 = parameter[ arg[3] ];
854 }
855 if( arg[1] & 4 )
856 {
857 py_2 = partial + size_t(arg[4]) * nc_partial;
858 size_t j = d + 1;
859 while(j--)
860 { py_2[j] += CondExpOp(
861 CompareOp( arg[0] ),
862 y_0,
863 y_1,
864 pz[j],
865 zero
866 );
867 }
868 }
869 if( arg[1] & 8 )
870 {
871 py_3 = partial + size_t(arg[5]) * nc_partial;
872 size_t j = d + 1;
873 while(j--)
874 { py_3[j] += CondExpOp(
875 CompareOp( arg[0] ),
876 y_0,
877 y_1,
878 zero,
879 pz[j]
880 );
881 }
882 }
883 return;
884 }
885
886 /*!
887 Compute forward Jacobian sparsity patterns for op = CExpOp.
888
889 <!-- replace sparse_conditional_exp_op -->
890 The C++ source code coresponding to this operation is
891 \verbatim
892 z = CondExpRel(y_0, y_1, y_2, y_3)
893 \endverbatim
894 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
895
896 \tparam Vector_set
897 is the type used for vectors of sets. It can be either
898 sparse::pack_setvec or sparse::list_setvec.
899
900 \param i_z
901 is the AD variable index corresponding to the variable z.
902
903 \param arg
904 \n
905 arg[0]
906 is static cast to size_t from the enum type
907 \verbatim
908 enum CompareOp {
909 CompareLt,
910 CompareLe,
911 CompareEq,
912 CompareGe,
913 CompareGt,
914 CompareNe
915 }
916 \endverbatim
917 for this operation.
918 Note that arg[0] cannot be equal to CompareNe.
919 \n
920 \n
921 arg[1] & 1
922 \n
923 If this is zero, y_0 is a parameter. Otherwise it is a variable.
924 \n
925 \n
926 arg[1] & 2
927 \n
928 If this is zero, y_1 is a parameter. Otherwise it is a variable.
929 \n
930 \n
931 arg[1] & 4
932 \n
933 If this is zero, y_2 is a parameter. Otherwise it is a variable.
934 \n
935 \n
936 arg[1] & 8
937 \n
938 If this is zero, y_3 is a parameter. Otherwise it is a variable.
939 \n
940 \n
941 arg[2 + j ] for j = 0, 1, 2, 3
942 \n
943 is the index corresponding to y_j.
944
945 \param num_par
946 is the total number of values in the vector parameter.
947
948 \par Checked Assertions
949 \li NumArg(CExpOp) == 6
950 \li NumRes(CExpOp) == 1
951 \li arg[0] < static_cast<size_t> ( CompareNe )
952 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
953 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
954 <!-- end sparse_conditional_exp_op -->
955
956 \param dependency
957 Are the derivatives with respect to left and right of the expression below
958 considered to be non-zero:
959 \code
960 CondExpRel(left, right, if_true, if_false)
961 \endcode
962 This is used by the optimizer to obtain the correct dependency relations.
963
964 \param sparsity
965 \b Input:
966 if y_2 is a variable, the set with index t is
967 the sparsity pattern corresponding to y_2.
968 This identifies which of the independent variables the variable y_2
969 depends on.
970 \n
971 \b Input:
972 if y_3 is a variable, the set with index t is
973 the sparsity pattern corresponding to y_3.
974 This identifies which of the independent variables the variable y_3
975 depends on.
976 \n
977 \b Output:
978 The set with index T is
979 the sparsity pattern corresponding to z.
980 This identifies which of the independent variables the variable z
981 depends on.
982 */
983 template <class Vector_set>
984 void forward_sparse_jacobian_cond_op(
985 bool dependency ,
986 size_t i_z ,
987 const addr_t* arg ,
988 size_t num_par ,
989 Vector_set& sparsity )
990 {
991 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
992 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
993 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
994 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
995 # ifndef NDEBUG
996 addr_t k = 1;
997 for( size_t j = 0; j < 4; j++)
998 { if( ! ( arg[1] & k ) )
999 CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par );
1000 k *= 2;
1001 }
1002 # endif
1003 sparsity.clear(i_z);
1004 if( dependency )
1005 { if( arg[1] & 1 )
1006 sparsity.binary_union(i_z, i_z, size_t(arg[2]), sparsity);
1007 if( arg[1] & 2 )
1008 sparsity.binary_union(i_z, i_z, size_t(arg[3]), sparsity);
1009 }
1010 if( arg[1] & 4 )
1011 sparsity.binary_union(i_z, i_z, size_t(arg[4]), sparsity);
1012 if( arg[1] & 8 )
1013 sparsity.binary_union(i_z, i_z, size_t(arg[5]), sparsity);
1014 return;
1015 }
1016
1017 /*!
1018 Compute reverse Jacobian sparsity patterns for op = CExpOp.
1019
1020 This routine is given the sparsity patterns
1021 for a function G(z, y, x, ... )
1022 and it uses them to compute the sparsity patterns for
1023 \verbatim
1024 H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1025 \endverbatim
1026 where y represents the combination of y_0, y_1, y_2, and y_3.
1027
1028 <!-- replace sparse_conditional_exp_op -->
1029 The C++ source code coresponding to this operation is
1030 \verbatim
1031 z = CondExpRel(y_0, y_1, y_2, y_3)
1032 \endverbatim
1033 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
1034
1035 \tparam Vector_set
1036 is the type used for vectors of sets. It can be either
1037 sparse::pack_setvec or sparse::list_setvec.
1038
1039 \param i_z
1040 is the AD variable index corresponding to the variable z.
1041
1042 \param arg
1043 \n
1044 arg[0]
1045 is static cast to size_t from the enum type
1046 \verbatim
1047 enum CompareOp {
1048 CompareLt,
1049 CompareLe,
1050 CompareEq,
1051 CompareGe,
1052 CompareGt,
1053 CompareNe
1054 }
1055 \endverbatim
1056 for this operation.
1057 Note that arg[0] cannot be equal to CompareNe.
1058 \n
1059 \n
1060 arg[1] & 1
1061 \n
1062 If this is zero, y_0 is a parameter. Otherwise it is a variable.
1063 \n
1064 \n
1065 arg[1] & 2
1066 \n
1067 If this is zero, y_1 is a parameter. Otherwise it is a variable.
1068 \n
1069 \n
1070 arg[1] & 4
1071 \n
1072 If this is zero, y_2 is a parameter. Otherwise it is a variable.
1073 \n
1074 \n
1075 arg[1] & 8
1076 \n
1077 If this is zero, y_3 is a parameter. Otherwise it is a variable.
1078 \n
1079 \n
1080 arg[2 + j ] for j = 0, 1, 2, 3
1081 \n
1082 is the index corresponding to y_j.
1083
1084 \param num_par
1085 is the total number of values in the vector parameter.
1086
1087 \par Checked Assertions
1088 \li NumArg(CExpOp) == 6
1089 \li NumRes(CExpOp) == 1
1090 \li arg[0] < static_cast<size_t> ( CompareNe )
1091 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
1092 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
1093 <!-- end sparse_conditional_exp_op -->
1094
1095 \param dependency
1096 Are the derivatives with respect to left and right of the expression below
1097 considered to be non-zero:
1098 \code
1099 CondExpRel(left, right, if_true, if_false)
1100 \endcode
1101 This is used by the optimizer to obtain the correct dependency relations.
1102
1103
1104 \param sparsity
1105 if y_2 is a variable, the set with index t is
1106 the sparsity pattern corresponding to y_2.
1107 This identifies which of the dependent variables depend on the variable y_2.
1108 On input, this pattern corresponds to the function G.
1109 On ouput, it corresponds to the function H.
1110 \n
1111 \n
1112 if y_3 is a variable, the set with index t is
1113 the sparsity pattern corresponding to y_3.
1114 This identifies which of the dependent variables depeond on the variable y_3.
1115 On input, this pattern corresponds to the function G.
1116 On ouput, it corresponds to the function H.
1117 \n
1118 \b Output:
1119 The set with index T is
1120 the sparsity pattern corresponding to z.
1121 This identifies which of the dependent variables depend on the variable z.
1122 On input and output, this pattern corresponds to the function G.
1123 */
1124 template <class Vector_set>
1125 void reverse_sparse_jacobian_cond_op(
1126 bool dependency ,
1127 size_t i_z ,
1128 const addr_t* arg ,
1129 size_t num_par ,
1130 Vector_set& sparsity )
1131 {
1132 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
1133 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
1134 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
1135 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
1136 # ifndef NDEBUG
1137 addr_t k = 1;
1138 for( size_t j = 0; j < 4; j++)
1139 { if( ! ( arg[1] & k ) )
1140 CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par );
1141 k *= 2;
1142 }
1143 # endif
1144 if( dependency )
1145 { if( arg[1] & 1 )
1146 sparsity.binary_union( size_t(arg[2]), size_t(arg[2]), i_z, sparsity);
1147 if( arg[1] & 2 )
1148 sparsity.binary_union( size_t(arg[3]), size_t(arg[3]), i_z, sparsity);
1149 }
1150 // --------------------------------------------------------------------
1151 if( arg[1] & 4 )
1152 sparsity.binary_union( size_t(arg[4]), size_t(arg[4]), i_z, sparsity);
1153 if( arg[1] & 8 )
1154 sparsity.binary_union( size_t(arg[5]), size_t(arg[5]), i_z, sparsity);
1155 return;
1156 }
1157
1158 /*!
1159 Compute reverse Hessian sparsity patterns for op = CExpOp.
1160
1161 This routine is given the sparsity patterns
1162 for a function G(z, y, x, ... )
1163 and it uses them to compute the sparsity patterns for
1164 \verbatim
1165 H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1166 \endverbatim
1167 where y represents the combination of y_0, y_1, y_2, and y_3.
1168
1169 <!-- replace sparse_conditional_exp_op -->
1170 The C++ source code coresponding to this operation is
1171 \verbatim
1172 z = CondExpRel(y_0, y_1, y_2, y_3)
1173 \endverbatim
1174 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
1175
1176 \tparam Vector_set
1177 is the type used for vectors of sets. It can be either
1178 sparse::pack_setvec or sparse::list_setvec.
1179
1180 \param i_z
1181 is the AD variable index corresponding to the variable z.
1182
1183 \param arg
1184 \n
1185 arg[0]
1186 is static cast to size_t from the enum type
1187 \verbatim
1188 enum CompareOp {
1189 CompareLt,
1190 CompareLe,
1191 CompareEq,
1192 CompareGe,
1193 CompareGt,
1194 CompareNe
1195 }
1196 \endverbatim
1197 for this operation.
1198 Note that arg[0] cannot be equal to CompareNe.
1199 \n
1200 \n
1201 arg[1] & 1
1202 \n
1203 If this is zero, y_0 is a parameter. Otherwise it is a variable.
1204 \n
1205 \n
1206 arg[1] & 2
1207 \n
1208 If this is zero, y_1 is a parameter. Otherwise it is a variable.
1209 \n
1210 \n
1211 arg[1] & 4
1212 \n
1213 If this is zero, y_2 is a parameter. Otherwise it is a variable.
1214 \n
1215 \n
1216 arg[1] & 8
1217 \n
1218 If this is zero, y_3 is a parameter. Otherwise it is a variable.
1219 \n
1220 \n
1221 arg[2 + j ] for j = 0, 1, 2, 3
1222 \n
1223 is the index corresponding to y_j.
1224
1225 \param num_par
1226 is the total number of values in the vector parameter.
1227
1228 \par Checked Assertions
1229 \li NumArg(CExpOp) == 6
1230 \li NumRes(CExpOp) == 1
1231 \li arg[0] < static_cast<size_t> ( CompareNe )
1232 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
1233 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
1234 <!-- end sparse_conditional_exp_op -->
1235
1236
1237 \param jac_reverse
1238 jac_reverse[i_z]
1239 is false (true) if the Jacobian of G with respect to z is always zero
1240 (may be non-zero).
1241 \n
1242 \n
1243 jac_reverse[ arg[4] ]
1244 If y_2 is a variable,
1245 jac_reverse[ arg[4] ]
1246 is false (true) if the Jacobian with respect to y_2 is always zero
1247 (may be non-zero).
1248 On input, it corresponds to the function G,
1249 and on output it corresponds to the function H.
1250 \n
1251 \n
1252 jac_reverse[ arg[5] ]
1253 If y_3 is a variable,
1254 jac_reverse[ arg[5] ]
1255 is false (true) if the Jacobian with respect to y_3 is always zero
1256 (may be non-zero).
1257 On input, it corresponds to the function G,
1258 and on output it corresponds to the function H.
1259
1260 \param hes_sparsity
1261 The set with index i_z in hes_sparsity
1262 is the Hessian sparsity pattern for the function G
1263 where one of the partials is with respect to z.
1264 \n
1265 \n
1266 If y_2 is a variable,
1267 the set with index arg[4] in hes_sparsity
1268 is the Hessian sparsity pattern
1269 where one of the partials is with respect to y_2.
1270 On input, this pattern corresponds to the function G.
1271 On output, this pattern corresponds to the function H.
1272 \n
1273 \n
1274 If y_3 is a variable,
1275 the set with index arg[5] in hes_sparsity
1276 is the Hessian sparsity pattern
1277 where one of the partials is with respect to y_3.
1278 On input, this pattern corresponds to the function G.
1279 On output, this pattern corresponds to the function H.
1280 */
1281 template <class Vector_set>
1282 void reverse_sparse_hessian_cond_op(
1283 size_t i_z ,
1284 const addr_t* arg ,
1285 size_t num_par ,
1286 bool* jac_reverse ,
1287 Vector_set& hes_sparsity )
1288 {
1289
1290 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
1291 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
1292 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
1293 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
1294 # ifndef NDEBUG
1295 addr_t k = 1;
1296 for( size_t j = 0; j < 4; j++)
1297 { if( ! ( arg[1] & k ) )
1298 CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par );
1299 k *= 2;
1300 }
1301 # endif
1302 if( arg[1] & 4 )
1303 {
1304 hes_sparsity.binary_union( size_t(arg[4]), size_t(arg[4]), i_z, hes_sparsity);
1305 jac_reverse[ arg[4] ] |= jac_reverse[i_z];
1306 }
1307 if( arg[1] & 8 )
1308 {
1309 hes_sparsity.binary_union( size_t(arg[5]), size_t(arg[5]), i_z, hes_sparsity);
1310 jac_reverse[ arg[5] ] |= jac_reverse[i_z];
1311 }
1312 return;
1313 }
1314
1315 } } // END_CPPAD_LOCAL_NAMESPACE
1316 # endif
+0
-238
include/cppad/local/cos_op.hpp less more
0 # ifndef CPPAD_LOCAL_COS_OP_HPP
1 # define CPPAD_LOCAL_COS_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file cos_op.hpp
18 Forward and reverse mode calculations for z = cos(x).
19 */
20
21 /*!
22 Compute forward mode Taylor coefficient for result of op = CosOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = cos(x)
27 \endverbatim
28 The auxillary result is
29 \verbatim
30 y = sin(x)
31 \endverbatim
32 The value of y, and its derivatives, are computed along with the value
33 and derivatives of z.
34
35 \copydetails CppAD::local::forward_unary2_op
36 */
37 template <class Base>
38 void forward_cos_op(
39 size_t p ,
40 size_t q ,
41 size_t i_z ,
42 size_t i_x ,
43 size_t cap_order ,
44 Base* taylor )
45 {
46 // check assumptions
47 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
48 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
49 CPPAD_ASSERT_UNKNOWN( q < cap_order );
50 CPPAD_ASSERT_UNKNOWN( p <= q );
51
52 // Taylor coefficients corresponding to argument and result
53 Base* x = taylor + i_x * cap_order;
54 Base* c = taylor + i_z * cap_order;
55 Base* s = c - cap_order;
56
57
58 // rest of this routine is identical for the following cases:
59 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op.
60 // (except that there is a sign difference for the hyperbolic case).
61 size_t k;
62 if( p == 0 )
63 { s[0] = sin( x[0] );
64 c[0] = cos( x[0] );
65 p++;
66 }
67 for(size_t j = p; j <= q; j++)
68 {
69 s[j] = Base(0.0);
70 c[j] = Base(0.0);
71 for(k = 1; k <= j; k++)
72 { s[j] += Base(double(k)) * x[k] * c[j-k];
73 c[j] -= Base(double(k)) * x[k] * s[j-k];
74 }
75 s[j] /= Base(double(j));
76 c[j] /= Base(double(j));
77 }
78 }
79 /*!
80 Compute forward mode Taylor coefficient for result of op = CosOp.
81
82 The C++ source code corresponding to this operation is
83 \verbatim
84 z = cos(x)
85 \endverbatim
86 The auxillary result is
87 \verbatim
88 y = sin(x)
89 \endverbatim
90 The value of y, and its derivatives, are computed along with the value
91 and derivatives of z.
92
93 \copydetails CppAD::local::forward_unary2_op_dir
94 */
95 template <class Base>
96 void forward_cos_op_dir(
97 size_t q ,
98 size_t r ,
99 size_t i_z ,
100 size_t i_x ,
101 size_t cap_order ,
102 Base* taylor )
103 {
104 // check assumptions
105 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
106 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
107 CPPAD_ASSERT_UNKNOWN( 0 < q );
108 CPPAD_ASSERT_UNKNOWN( q < cap_order );
109
110 // Taylor coefficients corresponding to argument and result
111 size_t num_taylor_per_var = (cap_order-1) * r + 1;
112 Base* x = taylor + i_x * num_taylor_per_var;
113 Base* c = taylor + i_z * num_taylor_per_var;
114 Base* s = c - num_taylor_per_var;
115
116
117 // rest of this routine is identical for the following cases:
118 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
119 // (except that there is a sign difference for the hyperbolic case).
120 size_t m = (q-1) * r + 1;
121 for(size_t ell = 0; ell < r; ell++)
122 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
123 c[m+ell] = - Base(double(q)) * x[m + ell] * s[0];
124 for(size_t k = 1; k < q; k++)
125 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
126 c[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
127 }
128 s[m+ell] /= Base(double(q));
129 c[m+ell] /= Base(double(q));
130 }
131 }
132
133 /*!
134 Compute zero order forward mode Taylor coefficient for result of op = CosOp.
135
136 The C++ source code corresponding to this operation is
137 \verbatim
138 z = cos(x)
139 \endverbatim
140 The auxillary result is
141 \verbatim
142 y = sin(x)
143 \endverbatim
144 The value of y is computed along with the value of z.
145
146 \copydetails CppAD::local::forward_unary2_op_0
147 */
148 template <class Base>
149 void forward_cos_op_0(
150 size_t i_z ,
151 size_t i_x ,
152 size_t cap_order ,
153 Base* taylor )
154 {
155 // check assumptions
156 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
157 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
158 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
159
160 // Taylor coefficients corresponding to argument and result
161 Base* x = taylor + i_x * cap_order;
162 Base* c = taylor + i_z * cap_order; // called z in documentation
163 Base* s = c - cap_order; // called y in documentation
164
165 c[0] = cos( x[0] );
166 s[0] = sin( x[0] );
167 }
168 /*!
169 Compute reverse mode partial derivatives for result of op = CosOp.
170
171 The C++ source code corresponding to this operation is
172 \verbatim
173 z = cos(x)
174 \endverbatim
175 The auxillary result is
176 \verbatim
177 y = sin(x)
178 \endverbatim
179 The value of y is computed along with the value of z.
180
181 \copydetails CppAD::local::reverse_unary2_op
182 */
183
184 template <class Base>
185 void reverse_cos_op(
186 size_t d ,
187 size_t i_z ,
188 size_t i_x ,
189 size_t cap_order ,
190 const Base* taylor ,
191 size_t nc_partial ,
192 Base* partial )
193 {
194 // check assumptions
195 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
196 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
197 CPPAD_ASSERT_UNKNOWN( d < cap_order );
198 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
199
200 // Taylor coefficients and partials corresponding to argument
201 const Base* x = taylor + i_x * cap_order;
202 Base* px = partial + i_x * nc_partial;
203
204 // Taylor coefficients and partials corresponding to first result
205 const Base* c = taylor + i_z * cap_order; // called z in doc
206 Base* pc = partial + i_z * nc_partial;
207
208 // Taylor coefficients and partials corresponding to auxillary result
209 const Base* s = c - cap_order; // called y in documentation
210 Base* ps = pc - nc_partial;
211
212
213 // rest of this routine is identical for the following cases:
214 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
215 size_t j = d;
216 size_t k;
217 while(j)
218 {
219 ps[j] /= Base(double(j));
220 pc[j] /= Base(double(j));
221 for(k = 1; k <= j; k++)
222 {
223 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
224 px[k] -= Base(double(k)) * azmul(pc[j], s[j-k]);
225
226 ps[j-k] -= Base(double(k)) * azmul(pc[j], x[k]);
227 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
228
229 }
230 --j;
231 }
232 px[0] += azmul(ps[0], c[0]);
233 px[0] -= azmul(pc[0], s[0]);
234 }
235
236 } } // END_CPPAD_LOCAL_NAMESPACE
237 # endif
+0
-238
include/cppad/local/cosh_op.hpp less more
0 # ifndef CPPAD_LOCAL_COSH_OP_HPP
1 # define CPPAD_LOCAL_COSH_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file cosh_op.hpp
18 Forward and reverse mode calculations for z = cosh(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = CoshOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = cosh(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = sinh(x)
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_cosh_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* c = taylor + i_z * cap_order;
56 Base* s = c - cap_order;
57
58 // rest of this routine is identical for the following cases:
59 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op.
60 // (except that there is a sign difference for hyperbolic case).
61 size_t k;
62 if( p == 0 )
63 { s[0] = sinh( x[0] );
64 c[0] = cosh( x[0] );
65 p++;
66 }
67 for(size_t j = p; j <= q; j++)
68 {
69 s[j] = Base(0.0);
70 c[j] = Base(0.0);
71 for(k = 1; k <= j; k++)
72 { s[j] += Base(double(k)) * x[k] * c[j-k];
73 c[j] += Base(double(k)) * x[k] * s[j-k];
74 }
75 s[j] /= Base(double(j));
76 c[j] /= Base(double(j));
77 }
78 }
79 /*!
80 Compute forward mode Taylor coefficient for result of op = CoshOp.
81
82 The C++ source code corresponding to this operation is
83 \verbatim
84 z = cosh(x)
85 \endverbatim
86 The auxillary result is
87 \verbatim
88 y = sinh(x)
89 \endverbatim
90 The value of y, and its derivatives, are computed along with the value
91 and derivatives of z.
92
93 \copydetails CppAD::local::forward_unary2_op_dir
94 */
95 template <class Base>
96 void forward_cosh_op_dir(
97 size_t q ,
98 size_t r ,
99 size_t i_z ,
100 size_t i_x ,
101 size_t cap_order ,
102 Base* taylor )
103 {
104 // check assumptions
105 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
106 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
107 CPPAD_ASSERT_UNKNOWN( 0 < q );
108 CPPAD_ASSERT_UNKNOWN( q < cap_order );
109
110 // Taylor coefficients corresponding to argument and result
111 size_t num_taylor_per_var = (cap_order-1) * r + 1;
112 Base* x = taylor + i_x * num_taylor_per_var;
113 Base* s = taylor + i_z * num_taylor_per_var;
114 Base* c = s - num_taylor_per_var;
115
116
117 // rest of this routine is identical for the following cases:
118 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
119 // (except that there is a sign difference for the hyperbolic case).
120 size_t m = (q-1) * r + 1;
121 for(size_t ell = 0; ell < r; ell++)
122 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
123 c[m+ell] = Base(double(q)) * x[m + ell] * s[0];
124 for(size_t k = 1; k < q; k++)
125 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
126 c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
127 }
128 s[m+ell] /= Base(double(q));
129 c[m+ell] /= Base(double(q));
130 }
131 }
132
133 /*!
134 Compute zero order forward mode Taylor coefficient for result of op = CoshOp.
135
136 The C++ source code corresponding to this operation is
137 \verbatim
138 z = cosh(x)
139 \endverbatim
140 The auxillary result is
141 \verbatim
142 y = sinh(x)
143 \endverbatim
144 The value of y is computed along with the value of z.
145
146 \copydetails CppAD::local::forward_unary2_op_0
147 */
148 template <class Base>
149 void forward_cosh_op_0(
150 size_t i_z ,
151 size_t i_x ,
152 size_t cap_order ,
153 Base* taylor )
154 {
155 // check assumptions
156 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
157 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
158 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
159
160 // Taylor coefficients corresponding to argument and result
161 Base* x = taylor + i_x * cap_order;
162 Base* c = taylor + i_z * cap_order; // called z in documentation
163 Base* s = c - cap_order; // called y in documentation
164
165 c[0] = cosh( x[0] );
166 s[0] = sinh( x[0] );
167 }
168 /*!
169 Compute reverse mode partial derivatives for result of op = CoshOp.
170
171 The C++ source code corresponding to this operation is
172 \verbatim
173 z = cosh(x)
174 \endverbatim
175 The auxillary result is
176 \verbatim
177 y = sinh(x)
178 \endverbatim
179 The value of y is computed along with the value of z.
180
181 \copydetails CppAD::local::reverse_unary2_op
182 */
183
184 template <class Base>
185 void reverse_cosh_op(
186 size_t d ,
187 size_t i_z ,
188 size_t i_x ,
189 size_t cap_order ,
190 const Base* taylor ,
191 size_t nc_partial ,
192 Base* partial )
193 {
194 // check assumptions
195 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
196 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
197 CPPAD_ASSERT_UNKNOWN( d < cap_order );
198 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
199
200 // Taylor coefficients and partials corresponding to argument
201 const Base* x = taylor + i_x * cap_order;
202 Base* px = partial + i_x * nc_partial;
203
204 // Taylor coefficients and partials corresponding to first result
205 const Base* c = taylor + i_z * cap_order; // called z in doc
206 Base* pc = partial + i_z * nc_partial;
207
208 // Taylor coefficients and partials corresponding to auxillary result
209 const Base* s = c - cap_order; // called y in documentation
210 Base* ps = pc - nc_partial;
211
212
213 // rest of this routine is identical for the following cases:
214 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
215 size_t j = d;
216 size_t k;
217 while(j)
218 {
219 ps[j] /= Base(double(j));
220 pc[j] /= Base(double(j));
221 for(k = 1; k <= j; k++)
222 {
223 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
224 px[k] += Base(double(k)) * azmul(pc[j], s[j-k]);
225
226 ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]);
227 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
228
229 }
230 --j;
231 }
232 px[0] += azmul(ps[0], c[0]);
233 px[0] += azmul(pc[0], s[0]);
234 }
235
236 } } // END_CPPAD_LOCAL_NAMESPACE
237 # endif
5858 This routine tries to minimize, with respect to the choice of colors,
5959 the number of colors.
6060 */
61 extern void cppad_colpack_general(
61 CPPAD_LIB_EXPORT void cppad_colpack_general(
6262 CppAD::vector<size_t>& color ,
6363 size_t m ,
6464 size_t n ,
9090 Efficient Computation of Sparse Hessians Using Coloring
9191 and Automatic Differentiation (pdf/ad/gebemedhin14.pdf)
9292 */
93 extern void cppad_colpack_symmetric(
93 CPPAD_LIB_EXPORT void cppad_colpack_symmetric(
9494 CppAD::vector<size_t>& color ,
9595 size_t n ,
9696 const CppAD::vector<unsigned int*>& adolc_pattern
+0
-199
include/cppad/local/cskip_op.hpp less more
0 # ifndef CPPAD_LOCAL_CSKIP_OP_HPP
1 # define CPPAD_LOCAL_CSKIP_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file cskip_op.hpp
17 Zero order forward mode set which operations to skip.
18 */
19
20 /*!
21 Zero order forward mode execution of op = CSkipOp.
22
23 \par Parameters and Variables
24 The terms parameter and variable depend on if we are referring to its
25 AD<Base> or Base value.
26 We use Base parameter and Base variable to refer to the
27 correspond Base value.
28 We use AD<Base> parameter and AD<Base> variable to refer to the
29 correspond AD<Base> value.
30
31 \tparam Base
32 base type for the operator; i.e., this operation was recorded
33 using AD<Base> and computations by this routine are done using type Base.
34
35 \param i_z
36 variable index corresponding to the result of the previous operation.
37 This is used for error checking. To be specific,
38 the left and right operands for the CExpOp operation must have indexes
39 less than or equal this value.
40
41 \param arg [in]
42 \n
43 arg[0]
44 is static cast to size_t from the enum type
45 \verbatim
46 enum CompareOp {
47 CompareLt,
48 CompareLe,
49 CompareEq,
50 CompareGe,
51 CompareGt,
52 CompareNe
53 }
54 \endverbatim
55 for this operation.
56 Note that arg[0] cannot be equal to CompareNe.
57 \n
58 \n
59 arg[1] & 1
60 \n
61 If this is zero, left is an AD<Base> parameter.
62 Otherwise it is an AD<Base> variable.
63 \n
64 \n
65 arg[1] & 2
66 \n
67 If this is zero, right is an AD<Base> parameter.
68 Otherwise it is an AD<Base> variable.
69 \n
70 arg[2]
71 is the index corresponding to left in comparison.
72 \n
73 arg[3]
74 is the index corresponding to right in comparison.
75 \n
76 arg[4]
77 is the number of operations to skip if the comparison result is true.
78 \n
79 arg[5]
80 is the number of operations to skip if the comparison result is false.
81 \n
82 <tt>arg[5+i]</tt>
83 for <tt>i = 1 , ... , arg[4]</tt> are the operations to skip if the
84 comparison result is true and both left and right are
85 identically Base parameters.
86 \n
87 <tt>arg[5+arg[4]+i]</tt>
88 for <tt>i = 1 , ... , arg[5]</tt> are the operations to skip if the
89 comparison result is false and both left and right are
90 identically Base parameters.
91
92 \param num_par [in]
93 is the total number of values in the vector parameter.
94
95 \param parameter [in]
96 If left is an AD<Base> parameter,
97 <code>parameter [ arg[2] ]</code> is its value.
98 If right is an AD<Base> parameter,
99 <code>parameter [ arg[3] ]</code> is its value.
100
101 \param cap_order [in]
102 number of columns in the matrix containing the Taylor coefficients.
103
104 \param taylor [in]
105 If left is an AD<Base> variable,
106 <code>taylor [ size_t(arg[2]) * cap_order + 0 ]</code>
107 is the zeroth order Taylor coefficient corresponding to left.
108 If right is an AD<Base> variable,
109 <code>taylor [ size_t(arg[3]) * cap_order + 0 ]</code>
110 is the zeroth order Taylor coefficient corresponding to right.
111
112 \param cskip_op [in,out]
113 is vector specifying which operations are at this point are know to be
114 unecessary and can be skipped.
115 This is both an input and an output.
116 */
117 template <class Base>
118 void forward_cskip_op_0(
119 size_t i_z ,
120 const addr_t* arg ,
121 size_t num_par ,
122 const Base* parameter ,
123 size_t cap_order ,
124 Base* taylor ,
125 bool* cskip_op )
126 {
127 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < size_t(CompareNe) );
128 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
129
130 Base left, right;
131 if( arg[1] & 1 )
132 { // If variable arg[2] <= i_z, it has already been computed,
133 // but it will be skipped for higher orders.
134 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) <= i_z );
135 left = taylor[ size_t(arg[2]) * cap_order + 0 ];
136 }
137 else
138 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
139 left = parameter[ arg[2] ];
140 }
141 if( arg[1] & 2 )
142 { // If variable arg[3] <= i_z, it has already been computed,
143 // but it will be skipped for higher orders.
144 CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= i_z );
145 right = taylor[ size_t(arg[3]) * cap_order + 0 ];
146 }
147 else
148 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
149 right = parameter[ arg[3] ];
150 }
151 bool ok_to_skip = IdenticalCon(left) & IdenticalCon(right);
152 if( ! ok_to_skip )
153 return;
154
155 // initialize to avoid compiler warning
156 bool true_case = false;
157 Base diff = left - right;
158 switch( CompareOp( arg[0] ) )
159 {
160 case CompareLt:
161 true_case = LessThanZero(diff);
162 break;
163
164 case CompareLe:
165 true_case = LessThanOrZero(diff);
166 break;
167
168 case CompareEq:
169 true_case = IdenticalZero(diff);
170 break;
171
172 case CompareGe:
173 true_case = GreaterThanOrZero(diff);
174 break;
175
176 case CompareGt:
177 true_case = GreaterThanZero(diff);
178 break;
179
180 case CompareNe:
181 true_case = ! IdenticalZero(diff);
182 break;
183
184 default:
185 CPPAD_ASSERT_UNKNOWN(false);
186 }
187 if( true_case )
188 { for(addr_t i = 0; i < arg[4]; i++)
189 cskip_op[ arg[6+i] ] = true;
190 }
191 else
192 { for(addr_t i = 0; i < arg[5]; i++)
193 cskip_op[ arg[6+arg[4]+i] ] = true;
194 }
195 return;
196 }
197 } } // END_CPPAD_LOCAL_NAMESPACE
198 # endif
+0
-612
include/cppad/local/csum_op.hpp less more
0 # ifndef CPPAD_LOCAL_CSUM_OP_HPP
1 # define CPPAD_LOCAL_CSUM_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file csum_op.hpp
17 Forward, reverse and sparsity calculations for cummulative summation.
18 */
19
20 /*!
21 Compute forward mode Taylor coefficients for result of op = CsumOp.
22
23 This operation is
24 \verbatim
25 z = s + x(0) + ... + x(n1-1) - y(0) - ... - y(n2-1)
26 + p(0) + ... + p(n3-1) - q(0) - ... - q(n4-1).
27 \endverbatim
28
29 \tparam Base
30 base type for the operator; i.e., this operation was recorded
31 using AD< Base > and computations by this routine are done using type
32 Base.
33
34 \param p
35 lowest order of the Taylor coefficient that we are computing.
36
37 \param q
38 highest order of the Taylor coefficient that we are computing.
39
40 \param i_z
41 variable index corresponding to the result for this operation;
42 i.e. the row index in taylor corresponding to z.
43
44 \param arg
45 -- arg[0]
46 parameter[arg[0]] is the parameter value s in this cummunative summation.
47
48 -- arg[1]
49 end in arg of addition variables in summation.
50 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(n1-1)
51
52 -- arg[2]
53 end in arg of subtraction variables in summation.
54 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n2-1)
55
56 -- arg[3]
57 end in arg of addition dynamic parameters in summation.
58 arg[arg[2]] , ... , arg[arg[3]-1] correspond to p(0), ... , p(n3-1)
59
60 -- arg[4]
61 end in arg of subtraction dynamic parameters in summation.
62 arg[arg[3]] , ... , arg[arg[4]-1] correspond to q(0), ... , q(n4-1)
63
64 \param num_par
65 is the number of parameters in parameter.
66
67 \param parameter
68 is the parameter vector for this operation sequence.
69
70 \param cap_order
71 number of colums in the matrix containing all the Taylor coefficients.
72
73 \param taylor
74 \b Input: taylor [ arg[5+i] * cap_order + k ]
75 for i = 0, ..., n1-1
76 and k = 0 , ... , q
77 is the k-th order Taylor coefficient corresponding to x(i)
78 \n
79 \b Input: taylor [ arg[arg[1]+1] * cap_order + k ]
80 for i = 0, ..., n2-1
81 and k = 0 , ... , q
82 is the k-th order Taylor coefficient corresponding to y(i)
83 \n
84 \b Input: taylor [ i_z * cap_order + k ]
85 for k = 0 , ... , p,
86 is the k-th order Taylor coefficient corresponding to z.
87 \n
88 \b Output: taylor [ i_z * cap_order + k ]
89 for k = p , ... , q,
90 is the k-th order Taylor coefficient corresponding to z.
91 */
92 template <class Base>
93 void forward_csum_op(
94 size_t p ,
95 size_t q ,
96 size_t i_z ,
97 const addr_t* arg ,
98 size_t num_par ,
99 const Base* parameter ,
100 size_t cap_order ,
101 Base* taylor )
102 { Base zero(0);
103
104 // check assumptions
105 CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 );
106 CPPAD_ASSERT_UNKNOWN( q < cap_order );
107 CPPAD_ASSERT_UNKNOWN( p <= q );
108 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par );
109 CPPAD_ASSERT_UNKNOWN(
110 arg[arg[4]] == arg[4]
111 );
112
113 // Taylor coefficients corresponding to result
114 Base* z = taylor + i_z * cap_order;
115 for(size_t k = p; k <= q; k++)
116 z[k] = zero;
117 if( p == 0 )
118 { // normal parameters in the sum
119 z[p] = parameter[ arg[0] ];
120 // addition dynamic parameters
121 for(size_t i = size_t(arg[2]); i < size_t(arg[3]); ++i)
122 z[p] += parameter[ arg[i] ];
123 // subtraction dynamic parameters
124 for(size_t i = size_t(arg[3]); i < size_t(arg[4]); ++i)
125 z[p] -= parameter[ arg[i] ];
126 }
127 Base* x;
128 for(size_t i = 5; i < size_t(arg[1]); ++i)
129 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
130 x = taylor + size_t(arg[i]) * cap_order;
131 for(size_t k = p; k <= q; k++)
132 z[k] += x[k];
133 }
134 for(size_t i = size_t(arg[1]); i < size_t(arg[2]); ++i)
135 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
136 x = taylor + size_t(arg[i]) * cap_order;
137 for(size_t k = p; k <= q; k++)
138 z[k] -= x[k];
139 }
140 }
141
142 /*!
143 Multiple direction forward mode Taylor coefficients for op = CsumOp.
144
145 This operation is
146 \verbatim
147 z = s + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
148 \endverbatim
149
150 \tparam Base
151 base type for the operator; i.e., this operation was recorded
152 using AD<Base> and computations by this routine are done using type
153 Base.
154
155 \param q
156 order ot the Taylor coefficients that we are computing.
157
158 \param r
159 number of directions for Taylor coefficients that we are computing.
160
161 \param i_z
162 variable index corresponding to the result for this operation;
163 i.e. the row index in taylor corresponding to z.
164
165 \param arg
166 -- arg[0]
167 parameter[arg[0]] is the parameter value s in this cummunative summation.
168
169 -- arg[1]
170 end in arg of addition variables in summation.
171 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
172
173 -- arg[2]
174 end in arg of subtraction variables in summation.
175 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
176
177 -- arg[3]
178 end in arg of addition dynamic parameters in summation.
179
180 -- arg[4]
181 end in arg of subtraction dynamic parameters in summation.
182
183 \param num_par
184 is the number of parameters in parameter.
185
186 \param parameter
187 is the parameter vector for this operation sequence.
188
189 \param cap_order
190 number of colums in the matrix containing all the Taylor coefficients.
191
192 \param taylor
193 \b Input: taylor [ arg[5+i]*((cap_order-1)*r + 1) + 0 ]
194 for i = 0, ..., m-1
195 is the 0-th order Taylor coefficient corresponding to x(i) and
196 taylor [ arg[5+i]*((cap_order-1)*r + 1) + (q-1)*r + ell + 1 ]
197 for i = 0, ..., m-1,
198 ell = 0 , ... , r-1
199 is the q-th order Taylor coefficient corresponding to x(i)
200 and direction ell.
201 \n
202 \b Input: taylor [ arg[arg[1]+1]*((cap_order-1)*r + 1) + 0 ]
203 for i = 0, ..., n-1
204 is the 0-th order Taylor coefficient corresponding to y(i) and
205 taylor [ arg[arg[1]+1]*((cap_order-1)*r + 1) + (q-1)*r + ell + 1 ]
206 for i = 0, ..., n-1,
207 ell = 0 , ... , r-1
208 is the q-th order Taylor coefficient corresponding to y(i)
209 and direction ell.
210 \n
211 \b Output: taylor [ i_z*((cap_order-1)*r+1) + (q-1)*r + ell + 1 ]
212 is the q-th order Taylor coefficient corresponding to z
213 for direction ell = 0 , ... , r-1.
214 */
215 template <class Base>
216 void forward_csum_op_dir(
217 size_t q ,
218 size_t r ,
219 size_t i_z ,
220 const addr_t* arg ,
221 size_t num_par ,
222 const Base* parameter ,
223 size_t cap_order ,
224 Base* taylor )
225 { Base zero(0);
226
227 // check assumptions
228 CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 );
229 CPPAD_ASSERT_UNKNOWN( q < cap_order );
230 CPPAD_ASSERT_UNKNOWN( 0 < q );
231 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par );
232 CPPAD_ASSERT_UNKNOWN(
233 arg[arg[4]] == arg[4]
234 );
235
236 // Taylor coefficients corresponding to result
237 size_t num_taylor_per_var = (cap_order-1) * r + 1;
238 size_t m = (q-1)*r + 1;
239 Base* z = taylor + i_z * num_taylor_per_var + m;
240 for(size_t ell = 0; ell < r; ell++)
241 z[ell] = zero;
242 Base* x;
243 for(size_t i = 5; i < size_t(arg[1]); ++i)
244 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
245 x = taylor + size_t(arg[i]) * num_taylor_per_var + m;
246 for(size_t ell = 0; ell < r; ell++)
247 z[ell] += x[ell];
248 }
249 for(size_t i = size_t(arg[1]); i < size_t(arg[2]); ++i)
250 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
251 x = taylor + size_t(arg[i]) * num_taylor_per_var + m;
252 for(size_t ell = 0; ell < r; ell++)
253 z[ell] -= x[ell];
254 }
255 }
256
257 /*!
258 Compute reverse mode Taylor coefficients for result of op = CsumOp.
259
260 This operation is
261 \verbatim
262 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
263 H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ]
264 \endverbatim
265
266 \tparam Base
267 base type for the operator; i.e., this operation was recorded
268 using AD< Base > and computations by this routine are done using type
269 Base.
270
271 \param d
272 order the highest order Taylor coefficient that we are computing
273 the partial derivatives with respect to.
274
275 \param i_z
276 variable index corresponding to the result for this operation;
277 i.e. the row index in taylor corresponding to z.
278
279 \param arg
280 -- arg[0]
281 parameter[arg[0]] is the parameter value s in this cummunative summation.
282
283 -- arg[1]
284 end in arg of addition variables in summation.
285 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
286
287 -- arg[2]
288 end in arg of subtraction variables in summation.
289 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
290
291 -- arg[3]
292 end in arg of addition dynamic parameters in summation.
293
294 -- arg[4]
295 end in arg of subtraction dynamic parameters in summation.
296
297 \param nc_partial
298 number of colums in the matrix containing all the partial derivatives.
299
300 \param partial
301 \b Input: partial [ arg[5+i] * nc_partial + k ]
302 for i = 0, ..., m-1
303 and k = 0 , ... , d
304 is the partial derivative of G(z, y, x, w, ...) with respect to the
305 k-th order Taylor coefficient corresponding to x(i)
306 \n
307 \b Input: partial [ arg[arg[1]+1] * nc_partial + k ]
308 for i = 0, ..., n-1
309 and k = 0 , ... , d
310 is the partial derivative of G(z, y, x, w, ...) with respect to the
311 k-th order Taylor coefficient corresponding to y(i)
312 \n
313 \b Input: partial [ i_z * nc_partial + k ]
314 for i = 0, ..., n-1
315 and k = 0 , ... , d
316 is the partial derivative of G(z, y, x, w, ...) with respect to the
317 k-th order Taylor coefficient corresponding to z.
318 \n
319 \b Output: partial [ arg[5+i] * nc_partial + k ]
320 for i = 0, ..., m-1
321 and k = 0 , ... , d
322 is the partial derivative of H(y, x, w, ...) with respect to the
323 k-th order Taylor coefficient corresponding to x(i)
324 \n
325 \b Output: partial [ arg[arg[1]+1] * nc_partial + k ]
326 for i = 0, ..., n-1
327 and k = 0 , ... , d
328 is the partial derivative of H(y, x, w, ...) with respect to the
329 k-th order Taylor coefficient corresponding to y(i)
330 */
331
332 template <class Base>
333 void reverse_csum_op(
334 size_t d ,
335 size_t i_z ,
336 const addr_t* arg ,
337 size_t nc_partial ,
338 Base* partial )
339 {
340 // check assumptions
341 CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 );
342 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
343
344 // Taylor coefficients and partial derivative corresponding to result
345 Base* pz = partial + i_z * nc_partial;
346 Base* px;
347 size_t d1 = d + 1;
348 for(size_t i = 5; i < size_t(arg[1]); ++i)
349 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
350 px = partial + size_t(arg[i]) * nc_partial;
351 size_t k = d1;
352 while(k--)
353 px[k] += pz[k];
354 }
355 for(size_t i = size_t(arg[1]); i < size_t(arg[2]); ++i)
356 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
357 px = partial + size_t(arg[i]) * nc_partial;
358 size_t k = d1;
359 while(k--)
360 px[k] -= pz[k];
361 }
362 }
363
364
365 /*!
366 Forward mode Jacobian sparsity pattern for CSumOp operator.
367
368 This operation is
369 \verbatim
370 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
371 \endverbatim
372
373 \tparam Vector_set
374 is the type used for vectors of sets. It can be either
375 sparse::pack_setvec or sparse::list_setvec.
376
377 \param i_z
378 variable index corresponding to the result for this operation;
379 i.e. the index in sparsity corresponding to z.
380
381 \param arg
382 -- arg[0]
383 parameter[arg[0]] is the parameter value s in this cummunative summation.
384
385 -- arg[1]
386 end in arg of addition variables in summation.
387 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
388
389 -- arg[2]
390 end in arg of subtraction variables in summation.
391 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
392
393 -- arg[3]
394 end in arg of addition dynamic parameters in summation.
395
396 -- arg[4]
397 end in arg of subtraction dynamic parameters in summation.
398
399 \param sparsity
400 \b Input:
401 For i = 0, ..., m-1,
402 the set with index arg[5+i] in sparsity
403 is the sparsity bit pattern for x(i).
404 This identifies which of the independent variables the variable
405 x(i) depends on.
406 \n
407 \b Input:
408 For i = 0, ..., n-1,
409 the set with index arg[2+arg[0]+i] in sparsity
410 is the sparsity bit pattern for x(i).
411 This identifies which of the independent variables the variable
412 y(i) depends on.
413 \n
414 \b Output:
415 The set with index i_z in sparsity
416 is the sparsity bit pattern for z.
417 This identifies which of the independent variables the variable z
418 depends on.
419 */
420
421 template <class Vector_set>
422 void forward_sparse_jacobian_csum_op(
423 size_t i_z ,
424 const addr_t* arg ,
425 Vector_set& sparsity )
426 { sparsity.clear(i_z);
427
428 for(size_t i = 5; i < size_t(arg[2]); ++i)
429 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
430 sparsity.binary_union(
431 i_z , // index in sparsity for result
432 i_z , // index in sparsity for left operand
433 size_t(arg[i]), // index for right operand
434 sparsity // sparsity vector for right operand
435 );
436 }
437 }
438
439 /*!
440 Reverse mode Jacobian sparsity pattern for CSumOp operator.
441
442 This operation is
443 \verbatim
444 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
445 H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ]
446 \endverbatim
447
448 \tparam Vector_set
449 is the type used for vectors of sets. It can be either
450 sparse::pack_setvec or sparse::list_setvec.
451
452 \param i_z
453 variable index corresponding to the result for this operation;
454 i.e. the index in sparsity corresponding to z.
455
456 \param arg
457 -- arg[0]
458 parameter[arg[0]] is the parameter value s in this cummunative summation.
459
460 -- arg[1]
461 end in arg of addition variables in summation.
462 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
463
464 -- arg[2]
465 end in arg of subtraction variables in summation.
466 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
467
468 -- arg[3]
469 end in arg of addition dynamic parameters in summation.
470
471 -- arg[4]
472 end in arg of subtraction dynamic parameters in summation.
473
474 \param sparsity
475 For i = 0, ..., m-1,
476 the set with index arg[5+i] in sparsity
477 is the sparsity bit pattern for x(i).
478 This identifies which of the dependent variables depend on x(i).
479 On input, the sparsity patter corresponds to G,
480 and on ouput it corresponds to H.
481 \n
482 For i = 0, ..., m-1,
483 the set with index arg[2+arg[0]+i] in sparsity
484 is the sparsity bit pattern for y(i).
485 This identifies which of the dependent variables depend on y(i).
486 On input, the sparsity patter corresponds to G,
487 and on ouput it corresponds to H.
488 \n
489 \b Input:
490 The set with index i_z in sparsity
491 is the sparsity bit pattern for z.
492 On input it corresponds to G and on output it is undefined.
493 */
494
495 template <class Vector_set>
496 void reverse_sparse_jacobian_csum_op(
497 size_t i_z ,
498 const addr_t* arg ,
499 Vector_set& sparsity )
500 {
501 for(size_t i = 5; i < size_t(arg[2]); ++i)
502 {
503 CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
504 sparsity.binary_union(
505 size_t(arg[i]), // index in sparsity for result
506 size_t(arg[i]), // index in sparsity for left operand
507 i_z , // index for right operand
508 sparsity // sparsity vector for right operand
509 );
510 }
511 }
512 /*!
513 Reverse mode Hessian sparsity pattern for CSumOp operator.
514
515 This operation is
516 \verbatim
517 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
518 H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ]
519 \endverbatim
520
521 \tparam Vector_set
522 is the type used for vectors of sets. It can be either
523 sparse::pack_setvec or sparse::list_setvec.
524
525 \param i_z
526 variable index corresponding to the result for this operation;
527 i.e. the index in sparsity corresponding to z.
528
529 \param arg
530 -- arg[0]
531 parameter[arg[0]] is the parameter value s in this cummunative summation.
532
533 -- arg[1]
534 end in arg of addition variables in summation.
535 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
536
537 -- arg[2]
538 end in arg of subtraction variables in summation.
539 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
540
541 -- arg[3]
542 end in arg of addition dynamic parameters in summation.
543
544 -- arg[4]
545 end in arg of subtraction dynamic parameters in summation.
546
547 \param rev_jacobian
548 rev_jacobian[i_z]
549 is all false (true) if the Jabobian of G with respect to z must be zero
550 (may be non-zero).
551 \n
552 \n
553 For i = 0, ..., m-1
554 rev_jacobian[ arg[5+i] ]
555 is all false (true) if the Jacobian with respect to x(i)
556 is zero (may be non-zero).
557 On input, it corresponds to the function G,
558 and on output it corresponds to the function H.
559 \n
560 \n
561 For i = 0, ..., n-1
562 rev_jacobian[ arg[2+arg[0]+i] ]
563 is all false (true) if the Jacobian with respect to y(i)
564 is zero (may be non-zero).
565 On input, it corresponds to the function G,
566 and on output it corresponds to the function H.
567
568 \param rev_hes_sparsity
569 The set with index i_z in in rev_hes_sparsity
570 is the Hessian sparsity pattern for the fucntion G
571 where one of the partials derivative is with respect to z.
572 \n
573 \n
574 For i = 0, ..., m-1
575 The set with index arg[5+i] in rev_hes_sparsity
576 is the Hessian sparsity pattern
577 where one of the partials derivative is with respect to x(i).
578 On input, it corresponds to the function G,
579 and on output it corresponds to the function H.
580 \n
581 \n
582 For i = 0, ..., n-1
583 The set with index arg[2+arg[0]+i] in rev_hes_sparsity
584 is the Hessian sparsity pattern
585 where one of the partials derivative is with respect to y(i).
586 On input, it corresponds to the function G,
587 and on output it corresponds to the function H.
588 */
589
590 template <class Vector_set>
591 void reverse_sparse_hessian_csum_op(
592 size_t i_z ,
593 const addr_t* arg ,
594 bool* rev_jacobian ,
595 Vector_set& rev_hes_sparsity )
596 {
597 for(size_t i = 5; i < size_t(arg[2]); ++i)
598 {
599 CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
600 rev_hes_sparsity.binary_union(
601 size_t(arg[i]), // index in sparsity for result
602 size_t(arg[i]), // index in sparsity for left operand
603 i_z , // index for right operand
604 rev_hes_sparsity // sparsity vector for right operand
605 );
606 rev_jacobian[arg[i]] |= rev_jacobian[i_z];
607 }
608 }
609
610 } } // END_CPPAD_LOCAL_NAMESPACE
611 # endif
00 # ifndef CPPAD_LOCAL_DEFINE_HPP
11 # define CPPAD_LOCAL_DEFINE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
6060 Special macro for exporting windows DLL symbols; see
6161 https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/BuildingWinDLL
6262 */
63 /*
64 This commented out code is for building windows shared libraries which
65 currently does not work for CppAD:
6366 # ifdef _MSC_VER
6467 # ifdef cppad_lib_EXPORTS
6568 # define CPPAD_LIB_EXPORT __declspec(dllexport)
6972 # else // _MSC_VER
7073 # define CPPAD_LIB_EXPORT
7174 # endif
72
75 */
76 # define CPPAD_LIB_EXPORT
7377
7478 // ============================================================================
7579 /*!
+0
-121
include/cppad/local/discrete_op.hpp less more
0 # ifndef CPPAD_LOCAL_DISCRETE_OP_HPP
1 # define CPPAD_LOCAL_DISCRETE_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file discrete_op.hpp
18 Forward mode for z = f(x) where f is piecewise constant.
19 */
20
21
22 /*!
23 forward mode Taylor coefficient for result of op = DisOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = f(x)
28 \endverbatim
29 where f is a piecewise constant function (and it's derivative is always
30 calculated as zero).
31
32 \tparam Base
33 base type for the operator; i.e., this operation was recorded
34 using AD< Base > and computations by this routine are done using type
35 Base .
36
37 \param p
38 is the lowest order Taylor coefficient that will be calculated.
39
40 \param q
41 is the highest order Taylor coefficient that will be calculated.
42
43 \param r
44 is the number of directions, for each order,
45 that will be calculated (except for order zero wich only has one direction).
46
47 \param i_z
48 variable index corresponding to the result for this operation;
49 i.e. the row index in taylor corresponding to z.
50
51 \param arg
52 arg[0]
53 \n
54 is the index, in the order of the discrete functions defined by the user,
55 for this discrete function.
56 \n
57 \n
58 arg[1]
59 variable index corresponding to the argument for this operator;
60 i.e. the row index in taylor corresponding to x.
61
62 \param cap_order
63 maximum number of orders that will fit in the taylor array.
64
65 \par tpv
66 We use the notation
67 <code>tpv = (cap_order-1) * r + 1</code>
68 which is the number of Taylor coefficients per variable
69
70 \param taylor
71 \b Input: <code>taylor [ arg[1] * tpv + 0 ]</code>
72 is the zero order Taylor coefficient corresponding to x.
73 \n
74 \b Output: if <code>p == 0</code>
75 <code>taylor [ i_z * tpv + 0 ]</code>
76 is the zero order Taylor coefficient corresponding to z.
77 For k = max(p, 1), ... , q,
78 <code>taylor [ i_z * tpv + (k-1)*r + 1 + ell ]</code>
79 is the k-th order Taylor coefficient corresponding to z
80 (which is zero).
81
82 \par Checked Assertions where op is the unary operator with one result:
83 \li NumArg(op) == 2
84 \li NumRes(op) == 1
85 \li q < cap_order
86 \li 0 < r
87 */
88 template <class Base>
89 void forward_dis_op(
90 size_t p ,
91 size_t q ,
92 size_t r ,
93 size_t i_z ,
94 const addr_t* arg ,
95 size_t cap_order ,
96 Base* taylor )
97 {
98 // check assumptions
99 CPPAD_ASSERT_UNKNOWN( NumArg(DisOp) == 2 );
100 CPPAD_ASSERT_UNKNOWN( NumRes(DisOp) == 1 );
101 CPPAD_ASSERT_UNKNOWN( q < cap_order );
102 CPPAD_ASSERT_UNKNOWN( 0 < r );
103
104 // Taylor coefficients corresponding to argument and result
105 size_t num_taylor_per_var = (cap_order-1) * r + 1;
106 Base* x = taylor + size_t(arg[1]) * num_taylor_per_var;
107 Base* z = taylor + i_z * num_taylor_per_var;
108
109 if( p == 0 )
110 { z[0] = discrete<Base>::eval(size_t(arg[0]), x[0]);
111 p++;
112 }
113 for(size_t ell = 0; ell < r; ell++)
114 for(size_t k = p; k <= q; k++)
115 z[ (k-1) * r + 1 + ell ] = Base(0.0);
116 }
117
118
119 } } // END_CPPAD_LOCAL_NAMESPACE
120 # endif
+0
-574
include/cppad/local/div_op.hpp less more
0 # ifndef CPPAD_LOCAL_DIV_OP_HPP
1 # define CPPAD_LOCAL_DIV_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file div_op.hpp
17 Forward and reverse mode calculations for z = x / y.
18 */
19
20 // --------------------------- Divvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = DivvvOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = x / y
27 \endverbatim
28 In the documentation below,
29 this operations is for the case where both x and y are variables
30 and the argument parameter is not used.
31
32 \copydetails CppAD::local::forward_binary_op
33 */
34
35 template <class Base>
36 void forward_divvv_op(
37 size_t p ,
38 size_t q ,
39 size_t i_z ,
40 const addr_t* arg ,
41 const Base* parameter ,
42 size_t cap_order ,
43 Base* taylor )
44 {
45 // check assumptions
46 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
47 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
48 CPPAD_ASSERT_UNKNOWN( q < cap_order );
49 CPPAD_ASSERT_UNKNOWN( p <= q );
50
51 // Taylor coefficients corresponding to arguments and result
52 Base* x = taylor + size_t(arg[0]) * cap_order;
53 Base* y = taylor + size_t(arg[1]) * cap_order;
54 Base* z = taylor + i_z * cap_order;
55
56
57 // Using CondExp, it can make sense to divide by zero,
58 // so do not make it an error.
59 size_t k;
60 for(size_t d = p; d <= q; d++)
61 { z[d] = x[d];
62 for(k = 1; k <= d; k++)
63 z[d] -= z[d-k] * y[k];
64 z[d] /= y[0];
65 }
66 }
67 /*!
68 Multiple directions forward mode Taylor coefficients for op = DivvvOp.
69
70 The C++ source code corresponding to this operation is
71 \verbatim
72 z = x / y
73 \endverbatim
74 In the documentation below,
75 this operations is for the case where both x and y are variables
76 and the argument parameter is not used.
77
78 \copydetails CppAD::local::forward_binary_op_dir
79 */
80
81 template <class Base>
82 void forward_divvv_op_dir(
83 size_t q ,
84 size_t r ,
85 size_t i_z ,
86 const addr_t* arg ,
87 const Base* parameter ,
88 size_t cap_order ,
89 Base* taylor )
90 {
91 // check assumptions
92 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
93 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
94 CPPAD_ASSERT_UNKNOWN( 0 < q );
95 CPPAD_ASSERT_UNKNOWN( q < cap_order );
96
97 // Taylor coefficients corresponding to arguments and result
98 size_t num_taylor_per_var = (cap_order-1) * r + 1;
99 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
100 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
101 Base* z = taylor + i_z * num_taylor_per_var;
102
103
104 // Using CondExp, it can make sense to divide by zero,
105 // so do not make it an error.
106 size_t m = (q-1) * r + 1;
107 for(size_t ell = 0; ell < r; ell++)
108 { z[m+ell] = x[m+ell] - z[0] * y[m+ell];
109 for(size_t k = 1; k < q; k++)
110 z[m+ell] -= z[(q-k-1)*r+1+ell] * y[(k-1)*r+1+ell];
111 z[m+ell] /= y[0];
112 }
113 }
114
115
116 /*!
117 Compute zero order forward mode Taylor coefficients for result of op = DivvvOp.
118
119 The C++ source code corresponding to this operation is
120 \verbatim
121 z = x / y
122 \endverbatim
123 In the documentation below,
124 this operations is for the case where both x and y are variables
125 and the argument parameter is not used.
126
127 \copydetails CppAD::local::forward_binary_op_0
128 */
129
130 template <class Base>
131 void forward_divvv_op_0(
132 size_t i_z ,
133 const addr_t* arg ,
134 const Base* parameter ,
135 size_t cap_order ,
136 Base* taylor )
137 {
138 // check assumptions
139 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
140 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
141
142 // Taylor coefficients corresponding to arguments and result
143 Base* x = taylor + size_t(arg[0]) * cap_order;
144 Base* y = taylor + size_t(arg[1]) * cap_order;
145 Base* z = taylor + i_z * cap_order;
146
147 z[0] = x[0] / y[0];
148 }
149
150 /*!
151 Compute reverse mode partial derivatives for result of op = DivvvOp.
152
153 The C++ source code corresponding to this operation is
154 \verbatim
155 z = x / y
156 \endverbatim
157 In the documentation below,
158 this operations is for the case where both x and y are variables
159 and the argument parameter is not used.
160
161 \copydetails CppAD::local::reverse_binary_op
162 */
163
164 template <class Base>
165 void reverse_divvv_op(
166 size_t d ,
167 size_t i_z ,
168 const addr_t* arg ,
169 const Base* parameter ,
170 size_t cap_order ,
171 const Base* taylor ,
172 size_t nc_partial ,
173 Base* partial )
174 {
175 // check assumptions
176 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
177 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
178 CPPAD_ASSERT_UNKNOWN( d < cap_order );
179 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
180
181 // Arguments
182 const Base* y = taylor + size_t(arg[1]) * cap_order;
183 const Base* z = taylor + i_z * cap_order;
184
185 // Partial derivatives corresponding to arguments and result
186 Base* px = partial + size_t(arg[0]) * nc_partial;
187 Base* py = partial + size_t(arg[1]) * nc_partial;
188 Base* pz = partial + i_z * nc_partial;
189
190 // Using CondExp, it can make sense to divide by zero
191 // so do not make it an error.
192 Base inv_y0 = Base(1.0) / y[0];
193
194 size_t k;
195 // number of indices to access
196 size_t j = d + 1;
197 while(j)
198 { --j;
199 // scale partial w.r.t. z[j]
200 pz[j] = azmul(pz[j], inv_y0);
201
202 px[j] += pz[j];
203 for(k = 1; k <= j; k++)
204 { pz[j-k] -= azmul(pz[j], y[k] );
205 py[k] -= azmul(pz[j], z[j-k]);
206 }
207 py[0] -= azmul(pz[j], z[j]);
208 }
209 }
210
211 // --------------------------- Divpv -----------------------------------------
212 /*!
213 Compute forward mode Taylor coefficients for result of op = DivpvOp.
214
215 The C++ source code corresponding to this operation is
216 \verbatim
217 z = x / y
218 \endverbatim
219 In the documentation below,
220 this operations is for the case where x is a parameter and y is a variable.
221
222 \copydetails CppAD::local::forward_binary_op
223 */
224
225 template <class Base>
226 void forward_divpv_op(
227 size_t p ,
228 size_t q ,
229 size_t i_z ,
230 const addr_t* arg ,
231 const Base* parameter ,
232 size_t cap_order ,
233 Base* taylor )
234 {
235 // check assumptions
236 CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
237 CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
238 CPPAD_ASSERT_UNKNOWN( q < cap_order );
239 CPPAD_ASSERT_UNKNOWN( p <= q );
240
241 // Taylor coefficients corresponding to arguments and result
242 Base* y = taylor + size_t(arg[1]) * cap_order;
243 Base* z = taylor + i_z * cap_order;
244
245 // Paraemter value
246 Base x = parameter[ arg[0] ];
247
248 // Using CondExp, it can make sense to divide by zero,
249 // so do not make it an error.
250 size_t k;
251 if( p == 0 )
252 { z[0] = x / y[0];
253 p++;
254 }
255 for(size_t d = p; d <= q; d++)
256 { z[d] = Base(0.0);
257 for(k = 1; k <= d; k++)
258 z[d] -= z[d-k] * y[k];
259 z[d] /= y[0];
260 }
261 }
262 /*!
263 Multiple directions forward mode Taylor coefficients for op = DivpvOp.
264
265 The C++ source code corresponding to this operation is
266 \verbatim
267 z = x / y
268 \endverbatim
269 In the documentation below,
270 this operations is for the case where x is a parameter and y is a variable.
271
272 \copydetails CppAD::local::forward_binary_op_dir
273 */
274
275 template <class Base>
276 void forward_divpv_op_dir(
277 size_t q ,
278 size_t r ,
279 size_t i_z ,
280 const addr_t* arg ,
281 const Base* parameter ,
282 size_t cap_order ,
283 Base* taylor )
284 {
285 // check assumptions
286 CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
287 CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
288 CPPAD_ASSERT_UNKNOWN( 0 < q );
289 CPPAD_ASSERT_UNKNOWN( q < cap_order );
290
291 // Taylor coefficients corresponding to arguments and result
292 size_t num_taylor_per_var = (cap_order-1) * r + 1;
293 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
294 Base* z = taylor + i_z * num_taylor_per_var;
295
296 // Using CondExp, it can make sense to divide by zero,
297 // so do not make it an error.
298 size_t m = (q-1) * r + 1;
299 for(size_t ell = 0; ell < r; ell++)
300 { z[m+ell] = - z[0] * y[m+ell];
301 for(size_t k = 1; k < q; k++)
302 z[m+ell] -= z[(q-k-1)*r+1+ell] * y[(k-1)*r+1+ell];
303 z[m+ell] /= y[0];
304 }
305 }
306
307 /*!
308 Compute zero order forward mode Taylor coefficient for result of op = DivpvOp.
309
310 The C++ source code corresponding to this operation is
311 \verbatim
312 z = x / y
313 \endverbatim
314 In the documentation below,
315 this operations is for the case where x is a parameter and y is a variable.
316
317 \copydetails CppAD::local::forward_binary_op_0
318 */
319
320 template <class Base>
321 void forward_divpv_op_0(
322 size_t i_z ,
323 const addr_t* arg ,
324 const Base* parameter ,
325 size_t cap_order ,
326 Base* taylor )
327 {
328 // check assumptions
329 CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
330 CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
331
332 // Paraemter value
333 Base x = parameter[ arg[0] ];
334
335 // Taylor coefficients corresponding to arguments and result
336 Base* y = taylor + size_t(arg[1]) * cap_order;
337 Base* z = taylor + i_z * cap_order;
338
339 z[0] = x / y[0];
340 }
341
342 /*!
343 Compute reverse mode partial derivative for result of op = DivpvOp.
344
345 The C++ source code corresponding to this operation is
346 \verbatim
347 z = x / y
348 \endverbatim
349 In the documentation below,
350 this operations is for the case where x is a parameter and y is a variable.
351
352 \copydetails CppAD::local::reverse_binary_op
353 */
354
355 template <class Base>
356 void reverse_divpv_op(
357 size_t d ,
358 size_t i_z ,
359 const addr_t* arg ,
360 const Base* parameter ,
361 size_t cap_order ,
362 const Base* taylor ,
363 size_t nc_partial ,
364 Base* partial )
365 {
366 // check assumptions
367 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
368 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
369 CPPAD_ASSERT_UNKNOWN( d < cap_order );
370 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
371
372 // Arguments
373 const Base* y = taylor + size_t(arg[1]) * cap_order;
374 const Base* z = taylor + i_z * cap_order;
375
376 // Partial derivatives corresponding to arguments and result
377 Base* py = partial + size_t(arg[1]) * nc_partial;
378 Base* pz = partial + i_z * nc_partial;
379
380 // Using CondExp, it can make sense to divide by zero so do not
381 // make it an error.
382 Base inv_y0 = Base(1.0) / y[0];
383
384 size_t k;
385 // number of indices to access
386 size_t j = d + 1;
387 while(j)
388 { --j;
389 // scale partial w.r.t z[j]
390 pz[j] = azmul(pz[j], inv_y0);
391
392 for(k = 1; k <= j; k++)
393 { pz[j-k] -= azmul(pz[j], y[k] );
394 py[k] -= azmul(pz[j], z[j-k] );
395 }
396 py[0] -= azmul(pz[j], z[j]);
397 }
398 }
399
400
401 // --------------------------- Divvp -----------------------------------------
402 /*!
403 Compute forward mode Taylor coefficients for result of op = DivvvOp.
404
405 The C++ source code corresponding to this operation is
406 \verbatim
407 z = x / y
408 \endverbatim
409 In the documentation below,
410 this operations is for the case where x is a variable and y is a parameter.
411
412 \copydetails CppAD::local::forward_binary_op
413 */
414
415 template <class Base>
416 void forward_divvp_op(
417 size_t p ,
418 size_t q ,
419 size_t i_z ,
420 const addr_t* arg ,
421 const Base* parameter ,
422 size_t cap_order ,
423 Base* taylor )
424 {
425 // check assumptions
426 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
427 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
428 CPPAD_ASSERT_UNKNOWN( q < cap_order );
429 CPPAD_ASSERT_UNKNOWN( p <= q );
430
431 // Taylor coefficients corresponding to arguments and result
432 Base* x = taylor + size_t(arg[0]) * cap_order;
433 Base* z = taylor + i_z * cap_order;
434
435 // Parameter value
436 Base y = parameter[ arg[1] ];
437
438 // Using CondExp and multiple levels of AD, it can make sense
439 // to divide by zero so do not make it an error.
440 for(size_t d = p; d <= q; d++)
441 z[d] = x[d] / y;
442 }
443 /*!
444 Multiple direction forward mode Taylor coefficients for op = DivvvOp.
445
446 The C++ source code corresponding to this operation is
447 \verbatim
448 z = x / y
449 \endverbatim
450 In the documentation below,
451 this operations is for the case where x is a variable and y is a parameter.
452
453 \copydetails CppAD::local::forward_binary_op_dir
454 */
455
456 template <class Base>
457 void forward_divvp_op_dir(
458 size_t q ,
459 size_t r ,
460 size_t i_z ,
461 const addr_t* arg ,
462 const Base* parameter ,
463 size_t cap_order ,
464 Base* taylor )
465 {
466 // check assumptions
467 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
468 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
469 CPPAD_ASSERT_UNKNOWN( q < cap_order );
470 CPPAD_ASSERT_UNKNOWN( 0 < q );
471
472 // Taylor coefficients corresponding to arguments and result
473 size_t num_taylor_per_var = (cap_order-1) * r + 1;
474 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
475 Base* z = taylor + i_z * num_taylor_per_var;
476
477 // Parameter value
478 Base y = parameter[ arg[1] ];
479
480 // Using CondExp and multiple levels of AD, it can make sense
481 // to divide by zero so do not make it an error.
482 size_t m = (q-1)*r + 1;
483 for(size_t ell = 0; ell < r; ell++)
484 z[m + ell] = x[m + ell] / y;
485 }
486
487
488 /*!
489 Compute zero order forward mode Taylor coefficients for result of op = DivvvOp.
490
491 The C++ source code corresponding to this operation is
492 \verbatim
493 z = x / y
494 \endverbatim
495 In the documentation below,
496 this operations is for the case where x is a variable and y is a parameter.
497
498 \copydetails CppAD::local::forward_binary_op_0
499 */
500
501 template <class Base>
502 void forward_divvp_op_0(
503 size_t i_z ,
504 const addr_t* arg ,
505 const Base* parameter ,
506 size_t cap_order ,
507 Base* taylor )
508 {
509 // check assumptions
510 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
511 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
512
513 // Parameter value
514 Base y = parameter[ arg[1] ];
515
516 // Taylor coefficients corresponding to arguments and result
517 Base* x = taylor + size_t(arg[0]) * cap_order;
518 Base* z = taylor + i_z * cap_order;
519
520 z[0] = x[0] / y;
521 }
522
523 /*!
524 Compute reverse mode partial derivative for result of op = DivvpOp.
525
526 The C++ source code corresponding to this operation is
527 \verbatim
528 z = x / y
529 \endverbatim
530 In the documentation below,
531 this operations is for the case where x is a variable and y is a parameter.
532
533 \copydetails CppAD::local::reverse_binary_op
534 */
535
536 template <class Base>
537 void reverse_divvp_op(
538 size_t d ,
539 size_t i_z ,
540 const addr_t* arg ,
541 const Base* parameter ,
542 size_t cap_order ,
543 const Base* taylor ,
544 size_t nc_partial ,
545 Base* partial )
546 {
547 // check assumptions
548 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
549 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
550 CPPAD_ASSERT_UNKNOWN( d < cap_order );
551 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
552
553 // Argument values
554 Base y = parameter[ arg[1] ];
555
556 // Partial derivatives corresponding to arguments and result
557 Base* px = partial + size_t(arg[0]) * nc_partial;
558 Base* pz = partial + i_z * nc_partial;
559
560 // Using CondExp, it can make sense to divide by zero
561 // so do not make it an error.
562 Base inv_y = Base(1.0) / y;
563
564 // number of indices to access
565 size_t j = d + 1;
566 while(j)
567 { --j;
568 px[j] += azmul(pz[j], inv_y);
569 }
570 }
571
572 } } // END_CPPAD_LOCAL_NAMESPACE
573 # endif
+0
-598
include/cppad/local/erf_op.hpp less more
0 # ifndef CPPAD_LOCAL_ERF_OP_HPP
1 # define CPPAD_LOCAL_ERF_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15 # include <cppad/local/mul_op.hpp>
16 # include <cppad/local/sub_op.hpp>
17 # include <cppad/local/exp_op.hpp>
18
19
20 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
21 /*!
22 \file erf_op.hpp
23 Forward and reverse mode calculations for z = erf(x) or erfc(x).
24 */
25
26 /*!
27 Forward mode Taylor coefficient for result of op = ErfOp or ErfcOp.
28
29 The C++ source code corresponding to this operation is one of
30 \verbatim
31 z = erf(x)
32 z = erfc(x)
33 \endverbatim
34
35 \tparam Base
36 base type for the operator; i.e., this operation was recorded
37 using AD< Base > and computations by this routine are done using type Base.
38
39 \param op
40 must be either ErfOp or ErfcOp and indicates if this is
41 z = erf(x) or z = erfc(x).
42
43 \param p
44 lowest order of the Taylor coefficients that we are computing.
45
46 \param q
47 highest order of the Taylor coefficients that we are computing.
48
49 \param i_z
50 variable index corresponding to the last (primary) result for this operation;
51 i.e. the row index in taylor corresponding to z.
52 The auxillary results are called y_j have index i_z - j.
53
54 \param arg
55 arg[0]: is the variable index corresponding to x.
56 \n
57 arg[1]: is the parameter index corresponding to the value zero.
58 \n
59 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
60
61 \param parameter
62 parameter[ arg[1] ] is the value zero,
63 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
64
65 \param cap_order
66 maximum number of orders that will fit in the taylor array.
67
68 \param taylor
69 \b Input:
70 taylor [ size_t(arg[0]) * cap_order + k ]
71 for k = 0 , ... , q,
72 is the k-th order Taylor coefficient corresponding to x.
73 \n
74 \b Input:
75 taylor [ i_z * cap_order + k ]
76 for k = 0 , ... , p - 1,
77 is the k-th order Taylor coefficient corresponding to z.
78 \n
79 \b Input:
80 taylor [ ( i_z - j) * cap_order + k ]
81 for k = 0 , ... , p-1,
82 and j = 0 , ... , 4,
83 is the k-th order Taylor coefficient corresponding to the j-th result for z.
84 \n
85 \b Output:
86 taylor [ (i_z-j) * cap_order + k ],
87 for k = p , ... , q,
88 and j = 0 , ... , 4,
89 is the k-th order Taylor coefficient corresponding to the j-th result for z.
90
91 */
92 template <class Base>
93 void forward_erf_op(
94 OpCode op ,
95 size_t p ,
96 size_t q ,
97 size_t i_z ,
98 const addr_t* arg ,
99 const Base* parameter ,
100 size_t cap_order ,
101 Base* taylor )
102 {
103 // check assumptions
104 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
105 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
106 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
107 CPPAD_ASSERT_UNKNOWN( q < cap_order );
108 CPPAD_ASSERT_UNKNOWN( p <= q );
109 CPPAD_ASSERT_UNKNOWN(
110 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
111 );
112
113 // array used to pass parameter values for sub-operations
114 addr_t addr[2];
115
116 // convert from final result to first result
117 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
118
119 // z_0 = x * x
120 addr[0] = arg[0]; // x
121 addr[1] = arg[0]; // x
122 forward_mulvv_op(p, q, i_z+0, addr, parameter, cap_order, taylor);
123
124 // z_1 = - x * x
125 addr[0] = arg[1]; // zero
126 addr[1] = addr_t( i_z ); // z_0
127 forward_subpv_op(p, q, i_z+1, addr, parameter, cap_order, taylor);
128
129 // z_2 = exp( - x * x )
130 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
131
132 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
133 addr[0] = arg[2]; // 2 / sqrt(pi)
134 addr[1] = addr_t( i_z + 2 ); // z_2
135 forward_mulpv_op(p, q, i_z+3, addr, parameter, cap_order, taylor);
136
137 // pointers to taylor coefficients for x , z_3, and z_4
138 Base* x = taylor + size_t(arg[0]) * cap_order;
139 Base* z_3 = taylor + (i_z+3) * cap_order;
140 Base* z_4 = taylor + (i_z+4) * cap_order;
141
142 // calculte z_4 coefficients
143 if( p == 0 )
144 { // z4 (t) = erf[x(t)]
145 if( op == ErfOp )
146 z_4[0] = erf(x[0]);
147 else
148 z_4[0] = erfc(x[0]);
149 p++;
150 }
151 // sign
152 Base sign(1.0);
153 if( op == ErfcOp )
154 sign = Base(-1.0);
155 //
156 for(size_t j = p; j <= q; j++)
157 { // erf: z_4' (t) = erf'[x(t)] * x'(t) = z3(t) * x'(t)
158 // erfc: z_4' (t) = - erf'[x(t)] * x'(t) = - z3(t) * x'(t)
159 // z_4[1] + 2 * z_4[2] * t + ... =
160 // sign * (z_3[0] + z_3[1] * t + ...) * (x[1] + 2 * x[2] * t + ...)
161 Base base_j = static_cast<Base>(double(j));
162 z_4[j] = static_cast<Base>(0);
163 for(size_t k = 1; k <= j; k++)
164 z_4[j] += sign * (Base(double(k)) / base_j) * x[k] * z_3[j-k];
165 }
166 }
167
168 /*!
169 Zero order Forward mode Taylor coefficient for result of op = ErfOp or ErfcOp.
170
171 The C++ source code corresponding to this operation one of
172 \verbatim
173 z = erf(x)
174 z = erfc(x)
175 \endverbatim
176
177 \tparam Base
178 base type for the operator; i.e., this operation was recorded
179 using AD< Base > and computations by this routine are done using type Base.
180
181 \param op
182 must be either ErfOp or ErfcOp and indicates if this is
183 z = erf(x) or z = erfc(x).
184
185 \param i_z
186 variable index corresponding to the last (primary) result for this operation;
187 i.e. the row index in taylor corresponding to z.
188 The auxillary results are called y_j have index i_z - j.
189
190 \param arg
191 arg[0]: is the variable index corresponding to x.
192 \n
193 arg[1]: is the parameter index corresponding to the value zero.
194 \n
195 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
196
197 \param parameter
198 parameter[ arg[1] ] is the value zero,
199 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
200
201 \param cap_order
202 maximum number of orders that will fit in the taylor array.
203
204 \param taylor
205 \b Input:
206 taylor [ size_t(arg[0]) * cap_order + 0 ]
207 is the zero order Taylor coefficient corresponding to x.
208 \n
209 \b Input:
210 taylor [ i_z * cap_order + 0 ]
211 is the zero order Taylor coefficient corresponding to z.
212 \n
213 \b Output:
214 taylor [ (i_z-j) * cap_order + 0 ],
215 for j = 0 , ... , 4,
216 is the zero order Taylor coefficient for j-th result corresponding to z.
217
218 */
219 template <class Base>
220 void forward_erf_op_0(
221 OpCode op ,
222 size_t i_z ,
223 const addr_t* arg ,
224 const Base* parameter ,
225 size_t cap_order ,
226 Base* taylor )
227 {
228 // check assumptions
229 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
230 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
231 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
232 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
233 CPPAD_ASSERT_UNKNOWN(
234 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
235 );
236
237 // array used to pass parameter values for sub-operations
238 addr_t addr[2];
239
240 // convert from final result to first result
241 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
242
243 // z_0 = x * x
244 addr[0] = arg[0]; // x
245 addr[1] = arg[0]; // x
246 forward_mulvv_op_0(i_z+0, addr, parameter, cap_order, taylor);
247
248 // z_1 = - x * x
249 addr[0] = arg[1]; // zero
250 addr[1] = addr_t(i_z); // z_0
251 forward_subpv_op_0(i_z+1, addr, parameter, cap_order, taylor);
252
253 // z_2 = exp( - x * x )
254 forward_exp_op_0(i_z+2, i_z+1, cap_order, taylor);
255
256 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
257 addr[0] = arg[2]; // 2 / sqrt(pi)
258 addr[1] = addr_t(i_z + 2); // z_2
259 forward_mulpv_op_0(i_z+3, addr, parameter, cap_order, taylor);
260
261 // zero order Taylor coefficient for z_4
262 Base* x = taylor + size_t(arg[0]) * cap_order;
263 Base* z_4 = taylor + (i_z + 4) * cap_order;
264 if( op == ErfOp )
265 z_4[0] = erf(x[0]);
266 else
267 z_4[0] = erfc(x[0]);
268 }
269 /*!
270 Forward mode Taylor coefficient for result of op = ErfOp or ErfcOp.
271
272 The C++ source code corresponding to this operation is one of
273 \verbatim
274 z = erf(x)
275 z = erfc(x)
276 \endverbatim
277
278 \tparam Base
279 base type for the operator; i.e., this operation was recorded
280 using AD< Base > and computations by this routine are done using type Base.
281
282 \param op
283 must be either ErfOp or ErfcOp and indicates if this is
284 z = erf(x) or z = erfc(x).
285
286 \param q
287 order of the Taylor coefficients that we are computing.
288
289 \param r
290 number of directions for the Taylor coefficients that we afre computing.
291
292 \param i_z
293 variable index corresponding to the last (primary) result for this operation;
294 i.e. the row index in taylor corresponding to z.
295 The auxillary results have index i_z - j for j = 0 , ... , 4
296 (and include z).
297
298 \param arg
299 arg[0]: is the variable index corresponding to x.
300 \n
301 arg[1]: is the parameter index corresponding to the value zero.
302 \n
303 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
304
305 \param parameter
306 parameter[ arg[1] ] is the value zero,
307 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
308
309 \param cap_order
310 maximum number of orders that will fit in the taylor array.
311
312 \par tpv
313 We use the notation
314 <code>tpv = (cap_order-1) * r + 1</code>
315 which is the number of Taylor coefficients per variable
316
317 \param taylor
318 \b Input: If x is a variable,
319 <code>taylor [ arg[0] * tpv + 0 ]</code>,
320 is the zero order Taylor coefficient for all directions and
321 <code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
322 for k = 1 , ... , q,
323 ell = 0, ..., r-1,
324 is the k-th order Taylor coefficient
325 corresponding to x and the ell-th direction.
326 \n
327 \b Input:
328 taylor [ (i_z - j) * tpv + 0 ]
329 is the zero order Taylor coefficient for all directions and the
330 j-th result for z.
331 for k = 1 , ... , q-1,
332 ell = 0, ... , r-1,
333 <code>
334 taylor[ (i_z - j) * tpv + (k-1)*r + ell + 1]
335 </code>
336 is the Taylor coefficient for the k-th order, ell-th direction,
337 and j-th auzillary result.
338 \n
339 \b Output:
340 taylor [ (i_z-j) * tpv + (q-1)*r + ell + 1 ],
341 for ell = 0 , ... , r-1,
342 is the Taylor coefficient for the q-th order, ell-th direction,
343 and j-th auzillary result.
344
345 */
346 template <class Base>
347 void forward_erf_op_dir(
348 OpCode op ,
349 size_t q ,
350 size_t r ,
351 size_t i_z ,
352 const addr_t* arg ,
353 const Base* parameter ,
354 size_t cap_order ,
355 Base* taylor )
356 {
357 // check assumptions
358 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
359 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
360 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
361 CPPAD_ASSERT_UNKNOWN( q < cap_order );
362 CPPAD_ASSERT_UNKNOWN( 0 < q );
363 CPPAD_ASSERT_UNKNOWN(
364 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
365 );
366
367 // array used to pass parameter values for sub-operations
368 addr_t addr[2];
369
370 // convert from final result to first result
371 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
372
373 // z_0 = x * x
374 addr[0] = arg[0]; // x
375 addr[1] = arg[0]; // x
376 forward_mulvv_op_dir(q, r, i_z+0, addr, parameter, cap_order, taylor);
377
378 // z_1 = - x * x
379 addr[0] = arg[1]; // zero
380 addr[1] = addr_t( i_z ); // z_0
381 forward_subpv_op_dir(q, r, i_z+1, addr, parameter, cap_order, taylor);
382
383 // z_2 = exp( - x * x )
384 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
385
386 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
387 addr[0] = arg[2]; // 2 / sqrt(pi)
388 addr[1] = addr_t( i_z + 2 ); // z_2
389 forward_mulpv_op_dir(q, r, i_z+3, addr, parameter, cap_order, taylor);
390
391 // pointers to taylor coefficients for x , z_3, and z_4
392 size_t num_taylor_per_var = (cap_order - 1) * r + 1;
393 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
394 Base* z_3 = taylor + (i_z+3) * num_taylor_per_var;
395 Base* z_4 = taylor + (i_z+4) * num_taylor_per_var;
396
397 // sign
398 Base sign(1.0);
399 if( op == ErfcOp )
400 sign = Base(-1.0);
401
402 // erf: z_4' (t) = erf'[x(t)] * x'(t) = z3(t) * x'(t)
403 // erfc: z_4' (t) = - erf'[x(t)] * x'(t) = z3(t) * x'(t)
404 // z_4[1] + 2 * z_4[2] * t + ... =
405 // sign * (z_3[0] + z_3[1] * t + ...) * (x[1] + 2 * x[2] * t + ...)
406 Base base_q = static_cast<Base>(double(q));
407 for(size_t ell = 0; ell < r; ell++)
408 { // index in z_4 and x for q-th order term
409 size_t m = (q-1)*r + ell + 1;
410 // initialize q-th order term summation
411 z_4[m] = sign * z_3[0] * x[m];
412 for(size_t k = 1; k < q; k++)
413 { size_t x_index = (k-1)*r + ell + 1;
414 size_t z3_index = (q-k-1)*r + ell + 1;
415 Base bk = Base(double(k));
416 z_4[m] += sign * (bk / base_q) * x[x_index] * z_3[z3_index];
417 }
418 }
419 }
420
421 /*!
422 Compute reverse mode partial derivatives for result of op = ErfOp or ErfcOp.
423
424 The C++ source code corresponding to this operation is one of
425 \verbatim
426 z = erf(x)
427 z = erfc(x)
428 \endverbatim
429
430 \tparam Base
431 base type for the operator; i.e., this operation was recorded
432 using AD< Base > and computations by this routine are done using type Base.
433
434 \param op
435 must be either ErfOp or ErfcOp and indicates if this is
436 z = erf(x) or z = erfc(x).
437
438 \param d
439 highest order Taylor of the Taylor coefficients that we are computing
440 the partial derivatives with respect to.
441
442 \param i_z
443 variable index corresponding to the last (primary) result for this operation;
444 i.e. the row index in taylor corresponding to z.
445 The auxillary results are called y_j have index i_z - j.
446
447 \param arg
448 arg[0]: is the variable index corresponding to x.
449 \n
450 arg[1]: is the parameter index corresponding to the value zero.
451 \n
452 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
453
454 \param parameter
455 parameter[ arg[1] ] is the value zero,
456 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
457
458 \param cap_order
459 maximum number of orders that will fit in the taylor array.
460
461 \param taylor
462 \b Input:
463 taylor [ size_t(arg[0]) * cap_order + k ]
464 for k = 0 , ... , d,
465 is the k-th order Taylor coefficient corresponding to x.
466 \n
467 taylor [ (i_z - j) * cap_order + k ]
468 for k = 0 , ... , d,
469 and for j = 0 , ... , 4,
470 is the k-th order Taylor coefficient corresponding to the j-th result
471 for this operation.
472
473 \param nc_partial
474 number of columns in the matrix containing all the partial derivatives
475
476 \param partial
477 \b Input:
478 partial [ size_t(arg[0]) * nc_partial + k ]
479 for k = 0 , ... , d,
480 is the partial derivative of G( z , x , w , u , ... ) with respect to
481 the k-th order Taylor coefficient for x.
482 \n
483 \b Input:
484 partial [ (i_z - j) * nc_partial + k ]
485 for k = 0 , ... , d,
486 and for j = 0 , ... , 4,
487 is the partial derivative of G( z , x , w , u , ... ) with respect to
488 the k-th order Taylor coefficient for the j-th result of this operation.
489 \n
490 \b Output:
491 partial [ size_t(arg[0]) * nc_partial + k ]
492 for k = 0 , ... , d,
493 is the partial derivative of H( x , w , u , ... ) with respect to
494 the k-th order Taylor coefficient for x.
495 \n
496 \b Output:
497 partial [ (i_z-j) * nc_partial + k ]
498 for k = 0 , ... , d,
499 and for j = 0 , ... , 4,
500 may be used as work space; i.e., may change in an unspecified manner.
501
502 */
503 template <class Base>
504 void reverse_erf_op(
505 OpCode op ,
506 size_t d ,
507 size_t i_z ,
508 const addr_t* arg ,
509 const Base* parameter ,
510 size_t cap_order ,
511 const Base* taylor ,
512 size_t nc_partial ,
513 Base* partial )
514 {
515 // check assumptions
516 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
517 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
518 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
519 CPPAD_ASSERT_UNKNOWN( d < cap_order );
520 CPPAD_ASSERT_UNKNOWN(
521 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
522 );
523
524 // array used to pass parameter values for sub-operations
525 addr_t addr[2];
526
527 // If pz is zero, make sure this operation has no effect
528 // (zero times infinity or nan would be non-zero).
529 Base* pz = partial + i_z * nc_partial;
530 bool skip(true);
531 for(size_t i_d = 0; i_d <= d; i_d++)
532 skip &= IdenticalZero(pz[i_d]);
533 if( skip )
534 return;
535
536 // convert from final result to first result
537 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
538
539 // Taylor coefficients and partials corresponding to x
540 const Base* x = taylor + size_t(arg[0]) * cap_order;
541 Base* px = partial + size_t(arg[0]) * nc_partial;
542
543 // Taylor coefficients and partials corresponding to z_3
544 const Base* z_3 = taylor + (i_z+3) * cap_order;
545 Base* pz_3 = partial + (i_z+3) * nc_partial;
546
547 // Taylor coefficients and partials corresponding to z_4
548 Base* pz_4 = partial + (i_z+4) * nc_partial;
549
550 // sign
551 Base sign(1.0);
552 if( op == ErfcOp )
553 sign = Base(-1.0);
554
555 // Reverse z_4
556 size_t j = d;
557 while(j)
558 { pz_4[j] /= Base(double(j));
559 for(size_t k = 1; k <= j; k++)
560 { px[k] += sign * azmul(pz_4[j], z_3[j-k]) * Base(double(k));
561 pz_3[j-k] += sign * azmul(pz_4[j], x[k]) * Base(double(k));
562 }
563 j--;
564 }
565 px[0] += sign * azmul(pz_4[0], z_3[0]);
566
567 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
568 addr[0] = arg[2]; // 2 / sqrt(pi)
569 addr[1] = addr_t( i_z + 2 ); // z_2
570 reverse_mulpv_op(
571 d, i_z+3, addr, parameter, cap_order, taylor, nc_partial, partial
572 );
573
574 // z_2 = exp( - x * x )
575 reverse_exp_op(
576 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
577 );
578
579 // z_1 = - x * x
580 addr[0] = arg[1]; // zero
581 addr[1] = addr_t( i_z ); // z_0
582 reverse_subpv_op(
583 d, i_z+1, addr, parameter, cap_order, taylor, nc_partial, partial
584 );
585
586 // z_0 = x * x
587 addr[0] = arg[0]; // x
588 addr[1] = arg[0]; // x
589 reverse_mulvv_op(
590 d, i_z+0, addr, parameter, cap_order, taylor, nc_partial, partial
591 );
592
593 }
594
595
596 } } // END_CPPAD_LOCAL_NAMESPACE
597 # endif // CPPAD_ERF_OP_INCLUDED
+0
-194
include/cppad/local/exp_op.hpp less more
0 # ifndef CPPAD_LOCAL_EXP_OP_HPP
1 # define CPPAD_LOCAL_EXP_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file exp_op.hpp
18 Forward and reverse mode calculations for z = exp(x).
19 */
20
21
22 /*!
23 Forward mode Taylor coefficient for result of op = ExpOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = exp(x)
28 \endverbatim
29
30 \copydetails CppAD::local::forward_unary1_op
31 */
32 template <class Base>
33 void forward_exp_op(
34 size_t p ,
35 size_t q ,
36 size_t i_z ,
37 size_t i_x ,
38 size_t cap_order ,
39 Base* taylor )
40 {
41 // check assumptions
42 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
43 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
44 CPPAD_ASSERT_UNKNOWN( q < cap_order );
45 CPPAD_ASSERT_UNKNOWN( p <= q );
46
47 // Taylor coefficients corresponding to argument and result
48 Base* x = taylor + i_x * cap_order;
49 Base* z = taylor + i_z * cap_order;
50
51 size_t k;
52 if( p == 0 )
53 { z[0] = exp( x[0] );
54 p++;
55 }
56 for(size_t j = p; j <= q; j++)
57 {
58 z[j] = x[1] * z[j-1];
59 for(k = 2; k <= j; k++)
60 z[j] += Base(double(k)) * x[k] * z[j-k];
61 z[j] /= Base(double(j));
62 }
63 }
64
65
66 /*!
67 Multiple direction forward mode Taylor coefficient for op = ExpOp.
68
69 The C++ source code corresponding to this operation is
70 \verbatim
71 z = exp(x)
72 \endverbatim
73
74 \copydetails CppAD::local::forward_unary1_op_dir
75 */
76 template <class Base>
77 void forward_exp_op_dir(
78 size_t q ,
79 size_t r ,
80 size_t i_z ,
81 size_t i_x ,
82 size_t cap_order ,
83 Base* taylor )
84 {
85 // check assumptions
86 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
87 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
88 CPPAD_ASSERT_UNKNOWN( q < cap_order );
89 CPPAD_ASSERT_UNKNOWN( 0 < q );
90
91 // Taylor coefficients corresponding to argument and result
92 size_t num_taylor_per_var = (cap_order-1) * r + 1;
93 Base* x = taylor + i_x * num_taylor_per_var;
94 Base* z = taylor + i_z * num_taylor_per_var;
95
96 size_t m = (q-1)*r + 1;
97 for(size_t ell = 0; ell < r; ell++)
98 { z[m+ell] = Base(double(q)) * x[m+ell] * z[0];
99 for(size_t k = 1; k < q; k++)
100 z[m+ell] += Base(double(k)) * x[(k-1)*r+ell+1] * z[(q-k-1)*r+ell+1];
101 z[m+ell] /= Base(double(q));
102 }
103 }
104
105 /*!
106 Zero order forward mode Taylor coefficient for result of op = ExpOp.
107
108 The C++ source code corresponding to this operation is
109 \verbatim
110 z = exp(x)
111 \endverbatim
112
113 \copydetails CppAD::local::forward_unary1_op_0
114 */
115 template <class Base>
116 void forward_exp_op_0(
117 size_t i_z ,
118 size_t i_x ,
119 size_t cap_order ,
120 Base* taylor )
121 {
122 // check assumptions
123 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
124 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
125 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
126
127 // Taylor coefficients corresponding to argument and result
128 Base* x = taylor + i_x * cap_order;
129 Base* z = taylor + i_z * cap_order;
130
131 z[0] = exp( x[0] );
132 }
133 /*!
134 Reverse mode partial derivatives for result of op = ExpOp.
135
136 The C++ source code corresponding to this operation is
137 \verbatim
138 z = exp(x)
139 \endverbatim
140
141 \copydetails CppAD::local::reverse_unary1_op
142 */
143
144 template <class Base>
145 void reverse_exp_op(
146 size_t d ,
147 size_t i_z ,
148 size_t i_x ,
149 size_t cap_order ,
150 const Base* taylor ,
151 size_t nc_partial ,
152 Base* partial )
153 {
154 // check assumptions
155 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
156 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
157 CPPAD_ASSERT_UNKNOWN( d < cap_order );
158 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
159
160 // Taylor coefficients and partials corresponding to argument
161 const Base* x = taylor + i_x * cap_order;
162 Base* px = partial + i_x * nc_partial;
163
164 // Taylor coefficients and partials corresponding to result
165 const Base* z = taylor + i_z * cap_order;
166 Base* pz = partial + i_z * nc_partial;
167
168 // If pz is zero, make sure this operation has no effect
169 // (zero times infinity or nan would be non-zero).
170 bool skip(true);
171 for(size_t i_d = 0; i_d <= d; i_d++)
172 skip &= IdenticalZero(pz[i_d]);
173 if( skip )
174 return;
175
176 // loop through orders in reverse
177 size_t j, k;
178 j = d;
179 while(j)
180 { // scale partial w.r.t z[j]
181 pz[j] /= Base(double(j));
182
183 for(k = 1; k <= j; k++)
184 { px[k] += Base(double(k)) * azmul(pz[j], z[j-k]);
185 pz[j-k] += Base(double(k)) * azmul(pz[j], x[k]);
186 }
187 --j;
188 }
189 px[0] += azmul(pz[0], z[0]);
190 }
191
192 } } // END_CPPAD_LOCAL_NAMESPACE
193 # endif
+0
-199
include/cppad/local/expm1_op.hpp less more
0 # ifndef CPPAD_LOCAL_EXPM1_OP_HPP
1 # define CPPAD_LOCAL_EXPM1_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17 /*!
18 \file expm1_op.hpp
19 Forward and reverse mode calculations for z = expm1(x).
20 */
21
22
23 /*!
24 Forward mode Taylor coefficient for result of op = Expm1Op.
25
26 The C++ source code corresponding to this operation is
27 \verbatim
28 z = expm1(x)
29 \endverbatim
30
31 \copydetails CppAD::local::forward_unary1_op
32 */
33 template <class Base>
34 void forward_expm1_op(
35 size_t p ,
36 size_t q ,
37 size_t i_z ,
38 size_t i_x ,
39 size_t cap_order ,
40 Base* taylor )
41 {
42 // check assumptions
43 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
44 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
45 CPPAD_ASSERT_UNKNOWN( q < cap_order );
46 CPPAD_ASSERT_UNKNOWN( p <= q );
47
48 // Taylor coefficients corresponding to argument and result
49 Base* x = taylor + i_x * cap_order;
50 Base* z = taylor + i_z * cap_order;
51
52 size_t k;
53 if( p == 0 )
54 { z[0] = expm1( x[0] );
55 p++;
56 }
57 for(size_t j = p; j <= q; j++)
58 {
59 z[j] = x[1] * z[j-1];
60 for(k = 2; k <= j; k++)
61 z[j] += Base(double(k)) * x[k] * z[j-k];
62 z[j] /= Base(double(j));
63 z[j] += x[j];
64 }
65 }
66
67
68 /*!
69 Multiple direction forward mode Taylor coefficient for op = Expm1Op.
70
71 The C++ source code corresponding to this operation is
72 \verbatim
73 z = expm1(x)
74 \endverbatim
75
76 \copydetails CppAD::local::forward_unary1_op_dir
77 */
78 template <class Base>
79 void forward_expm1_op_dir(
80 size_t q ,
81 size_t r ,
82 size_t i_z ,
83 size_t i_x ,
84 size_t cap_order ,
85 Base* taylor )
86 {
87 // check assumptions
88 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
89 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
90 CPPAD_ASSERT_UNKNOWN( q < cap_order );
91 CPPAD_ASSERT_UNKNOWN( 0 < q );
92
93 // Taylor coefficients corresponding to argument and result
94 size_t num_taylor_per_var = (cap_order-1) * r + 1;
95 Base* x = taylor + i_x * num_taylor_per_var;
96 Base* z = taylor + i_z * num_taylor_per_var;
97
98 size_t m = (q-1)*r + 1;
99 for(size_t ell = 0; ell < r; ell++)
100 { z[m+ell] = Base(double(q)) * x[m+ell] * z[0];
101 for(size_t k = 1; k < q; k++)
102 z[m+ell] += Base(double(k)) * x[(k-1)*r+ell+1] * z[(q-k-1)*r+ell+1];
103 z[m+ell] /= Base(double(q));
104 z[m+ell] += x[m+ell];
105 }
106 }
107
108 /*!
109 Zero order forward mode Taylor coefficient for result of op = Expm1Op.
110
111 The C++ source code corresponding to this operation is
112 \verbatim
113 z = expm1(x)
114 \endverbatim
115
116 \copydetails CppAD::local::forward_unary1_op_0
117 */
118 template <class Base>
119 void forward_expm1_op_0(
120 size_t i_z ,
121 size_t i_x ,
122 size_t cap_order ,
123 Base* taylor )
124 {
125 // check assumptions
126 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
127 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
128 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
129
130 // Taylor coefficients corresponding to argument and result
131 Base* x = taylor + i_x * cap_order;
132 Base* z = taylor + i_z * cap_order;
133
134 z[0] = expm1( x[0] );
135 }
136 /*!
137 Reverse mode partial derivatives for result of op = Expm1Op.
138
139 The C++ source code corresponding to this operation is
140 \verbatim
141 z = expm1(x)
142 \endverbatim
143
144 \copydetails CppAD::local::reverse_unary1_op
145 */
146
147 template <class Base>
148 void reverse_expm1_op(
149 size_t d ,
150 size_t i_z ,
151 size_t i_x ,
152 size_t cap_order ,
153 const Base* taylor ,
154 size_t nc_partial ,
155 Base* partial )
156 {
157 // check assumptions
158 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
159 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
160 CPPAD_ASSERT_UNKNOWN( d < cap_order );
161 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
162
163 // Taylor coefficients and partials corresponding to argument
164 const Base* x = taylor + i_x * cap_order;
165 Base* px = partial + i_x * nc_partial;
166
167 // Taylor coefficients and partials corresponding to result
168 const Base* z = taylor + i_z * cap_order;
169 Base* pz = partial + i_z * nc_partial;
170
171 // If pz is zero, make sure this operation has no effect
172 // (zero times infinity or nan would be non-zero).
173 bool skip(true);
174 for(size_t i_d = 0; i_d <= d; i_d++)
175 skip &= IdenticalZero(pz[i_d]);
176 if( skip )
177 return;
178
179 // loop through orders in reverse
180 size_t j, k;
181 j = d;
182 while(j)
183 { px[j] += pz[j];
184
185 // scale partial w.r.t z[j]
186 pz[j] /= Base(double(j));
187
188 for(k = 1; k <= j; k++)
189 { px[k] += Base(double(k)) * azmul(pz[j], z[j-k]);
190 pz[j-k] += Base(double(k)) * azmul(pz[j], x[k]);
191 }
192 --j;
193 }
194 px[0] += pz[0] + azmul(pz[0], z[0]);
195 }
196
197 } } // END_CPPAD_LOCAL_NAMESPACE
198 # endif
00 # ifndef CPPAD_LOCAL_GRAPH_CPP_GRAPH_ITR_HPP
11 # define CPPAD_LOCAL_GRAPH_CPP_GRAPH_ITR_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
148148 case expm1_graph_op:
149149 case log1p_graph_op:
150150 case log_graph_op:
151 case neg_graph_op:
151152 case sign_graph_op:
152153 case sin_graph_op:
153154 case sinh_graph_op:
00 # ifndef CPPAD_LOCAL_GRAPH_CPP_GRAPH_OP_HPP
11 # define CPPAD_LOCAL_GRAPH_CPP_GRAPH_OP_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5959 This is a mapping from the operator name to its enum value.
6060 The name is the operator enum without the $code _operator$$ at the end.
6161 $srccode%hpp% */
62 extern std::map< std::string, graph_op_enum > op_name2enum;
62 extern CPPAD_LIB_EXPORT std::map< std::string, graph_op_enum > op_name2enum;
6363 /* %$$
6464
6565 $head op_enum2fixed_n_arg$$
6767 a fixed number of arguments and one result.
6868 For other operators, this value is zero.
6969 $srccode%hpp% */
70 extern size_t op_enum2fixed_n_arg[];
70 extern CPPAD_LIB_EXPORT size_t op_enum2fixed_n_arg[];
7171 /* %$$
7272
7373 $head op_enum2name$$
7474 This is mapping from operator enum value to its name.
7575 In the $code local::graph$$ namespace:
7676 $srccode%hpp% */
77 extern const char* op_enum2name[];
77 extern CPPAD_LIB_EXPORT const char* op_enum2name[];
7878 /* %$$
7979
8080 $head set_operator_info$$
8383 $code op_enum2name$$, and
8484 $code op_name2enum$$.
8585 $srccode%hpp% */
86 extern void set_operator_info(void);
86 extern CPPAD_LIB_EXPORT void set_operator_info(void);
8787 /* %$$
8888 $end
8989 */
00 # ifndef CPPAD_LOCAL_GRAPH_JSON_LEXER_HPP
11 # define CPPAD_LOCAL_GRAPH_JSON_LEXER_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
210210 are set to the first non white space character in $code json_$$.
211211 If this is not a left brace character $code '{'$$,
212212 the error is reported and the constructor does not return.
213
214 $head Side Effect$$
215 If $code local::graph::op_name2enum.size() == 0$$,
216 the routine $cref/set_operator_info/cpp_graph_op/set_operator_info/$$
217 is called to initialize
218 $code op_enum2fixed_n_arg$$,
219 $code op_enum2name$$, and
220 $code op_name2enum$$.
221 This initialization cannot be done in
222 $cref/parallel mode/ta_in_parallel/$$.
223213
224214 $head Prototype$$
225215 $srccode%hpp% */
4141 $head Prototype$$
4242 $srccode%hpp% */
4343 namespace CppAD { namespace local { namespace graph {
44 void json_parser(
44 CPPAD_LIB_EXPORT void json_parser(
4545 const std::string& json ,
4646 cpp_graph& graph_obj
4747 );
4040 $head Prototype$$
4141 $srccode%hpp% */
4242 namespace CppAD { namespace local { namespace graph {
43 void json_writer(
43 CPPAD_LIB_EXPORT void json_writer(
4444 std::string& json ,
4545 const cpp_graph& graph_obj
4646 );
+0
-697
include/cppad/local/load_op.hpp less more
0 # ifndef CPPAD_LOCAL_LOAD_OP_HPP
1 # define CPPAD_LOCAL_LOAD_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*
17 ------------------------------------------------------------------------------
18 $begin load_op_var$$
19 $spell
20 pv
21 Vec
22 op
23 var
24 isvar
25 ind
26 Taylor
27 arg
28 num
29 Addr
30 vecad
31 $$
32 $section Accessing an Element in a Variable VecAD Vector$$
33
34 $head See Also$$
35 $cref/op_code_var load/op_code_var/Load/$$.
36
37 $head Syntax$$
38 $codei%forward_load_%I%_op_0(
39 %play%,
40 %i_z%,
41 %arg%,
42 %parameter%,
43 %cap_order%,
44 %taylor%,
45 %vec_ad2isvar%,
46 %vec_ad2index%,
47 %load_op2var%
48 )
49 %$$
50 where the index type $icode I$$ is $code p$$ (for parameter)
51 or $code v$$ (for variable).
52
53 $head Prototype$$
54 $srcthisfile%
55 0%// BEGIN_FORWARD_LOAD_P_OP_0%// END_FORWARD_LOAD_P_OP_0%1
56 %$$
57 The prototype for $code forward_load_v_op_0$$ is the same
58 except for the function name.
59
60 $head Notation$$
61
62 $subhead v$$
63 We use $icode v$$ to denote the $cref VecAD$$ vector for this operation.
64
65 $subhead x$$
66 We use $icode x$$ to denote the $codei%AD%<%Base%>%$$
67 index for this operation.
68
69 $subhead i_vec$$
70 We use $icode i_vec$$ to denote the $code size_t$$ value
71 corresponding to $icode x$$.
72
73 $subhead n_load$$
74 This is the number of load instructions in this recording; i.e.,
75 $icode%play%->num_var_load_rec()%$$.
76
77 $subhead n_all$$
78 This is the number of values in the single array that includes
79 all the vectors together with the size of each vector; i.e.,
80 $icode%play%->num_var_vecad_ind_rec()%$$.
81
82 $head Addr$$
83 Is the type used for address on this tape.
84
85 $head Base$$
86 base type for the operator; i.e., this operation was recorded
87 using AD<Base> and computations by this routine are done using type Base.
88
89 $head play$$
90 is the tape that this operation appears in.
91 This is for error detection and not used when NDEBUG is defined.
92
93 $head i_z$$
94 is the AD variable index corresponding to the result of this load operation.
95
96 $head arg$$
97
98 $subhead arg[0]$$
99 is the offset of this VecAD vector relative to the beginning
100 of the $icode vec_ad2isvar$$ and $icode vec_ad2index$$ arrays.
101
102 $subhead arg[1]$$
103 If this is
104 $code forward_load_p_op_0$$ ($code forward_load_v_op_0$$)
105 $icode%arg%[%1%]%$$ is the parameter index (variable index)
106 corresponding to $cref/i_vec/load_op_var/Notation/i_vec/$$.
107
108 $subhead arg[2]$$
109 Is the index of this VecAD load instruction in the
110 $icode load_op2var$$ array.
111
112 $head parameter$$
113 This is the vector of parameters for this recording which has size
114 $icode%play%->num_par_rec()%$$.
115
116 $head cap_order$$
117 number of columns in the matrix containing the Taylor coefficients.
118
119 $head taylor$$
120 Is the matrix of Taylor coefficients.
121
122 $subhead Input$$
123 In the $code forward_load_v_op_0$$ case,
124 $codei%
125 size_t( %taylor%[ %arg%[1]% * %cap_order% + 0 ] )
126 %$$
127 is the index in this VecAD vector.
128
129 $subhead Output$$
130 $icode%taylor%[ %i_z% * %cap_order% + 0 ]%$$
131 is set to the zero order Taylor coefficient for the result of this operator.
132
133 $head vec_ad2isvar$$
134 This vector has size $icode n_all$$.
135 If $icode%vec_ad2isvar%[ %arg%[%0%] + %i_vec% ]%$$ is false (true),
136 the vector element is parameter (variable).
137
138 $subhead i_pv$$
139 If this element is a parameter (variable),
140 $codei%
141 %i_pv% = %vec_ad2index%[ %arg%[%0%] + %i_vec% ]
142 %$$
143 is the corresponding parameter (variable) index;
144
145 $head vec_ad2index$$
146 This array has size $icode n_all$$
147 The value $icode%vec_ad2index%[ %arg%[0] - 1 ]%$$
148 is the number of elements in the user vector containing this load.
149 $icode%vec_ad2index%[%i_pv%]%$$ is the variable or
150 parameter index for this element,
151
152 $head load_op2var$$
153 is a vector with size $icode n_load$$.
154 The input value of its elements does not matter.
155 If the result of this load is a variable,
156 $codei%
157 %load_op2var%[%arg%[2]] = %i_pv%
158 %$$
159 Otherwise,
160 $codei%
161 %load_op2var%[%arg%[2]] = 0
162 %$$
163
164 $end
165 */
166 // BEGIN_FORWARD_LOAD_P_OP_0
167 template <class Addr, class Base>
168 void forward_load_p_op_0(
169 const local::player<Base>* play ,
170 size_t i_z ,
171 const Addr* arg ,
172 const Base* parameter ,
173 size_t cap_order ,
174 Base* taylor ,
175 const bool* vec_ad2isvar ,
176 const size_t* vec_ad2index ,
177 Addr* load_op2var )
178 // END_FORWARD_LOAD_P_OP_0
179 { CPPAD_ASSERT_UNKNOWN( NumArg(LdpOp) == 3 );
180 CPPAD_ASSERT_UNKNOWN( NumRes(LdpOp) == 1 );
181 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
182 CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < play->num_par_rec() );
183 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_var_load_rec() );
184 CPPAD_ASSERT_UNKNOWN(
185 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
186 );
187
188 addr_t i_vec = addr_t( Integer( parameter[ arg[1] ] ) );
189 CPPAD_ASSERT_KNOWN(
190 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
191 "VecAD: dynamic parmaeter index out or range during zero order forward"
192 );
193 CPPAD_ASSERT_UNKNOWN( size_t(arg[0] + i_vec) < play->num_var_vecad_ind_rec() );
194
195 size_t i_pv = vec_ad2index[ arg[0] + i_vec ];
196 Base* z = taylor + i_z * cap_order;
197 if( vec_ad2isvar[ arg[0] + i_vec ] )
198 { CPPAD_ASSERT_UNKNOWN( i_pv < i_z );
199 load_op2var[ arg[2] ] = addr_t( i_pv );
200 Base* v_x = taylor + i_pv * cap_order;
201 z[0] = v_x[0];
202 }
203 else
204 { CPPAD_ASSERT_UNKNOWN( i_pv < play->num_par_rec() );
205 load_op2var[ arg[2] ] = 0;
206 Base v_x = parameter[i_pv];
207 z[0] = v_x;
208 }
209 }
210 template <class Addr, class Base>
211 void forward_load_v_op_0(
212 const local::player<Base>* play ,
213 size_t i_z ,
214 const Addr* arg ,
215 const Base* parameter ,
216 size_t cap_order ,
217 Base* taylor ,
218 const bool* vec_ad2isvar ,
219 const size_t* vec_ad2index ,
220 Addr* load_op2var )
221 { CPPAD_ASSERT_UNKNOWN( NumArg(LdvOp) == 3 );
222 CPPAD_ASSERT_UNKNOWN( NumRes(LdvOp) == 1 );
223 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
224 CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z );
225 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_var_load_rec() );
226 CPPAD_ASSERT_UNKNOWN(
227 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
228 );
229
230 addr_t i_vec = addr_t(Integer(taylor[ size_t(arg[1]) * cap_order + 0 ] ));
231 CPPAD_ASSERT_KNOWN(
232 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
233 "VecAD: variable index out or range during zero order forward"
234 );
235 CPPAD_ASSERT_UNKNOWN( size_t(arg[0] + i_vec) < play->num_var_vecad_ind_rec() );
236
237 size_t i_pv = vec_ad2index[ arg[0] + i_vec ];
238 Base* z = taylor + i_z * cap_order;
239 if( vec_ad2isvar[ arg[0] + i_vec ] )
240 { CPPAD_ASSERT_UNKNOWN( i_pv < i_z );
241 load_op2var[ arg[2] ] = addr_t( i_pv );
242 Base* v_x = taylor + i_pv * cap_order;
243 z[0] = v_x[0];
244 }
245 else
246 { CPPAD_ASSERT_UNKNOWN( i_pv < play->num_par_rec() );
247 load_op2var[ arg[2] ] = 0;
248 Base v_x = parameter[i_pv];
249 z[0] = v_x;
250 }
251 }
252 /*!
253 ------------------------------------------------------------------------------
254 Shared documentation for sparsity operations corresponding to
255 op = LdpOp or LdvOp (not called).
256
257 <!-- replace preamble -->
258 The C++ source code corresponding to this operation is
259 \verbatim
260 v[x] = y
261 \endverbatim
262 where v is a VecAD<Base> vector, x is an AD<Base> object,
263 and y is AD<Base> or Base objects.
264 We define the index corresponding to v[x] by
265 \verbatim
266 i_pv = vec_ad2index[ arg[0] + i_vec ]
267 \endverbatim
268 where i_vec is defined under the heading arg[1] below:
269 <!-- end preamble -->
270
271 \tparam Vector_set
272 is the type used for vectors of sets. It can be either
273 sparse::pack_setvec or sparse::list_setvec.
274
275 \param op
276 is the code corresponding to this operator;
277 i.e., LdpOp or LdvOp.
278
279 \param i_z
280 is the AD variable index corresponding to the variable z; i.e.,
281 the set with index i_z in var_sparsity is the sparsity pattern
282 corresponding to z.
283
284 \param arg
285 \n
286 arg[0]
287 is the offset corresponding to this VecAD vector in the VecAD combined array.
288
289 \param num_combined
290 is the total number of elements in the VecAD combinded array.
291
292 \param combined
293 is the VecAD combined array.
294 \n
295 \n
296 combined[ arg[0] - 1 ]
297 is the index of the set corresponding to the vector v in vecad_sparsity.
298 We use the notation i_v for this value; i.e.,
299 \verbatim
300 i_v = combined[ arg[0] - 1 ]
301 \endverbatim
302
303 \param var_sparsity
304 The set with index i_z in var_sparsity is the sparsity pattern for z.
305 This is an output for forward mode operations,
306 and an input for reverse mode operations.
307
308 \param vecad_sparsity
309 The set with index i_v is the sparsity pattern for the vector v.
310 This is an input for forward mode operations.
311 For reverse mode operations,
312 the sparsity pattern for z is added to the sparsity pattern for v.
313
314 \par Checked Assertions
315 \li NumArg(op) == 3
316 \li NumRes(op) == 1
317 \li 0 < arg[0]
318 \li arg[0] < num_combined
319 \li i_v < vecad_sparsity.n_set()
320 */
321 template <class Vector_set, class Addr>
322 void sparse_load_op(
323 OpCode op ,
324 size_t i_z ,
325 const Addr* arg ,
326 size_t num_combined ,
327 const size_t* combined ,
328 Vector_set& var_sparsity ,
329 Vector_set& vecad_sparsity )
330 {
331 // This routine is only for documentaiton, it should not be used
332 CPPAD_ASSERT_UNKNOWN( false );
333 }
334
335
336
337 /*!
338 Forward mode, except for zero order, for op = LdpOp or op = LdvOp
339
340
341 <!-- replace preamble -->
342 The C++ source code corresponding to this operation is
343 \verbatim
344 v[x] = y
345 \endverbatim
346 where v is a VecAD<Base> vector, x is an AD<Base> object,
347 and y is AD<Base> or Base objects.
348 We define the index corresponding to v[x] by
349 \verbatim
350 i_pv = vec_ad2index[ arg[0] + i_vec ]
351 \endverbatim
352 where i_vec is defined under the heading arg[1] below:
353 <!-- end preamble -->
354
355 \tparam Base
356 base type for the operator; i.e., this operation was recorded
357 using AD<Base> and computations by this routine are done using type Base.
358
359 \param play
360 is the tape that this operation appears in.
361 This is for error detection and not used when NDEBUG is defined.
362
363 \param op
364 is the code corresponding to this operator; i.e., LdpOp or LdvOp
365 (only used for error checking).
366
367 \param p
368 is the lowest order of the Taylor coefficient that we are computing.
369
370 \param q
371 is the highest order of the Taylor coefficient that we are computing.
372
373 \param r
374 is the number of directions for the Taylor coefficients that we
375 are computing.
376
377 \param cap_order
378 number of columns in the matrix containing the Taylor coefficients.
379
380 \par tpv
381 We use the notation
382 <code>tpv = (cap_order-1) * r + 1</code>
383 which is the number of Taylor coefficients per variable
384
385 \param i_z
386 is the AD variable index corresponding to the variable z.
387
388 \param arg
389 arg[2]
390 Is the index of this vecad load instruction in the load_op2var array.
391
392 \param load_op2var
393 is a vector with size play->num_var_load_rec().
394 It contains the variable index corresponding to each load instruction.
395 In the case where the index is zero,
396 the instruction corresponds to a parameter (not variable).
397
398 \par i_var
399 We use the notation
400 \verbatim
401 i_var = size_t( load_op2var[ arg[2] ] )
402 \endverbatim
403
404 \param taylor
405 \n
406 Input
407 \n
408 If <code>i_var > 0</code>, v[x] is a variable and
409 for k = 1 , ... , q
410 <code>taylor[ i_var * tpv + (k-1)*r+1+ell ]</code>
411 is the k-th order coefficient for v[x] in the ell-th direction,
412 \n
413 \n
414 Output
415 \n
416 for k = p , ... , q,
417 <code>taylor[ i_z * tpv + (k-1)*r+1+ell ]</code>
418 is set to the k-order Taylor coefficient for z in the ell-th direction.
419 */
420 template <class Addr, class Base>
421 void forward_load_op(
422 const local::player<Base>* play,
423 OpCode op ,
424 size_t p ,
425 size_t q ,
426 size_t r ,
427 size_t cap_order ,
428 size_t i_z ,
429 const Addr* arg ,
430 const Addr* load_op2var ,
431 Base* taylor )
432 {
433 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
434 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
435 CPPAD_ASSERT_UNKNOWN( q < cap_order );
436 CPPAD_ASSERT_UNKNOWN( 0 < r);
437 CPPAD_ASSERT_UNKNOWN( 0 < p);
438 CPPAD_ASSERT_UNKNOWN( p <= q );
439 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_var_load_rec() );
440
441 size_t i_var = size_t( load_op2var[ arg[2] ] );
442 CPPAD_ASSERT_UNKNOWN( i_var < i_z );
443
444 size_t num_taylor_per_var = (cap_order-1) * r + 1;
445 Base* z = taylor + i_z * num_taylor_per_var;
446 if( i_var > 0 )
447 { Base* v_x = taylor + i_var * num_taylor_per_var;
448 for(size_t ell = 0; ell < r; ell++)
449 { for(size_t k = p; k <= q; k++)
450 { size_t m = (k-1) * r + 1 + ell;
451 z[m] = v_x[m];
452 }
453 }
454 }
455 else
456 { for(size_t ell = 0; ell < r; ell++)
457 { for(size_t k = p; k <= q; k++)
458 { size_t m = (k-1) * r + 1 + ell;
459 z[m] = Base(0.0);
460 }
461 }
462 }
463 }
464
465 /*!
466 Reverse mode for op = LdpOp or LdvOp.
467
468 <!-- replace preamble -->
469 The C++ source code corresponding to this operation is
470 \verbatim
471 v[x] = y
472 \endverbatim
473 where v is a VecAD<Base> vector, x is an AD<Base> object,
474 and y is AD<Base> or Base objects.
475 We define the index corresponding to v[x] by
476 \verbatim
477 i_pv = vec_ad2index[ arg[0] + i_vec ]
478 \endverbatim
479 where i_vec is defined under the heading arg[1] below:
480 <!-- end preamble -->
481
482 This routine is given the partial derivatives of a function
483 G(z , y[x] , w , u ... )
484 and it uses them to compute the partial derivatives of
485 \verbatim
486 H( y[x] , w , u , ... ) = G[ z( y[x] ) , y[x] , w , u , ... ]
487 \endverbatim
488
489 \tparam Base
490 base type for the operator; i.e., this operation was recorded
491 using AD< Base > and computations by this routine are done using type
492 Base.
493
494 \param op
495 is the code corresponding to this operator; i.e., LdpOp or LdvOp
496 (only used for error checking).
497
498 \param d
499 highest order the Taylor coefficient that we are computing the partial
500 derivative with respect to.
501
502 \param i_z
503 is the AD variable index corresponding to the variable z.
504
505 \param arg
506 arg[2]
507 Is the index of this vecad load instruction in the
508 load_op2var array.
509
510 \param cap_order
511 number of columns in the matrix containing the Taylor coefficients
512 (not used).
513
514 \param taylor
515 matrix of Taylor coefficients (not used).
516
517 \param nc_partial
518 number of colums in the matrix containing all the partial derivatives
519 (not used if arg[2] is zero).
520
521 \param partial
522 If arg[2] is zero, y[x] is a parameter
523 and no values need to be modified; i.e., partial is not used.
524 Otherwise, y[x] is a variable and:
525 \n
526 \n
527 partial [ i_z * nc_partial + k ]
528 for k = 0 , ... , d
529 is the partial derivative of G
530 with respect to the k-th order Taylor coefficient for z.
531 \n
532 \n
533 If arg[2] is not zero,
534 partial [ arg[2] * nc_partial + k ]
535 for k = 0 , ... , d
536 is the partial derivative with respect to
537 the k-th order Taylor coefficient for x.
538 On input, it corresponds to the function G,
539 and on output it corresponds to the the function H.
540
541 \param load_op2var
542 is a vector with size play->num_var_load_rec().
543 It contains the variable index corresponding to each load instruction.
544 In the case where the index is zero,
545 the instruction corresponds to a parameter (not variable).
546
547 \par Checked Assertions
548 \li NumArg(op) == 3
549 \li NumRes(op) == 1
550 \li d < cap_order
551 \li size_t(arg[2]) < i_z
552 */
553 template <class Addr, class Base>
554 void reverse_load_op(
555 OpCode op ,
556 size_t d ,
557 size_t i_z ,
558 const Addr* arg ,
559 size_t cap_order ,
560 const Base* taylor ,
561 size_t nc_partial ,
562 Base* partial ,
563 const Addr* load_op2var )
564 { size_t i_load = size_t( load_op2var[ arg[2] ] );
565
566 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
567 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
568 CPPAD_ASSERT_UNKNOWN( d < cap_order );
569 CPPAD_ASSERT_UNKNOWN( i_load < i_z );
570
571 if( i_load > 0 )
572 {
573 Base* pz = partial + i_z * nc_partial;
574 Base* py_x = partial + i_load * nc_partial;
575 size_t j = d + 1;
576 while(j--)
577 py_x[j] += pz[j];
578 }
579 }
580
581
582 /*!
583 Forward mode sparsity operations for LdpOp and LdvOp
584
585 \param dependency
586 is this a dependency (or sparsity) calculation.
587
588 \copydetails CppAD::local::sparse_load_op
589 */
590 template <class Vector_set, class Addr>
591 void forward_sparse_load_op(
592 bool dependency ,
593 OpCode op ,
594 size_t i_z ,
595 const Addr* arg ,
596 size_t num_combined ,
597 const size_t* combined ,
598 Vector_set& var_sparsity ,
599 Vector_set& vecad_sparsity )
600 {
601 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
602 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
603 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
604 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
605 size_t i_v = combined[ arg[0] - 1 ];
606 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
607
608 var_sparsity.assignment(i_z, i_v, vecad_sparsity);
609 if( dependency & (op == LdvOp) )
610 var_sparsity.binary_union(i_z, i_z, size_t(arg[1]), var_sparsity);
611
612 return;
613 }
614
615
616 /*!
617 Reverse mode Jacobian sparsity operations for LdpOp and LdvOp
618
619 \param dependency
620 is this a dependency (or sparsity) calculation.
621
622 \copydetails CppAD::local::sparse_load_op
623 */
624 template <class Vector_set, class Addr>
625 void reverse_sparse_jacobian_load_op(
626 bool dependency ,
627 OpCode op ,
628 size_t i_z ,
629 const Addr* arg ,
630 size_t num_combined ,
631 const size_t* combined ,
632 Vector_set& var_sparsity ,
633 Vector_set& vecad_sparsity )
634 {
635 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
636 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
637 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
638 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
639 size_t i_v = combined[ arg[0] - 1 ];
640 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
641
642 vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity);
643 if( dependency & (op == LdvOp) )
644 var_sparsity.binary_union( size_t(arg[1]), size_t(arg[1]), i_z, var_sparsity);
645
646 return;
647 }
648
649
650 /*!
651 Reverse mode Hessian sparsity operations for LdpOp and LdvOp
652
653 \copydetails CppAD::local::sparse_load_op
654
655 \param var_jacobian
656 var_jacobian[i_z]
657 is false (true) if the Jacobian of G with respect to z is always zero
658 (many be non-zero).
659
660 \param vecad_jacobian
661 vecad_jacobian[i_v]
662 is false (true) if the Jacobian with respect to x is always zero
663 (may be non-zero).
664 On input, it corresponds to the function G,
665 and on output it corresponds to the function H.
666
667 */
668 template <class Vector_set, class Addr>
669 void reverse_sparse_hessian_load_op(
670 OpCode op ,
671 size_t i_z ,
672 const Addr* arg ,
673 size_t num_combined ,
674 const size_t* combined ,
675 Vector_set& var_sparsity ,
676 Vector_set& vecad_sparsity ,
677 bool* var_jacobian ,
678 bool* vecad_jacobian )
679 {
680 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
681 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
682 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
683 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
684 size_t i_v = combined[ arg[0] - 1 ];
685 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
686
687 vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity);
688
689 vecad_jacobian[i_v] |= var_jacobian[i_z];
690
691 return;
692 }
693
694
695 } } // END_CPPAD_LOCAL_NAMESPACE
696 # endif
+0
-203
include/cppad/local/log1p_op.hpp less more
0 # ifndef CPPAD_LOCAL_LOG1P_OP_HPP
1 # define CPPAD_LOCAL_LOG1P_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file log1p_op.hpp
18 Forward and reverse mode calculations for z = log1p(x).
19 */
20
21 /*!
22 Compute forward mode Taylor coefficient for result of op = Log1pOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = log1p(x)
27 \endverbatim
28
29 \copydetails CppAD::local::forward_unary1_op
30 */
31 template <class Base>
32 void forward_log1p_op(
33 size_t p ,
34 size_t q ,
35 size_t i_z ,
36 size_t i_x ,
37 size_t cap_order ,
38 Base* taylor )
39 {
40 size_t k;
41
42 // check assumptions
43 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
44 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
45 CPPAD_ASSERT_UNKNOWN( q < cap_order );
46 CPPAD_ASSERT_UNKNOWN( p <= q );
47
48 // Taylor coefficients corresponding to argument and result
49 Base* x = taylor + i_x * cap_order;
50 Base* z = taylor + i_z * cap_order;
51
52 if( p == 0 )
53 { z[0] = log1p( x[0] );
54 p++;
55 if( q == 0 )
56 return;
57 }
58 if ( p == 1 )
59 { z[1] = x[1] / (Base(1.0) + x[0]);
60 p++;
61 }
62 for(size_t j = p; j <= q; j++)
63 {
64 z[j] = -z[1] * x[j-1];
65 for(k = 2; k < j; k++)
66 z[j] -= Base(double(k)) * z[k] * x[j-k];
67 z[j] /= Base(double(j));
68 z[j] += x[j];
69 z[j] /= (Base(1.0) + x[0]);
70 }
71 }
72
73 /*!
74 Muiltiple directions Taylor coefficient for op = Log1pOp.
75
76 The C++ source code corresponding to this operation is
77 \verbatim
78 z = log1p(x)
79 \endverbatim
80
81 \copydetails CppAD::local::forward_unary1_op_dir
82 */
83 template <class Base>
84 void forward_log1p_op_dir(
85 size_t q ,
86 size_t r ,
87 size_t i_z ,
88 size_t i_x ,
89 size_t cap_order ,
90 Base* taylor )
91 {
92
93 // check assumptions
94 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
95 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
96 CPPAD_ASSERT_UNKNOWN( 0 < q );
97 CPPAD_ASSERT_UNKNOWN( q < cap_order );
98
99 // Taylor coefficients corresponding to argument and result
100 size_t num_taylor_per_var = (cap_order-1) * r + 1;
101 Base* x = taylor + i_x * num_taylor_per_var;
102 Base* z = taylor + i_z * num_taylor_per_var;
103
104 size_t m = (q-1) * r + 1;
105 for(size_t ell = 0; ell < r; ell++)
106 { z[m+ell] = Base(double(q)) * x[m+ell];
107 for(size_t k = 1; k < q; k++)
108 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
109 z[m+ell] /= (Base(double(q)) + Base(q) * x[0]);
110 }
111 }
112
113 /*!
114 Compute zero order forward mode Taylor coefficient for result of op = Log1pOp.
115
116 The C++ source code corresponding to this operation is
117 \verbatim
118 z = log1p(x)
119 \endverbatim
120
121 \copydetails CppAD::local::forward_unary1_op_0
122 */
123 template <class Base>
124 void forward_log1p_op_0(
125 size_t i_z ,
126 size_t i_x ,
127 size_t cap_order ,
128 Base* taylor )
129 {
130
131 // check assumptions
132 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
133 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
134 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
135
136 // Taylor coefficients corresponding to argument and result
137 Base* x = taylor + i_x * cap_order;
138 Base* z = taylor + i_z * cap_order;
139
140 z[0] = log1p( x[0] );
141 }
142
143 /*!
144 Compute reverse mode partial derivatives for result of op = Log1pOp.
145
146 The C++ source code corresponding to this operation is
147 \verbatim
148 z = log1p(x)
149 \endverbatim
150
151 \copydetails CppAD::local::reverse_unary1_op
152 */
153
154 template <class Base>
155 void reverse_log1p_op(
156 size_t d ,
157 size_t i_z ,
158 size_t i_x ,
159 size_t cap_order ,
160 const Base* taylor ,
161 size_t nc_partial ,
162 Base* partial )
163 { size_t j, k;
164
165 // check assumptions
166 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
167 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
168 CPPAD_ASSERT_UNKNOWN( d < cap_order );
169 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
170
171 // Taylor coefficients and partials corresponding to argument
172 const Base* x = taylor + i_x * cap_order;
173 Base* px = partial + i_x * nc_partial;
174
175 // Taylor coefficients and partials corresponding to result
176 const Base* z = taylor + i_z * cap_order;
177 Base* pz = partial + i_z * nc_partial;
178
179 Base inv_1px0 = Base(1.0) / (Base(1) + x[0]);
180
181 j = d;
182 while(j)
183 { // scale partial w.r.t z[j]
184 pz[j] = azmul(pz[j] , inv_1px0);
185
186 px[0] -= azmul(pz[j], z[j]);
187 px[j] += pz[j];
188
189 // further scale partial w.r.t. z[j]
190 pz[j] /= Base(double(j));
191
192 for(k = 1; k < j; k++)
193 { pz[k] -= Base(double(k)) * azmul(pz[j], x[j-k]);
194 px[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
195 }
196 --j;
197 }
198 px[0] += azmul(pz[0], inv_1px0);
199 }
200
201 } } // END_CPPAD_LOCAL_NAMESPACE
202 # endif
+0
-202
include/cppad/local/log_op.hpp less more
0 # ifndef CPPAD_LOCAL_LOG_OP_HPP
1 # define CPPAD_LOCAL_LOG_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file log_op.hpp
17 Forward and reverse mode calculations for z = log(x).
18 */
19
20 /*!
21 Compute forward mode Taylor coefficient for result of op = LogOp.
22
23 The C++ source code corresponding to this operation is
24 \verbatim
25 z = log(x)
26 \endverbatim
27
28 \copydetails CppAD::local::forward_unary1_op
29 */
30 template <class Base>
31 void forward_log_op(
32 size_t p ,
33 size_t q ,
34 size_t i_z ,
35 size_t i_x ,
36 size_t cap_order ,
37 Base* taylor )
38 {
39 size_t k;
40
41 // check assumptions
42 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
43 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
44 CPPAD_ASSERT_UNKNOWN( q < cap_order );
45 CPPAD_ASSERT_UNKNOWN( p <= q );
46
47 // Taylor coefficients corresponding to argument and result
48 Base* x = taylor + i_x * cap_order;
49 Base* z = taylor + i_z * cap_order;
50
51 if( p == 0 )
52 { z[0] = log( x[0] );
53 p++;
54 if( q == 0 )
55 return;
56 }
57 if ( p == 1 )
58 { z[1] = x[1] / x[0];
59 p++;
60 }
61 for(size_t j = p; j <= q; j++)
62 {
63 z[j] = -z[1] * x[j-1];
64 for(k = 2; k < j; k++)
65 z[j] -= Base(double(k)) * z[k] * x[j-k];
66 z[j] /= Base(double(j));
67 z[j] += x[j];
68 z[j] /= x[0];
69 }
70 }
71
72 /*!
73 Muiltiple directions Taylor coefficient for op = LogOp.
74
75 The C++ source code corresponding to this operation is
76 \verbatim
77 z = log(x)
78 \endverbatim
79
80 \copydetails CppAD::local::forward_unary1_op_dir
81 */
82 template <class Base>
83 void forward_log_op_dir(
84 size_t q ,
85 size_t r ,
86 size_t i_z ,
87 size_t i_x ,
88 size_t cap_order ,
89 Base* taylor )
90 {
91
92 // check assumptions
93 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
94 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
95 CPPAD_ASSERT_UNKNOWN( 0 < q );
96 CPPAD_ASSERT_UNKNOWN( q < cap_order );
97
98 // Taylor coefficients corresponding to argument and result
99 size_t num_taylor_per_var = (cap_order-1) * r + 1;
100 Base* x = taylor + i_x * num_taylor_per_var;
101 Base* z = taylor + i_z * num_taylor_per_var;
102
103 size_t m = (q-1) * r + 1;
104 for(size_t ell = 0; ell < r; ell++)
105 { z[m+ell] = Base(double(q)) * x[m+ell];
106 for(size_t k = 1; k < q; k++)
107 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
108 z[m+ell] /= (Base(double(q)) * x[0]);
109 }
110 }
111
112 /*!
113 Compute zero order forward mode Taylor coefficient for result of op = LogOp.
114
115 The C++ source code corresponding to this operation is
116 \verbatim
117 z = log(x)
118 \endverbatim
119
120 \copydetails CppAD::local::forward_unary1_op_0
121 */
122 template <class Base>
123 void forward_log_op_0(
124 size_t i_z ,
125 size_t i_x ,
126 size_t cap_order ,
127 Base* taylor )
128 {
129
130 // check assumptions
131 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
132 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
133 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
134
135 // Taylor coefficients corresponding to argument and result
136 Base* x = taylor + i_x * cap_order;
137 Base* z = taylor + i_z * cap_order;
138
139 z[0] = log( x[0] );
140 }
141
142 /*!
143 Compute reverse mode partial derivatives for result of op = LogOp.
144
145 The C++ source code corresponding to this operation is
146 \verbatim
147 z = log(x)
148 \endverbatim
149
150 \copydetails CppAD::local::reverse_unary1_op
151 */
152
153 template <class Base>
154 void reverse_log_op(
155 size_t d ,
156 size_t i_z ,
157 size_t i_x ,
158 size_t cap_order ,
159 const Base* taylor ,
160 size_t nc_partial ,
161 Base* partial )
162 { size_t j, k;
163
164 // check assumptions
165 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
166 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
167 CPPAD_ASSERT_UNKNOWN( d < cap_order );
168 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
169
170 // Taylor coefficients and partials corresponding to argument
171 const Base* x = taylor + i_x * cap_order;
172 Base* px = partial + i_x * nc_partial;
173
174 // Taylor coefficients and partials corresponding to result
175 const Base* z = taylor + i_z * cap_order;
176 Base* pz = partial + i_z * nc_partial;
177
178 Base inv_x0 = Base(1.0) / x[0];
179
180 j = d;
181 while(j)
182 { // scale partial w.r.t z[j]
183 pz[j] = azmul(pz[j] , inv_x0);
184
185 px[0] -= azmul(pz[j], z[j]);
186 px[j] += pz[j];
187
188 // further scale partial w.r.t. z[j]
189 pz[j] /= Base(double(j));
190
191 for(k = 1; k < j; k++)
192 { pz[k] -= Base(double(k)) * azmul(pz[j], x[j-k]);
193 px[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
194 }
195 --j;
196 }
197 px[0] += azmul(pz[0], inv_x0);
198 }
199
200 } } // END_CPPAD_LOCAL_NAMESPACE
201 # endif
+0
-359
include/cppad/local/mul_op.hpp less more
0 # ifndef CPPAD_LOCAL_MUL_OP_HPP
1 # define CPPAD_LOCAL_MUL_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file mul_op.hpp
17 Forward and reverse mode calculations for z = x * y.
18 */
19
20 // --------------------------- Mulvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = MulvvOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = x * y
27 \endverbatim
28 In the documentation below,
29 this operations is for the case where both x and y are variables
30 and the argument parameter is not used.
31
32 \copydetails CppAD::local::forward_binary_op
33 */
34
35 template <class Base>
36 void forward_mulvv_op(
37 size_t p ,
38 size_t q ,
39 size_t i_z ,
40 const addr_t* arg ,
41 const Base* parameter ,
42 size_t cap_order ,
43 Base* taylor )
44 {
45 // check assumptions
46 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
47 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
48 CPPAD_ASSERT_UNKNOWN( q < cap_order );
49 CPPAD_ASSERT_UNKNOWN( p <= q );
50
51 // Taylor coefficients corresponding to arguments and result
52 Base* x = taylor + size_t(arg[0]) * cap_order;
53 Base* y = taylor + size_t(arg[1]) * cap_order;
54 Base* z = taylor + i_z * cap_order;
55
56 size_t k;
57 for(size_t d = p; d <= q; d++)
58 { z[d] = Base(0.0);
59 for(k = 0; k <= d; k++)
60 z[d] += x[d-k] * y[k];
61 }
62 }
63 /*!
64 Multiple directions forward mode Taylor coefficients for op = MulvvOp.
65
66 The C++ source code corresponding to this operation is
67 \verbatim
68 z = x * y
69 \endverbatim
70 In the documentation below,
71 this operations is for the case where both x and y are variables
72 and the argument parameter is not used.
73
74 \copydetails CppAD::local::forward_binary_op_dir
75 */
76
77 template <class Base>
78 void forward_mulvv_op_dir(
79 size_t q ,
80 size_t r ,
81 size_t i_z ,
82 const addr_t* arg ,
83 const Base* parameter ,
84 size_t cap_order ,
85 Base* taylor )
86 {
87 // check assumptions
88 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
89 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
90 CPPAD_ASSERT_UNKNOWN( 0 < q );
91 CPPAD_ASSERT_UNKNOWN( q < cap_order );
92
93 // Taylor coefficients corresponding to arguments and result
94 size_t num_taylor_per_var = (cap_order-1) * r + 1;
95 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
96 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
97 Base* z = taylor + i_z * num_taylor_per_var;
98
99 size_t k, ell, m;
100 for(ell = 0; ell < r; ell++)
101 { m = (q-1)*r + ell + 1;
102 z[m] = x[0] * y[m] + x[m] * y[0];
103 for(k = 1; k < q; k++)
104 z[m] += x[(q-k-1)*r + ell + 1] * y[(k-1)*r + ell + 1];
105 }
106 }
107
108 /*!
109 Compute zero order forward mode Taylor coefficients for result of op = MulvvOp.
110
111 The C++ source code corresponding to this operation is
112 \verbatim
113 z = x * y
114 \endverbatim
115 In the documentation below,
116 this operations is for the case where both x and y are variables
117 and the argument parameter is not used.
118
119 \copydetails CppAD::local::forward_binary_op_0
120 */
121
122 template <class Base>
123 void forward_mulvv_op_0(
124 size_t i_z ,
125 const addr_t* arg ,
126 const Base* parameter ,
127 size_t cap_order ,
128 Base* taylor )
129 {
130 // check assumptions
131 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
132 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
133
134 // Taylor coefficients corresponding to arguments and result
135 Base* x = taylor + size_t(arg[0]) * cap_order;
136 Base* y = taylor + size_t(arg[1]) * cap_order;
137 Base* z = taylor + i_z * cap_order;
138
139 z[0] = x[0] * y[0];
140 }
141
142 /*!
143 Compute reverse mode partial derivatives for result of op = MulvvOp.
144
145 The C++ source code corresponding to this operation is
146 \verbatim
147 z = x * y
148 \endverbatim
149 In the documentation below,
150 this operations is for the case where both x and y are variables
151 and the argument parameter is not used.
152
153 \copydetails CppAD::local::reverse_binary_op
154 */
155
156 template <class Base>
157 void reverse_mulvv_op(
158 size_t d ,
159 size_t i_z ,
160 const addr_t* arg ,
161 const Base* parameter ,
162 size_t cap_order ,
163 const Base* taylor ,
164 size_t nc_partial ,
165 Base* partial )
166 {
167 // check assumptions
168 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
169 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
170 CPPAD_ASSERT_UNKNOWN( d < cap_order );
171 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
172
173 // Arguments
174 const Base* x = taylor + size_t(arg[0]) * cap_order;
175 const Base* y = taylor + size_t(arg[1]) * cap_order;
176
177 // Partial derivatives corresponding to arguments and result
178 Base* px = partial + size_t(arg[0]) * nc_partial;
179 Base* py = partial + size_t(arg[1]) * nc_partial;
180 Base* pz = partial + i_z * nc_partial;
181
182
183 // number of indices to access
184 size_t j = d + 1;
185 size_t k;
186 while(j)
187 { --j;
188 for(k = 0; k <= j; k++)
189 {
190 px[j-k] += azmul(pz[j], y[k]);
191 py[k] += azmul(pz[j], x[j-k]);
192 }
193 }
194 }
195 // --------------------------- Mulpv -----------------------------------------
196 /*!
197 Compute forward mode Taylor coefficients for result of op = MulpvOp.
198
199 The C++ source code corresponding to this operation is
200 \verbatim
201 z = x * y
202 \endverbatim
203 In the documentation below,
204 this operations is for the case where x is a parameter and y is a variable.
205
206 \copydetails CppAD::local::forward_binary_op
207 */
208
209 template <class Base>
210 void forward_mulpv_op(
211 size_t p ,
212 size_t q ,
213 size_t i_z ,
214 const addr_t* arg ,
215 const Base* parameter ,
216 size_t cap_order ,
217 Base* taylor )
218 {
219 // check assumptions
220 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
221 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
222 CPPAD_ASSERT_UNKNOWN( q < cap_order );
223 CPPAD_ASSERT_UNKNOWN( p <= q );
224
225 // Taylor coefficients corresponding to arguments and result
226 Base* y = taylor + size_t(arg[1]) * cap_order;
227 Base* z = taylor + i_z * cap_order;
228
229 // Paraemter value
230 Base x = parameter[ arg[0] ];
231
232 for(size_t d = p; d <= q; d++)
233 z[d] = x * y[d];
234 }
235 /*!
236 Multiple directions forward mode Taylor coefficients for op = MulpvOp.
237
238 The C++ source code corresponding to this operation is
239 \verbatim
240 z = x * y
241 \endverbatim
242 In the documentation below,
243 this operations is for the case where x is a parameter and y is a variable.
244
245 \copydetails CppAD::local::forward_binary_op_dir
246 */
247
248 template <class Base>
249 void forward_mulpv_op_dir(
250 size_t q ,
251 size_t r ,
252 size_t i_z ,
253 const addr_t* arg ,
254 const Base* parameter ,
255 size_t cap_order ,
256 Base* taylor )
257 {
258 // check assumptions
259 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
260 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
261 CPPAD_ASSERT_UNKNOWN( 0 < q );
262 CPPAD_ASSERT_UNKNOWN( q < cap_order );
263
264 // Taylor coefficients corresponding to arguments and result
265 size_t num_taylor_per_var = (cap_order-1) * r + 1;
266 size_t m = (q-1) * r + 1;
267 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
268 Base* z = taylor + i_z * num_taylor_per_var + m;
269
270 // Paraemter value
271 Base x = parameter[ arg[0] ];
272
273 for(size_t ell = 0; ell < r; ell++)
274 z[ell] = x * y[ell];
275 }
276 /*!
277 Compute zero order forward mode Taylor coefficient for result of op = MulpvOp.
278
279 The C++ source code corresponding to this operation is
280 \verbatim
281 z = x * y
282 \endverbatim
283 In the documentation below,
284 this operations is for the case where x is a parameter and y is a variable.
285
286 \copydetails CppAD::local::forward_binary_op_0
287 */
288
289 template <class Base>
290 void forward_mulpv_op_0(
291 size_t i_z ,
292 const addr_t* arg ,
293 const Base* parameter ,
294 size_t cap_order ,
295 Base* taylor )
296 {
297 // check assumptions
298 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
299 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
300
301 // Paraemter value
302 Base x = parameter[ arg[0] ];
303
304 // Taylor coefficients corresponding to arguments and result
305 Base* y = taylor + size_t(arg[1]) * cap_order;
306 Base* z = taylor + i_z * cap_order;
307
308 z[0] = x * y[0];
309 }
310
311 /*!
312 Compute reverse mode partial derivative for result of op = MulpvOp.
313
314 The C++ source code corresponding to this operation is
315 \verbatim
316 z = x * y
317 \endverbatim
318 In the documentation below,
319 this operations is for the case where x is a parameter and y is a variable.
320
321 \copydetails CppAD::local::reverse_binary_op
322 */
323
324 template <class Base>
325 void reverse_mulpv_op(
326 size_t d ,
327 size_t i_z ,
328 const addr_t* arg ,
329 const Base* parameter ,
330 size_t cap_order ,
331 const Base* taylor ,
332 size_t nc_partial ,
333 Base* partial )
334 {
335 // check assumptions
336 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
337 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
338 CPPAD_ASSERT_UNKNOWN( d < cap_order );
339 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
340
341 // Arguments
342 Base x = parameter[ arg[0] ];
343
344 // Partial derivatives corresponding to arguments and result
345 Base* py = partial + size_t(arg[1]) * nc_partial;
346 Base* pz = partial + i_z * nc_partial;
347
348 // number of indices to access
349 size_t j = d + 1;
350 while(j)
351 { --j;
352 py[j] += azmul(pz[j], x);
353 }
354 }
355
356
357 } } // END_CPPAD_LOCAL_NAMESPACE
358 # endif
0 # ifndef CPPAD_LOCAL_OP_ABS_OP_HPP
1 # define CPPAD_LOCAL_OP_ABS_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17 // See dev documentation: forward_unary_op
18 template <class Base>
19 void forward_abs_op(
20 size_t p ,
21 size_t q ,
22 size_t i_z ,
23 size_t i_x ,
24 size_t cap_order ,
25 Base* taylor )
26 {
27 // check assumptions
28 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
29 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( q < cap_order );
31 CPPAD_ASSERT_UNKNOWN( p <= q );
32
33 // Taylor coefficients corresponding to argument and result
34 Base* x = taylor + i_x * cap_order;
35 Base* z = taylor + i_z * cap_order;
36
37 for(size_t j = p; j <= q; j++)
38 z[j] = sign(x[0]) * x[j];
39 }
40
41 // See dev documentation: forward_unary_op
42 template <class Base>
43 void forward_abs_op_dir(
44 size_t q ,
45 size_t r ,
46 size_t i_z ,
47 size_t i_x ,
48 size_t cap_order ,
49 Base* taylor )
50 {
51 // check assumptions
52 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
53 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
54 CPPAD_ASSERT_UNKNOWN( 0 < q );
55 CPPAD_ASSERT_UNKNOWN( q < cap_order );
56
57 // Taylor coefficients corresponding to argument and result
58 size_t num_taylor_per_var = (cap_order-1) * r + 1;
59 Base* x = taylor + i_x * num_taylor_per_var;
60 Base* z = taylor + i_z * num_taylor_per_var;
61
62 size_t m = (q-1) * r + 1;
63 for(size_t ell = 0; ell < r; ell++)
64 z[m + ell] = sign(x[0]) * x[m + ell];
65 }
66
67 // See dev documentation: forward_unary_op
68 template <class Base>
69 void forward_abs_op_0(
70 size_t i_z ,
71 size_t i_x ,
72 size_t cap_order ,
73 Base* taylor )
74 {
75
76 // check assumptions
77 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
78 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
79 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
80
81 // Taylor coefficients corresponding to argument and result
82 Base x0 = *(taylor + i_x * cap_order);
83 Base* z = taylor + i_z * cap_order;
84
85 z[0] = fabs(x0);
86 }
87
88 // See dev documentation: reverse_unary_op
89 template <class Base>
90 void reverse_abs_op(
91 size_t d ,
92 size_t i_z ,
93 size_t i_x ,
94 size_t cap_order ,
95 const Base* taylor ,
96 size_t nc_partial ,
97 Base* partial )
98 { size_t j;
99
100 // check assumptions
101 CPPAD_ASSERT_UNKNOWN( NumArg(AbsOp) == 1 );
102 CPPAD_ASSERT_UNKNOWN( NumRes(AbsOp) == 1 );
103 CPPAD_ASSERT_UNKNOWN( d < cap_order );
104 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
105
106 // Taylor coefficients and partials corresponding to argument
107 const Base* x = taylor + i_x * cap_order;
108 Base* px = partial + i_x * nc_partial;
109
110 // Taylor coefficients and partials corresponding to result
111 Base* pz = partial + i_z * nc_partial;
112
113 // do not need azmul because sign is either +1, -1, or zero
114 for(j = 0; j <= d; j++)
115 px[j] += sign(x[0]) * pz[j];
116 }
117
118 } } // END_CPPAD_LOCAL_NAMESPACE
119 # endif
0 # ifndef CPPAD_LOCAL_OP_ACOS_OP_HPP
1 # define CPPAD_LOCAL_OP_ACOS_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_acos_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37 Base* b = z - cap_order; // called y in documentation
38
39 size_t k;
40 Base uj;
41 if( p == 0 )
42 { z[0] = acos( x[0] );
43 uj = Base(1.0) - x[0] * x[0];
44 b[0] = sqrt( uj );
45 p++;
46 }
47 for(size_t j = p; j <= q; j++)
48 { uj = Base(0.0);
49 for(k = 0; k <= j; k++)
50 uj -= x[k] * x[j-k];
51 b[j] = Base(0.0);
52 z[j] = Base(0.0);
53 for(k = 1; k < j; k++)
54 { b[j] -= Base(double(k)) * b[k] * b[j-k];
55 z[j] -= Base(double(k)) * z[k] * b[j-k];
56 }
57 b[j] /= Base(double(j));
58 z[j] /= Base(double(j));
59 //
60 b[j] += uj / Base(2.0);
61 z[j] -= x[j];
62 //
63 b[j] /= b[0];
64 z[j] /= b[0];
65 }
66 }
67 // See dev documentation: forward_unary_op
68 template <class Base>
69 void forward_acos_op_dir(
70 size_t q ,
71 size_t r ,
72 size_t i_z ,
73 size_t i_x ,
74 size_t cap_order ,
75 Base* taylor )
76 {
77 // check assumptions
78 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
79 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
80 CPPAD_ASSERT_UNKNOWN( 0 < q );
81 CPPAD_ASSERT_UNKNOWN( q < cap_order );
82
83 // Taylor coefficients corresponding to argument and result
84 size_t num_taylor_per_var = (cap_order-1) * r + 1;
85 Base* x = taylor + i_x * num_taylor_per_var;
86 Base* z = taylor + i_z * num_taylor_per_var;
87 Base* b = z - num_taylor_per_var; // called y in documentation
88
89 size_t k, ell;
90 size_t m = (q-1) * r + 1;
91 for(ell = 0; ell < r; ell ++)
92 { Base uq = - 2.0 * x[m + ell] * x[0];
93 for(k = 1; k < q; k++)
94 uq -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
95 b[m+ell] = Base(0.0);
96 z[m+ell] = Base(0.0);
97 for(k = 1; k < q; k++)
98 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
99 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
100 }
101 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
102 z[m+ell] = -( x[m+ell] + z[m+ell] / Base(double(q)) ) / b[0];
103 }
104 }
105
106 // See dev documentation: forward_unary_op
107 template <class Base>
108 void forward_acos_op_0(
109 size_t i_z ,
110 size_t i_x ,
111 size_t cap_order ,
112 Base* taylor )
113 {
114 // check assumptions
115 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
116 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
117 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
118
119 // Taylor coefficients corresponding to argument and result
120 Base* x = taylor + i_x * cap_order;
121 Base* z = taylor + i_z * cap_order;
122 Base* b = z - cap_order; // called y in documentation
123
124 z[0] = acos( x[0] );
125 b[0] = sqrt( Base(1.0) - x[0] * x[0] );
126 }
127
128 // See dev documentation: reverse_unary_op
129 template <class Base>
130 void reverse_acos_op(
131 size_t d ,
132 size_t i_z ,
133 size_t i_x ,
134 size_t cap_order ,
135 const Base* taylor ,
136 size_t nc_partial ,
137 Base* partial )
138 {
139 // check assumptions
140 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
141 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
142 CPPAD_ASSERT_UNKNOWN( d < cap_order );
143 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
144
145 // Taylor coefficients and partials corresponding to argument
146 const Base* x = taylor + i_x * cap_order;
147 Base* px = partial + i_x * nc_partial;
148
149 // Taylor coefficients and partials corresponding to first result
150 const Base* z = taylor + i_z * cap_order;
151 Base* pz = partial + i_z * nc_partial;
152
153 // Taylor coefficients and partials corresponding to auxillary result
154 const Base* b = z - cap_order; // called y in documentation
155 Base* pb = pz - nc_partial;
156
157 Base inv_b0 = Base(1.0) / b[0];
158
159 // number of indices to access
160 size_t j = d;
161 size_t k;
162 while(j)
163 {
164 // scale partials w.r.t b[j] by 1 / b[0]
165 pb[j] = azmul(pb[j], inv_b0);
166
167 // scale partials w.r.t z[j] by 1 / b[0]
168 pz[j] = azmul(pz[j], inv_b0);
169
170 // update partials w.r.t b^0
171 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
172
173 // update partial w.r.t. x^0
174 px[0] -= azmul(pb[j], x[j]);
175
176 // update partial w.r.t. x^j
177 px[j] -= pz[j] + azmul(pb[j], x[0]);
178
179 // further scale partial w.r.t. z[j] by 1 / j
180 pz[j] /= Base(double(j));
181
182 for(k = 1; k < j; k++)
183 { // update partials w.r.t b^(j-k)
184 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
185
186 // update partials w.r.t. x^k
187 px[k] -= azmul(pb[j], x[j-k]);
188
189 // update partials w.r.t. z^k
190 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
191 }
192 --j;
193 }
194
195 // j == 0 case
196 px[0] -= azmul( pz[0] + azmul(pb[0], x[0]), inv_b0);
197 }
198
199 } } // END_CPPAD_LOCAL_NAMESPACE
200 # endif
0 # ifndef CPPAD_LOCAL_OP_ACOSH_OP_HPP
1 # define CPPAD_LOCAL_OP_ACOSH_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17
18
19 // See dev documentation: forward_unary_op
20 template <class Base>
21 void forward_acosh_op(
22 size_t p ,
23 size_t q ,
24 size_t i_z ,
25 size_t i_x ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to argument and result
36 Base* x = taylor + i_x * cap_order;
37 Base* z = taylor + i_z * cap_order;
38 Base* b = z - cap_order; // called y in documentation
39
40 size_t k;
41 Base uj;
42 if( p == 0 )
43 { z[0] = acosh( x[0] );
44 uj = x[0] * x[0] - Base(1.0);
45 b[0] = sqrt( uj );
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 { uj = Base(0.0);
50 for(k = 0; k <= j; k++)
51 uj += x[k] * x[j-k];
52 b[j] = Base(0.0);
53 z[j] = Base(0.0);
54 for(k = 1; k < j; k++)
55 { b[j] -= Base(double(k)) * b[k] * b[j-k];
56 z[j] -= Base(double(k)) * z[k] * b[j-k];
57 }
58 b[j] /= Base(double(j));
59 z[j] /= Base(double(j));
60 //
61 b[j] += uj / Base(2.0);
62 z[j] += x[j];
63 //
64 b[j] /= b[0];
65 z[j] /= b[0];
66 }
67 }
68 // See dev documentation: forward_unary_op
69 template <class Base>
70 void forward_acosh_op_dir(
71 size_t q ,
72 size_t r ,
73 size_t i_z ,
74 size_t i_x ,
75 size_t cap_order ,
76 Base* taylor )
77 {
78 // check assumptions
79 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
80 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
81 CPPAD_ASSERT_UNKNOWN( 0 < q );
82 CPPAD_ASSERT_UNKNOWN( q < cap_order );
83
84 // Taylor coefficients corresponding to argument and result
85 size_t num_taylor_per_var = (cap_order-1) * r + 1;
86 Base* x = taylor + i_x * num_taylor_per_var;
87 Base* z = taylor + i_z * num_taylor_per_var;
88 Base* b = z - num_taylor_per_var; // called y in documentation
89
90 size_t k, ell;
91 size_t m = (q-1) * r + 1;
92 for(ell = 0; ell < r; ell ++)
93 { Base uq = 2.0 * x[m + ell] * x[0];
94 for(k = 1; k < q; k++)
95 uq += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
96 b[m+ell] = Base(0.0);
97 z[m+ell] = Base(0.0);
98 for(k = 1; k < q; k++)
99 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
100 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
101 }
102 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
103 z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0];
104 }
105 }
106
107 // See dev documentation: forward_unary_op
108 template <class Base>
109 void forward_acosh_op_0(
110 size_t i_z ,
111 size_t i_x ,
112 size_t cap_order ,
113 Base* taylor )
114 {
115 // check assumptions
116 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
117 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
118 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
119
120 // Taylor coefficients corresponding to argument and result
121 Base* x = taylor + i_x * cap_order;
122 Base* z = taylor + i_z * cap_order;
123 Base* b = z - cap_order; // called y in documentation
124
125 z[0] = acosh( x[0] );
126 b[0] = sqrt( x[0] * x[0] - Base(1.0) );
127 }
128
129 // See dev documentation: reverse_unary_op
130 template <class Base>
131 void reverse_acosh_op(
132 size_t d ,
133 size_t i_z ,
134 size_t i_x ,
135 size_t cap_order ,
136 const Base* taylor ,
137 size_t nc_partial ,
138 Base* partial )
139 {
140 // check assumptions
141 CPPAD_ASSERT_UNKNOWN( NumArg(AcoshOp) == 1 );
142 CPPAD_ASSERT_UNKNOWN( NumRes(AcoshOp) == 2 );
143 CPPAD_ASSERT_UNKNOWN( d < cap_order );
144 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
145
146 // Taylor coefficients and partials corresponding to argument
147 const Base* x = taylor + i_x * cap_order;
148 Base* px = partial + i_x * nc_partial;
149
150 // Taylor coefficients and partials corresponding to first result
151 const Base* z = taylor + i_z * cap_order;
152 Base* pz = partial + i_z * nc_partial;
153
154 // Taylor coefficients and partials corresponding to auxillary result
155 const Base* b = z - cap_order; // called y in documentation
156 Base* pb = pz - nc_partial;
157
158 Base inv_b0 = Base(1.0) / b[0];
159
160 // number of indices to access
161 size_t j = d;
162 size_t k;
163 while(j)
164 {
165 // scale partials w.r.t b[j] by 1 / b[0]
166 pb[j] = azmul(pb[j], inv_b0);
167
168 // scale partials w.r.t z[j] by 1 / b[0]
169 pz[j] = azmul(pz[j], inv_b0);
170
171 // update partials w.r.t b^0
172 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
173
174 // update partial w.r.t. x^0
175 px[0] += azmul(pb[j], x[j]);
176
177 // update partial w.r.t. x^j
178 px[j] += pz[j] + azmul(pb[j], x[0]);
179
180 // further scale partial w.r.t. z[j] by 1 / j
181 pz[j] /= Base(double(j));
182
183 for(k = 1; k < j; k++)
184 { // update partials w.r.t b^(j-k)
185 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
186
187 // update partials w.r.t. x^k
188 px[k] += azmul(pb[j], x[j-k]);
189
190 // update partials w.r.t. z^k
191 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
192 }
193 --j;
194 }
195
196 // j == 0 case
197 px[0] += azmul(pz[0] + azmul(pb[0], x[0]), inv_b0);
198 }
199
200 } } // END_CPPAD_LOCAL_NAMESPACE
201 # endif
0 # ifndef CPPAD_LOCAL_OP_ADD_OP_HPP
1 # define CPPAD_LOCAL_OP_ADD_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15
16 // --------------------------- Addvv -----------------------------------------
17
18 // See dev documentation: forward_unary_op
19 // See dev documentation: forward_binary_op
20 template <class Base>
21 void forward_addvv_op(
22 size_t p ,
23 size_t q ,
24 size_t i_z ,
25 const addr_t* arg ,
26 const Base* parameter ,
27 size_t cap_order ,
28 Base* taylor )
29 {
30 // check assumptions
31 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
32 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
33 CPPAD_ASSERT_UNKNOWN( q < cap_order );
34 CPPAD_ASSERT_UNKNOWN( p <= q );
35
36 // Taylor coefficients corresponding to arguments and result
37 Base* x = taylor + size_t(arg[0]) * cap_order;
38 Base* y = taylor + size_t(arg[1]) * cap_order;
39 Base* z = taylor + i_z * cap_order;
40
41 for(size_t j = p; j <= q; j++)
42 z[j] = x[j] + y[j];
43 }
44
45 // See dev documentation: forward_unary_op
46 // See dev documentation: forward_binary_op
47 template <class Base>
48 void forward_addvv_op_dir(
49 size_t q ,
50 size_t r ,
51 size_t i_z ,
52 const addr_t* arg ,
53 const Base* parameter ,
54 size_t cap_order ,
55 Base* taylor )
56 {
57 // check assumptions
58 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
59 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
60 CPPAD_ASSERT_UNKNOWN( q < cap_order );
61 CPPAD_ASSERT_UNKNOWN( 0 < q );
62
63 // Taylor coefficients corresponding to arguments and result
64 size_t num_taylor_per_var = (cap_order-1) * r + 1;
65 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
66 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
67 Base* z = taylor + i_z * num_taylor_per_var;
68
69 size_t m = (q-1)*r + 1 ;
70 for(size_t ell = 0; ell < r; ell++)
71 z[m+ell] = x[m+ell] + y[m+ell];
72 }
73
74
75 // See dev documentation: forward_unary_op
76 // See dev documentation: forward_binary_op
77 template <class Base>
78 void forward_addvv_op_0(
79 size_t i_z ,
80 const addr_t* arg ,
81 const Base* parameter ,
82 size_t cap_order ,
83 Base* taylor )
84 {
85 // check assumptions
86 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
87 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
88
89 // Taylor coefficients corresponding to arguments and result
90 Base* x = taylor + size_t(arg[0]) * cap_order;
91 Base* y = taylor + size_t(arg[1]) * cap_order;
92 Base* z = taylor + i_z * cap_order;
93
94 z[0] = x[0] + y[0];
95 }
96
97
98 // See dev documentation: reverse_unary_op
99 // See dev documentation: reverse_binary_op
100 template <class Base>
101 void reverse_addvv_op(
102 size_t d ,
103 size_t i_z ,
104 const addr_t* arg ,
105 const Base* parameter ,
106 size_t cap_order ,
107 const Base* taylor ,
108 size_t nc_partial ,
109 Base* partial )
110 {
111 // check assumptions
112 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
113 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
114 CPPAD_ASSERT_UNKNOWN( d < cap_order );
115 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
116
117 // Partial derivatives corresponding to arguments and result
118 Base* px = partial + size_t(arg[0]) * nc_partial;
119 Base* py = partial + size_t(arg[1]) * nc_partial;
120 Base* pz = partial + i_z * nc_partial;
121
122 // number of indices to access
123 size_t i = d + 1;
124 while(i)
125 { --i;
126 px[i] += pz[i];
127 py[i] += pz[i];
128 }
129 }
130
131 // --------------------------- Addpv -----------------------------------------
132 // See dev documentation: forward_unary_op
133 // See dev documentation: forward_binary_op
134 template <class Base>
135 void forward_addpv_op(
136 size_t p ,
137 size_t q ,
138 size_t i_z ,
139 const addr_t* arg ,
140 const Base* parameter ,
141 size_t cap_order ,
142 Base* taylor )
143 {
144 // check assumptions
145 CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 );
146 CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 );
147 CPPAD_ASSERT_UNKNOWN( q < cap_order );
148 CPPAD_ASSERT_UNKNOWN( p <= q );
149
150 // Taylor coefficients corresponding to arguments and result
151 Base* y = taylor + size_t(arg[1]) * cap_order;
152 Base* z = taylor + i_z * cap_order;
153
154 if( p == 0 )
155 { // Paraemter value
156 Base x = parameter[ arg[0] ];
157 z[0] = x + y[0];
158 p++;
159 }
160 for(size_t j = p; j <= q; j++)
161 z[j] = y[j];
162 }
163 // See dev documentation: forward_unary_op
164 // See dev documentation: forward_binary_op
165 template <class Base>
166 void forward_addpv_op_dir(
167 size_t q ,
168 size_t r ,
169 size_t i_z ,
170 const addr_t* arg ,
171 const Base* parameter ,
172 size_t cap_order ,
173 Base* taylor )
174 {
175 // check assumptions
176 CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 );
177 CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 );
178 CPPAD_ASSERT_UNKNOWN( 0 < q );
179 CPPAD_ASSERT_UNKNOWN( q < cap_order );
180
181 // Taylor coefficients corresponding to arguments and result
182 size_t num_taylor_per_var = (cap_order-1) * r + 1;
183 size_t m = (q-1) * r + 1;
184 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
185 Base* z = taylor + i_z * num_taylor_per_var + m;
186
187 for(size_t ell = 0; ell < r; ell++)
188 z[ell] = y[ell];
189 }
190
191 // See dev documentation: forward_unary_op
192 // See dev documentation: forward_binary_op
193 template <class Base>
194 void forward_addpv_op_0(
195 size_t i_z ,
196 const addr_t* arg ,
197 const Base* parameter ,
198 size_t cap_order ,
199 Base* taylor )
200 {
201 // check assumptions
202 CPPAD_ASSERT_UNKNOWN( NumArg(AddpvOp) == 2 );
203 CPPAD_ASSERT_UNKNOWN( NumRes(AddpvOp) == 1 );
204
205 // Paraemter value
206 Base x = parameter[ arg[0] ];
207
208 // Taylor coefficients corresponding to arguments and result
209 Base* y = taylor + size_t(arg[1]) * cap_order;
210 Base* z = taylor + i_z * cap_order;
211
212 z[0] = x + y[0];
213 }
214
215
216 // See dev documentation: reverse_unary_op
217 // See dev documentation: reverse_binary_op
218 template <class Base>
219 void reverse_addpv_op(
220 size_t d ,
221 size_t i_z ,
222 const addr_t* arg ,
223 const Base* parameter ,
224 size_t cap_order ,
225 const Base* taylor ,
226 size_t nc_partial ,
227 Base* partial )
228 {
229 // check assumptions
230 CPPAD_ASSERT_UNKNOWN( NumArg(AddvvOp) == 2 );
231 CPPAD_ASSERT_UNKNOWN( NumRes(AddvvOp) == 1 );
232 CPPAD_ASSERT_UNKNOWN( d < cap_order );
233 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
234
235 // Partial derivatives corresponding to arguments and result
236 Base* py = partial + size_t(arg[1]) * nc_partial;
237 Base* pz = partial + i_z * nc_partial;
238
239 // number of indices to access
240 size_t i = d + 1;
241 while(i)
242 { --i;
243 py[i] += pz[i];
244 }
245 }
246
247
248 } } // END_CPPAD_LOCAL_NAMESPACE
249 # endif
0 # ifndef CPPAD_LOCAL_OP_ASIN_OP_HPP
1 # define CPPAD_LOCAL_OP_ASIN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_asin_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37 Base* b = z - cap_order; // called y in documentation
38
39 size_t k;
40 Base uj;
41 if( p == 0 )
42 { z[0] = asin( x[0] );
43 uj = Base(1.0) - x[0] * x[0];
44 b[0] = sqrt( uj );
45 p++;
46 }
47 for(size_t j = p; j <= q; j++)
48 { uj = Base(0.0);
49 for(k = 0; k <= j; k++)
50 uj -= x[k] * x[j-k];
51 b[j] = Base(0.0);
52 z[j] = Base(0.0);
53 for(k = 1; k < j; k++)
54 { b[j] -= Base(double(k)) * b[k] * b[j-k];
55 z[j] -= Base(double(k)) * z[k] * b[j-k];
56 }
57 b[j] /= Base(double(j));
58 z[j] /= Base(double(j));
59 //
60 b[j] += uj / Base(2.0);
61 z[j] += x[j];
62 //
63 b[j] /= b[0];
64 z[j] /= b[0];
65 }
66 }
67 // See dev documentation: forward_unary_op
68 template <class Base>
69 void forward_asin_op_dir(
70 size_t q ,
71 size_t r ,
72 size_t i_z ,
73 size_t i_x ,
74 size_t cap_order ,
75 Base* taylor )
76 {
77 // check assumptions
78 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
79 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
80 CPPAD_ASSERT_UNKNOWN( 0 < q );
81 CPPAD_ASSERT_UNKNOWN( q < cap_order );
82
83 // Taylor coefficients corresponding to argument and result
84 size_t num_taylor_per_var = (cap_order-1) * r + 1;
85 Base* x = taylor + i_x * num_taylor_per_var;
86 Base* z = taylor + i_z * num_taylor_per_var;
87 Base* b = z - num_taylor_per_var; // called y in documentation
88
89 size_t k, ell;
90 size_t m = (q-1) * r + 1;
91 for(ell = 0; ell < r; ell ++)
92 { Base uq = - 2.0 * x[m + ell] * x[0];
93 for(k = 1; k < q; k++)
94 uq -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
95 b[m+ell] = Base(0.0);
96 z[m+ell] = Base(0.0);
97 for(k = 1; k < q; k++)
98 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
99 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
100 }
101 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
102 z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0];
103 }
104 }
105
106 // See dev documentation: forward_unary_op
107 template <class Base>
108 void forward_asin_op_0(
109 size_t i_z ,
110 size_t i_x ,
111 size_t cap_order ,
112 Base* taylor )
113 {
114 // check assumptions
115 CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
116 CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
117 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
118
119 // Taylor coefficients corresponding to argument and result
120 Base* x = taylor + i_x * cap_order;
121 Base* z = taylor + i_z * cap_order;
122 Base* b = z - cap_order; // called y in documentation
123
124 z[0] = asin( x[0] );
125 b[0] = sqrt( Base(1.0) - x[0] * x[0] );
126 }
127
128 // See dev documentation: reverse_unary_op
129 template <class Base>
130 void reverse_asin_op(
131 size_t d ,
132 size_t i_z ,
133 size_t i_x ,
134 size_t cap_order ,
135 const Base* taylor ,
136 size_t nc_partial ,
137 Base* partial )
138 {
139 // check assumptions
140 CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
141 CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
142 CPPAD_ASSERT_UNKNOWN( d < cap_order );
143 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
144
145 // Taylor coefficients and partials corresponding to argument
146 const Base* x = taylor + i_x * cap_order;
147 Base* px = partial + i_x * nc_partial;
148
149 // Taylor coefficients and partials corresponding to first result
150 const Base* z = taylor + i_z * cap_order;
151 Base* pz = partial + i_z * nc_partial;
152
153 // Taylor coefficients and partials corresponding to auxillary result
154 const Base* b = z - cap_order; // called y in documentation
155 Base* pb = pz - nc_partial;
156
157 Base inv_b0 = Base(1.0) / b[0];
158
159 // number of indices to access
160 size_t j = d;
161 size_t k;
162 while(j)
163 {
164 // scale partials w.r.t b[j] by 1 / b[0]
165 pb[j] = azmul(pb[j], inv_b0);
166
167 // scale partials w.r.t z[j] by 1 / b[0]
168 pz[j] = azmul(pz[j], inv_b0);
169
170 // update partials w.r.t b^0
171 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
172
173 // update partial w.r.t. x^0
174 px[0] -= azmul(pb[j], x[j]);
175
176 // update partial w.r.t. x^j
177 px[j] += pz[j] - azmul(pb[j], x[0]);
178
179 // further scale partial w.r.t. z[j] by 1 / j
180 pz[j] /= Base(double(j));
181
182 for(k = 1; k < j; k++)
183 { // update partials w.r.t b^(j-k)
184 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
185
186 // update partials w.r.t. x^k
187 px[k] -= azmul(pb[j], x[j-k]);
188
189 // update partials w.r.t. z^k
190 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
191 }
192 --j;
193 }
194
195 // j == 0 case
196 px[0] += azmul(pz[0] - azmul(pb[0], x[0]), inv_b0);
197 }
198
199 } } // END_CPPAD_LOCAL_NAMESPACE
200 # endif
0 # ifndef CPPAD_LOCAL_OP_ASINH_OP_HPP
1 # define CPPAD_LOCAL_OP_ASINH_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17
18
19 // See dev documentation: forward_unary_op
20 template <class Base>
21 void forward_asinh_op(
22 size_t p ,
23 size_t q ,
24 size_t i_z ,
25 size_t i_x ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to argument and result
36 Base* x = taylor + i_x * cap_order;
37 Base* z = taylor + i_z * cap_order;
38 Base* b = z - cap_order; // called y in documentation
39
40 size_t k;
41 Base uj;
42 if( p == 0 )
43 { z[0] = asinh( x[0] );
44 uj = Base(1.0) + x[0] * x[0];
45 b[0] = sqrt( uj );
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 { uj = Base(0.0);
50 for(k = 0; k <= j; k++)
51 uj += x[k] * x[j-k];
52 b[j] = Base(0.0);
53 z[j] = Base(0.0);
54 for(k = 1; k < j; k++)
55 { b[j] -= Base(double(k)) * b[k] * b[j-k];
56 z[j] -= Base(double(k)) * z[k] * b[j-k];
57 }
58 b[j] /= Base(double(j));
59 z[j] /= Base(double(j));
60 //
61 b[j] += uj / Base(2.0);
62 z[j] += x[j];
63 //
64 b[j] /= b[0];
65 z[j] /= b[0];
66 }
67 }
68 // See dev documentation: forward_unary_op
69 template <class Base>
70 void forward_asinh_op_dir(
71 size_t q ,
72 size_t r ,
73 size_t i_z ,
74 size_t i_x ,
75 size_t cap_order ,
76 Base* taylor )
77 {
78 // check assumptions
79 CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
80 CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
81 CPPAD_ASSERT_UNKNOWN( 0 < q );
82 CPPAD_ASSERT_UNKNOWN( q < cap_order );
83
84 // Taylor coefficients corresponding to argument and result
85 size_t num_taylor_per_var = (cap_order-1) * r + 1;
86 Base* x = taylor + i_x * num_taylor_per_var;
87 Base* z = taylor + i_z * num_taylor_per_var;
88 Base* b = z - num_taylor_per_var; // called y in documentation
89
90 size_t k, ell;
91 size_t m = (q-1) * r + 1;
92 for(ell = 0; ell < r; ell ++)
93 { Base uq = 2.0 * x[m + ell] * x[0];
94 for(k = 1; k < q; k++)
95 uq += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
96 b[m+ell] = Base(0.0);
97 z[m+ell] = Base(0.0);
98 for(k = 1; k < q; k++)
99 { b[m+ell] += Base(double(k)) * b[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
100 z[m+ell] += Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
101 }
102 b[m+ell] = ( uq / Base(2.0) - b[m+ell] / Base(double(q)) ) / b[0];
103 z[m+ell] = ( x[m+ell] - z[m+ell] / Base(double(q)) ) / b[0];
104 }
105 }
106
107 // See dev documentation: forward_unary_op
108 template <class Base>
109 void forward_asinh_op_0(
110 size_t i_z ,
111 size_t i_x ,
112 size_t cap_order ,
113 Base* taylor )
114 {
115 // check assumptions
116 CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 );
117 CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 );
118 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
119
120 // Taylor coefficients corresponding to argument and result
121 Base* x = taylor + i_x * cap_order;
122 Base* z = taylor + i_z * cap_order;
123 Base* b = z - cap_order; // called y in documentation
124
125 z[0] = asinh( x[0] );
126 b[0] = sqrt( Base(1.0) + x[0] * x[0] );
127 }
128
129 // See dev documentation: reverse_unary_op
130 template <class Base>
131 void reverse_asinh_op(
132 size_t d ,
133 size_t i_z ,
134 size_t i_x ,
135 size_t cap_order ,
136 const Base* taylor ,
137 size_t nc_partial ,
138 Base* partial )
139 {
140 // check assumptions
141 CPPAD_ASSERT_UNKNOWN( NumArg(AsinhOp) == 1 );
142 CPPAD_ASSERT_UNKNOWN( NumRes(AsinhOp) == 2 );
143 CPPAD_ASSERT_UNKNOWN( d < cap_order );
144 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
145
146 // Taylor coefficients and partials corresponding to argument
147 const Base* x = taylor + i_x * cap_order;
148 Base* px = partial + i_x * nc_partial;
149
150 // Taylor coefficients and partials corresponding to first result
151 const Base* z = taylor + i_z * cap_order;
152 Base* pz = partial + i_z * nc_partial;
153
154 // Taylor coefficients and partials corresponding to auxillary result
155 const Base* b = z - cap_order; // called y in documentation
156 Base* pb = pz - nc_partial;
157
158 Base inv_b0 = Base(1.0) / b[0];
159
160 // number of indices to access
161 size_t j = d;
162 size_t k;
163 while(j)
164 {
165 // scale partials w.r.t b[j] by 1 / b[0]
166 pb[j] = azmul(pb[j], inv_b0);
167
168 // scale partials w.r.t z[j] by 1 / b[0]
169 pz[j] = azmul(pz[j], inv_b0);
170
171 // update partials w.r.t b^0
172 pb[0] -= azmul(pz[j], z[j]) + azmul(pb[j], b[j]);
173
174 // update partial w.r.t. x^0
175 px[0] += azmul(pb[j], x[j]);
176
177 // update partial w.r.t. x^j
178 px[j] += pz[j] + azmul(pb[j], x[0]);
179
180 // further scale partial w.r.t. z[j] by 1 / j
181 pz[j] /= Base(double(j));
182
183 for(k = 1; k < j; k++)
184 { // update partials w.r.t b^(j-k)
185 pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]) + azmul(pb[j], b[k]);
186
187 // update partials w.r.t. x^k
188 px[k] += azmul(pb[j], x[j-k]);
189
190 // update partials w.r.t. z^k
191 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
192 }
193 --j;
194 }
195
196 // j == 0 case
197 px[0] += azmul(pz[0] + azmul(pb[0], x[0]), inv_b0);
198 }
199
200 } } // END_CPPAD_LOCAL_NAMESPACE
201 # endif
0 # ifndef CPPAD_LOCAL_OP_ATAN_OP_HPP
1 # define CPPAD_LOCAL_OP_ATAN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_atan_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37 Base* b = z - cap_order; // called y in documentation
38
39 size_t k;
40 if( p == 0 )
41 { z[0] = atan( x[0] );
42 b[0] = Base(1.0) + x[0] * x[0];
43 p++;
44 }
45 for(size_t j = p; j <= q; j++)
46 {
47 b[j] = Base(2.0) * x[0] * x[j];
48 z[j] = Base(0.0);
49 for(k = 1; k < j; k++)
50 { b[j] += x[k] * x[j-k];
51 z[j] -= Base(double(k)) * z[k] * b[j-k];
52 }
53 z[j] /= Base(double(j));
54 z[j] += x[j];
55 z[j] /= b[0];
56 }
57 }
58
59 // See dev documentation: forward_unary_op
60 template <class Base>
61 void forward_atan_op_dir(
62 size_t q ,
63 size_t r ,
64 size_t i_z ,
65 size_t i_x ,
66 size_t cap_order ,
67 Base* taylor )
68 {
69 // check assumptions
70 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
71 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
72 CPPAD_ASSERT_UNKNOWN( 0 < q );
73 CPPAD_ASSERT_UNKNOWN( q < cap_order );
74
75 // Taylor coefficients corresponding to argument and result
76 size_t num_taylor_per_var = (cap_order-1) * r + 1;
77 Base* x = taylor + i_x * num_taylor_per_var;
78 Base* z = taylor + i_z * num_taylor_per_var;
79 Base* b = z - num_taylor_per_var; // called y in documentation
80
81 size_t m = (q-1) * r + 1;
82 for(size_t ell = 0; ell < r; ell++)
83 { b[m+ell] = Base(2.0) * x[m+ell] * x[0];
84 z[m+ell] = Base(double(q)) * x[m+ell];
85 for(size_t k = 1; k < q; k++)
86 { b[m+ell] += x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
87 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
88 }
89 z[m+ell] /= ( Base(double(q)) * b[0] );
90 }
91 }
92
93 // See dev documentation: forward_unary_op
94 template <class Base>
95 void forward_atan_op_0(
96 size_t i_z ,
97 size_t i_x ,
98 size_t cap_order ,
99 Base* taylor )
100 {
101 // check assumptions
102 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
103 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
104 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
105
106 // Taylor coefficients corresponding to argument and result
107 Base* x = taylor + i_x * cap_order;
108 Base* z = taylor + i_z * cap_order;
109 Base* b = z - cap_order; // called y in documentation
110
111 z[0] = atan( x[0] );
112 b[0] = Base(1.0) + x[0] * x[0];
113 }
114
115 // See dev documentation: reverse_unary_op
116 template <class Base>
117 void reverse_atan_op(
118 size_t d ,
119 size_t i_z ,
120 size_t i_x ,
121 size_t cap_order ,
122 const Base* taylor ,
123 size_t nc_partial ,
124 Base* partial )
125 {
126 // check assumptions
127 CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
128 CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
129 CPPAD_ASSERT_UNKNOWN( d < cap_order );
130 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
131
132 // Taylor coefficients and partials corresponding to argument
133 const Base* x = taylor + i_x * cap_order;
134 Base* px = partial + i_x * nc_partial;
135
136 // Taylor coefficients and partials corresponding to first result
137 const Base* z = taylor + i_z * cap_order;
138 Base* pz = partial + i_z * nc_partial;
139
140 // Taylor coefficients and partials corresponding to auxillary result
141 const Base* b = z - cap_order; // called y in documentation
142 Base* pb = pz - nc_partial;
143
144 Base inv_b0 = Base(1.0) / b[0];
145
146 // number of indices to access
147 size_t j = d;
148 size_t k;
149 while(j)
150 { // scale partials w.r.t z[j] and b[j]
151 pz[j] = azmul(pz[j], inv_b0);
152 pb[j] *= Base(2.0);
153
154 pb[0] -= azmul(pz[j], z[j]);
155 px[j] += pz[j] + azmul(pb[j], x[0]);
156 px[0] += azmul(pb[j], x[j]);
157
158 // more scaling of partials w.r.t z[j]
159 pz[j] /= Base(double(j));
160
161 for(k = 1; k < j; k++)
162 { pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
163 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
164 px[k] += azmul(pb[j], x[j-k]);
165 }
166 --j;
167 }
168 px[0] += azmul(pz[0], inv_b0) + Base(2.0) * azmul(pb[0], x[0]);
169 }
170
171 } } // END_CPPAD_LOCAL_NAMESPACE
172 # endif
0 # ifndef CPPAD_LOCAL_OP_ATANH_OP_HPP
1 # define CPPAD_LOCAL_OP_ATANH_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17
18
19 // See dev documentation: forward_unary_op
20 template <class Base>
21 void forward_atanh_op(
22 size_t p ,
23 size_t q ,
24 size_t i_z ,
25 size_t i_x ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to argument and result
36 Base* x = taylor + i_x * cap_order;
37 Base* z = taylor + i_z * cap_order;
38 Base* b = z - cap_order; // called y in documentation
39
40 size_t k;
41 if( p == 0 )
42 { z[0] = atanh( x[0] );
43 b[0] = Base(1.0) - x[0] * x[0];
44 p++;
45 }
46 for(size_t j = p; j <= q; j++)
47 {
48 b[j] = - Base(2.0) * x[0] * x[j];
49 z[j] = Base(0.0);
50 for(k = 1; k < j; k++)
51 { b[j] -= x[k] * x[j-k];
52 z[j] -= Base(double(k)) * z[k] * b[j-k];
53 }
54 z[j] /= Base(double(j));
55 z[j] += x[j];
56 z[j] /= b[0];
57 }
58 }
59
60 // See dev documentation: forward_unary_op
61 template <class Base>
62 void forward_atanh_op_dir(
63 size_t q ,
64 size_t r ,
65 size_t i_z ,
66 size_t i_x ,
67 size_t cap_order ,
68 Base* taylor )
69 {
70 // check assumptions
71 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
72 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
73 CPPAD_ASSERT_UNKNOWN( 0 < q );
74 CPPAD_ASSERT_UNKNOWN( q < cap_order );
75
76 // Taylor coefficients corresponding to argument and result
77 size_t num_taylor_per_var = (cap_order-1) * r + 1;
78 Base* x = taylor + i_x * num_taylor_per_var;
79 Base* z = taylor + i_z * num_taylor_per_var;
80 Base* b = z - num_taylor_per_var; // called y in documentation
81
82 size_t m = (q-1) * r + 1;
83 for(size_t ell = 0; ell < r; ell++)
84 { b[m+ell] = - Base(2.0) * x[m+ell] * x[0];
85 z[m+ell] = Base(double(q)) * x[m+ell];
86 for(size_t k = 1; k < q; k++)
87 { b[m+ell] -= x[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
88 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * b[(q-k-1)*r+1+ell];
89 }
90 z[m+ell] /= ( Base(double(q)) * b[0] );
91 }
92 }
93
94 // See dev documentation: forward_unary_op
95 template <class Base>
96 void forward_atanh_op_0(
97 size_t i_z ,
98 size_t i_x ,
99 size_t cap_order ,
100 Base* taylor )
101 {
102 // check assumptions
103 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
104 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
105 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
106
107 // Taylor coefficients corresponding to argument and result
108 Base* x = taylor + i_x * cap_order;
109 Base* z = taylor + i_z * cap_order;
110 Base* b = z - cap_order; // called y in documentation
111
112 z[0] = atanh( x[0] );
113 b[0] = Base(1.0) - x[0] * x[0];
114 }
115
116 // See dev documentation: reverse_unary_op
117 template <class Base>
118 void reverse_atanh_op(
119 size_t d ,
120 size_t i_z ,
121 size_t i_x ,
122 size_t cap_order ,
123 const Base* taylor ,
124 size_t nc_partial ,
125 Base* partial )
126 {
127 // check assumptions
128 CPPAD_ASSERT_UNKNOWN( NumArg(AtanhOp) == 1 );
129 CPPAD_ASSERT_UNKNOWN( NumRes(AtanhOp) == 2 );
130 CPPAD_ASSERT_UNKNOWN( d < cap_order );
131 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
132
133 // Taylor coefficients and partials corresponding to argument
134 const Base* x = taylor + i_x * cap_order;
135 Base* px = partial + i_x * nc_partial;
136
137 // Taylor coefficients and partials corresponding to first result
138 const Base* z = taylor + i_z * cap_order;
139 Base* pz = partial + i_z * nc_partial;
140
141 // Taylor coefficients and partials corresponding to auxillary result
142 const Base* b = z - cap_order; // called y in documentation
143 Base* pb = pz - nc_partial;
144
145 Base inv_b0 = Base(1.0) / b[0];
146
147 // number of indices to access
148 size_t j = d;
149 size_t k;
150 while(j)
151 { // scale partials w.r.t z[j] and b[j]
152 pz[j] = azmul(pz[j], inv_b0);
153 pb[j] *= Base(2.0);
154
155 pb[0] -= azmul(pz[j], z[j]);
156 px[j] += pz[j] - azmul(pb[j], x[0]);
157 px[0] -= azmul(pb[j], x[j]);
158
159 // more scaling of partials w.r.t z[j]
160 pz[j] /= Base(double(j));
161
162 for(k = 1; k < j; k++)
163 { pb[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
164 pz[k] -= Base(double(k)) * azmul(pz[j], b[j-k]);
165 px[k] -= azmul(pb[j], x[j-k]);
166 }
167 --j;
168 }
169 px[0] += azmul(pz[0], inv_b0) - Base(2.0) * azmul(pb[0], x[0]);
170 }
171
172 } } // END_CPPAD_LOCAL_NAMESPACE
173 # endif
0 /* -------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 /*
12 $begin forward_binary_op$$
13 $spell
14 const addr_t arg
15 subvp
16 Taylor
17 op
18 $$
19
20 $section Variable Forward Binary Operators$$
21
22 $head Syntax$$
23 $codei%forward_%name%_op(
24 %p%, %q%, %i_z%, %arg%, %parameter% %cap_order%, %taylor%
25 )%$$
26
27 $head Assumption$$
28 The operator corresponding to $icode name$$ has
29 two arguments and one result.
30
31 $head Notation$$
32
33 $head name$$
34 The last two characters in the $icode name$$ for a binary operator are
35 $code p$$ (for parameter) or $code v$$ (for variable).
36 For example the name $code subvp$$ corresponding to subtraction
37 with a variable on the left (first) and a parameter on the right (second).
38
39 $subhead x$$
40 We use $icode x$$ to denote the first argument of this binary operation.
41 This argument is a variable or a parameter depending on the operator.
42
43 $subhead y$$
44 We use $icode y$$ to denote the second argument of this binary operation.
45 This argument is a variable or a parameter depending on the operator.
46
47 $subhead z$$
48 We use $icode z$$ to denote the result of this binary operation.
49 The result is always a variable.
50
51 $head Base$$
52 is the base type for the operator; i.e., this operation was recorded
53 using $codei%AD<%Base%>%$$ and computations by this routine are done using
54 type $icode Base$$.
55
56 $head p$$
57 This argument has type $code size_t$$ and
58 is lowest order of the Taylor coefficient that we are computing.
59
60 $head q$$
61 The argument $icode q >= p$$ has type $code size_t$$ and
62 is highest order of the Taylor coefficient that we are computing.
63
64 $head i_z$$
65 This argument has type $code size_t$$ and
66 is the variable index corresponding to the result for this operation;
67 i.e. the row index in $icode taylor$$ corresponding to $icode z$$.
68
69 $head arg$$
70 This argument has type $code const addr_t*$$.
71
72 $subhead i_x$$
73 We use $icode%i_x% = %arg%[0]%$$ for the
74 index corresponding to the first operand for this operator.
75 If $icode x$$ is a parameter,
76 $icode%parameter%[%i_x%]%$$ is the corresponding value.
77 If $icode x$$ is a variable,
78 $icode i_x$$ is the row index in $icode taylor$$ corresponding to $code x$$.
79
80 $subhead i_y$$
81 We use $icode%i_y% = %arg%[0]%$$ for the
82 index corresponding to the first operand for this operator.
83 If $icode y$$ is a parameter,
84 $icode%parameter%[%i_y%]%$$ is the corresponding value.
85 If $icode y$$ is a variable,
86 $icode i_y$$ is the row index in $icode taylor$$ corresponding to $code y$$.
87
88 $head parameter$$
89 This argument has type $codei%const %Base%*%$$
90 and maps parameter indices to parameter values.
91
92 $head cap_order$$
93 This argument has type $code size_t$$ and
94 is the maximum number of orders that will fit in $icode taylor$$.
95
96 $head taylor$$
97 This argument has type $icode%Base%*%$$.
98 The Taylor coefficient corresponding to
99 variable $icode i$$ and order $icode k$$ is
100 $codei%
101 %taylor%[ %i% * %cap_order% + %k% ]
102 %$$.
103
104 $subhead Input$$
105 $list number$$
106 If $icode x$$ is a variable,
107 the Taylor coefficients for variable $icode i_x$$ up to order $icode q$$.
108 $lnext
109 If $icode y$$ is a variable,
110 the Taylor coefficients for variable $icode i_y$$ up to order $icode q$$.
111 $lnext
112 The Taylor coefficients for variable $icode i_z$$ up to order $icode%p%-1%$$.
113 $lend
114
115 $subhead Output$$
116 The Taylor coefficients for variable $icode i_z$$ up to order $icode q$$.
117
118 $end
119 ------------------------------------------------------------------------------
120 $begin forward_binary_op_dir$$
121 $spell
122 const addr_t arg
123 op
124 tpv
125 Taylor
126 $$
127
128 $section Multiple Direction Forward Binary Operators$$
129
130 $head Syntax$$
131 $codei%forward_%name%_op(
132 %q%, %r%, %i_z%, %arg%, %parameter%, %cap_order%, %taylor%
133 )%$$
134
135 $head Assumption$$
136 The operator corresponding to $icode name$$ has
137 two arguments and one result.
138
139 $head Notation$$
140
141 $subhead x$$
142 We use $icode x$$ to denote the first argument of this binary operation.
143 This argument is a variable or a parameter depending on the operator.
144
145 $subhead y$$
146 We use $icode y$$ to denote the second argument of this binary operation.
147 This argument is a variable or a parameter depending on the operator.
148
149 $subhead z$$
150 We use $icode z$$ to denote the result of this binary operation.
151 The result is always a variable.
152
153 $head Base$$
154 is the base type for the operator; i.e., this operation was recorded
155 using $codei%AD<%Base%>%$$ and computations by this routine are done using
156 type $icode Base$$.
157
158 $head q$$
159 This argument has type $code size_t$$ and
160 is the order of the Taylor coefficients that we are computing.
161 Furthermore $icode%q% > 0%$$ and $icode%q% < %cap_order%$$.
162
163 $head r$$
164 This argument has type $code size_t$$ and
165 is number of directions for Taylor coefficients that we are computing.
166
167 $head i_z$$
168 This argument has type $code size_t$$ and
169 is the variable index corresponding to the result for this operation;
170 i.e. the row index in $icode taylor$$ corresponding to $icode z$$.
171
172 $head arg$$
173 This argument has type $codei%const addr_t* %arg%$$.
174
175 $subhead i_x$$
176 We use $icode%i_x% = %arg%[0]%$$ for the
177 index corresponding to the first operand for this operator.
178 If $icode x$$ is a parameter,
179 $icode%parameter%[%i_x%]%$$ is the corresponding value.
180 If $icode x$$ is a variable,
181 $icode i_x$$ is the row index in $icode taylor$$ corresponding to $code x$$.
182
183 $subhead i_y$$
184 We use $icode%i_y% = %arg%[0]%$$ for the
185 index corresponding to the first operand for this operator.
186 If $icode y$$ is a parameter,
187 $icode%parameter%[%i_y%]%$$ is the corresponding value.
188 If $icode y$$ is a variable,
189 $icode i_y$$ is the row index in $icode taylor$$ corresponding to $code y$$.
190
191 $head parameter$$
192 This argument has type $codei%const %Base%*%$$
193 and maps parameter indices to parameter values.
194
195 $head cap_order$$
196 This argument has type $code size_t$$ and
197 is the maximum number of orders that will fit in $icode taylor$$.
198 The zero order Taylor coefficient for a variable
199 is the same for all directions. We use the notation
200 $codei%
201 %tpv% = (%cap_order% - 1) * r + 1
202 %$$
203 which is the number of Taylor coefficients per variable.
204
205 $head taylor$$
206 This argument has type $icode%Base%*%$$.
207 The zero order Taylor coefficient for variable $icode i$$ is
208 $codei%
209 %taylor%[ %i% * %tpv% + 0 ]
210 %$$.
211 For $icode k > 0$$,
212 and $icode%ell% = 0 , %..% , %r-1%$$,
213 The Taylor coefficient for variable $icode i$$,
214 order $icode k$$, and direction $icode ell$$ is
215 $codei%
216 %taylor%[ %i% * %tpv% + (%k% - 1) * %r% + %ell% + 1 ]
217 %$$.
218
219 $head Input$$
220 $list number$$
221 If $icode x$$ is a variable,
222 the Taylor coefficients for variable $icode i_x$$ up to order $icode q$$
223 and all $icode r$$ directions.
224 $lnext
225 If $icode y$$ is a variable,
226 the Taylor coefficients for variable $icode i_x$$ up to order $icode q$$
227 and all $icode r$$ directions.
228 $lnext
229 The Taylor coefficients for variable $icode i_z$$ up to order $icode q-1$$
230 and all $icode r$$ directions.
231 $lend
232
233 $head Output$$
234 The Taylor coefficients for variable $icode i_z$$ up to order $icode q$$
235 and all $icode r$$ directions.
236
237 $end
238 -------------------------------------------------------------------------------
239 /*
240 $begin forward_binary_op_0$$
241 $spell
242 const addr_t arg
243 op
244 Taylor
245 $$
246
247 $section Zero Order Forward Binary Operators$$
248
249 $head Syntax$$
250 $codei%forward_%name%_op_0(
251 %i_z%, %arg%, %parameter%, %cap_order%, %taylor%
252 )%$$
253
254 $head Assumption$$
255 The operator corresponding to $icode name$$ has
256 two arguments and one result.
257
258 $head Notation$$
259
260 $subhead x$$
261 We use $icode x$$ to denote the first argument of this binary operation.
262 This argument is a variable or a parameter depending on the operator.
263
264 $subhead y$$
265 We use $icode y$$ to denote the second argument of this binary operation.
266 This argument is a variable or a parameter depending on the operator.
267
268 $subhead z$$
269 We use $icode z$$ to denote the result of this binary operation.
270 The result is always a variable.
271
272 $head Base$$
273 is the base type for the operator; i.e., this operation was recorded
274 using $codei%AD<%Base%>%$$ and computations by this routine are done using
275 type $icode Base$$.
276
277 $head i_z$$
278 This argument has type $code size_t$$ and
279 is the variable index corresponding to the result for this operation;
280 i.e. the row index in $icode taylor$$ corresponding to $icode z$$.
281
282 $head arg$$
283 This argument has type $code const addr_t*$$.
284
285 $subhead i_x$$
286 We use $icode%i_x% = %arg%[0]%$$ for the
287 index corresponding to the first operand for this operator.
288 If $icode x$$ is a parameter,
289 $icode%parameter%[%i_x%]%$$ is the corresponding value.
290 If $icode x$$ is a variable,
291 $icode i_x$$ is the row index in $icode taylor$$ corresponding to $code x$$.
292
293 $subhead i_y$$
294 We use $icode%i_y% = %arg%[0]%$$ for the
295 index corresponding to the first operand for this operator.
296 If $icode y$$ is a parameter,
297 $icode%parameter%[%i_y%]%$$ is the corresponding value.
298 If $icode y$$ is a variable,
299 $icode i_y$$ is the row index in $icode taylor$$ corresponding to $code y$$.
300
301 $head parameter$$
302 This argument has type $codei%const %Base%*%$$
303 and maps parameter indices to parameter values.
304
305 $head cap_order$$
306 This argument has type $code size_t$$ and
307 is the maximum number of orders that will fit in $icode taylor$$.
308
309 $head taylor$$
310 This argument has type $icode%Base%*%$$.
311 The Taylor coefficient corresponding to
312 variable $icode i$$ and order $icode k$$ is
313 $codei%
314 %taylor%[ %i% * %cap_order% + %k% ]
315 %$$.
316
317 $subhead Input$$
318 If $icode x$$ is a variable,
319 the zero order Taylor coefficients for variable $icode i_x$$.
320 If $icode y$$ is a variable,
321 the zero order Taylor coefficients for variable $icode i_y$$.
322
323 $subhead Output$$
324 The zero order Taylor coefficients for variable $icode i_z$$.
325
326 $end
327 ------------------------------------------------------------------------------
328 /*
329 $begin reverse_binary_op$$
330 $spell
331 const addr_ arg
332 op
333 Taylor
334 nc
335 const
336 $$
337
338 $section Reverse Binary Operators$$
339
340 $head Syntax$$
341 $codei%reverse_%name%_op(
342 %d%, %i_z%, %arg%, %parameter%, %cap_order%, %taylor%, %nc_partial%, %partial%
343 )%$$
344
345 $head Assumption$$
346 The operator corresponding to $icode name$$ has one argument and one result.
347
348 $head Notation$$
349
350 $subhead x$$
351 We use $icode x$$ to denote the first argument of this binary operation.
352 This argument is a variable or a parameter depending on the operator.
353
354 $subhead y$$
355 We use $icode y$$ to denote the second argument of this binary operation.
356 This argument is a variable or a parameter depending on the operator.
357
358 $subhead z$$
359 We use $icode z$$ to denote the result of this binary operation.
360 The result is always a variable.
361
362 $subhead G$$
363 We use $latex G(z, y, x, w, \ldots )$$ to denote a scalar valued function
364 of the variables up to variable index $icode i_z$$.
365
366 $subhead H$$
367 We use $latex H(y, x, w, \ldots )$$ to denote the scalar valued function
368 of the variables up to variable index $icode%i_z%-1%$$ defined by
369 $latex \[
370 H(y, x, w, \ldots ) = G [ z(x, y), y, x, w, \ldots ) ]
371 \]$$
372
373 $head Base$$
374 is the base type for the operator; i.e., this operation was recorded
375 using $codei%AD<%Base%>%$$ and computations by this routine are done using
376 type $icode Base$$.
377
378 $head d$$
379 This argument has type $code size_t$$ and
380 is this highest order Taylor coefficient that we are computing
381 partial derivatives with respect to.
382 Furthermore $icode%d% < %cap_order%$$ and $icode%d% < %nc_partial%$$.
383
384 $head i_z$$
385 This argument has type $code size_t$$ and
386 is the variable index corresponding to the result for this operation;
387 i.e. the row index in $icode taylor$$ corresponding to $icode z$$.
388
389 $head arg$$
390 This argument has type $code const addr_t*$$.
391
392 $subhead i_x$$
393 We use $icode%i_x% = %arg%[0]%$$ for the
394 index corresponding to the first operand for this operator.
395 If $icode x$$ is a parameter,
396 $icode%parameter%[%i_x%]%$$ is the corresponding value.
397 If $icode x$$ is a variable,
398 $icode i_x$$ is the row index in $icode taylor$$ corresponding to $code x$$.
399
400 $subhead i_y$$
401 We use $icode%i_y% = %arg%[0]%$$ for the
402 index corresponding to the first operand for this operator.
403 If $icode y$$ is a parameter,
404 $icode%parameter%[%i_y%]%$$ is the corresponding value.
405 If $icode y$$ is a variable,
406 $icode i_y$$ is the row index in $icode taylor$$ corresponding to $code y$$.
407
408 $head parameter$$
409 This argument has type $codei%const %Base%*%$$
410 and maps parameter indices to parameter values.
411
412 $head cap_order$$
413 This argument has type $code size_t$$ and
414 is the maximum number of orders that will fit in $icode taylor$$.
415
416 $head taylor$$
417 This argument has type $codei%const %Base%*%$$.
418 The Taylor coefficient corresponding to
419 variable $icode i$$ and order $icode k$$ is
420 $codei%
421 %taylor%[ %i% * %cap_order% + %k% ]
422 %$$.
423
424 $head nc_partial$$
425 This argument has type $code size_t$$ and
426 is the number of columns in the partial array.
427
428 $head partial$$
429 This argument has type $icode%Base%*%$$.
430 The partial derivative w.r.t. variable $icode i$$ and
431 Taylor coefficient of order $icode k$$ is
432 $code%
433 %partial% [ %i% * %nc_partial% + k ]
434 %$$
435 for $icode%k% = 0 , %...%, %d%$$.
436
437 $subhead Input$$
438 For variable $icode%i% = 0 ,%...%, %i_z%$$,
439 $icode partial$$ contains the
440 partial derivatives of $latex G(z, y, x, w, \ldots)$$.
441
442 $subhead Output$$
443 The array $icode partial$$ contains the
444 partial derivatives of $latex H(x, w, \ldots)$$.
445 The partial derivative for variable $icode i_z$$ is unspecified.
446
447 $end
448 ------------------------------------------------------------------------------
0 # ifndef CPPAD_LOCAL_OP_COMP_OP_HPP
1 # define CPPAD_LOCAL_OP_COMP_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file comp_op.hpp
18 Zero order forward mode check how many comparisons changed.
19 */
20
21 // -------------------------------- <= -----------------------------------
22 /*!
23 Zero order forward mode comparison check that left <= right
24
25 \param count
26 It the condition is not true, ths counter is incremented by one.
27
28 \param arg
29 parameter[ arg[0] ] is the left operand and
30 parameter[ arg[1] ] is the right operand.
31
32 \param parameter
33 vector of parameter values.
34 */
35 template <class Base>
36 void forward_lepp_op_0(
37 size_t& count ,
38 const addr_t* arg ,
39 const Base* parameter )
40 {
41 // check assumptions
42 CPPAD_ASSERT_UNKNOWN( NumArg(LeppOp) == 2 );
43 CPPAD_ASSERT_UNKNOWN( NumRes(LeppOp) == 0 );
44
45 // Taylor coefficients corresponding to arguments and result
46 Base x = parameter[ arg[0] ];
47 Base y = parameter[ arg[1] ];
48
49 count += size_t( GreaterThanZero(x - y) );
50 }
51 /*!
52 Zero order forward mode comparison check that left <= right
53
54 \param count
55 It the condition is not true, ths counter is incremented by one.
56
57 \param arg
58 parameter[ arg[0] ] is the left operand and
59 taylor[ size_t(arg[1]) * cap_order + 0 ] is the zero order Taylor coefficient
60 for the right operand.
61
62 \param parameter
63 vector of parameter values.
64
65 \param cap_order
66 number of Taylor coefficients allocated for each variable
67
68 \param taylor
69 vector of taylor coefficients.
70 */
71 template <class Base>
72 void forward_lepv_op_0(
73 size_t& count ,
74 const addr_t* arg ,
75 const Base* parameter ,
76 size_t cap_order ,
77 Base* taylor )
78 {
79 // check assumptions
80 CPPAD_ASSERT_UNKNOWN( NumArg(LepvOp) == 2 );
81 CPPAD_ASSERT_UNKNOWN( NumRes(LepvOp) == 0 );
82
83 // Taylor coefficients corresponding to arguments and result
84 Base x = parameter[ arg[0] ];
85 Base* y = taylor + size_t(arg[1]) * cap_order;
86
87 count += GreaterThanZero(x - y[0]);
88 }
89 /*!
90 Zero order forward mode comparison check that left <= right
91
92 \param count
93 It the condition is not true, ths counter is incremented by one.
94
95 \param arg
96 taylor[ size_t(arg[0]) * cap_order + 0 ] is the zero order Taylor coefficient
97 for the left operand and parameter[ arg[1] ] is the right operand
98
99 \param parameter
100 vector of parameter values.
101
102 \param cap_order
103 number of Taylor coefficients allocated for each variable
104
105 \param taylor
106 vector of taylor coefficients.
107 */
108 template <class Base>
109 void forward_levp_op_0(
110 size_t& count ,
111 const addr_t* arg ,
112 const Base* parameter ,
113 size_t cap_order ,
114 Base* taylor )
115 {
116 // check assumptions
117 CPPAD_ASSERT_UNKNOWN( NumArg(LevpOp) == 2 );
118 CPPAD_ASSERT_UNKNOWN( NumRes(LevpOp) == 0 );
119
120 // Taylor coefficients corresponding to arguments and result
121 Base* x = taylor + size_t(arg[0]) * cap_order;
122 Base y = parameter[ arg[1] ];
123
124 count += GreaterThanZero(x[0] - y);
125 }
126 /*!
127 Zero order forward mode comparison check that left <= right
128
129 \param count
130 It the condition is not true, ths counter is incremented by one.
131
132 \param arg
133 taylor[ size_t(arg[0]) * cap_order + 0 ] is the zero order Taylor coefficient
134 for the left operand and
135 taylor[ size_t(arg[1]) * cap_order + 0 ] is the zero order Taylor coefficient
136 for the right operand.
137
138 \param parameter
139 vector of parameter values.
140
141 \param cap_order
142 number of Taylor coefficients allocated for each variable
143
144 \param taylor
145 vector of taylor coefficients.
146 */
147 template <class Base>
148 void forward_levv_op_0(
149 size_t& count ,
150 const addr_t* arg ,
151 const Base* parameter ,
152 size_t cap_order ,
153 Base* taylor )
154 {
155 // check assumptions
156 CPPAD_ASSERT_UNKNOWN( NumArg(LevvOp) == 2 );
157 CPPAD_ASSERT_UNKNOWN( NumRes(LevvOp) == 0 );
158
159 // Taylor coefficients corresponding to arguments and result
160 Base* x = taylor + size_t(arg[0]) * cap_order;
161 Base* y = taylor + size_t(arg[1]) * cap_order;
162
163 count += GreaterThanZero(x[0] - y[0]);
164 }
165 // ------------------------------- < -------------------------------------
166 /*!
167 Zero order forward mode comparison check that left < right
168
169 \param count
170 It the condition is not true, ths counter is incremented by one.
171
172 \param arg
173 parameter[ arg[0] ] is the left operand and
174 parameter[ arg[1] ] is the right operand.
175
176 \param parameter
177 vector of parameter values.
178 */
179 template <class Base>
180 void forward_ltpp_op_0(
181 size_t& count ,
182 const addr_t* arg ,
183 const Base* parameter )
184 {
185 // check assumptions
186 CPPAD_ASSERT_UNKNOWN( NumArg(LtppOp) == 2 );
187 CPPAD_ASSERT_UNKNOWN( NumRes(LtppOp) == 0 );
188
189 // Taylor coefficients corresponding to arguments and result
190 Base x = parameter[ arg[0] ];
191 Base y = parameter[ arg[1] ];
192
193 count += GreaterThanOrZero(x - y);
194 }
195 /*!
196 Zero order forward mode comparison check that left < right
197
198 \copydetails CppAD::local::forward_lepv_op_0
199 */
200 template <class Base>
201 void forward_ltpv_op_0(
202 size_t& count ,
203 const addr_t* arg ,
204 const Base* parameter ,
205 size_t cap_order ,
206 Base* taylor )
207 {
208 // check assumptions
209 CPPAD_ASSERT_UNKNOWN( NumArg(LtpvOp) == 2 );
210 CPPAD_ASSERT_UNKNOWN( NumRes(LtpvOp) == 0 );
211
212 // Taylor coefficients corresponding to arguments and result
213 Base x = parameter[ arg[0] ];
214 Base* y = taylor + size_t(arg[1]) * cap_order;
215
216 count += GreaterThanOrZero(x - y[0]);
217 }
218 /*!
219 Zero order forward mode comparison check that left < right
220
221 \copydetails CppAD::local::forward_levp_op_0
222 */
223 template <class Base>
224 void forward_ltvp_op_0(
225 size_t& count ,
226 const addr_t* arg ,
227 const Base* parameter ,
228 size_t cap_order ,
229 Base* taylor )
230 {
231 // check assumptions
232 CPPAD_ASSERT_UNKNOWN( NumArg(LtvpOp) == 2 );
233 CPPAD_ASSERT_UNKNOWN( NumRes(LtvpOp) == 0 );
234
235 // Taylor coefficients corresponding to arguments and result
236 Base* x = taylor + size_t(arg[0]) * cap_order;
237 Base y = parameter[ arg[1] ];
238
239 count += GreaterThanOrZero(x[0] - y);
240 }
241 /*!
242 Zero order forward mode comparison check that left < right
243
244 \copydetails CppAD::local::forward_levv_op_0
245 */
246 template <class Base>
247 void forward_ltvv_op_0(
248 size_t& count ,
249 const addr_t* arg ,
250 const Base* parameter ,
251 size_t cap_order ,
252 Base* taylor )
253 {
254 // check assumptions
255 CPPAD_ASSERT_UNKNOWN( NumArg(LtvvOp) == 2 );
256 CPPAD_ASSERT_UNKNOWN( NumRes(LtvvOp) == 0 );
257
258 // Taylor coefficients corresponding to arguments and result
259 Base* x = taylor + size_t(arg[0]) * cap_order;
260 Base* y = taylor + size_t(arg[1]) * cap_order;
261
262 count += GreaterThanOrZero(x[0] - y[0]);
263 }
264 // ------------------------------ == -------------------------------------
265 /*!
266 Zero order forward mode comparison check that left == right
267
268 \param count
269 It the condition is not true, ths counter is incremented by one.
270
271 \param arg
272 parameter[ arg[0] ] is the left operand and
273 parameter[ arg[1] ] is the right operand.
274
275 \param parameter
276 vector of parameter values.
277 */
278 template <class Base>
279 void forward_eqpp_op_0(
280 size_t& count ,
281 const addr_t* arg ,
282 const Base* parameter )
283 {
284 // check assumptions
285 CPPAD_ASSERT_UNKNOWN( NumArg(EqppOp) == 2 );
286 CPPAD_ASSERT_UNKNOWN( NumRes(EqppOp) == 0 );
287
288 // Taylor coefficients corresponding to arguments and result
289 Base x = parameter[ arg[0] ];
290 Base y = parameter[ arg[1] ];
291
292 count += size_t(x != y);
293 }
294 /*!
295 Zero order forward mode comparison check that left == right
296
297 \copydetails CppAD::local::forward_lepv_op_0
298 */
299 template <class Base>
300 void forward_eqpv_op_0(
301 size_t& count ,
302 const addr_t* arg ,
303 const Base* parameter ,
304 size_t cap_order ,
305 Base* taylor )
306 {
307 // check assumptions
308 CPPAD_ASSERT_UNKNOWN( NumArg(EqpvOp) == 2 );
309 CPPAD_ASSERT_UNKNOWN( NumRes(EqpvOp) == 0 );
310
311 // Taylor coefficients corresponding to arguments and result
312 Base x = parameter[ arg[0] ];
313 Base* y = taylor + size_t(arg[1]) * cap_order;
314
315 count += size_t(x != y[0]);
316 }
317 /*!
318 Zero order forward mode comparison check that left == right
319
320 \copydetails CppAD::local::forward_levv_op_0
321 */
322 template <class Base>
323 void forward_eqvv_op_0(
324 size_t& count ,
325 const addr_t* arg ,
326 const Base* parameter ,
327 size_t cap_order ,
328 Base* taylor )
329 {
330 // check assumptions
331 CPPAD_ASSERT_UNKNOWN( NumArg(EqvvOp) == 2 );
332 CPPAD_ASSERT_UNKNOWN( NumRes(EqvvOp) == 0 );
333
334 // Taylor coefficients corresponding to arguments and result
335 Base* x = taylor + size_t(arg[0]) * cap_order;
336 Base* y = taylor + size_t(arg[1]) * cap_order;
337
338 count += size_t(x[0] != y[0]);
339 }
340 // -------------------------------- != -----------------------------------
341 /*!
342 Zero order forward mode comparison check that left != right
343
344 \param count
345 It the condition is not true, ths counter is incremented by one.
346
347 \param arg
348 parameter[ arg[0] ] is the left operand and
349 parameter[ arg[1] ] is the right operand.
350
351 \param parameter
352 vector of parameter values.
353 */
354 template <class Base>
355 void forward_nepp_op_0(
356 size_t& count ,
357 const addr_t* arg ,
358 const Base* parameter )
359 {
360 // check assumptions
361 CPPAD_ASSERT_UNKNOWN( NumArg(NeppOp) == 2 );
362 CPPAD_ASSERT_UNKNOWN( NumRes(NeppOp) == 0 );
363
364 // Taylor coefficients corresponding to arguments and result
365 Base x = parameter[ arg[0] ];
366 Base y = parameter[ arg[1] ];
367
368 count += size_t(x == y);
369 }
370 /*!
371 Zero order forward mode comparison check that left != right
372
373 \copydetails CppAD::local::forward_lepv_op_0
374 */
375 template <class Base>
376 void forward_nepv_op_0(
377 size_t& count ,
378 const addr_t* arg ,
379 const Base* parameter ,
380 size_t cap_order ,
381 Base* taylor )
382 {
383 // check assumptions
384 CPPAD_ASSERT_UNKNOWN( NumArg(NepvOp) == 2 );
385 CPPAD_ASSERT_UNKNOWN( NumRes(NepvOp) == 0 );
386
387 // Taylor coefficients corresponding to arguments and result
388 Base x = parameter[ arg[0] ];
389 Base* y = taylor + size_t(arg[1]) * cap_order;
390
391 count += size_t(x == y[0]);
392 }
393 /*!
394 Zero order forward mode comparison check that left != right
395
396 \copydetails CppAD::local::forward_levv_op_0
397 */
398 template <class Base>
399 void forward_nevv_op_0(
400 size_t& count ,
401 const addr_t* arg ,
402 const Base* parameter ,
403 size_t cap_order ,
404 Base* taylor )
405 {
406 // check assumptions
407 CPPAD_ASSERT_UNKNOWN( NumArg(NevvOp) == 2 );
408 CPPAD_ASSERT_UNKNOWN( NumRes(NevvOp) == 0 );
409
410 // Taylor coefficients corresponding to arguments and result
411 Base* x = taylor + size_t(arg[0]) * cap_order;
412 Base* y = taylor + size_t(arg[1]) * cap_order;
413
414 count += size_t(x[0] == y[0]);
415 }
416
417
418 } } // END_CPPAD_LOCAL_NAMESPACE
419 # endif
0 # ifndef CPPAD_LOCAL_OP_COND_OP_HPP
1 # define CPPAD_LOCAL_OP_COND_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file cond_op.hpp
17 Forward, reverse, and sparse operations for conditional expressions.
18 */
19
20 /*!
21 Shared documentation for conditional expressions (not called).
22
23 <!-- define conditional_exp_op -->
24 The C++ source code coresponding to this operation is
25 \verbatim
26 z = CondExpRel(y_0, y_1, y_2, y_3)
27 \endverbatim
28 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
29
30 \tparam Base
31 base type for the operator; i.e., this operation was recorded
32 using AD< Base > and computations by this routine are done using type
33 Base.
34
35 \param i_z
36 is the AD variable index corresponding to the variable z.
37
38 \param arg
39 \n
40 arg[0]
41 is static cast to size_t from the enum type
42 \verbatim
43 enum CompareOp {
44 CompareLt,
45 CompareLe,
46 CompareEq,
47 CompareGe,
48 CompareGt,
49 CompareNe
50 }
51 \endverbatim
52 for this operation.
53 Note that arg[0] cannot be equal to CompareNe.
54 \n
55 \n
56 arg[1] & 1
57 \n
58 If this is zero, y_0 is a parameter. Otherwise it is a variable.
59 \n
60 \n
61 arg[1] & 2
62 \n
63 If this is zero, y_1 is a parameter. Otherwise it is a variable.
64 \n
65 \n
66 arg[1] & 4
67 \n
68 If this is zero, y_2 is a parameter. Otherwise it is a variable.
69 \n
70 \n
71 arg[1] & 8
72 \n
73 If this is zero, y_3 is a parameter. Otherwise it is a variable.
74 \n
75 \n
76 arg[2 + j ] for j = 0, 1, 2, 3
77 \n
78 is the index corresponding to y_j.
79
80 \param num_par
81 is the total number of values in the vector parameter.
82
83 \param parameter
84 For j = 0, 1, 2, 3,
85 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
86
87 \param cap_order
88 number of columns in the matrix containing the Taylor coefficients.
89
90 \par Checked Assertions
91 \li NumArg(CExpOp) == 6
92 \li NumRes(CExpOp) == 1
93 \li arg[0] < static_cast<size_t> ( CompareNe )
94 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
95 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
96 <!-- end conditional_exp_op -->
97 */
98 template <class Base>
99 void conditional_exp_op(
100 size_t i_z ,
101 const addr_t* arg ,
102 size_t num_par ,
103 const Base* parameter ,
104 size_t cap_order )
105 { // This routine is only for documentation, it should never be used
106 CPPAD_ASSERT_UNKNOWN( false );
107 }
108
109 /*!
110 Shared documentation for conditional expression sparse operations (not called).
111
112 <!-- define sparse_conditional_exp_op -->
113 The C++ source code coresponding to this operation is
114 \verbatim
115 z = CondExpRel(y_0, y_1, y_2, y_3)
116 \endverbatim
117 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
118
119 \tparam Vector_set
120 is the type used for vectors of sets. It can be either
121 sparse::pack_setvec or sparse::list_setvec.
122
123 \param i_z
124 is the AD variable index corresponding to the variable z.
125
126 \param arg
127 \n
128 arg[0]
129 is static cast to size_t from the enum type
130 \verbatim
131 enum CompareOp {
132 CompareLt,
133 CompareLe,
134 CompareEq,
135 CompareGe,
136 CompareGt,
137 CompareNe
138 }
139 \endverbatim
140 for this operation.
141 Note that arg[0] cannot be equal to CompareNe.
142 \n
143 \n
144 arg[1] & 1
145 \n
146 If this is zero, y_0 is a parameter. Otherwise it is a variable.
147 \n
148 \n
149 arg[1] & 2
150 \n
151 If this is zero, y_1 is a parameter. Otherwise it is a variable.
152 \n
153 \n
154 arg[1] & 4
155 \n
156 If this is zero, y_2 is a parameter. Otherwise it is a variable.
157 \n
158 \n
159 arg[1] & 8
160 \n
161 If this is zero, y_3 is a parameter. Otherwise it is a variable.
162 \n
163 \n
164 arg[2 + j ] for j = 0, 1, 2, 3
165 \n
166 is the index corresponding to y_j.
167
168 \param num_par
169 is the total number of values in the vector parameter.
170
171 \par Checked Assertions
172 \li NumArg(CExpOp) == 6
173 \li NumRes(CExpOp) == 1
174 \li arg[0] < static_cast<size_t> ( CompareNe )
175 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
176 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
177 <!-- end sparse_conditional_exp_op -->
178 */
179 template <class Vector_set>
180 void sparse_conditional_exp_op(
181 size_t i_z ,
182 const addr_t* arg ,
183 size_t num_par )
184 { // This routine is only for documentation, it should never be used
185 CPPAD_ASSERT_UNKNOWN( false );
186 }
187
188 /*!
189 Compute forward mode Taylor coefficients for op = CExpOp.
190
191 <!-- replace conditional_exp_op -->
192 The C++ source code coresponding to this operation is
193 \verbatim
194 z = CondExpRel(y_0, y_1, y_2, y_3)
195 \endverbatim
196 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
197
198 \tparam Base
199 base type for the operator; i.e., this operation was recorded
200 using AD< Base > and computations by this routine are done using type
201 Base.
202
203 \param i_z
204 is the AD variable index corresponding to the variable z.
205
206 \param arg
207 \n
208 arg[0]
209 is static cast to size_t from the enum type
210 \verbatim
211 enum CompareOp {
212 CompareLt,
213 CompareLe,
214 CompareEq,
215 CompareGe,
216 CompareGt,
217 CompareNe
218 }
219 \endverbatim
220 for this operation.
221 Note that arg[0] cannot be equal to CompareNe.
222 \n
223 \n
224 arg[1] & 1
225 \n
226 If this is zero, y_0 is a parameter. Otherwise it is a variable.
227 \n
228 \n
229 arg[1] & 2
230 \n
231 If this is zero, y_1 is a parameter. Otherwise it is a variable.
232 \n
233 \n
234 arg[1] & 4
235 \n
236 If this is zero, y_2 is a parameter. Otherwise it is a variable.
237 \n
238 \n
239 arg[1] & 8
240 \n
241 If this is zero, y_3 is a parameter. Otherwise it is a variable.
242 \n
243 \n
244 arg[2 + j ] for j = 0, 1, 2, 3
245 \n
246 is the index corresponding to y_j.
247
248 \param num_par
249 is the total number of values in the vector parameter.
250
251 \param parameter
252 For j = 0, 1, 2, 3,
253 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
254
255 \param cap_order
256 number of columns in the matrix containing the Taylor coefficients.
257
258 \par Checked Assertions
259 \li NumArg(CExpOp) == 6
260 \li NumRes(CExpOp) == 1
261 \li arg[0] < static_cast<size_t> ( CompareNe )
262 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
263 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
264 <!-- end conditional_exp_op -->
265
266 \param p
267 is the lowest order of the Taylor coefficient of z that we are computing.
268
269 \param q
270 is the highest order of the Taylor coefficient of z that we are computing.
271
272 \param taylor
273 \b Input:
274 For j = 0, 1, 2, 3 and k = 0 , ... , q,
275 if y_j is a variable then
276 <code>taylor [ arg[2+j] * cap_order + k ]</code>
277 is the k-th order Taylor coefficient corresponding to y_j.
278 \n
279 \b Input: <code>taylor [ i_z * cap_order + k ]</code>
280 for k = 0 , ... , p-1,
281 is the k-th order Taylor coefficient corresponding to z.
282 \n
283 \b Output: <code>taylor [ i_z * cap_order + k ]</code>
284 for k = p , ... , q,
285 is the k-th order Taylor coefficient corresponding to z.
286
287 */
288 template <class Base>
289 void forward_cond_op(
290 size_t p ,
291 size_t q ,
292 size_t i_z ,
293 const addr_t* arg ,
294 size_t num_par ,
295 const Base* parameter ,
296 size_t cap_order ,
297 Base* taylor )
298 { Base y_0, y_1, y_2, y_3;
299 Base zero(0);
300 Base* z = taylor + i_z * cap_order;
301
302 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
303 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
304 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
305 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
306
307 if( arg[1] & 1 )
308 {
309 y_0 = taylor[ size_t(arg[2]) * cap_order + 0 ];
310 }
311 else
312 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
313 y_0 = parameter[ arg[2] ];
314 }
315 if( arg[1] & 2 )
316 {
317 y_1 = taylor[ size_t(arg[3]) * cap_order + 0 ];
318 }
319 else
320 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
321 y_1 = parameter[ arg[3] ];
322 }
323 if( p == 0 )
324 { if( arg[1] & 4 )
325 {
326 y_2 = taylor[ size_t(arg[4]) * cap_order + 0 ];
327 }
328 else
329 { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_par );
330 y_2 = parameter[ arg[4] ];
331 }
332 if( arg[1] & 8 )
333 {
334 y_3 = taylor[ size_t(arg[5]) * cap_order + 0 ];
335 }
336 else
337 { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < num_par );
338 y_3 = parameter[ arg[5] ];
339 }
340 z[0] = CondExpOp(
341 CompareOp( arg[0] ),
342 y_0,
343 y_1,
344 y_2,
345 y_3
346 );
347 p++;
348 }
349 for(size_t d = p; d <= q; d++)
350 { if( arg[1] & 4 )
351 {
352 y_2 = taylor[ size_t(arg[4]) * cap_order + d];
353 }
354 else
355 y_2 = zero;
356 if( arg[1] & 8 )
357 {
358 y_3 = taylor[ size_t(arg[5]) * cap_order + d];
359 }
360 else
361 y_3 = zero;
362 z[d] = CondExpOp(
363 CompareOp( arg[0] ),
364 y_0,
365 y_1,
366 y_2,
367 y_3
368 );
369 }
370 return;
371 }
372
373 /*!
374 Multiple directions forward mode Taylor coefficients for op = CExpOp.
375
376 <!-- replace conditional_exp_op -->
377 The C++ source code coresponding to this operation is
378 \verbatim
379 z = CondExpRel(y_0, y_1, y_2, y_3)
380 \endverbatim
381 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
382
383 \tparam Base
384 base type for the operator; i.e., this operation was recorded
385 using AD< Base > and computations by this routine are done using type
386 Base.
387
388 \param i_z
389 is the AD variable index corresponding to the variable z.
390
391 \param arg
392 \n
393 arg[0]
394 is static cast to size_t from the enum type
395 \verbatim
396 enum CompareOp {
397 CompareLt,
398 CompareLe,
399 CompareEq,
400 CompareGe,
401 CompareGt,
402 CompareNe
403 }
404 \endverbatim
405 for this operation.
406 Note that arg[0] cannot be equal to CompareNe.
407 \n
408 \n
409 arg[1] & 1
410 \n
411 If this is zero, y_0 is a parameter. Otherwise it is a variable.
412 \n
413 \n
414 arg[1] & 2
415 \n
416 If this is zero, y_1 is a parameter. Otherwise it is a variable.
417 \n
418 \n
419 arg[1] & 4
420 \n
421 If this is zero, y_2 is a parameter. Otherwise it is a variable.
422 \n
423 \n
424 arg[1] & 8
425 \n
426 If this is zero, y_3 is a parameter. Otherwise it is a variable.
427 \n
428 \n
429 arg[2 + j ] for j = 0, 1, 2, 3
430 \n
431 is the index corresponding to y_j.
432
433 \param num_par
434 is the total number of values in the vector parameter.
435
436 \param parameter
437 For j = 0, 1, 2, 3,
438 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
439
440 \param cap_order
441 number of columns in the matrix containing the Taylor coefficients.
442
443 \par Checked Assertions
444 \li NumArg(CExpOp) == 6
445 \li NumRes(CExpOp) == 1
446 \li arg[0] < static_cast<size_t> ( CompareNe )
447 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
448 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
449 <!-- end conditional_exp_op -->
450
451 \param q
452 is order of the Taylor coefficient of z that we are computing.
453
454 \param r
455 is the number of Taylor coefficient directions that we are computing.
456
457 \par tpv
458 We use the notation
459 <code>tpv = (cap_order-1) * r + 1</code>
460 which is the number of Taylor coefficients per variable
461
462 \param taylor
463 \b Input:
464 For j = 0, 1, 2, 3, k = 1, ..., q,
465 if y_j is a variable then
466 <code>taylor [ arg[2+j] * tpv + 0 ]</code>
467 is the zero order Taylor coefficient corresponding to y_j and
468 <code>taylor [ arg[2+j] * tpv + (k-1)*r+1+ell</code> is its
469 k-th order Taylor coefficient in the ell-th direction.
470 \n
471 \b Input:
472 For j = 0, 1, 2, 3, k = 1, ..., q-1,
473 <code>taylor [ i_z * tpv + 0 ]</code>
474 is the zero order Taylor coefficient corresponding to z and
475 <code>taylor [ i_z * tpv + (k-1)*r+1+ell</code> is its
476 k-th order Taylor coefficient in the ell-th direction.
477 \n
478 \b Output: <code>taylor [ i_z * tpv + (q-1)*r+1+ell ]</code>
479 is the q-th order Taylor coefficient corresponding to z
480 in the ell-th direction.
481 */
482 template <class Base>
483 void forward_cond_op_dir(
484 size_t q ,
485 size_t r ,
486 size_t i_z ,
487 const addr_t* arg ,
488 size_t num_par ,
489 const Base* parameter ,
490 size_t cap_order ,
491 Base* taylor )
492 { Base y_0, y_1, y_2, y_3;
493 Base zero(0);
494 size_t num_taylor_per_var = (cap_order-1) * r + 1;
495 Base* z = taylor + i_z * num_taylor_per_var;
496
497 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
498 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
499 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
500 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
501 CPPAD_ASSERT_UNKNOWN( 0 < q );
502 CPPAD_ASSERT_UNKNOWN( q < cap_order );
503
504 if( arg[1] & 1 )
505 {
506 y_0 = taylor[ size_t(arg[2]) * num_taylor_per_var + 0 ];
507 }
508 else
509 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
510 y_0 = parameter[ arg[2] ];
511 }
512 if( arg[1] & 2 )
513 {
514 y_1 = taylor[ size_t(arg[3]) * num_taylor_per_var + 0 ];
515 }
516 else
517 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
518 y_1 = parameter[ arg[3] ];
519 }
520 size_t m = (q-1) * r + 1;
521 for(size_t ell = 0; ell < r; ell++)
522 { if( arg[1] & 4 )
523 {
524 y_2 = taylor[ size_t(arg[4]) * num_taylor_per_var + m + ell];
525 }
526 else
527 y_2 = zero;
528 if( arg[1] & 8 )
529 {
530 y_3 = taylor[ size_t(arg[5]) * num_taylor_per_var + m + ell];
531 }
532 else
533 y_3 = zero;
534 z[m+ell] = CondExpOp(
535 CompareOp( arg[0] ),
536 y_0,
537 y_1,
538 y_2,
539 y_3
540 );
541 }
542 return;
543 }
544
545 /*!
546 Compute zero order forward mode Taylor coefficients for op = CExpOp.
547
548 <!-- replace conditional_exp_op -->
549 The C++ source code coresponding to this operation is
550 \verbatim
551 z = CondExpRel(y_0, y_1, y_2, y_3)
552 \endverbatim
553 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
554
555 \tparam Base
556 base type for the operator; i.e., this operation was recorded
557 using AD< Base > and computations by this routine are done using type
558 Base.
559
560 \param i_z
561 is the AD variable index corresponding to the variable z.
562
563 \param arg
564 \n
565 arg[0]
566 is static cast to size_t from the enum type
567 \verbatim
568 enum CompareOp {
569 CompareLt,
570 CompareLe,
571 CompareEq,
572 CompareGe,
573 CompareGt,
574 CompareNe
575 }
576 \endverbatim
577 for this operation.
578 Note that arg[0] cannot be equal to CompareNe.
579 \n
580 \n
581 arg[1] & 1
582 \n
583 If this is zero, y_0 is a parameter. Otherwise it is a variable.
584 \n
585 \n
586 arg[1] & 2
587 \n
588 If this is zero, y_1 is a parameter. Otherwise it is a variable.
589 \n
590 \n
591 arg[1] & 4
592 \n
593 If this is zero, y_2 is a parameter. Otherwise it is a variable.
594 \n
595 \n
596 arg[1] & 8
597 \n
598 If this is zero, y_3 is a parameter. Otherwise it is a variable.
599 \n
600 \n
601 arg[2 + j ] for j = 0, 1, 2, 3
602 \n
603 is the index corresponding to y_j.
604
605 \param num_par
606 is the total number of values in the vector parameter.
607
608 \param parameter
609 For j = 0, 1, 2, 3,
610 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
611
612 \param cap_order
613 number of columns in the matrix containing the Taylor coefficients.
614
615 \par Checked Assertions
616 \li NumArg(CExpOp) == 6
617 \li NumRes(CExpOp) == 1
618 \li arg[0] < static_cast<size_t> ( CompareNe )
619 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
620 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
621 <!-- end conditional_exp_op -->
622
623 \param taylor
624 \b Input:
625 For j = 0, 1, 2, 3,
626 if y_j is a variable then
627 taylor [ arg[2+j] * cap_order + 0 ]
628 is the zero order Taylor coefficient corresponding to y_j.
629 \n
630 \b Output: taylor [ i_z * cap_order + 0 ]
631 is the zero order Taylor coefficient corresponding to z.
632 */
633 template <class Base>
634 void forward_cond_op_0(
635 size_t i_z ,
636 const addr_t* arg ,
637 size_t num_par ,
638 const Base* parameter ,
639 size_t cap_order ,
640 Base* taylor )
641 { Base y_0, y_1, y_2, y_3;
642 Base* z;
643
644 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
645 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
646 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
647 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
648
649 if( arg[1] & 1 )
650 {
651 y_0 = taylor[ size_t(arg[2]) * cap_order + 0 ];
652 }
653 else
654 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
655 y_0 = parameter[ arg[2] ];
656 }
657 if( arg[1] & 2 )
658 {
659 y_1 = taylor[ size_t(arg[3]) * cap_order + 0 ];
660 }
661 else
662 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
663 y_1 = parameter[ arg[3] ];
664 }
665 if( arg[1] & 4 )
666 {
667 y_2 = taylor[ size_t(arg[4]) * cap_order + 0 ];
668 }
669 else
670 { CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_par );
671 y_2 = parameter[ arg[4] ];
672 }
673 if( arg[1] & 8 )
674 {
675 y_3 = taylor[ size_t(arg[5]) * cap_order + 0 ];
676 }
677 else
678 { CPPAD_ASSERT_UNKNOWN( size_t(arg[5]) < num_par );
679 y_3 = parameter[ arg[5] ];
680 }
681 z = taylor + i_z * cap_order;
682 z[0] = CondExpOp(
683 CompareOp( arg[0] ),
684 y_0,
685 y_1,
686 y_2,
687 y_3
688 );
689 return;
690 }
691
692 /*!
693 Compute reverse mode Taylor coefficients for op = CExpOp.
694
695 This routine is given the partial derivatives of a function
696 G( z , y , x , w , ... )
697 and it uses them to compute the partial derivatives of
698 \verbatim
699 H( y , x , w , u , ... ) = G[ z(y) , y , x , w , u , ... ]
700 \endverbatim
701 where y above represents y_0, y_1, y_2, y_3.
702
703 <!-- replace conditional_exp_op -->
704 The C++ source code coresponding to this operation is
705 \verbatim
706 z = CondExpRel(y_0, y_1, y_2, y_3)
707 \endverbatim
708 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
709
710 \tparam Base
711 base type for the operator; i.e., this operation was recorded
712 using AD< Base > and computations by this routine are done using type
713 Base.
714
715 \param i_z
716 is the AD variable index corresponding to the variable z.
717
718 \param arg
719 \n
720 arg[0]
721 is static cast to size_t from the enum type
722 \verbatim
723 enum CompareOp {
724 CompareLt,
725 CompareLe,
726 CompareEq,
727 CompareGe,
728 CompareGt,
729 CompareNe
730 }
731 \endverbatim
732 for this operation.
733 Note that arg[0] cannot be equal to CompareNe.
734 \n
735 \n
736 arg[1] & 1
737 \n
738 If this is zero, y_0 is a parameter. Otherwise it is a variable.
739 \n
740 \n
741 arg[1] & 2
742 \n
743 If this is zero, y_1 is a parameter. Otherwise it is a variable.
744 \n
745 \n
746 arg[1] & 4
747 \n
748 If this is zero, y_2 is a parameter. Otherwise it is a variable.
749 \n
750 \n
751 arg[1] & 8
752 \n
753 If this is zero, y_3 is a parameter. Otherwise it is a variable.
754 \n
755 \n
756 arg[2 + j ] for j = 0, 1, 2, 3
757 \n
758 is the index corresponding to y_j.
759
760 \param num_par
761 is the total number of values in the vector parameter.
762
763 \param parameter
764 For j = 0, 1, 2, 3,
765 if y_j is a parameter, parameter [ arg[2 + j] ] is its value.
766
767 \param cap_order
768 number of columns in the matrix containing the Taylor coefficients.
769
770 \par Checked Assertions
771 \li NumArg(CExpOp) == 6
772 \li NumRes(CExpOp) == 1
773 \li arg[0] < static_cast<size_t> ( CompareNe )
774 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
775 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
776 <!-- end conditional_exp_op -->
777
778 \param d
779 is the order of the Taylor coefficient of z that we are computing.
780
781 \param taylor
782 \b Input:
783 For j = 0, 1, 2, 3 and k = 0 , ... , d,
784 if y_j is a variable then
785 taylor [ arg[2+j] * cap_order + k ]
786 is the k-th order Taylor coefficient corresponding to y_j.
787 \n
788 taylor [ i_z * cap_order + k ]
789 for k = 0 , ... , d
790 is the k-th order Taylor coefficient corresponding to z.
791
792 \param nc_partial
793 number of columns in the matrix containing the Taylor coefficients.
794
795 \param partial
796 \b Input:
797 For j = 0, 1, 2, 3 and k = 0 , ... , d,
798 if y_j is a variable then
799 partial [ arg[2+j] * nc_partial + k ]
800 is the partial derivative of G( z , y , x , w , u , ... )
801 with respect to the k-th order Taylor coefficient corresponding to y_j.
802 \n
803 \b Input: partial [ i_z * cap_order + k ]
804 for k = 0 , ... , d
805 is the partial derivative of G( z , y , x , w , u , ... )
806 with respect to the k-th order Taylor coefficient corresponding to z.
807 \n
808 \b Output:
809 For j = 0, 1, 2, 3 and k = 0 , ... , d,
810 if y_j is a variable then
811 partial [ arg[2+j] * nc_partial + k ]
812 is the partial derivative of H( y , x , w , u , ... )
813 with respect to the k-th order Taylor coefficient corresponding to y_j.
814
815 */
816 template <class Base>
817 void reverse_cond_op(
818 size_t d ,
819 size_t i_z ,
820 const addr_t* arg ,
821 size_t num_par ,
822 const Base* parameter ,
823 size_t cap_order ,
824 const Base* taylor ,
825 size_t nc_partial ,
826 Base* partial )
827 { Base y_0, y_1;
828 Base zero(0);
829 Base* pz;
830 Base* py_2;
831 Base* py_3;
832
833 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
834 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
835 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
836 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
837
838 pz = partial + i_z * nc_partial + 0;
839 if( arg[1] & 1 )
840 {
841 y_0 = taylor[ size_t(arg[2]) * cap_order + 0 ];
842 }
843 else
844 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
845 y_0 = parameter[ arg[2] ];
846 }
847 if( arg[1] & 2 )
848 {
849 y_1 = taylor[ size_t(arg[3]) * cap_order + 0 ];
850 }
851 else
852 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
853 y_1 = parameter[ arg[3] ];
854 }
855 if( arg[1] & 4 )
856 {
857 py_2 = partial + size_t(arg[4]) * nc_partial;
858 size_t j = d + 1;
859 while(j--)
860 { py_2[j] += CondExpOp(
861 CompareOp( arg[0] ),
862 y_0,
863 y_1,
864 pz[j],
865 zero
866 );
867 }
868 }
869 if( arg[1] & 8 )
870 {
871 py_3 = partial + size_t(arg[5]) * nc_partial;
872 size_t j = d + 1;
873 while(j--)
874 { py_3[j] += CondExpOp(
875 CompareOp( arg[0] ),
876 y_0,
877 y_1,
878 zero,
879 pz[j]
880 );
881 }
882 }
883 return;
884 }
885
886 /*!
887 Compute forward Jacobian sparsity patterns for op = CExpOp.
888
889 <!-- replace sparse_conditional_exp_op -->
890 The C++ source code coresponding to this operation is
891 \verbatim
892 z = CondExpRel(y_0, y_1, y_2, y_3)
893 \endverbatim
894 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
895
896 \tparam Vector_set
897 is the type used for vectors of sets. It can be either
898 sparse::pack_setvec or sparse::list_setvec.
899
900 \param i_z
901 is the AD variable index corresponding to the variable z.
902
903 \param arg
904 \n
905 arg[0]
906 is static cast to size_t from the enum type
907 \verbatim
908 enum CompareOp {
909 CompareLt,
910 CompareLe,
911 CompareEq,
912 CompareGe,
913 CompareGt,
914 CompareNe
915 }
916 \endverbatim
917 for this operation.
918 Note that arg[0] cannot be equal to CompareNe.
919 \n
920 \n
921 arg[1] & 1
922 \n
923 If this is zero, y_0 is a parameter. Otherwise it is a variable.
924 \n
925 \n
926 arg[1] & 2
927 \n
928 If this is zero, y_1 is a parameter. Otherwise it is a variable.
929 \n
930 \n
931 arg[1] & 4
932 \n
933 If this is zero, y_2 is a parameter. Otherwise it is a variable.
934 \n
935 \n
936 arg[1] & 8
937 \n
938 If this is zero, y_3 is a parameter. Otherwise it is a variable.
939 \n
940 \n
941 arg[2 + j ] for j = 0, 1, 2, 3
942 \n
943 is the index corresponding to y_j.
944
945 \param num_par
946 is the total number of values in the vector parameter.
947
948 \par Checked Assertions
949 \li NumArg(CExpOp) == 6
950 \li NumRes(CExpOp) == 1
951 \li arg[0] < static_cast<size_t> ( CompareNe )
952 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
953 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
954 <!-- end sparse_conditional_exp_op -->
955
956 \param dependency
957 Are the derivatives with respect to left and right of the expression below
958 considered to be non-zero:
959 \code
960 CondExpRel(left, right, if_true, if_false)
961 \endcode
962 This is used by the optimizer to obtain the correct dependency relations.
963
964 \param sparsity
965 \b Input:
966 if y_2 is a variable, the set with index t is
967 the sparsity pattern corresponding to y_2.
968 This identifies which of the independent variables the variable y_2
969 depends on.
970 \n
971 \b Input:
972 if y_3 is a variable, the set with index t is
973 the sparsity pattern corresponding to y_3.
974 This identifies which of the independent variables the variable y_3
975 depends on.
976 \n
977 \b Output:
978 The set with index T is
979 the sparsity pattern corresponding to z.
980 This identifies which of the independent variables the variable z
981 depends on.
982 */
983 template <class Vector_set>
984 void forward_sparse_jacobian_cond_op(
985 bool dependency ,
986 size_t i_z ,
987 const addr_t* arg ,
988 size_t num_par ,
989 Vector_set& sparsity )
990 {
991 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
992 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
993 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
994 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
995 # ifndef NDEBUG
996 addr_t k = 1;
997 for( size_t j = 0; j < 4; j++)
998 { if( ! ( arg[1] & k ) )
999 CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par );
1000 k *= 2;
1001 }
1002 # endif
1003 sparsity.clear(i_z);
1004 if( dependency )
1005 { if( arg[1] & 1 )
1006 sparsity.binary_union(i_z, i_z, size_t(arg[2]), sparsity);
1007 if( arg[1] & 2 )
1008 sparsity.binary_union(i_z, i_z, size_t(arg[3]), sparsity);
1009 }
1010 if( arg[1] & 4 )
1011 sparsity.binary_union(i_z, i_z, size_t(arg[4]), sparsity);
1012 if( arg[1] & 8 )
1013 sparsity.binary_union(i_z, i_z, size_t(arg[5]), sparsity);
1014 return;
1015 }
1016
1017 /*!
1018 Compute reverse Jacobian sparsity patterns for op = CExpOp.
1019
1020 This routine is given the sparsity patterns
1021 for a function G(z, y, x, ... )
1022 and it uses them to compute the sparsity patterns for
1023 \verbatim
1024 H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1025 \endverbatim
1026 where y represents the combination of y_0, y_1, y_2, and y_3.
1027
1028 <!-- replace sparse_conditional_exp_op -->
1029 The C++ source code coresponding to this operation is
1030 \verbatim
1031 z = CondExpRel(y_0, y_1, y_2, y_3)
1032 \endverbatim
1033 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
1034
1035 \tparam Vector_set
1036 is the type used for vectors of sets. It can be either
1037 sparse::pack_setvec or sparse::list_setvec.
1038
1039 \param i_z
1040 is the AD variable index corresponding to the variable z.
1041
1042 \param arg
1043 \n
1044 arg[0]
1045 is static cast to size_t from the enum type
1046 \verbatim
1047 enum CompareOp {
1048 CompareLt,
1049 CompareLe,
1050 CompareEq,
1051 CompareGe,
1052 CompareGt,
1053 CompareNe
1054 }
1055 \endverbatim
1056 for this operation.
1057 Note that arg[0] cannot be equal to CompareNe.
1058 \n
1059 \n
1060 arg[1] & 1
1061 \n
1062 If this is zero, y_0 is a parameter. Otherwise it is a variable.
1063 \n
1064 \n
1065 arg[1] & 2
1066 \n
1067 If this is zero, y_1 is a parameter. Otherwise it is a variable.
1068 \n
1069 \n
1070 arg[1] & 4
1071 \n
1072 If this is zero, y_2 is a parameter. Otherwise it is a variable.
1073 \n
1074 \n
1075 arg[1] & 8
1076 \n
1077 If this is zero, y_3 is a parameter. Otherwise it is a variable.
1078 \n
1079 \n
1080 arg[2 + j ] for j = 0, 1, 2, 3
1081 \n
1082 is the index corresponding to y_j.
1083
1084 \param num_par
1085 is the total number of values in the vector parameter.
1086
1087 \par Checked Assertions
1088 \li NumArg(CExpOp) == 6
1089 \li NumRes(CExpOp) == 1
1090 \li arg[0] < static_cast<size_t> ( CompareNe )
1091 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
1092 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
1093 <!-- end sparse_conditional_exp_op -->
1094
1095 \param dependency
1096 Are the derivatives with respect to left and right of the expression below
1097 considered to be non-zero:
1098 \code
1099 CondExpRel(left, right, if_true, if_false)
1100 \endcode
1101 This is used by the optimizer to obtain the correct dependency relations.
1102
1103
1104 \param sparsity
1105 if y_2 is a variable, the set with index t is
1106 the sparsity pattern corresponding to y_2.
1107 This identifies which of the dependent variables depend on the variable y_2.
1108 On input, this pattern corresponds to the function G.
1109 On ouput, it corresponds to the function H.
1110 \n
1111 \n
1112 if y_3 is a variable, the set with index t is
1113 the sparsity pattern corresponding to y_3.
1114 This identifies which of the dependent variables depeond on the variable y_3.
1115 On input, this pattern corresponds to the function G.
1116 On ouput, it corresponds to the function H.
1117 \n
1118 \b Output:
1119 The set with index T is
1120 the sparsity pattern corresponding to z.
1121 This identifies which of the dependent variables depend on the variable z.
1122 On input and output, this pattern corresponds to the function G.
1123 */
1124 template <class Vector_set>
1125 void reverse_sparse_jacobian_cond_op(
1126 bool dependency ,
1127 size_t i_z ,
1128 const addr_t* arg ,
1129 size_t num_par ,
1130 Vector_set& sparsity )
1131 {
1132 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
1133 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
1134 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
1135 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
1136 # ifndef NDEBUG
1137 addr_t k = 1;
1138 for( size_t j = 0; j < 4; j++)
1139 { if( ! ( arg[1] & k ) )
1140 CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par );
1141 k *= 2;
1142 }
1143 # endif
1144 if( dependency )
1145 { if( arg[1] & 1 )
1146 sparsity.binary_union( size_t(arg[2]), size_t(arg[2]), i_z, sparsity);
1147 if( arg[1] & 2 )
1148 sparsity.binary_union( size_t(arg[3]), size_t(arg[3]), i_z, sparsity);
1149 }
1150 // --------------------------------------------------------------------
1151 if( arg[1] & 4 )
1152 sparsity.binary_union( size_t(arg[4]), size_t(arg[4]), i_z, sparsity);
1153 if( arg[1] & 8 )
1154 sparsity.binary_union( size_t(arg[5]), size_t(arg[5]), i_z, sparsity);
1155 return;
1156 }
1157
1158 /*!
1159 Compute reverse Hessian sparsity patterns for op = CExpOp.
1160
1161 This routine is given the sparsity patterns
1162 for a function G(z, y, x, ... )
1163 and it uses them to compute the sparsity patterns for
1164 \verbatim
1165 H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1166 \endverbatim
1167 where y represents the combination of y_0, y_1, y_2, and y_3.
1168
1169 <!-- replace sparse_conditional_exp_op -->
1170 The C++ source code coresponding to this operation is
1171 \verbatim
1172 z = CondExpRel(y_0, y_1, y_2, y_3)
1173 \endverbatim
1174 where Rel is one of the following: Lt, Le, Eq, Ge, Gt.
1175
1176 \tparam Vector_set
1177 is the type used for vectors of sets. It can be either
1178 sparse::pack_setvec or sparse::list_setvec.
1179
1180 \param i_z
1181 is the AD variable index corresponding to the variable z.
1182
1183 \param arg
1184 \n
1185 arg[0]
1186 is static cast to size_t from the enum type
1187 \verbatim
1188 enum CompareOp {
1189 CompareLt,
1190 CompareLe,
1191 CompareEq,
1192 CompareGe,
1193 CompareGt,
1194 CompareNe
1195 }
1196 \endverbatim
1197 for this operation.
1198 Note that arg[0] cannot be equal to CompareNe.
1199 \n
1200 \n
1201 arg[1] & 1
1202 \n
1203 If this is zero, y_0 is a parameter. Otherwise it is a variable.
1204 \n
1205 \n
1206 arg[1] & 2
1207 \n
1208 If this is zero, y_1 is a parameter. Otherwise it is a variable.
1209 \n
1210 \n
1211 arg[1] & 4
1212 \n
1213 If this is zero, y_2 is a parameter. Otherwise it is a variable.
1214 \n
1215 \n
1216 arg[1] & 8
1217 \n
1218 If this is zero, y_3 is a parameter. Otherwise it is a variable.
1219 \n
1220 \n
1221 arg[2 + j ] for j = 0, 1, 2, 3
1222 \n
1223 is the index corresponding to y_j.
1224
1225 \param num_par
1226 is the total number of values in the vector parameter.
1227
1228 \par Checked Assertions
1229 \li NumArg(CExpOp) == 6
1230 \li NumRes(CExpOp) == 1
1231 \li arg[0] < static_cast<size_t> ( CompareNe )
1232 \li arg[1] != 0; i.e., not all of y_0, y_1, y_2, y_3 are parameters.
1233 \li For j = 0, 1, 2, 3 if y_j is a parameter, arg[2+j] < num_par.
1234 <!-- end sparse_conditional_exp_op -->
1235
1236
1237 \param jac_reverse
1238 jac_reverse[i_z]
1239 is false (true) if the Jacobian of G with respect to z is always zero
1240 (may be non-zero).
1241 \n
1242 \n
1243 jac_reverse[ arg[4] ]
1244 If y_2 is a variable,
1245 jac_reverse[ arg[4] ]
1246 is false (true) if the Jacobian with respect to y_2 is always zero
1247 (may be non-zero).
1248 On input, it corresponds to the function G,
1249 and on output it corresponds to the function H.
1250 \n
1251 \n
1252 jac_reverse[ arg[5] ]
1253 If y_3 is a variable,
1254 jac_reverse[ arg[5] ]
1255 is false (true) if the Jacobian with respect to y_3 is always zero
1256 (may be non-zero).
1257 On input, it corresponds to the function G,
1258 and on output it corresponds to the function H.
1259
1260 \param hes_sparsity
1261 The set with index i_z in hes_sparsity
1262 is the Hessian sparsity pattern for the function G
1263 where one of the partials is with respect to z.
1264 \n
1265 \n
1266 If y_2 is a variable,
1267 the set with index arg[4] in hes_sparsity
1268 is the Hessian sparsity pattern
1269 where one of the partials is with respect to y_2.
1270 On input, this pattern corresponds to the function G.
1271 On output, this pattern corresponds to the function H.
1272 \n
1273 \n
1274 If y_3 is a variable,
1275 the set with index arg[5] in hes_sparsity
1276 is the Hessian sparsity pattern
1277 where one of the partials is with respect to y_3.
1278 On input, this pattern corresponds to the function G.
1279 On output, this pattern corresponds to the function H.
1280 */
1281 template <class Vector_set>
1282 void reverse_sparse_hessian_cond_op(
1283 size_t i_z ,
1284 const addr_t* arg ,
1285 size_t num_par ,
1286 bool* jac_reverse ,
1287 Vector_set& hes_sparsity )
1288 {
1289
1290 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < static_cast<size_t> (CompareNe) );
1291 CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
1292 CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
1293 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
1294 # ifndef NDEBUG
1295 addr_t k = 1;
1296 for( size_t j = 0; j < 4; j++)
1297 { if( ! ( arg[1] & k ) )
1298 CPPAD_ASSERT_UNKNOWN( size_t(arg[2+j]) < num_par );
1299 k *= 2;
1300 }
1301 # endif
1302 if( arg[1] & 4 )
1303 {
1304 hes_sparsity.binary_union( size_t(arg[4]), size_t(arg[4]), i_z, hes_sparsity);
1305 jac_reverse[ arg[4] ] |= jac_reverse[i_z];
1306 }
1307 if( arg[1] & 8 )
1308 {
1309 hes_sparsity.binary_union( size_t(arg[5]), size_t(arg[5]), i_z, hes_sparsity);
1310 jac_reverse[ arg[5] ] |= jac_reverse[i_z];
1311 }
1312 return;
1313 }
1314
1315 } } // END_CPPAD_LOCAL_NAMESPACE
1316 # endif
0 # ifndef CPPAD_LOCAL_OP_COS_OP_HPP
1 # define CPPAD_LOCAL_OP_COS_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17 // See dev documentation: forward_unary_op
18 template <class Base>
19 void forward_cos_op(
20 size_t p ,
21 size_t q ,
22 size_t i_z ,
23 size_t i_x ,
24 size_t cap_order ,
25 Base* taylor )
26 {
27 // check assumptions
28 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
29 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
30 CPPAD_ASSERT_UNKNOWN( q < cap_order );
31 CPPAD_ASSERT_UNKNOWN( p <= q );
32
33 // Taylor coefficients corresponding to argument and result
34 Base* x = taylor + i_x * cap_order;
35 Base* c = taylor + i_z * cap_order;
36 Base* s = c - cap_order;
37
38
39 // rest of this routine is identical for the following cases:
40 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op.
41 // (except that there is a sign difference for the hyperbolic case).
42 size_t k;
43 if( p == 0 )
44 { s[0] = sin( x[0] );
45 c[0] = cos( x[0] );
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 {
50 s[j] = Base(0.0);
51 c[j] = Base(0.0);
52 for(k = 1; k <= j; k++)
53 { s[j] += Base(double(k)) * x[k] * c[j-k];
54 c[j] -= Base(double(k)) * x[k] * s[j-k];
55 }
56 s[j] /= Base(double(j));
57 c[j] /= Base(double(j));
58 }
59 }
60 // See dev documentation: forward_unary_op
61 template <class Base>
62 void forward_cos_op_dir(
63 size_t q ,
64 size_t r ,
65 size_t i_z ,
66 size_t i_x ,
67 size_t cap_order ,
68 Base* taylor )
69 {
70 // check assumptions
71 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
72 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
73 CPPAD_ASSERT_UNKNOWN( 0 < q );
74 CPPAD_ASSERT_UNKNOWN( q < cap_order );
75
76 // Taylor coefficients corresponding to argument and result
77 size_t num_taylor_per_var = (cap_order-1) * r + 1;
78 Base* x = taylor + i_x * num_taylor_per_var;
79 Base* c = taylor + i_z * num_taylor_per_var;
80 Base* s = c - num_taylor_per_var;
81
82
83 // rest of this routine is identical for the following cases:
84 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
85 // (except that there is a sign difference for the hyperbolic case).
86 size_t m = (q-1) * r + 1;
87 for(size_t ell = 0; ell < r; ell++)
88 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
89 c[m+ell] = - Base(double(q)) * x[m + ell] * s[0];
90 for(size_t k = 1; k < q; k++)
91 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
92 c[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
93 }
94 s[m+ell] /= Base(double(q));
95 c[m+ell] /= Base(double(q));
96 }
97 }
98
99 // See dev documentation: forward_unary_op
100 template <class Base>
101 void forward_cos_op_0(
102 size_t i_z ,
103 size_t i_x ,
104 size_t cap_order ,
105 Base* taylor )
106 {
107 // check assumptions
108 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
109 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
110 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
111
112 // Taylor coefficients corresponding to argument and result
113 Base* x = taylor + i_x * cap_order;
114 Base* c = taylor + i_z * cap_order; // called z in documentation
115 Base* s = c - cap_order; // called y in documentation
116
117 c[0] = cos( x[0] );
118 s[0] = sin( x[0] );
119 }
120
121 // See dev documentation: reverse_unary_op
122 template <class Base>
123 void reverse_cos_op(
124 size_t d ,
125 size_t i_z ,
126 size_t i_x ,
127 size_t cap_order ,
128 const Base* taylor ,
129 size_t nc_partial ,
130 Base* partial )
131 {
132 // check assumptions
133 CPPAD_ASSERT_UNKNOWN( NumArg(CosOp) == 1 );
134 CPPAD_ASSERT_UNKNOWN( NumRes(CosOp) == 2 );
135 CPPAD_ASSERT_UNKNOWN( d < cap_order );
136 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
137
138 // Taylor coefficients and partials corresponding to argument
139 const Base* x = taylor + i_x * cap_order;
140 Base* px = partial + i_x * nc_partial;
141
142 // Taylor coefficients and partials corresponding to first result
143 const Base* c = taylor + i_z * cap_order; // called z in doc
144 Base* pc = partial + i_z * nc_partial;
145
146 // Taylor coefficients and partials corresponding to auxillary result
147 const Base* s = c - cap_order; // called y in documentation
148 Base* ps = pc - nc_partial;
149
150
151 // rest of this routine is identical for the following cases:
152 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
153 size_t j = d;
154 size_t k;
155 while(j)
156 {
157 ps[j] /= Base(double(j));
158 pc[j] /= Base(double(j));
159 for(k = 1; k <= j; k++)
160 {
161 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
162 px[k] -= Base(double(k)) * azmul(pc[j], s[j-k]);
163
164 ps[j-k] -= Base(double(k)) * azmul(pc[j], x[k]);
165 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
166
167 }
168 --j;
169 }
170 px[0] += azmul(ps[0], c[0]);
171 px[0] -= azmul(pc[0], s[0]);
172 }
173
174 } } // END_CPPAD_LOCAL_NAMESPACE
175 # endif
0 # ifndef CPPAD_LOCAL_OP_COSH_OP_HPP
1 # define CPPAD_LOCAL_OP_COSH_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_cosh_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* c = taylor + i_z * cap_order;
37 Base* s = c - cap_order;
38
39 // rest of this routine is identical for the following cases:
40 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op.
41 // (except that there is a sign difference for hyperbolic case).
42 size_t k;
43 if( p == 0 )
44 { s[0] = sinh( x[0] );
45 c[0] = cosh( x[0] );
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 {
50 s[j] = Base(0.0);
51 c[j] = Base(0.0);
52 for(k = 1; k <= j; k++)
53 { s[j] += Base(double(k)) * x[k] * c[j-k];
54 c[j] += Base(double(k)) * x[k] * s[j-k];
55 }
56 s[j] /= Base(double(j));
57 c[j] /= Base(double(j));
58 }
59 }
60 // See dev documentation: forward_unary_op
61 template <class Base>
62 void forward_cosh_op_dir(
63 size_t q ,
64 size_t r ,
65 size_t i_z ,
66 size_t i_x ,
67 size_t cap_order ,
68 Base* taylor )
69 {
70 // check assumptions
71 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
72 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
73 CPPAD_ASSERT_UNKNOWN( 0 < q );
74 CPPAD_ASSERT_UNKNOWN( q < cap_order );
75
76 // Taylor coefficients corresponding to argument and result
77 size_t num_taylor_per_var = (cap_order-1) * r + 1;
78 Base* x = taylor + i_x * num_taylor_per_var;
79 Base* s = taylor + i_z * num_taylor_per_var;
80 Base* c = s - num_taylor_per_var;
81
82
83 // rest of this routine is identical for the following cases:
84 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
85 // (except that there is a sign difference for the hyperbolic case).
86 size_t m = (q-1) * r + 1;
87 for(size_t ell = 0; ell < r; ell++)
88 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
89 c[m+ell] = Base(double(q)) * x[m + ell] * s[0];
90 for(size_t k = 1; k < q; k++)
91 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
92 c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
93 }
94 s[m+ell] /= Base(double(q));
95 c[m+ell] /= Base(double(q));
96 }
97 }
98
99 // See dev documentation: forward_unary_op
100 template <class Base>
101 void forward_cosh_op_0(
102 size_t i_z ,
103 size_t i_x ,
104 size_t cap_order ,
105 Base* taylor )
106 {
107 // check assumptions
108 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
109 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
110 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
111
112 // Taylor coefficients corresponding to argument and result
113 Base* x = taylor + i_x * cap_order;
114 Base* c = taylor + i_z * cap_order; // called z in documentation
115 Base* s = c - cap_order; // called y in documentation
116
117 c[0] = cosh( x[0] );
118 s[0] = sinh( x[0] );
119 }
120
121 // See dev documentation: reverse_unary_op
122 template <class Base>
123 void reverse_cosh_op(
124 size_t d ,
125 size_t i_z ,
126 size_t i_x ,
127 size_t cap_order ,
128 const Base* taylor ,
129 size_t nc_partial ,
130 Base* partial )
131 {
132 // check assumptions
133 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 );
134 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 );
135 CPPAD_ASSERT_UNKNOWN( d < cap_order );
136 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
137
138 // Taylor coefficients and partials corresponding to argument
139 const Base* x = taylor + i_x * cap_order;
140 Base* px = partial + i_x * nc_partial;
141
142 // Taylor coefficients and partials corresponding to first result
143 const Base* c = taylor + i_z * cap_order; // called z in doc
144 Base* pc = partial + i_z * nc_partial;
145
146 // Taylor coefficients and partials corresponding to auxillary result
147 const Base* s = c - cap_order; // called y in documentation
148 Base* ps = pc - nc_partial;
149
150
151 // rest of this routine is identical for the following cases:
152 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
153 size_t j = d;
154 size_t k;
155 while(j)
156 {
157 ps[j] /= Base(double(j));
158 pc[j] /= Base(double(j));
159 for(k = 1; k <= j; k++)
160 {
161 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
162 px[k] += Base(double(k)) * azmul(pc[j], s[j-k]);
163
164 ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]);
165 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
166
167 }
168 --j;
169 }
170 px[0] += azmul(ps[0], c[0]);
171 px[0] += azmul(pc[0], s[0]);
172 }
173
174 } } // END_CPPAD_LOCAL_NAMESPACE
175 # endif
0 # ifndef CPPAD_LOCAL_OP_CSKIP_OP_HPP
1 # define CPPAD_LOCAL_OP_CSKIP_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file cskip_op.hpp
17 Zero order forward mode set which operations to skip.
18 */
19
20 /*!
21 Zero order forward mode execution of op = CSkipOp.
22
23 \par Parameters and Variables
24 The terms parameter and variable depend on if we are referring to its
25 AD<Base> or Base value.
26 We use Base parameter and Base variable to refer to the
27 correspond Base value.
28 We use AD<Base> parameter and AD<Base> variable to refer to the
29 correspond AD<Base> value.
30
31 \tparam Base
32 base type for the operator; i.e., this operation was recorded
33 using AD<Base> and computations by this routine are done using type Base.
34
35 \param i_z
36 variable index corresponding to the result of the previous operation.
37 This is used for error checking. To be specific,
38 the left and right operands for the CExpOp operation must have indexes
39 less than or equal this value.
40
41 \param arg [in]
42 \n
43 arg[0]
44 is static cast to size_t from the enum type
45 \verbatim
46 enum CompareOp {
47 CompareLt,
48 CompareLe,
49 CompareEq,
50 CompareGe,
51 CompareGt,
52 CompareNe
53 }
54 \endverbatim
55 for this operation.
56 Note that arg[0] cannot be equal to CompareNe.
57 \n
58 \n
59 arg[1] & 1
60 \n
61 If this is zero, left is an AD<Base> parameter.
62 Otherwise it is an AD<Base> variable.
63 \n
64 \n
65 arg[1] & 2
66 \n
67 If this is zero, right is an AD<Base> parameter.
68 Otherwise it is an AD<Base> variable.
69 \n
70 arg[2]
71 is the index corresponding to left in comparison.
72 \n
73 arg[3]
74 is the index corresponding to right in comparison.
75 \n
76 arg[4]
77 is the number of operations to skip if the comparison result is true.
78 \n
79 arg[5]
80 is the number of operations to skip if the comparison result is false.
81 \n
82 <tt>arg[5+i]</tt>
83 for <tt>i = 1 , ... , arg[4]</tt> are the operations to skip if the
84 comparison result is true and both left and right are
85 identically Base parameters.
86 \n
87 <tt>arg[5+arg[4]+i]</tt>
88 for <tt>i = 1 , ... , arg[5]</tt> are the operations to skip if the
89 comparison result is false and both left and right are
90 identically Base parameters.
91
92 \param num_par [in]
93 is the total number of values in the vector parameter.
94
95 \param parameter [in]
96 If left is an AD<Base> parameter,
97 <code>parameter [ arg[2] ]</code> is its value.
98 If right is an AD<Base> parameter,
99 <code>parameter [ arg[3] ]</code> is its value.
100
101 \param cap_order [in]
102 number of columns in the matrix containing the Taylor coefficients.
103
104 \param taylor [in]
105 If left is an AD<Base> variable,
106 <code>taylor [ size_t(arg[2]) * cap_order + 0 ]</code>
107 is the zeroth order Taylor coefficient corresponding to left.
108 If right is an AD<Base> variable,
109 <code>taylor [ size_t(arg[3]) * cap_order + 0 ]</code>
110 is the zeroth order Taylor coefficient corresponding to right.
111
112 \param cskip_op [in,out]
113 is vector specifying which operations are at this point are know to be
114 unecessary and can be skipped.
115 This is both an input and an output.
116 */
117 template <class Base>
118 void forward_cskip_op_0(
119 size_t i_z ,
120 const addr_t* arg ,
121 size_t num_par ,
122 const Base* parameter ,
123 size_t cap_order ,
124 Base* taylor ,
125 bool* cskip_op )
126 {
127 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < size_t(CompareNe) );
128 CPPAD_ASSERT_UNKNOWN( arg[1] != 0 );
129
130 Base left, right;
131 if( arg[1] & 1 )
132 { // If variable arg[2] <= i_z, it has already been computed,
133 // but it will be skipped for higher orders.
134 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) <= i_z );
135 left = taylor[ size_t(arg[2]) * cap_order + 0 ];
136 }
137 else
138 { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
139 left = parameter[ arg[2] ];
140 }
141 if( arg[1] & 2 )
142 { // If variable arg[3] <= i_z, it has already been computed,
143 // but it will be skipped for higher orders.
144 CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) <= i_z );
145 right = taylor[ size_t(arg[3]) * cap_order + 0 ];
146 }
147 else
148 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
149 right = parameter[ arg[3] ];
150 }
151 bool ok_to_skip = IdenticalCon(left) & IdenticalCon(right);
152 if( ! ok_to_skip )
153 return;
154
155 // initialize to avoid compiler warning
156 bool true_case = false;
157 Base diff = left - right;
158 switch( CompareOp( arg[0] ) )
159 {
160 case CompareLt:
161 true_case = LessThanZero(diff);
162 break;
163
164 case CompareLe:
165 true_case = LessThanOrZero(diff);
166 break;
167
168 case CompareEq:
169 true_case = IdenticalZero(diff);
170 break;
171
172 case CompareGe:
173 true_case = GreaterThanOrZero(diff);
174 break;
175
176 case CompareGt:
177 true_case = GreaterThanZero(diff);
178 break;
179
180 case CompareNe:
181 true_case = ! IdenticalZero(diff);
182 break;
183
184 default:
185 CPPAD_ASSERT_UNKNOWN(false);
186 }
187 if( true_case )
188 { for(addr_t i = 0; i < arg[4]; i++)
189 cskip_op[ arg[6+i] ] = true;
190 }
191 else
192 { for(addr_t i = 0; i < arg[5]; i++)
193 cskip_op[ arg[6+arg[4]+i] ] = true;
194 }
195 return;
196 }
197 } } // END_CPPAD_LOCAL_NAMESPACE
198 # endif
0 # ifndef CPPAD_LOCAL_OP_CSUM_OP_HPP
1 # define CPPAD_LOCAL_OP_CSUM_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file csum_op.hpp
17 Forward, reverse and sparsity calculations for cummulative summation.
18 */
19
20 /*!
21 Compute forward mode Taylor coefficients for result of op = CsumOp.
22
23 This operation is
24 \verbatim
25 z = s + x(0) + ... + x(n1-1) - y(0) - ... - y(n2-1)
26 + p(0) + ... + p(n3-1) - q(0) - ... - q(n4-1).
27 \endverbatim
28
29 \tparam Base
30 base type for the operator; i.e., this operation was recorded
31 using AD< Base > and computations by this routine are done using type
32 Base.
33
34 \param p
35 lowest order of the Taylor coefficient that we are computing.
36
37 \param q
38 highest order of the Taylor coefficient that we are computing.
39
40 \param i_z
41 variable index corresponding to the result for this operation;
42 i.e. the row index in taylor corresponding to z.
43
44 \param arg
45 -- arg[0]
46 parameter[arg[0]] is the parameter value s in this cummunative summation.
47
48 -- arg[1]
49 end in arg of addition variables in summation.
50 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(n1-1)
51
52 -- arg[2]
53 end in arg of subtraction variables in summation.
54 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n2-1)
55
56 -- arg[3]
57 end in arg of addition dynamic parameters in summation.
58 arg[arg[2]] , ... , arg[arg[3]-1] correspond to p(0), ... , p(n3-1)
59
60 -- arg[4]
61 end in arg of subtraction dynamic parameters in summation.
62 arg[arg[3]] , ... , arg[arg[4]-1] correspond to q(0), ... , q(n4-1)
63
64 \param num_par
65 is the number of parameters in parameter.
66
67 \param parameter
68 is the parameter vector for this operation sequence.
69
70 \param cap_order
71 number of colums in the matrix containing all the Taylor coefficients.
72
73 \param taylor
74 \b Input: taylor [ arg[5+i] * cap_order + k ]
75 for i = 0, ..., n1-1
76 and k = 0 , ... , q
77 is the k-th order Taylor coefficient corresponding to x(i)
78 \n
79 \b Input: taylor [ arg[arg[1]+1] * cap_order + k ]
80 for i = 0, ..., n2-1
81 and k = 0 , ... , q
82 is the k-th order Taylor coefficient corresponding to y(i)
83 \n
84 \b Input: taylor [ i_z * cap_order + k ]
85 for k = 0 , ... , p,
86 is the k-th order Taylor coefficient corresponding to z.
87 \n
88 \b Output: taylor [ i_z * cap_order + k ]
89 for k = p , ... , q,
90 is the k-th order Taylor coefficient corresponding to z.
91 */
92 template <class Base>
93 void forward_csum_op(
94 size_t p ,
95 size_t q ,
96 size_t i_z ,
97 const addr_t* arg ,
98 size_t num_par ,
99 const Base* parameter ,
100 size_t cap_order ,
101 Base* taylor )
102 { Base zero(0);
103
104 // check assumptions
105 CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 );
106 CPPAD_ASSERT_UNKNOWN( q < cap_order );
107 CPPAD_ASSERT_UNKNOWN( p <= q );
108 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par );
109 CPPAD_ASSERT_UNKNOWN(
110 arg[arg[4]] == arg[4]
111 );
112
113 // Taylor coefficients corresponding to result
114 Base* z = taylor + i_z * cap_order;
115 for(size_t k = p; k <= q; k++)
116 z[k] = zero;
117 if( p == 0 )
118 { // normal parameters in the sum
119 z[p] = parameter[ arg[0] ];
120 // addition dynamic parameters
121 for(size_t i = size_t(arg[2]); i < size_t(arg[3]); ++i)
122 z[p] += parameter[ arg[i] ];
123 // subtraction dynamic parameters
124 for(size_t i = size_t(arg[3]); i < size_t(arg[4]); ++i)
125 z[p] -= parameter[ arg[i] ];
126 }
127 Base* x;
128 for(size_t i = 5; i < size_t(arg[1]); ++i)
129 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
130 x = taylor + size_t(arg[i]) * cap_order;
131 for(size_t k = p; k <= q; k++)
132 z[k] += x[k];
133 }
134 for(size_t i = size_t(arg[1]); i < size_t(arg[2]); ++i)
135 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
136 x = taylor + size_t(arg[i]) * cap_order;
137 for(size_t k = p; k <= q; k++)
138 z[k] -= x[k];
139 }
140 }
141
142 /*!
143 Multiple direction forward mode Taylor coefficients for op = CsumOp.
144
145 This operation is
146 \verbatim
147 z = s + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
148 \endverbatim
149
150 \tparam Base
151 base type for the operator; i.e., this operation was recorded
152 using AD<Base> and computations by this routine are done using type
153 Base.
154
155 \param q
156 order ot the Taylor coefficients that we are computing.
157
158 \param r
159 number of directions for Taylor coefficients that we are computing.
160
161 \param i_z
162 variable index corresponding to the result for this operation;
163 i.e. the row index in taylor corresponding to z.
164
165 \param arg
166 -- arg[0]
167 parameter[arg[0]] is the parameter value s in this cummunative summation.
168
169 -- arg[1]
170 end in arg of addition variables in summation.
171 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
172
173 -- arg[2]
174 end in arg of subtraction variables in summation.
175 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
176
177 -- arg[3]
178 end in arg of addition dynamic parameters in summation.
179
180 -- arg[4]
181 end in arg of subtraction dynamic parameters in summation.
182
183 \param num_par
184 is the number of parameters in parameter.
185
186 \param parameter
187 is the parameter vector for this operation sequence.
188
189 \param cap_order
190 number of colums in the matrix containing all the Taylor coefficients.
191
192 \param taylor
193 \b Input: taylor [ arg[5+i]*((cap_order-1)*r + 1) + 0 ]
194 for i = 0, ..., m-1
195 is the 0-th order Taylor coefficient corresponding to x(i) and
196 taylor [ arg[5+i]*((cap_order-1)*r + 1) + (q-1)*r + ell + 1 ]
197 for i = 0, ..., m-1,
198 ell = 0 , ... , r-1
199 is the q-th order Taylor coefficient corresponding to x(i)
200 and direction ell.
201 \n
202 \b Input: taylor [ arg[arg[1]+1]*((cap_order-1)*r + 1) + 0 ]
203 for i = 0, ..., n-1
204 is the 0-th order Taylor coefficient corresponding to y(i) and
205 taylor [ arg[arg[1]+1]*((cap_order-1)*r + 1) + (q-1)*r + ell + 1 ]
206 for i = 0, ..., n-1,
207 ell = 0 , ... , r-1
208 is the q-th order Taylor coefficient corresponding to y(i)
209 and direction ell.
210 \n
211 \b Output: taylor [ i_z*((cap_order-1)*r+1) + (q-1)*r + ell + 1 ]
212 is the q-th order Taylor coefficient corresponding to z
213 for direction ell = 0 , ... , r-1.
214 */
215 template <class Base>
216 void forward_csum_op_dir(
217 size_t q ,
218 size_t r ,
219 size_t i_z ,
220 const addr_t* arg ,
221 size_t num_par ,
222 const Base* parameter ,
223 size_t cap_order ,
224 Base* taylor )
225 { Base zero(0);
226
227 // check assumptions
228 CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 );
229 CPPAD_ASSERT_UNKNOWN( q < cap_order );
230 CPPAD_ASSERT_UNKNOWN( 0 < q );
231 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par );
232 CPPAD_ASSERT_UNKNOWN(
233 arg[arg[4]] == arg[4]
234 );
235
236 // Taylor coefficients corresponding to result
237 size_t num_taylor_per_var = (cap_order-1) * r + 1;
238 size_t m = (q-1)*r + 1;
239 Base* z = taylor + i_z * num_taylor_per_var + m;
240 for(size_t ell = 0; ell < r; ell++)
241 z[ell] = zero;
242 Base* x;
243 for(size_t i = 5; i < size_t(arg[1]); ++i)
244 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
245 x = taylor + size_t(arg[i]) * num_taylor_per_var + m;
246 for(size_t ell = 0; ell < r; ell++)
247 z[ell] += x[ell];
248 }
249 for(size_t i = size_t(arg[1]); i < size_t(arg[2]); ++i)
250 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
251 x = taylor + size_t(arg[i]) * num_taylor_per_var + m;
252 for(size_t ell = 0; ell < r; ell++)
253 z[ell] -= x[ell];
254 }
255 }
256
257 /*!
258 Compute reverse mode Taylor coefficients for result of op = CsumOp.
259
260 This operation is
261 \verbatim
262 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
263 H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ]
264 \endverbatim
265
266 \tparam Base
267 base type for the operator; i.e., this operation was recorded
268 using AD< Base > and computations by this routine are done using type
269 Base.
270
271 \param d
272 order the highest order Taylor coefficient that we are computing
273 the partial derivatives with respect to.
274
275 \param i_z
276 variable index corresponding to the result for this operation;
277 i.e. the row index in taylor corresponding to z.
278
279 \param arg
280 -- arg[0]
281 parameter[arg[0]] is the parameter value s in this cummunative summation.
282
283 -- arg[1]
284 end in arg of addition variables in summation.
285 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
286
287 -- arg[2]
288 end in arg of subtraction variables in summation.
289 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
290
291 -- arg[3]
292 end in arg of addition dynamic parameters in summation.
293
294 -- arg[4]
295 end in arg of subtraction dynamic parameters in summation.
296
297 \param nc_partial
298 number of colums in the matrix containing all the partial derivatives.
299
300 \param partial
301 \b Input: partial [ arg[5+i] * nc_partial + k ]
302 for i = 0, ..., m-1
303 and k = 0 , ... , d
304 is the partial derivative of G(z, y, x, w, ...) with respect to the
305 k-th order Taylor coefficient corresponding to x(i)
306 \n
307 \b Input: partial [ arg[arg[1]+1] * nc_partial + k ]
308 for i = 0, ..., n-1
309 and k = 0 , ... , d
310 is the partial derivative of G(z, y, x, w, ...) with respect to the
311 k-th order Taylor coefficient corresponding to y(i)
312 \n
313 \b Input: partial [ i_z * nc_partial + k ]
314 for i = 0, ..., n-1
315 and k = 0 , ... , d
316 is the partial derivative of G(z, y, x, w, ...) with respect to the
317 k-th order Taylor coefficient corresponding to z.
318 \n
319 \b Output: partial [ arg[5+i] * nc_partial + k ]
320 for i = 0, ..., m-1
321 and k = 0 , ... , d
322 is the partial derivative of H(y, x, w, ...) with respect to the
323 k-th order Taylor coefficient corresponding to x(i)
324 \n
325 \b Output: partial [ arg[arg[1]+1] * nc_partial + k ]
326 for i = 0, ..., n-1
327 and k = 0 , ... , d
328 is the partial derivative of H(y, x, w, ...) with respect to the
329 k-th order Taylor coefficient corresponding to y(i)
330 */
331
332 template <class Base>
333 void reverse_csum_op(
334 size_t d ,
335 size_t i_z ,
336 const addr_t* arg ,
337 size_t nc_partial ,
338 Base* partial )
339 {
340 // check assumptions
341 CPPAD_ASSERT_UNKNOWN( NumRes(CSumOp) == 1 );
342 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
343
344 // Taylor coefficients and partial derivative corresponding to result
345 Base* pz = partial + i_z * nc_partial;
346 Base* px;
347 size_t d1 = d + 1;
348 for(size_t i = 5; i < size_t(arg[1]); ++i)
349 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
350 px = partial + size_t(arg[i]) * nc_partial;
351 size_t k = d1;
352 while(k--)
353 px[k] += pz[k];
354 }
355 for(size_t i = size_t(arg[1]); i < size_t(arg[2]); ++i)
356 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
357 px = partial + size_t(arg[i]) * nc_partial;
358 size_t k = d1;
359 while(k--)
360 px[k] -= pz[k];
361 }
362 }
363
364
365 /*!
366 Forward mode Jacobian sparsity pattern for CSumOp operator.
367
368 This operation is
369 \verbatim
370 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
371 \endverbatim
372
373 \tparam Vector_set
374 is the type used for vectors of sets. It can be either
375 sparse::pack_setvec or sparse::list_setvec.
376
377 \param i_z
378 variable index corresponding to the result for this operation;
379 i.e. the index in sparsity corresponding to z.
380
381 \param arg
382 -- arg[0]
383 parameter[arg[0]] is the parameter value s in this cummunative summation.
384
385 -- arg[1]
386 end in arg of addition variables in summation.
387 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
388
389 -- arg[2]
390 end in arg of subtraction variables in summation.
391 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
392
393 -- arg[3]
394 end in arg of addition dynamic parameters in summation.
395
396 -- arg[4]
397 end in arg of subtraction dynamic parameters in summation.
398
399 \param sparsity
400 \b Input:
401 For i = 0, ..., m-1,
402 the set with index arg[5+i] in sparsity
403 is the sparsity bit pattern for x(i).
404 This identifies which of the independent variables the variable
405 x(i) depends on.
406 \n
407 \b Input:
408 For i = 0, ..., n-1,
409 the set with index arg[2+arg[0]+i] in sparsity
410 is the sparsity bit pattern for x(i).
411 This identifies which of the independent variables the variable
412 y(i) depends on.
413 \n
414 \b Output:
415 The set with index i_z in sparsity
416 is the sparsity bit pattern for z.
417 This identifies which of the independent variables the variable z
418 depends on.
419 */
420
421 template <class Vector_set>
422 void forward_sparse_jacobian_csum_op(
423 size_t i_z ,
424 const addr_t* arg ,
425 Vector_set& sparsity )
426 { sparsity.clear(i_z);
427
428 for(size_t i = 5; i < size_t(arg[2]); ++i)
429 { CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
430 sparsity.binary_union(
431 i_z , // index in sparsity for result
432 i_z , // index in sparsity for left operand
433 size_t(arg[i]), // index for right operand
434 sparsity // sparsity vector for right operand
435 );
436 }
437 }
438
439 /*!
440 Reverse mode Jacobian sparsity pattern for CSumOp operator.
441
442 This operation is
443 \verbatim
444 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
445 H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ]
446 \endverbatim
447
448 \tparam Vector_set
449 is the type used for vectors of sets. It can be either
450 sparse::pack_setvec or sparse::list_setvec.
451
452 \param i_z
453 variable index corresponding to the result for this operation;
454 i.e. the index in sparsity corresponding to z.
455
456 \param arg
457 -- arg[0]
458 parameter[arg[0]] is the parameter value s in this cummunative summation.
459
460 -- arg[1]
461 end in arg of addition variables in summation.
462 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
463
464 -- arg[2]
465 end in arg of subtraction variables in summation.
466 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
467
468 -- arg[3]
469 end in arg of addition dynamic parameters in summation.
470
471 -- arg[4]
472 end in arg of subtraction dynamic parameters in summation.
473
474 \param sparsity
475 For i = 0, ..., m-1,
476 the set with index arg[5+i] in sparsity
477 is the sparsity bit pattern for x(i).
478 This identifies which of the dependent variables depend on x(i).
479 On input, the sparsity patter corresponds to G,
480 and on ouput it corresponds to H.
481 \n
482 For i = 0, ..., m-1,
483 the set with index arg[2+arg[0]+i] in sparsity
484 is the sparsity bit pattern for y(i).
485 This identifies which of the dependent variables depend on y(i).
486 On input, the sparsity patter corresponds to G,
487 and on ouput it corresponds to H.
488 \n
489 \b Input:
490 The set with index i_z in sparsity
491 is the sparsity bit pattern for z.
492 On input it corresponds to G and on output it is undefined.
493 */
494
495 template <class Vector_set>
496 void reverse_sparse_jacobian_csum_op(
497 size_t i_z ,
498 const addr_t* arg ,
499 Vector_set& sparsity )
500 {
501 for(size_t i = 5; i < size_t(arg[2]); ++i)
502 {
503 CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
504 sparsity.binary_union(
505 size_t(arg[i]), // index in sparsity for result
506 size_t(arg[i]), // index in sparsity for left operand
507 i_z , // index for right operand
508 sparsity // sparsity vector for right operand
509 );
510 }
511 }
512 /*!
513 Reverse mode Hessian sparsity pattern for CSumOp operator.
514
515 This operation is
516 \verbatim
517 z = q + x(0) + ... + x(m-1) - y(0) - ... - y(n-1).
518 H(y, x, w, ...) = G[ z(x, y), y, x, w, ... ]
519 \endverbatim
520
521 \tparam Vector_set
522 is the type used for vectors of sets. It can be either
523 sparse::pack_setvec or sparse::list_setvec.
524
525 \param i_z
526 variable index corresponding to the result for this operation;
527 i.e. the index in sparsity corresponding to z.
528
529 \param arg
530 -- arg[0]
531 parameter[arg[0]] is the parameter value s in this cummunative summation.
532
533 -- arg[1]
534 end in arg of addition variables in summation.
535 arg[5] , ... , arg[arg[1]-1] correspond to x(0), ... , x(m-1)
536
537 -- arg[2]
538 end in arg of subtraction variables in summation.
539 arg[arg[1]] , ... , arg[arg[2]-1] correspond to y(0), ... , y(n-1)
540
541 -- arg[3]
542 end in arg of addition dynamic parameters in summation.
543
544 -- arg[4]
545 end in arg of subtraction dynamic parameters in summation.
546
547 \param rev_jacobian
548 rev_jacobian[i_z]
549 is all false (true) if the Jabobian of G with respect to z must be zero
550 (may be non-zero).
551 \n
552 \n
553 For i = 0, ..., m-1
554 rev_jacobian[ arg[5+i] ]
555 is all false (true) if the Jacobian with respect to x(i)
556 is zero (may be non-zero).
557 On input, it corresponds to the function G,
558 and on output it corresponds to the function H.
559 \n
560 \n
561 For i = 0, ..., n-1
562 rev_jacobian[ arg[2+arg[0]+i] ]
563 is all false (true) if the Jacobian with respect to y(i)
564 is zero (may be non-zero).
565 On input, it corresponds to the function G,
566 and on output it corresponds to the function H.
567
568 \param rev_hes_sparsity
569 The set with index i_z in in rev_hes_sparsity
570 is the Hessian sparsity pattern for the fucntion G
571 where one of the partials derivative is with respect to z.
572 \n
573 \n
574 For i = 0, ..., m-1
575 The set with index arg[5+i] in rev_hes_sparsity
576 is the Hessian sparsity pattern
577 where one of the partials derivative is with respect to x(i).
578 On input, it corresponds to the function G,
579 and on output it corresponds to the function H.
580 \n
581 \n
582 For i = 0, ..., n-1
583 The set with index arg[2+arg[0]+i] in rev_hes_sparsity
584 is the Hessian sparsity pattern
585 where one of the partials derivative is with respect to y(i).
586 On input, it corresponds to the function G,
587 and on output it corresponds to the function H.
588 */
589
590 template <class Vector_set>
591 void reverse_sparse_hessian_csum_op(
592 size_t i_z ,
593 const addr_t* arg ,
594 bool* rev_jacobian ,
595 Vector_set& rev_hes_sparsity )
596 {
597 for(size_t i = 5; i < size_t(arg[2]); ++i)
598 {
599 CPPAD_ASSERT_UNKNOWN( size_t(arg[i]) < i_z );
600 rev_hes_sparsity.binary_union(
601 size_t(arg[i]), // index in sparsity for result
602 size_t(arg[i]), // index in sparsity for left operand
603 i_z , // index for right operand
604 rev_hes_sparsity // sparsity vector for right operand
605 );
606 rev_jacobian[arg[i]] |= rev_jacobian[i_z];
607 }
608 }
609
610 } } // END_CPPAD_LOCAL_NAMESPACE
611 # endif
0 # ifndef CPPAD_LOCAL_OP_DISCRETE_OP_HPP
1 # define CPPAD_LOCAL_OP_DISCRETE_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file discrete_op.hpp
18 Forward mode for z = f(x) where f is piecewise constant.
19 */
20
21
22 /*!
23 forward mode Taylor coefficient for result of op = DisOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = f(x)
28 \endverbatim
29 where f is a piecewise constant function (and it's derivative is always
30 calculated as zero).
31
32 \tparam Base
33 base type for the operator; i.e., this operation was recorded
34 using AD< Base > and computations by this routine are done using type
35 Base .
36
37 \param p
38 is the lowest order Taylor coefficient that will be calculated.
39
40 \param q
41 is the highest order Taylor coefficient that will be calculated.
42
43 \param r
44 is the number of directions, for each order,
45 that will be calculated (except for order zero wich only has one direction).
46
47 \param i_z
48 variable index corresponding to the result for this operation;
49 i.e. the row index in taylor corresponding to z.
50
51 \param arg
52 arg[0]
53 \n
54 is the index, in the order of the discrete functions defined by the user,
55 for this discrete function.
56 \n
57 \n
58 arg[1]
59 variable index corresponding to the argument for this operator;
60 i.e. the row index in taylor corresponding to x.
61
62 \param cap_order
63 maximum number of orders that will fit in the taylor array.
64
65 \par tpv
66 We use the notation
67 <code>tpv = (cap_order-1) * r + 1</code>
68 which is the number of Taylor coefficients per variable
69
70 \param taylor
71 \b Input: <code>taylor [ arg[1] * tpv + 0 ]</code>
72 is the zero order Taylor coefficient corresponding to x.
73 \n
74 \b Output: if <code>p == 0</code>
75 <code>taylor [ i_z * tpv + 0 ]</code>
76 is the zero order Taylor coefficient corresponding to z.
77 For k = max(p, 1), ... , q,
78 <code>taylor [ i_z * tpv + (k-1)*r + 1 + ell ]</code>
79 is the k-th order Taylor coefficient corresponding to z
80 (which is zero).
81
82 \par Checked Assertions where op is the unary operator with one result:
83 \li NumArg(op) == 2
84 \li NumRes(op) == 1
85 \li q < cap_order
86 \li 0 < r
87 */
88 template <class Base>
89 void forward_dis_op(
90 size_t p ,
91 size_t q ,
92 size_t r ,
93 size_t i_z ,
94 const addr_t* arg ,
95 size_t cap_order ,
96 Base* taylor )
97 {
98 // check assumptions
99 CPPAD_ASSERT_UNKNOWN( NumArg(DisOp) == 2 );
100 CPPAD_ASSERT_UNKNOWN( NumRes(DisOp) == 1 );
101 CPPAD_ASSERT_UNKNOWN( q < cap_order );
102 CPPAD_ASSERT_UNKNOWN( 0 < r );
103
104 // Taylor coefficients corresponding to argument and result
105 size_t num_taylor_per_var = (cap_order-1) * r + 1;
106 Base* x = taylor + size_t(arg[1]) * num_taylor_per_var;
107 Base* z = taylor + i_z * num_taylor_per_var;
108
109 if( p == 0 )
110 { z[0] = discrete<Base>::eval(size_t(arg[0]), x[0]);
111 p++;
112 }
113 for(size_t ell = 0; ell < r; ell++)
114 for(size_t k = p; k <= q; k++)
115 z[ (k-1) * r + 1 + ell ] = Base(0.0);
116 }
117
118
119 } } // END_CPPAD_LOCAL_NAMESPACE
120 # endif
0 # ifndef CPPAD_LOCAL_OP_DIV_OP_HPP
1 # define CPPAD_LOCAL_OP_DIV_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15
16 // --------------------------- Divvv -----------------------------------------
17
18 // See dev documentation: forward_binary_op
19 template <class Base>
20 void forward_divvv_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 const addr_t* arg ,
25 const Base* parameter ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to arguments and result
36 Base* x = taylor + size_t(arg[0]) * cap_order;
37 Base* y = taylor + size_t(arg[1]) * cap_order;
38 Base* z = taylor + i_z * cap_order;
39
40
41 // Using CondExp, it can make sense to divide by zero,
42 // so do not make it an error.
43 size_t k;
44 for(size_t d = p; d <= q; d++)
45 { z[d] = x[d];
46 for(k = 1; k <= d; k++)
47 z[d] -= z[d-k] * y[k];
48 z[d] /= y[0];
49 }
50 }
51
52 // See dev documentation: forward_binary_op
53 template <class Base>
54 void forward_divvv_op_dir(
55 size_t q ,
56 size_t r ,
57 size_t i_z ,
58 const addr_t* arg ,
59 const Base* parameter ,
60 size_t cap_order ,
61 Base* taylor )
62 {
63 // check assumptions
64 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
65 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
66 CPPAD_ASSERT_UNKNOWN( 0 < q );
67 CPPAD_ASSERT_UNKNOWN( q < cap_order );
68
69 // Taylor coefficients corresponding to arguments and result
70 size_t num_taylor_per_var = (cap_order-1) * r + 1;
71 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
72 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
73 Base* z = taylor + i_z * num_taylor_per_var;
74
75
76 // Using CondExp, it can make sense to divide by zero,
77 // so do not make it an error.
78 size_t m = (q-1) * r + 1;
79 for(size_t ell = 0; ell < r; ell++)
80 { z[m+ell] = x[m+ell] - z[0] * y[m+ell];
81 for(size_t k = 1; k < q; k++)
82 z[m+ell] -= z[(q-k-1)*r+1+ell] * y[(k-1)*r+1+ell];
83 z[m+ell] /= y[0];
84 }
85 }
86
87
88
89 // See dev documentation: forward_binary_op
90 template <class Base>
91 void forward_divvv_op_0(
92 size_t i_z ,
93 const addr_t* arg ,
94 const Base* parameter ,
95 size_t cap_order ,
96 Base* taylor )
97 {
98 // check assumptions
99 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
100 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
101
102 // Taylor coefficients corresponding to arguments and result
103 Base* x = taylor + size_t(arg[0]) * cap_order;
104 Base* y = taylor + size_t(arg[1]) * cap_order;
105 Base* z = taylor + i_z * cap_order;
106
107 z[0] = x[0] / y[0];
108 }
109
110
111 // See dev documentation: reverse_binary_op
112 template <class Base>
113 void reverse_divvv_op(
114 size_t d ,
115 size_t i_z ,
116 const addr_t* arg ,
117 const Base* parameter ,
118 size_t cap_order ,
119 const Base* taylor ,
120 size_t nc_partial ,
121 Base* partial )
122 {
123 // check assumptions
124 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
125 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
126 CPPAD_ASSERT_UNKNOWN( d < cap_order );
127 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
128
129 // Arguments
130 const Base* y = taylor + size_t(arg[1]) * cap_order;
131 const Base* z = taylor + i_z * cap_order;
132
133 // Partial derivatives corresponding to arguments and result
134 Base* px = partial + size_t(arg[0]) * nc_partial;
135 Base* py = partial + size_t(arg[1]) * nc_partial;
136 Base* pz = partial + i_z * nc_partial;
137
138 // Using CondExp, it can make sense to divide by zero
139 // so do not make it an error.
140 Base inv_y0 = Base(1.0) / y[0];
141
142 size_t k;
143 // number of indices to access
144 size_t j = d + 1;
145 while(j)
146 { --j;
147 // scale partial w.r.t. z[j]
148 pz[j] = azmul(pz[j], inv_y0);
149
150 px[j] += pz[j];
151 for(k = 1; k <= j; k++)
152 { pz[j-k] -= azmul(pz[j], y[k] );
153 py[k] -= azmul(pz[j], z[j-k]);
154 }
155 py[0] -= azmul(pz[j], z[j]);
156 }
157 }
158
159 // --------------------------- Divpv -----------------------------------------
160
161 // See dev documentation: forward_binary_op
162 template <class Base>
163 void forward_divpv_op(
164 size_t p ,
165 size_t q ,
166 size_t i_z ,
167 const addr_t* arg ,
168 const Base* parameter ,
169 size_t cap_order ,
170 Base* taylor )
171 {
172 // check assumptions
173 CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
174 CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
175 CPPAD_ASSERT_UNKNOWN( q < cap_order );
176 CPPAD_ASSERT_UNKNOWN( p <= q );
177
178 // Taylor coefficients corresponding to arguments and result
179 Base* y = taylor + size_t(arg[1]) * cap_order;
180 Base* z = taylor + i_z * cap_order;
181
182 // Paraemter value
183 Base x = parameter[ arg[0] ];
184
185 // Using CondExp, it can make sense to divide by zero,
186 // so do not make it an error.
187 size_t k;
188 if( p == 0 )
189 { z[0] = x / y[0];
190 p++;
191 }
192 for(size_t d = p; d <= q; d++)
193 { z[d] = Base(0.0);
194 for(k = 1; k <= d; k++)
195 z[d] -= z[d-k] * y[k];
196 z[d] /= y[0];
197 }
198 }
199
200 // See dev documentation: forward_binary_op
201 template <class Base>
202 void forward_divpv_op_dir(
203 size_t q ,
204 size_t r ,
205 size_t i_z ,
206 const addr_t* arg ,
207 const Base* parameter ,
208 size_t cap_order ,
209 Base* taylor )
210 {
211 // check assumptions
212 CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
213 CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
214 CPPAD_ASSERT_UNKNOWN( 0 < q );
215 CPPAD_ASSERT_UNKNOWN( q < cap_order );
216
217 // Taylor coefficients corresponding to arguments and result
218 size_t num_taylor_per_var = (cap_order-1) * r + 1;
219 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
220 Base* z = taylor + i_z * num_taylor_per_var;
221
222 // Using CondExp, it can make sense to divide by zero,
223 // so do not make it an error.
224 size_t m = (q-1) * r + 1;
225 for(size_t ell = 0; ell < r; ell++)
226 { z[m+ell] = - z[0] * y[m+ell];
227 for(size_t k = 1; k < q; k++)
228 z[m+ell] -= z[(q-k-1)*r+1+ell] * y[(k-1)*r+1+ell];
229 z[m+ell] /= y[0];
230 }
231 }
232
233
234 // See dev documentation: forward_binary_op
235 template <class Base>
236 void forward_divpv_op_0(
237 size_t i_z ,
238 const addr_t* arg ,
239 const Base* parameter ,
240 size_t cap_order ,
241 Base* taylor )
242 {
243 // check assumptions
244 CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
245 CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
246
247 // Paraemter value
248 Base x = parameter[ arg[0] ];
249
250 // Taylor coefficients corresponding to arguments and result
251 Base* y = taylor + size_t(arg[1]) * cap_order;
252 Base* z = taylor + i_z * cap_order;
253
254 z[0] = x / y[0];
255 }
256
257
258 // See dev documentation: reverse_binary_op
259 template <class Base>
260 void reverse_divpv_op(
261 size_t d ,
262 size_t i_z ,
263 const addr_t* arg ,
264 const Base* parameter ,
265 size_t cap_order ,
266 const Base* taylor ,
267 size_t nc_partial ,
268 Base* partial )
269 {
270 // check assumptions
271 CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
272 CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
273 CPPAD_ASSERT_UNKNOWN( d < cap_order );
274 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
275
276 // Arguments
277 const Base* y = taylor + size_t(arg[1]) * cap_order;
278 const Base* z = taylor + i_z * cap_order;
279
280 // Partial derivatives corresponding to arguments and result
281 Base* py = partial + size_t(arg[1]) * nc_partial;
282 Base* pz = partial + i_z * nc_partial;
283
284 // Using CondExp, it can make sense to divide by zero so do not
285 // make it an error.
286 Base inv_y0 = Base(1.0) / y[0];
287
288 size_t k;
289 // number of indices to access
290 size_t j = d + 1;
291 while(j)
292 { --j;
293 // scale partial w.r.t z[j]
294 pz[j] = azmul(pz[j], inv_y0);
295
296 for(k = 1; k <= j; k++)
297 { pz[j-k] -= azmul(pz[j], y[k] );
298 py[k] -= azmul(pz[j], z[j-k] );
299 }
300 py[0] -= azmul(pz[j], z[j]);
301 }
302 }
303
304
305 // --------------------------- Divvp -----------------------------------------
306
307 // See dev documentation: forward_binary_op
308 template <class Base>
309 void forward_divvp_op(
310 size_t p ,
311 size_t q ,
312 size_t i_z ,
313 const addr_t* arg ,
314 const Base* parameter ,
315 size_t cap_order ,
316 Base* taylor )
317 {
318 // check assumptions
319 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
320 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
321 CPPAD_ASSERT_UNKNOWN( q < cap_order );
322 CPPAD_ASSERT_UNKNOWN( p <= q );
323
324 // Taylor coefficients corresponding to arguments and result
325 Base* x = taylor + size_t(arg[0]) * cap_order;
326 Base* z = taylor + i_z * cap_order;
327
328 // Parameter value
329 Base y = parameter[ arg[1] ];
330
331 // Using CondExp and multiple levels of AD, it can make sense
332 // to divide by zero so do not make it an error.
333 for(size_t d = p; d <= q; d++)
334 z[d] = x[d] / y;
335 }
336
337 // See dev documentation: forward_binary_op
338 template <class Base>
339 void forward_divvp_op_dir(
340 size_t q ,
341 size_t r ,
342 size_t i_z ,
343 const addr_t* arg ,
344 const Base* parameter ,
345 size_t cap_order ,
346 Base* taylor )
347 {
348 // check assumptions
349 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
350 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
351 CPPAD_ASSERT_UNKNOWN( q < cap_order );
352 CPPAD_ASSERT_UNKNOWN( 0 < q );
353
354 // Taylor coefficients corresponding to arguments and result
355 size_t num_taylor_per_var = (cap_order-1) * r + 1;
356 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
357 Base* z = taylor + i_z * num_taylor_per_var;
358
359 // Parameter value
360 Base y = parameter[ arg[1] ];
361
362 // Using CondExp and multiple levels of AD, it can make sense
363 // to divide by zero so do not make it an error.
364 size_t m = (q-1)*r + 1;
365 for(size_t ell = 0; ell < r; ell++)
366 z[m + ell] = x[m + ell] / y;
367 }
368
369
370
371 // See dev documentation: forward_binary_op
372 template <class Base>
373 void forward_divvp_op_0(
374 size_t i_z ,
375 const addr_t* arg ,
376 const Base* parameter ,
377 size_t cap_order ,
378 Base* taylor )
379 {
380 // check assumptions
381 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
382 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
383
384 // Parameter value
385 Base y = parameter[ arg[1] ];
386
387 // Taylor coefficients corresponding to arguments and result
388 Base* x = taylor + size_t(arg[0]) * cap_order;
389 Base* z = taylor + i_z * cap_order;
390
391 z[0] = x[0] / y;
392 }
393
394
395 // See dev documentation: reverse_binary_op
396 template <class Base>
397 void reverse_divvp_op(
398 size_t d ,
399 size_t i_z ,
400 const addr_t* arg ,
401 const Base* parameter ,
402 size_t cap_order ,
403 const Base* taylor ,
404 size_t nc_partial ,
405 Base* partial )
406 {
407 // check assumptions
408 CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
409 CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
410 CPPAD_ASSERT_UNKNOWN( d < cap_order );
411 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
412
413 // Argument values
414 Base y = parameter[ arg[1] ];
415
416 // Partial derivatives corresponding to arguments and result
417 Base* px = partial + size_t(arg[0]) * nc_partial;
418 Base* pz = partial + i_z * nc_partial;
419
420 // Using CondExp, it can make sense to divide by zero
421 // so do not make it an error.
422 Base inv_y = Base(1.0) / y;
423
424 // number of indices to access
425 size_t j = d + 1;
426 while(j)
427 { --j;
428 px[j] += azmul(pz[j], inv_y);
429 }
430 }
431
432 } } // END_CPPAD_LOCAL_NAMESPACE
433 # endif
0 # ifndef CPPAD_LOCAL_OP_ERF_OP_HPP
1 # define CPPAD_LOCAL_OP_ERF_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15 # include <cppad/local/op/mul_op.hpp>
16 # include <cppad/local/op/sub_op.hpp>
17 # include <cppad/local/op/exp_op.hpp>
18
19
20 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
21 /*!
22 \file erf_op.hpp
23 Forward and reverse mode calculations for z = erf(x) or erfc(x).
24 */
25
26 /*!
27 Forward mode Taylor coefficient for result of op = ErfOp or ErfcOp.
28
29 The C++ source code corresponding to this operation is one of
30 \verbatim
31 z = erf(x)
32 z = erfc(x)
33 \endverbatim
34
35 \tparam Base
36 base type for the operator; i.e., this operation was recorded
37 using AD< Base > and computations by this routine are done using type Base.
38
39 \param op
40 must be either ErfOp or ErfcOp and indicates if this is
41 z = erf(x) or z = erfc(x).
42
43 \param p
44 lowest order of the Taylor coefficients that we are computing.
45
46 \param q
47 highest order of the Taylor coefficients that we are computing.
48
49 \param i_z
50 variable index corresponding to the last (primary) result for this operation;
51 i.e. the row index in taylor corresponding to z.
52 The auxillary results are called y_j have index i_z - j.
53
54 \param arg
55 arg[0]: is the variable index corresponding to x.
56 \n
57 arg[1]: is the parameter index corresponding to the value zero.
58 \n
59 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
60
61 \param parameter
62 parameter[ arg[1] ] is the value zero,
63 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
64
65 \param cap_order
66 maximum number of orders that will fit in the taylor array.
67
68 \param taylor
69 \b Input:
70 taylor [ size_t(arg[0]) * cap_order + k ]
71 for k = 0 , ... , q,
72 is the k-th order Taylor coefficient corresponding to x.
73 \n
74 \b Input:
75 taylor [ i_z * cap_order + k ]
76 for k = 0 , ... , p - 1,
77 is the k-th order Taylor coefficient corresponding to z.
78 \n
79 \b Input:
80 taylor [ ( i_z - j) * cap_order + k ]
81 for k = 0 , ... , p-1,
82 and j = 0 , ... , 4,
83 is the k-th order Taylor coefficient corresponding to the j-th result for z.
84 \n
85 \b Output:
86 taylor [ (i_z-j) * cap_order + k ],
87 for k = p , ... , q,
88 and j = 0 , ... , 4,
89 is the k-th order Taylor coefficient corresponding to the j-th result for z.
90
91 */
92 template <class Base>
93 void forward_erf_op(
94 OpCode op ,
95 size_t p ,
96 size_t q ,
97 size_t i_z ,
98 const addr_t* arg ,
99 const Base* parameter ,
100 size_t cap_order ,
101 Base* taylor )
102 {
103 // check assumptions
104 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
105 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
106 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
107 CPPAD_ASSERT_UNKNOWN( q < cap_order );
108 CPPAD_ASSERT_UNKNOWN( p <= q );
109 CPPAD_ASSERT_UNKNOWN(
110 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
111 );
112
113 // array used to pass parameter values for sub-operations
114 addr_t addr[2];
115
116 // convert from final result to first result
117 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
118
119 // z_0 = x * x
120 addr[0] = arg[0]; // x
121 addr[1] = arg[0]; // x
122 forward_mulvv_op(p, q, i_z+0, addr, parameter, cap_order, taylor);
123
124 // z_1 = - x * x
125 addr[0] = arg[1]; // zero
126 addr[1] = addr_t( i_z ); // z_0
127 forward_subpv_op(p, q, i_z+1, addr, parameter, cap_order, taylor);
128
129 // z_2 = exp( - x * x )
130 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
131
132 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
133 addr[0] = arg[2]; // 2 / sqrt(pi)
134 addr[1] = addr_t( i_z + 2 ); // z_2
135 forward_mulpv_op(p, q, i_z+3, addr, parameter, cap_order, taylor);
136
137 // pointers to taylor coefficients for x , z_3, and z_4
138 Base* x = taylor + size_t(arg[0]) * cap_order;
139 Base* z_3 = taylor + (i_z+3) * cap_order;
140 Base* z_4 = taylor + (i_z+4) * cap_order;
141
142 // calculte z_4 coefficients
143 if( p == 0 )
144 { // z4 (t) = erf[x(t)]
145 if( op == ErfOp )
146 z_4[0] = erf(x[0]);
147 else
148 z_4[0] = erfc(x[0]);
149 p++;
150 }
151 // sign
152 Base sign(1.0);
153 if( op == ErfcOp )
154 sign = Base(-1.0);
155 //
156 for(size_t j = p; j <= q; j++)
157 { // erf: z_4' (t) = erf'[x(t)] * x'(t) = z3(t) * x'(t)
158 // erfc: z_4' (t) = - erf'[x(t)] * x'(t) = - z3(t) * x'(t)
159 // z_4[1] + 2 * z_4[2] * t + ... =
160 // sign * (z_3[0] + z_3[1] * t + ...) * (x[1] + 2 * x[2] * t + ...)
161 Base base_j = static_cast<Base>(double(j));
162 z_4[j] = static_cast<Base>(0);
163 for(size_t k = 1; k <= j; k++)
164 z_4[j] += sign * (Base(double(k)) / base_j) * x[k] * z_3[j-k];
165 }
166 }
167
168 /*!
169 Zero order Forward mode Taylor coefficient for result of op = ErfOp or ErfcOp.
170
171 The C++ source code corresponding to this operation one of
172 \verbatim
173 z = erf(x)
174 z = erfc(x)
175 \endverbatim
176
177 \tparam Base
178 base type for the operator; i.e., this operation was recorded
179 using AD< Base > and computations by this routine are done using type Base.
180
181 \param op
182 must be either ErfOp or ErfcOp and indicates if this is
183 z = erf(x) or z = erfc(x).
184
185 \param i_z
186 variable index corresponding to the last (primary) result for this operation;
187 i.e. the row index in taylor corresponding to z.
188 The auxillary results are called y_j have index i_z - j.
189
190 \param arg
191 arg[0]: is the variable index corresponding to x.
192 \n
193 arg[1]: is the parameter index corresponding to the value zero.
194 \n
195 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
196
197 \param parameter
198 parameter[ arg[1] ] is the value zero,
199 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
200
201 \param cap_order
202 maximum number of orders that will fit in the taylor array.
203
204 \param taylor
205 \b Input:
206 taylor [ size_t(arg[0]) * cap_order + 0 ]
207 is the zero order Taylor coefficient corresponding to x.
208 \n
209 \b Input:
210 taylor [ i_z * cap_order + 0 ]
211 is the zero order Taylor coefficient corresponding to z.
212 \n
213 \b Output:
214 taylor [ (i_z-j) * cap_order + 0 ],
215 for j = 0 , ... , 4,
216 is the zero order Taylor coefficient for j-th result corresponding to z.
217
218 */
219 template <class Base>
220 void forward_erf_op_0(
221 OpCode op ,
222 size_t i_z ,
223 const addr_t* arg ,
224 const Base* parameter ,
225 size_t cap_order ,
226 Base* taylor )
227 {
228 // check assumptions
229 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
230 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
231 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
232 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
233 CPPAD_ASSERT_UNKNOWN(
234 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
235 );
236
237 // array used to pass parameter values for sub-operations
238 addr_t addr[2];
239
240 // convert from final result to first result
241 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
242
243 // z_0 = x * x
244 addr[0] = arg[0]; // x
245 addr[1] = arg[0]; // x
246 forward_mulvv_op_0(i_z+0, addr, parameter, cap_order, taylor);
247
248 // z_1 = - x * x
249 addr[0] = arg[1]; // zero
250 addr[1] = addr_t(i_z); // z_0
251 forward_subpv_op_0(i_z+1, addr, parameter, cap_order, taylor);
252
253 // z_2 = exp( - x * x )
254 forward_exp_op_0(i_z+2, i_z+1, cap_order, taylor);
255
256 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
257 addr[0] = arg[2]; // 2 / sqrt(pi)
258 addr[1] = addr_t(i_z + 2); // z_2
259 forward_mulpv_op_0(i_z+3, addr, parameter, cap_order, taylor);
260
261 // zero order Taylor coefficient for z_4
262 Base* x = taylor + size_t(arg[0]) * cap_order;
263 Base* z_4 = taylor + (i_z + 4) * cap_order;
264 if( op == ErfOp )
265 z_4[0] = erf(x[0]);
266 else
267 z_4[0] = erfc(x[0]);
268 }
269 /*!
270 Forward mode Taylor coefficient for result of op = ErfOp or ErfcOp.
271
272 The C++ source code corresponding to this operation is one of
273 \verbatim
274 z = erf(x)
275 z = erfc(x)
276 \endverbatim
277
278 \tparam Base
279 base type for the operator; i.e., this operation was recorded
280 using AD< Base > and computations by this routine are done using type Base.
281
282 \param op
283 must be either ErfOp or ErfcOp and indicates if this is
284 z = erf(x) or z = erfc(x).
285
286 \param q
287 order of the Taylor coefficients that we are computing.
288
289 \param r
290 number of directions for the Taylor coefficients that we afre computing.
291
292 \param i_z
293 variable index corresponding to the last (primary) result for this operation;
294 i.e. the row index in taylor corresponding to z.
295 The auxillary results have index i_z - j for j = 0 , ... , 4
296 (and include z).
297
298 \param arg
299 arg[0]: is the variable index corresponding to x.
300 \n
301 arg[1]: is the parameter index corresponding to the value zero.
302 \n
303 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
304
305 \param parameter
306 parameter[ arg[1] ] is the value zero,
307 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
308
309 \param cap_order
310 maximum number of orders that will fit in the taylor array.
311
312 \par tpv
313 We use the notation
314 <code>tpv = (cap_order-1) * r + 1</code>
315 which is the number of Taylor coefficients per variable
316
317 \param taylor
318 \b Input: If x is a variable,
319 <code>taylor [ arg[0] * tpv + 0 ]</code>,
320 is the zero order Taylor coefficient for all directions and
321 <code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
322 for k = 1 , ... , q,
323 ell = 0, ..., r-1,
324 is the k-th order Taylor coefficient
325 corresponding to x and the ell-th direction.
326 \n
327 \b Input:
328 taylor [ (i_z - j) * tpv + 0 ]
329 is the zero order Taylor coefficient for all directions and the
330 j-th result for z.
331 for k = 1 , ... , q-1,
332 ell = 0, ... , r-1,
333 <code>
334 taylor[ (i_z - j) * tpv + (k-1)*r + ell + 1]
335 </code>
336 is the Taylor coefficient for the k-th order, ell-th direction,
337 and j-th auzillary result.
338 \n
339 \b Output:
340 taylor [ (i_z-j) * tpv + (q-1)*r + ell + 1 ],
341 for ell = 0 , ... , r-1,
342 is the Taylor coefficient for the q-th order, ell-th direction,
343 and j-th auzillary result.
344
345 */
346 template <class Base>
347 void forward_erf_op_dir(
348 OpCode op ,
349 size_t q ,
350 size_t r ,
351 size_t i_z ,
352 const addr_t* arg ,
353 const Base* parameter ,
354 size_t cap_order ,
355 Base* taylor )
356 {
357 // check assumptions
358 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
359 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
360 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
361 CPPAD_ASSERT_UNKNOWN( q < cap_order );
362 CPPAD_ASSERT_UNKNOWN( 0 < q );
363 CPPAD_ASSERT_UNKNOWN(
364 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
365 );
366
367 // array used to pass parameter values for sub-operations
368 addr_t addr[2];
369
370 // convert from final result to first result
371 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
372
373 // z_0 = x * x
374 addr[0] = arg[0]; // x
375 addr[1] = arg[0]; // x
376 forward_mulvv_op_dir(q, r, i_z+0, addr, parameter, cap_order, taylor);
377
378 // z_1 = - x * x
379 addr[0] = arg[1]; // zero
380 addr[1] = addr_t( i_z ); // z_0
381 forward_subpv_op_dir(q, r, i_z+1, addr, parameter, cap_order, taylor);
382
383 // z_2 = exp( - x * x )
384 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
385
386 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
387 addr[0] = arg[2]; // 2 / sqrt(pi)
388 addr[1] = addr_t( i_z + 2 ); // z_2
389 forward_mulpv_op_dir(q, r, i_z+3, addr, parameter, cap_order, taylor);
390
391 // pointers to taylor coefficients for x , z_3, and z_4
392 size_t num_taylor_per_var = (cap_order - 1) * r + 1;
393 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
394 Base* z_3 = taylor + (i_z+3) * num_taylor_per_var;
395 Base* z_4 = taylor + (i_z+4) * num_taylor_per_var;
396
397 // sign
398 Base sign(1.0);
399 if( op == ErfcOp )
400 sign = Base(-1.0);
401
402 // erf: z_4' (t) = erf'[x(t)] * x'(t) = z3(t) * x'(t)
403 // erfc: z_4' (t) = - erf'[x(t)] * x'(t) = z3(t) * x'(t)
404 // z_4[1] + 2 * z_4[2] * t + ... =
405 // sign * (z_3[0] + z_3[1] * t + ...) * (x[1] + 2 * x[2] * t + ...)
406 Base base_q = static_cast<Base>(double(q));
407 for(size_t ell = 0; ell < r; ell++)
408 { // index in z_4 and x for q-th order term
409 size_t m = (q-1)*r + ell + 1;
410 // initialize q-th order term summation
411 z_4[m] = sign * z_3[0] * x[m];
412 for(size_t k = 1; k < q; k++)
413 { size_t x_index = (k-1)*r + ell + 1;
414 size_t z3_index = (q-k-1)*r + ell + 1;
415 Base bk = Base(double(k));
416 z_4[m] += sign * (bk / base_q) * x[x_index] * z_3[z3_index];
417 }
418 }
419 }
420
421 /*!
422 Compute reverse mode partial derivatives for result of op = ErfOp or ErfcOp.
423
424 The C++ source code corresponding to this operation is one of
425 \verbatim
426 z = erf(x)
427 z = erfc(x)
428 \endverbatim
429
430 \tparam Base
431 base type for the operator; i.e., this operation was recorded
432 using AD< Base > and computations by this routine are done using type Base.
433
434 \param op
435 must be either ErfOp or ErfcOp and indicates if this is
436 z = erf(x) or z = erfc(x).
437
438 \param d
439 highest order Taylor of the Taylor coefficients that we are computing
440 the partial derivatives with respect to.
441
442 \param i_z
443 variable index corresponding to the last (primary) result for this operation;
444 i.e. the row index in taylor corresponding to z.
445 The auxillary results are called y_j have index i_z - j.
446
447 \param arg
448 arg[0]: is the variable index corresponding to x.
449 \n
450 arg[1]: is the parameter index corresponding to the value zero.
451 \n
452 arg[2]: is the parameter index correspodning to the value 2 / sqrt(pi).
453
454 \param parameter
455 parameter[ arg[1] ] is the value zero,
456 and parameter[ arg[2] ] is the value 2 / sqrt(pi).
457
458 \param cap_order
459 maximum number of orders that will fit in the taylor array.
460
461 \param taylor
462 \b Input:
463 taylor [ size_t(arg[0]) * cap_order + k ]
464 for k = 0 , ... , d,
465 is the k-th order Taylor coefficient corresponding to x.
466 \n
467 taylor [ (i_z - j) * cap_order + k ]
468 for k = 0 , ... , d,
469 and for j = 0 , ... , 4,
470 is the k-th order Taylor coefficient corresponding to the j-th result
471 for this operation.
472
473 \param nc_partial
474 number of columns in the matrix containing all the partial derivatives
475
476 \param partial
477 \b Input:
478 partial [ size_t(arg[0]) * nc_partial + k ]
479 for k = 0 , ... , d,
480 is the partial derivative of G( z , x , w , u , ... ) with respect to
481 the k-th order Taylor coefficient for x.
482 \n
483 \b Input:
484 partial [ (i_z - j) * nc_partial + k ]
485 for k = 0 , ... , d,
486 and for j = 0 , ... , 4,
487 is the partial derivative of G( z , x , w , u , ... ) with respect to
488 the k-th order Taylor coefficient for the j-th result of this operation.
489 \n
490 \b Output:
491 partial [ size_t(arg[0]) * nc_partial + k ]
492 for k = 0 , ... , d,
493 is the partial derivative of H( x , w , u , ... ) with respect to
494 the k-th order Taylor coefficient for x.
495 \n
496 \b Output:
497 partial [ (i_z-j) * nc_partial + k ]
498 for k = 0 , ... , d,
499 and for j = 0 , ... , 4,
500 may be used as work space; i.e., may change in an unspecified manner.
501
502 */
503 template <class Base>
504 void reverse_erf_op(
505 OpCode op ,
506 size_t d ,
507 size_t i_z ,
508 const addr_t* arg ,
509 const Base* parameter ,
510 size_t cap_order ,
511 const Base* taylor ,
512 size_t nc_partial ,
513 Base* partial )
514 {
515 // check assumptions
516 CPPAD_ASSERT_UNKNOWN( op == ErfOp || op == ErfcOp );
517 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
518 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 5 );
519 CPPAD_ASSERT_UNKNOWN( d < cap_order );
520 CPPAD_ASSERT_UNKNOWN(
521 size_t( std::numeric_limits<addr_t>::max() ) >= i_z + 2
522 );
523
524 // array used to pass parameter values for sub-operations
525 addr_t addr[2];
526
527 // If pz is zero, make sure this operation has no effect
528 // (zero times infinity or nan would be non-zero).
529 Base* pz = partial + i_z * nc_partial;
530 bool skip(true);
531 for(size_t i_d = 0; i_d <= d; i_d++)
532 skip &= IdenticalZero(pz[i_d]);
533 if( skip )
534 return;
535
536 // convert from final result to first result
537 i_z -= 4; // 4 = NumRes(ErfOp) - 1;
538
539 // Taylor coefficients and partials corresponding to x
540 const Base* x = taylor + size_t(arg[0]) * cap_order;
541 Base* px = partial + size_t(arg[0]) * nc_partial;
542
543 // Taylor coefficients and partials corresponding to z_3
544 const Base* z_3 = taylor + (i_z+3) * cap_order;
545 Base* pz_3 = partial + (i_z+3) * nc_partial;
546
547 // Taylor coefficients and partials corresponding to z_4
548 Base* pz_4 = partial + (i_z+4) * nc_partial;
549
550 // sign
551 Base sign(1.0);
552 if( op == ErfcOp )
553 sign = Base(-1.0);
554
555 // Reverse z_4
556 size_t j = d;
557 while(j)
558 { pz_4[j] /= Base(double(j));
559 for(size_t k = 1; k <= j; k++)
560 { px[k] += sign * azmul(pz_4[j], z_3[j-k]) * Base(double(k));
561 pz_3[j-k] += sign * azmul(pz_4[j], x[k]) * Base(double(k));
562 }
563 j--;
564 }
565 px[0] += sign * azmul(pz_4[0], z_3[0]);
566
567 // z_3 = (2 / sqrt(pi)) * exp( - x * x )
568 addr[0] = arg[2]; // 2 / sqrt(pi)
569 addr[1] = addr_t( i_z + 2 ); // z_2
570 reverse_mulpv_op(
571 d, i_z+3, addr, parameter, cap_order, taylor, nc_partial, partial
572 );
573
574 // z_2 = exp( - x * x )
575 reverse_exp_op(
576 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
577 );
578
579 // z_1 = - x * x
580 addr[0] = arg[1]; // zero
581 addr[1] = addr_t( i_z ); // z_0
582 reverse_subpv_op(
583 d, i_z+1, addr, parameter, cap_order, taylor, nc_partial, partial
584 );
585
586 // z_0 = x * x
587 addr[0] = arg[0]; // x
588 addr[1] = arg[0]; // x
589 reverse_mulvv_op(
590 d, i_z+0, addr, parameter, cap_order, taylor, nc_partial, partial
591 );
592
593 }
594
595
596 } } // END_CPPAD_LOCAL_NAMESPACE
597 # endif // CPPAD_ERF_OP_INCLUDED
0 # ifndef CPPAD_LOCAL_OP_EXP_OP_HPP
1 # define CPPAD_LOCAL_OP_EXP_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_exp_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37
38 size_t k;
39 if( p == 0 )
40 { z[0] = exp( x[0] );
41 p++;
42 }
43 for(size_t j = p; j <= q; j++)
44 {
45 z[j] = x[1] * z[j-1];
46 for(k = 2; k <= j; k++)
47 z[j] += Base(double(k)) * x[k] * z[j-k];
48 z[j] /= Base(double(j));
49 }
50 }
51
52
53 // See dev documentation: forward_unary_op
54 template <class Base>
55 void forward_exp_op_dir(
56 size_t q ,
57 size_t r ,
58 size_t i_z ,
59 size_t i_x ,
60 size_t cap_order ,
61 Base* taylor )
62 {
63 // check assumptions
64 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
65 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
66 CPPAD_ASSERT_UNKNOWN( q < cap_order );
67 CPPAD_ASSERT_UNKNOWN( 0 < q );
68
69 // Taylor coefficients corresponding to argument and result
70 size_t num_taylor_per_var = (cap_order-1) * r + 1;
71 Base* x = taylor + i_x * num_taylor_per_var;
72 Base* z = taylor + i_z * num_taylor_per_var;
73
74 size_t m = (q-1)*r + 1;
75 for(size_t ell = 0; ell < r; ell++)
76 { z[m+ell] = Base(double(q)) * x[m+ell] * z[0];
77 for(size_t k = 1; k < q; k++)
78 z[m+ell] += Base(double(k)) * x[(k-1)*r+ell+1] * z[(q-k-1)*r+ell+1];
79 z[m+ell] /= Base(double(q));
80 }
81 }
82
83 // See dev documentation: forward_unary_op
84 template <class Base>
85 void forward_exp_op_0(
86 size_t i_z ,
87 size_t i_x ,
88 size_t cap_order ,
89 Base* taylor )
90 {
91 // check assumptions
92 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
93 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
94 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
95
96 // Taylor coefficients corresponding to argument and result
97 Base* x = taylor + i_x * cap_order;
98 Base* z = taylor + i_z * cap_order;
99
100 z[0] = exp( x[0] );
101 }
102
103 // See dev documentation: reverse_unary_op
104 template <class Base>
105 void reverse_exp_op(
106 size_t d ,
107 size_t i_z ,
108 size_t i_x ,
109 size_t cap_order ,
110 const Base* taylor ,
111 size_t nc_partial ,
112 Base* partial )
113 {
114 // check assumptions
115 CPPAD_ASSERT_UNKNOWN( NumArg(ExpOp) == 1 );
116 CPPAD_ASSERT_UNKNOWN( NumRes(ExpOp) == 1 );
117 CPPAD_ASSERT_UNKNOWN( d < cap_order );
118 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
119
120 // Taylor coefficients and partials corresponding to argument
121 const Base* x = taylor + i_x * cap_order;
122 Base* px = partial + i_x * nc_partial;
123
124 // Taylor coefficients and partials corresponding to result
125 const Base* z = taylor + i_z * cap_order;
126 Base* pz = partial + i_z * nc_partial;
127
128 // If pz is zero, make sure this operation has no effect
129 // (zero times infinity or nan would be non-zero).
130 bool skip(true);
131 for(size_t i_d = 0; i_d <= d; i_d++)
132 skip &= IdenticalZero(pz[i_d]);
133 if( skip )
134 return;
135
136 // loop through orders in reverse
137 size_t j, k;
138 j = d;
139 while(j)
140 { // scale partial w.r.t z[j]
141 pz[j] /= Base(double(j));
142
143 for(k = 1; k <= j; k++)
144 { px[k] += Base(double(k)) * azmul(pz[j], z[j-k]);
145 pz[j-k] += Base(double(k)) * azmul(pz[j], x[k]);
146 }
147 --j;
148 }
149 px[0] += azmul(pz[0], z[0]);
150 }
151
152 } } // END_CPPAD_LOCAL_NAMESPACE
153 # endif
0 # ifndef CPPAD_LOCAL_OP_EXPM1_OP_HPP
1 # define CPPAD_LOCAL_OP_EXPM1_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17
18
19 template <class Base>
20 void forward_expm1_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37
38 size_t k;
39 if( p == 0 )
40 { z[0] = expm1( x[0] );
41 p++;
42 }
43 for(size_t j = p; j <= q; j++)
44 {
45 z[j] = x[1] * z[j-1];
46 for(k = 2; k <= j; k++)
47 z[j] += Base(double(k)) * x[k] * z[j-k];
48 z[j] /= Base(double(j));
49 z[j] += x[j];
50 }
51 }
52
53
54 template <class Base>
55 void forward_expm1_op_dir(
56 size_t q ,
57 size_t r ,
58 size_t i_z ,
59 size_t i_x ,
60 size_t cap_order ,
61 Base* taylor )
62 {
63 // check assumptions
64 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
65 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
66 CPPAD_ASSERT_UNKNOWN( q < cap_order );
67 CPPAD_ASSERT_UNKNOWN( 0 < q );
68
69 // Taylor coefficients corresponding to argument and result
70 size_t num_taylor_per_var = (cap_order-1) * r + 1;
71 Base* x = taylor + i_x * num_taylor_per_var;
72 Base* z = taylor + i_z * num_taylor_per_var;
73
74 size_t m = (q-1)*r + 1;
75 for(size_t ell = 0; ell < r; ell++)
76 { z[m+ell] = Base(double(q)) * x[m+ell] * z[0];
77 for(size_t k = 1; k < q; k++)
78 z[m+ell] += Base(double(k)) * x[(k-1)*r+ell+1] * z[(q-k-1)*r+ell+1];
79 z[m+ell] /= Base(double(q));
80 z[m+ell] += x[m+ell];
81 }
82 }
83
84 template <class Base>
85 void forward_expm1_op_0(
86 size_t i_z ,
87 size_t i_x ,
88 size_t cap_order ,
89 Base* taylor )
90 {
91 // check assumptions
92 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
93 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
94 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
95
96 // Taylor coefficients corresponding to argument and result
97 Base* x = taylor + i_x * cap_order;
98 Base* z = taylor + i_z * cap_order;
99
100 z[0] = expm1( x[0] );
101 }
102
103 template <class Base>
104 void reverse_expm1_op(
105 size_t d ,
106 size_t i_z ,
107 size_t i_x ,
108 size_t cap_order ,
109 const Base* taylor ,
110 size_t nc_partial ,
111 Base* partial )
112 {
113 // check assumptions
114 CPPAD_ASSERT_UNKNOWN( NumArg(Expm1Op) == 1 );
115 CPPAD_ASSERT_UNKNOWN( NumRes(Expm1Op) == 1 );
116 CPPAD_ASSERT_UNKNOWN( d < cap_order );
117 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
118
119 // Taylor coefficients and partials corresponding to argument
120 const Base* x = taylor + i_x * cap_order;
121 Base* px = partial + i_x * nc_partial;
122
123 // Taylor coefficients and partials corresponding to result
124 const Base* z = taylor + i_z * cap_order;
125 Base* pz = partial + i_z * nc_partial;
126
127 // If pz is zero, make sure this operation has no effect
128 // (zero times infinity or nan would be non-zero).
129 bool skip(true);
130 for(size_t i_d = 0; i_d <= d; i_d++)
131 skip &= IdenticalZero(pz[i_d]);
132 if( skip )
133 return;
134
135 // loop through orders in reverse
136 size_t j, k;
137 j = d;
138 while(j)
139 { px[j] += pz[j];
140
141 // scale partial w.r.t z[j]
142 pz[j] /= Base(double(j));
143
144 for(k = 1; k <= j; k++)
145 { px[k] += Base(double(k)) * azmul(pz[j], z[j-k]);
146 pz[j-k] += Base(double(k)) * azmul(pz[j], x[k]);
147 }
148 --j;
149 }
150 px[0] += pz[0] + azmul(pz[0], z[0]);
151 }
152
153 } } // END_CPPAD_LOCAL_NAMESPACE
154 # endif
0 # ifndef CPPAD_LOCAL_OP_LOAD_OP_HPP
1 # define CPPAD_LOCAL_OP_LOAD_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*
17 ------------------------------------------------------------------------------
18 $begin load_op_var$$
19 $spell
20 pv
21 Vec
22 op
23 var
24 isvar
25 ind
26 Taylor
27 arg
28 num
29 Addr
30 vecad
31 $$
32 $section Accessing an Element in a Variable VecAD Vector$$
33
34 $head See Also$$
35 $cref/op_code_var load/op_code_var/Load/$$.
36
37 $head Syntax$$
38 $codei%forward_load_%I%_op_0(
39 %play%,
40 %i_z%,
41 %arg%,
42 %parameter%,
43 %cap_order%,
44 %taylor%,
45 %vec_ad2isvar%,
46 %vec_ad2index%,
47 %load_op2var%
48 )
49 %$$
50 where the index type $icode I$$ is $code p$$ (for parameter)
51 or $code v$$ (for variable).
52
53 $head Prototype$$
54 $srcthisfile%
55 0%// BEGIN_FORWARD_LOAD_P_OP_0%// END_FORWARD_LOAD_P_OP_0%1
56 %$$
57 The prototype for $code forward_load_v_op_0$$ is the same
58 except for the function name.
59
60 $head Notation$$
61
62 $subhead v$$
63 We use $icode v$$ to denote the $cref VecAD$$ vector for this operation.
64
65 $subhead x$$
66 We use $icode x$$ to denote the $codei%AD%<%Base%>%$$
67 index for this operation.
68
69 $subhead i_vec$$
70 We use $icode i_vec$$ to denote the $code size_t$$ value
71 corresponding to $icode x$$.
72
73 $subhead n_load$$
74 This is the number of load instructions in this recording; i.e.,
75 $icode%play%->num_var_load_rec()%$$.
76
77 $subhead n_all$$
78 This is the number of values in the single array that includes
79 all the vectors together with the size of each vector; i.e.,
80 $icode%play%->num_var_vecad_ind_rec()%$$.
81
82 $head Addr$$
83 Is the type used for address on this tape.
84
85 $head Base$$
86 base type for the operator; i.e., this operation was recorded
87 using AD<Base> and computations by this routine are done using type Base.
88
89 $head play$$
90 is the tape that this operation appears in.
91 This is for error detection and not used when NDEBUG is defined.
92
93 $head i_z$$
94 is the AD variable index corresponding to the result of this load operation.
95
96 $head arg$$
97
98 $subhead arg[0]$$
99 is the offset of this VecAD vector relative to the beginning
100 of the $icode vec_ad2isvar$$ and $icode vec_ad2index$$ arrays.
101
102 $subhead arg[1]$$
103 If this is
104 $code forward_load_p_op_0$$ ($code forward_load_v_op_0$$)
105 $icode%arg%[%1%]%$$ is the parameter index (variable index)
106 corresponding to $cref/i_vec/load_op_var/Notation/i_vec/$$.
107
108 $subhead arg[2]$$
109 Is the index of this VecAD load instruction in the
110 $icode load_op2var$$ array.
111
112 $head parameter$$
113 This is the vector of parameters for this recording which has size
114 $icode%play%->num_par_rec()%$$.
115
116 $head cap_order$$
117 number of columns in the matrix containing the Taylor coefficients.
118
119 $head taylor$$
120 Is the matrix of Taylor coefficients.
121
122 $subhead Input$$
123 In the $code forward_load_v_op_0$$ case,
124 $codei%
125 size_t( %taylor%[ %arg%[1]% * %cap_order% + 0 ] )
126 %$$
127 is the index in this VecAD vector.
128
129 $subhead Output$$
130 $icode%taylor%[ %i_z% * %cap_order% + 0 ]%$$
131 is set to the zero order Taylor coefficient for the result of this operator.
132
133 $head vec_ad2isvar$$
134 This vector has size $icode n_all$$.
135 If $icode%vec_ad2isvar%[ %arg%[%0%] + %i_vec% ]%$$ is false (true),
136 the vector element is parameter (variable).
137
138 $subhead i_pv$$
139 If this element is a parameter (variable),
140 $codei%
141 %i_pv% = %vec_ad2index%[ %arg%[%0%] + %i_vec% ]
142 %$$
143 is the corresponding parameter (variable) index;
144
145 $head vec_ad2index$$
146 This array has size $icode n_all$$
147 The value $icode%vec_ad2index%[ %arg%[0] - 1 ]%$$
148 is the number of elements in the user vector containing this load.
149 $icode%vec_ad2index%[%i_pv%]%$$ is the variable or
150 parameter index for this element,
151
152 $head load_op2var$$
153 is a vector with size $icode n_load$$.
154 The input value of its elements does not matter.
155 If the result of this load is a variable,
156 $codei%
157 %load_op2var%[%arg%[2]] = %i_pv%
158 %$$
159 Otherwise,
160 $codei%
161 %load_op2var%[%arg%[2]] = 0
162 %$$
163
164 $end
165 */
166 // BEGIN_FORWARD_LOAD_P_OP_0
167 template <class Addr, class Base>
168 void forward_load_p_op_0(
169 const local::player<Base>* play ,
170 size_t i_z ,
171 const Addr* arg ,
172 const Base* parameter ,
173 size_t cap_order ,
174 Base* taylor ,
175 const bool* vec_ad2isvar ,
176 const size_t* vec_ad2index ,
177 Addr* load_op2var )
178 // END_FORWARD_LOAD_P_OP_0
179 { CPPAD_ASSERT_UNKNOWN( NumArg(LdpOp) == 3 );
180 CPPAD_ASSERT_UNKNOWN( NumRes(LdpOp) == 1 );
181 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
182 CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < play->num_par_rec() );
183 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_var_load_rec() );
184 CPPAD_ASSERT_UNKNOWN(
185 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
186 );
187
188 addr_t i_vec = addr_t( Integer( parameter[ arg[1] ] ) );
189 CPPAD_ASSERT_KNOWN(
190 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
191 "VecAD: dynamic parmaeter index out or range during zero order forward"
192 );
193 CPPAD_ASSERT_UNKNOWN( size_t(arg[0] + i_vec) < play->num_var_vecad_ind_rec() );
194
195 size_t i_pv = vec_ad2index[ arg[0] + i_vec ];
196 Base* z = taylor + i_z * cap_order;
197 if( vec_ad2isvar[ arg[0] + i_vec ] )
198 { CPPAD_ASSERT_UNKNOWN( i_pv < i_z );
199 load_op2var[ arg[2] ] = addr_t( i_pv );
200 Base* v_x = taylor + i_pv * cap_order;
201 z[0] = v_x[0];
202 }
203 else
204 { CPPAD_ASSERT_UNKNOWN( i_pv < play->num_par_rec() );
205 load_op2var[ arg[2] ] = 0;
206 Base v_x = parameter[i_pv];
207 z[0] = v_x;
208 }
209 }
210 template <class Addr, class Base>
211 void forward_load_v_op_0(
212 const local::player<Base>* play ,
213 size_t i_z ,
214 const Addr* arg ,
215 const Base* parameter ,
216 size_t cap_order ,
217 Base* taylor ,
218 const bool* vec_ad2isvar ,
219 const size_t* vec_ad2index ,
220 Addr* load_op2var )
221 { CPPAD_ASSERT_UNKNOWN( NumArg(LdvOp) == 3 );
222 CPPAD_ASSERT_UNKNOWN( NumRes(LdvOp) == 1 );
223 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
224 CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_z );
225 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_var_load_rec() );
226 CPPAD_ASSERT_UNKNOWN(
227 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
228 );
229
230 addr_t i_vec = addr_t(Integer(taylor[ size_t(arg[1]) * cap_order + 0 ] ));
231 CPPAD_ASSERT_KNOWN(
232 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
233 "VecAD: variable index out or range during zero order forward"
234 );
235 CPPAD_ASSERT_UNKNOWN( size_t(arg[0] + i_vec) < play->num_var_vecad_ind_rec() );
236
237 size_t i_pv = vec_ad2index[ arg[0] + i_vec ];
238 Base* z = taylor + i_z * cap_order;
239 if( vec_ad2isvar[ arg[0] + i_vec ] )
240 { CPPAD_ASSERT_UNKNOWN( i_pv < i_z );
241 load_op2var[ arg[2] ] = addr_t( i_pv );
242 Base* v_x = taylor + i_pv * cap_order;
243 z[0] = v_x[0];
244 }
245 else
246 { CPPAD_ASSERT_UNKNOWN( i_pv < play->num_par_rec() );
247 load_op2var[ arg[2] ] = 0;
248 Base v_x = parameter[i_pv];
249 z[0] = v_x;
250 }
251 }
252 /*!
253 ------------------------------------------------------------------------------
254 Shared documentation for sparsity operations corresponding to
255 op = LdpOp or LdvOp (not called).
256
257 <!-- replace preamble -->
258 The C++ source code corresponding to this operation is
259 \verbatim
260 v[x] = y
261 \endverbatim
262 where v is a VecAD<Base> vector, x is an AD<Base> object,
263 and y is AD<Base> or Base objects.
264 We define the index corresponding to v[x] by
265 \verbatim
266 i_pv = vec_ad2index[ arg[0] + i_vec ]
267 \endverbatim
268 where i_vec is defined under the heading arg[1] below:
269 <!-- end preamble -->
270
271 \tparam Vector_set
272 is the type used for vectors of sets. It can be either
273 sparse::pack_setvec or sparse::list_setvec.
274
275 \param op
276 is the code corresponding to this operator;
277 i.e., LdpOp or LdvOp.
278
279 \param i_z
280 is the AD variable index corresponding to the variable z; i.e.,
281 the set with index i_z in var_sparsity is the sparsity pattern
282 corresponding to z.
283
284 \param arg
285 \n
286 arg[0]
287 is the offset corresponding to this VecAD vector in the VecAD combined array.
288
289 \param num_combined
290 is the total number of elements in the VecAD combinded array.
291
292 \param combined
293 is the VecAD combined array.
294 \n
295 \n
296 combined[ arg[0] - 1 ]
297 is the index of the set corresponding to the vector v in vecad_sparsity.
298 We use the notation i_v for this value; i.e.,
299 \verbatim
300 i_v = combined[ arg[0] - 1 ]
301 \endverbatim
302
303 \param var_sparsity
304 The set with index i_z in var_sparsity is the sparsity pattern for z.
305 This is an output for forward mode operations,
306 and an input for reverse mode operations.
307
308 \param vecad_sparsity
309 The set with index i_v is the sparsity pattern for the vector v.
310 This is an input for forward mode operations.
311 For reverse mode operations,
312 the sparsity pattern for z is added to the sparsity pattern for v.
313
314 \par Checked Assertions
315 \li NumArg(op) == 3
316 \li NumRes(op) == 1
317 \li 0 < arg[0]
318 \li arg[0] < num_combined
319 \li i_v < vecad_sparsity.n_set()
320 */
321 template <class Vector_set, class Addr>
322 void sparse_load_op(
323 OpCode op ,
324 size_t i_z ,
325 const Addr* arg ,
326 size_t num_combined ,
327 const size_t* combined ,
328 Vector_set& var_sparsity ,
329 Vector_set& vecad_sparsity )
330 {
331 // This routine is only for documentaiton, it should not be used
332 CPPAD_ASSERT_UNKNOWN( false );
333 }
334
335
336
337 /*!
338 Forward mode, except for zero order, for op = LdpOp or op = LdvOp
339
340
341 <!-- replace preamble -->
342 The C++ source code corresponding to this operation is
343 \verbatim
344 v[x] = y
345 \endverbatim
346 where v is a VecAD<Base> vector, x is an AD<Base> object,
347 and y is AD<Base> or Base objects.
348 We define the index corresponding to v[x] by
349 \verbatim
350 i_pv = vec_ad2index[ arg[0] + i_vec ]
351 \endverbatim
352 where i_vec is defined under the heading arg[1] below:
353 <!-- end preamble -->
354
355 \tparam Base
356 base type for the operator; i.e., this operation was recorded
357 using AD<Base> and computations by this routine are done using type Base.
358
359 \param play
360 is the tape that this operation appears in.
361 This is for error detection and not used when NDEBUG is defined.
362
363 \param op
364 is the code corresponding to this operator; i.e., LdpOp or LdvOp
365 (only used for error checking).
366
367 \param p
368 is the lowest order of the Taylor coefficient that we are computing.
369
370 \param q
371 is the highest order of the Taylor coefficient that we are computing.
372
373 \param r
374 is the number of directions for the Taylor coefficients that we
375 are computing.
376
377 \param cap_order
378 number of columns in the matrix containing the Taylor coefficients.
379
380 \par tpv
381 We use the notation
382 <code>tpv = (cap_order-1) * r + 1</code>
383 which is the number of Taylor coefficients per variable
384
385 \param i_z
386 is the AD variable index corresponding to the variable z.
387
388 \param arg
389 arg[2]
390 Is the index of this vecad load instruction in the load_op2var array.
391
392 \param load_op2var
393 is a vector with size play->num_var_load_rec().
394 It contains the variable index corresponding to each load instruction.
395 In the case where the index is zero,
396 the instruction corresponds to a parameter (not variable).
397
398 \par i_var
399 We use the notation
400 \verbatim
401 i_var = size_t( load_op2var[ arg[2] ] )
402 \endverbatim
403
404 \param taylor
405 \n
406 Input
407 \n
408 If <code>i_var > 0</code>, v[x] is a variable and
409 for k = 1 , ... , q
410 <code>taylor[ i_var * tpv + (k-1)*r+1+ell ]</code>
411 is the k-th order coefficient for v[x] in the ell-th direction,
412 \n
413 \n
414 Output
415 \n
416 for k = p , ... , q,
417 <code>taylor[ i_z * tpv + (k-1)*r+1+ell ]</code>
418 is set to the k-order Taylor coefficient for z in the ell-th direction.
419 */
420 template <class Addr, class Base>
421 void forward_load_op(
422 const local::player<Base>* play,
423 OpCode op ,
424 size_t p ,
425 size_t q ,
426 size_t r ,
427 size_t cap_order ,
428 size_t i_z ,
429 const Addr* arg ,
430 const Addr* load_op2var ,
431 Base* taylor )
432 {
433 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
434 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
435 CPPAD_ASSERT_UNKNOWN( q < cap_order );
436 CPPAD_ASSERT_UNKNOWN( 0 < r);
437 CPPAD_ASSERT_UNKNOWN( 0 < p);
438 CPPAD_ASSERT_UNKNOWN( p <= q );
439 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < play->num_var_load_rec() );
440
441 size_t i_var = size_t( load_op2var[ arg[2] ] );
442 CPPAD_ASSERT_UNKNOWN( i_var < i_z );
443
444 size_t num_taylor_per_var = (cap_order-1) * r + 1;
445 Base* z = taylor + i_z * num_taylor_per_var;
446 if( i_var > 0 )
447 { Base* v_x = taylor + i_var * num_taylor_per_var;
448 for(size_t ell = 0; ell < r; ell++)
449 { for(size_t k = p; k <= q; k++)
450 { size_t m = (k-1) * r + 1 + ell;
451 z[m] = v_x[m];
452 }
453 }
454 }
455 else
456 { for(size_t ell = 0; ell < r; ell++)
457 { for(size_t k = p; k <= q; k++)
458 { size_t m = (k-1) * r + 1 + ell;
459 z[m] = Base(0.0);
460 }
461 }
462 }
463 }
464
465 /*!
466 Reverse mode for op = LdpOp or LdvOp.
467
468 <!-- replace preamble -->
469 The C++ source code corresponding to this operation is
470 \verbatim
471 v[x] = y
472 \endverbatim
473 where v is a VecAD<Base> vector, x is an AD<Base> object,
474 and y is AD<Base> or Base objects.
475 We define the index corresponding to v[x] by
476 \verbatim
477 i_pv = vec_ad2index[ arg[0] + i_vec ]
478 \endverbatim
479 where i_vec is defined under the heading arg[1] below:
480 <!-- end preamble -->
481
482 This routine is given the partial derivatives of a function
483 G(z , y[x] , w , u ... )
484 and it uses them to compute the partial derivatives of
485 \verbatim
486 H( y[x] , w , u , ... ) = G[ z( y[x] ) , y[x] , w , u , ... ]
487 \endverbatim
488
489 \tparam Base
490 base type for the operator; i.e., this operation was recorded
491 using AD< Base > and computations by this routine are done using type
492 Base.
493
494 \param op
495 is the code corresponding to this operator; i.e., LdpOp or LdvOp
496 (only used for error checking).
497
498 \param d
499 highest order the Taylor coefficient that we are computing the partial
500 derivative with respect to.
501
502 \param i_z
503 is the AD variable index corresponding to the variable z.
504
505 \param arg
506 arg[2]
507 Is the index of this vecad load instruction in the
508 load_op2var array.
509
510 \param cap_order
511 number of columns in the matrix containing the Taylor coefficients
512 (not used).
513
514 \param taylor
515 matrix of Taylor coefficients (not used).
516
517 \param nc_partial
518 number of colums in the matrix containing all the partial derivatives
519 (not used if arg[2] is zero).
520
521 \param partial
522 If arg[2] is zero, y[x] is a parameter
523 and no values need to be modified; i.e., partial is not used.
524 Otherwise, y[x] is a variable and:
525 \n
526 \n
527 partial [ i_z * nc_partial + k ]
528 for k = 0 , ... , d
529 is the partial derivative of G
530 with respect to the k-th order Taylor coefficient for z.
531 \n
532 \n
533 If arg[2] is not zero,
534 partial [ arg[2] * nc_partial + k ]
535 for k = 0 , ... , d
536 is the partial derivative with respect to
537 the k-th order Taylor coefficient for x.
538 On input, it corresponds to the function G,
539 and on output it corresponds to the the function H.
540
541 \param load_op2var
542 is a vector with size play->num_var_load_rec().
543 It contains the variable index corresponding to each load instruction.
544 In the case where the index is zero,
545 the instruction corresponds to a parameter (not variable).
546
547 \par Checked Assertions
548 \li NumArg(op) == 3
549 \li NumRes(op) == 1
550 \li d < cap_order
551 \li size_t(arg[2]) < i_z
552 */
553 template <class Addr, class Base>
554 void reverse_load_op(
555 OpCode op ,
556 size_t d ,
557 size_t i_z ,
558 const Addr* arg ,
559 size_t cap_order ,
560 const Base* taylor ,
561 size_t nc_partial ,
562 Base* partial ,
563 const Addr* load_op2var )
564 { size_t i_load = size_t( load_op2var[ arg[2] ] );
565
566 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
567 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
568 CPPAD_ASSERT_UNKNOWN( d < cap_order );
569 CPPAD_ASSERT_UNKNOWN( i_load < i_z );
570
571 if( i_load > 0 )
572 {
573 Base* pz = partial + i_z * nc_partial;
574 Base* py_x = partial + i_load * nc_partial;
575 size_t j = d + 1;
576 while(j--)
577 py_x[j] += pz[j];
578 }
579 }
580
581
582 /*!
583 Forward mode sparsity operations for LdpOp and LdvOp
584
585 \param dependency
586 is this a dependency (or sparsity) calculation.
587
588 \copydetails CppAD::local::sparse_load_op
589 */
590 template <class Vector_set, class Addr>
591 void forward_sparse_load_op(
592 bool dependency ,
593 OpCode op ,
594 size_t i_z ,
595 const Addr* arg ,
596 size_t num_combined ,
597 const size_t* combined ,
598 Vector_set& var_sparsity ,
599 Vector_set& vecad_sparsity )
600 {
601 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
602 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
603 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
604 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
605 size_t i_v = combined[ arg[0] - 1 ];
606 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
607
608 var_sparsity.assignment(i_z, i_v, vecad_sparsity);
609 if( dependency & (op == LdvOp) )
610 var_sparsity.binary_union(i_z, i_z, size_t(arg[1]), var_sparsity);
611
612 return;
613 }
614
615
616 /*!
617 Reverse mode Jacobian sparsity operations for LdpOp and LdvOp
618
619 \param dependency
620 is this a dependency (or sparsity) calculation.
621
622 \copydetails CppAD::local::sparse_load_op
623 */
624 template <class Vector_set, class Addr>
625 void reverse_sparse_jacobian_load_op(
626 bool dependency ,
627 OpCode op ,
628 size_t i_z ,
629 const Addr* arg ,
630 size_t num_combined ,
631 const size_t* combined ,
632 Vector_set& var_sparsity ,
633 Vector_set& vecad_sparsity )
634 {
635 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
636 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
637 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
638 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
639 size_t i_v = combined[ arg[0] - 1 ];
640 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
641
642 vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity);
643 if( dependency & (op == LdvOp) )
644 var_sparsity.binary_union( size_t(arg[1]), size_t(arg[1]), i_z, var_sparsity);
645
646 return;
647 }
648
649
650 /*!
651 Reverse mode Hessian sparsity operations for LdpOp and LdvOp
652
653 \copydetails CppAD::local::sparse_load_op
654
655 \param var_jacobian
656 var_jacobian[i_z]
657 is false (true) if the Jacobian of G with respect to z is always zero
658 (many be non-zero).
659
660 \param vecad_jacobian
661 vecad_jacobian[i_v]
662 is false (true) if the Jacobian with respect to x is always zero
663 (may be non-zero).
664 On input, it corresponds to the function G,
665 and on output it corresponds to the function H.
666
667 */
668 template <class Vector_set, class Addr>
669 void reverse_sparse_hessian_load_op(
670 OpCode op ,
671 size_t i_z ,
672 const Addr* arg ,
673 size_t num_combined ,
674 const size_t* combined ,
675 Vector_set& var_sparsity ,
676 Vector_set& vecad_sparsity ,
677 bool* var_jacobian ,
678 bool* vecad_jacobian )
679 {
680 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
681 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
682 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
683 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
684 size_t i_v = combined[ arg[0] - 1 ];
685 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
686
687 vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity);
688
689 vecad_jacobian[i_v] |= var_jacobian[i_z];
690
691 return;
692 }
693
694
695 } } // END_CPPAD_LOCAL_NAMESPACE
696 # endif
0 # ifndef CPPAD_LOCAL_OP_LOG1P_OP_HPP
1 # define CPPAD_LOCAL_OP_LOG1P_OP_HPP
2
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
5
6 CppAD is distributed under the terms of the
7 Eclipse Public License Version 2.0.
8
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12 GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17 template <class Base>
18 void forward_log1p_op(
19 size_t p ,
20 size_t q ,
21 size_t i_z ,
22 size_t i_x ,
23 size_t cap_order ,
24 Base* taylor )
25 {
26 size_t k;
27
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37
38 if( p == 0 )
39 { z[0] = log1p( x[0] );
40 p++;
41 if( q == 0 )
42 return;
43 }
44 if ( p == 1 )
45 { z[1] = x[1] / (Base(1.0) + x[0]);
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 {
50 z[j] = -z[1] * x[j-1];
51 for(k = 2; k < j; k++)
52 z[j] -= Base(double(k)) * z[k] * x[j-k];
53 z[j] /= Base(double(j));
54 z[j] += x[j];
55 z[j] /= (Base(1.0) + x[0]);
56 }
57 }
58
59 template <class Base>
60 void forward_log1p_op_dir(
61 size_t q ,
62 size_t r ,
63 size_t i_z ,
64 size_t i_x ,
65 size_t cap_order ,
66 Base* taylor )
67 {
68
69 // check assumptions
70 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
71 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
72 CPPAD_ASSERT_UNKNOWN( 0 < q );
73 CPPAD_ASSERT_UNKNOWN( q < cap_order );
74
75 // Taylor coefficients corresponding to argument and result
76 size_t num_taylor_per_var = (cap_order-1) * r + 1;
77 Base* x = taylor + i_x * num_taylor_per_var;
78 Base* z = taylor + i_z * num_taylor_per_var;
79
80 size_t m = (q-1) * r + 1;
81 for(size_t ell = 0; ell < r; ell++)
82 { z[m+ell] = Base(double(q)) * x[m+ell];
83 for(size_t k = 1; k < q; k++)
84 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
85 z[m+ell] /= (Base(double(q)) + Base(q) * x[0]);
86 }
87 }
88
89 template <class Base>
90 void forward_log1p_op_0(
91 size_t i_z ,
92 size_t i_x ,
93 size_t cap_order ,
94 Base* taylor )
95 {
96
97 // check assumptions
98 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
99 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
100 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
101
102 // Taylor coefficients corresponding to argument and result
103 Base* x = taylor + i_x * cap_order;
104 Base* z = taylor + i_z * cap_order;
105
106 z[0] = log1p( x[0] );
107 }
108
109
110 template <class Base>
111 void reverse_log1p_op(
112 size_t d ,
113 size_t i_z ,
114 size_t i_x ,
115 size_t cap_order ,
116 const Base* taylor ,
117 size_t nc_partial ,
118 Base* partial )
119 { size_t j, k;
120
121 // check assumptions
122 CPPAD_ASSERT_UNKNOWN( NumArg(Log1pOp) == 1 );
123 CPPAD_ASSERT_UNKNOWN( NumRes(Log1pOp) == 1 );
124 CPPAD_ASSERT_UNKNOWN( d < cap_order );
125 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
126
127 // Taylor coefficients and partials corresponding to argument
128 const Base* x = taylor + i_x * cap_order;
129 Base* px = partial + i_x * nc_partial;
130
131 // Taylor coefficients and partials corresponding to result
132 const Base* z = taylor + i_z * cap_order;
133 Base* pz = partial + i_z * nc_partial;
134
135 Base inv_1px0 = Base(1.0) / (Base(1) + x[0]);
136
137 j = d;
138 while(j)
139 { // scale partial w.r.t z[j]
140 pz[j] = azmul(pz[j] , inv_1px0);
141
142 px[0] -= azmul(pz[j], z[j]);
143 px[j] += pz[j];
144
145 // further scale partial w.r.t. z[j]
146 pz[j] /= Base(double(j));
147
148 for(k = 1; k < j; k++)
149 { pz[k] -= Base(double(k)) * azmul(pz[j], x[j-k]);
150 px[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
151 }
152 --j;
153 }
154 px[0] += azmul(pz[0], inv_1px0);
155 }
156
157 } } // END_CPPAD_LOCAL_NAMESPACE
158 # endif
0 # ifndef CPPAD_LOCAL_OP_LOG_OP_HPP
1 # define CPPAD_LOCAL_OP_LOG_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15
16 // See dev documentation: forward_unary_op
17 template <class Base>
18 void forward_log_op(
19 size_t p ,
20 size_t q ,
21 size_t i_z ,
22 size_t i_x ,
23 size_t cap_order ,
24 Base* taylor )
25 {
26 size_t k;
27
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37
38 if( p == 0 )
39 { z[0] = log( x[0] );
40 p++;
41 if( q == 0 )
42 return;
43 }
44 if ( p == 1 )
45 { z[1] = x[1] / x[0];
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 {
50 z[j] = -z[1] * x[j-1];
51 for(k = 2; k < j; k++)
52 z[j] -= Base(double(k)) * z[k] * x[j-k];
53 z[j] /= Base(double(j));
54 z[j] += x[j];
55 z[j] /= x[0];
56 }
57 }
58
59 // See dev documentation: forward_unary_op
60 template <class Base>
61 void forward_log_op_dir(
62 size_t q ,
63 size_t r ,
64 size_t i_z ,
65 size_t i_x ,
66 size_t cap_order ,
67 Base* taylor )
68 {
69
70 // check assumptions
71 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
72 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
73 CPPAD_ASSERT_UNKNOWN( 0 < q );
74 CPPAD_ASSERT_UNKNOWN( q < cap_order );
75
76 // Taylor coefficients corresponding to argument and result
77 size_t num_taylor_per_var = (cap_order-1) * r + 1;
78 Base* x = taylor + i_x * num_taylor_per_var;
79 Base* z = taylor + i_z * num_taylor_per_var;
80
81 size_t m = (q-1) * r + 1;
82 for(size_t ell = 0; ell < r; ell++)
83 { z[m+ell] = Base(double(q)) * x[m+ell];
84 for(size_t k = 1; k < q; k++)
85 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * x[(q-k-1)*r+1+ell];
86 z[m+ell] /= (Base(double(q)) * x[0]);
87 }
88 }
89
90 // See dev documentation: forward_unary_op
91 template <class Base>
92 void forward_log_op_0(
93 size_t i_z ,
94 size_t i_x ,
95 size_t cap_order ,
96 Base* taylor )
97 {
98
99 // check assumptions
100 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
101 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
102 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
103
104 // Taylor coefficients corresponding to argument and result
105 Base* x = taylor + i_x * cap_order;
106 Base* z = taylor + i_z * cap_order;
107
108 z[0] = log( x[0] );
109 }
110
111
112 // See dev documentation: reverse_unary_op
113 template <class Base>
114 void reverse_log_op(
115 size_t d ,
116 size_t i_z ,
117 size_t i_x ,
118 size_t cap_order ,
119 const Base* taylor ,
120 size_t nc_partial ,
121 Base* partial )
122 { size_t j, k;
123
124 // check assumptions
125 CPPAD_ASSERT_UNKNOWN( NumArg(LogOp) == 1 );
126 CPPAD_ASSERT_UNKNOWN( NumRes(LogOp) == 1 );
127 CPPAD_ASSERT_UNKNOWN( d < cap_order );
128 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
129
130 // Taylor coefficients and partials corresponding to argument
131 const Base* x = taylor + i_x * cap_order;
132 Base* px = partial + i_x * nc_partial;
133
134 // Taylor coefficients and partials corresponding to result
135 const Base* z = taylor + i_z * cap_order;
136 Base* pz = partial + i_z * nc_partial;
137
138 Base inv_x0 = Base(1.0) / x[0];
139
140 j = d;
141 while(j)
142 { // scale partial w.r.t z[j]
143 pz[j] = azmul(pz[j] , inv_x0);
144
145 px[0] -= azmul(pz[j], z[j]);
146 px[j] += pz[j];
147
148 // further scale partial w.r.t. z[j]
149 pz[j] /= Base(double(j));
150
151 for(k = 1; k < j; k++)
152 { pz[k] -= Base(double(k)) * azmul(pz[j], x[j-k]);
153 px[j-k] -= Base(double(k)) * azmul(pz[j], z[k]);
154 }
155 --j;
156 }
157 px[0] += azmul(pz[0], inv_x0);
158 }
159
160 } } // END_CPPAD_LOCAL_NAMESPACE
161 # endif
0 # ifndef CPPAD_LOCAL_OP_MUL_OP_HPP
1 # define CPPAD_LOCAL_OP_MUL_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15
16 // --------------------------- Mulvv -----------------------------------------
17
18 // See dev documentation: forward_binary_op
19 template <class Base>
20 void forward_mulvv_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 const addr_t* arg ,
25 const Base* parameter ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to arguments and result
36 Base* x = taylor + size_t(arg[0]) * cap_order;
37 Base* y = taylor + size_t(arg[1]) * cap_order;
38 Base* z = taylor + i_z * cap_order;
39
40 size_t k;
41 for(size_t d = p; d <= q; d++)
42 { z[d] = Base(0.0);
43 for(k = 0; k <= d; k++)
44 z[d] += x[d-k] * y[k];
45 }
46 }
47
48 // See dev documentation: forward_binary_op
49 template <class Base>
50 void forward_mulvv_op_dir(
51 size_t q ,
52 size_t r ,
53 size_t i_z ,
54 const addr_t* arg ,
55 const Base* parameter ,
56 size_t cap_order ,
57 Base* taylor )
58 {
59 // check assumptions
60 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
61 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
62 CPPAD_ASSERT_UNKNOWN( 0 < q );
63 CPPAD_ASSERT_UNKNOWN( q < cap_order );
64
65 // Taylor coefficients corresponding to arguments and result
66 size_t num_taylor_per_var = (cap_order-1) * r + 1;
67 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
68 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
69 Base* z = taylor + i_z * num_taylor_per_var;
70
71 size_t k, ell, m;
72 for(ell = 0; ell < r; ell++)
73 { m = (q-1)*r + ell + 1;
74 z[m] = x[0] * y[m] + x[m] * y[0];
75 for(k = 1; k < q; k++)
76 z[m] += x[(q-k-1)*r + ell + 1] * y[(k-1)*r + ell + 1];
77 }
78 }
79
80
81 // See dev documentation: forward_binary_op
82 template <class Base>
83 void forward_mulvv_op_0(
84 size_t i_z ,
85 const addr_t* arg ,
86 const Base* parameter ,
87 size_t cap_order ,
88 Base* taylor )
89 {
90 // check assumptions
91 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
92 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
93
94 // Taylor coefficients corresponding to arguments and result
95 Base* x = taylor + size_t(arg[0]) * cap_order;
96 Base* y = taylor + size_t(arg[1]) * cap_order;
97 Base* z = taylor + i_z * cap_order;
98
99 z[0] = x[0] * y[0];
100 }
101
102
103 // See dev documentation: reverse_binary_op
104 template <class Base>
105 void reverse_mulvv_op(
106 size_t d ,
107 size_t i_z ,
108 const addr_t* arg ,
109 const Base* parameter ,
110 size_t cap_order ,
111 const Base* taylor ,
112 size_t nc_partial ,
113 Base* partial )
114 {
115 // check assumptions
116 CPPAD_ASSERT_UNKNOWN( NumArg(MulvvOp) == 2 );
117 CPPAD_ASSERT_UNKNOWN( NumRes(MulvvOp) == 1 );
118 CPPAD_ASSERT_UNKNOWN( d < cap_order );
119 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
120
121 // Arguments
122 const Base* x = taylor + size_t(arg[0]) * cap_order;
123 const Base* y = taylor + size_t(arg[1]) * cap_order;
124
125 // Partial derivatives corresponding to arguments and result
126 Base* px = partial + size_t(arg[0]) * nc_partial;
127 Base* py = partial + size_t(arg[1]) * nc_partial;
128 Base* pz = partial + i_z * nc_partial;
129
130
131 // number of indices to access
132 size_t j = d + 1;
133 size_t k;
134 while(j)
135 { --j;
136 for(k = 0; k <= j; k++)
137 {
138 px[j-k] += azmul(pz[j], y[k]);
139 py[k] += azmul(pz[j], x[j-k]);
140 }
141 }
142 }
143 // --------------------------- Mulpv -----------------------------------------
144
145 // See dev documentation: forward_binary_op
146 template <class Base>
147 void forward_mulpv_op(
148 size_t p ,
149 size_t q ,
150 size_t i_z ,
151 const addr_t* arg ,
152 const Base* parameter ,
153 size_t cap_order ,
154 Base* taylor )
155 {
156 // check assumptions
157 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
158 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
159 CPPAD_ASSERT_UNKNOWN( q < cap_order );
160 CPPAD_ASSERT_UNKNOWN( p <= q );
161
162 // Taylor coefficients corresponding to arguments and result
163 Base* y = taylor + size_t(arg[1]) * cap_order;
164 Base* z = taylor + i_z * cap_order;
165
166 // Paraemter value
167 Base x = parameter[ arg[0] ];
168
169 for(size_t d = p; d <= q; d++)
170 z[d] = x * y[d];
171 }
172
173 // See dev documentation: forward_binary_op
174 template <class Base>
175 void forward_mulpv_op_dir(
176 size_t q ,
177 size_t r ,
178 size_t i_z ,
179 const addr_t* arg ,
180 const Base* parameter ,
181 size_t cap_order ,
182 Base* taylor )
183 {
184 // check assumptions
185 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
186 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
187 CPPAD_ASSERT_UNKNOWN( 0 < q );
188 CPPAD_ASSERT_UNKNOWN( q < cap_order );
189
190 // Taylor coefficients corresponding to arguments and result
191 size_t num_taylor_per_var = (cap_order-1) * r + 1;
192 size_t m = (q-1) * r + 1;
193 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
194 Base* z = taylor + i_z * num_taylor_per_var + m;
195
196 // Paraemter value
197 Base x = parameter[ arg[0] ];
198
199 for(size_t ell = 0; ell < r; ell++)
200 z[ell] = x * y[ell];
201 }
202
203 // See dev documentation: forward_binary_op
204 template <class Base>
205 void forward_mulpv_op_0(
206 size_t i_z ,
207 const addr_t* arg ,
208 const Base* parameter ,
209 size_t cap_order ,
210 Base* taylor )
211 {
212 // check assumptions
213 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
214 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
215
216 // Paraemter value
217 Base x = parameter[ arg[0] ];
218
219 // Taylor coefficients corresponding to arguments and result
220 Base* y = taylor + size_t(arg[1]) * cap_order;
221 Base* z = taylor + i_z * cap_order;
222
223 z[0] = x * y[0];
224 }
225
226
227 // See dev documentation: reverse_binary_op
228 template <class Base>
229 void reverse_mulpv_op(
230 size_t d ,
231 size_t i_z ,
232 const addr_t* arg ,
233 const Base* parameter ,
234 size_t cap_order ,
235 const Base* taylor ,
236 size_t nc_partial ,
237 Base* partial )
238 {
239 // check assumptions
240 CPPAD_ASSERT_UNKNOWN( NumArg(MulpvOp) == 2 );
241 CPPAD_ASSERT_UNKNOWN( NumRes(MulpvOp) == 1 );
242 CPPAD_ASSERT_UNKNOWN( d < cap_order );
243 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
244
245 // Arguments
246 Base x = parameter[ arg[0] ];
247
248 // Partial derivatives corresponding to arguments and result
249 Base* py = partial + size_t(arg[1]) * nc_partial;
250 Base* pz = partial + i_z * nc_partial;
251
252 // number of indices to access
253 size_t j = d + 1;
254 while(j)
255 { --j;
256 py[j] += azmul(pz[j], x);
257 }
258 }
259
260
261 } } // END_CPPAD_LOCAL_NAMESPACE
262 # endif
0 # ifndef CPPAD_LOCAL_OP_NEG_OP_HPP
1 # define CPPAD_LOCAL_OP_NEG_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 template <class Base>
16
17 // See forward_unary1_op in developer documentation
18 void forward_neg_op(
19 size_t p ,
20 size_t q ,
21 size_t i_z ,
22 size_t i_x ,
23 size_t cap_order ,
24 Base* taylor )
25 {
26 // check assumptions
27 CPPAD_ASSERT_NARG_NRES( NegOp, 1, 1 );
28 CPPAD_ASSERT_UNKNOWN( q < cap_order );
29 CPPAD_ASSERT_UNKNOWN( p <= q );
30
31 // Taylor coefficients corresponding to argument and result
32 Base* x = taylor + i_x * cap_order;
33 Base* z = taylor + i_z * cap_order;
34
35 for(size_t k = p; k <= q; k++)
36 z[k] = - x[k];
37 }
38
39 // See forward_unary1_op_dir in developer documentation
40 // See dev documentation: forward_unary_op
41 template <class Base>
42 void forward_neg_op_dir(
43 size_t q ,
44 size_t r ,
45 size_t i_z ,
46 size_t i_x ,
47 size_t cap_order ,
48 Base* taylor )
49 {
50
51 // check assumptions
52 CPPAD_ASSERT_NARG_NRES( NegOp, 1, 1 );
53 CPPAD_ASSERT_UNKNOWN( 0 < q );
54 CPPAD_ASSERT_UNKNOWN( q < cap_order );
55
56 // Taylor coefficients corresponding to argument and result
57 size_t num_taylor_per_var = (cap_order-1) * r + 1;
58 Base* x = taylor + i_x * num_taylor_per_var;
59 Base* z = taylor + i_z * num_taylor_per_var;
60
61 size_t m = (q-1) * r + 1;
62 for(size_t ell = 0; ell < r; ell++)
63 z[m+ell] = - x[m+ell];
64 }
65
66 // See forward_unary1_op_0 in developer documentation
67 // See dev documentation: forward_unary_op
68 template <class Base>
69 void forward_neg_op_0(
70 size_t i_z ,
71 size_t i_x ,
72 size_t cap_order ,
73 Base* taylor )
74 {
75
76 // check assumptions
77 CPPAD_ASSERT_NARG_NRES( NegOp, 1, 1 );
78 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
79
80 // Taylor coefficients corresponding to argument and result
81 Base* x = taylor + i_x * cap_order;
82 Base* z = taylor + i_z * cap_order;
83
84 z[0] = - x[0];
85 }
86
87 // See reverse_unary1_op in developer documentation
88 // See dev documentation: reverse_unary_op
89 template <class Base>
90 void reverse_neg_op(
91 size_t d ,
92 size_t i_z ,
93 size_t i_x ,
94 size_t cap_order ,
95 const Base* taylor ,
96 size_t nc_partial ,
97 Base* partial )
98 {
99 // check assumptions
100 CPPAD_ASSERT_NARG_NRES( NegOp, 1, 1 );
101 CPPAD_ASSERT_UNKNOWN( d < cap_order );
102 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
103
104 // Taylor coefficients and partials corresponding to argument
105 Base* px = partial + i_x * nc_partial;
106
107 // Taylor coefficients and partials corresponding to result
108 Base* pz = partial + i_z * nc_partial;
109
110 Base neg_one = Base(-1.0);
111 for(size_t k = 0; k <= d; ++k)
112 px[k] += azmul(pz[k], neg_one);
113
114 }
115
116 } } // END_CPPAD_LOCAL_NAMESPACE
117 # endif
0 # ifndef CPPAD_LOCAL_OP_PARAMETER_OP_HPP
1 # define CPPAD_LOCAL_OP_PARAMETER_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_par_op_0(
21 size_t i_z ,
22 const addr_t* arg ,
23 size_t num_par ,
24 const Base* parameter ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(ParOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(ParOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par );
32 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
33
34 Base* z = taylor + i_z * cap_order;
35
36 z[0] = parameter[ arg[0] ];
37 }
38
39 } } // END_CPPAD_LOCAL_NAMESPACE
40 # endif
0 # ifndef CPPAD_LOCAL_OP_POW_OP_HPP
1 # define CPPAD_LOCAL_OP_POW_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file pow_op.hpp
17 Forward and reverse mode calculations for z = pow(x, y).
18 */
19
20 // --------------------------- Powvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = PowvvOp.
23
24 In the documentation below,
25 this operations is for the case where both x and y are variables
26 and the argument parameter is not used.
27
28 \copydetails CppAD::local::forward_pow_op
29 */
30
31 template <class Base>
32 void forward_powvv_op(
33 size_t p ,
34 size_t q ,
35 size_t i_z ,
36 const addr_t* arg ,
37 const Base* parameter ,
38 size_t cap_order ,
39 Base* taylor )
40 {
41 // convert from final result to first result
42 i_z -= 2; // 2 = NumRes(PowvvOp) - 1;
43
44 // check assumptions
45 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
46 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
47 CPPAD_ASSERT_UNKNOWN( q < cap_order );
48 CPPAD_ASSERT_UNKNOWN( p <= q );
49 CPPAD_ASSERT_UNKNOWN(
50 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
51 );
52
53 // z_0 = log(x)
54 forward_log_op(p, q, i_z, size_t(arg[0]), cap_order, taylor);
55
56 // z_1 = z_0 * y
57 addr_t adr[2];
58 adr[0] = addr_t( i_z );
59 adr[1] = arg[1];
60 forward_mulvv_op(p, q, i_z+1, adr, parameter, cap_order, taylor);
61
62 // z_2 = exp(z_1)
63 // final result for zero order case is exactly the same as for Base
64 if( p == 0 )
65 { // Taylor coefficients corresponding to arguments and result
66 Base* x = taylor + size_t(arg[0]) * cap_order;
67 Base* y = taylor + size_t(arg[1]) * cap_order;
68 Base* z_2 = taylor + (i_z+2) * cap_order;
69
70 z_2[0] = pow(x[0], y[0]);
71 p++;
72 }
73 if( p <= q )
74 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
75 }
76 /*!
77 Multiple directions forward mode Taylor coefficients for op = PowvvOp.
78
79 The C++ source code corresponding to this operation is
80 \verbatim
81 z = pow(x, y)
82 \endverbatim
83 In the documentation below,
84 this operations is for the case where x is a variable and y is a parameter.
85
86 \copydetails CppAD::local::forward_pow_op_dir
87 */
88
89 template <class Base>
90 void forward_powvv_op_dir(
91 size_t q ,
92 size_t r ,
93 size_t i_z ,
94 const addr_t* arg ,
95 const Base* parameter ,
96 size_t cap_order ,
97 Base* taylor )
98 {
99 // convert from final result to first result
100 i_z -= 2; // 2 = NumRes(PowvvOp) - 1
101
102 // check assumptions
103 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
104 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
105 CPPAD_ASSERT_UNKNOWN( 0 < q );
106 CPPAD_ASSERT_UNKNOWN( q < cap_order );
107 CPPAD_ASSERT_UNKNOWN(
108 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
109 );
110
111 // z_0 = log(x)
112 forward_log_op_dir(q, r, i_z, size_t(arg[0]), cap_order, taylor);
113
114 // z_1 = y * z_0
115 addr_t adr[2];
116 adr[0] = addr_t( i_z );
117 adr[1] = arg[1];
118 forward_mulvv_op_dir(q, r, i_z+1, adr, parameter, cap_order, taylor);
119
120 // z_2 = exp(z_1)
121 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
122 }
123 /*!
124 Compute zero order forward mode Taylor coefficients for result of op = PowvvOp.
125
126 The C++ source code corresponding to this operation is
127 \verbatim
128 z = pow(x, y)
129 \endverbatim
130 In the documentation below,
131 this operations is for the case where both x and y are variables
132 and the argument parameter is not used.
133
134 \copydetails CppAD::local::forward_pow_op_0
135 */
136
137 template <class Base>
138 void forward_powvv_op_0(
139 size_t i_z ,
140 const addr_t* arg ,
141 const Base* parameter ,
142 size_t cap_order ,
143 Base* taylor )
144 {
145 // convert from final result to first result
146 i_z -= 2; // NumRes(PowvvOp) - 1;
147
148 // check assumptions
149 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
150 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
151
152 // Taylor coefficients corresponding to arguments and result
153 Base* x = taylor + size_t(arg[0]) * cap_order;
154 Base* y = taylor + size_t(arg[1]) * cap_order;
155 Base* z_0 = taylor + i_z * cap_order;
156 Base* z_1 = z_0 + cap_order;
157 Base* z_2 = z_1 + cap_order;
158
159 z_0[0] = log( x[0] );
160 z_1[0] = z_0[0] * y[0];
161 z_2[0] = pow(x[0], y[0]);
162
163 }
164
165 /*!
166 Compute reverse mode partial derivatives for result of op = PowvvOp.
167
168 The C++ source code corresponding to this operation is
169 \verbatim
170 z = pow(x, y)
171 \endverbatim
172 In the documentation below,
173 this operations is for the case where both x and y are variables
174 and the argument parameter is not used.
175
176 \copydetails CppAD::local::reverse_pow_op
177 */
178
179 template <class Base>
180 void reverse_powvv_op(
181 size_t d ,
182 size_t i_z ,
183 const addr_t* arg ,
184 const Base* parameter ,
185 size_t cap_order ,
186 const Base* taylor ,
187 size_t nc_partial ,
188 Base* partial )
189 {
190 // convert from final result to first result
191 i_z -= 2; // NumRes(PowvvOp) - 1;
192
193 // check assumptions
194 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
195 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
196 CPPAD_ASSERT_UNKNOWN( d < cap_order );
197 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
198 CPPAD_ASSERT_UNKNOWN(
199 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
200 );
201
202 // z_2 = exp(z_1)
203 reverse_exp_op(
204 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
205 );
206
207 // z_1 = z_0 * y
208 addr_t adr[2];
209 adr[0] = addr_t( i_z );
210 adr[1] = arg[1];
211 reverse_mulvv_op(
212 d, i_z+1, adr, parameter, cap_order, taylor, nc_partial, partial
213 );
214
215 // z_0 = log(x)
216 reverse_log_op(
217 d, i_z, size_t(arg[0]), cap_order, taylor, nc_partial, partial
218 );
219 }
220
221 // --------------------------- Powpv -----------------------------------------
222 /*!
223 Compute forward mode Taylor coefficients for result of op = PowpvOp.
224
225 The C++ source code corresponding to this operation is
226 \verbatim
227 z = pow(x, y)
228 \endverbatim
229 In the documentation below,
230 this operations is for the case where x is a parameter and y is a variable.
231
232 \copydetails CppAD::local::forward_pow_op
233 */
234
235 template <class Base>
236 void forward_powpv_op(
237 size_t p ,
238 size_t q ,
239 size_t i_z ,
240 const addr_t* arg ,
241 const Base* parameter ,
242 size_t cap_order ,
243 Base* taylor )
244 {
245 // convert from final result to first result
246 i_z -= 2; // 2 = NumRes(PowpvOp) - 1;
247
248 // check assumptions
249 CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 );
250 CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 );
251 CPPAD_ASSERT_UNKNOWN( q < cap_order );
252 CPPAD_ASSERT_UNKNOWN( p <= q );
253
254 // Taylor coefficients corresponding to arguments and result
255 Base* z_0 = taylor + i_z * cap_order;
256
257 // z_0 = log(x)
258 Base x = parameter[ arg[0] ];
259 size_t d;
260 for(d = p; d <= q; d++)
261 { if( d == 0 )
262 z_0[d] = log(x);
263 else
264 z_0[d] = Base(0.0);
265 }
266
267 // 2DO: remove requirement that i_z * cap_order <= max addr_t value
268 CPPAD_ASSERT_KNOWN(
269 size_t( std::numeric_limits<addr_t>::max() ) >= i_z * cap_order,
270 "cppad_tape_addr_type maximum value has been exceeded\n"
271 "This is due to a kludge in the pow operation and should be fixed."
272 );
273
274 // z_1 = z_0 * y
275 addr_t adr[2];
276 // offset of z_i in taylor (as if it were a parameter); i.e., log(x)
277 adr[0] = addr_t( i_z * cap_order );
278 // offset of y in taylor (as a variable)
279 adr[1] = arg[1];
280
281 // Trick: use taylor both for the parameter vector and variable values
282 forward_mulpv_op(p, q, i_z+1, adr, taylor, cap_order, taylor);
283
284 // z_2 = exp(z_1)
285 // zero order case exactly same as Base type operation
286 if( p == 0 )
287 { Base* y = taylor + size_t(arg[1]) * cap_order;
288 Base* z_2 = taylor + (i_z+2) * cap_order;
289 z_2[0] = pow(x, y[0]);
290 p++;
291 }
292 if( p <= q )
293 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
294 }
295 /*!
296 Multiple directions forward mode Taylor coefficients for op = PowpvOp.
297
298 The C++ source code corresponding to this operation is
299 \verbatim
300 z = pow(x, y)
301 \endverbatim
302 In the documentation below,
303 this operations is for the case where x is a parameter and y is a variable.
304
305 \copydetails CppAD::local::forward_pow_op_dir
306 */
307
308 template <class Base>
309 void forward_powpv_op_dir(
310 size_t q ,
311 size_t r ,
312 size_t i_z ,
313 const addr_t* arg ,
314 const Base* parameter ,
315 size_t cap_order ,
316 Base* taylor )
317 {
318 // convert from final result to first result
319 i_z -= 2; // 2 = NumRes(PowpvOp) - 1;
320
321 // check assumptions
322 CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 );
323 CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 );
324 CPPAD_ASSERT_UNKNOWN( 0 < q );
325 CPPAD_ASSERT_UNKNOWN( q < cap_order );
326
327 // Taylor coefficients corresponding to arguments and result
328 size_t num_taylor_per_var = (cap_order-1) * r + 1;
329 Base* z_0 = taylor + i_z * num_taylor_per_var;
330
331 // z_0 = log(x)
332 size_t m = (q-1) * r + 1;
333 for(size_t ell = 0; ell < r; ell++)
334 z_0[m+ell] = Base(0.0);
335
336 // 2DO: remove requirement i_z * num_taylor_per_var <= max addr_t value
337 CPPAD_ASSERT_KNOWN(
338 size_t( std::numeric_limits<addr_t>::max() ) >= i_z * num_taylor_per_var,
339 "cppad_tape_addr_type maximum value has been exceeded\n"
340 "This is due to a kludge in the pow operation and should be fixed."
341 );
342
343 // z_1 = z_0 * y
344 addr_t adr[2];
345 // offset of z_0 in taylor (as if it were a parameter); i.e., log(x)
346 adr[0] = addr_t( i_z * num_taylor_per_var );
347 // ofset of y in taylor (as a variable)
348 adr[1] = arg[1];
349
350 // Trick: use taylor both for the parameter vector and variable values
351 forward_mulpv_op_dir(q, r, i_z+1, adr, taylor, cap_order, taylor);
352
353 // z_2 = exp(z_1)
354 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
355 }
356 /*!
357 Compute zero order forward mode Taylor coefficient for result of op = PowpvOp.
358
359 The C++ source code corresponding to this operation is
360 \verbatim
361 z = pow(x, y)
362 \endverbatim
363 In the documentation below,
364 this operations is for the case where x is a parameter and y is a variable.
365
366 \copydetails CppAD::local::forward_pow_op_0
367 */
368
369 template <class Base>
370 void forward_powpv_op_0(
371 size_t i_z ,
372 const addr_t* arg ,
373 const Base* parameter ,
374 size_t cap_order ,
375 Base* taylor )
376 {
377 // convert from final result to first result
378 i_z -= 2; // NumRes(PowpvOp) - 1;
379
380 // check assumptions
381 CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 );
382 CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 );
383
384 // Paraemter value
385 Base x = parameter[ arg[0] ];
386
387 // Taylor coefficients corresponding to arguments and result
388 Base* y = taylor + size_t(arg[1]) * cap_order;
389 Base* z_0 = taylor + i_z * cap_order;
390 Base* z_1 = z_0 + cap_order;
391 Base* z_2 = z_1 + cap_order;
392
393 // z_0 = log(x)
394 z_0[0] = log(x);
395
396 // z_1 = z_0 * y
397 z_1[0] = z_0[0] * y[0];
398
399 // z_2 = exp(z_1)
400 // zero order case exactly same as Base type operation
401 z_2[0] = pow(x, y[0]);
402 }
403
404 /*!
405 Compute reverse mode partial derivative for result of op = PowpvOp.
406
407 The C++ source code corresponding to this operation is
408 \verbatim
409 z = pow(x, y)
410 \endverbatim
411 In the documentation below,
412 this operations is for the case where x is a parameter and y is a variable.
413
414 \copydetails CppAD::local::reverse_pow_op
415 */
416
417 template <class Base>
418 void reverse_powpv_op(
419 size_t d ,
420 size_t i_z ,
421 const addr_t* arg ,
422 const Base* parameter ,
423 size_t cap_order ,
424 const Base* taylor ,
425 size_t nc_partial ,
426 Base* partial )
427 {
428 // convert from final result to first result
429 i_z -= 2; // NumRes(PowpvOp) - 1;
430
431 // check assumptions
432 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
433 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
434 CPPAD_ASSERT_UNKNOWN( d < cap_order );
435 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
436
437 // z_2 = exp(z_1)
438 reverse_exp_op(
439 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
440 );
441
442 // 2DO: remove requirement that i_z * cap_order <= max addr_t value
443 CPPAD_ASSERT_KNOWN(
444 size_t( std::numeric_limits<addr_t>::max() ) >= i_z * cap_order,
445 "cppad_tape_addr_type maximum value has been exceeded\n"
446 "This is due to a kludge in the pow operation and should be fixed."
447 );
448
449 // z_1 = z_0 * y
450 addr_t adr[2];
451 adr[0] = addr_t( i_z * cap_order ); // offset of z_0[0] in taylor
452 adr[1] = arg[1]; // index of y in taylor and partial
453 // use taylor both for parameter and variable values
454 reverse_mulpv_op(
455 d, i_z+1, adr, taylor, cap_order, taylor, nc_partial, partial
456 );
457
458 // z_0 = log(x)
459 // x is a parameter
460 }
461
462 // --------------------------- Powvp -----------------------------------------
463 /*!
464 Compute forward mode Taylor coefficients for result of op = PowvpOp.
465
466 The C++ source code corresponding to this operation is
467 \verbatim
468 z = pow(x, y)
469 \endverbatim
470 In the documentation below,
471 this operations is for the case where x is a variable and y is a parameter.
472
473 \copydetails CppAD::local::forward_pow_op
474 */
475
476 template <class Base>
477 void forward_powvp_op(
478 size_t p ,
479 size_t q ,
480 size_t i_z ,
481 const addr_t* arg ,
482 const Base* parameter ,
483 size_t cap_order ,
484 Base* taylor )
485 {
486 // check assumptions
487 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
488 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 1 );
489 CPPAD_ASSERT_UNKNOWN( q < cap_order );
490 CPPAD_ASSERT_UNKNOWN( p <= q );
491 CPPAD_ASSERT_UNKNOWN(
492 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
493 );
494
495 // Taylor coefficients corresponding to arguments and result
496 Base* x = taylor + size_t(arg[0]) * cap_order;
497 Base* z = taylor + i_z * cap_order;
498
499 // Paraemter value
500 Base y = parameter[ arg[1] ];
501
502 // Special solution when x[0] is zero
503 Base b0 = Base( 0.0 );
504
505 // special case zero order
506 if( p == 0 )
507 { z[0] = pow(x[0], y);
508 p++;
509 }
510 for(size_t j = p; j <= q; ++j)
511 { Base sum = Base(0);
512 for(size_t k = 1; k < j; ++k)
513 { Base bk = Base( double(k) );
514 sum += bk * (y * x[k] * z[j-k] - z[k] * x[j-k]);
515 }
516 Base bj = Base( double(j) );
517 Base zj = ( y * z[0] * x[j] + sum / bj ) / x[0];
518 z[j] = CondExpEq(x[0], b0, b0, zj);
519 }
520 }
521 /*!
522 Multiple directions forward mode Taylor coefficients for op = PowvpOp.
523
524 The C++ source code corresponding to this operation is
525 \verbatim
526 z = pow(x, y)
527 \endverbatim
528 In the documentation below,
529 this operations is for the case where x is a variable and y is a parameter.
530
531 \copydetails CppAD::local::forward_pow_op_dir
532 */
533
534 template <class Base>
535 void forward_powvp_op_dir(
536 size_t q ,
537 size_t r ,
538 size_t i_z ,
539 const addr_t* arg ,
540 const Base* parameter ,
541 size_t cap_order ,
542 Base* taylor )
543 {
544 // check assumptions
545 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
546 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 1 );
547 CPPAD_ASSERT_UNKNOWN( 0 < q );
548 CPPAD_ASSERT_UNKNOWN( q < cap_order );
549 CPPAD_ASSERT_UNKNOWN(
550 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
551 );
552
553 // Taylor coefficients corresponding to arguments and result
554 size_t num_taylor_per_var = (cap_order-1) * r + 1;
555 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
556 Base* z = taylor + i_z * num_taylor_per_var;
557
558 // Parameter value
559 Base y = parameter[ arg[1] ];
560
561 // special solution when x[0] is zero
562 Base b0 = Base( 0.0 );
563
564 // index in Taylor coefficients where multiple directions start
565 size_t m = (q-1)*r + 1;
566 //
567 // loop over directions
568 for(size_t ell = 0; ell < r; ell++)
569 { Base sum = Base(0);
570 for(size_t k = 1; k < q; ++k)
571 { Base xk = x[(k-1)*r + ell + 1];
572 Base zk = z[(k-1)*r + ell + 1];
573 Base xqk = x[(q-k-1)*r + ell + 1];
574 Base zqk = z[(q-k-1)*r + ell + 1];
575 Base bk = Base( double(k) );
576 sum += bk * (y * xk * zqk - zk * xqk);
577 }
578 Base xq = x[(q-1)*r + ell + 1];
579 Base bq = Base( double(q) );
580 Base zell = ( y * z[0] * xq + sum / bq ) / x[0];
581 z[m+ell] = CondExpEq(x[0], b0, b0, zell);
582 }
583 }
584
585 /*!
586 Compute zero order forward mode Taylor coefficients for result of op = PowvpOp.
587
588 The C++ source code corresponding to this operation is
589 \verbatim
590 z = pow(x, y)
591 \endverbatim
592 In the documentation below,
593 this operations is for the case where x is a variable and y is a parameter.
594
595 \copydetails CppAD::local::forward_pow_op_0
596 */
597
598 template <class Base>
599 void forward_powvp_op_0(
600 size_t i_z ,
601 const addr_t* arg ,
602 const Base* parameter ,
603 size_t cap_order ,
604 Base* taylor )
605 {
606 // check assumptions
607 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
608 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 1 );
609
610 // Paraemter value
611 Base y = parameter[ arg[1] ];
612
613 // Taylor coefficients corresponding to arguments and result
614 Base* x = taylor + size_t(arg[0]) * cap_order;
615 Base* z = taylor + i_z * cap_order;
616
617 z[0] = pow(x[0], y);
618 }
619
620 /*!
621 Compute reverse mode partial derivative for result of op = PowvpOp.
622
623 The C++ source code corresponding to this operation is
624 \verbatim
625 z = pow(x, y)
626 \endverbatim
627 In the documentation below,
628 this operations is for the case where x is a variable and y is a parameter.
629
630 \copydetails CppAD::local::reverse_pow_op
631 */
632
633 template <class Base>
634 void reverse_powvp_op(
635 size_t d ,
636 size_t i_z ,
637 const addr_t* arg ,
638 const Base* parameter ,
639 size_t cap_order ,
640 const Base* taylor ,
641 size_t nc_partial ,
642 Base* partial ,
643 CppAD::vector<Base>& work )
644 {
645 // check assumptions
646 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
647 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 1 );
648 CPPAD_ASSERT_UNKNOWN( d < cap_order );
649 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
650 CPPAD_ASSERT_UNKNOWN(
651 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
652 );
653
654 // Taylor coefficients
655 const Base* x = taylor + size_t( arg[0] ) * cap_order;
656 const Base* z = taylor + i_z * cap_order;
657
658 // parameter value
659 const Base y = parameter[ arg[1] ];
660
661 // Partial derivatives corresponding to arguments and result
662 Base* px = partial + size_t(arg[0]) * nc_partial;
663 Base* pz = partial + i_z * nc_partial;
664
665 // Special solution when x[0] is zero
666 Base b0 = Base( 0.0 );
667
668 // Place to hold px for this operator until conditional assigment at end
669 work.resize(nc_partial);
670 for(size_t j = 0; j <= d; ++j)
671 work[j] = px[j];
672
673 // reverse z^j for j = d, ..., 1
674 size_t j = d;
675 while(j)
676 { // j
677 Base bj = Base( double(j) );
678 //
679 // x^j term
680 work[j] += azmul(pz[j], y * z[0] / x[0]);
681 //
682 // x^k terms
683 for(size_t k = 1; k < j; ++k)
684 { Base bk = Base( double(k) );
685 Base term = (bk * y - Base(j-k) ) * z[j-k] / (bj * x[0]);
686 work[k] += azmul(pz[j], term);
687 }
688 //
689 // z^k terms
690 for(size_t k = 1; k < j; ++k)
691 { Base bk = Base( double(k) );
692 Base term = (Base(j-k) * y - bk) * x[j-k] / (bj * x[0]);
693 pz[k] += azmul(pz[j], term);
694 }
695 //
696 // x^0 term
697 work[0] -= azmul(pz[j], z[j] / x[0]);
698 //
699 // z^0 term
700 pz[0] += azmul(pz[j], y * x[j] / x[0] );
701 //
702 // next j
703 --j;
704 }
705 // reverse z^0
706 work[0] += azmul(pz[0], y * z[0] / x[0]);
707 //
708 for(j = 0; j <=d; ++j)
709 px[j] = CondExpEq(x[0], b0, b0, work[j]);
710 }
711
712 } } // END_CPPAD_LOCAL_NAMESPACE
713 # endif
0 # ifndef CPPAD_LOCAL_OP_PRINT_OP_HPP
1 # define CPPAD_LOCAL_OP_PRINT_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 Print operation for parameters; i.e., op = PriOp.
18
19 The C++ source code corresponding to this operation is
20 \verbatim
21 f.Forward(0, x)
22 PrintFor(before, var)
23 PrintFor(pos, before, var, after)
24 \endverbatim
25 The PrintFor call puts the print operation on the tape
26 and the print occurs during the zero order forward mode computation.
27
28 \tparam Base
29 base type for the operator; i.e., this operation was recorded
30 using AD< Base > and computations by this routine are done using type
31 Base .
32
33 \param s_out
34 the results are printed on this output stream.
35
36 \param arg
37 arg[0] & 1
38 \n
39 If this is zero, pos is a parameter. Otherwise it is a variable.
40 \n
41 arg[0] & 2
42 \n
43 If this is zero, var is a parameter. Otherwise it is a variable.
44 \n
45 \n
46 arg[1]
47 \n
48 If pos is a parameter, <code>parameter[arg[1]]</code> is its value.
49 Othwise <code>taylor[ size_t(arg[1]) * cap_order + 0 ]</code> is the zero
50 order Taylor coefficient for pos.
51 \n
52 \n
53 arg[2]
54 \n
55 index of the text to be printed before var
56 if pos is not a positive value.
57 \n
58 \n
59 arg[3]
60 \n
61 If var is a parameter, <code>parameter[arg[3]]</code> is its value.
62 Othwise <code>taylor[ size_t(arg[3]) * cap_order + 0 ]</code> is the zero
63 order Taylor coefficient for var.
64 \n
65 \n
66 arg[4]
67 \n
68 index of the text to be printed after var
69 if pos is not a positive value.
70
71 \param num_text
72 is the total number of text characters on the tape
73 (only used for error checking).
74
75 \param text
76 \b Input: <code>text[arg[1]]</code> is the first character of the text
77 that will be printed. All the characters from there to (but not including)
78 the first '\\0' are printed.
79
80 \param num_par
81 is the total number of values in the parameter vector
82
83 \param parameter
84 Contains the value of parameters.
85
86 \param cap_order
87 number of colums in the matrix containing all the Taylor coefficients.
88
89 \param taylor
90 Contains the value of variables.
91
92 \par Checked Assertions:
93 \li NumArg(PriOp) == 5
94 \li NumRes(PriOp) == 0
95 \li text != nullptr
96 \li arg[1] < num_text
97 \li if pos is a parameter, arg[1] < num_par
98 \li if var is a parameter, arg[3] < num_par
99 */
100 template <class Base>
101 void forward_pri_0(
102 std::ostream& s_out ,
103 const addr_t* arg ,
104 size_t num_text ,
105 const char* text ,
106 size_t num_par ,
107 const Base* parameter ,
108 size_t cap_order ,
109 const Base* taylor )
110 { Base pos, var;
111 const char* before;
112 const char* after;
113 CPPAD_ASSERT_NARG_NRES(PriOp, 5, 0);
114
115 // pos
116 if( arg[0] & 1 )
117 { pos = taylor[ size_t(arg[1]) * cap_order + 0 ];
118 }
119 else
120 { CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
121 pos = parameter[ arg[1] ];
122 }
123
124 // before
125 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text );
126 before = text + arg[2];
127
128 // var
129 if( arg[0] & 2 )
130 { var = taylor[ size_t(arg[3]) * cap_order + 0 ];
131 }
132 else
133 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
134 var = parameter[ arg[3] ];
135 }
136
137 // after
138 CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text );
139 after = text + arg[4];
140
141 if( ! GreaterThanZero( pos ) )
142 s_out << before << var << after;
143 }
144
145 } } // END_CPPAD_LOCAL_NAMESPACE
146 # endif
0 # ifndef CPPAD_LOCAL_OP_PROTOTYPE_OP_HPP
1 # define CPPAD_LOCAL_OP_PROTOTYPE_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file prototype_op.hpp
18 Documentation for generic cases (these generic cases are never used).
19 */
20
21 // ==================== Unary operators with one result ====================
22
23
24 /*!
25 Prototype for forward mode unary operator with one result (not used).
26
27 \tparam Base
28 base type for the operator; i.e., this operation was recorded
29 using AD< Base > and computations by this routine are done using type
30 Base.
31
32 \param p
33 lowest order of the Taylor coefficient that we are computing.
34
35 \param q
36 highest order of the Taylor coefficient that we are computing.
37
38 \param i_z
39 variable index corresponding to the result for this operation;
40 i.e. the row index in taylor corresponding to z.
41
42 \param i_x
43 variable index corresponding to the argument for this operator;
44 i.e. the row index in taylor corresponding to x.
45
46 \param cap_order
47 maximum number of orders that will fit in the taylor array.
48
49 \param taylor
50 \b Input: <code>taylor [ i_x * cap_order + k ]</code>,
51 for k = 0 , ... , q,
52 is the k-th order Taylor coefficient corresponding to x.
53 \n
54 \b Input: <code>taylor [ i_z * cap_order + k ]</code>,
55 for k = 0 , ... , p-1,
56 is the k-th order Taylor coefficient corresponding to z.
57 \n
58 \b Output: <code>taylor [ i_z * cap_order + k ]</code>,
59 for k = p , ... , q,
60 is the k-th order Taylor coefficient corresponding to z.
61
62 \par Checked Assertions
63 \li NumArg(op) == 1
64 \li NumRes(op) == 1
65 \li q < cap_order
66 \li p <= q
67 */
68 template <class Base>
69 void forward_unary1_op(
70 size_t p ,
71 size_t q ,
72 size_t i_z ,
73 size_t i_x ,
74 size_t cap_order ,
75 Base* taylor )
76 {
77 // This routine is only for documentaiton, it should not be used
78 CPPAD_ASSERT_UNKNOWN( false );
79 }
80
81 /*!
82 Prototype for multiple direction forward mode unary operator with one result
83 (not used).
84
85 \tparam Base
86 base type for the operator; i.e., this operation was recorded
87 using AD< Base > and computations by this routine are done using type
88 Base.
89
90 \param q
91 order of the Taylor coefficients that we are computing.
92
93 \param r
94 number of directions for Taylor coefficients that we are computing.
95
96 \param i_z
97 variable index corresponding to the last (primary) result for this operation;
98 i.e. the row index in taylor corresponding to z.
99
100 \param i_x
101 variable index corresponding to the argument for this operator;
102 i.e. the row index in taylor corresponding to x.
103
104 \param cap_order
105 maximum number of orders that will fit in the taylor array.
106
107 \par tpv
108 We use the notation
109 <code>tpv = (cap_order-1) * r + 1</code>
110 which is the number of Taylor coefficients per variable
111
112 \param taylor
113 \b Input: If x is a variable,
114 <code>taylor [ arg[0] * tpv + 0 ]</code>,
115 is the zero order Taylor coefficient for all directions and
116 <code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
117 for k = 1 , ... , q,
118 ell = 0, ..., r-1,
119 is the k-th order Taylor coefficient
120 corresponding to x and the ell-th direction.
121 \n
122 \b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
123 is the zero order Taylor coefficient for all directions and
124 <code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
125 for k = 1 , ... , q-1,
126 ell = 0, ..., r-1,
127 is the k-th order Taylor coefficient
128 corresponding to z and the ell-th direction.
129 \n
130 \b Output:
131 <code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
132 ell = 0, ..., r-1,
133 is the q-th order Taylor coefficient
134 corresponding to z and the ell-th direction.
135
136 \par Checked Assertions
137 \li NumArg(op) == 1
138 \li NumRes(op) == 2
139 \li i_x < i_z
140 \li 0 < q
141 \li q < cap_order
142 */
143 template <class Base>
144 void forward_unary1_op_dir(
145 size_t q ,
146 size_t r ,
147 size_t i_z ,
148 size_t i_x ,
149 size_t cap_order ,
150 Base* taylor )
151 {
152 // This routine is only for documentaiton, it should not be used
153 CPPAD_ASSERT_UNKNOWN( false );
154 }
155
156 /*!
157 Prototype for zero order forward mode unary operator with one result (not used).
158 \tparam Base
159 base type for the operator; i.e., this operation was recorded
160 using AD< Base > and computations by this routine are done using type
161 Base .
162
163 \param i_z
164 variable index corresponding to the result for this operation;
165 i.e. the row index in taylor corresponding to z.
166
167 \param i_x
168 variable index corresponding to the argument for this operator;
169 i.e. the row index in taylor corresponding to x.
170
171 \param cap_order
172 maximum number of orders that will fit in the taylor array.
173
174 \param taylor
175 \b Input: taylor [ i_x * cap_order + 0 ]
176 is the zero order Taylor coefficient corresponding to x.
177 \n
178 \b Output: taylor [ i_z * cap_order + 0 ]
179 is the zero order Taylor coefficient corresponding to z.
180
181 \par Checked Assertions
182 \li NumArg(op) == 1
183 \li NumRes(op) == 1
184 \li i_x < i_z
185 \li 0 < cap_order
186 */
187 template <class Base>
188 void forward_unary1_op_0(
189 size_t i_z ,
190 size_t i_x ,
191 size_t cap_order ,
192 Base* taylor )
193 {
194 // This routine is only for documentaiton, it should not be used
195 CPPAD_ASSERT_UNKNOWN( false );
196 }
197
198 /*!
199 Prototype for reverse mode unary operator with one result (not used).
200
201 This routine is given the partial derivatives of a function
202 G(z , x , w, u ... )
203 and it uses them to compute the partial derivatives of
204 \verbatim
205 H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ]
206 \endverbatim
207
208 \tparam Base
209 base type for the operator; i.e., this operation was recorded
210 using AD< Base > and computations by this routine are done using type
211 Base .
212
213 \param d
214 highest order Taylor coefficient that
215 we are computing the partial derivatives with respect to.
216
217 \param i_z
218 variable index corresponding to the result for this operation;
219 i.e. the row index in taylor to z.
220
221 \param i_x
222 variable index corresponding to the argument for this operation;
223 i.e. the row index in taylor corresponding to x.
224
225 \param cap_order
226 maximum number of orders that will fit in the taylor array.
227
228 \param taylor
229 taylor [ i_x * cap_order + k ]
230 for k = 0 , ... , d
231 is the k-th order Taylor coefficient corresponding to x.
232 \n
233 taylor [ i_z * cap_order + k ]
234 for k = 0 , ... , d
235 is the k-th order Taylor coefficient corresponding to z.
236
237 \param nc_partial
238 number of colums in the matrix containing all the partial derivatives.
239
240 \param partial
241 \b Input: partial [ i_x * nc_partial + k ]
242 for k = 0 , ... , d
243 is the partial derivative of G( z , x , w , u , ... ) with respect to
244 the k-th order Taylor coefficient for x.
245 \n
246 \b Input: partial [ i_z * nc_partial + k ]
247 for k = 0 , ... , d
248 is the partial derivative of G( z , x , w , u , ... ) with respect to
249 the k-th order Taylor coefficient for z.
250 \n
251 \b Output: partial [ i_x * nc_partial + k ]
252 for k = 0 , ... , d
253 is the partial derivative of H( x , w , u , ... ) with respect to
254 the k-th order Taylor coefficient for x.
255 \n
256 \b Output: partial [ i_z * nc_partial + k ]
257 for k = 0 , ... , d
258 may be used as work space; i.e., may change in an unspecified manner.
259
260
261 \par Checked Assumptions
262 \li NumArg(op) == 1
263 \li NumRes(op) == 1
264 \li i_x < i_z
265 \li d < cap_order
266 \li d < nc_partial
267 */
268 template <class Base>
269 void reverse_unary1_op(
270 size_t d ,
271 size_t i_z ,
272 size_t i_x ,
273 size_t cap_order ,
274 const Base* taylor ,
275 size_t nc_partial ,
276 Base* partial )
277 {
278 // This routine is only for documentaiton, it should not be used
279 CPPAD_ASSERT_UNKNOWN( false );
280 }
281
282 // ==================== Unary operators with two results ====================
283
284 /*!
285 Prototype for forward mode unary operator with two results (not used).
286
287 \tparam Base
288 base type for the operator; i.e., this operation was recorded
289 using AD< Base > and computations by this routine are done using type
290 Base.
291
292 \param p
293 lowest order of the Taylor coefficients that we are computing.
294
295 \param q
296 highest order of the Taylor coefficients that we are computing.
297
298 \param i_z
299 variable index corresponding to the last (primary) result for this operation;
300 i.e. the row index in taylor corresponding to z.
301 The auxillary result is called y has index i_z - 1.
302
303 \param i_x
304 variable index corresponding to the argument for this operator;
305 i.e. the row index in taylor corresponding to x.
306
307 \param cap_order
308 maximum number of orders that will fit in the taylor array.
309
310 \param taylor
311 \b Input: <code>taylor [ i_x * cap_order + k ]</code>
312 for k = 0 , ... , q,
313 is the k-th order Taylor coefficient corresponding to x.
314 \n
315 \b Input: <code>taylor [ i_z * cap_order + k ]</code>
316 for k = 0 , ... , p - 1,
317 is the k-th order Taylor coefficient corresponding to z.
318 \n
319 \b Input: <code>taylor [ ( i_z - 1) * cap_order + k ]</code>
320 for k = 0 , ... , p-1,
321 is the k-th order Taylor coefficient corresponding to the auxillary result y.
322 \n
323 \b Output: <code>taylor [ i_z * cap_order + k ]</code>,
324 for k = p , ... , q,
325 is the k-th order Taylor coefficient corresponding to z.
326 \n
327 \b Output: <code>taylor [ ( i_z - 1 ) * cap_order + k ]</code>,
328 for k = p , ... , q,
329 is the k-th order Taylor coefficient corresponding to
330 the autillary result y.
331
332 \par Checked Assertions
333 \li NumArg(op) == 1
334 \li NumRes(op) == 2
335 \li i_x + 1 < i_z
336 \li q < cap_order
337 \li p <= q
338 */
339 template <class Base>
340 void forward_unary2_op(
341 size_t p ,
342 size_t q ,
343 size_t i_z ,
344 size_t i_x ,
345 size_t cap_order ,
346 Base* taylor )
347 {
348 // This routine is only for documentaiton, it should not be used
349 CPPAD_ASSERT_UNKNOWN( false );
350 }
351
352 /*!
353 Prototype for multiple direction forward mode unary operator with two results
354 (not used).
355
356 \tparam Base
357 base type for the operator; i.e., this operation was recorded
358 using AD< Base > and computations by this routine are done using type
359 Base.
360
361 \param q
362 order of the Taylor coefficients that we are computing.
363
364 \param r
365 number of directions for Taylor coefficients that we are computing.
366
367 \param i_z
368 variable index corresponding to the last (primary) result for this operation;
369 i.e. the row index in taylor corresponding to z.
370 The auxillary result is called y has index i_z - 1.
371
372 \param i_x
373 variable index corresponding to the argument for this operator;
374 i.e. the row index in taylor corresponding to x.
375
376 \param cap_order
377 maximum number of orders that will fit in the taylor array.
378
379 \par tpv
380 We use the notation
381 <code>tpv = (cap_order-1) * r + 1</code>
382 which is the number of Taylor coefficients per variable
383
384 \param taylor
385 \b Input: <code>taylor [ i_x * tpv + 0 ]</code>
386 is the zero order Taylor coefficient for all directions and
387 <code>taylor [ i_x * tpv + (k-1)*r + ell + 1</code>
388 for k = 1 , ... , q,
389 ell = 0 , ..., r-1,
390 is the k-th order Taylor coefficient
391 corresponding to x and the ell-th direction.
392 \n
393 \b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
394 is the zero order Taylor coefficient for all directions and
395 <code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
396 for k = 1 , ... , q-1,
397 ell = 0, ..., r-1,
398 is the k-th order Taylor coefficient
399 corresponding to z and the ell-th direction.
400 \n
401 \b Input: <code>taylor [ (i_z-1) * tpv + 0 ]</code>,
402 is the zero order Taylor coefficient for all directions and
403 <code>taylor [ (i_z-1) * tpv + (k-1)*r + ell + 1 ]</code>,
404 for k = 1 , ... , q-1,
405 ell = 0, ..., r-1,
406 is the k-th order Taylor coefficient
407 corresponding to the auxillary result y and the ell-th direction.
408 \n
409 \b Output:
410 <code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
411 ell = 0, ..., r-1,
412 is the q-th order Taylor coefficient
413 corresponding to z and the ell-th direction.
414
415 \par Checked Assertions
416 \li NumArg(op) == 1
417 \li NumRes(op) == 2
418 \li i_x + 1 < i_z
419 \li 0 < q
420 \li q < cap_order
421 */
422 template <class Base>
423 void forward_unary2_op_dir(
424 size_t q ,
425 size_t r ,
426 size_t i_z ,
427 size_t i_x ,
428 size_t cap_order ,
429 Base* taylor )
430 {
431 // This routine is only for documentaiton, it should not be used
432 CPPAD_ASSERT_UNKNOWN( false );
433 }
434
435 /*!
436 Prototype for zero order forward mode unary operator with two results (not used).
437 \tparam Base
438 base type for the operator; i.e., this operation was recorded
439 using AD< Base > and computations by this routine are done using type
440 Base .
441
442 \param i_z
443 variable index corresponding to the last (primary) result for this operation;
444 i.e. the row index in taylor corresponding to z.
445 The auxillary result is called y and has index i_z - 1.
446
447 \param i_x
448 variable index corresponding to the argument for this operator;
449 i.e. the row index in taylor corresponding to x.
450
451 \param cap_order
452 maximum number of orders that will fit in the taylor array.
453
454 \param taylor
455 \b Input: taylor [ i_x * cap_order + 0 ]
456 is the zero order Taylor coefficient corresponding to x.
457 \n
458 \b Output: taylor [ i_z * cap_order + 0 ]
459 is the zero order Taylor coefficient corresponding to z.
460 \n
461 \b Output: taylor [ ( i_z - 1 ) * cap_order + j ]
462 is the j-th order Taylor coefficient corresponding to
463 the autillary result y.
464
465 \par Checked Assertions
466 \li NumArg(op) == 1
467 \li NumRes(op) == 2
468 \li i_x + 1 < i_z
469 \li j < cap_order
470 */
471 template <class Base>
472 void forward_unary2_op_0(
473 size_t i_z ,
474 size_t i_x ,
475 size_t cap_order ,
476 Base* taylor )
477 {
478 // This routine is only for documentaiton, it should not be used
479 CPPAD_ASSERT_UNKNOWN( false );
480 }
481
482 /*!
483 Prototype for reverse mode unary operator with two results (not used).
484
485 This routine is given the partial derivatives of a function
486 G( z , y , x , w , ... )
487 and it uses them to compute the partial derivatives of
488 \verbatim
489 H( x , w , u , ... ) = G[ z(x) , y(x), x , w , u , ... ]
490 \endverbatim
491
492 \tparam Base
493 base type for the operator; i.e., this operation was recorded
494 using AD< Base > and computations by this routine are done using type
495 Base .
496
497 \param d
498 highest order Taylor coefficient that
499 we are computing the partial derivatives with respect to.
500
501 \param i_z
502 variable index corresponding to the last (primary) result for this operation;
503 i.e. the row index in taylor to z.
504 The auxillary result is called y and has index i_z - 1.
505
506 \param i_x
507 variable index corresponding to the argument for this operation;
508 i.e. the row index in taylor corresponding to x.
509
510 \param cap_order
511 maximum number of orders that will fit in the taylor array.
512
513 \param taylor
514 taylor [ i_x * cap_order + k ]
515 for k = 0 , ... , d
516 is the k-th order Taylor coefficient corresponding to x.
517 \n
518 taylor [ i_z * cap_order + k ]
519 for k = 0 , ... , d
520 is the k-th order Taylor coefficient corresponding to z.
521 \n
522 taylor [ ( i_z - 1) * cap_order + k ]
523 for k = 0 , ... , d
524 is the k-th order Taylor coefficient corresponding to
525 the auxillary variable y.
526
527 \param nc_partial
528 number of colums in the matrix containing all the partial derivatives.
529
530 \param partial
531 \b Input: partial [ i_x * nc_partial + k ]
532 for k = 0 , ... , d
533 is the partial derivative of
534 G( z , y , x , w , u , ... )
535 with respect to the k-th order Taylor coefficient for x.
536 \n
537 \b Input: partial [ i_z * nc_partial + k ]
538 for k = 0 , ... , d
539 is the partial derivative of G( z , y , x , w , u , ... ) with respect to
540 the k-th order Taylor coefficient for z.
541 \n
542 \b Input: partial [ ( i_z - 1) * nc_partial + k ]
543 for k = 0 , ... , d
544 is the partial derivative of G( z , x , w , u , ... ) with respect to
545 the k-th order Taylor coefficient for the auxillary variable y.
546 \n
547 \b Output: partial [ i_x * nc_partial + k ]
548 for k = 0 , ... , d
549 is the partial derivative of H( x , w , u , ... ) with respect to
550 the k-th order Taylor coefficient for x.
551 \n
552 \b Output: partial [ ( i_z - j ) * nc_partial + k ]
553 for j = 0 , 1 , and for k = 0 , ... , d
554 may be used as work space; i.e., may change in an unspecified manner.
555
556
557 \par Checked Assumptions
558 \li NumArg(op) == 1
559 \li NumRes(op) == 2
560 \li i_x + 1 < i_z
561 \li d < cap_order
562 \li d < nc_partial
563 */
564 template <class Base>
565 void reverse_unary2_op(
566 size_t d ,
567 size_t i_z ,
568 size_t i_x ,
569 size_t cap_order ,
570 const Base* taylor ,
571 size_t nc_partial ,
572 Base* partial )
573 {
574 // This routine is only for documentaiton, it should not be used
575 CPPAD_ASSERT_UNKNOWN( false );
576 }
577 // =================== Binary operators with one result ====================
578
579 /*!
580 Prototype forward mode x op y (not used)
581
582 \tparam Base
583 base type for the operator; i.e., this operation was recorded
584 using AD< Base > and computations by this routine are done using type
585 Base.
586
587 \param p
588 lowest order of the Taylor coefficient that we are computing.
589
590 \param q
591 highest order of the Taylor coefficient that we are computing.
592
593 \param i_z
594 variable index corresponding to the result for this operation;
595 i.e. the row index in taylor corresponding to z.
596
597 \param arg
598 arg[0]
599 index corresponding to the left operand for this operator;
600 i.e. the index corresponding to x.
601 \n
602 arg[1]
603 index corresponding to the right operand for this operator;
604 i.e. the index corresponding to y.
605
606 \param parameter
607 If x is a parameter, parameter [ arg[0] ]
608 is the value corresponding to x.
609 \n
610 If y is a parameter, parameter [ arg[1] ]
611 is the value corresponding to y.
612
613 \param cap_order
614 maximum number of orders that will fit in the taylor array.
615
616 \param taylor
617 \b Input: If x is a variable,
618 <code>taylor [ size_t(arg[0]) * cap_order + k ]</code>,
619 for k = 0 , ... , q,
620 is the k-th order Taylor coefficient corresponding to x.
621 \n
622 \b Input: If y is a variable,
623 <code>taylor [ size_t(arg[1]) * cap_order + k ]</code>,
624 for k = 0 , ... , q,
625 is the k-th order Taylor coefficient corresponding to y.
626 \n
627 \b Input: <code>taylor [ i_z * cap_order + k ]</code>,
628 for k = 0 , ... , p-1,
629 is the k-th order Taylor coefficient corresponding to z.
630 \n
631 \b Output: <code>taylor [ i_z * cap_order + k ]</code>,
632 for k = p, ... , q,
633 is the k-th order Taylor coefficient corresponding to z.
634
635 \par Checked Assertions
636 \li NumArg(op) == 2
637 \li NumRes(op) == 1
638 \li q < cap_order
639 \li p <= q
640 */
641 template <class Base>
642 void forward_binary_op(
643 size_t p ,
644 size_t q ,
645 size_t i_z ,
646 const addr_t* arg ,
647 const Base* parameter ,
648 size_t cap_order ,
649 Base* taylor )
650 {
651 // This routine is only for documentaiton, it should not be used
652 CPPAD_ASSERT_UNKNOWN( false );
653 }
654
655 /*!
656 Prototype multiple direction forward mode x op y (not used)
657
658 \tparam Base
659 base type for the operator; i.e., this operation was recorded
660 using AD< Base > and computations by this routine are done using type
661 Base.
662
663 \param q
664 is the order of the Taylor coefficients that we are computing.
665
666 \param r
667 number of directions for Taylor coefficients that we are computing
668
669 \param i_z
670 variable index corresponding to the result for this operation;
671 i.e. the row index in taylor corresponding to z.
672
673 \param arg
674 arg[0]
675 index corresponding to the left operand for this operator;
676 i.e. the index corresponding to x.
677 \n
678 arg[1]
679 index corresponding to the right operand for this operator;
680 i.e. the index corresponding to y.
681
682 \param parameter
683 If x is a parameter, parameter [ arg[0] ]
684 is the value corresponding to x.
685 \n
686 If y is a parameter, parameter [ arg[1] ]
687 is the value corresponding to y.
688
689 \param cap_order
690 maximum number of orders that will fit in the taylor array.
691
692 \par tpv
693 We use the notation
694 <code>tpv = (cap_order-1) * r + 1</code>
695 which is the number of Taylor coefficients per variable
696
697 \param taylor
698 \b Input: If x is a variable,
699 <code>taylor [ arg[0] * tpv + 0 ]</code>,
700 is the zero order Taylor coefficient for all directions and
701 <code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
702 for k = 1 , ... , q,
703 ell = 0, ..., r-1,
704 is the k-th order Taylor coefficient
705 corresponding to x and the ell-th direction.
706 \n
707 \b Input: If y is a variable,
708 <code>taylor [ arg[1] * tpv + 0 ]</code>,
709 is the zero order Taylor coefficient for all directions and
710 <code>taylor [ arg[1] * tpv + (k-1)*r + ell + 1 ]</code>,
711 for k = 1 , ... , q,
712 ell = 0, ..., r-1,
713 is the k-th order Taylor coefficient
714 corresponding to y and the ell-th direction.
715 \n
716 \b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
717 is the zero order Taylor coefficient for all directions and
718 <code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
719 for k = 1 , ... , q-1,
720 ell = 0, ..., r-1,
721 is the k-th order Taylor coefficient
722 corresponding to z and the ell-th direction.
723 \n
724 \b Output:
725 <code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
726 ell = 0, ..., r-1,
727 is the q-th order Taylor coefficient
728 corresponding to z and the ell-th direction.
729
730 \par Checked Assertions
731 \li NumArg(op) == 2
732 \li NumRes(op) == 1
733 \li 0 < q < cap_order
734 */
735 template <class Base>
736 void forward_binary_op_dir(
737 size_t q ,
738 size_t r ,
739 size_t i_z ,
740 const addr_t* arg ,
741 const Base* parameter ,
742 size_t cap_order ,
743 Base* taylor )
744 {
745 // This routine is only for documentaiton, it should not be used
746 CPPAD_ASSERT_UNKNOWN( false );
747 }
748
749
750 /*!
751 Prototype zero order forward mode x op y (not used)
752
753 \tparam Base
754 base type for the operator; i.e., this operation was recorded
755 using AD< Base > and computations by this routine are done using type
756 Base.
757
758 \param i_z
759 variable index corresponding to the result for this operation;
760 i.e. the row index in taylor corresponding to z.
761
762 \param arg
763 arg[0]
764 index corresponding to the left operand for this operator;
765 i.e. the index corresponding to x.
766 \n
767 arg[1]
768 index corresponding to the right operand for this operator;
769 i.e. the index corresponding to y.
770
771 \param parameter
772 If x is a parameter, parameter [ arg[0] ]
773 is the value corresponding to x.
774 \n
775 If y is a parameter, parameter [ arg[1] ]
776 is the value corresponding to y.
777
778 \param cap_order
779 maximum number of orders that will fit in the taylor array.
780
781 \param taylor
782 \b Input: If x is a variable, taylor [ arg[0] * cap_order + 0 ]
783 is the zero order Taylor coefficient corresponding to x.
784 \n
785 \b Input: If y is a variable, taylor [ arg[1] * cap_order + 0 ]
786 is the zero order Taylor coefficient corresponding to y.
787 \n
788 \b Output: taylor [ i_z * cap_order + 0 ]
789 is the zero order Taylor coefficient corresponding to z.
790
791 \par Checked Assertions
792 \li NumArg(op) == 2
793 \li NumRes(op) == 1
794 */
795 template <class Base>
796 void forward_binary_op_0(
797 size_t i_z ,
798 const addr_t* arg ,
799 const Base* parameter ,
800 size_t cap_order ,
801 Base* taylor )
802 {
803 // This routine is only for documentaiton, it should not be used
804 CPPAD_ASSERT_UNKNOWN( false );
805 }
806
807 /*!
808 Prototype for reverse mode binary operator x op y (not used).
809
810 This routine is given the partial derivatives of a function
811 G( z , y , x , w , ... )
812 and it uses them to compute the partial derivatives of
813 \verbatim
814 H( y , x , w , u , ... ) = G[ z(x , y) , y , x , w , u , ... ]
815 \endverbatim
816
817 \tparam Base
818 base type for the operator; i.e., this operation was recorded
819 using AD< Base > and computations by this routine are done using type
820 Base .
821
822 \param d
823 highest order Taylor coefficient that
824 we are computing the partial derivatives with respect to.
825
826 \param i_z
827 variable index corresponding to the result for this operation;
828 i.e. the row index in taylor corresponding to z.
829
830 \param arg
831 arg[0]
832 index corresponding to the left operand for this operator;
833 i.e. the index corresponding to x.
834 \n
835 arg[1]
836 index corresponding to the right operand for this operator;
837 i.e. the index corresponding to y.
838
839 \param parameter
840 If x is a parameter, parameter [ arg[0] ]
841 is the value corresponding to x.
842 \n
843 If y is a parameter, parameter [ arg[1] ]
844 is the value corresponding to y.
845
846 \param cap_order
847 maximum number of orders that will fit in the taylor array.
848
849 \param taylor
850 taylor [ i_z * cap_order + k ]
851 for k = 0 , ... , d
852 is the k-th order Taylor coefficient corresponding to z.
853 \n
854 If x is a variable, taylor [ arg[0] * cap_order + k ]
855 for k = 0 , ... , d
856 is the k-th order Taylor coefficient corresponding to x.
857 \n
858 If y is a variable, taylor [ arg[1] * cap_order + k ]
859 for k = 0 , ... , d
860 is the k-th order Taylor coefficient corresponding to y.
861
862 \param nc_partial
863 number of colums in the matrix containing all the partial derivatives.
864
865 \param partial
866 \b Input: partial [ i_z * nc_partial + k ]
867 for k = 0 , ... , d
868 is the partial derivative of
869 G( z , y , x , w , u , ... )
870 with respect to the k-th order Taylor coefficient for z.
871 \n
872 \b Input: If x is a variable, partial [ arg[0] * nc_partial + k ]
873 for k = 0 , ... , d
874 is the partial derivative of G( z , y , x , w , u , ... ) with respect to
875 the k-th order Taylor coefficient for x.
876 \n
877 \b Input: If y is a variable, partial [ arg[1] * nc_partial + k ]
878 for k = 0 , ... , d
879 is the partial derivative of G( z , x , w , u , ... ) with respect to
880 the k-th order Taylor coefficient for the auxillary variable y.
881 \n
882 \b Output: If x is a variable, partial [ arg[0] * nc_partial + k ]
883 for k = 0 , ... , d
884 is the partial derivative of H( y , x , w , u , ... ) with respect to
885 the k-th order Taylor coefficient for x.
886 \n
887 \b Output: If y is a variable, partial [ arg[1] * nc_partial + k ]
888 for k = 0 , ... , d
889 is the partial derivative of H( y , x , w , u , ... ) with respect to
890 the k-th order Taylor coefficient for y.
891 \n
892 \b Output: partial [ i_z * nc_partial + k ]
893 for k = 0 , ... , d
894 may be used as work space; i.e., may change in an unspecified manner.
895
896 \par Checked Assumptions
897 \li NumArg(op) == 2
898 \li NumRes(op) == 1
899 \li If x is a variable, arg[0] < i_z
900 \li If y is a variable, arg[1] < i_z
901 \li d < cap_order
902 \li d < nc_partial
903 */
904 template <class Base>
905 void reverse_binary_op(
906 size_t d ,
907 size_t i_z ,
908 addr_t* arg ,
909 const Base* parameter ,
910 size_t cap_order ,
911 const Base* taylor ,
912 size_t nc_partial ,
913 Base* partial )
914 {
915 // This routine is only for documentaiton, it should not be used
916 CPPAD_ASSERT_UNKNOWN( false );
917 }
918 // ======================= Pow Function ===================================
919 /*!
920 Prototype for forward mode z = pow(x, y) (not used).
921
922 \tparam Base
923 base type for the operator; i.e., this operation was recorded
924 using AD< Base > and computations by this routine are done using type
925 Base.
926
927 \param p
928 lowest order of the Taylor coefficient that we are computing.
929
930 \param q
931 highest order of the Taylor coefficient that we are computing.
932
933 \param i_z
934 variable index corresponding to the last (primary) result for this operation;
935 i.e. the row index in taylor corresponding to z.
936 Note that there are three results for this operation,
937 below they are referred to as z_0, z_1, z_2 and correspond to
938 \verbatim
939 z_0 = log(x)
940 z_1 = z0 * y
941 z_2 = exp(z1)
942 \endverbatim
943 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
944
945 \param arg
946 arg[0]
947 index corresponding to the left operand for this operator;
948 i.e. the index corresponding to x.
949 \n
950 arg[1]
951 index corresponding to the right operand for this operator;
952 i.e. the index corresponding to y.
953
954 \param parameter
955 If x is a parameter, parameter [ arg[0] ]
956 is the value corresponding to x.
957 \n
958 If y is a parameter, parameter [ arg[1] ]
959 is the value corresponding to y.
960
961 \param cap_order
962 maximum number of orders that will fit in the taylor array.
963
964 \param taylor
965 \b Input: If x is a variable,
966 <code>taylor [ size_t(arg[0]) * cap_order + k ]</code>
967 for k = 0 , ... , q,
968 is the k-th order Taylor coefficient corresponding to x.
969 \n
970 \b Input: If y is a variable,
971 <code>taylor [ size_t(arg[1]) * cap_order + k ]</code>
972 for k = 0 , ... , q
973 is the k-th order Taylor coefficient corresponding to y.
974 \n
975 \b Input: <code>taylor [ (i_z-2+j) * cap_order + k ]</code>,
976 for j = 0, 1, 2 , for k = 0 , ... , p-1,
977 is the k-th order Taylor coefficient corresponding to z_j.
978 \n
979 \b Output: <code>taylor [ (i_z-2+j) * cap_order + k ]</code>,
980 is the k-th order Taylor coefficient corresponding to z_j.
981
982 \par Checked Assertions
983 \li NumArg(op) == 2
984 \li NumRes(op) == 3
985 \li If x is a variable, arg[0] < i_z - 2
986 \li If y is a variable, arg[1] < i_z - 2
987 \li q < cap_order
988 \li p <= q
989 */
990 template <class Base>
991 void forward_pow_op(
992 size_t p ,
993 size_t q ,
994 size_t i_z ,
995 const addr_t* arg ,
996 const Base* parameter ,
997 size_t cap_order ,
998 Base* taylor )
999 {
1000 // This routine is only for documentaiton, it should not be used
1001 CPPAD_ASSERT_UNKNOWN( false );
1002 }
1003 /*!
1004 Prototype for multiple direction forward mode z = pow(x, y) (not used).
1005
1006 \tparam Base
1007 base type for the operator; i.e., this operation was recorded
1008 using AD< Base > and computations by this routine are done using type
1009 Base.
1010
1011 \param q
1012 order of the Taylor coefficient that we are computing.
1013
1014 \param r
1015 is the number of Taylor coefficient directions that we are computing
1016
1017 \param i_z
1018 variable index corresponding to the last (primary) result for this operation;
1019 i.e. the row index in taylor corresponding to z.
1020 Note that there are three results for this operation,
1021 below they are referred to as z_0, z_1, z_2 and correspond to
1022 \verbatim
1023 z_0 = log(x)
1024 z_1 = z0 * y
1025 z_2 = exp(z1)
1026 \endverbatim
1027 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1028
1029 \param arg
1030 arg[0]
1031 index corresponding to the left operand for this operator;
1032 i.e. the index corresponding to x.
1033 \n
1034 arg[1]
1035 index corresponding to the right operand for this operator;
1036 i.e. the index corresponding to y.
1037
1038 \param parameter
1039 If x is a parameter, parameter [ arg[0] ]
1040 is the value corresponding to x.
1041 \n
1042 If y is a parameter, parameter [ arg[1] ]
1043 is the value corresponding to y.
1044
1045 \param cap_order
1046 maximum number of orders that will fit in the taylor array.
1047
1048 \par tpv
1049 We use the notation
1050 <code>tpv = (cap_order-1) * r + 1</code>
1051 which is the number of Taylor coefficients per variable
1052
1053 \param taylor
1054 \b Input: If x is a variable,
1055 <code>taylor [ arg[0] * tpv + 0 ]</code>
1056 is the zero order coefficient corresponding to x and
1057 <code>taylor [ arg[0] * tpv + (k-1)*r+1+ell ]</code>
1058 for k = 1 , ... , q,
1059 ell = 0 , ... , r-1,
1060 is the k-th order Taylor coefficient corresponding to x
1061 for the ell-th direction.
1062 \n
1063 \n
1064 \b Input: If y is a variable,
1065 <code>taylor [ arg[1] * tpv + 0 ]</code>
1066 is the zero order coefficient corresponding to y and
1067 <code>taylor [ arg[1] * tpv + (k-1)*r+1+ell ]</code>
1068 for k = 1 , ... , q,
1069 ell = 0 , ... , r-1,
1070 is the k-th order Taylor coefficient corresponding to y
1071 for the ell-th direction.
1072 \n
1073 \n
1074 \b Input:
1075 <code>taylor [ (i_z-2+j) * tpv + 0 ]</code>,
1076 is the zero order coefficient corresponding to z_j and
1077 <code>taylor [ (i_z-2+j) * tpv + (k-1)*r+1+ell ]</code>,
1078 for j = 0, 1, 2 , k = 0 , ... , q-1, ell = 0, ... , r-1,
1079 is the k-th order Taylor coefficient corresponding to z_j
1080 for the ell-th direction.
1081 \n
1082 \n
1083 \b Output:
1084 <code>taylor [ (i_z-2+j) * tpv + (q-1)*r+1+ell ]</code>,
1085 for j = 0, 1, 2 , ell = 0, ... , r-1,
1086 is the q-th order Taylor coefficient corresponding to z_j
1087 for the ell-th direction.
1088
1089 \par Checked Assertions
1090 \li NumArg(op) == 2
1091 \li NumRes(op) == 3
1092 \li If x is a variable, arg[0] < i_z - 2
1093 \li If y is a variable, arg[1] < i_z - 2
1094 \li 0 < q
1095 \li q < cap_order
1096 */
1097 template <class Base>
1098 void forward_pow_op_dir(
1099 size_t q ,
1100 size_t r ,
1101 size_t i_z ,
1102 const addr_t* arg ,
1103 const Base* parameter ,
1104 size_t cap_order ,
1105 Base* taylor )
1106 {
1107 // This routine is only for documentaiton, it should not be used
1108 CPPAD_ASSERT_UNKNOWN( false );
1109 }
1110 /*!
1111 Prototype for zero order forward mode z = pow(x, y) (not used).
1112
1113 \tparam Base
1114 base type for the operator; i.e., this operation was recorded
1115 using AD< Base > and computations by this routine are done using type
1116 Base.
1117
1118 \param i_z
1119 variable index corresponding to the last (primary) result for this operation;
1120 i.e. the row index in taylor corresponding to z.
1121 Note that there are three results for this operation,
1122 below they are referred to as z_0, z_1, z_2 and correspond to
1123 \verbatim
1124 z_0 = log(x)
1125 z_1 = z0 * y
1126 z_2 = exp(z1)
1127 \endverbatim
1128 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1129
1130 \param arg
1131 arg[0]
1132 index corresponding to the left operand for this operator;
1133 i.e. the index corresponding to x.
1134 \n
1135 arg[1]
1136 index corresponding to the right operand for this operator;
1137 i.e. the index corresponding to y.
1138
1139 \param parameter
1140 If x is a parameter, parameter [ arg[0] ]
1141 is the value corresponding to x.
1142 \n
1143 If y is a parameter, parameter [ arg[1] ]
1144 is the value corresponding to y.
1145
1146 \param cap_order
1147 maximum number of orders that will fit in the taylor array.
1148
1149 \param taylor
1150 \b Input: If x is a variable, taylor [ arg[0] * cap_order + 0 ]
1151 is the zero order Taylor coefficient corresponding to x.
1152 \n
1153 \b Input: If y is a variable, taylor [ arg[1] * cap_order + 0 ]
1154 is the k-th order Taylor coefficient corresponding to y.
1155 \n
1156 \b Output: taylor [ (i_z - 2 + j) * cap_order + 0 ]
1157 is the zero order Taylor coefficient corresponding to z_j.
1158
1159 \par Checked Assertions
1160 \li NumArg(op) == 2
1161 \li NumRes(op) == 3
1162 \li If x is a variable, arg[0] < i_z - 2
1163 \li If y is a variable, arg[1] < i_z - 2
1164 */
1165 template <class Base>
1166 void forward_pow_op_0(
1167 size_t i_z ,
1168 const addr_t* arg ,
1169 const Base* parameter ,
1170 size_t cap_order ,
1171 Base* taylor )
1172 {
1173 // This routine is only for documentaiton, it should not be used
1174 CPPAD_ASSERT_UNKNOWN( false );
1175 }
1176 /*!
1177 Prototype for reverse mode z = pow(x, y) (not used).
1178
1179 This routine is given the partial derivatives of a function
1180 G( z , y , x , w , ... )
1181 and it uses them to compute the partial derivatives of
1182 \verbatim
1183 H( y , x , w , u , ... ) = G[ pow(x , y) , y , x , w , u , ... ]
1184 \endverbatim
1185
1186 \tparam Base
1187 base type for the operator; i.e., this operation was recorded
1188 using AD< Base > and computations by this routine are done using type
1189 Base .
1190
1191 \param d
1192 highest order Taylor coefficient that
1193 we are computing the partial derivatives with respect to.
1194
1195 \param i_z
1196 variable index corresponding to the last (primary) result for this operation;
1197 i.e. the row index in taylor corresponding to z.
1198 Note that there are three results for this operation,
1199 below they are referred to as z_0, z_1, z_2 and correspond to
1200 \verbatim
1201 z_0 = log(x)
1202 z_1 = z0 * y
1203 z_2 = exp(z1)
1204 \endverbatim
1205 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1206
1207 \param arg
1208 arg[0]
1209 index corresponding to the left operand for this operator;
1210 i.e. the index corresponding to x.
1211 \n
1212 arg[1]
1213 index corresponding to the right operand for this operator;
1214 i.e. the index corresponding to y.
1215
1216 \param parameter
1217 If x is a parameter, parameter [ arg[0] ]
1218 is the value corresponding to x.
1219 \n
1220 If y is a parameter, parameter [ arg[1] ]
1221 is the value corresponding to y.
1222
1223 \param cap_order
1224 maximum number of orders that will fit in the taylor array.
1225
1226 \param taylor
1227 taylor [ (i_z - 2 + j) * cap_order + k ]
1228 for j = 0, 1, 2 and k = 0 , ... , d
1229 is the k-th order Taylor coefficient corresponding to z_j.
1230 \n
1231 If x is a variable, taylor [ arg[0] * cap_order + k ]
1232 for k = 0 , ... , d
1233 is the k-th order Taylor coefficient corresponding to x.
1234 \n
1235 If y is a variable, taylor [ arg[1] * cap_order + k ]
1236 for k = 0 , ... , d
1237 is the k-th order Taylor coefficient corresponding to y.
1238
1239 \param nc_partial
1240 number of colums in the matrix containing all the partial derivatives.
1241
1242 \param partial
1243 \b Input: partial [ (i_z - 2 + j) * nc_partial + k ]
1244 for j = 0, 1, 2, and k = 0 , ... , d
1245 is the partial derivative of
1246 G( z , y , x , w , u , ... )
1247 with respect to the k-th order Taylor coefficient for z_j.
1248 \n
1249 \b Input: If x is a variable, partial [ arg[0] * nc_partial + k ]
1250 for k = 0 , ... , d
1251 is the partial derivative of G( z , y , x , w , u , ... ) with respect to
1252 the k-th order Taylor coefficient for x.
1253 \n
1254 \b Input: If y is a variable, partial [ arg[1] * nc_partial + k ]
1255 for k = 0 , ... , d
1256 is the partial derivative of G( z , x , w , u , ... ) with respect to
1257 the k-th order Taylor coefficient for the auxillary variable y.
1258 \n
1259 \b Output: If x is a variable, partial [ arg[0] * nc_partial + k ]
1260 for k = 0 , ... , d
1261 is the partial derivative of H( y , x , w , u , ... ) with respect to
1262 the k-th order Taylor coefficient for x.
1263 \n
1264 \b Output: If y is a variable, partial [ arg[1] * nc_partial + k ]
1265 for k = 0 , ... , d
1266 is the partial derivative of H( y , x , w , u , ... ) with respect to
1267 the k-th order Taylor coefficient for y.
1268 \n
1269 \b Output: partial [ ( i_z - j ) * nc_partial + k ]
1270 for j = 0 , 1 , 2 and for k = 0 , ... , d
1271 may be used as work space; i.e., may change in an unspecified manner.
1272
1273 \par Checked Assumptions
1274 \li NumArg(op) == 2
1275 \li NumRes(op) == 3
1276 \li If x is a variable, arg[0] < i_z - 2
1277 \li If y is a variable, arg[1] < i_z - 2
1278 \li d < cap_order
1279 \li d < nc_partial
1280 */
1281 template <class Base>
1282 void reverse_pow_op(
1283 size_t d ,
1284 size_t i_z ,
1285 addr_t* arg ,
1286 const Base* parameter ,
1287 size_t cap_order ,
1288 const Base* taylor ,
1289 size_t nc_partial ,
1290 Base* partial )
1291 {
1292 // This routine is only for documentaiton, it should not be used
1293 CPPAD_ASSERT_UNKNOWN( false );
1294 }
1295
1296 // ==================== Sparsity Calculations ==============================
1297 /*!
1298 Prototype for reverse mode Hessian sparsity unary operators.
1299
1300 This routine is given the forward mode Jacobian sparsity patterns for x.
1301 It is also given the reverse mode dependence of G on z.
1302 In addition, it is given the revese mode Hessian sparsity
1303 for the quanity of interest G(z , y , ... )
1304 and it uses them to compute the sparsity patterns for
1305 \verbatim
1306 H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ]
1307 \endverbatim
1308
1309 \tparam Vector_set
1310 is the type used for vectors of sets. It can be either
1311 sparse::pack_setvec or sparse::list_setvec.
1312
1313 \param i_z
1314 variable index corresponding to the result for this operation;
1315 i.e. the row index in sparsity corresponding to z.
1316
1317 \param i_x
1318 variable index corresponding to the argument for this operator;
1319 i.e. the row index in sparsity corresponding to x.
1320
1321 \param rev_jacobian
1322 rev_jacobian[i_z]
1323 is all false (true) if the Jacobian of G with respect to z must be zero
1324 (may be non-zero).
1325 \n
1326 \n
1327 rev_jacobian[i_x]
1328 is all false (true) if the Jacobian with respect to x must be zero
1329 (may be non-zero).
1330 On input, it corresponds to the function G,
1331 and on output it corresponds to the function H.
1332
1333 \param for_jac_sparsity
1334 The set with index i_x in for_jac_sparsity
1335 is the forward mode Jacobian sparsity pattern for the variable x.
1336
1337 \param rev_hes_sparsity
1338 The set with index i_z in in rev_hes_sparsity
1339 is the Hessian sparsity pattern for the fucntion G
1340 where one of the partials derivative is with respect to z.
1341 \n
1342 \n
1343 The set with index i_x in rev_hes_sparsity
1344 is the Hessian sparsity pattern
1345 where one of the partials derivative is with respect to x.
1346 On input, it corresponds to the function G,
1347 and on output it corresponds to the function H.
1348
1349 \par Checked Assertions:
1350 \li i_x < i_z
1351 */
1352
1353 template <class Vector_set>
1354 void reverse_sparse_hessian_unary_op(
1355 size_t i_z ,
1356 size_t i_x ,
1357 bool* rev_jacobian ,
1358 Vector_set& for_jac_sparsity ,
1359 Vector_set& rev_hes_sparsity )
1360 {
1361 // This routine is only for documentaiton, it should not be used
1362 CPPAD_ASSERT_UNKNOWN( false );
1363 }
1364
1365 /*!
1366 Prototype for reverse mode Hessian sparsity binary operators.
1367
1368 This routine is given the sparsity patterns the Hessian
1369 of a function G(z, y, x, ... )
1370 and it uses them to compute the sparsity patterns for the Hessian of
1371 \verbatim
1372 H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1373 \endverbatim
1374
1375 \tparam Vector_set
1376 is the type used for vectors of sets. It can be either
1377 sparse::pack_setvec or sparse::list_setvec.
1378
1379 \param i_z
1380 variable index corresponding to the result for this operation;
1381 i.e. the row index in sparsity corresponding to z.
1382
1383 \param arg
1384 arg[0]
1385 variable index corresponding to the left operand for this operator;
1386 i.e. the set with index arg[0] in var_sparsity
1387 is the spasity pattern correspoding to x.
1388 \n
1389 \n arg[1]
1390 variable index corresponding to the right operand for this operator;
1391 i.e. the row index in sparsity patterns corresponding to y.
1392
1393 \param jac_reverse
1394 jac_reverse[i_z]
1395 is false (true) if the Jacobian of G with respect to z is always zero
1396 (may be non-zero).
1397 \n
1398 \n
1399 jac_reverse[ arg[0] ]
1400 is false (true) if the Jacobian with respect to x is always zero
1401 (may be non-zero).
1402 On input, it corresponds to the function G,
1403 and on output it corresponds to the function H.
1404 \n
1405 \n
1406 jac_reverse[ arg[1] ]
1407 is false (true) if the Jacobian with respect to y is always zero
1408 (may be non-zero).
1409 On input, it corresponds to the function G,
1410 and on output it corresponds to the function H.
1411
1412 \param for_jac_sparsity
1413 The set with index arg[0] in for_jac_sparsity for the
1414 is the forward Jacobian sparsity pattern for x.
1415 \n
1416 \n
1417 The set with index arg[1] in for_jac_sparsity
1418 is the forward sparsity pattern for y.
1419
1420 \param rev_hes_sparsity
1421 The set wiht index i_x in rev_hes_sparsity
1422 is the Hessian sparsity pattern for the function G
1423 where one of the partial derivatives is with respect to z.
1424 \n
1425 \n
1426 The set with index arg[0] in rev_hes_sparsity
1427 is the Hessian sparsity pattern where one of the
1428 partial derivatives is with respect to x.
1429 On input, it corresponds to the function G,
1430 and on output it correspondst to H.
1431 \n
1432 \n
1433 The set with index arg[1] in rev_hes_sparsity
1434 is the Hessian sparsity pattern where one of the
1435 partial derivatives is with respect to y.
1436 On input, it corresponds to the function G,
1437 and on output it correspondst to H.
1438
1439 \par Checked Assertions:
1440 \li arg[0] < i_z
1441 \li arg[1] < i_z
1442 */
1443 template <class Vector_set>
1444 void reverse_sparse_hessian_binary_op(
1445 size_t i_z ,
1446 const addr_t* arg ,
1447 bool* jac_reverse ,
1448 Vector_set& for_jac_sparsity ,
1449 Vector_set& rev_hes_sparsity )
1450 {
1451 // This routine is only for documentaiton, it should not be used
1452 CPPAD_ASSERT_UNKNOWN( false );
1453 }
1454
1455
1456 } } // END_CPPAD_LOCAL_NAMESPACE
1457 # endif
0 # ifndef CPPAD_LOCAL_OP_SIGN_OP_HPP
1 # define CPPAD_LOCAL_OP_SIGN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17 // See dev documentation: forward_unary_op
18 template <class Base>
19 void forward_sign_op(
20 size_t p ,
21 size_t q ,
22 size_t i_z ,
23 size_t i_x ,
24 size_t cap_order ,
25 Base* taylor )
26 {
27 // check assumptions
28 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
29 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( q < cap_order );
31 CPPAD_ASSERT_UNKNOWN( p <= q );
32
33 // Taylor coefficients corresponding to argument and result
34 Base* x = taylor + i_x * cap_order;
35 Base* z = taylor + i_z * cap_order;
36
37 if( p == 0 )
38 { z[0] = sign(x[0]);
39 p++;
40 }
41 for(size_t j = p; j <= q; j++)
42 z[j] = Base(0.);
43 }
44 // See dev documentation: forward_unary_op
45 template <class Base>
46 void forward_sign_op_dir(
47 size_t q ,
48 size_t r ,
49 size_t i_z ,
50 size_t i_x ,
51 size_t cap_order ,
52 Base* taylor )
53 {
54 // check assumptions
55 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
56 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
57 CPPAD_ASSERT_UNKNOWN( 0 < q );
58 CPPAD_ASSERT_UNKNOWN( q < cap_order );
59
60 // Taylor coefficients corresponding to argument and result
61 size_t num_taylor_per_var = (cap_order-1) * r + 1;
62 size_t m = (q - 1) * r + 1;
63 Base* z = taylor + i_z * num_taylor_per_var;
64
65 for(size_t ell = 0; ell < r; ell++)
66 z[m+ell] = Base(0.);
67 }
68
69 // See dev documentation: forward_unary_op
70 template <class Base>
71 void forward_sign_op_0(
72 size_t i_z ,
73 size_t i_x ,
74 size_t cap_order ,
75 Base* taylor )
76 {
77
78 // check assumptions
79 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
80 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
81 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
82
83 // Taylor coefficients corresponding to argument and result
84 Base x0 = *(taylor + i_x * cap_order);
85 Base* z = taylor + i_z * cap_order;
86
87 z[0] = sign(x0);
88 }
89
90 // See dev documentation: reverse_unary_op
91 template <class Base>
92 void reverse_sign_op(
93 size_t d ,
94 size_t i_z ,
95 size_t i_x ,
96 size_t cap_order ,
97 const Base* taylor ,
98 size_t nc_partial ,
99 Base* partial )
100 {
101 // check assumptions
102 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
103 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
104 CPPAD_ASSERT_UNKNOWN( d < cap_order );
105 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
106
107 // nothing to do because partials of sign are zero
108 return;
109 }
110
111 } } // END_CPPAD_LOCAL_NAMESPACE
112 # endif
0 # ifndef CPPAD_LOCAL_OP_SIN_OP_HPP
1 # define CPPAD_LOCAL_OP_SIN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_sin_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* s = taylor + i_z * cap_order;
37 Base* c = s - cap_order;
38
39 // rest of this routine is identical for the following cases:
40 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op.
41 // (except that there is a sign difference for the hyperbolic case).
42 size_t k;
43 if( p == 0 )
44 { s[0] = sin( x[0] );
45 c[0] = cos( x[0] );
46 p++;
47 }
48 for(size_t j = p; j <= q; j++)
49 {
50 s[j] = Base(0.0);
51 c[j] = Base(0.0);
52 for(k = 1; k <= j; k++)
53 { s[j] += Base(double(k)) * x[k] * c[j-k];
54 c[j] -= Base(double(k)) * x[k] * s[j-k];
55 }
56 s[j] /= Base(double(j));
57 c[j] /= Base(double(j));
58 }
59 }
60 // See dev documentation: forward_unary_op
61 template <class Base>
62 void forward_sin_op_dir(
63 size_t q ,
64 size_t r ,
65 size_t i_z ,
66 size_t i_x ,
67 size_t cap_order ,
68 Base* taylor )
69 {
70 // check assumptions
71 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
72 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
73 CPPAD_ASSERT_UNKNOWN( 0 < q );
74 CPPAD_ASSERT_UNKNOWN( q < cap_order );
75
76 // Taylor coefficients corresponding to argument and result
77 size_t num_taylor_per_var = (cap_order-1) * r + 1;
78 Base* x = taylor + i_x * num_taylor_per_var;
79 Base* s = taylor + i_z * num_taylor_per_var;
80 Base* c = s - num_taylor_per_var;
81
82
83 // rest of this routine is identical for the following cases:
84 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
85 // (except that there is a sign difference for the hyperbolic case).
86 size_t m = (q-1) * r + 1;
87 for(size_t ell = 0; ell < r; ell++)
88 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
89 c[m+ell] = - Base(double(q)) * x[m + ell] * s[0];
90 for(size_t k = 1; k < q; k++)
91 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
92 c[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
93 }
94 s[m+ell] /= Base(double(q));
95 c[m+ell] /= Base(double(q));
96 }
97 }
98
99
100 // See dev documentation: forward_unary_op
101 template <class Base>
102 void forward_sin_op_0(
103 size_t i_z ,
104 size_t i_x ,
105 size_t cap_order ,
106 Base* taylor )
107 {
108 // check assumptions
109 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
110 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
111 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
112
113 // Taylor coefficients corresponding to argument and result
114 Base* x = taylor + i_x * cap_order;
115 Base* s = taylor + i_z * cap_order; // called z in documentation
116 Base* c = s - cap_order; // called y in documentation
117
118 s[0] = sin( x[0] );
119 c[0] = cos( x[0] );
120 }
121
122
123 // See dev documentation: reverse_unary_op
124 template <class Base>
125 void reverse_sin_op(
126 size_t d ,
127 size_t i_z ,
128 size_t i_x ,
129 size_t cap_order ,
130 const Base* taylor ,
131 size_t nc_partial ,
132 Base* partial )
133 {
134 // check assumptions
135 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
136 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
137 CPPAD_ASSERT_UNKNOWN( d < cap_order );
138 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
139
140 // Taylor coefficients and partials corresponding to argument
141 const Base* x = taylor + i_x * cap_order;
142 Base* px = partial + i_x * nc_partial;
143
144 // Taylor coefficients and partials corresponding to first result
145 const Base* s = taylor + i_z * cap_order; // called z in doc
146 Base* ps = partial + i_z * nc_partial;
147
148 // Taylor coefficients and partials corresponding to auxillary result
149 const Base* c = s - cap_order; // called y in documentation
150 Base* pc = ps - nc_partial;
151
152
153 // rest of this routine is identical for the following cases:
154 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
155 size_t j = d;
156 size_t k;
157 while(j)
158 {
159 ps[j] /= Base(double(j));
160 pc[j] /= Base(double(j));
161 for(k = 1; k <= j; k++)
162 {
163 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
164 px[k] -= Base(double(k)) * azmul(pc[j], s[j-k]);
165
166 ps[j-k] -= Base(double(k)) * azmul(pc[j], x[k]);
167 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
168
169 }
170 --j;
171 }
172 px[0] += azmul(ps[0], c[0]);
173 px[0] -= azmul(pc[0], s[0]);
174 }
175
176 } } // END_CPPAD_LOCAL_NAMESPACE
177 # endif
0 # ifndef CPPAD_LOCAL_OP_SINH_OP_HPP
1 # define CPPAD_LOCAL_OP_SINH_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_sinh_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* s = taylor + i_z * cap_order;
37 Base* c = s - cap_order;
38
39
40 // rest of this routine is identical for the following cases:
41 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
42 // (except that there is a sign difference for hyperbolic case).
43 size_t k;
44 if( p == 0 )
45 { s[0] = sinh( x[0] );
46 c[0] = cosh( x[0] );
47 p++;
48 }
49 for(size_t j = p; j <= q; j++)
50 {
51 s[j] = Base(0.0);
52 c[j] = Base(0.0);
53 for(k = 1; k <= j; k++)
54 { s[j] += Base(double(k)) * x[k] * c[j-k];
55 c[j] += Base(double(k)) * x[k] * s[j-k];
56 }
57 s[j] /= Base(double(j));
58 c[j] /= Base(double(j));
59 }
60 }
61 // See dev documentation: forward_unary_op
62 template <class Base>
63 void forward_sinh_op_dir(
64 size_t q ,
65 size_t r ,
66 size_t i_z ,
67 size_t i_x ,
68 size_t cap_order ,
69 Base* taylor )
70 {
71 // check assumptions
72 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
73 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
74 CPPAD_ASSERT_UNKNOWN( 0 < q );
75 CPPAD_ASSERT_UNKNOWN( q < cap_order );
76
77 // Taylor coefficients corresponding to argument and result
78 size_t num_taylor_per_var = (cap_order-1) * r + 1;
79 Base* x = taylor + i_x * num_taylor_per_var;
80 Base* s = taylor + i_z * num_taylor_per_var;
81 Base* c = s - num_taylor_per_var;
82
83
84 // rest of this routine is identical for the following cases:
85 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
86 // (except that there is a sign difference for the hyperbolic case).
87 size_t m = (q-1) * r + 1;
88 for(size_t ell = 0; ell < r; ell++)
89 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
90 c[m+ell] = Base(double(q)) * x[m + ell] * s[0];
91 for(size_t k = 1; k < q; k++)
92 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
93 c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
94 }
95 s[m+ell] /= Base(double(q));
96 c[m+ell] /= Base(double(q));
97 }
98 }
99
100 // See dev documentation: forward_unary_op
101 template <class Base>
102 void forward_sinh_op_0(
103 size_t i_z ,
104 size_t i_x ,
105 size_t cap_order ,
106 Base* taylor )
107 {
108 // check assumptions
109 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
110 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
111 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
112
113 // Taylor coefficients corresponding to argument and result
114 Base* x = taylor + i_x * cap_order;
115 Base* s = taylor + i_z * cap_order; // called z in documentation
116 Base* c = s - cap_order; // called y in documentation
117
118 s[0] = sinh( x[0] );
119 c[0] = cosh( x[0] );
120 }
121
122 // See dev documentation: reverse_unary_op
123 template <class Base>
124 void reverse_sinh_op(
125 size_t d ,
126 size_t i_z ,
127 size_t i_x ,
128 size_t cap_order ,
129 const Base* taylor ,
130 size_t nc_partial ,
131 Base* partial )
132 {
133 // check assumptions
134 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
135 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
136 CPPAD_ASSERT_UNKNOWN( d < cap_order );
137 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
138
139 // Taylor coefficients and partials corresponding to argument
140 const Base* x = taylor + i_x * cap_order;
141 Base* px = partial + i_x * nc_partial;
142
143 // Taylor coefficients and partials corresponding to first result
144 const Base* s = taylor + i_z * cap_order; // called z in doc
145 Base* ps = partial + i_z * nc_partial;
146
147 // Taylor coefficients and partials corresponding to auxillary result
148 const Base* c = s - cap_order; // called y in documentation
149 Base* pc = ps - nc_partial;
150
151
152 // rest of this routine is identical for the following cases:
153 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
154 size_t j = d;
155 size_t k;
156 while(j)
157 {
158 ps[j] /= Base(double(j));
159 pc[j] /= Base(double(j));
160 for(k = 1; k <= j; k++)
161 {
162 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
163 px[k] += Base(double(k)) * azmul(pc[j], s[j-k]);
164
165 ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]);
166 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
167
168 }
169 --j;
170 }
171 px[0] += azmul(ps[0], c[0]);
172 px[0] += azmul(pc[0], s[0]);
173 }
174
175 } } // END_CPPAD_LOCAL_NAMESPACE
176 # endif
0 # ifndef CPPAD_LOCAL_OP_SQRT_OP_HPP
1 # define CPPAD_LOCAL_OP_SQRT_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_sqrt_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37
38 size_t k;
39 if( p == 0 )
40 { z[0] = sqrt( x[0] );
41 p++;
42 }
43 for(size_t j = p; j <= q; j++)
44 {
45 z[j] = Base(0.0);
46 for(k = 1; k < j; k++)
47 z[j] -= Base(double(k)) * z[k] * z[j-k];
48 z[j] /= Base(double(j));
49 z[j] += x[j] / Base(2.0);
50 z[j] /= z[0];
51 }
52 }
53
54 // See dev documentation: forward_unary_op
55 template <class Base>
56 void forward_sqrt_op_dir(
57 size_t q ,
58 size_t r ,
59 size_t i_z ,
60 size_t i_x ,
61 size_t cap_order ,
62 Base* taylor )
63 {
64 // check assumptions
65 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
66 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
67 CPPAD_ASSERT_UNKNOWN( 0 < q );
68 CPPAD_ASSERT_UNKNOWN( q < cap_order );
69
70 // Taylor coefficients corresponding to argument and result
71 size_t num_taylor_per_var = (cap_order-1) * r + 1;
72 Base* z = taylor + i_z * num_taylor_per_var;
73 Base* x = taylor + i_x * num_taylor_per_var;
74
75 size_t m = (q-1) * r + 1;
76 for(size_t ell = 0; ell < r; ell++)
77 { z[m+ell] = Base(0.0);
78 for(size_t k = 1; k < q; k++)
79 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell];
80 z[m+ell] /= Base(double(q));
81 z[m+ell] += x[m+ell] / Base(2.0);
82 z[m+ell] /= z[0];
83 }
84 }
85
86 // See dev documentation: forward_unary_op
87 template <class Base>
88 void forward_sqrt_op_0(
89 size_t i_z ,
90 size_t i_x ,
91 size_t cap_order ,
92 Base* taylor )
93 {
94 // check assumptions
95 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
96 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
97 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
98
99 // Taylor coefficients corresponding to argument and result
100 Base* x = taylor + i_x * cap_order;
101 Base* z = taylor + i_z * cap_order;
102
103 z[0] = sqrt( x[0] );
104 }
105
106 // See dev documentation: reverse_unary_op
107 template <class Base>
108 void reverse_sqrt_op(
109 size_t d ,
110 size_t i_z ,
111 size_t i_x ,
112 size_t cap_order ,
113 const Base* taylor ,
114 size_t nc_partial ,
115 Base* partial )
116 {
117 // check assumptions
118 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
119 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
120 CPPAD_ASSERT_UNKNOWN( d < cap_order );
121 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
122
123 // Taylor coefficients and partials corresponding to argument
124 Base* px = partial + i_x * nc_partial;
125
126 // Taylor coefficients and partials corresponding to result
127 const Base* z = taylor + i_z * cap_order;
128 Base* pz = partial + i_z * nc_partial;
129
130
131 Base inv_z0 = Base(1.0) / z[0];
132
133 // number of indices to access
134 size_t j = d;
135 size_t k;
136 while(j)
137 {
138
139 // scale partial w.r.t. z[j]
140 pz[j] = azmul(pz[j], inv_z0);
141
142 pz[0] -= azmul(pz[j], z[j]);
143 px[j] += pz[j] / Base(2.0);
144 for(k = 1; k < j; k++)
145 pz[k] -= azmul(pz[j], z[j-k]);
146 --j;
147 }
148 px[0] += azmul(pz[0], inv_z0) / Base(2.0);
149 }
150
151 } } // END_CPPAD_LOCAL_NAMESPACE
152 # endif
0 # ifndef CPPAD_LOCAL_OP_STORE_OP_HPP
1 # define CPPAD_LOCAL_OP_STORE_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*
16 $begin store_op_var$$
17 $spell
18 pv
19 vp
20 vv
21 Vec
22 op
23 var
24 isvar
25 ind
26 Taylor
27 arg
28 num
29 Addr
30 $$
31 $section Changing an Element in a Variable VecAD Vector$$
32
33 $head See Also$$
34 $cref/op_code_var store/op_code_var/Store/$$.
35
36 $head Syntax$$
37 $codei%forward_store_%IV%_op_0(
38 %i_z%,
39 %arg%,
40 %num_par%,
41 %parameter%,
42 %cap_order%,
43 %taylor%,
44 %vec_ad2isvar%,
45 %vec_ad2index%
46 )
47 %$$
48 where the index type $icode I$$ and the value being stored type $icode V$$
49 are $code p$$ (for parameter) or $code v$$ (for variable).
50
51 $head Prototype$$
52 $srcthisfile%
53 0%// BEGIN_FORWARD_STORE_PP_OP_0%// END_FORWARD_STORE_PP_OP_0%1
54 %$$
55 The prototype for
56 $code forward_store_pv_op_0$$,
57 $code forward_store_vp_op_0$$, and
58 $code forward_store_vv_op_0$$,
59 are the same except for the function name.
60
61 $head Notation$$
62
63 $subhead v$$
64 We use $icode v$$ to denote the $cref VecAD$$ vector for this operation.
65
66 $subhead x$$
67 We use $icode x$$ to denote the $codei%AD%<%Base%>%$$
68 index for this operation.
69
70 $subhead i_vec$$
71 We use $icode i_vec$$ to denote the $code size_t$$ value
72 corresponding to $icode x$$.
73
74 $subhead n_load$$
75 This is the number of load instructions in this recording.
76
77 $subhead n_all$$
78 This is the number of values in the single array that includes
79 all the vectors together with the size of each vector.
80
81 $head Base$$
82 base type for the operator; i.e., this operation was recorded
83 using AD<Base> and computations by this routine are done using type Base.
84
85 $head i_z$$
86 is the AD variable index corresponding to the result of this load operation.
87
88 $head arg$$
89
90 $subhead arg[0]$$
91 is the offset of this VecAD vector relative to the beginning
92 of the $icode vec_ad2isvar$$ and $icode vec_ad2index$$ arrays.
93
94 $subhead arg[1]$$
95 If this is
96 $code forward_load_p_op_0$$ ($code forward_load_v_op_0$$)
97 $icode%arg%[%1%]%$$ is the parameter index (variable index)
98 corresponding to $cref/i_vec/load_op_var/Notation/i_vec/$$.
99
100 $subhead arg[2]$$
101 Is the index of this VecAD load instruction in the
102 $icode load_op2var$$ array.
103
104 $head num_par$$
105 is the number of parameters in this recording.
106
107 $head parameter$$
108 This is the vector of parameters for this recording which has size
109 $icode num_par$$.
110
111 $head cap_order$$
112 number of columns in the matrix containing the Taylor coefficients.
113
114 $head taylor$$
115 Is the matrix of Taylor coefficients for all the variables.
116
117 $head vec_ad2isvar$$
118 This vector has size $icode n_all$$ and
119 the input values of its elements does not matter.
120 If the value being stored is a parameter (variable),
121 $icode%vec_ad2isvar%[ %arg%[0] + %i_vec% ]%$$
122 is set to false (true).
123
124 $head vec_ad2index$$
125 This array has size $icode n_all$$
126 and the input value of its elements does not matter.
127 If the value being stored is a parameter (variable),
128 $icode%vec_ad2index%[ %arg%[0] + %i_vec% ]%$$
129 is set to the parameter (variable) index
130 corresponding to the value being stored.
131
132 $end
133 */
134 // BEGIN_FORWARD_STORE_PP_OP_0
135 template <class Base>
136 void forward_store_pp_op_0(
137 size_t i_z ,
138 const addr_t* arg ,
139 size_t num_par ,
140 const Base* parameter ,
141 size_t cap_order ,
142 const Base* taylor ,
143 bool* vec_ad2isvar ,
144 size_t* vec_ad2index )
145 // END_FORWARD_STORE_PP_OP_0
146 { addr_t i_vec = addr_t( Integer( parameter[ arg[1] ] ) );
147 CPPAD_ASSERT_KNOWN(
148 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
149 "VecAD: zero order forward dynamic parameter index out of range"
150 );
151 CPPAD_ASSERT_UNKNOWN( NumArg(StppOp) == 3 );
152 CPPAD_ASSERT_UNKNOWN( NumRes(StppOp) == 0 );
153 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
154 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
155
156 vec_ad2isvar[ arg[0] + i_vec ] = false;
157 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
158 }
159 template <class Base>
160 void forward_store_pv_op_0(
161 size_t i_z ,
162 const addr_t* arg ,
163 size_t num_par ,
164 const Base* parameter ,
165 size_t cap_order ,
166 const Base* taylor ,
167 bool* vec_ad2isvar ,
168 size_t* vec_ad2index )
169 { addr_t i_vec = addr_t( Integer( parameter[ arg[1] ] ) );
170 CPPAD_ASSERT_KNOWN(
171 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
172 "VecAD: zero order forward dynamic parameter index out of range"
173 );
174 CPPAD_ASSERT_UNKNOWN( NumArg(StpvOp) == 3 );
175 CPPAD_ASSERT_UNKNOWN( NumRes(StpvOp) == 0 );
176 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
177
178 vec_ad2isvar[ arg[0] + i_vec ] = true;
179 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
180 }
181 template <class Base>
182 void forward_store_vp_op_0(
183 size_t i_z ,
184 const addr_t* arg ,
185 size_t num_par ,
186 size_t cap_order ,
187 const Base* taylor ,
188 bool* vec_ad2isvar ,
189 size_t* vec_ad2index )
190 {
191 addr_t i_vec = addr_t(Integer( taylor[ size_t(arg[1]) * cap_order + 0 ] ));
192 CPPAD_ASSERT_KNOWN(
193 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
194 "VecAD: zero order forward variable index out of range"
195 );
196
197 CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 );
198 CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 );
199 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
200 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
201
202 vec_ad2isvar[ arg[0] + i_vec ] = false;
203 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
204 }
205 template <class Base>
206 void forward_store_vv_op_0(
207 size_t i_z ,
208 const addr_t* arg ,
209 size_t num_par ,
210 size_t cap_order ,
211 const Base* taylor ,
212 bool* vec_ad2isvar ,
213 size_t* vec_ad2index )
214 {
215 addr_t i_vec = addr_t(Integer( taylor[ size_t(arg[1]) * cap_order + 0 ] ));
216 CPPAD_ASSERT_KNOWN(
217 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
218 "VecAD: index during zero order forward sweep is out of range"
219 );
220
221 CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 );
222 CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 );
223 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
224
225 vec_ad2isvar[ arg[0] + i_vec ] = true;
226 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
227 }
228 // ---------------------------------------------------------------------------
229 /*
230 ==============================================================================
231 <!-- define preamble -->
232 The C++ source code corresponding to this operation is
233 \verbatim
234 v[x] = y
235 \endverbatim
236 where v is a VecAD<Base> vector, x is an AD<Base> object,
237 and y is AD<Base> or Base objects.
238 We define the index corresponding to v[x] by
239 \verbatim
240 i_v_x = vec_ad2index[ arg[0] + i_vec ]
241 \endverbatim
242 where i_vec is defined under the heading arg[1] below:
243 <!-- end preamble -->
244 ==============================================================================
245 */
246 /*!
247 Shared documnetation for sparsity operations corresponding to
248 op = StpvOp or StvvOp (not called).
249
250 \tparam Vector_set
251 is the type used for vectors of sets. It can be either
252 sparse::pack_setvec or sparse::list_setvec.
253
254 \param op
255 is the code corresponding to this operator;
256 i.e., StpvOp, StvpOp, or StvvOp.
257
258 \param arg
259 \n
260 arg[0]
261 is the offset corresponding to this VecAD vector in the combined array.
262 \n
263 \n
264 arg[2]
265 \n
266 The set with index arg[2] in var_sparsity
267 is the sparsity pattern corresponding to y.
268 (Note that arg[2] > 0 because y is a variable.)
269
270 \param num_combined
271 is the total number of elements in the VecAD address array.
272
273 \param combined
274 combined [ arg[0] - 1 ]
275 is the index of the set in vecad_sparsity corresponding
276 to the sparsity pattern for the vector v.
277 We use the notation i_v below which is defined by
278 \verbatim
279 i_v = combined[ arg[0] - 1 ]
280 \endverbatim
281
282 \param var_sparsity
283 The set with index arg[2] in var_sparsity
284 is the sparsity pattern for y.
285 This is an input for forward mode operations.
286 For reverse mode operations:
287 The sparsity pattern for v is added to the spartisy pattern for y.
288
289 \param vecad_sparsity
290 The set with index i_v in vecad_sparsity
291 is the sparsity pattern for v.
292 This is an input for reverse mode operations.
293 For forward mode operations, the sparsity pattern for y is added
294 to the sparsity pattern for the vector v.
295
296 \par Checked Assertions
297 \li NumArg(op) == 3
298 \li NumRes(op) == 0
299 \li 0 < arg[0]
300 \li arg[0] < num_combined
301 \li arg[2] < var_sparsity.n_set()
302 \li i_v < vecad_sparsity.n_set()
303 */
304 template <class Vector_set>
305 void sparse_store_op(
306 OpCode op ,
307 const addr_t* arg ,
308 size_t num_combined ,
309 const size_t* combined ,
310 Vector_set& var_sparsity ,
311 Vector_set& vecad_sparsity )
312 {
313 // This routine is only for documentaiton, it should not be used
314 CPPAD_ASSERT_UNKNOWN( false );
315 }
316
317
318
319 /*!
320 Forward mode sparsity operations for StpvOp and StvvOp
321
322 <!-- replace preamble -->
323 The C++ source code corresponding to this operation is
324 \verbatim
325 v[x] = y
326 \endverbatim
327 where v is a VecAD<Base> vector, x is an AD<Base> object,
328 and y is AD<Base> or Base objects.
329 We define the index corresponding to v[x] by
330 \verbatim
331 i_v_x = vec_ad2index[ arg[0] + i_vec ]
332 \endverbatim
333 where i_vec is defined under the heading arg[1] below:
334 <!-- end preamble -->
335
336 \param dependency
337 is this a dependency (or sparsity) calculation.
338
339 \copydetails CppAD::local::sparse_store_op
340 */
341 template <class Vector_set>
342 void forward_sparse_store_op(
343 bool dependency ,
344 OpCode op ,
345 const addr_t* arg ,
346 size_t num_combined ,
347 const size_t* combined ,
348 Vector_set& var_sparsity ,
349 Vector_set& vecad_sparsity )
350 {
351 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
352 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
353 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
354 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
355 size_t i_v = combined[ arg[0] - 1 ];
356 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
357 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
358
359 if( dependency & ( (op == StvvOp) | (op == StvpOp) ) )
360 vecad_sparsity.binary_union(i_v, i_v, size_t(arg[1]), var_sparsity);
361
362 if( (op == StpvOp) | (op == StvvOp ) )
363 vecad_sparsity.binary_union(i_v, i_v, size_t(arg[2]), var_sparsity);
364
365 return;
366 }
367
368 /*!
369 Reverse mode sparsity operations for StpvOp, StvpOp, and StvvOp
370
371 <!-- replace preamble -->
372 The C++ source code corresponding to this operation is
373 \verbatim
374 v[x] = y
375 \endverbatim
376 where v is a VecAD<Base> vector, x is an AD<Base> object,
377 and y is AD<Base> or Base objects.
378 We define the index corresponding to v[x] by
379 \verbatim
380 i_v_x = vec_ad2index[ arg[0] + i_vec ]
381 \endverbatim
382 where i_vec is defined under the heading arg[1] below:
383 <!-- end preamble -->
384
385 This routine is given the sparsity patterns for
386 G(v[x], y , w , u ... ) and it uses them to compute the
387 sparsity patterns for
388 \verbatim
389 H(y , w , u , ... ) = G[ v[x], y , w , u , ... ]
390 \endverbatim
391
392 \param dependency
393 is this a dependency (or sparsity) calculation.
394
395 \copydetails CppAD::local::sparse_store_op
396 */
397 template <class Vector_set>
398 void reverse_sparse_jacobian_store_op(
399 bool dependency ,
400 OpCode op ,
401 const addr_t* arg ,
402 size_t num_combined ,
403 const size_t* combined ,
404 Vector_set& var_sparsity ,
405 Vector_set& vecad_sparsity )
406 {
407 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
408 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
409 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
410 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
411 size_t i_v = combined[ arg[0] - 1 ];
412 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
413 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
414
415 if( dependency & ( (op == StvpOp) | (op == StvvOp) ) )
416 var_sparsity.binary_union( size_t(arg[1]), size_t(arg[1]), i_v, vecad_sparsity);
417 if( (op == StpvOp) | (op == StvvOp) )
418 var_sparsity.binary_union( size_t(arg[2]), size_t(arg[2]), i_v, vecad_sparsity);
419
420 return;
421 }
422
423 /*!
424 Reverse mode sparsity operations for StpvOp and StvvOp
425
426 <!-- replace preamble -->
427 The C++ source code corresponding to this operation is
428 \verbatim
429 v[x] = y
430 \endverbatim
431 where v is a VecAD<Base> vector, x is an AD<Base> object,
432 and y is AD<Base> or Base objects.
433 We define the index corresponding to v[x] by
434 \verbatim
435 i_v_x = vec_ad2index[ arg[0] + i_vec ]
436 \endverbatim
437 where i_vec is defined under the heading arg[1] below:
438 <!-- end preamble -->
439
440 This routine is given the sparsity patterns for
441 G(v[x], y , w , u ... )
442 and it uses them to compute the sparsity patterns for
443 \verbatim
444 H(y , w , u , ... ) = G[ v[x], y , w , u , ... ]
445 \endverbatim
446
447 \copydetails CppAD::local::sparse_store_op
448
449 \param var_jacobian
450 var_jacobian[ arg[2] ]
451 is false (true) if the Jacobian of G with respect to y is always zero
452 (may be non-zero).
453
454 \param vecad_jacobian
455 vecad_jacobian[i_v]
456 is false (true) if the Jacobian with respect to x is always zero
457 (may be non-zero).
458 On input, it corresponds to the function G,
459 and on output it corresponds to the function H.
460 */
461 template <class Vector_set>
462 void reverse_sparse_hessian_store_op(
463 OpCode op ,
464 const addr_t* arg ,
465 size_t num_combined ,
466 const size_t* combined ,
467 Vector_set& var_sparsity ,
468 Vector_set& vecad_sparsity ,
469 bool* var_jacobian ,
470 bool* vecad_jacobian )
471 {
472 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
473 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
474 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
475 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
476 size_t i_v = combined[ arg[0] - 1 ];
477 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
478 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
479
480 var_sparsity.binary_union( size_t(arg[2]), size_t(arg[2]), i_v, vecad_sparsity);
481
482 var_jacobian[ arg[2] ] |= vecad_jacobian[i_v];
483
484 return;
485 }
486
487 } } // END_CPPAD_LOCAL_NAMESPACE
488 # endif
0 # ifndef CPPAD_LOCAL_OP_SUB_OP_HPP
1 # define CPPAD_LOCAL_OP_SUB_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15
16 // --------------------------- Subvv -----------------------------------------
17
18 // See dev documentation: forward_binary_op
19 template <class Base>
20 void forward_subvv_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 const addr_t* arg ,
25 const Base* parameter ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to arguments and result
36 Base* x = taylor + size_t(arg[0]) * cap_order;
37 Base* y = taylor + size_t(arg[1]) * cap_order;
38 Base* z = taylor + i_z * cap_order;
39
40 for(size_t d = p; d <= q; d++)
41 z[d] = x[d] - y[d];
42 }
43
44 // See dev documentation: forward_binary_op
45 template <class Base>
46 void forward_subvv_op_dir(
47 size_t q ,
48 size_t r ,
49 size_t i_z ,
50 const addr_t* arg ,
51 const Base* parameter ,
52 size_t cap_order ,
53 Base* taylor )
54 {
55 // check assumptions
56 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
57 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
58 CPPAD_ASSERT_UNKNOWN( 0 < q );
59 CPPAD_ASSERT_UNKNOWN( q < cap_order );
60
61 // Taylor coefficients corresponding to arguments and result
62 size_t num_taylor_per_var = (cap_order-1) * r + 1;
63 size_t m = (q-1) * r + 1;
64 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var + m;
65 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
66 Base* z = taylor + i_z * num_taylor_per_var + m;
67
68 for(size_t ell = 0; ell < r; ell++)
69 z[ell] = x[ell] - y[ell];
70 }
71
72
73 // See dev documentation: forward_binary_op
74 template <class Base>
75 void forward_subvv_op_0(
76 size_t i_z ,
77 const addr_t* arg ,
78 const Base* parameter ,
79 size_t cap_order ,
80 Base* taylor )
81 {
82 // check assumptions
83 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
84 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
85
86 // Taylor coefficients corresponding to arguments and result
87 Base* x = taylor + size_t(arg[0]) * cap_order;
88 Base* y = taylor + size_t(arg[1]) * cap_order;
89 Base* z = taylor + i_z * cap_order;
90
91 z[0] = x[0] - y[0];
92 }
93
94
95 // See dev documentation: reverse_binary_op
96 template <class Base>
97 void reverse_subvv_op(
98 size_t d ,
99 size_t i_z ,
100 const addr_t* arg ,
101 const Base* parameter ,
102 size_t cap_order ,
103 const Base* taylor ,
104 size_t nc_partial ,
105 Base* partial )
106 {
107 // check assumptions
108 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
109 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
110 CPPAD_ASSERT_UNKNOWN( d < cap_order );
111 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
112
113 // Partial derivatives corresponding to arguments and result
114 Base* px = partial + size_t(arg[0]) * nc_partial;
115 Base* py = partial + size_t(arg[1]) * nc_partial;
116 Base* pz = partial + i_z * nc_partial;
117
118 // number of indices to access
119 size_t i = d + 1;
120 while(i)
121 { --i;
122 px[i] += pz[i];
123 py[i] -= pz[i];
124 }
125 }
126
127 // --------------------------- Subpv -----------------------------------------
128
129 // See dev documentation: forward_binary_op
130 template <class Base>
131 void forward_subpv_op(
132 size_t p ,
133 size_t q ,
134 size_t i_z ,
135 const addr_t* arg ,
136 const Base* parameter ,
137 size_t cap_order ,
138 Base* taylor )
139 {
140 // check assumptions
141 CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );
142 CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
143 CPPAD_ASSERT_UNKNOWN( q < cap_order );
144 CPPAD_ASSERT_UNKNOWN( p <= q );
145
146 // Taylor coefficients corresponding to arguments and result
147 Base* y = taylor + size_t(arg[1]) * cap_order;
148 Base* z = taylor + i_z * cap_order;
149
150 // Paraemter value
151 Base x = parameter[ arg[0] ];
152 if( p == 0 )
153 { z[0] = x - y[0];
154 p++;
155 }
156 for(size_t d = p; d <= q; d++)
157 z[d] = - y[d];
158 }
159
160 // See dev documentation: forward_binary_op
161 template <class Base>
162 void forward_subpv_op_dir(
163 size_t q ,
164 size_t r ,
165 size_t i_z ,
166 const addr_t* arg ,
167 const Base* parameter ,
168 size_t cap_order ,
169 Base* taylor )
170 {
171 // check assumptions
172 CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );
173 CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
174 CPPAD_ASSERT_UNKNOWN( 0 < q );
175 CPPAD_ASSERT_UNKNOWN( q < cap_order );
176
177 // Taylor coefficients corresponding to arguments and result
178 size_t num_taylor_per_var = (cap_order-1) * r + 1;
179 size_t m = (q-1) * r + 1;
180 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
181 Base* z = taylor + i_z * num_taylor_per_var + m;
182
183 // Paraemter value
184 for(size_t ell = 0; ell < r; ell++)
185 z[ell] = - y[ell];
186 }
187
188 // See dev documentation: forward_binary_op
189 template <class Base>
190 void forward_subpv_op_0(
191 size_t i_z ,
192 const addr_t* arg ,
193 const Base* parameter ,
194 size_t cap_order ,
195 Base* taylor )
196 {
197 // check assumptions
198 CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );
199 CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
200
201 // Paraemter value
202 Base x = parameter[ arg[0] ];
203
204 // Taylor coefficients corresponding to arguments and result
205 Base* y = taylor + size_t(arg[1]) * cap_order;
206 Base* z = taylor + i_z * cap_order;
207
208 z[0] = x - y[0];
209 }
210
211
212 // See dev documentation: reverse_binary_op
213 template <class Base>
214 void reverse_subpv_op(
215 size_t d ,
216 size_t i_z ,
217 const addr_t* arg ,
218 const Base* parameter ,
219 size_t cap_order ,
220 const Base* taylor ,
221 size_t nc_partial ,
222 Base* partial )
223 {
224 // check assumptions
225 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
226 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
227 CPPAD_ASSERT_UNKNOWN( d < cap_order );
228 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
229
230 // Partial derivatives corresponding to arguments and result
231 Base* py = partial + size_t(arg[1]) * nc_partial;
232 Base* pz = partial + i_z * nc_partial;
233
234 // number of indices to access
235 size_t i = d + 1;
236 while(i)
237 { --i;
238 py[i] -= pz[i];
239 }
240 }
241
242 // --------------------------- Subvp -----------------------------------------
243
244 // See dev documentation: forward_binary_op
245 template <class Base>
246 void forward_subvp_op(
247 size_t p ,
248 size_t q ,
249 size_t i_z ,
250 const addr_t* arg ,
251 const Base* parameter ,
252 size_t cap_order ,
253 Base* taylor )
254 {
255 // check assumptions
256 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
257 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
258 CPPAD_ASSERT_UNKNOWN( q < cap_order );
259 CPPAD_ASSERT_UNKNOWN( p <= q );
260
261 // Taylor coefficients corresponding to arguments and result
262 Base* x = taylor + size_t(arg[0]) * cap_order;
263 Base* z = taylor + i_z * cap_order;
264
265 // Parameter value
266 Base y = parameter[ arg[1] ];
267 if( p == 0 )
268 { z[0] = x[0] - y;
269 p++;
270 }
271 for(size_t d = p; d <= q; d++)
272 z[d] = x[d];
273 }
274
275 // See dev documentation: forward_binary_op
276 template <class Base>
277 void forward_subvp_op_dir(
278 size_t q ,
279 size_t r ,
280 size_t i_z ,
281 const addr_t* arg ,
282 const Base* parameter ,
283 size_t cap_order ,
284 Base* taylor )
285 {
286 // check assumptions
287 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
288 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
289 CPPAD_ASSERT_UNKNOWN( 0 < q );
290 CPPAD_ASSERT_UNKNOWN( q < cap_order );
291
292 // Taylor coefficients corresponding to arguments and result
293 size_t num_taylor_per_var = (cap_order-1) * r + 1;
294 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
295 Base* z = taylor + i_z * num_taylor_per_var;
296
297 // Parameter value
298 size_t m = (q-1) * r + 1;
299 for(size_t ell = 0; ell < r; ell++)
300 z[m+ell] = x[m+ell];
301 }
302
303
304 // See dev documentation: forward_binary_op
305 template <class Base>
306 void forward_subvp_op_0(
307 size_t i_z ,
308 const addr_t* arg ,
309 const Base* parameter ,
310 size_t cap_order ,
311 Base* taylor )
312 {
313 // check assumptions
314 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
315 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
316
317 // Parameter value
318 Base y = parameter[ arg[1] ];
319
320 // Taylor coefficients corresponding to arguments and result
321 Base* x = taylor + size_t(arg[0]) * cap_order;
322 Base* z = taylor + i_z * cap_order;
323
324 z[0] = x[0] - y;
325 }
326
327
328 // See dev documentation: reverse_binary_op
329 template <class Base>
330 void reverse_subvp_op(
331 size_t d ,
332 size_t i_z ,
333 const addr_t* arg ,
334 const Base* parameter ,
335 size_t cap_order ,
336 const Base* taylor ,
337 size_t nc_partial ,
338 Base* partial )
339 {
340 // check assumptions
341 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
342 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
343 CPPAD_ASSERT_UNKNOWN( d < cap_order );
344 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
345
346 // Partial derivatives corresponding to arguments and result
347 Base* px = partial + size_t(arg[0]) * nc_partial;
348 Base* pz = partial + i_z * nc_partial;
349
350 // number of indices to access
351 size_t i = d + 1;
352 while(i)
353 { --i;
354 px[i] += pz[i];
355 }
356 }
357
358 } } // END_CPPAD_LOCAL_NAMESPACE
359 # endif
0 # ifndef CPPAD_LOCAL_OP_TAN_OP_HPP
1 # define CPPAD_LOCAL_OP_TAN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_tan_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37 Base* y = z - cap_order;
38
39 size_t k;
40 if( p == 0 )
41 { z[0] = tan( x[0] );
42 y[0] = z[0] * z[0];
43 p++;
44 }
45 for(size_t j = p; j <= q; j++)
46 { Base base_j = static_cast<Base>(double(j));
47
48 z[j] = x[j];
49 for(k = 1; k <= j; k++)
50 z[j] += Base(double(k)) * x[k] * y[j-k] / base_j;
51
52 y[j] = z[0] * z[j];
53 for(k = 1; k <= j; k++)
54 y[j] += z[k] * z[j-k];
55 }
56 }
57
58 // See dev documentation: forward_unary_op
59 template <class Base>
60 void forward_tan_op_dir(
61 size_t q ,
62 size_t r ,
63 size_t i_z ,
64 size_t i_x ,
65 size_t cap_order ,
66 Base* taylor )
67 {
68 // check assumptions
69 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
70 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
71 CPPAD_ASSERT_UNKNOWN( 0 < q );
72 CPPAD_ASSERT_UNKNOWN( q < cap_order );
73
74 // Taylor coefficients corresponding to argument and result
75 size_t num_taylor_per_var = (cap_order-1) * r + 1;
76 Base* x = taylor + i_x * num_taylor_per_var;
77 Base* z = taylor + i_z * num_taylor_per_var;
78 Base* y = z - num_taylor_per_var;
79
80 size_t k;
81 size_t m = (q-1) * r + 1;
82 for(size_t ell = 0; ell < r; ell++)
83 { z[m+ell] = Base(double(q)) * ( x[m+ell] + x[m+ell] * y[0]);
84 for(k = 1; k < q; k++)
85 z[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * y[(q-k-1)*r+1+ell];
86 z[m+ell] /= Base(double(q));
87 //
88 y[m+ell] = Base(2.0) * z[m+ell] * z[0];
89 for(k = 1; k < q; k++)
90 y[m+ell] += z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell];
91 }
92 }
93
94
95 // See dev documentation: forward_unary_op
96 template <class Base>
97 void forward_tan_op_0(
98 size_t i_z ,
99 size_t i_x ,
100 size_t cap_order ,
101 Base* taylor )
102 {
103 // check assumptions
104 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
105 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
106 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
107
108 // Taylor coefficients corresponding to argument and result
109 Base* x = taylor + i_x * cap_order;
110 Base* z = taylor + i_z * cap_order; // called z in documentation
111 Base* y = z - cap_order; // called y in documentation
112
113 z[0] = tan( x[0] );
114 y[0] = z[0] * z[0];
115 }
116
117
118 // See dev documentation: reverse_unary_op
119 template <class Base>
120 void reverse_tan_op(
121 size_t d ,
122 size_t i_z ,
123 size_t i_x ,
124 size_t cap_order ,
125 const Base* taylor ,
126 size_t nc_partial ,
127 Base* partial )
128 {
129 // check assumptions
130 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
131 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
132 CPPAD_ASSERT_UNKNOWN( d < cap_order );
133 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
134
135 // Taylor coefficients and partials corresponding to argument
136 const Base* x = taylor + i_x * cap_order;
137 Base* px = partial + i_x * nc_partial;
138
139 // Taylor coefficients and partials corresponding to first result
140 const Base* z = taylor + i_z * cap_order; // called z in doc
141 Base* pz = partial + i_z * nc_partial;
142
143 // Taylor coefficients and partials corresponding to auxillary result
144 const Base* y = z - cap_order; // called y in documentation
145 Base* py = pz - nc_partial;
146
147
148 size_t j = d;
149 size_t k;
150 Base base_two(2);
151 while(j)
152 {
153 px[j] += pz[j];
154 pz[j] /= Base(double(j));
155 for(k = 1; k <= j; k++)
156 { px[k] += azmul(pz[j], y[j-k]) * Base(double(k));
157 py[j-k] += azmul(pz[j], x[k]) * Base(double(k));
158 }
159 for(k = 0; k < j; k++)
160 pz[k] += azmul(py[j-1], z[j-k-1]) * base_two;
161
162 --j;
163 }
164 px[0] += azmul(pz[0], Base(1.0) + y[0]);
165 }
166
167 } } // END_CPPAD_LOCAL_NAMESPACE
168 # endif
0 # ifndef CPPAD_LOCAL_OP_TANH_OP_HPP
1 # define CPPAD_LOCAL_OP_TANH_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16
17
18 // See dev documentation: forward_unary_op
19 template <class Base>
20 void forward_tanh_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 size_t i_x ,
25 size_t cap_order ,
26 Base* taylor )
27 {
28 // check assumptions
29 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
30 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( q < cap_order );
32 CPPAD_ASSERT_UNKNOWN( p <= q );
33
34 // Taylor coefficients corresponding to argument and result
35 Base* x = taylor + i_x * cap_order;
36 Base* z = taylor + i_z * cap_order;
37 Base* y = z - cap_order;
38
39 size_t k;
40 if( p == 0 )
41 { z[0] = tanh( x[0] );
42 y[0] = z[0] * z[0];
43 p++;
44 }
45 for(size_t j = p; j <= q; j++)
46 { Base base_j = static_cast<Base>(double(j));
47
48 z[j] = x[j];
49 for(k = 1; k <= j; k++)
50 z[j] -= Base(double(k)) * x[k] * y[j-k] / base_j;
51
52 y[j] = z[0] * z[j];
53 for(k = 1; k <= j; k++)
54 y[j] += z[k] * z[j-k];
55 }
56 }
57
58 // See dev documentation: forward_unary_op
59 template <class Base>
60 void forward_tanh_op_dir(
61 size_t q ,
62 size_t r ,
63 size_t i_z ,
64 size_t i_x ,
65 size_t cap_order ,
66 Base* taylor )
67 {
68 // check assumptions
69 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
70 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
71 CPPAD_ASSERT_UNKNOWN( 0 < q );
72 CPPAD_ASSERT_UNKNOWN( q < cap_order );
73
74 // Taylor coefficients corresponding to argument and result
75 size_t num_taylor_per_var = (cap_order-1) * r + 1;
76 Base* x = taylor + i_x * num_taylor_per_var;
77 Base* z = taylor + i_z * num_taylor_per_var;
78 Base* y = z - num_taylor_per_var;
79
80 size_t k;
81 size_t m = (q-1) * r + 1;
82 for(size_t ell = 0; ell < r; ell++)
83 { z[m+ell] = Base(double(q)) * ( x[m+ell] - x[m+ell] * y[0] );
84 for(k = 1; k < q; k++)
85 z[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * y[(q-k-1)*r+1+ell];
86 z[m+ell] /= Base(double(q));
87 //
88 y[m+ell] = Base(2.0) * z[m+ell] * z[0];
89 for(k = 1; k < q; k++)
90 y[m+ell] += z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell];
91 }
92 }
93
94 // See dev documentation: forward_unary_op
95 template <class Base>
96 void forward_tanh_op_0(
97 size_t i_z ,
98 size_t i_x ,
99 size_t cap_order ,
100 Base* taylor )
101 {
102 // check assumptions
103 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
104 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
105 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
106
107 // Taylor coefficients corresponding to argument and result
108 Base* x = taylor + i_x * cap_order;
109 Base* z = taylor + i_z * cap_order; // called z in documentation
110 Base* y = z - cap_order; // called y in documentation
111
112 z[0] = tanh( x[0] );
113 y[0] = z[0] * z[0];
114 }
115
116
117 // See dev documentation: reverse_unary_op
118 template <class Base>
119 void reverse_tanh_op(
120 size_t d ,
121 size_t i_z ,
122 size_t i_x ,
123 size_t cap_order ,
124 const Base* taylor ,
125 size_t nc_partial ,
126 Base* partial )
127 {
128 // check assumptions
129 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
130 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
131 CPPAD_ASSERT_UNKNOWN( d < cap_order );
132 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
133
134 // Taylor coefficients and partials corresponding to argument
135 const Base* x = taylor + i_x * cap_order;
136 Base* px = partial + i_x * nc_partial;
137
138 // Taylor coefficients and partials corresponding to first result
139 const Base* z = taylor + i_z * cap_order; // called z in doc
140 Base* pz = partial + i_z * nc_partial;
141
142 // Taylor coefficients and partials corresponding to auxillary result
143 const Base* y = z - cap_order; // called y in documentation
144 Base* py = pz - nc_partial;
145
146
147 size_t j = d;
148 size_t k;
149 Base base_two(2);
150 while(j)
151 {
152 px[j] += pz[j];
153 pz[j] /= Base(double(j));
154 for(k = 1; k <= j; k++)
155 { px[k] -= azmul(pz[j], y[j-k]) * Base(double(k));
156 py[j-k] -= azmul(pz[j], x[k]) * Base(double(k));
157 }
158 for(k = 0; k < j; k++)
159 pz[k] += azmul(py[j-1], z[j-k-1]) * base_two;
160
161 --j;
162 }
163 px[0] += azmul(pz[0], Base(1.0) - y[0]);
164 }
165
166 } } // END_CPPAD_LOCAL_NAMESPACE
167 # endif
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 /*
12 $begin forward_unary_op$$
13 $spell
14 NumRes
15 Taylor
16 op
17 $$
18
19 $section Variable Forward Unary Operators$$
20
21 $head Syntax$$
22 $codei%forward_%name%_op(%p%, %q%, %i_z%, %i_x%, %cap_order%, %taylor%)%$$
23
24 $head Assumption$$
25 The operator corresponding to $icode name$$ has one argument and one result.
26
27 $head Notation$$
28
29 $subhead x$$
30 We use $icode x$$ to denote the argument of this unary operation.
31
32 $subhead z$$
33 We use $icode z$$ to denote the primary result of this unary operation.
34 If this operator has two results, $codei%NumRes(%op%) == 2%$$,
35 we call the other the auxillary result.
36
37 $head Base$$
38 is the base type for the operator; i.e., this operation was recorded
39 using $codei%AD<%Base%>%$$ and computations by this routine are done using
40 type $icode Base$$.
41
42 $head p$$
43 This argument has type $code size_t$$ and
44 is lowest order of the Taylor coefficient that we are computing.
45
46 $head q$$
47 The argument $icode q >= p$$ has type $code size_t$$ and
48 is highest order of the Taylor coefficient that we are computing.
49
50 $head i_z$$
51 This argument has type $code size_t$$ and
52 is the variable index corresponding to the primary result for this operation;
53 i.e. the row index in taylor corresponding to $icode z$$.
54 If this operator has an auxillary result, its variable index is
55 $icode%i_z% - 1%$$.
56
57 $head i_x$$
58 This argument has type $code size_t$$ and
59 is variable index corresponding to the argument for this operator;
60 i.e. the row index in taylor corresponding to $code x$$.
61
62 $head cap_order$$
63 This argument has type $code size_t$$ and
64 is the maximum number of orders that will fit in $icode taylor$$.
65
66 $head taylor$$
67 This argument has type $icode%Base%*%$$.
68 The Taylor coefficient corresponding to
69 variable $icode i$$ and order $icode k$$ is
70 $codei%
71 %taylor%[ %i% * %cap_order% + %k% ]
72 %$$.
73
74 $subhead Input$$
75 $list number$$
76 The Taylor coefficients for variable $icode i_x$$ up to order $icode q$$.
77 $lnext
78 The Taylor coefficients for variable $icode i_z$$ up to order $icode%p%-1%$$.
79 $lnext
80 If this operator has an auxillary result,
81 the Taylor coefficients for variable $icode%i_z%-1%$$
82 up to order $icode%p%-1%$$.
83 $lend
84
85 $subhead Output$$
86 The Taylor coefficients for variable $icode i_z$$ up to order $icode q$$.
87
88 $end
89 ------------------------------------------------------------------------------
90 $begin forward_unary_op_dir$$
91 $spell
92 NumRes
93 op
94 tpv
95 Taylor
96 $$
97
98 $section Multiple Direction Forward Unary Operators$$
99
100 $head Syntax$$
101 $codei%forward_%name%_op(%q%, %r%, %i_z%, %i_x%, %cap_order%, %taylor%)%$$
102
103 $head Assumption$$
104 The operator corresponding to $icode name$$ has one argument and one result.
105
106 $head Notation$$
107
108 $subhead x$$
109 We use $icode x$$ to denote the argument of this unary operation.
110
111 $subhead z$$
112 We use $icode z$$ to denote the primary result of this unary operation.
113 If this operator has two results, $codei%NumRes(%op%) == 2%$$,
114 we call the other the auxillary result.
115
116 $head Base$$
117 is the base type for the operator; i.e., this operation was recorded
118 using $codei%AD<%Base%>%$$ and computations by this routine are done using
119 type $icode Base$$.
120
121 $head q$$
122 This argument has type $code size_t$$ and
123 is the order of the Taylor coefficients that we are computing.
124 Furthermore $icode%q% > 0%$$ and $icode%q% < %cap_order%$$.
125
126 $head r$$
127 This argument has type $code size_t$$ and
128 is number of directions for Taylor coefficients that we are computing.
129
130 $head i_z$$
131 This argument has type $code size_t$$ and
132 is the variable index corresponding to the primary result for this operation;
133 i.e. the row index in taylor corresponding to $icode z$$.
134 If this operator has an auxillary result, its variable index is
135 $icode%i_z% - 1%$$.
136
137 $head i_x$$
138 This argument has type $code size_t$$ and
139 is variable index corresponding to the argument for this operator;
140 i.e. the row index in taylor corresponding to $code x$$.
141
142 $head cap_order$$
143 This argument has type $code size_t$$ and
144 is the maximum number of orders that will fit in $icode taylor$$.
145 The zero order Taylor coefficient for a variable
146 is the same for all directions. We use the notation
147 $codei%
148 %tpv% = (%cap_order% - 1) * r + 1
149 %$$
150 which is the number of Taylor coefficients per variable.
151
152 $head taylor$$
153 This argument has type $icode%Base%*%$$.
154 The zero order Taylor coefficient for variable $icode i$$ is
155 $codei%
156 %taylor%[ %i% * %tpv% + 0 ]
157 %$$.
158 For $icode k > 0$$,
159 and $icode%ell% = 0 , %..% , %r-1%$$,
160 The Taylor coefficient for variable $icode i$$,
161 order $icode k$$, and direction $icode ell$$ is
162 $codei%
163 %taylor%[ %i% * %tpv% + (%k% - 1) * %r% + %ell% + 1 ]
164 %$$.
165
166 $head Input$$
167 $list number$$
168 The Taylor coefficients for variable $icode i_x$$ up to order $icode q$$
169 and all $icode r$$ directions.
170 $lnext
171 The Taylor coefficients for variable $icode i_z$$ up to order $icode q-1$$
172 and all $icode r$$ directions.
173 $lnext
174 If this operator has an auxillary result,
175 the Taylor coefficients for variable $icode%i_z%-1%$$
176 up to order $icode%q%-1%$$.
177 $lend
178
179 $head Output$$
180 The Taylor coefficients for variable $icode i_z$$ up to order $icode q$$
181 and all $icode r$$ directions.
182
183 $end
184 -------------------------------------------------------------------------------
185 /*
186 $begin forward_unary_op_0$$
187 $spell
188 NumRes
189 op
190 Taylor
191 $$
192
193 $section Zero Order Forward Unary Operators$$
194
195 $head Syntax$$
196 $codei%forward_%name%_op_0(%i_z%, %i_x%, %cap_order%, %taylor%)%$$
197
198 $head Assumption$$
199 The operator corresponding to $icode name$$ has one argument and one result.
200
201 $head Notation$$
202
203 $subhead x$$
204 We use $icode x$$ to denote the argument of this unary operation.
205
206 $subhead z$$
207 We use $icode z$$ to denote the primary result of this unary operation.
208 If this operator has two results, $codei%NumRes(%op%) == 2%$$,
209 we call the other the auxillary result.
210
211 $head Base$$
212 is the base type for the operator; i.e., this operation was recorded
213 using $codei%AD<%Base%>%$$ and computations by this routine are done using
214 type $icode Base$$.
215
216 $head i_z$$
217 This argument has type $code size_t$$ and
218 is the variable index corresponding to the primary result for this operation;
219 i.e. the row index in taylor corresponding to $icode z$$.
220 If this operator has an auxillary result, its variable index is
221 $icode%i_z% - 1%$$.
222
223 $head i_x$$
224 This argument has type $code size_t$$ and
225 is variable index corresponding to the argument for this operator;
226 i.e. the row index in taylor corresponding to $code x$$.
227
228 $head cap_order$$
229 The argument $icode%cap_order% > 0%$$ has type $code size_t$$ and
230 is the maximum number of orders that will fit in $icode taylor$$.
231
232 $head taylor$$
233 This argument has type $icode%Base%*%$$.
234 The Taylor coefficient corresponding to
235 variable $icode i$$ and order $icode k$$ is
236 $codei%
237 %taylor%[ %i% * %cap_order% + %k% ]
238 %$$.
239
240 $subhead Input$$
241 The zero order Taylor coefficients for variable $icode i_x$$.
242
243 $subhead Output$$
244 The zero order Taylor coefficients for variable $icode i_z$$.
245 If this operator has an auxillary result,
246 the Taylor coefficient for variable $icode%i_z%-1%$$.
247
248 $end
249 ------------------------------------------------------------------------------
250 /*
251 $begin reverse_unary_op$$
252 $spell
253 NumRes
254 op
255 Taylor
256 nc
257 const
258 $$
259
260 $section Reverse Unary Operators$$
261
262 $head Syntax$$
263 $codei%reverse_%name%_op(
264 %d%, %i_z%, %i_x%, %cap_order%, %taylor%, %nc_partial%, %partial%
265 )%$$
266
267 $head Assumption$$
268 The operator corresponding to $icode name$$ has one argument and one result.
269
270 $head Notation$$
271
272 $subhead x$$
273 We use $icode x$$ to denote the argument of this unary operation.
274
275 $subhead z$$
276 We use $icode z$$ to denote the primary result of this unary operation.
277 If this operator has two results, $codei%NumRes(%op%) == 2%$$,
278 we call the other the auxillary result.
279
280 $subhead G$$
281 We use $latex G(z, x, w, \ldots )$$ to denote a scalar valued function of the
282 variables up to variable index $icode i_z$$.
283
284 $subhead H$$
285 We use $latex H(x, w, \ldots )$$ to denote the scalar valued function of the
286 variables up to variable index $icode%i_z%-1%$$ defined by
287 $latex \[
288 H(x, w, \ldots ) = G [ z(x), x, w, \ldots ) ]
289 \]$$
290
291 $head Base$$
292 is the base type for the operator; i.e., this operation was recorded
293 using $codei%AD<%Base%>%$$ and computations by this routine are done using
294 type $icode Base$$.
295
296 $head d$$
297 This argument has type $code size_t$$ and
298 is this highest order Taylor coefficient that we are computing
299 partial derivatives with respect to.
300 Furthermore $icode%d% < %cap_order%$$ and $icode%d% < %nc_partial%$$.
301
302 $head i_z$$
303 This argument has type $code size_t$$ and
304 is the variable index corresponding to the primary result for this operation;
305 i.e. the row index in taylor corresponding to $icode z$$.
306 If this operator has an auxillary result, its variable index is
307 $icode%i_z% - 1%$$.
308
309 $head i_x$$
310 This argument has type $code size_t$$ and
311 is variable index corresponding to the argument for this operator;
312 i.e. the row index in taylor corresponding to $code x$$.
313 Furthermore $icode%i_x% < %i_z%$$.
314
315 $head cap_order$$
316 This argument has type $code size_t$$ and
317 is the maximum number of orders that will fit in $icode taylor$$.
318
319 $head taylor$$
320 This argument has type $codei%const %Base%*%$$.
321 The Taylor coefficient corresponding to
322 variable $icode i$$ and order $icode k$$ is
323 $codei%
324 %taylor%[ %i% * %cap_order% + %k% ]
325 %$$.
326
327 $head nc_partial$$
328 This argument has type $code size_t$$ and
329 is the number of columns in the partial array.
330
331 $head partial$$
332 This argument has type $icode%Base%*%$$.
333 The partial derivative w.r.t. variable $icode i$$ and
334 Taylor coefficient order $icode k$$ is
335 $code%
336 %partial% [ %i% * %nc_partial% + k ]
337 %$$
338 for $icode%k% = 0 , %...%, %d%$$.
339
340 $subhead Input$$
341 For variable $icode%i% = 0 ,%...%, %i_z%$$,
342 $icode partial$$ contains the
343 partial derivatives of $latex G(z, x, w, \ldots)$$.
344
345 $subhead Output$$
346 The array $icode partial$$ contains the
347 partial derivatives of $latex H(x, w, \ldots)$$.
348 The partial derivative for variable $icode i_z$$ is unspecified.
349 If this operator has an auxillary result,
350 The partial derivative for variable $icode%i_z% - 1%$$ is unspecified.
351
352 $end
353 ------------------------------------------------------------------------------
0 # ifndef CPPAD_LOCAL_OP_ZMUL_OP_HPP
1 # define CPPAD_LOCAL_OP_ZMUL_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15
16 // --------------------------- Zmulvv -----------------------------------------
17
18 // See dev documentation: forward_binary_op
19 template <class Base>
20 void forward_zmulvv_op(
21 size_t p ,
22 size_t q ,
23 size_t i_z ,
24 const addr_t* arg ,
25 const Base* parameter ,
26 size_t cap_order ,
27 Base* taylor )
28 {
29 // check assumptions
30 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
31 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
32 CPPAD_ASSERT_UNKNOWN( q < cap_order );
33 CPPAD_ASSERT_UNKNOWN( p <= q );
34
35 // Taylor coefficients corresponding to arguments and result
36 Base* x = taylor + size_t(arg[0]) * cap_order;
37 Base* y = taylor + size_t(arg[1]) * cap_order;
38 Base* z = taylor + i_z * cap_order;
39
40 size_t k;
41 for(size_t d = p; d <= q; d++)
42 { z[d] = Base(0.0);
43 for(k = 0; k <= d; k++)
44 z[d] += azmul(x[d-k], y[k]);
45 }
46 }
47
48 // See dev documentation: forward_binary_op
49 template <class Base>
50 void forward_zmulvv_op_dir(
51 size_t q ,
52 size_t r ,
53 size_t i_z ,
54 const addr_t* arg ,
55 const Base* parameter ,
56 size_t cap_order ,
57 Base* taylor )
58 {
59 // check assumptions
60 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
61 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
62 CPPAD_ASSERT_UNKNOWN( 0 < q );
63 CPPAD_ASSERT_UNKNOWN( q < cap_order );
64
65 // Taylor coefficients corresponding to arguments and result
66 size_t num_taylor_per_var = (cap_order-1) * r + 1;
67 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
68 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
69 Base* z = taylor + i_z * num_taylor_per_var;
70
71 size_t k, ell, m;
72 for(ell = 0; ell < r; ell++)
73 { m = (q-1)*r + ell + 1;
74 z[m] = azmul(x[0], y[m]) + azmul(x[m], y[0]);
75 for(k = 1; k < q; k++)
76 z[m] += azmul(x[(q-k-1)*r + ell + 1], y[(k-1)*r + ell + 1]);
77 }
78 }
79
80
81 // See dev documentation: forward_binary_op
82 template <class Base>
83 void forward_zmulvv_op_0(
84 size_t i_z ,
85 const addr_t* arg ,
86 const Base* parameter ,
87 size_t cap_order ,
88 Base* taylor )
89 {
90 // check assumptions
91 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
92 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
93
94 // Taylor coefficients corresponding to arguments and result
95 Base* x = taylor + size_t(arg[0]) * cap_order;
96 Base* y = taylor + size_t(arg[1]) * cap_order;
97 Base* z = taylor + i_z * cap_order;
98
99 z[0] = azmul(x[0], y[0]);
100 }
101
102
103 // See dev documentation: reverse_binary_op
104 template <class Base>
105 void reverse_zmulvv_op(
106 size_t d ,
107 size_t i_z ,
108 const addr_t* arg ,
109 const Base* parameter ,
110 size_t cap_order ,
111 const Base* taylor ,
112 size_t nc_partial ,
113 Base* partial )
114 {
115 // check assumptions
116 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
117 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
118 CPPAD_ASSERT_UNKNOWN( d < cap_order );
119 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
120
121 // Arguments
122 const Base* x = taylor + size_t(arg[0]) * cap_order;
123 const Base* y = taylor + size_t(arg[1]) * cap_order;
124
125 // Partial derivatives corresponding to arguments and result
126 Base* px = partial + size_t(arg[0]) * nc_partial;
127 Base* py = partial + size_t(arg[1]) * nc_partial;
128 Base* pz = partial + i_z * nc_partial;
129
130 // number of indices to access
131 size_t j = d + 1;
132 size_t k;
133 while(j)
134 { --j;
135 for(k = 0; k <= j; k++)
136 {
137 px[j-k] += azmul(pz[j], y[k]);
138 py[k] += azmul(pz[j], x[j-k]);
139 }
140 }
141 }
142 // --------------------------- Zmulpv -----------------------------------------
143
144 // See dev documentation: forward_binary_op
145 template <class Base>
146 void forward_zmulpv_op(
147 size_t p ,
148 size_t q ,
149 size_t i_z ,
150 const addr_t* arg ,
151 const Base* parameter ,
152 size_t cap_order ,
153 Base* taylor )
154 {
155 // check assumptions
156 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
157 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
158 CPPAD_ASSERT_UNKNOWN( q < cap_order );
159 CPPAD_ASSERT_UNKNOWN( p <= q );
160
161 // Taylor coefficients corresponding to arguments and result
162 Base* y = taylor + size_t(arg[1]) * cap_order;
163 Base* z = taylor + i_z * cap_order;
164
165 // Paraemter value
166 Base x = parameter[ arg[0] ];
167
168 for(size_t d = p; d <= q; d++)
169 z[d] = azmul(x, y[d]);
170 }
171
172 // See dev documentation: forward_binary_op
173 template <class Base>
174 void forward_zmulpv_op_dir(
175 size_t q ,
176 size_t r ,
177 size_t i_z ,
178 const addr_t* arg ,
179 const Base* parameter ,
180 size_t cap_order ,
181 Base* taylor )
182 {
183 // check assumptions
184 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
185 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
186 CPPAD_ASSERT_UNKNOWN( 0 < q );
187 CPPAD_ASSERT_UNKNOWN( q < cap_order );
188
189 // Taylor coefficients corresponding to arguments and result
190 size_t num_taylor_per_var = (cap_order-1) * r + 1;
191 size_t m = (q-1) * r + 1;
192 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
193 Base* z = taylor + i_z * num_taylor_per_var + m;
194
195 // Paraemter value
196 Base x = parameter[ arg[0] ];
197
198 for(size_t ell = 0; ell < r; ell++)
199 z[ell] = azmul(x, y[ell]);
200 }
201
202 // See dev documentation: forward_binary_op
203 template <class Base>
204 void forward_zmulpv_op_0(
205 size_t i_z ,
206 const addr_t* arg ,
207 const Base* parameter ,
208 size_t cap_order ,
209 Base* taylor )
210 {
211 // check assumptions
212 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
213 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
214
215 // Paraemter value
216 Base x = parameter[ arg[0] ];
217
218 // Taylor coefficients corresponding to arguments and result
219 Base* y = taylor + size_t(arg[1]) * cap_order;
220 Base* z = taylor + i_z * cap_order;
221
222 z[0] = azmul(x, y[0]);
223 }
224
225
226 // See dev documentation: reverse_binary_op
227 template <class Base>
228 void reverse_zmulpv_op(
229 size_t d ,
230 size_t i_z ,
231 const addr_t* arg ,
232 const Base* parameter ,
233 size_t cap_order ,
234 const Base* taylor ,
235 size_t nc_partial ,
236 Base* partial )
237 {
238 // check assumptions
239 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
240 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
241 CPPAD_ASSERT_UNKNOWN( d < cap_order );
242 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
243
244 // Arguments
245 Base x = parameter[ arg[0] ];
246
247 // Partial derivatives corresponding to arguments and result
248 Base* py = partial + size_t(arg[1]) * nc_partial;
249 Base* pz = partial + i_z * nc_partial;
250
251 // number of indices to access
252 size_t j = d + 1;
253 while(j)
254 { --j;
255 py[j] += azmul(pz[j], x);
256 }
257 }
258 // --------------------------- Zmulvp -----------------------------------------
259
260 // See dev documentation: forward_binary_op
261 template <class Base>
262 void forward_zmulvp_op(
263 size_t p ,
264 size_t q ,
265 size_t i_z ,
266 const addr_t* arg ,
267 const Base* parameter ,
268 size_t cap_order ,
269 Base* taylor )
270 {
271 // check assumptions
272 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
273 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
274 CPPAD_ASSERT_UNKNOWN( q < cap_order );
275 CPPAD_ASSERT_UNKNOWN( p <= q );
276
277 // Taylor coefficients corresponding to arguments and result
278 Base* x = taylor + size_t(arg[0]) * cap_order;
279 Base* z = taylor + i_z * cap_order;
280
281 // Paraemter value
282 Base y = parameter[ arg[1] ];
283
284 for(size_t d = p; d <= q; d++)
285 z[d] = azmul(x[d], y);
286 }
287
288 // See dev documentation: forward_binary_op
289 template <class Base>
290 void forward_zmulvp_op_dir(
291 size_t q ,
292 size_t r ,
293 size_t i_z ,
294 const addr_t* arg ,
295 const Base* parameter ,
296 size_t cap_order ,
297 Base* taylor )
298 {
299 // check assumptions
300 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
301 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
302 CPPAD_ASSERT_UNKNOWN( 0 < q );
303 CPPAD_ASSERT_UNKNOWN( q < cap_order );
304
305 // Taylor coefficients corresponding to arguments and result
306 size_t num_taylor_per_var = (cap_order-1) * r + 1;
307 size_t m = (q-1) * r + 1;
308 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var + m;
309 Base* z = taylor + i_z * num_taylor_per_var + m;
310
311 // Paraemter value
312 Base y = parameter[ arg[1] ];
313
314 for(size_t ell = 0; ell < r; ell++)
315 z[ell] = azmul(x[ell], y);
316 }
317
318 // See dev documentation: forward_binary_op
319 template <class Base>
320 void forward_zmulvp_op_0(
321 size_t i_z ,
322 const addr_t* arg ,
323 const Base* parameter ,
324 size_t cap_order ,
325 Base* taylor )
326 {
327 // check assumptions
328 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
329 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
330
331 // Paraemter value
332 Base y = parameter[ arg[1] ];
333
334 // Taylor coefficients corresponding to arguments and result
335 Base* x = taylor + size_t(arg[0]) * cap_order;
336 Base* z = taylor + i_z * cap_order;
337
338 z[0] = azmul(x[0], y);
339 }
340
341
342 // See dev documentation: reverse_binary_op
343 template <class Base>
344 void reverse_zmulvp_op(
345 size_t d ,
346 size_t i_z ,
347 const addr_t* arg ,
348 const Base* parameter ,
349 size_t cap_order ,
350 const Base* taylor ,
351 size_t nc_partial ,
352 Base* partial )
353 {
354 // check assumptions
355 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
356 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
357 CPPAD_ASSERT_UNKNOWN( d < cap_order );
358 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
359
360 // Arguments
361 Base y = parameter[ arg[1] ];
362
363 // Partial derivatives corresponding to arguments and result
364 Base* px = partial + size_t(arg[0]) * nc_partial;
365 Base* pz = partial + i_z * nc_partial;
366
367 // number of indices to access
368 size_t j = d + 1;
369 while(j)
370 { --j;
371 px[j] += azmul(pz[j], y);
372 }
373 }
374
375 } } // END_CPPAD_LOCAL_NAMESPACE
376 # endif
00 # ifndef CPPAD_LOCAL_OP_HPP
11 # define CPPAD_LOCAL_OP_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
1616
1717 // operations
1818 # include <cppad/core/std_math_11.hpp>
19 # include <cppad/local/abs_op.hpp>
20 # include <cppad/local/add_op.hpp>
21 # include <cppad/local/acos_op.hpp>
22 # include <cppad/local/acosh_op.hpp>
23 # include <cppad/local/asin_op.hpp>
24 # include <cppad/local/asinh_op.hpp>
25 # include <cppad/local/atan_op.hpp>
26 # include <cppad/local/atanh_op.hpp>
27 # include <cppad/local/comp_op.hpp>
28 # include <cppad/local/cond_op.hpp>
29 # include <cppad/local/cos_op.hpp>
30 # include <cppad/local/cosh_op.hpp>
31 # include <cppad/local/cskip_op.hpp>
32 # include <cppad/local/csum_op.hpp>
33 # include <cppad/local/discrete_op.hpp>
34 # include <cppad/local/div_op.hpp>
35 # include <cppad/local/erf_op.hpp>
36 # include <cppad/local/exp_op.hpp>
37 # include <cppad/local/expm1_op.hpp>
38 # include <cppad/local/load_op.hpp>
39 # include <cppad/local/log_op.hpp>
40 # include <cppad/local/log1p_op.hpp>
41 # include <cppad/local/mul_op.hpp>
42 # include <cppad/local/parameter_op.hpp>
43 # include <cppad/local/pow_op.hpp>
44 # include <cppad/local/print_op.hpp>
45 # include <cppad/local/sign_op.hpp>
46 # include <cppad/local/sin_op.hpp>
47 # include <cppad/local/sinh_op.hpp>
48 # include <cppad/local/sqrt_op.hpp>
49 # include <cppad/local/sub_op.hpp>
19 # include <cppad/local/op/abs_op.hpp>
20 # include <cppad/local/op/add_op.hpp>
21 # include <cppad/local/op/acos_op.hpp>
22 # include <cppad/local/op/acosh_op.hpp>
23 # include <cppad/local/op/asin_op.hpp>
24 # include <cppad/local/op/asinh_op.hpp>
25 # include <cppad/local/op/atan_op.hpp>
26 # include <cppad/local/op/atanh_op.hpp>
27 # include <cppad/local/op/comp_op.hpp>
28 # include <cppad/local/op/cond_op.hpp>
29 # include <cppad/local/op/cos_op.hpp>
30 # include <cppad/local/op/cosh_op.hpp>
31 # include <cppad/local/op/cskip_op.hpp>
32 # include <cppad/local/op/csum_op.hpp>
33 # include <cppad/local/op/discrete_op.hpp>
34 # include <cppad/local/op/div_op.hpp>
35 # include <cppad/local/op/erf_op.hpp>
36 # include <cppad/local/op/exp_op.hpp>
37 # include <cppad/local/op/expm1_op.hpp>
38 # include <cppad/local/op/load_op.hpp>
39 # include <cppad/local/op/log_op.hpp>
40 # include <cppad/local/op/log1p_op.hpp>
41 # include <cppad/local/op/mul_op.hpp>
42 # include <cppad/local/op/neg_op.hpp>
43 # include <cppad/local/op/parameter_op.hpp>
44 # include <cppad/local/op/pow_op.hpp>
45 # include <cppad/local/op/print_op.hpp>
46 # include <cppad/local/op/sign_op.hpp>
47 # include <cppad/local/op/sin_op.hpp>
48 # include <cppad/local/op/sinh_op.hpp>
49 # include <cppad/local/op/sqrt_op.hpp>
50 # include <cppad/local/op/sub_op.hpp>
5051 # include <cppad/local/sparse/binary_op.hpp>
5152 # include <cppad/local/sparse/unary_op.hpp>
52 # include <cppad/local/store_op.hpp>
53 # include <cppad/local/tan_op.hpp>
54 # include <cppad/local/tanh_op.hpp>
55 # include <cppad/local/zmul_op.hpp>
53 # include <cppad/local/op/store_op.hpp>
54 # include <cppad/local/op/tan_op.hpp>
55 # include <cppad/local/op/tanh_op.hpp>
56 # include <cppad/local/op/zmul_op.hpp>
5657
5758
5859 # endif
00 # ifndef CPPAD_LOCAL_OP_CODE_DYN_HPP
11 # define CPPAD_LOCAL_OP_CODE_DYN_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
176176 log1p_dyn, // unary
177177 log_dyn, // unary
178178 mul_dyn, // binary
179 neg_dyn, // unary
179180 pow_dyn, // binary
180181 result_dyn, // 0 arguments: atomic function result
181182 sign_dyn, // unary
262263 /* log1p_dyn */ 1,
263264 /* log_dyn */ 1,
264265 /* mul_dyn */ 2,
266 /* neg_dyn */ 1,
265267 /* pow_dyn */ 2,
266268 /* result_dyn */ 0,
267269 /* sign_dyn */ 1,
351353 /* log1p_dyn */ "log1p",
352354 /* log_dyn */ "log",
353355 /* mul_dyn */ "mul",
356 /* neg_dyn */ "neg",
354357 /* pow_dyn */ "pow",
355358 /* result_dyn */ "result",
356359 /* sign_dyn */ "sign",
00 # ifndef CPPAD_LOCAL_OP_CODE_VAR_HPP
11 # define CPPAD_LOCAL_OP_CODE_VAR_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
5555 Funav
5656 Funrp
5757 Funrv
58 Powpv
59 Powvv
5860 $$
5961
6062 $head Namespace$$
103105 operand is a parameter and the right operand is a variable.
104106
105107 $subhead Pow$$
106 The binary $codei%pow(%x%, %y%)%$$ operators are
108 The binary $codei%pow(%x%, %y%)%$$ operators PowpvOp, PowvvOp are
107109 special because they have three variable results instead of one.
108110 To be specific, they compute
109111 $codei%log(%x%)%$$,
447449 LtvvOp, // ...
448450 MulpvOp, // binary *
449451 MulvvOp, // ...
452 NegOp, // unary negative
450453 NeppOp, // compare !=
451454 NepvOp, // ...
452455 NevvOp, // ...
453456 ParOp, // see its heading above
454 PowpvOp, // see Pow heading above
455 PowvpOp, // ...
456 PowvvOp, // ...
457 PowpvOp, // see its heading above
458 PowvpOp, // binary
459 PowvvOp, // see its heading above
457460 PriOp, // see its heading above
458461 SignOp, // unary sign
459462 SinOp, // unary sin
553556 2, // LtvvOp
554557 2, // MulpvOp
555558 2, // MulvvOp
559 1, // NegOp
556560 2, // NeppOp
557561 2, // NepvOp
558562 2, // NevvOp
671675 0, // LtvvOp
672676 1, // MulpvOp
673677 1, // MulvvOp
678 1, // NegOp
674679 0, // NeppOp
675680 0, // NepvOp
676681 0, // NevvOp
677682 1, // ParOp
678683 3, // PowpvOp
679 3, // PowvpOp
684 1, // PowvpOp
680685 3, // PowvvOp
681686 0, // PriOp
682687 1, // SignOp
767772 "Ltvv" ,
768773 "Mulpv" ,
769774 "Mulvv" ,
775 "Neg" ,
770776 "Nepp" ,
771777 "Nepv" ,
772778 "Nevv" ,
10901096 case Expm1Op:
10911097 case LogOp:
10921098 case Log1pOp:
1099 case NegOp:
10931100 case SignOp:
10941101 case SinOp:
10951102 case SinhOp:
13241331 case ExpOp:
13251332 case Log1pOp:
13261333 case LogOp:
1334 case NegOp:
13271335 case SignOp:
13281336 case SinhOp:
13291337 case SinOp:
00 # ifndef CPPAD_LOCAL_OPTIMIZE_GET_DYN_PREVIOUS_HPP
11 # define CPPAD_LOCAL_OPTIMIZE_GET_DYN_PREVIOUS_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
250250 case fabs_dyn:
251251 case log_dyn:
252252 case log1p_dyn:
253 case neg_dyn:
253254 case sign_dyn:
254255 case sin_dyn:
255256 case sinh_dyn:
00 # ifndef CPPAD_LOCAL_OPTIMIZE_GET_OP_PREVIOUS_HPP
11 # define CPPAD_LOCAL_OPTIMIZE_GET_OP_PREVIOUS_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
206206 case LtvvOp:
207207 case MulpvOp:
208208 case MulvvOp:
209 case NegOp:
209210 case NepvOp:
210211 case NevvOp:
211212 case PowpvOp:
00 # ifndef CPPAD_LOCAL_OPTIMIZE_GET_OP_USAGE_HPP
11 # define CPPAD_LOCAL_OPTIMIZE_GET_OP_USAGE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
410410 case Expm1Op:
411411 case LogOp:
412412 case Log1pOp:
413 case NegOp:
413414 case PowvpOp:
414415 case SignOp:
415416 case SinOp:
00 # ifndef CPPAD_LOCAL_OPTIMIZE_GET_PAR_USAGE_HPP
11 # define CPPAD_LOCAL_OPTIMIZE_GET_PAR_USAGE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
232232 case Log1pOp:
233233 case LtvvOp:
234234 case MulvvOp:
235 case NegOp:
235236 case NevvOp:
236237 case PowvvOp:
237238 case SignOp:
297297 dyn_previous
298298 );
299299 // -----------------------------------------------------------------------
300
301300 // conditional expression information
302301 //
303302 // Size of the conditional expression information structure.
699698 case Expm1Op:
700699 case LogOp:
701700 case Log1pOp:
701 case NegOp:
702702 case SignOp:
703703 case SinOp:
704704 case SinhOp:
11851185 CPPAD_ASSERT_NARG_NRES(op, 1, 0);
11861186 new_arg[0] = new_par[ arg[0] ];
11871187 if( new_arg[0] == addr_t_max )
1188 { // This parameter is not used, so we put zero here. If we
1189 // put nan here, atomic reverse mode would have to use azmul.
11881190 new_arg[0] = zero_par_index;
1191 }
11891192 rec->PutArg(new_arg[0]);
11901193 new_op[i_op] = addr_t( rec->num_op_rec() );
11911194 rec->PutOp(FunapOp);
12061209 rec->PutOp(FunavOp);
12071210 }
12081211 else
1209 { // This argument does not affect the result and
1210 // has been optimized out so use nan in its place.
1212 { // This argument does not affect the result.
12111213 new_arg[0] = zero_par_index;
12121214 rec->PutArg(new_arg[0]);
12131215 new_op[i_op] = addr_t( rec->num_op_rec() );
12451247 if( op_usage[i_op] == usage_t(yes_usage) )
12461248 new_var[i_op] = rec->PutOp(FunrvOp);
12471249 else
1248 { // change FunrvOp -> FunrpOp to avoid creating new variable
1250 { // This result is not used.
12491251 CPPAD_ASSERT_UNKNOWN( op_usage[i_op] == usage_t(no_usage) );
12501252 CPPAD_ASSERT_NARG_NRES(FunrpOp, 1, 0);
12511253 rec->PutArg( zero_par_index );
+0
-89
include/cppad/local/parameter_op.hpp less more
0 # ifndef CPPAD_LOCAL_PARAMETER_OP_HPP
1 # define CPPAD_LOCAL_PARAMETER_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file parameter_op.hpp
18 Zero order forward mode for ParOp
19 */
20
21
22 /*!
23 Compute zero order forward mode Taylor coefficient for result of op = ParOp.
24
25 The C++ source code corresponding to this operation is one of the following
26 \verbatim
27 ADFun<Base> f(x, y)
28 f.Dependent(x, y)
29 \endverbatim
30 where some of the components of the vector y are parameters.
31
32 \tparam Base
33 base type for the operator; i.e., this operation was recorded
34 using AD< Base > and computations by this routine are done using type
35 Base .
36
37 \param i_z
38 variable index corresponding to the result for this operation;
39 i.e. the row index in taylor corresponding to the component of y
40 that is a parameter.
41
42 \param arg
43 arg[0]
44 \n
45 index corresponding to the parameter value for this operator.
46
47 \param num_par
48 is the number of parameters in parameter.
49
50 \param parameter
51 \b Input: parameter[ arg[0] ] is the value of a component
52 of y that is a parameter.
53
54 \param cap_order
55 number of colums in the matrix containing all the Taylor coefficients.
56
57 \param taylor
58 \b Output: taylor [ i_z * cap_order + 0 ]
59 is the zero order Taylor coefficient corresponding to z.
60
61 \par Checked Assertions where op is the unary operator with one result:
62 \li NumArg(op) == 1
63 \li NumRes(op) == 1
64 \li size_t(arg[0]) < num_par
65 \li 0 < cap_order
66 */
67 template <class Base>
68 void forward_par_op_0(
69 size_t i_z ,
70 const addr_t* arg ,
71 size_t num_par ,
72 const Base* parameter ,
73 size_t cap_order ,
74 Base* taylor )
75 {
76 // check assumptions
77 CPPAD_ASSERT_UNKNOWN( NumArg(ParOp) == 1 );
78 CPPAD_ASSERT_UNKNOWN( NumRes(ParOp) == 1 );
79 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_par );
80 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
81
82 Base* z = taylor + i_z * cap_order;
83
84 z[0] = parameter[ arg[0] ];
85 }
86
87 } } // END_CPPAD_LOCAL_NAMESPACE
88 # endif
00 # ifndef CPPAD_LOCAL_PLAY_PLAYER_HPP
11 # define CPPAD_LOCAL_PLAY_PLAYER_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
320320 case LogOp:
321321 case Log1pOp:
322322 case LtvpOp:
323 case NegOp:
323324 case PowvpOp:
324325 case SignOp:
325326 case SinOp:
735736
736737 /// A measure of amount of memory used to store
737738 /// the operation sequence, just lengths, not capacities.
738 /// In user api as f.size_op_seq(); see the file seq_property.omh.
739 /// In user api as f.size_op_seq(); see the file fun_property.omh.
739740 size_t size_op_seq(void) const
740741 { // check assumptions made by ad_fun<Base>::size_op_seq()
741742 CPPAD_ASSERT_UNKNOWN( op_vec_.size() == num_op_rec() );
755756 ;
756757 }
757758 /// A measure of amount of memory used for random access routine
758 /// In user api as f.size_random(); see the file seq_property.omh.
759 /// In user api as f.size_random(); see the file fun_property.omh.
759760 size_t size_random(void) const
760761 {
761762 # ifndef NDEBUG
+0
-672
include/cppad/local/pow_op.hpp less more
0 # ifndef CPPAD_LOCAL_POW_OP_HPP
1 # define CPPAD_LOCAL_POW_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file pow_op.hpp
17 Forward and reverse mode calculations for z = pow(x, y).
18 */
19
20 // --------------------------- Powvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = PowvvOp.
23
24 In the documentation below,
25 this operations is for the case where both x and y are variables
26 and the argument parameter is not used.
27
28 \copydetails CppAD::local::forward_pow_op
29 */
30
31 template <class Base>
32 void forward_powvv_op(
33 size_t p ,
34 size_t q ,
35 size_t i_z ,
36 const addr_t* arg ,
37 const Base* parameter ,
38 size_t cap_order ,
39 Base* taylor )
40 {
41 // convert from final result to first result
42 i_z -= 2; // 2 = NumRes(PowvvOp) - 1;
43
44 // check assumptions
45 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
46 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
47 CPPAD_ASSERT_UNKNOWN( q < cap_order );
48 CPPAD_ASSERT_UNKNOWN( p <= q );
49 CPPAD_ASSERT_UNKNOWN(
50 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
51 );
52
53 // z_0 = log(x)
54 forward_log_op(p, q, i_z, size_t(arg[0]), cap_order, taylor);
55
56 // z_1 = z_0 * y
57 addr_t adr[2];
58 adr[0] = addr_t( i_z );
59 adr[1] = arg[1];
60 forward_mulvv_op(p, q, i_z+1, adr, parameter, cap_order, taylor);
61
62 // z_2 = exp(z_1)
63 // final result for zero order case is exactly the same as for Base
64 if( p == 0 )
65 { // Taylor coefficients corresponding to arguments and result
66 Base* x = taylor + size_t(arg[0]) * cap_order;
67 Base* y = taylor + size_t(arg[1]) * cap_order;
68 Base* z_2 = taylor + (i_z+2) * cap_order;
69
70 z_2[0] = pow(x[0], y[0]);
71 p++;
72 }
73 if( p <= q )
74 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
75 }
76 /*!
77 Multiple directions forward mode Taylor coefficients for op = PowvvOp.
78
79 The C++ source code corresponding to this operation is
80 \verbatim
81 z = pow(x, y)
82 \endverbatim
83 In the documentation below,
84 this operations is for the case where x is a variable and y is a parameter.
85
86 \copydetails CppAD::local::forward_pow_op_dir
87 */
88
89 template <class Base>
90 void forward_powvv_op_dir(
91 size_t q ,
92 size_t r ,
93 size_t i_z ,
94 const addr_t* arg ,
95 const Base* parameter ,
96 size_t cap_order ,
97 Base* taylor )
98 {
99 // convert from final result to first result
100 i_z -= 2; // 2 = NumRes(PowvvOp) - 1
101
102 // check assumptions
103 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
104 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
105 CPPAD_ASSERT_UNKNOWN( 0 < q );
106 CPPAD_ASSERT_UNKNOWN( q < cap_order );
107 CPPAD_ASSERT_UNKNOWN(
108 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
109 );
110
111 // z_0 = log(x)
112 forward_log_op_dir(q, r, i_z, size_t(arg[0]), cap_order, taylor);
113
114 // z_1 = y * z_0
115 addr_t adr[2];
116 adr[0] = addr_t( i_z );
117 adr[1] = arg[1];
118 forward_mulvv_op_dir(q, r, i_z+1, adr, parameter, cap_order, taylor);
119
120 // z_2 = exp(z_1)
121 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
122 }
123 /*!
124 Compute zero order forward mode Taylor coefficients for result of op = PowvvOp.
125
126 The C++ source code corresponding to this operation is
127 \verbatim
128 z = pow(x, y)
129 \endverbatim
130 In the documentation below,
131 this operations is for the case where both x and y are variables
132 and the argument parameter is not used.
133
134 \copydetails CppAD::local::forward_pow_op_0
135 */
136
137 template <class Base>
138 void forward_powvv_op_0(
139 size_t i_z ,
140 const addr_t* arg ,
141 const Base* parameter ,
142 size_t cap_order ,
143 Base* taylor )
144 {
145 // convert from final result to first result
146 i_z -= 2; // NumRes(PowvvOp) - 1;
147
148 // check assumptions
149 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
150 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
151
152 // Taylor coefficients corresponding to arguments and result
153 Base* x = taylor + size_t(arg[0]) * cap_order;
154 Base* y = taylor + size_t(arg[1]) * cap_order;
155 Base* z_0 = taylor + i_z * cap_order;
156 Base* z_1 = z_0 + cap_order;
157 Base* z_2 = z_1 + cap_order;
158
159 z_0[0] = log( x[0] );
160 z_1[0] = z_0[0] * y[0];
161 z_2[0] = pow(x[0], y[0]);
162
163 }
164
165 /*!
166 Compute reverse mode partial derivatives for result of op = PowvvOp.
167
168 The C++ source code corresponding to this operation is
169 \verbatim
170 z = pow(x, y)
171 \endverbatim
172 In the documentation below,
173 this operations is for the case where both x and y are variables
174 and the argument parameter is not used.
175
176 \copydetails CppAD::local::reverse_pow_op
177 */
178
179 template <class Base>
180 void reverse_powvv_op(
181 size_t d ,
182 size_t i_z ,
183 const addr_t* arg ,
184 const Base* parameter ,
185 size_t cap_order ,
186 const Base* taylor ,
187 size_t nc_partial ,
188 Base* partial )
189 {
190 // convert from final result to first result
191 i_z -= 2; // NumRes(PowvvOp) - 1;
192
193 // check assumptions
194 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
195 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
196 CPPAD_ASSERT_UNKNOWN( d < cap_order );
197 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
198 CPPAD_ASSERT_UNKNOWN(
199 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
200 );
201
202 // z_2 = exp(z_1)
203 reverse_exp_op(
204 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
205 );
206
207 // z_1 = z_0 * y
208 addr_t adr[2];
209 adr[0] = addr_t( i_z );
210 adr[1] = arg[1];
211 reverse_mulvv_op(
212 d, i_z+1, adr, parameter, cap_order, taylor, nc_partial, partial
213 );
214
215 // z_0 = log(x)
216 reverse_log_op(
217 d, i_z, size_t(arg[0]), cap_order, taylor, nc_partial, partial
218 );
219 }
220
221 // --------------------------- Powpv -----------------------------------------
222 /*!
223 Compute forward mode Taylor coefficients for result of op = PowpvOp.
224
225 The C++ source code corresponding to this operation is
226 \verbatim
227 z = pow(x, y)
228 \endverbatim
229 In the documentation below,
230 this operations is for the case where x is a parameter and y is a variable.
231
232 \copydetails CppAD::local::forward_pow_op
233 */
234
235 template <class Base>
236 void forward_powpv_op(
237 size_t p ,
238 size_t q ,
239 size_t i_z ,
240 const addr_t* arg ,
241 const Base* parameter ,
242 size_t cap_order ,
243 Base* taylor )
244 {
245 // convert from final result to first result
246 i_z -= 2; // 2 = NumRes(PowpvOp) - 1;
247
248 // check assumptions
249 CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 );
250 CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 );
251 CPPAD_ASSERT_UNKNOWN( q < cap_order );
252 CPPAD_ASSERT_UNKNOWN( p <= q );
253
254 // Taylor coefficients corresponding to arguments and result
255 Base* z_0 = taylor + i_z * cap_order;
256
257 // z_0 = log(x)
258 Base x = parameter[ arg[0] ];
259 size_t d;
260 for(d = p; d <= q; d++)
261 { if( d == 0 )
262 z_0[d] = log(x);
263 else
264 z_0[d] = Base(0.0);
265 }
266
267 // 2DO: remove requirement that i_z * cap_order <= max addr_t value
268 CPPAD_ASSERT_KNOWN(
269 size_t( std::numeric_limits<addr_t>::max() ) >= i_z * cap_order,
270 "cppad_tape_addr_type maximum value has been exceeded\n"
271 "This is due to a kludge in the pow operation and should be fixed."
272 );
273
274 // z_1 = z_0 * y
275 addr_t adr[2];
276 // offset of z_i in taylor (as if it were a parameter); i.e., log(x)
277 adr[0] = addr_t( i_z * cap_order );
278 // offset of y in taylor (as a variable)
279 adr[1] = arg[1];
280
281 // Trick: use taylor both for the parameter vector and variable values
282 forward_mulpv_op(p, q, i_z+1, adr, taylor, cap_order, taylor);
283
284 // z_2 = exp(z_1)
285 // zero order case exactly same as Base type operation
286 if( p == 0 )
287 { Base* y = taylor + size_t(arg[1]) * cap_order;
288 Base* z_2 = taylor + (i_z+2) * cap_order;
289 z_2[0] = pow(x, y[0]);
290 p++;
291 }
292 if( p <= q )
293 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
294 }
295 /*!
296 Multiple directions forward mode Taylor coefficients for op = PowpvOp.
297
298 The C++ source code corresponding to this operation is
299 \verbatim
300 z = pow(x, y)
301 \endverbatim
302 In the documentation below,
303 this operations is for the case where x is a parameter and y is a variable.
304
305 \copydetails CppAD::local::forward_pow_op_dir
306 */
307
308 template <class Base>
309 void forward_powpv_op_dir(
310 size_t q ,
311 size_t r ,
312 size_t i_z ,
313 const addr_t* arg ,
314 const Base* parameter ,
315 size_t cap_order ,
316 Base* taylor )
317 {
318 // convert from final result to first result
319 i_z -= 2; // 2 = NumRes(PowpvOp) - 1;
320
321 // check assumptions
322 CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 );
323 CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 );
324 CPPAD_ASSERT_UNKNOWN( 0 < q );
325 CPPAD_ASSERT_UNKNOWN( q < cap_order );
326
327 // Taylor coefficients corresponding to arguments and result
328 size_t num_taylor_per_var = (cap_order-1) * r + 1;
329 Base* z_0 = taylor + i_z * num_taylor_per_var;
330
331 // z_0 = log(x)
332 size_t m = (q-1) * r + 1;
333 for(size_t ell = 0; ell < r; ell++)
334 z_0[m+ell] = Base(0.0);
335
336 // 2DO: remove requirement i_z * num_taylor_per_var <= max addr_t value
337 CPPAD_ASSERT_KNOWN(
338 size_t( std::numeric_limits<addr_t>::max() ) >= i_z * num_taylor_per_var,
339 "cppad_tape_addr_type maximum value has been exceeded\n"
340 "This is due to a kludge in the pow operation and should be fixed."
341 );
342
343 // z_1 = z_0 * y
344 addr_t adr[2];
345 // offset of z_0 in taylor (as if it were a parameter); i.e., log(x)
346 adr[0] = addr_t( i_z * num_taylor_per_var );
347 // ofset of y in taylor (as a variable)
348 adr[1] = arg[1];
349
350 // Trick: use taylor both for the parameter vector and variable values
351 forward_mulpv_op_dir(q, r, i_z+1, adr, taylor, cap_order, taylor);
352
353 // z_2 = exp(z_1)
354 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
355 }
356 /*!
357 Compute zero order forward mode Taylor coefficient for result of op = PowpvOp.
358
359 The C++ source code corresponding to this operation is
360 \verbatim
361 z = pow(x, y)
362 \endverbatim
363 In the documentation below,
364 this operations is for the case where x is a parameter and y is a variable.
365
366 \copydetails CppAD::local::forward_pow_op_0
367 */
368
369 template <class Base>
370 void forward_powpv_op_0(
371 size_t i_z ,
372 const addr_t* arg ,
373 const Base* parameter ,
374 size_t cap_order ,
375 Base* taylor )
376 {
377 // convert from final result to first result
378 i_z -= 2; // NumRes(PowpvOp) - 1;
379
380 // check assumptions
381 CPPAD_ASSERT_UNKNOWN( NumArg(PowpvOp) == 2 );
382 CPPAD_ASSERT_UNKNOWN( NumRes(PowpvOp) == 3 );
383
384 // Paraemter value
385 Base x = parameter[ arg[0] ];
386
387 // Taylor coefficients corresponding to arguments and result
388 Base* y = taylor + size_t(arg[1]) * cap_order;
389 Base* z_0 = taylor + i_z * cap_order;
390 Base* z_1 = z_0 + cap_order;
391 Base* z_2 = z_1 + cap_order;
392
393 // z_0 = log(x)
394 z_0[0] = log(x);
395
396 // z_1 = z_0 * y
397 z_1[0] = z_0[0] * y[0];
398
399 // z_2 = exp(z_1)
400 // zero order case exactly same as Base type operation
401 z_2[0] = pow(x, y[0]);
402 }
403
404 /*!
405 Compute reverse mode partial derivative for result of op = PowpvOp.
406
407 The C++ source code corresponding to this operation is
408 \verbatim
409 z = pow(x, y)
410 \endverbatim
411 In the documentation below,
412 this operations is for the case where x is a parameter and y is a variable.
413
414 \copydetails CppAD::local::reverse_pow_op
415 */
416
417 template <class Base>
418 void reverse_powpv_op(
419 size_t d ,
420 size_t i_z ,
421 const addr_t* arg ,
422 const Base* parameter ,
423 size_t cap_order ,
424 const Base* taylor ,
425 size_t nc_partial ,
426 Base* partial )
427 {
428 // convert from final result to first result
429 i_z -= 2; // NumRes(PowpvOp) - 1;
430
431 // check assumptions
432 CPPAD_ASSERT_UNKNOWN( NumArg(PowvvOp) == 2 );
433 CPPAD_ASSERT_UNKNOWN( NumRes(PowvvOp) == 3 );
434 CPPAD_ASSERT_UNKNOWN( d < cap_order );
435 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
436
437 // z_2 = exp(z_1)
438 reverse_exp_op(
439 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
440 );
441
442 // 2DO: remove requirement that i_z * cap_order <= max addr_t value
443 CPPAD_ASSERT_KNOWN(
444 size_t( std::numeric_limits<addr_t>::max() ) >= i_z * cap_order,
445 "cppad_tape_addr_type maximum value has been exceeded\n"
446 "This is due to a kludge in the pow operation and should be fixed."
447 );
448
449 // z_1 = z_0 * y
450 addr_t adr[2];
451 adr[0] = addr_t( i_z * cap_order ); // offset of z_0[0] in taylor
452 adr[1] = arg[1]; // index of y in taylor and partial
453 // use taylor both for parameter and variable values
454 reverse_mulpv_op(
455 d, i_z+1, adr, taylor, cap_order, taylor, nc_partial, partial
456 );
457
458 // z_0 = log(x)
459 // x is a parameter
460 }
461
462 // --------------------------- Powvp -----------------------------------------
463 /*!
464 Compute forward mode Taylor coefficients for result of op = PowvpOp.
465
466 The C++ source code corresponding to this operation is
467 \verbatim
468 z = pow(x, y)
469 \endverbatim
470 In the documentation below,
471 this operations is for the case where x is a variable and y is a parameter.
472
473 \copydetails CppAD::local::forward_pow_op
474 */
475
476 template <class Base>
477 void forward_powvp_op(
478 size_t p ,
479 size_t q ,
480 size_t i_z ,
481 const addr_t* arg ,
482 const Base* parameter ,
483 size_t cap_order ,
484 Base* taylor )
485 {
486 // convert from final result to first result
487 i_z -= 2; // 2 = NumRes(PowvpOp) - 1
488
489 // check assumptions
490 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
491 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 );
492 CPPAD_ASSERT_UNKNOWN( q < cap_order );
493 CPPAD_ASSERT_UNKNOWN( p <= q );
494 CPPAD_ASSERT_UNKNOWN(
495 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
496 );
497
498 // z_0 = log(x)
499 forward_log_op(p, q, i_z, size_t(arg[0]), cap_order, taylor);
500
501 // z_1 = y * z_0
502 addr_t adr[2];
503 adr[0] = arg[1];
504 adr[1] = addr_t( i_z );
505 forward_mulpv_op(p, q, i_z+1, adr, parameter, cap_order, taylor);
506
507 // z_2 = exp(z_1)
508 // zero order case exactly same as Base type operation
509 if( p == 0 )
510 { Base* z_2 = taylor + (i_z+2) * cap_order;
511 Base* x = taylor + size_t(arg[0]) * cap_order;
512 Base y = parameter[ arg[1] ];
513 z_2[0] = pow(x[0], y);
514 p++;
515 }
516 if( p <= q )
517 forward_exp_op(p, q, i_z+2, i_z+1, cap_order, taylor);
518 }
519 /*!
520 Multiple directions forward mode Taylor coefficients for op = PowvpOp.
521
522 The C++ source code corresponding to this operation is
523 \verbatim
524 z = pow(x, y)
525 \endverbatim
526 In the documentation below,
527 this operations is for the case where x is a variable and y is a parameter.
528
529 \copydetails CppAD::local::forward_pow_op_dir
530 */
531
532 template <class Base>
533 void forward_powvp_op_dir(
534 size_t q ,
535 size_t r ,
536 size_t i_z ,
537 const addr_t* arg ,
538 const Base* parameter ,
539 size_t cap_order ,
540 Base* taylor )
541 {
542 // convert from final result to first result
543 i_z -= 2; // 2 = NumRes(PowvpOp) - 1
544
545 // check assumptions
546 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
547 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 );
548 CPPAD_ASSERT_UNKNOWN( 0 < q );
549 CPPAD_ASSERT_UNKNOWN( q < cap_order );
550 CPPAD_ASSERT_UNKNOWN(
551 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
552 );
553
554 // z_0 = log(x)
555 forward_log_op_dir(q, r, i_z, size_t(arg[0]), cap_order, taylor);
556
557 // z_1 = y * z_0
558 addr_t adr[2];
559 adr[0] = arg[1];
560 adr[1] = addr_t( i_z );
561 forward_mulpv_op_dir(q, r, i_z+1, adr, parameter, cap_order, taylor);
562
563 // z_2 = exp(z_1)
564 forward_exp_op_dir(q, r, i_z+2, i_z+1, cap_order, taylor);
565 }
566
567 /*!
568 Compute zero order forward mode Taylor coefficients for result of op = PowvpOp.
569
570 The C++ source code corresponding to this operation is
571 \verbatim
572 z = pow(x, y)
573 \endverbatim
574 In the documentation below,
575 this operations is for the case where x is a variable and y is a parameter.
576
577 \copydetails CppAD::local::forward_pow_op_0
578 */
579
580 template <class Base>
581 void forward_powvp_op_0(
582 size_t i_z ,
583 const addr_t* arg ,
584 const Base* parameter ,
585 size_t cap_order ,
586 Base* taylor )
587 {
588 // convert from final result to first result
589 i_z -= 2; // NumRes(PowvpOp) - 1;
590
591 // check assumptions
592 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
593 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 );
594
595 // Paraemter value
596 Base y = parameter[ arg[1] ];
597
598 // Taylor coefficients corresponding to arguments and result
599 Base* x = taylor + size_t(arg[0]) * cap_order;
600 Base* z_0 = taylor + i_z * cap_order;
601 Base* z_1 = z_0 + cap_order;
602 Base* z_2 = z_1 + cap_order;
603
604 // z_0 = log(x)
605 z_0[0] = log(x[0]);
606
607 // z_1 = z_0 * y
608 z_1[0] = z_0[0] * y;
609
610 // z_2 = exp(z_1)
611 // zero order case exactly same as Base type operation
612 z_2[0] = pow(x[0], y);
613 }
614
615 /*!
616 Compute reverse mode partial derivative for result of op = PowvpOp.
617
618 The C++ source code corresponding to this operation is
619 \verbatim
620 z = pow(x, y)
621 \endverbatim
622 In the documentation below,
623 this operations is for the case where x is a variable and y is a parameter.
624
625 \copydetails CppAD::local::reverse_pow_op
626 */
627
628 template <class Base>
629 void reverse_powvp_op(
630 size_t d ,
631 size_t i_z ,
632 const addr_t* arg ,
633 const Base* parameter ,
634 size_t cap_order ,
635 const Base* taylor ,
636 size_t nc_partial ,
637 Base* partial )
638 {
639 // convert from final result to first result
640 i_z -= 2; // NumRes(PowvpOp) - 1;
641
642 // check assumptions
643 CPPAD_ASSERT_UNKNOWN( NumArg(PowvpOp) == 2 );
644 CPPAD_ASSERT_UNKNOWN( NumRes(PowvpOp) == 3 );
645 CPPAD_ASSERT_UNKNOWN( d < cap_order );
646 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
647 CPPAD_ASSERT_UNKNOWN(
648 size_t( std::numeric_limits<addr_t>::max() ) >= i_z
649 );
650
651 // z_2 = exp(z_1)
652 reverse_exp_op(
653 d, i_z+2, i_z+1, cap_order, taylor, nc_partial, partial
654 );
655
656 // z_1 = y * z_0
657 addr_t adr[2];
658 adr[0] = arg[1];
659 adr[1] = addr_t( i_z );
660 reverse_mulpv_op(
661 d, i_z+1, adr, parameter, cap_order, taylor, nc_partial, partial
662 );
663
664 // z_0 = log(x)
665 reverse_log_op(
666 d, i_z, size_t(arg[0]), cap_order, taylor, nc_partial, partial
667 );
668 }
669
670 } } // END_CPPAD_LOCAL_NAMESPACE
671 # endif
+0
-147
include/cppad/local/print_op.hpp less more
0 # ifndef CPPAD_LOCAL_PRINT_OP_HPP
1 # define CPPAD_LOCAL_PRINT_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 Print operation for parameters; i.e., op = PriOp.
18
19 The C++ source code corresponding to this operation is
20 \verbatim
21 f.Forward(0, x)
22 PrintFor(before, var)
23 PrintFor(pos, before, var, after)
24 \endverbatim
25 The PrintFor call puts the print operation on the tape
26 and the print occurs during the zero order forward mode computation.
27
28 \tparam Base
29 base type for the operator; i.e., this operation was recorded
30 using AD< Base > and computations by this routine are done using type
31 Base .
32
33 \param s_out
34 the results are printed on this output stream.
35
36 \param arg
37 arg[0] & 1
38 \n
39 If this is zero, pos is a parameter. Otherwise it is a variable.
40 \n
41 arg[0] & 2
42 \n
43 If this is zero, var is a parameter. Otherwise it is a variable.
44 \n
45 \n
46 arg[1]
47 \n
48 If pos is a parameter, <code>parameter[arg[1]]</code> is its value.
49 Othwise <code>taylor[ size_t(arg[1]) * cap_order + 0 ]</code> is the zero
50 order Taylor coefficient for pos.
51 \n
52 \n
53 arg[2]
54 \n
55 index of the text to be printed before var
56 if pos is not a positive value.
57 \n
58 \n
59 arg[3]
60 \n
61 If var is a parameter, <code>parameter[arg[3]]</code> is its value.
62 Othwise <code>taylor[ size_t(arg[3]) * cap_order + 0 ]</code> is the zero
63 order Taylor coefficient for var.
64 \n
65 \n
66 arg[4]
67 \n
68 index of the text to be printed after var
69 if pos is not a positive value.
70
71 \param num_text
72 is the total number of text characters on the tape
73 (only used for error checking).
74
75 \param text
76 \b Input: <code>text[arg[1]]</code> is the first character of the text
77 that will be printed. All the characters from there to (but not including)
78 the first '\\0' are printed.
79
80 \param num_par
81 is the total number of values in the parameter vector
82
83 \param parameter
84 Contains the value of parameters.
85
86 \param cap_order
87 number of colums in the matrix containing all the Taylor coefficients.
88
89 \param taylor
90 Contains the value of variables.
91
92 \par Checked Assertions:
93 \li NumArg(PriOp) == 5
94 \li NumRes(PriOp) == 0
95 \li text != nullptr
96 \li arg[1] < num_text
97 \li if pos is a parameter, arg[1] < num_par
98 \li if var is a parameter, arg[3] < num_par
99 */
100 template <class Base>
101 void forward_pri_0(
102 std::ostream& s_out ,
103 const addr_t* arg ,
104 size_t num_text ,
105 const char* text ,
106 size_t num_par ,
107 const Base* parameter ,
108 size_t cap_order ,
109 const Base* taylor )
110 { Base pos, var;
111 const char* before;
112 const char* after;
113 CPPAD_ASSERT_NARG_NRES(PriOp, 5, 0);
114
115 // pos
116 if( arg[0] & 1 )
117 { pos = taylor[ size_t(arg[1]) * cap_order + 0 ];
118 }
119 else
120 { CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
121 pos = parameter[ arg[1] ];
122 }
123
124 // before
125 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_text );
126 before = text + arg[2];
127
128 // var
129 if( arg[0] & 2 )
130 { var = taylor[ size_t(arg[3]) * cap_order + 0 ];
131 }
132 else
133 { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par );
134 var = parameter[ arg[3] ];
135 }
136
137 // after
138 CPPAD_ASSERT_UNKNOWN( size_t(arg[4]) < num_text );
139 after = text + arg[4];
140
141 if( ! GreaterThanZero( pos ) )
142 s_out << before << var << after;
143 }
144
145 } } // END_CPPAD_LOCAL_NAMESPACE
146 # endif
+0
-1458
include/cppad/local/prototype_op.hpp less more
0 # ifndef CPPAD_LOCAL_PROTOTYPE_OP_HPP
1 # define CPPAD_LOCAL_PROTOTYPE_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file prototype_op.hpp
18 Documentation for generic cases (these generic cases are never used).
19 */
20
21 // ==================== Unary operators with one result ====================
22
23
24 /*!
25 Prototype for forward mode unary operator with one result (not used).
26
27 \tparam Base
28 base type for the operator; i.e., this operation was recorded
29 using AD< Base > and computations by this routine are done using type
30 Base.
31
32 \param p
33 lowest order of the Taylor coefficient that we are computing.
34
35 \param q
36 highest order of the Taylor coefficient that we are computing.
37
38 \param i_z
39 variable index corresponding to the result for this operation;
40 i.e. the row index in taylor corresponding to z.
41
42 \param i_x
43 variable index corresponding to the argument for this operator;
44 i.e. the row index in taylor corresponding to x.
45
46 \param cap_order
47 maximum number of orders that will fit in the taylor array.
48
49 \param taylor
50 \b Input: <code>taylor [ i_x * cap_order + k ]</code>,
51 for k = 0 , ... , q,
52 is the k-th order Taylor coefficient corresponding to x.
53 \n
54 \b Input: <code>taylor [ i_z * cap_order + k ]</code>,
55 for k = 0 , ... , p-1,
56 is the k-th order Taylor coefficient corresponding to z.
57 \n
58 \b Output: <code>taylor [ i_z * cap_order + k ]</code>,
59 for k = p , ... , q,
60 is the k-th order Taylor coefficient corresponding to z.
61
62 \par Checked Assertions
63 \li NumArg(op) == 1
64 \li NumRes(op) == 1
65 \li q < cap_order
66 \li p <= q
67 */
68 template <class Base>
69 void forward_unary1_op(
70 size_t p ,
71 size_t q ,
72 size_t i_z ,
73 size_t i_x ,
74 size_t cap_order ,
75 Base* taylor )
76 {
77 // This routine is only for documentaiton, it should not be used
78 CPPAD_ASSERT_UNKNOWN( false );
79 }
80
81 /*!
82 Prototype for multiple direction forward mode unary operator with one result
83 (not used).
84
85 \tparam Base
86 base type for the operator; i.e., this operation was recorded
87 using AD< Base > and computations by this routine are done using type
88 Base.
89
90 \param q
91 order of the Taylor coefficients that we are computing.
92
93 \param r
94 number of directions for Taylor coefficients that we are computing.
95
96 \param i_z
97 variable index corresponding to the last (primary) result for this operation;
98 i.e. the row index in taylor corresponding to z.
99
100 \param i_x
101 variable index corresponding to the argument for this operator;
102 i.e. the row index in taylor corresponding to x.
103
104 \param cap_order
105 maximum number of orders that will fit in the taylor array.
106
107 \par tpv
108 We use the notation
109 <code>tpv = (cap_order-1) * r + 1</code>
110 which is the number of Taylor coefficients per variable
111
112 \param taylor
113 \b Input: If x is a variable,
114 <code>taylor [ arg[0] * tpv + 0 ]</code>,
115 is the zero order Taylor coefficient for all directions and
116 <code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
117 for k = 1 , ... , q,
118 ell = 0, ..., r-1,
119 is the k-th order Taylor coefficient
120 corresponding to x and the ell-th direction.
121 \n
122 \b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
123 is the zero order Taylor coefficient for all directions and
124 <code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
125 for k = 1 , ... , q-1,
126 ell = 0, ..., r-1,
127 is the k-th order Taylor coefficient
128 corresponding to z and the ell-th direction.
129 \n
130 \b Output:
131 <code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
132 ell = 0, ..., r-1,
133 is the q-th order Taylor coefficient
134 corresponding to z and the ell-th direction.
135
136 \par Checked Assertions
137 \li NumArg(op) == 1
138 \li NumRes(op) == 2
139 \li i_x < i_z
140 \li 0 < q
141 \li q < cap_order
142 */
143 template <class Base>
144 void forward_unary1_op_dir(
145 size_t q ,
146 size_t r ,
147 size_t i_z ,
148 size_t i_x ,
149 size_t cap_order ,
150 Base* taylor )
151 {
152 // This routine is only for documentaiton, it should not be used
153 CPPAD_ASSERT_UNKNOWN( false );
154 }
155
156 /*!
157 Prototype for zero order forward mode unary operator with one result (not used).
158 \tparam Base
159 base type for the operator; i.e., this operation was recorded
160 using AD< Base > and computations by this routine are done using type
161 Base .
162
163 \param i_z
164 variable index corresponding to the result for this operation;
165 i.e. the row index in taylor corresponding to z.
166
167 \param i_x
168 variable index corresponding to the argument for this operator;
169 i.e. the row index in taylor corresponding to x.
170
171 \param cap_order
172 maximum number of orders that will fit in the taylor array.
173
174 \param taylor
175 \b Input: taylor [ i_x * cap_order + 0 ]
176 is the zero order Taylor coefficient corresponding to x.
177 \n
178 \b Output: taylor [ i_z * cap_order + 0 ]
179 is the zero order Taylor coefficient corresponding to z.
180
181 \par Checked Assertions
182 \li NumArg(op) == 1
183 \li NumRes(op) == 1
184 \li i_x < i_z
185 \li 0 < cap_order
186 */
187 template <class Base>
188 void forward_unary1_op_0(
189 size_t i_z ,
190 size_t i_x ,
191 size_t cap_order ,
192 Base* taylor )
193 {
194 // This routine is only for documentaiton, it should not be used
195 CPPAD_ASSERT_UNKNOWN( false );
196 }
197
198 /*!
199 Prototype for reverse mode unary operator with one result (not used).
200
201 This routine is given the partial derivatives of a function
202 G(z , x , w, u ... )
203 and it uses them to compute the partial derivatives of
204 \verbatim
205 H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ]
206 \endverbatim
207
208 \tparam Base
209 base type for the operator; i.e., this operation was recorded
210 using AD< Base > and computations by this routine are done using type
211 Base .
212
213 \param d
214 highest order Taylor coefficient that
215 we are computing the partial derivatives with respect to.
216
217 \param i_z
218 variable index corresponding to the result for this operation;
219 i.e. the row index in taylor to z.
220
221 \param i_x
222 variable index corresponding to the argument for this operation;
223 i.e. the row index in taylor corresponding to x.
224
225 \param cap_order
226 maximum number of orders that will fit in the taylor array.
227
228 \param taylor
229 taylor [ i_x * cap_order + k ]
230 for k = 0 , ... , d
231 is the k-th order Taylor coefficient corresponding to x.
232 \n
233 taylor [ i_z * cap_order + k ]
234 for k = 0 , ... , d
235 is the k-th order Taylor coefficient corresponding to z.
236
237 \param nc_partial
238 number of colums in the matrix containing all the partial derivatives.
239
240 \param partial
241 \b Input: partial [ i_x * nc_partial + k ]
242 for k = 0 , ... , d
243 is the partial derivative of G( z , x , w , u , ... ) with respect to
244 the k-th order Taylor coefficient for x.
245 \n
246 \b Input: partial [ i_z * nc_partial + k ]
247 for k = 0 , ... , d
248 is the partial derivative of G( z , x , w , u , ... ) with respect to
249 the k-th order Taylor coefficient for z.
250 \n
251 \b Output: partial [ i_x * nc_partial + k ]
252 for k = 0 , ... , d
253 is the partial derivative of H( x , w , u , ... ) with respect to
254 the k-th order Taylor coefficient for x.
255 \n
256 \b Output: partial [ i_z * nc_partial + k ]
257 for k = 0 , ... , d
258 may be used as work space; i.e., may change in an unspecified manner.
259
260
261 \par Checked Assumptions
262 \li NumArg(op) == 1
263 \li NumRes(op) == 1
264 \li i_x < i_z
265 \li d < cap_order
266 \li d < nc_partial
267 */
268 template <class Base>
269 void reverse_unary1_op(
270 size_t d ,
271 size_t i_z ,
272 size_t i_x ,
273 size_t cap_order ,
274 const Base* taylor ,
275 size_t nc_partial ,
276 Base* partial )
277 {
278 // This routine is only for documentaiton, it should not be used
279 CPPAD_ASSERT_UNKNOWN( false );
280 }
281
282 // ==================== Unary operators with two results ====================
283
284 /*!
285 Prototype for forward mode unary operator with two results (not used).
286
287 \tparam Base
288 base type for the operator; i.e., this operation was recorded
289 using AD< Base > and computations by this routine are done using type
290 Base.
291
292 \param p
293 lowest order of the Taylor coefficients that we are computing.
294
295 \param q
296 highest order of the Taylor coefficients that we are computing.
297
298 \param i_z
299 variable index corresponding to the last (primary) result for this operation;
300 i.e. the row index in taylor corresponding to z.
301 The auxillary result is called y has index i_z - 1.
302
303 \param i_x
304 variable index corresponding to the argument for this operator;
305 i.e. the row index in taylor corresponding to x.
306
307 \param cap_order
308 maximum number of orders that will fit in the taylor array.
309
310 \param taylor
311 \b Input: <code>taylor [ i_x * cap_order + k ]</code>
312 for k = 0 , ... , q,
313 is the k-th order Taylor coefficient corresponding to x.
314 \n
315 \b Input: <code>taylor [ i_z * cap_order + k ]</code>
316 for k = 0 , ... , p - 1,
317 is the k-th order Taylor coefficient corresponding to z.
318 \n
319 \b Input: <code>taylor [ ( i_z - 1) * cap_order + k ]</code>
320 for k = 0 , ... , p-1,
321 is the k-th order Taylor coefficient corresponding to the auxillary result y.
322 \n
323 \b Output: <code>taylor [ i_z * cap_order + k ]</code>,
324 for k = p , ... , q,
325 is the k-th order Taylor coefficient corresponding to z.
326 \n
327 \b Output: <code>taylor [ ( i_z - 1 ) * cap_order + k ]</code>,
328 for k = p , ... , q,
329 is the k-th order Taylor coefficient corresponding to
330 the autillary result y.
331
332 \par Checked Assertions
333 \li NumArg(op) == 1
334 \li NumRes(op) == 2
335 \li i_x + 1 < i_z
336 \li q < cap_order
337 \li p <= q
338 */
339 template <class Base>
340 void forward_unary2_op(
341 size_t p ,
342 size_t q ,
343 size_t i_z ,
344 size_t i_x ,
345 size_t cap_order ,
346 Base* taylor )
347 {
348 // This routine is only for documentaiton, it should not be used
349 CPPAD_ASSERT_UNKNOWN( false );
350 }
351
352 /*!
353 Prototype for multiple direction forward mode unary operator with two results
354 (not used).
355
356 \tparam Base
357 base type for the operator; i.e., this operation was recorded
358 using AD< Base > and computations by this routine are done using type
359 Base.
360
361 \param q
362 order of the Taylor coefficients that we are computing.
363
364 \param r
365 number of directions for Taylor coefficients that we are computing.
366
367 \param i_z
368 variable index corresponding to the last (primary) result for this operation;
369 i.e. the row index in taylor corresponding to z.
370 The auxillary result is called y has index i_z - 1.
371
372 \param i_x
373 variable index corresponding to the argument for this operator;
374 i.e. the row index in taylor corresponding to x.
375
376 \param cap_order
377 maximum number of orders that will fit in the taylor array.
378
379 \par tpv
380 We use the notation
381 <code>tpv = (cap_order-1) * r + 1</code>
382 which is the number of Taylor coefficients per variable
383
384 \param taylor
385 \b Input: <code>taylor [ i_x * tpv + 0 ]</code>
386 is the zero order Taylor coefficient for all directions and
387 <code>taylor [ i_x * tpv + (k-1)*r + ell + 1</code>
388 for k = 1 , ... , q,
389 ell = 0 , ..., r-1,
390 is the k-th order Taylor coefficient
391 corresponding to x and the ell-th direction.
392 \n
393 \b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
394 is the zero order Taylor coefficient for all directions and
395 <code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
396 for k = 1 , ... , q-1,
397 ell = 0, ..., r-1,
398 is the k-th order Taylor coefficient
399 corresponding to z and the ell-th direction.
400 \n
401 \b Input: <code>taylor [ (i_z-1) * tpv + 0 ]</code>,
402 is the zero order Taylor coefficient for all directions and
403 <code>taylor [ (i_z-1) * tpv + (k-1)*r + ell + 1 ]</code>,
404 for k = 1 , ... , q-1,
405 ell = 0, ..., r-1,
406 is the k-th order Taylor coefficient
407 corresponding to the auxillary result y and the ell-th direction.
408 \n
409 \b Output:
410 <code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
411 ell = 0, ..., r-1,
412 is the q-th order Taylor coefficient
413 corresponding to z and the ell-th direction.
414
415 \par Checked Assertions
416 \li NumArg(op) == 1
417 \li NumRes(op) == 2
418 \li i_x + 1 < i_z
419 \li 0 < q
420 \li q < cap_order
421 */
422 template <class Base>
423 void forward_unary2_op_dir(
424 size_t q ,
425 size_t r ,
426 size_t i_z ,
427 size_t i_x ,
428 size_t cap_order ,
429 Base* taylor )
430 {
431 // This routine is only for documentaiton, it should not be used
432 CPPAD_ASSERT_UNKNOWN( false );
433 }
434
435 /*!
436 Prototype for zero order forward mode unary operator with two results (not used).
437 \tparam Base
438 base type for the operator; i.e., this operation was recorded
439 using AD< Base > and computations by this routine are done using type
440 Base .
441
442 \param i_z
443 variable index corresponding to the last (primary) result for this operation;
444 i.e. the row index in taylor corresponding to z.
445 The auxillary result is called y and has index i_z - 1.
446
447 \param i_x
448 variable index corresponding to the argument for this operator;
449 i.e. the row index in taylor corresponding to x.
450
451 \param cap_order
452 maximum number of orders that will fit in the taylor array.
453
454 \param taylor
455 \b Input: taylor [ i_x * cap_order + 0 ]
456 is the zero order Taylor coefficient corresponding to x.
457 \n
458 \b Output: taylor [ i_z * cap_order + 0 ]
459 is the zero order Taylor coefficient corresponding to z.
460 \n
461 \b Output: taylor [ ( i_z - 1 ) * cap_order + j ]
462 is the j-th order Taylor coefficient corresponding to
463 the autillary result y.
464
465 \par Checked Assertions
466 \li NumArg(op) == 1
467 \li NumRes(op) == 2
468 \li i_x + 1 < i_z
469 \li j < cap_order
470 */
471 template <class Base>
472 void forward_unary2_op_0(
473 size_t i_z ,
474 size_t i_x ,
475 size_t cap_order ,
476 Base* taylor )
477 {
478 // This routine is only for documentaiton, it should not be used
479 CPPAD_ASSERT_UNKNOWN( false );
480 }
481
482 /*!
483 Prototype for reverse mode unary operator with two results (not used).
484
485 This routine is given the partial derivatives of a function
486 G( z , y , x , w , ... )
487 and it uses them to compute the partial derivatives of
488 \verbatim
489 H( x , w , u , ... ) = G[ z(x) , y(x), x , w , u , ... ]
490 \endverbatim
491
492 \tparam Base
493 base type for the operator; i.e., this operation was recorded
494 using AD< Base > and computations by this routine are done using type
495 Base .
496
497 \param d
498 highest order Taylor coefficient that
499 we are computing the partial derivatives with respect to.
500
501 \param i_z
502 variable index corresponding to the last (primary) result for this operation;
503 i.e. the row index in taylor to z.
504 The auxillary result is called y and has index i_z - 1.
505
506 \param i_x
507 variable index corresponding to the argument for this operation;
508 i.e. the row index in taylor corresponding to x.
509
510 \param cap_order
511 maximum number of orders that will fit in the taylor array.
512
513 \param taylor
514 taylor [ i_x * cap_order + k ]
515 for k = 0 , ... , d
516 is the k-th order Taylor coefficient corresponding to x.
517 \n
518 taylor [ i_z * cap_order + k ]
519 for k = 0 , ... , d
520 is the k-th order Taylor coefficient corresponding to z.
521 \n
522 taylor [ ( i_z - 1) * cap_order + k ]
523 for k = 0 , ... , d
524 is the k-th order Taylor coefficient corresponding to
525 the auxillary variable y.
526
527 \param nc_partial
528 number of colums in the matrix containing all the partial derivatives.
529
530 \param partial
531 \b Input: partial [ i_x * nc_partial + k ]
532 for k = 0 , ... , d
533 is the partial derivative of
534 G( z , y , x , w , u , ... )
535 with respect to the k-th order Taylor coefficient for x.
536 \n
537 \b Input: partial [ i_z * nc_partial + k ]
538 for k = 0 , ... , d
539 is the partial derivative of G( z , y , x , w , u , ... ) with respect to
540 the k-th order Taylor coefficient for z.
541 \n
542 \b Input: partial [ ( i_z - 1) * nc_partial + k ]
543 for k = 0 , ... , d
544 is the partial derivative of G( z , x , w , u , ... ) with respect to
545 the k-th order Taylor coefficient for the auxillary variable y.
546 \n
547 \b Output: partial [ i_x * nc_partial + k ]
548 for k = 0 , ... , d
549 is the partial derivative of H( x , w , u , ... ) with respect to
550 the k-th order Taylor coefficient for x.
551 \n
552 \b Output: partial [ ( i_z - j ) * nc_partial + k ]
553 for j = 0 , 1 , and for k = 0 , ... , d
554 may be used as work space; i.e., may change in an unspecified manner.
555
556
557 \par Checked Assumptions
558 \li NumArg(op) == 1
559 \li NumRes(op) == 2
560 \li i_x + 1 < i_z
561 \li d < cap_order
562 \li d < nc_partial
563 */
564 template <class Base>
565 void reverse_unary2_op(
566 size_t d ,
567 size_t i_z ,
568 size_t i_x ,
569 size_t cap_order ,
570 const Base* taylor ,
571 size_t nc_partial ,
572 Base* partial )
573 {
574 // This routine is only for documentaiton, it should not be used
575 CPPAD_ASSERT_UNKNOWN( false );
576 }
577 // =================== Binary operators with one result ====================
578
579 /*!
580 Prototype forward mode x op y (not used)
581
582 \tparam Base
583 base type for the operator; i.e., this operation was recorded
584 using AD< Base > and computations by this routine are done using type
585 Base.
586
587 \param p
588 lowest order of the Taylor coefficient that we are computing.
589
590 \param q
591 highest order of the Taylor coefficient that we are computing.
592
593 \param i_z
594 variable index corresponding to the result for this operation;
595 i.e. the row index in taylor corresponding to z.
596
597 \param arg
598 arg[0]
599 index corresponding to the left operand for this operator;
600 i.e. the index corresponding to x.
601 \n
602 arg[1]
603 index corresponding to the right operand for this operator;
604 i.e. the index corresponding to y.
605
606 \param parameter
607 If x is a parameter, parameter [ arg[0] ]
608 is the value corresponding to x.
609 \n
610 If y is a parameter, parameter [ arg[1] ]
611 is the value corresponding to y.
612
613 \param cap_order
614 maximum number of orders that will fit in the taylor array.
615
616 \param taylor
617 \b Input: If x is a variable,
618 <code>taylor [ size_t(arg[0]) * cap_order + k ]</code>,
619 for k = 0 , ... , q,
620 is the k-th order Taylor coefficient corresponding to x.
621 \n
622 \b Input: If y is a variable,
623 <code>taylor [ size_t(arg[1]) * cap_order + k ]</code>,
624 for k = 0 , ... , q,
625 is the k-th order Taylor coefficient corresponding to y.
626 \n
627 \b Input: <code>taylor [ i_z * cap_order + k ]</code>,
628 for k = 0 , ... , p-1,
629 is the k-th order Taylor coefficient corresponding to z.
630 \n
631 \b Output: <code>taylor [ i_z * cap_order + k ]</code>,
632 for k = p, ... , q,
633 is the k-th order Taylor coefficient corresponding to z.
634
635 \par Checked Assertions
636 \li NumArg(op) == 2
637 \li NumRes(op) == 1
638 \li q < cap_order
639 \li p <= q
640 */
641 template <class Base>
642 void forward_binary_op(
643 size_t p ,
644 size_t q ,
645 size_t i_z ,
646 const addr_t* arg ,
647 const Base* parameter ,
648 size_t cap_order ,
649 Base* taylor )
650 {
651 // This routine is only for documentaiton, it should not be used
652 CPPAD_ASSERT_UNKNOWN( false );
653 }
654
655 /*!
656 Prototype multiple direction forward mode x op y (not used)
657
658 \tparam Base
659 base type for the operator; i.e., this operation was recorded
660 using AD< Base > and computations by this routine are done using type
661 Base.
662
663 \param q
664 is the order of the Taylor coefficients that we are computing.
665
666 \param r
667 number of directions for Taylor coefficients that we are computing
668
669 \param i_z
670 variable index corresponding to the result for this operation;
671 i.e. the row index in taylor corresponding to z.
672
673 \param arg
674 arg[0]
675 index corresponding to the left operand for this operator;
676 i.e. the index corresponding to x.
677 \n
678 arg[1]
679 index corresponding to the right operand for this operator;
680 i.e. the index corresponding to y.
681
682 \param parameter
683 If x is a parameter, parameter [ arg[0] ]
684 is the value corresponding to x.
685 \n
686 If y is a parameter, parameter [ arg[1] ]
687 is the value corresponding to y.
688
689 \param cap_order
690 maximum number of orders that will fit in the taylor array.
691
692 \par tpv
693 We use the notation
694 <code>tpv = (cap_order-1) * r + 1</code>
695 which is the number of Taylor coefficients per variable
696
697 \param taylor
698 \b Input: If x is a variable,
699 <code>taylor [ arg[0] * tpv + 0 ]</code>,
700 is the zero order Taylor coefficient for all directions and
701 <code>taylor [ arg[0] * tpv + (k-1)*r + ell + 1 ]</code>,
702 for k = 1 , ... , q,
703 ell = 0, ..., r-1,
704 is the k-th order Taylor coefficient
705 corresponding to x and the ell-th direction.
706 \n
707 \b Input: If y is a variable,
708 <code>taylor [ arg[1] * tpv + 0 ]</code>,
709 is the zero order Taylor coefficient for all directions and
710 <code>taylor [ arg[1] * tpv + (k-1)*r + ell + 1 ]</code>,
711 for k = 1 , ... , q,
712 ell = 0, ..., r-1,
713 is the k-th order Taylor coefficient
714 corresponding to y and the ell-th direction.
715 \n
716 \b Input: <code>taylor [ i_z * tpv + 0 ]</code>,
717 is the zero order Taylor coefficient for all directions and
718 <code>taylor [ i_z * tpv + (k-1)*r + ell + 1 ]</code>,
719 for k = 1 , ... , q-1,
720 ell = 0, ..., r-1,
721 is the k-th order Taylor coefficient
722 corresponding to z and the ell-th direction.
723 \n
724 \b Output:
725 <code>taylor [ i_z * tpv + (q-1)*r + ell + 1]</code>,
726 ell = 0, ..., r-1,
727 is the q-th order Taylor coefficient
728 corresponding to z and the ell-th direction.
729
730 \par Checked Assertions
731 \li NumArg(op) == 2
732 \li NumRes(op) == 1
733 \li 0 < q < cap_order
734 */
735 template <class Base>
736 void forward_binary_op_dir(
737 size_t q ,
738 size_t r ,
739 size_t i_z ,
740 const addr_t* arg ,
741 const Base* parameter ,
742 size_t cap_order ,
743 Base* taylor )
744 {
745 // This routine is only for documentaiton, it should not be used
746 CPPAD_ASSERT_UNKNOWN( false );
747 }
748
749
750 /*!
751 Prototype zero order forward mode x op y (not used)
752
753 \tparam Base
754 base type for the operator; i.e., this operation was recorded
755 using AD< Base > and computations by this routine are done using type
756 Base.
757
758 \param i_z
759 variable index corresponding to the result for this operation;
760 i.e. the row index in taylor corresponding to z.
761
762 \param arg
763 arg[0]
764 index corresponding to the left operand for this operator;
765 i.e. the index corresponding to x.
766 \n
767 arg[1]
768 index corresponding to the right operand for this operator;
769 i.e. the index corresponding to y.
770
771 \param parameter
772 If x is a parameter, parameter [ arg[0] ]
773 is the value corresponding to x.
774 \n
775 If y is a parameter, parameter [ arg[1] ]
776 is the value corresponding to y.
777
778 \param cap_order
779 maximum number of orders that will fit in the taylor array.
780
781 \param taylor
782 \b Input: If x is a variable, taylor [ arg[0] * cap_order + 0 ]
783 is the zero order Taylor coefficient corresponding to x.
784 \n
785 \b Input: If y is a variable, taylor [ arg[1] * cap_order + 0 ]
786 is the zero order Taylor coefficient corresponding to y.
787 \n
788 \b Output: taylor [ i_z * cap_order + 0 ]
789 is the zero order Taylor coefficient corresponding to z.
790
791 \par Checked Assertions
792 \li NumArg(op) == 2
793 \li NumRes(op) == 1
794 */
795 template <class Base>
796 void forward_binary_op_0(
797 size_t i_z ,
798 const addr_t* arg ,
799 const Base* parameter ,
800 size_t cap_order ,
801 Base* taylor )
802 {
803 // This routine is only for documentaiton, it should not be used
804 CPPAD_ASSERT_UNKNOWN( false );
805 }
806
807 /*!
808 Prototype for reverse mode binary operator x op y (not used).
809
810 This routine is given the partial derivatives of a function
811 G( z , y , x , w , ... )
812 and it uses them to compute the partial derivatives of
813 \verbatim
814 H( y , x , w , u , ... ) = G[ z(x , y) , y , x , w , u , ... ]
815 \endverbatim
816
817 \tparam Base
818 base type for the operator; i.e., this operation was recorded
819 using AD< Base > and computations by this routine are done using type
820 Base .
821
822 \param d
823 highest order Taylor coefficient that
824 we are computing the partial derivatives with respect to.
825
826 \param i_z
827 variable index corresponding to the result for this operation;
828 i.e. the row index in taylor corresponding to z.
829
830 \param arg
831 arg[0]
832 index corresponding to the left operand for this operator;
833 i.e. the index corresponding to x.
834 \n
835 arg[1]
836 index corresponding to the right operand for this operator;
837 i.e. the index corresponding to y.
838
839 \param parameter
840 If x is a parameter, parameter [ arg[0] ]
841 is the value corresponding to x.
842 \n
843 If y is a parameter, parameter [ arg[1] ]
844 is the value corresponding to y.
845
846 \param cap_order
847 maximum number of orders that will fit in the taylor array.
848
849 \param taylor
850 taylor [ i_z * cap_order + k ]
851 for k = 0 , ... , d
852 is the k-th order Taylor coefficient corresponding to z.
853 \n
854 If x is a variable, taylor [ arg[0] * cap_order + k ]
855 for k = 0 , ... , d
856 is the k-th order Taylor coefficient corresponding to x.
857 \n
858 If y is a variable, taylor [ arg[1] * cap_order + k ]
859 for k = 0 , ... , d
860 is the k-th order Taylor coefficient corresponding to y.
861
862 \param nc_partial
863 number of colums in the matrix containing all the partial derivatives.
864
865 \param partial
866 \b Input: partial [ i_z * nc_partial + k ]
867 for k = 0 , ... , d
868 is the partial derivative of
869 G( z , y , x , w , u , ... )
870 with respect to the k-th order Taylor coefficient for z.
871 \n
872 \b Input: If x is a variable, partial [ arg[0] * nc_partial + k ]
873 for k = 0 , ... , d
874 is the partial derivative of G( z , y , x , w , u , ... ) with respect to
875 the k-th order Taylor coefficient for x.
876 \n
877 \b Input: If y is a variable, partial [ arg[1] * nc_partial + k ]
878 for k = 0 , ... , d
879 is the partial derivative of G( z , x , w , u , ... ) with respect to
880 the k-th order Taylor coefficient for the auxillary variable y.
881 \n
882 \b Output: If x is a variable, partial [ arg[0] * nc_partial + k ]
883 for k = 0 , ... , d
884 is the partial derivative of H( y , x , w , u , ... ) with respect to
885 the k-th order Taylor coefficient for x.
886 \n
887 \b Output: If y is a variable, partial [ arg[1] * nc_partial + k ]
888 for k = 0 , ... , d
889 is the partial derivative of H( y , x , w , u , ... ) with respect to
890 the k-th order Taylor coefficient for y.
891 \n
892 \b Output: partial [ i_z * nc_partial + k ]
893 for k = 0 , ... , d
894 may be used as work space; i.e., may change in an unspecified manner.
895
896 \par Checked Assumptions
897 \li NumArg(op) == 2
898 \li NumRes(op) == 1
899 \li If x is a variable, arg[0] < i_z
900 \li If y is a variable, arg[1] < i_z
901 \li d < cap_order
902 \li d < nc_partial
903 */
904 template <class Base>
905 void reverse_binary_op(
906 size_t d ,
907 size_t i_z ,
908 addr_t* arg ,
909 const Base* parameter ,
910 size_t cap_order ,
911 const Base* taylor ,
912 size_t nc_partial ,
913 Base* partial )
914 {
915 // This routine is only for documentaiton, it should not be used
916 CPPAD_ASSERT_UNKNOWN( false );
917 }
918 // ======================= Pow Function ===================================
919 /*!
920 Prototype for forward mode z = pow(x, y) (not used).
921
922 \tparam Base
923 base type for the operator; i.e., this operation was recorded
924 using AD< Base > and computations by this routine are done using type
925 Base.
926
927 \param p
928 lowest order of the Taylor coefficient that we are computing.
929
930 \param q
931 highest order of the Taylor coefficient that we are computing.
932
933 \param i_z
934 variable index corresponding to the last (primary) result for this operation;
935 i.e. the row index in taylor corresponding to z.
936 Note that there are three results for this operation,
937 below they are referred to as z_0, z_1, z_2 and correspond to
938 \verbatim
939 z_0 = log(x)
940 z_1 = z0 * y
941 z_2 = exp(z1)
942 \endverbatim
943 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
944
945 \param arg
946 arg[0]
947 index corresponding to the left operand for this operator;
948 i.e. the index corresponding to x.
949 \n
950 arg[1]
951 index corresponding to the right operand for this operator;
952 i.e. the index corresponding to y.
953
954 \param parameter
955 If x is a parameter, parameter [ arg[0] ]
956 is the value corresponding to x.
957 \n
958 If y is a parameter, parameter [ arg[1] ]
959 is the value corresponding to y.
960
961 \param cap_order
962 maximum number of orders that will fit in the taylor array.
963
964 \param taylor
965 \b Input: If x is a variable,
966 <code>taylor [ size_t(arg[0]) * cap_order + k ]</code>
967 for k = 0 , ... , q,
968 is the k-th order Taylor coefficient corresponding to x.
969 \n
970 \b Input: If y is a variable,
971 <code>taylor [ size_t(arg[1]) * cap_order + k ]</code>
972 for k = 0 , ... , q
973 is the k-th order Taylor coefficient corresponding to y.
974 \n
975 \b Input: <code>taylor [ (i_z-2+j) * cap_order + k ]</code>,
976 for j = 0, 1, 2 , for k = 0 , ... , p-1,
977 is the k-th order Taylor coefficient corresponding to z_j.
978 \n
979 \b Output: <code>taylor [ (i_z-2+j) * cap_order + k ]</code>,
980 is the k-th order Taylor coefficient corresponding to z_j.
981
982 \par Checked Assertions
983 \li NumArg(op) == 2
984 \li NumRes(op) == 3
985 \li If x is a variable, arg[0] < i_z - 2
986 \li If y is a variable, arg[1] < i_z - 2
987 \li q < cap_order
988 \li p <= q
989 */
990 template <class Base>
991 void forward_pow_op(
992 size_t p ,
993 size_t q ,
994 size_t i_z ,
995 const addr_t* arg ,
996 const Base* parameter ,
997 size_t cap_order ,
998 Base* taylor )
999 {
1000 // This routine is only for documentaiton, it should not be used
1001 CPPAD_ASSERT_UNKNOWN( false );
1002 }
1003 /*!
1004 Prototype for multiple direction forward mode z = pow(x, y) (not used).
1005
1006 \tparam Base
1007 base type for the operator; i.e., this operation was recorded
1008 using AD< Base > and computations by this routine are done using type
1009 Base.
1010
1011 \param q
1012 order of the Taylor coefficient that we are computing.
1013
1014 \param r
1015 is the number of Taylor coefficient directions that we are computing
1016
1017 \param i_z
1018 variable index corresponding to the last (primary) result for this operation;
1019 i.e. the row index in taylor corresponding to z.
1020 Note that there are three results for this operation,
1021 below they are referred to as z_0, z_1, z_2 and correspond to
1022 \verbatim
1023 z_0 = log(x)
1024 z_1 = z0 * y
1025 z_2 = exp(z1)
1026 \endverbatim
1027 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1028
1029 \param arg
1030 arg[0]
1031 index corresponding to the left operand for this operator;
1032 i.e. the index corresponding to x.
1033 \n
1034 arg[1]
1035 index corresponding to the right operand for this operator;
1036 i.e. the index corresponding to y.
1037
1038 \param parameter
1039 If x is a parameter, parameter [ arg[0] ]
1040 is the value corresponding to x.
1041 \n
1042 If y is a parameter, parameter [ arg[1] ]
1043 is the value corresponding to y.
1044
1045 \param cap_order
1046 maximum number of orders that will fit in the taylor array.
1047
1048 \par tpv
1049 We use the notation
1050 <code>tpv = (cap_order-1) * r + 1</code>
1051 which is the number of Taylor coefficients per variable
1052
1053 \param taylor
1054 \b Input: If x is a variable,
1055 <code>taylor [ arg[0] * tpv + 0 ]</code>
1056 is the zero order coefficient corresponding to x and
1057 <code>taylor [ arg[0] * tpv + (k-1)*r+1+ell ]</code>
1058 for k = 1 , ... , q,
1059 ell = 0 , ... , r-1,
1060 is the k-th order Taylor coefficient corresponding to x
1061 for the ell-th direction.
1062 \n
1063 \n
1064 \b Input: If y is a variable,
1065 <code>taylor [ arg[1] * tpv + 0 ]</code>
1066 is the zero order coefficient corresponding to y and
1067 <code>taylor [ arg[1] * tpv + (k-1)*r+1+ell ]</code>
1068 for k = 1 , ... , q,
1069 ell = 0 , ... , r-1,
1070 is the k-th order Taylor coefficient corresponding to y
1071 for the ell-th direction.
1072 \n
1073 \n
1074 \b Input:
1075 <code>taylor [ (i_z-2+j) * tpv + 0 ]</code>,
1076 is the zero order coefficient corresponding to z_j and
1077 <code>taylor [ (i_z-2+j) * tpv + (k-1)*r+1+ell ]</code>,
1078 for j = 0, 1, 2 , k = 0 , ... , q-1, ell = 0, ... , r-1,
1079 is the k-th order Taylor coefficient corresponding to z_j
1080 for the ell-th direction.
1081 \n
1082 \n
1083 \b Output:
1084 <code>taylor [ (i_z-2+j) * tpv + (q-1)*r+1+ell ]</code>,
1085 for j = 0, 1, 2 , ell = 0, ... , r-1,
1086 is the q-th order Taylor coefficient corresponding to z_j
1087 for the ell-th direction.
1088
1089 \par Checked Assertions
1090 \li NumArg(op) == 2
1091 \li NumRes(op) == 3
1092 \li If x is a variable, arg[0] < i_z - 2
1093 \li If y is a variable, arg[1] < i_z - 2
1094 \li 0 < q
1095 \li q < cap_order
1096 */
1097 template <class Base>
1098 void forward_pow_op_dir(
1099 size_t q ,
1100 size_t r ,
1101 size_t i_z ,
1102 const addr_t* arg ,
1103 const Base* parameter ,
1104 size_t cap_order ,
1105 Base* taylor )
1106 {
1107 // This routine is only for documentaiton, it should not be used
1108 CPPAD_ASSERT_UNKNOWN( false );
1109 }
1110 /*!
1111 Prototype for zero order forward mode z = pow(x, y) (not used).
1112
1113 \tparam Base
1114 base type for the operator; i.e., this operation was recorded
1115 using AD< Base > and computations by this routine are done using type
1116 Base.
1117
1118 \param i_z
1119 variable index corresponding to the last (primary) result for this operation;
1120 i.e. the row index in taylor corresponding to z.
1121 Note that there are three results for this operation,
1122 below they are referred to as z_0, z_1, z_2 and correspond to
1123 \verbatim
1124 z_0 = log(x)
1125 z_1 = z0 * y
1126 z_2 = exp(z1)
1127 \endverbatim
1128 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1129
1130 \param arg
1131 arg[0]
1132 index corresponding to the left operand for this operator;
1133 i.e. the index corresponding to x.
1134 \n
1135 arg[1]
1136 index corresponding to the right operand for this operator;
1137 i.e. the index corresponding to y.
1138
1139 \param parameter
1140 If x is a parameter, parameter [ arg[0] ]
1141 is the value corresponding to x.
1142 \n
1143 If y is a parameter, parameter [ arg[1] ]
1144 is the value corresponding to y.
1145
1146 \param cap_order
1147 maximum number of orders that will fit in the taylor array.
1148
1149 \param taylor
1150 \b Input: If x is a variable, taylor [ arg[0] * cap_order + 0 ]
1151 is the zero order Taylor coefficient corresponding to x.
1152 \n
1153 \b Input: If y is a variable, taylor [ arg[1] * cap_order + 0 ]
1154 is the k-th order Taylor coefficient corresponding to y.
1155 \n
1156 \b Output: taylor [ (i_z - 2 + j) * cap_order + 0 ]
1157 is the zero order Taylor coefficient corresponding to z_j.
1158
1159 \par Checked Assertions
1160 \li NumArg(op) == 2
1161 \li NumRes(op) == 3
1162 \li If x is a variable, arg[0] < i_z - 2
1163 \li If y is a variable, arg[1] < i_z - 2
1164 */
1165 template <class Base>
1166 void forward_pow_op_0(
1167 size_t i_z ,
1168 const addr_t* arg ,
1169 const Base* parameter ,
1170 size_t cap_order ,
1171 Base* taylor )
1172 {
1173 // This routine is only for documentaiton, it should not be used
1174 CPPAD_ASSERT_UNKNOWN( false );
1175 }
1176 /*!
1177 Prototype for reverse mode z = pow(x, y) (not used).
1178
1179 This routine is given the partial derivatives of a function
1180 G( z , y , x , w , ... )
1181 and it uses them to compute the partial derivatives of
1182 \verbatim
1183 H( y , x , w , u , ... ) = G[ pow(x , y) , y , x , w , u , ... ]
1184 \endverbatim
1185
1186 \tparam Base
1187 base type for the operator; i.e., this operation was recorded
1188 using AD< Base > and computations by this routine are done using type
1189 Base .
1190
1191 \param d
1192 highest order Taylor coefficient that
1193 we are computing the partial derivatives with respect to.
1194
1195 \param i_z
1196 variable index corresponding to the last (primary) result for this operation;
1197 i.e. the row index in taylor corresponding to z.
1198 Note that there are three results for this operation,
1199 below they are referred to as z_0, z_1, z_2 and correspond to
1200 \verbatim
1201 z_0 = log(x)
1202 z_1 = z0 * y
1203 z_2 = exp(z1)
1204 \endverbatim
1205 It follows that the final result is equal to z; i.e., z = z_2 = pow(x, y).
1206
1207 \param arg
1208 arg[0]
1209 index corresponding to the left operand for this operator;
1210 i.e. the index corresponding to x.
1211 \n
1212 arg[1]
1213 index corresponding to the right operand for this operator;
1214 i.e. the index corresponding to y.
1215
1216 \param parameter
1217 If x is a parameter, parameter [ arg[0] ]
1218 is the value corresponding to x.
1219 \n
1220 If y is a parameter, parameter [ arg[1] ]
1221 is the value corresponding to y.
1222
1223 \param cap_order
1224 maximum number of orders that will fit in the taylor array.
1225
1226 \param taylor
1227 taylor [ (i_z - 2 + j) * cap_order + k ]
1228 for j = 0, 1, 2 and k = 0 , ... , d
1229 is the k-th order Taylor coefficient corresponding to z_j.
1230 \n
1231 If x is a variable, taylor [ arg[0] * cap_order + k ]
1232 for k = 0 , ... , d
1233 is the k-th order Taylor coefficient corresponding to x.
1234 \n
1235 If y is a variable, taylor [ arg[1] * cap_order + k ]
1236 for k = 0 , ... , d
1237 is the k-th order Taylor coefficient corresponding to y.
1238
1239 \param nc_partial
1240 number of colums in the matrix containing all the partial derivatives.
1241
1242 \param partial
1243 \b Input: partial [ (i_z - 2 + j) * nc_partial + k ]
1244 for j = 0, 1, 2, and k = 0 , ... , d
1245 is the partial derivative of
1246 G( z , y , x , w , u , ... )
1247 with respect to the k-th order Taylor coefficient for z_j.
1248 \n
1249 \b Input: If x is a variable, partial [ arg[0] * nc_partial + k ]
1250 for k = 0 , ... , d
1251 is the partial derivative of G( z , y , x , w , u , ... ) with respect to
1252 the k-th order Taylor coefficient for x.
1253 \n
1254 \b Input: If y is a variable, partial [ arg[1] * nc_partial + k ]
1255 for k = 0 , ... , d
1256 is the partial derivative of G( z , x , w , u , ... ) with respect to
1257 the k-th order Taylor coefficient for the auxillary variable y.
1258 \n
1259 \b Output: If x is a variable, partial [ arg[0] * nc_partial + k ]
1260 for k = 0 , ... , d
1261 is the partial derivative of H( y , x , w , u , ... ) with respect to
1262 the k-th order Taylor coefficient for x.
1263 \n
1264 \b Output: If y is a variable, partial [ arg[1] * nc_partial + k ]
1265 for k = 0 , ... , d
1266 is the partial derivative of H( y , x , w , u , ... ) with respect to
1267 the k-th order Taylor coefficient for y.
1268 \n
1269 \b Output: partial [ ( i_z - j ) * nc_partial + k ]
1270 for j = 0 , 1 , 2 and for k = 0 , ... , d
1271 may be used as work space; i.e., may change in an unspecified manner.
1272
1273 \par Checked Assumptions
1274 \li NumArg(op) == 2
1275 \li NumRes(op) == 3
1276 \li If x is a variable, arg[0] < i_z - 2
1277 \li If y is a variable, arg[1] < i_z - 2
1278 \li d < cap_order
1279 \li d < nc_partial
1280 */
1281 template <class Base>
1282 void reverse_pow_op(
1283 size_t d ,
1284 size_t i_z ,
1285 addr_t* arg ,
1286 const Base* parameter ,
1287 size_t cap_order ,
1288 const Base* taylor ,
1289 size_t nc_partial ,
1290 Base* partial )
1291 {
1292 // This routine is only for documentaiton, it should not be used
1293 CPPAD_ASSERT_UNKNOWN( false );
1294 }
1295
1296 // ==================== Sparsity Calculations ==============================
1297 /*!
1298 Prototype for reverse mode Hessian sparsity unary operators.
1299
1300 This routine is given the forward mode Jacobian sparsity patterns for x.
1301 It is also given the reverse mode dependence of G on z.
1302 In addition, it is given the revese mode Hessian sparsity
1303 for the quanity of interest G(z , y , ... )
1304 and it uses them to compute the sparsity patterns for
1305 \verbatim
1306 H( x , w , u , ... ) = G[ z(x) , x , w , u , ... ]
1307 \endverbatim
1308
1309 \tparam Vector_set
1310 is the type used for vectors of sets. It can be either
1311 sparse::pack_setvec or sparse::list_setvec.
1312
1313 \param i_z
1314 variable index corresponding to the result for this operation;
1315 i.e. the row index in sparsity corresponding to z.
1316
1317 \param i_x
1318 variable index corresponding to the argument for this operator;
1319 i.e. the row index in sparsity corresponding to x.
1320
1321 \param rev_jacobian
1322 rev_jacobian[i_z]
1323 is all false (true) if the Jacobian of G with respect to z must be zero
1324 (may be non-zero).
1325 \n
1326 \n
1327 rev_jacobian[i_x]
1328 is all false (true) if the Jacobian with respect to x must be zero
1329 (may be non-zero).
1330 On input, it corresponds to the function G,
1331 and on output it corresponds to the function H.
1332
1333 \param for_jac_sparsity
1334 The set with index i_x in for_jac_sparsity
1335 is the forward mode Jacobian sparsity pattern for the variable x.
1336
1337 \param rev_hes_sparsity
1338 The set with index i_z in in rev_hes_sparsity
1339 is the Hessian sparsity pattern for the fucntion G
1340 where one of the partials derivative is with respect to z.
1341 \n
1342 \n
1343 The set with index i_x in rev_hes_sparsity
1344 is the Hessian sparsity pattern
1345 where one of the partials derivative is with respect to x.
1346 On input, it corresponds to the function G,
1347 and on output it corresponds to the function H.
1348
1349 \par Checked Assertions:
1350 \li i_x < i_z
1351 */
1352
1353 template <class Vector_set>
1354 void reverse_sparse_hessian_unary_op(
1355 size_t i_z ,
1356 size_t i_x ,
1357 bool* rev_jacobian ,
1358 Vector_set& for_jac_sparsity ,
1359 Vector_set& rev_hes_sparsity )
1360 {
1361 // This routine is only for documentaiton, it should not be used
1362 CPPAD_ASSERT_UNKNOWN( false );
1363 }
1364
1365 /*!
1366 Prototype for reverse mode Hessian sparsity binary operators.
1367
1368 This routine is given the sparsity patterns the Hessian
1369 of a function G(z, y, x, ... )
1370 and it uses them to compute the sparsity patterns for the Hessian of
1371 \verbatim
1372 H( y, x, w , u , ... ) = G[ z(x,y) , y , x , w , u , ... ]
1373 \endverbatim
1374
1375 \tparam Vector_set
1376 is the type used for vectors of sets. It can be either
1377 sparse::pack_setvec or sparse::list_setvec.
1378
1379 \param i_z
1380 variable index corresponding to the result for this operation;
1381 i.e. the row index in sparsity corresponding to z.
1382
1383 \param arg
1384 arg[0]
1385 variable index corresponding to the left operand for this operator;
1386 i.e. the set with index arg[0] in var_sparsity
1387 is the spasity pattern correspoding to x.
1388 \n
1389 \n arg[1]
1390 variable index corresponding to the right operand for this operator;
1391 i.e. the row index in sparsity patterns corresponding to y.
1392
1393 \param jac_reverse
1394 jac_reverse[i_z]
1395 is false (true) if the Jacobian of G with respect to z is always zero
1396 (may be non-zero).
1397 \n
1398 \n
1399 jac_reverse[ arg[0] ]
1400 is false (true) if the Jacobian with respect to x is always zero
1401 (may be non-zero).
1402 On input, it corresponds to the function G,
1403 and on output it corresponds to the function H.
1404 \n
1405 \n
1406 jac_reverse[ arg[1] ]
1407 is false (true) if the Jacobian with respect to y is always zero
1408 (may be non-zero).
1409 On input, it corresponds to the function G,
1410 and on output it corresponds to the function H.
1411
1412 \param for_jac_sparsity
1413 The set with index arg[0] in for_jac_sparsity for the
1414 is the forward Jacobian sparsity pattern for x.
1415 \n
1416 \n
1417 The set with index arg[1] in for_jac_sparsity
1418 is the forward sparsity pattern for y.
1419
1420 \param rev_hes_sparsity
1421 The set wiht index i_x in rev_hes_sparsity
1422 is the Hessian sparsity pattern for the function G
1423 where one of the partial derivatives is with respect to z.
1424 \n
1425 \n
1426 The set with index arg[0] in rev_hes_sparsity
1427 is the Hessian sparsity pattern where one of the
1428 partial derivatives is with respect to x.
1429 On input, it corresponds to the function G,
1430 and on output it correspondst to H.
1431 \n
1432 \n
1433 The set with index arg[1] in rev_hes_sparsity
1434 is the Hessian sparsity pattern where one of the
1435 partial derivatives is with respect to y.
1436 On input, it corresponds to the function G,
1437 and on output it correspondst to H.
1438
1439 \par Checked Assertions:
1440 \li arg[0] < i_z
1441 \li arg[1] < i_z
1442 */
1443 template <class Vector_set>
1444 void reverse_sparse_hessian_binary_op(
1445 size_t i_z ,
1446 const addr_t* arg ,
1447 bool* jac_reverse ,
1448 Vector_set& for_jac_sparsity ,
1449 Vector_set& rev_hes_sparsity )
1450 {
1451 // This routine is only for documentaiton, it should not be used
1452 CPPAD_ASSERT_UNKNOWN( false );
1453 }
1454
1455
1456 } } // END_CPPAD_LOCAL_NAMESPACE
1457 # endif
+0
-153
include/cppad/local/sign_op.hpp less more
0 # ifndef CPPAD_LOCAL_SIGN_OP_HPP
1 # define CPPAD_LOCAL_SIGN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file sign_op.hpp
18 Forward and reverse mode calculations for z = sign(x).
19 */
20
21 /*!
22 Compute forward mode Taylor coefficient for result of op = SignOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = sign(x)
27 \endverbatim
28
29 \copydetails CppAD::local::forward_unary1_op
30 */
31 template <class Base>
32 void forward_sign_op(
33 size_t p ,
34 size_t q ,
35 size_t i_z ,
36 size_t i_x ,
37 size_t cap_order ,
38 Base* taylor )
39 {
40 // check assumptions
41 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
42 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
43 CPPAD_ASSERT_UNKNOWN( q < cap_order );
44 CPPAD_ASSERT_UNKNOWN( p <= q );
45
46 // Taylor coefficients corresponding to argument and result
47 Base* x = taylor + i_x * cap_order;
48 Base* z = taylor + i_z * cap_order;
49
50 if( p == 0 )
51 { z[0] = sign(x[0]);
52 p++;
53 }
54 for(size_t j = p; j <= q; j++)
55 z[j] = Base(0.);
56 }
57 /*!
58 Multiple direction forward mode Taylor coefficient for op = SignOp.
59
60 The C++ source code corresponding to this operation is
61 \verbatim
62 z = sign(x)
63 \endverbatim
64
65 \copydetails CppAD::local::forward_unary1_op_dir
66 */
67 template <class Base>
68 void forward_sign_op_dir(
69 size_t q ,
70 size_t r ,
71 size_t i_z ,
72 size_t i_x ,
73 size_t cap_order ,
74 Base* taylor )
75 {
76 // check assumptions
77 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
78 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
79 CPPAD_ASSERT_UNKNOWN( 0 < q );
80 CPPAD_ASSERT_UNKNOWN( q < cap_order );
81
82 // Taylor coefficients corresponding to argument and result
83 size_t num_taylor_per_var = (cap_order-1) * r + 1;
84 size_t m = (q - 1) * r + 1;
85 Base* z = taylor + i_z * num_taylor_per_var;
86
87 for(size_t ell = 0; ell < r; ell++)
88 z[m+ell] = Base(0.);
89 }
90
91 /*!
92 Compute zero order forward mode Taylor coefficient for result of op = SignOp.
93
94 The C++ source code corresponding to this operation is
95 \verbatim
96 z = sign(x)
97 \endverbatim
98
99 \copydetails CppAD::local::forward_unary1_op_0
100 */
101 template <class Base>
102 void forward_sign_op_0(
103 size_t i_z ,
104 size_t i_x ,
105 size_t cap_order ,
106 Base* taylor )
107 {
108
109 // check assumptions
110 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
111 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
112 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
113
114 // Taylor coefficients corresponding to argument and result
115 Base x0 = *(taylor + i_x * cap_order);
116 Base* z = taylor + i_z * cap_order;
117
118 z[0] = sign(x0);
119 }
120 /*!
121 Compute reverse mode partial derivatives for result of op = SignOp.
122
123 The C++ source code corresponding to this operation is
124 \verbatim
125 z = sign(x)
126 \endverbatim
127
128 \copydetails CppAD::local::reverse_unary1_op
129 */
130
131 template <class Base>
132 void reverse_sign_op(
133 size_t d ,
134 size_t i_z ,
135 size_t i_x ,
136 size_t cap_order ,
137 const Base* taylor ,
138 size_t nc_partial ,
139 Base* partial )
140 {
141 // check assumptions
142 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 );
143 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 );
144 CPPAD_ASSERT_UNKNOWN( d < cap_order );
145 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
146
147 // nothing to do because partials of sign are zero
148 return;
149 }
150
151 } } // END_CPPAD_LOCAL_NAMESPACE
152 # endif
+0
-240
include/cppad/local/sin_op.hpp less more
0 # ifndef CPPAD_LOCAL_SIN_OP_HPP
1 # define CPPAD_LOCAL_SIN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file sin_op.hpp
18 Forward and reverse mode calculations for z = sin(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = SinOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = sin(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = cos(x)
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_sin_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* s = taylor + i_z * cap_order;
56 Base* c = s - cap_order;
57
58 // rest of this routine is identical for the following cases:
59 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op.
60 // (except that there is a sign difference for the hyperbolic case).
61 size_t k;
62 if( p == 0 )
63 { s[0] = sin( x[0] );
64 c[0] = cos( x[0] );
65 p++;
66 }
67 for(size_t j = p; j <= q; j++)
68 {
69 s[j] = Base(0.0);
70 c[j] = Base(0.0);
71 for(k = 1; k <= j; k++)
72 { s[j] += Base(double(k)) * x[k] * c[j-k];
73 c[j] -= Base(double(k)) * x[k] * s[j-k];
74 }
75 s[j] /= Base(double(j));
76 c[j] /= Base(double(j));
77 }
78 }
79 /*!
80 Compute forward mode Taylor coefficient for result of op = SinOp.
81
82 The C++ source code corresponding to this operation is
83 \verbatim
84 z = sin(x)
85 \endverbatim
86 The auxillary result is
87 \verbatim
88 y = cos(x)
89 \endverbatim
90 The value of y, and its derivatives, are computed along with the value
91 and derivatives of z.
92
93 \copydetails CppAD::local::forward_unary2_op_dir
94 */
95 template <class Base>
96 void forward_sin_op_dir(
97 size_t q ,
98 size_t r ,
99 size_t i_z ,
100 size_t i_x ,
101 size_t cap_order ,
102 Base* taylor )
103 {
104 // check assumptions
105 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
106 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
107 CPPAD_ASSERT_UNKNOWN( 0 < q );
108 CPPAD_ASSERT_UNKNOWN( q < cap_order );
109
110 // Taylor coefficients corresponding to argument and result
111 size_t num_taylor_per_var = (cap_order-1) * r + 1;
112 Base* x = taylor + i_x * num_taylor_per_var;
113 Base* s = taylor + i_z * num_taylor_per_var;
114 Base* c = s - num_taylor_per_var;
115
116
117 // rest of this routine is identical for the following cases:
118 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
119 // (except that there is a sign difference for the hyperbolic case).
120 size_t m = (q-1) * r + 1;
121 for(size_t ell = 0; ell < r; ell++)
122 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
123 c[m+ell] = - Base(double(q)) * x[m + ell] * s[0];
124 for(size_t k = 1; k < q; k++)
125 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
126 c[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
127 }
128 s[m+ell] /= Base(double(q));
129 c[m+ell] /= Base(double(q));
130 }
131 }
132
133
134 /*!
135 Compute zero order forward mode Taylor coefficient for result of op = SinOp.
136
137 The C++ source code corresponding to this operation is
138 \verbatim
139 z = sin(x)
140 \endverbatim
141 The auxillary result is
142 \verbatim
143 y = cos(x)
144 \endverbatim
145 The value of y is computed along with the value of z.
146
147 \copydetails CppAD::local::forward_unary2_op_0
148 */
149 template <class Base>
150 void forward_sin_op_0(
151 size_t i_z ,
152 size_t i_x ,
153 size_t cap_order ,
154 Base* taylor )
155 {
156 // check assumptions
157 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
158 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
159 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
160
161 // Taylor coefficients corresponding to argument and result
162 Base* x = taylor + i_x * cap_order;
163 Base* s = taylor + i_z * cap_order; // called z in documentation
164 Base* c = s - cap_order; // called y in documentation
165
166 s[0] = sin( x[0] );
167 c[0] = cos( x[0] );
168 }
169
170 /*!
171 Compute reverse mode partial derivatives for result of op = SinOp.
172
173 The C++ source code corresponding to this operation is
174 \verbatim
175 z = sin(x)
176 \endverbatim
177 The auxillary result is
178 \verbatim
179 y = cos(x)
180 \endverbatim
181 The value of y is computed along with the value of z.
182
183 \copydetails CppAD::local::reverse_unary2_op
184 */
185
186 template <class Base>
187 void reverse_sin_op(
188 size_t d ,
189 size_t i_z ,
190 size_t i_x ,
191 size_t cap_order ,
192 const Base* taylor ,
193 size_t nc_partial ,
194 Base* partial )
195 {
196 // check assumptions
197 CPPAD_ASSERT_UNKNOWN( NumArg(SinOp) == 1 );
198 CPPAD_ASSERT_UNKNOWN( NumRes(SinOp) == 2 );
199 CPPAD_ASSERT_UNKNOWN( d < cap_order );
200 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
201
202 // Taylor coefficients and partials corresponding to argument
203 const Base* x = taylor + i_x * cap_order;
204 Base* px = partial + i_x * nc_partial;
205
206 // Taylor coefficients and partials corresponding to first result
207 const Base* s = taylor + i_z * cap_order; // called z in doc
208 Base* ps = partial + i_z * nc_partial;
209
210 // Taylor coefficients and partials corresponding to auxillary result
211 const Base* c = s - cap_order; // called y in documentation
212 Base* pc = ps - nc_partial;
213
214
215 // rest of this routine is identical for the following cases:
216 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
217 size_t j = d;
218 size_t k;
219 while(j)
220 {
221 ps[j] /= Base(double(j));
222 pc[j] /= Base(double(j));
223 for(k = 1; k <= j; k++)
224 {
225 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
226 px[k] -= Base(double(k)) * azmul(pc[j], s[j-k]);
227
228 ps[j-k] -= Base(double(k)) * azmul(pc[j], x[k]);
229 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
230
231 }
232 --j;
233 }
234 px[0] += azmul(ps[0], c[0]);
235 px[0] -= azmul(pc[0], s[0]);
236 }
237
238 } } // END_CPPAD_LOCAL_NAMESPACE
239 # endif
+0
-239
include/cppad/local/sinh_op.hpp less more
0 # ifndef CPPAD_LOCAL_SINH_OP_HPP
1 # define CPPAD_LOCAL_SINH_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file sinh_op.hpp
18 Forward and reverse mode calculations for z = sinh(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = SinhOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = sinh(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = cosh(x)
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_sinh_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* s = taylor + i_z * cap_order;
56 Base* c = s - cap_order;
57
58
59 // rest of this routine is identical for the following cases:
60 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
61 // (except that there is a sign difference for hyperbolic case).
62 size_t k;
63 if( p == 0 )
64 { s[0] = sinh( x[0] );
65 c[0] = cosh( x[0] );
66 p++;
67 }
68 for(size_t j = p; j <= q; j++)
69 {
70 s[j] = Base(0.0);
71 c[j] = Base(0.0);
72 for(k = 1; k <= j; k++)
73 { s[j] += Base(double(k)) * x[k] * c[j-k];
74 c[j] += Base(double(k)) * x[k] * s[j-k];
75 }
76 s[j] /= Base(double(j));
77 c[j] /= Base(double(j));
78 }
79 }
80 /*!
81 Compute forward mode Taylor coefficient for result of op = SinhOp.
82
83 The C++ source code corresponding to this operation is
84 \verbatim
85 z = sinh(x)
86 \endverbatim
87 The auxillary result is
88 \verbatim
89 y = cosh(x)
90 \endverbatim
91 The value of y, and its derivatives, are computed along with the value
92 and derivatives of z.
93
94 \copydetails CppAD::local::forward_unary2_op_dir
95 */
96 template <class Base>
97 void forward_sinh_op_dir(
98 size_t q ,
99 size_t r ,
100 size_t i_z ,
101 size_t i_x ,
102 size_t cap_order ,
103 Base* taylor )
104 {
105 // check assumptions
106 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
107 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
108 CPPAD_ASSERT_UNKNOWN( 0 < q );
109 CPPAD_ASSERT_UNKNOWN( q < cap_order );
110
111 // Taylor coefficients corresponding to argument and result
112 size_t num_taylor_per_var = (cap_order-1) * r + 1;
113 Base* x = taylor + i_x * num_taylor_per_var;
114 Base* s = taylor + i_z * num_taylor_per_var;
115 Base* c = s - num_taylor_per_var;
116
117
118 // rest of this routine is identical for the following cases:
119 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
120 // (except that there is a sign difference for the hyperbolic case).
121 size_t m = (q-1) * r + 1;
122 for(size_t ell = 0; ell < r; ell++)
123 { s[m+ell] = Base(double(q)) * x[m + ell] * c[0];
124 c[m+ell] = Base(double(q)) * x[m + ell] * s[0];
125 for(size_t k = 1; k < q; k++)
126 { s[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
127 c[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
128 }
129 s[m+ell] /= Base(double(q));
130 c[m+ell] /= Base(double(q));
131 }
132 }
133
134 /*!
135 Compute zero order forward mode Taylor coefficient for result of op = SinhOp.
136
137 The C++ source code corresponding to this operation is
138 \verbatim
139 z = sinh(x)
140 \endverbatim
141 The auxillary result is
142 \verbatim
143 y = cosh(x)
144 \endverbatim
145 The value of y is computed along with the value of z.
146
147 \copydetails CppAD::local::forward_unary2_op_0
148 */
149 template <class Base>
150 void forward_sinh_op_0(
151 size_t i_z ,
152 size_t i_x ,
153 size_t cap_order ,
154 Base* taylor )
155 {
156 // check assumptions
157 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
158 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
159 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
160
161 // Taylor coefficients corresponding to argument and result
162 Base* x = taylor + i_x * cap_order;
163 Base* s = taylor + i_z * cap_order; // called z in documentation
164 Base* c = s - cap_order; // called y in documentation
165
166 s[0] = sinh( x[0] );
167 c[0] = cosh( x[0] );
168 }
169 /*!
170 Compute reverse mode partial derivatives for result of op = SinhOp.
171
172 The C++ source code corresponding to this operation is
173 \verbatim
174 z = sinh(x)
175 \endverbatim
176 The auxillary result is
177 \verbatim
178 y = cosh(x)
179 \endverbatim
180 The value of y is computed along with the value of z.
181
182 \copydetails CppAD::local::reverse_unary2_op
183 */
184
185 template <class Base>
186 void reverse_sinh_op(
187 size_t d ,
188 size_t i_z ,
189 size_t i_x ,
190 size_t cap_order ,
191 const Base* taylor ,
192 size_t nc_partial ,
193 Base* partial )
194 {
195 // check assumptions
196 CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
197 CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
198 CPPAD_ASSERT_UNKNOWN( d < cap_order );
199 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
200
201 // Taylor coefficients and partials corresponding to argument
202 const Base* x = taylor + i_x * cap_order;
203 Base* px = partial + i_x * nc_partial;
204
205 // Taylor coefficients and partials corresponding to first result
206 const Base* s = taylor + i_z * cap_order; // called z in doc
207 Base* ps = partial + i_z * nc_partial;
208
209 // Taylor coefficients and partials corresponding to auxillary result
210 const Base* c = s - cap_order; // called y in documentation
211 Base* pc = ps - nc_partial;
212
213
214 // rest of this routine is identical for the following cases:
215 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
216 size_t j = d;
217 size_t k;
218 while(j)
219 {
220 ps[j] /= Base(double(j));
221 pc[j] /= Base(double(j));
222 for(k = 1; k <= j; k++)
223 {
224 px[k] += Base(double(k)) * azmul(ps[j], c[j-k]);
225 px[k] += Base(double(k)) * azmul(pc[j], s[j-k]);
226
227 ps[j-k] += Base(double(k)) * azmul(pc[j], x[k]);
228 pc[j-k] += Base(double(k)) * azmul(ps[j], x[k]);
229
230 }
231 --j;
232 }
233 px[0] += azmul(ps[0], c[0]);
234 px[0] += azmul(pc[0], s[0]);
235 }
236
237 } } // END_CPPAD_LOCAL_NAMESPACE
238 # endif
+0
-193
include/cppad/local/sqrt_op.hpp less more
0 # ifndef CPPAD_LOCAL_SQRT_OP_HPP
1 # define CPPAD_LOCAL_SQRT_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file sqrt_op.hpp
18 Forward and reverse mode calculations for z = sqrt(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = SqrtOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = sqrt(x)
28 \endverbatim
29
30 \copydetails CppAD::local::forward_unary1_op
31 */
32 template <class Base>
33 void forward_sqrt_op(
34 size_t p ,
35 size_t q ,
36 size_t i_z ,
37 size_t i_x ,
38 size_t cap_order ,
39 Base* taylor )
40 {
41 // check assumptions
42 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
43 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
44 CPPAD_ASSERT_UNKNOWN( q < cap_order );
45 CPPAD_ASSERT_UNKNOWN( p <= q );
46
47 // Taylor coefficients corresponding to argument and result
48 Base* x = taylor + i_x * cap_order;
49 Base* z = taylor + i_z * cap_order;
50
51 size_t k;
52 if( p == 0 )
53 { z[0] = sqrt( x[0] );
54 p++;
55 }
56 for(size_t j = p; j <= q; j++)
57 {
58 z[j] = Base(0.0);
59 for(k = 1; k < j; k++)
60 z[j] -= Base(double(k)) * z[k] * z[j-k];
61 z[j] /= Base(double(j));
62 z[j] += x[j] / Base(2.0);
63 z[j] /= z[0];
64 }
65 }
66
67 /*!
68 Multiple direction forward mode Taylor coefficient for op = SqrtOp.
69
70 The C++ source code corresponding to this operation is
71 \verbatim
72 z = sqrt(x)
73 \endverbatim
74
75 \copydetails CppAD::local::forward_unary1_op_dir
76 */
77 template <class Base>
78 void forward_sqrt_op_dir(
79 size_t q ,
80 size_t r ,
81 size_t i_z ,
82 size_t i_x ,
83 size_t cap_order ,
84 Base* taylor )
85 {
86 // check assumptions
87 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
88 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
89 CPPAD_ASSERT_UNKNOWN( 0 < q );
90 CPPAD_ASSERT_UNKNOWN( q < cap_order );
91
92 // Taylor coefficients corresponding to argument and result
93 size_t num_taylor_per_var = (cap_order-1) * r + 1;
94 Base* z = taylor + i_z * num_taylor_per_var;
95 Base* x = taylor + i_x * num_taylor_per_var;
96
97 size_t m = (q-1) * r + 1;
98 for(size_t ell = 0; ell < r; ell++)
99 { z[m+ell] = Base(0.0);
100 for(size_t k = 1; k < q; k++)
101 z[m+ell] -= Base(double(k)) * z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell];
102 z[m+ell] /= Base(double(q));
103 z[m+ell] += x[m+ell] / Base(2.0);
104 z[m+ell] /= z[0];
105 }
106 }
107
108 /*!
109 Compute zero order forward mode Taylor coefficient for result of op = SqrtOp.
110
111 The C++ source code corresponding to this operation is
112 \verbatim
113 z = sqrt(x)
114 \endverbatim
115
116 \copydetails CppAD::local::forward_unary1_op_0
117 */
118 template <class Base>
119 void forward_sqrt_op_0(
120 size_t i_z ,
121 size_t i_x ,
122 size_t cap_order ,
123 Base* taylor )
124 {
125 // check assumptions
126 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
127 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
128 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
129
130 // Taylor coefficients corresponding to argument and result
131 Base* x = taylor + i_x * cap_order;
132 Base* z = taylor + i_z * cap_order;
133
134 z[0] = sqrt( x[0] );
135 }
136 /*!
137 Compute reverse mode partial derivatives for result of op = SqrtOp.
138
139 The C++ source code corresponding to this operation is
140 \verbatim
141 z = sqrt(x)
142 \endverbatim
143
144 \copydetails CppAD::local::reverse_unary1_op
145 */
146
147 template <class Base>
148 void reverse_sqrt_op(
149 size_t d ,
150 size_t i_z ,
151 size_t i_x ,
152 size_t cap_order ,
153 const Base* taylor ,
154 size_t nc_partial ,
155 Base* partial )
156 {
157 // check assumptions
158 CPPAD_ASSERT_UNKNOWN( NumArg(SqrtOp) == 1 );
159 CPPAD_ASSERT_UNKNOWN( NumRes(SqrtOp) == 1 );
160 CPPAD_ASSERT_UNKNOWN( d < cap_order );
161 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
162
163 // Taylor coefficients and partials corresponding to argument
164 Base* px = partial + i_x * nc_partial;
165
166 // Taylor coefficients and partials corresponding to result
167 const Base* z = taylor + i_z * cap_order;
168 Base* pz = partial + i_z * nc_partial;
169
170
171 Base inv_z0 = Base(1.0) / z[0];
172
173 // number of indices to access
174 size_t j = d;
175 size_t k;
176 while(j)
177 {
178
179 // scale partial w.r.t. z[j]
180 pz[j] = azmul(pz[j], inv_z0);
181
182 pz[0] -= azmul(pz[j], z[j]);
183 px[j] += pz[j] / Base(2.0);
184 for(k = 1; k < j; k++)
185 pz[k] -= azmul(pz[j], z[j-k]);
186 --j;
187 }
188 px[0] += azmul(pz[0], inv_z0) / Base(2.0);
189 }
190
191 } } // END_CPPAD_LOCAL_NAMESPACE
192 # endif
+0
-489
include/cppad/local/store_op.hpp less more
0 # ifndef CPPAD_LOCAL_STORE_OP_HPP
1 # define CPPAD_LOCAL_STORE_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*
16 $begin store_op_var$$
17 $spell
18 pv
19 vp
20 vv
21 Vec
22 op
23 var
24 isvar
25 ind
26 Taylor
27 arg
28 num
29 Addr
30 $$
31 $section Changing an Element in a Variable VecAD Vector$$
32
33 $head See Also$$
34 $cref/op_code_var store/op_code_var/Store/$$.
35
36 $head Syntax$$
37 $codei%forward_store_%IV%_op_0(
38 %i_z%,
39 %arg%,
40 %num_par%,
41 %parameter%,
42 %cap_order%,
43 %taylor%,
44 %vec_ad2isvar%,
45 %vec_ad2index%
46 )
47 %$$
48 where the index type $icode I$$ and the value being stored type $icode V$$
49 are $code p$$ (for parameter) or $code v$$ (for variable).
50
51 $head Prototype$$
52 $srcthisfile%
53 0%// BEGIN_FORWARD_STORE_PP_OP_0%// END_FORWARD_STORE_PP_OP_0%1
54 %$$
55 The prototype for
56 $code forward_store_pv_op_0$$,
57 $code forward_store_vp_op_0$$, and
58 $code forward_store_vv_op_0$$,
59 are the same except for the function name.
60
61 $head Notation$$
62
63 $subhead v$$
64 We use $icode v$$ to denote the $cref VecAD$$ vector for this operation.
65
66 $subhead x$$
67 We use $icode x$$ to denote the $codei%AD%<%Base%>%$$
68 index for this operation.
69
70 $subhead i_vec$$
71 We use $icode i_vec$$ to denote the $code size_t$$ value
72 corresponding to $icode x$$.
73
74 $subhead n_load$$
75 This is the number of load instructions in this recording.
76
77 $subhead n_all$$
78 This is the number of values in the single array that includes
79 all the vectors together with the size of each vector.
80
81 $head Base$$
82 base type for the operator; i.e., this operation was recorded
83 using AD<Base> and computations by this routine are done using type Base.
84
85 $head i_z$$
86 is the AD variable index corresponding to the result of this load operation.
87
88 $head arg$$
89
90 $subhead arg[0]$$
91 is the offset of this VecAD vector relative to the beginning
92 of the $icode vec_ad2isvar$$ and $icode vec_ad2index$$ arrays.
93
94 $subhead arg[1]$$
95 If this is
96 $code forward_load_p_op_0$$ ($code forward_load_v_op_0$$)
97 $icode%arg%[%1%]%$$ is the parameter index (variable index)
98 corresponding to $cref/i_vec/load_op_var/Notation/i_vec/$$.
99
100 $subhead arg[2]$$
101 Is the index of this VecAD load instruction in the
102 $icode load_op2var$$ array.
103
104 $head num_par$$
105 is the number of parameters in this recording.
106
107 $head parameter$$
108 This is the vector of parameters for this recording which has size
109 $icode num_par$$.
110
111 $head cap_order$$
112 number of columns in the matrix containing the Taylor coefficients.
113
114 $head taylor$$
115 Is the matrix of Taylor coefficients for all the variables.
116
117 $head vec_ad2isvar$$
118 This vector has size $icode n_all$$ and
119 the input values of its elements does not matter.
120 If the value being stored is a parameter (variable),
121 $icode%vec_ad2isvar%[ %arg%[0] + %i_vec% ]%$$
122 is set to false (true).
123
124 $head vec_ad2index$$
125 This array has size $icode n_all$$
126 and the input value of its elements does not matter.
127 If the value being stored is a parameter (variable),
128 $icode%vec_ad2index%[ %arg%[0] + %i_vec% ]%$$
129 is set to the parameter (variable) index
130 corresponding to the value being stored.
131
132 $end
133 */
134 // BEGIN_FORWARD_STORE_PP_OP_0
135 template <class Base>
136 void forward_store_pp_op_0(
137 size_t i_z ,
138 const addr_t* arg ,
139 size_t num_par ,
140 const Base* parameter ,
141 size_t cap_order ,
142 const Base* taylor ,
143 bool* vec_ad2isvar ,
144 size_t* vec_ad2index )
145 // END_FORWARD_STORE_PP_OP_0
146 { addr_t i_vec = addr_t( Integer( parameter[ arg[1] ] ) );
147 CPPAD_ASSERT_KNOWN(
148 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
149 "VecAD: zero order forward dynamic parameter index out of range"
150 );
151 CPPAD_ASSERT_UNKNOWN( NumArg(StppOp) == 3 );
152 CPPAD_ASSERT_UNKNOWN( NumRes(StppOp) == 0 );
153 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
154 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
155
156 vec_ad2isvar[ arg[0] + i_vec ] = false;
157 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
158 }
159 template <class Base>
160 void forward_store_pv_op_0(
161 size_t i_z ,
162 const addr_t* arg ,
163 size_t num_par ,
164 const Base* parameter ,
165 size_t cap_order ,
166 const Base* taylor ,
167 bool* vec_ad2isvar ,
168 size_t* vec_ad2index )
169 { addr_t i_vec = addr_t( Integer( parameter[ arg[1] ] ) );
170 CPPAD_ASSERT_KNOWN(
171 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
172 "VecAD: zero order forward dynamic parameter index out of range"
173 );
174 CPPAD_ASSERT_UNKNOWN( NumArg(StpvOp) == 3 );
175 CPPAD_ASSERT_UNKNOWN( NumRes(StpvOp) == 0 );
176 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
177
178 vec_ad2isvar[ arg[0] + i_vec ] = true;
179 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
180 }
181 template <class Base>
182 void forward_store_vp_op_0(
183 size_t i_z ,
184 const addr_t* arg ,
185 size_t num_par ,
186 size_t cap_order ,
187 const Base* taylor ,
188 bool* vec_ad2isvar ,
189 size_t* vec_ad2index )
190 {
191 addr_t i_vec = addr_t(Integer( taylor[ size_t(arg[1]) * cap_order + 0 ] ));
192 CPPAD_ASSERT_KNOWN(
193 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
194 "VecAD: zero order forward variable index out of range"
195 );
196
197 CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 );
198 CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 );
199 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
200 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par );
201
202 vec_ad2isvar[ arg[0] + i_vec ] = false;
203 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
204 }
205 template <class Base>
206 void forward_store_vv_op_0(
207 size_t i_z ,
208 const addr_t* arg ,
209 size_t num_par ,
210 size_t cap_order ,
211 const Base* taylor ,
212 bool* vec_ad2isvar ,
213 size_t* vec_ad2index )
214 {
215 addr_t i_vec = addr_t(Integer( taylor[ size_t(arg[1]) * cap_order + 0 ] ));
216 CPPAD_ASSERT_KNOWN(
217 size_t(i_vec) < vec_ad2index[ arg[0] - 1 ] ,
218 "VecAD: index during zero order forward sweep is out of range"
219 );
220
221 CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 );
222 CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 );
223 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
224
225 vec_ad2isvar[ arg[0] + i_vec ] = true;
226 vec_ad2index[ arg[0] + i_vec ] = size_t(arg[2]);
227 }
228 // ---------------------------------------------------------------------------
229 /*
230 ==============================================================================
231 <!-- define preamble -->
232 The C++ source code corresponding to this operation is
233 \verbatim
234 v[x] = y
235 \endverbatim
236 where v is a VecAD<Base> vector, x is an AD<Base> object,
237 and y is AD<Base> or Base objects.
238 We define the index corresponding to v[x] by
239 \verbatim
240 i_v_x = vec_ad2index[ arg[0] + i_vec ]
241 \endverbatim
242 where i_vec is defined under the heading arg[1] below:
243 <!-- end preamble -->
244 ==============================================================================
245 */
246 /*!
247 Shared documnetation for sparsity operations corresponding to
248 op = StpvOp or StvvOp (not called).
249
250 \tparam Vector_set
251 is the type used for vectors of sets. It can be either
252 sparse::pack_setvec or sparse::list_setvec.
253
254 \param op
255 is the code corresponding to this operator;
256 i.e., StpvOp, StvpOp, or StvvOp.
257
258 \param arg
259 \n
260 arg[0]
261 is the offset corresponding to this VecAD vector in the combined array.
262 \n
263 \n
264 arg[2]
265 \n
266 The set with index arg[2] in var_sparsity
267 is the sparsity pattern corresponding to y.
268 (Note that arg[2] > 0 because y is a variable.)
269
270 \param num_combined
271 is the total number of elements in the VecAD address array.
272
273 \param combined
274 combined [ arg[0] - 1 ]
275 is the index of the set in vecad_sparsity corresponding
276 to the sparsity pattern for the vector v.
277 We use the notation i_v below which is defined by
278 \verbatim
279 i_v = combined[ arg[0] - 1 ]
280 \endverbatim
281
282 \param var_sparsity
283 The set with index arg[2] in var_sparsity
284 is the sparsity pattern for y.
285 This is an input for forward mode operations.
286 For reverse mode operations:
287 The sparsity pattern for v is added to the spartisy pattern for y.
288
289 \param vecad_sparsity
290 The set with index i_v in vecad_sparsity
291 is the sparsity pattern for v.
292 This is an input for reverse mode operations.
293 For forward mode operations, the sparsity pattern for y is added
294 to the sparsity pattern for the vector v.
295
296 \par Checked Assertions
297 \li NumArg(op) == 3
298 \li NumRes(op) == 0
299 \li 0 < arg[0]
300 \li arg[0] < num_combined
301 \li arg[2] < var_sparsity.n_set()
302 \li i_v < vecad_sparsity.n_set()
303 */
304 template <class Vector_set>
305 void sparse_store_op(
306 OpCode op ,
307 const addr_t* arg ,
308 size_t num_combined ,
309 const size_t* combined ,
310 Vector_set& var_sparsity ,
311 Vector_set& vecad_sparsity )
312 {
313 // This routine is only for documentaiton, it should not be used
314 CPPAD_ASSERT_UNKNOWN( false );
315 }
316
317
318
319 /*!
320 Forward mode sparsity operations for StpvOp and StvvOp
321
322 <!-- replace preamble -->
323 The C++ source code corresponding to this operation is
324 \verbatim
325 v[x] = y
326 \endverbatim
327 where v is a VecAD<Base> vector, x is an AD<Base> object,
328 and y is AD<Base> or Base objects.
329 We define the index corresponding to v[x] by
330 \verbatim
331 i_v_x = vec_ad2index[ arg[0] + i_vec ]
332 \endverbatim
333 where i_vec is defined under the heading arg[1] below:
334 <!-- end preamble -->
335
336 \param dependency
337 is this a dependency (or sparsity) calculation.
338
339 \copydetails CppAD::local::sparse_store_op
340 */
341 template <class Vector_set>
342 void forward_sparse_store_op(
343 bool dependency ,
344 OpCode op ,
345 const addr_t* arg ,
346 size_t num_combined ,
347 const size_t* combined ,
348 Vector_set& var_sparsity ,
349 Vector_set& vecad_sparsity )
350 {
351 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
352 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
353 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
354 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
355 size_t i_v = combined[ arg[0] - 1 ];
356 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
357 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
358
359 if( dependency & ( (op == StvvOp) | (op == StvpOp) ) )
360 vecad_sparsity.binary_union(i_v, i_v, size_t(arg[1]), var_sparsity);
361
362 if( (op == StpvOp) | (op == StvvOp ) )
363 vecad_sparsity.binary_union(i_v, i_v, size_t(arg[2]), var_sparsity);
364
365 return;
366 }
367
368 /*!
369 Reverse mode sparsity operations for StpvOp, StvpOp, and StvvOp
370
371 <!-- replace preamble -->
372 The C++ source code corresponding to this operation is
373 \verbatim
374 v[x] = y
375 \endverbatim
376 where v is a VecAD<Base> vector, x is an AD<Base> object,
377 and y is AD<Base> or Base objects.
378 We define the index corresponding to v[x] by
379 \verbatim
380 i_v_x = vec_ad2index[ arg[0] + i_vec ]
381 \endverbatim
382 where i_vec is defined under the heading arg[1] below:
383 <!-- end preamble -->
384
385 This routine is given the sparsity patterns for
386 G(v[x], y , w , u ... ) and it uses them to compute the
387 sparsity patterns for
388 \verbatim
389 H(y , w , u , ... ) = G[ v[x], y , w , u , ... ]
390 \endverbatim
391
392 \param dependency
393 is this a dependency (or sparsity) calculation.
394
395 \copydetails CppAD::local::sparse_store_op
396 */
397 template <class Vector_set>
398 void reverse_sparse_jacobian_store_op(
399 bool dependency ,
400 OpCode op ,
401 const addr_t* arg ,
402 size_t num_combined ,
403 const size_t* combined ,
404 Vector_set& var_sparsity ,
405 Vector_set& vecad_sparsity )
406 {
407 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
408 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
409 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
410 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
411 size_t i_v = combined[ arg[0] - 1 ];
412 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
413 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
414
415 if( dependency & ( (op == StvpOp) | (op == StvvOp) ) )
416 var_sparsity.binary_union( size_t(arg[1]), size_t(arg[1]), i_v, vecad_sparsity);
417 if( (op == StpvOp) | (op == StvvOp) )
418 var_sparsity.binary_union( size_t(arg[2]), size_t(arg[2]), i_v, vecad_sparsity);
419
420 return;
421 }
422
423 /*!
424 Reverse mode sparsity operations for StpvOp and StvvOp
425
426 <!-- replace preamble -->
427 The C++ source code corresponding to this operation is
428 \verbatim
429 v[x] = y
430 \endverbatim
431 where v is a VecAD<Base> vector, x is an AD<Base> object,
432 and y is AD<Base> or Base objects.
433 We define the index corresponding to v[x] by
434 \verbatim
435 i_v_x = vec_ad2index[ arg[0] + i_vec ]
436 \endverbatim
437 where i_vec is defined under the heading arg[1] below:
438 <!-- end preamble -->
439
440 This routine is given the sparsity patterns for
441 G(v[x], y , w , u ... )
442 and it uses them to compute the sparsity patterns for
443 \verbatim
444 H(y , w , u , ... ) = G[ v[x], y , w , u , ... ]
445 \endverbatim
446
447 \copydetails CppAD::local::sparse_store_op
448
449 \param var_jacobian
450 var_jacobian[ arg[2] ]
451 is false (true) if the Jacobian of G with respect to y is always zero
452 (may be non-zero).
453
454 \param vecad_jacobian
455 vecad_jacobian[i_v]
456 is false (true) if the Jacobian with respect to x is always zero
457 (may be non-zero).
458 On input, it corresponds to the function G,
459 and on output it corresponds to the function H.
460 */
461 template <class Vector_set>
462 void reverse_sparse_hessian_store_op(
463 OpCode op ,
464 const addr_t* arg ,
465 size_t num_combined ,
466 const size_t* combined ,
467 Vector_set& var_sparsity ,
468 Vector_set& vecad_sparsity ,
469 bool* var_jacobian ,
470 bool* vecad_jacobian )
471 {
472 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
473 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
474 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
475 CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < num_combined );
476 size_t i_v = combined[ arg[0] - 1 ];
477 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() );
478 CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
479
480 var_sparsity.binary_union( size_t(arg[2]), size_t(arg[2]), i_v, vecad_sparsity);
481
482 var_jacobian[ arg[2] ] |= vecad_jacobian[i_v];
483
484 return;
485 }
486
487 } } // END_CPPAD_LOCAL_NAMESPACE
488 # endif
+0
-500
include/cppad/local/sub_op.hpp less more
0 # ifndef CPPAD_LOCAL_SUB_OP_HPP
1 # define CPPAD_LOCAL_SUB_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file sub_op.hpp
17 Forward and reverse mode calculations for z = x - y.
18 */
19
20 // --------------------------- Subvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = SubvvOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = x - y
27 \endverbatim
28 In the documentation below,
29 this operations is for the case where both x and y are variables
30 and the argument parameter is not used.
31
32 \copydetails CppAD::local::forward_binary_op
33 */
34
35 template <class Base>
36 void forward_subvv_op(
37 size_t p ,
38 size_t q ,
39 size_t i_z ,
40 const addr_t* arg ,
41 const Base* parameter ,
42 size_t cap_order ,
43 Base* taylor )
44 {
45 // check assumptions
46 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
47 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
48 CPPAD_ASSERT_UNKNOWN( q < cap_order );
49 CPPAD_ASSERT_UNKNOWN( p <= q );
50
51 // Taylor coefficients corresponding to arguments and result
52 Base* x = taylor + size_t(arg[0]) * cap_order;
53 Base* y = taylor + size_t(arg[1]) * cap_order;
54 Base* z = taylor + i_z * cap_order;
55
56 for(size_t d = p; d <= q; d++)
57 z[d] = x[d] - y[d];
58 }
59 /*!
60 Multiple directions forward mode Taylor coefficients for op = SubvvOp.
61
62 The C++ source code corresponding to this operation is
63 \verbatim
64 z = x - y
65 \endverbatim
66 In the documentation below,
67 this operations is for the case where both x and y are variables
68 and the argument parameter is not used.
69
70 \copydetails CppAD::local::forward_binary_op_dir
71 */
72
73 template <class Base>
74 void forward_subvv_op_dir(
75 size_t q ,
76 size_t r ,
77 size_t i_z ,
78 const addr_t* arg ,
79 const Base* parameter ,
80 size_t cap_order ,
81 Base* taylor )
82 {
83 // check assumptions
84 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
85 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
86 CPPAD_ASSERT_UNKNOWN( 0 < q );
87 CPPAD_ASSERT_UNKNOWN( q < cap_order );
88
89 // Taylor coefficients corresponding to arguments and result
90 size_t num_taylor_per_var = (cap_order-1) * r + 1;
91 size_t m = (q-1) * r + 1;
92 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var + m;
93 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
94 Base* z = taylor + i_z * num_taylor_per_var + m;
95
96 for(size_t ell = 0; ell < r; ell++)
97 z[ell] = x[ell] - y[ell];
98 }
99
100 /*!
101 Compute zero order forward mode Taylor coefficients for result of op = SubvvOp.
102
103 The C++ source code corresponding to this operation is
104 \verbatim
105 z = x - y
106 \endverbatim
107 In the documentation below,
108 this operations is for the case where both x and y are variables
109 and the argument parameter is not used.
110
111 \copydetails CppAD::local::forward_binary_op_0
112 */
113
114 template <class Base>
115 void forward_subvv_op_0(
116 size_t i_z ,
117 const addr_t* arg ,
118 const Base* parameter ,
119 size_t cap_order ,
120 Base* taylor )
121 {
122 // check assumptions
123 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
124 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
125
126 // Taylor coefficients corresponding to arguments and result
127 Base* x = taylor + size_t(arg[0]) * cap_order;
128 Base* y = taylor + size_t(arg[1]) * cap_order;
129 Base* z = taylor + i_z * cap_order;
130
131 z[0] = x[0] - y[0];
132 }
133
134 /*!
135 Compute reverse mode partial derivatives for result of op = SubvvOp.
136
137 The C++ source code corresponding to this operation is
138 \verbatim
139 z = x - y
140 \endverbatim
141 In the documentation below,
142 this operations is for the case where both x and y are variables
143 and the argument parameter is not used.
144
145 \copydetails CppAD::local::reverse_binary_op
146 */
147
148 template <class Base>
149 void reverse_subvv_op(
150 size_t d ,
151 size_t i_z ,
152 const addr_t* arg ,
153 const Base* parameter ,
154 size_t cap_order ,
155 const Base* taylor ,
156 size_t nc_partial ,
157 Base* partial )
158 {
159 // check assumptions
160 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
161 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
162 CPPAD_ASSERT_UNKNOWN( d < cap_order );
163 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
164
165 // Partial derivatives corresponding to arguments and result
166 Base* px = partial + size_t(arg[0]) * nc_partial;
167 Base* py = partial + size_t(arg[1]) * nc_partial;
168 Base* pz = partial + i_z * nc_partial;
169
170 // number of indices to access
171 size_t i = d + 1;
172 while(i)
173 { --i;
174 px[i] += pz[i];
175 py[i] -= pz[i];
176 }
177 }
178
179 // --------------------------- Subpv -----------------------------------------
180 /*!
181 Compute forward mode Taylor coefficients for result of op = SubpvOp.
182
183 The C++ source code corresponding to this operation is
184 \verbatim
185 z = x - y
186 \endverbatim
187 In the documentation below,
188 this operations is for the case where x is a parameter and y is a variable.
189
190 \copydetails CppAD::local::forward_binary_op
191 */
192
193 template <class Base>
194 void forward_subpv_op(
195 size_t p ,
196 size_t q ,
197 size_t i_z ,
198 const addr_t* arg ,
199 const Base* parameter ,
200 size_t cap_order ,
201 Base* taylor )
202 {
203 // check assumptions
204 CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );
205 CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
206 CPPAD_ASSERT_UNKNOWN( q < cap_order );
207 CPPAD_ASSERT_UNKNOWN( p <= q );
208
209 // Taylor coefficients corresponding to arguments and result
210 Base* y = taylor + size_t(arg[1]) * cap_order;
211 Base* z = taylor + i_z * cap_order;
212
213 // Paraemter value
214 Base x = parameter[ arg[0] ];
215 if( p == 0 )
216 { z[0] = x - y[0];
217 p++;
218 }
219 for(size_t d = p; d <= q; d++)
220 z[d] = - y[d];
221 }
222 /*!
223 Multiple directions forward mode Taylor coefficients for op = SubpvOp.
224
225 The C++ source code corresponding to this operation is
226 \verbatim
227 z = x - y
228 \endverbatim
229 In the documentation below,
230 this operations is for the case where x is a parameter and y is a variable.
231
232 \copydetails CppAD::local::forward_binary_op_dir
233 */
234
235 template <class Base>
236 void forward_subpv_op_dir(
237 size_t q ,
238 size_t r ,
239 size_t i_z ,
240 const addr_t* arg ,
241 const Base* parameter ,
242 size_t cap_order ,
243 Base* taylor )
244 {
245 // check assumptions
246 CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );
247 CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
248 CPPAD_ASSERT_UNKNOWN( 0 < q );
249 CPPAD_ASSERT_UNKNOWN( q < cap_order );
250
251 // Taylor coefficients corresponding to arguments and result
252 size_t num_taylor_per_var = (cap_order-1) * r + 1;
253 size_t m = (q-1) * r + 1;
254 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
255 Base* z = taylor + i_z * num_taylor_per_var + m;
256
257 // Paraemter value
258 for(size_t ell = 0; ell < r; ell++)
259 z[ell] = - y[ell];
260 }
261 /*!
262 Compute zero order forward mode Taylor coefficient for result of op = SubpvOp.
263
264 The C++ source code corresponding to this operation is
265 \verbatim
266 z = x - y
267 \endverbatim
268 In the documentation below,
269 this operations is for the case where x is a parameter and y is a variable.
270
271 \copydetails CppAD::local::forward_binary_op_0
272 */
273
274 template <class Base>
275 void forward_subpv_op_0(
276 size_t i_z ,
277 const addr_t* arg ,
278 const Base* parameter ,
279 size_t cap_order ,
280 Base* taylor )
281 {
282 // check assumptions
283 CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );
284 CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
285
286 // Paraemter value
287 Base x = parameter[ arg[0] ];
288
289 // Taylor coefficients corresponding to arguments and result
290 Base* y = taylor + size_t(arg[1]) * cap_order;
291 Base* z = taylor + i_z * cap_order;
292
293 z[0] = x - y[0];
294 }
295
296 /*!
297 Compute reverse mode partial derivative for result of op = SubpvOp.
298
299 The C++ source code corresponding to this operation is
300 \verbatim
301 z = x - y
302 \endverbatim
303 In the documentation below,
304 this operations is for the case where x is a parameter and y is a variable.
305
306 \copydetails CppAD::local::reverse_binary_op
307 */
308
309 template <class Base>
310 void reverse_subpv_op(
311 size_t d ,
312 size_t i_z ,
313 const addr_t* arg ,
314 const Base* parameter ,
315 size_t cap_order ,
316 const Base* taylor ,
317 size_t nc_partial ,
318 Base* partial )
319 {
320 // check assumptions
321 CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );
322 CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
323 CPPAD_ASSERT_UNKNOWN( d < cap_order );
324 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
325
326 // Partial derivatives corresponding to arguments and result
327 Base* py = partial + size_t(arg[1]) * nc_partial;
328 Base* pz = partial + i_z * nc_partial;
329
330 // number of indices to access
331 size_t i = d + 1;
332 while(i)
333 { --i;
334 py[i] -= pz[i];
335 }
336 }
337
338 // --------------------------- Subvp -----------------------------------------
339 /*!
340 Compute forward mode Taylor coefficients for result of op = SubvvOp.
341
342 The C++ source code corresponding to this operation is
343 \verbatim
344 z = x - y
345 \endverbatim
346 In the documentation below,
347 this operations is for the case where x is a variable and y is a parameter.
348
349 \copydetails CppAD::local::forward_binary_op
350 */
351
352 template <class Base>
353 void forward_subvp_op(
354 size_t p ,
355 size_t q ,
356 size_t i_z ,
357 const addr_t* arg ,
358 const Base* parameter ,
359 size_t cap_order ,
360 Base* taylor )
361 {
362 // check assumptions
363 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
364 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
365 CPPAD_ASSERT_UNKNOWN( q < cap_order );
366 CPPAD_ASSERT_UNKNOWN( p <= q );
367
368 // Taylor coefficients corresponding to arguments and result
369 Base* x = taylor + size_t(arg[0]) * cap_order;
370 Base* z = taylor + i_z * cap_order;
371
372 // Parameter value
373 Base y = parameter[ arg[1] ];
374 if( p == 0 )
375 { z[0] = x[0] - y;
376 p++;
377 }
378 for(size_t d = p; d <= q; d++)
379 z[d] = x[d];
380 }
381 /*!
382 Multiple directions forward mode Taylor coefficients for op = SubvvOp.
383
384 The C++ source code corresponding to this operation is
385 \verbatim
386 z = x - y
387 \endverbatim
388 In the documentation below,
389 this operations is for the case where x is a variable and y is a parameter.
390
391 \copydetails CppAD::local::forward_binary_op_dir
392 */
393
394 template <class Base>
395 void forward_subvp_op_dir(
396 size_t q ,
397 size_t r ,
398 size_t i_z ,
399 const addr_t* arg ,
400 const Base* parameter ,
401 size_t cap_order ,
402 Base* taylor )
403 {
404 // check assumptions
405 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
406 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
407 CPPAD_ASSERT_UNKNOWN( 0 < q );
408 CPPAD_ASSERT_UNKNOWN( q < cap_order );
409
410 // Taylor coefficients corresponding to arguments and result
411 size_t num_taylor_per_var = (cap_order-1) * r + 1;
412 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
413 Base* z = taylor + i_z * num_taylor_per_var;
414
415 // Parameter value
416 size_t m = (q-1) * r + 1;
417 for(size_t ell = 0; ell < r; ell++)
418 z[m+ell] = x[m+ell];
419 }
420
421 /*!
422 Compute zero order forward mode Taylor coefficients for result of op = SubvvOp.
423
424 The C++ source code corresponding to this operation is
425 \verbatim
426 z = x - y
427 \endverbatim
428 In the documentation below,
429 this operations is for the case where x is a variable and y is a parameter.
430
431 \copydetails CppAD::local::forward_binary_op_0
432 */
433
434 template <class Base>
435 void forward_subvp_op_0(
436 size_t i_z ,
437 const addr_t* arg ,
438 const Base* parameter ,
439 size_t cap_order ,
440 Base* taylor )
441 {
442 // check assumptions
443 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
444 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
445
446 // Parameter value
447 Base y = parameter[ arg[1] ];
448
449 // Taylor coefficients corresponding to arguments and result
450 Base* x = taylor + size_t(arg[0]) * cap_order;
451 Base* z = taylor + i_z * cap_order;
452
453 z[0] = x[0] - y;
454 }
455
456 /*!
457 Compute reverse mode partial derivative for result of op = SubvpOp.
458
459 The C++ source code corresponding to this operation is
460 \verbatim
461 z = x - y
462 \endverbatim
463 In the documentation below,
464 this operations is for the case where x is a variable and y is a parameter.
465
466 \copydetails CppAD::local::reverse_binary_op
467 */
468
469 template <class Base>
470 void reverse_subvp_op(
471 size_t d ,
472 size_t i_z ,
473 const addr_t* arg ,
474 const Base* parameter ,
475 size_t cap_order ,
476 const Base* taylor ,
477 size_t nc_partial ,
478 Base* partial )
479 {
480 // check assumptions
481 CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );
482 CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
483 CPPAD_ASSERT_UNKNOWN( d < cap_order );
484 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
485
486 // Partial derivatives corresponding to arguments and result
487 Base* px = partial + size_t(arg[0]) * nc_partial;
488 Base* pz = partial + i_z * nc_partial;
489
490 // number of indices to access
491 size_t i = d + 1;
492 while(i)
493 { --i;
494 px[i] += pz[i];
495 }
496 }
497
498 } } // END_CPPAD_LOCAL_NAMESPACE
499 # endif
00 # ifndef CPPAD_LOCAL_SWEEP_DYNAMIC_HPP
11 # define CPPAD_LOCAL_SWEEP_DYNAMIC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
311311 case mul_dyn:
312312 CPPAD_ASSERT_UNKNOWN( n_arg == 2 );
313313 all_par_vec[i_par] = *par[0] * *par[1];
314 break;
315
316 // neg
317 case neg_dyn:
318 CPPAD_ASSERT_UNKNOWN( n_arg == 1 );
319 all_par_vec[i_par] = - *par[0];
314320 break;
315321
316322 // pow
00 # ifndef CPPAD_LOCAL_SWEEP_FOR_HES_HPP
11 # define CPPAD_LOCAL_SWEEP_FOR_HES_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
254254 include |= op == FunrpOp;
255255 include |= op == FunrvOp;
256256 //
257 if( include ) switch( op )
257 if( ! include )
258 { if( op == InvOp )
259 ++count_independent;
260 }
261 else switch( op )
258262 { // operators that should not occurr
259263 // case BeginOp
260264
329333 case CoshOp:
330334 case ExpOp:
331335 case LogOp:
336 case NegOp:
332337 case SinOp:
333338 case SinhOp:
334339 case SqrtOp:
426431 // -------------------------------------------------
427432
428433 case PowvpOp:
429 CPPAD_ASSERT_NARG_NRES(op, 2, 3)
434 CPPAD_ASSERT_NARG_NRES(op, 2, 1)
430435 sparse::for_hes_nl_unary_op(
431436 np1, numvar, i_var, size_t(arg[0]), for_hes_sparse
432437 );
476481 break;
477482
478483 case FunapOp:
479 // parameter argument for a atomic function
484 // parameter argument for an atomic function
480485 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 );
481486 CPPAD_ASSERT_UNKNOWN( atom_state == arg_atom );
482487 CPPAD_ASSERT_UNKNOWN( atom_i == 0 );
497502 break;
498503
499504 case FunavOp:
500 // variable argument for a atomic function
505 // variable argument for an atomic function
501506 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 );
502507 CPPAD_ASSERT_UNKNOWN( atom_state == arg_atom );
503508 CPPAD_ASSERT_UNKNOWN( atom_i == 0 );
504509 CPPAD_ASSERT_UNKNOWN( atom_j < atom_n );
510 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
511 CPPAD_ASSERT_UNKNOWN( size_t( arg[0] ) < numvar );
505512 //
506513 // arguemnt variables not avaialbe during sparisty calculations
507514 atom_x[atom_j] = CppAD::numeric_limits<Base>::quiet_NaN();
514521 break;
515522
516523 case FunrpOp:
517 // parameter result for a atomic function
524 // parameter result for an atomic function
518525 CPPAD_ASSERT_NARG_NRES(op, 1, 0);
519526 CPPAD_ASSERT_UNKNOWN( atom_state == ret_atom );
520527 CPPAD_ASSERT_UNKNOWN( atom_i < atom_m );
532539 break;
533540
534541 case FunrvOp:
535 // variable result for a atomic function
542 // variable result for an atomic function
536543 CPPAD_ASSERT_NARG_NRES(op, 0, 1);
537544 CPPAD_ASSERT_UNKNOWN( atom_state == ret_atom );
538545 CPPAD_ASSERT_UNKNOWN( atom_i < atom_m );
00 # ifndef CPPAD_LOCAL_SWEEP_FOR_JAC_HPP
11 # define CPPAD_LOCAL_SWEEP_FOR_JAC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
415415 // -------------------------------------------------
416416
417417 case LogOp:
418 case NegOp:
418419 CPPAD_ASSERT_NARG_NRES(op, 1, 1);
419420 sparse::for_jac_unary_op(
420421 i_var, size_t(arg[0]), var_sparsity
453454 // -------------------------------------------------
454455
455456 case PowvpOp:
456 CPPAD_ASSERT_NARG_NRES(op, 2, 3);
457 CPPAD_ASSERT_NARG_NRES(op, 2, 1);
457458 sparse::for_jac_unary_op(
458459 i_var, size_t(arg[0]), var_sparsity
459460 );
00 # ifndef CPPAD_LOCAL_SWEEP_FORWARD0_HPP
11 # define CPPAD_LOCAL_SWEEP_FORWARD0_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
635635 }
636636 }
637637 break;
638 // -------------------------------------------------
639
640 case NegOp:
641 forward_neg_op_0(i_var, size_t(arg[0]), J, taylor);
642 break;
643
638644 // -------------------------------------------------
639645
640646 case NepvOp:
00 # ifndef CPPAD_LOCAL_SWEEP_FORWARD1_HPP
11 # define CPPAD_LOCAL_SWEEP_FORWARD1_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
692692
693693 case MulvvOp:
694694 forward_mulvv_op(p, q, i_var, arg, parameter, J, taylor);
695 break;
696 // --------------------------------------------------
697
698 case NegOp:
699 forward_neg_op(p, q, i_var, size_t(arg[0]), J, taylor);
695700 break;
696701 // -------------------------------------------------
697702
00 # ifndef CPPAD_LOCAL_SWEEP_FORWARD2_HPP
11 # define CPPAD_LOCAL_SWEEP_FORWARD2_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
425425
426426 case MulvvOp:
427427 forward_mulvv_op_dir(q, r, i_var, arg, parameter, J, taylor);
428 break;
429 // -------------------------------------------------
430
431 case NegOp:
432 forward_neg_op_dir(q, r, i_var, size_t(arg[0]), J, taylor);
428433 break;
429434 // -------------------------------------------------
430435
00 # ifndef CPPAD_LOCAL_SWEEP_REV_HES_HPP
11 # define CPPAD_LOCAL_SWEEP_REV_HES_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
436436 // -------------------------------------------------
437437
438438 case LogOp:
439 case NegOp:
439440 CPPAD_ASSERT_NARG_NRES(op, 1, 1)
440441 sparse::rev_hes_nl_unary_op(
441442 i_var, size_t(arg[0]), RevJac, for_jac_sparse, rev_hes_sparse
482483 // -------------------------------------------------
483484
484485 case PowvpOp:
485 CPPAD_ASSERT_NARG_NRES(op, 2, 3)
486 CPPAD_ASSERT_NARG_NRES(op, 2, 1)
486487 sparse::rev_hes_nl_unary_op(
487488 i_var, size_t(arg[0]), RevJac, for_jac_sparse, rev_hes_sparse
488489 );
00 # ifndef CPPAD_LOCAL_SWEEP_REV_JAC_HPP
11 # define CPPAD_LOCAL_SWEEP_REV_JAC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
443443 // -------------------------------------------------
444444
445445 case LogOp:
446 case NegOp:
446447 CPPAD_ASSERT_NARG_NRES(op, 1, 1);
447448 sparse::rev_jac_unary_op(
448449 i_var, size_t(arg[0]), var_sparsity
00 # ifndef CPPAD_LOCAL_SWEEP_REVERSE_HPP
11 # define CPPAD_LOCAL_SWEEP_REVERSE_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
209209 size_t atom_index=0, atom_old=0, atom_m=0, atom_n=0, atom_i=0, atom_j=0;
210210 enum_atom_state atom_state = end_atom; // proper initialization
211211
212 // A vector with unspecified contents declared here so that operator
213 // routines do not need to re-allocate it
214 vector<Base> work;
215
212216 // temporary indices
213217 size_t j, ell;
214218
524528 d, i_var, arg, parameter, J, Taylor, K, Partial
525529 );
526530 break;
531 // -------------------------------------------------
532
533 case NegOp:
534 reverse_neg_op(
535 d, i_var, size_t(arg[0]), J, Taylor, K, Partial
536 );
537 break;
527538 // --------------------------------------------------
528539
529540 case ParOp:
533544 case PowvpOp:
534545 CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < num_par );
535546 reverse_powvp_op(
536 d, i_var, arg, parameter, J, Taylor, K, Partial
547 d, i_var, arg, parameter, J, Taylor, K, Partial, work
537548 );
538549 break;
539550 // -------------------------------------------------
+0
-231
include/cppad/local/tan_op.hpp less more
0 # ifndef CPPAD_LOCAL_TAN_OP_HPP
1 # define CPPAD_LOCAL_TAN_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file tan_op.hpp
18 Forward and reverse mode calculations for z = tan(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = TanOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = tan(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = tan(x)^2
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_tan_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* z = taylor + i_z * cap_order;
56 Base* y = z - cap_order;
57
58 size_t k;
59 if( p == 0 )
60 { z[0] = tan( x[0] );
61 y[0] = z[0] * z[0];
62 p++;
63 }
64 for(size_t j = p; j <= q; j++)
65 { Base base_j = static_cast<Base>(double(j));
66
67 z[j] = x[j];
68 for(k = 1; k <= j; k++)
69 z[j] += Base(double(k)) * x[k] * y[j-k] / base_j;
70
71 y[j] = z[0] * z[j];
72 for(k = 1; k <= j; k++)
73 y[j] += z[k] * z[j-k];
74 }
75 }
76
77 /*!
78 Multiple directions forward mode Taylor coefficient for op = TanOp.
79
80 The C++ source code corresponding to this operation is
81 \verbatim
82 z = tan(x)
83 \endverbatim
84 The auxillary result is
85 \verbatim
86 y = tan(x)^2
87 \endverbatim
88 The value of y, and its derivatives, are computed along with the value
89 and derivatives of z.
90
91 \copydetails CppAD::local::forward_unary2_op_dir
92 */
93 template <class Base>
94 void forward_tan_op_dir(
95 size_t q ,
96 size_t r ,
97 size_t i_z ,
98 size_t i_x ,
99 size_t cap_order ,
100 Base* taylor )
101 {
102 // check assumptions
103 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
104 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
105 CPPAD_ASSERT_UNKNOWN( 0 < q );
106 CPPAD_ASSERT_UNKNOWN( q < cap_order );
107
108 // Taylor coefficients corresponding to argument and result
109 size_t num_taylor_per_var = (cap_order-1) * r + 1;
110 Base* x = taylor + i_x * num_taylor_per_var;
111 Base* z = taylor + i_z * num_taylor_per_var;
112 Base* y = z - num_taylor_per_var;
113
114 size_t k;
115 size_t m = (q-1) * r + 1;
116 for(size_t ell = 0; ell < r; ell++)
117 { z[m+ell] = Base(double(q)) * ( x[m+ell] + x[m+ell] * y[0]);
118 for(k = 1; k < q; k++)
119 z[m+ell] += Base(double(k)) * x[(k-1)*r+1+ell] * y[(q-k-1)*r+1+ell];
120 z[m+ell] /= Base(double(q));
121 //
122 y[m+ell] = Base(2.0) * z[m+ell] * z[0];
123 for(k = 1; k < q; k++)
124 y[m+ell] += z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell];
125 }
126 }
127
128
129 /*!
130 Compute zero order forward mode Taylor coefficient for result of op = TanOp.
131
132 The C++ source code corresponding to this operation is
133 \verbatim
134 z = tan(x)
135 \endverbatim
136 The auxillary result is
137 \verbatim
138 y = cos(x)
139 \endverbatim
140 The value of y is computed along with the value of z.
141
142 \copydetails CppAD::local::forward_unary2_op_0
143 */
144 template <class Base>
145 void forward_tan_op_0(
146 size_t i_z ,
147 size_t i_x ,
148 size_t cap_order ,
149 Base* taylor )
150 {
151 // check assumptions
152 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
153 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
154 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
155
156 // Taylor coefficients corresponding to argument and result
157 Base* x = taylor + i_x * cap_order;
158 Base* z = taylor + i_z * cap_order; // called z in documentation
159 Base* y = z - cap_order; // called y in documentation
160
161 z[0] = tan( x[0] );
162 y[0] = z[0] * z[0];
163 }
164
165 /*!
166 Compute reverse mode partial derivatives for result of op = TanOp.
167
168 The C++ source code corresponding to this operation is
169 \verbatim
170 z = tan(x)
171 \endverbatim
172 The auxillary result is
173 \verbatim
174 y = cos(x)
175 \endverbatim
176 The value of y is computed along with the value of z.
177
178 \copydetails CppAD::local::reverse_unary2_op
179 */
180
181 template <class Base>
182 void reverse_tan_op(
183 size_t d ,
184 size_t i_z ,
185 size_t i_x ,
186 size_t cap_order ,
187 const Base* taylor ,
188 size_t nc_partial ,
189 Base* partial )
190 {
191 // check assumptions
192 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
193 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
194 CPPAD_ASSERT_UNKNOWN( d < cap_order );
195 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
196
197 // Taylor coefficients and partials corresponding to argument
198 const Base* x = taylor + i_x * cap_order;
199 Base* px = partial + i_x * nc_partial;
200
201 // Taylor coefficients and partials corresponding to first result
202 const Base* z = taylor + i_z * cap_order; // called z in doc
203 Base* pz = partial + i_z * nc_partial;
204
205 // Taylor coefficients and partials corresponding to auxillary result
206 const Base* y = z - cap_order; // called y in documentation
207 Base* py = pz - nc_partial;
208
209
210 size_t j = d;
211 size_t k;
212 Base base_two(2);
213 while(j)
214 {
215 px[j] += pz[j];
216 pz[j] /= Base(double(j));
217 for(k = 1; k <= j; k++)
218 { px[k] += azmul(pz[j], y[j-k]) * Base(double(k));
219 py[j-k] += azmul(pz[j], x[k]) * Base(double(k));
220 }
221 for(k = 0; k < j; k++)
222 pz[k] += azmul(py[j-1], z[j-k-1]) * base_two;
223
224 --j;
225 }
226 px[0] += azmul(pz[0], Base(1.0) + y[0]);
227 }
228
229 } } // END_CPPAD_LOCAL_NAMESPACE
230 # endif
+0
-230
include/cppad/local/tanh_op.hpp less more
0 # ifndef CPPAD_LOCAL_TANH_OP_HPP
1 # define CPPAD_LOCAL_TANH_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*!
17 \file tanh_op.hpp
18 Forward and reverse mode calculations for z = tanh(x).
19 */
20
21
22 /*!
23 Compute forward mode Taylor coefficient for result of op = TanOp.
24
25 The C++ source code corresponding to this operation is
26 \verbatim
27 z = tanh(x)
28 \endverbatim
29 The auxillary result is
30 \verbatim
31 y = tanh(x)^2
32 \endverbatim
33 The value of y, and its derivatives, are computed along with the value
34 and derivatives of z.
35
36 \copydetails CppAD::local::forward_unary2_op
37 */
38 template <class Base>
39 void forward_tanh_op(
40 size_t p ,
41 size_t q ,
42 size_t i_z ,
43 size_t i_x ,
44 size_t cap_order ,
45 Base* taylor )
46 {
47 // check assumptions
48 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
49 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
50 CPPAD_ASSERT_UNKNOWN( q < cap_order );
51 CPPAD_ASSERT_UNKNOWN( p <= q );
52
53 // Taylor coefficients corresponding to argument and result
54 Base* x = taylor + i_x * cap_order;
55 Base* z = taylor + i_z * cap_order;
56 Base* y = z - cap_order;
57
58 size_t k;
59 if( p == 0 )
60 { z[0] = tanh( x[0] );
61 y[0] = z[0] * z[0];
62 p++;
63 }
64 for(size_t j = p; j <= q; j++)
65 { Base base_j = static_cast<Base>(double(j));
66
67 z[j] = x[j];
68 for(k = 1; k <= j; k++)
69 z[j] -= Base(double(k)) * x[k] * y[j-k] / base_j;
70
71 y[j] = z[0] * z[j];
72 for(k = 1; k <= j; k++)
73 y[j] += z[k] * z[j-k];
74 }
75 }
76
77 /*!
78 Multiple directions forward mode Taylor coefficient for op = TanOp.
79
80 The C++ source code corresponding to this operation is
81 \verbatim
82 z = tanh(x)
83 \endverbatim
84 The auxillary result is
85 \verbatim
86 y = tanh(x)^2
87 \endverbatim
88 The value of y, and its derivatives, are computed along with the value
89 and derivatives of z.
90
91 \copydetails CppAD::local::forward_unary2_op_dir
92 */
93 template <class Base>
94 void forward_tanh_op_dir(
95 size_t q ,
96 size_t r ,
97 size_t i_z ,
98 size_t i_x ,
99 size_t cap_order ,
100 Base* taylor )
101 {
102 // check assumptions
103 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
104 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
105 CPPAD_ASSERT_UNKNOWN( 0 < q );
106 CPPAD_ASSERT_UNKNOWN( q < cap_order );
107
108 // Taylor coefficients corresponding to argument and result
109 size_t num_taylor_per_var = (cap_order-1) * r + 1;
110 Base* x = taylor + i_x * num_taylor_per_var;
111 Base* z = taylor + i_z * num_taylor_per_var;
112 Base* y = z - num_taylor_per_var;
113
114 size_t k;
115 size_t m = (q-1) * r + 1;
116 for(size_t ell = 0; ell < r; ell++)
117 { z[m+ell] = Base(double(q)) * ( x[m+ell] - x[m+ell] * y[0] );
118 for(k = 1; k < q; k++)
119 z[m+ell] -= Base(double(k)) * x[(k-1)*r+1+ell] * y[(q-k-1)*r+1+ell];
120 z[m+ell] /= Base(double(q));
121 //
122 y[m+ell] = Base(2.0) * z[m+ell] * z[0];
123 for(k = 1; k < q; k++)
124 y[m+ell] += z[(k-1)*r+1+ell] * z[(q-k-1)*r+1+ell];
125 }
126 }
127
128 /*!
129 Compute zero order forward mode Taylor coefficient for result of op = TanOp.
130
131 The C++ source code corresponding to this operation is
132 \verbatim
133 z = tanh(x)
134 \endverbatim
135 The auxillary result is
136 \verbatim
137 y = cos(x)
138 \endverbatim
139 The value of y is computed along with the value of z.
140
141 \copydetails CppAD::local::forward_unary2_op_0
142 */
143 template <class Base>
144 void forward_tanh_op_0(
145 size_t i_z ,
146 size_t i_x ,
147 size_t cap_order ,
148 Base* taylor )
149 {
150 // check assumptions
151 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
152 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
153 CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
154
155 // Taylor coefficients corresponding to argument and result
156 Base* x = taylor + i_x * cap_order;
157 Base* z = taylor + i_z * cap_order; // called z in documentation
158 Base* y = z - cap_order; // called y in documentation
159
160 z[0] = tanh( x[0] );
161 y[0] = z[0] * z[0];
162 }
163
164 /*!
165 Compute reverse mode partial derivatives for result of op = TanOp.
166
167 The C++ source code corresponding to this operation is
168 \verbatim
169 z = tanh(x)
170 \endverbatim
171 The auxillary result is
172 \verbatim
173 y = cos(x)
174 \endverbatim
175 The value of y is computed along with the value of z.
176
177 \copydetails CppAD::local::reverse_unary2_op
178 */
179
180 template <class Base>
181 void reverse_tanh_op(
182 size_t d ,
183 size_t i_z ,
184 size_t i_x ,
185 size_t cap_order ,
186 const Base* taylor ,
187 size_t nc_partial ,
188 Base* partial )
189 {
190 // check assumptions
191 CPPAD_ASSERT_UNKNOWN( NumArg(TanOp) == 1 );
192 CPPAD_ASSERT_UNKNOWN( NumRes(TanOp) == 2 );
193 CPPAD_ASSERT_UNKNOWN( d < cap_order );
194 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
195
196 // Taylor coefficients and partials corresponding to argument
197 const Base* x = taylor + i_x * cap_order;
198 Base* px = partial + i_x * nc_partial;
199
200 // Taylor coefficients and partials corresponding to first result
201 const Base* z = taylor + i_z * cap_order; // called z in doc
202 Base* pz = partial + i_z * nc_partial;
203
204 // Taylor coefficients and partials corresponding to auxillary result
205 const Base* y = z - cap_order; // called y in documentation
206 Base* py = pz - nc_partial;
207
208
209 size_t j = d;
210 size_t k;
211 Base base_two(2);
212 while(j)
213 {
214 px[j] += pz[j];
215 pz[j] /= Base(double(j));
216 for(k = 1; k <= j; k++)
217 { px[k] -= azmul(pz[j], y[j-k]) * Base(double(k));
218 py[j-k] -= azmul(pz[j], x[k]) * Base(double(k));
219 }
220 for(k = 0; k < j; k++)
221 pz[k] += azmul(py[j-1], z[j-k-1]) * base_two;
222
223 --j;
224 }
225 px[0] += azmul(pz[0], Base(1.0) - y[0]);
226 }
227
228 } } // END_CPPAD_LOCAL_NAMESPACE
229 # endif
00 # ifndef CPPAD_LOCAL_UTILITY_CPPAD_VECTOR_ITR_HPP
11 # define CPPAD_LOCAL_UTILITY_CPPAD_VECTOR_ITR_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
305305 %$$
306306 $codei%*%itr% = %element%
307307 %$$
308 $icode%element% = %itr%[%n%]
309 %$$
310 $icode%itr%[%n%] = %element%
311 %$$
308312
309313 $head Source$$
310314 $srccode%hpp% */
311315 public:
316 # if CPPAD_CONST
312317 const Type& operator*(void) const
313318 { check_element();
314319 return (*data_)[index_];
315320 }
316 # if ! CPPAD_CONST
321 const Type& operator[](difference_type n)
322 { return *(*this + n);
323 }
324 const Type& operator[](size_t n)
325 { return *( *this + difference_type(n) );
326 }
327 # else
317328 Type& operator*(void)
318329 { check_element();
319330 return (*data_)[index_];
320331 }
332 Type& operator[](difference_type n)
333 { return *(*this + n);
334 }
335 Type& operator[](size_t n)
336 { return *( *this + difference_type(n) );
337 }
321338 # endif
322339 /* %$$
323340 $end
333350 $section Vector Class Iterator Random Access$$
334351
335352 $head Syntax$$
336 $icode%element% = %itr%[%n%]
337 %$$
338 $icode%itr%[%n%] = %element%
339 %$$
340353 $icode%itr% %+-% = %n%
341354 %$$
342355 $icode%itr% = %other% %+-% %n%
372385 $head Source$$
373386 $srccode%hpp% */
374387 public:
375 CPPAD_VECTOR_ITR operator[](difference_type n)
376 { return *(*this + n);
377 }
378388 // sum and difference operators
379389 CPPAD_VECTOR_ITR& operator+=(difference_type n) noexcept
380390 { index_ += n;
+0
-517
include/cppad/local/zmul_op.hpp less more
0 # ifndef CPPAD_LOCAL_ZMUL_OP_HPP
1 # define CPPAD_LOCAL_ZMUL_OP_HPP
2 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4
5 CppAD is distributed under the terms of the
6 Eclipse Public License Version 2.0.
7
8 This Source Code may also be made available under the following
9 Secondary License when the conditions for such availability set forth
10 in the Eclipse Public License, Version 2.0 are satisfied:
11 GNU General Public License, Version 2.0 or later.
12 ---------------------------------------------------------------------------- */
13
14 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
15 /*!
16 \file mul_op.hpp
17 Forward and reverse mode calculations for z = azmul(x, y).
18 */
19
20 // --------------------------- Zmulvv -----------------------------------------
21 /*!
22 Compute forward mode Taylor coefficients for result of op = ZmulvvOp.
23
24 The C++ source code corresponding to this operation is
25 \verbatim
26 z = azmul(x, y)
27 \endverbatim
28 In the documentation below,
29 this operations is for the case where both x and y are variables
30 and the argument parameter is not used.
31
32 \copydetails CppAD::local::forward_binary_op
33 */
34
35 template <class Base>
36 void forward_zmulvv_op(
37 size_t p ,
38 size_t q ,
39 size_t i_z ,
40 const addr_t* arg ,
41 const Base* parameter ,
42 size_t cap_order ,
43 Base* taylor )
44 {
45 // check assumptions
46 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
47 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
48 CPPAD_ASSERT_UNKNOWN( q < cap_order );
49 CPPAD_ASSERT_UNKNOWN( p <= q );
50
51 // Taylor coefficients corresponding to arguments and result
52 Base* x = taylor + size_t(arg[0]) * cap_order;
53 Base* y = taylor + size_t(arg[1]) * cap_order;
54 Base* z = taylor + i_z * cap_order;
55
56 size_t k;
57 for(size_t d = p; d <= q; d++)
58 { z[d] = Base(0.0);
59 for(k = 0; k <= d; k++)
60 z[d] += azmul(x[d-k], y[k]);
61 }
62 }
63 /*!
64 Multiple directions forward mode Taylor coefficients for op = ZmulvvOp.
65
66 The C++ source code corresponding to this operation is
67 \verbatim
68 z = azmul(x, y)
69 \endverbatim
70 In the documentation below,
71 this operations is for the case where both x and y are variables
72 and the argument parameter is not used.
73
74 \copydetails CppAD::local::forward_binary_op_dir
75 */
76
77 template <class Base>
78 void forward_zmulvv_op_dir(
79 size_t q ,
80 size_t r ,
81 size_t i_z ,
82 const addr_t* arg ,
83 const Base* parameter ,
84 size_t cap_order ,
85 Base* taylor )
86 {
87 // check assumptions
88 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
89 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
90 CPPAD_ASSERT_UNKNOWN( 0 < q );
91 CPPAD_ASSERT_UNKNOWN( q < cap_order );
92
93 // Taylor coefficients corresponding to arguments and result
94 size_t num_taylor_per_var = (cap_order-1) * r + 1;
95 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var;
96 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var;
97 Base* z = taylor + i_z * num_taylor_per_var;
98
99 size_t k, ell, m;
100 for(ell = 0; ell < r; ell++)
101 { m = (q-1)*r + ell + 1;
102 z[m] = azmul(x[0], y[m]) + azmul(x[m], y[0]);
103 for(k = 1; k < q; k++)
104 z[m] += azmul(x[(q-k-1)*r + ell + 1], y[(k-1)*r + ell + 1]);
105 }
106 }
107
108 /*!
109 Compute zero order forward mode Taylor coefficients for result of op = ZmulvvOp.
110
111 The C++ source code corresponding to this operation is
112 \verbatim
113 z = azmul(x, y)
114 \endverbatim
115 In the documentation below,
116 this operations is for the case where both x and y are variables
117 and the argument parameter is not used.
118
119 \copydetails CppAD::local::forward_binary_op_0
120 */
121
122 template <class Base>
123 void forward_zmulvv_op_0(
124 size_t i_z ,
125 const addr_t* arg ,
126 const Base* parameter ,
127 size_t cap_order ,
128 Base* taylor )
129 {
130 // check assumptions
131 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
132 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
133
134 // Taylor coefficients corresponding to arguments and result
135 Base* x = taylor + size_t(arg[0]) * cap_order;
136 Base* y = taylor + size_t(arg[1]) * cap_order;
137 Base* z = taylor + i_z * cap_order;
138
139 z[0] = azmul(x[0], y[0]);
140 }
141
142 /*!
143 Compute reverse mode partial derivatives for result of op = ZmulvvOp.
144
145 The C++ source code corresponding to this operation is
146 \verbatim
147 z = azmul(x, y)
148 \endverbatim
149 In the documentation below,
150 this operations is for the case where both x and y are variables
151 and the argument parameter is not used.
152
153 \copydetails CppAD::local::reverse_binary_op
154 */
155
156 template <class Base>
157 void reverse_zmulvv_op(
158 size_t d ,
159 size_t i_z ,
160 const addr_t* arg ,
161 const Base* parameter ,
162 size_t cap_order ,
163 const Base* taylor ,
164 size_t nc_partial ,
165 Base* partial )
166 {
167 // check assumptions
168 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvvOp) == 2 );
169 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvvOp) == 1 );
170 CPPAD_ASSERT_UNKNOWN( d < cap_order );
171 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
172
173 // Arguments
174 const Base* x = taylor + size_t(arg[0]) * cap_order;
175 const Base* y = taylor + size_t(arg[1]) * cap_order;
176
177 // Partial derivatives corresponding to arguments and result
178 Base* px = partial + size_t(arg[0]) * nc_partial;
179 Base* py = partial + size_t(arg[1]) * nc_partial;
180 Base* pz = partial + i_z * nc_partial;
181
182 // number of indices to access
183 size_t j = d + 1;
184 size_t k;
185 while(j)
186 { --j;
187 for(k = 0; k <= j; k++)
188 {
189 px[j-k] += azmul(pz[j], y[k]);
190 py[k] += azmul(pz[j], x[j-k]);
191 }
192 }
193 }
194 // --------------------------- Zmulpv -----------------------------------------
195 /*!
196 Compute forward mode Taylor coefficients for result of op = ZmulpvOp.
197
198 The C++ source code corresponding to this operation is
199 \verbatim
200 z = azmul(x, y)
201 \endverbatim
202 In the documentation below,
203 this operations is for the case where x is a parameter and y is a variable.
204
205 \copydetails CppAD::local::forward_binary_op
206 */
207
208 template <class Base>
209 void forward_zmulpv_op(
210 size_t p ,
211 size_t q ,
212 size_t i_z ,
213 const addr_t* arg ,
214 const Base* parameter ,
215 size_t cap_order ,
216 Base* taylor )
217 {
218 // check assumptions
219 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
220 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
221 CPPAD_ASSERT_UNKNOWN( q < cap_order );
222 CPPAD_ASSERT_UNKNOWN( p <= q );
223
224 // Taylor coefficients corresponding to arguments and result
225 Base* y = taylor + size_t(arg[1]) * cap_order;
226 Base* z = taylor + i_z * cap_order;
227
228 // Paraemter value
229 Base x = parameter[ arg[0] ];
230
231 for(size_t d = p; d <= q; d++)
232 z[d] = azmul(x, y[d]);
233 }
234 /*!
235 Multiple directions forward mode Taylor coefficients for op = ZmulpvOp.
236
237 The C++ source code corresponding to this operation is
238 \verbatim
239 z = azmul(x, y)
240 \endverbatim
241 In the documentation below,
242 this operations is for the case where x is a parameter and y is a variable.
243
244 \copydetails CppAD::local::forward_binary_op_dir
245 */
246
247 template <class Base>
248 void forward_zmulpv_op_dir(
249 size_t q ,
250 size_t r ,
251 size_t i_z ,
252 const addr_t* arg ,
253 const Base* parameter ,
254 size_t cap_order ,
255 Base* taylor )
256 {
257 // check assumptions
258 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
259 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
260 CPPAD_ASSERT_UNKNOWN( 0 < q );
261 CPPAD_ASSERT_UNKNOWN( q < cap_order );
262
263 // Taylor coefficients corresponding to arguments and result
264 size_t num_taylor_per_var = (cap_order-1) * r + 1;
265 size_t m = (q-1) * r + 1;
266 Base* y = taylor + size_t(arg[1]) * num_taylor_per_var + m;
267 Base* z = taylor + i_z * num_taylor_per_var + m;
268
269 // Paraemter value
270 Base x = parameter[ arg[0] ];
271
272 for(size_t ell = 0; ell < r; ell++)
273 z[ell] = azmul(x, y[ell]);
274 }
275 /*!
276 Compute zero order forward mode Taylor coefficient for result of op = ZmulpvOp.
277
278 The C++ source code corresponding to this operation is
279 \verbatim
280 z = azmul(x, y)
281 \endverbatim
282 In the documentation below,
283 this operations is for the case where x is a parameter and y is a variable.
284
285 \copydetails CppAD::local::forward_binary_op_0
286 */
287
288 template <class Base>
289 void forward_zmulpv_op_0(
290 size_t i_z ,
291 const addr_t* arg ,
292 const Base* parameter ,
293 size_t cap_order ,
294 Base* taylor )
295 {
296 // check assumptions
297 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
298 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
299
300 // Paraemter value
301 Base x = parameter[ arg[0] ];
302
303 // Taylor coefficients corresponding to arguments and result
304 Base* y = taylor + size_t(arg[1]) * cap_order;
305 Base* z = taylor + i_z * cap_order;
306
307 z[0] = azmul(x, y[0]);
308 }
309
310 /*!
311 Compute reverse mode partial derivative for result of op = ZmulpvOp.
312
313 The C++ source code corresponding to this operation is
314 \verbatim
315 z = azmul(x, y)
316 \endverbatim
317 In the documentation below,
318 this operations is for the case where x is a parameter and y is a variable.
319
320 \copydetails CppAD::local::reverse_binary_op
321 */
322
323 template <class Base>
324 void reverse_zmulpv_op(
325 size_t d ,
326 size_t i_z ,
327 const addr_t* arg ,
328 const Base* parameter ,
329 size_t cap_order ,
330 const Base* taylor ,
331 size_t nc_partial ,
332 Base* partial )
333 {
334 // check assumptions
335 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulpvOp) == 2 );
336 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulpvOp) == 1 );
337 CPPAD_ASSERT_UNKNOWN( d < cap_order );
338 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
339
340 // Arguments
341 Base x = parameter[ arg[0] ];
342
343 // Partial derivatives corresponding to arguments and result
344 Base* py = partial + size_t(arg[1]) * nc_partial;
345 Base* pz = partial + i_z * nc_partial;
346
347 // number of indices to access
348 size_t j = d + 1;
349 while(j)
350 { --j;
351 py[j] += azmul(pz[j], x);
352 }
353 }
354 // --------------------------- Zmulvp -----------------------------------------
355 /*!
356 Compute forward mode Taylor coefficients for result of op = ZmulvpOp.
357
358 The C++ source code corresponding to this operation is
359 \verbatim
360 z = azmul(x, y)
361 \endverbatim
362 In the documentation below,
363 this operations is for the case where x is a parameter and y is a variable.
364
365 \copydetails CppAD::local::forward_binary_op
366 */
367
368 template <class Base>
369 void forward_zmulvp_op(
370 size_t p ,
371 size_t q ,
372 size_t i_z ,
373 const addr_t* arg ,
374 const Base* parameter ,
375 size_t cap_order ,
376 Base* taylor )
377 {
378 // check assumptions
379 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
380 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
381 CPPAD_ASSERT_UNKNOWN( q < cap_order );
382 CPPAD_ASSERT_UNKNOWN( p <= q );
383
384 // Taylor coefficients corresponding to arguments and result
385 Base* x = taylor + size_t(arg[0]) * cap_order;
386 Base* z = taylor + i_z * cap_order;
387
388 // Paraemter value
389 Base y = parameter[ arg[1] ];
390
391 for(size_t d = p; d <= q; d++)
392 z[d] = azmul(x[d], y);
393 }
394 /*!
395 Multiple directions forward mode Taylor coefficients for op = ZmulvpOp.
396
397 The C++ source code corresponding to this operation is
398 \verbatim
399 z = azmul(x, y)
400 \endverbatim
401 In the documentation below,
402 this operations is for the case where x is a parameter and y is a variable.
403
404 \copydetails CppAD::local::forward_binary_op_dir
405 */
406
407 template <class Base>
408 void forward_zmulvp_op_dir(
409 size_t q ,
410 size_t r ,
411 size_t i_z ,
412 const addr_t* arg ,
413 const Base* parameter ,
414 size_t cap_order ,
415 Base* taylor )
416 {
417 // check assumptions
418 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
419 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
420 CPPAD_ASSERT_UNKNOWN( 0 < q );
421 CPPAD_ASSERT_UNKNOWN( q < cap_order );
422
423 // Taylor coefficients corresponding to arguments and result
424 size_t num_taylor_per_var = (cap_order-1) * r + 1;
425 size_t m = (q-1) * r + 1;
426 Base* x = taylor + size_t(arg[0]) * num_taylor_per_var + m;
427 Base* z = taylor + i_z * num_taylor_per_var + m;
428
429 // Paraemter value
430 Base y = parameter[ arg[1] ];
431
432 for(size_t ell = 0; ell < r; ell++)
433 z[ell] = azmul(x[ell], y);
434 }
435 /*!
436 Compute zero order forward mode Taylor coefficient for result of op = ZmulvpOp.
437
438 The C++ source code corresponding to this operation is
439 \verbatim
440 z = azmul(x, y)
441 \endverbatim
442 In the documentation below,
443 this operations is for the case where x is a parameter and y is a variable.
444
445 \copydetails CppAD::local::forward_binary_op_0
446 */
447
448 template <class Base>
449 void forward_zmulvp_op_0(
450 size_t i_z ,
451 const addr_t* arg ,
452 const Base* parameter ,
453 size_t cap_order ,
454 Base* taylor )
455 {
456 // check assumptions
457 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
458 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
459
460 // Paraemter value
461 Base y = parameter[ arg[1] ];
462
463 // Taylor coefficients corresponding to arguments and result
464 Base* x = taylor + size_t(arg[0]) * cap_order;
465 Base* z = taylor + i_z * cap_order;
466
467 z[0] = azmul(x[0], y);
468 }
469
470 /*!
471 Compute reverse mode partial derivative for result of op = ZmulvpOp.
472
473 The C++ source code corresponding to this operation is
474 \verbatim
475 z = azmul(x, y)
476 \endverbatim
477 In the documentation below,
478 this operations is for the case where x is a parameter and y is a variable.
479
480 \copydetails CppAD::local::reverse_binary_op
481 */
482
483 template <class Base>
484 void reverse_zmulvp_op(
485 size_t d ,
486 size_t i_z ,
487 const addr_t* arg ,
488 const Base* parameter ,
489 size_t cap_order ,
490 const Base* taylor ,
491 size_t nc_partial ,
492 Base* partial )
493 {
494 // check assumptions
495 CPPAD_ASSERT_UNKNOWN( NumArg(ZmulvpOp) == 2 );
496 CPPAD_ASSERT_UNKNOWN( NumRes(ZmulvpOp) == 1 );
497 CPPAD_ASSERT_UNKNOWN( d < cap_order );
498 CPPAD_ASSERT_UNKNOWN( d < nc_partial );
499
500 // Arguments
501 Base y = parameter[ arg[1] ];
502
503 // Partial derivatives corresponding to arguments and result
504 Base* px = partial + size_t(arg[0]) * nc_partial;
505 Base* pz = partial + i_z * nc_partial;
506
507 // number of indices to access
508 size_t j = d + 1;
509 while(j)
510 { --j;
511 px[j] += azmul(pz[j], y);
512 }
513 }
514
515 } } // END_CPPAD_LOCAL_NAMESPACE
516 # endif
00 # ifndef CPPAD_UTILITY_ELAPSED_SECONDS_HPP
11 # define CPPAD_UTILITY_ELAPSED_SECONDS_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
1515 $begin elapsed_seconds$$
1616 $spell
1717 cppad.hpp
18 Microsoft
19 gettimeofday
20 std
21 chrono
18 std::chrono
2219 $$
2320
2421 $section Returns Elapsed Number of Seconds$$
2926 %$$
3027 $icode%s% = elapsed_seconds()%$$
3128
32 $head Purpose$$
33 This routine is accurate to within .02 seconds
34 (see $cref elapsed_seconds.cpp$$).
35 It does not necessary work for time intervals that are greater than a day.
36 $list number$$
37 If the C++11 $code std::chrono::steady_clock$$ is available,
38 it will be used for timing.
39 $lnext
40 Otherwise, if running under the Microsoft compiler,
41 $code ::GetSystemTime$$ will be used for timing.
42 $lnext
43 Otherwise, if $code gettimeofday$$ is available, it is used for timing.
44 $lnext
45 Otherwise, $code std::clock()$$ will be used for timing.
46 $lend
29 $head Accuracy$$
30 This routine uses $code std::chrono::steady_clock$$ to do its timing.
4731
4832 $head s$$
4933 is a $code double$$ equal to the
6145 -----------------------------------------------------------------------
6246 */
6347
64 // For some unknown reason under Fedora (which needs to be understood),
65 // if you move this include for cppad_assert.hpp below include for define.hpp,
66 // cd work/speed/example
67 // make test.sh
68 // fails with the error message 'gettimeofday' not defined.
6948 # include <cppad/core/cppad_assert.hpp>
70
71 // define nullptr
72 # include <cppad/local/define.hpp>
7349
7450 // needed before one can use CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL
7551 # include <cppad/utility/thread_alloc.hpp>
8056
8157
8258 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
83 /*!
84 \file elapsed_seconds.hpp
85 \brief Function that returns the elapsed seconds from first call.
86 */
8759
88 /*!
89 Returns the elapsed number since the first call to this function.
90
91 This routine tries is accurate to within .02 seconds.
92 It does not necessary work for time intervals that are less than a day.
93 \li
94 If running under the Microsoft system, it uses ::%GetSystemTime for timing.
95 \li
96 Otherwise, if gettimeofday is available, it is used.
97 \li
98 Otherwise, std::clock() is used.
99
100 \return
101 The number of seconds since the first call to elapsed_seconds.
102 */
10360 inline double elapsed_seconds(void)
10461 // --------------------------------------------------------------------------
10562 { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;
11774 }
11875 // --------------------------------------------------------------------------
11976 } // END_CPPAD_NAMESPACE
77
12078 # endif
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
115115 plus the following:
116116
117117 $subhead Check Size$$
118 The size of $icode vec$$ must be either zero
119 or the same size as $icode other$$ before doing the assignment.
120 If this is not the case, and $code NDEBUG$$ is not defined,
121 $code CppAD::vector$$ will use
122 $cref ErrorHandler$$
123 to generate an appropriate error report.
124 Requiring the sizes to agree checks that memory will not need to
125 be allocated to do the assignment (except when $icode vec$$ is empty).
126 Allowing for assignment to a vector with size zero makes the following
127 code work:
128 $codei%
129 CppAD::vector<%Scalar%> %vec%;
130 %vec% = %other%;
131 %$$
118 It is no longer necessary for $icode vec$$ to have the
119 same size as $icode other$$.
120 This makes $code CppAD::vector$$ more like $code std::vector$$.
132121
133122 $subhead Return Reference$$
134123 A reference to the vector $icode vec$$ is returned.
00 # ifndef CPPAD_UTILITY_ROMBERG_MUL_HPP
11 # define CPPAD_UTILITY_ROMBERG_MUL_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
265265
266266 r = RombergMulM1(Fm1, a, b, n, p, e);
267267
268 size_t i, j;
269268 Float prod = 1;
269 for(size_t i = 0; i < m-1; i++)
270 prod *= (b[i] - a[i]);
271
272 # ifndef NDEBUG
270273 size_t pow2 = 1;
271 for(i = 0; i < m-1; i++)
272 { prod *= (b[i] - a[i]);
273 for(j = 0; j < (n[i] - 1); j++)
274 for(size_t i = 0; i < m-1; i++)
275 for(size_t j = 0; j < (n[i] - 1); j++)
274276 pow2 *= 2;
275 }
276277 assert( Fm1.GetEcount() == (pow2+1) );
278 # endif
277279
278280 e = e + Fm1.GetEsum() * prod / Float( double(Fm1.GetEcount()) );
279281
00 # ifndef CPPAD_UTILITY_SPARSE_RC_HPP
11 # define CPPAD_UTILITY_SPARSE_RC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
3333 %$$
3434 $codei%sparse_rc<%SizeVector%> %pattern%(%nr%, %nc%, %nnz%)
3535 %$$
36 $codei%sparse_rc<%SizeVector%> %pattern%(%other%)
37 %$$
3638 $icode%pattern% = %other%
3739 %$$
3840 $icode%pattern%.swap(%other%)
7678 except during its constructor, $code resize$$, and $code set$$.
7779
7880 $head other$$
79 The $icode other$$ variable has prototype
80 $codei%
81 sparse_rc<%SizeVector%> %other%
82 %$$
83
84 $subhead Assignment$$
85 After the assignment statement, $icode other$$ is an independent copy
86 of $icode pattern$$; i.e. it has all the same values as $icode pattern$$
87 and changes to $icode other$$ do not affect $icode pattern$$.
88 A move semantics version of the assignment operator is defined; e.g.,
89 it is used when $icode other$$ in the assignment syntax
90 is a function return value.
81
82 $subhead Assignment and Constructor$$
83 In the assignment and constructor, $icode other$$ has prototype
84 $codei%
85 const sparse_rc<%SizeVector%>& %other%
86 %$$
87 After the assignment and constructor, $icode pattern$$ is an independent copy
88 of $icode other$$; i.e. it has all the same values as $icode other$$
89 and changes to $icode pattern$$ do not affect $icode other$$.
90
91 $subhead Move Semantics Assignment and Constructor$$
92 In the assignment and constructor, if $icode other$$ has prototype
93 $codei%
94 sparse_rc<%SizeVector%>&& %other%
95 %$$
96 A move semantics version of the assignment or constructor is used; e.g.,
97 when $icode other$$ is a function return value.
9198
9299 $subhead swap$$
100 In the swap operation, $icode other$$ has prototype
101 $codei%
102 sparse_rc<%SizeVector%>& %other%
103 %$$
93104 After the swap operation $icode other$$ ($icode pattern$$) is equivalent
94105 to $icode pattern$$ ($icode other$$) before the operation.
95106
00 # ifndef CPPAD_UTILITY_SPARSE_RCV_HPP
11 # define CPPAD_UTILITY_SPARSE_RCV_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
7676 and number of possibly non-zero values $icode nnz$$,
7777 are all zero.
7878
79
8079 $head pattern$$
8180 This constructor argument has prototype
8281 $codei%
9594 assignment and swap syntax.
9695
9796 $head other$$
98 The $icode other$$ variable has prototype
99 $codei%
100 sparse_rcv<%SizeVector%, %ValueVector%> %other%
101 %$$
102
103 $subhead Assignment$$
104 After this assignment statement, $icode other$$ is an independent copy
97
98 $subhead Assignment and Constructor$$
99 In the assignment and constructor, $icode other$$ has prototype
100 $codei%
101 const sparse_rcv<%SizeVector%, %ValueVector%>& %other%
102 %$$
103 After this assignment and constructor, $icode other$$ is an independent copy
105104 of $icode matrix$$; i.e. it has all the same values as $icode matrix$$
106 and changes to $icode other$$ do not affect $icode matrix$$.
107 A move semantics version of the assignment operator is defined; e.g.,
108 it is used when $icode other$$ in the assignment syntax
109 is a function return value;
105 and changes to $icode matrix$$ do not affect $icode other$$.
106
107 $subhead Move Semantics Assignment and Constructor$$
108 In the assignment and constructor, if $icode other$$ has prototype
109 $codei%
110 sparse_rcv<%SizeVector%, %ValueVector%>&& %other%
111 %$$
112 A move semantics version of the assignment operator is used; e.g.,
113 when $icode other$$ is a function return value;
110114
111115 $subhead swap$$
112116 After the swap operation $icode other$$ ($icode matrix$$) is equivalent
243247 /// default constructor
244248 sparse_rcv(void)
245249 : pattern_(0, 0, 0)
250 { }
251 /// copy constructor
252 sparse_rcv(const sparse_rcv& other)
253 :
254 pattern_( other.pat() ) ,
255 val_( other.val() )
246256 { }
247257 /// move semantics constructor
248258 /// (none of the default constructor values are used by destructor)
00 # ifndef CPPAD_UTILITY_THREAD_ALLOC_HPP
11 # define CPPAD_UTILITY_THREAD_ALLOC_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
844844 // This uses the system allocator, which is thread safe, but slower,
845845 // because the thread might wait for a lock on the allocator.
846846 v_node = ::operator new(sizeof(block_t) + cap_bytes);
847 CPPAD_ASSERT_UNKNOWN( v_node != nullptr );
847848 node = reinterpret_cast<block_t*>(v_node);
848849 node->tc_index_ = tc_index;
849850 void* v_ptr = reinterpret_cast<void*>(node + 1);
00 # ifndef CPPAD_UTILITY_VECTOR_HPP
11 # define CPPAD_UTILITY_VECTOR_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
284284 see $cref/user API assignment/CppAD_vector/Assignment/$$
285285
286286 $head Move Semantics$$
287 A move semantics version of the assignment operator
287 The move semantics version of the assignment operator
288288 is implemented using $code swap$$.
289289
290290 $end
292292 */
293293 // BEGIN_SWAP
294294 public:
295 // swap does not do any allocation and hence is declared noexcept
295296 void swap(vector& other) noexcept
296297 // END_SWAP
297298 { // special case where vec and other are the same vector
305306 }
306307
307308 // BEGIN_MOVE_ASSIGN
308 // Move semantics should not do any allocation.
309 // If NDEBUG is defined, this should not throw an exception.
310 vector& operator=(vector&& other) CPPAD_NDEBUG_NOEXCEPT
309 // move assingment does not doe any allocation and hence is declared noexcept
310 vector& operator=(vector&& other) noexcept
311311 // END_MOVE_ASSIGN
312 { CPPAD_ASSERT_KNOWN(
313 length_ == other.length_ || (length_ == 0),
314 "vector: size miss match in assignment operation"
315 );
316 swap(other);
312 { swap(other);
317313 return *this;
318314 }
319315
320316 // BEGIN_ASSIGN
321317 vector& operator=(const vector& other)
322318 // END_ASSIGN
323 { if( length_ == 0 )
324 resize( other.length_ );
325 CPPAD_ASSERT_KNOWN(
326 length_ == other.length_ ,
327 "vector: size miss match in assignment operation"
328 );
319 { // avoid copying old elements
320 resize(0);
321 // new size for this vector
322 resize( other.length_ );
323 // copy elements from other
329324 for(size_t i = 0; i < length_; i++)
330325 data_[i] = other.data_[i];
331326 return *this;
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
117117 cppad/core/fun_check.hpp \
118118 cppad/core/fun_construct.hpp \
119119 cppad/core/fun_eval.hpp \
120 cppad/core/graph/cpp_graph.hpp \
121 cppad/core/graph/from_graph.hpp \
122 cppad/core/graph/from_json.hpp \
123 cppad/core/graph/graph_op_enum.hpp \
124 cppad/core/graph/to_graph.hpp \
125 cppad/core/graph/to_json.hpp \
120126 cppad/core/hash_code.hpp \
121127 cppad/core/hessian.hpp \
122128 cppad/core/identical.hpp \
123129 cppad/core/independent/independent.hpp \
124130 cppad/core/integer.hpp \
125131 cppad/core/jacobian.hpp \
126 cppad/core/graph/from_json.hpp \
127 cppad/core/graph/graph_op_enum.hpp \
128 cppad/core/graph/to_json.hpp \
129132 cppad/core/lu_ratio.hpp \
130133 cppad/core/mul.hpp \
131134 cppad/core/mul_eq.hpp \
183186 cppad/ipopt/solve.hpp \
184187 cppad/ipopt/solve_callback.hpp \
185188 cppad/ipopt/solve_result.hpp \
186 cppad/local/abs_op.hpp \
187 cppad/local/acos_op.hpp \
188 cppad/local/acosh_op.hpp \
189189 cppad/local/ad_tape.hpp \
190 cppad/local/add_op.hpp \
191 cppad/local/asin_op.hpp \
192 cppad/local/asinh_op.hpp \
193 cppad/local/atan_op.hpp \
194 cppad/local/atanh_op.hpp \
195190 cppad/local/atom_state.hpp \
196191 cppad/local/atomic_index.hpp \
197192 cppad/local/color_general.hpp \
198193 cppad/local/color_symmetric.hpp \
199 cppad/local/comp_op.hpp \
200 cppad/local/cond_op.hpp \
201 cppad/local/cos_op.hpp \
202 cppad/local/cosh_op.hpp \
203194 cppad/local/cppad_colpack.hpp \
204 cppad/local/cskip_op.hpp \
205 cppad/local/csum_op.hpp \
206195 cppad/local/declare_ad.hpp \
207196 cppad/local/define.hpp \
208 cppad/local/discrete_op.hpp \
209 cppad/local/div_op.hpp \
210 cppad/local/erf_op.hpp \
211 cppad/local/exp_op.hpp \
212 cppad/local/expm1_op.hpp \
197 cppad/local/graph/cpp_graph_itr.hpp \
198 cppad/local/graph/cpp_graph_op.hpp \
199 cppad/local/graph/json_lexer.hpp \
200 cppad/local/graph/json_parser.hpp \
201 cppad/local/graph/json_writer.hpp \
213202 cppad/local/hash_code.hpp \
214203 cppad/local/independent.hpp \
215204 cppad/local/is_pod.hpp \
216 cppad/core/graph/from_graph.hpp \
217 cppad/local/graph/json_lexer.hpp \
218 cppad/core/graph/to_graph.hpp \
219 cppad/core/graph/cpp_graph.hpp \
220 cppad/local/graph/cpp_graph_itr.hpp \
221 cppad/local/graph/cpp_graph_op.hpp \
222 cppad/local/graph/json_parser.hpp \
223 cppad/local/graph/json_writer.hpp \
224 cppad/local/load_op.hpp \
225 cppad/local/log1p_op.hpp \
226 cppad/local/log_op.hpp \
227 cppad/local/mul_op.hpp \
228205 cppad/local/op.hpp \
206 cppad/local/op/abs_op.hpp \
207 cppad/local/op/acos_op.hpp \
208 cppad/local/op/acosh_op.hpp \
209 cppad/local/op/add_op.hpp \
210 cppad/local/op/asin_op.hpp \
211 cppad/local/op/asinh_op.hpp \
212 cppad/local/op/atan_op.hpp \
213 cppad/local/op/atanh_op.hpp \
214 cppad/local/op/comp_op.hpp \
215 cppad/local/op/cond_op.hpp \
216 cppad/local/op/cos_op.hpp \
217 cppad/local/op/cosh_op.hpp \
218 cppad/local/op/cskip_op.hpp \
219 cppad/local/op/csum_op.hpp \
220 cppad/local/op/discrete_op.hpp \
221 cppad/local/op/div_op.hpp \
222 cppad/local/op/erf_op.hpp \
223 cppad/local/op/exp_op.hpp \
224 cppad/local/op/expm1_op.hpp \
225 cppad/local/op/load_op.hpp \
226 cppad/local/op/log1p_op.hpp \
227 cppad/local/op/log_op.hpp \
228 cppad/local/op/mul_op.hpp \
229 cppad/local/op/neg_op.hpp \
230 cppad/local/op/parameter_op.hpp \
231 cppad/local/op/pow_op.hpp \
232 cppad/local/op/print_op.hpp \
233 cppad/local/op/prototype_op.hpp \
234 cppad/local/op/sign_op.hpp \
235 cppad/local/op/sin_op.hpp \
236 cppad/local/op/sinh_op.hpp \
237 cppad/local/op/sqrt_op.hpp \
238 cppad/local/op/store_op.hpp \
239 cppad/local/op/sub_op.hpp \
240 cppad/local/op/tan_op.hpp \
241 cppad/local/op/tanh_op.hpp \
242 cppad/local/op/zmul_op.hpp \
229243 cppad/local/op_code_dyn.hpp \
230244 cppad/local/op_code_var.hpp \
231245 cppad/local/optimize/cexp_info.hpp \
245259 cppad/local/optimize/record_vv.hpp \
246260 cppad/local/optimize/size_pair.hpp \
247261 cppad/local/optimize/usage.hpp \
248 cppad/local/parameter_op.hpp \
249262 cppad/local/play/addr_enum.hpp \
250263 cppad/local/play/atom_op_info.hpp \
251264 cppad/local/play/player.hpp \
254267 cppad/local/play/sequential_iterator.hpp \
255268 cppad/local/play/subgraph_iterator.hpp \
256269 cppad/local/pod_vector.hpp \
257 cppad/local/pow_op.hpp \
258 cppad/local/print_op.hpp \
259 cppad/local/prototype_op.hpp \
270 cppad/local/record/comp_op.hpp \
260271 cppad/local/record/cond_exp.hpp \
261 cppad/local/record/comp_op.hpp \
262272 cppad/local/record/put_dyn_atomic.hpp \
263273 cppad/local/record/put_var_atomic.hpp \
264274 cppad/local/record/put_var_vecad.hpp \
265275 cppad/local/record/recorder.hpp \
266276 cppad/local/set_get_in_parallel.hpp \
267 cppad/local/sign_op.hpp \
268 cppad/local/sin_op.hpp \
269 cppad/local/sinh_op.hpp \
270277 cppad/local/sparse/binary_op.hpp \
271278 cppad/local/sparse/internal.hpp \
272279 cppad/local/sparse/list_setvec.hpp \
273280 cppad/local/sparse/pack_setvec.hpp \
274281 cppad/local/sparse/svec_setvec.hpp \
275282 cppad/local/sparse/unary_op.hpp \
276 cppad/local/sqrt_op.hpp \
277283 cppad/local/std_set.hpp \
278 cppad/local/store_op.hpp \
279 cppad/local/sub_op.hpp \
280284 cppad/local/subgraph/arg_variable.hpp \
281285 cppad/local/subgraph/entire_call.hpp \
282286 cppad/local/subgraph/get_rev.hpp \
293297 cppad/local/sweep/rev_hes.hpp \
294298 cppad/local/sweep/rev_jac.hpp \
295299 cppad/local/sweep/reverse.hpp \
296 cppad/local/tan_op.hpp \
297 cppad/local/tanh_op.hpp \
298300 cppad/local/utility/cppad_vector_itr.hpp \
299301 cppad/local/utility/vector_bool.hpp \
300 cppad/local/zmul_op.hpp \
301302 cppad/speed/det_33.hpp \
302303 cppad/speed/det_by_lu.hpp \
303304 cppad/speed/det_by_minor.hpp \
262262 builddir = @builddir@
263263 compiler_has_conversion_warn = @compiler_has_conversion_warn@
264264 cppad_boostvector = @cppad_boostvector@
265 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
266265 cppad_cppadvector = @cppad_cppadvector@
267266 cppad_cxx_flags = @cppad_cxx_flags@
268267 cppad_description = @cppad_description@
317316 prefix = @prefix@
318317 program_transform_name = @program_transform_name@
319318 psdir = @psdir@
319 runstatedir = @runstatedir@
320320 sbindir = @sbindir@
321321 sharedstatedir = @sharedstatedir@
322322 srcdir = @srcdir@
328328 @CppAD_POSTFIX_FALSE@postfix_dir = .
329329
330330 # -----------------------------------------------------------------------------
331 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
331 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
332332 #
333333 # CppAD is distributed under the terms of the
334334 # Eclipse Public License Version 2.0.
443443 cppad/core/fun_check.hpp \
444444 cppad/core/fun_construct.hpp \
445445 cppad/core/fun_eval.hpp \
446 cppad/core/graph/cpp_graph.hpp \
447 cppad/core/graph/from_graph.hpp \
448 cppad/core/graph/from_json.hpp \
449 cppad/core/graph/graph_op_enum.hpp \
450 cppad/core/graph/to_graph.hpp \
451 cppad/core/graph/to_json.hpp \
446452 cppad/core/hash_code.hpp \
447453 cppad/core/hessian.hpp \
448454 cppad/core/identical.hpp \
449455 cppad/core/independent/independent.hpp \
450456 cppad/core/integer.hpp \
451457 cppad/core/jacobian.hpp \
452 cppad/core/graph/from_json.hpp \
453 cppad/core/graph/graph_op_enum.hpp \
454 cppad/core/graph/to_json.hpp \
455458 cppad/core/lu_ratio.hpp \
456459 cppad/core/mul.hpp \
457460 cppad/core/mul_eq.hpp \
509512 cppad/ipopt/solve.hpp \
510513 cppad/ipopt/solve_callback.hpp \
511514 cppad/ipopt/solve_result.hpp \
512 cppad/local/abs_op.hpp \
513 cppad/local/acos_op.hpp \
514 cppad/local/acosh_op.hpp \
515515 cppad/local/ad_tape.hpp \
516 cppad/local/add_op.hpp \
517 cppad/local/asin_op.hpp \
518 cppad/local/asinh_op.hpp \
519 cppad/local/atan_op.hpp \
520 cppad/local/atanh_op.hpp \
521516 cppad/local/atom_state.hpp \
522517 cppad/local/atomic_index.hpp \
523518 cppad/local/color_general.hpp \
524519 cppad/local/color_symmetric.hpp \
525 cppad/local/comp_op.hpp \
526 cppad/local/cond_op.hpp \
527 cppad/local/cos_op.hpp \
528 cppad/local/cosh_op.hpp \
529520 cppad/local/cppad_colpack.hpp \
530 cppad/local/cskip_op.hpp \
531 cppad/local/csum_op.hpp \
532521 cppad/local/declare_ad.hpp \
533522 cppad/local/define.hpp \
534 cppad/local/discrete_op.hpp \
535 cppad/local/div_op.hpp \
536 cppad/local/erf_op.hpp \
537 cppad/local/exp_op.hpp \
538 cppad/local/expm1_op.hpp \
523 cppad/local/graph/cpp_graph_itr.hpp \
524 cppad/local/graph/cpp_graph_op.hpp \
525 cppad/local/graph/json_lexer.hpp \
526 cppad/local/graph/json_parser.hpp \
527 cppad/local/graph/json_writer.hpp \
539528 cppad/local/hash_code.hpp \
540529 cppad/local/independent.hpp \
541530 cppad/local/is_pod.hpp \
542 cppad/core/graph/from_graph.hpp \
543 cppad/local/graph/json_lexer.hpp \
544 cppad/core/graph/to_graph.hpp \
545 cppad/core/graph/cpp_graph.hpp \
546 cppad/local/graph/cpp_graph_itr.hpp \
547 cppad/local/graph/cpp_graph_op.hpp \
548 cppad/local/graph/json_parser.hpp \
549 cppad/local/graph/json_writer.hpp \
550 cppad/local/load_op.hpp \
551 cppad/local/log1p_op.hpp \
552 cppad/local/log_op.hpp \
553 cppad/local/mul_op.hpp \
554531 cppad/local/op.hpp \
532 cppad/local/op/abs_op.hpp \
533 cppad/local/op/acos_op.hpp \
534 cppad/local/op/acosh_op.hpp \
535 cppad/local/op/add_op.hpp \
536 cppad/local/op/asin_op.hpp \
537 cppad/local/op/asinh_op.hpp \
538 cppad/local/op/atan_op.hpp \
539 cppad/local/op/atanh_op.hpp \
540 cppad/local/op/comp_op.hpp \
541 cppad/local/op/cond_op.hpp \
542 cppad/local/op/cos_op.hpp \
543 cppad/local/op/cosh_op.hpp \
544 cppad/local/op/cskip_op.hpp \
545 cppad/local/op/csum_op.hpp \
546 cppad/local/op/discrete_op.hpp \
547 cppad/local/op/div_op.hpp \
548 cppad/local/op/erf_op.hpp \
549 cppad/local/op/exp_op.hpp \
550 cppad/local/op/expm1_op.hpp \
551 cppad/local/op/load_op.hpp \
552 cppad/local/op/log1p_op.hpp \
553 cppad/local/op/log_op.hpp \
554 cppad/local/op/mul_op.hpp \
555 cppad/local/op/neg_op.hpp \
556 cppad/local/op/parameter_op.hpp \
557 cppad/local/op/pow_op.hpp \
558 cppad/local/op/print_op.hpp \
559 cppad/local/op/prototype_op.hpp \
560 cppad/local/op/sign_op.hpp \
561 cppad/local/op/sin_op.hpp \
562 cppad/local/op/sinh_op.hpp \
563 cppad/local/op/sqrt_op.hpp \
564 cppad/local/op/store_op.hpp \
565 cppad/local/op/sub_op.hpp \
566 cppad/local/op/tan_op.hpp \
567 cppad/local/op/tanh_op.hpp \
568 cppad/local/op/zmul_op.hpp \
555569 cppad/local/op_code_dyn.hpp \
556570 cppad/local/op_code_var.hpp \
557571 cppad/local/optimize/cexp_info.hpp \
571585 cppad/local/optimize/record_vv.hpp \
572586 cppad/local/optimize/size_pair.hpp \
573587 cppad/local/optimize/usage.hpp \
574 cppad/local/parameter_op.hpp \
575588 cppad/local/play/addr_enum.hpp \
576589 cppad/local/play/atom_op_info.hpp \
577590 cppad/local/play/player.hpp \
580593 cppad/local/play/sequential_iterator.hpp \
581594 cppad/local/play/subgraph_iterator.hpp \
582595 cppad/local/pod_vector.hpp \
583 cppad/local/pow_op.hpp \
584 cppad/local/print_op.hpp \
585 cppad/local/prototype_op.hpp \
596 cppad/local/record/comp_op.hpp \
586597 cppad/local/record/cond_exp.hpp \
587 cppad/local/record/comp_op.hpp \
588598 cppad/local/record/put_dyn_atomic.hpp \
589599 cppad/local/record/put_var_atomic.hpp \
590600 cppad/local/record/put_var_vecad.hpp \
591601 cppad/local/record/recorder.hpp \
592602 cppad/local/set_get_in_parallel.hpp \
593 cppad/local/sign_op.hpp \
594 cppad/local/sin_op.hpp \
595 cppad/local/sinh_op.hpp \
596603 cppad/local/sparse/binary_op.hpp \
597604 cppad/local/sparse/internal.hpp \
598605 cppad/local/sparse/list_setvec.hpp \
599606 cppad/local/sparse/pack_setvec.hpp \
600607 cppad/local/sparse/svec_setvec.hpp \
601608 cppad/local/sparse/unary_op.hpp \
602 cppad/local/sqrt_op.hpp \
603609 cppad/local/std_set.hpp \
604 cppad/local/store_op.hpp \
605 cppad/local/sub_op.hpp \
606610 cppad/local/subgraph/arg_variable.hpp \
607611 cppad/local/subgraph/entire_call.hpp \
608612 cppad/local/subgraph/get_rev.hpp \
619623 cppad/local/sweep/rev_hes.hpp \
620624 cppad/local/sweep/rev_jac.hpp \
621625 cppad/local/sweep/reverse.hpp \
622 cppad/local/tan_op.hpp \
623 cppad/local/tanh_op.hpp \
624626 cppad/local/utility/cppad_vector_itr.hpp \
625627 cppad/local/utility/vector_bool.hpp \
626 cppad/local/zmul_op.hpp \
627628 cppad/speed/det_33.hpp \
628629 cppad/speed/det_by_lu.hpp \
629630 cppad/speed/det_by_minor.hpp \
293293 builddir = @builddir@
294294 compiler_has_conversion_warn = @compiler_has_conversion_warn@
295295 cppad_boostvector = @cppad_boostvector@
296 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
297296 cppad_cppadvector = @cppad_cppadvector@
298297 cppad_cxx_flags = @cppad_cxx_flags@
299298 cppad_description = @cppad_description@
348347 prefix = @prefix@
349348 program_transform_name = @program_transform_name@
350349 psdir = @psdir@
350 runstatedir = @runstatedir@
351351 sbindir = @sbindir@
352352 sharedstatedir = @sharedstatedir@
353353 srcdir = @srcdir@
6262 speed/cppad \
6363 speed/double \
6464 speed/example \
65 speed/xpackage \
6566 $(SPEED_FADBAD_TESTS) \
6667 $(SPEED_SACADO_TESTS)
6768 #
191191 CSCOPE = cscope
192192 DIST_SUBDIRS = cppad_ipopt/src example/ipopt_solve cppad_ipopt/example \
193193 cppad_ipopt/speed cppad_ipopt/test speed/src speed/adolc \
194 speed/cppad speed/double speed/example speed/fadbad \
195 speed/sacado cppad_lib example/abs_normal example/atomic_two \
196 example/atomic_three test_more/deprecated \
194 speed/cppad speed/double speed/example speed/xpackage \
195 speed/fadbad speed/sacado cppad_lib example/abs_normal \
196 example/atomic_two example/atomic_three test_more/deprecated \
197197 test_more/deprecated/atomic_two example/general \
198198 example/get_started example/optimize example/print_for \
199199 example/sparse example/utility include introduction \
341341 builddir = @builddir@
342342 compiler_has_conversion_warn = @compiler_has_conversion_warn@
343343 cppad_boostvector = @cppad_boostvector@
344 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
345344 cppad_cppadvector = @cppad_cppadvector@
346345 cppad_cxx_flags = @cppad_cxx_flags@
347346 cppad_description = @cppad_description@
396395 prefix = @prefix@
397396 program_transform_name = @program_transform_name@
398397 psdir = @psdir@
398 runstatedir = @runstatedir@
399399 sbindir = @sbindir@
400400 sharedstatedir = @sharedstatedir@
401401 srcdir = @srcdir@
458458 speed/cppad \
459459 speed/double \
460460 speed/example \
461 speed/xpackage \
461462 $(SPEED_FADBAD_TESTS) \
462463 $(SPEED_SACADO_TESTS)
463464
+0
-187
omh/adfun.omh less more
0 -------------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------------
11 $begin record_adfun$$
12 $spell
13 $$
14
15 $section Create an ADFun Object by Recording an Operation Sequence$$
16
17 $childtable%
18 include/cppad/core/independent/user.omh%
19 include/cppad/core/fun_construct.hpp%
20 include/cppad/core/dependent.hpp%
21 include/cppad/core/abort_recording.hpp%
22 omh/seq_property.omh
23 %$$
24
25 $end
26 -------------------------------------------------------------------------------
27 $begin other_adfun$$
28 $spell
29 $$
30
31 $section Other Ways to Create an ADFun Object$$
32
33
34 $childtable%
35 include/cppad/core/base2ad.hpp%
36 include/cppad/core/graph/json_ad_graph.omh%
37 include/cppad/core/graph/cpp_ad_graph.omh%
38 include/cppad/core/abs_normal_fun.hpp
39 %$$
40
41 $head See Also$$
42 $table
43 $rref switch_var_dyn.cpp$$
44 $tend
45
46 $end
47 -------------------------------------------------------------------------------
48 $begin drivers$$
49 $spell
50 $$
51
52
53 $section First and Second Order Derivatives: Easy Drivers$$
54
55
56 $childtable%
57 include/cppad/core/jacobian.hpp%
58 include/cppad/core/hessian.hpp%
59 include/cppad/core/for_one.hpp%
60 include/cppad/core/rev_one.hpp%
61 include/cppad/core/for_two.hpp%
62 include/cppad/core/rev_two.hpp
63 %$$
64
65 $end
66 -------------------------------------------------------------------------------
67 $begin Forward$$
68
69 $section Forward Mode$$
70
71 $childtable%
72 include/cppad/core/new_dynamic.hpp%
73 include/cppad/core/forward/forward_zero.omh%
74 include/cppad/core/forward/forward_one.omh%
75 include/cppad/core/forward/forward_two.omh%
76 include/cppad/core/forward/forward_order.omh%
77 include/cppad/core/forward/forward_dir.omh%
78 include/cppad/core/forward/size_order.omh%
79 include/cppad/core/forward/compare_change.omh%
80 include/cppad/core/capacity_order.hpp%
81 include/cppad/core/num_skip.hpp
82 %$$
83
84 $end
85 -------------------------------------------------------------------------------
86 $begin Reverse$$
87 $spell
88 xq
89 $$
90
91 $section Reverse Mode$$
92
93 $head Multiple Directions$$
94 Reverse mode after $cref/Forward(q, r, xq)/forward_dir/$$
95 with number of directions $icode%r% != 1%$$ is not yet supported.
96 There is one exception, $cref reverse_one$$ is allowed
97 because there is only one zero order forward direction.
98 After such an operation, only the zero order forward
99 results are retained (the higher order forward results are lost).
100
101 $childtable%
102 omh/reverse/reverse_one.omh%
103 omh/reverse/reverse_two.omh%
104 omh/reverse/reverse_any.omh%
105 include/cppad/core/subgraph_reverse.hpp
106 %$$
107
108 $end
109 -------------------------------------------------------------------------------
110 $begin sparsity_pattern$$
111 $spell
112 $$
113
114
115 $section Calculating Sparsity Patterns$$
116
117 $children%
118 include/cppad/core/for_jac_sparsity.hpp%
119 include/cppad/core/rev_jac_sparsity.hpp%
120 include/cppad/core/for_hes_sparsity.hpp%
121 include/cppad/core/rev_hes_sparsity.hpp%
122 include/cppad/core/subgraph_sparsity.hpp%
123
124 example/sparse/dependency.cpp%
125 example/sparse/rc_sparsity.cpp%
126
127 include/cppad/core/for_sparse_jac.hpp%
128 include/cppad/core/rev_sparse_jac.hpp%
129 include/cppad/core/rev_sparse_hes.hpp%
130 include/cppad/core/for_sparse_hes.hpp
131
132 %$$
133
134 $head Preferred Sparsity Pattern Calculations$$
135 $table
136 $rref for_jac_sparsity$$
137 $rref rev_jac_sparsity$$
138 $rref for_hes_sparsity$$
139 $rref rev_hes_sparsity$$
140 $rref subgraph_sparsity$$
141 $tend
142
143 $head Old Sparsity Pattern Calculations$$
144 $table
145 $rref ForSparseJac$$
146 $rref RevSparseJac$$
147 $rref ForSparseHes$$
148 $rref RevSparseHes$$
149 $tend
150
151
152 $end
153 -------------------------------------------------------------------------------
154 $begin sparse_derivative$$
155 $spell
156 $$
157
158
159 $section Calculating Sparse Derivatives$$
160
161 $children%
162 include/cppad/core/sparse_jac.hpp%
163 include/cppad/core/sparse_jacobian.hpp%
164
165 include/cppad/core/sparse_hes.hpp%
166 include/cppad/core/sparse_hessian.hpp%
167
168 include/cppad/core/subgraph_jac_rev.hpp
169 %$$
170
171 $head Preferred Sparsity Patterns$$
172 $table
173 $rref sparse_jac$$
174 $rref sparse_hes$$
175 $rref subgraph_jac_rev$$
176 $tend
177
178 $head Old Sparsity Patterns$$
179 $table
180 $rref sparse_jacobian$$
181 $rref sparse_hessian$$
182 $tend
183
184
185 $end
186 -------------------------------------------------------------------------------
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
121121 There are other sizes attached to an ADFun object, for example,
122122 the number of operations in the sequence.
123123 In order to avoid confusion with these other sizes,
124 use $cref/size_var/seq_property/size_var/$$ to obtain
124 use $cref/size_var/fun_property/size_var/$$ to obtain
125125 the number of variables in the operation sequence.
126126
127127 $head taylor_size$$
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
149149 range direction with respect to all the domain directions.
150150 The times required for (speed of)
151151 calls $code Forward$$ and $code Reverse$$ are about equal.
152 The $cref/Parameter/seq_property/Parameter/$$
152 The $cref/Parameter/fun_property/Parameter/$$
153153 function can be used to quickly determine that
154154 some range directions have derivative zero.
155155
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3535 $latex F : \B{R}^n \rightarrow \B{R}^m $$
3636 where $latex \B{R}$$ is the space corresponding to objects of type
3737 $icode Base$$ (usually the real numbers),
38 $icode n$$ is the size of the $cref/domain/seq_property/Domain/$$ space, and
39 $icode m$$ is the size of the $cref/range/seq_property/Range/$$ space.
38 $icode n$$ is the size of the $cref/domain/fun_property/Domain/$$ space, and
39 $icode m$$ is the size of the $cref/range/fun_property/Range/$$ space.
4040 We refer to $latex F$$ as the AD function corresponding to
4141 the operation sequence stored in the object $icode f$$.
4242 (See the $cref/FunCheck discussion/FunCheck/Discussion/$$ for
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
847847 $pre
848848
849849 $$
850 The $cref/f.Parameter()/seq_property/Parameter/$$ function was added so that
850 The $cref/f.Parameter()/fun_property/Parameter/$$ function was added so that
851851 one can count how many components of the range space depend
852852 on the value of the domain space components.
853853 This helps when deciding whether to use forward or reverse mode.
861861 $pre
862862
863863 $$
864 The $cref Independent$$ and $cref/Parameter/seq_property/Parameter/$$ functions
864 The $cref Independent$$ and $cref/Parameter/fun_property/Parameter/$$ functions
865865 were moved below $cref ADFun$$ in the documentation.
866866
867867
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
393393
394394 $$
395395 Correct some references to $code var_size$$ that should have been
396 $cref/size_var/seq_property/size_var/$$.
396 $cref/size_var/fun_property/size_var/$$.
397397
398398 $head 11-04$$
399399 Put text written to standard output in the documentation for the
800800
801801 $$
802802 The $code var_size$$ member function was changed to
803 $cref/size_var/seq_property/size_var/$$
803 $cref/size_var/fun_property/size_var/$$
804804 (this is not backward compatible, but $code var_size$$ was just added on
805805 $cref/04-03/whats_new_06/04-03/$$).
806806
838838 The member functions of $cref ADFun$$ that return properties of
839839 AD of $icode Base$$
840840 $cref/operation sequence/glossary/Operation/Sequence/$$
841 have been grouped into the $cref seq_property$$ section.
842 In addition, the $cref seq_property.cpp$$ example has been added.
841 have been grouped into the $cref fun_property$$ section.
842 In addition, the $cref fun_property.cpp$$ example has been added.
843843 $pre
844844
845845 $$
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
105105
106106 $$
107107 Add the following functions:
108 $cref/size_op/seq_property/size_op/$$,
109 $cref/size_op_arg/seq_property/size_op_arg/$$,
108 $cref/size_op/fun_property/size_op/$$,
109 $cref/size_op_arg/fun_property/size_op_arg/$$,
110110 and
111 $cref/size_op_seq/seq_property/size_op_seq/$$.
111 $cref/size_op_seq/fun_property/size_op_seq/$$.
112112 In addition, improve and extend the
113 $cref seq_property.cpp$$ example.
113 $cref fun_property.cpp$$ example.
114114
115115 $head 11-28$$
116116 Fix bug in tape optimization with $cref VecAD$$ objects.
294294
295295 $$
296296 The function
297 $cref/size_VecAD/seq_property/size_VecAD/$$ function was added
297 $cref/size_VecAD/fun_property/size_VecAD/$$ function was added
298298 so that the user could see the $code VecAD$$ vectors
299299 and elements corresponding to an operation sequence.
300300
312312 Add hash table coding to reduce the number of copies of the same
313313 parameter value necessary in a tape recording.
314314 In addition, add the function
315 $cref/size_par/seq_property/size_par/$$ was added
315 $cref/size_par/fun_property/size_par/$$ was added
316316 so that the user could see the number of parameters
317317 corresponding to an operation sequence.
318318
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
183183 $head 02-11$$
184184 The $code speed$$ directory has been reorganized and the
185185 common part of the $cref/link routines/speed_main/Link Routines/$$,
186 as well as the $cref microsoft_timer$$,
186 as well as the $code microsoft_timer$$,
187187 have been moved to the subdirectory $code speed/src$$
188188 where a library is built.
189189
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
709709 The $cref/tape_addr_type/autotools/tape_addr_type/$$ option was added
710710 to the $cref/configure/autotools/Configure/$$ command line.
711711 $lnext
712 The function $cref/size_op_seq/seq_property/size_op_seq/$$ results uses
712 The function $cref/size_op_seq/fun_property/size_op_seq/$$ results uses
713713 $code sizeof(CppAD_TAPE_ADDR_TYPE)$$
714714 where it used to use $code sizeof(size_t)$$.
715715 $lnext
781781 description has been changed to explicitly specify that the
782782 default constructor is used to initialize elements of the array.
783783 $lnext
784 The $cref/size_op_seq/seq_property/size_op_seq/$$ documentation
784 The $cref/size_op_seq/fun_property/size_op_seq/$$ documentation
785785 has been improved to mention that the allocated memory may be larger.
786786 $lend
787787
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
176176 $cref/CondExp/CondExp/Optimize/$$.
177177 $lnext
178178 Add a phantom argument at the beginning of the operations sequence;
179 $cref/size_op_arg/seq_property/size_op_arg/$$ and $cref seq_property.cpp$$.
179 $cref/size_op_arg/fun_property/size_op_arg/$$ and $cref fun_property.cpp$$.
180180 (This helps with the optimization mentioned above.)
181181 $lnext
182182 Add the function $cref number_skip$$ to measure how much optimization
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
159159 %f%.size_op() * sizeof(%tape_addr_type)
160160 %$$
161161 was added to the value returned by
162 $cref/size_op_seq/seq_property/size_op_seq/$$.
162 $cref/size_op_seq/fun_property/size_op_seq/$$.
163163
164164 $head 11-04$$
165165 The method for iterating through the tape has been changed.
169169 %f%.size_op() * sizeof(%tape_addr_type) * 2
170170 %$$
171171 was added to the value returned by
172 $cref/size_op_seq/seq_property/size_op_seq/$$.
172 $cref/size_op_seq/fun_property/size_op_seq/$$.
173173 In addition, some minor corrections were made to the
174174 $cref/tape_addr_type/cmake/cppad_tape_addr_type/$$
175175 requirements.
466466
467467 $head 03-11$$
468468 Add sparse assignment statements; see $icode other$$ for
469 $cref/sparse_rc/sparse_rc/other/Assignment/$$ and
470 $cref/sparse_rcv/sparse_rcv/other/Assignment/$$.
471
469 $cref/sparse_rc/
470 sparse_rc/
471 other/
472 Assignment and Constructor
473 /$$ and
474 $cref/sparse_rcv/
475 sparse_rcv/
476 other/
477 Assignment and Constructor
478 /$$.
472479 $head 03-10$$
473480 Add the a sizing constructor to the
474481 $cref/sparse_rc syntax/sparse_rc/Syntax/$$; i.e.,
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
384384
385385 $head 08-05$$
386386 The amount of memory in an operation sequence has changed; see
387 $cref/f.size_op_seq/seq_property/size_op_seq/$$.
387 $cref/f.size_op_seq/fun_property/size_op_seq/$$.
388388
389389 $head 08-04$$
390390 Remove the restrictions on dynamic parameters.
417417 in a call to Independent.
418418 For this reason the function
419419 $icode%f%.size_dynamic()%$$ has been replaced by
420 $cref/size_dyn_ind/seq_property/size_dyn_ind/$$,
421 $cref/size_dyn_par/seq_property/size_dyn_par/$$, and
422 $cref/size_dyn_arg/seq_property/size_dyn_arg/$$.
420 $cref/size_dyn_ind/fun_property/size_dyn_ind/$$,
421 $cref/size_dyn_par/fun_property/size_dyn_par/$$, and
422 $cref/size_dyn_arg/fun_property/size_dyn_arg/$$.
423423
424424
425425 $head 07-23$$
452452 Another (smaller) reduction in the amount of extra memory used during the
453453 $cref optimize$$ process.
454454 This time a vector of length
455 $cref/size_op/seq_property/size_op/$$ was converted from the type
455 $cref/size_op/fun_property/size_op/$$ was converted from the type
456456 used for C++ enums to a type that only used one byte.
457457
458458 $head 06-13$$
459459 Reduce the amount of extra memory used during the $cref optimize$$ process.
460460 To be more specific, two vectors that were separate now share the same memory.
461461 These vectors have size equal to
462 $cref/size_op/seq_property/size_op/$$
462 $cref/size_op/fun_property/size_op/$$
463463 for the old operation sequence, and element type
464464 $cref/cppad_tape_addr_type/cmake/cppad_tape_addr_type/$$.
465465
508508 one byte.
509509 This changed $code CppAD::local::OpCode$$ to
510510 $code CPPAD_VEC_ENUM_TYPE$$ in the expression used to compute
511 $cref/size_op_arg/seq_property/size_op_seq/$$.
511 $cref/size_op_arg/fun_property/size_op_seq/$$.
512512 Note $code CPPAD_VEC_ENUM_TYPE$$ is not in CppAD API and may change.
513513 $lnext
514514 There was a bug in the call to $code optimize$$ for the CppAD
542542 This caused CppAD to always use more memory for storing tapes.
543543 This has been fixed so this extra memory is only allocated when it is needed.
544544 In addition it can be freed; see
545 $cref/size_random/seq_property/size_random/$$ and
545 $cref/size_random/fun_property/size_random/$$ and
546546 $cref/clear_subgraph/subgraph_reverse/clear_subgraph/$$.
547547 In addition, this changed the amount of memory returned by
548 $cref/size_op_seq/seq_property/size_op_seq/$$ so that it
548 $cref/size_op_seq/fun_property/size_op_seq/$$ so that it
549549 no longer includes the part returned by $code size_random$$.
550550
551551 $head 04-29$$
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
714714 More improvements, and bug fixes, in the optimization of $cref atomic$$
715715 operations.
716716 This results in a reduction in the number of parameters
717 $cref/size_par/seq_property/size_par/$$
717 $cref/size_par/fun_property/size_par/$$
718718 and the number of variables
719 $cref/size_var/seq_property/size_var/$$.
719 $cref/size_var/fun_property/size_var/$$.
720720
721721 $head 01-15$$
722722 Fix a bug in the optimization of $cref atomic_three$$
759759 $cref/checkpoint/chkpoint_one/$$ documentation.
760760 $lnext
761761 A phantom parameter, at index zero, was added; see
762 $cref/size_par/seq_property/size_par/$$.
762 $cref/size_par/fun_property/size_par/$$.
763763 $lnext
764764 There appears to have been a bug in $code put_con_par$$ (not tested for)
765765 whereby a constant parameter might match a dynamic parameter
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
128128 $cref/sparse_rcv/sparse_rcv/other/swap/$$ template classes.
129129 $lnext
130130 A move semantics version of the assignment operator was added to the
131 $cref/sparse_rc/sparse_rc/other/Assignment/$$ and
132 $cref/sparse_rcv/sparse_rcv/other/Assignment/$$ template classes.
131 $cref/sparse_rc/
132 sparse_rc/
133 other/
134 Move Semantics Assignment and Constructor
135 /$$
136 $cref/sparse_rcv/
137 sparse_rcv/
138 other/
139 Move Semantics Assignment and Constructor
140 /$$ template classes.
133141 $lnext
134142 The $icode job$$ option was added to the
135143 $cref/det_minor/link_det_minor/job/$$ and
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------- */
11
12 $begin whats_new_21$$
13 $spell
14 CppAD
15 cppad
16 cxx
17 cmake
18 json_lexer
19 std::isdigit
20 Microsoft
21 const
22 ifndef
23 iterator
24 azmul
25 nans
26 optimizer
27 eigen
28 cppadcg
29 ipopt
30 op_enum
31 fabs
32 hpp
33 var
34 vec
35 msys
36 cygwin
37 rcv
38 det
39 ltmain
40 lcppad
41 pkgconfig
42 cplusplus
43 txt
44 atan
45 $$
46
47 $section Changes and Additions to CppAD During 2021$$
48
49 $head 12-17$$
50 Add forward mode calculations using $code AD<double>$$ to the
51 $cref atomic_three_vector_op.cpp$$ example.
52
53 $head 12-16$$
54 Change $code virtual$$ to $code override$$ in all the
55 $cref atomic_three_example$$ files and
56 $cref multi_atomic_three_user$$.
57
58 $head 12-10$$
59 $list number$$
60 Added the example $cref atomic_three_vector_op.cpp$$.
61 $lnext
62 Fix some compiler warnings when building with $code NDEBUG$$ defined.
63 $lend
64
65 $head 12-08$$
66 Update to a newer version of the $cref autotools$$.
67
68 $head 09-04$$
69 There was a bug in the $cref atan2$$ function.
70 For example, the derivative of $code atan2(0,1)$$ was incorrect; see
71 $href%https://github.com/coin-or/CppAD/issues/120%issue 120%$$.
72 This has been fixed and the $cref atan2.cpp$$ example has been
73 extended to do more testing.
74
75 $head 08-31$$
76 There was a bug in the CMake configuration files such that
77 $code make check_example_multi_thread$$ was not being constructed.
78 Hence $code make check$$ did not include the multi_thread tests.
79 This has been fixed.
80
81 $head 08-27$$
82 The following error occurred
83 $codei%
84 compile_source_test: cplusplus_201100_ok is defined before expected
85 %$$
86 if the $cref cmake$$ command was run twice,
87 without first removing the $code CMakeCache.txt$$ file.
88 This has been fixed.
89
90
91 $head 08-26$$
92 The cmake command was extended to allow for one to specify
93 $cref/CMAKE_BUILD_TYPE/cmake/cmake_build_type/$$.
94 This forced changing the default for
95 $cref/cppad_debug_which/cmake/cppad_debug_which/$$ from
96 $code debug_all$$ to the empty string.
97
98 $head 07-31$$
99 Do more work on pkgconfig files:
100 Remove duplicates and put $code -L$$ entries
101 before $code -l$$ entries in $code Libs$$ section.
102 Furthermore, move all information from private to normal section.
103
104 $head 07-30$$
105 Fix a bug in the $cref pkgconfig$$ files.
106 To be specific, there was an extra $code -l$$ at the front of the list
107 of library flags; e.g.,
108 $code -l-lcppad_lib$$ was changed to $code -lcppad_lib$$.
109
110 $head 07-12$$
111 $list number$$
112 Change all the scripts called by $cref get_optional.sh$$ to use
113 all the processing units available on the system when compiling
114 and linking the optional packages.
115 $lnext
116 Fix $cref get_colpack.sh$$ so that it does not leave behind
117 $code ltmain.sh$$ and $code test-driver$$ in the top source directory.
118 $lnext
119 Change the $cref cmake$$ script use of $code CHECK_CXX_SOURCE_RUNS$$
120 to $code CHECK_CXX_SOURCE_COMPILES$$.
121 This makes it easier to use CppAD in a cross compiling context.
122 $lend
123
124 $head 06-22$$
125 Improve $cref Var2Par$$ documentation and $cref var2par.cpp$$ example
126 by separating dynamic and constant parameters.
127
128 $head 06-06$$
129 The $code CppAD::vector$$ assignment statement no longer requires the
130 size of the vectors to be the same; see
131 $cref/check size/CppAD_vector/Assignment/Check Size/$$.
132
133 $head 06-02$$
134 $list number$$
135 Remove $code microsoft_timer$$ which is no longer needed by
136 $cref elapsed_seconds$$ because c++11 required (starting this year).
137 $lnext
138 Remove any use of $code CMAKE_SOURCE_DIR$$.
139 This allows CppAD's top source directory
140 to be used as a subdirectory of a larger CMake package.
141 $lend
142
143 $head 05-12$$
144 $list number$$
145 The cmake
146 $cref/include_cppadcg/cmake/include_cppadcg/$$ option was not working
147 when cppadcg was the only optional package.
148 This has been fixed.
149 $lnext
150 The smallest size
151 for the $cref/det_minor/link_det_minor/$$ speed test
152 was changed from one to two (a 2 by 2 matrix).
153 $lend
154
155
156 $head 04-30$$
157 $list number$$
158 The conditional expression example $cref cond_exp.cpp$$ was improved.
159 $lnext
160 Restore the
161 $cref/
162 sparse_rcv copy constructor
163 /sparse_rcv
164 /other
165 /Assignment and Constructor
166 /$$
167 which was removed by mistake when the $code sparse_rcv$$
168 move semantics constructor was added.
169 $lend
170
171 $head 04-28$$
172 $list number$$
173 The change to the $cref/pow(x,y)/pow/$$ function on
174 $cref/02-06/whats_new_21/02-06/$$ handled the case where $icode x$$ is zero.
175 The $cref pow_nan.cpp$$ example was modified to show when the new
176 version of this function generates nans.
177 $lnext
178 Remove some uses of the deprecated
179 $cref/nan(zero)/nan/nan(zero)/ Deprecated 2015-10-04/$$ function.
180 $lend
181
182 $head 04-27$$
183 Fix the msys2 and cygwin system builds so that they use static
184 (instead of dynamic) libraries.
185 This is necessary so that static variables (in include files) can not have
186 multiple instances in Windows.
187
188 $head 04-26$$
189 There was a problem with the $cref cmake$$ command when
190 $cref ipopt$$ was the only optional package installed.
191 This was related to the ipopt
192 $cref/include directories/ipopt/Include Directories/$$ problem.
193
194 $head 04-16$$
195 Improve the instruction for adding a new speed test package; see
196 $cref speed_xpackage$$.
197
198 $head 04-09$$
199 The $cref cpp_graph_print$$ operation was failing when there were
200 atomic or discrete functions. This has been fixed.
201
202 $head 04-07$$
203 Documentation was added for the
204 $cref/print_graph_op/cpp_ad_graph/operator_arg/print_graph_op/$$ operator.
205 This is different from the function
206 $cref cpp_graph_print$$ which prints an entire graph.
207
208
209 $head 04-05$$
210 The $cref cpp_graph_print$$ operation was modified so that it printed the
211 text corresponding to atomic function names, discrete function names,
212 and print operators.
213
214 $head 04-02$$
215 The enum value $code dis_graph_op$$ was corrected to $code discrete_graph_op$$
216 in the documentation for
217 $cref/discrete_graph_op/cpp_ad_graph/operator_arg/discrete_graph_op/$$.
218
219
220 $head 03-29$$
221 Include the $cref/dependent_vec/cpp_ad_graph/dependent_vec/$$
222 in the output of $cref cpp_graph_print$$; see $code y nodes$$ in
223 $cref print_graph.cpp$$ example output.
224
225 $head 03-24$$
226 The C++ AD graph constructor, $cref cpp_graph_ctor$$,
227 cannot be called the first tile in parallel mode.
228 This condition has been added to the documentation
229 and assets were added to make sure it is true.
230
231 $head 03-11$$
232 Improve the discussion of identically equal; see
233 $cref/more complicated case/base_identical/EqualOpSeq/More Complicated Case/$$.
234
235 $head 03-09$$
236 Simplify the $cref fabs.cpp$$ example.
237
238 $head 03-08$$
239 For years the following comment in reverse.hpp was forgotten:
240 $codei%
241 // ? should use += here, first make test to demonstrate bug
242 %$$
243 A test case was created to demonstrate this bug and it was fixed
244 (see $code duplicate_dependent_var$$ in $code test_more/general/reverse.cpp$$).
245 This only affects reverse mode when
246 $cref/w/reverse_any/w/$$ has size $icode%q% * %m%$$ and
247 two of the dependent variables in the range of $icode f$$
248 are identically equal (actually the same variable).
249
250 $head 03-07$$
251 $list number$$
252 Fix bug in $cref/f.to_graph/to_graph/$$ that ocurred
253 when $icode f$$ had $code fabs$$ dynamic parameter operators.
254 To be more specific, if $code NDEBUG$$ was not defined,
255 an error from an unknown source would be detected in the file $code to_graph.hpp$$.
256 $lnext
257 Make $cref UnaryMinus$$ an atomic operation,
258 instead of using binary subtraction of zero minus the value being negated.
259 In addition, add it to the $cref/json_graph unary operators/json_graph_op/Unary Operators/$$ and
260 the $cref/graph_op_enum values/graph_op_enum/Enum Values/$$ values.
261 $lend
262
263 $head 02-21$$
264 Add specifications for what is conditionally installed by the
265 $cref/include_eigen/cmake/include_eigen/$$ and
266 $cref/include_ipopt/cmake/include_ipopt/$$ options.
267 In addition, make it clearer that
268 $cref/include_cppadcg/cmake/include_cppadcg/$$ should only be used for testing.
269
270 $head 02-16$$
271 There was a problem with atomic functions, $cref optimize$$, and reverse mode
272 that would lead to unexpected nans.
273 This has been fixed by changing values,
274 that the optimizer determines are not used, from nan to zero.
275 A discussion of this was added below
276 $cref/azmul/atomic_three_reverse/partial_x/azmul/$$
277 in the atomic reverse documentation.
278
279 $head 02-14$$
280 $list number$$
281 Add the $cref/print/cpp_graph_print/$$ command to the
282 $code cpp_graph$$ class.
283 $lnext
284 Change the name of a documentation section form $code seq_property$$
285 to $cref fun_property$$.
286 $lnext
287 Add setting and getting a $code ADFun$$ function's
288 $cref/name/function_name/$$.
289 $lend
290
291 $head 02-12$$
292 $list number$$
293 In the case where
294 $cref/cppad_debug_which/cmake/cppad_debug_which/$$ is
295 $code debug_all$$ ($code debug_none$$) the corresponding
296 $icode CMAKE_BUILD_TYPE$$ is now specified as
297 $code Debug$$ ($code Release$$).
298 $lnext
299 Fix the $code Policy CMP0054$$ warning during the
300 $cref/cmake command/cmake/CMake Command/$$.
301 $lnext
302 Fix the $cref/Visual Studio/cmake/CMake Command/Visual Studio/$$ build.
303 This included commenting out part of the CppAD vector test
304 because the MSC compiler is confused between the vector's const_iterator and
305 iterator; see $code # ifndef _MSC_VER$$ in $cref cppad_vector.cpp$$.
306 $lend
307
308 $head 02-11$$
309 Fix some problems with the linking of the $code cppad_lib$$ library
310 when using the Microsoft compiler.
311
312 $head 02-08$$
313 Fix some problems in the
314 $cref/cppad.pc/pkgconfig/cppad.pc/$$ file; see pull request
315 $href%https://github.com/coin-or/CppAD/pull/95/files%95%$$.
316
317 $head 02-06$$
318 A special version of the $cref/pow(x, y)/pow/$$ function was added
319 for the special case where $icode y$$ is a parameter.
320 This properly handles the special case where $icode x$$ is zero
321 and $icode y$$ is greater than the order of the derivative.
322 In addition, it only requires one tape variable (instead of three)
323 for each $code pow$$ operation.
324
325 $head 01-27$$
326 There was a bug in the converting to abs_normal form when
327 the function $cref/f/abs_normal_fun/f/$$ made use of the
328 $cref pow$$ operator.
329 To be specific, when compiling without $code NDEBUG$$ defined,
330 an assert was generated even though the code was correct.
331 This has been fixed.
332
333 $head 01-26$$
334 Change the prototype for the cmake command
335 $cref/options/cmake/CMake Command/Options/$$ to use $icode true_or_false$$,
336 instead of $code true$$ to highlight the fact that one can choose either
337 true or false.
338
339 $head 01-08$$
340 On some systems, the file $code cppad_lib/json_lexer.cpp$$ would not compile
341 because the $code std::isdigit$$ function was not defined.
342 This has been fixed.
343
344 $head 01-07$$
345 The example $cref pow_nan.cpp$$ was added.
346
347 $head 01-05$$
348 $list number$$
349 Improve discussion of $cref/cppad_cxx/cmake/cppad_cxx_flags/$$
350 and make sure all uses are exactly as described.
351 In addition, change mention of optional features from C++11 to C++17.
352 $lnext
353 The required version of $cref cmake$$ was advanced from 2.8.4 to 3.0.
354 This fixes a policy CMP0042 warning on Mac systems.
355 $lnext
356 If the compiler, plus the flags in
357 $cref/cppad_cxx_flags/cmake/cppad_cxx_flags/$$,
358 does not by default support C++11, cmake is used
359 to find and add the flags necessary for this support.
360 $lend
361
362 $head 01-03$$
363 $list number$$
364 Fix a bug in $cref reverse$$ mode for an
365 $codei%ADFun< AD<%Base%> >%$$ function that has
366 $cref/dynamic/Independent/dynamic/$$ parameters and
367 value of one of these parameters was zero or one when the function
368 was recorded.
369 $lnext
370 Fix a bug in the $cref autotools$$ building of $code cppad_lib$$.
371 $lend
372
373 $end
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2626 assist you in learning about changes between various versions of CppAD.
2727
2828 $children%
29 omh/appendix/whats_new/21.omh%
2930 omh/appendix/whats_new/20.omh%
3031 omh/appendix/whats_new/19.omh%
3132 omh/appendix/whats_new/18.omh%
4748 %$$
4849
4950 $head This Year$$
50 $cref/2020/whats_new_20/$$
51 $cref/2021/whats_new_21/$$
5152
5253 $head Previous Years$$
54 $cref/2020/whats_new_20/$$,
5355 $cref/2019/whats_new_19/$$,
5456 $cref/2018/whats_new_18/$$,
5557 $cref/2017/whats_new_17/$$,
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
5656 For example, see
5757 $cref/base_alloc/base_alloc.hpp/EqualOpSeq/$$.
5858
59 $subhead More Complicated Cases$$
59 $subhead More Complicated Case$$
6060 The variables
61 $icode u$$ and $icode v$$ are not identically equal in the following case
62 (which CppAD automatically defines $code EqualOpSeq$$ for):
63 The type $icode Base$$ is $codei%AD<double>%$$,
64 $icode x[0] = x[1] = 1.$$,
65 then $cref independent$$ is used to make $icode x$$ the independent
66 variable vector,
67 and then $icode u = x[0]$$, $icode v = x[1]$$,
61 $icode u$$ and $icode v$$ are not identically equal in the following case:
62 $list number$$
63 The type $icode Base$$ is $codei%AD<double>%$$.
64 $lnext
65 The following assignment made using type $icode Base$$: $icode x[0] = x[1] = 1.$$,
66 $lnext
67 The $cref independent$$ operations is used to make $icode x$$
68 the independent variable vector,
69 $lnext
70 During the corresponding recording, $icode u = x[0]$$, $icode v = x[1]$$.
71 $lend
6872 Note that during a future $cref Forward$$ calculation,
6973 $icode u$$ and $icode v$$ could correspond to different values.
7074 For example, see
7680 A $icode Base$$ object is a
7781 $cref/constant/glossary/Parameter/Constant/$$ parameter
7882 when used in an $codei%AD<%Base%>%$$ operation sequence.
79 It is however still possible for a parameter to change its value.
80 For example,
81 the $icode Base$$ value $icode u$$ is not identically constant
82 in the following case
83 (which CppAD automatically defines $code IdenticalCon$$ for):
84 The type $icode Base$$ is $codei%AD<double>%$$,
85 $icode x[0] = 1.$$,
86 then $cref independent$$ is used to make $icode x$$ the independent
87 variable vector,
88 and then $icode u = x[0]$$,
89 Note that during a future $cref Forward$$ calculation,
90 $icode u$$ could correspond to different values.
83 It is however still possible for a parameter to change its value; e.g.,
84 see the more complicated case above.
9185
9286 $subhead Prototypes$$
9387 The argument $icode u$$ has prototype
00 $comment
11 -----------------------------------------------------------------------------
2 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
33
44 CppAD is distributed under the terms of the
55 Eclipse Public License Version 2.0.
6464
6565 $comment bin/version assumes that : follows cppad version number here$$
6666 $section
67 cppad-20210000.8: A C++ Algorithmic Differentiation Package$$
67 cppad-20220000.4: A C++ Algorithmic Differentiation Package$$
6868
6969 $comment =================================================================== $$
7070 $align middle$$
7676 $table
7777 $href%https://github.com/coin-or/CppAD/releases%
7878 releases%$$, $cnext
79 $href%https://github.com/coin-or/CppAD/archive/20210000.0.tar.gz%
80 20210000.0%$$, $cnext
79 $href%https://github.com/coin-or/CppAD/archive/20220000.0.tar.gz%
80 20220000.0%$$, $cnext
8181 $href%https://github.com/coin-or/CppAD%
8282 github%$$, $cnext
8383 $href%https://travis-ci.org/coin-or/CppAD%
00 -----------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2929 include/cppad/utility/omh/dev_utility.omh%
3030 include/cppad/local/op_code_var.hpp%
3131 omh/devel/vec_ad.omh%
32 include/cppad/local/is_pod.hpp
32 include/cppad/local/is_pod.hpp%
33 include/cppad/local/op/unary_op.omh%
34 include/cppad/local/op/binary_op.omh
3335 %$$
3436
3537
00 -----------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1717
1818 $childtable%
1919 include/cppad/core/vec_ad/vec_ad.hpp%
20 include/cppad/local/load_op.hpp%
21 include/cppad/local/store_op.hpp
20 include/cppad/local/op/load_op.hpp%
21 include/cppad/local/op/store_op.hpp
2222 %$$
2323
2424
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2121
2222 $comment BEGIN_SORT_THIS_LINE_PLUS_2$$
2323 $table
24 $rref AddEq.cpp$$
25 $rref Rombergmul.cpp$$
2426 $rref a11c_bthread.cpp$$
2527 $rref a11c_openmp.cpp$$
2628 $rref a11c_pthread.cpp$$
3638 $rref acosh.cpp$$
3739 $rref ad_assign.cpp$$
3840 $rref ad_ctor.cpp$$
39 $rref add.cpp$$
40 $rref AddEq.cpp$$
4141 $rref ad_fun.cpp$$
4242 $rref ad_in_c.cpp$$
4343 $rref ad_input.cpp$$
4444 $rref ad_output.cpp$$
45 $rref add.cpp$$
4546 $rref asin.cpp$$
4647 $rref asinh.cpp$$
48 $rref atan.cpp$$
4749 $rref atan2.cpp$$
48 $rref atan.cpp$$
4950 $rref atanh.cpp$$
5051 $rref atomic_three_base2ad.cpp$$
5152 $rref atomic_three_dynamic.cpp$$
6061 $rref atomic_three_rev_depend.cpp$$
6162 $rref atomic_three_reverse.cpp$$
6263 $rref atomic_three_tangent.cpp$$
64 $rref atomic_three_vector_op.cpp$$
6365 $rref atomic_two_eigen_cholesky.cpp$$
6466 $rref atomic_two_eigen_cholesky.hpp$$
6567 $rref atomic_two_eigen_mat_inv.cpp$$
8486 $rref chkpoint_two_dynamic.cpp$$
8587 $rref chkpoint_two_get_started.cpp$$
8688 $rref chkpoint_two_ode.cpp$$
89 $rref code_gen_fun_file.cpp$$
90 $rref code_gen_fun_function.cpp$$
91 $rref code_gen_fun_jac_as_fun.cpp$$
92 $rref code_gen_fun_jacobian.cpp$$
93 $rref code_gen_fun_sparse_jac_as_fun.cpp$$
94 $rref code_gen_fun_sparse_jacobian.cpp$$
8795 $rref colpack_hes.cpp$$
8896 $rref colpack_hessian.cpp$$
8997 $rref colpack_jac.cpp$$
9098 $rref colpack_jacobian.cpp$$
99 $rref compare.cpp$$
91100 $rref compare_change.cpp$$
92 $rref compare.cpp$$
93 $rref code_gen_fun_file.cpp$$
94 $rref code_gen_fun_function.cpp$$
95 $rref code_gen_fun_jacobian.cpp$$
96 $rref code_gen_fun_jac_as_fun.cpp$$
97 $rref code_gen_fun_sparse_jacobian.cpp$$
98 $rref code_gen_fun_sparse_jac_as_fun.cpp$$
99101 $rref complex_poly.cpp$$
102 $rref con_dyn_var.cpp$$
100103 $rref cond_exp.cpp$$
101 $rref con_dyn_var.cpp$$
102104 $rref conj_grad.cpp$$
103105 $rref cos.cpp$$
104106 $rref cosh.cpp$$
114116 $rref eigen_det.cpp$$
115117 $rref elapsed_seconds.cpp$$
116118 $rref equal_op_seq.cpp$$
119 $rref erf.cpp$$
117120 $rref erfc.cpp$$
118 $rref erf.cpp$$
119121 $rref error_handler.cpp$$
120122 $rref exp.cpp$$
121123 $rref expm1.cpp$$
133135 $rref from_json.cpp$$
134136 $rref fun_assign.cpp$$
135137 $rref fun_check.cpp$$
138 $rref fun_property.cpp$$
139 $rref function_name.cpp$$
136140 $rref general.cpp$$
137141 $rref get_started.cpp$$
138142 $rref graph_add_op.cpp$$
152156 $rref hes_lagrangian.cpp$$
153157 $rref hes_lu_det.cpp$$
154158 $rref hes_minor_det.cpp$$
159 $rref hes_times_dir.cpp$$
155160 $rref hessian.cpp$$
156 $rref hes_times_dir.cpp$$
157161 $rref independent.cpp$$
158162 $rref index_sort.cpp$$
159163 $rref integer.cpp$$
181185 $rref json_sub_op.cpp$$
182186 $rref json_sum_op.cpp$$
183187 $rref json_unary_op.cpp$$
188 $rref log.cpp$$
184189 $rref log10.cpp$$
185190 $rref log1p.cpp$$
186 $rref log.cpp$$
187191 $rref lp_box.cpp$$
188192 $rref lp_box.hpp$$
189193 $rref lu_factor.cpp$$
198202 $rref min_nso_quad.hpp$$
199203 $rref mul.cpp$$
200204 $rref mul_eq.cpp$$
205 $rref mul_level.cpp$$
201206 $rref mul_level_adolc.cpp$$
202207 $rref mul_level_adolc_ode.cpp$$
203 $rref mul_level.cpp$$
204208 $rref mul_level_ode.cpp$$
205209 $rref multi_atomic_three.cpp$$
206210 $rref multi_atomic_two.cpp$$
211215 $rref near_equal.cpp$$
212216 $rref near_equal_ext.cpp$$
213217 $rref new_dynamic.cpp$$
218 $rref num_limits.cpp$$
214219 $rref number_skip.cpp$$
215220 $rref numeric_type.cpp$$
216 $rref num_limits.cpp$$
217221 $rref ode_err_control.cpp$$
218222 $rref ode_err_maxabs.cpp$$
219223 $rref ode_evaluate.cpp$$
224 $rref ode_gear.cpp$$
220225 $rref ode_gear_control.cpp$$
221 $rref ode_gear.cpp$$
222226 $rref ode_stiff.cpp$$
227 $rref opt_val_hes.cpp$$
223228 $rref optimize_compare_op.cpp$$
224229 $rref optimize_conditional_skip.cpp$$
225230 $rref optimize_cumulative_sum.cpp$$
228233 $rref optimize_print_for.cpp$$
229234 $rref optimize_reverse_active.cpp$$
230235 $rref optimize_twice.cpp$$
231 $rref opt_val_hes.cpp$$
232236 $rref poly.cpp$$
233237 $rref pow.cpp$$
234238 $rref pow_int.cpp$$
239 $rref pow_nan.cpp$$
235240 $rref print_for_cout.cpp$$
236241 $rref print_for_string.cpp$$
242 $rref print_graph.cpp$$
237243 $rref qp_box.cpp$$
238244 $rref qp_box.hpp$$
239245 $rref qp_interior.cpp$$
240246 $rref qp_interior.hpp$$
241247 $rref rc_sparsity.cpp$$
242248 $rref rev_checkpoint.cpp$$
243 $rref reverse_one.cpp$$
244 $rref reverse_three.cpp$$
245 $rref reverse_two.cpp$$
246249 $rref rev_hes_sparsity.cpp$$
247250 $rref rev_jac_sparsity.cpp$$
248251 $rref rev_one.cpp$$
249252 $rref rev_sparse_hes.cpp$$
250253 $rref rev_sparse_jac.cpp$$
251254 $rref rev_two.cpp$$
252 $rref Rombergmul.cpp$$
255 $rref reverse_one.cpp$$
256 $rref reverse_three.cpp$$
257 $rref reverse_two.cpp$$
253258 $rref romberg_one.cpp$$
254259 $rref rosen_34.cpp$$
255260 $rref runge45_1.cpp$$
256261 $rref runge_45.cpp$$
257 $rref seq_property.cpp$$
258262 $rref set_union.cpp$$
259263 $rref simple_ad_bthread.cpp$$
260264 $rref simple_ad_openmp.cpp$$
270274 $rref sparse_hessian.cpp$$
271275 $rref sparse_jac_for.cpp$$
272276 $rref sparse_jac_fun.cpp$$
277 $rref sparse_jac_rev.cpp$$
273278 $rref sparse_jacobian.cpp$$
274 $rref sparse_jac_rev.cpp$$
275279 $rref sparse_rc.cpp$$
276280 $rref sparse_rcv.cpp$$
277281 $rref sparse_sub_hes.cpp$$
283287 $rref stack_machine.cpp$$
284288 $rref sub.cpp$$
285289 $rref sub_eq.cpp$$
290 $rref sub_sparse_hes.cpp$$
286291 $rref subgraph_hes2jac.cpp$$
287292 $rref subgraph_jac_rev.cpp$$
288293 $rref subgraph_reverse.cpp$$
289294 $rref subgraph_sparsity.cpp$$
290 $rref sub_sparse_hes.cpp$$
291295 $rref switch_var_dyn.cpp$$
292296 $rref tan.cpp$$
293297 $rref tanh.cpp$$
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
439439 std::numeric_limits<%tape_addr_type%>::max()
440440 %$$
441441 must be larger than any of the following:
442 $cref/size_op/seq_property/size_op/$$,
443 $cref/size_op_arg/seq_property/size_op_arg/$$,
444 $cref/size_par/seq_property/size_text/$$,
445 $cref/size_par/seq_property/size_par/$$,
446 $cref/size_par/seq_property/size_VecAD/$$.
442 $cref/size_op/fun_property/size_op/$$,
443 $cref/size_op_arg/fun_property/size_op_arg/$$,
444 $cref/size_par/fun_property/size_text/$$,
445 $cref/size_par/fun_property/size_par/$$,
446 $cref/size_par/fun_property/size_VecAD/$$.
447447
448448
449449 $head tape_id_type$$
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1212 $begin cmake$$
1313 $escape $$
1414 $spell
15 Rel
1516 cppadcg
1617 msys
1718 Hsc
130131 $codei%
131132 cmake %% \
132133 -D CMAKE_VERBOSE_MAKEFILE=%cmake_verbose_makefile% \
134 -D CMAKE_BUILD_TYPE=%cmake_build_type% \
133135 -G %generator% \
134136 \
135137 -D cppad_prefix=%cppad_prefix% \
141143 -D cmake_install_datadir=%cmake_install_datadir% \
142144 -D cmake_install_docdir=%cmake_install_docdir% \
143145 \
144 -D include_adolc=true \
145 -D include_eigen=true \
146 -D include_ipopt=true \
147 -D include_cppadcg=true
146 -D include_adolc=%true_or_false% \
147 -D include_eigen=%true_or_false% \
148 -D include_ipopt=%true_or_false% \
149 -D include_cppadcg=%true_or_false% \
148150 \
149151 -D colpack_prefix=%colpack_prefix% \
150152 -D fadbad_prefix=%fadbad_prefix% \
205207 nmake check
206208 $$
207209 $lend
210 Note that when using windows DLL's, CppAD builds a static version
211 of $code cppad_lib$$. There are problems using a DLL for $code cppad_lib$$
212 because Windows makes separate copies of static class member functions,
213 one for library and one for the rest of the program.
214
208215
209216 $subhead autotools$$
210217 The autotools build with the Visual Studio compiler should work
243250 will include all of the files and flags used to run the compiler
244251 and linker. This can be useful for seeing how to compile and link
245252 your own applications.
253
254 $head cmake_build_type$$
255 This value should be one of the valid CMake build types; e.g.,
256 $code Debug$$,
257 $code Release$$,
258 $code RelWithDebInfo$$,
259 $code MinSizeRel$$.
260 If this value is specified,
261 $cref/cppad_debug_which/cmake/cppad_debug_which/$$
262 must not be the empty string.
246263
247264 $head generator$$
248265 The CMake program is capable of generating different kinds of files.
369386
370387 $head include_adolc$$
371388 The $cref adolc$$ examples
372 will be compiled and tested if $icode include_adolc=true$$
389 will be compiled and tested if $code include_adolc=true$$
373390 is in the command line.
374391
375392 $head include_eigen$$
376393 The $cref eigen$$ examples
377394 will be compiled and tested if $code include_eigen=true$$
378395 is on the command line.
396 In addition, the $cref sparse2eigen$$ utility will be installed.
379397
380398 $head include_ipopt$$
381399 The $cref ipopt$$ examples
382400 will be compiled and tested if $code include_ipopt=true$$
383401 is on the command line.
402 In addition, $cref ipopt_solve$$ and $cref cppad_ipopt_nlp$$
403 will be installed.
384404
385405 $head include_cppadcg$$
386406 The $cref cppadcg$$ examples
387 will be compiled and tested if $code include_ipopt=true$$
407 will be compiled and tested if $code include_cppadcg=true$$
388408 is on the command line.
389409 $bold Warning$$ :
390410 Do not use this option when installing cppad because
391411 the cppadcg package depends on cppad and using this option
392412 makes cppad depend on cppadcg.
393 The script $cref get_cppadcg.sh$$ handles this confusion
394 for testing purposes only.
413 This option, and the script $cref get_cppadcg.sh$$ are only intended
414 for testing purposes.
395415
396416 $head package_prefix$$
397417 Each of these packages do not have $code pkg-config$$ files and
405425 $tend
406426
407427 $head cppad_cxx_flags$$
408 This specifies the addition compiler flags
409 that are used when compiling the CppAD examples and tests.
428 This specifies the compiler flags
429 that are used when compiling the CppAD examples, tests, and library.
430 This flags are in addition to the flags automatically generated by
431 cmake for debug and release build; i.e.,
432 $icode CMAKE_CXX_FLAGS_DEBUG$$ and $icode CMAKE_CXX_FLAGS_RELEASE$$.
410433 The default value for these flags is the empty string $code ""$$.
411434 These flags must be valid for the C++ compiler
412435 on your system.
413436 For example, if you are using $code g++$$ you could specify
414437 $codep
415 -D cppad_cxx_flags="-Wall -ansi -pedantic-errors -std=c++11 -Wshadow"
416 $$
417 $subhead C++11$$
418 In order for the compiler to take advantage of features that are new in C++11,
419 the $icode cppad_cxx_flags$$ must enable these features.
420 The compiler may still be used with a flag that disables the new features
421 (unless it is a Microsoft compiler; i.e., $code _MSC_VER$$ is defined).
438 -D cppad_cxx_flags="-Wall -ansi -pedantic-errors -std=c++17 -Wshadow"
439 $$
440 $subhead C++17$$
441 In order for the compiler to take advantage of features that are in C++17
442 ,but not in C++11, the $icode cppad_cxx_flags$$ must enable these features.
422443
423444 $subhead debug and release$$
424445 The CppAD examples and tests decide which files to compile for debugging
499520 std::numeric_limits<%cppad_tape_addr_type%>::max()
500521 %$$
501522 must be larger than any of the following:
502 $cref/size_op/seq_property/size_op/$$,
503 $cref/size_op_arg/seq_property/size_op_arg/$$,
504 $cref/size_par/seq_property/size_par/$$,
505 $cref/size_text/seq_property/size_text/$$,
506 $cref/size_VecAD/seq_property/size_VecAD/$$.
523 $cref/size_op/fun_property/size_op/$$,
524 $cref/size_op_arg/fun_property/size_op_arg/$$,
525 $cref/size_par/fun_property/size_par/$$,
526 $cref/size_text/fun_property/size_text/$$,
527 $cref/size_VecAD/fun_property/size_VecAD/$$.
507528
508529 $subhead cstdint$$
509530 If all of the following $code cstdint$$ types are defined,
518539 in debug or release mode (see exception below).
519540 This option controls which mode is chosen for the corresponding files.
520541 The value $icode cppad_debug_which$$ be one of the following:
521 $code debug_even$$, $code debug_odd$$, $code debug_all$$, $code debug_none$$.
522 If it is $code debug_even$$ ($code debug_odd$$),
523 files with an even (old) index in a list for each case will be compiled
524 in debug mode. The remaining files will be compiled in release mode.
525 If it is $code debug_all$$ ($code debug_none$$),
526 all the files will be compiled in debug (release) mode.
527 If $icode cppad_debug_which$$ does not appear on the command line,
528 the default value $code debug_all$$ is used.
542 $table
543 $icode cppad_debug_which$$ $cnext $icode CMAKE_BUILD_TYPE$$ $rnext
544 $code debug_all$$ $cnext $code Debug$$ $rnext
545 $code debug_none$$ $cnext $code Release$$ $rnext
546 $code debug_even$$ $cnext not specified $rnext
547 $code debug_odd$$ $cnext not specified $rnext
548 empty string $cnext not changed $rnext
549 $tend
550 If $code CMAKE_BUILD_TYPE$$ is specified on the command line,
551 then $icode cppad_debug_which$$ must be the empty string (its default value).
529552
530553 $children%
531554 bin/get_optional.sh%
0 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
0 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
11
22 CppAD is distributed under the terms of the
33 Eclipse Public License Version 2.0.
1818 hpp
1919 config
2020 CppAD
21 cflags
2122 $$
2223
2324 $section Including Ipopt Library Examples, Tests, and pkg-config$$
4950 The corresponding install prefix is
5051 $code build/prefix$$.
5152
53 $head Include Directories$$
54 It may be necessary to remove $code /coin-or$$ from the end of the
55 include directories reported by
56 $codei%
57 pkg-config ipopt --cflags
58 %$$
59
5260 $end
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1515 CppAD
1616 Rosen
1717 Runge
18 ctor
1819 $$
1920
2021 $section Using CppAD in a Multi-Threading Environment$$
6566 $cref/CheckNumericType/CheckNumericType/Parallel Mode/$$,
6667 $cref/discrete functions/Discrete/Parallel Mode/$$,
6768 $cref/Rosen34/Rosen34/Parallel Mode/$$,
68 $cref/Runge45/Runge45/Parallel Mode/$$.
69 $cref/Runge45/Runge45/Parallel Mode/$$,
70 $cref/cpp_graph_ctor/cpp_graph_ctor/Parallel Mode/$$.
6971
7072 $head Same Thread$$
7173 Some operations must be preformed by the same thread:
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
6969 (see $cref/Vector/reverse_one/Vector/$$ below)
7070 and its size
7171 must be equal to $icode m$$, the dimension of the
72 $cref/range/seq_property/Range/$$ space for $icode f$$.
72 $cref/range/fun_property/Range/$$ space for $icode f$$.
7373
7474 $head dw$$
7575 The result $icode dw$$ has prototype
8080 and its value is the derivative $latex W^{(1)} (x)$$.
8181 The size of $icode dw$$
8282 is equal to $icode n$$, the dimension of the
83 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
83 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
8484
8585 $head Vector$$
8686 The type $icode Vector$$ must be a $cref SimpleVector$$ class with
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
8989 (see $cref/Vector/reverse_two/Vector/$$ below)
9090 and its size
9191 must be equal to $icode m$$, the dimension of the
92 $cref/range/seq_property/Range/$$ space for $icode f$$.
92 $cref/range/fun_property/Range/$$ space for $icode f$$.
9393
9494 $head dw$$
9595 The result $icode dw$$ has prototype
102102 The size of $icode dw$$
103103 is equal to $latex n \times 2$$,
104104 where $latex n$$ is the dimension of the
105 $cref/domain/seq_property/Domain/$$ space for $icode f$$.
105 $cref/domain/fun_property/Domain/$$ space for $icode f$$.
106106
107107 $subhead First Order Partials$$
108108 For $latex j = 0 , \ldots , n - 1$$,
+0
-302
omh/seq_property.omh less more
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------- */
11
12 $begin seq_property$$
13 $spell
14 inuse
15 Addr
16 CppAD
17 sizeof
18 op
19 arg
20 enum
21 Taylor
22 const
23 bool
24 var
25 VecAD
26 subgraph
27 dyn
28 ind
29 $$
30
31 $section ADFun Sequence Properties$$
32
33 $head Syntax$$
34 $icode%n% = %f%.Domain()
35 %$$
36 $icode%m% = %f%.Range()
37 %$$
38 $icode%p% = %f%.Parameter(%i%)
39 %$$
40 $icode%s% = %f%.size_var()
41 %$$
42 $icode%s% = %f%.size_par()
43 %$$
44 $icode%s% = %f%.size_op()
45 %$$
46 $icode%s% = %f%.size_op_arg()
47 %$$
48 $icode%s% = %f%.size_text()
49 %$$
50 $icode%s% = %f%.size_VecAD()
51 %$$
52 $icode%s% = %f%.size_random()
53 %$$
54 $icode%s% = %f%.size_dyn_ind()
55 %$$
56 $icode%s% = %f%.size_dyn_par()
57 %$$
58 $icode%s% = %f%.size_dyn_arg()
59 %$$
60 $icode%s% = %f%.size_op_seq()
61 %$$
62
63 $subhead See Also$$
64 $cref size_order$$, $cref capacity_order$$, $cref number_skip$$.
65
66 $head Purpose$$
67 The operations above return properties of the
68 AD of $icode Base$$
69 $cref/operation sequence/glossary/Operation/Sequence/$$
70 stored in the ADFun object $icode f$$.
71 (If there is no operation sequence stored in $icode f$$,
72 $code size_var$$ returns zero.)
73
74 $head f$$
75 The object $icode f$$ has prototype
76 $codei%
77 const ADFun<%Base%> %f%
78 %$$
79 (see $codei%ADFun<%Base%>%$$ $cref/constructor/FunConstruct/$$).
80
81 $head Domain$$
82 The result $icode n$$ has prototype
83 $codei%
84 size_t %n%
85 %$$
86 and is the dimension of the domain space corresponding to $icode f$$.
87 This is equal to the size of the vector $icode x$$ in the call
88 $codei%
89 Independent(%x%)
90 %$$
91 that starting recording the operation sequence
92 currently stored in $icode f$$
93 (see $cref FunConstruct$$ and $cref Dependent$$).
94
95 $head Range$$
96 The result $icode m$$ has prototype
97 $codei%
98 size_t %m%
99 %$$
100 and is the dimension of the range space corresponding to $icode f$$.
101 This is equal to the size of the vector $icode y$$ in syntax
102 $codei%
103 ADFun<%Base> %f%(%x%, %y%)
104 %$$
105 or
106 $codei%
107 %f%.Dependent(%y%)
108 %$$
109 depending on which stored the operation sequence currently in $icode f$$
110 (see $cref FunConstruct$$ and $cref Dependent$$).
111
112 $head Parameter$$
113 The argument $icode i$$ has prototype
114 $codei%
115 size_t %i%
116 %$$
117 and $latex 0 \leq i < m$$.
118 The result $icode p$$ has prototype
119 $codei%
120 bool %p%
121 %$$
122 It is true if the $th i$$ component of range space for $latex F$$
123 corresponds to a
124 $cref/parameter/glossary/Parameter/$$ in the operation sequence.
125 In this case,
126 the $th i$$ component of $latex F$$ is constant and
127 $latex \[
128 \D{F_i}{x_j} (x) = 0
129 \] $$
130 for $latex j = 0 , \ldots , n-1$$ and all $latex x \in \B{R}^n$$.
131
132 $head size_var$$
133 The result $icode s$$ has prototype
134 $codei%
135 size_t %s%
136 %$$
137 and is the number of variables in the operation sequence plus the following:
138 one for a phantom variable with tape address zero,
139 one for each component of the range that is a parameter.
140 The amount of work and memory necessary for computing function values
141 and derivatives using $icode f$$ is roughly proportional to $icode s$$.
142 (The function call $cref/f.size_order()/size_order/$$
143 returns the number of Taylor coefficient orders, per variable,direction,
144 currently stored in $icode f$$.)
145 $pre
146
147 $$
148 If there is no operation sequence stored in $icode f$$,
149 $code size_var$$ returns zero
150 (see $cref/default constructor/FunConstruct/Default Constructor/$$).
151
152 $head size_par$$
153 The result $icode s$$ has prototype
154 $codei%
155 size_t %s%
156 %$$
157 and is the number of parameters in the operation sequence
158 (include a phantom parameter at index zero that is not used).
159 Parameters differ from variables in that only values
160 (and not derivatives) need to be stored for each parameter.
161 These parameters are considered part of the operation
162 sequence, as opposed to the Taylor coefficients which are
163 considered extra data in the function object $icode f$$.
164 Note that one $icode Base$$ value is required for each parameter.
165
166 $head size_op$$
167 The result $icode s$$ has prototype
168 $codei%
169 size_t %s%
170 %$$
171 and is the number of operations in the operation sequence.
172 Some operators, like comparison operators,
173 do not correspond to a variable.
174 Other operators, like the sine operator,
175 correspond to two variables.
176 Thus, this value will be different from
177 $cref/size_var/seq_property/size_var/$$.
178 Note that one $code enum$$ value is required for each operator.
179
180 $head size_op_arg$$
181 The result $icode s$$ has prototype
182 $codei%
183 size_t %s%
184 %$$
185 and is the total number of operator arguments in the operation sequence.
186 For example, Binary operators (e.g. addition) have two arguments.
187 Note that one integer index is stored in the operation sequence
188 for each argument.
189 Also note that, as of 2013-10-20, there is an extra
190 phantom argument with index 0 that is not used.
191
192 $head size_text$$
193 The result $icode s$$ has prototype
194 $codei%
195 size_t %s%
196 %$$
197 and is the total characters used in the $cref PrintFor$$ commands
198 in this operation sequence.
199
200 $head size_VecAD$$
201 The result $icode s$$ has prototype
202 $codei%
203 size_t %s%
204 %$$
205 and is the number of $cref VecAD$$ vectors,
206 plus the number of elements in the vectors.
207 Only $code VecAD$$ vectors that depend on the
208 independent variables are stored in the operation sequence.
209
210 $head size_random$$
211 The result $icode s$$ has prototype
212 $codei%
213 size_t %s%
214 %$$
215 and is the amount of memory currently holding information
216 for randomly access the operator sequence.
217 Random access is only used by the following routines
218 $cref subgraph_sparsity$$,
219 $cref subgraph_reverse$$, and
220 $cref optimize$$.
221 The optimize routine replaces the operation sequence, so the extra
222 memory is automatically dropped.
223 The subgraph routines hold onto this information
224 so that it does not need to be recalculated between calls.
225 The routine
226 $cref/clear_subgraph/subgraph_reverse/clear_subgraph/$$
227 will free this extra memory.
228
229 $head size_dyn_ind$$
230 The result $icode s$$ has prototype
231 $codei%
232 size_t %s%
233 %$$
234 and is the number of independent
235 $cref/dynamic/glossary/Parameter/Dynamic/$$ parameters
236 in the operation sequence.
237 This is the size of the
238 $cref/dynamic/Independent/dynamic/$$ parameter in the
239 corresponding call to $code Independent$$.
240
241 $head size_dyn_par$$
242 The result $icode s$$ has prototype
243 $codei%
244 size_t %s%
245 %$$
246 and is the number of
247 $cref/dynamic/glossary/Parameter/Dynamic/$$ parameters.
248 The dynamic parameters depend on the value of
249 the independent dynamic parameters but not on the value of the variables.
250 This includes the independent dynamic parameters.
251
252 $head size_dyn_arg$$
253 The result $icode s$$ has prototype
254 $codei%
255 size_t %s%
256 %$$
257 and is the total number of dynamic parameter operator arguments
258 in the operation sequence.
259 For example, Binary operators (e.g. addition) have two arguments.
260 Note that one integer index is stored in the operation sequence
261 for each argument.
262
263
264 $head size_op_seq$$
265 The result $icode s$$ has prototype
266 $codei%
267 size_t %s%
268 %$$
269 and is the amount of memory required to store the operation sequence
270 (not counting a small amount of memory required for every operation sequence).
271 For the current version of CppAD, this is given by
272 $comment see size_t player::Memory(void)$$
273 $codei%
274 %s% = %f%.size_op() * sizeof(CPPAD_VEC_ENUM_TYPE)
275 + %f%.size_op_arg() * sizeof(%tape_addr_type%)
276 + %f%.size_par() * sizeof(%Base%)
277 + %f%.size_par() * sizeof(bool)
278 + %f%.size_dyn_par() * sizeof(CPPAD_VEC_ENUM_TYPE)
279 + %f%.size_dyn_par() * sizeof(%tape_addr_type%)
280 + %f%.size_dyn_arg() * sizeof(%tape_addr_type%)
281 + %f%.size_text() * sizeof(char)
282 + %f%.size_VecAD() * sizeof(%tape_addr_type%)
283 %$$
284 see $cref/tape_addr_type/cmake/cppad_tape_addr_type/$$.
285 Note that this is the minimal amount of memory that can hold
286 the information corresponding to an operation sequence.
287 The actual amount of memory allocated ($cref/inuse/ta_inuse/$$)
288 for the operations sequence may be larger.
289 Also note that $code CPPAD_VEC_ENUM_TYPE$$ is not part
290 of the CppAD API and may change.
291
292 $head Example$$
293 $children%
294 example/general/seq_property.cpp
295 %$$
296 The file
297 $cref seq_property.cpp$$
298 contains an example and test of these operations.
299
300
301 $end
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
156156 e^{(j)} = d^{(j)} + \sum_{k=0}^j a^{(j-k)} * z^{(k)}
157157 \] $$
158158 We need to complete the induction by finding formulas for $latex z^{(j+1)}$$.
159 It follows for the formula for the
160 $cref/multiplication/ForwardTheory/Binary Operators/Multiplication/$$
161 operator that
159 It follows from the definition of $latex E(t)$$ that
162160 $latex \[
163 \begin{array}{rcl}
164 \left( \sum_{k=0}^j b^{(k)} t^k \right)
161 \left( \sum_{k=0}^j b^{(k)} * t^k \right)
165162 *
166163 \left( \sum_{k=1}^{j+1} k z^{(k)} * t^{k-1} \right)
167 & = &
164 =
168165 \left( \sum_{k=0}^j e^{(k)} * t^k \right)
169166 *
170167 \left( \sum_{k=1}^{j+1} k x^{(k)} * t^{k-1} \right)
171168 +
172169 o( t^p )
170 \] $$
171 Setting the left and right side coefficients of $latex t^j$$ equal,
172 and using the formula for
173 $cref/multiplication/ForwardTheory/Binary Operators/Multiplication/$$,
174 we obtain
175 $latex \[
176 \begin{array}{rcl}
177 \sum_{k=0}^j b^{(k)} (j+1-k) z^{(j+1-k)}
178 & = &
179 \sum_{k=0}^j e^{(k)} (j+1-k) x^{(j+1-k)}
173180 \\
174181 z^{(j+1)} & = & \frac{1}{j+1} \frac{1}{ b^{(0)} }
175182 \left(
186193 \] $$
187194 This completes the induction that computes $latex e^{(j)}$$
188195 and $latex z^{(j+1)}$$.
189
190
191196
192197
193198 $children%
199204 omh/theory/asin_forward.omh%
200205 omh/theory/acos_forward.omh%
201206 omh/theory/tan_forward.omh%
202 omh/theory/erf_forward.omh
207 omh/theory/erf_forward.omh%
208 omh/theory/pow_forward.omh
203209 %$$
204210
205211 $subhead Cases that Apply Recursion Above$$
211217 $rref atan_forward$$
212218 $rref asin_forward$$
213219 $rref acos_forward$$
220 $rref pow_forward$$
214221 $tend
215222
216223 $subhead Special Cases$$
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------- */
11
12 $begin pow_forward$$
13 $spell
14 Taylor
15 $$
16
17 $section Power Function Forward Mode Theory$$
18 We consider the operation $latex F(x) = x^y$$ where $latex x$$
19 is a variable and $latex y$$ is a parameter.
20
21 $head Derivatives$$
22 The corresponding derivative satisfies the equation
23 $latex \[
24 x * F^{(1)} (x) - y F(x) = 0
25 \] $$
26 This is the
27 $cref/standard math function differential equation
28 /ForwardTheory
29 /Standard Math Functions
30 /Differential Equation
31 /$$,
32 where
33 $latex A(x) = y$$,
34 $latex B(x) = x$$,
35 and $latex D(x) = 0$$.
36 We use $latex a$$, $latex b$$, $latex d$$,
37 and $latex z$$ to denote the
38 Taylor coefficients for
39 $latex A [ X (t) ] $$,
40 $latex B [ X (t) ]$$,
41 $latex D [ X (t) ] $$,
42 and $latex F [ X(t) ] $$ respectively.
43 It follows that
44 $latex b^j = x^j$$, $latex d^j = 0$$,
45 $latex \[
46 a^{(j)} = \left\{ \begin{array}{ll}
47 y & \R{if} \; j = 0
48 \\
49 0 & \R{otherwise}
50 \end{array} \right.
51 \] $$
52
53 $head Taylor Coefficients Recursion$$
54
55 $subhead z^(0)$$
56 $latex \[
57 z^{(0)} = F ( x^{(0)} )
58 \]$$
59
60 $subhead e^(j)$$
61 $latex \[
62 \begin{array}{rcl}
63 e^{(j)} & = & d^{(j)} + \sum_{k=0}^j a^{(j-k)} * z^{(k)}
64 \\
65 e^{(j)} & = & y * z^{(j)}
66 \end{array}
67 \] $$
68
69 $subhead z^j$$
70 For $latex j = 0, \ldots , p-1$$
71 $latex \[
72 \begin{array}{rcl}
73 z^{(j+1)} & = & \frac{1}{j+1} \frac{1}{ b^{(0)} }
74 \left(
75 \sum_{k=1}^{j+1} k x^{(k)} e^{(j+1-k)}
76 - \sum_{k=1}^j k z^{(k)} b^{(j+1-k)}
77 \right)
78 \\
79 & = & \frac{1}{j+1} \frac{1}{ x^{(0)} }
80 \left(
81 y \sum_{k=1}^{j+1} k x^{(k)} z^{(j+1-k)}
82 - \sum_{k=1}^j k z^{(k)} x^{(j+1-k)}
83 \right)
84 \\
85 & = &
86 \frac{1}{j+1} \frac{1}{ x^{(0)} }
87 \left(
88 y (j+1) x^{(j+1)} z^{(0)}
89 +
90 \sum_{k=1}^j k ( y x^{(k)} z^{(j+1-k)} - z^{(k)} x^{(j+1-k)} )
91 \right)
92 \\
93 & = &
94 y z^{(0)} x^{(j+1)} / x^{(0)}
95 +
96 \frac{1}{j+1} \frac{1}{ x^{(0)} }
97 \sum_{k=1}^j k ( y x^{(k)} z^{(j+1-k)} - z^{(k)} x^{(j+1-k)} )
98 \end{array}
99 \] $$
100 For $latex j = 1, \ldots , p$$
101 $latex \[
102 \begin{array}{rcl}
103 z^{(j)}
104 & = &
105 \left. \left(
106 y z^{(0)} x^{(j)}
107 +
108 \frac{1}{j} \sum_{k=1}^{j-1} k ( y x^{(k)} z^{(j-k)} - z^{(k)} x^{(j-k)} )
109 \right) \right/ x^{(0)}
110 \end{array}
111 \] $$
112
113
114
115 $end
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 -------------------------------------------------------------------------- */
11
12 $begin pow_reverse$$
13 $spell
14 Taylor
15 $$
16
17 $section Power Function Reverse Mode Theory$$
18
19 We use the reverse theory
20 $cref%standard math function
21 %ReverseTheory
22 %Standard Math Functions
23 %$$
24 definition for the functions $latex H$$ and $latex G$$.
25 The zero order forward mode formula for the
26 $cref/power/pow_forward/$$ function is
27 $latex \[
28 z^{(0)} = F ( x^{(0)} )
29 \] $$
30 $latex \[
31 \begin{array}{rcl}
32 \D{H}{ x^{(0)} }
33 & = & \D{G}{ x^{(0)} } + \D{G}{ z^{(0)} } \D{ z^{(0)} }{ x^{(0)} }
34 \\
35 \D{ z^{(0)} }{ x^{(0)} } & = & y [ x^{(0)} ]^{y - 1} = y z^{(0)} / x{(0)}
36 \end{array}
37 \] $$
38 All the equations below apply to the case where $latex j > 0$$.
39 For this case, the equation for $latex z^{(j)}$$ is
40 $latex \[
41 z^{(j)}
42 =
43 \left. \left(
44 y z^{(0)} x^{(j)}
45 +
46 \frac{1}{j} \sum_{k=1}^{j-1} k ( y x^{(k)} z^{(j-k)} - z^{(k)} x^{(j-k)} )
47 \right) \right/ x^{(0)}
48 \] $$
49
50 $head x^j$$
51 $latex \[
52 \begin{array}{rcl}
53 \D{H}{ x^{(j)} }
54 & = & \D{G}{ x^{(j)} } + \D{G}{ z^{(j)} } \D{ z^{(j)} }{ x^{(j)} }
55 \\
56 \D{ z^{(j)} }{ x^{(j)} } & = & y z^{(0)} / x^{(0)}
57 \end{array}
58 \] $$
59
60 $head x^k$$
61 For $latex k = 1 , \ldots , j-1$$
62 $latex \[
63 \begin{array}{rcl}
64 \D{H}{ x^{(k)} }
65 & = & \D{G}{ x^{(k)} } + \D{G}{ z^{(j)} } \D{ z^{(j)} }{ x^{(k)} }
66 \\
67 \D{ z^{(j)} }{ x^{(k)} } & = &
68 \frac{1}{j} ( k y - (j-k) ) z^{(j-k)} / x^{(0)}
69 \end{array}
70 \] $$
71
72 $head z^k$$
73 For $latex k = 1 , \ldots , j-1$$
74 $latex \[
75 \begin{array}{rcl}
76 \D{H}{ z^{(k)} }
77 & = & \D{G}{ z^{(k)} } + \D{G}{ z^{(j)} } \D{ z^{(j)} }{ z^{(k)} }
78 \\
79 \D{ z^{(j)} }{ z^{(k)} } & = &
80 \frac{1}{j} ( (j-k) y - k ) x^{(j-k)} / x^{(0)}
81 \end{array}
82 \] $$
83
84 $head x^0$$
85 $latex \[
86 \begin{array}{rcl}
87 \D{H}{ x^{(0)} }
88 & = & \D{G}{ x^{(0)} } + \D{G}{ z^{(j)} } \D{ z^{(j)} }{ x^{(0)} }
89 \\
90 \D{ z^{(j)} }{ x^{(0)} } & = & - z^{(j)} / x^{(0)}
91 \end{array}
92 \] $$
93
94 $head z^0$$
95 $latex \[
96 \begin{array}{rcl}
97 \D{H}{ z^{(0)} }
98 & = & \D{G}{ z^{(0)} } + \D{G}{ z^{(j)} } \D{ z^{(j)} }{ z^{(0)} }
99 \\
100 \D{ z^{(j)} }{ z^{(0)} } & = & y x^{(j)} / x^{(0)}
101 \end{array}
102 \] $$
103
104
105 $end
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
177177 omh/theory/asin_reverse.omh%
178178 omh/theory/acos_reverse.omh%
179179 omh/theory/tan_reverse.omh%
180 omh/theory/erf_reverse.omh
180 omh/theory/erf_reverse.omh%
181 omh/theory/pow_reverse.omh
181182 %$$
182183
183184 $end
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
125125 #
126126 # cppad_libdir
127127 LIST(GET cmake_install_libdirs 0 cppad_libdir)
128 #
129 # add_to_set
130 MACRO(add_to_set variable_name element)
131 IF( "${${variable_name}}" STREQUAL "" )
132 SET(${variable_name} ${element} )
133 ELSE( "${${variable_name}}" STREQUAL "" )
134 LIST(FIND ${variable_name} ${element} index)
135 IF( index EQUAL -1 )
136 SET(${variable_name} "${${variable_name}} ${element}")
137 ENDIF( index EQUAL -1 )
138 ENDIF( "${${variable_name}}" STREQUAL "" )
139 ENDMACRO(add_to_set variable_name element)
128140 # -----------------------------------------------------------------------------
129141 # initialize
130 SET(cppad_lib_list "-L${cppad_prefix}/${cppad_libdir} -l${cppad_lib}")
131 SET(cppad_requires "")
132 SET(cppad_libs_private "")
142 SET(cppad_libdir_list "-L${cppad_prefix}/${cppad_libdir}")
143 SET(cppad_lib_list "-l${cppad_lib}")
144 SET(cppad_requires "")
145 SET(cppad_libs_private "")
133146 SET(cppad_requires_private "")
134147 #
135148 # Colpack does not have a pkgconfig file.
144157 IF( NOT colpack_libdir )
145158 MESSAGE(FATAL_ERROR "Cannit find libColPack.* below ${colpack_prefix}")
146159 ENDIF( NOT colpack_libdir )
147 SET(cppad_lib_list
148 "${cppad_lib_list} -L${colpack_libdir} -lColPack"
149 )
160 add_to_set(cppad_libdir_list "-L${colpack_libdir}")
161 add_to_set(cppad_lib_list "-lColPack")
150162 ENDIF( cppad_has_colpack )
151163 #
152164 # Ipopt has a pkgconfig file.
153165 IF( cppad_has_ipopt )
154 SET(cppad_requires "${cppad_requires} ipopt")
155 SET(cppad_lib_list "${cppad_lib_list} -lcppad_ipopt")
166 SET(cppad_requires "${cppad_requires} ipopt")
167 add_to_set(cppad_lib_list "-lcppad_ipopt" )
156168 ENDIF( cppad_has_ipopt )
157169 # -----------------------------------------------------------------------------
158170 # cppad.pc
1313 # includedir=@cppad_SOURCE_DIR@/include
1414 #
1515 prefix=@cppad_prefix@
16 exec_prefix=$(prefix)
16 exec_prefix=${prefix}
1717 includedir=@cppad_SOURCE_DIR@/include
1818 libdir=${exec_prefix}/@cppad_libdir@
1919 #
2323 URL: @cppad_url@
2424 #
2525 Cflags: -I${includedir}
26 Libs: @cppad_lib_list@
26 Libs: @cppad_libdir_list@ @cppad_lib_list@
2727 Requires: @cppad_requires@
2828 Libs.private @cppad_libs_private@
2929 Requires.private: @cppad_requires_private@
1414 # for the meaning of these variables.
1515 #
1616 prefix=@cppad_prefix@
17 exec_prefix=$(prefix)
17 exec_prefix=${prefix}
1818 includedir=${prefix}/@cppad_includedir@
1919 libdir=${exec_prefix}/@cppad_libdir@
2020 #
2727 URL: @cppad_url@
2828 #
2929 Cflags: -I${includedir}
30 Libs: @cppad_lib_list@
30 Libs: @cppad_libdir_list@ @cppad_lib_list@
3131 Requires: @cppad_requires@
3232 Libs.private @cppad_libs_private@
3333 Requires.private: @cppad_requires_private@
22
33 # Links
44
5 - [docmentation](https://coin-or.github.io/CppAD/doc)
5 - [Documentation](https://coin-or.github.io/CppAD/doc)
66
77 - [News](https://coin-or.github.io/CppAD/doc/whats_new.htm)
88
1010
1111 - [Directories](https://coin-or.github.io/CppAD/doc/directory.htm)
1212
13 - [Coin-OR Download](https://www.coin-or.org/download/source/CppAD/)
13 - [Downloads Before 2019](https://www.coin-or.org/download/source/CppAD/)
1414
1515
1616 # License
1717 <pre>
18 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
18 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
1919
2020 CppAD is distributed under the terms of the
2121 Eclipse Public License Version 2.0.
2828
2929
3030 # Autotools
31 The preferred method to test and install CppAD uses cmake.
32 The deprecated autotools procedure can be used for this purpose,
31 The preferred method to test and install CppAD uses [CMake](https://cmake.org).
32 The deprecated Autotools procedure can be used for this purpose,
3333 but it will eventually be removed.
3434 For any sub-directory *dir*,
3535 files of the form *dir*/`makefile.am` and *dir*/`makefile.in`
36 are used to support the autotools test and install procedure.
36 are used to support the Autotools test and install procedure.
3737 In addition,
3838 the following files, in this directory, are also for this purpose:
3939 `compile`,
4545 `missing`.
4646
4747
48 # Copyright:
48 # Copyright
4949 See the file `authors` in this directory.
275275 builddir = @builddir@
276276 compiler_has_conversion_warn = @compiler_has_conversion_warn@
277277 cppad_boostvector = @cppad_boostvector@
278 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
279278 cppad_cppadvector = @cppad_cppadvector@
280279 cppad_cxx_flags = @cppad_cxx_flags@
281280 cppad_description = @cppad_description@
330329 prefix = @prefix@
331330 program_transform_name = @program_transform_name@
332331 psdir = @psdir@
332 runstatedir = @runstatedir@
333333 sbindir = @sbindir@
334334 sharedstatedir = @sharedstatedir@
335335 srcdir = @srcdir@
262262 builddir = @builddir@
263263 compiler_has_conversion_warn = @compiler_has_conversion_warn@
264264 cppad_boostvector = @cppad_boostvector@
265 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
266265 cppad_cppadvector = @cppad_cppadvector@
267266 cppad_cxx_flags = @cppad_cxx_flags@
268267 cppad_description = @cppad_description@
317316 prefix = @prefix@
318317 program_transform_name = @program_transform_name@
319318 psdir = @psdir@
319 runstatedir = @runstatedir@
320320 sbindir = @sbindir@
321321 sharedstatedir = @sharedstatedir@
322322 srcdir = @srcdir@
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
149149 }
150150 // --------------------------------------------------------------------
151151 //
152 // function object mapping matrix to gradiend of determinant
152 // function object mapping matrix to gradient of determinant
153153 static code_gen_fun static_fun;
154154 //
155 // size correspmnding to static_fun
155 // size corresponding static_fun
156156 static size_t static_size = 0;
157157 //
158158 // number of independent variables
262262 builddir = @builddir@
263263 compiler_has_conversion_warn = @compiler_has_conversion_warn@
264264 cppad_boostvector = @cppad_boostvector@
265 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
266265 cppad_cppadvector = @cppad_cppadvector@
267266 cppad_cxx_flags = @cppad_cxx_flags@
268267 cppad_description = @cppad_description@
317316 prefix = @prefix@
318317 program_transform_name = @program_transform_name@
319318 psdir = @psdir@
319 runstatedir = @runstatedir@
320320 sbindir = @sbindir@
321321 sharedstatedir = @sharedstatedir@
322322 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1414 # add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL]
1515 # source1 source2 ... sourceN
1616 # )
17 # We do not add ../src/speed_src library to avoid undefined externals.
18 # Instead we build our own copy of ../src/microsoft_timer.cpp.
1917 SET(source_list example.cpp
2018 det_by_lu.cpp
2119 det_by_minor.cpp
2725 sparse_jac_fun.cpp
2826 speed_test.cpp
2927 time_test.cpp
30 "../src/microsoft_timer.cpp"
3128 )
3229 set_compile_flags( speed_example "${cppad_debug_which}" "${source_list}" )
3330 #
284284 builddir = @builddir@
285285 compiler_has_conversion_warn = @compiler_has_conversion_warn@
286286 cppad_boostvector = @cppad_boostvector@
287 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
288287 cppad_cppadvector = @cppad_cppadvector@
289288 cppad_cxx_flags = @cppad_cxx_flags@
290289 cppad_description = @cppad_description@
339338 prefix = @prefix@
340339 program_transform_name = @program_transform_name@
341340 psdir = @psdir@
341 runstatedir = @runstatedir@
342342 sbindir = @sbindir@
343343 sharedstatedir = @sharedstatedir@
344344 srcdir = @srcdir@
263263 builddir = @builddir@
264264 compiler_has_conversion_warn = @compiler_has_conversion_warn@
265265 cppad_boostvector = @cppad_boostvector@
266 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
267266 cppad_cppadvector = @cppad_cppadvector@
268267 cppad_cxx_flags = @cppad_cxx_flags@
269268 cppad_description = @cppad_description@
318317 prefix = @prefix@
319318 program_transform_name = @program_transform_name@
320319 psdir = @psdir@
320 runstatedir = @runstatedir@
321321 sbindir = @sbindir@
322322 sharedstatedir = @sharedstatedir@
323323 srcdir = @srcdir@
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
604604 CppAD::vector<size_t> size_sparse_hessian(n_size);
605605 CppAD::vector<size_t> size_sparse_jacobian(n_size);
606606 for(size_t i = 0; i < n_size; i++)
607 { size_det_minor[i] = i + 1;
607 { size_det_minor[i] = i + 2;
608608 size_det_lu[i] = 10 * i + 1;
609609 size_mat_mul[i] = 10 * i + 1;
610610 size_ode[i] = 10 * i + 1;
263263 builddir = @builddir@
264264 compiler_has_conversion_warn = @compiler_has_conversion_warn@
265265 cppad_boostvector = @cppad_boostvector@
266 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
267266 cppad_cppadvector = @cppad_cppadvector@
268267 cppad_cxx_flags = @cppad_cxx_flags@
269268 cppad_description = @cppad_description@
318317 prefix = @prefix@
319318 program_transform_name = @program_transform_name@
320319 psdir = @psdir@
320 runstatedir = @runstatedir@
321321 sbindir = @sbindir@
322322 sharedstatedir = @sharedstatedir@
323323 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2525 link_poly.cpp
2626 link_sparse_hessian.cpp
2727 link_sparse_jacobian.cpp
28 microsoft_timer.cpp
2928 )
3029 # END_SORT_THIS_LINE_MINUS_2
3130
00 -----------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
4444 speed/src/link_ode.cpp%
4545 speed/src/link_poly.cpp%
4646 speed/src/link_sparse_hessian.hpp%
47 speed/src/link_sparse_jacobian.hpp%
48 speed/src/microsoft_timer.cpp
47 speed/src/link_sparse_jacobian.hpp
4948 %$$
5049
5150 $head Namespace$$
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2929 link_ode.cpp \
3030 link_poly.cpp \
3131 link_sparse_hessian.cpp \
32 link_sparse_jacobian.cpp \
33 microsoft_timer.cpp
32 link_sparse_jacobian.cpp
106106 libspeed_a_LIBADD =
107107 am_libspeed_a_OBJECTS = link_det_lu.$(OBJEXT) link_det_minor.$(OBJEXT) \
108108 link_mat_mul.$(OBJEXT) link_ode.$(OBJEXT) link_poly.$(OBJEXT) \
109 link_sparse_hessian.$(OBJEXT) link_sparse_jacobian.$(OBJEXT) \
110 microsoft_timer.$(OBJEXT)
109 link_sparse_hessian.$(OBJEXT) link_sparse_jacobian.$(OBJEXT)
111110 libspeed_a_OBJECTS = $(am_libspeed_a_OBJECTS)
112111 AM_V_P = $(am__v_P_@AM_V@)
113112 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
128127 ./$(DEPDIR)/link_det_minor.Po ./$(DEPDIR)/link_mat_mul.Po \
129128 ./$(DEPDIR)/link_ode.Po ./$(DEPDIR)/link_poly.Po \
130129 ./$(DEPDIR)/link_sparse_hessian.Po \
131 ./$(DEPDIR)/link_sparse_jacobian.Po \
132 ./$(DEPDIR)/microsoft_timer.Po
130 ./$(DEPDIR)/link_sparse_jacobian.Po
133131 am__mv = mv -f
134132 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
135133 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
200198 CYGPATH_W = @CYGPATH_W@
201199
202200 # -----------------------------------------------------------------------------
203 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
201 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
204202 #
205203 # CppAD is distributed under the terms of the
206204 # Eclipse Public License Version 2.0.
283281 builddir = @builddir@
284282 compiler_has_conversion_warn = @compiler_has_conversion_warn@
285283 cppad_boostvector = @cppad_boostvector@
286 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
287284 cppad_cppadvector = @cppad_cppadvector@
288285 cppad_cxx_flags = @cppad_cxx_flags@
289286 cppad_description = @cppad_description@
338335 prefix = @prefix@
339336 program_transform_name = @program_transform_name@
340337 psdir = @psdir@
338 runstatedir = @runstatedir@
341339 sbindir = @sbindir@
342340 sharedstatedir = @sharedstatedir@
343341 srcdir = @srcdir@
364362 link_ode.cpp \
365363 link_poly.cpp \
366364 link_sparse_hessian.cpp \
367 link_sparse_jacobian.cpp \
368 microsoft_timer.cpp
365 link_sparse_jacobian.cpp
369366
370367 all: all-am
371368
422419 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/link_poly.Po@am__quote@ # am--include-marker
423420 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/link_sparse_hessian.Po@am__quote@ # am--include-marker
424421 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/link_sparse_jacobian.Po@am__quote@ # am--include-marker
425 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/microsoft_timer.Po@am__quote@ # am--include-marker
426422
427423 $(am__depfiles_remade):
428424 @$(MKDIR_P) $(@D)
577573 -rm -f ./$(DEPDIR)/link_poly.Po
578574 -rm -f ./$(DEPDIR)/link_sparse_hessian.Po
579575 -rm -f ./$(DEPDIR)/link_sparse_jacobian.Po
580 -rm -f ./$(DEPDIR)/microsoft_timer.Po
581576 -rm -f makefile
582577 distclean-am: clean-am distclean-compile distclean-generic \
583578 distclean-tags
630625 -rm -f ./$(DEPDIR)/link_poly.Po
631626 -rm -f ./$(DEPDIR)/link_sparse_hessian.Po
632627 -rm -f ./$(DEPDIR)/link_sparse_jacobian.Po
633 -rm -f ./$(DEPDIR)/microsoft_timer.Po
634628 -rm -f makefile
635629 maintainer-clean-am: distclean-am maintainer-clean-generic
636630
+0
-89
speed/src/microsoft_timer.cpp less more
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 /*
12 $begin microsoft_timer$$
13 $spell
14 Microsoft
15 cpp
16 src
17 $$
18
19 $section Microsoft Version of Elapsed Number of Seconds$$
20
21
22 $head Syntax$$
23 $icode%s% = microsoft_timer()%$$
24
25 $head Purpose$$
26 This routine is accurate to within .02 seconds
27 (see $cref elapsed_seconds$$ which uses this routine when
28 the preprocessor symbol $code _MSC_VER$$ is defined).
29 It does not necessary work for time intervals that are greater than a day.
30 It uses $code ::GetSystemTime$$ for timing.
31
32 $head s$$
33 is a $code double$$ equal to the
34 number of seconds since the first call to $code microsoft_timer$$.
35
36 $head Linking$$
37 The source code for this routine is located in
38 $code speed/src/microsoft_timer.cpp$$.
39 The preprocessor symbol $code _MSC_VER$$ must
40 be defined, or this routine is not compiled.
41
42 $end
43 -----------------------------------------------------------------------
44 */
45 # ifdef _MSC_VER
46 # include <windows.h>
47 # include <cassert>
48
49 // Note that the doxygen for this routine does not get generated because
50 // _MSC_VER is not defined during generation. In general, it is a problem
51 // that not all preprocessor options get documented.
52 /*!
53 \{
54 \file microsoft_timer.cpp
55 \brief Microsoft version of elapsed_seconds.
56 */
57
58 /*!
59 Microsoft version of elapsed number of seconds since frist call.
60
61 \copydetails elapsed_seconds
62 */
63 double microsoft_timer(void)
64 { static bool first_ = true;
65 static SYSTEMTIME st_;
66 SYSTEMTIME st;
67
68 if( first_ )
69 { ::GetSystemTime(&st_);
70 first_ = false;
71 return 0.;
72 }
73 ::GetSystemTime(&st);
74
75 double hour = double(st.wHour) - double(st_.wHour);
76 double minute = double(st.wMinute) - double(st_.wMinute);
77 double second = double(st.wSecond) - double(st_.wSecond);
78 double milli = double(st.wMilliseconds) - double(st_.wMilliseconds);
79
80 double diff = 1e-3*milli + second + 60.*minute + 3600.*hour;
81 if( diff < 0. )
82 diff += 3600.*24.;
83 assert( 0 <= diff && diff < 3600.*24. );
84
85 return diff;
86 }
87
88 # endif
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1111 # Build the speed/xpackage directory tests
1212 # Inherit build type from ../CMakeList.txt
1313
14 # assert xpackage_prefix is defined
15 assert ( xpackage_prefix )
14 # Set the install prefix for this package
15 SET(xpackage_prefix "/usr")
1616
1717 # Adds flags to the compiler command line for sources in the current directory
1818 # and below. This command can be used to add any flags, but it was originally
2020 ADD_DEFINITIONS("-DCPPAD_XPACKAGE_SPEED")
2121
2222 # Local include directories to search (not in package_prefix/includdir)
23 INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../src )
23 INCLUDE_DIRECTORIES(
24 ${CMAKE_CURRENT_SOURCE_DIR}/../src
25 ${xpackage_prefix}/include
26 )
2427
2528 # add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL]
2629 # source1 source2 ... sourceN
0 # makefile.in generated by automake 1.16.1 from makefile.am.
0 # makefile.in generated by automake 1.16.2 from makefile.am.
11 # @configure_input@
22
3 # Copyright (C) 1994-2018 Free Software Foundation, Inc.
3 # Copyright (C) 1994-2020 Free Software Foundation, Inc.
44
55 # This Makefile.in is free software; the Free Software Foundation
66 # gives unlimited permission to copy and/or distribute it,
202202 EIGEN_DIR = @EIGEN_DIR@
203203 EIGEN_INCLUDE = @EIGEN_INCLUDE@
204204 EXEEXT = @EXEEXT@
205 XPACKAGE_DIR = @XPACKAGE_DIR@
205 FADBAD_DIR = @FADBAD_DIR@
206206 FC = @FC@
207207 FCFLAGS = @FCFLAGS@
208208 FCLIBS = @FCLIBS@
263263 builddir = @builddir@
264264 compiler_has_conversion_warn = @compiler_has_conversion_warn@
265265 cppad_boostvector = @cppad_boostvector@
266 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
267266 cppad_cppadvector = @cppad_cppadvector@
268267 cppad_cxx_flags = @cppad_cxx_flags@
269268 cppad_description = @cppad_description@
272271 cppad_has_boost = @cppad_has_boost@
273272 cppad_has_colpack = @cppad_has_colpack@
274273 cppad_has_eigen = @cppad_has_eigen@
275 cppad_has_xpackage = @cppad_has_xpackage@
274 cppad_has_fadbad = @cppad_has_fadbad@
276275 cppad_has_gettimeofday = @cppad_has_gettimeofday@
277276 cppad_has_ipopt = @cppad_has_ipopt@
278277 cppad_has_mkstemp = @cppad_has_mkstemp@
318317 prefix = @prefix@
319318 program_transform_name = @program_transform_name@
320319 psdir = @psdir@
320 runstatedir = @runstatedir@
321321 sbindir = @sbindir@
322322 sharedstatedir = @sharedstatedir@
323323 srcdir = @srcdir@
328328 top_srcdir = @top_srcdir@
329329
330330 # -----------------------------------------------------------------------------
331 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
331 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
332332 #
333333 # CppAD is distributed under the terms of the
334334 # Eclipse Public License Version 2.0.
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1818 cp
1919 ls
2020 sed
21 txt
22 cmake
23 det
24 lu
25 mul
26 jacobian
27 ifdef
28 endif
2129 $$
2230
2331
4856 cp -r speed/xpackage speed/%your_package%
4957 for file in `ls speed/%your_package%`
5058 do
51 sed -i speed/%your_package%/@file -e 's|xpackage|%your_package%|'
59 sed -i speed/%your_package%/@file \
60 -e 's|xpackage|%your_package%|' \
61 -e 's|Xpackage|%Your_package%|' \
62 -e 's|CPPAD_XPACKAGE_SPEED|%YOUR_PACKGE%|'
5263 done
64 git checkout speed/CMakeLists.txt
65 sed -i speed/CMakeLists.txt \
66 -e 's|^.*(xpackage)|ADD_SUBDIRECTORY(%your_package%)\n&|'
67 git checkout speed/main.cpp
68 line1='# ifdef CPPAD_%YOUR_PACKAGE%_SPEED'
69 line2='# define AD_PACKAGE "%your_package%"'
70 line3='# endif'
71 sed -i speed/main.cpp \
72 -e "/CPPAD_XPACKAGE_SPEED/s|^|@line1\n@line2\n@line3\n|"
5373 %$$
54 where $icode your_package$$ has been replaced by the name of the new package.
74 where $icode your_package$$ has been replaced by the name of the new package
75 $icode Your_package$$ is a capitalized version of the name, and
76 $icode YOUR_PACKAGE$$ is an all caps version of the name.
5577
5678
5779 $head Running Tests$$
58 To build the xpackage version of the tests,
59 execute the following commands starting in the
60 $cref/build directory/cmake/Build Directory/$$:
80 Starting in the distribution directory,
81 the following commands will build the new package version of the tests:
6182 $codei%
62 cd speed/xpackage
63 make check_speed_xpackage VERBOSE=1
83 bin/run_cmake.sh --no_optional
84 cd build/speed/%your_package%
85 make check_speed_%your_package% VERBOSE=1
6486 %$$
65 You can then run the corresponding speed tests
66 with the following command
67 $codei%
68 ./speed_xpackage speed %seed%
69 %$$
70 where $icode seed$$ is a positive integer.
71 See $cref speed_main$$ for more options.
87 This should result in the following output:
88 $codei|
89 |...|
90 |your_package|_det_lu_available = false
91 |your_package|_det_minor_available = false
92 |your_package|_mat_mul_available = false
93 |your_package|_ode_available = false
94 |your_package|_poly_available = false
95 |your_package|_sparse_hessian_available = false
96 |your_package|_sparse_jacobian_available = false
97 All 0 correctness tests passed.
98 No memory leak detected
99 speed main: OK
100 [100%] Built target check_speed_|your_package|
101 |$$
102 You can not edit one or more of the $icode%*%.cpp%$$ files in the
103 $icode your_package$$ directory so that the corresponding speed test
104 is available and then run the corresponding test using the
105 $cref speed_main$$ instructions.
106 See $cref speed_cppad$$ for examples of how to do this for each
107 of the speed tests.
72108
73109 $contents%
74110 speed/xpackage/det_minor.cpp%
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2020 ADD_SUBDIRECTORY(compare_c)
2121
2222 # debug_rel tests
23 IF( NOT CMAKE_VS_MSBUILD_COMMAND )
24 # during build Visual studio rejects this mix of debug and release flags
23 IF( NOT "${CMAKE_GENERATOR}" STREQUAL "NMake Makefiles" )
24 # Visual studio rejects mixing debug and release flags
2525 ADD_SUBDIRECTORY(debug_rel)
26 ENDIF( NOT CMAKE_VS_MSBUILD_COMMAND )
26 ENDIF( NOT "${CMAKE_GENERATOR}" STREQUAL "NMake Makefiles" )
2727 #
2828 # cppad_for_tmb tests
2929 IF( OPENMP_FOUND )
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
3939 # use cppad_debug_which to determine build type
4040 IF( "${cppad_debug_which}" STREQUAL debug_all )
4141 SET(CMAKE_BUILD_TYPE DEBUG)
42 SET(all_cxx_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGSS_DEBUG}")
4243 ELSEIF( "${cppad_debug_which}" STREQUAL debug_odd )
4344 SET(CMAKE_BUILD_TYPE DEBUG)
45 SET(all_cxx_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGSS_DEBUG}")
4446 ELSE( "${cppad_debug_which}" STREQUAL debug_odd )
4547 SET(CMAKE_BUILD_TYPE RELEASE)
48 SET(all_cxx_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGSS_RELEASE}")
4649 ENDIF( "${cppad_debug_which}" STREQUAL debug_all )
4750 #
4851 # Loop though the C and C++ compilers
5861 ADD_EXECUTABLE( det_by_minor_${com} EXCLUDE_FROM_ALL ${source})
5962 #
6063 IF( ${com} STREQUAL cpp )
61 # These are C++ compiler flags (may not be valid for C)
64 # cppad_cxx_flags are C++ compiler flags and may not be valid for C
6265 SET_TARGET_PROPERTIES(
63 det_by_minor_${com} PROPERTIES COMPILE_FLAGS "${cppad_cxx_flags}"
66 det_by_minor_${com} PROPERTIES COMPILE_FLAGS "${all_cxx_flags}"
6467 )
6568 ENDIF( ${com} STREQUAL cpp )
6669 #
272272 builddir = @builddir@
273273 compiler_has_conversion_warn = @compiler_has_conversion_warn@
274274 cppad_boostvector = @cppad_boostvector@
275 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
276275 cppad_cppadvector = @cppad_cppadvector@
277276 cppad_cxx_flags = @cppad_cxx_flags@
278277 cppad_description = @cppad_description@
327326 prefix = @prefix@
328327 program_transform_name = @program_transform_name@
329328 psdir = @psdir@
329 runstatedir = @runstatedir@
330330 sbindir = @sbindir@
331331 sharedstatedir = @sharedstatedir@
332332 srcdir = @srcdir@
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
1111 # Build the test_more/general tests
1212
1313 # set compiler flags for debug_rel.cpp and debug.cpp
14 IF( "${debug_which}" STREQUAL "debug_all" )
15 SET(debug_extra "${CMAKE_CXX_FLAGS_DEBUG}")
16 SET(release_extra "${CMAKE_CXX_FLAGS_DEBUG}")
17 ELSEIF( "${debug_which}" STREQUAL "debug_none" )
18 SET(debug_extra "${CMAKE_CXX_FLAGS_RELEASE}")
19 SET(release_extra "${CMAKE_CXX_FLAGS_RELEASE}")
20 ELSE( "${debug_which}" )
21 SET(debug_extra "${CMAKE_CXX_FLAGS_DEBUG}")
22 SET(release_extra "${CMAKE_CXX_FLAGS_RELEASE}")
23 ENDIF( "${debug_which}" STREQUAL "debug_all" )
14 IF( "${cppad_debug_which}" STREQUAL "debug_all" )
15 SET(debug_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS_DEBUG}")
16 SET(release_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS_DEBUG}")
17 ELSEIF( "${cppad_debug_which}" STREQUAL "debug_none" )
18 SET(debug_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS_RELEASE}")
19 SET(release_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS_RELEASE}")
20 ELSE( "${cppad_debug_which}" )
21 SET(debug_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS_DEBUG}")
22 SET(release_flags "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS_RELEASE}")
23 ENDIF( "${cppad_debug_which}" STREQUAL "debug_all" )
2424 #
2525 SET_SOURCE_FILES_PROPERTIES(
2626 debug_rel.cpp debug.cpp PROPERTIES COMPILE_FLAGS
27 "${cppad_cxx_flags} ${debug_extra} -DCPPAD_DEBUG_AND_RELEASE"
27 "${debug_flags} -DCPPAD_DEBUG_AND_RELEASE"
2828 )
2929 #
3030 SET_SOURCE_FILES_PROPERTIES(
3131 release.cpp PROPERTIES COMPILE_FLAGS
32 "${cppad_cxx_flags} ${release_extra} -DCPPAD_DEBUG_AND_RELEASE"
32 "${release_flags} -DCPPAD_DEBUG_AND_RELEASE"
3333 )
3434
3535 # now that we have the properties, add the executable
282282 builddir = @builddir@
283283 compiler_has_conversion_warn = @compiler_has_conversion_warn@
284284 cppad_boostvector = @cppad_boostvector@
285 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
286285 cppad_cppadvector = @cppad_cppadvector@
287286 cppad_cxx_flags = @cppad_cxx_flags@
288287 cppad_description = @cppad_description@
337336 prefix = @prefix@
338337 program_transform_name = @program_transform_name@
339338 psdir = @psdir@
339 runstatedir = @runstatedir@
340340 sbindir = @sbindir@
341341 sharedstatedir = @sharedstatedir@
342342 srcdir = @srcdir@
271271 builddir = @builddir@
272272 compiler_has_conversion_warn = @compiler_has_conversion_warn@
273273 cppad_boostvector = @cppad_boostvector@
274 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
275274 cppad_cppadvector = @cppad_cppadvector@
276275 cppad_cxx_flags = @cppad_cxx_flags@
277276 cppad_description = @cppad_description@
326325 prefix = @prefix@
327326 program_transform_name = @program_transform_name@
328327 psdir = @psdir@
328 runstatedir = @runstatedir@
329329 sbindir = @sbindir@
330330 sharedstatedir = @sharedstatedir@
331331 srcdir = @srcdir@
287287 builddir = @builddir@
288288 compiler_has_conversion_warn = @compiler_has_conversion_warn@
289289 cppad_boostvector = @cppad_boostvector@
290 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
291290 cppad_cppadvector = @cppad_cppadvector@
292291 cppad_cxx_flags = @cppad_cxx_flags@
293292 cppad_description = @cppad_description@
342341 prefix = @prefix@
343342 program_transform_name = @program_transform_name@
344343 psdir = @psdir@
344 runstatedir = @runstatedir@
345345 sbindir = @sbindir@
346346 sharedstatedir = @sharedstatedir@
347347 srcdir = @srcdir@
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2626 Consider the case where an inner function is used repeatedly in the
2727 definition of an outer function.
2828 In this case, it may reduce the number of variables
29 $cref/size_var/seq_property/size_var/$$,
29 $cref/size_var/fun_property/size_var/$$,
3030 and hence the required memory.
3131
3232 $head Simple Case$$
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2727 Consider the case where an inner function is used repeatedly in the
2828 definition of an outer function.
2929 In this case, it may reduce the number of variables
30 $cref/size_var/seq_property/size_var/$$,
30 $cref/size_var/fun_property/size_var/$$,
3131 and hence the required memory.
3232
3333 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
3737 ${eigen_sources}
3838 ${ipopt_sources}
3939 general.cpp
40 abs_normal.cpp
4041 acos.cpp
4142 acosh.cpp
4243 add.cpp
8384 forward_order.cpp
8485 from_base.cpp
8586 fun_check.cpp
87 cpp_graph.cpp
8688 hes_sparsity.cpp
8789 jacobian.cpp
8890 json_graph.cpp
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 # include <cppad/cppad.hpp>
12
13 namespace { // BEGIN_EMPTY_NAMESPACE
14 // join
15 CPPAD_TESTVECTOR(double) join(
16 const CPPAD_TESTVECTOR(double)& x ,
17 const CPPAD_TESTVECTOR(double)& u )
18 { size_t n = x.size();
19 size_t s = u.size();
20 CPPAD_TESTVECTOR(double) xu(n + s);
21 for(size_t j = 0; j < n; j++)
22 xu[j] = x[j];
23 for(size_t j = 0; j < s; j++)
24 xu[n + j] = u[j];
25 return xu;
26 }
27 // test_pow
28 bool test_pow(void)
29 { bool ok = true;
30 //
31 using CppAD::AD;
32 using CppAD::ADFun;
33 //
34 typedef CPPAD_TESTVECTOR(double) d_vector;
35 typedef CPPAD_TESTVECTOR( AD<double> ) ad_vector;
36 //
37 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
38 //
39 size_t n = 2; // size of x
40 size_t m = 1; // size of y
41 size_t s = 1; // number of absolute value terms
42 //
43 // record the function f(x)
44 ad_vector ad_x(n), ad_y(m);
45 for(size_t j = 0; j < n; j++)
46 ad_x[j] = double(j + 1);
47 Independent( ad_x );
48 //
49 // for this example, we the function is
50 // f(x) = pow( |x_0|, x_1) + pow( |x_0| , 2) + pow(2, |x_0|)
51 AD<double> abs_x0 = abs( ad_x[0] );
52 AD<double> pow_vv = pow( abs_x0 , ad_x[1] );
53 AD<double> pow_vp = pow( abs_x0 , 2.0 );
54 AD<double> pow_pv = pow( 2.0 , abs_x0 );
55 ad_y[0] = pow_vv + pow_vp + pow_pv;
56 ADFun<double> f(ad_x, ad_y);
57
58 // create its abs_normal representation in g, a
59 ADFun<double> g, a;
60 f.abs_normal_fun(g, a);
61
62 // check dimension of domain and range space for g
63 ok &= g.Domain() == n + s;
64 ok &= g.Range() == m + s;
65
66 // check dimension of domain and range space for a
67 ok &= a.Domain() == n;
68 ok &= a.Range() == s;
69
70 // --------------------------------------------------------------------
71 // Choose a point x_hat
72 d_vector x_hat(n);
73 x_hat[0] = -2.0;
74 x_hat[1] = 2.0;
75
76 // value of a_hat = a(x_hat)
77 d_vector a_hat = a.Forward(0, x_hat);
78
79 // (x_hat, a_hat)
80 d_vector xu_hat = join(x_hat, a_hat);
81
82 // value of g[ x_hat, a_hat ]
83 d_vector g_hat = g.Forward(0, xu_hat);
84
85 // Jacobian of g[ x_hat, a_hat ]
86 d_vector g_jac = g.Jacobian(xu_hat);
87
88 // value of delta_x
89 d_vector delta_x(n);
90 delta_x[0] = 4.0;
91 delta_x[1] = 1.0;
92
93 // value of x
94 d_vector x(n);
95 for(size_t j = 0; j < n; j++)
96 x[j] = x_hat[j] + delta_x[j];
97
98 // value of f(x)
99 d_vector y = f.Forward(0, x);
100
101 // check
102 double check = std::pow( std::fabs(x[0]) , x[1]);
103 check += std::pow( std::fabs(x[0]) , 2.0 );
104 check += std::pow( 2.0, std::fabs(x[0]) );
105 ok &= CppAD::NearEqual(y[0], check, eps99, eps99);
106
107 return ok;
108 }
109 } // END_EMPYT_NAMESPACE
110
111 bool abs_normal(void)
112 { bool ok = true;
113 ok &= test_pow();
114 return ok;
115 }
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1313 # include <cmath>
1414
1515 namespace {
16 bool test_base2ad(void)
17 { bool ok = true;
18 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
19
20 using CppAD::AD;
21
22 // Both recordiings are done with the dynamic parameter p = 0, 1
23 // to make sure does not short circut multiply
24 for(size_t ip = 0; ip < 2; ++ip)
25 {
26 // f(p; x) = p[0] * x[0] * x[0]
27 CPPAD_TESTVECTOR(AD<double>) ap(1), ax(1), ay(1), aw(1);
28 ap[0] = double(ip);
29 ax[0] = 0.0;
30 CppAD::Independent(ax, ap);
31 ay[0] = ap[0] * ax[0] * ax[0];
32 CppAD::ADFun<double> f(ax, ay);
33
34 // AD version of f
35 CppAD::ADFun< AD<double> , double > af = f.base2ad();
36
37 // g(p; x) = d/dx f(p, x) = 2 * p[0] * x[0]
38 CppAD::Independent(ax, ap);
39 af.new_dynamic(ap);
40 af.Forward(0, ax);
41 aw[0] = 1.0;
42 ay = af.Reverse(1, aw);
43 CppAD::ADFun<double> g(ax, ay);
44
45 // Evaluate g(p, x)
46 CPPAD_TESTVECTOR(double) p(1), x(1), y(1);
47 p[0] = 2.0;
48 x[0] = 3.0;
49 g.new_dynamic(p);
50 y = g.Forward(0, x);
51
52 // check result
53 double check = 2.0 * p[0] * x[0];
54 ok &= CppAD::NearEqual(y[0], check, eps99, eps99);
55 }
56 return ok;
57 }
1658 bool test_forward(void)
1759 { bool ok = true;
1860
258300 bool azmul(void)
259301 { bool ok = true;
260302
303 ok &= test_base2ad();
261304 ok &= test_forward();
262305 ok &= test_reverse();
263306 ok &= test_forward_dir();
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 /*
12 $begin graph_unary_op.cpp$$
13 $spell
14 sin
15 $$
16
17 $section Graph Unary Operator: Example and Test$$
18
19 $head Source Code$$
20 $srcthisfile%0%// BEGIN C++%// END C++%1%$$
21
22 $end
23 */
24 // BEGIN C++
25 # include <cppad/cppad.hpp>
26
27 namespace { // BEGIN_EMPTY_NAMESPACE
28
29 typedef double (*unary_fun_t)(double);
30
31 bool test_unary_fun(unary_fun_t fun, CppAD::graph::graph_op_enum op_enum)
32 { bool ok = true;
33 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
34 //
35 // C++ graph object
36 CppAD::cpp_graph graph_obj;
37 //
38 // value of constant in function
39 CPPAD_TESTVECTOR(double) p(1), x(1), c(1);
40 c[0] = 0.1;
41 p[0] = 0.2;
42 x[0] = 0.3;
43 if( std::isnan( fun( c[0] ) ) )
44 c[0] = 1.0;
45 if( std::isnan( fun( p[0] ) ) )
46 p[0] = 2.0;
47 if( std::isnan( fun( x[0] ) ) )
48 x[0] = 3.0;
49 //
50 // set scalars
51 graph_obj.function_name_set("unary_op example");
52 size_t n_dynamic_ind = 1;
53 graph_obj.n_dynamic_ind_set(n_dynamic_ind);
54 size_t n_variable_ind = 1;
55 graph_obj.n_variable_ind_set(n_variable_ind);
56 graph_obj.constant_vec_push_back( c[0] );
57 //
58 // node_4 : sin(p[0])
59 graph_obj.operator_vec_push_back(op_enum);
60 graph_obj.operator_arg_push_back(1);
61 //
62 // node_5 : sin(x[0])
63 graph_obj.operator_vec_push_back(op_enum);
64 graph_obj.operator_arg_push_back(2);
65 //
66 // node_6 : sin(c[0])
67 graph_obj.operator_vec_push_back(op_enum);
68 graph_obj.operator_arg_push_back(3);
69 //
70 // y[0] = sin(p[0])
71 graph_obj.dependent_vec_push_back(4);
72 // y[1] = sin(x[0])
73 graph_obj.dependent_vec_push_back(5);
74 // y[2] = sin(c[0])
75 graph_obj.dependent_vec_push_back(6);
76 //
77 // f(p, x) = y
78 CppAD::ADFun<double> f;
79 f.from_graph(graph_obj);
80 ok &= f.Domain() == 1;
81 ok &= f.size_dyn_ind() == 1;
82 ok &= f.Range() == 3;
83 //
84 //
85 // compute y = f(p, x)
86 f.new_dynamic(p);
87 CPPAD_TESTVECTOR(double) y = f.Forward(0, x);
88 //
89 // check result
90 ok &= CppAD::NearEqual(y[0], fun(p[0]), eps99, eps99);
91 ok &= CppAD::NearEqual(y[1], fun(x[0]), eps99, eps99);
92 ok &= CppAD::NearEqual(y[2], fun(c[0]), eps99, eps99);
93 // ------------------------------------------------------------------
94 // Convert to Graph graph and back again
95 f.to_graph(graph_obj);
96 f.from_graph(graph_obj);
97 // -------------------------------------------------------------------
98 //
99 // compute y = f(p, x)
100 f.new_dynamic(p);
101 y = f.Forward(0, x);
102 //
103 // check result
104 ok &= CppAD::NearEqual(y[0], fun(p[0]), eps99, eps99);
105 ok &= CppAD::NearEqual(y[1], fun(x[0]), eps99, eps99);
106 ok &= CppAD::NearEqual(y[2], fun(c[0]), eps99, eps99);
107 //
108 return ok;
109 }
110
111 double sign(double x)
112 { return CppAD::sign(x);
113 }
114 double neg(double x)
115 { return - x;
116 }
117
118 } // END_EMPTY_NAMESPACE
119
120 bool cpp_graph(void)
121 { bool ok = true;
122 ok &= test_unary_fun(std::fabs, CppAD::graph::abs_graph_op);
123 ok &= test_unary_fun(std::acos, CppAD::graph::acos_graph_op);
124 ok &= test_unary_fun(std::acosh, CppAD::graph::acosh_graph_op);
125 ok &= test_unary_fun(std::asinh, CppAD::graph::asinh_graph_op);
126 ok &= test_unary_fun(std::atanh, CppAD::graph::atanh_graph_op);
127 ok &= test_unary_fun(std::erf, CppAD::graph::erf_graph_op);
128 ok &= test_unary_fun(std::erfc, CppAD::graph::erfc_graph_op);
129 ok &= test_unary_fun(std::expm1, CppAD::graph::expm1_graph_op);
130 ok &= test_unary_fun(std::log1p, CppAD::graph::log1p_graph_op);
131 ok &= test_unary_fun(neg, CppAD::graph::neg_graph_op);
132 ok &= test_unary_fun(sign, CppAD::graph::sign_graph_op);
133 ok &= test_unary_fun(std::sinh, CppAD::graph::sinh_graph_op);
134 ok &= test_unary_fun(std::sin, CppAD::graph::sin_graph_op);
135 ok &= test_unary_fun(std::sqrt, CppAD::graph::sqrt_graph_op);
136 ok &= test_unary_fun(std::tanh, CppAD::graph::tanh_graph_op);
137 ok &= test_unary_fun(std::tan, CppAD::graph::tan_graph_op);
138 ok &= test_unary_fun(std::acosh, CppAD::graph::acosh_graph_op);
139 ok &= test_unary_fun(std::acosh, CppAD::graph::acosh_graph_op);
140 ok &= test_unary_fun(std::sin, CppAD::graph::sin_graph_op);
141 //
142 return ok;
143 }
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-22 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
3939 std::numeric_limits<double>::max();
4040 ok &= traits::lowest() ==
4141 std::numeric_limits<double>::min();
42 ok &= std::isnan(traits::quiet_NaN());
43 ok &= std::isinf(traits::infinity());
4244
4345 AD<double> x = 2.0;
4446 ok &= conj(x) == x;
4547 ok &= real(x) == x;
4648 ok &= imag(x) == 0.0;
4749 ok &= abs2(x) == 4.0;
50
51 ok &= (!std::isinf(x));
52 ok &= (!std::isnan(x));
53
54 x = traits::quiet_NaN();
55 ok &= std::isnan(x);
56
57 x = traits::infinity();
58 ok &= std::isinf(x);
4859
4960 // Outputing a matrix used to fail before partial specialization of
5061 // struct significant_decimals_default_impl in cppad_eigen.hpp.
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
7474 return ok;
7575 }
7676
77 # ifndef _MSC_VER
7778 bool test_sort(void)
7879 { // copy requires a random access iterator
7980 bool ok = true;
9091 //
9192 return ok;
9293 }
94 # endif
9395
9496
9597 } // END_EMPTY_NAMESPACE
100102 ok &= test_find();
101103 ok &= test_copy();
102104 ok &= test_reverse();
105 // 2DO: Determine out why this test fails with Visual Studio 2019
106 # ifndef _MSC_VER
103107 ok &= test_sort();
108 # endif
104109 //
105110 return ok;
106111 }
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
2222 # include <cppad/utility/test_boolofvoid.hpp>
2323
2424 // BEGIN_SORT_THIS_LINE_PLUS_1
25 extern bool abs_normal(void);
2526 extern bool acosh(void);
2627 extern bool acos(void);
2728 extern bool AddEq(void);
7172 extern bool Forward(void);
7273 extern bool FromBase(void);
7374 extern bool FunCheck(void);
75 extern bool cpp_graph(void);
7476 extern bool hes_sparsity(void);
7577 extern bool ipopt_solve(void);
7678 extern bool jacobian(void);
144146
145147 // BEGIN_SORT_THIS_LINE_PLUS_1
146148 Run( acos, "acos" );
149 Run( abs_normal, "abs_normal" );
147150 Run( acosh, "acosh" );
148151 Run( Add, "Add" );
149152 Run( AddEq, "AddEq" );
187190 Run( forward_order, "forward_order" );
188191 Run( FromBase, "FromBase" );
189192 Run( FunCheck, "FunCheck" );
193 Run( cpp_graph, "cpp_graph" );
190194 Run( hes_sparsity, "hes_sparsity" );
191195 Run( jacobian, "jacobian" );
192196 Run( json_graph, "json_graph" );
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
25442544 //
25452545 // Uncomment statement below to see the graph
25462546 // std::cout << graph;
2547 return ok;
2548 }
2549 // ---------------------------------------------------------------------------
2550 // Test unary operators
2551 bool unary(bool p_first)
2552 { bool ok = true;
2553 using CppAD::AD;
2554 //
2555 size_t np = 11;
2556 size_t nx = 11;
2557 size_t ny = np + nx;
2558 CPPAD_TESTVECTOR(double) p(np), x(nx), y(ny);
2559 CPPAD_TESTVECTOR( AD<double> ) ap(np), ax(nx), ay(ny);
2560 for(size_t i = 0; i < np; ++i)
2561 { p[i] = double(i + 1) / double( np + nx + 1 );
2562 ap[i] = p[i] / 2.0;
2563 }
2564 for(size_t i = 0; i < nx; ++i)
2565 { x[i] = double(i + 1 + np) / double( np + nx + 1);
2566 ax[i] = x[i] / 2.0;
2567 }
2568 CppAD::Independent(ax, ap);
2569 //
2570 CPPAD_TESTVECTOR( AD<double> ) atmp(np + nx);
2571 if( p_first )
2572 { for(size_t i = 0; i < np; ++i)
2573 atmp[i] = ap[i];
2574 for(size_t i = 0; i < nx; ++i)
2575 atmp[i + np] = ax[i];
2576 }
2577 else
2578 { for(size_t i = 0; i < np; ++i)
2579 atmp[i + nx] = ap[i];
2580 for(size_t i = 0; i < nx; ++i)
2581 atmp[i] = ax[i];
2582 }
2583 //
2584 ay[0] = fabs(atmp[0]);
2585 ay[1] = acos(atmp[1]);
2586 ay[2] = acosh(atmp[2] + 1.0);
2587 ay[3] = asin(atmp[3]);
2588 ay[4] = asinh(atmp[4]);
2589 ay[5] = atan(atmp[5]);
2590 ay[6] = atanh(atmp[6]);
2591 ay[7] = cos(atmp[7]);
2592 ay[8] = cosh(atmp[8]);
2593 ay[9] = erf(atmp[9]);
2594 ay[10] = erfc(atmp[10]);
2595 ay[11] = exp(atmp[11]);
2596 ay[12] = expm1(atmp[12]);
2597 ay[13] = log(atmp[13]);
2598 ay[14] = log1p(atmp[14]);
2599 ay[15] = - atmp[15];
2600 ay[16] = sign(atmp[16]);
2601 ay[17] = sin(atmp[17]);
2602 ay[18] = sinh(atmp[18]);
2603 ay[19] = sqrt(atmp[19]);
2604 ay[20] = tan(atmp[20]);
2605 ay[21] = sin(atmp[21]);
2606 // Create function
2607 CppAD::ADFun<double> f(ax, ay);
2608 f.optimize();
2609 //
2610 // Evaluate function at x before
2611 f.new_dynamic(p);
2612 CPPAD_TESTVECTOR(double) y_before = f.Forward(0, x);
2613 //
2614 // Convert to Json and back again
2615 std::string json = f.to_json();
2616 // std::cout << graph;
2617 f.from_json(json);
2618 //
2619 // Evaluate function at x after
2620 f.new_dynamic(p);
2621 CPPAD_TESTVECTOR(double) y_after = f.Forward(0, x);
2622 //
2623 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
2624 for(size_t i = 0; i < ny; ++i)
2625 ok &= CppAD::NearEqual( y_before[i], y_after[i], eps99, eps99 );
2626 //
25472627 return ok;
25482628 }
25492629
25862666 ok &= to_json_and_back();
25872667 ok &= binary_operators();
25882668 ok &= cumulative_sum();
2589 //
2590 return ok;
2591 }
2669 ok &= unary(true);
2670 ok &= unary(false);
2671 //
2672 return ok;
2673 }
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
7272 $(EIGEN_SRC_FILES) \
7373 $(IPOPT_SRC_FILES) \
7474 $(OPENMP_SRC_FILES) \
75 abs_normal.cpp \
7576 acos.cpp \
7677 acosh.cpp \
7778 add.cpp \
120121 from_base.cpp \
121122 fun_check.cpp \
122123 general.cpp \
124 cpp_graph.cpp \
123125 hes_sparsity.cpp \
124126 jacobian.cpp \
125127 json_graph.cpp \
9797 CONFIG_CLEAN_FILES =
9898 CONFIG_CLEAN_VPATH_FILES =
9999 am__general_SOURCES_DIST = base_adolc.cpp cppad_eigen.cpp \
100 eigen_mat_inv.cpp ipopt_solve.cpp alloc_openmp.cpp acos.cpp \
101 acosh.cpp add.cpp add_eq.cpp add_zero.cpp adfun.cpp asin.cpp \
102 asinh.cpp assign.cpp atan2.cpp atan.cpp atanh.cpp \
103 atomic_three.cpp azmul.cpp base_alloc.cpp bool_sparsity.cpp \
104 check_simple_vector.cpp chkpoint_one.cpp chkpoint_two.cpp \
105 compare_change.cpp compare.cpp cond_exp_ad.cpp cond_exp.cpp \
106 cond_exp_rev.cpp copy.cpp cos.cpp cosh.cpp cppad_vector.cpp \
107 dbl_epsilon.cpp dependency.cpp div.cpp div_eq.cpp \
108 div_zero_one.cpp erf.cpp exp.cpp expm1.cpp extern_value.cpp \
109 extern_value.hpp fabs.cpp for_hess.cpp for_sparse_hes.cpp \
110 for_sparse_jac.cpp forward.cpp forward_dir.cpp \
111 forward_order.cpp from_base.cpp fun_check.cpp general.cpp \
112 hes_sparsity.cpp jacobian.cpp json_graph.cpp local/is_pod.cpp \
113 local/json_lexer.cpp local/json_parser.cpp \
114 local/vector_set.cpp log10.cpp log1p.cpp log.cpp \
115 mul_cond_rev.cpp mul.cpp mul_cskip.cpp mul_eq.cpp \
100 eigen_mat_inv.cpp ipopt_solve.cpp alloc_openmp.cpp \
101 abs_normal.cpp acos.cpp acosh.cpp add.cpp add_eq.cpp \
102 add_zero.cpp adfun.cpp asin.cpp asinh.cpp assign.cpp atan2.cpp \
103 atan.cpp atanh.cpp atomic_three.cpp azmul.cpp base_alloc.cpp \
104 bool_sparsity.cpp check_simple_vector.cpp chkpoint_one.cpp \
105 chkpoint_two.cpp compare_change.cpp compare.cpp \
106 cond_exp_ad.cpp cond_exp.cpp cond_exp_rev.cpp copy.cpp cos.cpp \
107 cosh.cpp cppad_vector.cpp dbl_epsilon.cpp dependency.cpp \
108 div.cpp div_eq.cpp div_zero_one.cpp erf.cpp exp.cpp expm1.cpp \
109 extern_value.cpp extern_value.hpp fabs.cpp for_hess.cpp \
110 for_sparse_hes.cpp for_sparse_jac.cpp forward.cpp \
111 forward_dir.cpp forward_order.cpp from_base.cpp fun_check.cpp \
112 general.cpp cpp_graph.cpp hes_sparsity.cpp jacobian.cpp \
113 json_graph.cpp local/is_pod.cpp local/json_lexer.cpp \
114 local/json_parser.cpp local/vector_set.cpp log10.cpp log1p.cpp \
115 log.cpp mul_cond_rev.cpp mul.cpp mul_cskip.cpp mul_eq.cpp \
116116 mul_level.cpp mul_zdouble.cpp mul_zero_one.cpp \
117117 near_equal_ext.cpp neg.cpp new_dynamic.cpp num_limits.cpp \
118118 ode_err_control.cpp optimize.cpp parameter.cpp poly.cpp \
132132 @CppAD_OPENMP_TRUE@am__objects_4 = alloc_openmp.$(OBJEXT)
133133 am__dirstamp = $(am__leading_dot)dirstamp
134134 am_general_OBJECTS = $(am__objects_1) $(am__objects_2) \
135 $(am__objects_3) $(am__objects_4) acos.$(OBJEXT) \
136 acosh.$(OBJEXT) add.$(OBJEXT) add_eq.$(OBJEXT) \
135 $(am__objects_3) $(am__objects_4) abs_normal.$(OBJEXT) \
136 acos.$(OBJEXT) acosh.$(OBJEXT) add.$(OBJEXT) add_eq.$(OBJEXT) \
137137 add_zero.$(OBJEXT) adfun.$(OBJEXT) asin.$(OBJEXT) \
138138 asinh.$(OBJEXT) assign.$(OBJEXT) atan2.$(OBJEXT) \
139139 atan.$(OBJEXT) atanh.$(OBJEXT) atomic_three.$(OBJEXT) \
150150 for_sparse_jac.$(OBJEXT) forward.$(OBJEXT) \
151151 forward_dir.$(OBJEXT) forward_order.$(OBJEXT) \
152152 from_base.$(OBJEXT) fun_check.$(OBJEXT) general.$(OBJEXT) \
153 hes_sparsity.$(OBJEXT) jacobian.$(OBJEXT) json_graph.$(OBJEXT) \
154 local/is_pod.$(OBJEXT) local/json_lexer.$(OBJEXT) \
155 local/json_parser.$(OBJEXT) local/vector_set.$(OBJEXT) \
156 log10.$(OBJEXT) log1p.$(OBJEXT) log.$(OBJEXT) \
157 mul_cond_rev.$(OBJEXT) mul.$(OBJEXT) mul_cskip.$(OBJEXT) \
158 mul_eq.$(OBJEXT) mul_level.$(OBJEXT) mul_zdouble.$(OBJEXT) \
159 mul_zero_one.$(OBJEXT) near_equal_ext.$(OBJEXT) neg.$(OBJEXT) \
160 new_dynamic.$(OBJEXT) num_limits.$(OBJEXT) \
161 ode_err_control.$(OBJEXT) optimize.$(OBJEXT) \
162 parameter.$(OBJEXT) poly.$(OBJEXT) pow.$(OBJEXT) \
163 pow_int.$(OBJEXT) print_for.$(OBJEXT) reverse.$(OBJEXT) \
164 rev_sparse_jac.$(OBJEXT) rev_two.$(OBJEXT) \
153 cpp_graph.$(OBJEXT) hes_sparsity.$(OBJEXT) jacobian.$(OBJEXT) \
154 json_graph.$(OBJEXT) local/is_pod.$(OBJEXT) \
155 local/json_lexer.$(OBJEXT) local/json_parser.$(OBJEXT) \
156 local/vector_set.$(OBJEXT) log10.$(OBJEXT) log1p.$(OBJEXT) \
157 log.$(OBJEXT) mul_cond_rev.$(OBJEXT) mul.$(OBJEXT) \
158 mul_cskip.$(OBJEXT) mul_eq.$(OBJEXT) mul_level.$(OBJEXT) \
159 mul_zdouble.$(OBJEXT) mul_zero_one.$(OBJEXT) \
160 near_equal_ext.$(OBJEXT) neg.$(OBJEXT) new_dynamic.$(OBJEXT) \
161 num_limits.$(OBJEXT) ode_err_control.$(OBJEXT) \
162 optimize.$(OBJEXT) parameter.$(OBJEXT) poly.$(OBJEXT) \
163 pow.$(OBJEXT) pow_int.$(OBJEXT) print_for.$(OBJEXT) \
164 reverse.$(OBJEXT) rev_sparse_jac.$(OBJEXT) rev_two.$(OBJEXT) \
165165 romberg_one.$(OBJEXT) rosen_34.$(OBJEXT) runge_45.$(OBJEXT) \
166166 simple_vector.$(OBJEXT) sin_cos.$(OBJEXT) sin.$(OBJEXT) \
167167 sinh.$(OBJEXT) sparse_hessian.$(OBJEXT) \
195195 DEFAULT_INCLUDES =
196196 depcomp = $(SHELL) $(top_srcdir)/depcomp
197197 am__maybe_remake_depfiles = depfiles
198 am__depfiles_remade = ./$(DEPDIR)/acos.Po ./$(DEPDIR)/acosh.Po \
199 ./$(DEPDIR)/add.Po ./$(DEPDIR)/add_eq.Po \
198 am__depfiles_remade = ./$(DEPDIR)/abs_normal.Po ./$(DEPDIR)/acos.Po \
199 ./$(DEPDIR)/acosh.Po ./$(DEPDIR)/add.Po ./$(DEPDIR)/add_eq.Po \
200200 ./$(DEPDIR)/add_zero.Po ./$(DEPDIR)/adfun.Po \
201201 ./$(DEPDIR)/alloc_openmp.Po ./$(DEPDIR)/asin.Po \
202202 ./$(DEPDIR)/asinh.Po ./$(DEPDIR)/assign.Po ./$(DEPDIR)/atan.Po \
209209 ./$(DEPDIR)/compare_change.Po ./$(DEPDIR)/cond_exp.Po \
210210 ./$(DEPDIR)/cond_exp_ad.Po ./$(DEPDIR)/cond_exp_rev.Po \
211211 ./$(DEPDIR)/copy.Po ./$(DEPDIR)/cos.Po ./$(DEPDIR)/cosh.Po \
212 ./$(DEPDIR)/cppad_eigen.Po ./$(DEPDIR)/cppad_vector.Po \
213 ./$(DEPDIR)/dbl_epsilon.Po ./$(DEPDIR)/dependency.Po \
214 ./$(DEPDIR)/div.Po ./$(DEPDIR)/div_eq.Po \
215 ./$(DEPDIR)/div_zero_one.Po ./$(DEPDIR)/eigen_mat_inv.Po \
216 ./$(DEPDIR)/erf.Po ./$(DEPDIR)/exp.Po ./$(DEPDIR)/expm1.Po \
212 ./$(DEPDIR)/cpp_graph.Po ./$(DEPDIR)/cppad_eigen.Po \
213 ./$(DEPDIR)/cppad_vector.Po ./$(DEPDIR)/dbl_epsilon.Po \
214 ./$(DEPDIR)/dependency.Po ./$(DEPDIR)/div.Po \
215 ./$(DEPDIR)/div_eq.Po ./$(DEPDIR)/div_zero_one.Po \
216 ./$(DEPDIR)/eigen_mat_inv.Po ./$(DEPDIR)/erf.Po \
217 ./$(DEPDIR)/exp.Po ./$(DEPDIR)/expm1.Po \
217218 ./$(DEPDIR)/extern_value.Po ./$(DEPDIR)/fabs.Po \
218219 ./$(DEPDIR)/for_hess.Po ./$(DEPDIR)/for_sparse_hes.Po \
219220 ./$(DEPDIR)/for_sparse_jac.Po ./$(DEPDIR)/forward.Po \
330331 CYGPATH_W = @CYGPATH_W@
331332
332333 # -----------------------------------------------------------------------------
333 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
334 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
334335 #
335336 # CppAD is distributed under the terms of the
336337 # Eclipse Public License Version 2.0.
413414 builddir = @builddir@
414415 compiler_has_conversion_warn = @compiler_has_conversion_warn@
415416 cppad_boostvector = @cppad_boostvector@
416 cppad_cplusplus_201100_ok = @cppad_cplusplus_201100_ok@
417417 cppad_cppadvector = @cppad_cppadvector@
418418 cppad_cxx_flags = @cppad_cxx_flags@
419419 cppad_description = @cppad_description@
468468 prefix = @prefix@
469469 program_transform_name = @program_transform_name@
470470 psdir = @psdir@
471 runstatedir = @runstatedir@
471472 sbindir = @sbindir@
472473 sharedstatedir = @sharedstatedir@
473474 srcdir = @srcdir@
522523 $(EIGEN_SRC_FILES) \
523524 $(IPOPT_SRC_FILES) \
524525 $(OPENMP_SRC_FILES) \
526 abs_normal.cpp \
525527 acos.cpp \
526528 acosh.cpp \
527529 add.cpp \
570572 from_base.cpp \
571573 fun_check.cpp \
572574 general.cpp \
575 cpp_graph.cpp \
573576 hes_sparsity.cpp \
574577 jacobian.cpp \
575578 json_graph.cpp \
691694 distclean-compile:
692695 -rm -f *.tab.c
693696
697 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abs_normal.Po@am__quote@ # am--include-marker
694698 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acos.Po@am__quote@ # am--include-marker
695699 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acosh.Po@am__quote@ # am--include-marker
696700 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add.Po@am__quote@ # am--include-marker
720724 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/copy.Po@am__quote@ # am--include-marker
721725 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cos.Po@am__quote@ # am--include-marker
722726 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cosh.Po@am__quote@ # am--include-marker
727 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpp_graph.Po@am__quote@ # am--include-marker
723728 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cppad_eigen.Po@am__quote@ # am--include-marker
724729 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cppad_vector.Po@am__quote@ # am--include-marker
725730 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbl_epsilon.Po@am__quote@ # am--include-marker
951956 clean-am: clean-checkPROGRAMS clean-generic mostlyclean-am
952957
953958 distclean: distclean-am
954 -rm -f ./$(DEPDIR)/acos.Po
959 -rm -f ./$(DEPDIR)/abs_normal.Po
960 -rm -f ./$(DEPDIR)/acos.Po
955961 -rm -f ./$(DEPDIR)/acosh.Po
956962 -rm -f ./$(DEPDIR)/add.Po
957963 -rm -f ./$(DEPDIR)/add_eq.Po
980986 -rm -f ./$(DEPDIR)/copy.Po
981987 -rm -f ./$(DEPDIR)/cos.Po
982988 -rm -f ./$(DEPDIR)/cosh.Po
989 -rm -f ./$(DEPDIR)/cpp_graph.Po
983990 -rm -f ./$(DEPDIR)/cppad_eigen.Po
984991 -rm -f ./$(DEPDIR)/cppad_vector.Po
985992 -rm -f ./$(DEPDIR)/dbl_epsilon.Po
11061113 installcheck-am:
11071114
11081115 maintainer-clean: maintainer-clean-am
1109 -rm -f ./$(DEPDIR)/acos.Po
1116 -rm -f ./$(DEPDIR)/abs_normal.Po
1117 -rm -f ./$(DEPDIR)/acos.Po
11101118 -rm -f ./$(DEPDIR)/acosh.Po
11111119 -rm -f ./$(DEPDIR)/add.Po
11121120 -rm -f ./$(DEPDIR)/add_eq.Po
11351143 -rm -f ./$(DEPDIR)/copy.Po
11361144 -rm -f ./$(DEPDIR)/cos.Po
11371145 -rm -f ./$(DEPDIR)/cosh.Po
1146 -rm -f ./$(DEPDIR)/cpp_graph.Po
11381147 -rm -f ./$(DEPDIR)/cppad_eigen.Po
11391148 -rm -f ./$(DEPDIR)/cppad_vector.Po
11401149 -rm -f ./$(DEPDIR)/dbl_epsilon.Po
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
267267 // case where ODE does not make sense
268268 if( x[0] < 0. || x[1] < 0. )
269269 { was_negative_ = true;
270 f[0] = CppAD::nan(0.);
270 f[0] = std::numeric_limits<double>::quiet_NaN();
271271 }
272272 }
273273 // set f_t = df / dt
280280 f_t[1] = 0.;
281281 if( x[0] < 0. || x[1] < 0. )
282282 { was_negative_ = true;
283 f_t[0] = CppAD::nan(0.);
283 f_t[0] = std::numeric_limits<double>::quiet_NaN();
284284 }
285285 }
286286 // set f_x = df / dx
295295 f_x[1 * 2 + 1] = 0.; // f1 w.r.t. x1
296296 if( x[0] < 0. || x[1] < 0. )
297297 { was_negative_ = true;
298 f_x[0] = CppAD::nan(0.);
298 f_x[0] = std::numeric_limits<double>::quiet_NaN();
299299 }
300300 }
301301 bool was_negative(void)
390390 const CppAD::vector<double> &x,
391391 CppAD::vector<double> &f)
392392 { size_t i;
393 f[0] = CppAD::nan(0.);
393 f[0] = std::numeric_limits<double>::quiet_NaN();
394394 for(i = 1; i < n; i++)
395395 f[i] = double(i+1) * x[i-1];
396396 }
468468 ok &= OdeErrControl_four();
469469 return ok;
470470 }
471
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
410410 return ok;
411411 }
412412
413 /*
414 // This test does not pass because azmul is used be reverse mode to deteremine which
415 // partials are slected and the result is zero instead of nan or infinity.
416 // There is a wish list item to fix this problem.
417 bool PowTestSeven(void)
418 { bool ok = true;
419
420 using std::cout;
421 using CppAD::AD;
422 using CppAD::vector;
423 //
424 vector< double> x(1), y(1), dx(1), dy(1), w(1), dw(2);
425 vector< AD<double> > ax(1), ay(1);
426 //
427 ax[0] = 0.0;
428 //
429 CppAD::Independent(ax);
430 ay[0] = pow(ax[0], 0.5);
431 CppAD::ADFun<double> f(ax, ay);
432 f.check_for_nan(false);
433 //
434 x[0] = 0.0;
435 y = f.Forward(0, x);
436 //
437 dx[0] = 1.0;
438 dy = f.Forward(1, dx);
439 //
440 w[0] = 1.0;
441 dw = f.Reverse(2, w);
442 //
443 ok &= y[0] == 0.0;
444 ok &= ! std::isfinite( dw[0] );
445 ok &= ! std::isfinite( dw[1] );
446 //
447 return ok;
448 }
449 */
450413 // Test x^e where x is negative and e is AD<double> equal to an integer
451414 bool PowTestEight(void)
452415 { bool ok = true;
457420 using CppAD::NearEqual;
458421 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
459422 //
460 vector< double> x(1), y(2), dx(1), dy(2), w(2), dw(2);
423 vector<double> x(1), y(2), dx(1), dy(2), w(2), dw(2);
461424 vector< AD<double> > ax(1), ay(2);
462425 //
463426 x[0] = -2.0;
501464 //
502465 return ok;
503466 }
467 // k-th derivative of x^y .w.r.t. x
468 double dpow_dx(double x, double y, size_t k)
469 { double result = std::pow(x, y - double(k));
470 for(size_t ell = 0; ell < k; ++ell)
471 result *= (y - double(ell));
472 return result;
473 }
474 // Testing PowvpOp
475 bool PowTestNine(void)
476 { bool ok = true;
477 //
478 using std::cout;
479 using CppAD::AD;
480 using CppAD::vector;
481 using CppAD::NearEqual;
482 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
483 //
484 vector<double> x(1), dx(1);
485 vector<double> z(1), dz(1);
486 vector<double> w(1), dw(5);
487 vector< AD<double> > ax(1), az(1);
488 //
489 ax[0] = 1.0;
490 double y = 2.5;
491 //
492 CppAD::Independent(ax);
493 az[0] = pow(ax[0], y);
494 CppAD::ADFun<double> f(ax, az);
495 //
496 double check;
497 //
498 // zero order forward
499 for(size_t ix = 0; ix < 3; ++ix)
500 { x[0] = double(ix);
501 z = f.Forward(0, x);
502 check = dpow_dx(x[0], y, 0);
503 ok &= NearEqual(z[0], check, eps99, eps99);
504 //
505 // first order forward
506 dx[0] = 1.0;
507 dz = f.Forward(1, dx);
508 check = dpow_dx(x[0], y, 1);
509 ok &= NearEqual(dz[0], check, eps99, eps99);
510 //
511 // ell-th order forward
512 double factorial = 1.0;
513 for(size_t k = 2; k < 5; ++k)
514 { factorial *= double(k);
515 dx[0] = 0.0; // x^(k)
516 dz = f.Forward(k, dx);
517 check = dpow_dx(x[0], y, k) / factorial;
518 ok &= NearEqual(dz[0], check, eps99, eps99);
519 }
520 // second order reverse
521 w[0] = 1.0;
522 dw = f.Reverse(5, w);
523 factorial = 1.0;
524 for(size_t k = 0; k < 5; ++k)
525 { check = dpow_dx(x[0], y, k+1) / factorial;
526 ok &= NearEqual(dw[k], check, eps99, eps99);
527 factorial *= double(k+1);
528 }
529 }
530 //
531 return ok;
532 }
533 // Testing PowvpOp multiple direction forward
534 bool PowTestTen(void)
535 { bool ok = true;
536 //
537 using std::cout;
538 using CppAD::AD;
539 using CppAD::vector;
540 using CppAD::NearEqual;
541 double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
542 //
543 size_t n = 3;
544 vector<double> x(n), xq(n * n);
545 vector<double> z(n), zq(n * n);
546 vector<double> y(n);
547 vector< AD<double> > ax(n), az(n);
548 //
549 for(size_t j = 0; j < n; ++j)
550 { ax[j] = double(j);
551 y[j] = double(j) + 1.5;
552 }
553 //
554 CppAD::Independent(ax);
555 for(size_t j = 0; j < n; ++j)
556 az[j] = pow(ax[j], y[j]);
557 CppAD::ADFun<double> f(ax, az);
558 //
559 // zero order forward
560 for(size_t j = 0; j < n; ++j)
561 x[j] = double(j) + 1.5;
562 z = f.Forward(0, x);
563 double check;
564 for(size_t j = 0; j < n; ++j)
565 { check = dpow_dx(x[j], y[j], 0);
566 ok &= NearEqual(z[j], check, eps99, eps99);
567 }
568 //
569 // first order forward multiple directions
570 size_t r = n;
571 for(size_t j = 0; j < n; ++j)
572 { for(size_t ell = 0; ell < r; ell++)
573 { if( j == ell )
574 xq[ r * j + ell] = 1.0;
575 else
576 xq[ r * j + ell] = 0.0;
577 }
578 }
579 size_t q = 1;
580 zq = f.Forward(q, r, xq);
581 for(size_t j = 0; j < n; ++j)
582 { for(size_t ell = 0; ell < r; ell++)
583 { if( j == ell )
584 check = dpow_dx(x[j], y[j], 1);
585 else
586 check = 0.0;
587 ok &= NearEqual(zq[r * j + ell], check, eps99, eps99);
588 }
589 }
590 //
591 // second order forward multiple directions
592 for(size_t j = 0; j < n; ++j)
593 { for(size_t ell = 0; ell < r; ell++)
594 xq[ r * j + ell] = 0.0;
595 }
596 q = 2;
597 zq = f.Forward(q, r, xq);
598 for(size_t j = 0; j < n; ++j)
599 { for(size_t ell = 0; ell < r; ell++)
600 { if( j == ell )
601 check = dpow_dx(x[j], y[j], 2) / 2.0;
602 else
603 check = 0.0;
604 ok &= NearEqual(zq[r * j + ell], check, eps99, eps99);
605 }
606 }
607 return ok;
608 }
504609
505610 } // END empty namespace
506611
512617 ok &= PowTestFour();
513618 ok &= PowTestFive();
514619 ok &= PowTestSix();
515 // ok &= PowTestSeven();
620 // PowTestSeven was removed
516621 ok &= PowTestEight();
517 //
518 return ok;
519 }
622 ok &= PowTestNine();
623 ok &= PowTestTen();
624 //
625 return ok;
626 }
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-21 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
451451 return ok;
452452 }
453453 // ----------------------------------------------------------------------------
454 bool duplicate_dependent_var(void)
455 { bool ok = true;
456 using CppAD::AD;
457
458 // f(x) = [ y_0, y_1 ] = [ x_0 * x_0 , x_0 * x_0 ]
459 size_t nx = 1;
460 size_t ny = 2;
461 CPPAD_TESTVECTOR( AD<double> ) ax(nx), ay(ny);
462 ax[0] = 1.0;
463 CppAD::Independent(ax);
464 ay[0] = ax[0] * ax[0];
465 ay[1] = ay[0];
466 CppAD::ADFun<double> f(ax, ay);
467 //
468 // Forward zero
469 CPPAD_TESTVECTOR(double) x0(nx), x1(nx), yk(ny);
470 x0[0] = 3.0;
471 yk = f.Forward(0, x0);
472 ok &= yk[0] == x0[0] * x0[0];
473 ok &= yk[1] == yk[0];
474 //
475 // Forward one
476 x1[0] = 1.0;
477 yk = f.Forward(1, x1);
478 ok &= yk[0] == 2.0 * x0[0];
479 ok &= yk[1] == yk[0];
480 //
481 // Reverse two
482 size_t q = 2; // number of orders
483 CPPAD_TESTVECTOR(double) w(ny * q), dw(nx * q);
484 for(size_t i = 0; i < ny; ++i)
485 { w[ i * q + 0 ] = 0.0; // derivative w.r.t. zero order coefficient
486 w[ i * q + 1 ] = 1.0; // derivative w.r.t. first order coefficient
487 }
488 dw = f.Reverse(2, w);
489 // derivative w.r.t zero order coefficients
490 ok &= dw[nx * 0 + 0] == 4.0;
491 // derivative w.r.t first order coefficients
492 ok &= dw[nx * 0 + 1] == 4.0 * x0[0];
493 //
494 return ok;
495 }
496
454497 } // End empty namespace
455498
456499 # include <vector>
459502 { bool ok = true;
460503 ok &= reverse_one();
461504 ok &= reverse_mul();
505 ok &= duplicate_dependent_var();
462506
463507 ok &= reverse_any_cases< CppAD::vector <double> >();
464508 ok &= reverse_any_cases< std::vector <double> >();