summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-01-09 08:11:20 +0000
committerArne Juul <arnej@verizonmedia.com>2020-01-09 09:27:23 +0000
commit50a83238cd30154f5108f03028d0e5c3c964e768 (patch)
tree2a3757aecb6d08bf9b515ae3aa99a672b2a23396 /eval
parent09ad45c2c9a1766b9b0dfbee3557266c5bf0b819 (diff)
remove unused code
Diffstat (limited to 'eval')
-rw-r--r--eval/src/vespa/eval/tensor/sparse/CMakeLists.txt1
-rw-r--r--eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h27
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.cpp53
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.h31
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.cpp106
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.h4
6 files changed, 12 insertions, 210 deletions
diff --git a/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt b/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt
index 9304d890e34..8e1d18a87b7 100644
--- a/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt
+++ b/eval/src/vespa/eval/tensor/sparse/CMakeLists.txt
@@ -5,7 +5,6 @@ vespa_add_library(eval_tensor_sparse OBJECT
sparse_tensor_add.cpp
sparse_tensor_address_builder.cpp
sparse_tensor_address_combiner.cpp
- sparse_tensor_address_padder.cpp
sparse_tensor_address_reducer.cpp
sparse_tensor_address_ref.cpp
sparse_tensor_match.cpp
diff --git a/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h
index f9858e23b4d..d54c8810a81 100644
--- a/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h
+++ b/eval/src/vespa/eval/tensor/sparse/direct_sparse_tensor_builder.h
@@ -5,7 +5,6 @@
#include <vespa/vespalib/util/hdr_abort.h>
#include "sparse_tensor.h"
#include "sparse_tensor_address_builder.h"
-#include "sparse_tensor_address_padder.h"
namespace vespalib::tensor {
@@ -36,18 +35,6 @@ public:
}
}
- void
- copyCells(const Cells &cells_in, const eval::ValueType &cells_in_type)
- {
- SparseTensorAddressPadder addressPadder(_type, cells_in_type);
- for (const auto &cell : cells_in) {
- addressPadder.padAddress(cell.first);
- SparseTensorAddressRef oldRef = addressPadder.getAddressRef();
- SparseTensorAddressRef newRef(oldRef, _stash);
- _cells[newRef] = cell.second;
- }
- }
-
DirectSparseTensorBuilder()
: _stash(SparseTensor::STASH_CHUNK_SIZE),
_type(eval::ValueType::double_type()),
@@ -70,20 +57,6 @@ public:
copyCells(cells_in);
}
- DirectSparseTensorBuilder(const eval::ValueType &type_in,
- const Cells &cells_in,
- const eval::ValueType &cells_in_type)
- : _stash(SparseTensor::STASH_CHUNK_SIZE),
- _type(type_in),
- _cells()
- {
- if (type_in.dimensions().size() == cells_in_type.dimensions().size()) {
- copyCells(cells_in);
- } else {
- copyCells(cells_in, cells_in_type);
- }
- }
-
~DirectSparseTensorBuilder() {};
Tensor::UP build() {
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.cpp
deleted file mode 100644
index 46cd6537802..00000000000
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "sparse_tensor_address_padder.h"
-#include "sparse_tensor_address_decoder.h"
-#include <cassert>
-
-namespace vespalib::tensor {
-
-SparseTensorAddressPadder::SparseTensorAddressPadder(const eval::ValueType &resultType,
- const eval::ValueType &inputType)
- : SparseTensorAddressBuilder(),
- _padOps()
-{
- auto resultDimsItr = resultType.dimensions().cbegin();
- auto resultDimsItrEnd = resultType.dimensions().cend();
- for (auto &dim : inputType.dimensions()) {
- while (resultDimsItr != resultDimsItrEnd &&
- resultDimsItr->name < dim.name) {
- _padOps.push_back(PadOp::PAD);
- ++resultDimsItr;
- }
- assert(resultDimsItr != resultDimsItrEnd &&
- resultDimsItr->name == dim.name);
- _padOps.push_back(PadOp::COPY);
- ++resultDimsItr;
- }
- while (resultDimsItr != resultDimsItrEnd) {
- _padOps.push_back(PadOp::PAD);
- ++resultDimsItr;
- }
-}
-
-SparseTensorAddressPadder::~SparseTensorAddressPadder() = default;
-
-void
-SparseTensorAddressPadder::padAddress(SparseTensorAddressRef ref)
-{
- clear();
- SparseTensorAddressDecoder addr(ref);
- for (auto op : _padOps) {
- switch (op) {
- case PadOp::PAD:
- addUndefined();
- break;
- default:
- add(addr.decodeLabel());
- }
- }
- assert(!addr.valid());
-}
-
-}
-
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.h b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.h
deleted file mode 100644
index fbd34fcb0f8..00000000000
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_address_padder.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include "sparse_tensor_address_builder.h"
-#include <vespa/eval/eval/value_type.h>
-#include <cassert>
-
-namespace vespalib::tensor {
-
-/**
- * This class transforms serialized sparse tensor addresses by padding
- * in "undefined" labels for new dimensions.
- */
-class SparseTensorAddressPadder : public SparseTensorAddressBuilder
-{
- enum class PadOp { PAD, COPY };
-
- std::vector<PadOp> _padOps;
-
-public:
- SparseTensorAddressPadder(const eval::ValueType &resultType, const eval::ValueType &inputType);
- SparseTensorAddressPadder(SparseTensorAddressPadder &&) = default;
- SparseTensorAddressPadder & operator =(SparseTensorAddressPadder &&) = default;
- ~SparseTensorAddressPadder();
-
- void padAddress(SparseTensorAddressRef ref);
-};
-
-}
-
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.cpp
index 1de08de342a..75eff05cb37 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.cpp
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.cpp
@@ -3,76 +3,12 @@
#include "sparse_tensor_match.h"
#include "sparse_tensor_address_decoder.h"
#include <vespa/vespalib/stllike/hash_map.hpp>
+#include <vespa/vespalib/util/overload.h>
+#include <vespa/vespalib/util/visit_ranges.h>
+#include <assert.h>
namespace vespalib::tensor {
-namespace {
-
-enum class AddressOp
-{
- REMOVE,
- PAD,
- COPY
-};
-
-
-void
-buildTransformOps(std::vector<AddressOp> &ops,
- const eval::ValueType &lhs,
- const eval::ValueType &rhs)
-{
- auto rhsItr = rhs.dimensions().cbegin();
- auto rhsItrEnd = rhs.dimensions().cend();
- for (auto &lhsDim : lhs.dimensions()) {
- while (rhsItr != rhsItrEnd && rhsItr->name < lhsDim.name) {
- ops.push_back(AddressOp::PAD);
- ++rhsItr;
- }
- if (rhsItr != rhsItrEnd && rhsItr->name == lhsDim.name) {
- ops.push_back(AddressOp::COPY);
- ++rhsItr;
- } else {
- ops.push_back(AddressOp::REMOVE);
- }
- }
- while (rhsItr != rhsItrEnd) {
- ops.push_back(AddressOp::PAD);
- ++rhsItr;
- }
-}
-
-
-bool
-transformAddress(SparseTensorAddressBuilder &builder,
- SparseTensorAddressRef ref,
- const std::vector<AddressOp> &ops)
-{
- builder.clear();
- SparseTensorAddressDecoder addr(ref);
- for (auto op : ops) {
- switch (op) {
- case AddressOp::REMOVE:
- {
- auto label = addr.decodeLabel();
- if (label.size() != 0u) {
- return false;
- }
- }
- break;
- case AddressOp::PAD:
- builder.addUndefined();
- break;
- case AddressOp::COPY:
- builder.add(addr.decodeLabel());
- }
- }
- assert(!addr.valid());
- return true;
-}
-
-}
-
-
void
SparseTensorMatch::fastMatch(const TensorImplType &lhs, const TensorImplType &rhs)
{
@@ -85,39 +21,17 @@ SparseTensorMatch::fastMatch(const TensorImplType &lhs, const TensorImplType &rh
}
}
-void
-SparseTensorMatch::slowMatch(const TensorImplType &lhs, const TensorImplType &rhs)
-{
- std::vector<AddressOp> ops;
- SparseTensorAddressBuilder addressBuilder;
- SparseTensorAddressPadder addressPadder(_builder.fast_type(), lhs.fast_type());
- buildTransformOps(ops, lhs.fast_type(), rhs.fast_type());
- for (const auto &lhsCell : lhs.cells()) {
- if (!transformAddress(addressBuilder, lhsCell.first, ops)) {
- continue;
- }
- SparseTensorAddressRef ref(addressBuilder.getAddressRef());
- auto rhsItr = rhs.cells().find(ref);
- if (rhsItr != rhs.cells().end()) {
- addressPadder.padAddress(lhsCell.first);
- _builder.insertCell(addressPadder, lhsCell.second * rhsItr->second);
- }
- }
-}
-
SparseTensorMatch::SparseTensorMatch(const TensorImplType &lhs, const TensorImplType &rhs)
: Parent(lhs.combineDimensionsWith(rhs))
{
- if ((lhs.fast_type().dimensions().size() == rhs.fast_type().dimensions().size()) &&
- (lhs.fast_type().dimensions().size() == _builder.fast_type().dimensions().size())) {
- // Ensure that first tensor to fastMatch has fewest cells.
- if (lhs.cells().size() <= rhs.cells().size()) {
- fastMatch(lhs, rhs);
- } else {
- fastMatch(rhs, lhs);
- }
+ assert (lhs.fast_type().dimensions().size() == rhs.fast_type().dimensions().size());
+ assert (lhs.fast_type().dimensions().size() == _builder.fast_type().dimensions().size());
+
+ // Ensure that first tensor to fastMatch has fewest cells.
+ if (lhs.cells().size() <= rhs.cells().size()) {
+ fastMatch(lhs, rhs);
} else {
- slowMatch(lhs, rhs);
+ fastMatch(rhs, lhs);
}
}
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.h b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.h
index bb2c82a6d00..f5f52eda756 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.h
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_match.h
@@ -11,7 +11,8 @@ namespace vespalib::tensor {
* This returns a tensor which contains the matching cells in the two tensors,
* with their values multiplied.
*
- * If the two tensors have exactly the same dimensions, this is the Hadamard product.
+ * Only used when two tensors have exactly the same dimensions,
+ * this is the Hadamard product.
*/
class SparseTensorMatch : public TensorOperation<SparseTensor>
{
@@ -21,7 +22,6 @@ public:
using Parent::_builder;
private:
void fastMatch(const TensorImplType &lhs, const TensorImplType &rhs);
- void slowMatch(const TensorImplType &lhs, const TensorImplType &rhs);
public:
SparseTensorMatch(const TensorImplType &lhs, const TensorImplType &rhs);
};