| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de> | ||
| 2 | // SPDX-License-Identifier: MIT | ||
| 3 | /*! | ||
| 4 | * \file | ||
| 5 | * \ingroup Common | ||
| 6 | * \brief Common mathematical operations | ||
| 7 | */ | ||
| 8 | #ifndef GRIDFORMAT_COMMON_MATH_HPP_ | ||
| 9 | #define GRIDFORMAT_COMMON_MATH_HPP_ | ||
| 10 | |||
| 11 | #include <ranges> | ||
| 12 | #include <type_traits> | ||
| 13 | |||
| 14 | #include <gridformat/common/type_traits.hpp> | ||
| 15 | #include <gridformat/common/concepts.hpp> | ||
| 16 | #include <gridformat/common/ranges.hpp> | ||
| 17 | |||
| 18 | namespace GridFormat { | ||
| 19 | |||
| 20 | template<Concepts::StaticallySizedMDRange<1> V1, | ||
| 21 | Concepts::StaticallySizedMDRange<1> V2> | ||
| 22 | requires( | ||
| 23 | Concepts::Scalar<std::ranges::range_value_t<V1>> and | ||
| 24 | Concepts::Scalar<std::ranges::range_value_t<V2>> and | ||
| 25 | static_size<V1> == static_size<V2> | ||
| 26 | ) | ||
| 27 | 45968 | auto dot_product(V1&& v1, V2&& v2) { | |
| 28 | std::common_type_t< | ||
| 29 | std::ranges::range_value_t<V1>, | ||
| 30 | std::ranges::range_value_t<V2> | ||
| 31 | 45968 | > result{0}; | |
| 32 | 45968 | auto it1 = std::ranges::begin(v1); | |
| 33 |
1/2✓ Branch 1 taken 868 times.
✗ Branch 2 not taken.
|
174182 | std::ranges::for_each(v2, [&] (const Concepts::Scalar auto value) { |
| 34 | 129950 | result += value*(*it1); | |
| 35 | 129950 | ++it1; | |
| 36 | }); | ||
| 37 | 45968 | return result; | |
| 38 | } | ||
| 39 | |||
| 40 | } // namespace GridFormat | ||
| 41 | |||
| 42 | #endif // GRIDFORMAT_COMMON_MATH_HPP_ | ||
| 43 |