source: XIOS/trunk/src/transformation/Functions/reduction.cpp @ 895

Last change on this file since 895 was 895, checked in by mhnguyen, 6 years ago

Adding a new transformation: Reduce a domain to an axis

Test
+) On Curie
+) Tests pass and are correct

File size: 1.8 KB
Line 
1#include "reduction.hpp"
2#include "sum.hpp"
3#include "min.hpp"
4#include "max.hpp"
5#include "extract.hpp"
6
7namespace xios {
8
9CReductionAlgorithm::CallBackMap* CReductionAlgorithm::reductionCreationCallBacks_ = 0;
10std::map<StdString,EReductionType> CReductionAlgorithm::ReductionOperations = std::map<StdString,EReductionType>();
11bool CReductionAlgorithm::initReductionOperation(std::map<StdString,EReductionType>& m)
12{
13  // So so stupid way to intialize operation but it works ...
14  m["sum"] = TRANS_REDUCE_SUM;
15  CSumReductionAlgorithm::registerTrans();
16
17  m["min"] = TRANS_REDUCE_MIN;
18  CMinReductionAlgorithm::registerTrans();
19
20  m["max"] = TRANS_REDUCE_MAX;
21  CMaxReductionAlgorithm::registerTrans();
22
23  m["extract"] = TRANS_REDUCE_EXTRACT;
24  CExtractReductionAlgorithm::registerTrans();
25}
26
27bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations);
28
29CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType)
30{
31  int reduceTypeInt = reduceType;
32  typename CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType);
33  if ((*reductionCreationCallBacks_).end() == it)
34  {
35     ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)",
36           << "Operation type " << reduceType
37           << "doesn't exist. Please define.");
38  }
39  return (it->second)();
40}
41
42bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn)
43{
44  if (0 == reductionCreationCallBacks_)
45    reductionCreationCallBacks_ = new CallBackMap();
46
47  return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second;
48}
49
50bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType)
51{
52  int reduceTypeInt = reduceType;
53  return (1 == (*reductionCreationCallBacks_).erase(reduceType));
54}
55
56
57}
Note: See TracBrowser for help on using the repository browser.