/[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 2105 by jfenwick, Fri Nov 28 01:52:12 2008 UTC revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 UTC
# Line 29  Line 29 
29  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
30  #include "DataMaths.h"  #include "DataMaths.h"
31    
32    // #define CHECK_FOR_EX_WRITE if (!checkNoSharing()) {throw DataException("Attempt to modify shared object");}
33    
34    #define CHECK_FOR_EX_WRITE if (!checkNoSharing()) {std::ostringstream ss; ss << " Attempt to modify shared object. line " << __LINE__ << " of " << __FILE__; ss << m_owners.size(); cerr << ss << endl; /* *((int*)0)=17; */throw DataException(ss.str());}
35    
36  using namespace std;  using namespace std;
37  using namespace boost::python;  using namespace boost::python;
38    
39  namespace escript {  namespace escript {
40    
41  DataConstant::DataConstant(const boost::python::numeric::array& value,  DataConstant::DataConstant(const WrappedArray& value,
42                             const FunctionSpace& what)                             const FunctionSpace& what)
43    : parent(what,DataTypes::shapeFromNumArray(value))    : parent(what,value.getShape())
44  {  {
45  //   // extract the shape of the numarray    m_data.copyFromArray(value,1);
 //   DataTypes::ShapeType tempShape;  
 //   for (int i=0; i < value.getrank(); i++) {  
 //     tempShape.push_back(extract<int>(value.getshape()[i]));  
 //   }  
   
   // get the space for the data vector  
 //   int len = getNoValues();  
 //   DataVector temp_data(len, 0.0, len);  
 //   DataArrayView temp_dataView(temp_data, tempShape);  
 //   temp_dataView.copy(value);  
   
   m_data.copyFromNumArray(value,1);  
   //  
   
   // copy the data in the correct format  
 //   m_data=temp_data;  
   //  
   // create the view of the data  
 //   DataArrayView tempView(m_data,temp_dataView.getShape());  
 //   setPointDataView(tempView);  
46  }  }
47    
 // DataConstant::DataConstant(const DataArrayView& value,  
 //                            const FunctionSpace& what)  
 //   : DataAbstract(what)  
 // {  
 //   //  
 //   // copy the data in the correct format  
 //   m_data=value.getData();  
 //   //  
 //   // create the view of the data  
 //   DataArrayView tempView(m_data,value.getShape());  
 //   setPointDataView(tempView);  
 // }  
   
48  DataConstant::DataConstant(const DataConstant& other)  DataConstant::DataConstant(const DataConstant& other)
49    : parent(other.getFunctionSpace(),other.getShape())    : parent(other.getFunctionSpace(),other.getShape())
50  {  //  {
   // copy the data in the correct format  
51    m_data=other.m_data;    m_data=other.m_data;
   //  
 //   // create the view of the data  
 //   DataArrayView tempView(m_data,other.getPointDataView().getShape());  
 //   setPointDataView(tempView);  
52  }  }
53    
54  DataConstant::DataConstant(const DataConstant& other,  DataConstant::DataConstant(const DataConstant& other,
# Line 90  DataConstant::DataConstant(const DataCon Line 56  DataConstant::DataConstant(const DataCon
56    : parent(other.getFunctionSpace(),DataTypes::getResultSliceShape(region))    : parent(other.getFunctionSpace(),DataTypes::getResultSliceShape(region))
57  {  {
58    //    //
   // get the shape of the slice to copy from  
 //   DataTypes::ShapeType shape(DataTypes::getResultSliceShape(region));  
   //  
59    // allocate space for this new DataConstant's data    // allocate space for this new DataConstant's data
60    int len = getNoValues();    int len = getNoValues();
61    m_data.resize(len,0.,len);    m_data.resize(len,0.,len);
62    //    //
63    // create a view of the data with the correct shape    // create a view of the data with the correct shape
 //   DataArrayView tempView(m_data,shape);  
64    DataTypes::RegionLoopRangeType region_loop_range=DataTypes::getSliceRegionLoopRange(region);    DataTypes::RegionLoopRangeType region_loop_range=DataTypes::getSliceRegionLoopRange(region);
65    //    //
66    // load the view with the data from the slice    // load the view with the data from the slice
67  //   tempView.copySlice(other.getPointDataView(),region_loop_range);    DataTypes::copySlice(m_data,getShape(),0,other.getVectorRO(),other.getShape(),0,region_loop_range);
   DataTypes::copySlice(m_data,getShape(),0,other.getVector(),other.getShape(),0,region_loop_range);  
 //   setPointDataView(tempView);  
68  }  }
69    
70  DataConstant::DataConstant(const FunctionSpace& what,  DataConstant::DataConstant(const FunctionSpace& what,
# Line 163  DataConstant::getLength() const Line 123  DataConstant::getLength() const
123    return m_data.size();    return m_data.size();
124  }  }
125    
 // 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();  
 // }  
   
126  DataAbstract*  DataAbstract*
127  DataConstant::getSlice(const DataTypes::RegionType& region) const  DataConstant::getSlice(const DataTypes::RegionType& region) const
128  {  {
# Line 188  DataConstant::setSlice(const DataAbstrac Line 137  DataConstant::setSlice(const DataAbstrac
137    if (tempDataConst==0) {    if (tempDataConst==0) {
138      throw DataException("Programming error - casting to DataConstant.");      throw DataException("Programming error - casting to DataConstant.");
139    }    }
140      CHECK_FOR_EX_WRITE
141    //    //
142    DataTypes::ShapeType shape(DataTypes::getResultSliceShape(region));    DataTypes::ShapeType shape(DataTypes::getResultSliceShape(region));
143    DataTypes::RegionLoopRangeType region_loop_range=DataTypes::getSliceRegionLoopRange(region);    DataTypes::RegionLoopRangeType region_loop_range=DataTypes::getSliceRegionLoopRange(region);
# Line 201  DataConstant::setSlice(const DataAbstrac Line 151  DataConstant::setSlice(const DataAbstrac
151                  "Error - Couldn't copy slice due to shape mismatch.",shape,value->getShape()));                  "Error - Couldn't copy slice due to shape mismatch.",shape,value->getShape()));
152    }    }
153    //   getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);    //   getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);
154    DataTypes::copySliceFrom(m_data,getShape(),0,tempDataConst->getVector(), tempDataConst->getShape(),0,region_loop_range);    DataTypes::copySliceFrom(m_data,getShape(),0,tempDataConst->getVectorRO(), tempDataConst->getShape(),0,region_loop_range);
155  }  }
156    
157    
# Line 213  DataConstant::symmetric(DataAbstract* ev Line 163  DataConstant::symmetric(DataAbstract* ev
163    if (temp_ev==0) {    if (temp_ev==0) {
164      throw DataException("Error - DataConstant::symmetric: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::symmetric: casting to DataConstant failed (propably a programming error).");
165    }    }
166  /*  DataArrayView& thisView=getPointDataView();    DataMaths::symmetric(m_data,getShape(),0,temp_ev->getVectorRW(), temp_ev->getShape(),0);
   DataArrayView& evView=ev->getPointDataView();*/  
   DataMaths::symmetric(m_data,getShape(),0,temp_ev->getVector(), temp_ev->getShape(),0);  
