| 459 | }; |
| 460 | |
| 461 | inline void serialize(const tensor& item, std::ostream& out) |
| 462 | { |
| 463 | int version = 2; |
| 464 | serialize(version, out); |
| 465 | serialize(item.num_samples(), out); |
| 466 | serialize(item.k(), out); |
| 467 | serialize(item.nr(), out); |
| 468 | serialize(item.nc(), out); |
| 469 | byte_orderer bo; |
| 470 | auto sbuf = out.rdbuf(); |
| 471 | for (auto d : item) |
| 472 | { |
| 473 | // Write out our data as 4byte little endian IEEE floats rather than using |
| 474 | // dlib's default float serialization. We do this because it will result in |
| 475 | // more compact outputs. It's slightly less portable but it seems doubtful |
| 476 | // that any CUDA enabled platform isn't going to use IEEE floats. But if one |
| 477 | // does we can just update the serialization code here to handle it if such a |
| 478 | // platform is encountered. |
| 479 | bo.host_to_little(d); |
| 480 | static_assert(sizeof(d)==4, "This serialization code assumes we are writing 4 byte floats"); |
| 481 | sbuf->sputn((char*)&d, sizeof(d)); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | inline void deserialize(resizable_tensor& item, std::istream& in) |
| 486 | { |
nothing calls this directly
no test coverage detected