(self, x, y, rank)
| 38 | return norm / (max(x.shape[-2:]) * np.finfo(x.dtype).eps) |
| 39 | |
| 40 | def CompareOrthogonal(self, x, y, rank): |
| 41 | # We only compare the first 'rank' orthogonal vectors since the |
| 42 | # remainder form an arbitrary orthonormal basis for the |
| 43 | # (row- or column-) null space, whose exact value depends on |
| 44 | # implementation details. Notice that since we check that the |
| 45 | # matrices of singular vectors are unitary elsewhere, we do |
| 46 | # implicitly test that the trailing vectors of x and y span the |
| 47 | # same space. |
| 48 | x = x[..., 0:rank] |
| 49 | y = y[..., 0:rank] |
| 50 | # Q is only unique up to sign (complex phase factor for complex matrices), |
| 51 | # so we normalize the sign first. |
| 52 | sum_of_ratios = np.sum(np.divide(y, x), -2, keepdims=True) |
| 53 | phases = np.divide(sum_of_ratios, np.abs(sum_of_ratios)) |
| 54 | x *= phases |
| 55 | self.assertTrue(np.all(self.AdjustedNorm(x - y) < 2400.0)) |
| 56 | |
| 57 | def CheckApproximation(self, a, q, r): |
| 58 | # Tests that a ~= q*r. |
no test coverage detected