fn_max.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. // Copyright 2011-2017 Ryan Curtin (http://www.ratml.org/)
  2. // Copyright 2017 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. #include <armadillo>
  16. #include "catch.hpp"
  17. using namespace arma;
  18. TEST_CASE("fn_max_subview_test")
  19. {
  20. // We will assume subview.at() works and returns points within the bounds of
  21. // the matrix, so we just have to ensure the results are the same as
  22. // Mat.max()...
  23. for (size_t r = 50; r < 150; ++r)
  24. {
  25. mat x;
  26. x.randu(r, r);
  27. uword x_max;
  28. uword x_subview_max1;
  29. uword x_subview_max2;
  30. uword x_subview_max3;
  31. const double mval = x.max(x_max);
  32. const double mval1 = x.submat(0, 0, r - 1, r - 1).max(x_subview_max1);
  33. const double mval2 = x.cols(0, r - 1).max(x_subview_max2);
  34. const double mval3 = x.rows(0, r - 1).max(x_subview_max3);
  35. REQUIRE( x_max == x_subview_max1 );
  36. REQUIRE( x_max == x_subview_max2 );
  37. REQUIRE( x_max == x_subview_max3 );
  38. REQUIRE( mval == Approx(mval1) );
  39. REQUIRE( mval == Approx(mval2) );
  40. REQUIRE( mval == Approx(mval3) );
  41. }
  42. }
  43. TEST_CASE("fn_max_subview_col_test")
  44. {
  45. for (size_t r = 10; r < 50; ++r)
  46. {
  47. vec x;
  48. x.randu(r);
  49. uword x_max;
  50. uword x_subview_max1;
  51. uword x_subview_max2;
  52. const double mval = x.max(x_max);
  53. const double mval1 = x.submat(0, 0, r - 1, 0).max(x_subview_max1);
  54. const double mval2 = x.rows(0, r - 1).max(x_subview_max2);
  55. REQUIRE( x_max == x_subview_max1 );
  56. REQUIRE( x_max == x_subview_max2 );
  57. REQUIRE( mval == Approx(mval1) );
  58. REQUIRE( mval == Approx(mval2) );
  59. }
  60. }
  61. TEST_CASE("fn_max_subview_row_test")
  62. {
  63. for (size_t r = 10; r < 50; ++r)
  64. {
  65. rowvec x;
  66. x.randu(r);
  67. uword x_max;
  68. uword x_subview_max1;
  69. uword x_subview_max2;
  70. const double mval = x.max(x_max);
  71. const double mval1 = x.submat(0, 0, 0, r - 1).max(x_subview_max1);
  72. const double mval2 = x.cols(0, r - 1).max(x_subview_max2);
  73. REQUIRE( x_max == x_subview_max1 );
  74. REQUIRE( x_max == x_subview_max2 );
  75. REQUIRE( mval == Approx(mval1) );
  76. REQUIRE( mval == Approx(mval2) );
  77. }
  78. }
  79. TEST_CASE("fn_max_incomplete_subview_test")
  80. {
  81. for (size_t r = 50; r < 150; ++r)
  82. {
  83. mat x;
  84. x.randu(r, r);
  85. uword x_max;
  86. uword x_subview_max1;
  87. uword x_subview_max2;
  88. uword x_subview_max3;
  89. const double mval = x.max(x_max);
  90. const double mval1 = x.submat(1, 1, r - 2, r - 2).max(x_subview_max1);
  91. const double mval2 = x.cols(1, r - 2).max(x_subview_max2);
  92. const double mval3 = x.rows(1, r - 2).max(x_subview_max3);
  93. uword row, col;
  94. x.max(row, col);
  95. if (row != 0 && row != r - 1 && col != 0 && col != r - 1)
  96. {
  97. uword srow, scol;
  98. srow = x_subview_max1 % (r - 2);
  99. scol = x_subview_max1 / (r - 2);
  100. REQUIRE( x_max == (srow + 1) + r * (scol + 1) );
  101. REQUIRE( x_max == x_subview_max2 + r );
  102. srow = x_subview_max3 % (r - 2);
  103. scol = x_subview_max3 / (r - 2);
  104. REQUIRE( x_max == (srow + 1) + r * scol );
  105. REQUIRE( mval == Approx(mval1) );
  106. REQUIRE( mval == Approx(mval2) );
  107. REQUIRE( mval == Approx(mval3) );
  108. }
  109. }
  110. }
  111. TEST_CASE("fn_max_incomplete_subview_col_test")
  112. {
  113. for (size_t r = 10; r < 50; ++r)
  114. {
  115. vec x;
  116. x.randu(r);
  117. uword x_max;
  118. uword x_subview_max1;
  119. uword x_subview_max2;
  120. const double mval = x.max(x_max);
  121. const double mval1 = x.submat(1, 0, r - 2, 0).max(x_subview_max1);
  122. const double mval2 = x.rows(1, r - 2).max(x_subview_max2);
  123. if (x_max != 0 && x_max != r - 1)
  124. {
  125. REQUIRE( x_max == x_subview_max1 + 1 );
  126. REQUIRE( x_max == x_subview_max2 + 1 );
  127. REQUIRE( mval == Approx(mval1) );
  128. REQUIRE( mval == Approx(mval2) );
  129. }
  130. }
  131. }
  132. TEST_CASE("fn_max_cx_subview_row_test")
  133. {
  134. for (size_t r = 10; r < 50; ++r)
  135. {
  136. cx_rowvec x;
  137. x.randu(r);
  138. uword x_max;
  139. uword x_subview_max1;
  140. uword x_subview_max2;
  141. const std::complex<double> mval = x.max(x_max);
  142. const std::complex<double> mval1 = x.submat(0, 0, 0, r - 1).max(x_subview_max1);
  143. const std::complex<double> mval2 = x.cols(0, r - 1).max(x_subview_max2);
  144. REQUIRE( x_max == x_subview_max1 );
  145. REQUIRE( x_max == x_subview_max2 );
  146. REQUIRE( mval.real() == Approx(mval1.real()) );
  147. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  148. REQUIRE( mval.real() == Approx(mval2.real()) );
  149. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  150. }
  151. }
  152. TEST_CASE("fn_max_cx_incomplete_subview_test")
  153. {
  154. for (size_t r = 50; r < 150; ++r)
  155. {
  156. cx_mat x;
  157. x.randu(r, r);
  158. uword x_max;
  159. uword x_subview_max1;
  160. uword x_subview_max2;
  161. uword x_subview_max3;
  162. const std::complex<double> mval = x.max(x_max);
  163. const std::complex<double> mval1 = x.submat(1, 1, r - 2, r - 2).max(x_subview_max1);
  164. const std::complex<double> mval2 = x.cols(1, r - 2).max(x_subview_max2);
  165. const std::complex<double> mval3 = x.rows(1, r - 2).max(x_subview_max3);
  166. uword row, col;
  167. x.max(row, col);
  168. if (row != 0 && row != r - 1 && col != 0 && col != r - 1)
  169. {
  170. uword srow, scol;
  171. srow = x_subview_max1 % (r - 2);
  172. scol = x_subview_max1 / (r - 2);
  173. REQUIRE( x_max == (srow + 1) + r * (scol + 1) );
  174. REQUIRE( x_max == x_subview_max2 + r );
  175. srow = x_subview_max3 % (r - 2);
  176. scol = x_subview_max3 / (r - 2);
  177. REQUIRE( x_max == (srow + 1) + r * scol );
  178. REQUIRE( mval.real() == Approx(mval1.real()) );
  179. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  180. REQUIRE( mval.real() == Approx(mval2.real()) );
  181. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  182. REQUIRE( mval.real() == Approx(mval3.real()) );
  183. REQUIRE( mval.imag() == Approx(mval3.imag()) );
  184. }
  185. }
  186. }
  187. TEST_CASE("fn_max_cx_incomplete_subview_col_test")
  188. {
  189. for (size_t r = 10; r < 50; ++r)
  190. {
  191. cx_vec x;
  192. x.randu(r);
  193. uword x_max;
  194. uword x_subview_max1;
  195. uword x_subview_max2;
  196. const std::complex<double> mval = x.max(x_max);
  197. const std::complex<double> mval1 = x.submat(1, 0, r - 2, 0).max(x_subview_max1);
  198. const std::complex<double> mval2 = x.rows(1, r - 2).max(x_subview_max2);
  199. if (x_max != 0 && x_max != r - 1)
  200. {
  201. REQUIRE( x_max == x_subview_max1 + 1 );
  202. REQUIRE( x_max == x_subview_max2 + 1 );
  203. REQUIRE( mval.real() == Approx(mval1.real()) );
  204. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  205. REQUIRE( mval.real() == Approx(mval2.real()) );
  206. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  207. }
  208. }
  209. }
  210. TEST_CASE("fn_max_cx_incomplete_subview_row_test")
  211. {
  212. for (size_t r = 10; r < 50; ++r)
  213. {
  214. cx_rowvec x;
  215. x.randu(r);
  216. uword x_max;
  217. uword x_subview_max1;
  218. uword x_subview_max2;
  219. const std::complex<double> mval = x.max(x_max);
  220. const std::complex<double> mval1 = x.submat(0, 1, 0, r - 2).max(x_subview_max1);
  221. const std::complex<double> mval2 = x.cols(1, r - 2).max(x_subview_max2);
  222. if (x_max != 0 && x_max != r - 1)
  223. {
  224. REQUIRE( x_max == x_subview_max1 + 1 );
  225. REQUIRE( x_max == x_subview_max2 + 1 );
  226. REQUIRE( mval.real() == Approx(mval1.real()) );
  227. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  228. REQUIRE( mval.real() == Approx(mval2.real()) );
  229. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  230. }
  231. }
  232. }
  233. TEST_CASE("fn_max_weird_operation_test")
  234. {
  235. mat a(10, 10);
  236. mat b(25, 10);
  237. a.randn();
  238. b.randn();
  239. mat output = a * b.t();
  240. uword real_max;
  241. uword operation_max;
  242. const double mval = output.max(real_max);
  243. const double other_mval = (a * b.t()).max(operation_max);
  244. REQUIRE( real_max == operation_max );
  245. REQUIRE( mval == Approx(other_mval) );
  246. }
  247. TEST_CASE("fn_max_weird_sparse_operation_test")
  248. {
  249. sp_mat a(10, 10);
  250. sp_mat b(25, 10);
  251. a.sprandn(10, 10, 0.3);
  252. b.sprandn(25, 10, 0.3);
  253. sp_mat output = a * b.t();
  254. uword real_max;
  255. uword operation_max;
  256. const double mval = output.max(real_max);
  257. const double other_mval = (a * b.t()).max(operation_max);
  258. REQUIRE( real_max == operation_max );
  259. REQUIRE( mval == Approx(other_mval) );
  260. }
  261. TEST_CASE("fn_max_spsubview_test")
  262. {
  263. // We will assume subview.at() works and returns points within the bounds of
  264. // the matrix, so we just have to ensure the results are the same as
  265. // Mat.max()...
  266. for (size_t r = 50; r < 150; ++r)
  267. {
  268. sp_mat x;
  269. x.sprandn(r, r, 0.3);
  270. uword x_max;
  271. uword x_subview_max1;
  272. uword x_subview_max2;
  273. uword x_subview_max3;
  274. const double mval = x.max(x_max);
  275. const double mval1 = x.submat(0, 0, r - 1, r - 1).max(x_subview_max1);
  276. const double mval2 = x.cols(0, r - 1).max(x_subview_max2);
  277. const double mval3 = x.rows(0, r - 1).max(x_subview_max3);
  278. if (mval != 0.0)
  279. {
  280. REQUIRE( x_max == x_subview_max1 );
  281. REQUIRE( x_max == x_subview_max2 );
  282. REQUIRE( x_max == x_subview_max3 );
  283. REQUIRE( mval == Approx(mval1) );
  284. REQUIRE( mval == Approx(mval2) );
  285. REQUIRE( mval == Approx(mval3) );
  286. }
  287. }
  288. }
  289. TEST_CASE("fn_max_spsubview_col_test")
  290. {
  291. for (size_t r = 10; r < 50; ++r)
  292. {
  293. sp_vec x;
  294. x.sprandn(r, 1, 0.3);
  295. uword x_max;
  296. uword x_subview_max1;
  297. uword x_subview_max2;
  298. const double mval = x.max(x_max);
  299. const double mval1 = x.submat(0, 0, r - 1, 0).max(x_subview_max1);
  300. const double mval2 = x.rows(0, r - 1).max(x_subview_max2);
  301. if (mval != 0.0)
  302. {
  303. REQUIRE( x_max == x_subview_max1 );
  304. REQUIRE( x_max == x_subview_max2 );
  305. REQUIRE( mval == Approx(mval1) );
  306. REQUIRE( mval == Approx(mval2) );
  307. }
  308. }
  309. }
  310. TEST_CASE("fn_max_spsubview_row_test")
  311. {
  312. for (size_t r = 10; r < 50; ++r)
  313. {
  314. sp_rowvec x;
  315. x.sprandn(1, r, 0.3);
  316. uword x_max;
  317. uword x_subview_max1;
  318. uword x_subview_max2;
  319. const double mval = x.max(x_max);
  320. const double mval1 = x.submat(0, 0, 0, r - 1).max(x_subview_max1);
  321. const double mval2 = x.cols(0, r - 1).max(x_subview_max2);
  322. if (mval != 0.0)
  323. {
  324. REQUIRE( x_max == x_subview_max1 );
  325. REQUIRE( x_max == x_subview_max2 );
  326. REQUIRE( mval == Approx(mval1) );
  327. REQUIRE( mval == Approx(mval2) );
  328. }
  329. }
  330. }
  331. TEST_CASE("fn_max_spincompletesubview_test")
  332. {
  333. for (size_t r = 50; r < 150; ++r)
  334. {
  335. sp_mat x;
  336. x.sprandn(r, r, 0.3);
  337. uword x_max;
  338. uword x_subview_max1;
  339. uword x_subview_max2;
  340. uword x_subview_max3;
  341. const double mval = x.max(x_max);
  342. const double mval1 = x.submat(1, 1, r - 2, r - 2).max(x_subview_max1);
  343. const double mval2 = x.cols(1, r - 2).max(x_subview_max2);
  344. const double mval3 = x.rows(1, r - 2).max(x_subview_max3);
  345. uword row, col;
  346. x.max(row, col);
  347. if (row != 0 && row != r - 1 && col != 0 && col != r - 1 && mval != 0.0)
  348. {
  349. uword srow, scol;
  350. srow = x_subview_max1 % (r - 2);
  351. scol = x_subview_max1 / (r - 2);
  352. REQUIRE( x_max == (srow + 1) + r * (scol + 1) );
  353. REQUIRE( x_max == x_subview_max2 + r );
  354. srow = x_subview_max3 % (r - 2);
  355. scol = x_subview_max3 / (r - 2);
  356. REQUIRE( x_max == (srow + 1) + r * scol );
  357. REQUIRE( mval == Approx(mval1) );
  358. REQUIRE( mval == Approx(mval2) );
  359. REQUIRE( mval == Approx(mval3) );
  360. }
  361. }
  362. }
  363. TEST_CASE("fn_max_spincompletesubview_col_test")
  364. {
  365. for (size_t r = 10; r < 50; ++r)
  366. {
  367. sp_vec x;
  368. x.sprandu(r, 1, 0.3);
  369. uword x_max;
  370. uword x_subview_max1;
  371. uword x_subview_max2;
  372. const double mval = x.max(x_max);
  373. const double mval1 = x.submat(1, 0, r - 2, 0).max(x_subview_max1);
  374. const double mval2 = x.rows(1, r - 2).max(x_subview_max2);
  375. if (x_max != 0 && x_max != r - 1 && mval != 0.0)
  376. {
  377. REQUIRE( x_max == x_subview_max1 + 1 );
  378. REQUIRE( x_max == x_subview_max2 + 1 );
  379. REQUIRE( mval == Approx(mval1) );
  380. REQUIRE( mval == Approx(mval2) );
  381. }
  382. }
  383. }
  384. TEST_CASE("fn_max_spincompletesubview_row_test")
  385. {
  386. for (size_t r = 10; r < 50; ++r)
  387. {
  388. sp_rowvec x;
  389. x.sprandn(1, r, 0.3);
  390. uword x_max;
  391. uword x_subview_max1;
  392. uword x_subview_max2;
  393. const double mval = x.max(x_max);
  394. const double mval1 = x.submat(0, 1, 0, r - 2).max(x_subview_max1);
  395. const double mval2 = x.cols(1, r - 2).max(x_subview_max2);
  396. if (mval != 0.0 && x_max != 0 && x_max != r - 1)
  397. {
  398. REQUIRE( x_max == x_subview_max1 + 1 );
  399. REQUIRE( x_max == x_subview_max2 + 1 );
  400. REQUIRE( mval == Approx(mval1) );
  401. REQUIRE( mval == Approx(mval2) );
  402. }
  403. }
  404. }
  405. TEST_CASE("fn_max_cx_spsubview_test")
  406. {
  407. // We will assume subview.at() works and returns points within the bounds of
  408. // the matrix, so we just have to ensure the results are the same as
  409. // Mat.max()...
  410. for (size_t r = 50; r < 150; ++r)
  411. {
  412. sp_cx_mat x;
  413. x.sprandn(r, r, 0.3);
  414. uword x_max;
  415. uword x_subview_max1;
  416. uword x_subview_max2;
  417. uword x_subview_max3;
  418. const std::complex<double> mval = x.max(x_max);
  419. const std::complex<double> mval1 = x.submat(0, 0, r - 1, r - 1).max(x_subview_max1);
  420. const std::complex<double> mval2 = x.cols(0, r - 1).max(x_subview_max2);
  421. const std::complex<double> mval3 = x.rows(0, r - 1).max(x_subview_max3);
  422. if (mval != std::complex<double>(0.0))
  423. {
  424. REQUIRE( x_max == x_subview_max1 );
  425. REQUIRE( x_max == x_subview_max2 );
  426. REQUIRE( x_max == x_subview_max3 );
  427. REQUIRE( mval.real() == Approx(mval1.real()) );
  428. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  429. REQUIRE( mval.real() == Approx(mval2.real()) );
  430. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  431. REQUIRE( mval.real() == Approx(mval3.real()) );
  432. REQUIRE( mval.imag() == Approx(mval3.imag()) );
  433. }
  434. }
  435. }
  436. TEST_CASE("fn_max_cx_spsubview_col_test")
  437. {
  438. for (size_t r = 10; r < 50; ++r)
  439. {
  440. sp_cx_vec x;
  441. x.sprandn(r, 1, 0.3);
  442. uword x_max;
  443. uword x_subview_max1;
  444. uword x_subview_max2;
  445. const std::complex<double> mval = x.max(x_max);
  446. const std::complex<double> mval1 = x.submat(0, 0, r - 1, 0).max(x_subview_max1);
  447. const std::complex<double> mval2 = x.rows(0, r - 1).max(x_subview_max2);
  448. if (mval != std::complex<double>(0.0))
  449. {
  450. REQUIRE( x_max == x_subview_max1 );
  451. REQUIRE( x_max == x_subview_max2 );
  452. REQUIRE( mval.real() == Approx(mval1.real()) );
  453. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  454. REQUIRE( mval.real() == Approx(mval2.real()) );
  455. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  456. }
  457. }
  458. }
  459. TEST_CASE("fn_max_cx_spsubview_row_test")
  460. {
  461. for (size_t r = 10; r < 50; ++r)
  462. {
  463. sp_cx_rowvec x;
  464. x.sprandn(1, r, 0.3);
  465. uword x_max;
  466. uword x_subview_max1;
  467. uword x_subview_max2;
  468. const std::complex<double> mval = x.max(x_max);
  469. const std::complex<double> mval1 = x.submat(0, 0, 0, r - 1).max(x_subview_max1);
  470. const std::complex<double> mval2 = x.cols(0, r - 1).max(x_subview_max2);
  471. if (mval != std::complex<double>(0.0))
  472. {
  473. REQUIRE( x_max == x_subview_max1 );
  474. REQUIRE( x_max == x_subview_max2 );
  475. REQUIRE( mval.real() == Approx(mval1.real()) );
  476. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  477. REQUIRE( mval.real() == Approx(mval2.real()) );
  478. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  479. }
  480. }
  481. }
  482. TEST_CASE("fn_max_cx_spincompletesubview_test")
  483. {
  484. for (size_t r = 50; r < 150; ++r)
  485. {
  486. sp_cx_mat x;
  487. x.sprandn(r, r, 0.3);
  488. uword x_max;
  489. uword x_subview_max1;
  490. uword x_subview_max2;
  491. uword x_subview_max3;
  492. const std::complex<double> mval = x.max(x_max);
  493. const std::complex<double> mval1 = x.submat(1, 1, r - 2, r - 2).max(x_subview_max1);
  494. const std::complex<double> mval2 = x.cols(1, r - 2).max(x_subview_max2);
  495. const std::complex<double> mval3 = x.rows(1, r - 2).max(x_subview_max3);
  496. uword row, col;
  497. x.max(row, col);
  498. if (row != 0 && row != r - 1 && col != 0 && col != r - 1 && mval != std::complex<double>(0.0))
  499. {
  500. uword srow, scol;
  501. srow = x_subview_max1 % (r - 2);
  502. scol = x_subview_max1 / (r - 2);
  503. REQUIRE( x_max == (srow + 1) + r * (scol + 1) );
  504. REQUIRE( x_max == x_subview_max2 + r );
  505. srow = x_subview_max3 % (r - 2);
  506. scol = x_subview_max3 / (r - 2);
  507. REQUIRE( x_max == (srow + 1) + r * scol );
  508. REQUIRE( mval.real() == Approx(mval1.real()) );
  509. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  510. REQUIRE( mval.real() == Approx(mval2.real()) );
  511. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  512. REQUIRE( mval.real() == Approx(mval3.real()) );
  513. REQUIRE( mval.imag() == Approx(mval3.imag()) );
  514. }
  515. }
  516. }
  517. TEST_CASE("fn_max_cx_spincompletesubview_col_test")
  518. {
  519. for (size_t r = 10; r < 50; ++r)
  520. {
  521. sp_cx_vec x;
  522. x.sprandn(r, 1, 0.3);
  523. uword x_max;
  524. uword x_subview_max1;
  525. uword x_subview_max2;
  526. const std::complex<double> mval = x.max(x_max);
  527. const std::complex<double> mval1 = x.submat(1, 0, r - 2, 0).max(x_subview_max1);
  528. const std::complex<double> mval2 = x.rows(1, r - 2).max(x_subview_max2);
  529. if (x_max != 0 && x_max != r - 1 && mval != std::complex<double>(0.0))
  530. {
  531. REQUIRE( x_max == x_subview_max1 + 1 );
  532. REQUIRE( x_max == x_subview_max2 + 1 );
  533. REQUIRE( mval.real() == Approx(mval1.real()) );
  534. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  535. REQUIRE( mval.real() == Approx(mval2.real()) );
  536. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  537. }
  538. }
  539. }
  540. TEST_CASE("fn_max_cx_spincompletesubview_row_test")
  541. {
  542. for (size_t r = 10; r < 50; ++r)
  543. {
  544. sp_cx_rowvec x;
  545. x.sprandn(1, r, 0.3);
  546. uword x_max;
  547. uword x_subview_max1;
  548. uword x_subview_max2;
  549. const std::complex<double> mval = x.max(x_max);
  550. const std::complex<double> mval1 = x.submat(0, 1, 0, r - 2).max(x_subview_max1);
  551. const std::complex<double> mval2 = x.cols(1, r - 2).max(x_subview_max2);
  552. if (x_max != 0 && x_max != r - 1 && mval != std::complex<double>(0.0))
  553. {
  554. REQUIRE( x_max == x_subview_max1 + 1 );
  555. REQUIRE( x_max == x_subview_max2 + 1 );
  556. REQUIRE( mval.real() == Approx(mval1.real()) );
  557. REQUIRE( mval.imag() == Approx(mval1.imag()) );
  558. REQUIRE( mval.real() == Approx(mval2.real()) );
  559. REQUIRE( mval.imag() == Approx(mval2.imag()) );
  560. }
  561. }
  562. }