summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com>2020-09-24 17:32:46 +0200
committerGitHub <noreply@github.com>2020-09-24 17:32:46 +0200
commita16fc001d1de97543fed51ed519d86611c4bc66a (patch)
tree79157d193bd04bdc8243ef513e13bf8d5257dfd1 /eval
parentac4836ba4712994d5caf839276522a4f1fa01a07 (diff)
parentf6e339cce76c190b9007b608f1f139e60a88ff59 (diff)
Merge pull request #14535 from vespa-engine/arnej/packed-mixed-cleanup
Arnej/packed mixed cleanup
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/tensor/packed_mappings/packed_mappings_test.cpp12
-rw-r--r--eval/src/tests/tensor/packed_mappings/packed_mixed_test.cpp6
-rw-r--r--eval/src/vespa/eval/tensor/mixed/CMakeLists.txt4
-rw-r--r--eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor.h4
-rw-r--r--eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder.cpp (renamed from eval/src/vespa/eval/tensor/mixed/packed_mixed_builder.cpp)10
-rw-r--r--eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder.h (renamed from eval/src/vespa/eval/tensor/mixed/packed_mixed_builder.h)6
-rw-r--r--eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.cpp (renamed from eval/src/vespa/eval/tensor/mixed/packed_mixed_factory.cpp)15
-rw-r--r--eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.h (renamed from eval/src/vespa/eval/tensor/mixed/packed_mixed_factory.h)11
8 files changed, 38 insertions, 30 deletions
diff --git a/eval/src/tests/tensor/packed_mappings/packed_mappings_test.cpp b/eval/src/tests/tensor/packed_mappings/packed_mappings_test.cpp
index 70f98904809..c8814372bf5 100644
--- a/eval/src/tests/tensor/packed_mappings/packed_mappings_test.cpp
+++ b/eval/src/tests/tensor/packed_mappings/packed_mappings_test.cpp
@@ -4,8 +4,8 @@
#include <vespa/eval/tensor/mixed/packed_mappings.h>
#include <vespa/eval/tensor/mixed/packed_mappings_builder.h>
#include <vespa/eval/tensor/mixed/packed_mixed_tensor.h>
-#include <vespa/eval/tensor/mixed/packed_mixed_builder.h>
-#include <vespa/eval/tensor/mixed/packed_mixed_factory.h>
+#include <vespa/eval/tensor/mixed/packed_mixed_tensor_builder.h>
+#include <vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <stdlib.h>
#include <assert.h>
@@ -137,7 +137,7 @@ TEST_F(MappingsBuilderTest, some_random)
class MixedBuilderTest : public ::testing::Test {
public:
- std::unique_ptr<PackedMixedBuilder<float>> builder;
+ std::unique_ptr<PackedMixedTensorBuilder<float>> builder;
std::unique_ptr<Value> built;
MixedBuilderTest() = default;
@@ -170,7 +170,7 @@ TEST_F(MixedBuilderTest, empty_mapping)
size_t dsss = type.dense_subspace_size();
EXPECT_GT(dims, 0);
EXPECT_GT(dsss, 0);
- builder = std::make_unique<PackedMixedBuilder<float>>(type, dims, dsss, 3);
+ builder = std::make_unique<PackedMixedTensorBuilder<float>>(type, dims, dsss, 3);
build_and_compare(0);
}
}
@@ -183,7 +183,7 @@ TEST_F(MixedBuilderTest, just_one)
size_t dims = type.count_mapped_dimensions();
size_t dsss = type.dense_subspace_size();
EXPECT_GT(dsss, 0);
- builder = std::make_unique<PackedMixedBuilder<float>>(type, dims, dsss, 3);
+ builder = std::make_unique<PackedMixedTensorBuilder<float>>(type, dims, dsss, 3);
auto address = generate_random_address(dims);
auto ref = builder->add_subspace(address);
EXPECT_EQ(ref.size(), dsss);
@@ -203,7 +203,7 @@ TEST_F(MixedBuilderTest, some_random)
uint32_t dsss = type.dense_subspace_size();
EXPECT_GT(dims, 0);
EXPECT_GT(dsss, 0);
- builder = std::make_unique<PackedMixedBuilder<float>>(type, dims, dsss, 3);
+ builder = std::make_unique<PackedMixedTensorBuilder<float>>(type, dims, dsss, 3);
uint32_t cnt = random_range(dims*5, dims*20);
printf("MixBuild: generate %u addresses for %u dims\n", cnt, dims);
diff --git a/eval/src/tests/tensor/packed_mappings/packed_mixed_test.cpp b/eval/src/tests/tensor/packed_mappings/packed_mixed_test.cpp
index eb7607c13b8..bc1efdaba1d 100644
--- a/eval/src/tests/tensor/packed_mappings/packed_mixed_test.cpp
+++ b/eval/src/tests/tensor/packed_mappings/packed_mixed_test.cpp
@@ -3,7 +3,7 @@
#include <vespa/eval/eval/simple_value.h>
#include <vespa/eval/eval/value_codec.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
-#include <vespa/eval/tensor/mixed/packed_mixed_factory.h>
+#include <vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.h>
#include <vespa/vespalib/gtest/gtest.h>
using namespace vespalib::eval;
@@ -27,7 +27,7 @@ std::vector<Layout> layouts = {
TEST(PackedMixedTest, packed_mixed_tensors_can_be_converted_from_and_to_tensor_spec) {
for (const auto &layout: layouts) {
TensorSpec expect = spec(layout, N());
- std::unique_ptr<Value> value = value_from_spec(expect, PackedMixedFactory());
+ std::unique_ptr<Value> value = value_from_spec(expect, PackedMixedTensorBuilderFactory::get());
TensorSpec actual = spec_from_value(*value);
EXPECT_EQ(actual, expect);
}
@@ -35,7 +35,7 @@ TEST(PackedMixedTest, packed_mixed_tensors_can_be_converted_from_and_to_tensor_s
TEST(PackedMixedTest, packed_mixed_tensors_can_be_built_and_inspected) {
ValueType type = ValueType::from_spec("tensor<float>(x{},y[2],z{})");
- PackedMixedFactory factory;
+ const auto & factory = PackedMixedTensorBuilderFactory::get();
std::unique_ptr<ValueBuilder<float>> builder = factory.create_value_builder<float>(type);
float seq = 0.0;
for (vespalib::string x: {"a", "b", "c"}) {
diff --git a/eval/src/vespa/eval/tensor/mixed/CMakeLists.txt b/eval/src/vespa/eval/tensor/mixed/CMakeLists.txt
index 2621ec616c0..ceded3a7380 100644
--- a/eval/src/vespa/eval/tensor/mixed/CMakeLists.txt
+++ b/eval/src/vespa/eval/tensor/mixed/CMakeLists.txt
@@ -5,7 +5,7 @@ vespa_add_library(eval_tensor_mixed OBJECT
packed_labels.cpp
packed_mappings.cpp
packed_mappings_builder.cpp
- packed_mixed_factory.cpp
+ packed_mixed_tensor_builder_factory.cpp
packed_mixed_tensor.cpp
- packed_mixed_builder.cpp
+ packed_mixed_tensor_builder.cpp
)
diff --git a/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor.h b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor.h
index 60916b23565..604b1c94aeb 100644
--- a/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor.h
+++ b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor.h
@@ -15,7 +15,7 @@ namespace vespalib::eval::packed_mixed_tensor {
* An implementation of Value modeling a mixed tensor,
* where all the data (cells and sparse address mappings)
* can reside in a self-contained, contigous block of memory.
- * Currently must be built by a PackedMixedBuilder.
+ * Currently must be built by a PackedMixedTensorBuilder.
* Immutable (all data always const).
**/
class PackedMixedTensor : public Value, public Value::Index
@@ -33,7 +33,7 @@ private:
_mappings(mappings)
{}
- template<typename T> friend class PackedMixedBuilder;
+ template<typename T> friend class PackedMixedTensorBuilder;
public:
~PackedMixedTensor() override;
diff --git a/eval/src/vespa/eval/tensor/mixed/packed_mixed_builder.cpp b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder.cpp
index 1816e06bf25..d311d589a27 100644
--- a/eval/src/vespa/eval/tensor/mixed/packed_mixed_builder.cpp
+++ b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder.cpp
@@ -1,12 +1,12 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "packed_mixed_builder.h"
+#include "packed_mixed_tensor_builder.h"
namespace vespalib::eval::packed_mixed_tensor {
template <typename T>
ArrayRef<T>
-PackedMixedBuilder<T>::add_subspace(const std::vector<vespalib::stringref> &addr)
+PackedMixedTensorBuilder<T>::add_subspace(const std::vector<vespalib::stringref> &addr)
{
uint32_t idx = _mappings_builder.add_mapping_for(addr);
size_t offset = idx * _subspace_size;
@@ -20,7 +20,7 @@ PackedMixedBuilder<T>::add_subspace(const std::vector<vespalib::stringref> &addr
template <typename T>
std::unique_ptr<Value>
-PackedMixedBuilder<T>::build(std::unique_ptr<ValueBuilder<T>>)
+PackedMixedTensorBuilder<T>::build(std::unique_ptr<ValueBuilder<T>>)
{
size_t self_size = sizeof(PackedMixedTensor);
size_t mappings_size = _mappings_builder.extra_memory();
@@ -47,7 +47,7 @@ PackedMixedBuilder<T>::build(std::unique_ptr<ValueBuilder<T>>)
return std::unique_ptr<PackedMixedTensor>(built);
}
-template class PackedMixedBuilder<float>;
-template class PackedMixedBuilder<double>;
+template class PackedMixedTensorBuilder<float>;
+template class PackedMixedTensorBuilder<double>;
} // namespace
diff --git a/eval/src/vespa/eval/tensor/mixed/packed_mixed_builder.h b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder.h
index c851b839756..c99762b7e8b 100644
--- a/eval/src/vespa/eval/tensor/mixed/packed_mixed_builder.h
+++ b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder.h
@@ -11,7 +11,7 @@ namespace vespalib::eval::packed_mixed_tensor {
* appropriate for cell type T.
**/
template <typename T>
-class PackedMixedBuilder : public ValueBuilder<T>
+class PackedMixedTensorBuilder : public ValueBuilder<T>
{
private:
const ValueType & _type;
@@ -19,7 +19,7 @@ private:
std::vector<T> _cells;
PackedMappingsBuilder _mappings_builder;
public:
- PackedMixedBuilder(const ValueType &type,
+ PackedMixedTensorBuilder(const ValueType &type,
size_t num_mapped_in,
size_t subspace_size_in,
size_t expected_subspaces)
@@ -31,7 +31,7 @@ public:
_cells.reserve(_subspace_size * expected_subspaces);
}
- ~PackedMixedBuilder() override = default;
+ ~PackedMixedTensorBuilder() override = default;
ArrayRef<T> add_subspace(const std::vector<vespalib::stringref> &addr) override;
std::unique_ptr<Value> build(std::unique_ptr<ValueBuilder<T>> self) override;
diff --git a/eval/src/vespa/eval/tensor/mixed/packed_mixed_factory.cpp b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.cpp
index 75e6b1e996e..48eedd86f7f 100644
--- a/eval/src/vespa/eval/tensor/mixed/packed_mixed_factory.cpp
+++ b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.cpp
@@ -1,7 +1,7 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "packed_mixed_factory.h"
-#include "packed_mixed_builder.h"
+#include "packed_mixed_tensor_builder_factory.h"
+#include "packed_mixed_tensor_builder.h"
#include <vespa/vespalib/util/typify.h>
@@ -9,24 +9,27 @@ namespace vespalib::eval {
namespace {
-struct CreatePackedMixedBuilder {
+struct CreatePackedMixedTensorBuilder {
template <typename T, typename ...Args>
static std::unique_ptr<ValueBuilderBase> invoke(const ValueType &type, Args &&...args)
{
assert(check_cell_type<T>(type.cell_type()));
- return std::make_unique<packed_mixed_tensor::PackedMixedBuilder<T>>(type, std::forward<Args>(args)...);
+ return std::make_unique<packed_mixed_tensor::PackedMixedTensorBuilder<T>>(type, std::forward<Args>(args)...);
}
};
} // namespace <unnamed>
+PackedMixedTensorBuilderFactory::PackedMixedTensorBuilderFactory() = default;
+PackedMixedTensorBuilderFactory PackedMixedTensorBuilderFactory::_factory;
+
std::unique_ptr<ValueBuilderBase>
-PackedMixedFactory::create_value_builder_base(const ValueType &type,
+PackedMixedTensorBuilderFactory::create_value_builder_base(const ValueType &type,
size_t num_mapped_in,
size_t subspace_size_in,
size_t expected_subspaces) const
{
- return typify_invoke<1,TypifyCellType,CreatePackedMixedBuilder>(type.cell_type(),
+ return typify_invoke<1,TypifyCellType,CreatePackedMixedTensorBuilder>(type.cell_type(),
type, num_mapped_in, subspace_size_in, expected_subspaces);
}
diff --git a/eval/src/vespa/eval/tensor/mixed/packed_mixed_factory.h b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.h
index ae90e5e243b..20a581e2b35 100644
--- a/eval/src/vespa/eval/tensor/mixed/packed_mixed_factory.h
+++ b/eval/src/vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.h
@@ -7,14 +7,19 @@
namespace vespalib::eval {
/**
- * A factory that can generate PackedMixedBuilder
+ * A factory that can generate PackedMixedTensorBuilder
* objects appropriate for the requested CellType.
*/
-struct PackedMixedFactory : ValueBuilderFactory {
- ~PackedMixedFactory() override {}
+struct PackedMixedTensorBuilderFactory : ValueBuilderFactory {
+private:
+ PackedMixedTensorBuilderFactory();
+ static PackedMixedTensorBuilderFactory _factory;
+ ~PackedMixedTensorBuilderFactory() override {}
protected:
std::unique_ptr<ValueBuilderBase> create_value_builder_base(const ValueType &type,
size_t num_mapped_in, size_t subspace_size_in, size_t expect_subspaces) const override;
+public:
+ static const PackedMixedTensorBuilderFactory &get() { return _factory; }
};
} // namespace