aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vespalib/CMakeLists.txt3
-rw-r--r--vespalib/src/tests/tensor/simple_tensor_builder/.gitignore1
-rw-r--r--vespalib/src/tests/tensor/simple_tensor_builder/CMakeLists.txt9
-rw-r--r--vespalib/src/tests/tensor/simple_tensor_builder/FILES1
-rw-r--r--vespalib/src/tests/tensor/simple_tensor_builder/simple_tensor_builder_test.cpp52
-rw-r--r--vespalib/src/tests/tensor/tensor/.gitignore1
-rw-r--r--vespalib/src/tests/tensor/tensor/CMakeLists.txt9
-rw-r--r--vespalib/src/tests/tensor/tensor/FILES1
-rw-r--r--vespalib/src/tests/tensor/tensor/tensor_test.cpp49
-rw-r--r--vespalib/src/tests/tensor/tensor_mapper/tensor_mapper_test.cpp13
-rw-r--r--vespalib/src/tests/tensor/tensor_operations/tensor_operations_test.cpp8
-rw-r--r--vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp23
-rw-r--r--vespalib/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp8
-rw-r--r--vespalib/src/tests/tensor/tensor_slime_serialization/tensor_slime_serialization_test.cpp12
-rw-r--r--vespalib/src/vespa/vespalib/tensor/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/tensor/compact/compact_tensor.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/tensor/dense/dense_tensor.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/CMakeLists.txt9
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/direct_simple_tensor_builder.h93
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.cpp243
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.h60
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.cpp72
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.h42
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.cpp56
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.h27
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.cpp117
-rw-r--r--vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.h47
-rw-r--r--vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/tensor/tensor_apply.h1
-rw-r--r--vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp5
-rw-r--r--vespalib/src/vespa/vespalib/tensor/tensor_operation.h2
32 files changed, 11 insertions, 958 deletions
diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt
index ec43cee3498..d5caceb78a6 100644
--- a/vespalib/CMakeLists.txt
+++ b/vespalib/CMakeLists.txt
@@ -77,8 +77,6 @@ vespa_define_module(
src/tests/tensor/dense_tensor_builder
src/tests/tensor/dense_tensor_operations
src/tests/tensor/join_tensor_addresses
- src/tests/tensor/simple_tensor_builder
- src/tests/tensor/tensor
src/tests/tensor/tensor_address
src/tests/tensor/tensor_address_element_iterator
src/tests/tensor/tensor_conformance
@@ -135,7 +133,6 @@ vespa_define_module(
src/vespa/vespalib/tensor/compact
src/vespa/vespalib/tensor/dense
src/vespa/vespalib/tensor/serialization
- src/vespa/vespalib/tensor/simple
src/vespa/vespalib/test
src/vespa/vespalib/testkit
src/vespa/vespalib/text
diff --git a/vespalib/src/tests/tensor/simple_tensor_builder/.gitignore b/vespalib/src/tests/tensor/simple_tensor_builder/.gitignore
deleted file mode 100644
index b8e9dc6dfc5..00000000000
--- a/vespalib/src/tests/tensor/simple_tensor_builder/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-vespalib_simple_tensor_builder_test_app
diff --git a/vespalib/src/tests/tensor/simple_tensor_builder/CMakeLists.txt b/vespalib/src/tests/tensor/simple_tensor_builder/CMakeLists.txt
deleted file mode 100644
index cd67231d418..00000000000
--- a/vespalib/src/tests/tensor/simple_tensor_builder/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(vespalib_simple_tensor_builder_test_app TEST
- SOURCES
- simple_tensor_builder_test.cpp
- DEPENDS
- vespalib
- vespalib_vespalib_tensor
-)
-vespa_add_test(NAME vespalib_simple_tensor_builder_test_app COMMAND vespalib_simple_tensor_builder_test_app)
diff --git a/vespalib/src/tests/tensor/simple_tensor_builder/FILES b/vespalib/src/tests/tensor/simple_tensor_builder/FILES
deleted file mode 100644
index e8940ccf5ef..00000000000
--- a/vespalib/src/tests/tensor/simple_tensor_builder/FILES
+++ /dev/null
@@ -1 +0,0 @@
-simple_tensor_builder_test.cpp
diff --git a/vespalib/src/tests/tensor/simple_tensor_builder/simple_tensor_builder_test.cpp b/vespalib/src/tests/tensor/simple_tensor_builder/simple_tensor_builder_test.cpp
deleted file mode 100644
index d43e1606d26..00000000000
--- a/vespalib/src/tests/tensor/simple_tensor_builder/simple_tensor_builder_test.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vespalib/testkit/test_kit.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
-
-using namespace vespalib::tensor;
-
-void
-assertCellValue(double expValue, const TensorAddress &address, const SimpleTensor::Cells &cells)
-{
- auto itr = cells.find(address);
- EXPECT_FALSE(itr == cells.end());
- EXPECT_EQUAL(expValue, itr->second);
-}
-
-TEST("require that tensor can be constructed")
-{
- SimpleTensorBuilder builder;
- builder.add_label(builder.define_dimension("a"), "1").
- add_label(builder.define_dimension("b"), "2").add_cell(10).
- add_label(builder.define_dimension("c"), "3").
- add_label(builder.define_dimension("d"), "4").add_cell(20);
- Tensor::UP tensor = builder.build();
- const SimpleTensor &simpleTensor = dynamic_cast<const SimpleTensor &>(*tensor);
- const SimpleTensor::Cells &cells = simpleTensor.cells();
- EXPECT_EQUAL(2u, cells.size());
- assertCellValue(10, TensorAddress({{"a","1"},{"b","2"}}), cells);
- assertCellValue(20, TensorAddress({{"c","3"},{"d","4"}}), cells);
-}
-
-TEST("require that dimensions are extracted")
-{
- SimpleTensorBuilder builder;
- builder.define_dimension("c");
- builder.define_dimension("a");
- builder.define_dimension("b");
- builder.
- add_label(builder.define_dimension("a"), "1").
- add_label(builder.define_dimension("b"), "2").add_cell(10).
- add_label(builder.define_dimension("b"), "3").
- add_label(builder.define_dimension("c"), "4").add_cell(20);
- Tensor::UP tensor = builder.build();
- const SimpleTensor &simpleTensor = dynamic_cast<const SimpleTensor &>(*tensor);
- const SimpleTensor::Dimensions &dims = simpleTensor.dimensions();
- EXPECT_EQUAL(3u, dims.size());
- EXPECT_EQUAL("a", dims[0]);
- EXPECT_EQUAL("b", dims[1]);
- EXPECT_EQUAL("c", dims[2]);
- EXPECT_EQUAL("tensor(a{},b{},c{})", simpleTensor.getType().to_spec());
-}
-
-TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/vespalib/src/tests/tensor/tensor/.gitignore b/vespalib/src/tests/tensor/tensor/.gitignore
deleted file mode 100644
index 5682a3d5a74..00000000000
--- a/vespalib/src/tests/tensor/tensor/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-vespalib_tensor_test_app
diff --git a/vespalib/src/tests/tensor/tensor/CMakeLists.txt b/vespalib/src/tests/tensor/tensor/CMakeLists.txt
deleted file mode 100644
index bf902d3a71d..00000000000
--- a/vespalib/src/tests/tensor/tensor/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(vespalib_tensor_test_app TEST
- SOURCES
- tensor_test.cpp
- DEPENDS
- vespalib
- vespalib_vespalib_tensor
-)
-vespa_add_test(NAME vespalib_tensor_test_app COMMAND vespalib_tensor_test_app)
diff --git a/vespalib/src/tests/tensor/tensor/FILES b/vespalib/src/tests/tensor/tensor/FILES
deleted file mode 100644
index 6ece9b360b5..00000000000
--- a/vespalib/src/tests/tensor/tensor/FILES
+++ /dev/null
@@ -1 +0,0 @@
-tensor_test.cpp
diff --git a/vespalib/src/tests/tensor/tensor/tensor_test.cpp b/vespalib/src/tests/tensor/tensor/tensor_test.cpp
deleted file mode 100644
index df80e6cbf18..00000000000
--- a/vespalib/src/tests/tensor/tensor/tensor_test.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vespalib/testkit/test_kit.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
-#include <vespa/vespalib/tensor/tensor_factory.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
-
-using namespace vespalib::tensor;
-
-namespace
-{
-
-SimpleTensor::UP createTensor(const TensorCells &cells)
-{
- SimpleTensorBuilder builder;
- return SimpleTensor::UP(static_cast<SimpleTensor *>
- (TensorFactory::create(cells, builder).release()));
-}
-
-}
-
-void
-assertCellValue(double expValue, const TensorAddress &address, const SimpleTensor::Cells &cells)
-{
- auto itr = cells.find(address);
- EXPECT_FALSE(itr == cells.end());
- EXPECT_EQUAL(expValue, itr->second);
-}
-
-TEST("require that tensor can be constructed")
-{
- SimpleTensor::UP tensor = createTensor({ {{{"a","1"},{"b","2"}},10}, {{{"c","3"},{"d","4"}},20} });
- const SimpleTensor::Cells &cells = tensor->cells();
- EXPECT_EQUAL(2u, cells.size());
- assertCellValue(10, TensorAddress({{"a","1"},{"b","2"}}), cells);
- assertCellValue(20, TensorAddress({{"c","3"},{"d","4"}}), cells);
-}
-
-TEST("require that dimensions are extracted")
-{
- SimpleTensor::UP tensor = createTensor({ {{{"a","1"},{"b","2"}},10}, {{{"b","3"},{"c","4"}},20} });
- const SimpleTensor::Dimensions &dims = tensor->dimensions();
- EXPECT_EQUAL(3u, dims.size());
- EXPECT_EQUAL("a", dims[0]);
- EXPECT_EQUAL("b", dims[1]);
- EXPECT_EQUAL("c", dims[2]);
-}
-
-TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/vespalib/src/tests/tensor/tensor_mapper/tensor_mapper_test.cpp b/vespalib/src/tests/tensor/tensor_mapper/tensor_mapper_test.cpp
index 612b5366d77..5b802ef67c8 100644
--- a/vespalib/src/tests/tensor/tensor_mapper/tensor_mapper_test.cpp
+++ b/vespalib/src/tests/tensor/tensor_mapper/tensor_mapper_test.cpp
@@ -2,8 +2,6 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h>
@@ -41,11 +39,6 @@ template <typename BuilderType>
struct TensorTFromBuilder;
template <>
-struct TensorTFromBuilder<SimpleTensorBuilder> {
- using TensorT = SimpleTensor;
-};
-
-template <>
struct TensorTFromBuilder<CompactTensorBuilder> {
using TensorT = CompactTensor;
};
@@ -130,7 +123,6 @@ struct Fixture : public FixtureBase
}
};
-using SimpleFixture = Fixture<SimpleTensorBuilder>;
using CompactFixture = Fixture<CompactTensorBuilder>;
using CompactV2Fixture = Fixture<CompactTensorV2Builder>;
@@ -208,11 +200,6 @@ testTensorMapper(FixtureType &f)
{ "x", "y" }));
}
-TEST_F("test tensor mapper for SimpleTensor", SimpleFixture)
-{
- testTensorMapper(f);
-}
-
TEST_F("test tensor mapper for CompactTensor", CompactFixture)
{
testTensorMapper(f);
diff --git a/vespalib/src/tests/tensor/tensor_operations/tensor_operations_test.cpp b/vespalib/src/tests/tensor/tensor_operations/tensor_operations_test.cpp
index 3948a6d68a6..482a588ef76 100644
--- a/vespalib/src/tests/tensor/tensor_operations/tensor_operations_test.cpp
+++ b/vespalib/src/tests/tensor/tensor_operations/tensor_operations_test.cpp
@@ -1,8 +1,6 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h>
@@ -221,7 +219,6 @@ struct Fixture
}
};
-using SimpleFixture = Fixture<SimpleTensorBuilder>;
using CompactFixture = Fixture<CompactTensorBuilder>;
using CompactV2Fixture = Fixture<CompactTensorV2Builder>;
@@ -616,11 +613,6 @@ testAllTensorOperations(FixtureType &f)
TEST_DO(testTensorSumDimension(f));
}
-TEST_F("test tensor operations for SimpleTensor", SimpleFixture)
-{
- testAllTensorOperations(f);
-}
-
TEST_F("test tensor operations for CompactTensor", CompactFixture)
{
testAllTensorOperations(f);
diff --git a/vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp b/vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp
index 2b9370bb606..46d4657d30a 100644
--- a/vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp
+++ b/vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp
@@ -7,8 +7,6 @@
#include <vespa/vespalib/tensor/compact/compact_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
#include <vespa/vespalib/tensor/dense/dense_tensor_builder.h>
#include <vespa/vespalib/tensor/tensor.h>
#include <vespa/vespalib/tensor/tensor_builder.h>
@@ -86,7 +84,7 @@ tensor::Tensor::UP parse_tensor(const vespalib::string &tensor_str) {
Function function = Function::parse(tensor_str);
auto tensor = nodes::as<nodes::Tensor>(function.root());
ASSERT_TRUE(tensor);
- SimpleTensorBuilder builder;
+ CompactTensorV2Builder builder;
for (const auto &cell: tensor->cells()) {
for (const auto &dimension: cell.first) {
builder.add_label(builder.define_dimension(dimension.first), dimension.second);
@@ -226,11 +224,10 @@ tensor::Tensor::UP make_tensor_impl(const std::vector<DimensionSpec> &dimensions
//-----------------------------------------------------------------------------
-enum class BuilderType { DUMMY, SIMPLE, COMPACT, COMPACTV2, NUMBERDUMMY,
+enum class BuilderType { DUMMY, COMPACT, COMPACTV2, NUMBERDUMMY,
DENSE };
const BuilderType DUMMY = BuilderType::DUMMY;
-const BuilderType SIMPLE = BuilderType::SIMPLE;
const BuilderType COMPACT = BuilderType::COMPACT;
const BuilderType COMPACTV2 = BuilderType::COMPACTV2;
const BuilderType NUMBERDUMMY = BuilderType::NUMBERDUMMY;
@@ -239,7 +236,6 @@ const BuilderType DENSE = BuilderType::DENSE;
const char *name(BuilderType type) {
switch (type) {
case BuilderType::DUMMY: return " dummy";
- case BuilderType::SIMPLE: return " simple";
case BuilderType::COMPACT: return "compact";
case BuilderType::COMPACTV2: return "compactv2";
case BuilderType::NUMBERDUMMY: return "numberdummy";
@@ -253,9 +249,6 @@ tensor::Tensor::UP make_tensor(BuilderType type, const std::vector<DimensionSpec
case BuilderType::DUMMY:
return make_tensor_impl<DummyBuilder, TensorBuilder, StringBinding>
(dimensions);
- case BuilderType::SIMPLE:
- return make_tensor_impl<SimpleTensorBuilder, TensorBuilder,
- StringBinding>(dimensions);
case BuilderType::COMPACT:
return make_tensor_impl<CompactTensorBuilder, TensorBuilder,
StringBinding>(dimensions);
@@ -289,7 +282,7 @@ double benchmark_build_us(BuilderType type, const std::vector<DimensionSpec> &sp
TEST("benchmark create/destroy time for 1d tensors") {
for (size_t size: {5, 10, 25, 50, 100, 250, 500}) {
- for (auto type: {SIMPLE, COMPACT, COMPACTV2, DENSE}) {
+ for (auto type: {COMPACT, COMPACTV2, DENSE}) {
double time_us = benchmark_build_us(type, {DimensionSpec("x", size)});
fprintf(stderr, "-- 1d tensor create/destroy (%s) with size %zu: %g us\n", name(type), size, time_us);
}
@@ -298,7 +291,7 @@ TEST("benchmark create/destroy time for 1d tensors") {
TEST("benchmark create/destroy time for 2d tensors") {
for (size_t size: {5, 10, 25, 50, 100}) {
- for (auto type: {SIMPLE, COMPACT, COMPACTV2, DENSE}) {
+ for (auto type: {COMPACT, COMPACTV2, DENSE}) {
double time_us = benchmark_build_us(type, {DimensionSpec("x", size), DimensionSpec("y", size)});
fprintf(stderr, "-- 2d tensor create/destroy (%s) with size %zux%zu: %g us\n", name(type), size, size, time_us);
}
@@ -309,7 +302,7 @@ TEST("benchmark create/destroy time for 2d tensors") {
TEST("benchmark dot product using match") {
for (size_t size: {10, 25, 50, 100, 250}) {
- for (auto type: {SIMPLE, COMPACT, COMPACTV2, DENSE}) {
+ for (auto type: {COMPACT, COMPACTV2, DENSE}) {
Params params;
params.add("query", make_tensor(type, {DimensionSpec("x", size)}));
params.add("document", make_tensor(type, {DimensionSpec("x", size)}));
@@ -321,7 +314,7 @@ TEST("benchmark dot product using match") {
TEST("benchmark dot product using multiply") {
for (size_t size: {10, 25, 50, 100, 250}) {
- for (auto type: {SIMPLE, COMPACT, COMPACTV2, DENSE}) {
+ for (auto type: {COMPACT, COMPACTV2, DENSE}) {
Params params;
params.add("query", make_tensor(type, {DimensionSpec("x", size)}));
params.add("document", make_tensor(type, {DimensionSpec("x", size)}));
@@ -335,7 +328,7 @@ TEST("benchmark model match") {
for (size_t model_size: {25, 50, 100}) {
for (size_t vector_size: {5, 10, 25, 50, 100}) {
if (vector_size <= model_size) {
- for (auto type: {SIMPLE, COMPACT, COMPACTV2}) {
+ for (auto type: {COMPACT, COMPACTV2}) {
Params params;
params.add("query", make_tensor(type, {DimensionSpec("x", vector_size)}));
params.add("document", make_tensor(type, {DimensionSpec("y", vector_size)}));
@@ -351,7 +344,7 @@ TEST("benchmark model match") {
TEST("benchmark matrix product") {
for (size_t vector_size: {5, 10, 25, 50}) {
size_t matrix_size = vector_size * 2;
- for (auto type: {SIMPLE, COMPACT, COMPACTV2, DENSE}) {
+ for (auto type: {COMPACT, COMPACTV2, DENSE}) {
Params params;
size_t document_size = vector_size;
if (type == DENSE) {
diff --git a/vespalib/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp b/vespalib/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp
index 6a4fcefba9c..f83015c9d1b 100644
--- a/vespalib/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp
+++ b/vespalib/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp
@@ -1,8 +1,6 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h>
@@ -101,7 +99,6 @@ struct Fixture
}
};
-using SimpleFixture = Fixture<SimpleTensorBuilder>;
using CompactFixture = Fixture<CompactTensorBuilder>;
using CompactV2Fixture = Fixture<CompactTensorV2Builder>;
@@ -140,11 +137,6 @@ testTensorSerialization(FixtureType &f)
{ {{{"x","1"}}, 3} }, {"x", "y"}));
}
-TEST_F("test tensor serialization for SimpleTensor", SimpleFixture)
-{
- testTensorSerialization(f);
-}
-
TEST_F("test tensor serialization for CompactTensor", CompactFixture)
{
testTensorSerialization(f);
diff --git a/vespalib/src/tests/tensor/tensor_slime_serialization/tensor_slime_serialization_test.cpp b/vespalib/src/tests/tensor/tensor_slime_serialization/tensor_slime_serialization_test.cpp
index f53b42c433e..0423770db59 100644
--- a/vespalib/src/tests/tensor/tensor_slime_serialization/tensor_slime_serialization_test.cpp
+++ b/vespalib/src/tests/tensor/tensor_slime_serialization/tensor_slime_serialization_test.cpp
@@ -1,8 +1,6 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
-#include <vespa/vespalib/tensor/simple/simple_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h>
@@ -46,10 +44,6 @@ struct Fixture
template <>
uint32_t
-Fixture<SimpleTensorBuilder>::getTensorTypeId() { return 0u; }
-
-template <>
-uint32_t
Fixture<CompactTensorBuilder>::getTensorTypeId() { return 1u; }
template <>
@@ -57,7 +51,6 @@ uint32_t
Fixture<CompactTensorV2Builder>::getTensorTypeId() { return 2u; }
-using SimpleFixture = Fixture<SimpleTensorBuilder>;
using CompactFixture = Fixture<CompactTensorBuilder>;
using CompactV2Fixture = Fixture<CompactTensorV2Builder>;
@@ -128,11 +121,6 @@ testTensorSlimeSerialization(FixtureType &f)
{"x", "y"}));
}
-TEST_F("test tensor slime serialization for SimpleTensor", SimpleFixture)
-{
- testTensorSlimeSerialization(f);
-}
-
TEST_F("test tensor slime serialization for CompactTensor", CompactFixture)
{
testTensorSlimeSerialization(f);
diff --git a/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt b/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt
index 93a9f724235..388885b6e50 100644
--- a/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt
@@ -11,7 +11,6 @@ vespa_add_library(vespalib_vespalib_tensor
$<TARGET_OBJECTS:vespalib_vespalib_tensor_compact>
$<TARGET_OBJECTS:vespalib_vespalib_tensor_dense>
$<TARGET_OBJECTS:vespalib_vespalib_tensor_serialization>
- $<TARGET_OBJECTS:vespalib_vespalib_tensor_simple>
INSTALL lib64
DEPENDS
)
diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor.cpp b/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor.cpp
index 20dd57b233e..934593bb228 100644
--- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor.cpp
+++ b/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor.cpp
@@ -6,6 +6,7 @@
#include "compact_tensor_dimension_sum.h"
#include "compact_tensor_product.h"
#include <vespa/vespalib/tensor/join_tensors.h>
+#include <vespa/vespalib/tensor/tensor_address_builder.h>
#include <vespa/vespalib/tensor/tensor_apply.h>
#include <vespa/vespalib/tensor/tensor_visitor.h>
#include <sstream>
diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp b/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp
index a9b90196bc6..fdff22e9525 100644
--- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp
+++ b/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp
@@ -7,6 +7,7 @@
#include "compact_tensor_v2_match.h"
#include "compact_tensor_v2_product.h"
#include "join_compact_tensors_v2.h"
+#include <vespa/vespalib/tensor/tensor_address_builder.h>
#include <vespa/vespalib/tensor/tensor_apply.h>
#include <vespa/vespalib/tensor/tensor_visitor.h>
#include <sstream>
diff --git a/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor.cpp b/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor.cpp
index 108db088124..5a160329e79 100644
--- a/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor.cpp
+++ b/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor.cpp
@@ -7,6 +7,7 @@
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/stllike/asciistream.h>
+#include <vespa/vespalib/tensor/tensor_address_builder.h>
#include <vespa/vespalib/tensor/tensor_visitor.h>
#include <sstream>
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/CMakeLists.txt b/vespalib/src/vespa/vespalib/tensor/simple/CMakeLists.txt
deleted file mode 100644
index deeb18030e4..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_library(vespalib_vespalib_tensor_simple OBJECT
- SOURCES
- simple_tensor.cpp
- simple_tensor_builder.cpp
- simple_tensor_dimension_sum.cpp
- simple_tensor_product.cpp
- DEPENDS
-)
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/direct_simple_tensor_builder.h b/vespalib/src/vespa/vespalib/tensor/simple/direct_simple_tensor_builder.h
deleted file mode 100644
index 525d0ef9864..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/direct_simple_tensor_builder.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/vespalib/tensor/direct_tensor_builder.h>
-#include "simple_tensor.h"
-#include <vespa/vespalib/tensor/tensor_address_builder.h>
-
-namespace vespalib {
-namespace tensor {
-
-/**
- * Utility class to build tensors of type SimpleTensor, to be used by
- * tensor operations.
- */
-template <> class DirectTensorBuilder<SimpleTensor>
-{
-public:
- using TensorImplType = SimpleTensor;
- using Dimensions = typename TensorImplType::Dimensions;
- using Cells = typename TensorImplType::Cells;
- using AddressBuilderType = TensorAddressBuilder;
- using AddressRefType = TensorAddress;
- using AddressType = TensorAddress;
-
-private:
- Dimensions _dimensions;
- Cells _cells;
-
-public:
- DirectTensorBuilder()
- : _dimensions(),
- _cells()
- {
- }
-
- DirectTensorBuilder(const Dimensions &dimensions_in)
- : _dimensions(dimensions_in),
- _cells()
- {
- }
-
- DirectTensorBuilder(const Dimensions &dimensions_in,
- const Cells &cells_in)
- : _dimensions(dimensions_in),
- _cells(cells_in)
- {
- }
-
- Tensor::UP build() {
- return std::make_unique<SimpleTensor>(std::move(_dimensions),
- std::move(_cells));
- }
-
- template <class Function>
- void insertCell(const TensorAddress &address, double value,
- Function &&func)
- {
- auto res = _cells.insert(std::make_pair(address, value));
- if (!res.second) {
- res.first->second = func(res.first->second, value);
- }
- }
-
- void insertCell(const TensorAddress &address, double value) {
- // This address should not already exist and a new cell should be inserted.
- insertCell(address, value, [](double, double) -> double { abort(); });
- }
-
- // Note: moves data from TensorAddressBuilder to new TensorAddress.
- template <class Function>
- void insertCell(TensorAddressBuilder &address, double value,
- Function &&func)
- {
- auto res =
- _cells.insert(std::make_pair(address.build(), value));
- if (!res.second) {
- res.first->second = func(res.first->second, value);
- }
- }
-
- void insertCell(TensorAddressBuilder &address, double value) {
- // This address should not already exist and a new cell should be inserted.
- insertCell(address, value, [](double, double) -> double { abort(); });
- }
-
- Dimensions &dimensions() { return _dimensions; }
- Cells &cells() { return _cells; }
-};
-
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.cpp b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.cpp
deleted file mode 100644
index bb4b363a062..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/fastos/fastos.h>
-#include "simple_tensor.h"
-#include "simple_tensor_dimension_sum.h"
-#include "simple_tensor_product.h"
-#include <vespa/vespalib/tensor/join_tensors.h>
-#include <vespa/vespalib/tensor/tensor_apply.h>
-#include <sstream>
-#include <vespa/vespalib/tensor/tensor_visitor.h>
-
-namespace vespalib {
-namespace tensor {
-
-SimpleTensor::SimpleTensor(const Dimensions &dimensions_in, const Cells &cells_in)
- : _dimensions(dimensions_in),
- _cells(cells_in)
-{
-}
-
-SimpleTensor::SimpleTensor(Dimensions &&dimensions_in, Cells &&cells_in)
- : _dimensions(std::move(dimensions_in)),
- _cells(std::move(cells_in))
-{
-}
-
-bool
-SimpleTensor::operator==(const SimpleTensor &rhs) const
-{
- return _dimensions == rhs._dimensions && _cells == rhs._cells;
-}
-
-SimpleTensor::Dimensions
-SimpleTensor::combineDimensionsWith(const SimpleTensor &rhs) const
-{
- Dimensions result;
- std::set_union(_dimensions.cbegin(), _dimensions.cend(),
- rhs._dimensions.cbegin(), rhs._dimensions.cend(),
- std::back_inserter(result));
- return result;
-}
-
-eval::ValueType
-SimpleTensor::getType() const
-{
- if (_dimensions.empty()) {
- return eval::ValueType::double_type();
- }
- std::vector<eval::ValueType::Dimension> dimensions;
- std::copy(_dimensions.begin(), _dimensions.end(), std::back_inserter(dimensions));
- return eval::ValueType::tensor_type(dimensions);
-}
-
-double
-SimpleTensor::sum() const
-{
- double result = 0.0;
- for (const auto &cell : _cells) {
- result += cell.second;
- }
- return result;
-}
-
-Tensor::UP
-SimpleTensor::add(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- return joinTensors(*this, *rhs,
- [](double lhsValue, double rhsValue) { return lhsValue + rhsValue; });
-}
-
-Tensor::UP
-SimpleTensor::subtract(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- // Note that -rhsCell.second is passed to the lambda function, that is why we do addition.
- return joinTensorsNegated(*this, *rhs,
- [](double lhsValue, double rhsValue) { return lhsValue + rhsValue; });
-}
-
-Tensor::UP
-SimpleTensor::multiply(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- return SimpleTensorProduct(*this, *rhs).result();
-}
-
-Tensor::UP
-SimpleTensor::min(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- return joinTensors(*this, *rhs,
- [](double lhsValue, double rhsValue){ return std::min(lhsValue, rhsValue); });
-}
-
-Tensor::UP
-SimpleTensor::max(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- return joinTensors(*this, *rhs,
- [](double lhsValue, double rhsValue){ return std::max(lhsValue, rhsValue); });
-}
-
-Tensor::UP
-SimpleTensor::match(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- DirectTensorBuilder<SimpleTensor> builder(combineDimensionsWith(*rhs));
- for (const auto &lhsCell : cells()) {
- auto rhsItr = rhs->cells().find(lhsCell.first);
- if (rhsItr != rhs->cells().end()) {
- builder.insertCell(lhsCell.first, lhsCell.second * rhsItr->second);
- }
- }
- return builder.build();
-}
-
-Tensor::UP
-SimpleTensor::apply(const CellFunction &func) const
-{
- return TensorApply<SimpleTensor>(*this, func).result();
-}
-
-Tensor::UP
-SimpleTensor::sum(const vespalib::string &dimension) const
-{
- return SimpleTensorDimensionSum(*this, dimension).result();
-}
-
-bool
-SimpleTensor::equals(const Tensor &arg) const
-{
- const SimpleTensor *rhs = dynamic_cast<const SimpleTensor *>(&arg);
- if (!rhs) {
- return false;
- }
- return *this == *rhs;
-}
-
-vespalib::string
-SimpleTensor::toString() const
-{
- std::ostringstream stream;
- stream << *this;
- return stream.str();
-}
-
-Tensor::UP
-SimpleTensor::clone() const
-{
- return std::make_unique<SimpleTensor>(_dimensions, _cells);
-}
-
-namespace {
-
-TensorAddress
-getAddressNotFoundInCells(const SimpleTensor::Dimensions &dimensions,
- const SimpleTensor::Cells &cells)
-{
- TensorDimensionsSet dimensionsNotFoundInCells(dimensions.begin(),
- dimensions.end());
- for (const auto &cell : cells) {
- for (const auto &elem : cell.first.elements()) {
- dimensionsNotFoundInCells.erase(elem.dimension());
- }
- }
- SimpleTensor::Dimensions
- missingDimensions(dimensionsNotFoundInCells.begin(),
- dimensionsNotFoundInCells.end());
- std::sort(missingDimensions.begin(), missingDimensions.end());
- TensorAddress::Elements elements;
- for (const auto &dimension : missingDimensions) {
- elements.emplace_back(dimension, "-");
- }
- return TensorAddress(elements);
-}
-
-void
-printCells(const SimpleTensor::Cells &cells, std::ostream &out)
-{
- out << "{ ";
- bool first = true;
- for (const auto &cell : cells) {
- if (!first) {
- out << ", ";
- }
- out << cell.first << ":" << cell.second;
- first = false;
- }
- out << " }";
-}
-
-}
-
-void
-SimpleTensor::print(std::ostream &out) const
-{
- // This address represents the extra tensor dimensions that are not
- // explicitly found in the tensor cells.
- TensorAddress extraDimensionsAddress = getAddressNotFoundInCells(dimensions(), cells());
- if (extraDimensionsAddress.elements().empty()) {
- printCells(cells(), out);
- } else {
- out << "( ";
- printCells(cells(), out);
- out << " * ";
- // Multiplying with this cell gives us a way of representing the extra tensor
- // dimensions without having explicit syntax for printing dimensions.
- SimpleTensor::Cells extraDimensionsCell;
- extraDimensionsCell.insert(std::make_pair(extraDimensionsAddress, 1.0));
- printCells(extraDimensionsCell, out);
- out << " )";
- }
-}
-
-void
-SimpleTensor::accept(TensorVisitor &visitor) const
-{
- for (const auto &cell : _cells) {
- visitor.visit(cell.first, cell.second);
- }
-}
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.h b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.h
deleted file mode 100644
index aaa3c274f12..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/vespalib/tensor/cell_function.h>
-#include <vespa/vespalib/tensor/tensor.h>
-#include <vespa/vespalib/tensor/tensor_address.h>
-#include <vespa/vespalib/tensor/types.h>
-#include <vespa/vespalib/stllike/hash_map.h>
-#include <vespa/vespalib/stllike/string.h>
-#include <set>
-
-namespace vespalib {
-namespace tensor {
-
-/**
- * A sparse multi-dimensional array.
- *
- * A sparse tensor is a set of cells containing scalar values.
- * Each cell is identified by its address, which consists of a set of dimension -> label pairs,
- * where both dimension and label is a string on the form of an identifier or integer.
- */
-class SimpleTensor : public Tensor
-{
-public:
- typedef std::unique_ptr<SimpleTensor> UP;
- typedef vespalib::hash_map<TensorAddress, double> Cells;
- typedef TensorDimensions Dimensions;
-
-private:
- Dimensions _dimensions;
- Cells _cells;
-
-public:
- SimpleTensor(const Dimensions &dimensions_in, const Cells &cells_in);
- SimpleTensor(Dimensions &&dimensions_in, Cells &&cells_in);
- const Cells &cells() const { return _cells; }
- const Dimensions &dimensions() const { return _dimensions; }
- bool operator==(const SimpleTensor &rhs) const;
- Dimensions combineDimensionsWith(const SimpleTensor &rhs) const;
-
- virtual eval::ValueType getType() const override;
- virtual double sum() const override;
- virtual Tensor::UP add(const Tensor &arg) const override;
- virtual Tensor::UP subtract(const Tensor &arg) const override;
- virtual Tensor::UP multiply(const Tensor &arg) const override;
- virtual Tensor::UP min(const Tensor &arg) const override;
- virtual Tensor::UP max(const Tensor &arg) const override;
- virtual Tensor::UP match(const Tensor &arg) const override;
- virtual Tensor::UP apply(const CellFunction &func) const override;
- virtual Tensor::UP sum(const vespalib::string &dimension) const override;
- virtual bool equals(const Tensor &arg) const override;
- virtual void print(std::ostream &out) const override;
- virtual vespalib::string toString() const override;
- virtual Tensor::UP clone() const override;
- virtual void accept(TensorVisitor &visitor) const override;
-};
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.cpp b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.cpp
deleted file mode 100644
index 1d24dd9147d..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "simple_tensor_builder.h"
-#include <vespa/vespalib/tensor/tensor.h>
-
-namespace vespalib {
-namespace tensor {
-
-
-SimpleTensorBuilder::SimpleTensorBuilder()
- : TensorBuilder(),
- _addressBuilder(),
- _cells(),
- _dimensionsEnum(),
- _dimensions()
-{
-}
-
-SimpleTensorBuilder::~SimpleTensorBuilder()
-{
-}
-
-
-TensorBuilder::Dimension
-SimpleTensorBuilder::define_dimension(const vespalib::string &dimension)
-{
- auto it = _dimensionsEnum.find(dimension);
- if (it != _dimensionsEnum.end()) {
- return it->second;
- }
- Dimension res = _dimensionsEnum.size();
- auto insres = _dimensionsEnum.insert(std::make_pair(dimension, res));
- assert(insres.second);
- assert(insres.first->second == res);
- assert(_dimensions.size() == res);
- _dimensions.push_back(dimension);
- return res;
-}
-
-TensorBuilder &
-SimpleTensorBuilder::add_label(Dimension dimension,
- const vespalib::string &label)
-{
- assert(dimension <= _dimensions.size());
- _addressBuilder.add(_dimensions[dimension], label);
- return *this;
-}
-
-TensorBuilder &
-SimpleTensorBuilder::add_cell(double value)
-{
- _cells[_addressBuilder.build()] = value;
- _addressBuilder.clear();
- return *this;
-}
-
-
-Tensor::UP
-SimpleTensorBuilder::build()
-{
- SimpleTensor::Dimensions dimensions(_dimensions.begin(), _dimensions.end());
- std::sort(dimensions.begin(), dimensions.end());
- Tensor::UP ret = std::make_unique<SimpleTensor>(std::move(dimensions), std::move(_cells));
- SimpleTensor::Cells().swap(_cells);
- _dimensionsEnum.clear();
- _dimensions.clear();
- return ret;
-}
-
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.h b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.h
deleted file mode 100644
index 81d94921b03..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_builder.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include "simple_tensor.h"
-#include <vespa/vespalib/tensor/tensor_builder.h>
-#include <vespa/vespalib/tensor/tensor_address.h>
-#include <vespa/vespalib/tensor/tensor_address_builder.h>
-#include <vespa/vespalib/stllike/hash_map.h>
-
-namespace vespalib {
-namespace tensor {
-
-/**
- * A simple builder of tensors (sparse multi-dimensional array).
- *
- * A sparse tensor is a set of cells containing scalar values.
- * Each cell is identified by its address, which consists of a set of dimension -> label pairs,
- * where both dimension and label is a string on the form of an identifier or integer.
- */
-class SimpleTensorBuilder : public TensorBuilder
-{
- TensorAddressBuilder _addressBuilder;
- SimpleTensor::Cells _cells;
- vespalib::hash_map<vespalib::string, uint32_t> _dimensionsEnum;
- std::vector<vespalib::string> _dimensions;
-public:
- SimpleTensorBuilder();
- virtual ~SimpleTensorBuilder();
-
- virtual Dimension
- define_dimension(const vespalib::string &dimension) override;
- virtual TensorBuilder &
- add_label(Dimension dimension,
- const vespalib::string &label) override;
- virtual TensorBuilder &add_cell(double value) override;
-
- virtual Tensor::UP build() override;
-};
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.cpp b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.cpp
deleted file mode 100644
index 435034b8f35..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/fastos/fastos.h>
-#include "simple_tensor_dimension_sum.h"
-#include <vespa/vespalib/tensor/tensor_address_element_iterator.h>
-
-namespace vespalib {
-namespace tensor {
-
-namespace {
-
-template <class AddressBuilder, class Address>
-void
-removeDimension(AddressBuilder &addressBuilder,
- const Address &address,
- const vespalib::stringref dimension)
-{
- addressBuilder.clear();
- for (const auto &elem : address.elements()) {
- if (elem.dimension() != dimension) {
- addressBuilder.add(elem.dimension(), elem.label());
- }
- }
-}
-
-TensorDimensions
-removeDimension(const TensorDimensions &dimensions,
- const vespalib::string &dimension)
-{
- TensorDimensions result = dimensions;
- auto itr = std::lower_bound(result.begin(), result.end(), dimension);
- if (itr != result.end() && *itr == dimension) {
- result.erase(itr);
- }
- return result;
-}
-
-}
-
-SimpleTensorDimensionSum::SimpleTensorDimensionSum(const TensorImplType &tensor,
- const vespalib::string &
- dimension)
- : Parent(removeDimension(tensor.dimensions(), dimension))
-{
- AddressBuilderType reducedAddress;
- for (const auto &cell : tensor.cells()) {
- removeDimension<AddressBuilderType, AddressType>
- (reducedAddress, cell.first, dimension);
- _builder.insertCell(reducedAddress, cell.second,
- [](double cellValue, double rhsValue) { return cellValue + rhsValue; });
- }
-}
-
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.h b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.h
deleted file mode 100644
index adcbb2c1825..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_dimension_sum.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/vespalib/tensor/tensor_operation.h>
-
-namespace vespalib {
-namespace tensor {
-
-/**
- * Returns a tensor with the given dimension removed and the cell values in that dimension summed.
- */
-class SimpleTensorDimensionSum : public TensorOperation<SimpleTensor>
-{
-public:
- using TensorImplType = SimpleTensor;
- using Parent = TensorOperation<SimpleTensor>;
- using AddressBuilderType = typename Parent::AddressBuilderType;
- using AddressType = typename Parent::AddressType;
- using Parent::_builder;
- SimpleTensorDimensionSum(const TensorImplType &tensor,
- const vespalib::string &dimension);
-};
-
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.cpp b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.cpp
deleted file mode 100644
index b4e7eaf119b..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/fastos/fastos.h>
-#include "simple_tensor_product.h"
-#include <vespa/vespalib/tensor/tensor_address_element_iterator.h>
-#include <vespa/vespalib/tensor/dimensions_vector_iterator.h>
-#include <vespa/vespalib/tensor/join_tensor_addresses.h>
-#include <type_traits>
-
-namespace vespalib {
-namespace tensor {
-
-namespace {
-
-template <class Dimensions>
-void
-calcIntersectDimensions(DimensionsVector &res,
- const Dimensions &lhs, const Dimensions &rhs)
-{
- std::set_intersection(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(),
- std::back_inserter(res));
-}
-
-
-template <class Dimensions>
-void
-calcIntersectDimensions(DimensionsSet &res,
- const Dimensions &lhs, const Dimensions &rhs)
-{
- for (const auto &dimension : lhs) {
- if (std::binary_search(rhs.begin(), rhs.end(), dimension)) {
- res.insert(vespalib::stringref(dimension.c_str(),
- dimension.size()));
- }
- }
-}
-
-
-}
-
-
-template <class DimensionsCollection>
-void
-SimpleTensorProduct::template bruteForceProduct(const TensorImplType &lhs,
- const TensorImplType &rhs)
-{
- DimensionsCollection iDims;
- calcIntersectDimensions<Dimensions>(iDims,
- lhs.dimensions(), rhs.dimensions());
- AddressBuilderType combinedAddress;
- for (const auto &lhsCell : lhs.cells()) {
- for (const auto &rhsCell : rhs.cells()) {
- bool combineSuccess = joinTensorAddresses<AddressBuilderType,
- AddressType, AddressType>
- (combinedAddress, iDims,
- lhsCell.first, rhsCell.first);
- if (combineSuccess) {
- _builder.insertCell(combinedAddress, lhsCell.second * rhsCell.second);
- }
- }
- }
-}
-
-
-void
-SimpleTensorProduct::fastProduct(const TensorImplType &lhs,
- const TensorImplType &rhs)
-{
- const typename TensorImplType::Cells &rhsCells = rhs.cells();
- for (const auto &lhsCell : lhs.cells()) {
- auto itr = rhsCells.find(lhsCell.first);
- if (itr != rhsCells.end()) {
- _builder.insertCell(lhsCell.first, lhsCell.second * itr->second);
- }
- }
-}
-
-
-SimpleTensorProduct::SimpleTensorProduct(const TensorImplType &lhs,
- const TensorImplType &rhs)
- : Parent(lhs.combineDimensionsWith(rhs))
-{
-#if 0
- /* Commented ut for now since we want to see brute force performance. */
- // All dimensions are common
- if (lhs.dimensions().size() == rhs.dimensions().size() &&
- lhs.dimensions().size() == _builder.dimensions().size()) {
- fastProduct(lhs, rhs);
- return;
- }
- // TODO: Handle zero cells or zero dimensions cases
- // No dimensions are common
- if (lhs.dimensions().size() + rhs.dimensions().size() ==
- _builder.dimensions().size()) {
- bruteForceNoCommonDimensionProduct(lhs, rhs);
- return;
- }
- // lhs dimensions equals common dimensions
- if (rhs.dimensions().size() == _builder.dimensions().size()) {
- }
- // rhs dimensions equals common dimensions
- if (lhs.dimensions().size() == _builder.dimensions().size()) {
- }
-#endif
-#if 1
- // few common dimensions
- bruteForceProduct<DimensionsVector>(lhs, rhs);
-#else
- // many common dimensions, too expensive to iterate through all of
- // them if each cell has relatively few dimensions.
- bruteForceProduct<DimensionsSet>(lhs, rhs);
-#endif
-}
-
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.h b/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.h
deleted file mode 100644
index c811dd2d699..00000000000
--- a/vespalib/src/vespa/vespalib/tensor/simple/simple_tensor_product.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/vespalib/tensor/tensor_operation.h>
-
-namespace vespalib {
-namespace tensor {
-
-/**
- * Returns the sparse tensor product of the two given tensors.
- * This is all combinations of all cells in the first tensor with all cells of
- * the second tensor, except the combinations which would have multiple labels
- * for the same dimension due to shared dimensions between the two tensors.
- *
- * If there are no overlapping dimensions this is the regular tensor product.
- * If the two tensors have exactly the same dimensions this is the Hadamard product.
- *
- * The sparse tensor is associative and commutative. Its dimensions are the
- * set of the dimensions of the two input tensors.
- */
-class SimpleTensorProduct : public TensorOperation<SimpleTensor>
-{
-public:
- using TensorImplType = SimpleTensor;
- using Parent = TensorOperation<SimpleTensor>;
- using Dimensions = typename Parent::Dimensions;
- using AddressBuilderType = typename Parent::AddressBuilderType;
- using AddressRefType = typename Parent::AddressRefType;
- using AddressType = typename Parent::AddressType;
- using Parent::_builder;
-
-private:
- template <class DimensionsCollection>
- void
- bruteForceProduct(const TensorImplType &lhs, const TensorImplType &rhs);
-
- void
- fastProduct(const TensorImplType &lhs, const TensorImplType &rhs);
-
-public:
- SimpleTensorProduct(const TensorImplType &lhs, const TensorImplType &rhs);
-};
-
-
-} // namespace vespalib::tensor
-} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp b/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp
index ad9cab61243..9a2b0dcb7a6 100644
--- a/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp
+++ b/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp
@@ -16,7 +16,6 @@ TensorApply<TensorT>::TensorApply(const TensorImplType &tensor,
}
}
-template class TensorApply<SimpleTensor>;
template class TensorApply<CompactTensor>;
template class TensorApply<CompactTensorV2>;
diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_apply.h b/vespalib/src/vespa/vespalib/tensor/tensor_apply.h
index 7fc9cd2ccfa..328595299dc 100644
--- a/vespalib/src/vespa/vespalib/tensor/tensor_apply.h
+++ b/vespalib/src/vespa/vespalib/tensor/tensor_apply.h
@@ -21,7 +21,6 @@ public:
TensorApply(const TensorImplType &tensor, const CellFunction &func);
};
-extern template class TensorApply<SimpleTensor>;
extern template class TensorApply<CompactTensor>;
extern template class TensorApply<CompactTensorV2>;
diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp b/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp
index 80596672d5a..aa448841504 100644
--- a/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp
+++ b/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp
@@ -5,7 +5,6 @@
#include "tensor_mapper.h"
#include "tensor.h"
#include "tensor_visitor.h"
-#include <vespa/vespalib/tensor/simple/direct_simple_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/direct_compact_tensor_v2_builder.h>
#include <vespa/vespalib/tensor/compact/direct_compact_tensor_builder.h>
#include <vespa/vespalib/tensor/dense/dense_tensor.h>
@@ -272,10 +271,6 @@ TensorMapper::map(const Tensor &tensor) const
}
}
-template
-std::unique_ptr<Tensor>
-TensorMapper::mapToSparse<SimpleTensor>(const Tensor &tensor,
- const ValueType &type);
template
std::unique_ptr<Tensor>
diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_operation.h b/vespalib/src/vespa/vespalib/tensor/tensor_operation.h
index e115ec153b7..c62f42da0f1 100644
--- a/vespalib/src/vespa/vespalib/tensor/tensor_operation.h
+++ b/vespalib/src/vespa/vespalib/tensor/tensor_operation.h
@@ -2,9 +2,7 @@
#pragma once
-#include <vespa/vespalib/tensor/simple/simple_tensor.h>
#include "direct_tensor_builder.h"
-#include <vespa/vespalib/tensor/simple/direct_simple_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/direct_compact_tensor_builder.h>
#include <vespa/vespalib/tensor/compact/direct_compact_tensor_v2_builder.h>