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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 478 - (show annotations)
Tue Jan 31 02:21:49 2006 UTC (13 years, 10 months ago) by jgs
File MIME type: text/plain
File size: 2632 byte(s)
rationalise #includes

1 // $Id$
2 /*
3 ******************************************************************************
4 * *
5 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
6 * *
7 * This software is the property of ACcESS. No part of this code *
8 * may be copied in any form or by any means without the expressed written *
9 * consent of ACcESS. Copying, use or modification of this software *
10 * by any unauthorised person is illegal unless that person has a software *
11 * license agreement with ACcESS. *
12 * *
13 ******************************************************************************
14 */
15
16 #if !defined escript_UnaryOp_20040315_H
17 #define escript_UnaryOp_20040315_H
18
19 #include "DataArrayView.h"
20 #include "DataConstant.h"
21 #include "DataTagged.h"
22 #include "DataExpanded.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 DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
44 DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
45 #pragma omp parallel for private(i,j) schedule(static)
46 for (i=0;i<numSamples;i++) {
47 for (j=0;j<numDPPSample;j++) {
48 data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
49 }
50 }
51 }
52
53 template <class UnaryFunction>
54 inline
55 void
56 unaryOp(DataTagged& data,
57 UnaryFunction operation)
58 {
59 // perform the operation on each tagged value
60 const DataTagged::DataMapType& lookup=data.getTagLookup();
61 DataTagged::DataMapType::const_iterator i;
62 DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
63 DataArrayView& dataView=data.getPointDataView();
64 for (i=lookup.begin();i!=lookupEnd;i++) {
65 dataView.unaryOp(i->second,operation);
66 }
67 // perform the operation on the default value
68 data.getDefaultValue().unaryOp(operation);
69 }
70
71 template <class UnaryFunction>
72 inline
73 void
74 unaryOp(DataConstant& data,
75 UnaryFunction operation)
76 {
77 data.getPointDataView().unaryOp(operation);
78 }
79
80 } // end of namespace
81 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26