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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 697 - (hide annotations)
Fri Mar 31 04:48:56 2006 UTC (13 years, 7 months ago) by gross
File MIME type: text/plain
File size: 6347 byte(s)
bug with tagged data fixed
1 jgs 82 /*
2 elspeth 615 ************************************************************
3     * Copyright 2006 by ACcESS MNRF *
4     * *
5     * http://www.access.edu.au *
6     * Primary Business: Queensland, Australia *
7     * Licensed under the Open Software License version 3.0 *
8     * http://www.opensource.org/licenses/osl-3.0.php *
9     * *
10     ************************************************************
11    
12 jgs 82 */
13    
14     #if !defined escript_BinaryOp_20040315_H
15     #define escript_BinaryOp_20040315_H
16    
17 jgs 474 #include "DataArrayView.h"
18     #include "DataConstant.h"
19 jgs 478 #include "DataTagged.h"
20 jgs 474 #include "DataExpanded.h"
21 jgs 82
22     namespace escript {
23     /**
24     \brief
25     Perform the given binary operation.
26     \param left Input/Output - The left hand side.
27     \param right Input - The right hand side.
28 jgs 121 \param operation Input - The operation to perform.
29 jgs 82 */
30     template <class BinaryFunction>
31     inline void binaryOp(DataTagged& left, const DataConstant& right,
32     BinaryFunction operation)
33     {
34     binaryOp(left,right.getPointDataView(),operation);
35     }
36    
37     template <class BinaryFunction>
38     inline void binaryOp(DataTagged& left, const DataArrayView& right,
39     BinaryFunction operation)
40     {
41     //
42 jgs 154 // perform the operation on each tagged value
43 jgs 82 const DataTagged::DataMapType& lookup=left.getTagLookup();
44     DataTagged::DataMapType::const_iterator i;
45     DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
46     DataArrayView& leftView=left.getPointDataView();
47     if (right.getRank()==0) {
48 jgs 122 for (i=lookup.begin();i!=lookupEnd;i++) {
49 jgs 82 leftView.binaryOp(i->second,right(),operation);
50     }
51     } else {
52 jgs 122 for (i=lookup.begin();i!=lookupEnd;i++) {
53 jgs 82 leftView.binaryOp(i->second,right,right.getOffset(),operation);
54     }
55     }
56     //
57     // finally perform the operation on the default value
58 jgs 555 if (right.getRank()==0) {
59     left.getDefaultValue().binaryOp(0,right(),operation);
60     } else {
61     left.getDefaultValue().binaryOp(right,operation);
62     }
63 jgs 82 }
64    
65     template <class BinaryFunction>
66     inline void binaryOp(DataTagged& left, const DataTagged& right,
67     BinaryFunction operation)
68     {
69 gross 697 int right_rank=right.getPointDataView().getRank();
70 jgs 82 //
71     // Add the right hand tag keys which can't currently be found on the left
72     const DataTagged::DataMapType& rightLookup=right.getTagLookup();
73     DataTagged::DataMapType::const_iterator i;
74     DataTagged::DataMapType::const_iterator rightLookupEnd=rightLookup.end();
75 jgs 122 for (i=rightLookup.begin();i!=rightLookupEnd;i++) {
76 jgs 82 //
77 jgs 154 // If the left does not already have a value assigned to this tag,
78     // add the right hand tag to the left hand tag list and assign
79 jgs 543 // the left's default value.
80 jgs 154 if (!left.isCurrentTag(i->first)) {
81 jgs 543 left.addTaggedValue(i->first,left.getDefaultValue());
82 jgs 154 }
83 jgs 82 }
84     //
85 jgs 544 // Perform the operation.
86 jgs 82 const DataTagged::DataMapType& leftLookup=left.getTagLookup();
87     DataTagged::DataMapType::const_iterator leftLookupEnd=leftLookup.end();
88 jgs 122 for (i=leftLookup.begin();i!=leftLookupEnd;i++) {
89 gross 697 if (right_rank==0) {
90     left.getDataPointByTag(i->first).binaryOp(i->second,right.getDataPointByTag(i->first)(),operation);
91     } else {
92     left.getDataPointByTag(i->first).binaryOp(right.getDataPointByTag(i->first),operation);
93     }
94 jgs 82 }
95     //
96     // finally perform the operation on the default value
97 gross 697 if (right_rank==0) {
98     left.getDefaultValue().binaryOp(0,right.getDefaultValue()(),operation);
99     } else {
100     left.getDefaultValue().binaryOp(right.getDefaultValue(),operation);
101     }
102 jgs 82 }
103    
104     template <class BinaryFunction>
105     inline void binaryOp(DataConstant& left, const DataConstant& right,
106     BinaryFunction operation)
107     {
108     //
109     // As DataConstant there is only one point data
110     binaryOp(left,right.getPointDataView(),operation);
111     }
112    
113     template <class BinaryFunction>
114     inline void binaryOp(DataConstant& left, const DataArrayView& right,
115     BinaryFunction operation)
116     {
117     //
118     // perform an operand check, this will throw on error
119     if (right.getRank()==0) {
120     //
121     // special case of applying a single value to the entire array
122 jgs 122 left.getPointDataView().binaryOp(right(),operation);
123 jgs 82 } else {
124 jgs 122 left.getPointDataView().binaryOp(right,operation);
125 jgs 82 }
126     }
127    
128     template <class BinaryFunction>
129     inline void binaryOp(DataExpanded& left, const DataAbstract& right,
130     BinaryFunction operation)
131     {
132     int i,j;
133     DataArrayView::ValueType::size_type numDPPSample=left.getNumDPPSample();
134     DataArrayView::ValueType::size_type numSamples=left.getNumSamples();
135     if (right.getPointDataView().getRank()==0) {
136     //
137     // This will call the double version of binaryOp
138 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
139     for (i=0;i<numSamples;i++) {
140     for (j=0;j<numDPPSample;j++) {
141 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
142 jgs 122 right.getPointDataView().getData(right.getPointOffset(i,j)),
143     operation);
144 jgs 82 }
145     }
146     } else {
147 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
148     for (i=0;i<numSamples;i++) {
149     for (j=0;j<numDPPSample;j++) {
150 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
151     right.getPointDataView(),
152     right.getPointOffset(i,j),
153     operation);
154     }
155     }
156     }
157     }
158    
159     template <class BinaryFunction>
160     inline void binaryOp(DataExpanded& left, const DataArrayView& right,
161     BinaryFunction operation)
162     {
163     int i,j;
164     DataArrayView::ValueType::size_type numDPPSample=left.getNumDPPSample();
165     DataArrayView::ValueType::size_type numSamples=left.getNumSamples();
166     if (right.getRank()==0) {
167     //
168     // This will call the double version of binaryOp
169 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
170     for (i=0;i<numSamples;i++) {
171     for (j=0;j<numDPPSample;j++) {
172 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
173 jgs 122 right(),
174     operation);
175 jgs 82 }
176     }
177     } else {
178 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
179     for (i=0;i<numSamples;i++) {
180     for (j=0;j<numDPPSample;j++) {
181 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
182 jgs 122 right,
183     0,
184 jgs 82 operation);
185     }
186     }
187     }
188     }
189    
190     } // end of namespace
191 jgs 122
192 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26