SEAL icon indicating copy to clipboard operation
SEAL copied to clipboard

Some questions about CKKSEncoderTest.

Open qxzhou1010 opened this issue 9 months ago • 0 comments

In CKKSEncoderEncodeSingleDecodeTest, there is a comment that says there is a very large scale.

 {
      // Use a very large scale
      int data_bound = (1 << 20);
      Plaintext plain;
      vector<complex<double>> result;

      for (int iRun = 0; iRun < 50; iRun++) {
        int value = static_cast<int>(rand() % data_bound);
        encoder.encode(value, context.first_parms_id(), plain);

        // print the scale to verify
        if (iRun == 0) {
          std::cout << "plain scale: 2^" << std::log2(plain.scale()) << "\n";
        }

        encoder.decode(plain, result);

        for (size_t i = 0; i < slots; ++i) {
          auto tmp = abs(value - result[i].real());
          ASSERT_TRUE(tmp < 0.5);
        }
      }
    }
    {
      // Use a scale over 128 bits
      int data_bound = (1 << 20);
      Plaintext plain;
      vector<complex<double>> result;

      for (int iRun = 0; iRun < 50; iRun++) {
        int value = static_cast<int>(rand() % data_bound);
        encoder.encode(value, context.first_parms_id(), plain);

        if (iRun == 0) {
           // print the scale to verify
          std::cout << "plain scale: 2^" << std::log2(plain.scale()) << "\n";
        }

        encoder.decode(plain, result);

        for (size_t i = 0; i < slots; ++i) {
          auto tmp = abs(value - result[i].real());
          ASSERT_TRUE(tmp < 0.5);
        }
      }
    }

Then I output the scale() of Plaintext and found it is very small.

[ RUN      ] CKKSEncoderTest.CKKSEncoderEncodeSingleDecodeTest
plain scale: 2^16
plain scale: 2^0
plain scale: 2^0
plain scale: 2^0
[       OK ] CKKSEncoderTest.CKKSEncoderEncodeSingleDecodeTest (4 ms)
[----------] 2 tests from CKKSEncoderTest (43 ms total)

I am confused about this, are the comments here wrong? Or am I not understanding scale correctly?

qxzhou1010 avatar Mar 20 '25 11:03 qxzhou1010