提交 136c6d44 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3847 from jojolalpin/master

Update opt.py
...@@ -348,8 +348,8 @@ class StructuredDotCSC(gof.Op): ...@@ -348,8 +348,8 @@ class StructuredDotCSC(gof.Op):
// pointers to access actual data in the arrays passed as params. // pointers to access actual data in the arrays passed as params.
dtype_%(z)s* __restrict__ Dz = (dtype_%(z)s*)PyArray_DATA(%(z)s); dtype_%(z)s* __restrict__ Dz = (dtype_%(z)s*)PyArray_DATA(%(z)s);
const dtype_%(a_val)s* __restrict__ Dval = (dtype_%(a_val)s*)PyArray_DATA(%(a_val)s); const dtype_%(a_val)s* __restrict__ Dval = (dtype_%(a_val)s*)PyArray_DATA(%(a_val)s);
const npy_int32 * __restrict__ Dind = (npy_int32*)PyArray_DATA(%(a_ind)s; const npy_int32 * __restrict__ Dind = (npy_int32*)PyArray_DATA(%(a_ind)s);
const npy_int32 * __restrict__ Dptr = (npy_int32*)PyArray_DATA(%(a_ptr)s; const npy_int32 * __restrict__ Dptr = (npy_int32*)PyArray_DATA(%(a_ptr)s);
//npy_intp nnz = PyArray_DIMS(%(a_ind)s)[0]; //npy_intp nnz = PyArray_DIMS(%(a_ind)s)[0];
......
...@@ -152,3 +152,20 @@ def test_local_dense_from_sparse_sparse_from_dense(): ...@@ -152,3 +152,20 @@ def test_local_dense_from_sparse_sparse_from_dense():
# We should just have a deep copy. # We should just have a deep copy.
assert len(f.maker.fgraph.apply_nodes) == 1 assert len(f.maker.fgraph.apply_nodes) == 1
f([[1, 2], [3, 4]]) f([[1, 2], [3, 4]])
def test_sd_csc():
A = sp.rand(4, 5, density=0.60, format='csc', dtype=numpy.float32)
b = numpy.random.rand(5,2).astype(numpy.float32)
target = A*b
a_val = theano.tensor.as_tensor_variable(A.data)
a_ind = theano.tensor.as_tensor_variable(A.indices)
a_ptr = theano.tensor.as_tensor_variable(A.indptr)
nrows = theano.tensor.as_tensor_variable(numpy.int32(A.shape[0]))
b = theano.tensor.as_tensor_variable(b)
res = theano.sparse.opt.sd_csc(a_val, a_ind, a_ptr, nrows, b).eval()
assert (res==target).all()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论