You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

394 lines
13 KiB

  1. # Copyright (C) 2001-2015 Yves Renard
  2. #
  3. # This file is a part of GETFEM++
  4. #
  5. # Getfem++ is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU Lesser General Public License as published
  7. # by the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version along with the GCC Runtime Library
  9. # Exception either version 3.1 or (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. # License and GCC Runtime Library Exception for more details.
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  17. eval 'exec perl -S $0 "$@"'
  18. if 0;
  19. sub numerique { $a <=> $b; }
  20. $nb_iter = 1; # number of iterations on each test
  21. $islocal = 0;
  22. $with_qd = 0; # test also with dd_real and qd_real
  23. $with_lapack = 0; # link with lapack
  24. $srcdir = $ENV{srcdir}; # source directory
  25. $tests_to_be_done = "";
  26. $fix_base_type = -1;
  27. while(@ARGV) { # read optional parameters
  28. $param = $ARGV[0];
  29. $val = int(1 * $param);
  30. if ($param =~ /.cc/) {
  31. $tests_to_be_done = $param;
  32. }
  33. elsif ($param eq "with-qd") {
  34. $with_qd = 1;
  35. }
  36. elsif ($param eq "with-lapack") {
  37. $with_lapack = 1;
  38. }
  39. elsif ($param eq "float") {
  40. $fix_base_type = 0;
  41. }
  42. elsif ($param eq "double") {
  43. $fix_base_type = 1;
  44. }
  45. elsif ($param eq "complex_float") {
  46. $fix_base_type = 2;
  47. }
  48. elsif ($param eq "complex_double") {
  49. $fix_base_type = 3;
  50. }
  51. elsif ($param eq "dd_real") {
  52. $fix_base_type = 0; $with_qd = 1;
  53. }
  54. elsif ($param eq "qd_real") {
  55. $fix_base_type = 1; $with_qd = 1;
  56. }
  57. elsif ($param eq "complex_dd_real") {
  58. $fix_base_type = 2; $with_qd = 1;
  59. }
  60. elsif ($param eq "complex_qd_real") {
  61. $fix_base_type = 3; $with_qd = 1;
  62. }
  63. elsif ($param =~ "srcdir=") {
  64. ($param, $srcdir)=split('=', $param, 2);
  65. }
  66. elsif ($val != 0) {
  67. $nb_iter = $val;
  68. }
  69. else {
  70. print "Unrecognized parameter: $param\n";
  71. print "valid parameters are:\n";
  72. print ". the number of iterations on each test\n";
  73. print ". with-qd : test also with dd_real and qd_real\n";
  74. print ". with-lapack : link with lapack\n";
  75. print ". double, float, complex_double or complex_float";
  76. print " to fix the base type\n";
  77. print ". source name of a test procedure\n";
  78. print ". srcdir=name\n";
  79. exit(1);
  80. }
  81. shift @ARGV;
  82. }
  83. if ($srcdir eq "") {
  84. $srcdir="../../tests";
  85. print "WARNING : no srcdir, taking $srcdir\n";
  86. $islocal = 1;
  87. }
  88. if ($tests_to_be_done eq "") {
  89. $tests_to_be_done = `ls $srcdir/gmm_torture*.cc`; # list of tests
  90. }
  91. if ($with_qd && $with_lapack) {
  92. print "Options with_qd and with_lapack are not compatible\n";
  93. exit(1);
  94. }
  95. $nb_test = 0; # number of test procedures
  96. $tests_list = $tests_to_be_done;
  97. while ($tests_list)
  98. { ($org_name, $tests_list) = split('\s', $tests_list, 2); ++$nb_test; }
  99. print "Gmm tests : Making $nb_iter execution";
  100. if ($nb_iter > 1) { print "s"; }
  101. if ($nb_test == 1) { print " of $tests_to_be_done\n"; }
  102. else { print " of each test\n"; }
  103. for ($iter = 1; $iter <= $nb_iter; ++$iter) {
  104. $tests_list = $tests_to_be_done;
  105. while ($tests_list) {
  106. ($org_name, $tests_list) = split('\s', $tests_list, 2);
  107. if ($nb_iter == 1) { print "Testing $org_name"; }
  108. else { print "Test $iter for $org_name"; }
  109. if ($with_lapack) { print " linked with lapack"; }
  110. if ($with_qd) { print " with qd types"; }
  111. print "\n";
  112. $d = $org_name;
  113. do { ($b, $d) = split('/', $d, 2); } while ($d);
  114. $dest_name = "auto_$b";
  115. ($root_name, $d) = split('.cc', $dest_name, 2);
  116. $size_max = 30.0;
  117. open(DATAF, $org_name) or die "Open input file impossible : $!\n";
  118. open(TMPF, ">$dest_name") or die "Open output file impossible : $!\n";
  119. print TMPF "\n\n";
  120. if ($with_lapack) {
  121. print TMPF "#include<gmm_lapack_interface.h>\n\n";
  122. }
  123. if ($with_qd) {
  124. print TMPF "#include <qd/dd.h>\n";
  125. print TMPF "#include <qd/qd.h>\n";
  126. print TMPF "#include <qd/fpu.h>\n\n";
  127. }
  128. $reading_param = 1;
  129. $nb_param = 0;
  130. while (($li = <DATAF> )&& ($reading_param)) {
  131. chomp($li);
  132. if ($li=~/^\/\//) {
  133. if ($li=~/ENDPARAM/) { $reading_param = 0; }
  134. elsif ($li=~/DENSE_VECTOR_PARAM/) { $param[$nb_param++] = 1; }
  135. elsif ($li=~/VECTOR_PARAM/) { $param[$nb_param++] = 2; }
  136. elsif ($li=~/RECTANGULAR_MATRIX_PARAM/) { $param[$nb_param++] = 3; }
  137. elsif ($li=~/SQUARED_MATRIX_PARAM/) { $param[$nb_param++] = 4; }
  138. elsif ($li=~/\/\//) { }
  139. else { die "Error in parameter list"; }
  140. }
  141. }
  142. $TYPES[0] = "float";
  143. $TYPES[1] = "std::complex<float> ";
  144. $TYPES[2] = "double";
  145. $TYPES[3] = "std::complex<double> ";
  146. # $TYPES[4] = "long double";
  147. # $TYPES[5] = "std::complex<long double> ";
  148. $NB_TYPES = 4.0;
  149. if ($with_lapack) {
  150. $NB_TYPES = 4.0;
  151. }
  152. if ($with_qd) {
  153. $TYPES[0] = "dd_real";
  154. $TYPES[1] = "qd_real";
  155. $TYPES[2] = "std::complex<dd_real> ";
  156. $TYPES[3] = "std::complex<qd_real> ";
  157. $NB_TYPES = 4.0;
  158. }
  159. if ($fix_base_type == -1) { $TYPE = $TYPES[int($NB_TYPES * rand())]; }
  160. else { $TYPE = $TYPES[$fix_base_type]; }
  161. $VECTOR_TYPES[0] = "std::vector<$TYPE> ";
  162. $VECTOR_TYPES[1] = "std::vector<$TYPE> ";
  163. $VECTOR_TYPES[2] = "gmm::rsvector<$TYPE> ";
  164. $VECTOR_TYPES[3] = "gmm::wsvector<$TYPE> ";
  165. $VECTOR_TYPES[4] = "gmm::slvector<$TYPE> ";
  166. $NB_VECTOR_TYPES = 5.0;
  167. $MATRIX_TYPES[0] = "gmm::dense_matrix<$TYPE> ";
  168. $MATRIX_TYPES[1] = "gmm::dense_matrix<$TYPE> ";
  169. $MATRIX_TYPES[2] = "gmm::row_matrix<std::vector<$TYPE> > ";
  170. $MATRIX_TYPES[3] = "gmm::col_matrix<std::vector<$TYPE> > ";
  171. $MATRIX_TYPES[4] = "gmm::row_matrix<gmm::rsvector<$TYPE> > ";
  172. $MATRIX_TYPES[5] = "gmm::col_matrix<gmm::rsvector<$TYPE> > ";
  173. $MATRIX_TYPES[6] = "gmm::row_matrix<gmm::wsvector<$TYPE> > ";
  174. $MATRIX_TYPES[7] = "gmm::col_matrix<gmm::wsvector<$TYPE> > ";
  175. $MATRIX_TYPES[8] = "gmm::row_matrix<gmm::slvector<$TYPE> > ";
  176. $MATRIX_TYPES[9] = "gmm::col_matrix<gmm::slvector<$TYPE> > ";
  177. $NB_MATRIX_TYPES = 10.0;
  178. while ($li = <DATAF>) { print TMPF $li; }
  179. $sizep = int($size_max*rand());
  180. $theseed = int(10000.0*rand());
  181. # print "Parameters for the test:\n";
  182. print TMPF "\n\n\n";
  183. print TMPF "int main(void) {\n\n";
  184. if ($with_qd) {
  185. print TMPF " fpu_fix_start(0);\n\n";
  186. }
  187. print TMPF " srand($theseed);\n\n";
  188. print TMPF " gmm::set_warning_level(1);\n\n";
  189. print TMPF " for (int iter = 0; iter < 100000; ++iter) {\n\n";
  190. print TMPF " try {\n\n";
  191. for ($j = 0; $j < $nb_param; ++$j) {
  192. $a = rand(); $b = rand();
  193. if ($with_lapack) { $a = $b = 1.0; }
  194. $sizepp = $sizep + int(50.0*rand());
  195. $step = $sizep; if ($step == 0) { ++$step; }
  196. $step = int(1.0*int($sizepp/$step - 1)*rand()) + 1;
  197. if (($param[$j] == 1) || ($param[$j] == 2)) { # vectors
  198. $lt = $VECTOR_TYPES[0];
  199. if ($param[$j] == 2 && $with_lapack==0) {
  200. $lt = $VECTOR_TYPES[int($NB_VECTOR_TYPES * rand())];
  201. }
  202. if ($a < 0.1) {
  203. $li = " $lt param$j($sizepp);";
  204. $c = int(1.0*($sizepp-$sizep+1)*rand());
  205. $param_name[$j]
  206. = "gmm::sub_vector(param$j, gmm::sub_interval($c, $sizep))";
  207. }
  208. elsif ($a < 0.2) {
  209. $li = " $lt param$j($sizepp);";
  210. $c = int(1.0*($sizepp-($sizep*$step+1))*rand());
  211. $param_name[$j]
  212. = "gmm::sub_vector(param$j, gmm::sub_slice($c, $sizep, $step))";
  213. }
  214. elsif ($a < 0.3) {
  215. $li = " $lt param$j($sizepp);"; @sub_index = ();
  216. @sortind = 0 .. ($sizepp-1);
  217. while (@sortind)
  218. { push (@sub_index, splice(@sortind , rand @sortind, 1)); }
  219. @sub_index = @sub_index[0..$sizep-1];
  220. @sub_index = sort numerique @sub_index;
  221. if ($sizep == 0)
  222. { $li = "$li\n gmm::size_type param_tab$j [1] = {0};"; }
  223. else {
  224. $li="$li\n gmm::size_type param_tab$j [$sizep] ={$sub_index[0]";
  225. for ($k = 1; $k < $sizep; ++$k) { $li = "$li , $sub_index[$k]"; }
  226. $li = "$li};";
  227. }
  228. $param_name[$j] = "gmm::sub_vector(param$j,".
  229. " gmm::sub_index(&param_tab$j [0], &param_tab$j [$sizep]))";
  230. }
  231. else {
  232. $li = " $lt param$j($sizep);";
  233. $param_name[$j] = "param$j";
  234. }
  235. print TMPF "$li\n gmm::fill_random(param$j);\n";
  236. }
  237. elsif ($param[$j] == 3 || $param[$j] == 4) { # matrices
  238. $sm = $sizep; if ($a < 0.3) { $sm = $sizep + int(50.0*rand()); }
  239. $s = $sizep; if ($param[$j] == 3) { $s = int($size_max*rand()); }
  240. $sn = $s; if ($b < 0.3) { $sn = $s + int(50.0*rand()); }
  241. $param_name[$j] = "param$j";
  242. $lt = $MATRIX_TYPES[0];
  243. if ($with_lapack==0) {
  244. $lt = $MATRIX_TYPES[int($NB_MATRIX_TYPES * rand())];
  245. }
  246. $li = " $lt param$j($sm, $sn);";
  247. if ($a < 0.3 || $b < 0.3) {
  248. $sub1 = "gmm::sub_interval(0, $sizep)";
  249. $sub2 = "gmm::sub_interval(0, $s)";
  250. if ($a < 0.1) {
  251. $c = int(1.0*($sm-$sizep+1)*rand());
  252. $sub1 = "gmm::sub_interval($c, $sizep)";
  253. }
  254. elsif ($a < 0.2) {
  255. $step = $sizep; if ($step == 0) { ++$step; }
  256. $step = int(1.0*int($sm/$step - 1)*rand()) + 1;
  257. $c = int(1.0*($sm-($sizep*$step+1))*rand());
  258. $sub1 = "gmm::sub_slice($c, $sizep, $step)";
  259. }
  260. elsif ($a < 0.3) {
  261. @sub_index = ();
  262. @sortind = 0 .. ($sm-1);
  263. while (@sortind)
  264. { push (@sub_index, splice(@sortind , rand @sortind, 1)); }
  265. @sub_index = @sub_index[0..$sizep-1];
  266. @sub_index = sort numerique @sub_index;
  267. if ($sizep == 0)
  268. { $li = "$li\n gmm::size_type param_t$j [1] = {0};"; }
  269. else {
  270. $li="$li\n gmm::size_type param_t$j [$sizep]= {$sub_index[0]";
  271. for ($k = 1; $k < $sizep; ++$k) { $li = "$li , $sub_index[$k]"; }
  272. $li = "$li};";
  273. }
  274. $sub1 = "gmm::sub_index(&param_t$j [0], &param_t$j [$sizep])";
  275. }
  276. if ($b < 0.1) {
  277. $c = int(1.0*($sn-$s+1)*rand());
  278. $sub2 = "gmm::sub_interval($c, $s)";
  279. }
  280. elsif ($b < 0.2) {
  281. $step = $s; if ($step == 0) { ++$step; }
  282. $step = int(1.0*int($sn/$step - 1)*rand()) + 1;
  283. $c = int(1.0*($sn-($s*$step+1))*rand());
  284. $sub2 = "gmm::sub_slice($c, $s, $step)";
  285. }
  286. elsif ($b < 0.3) {
  287. @sub_index = ();
  288. @sortind = 0 .. ($sn-1);
  289. while (@sortind)
  290. { push (@sub_index, splice(@sortind , rand @sortind, 1)); }
  291. @sub_index = @sub_index[0..$s-1];
  292. @sub_index = sort numerique @sub_index;
  293. if ($s == 0)
  294. { $li = "$li\n gmm::size_type param_u$j [1] = {0};"; }
  295. else {
  296. $li="$li\n gmm::size_type param_u$j [$s] = {$sub_index[0]";
  297. for ($k = 1; $k < $s; ++$k) { $li = "$li , $sub_index[$k]"; }
  298. $li = "$li};";
  299. }
  300. $sub2 = "gmm::sub_index(&param_u$j [0], &param_u$j [$s])";
  301. }
  302. $param_name[$j] = "gmm::sub_matrix(param$j, $sub1, $sub2)";
  303. }
  304. if (1.0 * rand() < 0.5) {
  305. print TMPF "$li\n gmm::fill_random(param$j);\n";
  306. }
  307. else {
  308. print TMPF "$li\n gmm::fill_random(param$j, 0.2);\n";
  309. }
  310. $sizep = $s;
  311. }
  312. # print "$li ($param_name[$j])\n";
  313. }
  314. print TMPF " \n\n bool ret = test_procedure($param_name[0]";
  315. for ($j = 1; $j < $nb_param; ++$j) { print TMPF ", $param_name[$j]"; }
  316. print TMPF ");\n";
  317. print TMPF " if (ret) return 0;\n\n";
  318. print TMPF " }\n";
  319. print TMPF " GMM_STANDARD_CATCH_ERROR;\n";
  320. print TMPF " }\n";
  321. print TMPF " return 0;\n";
  322. print TMPF "}\n";
  323. close(DATAF);
  324. close(TMPF);
  325. `rm -f $root_name`;
  326. $compilo=`sh ../gmm-config --cxx` || die('cannot execute ../gmm-config --cxx'); chomp($compilo);
  327. $compile_options=`sh ../gmm-config --build-flags`;
  328. chomp($compile_options);
  329. $compile_options="$compile_options -I$srcdir/../src -I$srcdir/../include -I../src -I../include";
  330. $compile_libs="-lm";
  331. if ($with_lapack) {
  332. $compile_libs="-llapack -lblas -lg2c $compile_libs";
  333. $compile_options="$compile_options -DGMM_USES_LAPACK"
  334. }
  335. if ($with_qd) { $compile_libs="-lqd $compile_libs"; }
  336. # print "$compilo $compile_options $dest_name -o $root_name $compile_libs\n";
  337. print `$compilo $compile_options $dest_name -o $root_name $compile_libs`;
  338. if ($? != 0) {
  339. print "$compilo $compile_options $dest_name -o $root_name $compile_libs\n";
  340. print "\n******************************************************\n";
  341. print "* Compilation error, please submit this bug to\n";
  342. print "* Yves.Renard\@insa-lyon.fr, with the file\n";
  343. print "* $dest_name\n";
  344. print "* produced in directory \"tests\".\n";
  345. print "******************************************************\n";
  346. exit(1);
  347. }
  348. print `./$root_name`;
  349. if ($? != 0) {
  350. print "$compilo $compile_options $dest_name -o $root_name $compile_libs\n";
  351. print "\n******************************************************\n";
  352. print "* Execution error, please submit this bug to\n";
  353. print "* Yves.Renard\@insa-lyon.fr, with the file\n";
  354. print "* $dest_name\n";
  355. print "* produced in directory \"tests\".\n";
  356. print "******************************************************\n";
  357. exit(1);
  358. }
  359. # `rm -f $dest_name`;
  360. }
  361. }