Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/linalg/registrations_util.py: 19%
26 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Common utilities for registering LinearOperator methods."""
18# Note: only use this method in the commuting case.
19def combined_commuting_self_adjoint_hint(operator_a, operator_b):
20 """Get combined hint for self-adjoint-ness."""
22 # The property is preserved under composition when the operators commute.
23 if operator_a.is_self_adjoint and operator_b.is_self_adjoint:
24 return True
26 # The property is not preserved when an operator with the property is composed
27 # with an operator without the property.
29 # pylint:disable=g-bool-id-comparison
30 if ((operator_a.is_self_adjoint is True and
31 operator_b.is_self_adjoint is False) or
32 (operator_a.is_self_adjoint is False and
33 operator_b.is_self_adjoint is True)):
34 return False
35 # pylint:enable=g-bool-id-comparison
37 # The property is not known when operators are not known to have the property
38 # or both operators don't have the property (the property for the complement
39 # class is not closed under composition).
40 return None
43def is_square(operator_a, operator_b):
44 """Return a hint to whether the composition is square."""
45 if operator_a.is_square and operator_b.is_square:
46 return True
47 if operator_a.is_square is False and operator_b.is_square is False: # pylint:disable=g-bool-id-comparison
48 # Let A have shape [B, M, N], B have shape [B, N, L].
49 m = operator_a.range_dimension
50 l = operator_b.domain_dimension
51 if m is not None and l is not None:
52 return m == l
54 if (operator_a.is_square != operator_b.is_square) and (
55 operator_a.is_square is not None and operator_b.is_square is not None):
56 return False
58 return None
61# Note: Positive definiteness is only guaranteed to be preserved
62# when the operators commute and are symmetric. Only use this method in
63# commuting cases.
64def combined_commuting_positive_definite_hint(operator_a, operator_b):
65 """Get combined PD hint for compositions."""
66 # pylint:disable=g-bool-id-comparison
67 if (operator_a.is_positive_definite is True and
68 operator_a.is_self_adjoint is True and
69 operator_b.is_positive_definite is True and
70 operator_b.is_self_adjoint is True):
71 return True
72 # pylint:enable=g-bool-id-comparison
74 return None
77def combined_non_singular_hint(operator_a, operator_b):
78 """Get combined hint for when ."""
79 # If either operator is not-invertible the composition isn't.
81 # pylint:disable=g-bool-id-comparison
82 if (operator_a.is_non_singular is False or
83 operator_b.is_non_singular is False):
84 return False
85 # pylint:enable=g-bool-id-comparison
87 return operator_a.is_non_singular and operator_b.is_non_singular