Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 082646f

Browse filesBrowse files
committed
STY: Apply clang-format to convert.c
This is to provide an example for inspection.
1 parent eb100b4 commit 082646f
Copy full SHA for 082646f

File tree

1 file changed

+50
-52
lines changed
Filter options

1 file changed

+50
-52
lines changed

‎numpy/core/src/multiarray/convert.c

Copy file name to clipboardExpand all lines: numpy/core/src/multiarray/convert.c
+50-52Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#define PY_SSIZE_T_CLEAN
22
#include <Python.h>
3-
#include "structmember.h"
3+
#include <structmember.h>
44

55
#include <npy_config.h>
66

77
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
88
#define _MULTIARRAYMODULE
99
#include "numpy/arrayobject.h"
1010
#include "numpy/arrayscalars.h"
11+
1112
#include "npy_pycompat.h"
1213

13-
#include "common.h"
14+
#include "array_assign.h"
1415
#include "arrayobject.h"
16+
#include "common.h"
17+
#include "convert.h"
1518
#include "ctors.h"
16-
#include "mapping.h"
1719
#include "lowlevel_strided_loops.h"
20+
#include "mapping.h"
1821
#include "scalartypes.h"
19-
#include "array_assign.h"
20-
21-
#include "convert.h"
2222

2323
int
2424
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);
3030
* returns -1 and raises exception on no space, ignores all other errors
3131
*/
3232
static int
33-
npy_fallocate(npy_intp nbytes, FILE * fp)
33+
npy_fallocate(npy_intp nbytes, FILE *fp)
3434
{
3535
/*
3636
* unknown behavior on non-linux so don't try it
@@ -61,8 +61,10 @@ npy_fallocate(npy_intp nbytes, FILE * fp)
6161
* early exit on no space, other errors will also get found during fwrite
6262
*/
6363
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);
6668
return -1;
6769
}
6870
#endif
@@ -95,7 +97,7 @@ recursive_tolist(PyArrayObject *self, char *dataptr, int startdim)
9597
}
9698

9799
for (i = 0; i < n; ++i) {
98-
item = recursive_tolist(self, dataptr, startdim+1);
100+
item = recursive_tolist(self, dataptr, startdim + 1);
99101
if (item == NULL) {
100102
Py_DECREF(ret);
101103
return NULL;
@@ -138,7 +140,8 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
138140
if (n3 == 0) {
139141
/* binary data */
140142
if (PyDataType_FLAGCHK(PyArray_DESCR(self), NPY_LIST_PICKLE)) {
141-
PyErr_SetString(PyExc_OSError,
143+
PyErr_SetString(
144+
PyExc_OSError,
142145
"cannot write object arrays to a file in binary mode");
143146
return -1;
144147
}
@@ -154,7 +157,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
154157
size = PyArray_SIZE(self);
155158
NPY_BEGIN_ALLOW_THREADS;
156159

157-
#if defined (_MSC_VER) && defined(_WIN64)
160+
#if defined(_MSC_VER) && defined(_WIN64)
158161
/* Workaround Win64 fwrite() bug. Ticket #1660 */
159162
{
160163
npy_intp maxsize = 2147483648 / PyArray_DESCR(self)->elsize;
@@ -163,10 +166,11 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
163166
n = 0;
164167
while (size > 0) {
165168
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);
170174
if (n2 < chunksize) {
171175
break;
172176
}
@@ -177,30 +181,28 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
177181
}
178182
#else
179183
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);
182185
#endif
183186
NPY_END_ALLOW_THREADS;
184187
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);
188190
return -1;
189191
}
190192
}
191193
else {
192194
NPY_BEGIN_THREADS_DEF;
193195

194-
it = (PyArrayIterObject *) PyArray_IterNew((PyObject *)self);
196+
it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
195197
NPY_BEGIN_THREADS;
196198
while (it->index < it->size) {
197199
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) {
200201
NPY_END_THREADS;
201202
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);
204206
Py_DECREF(it);
205207
return -1;
206208
}
@@ -215,8 +217,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
215217
* text data
216218
*/
217219

