Function: calcFunc-histogram

calcFunc-histogram is an autoloaded and byte-compiled function defined in calc-vec.el.gz.

Signature

(calcFunc-histogram VEC WTS &optional N)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-vec.el.gz
;;; Compile a histogram of data from a vector.
(defun calcFunc-histogram (vec wts &optional n)
  (or n (setq n wts wts 1))
  (or (Math-vectorp vec)
      (math-reject-arg vec 'vectorp))
  (if (Math-vectorp wts)
      (or (= (length vec) (length wts))
	  (math-dimension-error)))
  (cond ((natnump n)
         (let ((res (make-vector n 0))
               (vp vec)
               (wvec (Math-vectorp wts))
               (wp wts)
               bin)
           (while (setq vp (cdr vp))
             (setq bin (car vp))
             (or (natnump bin)
                 (setq bin (math-floor bin)))
            (and (natnump bin)
                 (< bin n)
                 (aset res bin
                       (math-add (aref res bin)
                                 (if wvec (car (setq wp (cdr wp))) wts)))))
           (cons 'vec (append res nil))))
        ((Math-vectorp n) ;; n is a vector of midpoints
         (let* ((bds (math-vector-avg n))
                (res (make-vector (1- (length n)) 0))
                (vp (cdr vec))
                (wvec (Math-vectorp wts))
                (wp wts)
                num)
           (while vp
             (setq num (car vp))
             (let ((tbds (cdr bds))
                   (i 0))
               (while (and tbds (Math-lessp (car tbds) num))
                 (setq i (1+ i))
                 (setq tbds (cdr tbds)))
               (aset res i
                     (math-add (aref res i)
                               (if wvec (car (setq wp (cdr wp))) wts))))
             (setq vp (cdr vp)))
           (cons 'vec (append res nil))))
        (t
         (math-reject-arg n "*Expecting an integer or vector"))))