def test_diag(): m = theano.sparse.csc_matrix() d = sp.diag(m) f = theano.function([m], d) f2 = theano.function([m], d.shape) for K in 1, 5: np_matrix = numpy.asarray(numpy.reshape(range(K ** 2), (K, K)), dtype=theano.config.floatX) diag = numpy.diagonal(np_matrix) sp_matrix = scipy.sparse.csc_matrix(np_matrix) assert numpy.all(diag == f(sp_matrix)) assert f2(sp_matrix) == diag.shape
def test_diag(): m = theano.sparse.csc_matrix() d = sp.diag(m) f = theano.function([m], d) f2 = theano.function([m], d.shape) for K in 1, 5: np_matrix = numpy.asarray(numpy.reshape(range(K**2), (K, K)), dtype=theano.config.floatX) diag = numpy.diagonal(np_matrix) sp_matrix = scipy.sparse.csc_matrix(np_matrix) assert numpy.all(diag == f(sp_matrix)) assert f2(sp_matrix) == diag.shape
def d(x): sp_x = theano.sparse.csc_from_dense(x) diag_x = sp.diag(sp_x) return diag_x.sum()
def d(x): sp_x = theano.sparse.csc_from_dense(x) diag_x = sp.diag(sp_x) return diag_x.sum()