original_docstring: Takes a partially built 'worm' of length isplice and extends them by one based on ivertex_range
  
      Args:
          result (ResultJIT): accumulated pos, idx, and err
          verts (tuple(_Vertex)*N): Vertices in the linear 'ssdag', store entry/exit geometry
          edges (tuple(_Edge)*(N-1)): Edges in the linear 'ssdag', store allowed splices
          loss_function (jit function): Arbitrary loss function, must be numba-jitable
          loss_threshold (float): only worms with loss <= loss_threshold are put into result
          nresults (int): total number of accumulated results so far
          isplice (int): index of current out-vertex / edge / splice
          ivertex_range (tuple(int, int)): range of ivertex with allowed entry ienter
          splice_position (float32[:4,:4]): rigid body position of splice
  
      Returns:
          (int, ResultJIT): accumulated pos, idx, and err
      
docstring: Takes a partially built 'worm' of length isplice and extends them by one based on ivertex_range
docstring_tokens: Takes a partially built ' worm ' of length isplice and extends them by one based on ivertex_range
code: def _grow_linear_mc_recurse(
        result,
        bb_base,
        verts,
        edges,
        loss_function,
        loss_threshold,
        last_bb_same_as,
        nresults,
        max_linear,
        isplice,
        ivertex_range,
        splice_position,
        bases,
  ):
     """Takes a partially built 'worm' of length isplice and extends them by one based on ivertex_range
  
      Args:
          result (ResultJIT): accumulated pos, idx, and err
          verts (tuple(_Vertex)*N): Vertices in the linear 'ssdag', store entry/exit geometry
          edges (tuple(_Edge)*(N-1)): Edges in the linear 'ssdag', store allowed splices
          loss_function (jit function): Arbitrary loss function, must be numba-jitable
          loss_threshold (float): only worms with loss <= loss_threshold are put into result
          nresults (int): total number of accumulated results so far
          isplice (int): index of current out-vertex / edge / splice
          ivertex_range (tuple(int, int)): range of ivertex with allowed entry ienter
          splice_position (float32[:4,:4]): rigid body position of splice
  
      Returns:
          (int, ResultJIT): accumulated pos, idx, and err
      """
  
     current_vertex = verts[isplice]
     ivertex = np.random.randint(*ivertex_range)
     if not (last_bb_same_as >= 0 and isplice == len(edges)):
        basehash = bb_base[isplice][current_vertex.ibblock[ivertex]]
        if basehash != 0 and np.any(basehash == bases[:isplice]):
           return nresults, result
        bases[isplice] = basehash
     result.idx[nresults, isplice] = ivertex
     vertex_position = splice_position @ current_vertex.x2orig[ivertex]
     result.pos[nresults, isplice] = vertex_position
     if isplice == len(edges):
        result.stats.total_samples[0] += 1
        if _site_overlap(result, verts, ivertex, nresults, last_bb_same_as):
           return nresults, result
        result.stats.n_last_bb_same_as[0] += 1
        loss = loss_function(result.pos[nresults], result.idx[nresults], verts)
        result.err[nresults] = loss
        if loss <= loss_threshold:
           if nresults >= max_linear:
              return nresults, result
           nresults += 1
           result = expand_results(result, nresults)
     else:
        next_vertex = verts[isplice + 1]
        next_splicepos = splice_position @ current_vertex.x2exit[ivertex]
        iexit = current_vertex.exit_index[ivertex]
        allowed_entries = edges[isplice].allowed_entries(iexit)
        if len(allowed_entries) == 0:
           return nresults, result
        iskip = max(1, len(allowed_entries) / 100)
        istart = np.random.randint(0, iskip)
        for ienter in allowed_entries[istart:None:iskip]:
           # for ienter in allowed_entries:
           next_ivertex_range = next_vertex.entry_range(ienter)
           if isplice + 1 == len(edges):
              if _last_bb_mismatch(result, verts, next_ivertex_range[0], nresults, last_bb_same_as):
                 continue
           assert next_ivertex_range[0] >= 0, "ivrt rng err"
           assert next_ivertex_range[1] >= 0, "ivrt rng err"
           assert next_ivertex_range[0] <= next_vertex.len, "ivrt rng err"
           assert next_ivertex_range[1] <= next_vertex.len, "ivrt rng err"
           nresults, result = _grow_linear_mc_recurse(
              result=result,
              bb_base=bb_base,
              verts=verts,
              edges=edges,
              loss_function=loss_function,
              loss_threshold=loss_threshold,
              last_bb_same_as=last_bb_same_as,
              nresults=nresults,
              max_linear=max_linear,
              isplice=isplice + 1,
              ivertex_range=next_ivertex_range,
              splice_position=next_splicepos,
              bases=bases,
           )
     return nresults, result
