<commit_before>from joblib import Parallel, delayed

import numpy as np
from . import io_utils


def extract_patches(img, tilesize, steps_per, return_coords=False):
    #ch ro co
    step_size = int(tilesize/steps_per)
    img_shape = img.shape
    if len(img_shape) == 2:
        if io_utils.BACKEND == 'th':
            img = img.reshape((1,) + img_shape)
        else:
            img = img.reshape(img_shape + (1,))

    if io_utils.BACKEND != 'th':
        img = img.transpose(2,0,1)
    rows, cols = img.shape[1:]

    y_coords = list(range(0, rows, step_size))
    x_coords = list(range(0, cols, step_size))
    patches = []
    coords = []
    for ind_y in range(len(y_coords) - steps_per):
        y0 = y_coords[ind_y]
        y1 = y_coords[ind_y + steps_per]
        for ind_x in range(len(x_coords) - steps_per):
            x0 = x_coords[ind_x]
            x1 = x_coords[ind_x + steps_per]
            patches.append(img[:, y0:y1, x0:x1])
            coords.append((y0,x0))

    if rows % tilesize > 0:
        y0 = rows - tilesize
        y1 = rows
        for ind_x in range(len(x_coords) - steps_per):
            x0 = x_coords[ind_x]
            x1 = x_coords[ind_x + steps_per]
            patches.append(img[ :, y0:y1, x0:x1])
            coords.append((y0, x0))

    if cols % tilesize > 0:
        x0 = cols - tilesize
        x1 = cols
        for ind_y in range(len(y_coords) - steps_per):
            y0 = y_coords[ind_y]
            y1 = y_coords[ind_y + steps_per]
            patches.append(img[:, :, y0:y1, x0:x1])
            coords.append((y0, x0))

    patches = [patch.reshape(1,-1,tilesize,tilesize) for patch in patches]

    if io_utils.BACKEND != 'th':
        patches = [patch.transpose(0, 2, 3, 1) for patch in patches]<commit_msg>added timing<commit_after>from joblib import Parallel, delayed

import numpy as np
from . import io_utils


def extract_patches(img, tilesize, steps_per, return_coords=False):
    #ch ro co
    step_size = int(tilesize/steps_per)
    img_shape = img.shape
    if len(img_shape) == 2:
        if io_utils.BACKEND == 'th':
            img = img.reshape((1,) + img_shape)
        else:
            img = img.reshape(img_shape + (1,))

    if io_utils.BACKEND != 'th':
        img = img.transpose(2,0,1)
    rows, cols = img.shape[1:]

    y_coords = list(range(0, rows, step_size))
    x_coords = list(range(0, cols, step_size))
    patches = []
    coords = []
    for ind_y in range(len(y_coords) - steps_per):
        y0 = y_coords[ind_y]
        y1 = y_coords[ind_y + steps_per]
        for ind_x in range(len(x_coords) - steps_per):
            x0 = x_coords[ind_x]
            x1 = x_coords[ind_x + steps_per]
            patches.append(img[:, y0:y1, x0:x1])
            coords.append((y0,x0))

    if rows % tilesize > 0:
        y0 = rows - tilesize
        y1 = rows
        for ind_x in range(len(x_coords) - steps_per):
            x0 = x_coords[ind_x]
            x1 = x_coords[ind_x + steps_per]
            patches.append(img[ :, y0:y1, x0:x1])
            coords.append((y0, x0))

    if cols % tilesize > 0:
        x0 = cols - tilesize
        x1 = cols
        for ind_y in range(len(y_coords) - steps_per):
            y0 = y_coords[ind_y]
            y1 = y_coords[ind_y + steps_per]
            patches.append(img[:, y0:y1, x0:x1])
            coords.append((y0, x0))

    patches = [patch.reshape(1,-1,tilesize,tilesize) for patch in patches]

    if io_utils.BACKEND != 'th':
        patches = [patch.transpose(0, 2, 3, 1) for patch in patches]
{'fraction_non_alphanumeric': 0.12627406568516422, 'fraction_numerical': 0.026613816534541337, 'mean_word_length': 2.157283288650581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1969551', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1350, 'n_words': 290}