code: def use_stripe_map(
      matrix, group_width, stripe_map, stripe_ids, perm_map, permutation
  ):
      global sm_perturbations, sm_perturbation_limit
      used_stripes = []
      stripe_groups_optimized = 0
      improvement = 0.0
  
      # set the traversal order
      ix = np.flip(
          np.argsort(stripe_map)
      )  # small to large --> large to small
  
      for i in range(len(ix)):
          stripe_group_id = ix[i]
          perm = perm_map[stripe_group_id].copy()
  
          if (
              stripe_map[stripe_group_id]
              <= np.finfo(np.float16).tiny * 5.0
          ):
              # perturbations
              if (
                  len(used_stripes) == 0
                  and sm_perturbations < sm_perturbation_limit
              ):
                  sm_perturbations += 1
                  # use this permutation, but swap two channels from left/right halves to include two stripes, no matter the group size
                  stripe_group_id = ix[np.random.randint(len(ix))]
                  perm = perm_map[stripe_group_id].copy()
                  # a little easier to escape from
                  src = np.random.randint(int(len(perm) / 2))
                  dst = int(len(perm) / 2) + np.random.randint(
                      int(len(perm) / 2)
                  )
                  perm[src], perm[dst] = perm[dst], perm[src]
              else:
                  break
  
          stripe_group = stripe_ids[stripe_group_id]
  
          # don't work on stripes we've already touched
          touched_stripe = False
          for stripe in stripe_group:
              if stripe in used_stripes:
                  touched_stripe = True
          if touched_stripe:
              continue
  
          # apply the permutation we've already found to this stripe group
          subset = collect_stripes(matrix, stripe_group, group_width)
          sub_result = subset[..., perm]
          permutation = apply_stripe_group_permutation(
              perm, stripe_group, group_width, permutation
          )
  
          # scatter the results, track what changed
          for s, stripe in enumerate(stripe_group):
              # see if this group is in canonical form (entry 0 a multiple of 4, contiguous values))
              group = perm[
                  s * group_width : s * group_width + group_width
              ]  # columns in this group of the used permutation
              changed = False
              if group[0] % 4 != 0:
                  changed = True
              for c in range(1, group_width):
                  if group[c] != group[c - 1] + 1:
                      changed = True
                      break
              # if it's not, then it changed
              if changed:
                  used_stripes.append(stripe_group[s])
  
              matrix[
                  ...,
                  stripe * group_width : stripe * group_width
                  + group_width,
              ] = sub_result[
                  ..., s * group_width : s * group_width + group_width
              ]
  
          improvement += stripe_map[stripe_group_id]
          stripe_groups_optimized += 1
  
      return (
          matrix,
          stripe_groups_optimized,
          stripe_map,
          stripe_ids,
          used_stripes,
          improvement,
          permutation,
      )
  
file_path: apex/apex/contrib/sparsity/permutation_search_kernels/exhaustive_search.py
imports: from .permutation_utilities import *
  import pickle
  import os.path
  from os import path
  import math
label_desc: Use image node_id 10 for calling a global function with example usage: use_stripe_map(matrix, group_width, stripe_map, stripe_ids, perm_map, permutation) and returns: matrix,  stripe_groups_optimized,  stripe_map,  stripe_ids,  used_stripes,  improvement,  permutation