nodes: 0, module; 1, function_definition; 2, function_name:check; 3, parameters; 4, block; 5, identifier:labels; 6, expression_statement; 7, comment:# type checking; 8, if_statement; 9, if_statement; 10, if_statement; 11, comment:# dimension checking; 12, expression_statement; 13, if_statement; 14, if_statement; 15, if_statement; 16, comment:# sort checking; 17, for_statement; 18, comment:"""Raise IOError if labels are not correct
  
          `labels` must be a list of sorted numpy arrays of equal
               dimensions (must be 1D or 2D). In the case of 2D labels,
               the second axis must have the same shape for all labels.
  
          """; 19, not_operator; 20, block; 21, not_operator; 22, block; 23, not_operator; 24, block; 25, assignment; 26, comparison_operator:ndim not in [1, 2]; 27, block; 28, not_operator; 29, block; 30, comparison_operator:ndim == 2; 31, block; 32, identifier:label; 33, identifier:labels; 34, block; 35, call; 36, raise_statement; 37, call; 38, raise_statement; 39, call; 40, raise_statement; 41, identifier:ndim; 42, attribute; 43, identifier:ndim; 44, list; 45, raise_statement; 46, call; 47, raise_statement; 48, identifier:ndim; 49, integer:2; 50, expression_statement; 51, if_statement; 52, expression_statement; 53, comment:# print label, index; 54, comment:# print len(index), label.shape[0]; 55, assert_statement; 56, if_statement; 57, identifier:isinstance; 58, argument_list; 59, call; 60, identifier:len; 61, argument_list; 62, call; 63, identifier:all; 64, argument_list; 65, call; 66, subscript; 67, identifier:ndim; 68, integer:1; 69, integer:2; 70, call; 71, identifier:all; 72, argument_list; 73, call; 74, assignment; 75, not_operator; 76, block; 77, assignment; 78, comparison_operator:len(index) == label.shape[0]; 79, not_operator; 80, block; 81, identifier:labels; 82, identifier:list; 83, identifier:IOError; 84, argument_list; 85, identifier:labels; 86, identifier:IOError; 87, argument_list; 88, list_comprehension; 89, identifier:IOError; 90, argument_list; 91, identifier:labels; 92, integer:0; 93, identifier:IOError; 94, argument_list; 95, list_comprehension; 96, identifier:IOError; 97, argument_list; 98, identifier:shape1; 99, subscript; 100, call; 101, raise_statement; 102, identifier:index; 103, parenthesized_expression; 104, call; 105, subscript; 106, call; 107, raise_statement; 108, string; 109, string; 110, call; 111, for_in_clause; 112, string; 113, string; 114, comparison_operator:l.ndim == ndim; 115, for_in_clause; 116, string; 117, attribute; 118, integer:1; 119, identifier:all; 120, argument_list; 121, call; 122, conditional_expression:np.argsort(label) if label.ndim == 1
                       else np.lexsort(label.T); 123, identifier:len; 124, argument_list; 125, attribute; 126, integer:0; 127, identifier:all; 128, generator_expression; 129, call; 130, string_content:labels are not in a list; 131, string_content:the labels list is empty; 132, identifier:isinstance; 133, argument_list; 134, identifier:l; 135, identifier:labels; 136, string_content:all labels must be numpy arrays; 137, string_content:labels dimension must be 1 or 2; 138, attribute; 139, identifier:ndim; 140, identifier:l; 141, identifier:labels; 142, string_content:all labels dimensions must be equal; 143, subscript; 144, identifier:shape; 145, list_comprehension; 146, identifier:IOError; 147, argument_list; 148, call; 149, comparison_operator:label.ndim == 1; 150, call; 151, identifier:index; 152, identifier:label; 153, identifier:shape; 154, comparison_operator:n == index[n]; 155, for_in_clause; 156, identifier:IOError; 157, argument_list; 158, identifier:l; 159, attribute; 160, identifier:l; 161, identifier:ndim; 162, identifier:labels; 163, integer:0; 164, comparison_operator:l.shape[1] == shape1; 165, for_in_clause; 166, string; 167, attribute; 168, argument_list; 169, attribute; 170, integer:1; 171, attribute; 172, argument_list; 173, identifier:n; 174, subscript; 175, identifier:n; 176, call; 177, string; 178, identifier:np; 179, identifier:ndarray; 180, subscript; 181, identifier:shape1; 182, identifier:l; 183, identifier:labels; 184, string_content:all labels must have same shape on 2nd dim; 185, identifier:np; 186, identifier:argsort; 187, identifier:label; 188, identifier:label; 189, identifier:ndim; 190, identifier:np; 191, identifier:lexsort; 192, attribute; 193, identifier:index; 194, identifier:n; 195, identifier:range; 196, argument_list; 197, string_content:labels are not sorted in increasing order; 198, attribute; 199, integer:1; 200, identifier:label; 201, identifier:T; 202, binary_operator:label.shape[0]-1; 203, identifier:l; 204, identifier:shape; 205, subscript; 206, integer:1; 207, attribute; 208, integer:0; 209, identifier:label; 210, identifier:shape
code: def check(labels):
          """Raise IOError if labels are not correct
  
          `labels` must be a list of sorted numpy arrays of equal
               dimensions (must be 1D or 2D). In the case of 2D labels,
               the second axis must have the same shape for all labels.
  
          """
          # type checking
          if not isinstance(labels, list):
              raise IOError('labels are not in a list')
          if not len(labels):
              raise IOError('the labels list is empty')
          if not all([isinstance(l, np.ndarray) for l in labels]):
              raise IOError('all labels must be numpy arrays')
  
          # dimension checking
          ndim = labels[0].ndim
          if ndim not in [1, 2]:
              raise IOError('labels dimension must be 1 or 2')
          if not all([l.ndim == ndim for l in labels]):
              raise IOError('all labels dimensions must be equal')
          if ndim == 2:
              shape1 = labels[0].shape[1]
              if not all([l.shape[1] == shape1 for l in labels]):
                  raise IOError('all labels must have same shape on 2nd dim')
  
          # sort checking
          for label in labels:
              index = (np.argsort(label) if label.ndim == 1
                       else np.lexsort(label.T))
              # print label, index
              # print len(index), label.shape[0]
              assert len(index) == label.shape[0]
              if not all(n == index[n] for n in range(label.shape[0]-1)):
                  raise IOError('labels are not sorted in increasing order')