My Project
Loading...
Searching...
No Matches
amp.cpp
Go to the documentation of this file.
1#include "svd_si.h"
2#ifdef HAVE_SVD
3
4/************************************************************************
5Storage of mpfr lists
6************************************************************************/
7std::vector< amp::mpfr_record* > _mpfr_storage_v;
8VAR gmp_randstate_t _mpfr_storage_rs;
10
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
38{
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
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/************************************************************************
80Storage 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
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
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
VAR bool _mpfr_storage_init
Definition: amp.cpp:9
std::vector< amp::mpfr_record * > _mpfr_storage_v
Definition: amp.cpp:7
VAR gmp_randstate_t _mpfr_storage_rs
Definition: amp.cpp:8
int p
Definition: cfModGcd.cc:4078
void initialize(int Precision)
Definition: amp.cpp:115
mpfr_record * ref
Definition: amp.h:74
mpfr_reference & operator=(const mpfr_reference &r)
Definition: amp.cpp:94
mpfr_ptr getWritePtr()
Definition: amp.cpp:142
mpfr_srcptr getReadPtr() const
Definition: amp.cpp:134
static gmp_randstate_t * getRandState()
Definition: amp.cpp:37
static void deleteMpfr(mpfr_record *ref)
Definition: amp.cpp:30
static mpfr_record * newMpfr(unsigned int Precision)
Definition: amp.cpp:11
static mpfr_record_ptr & getList(unsigned int Precision)
Definition: amp.cpp:63
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define STATIC_VAR
Definition: globaldefs.h:7
#define VAR
Definition: globaldefs.h:5
lists getList(spectrum &spec)
Definition: ipshell.cc:3396
mpfr_t value
Definition: amp.h:37
unsigned int Precision
Definition: amp.h:36
mpfr_record * next
Definition: amp.h:38
unsigned int refCount
Definition: amp.h:35
#define free
Definition: omAllocFunc.c:14
#define NULL
Definition: omList.c:12