from chainer import cuda
from chainer import function
from chainer.utils import type_check


class Dropout(function.Function):

    """Dropout regularization."""

    def __init__(self, dropout_ratio):
        self.dropout_ratio = dropout_ratio

    def check_type_forwrad(self, in_types):
        type_check.expect(in_types.size() == 1)
        # TODO(okuta): float type check
        # type_check.expect(in_types[0].dtype == numpy.float32)

    def forward(self, x):
        scale = x[0].dtype.type(1. / (1 - self.dropout_ratio))
        xp = cuda.get_array_module(*x)
        self.mask = scale * \
            (xp.random.rand(*x[0].shape) >= self.dropout_ratio)
        return x[0] * self.mask,

    def backward(self, x, gy):
        return gy[0] * self.mask,


def dropout(x, ratio=.5, train=True):
    """Drops elements of input variable randomly.

    This function drops input elements randomly with probability ``ratio`` and
    scales the remaining elements by factor ``1 / (1 - ratio)``. In testing
    mode, it does nothing and just returns ``x``.

    Args:
        x (~chainer.Variable): Input variable.
        ratio (float): Dropout ratio.
        train (bool): If True, executes dropout. Otherwise, does nothing.

    Returns:
        ~chainer.Variable: Output variable.

    See the paper by G. Hinton: `Improving neural networks by preventing \
    co-adaptation of feature detectors <http://arxiv.org/abs/1207.0580>`_.

    """
    if train:
        return Dropout(ratio)(x)
    return x

@@ -1,28 +1,42 @@
+import numpy%0A%0A
 from chainer import cuda%0Afro
@@ -590,29 +590,106 @@
     
-self.mask = scale * %5C
+if xp == numpy:%0A            flag = xp.random.rand(*x%5B0%5D.shape) %3E= self.dropout_ratio%0A        else:
 %0A   
@@ -696,16 +696,23 @@
         
+ flag =
  (xp.ran
@@ -735,32 +735,106 @@
 hape
-) %3E= self.dropout_ratio)
+, dtype=numpy.float32)%0A                    %3E= self.dropout_ratio)%0A        self.mask = scale * flag
 %0A   

Use float32 rand