1 /*----------------------------------------------------------------------------
2  ADOL-C -- Automatic Differentiation by Overloading in C++
3  File:     adouble_tl_indo.cpp
4  Revision: $Id$
5  Contents: adouble_tl.cpp contains that definitions of procedures used for sparse patterns.
6 
7  Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
8                Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel,
9                Benjamin Letschert
10 
11  This file is part of ADOL-C. This software is provided as open source.
12  Any use, reproduction, or distribution of the software constitutes
13  recipient's acceptance of the terms of the accompanying license file.
14 
15 ----------------------------------------------------------------------------*/
16 
17 #include <adolc/adtl_indo.h>
18 #include <cmath>
19 #include <iostream>
20 #include <limits>
21 #include "dvlparms.h"
22 
23 using std::cout;
24 
25 extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line);
26 
27 namespace adtl_indo {
28 
29 /*******************  i/o operations  ***************************************/
operator <<(ostream & out,const adouble & a)30 ostream& operator << ( ostream& out, const adouble& a) {
31 	out << a.val;
32     return out;
33 }
34 
operator >>(istream & in,adouble & a)35 istream& operator >> ( istream& in, adouble& a) {
36 	in >> a.val;
37 	return in;
38 }
39 
40 /**************** ADOLC_TRACELESS_SPARSE_PATTERN ****************************/
ADOLC_Init_sparse_pattern(adouble * a,int n,unsigned int start_cnt)41 int ADOLC_Init_sparse_pattern(adouble *a, int n, unsigned int start_cnt) {
42     for(unsigned int i=0; i < n; i++) {
43 	a[i].delete_pattern();
44 	a[i].pattern.push_back( i+start_cnt );
45     }
46     return 3;
47 }
48 
ADOLC_get_sparse_pattern(const adouble * const b,int m,unsigned int ** & pat)49 int ADOLC_get_sparse_pattern(const adouble *const b, int m, unsigned int **&pat) {
50     pat = (unsigned int**) malloc(m*sizeof(unsigned int*));
51     for( int i=0; i < m ; i++){
52 	//const_cast<adouble&>(b[i]).pattern.sort();
53 	//const_cast<adouble&>(b[i]).pattern.unique();
54       if ( b[i].get_pattern_size() > 0 ) {
55          pat[i] = (unsigned int*) malloc(sizeof(unsigned int) * (b[i].get_pattern_size() +1) );
56          pat[i][0] = b[i].get_pattern_size();
57          const list<unsigned int>& tmp_set = b[i].get_pattern();
58          list<unsigned int>::const_iterator it;
59          unsigned int l=1;
60          for(it = tmp_set.begin() ; it != tmp_set.end() ; it++,l++)
61              pat[i][l] = *it;
62        } else {
63           pat[i] = (unsigned int*) malloc(sizeof(unsigned int));
64           pat[i][0] =0;
65        }
66     }
67     return 3;
68 }
69 
70 }
71