| 105 | } |
| 106 | |
| 107 | Result<std::shared_ptr<DataType>> FixedShapeTensorType::Deserialize( |
| 108 | std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const { |
| 109 | if (storage_type->id() != Type::FIXED_SIZE_LIST) { |
| 110 | return Status::Invalid("Expected FixedSizeList storage type, got ", |
| 111 | storage_type->ToString()); |
| 112 | } |
| 113 | auto fsl_type = internal::checked_pointer_cast<FixedSizeListType>(storage_type); |
| 114 | auto value_type = fsl_type->value_type(); |
| 115 | rj::Document document; |
| 116 | if (document.Parse(serialized_data.data(), serialized_data.length()).HasParseError() || |
| 117 | !document.IsObject() || !document.HasMember("shape") || |
| 118 | !document["shape"].IsArray()) { |
| 119 | return Status::Invalid("Invalid serialized JSON data: ", serialized_data); |
| 120 | } |
| 121 | |
| 122 | std::vector<int64_t> shape; |
| 123 | for (const auto& x : document["shape"].GetArray()) { |
| 124 | if (!x.IsInt64()) { |
| 125 | return Status::Invalid("shape must contain integers, got ", |
| 126 | internal::JsonTypeName(x)); |
| 127 | } |
| 128 | shape.emplace_back(x.GetInt64()); |
| 129 | } |
| 130 | |
| 131 | std::vector<int64_t> permutation; |
| 132 | if (document.HasMember("permutation")) { |
| 133 | const auto& json_permutation = document["permutation"]; |
| 134 | if (!json_permutation.IsArray()) { |
| 135 | return Status::Invalid("permutation must be an array, got ", |
| 136 | internal::JsonTypeName(json_permutation)); |
| 137 | } |
| 138 | for (const auto& x : json_permutation.GetArray()) { |
| 139 | if (!x.IsInt64()) { |
| 140 | return Status::Invalid("permutation must contain integers, got ", |
| 141 | internal::JsonTypeName(x)); |
| 142 | } |
| 143 | permutation.emplace_back(x.GetInt64()); |
| 144 | } |
| 145 | if (shape.size() != permutation.size()) { |
| 146 | return Status::Invalid("Invalid permutation"); |
| 147 | } |
| 148 | RETURN_NOT_OK(internal::IsPermutationValid(permutation)); |
| 149 | } |
| 150 | std::vector<std::string> dim_names; |
| 151 | if (document.HasMember("dim_names")) { |
| 152 | const auto& json_dim_names = document["dim_names"]; |
| 153 | if (!json_dim_names.IsArray()) { |
| 154 | return Status::Invalid("dim_names must be an array, got ", |
| 155 | internal::JsonTypeName(json_dim_names)); |
| 156 | } |
| 157 | for (const auto& x : json_dim_names.GetArray()) { |
| 158 | if (!x.IsString()) { |
| 159 | return Status::Invalid("dim_names must contain strings, got ", |
| 160 | internal::JsonTypeName(x)); |
| 161 | } |
| 162 | dim_names.emplace_back(x.GetString()); |
| 163 | } |
| 164 | if (shape.size() != dim_names.size()) { |
nothing calls this directly
no test coverage detected