@@ -234,6 +234,8 @@ def _check_device(self, other):
234
234
elif isinstance (other , Array ):
235
235
if self .device != other .device :
236
236
raise ValueError (f"Arrays from two different devices ({ self .device } and { other .device } ) can not be combined." )
237
+ else :
238
+ raise TypeError (f"Cannot combine an Array with { type (other )} ." )
237
239
238
240
# Helper function to match the type promotion rules in the spec
239
241
def _promote_scalar (self , scalar ):
@@ -1066,6 +1068,7 @@ def __imod__(self: Array, other: Union[int, float, Array], /) -> Array:
1066
1068
"""
1067
1069
Performs the operation __imod__.
1068
1070
"""
1071
+ self ._check_device (other )
1069
1072
other = self ._check_allowed_dtypes (other , "real numeric" , "__imod__" )
1070
1073
if other is NotImplemented :
1071
1074
return other
@@ -1088,6 +1091,7 @@ def __imul__(self: Array, other: Union[int, float, Array], /) -> Array:
1088
1091
"""
1089
1092
Performs the operation __imul__.
1090
1093
"""
1094
+ self ._check_device (other )
1091
1095
other = self ._check_allowed_dtypes (other , "numeric" , "__imul__" )
1092
1096
if other is NotImplemented :
1093
1097
return other
@@ -1110,6 +1114,7 @@ def __ior__(self: Array, other: Union[int, bool, Array], /) -> Array:
1110
1114
"""
1111
1115
Performs the operation __ior__.
1112
1116
"""
1117
+ self ._check_device (other )
1113
1118
other = self ._check_allowed_dtypes (other , "integer or boolean" , "__ior__" )
1114
1119
if other is NotImplemented :
1115
1120
return other
@@ -1132,6 +1137,7 @@ def __ipow__(self: Array, other: Union[int, float, Array], /) -> Array:
1132
1137
"""
1133
1138
Performs the operation __ipow__.
1134
1139
"""
1140
+ self ._check_device (other )
1135
1141
other = self ._check_allowed_dtypes (other , "numeric" , "__ipow__" )
1136
1142
if other is NotImplemented :
1137
1143
return other
@@ -1144,6 +1150,7 @@ def __rpow__(self: Array, other: Union[int, float, Array], /) -> Array:
1144
1150
"""
1145
1151
from ._elementwise_functions import pow
1146
1152
1153
+ self ._check_device (other )
1147
1154
other = self ._check_allowed_dtypes (other , "numeric" , "__rpow__" )
1148
1155
if other is NotImplemented :
1149
1156
return other
@@ -1155,6 +1162,7 @@ def __irshift__(self: Array, other: Union[int, Array], /) -> Array:
1155
1162
"""
1156
1163
Performs the operation __irshift__.
1157
1164
"""
1165
+ self ._check_device (other )
1158
1166
other = self ._check_allowed_dtypes (other , "integer" , "__irshift__" )
1159
1167
if other is NotImplemented :
1160
1168
return other
@@ -1177,6 +1185,7 @@ def __isub__(self: Array, other: Union[int, float, Array], /) -> Array:
1177
1185
"""
1178
1186
Performs the operation __isub__.
1179
1187
"""
1188
+ self ._check_device (other )
1180
1189
other = self ._check_allowed_dtypes (other , "numeric" , "__isub__" )
1181
1190
if other is NotImplemented :
1182
1191
return other
@@ -1199,6 +1208,7 @@ def __itruediv__(self: Array, other: Union[float, Array], /) -> Array:
1199
1208
"""
1200
1209
Performs the operation __itruediv__.
1201
1210
"""
1211
+ self ._check_device (other )
1202
1212
other = self ._check_allowed_dtypes (other , "floating-point" , "__itruediv__" )
1203
1213
if other is NotImplemented :
1204
1214
return other
@@ -1221,6 +1231,7 @@ def __ixor__(self: Array, other: Union[int, bool, Array], /) -> Array:
1221
1231
"""
1222
1232
Performs the operation __ixor__.
1223
1233
"""
1234
+ self ._check_device (other )
1224
1235
other = self ._check_allowed_dtypes (other , "integer or boolean" , "__ixor__" )
1225
1236
if other is NotImplemented :
1226
1237
return other
0 commit comments