Skip to content

Commit

Permalink
Merge pull request tesseract-ocr#2475 from stweil/std
Browse files Browse the repository at this point in the history
Add dot product implementation using std::inner_product
  • Loading branch information
zdenop authored May 31, 2019
2 parents 7b87389 + fefd521 commit ee2d717
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/arch/simddetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////

#include <numeric> // for std::inner_product
#include "simddetect.h"
#include "dotproduct.h"
#include "dotproductavx.h"
Expand Down Expand Up @@ -69,6 +70,11 @@ static double DotProductGeneric(const double* u, const double* v, int n) {
return total;
}

// Compute dot product using std::inner_product.
static double DotProductStdInnerProduct(const double* u, const double* v, int n) {
return std::inner_product(u, u + n, v, 0.0);
}

static void SetDotProduct(DotProductFunction f, const IntSimdMatrix* m = nullptr) {
DotProduct = f;
IntSimdMatrix::intSimdMatrix = m;
Expand Down Expand Up @@ -185,6 +191,10 @@ void SIMDDetect::Update() {
SetDotProduct(DotProductSSE, &IntSimdMatrix::intSimdMatrixSSE);
dotproduct_method = "sse";
#endif
} else if (!strcmp(dotproduct.string(), "std::inner_product")) {
// std::inner_product selected by config variable.
SetDotProduct(DotProductStdInnerProduct);
dotproduct_method = "std::inner_product";
} else {
// Unsupported value of config variable.
tprintf("Warning, ignoring unsupported config variable value: dotproduct=%s\n",
Expand All @@ -196,7 +206,7 @@ void SIMDDetect::Update() {
#if defined(SSE4_1)
" sse"
#endif
".\n");
" std::inner_product.\n");
}

dotproduct.set_value(dotproduct_method);
Expand Down

0 comments on commit ee2d717

Please sign in to comment.