Skip to content

Commit

Permalink
Update pyo3 code
Browse files Browse the repository at this point in the history
  • Loading branch information
mulimoen committed Nov 19, 2024
1 parent a9ca295 commit 56f153d
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions sprs-benches/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use sprs_rand::rand_csr_std;

fn scipy_mat<'a>(
scipy_sparse: &Bound<'a, PyModule>,
py: Python,
py: Python<'a>,
mat: &sprs::CsMat<f64>,
) -> Result<Bound<'a, PyAny>, String> {
let indptr = mat.indptr().to_proper().to_vec();
scipy_sparse
.call_method(
"csr_matrix",
((mat.data().to_vec(), mat.indices().to_vec(), indptr),),
Some(&[("shape", mat.shape())].into_py_dict_bound(py)),
Some(&[("shape", mat.shape())].into_py_dict(py).unwrap()),
)
.map_err(|e| {
let res = format!("Python error: {e:?}");
Expand Down Expand Up @@ -163,12 +163,11 @@ fn bench_densities_with_py(
},
];

let scipy_sparse =
PyModule::import_bound(py, "scipy.sparse").map_err(|e| {
let res = format!("Python error: {e:?}");
e.print_and_set_sys_last_vars(py);
res
})?;
let scipy_sparse = PyModule::import(py, "scipy.sparse").map_err(|e| {
let res = format!("Python error: {e:?}");
e.print_and_set_sys_last_vars(py);
res
})?;

for spec in &bench_specs {
let shape = spec.shape;
Expand Down Expand Up @@ -269,12 +268,9 @@ fn bench_densities_with_py(
let m2_py = scipy_mat(&scipy_sparse, py, &m2)?;
let now = std::time::Instant::now();
let _prod_py = py
.eval_bound(
"m1 * m2",
Some(
&[("m1", m1_py), ("m2", m2_py)]
.into_py_dict_bound(py),
),
.eval(
c"m1 * m2",
Some(&[("m1", m1_py), ("m2", m2_py)].into_py_dict(py)?),
None,
)
.map_err(|e| {
Expand Down

0 comments on commit 56f153d

Please sign in to comment.