Conversation
QuLogic
left a comment
There was a problem hiding this comment.
It's long, but I don't see too many major issues.
| border = '=' * maxfunc + ' ' + '=' * maxdoc | ||
| print(border) | ||
| print(' '.join(['symbol'.ljust(maxfunc), 'description'.ljust(maxdoc)])) | ||
| print('{:<{}} {:<{}}'.format('symbol', maxfunc, 'description', maxdoc)) |
There was a problem hiding this comment.
print inserts a space, so print('symbol.ljust(maxfunc), 'description'.ljust(maxdoc)) would have worked, right?
There was a problem hiding this comment.
Yes but that looks a bit "unintended" to me.
| Z = np.arange(10000.0) | ||
| Z.shape = 100, 100 | ||
| Z[:, 50:] = 1. | ||
| Z = np.arange(10000).reshape(100, 100) |
|
|
||
| Z1 = np.array(([0, 1]*4 + [1, 0]*4)*4) | ||
| Z1.shape = (8, 8) # chessboard | ||
| Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard |
There was a problem hiding this comment.
What does np.add.outer do (it works, but I've never seen it used that way)?
There was a problem hiding this comment.
It makes the first argument a column array and the second a row array, broadcasts them and applies the ufunc.
| dfile = cbook.get_sample_data('s1045.ima.gz') | ||
| im = np.fromstring(dfile.read(), np.uint16).astype(float) | ||
| im.shape = (256, 256) | ||
| im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256)) |
There was a problem hiding this comment.
No astype?
Also, can write np.fromfile(dfile, np.uint16) instead of the two step process.
There was a problem hiding this comment.
you can imshow an integer array just as well.
There was a problem hiding this comment.
Does the one below this still need astype, then?
There was a problem hiding this comment.
Actually, fromfile doesn't work with gzip.open'ed files (it seems to try to construct an array from the compressed representation). Reverting to read().
There was a problem hiding this comment.
Ah, unfortunate. Based on np.fromfile seeming to need fileno (since it doesn't work with BytesIO), it looks like it tries to stream from the fd directly, which GzipFile points at the underlying file object. In a way, it's a half-a-bug in both coming together to make one.
There was a problem hiding this comment.
Left a comment on numpy/numpy#7713; we'll see where it goes...
| dfile = cbook.get_sample_data('s1045.ima.gz') | ||
| im = np.fromstring(dfile.read(), np.uint16).astype(float) | ||
| im.shape = (256, 256) | ||
| im = np.fromstring(dfile.read(), np.uint16).astype(float).reshape((256, 256)) |
There was a problem hiding this comment.
Same np.fromfile comment as above.
| {val[0]: val[1] for val in six.itervalues(self.alphaStates)}) | ||
| self.writeHatches() | ||
| self.writeGouraudTriangles() | ||
| xobjects = dict(x[1:] for x in six.itervalues(self._images)) |
| @@ -1408,15 +1408,15 @@ def finddir(o, match, case=False): | |||
|
|
|||
| def reverse_dict(d): | |||
There was a problem hiding this comment.
Could probably be used in a couple places you've updated...
There was a problem hiding this comment.
I'd rather deprecate this function... I think everyone can understand what {v: k for k, v in d.items()} does and this way you don't have to go and check whether the function does something funny with duplicates.
| # by backends | ||
| # The reverse mapper is for mapping full names to short ones | ||
| ls_mapper_r = dict([(ls[1], ls[0]) for ls in _linestyles]) | ||
| ls_mapper_r = reverse_dict(ls_mapper) |
There was a problem hiding this comment.
Can _linestyles be dropped and ls_mapper written as a literal now?
lib/matplotlib/quiver.py
Outdated
| theta *= (np.pi / 180.0) | ||
| theta.shape = (theta.shape[0], 1) # for broadcasting | ||
| theta = ma.masked_invalid(np.deg2rad(self.angles)).filled(0) | ||
| theta = theta.reshape((-1, 1)) # for broadcasting |
There was a problem hiding this comment.
Was the change of indent intended?
lib/matplotlib/ticker.py
Outdated
| exponent -= 1 | ||
| scale = max([self.numticks-1, 1]) ** (-exponent) | ||
| exponent = round(math.log10(vmax - vmin) | ||
| / math.log10(max(self.numticks - 1, 1))) - 1 |
There was a problem hiding this comment.
I tested some completely arbitrary numbers that perhaps will never exist in these lines, but I'm not sure the result is the same. Perhaps I missed something:
>>> vr = np.linspace(1e-8, 1000, 100000) # vmax - vmin
>>> numticks = np.arange(30) # I expect 0 is invalid, but no matter...
>>> exponent, remainder = divmod(np.log10(vr[:, None]), np.log10(np.maximum(numticks - 1, 1))[None, :])
__main__:1: RuntimeWarning: invalid value encountered in floor_divide
__main__:1: RuntimeWarning: invalid value encountered in remainder
>>> exponent[remainder < 0.5] -= 1
__main__:1: RuntimeWarning: invalid value encountered in less
>>> exponent2 = np.round(np.log10(vr)[:, None] / np.log10(np.maximum(numticks - 1, 1))[None, :]) - 1
>>> exponent
array([[ nan, nan, nan, ..., -7., -6., -6.],
[ nan, nan, nan, ..., -2., -2., -2.],
[ nan, nan, nan, ..., -2., -2., -2.],
...,
[ nan, nan, nan, ..., 1., 1., 1.],
[ nan, nan, nan, ..., 1., 1., 1.],
[ nan, nan, nan, ..., 1., 1., 1.]])
>>> exponent2
array([[-inf, -inf, -inf, ..., -7., -7., -7.],
[-inf, -inf, -inf, ..., -2., -2., -2.],
[-inf, -inf, -inf, ..., -2., -2., -2.],
...,
[ inf, inf, inf, ..., 1., 1., 1.],
[ inf, inf, inf, ..., 1., 1., 1.],
[ inf, inf, inf, ..., 1., 1., 1.]])
>>> np.sum(exponent == exponent2)
2388308
>>> np.size(exponent)
3000000
# Percentage the same including nan/inf:
>>> np.sum(exponent == exponent2)/np.size(exponent)
0.79610266666666663
>>> mask = np.isfinite(exponent)
>>> np.all(mask == np.isfinite(exponent2))
True
>>> np.sum(exponent[mask] == exponent2[mask])
2388308
# Percentage of finite values that are the same:
>>> np.sum(exponent[mask] == exponent2[mask]) / np.sum(mask)
0.88455851851851852
>>> There was a problem hiding this comment.
You are correct that this is different: the previous implementation compares the remainder with 0.5 whereas I thought it was comparing it with half the divisor. My guess is that the previous version was incorrect.
However I can also just revert to the previous version...
78b4bcc to
7c2bc4c
Compare
Current coverage is 61.92% (diff: 60.86%)@@ master #7547 diff @@
==========================================
Files 173 173
Lines 56177 56125 -52
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 34784 34757 -27
+ Misses 21393 21368 -25
Partials 0 0
|
| Implemented as a separate function (not a call to :func:`norm` for speed). | ||
| """ | ||
| return np.sqrt(np.sum(np.absolute(a)**2)) | ||
| return np.sqrt(np.sum(np.abs(a) ** 2)) |
There was a problem hiding this comment.
Not for complex values.
7c2bc4c to
f1b25e6
Compare
|
(rebased following conflicts with sticky edges PR) |
|
AppVeyor failure looks transient. |
__cmp__method.reshapeinstead of assigning toshapeat least when it looks more legible.np.mininstead ofamin,np.max(amax),np.abs(fabs,absolute),np.conj(conjugate).