Exemplo n.º 1
0
def test__strided_from_memmap(tmpdir):
    fname = tmpdir.join('test.mmap').strpath
    size = 5 * mmap.ALLOCATIONGRANULARITY
    offset = mmap.ALLOCATIONGRANULARITY + 1
    # This line creates the mmap file that is reused later
    memmap_obj = np.memmap(fname, mode='w+', shape=size + offset)
    # filename, dtype, mode, offset, order, shape, strides, total_buffer_len
    memmap_obj = _strided_from_memmap(fname,
                                      dtype='uint8',
                                      mode='r',
                                      offset=offset,
                                      order='C',
                                      shape=size,
                                      strides=None,
                                      total_buffer_len=None)
    assert isinstance(memmap_obj, np.memmap)
    assert memmap_obj.offset == offset
    memmap_backed_obj = _strided_from_memmap(fname,
                                             dtype='uint8',
                                             mode='r',
                                             offset=offset,
                                             order='C',
                                             shape=(size // 2, ),
                                             strides=(2, ),
                                             total_buffer_len=size)
    assert _get_backing_memmap(memmap_backed_obj).offset == offset
Exemplo n.º 2
0
def test__strided_from_memmap(tmpdir):
    fname = tmpdir.join('test.mmap').strpath
    size = 5 * mmap.ALLOCATIONGRANULARITY
    offset = mmap.ALLOCATIONGRANULARITY + 1
    # This line creates the mmap file that is reused later
    memmap_obj = np.memmap(fname, mode='w+', shape=size + offset)
    # filename, dtype, mode, offset, order, shape, strides, total_buffer_len
    memmap_obj = _strided_from_memmap(fname, dtype='uint8', mode='r',
                                      offset=offset, order='C', shape=size,
                                      strides=None, total_buffer_len=None)
    assert isinstance(memmap_obj, np.memmap)
    assert memmap_obj.offset == offset
    memmap_backed_obj = _strided_from_memmap(fname, dtype='uint8', mode='r',
                                             offset=offset, order='C',
                                             shape=(size // 2,), strides=(2,),
                                             total_buffer_len=size)
    assert _get_backing_memmap(memmap_backed_obj).offset == offset