From a9510442554818a2288b9bb7ea1f2d8a584ef6a0 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Wed, 10 Jul 2019 13:12:04 +0000 Subject: remove concept of dimension 'bound-ness' clean up tensor attribute code --- eval/src/tests/eval/value_type/value_type_test.cpp | 5 +--- eval/src/vespa/eval/eval/function.cpp | 14 +-------- eval/src/vespa/eval/eval/value_type.h | 1 - .../vespa/eval/tensor/dense/dense_tensor_view.h | 13 ++++---- .../tensor/dense/mutable_dense_tensor_view.cpp | 25 ++-------------- .../eval/tensor/dense/mutable_dense_tensor_view.h | 35 +--------------------- 6 files changed, 13 insertions(+), 80 deletions(-) (limited to 'eval/src') diff --git a/eval/src/tests/eval/value_type/value_type_test.cpp b/eval/src/tests/eval/value_type/value_type_test.cpp index cf61da00cca..42b34c0d3ea 100644 --- a/eval/src/tests/eval/value_type/value_type_test.cpp +++ b/eval/src/tests/eval/value_type/value_type_test.cpp @@ -80,7 +80,7 @@ TEST("require that 'tensor()' is normalized to 'double'") { EXPECT_EQUAL(t.dimensions().size(), 0u); } -TEST("require that use of unbound dimensions result in error types") { +TEST("require that use of zero-size dimensions result in error types") { EXPECT_TRUE(ValueType::tensor_type({{"x", 0}}).is_error()); } @@ -276,13 +276,10 @@ TEST("require that dimension predicates work as expected") { ValueType::Dimension z("z", 0); EXPECT_TRUE(x.is_mapped()); EXPECT_TRUE(!x.is_indexed()); - EXPECT_TRUE(!x.is_bound()); EXPECT_TRUE(!y.is_mapped()); EXPECT_TRUE(y.is_indexed()); - EXPECT_TRUE(y.is_bound()); EXPECT_TRUE(!z.is_mapped()); EXPECT_TRUE(z.is_indexed()); - EXPECT_TRUE(!z.is_bound()); } TEST("require that removing dimensions from non-tensor types gives error type") { diff --git a/eval/src/vespa/eval/eval/function.cpp b/eval/src/vespa/eval/eval/function.cpp index 8b9e440318d..65c70a5bd7d 100644 --- a/eval/src/vespa/eval/eval/function.cpp +++ b/eval/src/vespa/eval/eval/function.cpp @@ -30,18 +30,6 @@ bool has_duplicates(const std::vector &list) { return false; } -bool check_tensor_lambda_type(const ValueType &type) { - if (!type.is_tensor() || type.dimensions().empty()) { - return false; - } - for (const auto &dim: type.dimensions()) { - if (!dim.is_indexed() || !dim.is_bound()) { - return false; - } - } - return true; -} - //----------------------------------------------------------------------------- class Params { @@ -566,7 +554,7 @@ void parse_tensor_lambda(ParseContext &ctx) { ctx.eat(')'); type_spec.push_back(')'); ValueType type = ValueType::from_spec(type_spec); - if (!check_tensor_lambda_type(type)) { + if (!type.is_dense()) { ctx.fail("invalid tensor type"); return; } diff --git a/eval/src/vespa/eval/eval/value_type.h b/eval/src/vespa/eval/eval/value_type.h index 423c8e15d92..0eb3e1ca28e 100644 --- a/eval/src/vespa/eval/eval/value_type.h +++ b/eval/src/vespa/eval/eval/value_type.h @@ -32,7 +32,6 @@ public: bool operator!=(const Dimension &rhs) const { return !(*this == rhs); } bool is_mapped() const { return (size == npos); } bool is_indexed() const { return (size != npos); } - bool is_bound() const { return ((size != npos) && (size != 0)); } }; private: diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h index c09202e50d0..1ec4daf40fd 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h +++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h @@ -21,11 +21,9 @@ public: DenseTensorView(const eval::ValueType &type_in, TypedCells cells_in) : _typeRef(type_in), _cellsRef(cells_in) - {} - explicit DenseTensorView(const eval::ValueType &type_in) - : _typeRef(type_in), - _cellsRef() - {} + { + assert(_typeRef.cell_type() == cells_in.type); + } const eval::ValueType &fast_type() const { return _typeRef; } const TypedCells &cellsRef() const { return _cellsRef; } @@ -45,6 +43,11 @@ public: eval::TensorSpec toSpec() const override; void accept(TensorVisitor &visitor) const override; protected: + explicit DenseTensorView(const eval::ValueType &type_in) + : _typeRef(type_in), + _cellsRef() + {} + void initCellsRef(TypedCells cells_in) { assert(_typeRef.cell_type() == cells_in.type); _cellsRef = cells_in; diff --git a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp index 08abc391179..ae3e8ad9023 100644 --- a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp +++ b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp @@ -6,31 +6,10 @@ using vespalib::eval::ValueType; namespace vespalib::tensor { -MutableDenseTensorView::MutableValueType::MutableValueType(ValueType type_in) - : _type(type_in) -{ - std::vector &dimensions = - const_cast &>(_type.dimensions()); - for (auto &dim : dimensions) { - if (!dim.is_bound()) { - _unboundDimSizes.emplace_back(&dim.size); - } - } -} - -MutableDenseTensorView::MutableValueType::~MutableValueType() = default; - MutableDenseTensorView::MutableDenseTensorView(ValueType type_in) - : DenseTensorView(_concreteType._type), - _concreteType(type_in) -{ -} - -MutableDenseTensorView::MutableDenseTensorView(ValueType type_in, TypedCells cells_in) - : DenseTensorView(_concreteType._type, cells_in), - _concreteType(type_in) + : DenseTensorView(_type), + _type(type_in) { } } - diff --git a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h index d71903d6c47..db241ef6a2b 100644 --- a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h +++ b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h @@ -13,46 +13,13 @@ namespace vespalib::tensor { class MutableDenseTensorView : public DenseTensorView { private: - struct MutableValueType - { - eval::ValueType _type; - private: - std::vector _unboundDimSizes; - - public: - MutableValueType(eval::ValueType type_in); - ~MutableValueType(); - const eval::ValueType &fast_type() const { return _type; } - void setUnboundDimensions(const uint32_t *unboundDimSizeBegin, const uint32_t *unboundDimSizeEnd) { - const uint32_t *unboundDimSizePtr = unboundDimSizeBegin; - for (auto unboundDimSize : _unboundDimSizes) { - *unboundDimSize = *unboundDimSizePtr++; - } - assert(unboundDimSizePtr == unboundDimSizeEnd); - (void) unboundDimSizeEnd; - } - void setUnboundDimensionsForEmptyTensor() { - for (auto unboundDimSize : _unboundDimSizes) { - *unboundDimSize = 1; - } - } - }; - - MutableValueType _concreteType; + eval::ValueType _type; public: MutableDenseTensorView(eval::ValueType type_in); - MutableDenseTensorView(eval::ValueType type_in, TypedCells cells_in); void setCells(TypedCells cells_in) { initCellsRef(cells_in); } - void setUnboundDimensions(const uint32_t *unboundDimSizeBegin, const uint32_t *unboundDimSizeEnd) { - _concreteType.setUnboundDimensions(unboundDimSizeBegin, unboundDimSizeEnd); - } - void setUnboundDimensionsForEmptyTensor() { - _concreteType.setUnboundDimensionsForEmptyTensor(); - } }; } - -- cgit v1.2.3