-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoolkit.lisp
43 lines (35 loc) · 1.48 KB
/
toolkit.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(in-package #:org.shirakumo.flare.matrix)
;; We choose this limit in order to ensure that matrix indices
;; always remain within fixnum range. I'm quite certain you don't
;; want to use matrices as big as this allows anyway. You'll want
;; BLAS/LAPACK and/or someone much smarter than me for that.
(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *matrix-limit* (min (floor (sqrt array-dimension-limit))
(floor (sqrt most-positive-fixnum)))))
(defvar *eps* (ecase *float-type*
(single-float 0.00001f0)
(double-float 0.00000000001d0)))
(declaim (type #.*float-type* *eps*))
(deftype mat-dim ()
'(integer 0 #.(1- *matrix-limit*)))
(declaim (inline ensure-function))
(defun ensure-function (functionish)
(etypecase functionish
(function functionish)
(symbol (fdefinition functionish))))
(declaim (ftype (function (float-type float-type) boolean) ~=))
(declaim (inline ~=))
(defun ~= (a b)
(< (abs (- a b)) *eps*))
(declaim (ftype (function (float-type float-type) boolean) ~/=))
(declaim (inline ~/=))
(defun ~/= (a b)
(<= *eps* (abs (- a b))))
(defmacro with-floats (&environment env bindings &body body)
`(let ,(loop for (var val) in bindings
collect `(,var (the ,*float-type* ,(ensure-float-param val env))))
,@body))
(defun intern* (&rest parts)
(let ((*print-case* (readtable-case *readtable*))
(*package* #.*package*))
(intern (format NIL "~{~a~}" parts) #.*package*)))