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

Diff of /trunk/escript/src/DataAlgorithm.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/escript/src/DataAlgorithm.h revision 478 by jgs, Tue Jan 31 02:21:49 2006 UTC temp/escript/src/DataAlgorithm.h revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /* $Id$ */
3   ******************************************************************************  
4   *                                                                            *  /*******************************************************
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *
6   *                                                                            *   *           Copyright 2003-2007 by ACceSS MNRF
7   * This software is the property of ACcESS. No part of this code              *   *       Copyright 2007 by University of Queensland
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          *   *                http://esscc.uq.edu.au
10   * by any unauthorised person is illegal unless that person has a software    *   *        Primary Business: Queensland, Australia
11   * license agreement with ACcESS.                                             *   *  Licensed under the Open Software License version 3.0
12   *                                                                            *   *     http://www.opensource.org/licenses/osl-3.0.php
13   ******************************************************************************   *
14  */   *******************************************************/
15                                                                              
16  #if !defined escript_DataAlgorithm_20040714_H  #if !defined escript_DataAlgorithm_20040714_H
17  #define escript_DataAlgorithm_20040714_H  #define escript_DataAlgorithm_20040714_H
18    #include "system_dep.h"
19    
20  #include "DataArrayView.h"  #include "DataArrayView.h"
21  #include "DataExpanded.h"  #include "DataExpanded.h"
# Line 23  Line 24 
24    
25  #include <iostream>  #include <iostream>
26  #include <algorithm>  #include <algorithm>
 #include <math.h>  
27    
28  namespace escript {  namespace escript {
29    
# Line 192  algorithm(DataTagged& data, Line 192  algorithm(DataTagged& data,
192            BinaryFunction operation,            BinaryFunction operation,
193        double initial_value)        double initial_value)
194  {  {
   const DataTagged::DataMapType& lookup=data.getTagLookup();  
   DataTagged::DataMapType::const_iterator i;  
   DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();  
   DataArrayView& dataView=data.getPointDataView();  
195    double current_value=initial_value;    double current_value=initial_value;
196    // perform the operation on each tagged value    // perform the operation on each tagged value
197    for (i=lookup.begin();i!=lookupEnd;i++) {    DataArrayView& dataView=data.getPointDataView();
198      const DataTagged::DataMapType& lookup=data.getTagLookup();
199      for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
200      current_value=operation(current_value,dataView.reductionOp(i->second,operation,initial_value));      current_value=operation(current_value,dataView.reductionOp(i->second,operation,initial_value));
201    }    }
202    // perform the operation on the default value    // perform the operation on the default value
# Line 259  dp_algorithm(DataTagged& data, Line 257  dp_algorithm(DataTagged& data,
257               BinaryFunction operation,               BinaryFunction operation,
258           double initial_value)           double initial_value)
259  {  {
260    const DataTagged::DataMapType& lookup=data.getTagLookup();    // perform the operation on each tagged value in data
   DataTagged::DataMapType::const_iterator i;  
   DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();  
   DataArrayView dataView=data.getPointDataView();  
   DataArrayView resultView=result.getPointDataView();  
   // perform the operation on each tagged data value  
261    // and assign this to the corresponding element in result    // and assign this to the corresponding element in result
262    for (i=lookup.begin();i!=lookupEnd;i++) {    const DataTagged::DataMapType& lookup=data.getTagLookup();
263      resultView.getData(i->second) =    for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
264        dataView.reductionOp(i->second,operation,initial_value);      result.getDataPointByTag(i->first).getData(0) =
265          data.getDataPointByTag(i->first).reductionOp(operation,initial_value);
266    }    }
267    // perform the operation on the default data value    // perform the operation on the default data value
268    // and assign this to the default element in result    // and assign this to the default element in result
269    resultView.getData(0) =    result.getDefaultValue().getData(0) =
270      data.getDefaultValue().reductionOp(operation,initial_value);      data.getDefaultValue().reductionOp(operation,initial_value);
271  }  }
272    

Legend:
Removed from v.478  
changed lines
  Added in v.1387

  ViewVC Help
Powered by ViewVC 1.1.26