30 #include <type_traits>
47 template<
typename dtype, std::enable_if_t<std::is_
integral_v<dtype> || std::is_same_v<dtype,
bool>,
int> = 0>
54 const auto numFullValues = a.
size() / 8;
55 const auto leftOvers = a.
size() % 8;
56 const auto resultSize = leftOvers == 0 ? numFullValues : numFullValues + 1;
63 const auto startIdx = i * 8;
64 for (
auto bit = 0; bit < 8; ++bit)
66 auto value =
static_cast<uint8>(a[startIdx + bit]);
67 value = value == 0 ? 0 : 1;
68 result[i] |= (value << bit);
74 const auto startIdx = numFullValues * 8;
75 for (std::remove_const_t<decltype(leftOvers)> bit = 0; bit < leftOvers; ++bit)
77 auto value =
static_cast<uint8>(a[startIdx + bit]);
78 value = value == 0 ? 0 : 1;
79 result.
back() |= (value << bit);
87 const auto aShape = a.
shape();
88 const auto numFullValues = aShape.
cols / 8;
89 const auto leftOvers = aShape.cols % 8;
90 const auto resultSize = leftOvers == 0 ? numFullValues : numFullValues + 1;
93 const auto resultCSlice = result.
cSlice();
94 const auto aCSlice = a.
cSlice();
125 template<
typename dtype, std::enable_if_t<std::is_
integral_v<dtype> || std::is_same_v<dtype,
bool>,
int> = 0>
132 const auto numFullValues = a.
size() / 8;
133 const auto leftOvers = a.
size() % 8;
134 const auto resultSize = leftOvers == 0 ? numFullValues : numFullValues + 1;
141 const auto startIdx = i * 8;
142 for (
auto bit = 0; bit < 8; ++bit)
144 auto value =
static_cast<uint8>(a[startIdx + bit]);
145 value = value == 0 ? 0 : 1;
146 result[i] |= (value << (7 - bit));
152 const auto startIdx = numFullValues * 8;
153 for (std::remove_const_t<decltype(leftOvers)> bit = 0; bit < leftOvers; ++bit)
155 auto value =
static_cast<uint8>(a[startIdx + bit]);
156 value = value == 0 ? 0 : 1;
157 result.
back() |= (value << (7 - bit));
165 const auto aShape = a.
shape();
166 const auto numFullValues = aShape.
cols / 8;
167 const auto leftOvers = aShape.cols % 8;
168 const auto resultSize = leftOvers == 0 ? numFullValues : numFullValues + 1;
171 const auto resultCSlice = result.
cSlice();
172 const auto aCSlice = a.
cSlice();
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3479
size_type size() const noexcept
Definition: NdArrayCore.hpp:4105
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:969
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4092
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2609
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2138
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4457
uint32 size_type
Definition: NdArrayCore.hpp:88
uint32 cols
Definition: Core/Shape.hpp:45
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:47
std::uint8_t uint8
Definition: Types.hpp:42
NdArray< uint8 > packbitsBigEndian(const NdArray< dtype > &a, Axis axis=Axis::NONE)
Definition: packbits.hpp:126
NdArray< uint8 > packbitsLittleEndian(const NdArray< dtype > &a, Axis axis=Axis::NONE)
Definition: packbits.hpp:48