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

Method solve

tensorflow/python/ops/linalg/linear_operator.py:741–814  ·  view source on GitHub ↗

Solve (exact or approx) `R` (batch) systems of equations: `A X = rhs`. The returned `Tensor` will be close to an exact solution if `A` is well conditioned. Otherwise closeness will vary. See class docstring for details. Examples: ```python # Make an operator acting like batch

(self, rhs, adjoint=False, adjoint_arg=False, name="solve")

Source from the content-addressed store, hash-verified

739 self.to_dense(), rhs, adjoint=adjoint)
740
741 def solve(self, rhs, adjoint=False, adjoint_arg=False, name="solve"):
742 """Solve (exact or approx) `R` (batch) systems of equations: `A X = rhs`.
743
744 The returned `Tensor` will be close to an exact solution if `A` is well
745 conditioned. Otherwise closeness will vary. See class docstring for details.
746
747 Examples:
748
749 ```python
750 # Make an operator acting like batch matrix A. Assume A.shape = [..., M, N]
751 operator = LinearOperator(...)
752 operator.shape = [..., M, N]
753
754 # Solve R > 0 linear systems for every member of the batch.
755 RHS = ... # shape [..., M, R]
756
757 X = operator.solve(RHS)
758 # X[..., :, r] is the solution to the r'th linear system
759 # sum_j A[..., :, j] X[..., j, r] = RHS[..., :, r]
760
761 operator.matmul(X)
762 ==> RHS
763 ```
764
765 Args:
766 rhs: `Tensor` with same `dtype` as this operator and compatible shape.
767 `rhs` is treated like a [batch] matrix meaning for every set of leading
768 dimensions, the last two dimensions defines a matrix.
769 See class docstring for definition of compatibility.
770 adjoint: Python `bool`. If `True`, solve the system involving the adjoint
771 of this `LinearOperator`: `A^H X = rhs`.
772 adjoint_arg: Python `bool`. If `True`, solve `A X = rhs^H` where `rhs^H`
773 is the hermitian transpose (transposition and complex conjugation).
774 name: A name scope to use for ops added by this method.
775
776 Returns:
777 `Tensor` with shape `[...,N, R]` and same `dtype` as `rhs`.
778
779 Raises:
780 NotImplementedError: If `self.is_non_singular` or `is_square` is False.
781 """
782 if self.is_non_singular is False:
783 raise NotImplementedError(
784 "Exact solve not implemented for an operator that is expected to "
785 "be singular.")
786 if self.is_square is False:
787 raise NotImplementedError(
788 "Exact solve not implemented for an operator that is expected to "
789 "not be square.")
790 if isinstance(rhs, LinearOperator):
791 left_operator = self.adjoint() if adjoint else self
792 right_operator = rhs.adjoint() if adjoint_arg else rhs
793
794 if (right_operator.range_dimension is not None and
795 left_operator.domain_dimension is not None and
796 right_operator.range_dimension != left_operator.domain_dimension):
797 raise ValueError(
798 "Operators are incompatible. Expected `rhs` to have dimension"

Callers 15

_solvevecMethod · 0.95
_testLegalInputsMethod · 0.80
_kl_brute_forceFunction · 0.80
_log_probMethod · 0.80
_inverseMethod · 0.80
_inverseMethod · 0.80
_verifySolveMethod · 0.80
_SolveWithNumpyFunction · 0.80
_verifySolveMethod · 0.80

Calls 6

adjointMethod · 0.95
_name_scopeMethod · 0.95
_check_input_dtypeMethod · 0.95
_solveMethod · 0.95
formatMethod · 0.45