-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnumpy-files.h
39 lines (32 loc) · 904 Bytes
/
numpy-files.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <cstddef>
#include <map>
#include <string>
#include <vector>
enum dtype {
int8,
uint8,
int16,
uint16,
int32,
uint32,
int64,
uint64,
float32,
float64
};
struct descr {
std::string name;
size_t size;
bool integer;
bool is_signed;
};
extern const std::map<dtype, descr> dtypes;
void write_numpy_file(void* data, dtype datatype, std::vector<size_t>& dimensions, const std::string& filename);
void read_numpy_file(const std::string& filename, void*& pdata, dtype& data_type, std::vector<size_t>& dimensions);
struct aligned_buffer {
void* base;
size_t stride; // in bytes
inline void* row(size_t index) { return (void*) ((char*)base + index*stride); }
};
void read_numpy_file_aligned(const std::string& filename, aligned_buffer& pdata, dtype& data_type, std::vector<size_t>& dimensions, size_t alignment = 32);