ivl 679
ivl/details/core/loops/row_func_nd.hpp
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 #ifndef IVL_CORE_DETAILS_LOOPS_ROW_FUNC_ND_HPP
00025 #define IVL_CORE_DETAILS_LOOPS_ROW_FUNC_ND_HPP
00026 
00027 namespace ivl {
00028 
00029 namespace loops {
00030 
00031 // The loops for the nd row func arrays.
00032 
00033 /* Performance Warning:
00034 * There is a possible improvement. Each array of the output arrays
00035 * is incemented using the sequential iterator. However, the ideal
00036 * would be to use the best-possible iterator, having either
00037 * sequential or nd-sequential iterations. This would make
00038 * the loop too complicated cause it would have many arrays with
00039 * many different iterator_nd, and so it is omitted.
00040 */
00041 
00042 
00043 template
00044 <
00045 class T, class D, class P,
00046 class S, class K,
00047 class L1, class M1, class N1,
00048 class L2, class M2, class N2>
00049 void row_func_nd_output(const array_nd<T, D, P>& in, size_t, in_dim,
00050         const array<size_t, S, K> in_dims, const array<size_t, S, K>& sizes,
00051         array_nd<L1, M1, N1>& o1, array_nd<L2, M2, N2>& o2)
00052 {
00053 
00054         /*
00055         array<size_t, data::little> dims(in.ndim() - 1);
00056         for(size_t i = 0; i < dims.length(); i++)
00057                 dims[i] = i + (i >= in_dim ? 1 : 0);
00058 
00059         array<size_t, data::little> sizes(dims.length());
00060         for(size_t i = 0; i < dims.length(); i++)
00061                 sizes[i] = in.size(dims[i]);
00062 
00063         size_t row = in_dim == 0 ? 1 : len;
00064         size_t col = in_dim == 1 ? 1 : len;
00065         */
00066         iter[in_dims.size() - 1] = in->_begin(in_dims[in_dims.size() - 1]);
00067         iter_e[in_dims.size() - 1] = in->_end(in_dims[in_dims.size() - 1]);
00068         for(size_t d = in_dims.size() - 2; d > 0; d++) {
00069                 iter[d] = in->_iter(in_dims[d], iter[d + 1]);
00070                 iter_e[d] = in->_next(in_dims[d], iter[d]);
00071         }
00072         in_dim0 = in_dims[0];
00073         iter0 = in->_begin(in_dim0);
00074         iter_e0 = in->_end(in_dim0);
00075         size0 = sizes[0];
00076 
00077         do {
00078                 for(; iter0 != iter_e0; iter0++) {
00079 
00080                         F::calculate(const_iter_array(in->_iter(in_dim, iter0)),
00081                                 *it1, *it2);
00082 
00083                         ++it1;
00084                         ++it2;
00085                 }
00086 
00087 
00088 
00089         } while(1);
00090 
00091         typename array_nd<L1, M1, N1>::iterator_nd it1 = o1._begin(1 - in_dim);
00092         typename array_nd<L2, M2, N2>::iterator_nd it2 = o2._begin(1 - in_dim);
00093 
00094         typedef typename array_nd<T, D, P>::const_iterator_nd in_iter_nd;
00095         in_iter_nd cit = in->_begin(1 - in_dim);
00096         in_iter_nd cit_end = in->_end(1 - in_dim);
00097 
00098         for(; cit != cit_end; ++cit, ++it1, ++it2) {
00099                 F::calculate(
00100                         const_iter_array(in->_iter(in_dim, cit)),
00101                         *it1, *it2);
00102         }
00103 }
00104 
00105 template
00106 <
00107 class T, class D, class P,
00108 class L1, class M1, class N1,
00109 class L2, class M2, class N2,
00110 class L3, class M3, class N3>
00111 void row_func_nd_output(const array_nd<T, D, P>& in, size_t, in_dim,
00112         array_nd<L1, M1, N1>& o1,
00113         array_nd<L2, M2, N2>& o2,
00114         array_nd<L3, M3, N3>& o3)
00115 {
00116         size_t len = this->length();
00117         size_t row = in_dim == 0 ? 1 : len;
00118         size_t col = in_dim == 1 ? 1 : len;
00119         o1.resize(row, col);
00120         o2.resize(row, col);
00121         o3.resize(row, col);
00122         typename array_nd<L1, M1, N1>::iterator_nd it1 = o1._begin(1 - in_dim);
00123         typename array_nd<L2, M2, N2>::iterator_nd it2 = o2._begin(1 - in_dim);
00124         typename array_nd<L3, M3, N3>::iterator_nd it3 = o3._begin(1 - in_dim);
00125 
00126         typedef typename array_nd<T, D, P>::const_iterator_nd in_iter_nd;
00127         in_iter_nd cit = in->_begin(1 - in_dim);
00128         in_iter_nd cit_end = this->_next(1 - in_dim, cit);
00129 
00130         for(; cit != cit_end; ++cit, ++it1, ++it2, ++it3) {
00131                 F::calculate(const_iter_array(in->_iter(in_dim, cit)),
00132                         *it1, *it2, *it3);
00133         }
00134 }
00135 
00136 
00137 template
00138 <
00139 class T, class D, class P,
00140 class L1, class M1, class N1,
00141 class L2, class M2, class N2,
00142 class L3, class M3, class N3,
00143 class L4, class M4, class N4>
00144 void row_func_nd_output(const array_nd<T, D, P>& in, size_t, in_dim,
00145 array_nd<L1, M1, N1>& o1,
00146 array_nd<L2, M2, N2>& o2,
00147 array_nd<L3, M3, N3>& o3,
00148 array_nd<L4, M4, N4>& o4)
00149 {
00150         size_t len = this->length();
00151         size_t row = in_dim == 0 ? 1 : len;
00152         size_t col = in_dim == 1 ? 1 : len;
00153         o1.resize(row, col);
00154         o2.resize(row, col);
00155         o3.resize(row, col);
00156         o4.resize(row, col);
00157         typename array_nd<L1, M1, N1>::iterator_nd it1 = o1._begin(1 - in_dim);
00158         typename array_nd<L2, M2, N2>::iterator_nd it2 = o2._begin(1 - in_dim);
00159         typename array_nd<L3, M3, N3>::iterator_nd it3 = o3._begin(1 - in_dim);
00160         typename array_nd<L4, M4, N4>::iterator_nd it4 = o4._begin(1 - in_dim);
00161 
00162         typedef typename array_nd<T, D, P>::const_iterator_nd in_iter_nd;
00163         in_iter_nd cit = in->_begin(1 - in_dim);
00164         in_iter_nd cit_end = this->_next(1 - in_dim, cit);
00165 
00166         for(; cit != cit_end; ++cit, ++it1, ++it2, ++it3, ++it4) {
00167                 F::calculate(const_iter_array(in->_iter(in_dim, cit)),
00168                         *it1, *it2, *it3, *it4);
00169         }
00170 }
00171 
00172 
00173 }; /*namespace loops*/
00174 
00175 }; /*namespace ivl*/
00176 
00177 #endif // IVL_CORE_DETAILS_LOOPS_ROW_FUNC_ND_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations