text: # BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
  
  from __future__ import absolute_import
  
  import awkward as ak
  from awkward._v2.index import Index
  from awkward._v2.contents.content import Content, NestedIndexError
  from awkward._v2.forms.indexedform import IndexedForm
  
  np = ak.nplike.NumpyMetadata.instance()
  
  
  class IndexedArray(Content):
      def __init__(self, index, content, identifier=None, parameters=None):
          if not (
              isinstance(index, Index)
              and index.dtype
              in (
                  np.dtype(np.int32),
                  np.dtype(np.uint32),
                  np.dtype(np.int64),
              )
          ):
              raise TypeError(
                  "{0} 'index' must be an Index with dtype in (int32, uint32, int64), "
                  "not {1}".format(type(self).__name__, repr(index))
              )
          if not isinstance(content, Content):
              raise TypeError(
                  "{0} 'content' must be a Content subtype, not {1}".format(
                      type(self).__name__, repr(content)
                  )
              )
  
          self._index = index
          self._content = content
          self._init(identifier, parameters)
  
      @property
      def index(self):
          return self._index
  
      @property
      def content(self):
          return self._content
  
      @property
      def nplike(self):
          return self._index.nplike
  
      Form = IndexedForm
  
      @property
      def form(self):
          return self.Form(
              self._index.form,
              self._content.form,
              has_identifier=self._identifier is not None,
              parameters=self._parameters,
              form_key=None,
          )
  
      def __len__(self):
          return len(self._index)
  
      def __repr__(self):
          return self._repr("", "", "")
  
      def _repr(self, indent, pre, post):
          out = [indent, pre, "<IndexedArray len="]
          out.append(repr(str(len(self))))
          out.append(">\n")
          out.append(self._index._repr(indent + "    ", "<index>", "</index>\n"))
          out.append(self._content._repr(indent + "    ", "<content>", "</content>\n"))
          out.append(indent)
          out.append("</IndexedArray>")
          out.append(post)
          return "".join(out)
  
      def _getitem_nothing(self):
          return self._content._getitem_range(slice(0, 0))
  
      def _getitem_at(self, where):
          if where < 0:
              where += len(self)
          if not (0 <= where < len(self)):
              raise NestedIndexError(self, where)
          return self._content._getitem_at(self._index[where])
  
      def _getitem_range(self, where):
          start, stop, step = where.indices(len(self))
          assert step == 1
          return IndexedArray(
              self._index[start:stop],
              self._content,
              self._range_identifier(start, stop),
              self._parameters,
          )
  
      def _getitem_field(self, where, only_fields=()):
          return IndexedArray(
              self._index,
              self._content._getitem_field(where, only_fields),
              self._field_identifier(where),
              None,
          )
  
      def _getitem_fields(self, where, only_fields=()):
          return IndexedArray(
              self._index,
              self._content._getitem_fields(where, only_fields),
              self._fields_identifier(where),
              None,
          )
  
      def _carry(self, carry, allow_lazy, exception):
          assert isinstance(carry, ak._v2.index.Index)
  
          try:
              nextindex = self._index[carry.data]
          except IndexError as err:
              if issubclass(exception, NestedIndexError):
                  raise exception(self, carry.data, str(err))
              else:
                  raise exception(str(err))
  
          return IndexedArray(
              nextindex,
              self._content,
              self._carry_identifier(carry, exception),
              self._parameters,
          )
  
      def _getitem_next(self, head, tail, advanced):
          nplike = self.nplike  # noqa: F841
  
          if head == ():
              return self
  
          elif isinstance(head, (int, slice, ak._v2.index.Index64)):
              nexthead, nexttail = self._headtail(tail)
  
              nextcarry = ak._v2.index.Index64.empty(len(self._index), nplike)
              self._handle_error(
                  nplike[
                      "awkward_IndexedArray_getitem_nextcarry",
                      nextcarry.dtype.type,
                      self._index.dtype.type,
                  ](
                      nextcarry.to(nplike),
                      self._index.to(nplike),
                      len(self._index),
                      len(self._content),
                  )
              )
  
              next = self._content._carry(nextcarry, False, NestedIndexError)
              return next._getitem_next(head, tail, advanced)
  
          elif ak._util.isstr(head):
              return self._getitem_next_field(head, tail, advanced)
  
          elif isinstance(head, list):
              return self._getitem_next_fields(head, tail, advanced)
  
          elif head is np.newaxis:
              return self._getitem_next_newaxis(tail, advanced)
  
          elif head is Ellipsis:
              return self._getitem_next_ellipsis(tail, advanced)
  
          elif isinstance(head, ak._v2.contents.ListOffsetArray):
              raise NotImplementedError
  
          elif isinstance(head, ak._v2.contents.IndexedOptionArray):
              raise NotImplementedError
  
          else:
              raise AssertionError(repr(head))
  
      def project(self):
          nextcarry = ak._v2.index.Index64.empty(len(self), self.nplike)
          self._handle_error(
              self.nplike[
                  "awkward_IndexedArray_getitem_nextcarry",
                  nextcarry.dtype.type,
                  self._index.dtype.type,
              ](
                  nextcarry.to(self.nplike),
                  self._index.to(self.nplike),
                  len(self._index),
                  len(self._content),
              )
          )
          return self._content._carry(nextcarry, False, NestedIndexError)
  
      def _localindex(self, axis, depth):
          posaxis = self._axis_wrap_if_negative(axis)
          if posaxis == depth:
              return self._localindex_axis0()
          else:
              return self.project()._localindex(posaxis, depth)
  