| 489 | |
| 490 | template<typename Scalar> |
| 491 | inline void |
| 492 | SaveArrayAsNumpy(const std::string &filename, bool fortran_order, unsigned int n_dims, const unsigned long shape[], |
| 493 | const Scalar* data) { |
| 494 | // static_assert(has_typestring<Scalar>::value, "scalar type not understood"); |
| 495 | const dtype_t dtype = dtype_map.at(std::type_index(typeid(Scalar))); |
| 496 | |
| 497 | std::ofstream stream(filename, std::ofstream::binary); |
| 498 | if (!stream) { |
| 499 | throw std::runtime_error("io error: failed to open a file."); |
| 500 | } |
| 501 | |
| 502 | std::vector <ndarray_len_t> shape_v(shape, shape + n_dims); |
| 503 | header_t header{dtype, fortran_order, shape_v}; |
| 504 | write_header(stream, header); |
| 505 | |
| 506 | auto size = static_cast<size_t>(comp_size(shape_v)); |
| 507 | |
| 508 | stream.write(reinterpret_cast<const char *>(data), sizeof(Scalar) * size); |
| 509 | } |
| 510 | |
| 511 | template<typename Scalar> |
| 512 | inline void |
nothing calls this directly
no test coverage detected