3737from tensorflow .python .ops import resource_variable_ops
3838from tensorflow .python .ops import variables
3939from tensorflow .python .ops .linalg import linalg_impl as linalg
40- from tensorflow .python .ops .linalg import linear_operator_algebra
4140from tensorflow .python .ops .linalg import linear_operator_util
4241from tensorflow .python .ops .linalg import property_hint_util
4342from tensorflow .python .ops .linalg import slicing
@@ -963,7 +962,7 @@ def solve(self, rhs, adjoint=False, adjoint_arg=False, name="solve"):
963962 " {} but got {}." .format (
964963 left_operator .domain_dimension , right_operator .range_dimension ))
965964 with self ._name_scope (name ): # pylint: disable=not-callable
966- return linear_operator_algebra . solve (left_operator , right_operator )
965+ return self . _linop_solve (left_operator , right_operator )
967966
968967 with self ._name_scope (name ): # pylint: disable=not-callable
969968 rhs = tensor_conversion .convert_to_tensor_v2_with_dispatch (
@@ -979,6 +978,48 @@ def solve(self, rhs, adjoint=False, adjoint_arg=False, name="solve"):
979978
980979 return self ._solve (rhs , adjoint = adjoint , adjoint_arg = adjoint_arg )
981980
981+ def _linop_solve (
982+ self , left_operator : "LinearOperator" , right_operator : "LinearOperator"
983+ ) -> "LinearOperator" :
984+ # instance of linear_operator_identity.LinearOperatorIdentity
985+ if hasattr (right_operator , "_ones_diag" ) and not hasattr (
986+ right_operator , "multiplier"
987+ ):
988+ return left_operator .inverse ()
989+
990+ # Generic solve of two `LinearOperator`s.
991+ is_square = property_hint_util .is_square (left_operator , right_operator )
992+ is_non_singular = None
993+ is_self_adjoint = None
994+ is_positive_definite = None
995+
996+ if is_square :
997+ is_non_singular = property_hint_util .combined_non_singular_hint (
998+ left_operator , right_operator
999+ )
1000+ elif is_square is False : # pylint:disable=g-bool-id-comparison
1001+ is_non_singular = False
1002+ is_self_adjoint = False
1003+ is_positive_definite = False
1004+
1005+ # LinearOperator outputs a LinearOperatorComposition instance that contains
1006+ # a LinearOperatorInversion instance, both of which
1007+ # inherit from LinearOperator. The inline import is necessary to avoid
1008+ # errors due to this cyclic dependency.
1009+ from tensorflow .python .ops .linalg import linear_operator_composition # pylint: disable=g-import-not-at-top
1010+ from tensorflow .python .ops .linalg import linear_operator_inversion # pylint: disable=g-import-not-at-top
1011+
1012+ return linear_operator_composition .LinearOperatorComposition (
1013+ operators = [
1014+ linear_operator_inversion .LinearOperatorInversion (left_operator ),
1015+ right_operator ,
1016+ ],
1017+ is_non_singular = is_non_singular ,
1018+ is_self_adjoint = is_self_adjoint ,
1019+ is_positive_definite = is_positive_definite ,
1020+ is_square = is_square ,
1021+ )
1022+
9821023 def _solvevec (self , rhs , adjoint = False ):
9831024 """Default implementation of _solvevec."""
9841025 rhs_mat = array_ops .expand_dims (rhs , axis = - 1 )
0 commit comments