/[escript]/temp/escript/src/Data.h
ViewVC logotype

Diff of /temp/escript/src/Data.h

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

revision 790 by bcumming, Wed Jul 26 23:12:34 2006 UTC revision 1137 by gross, Thu May 10 08:11:31 2007 UTC
# Line 70  class Data { Line 70  class Data {
70    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
71    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
72    
73    
74    /**    /**
75       Constructors.       Constructors.
76    */    */
# Line 253  class Data { Line 254  class Data {
254    ESCRIPT_DLL_API    ESCRIPT_DLL_API
255    bool    bool
256    isProtected() const;    isProtected() const;
257    
258    /**    /**
259       \brief       \brief
260       Return the values of all data-points as a single python numarray object.       Return the values of a data point on this process
261    */    */
262    ESCRIPT_DLL_API    ESCRIPT_DLL_API
263    const boost::python::numeric::array    const boost::python::numeric::array
264    convertToNumArray();    getValueOfDataPoint(int dataPointNo);
265    
266    /**    /**
267       \brief       \brief
268       Return the values of all data-points for the given sample as a single python numarray object.       sets the values of a data-point from a python object on this process
269    */    */
270    ESCRIPT_DLL_API    ESCRIPT_DLL_API
271    const boost::python::numeric::array    void
272    convertToNumArrayFromSampleNo(int sampleNo);    setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
273    
274    /**    /**
275       \brief       \brief
276       Return the value of the specified data-point as a single python numarray object.       sets the values of a data-point from a numarray object on this process
277    */    */
 #ifndef PASO_MPI    
278    ESCRIPT_DLL_API    ESCRIPT_DLL_API
279    const boost::python::numeric::array    void
280    convertToNumArrayFromDPNo(int ProcNo,    setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
                                                         int sampleNo,  
                             int dataPointNo);  
 #else  
   ESCRIPT_DLL_API  
   const boost::python::numeric::array  
   convertToNumArrayFromDPNo(int procNo,  
                 int sampleNo,  
                 int dataPointNo);  
 #endif  
   
