Skip to content

BUG: ticket #1805, replace type char by signed char for tables. #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions numpy/core/src/multiarray/nditer.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ typedef struct NpyIter_BD NpyIter_BufferData;
(iter->iterend)
#define NIT_ITERINDEX(iter) \
(iter->iterindex)
#define NIT_PERM(iter) ((char*)( \
#define NIT_PERM(iter) ((npy_int8 *)( \
&(iter)->iter_flexdata + NIT_PERM_OFFSET()))
#define NIT_DTYPES(iter) ((PyArray_Descr **)( \
&(iter)->iter_flexdata + NIT_DTYPES_OFFSET(itflags, ndim, nop)))
Expand Down Expand Up @@ -398,7 +398,7 @@ NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32 flags,
char *op_itflags;
char **op_dataptr;

char *perm;
npy_int8 *perm;
NpyIter_BufferData *bufferdata = NULL;
int any_allocate = 0, any_missing_dtypes = 0,
output_scalars = 0, need_subtype = 0;
Expand Down Expand Up @@ -542,7 +542,7 @@ NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32 flags,
/* Initialize the perm to the identity */
perm = NIT_PERM(iter);
for(idim = 0; idim < ndim; ++idim) {
perm[idim] = (char)idim;
perm[idim] = (npy_int8)idim;
}

/*
Expand Down Expand Up @@ -976,7 +976,7 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis)
int iop, nop = NIT_NOP(iter);

int xdim = 0;
char *perm = NIT_PERM(iter);
npy_int8 *perm = NIT_PERM(iter);
NpyIter_AxisData *axisdata_del = NIT_AXISDATA(iter), *axisdata;
npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);

Expand Down Expand Up @@ -1008,7 +1008,7 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis)
}

/* Reverse axis, since the iterator treats them that way */
axis = ndim-1-axis;
axis = ndim - 1 - axis;

