| 37 | { |
| 38 | template <typename T1, typename T2> |
| 39 | SimpleTensor<T2> accumulate(const SimpleTensor<T1> &src, DataType output_data_type) |
| 40 | { |
| 41 | SimpleTensor<T2> dst{src.shape(), output_data_type}; |
| 42 | |
| 43 | library->fill_tensor_uniform(dst, 1, static_cast<T2>(0), static_cast<T2>(std::numeric_limits<T1>::max())); |
| 44 | |
| 45 | using intermediate_type = typename common_promoted_signed_type<T1, T2>::intermediate_type; |
| 46 | #if defined(_OPENMP) |
| 47 | #pragma omp parallel for |
| 48 | #endif /* _OPENMP */ |
| 49 | for (int i = 0; i < src.num_elements(); ++i) |
| 50 | { |
| 51 | intermediate_type val = static_cast<intermediate_type>(src[i]) + static_cast<intermediate_type>(dst[i]); |
| 52 | dst[i] = saturate_cast<T2>(val); |
| 53 | } |
| 54 | |
| 55 | return dst; |
| 56 | } |
| 57 | |
| 58 | template <typename T1, typename T2> |
| 59 | SimpleTensor<T2> accumulate_weighted(const SimpleTensor<T1> &src, float alpha, DataType output_data_type) |