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); }
91 template <
typename V>
struct conjugated_vector_const_ref {
92 typedef conjugated_vector_const_ref<V> this_type;
93 typedef typename linalg_traits<V>::value_type value_type;
94 typedef typename linalg_traits<V>::const_iterator iterator;
95 typedef typename linalg_traits<this_type>::reference reference;
96 typedef typename linalg_traits<this_type>::origin_type origin_type;
98 iterator begin_, end_;
99 const origin_type *origin;
102 conjugated_vector_const_ref(
const V &v)
103 : begin_(vect_const_begin(v)), end_(vect_const_end(v)),
104 origin(linalg_origin(v)),
105 size_(vect_size(v)) {}
108 {
return gmm::conj(linalg_traits<V>::access(origin, begin_, end_, i)); }
111 template <
typename V>
struct linalg_traits<conjugated_vector_const_ref<V> > {
112 typedef conjugated_vector_const_ref<V> this_type;
113 typedef typename linalg_traits<V>::origin_type origin_type;
114 typedef linalg_const is_reference;
115 typedef abstract_vector linalg_type;
116 typedef typename linalg_traits<V>::value_type value_type;
117 typedef value_type reference;
118 typedef abstract_null_type iterator;
119 typedef conjugated_const_iterator<
typename
120 linalg_traits<V>::const_iterator> const_iterator;
121 typedef typename linalg_traits<V>::storage_type storage_type;
122 typedef typename linalg_traits<V>::index_sorted index_sorted;
123 static size_type size(
const this_type &v) {
return v.size_; }
124 static iterator begin(this_type &v) {
return iterator(v.begin_); }
125 static const_iterator begin(
const this_type &v)
126 {
return const_iterator(v.begin_); }
127 static iterator end(this_type &v)
128 {
return iterator(v.end_); }
129 static const_iterator end(
const this_type &v)
130 {
return const_iterator(v.end_); }
131 static value_type access(
const origin_type *o,
const const_iterator &it,
133 {
return gmm::conj(linalg_traits<V>::access(o, it.it, ite.it, i)); }
134 static const origin_type* origin(
const this_type &v) {
return v.origin; }
137 template<
typename V> std::ostream &
operator <<
138 (std::ostream &o,
const conjugated_vector_const_ref<V>& m)
139 { gmm::write(o,m);
return o; }
145 template <
typename M>
struct conjugated_row_const_iterator {
146 typedef conjugated_row_const_iterator<M> iterator;
147 typedef typename linalg_traits<M>::const_row_iterator ITER;
148 typedef typename linalg_traits<M>::value_type value_type;
149 typedef ptrdiff_t difference_type;
154 iterator operator ++(
int) { iterator tmp = *
this; it++;
return tmp; }
155 iterator operator --(
int) { iterator tmp = *
this; it--;
return tmp; }
156 iterator &operator ++() { it++;
return *
this; }
157 iterator &operator --() { it--;
return *
this; }
158 iterator &operator +=(difference_type i) { it += i;
return *
this; }
159 iterator &operator -=(difference_type i) { it -= i;
return *
this; }
161 { iterator itt = *
this;
return (itt += i); }
163 { iterator itt = *
this;
return (itt -= i); }
164 difference_type
operator -(
const iterator &i)
const
165 {
return it - i.it; }
167 ITER operator *()
const {
return it; }
168 ITER operator [](
int i) {
return it + i; }
170 bool operator ==(
const iterator &i)
const {
return (it == i.it); }
171 bool operator !=(
const iterator &i)
const {
return !(i == *
this); }
172 bool operator < (
const iterator &i)
const {
return (it < i.it); }
174 conjugated_row_const_iterator(
void) {}
175 conjugated_row_const_iterator(
const ITER &i) : it(i) { }
179 template <
typename M>
struct conjugated_row_matrix_const_ref {
181 typedef conjugated_row_matrix_const_ref<M> this_type;
182 typedef typename linalg_traits<M>::const_row_iterator iterator;
183 typedef typename linalg_traits<M>::value_type value_type;
184 typedef typename linalg_traits<this_type>::origin_type origin_type;
186 iterator begin_, end_;
187 const origin_type *origin;
190 conjugated_row_matrix_const_ref(
const M &m)
191 : begin_(mat_row_begin(m)), end_(mat_row_end(m)),
192 origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
195 {
return gmm::conj(linalg_traits<M>::access(begin_+j, i)); }
198 template<
typename M> std::ostream &
operator <<
199 (std::ostream &o,
const conjugated_row_matrix_const_ref<M>& m)
200 { gmm::write(o,m);
return o; }
203 template <
typename M>
struct conjugated_col_const_iterator {
204 typedef conjugated_col_const_iterator<M> iterator;
205 typedef typename linalg_traits<M>::const_col_iterator ITER;
206 typedef typename linalg_traits<M>::value_type value_type;
207 typedef ptrdiff_t difference_type;
212 iterator operator ++(
int) { iterator tmp = *
this; it++;
return tmp; }
213 iterator operator --(
int) { iterator tmp = *
this; it--;
return tmp; }
214 iterator &operator ++() { it++;
return *
this; }
215 iterator &operator --() { it--;
return *
this; }
216 iterator &operator +=(difference_type i) { it += i;
return *
this; }
217 iterator &operator -=(difference_type i) { it -= i;
return *
this; }
219 { iterator itt = *
this;
return (itt += i); }
221 { iterator itt = *
this;
return (itt -= i); }
222 difference_type
operator -(
const iterator &i)
const
223 {
return it - i.it; }
225 ITER operator *()
const {
return it; }
226 ITER operator [](
int i) {
return it + i; }
228 bool operator ==(
const iterator &i)
const {
return (it == i.it); }
229 bool operator !=(
const iterator &i)
const {
return !(i == *
this); }
230 bool operator < (
const iterator &i)
const {
return (it < i.it); }
232 conjugated_col_const_iterator(
void) {}
233 conjugated_col_const_iterator(
const ITER &i) : it(i) { }
237 template <
typename M>
struct conjugated_col_matrix_const_ref {
239 typedef conjugated_col_matrix_const_ref<M> this_type;
240 typedef typename linalg_traits<M>::const_col_iterator iterator;
241 typedef typename linalg_traits<M>::value_type value_type;
242 typedef typename linalg_traits<this_type>::origin_type origin_type;
244 iterator begin_, end_;
245 const origin_type *origin;
248 conjugated_col_matrix_const_ref(
const M &m)
249 : begin_(mat_col_begin(m)), end_(mat_col_end(m)),
250 origin(linalg_origin(m)), nr(mat_ncols(m)), nc(mat_nrows(m)) {}
253 {
return gmm::conj(linalg_traits<M>::access(begin_+i, j)); }
258 template<
typename M> std::ostream &
operator <<
259 (std::ostream &o,
const conjugated_col_matrix_const_ref<M>& m)
260 { gmm::write(o,m);
return o; }
263 template <
typename L,
typename SO>
struct conjugated_return__ {
264 typedef conjugated_row_matrix_const_ref<L> return_type;
266 template <
typename L>
struct conjugated_return__<L, col_major> {
267 typedef conjugated_col_matrix_const_ref<L> return_type;
269 template <
typename L,
typename T,
typename LT>
struct conjugated_return_ {
270 typedef const L & return_type;
272 template <
typename L,
typename T>
273 struct conjugated_return_<L, std::complex<T>, abstract_vector> {
274 typedef conjugated_vector_const_ref<L> return_type;
276 template <
typename L,
typename T>
277 struct conjugated_return_<L, T, abstract_matrix> {
278 typedef typename conjugated_return__<L,
279 typename principal_orientation_type<
typename
280 linalg_traits<L>::sub_orientation>::potype
281 >::return_type return_type;
283 template <
typename L>
struct conjugated_return {
285 conjugated_return_<L, typename linalg_traits<L>::value_type,
286 typename linalg_traits<L>::linalg_type
287 >::return_type return_type;
292 template <
typename L>
inline
293 typename conjugated_return<L>::return_type
295 return conjugated(v,
typename linalg_traits<L>::value_type(),
296 typename linalg_traits<L>::linalg_type());
300 template <
typename L,
typename T,
typename LT>
inline
301 const L & conjugated(
const L &v, T, LT) {
return v; }
303 template <
typename L,
typename T>
inline
304 conjugated_vector_const_ref<L>
conjugated(
const L &v, std::complex<T>,
306 {
return conjugated_vector_const_ref<L>(v); }
308 template <
typename L,
typename T>
inline
309 typename conjugated_return__<L,
310 typename principal_orientation_type<
typename
311 linalg_traits<L>::sub_orientation>::potype>::return_type
313 return conjugated(v,
typename principal_orientation_type<
typename
314 linalg_traits<L>::sub_orientation>::potype());
317 template <
typename L>
inline
318 conjugated_row_matrix_const_ref<L>
conjugated(
const L &v, row_major)
319 {
return conjugated_row_matrix_const_ref<L>(v); }
321 template <
typename L>
inline
322 conjugated_col_matrix_const_ref<L>
conjugated(
const L &v, col_major)
323 {
return conjugated_col_matrix_const_ref<L>(v); }
325 template <
typename M>
326 struct linalg_traits<conjugated_row_matrix_const_ref<M> > {
327 typedef conjugated_row_matrix_const_ref<M> this_type;
328 typedef typename linalg_traits<M>::origin_type origin_type;
329 typedef linalg_const is_reference;
330 typedef abstract_matrix linalg_type;
331 typedef typename linalg_traits<M>::value_type value_type;
332 typedef value_type reference;
333 typedef typename linalg_traits<M>::storage_type storage_type;
334 typedef typename org_type<typename linalg_traits<M>::const_sub_row_type>::t vector_type;
335 typedef conjugated_vector_const_ref<vector_type> sub_col_type;
336 typedef conjugated_vector_const_ref<vector_type> const_sub_col_type;
337 typedef conjugated_row_const_iterator<M> col_iterator;
338 typedef conjugated_row_const_iterator<M> const_col_iterator;
339 typedef abstract_null_type const_sub_row_type;
340 typedef abstract_null_type sub_row_type;
341 typedef abstract_null_type const_row_iterator;
342 typedef abstract_null_type row_iterator;
343 typedef col_major sub_orientation;
344 typedef typename linalg_traits<M>::index_sorted index_sorted;
345 static inline size_type ncols(
const this_type &m) {
return m.nc; }
346 static inline size_type nrows(
const this_type &m) {
return m.nr; }
347 static inline const_sub_col_type col(
const const_col_iterator &it)
348 {
return conjugated(linalg_traits<M>::row(it.it)); }
349 static inline const_col_iterator col_begin(
const this_type &m)
350 {
return const_col_iterator(m.begin_); }
351 static inline const_col_iterator col_end(
const this_type &m)
352 {
return const_col_iterator(m.end_); }
353 static inline const origin_type* origin(
const this_type &m)
355 static value_type access(
const const_col_iterator &it,
size_type i)
356 {
return gmm::conj(linalg_traits<M>::access(it.it, i)); }
359 template <
typename M>
360 struct linalg_traits<conjugated_col_matrix_const_ref<M> > {
361 typedef conjugated_col_matrix_const_ref<M> this_type;
362 typedef typename linalg_traits<M>::origin_type origin_type;
363 typedef linalg_const is_reference;
364 typedef abstract_matrix linalg_type;
365 typedef typename linalg_traits<M>::value_type value_type;
366 typedef value_type reference;
367 typedef typename linalg_traits<M>::storage_type storage_type;
368 typedef typename org_type<typename linalg_traits<M>::const_sub_col_type>::t vector_type;
369 typedef conjugated_vector_const_ref<vector_type> sub_row_type;
370 typedef conjugated_vector_const_ref<vector_type> const_sub_row_type;
371 typedef conjugated_col_const_iterator<M> row_iterator;
372 typedef conjugated_col_const_iterator<M> const_row_iterator;
373 typedef abstract_null_type const_sub_col_type;
374 typedef abstract_null_type sub_col_type;
375 typedef abstract_null_type const_col_iterator;
376 typedef abstract_null_type col_iterator;
377 typedef row_major sub_orientation;
378 typedef typename linalg_traits<M>::index_sorted index_sorted;
379 static inline size_type nrows(
const this_type &m) {
return m.nr; }
380 static inline size_type ncols(
const this_type &m) {
return m.nc; }
381 static inline const_sub_row_type row(
const const_row_iterator &it)
382 {
return conjugated(linalg_traits<M>::col(it.it)); }
383 static inline const_row_iterator row_begin(
const this_type &m)
384 {
return const_row_iterator(m.begin_); }
385 static inline const_row_iterator row_end(
const this_type &m)
386 {
return const_row_iterator(m.end_); }
387 static inline const origin_type* origin(
const this_type &m)
389 static value_type access(
const const_row_iterator &it,
size_type i)
390 {
return gmm::conj(linalg_traits<M>::access(it.it, i)); }
398 #endif // GMM_CONJUGATED_H__