See https://github.com/lisa-lab/pylearn2/blob/master/pylearn2/corruption.py#L154 . I didn't write this code, not sure why it is in diff.