Advertisement
Guest User

Untitled

a guest
Jul 28th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. (declaim (inline b-spline))
  2. (declaim (ftype (function (fixnum fixnum double-float (simple-array double-float)) double-float) b-spline))
  3. (defun b-spline (i m u nodes)
  4. (declare
  5. (type fixnum i)
  6. (type fixnum m)
  7. (type double-float u)
  8. (type (simple-array double-float 1) nodes)
  9. (optimize (debug 0) (safety 0) (speed 3)))
  10. (if (= m 1)
  11. (/ 1.0d0 (- (aref nodes i) (aref nodes (- i 1))))
  12. (let ((b1 (if (and (>= u (aref nodes (- i m))) (< u (aref nodes (- i 1))))
  13. (* (- u (the double-float (aref nodes (- i m)))) (b-spline (- i 1) (- m 1) u nodes))
  14. 0.0d0))
  15. (b2 (if (and (>= u (aref nodes (- i m -1))) (< u (aref nodes i)))
  16. (* (- (the double-float (aref nodes i)) u) (b-spline i (- m 1) u nodes))
  17. 0.0d0)))
  18. (declare (type double-float b1 b2))
  19. (the double-float (/ (+ b1 b2) (- (aref nodes i) (aref nodes (- i m))))))))
  20.  
  21. (defmacro def-b-spline (name nodes-p number-of-nodes)
  22. `(let ((nodes ,nodes-p)
  23. (b-spline-number-of-nodes ,number-of-nodes))
  24. (declare
  25. (type (simple-array double-float 1) nodes)
  26. (type fixnum b-spline-number-of-nodes)
  27. (optimize (debug 0) (safety 0) (speed 3)))
  28. (declaim (inline ,name))
  29. (declaim (ftype (function (fixnum fixnum double-float) double-float) ,name))
  30. (defun ,name(i m u)
  31. (declare
  32. (type fixnum i)
  33. (type fixnum m)
  34. (type double-float u)
  35. (optimize (debug 0) (safety 0) (speed 3)))
  36. (if (= m 1)
  37. (/ 1.0d0 (- (aref nodes i) (aref nodes (- i 1))))
  38. (let ((b1 (if (and (>= u (aref nodes (- i m))) (< u (aref nodes (- i 1))))
  39. (* (- u (the double-float (aref nodes (- i m)))) (,name (- i 1) (- m 1) u))
  40. 0.0d0))
  41. (b2 (if (and (>= u (aref nodes (- i m -1))) (< u (aref nodes i)))
  42. (* (- (the double-float (aref nodes i)) u) (,name i (- m 1) u))
  43. 0.0d0)))
  44. (declare (type double-float b1 b2))
  45. (the double-float (/ (+ b1 b2) (- (aref nodes i) (aref nodes (- i m))))))))))
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement