tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_dot.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2025 Tobias Hienzsch
3#ifndef TETL_LINALG_BLAS1_DOT_HPP
4#define TETL_LINALG_BLAS1_DOT_HPP
5
6#include <etl/_contracts/check.hpp>
7#include <etl/_linalg/exposition.hpp>
8#include <etl/_type_traits/declval.hpp>
9#include <etl/_utility/cmp_equal.hpp>
10
11namespace etl::linalg {
12
13/// \ingroup linalg
14template <in_vector InVec1, in_vector InVec2, typename Scalar>
15[[nodiscard]] constexpr auto dot(InVec1 v1, InVec2 v2, Scalar init) -> Scalar
16{
17 static_assert(detail::compatible_static_extents<InVec1, InVec2>(0, 0));
18 TETL_PRECONDITION(etl::cmp_equal(v1.extent(0), v2.extent(0)));
19
20 using index_type = detail::common_index_type_t<InVec1, InVec2>;
21 for (index_type i{0}; i < static_cast<index_type>(v1.extent(0)); ++i) {
22 init += static_cast<Scalar>(v1(i)) * static_cast<Scalar>(v2(i));
23 }
24 return init;
25}
26
27/// \ingroup linalg
28template <in_vector InVec1, in_vector InVec2>
29[[nodiscard]] constexpr auto dot(InVec1 v1, InVec2 v2)
30{
31 using scalar_type = decltype(declval<typename InVec1::value_type>() * declval<typename InVec2::value_type>());
32 return etl::linalg::dot(v1, v2, scalar_type{});
33}
34
35} // namespace etl::linalg
36
37#endif // TETL_LINALG_BLAS1_DOT_HPP
constexpr auto dot(InVec1 v1, InVec2 v2)
Definition blas1_dot.hpp:29
constexpr auto dot(InVec1 v1, InVec2 v2, Scalar init) -> Scalar
Definition blas1_dot.hpp:15
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9