Exemplo n.º 1
0
 def slice_owners(self, idx):
     start = idx.start if idx.start is not None else 0
     stop = idx.stop if idx.stop is not None else self.size
     step = idx.step if idx.step is not None else 1
     if tuple_intersection((start, stop, step), (0, self.size)):
         return [0]
     else:
         return []
Exemplo n.º 2
0
 def slice_owners(self, idx):
     start = idx.start if idx.start is not None else 0
     stop = idx.stop if idx.stop is not None else self.size
     step = idx.step if idx.step is not None else 1
     if tuple_intersection((start, stop, step), (0, self.size)):
         return [0]
     else:
         return []
Exemplo n.º 3
0
 def slice_owners(self, idx):
     coords = []
     start = idx.start if idx.start is not None else 0
     stop = idx.stop if idx.stop is not None else self.size
     step = idx.step if idx.step is not None else 1
     for (coord, (lower, upper)) in enumerate(self.bounds):
         if tuple_intersection((start, stop, step), (lower, upper)):
             coords.append(coord)
     return coords
Exemplo n.º 4
0
 def slice_owners(self, idx):
     coords = []
     start = idx.start if idx.start is not None else 0
     stop = idx.stop if idx.stop is not None else self.size
     step = idx.step if idx.step is not None else 1
     for (coord, (lower, upper)) in enumerate(self.bounds):
         if tuple_intersection((start, stop, step), (lower, upper)):
             coords.append(coord)
     return coords
Exemplo n.º 5
0
 def slice(self, idx):
     """Make a new Map from a slice."""
     start = idx.start if idx.start is not None else 0
     stop = idx.stop if idx.stop is not None else self.size
     step = idx.step if idx.step is not None else 1
     isection = tuple_intersection((start, stop, step), (0, self.size))
     if isection:
         step = idx.step if idx.step is not None else 1
         isection_size = int(np.ceil((isection[1] - isection[0]) / step))
     else:
         isection_size = 0
     return self.__class__(size=isection_size, grid_size=1)
Exemplo n.º 6
0
 def slice(self, idx):
     """Make a new Map from a slice."""
     start = idx.start if idx.start is not None else 0
     stop = idx.stop if idx.stop is not None else self.size
     step = idx.step if idx.step is not None else 1
     isection = tuple_intersection((start, stop, step), (0, self.size))
     if isection:
         step = idx.step if idx.step is not None else 1
         isection_size = int(np.ceil((isection[1] - isection[0]) / step))
     else:
         isection_size = 0
     return self.__class__(size=isection_size, grid_size=1)
Exemplo n.º 7
0
    def _redist_intersection_same_shape(source_dimdata, dest_dimdata):

        intersections = []
        for source_dimdict, dest_dimdict in zip(source_dimdata, dest_dimdata):

            if not (source_dimdict['dist_type'] ==
                    dest_dimdict['dist_type'] == 'b'):
                raise ValueError("Only 'b' dist_type supported")

            source_idxs = source_dimdict['start'], source_dimdict['stop']
            dest_idxs = dest_dimdict['start'], dest_dimdict['stop']

            intersections.append(tuple_intersection(source_idxs, dest_idxs))

        return intersections
Exemplo n.º 8
0
    def _redist_intersection_same_shape(source_dimdata, dest_dimdata):

        intersections = []
        for source_dimdict, dest_dimdict in zip(source_dimdata, dest_dimdata):

            if not (source_dimdict['dist_type'] == dest_dimdict['dist_type'] ==
                    'b'):
                raise ValueError("Only 'b' dist_type supported")

            source_idxs = source_dimdict['start'], source_dimdict['stop']
            dest_idxs = dest_dimdict['start'], dest_dimdict['stop']

            intersections.append(tuple_intersection(source_idxs, dest_idxs))

        return intersections
Exemplo n.º 9
0
    def slice(self, idx):
        """Make a new Map from a slice."""
        new_bounds = [0]
        start = idx.start if idx.start is not None else 0
        step = idx.step if idx.step is not None else 1
        # iterate over the processes in this dimension
        for proc_start, proc_stop in self.bounds:
            stop = idx.stop if idx.stop is not None else proc_stop
            isection = tuple_intersection((start, stop, step),
                                          (proc_start, proc_stop))
            if isection:
                isection_size = int(np.ceil((isection[1] - (isection[0])) / step))
                new_bounds.append(isection_size + new_bounds[-1])
        if new_bounds == [0]:
            new_bounds = []

        size = new_bounds[-1] if len(new_bounds) > 0 else 0
        grid_size = max(len(new_bounds) - 1, 1)
        new_bounds = list(zip(new_bounds[:-1], new_bounds[1:]))
        return self.__class__(size=size, grid_size=grid_size,
                              bounds=new_bounds)
Exemplo n.º 10
0
    def slice(self, idx):
        """Make a new Map from a slice."""
        new_bounds = [0]
        start = idx.start if idx.start is not None else 0
        step = idx.step if idx.step is not None else 1
        # iterate over the processes in this dimension
        for proc_start, proc_stop in self.bounds:
            stop = idx.stop if idx.stop is not None else proc_stop
            isection = tuple_intersection((start, stop, step),
                                          (proc_start, proc_stop))
            if isection:
                isection_size = int(
                    np.ceil((isection[1] - (isection[0])) / step))
                new_bounds.append(isection_size + new_bounds[-1])
        if new_bounds == [0]:
            new_bounds = []

        size = new_bounds[-1] if len(new_bounds) > 0 else 0
        grid_size = max(len(new_bounds) - 1, 1)
        new_bounds = list(zip(new_bounds[:-1], new_bounds[1:]))
        return self.__class__(size=size,
                              grid_size=grid_size,
                              bounds=new_bounds)
Exemplo n.º 11
0
 def test_big_step(self):
     t0 = (0, 59, 1000)
     t1 = (15, 90)
     expected = None
     result = metadata_utils.tuple_intersection(t0, t1)
     self.assertEqual(result, expected)
Exemplo n.º 12
0
 def test_with_step_3(self):
     t0 = (0, 59, 2)
     t1 = (15, 90)
     expected = (16, 59, 2)
     result = metadata_utils.tuple_intersection(t0, t1)
     self.assertSequenceEqual(result, expected)
Exemplo n.º 13
0
 def test_with_step_1(self):
     t0 = (0, 60, 1)
     t1 = (15, 30)
     expected = (15, 30, 1)
     result = metadata_utils.tuple_intersection(t0, t1)
     self.assertSequenceEqual(result, expected)
Exemplo n.º 14
0
 def check_intersection_and_reverse(self, t0, t1, expected):
     result = metadata_utils.tuple_intersection(t0, t1)
     self.assertEqual(result, expected)
     result = metadata_utils.tuple_intersection(t1, t0)
     self.assertEqual(result, expected)
Exemplo n.º 15
0
def _global_flat_indices_intersection(gfis0, gfis1):
    intersections = filter(None, [tuple_intersection(a, b)
                                  for (a, b) in product(gfis0, gfis1)])
    return [i[:2] for i in intersections]
Exemplo n.º 16
0
def _global_flat_indices_intersection(gfis0, gfis1):
    intersections = filter(
        None, [tuple_intersection(a, b) for (a, b) in product(gfis0, gfis1)])
    return [i[:2] for i in intersections]