31#include <unordered_map>
51 template<
typename dtype,
typename HashFunction = std::hash<dtype>>
54 const auto modeFunction =
57 std::unordered_map<dtype, int, HashFunction> counts{};
58 auto greatestCount =
int{ 0 };
60 for (
auto iter = iterBegin; iter != iterEnd; ++iter)
62 const auto& value = *iter;
64 if (counts.count(value) > 0)
66 auto& count = counts[value];
68 if (count > greatestCount)
70 greatestCount = count;
76 counts.insert({ value, 1 });
95 returnArray(0, row) = modeFunction(inArray.
cbegin(row), inArray.
cend(row));
123 template<
typename dtype>
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
self_type transpose() const
Definition NdArrayCore.hpp:4959
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition NdArrayCore.hpp:157
size_type numRows() const noexcept
Definition NdArrayCore.hpp:3553
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
Definition Cartesian.hpp:39
NdArray< dtype > mode(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition mode.hpp:52
Axis
Enum To describe an axis.
Definition Enums.hpp:36
@ ROW
Definition Enums.hpp:38
@ COL
Definition Enums.hpp:39
@ NONE
Definition Enums.hpp:37
std::uint32_t uint32
Definition Types.hpp:40
Definition StdComplexOperators.hpp:124