code: def search_matrix(matrix, group_width):
      # give up quickly if we'd go on forever
      prediction = predict_unique_combinations(
          matrix.shape[1], group_width
      )
      best_permutation = [c for c in range(matrix.shape[1])]
      if prediction > 1e10:
          print(
              f"There are {prediction} unique combinations with {matrix.shape[1]} columns and a group width of {group_width}, not searching."
          )
          return matrix, prediction, best_permutation
  
      start_time = time.perf_counter()
      full_permutation_list = generate_all_unique_combinations(
          matrix.shape[1], group_width
      )
  
      # found them, now try them
      best_improvement = 0.0
      use_cuda = use_gpu()
      if (
          use_cuda and matrix.shape[1] >= 8 and group_width == 4
      ):  # CUDA path only works for a group width of 4
          (
              best_improvement,
              best_permutation,
          ) = try_permutations_on_matrix(matrix, full_permutation_list)
      else:
          base_sum = sum_after_2_to_4(matrix)
          for i in range(1, len(full_permutation_list)):
              permutation = full_permutation_list[i]
              permuted = matrix[:, permutation]
              cur_improvement = sum_after_2_to_4(permuted) - base_sum
  
              if cur_improvement > best_improvement:
                  best_improvement = cur_improvement
                  best_permutation = permutation
      seconds = time.perf_counter() - start_time
      return (
          matrix[:, best_permutation],
          seconds,
          best_permutation,
          best_improvement,
      )
  
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 5 for calling a global function with example usage: search_matrix(matrix, group_width) and returns: matrix,  seconds,  best_permutation,  best_improvement, matrix,  prediction,  best_permutation