<commit_before>import numpy as np
from nose.tools import assert_equals

import menpo.io as mio
from menpo.landmark import labeller, ibug_face_68


def test_double_type():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert(patches[0].pixels.dtype == np.float64)


def test_float_type():
    image = mio.import_builtin_asset('breakingbad.jpg')
    image.pixels = image.pixels.astype(np.float32)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert(patches[0].pixels.dtype == np.float32)


def test_uint8_type():
    image = mio.import_builtin_asset('breakingbad.jpg', normalise=False)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert(patches[0].pixels.dtype == np.uint8)


def test_uint8_type_single_array():
    image = mio.import_builtin_asset('breakingbad.jpg', normalise=False)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape,
                                    as_single_array=True)
    assert(patches.dtype == np.uint8)


def test_squared_even_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_squared_odd_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (15, 15)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_nonsquared_even_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 18)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_nonsquared_odd_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (15, 17)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_nonsquared_even_odd_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (15, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_squared_even_patches_landmarks():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches_around_landmarks('PTS',
                                                     patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_squared_even_patches_landmarks_label():
    image = mio.import_builtin_asset('breakingbad.jpg')
    image = labeller(image, 'PTS', ibug_face_68)
    patch_shape = (16, 16)
    patches = image.extract_patches_around_landmarks('ibug_face_68',
                                                     label='nose',
                                                     patch_size=patch_shape)
    assert_equals(len(patches), 9)


def test_squared_even_patches_single_array():
    image = mio.import_builtin_asset('breakingbad.jpg')
    image = labeller(image, 'PTS', ibug_face_68)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    as_single_array=True,
                                    patch_size=patch_shape)
    assert_equals(patches.shape, ((68, 1, 3) + patch_shape))


def test_squared_even_patches_sample_offsets():
    image = mio.import_builtin_asset('breakingbad.jpg')
    image = labeller(image, 'PTS', ibug_face_68)
    sample_offsets = np.array([[0, 0], [1, 0]])
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    sample_offsets=sample_offsets)
    assert_equals(len(patches), 136)<commit_msg>Fixed broken import for test<commit_after>import numpy as np
from nose.tools import assert_equals

import menpo.io as mio
from menpo.landmark import labeller, face_ibug_68_to_face_ibug_68


def test_double_type():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert(patches[0].pixels.dtype == np.float64)


def test_float_type():
    image = mio.import_builtin_asset('breakingbad.jpg')
    image.pixels = image.pixels.astype(np.float32)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert(patches[0].pixels.dtype == np.float32)


def test_uint8_type():
    image = mio.import_builtin_asset('breakingbad.jpg', normalise=False)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert(patches[0].pixels.dtype == np.uint8)


def test_uint8_type_single_array():
    image = mio.import_builtin_asset('breakingbad.jpg', normalise=False)
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape,
                                    as_single_array=True)
    assert(patches.dtype == np.uint8)


def test_squared_even_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_squared_odd_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (15, 15)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_nonsquared_even_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 18)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_nonsquared_odd_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (15, 17)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_nonsquared_even_odd_patches():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (15, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_squared_even_patches_landmarks():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches_around_landmarks('PTS',
                                                     patch_size=patch_shape)
    assert_equals(len(patches), 68)


def test_squared_even_patches_landmarks_label():
    image = mio.import_builtin_asset('breakingbad.jpg')
    image = labeller(image, 'PTS', face_ibug_68_to_face_ibug_68)
    patch_shape = (16, 16)
    patches = image.extract_patches_around_landmarks('face_ibug_68',
                                                     label='nose',
                                                     patch_size=patch_shape)
    assert_equals(len(patches), 9)


def test_squared_even_patches_single_array():
    image = mio.import_builtin_asset('breakingbad.jpg')
    patch_shape = (16, 16)
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    as_single_array=True,
                                    patch_size=patch_shape)
    assert_equals(patches.shape, ((68, 1, 3) + patch_shape))


def test_squared_even_patches_sample_offsets():
    image = mio.import_builtin_asset('breakingbad.jpg')
    sample_offsets = np.array([[0, 0], [1, 0]])
    patches = image.extract_patches(image.landmarks['PTS'].lms,
                                    sample_offsets=sample_offsets)
    assert_equals(len(patches), 136)
{'fraction_non_alphanumeric': 0.10696546147626199, 'fraction_numerical': 0.02194755689037773, 'mean_word_length': 2.618052653572921, 'pattern_counts': {'":': 0, '<': 3, '<?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': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2227149', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2749, 'n_words': 389}