kerncraft/kernel.py
def transform_multidim_to_1d_ref(aref, dimension_dict):
    """
    Transform ast of multidimensional reference to a single dimension reference.

    In-place operation!
    """
    dims = []
    name = aref
    while type(name) is c_ast.ArrayRef:
        dims.append(name.subscript)
        name = name.name

    subscript_list = []
    for i, d in enumerate(dims):
        if i == 0:
            subscript_list.append(d)
        else:
            subscript_list.append(c_ast.BinaryOp('*', d, reduce(
                lambda l, r: c_ast.BinaryOp('*', l, r),
                dimension_dict[name.name][-1:-i-1:-1])))

    aref.subscript = reduce(
        lambda l, r: c_ast.BinaryOp('+', l, r), subscript_list)
    aref.name = name
def transform_multidim_to_1d_ref(aref, dimension_dict):
    dims = []
    name = aref
    while type(name) is c_ast.ArrayRef:
        dims.append(name.subscript)
        name = name.name

    subscript_list = []
    for i, d in enumerate(dims):
        if i == 0:
            subscript_list.append(d)
        else:
            subscript_list.append(c_ast.BinaryOp('*', d, reduce(
                lambda l, r: c_ast.BinaryOp('*', l, r),
                dimension_dict[name.name][-1:-i-1:-1])))

    aref.subscript = reduce(
        lambda l, r: c_ast.BinaryOp('+', l, r), subscript_list)
    aref.name = name
def transform_multidim_to_1d_ref ( aref , dimension_dict ) : dims = [ ] name = aref while type ( name ) is c_ast . ArrayRef : dims . append ( name . subscript ) name = name . name subscript_list = [ ] for i , d in enumerate ( dims ) : if i == 0 : subscript_list . append ( d ) else : subscript_list . append ( c_ast . BinaryOp ( '*' , d , reduce ( lambda l , r : c_ast . BinaryOp ( '*' , l , r ) , dimension_dict [ name . name ] [ - 1 : - i - 1 : - 1 ] ) ) ) aref . subscript = reduce ( lambda l , r : c_ast . BinaryOp ( '+' , l , r ) , subscript_list ) aref . name = name
Transform ast of multidimensional reference to a single dimension reference.

    In-place operation!
Transform ast of multidimensional reference to a single dimension reference .