Compute the matrix rank of one or more matrices. Arguments: a: (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be pseudo-inverted. tol: Threshold below which the singular value is counted as 'zero'. Default value: `None` (i.e., `eps * max(rows, cols) * max(singu
(a, tol=None, validate_args=False, name=None)
| 658 | |
| 659 | @tf_export('linalg.matrix_rank') |
| 660 | def matrix_rank(a, tol=None, validate_args=False, name=None): |
| 661 | """Compute the matrix rank of one or more matrices. |
| 662 | |
| 663 | Arguments: |
| 664 | a: (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be |
| 665 | pseudo-inverted. |
| 666 | tol: Threshold below which the singular value is counted as 'zero'. |
| 667 | Default value: `None` (i.e., `eps * max(rows, cols) * max(singular_val)`). |
| 668 | validate_args: When `True`, additional assertions might be embedded in the |
| 669 | graph. |
| 670 | Default value: `False` (i.e., no graph assertions are added). |
| 671 | name: Python `str` prefixed to ops created by this function. |
| 672 | Default value: 'matrix_rank'. |
| 673 | |
| 674 | Returns: |
| 675 | matrix_rank: (Batch of) `int32` scalars representing the number of non-zero |
| 676 | singular values. |
| 677 | """ |
| 678 | with ops.name_scope(name or 'matrix_rank'): |
| 679 | a = ops.convert_to_tensor(a, dtype_hint=dtypes.float32, name='a') |
| 680 | assertions = _maybe_validate_matrix(a, validate_args) |
| 681 | if assertions: |
| 682 | with ops.control_dependencies(assertions): |
| 683 | a = array_ops.identity(a) |
| 684 | s = svd(a, compute_uv=False) |
| 685 | if tol is None: |
| 686 | if (a.shape[-2:]).is_fully_defined(): |
| 687 | m = np.max(a.shape[-2:].as_list()) |
| 688 | else: |
| 689 | m = math_ops.reduce_max(array_ops.shape(a)[-2:]) |
| 690 | eps = np.finfo(a.dtype.as_numpy_dtype).eps |
| 691 | tol = ( |
| 692 | eps * math_ops.cast(m, a.dtype) * |
| 693 | math_ops.reduce_max(s, axis=-1, keepdims=True)) |
| 694 | return math_ops.reduce_sum(math_ops.cast(s > tol, dtypes.int32), axis=-1) |
| 695 | |
| 696 | |
| 697 | @tf_export('linalg.pinv') |
nothing calls this directly
no test coverage detected