| 226 | } |
| 227 | |
| 228 | Result<std::shared_ptr<FixedShapeTensorArray>> FixedShapeTensorArray::FromTensor( |
| 229 | const std::shared_ptr<Tensor>& tensor) { |
| 230 | auto permutation = internal::ArgSort(tensor->strides(), std::greater<>()); |
| 231 | if (permutation[0] != 0) { |
| 232 | return Status::Invalid( |
| 233 | "Only first-major tensors can be zero-copy converted to arrays"); |
| 234 | } |
| 235 | permutation.erase(permutation.begin()); |
| 236 | |
| 237 | std::vector<int64_t> cell_shape; |
| 238 | cell_shape.reserve(permutation.size()); |
| 239 | for (auto i : permutation) { |
| 240 | cell_shape.emplace_back(tensor->shape()[i]); |
| 241 | } |
| 242 | |
| 243 | std::vector<std::string> dim_names; |
| 244 | if (!tensor->dim_names().empty()) { |
| 245 | dim_names.reserve(permutation.size()); |
| 246 | for (auto i : permutation) { |
| 247 | dim_names.emplace_back(tensor->dim_names()[i]); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | for (int64_t& i : permutation) { |
| 252 | --i; |
| 253 | } |
| 254 | |
| 255 | auto ext_type = internal::checked_pointer_cast<ExtensionType>( |
| 256 | fixed_shape_tensor(tensor->type(), cell_shape, permutation, dim_names)); |
| 257 | |
| 258 | std::shared_ptr<Array> value_array; |
| 259 | switch (tensor->type_id()) { |
| 260 | case Type::UINT8: { |
| 261 | value_array = std::make_shared<UInt8Array>(tensor->size(), tensor->data()); |
| 262 | break; |
| 263 | } |
| 264 | case Type::INT8: { |
| 265 | value_array = std::make_shared<Int8Array>(tensor->size(), tensor->data()); |
| 266 | break; |
| 267 | } |
| 268 | case Type::UINT16: { |
| 269 | value_array = std::make_shared<UInt16Array>(tensor->size(), tensor->data()); |
| 270 | break; |
| 271 | } |
| 272 | case Type::INT16: { |
| 273 | value_array = std::make_shared<Int16Array>(tensor->size(), tensor->data()); |
| 274 | break; |
| 275 | } |
| 276 | case Type::UINT32: { |
| 277 | value_array = std::make_shared<UInt32Array>(tensor->size(), tensor->data()); |
| 278 | break; |
| 279 | } |
| 280 | case Type::INT32: { |
| 281 | value_array = std::make_shared<Int32Array>(tensor->size(), tensor->data()); |
| 282 | break; |
| 283 | } |
| 284 | case Type::UINT64: { |
| 285 | value_array = std::make_shared<UInt64Array>(tensor->size(), tensor->data()); |
nothing calls this directly
no test coverage detected