[1984] | 1 | #ifndef __WEIGHT_TRANSFORM_CONNECTOR_HPP__ |
---|
| 2 | #define __WEIGHT_TRANSFORM_CONNECTOR_HPP__ |
---|
| 3 | |
---|
| 4 | #include "xios_spl.hpp" |
---|
| 5 | #include "array_new.hpp" |
---|
| 6 | #include "local_view.hpp" |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | namespace xios |
---|
| 11 | { |
---|
| 12 | |
---|
| 13 | class CWeightTransformConnector |
---|
| 14 | { |
---|
| 15 | |
---|
| 16 | private: |
---|
[2267] | 17 | shared_ptr<CLocalView> srcView_; |
---|
| 18 | shared_ptr<CLocalView> dstView_; |
---|
[1984] | 19 | |
---|
| 20 | vector<double> weights_; // sizeof sum(nWeights_) |
---|
| 21 | vector<int> connector_; // sizeof sum(nWeights_) |
---|
| 22 | vector<int> nWeights_ ; // sizeof dstSize_ |
---|
| 23 | int srcSize_ ; |
---|
| 24 | int dstSize_ ; |
---|
| 25 | |
---|
| 26 | void computeConnector(unordered_map<int, std::vector<int>>& indexMap, unordered_map<int, std::vector<double>>& weightMap) ; |
---|
| 27 | |
---|
| 28 | public: |
---|
| 29 | |
---|
[2267] | 30 | CWeightTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, unordered_map<int, std::vector<int>>& indexMap, |
---|
[1984] | 31 | unordered_map<int, std::vector<double>>& weightMap) ; |
---|
| 32 | |
---|
| 33 | void transfer(int repeat, int sizeT, const CArray<double,1>& dataIn, CArray<double,1>& dataOut) |
---|
| 34 | { |
---|
| 35 | int dstSlice = dstSize_*sizeT ; |
---|
| 36 | int srcSlice = srcSize_*sizeT ; |
---|
| 37 | dataOut.resize(repeat* dstSlice) ; |
---|
| 38 | dataOut=0 ; // what to do about missing value => next step ? |
---|
| 39 | |
---|
| 40 | const double* input = dataIn.dataFirst() ; |
---|
| 41 | double* output = dataOut.dataFirst() ; |
---|
| 42 | |
---|
| 43 | for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice) |
---|
| 44 | { |
---|
| 45 | const double* in = input; |
---|
| 46 | double* out = output ; |
---|
| 47 | int k=0 ; |
---|
| 48 | for(int i=0; i<dstSize_; i++, out+=sizeT) |
---|
| 49 | for(int j=0 ; j<nWeights_[i] ; j++,k++) |
---|
| 50 | for(int l=0; l<sizeT; l++) out[l] += in[connector_[k]*sizeT+l]*weights_[k] ; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void transfer(int sizeT, const CArray<double,1>& dataIn, CArray<double,1>& dataOut) |
---|
| 55 | { |
---|
| 56 | transfer(1,sizeT, dataIn, dataOut) ; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void transfer(const CArray<double,1>& dataIn, CArray<double,1>& dataOut) |
---|
| 60 | { |
---|
| 61 | transfer(1,1,dataIn, dataOut) ; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | #endif |
---|