def benchmark(n_imgs, n_channels, img_shape, n_filters, filter_shape, pad):
    print('\nn_imgs: %i, n_channels: %i, img_shape: (%i, %i), '
          % ((n_imgs, n_channels) + img_shape)
          + 'n_filters: %i, filter_shape: (%i, %i), pad: %i'
          % ((n_filters,) + filter_shape + (pad,)))

    # Setup arrays
    padding = (pad, pad)
    strides = (1, 1)
    img_h, img_w = img_shape
    filter_h, filter_w = filter_shape
    convout_h = img_h + 2*pad - filter_h + 1
    convout_w = img_w + 2*pad - filter_w + 1

    imgs_bc01_shape = (n_imgs, n_channels, img_h, img_w)
    filters_bc01_shape = (n_filters, n_channels, filter_h, filter_w)

    imgs_bc01 = np.random.randn(n_imgs, n_channels, img_h, img_w)
    imgs_c01b = np.transpose(imgs_bc01, (1, 2, 3, 0))
    filters_fc01 = np.random.randn(n_filters, n_channels, filter_h, filter_w)
    filters_c01f = np.transpose(filters_fc01, (1, 2, 3, 0))
    convout_bc01 = np.random.randn(n_imgs, n_filters, convout_h, convout_w)
    convout_c01b = np.transpose(convout_bc01, (1, 2, 3, 0))

    imgs_bc01_t = theano.shared(imgs_bc01.astype(theano.config.floatX))
    imgs_c01b_t = theano.shared(imgs_c01b.astype(theano.config.floatX))
    filters_fc01_t = theano.shared(filters_fc01.astype(theano.config.floatX))
    filters_c01f_t = theano.shared(filters_c01f.astype(theano.config.floatX))
    convout_bc01_t = theano.shared(convout_bc01.astype(theano.config.floatX))
    convout_c01b_t = theano.shared(convout_c01b.astype(theano.config.floatX))
    imgs_bc01_ca = ca.array(imgs_bc01)
    filters_fc01_ca = ca.array(filters_fc01)
    convout_bc01_ca = ca.array(convout_bc01)

    # Forward propagation
    print('fprop')
    convout_cc_op = FilterActs(stride=1, partial_sum=4, pad=pad)
    convout_cc_expr = convout_cc_op(imgs_c01b_t, filters_c01f_t)
    convout_cc_fun = theano.function([], convout_cc_expr)
    convout_cc = convout_cc_fun()
    convout_cc = np.transpose(convout_cc, (3, 0, 1, 2))

    def convout_ca_fun():
        convout = ca.nnet.conv_bc01(imgs_bc01_ca, filters_fc01_ca, padding,
                                    strides)
        return convout
    convout_ca = np.array(convout_ca_fun())
    print('         correct: ' + str(allclose(convout_ca, convout_cc)))
    duration_cc = avg_running_time(convout_cc_fun)
    duration_ca = avg_running_time(convout_ca_fun)
    print('   avg. duration: cuda_convnet: %.4f  ca: %.4f'
          % (duration_cc, duration_ca))
    print('         speedup: %.2f' % (duration_cc/duration_ca))
    del convout_cc_op
    del convout_cc_expr
    del convout_cc_fun

#     Back propagation, imgs
    print('bprop_imgs')
    dimgs_cc_op = ImageActs(stride=1, partial_sum=1, pad=pad)
    dimgs_cc_expr = dimgs_cc_op(convout_c01b_t, filters_c01f_t)
    dimgs_cc_fun = theano.function([], dimgs_cc_expr)
    dimgs_cc = dimgs_cc_fun()
    dimgs_cc = np.transpose(dimgs_cc, (3, 0, 1, 2))

    def dimgs_ca_fun():
        return ca.nnet.conv_bc01_bprop_imgs(filters_fc01_ca, convout_bc01_ca,
                                            img_shape, padding, strides)
    dimgs_ca = np.array(dimgs_ca_fun())
    print('         correct: ' + str(allclose(dimgs_ca, dimgs_cc)))
    duration_cc = avg_running_time(dimgs_cc_fun)
    duration_ca = avg_running_time(dimgs_ca_fun)
    print('   avg. duration: cuda_convnet: %.4f  ca: %.4f'
          % (duration_cc, duration_ca))
    print('         speedup: %.2f' % (duration_cc/duration_ca))
    del dimgs_cc_op
    del dimgs_cc_expr
    del dimgs_cc_fun

    # Back propagation, filters
    dfilters_cc_op = WeightActs(stride=1, partial_sum=1, pad=pad)
    dfilters_cc_expr = dfilters_cc_op(imgs_c01b_t, convout_c01b_t,
                                      T.as_tensor_variable(filter_shape))
    dfilters_cc_fun = theano.function([], dfilters_cc_expr)
    dfilters_cc = dfilters_cc_fun()[0]
    dfilters_cc = np.transpose(dfilters_cc, (3, 0, 1, 2))

    def dfilters_ca_fun():
        return ca.nnet.conv_bc01_bprop_filters(imgs_bc01_ca, convout_bc01_ca,
                                               filter_shape, padding, strides)
    dfilters_ca = np.array(dfilters_ca_fun())

    print('bprop_filters')
    print('         correct: ' + str(allclose(dfilters_ca, dfilters_cc)))
    duration_cc = avg_running_time(dfilters_cc_fun)
    duration_ca = avg_running_time(dfilters_ca_fun)
    print('   avg. duration: cuda_convnet: %.4f  ca: %.4f'
          % (duration_cc, duration_ca))
    print('         speedup: %.2f' % (duration_ca/duration_cc))
dataset/ETHPy150Open andersbll/cudarray/examples/benchmark_conv.py/benchmark/swapped operands of `/`