rougier / from-python-to-numpy

An open-access book on numpy vectorization techniques, Nicolas P. Rougier, 2017
http://www.labri.fr/perso/nrougier/from-python-to-numpy
Other
2.05k stars 340 forks source link

3.4 Conclusion - Shouldn't byte_bounds(Z1)[0] point to the beginning of the 0-th element? #68

Closed skovorodkin closed 6 years ago

skovorodkin commented 6 years ago

Currently byte_bounds(Z1)[0] points to the beginning of the 1 element:

  byte_bounds(Z1)[0]                  byte_bounds(Z1)[-1]
          ↓                                   ↓ 
   ╌╌╌┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬╌╌
Z1    │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │
   ╌╌╌┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴╌╌

[But] byte_bounds's docstring says, that "the first integer is the first byte of the array" and:

>>> I = np.eye(2, dtype='f'); I.dtype
dtype('float32')
>>> low, high = np.byte_bounds(I)
>>> high - low == I.size*I.itemsize
True

So it looks like the pointer on the diagram should point before the 0-th element not after:

  byte_bounds(Z1)[0]                  byte_bounds(Z1)[-1]
      ↓                                       ↓ 
   ╌╌╌┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬╌╌
Z1    │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │
   ╌╌╌┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴╌╌
rougier commented 6 years ago

You're right, thanks. Could make a PR ?