hello, all,

i try to use following code to test the time of matrix multiple and 
slice-matrix multiple, some strange and confusing things happen for me:
please have a look.



import theano.tensor as T
import theano
import numpy
import numpy as np

from theano import function, config, shared, tensor, sandbox
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000


nw = np.random.sample((512, 30000))
nw = shared(np.array(nw, dtype=theano.config.floatX))


def multiple(x):
    return T.dot(x, nw)


def multiple2(x, i):
    return T.dot(x, nw[:, i])


x = T.dmatrix('x')
result1 = multiple(x)
result2 = multiple2(x, 29998)
fn1 = theano.function(inputs=[x], outputs=result1)
fn2 = theano.function(inputs=[x], outputs=result2)
nx = np.random.sample((2560, 512))
s = time.time()
fn1(nx)
e = time.time()
print 'no slice: ', (e - s)


s = time.time()
fn2(nx)
e = time.time()
print 'slice 1: ', (e - s)

i = T.ivector('i')
fn3 = theano.function(inputs=[x, i], outputs=multiple2(x, i))
ni = [29998]
s = time.time()
fn3(nx, ni)
e = time.time()
print 'slice 2: ', (e - s)

i = T.iscalar('i')
fn3 = theano.function(inputs=[x, i], outputs=multiple2(x, i))
s = time.time()
fn3(nx, 29998)
e = time.time()
print 'slice 3: ', (e - s)


when i run this cpu, i got following result:

no slice:  46.1797990799
slice 1:  0.00203585624695
slice 2:  0.0838360786438
slice 3:  0.00367498397827

and when i run this gpu, i got:
no slice:  0.525362014771
slice 1:  0.0137898921967
slice 2:  0.00286388397217
slice 3:  0.0097770690918

for first row, when i do not use slice, multipling 30K column large matrix 
is very slow, this is make sense.
however, i am confusing with the other three rows:
when i use slice, the way how i give parameter i to the function will 
effect the speed of slice
multiple, which way should i choose to make the slice multiple to be the 
fastest.
any reply will be appreciated very much.

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to