File indexing completed on 2026-11-07 09:44:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <cstdint>
0021 #include <memory>
0022 #include <optional>
0023 #include <string>
0024 #include <vector>
0025
0026 #include "arrow/extension_type.h"
0027
0028 namespace arrow::extension {
0029
0030 class ARROW_EXPORT VariableShapeTensorArray : public ExtensionArray {
0031 public:
0032 using ExtensionArray::ExtensionArray;
0033 };
0034
0035
0036
0037
0038 class ARROW_EXPORT VariableShapeTensorType : public ExtensionType {
0039 public:
0040 VariableShapeTensorType(const std::shared_ptr<DataType>& value_type, int32_t ndim,
0041 std::vector<int64_t> permutation = {},
0042 std::vector<std::string> dim_names = {},
0043 std::vector<std::optional<int64_t>> uniform_shape = {})
0044 : ExtensionType(struct_({::arrow::field("data", list(value_type)),
0045 ::arrow::field("shape", fixed_size_list(int32(), ndim))})),
0046 value_type_(value_type),
0047 ndim_(ndim),
0048 permutation_(std::move(permutation)),
0049 dim_names_(std::move(dim_names)),
0050 uniform_shape_(std::move(uniform_shape)) {}
0051
0052 std::string extension_name() const override { return "arrow.variable_shape_tensor"; }
0053 std::string ToString(bool show_metadata = false) const override;
0054
0055
0056 int32_t ndim() const { return ndim_; }
0057
0058
0059 const std::shared_ptr<DataType>& value_type() const { return value_type_; }
0060
0061
0062 const std::vector<int64_t>& permutation() const { return permutation_; }
0063
0064
0065 const std::vector<std::string>& dim_names() const { return dim_names_; }
0066
0067
0068 const std::vector<std::optional<int64_t>>& uniform_shape() const {
0069 return uniform_shape_;
0070 }
0071
0072 bool ExtensionEquals(const ExtensionType& other) const override;
0073
0074 std::string Serialize() const override;
0075
0076 Result<std::shared_ptr<DataType>> Deserialize(
0077 std::shared_ptr<DataType> storage_type,
0078 const std::string& serialized_data) const override;
0079
0080
0081 std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0082
0083
0084
0085
0086
0087
0088 static Result<std::shared_ptr<Tensor>> MakeTensor(
0089 const std::shared_ptr<ExtensionScalar>&);
0090
0091
0092 static Result<std::shared_ptr<DataType>> Make(
0093 const std::shared_ptr<DataType>& value_type, int32_t ndim,
0094 std::vector<int64_t> permutation = {}, std::vector<std::string> dim_names = {},
0095 std::vector<std::optional<int64_t>> uniform_shape = {});
0096
0097 private:
0098 std::shared_ptr<DataType> value_type_;
0099 int32_t ndim_;
0100 std::vector<int64_t> permutation_;
0101 std::vector<std::string> dim_names_;
0102 std::vector<std::optional<int64_t>> uniform_shape_;
0103 };
0104
0105
0106 ARROW_EXPORT std::shared_ptr<DataType> variable_shape_tensor(
0107 const std::shared_ptr<DataType>& value_type, int32_t ndim,
0108 std::vector<int64_t> permutation = {}, std::vector<std::string> dim_names = {},
0109 std::vector<std::optional<int64_t>> uniform_shape = {});
0110
0111 }