MP_data.cpp

Go to the documentation of this file.
00001 // ******************** FlopCpp **********************************************
00002 // File: MP_data.cpp
00003 // $Id$
00004 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
00005 // Copyright (C) 2003 Tim Helge Hultberg
00006 // All Rights Reserved.
00007 //****************************************************************************
00008 
00009 #include <iostream>
00010 
00011 #include "MP_data.hpp"
00012 #include "MP_domain.hpp" 
00013 #include "MP_index.hpp" 
00014 #include "MP_set.hpp" 
00015 #include "MP_constant.hpp" 
00016 #include "MP_expression.hpp" 
00017 
00018 using namespace flopc;
00019 using namespace std;
00020 
00021 double MP_data::outOfBoundData = 0;
00022 
00023 const DataRef& DataRef::operator=(const Constant& c) {
00024     C = c;
00025     ((D->S1(I1)*D->S2(I2)*D->S3(I3)*D->S4(I4)*D->S5(I5)).such_that(B)).Forall(this);
00026     return *this;;
00027 }
00028 
00029 const DataRef& DataRef::operator=(const DataRef& r) { 
00030     return operator=(Constant(const_cast<DataRef*>(&r)));
00031 }
00032 
00033 void DataRef::operator()() const {
00034     evaluate_lhs(C->evaluate());
00035 }
00036 
00037 DataRef& DataRef::such_that(const MP_boolean& b) {
00038     B = b;
00039     return *this;
00040 }
00041 
00042 
00043 double DataRef::evaluate() const {
00044     int i1 = D->S1.check(I1->evaluate());
00045     int i2 = D->S2.check(I2->evaluate());
00046     int i3 = D->S3.check(I3->evaluate());
00047     int i4 = D->S4.check(I4->evaluate());
00048     int i5 = D->S5.check(I5->evaluate());
00049 
00050     int i = D->f(i1,i2,i3,i4,i5);
00051     if ( i ==  outOfBound ) {
00052         return 0;
00053     } else {
00054         return D->v[i];
00055     }
00056 }
00057 
00058 
00059 
00060 int DataRef::getStage() const {
00061     int i1 = D->S1.checkStage(I1->evaluate());
00062     int i2 = D->S2.checkStage(I2->evaluate());
00063     int i3 = D->S3.checkStage(I3->evaluate());
00064     int i4 = D->S4.checkStage(I4->evaluate());
00065     int i5 = D->S5.checkStage(I5->evaluate());
00066 
00067     int stage = 0;
00068     if (i1>stage) stage = i1;
00069     if (i2>stage) stage = i2;
00070     if (i3>stage) stage = i3;
00071     if (i4>stage) stage = i4;
00072     if (i5>stage) stage = i5;
00073 
00074     // might need to add outofbound check here
00075     return stage+stochastic; 
00076 }
00077 
00078 
00079 void DataRef::evaluate_lhs(double v) const {
00080     int i1 = D->S1.check(I1->evaluate());
00081     int i2 = D->S2.check(I2->evaluate());
00082     int i3 = D->S3.check(I3->evaluate());
00083     int i4 = D->S4.check(I4->evaluate());
00084     int i5 = D->S5.check(I5->evaluate());
00085 
00086     int i = D->f(i1,i2,i3,i4,i5);
00087     if (i != outOfBound) {
00088         D->v[i] = v;
00089     }
00090 }
00091 
00092 void MP_data::operator()() const {
00093     if (&S1!=&MP_set::getEmpty()) cout << i1.evaluate() << " ";
00094     if (&S2!=&MP_set::getEmpty()) cout << i2.evaluate() << " ";
00095     if (&S3!=&MP_set::getEmpty()) cout << i3.evaluate() << " ";
00096     if (&S4!=&MP_set::getEmpty()) cout << i4.evaluate() << " ";
00097     if (&S5!=&MP_set::getEmpty()) cout << i5.evaluate() << " ";
00098     cout<<"  "<<v[f(i1.evaluate(),i2.evaluate(),i3.evaluate(),
00099                     i4.evaluate(),i5.evaluate())] << endl;
00100 }
00101 
00102 void MP_data::display(string s) {
00103     cout<<s<<endl;
00104     ((S1)(i1)*(S2)(i2)*(S3)(i3)*(S4)(i4)*(S5)(i5)).Forall(this);
00105 }

Generated on Sun Nov 6 03:14:50 2011 for FLOPC++ by  doxygen 1.4.7