Skip to content

Commit

Permalink
Fix the input to Hadamard functions in unit test
Browse files Browse the repository at this point in the history
The input to Hadamard transform is the residual block, whose pixels
can range from -((1 << BitDepth) - 1) to (1 << BitDepth) - 1. Earlier
values from -(1 << BitDepth) to (1 << BitDepth) - 1 were  being tested.
As -(1 << BitDepth) is not a valid value, changed the input to take
values in the range [-((1 << BitDepth) - 1), ((1 << BitDepth) - 1)].

The functions Rand9Signed() and Rand13Signed are deleted since they
are not used by any other caller.

Change-Id: I10b358a2ff7168ac595849d3c78a91cfa6b3b24d
  • Loading branch information
anupampandey-ittiam authored and wantehchang committed Jun 23, 2023
1 parent d2e0b70 commit 57dd20a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
12 changes: 0 additions & 12 deletions test/acm_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,13 @@ class ACMRandom {
return static_cast<int16_t>(Rand15()) - (1 << 14);
}

int16_t Rand13Signed() {
// Use 13 bits: values between 4095 and -4096.
const uint32_t value = random_.Generate(8192);
return static_cast<int16_t>(value) - 4096;
}

uint16_t Rand12() {
const uint32_t value =
random_.Generate(testing::internal::Random::kMaxRange);
// There's a bit more entropy in the upper bits of this implementation.
return (value >> 19) & 0xfff;
}

int16_t Rand9Signed() {
// Use 9 bits: values between 255 (0x0FF) and -256 (0x100).
const uint32_t value = random_.Generate(512);
return static_cast<int16_t>(value) - 256;
}

uint8_t Rand8() {
const uint32_t value =
random_.Generate(testing::internal::Random::kMaxRange);
Expand Down
34 changes: 30 additions & 4 deletions test/hadamard_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ class HadamardTestBase

virtual void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }

// The Rand() function generates values in the range [-((1 << BitDepth) - 1),
// (1 << BitDepth) - 1]. This is because the input to the Hadamard transform
// is the residual pixel, which is defined as 'source pixel - predicted
// pixel'. Source pixel and predicted pixel take values in the range
// [0, (1 << BitDepth) - 1] and thus the residual pixel ranges from
// -((1 << BitDepth) - 1) to ((1 << BitDepth) - 1).
virtual int16_t Rand() = 0;

void CompareReferenceRandom() {
Expand Down Expand Up @@ -344,7 +350,12 @@ class HadamardTestBase
class HadamardLowbdTest : public HadamardTestBase<tran_low_t, HadamardFunc> {
public:
HadamardLowbdTest() : HadamardTestBase(GetParam(), /*do_shift=*/true) {}
virtual int16_t Rand() { return rnd_.Rand9Signed(); }
// Use values between -255 (0xFF01) and 255 (0x00FF)
virtual int16_t Rand() {
int16_t src = rnd_.Rand8();
int16_t pred = rnd_.Rand8();
return src - pred;
}
};

TEST_P(HadamardLowbdTest, CompareReferenceRandom) { CompareReferenceRandom(); }
Expand Down Expand Up @@ -395,7 +406,12 @@ INSTANTIATE_TEST_SUITE_P(
class HadamardHighbdTest : public HadamardTestBase<tran_low_t, HadamardFunc> {
protected:
HadamardHighbdTest() : HadamardTestBase(GetParam(), /*do_shift=*/true) {}
virtual int16_t Rand() { return rnd_.Rand13Signed(); }
// Use values between -4095 (0xF001) and 4095 (0x0FFF)
virtual int16_t Rand() {
int16_t src = rnd_.Rand12();
int16_t pred = rnd_.Rand12();
return src - pred;
}
};

TEST_P(HadamardHighbdTest, CompareReferenceRandom) { CompareReferenceRandom(); }
Expand Down Expand Up @@ -430,7 +446,12 @@ INSTANTIATE_TEST_SUITE_P(
class HadamardLowbdLPTest : public HadamardTestBase<int16_t, HadamardLPFunc> {
public:
HadamardLowbdLPTest() : HadamardTestBase(GetParam(), /*do_shift=*/false) {}
virtual int16_t Rand() { return rnd_.Rand9Signed(); }
// Use values between -255 (0xFF01) and 255 (0x00FF)
virtual int16_t Rand() {
int16_t src = rnd_.Rand8();
int16_t pred = rnd_.Rand8();
return src - pred;
}
};

TEST_P(HadamardLowbdLPTest, CompareReferenceRandom) {
Expand Down Expand Up @@ -475,7 +496,12 @@ class HadamardLowbdLP8x8DualTest
public:
HadamardLowbdLP8x8DualTest()
: HadamardTestBase(GetParam(), /*do_shift=*/false) {}
virtual int16_t Rand() { return rnd_.Rand9Signed(); }
// Use values between -255 (0xFF01) and 255 (0x00FF)
virtual int16_t Rand() {
int16_t src = rnd_.Rand8();
int16_t pred = rnd_.Rand8();
return src - pred;
}
};

TEST_P(HadamardLowbdLP8x8DualTest, CompareReferenceRandom) {
Expand Down

0 comments on commit 57dd20a

Please sign in to comment.