diff options
53 files changed, 248 insertions, 249 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/CompactBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java index e850e20fcab..711e0e834da 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/CompactBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java @@ -12,7 +12,7 @@ import com.yahoo.text.Utf8; import java.util.*; /** - * Implementation of a compact binary format for a tensor on the form: + * Implementation of a sparse binary format for a tensor on the form: * * Sorted dimensions = num_dimensions [dimension_str_len dimension_str_bytes]* * Cells = num_cells [label_1_str_len label_1_str_bytes ... label_N_str_len label_N_str_bytes cell_value]* @@ -23,7 +23,7 @@ import java.util.*; * @author geirst */ @Beta -class CompactBinaryFormat implements BinaryFormat { +class SparseBinaryFormat implements BinaryFormat { @Override public void encode(GrowableByteBuffer buffer, Tensor tensor) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java index 9e2c0b5a63f..5a45f20b6d8 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java @@ -17,12 +17,12 @@ import com.yahoo.tensor.Tensor; @Beta public class TypedBinaryFormat { - private static final int COMPACT_BINARY_FORMAT_TYPE = 1; + private static final int SPARSE_BINARY_FORMAT_TYPE = 1; public static byte[] encode(Tensor tensor) { GrowableByteBuffer buffer = new GrowableByteBuffer(); - buffer.putInt1_4Bytes(COMPACT_BINARY_FORMAT_TYPE); - new CompactBinaryFormat().encode(buffer, tensor); + buffer.putInt1_4Bytes(SPARSE_BINARY_FORMAT_TYPE); + new SparseBinaryFormat().encode(buffer, tensor); buffer.flip(); byte[] result = new byte[buffer.remaining()]; buffer.get(result); @@ -33,8 +33,8 @@ public class TypedBinaryFormat { GrowableByteBuffer buffer = GrowableByteBuffer.wrap(data); int formatType = buffer.getInt1_4Bytes(); switch (formatType) { - case COMPACT_BINARY_FORMAT_TYPE: - return new CompactBinaryFormat().decode(buffer); + case SPARSE_BINARY_FORMAT_TYPE: + return new SparseBinaryFormat().decode(buffer); default: throw new IllegalArgumentException("Binary format type " + formatType + " is not a known format"); } diff --git a/vespajlib/src/test/java/com/yahoo/tensor/serialization/CompactBinaryFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/serialization/SparseBinaryFormatTestCase.java index bfa7f5a8546..8580868dfdf 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/CompactBinaryFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/SparseBinaryFormatTestCase.java @@ -12,14 +12,14 @@ import java.util.Set; import static org.junit.Assert.assertEquals; /** - * Tests for the compact binary format. + * Tests for the sparse binary format. * * TODO: When new formats are added we should refactor this test to test all formats * with the same set of tensor inputs (if feasible). * * @author geirst */ -public class CompactBinaryFormatTestCase { +public class SparseBinaryFormatTestCase { private static void assertSerialization(String tensorString) { assertSerialization(MapTensor.from(tensorString)); diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt index 11ccc12b549..2ca768bc483 100644 --- a/vespalib/CMakeLists.txt +++ b/vespalib/CMakeLists.txt @@ -72,7 +72,7 @@ vespa_define_module( src/tests/stllike src/tests/stringfmt src/tests/sync - src/tests/tensor/compact_tensor_v2_builder + src/tests/tensor/sparse_tensor_builder src/tests/tensor/dense_tensor_builder src/tests/tensor/dense_tensor_operations src/tests/tensor/join_tensor_addresses @@ -129,7 +129,7 @@ vespa_define_module( src/vespa/vespalib/objects src/vespa/vespalib/stllike src/vespa/vespalib/tensor - src/vespa/vespalib/tensor/compact + src/vespa/vespalib/tensor/sparse src/vespa/vespalib/tensor/dense src/vespa/vespalib/tensor/serialization src/vespa/vespalib/test diff --git a/vespalib/src/testlist.txt b/vespalib/src/testlist.txt index 5267b19cdfd..e3dd8414e2e 100644 --- a/vespalib/src/testlist.txt +++ b/vespalib/src/testlist.txt @@ -62,8 +62,7 @@ tests/stash tests/stllike tests/stringfmt tests/sync -tests/tensor/compact_tensor_builder -tests/tensor/compact_tensor_v2_builder +tests/tensor/sparse_tensor_builder tests/tensor/dense_tensor_builder tests/tensor/dense_tensor_operations tests/tensor/join_tensor_addresses diff --git a/vespalib/src/tests/tensor/compact_tensor_v2_builder/.gitignore b/vespalib/src/tests/tensor/compact_tensor_v2_builder/.gitignore deleted file mode 100644 index 22edb7555be..00000000000 --- a/vespalib/src/tests/tensor/compact_tensor_v2_builder/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vespalib_compact_tensor_v2_builder_test_app diff --git a/vespalib/src/tests/tensor/compact_tensor_v2_builder/CMakeLists.txt b/vespalib/src/tests/tensor/compact_tensor_v2_builder/CMakeLists.txt deleted file mode 100644 index 2bddcd3f021..00000000000 --- a/vespalib/src/tests/tensor/compact_tensor_v2_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_compact_tensor_v2_builder_test_app TEST - SOURCES - compact_tensor_v2_builder_test.cpp - DEPENDS - vespalib - vespalib_vespalib_tensor -) -vespa_add_test(NAME vespalib_compact_tensor_v2_builder_test_app COMMAND vespalib_compact_tensor_v2_builder_test_app) diff --git a/vespalib/src/tests/tensor/compact_tensor_v2_builder/FILES b/vespalib/src/tests/tensor/compact_tensor_v2_builder/FILES deleted file mode 100644 index 196c68833da..00000000000 --- a/vespalib/src/tests/tensor/compact_tensor_v2_builder/FILES +++ /dev/null @@ -1 +0,0 @@ -compact_tensor_v2_builder_test.cpp diff --git a/vespalib/src/tests/tensor/join_tensor_addresses/join_tensor_addresses_test.cpp b/vespalib/src/tests/tensor/join_tensor_addresses/join_tensor_addresses_test.cpp index f00cd23e322..db1e04d792a 100644 --- a/vespalib/src/tests/tensor/join_tensor_addresses/join_tensor_addresses_test.cpp +++ b/vespalib/src/tests/tensor/join_tensor_addresses/join_tensor_addresses_test.cpp @@ -4,8 +4,8 @@ #include <vespa/vespalib/stllike/hash_set.h> #include <vespa/vespalib/tensor/tensor_address.h> #include <vespa/vespalib/tensor/tensor_address_builder.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_address.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_address_builder.h> +#include <vespa/vespalib/tensor/sparse/compact_tensor_address.h> +#include <vespa/vespalib/tensor/sparse/compact_tensor_address_builder.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> diff --git a/vespalib/src/tests/tensor/sparse_tensor_builder/.gitignore b/vespalib/src/tests/tensor/sparse_tensor_builder/.gitignore new file mode 100644 index 00000000000..e0316d190bb --- /dev/null +++ b/vespalib/src/tests/tensor/sparse_tensor_builder/.gitignore @@ -0,0 +1 @@ +vespalib_sparse_tensor_builder_test_app diff --git a/vespalib/src/tests/tensor/sparse_tensor_builder/CMakeLists.txt b/vespalib/src/tests/tensor/sparse_tensor_builder/CMakeLists.txt new file mode 100644 index 00000000000..c8ae7ece908 --- /dev/null +++ b/vespalib/src/tests/tensor/sparse_tensor_builder/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_sparse_tensor_builder_test_app TEST + SOURCES + sparse_tensor_builder_test.cpp + DEPENDS + vespalib + vespalib_vespalib_tensor +) +vespa_add_test(NAME vespalib_sparse_tensor_builder_test_app COMMAND vespalib_sparse_tensor_builder_test_app) diff --git a/vespalib/src/tests/tensor/sparse_tensor_builder/FILES b/vespalib/src/tests/tensor/sparse_tensor_builder/FILES new file mode 100644 index 00000000000..ad47666278e --- /dev/null +++ b/vespalib/src/tests/tensor/sparse_tensor_builder/FILES @@ -0,0 +1 @@ +sparse_tensor_builder_test.cpp diff --git a/vespalib/src/tests/tensor/compact_tensor_v2_builder/compact_tensor_v2_builder_test.cpp b/vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp index 7dc1e6c1117..69d8a7c3062 100644 --- a/vespalib/src/tests/tensor/compact_tensor_v2_builder/compact_tensor_v2_builder_test.cpp +++ b/vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp @@ -1,7 +1,7 @@ // 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/compact/compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor_builder.h> using namespace vespalib::tensor; @@ -9,9 +9,9 @@ using namespace vespalib::tensor; void assertCellValue(double expValue, const TensorAddress &address, const TensorDimensions &dimensions, - const CompactTensorV2::Cells &cells) + const SparseTensor::Cells &cells) { - CompactTensorV2AddressBuilder addressBuilder; + SparseTensorAddressBuilder addressBuilder; auto dimsItr = dimensions.cbegin(); auto dimsItrEnd = dimensions.cend(); for (const auto &element : address.elements()) { @@ -35,7 +35,7 @@ assertCellValue(double expValue, const TensorAddress &address, TEST("require that tensor can be constructed") { - CompactTensorV2Builder builder; + SparseTensorBuilder builder; builder.define_dimension("c"); builder.define_dimension("d"); builder.define_dimension("a"); @@ -45,9 +45,9 @@ TEST("require that tensor can be constructed") add_label(builder.define_dimension("c"), "3"). add_label(builder.define_dimension("d"), "4").add_cell(20); Tensor::UP tensor = builder.build(); - const CompactTensorV2 &compactTensor = dynamic_cast<const CompactTensorV2 &>(*tensor); - const TensorDimensions &dimensions = compactTensor.dimensions(); - const CompactTensorV2::Cells &cells = compactTensor.cells(); + const SparseTensor &sparseTensor = dynamic_cast<const SparseTensor &>(*tensor); + const TensorDimensions &dimensions = sparseTensor.dimensions(); + const SparseTensor::Cells &cells = sparseTensor.cells(); EXPECT_EQUAL(2u, cells.size()); assertCellValue(10, TensorAddress({{"a","1"},{"b","2"}}), dimensions, cells); @@ -57,7 +57,7 @@ TEST("require that tensor can be constructed") TEST("require that dimensions are extracted") { - CompactTensorV2Builder builder; + SparseTensorBuilder builder; builder.define_dimension("c"); builder.define_dimension("a"); builder.define_dimension("b"); @@ -67,13 +67,13 @@ TEST("require that dimensions are extracted") add_label(builder.define_dimension("b"), "3"). add_label(builder.define_dimension("c"), "4").add_cell(20); Tensor::UP tensor = builder.build(); - const CompactTensorV2 &compactTensor = dynamic_cast<const CompactTensorV2 &>(*tensor); - const TensorDimensions &dims = compactTensor.dimensions(); + const SparseTensor &sparseTensor = dynamic_cast<const SparseTensor &>(*tensor); + const TensorDimensions &dims = sparseTensor.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{})", compactTensor.getType().to_spec()); + EXPECT_EQUAL("tensor(a{},b{},c{})", sparseTensor.getType().to_spec()); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vespalib/src/tests/tensor/tensor_address_element_iterator/tensor_address_element_iterator_test.cpp b/vespalib/src/tests/tensor/tensor_address_element_iterator/tensor_address_element_iterator_test.cpp index 95fe166937d..4e953048f67 100644 --- a/vespalib/src/tests/tensor/tensor_address_element_iterator/tensor_address_element_iterator_test.cpp +++ b/vespalib/src/tests/tensor/tensor_address_element_iterator/tensor_address_element_iterator_test.cpp @@ -4,8 +4,8 @@ #include <vespa/vespalib/stllike/hash_set.h> #include <vespa/vespalib/tensor/tensor_address.h> #include <vespa/vespalib/tensor/tensor_address_builder.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_address.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_address_builder.h> +#include <vespa/vespalib/tensor/sparse/compact_tensor_address.h> +#include <vespa/vespalib/tensor/sparse/compact_tensor_address_builder.h> #include <vespa/vespalib/tensor/tensor_address_element_iterator.h> using namespace vespalib::tensor; 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 41a86e05471..6977a857944 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,8 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stringfmt.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor_builder.h> #include <vespa/vespalib/tensor/dense/dense_tensor.h> #include <vespa/vespalib/tensor/dense/dense_tensor_builder.h> #include <vespa/vespalib/tensor/types.h> @@ -37,8 +37,8 @@ template <typename BuilderType> struct TensorTFromBuilder; template <> -struct TensorTFromBuilder<CompactTensorV2Builder> { - using TensorT = CompactTensorV2; +struct TensorTFromBuilder<SparseTensorBuilder> { + using TensorT = SparseTensor; }; template <typename BuilderType> @@ -116,7 +116,7 @@ struct Fixture : public FixtureBase } }; -using CompactV2Fixture = Fixture<CompactTensorV2Builder>; +using SparseFixture = Fixture<SparseTensorBuilder>; template <typename FixtureType> void @@ -192,7 +192,7 @@ testTensorMapper(FixtureType &f) { "x", "y" })); } -TEST_F("test tensor mapper for CompactTensorV2", CompactV2Fixture) +TEST_F("test tensor mapper for SparseTensor", SparseFixture) { 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 c4c32c41c43..a87c6555e84 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,8 @@ // 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/compact/compact_tensor_v2.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor_builder.h> #include <vespa/vespalib/tensor/types.h> #include <vespa/vespalib/tensor/tensor_factory.h> #include <vespa/vespalib/tensor/tensor_function.h> @@ -217,7 +217,7 @@ struct Fixture } }; -using CompactV2Fixture = Fixture<CompactTensorV2Builder>; +using SparseFixture = Fixture<SparseTensorBuilder>; template <typename FixtureType> @@ -610,7 +610,7 @@ testAllTensorOperations(FixtureType &f) TEST_DO(testTensorSumDimension(f)); } -TEST_F("test tensor operations for CompactTensorV2", CompactV2Fixture) +TEST_F("test tensor operations for SparseTensor", SparseFixture) { 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 aa0ed418a00..ab8acb9e296 100644 --- a/vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp +++ b/vespalib/src/tests/tensor/tensor_performance/tensor_performance_test.cpp @@ -3,8 +3,8 @@ #include <vespa/vespalib/eval/function.h> #include <vespa/vespalib/eval/interpreted_function.h> #include <vespa/vespalib/eval/tensor_nodes.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor.h> +#include <vespa/vespalib/tensor/sparse/sparse_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> @@ -82,7 +82,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); - CompactTensorV2Builder builder; + SparseTensorBuilder builder; for (const auto &cell: tensor->cells()) { for (const auto &dimension: cell.first) { builder.add_label(builder.define_dimension(dimension.first), dimension.second); @@ -222,18 +222,18 @@ tensor::Tensor::UP make_tensor_impl(const std::vector<DimensionSpec> &dimensions //----------------------------------------------------------------------------- -enum class BuilderType { DUMMY, COMPACTV2, NUMBERDUMMY, +enum class BuilderType { DUMMY, SPARSE, NUMBERDUMMY, DENSE }; const BuilderType DUMMY = BuilderType::DUMMY; -const BuilderType COMPACTV2 = BuilderType::COMPACTV2; +const BuilderType SPARSE = BuilderType::SPARSE; const BuilderType NUMBERDUMMY = BuilderType::NUMBERDUMMY; const BuilderType DENSE = BuilderType::DENSE; const char *name(BuilderType type) { switch (type) { case BuilderType::DUMMY: return " dummy"; - case BuilderType::COMPACTV2: return "compactv2"; + case BuilderType::SPARSE: return "sparse"; case BuilderType::NUMBERDUMMY: return "numberdummy"; case BuilderType::DENSE: return "dense"; } @@ -245,8 +245,8 @@ tensor::Tensor::UP make_tensor(BuilderType type, const std::vector<DimensionSpec case BuilderType::DUMMY: return make_tensor_impl<DummyBuilder, TensorBuilder, StringBinding> (dimensions); - case BuilderType::COMPACTV2: - return make_tensor_impl<CompactTensorV2Builder, TensorBuilder, + case BuilderType::SPARSE: + return make_tensor_impl<SparseTensorBuilder, TensorBuilder, StringBinding>(dimensions); case BuilderType::NUMBERDUMMY: return make_tensor_impl<DummyDenseTensorBuilder, @@ -275,7 +275,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: {COMPACTV2, DENSE}) { + for (auto type: {SPARSE, 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); } @@ -284,7 +284,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: {COMPACTV2, DENSE}) { + for (auto type: {SPARSE, 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); } @@ -295,7 +295,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: {COMPACTV2, DENSE}) { + for (auto type: {SPARSE, DENSE}) { Params params; params.add("query", make_tensor(type, {DimensionSpec("x", size)})); params.add("document", make_tensor(type, {DimensionSpec("x", size)})); @@ -307,7 +307,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: {COMPACTV2, DENSE}) { + for (auto type: {SPARSE, DENSE}) { Params params; params.add("query", make_tensor(type, {DimensionSpec("x", size)})); params.add("document", make_tensor(type, {DimensionSpec("x", size)})); @@ -321,7 +321,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: {COMPACTV2}) { + for (auto type: {SPARSE}) { Params params; params.add("query", make_tensor(type, {DimensionSpec("x", vector_size)})); params.add("document", make_tensor(type, {DimensionSpec("y", vector_size)})); @@ -337,7 +337,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: {COMPACTV2, DENSE}) { + for (auto type: {SPARSE, 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 d151d3317f1..d1d713c2987 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,8 @@ // 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/compact/compact_tensor_v2.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor_builder.h> #include <vespa/vespalib/tensor/types.h> #include <vespa/vespalib/tensor/default_tensor.h> #include <vespa/vespalib/tensor/tensor_factory.h> @@ -97,7 +97,7 @@ struct Fixture } }; -using CompactV2Fixture = Fixture<CompactTensorV2Builder>; +using SparseFixture = Fixture<SparseTensorBuilder>; template <typename FixtureType> @@ -134,7 +134,7 @@ testTensorSerialization(FixtureType &f) { {{{"x","1"}}, 3} }, {"x", "y"})); } -TEST_F("test tensor serialization for CompactTensorV2", CompactV2Fixture) +TEST_F("test tensor serialization for SparseTensor", SparseFixture) { 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 2de327e18a7..f3005a21730 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,8 @@ // 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/compact/compact_tensor_v2.h> -#include <vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor.h> +#include <vespa/vespalib/tensor/sparse/sparse_tensor_builder.h> #include <vespa/vespalib/tensor/types.h> #include <vespa/vespalib/tensor/default_tensor.h> #include <vespa/vespalib/tensor/tensor_factory.h> @@ -42,10 +42,10 @@ struct Fixture template <> uint32_t -Fixture<CompactTensorV2Builder>::getTensorTypeId() { return 2u; } +Fixture<SparseTensorBuilder>::getTensorTypeId() { return 2u; } -using CompactV2Fixture = Fixture<CompactTensorV2Builder>; +using SparseFixture = Fixture<SparseTensorBuilder>; namespace { @@ -114,7 +114,7 @@ testTensorSlimeSerialization(FixtureType &f) {"x", "y"})); } -TEST_F("test tensor slime serialization for CompactTensorV2", CompactV2Fixture) +TEST_F("test tensor slime serialization for SparseTensor", SparseFixture) { testTensorSlimeSerialization(f); } diff --git a/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt b/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt index 388885b6e50..ec610f2527c 100644 --- a/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/tensor/CMakeLists.txt @@ -8,7 +8,7 @@ vespa_add_library(vespalib_vespalib_tensor tensor_factory.cpp tensor_function.cpp tensor_mapper.cpp - $<TARGET_OBJECTS:vespalib_vespalib_tensor_compact> + $<TARGET_OBJECTS:vespalib_vespalib_tensor_sparse> $<TARGET_OBJECTS:vespalib_vespalib_tensor_dense> $<TARGET_OBJECTS:vespalib_vespalib_tensor_serialization> INSTALL lib64 diff --git a/vespalib/src/vespa/vespalib/tensor/default_tensor.h b/vespalib/src/vespa/vespalib/tensor/default_tensor.h index 61c564e4943..2423e677eff 100644 --- a/vespalib/src/vespa/vespalib/tensor/default_tensor.h +++ b/vespalib/src/vespa/vespalib/tensor/default_tensor.h @@ -2,15 +2,15 @@ #pragma once -#include "compact/compact_tensor_v2.h" -#include "compact/compact_tensor_v2_builder.h" +#include "sparse/sparse_tensor.h" +#include "sparse/sparse_tensor_builder.h" namespace vespalib { namespace tensor { struct DefaultTensor { - using type = CompactTensorV2; - using builder = CompactTensorV2Builder; + using type = SparseTensor; + using builder = SparseTensorBuilder; }; } // namespace vespalib::tensor diff --git a/vespalib/src/vespa/vespalib/tensor/serialization/CMakeLists.txt b/vespalib/src/vespa/vespalib/tensor/serialization/CMakeLists.txt index 246e1b17535..1f178dd7118 100644 --- a/vespalib/src/vespa/vespalib/tensor/serialization/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/tensor/serialization/CMakeLists.txt @@ -1,7 +1,7 @@ # 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_serialization OBJECT SOURCES - compact_binary_format.cpp + sparse_binary_format.cpp dense_binary_format.cpp slime_binary_format.cpp typed_binary_format.cpp diff --git a/vespalib/src/vespa/vespalib/tensor/serialization/compact_binary_format.cpp b/vespalib/src/vespa/vespalib/tensor/serialization/sparse_binary_format.cpp index 48b5cb971d6..af7a92d2c68 100644 --- a/vespalib/src/vespa/vespalib/tensor/serialization/compact_binary_format.cpp +++ b/vespalib/src/vespa/vespalib/tensor/serialization/sparse_binary_format.cpp @@ -1,7 +1,7 @@ // 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 "compact_binary_format.h" +#include "sparse_binary_format.h" #include <vespa/vespalib/tensor/types.h> #include <vespa/vespalib/tensor/tensor.h> #include <vespa/vespalib/tensor/tensor_builder.h> @@ -40,20 +40,20 @@ writeTensorAddress(nbostream &output, } -class CompactBinaryFormatSerializer : public TensorVisitor +class SparseBinaryFormatSerializer : public TensorVisitor { uint32_t _numCells; nbostream _cells; eval::ValueType _type; public: - CompactBinaryFormatSerializer(); - virtual ~CompactBinaryFormatSerializer() override; + SparseBinaryFormatSerializer(); + virtual ~SparseBinaryFormatSerializer() override; virtual void visit(const TensorAddress &address, double value) override; void serialize(nbostream &stream, const Tensor &tensor); }; -CompactBinaryFormatSerializer::CompactBinaryFormatSerializer() +SparseBinaryFormatSerializer::SparseBinaryFormatSerializer() : _numCells(0u), _cells(), _type(eval::ValueType::error_type()) @@ -61,12 +61,12 @@ CompactBinaryFormatSerializer::CompactBinaryFormatSerializer() } -CompactBinaryFormatSerializer::~CompactBinaryFormatSerializer() +SparseBinaryFormatSerializer::~SparseBinaryFormatSerializer() { } void -CompactBinaryFormatSerializer::visit(const TensorAddress &address, +SparseBinaryFormatSerializer::visit(const TensorAddress &address, double value) { ++_numCells; @@ -76,7 +76,7 @@ CompactBinaryFormatSerializer::visit(const TensorAddress &address, void -CompactBinaryFormatSerializer::serialize(nbostream &stream, +SparseBinaryFormatSerializer::serialize(nbostream &stream, const Tensor &tensor) { _type = tensor.getType(); @@ -91,15 +91,15 @@ CompactBinaryFormatSerializer::serialize(nbostream &stream, void -CompactBinaryFormat::serialize(nbostream &stream, const Tensor &tensor) +SparseBinaryFormat::serialize(nbostream &stream, const Tensor &tensor) { - CompactBinaryFormatSerializer serializer; + SparseBinaryFormatSerializer serializer; serializer.serialize(stream, tensor); } void -CompactBinaryFormat::deserialize(nbostream &stream, TensorBuilder &builder) +SparseBinaryFormat::deserialize(nbostream &stream, TensorBuilder &builder) { vespalib::string str; size_t dimensionsSize = stream.getInt1_4Bytes(); diff --git a/vespalib/src/vespa/vespalib/tensor/serialization/compact_binary_format.h b/vespalib/src/vespa/vespalib/tensor/serialization/sparse_binary_format.h index fd3abdc2b71..6102c13130e 100644 --- a/vespalib/src/vespa/vespalib/tensor/serialization/compact_binary_format.h +++ b/vespalib/src/vespa/vespalib/tensor/serialization/sparse_binary_format.h @@ -14,7 +14,7 @@ class TensorBuilder; /** * Class for serializing a tensor. */ -class CompactBinaryFormat +class SparseBinaryFormat { public: static void serialize(nbostream &stream, const Tensor &tensor); diff --git a/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.cpp b/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.cpp index d3d0ae40545..c282a20fe6e 100644 --- a/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.cpp +++ b/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.cpp @@ -2,7 +2,7 @@ #include <vespa/fastos/fastos.h> #include "typed_binary_format.h" -#include "compact_binary_format.h" +#include "sparse_binary_format.h" #include "dense_binary_format.h" #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/tensor/default_tensor.h> @@ -23,8 +23,8 @@ TypedBinaryFormat::serialize(nbostream &stream, const Tensor &tensor) stream.putInt1_4Bytes(DENSE_BINARY_FORMAT_TYPE); DenseBinaryFormat::serialize(stream, *denseTensor); } else { - stream.putInt1_4Bytes(COMPACT_BINARY_FORMAT_TYPE); - CompactBinaryFormat::serialize(stream, tensor); + stream.putInt1_4Bytes(SPARSE_BINARY_FORMAT_TYPE); + SparseBinaryFormat::serialize(stream, tensor); } } @@ -33,8 +33,8 @@ void TypedBinaryFormat::deserialize(nbostream &stream, TensorBuilder &builder) { auto formatId = stream.getInt1_4Bytes(); - assert(formatId == COMPACT_BINARY_FORMAT_TYPE); - CompactBinaryFormat::deserialize(stream, builder); + assert(formatId == SPARSE_BINARY_FORMAT_TYPE); + SparseBinaryFormat::deserialize(stream, builder); } @@ -42,9 +42,9 @@ std::unique_ptr<Tensor> TypedBinaryFormat::deserialize(nbostream &stream) { auto formatId = stream.getInt1_4Bytes(); - if (formatId == COMPACT_BINARY_FORMAT_TYPE) { + if (formatId == SPARSE_BINARY_FORMAT_TYPE) { DefaultTensor::builder builder; - CompactBinaryFormat::deserialize(stream, builder); + SparseBinaryFormat::deserialize(stream, builder); return builder.build(); } if (formatId == DENSE_BINARY_FORMAT_TYPE) { diff --git a/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.h b/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.h index 31bd12ddfc0..45cba6018d4 100644 --- a/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.h +++ b/vespalib/src/vespa/vespalib/tensor/serialization/typed_binary_format.h @@ -16,7 +16,7 @@ class TensorBuilder; */ class TypedBinaryFormat { - static constexpr uint32_t COMPACT_BINARY_FORMAT_TYPE = 1u; + static constexpr uint32_t SPARSE_BINARY_FORMAT_TYPE = 1u; static constexpr uint32_t DENSE_BINARY_FORMAT_TYPE = 2u; public: static void serialize(nbostream &stream, const Tensor &tensor); diff --git a/vespalib/src/vespa/vespalib/tensor/compact/CMakeLists.txt b/vespalib/src/vespa/vespalib/tensor/sparse/CMakeLists.txt index 77ddd2a0a94..aa2cc7869e5 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/CMakeLists.txt +++ b/vespalib/src/vespa/vespalib/tensor/sparse/CMakeLists.txt @@ -1,13 +1,13 @@ # 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_compact OBJECT +vespa_add_library(vespalib_vespalib_tensor_sparse OBJECT SOURCES - compact_tensor_v2.cpp - compact_tensor_v2_dimension_sum.cpp - compact_tensor_v2_match.cpp - compact_tensor_v2_product.cpp + sparse_tensor.cpp + sparse_tensor_dimension_sum.cpp + sparse_tensor_match.cpp + sparse_tensor_product.cpp compact_tensor_address.cpp compact_tensor_address_builder.cpp - compact_tensor_v2_builder.cpp + sparse_tensor_builder.cpp compact_tensor_unsorted_address_builder.cpp DEPENDS ) diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address.cpp index e3cada25285..97415e81e29 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address.cpp @@ -2,7 +2,7 @@ #include <vespa/fastos/fastos.h> #include "compact_tensor_address.h" -#include "compact_tensor_v2_address_decoder.h" +#include "sparse_tensor_address_decoder.h" #include <algorithm> namespace vespalib { @@ -93,7 +93,7 @@ CompactTensorAddress::deserializeFromAddressRefV2(CompactTensorAddressRef ref, dimensions) { _elements.clear(); - CompactTensorV2AddressDecoder addr(ref); + SparseTensorAddressDecoder addr(ref); for (auto &dim : dimensions) { auto label = addr.decodeLabel(); if (label.size() != 0u) { diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address.h b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address.h index 509c267323c..509c267323c 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address.h diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address_builder.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address_builder.cpp index 03f2ec0fd15..03f2ec0fd15 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address_builder.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address_builder.cpp diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address_builder.h b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address_builder.h index 2981352eef5..2981352eef5 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address_builder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address_builder.h diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address_ref.h b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address_ref.h index fa49e2fd39c..fa49e2fd39c 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_address_ref.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_address_ref.h diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_unsorted_address_builder.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_unsorted_address_builder.cpp index a88cd40afc2..1496ed0e5d5 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_unsorted_address_builder.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_unsorted_address_builder.cpp @@ -3,7 +3,7 @@ #include <vespa/fastos/fastos.h> #include "compact_tensor_unsorted_address_builder.h" #include "compact_tensor_address_builder.h" -#include "compact_tensor_v2_address_builder.h" +#include "sparse_tensor_address_builder.h" #include <algorithm> namespace vespalib { @@ -31,7 +31,7 @@ CompactTensorUnsortedAddressBuilder::buildTo(CompactTensorAddressBuilder & } void -CompactTensorUnsortedAddressBuilder::buildTo(CompactTensorV2AddressBuilder & +CompactTensorUnsortedAddressBuilder::buildTo(SparseTensorAddressBuilder & builder, const TensorDimensions & dimensions) diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_unsorted_address_builder.h b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_unsorted_address_builder.h index a3c9b4d8ca0..1ee7ccf0b60 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_unsorted_address_builder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/compact_tensor_unsorted_address_builder.h @@ -10,7 +10,7 @@ namespace vespalib { namespace tensor { class CompactTensorAddressBuilder; -class CompactTensorV2AddressBuilder; +class SparseTensorAddressBuilder; /** * A builder that buffers up a tensor address with unsorted @@ -73,7 +73,7 @@ public: * tensor address builder in sorted order. */ void buildTo(CompactTensorAddressBuilder &builder); - void buildTo(CompactTensorV2AddressBuilder &builder, + void buildTo(SparseTensorAddressBuilder &builder, const TensorDimensions &dimensions); void clear() { _elementStrings.clear(); _elements.clear(); } }; diff --git a/vespalib/src/vespa/vespalib/tensor/compact/direct_compact_tensor_v2_builder.h b/vespalib/src/vespa/vespalib/tensor/sparse/direct_sparse_tensor_builder.h index 6864895547a..5e51a750fc2 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/direct_compact_tensor_v2_builder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/direct_sparse_tensor_builder.h @@ -3,24 +3,24 @@ #pragma once #include <vespa/vespalib/tensor/direct_tensor_builder.h> -#include "compact_tensor_v2.h" -#include "compact_tensor_v2_address_builder.h" -#include "compact_tensor_v2_address_padder.h" +#include "sparse_tensor.h" +#include "sparse_tensor_address_builder.h" +#include "sparse_tensor_address_padder.h" namespace vespalib { namespace tensor { /** - * Utility class to build tensors of type CompactTensorV2, to be used by + * Utility class to build tensors of type SparseTensor, to be used by * tensor operations. */ -template <> class DirectTensorBuilder<CompactTensorV2> +template <> class DirectTensorBuilder<SparseTensor> { public: - using TensorImplType = CompactTensorV2; + using TensorImplType = SparseTensor; using Dimensions = typename TensorImplType::Dimensions; using Cells = typename TensorImplType::Cells; - using AddressBuilderType = CompactTensorV2AddressBuilder; + using AddressBuilderType = SparseTensorAddressBuilder; using AddressRefType = CompactTensorAddressRef; using AddressType = CompactTensorAddress; @@ -43,7 +43,7 @@ public: void copyCells(const Cells &cells_in, const Dimensions &cells_in_dimensions) { - CompactTensorV2AddressPadder addressPadder(_dimensions, + SparseTensorAddressPadder addressPadder(_dimensions, cells_in_dimensions); for (const auto &cell : cells_in) { addressPadder.padAddress(cell.first); @@ -91,7 +91,7 @@ public: } Tensor::UP build() { - return std::make_unique<CompactTensorV2>(std::move(_dimensions), + return std::make_unique<SparseTensor>(std::move(_dimensions), std::move(_cells), std::move(_stash)); } @@ -116,13 +116,13 @@ public: } template <class Function> - void insertCell(CompactTensorV2AddressBuilder &address, double value, + void insertCell(SparseTensorAddressBuilder &address, double value, Function &&func) { insertCell(address.getAddressRef(), value, func); } - void insertCell(CompactTensorV2AddressBuilder &address, double value) { + void insertCell(SparseTensorAddressBuilder &address, double value) { // This address should not already exist and a new cell should be inserted. insertCell(address.getAddressRef(), value, [](double, double) -> double { abort(); }); } diff --git a/vespalib/src/vespa/vespalib/tensor/compact/join_compact_tensors_v2.h b/vespalib/src/vespa/vespalib/tensor/sparse/join_sparse_tensors.h index 0fd89c4ec7b..e17f1812533 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/join_compact_tensors_v2.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/join_sparse_tensors.h @@ -11,17 +11,17 @@ namespace tensor { */ template <typename Function> Tensor::UP -joinCompactTensorsV2(const CompactTensorV2 &lhs, const CompactTensorV2 &rhs, +joinSparseTensors(const SparseTensor &lhs, const SparseTensor &rhs, Function &&func) { - DirectTensorBuilder<CompactTensorV2> builder(lhs.combineDimensionsWith(rhs), + DirectTensorBuilder<SparseTensor> builder(lhs.combineDimensionsWith(rhs), lhs.cells(), lhs.dimensions()); if (builder.dimensions().size() == rhs.dimensions().size()) { for (const auto &rhsCell : rhs.cells()) { builder.insertCell(rhsCell.first, rhsCell.second, func); } } else { - CompactTensorV2AddressPadder addressPadder(builder.dimensions(), + SparseTensorAddressPadder addressPadder(builder.dimensions(), rhs.dimensions()); for (const auto &rhsCell : rhs.cells()) { addressPadder.padAddress(rhsCell.first); @@ -37,18 +37,18 @@ joinCompactTensorsV2(const CompactTensorV2 &lhs, const CompactTensorV2 &rhs, */ template <typename Function> Tensor::UP -joinCompactTensorsV2Negated(const CompactTensorV2 &lhs, - const CompactTensorV2 &rhs, +joinSparseTensorsNegated(const SparseTensor &lhs, + const SparseTensor &rhs, Function &&func) { - DirectTensorBuilder<CompactTensorV2> builder(lhs.combineDimensionsWith(rhs), + DirectTensorBuilder<SparseTensor> builder(lhs.combineDimensionsWith(rhs), lhs.cells(), lhs.dimensions()); if (builder.dimensions().size() == rhs.dimensions().size()) { for (const auto &rhsCell : rhs.cells()) { builder.insertCell(rhsCell.first, -rhsCell.second, func); } } else { - CompactTensorV2AddressPadder addressPadder(builder.dimensions(), + SparseTensorAddressPadder addressPadder(builder.dimensions(), rhs.dimensions()); for (const auto &rhsCell : rhs.cells()) { addressPadder.padAddress(rhsCell.first); diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp index fdff22e9525..7f833bf0bce 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp @@ -1,12 +1,12 @@ // 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 "compact_tensor_v2.h" -#include "compact_tensor_v2_address_builder.h" -#include "compact_tensor_v2_dimension_sum.h" -#include "compact_tensor_v2_match.h" -#include "compact_tensor_v2_product.h" -#include "join_compact_tensors_v2.h" +#include "sparse_tensor.h" +#include "sparse_tensor_address_builder.h" +#include "sparse_tensor_dimension_sum.h" +#include "sparse_tensor_match.h" +#include "sparse_tensor_product.h" +#include "join_sparse_tensors.h" #include <vespa/vespalib/tensor/tensor_address_builder.h> #include <vespa/vespalib/tensor/tensor_apply.h> #include <vespa/vespalib/tensor/tensor_visitor.h> @@ -18,7 +18,7 @@ namespace tensor { namespace { -using Cells = CompactTensorV2::Cells; +using Cells = SparseTensor::Cells; void copyCells(Cells &cells, const Cells &cells_in, Stash &stash) @@ -32,7 +32,7 @@ copyCells(Cells &cells, const Cells &cells_in, Stash &stash) } -CompactTensorV2::CompactTensorV2(const Dimensions &dimensions_in, +SparseTensor::SparseTensor(const Dimensions &dimensions_in, const Cells &cells_in) : _cells(), _dimensions(dimensions_in), @@ -42,7 +42,7 @@ CompactTensorV2::CompactTensorV2(const Dimensions &dimensions_in, } -CompactTensorV2::CompactTensorV2(Dimensions &&dimensions_in, +SparseTensor::SparseTensor(Dimensions &&dimensions_in, Cells &&cells_in, Stash &&stash_in) : _cells(std::move(cells_in)), _dimensions(std::move(dimensions_in)), @@ -52,14 +52,14 @@ CompactTensorV2::CompactTensorV2(Dimensions &&dimensions_in, bool -CompactTensorV2::operator==(const CompactTensorV2 &rhs) const +SparseTensor::operator==(const SparseTensor &rhs) const { return _dimensions == rhs._dimensions && _cells == rhs._cells; } -CompactTensorV2::Dimensions -CompactTensorV2::combineDimensionsWith(const CompactTensorV2 &rhs) const +SparseTensor::Dimensions +SparseTensor::combineDimensionsWith(const SparseTensor &rhs) const { Dimensions result; std::set_union(_dimensions.cbegin(), _dimensions.cend(), @@ -69,7 +69,7 @@ CompactTensorV2::combineDimensionsWith(const CompactTensorV2 &rhs) const } eval::ValueType -CompactTensorV2::getType() const +SparseTensor::getType() const { if (_dimensions.empty()) { return eval::ValueType::double_type(); @@ -80,7 +80,7 @@ CompactTensorV2::getType() const } double -CompactTensorV2::sum() const +SparseTensor::sum() const { double result = 0.0; for (const auto &cell : _cells) { @@ -90,86 +90,86 @@ CompactTensorV2::sum() const } Tensor::UP -CompactTensorV2::add(const Tensor &arg) const +SparseTensor::add(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return Tensor::UP(); } - return joinCompactTensorsV2(*this, *rhs, + return joinSparseTensors(*this, *rhs, [](double lhsValue, double rhsValue) { return lhsValue + rhsValue; }); } Tensor::UP -CompactTensorV2::subtract(const Tensor &arg) const +SparseTensor::subtract(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return Tensor::UP(); } // Note that -rhsCell.second is passed to the lambda function, that is why we do addition. - return joinCompactTensorsV2Negated(*this, *rhs, + return joinSparseTensorsNegated(*this, *rhs, [](double lhsValue, double rhsValue) { return lhsValue + rhsValue; }); } Tensor::UP -CompactTensorV2::multiply(const Tensor &arg) const +SparseTensor::multiply(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return Tensor::UP(); } - return CompactTensorV2Product(*this, *rhs).result(); + return SparseTensorProduct(*this, *rhs).result(); } Tensor::UP -CompactTensorV2::min(const Tensor &arg) const +SparseTensor::min(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return Tensor::UP(); } - return joinCompactTensorsV2(*this, *rhs, + return joinSparseTensors(*this, *rhs, [](double lhsValue, double rhsValue) { return std::min(lhsValue, rhsValue); }); } Tensor::UP -CompactTensorV2::max(const Tensor &arg) const +SparseTensor::max(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return Tensor::UP(); } - return joinCompactTensorsV2(*this, *rhs, + return joinSparseTensors(*this, *rhs, [](double lhsValue, double rhsValue) { return std::max(lhsValue, rhsValue); }); } Tensor::UP -CompactTensorV2::match(const Tensor &arg) const +SparseTensor::match(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return Tensor::UP(); } - return CompactTensorV2Match(*this, *rhs).result(); + return SparseTensorMatch(*this, *rhs).result(); } Tensor::UP -CompactTensorV2::apply(const CellFunction &func) const +SparseTensor::apply(const CellFunction &func) const { - return TensorApply<CompactTensorV2>(*this, func).result(); + return TensorApply<SparseTensor>(*this, func).result(); } Tensor::UP -CompactTensorV2::sum(const vespalib::string &dimension) const +SparseTensor::sum(const vespalib::string &dimension) const { - return CompactTensorV2DimensionSum(*this, dimension).result(); + return SparseTensorDimensionSum(*this, dimension).result(); } bool -CompactTensorV2::equals(const Tensor &arg) const +SparseTensor::equals(const Tensor &arg) const { - const CompactTensorV2 *rhs = dynamic_cast<const CompactTensorV2 *>(&arg); + const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); if (!rhs) { return false; } @@ -177,7 +177,7 @@ CompactTensorV2::equals(const Tensor &arg) const } vespalib::string -CompactTensorV2::toString() const +SparseTensor::toString() const { std::ostringstream stream; stream << *this; @@ -185,13 +185,13 @@ CompactTensorV2::toString() const } Tensor::UP -CompactTensorV2::clone() const +SparseTensor::clone() const { - return std::make_unique<CompactTensorV2>(_dimensions, _cells); + return std::make_unique<SparseTensor>(_dimensions, _cells); } void -CompactTensorV2::print(std::ostream &out) const +SparseTensor::print(std::ostream &out) const { out << "{ "; bool first = true; @@ -208,12 +208,12 @@ CompactTensorV2::print(std::ostream &out) const } void -CompactTensorV2::accept(TensorVisitor &visitor) const +SparseTensor::accept(TensorVisitor &visitor) const { TensorAddressBuilder addrBuilder; TensorAddress addr; for (const auto &cell : _cells) { - CompactTensorV2AddressDecoder decoder(cell.first); + SparseTensorAddressDecoder decoder(cell.first); addrBuilder.clear(); for (const auto &dimension : _dimensions) { auto label = decoder.decodeLabel(); diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.h index d7a3f3e4e5c..8427e51ffd1 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.h @@ -19,7 +19,7 @@ namespace tensor { * improve CPU cache and TLB hit ratio, relative to SimpleTensor * implementation. */ -class CompactTensorV2 : public Tensor +class SparseTensor : public Tensor { public: typedef vespalib::hash_map<CompactTensorAddressRef, double> Cells; @@ -33,14 +33,14 @@ private: Stash _stash; public: - explicit CompactTensorV2(const Dimensions &dimensions_in, + explicit SparseTensor(const Dimensions &dimensions_in, const Cells &cells_in); - CompactTensorV2(Dimensions &&dimensions_in, + SparseTensor(Dimensions &&dimensions_in, Cells &&cells_in, Stash &&stash_in); const Cells &cells() const { return _cells; } const Dimensions &dimensions() const { return _dimensions; } - bool operator==(const CompactTensorV2 &rhs) const; - Dimensions combineDimensionsWith(const CompactTensorV2 &rhs) const; + bool operator==(const SparseTensor &rhs) const; + Dimensions combineDimensionsWith(const SparseTensor &rhs) const; virtual eval::ValueType getType() const override; virtual double sum() const override; diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_address_builder.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_builder.h index a029d84433f..239b405fe4c 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_address_builder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_builder.h @@ -19,7 +19,7 @@ class CompactTensorAddress; * * Format: (labelStr NUL)* */ -class CompactTensorV2AddressBuilder +class SparseTensorAddressBuilder { private: std::vector<char> _address; @@ -31,7 +31,7 @@ private: _address.insert(_address.end(), cstr, cstr + str.size() + 1); } public: - CompactTensorV2AddressBuilder() + SparseTensorAddressBuilder() : _address() { } diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_address_decoder.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_decoder.h index 3d22ad69b6f..bac864b53f3 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_address_decoder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_decoder.h @@ -13,12 +13,12 @@ namespace tensor { /** * A decoder for a serialized tensor address, with only labels present. */ -class CompactTensorV2AddressDecoder +class SparseTensorAddressDecoder { const char *_cur; const char *_end; public: - CompactTensorV2AddressDecoder(CompactTensorAddressRef ref) + SparseTensorAddressDecoder(CompactTensorAddressRef ref) : _cur(static_cast<const char *>(ref.start())), _end(_cur + ref.size()) { diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_address_padder.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_padder.h index 9ab2c8833ba..5de4bd00404 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_address_padder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_padder.h @@ -2,18 +2,18 @@ #pragma once -#include "compact_tensor_v2_address_builder.h" -#include "compact_tensor_v2_address_decoder.h" +#include "sparse_tensor_address_builder.h" +#include "sparse_tensor_address_decoder.h" namespace vespalib { namespace tensor { /** - * This class transforms serialized compact tensor v2 addresses by padding + * This class transforms serialized sparse tensor addresses by padding * in "undefined" labels for new dimensions. */ -class CompactTensorV2AddressPadder : public CompactTensorV2AddressBuilder +class SparseTensorAddressPadder : public SparseTensorAddressBuilder { enum class PadOp { @@ -24,9 +24,9 @@ class CompactTensorV2AddressPadder : public CompactTensorV2AddressBuilder std::vector<PadOp> _padOps; public: - CompactTensorV2AddressPadder(const TensorDimensions &resultDims, + SparseTensorAddressPadder(const TensorDimensions &resultDims, const TensorDimensions &inputDims) - : CompactTensorV2AddressBuilder(), + : SparseTensorAddressBuilder(), _padOps() { auto resultDimsItr = resultDims.cbegin(); @@ -50,7 +50,7 @@ public: padAddress(CompactTensorAddressRef ref) { clear(); - CompactTensorV2AddressDecoder addr(ref); + SparseTensorAddressDecoder addr(ref); for (auto op : _padOps) { switch (op) { case PadOp::PAD: diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_builder.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.cpp index 379943f10eb..a16774707b4 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_builder.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.cpp @@ -1,30 +1,30 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "compact_tensor_v2_builder.h" +#include "sparse_tensor_builder.h" #include <vespa/vespalib/tensor/tensor.h> namespace vespalib { namespace tensor { -CompactTensorV2Builder::CompactTensorV2Builder() +SparseTensorBuilder::SparseTensorBuilder() : TensorBuilder(), _addressBuilder(), _normalizedAddressBuilder(), _cells(), - _stash(CompactTensorV2::STASH_CHUNK_SIZE), + _stash(SparseTensor::STASH_CHUNK_SIZE), _dimensionsEnum(), _dimensions(), _sortedDimensions() { } -CompactTensorV2Builder::~CompactTensorV2Builder() +SparseTensorBuilder::~SparseTensorBuilder() { } void -CompactTensorV2Builder::makeSortedDimensions() +SparseTensorBuilder::makeSortedDimensions() { assert(_sortedDimensions.empty()); assert(_cells.empty()); @@ -34,7 +34,7 @@ CompactTensorV2Builder::makeSortedDimensions() TensorBuilder::Dimension -CompactTensorV2Builder::define_dimension(const vespalib::string &dimension) +SparseTensorBuilder::define_dimension(const vespalib::string &dimension) { auto it = _dimensionsEnum.find(dimension); if (it != _dimensionsEnum.end()) { @@ -50,7 +50,7 @@ CompactTensorV2Builder::define_dimension(const vespalib::string &dimension) } TensorBuilder & -CompactTensorV2Builder::add_label(Dimension dimension, +SparseTensorBuilder::add_label(Dimension dimension, const vespalib::string &label) { assert(dimension <= _dimensions.size()); @@ -59,14 +59,14 @@ CompactTensorV2Builder::add_label(Dimension dimension, } TensorBuilder & -CompactTensorV2Builder::add_cell(double value) +SparseTensorBuilder::add_cell(double value) { if (_dimensions.size() != _sortedDimensions.size()) { makeSortedDimensions(); } _addressBuilder.buildTo(_normalizedAddressBuilder, _sortedDimensions); CompactTensorAddressRef taddress(_normalizedAddressBuilder.getAddressRef()); - // Make a persistent copy of compact tensor address owned by _stash + // Make a persistent copy of sparse tensor address owned by _stash CompactTensorAddressRef address(taddress, _stash); _cells[address] = value; _addressBuilder.clear(); @@ -76,18 +76,18 @@ CompactTensorV2Builder::add_cell(double value) Tensor::UP -CompactTensorV2Builder::build() +SparseTensorBuilder::build() { assert(_addressBuilder.empty()); if (_dimensions.size() != _sortedDimensions.size()) { makeSortedDimensions(); } - CompactTensorV2::Dimensions dimensions(_sortedDimensions.begin(), + SparseTensor::Dimensions dimensions(_sortedDimensions.begin(), _sortedDimensions.end()); - Tensor::UP ret = std::make_unique<CompactTensorV2>(std::move(dimensions), + Tensor::UP ret = std::make_unique<SparseTensor>(std::move(dimensions), std::move(_cells), std::move(_stash)); - CompactTensorV2::Cells().swap(_cells); + SparseTensor::Cells().swap(_cells); _dimensionsEnum.clear(); _dimensions.clear(); _sortedDimensions.clear(); diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.h index a206d882f32..c7a7e8a5a9e 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_builder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.h @@ -2,8 +2,8 @@ #pragma once -#include "compact_tensor_v2.h" -#include "compact_tensor_v2_address_builder.h" +#include "sparse_tensor.h" +#include "sparse_tensor_address_builder.h" #include "compact_tensor_unsorted_address_builder.h" #include <vespa/vespalib/tensor/tensor_builder.h> #include <vespa/vespalib/tensor/tensor_address.h> @@ -14,13 +14,13 @@ namespace vespalib { namespace tensor { /** - * A builder of compact tensors. + * A builder of sparse tensors. */ -class CompactTensorV2Builder : public TensorBuilder +class SparseTensorBuilder : public TensorBuilder { CompactTensorUnsortedAddressBuilder _addressBuilder; // unsorted dimensions - CompactTensorV2AddressBuilder _normalizedAddressBuilder; // sorted dimensions - CompactTensorV2::Cells _cells; + SparseTensorAddressBuilder _normalizedAddressBuilder; // sorted dimensions + SparseTensor::Cells _cells; Stash _stash; vespalib::hash_map<vespalib::string, uint32_t> _dimensionsEnum; std::vector<vespalib::string> _dimensions; @@ -28,8 +28,8 @@ class CompactTensorV2Builder : public TensorBuilder void makeSortedDimensions(); public: - CompactTensorV2Builder(); - virtual ~CompactTensorV2Builder(); + SparseTensorBuilder(); + virtual ~SparseTensorBuilder(); virtual Dimension define_dimension(const vespalib::string &dimension) override; diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_dimension_sum.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_dimension_sum.cpp index d76078ba52e..54c8d9b175a 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_dimension_sum.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_dimension_sum.cpp @@ -1,8 +1,8 @@ // 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 "compact_tensor_v2_dimension_sum.h" -#include "compact_tensor_v2_address_decoder.h" +#include "sparse_tensor_dimension_sum.h" +#include "sparse_tensor_address_decoder.h" namespace vespalib { namespace tensor { @@ -35,12 +35,12 @@ buildReduceOps(const TensorDimensions &dims, void -reduceAddress(CompactTensorV2AddressBuilder &builder, +reduceAddress(SparseTensorAddressBuilder &builder, CompactTensorAddressRef ref, const ReduceOps &ops) { builder.clear(); - CompactTensorV2AddressDecoder addr(ref); + SparseTensorAddressDecoder addr(ref); for (auto op : ops) { switch (op) { case AddressOp::REMOVE: @@ -68,7 +68,7 @@ removeDimension(const TensorDimensions &dimensions, } -CompactTensorV2DimensionSum::CompactTensorV2DimensionSum(const TensorImplType & +SparseTensorDimensionSum::SparseTensorDimensionSum(const TensorImplType & tensor, const vespalib::string & diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_dimension_sum.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_dimension_sum.h index 959135ce91c..f88239834e9 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_dimension_sum.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_dimension_sum.h @@ -10,15 +10,15 @@ namespace tensor { /** * Returns a tensor with the given dimension removed and the cell values in that dimension summed. */ -class CompactTensorV2DimensionSum : public TensorOperation<CompactTensorV2> +class SparseTensorDimensionSum : public TensorOperation<SparseTensor> { public: - using TensorImplType = CompactTensorV2; - using Parent = TensorOperation<CompactTensorV2>; + using TensorImplType = SparseTensor; + using Parent = TensorOperation<SparseTensor>; using AddressBuilderType = typename Parent::AddressBuilderType; using AddressType = typename Parent::AddressType; using Parent::_builder; - CompactTensorV2DimensionSum(const TensorImplType &tensor, + SparseTensorDimensionSum(const TensorImplType &tensor, const vespalib::string &dimension); }; diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_match.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_match.cpp index c8044a5f828..27cede44ff4 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_match.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_match.cpp @@ -1,8 +1,8 @@ // 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 "compact_tensor_v2_match.h" -#include "compact_tensor_v2_address_decoder.h" +#include "sparse_tensor_match.h" +#include "sparse_tensor_address_decoder.h" namespace vespalib { namespace tensor { @@ -44,12 +44,12 @@ buildTransformOps(std::vector<AddressOp> &ops, bool -transformAddress(CompactTensorV2AddressBuilder &builder, +transformAddress(SparseTensorAddressBuilder &builder, CompactTensorAddressRef ref, const std::vector<AddressOp> &ops) { builder.clear(); - CompactTensorV2AddressDecoder addr(ref); + SparseTensorAddressDecoder addr(ref); for (auto op : ops) { switch (op) { case AddressOp::REMOVE: @@ -75,7 +75,7 @@ transformAddress(CompactTensorV2AddressBuilder &builder, void -CompactTensorV2Match::fastMatch(const TensorImplType &lhs, +SparseTensorMatch::fastMatch(const TensorImplType &lhs, const TensorImplType &rhs) { for (const auto &lhsCell : lhs.cells()) { @@ -87,12 +87,12 @@ CompactTensorV2Match::fastMatch(const TensorImplType &lhs, } void -CompactTensorV2Match::slowMatch(const TensorImplType &lhs, +SparseTensorMatch::slowMatch(const TensorImplType &lhs, const TensorImplType &rhs) { std::vector<AddressOp> ops; - CompactTensorV2AddressBuilder addressBuilder; - CompactTensorV2AddressPadder addressPadder(_builder.dimensions(), + SparseTensorAddressBuilder addressBuilder; + SparseTensorAddressPadder addressPadder(_builder.dimensions(), lhs.dimensions()); buildTransformOps(ops, lhs.dimensions(), rhs.dimensions()); for (const auto &lhsCell : lhs.cells()) { @@ -108,7 +108,7 @@ CompactTensorV2Match::slowMatch(const TensorImplType &lhs, } } -CompactTensorV2Match::CompactTensorV2Match(const TensorImplType &lhs, +SparseTensorMatch::SparseTensorMatch(const TensorImplType &lhs, const TensorImplType &rhs) : Parent(lhs.combineDimensionsWith(rhs)) { diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_match.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_match.h index 99fc3ce457a..f12fddc51f4 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_match.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_match.h @@ -14,17 +14,17 @@ namespace tensor { * * If the two tensors have exactly the same dimensions, this is the Hadamard product. */ -class CompactTensorV2Match : public TensorOperation<CompactTensorV2> +class SparseTensorMatch : public TensorOperation<SparseTensor> { public: - using Parent = TensorOperation<CompactTensorV2>; + using Parent = TensorOperation<SparseTensor>; using typename Parent::TensorImplType; using Parent::_builder; private: void fastMatch(const TensorImplType &lhs, const TensorImplType &rhs); void slowMatch(const TensorImplType &lhs, const TensorImplType &rhs); public: - CompactTensorV2Match(const TensorImplType &lhs, const TensorImplType &rhs); + SparseTensorMatch(const TensorImplType &lhs, const TensorImplType &rhs); }; } // namespace vespalib::tensor diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_product.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_product.cpp index 3eeb68b3098..1a276ad55dd 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_product.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_product.cpp @@ -1,8 +1,8 @@ // 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 "compact_tensor_v2_product.h" -#include "compact_tensor_v2_address_decoder.h" +#include "sparse_tensor_product.h" +#include "sparse_tensor_address_decoder.h" #include <type_traits> namespace vespalib { @@ -47,14 +47,14 @@ buildCombineOps(const TensorDimensions &lhs, bool -combineAddresses(CompactTensorV2AddressBuilder &builder, +combineAddresses(SparseTensorAddressBuilder &builder, CompactTensorAddressRef lhsRef, CompactTensorAddressRef rhsRef, const CombineOps &ops) { builder.clear(); - CompactTensorV2AddressDecoder lhs(lhsRef); - CompactTensorV2AddressDecoder rhs(rhsRef); + SparseTensorAddressDecoder lhs(lhsRef); + SparseTensorAddressDecoder rhs(rhsRef); for (auto op : ops) { switch (op) { case AddressOp::LHS: @@ -81,11 +81,11 @@ combineAddresses(CompactTensorV2AddressBuilder &builder, void -CompactTensorV2Product::bruteForceProduct(const TensorImplType &lhs, +SparseTensorProduct::bruteForceProduct(const TensorImplType &lhs, const TensorImplType &rhs) { CombineOps ops(buildCombineOps(lhs.dimensions(), rhs.dimensions())); - CompactTensorV2AddressBuilder addressBuilder; + SparseTensorAddressBuilder addressBuilder; for (const auto &lhsCell : lhs.cells()) { for (const auto &rhsCell : rhs.cells()) { bool combineSuccess = combineAddresses(addressBuilder, @@ -101,7 +101,7 @@ CompactTensorV2Product::bruteForceProduct(const TensorImplType &lhs, void -CompactTensorV2Product::fastProduct(const TensorImplType &lhs, +SparseTensorProduct::fastProduct(const TensorImplType &lhs, const TensorImplType &rhs) { const typename TensorImplType::Cells &rhsCells = rhs.cells(); @@ -115,7 +115,7 @@ CompactTensorV2Product::fastProduct(const TensorImplType &lhs, } -CompactTensorV2Product::CompactTensorV2Product(const TensorImplType &lhs, +SparseTensorProduct::SparseTensorProduct(const TensorImplType &lhs, const TensorImplType &rhs) : Parent(lhs.combineDimensionsWith(rhs)) { diff --git a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_product.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_product.h index c0e2f8f4088..6aa84e83541 100644 --- a/vespalib/src/vespa/vespalib/tensor/compact/compact_tensor_v2_product.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_product.h @@ -19,11 +19,11 @@ namespace tensor { * The sparse tensor is associative and commutative. Its dimensions are the * set of the dimensions of the two input tensors. */ -class CompactTensorV2Product : public TensorOperation<CompactTensorV2> +class SparseTensorProduct : public TensorOperation<SparseTensor> { public: - using TensorImplType = CompactTensorV2; - using Parent = TensorOperation<CompactTensorV2>; + using TensorImplType = SparseTensor; + using Parent = TensorOperation<SparseTensor>; using Dimensions = typename Parent::Dimensions; using AddressBuilderType = typename Parent::AddressBuilderType; using AddressRefType = typename Parent::AddressRefType; @@ -38,7 +38,7 @@ private: fastProduct(const TensorImplType &lhs, const TensorImplType &rhs); public: - CompactTensorV2Product(const TensorImplType &lhs, + SparseTensorProduct(const TensorImplType &lhs, const TensorImplType &rhs); }; diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp b/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp index bdd03169799..7f0293f6349 100644 --- a/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp +++ b/vespalib/src/vespa/vespalib/tensor/tensor_apply.cpp @@ -16,7 +16,7 @@ TensorApply<TensorT>::TensorApply(const TensorImplType &tensor, } } -template class TensorApply<CompactTensorV2>; +template class TensorApply<SparseTensor>; } // namespace vespalib::tensor } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_apply.h b/vespalib/src/vespa/vespalib/tensor/tensor_apply.h index ea5ad8ffb57..52be67ed30c 100644 --- a/vespalib/src/vespa/vespalib/tensor/tensor_apply.h +++ b/vespalib/src/vespa/vespalib/tensor/tensor_apply.h @@ -21,7 +21,7 @@ public: TensorApply(const TensorImplType &tensor, const CellFunction &func); }; -extern template class TensorApply<CompactTensorV2>; +extern template class TensorApply<SparseTensor>; } // namespace vespalib::tensor } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp b/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp index 98708002772..460cb8f8bb4 100644 --- a/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp +++ b/vespalib/src/vespa/vespalib/tensor/tensor_mapper.cpp @@ -5,7 +5,7 @@ #include "tensor_mapper.h" #include "tensor.h" #include "tensor_visitor.h" -#include <vespa/vespalib/tensor/compact/direct_compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/direct_sparse_tensor_builder.h> #include <vespa/vespalib/tensor/dense/dense_tensor.h> #include "tensor_address_element_iterator.h" #include "default_tensor.h" @@ -80,7 +80,7 @@ SparseTensorMapper<TensorT>::build() template <> void -SparseTensorMapper<CompactTensorV2>:: +SparseTensorMapper<SparseTensor>:: mapAddress(const TensorAddress &address) { _addressBuilder.clear(); @@ -272,7 +272,7 @@ TensorMapper::map(const Tensor &tensor) const template std::unique_ptr<Tensor> -TensorMapper::mapToSparse<CompactTensorV2>(const Tensor &tensor, +TensorMapper::mapToSparse<SparseTensor>(const Tensor &tensor, const ValueType &type); } // namespace vespalib::tensor diff --git a/vespalib/src/vespa/vespalib/tensor/tensor_operation.h b/vespalib/src/vespa/vespalib/tensor/tensor_operation.h index 2918903554e..f74f7a7990d 100644 --- a/vespalib/src/vespa/vespalib/tensor/tensor_operation.h +++ b/vespalib/src/vespa/vespalib/tensor/tensor_operation.h @@ -3,7 +3,7 @@ #pragma once #include "direct_tensor_builder.h" -#include <vespa/vespalib/tensor/compact/direct_compact_tensor_v2_builder.h> +#include <vespa/vespalib/tensor/sparse/direct_sparse_tensor_builder.h> namespace vespalib { namespace tensor { |