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

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

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 22  Line 23 
23  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
24  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
25    
26    #include <iostream>
27    
28  namespace escript {  namespace escript {
29    
30  /**  /**
# Line 178  class DataArrayView { Line 181  class DataArrayView {
181    
182    /**    /**
183       \brief       \brief
184       Return true if the shapes are the same.       Return true if the given shape is the same as this object's shape.
185    */    */
186    bool    bool
187    checkShape(const DataArrayView::ShapeType& other) const;    checkShape(const DataArrayView::ShapeType& other) const;
# Line 228  class DataArrayView { Line 231  class DataArrayView {
231    
232    /**    /**
233       \brief       \brief
234       Copy a slice from the given view. This view must be the right shape for the slice.       Copy a slice specified by the given region from the given view
235         into this view.
236         The given region must be the same shape as this view.
237    
238       \param other - Input - Data to copy from.       \param other - Input - view to copy from.
239       \param region - Input - Slice region.       \param region - Input - region in other to copy.
240    */    */
241    void    void
242    copySlice(const DataArrayView& other,    copySlice(const DataArrayView& other,
# Line 239  class DataArrayView { Line 244  class DataArrayView {
244    
245    /**    /**
246       \brief       \brief
247       Copy a slice from the given view. This view must be the right shape for the slice.       Copy a slice specified by the given region from the given view into this view.
248         The given region must be the same shape as this view.
249    
250       \param thisOffset - Input - use this view offset instead of the default.       \param thisOffset - Input - use this offset into this object instead of the default.
251       \param other - Input - Data to copy from.       \param other - Input - view to copy from.
252       \param otherOffset - Input - use this slice offset instead of the default.       \param otherOffset - Input - use this offset into the given object instead of the default.
253       \param region - Input - Slice region.       \param region - Input - region in other to copy.
254    */    */
255    void    void
256    copySlice(ValueType::size_type thisOffset,    copySlice(ValueType::size_type thisOffset,
# Line 254  class DataArrayView { Line 260  class DataArrayView {
260    
261   /**   /**
262       \brief       \brief
263       Copy into a slice from the given view. This view must have the same rank as the slice region.       Copy into a slice from the given view.
264         This view must have the same rank as the slice region.
265    
266       \param other - Input - Data to copy from.       \param other - Input - Data to copy from.
267       \param region - Input - Slice region.       \param region - Input - Slice region.
# Line 265  class DataArrayView { Line 272  class DataArrayView {
272    
273    /**    /**
274       \brief       \brief
275       Copy into a slice from the given value. This view must have the same rank as the slice region.       Copy into a slice from the given value.
276         This view must have the same rank as the slice region.
277    
278       \param thisOffset - Input - use this view offset instead of the default.       \param thisOffset - Input - use this view offset instead of the default.
279       \param other - Input - Data to copy from.       \param other - Input - Data to copy from.
# Line 288  class DataArrayView { Line 296  class DataArrayView {
296    
297    /**    /**
298       \brief       \brief
299       Returns the range for the slices defined by the key which is a Python       Determine the region specified by the given python slice object.
300       slice object or a tuple of Python slice object.  
301         \param key - Input - python slice object specifying region to be returned.
302    
303         \description
304    
305         The slice object is a tuple of n python slice specifiers, where
306         n <= the rank of this Data object. Each slice specifier specifies the
307         range of indexes to be sliced from the corresponding dimension. The
308         first specifier corresponds to the first dimension, the second to the
309         second and so on. Where n < the rank, the remaining dimensions are
310         sliced across the full range of their indicies.
311    
312         Each slice specifier is of the form "a:b", which specifies a slice
313         from index a, up to but not including index b. Where index a is ommitted
314         a is assumed to be 0. Where index b is ommitted, b is assumed to be the
315         length of this dimension.
316    
317         The return value is a vector of pairs with length equal to the rank of
318         this object. Each pair corresponds to the range of indexes from the
319         corresponding dimension to be sliced from, as specified in the input
320         slice object.
321    
322         Examples:
323    
324           For a rank 1 object of shape(5):
325    
326             getSliceRegion(:)   => < <0,5> >
327             getSliceRegion(2:3) => < <2,3> >
328             getSliceRegion(:3)  => < <0,3> >
329             getSliceRegion(2:)  => < <2,5> >
330    
331           For a rank 3 object of shape (2,4,6):
332    
333             getSliceRegion(0:2,0:4,0:6) => < <0,2> <0,4> <0,6> >
334             getSliceRegion(:,:,:)       => < <0,2> <0,4> <0,6> >
335             getSliceRegion(0:1)         => < <0,1> <0,4> <0,6> >
336             getSliceRegion(:1,0:2)      => < <0,1> <0,2> <0,6> >
337    */    */
338    DataArrayView::RegionType    DataArrayView::RegionType
339    getSliceRegion(const boost::python::object& key) const;    getSliceRegion(const boost::python::object& key) const;
   /*  
   DataArrayView::RegionType  
   getSliceRegion2(const boost::python::object& key) const;  
   */  
340    
341    // *******************************************************************    // *******************************************************************
342    // NOTE: The following relIndex functions are a hack. The indexing    // NOTE: The following relIndex functions are a hack. The indexing
# Line 451  class DataArrayView { Line 491  class DataArrayView {
491    
492    /**    /**
493       \brief       \brief
494         Perform the given data point reduction operation on the data point
495         specified by the given offset into the view. Reduces all elements of
496         the data point using the given operation, returning the result as a
497         scalar.
498    
499         Called by escript::dp_algorithm.
500      */
501      template <class UnaryFunction>
502      double
503      dp_algorithm(ValueType::size_type leftOffset,
504                   UnaryFunction operation);
505    
506      /**
507         \brief
508         Perform the given data point reduction operation on the data point
509         specified by the default offset into the view. Reduces all elements of
510         the data point using the given operation, returning the result as a
511         scalar.
512    
513         Called by escript::dp_algorithm.
514      */
515      template <class UnaryFunction>
516      double
517      dp_algorithm(UnaryFunction operation);
518    
519      /**
520         \brief
521       Perform the given operation and return a result.       Perform the given operation and return a result.
522    */    */
523    template <class UnaryFunction>    template <class UnaryFunction>
# Line 567  class DataArrayView { Line 634  class DataArrayView {
634    
635  };  };
636    
637    /**
638      \brief
639      Calculate the slice range from the given python key object
640      Used by DataArrayView::getSliceRegion.
641      Returns the python slice object key as a pair of ints where the first
642      member is the start and the second member is the end. the presence of a possible
643      step attribute with value different from one will throw an exception
644    
645      /param key - Input - key object specifying slice range.
646    */
647    std::pair<int,int>
648    getSliceRange(const boost::python::object& key,
649                  const int shape);
650    
651  inline  inline
652  DataArrayView::ValueType::size_type  DataArrayView::ValueType::size_type
653  DataArrayView::getOffset() const  DataArrayView::getOffset() const
# Line 598  void Line 679  void
679  DataArrayView::unaryOp(ValueType::size_type leftOffset,  DataArrayView::unaryOp(ValueType::size_type leftOffset,
680                         UnaryFunction operation)                         UnaryFunction operation)
681  {  {
682    for (ValueType::size_type i=0;i<(noValues(m_shape));++i) {    for (ValueType::size_type i=0;i<(noValues(m_shape));i++) {
683      (*m_data)[i+leftOffset]=operation((*m_data)[i+leftOffset]);      (*m_data)[i+leftOffset]=operation((*m_data)[i+leftOffset]);
684    }    }
685  }  }
# Line 614  DataArrayView::unaryOp(UnaryFunction ope Line 695  DataArrayView::unaryOp(UnaryFunction ope
695  template <class UnaryFunction>  template <class UnaryFunction>
696  inline  inline
697  double  double
698    DataArrayView::dp_algorithm(ValueType::size_type leftOffset,
699                                UnaryFunction operation)
700    {
701      for (ValueType::size_type i=0;i<(noValues(m_shape));i++) {
702        operation((*m_data)[i+leftOffset]);
703      }
704      return operation.getResult();
705    }
706    
707    template <class UnaryFunction>
708    inline
709    double
710    DataArrayView::dp_algorithm(UnaryFunction operation)
711    {
712      return dp_algorithm(m_offset,operation);
713    }
714    
715    template <class UnaryFunction>
716    inline
717    double
718  DataArrayView::algorithm(ValueType::size_type leftOffset,  DataArrayView::algorithm(ValueType::size_type leftOffset,
719                           UnaryFunction operation) const                           UnaryFunction operation) const
720  {  {
# Line 875  DataArrayView::operator()() const Line 976  DataArrayView::operator()() const
976  bool operator==(const DataArrayView& left, const DataArrayView& right);  bool operator==(const DataArrayView& left, const DataArrayView& right);
977  bool operator!=(const DataArrayView& left, const DataArrayView& right);  bool operator!=(const DataArrayView& left, const DataArrayView& right);
978    
 /* 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 truow an exception */  
 std::pair<int,int>  
 getSliceRange(const int s,  
               const boost::python::object&  key);  
   
979  } // end of namespace  } // end of namespace
980    
981  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26