Commit b2f6ae1f by Liam M. Healy

Add direct foreign-vector view of 1D histograms

Defined two functions, view-range-as-foreign-array and view-bin-as-foreign-array that proved direct foreign-vector view of 1D histograms (shared data memory with the foreign histogram). This maybe be a precursor to some eventual generic "view" function, so the function symbols are not exported yet as the name may change. Also, the defcstruct should be done as a grovel on the C header. However, the functions do work now.
parent 6f2ef048
;; The histogram structure
;; Liam Healy, Mon Jan 1 2007 - 11:32
;; Time-stamp: <2013-05-03 15:46:46EDT histogram.lisp>
;; Time-stamp: <2013-10-04 10:40:54EDT histogram.lisp>
;;
;; Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -129,3 +129,29 @@
(if destination
(histo2d-copy destination source)
(histo2d-clone destination)))
;;;;****************************************************************************
;;; Experimental direct access to vector
;;; Note this does not grovel.
(cffi:defcstruct histogram-c
(n :sizet)
(range :pointer)
(bin :pointer))
(defun view-bin-as-foreign-array (histogram)
"A view of the histogram bin counts as a foreign array. The two objects point to the same foreign data."
;; 1D histograms only so far
(grid:make-foreign-array-from-pointer
(cffi:foreign-slot-value (mpointer histogram) '(:struct histogram-c) 'bin)
(grid:dimensions histogram)
'double-float
nil))
(defun view-range-as-foreign-array (histogram)
"A view of the histogram range as a foreign array. This vector has one more element than the number of bins; the first element is the lower bound of the first bin, and the last element is the upper bound of the last bin. The two objects point to the same foreign data."
;; 1D histograms only so far
(grid:make-foreign-array-from-pointer
(cffi:foreign-slot-value (mpointer histogram) '(:struct histogram-c) 'range)
(list (1+ (grid:dim0 histogram)))
'double-float
nil))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment