36 #ifndef GMM_CONJUGATED_H__
37 #define GMM_CONJUGATED_H__
48 template <
typename IT>
struct conjugated_const_iterator {
49 typedef typename std::iterator_traits<IT>::value_type value_type;
50 typedef typename std::iterator_traits<IT>::pointer pointer;
51 typedef typename std::iterator_traits<IT>::reference reference;
52 typedef typename std::iterator_traits<IT>::difference_type difference_type;
53 typedef typename std::iterator_traits<IT>::iterator_category
58 conjugated_const_iterator(
void) {}
59 conjugated_const_iterator(
const IT &i) : it(i) {}
61 inline size_type index(
void)
const {
return it.index(); }
62 conjugated_const_iterator operator ++(
int)
63 { conjugated_const_iterator tmp = *
this; ++it;
return tmp; }
64 conjugated_const_iterator operator --(
int)
65 { conjugated_const_iterator tmp = *
this; --it;
return tmp; }
66 conjugated_const_iterator &operator ++() { ++it;
return *
this; }
67 conjugated_const_iterator &operator --() { --it;
return *
this; }
68 conjugated_const_iterator &operator +=(difference_type i)
69 { it += i;
return *
this; }
70 conjugated_const_iterator &operator -=(difference_type i)
71 { it -= i;
return *
this; }
72 conjugated_const_iterator
operator +(difference_type i)
const
73 { conjugated_const_iterator itb = *
this;
return (itb += i); }
74 conjugated_const_iterator
operator -(difference_type i)
const
75 { conjugated_const_iterator itb = *
this;
return (itb -= i); }
76 difference_type
operator -(
const conjugated_const_iterator &i)
const
77 {
return difference_type(it - i.it); }
79 value_type operator *()
const {
return gmm::conj(*it); }
80 value_type operator [](
size_type ii)
const {
return gmm::conj(it[ii]); }
82 bool operator ==(
const conjugated_const_iterator &i)
const
83 {
return (i.it == it); }
84 bool operator !=(
const conjugated_const_iterator &i)
const
85 {
return (i.it != it); }
86 bool operator < (
const conjugated_const_iterator &i)
const
87 {
return (it < i.it); }
88 bool operator > (
const conjugated_const_iterator &i)
const
89 {
return (it > i.it); }
90 bool operator >= (
const conjugated_const_iterator &i)
const
91 {
return (it >= i.it); }
94 template <
typename V>
struct conjugated_vector_const_ref {
95 typedef conjugated_vector_const_ref<V> this_type;
96 typedef typename linalg_traits<V>::value_type value_type;
97 typedef typename linalg_traits<V>::const_iterator iterator;
98 typedef typename linalg_traits<this_type>::reference reference;
99 typedef typename linalg_traits<this_type>::origin_type origin_type;
101 iterator begin_, end_;
102 const origin_type *origin;
105 conjugated_vector_const_ref(
const V &v)
106 : begin_(vect_const_begin(v)), end_(vect_const_end(v)),
107 origin(linalg_origin(v)),
108 size_(vect_size(v)) {}
111 {
return gmm::conj(linalg_traits<V>::access(origin, begin_, end_, i)); }
114 template <
typename V>
struct linalg_traits<conjugated_vector_const_ref<V> > {
115 typedef conjugated_vector_const_ref<V> this_type;
116 typedef typename linalg_traits<V>::origin_type origin_type;
117 typedef linalg_const is_reference;
118 typedef abstract_vector linalg_type;
119 typedef typename linalg_traits<V>::value_type value_type;
120 typedef value_type reference;
121 typedef abstract_null_type iterator;
122 typedef conjugated_const_iterator<
typename
123 linalg_traits<V>::const_iterator> const_iterator;
124 typedef typename linalg_traits<V>::storage_type storage_type;
125 typedef typename linalg_traits<V>::index_sorted index_sorted;
126 static size_type size(
const this_type &v) {
return v.size_; }
127 static iterator begin(this_type &v) {
return iterator(v.begin_); }
128 static const_iterator begin(
const this_type &v)
129 {
return const_iterator(v.begin_); }
130 static iterator end(this_type &v)
131 {
return iterator(v.end_); }
132 static const_iterator end(
const this_type &v)
133 {
return const_iterator(v.end_); }
134 static value_type access(
const origin_type *o,
const const_iterator &it,
136 {
return gmm::conj(linalg_traits<V>::access(o, it.it, ite.it, i)); }
137 static const origin_type* origin(
const this_type &v) {
return v.origin; }
140 template<
typename V> std::ostream &
operator <<
141 (std::ostream &o,
const conjugated_vector_const_ref<V>& m)
142 { gmm::write(o,m);
return o; }
148 template <
typename M>
struct conjugated_row_const_iterator {
149 typedef conjugated_row_const_iterator<M> iterator;
150 typedef typename linalg_traits<M>::const_row_iterator ITER;
151 typedef typename linalg_traits<M>::value_type value_type;
152 typedef ptrdiff_t difference_type;
157 iterator operator ++(
int) { iterator tmp = *
this; it++;
return tmp; }
158 iterator operator --(
int) { iterator tmp = *
this; it--;
return tmp; }
159 iterator &operator ++() { it++;
return *
this; }
160 iterator &operator --() { it--;
return *
this; }
161 iterator &operator +=(difference_type i) { it += i;
return *
this; }
162 iterator &operator -=(difference_type i) { it -= i;
return *
this; }
164 { iterator itt = *
this;
return (itt += i); }
166 { iterator itt = *
this;
return (itt -= i); }
167 difference_type
operator -(
const iterator &i)
const
168 {
return it - i.it; }
170 ITER operator *()
const {
return it; }
171 ITER operator [](
int i) {
return it + i; }
173 bool operator ==(
const iterator &i)
const {
return (it == i.it); }
174 bool operator !=(
const iterator &i)
const {
return !(i == *
this); }
175 bool operator < (
const iterator &i)
const {
return (it < i.it); }
176 bool operator > (
const iterator &i)
const {
return (it > i.it); }
177 bool operator >=(
const iterator &i)
const {
return (it >= i.it); }
179 conjugated_row_const_iterator(
void) {}
180 conjugated_row_const_iterator(
const ITER &i) : it(i) { }
184 template <
typename M>
struct conjugated_row_matrix_const_ref {
186 typedef conjugated_row_matrix_const_ref<M> this_type;
187 typedef typename linalg_traits<M>::const_row_iterator iterator;
188 typedef typename linalg_traits<M>::value_type value_type;
189 typedef typename linalg_traits<this_type>::origin_type origin_type;
191 iterator begin_, end_;
192 const origin_type *origin;
195 conjugated_row_matrix_const_ref(
const M &m)
196 : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
197 origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
200 {
return gmm::conj(linalg_traits<M>::access(begin_+j, i)); }
203 template<
typename M> std::ostream &
operator <<
204 (std::ostream &o,
const conjugated_row_matrix_const_ref<M>& m)
205 { gmm::write(o,m);
return o; }
208 template <
typename M>
struct conjugated_col_const_iterator {
209 typedef conjugated_col_const_iterator<M> iterator;
210 typedef typename linalg_traits<M>::const_col_iterator ITER;
211 typedef typename linalg_traits<M>::value_type value_type;
212 typedef ptrdiff_t difference_type;
217 iterator operator ++(
int) { iterator tmp = *
this; it++;
return tmp; }
218 iterator operator --(
int) { iterator tmp = *
this; it--;
return tmp; }
219 iterator &operator ++() { it++;
return *
this; }
220 iterator &operator --() { it--;
return *
this; }
221 iterator &operator +=(difference_type i) { it += i;
return *
this; }
222 iterator &operator -=(difference_type i) { it -= i;
return *
this; }
224 { iterator itt = *
this;
return (itt += i); }
226 { iterator itt = *
this;
return (itt -= i); }
227 difference_type
operator -(
const iterator &i)
const
228 {
return it - i.it; }
230 ITER operator *()
const {
return it; }
231 ITER operator [](
int i) {
return it + i; }
233 bool operator ==(
const iterator &i)
const {
return (it == i.it); }
234 bool operator !=(
const iterator &i)
const {
return !(i == *
this); }
235 bool operator < (
const iterator &i)
const {
return (it < i.it); }
236 bool operator > (
const iterator &i)
const {
return (it > i.it); }
237 bool operator >=(
const iterator &i)
const {
return (it >= i.it); }
239 conjugated_col_const_iterator(
void) {}
240 conjugated_col_const_iterator(
const ITER &i) : it(i) { }
244 template <
typename M>
struct conjugated_col_matrix_const_ref {
246 typedef conjugated_col_matrix_const_ref<M> this_type;
247 typedef typename linalg_traits<M>::const_col_iterator iterator;
248 typedef typename linalg_traits<M>::value_type value_type;
249 typedef typename linalg_traits<this_type>::origin_type origin_type;
251 iterator begin_, end_;
252 const origin_type *origin;
255 conjugated_col_matrix_const_ref(
const M &m)
256 : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
257 origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
260 {
return gmm::conj(linalg_traits<M>::access(begin_+i, j)); }
265 template<
typename M> std::ostream &
operator <<
266 (std::ostream &o,
const conjugated_col_matrix_const_ref<M>& m)
267 { gmm::write(o,m);
return o; }
270 template <
typename L,
typename SO>
struct conjugated_return__ {
271 typedef conjugated_row_matrix_const_ref<L> return_type;
273 template <
typename L>
struct conjugated_return__<L, col_major> {
274 typedef conjugated_col_matrix_const_ref<L> return_type;
276 template <
typename L,
typename T,
typename LT>
struct conjugated_return_ {
277 typedef const L & return_type;
279 template <
typename L,
typename T>
280 struct conjugated_return_<L, std::complex<T>, abstract_vector> {
281 typedef conjugated_vector_const_ref<L> return_type;
283 template <
typename L,
typename T>
284 struct conjugated_return_<L, T, abstract_matrix> {
285 typedef typename conjugated_return__<L,
286 typename principal_orientation_type<
typename
287 linalg_traits<L>::sub_orientation>::potype
288 >::return_type return_type;
290 template <
typename L>
struct conjugated_return {
292 conjugated_return_<L, typename linalg_traits<L>::value_type,
293 typename linalg_traits<L>::linalg_type
294 >::return_type return_type;
299 template <
typename L>
inline
300 typename conjugated_return<L>::return_type
302 return conjugated(v,
typename linalg_traits<L>::value_type(),
303 typename linalg_traits<L>::linalg_type());
307 template <
typename L,
typename T,
typename LT>
inline
308 const L & conjugated(
const L &v, T, LT) {
return v; }
310 template <
typename L,
typename T>
inline
311 conjugated_vector_const_ref<L>
conjugated(
const L &v, std::complex<T>,
313 {
return conjugated_vector_const_ref<L>(v); }
315 template <
typename L,
typename T>
inline
316 typename conjugated_return__<L,
317 typename principal_orientation_type<
typename
318 linalg_traits<L>::sub_orientation>::potype>::return_type
320 return conjugated(v,
typename principal_orientation_type<
typename
321 linalg_traits<L>::sub_orientation>::potype());
324 template <
typename L>
inline
325 conjugated_row_matrix_const_ref<L>
conjugated(
const L &v, row_major)
326 {
return conjugated_row_matrix_const_ref<L>(v); }
328 template <
typename L>
inline
329 conjugated_col_matrix_const_ref<L>
conjugated(
const L &v, col_major)
330 {
return conjugated_col_matrix_const_ref<L>(v); }
332 template <
typename M>
333 struct linalg_traits<conjugated_row_matrix_const_ref<M> > {
334 typedef conjugated_row_matrix_const_ref<M> this_type;
335 typedef typename linalg_traits<M>::origin_type origin_type;
336 typedef linalg_const is_reference;
337 typedef abstract_matrix linalg_type;
338 typedef typename linalg_traits<M>::value_type value_type;
339 typedef value_type reference;
340 typedef typename linalg_traits<M>::storage_type storage_type;
341 typedef typename org_type<typename linalg_traits<M>::const_sub_row_type>::t vector_type;
342 typedef conjugated_vector_const_ref<vector_type> sub_col_type;
343 typedef conjugated_vector_const_ref<vector_type> const_sub_col_type;
344 typedef conjugated_row_const_iterator<M> col_iterator;
345 typedef conjugated_row_const_iterator<M> const_col_iterator;
346 typedef abstract_null_type const_sub_row_type;
347 typedef abstract_null_type sub_row_type;
348 typedef abstract_null_type const_row_iterator;
349 typedef abstract_null_type row_iterator;
350 typedef col_major sub_orientation;
351 typedef typename linalg_traits<M>::index_sorted index_sorted;
352 static inline size_type ncols(
const this_type &m) {
return m.nc; }
353 static inline size_type nrows(
const this_type &m) {
return m.nr; }
354 static inline const_sub_col_type col(
const const_col_iterator &it)
355 {
return conjugated(linalg_traits<M>::row(it.it)); }
356 static inline const_col_iterator col_begin(
const this_type &m)
357 {
return const_col_iterator(m.begin_); }
358 static inline const_col_iterator col_end(
const this_type &m)
359 {
return const_col_iterator(m.end_); }
360 static inline const origin_type* origin(
const this_type &m)
362 static value_type access(
const const_col_iterator &it,
size_type i)
363 {
return gmm::conj(linalg_traits<M>::access(it.it, i)); }
366 template <
typename M>
367 struct linalg_traits<conjugated_col_matrix_const_ref<M> > {
368 typedef conjugated_col_matrix_const_ref<M> this_type;
369 typedef typename linalg_traits<M>::origin_type origin_type;
370 typedef linalg_const is_reference;
371 typedef abstract_matrix linalg_type;
372 typedef typename linalg_traits<M>::value_type value_type;
373 typedef value_type reference;
374 typedef typename linalg_traits<M>::storage_type storage_type;
375 typedef typename org_type<typename linalg_traits<M>::const_sub_col_type>::t vector_type;
376 typedef conjugated_vector_const_ref<vector_type> sub_row_type;
377 typedef conjugated_vector_const_ref<vector_type> const_sub_row_type;
378 typedef conjugated_col_const_iterator<M> row_iterator;
379 typedef conjugated_col_const_iterator<M> const_row_iterator;
380 typedef abstract_null_type const_sub_col_type;
381 typedef abstract_null_type sub_col_type;
382 typedef abstract_null_type const_col_iterator;
383 typedef abstract_null_type col_iterator;
384 typedef row_major sub_orientation;
385 typedef typename linalg_traits<M>::index_sorted index_sorted;
386 static inline size_type nrows(
const this_type &m) {
return m.nr; }
387 static inline size_type ncols(
const this_type &m) {
return m.nc; }
388 static inline const_sub_row_type row(
const const_row_iterator &it)
389 {
return conjugated(linalg_traits<M>::col(it.it)); }
390 static inline const_row_iterator row_begin(
const this_type &m)
391 {
return const_row_iterator(m.begin_); }
392 static inline const_row_iterator row_end(
const this_type &m)
393 {
return const_row_iterator(m.end_); }
394 static inline const origin_type* origin(
const this_type &m)
396 static value_type access(
const const_row_iterator &it,
size_type i)
397 {
return gmm::conj(linalg_traits<M>::access(it.it, i)); }
conjugated_return< L >::return_type conjugated(const L &v)
return a conjugated view of the input matrix or vector.
Basic definitions and tools of GMM.
rational_fraction< T > operator-(const polynomial< T > &P, const rational_fraction< T > &Q)
Subtract Q from P.
rational_fraction< T > operator+(const polynomial< T > &P, const rational_fraction< T > &Q)
Add Q to P.
size_t size_type
used as the common size type in the library