|
5 | 5 | #define OPERON_METRICS_CORRELATION_COEFFICIENT_HPP |
6 | 6 |
|
7 | 7 | #include <iterator> |
8 | | -#include <type_traits> |
9 | 8 | #include <vstat/vstat.hpp> |
10 | | -#include "operon/core/types.hpp" |
| 9 | +#include "operon/core/concepts.hpp" |
11 | 10 |
|
12 | 11 | namespace Operon { |
13 | 12 |
|
14 | | -template<typename InputIt1, typename InputIt2> |
| 13 | +template<std::contiguous_iterator InputIt1, std::contiguous_iterator InputIt2> |
| 14 | + requires Concepts::Arithmetic<typename std::iterator_traits<InputIt1>::value_type> |
| 15 | + && std::same_as<typename std::iterator_traits<InputIt1>::value_type, |
| 16 | + typename std::iterator_traits<InputIt2>::value_type> |
15 | 17 | inline auto CorrelationCoefficient(InputIt1 begin1, InputIt1 end1, InputIt2 begin2) noexcept -> double |
16 | 18 | { |
17 | 19 | using V1 = typename std::iterator_traits<InputIt1>::value_type; |
18 | | - using V2 = typename std::iterator_traits<InputIt2>::value_type; |
19 | | - static_assert(std::is_arithmetic_v<V1>, "InputIt1: value_type must be arithmetic."); |
20 | | - static_assert(std::is_arithmetic_v<V2>, "InputIt2: value_type must be arithmetic."); |
21 | | - static_assert(std::is_same_v<V1, V2>, "The types must be the same"); |
22 | 20 | return vstat::bivariate::accumulate<V1>(begin1, end1, begin2).correlation; |
23 | 21 | } |
24 | 22 |
|
25 | | -template<typename InputIt1, typename InputIt2, typename InputIt3> |
| 23 | +template<std::contiguous_iterator InputIt1, std::contiguous_iterator InputIt2, std::contiguous_iterator InputIt3> |
| 24 | + requires Concepts::Arithmetic<typename std::iterator_traits<InputIt1>::value_type> |
| 25 | + && std::same_as<typename std::iterator_traits<InputIt1>::value_type, |
| 26 | + typename std::iterator_traits<InputIt2>::value_type> |
26 | 27 | inline auto CorrelationCoefficient(InputIt1 begin1, InputIt1 end1, InputIt2 begin2, InputIt3 begin3) noexcept -> double |
27 | 28 | { |
28 | 29 | using V1 = typename std::iterator_traits<InputIt1>::value_type; |
29 | | - using V2 = typename std::iterator_traits<InputIt2>::value_type; |
30 | | - static_assert(std::is_arithmetic_v<V1>, "InputIt1: value_type must be arithmetic."); |
31 | | - static_assert(std::is_arithmetic_v<V2>, "InputIt2: value_type must be arithmetic."); |
32 | | - static_assert(std::is_same_v<V1, V2>, "The types must be the same"); |
33 | 30 | return vstat::bivariate::accumulate<V1>(begin1, end1, begin2, begin3).correlation; |
34 | 31 | } |
35 | 32 |
|
36 | | -template<typename T> |
| 33 | +template<Concepts::Arithmetic T> |
37 | 34 | inline auto CorrelationCoefficient(Operon::Span<T const> x, Operon::Span<T const> y) -> double |
38 | 35 | { |
39 | | - static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type."); |
40 | 36 | EXPECT(x.size() == y.size()); |
41 | 37 | EXPECT(!x.empty()); |
42 | | - return vstat::bivariate::accumulate<T>(x.begin(), x.end(), y.begin()).correlation; |
| 38 | + return vstat::bivariate::accumulate<T>(x.data(), x.data() + x.size(), y.data()).correlation; |
43 | 39 | } |
44 | 40 |
|
45 | | -template<typename T> |
| 41 | +template<Concepts::Arithmetic T> |
46 | 42 | inline auto CorrelationCoefficient(Operon::Span<T const> x, Operon::Span<T const> y, Operon::Span<T const> w) -> double |
47 | 43 | { |
48 | | - static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type."); |
49 | 44 | EXPECT(x.size() == y.size()); |
50 | 45 | EXPECT(!x.empty()); |
51 | | - return vstat::bivariate::accumulate<T>(x.begin(), x.end(), y.begin(), w.begin()).correlation; |
| 46 | + return vstat::bivariate::accumulate<T>(x.data(), x.data() + x.size(), y.data(), w.data()).correlation; |
52 | 47 | } |
53 | 48 |
|
54 | | -template<typename InputIt1, typename InputIt2> |
| 49 | +template<std::contiguous_iterator InputIt1, std::contiguous_iterator InputIt2> |
| 50 | + requires Concepts::Arithmetic<typename std::iterator_traits<InputIt1>::value_type> |
| 51 | + && std::same_as<typename std::iterator_traits<InputIt1>::value_type, |
| 52 | + typename std::iterator_traits<InputIt2>::value_type> |
55 | 53 | inline auto SquaredCorrelation(InputIt1 begin1, InputIt1 end1, InputIt2 begin2) noexcept -> double { |
56 | 54 | auto r = CorrelationCoefficient(begin1, end1, begin2); |
57 | 55 | return r * r; |
58 | 56 | } |
59 | 57 |
|
60 | | -template<typename InputIt1, typename InputIt2, typename InputIt3> |
| 58 | +template<std::contiguous_iterator InputIt1, std::contiguous_iterator InputIt2, std::contiguous_iterator InputIt3> |
| 59 | + requires Concepts::Arithmetic<typename std::iterator_traits<InputIt1>::value_type> |
| 60 | + && std::same_as<typename std::iterator_traits<InputIt1>::value_type, |
| 61 | + typename std::iterator_traits<InputIt2>::value_type> |
61 | 62 | inline auto SquaredCorrelation(InputIt1 begin1, InputIt1 end1, InputIt2 begin2, InputIt3 begin3) noexcept -> double { |
62 | 63 | auto r = CorrelationCoefficient(begin1, end1, begin2, begin3); |
63 | 64 | return r * r; |
64 | 65 | } |
65 | 66 |
|
66 | | -template<typename T> |
| 67 | +template<Concepts::Arithmetic T> |
67 | 68 | inline auto SquaredCorrelation(Operon::Span<T const> x, Operon::Span<T const> y) -> double { |
68 | 69 | auto r = CorrelationCoefficient(x, y); |
69 | 70 | return r * r; |
70 | 71 | } |
71 | 72 |
|
72 | | -template<typename T> |
| 73 | +template<Concepts::Arithmetic T> |
73 | 74 | inline auto SquaredCorrelation(Operon::Span<T const> x, Operon::Span<T const> y, Operon::Span<T const> w) -> double { |
74 | 75 | auto r = CorrelationCoefficient(x, y, w); |
75 | 76 | return r * r; |
|
0 commit comments