def testL2Distance(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(n1, n2)) testing.assert_allclose( out[0], numpy.array( [euclidean(n1[0], n2[0]), euclidean(n1[1], n2[1]) ]), rtol=TOLERANCE)
def testL2DistanceWithBroadcast(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(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])]]) testing.assert_allclose(expected, out[0], atol=TOLERANCE)
def test_l2_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.l2_distance(n1, n2)) testing.assert_allclose( out[0], numpy.array( [euclidean(n1[0], n2[0]), 1e-6 # Epsilon sets the minimum distance so use that instead of 0. ]), rtol=TOLERANCE, atol=TOLERANCE)
def test_l2_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.l2_distance(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])]]) testing.assert_allclose(expected, out[0], atol=TOLERANCE)
def testL2Distance(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(n1, n2)) testing.assert_allclose( out[0], numpy.array([euclidean(n1[0], n2[0]), euclidean(n1[1], n2[1])]), rtol=TOLERANCE)