test_assignment.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. //
  2. // Copyright (c) 2010 Athanasios Iliopoulos
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #include <boost/numeric/ublas/assignment.hpp>
  9. #include <boost/numeric/ublas/vector.hpp>
  10. #include <boost/numeric/ublas/vector_proxy.hpp>
  11. #include <boost/numeric/ublas/vector_sparse.hpp>
  12. #include <boost/numeric/ublas/matrix_sparse.hpp>
  13. #include <boost/numeric/ublas/io.hpp>
  14. #include <boost/numeric/ublas/matrix.hpp>
  15. #include <boost/timer.hpp>
  16. #include <ctime>
  17. #include "common/testhelper.hpp"
  18. #include "utils.hpp"
  19. using namespace boost::numeric::ublas;
  20. template <class V>
  21. bool test_vector() {
  22. bool pass = true;
  23. V a(3), ra(3);
  24. a <<= 1, 2, 3;
  25. ra(0) = typename V::value_type(1); ra(1) = typename V::value_type(2); ra(2) = typename V::value_type(3);
  26. pass &= compare_distance(a, ra);
  27. V b(7), rb(7);
  28. b<<= a, 10, a;
  29. rb(0) = typename V::value_type(1); rb(1) = typename V::value_type(2); rb(2) = typename V::value_type(3);
  30. rb(3) = typename V::value_type(10); rb(4) = typename V::value_type(1); rb(5) = typename V::value_type(2); rb(6) = typename V::value_type(3);
  31. pass &= compare_distance(b, rb);
  32. {
  33. V c(6), rc(6);
  34. c <<= 1, move(2), 3 ,4, 5, move(-5), 10, 10;
  35. rc(0) = typename V::value_type(1); rc(1) = typename V::value_type(10); rc(2) = typename V::value_type(10);
  36. rc(3) = typename V::value_type(3); rc(4) = typename V::value_type(4); rc(5) = typename V::value_type(5);
  37. pass &= compare_distance(c, rc);
  38. V d(6), rd(6);
  39. d <<= 1, move_to(3), 3 ,4, 5, move_to(1), 10, 10;
  40. rd(0) = typename V::value_type(1); rd(1) = typename V::value_type(10); rd(2) = typename V::value_type(10);
  41. rd(3) = typename V::value_type(3); rd(4) = typename V::value_type(4); rd(5) = typename V::value_type(5);
  42. pass &= compare_distance(d, rd);
  43. }
  44. {
  45. V c(6), rc(6);
  46. c <<= 1, move<2>(), 3 ,4, 5, move<-5>(), 10, 10;
  47. rc(0) = typename V::value_type(1); rc(1) = typename V::value_type(10); rc(2) = typename V::value_type(10);
  48. rc(3) = typename V::value_type(3); rc(4) = typename V::value_type(4); rc(5) = typename V::value_type(5);
  49. pass &= compare_distance(c, rc);
  50. V d(6), rd(6);
  51. d <<= 1, move_to<3>(), 3 ,4, 5, move_to<1>(), 10, 10;
  52. rd(0) = typename V::value_type(1); rd(1) = typename V::value_type(10); rd(2) = typename V::value_type(10);
  53. rd(3) = typename V::value_type(3); rd(4) = typename V::value_type(4); rd(5) = typename V::value_type(5);
  54. pass &= compare_distance(d, rd);
  55. }
  56. {
  57. V f(6), rf(6);
  58. f <<= 5, 5, 5, 5, 5, 5;
  59. V fa(3); fa<<= 1, 2, 3;
  60. f <<= fill_policy::index_plus_assign(), fa;
  61. rf <<= 6,7,8, 5, 5, 5;
  62. pass &= compare_distance(f, rf);
  63. }
  64. {
  65. V f(6), rf(6);
  66. f <<= 5, 5, 5, 5, 5, 5;
  67. V fa(3); fa<<= 1, 2, 3;
  68. f <<= fill_policy::index_minus_assign(), fa;
  69. rf <<= 4,3,2, 5, 5, 5;
  70. pass &= compare_distance(f, rf);
  71. }
  72. return pass;
  73. }
  74. template <class V>
  75. bool test_vector_sparse_push_back() {
  76. bool pass = true;
  77. V a(3), ra(3);
  78. a <<= fill_policy::sparse_push_back(), 1, 2, 3;
  79. ra(0) = typename V::value_type(1); ra(1) = typename V::value_type(2); ra(2) = typename V::value_type(3);
  80. pass &= compare_distance(a, ra);
  81. V b(7), rb(7);
  82. b<<= fill_policy::sparse_push_back(), a, 10, a;
  83. rb(0) = typename V::value_type(1); rb(1) = typename V::value_type(2); rb(2) = typename V::value_type(3);
  84. rb(3) = typename V::value_type(10), rb(4)= typename V::value_type(1); rb(5) = typename V::value_type(2); rb(6) = typename V::value_type(3);
  85. pass &= compare_distance(b, rb);
  86. V c(6), rc(6);
  87. c <<= fill_policy::sparse_push_back(), 1, move(2), 3 ,4, 5; // Move back (i.e. negative is dangerous for push_back)
  88. rc(0) = typename V::value_type(1); rc(1) = typename V::value_type(0); rc(2) = typename V::value_type(0);
  89. rc(3) = typename V::value_type(3); rc(4) = typename V::value_type(4); rc(5) = typename V::value_type(5);
  90. pass &= compare_distance(c, rc);
  91. V d(6), rd(6);
  92. d <<= fill_policy::sparse_push_back(), 1, move_to(3), 3 ,4, 5; // Move back (i.e. before current index is dangerous for push_back)
  93. rd(0) = typename V::value_type(1); rd(1) = typename V::value_type(0); rd(2) = typename V::value_type(0);
  94. rd(3) = typename V::value_type(3); rd(4) = typename V::value_type(4); rd(5) = typename V::value_type(5);
  95. pass &= compare_distance(d, rd);
  96. V e(6), re(6);
  97. e <<= fill_policy::sparse_push_back(), 1, move_to(3), 3 ,4, 5, fill_policy::sparse_insert(), move_to(1), 10, 10; // If you want to move back, use this
  98. re(0) = typename V::value_type(1); re(1) = typename V::value_type(10); re(2) = typename V::value_type(10);
  99. re(3) = typename V::value_type(3); re(4) = typename V::value_type(4); re(5) = typename V::value_type(5);
  100. pass &= compare_distance(e, re);
  101. return pass;
  102. }
  103. template <class V>
  104. bool test_vector_sparse_insert() {
  105. bool pass = true;
  106. V a(3), ra(3);
  107. a <<= fill_policy::sparse_insert(), 1, 2, 3;
  108. ra(0) = typename V::value_type(1); ra(1) = typename V::value_type(2); ra(2) = typename V::value_type(3);
  109. pass &= compare_distance(a, ra);
  110. V b(7), rb(7);
  111. b<<= fill_policy::sparse_insert(), a, 10, a;
  112. rb(0) = typename V::value_type(1); rb(1) = typename V::value_type(2); rb(2) = typename V::value_type(3);
  113. rb(3) = typename V::value_type(10), rb(4) = typename V::value_type(1); rb(5)= typename V::value_type(2); rb(6) = typename V::value_type(3);
  114. pass &= compare_distance(b, rb);
  115. V c(6), rc(6);
  116. c <<= fill_policy::sparse_insert(), 1, move(2), 3 ,4, 5, move(-5), 10, 10; // Move back (i.e. negative is dangerous for sparse)
  117. rc(0) = typename V::value_type(1); rc(1) = typename V::value_type(10); rc(2) = typename V::value_type(10);
  118. rc(3) = typename V::value_type(3); rc(4) = typename V::value_type(4); rc(5) = typename V::value_type(5);
  119. pass &= compare_distance(c, rc);
  120. V d(6), rd(6);
  121. d <<= fill_policy::sparse_insert(), 1, move_to(3), 3 ,4, 5, move_to(1), 10, 10; // Move back (i.e.before is dangerous for sparse)
  122. rd(0) = typename V::value_type(1); rd(1) = typename V::value_type(10); rd(2) = typename V::value_type(10);
  123. rd(3) = typename V::value_type(3); rd(4) = typename V::value_type(4); rd(5) = typename V::value_type(5);
  124. pass &= compare_distance(d, rd);
  125. return pass;
  126. }
  127. template <class V>
  128. bool test_matrix() {
  129. bool pass = true;
  130. V A(3,3), RA(3,3);
  131. A <<= 1, 2, 3, 4, 5, 6, 7, 8, 9;
  132. RA(0,0)= typename V::value_type(1); RA(0,1)=typename V::value_type(2); RA(0,2)=typename V::value_type(3);
  133. RA(1,0)= typename V::value_type(4); RA(1,1)=typename V::value_type(5); RA(1,2)=typename V::value_type(6);
  134. RA(2,0)= typename V::value_type(7); RA(2,1)=typename V::value_type(8); RA(2,2)=typename V::value_type(9);
  135. pass &= compare_distance(A, RA);
  136. {
  137. V B(3,3), RB(3,3);
  138. vector<typename V::value_type> b(3);
  139. b<<= 4,5,6;
  140. B<<= 1, 2, 3, b, 7, project(b, range(1,3));
  141. RB<<=1, 2, 3, 4, 5, 6, 7, 5, 6; // If the first worked we can now probably use it.
  142. pass &= compare_distance(B, RB);
  143. }
  144. {
  145. V B(3,3), RB(3,3);
  146. vector<typename V::value_type> b(3);
  147. b<<= 4,5,6;
  148. B<<= move(1,0), b, move_to(0,0), 1, 2, 3, move(1,0), 7, project(b, range(1,3));
  149. RB<<=1, 2, 3, 4, 5, 6, 7, 5, 6;
  150. pass &= compare_distance(B, RB);
  151. }
  152. {
  153. V B(3,3), RB(3,3);
  154. vector<typename V::value_type> b(9);
  155. b<<= 1, 2, 3, 4, 5, 6, 7, 8, 9;
  156. B<<=b;
  157. RB<<=1, 2, 3, 4, 5, 6, 7, 8, 9;
  158. pass &= compare_distance(B, RB);
  159. }
  160. {
  161. V B(4,4), RB(4,4);
  162. V C(2,2);
  163. C <<= 2, 3,
  164. 4, 5;
  165. B<<= C,C,
  166. C,C;
  167. RB <<= 2,3,2,3,
  168. 4,5,4,5,
  169. 2,3,2,3,
  170. 4,5,4,5;
  171. pass &= compare_distance(B, RB);
  172. }
  173. {
  174. V B(4,4), RB(4,4);
  175. V C(2,2);
  176. C <<= 2, 3, 4, 5;
  177. B<<= C, zero_matrix<typename V::value_type>(2,2),
  178. zero_matrix<typename V::value_type>(2,2), C;
  179. RB<<= 2,3,0,0,
  180. 4,5,0,0,
  181. 0,0,2,3,
  182. 0,0,4,5;
  183. pass &= compare_distance(B, RB);
  184. }
  185. {
  186. V B(4,4), RB(4,4);
  187. V C(2,2);
  188. C <<= 2, 3, 4, 5;
  189. B<<= C, zero_matrix<typename V::value_type>(2,2),
  190. zero_matrix<typename V::value_type>(2,2), C;
  191. RB<<= 2,3,0,0,
  192. 4,5,0,0,
  193. 0,0,2,3,
  194. 0,0,4,5;
  195. pass &= compare_distance(B, RB);
  196. }
  197. {
  198. V B(4,4), RB(4,4);
  199. B = zero_matrix<typename V::value_type>(4,4); // We need that because of the non-zero instatiation of dense types.
  200. V C(2,2);
  201. C <<= 2, 3, 4, 5;
  202. B<<= move(1,1), C;
  203. RB<<= 0,0,0,0,
  204. 0,2,3,0,
  205. 0,4,5,0,
  206. 0,0,0,0;
  207. pass &= compare_distance(B, RB);
  208. }
  209. {
  210. V B(4,4), RB(4,4);
  211. B = zero_matrix<typename V::value_type>(4,4);
  212. B<<= move_to(0,1), 2, 3, next_row(), 1, 2, next_row(), 4, 5;
  213. RB<<= 0,2,3,0,
  214. 1,2,0,0,
  215. 4,5,0,0,
  216. 0,0,0,0;
  217. pass &= compare_distance(B, RB);
  218. }
  219. {
  220. V B(4,4), RB(4,4);
  221. B = zero_matrix<typename V::value_type>(4,4);
  222. B<<=traverse_policy::by_column(), move_to(0,1), 2, 3, 6, next_column(), 4, 5;
  223. RB<<= 0,2,4,0,
  224. 0,3,5,0,
  225. 0,6,0,0,
  226. 0,0,0,0;
  227. pass &= compare_distance(B, RB);
  228. }
  229. {
  230. V B(4,4), RB(4,4);
  231. B = zero_matrix<typename V::value_type>(4,4);
  232. B<<=traverse_policy::by_column(), move_to(0,1), 2, 3, next_row(), traverse_policy::by_row(), 4, 5;
  233. RB<<= 0,2,0,0,
  234. 0,3,0,0,
  235. 0,0,0,0,
  236. 4,5,0,0;
  237. pass &= compare_distance(B, RB);
  238. }
  239. {
  240. V B(4,4), RB(4,4);
  241. B = zero_matrix<typename V::value_type>(4,4);
  242. B<<=traverse_policy::by_column(), move_to(0,1), 2, 3, begin2(), traverse_policy::by_row(), 4, 5, 6, 7, 8;
  243. RB<<= 0,2,0,0,
  244. 0,3,0,0,
  245. 4,5,6,7,
  246. 8,0,0,0;
  247. pass &= compare_distance(B, RB);
  248. }
  249. {
  250. V B(4,4), RB(4,4);
  251. B = zero_matrix<typename V::value_type>(4,4);
  252. B<<=traverse_policy::by_column(), move_to(0,1), 2, 3, begin2(), traverse_policy::by_row(), 4, 5, 6, 7, 8,9, begin1(), 1, 2;
  253. RB<<= 0,2,1,2,
  254. 0,3,0,0,
  255. 4,5,6,7,
  256. 8,9,0,0;
  257. pass &= compare_distance(B, RB);
  258. }
  259. {
  260. V B(4,4), RB(4,4);
  261. B = scalar_matrix<typename V::value_type>(4,4,1);
  262. V C(2,2);
  263. C <<= 1, 2, 3, 4;
  264. B<<= fill_policy::index_plus_assign(), move(1,1), C;
  265. RB<<= 1,1,1,1,
  266. 1,2,3,1,
  267. 1,4,5,1,
  268. 1,1,1,1;
  269. pass &= compare_distance(B, RB);
  270. }
  271. {
  272. V B(4,4), RB(4,4);
  273. B = scalar_matrix<typename V::value_type>(4,4,5);
  274. V C(2,2);
  275. C <<= 1, 2, 3, 4;
  276. B<<= fill_policy::index_minus_assign(), move(1,1), C;
  277. RB<<= 5,5,5,5,
  278. 5,4,3,5,
  279. 5,2,1,5,
  280. 5,5,5,5;
  281. pass &= compare_distance(B, RB);
  282. }
  283. return pass;
  284. }
  285. template <class V>
  286. bool test_matrix_sparse_push_back() {
  287. bool pass = true;
  288. V A(3,3), RA(3,3);
  289. A <<= fill_policy::sparse_push_back(), 1, 2, 3, 4, 5, 6, 7, 8, 9;
  290. RA(0,0)= typename V::value_type(1); RA(0,1)= typename V::value_type(2); RA(0,2)= typename V::value_type(3);
  291. RA(1,0)= typename V::value_type(4); RA(1,1)= typename V::value_type(5); RA(1,2)= typename V::value_type(6);
  292. RA(2,0)= typename V::value_type(7); RA(2,1)= typename V::value_type(8); RA(2,2)= typename V::value_type(9);
  293. pass &= compare_distance(A, RA);
  294. {
  295. V B(3,3), RB(3,3);
  296. vector<typename V::value_type> b(3);
  297. b<<= 4,5,6;
  298. B<<=fill_policy::sparse_push_back(), 1, 2, 3, b, 7, project(b, range(1,3));
  299. RB<<= 1, 2, 3, 4, 5, 6, 7, 5, 6; // If the first worked we can now probably use it.
  300. pass &= compare_distance(B, RB);
  301. }
  302. {
  303. V B(3,3), RB(3,3);
  304. vector<typename V::value_type> b(3);
  305. b<<= 4,5,6;
  306. B<<=fill_policy::sparse_push_back(), move(1,0), b, fill_policy::sparse_insert(), move_to(0,0), 1, 2, 3, move(1,0), 7, project(b, range(1,3));
  307. RB<<=1, 2, 3, 4, 5, 6, 7, 5, 6;
  308. pass &= compare_distance(B, RB);
  309. }
  310. {
  311. V B(3,3), RB(3,3);
  312. vector<typename V::value_type> b(9);
  313. b<<= 1, 2, 3, 4, 5, 6, 7, 8, 9;
  314. B<<=b;
  315. RB<<=1, 2, 3, 4, 5, 6, 7, 8, 9;
  316. pass &= compare_distance(B, RB);
  317. }
  318. {
  319. V B(4,4), RB(4,4);
  320. V C(2,2);
  321. C <<= 2, 3,
  322. 4, 5;
  323. // It might get complicated for sparse push_back, this must go into the tutorial. (This way is not convient nor fast)
  324. B<<=fill_policy::sparse_push_back(), C, move_to(2,2), C, fill_policy::sparse_insert(), move_to(0,2), C, C;
  325. RB <<= 2,3,2,3,
  326. 4,5,4,5,
  327. 2,3,2,3,
  328. 4,5,4,5;
  329. pass &= compare_distance(B, RB);
  330. }
  331. {
  332. V B(4,4), RB(4,4);
  333. V C(2,2);
  334. C <<= 2, 3, 4, 5;
  335. B<<=fill_policy::sparse_push_back(), C, move_to(2,2), C;
  336. RB<<= 2,3,0,0,
  337. 4,5,0,0,
  338. 0,0,2,3,
  339. 0,0,4,5;
  340. pass &= compare_distance(B, RB);
  341. }
  342. {
  343. V B(4,4), RB(4,4);
  344. V C(2,2);
  345. C <<= 2, 3, 4, 5;
  346. B<<=fill_policy::sparse_push_back(), move(1,1), C;
  347. RB<<= 0,0,0,0,
  348. 0,2,3,0,
  349. 0,4,5,0,
  350. 0,0,0,0;
  351. pass &= compare_distance(B, RB);
  352. }
  353. {
  354. V B(4,4), RB(4,4);
  355. B = zero_matrix<typename V::value_type>(4,4);
  356. B<<=fill_policy::sparse_push_back(), move_to(0,1), 2, 3, next_row(), 1, 2, next_row(), 4, 5;
  357. RB<<= 0,2,3,0,
  358. 1,2,0,0,
  359. 4,5,0,0,
  360. 0,0,0,0;
  361. pass &= compare_distance(B, RB);
  362. }
  363. // The next will not work with sparse push_back because elements that are prior to the ones already in are attempted to be added
  364. /*
  365. {
  366. V B(4,4), RB(4,4);
  367. B = zero_matrix<typename V::value_type>(4,4);
  368. B<<=fill_policy::sparse_push_back(),traverse_policy::by_column(), move_to(0,1), 2, 3, 6, next_column(), 4, 5;
  369. RB<<= 0,2,4,0,
  370. 0,3,5,0,
  371. 0,6,0,0,
  372. 0,0,0,0;
  373. pass &= compare_distance(B, RB);
  374. }
  375. */
  376. {
  377. V B(4,4), RB(4,4);
  378. B = zero_matrix<typename V::value_type>(4,4);
  379. B<<=fill_policy::sparse_push_back(),traverse_policy::by_column(), move_to(0,1), 2, 3, next_row(), traverse_policy::by_row(), 4, 5;
  380. RB<<= 0,2,0,0,
  381. 0,3,0,0,
  382. 0,0,0,0,
  383. 4,5,0,0;
  384. pass &= compare_distance(B, RB);
  385. }
  386. {
  387. V B(4,4), RB(4,4);
  388. B = zero_matrix<typename V::value_type>(4,4);
  389. B<<=fill_policy::sparse_push_back(),traverse_policy::by_column(), move_to(0,1), 2, 3, begin2(), traverse_policy::by_row(), 4, 5, 6, 7, 8;
  390. RB<<= 0,2,0,0,
  391. 0,3,0,0,
  392. 4,5,6,7,
  393. 8,0,0,0;
  394. pass &= compare_distance(B, RB);
  395. }
  396. // The next will not work with sparse push_back because elements that are prior to the ones already in are attempted to be added
  397. /*
  398. {
  399. V B(4,4), RB(4,4);
  400. B = zero_matrix<typename V::value_type>(4,4);
  401. B<<=fill_policy::sparse_push_back(),traverse_policy::by_column(), move_to(0,1), 2, 3, begin2(), traverse_policy::by_row(), 4, 5, 6, 7, 8,9, begin1(), 1, 2;
  402. RB<<= 0,2,1,2,
  403. 0,3,0,0,
  404. 4,5,6,7,
  405. 8,9,0,0;
  406. pass &= compare_distance(B, RB);
  407. }
  408. */
  409. return pass;
  410. }
  411. template <class V>
  412. bool test_matrix_sparse_insert() {
  413. bool pass = true;
  414. V A(3,3), RA(3,3);
  415. A <<= fill_policy::sparse_insert(), 1, 2, 3, 4, 5, 6, 7, 8, 9;
  416. RA(0,0)= typename V::value_type(1); RA(0,1)= typename V::value_type(2); RA(0,2)= typename V::value_type(3);
  417. RA(1,0)= typename V::value_type(4); RA(1,1)= typename V::value_type(5); RA(1,2)= typename V::value_type(6);
  418. RA(2,0)= typename V::value_type(7); RA(2,1)= typename V::value_type(8); RA(2,2)= typename V::value_type(9);
  419. pass &= compare_distance(A, RA);
  420. {
  421. V B(3,3), RB(3,3);
  422. vector<typename V::value_type> b(3);
  423. b<<= 4,5,6;
  424. B<<=fill_policy::sparse_insert(), 1, 2, 3, b, 7, project(b, range(1,3));
  425. RB<<=1, 2, 3, 4, 5, 6, 7, 5, 6; // If the first worked we can now probably use it.
  426. pass &= compare_distance(B, RB);
  427. }
  428. {
  429. V B(3,3), RB(3,3);
  430. vector<typename V::value_type> b(3);
  431. b<<= 4,5,6;
  432. B<<=fill_policy::sparse_insert(), move(1,0), b, fill_policy::sparse_insert(), move_to(0,0), 1, 2, 3, move(1,0), 7, project(b, range(1,3));
  433. RB<<=1, 2, 3, 4, 5, 6, 7, 5, 6;
  434. pass &= compare_distance(B, RB);
  435. }
  436. {
  437. V B(3,3), RB(3,3);
  438. vector<typename V::value_type> b(9);
  439. b<<= 1, 2, 3, 4, 5, 6, 7, 8, 9;
  440. B<<=b;
  441. RB<<=1, 2, 3, 4, 5, 6, 7, 8, 9;
  442. pass &= compare_distance(B, RB);
  443. }
  444. {
  445. V B(4,4), RB(4,4);
  446. V C(2,2);
  447. C <<= 2, 3,
  448. 4, 5;
  449. B<<=fill_policy::sparse_insert(), C, C, C, C;
  450. RB <<= 2,3,2,3,
  451. 4,5,4,5,
  452. 2,3,2,3,
  453. 4,5,4,5;
  454. pass &= compare_distance(B, RB);
  455. }
  456. {
  457. V B(4,4), RB(4,4);
  458. V C(2,2);
  459. C <<= 2, 3, 4, 5;
  460. B<<=fill_policy::sparse_insert(), C, move_to(2,2), C;
  461. RB<<= 2,3,0,0,
  462. 4,5,0,0,
  463. 0,0,2,3,
  464. 0,0,4,5;
  465. pass &= compare_distance(B, RB);
  466. }
  467. {
  468. V B(4,4), RB(4,4);
  469. V C(2,2);
  470. C <<= 2, 3, 4, 5;
  471. B<<=fill_policy::sparse_insert(), move(1,1), C;
  472. RB<<= 0,0,0,0,
  473. 0,2,3,0,
  474. 0,4,5,0,
  475. 0,0,0,0;
  476. pass &= compare_distance(B, RB);
  477. }
  478. {
  479. V B(4,4), RB(4,4);
  480. B = zero_matrix<typename V::value_type>(4,4);
  481. B<<=fill_policy::sparse_insert(), move_to(0,1), 2, 3, next_row(), 1, 2, next_row(), 4, 5;
  482. RB<<= 0,2,3,0,
  483. 1,2,0,0,
  484. 4,5,0,0,
  485. 0,0,0,0;
  486. pass &= compare_distance(B, RB);
  487. }
  488. {
  489. V B(4,4), RB(4,4);
  490. B = zero_matrix<typename V::value_type>(4,4);
  491. B<<=fill_policy::sparse_insert(),traverse_policy::by_column(), move_to(0,1), 2, 3, 6, next_column(), 4, 5;
  492. RB<<= 0,2,4,0,
  493. 0,3,5,0,
  494. 0,6,0,0,
  495. 0,0,0,0;
  496. pass &= compare_distance(B, RB);
  497. }
  498. {
  499. V B(4,4), RB(4,4);
  500. B = zero_matrix<typename V::value_type>(4,4);
  501. B<<=fill_policy::sparse_insert(),traverse_policy::by_column(), move_to(0,1), 2, 3, next_row(), traverse_policy::by_row(), 4, 5;
  502. RB<<= 0,2,0,0,
  503. 0,3,0,0,
  504. 0,0,0,0,
  505. 4,5,0,0;
  506. pass &= compare_distance(B, RB);
  507. }
  508. {
  509. V B(4,4), RB(4,4);
  510. B = zero_matrix<typename V::value_type>(4,4);
  511. B<<=fill_policy::sparse_insert(),traverse_policy::by_column(), move_to(0,1), 2, 3, begin2(), traverse_policy::by_row(), 4, 5, 6, 7, 8;
  512. RB<<= 0,2,0,0,
  513. 0,3,0,0,
  514. 4,5,6,7,
  515. 8,0,0,0;
  516. pass &= compare_distance(B, RB);
  517. }
  518. {
  519. V B(4,4), RB(4,4);
  520. B = zero_matrix<typename V::value_type>(4,4);
  521. B<<=fill_policy::sparse_insert(),traverse_policy::by_column(), move_to(0,1), 2, 3, begin2(), traverse_policy::by_row(), 4, 5, 6, 7, 8,9, begin1(), 1, 2;
  522. RB<<= 0,2,1,2,
  523. 0,3,0,0,
  524. 4,5,6,7,
  525. 8,9,0,0;
  526. pass &= compare_distance(B, RB);
  527. }
  528. return pass;
  529. }
  530. BOOST_UBLAS_TEST_DEF (test_vector) {
  531. BOOST_UBLAS_DEBUG_TRACE( "Starting operator \"<<= \" vector assignment tests" );
  532. BOOST_UBLAS_TEST_CHECK(test_vector<vector<double> >());
  533. BOOST_UBLAS_TEST_CHECK(test_vector<vector<float> >());
  534. BOOST_UBLAS_TEST_CHECK(test_vector<vector<long> >());
  535. BOOST_UBLAS_TEST_CHECK(test_vector<vector<unsigned long> >());
  536. BOOST_UBLAS_TEST_CHECK(test_vector<vector<int> >());
  537. BOOST_UBLAS_TEST_CHECK(test_vector<vector<unsigned int> >());
  538. BOOST_UBLAS_TEST_CHECK(test_vector<vector<std::size_t> >());
  539. BOOST_UBLAS_TEST_CHECK(test_vector<vector<char> >());
  540. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<double,7> >()));
  541. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<float,7> >()));
  542. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<long,7> >()));
  543. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<unsigned long,7> >()));
  544. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<int,7> >()));
  545. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<unsigned int,7> >()));
  546. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<std::size_t,7> >()));
  547. BOOST_UBLAS_TEST_CHECK((test_vector<bounded_vector<char,7> >()));
  548. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<double> >());
  549. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<float> >());
  550. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<long> >());
  551. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<unsigned long> >());
  552. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<int> >());
  553. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<unsigned int> >())
  554. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<std::size_t> >())
  555. BOOST_UBLAS_TEST_CHECK(test_vector<mapped_vector<char> >());
  556. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<double> >());
  557. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<float> >());
  558. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<long> >());
  559. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<unsigned long> >());
  560. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<int> >());
  561. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<unsigned int> >());
  562. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<std::size_t> >());
  563. BOOST_UBLAS_TEST_CHECK(test_vector<compressed_vector<char> >());
  564. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<double> >());
  565. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<float> >());
  566. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<long> >())
  567. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<unsigned long> >())
  568. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<int> >());
  569. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<unsigned int> >());
  570. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<std::size_t> >());
  571. BOOST_UBLAS_TEST_CHECK(test_vector<coordinate_vector<char> >());
  572. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<double> >());
  573. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<float> >());
  574. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<long> >());
  575. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<unsigned long> >());
  576. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<int> >());
  577. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<unsigned int> >());
  578. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<std::size_t> >());
  579. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<compressed_vector<char> >());
  580. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<double> >());
  581. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<float> >());
  582. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<long> >());
  583. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<unsigned long> >());
  584. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<int> >());
  585. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<unsigned int> >());
  586. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<std::size_t> >());
  587. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_push_back<coordinate_vector<char> >());
  588. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<double> >());
  589. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<float> >());
  590. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<long> >());
  591. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<unsigned long> >());
  592. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<int> >());
  593. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<unsigned int> >());
  594. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<std::size_t> >());
  595. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<compressed_vector<char> >());
  596. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<double> >());
  597. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<float> >());
  598. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<long> >());
  599. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<unsigned long> >());
  600. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<int> >());
  601. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<unsigned int> >());
  602. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<std::size_t> >());
  603. BOOST_UBLAS_TEST_CHECK(test_vector_sparse_insert<coordinate_vector<char> >());
  604. }
  605. BOOST_UBLAS_TEST_DEF (test_matrix) {
  606. BOOST_UBLAS_DEBUG_TRACE( "Starting operator \"<<= \" matrix assignment tests" );
  607. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<double> >());
  608. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<float> >());
  609. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<long> >());
  610. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<unsigned long> >());
  611. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<int> >());
  612. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<unsigned int> >());
  613. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<std::size_t> >());
  614. BOOST_UBLAS_TEST_CHECK(test_matrix<matrix<char> >());
  615. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<double,7, 7> >()));
  616. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<float,7, 7> >()));
  617. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<long,7, 7> >()));
  618. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<unsigned long,7, 7> >()));
  619. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<int,7,7 > >()));
  620. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<unsigned int,7, 7> >()));
  621. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<char,7, 7> >()));
  622. BOOST_UBLAS_TEST_CHECK((test_matrix<bounded_matrix<std::size_t,7, 7> >()));
  623. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<double> >());
  624. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<float> >());
  625. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<long> >());
  626. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<unsigned long> >());
  627. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<int> >());
  628. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<unsigned int> >())
  629. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<std::size_t> >())
  630. BOOST_UBLAS_TEST_CHECK(test_matrix<mapped_matrix<char> >());
  631. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<double> >());
  632. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<float> >());
  633. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<long> >());
  634. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<unsigned long> >());
  635. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<int> >());
  636. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<unsigned int> >());
  637. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<std::size_t> >());
  638. BOOST_UBLAS_TEST_CHECK(test_matrix<compressed_matrix<char> >());
  639. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<double> >());
  640. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<float> >());
  641. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<long> >())
  642. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<unsigned long> >())
  643. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<int> >());
  644. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<unsigned int> >());
  645. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<std::size_t> >());
  646. BOOST_UBLAS_TEST_CHECK(test_matrix<coordinate_matrix<char> >());
  647. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<double> >());
  648. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<float> >());
  649. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<long> >());
  650. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<unsigned long> >());
  651. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<int> >());
  652. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<unsigned int> >());
  653. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<std::size_t> >());
  654. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<compressed_matrix<char> >());
  655. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<double> >());
  656. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<float> >());
  657. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<long> >());
  658. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<unsigned long> >());
  659. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<int> >());
  660. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<unsigned int> >());
  661. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<std::size_t> >());
  662. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_push_back<coordinate_matrix<char> >());
  663. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<double> >());
  664. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<float> >());
  665. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<long> >());
  666. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<unsigned long> >());
  667. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<int> >());
  668. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<unsigned int> >());
  669. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<std::size_t> >());
  670. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<compressed_matrix<char> >());
  671. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<double> >());
  672. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<float> >());
  673. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<long> >());
  674. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<unsigned long> >());
  675. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<int> >());
  676. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<unsigned int> >());
  677. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<std::size_t> >());
  678. BOOST_UBLAS_TEST_CHECK(test_matrix_sparse_insert<coordinate_matrix<char> >());
  679. }
  680. int main () {
  681. BOOST_UBLAS_TEST_BEGIN();
  682. BOOST_UBLAS_TEST_DO( test_vector );
  683. BOOST_UBLAS_TEST_DO( test_matrix );
  684. BOOST_UBLAS_TEST_END();
  685. }