<commit_before>"""
Routines for extracting (reflected) windows of image stacks in
(channels, rows, cols, batch_size) format.
"""
import numpy as np
cimport numpy as np
cimport cython

from pylearn2.utils.rng import make_np_rng


cdef extern from "stdlib.h":
    int rand_r(unsigned int *seedp) nogil


def _check_args(np.ndarray[np.float32_t, ndim=4] images,
                tuple window_shape,
                np.ndarray[np.float32_t, ndim=4] out=None):
    """
    Do common validation for the two routines in this file.
    """
    cdef np.npy_intp rows = images.shape[1]
    cdef np.npy_intp cols = images.shape[2]
    cdef np.npy_intp window_r = window_shape[0]
    cdef np.npy_intp window_c = window_shape[1]
    if len(window_shape) != 2:
        raise ValueError("window_shape should be length 2")
    elif window_r > rows or window_c > cols:
        raise ValueError("window_shape (%d, %d) greater than image shape "
                         "(%d, %d)" % (window_r, window_c, rows, cols))
    if out is not None:
        if (out.shape[0] != images.shape[0] or out.shape[1] != window_r or
            out.shape[2] != window_c or out.shape[3] != images.shape[3]):
            raise ValueError("out argument had wrong shape")


@cython.boundscheck(False)
@cython.cdivision(True)
def random_window_and_flip_c01b(np.ndarray[np.float32_t, ndim=4] images,
                                tuple window_shape,
                                np.ndarray[np.float32_t, ndim=4] out=None,<commit_msg>Disable rand_r at compile time on Windows.<commit_after>"""
Routines for extracting (reflected) windows of image stacks in
(channels, rows, cols, batch_size) format.
"""
import logging
import numpy as np
cimport numpy as np
cimport cython

from pylearn2.utils.rng import make_np_rng


IF UNAME_SYSNAME == "Windows":
    cdef extern from "stdlib.h":
        int rand()
    cdef int rand_r(unsigned int *seedp) nogil:
        return rand()
    log = logging.getLogger(__name__)
    log.warning("Microsoft Windows detected; experiments with WindowAndFlip "
                "will not be deterministic/repeatable even with same seed "
                "because MSVCRT does not implement rand_r.")
ELSE:
    cdef extern from "stdlib.h":
        int rand_r(unsigned int *seedp) nogil


def _check_args(np.ndarray[np.float32_t, ndim=4] images,
                tuple window_shape,
                np.ndarray[np.float32_t, ndim=4] out=None):
    """
    Do common validation for the two routines in this file.
    """
    cdef np.npy_intp rows = images.shape[1]
    cdef np.npy_intp cols = images.shape[2]
    cdef np.npy_intp window_r = window_shape[0]
    cdef np.npy_intp window_c = window_shape[1]
    if len(window_shape) != 2:
        raise ValueError("window_shape should be length 2")
    elif window_r > rows or window_c > cols:
        raise ValueError("window_shape (%d, %d) greater than image shape "
                         "(%d, %d)" % (window_r, window_c, rows, cols))
    if out is not None:
        if (out.shape[0] != images.shape[0] or out.shape[1] != window_r or
            out.shape[2] != window_c or out.shape[3] != images.shape[3]):
            raise ValueError("out argument had wrong shape")


@cython.boundscheck(False)
@cython.cdivision(True)
def random_window_and_flip_c01b(np.ndarray[np.float32_t, ndim=4] images,
                                tuple window_shape,
                                np.ndarray[np.float32_t, ndim=4] out=None,
{'fraction_non_alphanumeric': 0.10387731481481481, 'fraction_numerical': 0.015625, 'mean_word_length': 2.7292340884573894, 'pattern_counts': {'":': 4, '<': 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': '1662512', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1135, 'n_words': 319}