Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/pypipublish_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
cd third_party/differential-privacy
git checkout 0b0a5c2315d84a6a7b1ff34591e33ec11680891e
cd -
rm -rf third_party/differential-privacy/java
rm -rf third_party/differential-privacy/java
rm -rf third_party/differential-privacy/examples/java
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
Expand Down Expand Up @@ -55,8 +55,8 @@ jobs:
- name: Build pydp lib
run: |
bazel build src/python:bindings_test --verbose_failures
rm -f pydp.so
cp -f ./bazel-bin/src/bindings/pydp.so ./pydp
rm -f _pydp.so
cp -f ./bazel-bin/src/bindings/_pydp.so ./pydp

- name: Build wheel
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pypipublish_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
cd third_party/differential-privacy
git checkout 0b0a5c2315d84a6a7b1ff34591e33ec11680891es
cd -
rm -rf third_party/differential-privacy/java
rm -rf third_party/differential-privacy/java
rm -rf third_party/differential-privacy/examples/java
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
Expand All @@ -36,8 +36,8 @@ jobs:
- name: Build pydp lib
run: |
bazel build src/python:bindings_test --verbose_failures
rm -f pydp.so
cp -f ./bazel-bin/src/bindings/pydp.so ./pydp
rm -f _pydp.so
cp -f ./bazel-bin/src/bindings/_pydp.so ./pydp


- name: Build wheel
Expand All @@ -49,4 +49,4 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TOKEN }}
run: |
twine upload --skip-existing dist/*.whl
twine upload --skip-existing dist/*.whl
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pydp.so
_pydp.so
# bazel files
bazel-bin
bazel-out
Expand Down
4 changes: 2 additions & 2 deletions build_PyDP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

pipenv install --dev --skip-lock
bazel build src/python:bindings_test --verbose_failures
find ./ -name pydp.so -print0 | xargs -0 -I {} rm {}
cp -f ./bazel-bin/src/bindings/pydp.so ./pydp
find ./ -name _pydp.so -print0 | xargs -0 -I {} rm {}
cp -f ./bazel-bin/src/bindings/_pydp.so ./pydp
4 changes: 3 additions & 1 deletion pydp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .pydp import *
from ._pydp import *
from pydp import algorithms


__version__ = "0.1.4"
3 changes: 3 additions & 0 deletions pydp/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import laplacian

__all__ = ["laplacian"]
3 changes: 3 additions & 0 deletions pydp/algorithms/laplacian/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .count import Count

__all__ = ["Count"]
21 changes: 21 additions & 0 deletions pydp/algorithms/laplacian/count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from ..._pydp import _algorithms


def map_type_str(type):
if type == "int":
return "Int"
elif type == "float":
return "Double"
else:
raise RuntimeError(f"dtype: {dtype} is not supported")


class Count:
def __init__(self, epsilon=1.0, dtype="int"):
class_ = getattr(_algorithms, f"Count{map_type_str(dtype)}")

self.dtype = dtype
self.__algorithm = class_(epsilon)

def result(self, list):
return self.__algorithm.result(list)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def read(fname):
include_package_data=True,
keywords="pydp",
name="python-dp",
package_data={"pydp": ["pydp.so"],},
package_data={"_pydp": ["_pydp.so"],},
packages=find_packages(exclude=["tests"]), # need to check this
setup_requires=setup_requirements,
test_suite="tests",
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")

pybind_extension(
name = "pydp",
name = "_pydp",
srcs = glob([
"PyDP/*.cpp",
"PyDP/base/*.cpp",
Expand Down
7 changes: 4 additions & 3 deletions src/bindings/PyDP/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void init_algorithms_rand(py::module &);
// proto
void init_proto(py::module &);

PYBIND11_MODULE(pydp, m) {
PYBIND11_MODULE(_pydp, m) {
m.doc() = "Google Differential Privacy python extension";

// Base
Expand All @@ -37,12 +37,13 @@ PYBIND11_MODULE(pydp, m) {
init_base_percentile(m);

// Algorithms
init_algorithms_bounded_functions(m);
auto malgorithms = m.def_submodule("_algorithms");
init_algorithms_bounded_functions(malgorithms);
init_algorithms_util(m);
init_algorithms_distributions(m);
init_algorithms_order_statistics(m);
init_algorithms_rand(m);
init_algorithms_count(m);
init_algorithms_count(malgorithms);

// Proto
init_proto(m);
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/PyDP/pydp_lib/algorithm_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AlgorithmBuilder {
void declare(py::module& m) {
py::class_<Algorithm> pyself(m, get_algorithm_name().c_str());

pyself.attr("__module__") = "pydp";
pyself.attr("__module__") = "_algorithms";

// Constructors
if constexpr (is_bounded_algorithm<T, Algorithm>()) {
Expand Down
2 changes: 1 addition & 1 deletion src/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ py_binary(
name = "bindings_test",
srcs = ["__init__.py"],
main = "__init__.py",
data = ["//src/bindings:pydp.so"]
data = ["//src/bindings:_pydp.so"]
)