• Kirill Smelkov's avatar
    bigarray: Fix __getitem__ for cases where element overlaps with edge between pages · e5b7c31b
    Kirill Smelkov authored
    When we serve indexing request, we first compute page range in backing
    file, which contains the result based on major index range, then mmap
    that file range and pick up result from there.
    
    Page range math was however not correct: e.g. for positive strides, last
    element's byte is (byte0_stop-1), NOT (byte0_stop - byte0_stride) which
    for cases where byte0_stop is just a bit after page boundary, can make a
    difference - page_max will be 1 page less what it should be and then
    whole ndarray view creation breaks:
    
        ...
        Module wendelin.bigarray, line 381, in __getitem__
          view0 = ndarray(view0_shape, self._dtype, vma0, view0_offset, view0_stridev)
      ValueError: strides is incompatible with shape of requested array and size of buffer
    
    ( because vma0 was created less in size than what is needed to create view0_shape
      shaped array starting from view0_offset in vma0. )
    
    Similar story for negative strides math - it was not correct neither.
    
    Fix it.
    
    /reported-by @Camata
    e5b7c31b
__init__.py 15.8 KB