1 | /*! |
---|
2 | \file scalar_algorithm_reduce_scalar.cpp |
---|
3 | \author Ha NGUYEN |
---|
4 | \since 23 June 2016 |
---|
5 | \date 23 June 2016 |
---|
6 | |
---|
7 | \brief Algorithm for reduce an axis to a scalar |
---|
8 | */ |
---|
9 | #include "scalar_algorithm_reduce_axis.hpp" |
---|
10 | #include "axis.hpp" |
---|
11 | #include "scalar.hpp" |
---|
12 | #include "reduce_axis_to_scalar.hpp" |
---|
13 | #include "sum.hpp" |
---|
14 | |
---|
15 | namespace xios { |
---|
16 | |
---|
17 | CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CAxis* axisSource, CReduceAxisToScalar* algo) |
---|
18 | : CScalarAlgorithmTransformation(scalarDestination, axisSource), |
---|
19 | reduction_(0) |
---|
20 | { |
---|
21 | if (algo->operation.isEmpty()) |
---|
22 | ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)", |
---|
23 | << "Operation must be defined." |
---|
24 | << "Axis source " <<axisSource->getId() << std::endl |
---|
25 | << "Scalar destination " << scalarDestination->getId()); |
---|
26 | StdString op = algo->operation; |
---|
27 | if (CReductionAlgorithm::ReductionOperations.end() == CReductionAlgorithm::ReductionOperations.find(op)) |
---|
28 | ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)", |
---|
29 | << "Operation '" << op << "' not found. Please make sure to use a supported one" |
---|
30 | << "Axis source " <<axisSource->getId() << std::endl |
---|
31 | << "Scalar destination " << scalarDestination->getId()); |
---|
32 | |
---|
33 | reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]); |
---|
34 | } |
---|
35 | |
---|
36 | void CScalarAlgorithmReduceScalar::apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
37 | const double* dataInput, |
---|
38 | CArray<double,1>& dataOut, |
---|
39 | std::vector<bool>& flagInitial) |
---|
40 | { |
---|
41 | reduction_->apply(localIndex, dataInput, dataOut, flagInitial); |
---|
42 | } |
---|
43 | |
---|
44 | CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar() |
---|
45 | { |
---|
46 | if (0 != reduction_) delete reduction_; |
---|
47 | } |
---|
48 | |
---|
49 | void CScalarAlgorithmReduceScalar::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
50 | { |
---|
51 | this->transformationMapping_.resize(1); |
---|
52 | this->transformationWeight_.resize(1); |
---|
53 | |
---|
54 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
55 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
56 | |
---|
57 | CArray<int,1>& axisSrcIndex = axisSrc_->index; |
---|
58 | int globalIndexSize = axisSrcIndex.numElements(); |
---|
59 | |
---|
60 | for (int idx = 0; idx < globalIndexSize; ++idx) |
---|
61 | { |
---|
62 | transMap[0].push_back(axisSrcIndex(idx)); |
---|
63 | transWeight[0].push_back(1.0); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | } |
---|