1
1
#define PY_SSIZE_T_CLEAN
2
2
#include <Python.h>
3
- #include "structmember.h"
4
-
5
3
#include <npy_config.h>
6
4
5
+ #include "structmember.h"
6
+
7
7
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
8
8
#define _MULTIARRAYMODULE
9
- #include "numpy/arrayobject.h"
10
- #include "numpy/arrayscalars.h"
11
- #include "npy_pycompat.h"
12
-
13
- #include "common.h"
9
+ #include "array_assign.h"
14
10
#include "arrayobject.h"
11
+ #include "common.h"
12
+ #include "convert.h"
15
13
#include "ctors.h"
16
- #include "mapping.h"
17
14
#include "lowlevel_strided_loops.h"
15
+ #include "mapping.h"
16
+ #include "npy_pycompat.h"
17
+ #include "numpy/arrayobject.h"
18
+ #include "numpy/arrayscalars.h"
18
19
#include "scalartypes.h"
19
- #include "array_assign.h"
20
-
21
- #include "convert.h"
22
20
23
21
int
24
22
fallocate (int fd , int mode , off_t offset , off_t len );
@@ -30,7 +28,7 @@ fallocate(int fd, int mode, off_t offset, off_t len);
30
28
* returns -1 and raises exception on no space, ignores all other errors
31
29
*/
32
30
static int
33
- npy_fallocate (npy_intp nbytes , FILE * fp )
31
+ npy_fallocate (npy_intp nbytes , FILE * fp )
34
32
{
35
33
/*
36
34
* unknown behavior on non-linux so don't try it
@@ -61,8 +59,10 @@ npy_fallocate(npy_intp nbytes, FILE * fp)
61
59
* early exit on no space, other errors will also get found during fwrite
62
60
*/
63
61
if (r == -1 && errno == ENOSPC ) {
64
- PyErr_Format (PyExc_IOError , "Not enough free space to write "
65
- "%" NPY_INTP_FMT " bytes" , nbytes );
62
+ PyErr_Format (PyExc_IOError ,
63
+ "Not enough free space to write "
64
+ "%" NPY_INTP_FMT " bytes" ,
65
+ nbytes );
66
66
return -1 ;
67
67
}
68
68
#endif
@@ -95,7 +95,7 @@ recursive_tolist(PyArrayObject *self, char *dataptr, int startdim)
95
95
}
96
96
97
97
for (i = 0 ; i < n ; ++ i ) {
98
- item = recursive_tolist (self , dataptr , startdim + 1 );
98
+ item = recursive_tolist (self , dataptr , startdim + 1 );
99
99
if (item == NULL ) {
100
100
Py_DECREF (ret );
101
101
return NULL ;
@@ -138,8 +138,9 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
138
138
if (n3 == 0 ) {
139
139
/* binary data */
140
140
if (PyDataType_FLAGCHK (PyArray_DESCR (self ), NPY_LIST_PICKLE )) {
141
- PyErr_SetString (PyExc_IOError ,
142
- "cannot write object arrays to a file in binary mode" );
141
+ PyErr_SetString (
142
+ PyExc_IOError ,
143
+ "cannot write object arrays to a file in binary mode" );
143
144
return -1 ;
144
145
}
145
146
if (PyArray_DESCR (self )-> elsize == 0 ) {
@@ -154,7 +155,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
154
155
size = PyArray_SIZE (self );
155
156
NPY_BEGIN_ALLOW_THREADS ;
156
157
157
- #if defined (_MSC_VER ) && defined(_WIN64 )
158
+ #if defined(_MSC_VER ) && defined(_WIN64 )
158
159
/* Workaround Win64 fwrite() bug. Ticket #1660 */
159
160
{
160
161
npy_intp maxsize = 2147483648 / PyArray_DESCR (self )-> elsize ;
@@ -163,10 +164,11 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
163
164
n = 0 ;
164
165
while (size > 0 ) {
165
166
chunksize = (size > maxsize ) ? maxsize : size ;
166
- n2 = fwrite ((const void * )
167
- ((char * )PyArray_DATA (self ) + (n * PyArray_DESCR (self )-> elsize )),
168
- (size_t ) PyArray_DESCR (self )-> elsize ,
169
- (size_t ) chunksize , fp );
167
+ n2 = fwrite (
168
+ (const void * )((char * )PyArray_DATA (self ) +
169
+ (n * PyArray_DESCR (self )-> elsize )),
170
+ (size_t )PyArray_DESCR (self )-> elsize , (size_t )chunksize ,
171
+ fp );
170
172
if (n2 < chunksize ) {
171
173
break ;
172
174
}
@@ -177,30 +179,28 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
177
179
}
178
180
#else
179
181
n = fwrite ((const void * )PyArray_DATA (self ),
180
- (size_t ) PyArray_DESCR (self )-> elsize ,
181
- (size_t ) size , fp );
182
+ (size_t )PyArray_DESCR (self )-> elsize , (size_t )size , fp );
182
183
#endif
183
184
NPY_END_ALLOW_THREADS ;
184
185
if (n < size ) {
185
- PyErr_Format (PyExc_IOError ,
186
- "%ld requested and %ld written" ,
187
- (long ) size , (long ) n );
186
+ PyErr_Format (PyExc_IOError , "%ld requested and %ld written" ,
187
+ (long )size , (long )n );
188
188
return -1 ;
189
189
}
190
190
}
191
191
else {
192
192
NPY_BEGIN_THREADS_DEF ;
193
193
194
- it = (PyArrayIterObject * ) PyArray_IterNew ((PyObject * )self );
194
+ it = (PyArrayIterObject * )PyArray_IterNew ((PyObject * )self );
195
195
NPY_BEGIN_THREADS ;
196
196
while (it -> index < it -> size ) {
197
197
if (fwrite ((const void * )it -> dataptr ,
198
- (size_t ) PyArray_DESCR (self )-> elsize ,
199
- 1 , fp ) < 1 ) {
198
+ (size_t )PyArray_DESCR (self )-> elsize , 1 , fp ) < 1 ) {
200
199
NPY_END_THREADS ;
201
200
PyErr_Format (PyExc_IOError ,
202
- "problem writing element %" NPY_INTP_FMT
203
- " to file" , it -> index );
201
+ "problem writing element %" NPY_INTP_FMT
202
+ " to file" ,
203
+ it -> index );
204
204
Py_DECREF (it );
205
205
return -1 ;
206
206
}
@@ -215,8 +215,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
215
215
* text data
216
216
*/
217
217
218
- it = (PyArrayIterObject * )
219
- PyArray_IterNew ((PyObject * )self );
218
+ it = (PyArrayIterObject * )PyArray_IterNew ((PyObject * )self );
220
219
n4 = (format ? strlen ((const char * )format ) : 0 );
221
220
while (it -> index < it -> size ) {
222
221
obj = PyArray_GETITEM (self , it -> dataptr );
@@ -244,7 +243,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
244
243
Py_DECREF (it );
245
244
return -1 ;
246
245
}
247
- PyTuple_SET_ITEM (tupobj ,0 , obj );
246
+ PyTuple_SET_ITEM (tupobj , 0 , obj );
248
247
obj = PyUnicode_FromString ((const char * )format );
249
248
if (obj == NULL ) {
250
249
Py_DECREF (tupobj );
@@ -267,17 +266,18 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
267
266
Py_DECREF (byteobj );
268
267
if (n < n2 ) {
269
268
PyErr_Format (PyExc_IOError ,
270
- "problem writing element %" NPY_INTP_FMT
271
- " to file" , it -> index );
269
+ "problem writing element %" NPY_INTP_FMT
270
+ " to file" ,
271
+ it -> index );
272
272
Py_DECREF (strobj );
273
273
Py_DECREF (it );
274
274
return -1 ;
275
275
}
276
276
/* write separator for all but last one */
277
- if (it -> index != it -> size - 1 ) {
277
+ if (it -> index != it -> size - 1 ) {
278
278
if (fwrite (sep , 1 , n3 , fp ) < n3 ) {
279
279
PyErr_Format (PyExc_IOError ,
280
- "problem writing separator to file" );
280
+ "problem writing separator to file" );
281
281
Py_DECREF (strobj );
282
282
Py_DECREF (it );
283
283
return -1 ;
@@ -313,9 +313,10 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
313
313
*/
314
314
315
315
numbytes = PyArray_NBYTES (self );
316
- if ((PyArray_IS_C_CONTIGUOUS (self ) && (order == NPY_CORDER ))
317
- || (PyArray_IS_F_CONTIGUOUS (self ) && (order == NPY_FORTRANORDER ))) {
318
- ret = PyBytes_FromStringAndSize (PyArray_DATA (self ), (Py_ssize_t ) numbytes );
316
+ if ((PyArray_IS_C_CONTIGUOUS (self ) && (order == NPY_CORDER )) ||
317
+ (PyArray_IS_F_CONTIGUOUS (self ) && (order == NPY_FORTRANORDER ))) {
318
+ ret = PyBytes_FromStringAndSize (PyArray_DATA (self ),
319
+ (Py_ssize_t )numbytes );
319
320
}
320
321
else {
321
322
PyObject * new ;
@@ -335,7 +336,7 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
335
336
if (it == NULL ) {
336
337
return NULL ;
337
338
}
338
- ret = PyBytes_FromStringAndSize (NULL , (Py_ssize_t ) numbytes );
339
+ ret = PyBytes_FromStringAndSize (NULL , (Py_ssize_t )numbytes );
339
340
if (ret == NULL ) {
340
341
Py_DECREF (it );
341
342
return NULL ;
@@ -368,8 +369,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
368
369
* the element in that array instead.
369
370
*/
370
371
if (PyArray_DESCR (arr )-> type_num == NPY_OBJECT &&
371
- !(PyArray_Check (obj ) &&
372
- PyArray_NDIM ((PyArrayObject * )obj ) == 0 )) {
372
+ !(PyArray_Check (obj ) && PyArray_NDIM ((PyArrayObject * )obj ) == 0 )) {
373
373
value = (char * )& obj ;
374
374
375
375
dtype = PyArray_DescrFromType (NPY_OBJECT );
@@ -469,8 +469,8 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
469
469
/* Use the value pointer we got if possible */
470
470
if (value != NULL ) {
471
471
/* TODO: switch to SAME_KIND casting */
472
- retcode = PyArray_AssignRawScalar (arr , dtype , value ,
473
- NULL , NPY_UNSAFE_CASTING );
472
+ retcode = PyArray_AssignRawScalar (arr , dtype , value , NULL ,
473
+ NPY_UNSAFE_CASTING );
474
474
Py_DECREF (dtype );
475
475
return retcode ;
476
476
}
@@ -484,15 +484,15 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
484
484
* recognized as a struct scalar of the required type.
485
485
*/
486
486
Py_INCREF (PyArray_DTYPE (arr ));
487
- src_arr = (PyArrayObject * )PyArray_FromAny (obj ,
488
- PyArray_DTYPE ( arr ), 0 , 0 , 0 , NULL );
487
+ src_arr = (PyArrayObject * )PyArray_FromAny (obj , PyArray_DTYPE ( arr ), 0 ,
488
+ 0 , 0 , NULL );
489
489
if (src_arr == NULL ) {
490
490
return -1 ;
491
491
}
492
492
493
493
if (PyArray_NDIM (src_arr ) != 0 ) {
494
494
PyErr_SetString (PyExc_ValueError ,
495
- "Input object to FillWithScalar is not a scalar" );
495
+ "Input object to FillWithScalar is not a scalar" );
496
496
Py_DECREF (src_arr );
497
497
return -1 ;
498
498
}
@@ -513,8 +513,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
513
513
* Returns 0 on success, -1 on failure.
514
514
*/
515
515
NPY_NO_EXPORT int
516
- PyArray_AssignZero (PyArrayObject * dst ,
517
- PyArrayObject * wheremask )
516
+ PyArray_AssignZero (PyArrayObject * dst , PyArrayObject * wheremask )
518
517
{
519
518
npy_bool value ;
520
519
PyArray_Descr * bool_dtype ;
@@ -534,7 +533,6 @@ PyArray_AssignZero(PyArrayObject *dst,
534
533
return retcode ;
535
534
}
536
535
537
-
538
536
/*NUMPY_API
539
537
* Copy an array.
540
538
*/
@@ -580,11 +578,9 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)
580
578
581
579
Py_INCREF (dtype );
582
580
ret = (PyArrayObject * )PyArray_NewFromDescr_int (
583
- subtype , dtype ,
584
- PyArray_NDIM (self ), PyArray_DIMS (self ), PyArray_STRIDES (self ),
585
- PyArray_DATA (self ),
586
- flags , (PyObject * )self , (PyObject * )self ,
587
- 0 , 1 );
581
+ subtype , dtype , PyArray_NDIM (self ), PyArray_DIMS (self ),
582
+ PyArray_STRIDES (self ), PyArray_DATA (self ), flags , (PyObject * )self ,
583
+ (PyObject * )self , 0 , 1 );
588
584
if (ret == NULL ) {
589
585
Py_XDECREF (type );
590
586
return NULL ;
0 commit comments