Mercurial > pylearn
annotate misc.py @ 232:c047238e5b3f
Fixed by James
author | delallea@opale.iro.umontreal.ca |
---|---|
date | Tue, 27 May 2008 15:49:09 -0400 |
parents | d7250ee86f72 |
children | 9e96fe8b955c |
rev | line source |
---|---|
175 | 1 |
2 import theano | |
3 | |
4 class Print(theano.Op): | |
5 def __init__(self,message=""): | |
6 self.message=message | |
7 self.view_map={0:[0]} | |
8 | |
9 def make_node(self,xin): | |
10 xout = xin.type.make_result() | |
11 return theano.Apply(op = self, inputs = [xin], outputs=[xout]) | |
12 | |
13 def perform(self,node,inputs,output_storage): | |
14 xin, = inputs | |
15 xout, = output_storage | |
16 xout[0] = xin | |
17 print self.message,xin | |
18 | |
19 def grad(self,input,output_gradients): | |
20 return output_gradients | |
21 | |
49
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
22 |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
23 def unique_elements_list_intersection(list1,list2): |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
24 """ |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
25 Return the unique elements that are in both list1 and list2 |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
26 (repeated elements in listi will not be duplicated in the result). |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
27 This should run in O(n1+n2) where n1=|list1|, n2=|list2|. |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
28 """ |
718befdc8671
Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff
changeset
|
29 return list(set.intersection(set(list1),set(list2))) |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
30 import time |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
31 #http://www.daniweb.com/code/snippet368.html |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
32 def print_timing(func): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
33 def wrapper(*arg): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
34 t1 = time.time() |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
35 res = func(*arg) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
36 t2 = time.time() |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
37 print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
38 return res |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
175
diff
changeset
|
39 return wrapper |