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

Function TopKShapeFn

tensorflow/core/ops/nn_ops.cc:1355–1387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1353namespace {
1354
1355Status TopKShapeFn(InferenceContext* c) {
1356 ShapeHandle input;
1357 TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), 1, &input));
1358
1359 // Get the k value, either from input tensor or attribute.
1360 DimensionHandle k_dim;
1361 if (c->num_inputs() >= 2) {
1362 TF_RETURN_IF_ERROR(c->MakeDimForScalarInput(1, &k_dim));
1363 } else {
1364 int32 k;
1365 TF_RETURN_IF_ERROR(c->GetAttr("k", &k));
1366 if (k < 0) {
1367 return errors::InvalidArgument("Need k >= 0, got ", k);
1368 }
1369 k_dim = c->MakeDim(k);
1370 }
1371
1372 DimensionHandle last_dim = c->Dim(input, -1);
1373 if (c->ValueKnown(last_dim) && c->ValueKnown(k_dim) &&
1374 c->Value(last_dim) < c->Value(k_dim)) {
1375 return errors::InvalidArgument(
1376 "input must have last dimension >= k = ", c->Value(k_dim), " but is ",
1377 c->Value(last_dim));
1378 }
1379
1380 // Replace last_dim with k_dim.
1381 ShapeHandle s;
1382 TF_RETURN_IF_ERROR(c->Subshape(input, 0, -1, &s));
1383 TF_RETURN_IF_ERROR(c->Concatenate(s, c->Vector(k_dim), &s));
1384 c->set_output(0, s);
1385 c->set_output(1, s);
1386 return Status::OK();
1387}
1388
1389} // namespace
1390

Callers

nothing calls this directly

Calls 14

InvalidArgumentFunction · 0.85
WithRankAtLeastMethod · 0.80
MakeDimForScalarInputMethod · 0.80
ValueKnownMethod · 0.80
SubshapeMethod · 0.80
VectorMethod · 0.80
inputMethod · 0.45
num_inputsMethod · 0.45
GetAttrMethod · 0.45
MakeDimMethod · 0.45
DimMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected