nodes: 0, module; 1, function_definition; 2, function_name:reduce_sorted_to_intersect; 3, parameters; 4, block; 5, identifier:ar1; 6, identifier:ar2; 7, expression_statement; 8, comment:# Ravel both arrays, behavior for the first array could be different; 9, expression_statement; 10, expression_statement; 11, comment:# get min max values of the arrays; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, if_statement; 17, comment:# get min/max indices with values that are also in the other array; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, if_statement; 23, if_statement; 24, if_statement; 25, if_statement; 26, comment:# reduce the data; 27, return_statement; 28, comment:"""
      Takes two sorted arrays and return the intersection ar1 in ar2, ar2 in ar1.
  
      Parameters
      ----------
      ar1 : (M,) array_like
          Input array.
      ar2 : array_like
           Input array.
  
      Returns
      -------
      ar1, ar1 : ndarray, ndarray
          The intersection values.
  
      """; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, assignment; 35, boolean_operator; 36, comment:# special case, no intersection at all; 37, block; 38, assignment; 39, assignment; 40, assignment; 41, assignment; 42, comparison_operator:min_index_ar1 < 0; 43, block; 44, comparison_operator:min_index_ar2 < 0; 45, block; 46, boolean_operator; 47, block; 48, boolean_operator; 49, block; 50, expression_list; 51, identifier:ar1; 52, call; 53, identifier:ar2; 54, call; 55, identifier:ar1_biggest_value; 56, subscript; 57, identifier:ar1_smallest_value; 58, subscript; 59, identifier:ar2_biggest_value; 60, subscript; 61, identifier:ar2_smallest_value; 62, subscript; 63, comparison_operator:ar1_biggest_value < ar2_smallest_value; 64, comparison_operator:ar1_smallest_value > ar2_biggest_value; 65, return_statement; 66, identifier:min_index_ar1; 67, call; 68, identifier:max_index_ar1; 69, call; 70, identifier:min_index_ar2; 71, call; 72, identifier:max_index_ar2; 73, call; 74, identifier:min_index_ar1; 75, integer:0; 76, expression_statement; 77, identifier:min_index_ar2; 78, integer:0; 79, expression_statement; 80, comparison_operator:max_index_ar1 == 0; 81, comparison_operator:max_index_ar1 > ar1.shape[0]; 82, expression_statement; 83, comparison_operator:max_index_ar2 == 0; 84, comparison_operator:max_index_ar2 > ar2.shape[0]; 85, expression_statement; 86, subscript; 87, subscript; 88, attribute; 89, argument_list; 90, attribute; 91, argument_list; 92, identifier:ar1; 93, unary_operator; 94, identifier:ar1; 95, integer:0; 96, identifier:ar2; 97, unary_operator; 98, identifier:ar2; 99, integer:0; 100, identifier:ar1_biggest_value; 101, identifier:ar2_smallest_value; 102, identifier:ar1_smallest_value; 103, identifier:ar2_biggest_value; 104, expression_list; 105, attribute; 106, argument_list; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, attribute; 112, argument_list; 113, assignment; 114, assignment; 115, identifier:max_index_ar1; 116, integer:0; 117, identifier:max_index_ar1; 118, subscript; 119, assignment; 120, identifier:max_index_ar2; 121, integer:0; 122, identifier:max_index_ar2; 123, subscript; 124, assignment; 125, identifier:ar1; 126, slice; 127, identifier:ar2; 128, slice; 129, call; 130, identifier:ravel; 131, call; 132, identifier:ravel; 133, integer:1; 134, integer:1; 135, subscript; 136, subscript; 137, identifier:np; 138, identifier:argmin; 139, comparison_operator:ar1 < ar2_smallest_value; 140, identifier:np; 141, identifier:argmax; 142, comparison_operator:ar1 > ar2_biggest_value; 143, identifier:np; 144, identifier:argmin; 145, comparison_operator:ar2 < ar1_smallest_value; 146, identifier:np; 147, identifier:argmax; 148, comparison_operator:ar2 > ar1_biggest_value; 149, identifier:min_index_ar1; 150, integer:0; 151, identifier:min_index_ar2; 152, integer:0; 153, attribute; 154, integer:0; 155, identifier:max_index_ar1; 156, subscript; 157, attribute; 158, integer:0; 159, identifier:max_index_ar2; 160, subscript; 161, identifier:min_index_ar1; 162, identifier:max_index_ar1; 163, identifier:min_index_ar2; 164, identifier:max_index_ar2; 165, attribute; 166, argument_list; 167, attribute; 168, argument_list; 169, identifier:ar1; 170, slice; 171, identifier:ar2; 172, slice; 173, identifier:ar1; 174, identifier:ar2_smallest_value; 175, identifier:ar1; 176, identifier:ar2_biggest_value; 177, identifier:ar2; 178, identifier:ar1_smallest_value; 179, identifier:ar2; 180, identifier:ar1_biggest_value; 181, identifier:ar1; 182, identifier:shape; 183, attribute; 184, integer:0; 185, identifier:ar2; 186, identifier:shape; 187, attribute; 188, integer:0; 189, identifier:np; 190, identifier:asarray; 191, identifier:ar1; 192, identifier:np; 193, identifier:asarray; 194, identifier:ar2; 195, integer:0; 196, integer:0; 197, integer:0; 198, integer:0; 199, identifier:ar1; 200, identifier:shape; 201, identifier:ar2; 202, identifier:shape
code: def reduce_sorted_to_intersect(ar1, ar2):
      """
      Takes two sorted arrays and return the intersection ar1 in ar2, ar2 in ar1.
  
      Parameters
      ----------
      ar1 : (M,) array_like
          Input array.
      ar2 : array_like
           Input array.
  
      Returns
      -------
      ar1, ar1 : ndarray, ndarray
          The intersection values.
  
      """
      # Ravel both arrays, behavior for the first array could be different
      ar1 = np.asarray(ar1).ravel()
      ar2 = np.asarray(ar2).ravel()
  
      # get min max values of the arrays
      ar1_biggest_value = ar1[-1]
      ar1_smallest_value = ar1[0]
      ar2_biggest_value = ar2[-1]
      ar2_smallest_value = ar2[0]
  
      if ar1_biggest_value < ar2_smallest_value or ar1_smallest_value > ar2_biggest_value:  # special case, no intersection at all
          return ar1[0:0], ar2[0:0]
  
      # get min/max indices with values that are also in the other array
      min_index_ar1 = np.argmin(ar1 < ar2_smallest_value)
      max_index_ar1 = np.argmax(ar1 > ar2_biggest_value)
      min_index_ar2 = np.argmin(ar2 < ar1_smallest_value)
      max_index_ar2 = np.argmax(ar2 > ar1_biggest_value)
  
      if min_index_ar1 < 0:
          min_index_ar1 = 0
      if min_index_ar2 < 0:
          min_index_ar2 = 0
      if max_index_ar1 == 0 or max_index_ar1 > ar1.shape[0]:
          max_index_ar1 = ar1.shape[0]
      if max_index_ar2 == 0 or max_index_ar2 > ar2.shape[0]:
          max_index_ar2 = ar2.shape[0]
  
      # reduce the data
      return ar1[min_index_ar1:max_index_ar1], ar2[min_index_ar2:max_index_ar2]