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

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

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

trunk/esys2/escript/src/Data/UnaryOp.h revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC trunk/escript/src/Data/UnaryOp.h revision 155 by jgs, Wed Nov 9 02:02:19 2005 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       \param operation Input - The operation to perform.
40  */  */
41    
42  template <class UnaryFunction>  template <class UnaryFunction>
43  inline void unaryOp(DataExpanded& data, UnaryFunction operation)  inline
44    void
45    unaryOp(DataExpanded& data,
46            UnaryFunction operation)
47  {  {
48    int i,j;    int i,j;
49    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
50    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
51  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
52     for (i=0;i<numSamples;++i) {    for (i=0;i<numSamples;i++) {
53       for (j=0;j<numDPPSample;++j) {      for (j=0;j<numDPPSample;j++) {
54        data.getPointDataView().unaryOp(data.getPointOffset(i,j),        data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
                   operation);  
55      }      }
56    }    }
57  }  }
58    
59  template <class UnaryFunction>  template <class UnaryFunction>
60  inline void unaryOp(DataTagged& data, UnaryFunction operation)  inline
61    void
62    unaryOp(DataTagged& data,
63            UnaryFunction operation)
64  {  {
65    //    // perform the operation on each tagged value
   // perform the operation on each tagged value including the default  
66    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
67    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
68    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
69    DataArrayView& dataView=data.getPointDataView();    DataArrayView& dataView=data.getPointDataView();
70    for (i=lookup.begin();i!=lookupEnd;++i) {    for (i=lookup.begin();i!=lookupEnd;i++) {
71      dataView.unaryOp(i->second,operation);      dataView.unaryOp(i->second,operation);
72    }    }
73    //    // perform the operation on the default value
   // finally perform the operation on the default value  
74    data.getDefaultValue().unaryOp(operation);    data.getDefaultValue().unaryOp(operation);
75  }  }
76    
77  template <class UnaryFunction>  template <class UnaryFunction>
78  inline void unaryOp(DataConstant& data, UnaryFunction operation)  inline
79    void
80    unaryOp(DataConstant& data,
81            UnaryFunction operation)
82  {  {
83    data.getPointDataView().unaryOp(operation);    data.getPointDataView().unaryOp(operation);
84  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26