1 #ifndef CORE_MorseArray_HPP 2 #define CORE_MorseArray_HPP 10 ret+=
"Values:"+mValues.toString()+
"\n";
11 ret+=
"Indices:"+mIndices->toString()+
"\n";
19 ofstream f(fileName.c_str(),ios::out);
22 f <<
"# save a morse array \n";
23 f <<
"# M is the number of element \n";
24 f <<
"# P: is the max number of values at each element \n";
25 f<< mSize<<
"\t"<<mLD<<
"\n";
26 f <<
"# U is 1: if the tensor is uniform over the domain, 0: otherwise \n";
27 f <<((
tUSInt)!mIncI)<<
"\n";
28 f <<
"# M[i][0] M[i][1] .... M[i][d] with d< P and i in [0,getSize()[ and line may be empty for no data on element i \n";
32 const tUIndex *k0=&(*mIndices.get())[0];
37 const T* Mi=&mValues[0];
77 ifstream f(fileName.c_str(),ios::in);
100 tUSInt nLinesBeforeData=0;
101 tUSInt nMaxLinesBeforeData=10;
112 mIsIndicesReferenced=
false;
119 while ( (!f.eof()) && ((mSize==0) || (nDataRead<mSize)) ) {
126 tokenizer->setString(line);
129 iComment=tokenizer->getString().find(
"#");
130 if (iComment!=tString::npos) {
133 if (iComment==0)
continue;
136 tokenizer->setString(tokenizer->getString().substr(0,iComment));
143 tokenizer->tokenize();
146 nTokens=tokenizer->getTokensNumber();
153 if ((mSize==0) || (mLD==0)) {
157 mValues.setSize(mSize*mLD);
158 mIndices->setSize(mSize+1);
160 indices=&(*mIndices.get())[0];
165 if (nLinesBeforeData>nMaxLinesBeforeData) {
167 cout <<
"warning : no data in file "<<fileName<<
"\n";
175 if (!isUniformRead) {
179 if (mIncI==0) mIsConstant=
true;
182 if (nLinesBeforeData>nMaxLinesBeforeData) {
184 cout <<
"warning : no data in file "<<fileName<<
"\n";
202 for (i=0;i<nTokens;i++) {
213 mIndices->setSize(2);
226 "CORE_MorseArray::loadFromFile("+fileName+
")",
227 "impossible to open file");
238 tUIndex *I=&(*mIndices.get())[0];
241 const T* W=&mValues[0];
251 for (i=0;i<mSize;i++) {
299 const tUIndex *I=&(*mIndices.get())[i];
300 const T *Vi,*V=&mValues[*I];
303 const T *Ri,*R=&mValues[0];
329 if (fabs((*Vi)-(*Ri))>eps) {
348 mIndices->setSize(2);
349 mValues.setSize(mLD);
352 mIndices->fitToSize();
392 for (subsetId=0;subsetId<nSubsets;subsetId++) {
395 start=subsetId*N/nSubsets;
398 end=(subsetId+1)*N/nSubsets;
403 Ip=&indices[start+subsetId];
408 for (i=start;i<end;i++) {
463 typename vector<CORE_Array<T>* >::const_iterator iArray;
470 iArray=arrays.begin();
471 while(iArray!=arrays.end()) {
501 tUIndex s,nArrays=arrays.size();
503 const T* Aps[nArrays];
507 iArray=arrays.begin();
508 if (iArray==arrays.end()) {
514 while(iArray!=arrays.end()) {
532 for (subsetId=0;subsetId<nSubsets;subsetId++) {
535 start=subsetId*N/nSubsets;
538 end=(subsetId+1)*N/nSubsets;
544 Ip=&indices[start+subsetId];
547 iArray=arrays.begin();
549 while(iArray!=arrays.end()) {
550 Aps[s]=&(*(*iArray))[start*ld];
555 for (i=start;i<end;i++) {
568 for (s=0;s<nArrays;s++) {
592 iArray=arrays.begin();
593 while(iArray!=arrays.end()) {
const tUIndex & getSize() const
return the size of the array for reading
Definition: CORE_Array.h:1018
static tLLInt parseInt(const tString &str)
return the integer associated to the string
Definition: CORE_Integer.cpp:102
static boost::shared_ptr< CORE_Array< tUIndex > > New()
return a CORE_Array shared pointer
Definition: CORE_Array.h:120
#define tUInteger
Definition: types.h:91
tBoolean loadFromFile(const tString &fn)
load the morse array from file
Definition: CORE_MorseArray.hpp:74
static tLDouble parseReal(const tString &str)
return the real associated to the string
Definition: CORE_Real.h:201
#define tUSInt
Definition: types.h:28
#define tBoolean
Definition: types.h:139
void setSize(const tUIndex &n)
set the size
Definition: CORE_Array.h:292
tBoolean uniformize()
uniformize the array
Definition: CORE_MorseArray.h:558
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
#define null
Definition: types.h:144
tBoolean saveToFile(const tString &fn) const
save the morse array into file
Definition: CORE_MorseArray.hpp:16
static void MergeMorseArrays(const tUInteger &nSubsets, CORE_UIndexArray &indices, const tUIndex &ld, const vector< CORE_Array< T > * > &arrays)
merge morse arrays
Definition: CORE_MorseArray.hpp:459
#define tIndex
Definition: types.h:129
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
void removeValue(const T &v)
remove the value
Definition: CORE_MorseArray.hpp:237
virtual tString toString() const
return the string reprensetaion of the morse array
Definition: CORE_MorseArray.hpp:5
virtual void fitToSize()
fit the array alocation exactly to size fit the allocation of the array to its size ...
Definition: CORE_Array.hpp:128
#define tUIndex
Definition: types.h:126
#define tString
Definition: types.h:135
static SP::CORE_String New()
create a class String
Definition: CORE_String.h:96
#define tReal
Definition: types.h:118
static void MergeMorseArray(const tUInteger &P, CORE_UIndexArray &indices, const tUIndex &ld, CORE_Array< T > &array)
merge morse arrays
Definition: CORE_MorseArray.hpp:358