Skip to content
Snippets Groups Projects
Commit 7151b5bb authored by Liam M. Healy's avatar Liam M. Healy
Browse files

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.
parent 1a7e83f1
No related branches found
No related tags found
No related merge requests found
;; Sorting ;; Sorting
;; Liam Healy, Fri Apr 14 2006 - 20:20 ;; 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 ;; Distributed under the terms of the GNU General Public License
;; ;;
;; This program is free software: you can redistribute it and/or modify ;; This program is free software: you can redistribute it and/or modify
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
(in-package :gsl) (in-package :gsl)
;;; #'heapsort has just a cursory port, use CL's #'sort. ;;; #'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 ;;;; Heapsort, not recommended
...@@ -182,23 +183,21 @@ ...@@ -182,23 +183,21 @@
allocated and returned. If it is a CL vector, allocated and returned. If it is a CL vector,
it will be filled with the indices.") 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") ("gsl_sort" :type "_smallest_index")
(((grid:foreign-pointer combination) :pointer) ((size combination) sizet) (((grid:foreign-pointer combination) :pointer) ((size combination) sizet)
((grid:foreign-pointer v) :pointer) ((grid:foreign-pointer v) :pointer)
(1 sizet) ; stride, set to 1 for now (1 sizet) ; stride, set to 1 for now
((first (grid:dimensions combination)) sizet)) ((first (grid:dimensions v)) sizet))
:definition :generic
:element-types :no-complex :element-types :no-complex
:definition :generic
:c-return :void :c-return :void
:inputs (v) :inputs (v)
:outputs (combination) :outputs (combination)
:documentation :documentation
"The indices of the smallest elements of the vector stored, "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.")
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.")
(defmfun sort-vector-largest (dest (v vector)) (defmfun sort-vector-largest (dest (v vector))
("gsl_sort_vector" :type "_largest") ("gsl_sort_vector" :type "_largest")
...@@ -246,23 +245,21 @@ ...@@ -246,23 +245,21 @@
allocated and returned. If it is a CL vector, allocated and returned. If it is a CL vector,
it will be filled with the indices.") 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") ("gsl_sort" :type "_largest_index")
(((grid:foreign-pointer combination) :pointer) ((size combination) sizet) (((grid:foreign-pointer combination) :pointer) ((size combination) sizet)
((grid:foreign-pointer v) :pointer) ((grid:foreign-pointer v) :pointer)
(1 sizet) ; stride, set to 1 for now (1 sizet) ; stride, set to 1 for now
((first (grid:dimensions combination)) sizet)) ((first (grid:dimensions v)) sizet))
:element-types :no-complex :element-types :no-complex
:definition :generic :definition :generic
:c-return :void :c-return :void
:inputs (v) :inputs (v)
:outputs (combination) :outputs (combination)
:documentation :documentation
"The indices of the largest elements of the vector stored, "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.")
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.")
;;;;**************************************************************************** ;;;;****************************************************************************
;;;; Examples and unit test ;;;; Examples and unit test
......
;; Structures returned by special functions. ;; Structures returned by special functions.
;; Liam Healy, Mon Jan 1 2007 - 11:35 ;; 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 ;; Distributed under the terms of the GNU General Public License
;; ;;
;; This program is free software: you can redistribute it and/or modify ;; This program is free software: you can redistribute it and/or modify
...@@ -63,14 +63,19 @@ ...@@ -63,14 +63,19 @@
(defparameter *default-sf-array-size* 5 (defparameter *default-sf-array-size* 5
"The default size to make an array returned from a special function.") "The default size to make an array returned from a special function.")
(defun vdf (size-or-array) (defun vdf (size-or-array &optional (type 'double-float))
"Make or take a vector-double-float." "Make or take a vector."
(if (integerp size-or-array) (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)) size-or-array))
(defun vdf-size (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) (if (integerp size-or-array)
size-or-array size-or-array
(size size-or-array))) (size size-or-array)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment