<commit_before>;;; Common Lisp implementation of the Kuhn-Munkres (Hungarian) algorithm.
;;; http://en.wikipedia.org/wiki/Hungarian_algorithm

(defun order-of-matrix (matrix)
  "Given a regular matrix, return its order as a cons (r c)."
  (cons (length matrix) (length (car matrix))))

(defun max-in-matrix (matrix)
  "Find the largest element in the matrix."
  (apply #'max (mapcar #'(lambda (list) (apply #'max list)) matrix)))

(defun pad-matrix (matrix)
  "Pad non-square matrices with zeros to make them square."
  (let* ((order (order-of-matrix matrix))
         (pad-num (- (car order) (cdr order)))
         (max-element (max-in-matrix matrix)))
    (cond ((= pad-num 0) matrix)
          ((> pad-num 0)
           (mapcar #'(lambda (list)
                       (append list (make-list pad-num :initial-element max-element))) matrix))
          ((< pad-num 0)
           (append matrix (make-list (abs pad-num) :initial-element
                                     (make-list (length (car matrix)) :initial-element max-element))))
          (t matrix))))

(defun reduce-rows (matrix)
  "Reduce all elements in each row by the lowest element in the row."
  (mapcar #'(lambda (each-row)
	      (let* ((min-of-row (apply #'min each-row)))
		(mapcar #'(lambda (each-element)
			    (- each-element min-of-row)) each-row))) matrix))

(defun reduce-columns (matrix)
  "Reduce all elements in each column by the lowest element in the column."
  (let* ((transpose (apply #'mapcar #'list matrix)))
    (apply #'mapcar #'list (reduce-rows transpose))))

(defun find-zeros (matrix)
  "Return positions of all zeros in matrix."
  (let* ((zeros '())
         (row-count 0))
    (mapcar #'(lambda (each-row)
                (let* ((column-count 0))
                  (mapcar #'(lambda (each-element)
                              (cond
                                ((eql each-element 0)
                                 (setq zeros (nconc zeros (list (cons row-count column-count))))
                                 (incf column-count))
                                (t (incf column-count))))
                          each-row)
                  (incf row-count)))
            matrix)
    zeros))<commit_msg>Return an array of zero counts for all rows and columns<commit_after>;;; Common Lisp implementation of the Kuhn-Munkres (Hungarian) algorithm.
;;; http://en.wikipedia.org/wiki/Hungarian_algorithm

(defun order-of-matrix (matrix)
  "Given a regular matrix, return its order as a cons (r c)."
  (cons (length matrix) (length (car matrix))))

(defun max-in-matrix (matrix)
  "Find the largest element in the matrix."
  (apply #'max (mapcar #'(lambda (list) (apply #'max list)) matrix)))

(defun pad-matrix (matrix)
  "Pad non-square matrices with zeros to make them square."
  (let* ((order (order-of-matrix matrix))
         (pad-num (- (car order) (cdr order)))
         (max-element (max-in-matrix matrix)))
    (cond ((= pad-num 0) matrix)
          ((> pad-num 0)
           (mapcar #'(lambda (list)
                       (append list (make-list pad-num :initial-element max-element))) matrix))
          ((< pad-num 0)
           (append matrix (make-list (abs pad-num) :initial-element
                                     (make-list (length (car matrix)) :initial-element max-element))))
          (t matrix))))

(defun reduce-rows (matrix)
  "Reduce all elements in each row by the lowest element in the row."
  (mapcar #'(lambda (each-row)
	      (let* ((min-of-row (apply #'min each-row)))
		(mapcar #'(lambda (each-element)
			    (- each-element min-of-row)) each-row))) matrix))

(defun reduce-columns (matrix)
  "Reduce all elements in each column by the lowest element in the column."
  (let* ((transpose (apply #'mapcar #'list matrix)))
    (apply #'mapcar #'list (reduce-rows transpose))))

(defun find-zeros (matrix)
  "Return positions of all zeros in matrix."
  (let* ((zeros '())
         (row-count 0)
         (zero-count (make-array (list 2 (car (order-of-matrix matrix))) :initial-element 0)))
    (mapcar #'(lambda (each-row)
                (let* ((column-count 0))
                  (mapcar #'(lambda (each-element)
                              (cond
                                ((eql each-element 0)
                                 (incf (aref zero-count 0 row-count))
                                 (incf (aref zero-count 1 column-count))
                                 (setq zeros (nconc zeros (list (cons row-count column-count))))
                                 (incf column-count))
                                (t (incf column-count))))
                          each-row)
                  (incf row-count)))
            matrix)
    (list :count zero-count :zeros zeros)))
{'fraction_non_alphanumeric': 0.13971676178397802, 'fraction_numerical': 0.0033819488480236735, 'mean_word_length': 1.9930423782416193, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1594330', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1368, 'n_words': 450}