|
1 |
| -// Copyright 2021-2024 Tier IV, Inc. |
| 1 | +// Copyright 2025 The Autoware Contributors |
2 | 2 | //
|
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | // you may not use this file except in compliance with the License.
|
|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 |
| -#include <iostream> |
16 |
| -#include <limits> |
17 |
| - |
18 | 15 | #ifndef AUTOWARE_UTILS__MATH__ACCUMULATOR_HPP_
|
19 | 16 | #define AUTOWARE_UTILS__MATH__ACCUMULATOR_HPP_
|
20 | 17 |
|
21 |
| -namespace autoware_utils |
22 |
| -{ |
23 |
| -/** |
24 |
| - * @brief class to accumulate statistical data, supporting min, max and mean. |
25 |
| - * @typedef T type of the values (default to double) |
26 |
| - */ |
27 |
| -template <typename T = double> |
28 |
| -class Accumulator |
29 |
| -{ |
30 |
| -public: |
31 |
| - /** |
32 |
| - * @brief add a value |
33 |
| - * @param value value to add |
34 |
| - */ |
35 |
| - void add(const T & value) |
36 |
| - { |
37 |
| - if (value < min_) { |
38 |
| - min_ = value; |
39 |
| - } |
40 |
| - if (value > max_) { |
41 |
| - max_ = value; |
42 |
| - } |
43 |
| - ++count_; |
44 |
| - mean_ = mean_ + (value - mean_) / count_; |
45 |
| - } |
46 |
| - |
47 |
| - /** |
48 |
| - * @brief get the mean value |
49 |
| - */ |
50 |
| - long double mean() const { return mean_; } |
51 |
| - |
52 |
| - /** |
53 |
| - * @brief get the minimum value |
54 |
| - */ |
55 |
| - T min() const { return min_; } |
56 |
| - |
57 |
| - /** |
58 |
| - * @brief get the maximum value |
59 |
| - */ |
60 |
| - T max() const { return max_; } |
61 |
| - |
62 |
| - /** |
63 |
| - * @brief get the number of values used to build this statistic |
64 |
| - */ |
65 |
| - unsigned int count() const { return count_; } |
66 |
| - |
67 |
| - template <typename U> |
68 |
| - friend std::ostream & operator<<(std::ostream & os, const Accumulator<U> & accumulator); |
69 |
| - |
70 |
| -private: |
71 |
| - T min_ = std::numeric_limits<T>::max(); |
72 |
| - T max_ = std::numeric_limits<T>::lowest(); |
73 |
| - long double mean_ = 0.0; |
74 |
| - unsigned int count_ = 0; |
75 |
| -}; |
| 18 | +// NOLINTBEGIN(build/namespaces, whitespace/line_length) |
| 19 | +// clang-format off |
76 | 20 |
|
77 |
| -/** |
78 |
| - * @brief overload << operator for easy print to output stream |
79 |
| - */ |
80 |
| -template <typename T> |
81 |
| -std::ostream & operator<<(std::ostream & os, const Accumulator<T> & accumulator) |
82 |
| -{ |
83 |
| - if (accumulator.count() == 0) { |
84 |
| - os << "None None None"; |
85 |
| - } else { |
86 |
| - os << accumulator.min() << " " << accumulator.max() << " " << accumulator.mean(); |
87 |
| - } |
88 |
| - return os; |
89 |
| -} |
| 21 | +#pragma message("#include <autoware_utils/math/accumulator.hpp> is deprecated. Use #include <autoware_utils_math/accumulator.hpp> instead.") |
| 22 | +#include <autoware_utils_math/accumulator.hpp> |
| 23 | +namespace autoware_utils { using namespace autoware_utils_math; } |
90 | 24 |
|
91 |
| -} // namespace autoware_utils |
| 25 | +// clang-format on |
| 26 | +// NOLINTEND |
92 | 27 |
|
93 | 28 | #endif // AUTOWARE_UTILS__MATH__ACCUMULATOR_HPP_
|
0 commit comments