<commit_before># -*- coding: utf-8 -*-

"""
Lift ckernels to their appropriate rank so they always consume the full array
arguments.
"""

from __future__ import print_function, division, absolute_import
from pykit.ir import visit

#------------------------------------------------------------------------
# Run
#------------------------------------------------------------------------

def run(func, env):
    visit(CKernelLifter(), func)

#------------------------------------------------------------------------
# Lift CKernels
#------------------------------------------------------------------------

class CKernelLifter(object):
    """
    Lift ckernels to their appropriate rank so they always consume the
    full array arguments.
    """

    def op_ckernel(self, op):
        if op.metadata['rank'] < len(op.type.shape):
            ckernel, args = op.args
            in_dshapes = [arg.type for arg in args]
            out_dshape = op.type
            new_ckernel = lift_ckernel(ckernel, out_dshape, in_dshapes)
            op.args[0] = new_ckernel


def lift_ckernel(ckernel, out_dshape, in_dshapes):
    raise NotImplementedError<commit_msg>Try to connect the lifting<commit_after># -*- coding: utf-8 -*-

"""
Lift ckernels to their appropriate rank so they always consume the full array
arguments.
"""

from __future__ import print_function, division, absolute_import
from pykit.ir import visit
from dynd import nd, ndt, _lowlevel

#------------------------------------------------------------------------
# Run
#------------------------------------------------------------------------

def run(func, env):
    visit(CKernelLifter(), func)

#------------------------------------------------------------------------
# Lift CKernels
#------------------------------------------------------------------------

class CKernelLifter(object):
    """
    Lift ckernels to their appropriate rank so they always consume the
    full array arguments.
    """

    def op_ckernel(self, op):
        if op.metadata['rank'] < len(op.type.shape):
            ckernel, args = op.args
            in_dshapes = [arg.type for arg in args]
            out_dshape = op.type
            new_ckernel = lift_ckernel(ckernel, out_dshape, in_dshapes)
            op.args[0] = new_ckernel


def lift_ckernel(ckernel, out_dshape, in_dshapes):
    lifted_types = [ndt.type(str(ds)) for ds in [out_dshape] + in_dshapes]
    print("original types:", repr(ckernel.types))
    print("lifted types:", lifted_types)
    return _lowlevel.lift_ckernel_deferred(ckernel, lifted_types)
{'fraction_non_alphanumeric': 0.30378758297540026, 'fraction_numerical': 0.0015618898867629833, 'mean_word_length': 1.435361216730038, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600532', 'n_tokens_mistral': 664, 'n_tokens_neox': 654, 'n_words': 183}