Using symbolic vector elements as key in python OrderedDict

13 views
Skip to first unread message

Ugur

unread,
Jun 8, 2018, 1:17:02 AM6/8/18
to theano-dev
Hi,

I am a newbie for theano. I am trying to store symbolic keys and values into a python OrderedDict as follows;
hmap=OrderedDict()
key = T.vector('key', dtype='int64')
val = T.scalar('val', dtype='int64')
minus_one=T.constant(-1, dtype='int64')

def read_map(key_):
return hmap.get(key_, minus_one)

def update_map(key_, val_):
hmap[key_]=val_
return hmap[key_]

read_map_result, _ = theano.scan(fn=read_map, sequences=[key], outputs_info=None)
read_map_f = theano.function(inputs=[key], outputs=read_map_result)

update_map_result, updates = theano.scan(fn=update_map, sequences = [key], non_sequences=val, outputs_info=None)
update_map_f = theano.function(inputs=[key, val], outputs=update_map_result, updates=updates)

print(update_map_f([0, 1, 2], 5))
print(read_map_f([2]))
print(hmap)

Giving this output;

[5 5 5]

[-1]

OrderedDict([(key[t], val)])


So lookup for key 2 fails with `read_map_f`.
Any easy solution to this?

Thanks,
Ugur

awbe...@gmail.com

unread,
Oct 19, 2018, 5:03:25 AM10/19/18
to theano-dev
I suppose you'll have to wrap updates to dictionary with new theano operators, at least one for reading http://deeplearning.net/software/theano/extending/extending_theano.html.
Should be simple, just do update in "perform" method.
Reply all
Reply to author
Forward
0 new messages