Escript  Revision_4320
UnaryOp.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #if !defined escript_UnaryOp_20040315_H
18 #define escript_UnaryOp_20040315_H
19 #include "system_dep.h"
20 
21 #include "DataConstant.h"
22 #include "DataTagged.h"
23 #include "DataExpanded.h"
24 #include "DataTypes.h"
25 
26 namespace escript {
27 
38 template <class UnaryFunction>
39 inline
40 void
42  UnaryFunction operation)
43 {
44  int i,j;
47  DataTypes::ValueType& left=data.getVectorRW();
48  const DataTypes::ShapeType& shape=data.getShape();
49  #pragma omp parallel for private(i,j) schedule(static)
50  for (i=0;i<numSamples;i++) {
51  for (j=0;j<numDPPSample;j++) {
52  DataMaths::unaryOp(left,shape,data.getPointOffset(i,j),operation);
53  }
54  }
55 }
56 
57 template <class UnaryFunction>
58 inline
59 void
61  UnaryFunction operation)
62 {
63  // perform the operation on each tagged value
64  const DataTagged::DataMapType& lookup=data.getTagLookup();
65  DataTagged::DataMapType::const_iterator i;
66  DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
67  DataTypes::ValueType& left=data.getVectorRW();
68  const DataTypes::ShapeType& shape=data.getShape();
69  for (i=lookup.begin();i!=lookupEnd;i++) {
70  DataMaths::unaryOp(left,shape,i->second,operation);
71  }
72  // perform the operation on the default value
73  DataMaths::unaryOp(left,shape,data.getDefaultOffset(),operation);
74 }
75 
76 template <class UnaryFunction>
77 inline
78 void
80  UnaryFunction operation)
81 {
82  DataMaths::unaryOp(data.getVectorRW(),data.getShape(),0,operation);
83 }
84 
85 } // end of namespace
86 #endif