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

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

  ViewVC Help
Powered by ViewVC 1.1.26