Loading...
Searching...
No Matches
amp.cpp
Go to the documentation of this file.
#include "svd_si.h"
#ifdef HAVE_SVD
/************************************************************************
Storage of mpfr lists
************************************************************************/
std::vector< amp::mpfr_record* > _mpfr_storage_v;
VAR gmp_randstate_t _mpfr_storage_rs;
VAR bool _mpfr_storage_init = false;
amp::mpfr_record* amp::mpfr_storage::newMpfr(unsigned int Precision)
{
amp::mpfr_record_ptr &lst = getList(Precision);
if( lst==NULL )
{
amp::mpfr_record *rec = new amp::mpfr_record;
rec->Precision = Precision;
rec->refCount = 0;
mpfr_init2(rec->value, Precision);
rec->next = lst;
lst = rec;
}
amp::mpfr_record *p = lst;
p->refCount = 1;
lst = lst->next;
return p;
}
void amp::mpfr_storage::deleteMpfr(amp::mpfr_record* ref)
{
amp::mpfr_record_ptr &lst = getList(ref->Precision);
ref->next = lst;
lst = ref;
}
gmp_randstate_t* amp::mpfr_storage::getRandState()
{
if( !_mpfr_storage_init )
{
time_t _timer;
gmp_randinit_default(_mpfr_storage_rs);
gmp_randseed_ui(_mpfr_storage_rs, (unsigned long int)(time(&_timer)));
_mpfr_storage_init = true;
}
return &_mpfr_storage_rs;
}
/*amp::mpfr_storage::clearStorage()
{
unsigned int i;
amp::mpfr_record *p;
for(i=0; i<v.size(); i++)
while( v[i]!=NULL )
{
p = _mpfr_storage_v[i]->next;
mpfr_clear(_mpfr_storage_v[i]->value);
delete _mpfr_storage_v[i];
_mpfr_storage_v[i] = p;
}
}*/
amp::mpfr_record_ptr& amp::mpfr_storage::getList(unsigned int Precision)
{
static amp::mpfr_record_ptr tmp = NULL;
STATIC_VAR int lastPrec = -1;
static amp::mpfr_record_ptr &lastList = tmp;
if( lastPrec!=Precision )
{
while( _mpfr_storage_v.size()<Precision+1 )
_mpfr_storage_v.push_back(NULL);
lastPrec = (int)Precision;
lastList = _mpfr_storage_v[Precision];
}
return lastList;
}
/************************************************************************
Storage of mpfr lists
************************************************************************/
amp::mpfr_reference::mpfr_reference()
{
ref = NULL;
}
amp::mpfr_reference::mpfr_reference(const amp::mpfr_reference& r)
{
ref = r.ref;
if( ref!=NULL )
ref->refCount++;
}
amp::mpfr_reference& amp::mpfr_reference::operator= (
const amp::mpfr_reference &r)
{
if ( &r==this )
return *this;
if ( ref==r.ref )
return *this;
if( ref!=NULL )
free();
ref = r.ref;
if( ref!=NULL )
ref->refCount++;
return *this;
}
amp::mpfr_reference::~mpfr_reference()
{
if( ref!=NULL )
free();
}
void amp::mpfr_reference::initialize(int Precision)
{
if( ref!=NULL )
free();
ref = amp::mpfr_storage::newMpfr(Precision);
ref->refCount = 1;
}
void amp::mpfr_reference::free()
{
if( ref==NULL )
//throw amp::internalError();
{WerrorS("internalError");return;}
ref->refCount--;
if( ref->refCount==0 )
amp::mpfr_storage::deleteMpfr(ref);
ref = NULL;
}
mpfr_srcptr amp::mpfr_reference::getReadPtr() const
{
if( ref==NULL )
//throw amp::internalError();
{WerrorS("internalError");return NULL;}
return ref->value;
}
mpfr_ptr amp::mpfr_reference::getWritePtr()
{
if( ref==NULL )
//throw amp::internalError();
{WerrorS("internalError");return NULL;}
if( ref->refCount==1 )
return ref->value;
amp::mpfr_record *newref = amp::mpfr_storage::newMpfr(ref->Precision);
mpfr_set(newref->value, ref->value, GMP_RNDN);
free();
ref = newref;
return ref->value;
}
#endif
_mpfr_storage_init
VAR bool _mpfr_storage_init
Definition amp.cpp:9
_mpfr_storage_v
std::vector< amp::mpfr_record * > _mpfr_storage_v
Definition amp.cpp:7
_mpfr_storage_rs
VAR gmp_randstate_t _mpfr_storage_rs
Definition amp.cpp:8
p
int p
Definition cfModGcd.cc:4086
amp::mpfr_reference
Definition amp.h:61
amp::mpfr_reference::initialize
void initialize(int Precision)
Definition amp.cpp:115
amp::mpfr_reference::mpfr_reference
mpfr_reference()
Definition amp.cpp:82
amp::mpfr_reference::ref
mpfr_record * ref
Definition amp.h:74
amp::mpfr_reference::operator=
mpfr_reference & operator=(const mpfr_reference &r)
Definition amp.cpp:94
amp::mpfr_reference::getWritePtr
mpfr_ptr getWritePtr()
Definition amp.cpp:142
amp::mpfr_reference::free
void free()
Definition amp.cpp:123
amp::mpfr_reference::~mpfr_reference
~mpfr_reference()
Definition amp.cpp:109
amp::mpfr_reference::getReadPtr
mpfr_srcptr getReadPtr() const
Definition amp.cpp:134
amp::mpfr_storage::getRandState
static gmp_randstate_t * getRandState()
Definition amp.cpp:37
amp::mpfr_storage::deleteMpfr
static void deleteMpfr(mpfr_record *ref)
Definition amp.cpp:30
amp::mpfr_storage::newMpfr
static mpfr_record * newMpfr(unsigned int Precision)
Definition amp.cpp:11
amp::mpfr_storage::getList
static mpfr_record_ptr & getList(unsigned int Precision)
Definition amp.cpp:63
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
STATIC_VAR
#define STATIC_VAR
Definition globaldefs.h:7
VAR
#define VAR
Definition globaldefs.h:5
getList
lists getList(spectrum &spec)
Definition ipshell.cc:3398
amp::mpfr_record::value
mpfr_t value
Definition amp.h:37
amp::mpfr_record::Precision
unsigned int Precision
Definition amp.h:36
amp::mpfr_record_ptr
mpfr_record * mpfr_record_ptr
Definition amp.h:41
amp::mpfr_record::next
mpfr_record * next
Definition amp.h:38
amp::mpfr_record::refCount
unsigned int refCount
Definition amp.h:35
amp::mpfr_record
Definition amp.h:34
free
#define free
Definition omAllocFunc.c:14
NULL
#define NULL
Definition omList.c:12
svd_si.h