Commit 67cea885 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Fix and simplify pqval (physical-quantity) for non scalar-dimension

There was an error in #'pqval when the argument was a non scalar-dimension grid. This has been fixed by moving the binding of 'units into the then clause of the if (it wasn't used in the else clause anyway, and that's what caused the error). The units construction for non-scalar dimension makes use of grid:map-grid and is simpler.
parent f0e84bc2
;; Objects that represent physical measurements.
;; Liam Healy Wed Mar 6 2002 - 09:04
;; Time-stamp: <2013-03-24 20:48:50EDT physical-quantities.lisp>
;; Time-stamp: <2013-04-14 10:00:32EDT physical-quantities.lisp>
;; Copyright 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -198,26 +198,21 @@
(values pq nil nil)))
(defmethod pqval ((pq physical-quantity))
(let ((units
(pq-dimension pq)
(scalar-dimension pq))))
(if (scalar-dimension pq)
(if (scalar-dimension pq)
(let ((units (make-unit-sexp (pq-dimension pq) t)))
(antik:/ (pq-magnitude pq) (nth-value 1 (parse-unit-sexp units)))
;; Grid dimensions
;;(funcall (grid:elementwise ))
(loop with newmag = (grid:copy-to (pq-magnitude pq) (grid:gridp (pq-magnitude pq)))
with newdim = (grid:copy-to (pq-dimension pq) 'array)
for i from 0 below (grid:total-size pq)
(multiple-value-bind (mag dim)
(pqval (grid:aref* pq i))
(setf (grid:aref* newmag i) mag
(grid:aref* newdim i) dim))
finally (return (values newmag newdim nil))))))
:source pq
:destination-specification (grid:specification (pq-magnitude pq))
:element-function 'pqval)
:source (pq-dimension pq)
:destination-specification (grid:specification (pq-dimension pq))
:element-function (alexandria:rcurry 'make-unit-sexp t)))))
(defparameter *pqval-allsame-sequence-collapse* t
"If a sequence passed to pqval has all the same units,
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