Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate ArrayBuilder to new GrowableBuffer #1542

Merged
merged 27 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ target_compile_features(awkward-parent INTERFACE cxx_std_11)
# C++ dependencies (header-only): RapidJSON and dlpack
target_include_directories(awkward-parent INTERFACE rapidjson/include dlpack/include)

# C++ dependencies (header-only): GrowableBuffer
target_include_directories(awkward-parent INTERFACE src/awkward/_v2/cpp-headers/)

# First tier: cpu-kernels (object files, static library, and dynamic library).
add_library(awkward-cpu-kernels-objects OBJECT ${CPU_KERNEL_SOURCES})
set_target_properties(awkward-cpu-kernels-objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
Expand Down Expand Up @@ -91,7 +94,12 @@ target_link_libraries(awkward PUBLIC awkward-parent)
include(CTest)

if(BUILD_TESTING)
add_subdirectory(tests-cpp)
add_subdirectory(tests)

addtest_nolibs(test_1542-growable-buffer tests-cpp/test_1542-growable-buffer.cpp)
addtest(test_1542-array-builder tests-cpp/test_1542-array-builder.cpp)

endif()

option(PYBUILD "Build Python modules")
Expand Down
7 changes: 2 additions & 5 deletions include/awkward/builder/ArrayBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include "awkward/builder/Builder.h"

namespace awkward {
class Content;
using ContentPtr = std::shared_ptr<Content>;
class ArrayBuilderOptions;
class Builder;
using BuilderPtr = std::shared_ptr<Builder>;

Expand All @@ -26,9 +23,9 @@ namespace awkward {
public:
/// @brief Creates an ArrayBuilder from a full set of parameters.
///
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
ArrayBuilder(const ArrayBuilderOptions& options);
ArrayBuilder(const int64_t initial);

/// @brief Copy the current snapshot into the BuffersContainer and
/// return a Form as a std::string (JSON).
Expand Down
43 changes: 0 additions & 43 deletions include/awkward/builder/ArrayBuilderOptions.h

This file was deleted.

17 changes: 8 additions & 9 deletions include/awkward/builder/BoolBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@
#include <string>

#include "awkward/common.h"
#include "awkward/builder/GrowableBuffer.h"
#include "awkward/GrowableBuffer.h"
#include "awkward/builder/Builder.h"

namespace awkward {
class ArrayBuilderOptions;

/// @class BoolBuilder
///
/// @brief Builder node that accumulates boolean values.
class LIBAWKWARD_EXPORT_SYMBOL BoolBuilder: public Builder {
public:
/// @brief Create an empty BoolBuilder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
static const BuilderPtr
fromempty(const ArrayBuilderOptions& options);
fromempty(const int64_t initial);

/// @brief Create a BoolBuilder from a full set of parameters.
///
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param buffer Contains the accumulated boolean values.
BoolBuilder(const ArrayBuilderOptions& options,
BoolBuilder(const int64_t initial,
GrowableBuffer<uint8_t> buffer);

/// @brief User-friendly name of this class: `"BoolBuilder"`.
Expand Down Expand Up @@ -99,13 +98,13 @@ namespace awkward {
const BuilderPtr
endrecord() override;

const ArrayBuilderOptions&
options() const { return options_; }
const int64_t
initial() const { return initial_; }

const GrowableBuffer<uint8_t>& buffer() const { return buffer_; }

private:
const ArrayBuilderOptions options_;
const int64_t initial_;
GrowableBuffer<uint8_t> buffer_;
};

Expand Down
5 changes: 3 additions & 2 deletions include/awkward/builder/Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "awkward/common.h"

namespace awkward {
class Content;
using ContentPtr = std::shared_ptr<Content>;
class Builder;
using BuilderPtr = std::shared_ptr<Builder>;

Expand All @@ -31,6 +29,9 @@ namespace awkward {
/// @brief Create an array initialized to a given fill value.
virtual void
full_buffer(const std::string& name, int64_t length, int64_t value, const std::string& dtype) = 0;

virtual void*
empty_buffer(const std::string& name, int64_t num_bytes) = 0;
};

/// @class Builder
Expand Down
29 changes: 14 additions & 15 deletions include/awkward/builder/Complex128Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#define AWKWARD_COMPLEX128BUILDER_H_

#include "awkward/common.h"
#include "awkward/builder/ArrayBuilderOptions.h"
#include "awkward/builder/GrowableBuffer.h"
#include "awkward/GrowableBuffer.h"
#include "awkward/builder/Builder.h"

#include <complex>
Expand All @@ -17,33 +16,33 @@ namespace awkward {
class LIBAWKWARD_EXPORT_SYMBOL Complex128Builder: public Builder {
public:
/// @brief Create an empty Complex128Builder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
static const BuilderPtr
fromempty(const ArrayBuilderOptions& options);
fromempty(const int64_t initial);

/// @brief Create a Complex128Builder from an existing Int64Builder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param old The Int64Builder's buffer.
static const BuilderPtr
fromint64(const ArrayBuilderOptions& options,
GrowableBuffer<int64_t> old);
fromint64(const int64_t initial,
const GrowableBuffer<int64_t>& old);

/// @brief Create a Complex128Builder from an existing Float64Builder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param old The Float64Builder's buffer.
static const BuilderPtr
fromfloat64(const ArrayBuilderOptions& options,
GrowableBuffer<double> old);
fromfloat64(const int64_t initial,
const GrowableBuffer<double>& old);

/// @brief Create a Complex128Builder from a full set of parameters.
///
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param buffer Contains the accumulated real numbers.
Complex128Builder(const ArrayBuilderOptions& options,
Complex128Builder(const int64_t initial,
GrowableBuffer<std::complex<double>> buffer);

/// @brief User-friendly name of this class: `"Complex128Builder"`.
Expand Down Expand Up @@ -113,13 +112,13 @@ namespace awkward {
const BuilderPtr
endrecord() override;

const ArrayBuilderOptions&
options() const { return options_; }
const int64_t
initial() const { return initial_; }

const GrowableBuffer<std::complex<double>>& buffer() const { return buffer_; }

private:
const ArrayBuilderOptions options_;
const int64_t initial_;
GrowableBuffer<std::complex<double>> buffer_;
};

Expand Down
17 changes: 8 additions & 9 deletions include/awkward/builder/DatetimeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
#define AWKWARD_DATETIMEBUILDER_H_

#include "awkward/common.h"
#include "awkward/builder/GrowableBuffer.h"
#include "awkward/GrowableBuffer.h"
#include "awkward/builder/Builder.h"

namespace awkward {
class ArrayBuilderOptions;

/// @class DatetimeBuilder
///
/// @brief Builder node that accumulates integers (`int64_t`).
class LIBAWKWARD_EXPORT_SYMBOL DatetimeBuilder: public Builder {
public:
/// @brief Create an empty DatetimeBuilder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
static const BuilderPtr
fromempty(const ArrayBuilderOptions& options, const std::string& units);
fromempty(const int64_t initial, const std::string& units);

/// @brief Create an DatetimeBuilder from a full set of parameters.
///
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param buffer Contains the accumulated integers.
DatetimeBuilder(const ArrayBuilderOptions& options,
DatetimeBuilder(const int64_t initial,
GrowableBuffer<int64_t> content,
const std::string& units);

Expand Down Expand Up @@ -97,8 +96,8 @@ namespace awkward {
const BuilderPtr
endrecord() override;

const ArrayBuilderOptions&
options() const { return options_; }
const int64_t
initial() const { return initial_; }

const std::string&
units() const;
Expand All @@ -108,7 +107,7 @@ namespace awkward {
const std::string& unit() const { return units_; }

private:
const ArrayBuilderOptions options_;
const int64_t initial_;
GrowableBuffer<int64_t> content_;
const std::string units_;
};
Expand Down
23 changes: 11 additions & 12 deletions include/awkward/builder/Float64Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,36 @@
#include <string>

#include "awkward/common.h"
#include "awkward/builder/GrowableBuffer.h"
#include "awkward/GrowableBuffer.h"
#include "awkward/builder/Builder.h"

namespace awkward {
class ArrayBuilderOptions;

/// @class Float64Builder
///
/// @brief Builder node that accumulates real numbers (`double`).
class LIBAWKWARD_EXPORT_SYMBOL Float64Builder: public Builder {
public:
/// @brief Create an empty Float64Builder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
static const BuilderPtr
fromempty(const ArrayBuilderOptions& options);
fromempty(const int64_t initial);

/// @brief Create a Float64Builder from an existing Int64Builder.
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param old The Int64Builder's buffer.
static const BuilderPtr
fromint64(const ArrayBuilderOptions& options,
GrowableBuffer<int64_t> old);
fromint64(const int64_t initial,
const GrowableBuffer<int64_t>& old);

/// @brief Create a Float64Builder from a full set of parameters.
///
/// @param options Configuration options for building an array;
/// @param initial Configuration initial for building an array;
/// these are passed to every Builder's constructor.
/// @param buffer Contains the accumulated real numbers.
Float64Builder(const ArrayBuilderOptions& options,
Float64Builder(const int64_t initial,
GrowableBuffer<double> buffer);

/// @brief Contains the accumulated real numbers (`double`).
Expand Down Expand Up @@ -110,11 +109,11 @@ namespace awkward {
const BuilderPtr
endrecord() override;

const ArrayBuilderOptions&
options() const { return options_; }
const int64_t
initial() const { return initial_; }

private:
const ArrayBuilderOptions options_;
const int64_t initial_;
GrowableBuffer<double> buffer_;
};

Expand Down
Loading