/[escript]/branches/subworld2/escriptcore/src/UnaryOp.h
ViewVC logotype

Contents of /branches/subworld2/escriptcore/src/UnaryOp.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5504 - (show annotations)
Wed Mar 4 22:58:13 2015 UTC (4 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 2551 byte(s)
Again with a more up to date copy


1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2015 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 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 #if !defined escript_UnaryOp_20040315_H
19 #define escript_UnaryOp_20040315_H
20 #include "system_dep.h"
21
22 #include "DataConstant.h"
23 #include "DataTagged.h"
24 #include "DataExpanded.h"
25 #include "DataTypes.h"
26
27 namespace escript {
28
29 /**
30 \brief
31 Perform the given unary operation on each data point of the given Data object.
32 Called by Data::unaryOp.
33 Calls DataArrayView::unaryOp.
34 For DataExpanded objects, operation is done in parallel.
35 \param data Input/Output - The data.
36 \param operation Input - The operation to perform.
37 */
38
39 template <class UnaryFunction>
40 inline
41 void
42 unaryOp(DataExpanded& data,
43 UnaryFunction operation)
44 {
45 int i,j;
46 DataTypes::ValueType::size_type numDPPSample=data.getNumDPPSample();
47 DataTypes::ValueType::size_type numSamples=data.getNumSamples();
48 DataTypes::ValueType& left=data.getVectorRW();
49 const DataTypes::ShapeType& shape=data.getShape();
50 #pragma omp parallel for private(i,j) schedule(static)
51 for (i=0;i<numSamples;i++) {
52 for (j=0;j<numDPPSample;j++) {
53 DataMaths::unaryOp(left,shape,data.getPointOffset(i,j),operation);
54 }
55 }
56 }
57
58 template <class UnaryFunction>
59 inline
60 void
61 unaryOp(DataTagged& data,
62 UnaryFunction operation)
63 {
64 // perform the operation on each tagged value
65 const DataTagged::DataMapType& lookup=data.getTagLookup();
66 DataTagged::DataMapType::const_iterator i;
67 DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
68 DataTypes::ValueType& left=data.getVectorRW();
69 const DataTypes::ShapeType& shape=data.getShape();
70 for (i=lookup.begin();i!=lookupEnd;i++) {
71 DataMaths::unaryOp(left,shape,i->second,operation);
72 }
73 // perform the operation on the default value
74 DataMaths::unaryOp(left,shape,data.getDefaultOffset(),operation);
75 }
76
77 template <class UnaryFunction>
78 inline
79 void
80 unaryOp(DataConstant& data,
81 UnaryFunction operation)
82 {
83 DataMaths::unaryOp(data.getVectorRW(),data.getShape(),0,operation);
84 }
85
86 } // end of namespace
87 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26