From 7151b5bb38d01746f729ee7e37cab4f4fdf7c7e8 Mon Sep 17 00:00:00 2001
From: "Liam M. Healy" <lnp@healy.washington.dc.us>
Date: Tue, 3 Jan 2012 18:05:55 -0500
Subject: [PATCH] Optional index arrays for sort-smallest-index,
 sort-largest-index

Arguments simplified in sort-smallest-index, sort-largest-index;
output array is optional and may be specified by size.  Docstrings
made accurate.  Previous versions selected only the first n part of
the unsorted array.  Other functions in this file could benefit from
similar changes, but the changes have not been made because of the
existence of tests.
---
 sorting.lisp                             | 31 +++++++++++-------------
 special-functions/return-structures.lisp | 17 ++++++++-----
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/sorting.lisp b/sorting.lisp
index 6edcfc9b..8cdc9508 100644
--- a/sorting.lisp
+++ b/sorting.lisp
@@ -1,8 +1,8 @@
 ;; Sorting
 ;; Liam Healy, Fri Apr 14 2006 - 20:20
-;; Time-stamp: <2011-01-10 18:16:18EST sorting.lisp>
+;; Time-stamp: <2012-01-03 13:16:28EST sorting.lisp>
 ;;
-;; Copyright 2006, 2007, 2008, 2009, 2011 Liam M. Healy
+;; Copyright 2006, 2007, 2008, 2009, 2011, 2012 Liam M. Healy
 ;; Distributed under the terms of the GNU General Public License
 ;;
 ;; This program is free software: you can redistribute it and/or modify
@@ -21,6 +21,7 @@
 (in-package :gsl)
 
 ;;; #'heapsort has just a cursory port, use CL's #'sort.
+;;; [2012-01-03 Tue 13:15] To do: rewrite other index functions to take an optional array or size (sort-smallest-index, sort-largest-index already done).
 
 ;;;;****************************************************************************
 ;;;; Heapsort, not recommended
@@ -182,23 +183,21 @@
     allocated and returned.  If it is a CL vector,
     it will be filled with the indices.")
 
-(defmfun sort-smallest-index (combination (v vector))
+(defmfun sort-smallest-index
+    ((v vector) &optional (size-or-array 3)
+		&aux (combination (vdf size-or-array 'sizet)))
   ("gsl_sort" :type "_smallest_index")
   (((grid:foreign-pointer combination) :pointer) ((size combination) sizet)
    ((grid:foreign-pointer v) :pointer)
    (1 sizet)				; stride, set to 1 for now
-   ((first (grid:dimensions combination)) sizet))
-  :definition :generic
+   ((first (grid:dimensions v)) sizet))
   :element-types :no-complex
+  :definition :generic
   :c-return :void
   :inputs (v)
   :outputs (combination)
   :documentation
-  "The indices of the smallest elements of the vector stored,
-    returned as a CL vector of element type fixnum.  If
-    indices is a positive initeger, a vector will be
-    allocated and returned.  If it is a CL vector,
-    it will be filled with the indices.")
+  "The indices of the smallest elements of the vector.  If size-or-array is an integer, it is the number of smallest elements.  If it is an array of sizet elements, it is filled.")
 
 (defmfun sort-vector-largest (dest (v vector))
   ("gsl_sort_vector" :type "_largest")
@@ -246,23 +245,21 @@
     allocated and returned.  If it is a CL vector,
     it will be filled with the indices.")
 
-(defmfun sort-largest-index (combination (v vector))
+(defmfun sort-largest-index
+    ((v vector) &optional (size-or-array 3)
+		&aux (combination (vdf size-or-array 'sizet)))
   ("gsl_sort" :type "_largest_index")
   (((grid:foreign-pointer combination) :pointer) ((size combination) sizet)
    ((grid:foreign-pointer v) :pointer)
    (1 sizet)				; stride, set to 1 for now
-   ((first (grid:dimensions combination)) sizet))
+   ((first (grid:dimensions v)) sizet))
   :element-types :no-complex
   :definition :generic
   :c-return :void
   :inputs (v)
   :outputs (combination)
   :documentation
-  "The indices of the largest elements of the vector stored,
-    returned as a CL vector of element type fixnum.  If
-    indices is a positive initeger, a vector will be
-    allocated and returned.  If it is a CL vector,
-    it will be filled with the indices.")
+  "The indices of the largest elements of the vector.  If size-or-array is an integer, it is the number of smallest elements.  If it is an array of sizet elements, it is filled.")
 
 ;;;;****************************************************************************
 ;;;; Examples and unit test
diff --git a/special-functions/return-structures.lisp b/special-functions/return-structures.lisp
index c4e81e5b..9b6b1070 100644
--- a/special-functions/return-structures.lisp
+++ b/special-functions/return-structures.lisp
@@ -1,8 +1,8 @@
 ;; Structures returned by special functions.
 ;; Liam Healy, Mon Jan  1 2007 - 11:35
-;; Time-stamp: <2011-10-29 18:24:42EDT return-structures.lisp>
+;; Time-stamp: <2012-01-03 13:16:46EST return-structures.lisp>
 ;;
-;; Copyright 2007, 2008, 2009, 2010, 2011 Liam M. Healy
+;; Copyright 2007, 2008, 2009, 2010, 2011, 2012 Liam M. Healy
 ;; Distributed under the terms of the GNU General Public License
 ;;
 ;; This program is free software: you can redistribute it and/or modify
@@ -63,14 +63,19 @@
 (defparameter *default-sf-array-size* 5
   "The default size to make an array returned from a special function.")
 
-(defun vdf (size-or-array)
-  "Make or take a vector-double-float."
+(defun vdf (size-or-array &optional (type 'double-float))
+  "Make or take a vector."
   (if (integerp size-or-array)
-      (grid:make-foreign-array 'double-float :dimensions size-or-array)
+      (grid:make-foreign-array
+       (if (eq type 'sizet)
+	   #+int64 '(unsigned-byte 64)
+	   #+int32 '(unsigned-byte 32)
+	   type)
+       :dimensions size-or-array)
       size-or-array))
 
 (defun vdf-size (size-or-array)
-  "Make or take a vector-double-float."
+  "Size of vector made with vfd."
   (if (integerp size-or-array)
       size-or-array
       (size size-or-array)))
-- 
GitLab