source: trunk/ADOL-C/examples/additional_examples/taylor/taylorexam.cpp @ 171

Last change on this file since 171 was 171, checked in by kulshres, 9 years ago

Squashed merge branch 'master' of 'gitclone' into svn

  • 'master' of 'gitclone': (84 commits) adjust example makefiles and include paths get rid of the symlink in the src subdirectory

details of the commits:
commit c9e4bc332d2363f737fc2e8a8fcfc2e43ddb9d15
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:43:47 2010 +0200

adjust example makefiles and include paths

include paths in example sources were wrong for some time now
simplify makefile rules too, there is really no need for checking SPARSE
adjust include paths in makefiles.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e6e1963e41e097fd5b4a79cd1611c12f6868dc94
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:41:25 2010 +0200

get rid of the symlink in the src subdirectory

windows doesn't like symlinks and make infinite depth directories
we now create a symlink for build in the directory parallel to src
adjust all makefiles.am accordingly for build

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     taylorexam.cpp
4 Revision: $Id: taylorexam.cpp 171 2010-10-04 13:57:19Z kulshres $
5 Contents: Test driver 'tensor_eval(..)' to compute
6           higher order derivatives
7
8 Copyright (c) Andrea Walther, Andreas Griewank
9 
10 This file is part of ADOL-C. This software is provided as open source.
11 Any use, reproduction, or distribution of the software constitutes
12 recipient's acceptance of the terms of the accompanying license file.
13 
14---------------------------------------------------------------------------*/
15
16/****************************************************************************/
17/*                                                                 INCLUDES */
18#include <adolc/adolc.h>
19
20#include <cstdlib>
21#include <iostream>
22using namespace std;
23
24/****************************************************************************/
25/*                                                                     MAIN */
26int main() {
27    int i,j,m,n,d,p,dim;
28
29    /*--------------------------------------------------------------------------*/
30    cout << "TAYLOREXAM (ADOL-C Example)\n\n";                      /* inputs */
31    cout << " Number of indenpendents = ?\n ";
32    cin >> n;
33    cout << " Number of dependents = (<=n) ?\n ";
34    cin >> m;
35    cout << " Degree = ?\n ";
36    cin >> d;
37    cout << " Number of directions = ?\n ";
38    cin >> p;
39
40    /*--------------------------------------------------------------------------*/
41    int* multi = new int[d];                         /* allocations and inits */
42    double* xp = new double[n];
43    double* yp = new double[m];
44    double** S = new double*[n];
45    double* test = new double[m];
46    double** tensoren;
47    adouble* x = new adouble[n];
48    adouble* y = new adouble[m];
49
50    for (i=0; i<d; i++)
51        multi[i] = 0;
52
53    for (i=0; i<n; i++) {
54        xp[i] = (i+1.0)/(2.0+i);
55        S[i] = new double[p];
56        for (j=0; j<p; j++)
57            S[i][j] = (i==j)?1.0:0.0;
58    }
59
60    /*--------------------------------------------------------------------------*/
61    trace_on(1);                                       /* tracing the function */
62    // adouble* x = new adouble[n];
63    // adouble* y = new adouble[m];
64    y[0] = 1;
65
66    for (i=0; i<n; i++) {
67        x[i] <<= xp[i];
68        y[0] *= x[i];
69    }
70    for (i=1; i<m; i++)
71        y[i] = x[i];
72    for (i=0; i<m; i++)
73        y[i] >>= yp[i] ;
74    trace_off();
75
76    /*--------------------------------------------------------------------------*/
77    d = d-1;                                                /* 1. tensor_eval */
78    dim = binomi(p+d,d);
79    cout <<"TASK 1:\n";
80    cout <<" d = "<<d<<", dim = "<<dim<<"\n";
81    tensoren = myalloc2(m,dim);
82
83    tensor_eval(1,m,n,d,p,xp,tensoren,S);
84
85    for (i=0; i<p; i++) {
86        multi[0] = i+1;
87        tensor_value(d,m,test,tensoren,multi);
88        cout << i+1 << ": ";
89        for(j=0; j<m; j++)
90            cout << " " << test[j] << " ";
91        cout << "\n";
92    }
93
94    myfree2(tensoren);
95
96    /*--------------------------------------------------------------------------*/
97    d = d+1;                                                /* 2. tensor_eval */
98    dim = binomi(p+d,d);
99    cout <<"TASK 2:\n";
100    cout <<" d = "<<d<<", dim = "<<dim<<"\n";
101    tensoren = myalloc2(m,dim);
102
103    tensor_eval(1,m,n,d,p,xp,tensoren,S);
104
105    for(i=0; i<p; i++) {
106        multi[0] = i+1;
107        tensor_value(d,m,test,tensoren,multi);
108        cout << i+1 << ": ";
109        for (j=0; j<m; j++)
110            cout << " " << test[j] << " ";
111        cout << "\n";
112    }
113    cout << "\n";
114
115
116    /*--------------------------------------------------------------------------*/
117    xp[0] = 2*xp[0];                                        /* 3. tensor_eval */
118
119    cout <<"TASK 3:\n";
120    cout <<" NEW independend values !!!\n";
121    cout <<" d = "<<d<<", dim = "<<dim<<"\n";
122
123    tensor_eval(1,m,n,d,p,xp,tensoren,S);
124
125    for(i=0; i<p; i++) {
126        multi[0] = i+1;
127        tensor_value(d,m,test,tensoren,multi);
128        cout << i+1 << ": ";
129        for (j=0; j<m; j++)
130            cout << " " << test[j] << " ";
131        cout << "\n";
132    }
133
134    myfree2(tensoren);
135
136    /*--------------------------------------------------------------------------*/
137    d = d-1;                                                /* 4. tensor_eval */
138    dim = binomi(p+d,d);
139    cout <<"TASK 4:\n";
140    cout <<" d = "<<d<<", dim = "<<dim<<"\n";
141    tensoren = myalloc2(m,dim);
142
143    tensor_eval(1,m,n,d,p,xp,tensoren,S);
144    for(i=0;i<p;i++) {
145        multi[0] = i+1;
146        tensor_value(d,m,test,tensoren,multi);
147        cout << i+1 << ": ";
148        for (j=0; j<m; j++)
149            cout << " " << test[j] << " ";
150        cout << "\n";
151    }
152
153    myfree2(tensoren);
154
155    /*--------------------------------------------------------------------------*/
156    d = d+1;                                                /* 5. tensor_eval */
157    dim = binomi(p+d,d);
158    xp[0] = 0.5*xp[0];
159    cout <<"TASK 5:\n";
160    cout <<" OLD independend values !!!\n";
161    cout <<" d = "<<d<<", dim = "<<dim<<"\n";
162    tensoren = myalloc2(m,dim);
163
164    tensor_eval(1,m,n,d,p,xp,tensoren,S);
165    for(i=0;i<p;i++) {
166        multi[0] = i+1;
167        tensor_value(d,m,test,tensoren,multi);
168        cout << i+1 << ": ";
169        for (j=0; j<m; j++)
170            cout << " " << test[j] << " ";
171        cout << "\n";
172    }
173
174    myfree2(tensoren);
175
176    return 1;
177}
178
179
180/****************************************************************************/
181/*                                                               THAT'S ALL */
182
Note: See TracBrowser for help on using the repository browser.