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

Method Compute

tensorflow/core/kernels/tensor_array_ops.cc:1234–1350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1232 : OpKernel(context) {}
1233
1234 void Compute(OpKernelContext* ctx) override {
1235 OP_REQUIRES_OK(ctx, SetupFlowControlInputs(ctx, true));
1236
1237 TensorArray* tensor_array = nullptr;
1238 OP_REQUIRES_OK(ctx, GetTensorArray(ctx, &tensor_array));
1239 core::ScopedUnref unref(tensor_array);
1240 const Tensor* tensor_value;
1241 OP_REQUIRES_OK(ctx, ctx->input("value", &tensor_value));
1242 const Tensor* tensor_lengths;
1243 OP_REQUIRES_OK(ctx, ctx->input("lengths", &tensor_lengths));
1244
1245 OP_REQUIRES(ctx, TensorShapeUtils::IsVector(tensor_lengths->shape()),
1246 errors::InvalidArgument(
1247 "Expected lengths to be a vector, received shape: ",
1248 tensor_lengths->shape().DebugString()));
1249 OP_REQUIRES(ctx,
1250 FastBoundsCheck(tensor_lengths->NumElements(),
1251 std::numeric_limits<int32>::max()),
1252 errors::InvalidArgument(
1253 "Expected lengths to have < max int32 entries"));
1254
1255 int32 num_tensors = static_cast<int32>(tensor_lengths->NumElements());
1256 auto tensor_lengths_t = tensor_lengths->vec<int64>();
1257 std::vector<int64> cumulative_lengths;
1258 cumulative_lengths.reserve(num_tensors);
1259 int64 total_length = 0;
1260 for (int i = 0; i < num_tensors; ++i) {
1261 total_length += tensor_lengths_t(i);
1262 cumulative_lengths.push_back(total_length);
1263 }
1264
1265 OP_REQUIRES(
1266 ctx, TensorShapeUtils::IsVectorOrHigher(tensor_value->shape()),
1267 errors::InvalidArgument(
1268 "Expected value to be at least a vector, but received shape: ",
1269 tensor_value->shape().DebugString()));
1270
1271 OP_REQUIRES(
1272 ctx, total_length == tensor_value->shape().dim_size(0),
1273 errors::InvalidArgument("Expected sum of lengths to be equal to "
1274 "values.shape[0], but sum of lengths is ",
1275 total_length, " and value's shape is: ",
1276 tensor_value->shape().DebugString()));
1277 int64 elements_per_row =
1278 (total_length == 0) ? 0 : (tensor_value->NumElements() / total_length);
1279
1280 int32 array_size;
1281 OP_REQUIRES_OK(ctx, tensor_array->Size(&array_size));
1282 bool dynamic_size = tensor_array->HasDynamicSize();
1283
1284 std::vector<TensorShape> element_shapes(num_tensors, tensor_value->shape());
1285 for (int32 i = 0; i < num_tensors; ++i) {
1286 element_shapes[i].set_dim(0, tensor_lengths_t(i));
1287 }
1288
1289 // If dynamic size, we may have to resize the TensorArray to fit.
1290 if (dynamic_size && array_size < num_tensors) {
1291 array_size = num_tensors;

Callers

nothing calls this directly

Calls 15

SetupFlowControlInputsFunction · 0.85
GetTensorArrayFunction · 0.85
InvalidArgumentFunction · 0.85
FastBoundsCheckFunction · 0.85
HasDynamicSizeMethod · 0.80
SetMarkedSizeMethod · 0.80
maxFunction · 0.50
DataTypeStringFunction · 0.50
inputMethod · 0.45
shapeMethod · 0.45
DebugStringMethod · 0.45
NumElementsMethod · 0.45

Tested by

no test coverage detected