Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e179f0

Browse files
committed
Merge pull request #2900 from certik/backport2886and7
Backport2886and7
2 parents ac69b7c + d4a3937 commit 4e179f0

10 files changed

Lines changed: 53 additions & 51 deletions

File tree

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,9 @@ HALF_to_@TYPE@(npy_half *ip, @type@ *op, npy_intp n,
946946
}
947947

948948
/**end repeat**/
949-
#if SIZEOF_SHORT == 2
949+
#if NPY_SIZEOF_SHORT == 2
950950
#define HALF_to_HALF SHORT_to_SHORT
951-
#elif SIZEOF_INT == 2
951+
#elif NPY_SIZEOF_INT == 2
952952
#define HALF_to_HALF INT_to_INT
953953
#endif
954954

@@ -1612,35 +1612,35 @@ static void
16121612
char *a, *b, c;
16131613

16141614
a = (char *)dst;
1615-
#if SIZEOF_@fsize@ == 2
1615+
#if NPY_SIZEOF_@fsize@ == 2
16161616
b = a + 1;
16171617
c = *a; *a++ = *b; *b = c;
1618-
#elif SIZEOF_@fsize@ == 4
1618+
#elif NPY_SIZEOF_@fsize@ == 4
16191619
b = a + 3;
16201620
c = *a; *a++ = *b; *b-- = c;
16211621
c = *a; *a++ = *b; *b = c;
1622-
#elif SIZEOF_@fsize@ == 8
1622+
#elif NPY_SIZEOF_@fsize@ == 8
16231623
b = a + 7;
16241624
c = *a; *a++ = *b; *b-- = c;
16251625
c = *a; *a++ = *b; *b-- = c;
16261626
c = *a; *a++ = *b; *b-- = c;
16271627
c = *a; *a++ = *b; *b = c;
1628-
#elif SIZEOF_@fsize@ == 10
1628+
#elif NPY_SIZEOF_@fsize@ == 10
16291629
b = a + 9;
16301630
c = *a; *a++ = *b; *b-- = c;
16311631
c = *a; *a++ = *b; *b-- = c;
16321632
c = *a; *a++ = *b; *b-- = c;
16331633
c = *a; *a++ = *b; *b-- = c;
16341634
c = *a; *a++ = *b; *b = c;
1635-
#elif SIZEOF_@fsize@ == 12
1635+
#elif NPY_SIZEOF_@fsize@ == 12
16361636
b = a + 11;
16371637
c = *a; *a++ = *b; *b-- = c;
16381638
c = *a; *a++ = *b; *b-- = c;
16391639
c = *a; *a++ = *b; *b-- = c;
16401640
c = *a; *a++ = *b; *b-- = c;
16411641
c = *a; *a++ = *b; *b-- = c;
16421642
c = *a; *a++ = *b; *b = c;
1643-
#elif SIZEOF_@fsize@ == 16
1643+
#elif NPY_SIZEOF_@fsize@ == 16
16441644
b = a + 15;
16451645
c = *a; *a++ = *b; *b-- = c;
16461646
c = *a; *a++ = *b; *b-- = c;
@@ -1744,15 +1744,15 @@ static void
17441744
if (swap) {
17451745
char *a, *b, c;
17461746
a = (char *)dst;
1747-
#if SIZEOF_@fsize@ == 4
1747+
#if NPY_SIZEOF_@fsize@ == 4
17481748
b = a + 3;
17491749
c = *a; *a++ = *b; *b-- = c;
17501750
c = *a; *a++ = *b; *b = c;
17511751
a += 2;
17521752
b = a + 3;
17531753
c = *a; *a++ = *b; *b-- = c;
17541754
c = *a; *a++ = *b; *b = c;
1755-
#elif SIZEOF_@fsize@ == 8
1755+
#elif NPY_SIZEOF_@fsize@ == 8
17561756
b = a + 7;
17571757
c = *a; *a++ = *b; *b-- = c;
17581758
c = *a; *a++ = *b; *b-- = c;
@@ -1764,7 +1764,7 @@ static void
17641764
c = *a; *a++ = *b; *b-- = c;
17651765
c = *a; *a++ = *b; *b-- = c;
17661766
c = *a; *a++ = *b; *b = c;
1767-
#elif SIZEOF_@fsize@ == 10
1767+
#elif NPY_SIZEOF_@fsize@ == 10
17681768
b = a + 9;
17691769
c = *a; *a++ = *b; *b-- = c;
17701770
c = *a; *a++ = *b; *b-- = c;
@@ -1778,7 +1778,7 @@ static void
17781778
c = *a; *a++ = *b; *b-- = c;
17791779
c = *a; *a++ = *b; *b-- = c;
17801780
c = *a; *a++ = *b; *b = c;
1781-
#elif SIZEOF_@fsize@ == 12
1781+
#elif NPY_SIZEOF_@fsize@ == 12
17821782
b = a + 11;
17831783
c = *a; *a++ = *b; *b-- = c;
17841784
c = *a; *a++ = *b; *b-- = c;
@@ -1794,7 +1794,7 @@ static void
17941794
c = *a; *a++ = *b; *b-- = c;
17951795
c = *a; *a++ = *b; *b-- = c;
17961796
c = *a; *a++ = *b; *b = c;
1797-
#elif SIZEOF_@fsize@ == 16
1797+
#elif NPY_SIZEOF_@fsize@ == 16
17981798
b = a + 15;
17991799
c = *a; *a++ = *b; *b-- = c;
18001800
c = *a; *a++ = *b; *b-- = c;
@@ -1825,9 +1825,8 @@ static void
18251825
*a++ = *b;
18261826
*b-- = c;
18271827
}
1828-
a += nn / 2;
1828+
a += nn;
18291829
b = a + (NPY_SIZEOF_@fsize@ - 1);
1830-
nn = NPY_SIZEOF_@fsize@ / 2;
18311830
for (i = 0; i < nn; i++) {
18321831
c = *a;
18331832
*a++ = *b;
@@ -4089,8 +4088,6 @@ set_typeinfo(PyObject *dict)
40894088
infodict = PyDict_New();
40904089
if (infodict == NULL) return -1;
40914090

4092-
#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T
4093-
#define BITSOF_BYTE CHAR_BIT
40944091

40954092
/**begin repeat
40964093
*
@@ -4220,7 +4217,7 @@ set_typeinfo(PyObject *dict)
42204217
s = Py_BuildValue("ciiiNNO", NPY_DATETIMELTR,
42214218
#endif
42224219
NPY_DATETIME,
4223-
sizeof(npy_datetime) * CHAR_BIT,
4220+
NPY_BITSOF_DATETIME,
42244221
_ALIGN(npy_datetime),
42254222
MyPyLong_FromInt64(NPY_MAX_DATETIME),
42264223
MyPyLong_FromInt64(NPY_MIN_DATETIME),
@@ -4233,7 +4230,7 @@ set_typeinfo(PyObject *dict)
42334230
s = Py_BuildValue("ciiiNNO",NPY_TIMEDELTALTR,
42344231
#endif
42354232
NPY_TIMEDELTA,
4236-
sizeof(npy_timedelta) * CHAR_BIT,
4233+
NPY_BITSOF_TIMEDELTA,
42374234
_ALIGN(npy_timedelta),
42384235
MyPyLong_FromInt64(NPY_MAX_TIMEDELTA),
42394236
MyPyLong_FromInt64(NPY_MIN_TIMEDELTA),

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ PyArray_PyIntAsInt(PyObject *o)
742742
return -1;
743743
}
744744

745-
#if (SIZEOF_LONG > SIZEOF_INT)
745+
#if (NPY_SIZEOF_LONG > NPY_SIZEOF_INT)
746746
if ((long_value < INT_MIN) || (long_value > INT_MAX)) {
747747
PyErr_SetString(PyExc_ValueError, "integer won't fit into a C int");
748748
return -1;
@@ -774,9 +774,9 @@ PyArray_PyIntAsIntp(PyObject *o)
774774
goto finish;
775775
}
776776

777-
#if NPY_SIZEOF_INTP == SIZEOF_LONG
777+
#if NPY_SIZEOF_INTP == NPY_SIZEOF_LONG
778778
descr = &LONG_Descr;
779-
#elif NPY_SIZEOF_INTP == SIZEOF_INT
779+
#elif NPY_SIZEOF_INTP == NPY_SIZEOF_INT
780780
descr = &INT_Descr;
781781
#else
782782
descr = &LONGLONG_Descr;
@@ -869,7 +869,7 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
869869
*/
870870
if ((nd=PySequence_Length(seq)) == -1) {
871871
if (PyErr_Occurred()) PyErr_Clear();
872-
#if SIZEOF_LONG >= NPY_SIZEOF_INTP && !defined(NPY_PY3K)
872+
#if NPY_SIZEOF_LONG >= NPY_SIZEOF_INTP && !defined(NPY_PY3K)
873873
if (!(op = PyNumber_Int(seq))) {
874874
return -1;
875875
}
@@ -879,7 +879,7 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
879879
}
880880
#endif
881881
nd = 1;
882-
#if SIZEOF_LONG >= NPY_SIZEOF_INTP
882+
#if NPY_SIZEOF_LONG >= NPY_SIZEOF_INTP
883883
vals[0] = (npy_intp ) PyInt_AsLong(op);
884884
#else
885885
vals[0] = (npy_intp ) PyLong_AsLongLong(op);
@@ -908,7 +908,7 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
908908
if (op == NULL) {
909909
return -1;
910910
}
911-
#if SIZEOF_LONG >= NPY_SIZEOF_INTP
911+
#if NPY_SIZEOF_LONG >= NPY_SIZEOF_INTP
912912
vals[i]=(npy_intp )PyInt_AsLong(op);
913913
#else
914914
vals[i]=(npy_intp )PyLong_AsLongLong(op);
@@ -1153,7 +1153,7 @@ PyArray_IntTupleFromIntp(int len, npy_intp *vals)
11531153
goto fail;
11541154
}
11551155
for (i = 0; i < len; i++) {
1156-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
1156+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
11571157
PyObject *o = PyInt_FromLong((long) vals[i]);
11581158
#else
11591159
PyObject *o = PyLong_FromLongLong((npy_longlong) vals[i]);

numpy/core/src/multiarray/getset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static PyObject *
383383
array_size_get(PyArrayObject *self)
384384
{
385385
npy_intp size=PyArray_SIZE(self);
386-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
386+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
387387
return PyInt_FromLong((long) size);
388388
#else
389389
if (size > NPY_MAX_LONG || size < NPY_MIN_LONG) {
@@ -399,7 +399,7 @@ static PyObject *
399399
array_nbytes_get(PyArrayObject *self)
400400
{
401401
npy_intp nbytes = PyArray_NBYTES(self);
402-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
402+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
403403
return PyInt_FromLong((long) nbytes);
404404
#else
405405
if (nbytes > NPY_MAX_LONG || nbytes < NPY_MIN_LONG) {

numpy/core/src/multiarray/iterators.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ arraymultiter_dealloc(PyArrayMultiIterObject *multi)
16771677
static PyObject *
16781678
arraymultiter_size_get(PyArrayMultiIterObject *self)
16791679
{
1680-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
1680+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
16811681
return PyInt_FromLong((long) self->size);
16821682
#else
16831683
if (self->size < NPY_MAX_LONG) {
@@ -1692,7 +1692,7 @@ arraymultiter_size_get(PyArrayMultiIterObject *self)
16921692
static PyObject *
16931693
arraymultiter_index_get(PyArrayMultiIterObject *self)
16941694
{
1695-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
1695+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
16961696
return PyInt_FromLong((long) self->index);
16971697
#else
16981698
if (self->size < NPY_MAX_LONG) {

numpy/core/src/multiarray/mapping.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ NPY_NO_EXPORT int
2323
array_ass_big_item(PyArrayObject *self, npy_intp i, PyObject *v);
2424

2525
#if PY_VERSION_HEX < 0x02050000
26-
#if SIZEOF_INT == NPY_SIZEOF_INTP
26+
#if NPY_SIZEOF_INT == NPY_SIZEOF_INTP
2727
#define array_ass_item array_ass_big_item
2828
#endif
2929
#else
30+
/* SIZEOF_SIZE_T is nowhere defined, Py_ssize_t perhaps?*/
3031
#if SIZEOF_SIZE_T == NPY_SIZEOF_INTP
3132
#define array_ass_item array_ass_big_item
3233
#endif

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,7 +3784,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
37843784
SINGLE_INHERIT(Bool, Generic);
37853785
SINGLE_INHERIT(Byte, SignedInteger);
37863786
SINGLE_INHERIT(Short, SignedInteger);
3787-
#if SIZEOF_INT == SIZEOF_LONG && !defined(NPY_PY3K)
3787+
#if NPY_SIZEOF_INT == NPY_SIZEOF_LONG && !defined(NPY_PY3K)
37883788
DUAL_INHERIT(Int, Int, SignedInteger);
37893789
#else
37903790
SINGLE_INHERIT(Int, SignedInteger);
@@ -3794,7 +3794,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
37943794
#else
37953795
SINGLE_INHERIT(Long, SignedInteger);
37963796
#endif
3797-
#if NPY_SIZEOF_LONGLONG == SIZEOF_LONG && !defined(NPY_PY3K)
3797+
#if NPY_SIZEOF_LONGLONG == NPY_SIZEOF_LONG && !defined(NPY_PY3K)
37983798
DUAL_INHERIT(LongLong, Int, SignedInteger);
37993799
#else
38003800
SINGLE_INHERIT(LongLong, SignedInteger);

numpy/core/src/multiarray/scalartypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ int_arrtype_hash(PyObject *obj)
29392939
* #ext = && (x >= LONG_MIN),#
29402940
*/
29412941
#if NPY_SIZEOF_LONG != NPY_SIZEOF_LONGLONG
2942-
/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */
2942+
/* we assume NPY_SIZEOF_LONGLONG=2*NPY_SIZEOF_LONG */
29432943
static long
29442944
@char@longlong_arrtype_hash(PyObject *obj)
29452945
{

numpy/core/src/npymath/_signbit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ _npy_signbit_d(double x)
1212

1313
u.d = x;
1414

15-
#if SIZEOF_INT == 4
15+
#if NPY_SIZEOF_INT == 4
1616

1717
#ifdef WORDS_BIGENDIAN /* defined in pyconfig.h */
1818
return u.i[0] < 0;
1919
#else
2020
return u.i[1] < 0;
2121
#endif
2222

23-
#else /* SIZEOF_INT != 4 */
23+
#else /* NPY_SIZEOF_INT != 4 */
2424

2525
#ifdef WORDS_BIGENDIAN
2626
return u.s[0] < 0;
2727
#else
2828
return u.s[3] < 0;
2929
#endif
3030

31-
#endif /* SIZEOF_INT */
31+
#endif /* NPY_SIZEOF_INT */
3232
}

numpy/core/src/scalarmathmodule.c.src

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* types of the same rank to have the same width.
2525
*/
2626

27-
#if SIZEOF_LONGLONG == 64
27+
#if NPY_SIZEOF_LONGLONG == 64
2828

2929
static int
3030
ulonglong_overflow(npy_ulonglong a, npy_ulonglong b)
@@ -72,7 +72,7 @@ slonglong_overflow(npy_longlong a0, npy_longlong b0)
7272
(((x & mask) + (y & mask) + (w >> 32)) >> 31);
7373
}
7474

75-
#elif SIZEOF_LONGLONG == 128
75+
#elif NPY_SIZEOF_LONGLONG == 128
7676

7777
static int
7878
ulonglong_overflow(npy_ulonglong a, npy_ulonglong b)
@@ -203,8 +203,8 @@ static void
203203
}
204204
/**end repeat**/
205205

206-
#ifndef SIZEOF_BYTE
207-
#define SIZEOF_BYTE 1
206+
#ifndef NPY_SIZEOF_BYTE
207+
#define NPY_SIZEOF_BYTE 1
208208
#endif
209209

210210
/**begin repeat

numpy/core/tests/test_regression.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,16 +1262,20 @@ def test_misaligned_dot_product_objects(self):
12621262
np.dot(a['f0'], b['f0'])
12631263

12641264
def test_byteswap_complex_scalar(self):
1265-
"""Ticket #1259"""
1266-
z = np.array([-1j], '<c8')
1267-
x = z[0] # always native-endian
1268-
y = x.byteswap()
1269-
if x.dtype.byteorder == z.dtype.byteorder:
1270-
# little-endian machine
1271-
assert_equal(x, np.fromstring(y.tostring(), dtype='>c8'))
1272-
else:
1273-
# big-endian machine
1274-
assert_equal(x, np.fromstring(y.tostring(), dtype='<c8'))
1265+
"""Ticket #1259 and gh-441"""
1266+
for dtype in [np.dtype('<'+t) for t in np.typecodes['Complex']]:
1267+
z = np.array([2.2-1.1j], dtype)
1268+
x = z[0] # always native-endian
1269+
y = x.byteswap()
1270+
if x.dtype.byteorder == z.dtype.byteorder:
1271+
# little-endian machine
1272+
assert_equal(x, np.fromstring(y.tostring(), dtype=dtype.newbyteorder()))
1273+
else:
1274+
# big-endian machine
1275+
assert_equal(x, np.fromstring(y.tostring(), dtype=dtype))
1276+
# double check real and imaginary parts:
1277+
assert_equal(x.real, y.real.byteswap())
1278+
assert_equal(x.imag, y.imag.byteswap())
12751279

12761280
def test_structured_arrays_with_objects1(self):
12771281
"""Ticket #1299"""

0 commit comments

Comments
 (0)