Inserts and Deletes

With ironArray you can insert or delete data in the middle of the array without having to copy the data as you would need to do with other tools. In this bench, we will show how ironArray just reorders the data instead of copying it. Let’s go!

[1]:
import iarray as ia
import numpy as np
import zarr

%load_ext memprofiler
[2]:
shape = (10000, 10000)
size = np.prod(shape)

chunks = (1, 10000)
blocks = (1, 1000)
insert_shape = (1, 10000)

Insertions

[3]:
a = ia.arange(shape, 0, 1, chunks=chunks, blocks=blocks, dtype=np.float64)

insert_size = np.prod(insert_shape)
buffer = ia.arange(shape=insert_shape, start=2, stop=4, dtype=a.dtype).data
[4]:
%%mprof_run insert::iarray

a.insert(data=buffer, axis=0, start=500)
memprofiler: used 0.24 MiB RAM (peak of 0.24 MiB) in 0.0019 s, total RAM usage 488.49 MiB
[5]:
%%mprof_run copy::iarray

b = a.copy()
memprofiler: used 260.01 MiB RAM (peak of 260.01 MiB) in 0.8724 s, total RAM usage 748.60 MiB
[6]:
%mprof_plot  .*::iarray