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

Method Compute

tensorflow/core/kernels/shape_ops.h:117–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115 explicit SizeOp(OpKernelConstruction* ctx) : OpKernel(ctx) {}
116
117 void Compute(OpKernelContext* ctx) override {
118 TensorShape shape;
119 OP_REQUIRES_OK(ctx, shape_op_helpers::GetShape(ctx, 0, &shape));
120 const int64 size = shape.num_elements();
121 Tensor* out = nullptr;
122 OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({}), &out));
123 if (out->dtype() == DT_INT32) {
124 OP_REQUIRES(
125 ctx, FastBoundsCheck(size, std::numeric_limits<int32>::max()),
126 errors::InvalidArgument("Number of elements was larger than "
127 "representable by 32-bit output type"));
128 }
129 out->scalar<OutType>()() = static_cast<OutType>(size);
130 }
131
132 bool IsExpensive() override { return false; }
133};

Callers

nothing calls this directly

Calls 8

FastBoundsCheckFunction · 0.85
InvalidArgumentFunction · 0.85
allocate_outputMethod · 0.80
GetShapeFunction · 0.70
TensorShapeClass · 0.50
maxFunction · 0.50
num_elementsMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected