Skip to content

FIX: bug in np.where and recarray swapping #395

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

Merged
merged 1 commit into from
Aug 31, 2012
Merged
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
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it matters or is the case. But it may be necessary to test both '>' and '<' for big-endian machines where I guess the singletons should be big endian? would be just a second net here and a second test below (unless there is a way to make net non-native).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind sending a PR for this please? I am going to merge this issue now.

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