Skip to content

Commit

Permalink
Merge pull request #395 from certik/fix369
Browse files Browse the repository at this point in the history
FIX: bug in np.where and recarray swapping
  • Loading branch information
certik committed Aug 31, 2012
2 parents c6d8734 + ecbd938 commit 8c75aa0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/scalarapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)
if (outcode == NULL) {
return (PyObject *)r;
}
if (outcode->type_num == typecode->type_num) {
if (PyArray_EquivTypes(outcode, typecode)) {
if (!PyTypeNum_ISEXTENDED(typecode->type_num)
|| (outcode->elsize == typecode->elsize)) {
Py_DECREF(outcode);
Expand Down
28 changes: 28 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ def test_endian_bool_indexing(self,level=rlevel):
assert_(np.all(a[ya] > 0.5))
assert_(np.all(b[yb] > 0.5))

def test_endian_where(self,level=rlevel):
"""GitHuB issue #369"""
net = np.zeros(3, dtype='>f4')
net[1] = 0.00458849
net[2] = 0.605202
max_net = net.max()
test = np.where(net <= 0., max_net, net)
correct = np.array([ 0.60520202, 0.00458849, 0.60520202])
assert_array_almost_equal(test, correct)

def test_endian_recarray(self,level=rlevel):
"""Ticket #2185"""
dt = np.dtype([
('head', '>u4'),
('data', '>u4', 2),
])
buf = np.recarray(1, dtype=dt)
buf[0]['head'] = 1
buf[0]['data'][:] = [1,1]

h = buf[0]['head']
d = buf[0]['data'][0]
buf[0]['head'] = h
buf[0]['data'][0] = d
print buf[0]['head']
assert_(buf[0]['head'] == 1)


def test_mem_dot(self,level=rlevel):
"""Ticket #106"""
x = np.random.randn(0,1)
Expand Down

0 comments on commit 8c75aa0

Please sign in to comment.