|
61 | 61 |
|
62 | 62 | (when (member var-type '(:cindex-width))
|
63 | 63 | (setf (getf sub-params :coordinate-width) width))
|
64 |
| - ;; these variable types impose a width limit on subordinate variables; |
65 |
| - ;; i.e. the sub-byte values of an integer must be half or less of |
66 |
| - ;; that integer's width |
| 64 | + ;; these variable types impose a width limit on subordinate |
| 65 | + ;; variables; i.e. the sub-byte values of an integer must |
| 66 | + ;; be half or less of that integer's width |
67 | 67 | (process-var-range
|
68 | 68 | form (cddr vars) sub-params
|
69 | 69 | (if (not (member var-type '(:lindex-width :eindex-width
|
|
81 | 81 | (setf ,@output)
|
82 | 82 | ,table))))
|
83 | 83 |
|
84 |
| -(defun indexer-section (inverse dims dimensions output-shorter span padding) |
| 84 | +(defun indexer-section (inverse dims output-shorter span padding) |
85 | 85 | "Return indices of an array sectioned as with the [↑ take] or [↓ drop] functions."
|
86 | 86 | ;; (print (list :is inverse dims dimensions output-shorter span padding))
|
87 | 87 | (let* ((scalar (not dims))
|
88 | 88 | (dims (or dims '(1)))
|
89 | 89 | (isize (reduce #'* dims)) (irank (length dims))
|
90 |
| - (rdiff (- irank (length dimensions))) |
91 | 90 | (idims (make-array irank :element-type (if (zerop isize) t (list 'integer 0 isize))
|
92 | 91 | :initial-contents dims))
|
93 |
| - ;; (odims (loop :for odim :across dimensions :for idim :across idims |
94 |
| - ;; :collect (if (not inverse) (abs odim) (- idim (abs odim))))) |
95 |
| - (odims (if (and span (not scalar)) |
96 |
| - (loop :for ix :below irank :for sp :across span |
97 |
| - :collect (+ (- sp) (aref span (+ ix irank)) |
98 |
| - (aref padding ix) |
99 |
| - (aref padding (+ ix irank)))) |
100 |
| - (loop :for odim :across dimensions :for idim :across idims |
101 |
| - :collect (if (not inverse) (abs odim) (- idim (abs odim)))))) |
| 92 | + (odims (loop :for ix :below irank :for sp :across span |
| 93 | + :collect (+ (- sp) (aref span (+ ix irank)) |
| 94 | + (aref padding ix) |
| 95 | + (aref padding (+ ix irank))))) |
102 | 96 | (osize (reduce #'* odims))
|
103 | 97 | (last-dim)
|
104 | 98 | (id-factors (make-array irank :element-type 'fixnum))
|
|
119 | 113 | ;; choose shorter path depending on whether input or output are larger, and
|
120 | 114 | ;; always iterate over output in the case of sub-7-bit arrays as this is necessary
|
121 | 115 | ;; to respect the segmentation of the elements
|
122 |
| - (lambda (i) |
| 116 | + (lambda (i) ;; x←4 5⍴⍳20 ⋄ (2 3↓x)←0 ⋄ x |
123 | 117 | (let ((oindex 0) (remaining i) (valid t))
|
124 | 118 | ;; calculate row-major offset for outer array dimensions
|
125 |
| - (loop :for i :from 0 :to (- irank 1) :while valid |
126 |
| - :for dim :across dimensions :for id :across idims :for od :in odims |
| 119 | + (loop :for i :below irank :while valid :for id :across idims :for od :in odims |
127 | 120 | :for ifactor :across id-factors :for ofactor :across od-factors
|
128 | 121 | :do (multiple-value-bind (index remainder) (floor remaining ifactor)
|
129 |
| - (let ((adj-index (- index (if inverse (if (> 0 dim) 0 dim) |
130 |
| - (if (< 0 dim) 0 (+ dim id)))))) |
| 122 | + (let ((adj-index (+ (if padding (aref padding i) 0) ;; TODO: OPTIMIZE, SLOW |
| 123 | + (- index (if span (aref span i) 0))))) |
131 | 124 | (setf valid (when (< -1 adj-index od)
|
132 | 125 | (incf oindex (* ofactor adj-index))
|
133 | 126 | (setq remaining remainder))))))
|
134 | 127 | (when valid oindex)))
|
135 | 128 | (lambda (i)
|
136 | 129 | (let ((iindex 0) (remaining i) (valid t))
|
137 | 130 | ;; calculate row-major offset for outer array dimensions
|
138 |
| - (loop :for i :from 0 :to (- irank 1) :while valid |
139 |
| - :for dim :across dimensions :for id :across idims :for od :in odims |
| 131 | + (loop :for i :below irank :while valid :for id :across idims |
140 | 132 | :for ifactor :across id-factors :for ofactor :across od-factors
|
141 | 133 | :do (multiple-value-bind (index remainder) (floor remaining ofactor)
|
142 |
| - (let ((adj-index (+ index (if inverse (if (> 0 dim) 0 dim) |
143 |
| - (if (< 0 dim) 0 (+ dim id))))) |
144 |
| - ;; (adj-index (- index (aref padding i))) |
145 |
| - ) |
146 |
| - ;; (print (list :sp index span padding id adj-index (+ irank i))) |
147 |
| - (setf valid (when ;; (< -1 adj-index (aref span (+ irank i))) |
148 |
| - (< -1 adj-index id) |
| 134 | + (let ((adj-index (+ (if span (aref span i) 0) ;; TODO: OPTIMIZE, SLOW |
| 135 | + (- index (if padding (aref padding i) 0))))) |
| 136 | + ;; (print (list :sp adj-index (- adj-index (aref padding i)) id (+ irank i) |
| 137 | + ;; span padding id (+ irank i) idims)) |
| 138 | + (setf valid (when (< -1 adj-index id) |
149 | 139 | (incf iindex (* ifactor adj-index))
|
150 | 140 | (setq remaining remainder))))))
|
151 | 141 | (when valid iindex))))))
|
152 | 142 |
|
153 | 143 | ;; (defun indexer-section (inverse dims dimensions output-shorter span padding)
|
154 | 144 | ;; "Return indices of an array sectioned as with the [↑ take] or [↓ drop] functions."
|
155 |
| -;; ;; (print (list :is inverse dims dimensions output-shorter)) |
156 |
| -;; (let* ((isize (reduce #'* dims)) (irank (length dims)) |
| 145 | +;; ;; (print (list :is inverse dims dimensions output-shorter span padding)) |
| 146 | +;; (let* ((scalar (not dims)) |
| 147 | +;; (dims (or dims '(1))) |
| 148 | +;; (isize (reduce #'* dims)) (irank (length dims)) |
157 | 149 | ;; (rdiff (- irank (length dimensions)))
|
158 | 150 | ;; (idims (make-array irank :element-type (if (zerop isize) t (list 'integer 0 isize))
|
159 | 151 | ;; :initial-contents dims))
|
160 | 152 | ;; ;; (odims (loop :for odim :across dimensions :for idim :across idims
|
161 | 153 | ;; ;; :collect (if (not inverse) (abs odim) (- idim (abs odim)))))
|
162 |
| -;; (odims (loop :for ix :below irank |
163 |
| -;; :collect (+ (aref span (+ ix irank)) |
164 |
| -;; (- (aref span ix)) |
165 |
| -;; (aref padding ix) |
166 |
| -;; (aref padding (+ ix irank))))) |
| 154 | +;; (odims (if (and span (not scalar)) |
| 155 | +;; (loop :for ix :below irank :for sp :across span |
| 156 | +;; :collect (+ (- sp) (aref span (+ ix irank)) |
| 157 | +;; (aref padding ix) |
| 158 | +;; (aref padding (+ ix irank)))) |
| 159 | +;; (loop :for odim :across dimensions :for idim :across idims |
| 160 | +;; :collect (if (not inverse) (abs odim) (- idim (abs odim)))))) |
167 | 161 | ;; (osize (reduce #'* odims))
|
168 | 162 | ;; (last-dim)
|
169 | 163 | ;; (id-factors (make-array irank :element-type 'fixnum))
|
|
179 | 173 | ;; :do (setf (aref od-factors (- irank 1 dx))
|
180 | 174 | ;; (if (zerop dx) 1 (* last-dim (aref od-factors (- irank dx))))
|
181 | 175 | ;; last-dim d))
|
182 |
| -;; ;; (print (list :pad span padding odims id-factors od-factors dimensions output-shorter)) |
| 176 | +;; ;; (print (list :pad odims irank dims span padding idims odims id-factors od-factors dimensions)) |
183 | 177 | ;; (if output-shorter
|
184 | 178 | ;; ;; choose shorter path depending on whether input or output are larger, and
|
185 | 179 | ;; ;; always iterate over output in the case of sub-7-bit arrays as this is necessary
|
186 | 180 | ;; ;; to respect the segmentation of the elements
|
187 | 181 | ;; (lambda (i)
|
188 | 182 | ;; (let ((oindex 0) (remaining i) (valid t))
|
189 | 183 | ;; ;; calculate row-major offset for outer array dimensions
|
190 |
| -;; (loop :for i :from 0 :to (1- irank) :while valid |
| 184 | +;; (loop :for i :below irank :while valid |
191 | 185 | ;; :for dim :across dimensions :for id :across idims :for od :in odims
|
192 | 186 | ;; :for ifactor :across id-factors :for ofactor :across od-factors
|
193 | 187 | ;; :do (multiple-value-bind (index remainder) (floor remaining ifactor)
|
194 |
| -;; (let (;; (adj-index (- index (if inverse (if (> 0 dim) 0 dim) |
195 |
| -;; ;; (if (< 0 dim) 0 (+ dim id))))) |
196 |
| -;; (adj-index (- index (aref padding i))) |
197 |
| -;; ) |
198 |
| -;; (setf valid (when (< -1 adj-index (aref span (+ irank i))) |
| 188 | +;; (let ((adj-index (- index (if inverse (if (> 0 dim) 0 dim) |
| 189 | +;; (if (< 0 dim) 0 (+ dim id)))))) |
| 190 | +;; (setf valid (when (< -1 adj-index od) |
199 | 191 | ;; (incf oindex (* ofactor adj-index))
|
200 | 192 | ;; (setq remaining remainder))))))
|
201 | 193 | ;; (when valid oindex)))
|
202 | 194 | ;; (lambda (i)
|
203 | 195 | ;; (let ((iindex 0) (remaining i) (valid t))
|
204 | 196 | ;; ;; calculate row-major offset for outer array dimensions
|
205 |
| -;; (loop :for i :from 0 :to (1- irank) :while valid |
| 197 | +;; (loop :for i :below irank :while valid |
206 | 198 | ;; :for dim :across dimensions :for id :across idims :for od :in odims
|
207 | 199 | ;; :for ifactor :across id-factors :for ofactor :across od-factors
|
208 | 200 | ;; :do (multiple-value-bind (index remainder) (floor remaining ofactor)
|
209 | 201 | ;; (let (;; (adj-index (+ index (if inverse (if (> 0 dim) 0 dim)
|
210 | 202 | ;; ;; (if (< 0 dim) 0 (+ dim id)))))
|
211 |
| -;; (adj-index (- index (aref padding i))) |
| 203 | +;; (adj-index (+ (if span (aref span i) 0) ;; TODO: OPTIMIZE, SLOW |
| 204 | +;; (- index (if padding (aref padding i) 0)))) |
212 | 205 | ;; )
|
213 |
| -;; ;; (print (list :adj adj-index)) |
214 |
| -;; (setf valid (when (< -1 adj-index (aref span (+ irank i))) |
215 |
| -;; ;; (< -1 adj-index id) |
| 206 | +;; ;; (print (list :sp index adj-index dim id span padding id (+ irank i) idims)) |
| 207 | +;; (setf valid (when ;; (< -1 adj-index (aref span (+ irank i))) |
| 208 | +;; (< -1 adj-index id) |
216 | 209 | ;; (incf iindex (* ifactor adj-index))
|
217 | 210 | ;; (setq remaining remainder))))))
|
218 | 211 | ;; (when valid iindex))))))
|
|
0 commit comments