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