The reason for this is that the index is a symbolic tensor variable (a long scalar, as you can see in line 4). Therefore, when python tries to build the dictionary that anano needs for its βgivenβ input, it tries to truncate the numpy array using a symbolic variable, which obviously cannot be done since it doesn't matter yet (this is only when you type then into the function).
As you understand, data transfer through theano.shared is the best approach. This means that all training data can be uploaded to the GPU and then sliced ββ/ indexed on the fly to run each example.
However, you may find that you have too much training data to match your GPU memory, or for some other reason do not want to use a shared variable. Then you can simply change your function definition
data = T.matrix() fff=theano.function(inputs=[data], outputs=cost, givens={x: data} )
Then instead of writing
fff(index)
You write
fff(train_set_x[index: index+1])
It should be warned that the process of moving data to the GPU is slow, so it is much better to minimize the number of transfers, if possible.
source share