• Kirill Smelkov's avatar
    bigarray: Add ArrayRef utility · d53371b6
    Kirill Smelkov authored
    ArrayRef is a tool to find out for a NumPy array its top-level root
    parent and remember instructions how to recreate original array from
    the root. For example if
    
    	root = arange(1E7)
    	z = root[1000:2000]
    	a = z[10:20]
    
    `ArrayRef(a)` will find out that the root array for `a` is `root` and
    that `a` occupies 1010:1020 bytes in it. The vice versa operation is
    also possible, for example given
    
    	aref = ArrayRef(a)
    
    it is possible to restore original `a` from `aref`:
    
    	a_ = aref.deref()
    	assert array_equal(a_, a)
    
    the restoration works without copying by creating appropriate view of
    root.
    
    ArrayRef should work reliably for arrays of arbitrary dimensions,
    strides etc - even fancy arrays created via stride tricks such as arrays
    whose elements overlap each other should be supported.
    
    This patch adds ArrayRef with support for regular ndarrays only.
    
    The next patch will add ArrayRef support for BigArray and description
    for ArrayRef rationale.
    d53371b6
__init__.py 26.7 KB