| 1004 | } |
| 1005 | |
| 1006 | Result<std::shared_ptr<Tensor>> FixedSizeListArray::ToTensorWithNulls() const { |
| 1007 | const auto* data = this->data().get(); |
| 1008 | auto type = this->type(); |
| 1009 | int64_t offset = data->offset; |
| 1010 | int64_t length = data->length; |
| 1011 | std::vector<int64_t> shape{length}; |
| 1012 | |
| 1013 | // Iterate over nested fixed length container types. |
| 1014 | // Each nested container increase the tensor dimension. |
| 1015 | while (type->id() == Type::FIXED_SIZE_LIST) { |
| 1016 | const auto* fsl = internal::checked_cast<const FixedSizeListType*>(type.get()); |
| 1017 | type = fsl->value_type(); |
| 1018 | data = data->child_data.front().get(); |
| 1019 | // Overflow cannot happen on a valid array (its data needs to fit in memory, |
| 1020 | // therefore be smaller than INT64_MAX) |
| 1021 | offset = offset * fsl->list_size() + data->offset; |
| 1022 | length = length * fsl->list_size(); |
| 1023 | shape.push_back(fsl->list_size()); |
| 1024 | } |
| 1025 | |
| 1026 | // Only checking byte_width which we need here and leaving Tensor::Make error on |
| 1027 | // unsupported types. |
| 1028 | if (!is_fixed_width(*type)) { |
| 1029 | return Status::TypeError("Expected a fixed width leaf type, got ", type->name()); |
| 1030 | } |
| 1031 | |
| 1032 | std::shared_ptr<Buffer> buffer = nullptr; |
| 1033 | if (const auto& buf = data->buffers[1]; buf != NULLPTR) { |
| 1034 | const int64_t byte_width = type->byte_width(); |
| 1035 | // Buffer guarantees this fits into an int64_t. |
| 1036 | const int64_t byte_offset = offset * byte_width; |
| 1037 | const int64_t byte_length = length * byte_width; |
| 1038 | ARROW_ASSIGN_OR_RAISE(buffer, SliceBufferSafe(buf, byte_offset, byte_length)); |
| 1039 | } |
| 1040 | |
| 1041 | return Tensor::Make(std::move(type), std::move(buffer), std::move(shape)); |
| 1042 | } |
| 1043 | |
| 1044 | // ---------------------------------------------------------------------- |
| 1045 | // Struct |
nothing calls this directly
no test coverage detected