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 5aa1593

Browse filesBrowse files
committed
STY: Apply clang-format to convert.c
This is to provide an example of the result for review.
1 parent 440a190 commit 5aa1593
Copy full SHA for 5aa1593

File tree

Expand file treeCollapse file tree

1 file changed

+54
-58
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+54
-58
lines changed

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

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

5+
#include "structmember.h"
6+
77
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
88
#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"
1410
#include "arrayobject.h"
11+
#include "common.h"
12+
#include "convert.h"
1513
#include "ctors.h"
16-
#include "mapping.h"
1714
#include "lowlevel_strided_loops.h"
15+
#include "mapping.h"
16+
#include "npy_pycompat.h"
17+
#include "numpy/arrayobject.h"
18+
#include "numpy/arrayscalars.h"
1819
#include "scalartypes.h"
19-
#include "array_assign.h"
20-
21-
#include "convert.h"
2220

2321
int
2422
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);
3028
* returns -1 and raises exception on no space, ignores all other errors
3129
*/
3230
static int
33-
npy_fallocate(npy_intp nbytes, FILE * fp)
31+
npy_fallocate(npy_intp nbytes, FILE *fp)
3432
{
3533
/*
3634
* unknown behavior on non-linux so don't try it
@@ -61,8 +59,10 @@ npy_fallocate(npy_intp nbytes, FILE * fp)
6159
* early exit on no space, other errors will also get found during fwrite
6260
*/
6361
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);
6666
return -1;
6767
}
6868
#endif
@@ -95,7 +95,7 @@ recursive_tolist(PyArrayObject *self, char *dataptr, int startdim)
9595
}
9696

9797
for (i = 0; i < n; ++i) {
98-
item = recursive_tolist(self, dataptr, startdim+1);
98+
item = recursive_tolist(self, dataptr, startdim + 1);
9999
if (item == NULL) {
100100
Py_DECREF(ret);
101101
return NULL;
@@ -138,8 +138,9 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
138138
if (n3 == 0) {
139139
/* binary data */
140140
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");
143144
return -1;
144145
}
145146
if (PyArray_DESCR(self)->elsize == 0) {
@@ -154,7 +155,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
154155
size = PyArray_SIZE(self);
155156
NPY_BEGIN_ALLOW_THREADS;
156157

157-
#if defined (_MSC_VER) && defined(_WIN64)
158+
#if defined(_MSC_VER) && defined(_WIN64)
158159
/* Workaround Win64 fwrite() bug. Ticket #1660 */
159160
{
160161
npy_intp maxsize = 2147483648 / PyArray_DESCR(self)->elsize;
@@ -163,10 +164,11 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
163164
n = 0;
164165
while (size > 0) {
165166
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);
170172
if (n2 < chunksize) {
171173
break;
172174
}
@@ -177,30 +179,28 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
177179
}
178180
#else
179181
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);
182183
#endif
183184
NPY_END_ALLOW_THREADS;
184185
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);
188188
return -1;
189189
}
190190
}
191191
else {
192192
NPY_BEGIN_THREADS_DEF;
193193

194-
it = (PyArrayIterObject *) PyArray_IterNew((PyObject *)self);
194+
it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
195195
NPY_BEGIN_THREADS;
196196
while (it->index < it->size) {
197197
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) {
200199
NPY_END_THREADS;
201200
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);
204204
Py_DECREF(it);
205205
return -1;
206206
}
@@ -215,8 +215,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
215215
* text data
216216
*/
217217

218-
it = (PyArrayIterObject *)
219-
PyArray_IterNew((PyObject *)self);
218+
it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
220219
n4 = (format ? strlen((const char *)format) : 0);
221220
while (it->index < it->size) {
222221
obj = PyArray_GETITEM(self, it->dataptr);
@@ -244,7 +243,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
244243
Py_DECREF(it);
245244
return -1;
246245
}
247-
PyTuple_SET_ITEM(tupobj,0,obj);
246+
PyTuple_SET_ITEM(tupobj, 0, obj);
248247
obj = PyUnicode_FromString((const char *)format);
249248
if (obj == NULL) {
250249
Py_DECREF(tupobj);
@@ -267,17 +266,18 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
267266
Py_DECREF(byteobj);
268267
if (n < n2) {
269268
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);
272272
Py_DECREF(strobj);
273273
Py_DECREF(it);
274274
return -1;
275275
}
276276
/* write separator for all but last one */
277-
if (it->index != it->size-1) {
277+
if (it->index != it->size - 1) {
278278
if (fwrite(sep, 1, n3, fp) < n3) {
279279
PyErr_Format(PyExc_IOError,
280-
"problem writing separator to file");
280+
"problem writing separator to file");
281281
Py_DECREF(strobj);
282282
Py_DECREF(it);
283283
return -1;
@@ -313,9 +313,10 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
313313
*/
314314

315315
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);
319320
}
320321
else {
321322
PyObject *new;
@@ -335,7 +336,7 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
335336
if (it == NULL) {
336337
return NULL;
337338
}
338-
ret = PyBytes_FromStringAndSize(NULL, (Py_ssize_t) numbytes);
339+
ret = PyBytes_FromStringAndSize(NULL, (Py_ssize_t)numbytes);
339340
if (ret == NULL) {
340341
Py_DECREF(it);
341342
return NULL;
@@ -368,8 +369,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
368369
* the element in that array instead.
369370
*/
370371
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)) {
373373
value = (char *)&obj;
374374

375375
dtype = PyArray_DescrFromType(NPY_OBJECT);
@@ -469,8 +469,8 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
469469
/* Use the value pointer we got if possible */
470470
if (value != NULL) {
471471
/* 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);
474474
Py_DECREF(dtype);
475475
return retcode;
476476
}
@@ -484,15 +484,15 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
484484
* recognized as a struct scalar of the required type.
485485
*/
486486
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);
489489
if (src_arr == NULL) {
490490
return -1;
491491
}
492492

493493
if (PyArray_NDIM(src_arr) != 0) {
494494
PyErr_SetString(PyExc_ValueError,
495-
"Input object to FillWithScalar is not a scalar");
495+
"Input object to FillWithScalar is not a scalar");
496496
Py_DECREF(src_arr);
497497
return -1;
498498
}
@@ -513,8 +513,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
513513
* Returns 0 on success, -1 on failure.
514514
*/
515515
NPY_NO_EXPORT int
516-
PyArray_AssignZero(PyArrayObject *dst,
517-
PyArrayObject *wheremask)
516+
PyArray_AssignZero(PyArrayObject *dst, PyArrayObject *wheremask)
518517
{
519518
npy_bool value;
520519
PyArray_Descr *bool_dtype;
@@ -534,7 +533,6 @@ PyArray_AssignZero(PyArrayObject *dst,
534533
return retcode;
535534
}
536535

537-
538536
/*NUMPY_API
539537
* Copy an array.
540538
*/
@@ -580,11 +578,9 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)
580578

581579
Py_INCREF(dtype);
582580
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);
588584
if (ret == NULL) {
589585
Py_XDECREF(type);
590586
return NULL;

0 commit comments

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