Hybrid ks validity check

Hi!

I am learning the implementation of Keyswtich, and i would like to know why we need to check whether sizeQ <= (a * (numPartQ - 1)) in the following part?

        // Compute ceil(sizeQ/numPartQ), the # of towers per digit
        uint32_t a = static_cast<uint32_t>(std::ceil(static_cast<double>(sizeQ) / numPartQ));
        if (sizeQ <= (a * (numPartQ - 1))) {
            auto str = "HYBRID key switching parameters: Can't appropriately distribute " + std::to_string(sizeQ) +
                       " towers into " + std::to_string(numPartQ) +
                       " digits. Please select different number of digits.";
            OPENFHE_THROW(str);
        }

Thanks for your time!

This check catches edge cases where sizeQ moduli (or limbs) are not appropriately distributed into numPartQ digits.

If the condition sizeQ <= (a * (numPartQ - 1)) is true, it indicates that there are not enough moduli to fill all the digits, leaving the last digit with zero or a very small number of moduli. This would lead to unnecessary computation or incorrect results.

Example:

sizeQ = 33;
numPartQ = 8;
a = Ceiling[sizeQ/numPartQ]; // 5

Here we want to distribute 33 moduli over 8 digits, each containing 5 moduli.
Apparently, the last digit includes 0 moduli with these parameters, hence the check.