| 82 | } |
| 83 | |
| 84 | std::string VariableShapeTensorType::Serialize() const { |
| 85 | rj::Document document; |
| 86 | document.SetObject(); |
| 87 | rj::Document::AllocatorType& allocator = document.GetAllocator(); |
| 88 | |
| 89 | if (!permutation_.empty()) { |
| 90 | rj::Value permutation(rj::kArrayType); |
| 91 | for (auto v : permutation_) { |
| 92 | permutation.PushBack(v, allocator); |
| 93 | } |
| 94 | document.AddMember(rj::Value("permutation", allocator), permutation, allocator); |
| 95 | } |
| 96 | |
| 97 | if (!dim_names_.empty()) { |
| 98 | rj::Value dim_names(rj::kArrayType); |
| 99 | for (const std::string& v : dim_names_) { |
| 100 | dim_names.PushBack(rj::Value{}.SetString(v.c_str(), allocator), allocator); |
| 101 | } |
| 102 | document.AddMember(rj::Value("dim_names", allocator), dim_names, allocator); |
| 103 | } |
| 104 | |
| 105 | if (!uniform_shape_.empty()) { |
| 106 | rj::Value uniform_shape(rj::kArrayType); |
| 107 | for (auto v : uniform_shape_) { |
| 108 | if (v.has_value()) { |
| 109 | uniform_shape.PushBack(v.value(), allocator); |
| 110 | } else { |
| 111 | uniform_shape.PushBack(rj::Value{}.SetNull(), allocator); |
| 112 | } |
| 113 | } |
| 114 | document.AddMember(rj::Value("uniform_shape", allocator), uniform_shape, allocator); |
| 115 | } |
| 116 | |
| 117 | rj::StringBuffer buffer; |
| 118 | rj::Writer<rj::StringBuffer> writer(buffer); |
| 119 | document.Accept(writer); |
| 120 | return buffer.GetString(); |
| 121 | } |
| 122 | |
| 123 | Result<std::shared_ptr<DataType>> VariableShapeTensorType::Deserialize( |
| 124 | std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const { |