[1984] | 1 | #include "weight_transform_connector.hpp" |
---|
| 2 | |
---|
| 3 | namespace xios |
---|
| 4 | { |
---|
| 5 | |
---|
[2267] | 6 | CWeightTransformConnector::CWeightTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, unordered_map<int, std::vector<int>>& indexMap, |
---|
[2313] | 7 | unordered_map<int, std::vector<double>>& weightMap, bool detectMissingValue, bool renormalize) : |
---|
| 8 | srcView_(srcView), dstView_(dstView), detectMissingValue_(detectMissingValue), renormalize_(renormalize) |
---|
[1984] | 9 | { |
---|
| 10 | computeConnector(indexMap, weightMap) ; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | void CWeightTransformConnector::computeConnector(unordered_map<int, std::vector<int>>& indexMap, |
---|
| 14 | unordered_map<int, std::vector<double>>& weightMap) |
---|
| 15 | { |
---|
| 16 | CArray<size_t,1> dstGlobalIndex ; |
---|
| 17 | CArray<size_t,1> srcGlobalIndex ; |
---|
| 18 | dstView_->getGlobalIndexView(dstGlobalIndex) ; |
---|
| 19 | srcView_->getGlobalIndexView(srcGlobalIndex) ; |
---|
| 20 | unordered_map<size_t,int> srcMapIndex ; |
---|
| 21 | srcSize_ = srcGlobalIndex.numElements() ; |
---|
| 22 | dstSize_ = dstGlobalIndex.numElements() ; |
---|
| 23 | |
---|
| 24 | for(int i=0;i<srcSize_;i++) srcMapIndex[srcGlobalIndex(i)]=i ; |
---|
| 25 | for(int i=0; i< dstSize_;i++) |
---|
| 26 | { |
---|
| 27 | if (indexMap.count(dstGlobalIndex(i))!=0 && weightMap.count(dstGlobalIndex(i))!=0) |
---|
| 28 | { |
---|
| 29 | auto& vectIndex = indexMap[dstGlobalIndex(i)] ; |
---|
| 30 | auto& vectWeight = weightMap[dstGlobalIndex(i)] ; |
---|
| 31 | nWeights_.push_back(vectIndex.size()) ; |
---|
| 32 | for(int j=0; j<vectIndex.size();j++) |
---|
| 33 | { |
---|
| 34 | connector_.push_back(srcMapIndex[vectIndex[j]]) ; |
---|
| 35 | weights_.push_back(vectWeight[j]) ; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | else nWeights_.push_back(0) ; |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | } |
---|