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