Revision 1588 trunk/src/linad99/fvar2.cpp

fvar2.cpp (revision 1588)
21 21
  #include <iostream.hpp>
22 22
#endif
23 23

  
24

  
25 24
#include <stdio.h>
26 25
#ifndef __SUN__
27 26
#endif
28 27
#include <math.h>
29 28

  
30
void gradfree(dlink *);
31

  
32 29
/**
33 30
  Creates an entry in the gradient structure linked list.
34 31
  \return Pointer instance of class double_and_int
35 32
 */
36
double_and_int * gradnew()
33
double_and_int* gradnew()
37 34
{
38
  #if defined (SAFE_ARRAYS)
39
    if (!gradient_structure::instances)
40
    {
41
      cerr << "Error -- you are trying to create a dvariable object"
42
              " when there is " << endl << "no object of type"
43
              " gradient_structure in scope " << endl;
44
      ad_exit(1);
45
    }
46
  #endif
35
#if defined (SAFE_ARRAYS)
36
  if (!gradient_structure::instances)
47 37
  {
48
    dlink * tmp;
49
    tmp = gradient_structure::GRAD_LIST->last_remove();
50
    if (!tmp)
51
    {
52
      tmp=gradient_structure::GRAD_LIST->create();
53
    }
54

  
55
    //  cout << "In gradnew the address of the double * ptr is "
56
    //       << _farptr_tolong(tmp) << "\n";
57

  
58
    return (double_and_int *) tmp;
38
    cerr << "Error -- you are trying to create a dvariable object"
39
            " when there is " << endl << "no object of type"
40
            " gradient_structure in scope " << endl;
41
    ad_exit(1);
59 42
  }
43
#endif
44
  dlink* tmp = gradient_structure::GRAD_LIST->last_remove();
45
  if (!tmp)
46
  {
47
    tmp = gradient_structure::GRAD_LIST->create();
48
  }
49
  //  cout << "In gradnew the address of the double * ptr is "
50
  //       << _farptr_tolong(tmp) << "\n";
51
  return (double_and_int*)tmp;
60 52
}
61

  
62 53
/**
63 54
 * Description not yet available.
64 55
 * \param
65 56
 */
66
void gradfree(dlink * v)
57
void gradfree(dlink* v)
67 58
{
68 59
  if (gradient_structure::GRAD_LIST)
69 60
  {
......
73 64
    }
74 65
    else
75 66
    {
76
      delete (double_and_int *) v;
77
      v=NULL;
67
      delete (double_and_int*)v;
68
      v = NULL;
78 69
    }
79 70
  }
80 71
}
81

  
82 72
//prevariable::prevariable(const prevariable& t)
83 73
//  {
84 74
//     v=t.v;
85 75
//     (*v).nc++;
86 76
//  }
87

  
88 77
/**
89 78
  Constructor for dvariable object from its base class; deep copy.
90 79
  Allocates memory and assigns value of argument to new object.
91 80
  \param t constant prevariable object
92 81
 */
93 82
dvariable::dvariable(const prevariable& t)
94
    {
95
      v=gradnew();
96
      //(*v).nc=0;
97
      v->x=t.v->x;
98
      gradient_structure::GRAD_STACK1->
99
	 set_gradient_stack(default_evaluation1,&(v->x),&(t.v->x));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff