MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / SaveArrayAsNumpy

Function SaveArrayAsNumpy

lite/example/cpp_example/npy.h:541–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539
540template <typename Scalar>
541inline void SaveArrayAsNumpy(
542 const std::string& filename, bool fortran_order, unsigned int n_dims,
543 const unsigned long shape[], const std::vector<Scalar>& data) {
544 Typestring typestring_o(data);
545 std::string typestring = typestring_o.str();
546
547 std::ofstream stream(filename, std::ofstream::binary);
548 if (!stream) {
549 fprintf(stderr, "io error: failed to open a file.");
550 }
551
552 std::vector<ndarray_len_t> shape_v(shape, shape + n_dims);
553 write_header(stream, typestring, fortran_order, shape_v);
554
555 auto size = static_cast<size_t>(comp_size(shape_v));
556
557 stream.write(reinterpret_cast<const char*>(data.data()), sizeof(Scalar) * size);
558}
559
560template <typename Scalar>
561inline void LoadArrayFromNumpy(

Callers

nothing calls this directly

Calls 5

write_headerFunction · 0.70
comp_sizeFunction · 0.70
strMethod · 0.45
writeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected