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

Function CheckApproximation

tensorflow/python/kernel_tests/svd_op_test.py:115–130  ·  view source on GitHub ↗
(self, a, u, s, v, full_matrices_, tol)

Source from the content-addressed store, hash-verified

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).
117 batch_shape = a.shape[:-2]
118 m = a.shape[-2]
119 n = a.shape[-1]
120 diag_s = math_ops.cast(array_ops.matrix_diag(s), dtype=dtype_)
121 if full_matrices_:
122 if m > n:
123 zeros = array_ops.zeros(batch_shape + (m - n, n), dtype=dtype_)
124 diag_s = array_ops.concat([diag_s, zeros], a.ndim - 2)
125 elif n > m:
126 zeros = array_ops.zeros(batch_shape + (m, n - m), dtype=dtype_)
127 diag_s = array_ops.concat([diag_s, zeros], a.ndim - 1)
128 a_recon = math_ops.matmul(u, diag_s)
129 a_recon = math_ops.matmul(a_recon, v, adjoint_b=True)
130 self.assertAllClose(a_recon, a, rtol=tol, atol=tol)
131
132 def CheckUnitary(self, x, tol):
133 # Tests that x[...,:,:]^H * x[...,:,:] is close to the identity.

Callers 1

TestFunction · 0.70

Calls 4

castMethod · 0.45
concatMethod · 0.45
matmulMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected