37 #ifndef GMM_CONJUGATED_H__
38 #define GMM_CONJUGATED_H__
49 template <
typename IT>
struct conjugated_const_iterator {
50 typedef typename std::iterator_traits<IT>::value_type value_type;
51 typedef typename std::iterator_traits<IT>::pointer pointer;
52 typedef typename std::iterator_traits<IT>::reference reference;
53 typedef typename std::iterator_traits<IT>::difference_type difference_type;
54 typedef typename std::iterator_traits<IT>::iterator_category
59 conjugated_const_iterator(
void) {}
60 conjugated_const_iterator(
const IT &i) : it(i) {}
62 inline size_type index(
void)
const {
return it.index(); }
63 conjugated_const_iterator operator ++(
int)
64 { conjugated_const_iterator tmp = *
this; ++it;
return tmp; }
65 conjugated_const_iterator operator --(
int)
66 { conjugated_const_iterator tmp = *
this; --it;
return tmp; }
67 conjugated_const_iterator &operator ++() { ++it;
return *
this; }
68 conjugated_const_iterator &operator --() { --it;
return *
this; }
69 conjugated_const_iterator &operator +=(difference_type i)
70 { it += i;
return *
this; }
71 conjugated_const_iterator &operator -=(difference_type i)
72 { it -= i;
return *
this; }
73 conjugated_const_iterator
operator +(difference_type i)
const
74 { conjugated_const_iterator itb = *
this;
return (itb += i); }
75 conjugated_const_iterator
operator -(difference_type i)
const
76 { conjugated_const_iterator itb = *
this;
return (itb -= i); }
77 difference_type
operator -(
const conjugated_const_iterator &i)
const
78 {
return difference_type(it - i.it); }
80 value_type operator *()
const {
return gmm::conj(*it); }
81 value_type operator [](
size_type ii)
const {
return gmm::conj(it[ii]); }
83 bool operator ==(
const conjugated_const_iterator &i)
const
84 {
return (i.it == it); }
85 bool operator !=(
const conjugated_const_iterator &i)
const
86 {
return (i.it != it); }
87 bool operator < (
const conjugated_const_iterator &i)
const
88 {
return (it < i.it); }
89 bool operator > (
const conjugated_const_iterator &i)
const
90 {
return (it > i.it); }
91 bool operator >= (
const conjugated_const_iterator &i)
const
92 {
return (it >= i.it); }
95 template <
typename V>
struct conjugated_vector_const_ref {
96 typedef conjugated_vector_const_ref<V> this_type;
97 typedef typename linalg_traits<V>::value_type value_type;
98 typedef typename linalg_traits<V>::const_iterator iterator;
99 typedef typename linalg_traits<this_type>::reference reference;
100 typedef typename linalg_traits<this_type>::origin_type origin_type;
102 iterator begin_, end_;
103 const origin_type *origin;
106 conjugated_vector_const_ref(
const V &v)
107 : begin_(vect_const_begin(v)), end_(vect_const_end(v)),
108 origin(linalg_origin(v)),
109 size_(vect_size(v)) {}
112 {
return gmm::conj(linalg_traits<V>::access(origin, begin_, end_, i)); }
115 template <
typename V>
struct linalg_traits<conjugated_vector_const_ref<V> > {
116 typedef conjugated_vector_const_ref<V> this_type;
117 typedef typename linalg_traits<V>::origin_type origin_type;
118 typedef linalg_const is_reference;
119 typedef abstract_vector linalg_type;
120 typedef typename linalg_traits<V>::value_type value_type;
121 typedef value_type reference;
122 typedef abstract_null_type iterator;
123 typedef conjugated_const_iterator<
typename
124 linalg_traits<V>::const_iterator> const_iterator;
125 typedef typename linalg_traits<V>::storage_type storage_type;
126 typedef typename linalg_traits<V>::index_sorted index_sorted;
127 static size_type size(
const this_type &v) {
return v.size_; }
128 static iterator begin(this_type &v) {
return iterator(v.begin_); }
129 static const_iterator begin(
const this_type &v)
130 {
return const_iterator(v.begin_); }
131 static iterator end(this_type &v)
132 {
return iterator(v.end_); }
133 static const_iterator end(
const this_type &v)
134 {
return const_iterator(v.end_); }
135 static value_type access(
const origin_type *o,
const const_iterator &it,
137 {
return gmm::conj(linalg_traits<V>::access(o, it.it, ite.it, i)); }
138 static const origin_type* origin(
const this_type &v) {
return v.origin; }
141 template<
typename V> std::ostream &
operator <<
142 (std::ostream &o,
const conjugated_vector_const_ref<V>& m)
143 { gmm::write(o,m);
return o; }
149 template <
typename M>
struct conjugated_row_const_iterator {
150 typedef conjugated_row_const_iterator<M> iterator;
151 typedef typename linalg_traits<M>::const_row_iterator ITER;
152 typedef typename linalg_traits<M>::value_type value_type;
153 typedef ptrdiff_t difference_type;
158 iterator operator ++(
int) { iterator tmp = *
this; it++;
return tmp; }
159 iterator operator --(
int) { iterator tmp = *
this; it--;
return tmp; }
160 iterator &operator ++() { it++;
return *
this; }
161 iterator &operator --() { it--;
return *
this; }
162 iterator &operator +=(difference_type i) { it += i;
return *
this; }
163 iterator &operator -=(difference_type i) { it -= i;
return *
this; }
165 { iterator itt = *
this;
return (itt += i); }
167 { iterator itt = *
this;
return (itt -= i); }
168 difference_type
operator -(
const iterator &i)
const
169 {
return it - i.it; }
171 ITER operator *()
const {
return it; }
172 ITER operator [](
int i) {
return it + i; }
174 bool operator ==(
const iterator &i)
const {
return (it == i.it); }
175 bool operator !=(
const iterator &i)
const {
return !(i == *
this); }
176 bool operator < (
const iterator &i)
const {
return (it < i.it); }
177 bool operator > (
const iterator &i)
const {
return (it > i.it); }
178 bool operator >=(
const iterator &i)
const {
return (it >= i.it); }
180 conjugated_row_const_iterator(
void) {}
181 conjugated_row_const_iterator(
const ITER &i) : it(i) { }
185 template <
typename M>
struct conjugated_row_matrix_const_ref {
187 typedef conjugated_row_matrix_const_ref<M> this_type;
188 typedef typename linalg_traits<M>::const_row_iterator iterator;
189 typedef typename linalg_traits<M>::value_type value_type;
190 typedef typename linalg_traits<this_type>::origin_type origin_type;
192 iterator begin_, end_;
193 const origin_type *origin;
196 conjugated_row_matrix_const_ref(
const M &m)
197 : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
198 origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
201 {
return gmm::conj(linalg_traits<M>::access(begin_+j, i)); }
204 template<
typename M> std::ostream &
operator <<
205 (std::ostream &o,
const conjugated_row_matrix_const_ref<M>& m)
206 { gmm::write(o,m);
return o; }
209 template <
typename M>
struct conjugated_col_const_iterator {
210 typedef conjugated_col_const_iterator<M> iterator;
211 typedef typename linalg_traits<M>::const_col_iterator ITER;
212 typedef typename linalg_traits<M>::value_type value_type;
213 typedef ptrdiff_t difference_type;
218 iterator operator ++(
int) { iterator tmp = *
this; it++;
return tmp; }
219 iterator operator --(
int) { iterator tmp = *
this; it--;
return tmp; }
220 iterator &operator ++() { it++;
return *
this; }
221 iterator &operator --() { it--;
return *
this; }
222 iterator &operator +=(difference_type i) { it += i;
return *
this; }
223 iterator &operator -=(difference_type i) { it -= i;
return *
this; }
225 { iterator itt = *
this;
return (itt += i); }
227 { iterator itt = *
this;
return (itt -= i); }
228 difference_type
operator -(
const iterator &i)
const
229 {
return it - i.it; }
231 ITER operator *()
const {
return it; }
232 ITER operator [](
int i) {
return it + i; }
234 bool operator ==(
const iterator &i)
const {
return (it == i.it); }
235 bool operator !=(
const iterator &i)
const {
return !(i == *
this); }
236 bool operator < (
const iterator &i)
const {
return (it < i.it); }
237 bool operator > (
const iterator &i)
const {
return (it > i.it); }
238 bool operator >=(
const iterator &i)
const {
return (it >= i.it); }
240 conjugated_col_const_iterator(
void) {}
241 conjugated_col_const_iterator(
const ITER &i) : it(i) { }
245 template <
typename M>
struct conjugated_col_matrix_const_ref {
247 typedef conjugated_col_matrix_const_ref<M> this_type;
248 typedef typename linalg_traits<M>::const_col_iterator iterator;
249 typedef typename linalg_traits<M>::value_type value_type;
250 typedef typename linalg_traits<this_type>::origin_type origin_type;
252 iterator begin_, end_;
253 const origin_type *origin;
256 conjugated_col_matrix_const_ref(
const M &m)
257 : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
258 origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
261 {
return gmm::conj(linalg_traits<M>::access(begin_+i, j)); }
266 template<
typename M> std::ostream &
operator <<
267 (std::ostream &o,
const conjugated_col_matrix_const_ref<M>& m)
268 { gmm::write(o,m);
return o; }
271 template <
typename L,
typename SO>
struct conjugated_return__ {
272 typedef conjugated_row_matrix_const_ref<L> return_type;
274 template <
typename L>
struct conjugated_return__<L, col_major> {
275 typedef conjugated_col_matrix_const_ref<L> return_type;
277 template <
typename L,
typename T,
typename LT>
struct conjugated_return_ {
278 typedef const L & return_type;
280 template <
typename L,
typename T>
281 struct conjugated_return_<L, std::complex<T>, abstract_vector> {
282 typedef conjugated_vector_const_ref<L> return_type;
284 template <
typename L,
typename T>
285 struct conjugated_return_<L, T, abstract_matrix> {
286 typedef typename conjugated_return__<L,
287 typename principal_orientation_type<
typename
288 linalg_traits<L>::sub_orientation>::potype
289 >::return_type return_type;
291 template <
typename L>
struct conjugated_return {
293 conjugated_return_<L, typename linalg_traits<L>::value_type,
294 typename linalg_traits<L>::linalg_type
295 >::return_type return_type;
300 template <
typename L>
inline
301 typename conjugated_return<L>::return_type
303 return conjugated(v,
typename linalg_traits<L>::value_type(),
304 typename linalg_traits<L>::linalg_type());
308 template <
typename L,
typename T,
typename LT>
inline
309 const L & conjugated(
const L &v, T, LT) {
return v; }
311 template <
typename L,
typename T>
inline
312 conjugated_vector_const_ref<L>
conjugated(
const L &v, std::complex<T>,
314 {
return conjugated_vector_const_ref<L>(v); }
316 template <
typename L,
typename T>
inline
317 typename conjugated_return__<L,
318 typename principal_orientation_type<
typename
319 linalg_traits<L>::sub_orientation>::potype>::return_type
321 return conjugated(v,
typename principal_orientation_type<
typename
322 linalg_traits<L>::sub_orientation>::potype());
325 template <
typename L>
inline
326 conjugated_row_matrix_const_ref<L>
conjugated(
const L &v, row_major)
327 {
return conjugated_row_matrix_const_ref<L>(v); }
329 template <
typename L>
inline
330 conjugated_col_matrix_const_ref<L>
conjugated(
const L &v, col_major)
331 {
return conjugated_col_matrix_const_ref<L>(v); }
333 template <
typename M>
334 struct linalg_traits<conjugated_row_matrix_const_ref<M> > {
335 typedef conjugated_row_matrix_const_ref<M> this_type;
336 typedef typename linalg_traits<M>::origin_type origin_type;
337 typedef linalg_const is_reference;
338 typedef abstract_matrix linalg_type;
339 typedef typename linalg_traits<M>::value_type value_type;
340 typedef value_type reference;
341 typedef typename linalg_traits<M>::storage_type storage_type;
342 typedef typename org_type<typename linalg_traits<M>::const_sub_row_type>::t vector_type;
343 typedef conjugated_vector_const_ref<vector_type> sub_col_type;
344 typedef conjugated_vector_const_ref<vector_type> const_sub_col_type;
345 typedef conjugated_row_const_iterator<M> col_iterator;
346 typedef conjugated_row_const_iterator<M> const_col_iterator;
347 typedef abstract_null_type const_sub_row_type;
348 typedef abstract_null_type sub_row_type;
349 typedef abstract_null_type const_row_iterator;
350 typedef abstract_null_type row_iterator;
351 typedef col_major sub_orientation;
352 typedef typename linalg_traits<M>::index_sorted index_sorted;
353 static inline size_type ncols(
const this_type &m) {
return m.nc; }
354 static inline size_type nrows(
const this_type &m) {
return m.nr; }
355 static inline const_sub_col_type col(
const const_col_iterator &it)
356 {
return conjugated(linalg_traits<M>::row(it.it)); }
357 static inline const_col_iterator col_begin(
const this_type &m)
358 {
return const_col_iterator(m.begin_); }
359 static inline const_col_iterator col_end(
const this_type &m)
360 {
return const_col_iterator(m.end_); }
361 static inline const origin_type* origin(
const this_type &m)
363 static value_type access(
const const_col_iterator &it,
size_type i)
364 {
return gmm::conj(linalg_traits<M>::access(it.it, i)); }
367 template <
typename M>
368 struct linalg_traits<conjugated_col_matrix_const_ref<M> > {
369 typedef conjugated_col_matrix_const_ref<M> this_type;
370 typedef typename linalg_traits<M>::origin_type origin_type;
371 typedef linalg_const is_reference;
372 typedef abstract_matrix linalg_type;
373 typedef typename linalg_traits<M>::value_type value_type;
374 typedef value_type reference;
375 typedef typename linalg_traits<M>::storage_type storage_type;
376 typedef typename org_type<typename linalg_traits<M>::const_sub_col_type>::t vector_type;
377 typedef conjugated_vector_const_ref<vector_type> sub_row_type;
378 typedef conjugated_vector_const_ref<vector_type> const_sub_row_type;
379 typedef conjugated_col_const_iterator<M> row_iterator;
380 typedef conjugated_col_const_iterator<M> const_row_iterator;
381 typedef abstract_null_type const_sub_col_type;
382 typedef abstract_null_type sub_col_type;
383 typedef abstract_null_type const_col_iterator;
384 typedef abstract_null_type col_iterator;
385 typedef row_major sub_orientation;
386 typedef typename linalg_traits<M>::index_sorted index_sorted;
387 static inline size_type nrows(
const this_type &m) {
return m.nr; }
388 static inline size_type ncols(
const this_type &m) {
return m.nc; }
389 static inline const_sub_row_type row(
const const_row_iterator &it)
390 {
return conjugated(linalg_traits<M>::col(it.it)); }
391 static inline const_row_iterator row_begin(
const this_type &m)
392 {
return const_row_iterator(m.begin_); }
393 static inline const_row_iterator row_end(
const this_type &m)
394 {
return const_row_iterator(m.end_); }
395 static inline const origin_type* origin(
const this_type &m)
397 static value_type access(
const const_row_iterator &it,
size_type i)
398 {
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