<commit_before>import math
import unittest

import mock
import numpy
import six

import chainer
from chainer import cuda
from chainer import functions
from chainer import gradient_check
from chainer import testing
from chainer.testing import attr
from chainer.testing import condition


class TestSoftmaxCrossEntropy(unittest.TestCase):

    shape = (4, 3)
    backward_atol = 1e-4
    store_forward = True

    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32)
        out_shape = (self.shape[0],) + self.shape[2:]
        self.t = numpy.random.randint(0, 3, out_shape).astype(numpy.int32)

    def check_forward(self, x_data, t_data, use_cudnn=True):
        x = chainer.Variable(x_data)
        t = chainer.Variable(t_data)
        loss = functions.softmax_cross_entropy(
            x, t, use_cudnn=use_cudnn, store_forward=self.store_forward)
        self.assertEqual(loss.data.shape, ())
        self.assertEqual(loss.data.dtype, numpy.float32)
        loss_value = float(cuda.to_cpu(loss.data))

        # Compute expected value<commit_msg>Check if sce actually stores its forward result<commit_after>import math
import unittest

import mock
import numpy
import six

import chainer
from chainer import cuda
from chainer import functions
from chainer import gradient_check
from chainer import testing
from chainer.testing import attr
from chainer.testing import condition


class TestSoftmaxCrossEntropy(unittest.TestCase):

    shape = (4, 3)
    backward_atol = 1e-4
    store_forward = True

    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32)
        out_shape = (self.shape[0],) + self.shape[2:]
        self.t = numpy.random.randint(0, 3, out_shape).astype(numpy.int32)

    def check_forward(self, x_data, t_data, use_cudnn=True):
        x = chainer.Variable(x_data)
        t = chainer.Variable(t_data)
        loss = functions.softmax_cross_entropy(
            x, t, use_cudnn=use_cudnn, store_forward=self.store_forward)
        self.assertEqual(loss.data.shape, ())
        self.assertEqual(loss.data.dtype, numpy.float32)
        self.assertEqual(hasattr(loss.creator, 'y'), self.store_forward)
        loss_value = float(cuda.to_cpu(loss.data))

        # Compute expected value
{'fraction_non_alphanumeric': 0.0963802878325338, 'fraction_numerical': 0.013955516790231139, 'mean_word_length': 3.4980392156862745, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1091651', 'n_tokens_mistral': 762, 'n_tokens_neox': 737, 'n_words': 171}