def ref_convolution(x, w, b, base_axis, pad, stride, dilation, group): y = [] for xx in x.reshape((-1,) + x.shape[base_axis:]): y += [refs.convolution_nd(xx, w, b, pad, stride, dilation, group)[np.newaxis]] y = np.vstack(y) return y.reshape(x.shape[:base_axis] + y.shape[1:])
def ref_convolution(x, w, b, base_axis, pad, stride, dilation, group, channel_last): if channel_last: t = refs.ChannelLastToFirstTranspose(x.ndim, len(pad)) x = t(x) tw = refs.ChannelLastToFirstTranspose(w.ndim, len(pad)) w = tw(w) y = ref_convolution(x, w, b, base_axis, pad, stride, dilation, group, False) return t.inv(y) y = [] for xx in x.reshape((-1,) + x.shape[base_axis:]): y += [refs.convolution_nd(xx, w, b, pad, stride, dilation, group)[np.newaxis]] y = np.vstack(y) return y.reshape(x.shape[:base_axis] + y.shape[1:])