# Diff of /trunk/escript/src/Data.h

revision 146 by jgs, Fri Jul 22 03:53:08 2005 UTC revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC
# Line 983  class Data { Line 983  class Data {
983       Perform the specified reduction algorithm on every element of every data point in       Perform the specified reduction algorithm on every element of every data point in
984       this Data object according to the given function and return the single value result.       this Data object according to the given function and return the single value result.
985    */    */
986    template <class UnaryFunction>    template <class BinaryFunction>
987    inline    inline
988    double    double
989    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
990                double initial_value) const;
991
992    /**    /**
993       \brief       \brief
# Line 995  class Data { Line 996  class Data {
996       one value - the result of the reduction operation on the corresponding data-point in       one value - the result of the reduction operation on the corresponding data-point in
997       this Data object       this Data object
998    */    */
999    template <class UnaryFunction>    template <class BinaryFunction>
1000    inline    inline
1001    Data    Data
1002    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1003                   double initial_value) const;
1004
1005    /**    /**
1006       \brief       \brief
# Line 1364  Data::unaryOp(UnaryFunction operation) Line 1366  Data::unaryOp(UnaryFunction operation)
1366    object (*this) is a rank n Data object, and returned object is a scalar.    object (*this) is a rank n Data object, and returned object is a scalar.
1367    Calls escript::algorithm.    Calls escript::algorithm.
1368  */  */
1369  template <class UnaryFunction>  template <class BinaryFunction>
1370  inline  inline
1371  double  double
1372  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1373  {  {
1374    if (isExpanded()) {    if (isExpanded()) {
1375      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1376      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1377      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1378    } else if (isTagged()) {    } else if (isTagged()) {
1379      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1380      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1381      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1382    } else if (isConstant()) {    } else if (isConstant()) {
1383      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1384      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1385      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1386    }    }
1387    return 0;    return 0;
1388  }  }
# Line 1393  Data::algorithm(UnaryFunction operation) Line 1395  Data::algorithm(UnaryFunction operation)
1395    rank 0 Data object.    rank 0 Data object.
1396    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1397  */  */
1398  template <class UnaryFunction>  template <class BinaryFunction>
1399  inline  inline
1400  Data  Data
1401  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1402  {  {
1403    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1404    if (isExpanded()) {    if (isExpanded()) {
# Line 1404  Data::dp_algorithm(UnaryFunction operati Line 1406  Data::dp_algorithm(UnaryFunction operati
1406      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1407      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1408      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1409      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1410    } else if (isTagged()) {    } else if (isTagged()) {
1411      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1412      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1413      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1414      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1415      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1416    } else if (isConstant()) {    } else if (isConstant()) {
1417      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1418      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1419      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1420      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1421      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1422    }    }
1423    return result;    return result;
1424  }  }

Legend:
 Removed from v.146 changed lines Added in v.147