|
34 | 34 | "The prototype representation of an item is returned by the (apl-array-prototype) function."
|
35 | 35 | (if (and (arrayp item)
|
36 | 36 | (array-displacement item)
|
| 37 | + (vectorp (array-displacement item)) |
37 | 38 | (listp (aref (array-displacement item) 0))
|
38 | 39 | (member :empty-array-prototype (aref (array-displacement item) 0)))
|
| 40 | + ;; if an empty array prototype has been stored, retrieve it |
39 | 41 | (getf (aref (array-displacement item) 0) :empty-array-prototype)
|
40 | 42 | (apl-array-prototype item)))
|
41 | 43 |
|
|
89 | 91 | (if (= 0 (array-rank array))
|
90 | 92 | array (if (= 0 (array-total-size array))
|
91 | 93 | (prototype-of array)
|
92 |
| - (lambda (index) (row-major-aref array index))))) |
| 94 | + (lambda (index) |
| 95 | + (row-major-aref array index))))) |
93 | 96 |
|
94 | 97 | (defmethod render ((item t))
|
95 | 98 | item)
|
96 | 99 |
|
97 | 100 | (defmethod render ((varray varray))
|
| 101 | + ;; (print :abc) |
| 102 | + ;; (print (list :ss (shape-of varray) |
| 103 | + ;; (prototype-of varray))) |
98 | 104 | (let ((output-shape (shape-of varray))
|
| 105 | + (prototype (prototype-of varray)) |
99 | 106 | (indexer (indexer-of varray)))
|
100 | 107 | (if output-shape
|
101 | 108 | (if (zerop (reduce #'* output-shape))
|
|
108 | 115 | (make-array (shape-of varray) :element-type (assign-element-type
|
109 | 116 | this-prototype)))))
|
110 | 117 | output))
|
111 |
| - (let ((output (make-array (shape-of varray) :element-type (etype-of varray)))) |
| 118 | + (let ((output (make-array (shape-of varray) :element-type (etype-of varray) |
| 119 | + ))) |
| 120 | + ;; (print (list :out output (etype-of varray))) |
112 | 121 | (dotimes (i (array-total-size output))
|
113 | 122 | (let ((indexed (funcall indexer i)))
|
114 |
| - (if indexed (setf (row-major-aref output i) indexed)))) |
| 123 | + (if indexed (setf (row-major-aref output i) indexed) |
| 124 | + (setf (row-major-aref output i) prototype)))) |
115 | 125 | output))
|
116 | 126 | (funcall indexer 1))))
|
117 | 127 |
|
|
137 | 147 | ;; the default shape of a derived array is the same as its base array
|
138 | 148 | (defmethod prototype-of ((varray varray-derived))
|
139 | 149 | (if (varrayp (vader-base varray))
|
140 |
| - (apl-array-prototype (funcall (indexer-of (vader-base varray)) 0)) |
| 150 | + ;; (apl-array-prototype (funcall (indexer-of (vader-base varray)) 0)) |
| 151 | + (prototype-of (vader-base varray)) |
141 | 152 | (prototype-of (vader-base varray))))
|
142 | 153 |
|
143 | 154 | (defmethod shape-of ((varray varray-derived))
|
|
240 | 251 | nil (:documentation "A reshaped array as from the [⍴ reshape] function."))
|
241 | 252 |
|
242 | 253 | (defmethod prototype-of ((varray vader-reshape))
|
| 254 | + (shape-of (vader-base varray)) ;; must get shape so that base array can be rendered |
243 | 255 | (let ((indexer (indexer-of (vader-base varray))))
|
244 | 256 | ;; TODO: remove-disclose when [⍴ shape] is virtually implemented
|
245 | 257 | (aplesque::make-empty-array (disclose (if (not (functionp indexer))
|
|
251 | 263 | (get-or-assign-shape
|
252 | 264 | varray (let ((arg (setf (vads-argument varray)
|
253 | 265 | (render (vads-argument varray)))))
|
254 |
| - (if (vectorp arg) |
| 266 | + (if (typep arg 'sequence) |
255 | 267 | (coerce arg 'list)
|
256 | 268 | (list arg)))))
|
257 | 269 |
|
|
361 | 373 | (defclass vader-expand (varray-derived vad-on-axis vad-with-io vad-with-argument vad-invertable)
|
362 | 374 | nil (:documentation "An expanded (as from [\ expand]) or compressed (as from [/ compress]) array."))
|
363 | 375 |
|
364 |
| -(defmethod prototype-of ((varray vader-expand)) |
365 |
| - (let ((indexer (indexer-of (vader-base varray)))) |
366 |
| - ;; TODO: remove-disclose when [⍴ shape] is virtually implemented |
367 |
| - (aplesque::make-empty-array (disclose (if (not (functionp indexer)) |
368 |
| - indexer ;; ←← remove |
369 |
| - (funcall (indexer-of (vader-base varray)) 0)))))) |
| 376 | +;; (defmethod prototype-of ((varray vader-expand)) |
| 377 | +;; (call-next-method) |
| 378 | +;; ;; (prototype-of (vader-base varray)) |
| 379 | +;; ;; (let ((indexer (indexer-of (vader-base varray)))) |
| 380 | +;; ;; (print (list :vb (vader-base varray))) |
| 381 | +;; ;; ;; TODO: remove-disclose when [⍴ shape] is virtually implemented |
| 382 | +;; ;; (aplesque::make-empty-array (disclose (if (not (functionp indexer)) |
| 383 | +;; ;; indexer ;; ←← remove |
| 384 | +;; ;; (funcall (indexer-of (vader-base varray)) 0))))) |
| 385 | +;; ) |
370 | 386 |
|
371 | 387 | (defmethod shape-of ((varray vader-expand))
|
372 | 388 | "The shape of an expanded or compressed array."
|
|
377 | 393 | (degrees (setf (vads-argument varray)
|
378 | 394 | (funcall (lambda (i)
|
379 | 395 | (if (arrayp i)
|
380 |
| - i (vector i))) |
| 396 | + (if (< 0 (array-rank i)) |
| 397 | + i (vector (aref i))) |
| 398 | + (vector i))) |
381 | 399 | (render (vads-argument varray)))))
|
382 | 400 | (base-shape (copy-list (shape-of (vader-base varray))))
|
383 | 401 | (base-rank (length base-shape))
|
384 | 402 | (is-inverse (vads-inverse varray))
|
385 | 403 | (axis (setf (vads-axis varray)
|
386 |
| - (max 0 (- (if (eq :last (vads-axis varray)) |
387 |
| - base-rank (vads-axis varray)) |
388 |
| - (vads-io varray)))))) |
| 404 | + (max 0 (if (eq :last (vads-axis varray)) |
| 405 | + (1- base-rank) |
| 406 | + (- (vads-axis varray) |
| 407 | + (vads-io varray))))))) |
389 | 408 |
|
390 | 409 | ;; (print (list :br degrees-count is-inverse base-shape base-rank axis (vads-axis varray)
|
391 | 410 | ;; (vader-base varray)))
|
| 411 | + |
| 412 | + ;; (print (list :va (vads-argument varray))) |
| 413 | + |
| 414 | + ;; (print (list :deg degrees)) |
392 | 415 |
|
393 | 416 | (cond ((and base-shape (zerop (reduce #'* base-shape)))
|
394 | 417 | ;; (print :ee)
|
|
434 | 457 | (append (butlast base-shape) (list 0)))
|
435 | 458 | ((and (not base-shape)
|
436 | 459 | (not (arrayp degrees)))
|
437 |
| - ;; (print :gg) |
438 | 460 | (setf (vads-argument varray) (list (abs degrees))))
|
439 | 461 | ((and is-inverse base-shape degrees-count (< 1 degrees-count)
|
440 | 462 | (nth axis base-shape)
|
|
474 | 496 | :collect (if (/= index axis) dim (* 1 ex-dim)))))))))
|
475 | 497 |
|
476 | 498 | (defmethod indexer-of ((varray vader-expand))
|
477 |
| - (let ((base-indexer (indexer-of (vader-base varray))) |
478 |
| - (indexer (indexer-expand (coerce (vads-argument varray) 'vector) |
479 |
| - (shape-of (vader-base varray)) |
480 |
| - (vads-axis varray) |
481 |
| - (vads-inverse varray)))) |
| 499 | + ;; (Print (list :eeo (vads-argument varray) |
| 500 | + ;; (vader-base varray) |
| 501 | + ;; (shape-of (vader-base varray)) |
| 502 | + ;; (vads-axis varray) |
| 503 | + ;; (vads-inverse varray))) |
| 504 | + ;; (print (vads-argument varray)) |
| 505 | + (let* ((arg-vector (coerce (vads-argument varray) 'vector)) |
| 506 | + (base-indexer (indexer-of (vader-base varray))) |
| 507 | + (indexer (if (< 0 (length arg-vector)) |
| 508 | + (indexer-expand arg-vector (shape-of (vader-base varray)) |
| 509 | + (vads-axis varray) |
| 510 | + (vads-inverse varray))))) |
482 | 511 | ;; (PRINT (LIST :ss (shape-of varray)))
|
483 | 512 | (lambda (index)
|
484 | 513 | ;; (print (list :iin base-indexer (funcall indexer index) indexer))
|
|
488 | 517 | (let ((indexed (funcall indexer index)))
|
489 | 518 | (if indexed (funcall base-indexer indexed)))))))
|
490 | 519 |
|
491 |
| -;; (defclass vader-meta-scalar-pass (varray-derived) nil) |
492 |
| - |
493 | 520 | (defclass vader-turn (varray-derived vad-on-axis vad-with-io vad-with-argument)
|
494 | 521 | nil (:documentation "A rotated array as from the [⌽ rotate] function."))
|
495 | 522 |
|
|
0 commit comments