small-1.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Making ra::Small and its iterator work with expressions/traversal.
  3. // (c) Daniel Llorens - 2014-2023
  4. // This library is free software; you can redistribute it and/or modify it under
  5. // the terms of the GNU Lesser General Public License as published by the Free
  6. // Software Foundation; either version 3 of the License, or (at your option) any
  7. // later version.
  8. // See also small-0.cc.
  9. #include <iostream>
  10. #include <iterator>
  11. #include "ra/test.hh"
  12. #include "mpdebug.hh"
  13. using std::cout, std::endl, std::flush, ra::TestRecorder;
  14. using ra::mp::int_list, ra::int_c, ra::mp::print_int_list, ra::mp::ref;
  15. using int2 = ra::Small<int, 2>;
  16. int main()
  17. {
  18. TestRecorder tr;
  19. tr.section("transpose(ra::Small)");
  20. {
  21. ra::Small<double, 2, 3> const a(ra::_0 + 10*ra::_1);
  22. tr.info("<0 1>").test_eq(a, ra::transpose<0, 1>(a));
  23. tr.info("<1 0>").test_eq(ra::Small<double, 3, 2>(10*ra::_0 + ra::_1), ra::transpose<1, 0>(a));
  24. tr.info("<0 0>").test_eq(ra::Small<double, 2> {0, 11}, ra::transpose<0, 0>(a));
  25. ra::Small<double, 2, 3> b(ra::_0 + 10*ra::_1);
  26. tr.info("<0 1>").test_eq(a, ra::transpose<0, 1>(a));
  27. tr.info("<1 0>").test_eq(ra::Small<double, 3, 2>(10*ra::_0 + ra::_1), ra::transpose<1, 0>(a));
  28. ra::transpose<0, 0>(b) = {7, 9};
  29. tr.info("<0 0>").test_eq(ra::Small<double, 2, 3>{7, 10, 20, 1, 9, 21}, b);
  30. ra::Small<double> x {99};
  31. auto xt = transpose<>(x);
  32. tr.info("<> rank").test_eq(0, xt.rank());
  33. tr.info("<>").test_eq(99, xt);
  34. ra::Small<double, 3, 3> x3 = ra::_0 - ra::_1;
  35. ra::Small<double, 3, 3> y3 = transpose<1, 0>(x3);
  36. tr.info("transpose copy").test_eq(y3, ra::_1 - ra::_0);
  37. x3() = transpose<1, 0>(y3());
  38. tr.info("transpose copy").test_eq(x3, ra::_0 - ra::_1);
  39. }
  40. tr.section("sizeof");
  41. {
  42. // These all static, but show the numbers if there's an error.
  43. tr.info("sizeof(ra::Small<double>)")
  44. .test_eq(sizeof(double), sizeof(ra::Small<double>));
  45. tr.info("sizeof(ra::Small<double, 0>)")
  46. .test(sizeof(double)==sizeof(ra::Small<double, 0>) || 0==sizeof(ra::Small<double, 0>)); // don't rely on either.
  47. tr.info("sizeof(ra::Small<double, 1>)")
  48. .test_eq(sizeof(double), sizeof(ra::Small<double, 1>));
  49. tr.info("sizeof(ra::Small<double, 2>)")
  50. .test_eq(2*sizeof(double), sizeof(ra::Small<double, 2>));
  51. }
  52. tr.section("internal fields");
  53. {
  54. {
  55. using A = ra::Small<double, 10, 10>;
  56. alignas(A) double storage[sizeof(A)/sizeof(double)];
  57. A * a = new (&storage) A();
  58. std::fill(a->data(), a->data()+100, 0.);
  59. storage[99] = 1.3;
  60. std::cout << (*a) << std::endl;
  61. tr.test_eq(1.3, a->data()[99]);
  62. tr.test_eq(1.3, (*a)(9, 9));
  63. }
  64. {
  65. ra::Small<double, 2, 3> a {1, 2, 3, 4, 5, 6};
  66. tr.test_eq(2*3*sizeof(double), sizeof(a));
  67. tr.test_eq(1, a.data()[0]);
  68. }
  69. }
  70. tr.section("top level generics");
  71. {
  72. ra::Small<double, 2, 3> a {1, 2, 3, 4, 5, 6};
  73. tr.test_eq(ra::Small<ra::dim_t, 2> {2, 3}, shape(a));
  74. tr.test_eq(3u, ra::size(std::array<double, 3>()));
  75. }
  76. tr.section("static step computation");
  77. {
  78. using d = int_list<3, 4, 5>;
  79. using s = ra::default_steps<d>;
  80. tr.info("step 0").test_eq(20, ref<s, 0>::value);
  81. tr.info("step 1").test_eq(5, ref<s, 1>::value);
  82. tr.info("step 2").test_eq(1, ref<s, 2>::value);
  83. }
  84. tr.section("subscripts");
  85. {
  86. tr.section("with scalar indices");
  87. {
  88. ra::Small<double, 3, 2> s { 1, 4, 2, 5, 3, 6 };
  89. auto s0 = s();
  90. double check0[6] = { 1, 4, 2, 5, 3, 6 };
  91. tr.test(std::equal(s0.begin(), s0.end(), check0));
  92. auto s1 = s(1);
  93. double check1[3] = { 2, 5 };
  94. cout << "s1: " << s1(0) << ", " << s1(1) << endl;
  95. tr.test(s1(0)==2 && s1(1)==5);
  96. tr.test(std::equal(s1.begin(), s1.end(), check1));
  97. tr.test_eq(5, s(1, 1));
  98. }
  99. tr.section("using ViewSmall as rvalue");
  100. {
  101. ra::Small<double, 3, 2> s { 1, 4, 2, 5, 3, 6 };
  102. // use as rvalue.
  103. s(0) = { 3, 2 };
  104. s(1) = { 5, 4 };
  105. s(2) = { 7, 6 };
  106. cout << s << endl;
  107. tr.test_eq(ra::Small<double, 3, 2> { 3, 2, 5, 4, 7, 6 }, s);
  108. ra::Small<double, 3, 2> z = s;
  109. z *= -1;
  110. // check that ViewSmall = ViewSmall copies contents, just as View = View.
  111. s(0) = z(2);
  112. s(1) = z(1);
  113. s(2) = z(0);
  114. tr.test_eq(ra::Small<double, 3, 2> { -3, -2, -5, -4, -7, -6 }, z);
  115. tr.test_eq(ra::Small<double, 3, 2> { -7, -6, -5, -4, -3, -2 }, s);
  116. }
  117. tr.section("with tuples");
  118. {
  119. ra::Small<double, 3, 2> s { 1, 4, 2, 5, 3, 6 };
  120. ra::Small<int, 2> i2 { 1, 1 };
  121. ra::Small<int, 1> i1 { 1 };
  122. ra::Small<int, 0> i0 { };
  123. double check2[1] = { 5 };
  124. double check1[2] = { 2, 5 };
  125. double check0[6] = { 1, 4, 2, 5, 3, 6 };
  126. auto k2 = s.at(i2);
  127. tr.test_eq(0, ra::rank(k2));
  128. tr.test_eq(check2[0], k2);
  129. auto k1 = s.at(i1).begin(); tr.test(std::equal(check1, check1+2, k1));
  130. auto k0 = s.at(i0).begin(); tr.test(std::equal(check0, check0+6, k0));
  131. }
  132. tr.section("with rank 1 subscripts");
  133. {
  134. ra::Small<double, 3, 2> s { 1, 4, 2, 5, 3, 6 };
  135. tr.test_eq(ra::Small<int, 2> { 1, 4 }, s(0));
  136. tr.test_eq(ra::Small<int, 2> { 2, 5 }, s(1));
  137. tr.test_eq(ra::Small<int, 2> { 3, 6 }, s(2));
  138. tr.test_eq(ra::Small<int, 3> { 1, 2, 3 }, s(ra::all, 0));
  139. tr.test_eq(ra::Small<int, 3> { 4, 5, 6 }, s(ra::all, 1));
  140. tr.test_eq(1, s(ra::all, 1).rank());
  141. // check STL iterator.
  142. {
  143. int check0[] = { 1, 2, 3 };
  144. int check1[] = { 4, 5, 6 };
  145. tr.test(std::ranges::equal(check0, check0+3, s(ra::all, 0).begin(), s(ra::all, 0).end()));
  146. tr.test(std::ranges::equal(check1, check1+3, s(ra::all, 1).begin(), s(ra::all, 1).end()));
  147. tr.test(std::ranges::equal(s(ra::all, 0).begin(), s(ra::all, 0).end(), check0, check0+3));
  148. tr.test(std::ranges::equal(s(ra::all, 1).begin(), s(ra::all, 1).end(), check1, check1+3));
  149. }
  150. tr.test_eq(1, s(ra::all, 0)[0]);
  151. tr.test_eq(2, s(ra::all, 0)[1]);
  152. tr.test_eq(3, s(ra::all, 0)[2]);
  153. tr.test_eq(4, s(ra::all, 1)(0));
  154. tr.test_eq(5, s(ra::all, 1)(1));
  155. tr.test_eq(6, s(ra::all, 1)(2));
  156. using I0 = ra::Small<ra::dim_t, 1>;
  157. tr.test_eq(1, s(ra::all, 0).at(I0 {0}));
  158. tr.test_eq(2, s(ra::all, 0).at(I0 {1}));
  159. tr.test_eq(3, s(ra::all, 0).at(I0 {2}));
  160. tr.test_eq(4, s(ra::all, 1).at(I0 {0}));
  161. tr.test_eq(5, s(ra::all, 1).at(I0 {1}));
  162. tr.test_eq(6, s(ra::all, 1).at(I0 {2}));
  163. }
  164. tr.section("with rank 1 subscripts, result rank > 1");
  165. {
  166. ra::Small<double, 3, 2, 2> s = 100*ra::_0 + 10*ra::_1 + 1*ra::_2;
  167. cout << s << endl;
  168. auto t = s(ra::all, 1, ra::all);
  169. tr.test_eq(2, t.rank());
  170. tr.test_eq(3, t.len(0));
  171. tr.test_eq(2, t.len(1));
  172. tr.test_eq(10, t(0, 0));
  173. tr.test_eq(11, t(0, 1));
  174. tr.test_eq(110, t(1, 0));
  175. tr.test_eq(111, t(1, 1));
  176. tr.test_eq(210, t(2, 0));
  177. tr.test_eq(211, t(2, 1));
  178. tr.test_eq(ra::Small<int, 3, 2> { 10, 11, 110, 111, 210, 211 }, t);
  179. tr.test_eq(4, t.step(0));
  180. tr.test_eq(1, t.step(1));
  181. // check STL iterator.
  182. {
  183. int check[] = { 10, 11, 110, 111, 210, 211 };
  184. tr.test(std::ranges::equal(t.begin(), t.end(), check, check+6));
  185. tr.test(std::ranges::equal(check, check+6, t.begin(), t.end()));
  186. }
  187. }
  188. }
  189. tr.section("Small<> can be constexpr");
  190. {
  191. constexpr ra::Small<int, 2, 2> a = {1, 2, 3, 4};
  192. using Va = int_c<int(a(1, 0))>;
  193. tr.test_eq(3, Va::value);
  194. using Vc = int_c<sum(a)>; // constexpr reduction!
  195. tr.test_eq(10, Vc::value);
  196. constexpr ra::Small<int> b = { 9 }; // needs std::fill
  197. using Vb = int_c<int(b)>;
  198. tr.test_eq(9, Vb::value);
  199. }
  200. tr.section("custom steps. List init is row-major regardless.");
  201. {
  202. auto test = [&tr](auto && a)
  203. {
  204. tr.test_eq(1, a(0, 0));
  205. tr.test_eq(2, a(0, 1));
  206. tr.test_eq(3, a(0, 2));
  207. tr.test_eq(4, a(1, 0));
  208. tr.test_eq(5, a(1, 1));
  209. tr.test_eq(6, a(1, 2));
  210. tr.test_eq(1, a(0)(0));
  211. tr.test_eq(2, a(0)(1));
  212. tr.test_eq(3, a(0)(2));
  213. tr.test_eq(4, a(1)(0));
  214. tr.test_eq(5, a(1)(1));
  215. tr.test_eq(6, a(1)(2));
  216. using A = std::decay_t<decltype(a(0))>;
  217. using dim1 = std::array<ra::dim_t, 1>;
  218. auto lens = ra::mp::tuple2array<ra::dim_t, typename A::lens>();
  219. auto steps = ra::mp::tuple2array<ra::dim_t, typename A::steps>();
  220. tr.test_eq(dim1 {3}, ra::start(lens));
  221. tr.test_eq(dim1 {2}, ra::start(steps));
  222. };
  223. ra::SmallArray<double, int_list<2, 3>, int_list<1, 2>> a { 1, 2, 3, 4, 5, 6 };
  224. ra::SmallArray<double, int_list<2, 3>, int_list<1, 2>> b { {1, 2, 3}, {4, 5, 6} };
  225. test(a);
  226. test(b);
  227. }
  228. tr.section("SmallArray converted to ViewSmall");
  229. {
  230. ra::Small<double, 2, 3> a { 1, 2, 3, 4, 5, 6 };
  231. ra::ViewSmall<double, int_list<2, 3>, int_list<3, 1>> b = a();
  232. tr.test_eq(a, b);
  233. // non-default steps (fortran / column major order).
  234. ra::SmallArray<double, int_list<2, 3>, int_list<1, 2>> ax { 1, 2, 3, 4, 5, 6 };
  235. ra::ViewSmall<double, int_list<2, 3>, int_list<1, 2>> bx = ax();
  236. tr.test_eq(a, ax);
  237. tr.test_eq(a, bx);
  238. // check iterators.
  239. tr.test(std::ranges::equal(a.begin(), a.end(), ax.begin(), ax.end()));
  240. tr.test(std::ranges::equal(ax.begin(), ax.end(), a.begin(), a.end()));
  241. tr.test(std::ranges::equal(b.begin(), b.end(), bx.begin(), bx.end()));
  242. tr.test(std::ranges::equal(bx.begin(), bx.end(), b.begin(), b.end()));
  243. // check memory order.
  244. double fcheck[6] = { 1, 4, 2, 5, 3, 6 };
  245. tr.test(std::equal(fcheck, fcheck+6, ax.data()));
  246. tr.test(std::equal(fcheck, fcheck+6, bx.data()));
  247. // views work as views.
  248. bx = 77.;
  249. tr.test_eq(77., ax);
  250. b = 99.;
  251. tr.test_eq(99., a);
  252. }
  253. tr.section("expr with Small, rank 1");
  254. {
  255. ra::Small<double, 3> a { 1, 4, 2 };
  256. tr.test_eq(3, a.iter().len(0));
  257. #define TEST(plier) \
  258. { \
  259. double s = 0; \
  260. plier(ra::expr([&s](double & a) { s += a; }, a.iter())); \
  261. tr.test_eq(7, s); \
  262. }
  263. TEST(ply_ravel);
  264. TEST(ply);
  265. #undef TEST
  266. }
  267. tr.section("expr with Small, rank 2");
  268. {
  269. ra::Small<double, 3, 2> a { 1, 4, 2, 5, 3, 6 };
  270. tr.test_eq(3, a.iter().len(0));
  271. tr.test_eq(2, a.iter().len(1));
  272. #define TEST(plier) \
  273. { \
  274. double s = 0; \
  275. plier(ra::expr([&s](double & a) { s += a; }, a.iter())); \
  276. tr.test_eq(21, s); \
  277. }
  278. TEST(ply_ravel);
  279. TEST(ply);
  280. #undef TEST
  281. #define TEST(plier) \
  282. { \
  283. ra::Small<double, 3, 2> b; \
  284. plier(ra::expr([](double & a, double & b) { b = -a; }, a.iter(), b.iter())); \
  285. tr.test_eq(-1, b(0, 0)); \
  286. tr.test_eq(-4, b(0, 1)); \
  287. tr.test_eq(-2, b(1, 0)); \
  288. tr.test_eq(-5, b(1, 1)); \
  289. tr.test_eq(-3, b(2, 0)); \
  290. tr.test_eq(-6, b(2, 1)); \
  291. }
  292. TEST(ply_ravel);
  293. TEST(ply);
  294. #undef TEST
  295. }
  296. tr.section("Small as value type in var-size array");
  297. {
  298. {
  299. // This pain with rank 0 arrays and ra::scalar can be avoided with ply; see e.g. grid_interp_n() in src/grid.cc.
  300. ra::Unique<ra::Small<double, 2>, 1> b({4}, ra::scalar(ra::Small<double, 2> { 3., 1. }));
  301. tr.test_eq(3., b(0)(0));
  302. tr.test_eq(1., b(0)(1));
  303. // if () returns rank 0 instead of scalar, otherwise ct error.
  304. // b(1) = ra::scalar(ra::Small<double, 2> { 7., 9. });
  305. // cout << b << endl;
  306. // if () returns scalar instead of rank 0, otherwise bug. (This is what happens).
  307. b(1) = ra::Small<double, 2> { 7., 9. };
  308. tr.test_eq(3., b(0)(0));
  309. tr.test_eq(1., b(0)(1));
  310. tr.test_eq(7., b(1)(0));
  311. tr.test_eq(9., b(1)(1));
  312. }
  313. {
  314. ra::Unique<double, 1> b({2}, { 3., 1. });
  315. tr.test_eq(3., b(0));
  316. tr.test_eq(1., b(1));
  317. b = ra::Small<double, 2> { 7., 9. };
  318. cout << b << endl;
  319. tr.test_eq(7., b(0));
  320. tr.test_eq(9., b(1));
  321. }
  322. {
  323. ra::Unique<double, 2> b({2, 2}, { 3., 1., 3., 1. });
  324. b(1) = ra::Small<double, 2> { 7., 9. };
  325. tr.test_eq(3., b(0, 0));
  326. tr.test_eq(1., b(0, 1));
  327. tr.test_eq(7., b(1, 0));
  328. tr.test_eq(9., b(1, 1));
  329. }
  330. {
  331. ra::Unique<ra::Small<double, 2>, 0> b(ra::scalar(ra::Small<double, 2>{3., 1.}));
  332. b = ra::scalar(ra::Small<double, 2> { 7., 9. });
  333. tr.test_eq(7., b()(0));
  334. tr.test_eq(9., b()(1));
  335. }
  336. {
  337. ra::Unique<ra::Small<double, 2>, 1> b({4}, ra::scalar(ra::Small<double, 2> { 3., 1. }));
  338. ra::Small<double, 2> u = b(1);
  339. tr.test_eq(3, u[0]);
  340. tr.test_eq(1, u[1]);
  341. ra::Small<double, 2> v(b(1));
  342. tr.test_eq(3, v[0]);
  343. tr.test_eq(1, v[1]);
  344. }
  345. }
  346. tr.section("transpose");
  347. {
  348. ra::Small<double, 2, 3> a { 1, 2, 3, 4, 5, 6 };
  349. tr.test_eq(ra::Small<double, 3, 2> { 1, 4, 2, 5, 3, 6 }, transpose<1, 0>(a));
  350. ra::transpose<1, 0>(a) = { 1, 2, 3, 4, 5, 6 };
  351. tr.test_eq(ra::Small<double, 2, 3> { 1, 3, 5, 2, 4, 6 }, a);
  352. }
  353. tr.section("diag");
  354. {
  355. ra::Small<double, 3, 3> a = ra::_0*3 + ra::_1;
  356. tr.test_eq(ra::Small<double, 3> { 0, 4, 8 }, diag(a));
  357. diag(a) = { 11, 22, 33 };
  358. tr.test_eq(ra::Small<double, 3, 3> { 11, 1, 2, 3, 22, 5, 6, 7, 33 }, a);
  359. }
  360. tr.section(".back()");
  361. {
  362. ra::Small<double, 3> a = ra::_0*3;
  363. tr.test_eq(0, a[0]);
  364. tr.test_eq(3, a[1]);
  365. tr.test_eq(6, a[2]);
  366. tr.test_eq(6, a.back());
  367. }
  368. tr.section(".back() is last element not last item");
  369. {
  370. ra::Small<int2> b(ra::scalar(int2 {1, 3})); // cf [ma116]
  371. tr.test_eq(int2 {1, 3}, b.back());
  372. }
  373. // TODO Replace with uniform subscripting (ra::iota).
  374. tr.section("compile time subscripting of ra::Small (as)");
  375. {
  376. auto test_as = [&tr](auto && a, auto && b)
  377. {
  378. tr.test_eq(2, b.size());
  379. tr.test_eq(1, b[0]);
  380. tr.test_eq(2, b[1]);
  381. b = { 7, 8 };
  382. tr.test_eq(7, a[0]);
  383. tr.test_eq(8, a[1]);
  384. tr.test_eq(3, a[2]);
  385. };
  386. {
  387. ra::Small<double, 3> a = { 1, 2, 3 };
  388. test_as(a, a.as<2>());
  389. ra::Small<double, 6> b = { 1, 99, 2, 99, 3, 99 };
  390. ra::ViewSmall<double, int_list<3>, int_list<2>> c(b.data()); // TODO no syntax yet.
  391. test_as(c, c.as<2>());
  392. }
  393. auto test_fra = [&tr](auto && a, auto && b)
  394. {
  395. tr.test_eq(2, b.size());
  396. tr.test_eq(2, b[0]);
  397. tr.test_eq(3, b[1]);
  398. b = { 7, 8 };
  399. tr.test_eq(1, a[0]);
  400. tr.test_eq(7, a[1]);
  401. tr.test_eq(8, a[2]);
  402. };
  403. {
  404. ra::Small<double, 3> a = { 1, 2, 3 };
  405. test_fra(a, a.as<2, 1>());
  406. ra::Small<double, 6> b = { 1, 99, 2, 99, 3, 99 };
  407. ra::ViewSmall<double, int_list<3>, int_list<2>> c(b.data()); // TODO no syntax yet.
  408. test_fra(c, c.as<2, 1>());
  409. }
  410. auto test_fra_rank_2 = [&tr](auto && a, auto && b)
  411. {
  412. tr.test_eq(2, b.len(0));
  413. tr.test_eq(2, b.len(1));
  414. tr.test_eq(ra::Small<double, 2, 2> { 3, 4, 5, 6 }, b);
  415. b = ra::Small<double, 2, 2> { 13, 14, 15, 16 };
  416. tr.test_eq(ra::Small<double, 3, 2> { 1, 2, 13, 14, 15, 16 }, a);
  417. };
  418. {
  419. ra::Small<double, 3, 2> a = { 1, 2, 3, 4, 5, 6 };
  420. test_fra_rank_2(a, a.as<2, 1>());
  421. ra::Small<double, 6, 2> b = { 1, 2, 99, 99, 3, 4, 99, 99, 5, 6, 99, 99 };
  422. ra::ViewSmall<double, int_list<3, 2>, int_list<4, 1>> c(b.data()); // TODO no syntax yet.
  423. test_fra_rank_2(c, c.as<2, 1>());
  424. }
  425. }
  426. tr.section("cat");
  427. {
  428. tr.test_eq(ra::Small<int, 4> {1, 2, 3, 4}, cat(ra::Small<int, 3> {1, 2, 3}, 4));
  429. tr.test_eq(ra::Small<int, 4> {4, 1, 2, 3}, cat(4, ra::Small<int, 3> {1, 2, 3}));
  430. tr.test_eq(ra::Small<int, 5> {1, 2, 3, 4, 5}, cat(ra::Small<int, 2> {1, 2}, ra::Small<int, 3> {3, 4, 5}));
  431. }
  432. tr.section("a demo on rank1of1 vs rank2");
  433. {
  434. // by prefix matching, first dim is 2 for both so they get matched. Then {1 2}
  435. // (a 'scalar') gets matched to 10 & 20 in succesion. This used to be forbidden in Small::Small(X && x), but now I value consistency more.
  436. ra::Small<ra::Small<double, 2>, 2> a = { {1, 2}, {3, 4} };
  437. ra::Small<double, 2, 2> b = { 10, 20, 30, 40 };
  438. cout << "a: " << a << endl;
  439. cout << "b: " << b << endl;
  440. // a = b; // TODO Check that this static fails
  441. cout << "a = b, a: " << a << endl;
  442. }
  443. // ASSIGNOPS for SmallBase.iter()
  444. {
  445. ra::Small<int, 3> s {1, 2, 3};
  446. s.iter() += 9;
  447. tr.test_eq(ra::start({10, 11, 12}), s);
  448. }
  449. tr.section("multidimensional []");
  450. {
  451. ra::Small<int, 3, 2, 4> a = ra::_0 + ra::_1 - ra::_2;
  452. tr.test_eq(a(ra::all, 0), a[ra::all, 0]);
  453. }
  454. tr.section("deduction guides");
  455. {
  456. ra::SmallArray a {1, 2, 3}; // FIXME the deduction guide can't work for ra::Small
  457. tr.test_eq(ra::start({1, 2, 3}), a);
  458. }
  459. return tr.summary();
  460. }