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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4154 - (show annotations)
Tue Jan 22 09:30:23 2013 UTC (6 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 2483 byte(s)
Round 1 of copyright fixes
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
28 /**
29 \brief
30 Perform the given unary operation on each data point of the given Data object.
31 Called by Data::unaryOp.
32 Calls DataArrayView::unaryOp.
33 For DataExpanded objects, operation is done in parallel.
34 \param data Input/Output - The data.
35 \param operation Input - The operation to perform.
36 */
37
38 template <class UnaryFunction>
39 inline
40 void
41 unaryOp(DataExpanded& data,
42 UnaryFunction operation)
43 {
44 int i,j;
45 DataTypes::ValueType::size_type numDPPSample=data.getNumDPPSample();
46 DataTypes::ValueType::size_type numSamples=data.getNumSamples();
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
60 unaryOp(DataTagged& data,
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
79 unaryOp(DataConstant& data,
80 UnaryFunction operation)
81 {
82 DataMaths::unaryOp(data.getVectorRW(),data.getShape(),0,operation);
83 }
84
85 } // end of namespace
86 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26