@@ -36,21 +36,22 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel {
36
36
auto x_dims = ctx->GetInputDim (" X" );
37
37
auto y_dims = ctx->GetInputDim (" Y" );
38
38
39
- PADDLE_ENFORCE_EQ (
40
- framework::arity (x_dims), framework::arity (y_dims),
41
- platform::errors::InvalidArgument (
42
- " Input(X) and Input(X) of SquaredL2DistanceOp should " ,
43
- " have same dimensions. " ,
44
- " But received X's shape = [%s] and Y's shape = [%s], " ,
45
- " the dimensions are %d and %d respectively " , x_dims, y_dims,
46
- framework::arity (x_dims), framework::arity (y_dims)));
39
+ PADDLE_ENFORCE_EQ (framework::arity (x_dims), framework::arity (y_dims),
40
+ platform::errors::InvalidArgument (
41
+ " Input(X) and Input(X) of SquaredL2DistanceOp should "
42
+ " have same dimensions. "
43
+ " But received X's shape = [%s] and Y's shape = [%s], "
44
+ " the dimensions are %d and %d respectively " ,
45
+ x_dims, y_dims, framework::arity (x_dims) ,
46
+ framework::arity (y_dims)));
47
47
48
48
int rank = framework::arity (x_dims);
49
49
PADDLE_ENFORCE_GE (
50
50
rank, 2 ,
51
51
platform::errors::InvalidArgument (
52
- " Input dimensions of SquaredL2DistanceOp should be " , " at least 2." ,
53
- " But received shape = [%s] and dimension is %d." , x_dims, rank));
52
+ " Input dimensions of SquaredL2DistanceOp should be at least 2."
53
+ " But received shape = [%s] and dimension is %d." ,
54
+ x_dims, rank));
54
55
bool check = true ;
55
56
if ((!ctx->IsRuntime ()) &&
56
57
(framework::product (x_dims) <= 0 || framework::product (y_dims) <= 0 )) {
@@ -60,11 +61,12 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel {
60
61
PADDLE_ENFORCE_EQ (
61
62
product (x_dims) / x_dims[0 ], product (y_dims) / y_dims[0 ],
62
63
platform::errors::InvalidArgument (
63
- " Input(X) and Input(Y) of SquaredL2DistanceOp should " ,
64
- " have same dimensions." ,
65
- " But received X's shape = [%s] and Y's shape = [%s]" ,
66
- " , the products are %d and %d respectively" , x_dims, y_dims,
67
- product (x_dims) / x_dims[0 ], product (y_dims) / y_dims[0 ]));
64
+ " Input(X) and Input(Y) of SquaredL2DistanceOp should "
65
+ " have same dimensions."
66
+ " But received X's shape = [%s] and Y's shape = [%s]"
67
+ " , the products are %d and %d respectively" ,
68
+ x_dims, y_dims, product (x_dims) / x_dims[0 ],
69
+ product (y_dims) / y_dims[0 ]));
68
70
}
69
71
check = true ;
70
72
if ((!ctx->IsRuntime ()) && (y_dims[0 ] <= 0 || x_dims[0 ] <= 0 )) {
@@ -74,11 +76,11 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel {
74
76
PADDLE_ENFORCE_EQ (
75
77
y_dims[0 ] == 1 || y_dims[0 ] == x_dims[0 ], true ,
76
78
platform::errors::InvalidArgument (
77
- " First dimension of Input(Y) of SquaredL2DistanceOp " ,
78
- " must be equal to 1" , " or to first dimension of Input(X)." ,
79
- " But received X's shape = [%s] and Y's shape = [%s]," ,
80
- " the first dimensions are %d and %d respectively" , x_dims, y_dims,
81
- x_dims[0 ], y_dims[0 ]));
79
+ " First dimension of Input(Y) of SquaredL2DistanceOp "
80
+ " must be equal to 1 or to first dimension of Input(X)."
81
+ " But received X's shape = [%s] and Y's shape = [%s],"
82
+ " the first dimensions are %d and %d respectively" ,
83
+ x_dims, y_dims, x_dims [0 ], y_dims[0 ]));
82
84
}
83
85
ctx->SetOutputDim (" sub_result" , {x_dims[0 ], product (x_dims) / x_dims[0 ]});
84
86
ctx->SetOutputDim (" Out" , {x_dims[0 ], 1 });
@@ -152,17 +154,18 @@ class SquaredL2DistanceGradOp : public framework::OperatorWithKernel {
152
154
PADDLE_ENFORCE_EQ (
153
155
out_dims[0 ], x_dims[0 ],
154
156
platform::errors::InvalidArgument (
155
- " First dimension of output gradient and Input(X) " ,
156
- " of SquaredL2DistanceGradOp must be equal" ,
157
- " But received X's shape = [%s] and grad's shape = [%s]," ,
158
- " the first dimensions are %d and %d respectively" , x_dims,
159
- out_dims, x_dims[0 ], out_dims[0 ]));
157
+ " First dimension of output gradient and Input(X) "
158
+ " of SquaredL2DistanceGradOp must be equal "
159
+ " But received X's shape = [%s] and grad's shape = [%s], "
160
+ " the first dimensions are %d and %d respectively" ,
161
+ x_dims, out_dims, x_dims[0 ], out_dims[0 ]));
160
162
PADDLE_ENFORCE_EQ (out_dims[1 ], 1 ,
161
163
platform::errors::InvalidArgument (
162
- " Second dimension of output gradient of " ,
163
- " SquaredL2DistanceGradOp must be 1."
164
- " But received grad's shape = [%s]," ,
165
- " with first dimensions %d" , out_dims, out_dims[1 ]));
164
+ " Second dimension of output gradient of "
165
+ " SquaredL2DistanceGradOp must be 1. "
166
+ " But received grad's shape = [%s], "
167
+ " with second dimension %d" ,
168
+ out_dims, out_dims[1 ]));
166
169
}
167
170
auto x_grad_name = framework::GradVarName (" X" );
168
171
auto y_grad_name = framework::GradVarName (" Y" );
0 commit comments