[888] | 1 | /*! |
---|
| 2 | \file min.cpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 27 June 2016 |
---|
[1158] | 5 | \date 9 Jan 2017 |
---|
[888] | 6 | |
---|
| 7 | \brief min reduction |
---|
| 8 | */ |
---|
[979] | 9 | #include "min_reduction.hpp" |
---|
[1158] | 10 | #include "utils.hpp" |
---|
[888] | 11 | |
---|
| 12 | namespace xios { |
---|
| 13 | |
---|
| 14 | CMinReductionAlgorithm::CMinReductionAlgorithm() |
---|
| 15 | : CReductionAlgorithm() |
---|
| 16 | { |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | CReductionAlgorithm* CMinReductionAlgorithm::create() |
---|
| 20 | { |
---|
| 21 | return (new CMinReductionAlgorithm()); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | bool CMinReductionAlgorithm::registerTrans() |
---|
| 25 | { |
---|
| 26 | return registerOperation(TRANS_REDUCE_MIN, CMinReductionAlgorithm::create); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void CMinReductionAlgorithm::apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
| 30 | const double* dataInput, |
---|
| 31 | CArray<double,1>& dataOut, |
---|
[1158] | 32 | std::vector<bool>& flagInitial, |
---|
[1260] | 33 | bool ignoreMissingValue, bool firstPass) |
---|
[888] | 34 | { |
---|
[1158] | 35 | if (ignoreMissingValue) |
---|
[888] | 36 | { |
---|
[1158] | 37 | int nbLocalIndex = localIndex.size(); |
---|
| 38 | int currentlocalIndex = 0; |
---|
[1260] | 39 | if (firstPass) dataOut=std::numeric_limits<double>::quiet_NaN(); |
---|
[1158] | 40 | for (int idx = 0; idx < nbLocalIndex; ++idx) |
---|
[888] | 41 | { |
---|
[1158] | 42 | currentlocalIndex = localIndex[idx].first; |
---|
[1474] | 43 | if (!NumTraits<double>::isNan(*(dataInput + idx))) |
---|
[1158] | 44 | { |
---|
| 45 | if (flagInitial[currentlocalIndex]) |
---|
| 46 | { |
---|
| 47 | dataOut(currentlocalIndex) = *(dataInput + idx); |
---|
| 48 | flagInitial[currentlocalIndex] = false; |
---|
| 49 | } |
---|
| 50 | else |
---|
| 51 | { |
---|
| 52 | dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex)); |
---|
| 53 | } |
---|
| 54 | } |
---|
[888] | 55 | } |
---|
[1158] | 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | int nbLocalIndex = localIndex.size(); |
---|
| 60 | int currentlocalIndex = 0; |
---|
| 61 | for (int idx = 0; idx < nbLocalIndex; ++idx) |
---|
[888] | 62 | { |
---|
[1158] | 63 | currentlocalIndex = localIndex[idx].first; |
---|
| 64 | if (flagInitial[currentlocalIndex]) |
---|
| 65 | { |
---|
| 66 | dataOut(currentlocalIndex) = *(dataInput + idx); |
---|
| 67 | flagInitial[currentlocalIndex] = false; |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex)); |
---|
| 72 | } |
---|
[888] | 73 | } |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | } |
---|