Since Theano allows to update the memory on the graphics card DRAM by simply defining which memory area has to be updated and how this should be done, I was wondering if the following is somehoe possible (imho it should be).
I have a 2x5 randomly initialized matrix which first column will be initialized with start-values. I would like to write a function that depends of the preceeding column and updates the next one based on arbitrary calulations.
I think this code explains it very well:
Note: This code is not working, it's just an illustration:
from theano import function, sandbox, shared
import theano.tensor as T
import numpy as np
reservoirSize = 2
samples = 5
# To initialize _mat first column
_vec = np.asarray([1 for i in range(reservoirSize)], np.float32)
# Random matrix, first column will be initialized correctly (_vec)
_mat = np.asarray(np.random.rand(reservoirSize, samples), np.float32)
_mat[:,0] = _vec
print "Init:\n",_mat
_mat = shared(_mat)
idx = T.iscalar()
test = function([idx], updates= {
# The indexing causes the problem here. Imho there should be
# a way to do something like this:
# update: _mat[:, idx] = _max[:, idx-1] * 2
_mat[:,idx]:sandbox.cuda.basic_ops.gpu_from_host(_mat[:,idx-1] * 2)
})
for i in range(1, samples):
test(i)
print "Done:\n",_mat
My desired output would be:
Init:
[[ 1. 0.62166548 0.17463242 0.00858122 0.59709388]
[ 1. 0.52690667 0.20800008 0.86816955 0.43518791]]
Done:
[[ 1. 2. 4. 8. 16. ]
1. 2. 4. 8. 16. ]]
but instead I get
Init:
[[ 1. 0.62166548 0.17463242 0.00858122 0.59709388]
[ 1. 0.52690667 0.20800008 0.86816955 0.43518791]]
Traceback (most recent call last):
File "/home/snooc/workspace/eclipse-python/Bachelorarbeit/theano/test.py", line 20, in <module>
_mat[:,idx]:sandbox.cuda.basic_ops.gpu_from_host(_mat[:,idx-1] * 2) })
File "/usr/lib/python2.7/site-packages/theano/compile/function.py", line 223, in function
profile=profile)
File "/usr/lib/python2.7/site-packages/theano/compile/pfunc.py", line 490, in pfunc
no_default_updates=no_default_updates)
File "/usr/lib/python2.7/site-packages/theano/compile/pfunc.py", line 194, in rebuild_collect_shared
store_into)
TypeError: ('update target must be a SharedVariable', Subtensor{::, int32}.0)
Can anybody help me here?
Wow: This question is 9 minutes after asking already in the Top 4 of google results for "Theano indexing gpu" for me. O_o