Ejemplo n.º 1
0
 def testL2DistanceSq(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.l2_distance_sq(n1, n2))
   testing.assert_allclose(
       out[0],
       numpy.power(
           numpy.array(
               [euclidean(n1[0], n2[0]), euclidean(
                   n1[1], n2[1])]), 2),
       rtol=TOLERANCE)
Ejemplo n.º 2
0
 def test_l2_distance_sq(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.l2_distance_sq(n1, n2))
   testing.assert_allclose(
       out[0],
       numpy.power(
           numpy.array(
               [euclidean(n1[0], n2[0]), euclidean(
                   n1[1], n2[1])]), 2),
       rtol=TOLERANCE, atol=TOLERANCE)
Ejemplo n.º 3
0
 def testL2DistanceSqWithBroadcast(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.l2_distance_sq(n1, n2))
   expected = numpy.array(
       [[euclidean(n1[0, 0], n2[0]), euclidean(
           n1[0, 1], n2[1])], [euclidean(n1[1, 0], n2[0]),
                               euclidean(n1[1, 1], n2[1])]])
   expected = numpy.power(expected, 2)
   testing.assert_allclose(expected, out[0], atol=TOLERANCE)
Ejemplo n.º 4
0
 def test_l2_distance_sq_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.l2_distance_sq(n1, n2))
   expected = numpy.array(
       [[euclidean(n1[0, 0], n2[0]), euclidean(
           n1[0, 1], n2[1])], [euclidean(n1[1, 0], n2[0]),
                               euclidean(n1[1, 1], n2[1])]])
   expected = numpy.power(expected, 2)
   testing.assert_allclose(expected, out[0], atol=TOLERANCE)