167  }  }
168    
169  void  void
# Line 225  DataConstant::nonsymmetric(DataAbstract* Line 173  DataConstant::nonsymmetric(DataAbstract*
173    if (temp_ev==0) {    if (temp_ev==0) {
174      throw DataException("Error - DataConstant::nonsymmetric: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::nonsymmetric: casting to DataConstant failed (propably a programming error).");
175    }    }
176  /*  DataArrayView& thisView=getPointDataView();    DataMaths::nonsymmetric(m_data,getShape(),0,temp_ev->getVectorRW(), temp_ev->getShape(),0);
   DataArrayView& evView=ev->getPointDataView();*/  
   DataMaths::nonsymmetric(m_data,getShape(),0,temp_ev->getVector(), temp_ev->getShape(),0);  
177  }  }
178    
179  void  void
# Line 237  DataConstant::trace(DataAbstract* ev, in Line 183  DataConstant::trace(DataAbstract* ev, in
183    if (temp_ev==0) {    if (temp_ev==0) {
184      throw DataException("Error - DataConstant::trace: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::trace: casting to DataConstant failed (propably a programming error).");
185    }    }
186  /*  DataArrayView& thisView=getPointDataView();    ValueType& evVec=temp_ev->getVectorRW();
   DataArrayView& evView=ev->getPointDataView();*/  
   ValueType& evVec=temp_ev->getVector();  
