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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (show annotations)
Mon Jan 30 04:23:44 2006 UTC (13 years, 8 months ago) by jgs
File MIME type: text/plain
File size: 2753 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

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 "DataException.h"
20 #include "DataArrayView.h"
21 #include "DataConstant.h"
22 #include "DataExpanded.h"
23 #include "DataTagged.h"
24
25 #include <boost/scoped_ptr.hpp>
26
27 #include <iostream>
28 #include <functional>
29 #include <string>
30
31 namespace escript {
32
33 /**
34 \brief
35 Perform the given unary operation on each data point of the given Data object.
36 Called by Data::unaryOp.
37 Calls DataArrayView::unaryOp.
38 For DataExpanded objects, operation is done in parallel.
39 \param data Input/Output - The data.
40 \param operation Input - The operation to perform.
41 */
42
43 template <class UnaryFunction>
44 inline
45 void
46 unaryOp(DataExpanded& data,
47 UnaryFunction operation)
48 {
49 int i,j;
50 DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
51 DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
52 #pragma omp parallel for private(i,j) schedule(static)
53 for (i=0;i<numSamples;i++) {
54 for (j=0;j<numDPPSample;j++) {
55 data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
56 }
57 }
58 }
59
60 template <class UnaryFunction>
61 inline
62 void
63 unaryOp(DataTagged& data,
64 UnaryFunction operation)
65 {
66 // perform the operation on each tagged value
67 const DataTagged::DataMapType& lookup=data.getTagLookup();
68 DataTagged::DataMapType::const_iterator i;
69 DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
70 DataArrayView& dataView=data.getPointDataView();
71 for (i=lookup.begin();i!=lookupEnd;i++) {
72 dataView.unaryOp(i->second,operation);
73 }
74 // perform the operation on the default value
75 data.getDefaultValue().unaryOp(operation);
76 }
77
78 template <class UnaryFunction>
79 inline
80 void
81 unaryOp(DataConstant& data,
82 UnaryFunction operation)
83 {
84 data.getPointDataView().unaryOp(operation);
85 }
86
87 } // end of namespace
88 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26