281    
282    /**    /**
283       \brief       \brief
284       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point on this process
285    */    */
286    ESCRIPT_DLL_API    ESCRIPT_DLL_API
287    void    void
288    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPoint(int dataPointNo, const double);
289    
290      /**
291         \brief
292         Return the value of the specified data-point across all processors
293      */
294      ESCRIPT_DLL_API
295      const boost::python::numeric::array
296      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
297    
298    /**    /**
299       \brief       \brief
# Line 334  class Data { Line 333  class Data {
333    {    {
334      return m_data->toString();      return m_data->toString();
335    }    }
336      
337      /**
338         \brief
339         Return a description for this domain for python.
340      */
341      ESCRIPT_DLL_API
342      const boost::python::str str() const;
343    
344    /**    /**
345       \brief       \brief
# Line 454  class Data { Line 460  class Data {
460    
461    /**    /**
462       \brief       \brief
463         Return the number of data points
464      */
465      ESCRIPT_DLL_API
466      inline
467      int
468      getNumDataPoints() const
469      {
470        return getNumSamples() * getNumDataPointsPerSample();
471      }
472      /**
473         \brief
474       Return the number of samples.       Return the number of samples.
475    */    */
476    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 475  class Data { Line 492  class Data {
492    {    {
493      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
494    }    }
495      /**
496         \brief
497         dumps the object into a netCDF file
498      */
499      ESCRIPT_DLL_API
500      inline
501      void
502      dump(const std::string fileName) const
503      {
504        return m_data->dump(fileName);
505      }
506    
507    /**    /**
508       \brief       \brief
# Line 506  class Data { Line 534  class Data {
534    
535    /**    /**
536       \brief       \brief
      Assign the given value to the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object.  The data from this numarray  
      is unpacked into a DataArray, and this is used to set the corresponding  
      data-points in the underlying Data object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Input - value to assign to data-points associated with  
                             the given reference number.  
   */  
   ESCRIPT_DLL_API  
   void  
   setRefValue(int ref,  
               const boost::python::numeric::array& value);  
   
   /**  
      \brief  
      Return the values associated with the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object. The data from the corresponding  
      data-points in this Data object are packed into the given numarray object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Output - object to receive values from data-points  
                              associated with the given reference number.  
   */  
   ESCRIPT_DLL_API  
   void  
   getRefValue(int ref,  
               boost::python::numeric::array& value);  
   
   /**  
      \brief  
537       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
538       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
539       operation.       operation.
# Line 595  class Data { Line 582  class Data {
582    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
583    getLength() const;    getLength() const;
584    
585    
586    
587      /**
588         \brief
589         Assign the given value to the tag assocciated with name. Implicitly converts this
590         object to type DataTagged. Throws an exception if this object
591         cannot be converted to a DataTagged object or name cannot be mapped onto a tag key.
592         \param tagKey - Input - Integer key.
593         \param value - Input - Value to associate with given key.
594        ==>*
595      */
596      ESCRIPT_DLL_API
597      void
598      setTaggedValueByName(std::string name,
599                           const boost::python::object& value);
600    
601    /**    /**
602       \brief       \brief
603       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 638  class Data { Line 641  class Data {
641    
642    /**    /**
643       \brief       \brief
644         set all values to zero
645         *
646      */
647      ESCRIPT_DLL_API
648      void
649      setToZero();
650    
651      /**
652         \brief
653       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
654       the result as a Data object.       the result as a Data object.
655       *       *
# Line 645  class Data { Line 657  class Data {
657    ESCRIPT_DLL_API    ESCRIPT_DLL_API
658    Data    Data
659    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
   
660    /**    /**
661       \brief       \brief
662       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
# Line 671  class Data { Line 682  class Data {
682    
683    /**    /**
684       \brief       \brief
685         Returns 1./ Data object
686         *
687      */
688      ESCRIPT_DLL_API
689      Data
690      oneOver() const;
691      /**
692         \brief
693       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
694       *       *
695    */    */
# Line 793  class Data { Line 812  class Data {
812    */    */
813    ESCRIPT_DLL_API    ESCRIPT_DLL_API
814    const boost::python::tuple    const boost::python::tuple
815    mindp() const;    minGlobalDataPoint() const;
816    
817    ESCRIPT_DLL_API    ESCRIPT_DLL_API
818    void    void
819    calc_mindp(int& ProcNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
                         int& SampleNo,    
              int& DataPointNo) const;  
820    /**    /**
821       \brief       \brief
822       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
# Line 835  class Data { Line 852  class Data {
852    */    */
853    ESCRIPT_DLL_API    ESCRIPT_DLL_API
854    Data    Data
855    matrixtrace(int axis_offset) const;    trace(int axis_offset) const;
856    
857    /**    /**
858       \brief       \brief
# Line 871  class Data { Line 888  class Data {
888    
889    /**    /**
890       \brief       \brief
891       Calculate the trace of each data point of this Data object.       swaps the components axis0 and axis1
892       *       *
893    */    */
894    ESCRIPT_DLL_API    ESCRIPT_DLL_API
895    Data    Data
896    trace() const;    swapaxes(const int axis0, const int axis1) const;
897    
898      /**
899         \brief
900         Return the error function erf of each data point of this Data object.
901         *
902      */
903      ESCRIPT_DLL_API
904      Data
905      erf() const;
906    
907    /**    /**
908       \brief       \brief
# Line 1279  class Data { Line 1305  class Data {
1305    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1306      MPI_Comm      MPI_Comm
1307      get_MPIComm(void) const;      get_MPIComm(void) const;
1308        
1309      /**
1310         \brief
1311         return the object produced by the factory, which is a DataConstant or DataExpanded
1312      */
1313      ESCRIPT_DLL_API
1314        DataAbstract*
1315        borrowData(void) const;
1316    
1317   protected:   protected:
1318    
1319   private:   private:
# Line 1337  class Data { Line 1371  class Data {
1371    
1372    /**    /**
1373       \brief       \brief
      Perform the given binary operation on all of the data's elements.  
      RHS is a boost::python object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const boost::python::object& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
1374       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1375       \param right - Input - data type to match.       \param right - Input - data type to match.
1376    */    */
# Line 1372  class Data { Line 1395  class Data {
1395               const FunctionSpace& what,               const FunctionSpace& what,
1396               bool expanded);               bool expanded);
1397    
   /**  
      \brief  
      Reshape the data point if the data point is currently rank 0.  
      Will throw an exception if the data points are not rank 0.  
      The original data point value is used for all values of the new  
      data point.  
   */  
   void  
   reshapeDataPoint(const DataArrayView::ShapeType& shape);  
   
