You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 31, 2019. It is now read-only.
Copy file name to clipboardexpand all lines: README.md
+20-22
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# c2numpy
2
2
3
-
Write Numpy (.npy) files from C or C++ for analysis in [Numpy](http://www.numpy.org/), [Scipy](https://www.scipy.org/), [Scikit-Learn](http://scikit-learn.org/stable/), [Pandas](http://pandas.pydata.org/), etc.
3
+
Write Numpy (.npy) files from C++ for analysis in [Numpy](http://www.numpy.org/), [Scipy](https://www.scipy.org/), [Scikit-Learn](http://scikit-learn.org/stable/), [Pandas](http://pandas.pydata.org/), etc.
4
4
5
5
Fills a collection of .npy files with a maximum size, a common prefix and a rotating number (like rotating log files). Each file contains one [structured array](http://docs.scipy.org/doc/numpy/user/basics.rec.html), consisting of named, typed columns (numbers and fixed-size strings) and many rows. In Python, you access rows and columns with string and integer indexing:
6
6
@@ -10,11 +10,11 @@ myarray[3:5] # all columns, slice of rows
10
10
# etc.
11
11
```
12
12
13
-
This project does not support _reading_ of Numpy files in C.
13
+
This project does not support _reading_ of Numpy files in C++.
14
14
15
15
## Installation
16
16
17
-
Put `c2numpy.h` in your C or C++ project and compile. No libraries are required. Adheres to strict [ISO C99](http://www.iso-9899.info/wiki/The_Standard).
17
+
Put `c2numpy.h` in your C++ project and compile. No libraries are required. Earlier versions of this worked with strict C99, but this project now requires C++.
18
18
19
19
For an example and testing, `test.c` is provided. Compile and run it with
The original version of this project could be used in pure C projects, and hence it has a pure C API. However, now that the internals require C++, this API will be replaced by a C++ API. This documentation will always be in sync with the codebase (in the same branch of GitHub).
64
66
65
67
### Enumeration constants for Numpy types: `c2numpy_type`
66
68
67
69
See [number type definitions](http://docs.scipy.org/doc/numpy/user/basics.types.html) in the Numpy documentation.
68
70
69
-
```c
71
+
```c++
70
72
C2NUMPY_BOOL // Boolean (True or False) stored as a byte
71
73
C2NUMPY_INT // Default integer type (same as C long; normally either int64 or int32)
72
74
C2NUMPY_INTC // Identical to C int (normally int32 or int64)
@@ -103,18 +105,18 @@ Not currently supported:
103
105
104
106
A writer contains the following fields. Some of them are internal, and all of them should be treated as read-only. Use the associated functions to manipulate.
105
107
106
-
```c
108
+
```c++
107
109
typedefstruct {
108
110
char buffer[16]; // (internal) used for temporary copies in c2numpy_row
109
111
110
112
FILE *file; // output file handle
111
-
char *outputFilePrefix; // output file name, not including the rotating number and .npy
113
+
std::string outputFilePrefix; // output file name, not including the rotating number and .npy
112
114
int64_t sizeSeekPosition; // (internal) keep track of number of rows to modify before closing
113
115
int64_t sizeSeekSize; // (internal)
114
116
115
117
int32_t numColumns; // number of columns in the record array
@@ -163,7 +165,7 @@ This is the second function you should call on a new writer. Call it once for ea
163
165
164
166
### Optional open file: `c2numpy_open`
165
167
166
-
```c
168
+
```c++
167
169
int c2numpy_open(c2numpy_writer *writer);
168
170
```
169
171
@@ -175,7 +177,7 @@ Open a file and write its header to disk. If you don't call this explicitly, wri
175
177
176
178
The following suite of functions push one datum (item in a row/column) to the writer. They check the requested data type against the expected data type for the current column, but cannot prevent column-misalignment if all data types are the same.
177
179
178
-
```c
180
+
```c++
179
181
intc2numpy_bool(c2numpy_writer *writer, int8_t data); // "bool" is just a byte
180
182
int c2numpy_int(c2numpy_writer *writer, int64_t data); // Numpy's default int is 64-bit
181
183
int c2numpy_intc(c2numpy_writer *writer, int data); // the built-in C int
@@ -204,18 +206,14 @@ The string form, `c2numpy_string`, **only writes** the string `data`, so you are
204
206
205
207
### Required close file: `c2numpy_close`
206
208
207
-
```c
209
+
```c++
208
210
int c2numpy_close(c2numpy_writer *writer);
209
211
```
210
212
211
213
If you do not explicitly close the writer, your last file may be corrupted. Be sure to do this after your loop over data.
212
214
213
215
**Returns:** 0 if successful and -1 otherwise.
214
216
215
-
## C++ example and C++ API
216
-
217
-
Not written yet (will wrap the C functions with C++ class structure using [__cplusplus](http://stackoverflow.com/a/6779715/1623645)).
218
-
219
217
## To do
220
218
221
219
* Add convenience function to calculate number of rows for a target file size.
@@ -224,4 +222,4 @@ Not written yet (will wrap the C functions with C++ class structure using [__cpl
224
222
* Faster guessing of header size and column types.
225
223
* Float16 and complex numbers.
226
224
* Distinct return values for different errors and documentation of those errors.
0 commit comments