Ejemplo n.º 1
0
 def test_structured_add_s_v_grad(self):
     sp_types = {'csc': sp.csc_matrix,
         'csr': sp.csr_matrix}
     
     for format in ['csr', 'csc']:
         for dtype in ['float32', 'float64']:
             spmat = sp_types[format](random_lil((4, 3), dtype, 3))
             mat = numpy.asarray(numpy.random.rand(3), dtype=dtype)
             
             S.verify_grad_sparse(S2.mul_s_v,
                 [spmat, mat], structured=True)
Ejemplo n.º 2
0
 def test_structured_add_s_v_grad(self):
     sp_types = {'csc': sp.csc_matrix,
         'csr': sp.csr_matrix}
     
     for format in ['csr', 'csc']:
         for dtype in ['float32', 'float64']:
             spmat = sp_types[format](random_lil((4, 3), dtype, 3))
             mat = numpy.ones(3, dtype=dtype)
             
             S.verify_grad_sparse(S2.structured_add_s_v,
                 [spmat, mat], structured=True)
Ejemplo n.º 3
0
def test_col_scale():
    x = theano.sparse.csc_dmatrix()
    s = theano.tensor.dvector()

    rng = numpy.random.RandomState(8723)
    R = 5
    C = 8

    x_val_dense = numpy.zeros((R, C), dtype="d")
    for idx in [(0, 0), (4, 1), (2, 1), (3, 3), (4, 4), (3, 7), (2, 7)]:
        x_val_dense.__setitem__(idx, rng.randn())
    x_val = scipy.sparse.csc_matrix(x_val_dense)

    s_val = rng.randn(C)

    f = theano.function([x, s], sp.col_scale(x, s))

    #    print 'A', f(x_val, s_val).toarray()
    #    print 'B', (x_val_dense * s_val)

    assert numpy.all(f(x_val, s_val).toarray() == (x_val_dense * s_val))

    verify_grad_sparse(sp.col_scale, [x_val, s_val], structured=False)
Ejemplo n.º 4
0
def test_col_scale():
    x = theano.sparse.csc_dmatrix()
    s = theano.tensor.dvector()

    rng = numpy.random.RandomState(8723)
    R = 5
    C = 8

    x_val_dense = numpy.zeros((R, C), dtype='d')
    for idx in [(0, 0), (4, 1), (2, 1), (3, 3), (4, 4), (3, 7), (2, 7)]:
        x_val_dense.__setitem__(idx, rng.randn())
    x_val = scipy.sparse.csc_matrix(x_val_dense)

    s_val = rng.randn(C)

    f = theano.function([x, s], sp.col_scale(x, s))

    #    print 'A', f(x_val, s_val).toarray()
    #    print 'B', (x_val_dense * s_val)

    assert numpy.all(f(x_val, s_val).toarray() == (x_val_dense * s_val))

    verify_grad_sparse(sp.col_scale, [x_val, s_val], structured=False)