@@ -35,24 +35,12 @@ impl NpyDataType {
35
35
x if x == NPY_TYPES :: NPY_BYTE as i32 => NpyDataType :: Int8 ,
36
36
x if x == NPY_TYPES :: NPY_SHORT as i32 => NpyDataType :: Int16 ,
37
37
x if x == NPY_TYPES :: NPY_INT as i32 => NpyDataType :: Int32 ,
38
- x if x == NPY_TYPES :: NPY_LONG as i32 => {
39
- if cfg ! ( any( windows, target_pointer_width = "32" ) ) {
40
- NpyDataType :: Int32
41
- } else {
42
- NpyDataType :: Int64
43
- }
44
- }
38
+ x if x == NPY_TYPES :: NPY_LONG as i32 => NpyDataType :: from_clong ( false ) ,
45
39
x if x == NPY_TYPES :: NPY_LONGLONG as i32 => NpyDataType :: Int64 ,
46
40
x if x == NPY_TYPES :: NPY_UBYTE as i32 => NpyDataType :: Uint8 ,
47
41
x if x == NPY_TYPES :: NPY_USHORT as i32 => NpyDataType :: Uint16 ,
48
42
x if x == NPY_TYPES :: NPY_UINT as i32 => NpyDataType :: Uint32 ,
49
- x if x == NPY_TYPES :: NPY_ULONG as i32 => {
50
- if cfg ! ( any( windows, target_pointer_width = "32" ) ) {
51
- NpyDataType :: Uint32
52
- } else {
53
- NpyDataType :: Uint64
54
- }
55
- }
43
+ x if x == NPY_TYPES :: NPY_ULONG as i32 => NpyDataType :: from_clong ( true ) ,
56
44
x if x == NPY_TYPES :: NPY_ULONGLONG as i32 => NpyDataType :: Uint64 ,
57
45
x if x == NPY_TYPES :: NPY_FLOAT as i32 => NpyDataType :: Float32 ,
58
46
x if x == NPY_TYPES :: NPY_DOUBLE as i32 => NpyDataType :: Float64 ,
@@ -61,6 +49,24 @@ impl NpyDataType {
61
49
_ => NpyDataType :: Unsupported ,
62
50
}
63
51
}
52
+ #[ inline( always) ]
53
+ fn from_clong ( is_usize : bool ) -> NpyDataType {
54
+ if cfg ! ( any( target_pointer_width = "32" , windows) ) {
55
+ if is_usize {
56
+ NpyDataType :: Uint32
57
+ } else {
58
+ NpyDataType :: Int32
59
+ }
60
+ } else if cfg ! ( all( target_pointer_width = "64" , not( windows) ) ) {
61
+ if is_usize {
62
+ NpyDataType :: Uint64
63
+ } else {
64
+ NpyDataType :: Int64
65
+ }
66
+ } else {
67
+ NpyDataType :: Unsupported
68
+ }
69
+ }
64
70
}
65
71
66
72
pub trait TypeNum : Clone {
@@ -84,7 +90,7 @@ macro_rules! impl_type_num {
84
90
}
85
91
}
86
92
} ;
87
- } // impl_type_num!
93
+ }
88
94
89
95
impl_type_num ! ( bool , Bool , NPY_BOOL ) ;
90
96
impl_type_num ! ( i8 , Int8 , NPY_BYTE ) ;
@@ -97,12 +103,12 @@ impl_type_num!(c32, Complex32, NPY_CFLOAT);
97
103
impl_type_num ! ( c64, Complex64 , NPY_CDOUBLE ) ;
98
104
99
105
cfg_if ! {
100
- if #[ cfg( any( windows , target_pointer_width = "32" ) ) ] {
106
+ if #[ cfg( any( target_pointer_width = "32" , windows ) ) ] {
101
107
impl_type_num!( i32 , Int32 , NPY_INT , NPY_LONG ) ;
102
108
impl_type_num!( u32 , Uint32 , NPY_UINT , NPY_ULONG ) ;
103
109
impl_type_num!( i64 , Int64 , NPY_LONGLONG ) ;
104
110
impl_type_num!( u64 , Uint64 , NPY_ULONGLONG ) ;
105
- } else {
111
+ } else if # [ cfg ( all ( target_pointer_width = "64" , not ( windows ) ) ) ] {
106
112
impl_type_num!( i32 , Int32 , NPY_INT ) ;
107
113
impl_type_num!( u32 , Uint32 , NPY_UINT ) ;
108
114
impl_type_num!( i64 , Int64 , NPY_LONG , NPY_LONGLONG ) ;
0 commit comments