<commit_before>#cython: cdivision=True
#cython: boundscheck=False
#cython: nonecheck=False
#cython: wraparound=False
import numpy as np
cimport numpy as cnp
from libc.float cimport DBL_MAX

from skimage.color import rgb2grey
from skimage.util import img_as_float


def moravec(image, int block_size=1):
    """Compute Moravec response image.

    This interest operator is comparatively fast but not rotation invariant.

    Parameters
    ----------
    image : ndarray
        Input image.
    block_size : int, optional
        Block size for mean filtering the squared gradients.

    Returns
    -------
    response : ndarray
        Moravec response image.

    References
    ----------
    ..[1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/moravec.htm

    Examples
    -------
    >>> from skimage.feature import moravec, peak_local_max
    >>> square = np.zeros([7, 7])
    >>> square[3, 3] = 1
    >>> square
    array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
    >>> moravec(square)
    array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
           [ 0.,  0.,  1.,  2.,  1.,  0.,  0.],
           [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
    """

    cdef int rows = image.shape[0]
    cdef int cols = image.shape[1]

    cdef cnp.ndarray[dtype=cnp.double_t, ndim=2, mode='c'] cimage, out

    if image.ndim == 3:
        cimage = rgb2grey(image)
    cimage = np.ascontiguousarray(img_as_float(image))

    out = np.zeros_like(image)

    cdef double* image_data = <double*>cimage.data
    cdef double* out_data = <double*>out.data

    cdef double msum, min_msum
    cdef int r, c, br, bc, mr, mc, a, b
    for r in range(2 * block_size, rows - 2 * block_size):
        for c in range(2 * block_size, cols - 2 * block_size):
            min_msum = DBL_MAX
            for br in range(r - block_size, r + block_size + 1):
                for bc in range(c - block_size, c + block_size + 1):
                    if br != r and bc != c:
                        msum = 0
                        for mr in range(- block_size, block_size + 1):
                            for mc in range(- block_size, block_size + 1):
                                a = (r + mr) * cols + c + mc
                                b = (br + mr) * cols + bc + mc
                                msum += (image_data[a] - image_data[b]) ** 2
                        min_msum = min(msum, min_msum)

            out_data[r * cols + c] = min_msum<commit_msg>Rename window size parameter of moravec operator<commit_after>#cython: cdivision=True
#cython: boundscheck=False
#cython: nonecheck=False
#cython: wraparound=False
import numpy as np
cimport numpy as cnp
from libc.float cimport DBL_MAX

from skimage.color import rgb2grey
from skimage.util import img_as_float


def moravec(image, int window_size=1):
    """Compute Moravec response image.

    This interest operator is comparatively fast but not rotation invariant.

    Parameters
    ----------
    image : ndarray
        Input image.
    window_size : int, optional
        Window size.

    Returns
    -------
    response : ndarray
        Moravec response image.

    References
    ----------
    ..[1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/moravec.htm

    Examples
    -------
    >>> from skimage.feature import moravec, peak_local_max
    >>> square = np.zeros([7, 7])
    >>> square[3, 3] = 1
    >>> square
    array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
    >>> moravec(square)
    array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
           [ 0.,  0.,  1.,  2.,  1.,  0.,  0.],
           [ 0.,  0.,  1.,  1.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.]])
    """

    cdef int rows = image.shape[0]
    cdef int cols = image.shape[1]

    cdef cnp.ndarray[dtype=cnp.double_t, ndim=2, mode='c'] cimage, out

    if image.ndim == 3:
        cimage = rgb2grey(image)
    cimage = np.ascontiguousarray(img_as_float(image))

    out = np.zeros_like(image)

    cdef double* image_data = <double*>cimage.data
    cdef double* out_data = <double*>out.data

    cdef double msum, min_msum
    cdef int r, c, br, bc, mr, mc, a, b
    for r in range(2 * window_size, rows - 2 * window_size):
        for c in range(2 * window_size, cols - 2 * window_size):
            min_msum = DBL_MAX
            for br in range(r - window_size, r + window_size + 1):
                for bc in range(c - window_size, c + window_size + 1):
                    if br != r and bc != c:
                        msum = 0
                        for mr in range(- window_size, window_size + 1):
                            for mc in range(- window_size, window_size + 1):
                                a = (r + mr) * cols + c + mc
                                b = (br + mr) * cols + bc + mc
                                msum += (image_data[a] - image_data[b]) ** 2
                        min_msum = min(msum, min_msum)

            out_data[r * cols + c] = min_msum
{'fraction_non_alphanumeric': 0.1663522551877894, 'fraction_numerical': 0.04150231521179901, 'mean_word_length': 1.3931062782109151, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2339982', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2117, 'n_words': 617}