Commit 141dbe9b authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Create grids from index/indices

Two new functions in new file grid/index-functions.lisp
    make-grid-from-index
    make-grid-sequential-elements
will create grids from the index or indices. The first one is general,
the second one creates elements as an affine transformation
(step/offset) of the indices. These functions are more general than
and replace the test-grid-double-float and offset-ifd which were
written for test grid generation.
parent 86671c4e
;; Tests of grid composition functions on foreign-array
;; Liam Healy 2009-11-28 17:12:53EST compose.lisp
;; Time-stamp: <2010-07-15 09:37:51EDT compose.lisp>
;; Time-stamp: <2013-12-28 11:00:56EST compose.lisp>
;;
;; Copyright 2009, 2010 Liam M. Healy
;; Copyright 2009, 2010, 2013 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
......@@ -27,10 +27,18 @@
(lisp-unit:define-test drop-fa
(lisp-unit:assert-numerical-equal
'(0.0d0 10.0d0 20.0d0 30.0d0 40.0d0)
(contents (drop (test-grid-double-float 'foreign-array '(5 1)))))
(contents (drop
(make-grid-sequential-elements
:dimensions '(5 1)
:grid-type 'foreign-array
:element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0)
(contents (drop (test-grid-double-float 'foreign-array '(1 5))))))
(contents (drop
(make-grid-sequential-elements
:dimensions '(1 5)
:grid-type 'foreign-array
:element-type 'double-float)))))
;;;;****************************************************************************
;;;; Subgrid
......@@ -39,28 +47,28 @@
(lisp-unit:define-test subgrid-fa
(lisp-unit:assert-numerical-equal
'(0.0d0 1.0d0 2.0d0 3.0d0)
(contents (row (test-grid-double-float 'foreign-array '(3 4)) 0)))
(contents (row (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 0)))
(lisp-unit:assert-numerical-equal
'(10.0d0 11.0d0 12.0d0 13.0d0)
(contents (row (test-grid-double-float 'foreign-array '(3 4)) 1)))
(contents (row (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 1)))
(lisp-unit:assert-numerical-equal
'(20.0d0 21.0d0 22.0d0 23.0d0)
(contents (row (test-grid-double-float 'foreign-array '(3 4)) 2)))
(contents (row (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 2)))
(lisp-unit:assert-numerical-equal
'(0.0d0 10.0d0 20.0d0)
(contents (column (test-grid-double-float 'foreign-array '(3 4)) 0)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 0)))
(lisp-unit:assert-numerical-equal
'(1.0d0 11.0d0 21.0d0)
(contents (column (test-grid-double-float 'foreign-array '(3 4)) 1)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 1)))
(lisp-unit:assert-numerical-equal
'(2.0d0 12.0d0 22.0d0)
(contents (column (test-grid-double-float 'foreign-array '(3 4)) 2)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 2)))
(lisp-unit:assert-numerical-equal
'(3.0d0 13.0d0 23.0d0)
(contents (column (test-grid-double-float 'foreign-array '(3 4)) 3)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) 3)))
(lisp-unit:assert-numerical-equal
'((12.0d0 13.0d0) (22.0d0 23.0d0))
(contents (subgrid (test-grid-double-float 'foreign-array '(3 4)) '(2 2) '(1 2)))))
(contents (subgrid (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) '(2 2) '(1 2)))))
(lisp-unit:define-test subgrid-setf-fa
(lisp-unit:assert-numerical-equal
......@@ -138,10 +146,13 @@
(lisp-unit:assert-numerical-equal
'((0.0d0 10.0d0 20.0d0) (1.0d0 11.0d0 21.0d0)
(2.0d0 12.0d0 22.0d0) (3.0d0 13.0d0 23.0d0))
(contents (transpose (test-grid-double-float 'foreign-array '(3 4)))))
(contents (transpose (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'((0.0d0 10.0d0 20.0d0 30.0d0 40.0d0))
(contents (transpose (test-grid-double-float 'foreign-array '(5 1)))))
(contents (transpose (make-grid-sequential-elements
:dimensions '(5 1)
:grid-type 'foreign-array
:element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'((0.0d0 10.0d0 20.0d0 0.0d0 0.0d0)
(1.0d0 11.0d0 21.0d0 0.0d0 0.0d0)
......@@ -149,7 +160,7 @@
(3.0d0 13.0d0 23.0d0 0.0d0 0.0d0)
(0.0d0 0.0d0 0.0d0 0.0d0 0.0d0))
(contents (transpose
(test-grid-double-float 'foreign-array '(3 4))
(make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float)
:destination
(make-array '(5 5) :element-type 'double-float :initial-element 0.0d0))))
(lisp-unit:assert-numerical-equal
......@@ -159,7 +170,7 @@
(0.0d0 2.0d0 12.0d0 22.0d0 0.0d0)
(0.0d0 3.0d0 13.0d0 23.0d0 0.0d0))
(contents (transpose
(test-grid-double-float 'foreign-array '(3 4))
(make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float)
:destination
(make-array '(5 5) :element-type 'double-float :initial-element 0.0d0)
:start '(1 1)))))
......@@ -171,22 +182,22 @@
(lisp-unit:define-test diagonal-fa
(lisp-unit:assert-numerical-equal
'(0.0d0 11.0d0 22.0d0)
(contents (diagonal (test-grid-double-float 'foreign-array '(3 4)))))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'(1.0d0 12.0d0 23.0d0)
(contents (diagonal (test-grid-double-float 'foreign-array '(3 4)) :offset 1)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) :offset 1)))
(lisp-unit:assert-numerical-equal
'(2.0d0 13.0d0)
(contents (diagonal (test-grid-double-float 'foreign-array '(3 4)) :offset 2)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) :offset 2)))
(lisp-unit:assert-numerical-equal
'(3.0d0)
(contents (diagonal (test-grid-double-float 'foreign-array '(3 4)) :offset 3)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) :offset 3)))
(lisp-unit:assert-numerical-equal
'(10.0d0 21.0d0)
(contents (diagonal (test-grid-double-float 'foreign-array '(3 4)) :offset -1)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) :offset -1)))
(lisp-unit:assert-numerical-equal
'(20.0d0)
(contents (diagonal (test-grid-double-float 'foreign-array '(3 4)) :offset -2)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float) :offset -2)))
(lisp-unit:assert-numerical-equal
'((1.0d0 0.0d0 0.0d0) (0.0d0 2.0d0 0.0d0) (0.0d0 0.0d0 3.0d0))
(let ((arr3x3 (make-grid '((foreign-array 3 3) double-float)
......@@ -216,18 +227,20 @@
(lisp-unit:assert-numerical-equal
'(-77.7d0 -77.7d0 -77.7d0 0.0d0 11.0d0 22.0d0)
(contents
(map-grid :source (test-grid-double-float 'foreign-array '(3 4))
:source-affi (affi:diagonal (affi (test-grid-double-float 'foreign-array '(3 4))))
:destination-affi (affi:make-affi '(6) 3)
:initial-element -77.7d0)))
(let ((source (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float)))
(map-grid :source source
:source-affi (affi:diagonal (affi source))
:destination-affi (affi:make-affi '(6) 3)
:initial-element -77.7d0))))
(lisp-unit:assert-numerical-equal
'(-77.7d0 -77.7d0 -77.7d0 -77.7d0 -66.7d0 -55.7d0)
(contents
(map-grid :source (test-grid-double-float 'foreign-array '(3 4))
:source-affi (affi:diagonal (affi (test-grid-double-float 'foreign-array '(3 4))))
:destination-affi (affi:make-affi '(6) 3)
:initial-element -77.7d0
:combination-function '+))))
(let ((source (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'foreign-array :element-type 'double-float)))
(map-grid :source source
:source-affi (affi:diagonal (affi source))
:destination-affi (affi:make-affi '(6) 3)
:initial-element -77.7d0
:combination-function '+)))))
;;;;****************************************************************************
;;;; Concatenate
......
;; Antik system definition
;; Liam Healy 2010-12-24 09:43:28EST antik.asd
;; Time-stamp: <2013-11-24 12:25:02EST grid.asd>
;; Time-stamp: <2013-12-25 16:00:14EST grid.asd>
;; Copyright 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -48,9 +48,7 @@
(:file "copy")
(:file "iterate" :depends-on ("compose"))
(:file "mathematics" :depends-on ("map"))
(:module tests
:components
((:file "grids")))))))
(:file "index-functions")))))
(asdf:defsystem-connection #:grid-tests
:serial t
......
;; Function to make grids based on functions of the indices
;; Liam Healy 2013-12-25 12:56:53EST index-functions.lisp
;; Time-stamp: <2013-12-28 11:09:32EST index-functions.lisp>
;; Copyright 2013 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
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :grid)
(export '(make-grid-from-index make-grid-sequential-elements))
;;; Needed:
;;; Tests with destination
;;; Tests without destination
;;; Documentation/examples
;;; Examples
;;; (make-grid-from-index (lambda (i j) (+ j (* 10 i))) :dimensions '(4 4))
;;; (make-grid-from-index (lambda (i) (+ 4 (* 3 i))))
;;; (make-grid-sequential-elements :dimensions '(4 4) :grid-type 'foreign-array)
;;; (make-grid-sequential-elements :dimensions '(4 4) :element-type '(signed-byte 64))
;;; (make-grid-sequential-elements :dimensions '(4 4) :grid-type 'array)
;;; (make-grid-sequential-elements :dimensions '(4 4) :grid-type 'array :element-type 'fixnum)
;;; #2A((0 1 2 3) (10 11 12 13) (20 21 22 23) (30 31 32 33))
(defun make-grid-from-index
(function
&key
destination
destination-specification
(grid-type *default-grid-type*)
(dimensions *default-dimensions*)
(element-type *default-element-type*))
"Make or set a grid from the index or indices. The function gets the indices as arguments, and returns a value that will become the element at that index."
(grid:map-grid
:source function
:destination-specification
(or destination-specification (make-specification grid-type dimensions element-type))
:destination destination))
(defun make-grid-sequential-elements
(&rest args &key (offset 0) (step-col 1) (step-row 10) &allow-other-keys)
"Create or set values in a grid with a value based on an affine transformation of the index or indices."
(apply
#'make-grid-from-index
(lambda (i &optional j)
(if j
(+ offset (* step-col j) (* step-row i))
(+ offset (* step-col i))))
(alexandria:remove-from-plist args :offset :step-col :step-row)))
;; Iterate
;; Norman Werner 2009-05-26 22:23:40EDT iterate.lisp
;; Time-stamp: <2013-06-23 22:46:42EDT iterate.lisp>
;; Time-stamp: <2013-12-25 15:40:34EST iterate.lisp>
;;
;; Copyright 2009, 2013 Norman Werner, Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -23,7 +23,7 @@
#|
As an example try:
(defparameter *array-3-4-double-float* (test-grid-double-float 'array '(3 4)))
(defparameter *array-3-4-double-float* (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float))
(iter:iter (iter:for e :matrix-element *array-3-4-double-float*)
(princ e) (princ " "))
......
;; Tests of grid composition functions
;; Liam Healy 2009-11-28 17:12:53EST compose.lisp
;; Time-stamp: <2010-07-15 09:41:17EDT compose.lisp>
;; Time-stamp: <2013-12-28 10:22:46EST compose.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Copyright 2009, 2010, 2013 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
......@@ -27,10 +27,16 @@
(lisp-unit:define-test drop
(lisp-unit:assert-numerical-equal
'(0.0d0 10.0d0 20.0d0 30.0d0 40.0d0)
(contents (drop (test-grid-double-float 'array '(5 1)))))
(contents (drop (make-grid-sequential-elements
:dimensions '(5 1)
:grid-type 'array
:element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0)
(contents (drop (test-grid-double-float 'array '(1 5))))))
(contents (drop (make-grid-sequential-elements
:dimensions '(1 5)
:grid-type 'array
:element-type 'double-float)))))
;;;;****************************************************************************
;;;; Subgrid
......@@ -39,28 +45,28 @@
(lisp-unit:define-test subgrid
(lisp-unit:assert-numerical-equal
'(0.0d0 1.0d0 2.0d0 3.0d0)
(contents (row (test-grid-double-float 'array '(3 4)) 0)))
(contents (row (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 0)))
(lisp-unit:assert-numerical-equal
'(10.0d0 11.0d0 12.0d0 13.0d0)
(contents (row (test-grid-double-float 'array '(3 4)) 1)))
(contents (row (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 1)))
(lisp-unit:assert-numerical-equal
'(20.0d0 21.0d0 22.0d0 23.0d0)
(contents (row (test-grid-double-float 'array '(3 4)) 2)))
(contents (row (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 2)))
(lisp-unit:assert-numerical-equal
'(0.0d0 10.0d0 20.0d0)
(contents (column (test-grid-double-float 'array '(3 4)) 0)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 0)))
(lisp-unit:assert-numerical-equal
'(1.0d0 11.0d0 21.0d0)
(contents (column (test-grid-double-float 'array '(3 4)) 1)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 1)))
(lisp-unit:assert-numerical-equal
'(2.0d0 12.0d0 22.0d0)
(contents (column (test-grid-double-float 'array '(3 4)) 2)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 2)))
(lisp-unit:assert-numerical-equal
'(3.0d0 13.0d0 23.0d0)
(contents (column (test-grid-double-float 'array '(3 4)) 3)))
(contents (column (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) 3)))
(lisp-unit:assert-numerical-equal
'((12.0d0 13.0d0) (22.0d0 23.0d0))
(contents (subgrid (test-grid-double-float 'array '(3 4)) '(2 2) '(1 2)))))
(contents (subgrid (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) '(2 2) '(1 2)))))
(lisp-unit:define-test subgrid-setf
(lisp-unit:assert-numerical-equal
......@@ -138,10 +144,13 @@
(lisp-unit:assert-numerical-equal
'((0.0d0 10.0d0 20.0d0) (1.0d0 11.0d0 21.0d0)
(2.0d0 12.0d0 22.0d0) (3.0d0 13.0d0 23.0d0))
(contents (transpose (test-grid-double-float 'array '(3 4)))))
(contents (transpose (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'((0.0d0 10.0d0 20.0d0 30.0d0 40.0d0))
(contents (transpose (test-grid-double-float 'array '(5 1)))))
(contents (transpose (make-grid-sequential-elements
:dimensions '(5 1)
:grid-type 'array
:element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'((0.0d0 10.0d0 20.0d0 0.0d0 0.0d0)
(1.0d0 11.0d0 21.0d0 0.0d0 0.0d0)
......@@ -149,7 +158,7 @@
(3.0d0 13.0d0 23.0d0 0.0d0 0.0d0)
(0.0d0 0.0d0 0.0d0 0.0d0 0.0d0))
(contents (transpose
(test-grid-double-float 'array '(3 4))
(make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
:destination
(make-array '(5 5) :element-type 'double-float :initial-element 0.0d0))))
(lisp-unit:assert-numerical-equal
......@@ -159,7 +168,7 @@
(0.0d0 2.0d0 12.0d0 22.0d0 0.0d0)
(0.0d0 3.0d0 13.0d0 23.0d0 0.0d0))
(contents (transpose
(test-grid-double-float 'array '(3 4))
(make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
:destination
(make-array '(5 5) :element-type 'double-float :initial-element 0.0d0)
:start '(1 1))))
......@@ -170,7 +179,7 @@
0.0d0 2.0d0 12.0d0 22.0d0 0.0d0 0.0d0 3.0d0 13.0d0 23.0d0
0.0d0 0.0d0 0.0d0 0.0d0 0.0d0 0.0d0 0.0d0))
(transpose
(test-grid-double-float 'array '(3 4))
(make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
:destination
(make-grid '((list 5) (list 5) double-float))))
#+(or) ; not yet ready for composite grids
......@@ -180,7 +189,7 @@
0.0d0 2.0d0 12.0d0 22.0d0 0.0d0 0.0d0 3.0d0 13.0d0 23.0d0
0.0d0 0.0d0 0.0d0 0.0d0 0.0d0 0.0d0 0.0d0))
(transpose
(test-grid-double-float 'array '(3 4))
(make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
:destination
(make-grid '((list 5) (array 5) double-float)))))
......@@ -191,22 +200,22 @@
(lisp-unit:define-test diagonal
(lisp-unit:assert-numerical-equal
'(0.0d0 11.0d0 22.0d0)
(contents (diagonal (test-grid-double-float 'array '(3 4)))))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float))))
(lisp-unit:assert-numerical-equal
'(1.0d0 12.0d0 23.0d0)
(contents (diagonal (test-grid-double-float 'array '(3 4)) :offset 1)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) :offset 1)))
(lisp-unit:assert-numerical-equal
'(2.0d0 13.0d0)
(contents (diagonal (test-grid-double-float 'array '(3 4)) :offset 2)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) :offset 2)))
(lisp-unit:assert-numerical-equal
'(3.0d0)
(contents (diagonal (test-grid-double-float 'array '(3 4)) :offset 3)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) :offset 3)))
(lisp-unit:assert-numerical-equal
'(10.0d0 21.0d0)
(contents (diagonal (test-grid-double-float 'array '(3 4)) :offset -1)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) :offset -1)))
(lisp-unit:assert-numerical-equal
'(20.0d0)
(contents (diagonal (test-grid-double-float 'array '(3 4)) :offset -2)))
(contents (diagonal (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float) :offset -2)))
(lisp-unit:assert-numerical-equal
'((1.0d0 0.0d0 0.0d0) (0.0d0 2.0d0 0.0d0) (0.0d0 0.0d0 3.0d0))
(let ((arr3x3 (make-grid '((array 3 3) double-float)
......@@ -236,15 +245,15 @@
(lisp-unit:assert-numerical-equal
'(-77.7d0 -77.7d0 -77.7d0 0.0d0 11.0d0 22.0d0)
(contents
(map-grid :source (test-grid-double-float 'array '(3 4))
:source-affi (affi:diagonal (affi (test-grid-double-float 'array '(3 4))))
(map-grid :source (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
:source-affi (affi:diagonal (affi (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)))
:destination-affi (affi:make-affi '(6) 3)
:initial-element -77.7d0)))
(lisp-unit:assert-numerical-equal
'(-77.7d0 -77.7d0 -77.7d0 -77.7d0 -66.7d0 -55.7d0)
(contents
(map-grid :source (test-grid-double-float 'array '(3 4))
:source-affi (affi:diagonal (affi (test-grid-double-float 'array '(3 4))))
(map-grid :source (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
:source-affi (affi:diagonal (affi (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)))
:destination-affi (affi:make-affi '(6) 3)
:initial-element -77.7d0
:combination-function '+))))
......@@ -262,20 +271,20 @@
(10.5d0 11.5d0 12.5d0 13.5d0))
(contents
(concatenate-grids
(map-grid :source 'index-fill-decadal
:destination-specification '((array 3 4) double-float))
(map-grid :source (offset-ifd 0.5d0)
:destination-specification '((array 2 4) double-float)))))
(make-grid-sequential-elements
:destination-specification '((array 3 4) double-float))
(make-grid-sequential-elements
:offset 0.5 :destination-specification '((array 2 4) double-float)))))
(lisp-unit:assert-numerical-equal
'((0.5d0 1.5d0 2.5d0 3.5d0 0.1d0 1.1d0)
(10.5d0 11.5d0 12.5d0 13.5d0 10.1d0 11.1d0)
(20.5d0 21.5d0 22.5d0 23.5d0 20.1d0 21.1d0))
(contents
(concatenate-grids
(map-grid :source (offset-ifd 0.5d0)
:destination-specification '((array 3 4) double-float))
(map-grid :source (offset-ifd 0.1d0)
:destination-specification '((array 3 2) double-float))
(make-grid-sequential-elements
:offset 0.5 :destination-specification '((array 3 4) double-float))
(make-grid-sequential-elements
:offset 0.1 :destination-specification '((array 3 2) double-float))
:axis 1)))
#+(or) ; not yet ready for composite grids
(lisp-unit:assert-numerical-equal
......@@ -284,8 +293,8 @@
13.5d0 10.1d0 11.1d0 20.5d0 21.5d0 22.5d0 23.5d0 20.1d0
21.1d0))
(concatenate-grids
(map-grid :source (offset-ifd 0.5d0)
:destination-specification '((array 3 4) double-float))
(map-grid :source (offset-ifd 0.1d0)
:destination-specification '((array 3 2) double-float))
(make-grid-sequential-elements
:offset 0.5 :destination-specification '((array 3 4) double-float))
(make-grid-sequential-elements
:offset 0.1 :destination-specification '((array 3 2) double-float))
:axis 1 :gtype-OBSOLETE '(list list double-float))))
;; Test grids
;; Liam Healy 2009-11-28 09:47:35EST grids.lisp
;; Time-stamp: <2013-11-27 10:51:06EST grids.lisp>
;;
;; Copyright 2009 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
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :grid)
(defun index-fill-decadal (&rest args)
"Element will be computed from the indices by multiplying
by powers of 10 and summing."
(loop with dims = (length args)
for i from 0 below dims
sum (* (expt 10 (- dims 1 i)) (the number (elt args i)))))
(defun offset-ifd (offset)
(lambda (&rest args) (+ offset (apply 'index-fill-decadal args))))
(defun test-grid-double-float
(type dimensions &optional (index-fill-function 'index-fill-decadal))
"Make a grid of the specified type and dimensions,
where the contents are computed by the index-fill-function."
(map-grid :source index-fill-function
:source-dims dimensions
:destination-specification
(make-specification type dimensions 'double-float)))
;; Test of map
;; Liam Healy 2010-01-01 12:51:51EST map.lisp
;; Time-stamp: <2010-07-18 00:33:55EDT map.lisp>
;; Time-stamp: <2013-12-28 10:03:20EST map.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Copyright 2010, 2013 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
......@@ -26,10 +26,11 @@
(10.4d0 12.4d0 14.4d0)
(20.4d0 22.4d0 24.4d0))
(let ((mat1
(map-grid :source (offset-ifd 0.1d0)
:destination-specification '((array 3 3) double-float)))
(vec (map-grid :source (offset-ifd 0.3d0)
:destination-specification '((array 3) double-float))))
(make-grid-sequential-elements
:offset 0.1d0 :destination-specification '((array 3 3) double-float)))
(vec
(make-grid-sequential-elements
:offset 0.3d0 :destination-specification '((array 3) double-float))))
(contents
(map-n-grids
:sources
......@@ -43,12 +44,13 @@
(20.3d0 33.4d0 48.5d0)
(40.3d0 63.4d0 88.5d0))
(let ((mat1
(map-grid :source (offset-ifd 0.1d0)
:destination-specification '((array 3 3) double-float)))
(mat2 (map-grid :source (offset-ifd 0.2d0)
:destination-specification '((array 3 3) double-float)))
(vec (map-grid :source '1+
:destination-specification '((array 3) double-float))))
(make-grid-sequential-elements
:offset 0.1d0 :destination-specification '((array 3 3) double-float)))
(mat2
(make-grid-sequential-elements
:offset 0.2d0 :destination-specification '((array 3 3) double-float)))
(vec (make-grid-sequential-elements
:offset 1 :destination-specification '((array 3) double-float))))
(contents
(map-n-grids
:sources
......
;; Tests of slice
;; Liam Healy 2009-12-05 20:25:35EST slice.lisp
;; Time-stamp: <2010-06-20 11:08:51EDT slice.lisp>
;; Time-stamp: <2013-12-25 15:45:33EST slice.lisp>
;;
;; Copyright 2009 Liam M. Healy
;; Copyright 2009, 2010, 2013 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
......@@ -24,34 +24,34 @@
(lisp-unit:assert-numerical-equal
'((10.0d0 11.0d0 12.0d0))
(contents
(slice (test-grid-double-float 'array '(3 4))
(slice (make-grid-sequential-elements :dimensions '(3 4) :grid-type 'array :element-type 'double-float)
'(1 (:range 0 2)) :drop nil)))
(lisp-unit:assert-numerical-equal
'(10.0d0 11.0d0 12.0d0)
(contents
(slice (test-grid-double-float 'array '(3 4))