(self, a, u, s, v, full_matrices_, tol)
| 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. |
no test coverage detected