Skip to content

Commit

Permalink
Merge pull request numpy#14483 from seberg/clang-fixes
Browse files Browse the repository at this point in the history
BUG,MAINT: Some fixes and minor cleanup based on clang analysis
  • Loading branch information
mattip authored Sep 12, 2019
2 parents bc2d265 + e256762 commit 842079e
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 73 deletions.
29 changes: 0 additions & 29 deletions numpy/core/src/multiarray/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,35 +543,6 @@ PyArray_AssignZero(PyArrayObject *dst,
return retcode;
}

/*
* Fills an array with ones.
*
* dst: The destination array.
* wheremask: If non-NULL, a boolean mask specifying where to set the values.
*
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
PyArray_AssignOne(PyArrayObject *dst,
PyArrayObject *wheremask)
{
npy_bool value;
PyArray_Descr *bool_dtype;
int retcode;

/* Create a raw bool scalar with the value True */
bool_dtype = PyArray_DescrFromType(NPY_BOOL);
if (bool_dtype == NULL) {
return -1;
}
value = 1;

retcode = PyArray_AssignRawScalar(dst, bool_dtype, (char *)&value,
wheremask, NPY_SAFE_CASTING);

Py_DECREF(bool_dtype);
return retcode;
}

/*NUMPY_API
* Copy an array.
Expand Down
22 changes: 0 additions & 22 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,28 +1426,6 @@ _dtype_from_buffer_3118(PyObject *memoryview)
}


/*
* Call the python _is_from_ctypes
*/
NPY_NO_EXPORT int
_is_from_ctypes(PyObject *obj) {
PyObject *ret_obj;
static PyObject *py_func = NULL;

npy_cache_import("numpy.core._internal", "_is_from_ctypes", &py_func);

if (py_func == NULL) {
return -1;
}
ret_obj = PyObject_CallFunctionObjArgs(py_func, obj, NULL);
if (ret_obj == NULL) {
return -1;
}

return PyObject_IsTrue(ret_obj);
}


NPY_NO_EXPORT PyObject *
_array_from_buffer_3118(PyObject *memoryview)
{
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/dtype_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3337,7 +3337,7 @@ get_decsrcref_transfer_function(int aligned,
/* If there are subarrays, need to wrap it */
else if (PyDataType_HASSUBARRAY(src_dtype)) {
PyArray_Dims src_shape = {NULL, -1};
npy_intp src_size = 1;
npy_intp src_size;
PyArray_StridedUnaryOp *stransfer;
NpyAuxData *data;

Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis)
int *swaps;

assert(N > 0); /* Guaranteed and assumed by indbuffer */
int valbufsize = N * maxelsize;
npy_intp valbufsize = N * maxelsize;
if (NPY_UNLIKELY(valbufsize) == 0) {
valbufsize = 1; /* Ensure allocation is not empty */
}
Expand Down
1 change: 0 additions & 1 deletion numpy/core/src/multiarray/iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
if (check_and_adjust_index(&start, self->size, -1, NULL) < 0) {
goto finish;
}
retval = 0;
PyArray_ITER_GOTO1D(self, start);
retval = type->f->setitem(val, self->dataptr, self->ao);
PyArray_ITER_RESET(self);
Expand Down
13 changes: 6 additions & 7 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,8 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
PyArrayObject *oparr = NULL, *ret = NULL;
npy_bool subok = NPY_FALSE;
npy_bool copy = NPY_TRUE;
int ndmin = 0, nd;
int nd;
npy_intp ndmin = 0;
PyArray_Descr *type = NULL;
PyArray_Descr *oldtype = NULL;
NPY_ORDER order = NPY_KEEPORDER;
Expand Down Expand Up @@ -1631,12 +1632,10 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
}
}

/* copy=False with default dtype, order and ndim */
if (STRIDING_OK(oparr, order)) {
ret = oparr;
Py_INCREF(ret);
goto finish;
}
/* copy=False with default dtype, order (any is OK) and ndim */
ret = oparr;
Py_INCREF(ret);
goto finish;
}
}

Expand Down
5 changes: 1 addition & 4 deletions numpy/core/src/multiarray/nditer_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1628,15 +1628,12 @@ npyiter_coalesce_axes(NpyIter *iter)
npy_intp istrides, nstrides = NAD_NSTRIDES();
NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
NpyIter_AxisData *ad_compress;
NpyIter_AxisData *ad_compress = axisdata;
npy_intp new_ndim = 1;

/* The HASMULTIINDEX or IDENTPERM flags do not apply after coalescing */
NIT_ITFLAGS(iter) &= ~(NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_HASMULTIINDEX);

axisdata = NIT_AXISDATA(iter);
ad_compress = axisdata;

for (idim = 0; idim < ndim-1; ++idim) {
int can_coalesce = 1;
npy_intp shape0 = NAD_SHAPE(ad_compress);
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/nditer_pywrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ npyiter_convert_dtypes(PyObject *op_dtypes_in,
}

static int
npyiter_convert_op_axes(PyObject *op_axes_in, npy_intp nop,
npyiter_convert_op_axes(PyObject *op_axes_in, int nop,
int **op_axes, int *oa_ndim)
{
PyObject *a;
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/src/multiarray/shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
{
npy_intp oldnbytes, newnbytes;
npy_intp oldsize, newsize;
int new_nd=newshape->len, k, n, elsize;
int new_nd=newshape->len, k, elsize;
int refcnt;
npy_intp* new_dimensions=newshape->ptr;
npy_intp new_strides[NPY_MAXDIMS];
Expand Down Expand Up @@ -136,8 +136,8 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
PyObject *zero = PyInt_FromLong(0);
char *optr;
optr = PyArray_BYTES(self) + oldnbytes;
n = newsize - oldsize;
for (k = 0; k < n; k++) {
npy_intp n_new = newsize - oldsize;
for (npy_intp i = 0; i < n_new; i++) {
_putzero((char *)optr, zero, PyArray_DESCR(self));
optr += elsize;
}
Expand Down
8 changes: 4 additions & 4 deletions numpy/core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ parse_ufunc_keywords(PyUFuncObject *ufunc, PyObject *kwds, PyObject **kwnames, .
typedef int converter(PyObject *, void *);

while (PyDict_Next(kwds, &pos, &key, &value)) {
int i;
npy_intp i;
converter *convert;
void *output = NULL;
npy_intp index = locate_key(kwnames, key);
Expand Down Expand Up @@ -4053,14 +4053,14 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
int *op_axes[3] = {op_axes_arrays[0], op_axes_arrays[1],
op_axes_arrays[2]};
npy_uint32 op_flags[3];
int i, idim, ndim, otype_final;
int idim, ndim, otype_final;
int need_outer_iterator = 0;

NpyIter *iter = NULL;

/* The reduceat indices - ind must be validated outside this call */
npy_intp *reduceat_ind;
npy_intp ind_size, red_axis_size;
npy_intp i, ind_size, red_axis_size;
/* The selected inner loop */
PyUFuncGenericFunction innerloop = NULL;
void *innerloopdata = NULL;
Expand Down Expand Up @@ -4146,7 +4146,7 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
#endif

/* Set up the op_axes for the outer loop */
for (i = 0, idim = 0; idim < ndim; ++idim) {
for (idim = 0; idim < ndim; ++idim) {
/* Use the i-th iteration dimension to match up ind */
if (idim == axis) {
op_axes_arrays[0][idim] = axis;
Expand Down

0 comments on commit 842079e

Please sign in to comment.