Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • antik/gsll
  • mvukovic/gsll
  • ssimsek/gsll
  • ajuan/gsll
4 results
Show changes
Commits on Source (2)
  • Liam M. Healy's avatar
    Load GSL lib v19 in preference to v0 · cb9c6bfd
    Liam M. Healy authored
    Load GSL library version 19 (libgsl.so.19) in preference to version 0,
    if it is available. This version, corresponding to GSL 2.0+, loads but
    functions whose API changed have not been tested. This required a fix to
    have-at-least-gsl-version which was incorrectly comparing version
    numbers.
    cb9c6bfd
  • Liam M. Healy's avatar
    Define defmobject for permutation · 35688357
    Liam M. Healy authored
    Permutation object is now defined by defmobject. This should be more
    portable to various word sizes.
    35688357
;; Permutations
;; Liam Healy, Sun Mar 26 2006 - 11:51
;; Time-stamp: <2016-06-14 23:31:07EDT permutation.lisp>
;; Time-stamp: <2016-12-03 21:03:56CST permutation.lisp>
;;
;; Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014, 2016 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -27,57 +27,41 @@
;;;; Permutation structure and CL object
;;;;****************************************************************************
(defclass permutation
(#+int64 grid:vector-unsigned-byte-64 #+int32 grid:vector-unsigned-byte-32)
()
(:documentation "GSL permutations."))
(defmethod initialize-instance :after
((object permutation) &key dimensions &allow-other-keys)
(let ((mptr (cffi:foreign-alloc '(:struct gsl-permutation-c))))
(setf (grid:metadata-slot object 'mpointer)
mptr
(cffi:foreign-slot-value mptr '(:struct gsl-permutation-c) 'data)
(grid:foreign-pointer object)
(cffi:foreign-slot-value mptr '(:struct gsl-permutation-c) 'size)
(first dimensions))
(tg:finalize object (lambda () (cffi:foreign-free mptr)))))
(export 'make-permutation)
(defun make-permutation (n &optional (initialize t))
"Make the object representing a permutation of n objects.
If n is a permutation, make a new permutation of the same size. If
initialize is T (default), set to the identity permutation if n is
an integer, or copy the permutation if it's a permutation."
(let ((perm
(make-instance
'permutation
:element-type '(unsigned-byte #+int64 64 #+int32 32)
:dimensions (if (typep n 'permutation) (grid:dimensions n) (list n)))))
(when initialize
(if (typep n 'permutation)
(error "not available yet") ; (copy perm n)
(set-identity perm)))
perm))
(defmobject permutation
"gsl_permutation"
((size :sizet))
"permutation"
:initialize-suffix "init")
;;; Need this because default the method defined by defmobject has c-return = :int.
(defmfun reinitialize-instance ((object permutation) &key)
"gsl_permutation_init"
(((mpointer object) :pointer))
:definition :method
:qualifier :after
:return (object)
:c-return :void
:export nil
:index (reinitialize-instance permutation))
(defun make-permutation (size &optional (initialize t))
;; Define this outside of defmobject in order to add the optional argument.
"Create the GSL object representing a permutation (class PERMUTATION)."
(let ((object (make-instance 'permutation :size size)))
(when initialize (reinitialize-instance object))
object))
(defmethod print-object ((object permutation) stream)
(print-unreadable-object (object stream :type t)
(princ (grid:contents object) stream)))
(format stream "size ~d contents ~a" (size object) (grid:contents object))))
;;;;****************************************************************************
;;;; Setting values
;;;; Setting/getting values
;;;;****************************************************************************
(defmfun set-identity ((permutation permutation))
"gsl_permutation_init"
(((mpointer permutation) :pointer))
:definition :method
:c-return :void
:outputs (permutation)
:return (permutation)
:documentation ; FDL
"Initialize the permutation p to the identity, i.e.
(0,1,2,...,n-1).")
(defmethod set-identity ((p permutation))
"Initialize the permutation p to the identity, i.e. (0,1,2,...,n-1)."
(reinitialize-instance p))
(defmfun perm-copy (source destination)
"gsl_permutation_memcpy"
......@@ -109,6 +93,12 @@
:documentation ; FDL
"Exchanges the ith and jth elements of the permutation p.")
(defmfun grid:aref ((p permutation) &rest indices)
"gsl_permutation_get"
(((mpointer p) :pointer) ((first indices) :sizet))
:definition :method
:c-return :sizet)
;;;;****************************************************************************
;;;; Permutation properties
;;;;****************************************************************************
......@@ -122,6 +112,9 @@
:documentation ; FDL
"The size of the permutation p.")
(defmethod grid:dimensions ((p permutation))
(list (size p)))
(defmfun permutation-data (p)
"gsl_permutation_data"
(((mpointer p) :pointer))
......@@ -226,8 +219,7 @@
:outputs (data)
:return (data)
:documentation ; FDL
"Apply the permutation p to the array data of
size n with stride stride.")
"Apply the permutation p to the array data of size n with stride stride.")
(defmfun permute-inverse
((p permutation) (v vector) &optional size stride)
......@@ -238,12 +230,7 @@
:outputs (v)
:return (v)
:documentation ; FDL
"Apply the permutation p to the elements of the
vector v considered as a row-vector acted on by a permutation
matrix from the right, v' = v P. The jth column of the
permutation matrix P is given by the p_j-th column of the
identity matrix. The permutation p and the vector v must
have the same length.")
"Apply the permutation p to the elements of the vector v considered as a row-vector acted on by a permutation matrix from the right, v' = v P. The jth column of the permutation matrix P is given by the p_j-th column of the identity matrix. The permutation p and the vector v must have the same length.")
(defmfun permute-inverse
(p (data #.grid:+foreign-pointer-class+) &optional (size 1) (stride 1))
......@@ -266,9 +253,7 @@
:outputs (p)
:return (p)
:documentation ; FDL
"Combine the two permutations pa and pb into a
single permutation p where p = pa . pb. The permutation
p is equivalent to applying pb first and then pa.")
"Combine the two permutations pa and pb into a single permutation p where p = pa . pb. The permutation p is equivalent to applying pb first and then pa.")
;;;;****************************************************************************
;;;; Permutations in cyclic form
......
;; GSL library version
;; Liam Healy 2016-08-06 10:37:52EDT gsl-version.lisp
;; Time-stamp: <2016-08-06 22:05:11EDT gsl-version.lisp>
;; Time-stamp: <2016-11-20 16:42:06CST gsl-version.lisp>
;;
;; Copyright 2016 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -26,19 +26,17 @@
"The version of the GSL library being used.")
(export '*gsl-version*)
(defun have-at-least-gsl-version (major-minor)
"The GSL version currently running is at least the specified major/minor version."
(or (null major-minor)
(let* ((sep-pos (position #\. *gsl-version*))
(my-major
(read-from-string *gsl-version* nil nil :end sep-pos))
(my-minor
(read-from-string *gsl-version* nil nil :start (1+ sep-pos))))
(and (>= my-major (first major-minor))
(>= my-minor (second major-minor))))))
)
(defun have-at-least-gsl-version (version-wanted)
"The GSL version currently running is at least the version wanted, specified as (major minor)."
(or (null version-wanted)
(let ((version-loaded
(mapcar 'read-from-string (split-sequence:split-sequence #\. *gsl-version*))))
;; subminor version number ignored
(or (> (first version-loaded) (first version-wanted))
(and
(= (first version-loaded) (first version-wanted))
(>= (second version-loaded) (second version-wanted)))))))
(when (have-at-least-gsl-version '(2 0))
(pushnew :gsl2 *features*)
;; Following form to be deleted when GSL 2 support is present
(error "GSLL does not currently work with GSL version 2.x"))
(when (have-at-least-gsl-version '(2 0))
(pushnew :gsl2 *features*))
)
;; Load GSL
;; Liam Healy Sat Mar 4 2006 - 18:53
;; Time-stamp: <2015-12-06 09:45:33EST init.lisp>
;; Time-stamp: <2016-11-20 14:46:05CST init.lisp>
;;
;; Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2015 Liam M. Healy
;; Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2015, 2016 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......@@ -100,7 +100,7 @@
(gsl-config-pathname "libgsl.dylib"))
#-ccl #.(gsl-config-pathname "libgsl.dylib"))
(:windows (:or "libgsl-0.dll" "cyggsl-0.dll"))
(:unix (:or "libgsl.so.0" "libgsl.so"))
(:unix (:or "libgsl.so.19" "libgsl.so.0" "libgsl.so"))
(t (:default "libgsl")))
(cffi:use-foreign-library libgsl)