FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: bug in np.where and recarray swapping by certik · Pull Request #395 · numpy/numpy · GitHub

/ numpy Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/scalarapi.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Back | FazBrowse Home | New Git URL