Exemple #1
0
def test_forward_gpu():
    x = cuda.to_gpu(numpy.array([[1, 2, 3], [6, 5, 4]], dtype=numpy.float32))
    output = softmax(x)
    expect_output = numpy.array([[0.09003057, 0.24472848, 0.66524094],
                                 [0.66524094, 0.24472848, 0.09003057]],
                                dtype=numpy.float32)
    numpy.allclose(cuda.to_cpu(output.array), expect_output)
def test_forward_gpu():
    x = cuda.to_gpu(numpy.array([[1, 2, 3], [6, 5, 4]], dtype=numpy.float32))
    output = softmax(x)
    expect_output = numpy.array([
        [0.09003057, 0.24472848, 0.66524094],
        [0.66524094, 0.24472848, 0.09003057]], dtype=numpy.float32)
    numpy.allclose(cuda.to_cpu(output.array), expect_output)
Exemple #3
0
def test_forward_cpu_with_mask():
    x = numpy.array([[1, 2, 3, 2, 5], [1, 6, 5, 4, 2]], dtype=numpy.float32)
    mask = numpy.array([[1, 1, 1, 0, 0], [0, 1, 1, 1, 0]], dtype=numpy.float32)
    output = softmax(x, mask=mask)
    expect_output = numpy.array([[0.09003057, 0.24472848, 0.66524094, 0., 0.],
                                 [0., 0.66524094, 0.24472848, 0.09003057, 0.]],
                                dtype=numpy.float32)
    numpy.allclose(output.array, expect_output)
def test_forward_cpu_with_mask():
    x = numpy.array([[1, 2, 3, 2, 5], [1, 6, 5, 4, 2]], dtype=numpy.float32)
    mask = numpy.array([[1, 1, 1, 0, 0], [0, 1, 1, 1, 0]], dtype=numpy.float32)
    output = softmax(x, mask=mask)
    expect_output = numpy.array([
        [0.09003057, 0.24472848, 0.66524094, 0., 0.],
        [0., 0.66524094, 0.24472848, 0.09003057, 0.]], dtype=numpy.float32)
    numpy.allclose(output.array, expect_output)