Really move check-sequence to sequence package.
[CommonLispStat.git] / cffiglue.lsp
blob559ebd1f69750a6cdb1b0dd7c4f1eceb47964e3e
1 ;; -*- mode: lisp -*-
3 ;;;; cffiglue -- Interface to C library
4 ;;;;
5 ;;;; Copyright (c) 1991, by Luke Tierney.
6 ;;;; Copyright (c) 2007, by Carlos Ungil.
7 ;;;; Copyright (c) 2007, by AJ Rossini <blindglobe@gmail.com>.
8 ;;;; Permission is granted for unrestricted use.
10 ;;;; Tested (but the results have not been checked):
11 ;;;; Probability Distributions
12 ;;;; Internal Error Message Emulation
13 ;;;; Matrix Manipulation
15 ;;;; Untested
16 ;;;; numgrad numhess minfo-maximize
18 (defpackage :lisp-stat-ffi-int
19 (:use :common-lisp
20 :cffi)
21 (:export
23 chol-decomp-front
24 lu-decomp-front lu-solve-front
25 sv-decomp-front
26 qr-decomp-front
28 rcondest-front
29 make-rotation-front
31 eigen-front
33 la-range-to-rseq
34 spline-front
36 kernel-dens-front
37 kernel-smooth-front
39 base-lowess-front
41 numgrad-front
42 numhess-front
43 base-minfo-maximize
45 one-uniform-rand
46 base-log-gamma
48 base-normal-cdf
49 base-normal-quant
50 base-normal-dens
51 one-normal-rand
52 base-bivnorm-cdf
54 base-cauchy-cdf
55 base-cauchy-quant
56 base-cauchy-dens
57 one-cauchy-rand
59 base-gamma-cdf
60 base-gamma-quant
61 base-gamma-dens
62 one-gamma-rand
64 base-chisq-cdf
65 base-chisq-quant
66 base-chisq-dens
67 one-chisq-rand
69 base-beta-cdf
70 base-beta-quant
71 base-beta-dens
72 one-beta-rand
74 base-t-cdf
75 base-t-quant
76 base-t-dens
77 one-t-rand
79 base-f-cdf
80 base-f-quant
81 base-f-dens
82 one-f-rand
84 base-poisson-cdf
85 base-poisson-quant
86 base-poisson-dens
87 one-poisson-rand
89 base-binomial-cdf
90 base-binomial-quant
91 base-binomial-dens
92 one-binomial-rand
95 ))
97 (in-package :lisp-stat-ffi-int)
99 (cffi:load-foreign-library
100 (concatenate 'string
101 (namestring cl-user::*lispstat-home-dir*)
102 "lib/liblispstat"
103 #+darwin ".dylib"
104 #-darwin ".so"))
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;;;;
108 ;;;; Callback Support Functions
109 ;;;;
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 (cffi:defcfun ("ccl_store_integer" ccl-store-integer)
113 :void (x :int))
114 (cffi:defcfun ("ccl_store_double" ccl-store-double)
115 :void (x :double))
116 (cffi:defcfun ("ccl_store_ptr" ccl-store-ptr)
117 :void (x :pointer))
119 ;;;;
120 ;;;; Lisp-Managed Calloc/Free
121 ;;;;
123 ;;;; this section is commented out in mclglue.lsp
124 ;;;; and the relevant fragment in cffi-glue.c is not compiled (ifdef DODO)
126 ;;;;
127 ;;;; Storage Allocation Functions
128 ;;;;
131 (defun null-ptr-p (p) (cffi:null-pointer-p p))
132 (defun ptr-eq (p q) (cffi:pointer-eq p q))
134 (cffi:defcfun ("la_base_allocate" ccl-la-base-allocate)
135 :pointer (n :int) (m :int))
136 (defun la-base-allocate (n m)
137 (ccl-la-base-allocate n m))
139 (cffi:defcfun ("la_base_free_alloc" ccl-la-base-free-alloc)
140 :void (p :pointer))
141 (defun la-base-free (p)
142 (ccl-la-base-free-alloc p))
144 (cffi:defcfun ("la_mode_size" ccl-la-mode-size)
145 :int (x :int))
147 (defun la-mode-size (mode)
148 (ccl-la-mode-size mode))
150 ;;;;
151 ;;;; Callbacks for Internal Storage
152 ;;;;
154 (cffi:defcallback lisp-la-allocate :void ((n :long) (m :long))
155 (ccl-store-ptr (la-allocate n m)))
156 (cffi:defcfun ("register_la_allocate" register-la-allocate)
157 :void (p :pointer))
158 (register-la-allocate (cffi:callback lisp-la-allocate))
159 (cffi:defcfun ("la_allocate" la)
160 :pointer (x :int) (y :int))
162 (cffi:defcallback lisp-la-free-alloc :void ((p :pointer))
163 (la-free p))
164 (cffi:defcfun ("register_la_free_alloc" register-la-free-alloc)
165 :void (p :pointer))
166 (register-la-free-alloc (cffi:callback lisp-la-free-alloc))
167 (cffi:defcfun ("la_free_alloc" lf)
168 :void (p :pointer))
170 ;;;;
171 ;;;; Storage Access Functions
172 ;;;;
174 (cffi:defcfun ("la_get_integer" ccl-la-get-integer)
175 :int (p :pointer) (i :int))
176 (defun la-get-integer (p i)
177 (ccl-la-get-integer p i))
179 (cffi:defcfun ("la_get_double" ccl-la-get-double)
180 :double (p :pointer) (i :int))
181 (defun la-get-double (p i)
182 (ccl-la-get-double p i))
184 (cffi:defcfun ("la_get_complex_real" ccl-la-get-complex-real)
185 :double (p :pointer) (i :int))
186 (defun la-get-complex-real (p i)
187 (ccl-la-get-complex-real p i))
189 (cffi:defcfun ("la_get_complex_imag" ccl-la-get-complex-imag)
190 :double (p :pointer) (i :int))
191 (defun la-get-complex-imag (p i)
192 (ccl-la-get-complex-imag p i))
194 (defun la-get-complex (p i)
195 (complex (la-get-complex-real p i) (la-get-complex-imag p i)))
197 (cffi:defcfun ("la_get_pointer" ccl-la-get-pointer)
198 :pointer (p :pointer) (i :int))
199 (defun la-get-pointer (p i)
200 (ccl-la-get-pointer p i))
202 ;;;;
203 ;;;; Storage Mutation Functions
204 ;;;;
206 (cffi:defcfun ("la_put_integer" ccl-la-put-integer)
207 :void (p :pointer) (i :int) (x :int))
208 (defun la-put-integer (p i x)
209 (ccl-la-put-integer p i x))
211 (cffi:defcfun ("la_put_double" ccl-la-put-double)
212 :void (p :pointer) (i :int) (x :double))
213 (defun la-put-double (p i x)
214 (ccl-la-put-double p i (float x 1d0)))
216 (cffi:defcfun ("la_put_complex" ccl-la-put-complex)
217 :void (p :pointer) (i :int) (x :double) (y :double))
218 (defun la-put-complex (p i x y)
219 (ccl-la-put-complex p i (float x 1d0) (float y 1d0)))
221 (cffi:defcfun ("la_put_pointer" ccl-la-put-pointer)
222 :void (p :pointer) (i :int) (q :pointer))
223 (defun la-put-pointer (p i q)
224 (ccl-la-put-pointer p i q))
226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
227 ;;;;
228 ;;;; XLISP Internal Error Message Emulation
229 ;;;;
230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
232 (defvar *buf* (make-string 1000))
234 (defun set-buf-char (i c) (setf (elt *buf* i) (code-char c)))
236 (defun get-buf (&optional (n (position (code-char 0) *buf*)))
237 (subseq *buf* 0 n))
239 (cffi:defcfun ("register_set_buf_char" register-set-buf-char)
240 :void (p :pointer))
241 (cffi:defcallback ccl-set-buf-char :void ((n :int) (c :int))
242 (set-buf-char n c))
243 (register-set-buf-char (cffi:callback ccl-set-buf-char))
245 (cffi:defcfun ("register_print_buffer" register-print-buffer)
246 :void (p :pointer))
247 (cffi:defcallback ccl-print-buffer :void ((n :int) (type :int))
248 (case type
249 (0 (princ (get-buf n)))
250 (1 (error (get-buf n))))
252 (register-print-buffer (cffi:callback ccl-print-buffer))
254 (cffi:defcfun ("stdputstr" stdputstr)
255 :void (string :string))
256 (cffi:defcfun ("xlfail" xlfail)
257 :void (string :string))
259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261 ;;; Lisp Interfaces to Linear Algebra Routines
263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
266 ;;; Cholesky Decomposition
269 (cffi:defcfun ("ccl_chol_decomp_front" ccl-chol-decomp-front)
270 :int (x :pointer) (y :int) (z :pointer))
271 (defun chol-decomp-front (x y z)
272 (ccl-chol-decomp-front x y z))
274 ;;;;
275 ;;;; LU Decomposition
276 ;;;;
278 (cffi:defcfun ("ccl_lu_decomp_front" ccl-lu-decomp-front)
279 :int (x :pointer) (y :int) (z :pointer) (u :int) (v :pointer))
280 (defun lu-decomp-front (x y z u v)
281 (ccl-lu-decomp-front x y z u v))
283 (cffi:defcfun ("ccl_lu_solve_front" ccl-lu-solve-front)
284 :int (x :pointer) (y :int) (z :pointer) (u :pointer) (v :int))
285 (defun lu-solve-front (x y z u v)
286 (ccl-lu-solve-front x y z u v))
288 (cffi:defcfun ("ccl_lu_inverse_front" ccl-lu-inverse-front)
289 :int (x :pointer) (y :int) (z :pointer) (u :pointer) (v :int) (w :pointer))
290 (defun lu-inverse-front (x y z u v w)
291 (ccl-lu-inverse-front x y z u v w))
293 ;;;;
294 ;;;; SV Decomposition
295 ;;;;
297 (cffi:defcfun ("ccl_sv_decomp_front" ccl-sv-decomp-front)
298 :int (x :pointer) (y :int) (z :int) (u :pointer) (v :pointer))
299 (defun sv-decomp-front (x y z u v)
300 (ccl-sv-decomp-front x y z u v))
302 ;;;;
303 ;;;; QR Decomposition
304 ;;;;
306 (cffi:defcfun ("ccl_qr_decomp_front" ccl-qr-decomp-front)
307 :int (x :pointer) (y :int) (z :int) (u :pointer) (v :pointer) (w :int))
308 (defun qr-decomp-front (x y z u v w)
309 (ccl-qr-decomp-front x y z u v w))
311 ;;;;
312 ;;;; Estimate of Condition Number for Lower Triangular Matrix
313 ;;;;
315 (cffi:defcfun ("ccl_rcondest_front" ccl-rcondest-front)
316 :double (x :pointer) (y :int))
317 (defun rcondest-front (x y)
318 (ccl-rcondest-front x y))
320 ;;;;
321 ;;;; Make Rotation Matrix
322 ;;;;
324 (cffi:defcfun ("ccl_make_rotation_front" ccl-make-rotation-front)
325 :int (x :int) (y :pointer) (z :pointer) (u :pointer) (v :int) (w :double))
326 (defun make-rotation-front (x y z u v w)
327 (ccl-make-rotation-front x y z u v (float w 1d0)))
329 ;;;;
330 ;;;; Eigenvalues and Eigenvectors
331 ;;;;
333 (cffi:defcfun ("ccl_eigen_front" ccl-eigen-front)
334 :int (x :pointer) (y :int) (z :pointer) (u :pointer) (v :pointer))
335 (defun eigen-front (x y z u v)
336 (ccl-eigen-front x y z u v))
338 ;;;;
339 ;;;; Spline Interpolation
340 ;;;;
342 (cffi:defcfun ("ccl_range_to_rseq" ccl-range-to-rseq)
343 :int (x :int) (y :pointer) (z :int) (u :pointer))
344 (defun la-range-to-rseq (x y z u)
345 (ccl-range-to-rseq x y z u))
347 (cffi:defcfun ("ccl_spline_front" ccl-spline-front)
348 :int (x :int) (y :pointer) (z :pointer) (u :int) (v :pointer) (w :pointer) (a :pointer))
349 (defun spline-front (x y z u v w a)
350 (ccl-spline-front x y z u v w a))
352 ;;;;
353 ;;;; Kernel Density Estimators and Smoothers
354 ;;;;
356 (cffi:defcfun ("ccl_kernel_dens_front" ccl-kernel-dens-front)
357 :int (x :pointer) (y :int) (z :double) (u :pointer) (v :pointer) (w :int) (a :int))
358 (defun kernel-dens-front (x y z u v w a)
359 (ccl-kernel-dens-front x y (float z 1d0) u v w a))
361 (cffi:defcfun ("ccl_kernel_smooth_front" ccl-kernel-smooth-front)
362 :int (x :pointer) (y :pointer) (z :int) (u :double) (v :pointer) (w :pointer) (a :int) (b :int))
363 (defun kernel-smooth-front (x y z u v w a b)
364 (ccl-kernel-smooth-front x y z (float u 1d0) v w a b))
366 ;;;;
367 ;;;; Lowess Smoother Interface
368 ;;;;
370 (cffi:defcfun ("ccl_base_lowess_front" ccl-base-lowess-front)
371 :int (x :pointer) (y :pointer) (z :int) (u :double) (v :int) (w :double) (a :pointer) (b :pointer) (c :pointer))
372 (defun base-lowess-front (x y z u v w a b c)
373 (ccl-base-lowess-front x y z (float u 1d0) v (float w 1d0) a b c))
375 ;;;;
376 ;;;; FFT
377 ;;;;
379 (cffi:defcfun ("ccl_fft_front" ccl-fft-front)
380 :int (x :int) (y :pointer) (z :pointer) (u :int))
381 (defun fft-front (x y z u)
382 (ccl-fft-front x y z u))
384 ;;;;
385 ;;;; Maximization and Numerical Derivatives
386 ;;;;
388 (cffi:defcallback ccl-maximize-callback :void ((n :int)
389 (px :pointer)
390 (pfval :pointer)
391 (pgrad :pointer)
392 (phess :pointer)
393 (pderivs :pointer))
394 (lisp-stat-optimize::maximize-callback n px pfval pgrad phess pderivs))
396 (cffi:defcfun ("register_maximize_callback" register-maximize-callback)
397 :void (x :pointer))
398 (register-maximize-callback (cffi:callback ccl-maximize-callback))
400 (cffi:defcfun ("ccl_numgrad_front" ccl-numgrad-front)
401 :int (x :int) (y :pointer) (z :pointer) (u :double) (v :pointer))
402 (defun numgrad-front (x y z u v)
403 (ccl-numgrad-front x y z (float u 1d0) v))
405 (cffi:defcfun ("ccl_numhess_front" ccl-numhess-front)
406 :int (x :int) (y :pointer) (z :pointer) (u :pointer) (v :pointer) (w :double) (a :pointer))
407 (defun numhess-front (x y z u v w a)
408 (ccl-numhess-front x y z u v (float w 1d0) a))
410 (cffi:defcfun ("ccl_minfo_maximize" ccl-minfo-maximize)
411 :int (x :pointer) (y :pointer) (z :pointer) (u :pointer) (v :pointer) (w :int))
412 (defun base-minfo-maximize (x y z u v w)
413 (ccl-minfo-maximize x y z u v w))
415 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
416 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
417 ;;;;
418 ;;;; Probability Distributions
419 ;;;;
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
423 ;;;;
424 ;;;; C-callable uniform generator
425 ;;;;
427 (cffi:defcfun ("register_uni" register-uni)
428 :void (f :pointer))
429 (cffi:defcallback ccl-uni :int () (ccl-store-double (random 1.0)) 0)
430 (register-uni (cffi:callback ccl-uni))
432 (defun one-uniform-rand () (random 1.0))
434 ;;;;
435 ;;;; Log-gamma function
436 ;;;;
438 (cffi:defcfun ("ccl_gamma" ccl-base-log-gamma)
439 :double (x :double))
440 (defun base-log-gamma (x)
441 (ccl-base-log-gamma (float x 1d0)))
443 ;;;;
444 ;;;; Normal distribution
445 ;;;;
447 (cffi:defcfun ("ccl_normalcdf" ccl-base-normal-cdf)
448 :double (x :double))
449 (defun base-normal-cdf (x)
450 (ccl-base-normal-cdf (float x 1d0)))
452 (cffi:defcfun ("ccl_normalquant" ccl-base-normal-quant)
453 :double (x :double))
454 (defun base-normal-quant (x)
455 (ccl-base-normal-quant (float x 1d0)))
457 (cffi:defcfun ("ccl_normaldens" ccl-base-normal-dens)
458 :double (x :double))
459 (defun base-normal-dens (x)
460 (ccl-base-normal-dens (float x 1d0)))
462 (cffi:defcfun ("ccl_normalrand" one-normal-rand)
463 :float)
465 (cffi:defcfun ("ccl_bnormcdf" ccl-base-bivnorm-cdf)
466 :double (x :double) (y :double) (z :double))
467 (defun base-bivnorm-cdf (x y z)
468 (ccl-base-bivnorm-cdf (float x 1d0) (float y 1d0) (float z 1d0)))
470 ;;;;
471 ;;;; Cauchy distribution
472 ;;;;
474 (cffi:defcfun ("ccl_cauchycdf" ccl-base-cauchy-cdf)
475 :double (x :double))
476 (defun base-cauchy-cdf (x)
477 (ccl-base-cauchy-cdf (float x 1d0)))
479 (cffi:defcfun ("ccl_cauchyquant" ccl-base-cauchy-quant)
480 :double (x :double))
481 (defun base-cauchy-quant (x)
482 (ccl-base-cauchy-quant (float x 1d0)))
484 (cffi:defcfun ("ccl_cauchydens" ccl-base-cauchy-dens)
485 :double (x :double))
486 (defun base-cauchy-dens (x)
487 (ccl-base-cauchy-dens (float x 1d0)))
489 (cffi:defcfun ("ccl_cauchyrand" one-cauchy-rand)
490 :double)
492 ;;;;
493 ;;;; Gamma distribution
494 ;;;;
496 (cffi:defcfun ("ccl_gammacdf" ccl-base-gamma-cdf)
497 :double (x :double) (y :double))
498 (defun base-gamma-cdf (x y)
499 (ccl-base-gamma-cdf (float x 1d0) (float y 1d0)))
501 (cffi:defcfun ("ccl_gammaquant" ccl-base-gamma-quant)
502 :double (x :double) (y :double))
503 (defun base-gamma-quant (x y)
504 (ccl-base-gamma-quant (float x 1d0) (float y 1d0)))
506 (cffi:defcfun ("ccl_gammadens" ccl-base-gamma-dens)
507 :double (x :double) (y :double))
508 (defun base-gamma-dens (x y)
509 (ccl-base-gamma-dens (float x 1d0) (float y 1d0)))
511 (cffi:defcfun ("ccl_gammarand" ccl-gamma-rand)
512 :double (x :double))
513 (defun one-gamma-rand (x)
514 (ccl-gamma-rand (float x 1d0)))
516 ;;;;
517 ;;;; Chi-square distribution
518 ;;;;
520 (cffi:defcfun ("ccl_chisqcdf" ccl-base-chisq-cdf)
521 :double (x :double) (y :double))
522 (defun base-chisq-cdf (x y)
523 (ccl-base-chisq-cdf (float x 1d0) (float y 1d0)))
525 (cffi:defcfun ("ccl_chisqquant" ccl-base-chisq-quant)
526 :double (x :double) (y :double))
527 (defun base-chisq-quant (x y)
528 (ccl-base-chisq-quant (float x 1d0) (float y 1d0)))
530 (cffi:defcfun ("ccl_chisqdens" ccl-base-chisq-dens)
531 :double (x :double) (y :double))
532 (defun base-chisq-dens (x y)
533 (ccl-base-chisq-dens (float x 1d0) (float y 1d0)))
535 (cffi:defcfun ("ccl_chisqrand" ccl-chisq-rand)
536 :double (x :double))
537 (defun one-chisq-rand (x)
538 (ccl-chisq-rand (float x 1d0)))
540 ;;;;
541 ;;;; Beta distribution
542 ;;;;
544 (cffi:defcfun ("ccl_betacdf" ccl-base-beta-cdf)
545 :double (x :double) (y :double) (z :double))
546 (defun base-beta-cdf (x y z)
547 (ccl-base-beta-cdf (float x 1d0) (float y 1d0) (float z 1d0)))
549 (cffi:defcfun ("ccl_betaquant" ccl-base-beta-quant)
550 :double (x :double) (y :double) (z :double))
551 (defun base-beta-quant (x y z)
552 (ccl-base-beta-quant (float x 1d0) (float y 1d0) (float z 1d0)))
554 (cffi:defcfun ("ccl_betadens" ccl-base-beta-dens)
555 :double (x :double) (y :double) (z :double))
556 (defun base-beta-dens (x y z)
557 (ccl-base-beta-dens (float x 1d0) (float y 1d0) (float z 1d0)))
559 (cffi:defcfun ("ccl_betarand" ccl-beta-rand)
560 :double (x :double) (y :double))
561 (defun one-beta-rand (x y)
562 (ccl-beta-rand (float x 1d0) (float y 1d0)))
564 ;;;;
565 ;;;; t distribution
566 ;;;;
568 (cffi:defcfun ("ccl_tcdf" ccl-base-t-cdf)
569 :double (x :double) (y :double))
570 (defun base-t-cdf (x y)
571 (ccl-base-t-cdf (float x 1d0) (float y 1d0)))
573 (cffi:defcfun ("ccl_tquant" ccl-base-t-quant)
574 :double (x :double) (y :double))
575 (defun base-t-quant (x y)
576 (ccl-base-t-quant (float x 1d0) (float y 1d0)))
578 (cffi:defcfun ("ccl_tdens" ccl-base-t-dens)
579 :double (x :double) (y :double))
580 (defun base-t-dens (x y)
581 (ccl-base-t-dens (float x 1d0) (float y 1d0)))
583 (cffi:defcfun ("ccl_trand" ccl-t-rand)
584 :double (x :double))
585 (defun one-t-rand (x)
586 (ccl-t-rand (float x 1d0)))
588 ;;;;
589 ;;;; F distribution
590 ;;;;
592 (cffi:defcfun ("ccl_fcdf" ccl-base-f-cdf)
593 :double (x :double) (y :double) (z :double))
594 (defun base-f-cdf (x y z)
595 (ccl-base-f-cdf (float x 1d0) (float y 1d0) (float z 1d0)))
597 (cffi:defcfun ("ccl_fquant" ccl-base-f-quant)
598 :double (x :double) (y :double) (z :double))
599 (defun base-f-quant (x y z)
600 (ccl-base-f-quant (float x 1d0) (float y 1d0) (float z 1d0)))
602 (cffi:defcfun ("ccl_fdens" ccl-base-f-dens)
603 :double (x :double) (y :double) (z :double))
604 (defun base-f-dens (x y z)
605 (ccl-base-f-dens (float x 1d0) (float y 1d0) (float z 1d0)))
607 (cffi:defcfun ("ccl_frand" ccl-f-rand)
608 :double (x :double) (y :double))
609 (defun one-f-rand (x y) (ccl-f-rand (float x 1d0) (float y 1d0)))
611 ;;;;
612 ;;;; Poisson distribution
613 ;;;;
615 (cffi:defcfun ("ccl_poissoncdf" ccl-base-poisson-cdf)
616 :double (x :double) (y :double))
617 (defun base-poisson-cdf (x y)
618 (ccl-base-poisson-cdf (float x 1d0) (float y 1d0)))
620 (cffi:defcfun ("ccl_poissonquant" ccl-base-poisson-quant)
621 :int (x :double) (y :double))
622 (defun base-poisson-quant (x y)
623 (ccl-base-poisson-quant (float x 1d0) (float y 1d0)))
625 (cffi:defcfun ("ccl_poissonpmf" ccl-base-poisson-pmf)
626 :double (x :int) (y :double))
627 (defun base-poisson-pmf (x y)
628 (ccl-base-poisson-pmf x (float y 1d0)))
630 (cffi:defcfun ("ccl_poissonrand" ccl-poisson-rand)
631 :int (x :double))
632 (defun one-poisson-rand (x)
633 (ccl-poisson-rand (float x 1d0)))
635 ;;;;
636 ;;;; Binomial distribution
637 ;;;;
639 (cffi:defcfun ("ccl_binomialcdf" ccl-base-binomial-cdf)
640 :double (x :double) (y :int) (z :double))
641 (defun base-binomial-cdf (x y z)
642 (ccl-base-binomial-cdf (float x 1d0) y (float z 1d0)))
644 (cffi:defcfun ("ccl_binomialquant" ccl-base-binomial-quant)
645 :int (x :double) (y :int) (z :double))
646 (defun base-binomial-quant (x y z)
647 (ccl-base-binomial-quant (float x 1d0) y (float z 1d0)))
649 (cffi:defcfun ("ccl_binomialpmf" ccl-base-binomial-pmf)
650 :double (x :int) (y :int) (z :double))
651 (defun base-binomial-pmf (x y z)
652 (ccl-base-binomial-pmf x y (float z 1d0)))
654 (cffi:defcfun ("ccl_binomialrand" ccl-binomial-rand)
655 :int (x :int) (y :double))
656 (defun one-binomial-rand (x y)
657 (ccl-binomial-rand x (float y 1d0)))