Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc66881

Browse files
committed
minor fixes in auto_tuning.c
1 parentea3cf92 commitcc66881

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

‎auto_tuning.c‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ static bool is_in_infinite_loop_cq(double *elems, int nelems);
2222
double
2323
get_mean(double*elems,intnelems)
2424
{
25-
doublesum=0;
26-
inti;
25+
doublesum=0;
26+
inti;
27+
28+
AssertArg(nelems>0);
2729

2830
for (i=0;i<nelems;++i)
2931
sum+=elems[i];
@@ -37,7 +39,9 @@ get_mean(double *elems, int nelems)
3739
double
3840
get_estimation(double*elems,intnelems)
3941
{
40-
intstart;
42+
intstart;
43+
44+
AssertArg(nelems>0);
4145

4246
if (nelems>auto_tuning_window_size)
4347
start=nelems-auto_tuning_window_size;
@@ -53,11 +57,16 @@ get_estimation(double *elems, int nelems)
5357
bool
5458
is_stable(double*elems,intnelems)
5559
{
56-
doubleest;
60+
doubleest,
61+
last;
62+
63+
AssertArg(nelems>1);
5764

5865
est=get_mean(elems,nelems-1);
59-
return (est*1.1>elems[nelems-1]||est+0.1>elems[nelems-1])&&
60-
(est*0.9<elems[nelems-1]||est-0.1<elems[nelems-1]);
66+
last=elems[nelems-1];
67+
68+
return (est*1.1>last||est+0.1>last)&&
69+
(est*0.9<last||est-0.1<last);
6170
}
6271

6372
/*
@@ -89,7 +98,7 @@ is_in_infinite_loop_cq(double *elems, int nelems)
8998
return false;
9099

91100
return !converged_cq(elems,nelems)&&
92-
!converged_cq(elems,nelems-auto_tuning_window_size);
101+
!converged_cq(elems,nelems-auto_tuning_window_size);
93102
}
94103

95104
/*
@@ -142,16 +151,19 @@ automatical_query_tuning(int query_hash, QueryStat * stat)
142151
stat->execution_time_with_aqo_size)+
143152
get_estimation(stat->planning_time_with_aqo,
144153
stat->planning_time_with_aqo_size);
154+
145155
t_not_aqo=get_estimation(stat->execution_time_without_aqo,
146156
stat->execution_time_without_aqo_size)+
147157
get_estimation(stat->planning_time_without_aqo,
148158
stat->planning_time_without_aqo_size);
159+
149160
p_use=t_not_aqo / (t_not_aqo+t_aqo);
150161
p_use=1 / (1+exp((p_use-0.5) /unstability));
151162
p_use-=1 / (1+exp(-0.5 /unstability));
152163
p_use /=1-2 / (1+exp(-0.5 /unstability));
153164

154-
use_aqo= ((double)rand() /RAND_MAX<p_use);
165+
/* borrowed from drandom() in float.c */
166+
use_aqo= (random() / ((double)MAX_RANDOM_VALUE+1))<p_use;
155167
learn_aqo=use_aqo;
156168
}
157169

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp