fml
0.1-0
Fused Matrix Library
dot.hh
1
// This file is part of fml which is released under the Boost Software
2
// License, Version 1.0. See accompanying file LICENSE or copy at
3
// https://www.boost.org/LICENSE_1_0.txt
4
5
#ifndef FML_CPU_LINALG_DOT_H
6
#define FML_CPU_LINALG_DOT_H
7
#pragma once
8
9
10
#include "../cpuvec.hh"
11
12
13
namespace
fml
14
{
15
namespace
linalg
16
{
30
template
<
typename
REAL>
31
REAL
dot
(
const
cpuvec<REAL>
&x,
const
cpuvec<REAL>
&y)
32
{
33
const
len_t n = std::min(x.
size
(), y.
size
());
34
const
REAL *x_d = x.
data_ptr
();
35
const
REAL *y_d = y.
data_ptr
();
36
37
REAL d = 0;
38
#pragma omp simd reduction(+:d)
39
for
(len_t i=0; i<n; i++)
40
d += x_d[i] * y_d[i];
41
42
return
d;
43
}
44
45
46
48
template
<
typename
REAL>
49
REAL
dot
(
const
cpuvec<REAL>
&x)
50
{
51
return
dot
(x, x);
52
}
53
}
54
}
55
56
57
#endif
fml::univec::data_ptr
T * data_ptr()
Pointer to the internal array.
Definition:
univec.hh:28
fml::cpuvec
Vector class for data held on a single CPU.
Definition:
cpuvec.hh:31
fml
Core namespace.
Definition:
dimops.hh:10
fml::univec::size
len_t size() const
Number of elements in the vector.
Definition:
univec.hh:26
fml::linalg::dot
REAL dot(const cpuvec< REAL > &x, const cpuvec< REAL > &y)
Computes the dot product of two vectors, i.e. the sum of the product of the elements.
Definition:
dot.hh:31
fml
src
fml
cpu
linalg
dot.hh
Generated by
1.8.17