Input is [...,M,N]. First output is [...,min(M,N)]. Second and third outputs are: [0]; [0], if compute_uv is false. [...,M,M]; [...,N,N], if compute_uv is true and full_matrices is true, [...,M,P]; [...,N,P], if compute_uv is true and full_matrices is false, where P = min(M,N).
| 170 | // [...,M,P]; [...,N,P], if compute_uv is true and full_matrices is false, |
| 171 | // where P = min(M,N). |
| 172 | Status SvdShapeFn(InferenceContext* c) { |
| 173 | ShapeHandle input; |
| 174 | TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), 2, &input)); |
| 175 | DimensionHandle m = c->Dim(input, -2); |
| 176 | DimensionHandle n = c->Dim(input, -1); |
| 177 | DimensionHandle p; |
| 178 | TF_RETURN_IF_ERROR(c->Min(m, n, &p)); |
| 179 | ShapeHandle batch_shape; |
| 180 | TF_RETURN_IF_ERROR(c->Subshape(input, 0, -2, &batch_shape)); |
| 181 | ShapeHandle e_shape; |
| 182 | TF_RETURN_IF_ERROR(c->Concatenate(batch_shape, c->Vector(p), &e_shape)); |
| 183 | c->set_output(0, e_shape); |
| 184 | bool compute_uv; |
| 185 | TF_RETURN_IF_ERROR(c->GetAttr("compute_uv", &compute_uv)); |
| 186 | if (compute_uv) { |
| 187 | ShapeHandle u_shape; |
| 188 | ShapeHandle v_shape; |
| 189 | bool full_matrices; |
| 190 | TF_RETURN_IF_ERROR(c->GetAttr("full_matrices", &full_matrices)); |
| 191 | if (full_matrices) { |
| 192 | TF_RETURN_IF_ERROR( |
| 193 | c->Concatenate(batch_shape, c->Matrix(m, m), &u_shape)); |
| 194 | TF_RETURN_IF_ERROR( |
| 195 | c->Concatenate(batch_shape, c->Matrix(n, n), &v_shape)); |
| 196 | } else { |
| 197 | TF_RETURN_IF_ERROR( |
| 198 | c->Concatenate(batch_shape, c->Matrix(m, p), &u_shape)); |
| 199 | TF_RETURN_IF_ERROR( |
| 200 | c->Concatenate(batch_shape, c->Matrix(n, p), &v_shape)); |
| 201 | } |
| 202 | c->set_output(1, u_shape); |
| 203 | c->set_output(2, v_shape); |
| 204 | } else { |
| 205 | c->set_output(1, c->Vector(0ll)); |
| 206 | c->set_output(2, c->Vector(0ll)); |
| 207 | } |
| 208 | return Status::OK(); |
| 209 | } |
| 210 | |
| 211 | // Inputs: [...,1,M], [...,1,M], [...,1,M],[...,M,N]. |
| 212 | // Output is [...,M,N]. |
nothing calls this directly
no test coverage detected