| 72 | } |
| 73 | |
| 74 | std::string FixedShapeTensorType::Serialize() const { |
| 75 | rj::Document document; |
| 76 | document.SetObject(); |
| 77 | rj::Document::AllocatorType& allocator = document.GetAllocator(); |
| 78 | |
| 79 | rj::Value shape(rj::kArrayType); |
| 80 | for (auto v : shape_) { |
| 81 | shape.PushBack(v, allocator); |
| 82 | } |
| 83 | document.AddMember(rj::Value("shape", allocator), shape, allocator); |
| 84 | |
| 85 | if (!permutation_.empty()) { |
| 86 | rj::Value permutation(rj::kArrayType); |
| 87 | for (auto v : permutation_) { |
| 88 | permutation.PushBack(v, allocator); |
| 89 | } |
| 90 | document.AddMember(rj::Value("permutation", allocator), permutation, allocator); |
| 91 | } |
| 92 | |
| 93 | if (!dim_names_.empty()) { |
| 94 | rj::Value dim_names(rj::kArrayType); |
| 95 | for (const std::string& v : dim_names_) { |
| 96 | dim_names.PushBack(rj::Value{}.SetString(v.c_str(), allocator), allocator); |
| 97 | } |
| 98 | document.AddMember(rj::Value("dim_names", allocator), dim_names, allocator); |
| 99 | } |
| 100 | |
| 101 | rj::StringBuffer buffer; |
| 102 | rj::Writer<rj::StringBuffer> writer(buffer); |
| 103 | document.Accept(writer); |
| 104 | return buffer.GetString(); |
| 105 | } |
| 106 | |
| 107 | Result<std::shared_ptr<DataType>> FixedShapeTensorType::Deserialize( |
| 108 | std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const { |