Commit ec0b14d7 authored by Liam M. Healy's avatar Liam M. Healy

Sum of two pq grids

Fixes error encountered when columns from a dimensioned matrix with
zeros are added. Included new test in grid-array-units to test for the
parent 9a02ccbd
;; Objects that represent physical measurements.
;; Liam Healy Wed Mar 6 2002 - 09:04
;; Time-stamp: <2017-10-15 23:09:10EDT physical-quantities.lisp>
;; Time-stamp: <2017-11-23 19:09:19EST physical-quantities.lisp>
;; Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -125,31 +125,32 @@
(or (not (scalar-dimension y)) (not (scalar-dimension x))))
;; All same units, possibly one has scalar dimension
;; Note, dimension returned is for the last element in the grid.
(equal-dimension-pqgrid x y errorp zeros-have-any-dimension match-dimensionless)
(equal-dimension-pqgrid x y errorp zeros-have-any-dimension match-dimensionless))
(t (err-return)))))
(defun equal-dimension-pqgrid
"If each of the corresponding elements of the grid have equal dimensions, return the last dimel, otherwise NIL."
(grid0 grid1
(errorp t)
(zeros-have-any-dimension *zero-is-dimensionless*)
"If the two pqgrids have equal dimension, return the dimel and nil (not scalar dim)."
;; Cribbed from grid:inner for scalar cumulation
(let ((w0 (affi:make-walker (grid::affi grid0)))
(w1 (affi:make-walker (grid::affi grid1))))
(loop for e0 = (funcall w0)
for e1 = (funcall w1)
while (and e0 e1)
for answer
for eqdim
= (equal-dimension
(grid:aref* grid0 e0)
(grid:aref* grid1 e1)
errorp zeros-have-any-dimension match-dimensionless)
until (not answer)
finally (return answer))))
collect eqdim into result-dims
while eqdim
finally (if eqdim
(return (values (cl:coerce result-dims 'vector) nil))
(return (values nil nil))))))
(defun dimel-or-not (object)
"Find the dimel for this object (a physical dimension quantity or a dimel), or
;; Tests of physical quantities
;; Liam Healy 2011-01-09 17:38:41EST tests.lisp
;; Time-stamp: <2017-10-14 17:11:21EDT physical-quantities-grid.lisp>
;; Time-stamp: <2017-11-23 22:44:41EST physical-quantities-grid.lisp>
;; Copyright 2011, 2013, 2014, 2015, 2017 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -138,7 +138,7 @@
:initial-contents '((#_1_km #_2_km #_3_sec) (#_1_m #_2_m #_88_sec)))
'double-float :dimensions '(2 3)
:initial-contents '((1000.0d0 2000.0d0 3.0d0) (1.0d0 2.0d0 88.0d0)))
:initial-contents '((1000.0d0 2000.0d0 3.0d0) (1.0d0 2.0d0 88.0d0)))
#2A((meter meter second) (meter meter second))))
;; Concatenate grids, array
......@@ -162,8 +162,20 @@
:dimensions '(4)
:initial-contents '(1.0d0 2.0d0 3.0d0 4.0d0))
#(meter meter second second)))
;; See [[id:39fe9321-7260-4335-bb3e-735ba1d00e43][Alternative approach to mixed/scalar pq-grid]]
;; I'd really like to have a better test than the overall type, but assert-equal won't match on the actual object.
;; Anyway the major problem was this would get an error, so this test at least checks for that.
(let* ((grid:*default-grid-type* 'grid:foreign-array)
(grid:grid 0.0 0.0 1000.0)
(grid:grid 0.0 -700.0 -800.0)
(grid:grid 0.0 900.0 500.0))
(grid:specification (+ (grid:column ex73 0) (grid:column ex73 1))))))
;;; Things that should be made to work.
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