You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

605 lines
26 KiB

  1. /* -*- c++ -*- (enables emacs c++ mode) */
  2. /*===========================================================================
  3. Copyright (C) 2003-2017 Yves Renard
  4. This file is a part of GetFEM++
  5. GetFEM++ is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Lesser General Public License as published
  7. by the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version along with the GCC Runtime Library
  9. Exception either version 3.1 or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License and GCC Runtime Library Exception for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  17. As a special exception, you may use this file as it is a part of a free
  18. software library without restriction. Specifically, if other files
  19. instantiate templates or use macros or inline functions from this file,
  20. or you compile this file and link it with other files to produce an
  21. executable, this file does not by itself cause the resulting executable
  22. to be covered by the GNU Lesser General Public License. This exception
  23. does not however invalidate any other reasons why the executable file
  24. might be covered by the GNU Lesser General Public License.
  25. ===========================================================================*/
  26. /**@file gmm_real_part.h
  27. @author Yves Renard <Yves.Renard@insa-lyon.fr>
  28. @date September 18, 2003.
  29. @brief extract the real/imaginary part of vectors/matrices
  30. */
  31. #ifndef GMM_REAL_PART_H
  32. #define GMM_REAL_PART_H
  33. #include "gmm_def.h"
  34. #include "gmm_vector.h"
  35. namespace gmm {
  36. struct linalg_real_part {};
  37. struct linalg_imag_part {};
  38. template <typename R, typename PART> struct which_part {};
  39. template <typename C> typename number_traits<C>::magnitude_type
  40. real_or_imag_part(C x, linalg_real_part) { return gmm::real(x); }
  41. template <typename C> typename number_traits<C>::magnitude_type
  42. real_or_imag_part(C x, linalg_imag_part) { return gmm::imag(x); }
  43. template <typename T, typename C, typename OP> C
  44. complex_from(T x, C y, OP op, linalg_real_part) { return std::complex<T>(op(std::real(y), x), std::imag(y)); }
  45. template <typename T, typename C, typename OP> C
  46. complex_from(T x, C y, OP op,linalg_imag_part) { return std::complex<T>(std::real(y), op(std::imag(y), x)); }
  47. template<typename T> struct project2nd {
  48. T operator()(T , T b) const { return b; }
  49. };
  50. template<typename T, typename R, typename PART> class ref_elt_vector<T, which_part<R, PART> > {
  51. R r;
  52. public :
  53. operator T() const { return real_or_imag_part(std::complex<T>(r), PART()); }
  54. ref_elt_vector(R r_) : r(r_) {}
  55. inline ref_elt_vector &operator =(T v)
  56. { r = complex_from(v, std::complex<T>(r), gmm::project2nd<T>(), PART()); return *this; }
  57. inline bool operator ==(T v) const { return (r == v); }
  58. inline bool operator !=(T v) const { return (r != v); }
  59. inline ref_elt_vector &operator +=(T v)
  60. { r = complex_from(v, std::complex<T>(r), std::plus<T>(), PART()); return *this; }
  61. inline ref_elt_vector &operator -=(T v)
  62. { r = complex_from(v, std::complex<T>(r), std::minus<T>(), PART()); return *this; }
  63. inline ref_elt_vector &operator /=(T v)
  64. { r = complex_from(v, std::complex<T>(r), std::divides<T>(), PART()); return *this; }
  65. inline ref_elt_vector &operator *=(T v)
  66. { r = complex_from(v, std::complex<T>(r), std::multiplies<T>(), PART()); return *this; }
  67. inline ref_elt_vector &operator =(const ref_elt_vector &re)
  68. { *this = T(re); return *this; }
  69. T operator +() { return T(*this); } // necessary for unknow reason
  70. T operator -() { return -T(*this); } // necessary for unknow reason
  71. T operator +(T v) { return T(*this)+ v; } // necessary for unknow reason
  72. T operator -(T v) { return T(*this)- v; } // necessary for unknow reason
  73. T operator *(T v) { return T(*this)* v; } // necessary for unknow reason
  74. T operator /(T v) { return T(*this)/ v; } // necessary for unknow reason
  75. };
  76. template<typename reference> struct ref_or_value_type {
  77. template <typename T, typename W>
  78. static W r(const T &x, linalg_real_part, W) {
  79. return gmm::real(x);
  80. }
  81. template <typename T, typename W>
  82. static W r(const T &x, linalg_imag_part, W) {
  83. return gmm::imag(x);
  84. }
  85. };
  86. template<typename U, typename R, typename PART>
  87. struct ref_or_value_type<ref_elt_vector<U, which_part<R, PART> > > {
  88. template<typename T , typename W>
  89. static const T &r(const T &x, linalg_real_part, W)
  90. { return x; }
  91. template<typename T, typename W>
  92. static const T &r(const T &x, linalg_imag_part, W) {
  93. return x;
  94. }
  95. template<typename T , typename W>
  96. static T &r(T &x, linalg_real_part, W)
  97. { return x; }
  98. template<typename T, typename W>
  99. static T &r(T &x, linalg_imag_part, W) {
  100. return x;
  101. }
  102. };
  103. /* ********************************************************************* */
  104. /* Reference to the real part of (complex) vectors */
  105. /* ********************************************************************* */
  106. template <typename IT, typename MIT, typename PART>
  107. struct part_vector_iterator {
  108. typedef typename std::iterator_traits<IT>::value_type vtype;
  109. typedef typename gmm::number_traits<vtype>::magnitude_type value_type;
  110. typedef value_type *pointer;
  111. typedef ref_elt_vector<value_type, which_part<typename std::iterator_traits<IT>::reference, PART> > reference;
  112. typedef typename std::iterator_traits<IT>::difference_type difference_type;
  113. typedef typename std::iterator_traits<IT>::iterator_category
  114. iterator_category;
  115. IT it;
  116. part_vector_iterator(void) {}
  117. explicit part_vector_iterator(const IT &i) : it(i) {}
  118. part_vector_iterator(const part_vector_iterator<MIT, MIT, PART> &i) : it(i.it) {}
  119. size_type index(void) const { return it.index(); }
  120. part_vector_iterator operator ++(int)
  121. { part_vector_iterator tmp = *this; ++it; return tmp; }
  122. part_vector_iterator operator --(int)
  123. { part_vector_iterator tmp = *this; --it; return tmp; }
  124. part_vector_iterator &operator ++() { ++it; return *this; }
  125. part_vector_iterator &operator --() { --it; return *this; }
  126. part_vector_iterator &operator +=(difference_type i)
  127. { it += i; return *this; }
  128. part_vector_iterator &operator -=(difference_type i)
  129. { it -= i; return *this; }
  130. part_vector_iterator operator +(difference_type i) const
  131. { part_vector_iterator itb = *this; return (itb += i); }
  132. part_vector_iterator operator -(difference_type i) const
  133. { part_vector_iterator itb = *this; return (itb -= i); }
  134. difference_type operator -(const part_vector_iterator &i) const
  135. { return difference_type(it - i.it); }
  136. reference operator *() const { return reference(*it); }
  137. reference operator [](size_type ii) const { return reference(it[ii]); }
  138. bool operator ==(const part_vector_iterator &i) const
  139. { return (i.it == it); }
  140. bool operator !=(const part_vector_iterator &i) const
  141. { return (i.it != it); }
  142. bool operator < (const part_vector_iterator &i) const
  143. { return (it < i.it); }
  144. };
  145. template <typename PT, typename PART> struct part_vector {
  146. typedef part_vector<PT, PART> this_type;
  147. typedef typename std::iterator_traits<PT>::value_type V;
  148. typedef V * CPT;
  149. typedef typename select_ref<typename linalg_traits<V>::const_iterator,
  150. typename linalg_traits<V>::iterator, PT>::ref_type iterator;
  151. typedef typename linalg_traits<this_type>::reference reference;
  152. typedef typename linalg_traits<this_type>::value_type value_type;
  153. typedef typename linalg_traits<this_type>::porigin_type porigin_type;
  154. iterator begin_, end_;
  155. porigin_type origin;
  156. size_type size_;
  157. size_type size(void) const { return size_; }
  158. reference operator[](size_type i) const {
  159. return reference(ref_or_value_type<reference>::r(
  160. linalg_traits<V>::access(origin, begin_, end_, i),
  161. PART(), value_type()));
  162. }
  163. part_vector(V &v)
  164. : begin_(vect_begin(v)), end_(vect_end(v)),
  165. origin(linalg_origin(v)), size_(gmm::vect_size(v)) {}
  166. part_vector(const V &v)
  167. : begin_(vect_begin(const_cast<V &>(v))),
  168. end_(vect_end(const_cast<V &>(v))),
  169. origin(linalg_origin(const_cast<V &>(v))), size_(gmm::vect_size(v)) {}
  170. part_vector() {}
  171. part_vector(const part_vector<CPT, PART> &cr)
  172. : begin_(cr.begin_),end_(cr.end_),origin(cr.origin), size_(cr.size_) {}
  173. };
  174. template <typename IT, typename MIT, typename ORG, typename PT,
  175. typename PART> inline
  176. void set_to_begin(part_vector_iterator<IT, MIT, PART> &it,
  177. ORG o, part_vector<PT, PART> *, linalg_modifiable) {
  178. typedef part_vector<PT, PART> VECT;
  179. typedef typename linalg_traits<VECT>::V_reference ref_t;
  180. set_to_begin(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
  181. }
  182. template <typename IT, typename MIT, typename ORG, typename PT,
  183. typename PART> inline
  184. void set_to_begin(part_vector_iterator<IT, MIT, PART> &it,
  185. ORG o, const part_vector<PT, PART> *, linalg_modifiable) {
  186. typedef part_vector<PT, PART> VECT;
  187. typedef typename linalg_traits<VECT>::V_reference ref_t;
  188. set_to_begin(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
  189. }
  190. template <typename IT, typename MIT, typename ORG, typename PT,
  191. typename PART> inline
  192. void set_to_end(part_vector_iterator<IT, MIT, PART> &it,
  193. ORG o, part_vector<PT, PART> *, linalg_modifiable) {
  194. typedef part_vector<PT, PART> VECT;
  195. typedef typename linalg_traits<VECT>::V_reference ref_t;
  196. set_to_end(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
  197. }
  198. template <typename IT, typename MIT, typename ORG,
  199. typename PT, typename PART> inline
  200. void set_to_end(part_vector_iterator<IT, MIT, PART> &it,
  201. ORG o, const part_vector<PT, PART> *,
  202. linalg_modifiable) {
  203. typedef part_vector<PT, PART> VECT;
  204. typedef typename linalg_traits<VECT>::V_reference ref_t;
  205. set_to_end(it.it, o, typename linalg_traits<VECT>::pV(), ref_t());
  206. }
  207. template <typename PT, typename PART> std::ostream &operator <<
  208. (std::ostream &o, const part_vector<PT, PART>& m)
  209. { gmm::write(o,m); return o; }
  210. /* ********************************************************************* */
  211. /* Reference to the real or imaginary part of (complex) matrices */
  212. /* ********************************************************************* */
  213. template <typename PT, typename PART> struct part_row_ref {
  214. typedef part_row_ref<PT, PART> this_type;
  215. typedef typename std::iterator_traits<PT>::value_type M;
  216. typedef M * CPT;
  217. typedef typename std::iterator_traits<PT>::reference ref_M;
  218. typedef typename select_ref<typename linalg_traits<this_type>
  219. ::const_row_iterator, typename linalg_traits<this_type>
  220. ::row_iterator, PT>::ref_type iterator;
  221. typedef typename linalg_traits<this_type>::value_type value_type;
  222. typedef typename linalg_traits<this_type>::reference reference;
  223. typedef typename linalg_traits<this_type>::porigin_type porigin_type;
  224. iterator begin_, end_;
  225. porigin_type origin;
  226. size_type nr, nc;
  227. part_row_ref(ref_M m)
  228. : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
  229. origin(linalg_origin(m)), nr(mat_nrows(m)), nc(mat_ncols(m)) {}
  230. part_row_ref(const part_row_ref<CPT, PART> &cr) :
  231. begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
  232. reference operator()(size_type i, size_type j) const {
  233. return reference(ref_or_value_type<reference>::r(
  234. linalg_traits<M>::access(begin_+i, j),
  235. PART(), value_type()));
  236. }
  237. };
  238. template<typename PT, typename PART> std::ostream &operator <<
  239. (std::ostream &o, const part_row_ref<PT, PART>& m)
  240. { gmm::write(o,m); return o; }
  241. template <typename PT, typename PART> struct part_col_ref {
  242. typedef part_col_ref<PT, PART> this_type;
  243. typedef typename std::iterator_traits<PT>::value_type M;
  244. typedef M * CPT;
  245. typedef typename std::iterator_traits<PT>::reference ref_M;
  246. typedef typename select_ref<typename linalg_traits<this_type>
  247. ::const_col_iterator, typename linalg_traits<this_type>
  248. ::col_iterator, PT>::ref_type iterator;
  249. typedef typename linalg_traits<this_type>::value_type value_type;
  250. typedef typename linalg_traits<this_type>::reference reference;
  251. typedef typename linalg_traits<this_type>::porigin_type porigin_type;
  252. iterator begin_, end_;
  253. porigin_type origin;
  254. size_type nr, nc;
  255. part_col_ref(ref_M m)
  256. : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
  257. origin(linalg_origin(m)), nr(mat_nrows(m)), nc(mat_ncols(m)) {}
  258. part_col_ref(const part_col_ref<CPT, PART> &cr) :
  259. begin_(cr.begin_),end_(cr.end_), origin(cr.origin),nr(cr.nr),nc(cr.nc) {}
  260. reference operator()(size_type i, size_type j) const {
  261. return reference(ref_or_value_type<reference>::r(
  262. linalg_traits<M>::access(begin_+j, i),
  263. PART(), value_type()));
  264. }
  265. };
  266. template<typename PT, typename PART> std::ostream &operator <<
  267. (std::ostream &o, const part_col_ref<PT, PART>& m)
  268. { gmm::write(o,m); return o; }
  269. template <typename TYPE, typename PART, typename PT>
  270. struct part_return_ {
  271. typedef abstract_null_type return_type;
  272. };
  273. template <typename PT, typename PART>
  274. struct part_return_<row_major, PART, PT> {
  275. typedef typename std::iterator_traits<PT>::value_type L;
  276. typedef typename select_return<part_row_ref<const L *, PART>,
  277. part_row_ref< L *, PART>, PT>::return_type return_type;
  278. };
  279. template <typename PT, typename PART>
  280. struct part_return_<col_major, PART, PT> {
  281. typedef typename std::iterator_traits<PT>::value_type L;
  282. typedef typename select_return<part_col_ref<const L *, PART>,
  283. part_col_ref<L *, PART>, PT>::return_type return_type;
  284. };
  285. template <typename PT, typename PART, typename LT> struct part_return__{
  286. typedef abstract_null_type return_type;
  287. };
  288. template <typename PT, typename PART>
  289. struct part_return__<PT, PART, abstract_matrix> {
  290. typedef typename std::iterator_traits<PT>::value_type L;
  291. typedef typename part_return_<typename principal_orientation_type<
  292. typename linalg_traits<L>::sub_orientation>::potype, PART,
  293. PT>::return_type return_type;
  294. };
  295. template <typename PT, typename PART>
  296. struct part_return__<PT, PART, abstract_vector> {
  297. typedef typename std::iterator_traits<PT>::value_type L;
  298. typedef typename select_return<part_vector<const L *, PART>,
  299. part_vector<L *, PART>, PT>::return_type return_type;
  300. };
  301. template <typename PT, typename PART> struct part_return {
  302. typedef typename std::iterator_traits<PT>::value_type L;
  303. typedef typename part_return__<PT, PART,
  304. typename linalg_traits<L>::linalg_type>::return_type return_type;
  305. };
  306. template <typename L> inline
  307. typename part_return<const L *, linalg_real_part>::return_type
  308. real_part(const L &l) {
  309. return typename part_return<const L *, linalg_real_part>::return_type
  310. (linalg_cast(const_cast<L &>(l)));
  311. }
  312. template <typename L> inline
  313. typename part_return<L *, linalg_real_part>::return_type
  314. real_part(L &l) {
  315. return typename part_return<L *, linalg_real_part>::return_type(linalg_cast(l));
  316. }
  317. template <typename L> inline
  318. typename part_return<const L *, linalg_imag_part>::return_type
  319. imag_part(const L &l) {
  320. return typename part_return<const L *, linalg_imag_part>::return_type
  321. (linalg_cast(const_cast<L &>(l)));
  322. }
  323. template <typename L> inline
  324. typename part_return<L *, linalg_imag_part>::return_type
  325. imag_part(L &l) {
  326. return typename part_return<L *, linalg_imag_part>::return_type(linalg_cast(l));
  327. }
  328. template <typename PT, typename PART>
  329. struct linalg_traits<part_vector<PT, PART> > {
  330. typedef part_vector<PT, PART> this_type;
  331. typedef this_type * pthis_type;
  332. typedef PT pV;
  333. typedef typename std::iterator_traits<PT>::value_type V;
  334. typedef typename linalg_traits<V>::index_sorted index_sorted;
  335. typedef typename linalg_traits<V>::is_reference V_reference;
  336. typedef typename linalg_traits<V>::origin_type origin_type;
  337. typedef typename select_ref<const origin_type *, origin_type *,
  338. PT>::ref_type porigin_type;
  339. typedef typename which_reference<PT>::is_reference is_reference;
  340. typedef abstract_vector linalg_type;
  341. typedef typename linalg_traits<V>::value_type vtype;
  342. typedef typename number_traits<vtype>::magnitude_type value_type;
  343. typedef typename select_ref<value_type, ref_elt_vector<value_type,
  344. which_part<typename linalg_traits<V>::reference,
  345. PART> >, PT>::ref_type reference;
  346. typedef typename select_ref<typename linalg_traits<V>::const_iterator,
  347. typename linalg_traits<V>::iterator, PT>::ref_type pre_iterator;
  348. typedef typename select_ref<abstract_null_type,
  349. part_vector_iterator<pre_iterator, pre_iterator, PART>,
  350. PT>::ref_type iterator;
  351. typedef part_vector_iterator<typename linalg_traits<V>::const_iterator,
  352. pre_iterator, PART> const_iterator;
  353. typedef typename linalg_traits<V>::storage_type storage_type;
  354. static size_type size(const this_type &v) { return v.size(); }
  355. static iterator begin(this_type &v) {
  356. iterator it; it.it = v.begin_;
  357. if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
  358. set_to_begin(it, v.origin, pthis_type(), is_reference());
  359. return it;
  360. }
  361. static const_iterator begin(const this_type &v) {
  362. const_iterator it(v.begin_);
  363. if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
  364. { set_to_begin(it, v.origin, pthis_type(), is_reference()); }
  365. return it;
  366. }
  367. static iterator end(this_type &v) {
  368. iterator it(v.end_);
  369. if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
  370. set_to_end(it, v.origin, pthis_type(), is_reference());
  371. return it;
  372. }
  373. static const_iterator end(const this_type &v) {
  374. const_iterator it(v.end_);
  375. if (!is_const_reference(is_reference()) && is_sparse(storage_type()))
  376. set_to_end(it, v.origin, pthis_type(), is_reference());
  377. return it;
  378. }
  379. static origin_type* origin(this_type &v) { return v.origin; }
  380. static const origin_type* origin(const this_type &v) { return v.origin; }
  381. static void clear(origin_type* o, const iterator &begin_,
  382. const iterator &end_, abstract_sparse) {
  383. std::deque<size_type> ind;
  384. iterator it = begin_;
  385. for (; it != end_; ++it) ind.push_front(it.index());
  386. for (; !(ind.empty()); ind.pop_back())
  387. access(o, begin_, end_, ind.back()) = value_type(0);
  388. }
  389. static void clear(origin_type* o, const iterator &begin_,
  390. const iterator &end_, abstract_skyline) {
  391. clear(o, begin_, end_, abstract_sparse());
  392. }
  393. static void clear(origin_type* o, const iterator &begin_,
  394. const iterator &end_, abstract_dense) {
  395. for (iterator it = begin_; it != end_; ++it) *it = value_type(0);
  396. }
  397. static void clear(origin_type* o, const iterator &begin_,
  398. const iterator &end_)
  399. { clear(o, begin_, end_, storage_type()); }
  400. static void do_clear(this_type &v) { clear(v.origin, begin(v), end(v)); }
  401. static value_type access(const origin_type *o, const const_iterator &it,
  402. const const_iterator &ite, size_type i) {
  403. return real_or_imag_part(linalg_traits<V>::access(o, it.it, ite.it,i),
  404. PART());
  405. }
  406. static reference access(origin_type *o, const iterator &it,
  407. const iterator &ite, size_type i)
  408. { return reference(linalg_traits<V>::access(o, it.it, ite.it,i)); }
  409. };
  410. template <typename PT, typename PART>
  411. struct linalg_traits<part_row_ref<PT, PART> > {
  412. typedef part_row_ref<PT, PART> this_type;
  413. typedef typename std::iterator_traits<PT>::value_type M;
  414. typedef typename linalg_traits<M>::origin_type origin_type;
  415. typedef typename select_ref<const origin_type *, origin_type *,
  416. PT>::ref_type porigin_type;
  417. typedef typename which_reference<PT>::is_reference is_reference;
  418. typedef abstract_matrix linalg_type;
  419. typedef typename linalg_traits<M>::value_type vtype;
  420. typedef typename number_traits<vtype>::magnitude_type value_type;
  421. typedef typename linalg_traits<M>::storage_type storage_type;
  422. typedef abstract_null_type sub_col_type;
  423. typedef abstract_null_type const_sub_col_type;
  424. typedef abstract_null_type col_iterator;
  425. typedef abstract_null_type const_col_iterator;
  426. typedef typename org_type<typename linalg_traits<M>::const_sub_row_type>::t
  427. pre_const_sub_row_type;
  428. typedef typename org_type<typename linalg_traits<M>::sub_row_type>::t pre_sub_row_type;
  429. typedef part_vector<const pre_const_sub_row_type *, PART>
  430. const_sub_row_type;
  431. typedef typename select_ref<abstract_null_type,
  432. part_vector<pre_sub_row_type *, PART>, PT>::ref_type sub_row_type;
  433. typedef typename linalg_traits<M>::const_row_iterator const_row_iterator;
  434. typedef typename select_ref<abstract_null_type, typename
  435. linalg_traits<M>::row_iterator, PT>::ref_type row_iterator;
  436. typedef typename select_ref<
  437. typename linalg_traits<const_sub_row_type>::reference,
  438. typename linalg_traits<sub_row_type>::reference,
  439. PT>::ref_type reference;
  440. typedef row_major sub_orientation;
  441. typedef typename linalg_traits<M>::index_sorted index_sorted;
  442. static size_type ncols(const this_type &v) { return v.nc; }
  443. static size_type nrows(const this_type &v) { return v.nr; }
  444. static const_sub_row_type row(const const_row_iterator &it)
  445. { return const_sub_row_type(linalg_traits<M>::row(it)); }
  446. static sub_row_type row(const row_iterator &it)
  447. { return sub_row_type(linalg_traits<M>::row(it)); }
  448. static row_iterator row_begin(this_type &m) { return m.begin_; }
  449. static row_iterator row_end(this_type &m) { return m.end_; }
  450. static const_row_iterator row_begin(const this_type &m)
  451. { return m.begin_; }
  452. static const_row_iterator row_end(const this_type &m) { return m.end_; }
  453. static origin_type* origin(this_type &v) { return v.origin; }
  454. static const origin_type* origin(const this_type &v) { return v.origin; }
  455. static void do_clear(this_type &v);
  456. static value_type access(const const_row_iterator &itrow, size_type i)
  457. { return real_or_imag_part(linalg_traits<M>::access(itrow, i), PART()); }
  458. static reference access(const row_iterator &itrow, size_type i) {
  459. return reference(ref_or_value_type<reference>::r(
  460. linalg_traits<M>::access(itrow, i),
  461. PART(), value_type()));
  462. }
  463. };
  464. template <typename PT, typename PART>
  465. struct linalg_traits<part_col_ref<PT, PART> > {
  466. typedef part_col_ref<PT, PART> this_type;
  467. typedef typename std::iterator_traits<PT>::value_type M;
  468. typedef typename linalg_traits<M>::origin_type origin_type;
  469. typedef typename select_ref<const origin_type *, origin_type *,
  470. PT>::ref_type porigin_type;
  471. typedef typename which_reference<PT>::is_reference is_reference;
  472. typedef abstract_matrix linalg_type;
  473. typedef typename linalg_traits<M>::value_type vtype;
  474. typedef typename number_traits<vtype>::magnitude_type value_type;
  475. typedef typename linalg_traits<M>::storage_type storage_type;
  476. typedef abstract_null_type sub_row_type;
  477. typedef abstract_null_type const_sub_row_type;
  478. typedef abstract_null_type row_iterator;
  479. typedef abstract_null_type const_row_iterator;
  480. typedef typename org_type<typename linalg_traits<M>::const_sub_col_type>::t
  481. pre_const_sub_col_type;
  482. typedef typename org_type<typename linalg_traits<M>::sub_col_type>::t pre_sub_col_type;
  483. typedef part_vector<const pre_const_sub_col_type *, PART>
  484. const_sub_col_type;
  485. typedef typename select_ref<abstract_null_type,
  486. part_vector<pre_sub_col_type *, PART>, PT>::ref_type sub_col_type;
  487. typedef typename linalg_traits<M>::const_col_iterator const_col_iterator;
  488. typedef typename select_ref<abstract_null_type, typename
  489. linalg_traits<M>::col_iterator, PT>::ref_type col_iterator;
  490. typedef typename select_ref<
  491. typename linalg_traits<const_sub_col_type>::reference,
  492. typename linalg_traits<sub_col_type>::reference,
  493. PT>::ref_type reference;
  494. typedef col_major sub_orientation;
  495. typedef typename linalg_traits<M>::index_sorted index_sorted;
  496. static size_type nrows(const this_type &v) { return v.nr; }
  497. static size_type ncols(const this_type &v) { return v.nc; }
  498. static const_sub_col_type col(const const_col_iterator &it)
  499. { return const_sub_col_type(linalg_traits<M>::col(it)); }
  500. static sub_col_type col(const col_iterator &it)
  501. { return sub_col_type(linalg_traits<M>::col(it)); }
  502. static col_iterator col_begin(this_type &m) { return m.begin_; }
  503. static col_iterator col_end(this_type &m) { return m.end_; }
  504. static const_col_iterator col_begin(const this_type &m)
  505. { return m.begin_; }
  506. static const_col_iterator col_end(const this_type &m) { return m.end_; }
  507. static origin_type* origin(this_type &v) { return v.origin; }
  508. static const origin_type* origin(const this_type &v) { return v.origin; }
  509. static void do_clear(this_type &v);
  510. static value_type access(const const_col_iterator &itcol, size_type i)
  511. { return real_or_imag_part(linalg_traits<M>::access(itcol, i), PART()); }
  512. static reference access(const col_iterator &itcol, size_type i) {
  513. return reference(ref_or_value_type<reference>::r(
  514. linalg_traits<M>::access(itcol, i),
  515. PART(), value_type()));
  516. }
  517. };
  518. template <typename PT, typename PART>
  519. void linalg_traits<part_col_ref<PT, PART> >::do_clear(this_type &v) {
  520. col_iterator it = mat_col_begin(v), ite = mat_col_end(v);
  521. for (; it != ite; ++it) clear(col(it));
  522. }
  523. template <typename PT, typename PART>
  524. void linalg_traits<part_row_ref<PT, PART> >::do_clear(this_type &v) {
  525. row_iterator it = mat_row_begin(v), ite = mat_row_end(v);
  526. for (; it != ite; ++it) clear(row(it));
  527. }
  528. }
  529. #endif // GMM_REAL_PART_H