File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
paddle/fluid/operators/math Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ struct CosSimFunctor {
35
35
inline HOSTDEVICE void operator ()(size_t row_id) const {
36
36
auto * x = x_ + cols_ * row_id;
37
37
T xx = 0 , xy = 0 , yy = 0 ;
38
+ T eps = 1e-8 ;
38
39
if (same_row) {
39
40
auto * y = y_ + cols_ * row_id;
40
41
T tep_x, tep_y;
@@ -45,6 +46,8 @@ struct CosSimFunctor {
45
46
yy += tep_y * tep_y;
46
47
xy += tep_x * tep_y;
47
48
}
49
+ xx = xx > eps ? xx : eps;
50
+ yy = yy > eps ? yy : eps;
48
51
xx = sqrt (xx);
49
52
yy = sqrt (yy);
50
53
y_norm_[row_id] = yy;
@@ -59,6 +62,8 @@ struct CosSimFunctor {
59
62
yy += tep_y * tep_y;
60
63
xy += tep_x * tep_y;
61
64
}
65
+ xx = xx > eps ? xx : eps;
66
+ yy = yy > eps ? yy : eps;
62
67
xx = sqrt (xx);
63
68
yy = sqrt (yy);
64
69
if (row_id == 0 ) y_norm_[0 ] = yy;
You can’t perform that action at this time.
0 commit comments