/[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

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

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

  ViewVC Help
Powered by ViewVC 1.1.26