(tensor, blocksize, criteria)
return agg
Aggregates tensor dimensions according to criteria.

    :param tensor: PyTorch tensor
    :type tensor: `torch.Tensor`
    :param blocksize: Size of blocks to aggregate
    :type blocksize: `Tuple(int)`
    :param criteria: Aggregation criteria
    :type criteria: `condensa.functional`
    :return: Aggregated tensor
    :rtype: `torch.Tensor`
Aggregates tensor dimensions according to criteria.
Aggregates tensor dimensions according to criteria .
def aggregate(tensor, blocksize, criteria):
    """
    Aggregates tensor dimensions according to criteria.

    :param tensor: PyTorch tensor
    :type tensor: `torch.Tensor`
    :param blocksize: Size of blocks to aggregate
    :type blocksize: `Tuple(int)`
    :param criteria: Aggregation criteria
    :type criteria: `condensa.functional`
    :return: Aggregated tensor
    :rtype: `torch.Tensor`
    """
    if tensor.dim() != len(blocksize):
        raise RuntimeError('Tensor and block dimensions do not match')
    ndim = tensor.dim()

    blocksize_flat = np.prod(np.array(blocksize))
    shape = np.array(tensor.shape)
    repeats = (shape / blocksize).astype(int)
    divcheck = (shape % blocksize).astype(int)

    if not np.all(divcheck == 0):
        raise TypeError('Block size must be divisible by tensor size')

    tmpshape = np.column_stack([repeats, blocksize]).ravel()
    order = np.arange(len(tmpshape))
    order = np.concatenate([order[::2], order[1::2]])
    blocks = tensor.abs().reshape(tuple(tmpshape))
    blocks = blocks.permute(tuple(order)).reshape(-1, *blocksize)
    agg = criteria(blocks.reshape(-1, blocksize_flat), dim=1, keepdim=True)
    return agg
def aggregate ( tensor , blocksize , criteria ) : if tensor . dim ( ) != len ( blocksize ) : raise RuntimeError ( 'Tensor and block dimensions do not match' ) ndim = tensor . dim ( ) blocksize_flat = np . prod ( np . array ( blocksize ) ) shape = np . array ( tensor . shape ) repeats = ( shape / blocksize ) . astype ( int ) divcheck = ( shape % blocksize ) . astype ( int ) if not np . all ( divcheck == 0 ) : raise TypeError ( 'Block size must be divisible by tensor size' ) tmpshape = np . column_stack ( [ repeats , blocksize ] ) . ravel ( ) order = np . arange ( len ( tmpshape ) ) order = np . concatenate ( [ order [ : : 2 ] , order [ 1 : : 2 ] ] ) blocks = tensor . abs ( ) . reshape ( tuple ( tmpshape ) ) blocks = blocks . permute ( tuple ( order ) ) . reshape ( - 1 , * blocksize ) agg = criteria ( blocks . reshape ( - 1 , blocksize_flat ) , dim = 1 , keepdim = True ) return agg