All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sum.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_REDUCE_HPP_
#define VIENNACL_LINALG_REDUCE_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include "viennacl/forwards.h"
#include "viennacl/tools/tools.hpp"
#include "viennacl/meta/enable_if.hpp"
#include "viennacl/meta/tag_of.hpp"
#include "viennacl/meta/result_of.hpp"
namespace viennacl
{
namespace linalg
{
//
// Sum of vector entries
//
template<typename NumericT>
viennacl::scalar_expression< const viennacl::vector_base<NumericT>,
const viennacl::vector_base<NumericT>,
viennacl::op_sum >
sum(viennacl::vector_base<NumericT> const & x)
{
return viennacl::scalar_expression< const viennacl::vector_base<NumericT>,
const viennacl::vector_base<NumericT>,
viennacl::op_sum >(x, x);
}
template<typename LHS, typename RHS, typename OP>
viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>,
const viennacl::vector_expression<const LHS, const RHS, OP>,
viennacl::op_sum>
sum(viennacl::vector_expression<const LHS, const RHS, OP> const & x)
{
return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>,
const viennacl::vector_expression<const LHS, const RHS, OP>,
viennacl::op_sum >(x, x);
}
//
// Sum of entries in rows of a matrix
//
template<typename NumericT>
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)
{
return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
const viennacl::matrix_base<NumericT>,
viennacl::op_row_sum >(A, A);
}
template<typename LHS, typename RHS, typename OP>
viennacl::vector_expression<const viennacl::matrix_expression<const LHS, const RHS, OP>,
const viennacl::matrix_expression<const LHS, const RHS, OP>,
viennacl::op_row_sum>
row_sum(viennacl::matrix_expression<const LHS, const RHS, OP> const & A)
{
return viennacl::vector_expression< const viennacl::matrix_expression<const LHS, const RHS, OP>,
const viennacl::matrix_expression<const LHS, const RHS, OP>,
viennacl::op_row_sum >(A, A);
}
//
// Sum of entries in columns of a matrix
//
template<typename NumericT>
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)
{
return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
const viennacl::matrix_base<NumericT>,
viennacl::op_col_sum >(A, A);
}
template<typename LHS, typename RHS, typename OP>
viennacl::vector_expression<const viennacl::matrix_expression<const LHS, const RHS, OP>,
const viennacl::matrix_expression<const LHS, const RHS, OP>,
viennacl::op_col_sum>
column_sum(viennacl::matrix_expression<const LHS, const RHS, OP> const & A)
{
return viennacl::vector_expression< const viennacl::matrix_expression<const LHS, const RHS, OP>,
const viennacl::matrix_expression<const LHS, const RHS, OP>,
viennacl::op_col_sum >(A, A);
}
} // end namespace linalg
} // end namespace viennacl
#endif
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.