[1999] | 1 | #include "reduce_transform_connector.hpp" |
---|
| 2 | #include "exception.hpp" |
---|
| 3 | |
---|
| 4 | namespace xios |
---|
| 5 | { |
---|
| 6 | |
---|
[2267] | 7 | CReduceTransformConnector::CReduceTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, EReduction op, |
---|
[1999] | 8 | unordered_map<int, std::vector<int>>& indexMap, bool detectMissingValue) |
---|
| 9 | : srcView_(srcView), dstView_(dstView), detectMissingValue_(detectMissingValue) |
---|
| 10 | { |
---|
| 11 | switch(op) |
---|
| 12 | { |
---|
| 13 | case EReduction::sum : |
---|
| 14 | transfer_=&CReduceTransformConnector::transferSum ; |
---|
| 15 | break ; |
---|
| 16 | case EReduction::min : |
---|
[2000] | 17 | transfer_=&CReduceTransformConnector::transferMin ; |
---|
[1999] | 18 | break ; |
---|
| 19 | case EReduction::max : |
---|
[2000] | 20 | transfer_=&CReduceTransformConnector::transferMax ; |
---|
[1999] | 21 | break ; |
---|
[2000] | 22 | case EReduction::average : |
---|
| 23 | transfer_=&CReduceTransformConnector::transferAverage ; |
---|
[1999] | 24 | break ; |
---|
| 25 | default : |
---|
| 26 | ERROR("CReduceTransformConnector::CReduceTransformConnector", |
---|
| 27 | <<"reduction operator "<<(int)op<<" is not defined for this operation") ; |
---|
| 28 | break ; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | computeConnector(indexMap) ; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void CReduceTransformConnector::computeConnector(unordered_map<int, std::vector<int>>& indexMap) |
---|
| 35 | { |
---|
| 36 | CArray<size_t,1> dstGlobalIndex ; |
---|
| 37 | CArray<size_t,1> srcGlobalIndex ; |
---|
| 38 | dstView_->getGlobalIndexView(dstGlobalIndex) ; |
---|
| 39 | srcView_->getGlobalIndexView(srcGlobalIndex) ; |
---|
| 40 | unordered_map<size_t,int> srcMapIndex ; |
---|
| 41 | srcSize_ = srcGlobalIndex.numElements() ; |
---|
| 42 | dstSize_ = dstGlobalIndex.numElements() ; |
---|
| 43 | |
---|
| 44 | for(int i=0;i<srcSize_;i++) srcMapIndex[srcGlobalIndex(i)]=i ; |
---|
| 45 | for(int i=0; i< dstSize_;i++) |
---|
| 46 | { |
---|
| 47 | if (indexMap.count(dstGlobalIndex(i))!=0) |
---|
| 48 | { |
---|
| 49 | auto& vectIndex = indexMap[dstGlobalIndex(i)] ; |
---|
| 50 | nSrc_.push_back(vectIndex.size()) ; |
---|
| 51 | for(int j=0; j<vectIndex.size();j++) connector_.push_back(srcMapIndex[vectIndex[j]]) ; |
---|
| 52 | } |
---|
| 53 | else nSrc_.push_back(0) ; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | } |
---|