diff --git a/histogram/histogram.lisp b/histogram/histogram.lisp index dee1e6dbe91a850a31ed70cb84c8bf73283e6c24..73572b47370c89bcdd35f60d17b60beb951cc2e2 100644 --- a/histogram/histogram.lisp +++ b/histogram/histogram.lisp @@ -1,6 +1,6 @@ ;; 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))