home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1871 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.4 KB  |  87 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. import types
  6. from IPython.genutils import flatten as genutil_flatten
  7. arrayModules = []
  8.  
  9. try:
  10.     import Numeric
  11. except ImportError:
  12.     pass
  13.  
  14. arrayModules.append({
  15.     'module': Numeric,
  16.     'type': Numeric.arraytype })
  17.  
  18. try:
  19.     import numpy
  20. except ImportError:
  21.     pass
  22.  
  23. arrayModules.append({
  24.     'module': numpy,
  25.     'type': numpy.ndarray })
  26.  
  27. try:
  28.     import numarray
  29. except ImportError:
  30.     pass
  31.  
  32. arrayModules.append({
  33.     'module': numarray,
  34.     'type': numarray.numarraycore.NumArray })
  35.  
  36. class Map:
  37.     
  38.     def getPartition(self, seq, p, q):
  39.         if p < 0 or p >= q:
  40.             print 'No partition exists.'
  41.             return None
  42.         remainder = len(seq) % q
  43.         basesize = len(seq) / q
  44.         hi = []
  45.         lo = []
  46.         for n in range(q):
  47.             if n < remainder:
  48.                 lo.append(n * (basesize + 1))
  49.                 hi.append(lo[-1] + basesize + 1)
  50.                 continue
  51.             p >= q
  52.             lo.append(n * basesize + remainder)
  53.             hi.append(lo[-1] + basesize)
  54.         
  55.         result = seq[lo[p]:hi[p]]
  56.         return result
  57.  
  58.     
  59.     def joinPartitions(self, listOfPartitions):
  60.         return self.concatenate(listOfPartitions)
  61.  
  62.     
  63.     def concatenate(self, listOfPartitions):
  64.         testObject = listOfPartitions[0]
  65.         for m in arrayModules:
  66.             if isinstance(testObject, m['type']):
  67.                 return m['module'].concatenate(listOfPartitions)
  68.         
  69.         if isinstance(testObject, (types.ListType, types.TupleType)):
  70.             return genutil_flatten(listOfPartitions)
  71.         return listOfPartitions
  72.  
  73.  
  74.  
  75. class RoundRobinMap(Map):
  76.     
  77.     def getPartition(self, seq, p, q):
  78.         return seq[p:len(seq):q]
  79.  
  80.     
  81.     def joinPartitions(self, listOfPartitions):
  82.         return self.concatenate(listOfPartitions)
  83.  
  84.  
  85. dists = {
  86.     'b': Map }
  87.