1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/vespalib/util/arrayref.h>
#include <vespa/eval/eval/cell_type.h>
namespace vespalib::eval {
// Low-level typed cells reference
struct TypedCells {
const void *data;
size_t size:56;
CellType type;
explicit TypedCells(ConstArrayRef<double> cells) noexcept : data(cells.begin()), size(cells.size()), type(CellType::DOUBLE) {}
explicit TypedCells(ConstArrayRef<float> cells) noexcept : data(cells.begin()), size(cells.size()), type(CellType::FLOAT) {}
explicit TypedCells(ConstArrayRef<BFloat16> cells) noexcept : data(cells.begin()), size(cells.size()), type(CellType::BFLOAT16) {}
explicit TypedCells(ConstArrayRef<Int8Float> cells) noexcept : data(cells.begin()), size(cells.size()), type(CellType::INT8) {}
TypedCells() noexcept : data(nullptr), size(0), type(CellType::DOUBLE) {}
TypedCells(const void *dp, CellType ct, size_t sz) noexcept : data(dp), size(sz), type(ct) {}
template <typename T> bool check_type() const noexcept { return check_cell_type<T>(type); }
template <typename T> ConstArrayRef<T> typify() const noexcept {
assert(check_type<T>());
return ConstArrayRef<T>((const T *)data, size);
}
template <typename T> ConstArrayRef<T> unsafe_typify() const noexcept {
return ConstArrayRef<T>((const T *)data, size);
}
TypedCells(TypedCells &&other) noexcept = default;
TypedCells(const TypedCells &other) noexcept = default;
TypedCells & operator= (TypedCells &&other) noexcept = default;
TypedCells & operator= (const TypedCells &other) noexcept = default;
bool valid() const noexcept { return size != 0; }
};
} // namespace
|