Re: Anyone understand this?
"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
Here is properly working code, just FYI:
(and with the (fli:with-dynamic-lisp-array-pointer (parr arr2 :type :double), using a :START arg defaulting to zero makes the code portable into the future, when someday the function is fixed.)
#+:MACOSX
(defvar *vdsp-lib*
"/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib")
#+:MACOSX
(fli:define-foreign-function (_vdsp-dotprd "vDSP_dotprD" :source)
((va :lisp-simple-1d-array)
(ia :long)
(vb :pointer)
(ib :long)
(pc (:pointer :double-float))
(nel :long))
:result-type :void
:language :c
:calling-convention :cdecl
:module *vdsp-lib*)
#+:MACOSX
(defun vdot (arr1 arr2 &key (start2 0))
;; intended for pre-decimation FIR filtering, where:
;; arr1 = FIR filter kernel
;; arr2 = input data buffer
;; nel = length of FIR filter (ntaps)
;; start2 = starting position in data buffer for filtering,
;; as kernel steps along by ndec
(declare (array (double-float *) arr1 arr2))
(fli:with-dynamic-foreign-objects ()
(let ((ans (fli:allocate-dynamic-foreign-object :type :double-float)))
(hcl:with-pinned-objects (arr2)
(fli:with-dynamic-lisp-array-pointer (parr arr2 :type :double)
(fli:incf-pointer parr start2)
(_vdsp-dotprd arr1 1 parr 1 ans (length arr1))
(fli:dereference ans))
))))
> On Jan 22, 2025, at 12:39, David McClain (as dbm at refined-audiometrics dot com) <[email protected]> wrote:
>
> YES!! Thanks for that suggestion!
>
> Use FLI:INCF-POINTER by START * 8 for a :DOUBLE array. And now it works!
>
> Thanks for the suggestion!!
>
>
>> On Jan 22, 2025, at 12:36, David McClain <[email protected]> wrote:
>>
>> I do seem to recall doing that sort of thing, many years ago when I wrote a direct memory file access mechanism for Lisp. Maybe…
>>
>>
>>
>>> On Jan 22, 2025, at 12:35, Yuri Davidovsky <[email protected]> wrote:
>>>
>>>
>>> Is there a way to increment a pointer in a separate step after creation?
>>>
>>>> On 22 Jan 2025, at 20:15, David McClain <[email protected]> wrote:
>>>>
>>>> This produces 10.0 instead of 30.0.
>>>>
>>>> (let* ((arr (make-array 3
>>>> :element-type 'double-float
>>>> :allocation :pinnable
>>>> :initial-contents '(10d0 20d0 30d0))))
>>>> (hcl:with-pinned-objects (arr)
>>>> (fli:with-dynamic-lisp-array-pointer (parr arr :start 2 :type :double-float)
>>>> (fli:dereference parr))))
>>
>