31#ifndef NUMCPP_NO_USE_BOOST
41#include "boost/dynamic_bitset.hpp"
56 template<
typename IntType, std::enable_if_t<std::is_
integral_v<IntType>,
int> = 0>
60 return n != 0 && (
n & (
n - 1)) == 0;
75 template<
typename IntType, std::enable_if_t<std::is_
integral_v<IntType>,
int> = 0>
80 throw std::invalid_argument(
"Input value must be greater than or equal to zero.");
85 return static_cast<std::size_t
>(
n) << 1;
88 return static_cast<std::size_t
>(std::pow(2, std::ceil(std::log2(
n))));
99 template<
typename IntType, std::enable_if_t<std::is_
integral_v<IntType>,
int> = 0>
102 auto i = std::size_t{ 0 };
103 auto power = std::size_t{ 1 };
104 auto powers = std::vector<std::size_t>();
107 while (i <
static_cast<std::size_t
>(
n))
126 template<
typename IntType, std::enable_if_t<std::is_
integral_v<IntType>,
int> = 0>
130 const auto lowerBin =
static_cast<std::size_t
>(std::floor(std::log2(
n)));
137 throw std::runtime_error(
"input number of data bits is not a valid Hamming SECDED code configuration.");
157 std::enable_if_t<std::is_integral_v<IntType1>,
int> = 0,
158 std::enable_if_t<std::is_integral_v<IntType2>,
int> = 0>
163 throw std::invalid_argument(
"All hamming parity bits are indexed by powers of two.");
170 auto indices = std::vector<std::size_t>();
195 template<std::
size_t DataBits>
199 for (std::size_t i = 0; i <
DataBits - 1; ++i)
217 for (std::size_t i = 0; i < data.size() - 1; ++i)
236 template<std::
size_t DataBits,
typename IntType, std::enable_if_t<std::is_
integral_v<IntType>,
int> = 0>
243 [&data](
bool parity,
const auto value)
noexcept ->
bool { return parity ^= value; });
256 std::enable_if_t<greaterThan_v<EncodedBits, DataBits>,
int> = 0>
262 throw std::runtime_error(
"DataBits and EncodedBits are not consistent");
278 std::enable_if_t<greaterThan_v<EncodedBits, DataBits>,
int> = 0>
281 auto dataBits = std::bitset<DataBits>();
308 template<std::
size_t DataBits>
354 std::enable_if_t<greaterThan_v<EncodedBits, DataBits>,
int> = 0>
357 const auto numParityBits = detail::checkBitsConsistent<DataBits, EncodedBits>();
std::vector< std::size_t > powersOfTwo(IntType n)
Definition hammingEncode.hpp:100
std::size_t nextPowerOfTwo(IntType n)
Definition hammingEncode.hpp:76
std::bitset< DataBits > extractData(const std::bitset< EncodedBits > &encodedBits) noexcept
Definition hammingEncode.hpp:279
std::size_t numSecdedParityBitsNeeded(IntType numDataBits)
Definition hammingEncode.hpp:127
constexpr bool isPowerOfTwo(IntType n) noexcept
Tests if value is a power of two.
Definition hammingEncode.hpp:57
std::vector< std::size_t > dataBitsCovered(IntType1 numDataBits, IntType2 parityBit)
Definition hammingEncode.hpp:159
constexpr bool calculateParity(const std::bitset< DataBits > &data) noexcept
Definition hammingEncode.hpp:196
std::size_t checkBitsConsistent()
Definition hammingEncode.hpp:257
Definition hammingEncode.hpp:46
int decode(std::bitset< EncodedBits > encodedBits, std::bitset< DataBits > &decodedBits)
Definition hammingEncode.hpp:355
boost::dynamic_bitset encode(const std::bitset< DataBits > &dataBits)
Definition hammingEncode.hpp:309
constexpr dtype power(dtype inValue, uint8 inExponent) noexcept
Definition Functions/power.hpp:52
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59