from collections import Mapping from numbers import Integral import numpy as np from distarray.externals import six from distarray.externals.six.moves import zip from distarray.local.mpiutils import MPI from distarray.utils import _raise_nie from distarray.local import format, maps from distarray.local.error import InvalidDimensionError, IncompatibleArrayError # Register numpy integer types with numbers.Integral ABC. Integral.register(np.signedinteger) Integral.register(np.unsignedinteger) def _sanitize_indices(indices): if isinstance(indices, Integral) or isinstance(indices, slice): return (indices,) elif all(isinstance(i, Integral) or isinstance(i, slice) for i in indices): return indices else: raise TypeError("Index must be a sequence of ints and slices") class GlobalIndex(object): """Object which provides access to global indexing on LocalArrays.
import operator from itertools import product from functools import reduce from numbers import Integral from collections import Sequence, Mapping import numpy from distarray import utils from distarray.externals.six import next from distarray.externals.six.moves import map, zip # Register numpy integer types with numbers.Integral ABC. Integral.register(numpy.signedinteger) Integral.register(numpy.unsignedinteger) class InvalidGridShapeError(Exception): """ Exception class when the grid shape is incompatible with the distribution or communicator. """ pass class GridShapeError(Exception): """ Exception class when it is not possible to distribute the processes over the number of dimensions. """ pass def check_grid_shape_preconditions(shape, dist, comm_size): """
def get_vmc_version(): import os from subprocess import check_output, CalledProcessError original_directory = os.getcwd() try: os.chdir(os.path.dirname(__file__)) try: return check_output(["git", "describe", "--always"]) except CalledProcessError: return None finally: os.chdir(original_directory) import six if six.PY3: import numpy from collections import Hashable from numbers import Integral # FIXME: track down why we are passing around these int64's anyway if not isinstance(numpy.int64, Integral): Integral.register(numpy.int64) if not isinstance(numpy.int64, Hashable): Hashable.register(numpy.int64) # FIXME: numpy.ndarray is Hashable in python2 but not python3. Honestly, I # don't think it should be in either... Hashable.register(numpy.ndarray)
from matplotlib import cbook from matplotlib.axes import Axes from matplotlib.backend_bases import RendererBase from matplotlib.collections import (LineCollection, PatchCollection, PathCollection) from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer from matplotlib.figure import Figure from matplotlib.image import AxesImage from matplotlib.lines import Line2D from matplotlib.patches import Patch, PathPatch, Polygon, Rectangle from matplotlib.quiver import Barbs, Quiver from matplotlib.text import Text from matplotlib.transforms import Affine2D import numpy as np Integral.register(np.integer) # numpy<1.9 backcompat. PATCH_PICKRADIUS = 5 # FIXME Patches do not provide `pickradius`. def _register_scatter(): """ Patch `PathCollection` and `scatter` to register their return values. This registration allows us to distinguish `PathCollection`s created by `Axes.scatter`, which should use point-like picking, from others, which should use path-like picking. The former is more common, so we store the latter instead; this also lets us guess the type better if this module is imported late. """ @functools.wraps(PathCollection.__init__) def __init__(self, *args, **kwargs):
from matplotlib import cbook from matplotlib.axes import Axes from matplotlib.collections import LineCollection, PathCollection from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer from matplotlib.image import AxesImage from matplotlib.lines import Line2D from matplotlib.patches import Patch, PathPatch, Polygon, Rectangle from matplotlib.path import Path as MPath from matplotlib.quiver import Barbs, Quiver from matplotlib.text import Text from matplotlib.transforms import Affine2D import numpy as np Integral.register(np.integer) # Back-compatibility for numpy 1.7, 1.8. def _register_scatter(): """Patch `PathCollection` and `scatter` to register their return values. This registration allows us to distinguish `PathCollection`s created by `Axes.scatter`, which should use point-like picking, from others, which should use path-like picking. The former is more common, so we store the latter instead; this also lets us guess the type better if this module is imported late. """ @functools.wraps(PathCollection.__init__) def __init__(self, *args, **kwargs): _nonscatter_pathcollections.add(self)
from __future__ import division import operator from itertools import product from functools import reduce from numbers import Integral from collections import Sequence, Mapping import numpy from distarray import utils from distarray.externals.six import next from distarray.externals.six.moves import map, zip # Register numpy integer types with numbers.Integral ABC. Integral.register(numpy.signedinteger) Integral.register(numpy.unsignedinteger) class InvalidGridShapeError(Exception): """ Exception class when the grid shape is incompatible with the distribution or communicator. """ pass class GridShapeError(Exception): """ Exception class when it is not possible to distribute the processes over the number of dimensions. """ pass def check_grid_shape_preconditions(shape, dist, comm_size): """
assert isinstance(i, int) self.i = i def __int__(self): """int(self)""" return self.i __index__ = __int__ def __eq__(self, i): """self == i""" return self.i == i # noinspection PyUnresolvedReferences Integral.register(IntWrapper) class FloatWrapper: def __init__(self, f): assert isinstance(f, float) self.f = f def __float__(self): """float(self)""" return self.f def __eq__(self, f): """self == f""" return self.f == f
def test_integral_is_integer(self): self.assertTrue(Integral.is_integer(-1)) self.assertTrue(Integral.is_integer(0)) self.assertTrue(Integral.is_integer(1)) self.assertTrue(Integral.is_integer(1729))
from __future__ import division import operator from functools import reduce from numbers import Integral import numpy as np from distarray.externals.six.moves import range, zip, reduce from distarray.localapi import construct from distarray.metadata_utils import (make_grid_shape, normalize_grid_shape, normalize_dist, distribute_indices, sanitize_indices) # Register numpy integer types with numbers.Integral ABC. Integral.register(np.signedinteger) Integral.register(np.unsignedinteger) class Distribution(object): """Multi-dimensional Map class. Manages one or more one-dimensional map classes. """ def __init__(self, comm, dim_data): """Create a Distribution from a `dim_data` structure.""" self._maps = tuple( map_from_dim_dict(dim_dict) for dim_dict in dim_data) self.base_comm = construct.init_base_comm(comm) self.comm = construct.init_comm(self.base_comm, self.grid_shape)