ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00024 #if 0 00025 00044 template <class T, 00045 class A1, 00046 class A2, 00047 int CATDIM, 00048 class DERIVED_INFO 00049 > 00050 class array_nd<T, data::catarray<A1, A2, CATDIM, DERIVED_INFO> > 00051 : 00052 public 00053 array_common_base<array_nd<T, 00054 data::catarray<A1, A2, CATDIM, DERIVED_INFO> > > 00055 00056 { 00057 private: 00058 typedef array_nd prv_this_type; 00059 typedef typename prv_this_type::common_base_class common_base_class; 00060 00061 typedef typename common_base_class::base_class prv_base_class; 00062 00063 class not_a_type { typedef not_a_type reference; }; 00064 00065 typedef array_nd_details::catarray_common_tools::sub_type sub_type; 00066 static inline sub_type type_from_indtype(ivl::index_array:: 00067 index_array_type y) 00068 { 00069 return array_nd_details::catarray_common_tools:: 00070 type_from_indtype(y); 00071 } 00072 00073 protected: 00074 typedef typename array_nd::best_reference_iterator 00075 best_reference_iterator; 00076 00077 typedef typename array_nd::const_reference_iterator 00078 const_reference_iterator; 00079 00080 typedef typename array_nd::tool tool; 00081 00082 using prv_base_class::in; 00083 using prv_base_class::idx; 00084 00085 using prv_base_class::all_sizes; 00086 using prv_base_class::all_len; 00087 using prv_base_class::diffs_ar; 00088 using prv_base_class::diffs; 00089 using prv_base_class::sizes; 00090 using prv_base_class::steps; 00091 using prv_base_class::iter; 00092 using prv_base_class::back_diffs; 00093 using prv_base_class::begin_to_ends; 00094 using prv_base_class::first_to_lasts; 00095 00096 using prv_base_class::nonsing_map; 00097 using prv_base_class::nonsing_rmap; 00098 using prv_base_class::idx_ar_map; 00099 using prv_base_class::idx_ar_rmap; 00100 00101 using prv_base_class::get_iter; 00102 00103 public: 00104 typedef array_nd this_type; 00105 00106 typedef this_type this_array_nd_type; 00107 00108 typedef typename this_type::derived_type derived_type; 00109 00110 typedef typename common_base_class::base_class base_class; 00111 00112 typedef this_type array_type; 00113 00115 typedef array<size_t, tiny> size_type; 00116 00118 typedef const array<size_t, tiny>& size_nd_ref_type; 00119 00121 //note: why should a non-ra array have stride anyway???? 00122 typedef array<size_t, tiny> stride_ref_type; 00123 00125 typedef types::t_true has_1d_parenthesis; 00126 typedef types::t_true has_2d_parenthesis; 00127 typedef types::t_true has_3d_parenthesis; 00128 typedef types::t_true has_nd_parenthesis; 00129 00130 00131 00132 // typedefs for class iterators 00133 typedef typename types::t_if<typename array_nd::is_writeable, 00134 data::catarray_nd_iterator<T, 00135 typename base_class::best_reference_iterator, 00136 typename base_class::const_reference_iterator, 00137 base_class::reference_iterator_is_nd::value, false>, 00138 not_a_type>::type iterator_nd; 00139 00140 typedef data::catarray_nd_iterator<T, 00141 typename base_class::const_reference_iterator, 00142 typename base_class::const_reference_iterator, 00143 base_class::reference_iterator_is_nd::value, true> const_iterator_nd; 00144 00145 typedef typename types::t_if<typename array_nd::is_writeable, 00146 data::catarray_nd_iterator<T, 00147 typename base_class::best_reference_iterator, 00148 typename base_class::const_reference_iterator, 00149 base_class::reference_iterator_is_nd::value, false, 0, false>, 00150 not_a_type>::type _fast_iterator_nd; 00151 00152 typedef data::catarray_nd_iterator<T, 00153 typename base_class::const_reference_iterator, 00154 typename base_class::const_reference_iterator, 00155 base_class::reference_iterator_is_nd::value, true, 0, false> 00156 _fast_const_iterator_nd; 00157 00158 typedef std::reverse_iterator<iterator_nd> reverse_iterator_nd; 00159 00160 typedef std::reverse_iterator<const_iterator_nd> 00161 const_reverse_iterator_nd; 00162 00163 template<int SPC> 00164 struct s_iterator_nd 00165 { 00166 typedef typename types::t_if<typename array_nd::is_writeable, 00167 data::catarray_nd_iterator<T, 00168 typename base_class::best_reference_iterator, 00169 typename base_class::const_reference_iterator, 00170 base_class::reference_iterator_is_nd::value, false, SPC>, 00171 not_a_type>::type type; 00172 }; 00173 template<int SPC> 00174 struct const_s_iterator_nd 00175 { 00176 typedef data::catarray_nd_iterator<T, 00177 typename base_class::const_reference_iterator, 00178 typename base_class::const_reference_iterator, 00179 base_class::reference_iterator_is_nd::value, true, SPC> type; 00180 }; 00181 00182 template<int SPC> 00183 struct _fast_s_iterator_nd 00184 { 00185 typedef typename types::t_if<typename array_nd::is_writeable, 00186 data::catarray_nd_iterator<T, 00187 typename base_class::best_reference_iterator, 00188 typename base_class::const_reference_iterator, 00189 base_class::reference_iterator_is_nd::value, false, SPC, false>, 00190 not_a_type>::type type; 00191 }; 00192 template<int SPC> 00193 struct _fast_const_s_iterator_nd 00194 { 00195 typedef data::catarray_nd_iterator<T, 00196 typename base_class::const_reference_iterator, 00197 typename base_class::const_reference_iterator, 00198 base_class::reference_iterator_is_nd::value, true, SPC, false> type; 00199 }; 00200 00201 template<int SPC> 00202 struct reverse_s_iterator_nd 00203 { 00204 typedef std::reverse_iterator<s_iterator_nd<SPC> > type; 00205 }; 00206 template<int SPC> 00207 struct const_reverse_s_iterator 00208 { 00209 typedef std::reverse_iterator<const_s_iterator_nd<SPC> > type; 00210 }; 00211 int iter_specialization_nd(size_t dim) const 00212 { 00213 return ((*idx)[dim].is_array()) ? 2 : 1; 00214 } 00215 00216 typedef typename const_iterator_nd:: 00217 iter_nd_border_walker iter_nd_border_walker; 00218 00219 00220 00221 /* 00222 size_t begin_pos(size_t d, size_t pos) 00223 { 00224 size_t mod = pos % nd().stride(d); 00225 if(d == nd().ndim() - 1) return mod; 00226 return pos - pos % nd().stride(d + 1) + mod; 00227 } 00228 00229 size_t end_pos(size_t d, size_t pos) 00230 { 00231 size_t mod = pos % nd().stride(d); 00232 if(d == nd().ndim() - 1) return mod + nd().length(); 00233 return pos - pos % nd().stride(d + 1) + mod + 00234 nd().stride(d + 1); 00235 } 00236 */ 00237 00238 // friend declarations for subarray iterator helper construction functions. 00239 template<class IT, class X> 00240 friend IT catarray_iter_create::_begin(X& a, size_t d); 00241 template <class IT, class X> 00242 friend IT catarray_iter_create::_begin(X& a, size_t d, const IT& it); 00243 template <class IT, class ITS, class X> 00244 friend IT catarray_iter_create::_iter(X& a, size_t d, const ITS& it); 00245 template <class IT, class S, class X> 00246 friend IT catarray_iter_create::_iter(X& a, size_t d, 00247 const array<size_t, S>& ind); 00248 template <class IT, class X> 00249 friend IT catarray_iter_create::_next(X& a, size_t d, const IT& it); 00250 template <class IT, class X> 00251 friend IT catarray_iter_create::_end(X& a, size_t d); 00252 template <class IT, class X> 00253 friend IT catarray_iter_create::_last(X& a, size_t d); 00254 00255 // non-const iterator 00256 iterator_nd _begin(size_t d) 00257 { return catarray_iter_create::_begin<iterator_nd>(*this, d); } 00258 00259 iterator_nd _begin(size_t d, const iterator_nd& it) 00260 { return catarray_iter_create::_begin<iterator_nd>(*this, d, it); } 00261 00262 iterator_nd _iter(size_t d, const typename 00263 array_nd::best_iterator& it) 00264 { return catarray_iter_create::_iter<iterator_nd>(*this, d, it); } 00265 00266 template <class S> 00267 iterator_nd _iter(size_t d, const array<size_t, S>& ind) 00268 { return catarray_iter_create::_iter<iterator_nd>(*this, d, ind); } 00269 00270 iterator_nd _next(size_t d, const iterator_nd& it) 00271 { return catarray_iter_create::_next<iterator_nd>(*this, d, it); } 00272 00273 iterator_nd _end(size_t d) 00274 { return catarray_iter_create::_end<iterator_nd>(*this, d); } 00275 00276 iterator_nd _last(size_t d) 00277 { return catarray_iter_create::_last<iterator_nd>(*this, d); } 00278 00279 // const iterator 00280 const_iterator_nd _begin(size_t d) const 00281 { return catarray_iter_create::_begin<const_iterator_nd>(*this, d); } 00282 00283 const_iterator_nd _begin(size_t d, const const_iterator_nd& it) const 00284 { return catarray_iter_create::_begin<const_iterator_nd>(*this, d, it); } 00285 00286 const_iterator_nd _iter(size_t d, const typename 00287 array_nd::const_iterator& it) const 00288 { return catarray_iter_create::_iter<const_iterator_nd>(*this, d, it); } 00289 00290 template <class S> 00291 const_iterator_nd _iter(size_t d, const array<size_t, S>& ind) const 00292 { return catarray_iter_create::_iter<const_iterator_nd>(*this, d, ind); } 00293 00294 const_iterator_nd _next(size_t d, const const_iterator_nd& it) const 00295 { return catarray_iter_create::_next<const_iterator_nd>(*this, d, it); } 00296 00297 const_iterator_nd _end(size_t d) const 00298 { return catarray_iter_create::_end<const_iterator_nd>(*this, d); } 00299 00300 const_iterator_nd _last(size_t d) const 00301 { return catarray_iter_create::_last<const_iterator_nd>(*this, d); } 00302 00303 // fast 00304 _fast_iterator_nd _fast_begin(size_t d) 00305 { return catarray_iter_create::_begin<_fast_iterator_nd>(*this, d); } 00306 _fast_iterator_nd _fast_last(size_t d) 00307 { return catarray_iter_create::_last<_fast_iterator_nd>(*this, d); } 00308 _fast_const_iterator_nd _fast_begin(size_t d) const 00309 { return catarray_iter_create::_begin<_fast_const_iterator_nd>(*this, d); } 00310 _fast_const_iterator_nd _fast_last(size_t d) const 00311 { return catarray_iter_create::_last<_fast_const_iterator_nd>(*this, d); } 00312 00313 #if 0 00314 // non-const reverse iterator 00315 reverse_iterator_nd _rbegin(size_t d); 00316 reverse_iterator_nd _rbegin(size_t d, const reverse_iterator_nd& itr); 00317 reverse_iterator_nd _riter(size_t d, const 00318 typename array_nd::best_iterator& it); 00319 template <class S> 00320 reverse_iterator_nd _riter(size_t d, array<size_t, S> ind); 00321 reverse_iterator_nd _rnext(size_t d, const reverse_iterator_nd& itr); 00322 reverse_iterator_nd _rend(size_t d); 00323 reverse_iterator_nd _rlast(size_t d); 00324 // const reverse reverse_iterator 00325 const_reverse_iterator_nd _rbegin(size_t d) const; 00326 const_reverse_iterator_nd _rbegin(size_t d, 00327 const const_reverse_iterator_nd& itr) const; 00328 const_reverse_iterator_nd _riter(size_t d, 00329 const typename array_nd::const_iterator& it) const; 00330 template <class S> 00331 const_reverse_iterator_nd _riter(size_t d, array<size_t, S> ind) const; 00332 const_reverse_iterator_nd _rnext(size_t d, 00333 const const_reverse_iterator_nd& itr) const; 00334 const_reverse_iterator_nd _rend(size_t d) const; 00335 const_reverse_iterator_nd _rlast(size_t d) const; 00336 #endif 00337 00338 // iter_nd_border_walker functions 00339 iter_nd_border_walker first_to_last(size_t d) const 00340 { 00341 size_t j = nonsing_rmap[d]; 00342 ptrdiff_t k = idx_ar_rmap[d]; 00343 return iter_nd_border_walker(iter[j], first_to_lasts[j], 00344 sizes[j] - 1, k); 00345 } 00346 00347 iter_nd_border_walker begin_to_end(size_t d) const 00348 { 00349 size_t j = nonsing_rmap[d]; 00350 ptrdiff_t k = idx_ar_rmap[d]; 00351 return iter_nd_border_walker(iter[j], begin_to_ends[j], 00352 sizes[j], k); 00353 } 00354 00355 00356 00357 using base_class::derived; 00358 00359 00360 00361 00362 00364 base_class& base() { return *this; } 00365 const base_class& base() const { return *this; } 00366 00367 00374 using base_class::operator[]; 00375 using base_class::length; 00376 using base_class::numel; 00377 00378 using common_base_class::operator(); 00379 00383 #if 0 00384 // TODO: have to implement 00389 T& operator()(size_t s1); 00390 T& operator()(size_t s1, size_t s2); 00391 T& operator()(size_t s1, size_t s2, size_t s3); 00392 T& operator()(size_t s1, size_t s2, size_t s3, size_t s4); 00393 T& operator()(size_t s1, size_t s2, size_t s3, size_t s4, size_t s5); 00394 T& operator()(size_t s1, size_t s2, size_t s3, size_t s4, size_t s5, size_t s6); 00395 #endif 00396 00399 template<class S> 00400 typename types::best_iterator<array_nd>::type::reference operator()( 00401 const array<size_t, S>& indx) 00402 { 00403 iterator_nd p(_begin(0) + indx[0]); 00404 for(size_t i = 1; i < indx.length(); i++) 00405 p.move_along(_begin(i), indx[i]); 00406 return *p; 00407 } 00408 00409 #if 0 00410 const T& operator()(size_t s1) const; 00411 const T& operator()(size_t s1, size_t s2) const; 00412 const T& operator()(size_t s1, size_t s2, size_t s3) const; 00413 const T& operator()(size_t s1, size_t s2, size_t s3, size_t s4) const; 00414 const T& operator()(size_t s1, size_t s2, size_t s3, size_t s4, size_t s5) const; 00415 const T& operator()(size_t s1, size_t s2, size_t s3, size_t s4, size_t s5, size_t s6) const; 00416 #endif 00417 00420 template<class S> 00421 typename array_nd::const_iterator::reference operator() 00422 (const array<size_t, S>& indx) const 00423 { 00424 const_iterator_nd p(_begin(0) + indx[0]); 00425 00426 for(size_t i = 1; i < indx.length(); i++) 00427 p.move_along(_begin(i), indx[i]); 00428 00429 return *p; 00430 } 00431 00432 00435 00436 array_nd() { } 00437 00439 array_nd(A& a, const I& idx) { this->setref(a, idx); } 00440 00442 array_nd(const this_type& a) : 00443 common_base_class(a) {}; 00450 // Construct by defining an element count. 00451 explicit array_nd(size_t count) { } 00452 00453 // Construct by defining an element count and a sigle default value 00454 array_nd(size_t count, const T& s) { } 00455 00456 // Construct by defining an element count and a pointer to data. 00457 array_nd(size_t count, const T *data) { } 00458 00459 // Construct from a size_array containing the dimension sizes 00460 template<class S> 00461 array_nd(const array<size_t, S>& sz) { } 00462 00463 // construct from a size_array containing the dimension sizes and scalar 00464 template<class S> 00465 array_nd(const array<size_t, S>& sz, const T& s) { } 00466 00467 //Construct from a size_array and pointer 00468 template<class S> 00469 array_nd(const array<size_t, S>& sz, const T* ptr) { } 00470 00471 //Construct from a size_array and an array with the values. 00472 template<class S, class J, class D> 00473 array_nd(const array<size_t, S>& sz, const array<J, D>& a) { } 00474 00475 // Constructor using another form of array_nd 00476 template<class J, class S> 00477 array_nd(const array_nd<J, S>& a) { } 00478 00484 00485 size_nd_ref_type size_nd() const { return all_sizes; } 00486 00488 size_t size_nd(size_t d) const { return all_sizes[d]; } 00489 00490 stride_ref_type stride() const 00491 { 00492 // no stored stride information because catarray has no random access 00493 return cumprod(shift(all_sizes, 1, size_t(1))); 00494 } 00495 00497 size_type size() const { return all_sizes; } 00498 00500 size_t size(size_t d) const { return all_sizes[d]; } 00501 00503 size_t ndims() const { return all_sizes.length(); } 00509 // TODO: need to perform cut on resize(0) for special index_array values 00516 template<class K> 00517 derived_type& operator=(const K& k) 00518 { common_base_class::operator=(k); return derived(); } 00519 //using common_base_class::operator=; 00520 00522 this_type& operator=(const this_type& in) 00523 { common_base_class::operator=(in); return *this; } 00524 /* 00526 derived_type& operator=(const T& s) 00527 { 00528 base_class::operator=(array<T, 00529 data::ref_val_repeat, types::term>(this->length(), s)); 00530 return this->derived(); 00531 } 00532 00534 template<class S, class K> 00535 derived_type& operator=(const array_nd<T, S, K>& a) 00536 { base_class::operator=(a); return *this; } 00537 */ 00540 }; 00541 00542 #endif