ESYS13
Revision_
|
00001 00002 /******************************************************* 00003 * 00004 * Copyright (c) 2003-2012 by University of Queensland 00005 * Earth Systems Science Computational Center (ESSCC) 00006 * http://www.uq.edu.au/esscc 00007 * 00008 * Primary Business: Queensland, Australia 00009 * Licensed under the Open Software License version 3.0 00010 * http://www.opensource.org/licenses/osl-3.0.php 00011 * 00012 *******************************************************/ 00013 00014 00015 #if !defined escript_UnaryOp_20040315_H 00016 #define escript_UnaryOp_20040315_H 00017 #include "system_dep.h" 00018 00019 #include "DataConstant.h" 00020 #include "DataTagged.h" 00021 #include "DataExpanded.h" 00022 #include "DataTypes.h" 00023 00024 namespace escript { 00025 00036 template <class UnaryFunction> 00037 inline 00038 void 00039 unaryOp(DataExpanded& data, 00040 UnaryFunction operation) 00041 { 00042 int i,j; 00043 DataTypes::ValueType::size_type numDPPSample=data.getNumDPPSample(); 00044 DataTypes::ValueType::size_type numSamples=data.getNumSamples(); 00045 DataTypes::ValueType& left=data.getVectorRW(); 00046 const DataTypes::ShapeType& shape=data.getShape(); 00047 #pragma omp parallel for private(i,j) schedule(static) 00048 for (i=0;i<numSamples;i++) { 00049 for (j=0;j<numDPPSample;j++) { 00050 DataMaths::unaryOp(left,shape,data.getPointOffset(i,j),operation); 00051 } 00052 } 00053 } 00054 00055 template <class UnaryFunction> 00056 inline 00057 void 00058 unaryOp(DataTagged& data, 00059 UnaryFunction operation) 00060 { 00061 // perform the operation on each tagged value 00062 const DataTagged::DataMapType& lookup=data.getTagLookup(); 00063 DataTagged::DataMapType::const_iterator i; 00064 DataTagged::DataMapType::const_iterator lookupEnd=lookup.end(); 00065 DataTypes::ValueType& left=data.getVectorRW(); 00066 const DataTypes::ShapeType& shape=data.getShape(); 00067 for (i=lookup.begin();i!=lookupEnd;i++) { 00068 DataMaths::unaryOp(left,shape,i->second,operation); 00069 } 00070 // perform the operation on the default value 00071 DataMaths::unaryOp(left,shape,data.getDefaultOffset(),operation); 00072 } 00073 00074 template <class UnaryFunction> 00075 inline 00076 void 00077 unaryOp(DataConstant& data, 00078 UnaryFunction operation) 00079 { 00080 DataMaths::unaryOp(data.getVectorRW(),data.getShape(),0,operation); 00081 } 00082 00083 } // end of namespace 00084 #endif