| 120 | } |
| 121 | |
| 122 | inline void CreateMetaData( |
| 123 | std::string& preamble, std::string& header, |
| 124 | const std::string& descriptor, bool fortran_order, |
| 125 | int n_dims, const int shape[]) |
| 126 | { |
| 127 | header = "{'descr': '"; |
| 128 | header.append(descriptor); |
| 129 | if(fortran_order) { |
| 130 | header.append("', 'fortran_order': True, "); |
| 131 | } else { |
| 132 | header.append("', 'fortran_order': False, "); |
| 133 | } |
| 134 | header.append("'shape': ("); |
| 135 | std::stringstream shape_stream; |
| 136 | if(1 < n_dims) { |
| 137 | for(int d=0; d<n_dims; ++d) { |
| 138 | shape_stream << shape[d]; |
| 139 | if(d + 1 != n_dims) { |
| 140 | shape_stream << ","; |
| 141 | } |
| 142 | } |
| 143 | } else { |
| 144 | shape_stream << shape[0] << ","; |
| 145 | } |
| 146 | shape_stream << "), }"; |
| 147 | header.append(shape_stream.str()); |
| 148 | const int to_padding = 16 - (10 + header.size() + 1) % 16; |
| 149 | for(int m=0; m<to_padding; ++m) { |
| 150 | header.push_back(' '); |
| 151 | } |
| 152 | header.push_back('\n'); |
| 153 | |
| 154 | preamble = "\x93NUMPY"; |
| 155 | preamble.push_back((char)1); |
| 156 | preamble.push_back((char)0); |
| 157 | uint16_t header_length = detail::ReorderInteger((uint16_t)header.size()); |
| 158 | preamble.append(reinterpret_cast<char*>(&header_length), 2); |
| 159 | } |
| 160 | |
| 161 | } // namespace detail |
| 162 |
no test coverage detected