nodes: 0, module; 1, function_definition; 2, function_name:lovasz_grad; 3, parameters; 4, block; 5, identifier:gt_sorted; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, comment:"""
      Computes gradient of the Lovasz extension w.r.t sorted errors
      See Alg. 1 in paper
      """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, comparison_operator:p > 1; 21, comment:# cover 1-pixel case; 22, block; 23, identifier:jaccard; 24, identifier:p; 25, call; 26, identifier:gts; 27, call; 28, identifier:intersection; 29, binary_operator:gts - gt_sorted.float().cumsum(0); 30, identifier:union; 31, binary_operator:gts + (1 - gt_sorted).float().cumsum(0); 32, identifier:jaccard; 33, binary_operator:1. - intersection / union; 34, identifier:p; 35, integer:1; 36, expression_statement; 37, identifier:len; 38, argument_list; 39, attribute; 40, argument_list; 41, identifier:gts; 42, call; 43, identifier:gts; 44, call; 45, float:1.; 46, binary_operator:intersection / union; 47, assignment; 48, identifier:gt_sorted; 49, identifier:gt_sorted; 50, identifier:sum; 51, attribute; 52, argument_list; 53, attribute; 54, argument_list; 55, identifier:intersection; 56, identifier:union; 57, subscript; 58, binary_operator:jaccard[1:p] - jaccard[0:-1]; 59, call; 60, identifier:cumsum; 61, integer:0; 62, call; 63, identifier:cumsum; 64, integer:0; 65, identifier:jaccard; 66, slice; 67, subscript; 68, subscript; 69, attribute; 70, argument_list; 71, attribute; 72, argument_list; 73, integer:1; 74, identifier:p; 75, identifier:jaccard; 76, slice; 77, identifier:jaccard; 78, slice; 79, identifier:gt_sorted; 80, identifier:float; 81, parenthesized_expression; 82, identifier:float; 83, integer:1; 84, identifier:p; 85, integer:0; 86, unary_operator; 87, binary_operator:1 - gt_sorted; 88, integer:1; 89, integer:1; 90, identifier:gt_sorted
code: def lovasz_grad(gt_sorted):
      """
      Computes gradient of the Lovasz extension w.r.t sorted errors
      See Alg. 1 in paper
      """
      p = len(gt_sorted)
      gts = gt_sorted.sum()
      intersection = gts - gt_sorted.float().cumsum(0)
      union = gts + (1 - gt_sorted).float().cumsum(0)
      jaccard = 1. - intersection / union
      if p > 1: # cover 1-pixel case
          jaccard[1:p] = jaccard[1:p] - jaccard[0:-1]
      return jaccard