dot_product_simple.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <util/system/compiler.h>
  3. #include <util/system/types.h>
  4. #include <numeric>
  5. /**
  6. * Dot product implementation without SSE optimizations.
  7. */
  8. Y_PURE_FUNCTION
  9. inline ui32 DotProductSimple(const ui8* lhs, const ui8* rhs, size_t length) noexcept {
  10. return std::inner_product(lhs, lhs + length, rhs, static_cast<ui32>(0u),
  11. [](ui32 x1, ui16 x2) {return x1 + x2;},
  12. [](ui16 x1, ui8 x2) {return x1 * x2;});
  13. }
  14. Y_PURE_FUNCTION
  15. inline i32 DotProductSimple(const i8* lhs, const i8* rhs, size_t length) noexcept {
  16. return std::inner_product(lhs, lhs + length, rhs, static_cast<i32>(0),
  17. [](i32 x1, i16 x2) {return x1 + x2;},
  18. [](i16 x1, i8 x2) {return x1 * x2;});
  19. }
  20. Y_PURE_FUNCTION
  21. inline i64 DotProductSimple(const i32* lhs, const i32* rhs, size_t length) noexcept {
  22. return std::inner_product(lhs, lhs + length, rhs, static_cast<i64>(0),
  23. [](i64 x1, i64 x2) {return x1 + x2;},
  24. [](i64 x1, i32 x2) {return x1 * x2;});
  25. }
  26. Y_PURE_FUNCTION
  27. float DotProductSimple(const float* lhs, const float* rhs, size_t length) noexcept;
  28. Y_PURE_FUNCTION
  29. double DotProductSimple(const double* lhs, const double* rhs, size_t length) noexcept;
  30. Y_PURE_FUNCTION
  31. ui32 DotProductUI4Simple(const ui8* lhs, const ui8* rhs, size_t lengtInBytes) noexcept;