Skip to content

Commit

Permalink
test(math): test DFTBatch and CosetLDEBatch
Browse files Browse the repository at this point in the history
  • Loading branch information
ashjeong committed Jun 21, 2024
1 parent f5b0b3a commit 750e846
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tachyon/math/polynomials/univariate/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ tachyon_cc_unittest(
name = "univariate_unittests",
srcs = [
"lagrange_interpolation_unittest.cc",
"radix2_evaluation_domain_unittest.cc",
"univariate_dense_polynomial_unittest.cc",
"univariate_evaluation_domain_unittest.cc",
"univariate_evaluations_unittest.cc",
Expand All @@ -138,6 +139,7 @@ tachyon_cc_unittest(
deps = [
":lagrange_interpolation",
":mixed_radix_evaluation_domain",
":naive_batch_fft",
":radix2_evaluation_domain",
":univariate_polynomial",
"//tachyon/base:optional",
Expand All @@ -148,6 +150,8 @@ tachyon_cc_unittest(
"//tachyon/math/elliptic_curves/bls12/bls12_381:fr",
"//tachyon/math/elliptic_curves/bn/bn254:fr",
"//tachyon/math/elliptic_curves/bn/bn384_small_two_adicity:fq",
"//tachyon/math/finite_fields/baby_bear:packed_baby_bear",
"//tachyon/math/finite_fields/koala_bear:packed_koala_bear",
"//tachyon/math/finite_fields/test:finite_field_test",
"//tachyon/math/finite_fields/test:gf7",
"@com_google_absl//absl/hash:hash_testing",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "tachyon/math/polynomials/univariate/radix2_evaluation_domain.h"

#include <memory>

#include "gtest/gtest.h"

#include "tachyon/math/finite_fields/baby_bear/packed_baby_bear.h"
#include "tachyon/math/finite_fields/koala_bear/packed_koala_bear.h"
#include "tachyon/math/finite_fields/test/finite_field_test.h"
#include "tachyon/math/matrix/matrix_types.h"
#include "tachyon/math/polynomials/univariate/naive_batch_fft.h"

namespace tachyon::math {

namespace {

template <typename F>
class Radix2EvaluationDomainTest
: public FiniteFieldTest<
typename PackedPrimeFieldTraits<F>::PackedPrimeField> {};

} // namespace

using RangeTypes = testing::Types<BabyBear, KoalaBear>;
TYPED_TEST_SUITE(Radix2EvaluationDomainTest, RangeTypes);

TYPED_TEST(Radix2EvaluationDomainTest, DFTBatch) {
using F = TypeParam;
for (size_t log_r = 0; log_r < 5; ++log_r) {
RowMajorMatrix<F> expected = RowMajorMatrix<F>::Random(1 << log_r, 3);
RowMajorMatrix<F> result = expected;
NaiveBatchFFT<F>::DFTBatch(expected);
std::unique_ptr<Radix2EvaluationDomain<F>> domain =
Radix2EvaluationDomain<F>::Create(1 << log_r);
domain->DFTBatch(result);
EXPECT_EQ(expected, result);
}
}

TYPED_TEST(Radix2EvaluationDomainTest, CosetLDEBatch) {
using F = TypeParam;
const F shift = F::FromMontgomery(F::Config::kSubgroupGenerator);
for (size_t log_r = 0; log_r < 5; ++log_r) {
RowMajorMatrix<F> expected = RowMajorMatrix<F>::Random(1 << log_r, 3);
RowMajorMatrix<F> result = expected;
NaiveBatchFFT<F>::CosetLDEBatch(expected, 1, shift);
std::unique_ptr<Radix2EvaluationDomain<F>> domain =
Radix2EvaluationDomain<F>::Create(1 << log_r);
domain->CosetLDEBatch(result, 1, shift);
EXPECT_EQ(expected, result);
}
}

} // namespace tachyon::math

0 comments on commit 750e846

Please sign in to comment.