File size: 104,182 Bytes
9375c9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - find_max_global.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2017 Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_FiND_GLOBAL_MAXIMUM_hH_
<font color='#0000FF'>#define</font> DLIB_FiND_GLOBAL_MAXIMUM_hH_
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='find_max_global_abstract.h.html'>find_max_global_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='global_function_search.h.html'>global_function_search.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../metaprogramming.h.html'>../metaprogramming.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>utility<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>chrono<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>memory<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>thread<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>functional<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../threads/thread_pool_extension.h.html'>../threads/thread_pool_extension.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../statistics/statistics.h.html'>../statistics/statistics.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../enable_if.h.html'>../enable_if.h</a>"
<font color='#0000FF'>namespace</font> dlib
<b>{</b>
<font color='#0000FF'>namespace</font> gopt_impl
<b>{</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>class</font> <b><a name='disable_decay_to_scalar'></a>disable_decay_to_scalar</b>
<b>{</b>
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a;
<font color='#0000FF'>public</font>:
<b><a name='disable_decay_to_scalar'></a>disable_decay_to_scalar</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> : a<font face='Lucida Console'>(</font>a<font face='Lucida Console'>)</font><b>{</b><b>}</b>
<b><a name='operator'></a>operator</b> <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> a;<b>}</b>
<b>}</b>;
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'><u>size_t</u></font>... indices<font color='#5555FF'>></font>
<font color='#0000FF'>auto</font> <b><a name='_cwv'></a>_cwv</b> <font face='Lucida Console'>(</font>
T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a,
compile_time_integer_list<font color='#5555FF'><</font>indices...<font color='#5555FF'>></font>
<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font>indices<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#0000FF'>sizeof</font>...<font face='Lucida Console'>(</font>indices<font face='Lucida Console'>)</font>,
"<font color='#CC0000'>You invoked dlib::call_function_and_expand_args(f,a) but the number of arguments expected by f() doesn't match the size of 'a'. </font>"
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>Expected </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> <font color='#0000FF'>sizeof</font>...<font face='Lucida Console'>(</font>indices<font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'> arguments but got </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>.</font>"
<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font>indices<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// Visual studio, as of November 2017, doesn't support C++11 and can't compile this code.
</font> <font color='#009900'>// So we write the terrible garbage in the #else for visual studio. When Visual Studio supports C++11 I'll update this #ifdef to use the C++11 code.
</font><font color='#0000FF'>#ifndef</font> _MSC_VER
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font> max_unpack<font color='#5555FF'>></font>
<font color='#0000FF'>struct</font> <b><a name='call_function_and_expand_args'></a>call_function_and_expand_args</b>
<b>{</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>_cwv</font><font face='Lucida Console'>(</font>std::forward<font color='#5555FF'><</font>T<font color='#5555FF'>></font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>,a,<font color='#0000FF'>typename</font> make_compile_time_integer_range<font color='#5555FF'><</font>max_unpack<font color='#5555FF'>></font>::<font color='#BB00BB'>type</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>_cwv</font><font face='Lucida Console'>(</font>std::forward<font color='#5555FF'><</font>T<font color='#5555FF'>></font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>,a,<font color='#0000FF'>typename</font> make_compile_time_integer_range<font color='#5555FF'><</font>max_unpack<font color='#5555FF'>></font>::<font color='#BB00BB'>type</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font>call_function_and_expand_args<font color='#5555FF'><</font>max_unpack<font color='#5555FF'>-</font><font color='#979000'>1</font><font color='#5555FF'>></font>::<font color='#0000FF'>template</font> <font color='#BB00BB'>go</font><font face='Lucida Console'>(</font>std::forward<font color='#5555FF'><</font>T<font color='#5555FF'>></font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>,a<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> call_function_and_expand_args<font color='#5555FF'><</font>max_unpack<font color='#5555FF'>-</font><font color='#979000'>1</font><font color='#5555FF'>></font>::<font color='#BB00BB'>go</font><font face='Lucida Console'>(</font>std::forward<font color='#5555FF'><</font>T<font color='#5555FF'>></font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>,a<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>;
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#5555FF'>></font>
<font color='#0000FF'>struct</font> <b><a name='call_function_and_expand_args'></a>call_function_and_expand_args</b><font color='#5555FF'><</font><font color='#979000'>0</font><font color='#5555FF'>></font>
<b>{</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>disable_decay_to_scalar</font><font face='Lucida Console'>(</font>a<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>disable_decay_to_scalar</font><font face='Lucida Console'>(</font>a<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>;
<font color='#0000FF'>#else</font>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font> max_unpack<font color='#5555FF'>></font>
<font color='#0000FF'>struct</font> <b><a name='call_function_and_expand_args'></a>call_function_and_expand_args</b>
<b>{</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>disable_decay_to_scalar</font><font face='Lucida Console'>(</font>a<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b><font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>disable_decay_to_scalar</font><font face='Lucida Console'>(</font>a<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>3</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>4</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>5</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>5</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>6</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>5</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> <font color='#0000FF'>static</font> <font color='#0000FF'>auto</font> <b><a name='go'></a>go</b><font face='Lucida Console'>(</font>T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f, <font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>, <font color='#979000'>0</font>, <font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font><font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>6</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>a.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>7</font><font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>a</font><font face='Lucida Console'>(</font><font color='#979000'>6</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
<b>}</b>;
<font color='#0000FF'>#endif</font>
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'>auto</font> <b><a name='call_function_and_expand_args'></a>call_function_and_expand_args</b><font face='Lucida Console'>(</font>
T<font color='#5555FF'>&</font><font color='#5555FF'>&</font> f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> a
<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>></font> <b><a name='decltype'></a>decltype</b><font face='Lucida Console'>(</font>gopt_impl::call_function_and_expand_args<font color='#5555FF'><</font><font color='#979000'>40</font><font color='#5555FF'>></font>::<font color='#BB00BB'>go</font><font face='Lucida Console'>(</font>f,a<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>// unpack up to 40 parameters when calling f()
</font> <font color='#0000FF'>return</font> gopt_impl::call_function_and_expand_args<font color='#5555FF'><</font><font color='#979000'>40</font><font color='#5555FF'>></font>::<font color='#BB00BB'>go</font><font face='Lucida Console'>(</font>std::forward<font color='#5555FF'><</font>T<font color='#5555FF'>></font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>,a<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>struct</font> <b><a name='max_function_calls'></a>max_function_calls</b>
<b>{</b>
<b><a name='max_function_calls'></a>max_function_calls</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>default</font>;
<font color='#0000FF'>explicit</font> <b><a name='max_function_calls'></a>max_function_calls</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> max_calls<font face='Lucida Console'>)</font> : max_calls<font face='Lucida Console'>(</font>max_calls<font face='Lucida Console'>)</font> <b>{</b><b>}</b>
<font color='#0000FF'><u>size_t</u></font> max_calls <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>></font>::<b><a name='max'></a>max</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
<b>}</b>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> FOREVER <font color='#5555FF'>=</font> std::chrono::<b><a name='hours'></a>hours</b><font face='Lucida Console'>(</font><font color='#979000'>24</font><font color='#5555FF'>*</font><font color='#979000'>365</font><font color='#5555FF'>*</font><font color='#979000'>290</font><font face='Lucida Console'>)</font>; <font color='#009900'>// 290 years
</font> <font color='#0000FF'>using</font> stop_condition <font color='#5555FF'>=</font> std::function<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>></font>;
<font color='#0000FF'>const</font> stop_condition never_stop_early <font color='#5555FF'>=</font> []<font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; <b>}</b>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>namespace</font> impl
<b>{</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> ymult,
thread_pool<font color='#5555FF'>&</font> tp,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
<font color='#0000FF'>const</font> max_function_calls num,
<font color='#0000FF'>const</font> std::chrono::nanoseconds max_runtime <font color='#5555FF'>=</font> FOREVER,
<font color='#0000FF'><u>double</u></font> solver_epsilon <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
std::vector<font color='#5555FF'><</font>std::vector<font color='#5555FF'><</font>function_evaluation<font color='#5555FF'>></font><font color='#5555FF'>></font> initial_function_evals <font color='#5555FF'>=</font> <b>{</b><b>}</b>,
stop_condition should_stop <font color='#5555FF'>=</font> never_stop_early
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>// Decide which parameters should be searched on a log scale. Basically, it's
</font> <font color='#009900'>// common for machine learning models to have parameters that should be searched on
</font> <font color='#009900'>// a log scale (e.g. SVM C). These parameters are usually identifiable because
</font> <font color='#009900'>// they have bounds like [1e-5 1e10], that is, they span a very large range of
</font> <font color='#009900'>// magnitudes from really small to really big. So there we are going to check for
</font> <font color='#009900'>// that and if we find parameters with that kind of bound constraints we will
</font> <font color='#009900'>// transform them to a log scale automatically.
</font> std::vector<font color='#5555FF'><</font>std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#BB00BB'>log_scale</font><font face='Lucida Console'>(</font>specs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> specs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> specs[i].lower.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>specs[i].is_integer_variable[j] <font color='#5555FF'>&</font><font color='#5555FF'>&</font> specs[i].<font color='#BB00BB'>lower</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>></font> <font color='#979000'>0</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> specs[i].<font color='#BB00BB'>upper</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>specs[i].<font color='#BB00BB'>lower</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>=</font> <font color='#979000'>1000</font><font face='Lucida Console'>)</font>
<b>{</b>
log_scale[i].<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font>;
specs[i].<font color='#BB00BB'>lower</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>log</font><font face='Lucida Console'>(</font>specs[i].<font color='#BB00BB'>lower</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
specs[i].<font color='#BB00BB'>upper</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>log</font><font face='Lucida Console'>(</font>specs[i].<font color='#BB00BB'>upper</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
log_scale[i].<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>initial_function_evals.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
initial_function_evals.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>specs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&</font> evals : initial_function_evals<font face='Lucida Console'>)</font> <b>{</b>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&</font> eval : evals<font face='Lucida Console'>)</font> <b>{</b>
eval.y <font color='#5555FF'>*</font><font color='#5555FF'>=</font> ymult;
<b>}</b>
<b>}</b>
global_function_search <font color='#BB00BB'>opt</font><font face='Lucida Console'>(</font>specs, <b>{</b>initial_function_evals<b>}</b><font face='Lucida Console'>)</font>;
opt.<font color='#BB00BB'>set_solver_epsilon</font><font face='Lucida Console'>(</font>solver_epsilon<font face='Lucida Console'>)</font>;
running_stats_decayed<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>objective_funct_eval_time</font><font face='Lucida Console'>(</font>functions.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>;
std::mutex eval_time_mutex;
<font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std::chrono;
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> time_to_stop <font color='#5555FF'>=</font> steady_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> max_runtime;
<font color='#009900'>//atomic<bool> doesn't support .fetch_or, use std::atomic<int> instead
</font> std::atomic<font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font><font color='#5555FF'>></font> this_should_stop<b>{</b><font color='#979000'>false</font><b>}</b>;
<font color='#0000FF'><u>double</u></font> max_solver_overhead_time <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#009900'>// Now run the main solver loop.
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> num.max_calls <font color='#5555FF'>&</font><font color='#5555FF'>&</font> steady_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> time_to_stop <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font color='#5555FF'>!</font>this_should_stop.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> get_next_x_start_time <font color='#5555FF'>=</font> steady_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>auto</font> next <font color='#5555FF'>=</font> std::make_shared<font color='#5555FF'><</font>function_evaluation_request<font color='#5555FF'>></font><font face='Lucida Console'>(</font>opt.<font color='#BB00BB'>get_next_x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> get_next_x_runtime <font color='#5555FF'>=</font> steady_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> get_next_x_start_time;
<font color='#0000FF'>auto</font> execute_call <font color='#5555FF'>=</font> [<font color='#5555FF'>&</font>functions,<font color='#5555FF'>&</font>ymult,<font color='#5555FF'>&</font>log_scale,<font color='#5555FF'>&</font>eval_time_mutex,<font color='#5555FF'>&</font>objective_funct_eval_time,next,<font color='#5555FF'>&</font>should_stop,<font color='#5555FF'>&</font>this_should_stop]<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b>{</b>
matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font> x <font color='#5555FF'>=</font> next<font color='#5555FF'>-</font><font color='#5555FF'>></font><font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
<font color='#009900'>// Undo any log-scaling that was applied to the variables before we pass them
</font> <font color='#009900'>// to the functions being optimized.
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>log_scale[next<font color='#5555FF'>-</font><font color='#5555FF'>></font><font color='#BB00BB'>function_idx</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>][j]<font face='Lucida Console'>)</font>
<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>exp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>x</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> funct_eval_start <font color='#5555FF'>=</font> steady_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'><u>double</u></font> y <font color='#5555FF'>=</font> ymult<font color='#5555FF'>*</font><font color='#BB00BB'>call_function_and_expand_args</font><font face='Lucida Console'>(</font>functions[next<font color='#5555FF'>-</font><font color='#5555FF'>></font><font color='#BB00BB'>function_idx</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>], x<font face='Lucida Console'>)</font>;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> funct_eval_runtime <font color='#5555FF'>=</font> duration_cast<font color='#5555FF'><</font>nanoseconds<font color='#5555FF'>></font><font face='Lucida Console'>(</font>steady_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> funct_eval_start<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
this_should_stop.<font color='#BB00BB'>fetch_or</font><font face='Lucida Console'>(</font><font color='#BB00BB'>should_stop</font><font face='Lucida Console'>(</font>y<font color='#5555FF'>*</font>ymult<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
next<font color='#5555FF'>-</font><font color='#5555FF'>></font><font color='#BB00BB'>set</font><font face='Lucida Console'>(</font>y<font face='Lucida Console'>)</font>;
std::lock_guard<font color='#5555FF'><</font>std::mutex<font color='#5555FF'>></font> <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>eval_time_mutex<font face='Lucida Console'>)</font>;
objective_funct_eval_time.<font color='#BB00BB'>add</font><font face='Lucida Console'>(</font>funct_eval_runtime<font face='Lucida Console'>)</font>;
<b>}</b>;
tp.<font color='#BB00BB'>add_task_by_value</font><font face='Lucida Console'>(</font>execute_call<font face='Lucida Console'>)</font>;
std::lock_guard<font color='#5555FF'><</font>std::mutex<font color='#5555FF'>></font> <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>eval_time_mutex<font face='Lucida Console'>)</font>;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> obj_funct_time <font color='#5555FF'>=</font> objective_funct_eval_time.<font color='#BB00BB'>mean</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>ul,tp.<font color='#BB00BB'>num_threads_in_pool</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> solver_overhead_time <font color='#5555FF'>=</font> duration_cast<font color='#5555FF'><</font>nanoseconds<font color='#5555FF'>></font><font face='Lucida Console'>(</font>get_next_x_runtime<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
max_solver_overhead_time <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>max_solver_overhead_time, solver_overhead_time<font face='Lucida Console'>)</font>;
<font color='#009900'>// Don't start thinking about the logic below until we have at least 5 objective
</font> <font color='#009900'>// function samples for each objective function. This way we have a decent idea how
</font> <font color='#009900'>// fast these things are. The solver overhead is really small initially so none of
</font> <font color='#009900'>// the stuff below really matters in the beginning anyway.
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>objective_funct_eval_time.<font color='#BB00BB'>current_n</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> functions.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>5</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>// If calling opt.get_next_x() is taking a long time relative to how long it takes
</font> <font color='#009900'>// to evaluate the objective function then we should spend less time grinding on the
</font> <font color='#009900'>// internal details of the optimizer and more time running the actual objective
</font> <font color='#009900'>// function. E.g. if we could just run 2x more objective function calls in the same
</font> <font color='#009900'>// amount of time then we should just do that. The main slowness in the solver is
</font> <font color='#009900'>// from the Monte Carlo sampling, which we can turn down if the objective function
</font> <font color='#009900'>// is really fast to evaluate. This is because the point of the Monte Carlo part is
</font> <font color='#009900'>// to try really hard to avoid calls to really expensive objective functions. But
</font> <font color='#009900'>// if the objective function is not expensive then we should just call it.
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>obj_funct_time <font color='#5555FF'><</font> solver_overhead_time<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>// Reduce the amount of Monte Carlo sampling we do. If it goes low enough
</font> <font color='#009900'>// we will disable it altogether.
</font> <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> new_val <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>opt.<font color='#BB00BB'>get_monte_carlo_upper_bound_sample_num</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.8</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
opt.<font color='#BB00BB'>set_monte_carlo_upper_bound_sample_num</font><font face='Lucida Console'>(</font>std::max<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, new_val<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#009900'>// At this point just disable the upper bounding Monte Carlo search stuff and
</font> <font color='#009900'>// use only pure random search since the objective function is super cheap to
</font> <font color='#009900'>// evaluate, making this more fancy search a waste of time.
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>opt.<font color='#BB00BB'>get_monte_carlo_upper_bound_sample_num</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
<b>{</b>
opt.<font color='#BB00BB'>set_pure_random_search_probability</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>obj_funct_time <font color='#5555FF'>></font> <font color='#979000'>1.5</font><font color='#5555FF'>*</font>max_solver_overhead_time<font face='Lucida Console'>)</font> <font color='#009900'>// Consider reenabling
</font> <b>{</b>
<font color='#009900'>// The Monte Carlo overhead grows over time as the solver accumulates more
</font> <font color='#009900'>// information about the objective function. So we only want to reenable it
</font> <font color='#009900'>// or make it bigger if the objective function really is more expensive. So
</font> <font color='#009900'>// we compare to the max solver runtime we have seen so far. If the
</font> <font color='#009900'>// objective function has suddenly gotten more expensive then we start to
</font> <font color='#009900'>// turn the Monte Carlo modeling back on.
</font> <font color='#0000FF'>const</font> <font color='#0000FF'><u>size_t</u></font> new_val <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font>opt.<font color='#BB00BB'>get_monte_carlo_upper_bound_sample_num</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>1.28</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
opt.<font color='#BB00BB'>set_monte_carlo_upper_bound_sample_num</font><font face='Lucida Console'>(</font>std::min<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><font color='#979000'>5000</font>, new_val<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#009900'>// Set this back to its default value.
</font> opt.<font color='#BB00BB'>set_pure_random_search_probability</font><font face='Lucida Console'>(</font><font color='#979000'>0.02</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<b>}</b>
tp.<font color='#BB00BB'>wait_for_all_tasks</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font> x;
<font color='#0000FF'><u>double</u></font> y;
<font color='#0000FF'><u>size_t</u></font> function_idx;
opt.<font color='#BB00BB'>get_best_function_eval</font><font face='Lucida Console'>(</font>x,y,function_idx<font face='Lucida Console'>)</font>;
<font color='#009900'>// Undo any log-scaling that was applied to the variables before we output them.
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> x.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>log_scale[function_idx][j]<font face='Lucida Console'>)</font>
<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> std::<font color='#BB00BB'>exp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>x</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>return</font> std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>function_idx, <font color='#BB00BB'>function_evaluation</font><font face='Lucida Console'>(</font>x,y<font color='#5555FF'>/</font>ymult<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// This overload allows the order of max_runtime and num to be reversed.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> ymult,
thread_pool<font color='#5555FF'>&</font> tp,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
<font color='#0000FF'>const</font> std::chrono::nanoseconds max_runtime,
<font color='#0000FF'>const</font> max_function_calls num,
<font color='#0000FF'><u>double</u></font> solver_epsilon <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>ymult, tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, num, max_runtime, solver_epsilon, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// This overload allows the num argument to be skipped.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> ymult,
thread_pool<font color='#5555FF'>&</font> tp,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
<font color='#0000FF'>const</font> std::chrono::nanoseconds max_runtime,
<font color='#0000FF'><u>double</u></font> solver_epsilon <font color='#5555FF'>=</font> <font color='#979000'>0</font>,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>ymult, tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, <font color='#BB00BB'>max_function_calls</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_runtime, solver_epsilon, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// This overload allows the max_runtime argument to be skipped.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> ymult,
thread_pool<font color='#5555FF'>&</font> tp,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
<font color='#0000FF'>const</font> max_function_calls num,
<font color='#0000FF'><u>double</u></font> solver_epsilon,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>ymult, tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, num, FOREVER, solver_epsilon, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// This overload makes the thread_pool argument optional.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> ymult,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>// disabled, don't use any threads
</font> thread_pool <font color='#BB00BB'>tp</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>ymult, tp, functions, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// The point of normalize() is to handle some of the overloaded argument types in
</font> <font color='#009900'>// find_max_global() instances below and turn them into the argument types expected by
</font> <font color='#009900'>// find_max_global() above.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> <b><a name='normalize'></a>normalize</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> item<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> item;
<b>}</b>
<font color='#0000FF'>inline</font> std::vector<font color='#5555FF'><</font>std::vector<font color='#5555FF'><</font>function_evaluation<font color='#5555FF'>></font><font color='#5555FF'>></font> <b><a name='normalize'></a>normalize</b><font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font>function_evaluation<font color='#5555FF'>></font><font color='#5555FF'>&</font> initial_function_evals
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <b>{</b>initial_function_evals<b>}</b>;
<b>}</b>
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> impl::<font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> impl::<font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> impl::<font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
std::pair<font color='#5555FF'><</font><font color='#0000FF'><u>size_t</u></font>,function_evaluation<font color='#5555FF'>></font> <b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font><font color='#5555FF'>&</font> functions,
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> specs,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> impl::<font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, std::forward<font color='#5555FF'><</font>Args<font color='#5555FF'>></font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#009900'>// Overloads that take function objects and simple matrix bounds instead of function_specs.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>&</font> is_integer_variable,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font> <font color='#BB00BB'>functions</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> <font color='#BB00BB'>specs</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, <font color='#BB00BB'>function_spec</font><font face='Lucida Console'>(</font>bound1, bound2, is_integer_variable<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>.second;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>&</font> is_integer_variable,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font> <font color='#BB00BB'>functions</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> <font color='#BB00BB'>specs</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, <font color='#BB00BB'>function_spec</font><font face='Lucida Console'>(</font>bound1, bound2, is_integer_variable<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_min_global</font><font face='Lucida Console'>(</font>functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>.second;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>&</font> is_integer_variable,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font> <font color='#BB00BB'>functions</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> <font color='#BB00BB'>specs</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, <font color='#BB00BB'>function_spec</font><font face='Lucida Console'>(</font>bound1, bound2, is_integer_variable<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>.second;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>&</font> is_integer_variable,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
std::vector<font color='#5555FF'><</font>funct<font color='#5555FF'>></font> <font color='#BB00BB'>functions</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
std::vector<font color='#5555FF'><</font>function_spec<font color='#5555FF'>></font> <font color='#BB00BB'>specs</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, <font color='#BB00BB'>function_spec</font><font face='Lucida Console'>(</font>bound1, bound2, is_integer_variable<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_min_global</font><font face='Lucida Console'>(</font>tp, functions, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>specs<font face='Lucida Console'>)</font>, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>.second;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#009900'>// overloads that are the same as above, but is_integer_variable defaulted to false for all parameters.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
<font color='#0000FF'>typename</font> disable_if<font color='#5555FF'><</font>std::is_same<font color='#5555FF'><</font>T,std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>></font>, function_evaluation<font color='#5555FF'>></font>::type
<b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>is_integer_variable</font><font face='Lucida Console'>(</font>bound1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>false</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, bound1, bound2, is_integer_variable, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
<font color='#0000FF'>typename</font> disable_if<font color='#5555FF'><</font>std::is_same<font color='#5555FF'><</font>T,std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>></font>, function_evaluation<font color='#5555FF'>></font>::type
<b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>is_integer_variable</font><font face='Lucida Console'>(</font>bound1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>false</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_min_global</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, bound1, bound2, is_integer_variable, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
<font color='#0000FF'>typename</font> disable_if<font color='#5555FF'><</font>std::is_same<font color='#5555FF'><</font>T,std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>></font>, function_evaluation<font color='#5555FF'>></font>::type
<b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>is_integer_variable</font><font face='Lucida Console'>(</font>bound1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>false</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>tp, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, bound1, bound2, is_integer_variable, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
<font color='#0000FF'>typename</font> disable_if<font color='#5555FF'><</font>std::is_same<font color='#5555FF'><</font>T,std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font><font color='#5555FF'>></font>, function_evaluation<font color='#5555FF'>></font>::type
<b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
funct f,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound1,
<font color='#0000FF'>const</font> matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>bool</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>is_integer_variable</font><font face='Lucida Console'>(</font>bound1.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>false</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_min_global</font><font face='Lucida Console'>(</font>tp, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, bound1, bound2, is_integer_variable, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#009900'>// overloads for a function taking a single scalar.
</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
funct f,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound1,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound1<b>}</b><font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound2<b>}</b><font face='Lucida Console'>)</font>, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
funct f,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound1,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_min_global</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound1<b>}</b><font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound2<b>}</b><font face='Lucida Console'>)</font>, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_max_global'></a>find_max_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
funct f,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound1,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_max_global</font><font face='Lucida Console'>(</font>tp, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound1<b>}</b><font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound2<b>}</b><font face='Lucida Console'>)</font>, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> funct,
<font color='#0000FF'>typename</font> T,
<font color='#0000FF'>typename</font> ...Args
<font color='#5555FF'>></font>
function_evaluation <b><a name='find_min_global'></a>find_min_global</b> <font face='Lucida Console'>(</font>
thread_pool<font color='#5555FF'>&</font> tp,
funct f,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound1,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> bound2,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> arg,
Args<font color='#5555FF'>&</font><font color='#5555FF'>&</font> ...args
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>find_min_global</font><font face='Lucida Console'>(</font>tp, std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound1<b>}</b><font face='Lucida Console'>)</font>, matrix<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>></font><font face='Lucida Console'>(</font><b>{</b>bound2<b>}</b><font face='Lucida Console'>)</font>, arg, impl::<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font>args<font face='Lucida Console'>)</font>...<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_FiND_GLOBAL_MAXIMUM_hH_
</font>
</pre></body></html> |