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

Method CompareOrthogonal

tensorflow/compiler/tests/qr_op_test.py:40–55  ·  view source on GitHub ↗
(self, x, y, rank)

Source from the content-addressed store, hash-verified

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.

Callers 1

_testMethod · 0.95

Calls 4

AdjustedNormMethod · 0.95
divideMethod · 0.80
sumMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected