Example #1
0
 def testGain(self):
   self.skipTest("Doesn't work without the graphs")
   init1 = init_ops_v2.Orthogonal(seed=1)
   init2 = init_ops_v2.Orthogonal(gain=3.14, seed=1)
   with test_util.use_gpu():
     t1 = self.evaluate(init1(shape=(10, 10)))
     t2 = self.evaluate(init2(shape=(10, 10)))
   self.assertAllClose(t1, t2 / 3.14)
 def testPartition(self):
     init = init_ops_v2.Orthogonal(seed=1)
     with self.assertRaisesWithLiteralMatch(
             ValueError,
             r"Orthogonal initializer doesn't support partition-related arguments"
     ):
         init((4, 2), dtype=dtypes.float32, partition_shape=(2, 2))
Example #3
0
    def testShapesValues(self):

        if test.is_built_with_rocm():
            self.skipTest(
                "Disable subtest on ROCm due to missing QR op support")

        for shape in [(10, 10), (10, 9, 8), (100, 5, 5), (50, 40), (40, 50)]:
            init = init_ops_v2.Orthogonal()
            tol = 1e-5
            with test_util.use_gpu():
                # Check the shape
                t = self.evaluate(init(shape))
                self.assertAllEqual(shape, t.shape)
                # Check orthogonality by computing the inner product
                t = t.reshape((np.prod(t.shape[:-1]), t.shape[-1]))
                if t.shape[0] > t.shape[1]:
                    self.assertAllClose(np.dot(t.T, t),
                                        np.eye(t.shape[1]),
                                        rtol=tol,
                                        atol=tol)
                else:
                    self.assertAllClose(np.dot(t, t.T),
                                        np.eye(t.shape[0]),
                                        rtol=tol,
                                        atol=tol)
Example #4
0
 def testShapesValues(self):
   for shape in [(10, 10), (10, 9, 8), (100, 5, 5), (50, 40), (40, 50)]:
     init = init_ops_v2.Orthogonal()
     tol = 1e-5
     with test_util.use_gpu():
       # Check the shape
       t = self.evaluate(init(shape))
       self.assertAllEqual(shape, t.shape)
       # Check orthogonality by computing the inner product
       t = t.reshape((np.prod(t.shape[:-1]), t.shape[-1]))
       if t.shape[0] > t.shape[1]:
         self.assertAllClose(
             np.dot(t.T, t), np.eye(t.shape[1]), rtol=tol, atol=tol)
       else:
         self.assertAllClose(
             np.dot(t, t.T), np.eye(t.shape[0]), rtol=tol, atol=tol)
Example #5
0
 def testInvalidShape(self):
   init = init_ops_v2.Orthogonal()
   with test_util.use_gpu():
     self.assertRaises(ValueError, init, shape=[5])
Example #6
0
 def testInvalidDataType(self):
   init = init_ops_v2.Orthogonal()
   self.assertRaises(ValueError, init, shape=(10, 10), dtype=dtypes.string)
Example #7
0
 def testDuplicatedInitializer(self):
   init = init_ops_v2.Orthogonal()
   self._duplicated_test(init, (10, 10))
Example #8
0
 def testInitializerDifferent(self):
   init1 = init_ops_v2.Orthogonal(seed=1)
   init2 = init_ops_v2.Orthogonal(seed=2)
   self._identical_test(init1, init2, False, (10, 10))
Example #9
0
 def testInitializerIdentical(self):
   self.skipTest("Doesn't work without the graphs")
   init1 = init_ops_v2.Orthogonal(seed=1)
   init2 = init_ops_v2.Orthogonal(seed=1)
   self._identical_test(init1, init2, True, (10, 10))
Example #10
0
 def testRangeInitializer(self):
   self._range_test(init_ops_v2.Orthogonal(seed=123), shape=(20, 20),
                    target_mean=0.)