@@ -22,7 +22,7 @@ static SPMATRIX: GILOnceCell<Py<PyAny>> = GILOnceCell::new();
22
22
pub struct WrappedCsx < N , I : SpIndex , Iptr : SpIndex > ( pub CsMatI < N , I , Iptr > ) ;
23
23
24
24
fn get_scipy_sparse ( py : Python ) -> PyResult < & Py < PyModule > > {
25
- SP_SPARSE . get_or_try_init ( py, || Ok ( py. import_bound ( "scipy.sparse" ) ?. unbind ( ) ) )
25
+ SP_SPARSE . get_or_try_init ( py, || Ok ( py. import ( "scipy.sparse" ) ?. unbind ( ) ) )
26
26
}
27
27
28
28
fn get_scipy_sparse_attr ( py : Python , attr : & str ) -> PyResult < PyObject > {
@@ -46,16 +46,20 @@ where
46
46
let ( indptr, indices, data) = cs. into_raw_storage ( ) ;
47
47
48
48
return (
49
- data. into_pyarray_bound ( py) ,
50
- indices. into_pyarray_bound ( py) ,
51
- indptr. into_pyarray_bound ( py) ,
49
+ data. into_pyarray ( py) ,
50
+ indices. into_pyarray ( py) ,
51
+ indptr. into_pyarray ( py) ,
52
52
) ;
53
53
}
54
54
55
- impl < N : Element , I : SpIndex + Element , Iptr : SpIndex + Element > IntoPy < PyObject >
55
+ impl < ' py , N : Element , I : SpIndex + Element , Iptr : SpIndex + Element > IntoPyObject < ' py >
56
56
for WrappedCsx < N , I , Iptr >
57
57
{
58
- fn into_py ( self , py : Python < ' _ > ) -> PyObject {
58
+ type Target = PyAny ;
59
+ type Output = Bound < ' py , Self :: Target > ;
60
+ type Error = PyErr ; // TODO: propagate better errors?
61
+
62
+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
59
63
let csx = self . 0 ;
60
64
let shape = csx. shape ( ) ;
61
65
@@ -67,16 +71,14 @@ impl<N: Element, I: SpIndex + Element, Iptr: SpIndex + Element> IntoPy<PyObject>
67
71
sparray
68
72
. unwrap ( )
69
73
. call1 ( py, ( make_csx_tuple ( py, csx) , shape) )
70
- . unwrap ( )
71
- . extract ( py)
72
- . unwrap ( )
74
+ . map ( move |x| x. into_bound ( py) )
73
75
}
74
76
}
75
- impl < ' py , N : Element , I : SpIndex + Element , Iptr : SpIndex + Element > FromPyObject < ' py >
77
+ impl < ' py , N : Element + Clone , I : SpIndex + Element , Iptr : SpIndex + Element > FromPyObject < ' py >
76
78
for WrappedCsx < N , I , Iptr >
77
79
{
78
80
fn extract_bound ( obj : & Bound < ' py , PyAny > ) -> PyResult < Self > {
79
- fn boundpyarray_to_vec < T : Element > ( obj : Bound < ' _ , PyAny > ) -> PyResult < Vec < T > > {
81
+ fn boundpyarray_to_vec < T : Element + Clone > ( obj : Bound < ' _ , PyAny > ) -> PyResult < Vec < T > > {
80
82
Ok ( obj. extract :: < PyReadonlyArray1 < T > > ( ) ?. as_array ( ) . to_vec ( ) )
81
83
}
82
84
0 commit comments