218-
it = (PyArrayIterObject *)
219-
PyArray_IterNew((PyObject *)self);
220+
it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
220221
n4 = (format ? strlen((const char *)format) : 0);
221222
while (it->index < it->size) {
222223
obj = PyArray_GETITEM(self, it->dataptr);
@@ -244,7 +245,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
244245
Py_DECREF(it);
245246
return -1;
246247
}
247-
PyTuple_SET_ITEM(tupobj,0,obj);
248+
PyTuple_SET_ITEM(tupobj, 0, obj);
248249
obj = PyUnicode_FromString((const char *)format);
249250
if (obj == NULL) {
250251
Py_DECREF(tupobj);
@@ -267,17 +268,18 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
267268
Py_DECREF(byteobj);
268269
if (n < n2) {
269270
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);
272274
Py_DECREF(strobj);
273275
Py_DECREF(it);
274276
return -1;
275277
}
276278
/* write separator for all but last one */
277-
if (it->index != it->size-1) {
279+
if (it->index != it->size - 1) {
278280
if (fwrite(sep, 1, n3, fp) < n3) {
279281
PyErr_Format(PyExc_OSError,
280-
"problem writing separator to file");
282+
"problem writing separator to file");
281283
Py_DECREF(strobj);
282284
Py_DECREF(it);
283285
return -1;
@@ -313,9 +315,10 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
313315
*/
314316

315317
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);
319322
}
320323
else {
321324
PyObject *new;
@@ -335,7 +338,7 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
335338
if (it == NULL) {
336339
return NULL;
337340
}
338-
ret = PyBytes_FromStringAndSize(NULL, (Py_ssize_t) numbytes);
341+
ret = PyBytes_FromStringAndSize(NULL, (Py_ssize_t)numbytes);
339342
if (ret == NULL) {
340343
Py_DECREF(it);
341344
return NULL;
@@ -368,8 +371,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
368371
* the element in that array instead.
369372
*/
370373
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)) {
373375
value = (char *)&obj;
374376

375377
dtype = PyArray_DescrFromType(NPY_OBJECT);
@@ -469,8 +471,8 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
469471
/* Use the value pointer we got if possible */
470472
if (value != NULL) {
471473
/* 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);
474476
Py_DECREF(dtype);
475477
return retcode;
476478
}
@@ -484,15 +486,15 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
484486
* recognized as a struct scalar of the required type.
485487
*/
486488
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);
489491
if (src_arr == NULL) {
490492
return -1;
491493
}
492494

493495
if (PyArray_NDIM(src_arr) != 0) {
494496
PyErr_SetString(PyExc_ValueError,
495-
"Input object to FillWithScalar is not a scalar");
497+
"Input object to FillWithScalar is not a scalar");
496498
Py_DECREF(src_arr);
497499
return -1;
498500
}
@@ -513,8 +515,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
513515
* Returns 0 on success, -1 on failure.
514516
*/
515517
NPY_NO_EXPORT int
516-
PyArray_AssignZero(PyArrayObject *dst,
517-
PyArrayObject *wheremask)
518+
PyArray_AssignZero(PyArrayObject *dst, PyArrayObject *wheremask)
518519
{
519520
npy_bool value;
520521
PyArray_Descr *bool_dtype;
@@ -534,7 +535,6 @@ PyArray_AssignZero(PyArrayObject *dst,
534535
return retcode;
535536
}
536537

537-
538538
/*NUMPY_API
539539
* Copy an array.
540540
*/
@@ -580,11 +580,9 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)
580580

581581
Py_INCREF(dtype);
582582
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);
588586
if (ret == NULL) {
589587
Py_XDECREF(type);
590588
return NULL;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.