escript  Revision_
UnaryOp.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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 
39 template <class UnaryFunction>
40 inline
41 void
43  UnaryFunction operation)
44 {
45  int i,j;
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
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
81  UnaryFunction operation)
82 {
83  DataMaths::unaryOp(data.getVectorRW(),data.getShape(),0,operation);
84 }
85 
86 } // end of namespace
87 #endif
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
virtual DataTypes::ValueType::size_type getPointOffset(int sampleNo, int dataPointNo) const
Return the offset for the given given data point. This returns the offset in bytes for the given poin...
Definition: DataExpanded.cpp:305
void unaryOp(DataExpanded &data, UnaryFunction operation)
Perform the given unary operation on each data point of the given Data object. Called by Data::unaryO...
Definition: UnaryOp.h:42
DataTypes::ValueType::size_type getDefaultOffset() const
Returns the offset in the structure which stores the default value.
Definition: DataTagged.h:608
Definition: AbstractContinuousDomain.cpp:24
DataConstant stores a single data point which represents the entire function space.
Definition: DataConstant.h:37
Give a short description of what DataExpanded does.
Definition: DataExpanded.h:44
const DataMapType & getTagLookup() const
getTagLookup
Definition: DataTagged.h:629
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:38
void unaryOp(DataTypes::ValueType &data, const DataTypes::ShapeType &shape, DataTypes::ValueType::size_type offset, UnaryFunction operation)
Perform the unary operation on the data point specified by the given offset. Applies the specified op...
Definition: DataMaths.h:826
Simulates a full dataset accessible via sampleNo and dataPointNo.
Definition: DataTagged.h:44
DataTypes::ValueType & getVectorRW()
Return a reference to the underlying DataVector.
Definition: DataTagged.cpp:890
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:562
std::map< int, int > DataMapType
Definition: DataTagged.h:57
DataTypes::ValueType & getVectorRW()
Return a reference to the underlying DataVector.
Definition: DataConstant.cpp:388
int getNumSamples() const
Return the number of samples.
Definition: DataAbstract.h:573
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition: DataAbstract.h:592
DataTypes::ValueType & getVectorRW()
Return a a reference to the underlying DataVector.
Definition: DataExpanded.cpp:749
long size_type
Definition: DataVector.h:60