C++ main module for emicrom Package  1.0
EMM_Tensors.h
Go to the documentation of this file.
1 #ifndef EMM_Tensor_H
2 #define EMM_Tensor_H
3 
4 #include "CORE_Object.h"
5 #include "CORE_Integer.h"
6 #include "CORE_Exception.h"
7 #include "CORE_MorseArray.h"
8 
20 class EMM_Tensors : public CORE_Object {
21 
22 
24 
25  // ATTRIBUTES
26 
27 
28 public:
29 
30 
31 private:
32 
35 
36 
37 protected:
38  // METHODS
39 
40  // CONSTRUCTORS
41 
45  mDimension=3;
46  }
47 
48 
49 
50 
51 
52 
53  // DESTRUCTORS
54 
55 
58  virtual ~EMM_Tensors(void) {
59  }
60 
61 
62 public:
63 
64  // CONSTRUCTORS
65 
66 
67 
68  //operator
69 public:
70 
75  inline const tReal* operator[](const tUIndex& index) const {
76  return mValues[index];
77  }
82  inline tReal* operator[](const tUIndex& index) {
83  return mValues[index];
84  }
85 
86 
87 
88 public:
89 
90  //NEW
91 
95  inline SP::EMM_Tensors NewCopyInstance() const {
96  SP::EMM_Tensors p=NewInstance();
97  p->copy(*this);
98  return p;
99  }
103  virtual SP::EMM_Tensors NewInstance() const=0;
104 
105  //SET methods
106 
107 protected:
111  virtual void copy(const EMM_Tensors& tensors) {
112  mDimension=tensors.getDimension();
113  mValues.copy(tensors.getValues());
114  }
115 
116 public:
120  virtual void setDimension(const tUSInt& dim) {
121  mDimension=dim;
122  }
123 
128  inline void setTensorsNumber(const tUIndex& n,const tUInteger& nPacks) {
129  if (n==0) return;
130 
131  //set the morse array dimension
132  mValues.setSize(n,getTensorSize(),nPacks);
133 
134  }
135 
139  inline void setTensorsNumber(const tUIndex& n) {
140  setTensorsNumber(n,1);
141  //init the indices
142  tUSInt p=getTensorSize();
143  tUIndex *indices=&mValues.getIndices()[0];
144  tUIndex i,index=0;
145  for (i=0;i<=n;i++) {
146  (*indices)=index;
147  //next i
148  index+=p;
149  indices++;
150  }
151  }
152 
156  inline void setUniformTensorsNumber(const tUIndex& n) {
157  if (n==0) return;
158  tUSInt p=getTensorSize();
159  //set the morse array dimension
160  mValues.setUniformSize(n,p);
161 
162  }
163 
166  inline void reset() {
167  mValues.reset();
168  }
175  inline void init(const tUIndex& index,
176  const tReal& v) {
177 
178  tReal *vs=mValues[index];
179  tUSInt n=getTensorSize();
180  if (v==0.) memset(vs,0,n*sizeof(tReal));
181  else {
182  for (tUSInt i=0;i<n;i++) {
183  *vs=v;
184  vs++;
185  }
186  }
187  }
194  inline void init(const tUIndex& index,
195  const vector<tReal>& v) {
196  tReal *vs=mValues[index];
197  tUSInt i,n=getTensorSize();
198  tUSInt nv=v.size();
199  tUSInt m=(nv<n)?nv:n;
200  vector<tReal>::const_iterator iv=v.begin();
201  for (i=0;i<m;i++) {
202  *vs=*iv;
203  vs++;
204  iv++;
205  }
206  if (m<n) memset(vs,0,(n-m)*sizeof(tReal));
207 
208 
209  }
217  inline void init(const tUIndex& index,
218  const tUSInt& nv,
219  const tReal* v) {
220  tReal *vs=mValues[index];
221  tUSInt i,n=getTensorSize();
222  tUSInt m=(nv<n)?nv:n;
223  const tReal *iv=v;
224  for (i=0;i<m;i++) {
225  *vs=*iv;
226  vs++;
227  iv++;
228  }
229  if (m<n) memset(vs,0,(n-m)*sizeof(tReal));
230 
231 
232  }
233 
234 
235  // GET methods
236 public:
237 
246  virtual tULLInt getMemorySize() const {
247  return mValues.getMemorySize();
248  }
252  inline const tUSInt& getDimension() const {
253  return mDimension;
254  }
258  virtual tUSInt getTensorSize() const=0;
259 
263  inline const tUIndex& getTensorsNumber() const {
264  return mValues.getSize();
265  }
266 
270  inline const CORE_RealMorseArray& getValues() const {
271  return mValues;
272  }
277  return mValues;
278  }
279 
280 
281 
284  inline tBoolean isUniform() const {
285  return mValues.isUniform();
286  }
287 
291  inline tBoolean isNull(const tUIndex& i) const {
292  return (mValues.getSize(i)==0);
293  }
297  inline tBoolean isNotNull(const tUIndex& i) const {
298  return (mValues.getSize(i)!=0);
299  }
314  inline tBoolean saveToFile(const tString& fn) const {
315  return mValues.saveToFile(fn);
316  }
331  inline tBoolean loadFromFile(const tString& fn) {
332  return mValues.loadFromFile(fn);
333  }
334 
335 
336 
337  // STRING representation
338  //=======================
339 
343  virtual tString toString() const {
344  return getIdentityString()+":"+mValues.toString();
345  }
346 
347 };
348 
349 #endif
CORE_RealMorseArray mValues
Definition: EMM_Tensors.h:34
SP_OBJECT(EMM_Tensors)
EMM_Tensors()
create a tendor
Definition: EMM_Tensors.h:44
const CORE_UIndexArray & getIndices() const
get the indices of the morse array for reading
Definition: CORE_MorseArray.h:449
void copy(const CORE_MorseArray< Q > &c)
copy the morse array param c: the morse array to copy
Definition: CORE_MorseArray.h:308
CORE_RealMorseArray & getValues()
get the values as a morse array of the tensors
Definition: EMM_Tensors.h:276
void setUniformSize(const tUIndex &n, const tUIndex &ld)
set the morse array to be uniform of size n x ld
Definition: CORE_MorseArray.h:328
tBoolean saveToFile(const tString &fn) const
save the tensor into file
Definition: EMM_Tensors.h:314
#define tUInteger
Definition: types.h:91
virtual SP::EMM_Tensors NewInstance() const =0
create a new instance
virtual void setDimension(const tUSInt &dim)
set the dimension of the tensor
Definition: EMM_Tensors.h:120
SP::EMM_Tensors NewCopyInstance() const
create a new copy instance
Definition: EMM_Tensors.h:95
tBoolean loadFromFile(const tString &fn)
load the morse array from file
Definition: CORE_MorseArray.hpp:74
void init(const tUIndex &index, const vector< tReal > &v)
init the tensor at index to uniform value
Definition: EMM_Tensors.h:194
tBoolean loadFromFile(const tString &fn)
load the tensor from file
Definition: EMM_Tensors.h:331
tBoolean isNotNull(const tUIndex &i) const
Definition: EMM_Tensors.h:297
void reset()
init the array to 0
Definition: CORE_MorseArray.h:381
virtual void copy(const EMM_Tensors &tensors)
copy
Definition: EMM_Tensors.h:111
#define tUSInt
Definition: types.h:28
#define tBoolean
Definition: types.h:139
void setTensorsNumber(const tUIndex &n)
set the tensors number
Definition: EMM_Tensors.h:139
DEFINE_SPTR(EMM_Tensors)
virtual tString toString() const
return the string representation of the class
Definition: EMM_Tensors.h:343
const tReal * operator[](const tUIndex &index) const
get the first tensor values at index in [0,getTensorsNumber()[ for reading only
Definition: EMM_Tensors.h:75
tBoolean saveToFile(const tString &fn) const
save the morse array into file
Definition: CORE_MorseArray.hpp:16
const tUSInt & getDimension() const
get the dimension of the tensor
Definition: EMM_Tensors.h:252
void setUniformTensorsNumber(const tUIndex &n)
set the tensors number : all the tensor are the same
Definition: EMM_Tensors.h:156
tString getIdentityString() const
return the identity string of the object of the form className_at_address
Definition: CORE_Object.h:241
tBoolean isUniform() const
return true if the morse array is unifom
Definition: CORE_MorseArray.h:518
void init(const tUIndex &index, const tUSInt &nv, const tReal *v)
init the tensor at index to uniform value
Definition: EMM_Tensors.h:217
virtual tString toString() const
return the string reprensetaion of the morse array
Definition: CORE_MorseArray.hpp:5
virtual tULLInt getMemorySize() const
return the memory size in byte
Definition: EMM_Tensors.h:246
const tUIndex & getSize() const
get the number of elements of the array
Definition: CORE_MorseArray.h:404
tUSInt mDimension
Definition: EMM_Tensors.h:33
tBoolean isUniform() const
Definition: EMM_Tensors.h:284
virtual tULLInt getMemorySize() const
return the memory size in byte
Definition: CORE_MorseArray.h:396
void init(const tUIndex &index, const tReal &v)
init the tensor at index to uniform value
Definition: EMM_Tensors.h:175
#define tUIndex
Definition: types.h:126
tBoolean isNull(const tUIndex &i) const
Definition: EMM_Tensors.h:291
virtual ~EMM_Tensors(void)
destroy
Definition: EMM_Tensors.h:58
virtual tUSInt getTensorSize() const =0
get the memory size of the storage of each tensor
abstract base class for most classes.
Definition: CORE_Object.h:53
#define tString
Definition: types.h:135
const tUIndex & getTensorsNumber() const
get the number of tensors
Definition: EMM_Tensors.h:263
const CORE_RealMorseArray & getValues() const
get the values as a morse array of the tensors
Definition: EMM_Tensors.h:270
void reset()
reset the values
Definition: EMM_Tensors.h:166
void setTensorsNumber(const tUIndex &n, const tUInteger &nPacks)
set the tensors number
Definition: EMM_Tensors.h:128
tReal * operator[](const tUIndex &index)
get the first tensor values at index in [0,getTensorsNumber()[ for reading only
Definition: EMM_Tensors.h:82
#define tULLInt
Definition: types.h:45
#define tReal
Definition: types.h:118
This class describes a morse array of tensors.
Definition: EMM_Tensors.h:20
void setSize(const tUIndex &n, const tUIndex &m, const tUInteger &p)
set the size of the morse array
Definition: CORE_MorseArray.h:342