MCPcopy Create free account
hub / github.com/apache/arrow / Make

Method Make

cpp/src/arrow/extension/variable_shape_tensor.cc:282–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282Result<std::shared_ptr<DataType>> VariableShapeTensorType::Make(
283 const std::shared_ptr<DataType>& value_type, int32_t ndim,
284 std::vector<int64_t> permutation, std::vector<std::string> dim_names,
285 std::vector<std::optional<int64_t>> uniform_shape) {
286 if (!is_fixed_width(*value_type)) {
287 return Status::Invalid("Cannot convert non-fixed-width values to Tensor.");
288 }
289 if (ndim < 0) {
290 return Status::Invalid("ndim must be non-negative. Got: ", ndim);
291 }
292
293 if (!dim_names.empty() && dim_names.size() != static_cast<size_t>(ndim)) {
294 return Status::Invalid("dim_names size must match ndim. Expected: ", ndim,
295 " Got: ", dim_names.size());
296 }
297 if (!uniform_shape.empty() && uniform_shape.size() != static_cast<size_t>(ndim)) {
298 return Status::Invalid("uniform_shape size must match ndim. Expected: ", ndim,
299 " Got: ", uniform_shape.size());
300 }
301 if (!uniform_shape.empty()) {
302 for (const auto& v : uniform_shape) {
303 if (v.has_value() && v.value() < 0) {
304 return Status::Invalid("uniform_shape must have non-negative values");
305 }
306 }
307 }
308 if (!permutation.empty()) {
309 if (permutation.size() != static_cast<size_t>(ndim)) {
310 return Status::Invalid("permutation size must match ndim. Expected: ", ndim,
311 " Got: ", permutation.size());
312 }
313 RETURN_NOT_OK(internal::IsPermutationValid(permutation));
314 }
315
316 return std::make_shared<VariableShapeTensorType>(
317 value_type, ndim, std::move(permutation), std::move(dim_names),
318 std::move(uniform_shape));
319}
320
321std::shared_ptr<DataType> variable_shape_tensor(
322 const std::shared_ptr<DataType>& value_type, int32_t ndim,

Callers

nothing calls this directly

Calls 6

is_fixed_widthFunction · 0.85
IsPermutationValidFunction · 0.85
InvalidFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected