/[escript]/branches/lapack2681/escript/src/DataConstant.cpp
ViewVC logotype

Diff of /branches/lapack2681/escript/src/DataConstant.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC
# Line 1  Line 1 
 //$Id$  
1  /*  /*
2   ******************************************************************************   ******************************************************************************
3   *                                                                            *   *                                                                            *
# Line 20  Line 19 
19  #include <iostream>  #include <iostream>
20  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
21    
22    
23  using namespace std;  using namespace std;
24    
25  namespace escript {  namespace escript {
26    
27  DataConstant::DataConstant(const boost::python::numeric::array& value,    DataConstant::DataConstant(const boost::python::numeric::array& value, const FunctionSpace& what): DataAbstract(what)
28                             const FunctionSpace& what)    {
29    : DataAbstract(what)      //cout << "Calling DataConstant constructor 1." << endl;
30  {      DataArray temp(value);
31    DataArray temp(value);      //
32    //      // copy the data in the correct format
33    // copy the data in the correct format      m_data=temp.getData();
34    m_data=temp.getData();      DataArrayView tempView(m_data,temp.getView().getShape());
35    DataArrayView tempView(m_data,temp.getView().getShape());      //
36    //      // copy the view of the data
37    // copy the view of the data      setPointDataView(tempView);
38    setPointDataView(tempView);    }
39  }  
40      DataConstant::DataConstant(const DataArrayView& value, const FunctionSpace& what): DataAbstract(what)
41  DataConstant::DataConstant(const DataArrayView& value,    {
42                             const FunctionSpace& what)      //cout << "Calling DataConstant constructor 2." << endl;
43    : DataAbstract(what)      //
44  {      // copy the data in the correct format
45    //      m_data=value.getData();
46    // copy the data in the correct format      DataArrayView tempView(m_data,value.getShape());
47    m_data=value.getData();      //
48    DataArrayView tempView(m_data,value.getShape());      // copy the view of the data
49    //      setPointDataView(tempView);
50    // copy the view of the data    }
51    setPointDataView(tempView);  
52  }    DataConstant::DataConstant(const DataConstant& other): DataAbstract(other.getFunctionSpace()), m_data(other.m_data)
53      {
54  DataConstant::DataConstant(const DataConstant& other)      //cout << "Calling DataConstant copy constructor." << endl;
55    : DataAbstract(other.getFunctionSpace())      //
56  {      DataArrayView tempView(m_data,other.getPointDataView().getShape());
57    //      //
58    // copy the data in the correct format      // copy the view of the data
59    m_data=other.m_data;      setPointDataView(tempView);
60    DataArrayView tempView(m_data,other.getPointDataView().getShape());    }
61    //  
62    // copy the view of the data    DataConstant::DataConstant(const DataConstant& other, const DataArrayView::RegionType& region): DataAbstract(other.getFunctionSpace())
63    setPointDataView(tempView);    {
64  }      //cout << "Calling DataConstant slice constructor." << endl;
65        //
66  DataConstant::DataConstant(const DataConstant& other,      //
67                             const DataArrayView::RegionType& region)      // get the shape of the slice
68    : DataAbstract(other.getFunctionSpace())      DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
69  {      //
70    //      // allocate space for this DataConstant
71    // get the shape of the slice to copy from      m_data.resize(DataArrayView::noValues(shape));
72    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));      DataArrayView tempView(m_data,shape);
73    //      tempView.copySlice(other.getPointDataView(),region);
74    // allocate space for this new DataConstant's data      //
75    m_data.resize(DataArrayView::noValues(shape));      // copy the view of the data
76    //      setPointDataView(tempView);
77    // create a view of the data with the correct shape    }
78    DataArrayView tempView(m_data,shape);  
79    // copy the data from the slice to the temp view    string DataConstant::toString() const
80    tempView.copySlice(other.getPointDataView(),region);    {
81    //      return getPointDataView().toString("");
82    // store the temp view of the data in this object    }
83    setPointDataView(tempView);  
84  }    DataArrayView::ValueType::size_type DataConstant::getPointOffset(int sampleNo, int dataPointNo) const
85      {
86  string      EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
87  DataConstant::toString() const             "Invalid index, sampleNo: " << sampleNo
88  {             << " dataPointNo: " << dataPointNo);
89    return getPointDataView().toString("");      return 0;
90  }    }
91    
92  DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type DataConstant::getLength() const
93  DataConstant::getPointOffset(int sampleNo,    {
94                               int dataPointNo) const      return m_data.size();
95  {    }
96    EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),  
97                "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);    DataArrayView DataConstant::getDataPoint(int sampleNo, int dataPointNo)
98    return 0;    {
99  }      EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),
100               "Invalid index, sampleNo: " << sampleNo
101  DataArrayView::ValueType::size_type             << " dataPointNo: " << dataPointNo);
102  DataConstant::getLength() const      //
103  {      // Whatever the coord's always return the same value
104    return m_data.size();      return getPointDataView();
105  }    }
   
 DataArrayView  
 DataConstant::getDataPoint(int sampleNo,  
                            int dataPointNo)  
 {  
   EsysAssert((validSamplePointNo(dataPointNo) && validSampleNo(sampleNo)),  
              "Invalid index, sampleNo: " << sampleNo << " dataPointNo: " << dataPointNo);  
   //  
   // Whatever the coord's always return the same value as this is constant data.  
   return getPointDataView();  
 }  
106        
107  DataAbstract*    DataAbstract* DataConstant::getSlice(const DataArrayView::RegionType& region) const
108  DataConstant::getSlice(const DataArrayView::RegionType& region) const    {
109  {      return new DataConstant(*this,region);
110    return new DataConstant(*this,region);    }
111  }  
112      void DataConstant::setSlice(const DataAbstract* value, const DataArrayView::RegionType& region)
113  void    {
114  DataConstant::setSlice(const DataAbstract* value,      const DataConstant* tempDataConst=dynamic_cast<const DataConstant*>(value);
115                         const DataArrayView::RegionType& region)      if (tempDataConst==0)
116  {      {
117    const DataConstant* tempDataConst=dynamic_cast<const DataConstant*>(value);        throw DataException("Programming error - casting to DataConstant.");
118    if (tempDataConst==0) {      }
119      throw DataException("Programming error - casting to DataConstant.");      getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region);
120    }    }
121    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region);  
122  }    void DataConstant::reshapeDataPoint(const DataArrayView::ShapeType& shape)
123      {
124  void      //
125  DataConstant::reshapeDataPoint(const DataArrayView::ShapeType& shape)      // reshape a rank zero data point
126  {      if (getPointDataView().getRank()!=0) {
127    if (getPointDataView().getRank()!=0) {        stringstream temp;
128      stringstream temp;        temp << "Error - Can only reshape Data with data points of rank 0. "
129      temp << "Error - Can only reshape Data with data points of rank 0. "         << "This Data has data points with rank: "
130           << "This Data has data points with rank: " << getPointDataView().getRank();         << getPointDataView().getRank();
131      throw DataException(temp.str());        throw DataException(temp.str());
132    }      }
133    m_data.resize(DataArrayView::noValues(shape),getPointDataView()());      m_data.resize(DataArrayView::noValues(shape),getPointDataView()());
134    DataArrayView newView(m_data,shape);      DataArrayView newView(m_data,shape);
135    setPointDataView(newView);      setPointDataView(newView);
136  }    }
137    
138  }  // end of namespace  }  // end of namespace
139    
140    
141    
142    

Legend:
Removed from v.97  
changed lines
  Added in v.100

  ViewVC Help
Powered by ViewVC 1.1.26