c18ea010c0f43c5144f1c5265874709f68c2e1f3,lazyflow/utility/blockwise_view.py,,blockwise_view,#Any#Any#Any#,3

Before Change


    blockshape = tuple(blockshape)

    // Pad leading dims with 1
    padded_dims = 5-a.ndim
    blockshape_5d = (1,) * padded_dims + blockshape
    a_5d = a[(None,)*padded_dims]

    view_10d = blockwise_view_5d( a_5d, blockshape_5d )
    
    // Drop the extra dimensions
    slicing_5d = (0,)*padded_dims + (slice(None),)*a.ndim
    slicing_10d = slicing_5d + slicing_5d
    
    view = view_10d[slicing_10d]
    assert view.shape == tuple(numpy.array(a.shape) / blockshape) + blockshape
    if require_aligned_blocks:
        assert view.size == a.size
    return view
    
def blockwise_view_5d( a, blockshape ):
    
    Return a 10-D view of a 5-D array, rearranged so each 5D block (tile) of the 

After Change


    
    assert a.flags["C_CONTIGUOUS"], "This function relies on the memory layout of the array."
    blockshape = tuple(blockshape)
    view_shape = tuple(numpy.array(a.shape) / blockshape) + blockshape

    if require_aligned_blocks:
        assert (numpy.mod(a.shape, blockshape) == 0).all(), \
            "blockshape {} must divide evenly into array shape {}"\
            .format( blockshape, a.shape )

    // The code below is for the ND case.
    // For example, in 4D, given shape=(t,z,y,x) and blockshape=(bt,bz,by,bx),
    // we could have written this:
    //
    // intra_block_strides = a.itemsize * numpy.array([z*y*x,    y*x,    x,     1])
    // inter_block_strides = a.itemsize * numpy.array([z*y*x*bt, y*x*bz, x*by, bx])

    // strides within each block
    intra_block_strides = [1]
    for s in a.shape[-1:0:-1]:
        intra_block_strides.append( s*intra_block_strides[-1] )
    intra_block_strides = numpy.array(intra_block_strides[::-1])
    
    // strides from one block to another
    inter_block_strides = numpy.array(intra_block_strides) * blockshape
    
    intra_block_strides *= a.itemsize
    inter_block_strides *= a.itemsize

    strides = tuple(inter_block_strides) + tuple(intra_block_strides)

    // This is where the magic happens.
    // Generate a view with our new strides.
    return numpy.lib.stride_tricks.as_strided(a, shape=view_shape, strides=strides)
    
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 5

Non-data size: 12

Instances


Project Name: ilastik/ilastik
Commit Name: c18ea010c0f43c5144f1c5265874709f68c2e1f3
Time: 2015-01-28
Author: bergs@janelia.hhmi.org
File Name: lazyflow/utility/blockwise_view.py
Class Name:
Method Name: blockwise_view


Project Name: richzhang/PerceptualSimilarity
Commit Name: 7b34113cc3b5529a127bd02667de9de0b5b75df9
Time: 2019-07-26
Author: rich.zhang@eecs.berkeley.edu
File Name: models/networks_basic.py
Class Name: PNet
Method Name: forward


Project Name: nltk/nltk
Commit Name: 8c541c9b9a7f968790c11ae8d74b302fb397c92b
Time: 2017-05-04
Author: alvations@gmail.com
File Name: nltk/tokenize/treebank.py
Class Name: TreebankWordTokenizer
Method Name: tokenize


Project Name: bethgelab/foolbox
Commit Name: 80cfb0e5f889c65a972ebde6c6dae4278b5e28c1
Time: 2020-02-14
Author: git@jonasrauber.de
File Name: foolbox/attacks/base.py
Class Name: MinimizationAttack
Method Name: __call__


Project Name: probcomp/bayeslite
Commit Name: 93a71bd6c3f3c731473bc0ddd9b894a252738d01
Time: 2019-12-06
Author: jar23@mumble.net
File Name: src/backends/cgpm_backend.py
Class Name: CGPM_Backend
Method Name: json_ready_models