Commit 66fee202 authored by Yuriy Polyakov's avatar Yuriy Polyakov

added more demos

parent 2ad50af7
......@@ -24,6 +24,8 @@
*/
#include "math/discretegaussiangenerator.h"
#include "math/discretegaussiangeneratorgeneric.h"
#include "math/discreteuniformgenerator.h"
#include "math/ternaryuniformgenerator.h"
#include "utils/debug.h"
#define LOGSAMPLES
......@@ -32,7 +34,7 @@ using namespace lbcrypto;
using namespace std;
// Demos for generic samplers
// All smaplers are descsribed in discretegaussiangenerator.h and
// All Gaussian samplers are described in discretegaussiangenerator.h and
// discretegaussiangeneratorgeneric.h
void SamplingRejection();
void SamplingKarney();
......@@ -42,6 +44,10 @@ void SamplingMWKnuthYao();
// inversion algorithm for FHE
void SamplingPeikert();
// uniform distributions
void SamplingUniform();
void SamplingTernary();
int main() {
SamplingRejection();
......@@ -49,7 +55,8 @@ int main() {
SamplingMWPeikert();
SamplingMWKnuthYao();
SamplingPeikert();
SamplingUniform();
SamplingTernary();
}
......@@ -299,3 +306,67 @@ void SamplingPeikert() {
}
void SamplingUniform() {
#ifdef LOGSAMPLES
ofstream outFile;
outFile.open("demoData/uniform.txt");
#endif
DiscreteUniformGeneratorImpl<NativeVector> dug;
dug.SetModulus(576460752303423488);
double start, finish;
size_t count = 1000000;
NativeInteger output;
start = currentDateTime();
for (size_t i = 0;i < count;i++) {
output = dug.GenerateInteger();
#ifdef LOGSAMPLES
outFile << output << std::endl;
#endif
}
finish = currentDateTime();
std::cout << "last output: " << output << std::endl;
std::cout << "Sampling " << std::to_string(count) << " integers (uniform): " << (finish - start) << " ms\n";
#ifdef LOGSAMPLES
outFile.close();
#endif
}
void SamplingTernary() {
#ifdef LOGSAMPLES
ofstream outFile;
outFile.open("demoData/ternary.txt");
#endif
TernaryUniformGenerator tug;
double start, finish;
size_t count = 1000000;
start = currentDateTime();
auto vec = tug.GenerateIntVector(count);
finish = currentDateTime();
for (size_t i = 0;i < count;i++) {
#ifdef LOGSAMPLES
outFile << (vec.get())[i] << std::endl;
#endif
}
std::cout << "Sampling " << std::to_string(count) << " integers (ternary): " << (finish - start) << " ms\n";
#ifdef LOGSAMPLES
outFile.close();
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment