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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 6 months ago) by jfenwick
File MIME type: text/plain
File size: 2364 byte(s)
Don't panic.
Updating copyright stamps

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26