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