def __getitem__(self, index):
<EOL>distaxis = self._distaxis<EOL>if isinstance(index, np.ndarray) and index.dtype.type is np.bool_:<EOL><INDENT>raise Error('<STR_LIT>')<EOL><DEDENT>if not isinstance(index, Sequence):<EOL><INDENT>index = (index,) + (slice(None),)*(self.ndim - <NUM_LIT:1>)<EOL><DEDENT>ix_types = tuple(type(x) for x in index)<EOL>if (np.ndarray in ix_types or<EOL>(not isinstance(index, _TupleType) and <EOL>_NewaxisType not in ix_types and <EOL>_EllipsisType not in ix_types and<EOL>_SliceType not in ix_types) or<EOL>any(issubclass(T, Sequence) for T in ix_types)):<EOL><INDENT>basic_slicing = False<EOL><DEDENT>else:<EOL><INDENT>basic_slicing = True<EOL><DEDENT>while _EllipsisType in ix_types:<EOL><INDENT>pos = ix_types.index(_EllipsisType)<EOL>m = (self.ndim + ix_types.count(_NewaxisType) - len(index) + <NUM_LIT:1>)<EOL>index = index[:pos] + (slice(None),)*m + index[(pos+<NUM_LIT:1>):]<EOL>ix_types = tuple(type(x) for x in index)<EOL><DEDENT>if _NewaxisType in ix_types:<EOL><INDENT>new_distaxis = distaxis<EOL>subix = [slice(None)] * self.ndim<EOL>while _NewaxisType in ix_types:<EOL><INDENT>pos = ix_types.index(type(np.newaxis))<EOL>index = index[:pos] + (slice(None),) + index[(pos+<NUM_LIT:1>):]<EOL>ix_types = tuple(type(x) for x in index)<EOL>if pos <= distaxis:<EOL><INDENT>subix[pos] = np.newaxis<EOL>new_distaxis += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>subix[pos - <NUM_LIT:1>] = np.newaxis<EOL><DEDENT><DEDENT>new_subarrays = [ra[tuple(subix)] for ra in self._subarrays]<EOL>return DistArray(new_subarrays, new_distaxis)[index]<EOL><DEDENT>index = tuple(index) + (slice(None),)*(self.ndim - len(index))<EOL>if len(index) > self.ndim:<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT>if basic_slicing:<EOL><INDENT>distix = index[distaxis]<EOL>if isinstance(distix, numbers.Number):<EOL><INDENT>s, i = self._tosub(distix)<EOL>subix = index[<NUM_LIT:0>:distaxis] + (i,) + index[(distaxis+<NUM_LIT:1>):]<EOL>return self._subarrays[s][subix]<EOL><DEDENT>else:<EOL><INDENT>result_ras = []<EOL>ss, ms = self._tosubslices(distix)<EOL>for s, m in zip(ss, ms):<EOL><INDENT>subix = index[<NUM_LIT:0>:distaxis] + (m,) + index[(distaxis+<NUM_LIT:1>):]<EOL>result_ras.append(self._subarrays[s][subix])<EOL><DEDENT>axes_removed = sum(<NUM_LIT:1> for x in index[:distaxis] if isinstance(<EOL>x, numbers.Integral))<EOL>new_distaxis = distaxis - axes_removed<EOL><DEDENT><DEDENT>else:<EOL><INDENT>is_fancy = tuple(not isinstance(x, _SliceType) for x in index)<EOL>fancy_pos = tuple(i for i in range(len(index)) if is_fancy[i])<EOL>slice_pos = tuple(i for i in range(len(index)) if not is_fancy[i])<EOL>contiguous = (fancy_pos[-<NUM_LIT:1>] - fancy_pos[<NUM_LIT:0>] == len(fancy_pos) - <NUM_LIT:1>)<EOL>index = list(index)<EOL>ix_arrays = [index[j] for j in fancy_pos]<EOL>ix_arrays = np.broadcast_arrays(*ix_arrays)<EOL>for j in range(len(fancy_pos)):<EOL><INDENT>if ix_arrays[j].shape is ():<EOL><INDENT>ix_arrays[j] = np.expand_dims(ix_arrays[j], <NUM_LIT:0>)<EOL><DEDENT>index[fancy_pos[j]] = ix_arrays[j]<EOL><DEDENT>index = tuple(index)<EOL>idim = index[fancy_pos[<NUM_LIT:0>]].ndim <EOL>assert(idim > <NUM_LIT:0>)<EOL>distix = index[distaxis]<EOL>otherix = index[<NUM_LIT:0>:distaxis] + (slice(None),) + index[(distaxis+<NUM_LIT:1>):]<EOL>if not is_fancy[distaxis]:<EOL><INDENT>result_ras = []<EOL>ss, ms = self._tosubslices(distix)<EOL>for s, m in zip(ss, ms):<EOL><INDENT>subix = index[<NUM_LIT:0>:distaxis] + (m,) + index[(distaxis+<NUM_LIT:1>):]<EOL>result_ras.append(self._subarrays[s][subix])<EOL><DEDENT>if contiguous:<EOL><INDENT>if fancy_pos[<NUM_LIT:0>] > distaxis:<EOL><INDENT>new_distaxis = distaxis<EOL><DEDENT>else:<EOL><INDENT>new_distaxis = distaxis - len(fancy_pos) + idim<EOL><DEDENT><DEDENT>else:<EOL><INDENT>earlier_fancy = len([i for i in fancy_pos if i < distaxis])<EOL>new_distaxis = distaxis - earlier_fancy + idim<EOL><DEDENT><DEDENT>else:<EOL><INDENT>nonconstant_ix_axes = []<EOL>for j in range(idim):<EOL><INDENT>n = distix.shape[j]<EOL>if n > <NUM_LIT:1>:<EOL><INDENT>partix = np.split(distix, n, axis=j)<EOL>if not all(np.array_equal(<EOL>partix[<NUM_LIT:0>], partix[i]) for i in range(<NUM_LIT:1>, n)):<EOL><INDENT>nonconstant_ix_axes.append(j)<EOL><DEDENT><DEDENT><DEDENT>if len(nonconstant_ix_axes) <= <NUM_LIT:1>:<EOL><INDENT>if len(nonconstant_ix_axes) is <NUM_LIT:0>:<EOL><INDENT>all_same_engine = True<EOL>iax = idim - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>all_same_engine = False<EOL>iax = nonconstant_ix_axes[<NUM_LIT:0>]<EOL><DEDENT>iix = [<NUM_LIT:0>] * idim<EOL>iix[iax] = slice(None)<EOL>iix = tuple(iix)<EOL>ixlist = self._placeholders[distix[iix]]<EOL>if contiguous:<EOL><INDENT>new_distaxis = fancy_pos[<NUM_LIT:0>] + iax<EOL><DEDENT>else:<EOL><INDENT>new_distaxis = <NUM_LIT:0> + iax<EOL><DEDENT>result_ras = []<EOL>ss, ms, js = self._tosubsj(ixlist)<EOL>shp = [<NUM_LIT:1>] * idim<EOL>for s, m, jlist in zip(ss, ms, js):<EOL><INDENT>shp[iax] = len(m)<EOL>m = np.array(m).reshape(shp) <EOL>sl = [slice(None)] * idim<EOL>sl[iax] = jlist<EOL>sl = tuple(sl)<EOL>subix = list(index)<EOL>for i in range(len(subix)):<EOL><INDENT>if isinstance(subix[i], np.ndarray):<EOL><INDENT>if i == distaxis:<EOL><INDENT>subix[i] = m<EOL><DEDENT>else:<EOL><INDENT>subix[i] = subix[i][sl]<EOL><DEDENT><DEDENT><DEDENT>subix = tuple(subix)<EOL>result_ras.append(self._subarrays[s][subix])<EOL><DEDENT>if all_same_engine:<EOL><INDENT>result_ras = [expand_dims(r, new_distaxis) for<EOL>r in result_ras]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>msg = (u'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>warnings.warn(msg, RuntimeWarning)<EOL>return self._ob[index]<EOL><DEDENT><DEDENT><DEDENT>if len(result_ras) == <NUM_LIT:0>:<EOL><INDENT>subix = index[<NUM_LIT:0>:distaxis] + (slice(<NUM_LIT:0>),) + index[(distaxis+<NUM_LIT:1>):]<EOL>return self._subarrays[<NUM_LIT:0>][subix]<EOL><DEDENT>if all(not isinstance(ra, RemoteArray) or ra._id.engine == -<NUM_LIT:1> for<EOL>ra in result_ras):<EOL><INDENT>return gather(concatenate(result_ras, axis=new_distaxis))<EOL><DEDENT>engines = [ra._id.engine if isinstance(ra, RemoteArray) else -<NUM_LIT:1> for<EOL>ra in result_ras]<EOL>if all(e == engines[<NUM_LIT:0>] for e in engines):<EOL><INDENT>return concatenate(result_ras, axis=new_distaxis)<EOL><DEDENT>else:<EOL><INDENT>return DistArray(result_ras, new_distaxis)<EOL><DEDENT>
Slice the distributed array