/usr/include/viennacl/linalg/inner_prod.hpp is in libviennacl-dev 1.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #ifndef VIENNACL_LINALG_INNER_PROD_HPP_
#define VIENNACL_LINALG_INNER_PROD_HPP_
/* =========================================================================
Copyright (c) 2010-2014, 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 PDF manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
/** @file viennacl/linalg/inner_prod.hpp
@brief Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
*/
#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
{
//
// generic inner_prod function
// uses tag dispatch to identify which algorithm
// should be called
//
namespace linalg
{
#ifdef VIENNACL_WITH_EIGEN
// ----------------------------------------------------
// EIGEN
//
template< typename VectorT1, typename VectorT2 >
typename viennacl::enable_if< viennacl::is_eigen< typename viennacl::traits::tag_of< VectorT1 >::type >::value,
typename VectorT1::RealScalar>::type
inner_prod(VectorT1 const& v1, VectorT2 const& v2)
{
//std::cout << "eigen .. " << std::endl;
return v1.dot(v2);
}
#endif
#ifdef VIENNACL_WITH_MTL4
// ----------------------------------------------------
// MTL4
//
template< typename VectorT1, typename VectorT2 >
typename viennacl::enable_if< viennacl::is_mtl4< typename viennacl::traits::tag_of< VectorT1 >::type >::value,
typename VectorT1::value_type>::type
inner_prod(VectorT1 const& v1, VectorT2 const& v2)
{
//std::cout << "mtl4 .. " << std::endl;
return mtl::dot(v1, v2);
}
#endif
#ifdef VIENNACL_WITH_UBLAS
// ----------------------------------------------------
// UBLAS
//
template< typename VectorT1, typename VectorT2 >
typename viennacl::enable_if< viennacl::is_ublas< typename viennacl::traits::tag_of< VectorT1 >::type >::value,
typename VectorT1::value_type>::type
inner_prod(VectorT1 const& v1, VectorT2 const& v2)
{
//std::cout << "ublas .. " << std::endl;
return boost::numeric::ublas::inner_prod(v1, v2);
}
#endif
// ----------------------------------------------------
// STL
//
template< typename VectorT1, typename VectorT2 >
typename viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value,
typename VectorT1::value_type>::type
inner_prod(VectorT1 const& v1, VectorT2 const& v2)
{
assert(v1.size() == v2.size() && bool("Vector sizes mismatch"));
//std::cout << "stl .. " << std::endl;
typename VectorT1::value_type result = 0;
for (typename VectorT1::size_type i=0; i<v1.size(); ++i)
result += v1[i] * v2[i];
return result;
}
// ----------------------------------------------------
// VIENNACL
//
template< typename NumericT>
viennacl::scalar_expression< const vector_base<NumericT>, const vector_base<NumericT>, viennacl::op_inner_prod >
inner_prod(vector_base<NumericT> const & vector1,
vector_base<NumericT> const & vector2)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const vector_base<NumericT>,
const vector_base<NumericT>,
viennacl::op_inner_prod >(vector1, vector2);
}
// expression on lhs:
template< typename LHS, typename RHS, typename OP, typename NumericT>
viennacl::scalar_expression< const viennacl::vector_expression<LHS, RHS, OP>,
const vector_base<NumericT>,
viennacl::op_inner_prod >
inner_prod(viennacl::vector_expression<LHS, RHS, OP> const & vector1,
vector_base<NumericT> const & vector2)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const viennacl::vector_expression<LHS, RHS, OP>,
const vector_base<NumericT>,
viennacl::op_inner_prod >(vector1, vector2);
}
// expression on rhs:
template <typename NumericT, typename LHS, typename RHS, typename OP>
viennacl::scalar_expression< const vector_base<NumericT>,
const viennacl::vector_expression<LHS, RHS, OP>,
viennacl::op_inner_prod >
inner_prod(vector_base<NumericT> const & vector1,
viennacl::vector_expression<LHS, RHS, OP> const & vector2)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const vector_base<NumericT>,
const viennacl::vector_expression<LHS, RHS, OP>,
viennacl::op_inner_prod >(vector1, vector2);
}
// expression on lhs and rhs:
template <typename LHS1, typename RHS1, typename OP1,
typename LHS2, typename RHS2, typename OP2>
viennacl::scalar_expression< const viennacl::vector_expression<LHS1, RHS1, OP1>,
const viennacl::vector_expression<LHS2, RHS2, OP2>,
viennacl::op_inner_prod >
inner_prod(viennacl::vector_expression<LHS1, RHS1, OP1> const & vector1,
viennacl::vector_expression<LHS2, RHS2, OP2> const & vector2)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const viennacl::vector_expression<LHS1, RHS1, OP1>,
const viennacl::vector_expression<LHS2, RHS2, OP2>,
viennacl::op_inner_prod >(vector1, vector2);
}
// Multiple inner products:
template< typename NumericT>
viennacl::vector_expression< const vector_base<NumericT>, const vector_tuple<NumericT>, viennacl::op_inner_prod >
inner_prod(vector_base<NumericT> const & x,
vector_tuple<NumericT> const & y_tuple)
{
return viennacl::vector_expression< const vector_base<NumericT>,
const vector_tuple<NumericT>,
viennacl::op_inner_prod >(x, y_tuple);
}
} // end namespace linalg
} // end namespace viennacl
#endif
|