Skip to content

Commit 528c5a1

Browse files
authored
Added documentation to Utils (#341)
* Add documentation to Utils * Fix __init__.py style
1 parent 34e73ca commit 528c5a1

File tree

2 files changed

+64
-34
lines changed

2 files changed

+64
-34
lines changed

src/bindings/PyDP/algorithms/util.cpp

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,63 @@ namespace dp = differential_privacy;
1010

1111
void init_algorithms_util(py::module& m) {
1212
m.attr("__module__") = "pydp";
13-
m.def("xor_strings", &dp::XorStrings);
14-
m.def("default_epsilon", &dp::DefaultEpsilon);
15-
m.def("get_next_power_of_two", &dp::GetNextPowerOfTwo);
16-
m.def("qnorm", &dp::Qnorm);
17-
m.def("mean", &dp::Mean<double>);
18-
m.def("mean", &dp::Mean<int>);
19-
m.def("variance", &dp::Variance<double>);
20-
m.def("standard_deviation", &dp::StandardDev<double>);
21-
m.def("order_statistics", &dp::OrderStatistic<double>);
22-
m.def("correlation", &dp::Correlation<double>);
23-
m.def("vector_filter", &dp::VectorFilter<double>);
24-
m.def("vector_to_string", &dp::VectorToString<double>);
25-
m.def("round_to_nearest_multiple", &dp::RoundToNearestMultiple);
26-
m.def("safe_add", [](int64_t i, int64_t j) {
27-
int64_t k;
28-
bool result = dp::SafeAdd(i, j, &k);
29-
if (result) return k;
30-
throw std::runtime_error("Result of addition will overflow.");
31-
});
32-
m.def("safe_subtract", [](int64_t i, int64_t j) {
33-
int64_t k;
34-
bool result = dp::SafeSubtract(i, j, &k);
35-
if (result) return k;
36-
throw std::runtime_error("Result of subtraction will overflow.");
37-
});
38-
m.def("safe_square", [](int64_t i) {
39-
int64_t k;
40-
bool result = dp::SafeSquare(i, &k);
41-
if (result) return k;
42-
throw std::runtime_error("Result of squaring will overflow.");
43-
});
44-
}
13+
m.def(
14+
"xor_strings", &dp::XorStrings,
15+
R"pbdoc(Character-wise XOR of two strings. In case of differing string lengths, operation will be performed by the repeated concatenation of the smaler string till it is of the same length as the longer before the performance of the XOR operation.)pbdoc");
16+
m.def("default_epsilon", &dp::DefaultEpsilon); // deprecated, default epsilon value
17+
m.def(
18+
"get_next_power_of_two", &dp::GetNextPowerOfTwo,
19+
R"pbdoc(Outputs value of a power of two that is greater than and closest to the given numerical input.)pbdoc");
20+
m.def(
21+
"qnorm", &dp::Qnorm,
22+
R"pbdoc(Quantile function of normal distribution, inverse of the cumulative distribution function.)pbdoc");
23+
m.def(
24+
"mean", &dp::Mean<double>,
25+
R"pbdoc(Calculation of the mean of given set of numbers for a double int data type.)pbdoc");
26+
m.def(
27+
"mean", &dp::Mean<int>,
28+
R"pbdoc(Calculation of the mean of given set of numbers for an int data type.)pbdoc");
29+
m.def("variance", &dp::Variance<double>,
30+
R"pbdoc(Calculate variance for a set of values.)pbdoc");
31+
m.def("standard_deviation", &dp::StandardDev<double>,
32+
R"pbdoc(Standard Deviation, the square root of variance.)pbdoc");
33+
m.def("order_statistics", &dp::OrderStatistic<double>,
34+
R"pbdoc(Sample values placed in ascending order.)pbdoc");
35+
m.def("correlation", &dp::Correlation<double>,
36+
R"pbdoc(Returns linear correlation coefficient.)pbdoc");
37+
m.def(
38+
"vector_filter", &dp::VectorFilter<double>,
39+
R"pbdoc(Filtering a vector using a logical operatio with only values selected using true output in their positions.)pbdoc");
40+
m.def("vector_to_string", &dp::VectorToString<double>,
41+
R"pbdoc(Conversion of a vector to a string data type.)pbdoc");
42+
m.def(
43+
"round_to_nearest_multiple", &dp::RoundToNearestMultiple,
44+
R"pbdoc(Returns closest multiple of n that is greater than the given number.)pbdoc");
45+
m.def(
46+
"safe_add",
47+
[](int64_t i, int64_t j) {
48+
int64_t k;
49+
bool result = dp::SafeAdd(i, j, &k);
50+
if (result) return k;
51+
throw std::runtime_error("Result of addition will overflow.");
52+
},
53+
R"pbdoc(Addition performed with safety to cater to overflow conditions.)pbdoc");
54+
m.def(
55+
"safe_subtract",
56+
[](int64_t i, int64_t j) {
57+
int64_t k;
58+
bool result = dp::SafeSubtract(i, j, &k);
59+
if (result) return k;
60+
throw std::runtime_error("Result of subtraction will overflow.");
61+
},
62+
R"pbdoc(Subtraction performed with safety to cater to overflow conditions.)pbdoc");
63+
m.def(
64+
"safe_square",
65+
[](int64_t i) {
66+
int64_t k;
67+
bool result = dp::SafeSquare(i, &k);
68+
if (result) return k;
69+
throw std::runtime_error("Result of squaring will overflow.");
70+
},
71+
R"pbdoc(A number squared, with safety to cater to overflow conditions.)pbdoc");
72+
}

src/pydp/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
# assert sys.version_info >= (3, 6)
1010
if sys.version_info < (3, 6):
11-
print("WARN: Support for Python 3.5 and below is being deprecated. \
12-
Please upgrade your version.")
11+
print(
12+
"WARN: Support for Python 3.5 and below is being deprecated. \
13+
Please upgrade your version."
14+
)

0 commit comments

Comments
 (0)