Skip to content

Commit

Permalink
Merge pull request #364 from mulimoen/update/pyo3
Browse files Browse the repository at this point in the history
Bump pyo3
  • Loading branch information
mulimoen authored Sep 22, 2024
2 parents d83186c + cfb489d commit c889dcd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion sprs-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition.workspace = true
sprs = { version = "0.11.0", path = "../sprs" }
sprs-rand = { version = "0.4.0", path = "../sprs-rand" }
plotters = "0.3.4"
pyo3 = { version = "0.18.3", features = ["auto-initialize"] }
pyo3 = { version = "0.22.3", features = ["auto-initialize"] }

[build-dependencies]
cc = "1.0.52"
Expand Down
28 changes: 16 additions & 12 deletions sprs-benches/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use sprs::smmp;
use sprs_rand::rand_csr_std;

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

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
})?;
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
})?;

for spec in &bench_specs {
let shape = spec.shape;
Expand Down Expand Up @@ -264,13 +265,16 @@ fn bench_densities_with_py(

// bench scipy as well
{
let m1_py = scipy_mat(scipy_sparse, py, &m1)?;
let m2_py = scipy_mat(scipy_sparse, py, &m2)?;
let m1_py = scipy_mat(&scipy_sparse, py, &m1)?;
let m2_py = scipy_mat(&scipy_sparse, py, &m2)?;
let now = std::time::Instant::now();
let _prod_py = py
.eval(
.eval_bound(
"m1 * m2",
Some([("m1", m1_py), ("m2", m2_py)].into_py_dict(py)),
Some(
&[("m1", m1_py), ("m2", m2_py)]
.into_py_dict_bound(py),
),
None,
)
.map_err(|e| {
Expand Down

0 comments on commit c889dcd

Please sign in to comment.