|
|
|
@ -75,7 +75,11 @@ class CPUUniformRandomKernel : public framework::OpKernel<T> {
|
|
|
|
|
auto diag_val = static_cast<T>(ctx.Attr<float>("diag_val"));
|
|
|
|
|
if (diag_num > 0) {
|
|
|
|
|
PADDLE_ENFORCE_GT(size, (diag_num - 1) * (diag_step + 1),
|
|
|
|
|
"The index of diagonal elements is out of bounds");
|
|
|
|
|
"ShapeError: the diagonal's elements is equal (num-1) "
|
|
|
|
|
"* (step-1) with num %d, step %d,"
|
|
|
|
|
"It should be smaller than %d, but received %d",
|
|
|
|
|
diag_num, diag_step, (diag_num - 1) * (diag_step + 1),
|
|
|
|
|
size);
|
|
|
|
|
for (int64_t i = 0; i < diag_num; ++i) {
|
|
|
|
|
int64_t pos = i * diag_step + i;
|
|
|
|
|
data[pos] = diag_val;
|
|
|
|
@ -118,9 +122,10 @@ class UniformRandomOp : public framework::OperatorWithKernel {
|
|
|
|
|
auto shape_dims = ctx->GetInputDim("ShapeTensor");
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
shape_dims.size(), 1,
|
|
|
|
|
"Input(ShapeTensor)' dimension size of Op(uniform_random) must be 1."
|
|
|
|
|
"Please check the Attr(shape)'s dimension size of"
|
|
|
|
|
"Op(fluid.layers.uniform_random).)");
|
|
|
|
|
"ShapeError: Input(ShapeTensor)' dimension size of "
|
|
|
|
|
"Op(uniform_random) must be 1."
|
|
|
|
|
"But received ShapeTensor's dimensions = %d, shape = [%s]",
|
|
|
|
|
shape_dims.size(), shape_dims);
|
|
|
|
|
int num_ele = 1;
|
|
|
|
|
for (int i = 0; i < shape_dims.size(); ++i) {
|
|
|
|
|
num_ele *= shape_dims[i];
|
|
|
|
|