Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/bindings/PyDP/algorithms/bounded_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ void declareBoundedAlgorithm(py::module& m) {
bld.def("privacy_budget_left",
[](Algorithm& obj) { return obj.RemainingPrivacyBudget(); });

bld.def("add_entry", [](Algorithm& obj, T& v) {
obj.AddEntry(v);
});

bld.def("add_entries", [](Algorithm& obj, std::vector<T>& v) {
obj.AddEntries(v.begin(), v.end());
});
Expand All @@ -56,30 +60,28 @@ void declareBoundedAlgorithm(py::module& m) {
if (!result.ok()) {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<double>(result.ValueOrDie());
});

bld.def("partial_result", [](Algorithm& obj, double privacy_budget) {
if (privacy_budget > obj.RemainingPrivacyBudget()){
throw std::runtime_error("Privacy budget requeted exceeds set privacy budget");
}
auto result = obj.PartialResult(privacy_budget);

if (!result.ok()) {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<double>(result.ValueOrDie());
});

bld.def_property_readonly("epsilon", [](Algorithm& obj) { return obj.GetEpsilon(); });

bld.def("result", [](Algorithm& obj, std::vector<T>& v) {
auto result = obj.Result(v.begin(), v.end());

if (!result.ok()) {
throw std::runtime_error(result.status().error_message());
}

return dp::GetValue<T>(result.ValueOrDie());
return dp::GetValue<double>(result.ValueOrDie());
});
}

Expand Down