fold_rows.hpp
Go to the documentation of this file.
1/*!
2 *
3 *
4 * \brief Folds the rows of a row-major or column major matrix.
5 *
6 * \author O. Krause
7 * \date 2018
8 *
9 *
10 * \par Copyright 1995-2015 Shark Development Team
11 *
12 * <BR><HR>
13 * This file is part of Shark.
14 * <http://image.diku.dk/shark/>
15 *
16 * Shark is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Lesser General Public License as published
18 * by the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * Shark is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
28 *
29 */
30
31#ifndef REMORA_KERNELS_FOLD_ROWS_HPP
32#define REMORA_KERNELS_FOLD_ROWS_HPP
33
34#include "default/fold_rows.hpp"
35#ifdef REMORA_USE_GPU
36#include "gpu/fold_rows.hpp"
37#endif
38
39namespace remora {namespace bindings{
40template<class F, class G, class M,class V, class Device>
41void fold_rows(
42 matrix_expression<M, Device> const & A,
43 vector_expression<V, Device>& b,
44 F f,
45 G g,
46 unknown_orientation
47){
48 fold_rows(A, b, f, g, row_major());
49}
50}
51
52namespace kernels{
53///\brief Folds each row of a matrix with a function f and transforms the result with another function g
54///
55/// output v_i is computed as v_i += g( f(A_i0, f(A_i1,... f(A_n-2i, A_n-1i) ))). That is, the result is the same
56/// as folding each row separately as if it was a collection of numbers.
57template <class F, class G, class M, class V, class Device>
58void fold_rows(
59 matrix_expression<M, Device> const & A,
60 vector_expression<V, Device>& b,
61 F f,
62 G g
63){
64 REMORA_SIZE_CHECK(A().size1() == b().size());
65 if(A().size1() == 0) return; //undefined
66 bindings::fold_rows(
67 A, b, f, g, typename M::orientation()
68 );
69}
70
71}}
72
73#endif