• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TENSORFLOW_COMPILER_XLA_CLIENT_LIB_SVD_H_
17 #define TENSORFLOW_COMPILER_XLA_CLIENT_LIB_SVD_H_
18 
19 #include "tensorflow/compiler/xla/client/xla_builder.h"
20 #include "tensorflow/compiler/xla/xla_data.pb.h"
21 
22 namespace xla {
23 
24 // The singular value decomposition of a given matrix A[..., M, N], the original
25 // matrix is recovered by u * diag(d) * v_t, where the first dims(A) - 2
26 // dimensions are batch dimensions.
27 struct SVDResult {
28   // The columns of U are the left-singular vectors, e.g.,
29   // U[..., :, :]_T * U[..., :, :] = I.
30   XlaOp u;
31   // Vector(s) with the singular values, within each vector sorted in descending
32   // order. The first dims(D) - 1 dimensions have the same size as the batch
33   // dimensions of A. And U[..., :, i] * D[..., i] = A[..., :, :] * V[..., :,
34   // i].
35   XlaOp d;
36   // The columns of V are the right-singular vectors. e.g.,
37   // V[..., :, :]_T * U[..., :, :] = I.
38   XlaOp v;
39 };
40 
41 // TODO(kuny): Add a bool flag that supports SVD with economy (reduced)
42 // representation, which is more memory efficient, especially in the case of
43 // tall-skinny matrices.
44 SVDResult SVD(XlaOp a, int64 max_iter = 100, float epsilon = 1e-6,
45               PrecisionConfig::Precision precision = PrecisionConfig::HIGHEST);
46 
47 }  // namespace xla
48 
49 #endif  // TENSORFLOW_COMPILER_XLA_CLIENT_LIB_SVD_H_
50