diff --git a/arrayfire.asd b/arrayfire.asd new file mode 100644 index 0000000..efaab6e --- /dev/null +++ b/arrayfire.asd @@ -0,0 +1,19 @@ +;;;; arrayfire-lisp.asd +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(asdf:defsystem #:arrayfire + :description "ArrayFire Bindings for Common Lisp" + :author "Justin Patera " + :license "BSD 3-Clause License" + + :depends-on (#:cffi + #:trivial-garbage) + + :serial t + :pathname "src" + :components + ((:file "package") + (:file "cffi") + (:file "utils"))) diff --git a/src/cffi.lisp b/src/cffi.lisp new file mode 100644 index 0000000..e173380 --- /dev/null +++ b/src/cffi.lisp @@ -0,0 +1,65 @@ +;;;; cffi.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(in-package :arrayfire) + +(define-foreign-library arrayfire + (t (:default "af"))) + +(use-foreign-library arrayfire) + +; make array +(defctype af-array :pointer) +(defctype dim-t :long-long) + +(defcenum af-dtype + :f32 + :c32 + :f64 + :c64 + :b8 + :s32 + :u32 + :u8 + :s64 + :u64 + :s16 + :u16) + + +(defcenum af-err + :af-success + :af-err-no-mem + :af-err-driver + :af-err-runtime + :af-err-invalid-array + :af-err-arg + :af-err-size + :af-err-type + :af-err-diff-type + :af-err-batch + :af-err-device + :af-err-not-supported + :af-err-not-configured + :af-err-nonfree + :af-err-no-dbl + :af-err-no-gfx + :af-err-load-lib + :af-err-load-sym + :af-err-arr-bknd-mismatch + :af-err-internal + :af-err-unknown ) + + + +(defcfun "af_create_array" af-err + (arr af-array) + (data :pointer) + (ndims :unsigned-int) + (dims dim-t) + (type af-dtype)) + +;(let ((arr)) +; (af-create-array arr 0 1 1 :b8)) diff --git a/src/package.lisp b/src/package.lisp new file mode 100644 index 0000000..63cac98 --- /dev/null +++ b/src/package.lisp @@ -0,0 +1,39 @@ +;;;; package.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(in-package :cl) + +(defpackage #:arrayfire + (:nicknames #:af) + (:use #:cl #:cffi) + ; as these will probably pose a small issue... + (:shadow ; Arithmatic Ops + #:+ #:- #:* #:/ + ; Complex Ops + #:complex #:real + ; Exponential & Logarithmic Fns + #:exp #:log #:sqrt + ; Logical Ops + #:and #:eq #:not #:or + ; Numeric Fns + #:abs #:floor #:max #:min #:mod #:rem #:round + ; Trigonometric & Hyberbolic Fns + #:acos #:asin #:atan #:cos #:sin #:tan + #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh) + + (:export ;; lots more than this... + ; Arithmatic Ops + #:+ #:- #:* #:/ + ; Complex Ops + #:complex #:real + ; Exponential & Logarithmic Fns + #:exp #:log #:sqrt + ; Logical Ops + #:and #:eq #:not #:or + ; Numeric Fns + #:abs #:floor #:max #:min #:mod #:rem #:round + ; Trigonometric & Hyberbolic Fns + #:acos #:asin #:atan #:cos #:sin #:tan + #:acosh #:asinh #:atanh #:cosh #:sinh #:tanh)) diff --git a/src/utils.lisp b/src/utils.lisp new file mode 100644 index 0000000..dd2c13e --- /dev/null +++ b/src/utils.lisp @@ -0,0 +1,24 @@ +;;;; autowrap.lisp +;;;; +;;;; Copyright (c) 2016 ArrayFire +;;;; Copyright (c) 2016 Justin Patera + +(in-package :arrayfire) + +; add utils here + +; because FizzBuzz is *essential* to our success!!! +(defun fizzbuzz (n) + (if (< 0 n) + (fizzbuzz-helper 1 n) + (error "The Fizzing And The Buzzing And The FizzBuzzing Needs Numbers Greater Than Zero"))) + +(defun fizzbuzz-helper (n x) + (if (<= n x) + (cons + (case (cl:mod n 15) + (0 "FizzBuzz") + ((3 6 9 12) "Fizz") + ((5 10) "Buzz") + (otherwise n)) + (fizzbuzz-helper (1+ n) x))))