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 cdb8e51

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

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+51
-54
lines changed

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

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

75
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
86
#define _MULTIARRAYMODULE
97
#include "numpy/arrayobject.h"
108
#include "numpy/arrayscalars.h"
9+
10+
#include "npy_config.h"
1111
#include "npy_pycompat.h"
1212

13-
#include "common.h"
13+
#include "array_assign.h"
1414
#include "arrayobject.h"
15+
#include "common.h"
16+
#include "convert.h"
1517
#include "ctors.h"
16-
#include "mapping.h"
1718
#include "lowlevel_strided_loops.h"
19+
#include "mapping.h"
1820
#include "scalartypes.h"
19-
#include "array_assign.h"
20-
21-
#include "convert.h"
2221

2322
int
2423
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);
3029
* returns -1 and raises exception on no space, ignores all other errors
3130
*/
3231
static int
33-
npy_fallocate(npy_intp nbytes, FILE * fp)
32+
npy_fallocate(npy_intp nbytes, FILE *fp)
3433
{
3534
/*
3635
* unknown behavior on non-linux so don't try it
@@ -61,8 +60,10 @@ npy_fallocate(npy_intp nbytes, FILE * fp)
6160
* early exit on no space, other errors will also get found during fwrite
6261
*/
6362
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);
6667
return -1;
6768
}
6869
#endif
@@ -95,7 +96,7 @@ recursive_tolist(PyArrayObject *self, char *dataptr, int startdim)
9596
}
9697

9798
for (i = 0; i < n; ++i) {
98-
item = recursive_tolist(self, dataptr, startdim+1);
99+
item = recursive_tolist(self, dataptr, startdim + 1);
99100
if (item == NULL) {
100101
Py_DECREF(ret);
101102
return NULL;
@@ -138,7 +139,8 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
138139
if (n3 == 0) {
139140
/* binary data */
140141
if (PyDataType_FLAGCHK(PyArray_DESCR(self), NPY_LIST_PICKLE)) {
141-
PyErr_SetString(PyExc_IOError,
142+
PyErr_SetString(
143+
PyExc_IOError,
142144
"cannot write object arrays to a file in binary mode");
143145
return -1;
144146
}
@@ -154,7 +156,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
154156
size = PyArray_SIZE(self);
155157
NPY_BEGIN_ALLOW_THREADS;
156158

157-
#if defined (_MSC_VER) && defined(_WIN64)
159+
#if defined(_MSC_VER) && defined(_WIN64)
158160
/* Workaround Win64 fwrite() bug. Ticket #1660 */
159161
{
160162
npy_intp maxsize = 2147483648 / PyArray_DESCR(self)->elsize;
@@ -163,10 +165,11 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
163165
n = 0;
164166
while (size > 0) {
165167
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);
170173
if (n2 < chunksize) {
171174
break;
172175
}
@@ -177,30 +180,28 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
177180
}
178181
#else
179182
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);
182184
#endif
183185
NPY_END_ALLOW_THREADS;
184186
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);
188189
return -1;
189190
}
190191
}
191192
else {
192193
NPY_BEGIN_THREADS_DEF;
193194

194-
it = (PyArrayIterObject *) PyArray_IterNew((PyObject *)self);
195+
it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
195196
NPY_BEGIN_THREADS;
196197
while (it->index < it->size) {
197198
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) {
200200
NPY_END_THREADS;
201201
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);
204205
Py_DECREF(it);
205206
return -1;
206207
}
@@ -215,8 +216,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
215216
* text data
216217
*/
217218

218-
it = (PyArrayIterObject *)
219-
PyArray_IterNew((PyObject *)self);
219+
it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);
220220
n4 = (format ? strlen((const char *)format) : 0);
221221
while (it->index < it->size) {
222222
obj = PyArray_GETITEM(self, it->dataptr);
@@ -244,7 +244,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
244244
Py_DECREF(it);
245245
return -1;
246246
}
247-
PyTuple_SET_ITEM(tupobj,0,obj);
247+
PyTuple_SET_ITEM(tupobj, 0, obj);
248248
obj = PyUnicode_FromString((const char *)format);
249249
if (obj == NULL) {
250250
Py_DECREF(tupobj);
@@ -267,17 +267,18 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
267267
Py_DECREF(byteobj);
268268
if (n < n2) {
269269
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);
272273
Py_DECREF(strobj);
273274
Py_DECREF(it);
274275
return -1;
275276
}
276277
/* write separator for all but last one */
277-
if (it->index != it->size-1) {
278+
if (it->index != it->size - 1) {
278279
if (fwrite(sep, 1, n3, fp) < n3) {
279280
PyErr_Format(PyExc_IOError,
280-
"problem writing separator to file");
281+
"problem writing separator to file");
281282
Py_DECREF(strobj);
282283
Py_DECREF(it);
283284
return -1;
@@ -313,9 +314,10 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
313314
*/
314315

315316
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);
319321
}
320322
else {
321323
PyObject *new;
@@ -335,7 +337,7 @@ PyArray_ToString(PyArrayObject *self, NPY_ORDER order)
335337
if (it == NULL) {
336338
return NULL;
337339
}
338-
ret = PyBytes_FromStringAndSize(NULL, (Py_ssize_t) numbytes);
340+
ret = PyBytes_FromStringAndSize(NULL, (Py_ssize_t)numbytes);
339341
if (ret == NULL) {
340342
Py_DECREF(it);
341343
return NULL;
@@ -368,8 +370,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
368370
* the element in that array instead.
369371
*/
370372
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)) {
373374
value = (char *)&obj;
374375

375376
dtype = PyArray_DescrFromType(NPY_OBJECT);
@@ -469,8 +470,8 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
469470
/* Use the value pointer we got if possible */
470471
if (value != NULL) {
471472
/* 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);
474475
Py_DECREF(dtype);
475476
return retcode;
476477
}
@@ -484,15 +485,15 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
484485
* recognized as a struct scalar of the required type.
485486
*/
486487
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);
489490
if (src_arr == NULL) {
490491
return -1;
491492
}
492493

493494
if (PyArray_NDIM(src_arr) != 0) {
494495
PyErr_SetString(PyExc_ValueError,
495-
"Input object to FillWithScalar is not a scalar");
496+
"Input object to FillWithScalar is not a scalar");
496497
Py_DECREF(src_arr);
497498
return -1;
498499
}
@@ -513,8 +514,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
513514
* Returns 0 on success, -1 on failure.
514515
*/
515516
NPY_NO_EXPORT int
516-
PyArray_AssignZero(PyArrayObject *dst,
517-
PyArrayObject *wheremask)
517+
PyArray_AssignZero(PyArrayObject *dst, PyArrayObject *wheremask)
518518
{
519519
npy_bool value;
520520
PyArray_Descr *bool_dtype;
@@ -534,7 +534,6 @@ PyArray_AssignZero(PyArrayObject *dst,
534534
return retcode;
535535
}
536536

537-
538537
/*NUMPY_API
539538
* Copy an array.
540539
*/
@@ -580,11 +579,9 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)
580579

581580
Py_INCREF(dtype);
582581
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);
588585
if (ret == NULL) {
589586
Py_XDECREF(type);
590587
return NULL;

0 commit comments

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