SpSubview_meat.hpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  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 SpSubview
  16. //! @{
  17. template<typename eT>
  18. inline
  19. SpSubview<eT>::SpSubview(const SpMat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols)
  20. : m(in_m)
  21. , aux_row1(in_row1)
  22. , aux_col1(in_col1)
  23. , n_rows(in_n_rows)
  24. , n_cols(in_n_cols)
  25. , n_elem(in_n_rows * in_n_cols)
  26. , n_nonzero(0)
  27. {
  28. arma_extra_debug_sigprint();
  29. m.sync_csc();
  30. // There must be a O(1) way to do this
  31. uword lend = m.col_ptrs[in_col1 + in_n_cols];
  32. uword lend_row = in_row1 + in_n_rows;
  33. uword count = 0;
  34. for(uword i = m.col_ptrs[in_col1]; i < lend; ++i)
  35. {
  36. const uword m_row_indices_i = m.row_indices[i];
  37. const bool condition = (m_row_indices_i >= in_row1) && (m_row_indices_i < lend_row);
  38. count += condition ? uword(1) : uword(0);
  39. }
  40. access::rw(n_nonzero) = count;
  41. }
  42. template<typename eT>
  43. inline
  44. SpSubview<eT>::SpSubview(SpMat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols)
  45. : m(in_m)
  46. , aux_row1(in_row1)
  47. , aux_col1(in_col1)
  48. , n_rows(in_n_rows)
  49. , n_cols(in_n_cols)
  50. , n_elem(in_n_rows * in_n_cols)
  51. , n_nonzero(0)
  52. {
  53. arma_extra_debug_sigprint();
  54. m.sync_csc();
  55. // There must be a O(1) way to do this
  56. uword lend = m.col_ptrs[in_col1 + in_n_cols];
  57. uword lend_row = in_row1 + in_n_rows;
  58. uword count = 0;
  59. for(uword i = m.col_ptrs[in_col1]; i < lend; ++i)
  60. {
  61. const uword m_row_indices_i = m.row_indices[i];
  62. const bool condition = (m_row_indices_i >= in_row1) && (m_row_indices_i < lend_row);
  63. count += condition ? uword(1) : uword(0);
  64. }
  65. access::rw(n_nonzero) = count;
  66. }
  67. template<typename eT>
  68. inline
  69. SpSubview<eT>::~SpSubview()
  70. {
  71. arma_extra_debug_sigprint();
  72. }
  73. template<typename eT>
  74. inline
  75. const SpSubview<eT>&
  76. SpSubview<eT>::operator+=(const eT val)
  77. {
  78. arma_extra_debug_sigprint();
  79. if(val == eT(0))
  80. {
  81. return *this;
  82. }
  83. Mat<eT> tmp( (*this).n_rows, (*this).n_cols );
  84. tmp.fill(val);
  85. return (*this).operator=( (*this) + tmp );
  86. }
  87. template<typename eT>
  88. inline
  89. const SpSubview<eT>&
  90. SpSubview<eT>::operator-=(const eT val)
  91. {
  92. arma_extra_debug_sigprint();
  93. if(val == eT(0))
  94. {
  95. return *this;
  96. }
  97. Mat<eT> tmp( (*this).n_rows, (*this).n_cols );
  98. tmp.fill(val);
  99. return (*this).operator=( (*this) - tmp );
  100. }
  101. template<typename eT>
  102. inline
  103. const SpSubview<eT>&
  104. SpSubview<eT>::operator*=(const eT val)
  105. {
  106. arma_extra_debug_sigprint();
  107. if(val == eT(0)) { (*this).zeros(); return *this; }
  108. if((n_elem == 0) || (n_nonzero == 0)) { return *this; }
  109. m.sync_csc();
  110. m.invalidate_cache();
  111. const uword lstart_row = aux_row1;
  112. const uword lend_row = aux_row1 + n_rows;
  113. const uword lstart_col = aux_col1;
  114. const uword lend_col = aux_col1 + n_cols;
  115. const uword* m_row_indices = m.row_indices;
  116. eT* m_values = access::rwp(m.values);
  117. bool has_zero = false;
  118. for(uword c = lstart_col; c < lend_col; ++c)
  119. {
  120. const uword r_start = m.col_ptrs[c ];
  121. const uword r_end = m.col_ptrs[c + 1];
  122. for(uword r = r_start; r < r_end; ++r)
  123. {
  124. const uword m_row_indices_r = m_row_indices[r];
  125. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  126. {
  127. eT& m_values_r = m_values[r];
  128. m_values_r *= val;
  129. if(m_values_r == eT(0)) { has_zero = true; }
  130. }
  131. }
  132. }
  133. if(has_zero)
  134. {
  135. const uword old_m_n_nonzero = m.n_nonzero;
  136. access::rw(m).remove_zeros();
  137. if(m.n_nonzero != old_m_n_nonzero)
  138. {
  139. access::rw(n_nonzero) = n_nonzero - (old_m_n_nonzero - m.n_nonzero);
  140. }
  141. }
  142. return *this;
  143. }
  144. template<typename eT>
  145. inline
  146. const SpSubview<eT>&
  147. SpSubview<eT>::operator/=(const eT val)
  148. {
  149. arma_extra_debug_sigprint();
  150. arma_debug_check( (val == eT(0)), "element-wise division: division by zero" );
  151. m.sync_csc();
  152. m.invalidate_cache();
  153. const uword lstart_row = aux_row1;
  154. const uword lend_row = aux_row1 + n_rows;
  155. const uword lstart_col = aux_col1;
  156. const uword lend_col = aux_col1 + n_cols;
  157. const uword* m_row_indices = m.row_indices;
  158. eT* m_values = access::rwp(m.values);
  159. bool has_zero = false;
  160. for(uword c = lstart_col; c < lend_col; ++c)
  161. {
  162. const uword r_start = m.col_ptrs[c ];
  163. const uword r_end = m.col_ptrs[c + 1];
  164. for(uword r = r_start; r < r_end; ++r)
  165. {
  166. const uword m_row_indices_r = m_row_indices[r];
  167. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  168. {
  169. eT& m_values_r = m_values[r];
  170. m_values_r /= val;
  171. if(m_values_r == eT(0)) { has_zero = true; }
  172. }
  173. }
  174. }
  175. if(has_zero)
  176. {
  177. const uword old_m_n_nonzero = m.n_nonzero;
  178. access::rw(m).remove_zeros();
  179. if(m.n_nonzero != old_m_n_nonzero)
  180. {
  181. access::rw(n_nonzero) = n_nonzero - (old_m_n_nonzero - m.n_nonzero);
  182. }
  183. }
  184. return *this;
  185. }
  186. template<typename eT>
  187. template<typename T1>
  188. inline
  189. const SpSubview<eT>&
  190. SpSubview<eT>::operator=(const Base<eT, T1>& in)
  191. {
  192. arma_extra_debug_sigprint();
  193. if(is_same_type< T1, Gen<Mat<eT>, gen_zeros> >::yes)
  194. {
  195. const Proxy<T1> P(in.get_ref());
  196. arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "insertion into sparse submatrix");
  197. (*this).zeros();
  198. return *this;
  199. }
  200. if(is_same_type< T1, Gen<Mat<eT>, gen_eye> >::yes)
  201. {
  202. const Proxy<T1> P(in.get_ref());
  203. arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "insertion into sparse submatrix");
  204. (*this).eye();
  205. return *this;
  206. }
  207. const quasi_unwrap<T1> U(in.get_ref());
  208. arma_debug_assert_same_size(n_rows, n_cols, U.M.n_rows, U.M.n_cols, "insertion into sparse submatrix");
  209. spglue_merge::subview_merge(*this, U.M);
  210. return *this;
  211. }
  212. template<typename eT>
  213. template<typename T1>
  214. inline
  215. const SpSubview<eT>&
  216. SpSubview<eT>::operator+=(const Base<eT, T1>& x)
  217. {
  218. arma_extra_debug_sigprint();
  219. return (*this).operator=( (*this) + x.get_ref() );
  220. }
  221. template<typename eT>
  222. template<typename T1>
  223. inline
  224. const SpSubview<eT>&
  225. SpSubview<eT>::operator-=(const Base<eT, T1>& x)
  226. {
  227. arma_extra_debug_sigprint();
  228. return (*this).operator=( (*this) - x.get_ref() );
  229. }
  230. template<typename eT>
  231. template<typename T1>
  232. inline
  233. const SpSubview<eT>&
  234. SpSubview<eT>::operator*=(const Base<eT, T1>& x)
  235. {
  236. arma_extra_debug_sigprint();
  237. SpMat<eT> tmp(*this);
  238. tmp *= x.get_ref();
  239. return (*this).operator=(tmp);
  240. }
  241. template<typename eT>
  242. template<typename T1>
  243. inline
  244. const SpSubview<eT>&
  245. SpSubview<eT>::operator%=(const Base<eT, T1>& x)
  246. {
  247. arma_extra_debug_sigprint();
  248. return (*this).operator=( (*this) % x.get_ref() );
  249. }
  250. template<typename eT>
  251. template<typename T1>
  252. inline
  253. const SpSubview<eT>&
  254. SpSubview<eT>::operator/=(const Base<eT, T1>& x)
  255. {
  256. arma_extra_debug_sigprint();
  257. return (*this).operator=( (*this) / x.get_ref() );
  258. }
  259. template<typename eT>
  260. inline
  261. const SpSubview<eT>&
  262. SpSubview<eT>::operator=(const SpSubview<eT>& x)
  263. {
  264. arma_extra_debug_sigprint();
  265. return (*this).operator_equ_common(x);
  266. }
  267. template<typename eT>
  268. template<typename T1>
  269. inline
  270. const SpSubview<eT>&
  271. SpSubview<eT>::operator=(const SpBase<eT, T1>& x)
  272. {
  273. arma_extra_debug_sigprint();
  274. return (*this).operator_equ_common( x.get_ref() );
  275. }
  276. template<typename eT>
  277. template<typename T1>
  278. inline
  279. const SpSubview<eT>&
  280. SpSubview<eT>::operator_equ_common(const SpBase<eT, T1>& in)
  281. {
  282. arma_extra_debug_sigprint();
  283. const unwrap_spmat<T1> U(in.get_ref());
  284. if(U.is_alias(m))
  285. {
  286. const SpMat<eT> tmp(U.M);
  287. return (*this).operator_equ_common(tmp);
  288. }
  289. arma_debug_assert_same_size(n_rows, n_cols, U.M.n_rows, U.M.n_cols, "insertion into sparse submatrix");
  290. spglue_merge::subview_merge(*this, U.M);
  291. return *this;
  292. }
  293. template<typename eT>
  294. template<typename T1>
  295. inline
  296. const SpSubview<eT>&
  297. SpSubview<eT>::operator+=(const SpBase<eT, T1>& x)
  298. {
  299. arma_extra_debug_sigprint();
  300. // TODO: implement dedicated machinery
  301. return (*this).operator=( (*this) + x.get_ref() );
  302. }
  303. template<typename eT>
  304. template<typename T1>
  305. inline
  306. const SpSubview<eT>&
  307. SpSubview<eT>::operator-=(const SpBase<eT, T1>& x)
  308. {
  309. arma_extra_debug_sigprint();
  310. // TODO: implement dedicated machinery
  311. return (*this).operator=( (*this) - x.get_ref() );
  312. }
  313. template<typename eT>
  314. template<typename T1>
  315. inline
  316. const SpSubview<eT>&
  317. SpSubview<eT>::operator*=(const SpBase<eT, T1>& x)
  318. {
  319. arma_extra_debug_sigprint();
  320. return (*this).operator=( (*this) * x.get_ref() );
  321. }
  322. template<typename eT>
  323. template<typename T1>
  324. inline
  325. const SpSubview<eT>&
  326. SpSubview<eT>::operator%=(const SpBase<eT, T1>& x)
  327. {
  328. arma_extra_debug_sigprint();
  329. // TODO: implement dedicated machinery
  330. return (*this).operator=( (*this) % x.get_ref() );
  331. }
  332. template<typename eT>
  333. template<typename T1>
  334. inline
  335. const SpSubview<eT>&
  336. SpSubview<eT>::operator/=(const SpBase<eT, T1>& x)
  337. {
  338. arma_extra_debug_sigprint();
  339. // NOTE: use of this function is not advised; it is implemented only for completeness
  340. SpProxy<T1> p(x.get_ref());
  341. arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division");
  342. if(p.is_alias(m) == false)
  343. {
  344. for(uword lcol = 0; lcol < n_cols; ++lcol)
  345. for(uword lrow = 0; lrow < n_rows; ++lrow)
  346. {
  347. at(lrow,lcol) /= p.at(lrow,lcol);
  348. }
  349. }
  350. else
  351. {
  352. const SpMat<eT> tmp(p.Q);
  353. (*this).operator/=(tmp);
  354. }
  355. return *this;
  356. }
  357. //! apply a functor to each element
  358. template<typename eT>
  359. template<typename functor>
  360. inline
  361. void
  362. SpSubview<eT>::for_each(functor F)
  363. {
  364. arma_extra_debug_sigprint();
  365. m.sync_csc();
  366. m.invalidate_cache();
  367. const uword lstart_row = aux_row1;
  368. const uword lend_row = aux_row1 + n_rows;
  369. const uword lstart_col = aux_col1;
  370. const uword lend_col = aux_col1 + n_cols;
  371. const uword* m_row_indices = m.row_indices;
  372. eT* m_values = access::rwp(m.values);
  373. bool has_zero = false;
  374. for(uword c = lstart_col; c < lend_col; ++c)
  375. {
  376. const uword r_start = m.col_ptrs[c ];
  377. const uword r_end = m.col_ptrs[c + 1];
  378. for(uword r = r_start; r < r_end; ++r)
  379. {
  380. const uword m_row_indices_r = m_row_indices[r];
  381. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  382. {
  383. eT& m_values_r = m_values[r];
  384. F(m_values_r);
  385. if(m_values_r == eT(0)) { has_zero = true; }
  386. }
  387. }
  388. }
  389. if(has_zero)
  390. {
  391. const uword old_m_n_nonzero = m.n_nonzero;
  392. access::rw(m).remove_zeros();
  393. if(m.n_nonzero != old_m_n_nonzero)
  394. {
  395. access::rw(n_nonzero) = n_nonzero - (old_m_n_nonzero - m.n_nonzero);
  396. }
  397. }
  398. }
  399. template<typename eT>
  400. template<typename functor>
  401. inline
  402. void
  403. SpSubview<eT>::for_each(functor F) const
  404. {
  405. arma_extra_debug_sigprint();
  406. m.sync_csc();
  407. const uword lstart_row = aux_row1;
  408. const uword lend_row = aux_row1 + n_rows;
  409. const uword lstart_col = aux_col1;
  410. const uword lend_col = aux_col1 + n_cols;
  411. const uword* m_row_indices = m.row_indices;
  412. for(uword c = lstart_col; c < lend_col; ++c)
  413. {
  414. const uword r_start = m.col_ptrs[c ];
  415. const uword r_end = m.col_ptrs[c + 1];
  416. for(uword r = r_start; r < r_end; ++r)
  417. {
  418. const uword m_row_indices_r = m_row_indices[r];
  419. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  420. {
  421. F(m.values[r]);
  422. }
  423. }
  424. }
  425. }
  426. //! transform each element using a functor
  427. template<typename eT>
  428. template<typename functor>
  429. inline
  430. void
  431. SpSubview<eT>::transform(functor F)
  432. {
  433. arma_extra_debug_sigprint();
  434. m.sync_csc();
  435. m.invalidate_cache();
  436. const uword lstart_row = aux_row1;
  437. const uword lend_row = aux_row1 + n_rows;
  438. const uword lstart_col = aux_col1;
  439. const uword lend_col = aux_col1 + n_cols;
  440. const uword* m_row_indices = m.row_indices;
  441. eT* m_values = access::rwp(m.values);
  442. bool has_zero = false;
  443. for(uword c = lstart_col; c < lend_col; ++c)
  444. {
  445. const uword r_start = m.col_ptrs[c ];
  446. const uword r_end = m.col_ptrs[c + 1];
  447. for(uword r = r_start; r < r_end; ++r)
  448. {
  449. const uword m_row_indices_r = m_row_indices[r];
  450. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  451. {
  452. eT& m_values_r = m_values[r];
  453. m_values_r = eT( F(m_values_r) );
  454. if(m_values_r == eT(0)) { has_zero = true; }
  455. }
  456. }
  457. }
  458. if(has_zero)
  459. {
  460. const uword old_m_n_nonzero = m.n_nonzero;
  461. access::rw(m).remove_zeros();
  462. if(m.n_nonzero != old_m_n_nonzero)
  463. {
  464. access::rw(n_nonzero) = n_nonzero - (old_m_n_nonzero - m.n_nonzero);
  465. }
  466. }
  467. }
  468. template<typename eT>
  469. inline
  470. void
  471. SpSubview<eT>::replace(const eT old_val, const eT new_val)
  472. {
  473. arma_extra_debug_sigprint();
  474. if(old_val == eT(0))
  475. {
  476. if(new_val != eT(0))
  477. {
  478. Mat<eT> tmp(*this);
  479. tmp.replace(old_val, new_val);
  480. (*this).operator=(tmp);
  481. }
  482. return;
  483. }
  484. m.sync_csc();
  485. m.invalidate_cache();
  486. const uword lstart_row = aux_row1;
  487. const uword lend_row = aux_row1 + n_rows;
  488. const uword lstart_col = aux_col1;
  489. const uword lend_col = aux_col1 + n_cols;
  490. const uword* m_row_indices = m.row_indices;
  491. eT* m_values = access::rwp(m.values);
  492. if(arma_isnan(old_val))
  493. {
  494. for(uword c = lstart_col; c < lend_col; ++c)
  495. {
  496. const uword r_start = m.col_ptrs[c ];
  497. const uword r_end = m.col_ptrs[c + 1];
  498. for(uword r = r_start; r < r_end; ++r)
  499. {
  500. const uword m_row_indices_r = m_row_indices[r];
  501. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  502. {
  503. eT& val = m_values[r];
  504. val = (arma_isnan(val)) ? new_val : val;
  505. }
  506. }
  507. }
  508. }
  509. else
  510. {
  511. for(uword c = lstart_col; c < lend_col; ++c)
  512. {
  513. const uword r_start = m.col_ptrs[c ];
  514. const uword r_end = m.col_ptrs[c + 1];
  515. for(uword r = r_start; r < r_end; ++r)
  516. {
  517. const uword m_row_indices_r = m_row_indices[r];
  518. if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) )
  519. {
  520. eT& val = m_values[r];
  521. val = (val == old_val) ? new_val : val;
  522. }
  523. }
  524. }
  525. }
  526. if(new_val == eT(0)) { access::rw(m).remove_zeros(); }
  527. }
  528. template<typename eT>
  529. inline
  530. void
  531. SpSubview<eT>::clean(const typename get_pod_type<eT>::result threshold)
  532. {
  533. arma_extra_debug_sigprint();
  534. if((n_elem == 0) || (n_nonzero == 0)) { return; }
  535. // TODO: replace with a more efficient implementation
  536. SpMat<eT> tmp(*this);
  537. tmp.clean(threshold);
  538. if(is_cx<eT>::yes)
  539. {
  540. (*this).operator=(tmp);
  541. }
  542. else
  543. if(tmp.n_nonzero != n_nonzero)
  544. {
  545. (*this).operator=(tmp);
  546. }
  547. }
  548. template<typename eT>
  549. inline
  550. void
  551. SpSubview<eT>::fill(const eT val)
  552. {
  553. arma_extra_debug_sigprint();
  554. if(val != eT(0))
  555. {
  556. Mat<eT> tmp( (*this).n_rows, (*this).n_cols );
  557. tmp.fill(val);
  558. (*this).operator=(tmp);
  559. }
  560. else
  561. {
  562. (*this).zeros();
  563. }
  564. }
  565. template<typename eT>
  566. inline
  567. void
  568. SpSubview<eT>::zeros()
  569. {
  570. arma_extra_debug_sigprint();
  571. if((n_elem == 0) || (n_nonzero == 0)) { return; }
  572. if((m.n_nonzero - n_nonzero) == 0)
  573. {
  574. access::rw(m).zeros();
  575. access::rw(n_nonzero) = 0;
  576. return;
  577. }
  578. SpMat<eT> tmp(arma_reserve_indicator(), m.n_rows, m.n_cols, m.n_nonzero - n_nonzero);
  579. const uword sv_row_start = aux_row1;
  580. const uword sv_col_start = aux_col1;
  581. const uword sv_row_end = aux_row1 + n_rows - 1;
  582. const uword sv_col_end = aux_col1 + n_cols - 1;
  583. typename SpMat<eT>::const_iterator m_it = m.begin();
  584. typename SpMat<eT>::const_iterator m_it_end = m.end();
  585. uword tmp_count = 0;
  586. for(; m_it != m_it_end; ++m_it)
  587. {
  588. const uword m_it_row = m_it.row();
  589. const uword m_it_col = m_it.col();
  590. const bool inside_box = ((m_it_row >= sv_row_start) && (m_it_row <= sv_row_end)) && ((m_it_col >= sv_col_start) && (m_it_col <= sv_col_end));
  591. if(inside_box == false)
  592. {
  593. access::rw(tmp.values[tmp_count]) = (*m_it);
  594. access::rw(tmp.row_indices[tmp_count]) = m_it_row;
  595. access::rw(tmp.col_ptrs[m_it_col + 1])++;
  596. ++tmp_count;
  597. }
  598. }
  599. for(uword i=0; i < tmp.n_cols; ++i)
  600. {
  601. access::rw(tmp.col_ptrs[i + 1]) += tmp.col_ptrs[i];
  602. }
  603. access::rw(m).steal_mem(tmp);
  604. access::rw(n_nonzero) = 0;
  605. }
  606. template<typename eT>
  607. inline
  608. void
  609. SpSubview<eT>::ones()
  610. {
  611. arma_extra_debug_sigprint();
  612. (*this).fill(eT(1));
  613. }
  614. template<typename eT>
  615. inline
  616. void
  617. SpSubview<eT>::eye()
  618. {
  619. arma_extra_debug_sigprint();
  620. SpMat<eT> tmp;
  621. tmp.eye( (*this).n_rows, (*this).n_cols );
  622. (*this).operator=(tmp);
  623. }
  624. template<typename eT>
  625. arma_hot
  626. inline
  627. SpSubview_MapMat_val<eT>
  628. SpSubview<eT>::operator[](const uword i)
  629. {
  630. const uword lrow = i % n_rows;
  631. const uword lcol = i / n_rows;
  632. return (*this).at(lrow, lcol);
  633. }
  634. template<typename eT>
  635. arma_hot
  636. inline
  637. eT
  638. SpSubview<eT>::operator[](const uword i) const
  639. {
  640. const uword lrow = i % n_rows;
  641. const uword lcol = i / n_rows;
  642. return (*this).at(lrow, lcol);
  643. }
  644. template<typename eT>
  645. arma_hot
  646. inline
  647. SpSubview_MapMat_val<eT>
  648. SpSubview<eT>::operator()(const uword i)
  649. {
  650. arma_debug_check( (i >= n_elem), "SpSubview::operator(): index out of bounds");
  651. const uword lrow = i % n_rows;
  652. const uword lcol = i / n_rows;
  653. return (*this).at(lrow, lcol);
  654. }
  655. template<typename eT>
  656. arma_hot
  657. inline
  658. eT
  659. SpSubview<eT>::operator()(const uword i) const
  660. {
  661. arma_debug_check( (i >= n_elem), "SpSubview::operator(): index out of bounds");
  662. const uword lrow = i % n_rows;
  663. const uword lcol = i / n_rows;
  664. return (*this).at(lrow, lcol);
  665. }
  666. template<typename eT>
  667. arma_hot
  668. inline
  669. SpSubview_MapMat_val<eT>
  670. SpSubview<eT>::operator()(const uword in_row, const uword in_col)
  671. {
  672. arma_debug_check( (in_row >= n_rows) || (in_col >= n_cols), "SpSubview::operator(): index out of bounds");
  673. return (*this).at(in_row, in_col);
  674. }
  675. template<typename eT>
  676. arma_hot
  677. inline
  678. eT
  679. SpSubview<eT>::operator()(const uword in_row, const uword in_col) const
  680. {
  681. arma_debug_check( (in_row >= n_rows) || (in_col >= n_cols), "SpSubview::operator(): index out of bounds");
  682. return (*this).at(in_row, in_col);
  683. }
  684. template<typename eT>
  685. arma_hot
  686. inline
  687. SpSubview_MapMat_val<eT>
  688. SpSubview<eT>::at(const uword i)
  689. {
  690. const uword lrow = i % n_rows;
  691. const uword lcol = i / n_cols;
  692. return (*this).at(lrow, lcol);
  693. }
  694. template<typename eT>
  695. arma_hot
  696. inline
  697. eT
  698. SpSubview<eT>::at(const uword i) const
  699. {
  700. const uword lrow = i % n_rows;
  701. const uword lcol = i / n_cols;
  702. return (*this).at(lrow, lcol);
  703. }
  704. template<typename eT>
  705. arma_hot
  706. inline
  707. SpSubview_MapMat_val<eT>
  708. SpSubview<eT>::at(const uword in_row, const uword in_col)
  709. {
  710. return SpSubview_MapMat_val<eT>((*this), m.cache, aux_row1 + in_row, aux_col1 + in_col);
  711. }
  712. template<typename eT>
  713. arma_hot
  714. inline
  715. eT
  716. SpSubview<eT>::at(const uword in_row, const uword in_col) const
  717. {
  718. return m.at(aux_row1 + in_row, aux_col1 + in_col);
  719. }
  720. template<typename eT>
  721. inline
  722. bool
  723. SpSubview<eT>::check_overlap(const SpSubview<eT>& x) const
  724. {
  725. const SpSubview<eT>& t = *this;
  726. if(&t.m != &x.m)
  727. {
  728. return false;
  729. }
  730. else
  731. {
  732. if( (t.n_elem == 0) || (x.n_elem == 0) )
  733. {
  734. return false;
  735. }
  736. else
  737. {
  738. const uword t_row_start = t.aux_row1;
  739. const uword t_row_end_p1 = t_row_start + t.n_rows;
  740. const uword t_col_start = t.aux_col1;
  741. const uword t_col_end_p1 = t_col_start + t.n_cols;
  742. const uword x_row_start = x.aux_row1;
  743. const uword x_row_end_p1 = x_row_start + x.n_rows;
  744. const uword x_col_start = x.aux_col1;
  745. const uword x_col_end_p1 = x_col_start + x.n_cols;
  746. const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) );
  747. const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) );
  748. return ( (outside_rows == false) && (outside_cols == false) );
  749. }
  750. }
  751. }
  752. template<typename eT>
  753. inline
  754. bool
  755. SpSubview<eT>::is_vec() const
  756. {
  757. return ( (n_rows == 1) || (n_cols == 1) );
  758. }
  759. template<typename eT>
  760. inline
  761. SpSubview_row<eT>
  762. SpSubview<eT>::row(const uword row_num)
  763. {
  764. arma_extra_debug_sigprint();
  765. arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds");
  766. return SpSubview_row<eT>(const_cast< SpMat<eT>& >(m), row_num + aux_row1, aux_col1, n_cols);
  767. }
  768. template<typename eT>
  769. inline
  770. const SpSubview_row<eT>
  771. SpSubview<eT>::row(const uword row_num) const
  772. {
  773. arma_extra_debug_sigprint();
  774. arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds");
  775. return SpSubview_row<eT>(m, row_num + aux_row1, aux_col1, n_cols);
  776. }
  777. template<typename eT>
  778. inline
  779. SpSubview_col<eT>
  780. SpSubview<eT>::col(const uword col_num)
  781. {
  782. arma_extra_debug_sigprint();
  783. arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds");
  784. return SpSubview_col<eT>(const_cast< SpMat<eT>& >(m), col_num + aux_col1, aux_row1, n_rows);
  785. }
  786. template<typename eT>
  787. inline
  788. const SpSubview_col<eT>
  789. SpSubview<eT>::col(const uword col_num) const
  790. {
  791. arma_extra_debug_sigprint();
  792. arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds");
  793. return SpSubview_col<eT>(m, col_num + aux_col1, aux_row1, n_rows);
  794. }
  795. template<typename eT>
  796. inline
  797. SpSubview<eT>
  798. SpSubview<eT>::rows(const uword in_row1, const uword in_row2)
  799. {
  800. arma_extra_debug_sigprint();
  801. arma_debug_check
  802. (
  803. (in_row1 > in_row2) || (in_row2 >= n_rows),
  804. "SpSubview::rows(): indices out of bounds or incorrectly used"
  805. );
  806. return submat(in_row1, 0, in_row2, n_cols - 1);
  807. }
  808. template<typename eT>
  809. inline
  810. const SpSubview<eT>
  811. SpSubview<eT>::rows(const uword in_row1, const uword in_row2) const
  812. {
  813. arma_extra_debug_sigprint();
  814. arma_debug_check
  815. (
  816. (in_row1 > in_row2) || (in_row2 >= n_rows),
  817. "SpSubview::rows(): indices out of bounds or incorrectly used"
  818. );
  819. return submat(in_row1, 0, in_row2, n_cols - 1);
  820. }
  821. template<typename eT>
  822. inline
  823. SpSubview<eT>
  824. SpSubview<eT>::cols(const uword in_col1, const uword in_col2)
  825. {
  826. arma_extra_debug_sigprint();
  827. arma_debug_check
  828. (
  829. (in_col1 > in_col2) || (in_col2 >= n_cols),
  830. "SpSubview::cols(): indices out of bounds or incorrectly used"
  831. );
  832. return submat(0, in_col1, n_rows - 1, in_col2);
  833. }
  834. template<typename eT>
  835. inline
  836. const SpSubview<eT>
  837. SpSubview<eT>::cols(const uword in_col1, const uword in_col2) const
  838. {
  839. arma_extra_debug_sigprint();
  840. arma_debug_check
  841. (
  842. (in_col1 > in_col2) || (in_col2 >= n_cols),
  843. "SpSubview::cols(): indices out of bounds or incorrectly used"
  844. );
  845. return submat(0, in_col1, n_rows - 1, in_col2);
  846. }
  847. template<typename eT>
  848. inline
  849. SpSubview<eT>
  850. SpSubview<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
  851. {
  852. arma_extra_debug_sigprint();
  853. arma_debug_check
  854. (
  855. (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
  856. "SpSubview::submat(): indices out of bounds or incorrectly used"
  857. );
  858. return access::rw(m).submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row1, in_col2 + aux_col1);
  859. }
  860. template<typename eT>
  861. inline
  862. const SpSubview<eT>
  863. SpSubview<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const
  864. {
  865. arma_extra_debug_sigprint();
  866. arma_debug_check
  867. (
  868. (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
  869. "SpSubview::submat(): indices out of bounds or incorrectly used"
  870. );
  871. return m.submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row1, in_col2 + aux_col1);
  872. }
  873. template<typename eT>
  874. inline
  875. SpSubview<eT>
  876. SpSubview<eT>::submat(const span& row_span, const span& col_span)
  877. {
  878. arma_extra_debug_sigprint();
  879. const bool row_all = row_span.whole;
  880. const bool col_all = row_span.whole;
  881. const uword in_row1 = row_all ? 0 : row_span.a;
  882. const uword in_row2 = row_all ? n_rows : row_span.b;
  883. const uword in_col1 = col_all ? 0 : col_span.a;
  884. const uword in_col2 = col_all ? n_cols : col_span.b;
  885. arma_debug_check
  886. (
  887. ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows)))
  888. ||
  889. ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))),
  890. "SpSubview::submat(): indices out of bounds or incorrectly used"
  891. );
  892. return submat(in_row1, in_col1, in_row2, in_col2);
  893. }
  894. template<typename eT>
  895. inline
  896. const SpSubview<eT>
  897. SpSubview<eT>::submat(const span& row_span, const span& col_span) const
  898. {
  899. arma_extra_debug_sigprint();
  900. const bool row_all = row_span.whole;
  901. const bool col_all = row_span.whole;
  902. const uword in_row1 = row_all ? 0 : row_span.a;
  903. const uword in_row2 = row_all ? n_rows - 1 : row_span.b;
  904. const uword in_col1 = col_all ? 0 : col_span.a;
  905. const uword in_col2 = col_all ? n_cols - 1 : col_span.b;
  906. arma_debug_check
  907. (
  908. ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows)))
  909. ||
  910. ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))),
  911. "SpSubview::submat(): indices out of bounds or incorrectly used"
  912. );
  913. return submat(in_row1, in_col1, in_row2, in_col2);
  914. }
  915. template<typename eT>
  916. inline
  917. SpSubview<eT>
  918. SpSubview<eT>::operator()(const uword row_num, const span& col_span)
  919. {
  920. arma_extra_debug_sigprint();
  921. return submat(span(row_num, row_num), col_span);
  922. }
  923. template<typename eT>
  924. inline
  925. const SpSubview<eT>
  926. SpSubview<eT>::operator()(const uword row_num, const span& col_span) const
  927. {
  928. arma_extra_debug_sigprint();
  929. return submat(span(row_num, row_num), col_span);
  930. }
  931. template<typename eT>
  932. inline
  933. SpSubview<eT>
  934. SpSubview<eT>::operator()(const span& row_span, const uword col_num)
  935. {
  936. arma_extra_debug_sigprint();
  937. return submat(row_span, span(col_num, col_num));
  938. }
  939. template<typename eT>
  940. inline
  941. const SpSubview<eT>
  942. SpSubview<eT>::operator()(const span& row_span, const uword col_num) const
  943. {
  944. arma_extra_debug_sigprint();
  945. return submat(row_span, span(col_num, col_num));
  946. }
  947. template<typename eT>
  948. inline
  949. SpSubview<eT>
  950. SpSubview<eT>::operator()(const span& row_span, const span& col_span)
  951. {
  952. arma_extra_debug_sigprint();
  953. return submat(row_span, col_span);
  954. }
  955. template<typename eT>
  956. inline
  957. const SpSubview<eT>
  958. SpSubview<eT>::operator()(const span& row_span, const span& col_span) const
  959. {
  960. arma_extra_debug_sigprint();
  961. return submat(row_span, col_span);
  962. }
  963. template<typename eT>
  964. inline
  965. void
  966. SpSubview<eT>::swap_rows(const uword in_row1, const uword in_row2)
  967. {
  968. arma_extra_debug_sigprint();
  969. arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview::swap_rows(): invalid row index");
  970. const uword lstart_col = aux_col1;
  971. const uword lend_col = aux_col1 + n_cols;
  972. for(uword c = lstart_col; c < lend_col; ++c)
  973. {
  974. const eT val = access::rw(m).at(in_row1 + aux_row1, c);
  975. access::rw(m).at(in_row2 + aux_row1, c) = eT( access::rw(m).at(in_row1 + aux_row1, c) );
  976. access::rw(m).at(in_row1 + aux_row1, c) = val;
  977. }
  978. }
  979. template<typename eT>
  980. inline
  981. void
  982. SpSubview<eT>::swap_cols(const uword in_col1, const uword in_col2)
  983. {
  984. arma_extra_debug_sigprint();
  985. arma_debug_check((in_col1 >= n_cols) || (in_col2 >= n_cols), "SpSubview::swap_cols(): invalid column index");
  986. const uword lstart_row = aux_row1;
  987. const uword lend_row = aux_row1 + n_rows;
  988. for(uword r = lstart_row; r < lend_row; ++r)
  989. {
  990. const eT val = access::rw(m).at(r, in_col1 + aux_col1);
  991. access::rw(m).at(r, in_col1 + aux_col1) = eT( access::rw(m).at(r, in_col2 + aux_col1) );
  992. access::rw(m).at(r, in_col2 + aux_col1) = val;
  993. }
  994. }
  995. template<typename eT>
  996. inline
  997. typename SpSubview<eT>::iterator
  998. SpSubview<eT>::begin()
  999. {
  1000. return iterator(*this);
  1001. }
  1002. template<typename eT>
  1003. inline
  1004. typename SpSubview<eT>::const_iterator
  1005. SpSubview<eT>::begin() const
  1006. {
  1007. m.sync_csc();
  1008. return const_iterator(*this);
  1009. }
  1010. template<typename eT>
  1011. inline
  1012. typename SpSubview<eT>::const_iterator
  1013. SpSubview<eT>::cbegin() const
  1014. {
  1015. m.sync_csc();
  1016. return const_iterator(*this);
  1017. }
  1018. template<typename eT>
  1019. inline
  1020. typename SpSubview<eT>::iterator
  1021. SpSubview<eT>::begin_col(const uword col_num)
  1022. {
  1023. m.sync_csc();
  1024. return iterator(*this, 0, col_num);
  1025. }
  1026. template<typename eT>
  1027. inline
  1028. typename SpSubview<eT>::const_iterator
  1029. SpSubview<eT>::begin_col(const uword col_num) const
  1030. {
  1031. m.sync_csc();
  1032. return const_iterator(*this, 0, col_num);
  1033. }
  1034. template<typename eT>
  1035. inline
  1036. typename SpSubview<eT>::row_iterator
  1037. SpSubview<eT>::begin_row(const uword row_num)
  1038. {
  1039. m.sync_csc();
  1040. return row_iterator(*this, row_num, 0);
  1041. }
  1042. template<typename eT>
  1043. inline
  1044. typename SpSubview<eT>::const_row_iterator
  1045. SpSubview<eT>::begin_row(const uword row_num) const
  1046. {
  1047. m.sync_csc();
  1048. return const_row_iterator(*this, row_num, 0);
  1049. }
  1050. template<typename eT>
  1051. inline
  1052. typename SpSubview<eT>::iterator
  1053. SpSubview<eT>::end()
  1054. {
  1055. m.sync_csc();
  1056. return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero);
  1057. }
  1058. template<typename eT>
  1059. inline
  1060. typename SpSubview<eT>::const_iterator
  1061. SpSubview<eT>::end() const
  1062. {
  1063. m.sync_csc();
  1064. return const_iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero);
  1065. }
  1066. template<typename eT>
  1067. inline
  1068. typename SpSubview<eT>::const_iterator
  1069. SpSubview<eT>::cend() const
  1070. {
  1071. m.sync_csc();
  1072. return const_iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero);
  1073. }
  1074. template<typename eT>
  1075. inline
  1076. typename SpSubview<eT>::row_iterator
  1077. SpSubview<eT>::end_row()
  1078. {
  1079. m.sync_csc();
  1080. return row_iterator(*this, n_nonzero);
  1081. }
  1082. template<typename eT>
  1083. inline
  1084. typename SpSubview<eT>::const_row_iterator
  1085. SpSubview<eT>::end_row() const
  1086. {
  1087. m.sync_csc();
  1088. return const_row_iterator(*this, n_nonzero);
  1089. }
  1090. template<typename eT>
  1091. inline
  1092. typename SpSubview<eT>::row_iterator
  1093. SpSubview<eT>::end_row(const uword row_num)
  1094. {
  1095. m.sync_csc();
  1096. return row_iterator(*this, row_num + 1, 0);
  1097. }
  1098. template<typename eT>
  1099. inline
  1100. typename SpSubview<eT>::const_row_iterator
  1101. SpSubview<eT>::end_row(const uword row_num) const
  1102. {
  1103. m.sync_csc();
  1104. return const_row_iterator(*this, row_num + 1, 0);
  1105. }
  1106. template<typename eT>
  1107. arma_inline
  1108. bool
  1109. SpSubview<eT>::is_alias(const SpMat<eT>& X) const
  1110. {
  1111. return m.is_alias(X);
  1112. }
  1113. template<typename eT>
  1114. inline
  1115. arma_warn_unused
  1116. eT&
  1117. SpSubview<eT>::insert_element(const uword in_row, const uword in_col, const eT in_val)
  1118. {
  1119. arma_extra_debug_sigprint();
  1120. // This may not actually insert an element.
  1121. const uword old_n_nonzero = m.n_nonzero;
  1122. eT& retval = access::rw(m).insert_element(in_row + aux_row1, in_col + aux_col1, in_val);
  1123. // Update n_nonzero (if necessary).
  1124. access::rw(n_nonzero) += (m.n_nonzero - old_n_nonzero);
  1125. return retval;
  1126. }
  1127. template<typename eT>
  1128. inline
  1129. void
  1130. SpSubview<eT>::delete_element(const uword in_row, const uword in_col)
  1131. {
  1132. arma_extra_debug_sigprint();
  1133. // This may not actually delete an element.
  1134. const uword old_n_nonzero = m.n_nonzero;
  1135. access::rw(m).delete_element(in_row + aux_row1, in_col + aux_col1);
  1136. access::rw(n_nonzero) -= (old_n_nonzero - m.n_nonzero);
  1137. }
  1138. template<typename eT>
  1139. inline
  1140. void
  1141. SpSubview<eT>::invalidate_cache() const
  1142. {
  1143. arma_extra_debug_sigprint();
  1144. m.invalidate_cache();
  1145. }
  1146. //
  1147. //
  1148. //
  1149. template<typename eT>
  1150. inline
  1151. SpSubview_col<eT>::SpSubview_col(const SpMat<eT>& in_m, const uword in_col)
  1152. : SpSubview<eT>(in_m, 0, in_col, in_m.n_rows, 1)
  1153. {
  1154. arma_extra_debug_sigprint();
  1155. }
  1156. template<typename eT>
  1157. inline
  1158. SpSubview_col<eT>::SpSubview_col(SpMat<eT>& in_m, const uword in_col)
  1159. : SpSubview<eT>(in_m, 0, in_col, in_m.n_rows, 1)
  1160. {
  1161. arma_extra_debug_sigprint();
  1162. }
  1163. template<typename eT>
  1164. inline
  1165. SpSubview_col<eT>::SpSubview_col(const SpMat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows)
  1166. : SpSubview<eT>(in_m, in_row1, in_col, in_n_rows, 1)
  1167. {
  1168. arma_extra_debug_sigprint();
  1169. }
  1170. template<typename eT>
  1171. inline
  1172. SpSubview_col<eT>::SpSubview_col(SpMat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows)
  1173. : SpSubview<eT>(in_m, in_row1, in_col, in_n_rows, 1)
  1174. {
  1175. arma_extra_debug_sigprint();
  1176. }
  1177. template<typename eT>
  1178. inline
  1179. void
  1180. SpSubview_col<eT>::operator=(const SpSubview<eT>& x)
  1181. {
  1182. arma_extra_debug_sigprint();
  1183. SpSubview<eT>::operator=(x);
  1184. }
  1185. template<typename eT>
  1186. inline
  1187. void
  1188. SpSubview_col<eT>::operator=(const SpSubview_col<eT>& x)
  1189. {
  1190. arma_extra_debug_sigprint();
  1191. SpSubview<eT>::operator=(x); // interprets 'SpSubview_col' as 'SpSubview'
  1192. }
  1193. template<typename eT>
  1194. template<typename T1>
  1195. inline
  1196. void
  1197. SpSubview_col<eT>::operator=(const SpBase<eT,T1>& x)
  1198. {
  1199. arma_extra_debug_sigprint();
  1200. SpSubview<eT>::operator=(x);
  1201. }
  1202. template<typename eT>
  1203. template<typename T1>
  1204. inline
  1205. void
  1206. SpSubview_col<eT>::operator=(const Base<eT,T1>& x)
  1207. {
  1208. arma_extra_debug_sigprint();
  1209. SpSubview<eT>::operator=(x);
  1210. }
  1211. template<typename eT>
  1212. inline
  1213. const SpOp<SpSubview_col<eT>,spop_htrans>
  1214. SpSubview_col<eT>::t() const
  1215. {
  1216. return SpOp<SpSubview_col<eT>,spop_htrans>(*this);
  1217. }
  1218. template<typename eT>
  1219. inline
  1220. const SpOp<SpSubview_col<eT>,spop_htrans>
  1221. SpSubview_col<eT>::ht() const
  1222. {
  1223. return SpOp<SpSubview_col<eT>,spop_htrans>(*this);
  1224. }
  1225. template<typename eT>
  1226. inline
  1227. const SpOp<SpSubview_col<eT>,spop_strans>
  1228. SpSubview_col<eT>::st() const
  1229. {
  1230. return SpOp<SpSubview_col<eT>,spop_strans>(*this);
  1231. }
  1232. //
  1233. //
  1234. //
  1235. template<typename eT>
  1236. inline
  1237. SpSubview_row<eT>::SpSubview_row(const SpMat<eT>& in_m, const uword in_row)
  1238. : SpSubview<eT>(in_m, in_row, 0, 1, in_m.n_cols)
  1239. {
  1240. arma_extra_debug_sigprint();
  1241. }
  1242. template<typename eT>
  1243. inline
  1244. SpSubview_row<eT>::SpSubview_row(SpMat<eT>& in_m, const uword in_row)
  1245. : SpSubview<eT>(in_m, in_row, 0, 1, in_m.n_cols)
  1246. {
  1247. arma_extra_debug_sigprint();
  1248. }
  1249. template<typename eT>
  1250. inline
  1251. SpSubview_row<eT>::SpSubview_row(const SpMat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols)
  1252. : SpSubview<eT>(in_m, in_row, in_col1, 1, in_n_cols)
  1253. {
  1254. arma_extra_debug_sigprint();
  1255. }
  1256. template<typename eT>
  1257. inline
  1258. SpSubview_row<eT>::SpSubview_row(SpMat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols)
  1259. : SpSubview<eT>(in_m, in_row, in_col1, 1, in_n_cols)
  1260. {
  1261. arma_extra_debug_sigprint();
  1262. }
  1263. template<typename eT>
  1264. inline
  1265. void
  1266. SpSubview_row<eT>::operator=(const SpSubview<eT>& x)
  1267. {
  1268. arma_extra_debug_sigprint();
  1269. SpSubview<eT>::operator=(x);
  1270. }
  1271. template<typename eT>
  1272. inline
  1273. void
  1274. SpSubview_row<eT>::operator=(const SpSubview_row<eT>& x)
  1275. {
  1276. arma_extra_debug_sigprint();
  1277. SpSubview<eT>::operator=(x); // interprets 'SpSubview_row' as 'SpSubview'
  1278. }
  1279. template<typename eT>
  1280. template<typename T1>
  1281. inline
  1282. void
  1283. SpSubview_row<eT>::operator=(const SpBase<eT,T1>& x)
  1284. {
  1285. arma_extra_debug_sigprint();
  1286. SpSubview<eT>::operator=(x);
  1287. }
  1288. template<typename eT>
  1289. template<typename T1>
  1290. inline
  1291. void
  1292. SpSubview_row<eT>::operator=(const Base<eT,T1>& x)
  1293. {
  1294. arma_extra_debug_sigprint();
  1295. SpSubview<eT>::operator=(x);
  1296. }
  1297. template<typename eT>
  1298. inline
  1299. const SpOp<SpSubview_row<eT>,spop_htrans>
  1300. SpSubview_row<eT>::t() const
  1301. {
  1302. return SpOp<SpSubview_row<eT>,spop_htrans>(*this);
  1303. }
  1304. template<typename eT>
  1305. inline
  1306. const SpOp<SpSubview_row<eT>,spop_htrans>
  1307. SpSubview_row<eT>::ht() const
  1308. {
  1309. return SpOp<SpSubview_row<eT>,spop_htrans>(*this);
  1310. }
  1311. template<typename eT>
  1312. inline
  1313. const SpOp<SpSubview_row<eT>,spop_strans>
  1314. SpSubview_row<eT>::st() const
  1315. {
  1316. return SpOp<SpSubview_row<eT>,spop_strans>(*this);
  1317. }
  1318. //! @}