ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
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-2015, 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"
28 #include "viennacl/meta/tag_of.hpp"
30 
31 namespace viennacl
32 {
33 namespace linalg
34 {
35 
36 //
37 // Sum of vector entries
38 //
39 
41 template<typename NumericT>
45 sum(viennacl::vector_base<NumericT> const & x)
46 {
48  const viennacl::vector_base<NumericT>,
49  viennacl::op_sum >(x, x);
50 }
51 
56 template<typename LHS, typename RHS, typename OP>
60 sum(viennacl::vector_expression<const LHS, const RHS, OP> const & x)
61 {
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>
77 row_sum(viennacl::matrix_base<NumericT> const & A)
78 {
80  const viennacl::matrix_base<NumericT>,
81  viennacl::op_row_sum >(A, A);
82 }
83 
88 template<typename LHS, typename RHS, typename OP>
92 row_sum(viennacl::matrix_expression<const LHS, const RHS, OP> const & A)
93 {
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>
107  const viennacl::matrix_base<NumericT>,
109 column_sum(viennacl::matrix_base<NumericT> const & A)
110 {
112  const viennacl::matrix_base<NumericT>,
113  viennacl::op_col_sum >(A, A);
114 }
115 
120 template<typename LHS, typename RHS, typename OP>
122  const viennacl::matrix_expression<const LHS, const RHS, OP>,
124 column_sum(viennacl::matrix_expression<const LHS, const RHS, OP> const & A)
125 {
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 
A tag class representing the summation of all columns of a matrix.
Definition: forwards.h:122
Dispatch facility for distinguishing between ublas, STL and ViennaCL types.
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
A tag class representing the summation of a vector.
Definition: forwards.h:116
A tag class representing the summation of all rows of a matrix.
Definition: forwards.h:119
Various little tools used here and there in ViennaCL.
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
Expression template class for representing a tree of expressions which ultimately result in a matrix...
Definition: forwards.h:341
This file provides the forward declarations for the main types used within ViennaCL.
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:230
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
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
A collection of compile time type deductions.
Simple enable-if variant that uses the SFINAE pattern.