1398    //    //
1399    // flag to protect the data object against any update    // flag to protect the data object against any update
1400    bool m_protected;    bool m_protected;
# Line 1390  class Data { Line 1403  class Data {
1403    // pointer to the actual data object    // pointer to the actual data object
1404    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1405    
   //  
   // pointer to the internal profiling data  
   struct profDataEntry *profData;  
   
1406  };  };
1407    
1408  template <class IValueType>  template <class IValueType>
# Line 1421  Data::initialise(const IValueType& value Line 1430  Data::initialise(const IValueType& value
1430  /**  /**
1431     Binary Data object operators.     Binary Data object operators.
1432  */  */
1433    inline double rpow(double x,double y)
1434    {
1435        return pow(y,x);
1436    }
1437    
1438  /**  /**
1439    \brief    \brief
# Line 1522  ESCRIPT_DLL_API std::ostream& operator<< Line 1535  ESCRIPT_DLL_API std::ostream& operator<<
1535    
1536  /**  /**
1537    \brief    \brief
1538      Compute a tensor product of two Data objects
1539      \param arg0 - Input - Data object
1540      \param arg1 - Input - Data object
1541      \param axis_offset - Input - axis offset
1542      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1543    */
1544    ESCRIPT_DLL_API
1545    Data
1546    C_GeneralTensorProduct(Data& arg0,
1547                         Data& arg1,
1548                         int axis_offset=0,
1549                         int transpose=0);
1550    
1551    /**
1552      \brief
1553    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1554    NB: this operator does very little at this point, and isn't to    NB: this operator does very little at this point, and isn't to
1555    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1542  Data::binaryOp(const Data& right, Line 1570  Data::binaryOp(const Data& right,
1570     //     //
1571     // if this has a rank of zero promote it to the rank of the RHS     // if this has a rank of zero promote it to the rank of the RHS
1572     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1573       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1574     }     }
1575     //     //
1576     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1596  Data::binaryOp(const Data& right, Line 1624  Data::binaryOp(const Data& right,
1624     }     }
1625  }  }
1626    
 /**  
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a boost::python object.  
 */  
 template <class BinaryFunction>  
 inline  
 void  
 Data::binaryOp(const boost::python::object& right,  
                BinaryFunction operation)  
 {  
    DataArray temp(right);  
    //  
    // if this has a rank of zero promote it to the rank of the RHS.  
    if (getPointDataView().getRank()==0 && temp.getView().getRank()!=0) {  
       reshapeDataPoint(temp.getView().getShape());  
    }  
    //  
    // Always allow scalar values for the RHS but check other shapes  
    if (temp.getView().getRank()!=0) {  
      if (!getPointDataView().checkShape(temp.getView().getShape())) {  
        throw DataException(getPointDataView().createShapeErrorMessage(  
                   "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));  
      }  
    }  
    if (isExpanded()) {  
      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isTagged()) {  
      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());  
      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isConstant()) {  
      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    }  
 }  
   
1627  /**  /**
1628    \brief    \brief
1629    Perform the given unary operation on other and return the result.    Perform the given unary operation on other and return the result.

Legend:
Removed from v.790  
changed lines
  Added in v.1137

  ViewVC Help
Powered by ViewVC 1.1.26