MCPcopy Create free account
hub / github.com/OpenMined/TenSEAL / decrypt

Method decrypt

tenseal/cpp/tensors/ckkstensor.cpp:117–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117PlainTensor<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
152shared_ptr<CKKSTensor> CKKSTensor::negate_inplace() {
153 for (auto& ct : _data)

Callers

nothing calls this directly

Calls 6

shape_with_batchMethod · 0.95
tenseal_contextMethod · 0.80
flat_sizeMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected