annotate misc.py @ 296:f5d33f9c0b9c

ApplyFunctionDataSet passing
author James Bergstra <bergstrj@iro.umontreal.ca>
date Fri, 06 Jun 2008 17:50:29 -0400
parents 9e96fe8b955c
children 430c9e92cd23
rev   line source
49
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
1
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
2 def unique_elements_list_intersection(list1,list2):
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
3 """
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
4 Return the unique elements that are in both list1 and list2
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
5 (repeated elements in listi will not be duplicated in the result).
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
6 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
7 """
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
8 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
9 import time
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
10 #http://www.daniweb.com/code/snippet368.html
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
11 def print_timing(func):
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
12 def wrapper(*arg):
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
13 t1 = time.time()
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
14 res = func(*arg)
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
15 t2 = time.time()
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
16 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
17 return res
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
18 return wrapper