187    const ShapeType& evShape=temp_ev->getShape();    const ShapeType& evShape=temp_ev->getShape();
188    DataMaths::trace(m_data,getShape(),0,evVec,evShape,0,axis_offset);    DataMaths::trace(m_data,getShape(),0,evVec,evShape,0,axis_offset);
189  }  }
# Line 251  DataConstant::swapaxes(DataAbstract* ev, Line 195  DataConstant::swapaxes(DataAbstract* ev,
195    if (temp_ev==0) {    if (temp_ev==0) {
196      throw DataException("Error - DataConstant::swapaxes: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::swapaxes: casting to DataConstant failed (propably a programming error).");
197    }    }
198  //   DataArrayView& thisView=getPointDataView();    DataMaths::swapaxes(m_data,getShape(),0,temp_ev->getVectorRW(), temp_ev->getShape(),0,axis0,axis1);
 //   DataArrayView& evView=ev->getPointDataView();  
   DataMaths::swapaxes(m_data,getShape(),0,temp_ev->getVector(), temp_ev->getShape(),0,axis0,axis1);  
199  }  }
200    
201  void  void
# Line 263  DataConstant::transpose(DataAbstract* ev Line 205  DataConstant::transpose(DataAbstract* ev
205    if (temp_ev==0) {    if (temp_ev==0) {
206      throw DataException("Error - DataConstant::transpose: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::transpose: casting to DataConstant failed (propably a programming error).");
207    }    }
208  /*  DataArrayView& thisView=getPointDataView();    DataMaths::transpose(m_data, getShape(),0, temp_ev->getVectorRW(),temp_ev->getShape(),0,axis_offset);
   DataArrayView& evView=ev->getPointDataView();*/  
   DataMaths::transpose(m_data, getShape(),0, temp_ev->getVector(),temp_ev->getShape(),0,axis_offset);  
209  }  }
210    
211  void  void
# Line 275  DataConstant::eigenvalues(DataAbstract* Line 215  DataConstant::eigenvalues(DataAbstract*
215    if (temp_ev==0) {    if (temp_ev==0) {
216      throw DataException("Error - DataConstant::eigenvalues: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::eigenvalues: casting to DataConstant failed (propably a programming error).");
217    }    }
218  /*  DataArrayView& thisView=getPointDataView();    DataMaths::eigenvalues(m_data,getShape(),0,temp_ev->getVectorRW(), temp_ev->getShape(),0);
   DataArrayView& evView=ev->getPointDataView();*/  
   DataMaths::eigenvalues(m_data,getShape(),0,temp_ev->getVector(), temp_ev->getShape(),0);  
219  }  }
220  void  void
221  DataConstant::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)  DataConstant::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
# Line 290  DataConstant::eigenvalues_and_eigenvecto Line 228  DataConstant::eigenvalues_and_eigenvecto
228    if (temp_V==0) {    if (temp_V==0) {
229      throw DataException("Error - DataConstant::eigenvalues_and_eigenvectors: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::eigenvalues_and_eigenvectors: casting to DataConstant failed (propably a programming error).");
230    }    }
231  //   DataArrayView thisView=getPointDataView();    DataMaths::eigenvalues_and_eigenvectors(m_data, getShape(),0,temp_ev->getVectorRW(), temp_ev->getShape(),0,temp_V->getVectorRW(), temp_V->getShape(),0,tol);
 //   DataArrayView evView=ev->getPointDataView();  
 //   DataArrayView VView=V->getPointDataView();  
   
   DataMaths::eigenvalues_and_eigenvectors(m_data, getShape(),0,temp_ev->getVector(), temp_ev->getShape(),0,temp_V->getVector(), temp_V->getShape(),0,tol);  
232  }  }
233    
234  void  void
235  DataConstant::setToZero()  DataConstant::setToZero()
236  {  {
237        CHECK_FOR_EX_WRITE
238      DataTypes::ValueType::size_type n=m_data.size();      DataTypes::ValueType::size_type n=m_data.size();
239      for (int i=0; i<n ;++i) m_data[i]=0.;      for (int i=0; i<n ;++i) m_data[i]=0.;
240  }  }
# Line 381  DataConstant::dump(const std::string fil Line 316  DataConstant::dump(const std::string fil
316     #endif     #endif
317  }  }
318    
319    // These used to be marked as inline in DataConstant.
320    // But they are marked virtual in DataReady
321    DataTypes::ValueType&
322    DataConstant::getVectorRW()
323    {
324      CHECK_FOR_EX_WRITE
325      return m_data;
326    }
327    
328    const DataTypes::ValueType&
329    DataConstant::getVectorRO() const
330    {
331      return m_data;
332    }
333    
334  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.2105  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26