Discussion:
[theano-users] Can I set values to the indexes of a sparse matrix using the scan function?
Ugur Koc
2018-06-22 17:24:55 UTC
Permalink
Consider this code;
import scipy.sparse as sp
from theano import sparse

hmap = sparse.csc_matrix('hmap', dtype='int64')
did = T.vector('did', dtype='int64')
xid = T.vector('xid', dtype='int64')
val = T.scalar('val', dtype='int64')

def update_map(did_, xid_, val_, mymap):
mymap[did_, xid_] = val_
return mymap

rval, updates = theano.scan(fn=update_map, sequences=[did, xid],
non_sequences=val, outputs_info=hmap)
update_map_tf = theano.function(inputs=[did, xid, val, hmap], outputs=rval,
updates=updates)

spm = sp.csc_matrix((4, 4), dtype='int64')
update_map_tf([0, 1], [2, 3], 5, spm)
print(spm.toarray())


So I'd like to have following result from the previous code;
[[0 5 0 0]
[0 0 0 0]
[0 0 0 5]
[0 0 0 0]]


Assuming the values in `did` and `xid` are within the bounds of the matrix
`hmap`, is this possible?

Thanks,
Ugur
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Frédéric Bastien
2018-06-22 19:06:09 UTC
Permalink
Scan do not support sparse variable in input or output.

Due to
https://groups.google.com/forum/#!msg/theano-users/7Poq8BZutbY/rNCIfvAEAwAJ
we won't add that feature.

Frédéric
Post by Ugur Koc
Consider this code;
import scipy.sparse as sp
from theano import sparse
hmap = sparse.csc_matrix('hmap', dtype='int64')
did = T.vector('did', dtype='int64')
xid = T.vector('xid', dtype='int64')
val = T.scalar('val', dtype='int64')
mymap[did_, xid_] = val_
return mymap
rval, updates = theano.scan(fn=update_map, sequences=[did, xid],
non_sequences=val, outputs_info=hmap)
update_map_tf = theano.function(inputs=[did, xid, val, hmap], outputs=rval
, updates=updates)
spm = sp.csc_matrix((4, 4), dtype='int64')
update_map_tf([0, 1], [2, 3], 5, spm)
print(spm.toarray())
So I'd like to have following result from the previous code;
[[0 5 0 0]
[0 0 0 0]
[0 0 0 5]
[0 0 0 0]]
Assuming the values in `did` and `xid` are within the bounds of the matrix
`hmap`, is this possible?
Thanks,
Ugur
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...