/[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 146 by jgs, Fri Jul 22 03:53:08 2005 UTC revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC
# Line 745  class DataArrayView { Line 745  class DataArrayView {
745       \param operation - Input -       \param operation - Input -
746                    Operation to apply. Must be a pointer to a function.                    Operation to apply. Must be a pointer to a function.
747    */    */
748    template <class UnaryFunction>    template <class BinaryFunction>
749    double    double
750    reductionOp(UnaryFunction operation) const;    reductionOp(BinaryFunction operation,
751                  double initial_value) const;
752    
753    /**    /**
754       \brief       \brief
# Line 763  class DataArrayView { Line 764  class DataArrayView {
764       \param operation - Input -       \param operation - Input -
765                    Operation to apply. Must be a pointer to a function.                    Operation to apply. Must be a pointer to a function.
766    */    */
767    template <class UnaryFunction>    template <class BinaryFunction>
768    double    double
769    reductionOp(ValueType::size_type offset,    reductionOp(ValueType::size_type offset,
770                UnaryFunction operation) const;                BinaryFunction operation,
771                  double initial_value) const;
772    
773    /**    /**
774       \brief       \brief
# Line 940  DataArrayView::binaryOp(ValueType::size_ Line 942  DataArrayView::binaryOp(ValueType::size_
942    }    }
943  }  }
944    
945  template <class UnaryFunction>  template <class BinaryFunction>
946  inline  inline
947  double  double
948  DataArrayView::reductionOp(UnaryFunction operation) const  DataArrayView::reductionOp(BinaryFunction operation,
949                               double initial_value) const
950  {  {
951    return reductionOp(m_offset,operation);    return reductionOp(m_offset,operation,initial_value);
952  }  }
953    
954  template <class UnaryFunction>  template <class BinaryFunction>
955  inline  inline
956  double  double
957  DataArrayView::reductionOp(ValueType::size_type offset,  DataArrayView::reductionOp(ValueType::size_type offset,
958                             UnaryFunction operation) const                             BinaryFunction operation,
959                               double initial_value) const
960  {  {
961    EsysAssert((!isEmpty()&&checkOffset(offset)),    EsysAssert((!isEmpty()&&checkOffset(offset)),
962                 "Error - Couldn't perform reductionOp due to insufficient storage.");                 "Error - Couldn't perform reductionOp due to insufficient storage.");
963    operation.resetResult();    double current_value=initial_value;
964    for (ValueType::size_type i=0;i<noValues();i++) {    for (ValueType::size_type i=0;i<noValues();i++) {
965      operation((*m_data)[offset+i]);      current_value=operation(current_value,(*m_data)[offset+i]);
966    }    }
967    return operation.getResult();    return current_value;
968  }  }
969    
970  inline  inline

Legend:
Removed from v.146  
changed lines
  Added in v.147

  ViewVC Help
Powered by ViewVC 1.1.26