FlopCpp trunk
Loading...
Searching...
No Matches
MP_data.hpp
Go to the documentation of this file.
1// ******************** FlopCpp **********************************************
2// File: MP_data.hpp
3// $Id$
4// Author: Tim Helge Hultberg (thh@mat.ua.pt)
5// Copyright (C) 2003 Tim Helge Hultberg
6// All Rights Reserved.
7// ****************************************************************************
8
9#ifndef _MP_data_hpp_
10#define _MP_data_hpp_
11
12#include <vector>
13#include <string>
14
15#include "MP_index.hpp"
16#include "MP_set.hpp"
17#include "MP_constant.hpp"
18#include "MP_boolean.hpp"
19
20namespace flopc {
21
22 class MP_data;
23
29 class DataRef : public Constant_base, public Functor {
30 public:
32 const MP_index_exp& i1,
33 const MP_index_exp& i2,
34 const MP_index_exp& i3,
35 const MP_index_exp& i4,
36 const MP_index_exp& i5,
37 int s = 0) :
38 D(d),I1(i1),I2(i2),I3(i3),I4(i4),I5(i5),C(0),stochastic(s) {}
39
42 double evaluate() const;
43 int getStage() const;
44 const DataRef& operator=(const DataRef& r);
45 const DataRef& operator=(const Constant& c);
46 void evaluate_lhs(double v) const;
47 void operator()() const;
48 private:
49 MP_data* D;
50 MP_index_exp I1,I2,I3,I4,I5;
51 Constant C;
52 int stochastic;
53 MP_boolean B;
54 };
55
71 class MP_data : public RowMajor, public Functor , public Named {
72 friend class MP_variable;
73 friend class DisplayData;
74 friend class DataRef;
75 friend class MP_model;
76 public:
77 void operator()() const;
79 void initialize(double d) {
80 for (int i=0; i<size(); i++) {
81 v[i] = d;
82 }
83 }
84
88 const MP_set_base &s2 = MP_set::getEmpty(),
89 const MP_set_base &s3 = MP_set::getEmpty(),
90 const MP_set_base &s4 = MP_set::getEmpty(),
91 const MP_set_base &s5 = MP_set::getEmpty()) :
92 RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
93 S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
94 v(new double[size()]), manageData(true)
95 {
96 initialize(0);
97 }
98
102 MP_data(double* value,
103 const MP_set_base &s1 = MP_set::getEmpty(),
104 const MP_set_base &s2 = MP_set::getEmpty(),
105 const MP_set_base &s3 = MP_set::getEmpty(),
106 const MP_set_base &s4 = MP_set::getEmpty(),
107 const MP_set_base &s5 = MP_set::getEmpty()) :
108 RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
109 S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
110 v(value), manageData(false)
111 {
112 }
113
115 if (manageData == true) delete[] v;
117// for (unsigned int i=0; i<myrefs.size(); i++) {
118// cout<<"# "<<i<<" "<<myrefs[i]<<endl;
119// delete myrefs[i]; //Gives segmentation fault. I dont know why!
120// }
121 }
122
124 void value(const double* d) {
125 for (int i=0; i<size(); i++) {
126 v[i] = d[i];
127 }
128 }
129
131 operator double() {
132 return operator()(0);
133 }
134
139 double& operator()(int lcli1, int lcli2=0, int lcli3=0, int lcli4=0, int lcli5=0) {
140 lcli1 = S1.check(lcli1);
141 lcli2 = S2.check(lcli2);
142 lcli3 = S3.check(lcli3);
143 lcli4 = S4.check(lcli4);
144 lcli5 = S5.check(lcli5);
145 int i = f(lcli1,lcli2,lcli3,lcli4,lcli5);
146 if (i == outOfBound) {
147 outOfBoundData = 0;
148 return outOfBoundData;
149 } else {
150 return v[i];
151 }
152 }
153
159 const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
160 const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
161 const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
162 const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
163 const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
164 ) {
165 myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5));
166 return *myrefs.back();
167 }
168
169
171 void display(std::string s = "");
172 protected:
173 std::vector<DataRef*> myrefs;
174 private:
175 MP_data(const MP_data&); // Forbid copy constructor
176 MP_data& operator=(const MP_data&); // Forbid assignment
177
178 static double outOfBoundData;
179
180 MP_index i1,i2,i3,i4,i5;
181 const MP_set_base &S1,&S2,&S3,&S4,&S5;
182 double* v;
183 bool manageData;
184 };
185
187 public:
189 const MP_set_base &s2 = MP_set::getEmpty(),
190 const MP_set_base &s3 = MP_set::getEmpty(),
191 const MP_set_base &s4 = MP_set::getEmpty(),
192 const MP_set_base &s5 = MP_set::getEmpty()) :
193 MP_data(s1,s2,s3,s4,s5) {}
194
195 using flopc::MP_data::operator();
197 const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
198 const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
199 const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
200 const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
201 const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
202 ) {
203 myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5, 1));
204 return *myrefs.back();
205 }
206 };
207
208} // End of namespace flopc
209#endif
friend class Constant
DataRef(MP_data *d, const MP_index_exp &i1, const MP_index_exp &i2, const MP_index_exp &i3, const MP_index_exp &i4, const MP_index_exp &i5, int s=0)
Definition MP_data.hpp:31
double evaluate() const
void operator()() const
void evaluate_lhs(double v) const
int getStage() const
const DataRef & operator=(const DataRef &r)
DataRef & such_that(const MP_boolean &b)
const DataRef & operator=(const Constant &c)
Reference counted class for all "boolean" types of data.
Input data set.
Definition MP_data.hpp:71
void initialize(double d)
similar to value() but copies the same value to all entries.
Definition MP_data.hpp:79
friend class MP_model
Definition MP_data.hpp:75
void operator()() const
friend class DisplayData
Definition MP_data.hpp:73
void value(const double *d)
Used to bind and deep copy data into the MP_data data structure.
Definition MP_data.hpp:124
std::vector< DataRef * > myrefs
Definition MP_data.hpp:173
MP_data(const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
Constructs the MP_data object, and allocates space for data, but does not initialize the data.
Definition MP_data.hpp:87
friend class DataRef
Definition MP_data.hpp:74
MP_data(double *value, const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
Construct the object, and uses the data in the original array (shallow copy)
Definition MP_data.hpp:102
friend class MP_variable
Definition MP_data.hpp:72
void display(std::string s="")
For displaying data in a human readable format.
double & operator()(int lcli1, int lcli2=0, int lcli3=0, int lcli4=0, int lcli5=0)
Looks up the data based on the index values passed in.
Definition MP_data.hpp:139
Representation of an expression involving an index.
Definition MP_index.hpp:145
static const MP_index_exp & getEmpty()
Return the unique empty expression.
Representation of an index.
Definition MP_index.hpp:53
Internal representation of a "set".
Definition MP_set.hpp:28
static MP_set & getEmpty()
gets the distinct 'empty' MP_set.
MP_stochastic_data(const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
Definition MP_data.hpp:188
Utility interface class for adding a string name onto a structure.
int size() const
int f(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
RowMajor(int s1, int s2, int s3, int s4, int s5)
All flopc++ code is contained within the flopc namespace.
Definition flopc.hpp:49
const int outOfBound
Distinct return value on conditions where an index goes out of bounds.