/[escript]/branches/arrayview_from_1695_trunk/escript/src/UnaryOp.h
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/UnaryOp.h

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

revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC
# Line 1  Line 1 
1    // $Id$
2  /*  /*
3   ******************************************************************************   ******************************************************************************
4   *                                                                            *   *                                                                            *
# Line 12  Line 13 
13   ******************************************************************************   ******************************************************************************
14  */  */
15                                                                                                                                                        
16  #if !defined  escript_UnaryOp_20040315_H  #if !defined escript_UnaryOp_20040315_H
17  #define escript_UnaryOp_20040315_H  #define escript_UnaryOp_20040315_H
18    
19  #include "escript/Data/DataException.h"  #include "escript/Data/DataException.h"
# Line 30  namespace escript { Line 31  namespace escript {
31    
32  /**  /**
33     \brief     \brief
34     Perform the given unary operation.     Perform the given unary operation on each data point of the given Data object.
35       Called by Data::unaryOp.
36       Calls DataArrayView::unaryOp.
37       For DataExpanded objects, operation is done in parallel.
38     \param data Input/Output - The data.     \param data Input/Output - The data.
39  */  */
40    
41  template <class UnaryFunction>  template <class UnaryFunction>
42  inline void unaryOp(DataExpanded& data, UnaryFunction operation)  inline
43    void
44    unaryOp(DataExpanded& data,
45            UnaryFunction operation)
46  {  {
47    int i,j;    int i,j;
48    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
49    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
50  #pragma omp parallel for private(i,j) schedule(static)  #pragma omp parallel for private(i,j) schedule(static)
51     for (i=0;i<numSamples;++i) {    for (i=0;i<numSamples;i++) {
52       for (j=0;j<numDPPSample;++j) {      for (j=0;j<numDPPSample;j++) {
53        data.getPointDataView().unaryOp(data.getPointOffset(i,j),        data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
                   operation);  
54      }      }
55    }    }
56  }  }
57    
58  template <class UnaryFunction>  template <class UnaryFunction>
59  inline void unaryOp(DataTagged& data, UnaryFunction operation)  inline
60    void
61    unaryOp(DataTagged& data,
62            UnaryFunction operation)
63  {  {
64    //    // perform the operation on each tagged value
   // perform the operation on each tagged value including the default  
65    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
66    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
67    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
68    DataArrayView& dataView=data.getPointDataView();    DataArrayView& dataView=data.getPointDataView();
69    for (i=lookup.begin();i!=lookupEnd;++i) {    for (i=lookup.begin();i!=lookupEnd;i++) {
70      dataView.unaryOp(i->second,operation);      dataView.unaryOp(i->second,operation);
71    }    }
72    //    // perform the operation on the default value
   // finally perform the operation on the default value  
73    data.getDefaultValue().unaryOp(operation);    data.getDefaultValue().unaryOp(operation);
74  }  }
75    
76  template <class UnaryFunction>  template <class UnaryFunction>
77  inline void unaryOp(DataConstant& data, UnaryFunction operation)  inline
78    void
79    unaryOp(DataConstant& data,
80            UnaryFunction operation)
81  {  {
82    data.getPointDataView().unaryOp(operation);    data.getPointDataView().unaryOp(operation);
83  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26