Call BLAS ddot from SBCL

I am trying to call the BLD ddot procedure from SBCL.

Based:

I came up with the following script:

(load-shared-object "libblas.so.3") (declaim (inline ddot)) (define-alien-routine ("ddot_" ddot) void (n int :copy) (dx (* double)) (incx int :copy) (dy (* double)) (incy int :copy)) (defun pointer (array) (sap-alien (sb-sys:vector-sap (array-storage-vector array)) (* double))) (defun dot (dx dy) (unless (= (length dx) (length dy)) (error "Vectors length does not match")) (let ((n (length dx)) (result 0.0d0)) (sb-sys:with-pinned-objects (dx dy result) (ddot n (pointer dx) 1 (pointer dy) 1)))) 

However, the following script:

 (defvar *a* (make-array 4 :initial-element 1.0d0 :element-type 'double-float)) (defvar *b* (make-array 4 :initial-element 2.0d0 :element-type 'double-float)) (dot *a* *b*) 

produces the following error:

 arithmetic error FLOATING-POINT-INVALID-OPERATION signalled [Condition of type FLOATING-POINT-INVALID-OPERATION] 

Any clues?

+5
source share
2 answers

Found. Credits to Miroslav Urbanek from Charles University in Prague for a hint.

 -(define-alien-routine ("ddot_" ddot) void +(define-alien-routine ("ddot_" ddot) double (defun dot (dx dy) (unless (= (length dx) (length dy)) (error "Vectors length does not match")) - (let ((n (length dx)) - (result 0.0d0)) - (sb-sys:with-pinned-objects (dx dy result) + (let ((n (length dx))) + (sb-sys:with-pinned-objects (dx dy) 

The ddot procedure is designed to return a double, not a void. And the result variable is useless. Everything becomes so obvious after you become aware of them :-)

+4
source

I know that it does not directly answer your question, but have you tried using the already written binding with Blas? For example, Matlisp already provides a lispy interface for dot

+3
source

All Articles