MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TridiagonalMatMulShapeFn

Function TridiagonalMatMulShapeFn

tensorflow/core/ops/linalg_ops.cc:213–257  ·  view source on GitHub ↗

Inputs: [...,1,M], [...,1,M], [...,1,M],[...,M,N]. Output is [...,M,N].

Source from the content-addressed store, hash-verified

211// Inputs: [...,1,M], [...,1,M], [...,1,M],[...,M,N].
212// Output is [...,M,N].
213Status TridiagonalMatMulShapeFn(InferenceContext* c) {
214 ShapeHandle superdiag;
215 ShapeHandle maindiag;
216 ShapeHandle subdiag;
217 ShapeHandle rhs;
218
219 // Check that rank is at least 2.
220 TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), 2, &superdiag));
221 TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(1), 2, &maindiag));
222 TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(2), 2, &subdiag));
223 TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(3), 2, &rhs));
224
225 // Extract batch dimensions and check they are the same.
226 ShapeHandle superdiag_batch_shape;
227 ShapeHandle maindiag_batch_shape;
228 ShapeHandle subdiag_batch_shape;
229 ShapeHandle rhs_batch_shape;
230 TF_RETURN_IF_ERROR(c->Subshape(superdiag, 0, -2, &superdiag_batch_shape));
231 TF_RETURN_IF_ERROR(c->Subshape(maindiag, 0, -2, &maindiag_batch_shape));
232 TF_RETURN_IF_ERROR(c->Subshape(subdiag, 0, -2, &subdiag_batch_shape));
233 TF_RETURN_IF_ERROR(c->Subshape(rhs, 0, -2, &rhs_batch_shape));
234 TF_RETURN_IF_ERROR(c->Merge(superdiag, maindiag, &superdiag));
235 TF_RETURN_IF_ERROR(
236 c->Merge(maindiag_batch_shape, rhs_batch_shape, &rhs_batch_shape));
237 TF_RETURN_IF_ERROR(
238 c->Merge(subdiag_batch_shape, rhs_batch_shape, &rhs_batch_shape));
239
240 // Check that diagonals have the same shape.
241 TF_RETURN_IF_ERROR(c->Merge(superdiag, maindiag, &maindiag));
242 TF_RETURN_IF_ERROR(c->Merge(subdiag, maindiag, &maindiag));
243
244 // Check that size of tri-diagonal matrix is the same as height of matrix on
245 // the right.
246 DimensionHandle m_lhs = c->Dim(maindiag, -1);
247 DimensionHandle m_rhs = c->Dim(rhs, -2);
248 TF_RETURN_IF_ERROR(c->Merge(m_lhs, m_rhs, &m_lhs));
249
250 // Check that next-to-last dimension of diagonals is 1.
251 DimensionHandle unused;
252 TF_RETURN_IF_ERROR(c->WithValue(c->Dim(maindiag, -2), 1, &unused));
253
254 // The output shape is the same as rhs shape.
255 c->set_output(0, rhs);
256 return Status::OK();
257}
258
259// The first input is [...,3,M] and second input is [...,M,K].
260// Output is [...,M,K].

Callers

nothing calls this directly

Calls 7

WithRankAtLeastMethod · 0.80
SubshapeMethod · 0.80
WithValueMethod · 0.80
inputMethod · 0.45
MergeMethod · 0.45
DimMethod · 0.45
set_outputMethod · 0.45

Tested by

no test coverage detected