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

Legend:
Removed from v.101  
changed lines
  Added in v.102

  ViewVC Help
Powered by ViewVC 1.1.26