Commit bb03e233 authored by Liam Healy's avatar Liam Healy

Define equal-dimension-pqgrid

parent ad6432e3
;; Objects that represent physical measurements.
;; Liam Healy Wed Mar 6 2002 - 09:04
;; Time-stamp: <2015-11-28 22:24:53EST physical-quantities.lisp>
;; Time-stamp: <2016-01-04 23:06:53EST physical-quantities.lisp>
;; Copyright 2011, 2012, 2013, 2014, 2015 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -124,18 +124,32 @@
((and (grid:gridp x) (grid:gridp y)
(or (not (scalar-dimension y)) (not (scalar-dimension x))))
;; All same units, possibly one has scalar dimension
(multiple-value-bind (they-are value)
(all-same ; repurposing 2nd return value
(concatenate
'list
(if (scalar-dimension x) (list (pq-dimension x)) (pq-dimension x))
(if (scalar-dimension y) (list (pq-dimension y)) (pq-dimension y)))
:test #'cl:equal)
(if they-are
(values they-are value)
(err-return))))
;; Note, dimension returned is for the last element in the grid.
(values
(equal-dimension-pqgrid x y errorp zeros-have-any-dimension match-dimensionless)
nil))
(t (err-return)))))
(defun equal-dimension-pqgrid
(grid0 grid1
&optional
(errorp t)
(zeros-have-any-dimension *zero-is-dimensionless*)
match-dimensionless)
;; 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
= (equal-dimension
(grid:aref* grid0 e0)
(grid:aref* grid1 e1)
errorp zeros-have-any-dimension match-dimensionless)
until (not answer)
finally (return answer))))
(defun dimel-or-not (object)
"Find the dimel for this object (a physical dimension quantity or a dimel), or
return the dimensionless dimel."
......
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