@@ -26,7 +26,6 @@ Calculates the determinant of a square matrix.
2626
2727input: A tensor of shape `[M, M]`.
2828output: A scalar, equal to the determinant of the input.
29- T: The type of values in the input and output.
3029)doc" );
3130
3231REGISTER_OP (" BatchMatrixDeterminant" )
@@ -42,7 +41,6 @@ for all input submatrices `[..., :, :]`.
4241
4342input: Shape is `[..., M, M]`.
4443output: Shape is `[...]`.
45- T: The type of values in the input and output.
4644)doc" );
4745
4846REGISTER_OP (" MatrixInverse" )
@@ -61,7 +59,6 @@ garbage result.
6159
6260input: Shape is `[M, M]`.
6361output: Shape is `[M, M]` containing the matrix inverse of the input.
64- T: The type of values in the input and output.
6562)doc" );
6663
6764REGISTER_OP (" BatchMatrixInverse" )
@@ -84,7 +81,6 @@ garbage result.
8481
8582input: Shape is `[..., M, M]`.
8683output: Shape is `[..., M, M]`.
87- T: The type of values in the input and output.
8884)doc" );
8985
9086REGISTER_OP (" Cholesky" )
@@ -103,7 +99,6 @@ input.
10399
104100input: Shape is `[M, M]`.
105101output: Shape is `[M, M]`.
106- T: The type of values in the input and output.
107102)doc" );
108103
109104REGISTER_OP (" BatchCholesky" )
@@ -120,7 +115,6 @@ containing the Cholesky decompositions for all input submatrices `[..., :, :]`.
120115
121116input: Shape is `[..., M, M]`.
122117output: Shape is `[..., M, M]`.
123- T: The type of values in the input and output.
124118)doc" );
125119
126120REGISTER_OP (" SelfAdjointEig" )
@@ -138,7 +132,6 @@ subsequent rows are eigenvectors.
138132
139133input: Shape is `[M, M]`.
140134output: Shape is `[M+1, M]`.
141- T: The type of values in the input and output.
142135)doc" );
143136
144137REGISTER_OP (" BatchSelfAdjointEig" )
@@ -157,7 +150,6 @@ eigenvalues, and subsequent [...,1:, :] containing the eigenvectors.
157150
158151input: Shape is `[..., M, M]`.
159152output: Shape is `[..., M+1, M]`.
160- T: The type of values in the input and output.
161153)doc" );
162154
163155REGISTER_OP (" MatrixSolve" )
@@ -172,7 +164,6 @@ matrix: Shape is `[M, M]`.
172164rhs: Shape is `[M, K]`.
173165output: Shape is `[M, K]` containing the tensor that solves
174166matrix * output = rhs.
175- T: The type of values in the input and output.
176167)doc" );
177168
178169REGISTER_OP (" BatchMatrixSolve" )
@@ -191,7 +182,6 @@ matrix satisfies matrix[..., :, :] * output[..., :, :] = rhs[..., :, :].
191182matrix: Shape is `[..., M, M]`.
192183rhs: Shape is `[..., M, K]`.
193184output: Shape is `[..., M, K]`.
194- T: The type of values in the input and output.
195185)doc" );
196186
197187REGISTER_OP (" MatrixTriangularSolve" )
@@ -218,7 +208,6 @@ matrix: Shape is `[M, M]`.
218208rhs: Shape is `[M, K]`.
219209output: Shape is `[M, K]`.
220210lower: Boolean indicating whether matrix is lower or upper triangular.
221- T: The type of values in the input and output.
222211)doc" );
223212
224213REGISTER_OP (" BatchMatrixTriangularSolve" )
@@ -247,7 +236,99 @@ matrix: Shape is `[..., M, M]`.
247236rhs: Shape is `[..., M, K]`.
248237output: Shape is `[..., M, K]`.
249238lower: Boolean indicating whether matrix is lower or upper triangular.
250- T: The type of values in the input and output.
239+ )doc" );
240+
241+ REGISTER_OP (" MatrixSolveLs" )
242+ .Input(" matrix: T" )
243+ .Input(" rhs: T" )
244+ .Input(" l2_regularizer: double" )
245+ .Output(" output: T" )
246+ .Attr(" T: {float, double}" )
247+ .Attr(" fast: bool = True" )
248+ .Doc(R"doc(
249+ Solves a linear least-squares problem.
250+
251+ Below we will use the following notation
252+ `matrix`=\\(A \in \Re^{m \times n}\\),
253+ `rhs`=\\(B \in \Re^{m \times k}\\),
254+ `output`=\\(X \in \Re^{n \times k}\\),
255+ `l2_regularizer`=\\(\lambda\\).
256+
257+ If `fast` is `True`, then the solution is computed by solving the normal
258+ equations using Cholesky decomposition. Specifically, if \\(m \ge n\\) then
259+ \\(X = (A^T A + \lambda I)^{-1} A^T B\\), which solves the least-squares
260+ problem \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k}} ||A Z - B||_F^2 +
261+ \lambda ||Z||_F^2\\). If \\(m \lt n\\) then `output` is computed as
262+ \\(X = A^T (A A^T + \lambda I)^{-1} B\\),
263+ which (for \\(\lambda = 0\\)) is the minimum-norm solution to the
264+ under-determined linear system, i.e.
265+ \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k}} ||Z||_F^2 \\),
266+ subject to \\(A Z = B\\).
267+ Notice that the fast path is only numerically stable when \\(A\\) is
268+ numerically full rank and has a condition number
269+ \\(\mathrm{cond}(A) \lt \frac{1}{\sqrt{\epsilon_{mach}}}\\)
270+ or \\(\lambda\\) is sufficiently large.
271+
272+ If `fast` is `False` then the solution is computed using the rank revealing QR
273+ decomposition with column pivoting. This will always compute a least-squares
274+ solution that minimizes the residual norm \\(||A X - B||_F^2 \\), even when
275+ \\( A \\) is rank deficient or ill-conditioned. Notice: The current version
276+ does not compute a minimum norm solution. If `fast` is `False` then
277+ `l2_regularizer` is ignored.
278+
279+ matrix: Shape is `[M, N]`.
280+ rhs: Shape is `[M, K]`.
281+ output: Shape is `[N, K]` containing the tensor that solves
282+ `matrix * output = rhs` in the least-squares sense.
283+ )doc" );
284+
285+ REGISTER_OP (" BatchMatrixSolveLs" )
286+ .Input(" matrix: T" )
287+ .Input(" rhs: T" )
288+ .Input(" l2_regularizer: double" )
289+ .Output(" output: T" )
290+ .Attr(" T: {float, double}" )
291+ .Attr(" fast: bool = True" )
292+ .Doc(R"doc(
293+ Solves multiple linear least-squares problems.
294+
295+ `matrix` is a tensor of shape `[..., M, N]` whose inner-most 2 dimensions
296+ form square matrices. Rhs is a tensor of shape `[..., M, K]`. The output
297+ is a tensor shape `[..., N, K]` where each output matrix solves each of
298+ the equations matrix[..., :, :] * output[..., :, :] = rhs[..., :, :] in the
299+ least squares sense.
300+
301+ Below we will use the following notation for each pair of
302+ matrix and right-hand sides in the batch:
303+
304+ `matrix`=\\(A \in \Re^{m \times n}\\),
305+ `rhs`=\\(B \in \Re^{m \times k}\\),
306+ `output`=\\(X \in \Re^{n \times k}\\),
307+ `l2_regularizer`=\\(\lambda\\).
308+
309+ If `fast` is `True`, then the solution is computed by solving the normal
310+ equations using Cholesky decomposition. Specifically, if \\(m \ge n\\) then
311+ \\(X = (A^T A + \lambda I)^{-1} A^T B\\), which solves the least-squares
312+ problem \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k}} ||A Z - B||_F^2 +
313+ \lambda ||Z||_F^2\\). If \\(m \lt n\\) then `output` is computed as
314+ \\(X = A^T (A A^T + \lambda I)^{-1} B\\), which (for \\(\lambda = 0\\)) is the
315+ minimum-norm solution to the under-determined linear system, i.e.
316+ \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k}} ||Z||_F^2 \\), subject to
317+ \\(A Z = B\\). Notice that the fast path is only numerically stable when
318+ \\(A\\) is numerically full rank and has a condition number
319+ \\(\mathrm{cond}(A) \lt \frac{1}{\sqrt{\epsilon_{mach}}}\\) or\\(\lambda\\) is
320+ sufficiently large.
321+
322+ If `fast` is `False` then the solution is computed using the rank revealing QR
323+ decomposition with column pivoting. This will always compute a least-squares
324+ solution that minimizes the residual norm \\(||A X - B||_F^2\\), even when
325+ \\(A\\) is rank deficient or ill-conditioned. Notice: The current version does
326+ not compute a minimum norm solution. If `fast` is `False` then `l2_regularizer`
327+ is ignored.
328+
329+ matrix: Shape is `[..., M, N]`.
330+ rhs: Shape is `[..., M, K]`.
331+ output: Shape is `[..., N, K]`.
251332)doc" );
252333
253334} // namespace tensorflow
0 commit comments