Skip to content
This repository was archived by the owner on Mar 31, 2019. It is now read-only.

Commit 090e5aa

Browse files
authored
Bring up to date with what's actually in the code
1 parent 134c49f commit 090e5aa

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

README.md

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# c2numpy
22

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.
44

55
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:
66

@@ -10,11 +10,11 @@ myarray[3:5] # all columns, slice of rows
1010
# etc.
1111
```
1212

13-
This project does not support _reading_ of Numpy files in C.
13+
This project does not support _reading_ of Numpy files in C++.
1414

1515
## Installation
1616

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++.
1818

1919
For an example and testing, `test.c` is provided. Compile and run it with
2020

@@ -29,9 +29,9 @@ python -c "import numpy; print numpy.load(open('testout0.npy'));"
2929
python -c "import numpy; print numpy.load(open('testout1.npy'));"
3030
```
3131

32-
## C example
32+
## C++ example
3333

34-
```c
34+
```c++
3535
// declare writer
3636
c2numpy_writer writer;
3737

@@ -60,13 +60,15 @@ c2numpy_string(&writer, "THREE");
6060
c2numpy_close(&writer);
6161
```
6262
63-
## C API
63+
## C-like API
64+
65+
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).
6466
6567
### Enumeration constants for Numpy types: `c2numpy_type`
6668
6769
See [number type definitions](http://docs.scipy.org/doc/numpy/user/basics.types.html) in the Numpy documentation.
6870
69-
```c
71+
```c++
7072
C2NUMPY_BOOL // Boolean (True or False) stored as a byte
7173
C2NUMPY_INT // Default integer type (same as C long; normally either int64 or int32)
7274
C2NUMPY_INTC // Identical to C int (normally int32 or int64)
@@ -103,18 +105,18 @@ Not currently supported:
103105

104106
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.
105107

106-
```c
108+
```c++
107109
typedef struct {
108110
char buffer[16]; // (internal) used for temporary copies in c2numpy_row
109111

110112
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
112114
int64_t sizeSeekPosition; // (internal) keep track of number of rows to modify before closing
113115
int64_t sizeSeekSize; // (internal)
114116

115117
int32_t numColumns; // number of columns in the record array
116-
char **columnNames; // column names
117-
c2numpy_type *columnTypes; // column types
118+
std::vector<std::string> columnNames; // column names
119+
std::vector<c2numpy_type> columnTypes; // column types
118120

119121
int32_t numRowsPerFile; // maximum number of rows per file
120122
int32_t currentColumn; // current column number
@@ -125,15 +127,15 @@ typedef struct {
125127

126128
### Numpy description string from type: `c2numpy_descr`
127129

128-
```c
130+
```c++
129131
const char *c2numpy_descr(c2numpy_type type);
130132
```
131133
132134
Rarely needed by typical users; converts a `c2numpy_type` to the corresponding Numpy "descr" string. **Returns** `NULL` if the `type` is invalid.
133135
134136
### Initialize a writer object: `c2numpy_init`
135137
136-
```c
138+
```c++
137139
int c2numpy_init(c2numpy_writer *writer, const char *outputFilePrefix, int32_t numRowsPerFile);
138140
```
139141

@@ -148,7 +150,7 @@ This is the first function you should call on a new writer. After this, call `c2
148150

149151
### Add a column to the writer: `c2numpy_addcolumn`
150152

151-
```c
153+
```c++
152154
int c2numpy_addcolumn(c2numpy_writer *writer, const char *name, c2numpy_type type);
153155
```
154156
@@ -163,7 +165,7 @@ This is the second function you should call on a new writer. Call it once for ea
163165
164166
### Optional open file: `c2numpy_open`
165167
166-
```c
168+
```c++
167169
int c2numpy_open(c2numpy_writer *writer);
168170
```
169171

@@ -175,7 +177,7 @@ Open a file and write its header to disk. If you don't call this explicitly, wri
175177

176178
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.
177179

178-
```c
180+
```c++
179181
int c2numpy_bool(c2numpy_writer *writer, int8_t data); // "bool" is just a byte
180182
int c2numpy_int(c2numpy_writer *writer, int64_t data); // Numpy's default int is 64-bit
181183
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
204206
205207
### Required close file: `c2numpy_close`
206208
207-
```c
209+
```c++
208210
int c2numpy_close(c2numpy_writer *writer);
209211
```
210212

211213
If you do not explicitly close the writer, your last file may be corrupted. Be sure to do this after your loop over data.
212214

213215
**Returns:** 0 if successful and -1 otherwise.
214216

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-
219217
## To do
220218

221219
* 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
224222
* Faster guessing of header size and column types.
225223
* Float16 and complex numbers.
226224
* Distinct return values for different errors and documentation of those errors.
227-
* Optional C++ API.
225+
* C++ API.

0 commit comments

Comments
 (0)