# Diff of /trunk/escript/src/DataAlgorithm.h

revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 106 by jgs, Thu Dec 23 07:20:12 2004 UTC
# Line 75  struct AbsMax : public std::binary_funct Line 75  struct AbsMax : public std::binary_funct
75
76  /**  /**
77     \brief     \brief
78       Return the length.
79
80       Description:
81       Return the length.
82    */
83    struct Length : public std::binary_function<double,double,double>
84    {
85      inline double operator()(double x, double y) const
86      {
87        return std::sqrt(std::pow(x,2)+std::pow(y,2));
88      }
89    };
90
91    /**
92       \brief
93       Return the trace.
94
95       Description:
96       Return the trace.
97    */
98    struct Trace : public std::binary_function<double,double,double>
99    {
100      inline double operator()(double x, double y) const
101      {
102        return x+y;
103      }
104    };
105
106    /**
107       \brief
108     Adapt algorithms so they may be used by Data.     Adapt algorithms so they may be used by Data.
109
110     Description:     Description:
111     Adapt algorithms so they may be used by Data. The functor     Adapt algorithms so they may be used by Data. The functor
112     maintains state, ie the currentValue retuned by the operation.     maintains state, the currentValue returned by the operation,
113       and the initial value.
114  */  */
115  template <class BinaryFunction>  template <class BinaryFunction>
117   public:   public:
119          m_initialValue(initialValue),
120        m_currentValue(initialValue)        m_currentValue(initialValue)
121      {}      {}
122      inline void operator()(double value)      inline void operator()(double value)
124        m_currentValue=operation(m_currentValue,value);        m_currentValue=operation(m_currentValue,value);
125        return;        return;
126      }      }
127        inline void resetResult()
128        {
129          m_currentValue=m_initialValue;
130        }
131      inline double getResult() const      inline double getResult() const
132      {      {
133        return m_currentValue;        return m_currentValue;
134      }      }
135   private:   private:
136      //      //
137        // the initial operation value
138        double m_initialValue;
139        //
140      // the current operation value      // the current operation value
141      double m_currentValue;      double m_currentValue;
142      //      //
# Line 170  algorithm(DataConstant& data, Line 209  algorithm(DataConstant& data,
209
210  /**  /**
211     \brief     \brief
212     Perform the given data point reduction operation upon all data points     Perform the given data point reduction operation on all data points
213     in data, storing results in corresponding elements of result.     in data, storing results in corresponding elements of result.
214
215     Objects data and result must be of the same type, and have the same number     Objects data and result must be of the same type, and have the same number
216     of samples and number of data points per sample, but where data has data     of data points, but where data has data points of rank n, result must have
217     points of rank n, result must have data points of rank 0.     data points of rank 0.
218
219     Calls DataArrayView::dp_algorithm.     Calls DataArrayView::dp_algorithm.
220  */  */
221  template <class UnaryFunction>  template <class UnaryFunction>
222  inline  inline
223  void  void
224  dp_algorithm(DataExpanded& result,  dp_algorithm(DataExpanded& data,
225               DataExpanded& data,               DataExpanded& result,
226               UnaryFunction operation)               UnaryFunction operation)
227  {  {
228      //
229      // perform the operation on each data value
230      // and assign this to the corresponding element in result
231    int i,j;    int i,j;
232    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
233    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
# Line 193  dp_algorithm(DataExpanded& result, Line 235  dp_algorithm(DataExpanded& result,
235  #pragma omp for private(i,j) schedule(static)  #pragma omp for private(i,j) schedule(static)
236      for (i=0;i<numSamples;i++) {      for (i=0;i<numSamples;i++) {
237        for (j=0;j<numDPPSample;j++) {        for (j=0;j<numDPPSample;j++) {
// assign this to corresponding element in result
data.getPointDataView().dp_algorithm(data.getPointOffset(i,j),operation);
238  #pragma omp critical (dp_algorithm)  #pragma omp critical (dp_algorithm)
239            result.getPointDataView().getData(data.getPointOffset(i,j)) =
240              data.getPointDataView().dp_algorithm(data.getPointOffset(i,j),operation);
241        }        }
242      }      }
243    }    }
# Line 204  dp_algorithm(DataExpanded& result, Line 246  dp_algorithm(DataExpanded& result,
246  template <class UnaryFunction>  template <class UnaryFunction>
247  inline  inline
248  void  void
249  dp_algorithm(DataTagged& result,  dp_algorithm(DataTagged& data,
250               DataTagged& data,               DataTagged& result,
251               UnaryFunction operation)               UnaryFunction operation)
252  {  {
253    //    //
254    // perform the operation on each tagged value    // perform the operation on each tagged data value
255      // and assign this to the corresponding element in result
256    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
257    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
258    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
259    for (i=lookup.begin();i!=lookupEnd;i++) {    for (i=lookup.begin();i!=lookupEnd;i++) {
260      // assign this to corresponding element in result      result.getPointDataView().getData(i->second) =
261      data.getPointDataView().dp_algorithm(i->second,operation);        data.getPointDataView().dp_algorithm(i->second,operation);
262    }    }
263    //    //
264    // finally perform the operation on the default value    // finally perform the operation on the default data value
265    // assign this to corresponding element in result    // and assign this to the default element in result
266    data.getDefaultValue().dp_algorithm(operation);    result.getPointDataView().getData(0) =
267        data.getDefaultValue().dp_algorithm(operation);
268  }  }
269
270  template <class UnaryFunction>  template <class UnaryFunction>
271  inline  inline
272  void  void
273  dp_algorithm(DataConstant& result,  dp_algorithm(DataConstant& data,
274               DataConstant& data,               DataConstant& result,
275               UnaryFunction operation)               UnaryFunction operation)
276  {  {
277    //result.getPointDataView().getData()    //
278    // assign this to corresponding element in result    // perform the operation on the default data value
279    data.getPointDataView().dp_algorithm(operation);    // and assign this to the default element in result
280      result.getPointDataView().getData(0) =
281        data.getPointDataView().dp_algorithm(operation);
282  }  }
283
284  } // end of namespace  } // end of namespace

Legend:
 Removed from v.97 changed lines Added in v.106