21#include <tesseract/genericvector.h>
33 std::locale::global(std::locale(
""));
37 GENERIC_2D_ARRAY<int8_t>
InitRandom(
int no,
int ni) {
38 GENERIC_2D_ARRAY<int8_t> a(no, ni, 0);
39 for (
int i = 0;
i < no; ++
i) {
40 for (
int j = 0; j < ni; ++j) {
41 a(
i, j) =
static_cast<int8_t
>(
random_.SignedRand(INT8_MAX));
47 std::vector<int8_t>
RandomVector(
int size,
const IntSimdMatrix& matrix) {
48 int rounded_size = matrix.RoundInputs(size);
49 std::vector<int8_t> v(rounded_size, 0);
50 for (
int i = 0;
i < size; ++
i) {
51 v[
i] =
static_cast<int8_t
>(
random_.SignedRand(INT8_MAX));
57 GenericVector<double> v(size, 0.0);
58 for (
int i = 0;
i < size; ++
i) {
59 v[
i] = 1.0 +
random_.SignedRand(1.0);
66 for (
int num_out = 1; num_out < 130; ++num_out) {
67 for (
int num_in = 1; num_in < 130; ++num_in) {
68 GENERIC_2D_ARRAY<int8_t> w =
InitRandom(num_out, num_in + 1);
71 std::vector<double> base_result(num_out);
73 std::vector<double> test_result(num_out);
74 std::vector<int8_t> shaped_wi;
75 matrix.Init(w, shaped_wi);
76 if (matrix.matrixDotVectorFunction) {
77 matrix.matrixDotVectorFunction(w.dim1(), w.dim2(), &shaped_wi[0],
78 &scales[0], &u[0], &test_result[0]);
82 for (
int i = 0;
i < num_out; ++
i) {
84 total += base_result[
i];
96TEST_F(IntSimdMatrixTest, C) {
97 static const IntSimdMatrix matrix = {
nullptr, 1, 1, 1, 1};
98 ExpectEqualResults(matrix);
102TEST_F(IntSimdMatrixTest, SSE) {
103#if defined(HAVE_SSE4_1)
116TEST_F(IntSimdMatrixTest, AVX2) {
117#if defined(HAVE_AVX2)
#define EXPECT_FLOAT_EQ(val1, val2)
#define GTEST_LOG_(severity)
TEST_F(EuroText, FastLatinOCR)
static const IntSimdMatrix intSimdMatrixAVX2
static void MatrixDotVector(const GENERIC_2D_ARRAY< int8_t > &w, const std::vector< TFloat > &scales, const int8_t *u, TFloat *v)
static const IntSimdMatrix intSimdMatrixSSE
static bool IsSSEAvailable()
static bool IsAVX2Available()
std::vector< int8_t > RandomVector(int size, const IntSimdMatrix &matrix)
std::vector< TFloat > RandomScales(int size)
void ExpectEqualResults(const IntSimdMatrix &matrix)
GENERIC_2D_ARRAY< int8_t > InitRandom(int no, int ni)