EncryptedRowVector LinearAlgebra::sum_cols_many()

in src/hit/api/linearalgebra/linearalgebra.cpp [1017:1042]


    EncryptedRowVector LinearAlgebra::sum_cols_many(const vector<EncryptedMatrix> &enc_mats, double scalar) {
        vector<vector<CKKSCiphertext>> concat_cts(enc_mats[0].num_vertical_units());

        for (int i = 0; i < enc_mats[0].num_vertical_units(); i++) {
            for (int k = 0; k < enc_mats.size(); k++) {
                if (enc_mats[k].encoding_unit() != enc_mats[0].encoding_unit()) {
                    LOG_AND_THROW_STREAM("Inputs to sum_cols_many must have the same encoding unit, but "
                                         << dim_string(enc_mats[k].encoding_unit())
                                         << "!=" << dim_string(enc_mats[0].encoding_unit()));
                }
                if (enc_mats[k].height() != enc_mats[0].height()) {
                    LOG_AND_THROW_STREAM("Inputs to sum_cols_many must have the same height, but "
                                         << enc_mats[k].height() << "!=" << enc_mats[0].height());
                }

                for (int j = 0; j < enc_mats[k].cts[i].size(); j++) {
                    concat_cts[i].push_back(enc_mats[k].cts[i][j]);
                }
            }
        }

        size_t synthetic_width = concat_cts[0].size() * enc_mats[0].encoding_unit().encoding_width();

        return sum_cols(EncryptedMatrix(enc_mats[0].height(), synthetic_width, enc_mats[0].encoding_unit(), concat_cts),
                        scalar);
    }