Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "test_util.h"
 
class MlasFindMinMaxElementsTest : public MlasTestBase {
 private:
  MatrixGuardBuffer<float> BufferInput;
 
  void Test(size_t N, float MinimumValue, float MaximumValue) {
    float* Input = BufferInput.GetBuffer(N);
 
    std::default_random_engine generator(static_cast<unsigned>(N));
    std::uniform_real_distribution<float> distribution(MinimumValue, MaximumValue);
 
    for (size_t n = 0; n < N; n++) {
      Input[n] = distribution(generator);
    }
 
    auto min_max_pair = std::minmax_element(Input, Input + N);
    float min_ref = *min_max_pair.first;
    float max_ref = *min_max_pair.second;
 
    float min, max;
    MlasFindMinMaxElement(Input, &min, &max, N);
 
    constexpr float epsilon = 1e-6f;
 
    float diff_min = std::fabs(min - min_ref);
    ASSERT_LE(diff_min, epsilon) << " for minimum with parameter (" << N << "," << MinimumValue << "," << MaximumValue << ")";
 
    float diff_max = std::fabs(max - max_ref);
    ASSERT_LE(diff_max, epsilon) << " for maximum with parameter (" << N << "," << MinimumValue << "," << MaximumValue << ")";
  }
 
 public:
  static const char* GetTestSuiteName() {
    static const std::string suite_name("MinMaxElement");
    return suite_name.c_str();
  }
 
  void ExecuteShort(void) override {
    for (size_t n = 1; n < 128; n++) {
      Test(n, -10.f, 10.f);
    }
 
    // Lengths that span several vectors of the widest kernels, with tails of
    // every alignment: an RVV e32m4 group holds 128 floats at VLEN=1024, so
    // nothing below 128 crosses a group boundary there, and the accumulator
    // carry and the tail-undisturbed final group would go untested.
    for (size_t n : {128, 129, 255, 256, 257, 383, 1000, 1024, 1025, 4097}) {
      Test(n, -10.f, 10.f);
      Test(n, 0.f, 1.f);
    }
  }
};
 
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
 
static UNUSED_VARIABLE bool added_to_main = AddTestRegister([](bool is_short_execute) {
  return is_short_execute ? MlasDirectShortExecuteTests<MlasFindMinMaxElementsTest>::RegisterShortExecute() : 0;
});