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
22 changes: 12 additions & 10 deletions src/scalib_ext/scalib-py/src/belief_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ pub fn run_bp(
.map(|x| to_var(x.downcast::<PyDict>().unwrap()))
.collect();

scalib::belief_propagation::run_bp(
&functions_rust,
&mut variables_rust,
it,
edge,
nc,
n,
progress,
)
.unwrap();
py.allow_threads(|| {
scalib::belief_propagation::run_bp(
&functions_rust,
&mut variables_rust,
it,
edge,
nc,
n,
progress,
)
.unwrap();
});

variables_rust
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/scalib_ext/scalib-py/src/lda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl LDA {
/// x : traces with shape (n,ns)
/// return prs with shape (n,nc). Every row corresponds to one probability distribution
fn predict_proba<'py>(
&mut self,
&self,
py: Python<'py>,
x: PyReadonlyArray2<i16>,
) -> PyResult<&'py PyArray2<f64>> {
Expand Down
34 changes: 20 additions & 14 deletions src/scalib_ext/scalib-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,45 @@ fn _scalib_ext(_py: Python, m: &PyModule) -> PyResult<()> {

#[pyfn(m, "rank_accuracy")]
fn rank_accuracy(
py: Python,
costs: Vec<Vec<f64>>,
key: Vec<usize>,
acc: f64,
merge: Option<usize>,
method: String,
max_nb_bin: usize,
) -> PyResult<(f64, f64, f64)> {
let res = str2method(&method).unwrap_or_else(|s| panic!("{}", s));
let res = res.rank_accuracy(&costs, &key, acc, merge, max_nb_bin);
match res {
Ok(res) => Ok((res.min, res.est, res.max)),
Err(s) => {
panic!("{}", s);
py.allow_threads(|| {
let res = str2method(&method).unwrap_or_else(|s| panic!("{}", s));
let res = res.rank_accuracy(&costs, &key, acc, merge, max_nb_bin);
match res {
Ok(res) => Ok((res.min, res.est, res.max)),
Err(s) => {
panic!("{}", s);
}
}
}
})
}

#[pyfn(m, "rank_nbin")]
fn rank_nbin(
py: Python,
costs: Vec<Vec<f64>>,
key: Vec<usize>,
nb_bin: usize,
merge: Option<usize>,
method: String,
) -> PyResult<(f64, f64, f64)> {
let res = str2method(&method).unwrap_or_else(|s| panic!("{}", s));
let res = res.rank_nbin(&costs, &key, nb_bin, merge);
match res {
Ok(res) => Ok((res.min, res.est, res.max)),
Err(s) => {
panic!("{}", s);
py.allow_threads(|| {
let res = str2method(&method).unwrap_or_else(|s| panic!("{}", s));
let res = res.rank_nbin(&costs, &key, nb_bin, merge);
match res {
Ok(res) => Ok((res.min, res.est, res.max)),
Err(s) => {
panic!("{}", s);
}
}
}
})
}

Ok(())
Expand Down