Skip to content

Some questions about CKKSEncoderTest. #728

@qxzhou1010

Description

@qxzhou1010

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions