ViennaCL - The Vienna Computing Library: viennacl/linalg/sum.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sum.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_REDUCE_HPP_
2 #define VIENNACL_LINALG_REDUCE_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
25 #include "viennacl/forwards.h"
26 #include "viennacl/tools/tools.hpp"
27 #include "viennacl/meta/enable_if.hpp"
28 #include "viennacl/meta/tag_of.hpp"
29 #include "viennacl/meta/result_of.hpp"
30
31 namespace viennacl
32 {
33 namespace linalg
34 {
35
36 //
37 // Sum of vector entries
38 //
39
41 template<typename NumericT>
42 viennacl::scalar_expression< const viennacl::vector_base<NumericT>,
43 const viennacl::vector_base<NumericT>,
44 viennacl::op_sum >
45 sum(viennacl::vector_base<NumericT> const & x)
46 {
47 return viennacl::scalar_expression< const viennacl::vector_base<NumericT>,
48 const viennacl::vector_base<NumericT>,
49 viennacl::op_sum >(x, x);
50 }
51
56 template<typename LHS, typename RHS, typename OP>
57 viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>,
58 const viennacl::vector_expression<const LHS, const RHS, OP>,
59 viennacl::op_sum>
60 sum(viennacl::vector_expression<const LHS, const RHS, OP> const & x)
61 {
62 return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>,
63 const viennacl::vector_expression<const LHS, const RHS, OP>,
64 viennacl::op_sum >(x, x);
65 }
66
67
68 //
69 // Sum of entries in rows of a matrix
70 //
71
73 template<typename NumericT>
74 viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
75 const viennacl::matrix_base<NumericT>,
76 viennacl::op_row_sum >
77 row_sum(viennacl::matrix_base<NumericT> const & A)
78 {
79 return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
80 const viennacl::matrix_base<NumericT>,
81 viennacl::op_row_sum >(A, A);
82 }
83
88 template<typename LHS, typename RHS, typename OP>
89 viennacl::vector_expression<const viennacl::matrix_expression<const LHS, const RHS, OP>,
90 const viennacl::matrix_expression<const LHS, const RHS, OP>,
91 viennacl::op_row_sum>
92 row_sum(viennacl::matrix_expression<const LHS, const RHS, OP> const & A)
93 {
94 return viennacl::vector_expression< const viennacl::matrix_expression<const LHS, const RHS, OP>,
95 const viennacl::matrix_expression<const LHS, const RHS, OP>,
96 viennacl::op_row_sum >(A, A);
97 }
98
99
100 //
101 // Sum of entries in columns of a matrix
102 //
103
105 template<typename NumericT>
106 viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
107 const viennacl::matrix_base<NumericT>,
108 viennacl::op_col_sum >
109 column_sum(viennacl::matrix_base<NumericT> const & A)
110 {
111 return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
112 const viennacl::matrix_base<NumericT>,
113 viennacl::op_col_sum >(A, A);
114 }
115
120 template<typename LHS, typename RHS, typename OP>
121 viennacl::vector_expression<const viennacl::matrix_expression<const LHS, const RHS, OP>,
122 const viennacl::matrix_expression<const LHS, const RHS, OP>,
123 viennacl::op_col_sum>
124 column_sum(viennacl::matrix_expression<const LHS, const RHS, OP> const & A)
125 {
126 return viennacl::vector_expression< const viennacl::matrix_expression<const LHS, const RHS, OP>,
127 const viennacl::matrix_expression<const LHS, const RHS, OP>,
128 viennacl::op_col_sum >(A, A);
129 }
130
131
132 } // end namespace linalg
133 } // end namespace viennacl
134 #endif
135
136
viennacl::op_col_sum
A tag class representing the summation of all columns of a matrix.
Definition: forwards.h:122
tag_of.hpp
Dispatch facility for distinguishing between ublas, STL and ViennaCL types.
viennacl::linalg::sum
viennacl::scalar_expression< const viennacl::vector_base< NumericT >, const viennacl::vector_base< NumericT >, viennacl::op_sum > sum(viennacl::vector_base< NumericT > const &x)
User interface function for computing the sum of all elements of a vector.
Definition: sum.hpp:45
viennacl::op_sum
A tag class representing the summation of a vector.
Definition: forwards.h:116
viennacl::op_row_sum
A tag class representing the summation of all rows of a matrix.
Definition: forwards.h:119
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::linalg::row_sum
viennacl::vector_expression< const viennacl::matrix_base< NumericT >, const viennacl::matrix_base< NumericT >, viennacl::op_row_sum > row_sum(viennacl::matrix_base< NumericT > const &A)
User interface function for computing the sum of all elements of each row of a matrix.
Definition: sum.hpp:77
viennacl::matrix_base< NumericT >
viennacl::matrix_expression
Expression template class for representing a tree of expressions which ultimately result in a matrix...
Definition: forwards.h:341
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::scalar_expression
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:230
viennacl::vector_expression
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
viennacl::vector_base< NumericT >
viennacl::linalg::column_sum
viennacl::vector_expression< const viennacl::matrix_base< NumericT >, const viennacl::matrix_base< NumericT >, viennacl::op_col_sum > column_sum(viennacl::matrix_base< NumericT > const &A)
User interface function for computing the sum of all elements of each column of a matrix...
Definition: sum.hpp:109
result_of.hpp
A collection of compile time type deductions.
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.