def bprop_test()

in blocksparse/matmul.py [0:0]


    def bprop_test(self, E, W, gate=None):
        bsize = self.bsize
        if self.axis:
            B = np.zeros((E.shape[0], self.CB, bsize))
            E = E.reshape((-1, self.KB, bsize))
            for c, lut in self.bprop_list:
                for k, w in lut:
                    B[:,c,:] += np.dot( E[:,k,:], W[w,:,:].T ) # NK x CK.T = NC
            return B.reshape(E.shape[0], -1)
        else:
            N = E[0].size
            B = np.zeros((self.CB, bsize, N))
            E = E.reshape((self.KB, bsize, N))
            for c, lut in self.bprop_list:
                if gate is None:
                    for k, w in lut:
                        B[c,:,:] += np.dot( W[w,:,:], E[k,:,:] ) # CK x KN = CN
                else:
                    for k, w in lut:
                        if gate[w] != 0.0:
                            B[c,:,:] += np.dot( W[w,:,:], E[k,:,:] ) * gate[w] # CK x KN = CN

            return B.reshape(-1, N)