From 6377b63b5707c07fc0fe5f1f35ce0a0c23abc2d2 Mon Sep 17 00:00:00 2001
From: "Liam M. Healy" <lhealy@common-lisp.net>
Date: Fri, 29 Jul 2011 12:15:58 -0400
Subject: [PATCH] Dirichlet PDF functions, vector length should be K, not K-1

For the Dirichlet PDF functions, the vector length should be K, the
first argument, not K-1.  Reported by Nils Bertschinger.
---
 random/dirichlet.lisp | 6 +++---
 tests/dirichlet.lisp  | 5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/random/dirichlet.lisp b/random/dirichlet.lisp
index b86e5ac2..e1e493d3 100644
--- a/random/dirichlet.lisp
+++ b/random/dirichlet.lisp
@@ -1,6 +1,6 @@
 ;; Dirichlet distribution
 ;; Liam Healy, Sun Oct 29 2006
-;; Time-stamp: <2011-01-10 17:59:28EST dirichlet.lisp>
+;; Time-stamp: <2011-07-29 12:09:55EDT dirichlet.lisp>
 ;;
 ;; Copyright 2006, 2007, 2008, 2009, 2011 Liam M. Healy
 ;; Distributed under the terms of the GNU General Public License
@@ -54,7 +54,7 @@
 
 (defmfun dirichlet-pdf (alpha theta)
   "gsl_ran_dirichlet_pdf"
-  (((1- (dim0 alpha)) sizet)
+  (((dim0 alpha) sizet)
    ((grid:foreign-pointer alpha) :pointer)
    ;; theta had better be at least as long as alpha, or they'll be trouble
    ((grid:foreign-pointer theta) :pointer))
@@ -67,7 +67,7 @@
 
 (defmfun dirichlet-log-pdf (alpha theta)
   "gsl_ran_dirichlet_lnpdf"
-  (((1- (dim0 alpha)) sizet)
+  (((dim0 alpha) sizet)
    ((grid:foreign-pointer alpha) :pointer)
    ;; theta had better be at least as long as alpha, or they'll be trouble
    ((grid:foreign-pointer theta) :pointer))
diff --git a/tests/dirichlet.lisp b/tests/dirichlet.lisp
index d2736355..7740e812 100644
--- a/tests/dirichlet.lisp
+++ b/tests/dirichlet.lisp
@@ -28,7 +28,7 @@
 	  (alpha #m(1.0d0 2.0d0 3.0d0 4.0d0)))
       (grid:copy-to (sample rng :dirichlet :alpha alpha)))))
   (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
-   (LIST 1080.0000000000025d0)
+   (list 3.483648000000004d7)
    (MULTIPLE-VALUE-LIST
     (LET ((ALPHA
 	   (GRID:MAKE-FOREIGN-ARRAY 'DOUBLE-FLOAT :INITIAL-CONTENTS
@@ -38,7 +38,7 @@
 			'(1.0d0 2.0d0 3.0d0 4.0d0))))
       (DIRICHLET-PDF ALPHA THETA))))
   (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
-   (LIST 6.984716320118268d0)
+   (list 17.366175671549307d0)
    (MULTIPLE-VALUE-LIST
     (LET ((ALPHA
 	   (GRID:MAKE-FOREIGN-ARRAY 'DOUBLE-FLOAT :INITIAL-CONTENTS
@@ -47,4 +47,3 @@
 	   (GRID:MAKE-FOREIGN-ARRAY 'DOUBLE-FLOAT :INITIAL-CONTENTS
 			'(1.0d0 2.0d0 3.0d0 4.0d0))))
       (DIRICHLET-LOG-PDF ALPHA THETA)))))
-
-- 
GitLab