@@ -119,28 +119,31 @@ def __str__(self):
119
119
### comparisons ###
120
120
def __eq__ (self , other ):
121
121
try :
122
- t_other = asarray (other ). get
122
+ return _ufunc_impl . equal ( self , asarray (other ))
123
123
except RuntimeError :
124
124
# Failed to convert other to array: definitely not equal.
125
- # TODO: generalize, delegate to ufuncs
126
125
falsy = torch .full (self .shape , fill_value = False , dtype = bool )
127
126
return asarray (falsy )
128
- return asarray (self ._tensor == asarray (other ).get ())
129
127
130
128
def __neq__ (self , other ):
131
- return asarray (self ._tensor != asarray (other ).get ())
129
+ try :
130
+ return _ufunc_impl .not_equal (self , asarray (other ))
131
+ except RuntimeError :
132
+ # Failed to convert other to array: definitely not equal.
133
+ falsy = torch .full (self .shape , fill_value = True , dtype = bool )
134
+ return asarray (falsy )
132
135
133
136
def __gt__ (self , other ):
134
- return asarray (self . _tensor > asarray (other ). get ( ))
137
+ return _ufunc_impl . greater (self , asarray (other ))
135
138
136
139
def __lt__ (self , other ):
137
- return asarray (self . _tensor < asarray (other ). get ( ))
140
+ return _ufunc_impl . less (self , asarray (other ))
138
141
139
142
def __ge__ (self , other ):
140
- return asarray (self . _tensor >= asarray (other ). get ( ))
143
+ return _ufunc_impl . greater_equal (self , asarray (other ))
141
144
142
145
def __le__ (self , other ):
143
- return asarray (self . _tensor <= asarray (other ). get ( ))
146
+ return _ufunc_impl . less_equal (self , asarray (other ))
144
147
145
148
def __bool__ (self ):
146
149
try :
@@ -270,6 +273,7 @@ def __rand__(self, other):
270
273
def __iand__ (self , other ):
271
274
return _ufunc_impl .bitwise_and (self , asarray (other ), out = self )
272
275
276
+
273
277
# or, self | other
274
278
def __or__ (self , other ):
275
279
return _ufunc_impl .bitwise_or (self , asarray (other ))
@@ -280,6 +284,7 @@ def __ror__(self, other):
280
284
def __ior__ (self , other ):
281
285
return _ufunc_impl .bitwise_or (self , asarray (other ), out = self )
282
286
287
+
283
288
# xor, self ^ other
284
289
def __xor__ (self , other ):
285
290
return _ufunc_impl .bitwise_xor (self , asarray (other ))
@@ -305,7 +310,6 @@ def __neg__(self):
305
310
return _ufunc_impl .negative (self )
306
311
307
312
308
-
309
313
### methods to match namespace functions
310
314
311
315
def squeeze (self , axis = None ):
0 commit comments