(self, x, y, rank)
| 82 | is_single = dtype_ in (np.float32, np.complex64) |
| 83 | |
| 84 | def CompareOrthogonal(self, x, y, rank): |
| 85 | if is_single: |
| 86 | atol = 5e-4 |
| 87 | else: |
| 88 | atol = 5e-14 |
| 89 | # We only compare the first 'rank' orthogonal vectors since the |
| 90 | # remainder form an arbitrary orthonormal basis for the |
| 91 | # (row- or column-) null space, whose exact value depends on |
| 92 | # implementation details. Notice that since we check that the |
| 93 | # matrices of singular vectors are unitary elsewhere, we do |
| 94 | # implicitly test that the trailing vectors of x and y span the |
| 95 | # same space. |
| 96 | x = x[..., 0:rank] |
| 97 | y = y[..., 0:rank] |
| 98 | # Q is only unique up to sign (complex phase factor for complex matrices), |
| 99 | # so we normalize the sign first. |
| 100 | sum_of_ratios = np.sum(np.divide(y, x), -2, keepdims=True) |
| 101 | phases = np.divide(sum_of_ratios, np.abs(sum_of_ratios)) |
| 102 | x *= phases |
| 103 | self.assertAllClose(x, y, atol=atol) |
| 104 | |
| 105 | def CheckApproximation(self, a, q, r): |
| 106 | if is_single: |
no test coverage detected