

def update_viewer(dataset, batch, rows, cols, pv, recons_func, vis_batch):
    '\n    Function to update the viewer with a new visible batch.\n\n    Parameters\n    ----------\n    dataset: pylearn2 dataset\n    batch: numpy array\n    rows: int\n    cols: int\n    pv: PatchViewer\n    recons_func: theano function\n    vis_batch: numpy array\n    '
    mapback = hasattr(dataset, 'mapback_for_viewer')
    topo = (batch.ndim > 2)
    ipt = vis_batch.copy()
    if (not topo):
        ipt = dataset.get_design_matrix(ipt)
    recons_batch = recons_func(ipt.astype(batch.dtype))
    if (not topo):
        recons_batch = dataset.get_topological_view(recons_batch)
    if mapback:
        mapped_batch = get_mapped_batch(dataset, vis_batch)
        mapped_r_batch = get_mapped_batch(dataset, recons_batch.copy())
    for row in xrange(rows):
        row_start = (cols * row)
        for j in xrange(cols):
            vis_patch = vis_batch[(row_start + j), :, :, :].copy()
            adjusted_vis_patch = dataset.adjust_for_viewer(vis_patch)
            if (vis_patch.shape[(- 1)] == 2):
                pv.add_patch(adjusted_vis_patch[:, :, 1], rescale=False)
                pv.add_patch(adjusted_vis_patch[:, :, 0], rescale=False)
            else:
                pv.add_patch(adjusted_vis_patch, rescale=False)
            if mapback:
                pv.add_patch(dataset.adjust_for_viewer(mapped_batch[(row_start + j), :, :, :].copy()), rescale=False)
                pv.add_patch(dataset.adjust_to_be_viewed_with(mapped_r_batch[(row_start + j), :, :, :].copy(), mapped_batch[(row_start + j), :, :, :].copy()), rescale=False)
            if (recons_batch.shape[(- 1)] == 2):
                pv.add_patch(dataset.adjust_to_be_viewed_with(recons_batch[(row_start + j), :, :, 1].copy(), vis_patch), rescale=False)
                pv.add_patch(dataset.adjust_to_be_viewed_with(recons_batch[(row_start + j), :, :, 0].copy(), vis_patch), rescale=False)
            else:
                pv.add_patch(dataset.adjust_to_be_viewed_with(recons_batch[(row_start + j), :, :, :].copy(), vis_patch), rescale=False)

dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/scripts/dbm/show_reconstructions.py update_viewer/original