Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
include
shark
LinAlg
BLAS
kernels
default
matrix_fold.hpp
Go to the documentation of this file.
1
/*!
2
* \brief Kernels for folding matrix expressions
3
*
4
* \author O. Krause
5
* \date 2016
6
*
7
*
8
* \par Copyright 1995-2015 Shark Development Team
9
*
10
* <BR><HR>
11
* This file is part of Shark.
12
* <http://image.diku.dk/shark/>
13
*
14
* Shark is free software: you can redistribute it and/or modify
15
* it under the terms of the GNU Lesser General Public License as published
16
* by the Free Software Foundation, either version 3 of the License, or
17
* (at your option) any later version.
18
*
19
* Shark is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU Lesser General Public License for more details.
23
*
24
* You should have received a copy of the GNU Lesser General Public License
25
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
26
*
27
*/
28
#ifndef REMORA_KERNELS_DEFAULT_MATRIX_FOLD_HPP
29
#define REMORA_KERNELS_DEFAULT_MATRIX_FOLD_HPP
30
31
#include "../../detail/traits.hpp"
//orientations
32
#include "../../expression_types.hpp"
33
#include <type_traits>
34
namespace
remora{
namespace
bindings{
35
36
template
<
class
F,
class
M,
class
Orientation,
class
Tag>
37
void
matrix_fold(matrix_expression<M, cpu_tag>
const
& m,
typename
F::result_type& value, Orientation, Tag) {
38
F f;
39
for
(std::size_t i = 0; i != major_size(m); ++i){
40
auto
end = m().major_end(i);
41
for
(
auto
pos = m().major_begin(i);pos != end; ++pos){
42
value = f(value,*pos);
43
}
44
}
45
}
46
47
}}
48
#endif