32#include <unordered_map>
54 template<
typename dtype,
typename HashFunction = std::hash<dtype>>
57 const auto modeFunction =
60 std::unordered_map<dtype, int, HashFunction> counts{};
61 auto greatestCount =
int{ 0 };
63 for (
auto iter = iterBegin; iter != iterEnd; ++iter)
65 const auto& value = *iter;
67 if (counts.count(value) > 0)
69 auto&
count = counts[value];
71 if (
count > greatestCount)
73 greatestCount =
count;
79 counts.insert({ value, 1 });
98 returnArray(0, row) = modeFunction(inArray.
cbegin(row), inArray.
cend(row));
126 template<
typename dtype>
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:41
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1365
self_type transpose() const
Definition: NdArrayCore.hpp:4963
size_type numRows() const noexcept
Definition: NdArrayCore.hpp:3557
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1673
std::iterator_traits< InputIt >::difference_type count(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:120
Definition: Cartesian.hpp:40
NdArray< dtype > mode(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: mode.hpp:55
Axis
Enum To describe an axis.
Definition: Enums.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40
Definition: StdComplexOperators.hpp:125