in src/hit/api/linearalgebra/encryptedmatrix.cpp [139:182]
void EncryptedMatrix::validate() const {
// validate the unit
unit.validate();
if (height_ <= 0) {
LOG_AND_THROW_STREAM("Invalid EncryptedMatrix: "
<< "height must be non-negative, got " << height_);
}
if (width_ <= 0) {
LOG_AND_THROW_STREAM("Invalid EncryptedMatrix: "
<< "width must be non-negative, got " << width_);
}
if (cts.size() != ceil(height_ / static_cast<double>(unit.encoding_height()))) {
LOG_AND_THROW_STREAM("Invalid ciphertexts in EncryptedMatrix: "
<< "Expected " << ceil(height_ / static_cast<double>(unit.encoding_height()))
<< " vertical units, found a " << cts.size() << ". ");
}
if (cts[0].size() != ceil(width_ / static_cast<double>(unit.encoding_width()))) {
LOG_AND_THROW_STREAM("Invalid ciphertexts in EncryptedMatrix: "
<< "Expected " << ceil(width_ / static_cast<double>(unit.encoding_width()))
<< " horizontal units, found a " << cts[0].size() << ". ");
}
int row_size = cts[0].size();
for (const auto &cts_i : cts) {
if (cts_i.size() != row_size) {
LOG_AND_THROW_STREAM("Invalid ciphertexts in EncryptedMatrix: "
<< "Each horizontal row should have " << row_size << " units, but a row has "
<< cts_i.size() << " horizontal units. ");
}
for (const auto &ct : cts_i) {
if (ct.scale() != cts[0][0].scale()) {
LOG_AND_THROW_STREAM("Invalid EncryptedMatrix: "
<< "Each ciphertext must have the same scale.");
}
if (ct.he_level() != cts[0][0].he_level()) {
LOG_AND_THROW_STREAM("Invalid EncryptedMatrix: "
<< "Each ciphertext must have the same level.");
}
}
}
}