code_tokens: def _grow_linear_mc_recurse ( result , bb_base , verts , edges , loss_function , loss_threshold , last_bb_same_as , nresults , max_linear , isplice , ivertex_range , splice_position , bases , ) : current_vertex = verts [ isplice ] ivertex = np . random . randint ( * ivertex_range ) if not ( last_bb_same_as >= 0 and isplice == len ( edges ) ) : basehash = bb_base [ isplice ] [ current_vertex . ibblock [ ivertex ] ] if basehash != 0 and np . any ( basehash == bases [ : isplice ] ) : return nresults , result bases [ isplice ] = basehash result . idx [ nresults , isplice ] = ivertex vertex_position = splice_position @ current_vertex . x2orig [ ivertex ] result . pos [ nresults , isplice ] = vertex_position if isplice == len ( edges ) : result . stats . total_samples [ 0 ] += 1 if _site_overlap ( result , verts , ivertex , nresults , last_bb_same_as ) : return nresults , result result . stats . n_last_bb_same_as [ 0 ] += 1 loss = loss_function ( result . pos [ nresults ] , result . idx [ nresults ] , verts ) result . err [ nresults ] = loss if loss <= loss_threshold : if nresults >= max_linear : return nresults , result nresults += 1 result = expand_results ( result , nresults ) else : next_vertex = verts [ isplice + 1 ] next_splicepos = splice_position @ current_vertex . x2exit [ ivertex ] iexit = current_vertex . exit_index [ ivertex ] allowed_entries = edges [ isplice ] . allowed_entries ( iexit ) if len ( allowed_entries ) == 0 : return nresults , result iskip = max ( 1 , len ( allowed_entries ) / 100 ) istart = np . random . randint ( 0 , iskip ) for ienter in allowed_entries [ istart : None : iskip ] : next_ivertex_range = next_vertex . entry_range ( ienter ) if isplice + 1 == len ( edges ) : if _last_bb_mismatch ( result , verts , next_ivertex_range [ 0 ] , nresults , last_bb_same_as ) : continue assert next_ivertex_range [ 0 ] >= 0 , "ivrt rng err" assert next_ivertex_range [ 1 ] >= 0 , "ivrt rng err" assert next_ivertex_range [ 0 ] <= next_vertex . len , "ivrt rng err" assert next_ivertex_range [ 1 ] <= next_vertex . len , "ivrt rng err" nresults , result = _grow_linear_mc_recurse ( result = result , bb_base = bb_base , verts = verts , edges = edges , loss_function = loss_function , loss_threshold = loss_threshold , last_bb_same_as = last_bb_same_as , nresults = nresults , max_linear = max_linear , isplice = isplice + 1 , ivertex_range = next_ivertex_range , splice_position = next_splicepos , bases = bases , ) return nresults , result
short_docstring: Takes a partially built 'worm' of length isplice and extends them by one based on ivertex_range
short_docstring_tokens: Takes a partially built ' worm ' of length isplice and extends them by one based on ivertex_range
comment: """Takes a partially built 'worm' of length isplice and extends them by one based on ivertex_range
  
      Args:
          result (ResultJIT): accumulated pos, idx, and err
          verts (tuple(_Vertex)*N): Vertices in the linear 'ssdag', store entry/exit geometry
          edges (tuple(_Edge)*(N-1)): Edges in the linear 'ssdag', store allowed splices
          loss_function (jit function): Arbitrary loss function, must be numba-jitable
          loss_threshold (float): only worms with loss <= loss_threshold are put into result
          nresults (int): total number of accumulated results so far
          isplice (int): index of current out-vertex / edge / splice
          ivertex_range (tuple(int, int)): range of ivertex with allowed entry ienter
          splice_position (float32[:4,:4]): rigid body position of splice
  
      Returns:
          (int, ResultJIT): accumulated pos, idx, and err
      """$SEP$# for ienter in allowed_entries: