annotate misc.py @ 313:009ce84e9f52

behaviour is now the same as a list in pylearn, so if len(ds) = 10, ds[10] raise an IndexError, same thing for ds[[1,10]], and ds[0:14:1] returns 10 elements
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Wed, 11 Jun 2008 13:53:39 -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