MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ops_test

Method ops_test

tensorflow/python/eager/ops_test.py:169–202  ·  view source on GitHub ↗
(v1, v2)

Source from the content-addressed store, hash-verified

167 def testOperatorOverrides(self):
168
169 def ops_test(v1, v2):
170 a = constant_op.constant(v1)
171 b = constant_op.constant(v2)
172
173 self.assertAllEqual((-a), np.negative(v1))
174 self.assertAllEqual(abs(b), np.absolute(v2))
175
176 self.assertAllEqual((a + b), np.add(v1, v2))
177 self.assertAllEqual((a - b), np.subtract(v1, v2))
178 self.assertAllEqual((a * b), np.multiply(v1, v2))
179 self.assertAllEqual((a * a), np.multiply(v1, v1))
180
181 if all(x >= 0 for x in v2):
182 self.assertAllEqual((a**b), np.power(v1, v2))
183 self.assertAllEqual((a / b), np.true_divide(v1, v2))
184
185 self.assertAllEqual((a / a), np.true_divide(v1, v1))
186 self.assertAllEqual((a % b), np.mod(v1, v2))
187
188 self.assertAllEqual((a < b), np.less(v1, v2))
189 self.assertAllEqual((a <= b), np.less_equal(v1, v2))
190 self.assertAllEqual((a > b), np.greater(v1, v2))
191 self.assertAllEqual((a >= b), np.greater_equal(v1, v2))
192
193 # TODO(b/120678848): Remove the else branch once we enable
194 # ops.Tensor._USE_EQUALITY by default.
195 if ops.Tensor._USE_EQUALITY:
196 self.assertAllEqual((a == b), np.equal(v1, v2))
197 self.assertAllEqual((a != b), np.not_equal(v1, v2))
198 else:
199 self.assertAllEqual((a == b), np.equal(v1, v2)[0])
200 self.assertAllEqual((a != b), np.not_equal(v1, v2)[0])
201
202 self.assertAllEqual(v1[0], a[constant_op.constant(0)])
203
204 ops_test([1, 4, 8], [2, 3, 5])
205 ops_test([1, -4, -5], [-2, 3, -6])

Callers

nothing calls this directly

Calls 11

allFunction · 0.85
multiplyMethod · 0.80
powerMethod · 0.80
modMethod · 0.80
greaterMethod · 0.80
equalMethod · 0.80
not_equalMethod · 0.80
absFunction · 0.50
constantMethod · 0.45
assertAllEqualMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected