arma_ostream_meat.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 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. //! \addtogroup arma_ostream
  16. //! @{
  17. inline
  18. arma_ostream_state::arma_ostream_state(const std::ostream& o)
  19. : orig_flags (o.flags())
  20. , orig_precision(o.precision())
  21. , orig_width (o.width())
  22. , orig_fill (o.fill())
  23. {
  24. }
  25. inline
  26. void
  27. arma_ostream_state::restore(std::ostream& o) const
  28. {
  29. o.flags (orig_flags);
  30. o.precision(orig_precision);
  31. o.width (orig_width);
  32. o.fill (orig_fill);
  33. }
  34. //
  35. //
  36. template<typename eT>
  37. inline
  38. std::streamsize
  39. arma_ostream::modify_stream(std::ostream& o, const eT* data, const uword n_elem)
  40. {
  41. o.unsetf(ios::showbase);
  42. o.unsetf(ios::uppercase);
  43. o.unsetf(ios::showpos);
  44. o.fill(' ');
  45. std::streamsize cell_width;
  46. bool use_layout_B = false;
  47. bool use_layout_C = false;
  48. bool use_layout_D = false;
  49. for(uword i=0; i<n_elem; ++i)
  50. {
  51. const eT val = data[i];
  52. if(arma_isfinite(val) == false) { continue; }
  53. if(
  54. ( cond_rel< (sizeof(eT) > 4) && (is_same_type<uword,eT>::yes || is_same_type<sword,eT>::yes) >::geq(val, eT(+10000000000)) )
  55. ||
  56. ( cond_rel< (sizeof(eT) > 4) && is_same_type<sword,eT>::yes >::leq(val, eT(-10000000000)) )
  57. )
  58. {
  59. use_layout_D = true;
  60. break;
  61. }
  62. if(
  63. ( val >= eT(+100) )
  64. ||
  65. //( (is_signed<eT>::value) && (val <= eT(-100)) ) ||
  66. //( (is_non_integral<eT>::value) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
  67. //( (is_non_integral<eT>::value) && (is_signed<eT>::value) && (val < eT(0)) && (val >= eT(-1e-4)) )
  68. (
  69. cond_rel< is_signed<eT>::value >::leq(val, eT(-100))
  70. )
  71. ||
  72. (
  73. cond_rel< is_non_integral<eT>::value >::gt(val, eT(0))
  74. &&
  75. cond_rel< is_non_integral<eT>::value >::leq(val, eT(+1e-4))
  76. )
  77. ||
  78. (
  79. cond_rel< is_non_integral<eT>::value && is_signed<eT>::value >::lt(val, eT(0))
  80. &&
  81. cond_rel< is_non_integral<eT>::value && is_signed<eT>::value >::geq(val, eT(-1e-4))
  82. )
  83. )
  84. {
  85. use_layout_C = true;
  86. break;
  87. }
  88. if(
  89. // (val >= eT(+10)) || ( (is_signed<eT>::value) && (val <= eT(-10)) )
  90. (val >= eT(+10)) || ( cond_rel< is_signed<eT>::value >::leq(val, eT(-10)) )
  91. )
  92. {
  93. use_layout_B = true;
  94. }
  95. }
  96. if(use_layout_D)
  97. {
  98. o.setf(ios::scientific);
  99. o.setf(ios::right);
  100. o.unsetf(ios::fixed);
  101. o.precision(4);
  102. cell_width = 21;
  103. }
  104. else
  105. if(use_layout_C)
  106. {
  107. o.setf(ios::scientific);
  108. o.setf(ios::right);
  109. o.unsetf(ios::fixed);
  110. o.precision(4);
  111. cell_width = 13;
  112. }
  113. else
  114. if(use_layout_B)
  115. {
  116. o.unsetf(ios::scientific);
  117. o.setf(ios::right);
  118. o.setf(ios::fixed);
  119. o.precision(4);
  120. cell_width = 10;
  121. }
  122. else
  123. {
  124. o.unsetf(ios::scientific);
  125. o.setf(ios::right);
  126. o.setf(ios::fixed);
  127. o.precision(4);
  128. cell_width = 9;
  129. }
  130. return cell_width;
  131. }
  132. //! "better than nothing" settings for complex numbers
  133. template<typename T>
  134. inline
  135. std::streamsize
  136. arma_ostream::modify_stream(std::ostream& o, const std::complex<T>* data, const uword n_elem)
  137. {
  138. arma_ignore(data);
  139. arma_ignore(n_elem);
  140. o.unsetf(ios::showbase);
  141. o.unsetf(ios::uppercase);
  142. o.fill(' ');
  143. o.setf(ios::scientific);
  144. o.setf(ios::showpos);
  145. o.setf(ios::right);
  146. o.unsetf(ios::fixed);
  147. std::streamsize cell_width;
  148. o.precision(3);
  149. cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1;
  150. return cell_width;
  151. }
  152. template<typename eT>
  153. inline
  154. std::streamsize
  155. arma_ostream::modify_stream(std::ostream& o, typename SpMat<eT>::const_iterator begin, const uword n_elem, const typename arma_not_cx<eT>::result* junk)
  156. {
  157. arma_extra_debug_sigprint();
  158. arma_ignore(junk);
  159. o.unsetf(ios::showbase);
  160. o.unsetf(ios::uppercase);
  161. o.unsetf(ios::showpos);
  162. o.fill(' ');
  163. std::streamsize cell_width;
  164. bool use_layout_B = false;
  165. bool use_layout_C = false;
  166. for(typename SpMat<eT>::const_iterator it = begin; it.pos() < n_elem; ++it)
  167. {
  168. const eT val = (*it);
  169. if(arma_isfinite(val) == false) { continue; }
  170. if(
  171. val >= eT(+100) ||
  172. ( (is_signed<eT>::value) && (val <= eT(-100)) ) ||
  173. ( (is_non_integral<eT>::value) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
  174. ( (is_non_integral<eT>::value) && (is_signed<eT>::value) && (val < eT(0)) && (val >= eT(-1e-4)) )
  175. )
  176. {
  177. use_layout_C = true;
  178. break;
  179. }
  180. if(
  181. (val >= eT(+10)) || ( (is_signed<eT>::value) && (val <= eT(-10)) )
  182. )
  183. {
  184. use_layout_B = true;
  185. }
  186. }
  187. if(use_layout_C)
  188. {
  189. o.setf(ios::scientific);
  190. o.setf(ios::right);
  191. o.unsetf(ios::fixed);
  192. o.precision(4);
  193. cell_width = 13;
  194. }
  195. else
  196. if(use_layout_B)
  197. {
  198. o.unsetf(ios::scientific);
  199. o.setf(ios::right);
  200. o.setf(ios::fixed);
  201. o.precision(4);
  202. cell_width = 10;
  203. }
  204. else
  205. {
  206. o.unsetf(ios::scientific);
  207. o.setf(ios::right);
  208. o.setf(ios::fixed);
  209. o.precision(4);
  210. cell_width = 9;
  211. }
  212. return cell_width;
  213. }
  214. //! "better than nothing" settings for complex numbers
  215. template<typename T>
  216. inline
  217. std::streamsize
  218. arma_ostream::modify_stream(std::ostream& o, typename SpMat<T>::const_iterator begin, const uword n_elem, const typename arma_cx_only<T>::result* junk)
  219. {
  220. arma_ignore(begin);
  221. arma_ignore(n_elem);
  222. arma_ignore(junk);
  223. o.unsetf(ios::showbase);
  224. o.unsetf(ios::uppercase);
  225. o.fill(' ');
  226. o.setf(ios::scientific);
  227. o.setf(ios::showpos);
  228. o.setf(ios::right);
  229. o.unsetf(ios::fixed);
  230. std::streamsize cell_width;
  231. o.precision(3);
  232. cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1;
  233. return cell_width;
  234. }
  235. template<typename eT>
  236. inline
  237. void
  238. arma_ostream::print_elem_zero(std::ostream& o, const bool modify)
  239. {
  240. typedef typename promote_type<eT, s16>::result promoted_eT;
  241. if(modify)
  242. {
  243. const ios::fmtflags save_flags = o.flags();
  244. const std::streamsize save_precision = o.precision();
  245. o.unsetf(ios::scientific);
  246. o.setf(ios::fixed);
  247. o.precision(0);
  248. o << promoted_eT(0);
  249. o.flags(save_flags);
  250. o.precision(save_precision);
  251. }
  252. else
  253. {
  254. o << promoted_eT(0);
  255. }
  256. }
  257. template<typename eT>
  258. inline
  259. void
  260. arma_ostream::print_elem(std::ostream& o, const eT& x, const bool modify)
  261. {
  262. if(x == eT(0))
  263. {
  264. arma_ostream::print_elem_zero<eT>(o, modify);
  265. }
  266. else
  267. {
  268. arma_ostream::raw_print_elem(o, x);
  269. }
  270. }
  271. template<typename eT>
  272. inline
  273. void
  274. arma_ostream::raw_print_elem(std::ostream& o, const eT& x)
  275. {
  276. if(is_signed<eT>::value)
  277. {
  278. typedef typename promote_type<eT, s16>::result promoted_eT;
  279. if(arma_isfinite(x))
  280. {
  281. o << promoted_eT(x);
  282. }
  283. else
  284. {
  285. o << ( arma_isinf(x) ? ((x <= eT(0)) ? "-inf" : "inf") : "nan" );
  286. }
  287. }
  288. else
  289. {
  290. typedef typename promote_type<eT, u16>::result promoted_eT;
  291. o << promoted_eT(x);
  292. }
  293. }
  294. template<typename T>
  295. inline
  296. void
  297. arma_ostream::print_elem(std::ostream& o, const std::complex<T>& x, const bool modify)
  298. {
  299. if( (x.real() == T(0)) && (x.imag() == T(0)) && (modify) )
  300. {
  301. o << "(0,0)";
  302. }
  303. else
  304. {
  305. arma_ostream::raw_print_elem(o, x);
  306. }
  307. }
  308. template<typename T>
  309. inline
  310. void
  311. arma_ostream::raw_print_elem(std::ostream& o, const std::complex<T>& x)
  312. {
  313. std::ostringstream ss;
  314. ss.flags(o.flags());
  315. //ss.imbue(o.getloc());
  316. ss.precision(o.precision());
  317. ss << '(';
  318. const T a = x.real();
  319. if(arma_isfinite(a))
  320. {
  321. ss << a;
  322. }
  323. else
  324. {
  325. ss << ( arma_isinf(a) ? ((a <= T(0)) ? "-inf" : "+inf") : "nan" );
  326. }
  327. ss << ',';
  328. const T b = x.imag();
  329. if(arma_isfinite(b))
  330. {
  331. ss << b;
  332. }
  333. else
  334. {
  335. ss << ( arma_isinf(b) ? ((b <= T(0)) ? "-inf" : "+inf") : "nan" );
  336. }
  337. ss << ')';
  338. o << ss.str();
  339. }
  340. //! Print a matrix to the specified stream
  341. template<typename eT>
  342. arma_cold
  343. inline
  344. void
  345. arma_ostream::print(std::ostream& o, const Mat<eT>& m, const bool modify)
  346. {
  347. arma_extra_debug_sigprint();
  348. const arma_ostream_state stream_state(o);
  349. const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, m.memptr(), m.n_elem) : o.width();
  350. const uword m_n_rows = m.n_rows;
  351. const uword m_n_cols = m.n_cols;
  352. if(m.is_empty() == false)
  353. {
  354. if(m_n_cols > 0)
  355. {
  356. if(cell_width > 0)
  357. {
  358. for(uword row=0; row < m_n_rows; ++row)
  359. {
  360. for(uword col=0; col < m_n_cols; ++col)
  361. {
  362. // the cell width appears to be reset after each element is printed,
  363. // hence we need to restore it
  364. o.width(cell_width);
  365. arma_ostream::print_elem(o, m.at(row,col), modify);
  366. }
  367. o << '\n';
  368. }
  369. }
  370. else
  371. {
  372. for(uword row=0; row < m_n_rows; ++row)
  373. {
  374. for(uword col=0; col < m_n_cols-1; ++col)
  375. {
  376. arma_ostream::print_elem(o, m.at(row,col), modify);
  377. o << ' ';
  378. }
  379. arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify);
  380. o << '\n';
  381. }
  382. }
  383. }
  384. }
  385. else
  386. {
  387. o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n";
  388. }
  389. o.flush();
  390. stream_state.restore(o);
  391. }
  392. //! Print a cube to the specified stream
  393. template<typename eT>
  394. arma_cold
  395. inline
  396. void
  397. arma_ostream::print(std::ostream& o, const Cube<eT>& x, const bool modify)
  398. {
  399. arma_extra_debug_sigprint();
  400. const arma_ostream_state stream_state(o);
  401. if(x.is_empty() == false)
  402. {
  403. for(uword slice=0; slice < x.n_slices; ++slice)
  404. {
  405. const Mat<eT> tmp(const_cast<eT*>(x.slice_memptr(slice)), x.n_rows, x.n_cols, false);
  406. o << "[cube slice " << slice << ']' << '\n';
  407. arma_ostream::print(o, tmp, modify);
  408. o << '\n';
  409. }
  410. }
  411. else
  412. {
  413. o << "[cube size: " << x.n_rows << 'x' << x.n_cols << 'x' << x.n_slices << "]\n";
  414. }
  415. stream_state.restore(o);
  416. }
  417. //! Print a field to the specified stream
  418. //! Assumes type oT can be printed, i.e. oT has std::ostream& operator<< (std::ostream&, const oT&)
  419. template<typename oT>
  420. arma_cold
  421. inline
  422. void
  423. arma_ostream::print(std::ostream& o, const field<oT>& x)
  424. {
  425. arma_extra_debug_sigprint();
  426. const arma_ostream_state stream_state(o);
  427. const std::streamsize cell_width = o.width();
  428. const uword x_n_rows = x.n_rows;
  429. const uword x_n_cols = x.n_cols;
  430. const uword x_n_slices = x.n_slices;
  431. if(x.is_empty() == false)
  432. {
  433. if(x_n_slices == 1)
  434. {
  435. for(uword col=0; col<x_n_cols; ++col)
  436. {
  437. o << "[field column " << col << ']' << '\n';
  438. for(uword row=0; row<x_n_rows; ++row)
  439. {
  440. o.width(cell_width);
  441. o << x.at(row,col) << '\n';
  442. }
  443. o << '\n';
  444. }
  445. }
  446. else
  447. {
  448. for(uword slice=0; slice<x_n_slices; ++slice)
  449. {
  450. o << "[field slice " << slice << ']' << '\n';
  451. for(uword col=0; col<x_n_cols; ++col)
  452. {
  453. o << "[field column " << col << ']' << '\n';
  454. for(uword row=0; row<x_n_rows; ++row)
  455. {
  456. o.width(cell_width);
  457. o << x.at(row,col,slice) << '\n';
  458. }
  459. o << '\n';
  460. }
  461. o << '\n';
  462. }
  463. }
  464. }
  465. else
  466. {
  467. o << "[field size: " << x_n_rows << 'x' << x_n_cols << 'x' << x_n_slices << "]\n";
  468. }
  469. o.flush();
  470. stream_state.restore(o);
  471. }
  472. //! Print a subfield to the specified stream
  473. //! Assumes type oT can be printed, i.e. oT has std::ostream& operator<< (std::ostream&, const oT&)
  474. template<typename oT>
  475. arma_cold
  476. inline
  477. void
  478. arma_ostream::print(std::ostream& o, const subview_field<oT>& x)
  479. {
  480. arma_extra_debug_sigprint();
  481. const arma_ostream_state stream_state(o);
  482. const std::streamsize cell_width = o.width();
  483. const uword x_n_rows = x.n_rows;
  484. const uword x_n_cols = x.n_cols;
  485. const uword x_n_slices = x.n_slices;
  486. if(x.is_empty() == false)
  487. {
  488. if(x_n_slices == 1)
  489. {
  490. for(uword col=0; col<x_n_cols; ++col)
  491. {
  492. o << "[field column " << col << ']' << '\n';
  493. for(uword row=0; row<x_n_rows; ++row)
  494. {
  495. o.width(cell_width);
  496. o << x.at(row,col) << '\n';
  497. }
  498. o << '\n';
  499. }
  500. }
  501. else
  502. {
  503. for(uword slice=0; slice<x_n_slices; ++slice)
  504. {
  505. o << "[field slice " << slice << ']' << '\n';
  506. for(uword col=0; col<x_n_cols; ++col)
  507. {
  508. o << "[field column " << col << ']' << '\n';
  509. for(uword row=0; row<x_n_rows; ++row)
  510. {
  511. o.width(cell_width);
  512. o << x.at(row,col,slice) << '\n';
  513. }
  514. o << '\n';
  515. }
  516. o << '\n';
  517. }
  518. }
  519. }
  520. else
  521. {
  522. o << "[field size: " << x_n_rows << 'x' << x_n_cols << 'x' << x_n_slices << "]\n";
  523. }
  524. o.flush();
  525. stream_state.restore(o);
  526. }
  527. template<typename eT>
  528. arma_cold
  529. inline
  530. void
  531. arma_ostream::print_dense(std::ostream& o, const SpMat<eT>& m, const bool modify)
  532. {
  533. arma_extra_debug_sigprint();
  534. const arma_ostream_state stream_state(o);
  535. std::streamsize cell_width = o.width();
  536. if(modify)
  537. {
  538. if(m.n_nonzero > 0)
  539. {
  540. cell_width = arma_ostream::modify_stream<eT>(o, m.begin(), m.n_nonzero);
  541. }
  542. else
  543. {
  544. eT tmp[1]; tmp[0] = eT(0);
  545. cell_width = arma_ostream::modify_stream(o, &tmp[0], 1);
  546. }
  547. }
  548. const uword m_n_rows = m.n_rows;
  549. const uword m_n_cols = m.n_cols;
  550. if(m.is_empty() == false)
  551. {
  552. if(m_n_cols > 0)
  553. {
  554. if(cell_width > 0)
  555. {
  556. for(uword row=0; row < m_n_rows; ++row)
  557. {
  558. for(uword col=0; col < m_n_cols; ++col)
  559. {
  560. // the cell width appears to be reset after each element is printed,
  561. // hence we need to restore it
  562. o.width(cell_width);
  563. arma_ostream::print_elem(o, m.at(row,col), modify);
  564. }
  565. o << '\n';
  566. }
  567. }
  568. else
  569. {
  570. for(uword row=0; row < m_n_rows; ++row)
  571. {
  572. for(uword col=0; col < m_n_cols-1; ++col)
  573. {
  574. arma_ostream::print_elem(o, m.at(row,col), modify);
  575. o << ' ';
  576. }
  577. arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify);
  578. o << '\n';
  579. }
  580. }
  581. }
  582. }
  583. else
  584. {
  585. o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n";
  586. }
  587. o.flush();
  588. stream_state.restore(o);
  589. }
  590. template<typename eT>
  591. arma_cold
  592. inline
  593. void
  594. arma_ostream::print(std::ostream& o, const SpMat<eT>& m, const bool modify)
  595. {
  596. arma_extra_debug_sigprint();
  597. const arma_ostream_state stream_state(o);
  598. o.unsetf(ios::showbase);
  599. o.unsetf(ios::uppercase);
  600. o.unsetf(ios::showpos);
  601. o.unsetf(ios::scientific);
  602. o.setf(ios::right);
  603. o.setf(ios::fixed);
  604. const uword m_n_nonzero = m.n_nonzero;
  605. const double density = (m.n_elem > 0) ? (double(m_n_nonzero) / double(m.n_elem) * double(100)) : double(0);
  606. o << "[matrix size: " << m.n_rows << 'x' << m.n_cols << "; n_nonzero: " << m_n_nonzero;
  607. if(density == double(0))
  608. {
  609. o.precision(0);
  610. }
  611. else
  612. if(density >= (double(10.0)-std::numeric_limits<double>::epsilon()))
  613. {
  614. o.precision(1);
  615. }
  616. else
  617. if(density > (double(0.01)-std::numeric_limits<double>::epsilon()))
  618. {
  619. o.precision(2);
  620. }
  621. else
  622. if(density > (double(0.001)-std::numeric_limits<double>::epsilon()))
  623. {
  624. o.precision(3);
  625. }
  626. else
  627. if(density > (double(0.0001)-std::numeric_limits<double>::epsilon()))
  628. {
  629. o.precision(4);
  630. }
  631. else
  632. {
  633. o.unsetf(ios::fixed);
  634. o.setf(ios::scientific);
  635. o.precision(2);
  636. }
  637. o << "; density: " << density << "%]\n\n";
  638. if(modify == false) { stream_state.restore(o); }
  639. if(m_n_nonzero > 0)
  640. {
  641. const std::streamsize cell_width = modify ? arma_ostream::modify_stream<eT>(o, m.begin(), m_n_nonzero) : o.width();
  642. typename SpMat<eT>::const_iterator begin = m.begin();
  643. typename SpMat<eT>::const_iterator m_end = m.end();
  644. while(begin != m_end)
  645. {
  646. const uword row = begin.row();
  647. // TODO: change the maximum number of spaces before and after each location to be dependent on n_rows and n_cols
  648. if(row < 10) { o << " "; }
  649. else if(row < 100) { o << " "; }
  650. else if(row < 1000) { o << " "; }
  651. else if(row < 10000) { o << " "; }
  652. else if(row < 100000) { o << ' '; }
  653. const uword col = begin.col();
  654. o << '(' << row << ", " << col << ") ";
  655. if(col < 10) { o << " "; }
  656. else if(col < 100) { o << " "; }
  657. else if(col < 1000) { o << " "; }
  658. else if(col < 10000) { o << " "; }
  659. else if(col < 100000) { o << ' '; }
  660. if(cell_width > 0) { o.width(cell_width); }
  661. arma_ostream::print_elem(o, eT(*begin), modify);
  662. o << '\n';
  663. ++begin;
  664. }
  665. o << '\n';
  666. }
  667. o.flush();
  668. stream_state.restore(o);
  669. }
  670. arma_cold
  671. inline
  672. void
  673. arma_ostream::print(std::ostream& o, const SizeMat& S)
  674. {
  675. arma_extra_debug_sigprint();
  676. const arma_ostream_state stream_state(o);
  677. o.unsetf(ios::showbase);
  678. o.unsetf(ios::uppercase);
  679. o.unsetf(ios::showpos);
  680. o.setf(ios::fixed);
  681. o << S.n_rows << 'x' << S.n_cols;
  682. stream_state.restore(o);
  683. }
  684. arma_cold
  685. inline
  686. void
  687. arma_ostream::print(std::ostream& o, const SizeCube& S)
  688. {
  689. arma_extra_debug_sigprint();
  690. const arma_ostream_state stream_state(o);
  691. o.unsetf(ios::showbase);
  692. o.unsetf(ios::uppercase);
  693. o.unsetf(ios::showpos);
  694. o.setf(ios::fixed);
  695. o << S.n_rows << 'x' << S.n_cols << 'x' << S.n_slices;
  696. stream_state.restore(o);
  697. }
  698. //! @}