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