1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of this source tree. 7 */ 8 9 #include <executorch/extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_test_impl.h> 10 #include <executorch/extension/llm/custom_ops/spinquant/third-party/FFHT/dumb_fht.h> 11 12 #include <cmath> 13 #include <random> 14 #include <vector> 15 16 namespace executorch::runtime::testing { 17 reference_fht_impl(float * buf,int n)18void reference_fht_impl(float* buf, int n) { 19 dumb_fht(buf, std::log2<int>(n)); 20 const auto root_n = std::sqrt(n); 21 for (int ii = 0; ii < n; ++ii) { 22 buf[ii] /= root_n; 23 } 24 } 25 random_floats(int howMany)26std::vector<float> random_floats(int howMany) { 27 std::random_device rd; 28 std::mt19937 gen(rd()); 29 std::normal_distribution<float> dist; 30 std::vector<float> data(howMany); 31 for (int ii = 0; ii < data.size(); ++ii) { 32 data[ii] = dist(gen); 33 } 34 return data; 35 } 36 37 } // namespace executorch::runtime::testing 38