43 #include "../utility/print_function.hpp"
55 char map_type(
const std::type_info& t);
57 void split(vector<string>& strs,
string& input,
const string& pat);
85 ,
const size_t data_len,
const size_t numcols
90 (char)0x93,
'N',
'U',
'M',
'P',
'Y'
91 , (
char)0x01, (char) 0x00
97 ,
const vector<string>& colnames
98 , vector<unsigned int>shape ,
char version
102 fseek( fp, 0, SEEK_SET );
107 dict +=
"{'descr': [";
108 for( vector<string>::const_iterator it = colnames.begin();
109 it != colnames.end(); it++ )
110 dict +=
"('" + *it +
"' , '" + endianChar + formatChar +
"'),";
112 dict +=
"], 'fortran_order': False, 'shape': (";
114 for(
size_t i = 1; i < shape.size(); i++)
119 if( shape.size() == 1) dict +=
",";
128 dict += string(11,
' ');
133 unsigned int remainder = 16 - (12 + dict.size()) % 16;
134 dict.insert(dict.end(),remainder,
' ');
135 *(dict.end()-1) =
'\n';
146 uint32_t s = dict.size();
147 fwrite( (
char*)&s,
sizeof( uint32_t ), 1, fp );
151 int16_t s = dict.size();
152 fwrite( (
char*)&s,
sizeof( uint16_t ), 1, fp );
154 fwrite( dict.c_str(),
sizeof(char), dict.size(), fp );
160 const string& outfile
161 ,
const vector<double>& vec
162 , vector<string> colnames
163 ,
const string openmode
164 ,
const char version =
'1'
170 vector<unsigned int> shape;
172 if( colnames.size() == 0)
175 shape.push_back( vec.size() / colnames.size());
180 if( openmode ==
"w" )
182 FILE* fp = fopen( outfile.c_str(),
"wb" );
188 write_header<T>( fp, colnames, shape, version );
194 FILE* fp = fopen( outfile.c_str(),
"r" );
203 +
" I am not goind to write to it"
213 FILE* fp = fopen( outfile.c_str(),
"ab" );
219 fwrite( &vec[0],
sizeof(T), vec.size(), fp );
string toString(double x)
Convert a given value to string.
char map_type(const std::type_info &t)
void split(vector< string > &strs, string &input, const string &pat)
static char __pre__[__pre__size__]
void write_header(FILE *fp, const vector< string > &colnames, vector< unsigned int >shape, char version)
void showError(string msg)
bool is_valid_numpy_file(FILE *fp)
Check if a numpy file is sane or not.
void save_numpy(const string &outfile, const vector< double > &vec, vector< string > colnames, const string openmode, const char version= '1')
static const unsigned int __pre__size__
void parse_header(FILE *fp, string &header)
Parser header from a numpy file. Store it in vector.
void showWarn(string msg)
void change_shape_in_header(const string &filename, const size_t data_len, const size_t numcols)
Change shape in numpy header.