bolt/spark/chunk.py
def getslices(plan, padding, shape):
        """
        Obtain slices for the given dimensions, padding, and chunks.

        Given a plan for the number of chunks along each dimension and the amount of padding,
        calculate a list of slices required to generate those chunks.

        Parameters
        ----------
        plan: tuple or array-like
            Size of chunks (in number of elements) along each dimensions.
            Length must be equal to the number of dimensions.

        padding: tuple or array-like
            Size of overlap (in number of elements) between chunks along each dimension.
            Length must be equal to the number of dimensions.

        shape: tuple
             Dimensions of axes to be chunked.
        """
        slices = []
        for size, pad, d in zip(plan, padding, shape):
            nchunks = int(floor(d/size))
            remainder = d % size
            start = 0
            dimslices = []
            for idx in range(nchunks):
                end = start + size
                # left endpoint
                if idx == 0:
                    left = start
                else:
                    left = start - pad
                # right endpoint
                if idx == nchunks:
                    right = end
                else:
                    right = end + pad
                dimslices.append(slice(left, right, 1))
                start = end
            if remainder:
                dimslices.append(slice(end - pad, d, 1))
            slices.append(dimslices)
        return slices
def getslices(plan, padding, shape):
        """
        Obtain slices for the given dimensions, padding, and chunks.

        Given a plan for the number of chunks along each dimension and the amount of padding,
        calculate a list of slices required to generate those chunks.

        Parameters
        ----------
        plan: tuple or array-like
            Size of chunks (in number of elements) along each dimensions.
            Length must be equal to the number of dimensions.

        padding: tuple or array-like
            Size of overlap (in number of elements) between chunks along each dimension.
            Length must be equal to the number of dimensions.

        shape: tuple
             Dimensions of axes to be chunked.
        """
        slices = []
        for size, pad, d in zip(plan, padding, shape):
            nchunks = int(floor(d/size))
            remainder = d % size
            start = 0
            dimslices = []
            for idx in range(nchunks):
                end = start + size
                # left endpoint
                if idx == 0:
                    left = start
                else:
                    left = start - pad
                # right endpoint
                if idx == nchunks:
                    right = end
                else:
                    right = end + pad
                dimslices.append(slice(left, right, 1))
                start = end
            if remainder:
                dimslices.append(slice(end - pad, d, 1))
            slices.append(dimslices)
        return slices
Obtain slices for the given dimensions, padding, and chunks.

        Given a plan for the number of chunks along each dimension and the amount of padding,
        calculate a list of slices required to generate those chunks.

        Parameters
        ----------
        plan: tuple or array-like
            Size of chunks (in number of elements) along each dimensions.
            Length must be equal to the number of dimensions.

        padding: tuple or array-like
            Size of overlap (in number of elements) between chunks along each dimension.
            Length must be equal to the number of dimensions.

        shape: tuple
             Dimensions of axes to be chunked.