SEP Solver Library  1.0
 All Classes Namespaces Files Functions Variables Typedefs Macros
Vector.h
Go to the documentation of this file.
1 #ifndef VECTOR_H
2 #define VECTOR_H 1
3 #include "Space.h"
4 #include "handleIO.h"
5 #include "inCoreFloat.h"
6 
7 namespace SEP {
8 
9 class Vector: public Writeable {
10  private:
11  Space *sp;
12  dataContainer *d;
13 
14 
15  public:
16  Vector(){sp=NULL;d=NULL;}
18  return d;
19  }
20  Vector(Space *sp1){
21  sp=sp1;
22  d=sp->buildDataContainer();
23  }
24 
26  sp=x->getSpace();
27  d=sp->buildDataContainer();
28  sp->linearCombo(0.,d,1.,x->getDataContainer());
29  }
30 
31 
32 // //Return pointer to data storage (depends on data container type)
33  // void *returnData() const { return d->returnData();}
34 
35  Vector(Space *sp1, const dataContainer &otherContainer){
36  sp=sp1;
37  if (sp->isCompatible(getDataContainer())) {
38  *d = otherContainer;
39  }
40  else {
41  SEPException e;
42  e<<"The data container is not compatible with the space!";
43  throw e;
44  }
45  }
46 
47  virtual ~Vector(){
48  delete d;// delete data and pointer to data
49  d = NULL;
50  }
51 
52  Space *getSpace() const { return sp; }
53 
54  bool inSpace(Space *sp1) const { return (sp==sp1); }
55 
56  bool inSameSpace(const Vector &x) const { return (inSpace(x.sp)); }
57 
59  Vector y(this);
60  return y;
61  }
62 
63  void clone(Vector *in){
64  sp=in->getSpace();
65  d=sp->buildDataContainer();
66  zeroElement();
67  linearCombo( 1.0, *in, 1.0);
68  }
69 
70  void zeroElement() {
71  sp->zeroElement((this->getDataContainer()));
72  }
73 
74  void linearCombo(float a, const Vector &x, float b) {
75  if (inSameSpace(x)){
76  sp->linearCombo(a, (this->getDataContainer()), b, (x.getDataContainer()));
77  }
78  else {
79  SEPException e;
80  e<<"The two vectors you intended to combine are not in the same space!";
81  throw e;
82  }
83  }
84 
85  double innerProd(const Vector &x) {
86  if (inSameSpace(x)){
87  double ip = sp->innerProd((x.getDataContainer()), (this->getDataContainer()));
88  return ip;
89  }
90  else {
91  SEPException e;
92  e<<"The two vectors you are trying to take the inner product of are not in the same space!";
93  throw e;
94  }
95  }
96 
97  void scale(float a) {
98 
100  sp->scale(a, x);
101  }
102 
103  void scale(float a, dataContainer *ax) { sp->scale(a, (this->getDataContainer()), ax); }
104 
105  void random() { sp->random(this->getDataContainer()); }
106 
107 
108 
109 /*Add back later
110  void scale(float a, const Vector &ax) {
111  if (inSameSpace(ax))
112  sp->scale(a, (this->getDataContainer()), (ax.getDataContainer()));
113  else {
114  SEPException e;
115  e<<"The output and input vectors are not in the same space!";
116  throw e;
117  }
118  }
119  */
120 
121  void addInv() { sp->addInv((this->getDataContainer())); }
122 
123  void addInv(const Vector &xNeg) {
124  if (inSameSpace(xNeg))
125  sp->addInv((this->getDataContainer()), (xNeg.getDataContainer()));
126  else {
127  SEPException e;
128  e<<"The output and input vectors are not in the same space!";
129  throw e;
130  }
131  }
132 };
133 
134 
135 
136 class MultiVector: public Vector{
137  private:
138  MultiSpace *sp;
139  dataContainer *d1, *d2;
140  public:
143  Space *sp1 = v1->getSpace();
144  Space *sp2 = v2->getSpace();
145  this->sp = new MultiSpace(sp1, sp2);
146  d1 = sp1->buildDataContainer(); // ****should this actually copy vectors?
147  sp1->linearCombo(float(0), d1, float(1), v1->getDataContainer());
148  d2 = sp2->buildDataContainer();
149  sp2->linearCombo(float(0), d2, float(1), v2->getDataContainer());
150  };
152  // ******compatibility checks etc... then create multivector****
153  };
155  Space *sp1=s1;
156  this->d1=sp1->buildDataContainer();
157  Space *sp2=s2;
158  this->d2=sp2->buildDataContainer();
159  };
161  sp = m-> getSpace();
162  Space *sp1 = sp->getSpace1();
163  d1 = sp1->buildDataContainer();
164  sp1->linearCombo(float(0),d1,float(1),m->getDataContainer1());
165  Space *sp2 = sp->getSpace2();
166  d2 = sp2->buildDataContainer();
167  sp2->linearCombo(float(0),d2,float(1),m->getDataContainer2());
168  };
169  MultiVector(Space *s1, const dataContainer &otherContainer1, Space *s2, const dataContainer &otherContainer2){
170  Space *sp1 = s1;
171  if(sp1->isCompatible(getDataContainer())){
172  *d1 = otherContainer1;
173  } else{
174  SEPException e;
175  e<<"The data container is not compatible with the space!";
176  throw e;
177  }
178  Space *sp2 = s2;
179  if(sp2->isCompatible(getDataContainer())){
180  *d2 = otherContainer2;
181  } else{
182  SEPException e;
183  e<<"The data container is not compatible with the space!";
184  throw e;
185  }
186  };
187  virtual ~MultiVector() {};
189  MultiDataContainer *temp=new MultiDataContainer(d1, d2);
190  return temp;
191  };
192  dataContainer *getDataContainer1() const{ return d1;}
193  dataContainer *getDataContainer2() const{ return d2;}
194  MultiSpace *getSpace() const{ return sp;}
195  bool inSpace (const MultiSpace *m) const{};
196  bool inSameSpace(const MultiVector &x) const{ //if not a const this compiles, or add const{} to inSpace
197  const MultiSpace *multsp = x.getSpace();
198  return (inSpace(multsp));
199  //std::cout << "WARNING: Called inSameSpace on MultiVector, needs implementation\n";
200  //return true; // **********************just to compile code*****
201  };
202  MultiVector clone(void);
203  void zeroElement(void);
204  void linearCombo(float a, const MultiVector &x, float b);
205  double innerProd(const MultiVector &x); //inherit from vector
206  void scale(float a);
207 
208 };
209 
210 };
211 #endif
212