home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __docformat__ = 'restructuredtext en'
- import types
- from IPython.genutils import flatten as genutil_flatten
- arrayModules = []
-
- try:
- import Numeric
- except ImportError:
- pass
-
- arrayModules.append({
- 'module': Numeric,
- 'type': Numeric.arraytype })
-
- try:
- import numpy
- except ImportError:
- pass
-
- arrayModules.append({
- 'module': numpy,
- 'type': numpy.ndarray })
-
- try:
- import numarray
- except ImportError:
- pass
-
- arrayModules.append({
- 'module': numarray,
- 'type': numarray.numarraycore.NumArray })
-
- class Map:
-
- def getPartition(self, seq, p, q):
- if p < 0 or p >= q:
- print 'No partition exists.'
- return None
- remainder = len(seq) % q
- basesize = len(seq) / q
- hi = []
- lo = []
- for n in range(q):
- if n < remainder:
- lo.append(n * (basesize + 1))
- hi.append(lo[-1] + basesize + 1)
- continue
- p >= q
- lo.append(n * basesize + remainder)
- hi.append(lo[-1] + basesize)
-
- result = seq[lo[p]:hi[p]]
- return result
-
-
- def joinPartitions(self, listOfPartitions):
- return self.concatenate(listOfPartitions)
-
-
- def concatenate(self, listOfPartitions):
- testObject = listOfPartitions[0]
- for m in arrayModules:
- if isinstance(testObject, m['type']):
- return m['module'].concatenate(listOfPartitions)
-
- if isinstance(testObject, (types.ListType, types.TupleType)):
- return genutil_flatten(listOfPartitions)
- return listOfPartitions
-
-
-
- class RoundRobinMap(Map):
-
- def getPartition(self, seq, p, q):
- return seq[p:len(seq):q]
-
-
- def joinPartitions(self, listOfPartitions):
- return self.concatenate(listOfPartitions)
-
-
- dists = {
- 'b': Map }
-