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

Function _NormalizingSvd

tensorflow/python/kernel_tests/svd_op_test.py:204–223  ·  view source on GitHub ↗
(tf_a, full_matrices_)

Source from the content-addressed store, hash-verified

202
203
204def _NormalizingSvd(tf_a, full_matrices_):
205 tf_s, tf_u, tf_v = linalg_ops.svd(
206 tf_a, compute_uv=True, full_matrices=full_matrices_)
207 # Singular vectors are only unique up to an arbitrary phase. We normalize
208 # the vectors such that the first component of u (if m >=n) or v (if n > m)
209 # have phase 0.
210 m = tf_a.shape[-2]
211 n = tf_a.shape[-1]
212 if m >= n:
213 top_rows = tf_u[..., 0:1, :]
214 else:
215 top_rows = tf_v[..., 0:1, :]
216 if tf_u.dtype.is_complex:
217 angle = -math_ops.angle(top_rows)
218 phase = math_ops.complex(math_ops.cos(angle), math_ops.sin(angle))
219 else:
220 phase = math_ops.sign(top_rows)
221 tf_u *= phase[..., :m]
222 tf_v *= phase[..., :n]
223 return tf_s, tf_u, tf_v
224
225
226def _GetSvdGradOpTest(dtype_, shape_, compute_uv_, full_matrices_):

Callers 1

TestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected