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

Method Compute

tensorflow/core/kernels/random_op.cc:97–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95 }
96
97 void Compute(OpKernelContext* ctx) override {
98 const Tensor& shape = ctx->input(0);
99 const Tensor& minval = ctx->input(1);
100 const Tensor& maxval = ctx->input(2);
101 OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(minval.shape()),
102 errors::InvalidArgument("minval must be 0-D, got shape ",
103 minval.shape().DebugString()));
104 OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(maxval.shape()),
105 errors::InvalidArgument("maxval must be 0-D, got shape ",
106 maxval.shape().DebugString()));
107
108 // Allocate output, and exit early if possible
109 Tensor* output;
110 OP_REQUIRES_OK(ctx, AllocateOutputWithShape(ctx, shape, 0, &output));
111 if (output->NumElements() == 0) return;
112
113 // Verify that minval < maxval. This check intentionally happens after the
114 // early exit for empty output. Zero impossible things are fine.
115 IntType lo = minval.scalar<IntType>()();
116 IntType hi = maxval.scalar<IntType>()();
117 OP_REQUIRES(
118 ctx, lo < hi,
119 errors::InvalidArgument("Need minval < maxval, got ", lo, " >= ", hi));
120
121 // Build distribution
122 typedef random::UniformDistribution<random::PhiloxRandom, IntType>
123 Distribution;
124 Distribution dist(lo, hi);
125
126 auto output_flat = output->flat<IntType>();
127 functor::FillPhiloxRandom<Device, Distribution>()(
128 ctx, ctx->eigen_device<Device>(),
129 // Multiplier 256 is the same as in FillPhiloxRandomTask; do not change
130 // it just here.
131 generator_.ReserveRandomOutputs(output_flat.size(), 256),
132 output_flat.data(), output_flat.size(), dist);
133 }
134
135 private:
136 GuardedPhiloxRandom generator_;

Callers

nothing calls this directly

Calls 10

InvalidArgumentFunction · 0.85
AllocateOutputWithShapeFunction · 0.85
ReserveRandomOutputsMethod · 0.80
IsScalarFunction · 0.50
inputMethod · 0.45
shapeMethod · 0.45
DebugStringMethod · 0.45
NumElementsMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected