@@ -27,7 +27,7 @@ impl DType for f64 {
2727}
2828
2929pub ( crate ) fn unknown_type_exception ( name : & str , obj : & Bound < PyAny > ) -> Exception {
30- let message = if let Ok ( arr) = obj. downcast :: < PyUntypedArray > ( ) {
30+ let message = if let Ok ( arr) = obj. cast :: < PyUntypedArray > ( ) {
3131 let ndim = arr. ndim ( ) ;
3232 if ndim != 1 {
3333 format ! ( "'{name}' is a {ndim}-d array, only 1-d arrays are supported." )
@@ -59,13 +59,13 @@ fn cast_fail_reason<const N: usize>(
5959 let first_name = names. first ( ) . expect ( "Empty names slice" ) ;
6060 let fist_obj = objects. first ( ) . expect ( "Empty objects slice" ) ;
6161
62- // If the very first argument downcast
62+ // If the very first argument cast
6363 if idx == 0 {
6464 return unknown_type_exception ( first_name, fist_obj) ;
6565 }
6666
67- let maybe_first_f32_array = try_downcast_to_f32_array ( objects[ 0 ] ) ;
68- let maybe_first_f64_array = try_downcast_to_f64_array ( objects[ 0 ] , cast) ;
67+ let maybe_first_f32_array = try_cast_to_f32_array ( objects[ 0 ] ) ;
68+ let maybe_first_f64_array = try_cast_to_f64_array ( objects[ 0 ] , cast) ;
6969 let ( first_arr, first_dtype_name) = if let Some ( f32_array) = maybe_first_f32_array. as_ref ( ) {
7070 ( f32_array. as_untyped ( ) , f32:: dtype_name ( ) )
7171 } else if let Some ( f64_array) = maybe_first_f64_array. as_ref ( ) {
@@ -79,7 +79,7 @@ fn cast_fail_reason<const N: usize>(
7979 . get ( idx)
8080 . expect ( "idx is out of bounds of objects slice" ) ;
8181
82- let error_message = if let Ok ( fail_arr) = fail_obj. downcast :: < PyUntypedArray > ( ) {
82+ let error_message = if let Ok ( fail_arr) = fail_obj. cast :: < PyUntypedArray > ( ) {
8383 if fail_arr. ndim ( ) != 1 {
8484 format ! (
8585 "'{}' is a {}-d array, only 1-d arrays are supported." ,
@@ -125,12 +125,12 @@ impl<const N: usize> GenericPyReadonlyArrays<'_, N> {
125125 }
126126}
127127
128- fn try_downcast_objects_to_f32_arrays < ' py , const N : usize > (
128+ fn try_cast_objects_to_f32_arrays < ' py , const N : usize > (
129129 objects : & [ & Bound < ' py , PyAny > ; N ] ,
130130) -> [ Option < PyReadonlyArray1 < ' py , f32 > > ; N ] {
131131 let mut arrays = [ const { None } ; N ] ;
132132 for ( & obj, arr) in objects. iter ( ) . zip ( arrays. iter_mut ( ) ) {
133- * arr = try_downcast_to_f32_array ( obj) ;
133+ * arr = try_cast_to_f32_array ( obj) ;
134134 // If we cannot cast an array, we stop trying for future arguments
135135 if arr. is_none ( ) {
136136 break ;
@@ -139,16 +139,16 @@ fn try_downcast_objects_to_f32_arrays<'py, const N: usize>(
139139 arrays
140140}
141141
142- fn try_downcast_to_f32_array < ' py > ( obj : & Bound < ' py , PyAny > ) -> Option < PyReadonlyArray1 < ' py , f32 > > {
143- let py_array = obj. downcast :: < PyArray1 < f32 > > ( ) . ok ( ) ?;
142+ fn try_cast_to_f32_array < ' py > ( obj : & Bound < ' py , PyAny > ) -> Option < PyReadonlyArray1 < ' py , f32 > > {
143+ let py_array = obj. cast :: < PyArray1 < f32 > > ( ) . ok ( ) ?;
144144 Some ( py_array. readonly ( ) )
145145}
146146
147- fn try_downcast_to_f64_array < ' py > (
147+ fn try_cast_to_f64_array < ' py > (
148148 obj : & Bound < ' py , PyAny > ,
149149 cast : bool ,
150150) -> Option < PyReadonlyArray1 < ' py , f64 > > {
151- match ( obj. downcast :: < PyArray1 < f64 > > ( ) , cast) {
151+ match ( obj. cast :: < PyArray1 < f64 > > ( ) , cast) {
152152 ( Ok ( py_array) , _) => Some ( py_array. readonly ( ) ) ,
153153 ( Err ( _) , true ) => match PyArrayLike1 :: < f64 , AllowTypeChange > :: extract ( obj. as_borrowed ( ) ) {
154154 Ok ( py_array) => Some ( py_array. readonly ( ) ) ,
@@ -168,11 +168,11 @@ const fn index<const N: usize>() -> [usize; N] {
168168 arr
169169}
170170
171- fn downcast_objects_cast < ' py , const N : usize > (
171+ fn cast_objects_with_dtype_change < ' py , const N : usize > (
172172 names : & ' static [ & ' static str ; N ] ,
173173 objects : & [ & Bound < ' py , PyAny > ; N ] ,
174174) -> Res < GenericPyReadonlyArrays < ' py , N > > {
175- let f32_arrays = try_downcast_objects_to_f32_arrays ( objects) ;
175+ let f32_arrays = try_cast_objects_to_f32_arrays ( objects) ;
176176
177177 if f32_arrays. iter ( ) . all ( |arr| arr. is_some ( ) ) {
178178 Ok ( GenericPyReadonlyArrays :: F32 (
@@ -183,7 +183,7 @@ fn downcast_objects_cast<'py, const N: usize>(
183183 let f64_arr = if let Some ( f32_arr) = & f32_arrays[ i] {
184184 f32_arr. cast_array :: < f64 > ( false ) ?. readonly ( )
185185 } else {
186- try_downcast_to_f64_array ( objects[ i] , true )
186+ try_cast_to_f64_array ( objects[ i] , true )
187187 . ok_or_else ( || cast_fail_reason ( i, names, objects, true ) ) ?
188188 } ;
189189 Ok ( f64_arr)
@@ -193,11 +193,11 @@ fn downcast_objects_cast<'py, const N: usize>(
193193 }
194194}
195195
196- fn downcast_objects_no_cast < ' py , const N : usize > (
196+ fn cast_objects_no_dtype_change < ' py , const N : usize > (
197197 names : & ' static [ & ' static str ; N ] ,
198198 objects : & [ & Bound < ' py , PyAny > ; N ] ,
199199) -> Res < GenericPyReadonlyArrays < ' py , N > > {
200- let f32_arrays = try_downcast_objects_to_f32_arrays ( objects) ;
200+ let f32_arrays = try_cast_objects_to_f32_arrays ( objects) ;
201201
202202 if f32_arrays. iter ( ) . all ( |arr| arr. is_some ( ) ) {
203203 Ok ( GenericPyReadonlyArrays :: F32 (
@@ -208,7 +208,7 @@ fn downcast_objects_no_cast<'py, const N: usize>(
208208 let f64_arrays = objects
209209 . map_option ( |obj| {
210210 valid_f64_count += 1 ;
211- try_downcast_to_f64_array ( obj, false )
211+ try_cast_to_f64_array ( obj, false )
212212 } )
213213 . ok_or_else ( || {
214214 let valid_f32_count = f32_arrays. iter ( ) . filter ( |arr| arr. is_some ( ) ) . count ( ) ;
@@ -224,7 +224,7 @@ fn downcast_objects_no_cast<'py, const N: usize>(
224224 }
225225}
226226
227- pub ( crate ) fn downcast_and_validate < ' py , const N : usize > (
227+ pub ( crate ) fn cast_and_validate < ' py , const N : usize > (
228228 names : & ' static [ & ' static str ; N ] ,
229229 objects : & [ & Bound < ' py , PyAny > ; N ] ,
230230 check_size : & [ bool ; N ] ,
@@ -233,9 +233,9 @@ pub(crate) fn downcast_and_validate<'py, const N: usize>(
233233 assert_eq ! ( names. len( ) , objects. len( ) ) ;
234234
235235 let arrays = if cast {
236- downcast_objects_cast ( names, objects) ?
236+ cast_objects_with_dtype_change ( names, objects) ?
237237 } else {
238- downcast_objects_no_cast ( names, objects) ?
238+ cast_objects_no_dtype_change ( names, objects) ?
239239 } ;
240240 let mut first_array_len = None ;
241241 // We checked that 1) names size matches objects size, 2) objects is not empty
@@ -299,7 +299,7 @@ macro_rules! dtype_dispatch {
299299 let objects = & [ & $first_arg, $( & $arg, ) * ] ;
300300 let check_size = & [ false , $( _distinguish_eq_symbol!( $eq) , ) * ] ;
301301
302- let generic_arrays = crate :: np_array:: downcast_and_validate ( names, objects, check_size, $cast) ?;
302+ let generic_arrays = crate :: np_array:: cast_and_validate ( names, objects, check_size, $cast) ?;
303303 match generic_arrays {
304304 crate :: np_array:: GenericPyReadonlyArrays :: F32 ( arrays) => {
305305 let func = $f32;
0 commit comments