Skip to content

fix undefined function and add integer divisions #3168

Merged
merged 1 commit into from Mar 28, 2013

3 participants

@juliantaylor

Fix a undefined function and some floats which appear through division and are used as slice indices.
Loosely based on the patch in https://bugs.launchpad.net/ubuntu/+source/python-numpy/+bug/701549

@njsmith njsmith commented on the diff Mar 26, 2013
numpy/numarray/functions.py
a = np.ndarray(shape=shape, dtype=type, buffer=buf)
if a.dtype.char == '?':
np.not_equal(a, 0, a)
return a
+
+# this function is referenced in the code above but not defined. adding
+# it back. - phensley
@njsmith
NumPy member
njsmith added a note Mar 26, 2013

This should be removed, because it won't be meaningful to anyone reading this code later -- it's a commit message, not a code comment.

@juliantaylor
juliantaylor added a note Mar 26, 2013

just paranoia
I was pretty sure that its always a int, but better a nop than sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@njsmith njsmith commented on the diff Mar 26, 2013
numpy/numarray/functions.py
@@ -204,8 +204,8 @@ def fromfile(infile, type=None, shape=None, sizing=STRICT,
##file whose size may be determined before allocation, should be
##quick -- only one allocation will be needed.
- recsize = dtype.itemsize * np.product([i for i in shape if i != -1])
- blocksize = max(_BLOCKSIZE/recsize, 1)*recsize
+ recsize = int(dtype.itemsize * np.product([i for i in shape if i != -1]))
@njsmith
NumPy member
njsmith added a note Mar 26, 2013

Why is the call to int necessary here? How could the stuff on the right ever be anything other than an int?

@juliantaylor
juliantaylor added a note Mar 26, 2013

just paranoia
I was pretty sure that its always a int, but better a nop than sorry
should I remove it?

@njsmith
NumPy member
njsmith added a note Mar 27, 2013

Ah, okay. Yeah, it should be removed, because it's misleading to readers then. If you're still paranoid then the way to express that is

assert isinstance(recsize, int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@njsmith
NumPy member
njsmith commented Mar 27, 2013

Oh also, should have thought of this before -- is there any easy way to write a test case that hits the undefined function? It looks like one way is to pass a file-like object that defines read() but not seek/tell (to get to line 230), and I can't see how to get to the call on line 252.

@juliantaylor

is it worth adding a test for that? the function is simple enough
maybe one can use the already tested np.resize

time would probably be better spent replacing the whole function with a wrapper around np.fromfile instead of trying to test all the branches.

@njsmith
NumPy member
njsmith commented Mar 27, 2013

Oh man, I totally missed that this was the numarray compatibility code. Yeah, okay, that makes me less concerned about... well, everything...

This code is pretty much unmaintained and we're planning to drop it in a few releases in any case. Honestly I'd be fine with just merging this as is in that case, it won't reduce the overall quality of this module at all. Anyone object?

@rgommers
NumPy member

+1

we shouldn't break it, but slightly lower standards for code quality and test coverage aren't a big issue imho

@njsmith njsmith merged commit db75eb4 into numpy:master Mar 28, 2013

1 check passed

Details default The Travis build passed
@juliantaylor juliantaylor deleted the juliantaylor:numarray-fixes branch Nov 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.