diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d40599b736..250c3cda4f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -350,6 +350,7 @@ jobs: path: docs/_build/.jupyter_cache branch-preview: + if: github.repository_owner == 'scikit-hep' runs-on: ubuntu-22.04 needs: [build-docs] name: Deploy Branch Preview diff --git a/.github/workflows/header-only-test.yml b/.github/workflows/header-only-test.yml index d91c48fe0b..5c5e855b4d 100644 --- a/.github/workflows/header-only-test.yml +++ b/.github/workflows/header-only-test.yml @@ -24,7 +24,7 @@ jobs: - name: Run CMake run: | - cmake -B build -S header-only -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=bin -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON + cmake -B build -S header-only -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=bin -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON cmake --build build/ - name: Run tests diff --git a/header-only/layout-builder/awkward/LayoutBuilder.h b/header-only/layout-builder/awkward/LayoutBuilder.h index cf80bcbe5c..d11c6a3d79 100644 --- a/header-only/layout-builder/awkward/LayoutBuilder.h +++ b/header-only/layout-builder/awkward/LayoutBuilder.h @@ -1088,10 +1088,9 @@ namespace awkward { /// @class Indexed /// /// @brief Builds an IndexedArray which consists of an `index` buffer. - /// The negative values in the index are interpreted as missing. /// /// The index values can be 64-bit signed integers `int64`, 32-bit signed - /// integers `int32`. + /// integers `int32` or 32-bit unsigned integers `uint32`. /// /// @tparam PRIMITIVE The type of `index` buffer. /// @tparam BUILDER The type of builder content. @@ -1102,8 +1101,7 @@ namespace awkward { /// buffer, using `AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS` for initializing the buffer. Indexed() : index_( - awkward::GrowableBuffer(AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS)), - last_valid_(-1) { + awkward::GrowableBuffer(AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS)) { size_t id = 0; set_id(id); } @@ -1114,8 +1112,7 @@ namespace awkward { /// /// @param options Initial size configuration of a buffer. Indexed(const awkward::BuilderOptions& options) - : index_(awkward::GrowableBuffer(options)), - last_valid_(-1) { + : index_(awkward::GrowableBuffer(options)) { size_t id = 0; set_id(id); } @@ -1129,43 +1126,25 @@ namespace awkward { /// @brief Inserts the last valid index in the `index` buffer and /// returns the reference to the builder content. BUILDER& - append_valid() noexcept { - last_valid_ = content_.length(); - index_.append(last_valid_); + append_index() noexcept { + index_.append(content_.length()); return content_; } - /// @brief Inserts `size` number of valid index in the `index` buffer + /// @brief Inserts `size` number indices in the `index` buffer /// and returns the reference to the builder content. /// /// Just an interface; not actually faster than calling append many times. BUILDER& - extend_valid(size_t size) noexcept { + extend_index(size_t size) noexcept { size_t start = content_.length(); size_t stop = start + size; - last_valid_ = stop - 1; for (size_t i = start; i < stop; i++) { index_.append(i); } return content_; } - /// @brief Inserts `-1` in the `index` buffer. - void - append_invalid() noexcept { - index_.append(-1); - } - - /// @brief Inserts `-1` in the `index` buffer `size` number of times - /// - /// Just an interface; not actually faster than calling append many times. - void - extend_invalid(size_t size) noexcept { - for (size_t i = 0; i < size; i++) { - index_.append(-1); - } - } - /// @brief Parameters for the builder form. const std::string& parameters() const noexcept { @@ -1187,10 +1166,9 @@ namespace awkward { } /// @brief Discards the accumulated index and clears the content - /// of the builder. Also, last valid returns to `-1`. + /// of the builder. void clear() noexcept { - last_valid_ = -1; index_.clear(); content_.clear(); } @@ -1201,13 +1179,22 @@ namespace awkward { return index_.length(); } + /// @brief Retrieves the names and sizes (in bytes) of the buffers used + /// in the builder and its contents. + void + buffer_nbytes(std::map& names_nbytes) const + noexcept { + names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes(); + content_.buffer_nbytes(names_nbytes); + } + /// @brief Checks for validity and consistency. bool is_valid(std::string& error) const noexcept { - if (content_.length() != last_valid_ + 1) { + if (content_.length() != index_.length()) { std::stringstream out; out << "Indexed node" << id_ << " has content length " - << content_.length() << " but last valid index is " << last_valid_ + << content_.length() << " but index has length " << index_.length() << "\n"; error.append(out.str()); @@ -1217,15 +1204,6 @@ namespace awkward { } } - /// @brief Retrieves the names and sizes (in bytes) of the buffers used - /// in the builder and its contents. - void - buffer_nbytes(std::map& names_nbytes) const - noexcept { - names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes(); - content_.buffer_nbytes(names_nbytes); - } - /// @brief Copies and concatenates all the accumulated data in each of the /// buffers of the builder and its contents to user-defined pointers. /// @@ -1272,7 +1250,7 @@ namespace awkward { } else { params = std::string(", \"parameters\": { " + parameters_ + " }"); } - return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" + + return "{ \"class\": \"IndexedArray\", \"index\": \"" + type_to_numpy_like() + "\", \"content\": " + content_.form() + params + ", \"form_key\": \"" + form_key.str() + "\" }"; @@ -1292,9 +1270,6 @@ namespace awkward { /// @brief Unique form ID. size_t id_; - - /// @brief Last valid index. - size_t last_valid_; }; /// @class IndexedOption diff --git a/header-only/tests/test_1494-layout-builder.cpp b/header-only/tests/test_1494-layout-builder.cpp index c9c6201fef..99ee34bf6a 100644 --- a/header-only/tests/test_1494-layout-builder.cpp +++ b/header-only/tests/test_1494-layout-builder.cpp @@ -58,6 +58,9 @@ using TupleBuilder = awkward::LayoutBuilder::Tuple; template using RegularBuilder = awkward::LayoutBuilder::Regular; +template +using IndexedBuilder = awkward::LayoutBuilder::Indexed; + template using IndexedOptionBuilder = awkward::LayoutBuilder::IndexedOption; @@ -1210,19 +1213,19 @@ test_Regular_size0() { } void -test_Indexed_as_IndexedOption() { - IndexedOptionBuilder> builder; +test_Indexed() { + IndexedBuilder> builder; assert(builder.length() == 0); - auto& subbuilder = builder.append_valid(); + auto& subbuilder = builder.append_index(); subbuilder.append(1.1); - builder.append_valid(); + builder.append_index(); subbuilder.append(2.2); double data[3] = {3.3, 4.4, 5.5}; - builder.extend_valid(3); + builder.extend_index(3); subbuilder.extend(data, 3); // [1.1, 2.2, 3.3, 4.4, 5.5] @@ -1248,7 +1251,7 @@ test_Indexed_as_IndexedOption() { assert(builder.form() == "{ " - "\"class\": \"IndexedOptionArray\", " + "\"class\": \"IndexedArray\", " "\"index\": \"u32\", " "\"content\": { " "\"class\": \"NumpyArray\", " @@ -1874,7 +1877,7 @@ int main(int /* argc */, char ** /* argv */) { test_Tuple_Numpy_ListOffset(); test_Regular(); test_Regular_size0(); - test_Indexed_as_IndexedOption(); + test_Indexed(); test_IndexedOption(); test_IndexedOption_Record(); test_Unmasked();