Skip to content

Commit

Permalink
add evaluator
Browse files Browse the repository at this point in the history
Signed-off-by: weiwee <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Aug 9, 2023
1 parent 2ff5aaf commit be76283
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
1 change: 0 additions & 1 deletion python/requirements-fate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ numpy==1.23.1
torch==1.13.1
urllib3==1.26.5
grpcio==1.46.3
ml_metadata
beautifultable
rust_paillier
32 changes: 32 additions & 0 deletions rust/fate_utils/crates/fate_utils/src/paillier/evaluator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use fixedpoint::CT;
use ndarray::prelude::*;
use pyo3::prelude::*;
use super::paillier;

#[pyclass]
pub struct Evaluator {}

#[pymethods]
impl Evaluator {
#[staticmethod]
fn cat(vec_list: Vec<PyRef<paillier::FixedpointPaillierVector>>) -> PyResult<paillier::FixedpointPaillierVector> {
let mut data = vec![CT::zero(); 0];
for vec in vec_list {
data.extend(vec.data.clone());
}
Ok(paillier::FixedpointPaillierVector { data })
}
#[staticmethod]
fn slice_indexes(a: &paillier::FixedpointPaillierVector, indexes: Vec<usize>) -> PyResult<paillier::FixedpointPaillierVector> {
let data = indexes
.iter()
.map(|i| a.data[*i].clone())
.collect::<Vec<_>>();
Ok(paillier::FixedpointPaillierVector { data })
}
}

pub(crate) fn register(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Evaluator>()?;
Ok(())
}
2 changes: 2 additions & 0 deletions rust/fate_utils/crates/fate_utils/src/paillier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod paillier;
mod evaluator;

use pyo3::prelude::*;

pub(crate) fn register(py: Python, m: &PyModule) -> PyResult<()> {
let submodule = PyModule::new(py, "paillier")?;
paillier::register(py, submodule)?;
evaluator::register(py, submodule)?;
m.add_submodule(submodule)?;
py.import("sys")?
.getattr("modules")?
Expand Down
4 changes: 2 additions & 2 deletions rust/fate_utils/crates/fate_utils/src/paillier/paillier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl FixedpointPaillierVector {
}

#[staticmethod]
fn zeros(size: usize) -> PyResult<Self> {
pub fn zeros(size: usize) -> PyResult<Self> {
let data = vec![CT::zero(); size];
Ok(FixedpointPaillierVector { data })
}
Expand All @@ -280,7 +280,7 @@ impl FixedpointPaillierVector {
.collect::<Vec<_>>();
Ok(FixedpointPaillierVector { data })
}
fn cat(&self, others: Vec<PyRef<FixedpointPaillierVector>>) -> PyResult<Self> {
pub fn cat(&self, others: Vec<PyRef<FixedpointPaillierVector>>) -> PyResult<Self> {
let mut data = self.data.clone();
for other in others {
data.extend(other.data.clone());
Expand Down

0 comments on commit be76283

Please sign in to comment.