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

Function CompareSingularVectors

tensorflow/python/kernel_tests/svd_op_test.py:98–113  ·  view source on GitHub ↗
(self, x, y, rank, tol)

Source from the content-addressed store, hash-verified

96 self.assertAllClose(x, y, atol=(x[0] + y[0]) * tol)
97
98 def CompareSingularVectors(self, x, y, rank, tol):
99 # We only compare the first 'rank' singular vectors since the
100 # remainder form an arbitrary orthonormal basis for the
101 # (row- or column-) null space, whose exact value depends on
102 # implementation details. Notice that since we check that the
103 # matrices of singular vectors are unitary elsewhere, we do
104 # implicitly test that the trailing vectors of x and y span the
105 # same space.
106 x = x[..., 0:rank]
107 y = y[..., 0:rank]
108 # Singular vectors are only unique up to sign (complex phase factor for
109 # complex matrices), so we normalize the sign first.
110 sum_of_ratios = np.sum(np.divide(y, x), -2, keepdims=True)
111 phases = np.divide(sum_of_ratios, np.abs(sum_of_ratios))
112 x *= phases
113 self.assertAllClose(x, y, atol=2 * tol)
114
115 def CheckApproximation(self, a, u, s, v, full_matrices_, tol):
116 # Tests that a ~= u*diag(s)*transpose(v).

Callers 1

TestFunction · 0.85

Calls 3

divideMethod · 0.80
sumMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected