summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-07-10 13:12:04 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-07-10 15:03:09 +0000
commita9510442554818a2288b9bb7ea1f2d8a584ef6a0 (patch)
tree45aa8d38114f69ad52cb46ad69163ed412edc782 /eval
parent6a7d07037ce40a637441078afe6951c00d189e7b (diff)
remove concept of dimension 'bound-ness'
clean up tensor attribute code
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/value_type/value_type_test.cpp5
-rw-r--r--eval/src/vespa/eval/eval/function.cpp14
-rw-r--r--eval/src/vespa/eval/eval/value_type.h1
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_view.h13
-rw-r--r--eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp25
-rw-r--r--eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h35
6 files changed, 13 insertions, 80 deletions
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<float>()' 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<vespalib::string> &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<ValueType::Dimension> &dimensions =
- const_cast<std::vector<ValueType::Dimension> &>(_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<eval::ValueType::Dimension::size_type *> _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();
- }
};
}
-