/[escript]/trunk/esys2/escript/src/Data/DataArrayView.h
ViewVC logotype

Diff of /trunk/esys2/escript/src/Data/DataArrayView.h

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

revision 99 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 23  Line 22 
22  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
23  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
24    
 #include <iostream>  
   
25  namespace escript {  namespace escript {
26    
27  /**  /**
# Line 181  class DataArrayView { Line 178  class DataArrayView {
178    
179    /**    /**
180       \brief       \brief
181       Return true if the given shape is the same as this object's shape.       Return true if the shapes are the same.
182    */    */
183    bool    bool
184    checkShape(const DataArrayView::ShapeType& other) const;    checkShape(const DataArrayView::ShapeType& other) const;
# Line 231  class DataArrayView { Line 228  class DataArrayView {
228    
229    /**    /**
230       \brief       \brief
231       Copy a slice specified by the given region from the given view       Copy a slice from the given view. This view must be the right shape for the slice.
      into this view.  
      The given region must be the same shape as this view.  
232    
233       \param other - Input - view to copy from.       \param other - Input - Data to copy from.
234       \param region - Input - region in other to copy.       \param region - Input - Slice region.
235    */    */
236    void    void
237    copySlice(const DataArrayView& other,    copySlice(const DataArrayView& other,
# Line 244  class DataArrayView { Line 239  class DataArrayView {
239    
240    /**    /**
241       \brief       \brief
242       Copy a slice specified by the given region from the given view into this view.       Copy a slice from the given view. This view must be the right shape for the slice.
      The given region must be the same shape as this view.  
243    
244       \param thisOffset - Input - use this offset into this object instead of the default.       \param thisOffset - Input - use this view offset instead of the default.
245       \param other - Input - view to copy from.       \param other - Input - Data to copy from.
246       \param otherOffset - Input - use this offset into the given object instead of the default.       \param otherOffset - Input - use this slice offset instead of the default.
247       \param region - Input - region in other to copy.       \param region - Input - Slice region.
248    */    */
249    void    void
250    copySlice(ValueType::size_type thisOffset,    copySlice(ValueType::size_type thisOffset,
# Line 260  class DataArrayView { Line 254  class DataArrayView {
254    
255   /**   /**
256       \brief       \brief
257       Copy into a slice from the given view.       Copy into a slice from the given view. This view must have the same rank as the slice region.
      This view must have the same rank as the slice region.  
258    
259       \param other - Input - Data to copy from.       \param other - Input - Data to copy from.
260       \param region - Input - Slice region.       \param region - Input - Slice region.
# Line 272  class DataArrayView { Line 265  class DataArrayView {
265    
266    /**    /**
267       \brief       \brief
268       Copy into a slice from the given value.       Copy into a slice from the given value. This view must have the same rank as the slice region.
      This view must have the same rank as the slice region.  
269    
270       \param thisOffset - Input - use this view offset instead of the default.       \param thisOffset - Input - use this view offset instead of the default.
271       \param other - Input - Data to copy from.       \param other - Input - Data to copy from.
# Line 296  class DataArrayView { Line 288  class DataArrayView {
288    
289    /**    /**
290       \brief       \brief
291       Determine the region specified by the given python slice object.       Returns the range for the slices defined by the key which is a Python
292         slice object or a tuple of Python slice object.
      \param key - Input - python slice object specifying region to be returned.  
   
      \description  
   
      The slice object is a tuple of n python slice specifiers, where  
      n <= the rank of this Data object. Each slice specifier specifies the  
      range of indexes to be sliced from the corresponding dimension. The  
      first specifier corresponds to the first dimension, the second to the  
      second and so on. Where n < the rank, the remaining dimensions are  
      sliced across the full range of their indicies.  
   
      Each slice specifier is of the form "a:b", which specifies a slice  
      from index a, up to but not including index b. Where index a is ommitted  
      a is assumed to be 0. Where index b is ommitted, b is assumed to be the  
      length of this dimension.  
   
      The return value is a vector of pairs with length equal to the rank of  
      this object. Each pair corresponds to the range of indexes from the  
      corresponding dimension to be sliced from, as specified in the input  
      slice object.  
   
      Examples:  
   
        For a rank 1 object of shape(5):  
   
          getSliceRegion(:)   => < <0,5> >  
          getSliceRegion(2:3) => < <2,3> >  
          getSliceRegion(:3)  => < <0,3> >  
          getSliceRegion(2:)  => < <2,5> >  
   
        For a rank 3 object of shape (2,4,6):  
   
          getSliceRegion(0:2,0:4,0:6) => < <0,2> <0,4> <0,6> >  
          getSliceRegion(:,:,:)       => < <0,2> <0,4> <0,6> >  
          getSliceRegion(0:1)         => < <0,1> <0,4> <0,6> >  
          getSliceRegion(:1,0:2)      => < <0,1> <0,2> <0,6> >  
293    */    */
294    DataArrayView::RegionType    DataArrayView::RegionType
295    getSliceRegion(const boost::python::object& key) const;    getSliceRegion(const boost::python::object& key) const;
296      /*
297      DataArrayView::RegionType
298      getSliceRegion2(const boost::python::object& key) const;
299      */
300    
301    // *******************************************************************    // *******************************************************************
302    // NOTE: The following relIndex functions are a hack. The indexing    // NOTE: The following relIndex functions are a hack. The indexing
# Line 491  class DataArrayView { Line 451  class DataArrayView {
451    
452    /**    /**
453       \brief       \brief
      Perform the given data point reduction operation on the data point  
      specified by the given offset into the view. Reduces all elements of  
      the data point using the given operation, returning the result as a  
      scalar.  
   
      Called by escript::dp_algorithm.  
   */  
   template <class UnaryFunction>  
   double  
   dp_algorithm(ValueType::size_type leftOffset,  
                UnaryFunction operation);  
   
   /**  
      \brief  
      Perform the given data point reduction operation on the data point  
      specified by the default offset into the view. Reduces all elements of  
      the data point using the given operation, returning the result as a  
      scalar.  
   
      Called by escript::dp_algorithm.  
   */  
   template <class UnaryFunction>  
   double  
   dp_algorithm(UnaryFunction operation);  
   
   /**  
      \brief  
454       Perform the given operation and return a result.       Perform the given operation and return a result.
455    */    */
456    template <class UnaryFunction>    template <class UnaryFunction>
# Line 634  class DataArrayView { Line 567  class DataArrayView {
567    
568  };  };
569    
 /**  
   \brief  
   Calculate the slice range from the given python key object  
   Used by DataArrayView::getSliceRegion.  
   Returns the python slice object key as a pair of ints where the first  
   member is the start and the second member is the end. the presence of a possible  
   step attribute with value different from one will throw an exception  
   
   /param key - Input - key object specifying slice range.  
 */  
 std::pair<int,int>  
 getSliceRange(const boost::python::object& key,  
               const int shape);  
   
570  inline  inline
571  DataArrayView::ValueType::size_type  DataArrayView::ValueType::size_type
572  DataArrayView::getOffset() const  DataArrayView::getOffset() const
# Line 679  void Line 598  void
598  DataArrayView::unaryOp(ValueType::size_type leftOffset,  DataArrayView::unaryOp(ValueType::size_type leftOffset,
599                         UnaryFunction operation)                         UnaryFunction operation)
600  {  {
601    for (ValueType::size_type i=0;i<(noValues(m_shape));i++) {    for (ValueType::size_type i=0;i<(noValues(m_shape));++i) {
602      (*m_data)[i+leftOffset]=operation((*m_data)[i+leftOffset]);      (*m_data)[i+leftOffset]=operation((*m_data)[i+leftOffset]);
603    }    }
604  }  }
# Line 695  DataArrayView::unaryOp(UnaryFunction ope Line 614  DataArrayView::unaryOp(UnaryFunction ope
614  template <class UnaryFunction>  template <class UnaryFunction>
615  inline  inline
616  double  double
 DataArrayView::dp_algorithm(ValueType::size_type leftOffset,  
                             UnaryFunction operation)  
 {  
   for (ValueType::size_type i=0;i<(noValues(m_shape));i++) {  
     operation((*m_data)[i+leftOffset]);  
   }  
   return operation.getResult();  
 }  
   
 template <class UnaryFunction>  
 inline  
 double  
 DataArrayView::dp_algorithm(UnaryFunction operation)  
 {  
   return dp_algorithm(m_offset,operation);  
 }  
   
 template <class UnaryFunction>  
 inline  
 double  
617  DataArrayView::algorithm(ValueType::size_type leftOffset,  DataArrayView::algorithm(ValueType::size_type leftOffset,
618                           UnaryFunction operation) const                           UnaryFunction operation) const
619  {  {
# Line 976  DataArrayView::operator()() const Line 875  DataArrayView::operator()() const
875  bool operator==(const DataArrayView& left, const DataArrayView& right);  bool operator==(const DataArrayView& left, const DataArrayView& right);
876  bool operator!=(const DataArrayView& left, const DataArrayView& right);  bool operator!=(const DataArrayView& left, const DataArrayView& right);
877    
878    /* returns the python slice object key as a pair of ints where the first
879        member is the start and the second member is the end. the presence of a possible
880        step attribute with value different from one will truow an exception */
881    std::pair<int,int>
882    getSliceRange(const int s,
883                  const boost::python::object&  key);
884    
885  } // end of namespace  } // end of namespace
886    
887  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26