Example #1
0
 def testL1Distance(self):
   n1 = numpy.array([[1., 2., 3., 4.], [1., 1., 1., 1.]], dtype=numpy.float32)
   n2 = numpy.array([[5., 6., 7., -8.], [1., 1., 1., 1.]], dtype=numpy.float32)
   out = self.Run(functions.l1_distance(n1, n2))
   testing.assert_allclose(
       out[0],
       numpy.array(
           [cityblock(n1[0], n2[0]), cityblock(n1[1], n2[1])
           ]),
       rtol=TOLERANCE)
Example #2
0
 def test_l1_distance(self):
   n1 = numpy.array([[1., 2., 3., 4.], [1., 1., 1., 1.]], dtype=numpy.float32)
   n2 = numpy.array([[5., 6., 7., -8.], [1., 1., 1., 1.]], dtype=numpy.float32)
   out = self.eval_tensor(functions.l1_distance(n1, n2))
   testing.assert_allclose(
       out[0],
       numpy.array(
           [cityblock(n1[0], n2[0]), cityblock(n1[1], n2[1])
           ]),
       rtol=TOLERANCE, atol=TOLERANCE)
Example #3
0
 def testL1DistanceWithBroadcast(self):
   n1 = numpy.array([[[1., 2., 3., 4.], [1., 1., 1., 1.]], [[5., 6., 7., 8.],
                                                            [1., 1., 1., 2.]]],
                    dtype=numpy.float32)
   n2 = numpy.array([[5., 6., 7., -8.], [1., 1., 1., 1.]], dtype=numpy.float32)
   out = self.Run(functions.l1_distance(n1, n2))
   expected = numpy.array(
       [[cityblock(n1[0, 0], n2[0]), cityblock(
           n1[0, 1], n2[1])], [cityblock(n1[1, 0], n2[0]),
                               cityblock(n1[1, 1], n2[1])]])
   testing.assert_allclose(expected, out[0], atol=TOLERANCE)
Example #4
0
 def test_l1_distance_with_broadcast(self):
   n1 = numpy.array([[[1., 2., 3., 4.], [1., 1., 1., 1.]], [[5., 6., 7., 8.],
                                                            [1., 1., 1., 2.]]],
                    dtype=numpy.float32)
   n2 = numpy.array([[5., 6., 7., -8.], [1., 1., 1., 1.]], dtype=numpy.float32)
   out = self.eval_tensor(functions.l1_distance(n1, n2))
   expected = numpy.array(
       [[cityblock(n1[0, 0], n2[0]), cityblock(
           n1[0, 1], n2[1])], [cityblock(n1[1, 0], n2[0]),
                               cityblock(n1[1, 1], n2[1])]])
   testing.assert_allclose(expected, out[0], atol=TOLERANCE)