86 static const char *c2numpy_float16 =
"<f2";
89 static const char *c2numpy_complex =
"<c16";
90 static const char *c2numpy_complex64 =
"<c8";
91 static const char *c2numpy_complex128 =
"<c16";
93 static const char *c2numpy_str[155] = {
"|S0",
"|S1",
"|S2",
"|S3",
"|S4",
"|S5",
"|S6",
"|S7",
"|S8",
"|S9",
"|S10",
"|S11",
"|S12",
"|S13",
"|S14",
"|S15",
"|S16",
"|S17",
"|S18",
"|S19",
"|S20",
"|S21",
"|S22",
"|S23",
"|S24",
"|S25",
"|S26",
"|S27",
"|S28",
"|S29",
"|S30",
"|S31",
"|S32",
"|S33",
"|S34",
"|S35",
"|S36",
"|S37",
"|S38",
"|S39",
"|S40",
"|S41",
"|S42",
"|S43",
"|S44",
"|S45",
"|S46",
"|S47",
"|S48",
"|S49",
"|S50",
"|S51",
"|S52",
"|S53",
"|S54",
"|S55",
"|S56",
"|S57",
"|S58",
"|S59",
"|S60",
"|S61",
"|S62",
"|S63",
"|S64",
"|S65",
"|S66",
"|S67",
"|S68",
"|S69",
"|S70",
"|S71",
"|S72",
"|S73",
"|S74",
"|S75",
"|S76",
"|S77",
"|S78",
"|S79",
"|S80",
"|S81",
"|S82",
"|S83",
"|S84",
"|S85",
"|S86",
"|S87",
"|S88",
"|S89",
"|S90",
"|S91",
"|S92",
"|S93",
"|S94",
"|S95",
"|S96",
"|S97",
"|S98",
"|S99",
"|S100",
"|S101",
"|S102",
"|S103",
"|S104",
"|S105",
"|S106",
"|S107",
"|S108",
"|S109",
"|S110",
"|S111",
"|S112",
"|S113",
"|S114",
"|S115",
"|S116",
"|S117",
"|S118",
"|S119",
"|S120",
"|S121",
"|S122",
"|S123",
"|S124",
"|S125",
"|S126",
"|S127",
"|S128",
"|S129",
"|S130",
"|S131",
"|S132",
"|S133",
"|S134",
"|S135",
"|S136",
"|S137",
"|S138",
"|S139",
"|S140",
"|S141",
"|S142",
"|S143",
"|S144",
"|S145",
"|S146",
"|S147",
"|S148",
"|S149",
"|S150",
"|S151",
"|S152",
"|S153",
"|S154"};
123 return c2numpy_float16;
129 return c2numpy_complex;
131 return c2numpy_complex64;
133 return c2numpy_complex128;
166 std::stringstream fileNameStream;
169 fileNameStream <<
".npy";
171 writer->
file = fopen(fileName.c_str(),
"wb");
173 std::stringstream headerStream;
174 headerStream <<
"{'descr': [";
180 headerStream <<
", ";
183 headerStream <<
"], 'fortran_order': False, 'shape': (";
191 headerStream <<
",), }";
193 int headerSize = headerStream.str().size();
196 if (headerSize > 65535) version = 2;
197 while ((6 + 2 + (version == 1 ? 2 : 4) + headerSize) % 16 != 0) {
200 if (headerSize > 65535) version = 2;
203 fwrite(
"\x93NUMPY", 1, 6, writer->
file);
205 fwrite(
"\x01\x00", 1, 2, writer->
file);
206 fwrite(&headerSize, 1, 2, writer->
file);
210 fwrite(
"\x02\x00", 1, 2, writer->
file);
211 fwrite(&headerSize, 1, 4, writer->
file);
216 fwrite(header.c_str(), 1, header.size(), writer->
file);
221 #define C2NUMPY_CHECK_ITEM { \ 222 if (writer->file == NULL) { \ 223 int status = c2numpy_open(writer); \ 229 #define C2NUMPY_INCREMENT_ITEM { \ 230 if (writer->currentColumn == 0) { \ 231 writer->currentRowInFile += 1; \ 232 if (writer->currentRowInFile == writer->numRowsPerFile) { \ 233 fclose(writer->file); \ 234 writer->file = NULL; \ 235 writer->currentRowInFile = 0; \ 236 writer->currentFileNumber += 1; \ 245 fwrite(&data,
sizeof(int8_t), 1, writer->
file);
253 fwrite(&data,
sizeof(int64_t), 1, writer->
file);
261 fwrite(&data,
sizeof(
int), 1, writer->
file);
269 fwrite(&data,
sizeof(
size_t), 1, writer->
file);
277 fwrite(&data,
sizeof(int8_t), 1, writer->
file);
285 fwrite(&data,
sizeof(int16_t), 1, writer->
file);
293 fwrite(&data,
sizeof(int32_t), 1, writer->
file);
301 fwrite(&data,
sizeof(int64_t), 1, writer->
file);
309 fwrite(&data,
sizeof(uint8_t), 1, writer->
file);
317 fwrite(&data,
sizeof(uint16_t), 1, writer->
file);
325 fwrite(&data,
sizeof(uint32_t), 1, writer->
file);
333 fwrite(&data,
sizeof(uint64_t), 1, writer->
file);
341 fwrite(&data,
sizeof(
double), 1, writer->
file);
357 fwrite(&data,
sizeof(
float), 1, writer->
file);
365 fwrite(&data,
sizeof(
double), 1, writer->
file);
398 if (0 < stringlength && stringlength < 155)
399 fwrite(data, 1, stringlength, writer->
file);
408 if (writer->
file != NULL) {
416 fputc(
' ', writer->
file);
422 fclose(writer->
file);
int c2numpy_int32(c2numpy_writer *writer, int32_t data)
#define C2NUMPY_CHECK_ITEM
int c2numpy_init(c2numpy_writer *writer, const std::string outputFilePrefix, int32_t numRowsPerFile)
const char * C2NUMPY_VERSION
int c2numpy_int(c2numpy_writer *writer, int64_t data)
int32_t currentFileNumber
int c2numpy_int16(c2numpy_writer *writer, int16_t data)
int c2numpy_bool(c2numpy_writer *writer, int8_t data)
std::vector< std::string > columnNames
int c2numpy_uint64(c2numpy_writer *writer, uint64_t data)
int c2numpy_int8(c2numpy_writer *writer, int8_t data)
int c2numpy_close(c2numpy_writer *writer)
int c2numpy_uint16(c2numpy_writer *writer, uint16_t data)
std::vector< c2numpy_type > columnTypes
int c2numpy_addcolumn(c2numpy_writer *writer, const std::string name, c2numpy_type type)
int c2numpy_intp(c2numpy_writer *writer, size_t data)
int c2numpy_open(c2numpy_writer *writer)
int c2numpy_uint32(c2numpy_writer *writer, uint32_t data)
int c2numpy_uint8(c2numpy_writer *writer, uint8_t data)
int c2numpy_int64(c2numpy_writer *writer, int64_t data)
int c2numpy_float64(c2numpy_writer *writer, double data)
const char * c2numpy_descr(c2numpy_type type)
#define C2NUMPY_INCREMENT_ITEM
int c2numpy_string(c2numpy_writer *writer, const char *data)
std::string outputFilePrefix
int c2numpy_float(c2numpy_writer *writer, double data)
int c2numpy_float32(c2numpy_writer *writer, float data)
std::vector< std::string > column
int c2numpy_intc(c2numpy_writer *writer, int data)