/[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 82 by jgs, Tue Oct 26 06:53:54 2004 UTC trunk/escript/src/UnaryOp.h revision 474 by jgs, Mon Jan 30 04:23:44 2006 UTC
# Line 1  Line 1 
1    // $Id$
2  /*  /*
3   ******************************************************************************   ******************************************************************************
4   *                                                                            *   *                                                                            *
# Line 11  Line 12 
12   *                                                                            *   *                                                                            *
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 "DataException.h"
20  #include "escript/Data/DataArrayView.h"  #include "DataArrayView.h"
21  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
22  #include "escript/Data/DataExpanded.h"  #include "DataExpanded.h"
23  #include "escript/Data/DataTagged.h"  #include "DataTagged.h"
24    
 #include <iostream>  
25  #include <boost/scoped_ptr.hpp>  #include <boost/scoped_ptr.hpp>
26    
27    #include <iostream>
28  #include <functional>  #include <functional>
29  #include <string>  #include <string>
30    
# Line 30  namespace escript { Line 32  namespace escript {
32    
33  /**  /**
34     \brief     \brief
35     Perform the given unary operation.     Perform the given unary operation on each data point of the given Data object.
36       Called by Data::unaryOp.
37       Calls DataArrayView::unaryOp.
38       For DataExpanded objects, operation is done in parallel.
39     \param data Input/Output - The data.     \param data Input/Output - The data.
40       \param operation Input - The operation to perform.
41  */  */
42    
43  template <class UnaryFunction>  template <class UnaryFunction>
44  inline void unaryOp(DataExpanded& data, UnaryFunction operation)  inline
45    void
46    unaryOp(DataExpanded& data,
47            UnaryFunction operation)
48  {  {
49    int i,j;    int i,j;
50    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
51    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
52  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
53     for (i=0;i<numSamples;++i) {    for (i=0;i<numSamples;i++) {
54       for (j=0;j<numDPPSample;++j) {      for (j=0;j<numDPPSample;j++) {
55        data.getPointDataView().unaryOp(data.getPointOffset(i,j),        data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
                   operation);  
56      }      }
57    }    }
58  }  }
59    
60  template <class UnaryFunction>  template <class UnaryFunction>
61  inline void unaryOp(DataTagged& data, UnaryFunction operation)  inline
62    void
63    unaryOp(DataTagged& data,
64            UnaryFunction operation)
65  {  {
66    //    // perform the operation on each tagged value
   // perform the operation on each tagged value including the default  
67    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
68    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
69    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
70    DataArrayView& dataView=data.getPointDataView();    DataArrayView& dataView=data.getPointDataView();
71    for (i=lookup.begin();i!=lookupEnd;++i) {    for (i=lookup.begin();i!=lookupEnd;i++) {
72      dataView.unaryOp(i->second,operation);      dataView.unaryOp(i->second,operation);
73    }    }
74    //    // perform the operation on the default value
   // finally perform the operation on the default value  
75    data.getDefaultValue().unaryOp(operation);    data.getDefaultValue().unaryOp(operation);
76  }  }
77    
78  template <class UnaryFunction>  template <class UnaryFunction>
79  inline void unaryOp(DataConstant& data, UnaryFunction operation)  inline
80    void
81    unaryOp(DataConstant& data,
82            UnaryFunction operation)
83  {  {
84    data.getPointDataView().unaryOp(operation);    data.getPointDataView().unaryOp(operation);
85  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26