My Project  debian-1:4.1.2-p1+ds-2
amp.cpp
Go to the documentation of this file.
1 #include "svd_si.h"
2 #ifdef HAVE_SVD
3 
4 /************************************************************************
5 Storage of mpfr lists
6 ************************************************************************/
7 std::vector< amp::mpfr_record* > _mpfr_storage_v;
8 VAR gmp_randstate_t _mpfr_storage_rs;
9 VAR bool _mpfr_storage_init = false;
10 
11 amp::mpfr_record* amp::mpfr_storage::newMpfr(unsigned int Precision)
12 {
13  amp::mpfr_record_ptr &lst = getList(Precision);
14  if( lst==NULL )
15  {
17  rec->Precision = Precision;
18  rec->refCount = 0;
19  mpfr_init2(rec->value, Precision);
20  rec->next = lst;
21  lst = rec;
22  }
23 
24  amp::mpfr_record *p = lst;
25  p->refCount = 1;
26  lst = lst->next;
27  return p;
28 }
29 
31 {
33  ref->next = lst;
34  lst = ref;
35 }
36 
37 gmp_randstate_t* amp::mpfr_storage::getRandState()
38 {
39  if( !_mpfr_storage_init )
40  {
41  time_t _timer;
42  gmp_randinit_default(_mpfr_storage_rs);
43  gmp_randseed_ui(_mpfr_storage_rs, (unsigned long int)(time(&_timer)));
44  _mpfr_storage_init = true;
45  }
46  return &_mpfr_storage_rs;
47 }
48 
49 /*amp::mpfr_storage::clearStorage()
50 {
51  unsigned int i;
52  amp::mpfr_record *p;
53  for(i=0; i<v.size(); i++)
54  while( v[i]!=NULL )
55  {
56  p = _mpfr_storage_v[i]->next;
57  mpfr_clear(_mpfr_storage_v[i]->value);
58  delete _mpfr_storage_v[i];
59  _mpfr_storage_v[i] = p;
60  }
61 }*/
62 
63 amp::mpfr_record_ptr& amp::mpfr_storage::getList(unsigned int Precision)
64 {
65  static amp::mpfr_record_ptr tmp = NULL;
66  STATIC_VAR int lastPrec = -1;
67  static amp::mpfr_record_ptr &lastList = tmp;
68  if( lastPrec!=Precision )
69  {
70  while( _mpfr_storage_v.size()<Precision+1 )
71  _mpfr_storage_v.push_back(NULL);
72  lastPrec = (int)Precision;
73  lastList = _mpfr_storage_v[Precision];
74  }
75  return lastList;
76 }
77 
78 
79 /************************************************************************
80 Storage of mpfr lists
81 ************************************************************************/
83 {
84  ref = NULL;
85 }
86 
88 {
89  ref = r.ref;
90  if( ref!=NULL )
91  ref->refCount++;
92 }
93 
95  const amp::mpfr_reference &r)
96 {
97  if ( &r==this )
98  return *this;
99  if ( ref==r.ref )
100  return *this;
101  if( ref!=NULL )
102  free();
103  ref = r.ref;
104  if( ref!=NULL )
105  ref->refCount++;
106  return *this;
107 }
108 
110 {
111  if( ref!=NULL )
112  free();
113 }
114 
115 void amp::mpfr_reference::initialize(int Precision)
116 {
117  if( ref!=NULL )
118  free();
119  ref = amp::mpfr_storage::newMpfr(Precision);
120  ref->refCount = 1;
121 }
122 
124 {
125  if( ref==NULL )
126  //throw amp::internalError();
127  {WerrorS("internalError");return;}
128  ref->refCount--;
129  if( ref->refCount==0 )
131  ref = NULL;
132 }
133 
134 mpfr_srcptr amp::mpfr_reference::getReadPtr() const
135 {
136  if( ref==NULL )
137  //throw amp::internalError();
138  {WerrorS("internalError");return NULL;}
139  return ref->value;
140 }
141 
143 {
144  if( ref==NULL )
145  //throw amp::internalError();
146  {WerrorS("internalError");return NULL;}
147  if( ref->refCount==1 )
148  return ref->value;
149 
150  amp::mpfr_record *newref = amp::mpfr_storage::newMpfr(ref->Precision);
151  mpfr_set(newref->value, ref->value, GMP_RNDN);
152 
153  free();
154  ref = newref;
155  return ref->value;
156 }
157 #endif
amp::mpfr_reference::initialize
void initialize(int Precision)
Definition: amp.cpp:113
_mpfr_storage_rs
VAR gmp_randstate_t _mpfr_storage_rs
Definition: amp.cpp:7
svd_si.h
STATIC_VAR
#define STATIC_VAR
Definition: globaldefs.h:7
amp::mpfr_storage::getRandState
static gmp_randstate_t * getRandState()
Definition: amp.cpp:36
amp::mpfr_reference::mpfr_reference
mpfr_reference()
Definition: amp.cpp:80
amp::mpfr_record::refCount
unsigned int refCount
Definition: amp.h:35
_mpfr_storage_init
VAR bool _mpfr_storage_init
Definition: amp.cpp:8
amp::mpfr_record::next
mpfr_record * next
Definition: amp.h:38
VAR
#define VAR
Definition: globaldefs.h:5
amp::mpfr_reference::free
void free()
Definition: amp.cpp:121
amp::mpfr_reference::ref
mpfr_record * ref
Definition: amp.h:74
free
#define free
Definition: omAllocFunc.c:13
amp::mpfr_reference::getWritePtr
mpfr_ptr getWritePtr()
Definition: amp.cpp:140
amp::mpfr_reference::~mpfr_reference
~mpfr_reference()
Definition: amp.cpp:107
amp::mpfr_reference::operator=
mpfr_reference & operator=(const mpfr_reference &r)
Definition: amp.cpp:92
amp::mpfr_reference
Definition: amp.h:60
amp::mpfr_record::Precision
unsigned int Precision
Definition: amp.h:36
_mpfr_storage_v
std::vector< amp::mpfr_record * > _mpfr_storage_v
Definition: amp.cpp:6
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
NULL
#define NULL
Definition: omList.c:11
amp::mpfr_record
Definition: amp.h:33
amp::mpfr_storage::newMpfr
static mpfr_record * newMpfr(unsigned int Precision)
Definition: amp.cpp:10
p
int p
Definition: cfModGcd.cc:4019
amp::mpfr_reference::getReadPtr
mpfr_srcptr getReadPtr() const
Definition: amp.cpp:132
amp::mpfr_record::value
mpfr_t value
Definition: amp.h:37
amp::mpfr_storage::deleteMpfr
static void deleteMpfr(mpfr_record *ref)
Definition: amp.cpp:29
getList
lists getList(spectrum &spec)
Definition: ipshell.cc:3369
amp::mpfr_storage::getList
static mpfr_record_ptr & getList(unsigned int Precision)
Definition: amp.cpp:62