[alexandria.git] updated branch master: 4119ce8 Revert "generic MEAN and MEDIAN, new function DISPLACE-ARRAY"
Nikodemus Siivola
nsiivola at common-lisp.net
Fri Mar 30 15:00:49 UTC 2012
The branch master has been updated:
via 4119ce8ae6baf661d426a09e44d07c262dc55b9a (commit)
from 95f8d2213e3c4be345f0bdf4d06ab82ade67d898 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4119ce8ae6baf661d426a09e44d07c262dc55b9a
Author: Nikodemus Siivola <nikodemus at random-state.net>
Date: Fri Mar 30 17:55:55 2012 +0300
Revert "generic MEAN and MEDIAN, new function DISPLACE-ARRAY"
This reverts commit 485544d4feb13d3f463f54a5605b3a480bc49046.
MEAN and MEDIAN are again non-generic, and DISPLACE-ARRAY is removed.
Motivation on the mailing list.
-----------------------------------------------------------------------
Summary of changes:
arrays.lisp | 11 -----------
numbers.lisp | 53 ++++++++---------------------------------------------
package.lisp | 1 -
tests.lisp | 29 -----------------------------
4 files changed, 8 insertions(+), 86 deletions(-)
diff --git a/arrays.lisp b/arrays.lisp
index 1f30150..76c1879 100644
--- a/arrays.lisp
+++ b/arrays.lisp
@@ -16,14 +16,3 @@ arguments."
(setf (row-major-aref new-array i)
(row-major-aref array i)))
new-array))
-
-(declaim (inline displace-array))
-(defun displace-array (array &key (offset 0)
- (dimensions (- (array-total-size array)
- offset)))
- "Return an array displaced to ARRAY with the given OFFSET and DIMENSIONS.
-Default arguments displace to a vector."
- (make-array dimensions
- :displaced-to array
- :displaced-index-offset offset
- :element-type (array-element-type array)))
diff --git a/numbers.lisp b/numbers.lisp
index 7340f26..03430cc 100644
--- a/numbers.lisp
+++ b/numbers.lisp
@@ -84,58 +84,21 @@ Examples:
interpolation coefficient V."
(+ a (* v (- b a))))
-(defgeneric mean (object)
- (:documentation "Returns the mean of OBJECT.
-Predefined methods work on sequences and arrays of numbers. Users can
-define new methods.")
- (:method ((object list))
- (let ((sum 0)
- (count 0))
- (declare (fixnum count))
- (dolist (elt object)
- (incf sum elt)
- (incf count))
- (/ sum count)))
- (:method ((object vector))
- ;; Need a separate method for vectors, since
- ;; they could have fill-pointers which we need to respect.
- (let ((n (length object)))
- (/ (loop for index below n
- summing (aref object index))
- n)))
- (:method ((object array))
- (let ((n (array-total-size object)))
- (/ (loop for index below n
- summing (row-major-aref object index))
- n)))
- (:method ((object sequence))
- ;; For implementations supporting custom sequence types.
- (/ (reduce #'+ object) (length object))))
-
-(defun median-in-place (vector)
- (declare (vector vector))
- (let* ((vector (sort vector #'<))
+(declaim (inline mean))
+(defun mean (sample)
+ "Returns the mean of SAMPLE. SAMPLE must be a sequence of numbers."
+ (/ (reduce #'+ sample) (length sample)))
+
+(declaim (inline median))
+(defun median (sample)
+ "Returns median of SAMPLE. SAMPLE must be a sequence of real numbers."
+ (let* ((vector (sort (copy-sequence 'vector sample) #'<))
(length (length vector))
(middle (truncate length 2)))
(if (oddp length)
(aref vector middle)
(/ (+ (aref vector middle) (aref vector (1- middle))) 2))))
-(defgeneric median (object)
- (:documentation
- "Returns median of OBJECT.
-Predefined methods work on sequences and arrays of numbers. Users can
-define new methods.")
- (:method ((object list))
- (median-in-place (copy-sequence 'vector object)))
- (:method ((object array))
- (median-in-place (copy-sequence 'vector (if (vectorp object)
- object
- (displace-array object)))))
- (:method ((object sequence))
- ;; For implementations supporting custom sequence types.
- (median-in-place (copy-sequence 'vector object))))
-
(declaim (inline variance))
(defun variance (sample &key (biased t))
"Variance of SAMPLE. Returns the biased variance if BIASED is true (the default),
diff --git a/package.lisp b/package.lisp
index 8bdf060..673ed30 100644
--- a/package.lisp
+++ b/package.lisp
@@ -101,7 +101,6 @@
#:array-index
#:array-length
#:copy-array
- #:displace-array
;; Sequences
#:copy-sequence
#:deletef
diff --git a/tests.lisp b/tests.lisp
index 7d7d1ca..bd2725f 100644
--- a/tests.lisp
+++ b/tests.lisp
@@ -47,24 +47,6 @@
(typep copy 'simple-array)))
t)
-(deftest displace-array.1
- (displace-array #2A((1 2)
- (3 4)))
- #(1 2 3 4))
-
-(deftest displace-array.2
- (displace-array #2A((1 2)
- (3 4))
- :offset 1)
- #(2 3 4))
-
-(deftest displace-array.3
- (displace-array #2A((1 2)
- (3 4))
- :offset 1
- :dimensions '(3 1))
- #2A((2) (3) (4)))
-
(deftest array-index.1
(typep 0 'array-index)
t)
@@ -976,12 +958,6 @@
(mean '(1 2 10))
13/3)
-(deftest mean.4
- (mean #2A((1 2 3)
- (4 5 6)
- (7 8 9)))
- 5)
-
(deftest median.1
(median '(100 0 99 1 98 2 97))
97)
@@ -990,11 +966,6 @@
(median '(100 0 99 1 98 2 97 96))
193/2)
-(deftest median.3
- (median #2A((100 0 99 1)
- (98 2 97 96)))
- 193/2)
-
(deftest variance.1
(variance (list 1 2 3))
2/3)
--
Alexandria hooks/post-receive
More information about the alexandria-cvs
mailing list