/* First find the axis in question */
for (idim = 0; idim < ndim; ++idim) {
Expand All @@ -1018,7 +1018,7 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis)
break;
}
/* If this is it, but it's iterated backward, must reverse the axis */
else if (-1-perm[idim] == axis) {
else if (-1 - perm[idim] == axis) {
npy_intp *strides = NAD_STRIDES(axisdata_del);
npy_intp shape = NAD_SHAPE(axisdata_del), offset;

Expand Down Expand Up @@ -1053,7 +1053,7 @@ NpyIter_RemoveAxis(NpyIter *iter, int axis)

/* Adjust the permutation */
for (idim = 0; idim < ndim-1; ++idim) {
char p = (idim < xdim) ? perm[idim] : perm[idim+1];
npy_int8 p = (idim < xdim) ? perm[idim] : perm[idim+1];
if (p >= 0) {
if (p > axis) {
--p;
Expand Down Expand Up @@ -1336,7 +1336,7 @@ NpyIter_GotoMultiIndex(NpyIter *iter, npy_intp *multi_index)
npy_intp iterindex, factor;
NpyIter_AxisData *axisdata;
npy_intp sizeof_axisdata;
char *perm;
npy_int8 *perm;

if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) {
PyErr_SetString(PyExc_ValueError,
Expand Down Expand Up @@ -1367,7 +1367,7 @@ NpyIter_GotoMultiIndex(NpyIter *iter, npy_intp *multi_index)
iterindex = 0;
factor = 1;
for (idim = 0; idim < ndim; ++idim) {
char p = perm[idim];
npy_int8 p = perm[idim];
npy_intp i, shape;

shape = NAD_SHAPE(axisdata);
Expand Down Expand Up @@ -2062,7 +2062,7 @@ npyiter_get_multi_index_itflags@tag_itflags@(
npy_intp sizeof_axisdata;
NpyIter_AxisData *axisdata;
#if !((@const_itflags@)&NPY_ITFLAG_IDENTPERM)
char* perm = NIT_PERM(iter);
npy_int8 *perm = NIT_PERM(iter);
#endif

axisdata = NIT_AXISDATA(iter);
Expand All @@ -2075,12 +2075,12 @@ npyiter_get_multi_index_itflags@tag_itflags@(
}
#elif !((@const_itflags@)&NPY_ITFLAG_NEGPERM)
for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
char p = perm[idim];
npy_int8 p = perm[idim];
out_multi_index[ndim-p-1] = NAD_INDEX(axisdata);
}
#else
for(idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
char p = perm[idim];
npy_int8 p = perm[idim];
if (p < 0) {
/* If the perm entry is negative, reverse the index */
out_multi_index[ndim+p] = NAD_SHAPE(axisdata) - NAD_INDEX(axisdata) - 1;
Expand Down Expand Up @@ -2358,15 +2358,15 @@ NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)

int idim, sizeof_axisdata;
NpyIter_AxisData *axisdata;
char *perm;
npy_int8 *perm;

axisdata = NIT_AXISDATA(iter);
sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);

if (itflags&NPY_ITFLAG_HASMULTIINDEX) {
perm = NIT_PERM(iter);
for(idim = 0; idim < ndim; ++idim) {
char p = perm[idim];
npy_int8 p = perm[idim];
if (p < 0) {
outshape[ndim+p] = NAD_SHAPE(axisdata);
}
Expand Down Expand Up @@ -2422,7 +2422,7 @@ NpyIter_CreateCompatibleStrides(NpyIter *iter,

npy_intp sizeof_axisdata;
NpyIter_AxisData *axisdata;
char *perm;
npy_int8 *perm;

if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) {
PyErr_SetString(PyExc_RuntimeError,
Expand All @@ -2436,7 +2436,7 @@ NpyIter_CreateCompatibleStrides(NpyIter *iter,

perm = NIT_PERM(iter);
for(idim = 0; idim < ndim; ++idim) {
char p = perm[idim];
npy_int8 p = perm[idim];
if (p < 0) {
PyErr_SetString(PyExc_RuntimeError,
"Iterator CreateCompatibleStrides may only be called "
Expand Down Expand Up @@ -2679,7 +2679,7 @@ NpyIter_GetAxisStrideArray(NpyIter *iter, int axis)
int idim, ndim = NIT_NDIM(iter);
int nop = NIT_NOP(iter);

char *perm = NIT_PERM(iter);
npy_int8 *perm = NIT_PERM(iter);
NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);

Expand All @@ -2695,7 +2695,7 @@ NpyIter_GetAxisStrideArray(NpyIter *iter, int axis)

/* First find the axis in question */
for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
if (perm[idim] == axis || -1-perm[idim] == axis) {
if (perm[idim] == axis || -1 - perm[idim] == axis) {
return NAD_STRIDES(axisdata);
}
}
Expand Down Expand Up @@ -3900,7 +3900,7 @@ npyiter_replace_axisdata(NpyIter *iter, int iop,

NpyIter_AxisData *axisdata0, *axisdata;
npy_intp sizeof_axisdata;
char *perm;
npy_int8 *perm;
npy_intp baseoffset = 0;

perm = NIT_PERM(iter);
Expand All @@ -3915,7 +3915,7 @@ npyiter_replace_axisdata(NpyIter *iter, int iop,

if (op_axes != NULL) {
for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
char p;
npy_int8 p;
int i;
npy_intp shape;

Expand Down Expand Up @@ -3946,7 +3946,7 @@ npyiter_replace_axisdata(NpyIter *iter, int iop,
}
else {
for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
char p;
npy_int8 p;
int i;
npy_intp shape;

Expand Down Expand Up @@ -4201,7 +4201,7 @@ npyiter_reverse_axis_ordering(NpyIter *iter)

npy_intp i, temp, size;
npy_intp *first, *last;
char *perm;
npy_int8 *perm;

size = NIT_AXISDATA_SIZEOF(itflags, ndim, nop)/NPY_SIZEOF_INTP;
first = (npy_intp*)NIT_AXISDATA(iter);
Expand All @@ -4221,7 +4221,7 @@ npyiter_reverse_axis_ordering(NpyIter *iter)
/* Store the perm we applied */
perm = NIT_PERM(iter);
for(i = ndim-1; i >= 0; --i, ++perm) {
*perm = (char)i;
*perm = (npy_int8)i;
}

NIT_ITFLAGS(iter) &= ~NPY_ITFLAG_IDENTPERM;
Expand All @@ -4241,7 +4241,7 @@ npyiter_find_best_axis_ordering(NpyIter *iter)

npy_intp ax_i0, ax_i1, ax_ipos;
char ax_j0, ax_j1;
char *perm;
npy_int8 *perm;
NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
int permuted = 0;
Expand Down Expand Up @@ -4335,14 +4335,14 @@ npyiter_find_best_axis_ordering(NpyIter *iter)

/* If this axis hasn't been touched yet, process it */
if (NAD_INDEX(ad_i) == 1) {
char pidim = perm[idim], qidim;
npy_int8 pidim = perm[idim], qidim;
npy_intp tmp;
NpyIter_AxisData *ad_p, *ad_q;

if (pidim != idim) {
/* Follow the cycle, copying the data */
for (i = 0; i < size; ++i) {
qidim = (char)idim;
qidim = (npy_int8)idim;
pidim = perm[idim];
ad_q = ad_i;
tmp = *((npy_intp*)ad_q + i);
Expand Down Expand Up @@ -4434,11 +4434,11 @@ npyiter_coalesce_axes(NpyIter *iter)
* compress the data into the new layout.
*/
if (new_ndim < ndim) {
char *perm = NIT_PERM(iter);
npy_int8 *perm = NIT_PERM(iter);

/* Reset to an identity perm */
for (idim = 0; idim < new_ndim; ++idim) {
perm[idim] = (char)idim;
perm[idim] = (npy_int8)idim;
}
NIT_NDIM(iter) = new_ndim;
}
Expand All @@ -4464,7 +4464,7 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
int idim, ndim = NIT_NDIM(iter);
int nop = NIT_NOP(iter);

char *perm = NIT_PERM(iter);
npy_int8 *perm = NIT_PERM(iter);
npy_intp new_shape[NPY_MAXDIMS], strides[NPY_MAXDIMS],
stride = op_dtype->elsize;
char reversestride[NPY_MAXDIMS], anyreverse = 0;
Expand Down Expand Up @@ -4503,7 +4503,7 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,

if (op_axes != NULL) {
for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
char p;
npy_int8 p;

/* Apply the perm to get the original axis */
p = perm[idim];
Expand Down Expand Up @@ -4572,15 +4572,15 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
}
else {
for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
char p;
npy_int8 p;

/* Apply the perm to get the original axis */
p = perm[idim];
if (p < 0) {
i = op_ndim+p;
i = op_ndim + p;
}
else {
i = op_ndim-p-1;
i = op_ndim - p - 1;
}

if (i >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions numpy/core/src/multiarray/nditer_pywrap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __NEW_ITERATOR_PYWRAP_H
#define __NEW_ITERATOR_PYWRAP_H
#ifndef __NDITER_PYWRAP_H
#define __NDITER_PYWRAP_H

NPY_NO_EXPORT PyObject *
NpyIter_NestedIters(PyObject *NPY_UNUSED(self),
Expand Down
8 changes: 4 additions & 4 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -3355,21 +3355,21 @@ NPY_NO_EXPORT PyTypeObject Py@NAME@ArrType_Type = {
* type numbers. Note that signed integers are mapped to INTNEG_SCALAR,
* which is different than what PyArray_ScalarKind returns.
*/
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_scalar_kinds_table[NPY_NTYPES];

/*
* This table maps a scalar kind (excluding NPY_NOSCALAR)
* to the smallest type number of that kind.
*/
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];

/*
* This table gives the type of the same kind, but next in the sequence
* of sizes.
*/
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_next_larger_type_table[NPY_NTYPES];

/*
Expand All @@ -3383,7 +3383,7 @@ _npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
* This table gives the smallest-size and smallest-kind type to which
* the input types may be safely cast, according to _npy_can_cast_safely.
*/
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
#endif

Expand Down
16 changes: 8 additions & 8 deletions numpy/core/src/multiarray/scalartypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
#ifdef NPY_ENABLE_SEPARATE_COMPILATION
extern NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT char
extern NPY_NO_EXPORT signed char
_npy_scalar_kinds_table[NPY_NTYPES];
extern NPY_NO_EXPORT char
extern NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
extern NPY_NO_EXPORT char
extern NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
extern NPY_NO_EXPORT char
extern NPY_NO_EXPORT signed char
_npy_next_larger_type_table[NPY_NTYPES];
#else
NPY_NO_EXPORT unsigned char
_npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES];
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_scalar_kinds_table[NPY_NTYPES];
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES];
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_smallest_type_of_kind_table[NPY_NSCALARKINDS];
NPY_NO_EXPORT char
NPY_NO_EXPORT signed char
_npy_next_larger_type_table[NPY_NTYPES];
#endif

Expand Down