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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (hide annotations)
Mon Jan 30 04:23:44 2006 UTC (13 years, 9 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 jgs 102 // $Id$
2 jgs 82 /*
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 jgs 474
16 jgs 102 #if !defined escript_UnaryOp_20040315_H
17 jgs 82 #define escript_UnaryOp_20040315_H
18    
19 jgs 474 #include "DataException.h"
20     #include "DataArrayView.h"
21     #include "DataConstant.h"
22     #include "DataExpanded.h"
23     #include "DataTagged.h"
24 jgs 82
25 jgs 474 #include <boost/scoped_ptr.hpp>
26    
27 jgs 82 #include <iostream>
28     #include <functional>
29     #include <string>
30    
31     namespace escript {
32    
33     /**
34     \brief
35 jgs 102 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 jgs 82 \param data Input/Output - The data.
40 jgs 121 \param operation Input - The operation to perform.
41 jgs 82 */
42 jgs 102
43 jgs 82 template <class UnaryFunction>
44 jgs 102 inline
45     void
46     unaryOp(DataExpanded& data,
47     UnaryFunction operation)
48 jgs 82 {
49     int i,j;
50     DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
51     DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
52 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
53 jgs 102 for (i=0;i<numSamples;i++) {
54     for (j=0;j<numDPPSample;j++) {
55     data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
56 jgs 82 }
57     }
58     }
59    
60     template <class UnaryFunction>
61 jgs 102 inline
62     void
63     unaryOp(DataTagged& data,
64     UnaryFunction operation)
65 jgs 82 {
66 jgs 102 // perform the operation on each tagged value
67 jgs 82 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 jgs 102 for (i=lookup.begin();i!=lookupEnd;i++) {
72 jgs 82 dataView.unaryOp(i->second,operation);
73     }
74 jgs 102 // perform the operation on the default value
75 jgs 82 data.getDefaultValue().unaryOp(operation);
76     }
77    
78     template <class UnaryFunction>
79 jgs 102 inline
80     void
81     unaryOp(DataConstant& data,
82     UnaryFunction operation)
83 jgs 82 {
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