| 115 | } |
| 116 | |
| 117 | PlainTensor<double> CKKSTensor::decrypt(const shared_ptr<SecretKey>& sk) const { |
| 118 | Plaintext plaintext; |
| 119 | auto sz = this->_data.flat_size(); |
| 120 | auto shape = this->shape_with_batch(); |
| 121 | |
| 122 | if (_batch_size) { |
| 123 | vector<vector<double>> result; |
| 124 | result.reserve(sz); |
| 125 | |
| 126 | for (auto it = _data.cbegin(); it != _data.cend(); it++) { |
| 127 | vector<double> buff; |
| 128 | this->tenseal_context()->decrypt(*sk, *it, plaintext); |
| 129 | this->tenseal_context()->decode<CKKSEncoder>(plaintext, buff); |
| 130 | result.push_back( |
| 131 | vector<double>(buff.begin(), buff.begin() + *_batch_size)); |
| 132 | } |
| 133 | |
| 134 | return PlainTensor<double>(/*batched_tensor=*/result, |
| 135 | /*shape_with_batch=*/shape, |
| 136 | /*batch_axis=*/0); |
| 137 | } else { |
| 138 | vector<double> result; |
| 139 | result.reserve(sz); |
| 140 | |
| 141 | for (auto it = _data.cbegin(); it != _data.cend(); it++) { |
| 142 | vector<double> buff; |
| 143 | this->tenseal_context()->decrypt(*sk, *it, plaintext); |
| 144 | this->tenseal_context()->decode<CKKSEncoder>(plaintext, buff); |
| 145 | result.push_back(buff[0]); |
| 146 | } |
| 147 | |
| 148 | return PlainTensor<double>(result, /*shape_with_batch=*/shape); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | shared_ptr<CKKSTensor> CKKSTensor::negate_inplace() { |
| 153 | for (auto& ct : _data) |
nothing calls this directly
no test coverage detected