AntoinePrv commented on code in PR #47515:
URL: https://github.com/apache/arrow/pull/47515#discussion_r2333746786


##########
cpp/src/arrow/util/bpacking_test.cc:
##########
@@ -0,0 +1,180 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <stdexcept>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "arrow/testing/util.h"
+#include "arrow/util/bit_stream_utils_internal.h"
+#include "arrow/util/bpacking_internal.h"
+#include "arrow/util/logging.h"
+
+#if defined(ARROW_HAVE_AVX2)
+#  include "arrow/util/bpacking_avx2_internal.h"
+#endif
+#if defined(ARROW_HAVE_AVX512)
+#  include "arrow/util/bpacking_avx512_internal.h"
+#endif
+#if defined(ARROW_HAVE_NEON)
+#  include "arrow/util/bpacking_neon_internal.h"
+#endif
+
+namespace arrow::internal {
+
+template <typename Int>
+using UnpackFunc = int (*)(const uint8_t*, Int*, int, int);
+
+/// Get the number of bytes associate with a packing.
+constexpr int32_t getNumBytes(int32_t num_values, int32_t bit_width) {
+  auto const num_bits = num_values * bit_width;
+  if (num_bits % 8 != 0) {
+    throw std::invalid_argument("Must pack a multiple of 8 bits.");
+  }
+  return num_bits / 8;
+}
+
+/// Generate random bytes as packed integers.
+std::vector<uint8_t> generateRandomPackedValues(int32_t num_values, int32_t 
bit_width) {
+  constexpr uint32_t kSeed = 3214;
+  auto const num_bytes = getNumBytes(num_values, bit_width);
+
+  std::vector<uint8_t> out(num_bytes);
+  random_bytes(num_bytes, kSeed, out.data());
+
+  return out;
+}
+
+/// Convenience wrapper to unpack into a vector
+template <typename Int>
+std::vector<Int> unpackValues(const uint8_t* packed, int32_t num_values,
+                              int32_t bit_width, UnpackFunc<Int> unpack) {
+  std::vector<Int> out(num_values);
+  int values_read = unpack(packed, out.data(), num_values, bit_width);
+  ARROW_DCHECK_GE(values_read, 0);
+  out.resize(values_read);
+  return out;
+}
+
+/// Use BitWriter to pack values into a vector.

Review Comment:
   I have added tests for some known values for which we can easily extrapolate 
the unpacking almost independently of the bit_width:
   - All zeros
   - All ones
   - Alternating ones and zeros



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to