This file is indexed.

/usr/include/viennacl/linalg/prod.hpp is in libviennacl-dev 1.7.1+dfsg1-2.

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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#ifndef VIENNACL_LINALG_PROD_HPP_
#define VIENNACL_LINALG_PROD_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
============================================================================= */

/** @file viennacl/linalg/prod.hpp
    @brief Generic interface for matrix-vector and matrix-matrix products.
           See viennacl/linalg/vector_operations.hpp, viennacl/linalg/matrix_operations.hpp, and
           viennacl/linalg/sparse_matrix_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 <vector>
#include <map>

namespace viennacl
{
  //
  // generic prod function
  //   uses tag dispatch to identify which algorithm
  //   should be called
  //
  namespace linalg
  {
    #ifdef VIENNACL_WITH_MTL4
    // ----------------------------------------------------
    // mtl4
    //
    template< typename MatrixT, typename VectorT >
    typename viennacl::enable_if< viennacl::is_mtl4< typename viennacl::traits::tag_of< MatrixT >::type >::value,
                                  VectorT>::type
    prod(MatrixT const& matrix, VectorT const& vector)
    {
      return VectorT(matrix * vector);
    }
    #endif

    #ifdef VIENNACL_WITH_ARMADILLO
    // ----------------------------------------------------
    // Armadillo
    //
    template<typename NumericT, typename VectorT>
    VectorT prod(arma::SpMat<NumericT> const& A, VectorT const& vector)
    {
      return A * vector;
    }
    #endif

    #ifdef VIENNACL_WITH_EIGEN
    // ----------------------------------------------------
    // Eigen
    //
    template< typename MatrixT, typename VectorT >
    typename viennacl::enable_if< viennacl::is_eigen< typename viennacl::traits::tag_of< MatrixT >::type >::value,
                                  VectorT>::type
    prod(MatrixT const& matrix, VectorT const& vector)
    {
      return matrix * vector;
    }
    #endif

    #ifdef VIENNACL_WITH_UBLAS
    // ----------------------------------------------------
    // UBLAS
    //
    template< typename MatrixT, typename VectorT >
    typename viennacl::enable_if< viennacl::is_ublas< typename viennacl::traits::tag_of< MatrixT >::type >::value,
                                  VectorT>::type
    prod(MatrixT const& matrix, VectorT const& vector)
    {
      // std::cout << "ublas .. " << std::endl;
      return boost::numeric::ublas::prod(matrix, vector);
    }
    #endif


    // ----------------------------------------------------
    // STL type
    //

    // dense matrix-vector product:
    template< typename T, typename A1, typename A2, typename VectorT >
    VectorT
    prod(std::vector< std::vector<T, A1>, A2 > const & matrix, VectorT const& vector)
    {
      VectorT result(matrix.size());
      for (typename std::vector<T, A1>::size_type i=0; i<matrix.size(); ++i)
      {
        result[i] = 0; //we will not assume that VectorT is initialized to zero
        for (typename std::vector<T, A1>::size_type j=0; j<matrix[i].size(); ++j)
          result[i] += matrix[i][j] * vector[j];
      }
      return result;
    }

    // sparse matrix-vector product:
    template< typename KEY, typename DATA, typename COMPARE, typename AMAP, typename AVEC, typename VectorT >
    VectorT
    prod(std::vector< std::map<KEY, DATA, COMPARE, AMAP>, AVEC > const& matrix, VectorT const& vector)
    {
      typedef std::vector< std::map<KEY, DATA, COMPARE, AMAP>, AVEC > MatrixType;

      VectorT result(matrix.size());
      for (typename MatrixType::size_type i=0; i<matrix.size(); ++i)
      {
        result[i] = 0; //we will not assume that VectorT is initialized to zero
        for (typename std::map<KEY, DATA, COMPARE, AMAP>::const_iterator row_entries = matrix[i].begin();
             row_entries != matrix[i].end();
             ++row_entries)
          result[i] += row_entries->second * vector[row_entries->first];
      }
      return result;
    }


    /*template< typename MatrixT, typename VectorT >
    VectorT
    prod(MatrixT const& matrix, VectorT const& vector,
         typename viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< MatrixT >::type >::value
                                     >::type* dummy = 0)
    {
      // std::cout << "std .. " << std::endl;
      return prod_impl(matrix, vector);
    }*/

    // ----------------------------------------------------
    // VIENNACL
    //

    // standard product:
    template<typename NumericT>
    viennacl::matrix_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::matrix_base<NumericT>,
                                 viennacl::op_mat_mat_prod >
    prod(viennacl::matrix_base<NumericT> const & A,
         viennacl::matrix_base<NumericT> const & B)
    {
      return viennacl::matrix_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::matrix_base<NumericT>,
                                          viennacl::op_mat_mat_prod >(A, B);
    }

    // right factor is a matrix expression:
    template<typename NumericT, typename LhsT, typename RhsT, typename OpT>
    viennacl::matrix_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::matrix_expression<const LhsT, const RhsT, OpT>,
                                 viennacl::op_mat_mat_prod >
    prod(viennacl::matrix_base<NumericT> const & A,
         viennacl::matrix_expression<const LhsT, const RhsT, OpT> const & B)
    {
      return viennacl::matrix_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::matrix_expression<const LhsT, const RhsT, OpT>,
                                          viennacl::op_mat_mat_prod >(A, B);
    }

    // left factor is a matrix expression:
    template<typename LhsT, typename RhsT, typename OpT, typename NumericT>
    viennacl::matrix_expression< const viennacl::matrix_expression<const LhsT, const RhsT, OpT>,
                                 const viennacl::matrix_base<NumericT>,
                                 viennacl::op_mat_mat_prod >
    prod(viennacl::matrix_expression<const LhsT, const RhsT, OpT> const & A,
         viennacl::matrix_base<NumericT> const & B)
    {
      return viennacl::matrix_expression< const viennacl::matrix_expression<const LhsT, const RhsT, OpT>,
                                          const viennacl::matrix_base<NumericT>,
                                          viennacl::op_mat_mat_prod >(A, B);
    }


    // both factors transposed:
    template<typename LhsT1, typename RhsT1, typename OpT1,
             typename LhsT2, typename RhsT2, typename OpT2>
    viennacl::matrix_expression< const viennacl::matrix_expression<const LhsT1, const RhsT1, OpT1>,
                                 const viennacl::matrix_expression<const LhsT2, const RhsT2, OpT2>,
                                 viennacl::op_mat_mat_prod >
    prod(viennacl::matrix_expression<const LhsT1, const RhsT1, OpT1> const & A,
         viennacl::matrix_expression<const LhsT2, const RhsT2, OpT2> const & B)
    {
      return viennacl::matrix_expression< const viennacl::matrix_expression<const LhsT1, const RhsT1, OpT1>,
                                          const viennacl::matrix_expression<const LhsT2, const RhsT2, OpT2>,
                                          viennacl::op_mat_mat_prod >(A, B);
    }



    // matrix-vector product
    template< typename NumericT>
    viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::vector_base<NumericT>,
                                 viennacl::op_prod >
    prod(viennacl::matrix_base<NumericT> const & A,
         viennacl::vector_base<NumericT> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::vector_base<NumericT>,
                                          viennacl::op_prod >(A, x);
    }

    // matrix-vector product (resolve ambiguity)
    template<typename NumericT, typename F>
    viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::vector_base<NumericT>,
                                 viennacl::op_prod >
    prod(viennacl::matrix<NumericT, F> const & A,
         viennacl::vector_base<NumericT> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::vector_base<NumericT>,
                                          viennacl::op_prod >(A, x);
    }

    // matrix-vector product (resolve ambiguity)
    template<typename MatrixT, typename NumericT>
    viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::vector_base<NumericT>,
                                 viennacl::op_prod >
    prod(viennacl::matrix_range<MatrixT> const & A,
         viennacl::vector_base<NumericT> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::vector_base<NumericT>,
                                          viennacl::op_prod >(A, x);
    }

    // matrix-vector product (resolve ambiguity)
    template<typename MatrixT, typename NumericT>
    viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::vector_base<NumericT>,
                                 viennacl::op_prod >
    prod(viennacl::matrix_slice<MatrixT> const & A,
         viennacl::vector_base<NumericT> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::vector_base<NumericT>,
                                          viennacl::op_prod >(A, x);
    }

    // matrix-vector product with matrix expression (including transpose)
    template< typename NumericT, typename LhsT, typename RhsT, typename OpT>
    viennacl::vector_expression< const viennacl::matrix_expression<const LhsT, const RhsT, OpT>,
                                 const viennacl::vector_base<NumericT>,
                                 viennacl::op_prod >
    prod(viennacl::matrix_expression<const LhsT, const RhsT, OpT> const & A,
         viennacl::vector_base<NumericT> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_expression<const LhsT, const RhsT, OpT>,
                                          const viennacl::vector_base<NumericT>,
                                          viennacl::op_prod >(A, x);
    }


    // matrix-vector product with vector expression
    template< typename NumericT, typename LhsT, typename RhsT, typename OpT>
    viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                 const viennacl::vector_expression<const LhsT, const RhsT, OpT>,
                                 viennacl::op_prod >
    prod(viennacl::matrix_base<NumericT> const & A,
         viennacl::vector_expression<const LhsT, const RhsT, OpT> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_base<NumericT>,
                                          const viennacl::vector_expression<const LhsT, const RhsT, OpT>,
                                          viennacl::op_prod >(A, x);
    }


    // matrix-vector product with matrix expression (including transpose) and vector expression
    template<typename LhsT1, typename RhsT1, typename OpT1,
             typename LhsT2, typename RhsT2, typename OpT2>
    viennacl::vector_expression< const viennacl::matrix_expression<const LhsT1, const RhsT1, OpT1>,
                                 const viennacl::vector_expression<const LhsT2, const RhsT2, OpT2>,
                                 viennacl::op_prod >
    prod(viennacl::matrix_expression<const LhsT1, const RhsT1, OpT1> const & A,
         viennacl::vector_expression<const LhsT2, const RhsT2, OpT2> const & x)
    {
      return viennacl::vector_expression< const viennacl::matrix_expression<const LhsT1, const RhsT1, OpT1>,
                                          const viennacl::vector_expression<const LhsT2, const RhsT2, OpT2>,
                                          viennacl::op_prod >(A, x);
    }




    template< typename SparseMatrixType, typename SCALARTYPE>
    typename viennacl::enable_if< viennacl::is_any_sparse_matrix<SparseMatrixType>::value,
                                  viennacl::matrix_expression<const SparseMatrixType,
                                                              const matrix_base <SCALARTYPE>,
                                                              op_prod >
                                 >::type
    prod(const SparseMatrixType & sp_mat,
         const viennacl::matrix_base<SCALARTYPE> & d_mat)
    {
      return viennacl::matrix_expression<const SparseMatrixType,
                                         const viennacl::matrix_base<SCALARTYPE>,
                                         op_prod >(sp_mat, d_mat);
    }

    // right factor is transposed
    template< typename SparseMatrixType, typename SCALARTYPE>
    typename viennacl::enable_if< viennacl::is_any_sparse_matrix<SparseMatrixType>::value,
                                  viennacl::matrix_expression< const SparseMatrixType,
                                                               const viennacl::matrix_expression<const viennacl::matrix_base<SCALARTYPE>,
                                                                                                 const viennacl::matrix_base<SCALARTYPE>,
                                                                                                 op_trans>,
                                                               viennacl::op_prod >
                                  >::type
    prod(const SparseMatrixType & A,
         viennacl::matrix_expression<const viennacl::matrix_base<SCALARTYPE>,
                                     const viennacl::matrix_base<SCALARTYPE>,
                                     op_trans> const & B)
    {
      return viennacl::matrix_expression< const SparseMatrixType,
                                          const viennacl::matrix_expression<const viennacl::matrix_base<SCALARTYPE>,
                                                                            const viennacl::matrix_base<SCALARTYPE>,
                                                                            op_trans>,
                                          viennacl::op_prod >(A, B);
    }


    /** @brief Sparse matrix-matrix product with compressed_matrix objects */
    template<typename NumericT>
    viennacl::matrix_expression<const compressed_matrix<NumericT>,
                                const compressed_matrix<NumericT>,
                                op_prod >
    prod(compressed_matrix<NumericT> const & A,
         compressed_matrix<NumericT> const & B)
    {
      return viennacl::matrix_expression<const compressed_matrix<NumericT>,
                                         const compressed_matrix<NumericT>,
                                         op_prod >(A, B);
    }

    /** @brief Generic matrix-vector product with user-provided sparse matrix type */
    template<typename SparseMatrixType, typename NumericT>
    vector_expression<const SparseMatrixType,
                      const vector_base<NumericT>,
                      op_prod >
    prod(const SparseMatrixType & A,
         const vector_base<NumericT> & x)
    {
      return vector_expression<const SparseMatrixType,
                               const vector_base<NumericT>,
                               op_prod >(A, x);
    }

  } // end namespace linalg
} // end namespace viennacl
#endif