Changeset 39532 in project
- Timestamp:
- 01/27/21 05:44:35 (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/eggref/5/srfi-179
r39531 r39532 152 152 ==== Procedures 153 153 154 ===== translation? 154 155 <procedure>(translation? object)</procedure> 155 156 156 157 Returns {{#t}} if {{object}} is a translation, and {{#f}} otherwise. 157 158 159 ===== permutation? 158 160 <procedure>(permutation? object)</procedure> 159 161 … … 168 170 ==== Procedures 169 171 172 ===== make-interval 170 173 <procedure>(make-interval arg1 #!optional arg2)</procedure> 171 174 … … 179 182 for $0\leq i<{}${{(vector-length lower-bounds)}}. It is an error if {{lower-bounds}} and {{upper-bounds}} do not satisfy these conditions. 180 183 184 ===== interval? 181 185 <procedure>(interval? obj)</procedure> 182 186 183 187 Returns {{#t}} if {{obj}} is an interval, and {{#f}} otherwise. 184 188 189 ===== interval-dimension 185 190 <procedure>(interval-dimension interval)</procedure> 186 191 … … 190 195 then {{interval-dimension}} returns {{(vector-length lower-bounds)}}. It is an error to call {{interval-dimension}} if {{interval}} is not an interval. 191 196 197 ===== interval-lower-bound 192 198 <procedure>(interval-lower-bound interval i)</procedure> 193 199 200 ===== interval-upper-bound 194 201 <procedure>(interval-upper-bound interval i)</procedure> 195 202 … … 204 211 then {{interval-lower-bound}} returns {{(vector-ref lower-bounds i)}} and {{interval-upper-bound}} returns {{(vector-ref upper-bounds i)}}. It is an error to call {{interval-lower-bound}} or {{interval-upper-bound}} if {{interval}} and {{i}} do not satisfy these conditions. 205 212 213 ===== interval-lower-bounds->list 206 214 <procedure>(interval-lower-bounds->list interval)</procedure> 207 215 216 ===== interval-upper-bounds->list 208 217 <procedure>(interval-upper-bounds->list interval)</procedure> 209 218 … … 214 223 then {{interval-lower-bounds->list}} returns {{(vector->list lower-bounds)}} and {{interval-upper-bounds->list}} returns {{(vector->list upper-bounds)}}. It is an error to call {{interval-lower-bounds->list}} or {{interval-upper-bounds->list}} if {{interval}} does not satisfy these conditions. 215 224 225 ===== interval-lower-bounds->vector 216 226 <procedure>(interval-lower-bounds->vector interval)</procedure> 217 227 228 ===== interval-upper-bounds->vector 218 229 <procedure>(interval-upper-bounds->vector interval)</procedure> 219 230 … … 223 234 then {{interval-lower-bounds->vector}} returns a copy of {{lower-bounds}} and {{interval-upper-bounds->vector}} returns a copy of {{upper-bounds}}. It is an error to call {{interval-lower-bounds->vector}} or {{interval-upper-bounds->vector}} if {{interval}} does not satisfy these conditions. 224 235 236 ===== interval-volume 225 237 <procedure>(interval-volume interval)</procedure> 226 238 … … 233 245 It is an error to call {{interval-volume}} if {{interval}} does not satisfy this condition. 234 246 247 ===== interval= 235 248 <procedure>(interval= interval1 interval2)</procedure> 236 249 … … 246 259 It is an error to call {{interval=}} if {{interval1}} or {{interval2}} do not satisfy this condition. 247 260 261 ===== interval-subset? 248 262 <procedure>(interval-subset? interval1 interval2)</procedure> 249 263 … … 256 270 for all $0\leq j<d$, otherwise it returns {{#f}}. It is an error if the arguments do not satisfy these conditions. 257 271 272 ===== interval-contains-multi-index? 258 273 <procedure>(interval-contains-multi-index? interval index-0 index-1 ...)</procedure> 259 274 … … 266 281 It is an error to call {{interval-contains-multi-index?}} if {{interval}} and {{index-0}},..., do not satisfy this condition. 267 282 283 ===== interval-projections 268 284 <procedure>(interval-projections interval right-dimension)</procedure> 269 285 … … 303 319 It is an error to call {{interval-projections}} if its arguments do not satisfy these conditions. 304 320 321 ===== interval-for-each 305 322 <procedure>(interval-for-each f interval)</procedure> 306 323 … … 309 326 {{interval-for-each}} calls {{f}} with each multi-index of {{interval}} as arguments, all in lexicographical order. 310 327 328 ===== interval-dilate 311 329 <procedure>(interval-dilate interval lower-diffs upper-diffs)</procedure> 312 330 … … 330 348 (make-interval '#(100 100)) 331 349 '#(0 0) '#(-500 -50)) => error</enscript> 350 ===== interval-intersect 332 351 <procedure>(interval-intersect interval-1 interval-2 ...)</procedure> 333 352 … … 336 355 It is an error if the arguments are not all intervals with the same dimension. 337 356 357 ===== interval-translate 338 358 <procedure>(interval-translate interval translation)</procedure> 339 359 … … 342 362 One could define {{(interval-translate interval translation)}} by {{(interval-dilate interval translation translation)}}. 343 363 364 ===== interval-permute 344 365 <procedure>(interval-permute interval permutation)</procedure> 345 366 … … 352 373 For example, if the argument interval represents $[0,4)\times[0,8)\times[0,21)\times [0,16)$ and the permutation is {{#(3 0 1 2)}}, then the result of {{(interval-permute interval permutation)}} will be the representation of $[0,16)\times [0,4)\times[0,8)\times[0,21)$. 353 374 375 ===== interval-rotate 354 376 <procedure>(interval-rotate interval dim)</procedure> 355 377 … … 358 380 More precisely, {{(interval-rotate interval dim)}} assumes that {{interval}} is an interval and {{dim}} is an exact integer between 0 (inclusive) and {{(interval-dimension interval)}} (exclusive). It computes the permutation {{(vector dim ... (- (interval-dimension interval) 1) 0 ... (- dim 1))}} (unless {{dim}} is zero, in which case it constructs the identity permutation) and returns {{(interval-permute interval permutation)}}. It is an error if the arguments do not satisfy these conditions. 359 381 382 ===== interval-scale 360 383 <procedure>(interval-scale interval scales)</procedure> 361 384 … … 364 387 It is an error if {{interval}} and {{scales}} do not satisfy this condition. 365 388 389 ===== interval-cartesian-product 366 390 <procedure>(interval-cartesian-product interval . intervals)</procedure> 367 391 … … 378 402 ==== Procedures 379 403 404 ===== make-storage-class 380 405 <procedure>(make-storage-class getter setter checker maker copier length default)</procedure> 381 406 … … 392 417 Note that we assume that {{getter}} and {{setter}} generally take ''O''(1) time to execute. 393 418 419 ===== storage-class? 394 420 <procedure>(storage-class? m)</procedure> 395 421 396 422 Returns {{#t}} if {{m}} is a storage class, and {{#f}} otherwise. 397 423 424 ===== storage-class-getter 398 425 <procedure>(storage-class-getter m)</procedure> 399 426 427 ===== storage-class-setter 400 428 <procedure>(storage-class-setter m)</procedure> 401 429 430 ===== storage-class-checker 402 431 <procedure>(storage-class-checker m)</procedure> 403 432 433 ===== storage-class-maker 404 434 <procedure>(storage-class-maker m)</procedure> 405 435 436 ===== storage-class-copier 406 437 <procedure>(storage-class-copier m)</procedure> 407 438 439 ===== storage-class-length 408 440 <procedure>(storage-class-length m)</procedure> 409 441 442 ===== storage-class-default 410 443 <procedure>(storage-class-default m)</procedure> 411 444 … … 470 503 ==== Procedures 471 504 505 ===== make-array 472 506 <procedure>(make-array interval getter [ setter ])</procedure> 473 507 … … 542 576 (a_ 12345 6789) => 0. 543 577 (a_ 0 0) => 1.</enscript> 578 ===== array? 544 579 <procedure>(array? obj)</procedure> 545 580 546 581 Returns {{#t}} if {{obj}} is an array and {{#f}} otherwise. 547 582 583 ===== array-domain 548 584 <procedure>(array-domain array)</procedure> 549 585 586 ===== array-getter 550 587 <procedure>(array-getter array)</procedure> 551 588 … … 567 604 (a_ 2 3) => 0 568 605 (a_ 11 0) => is an error</enscript> 606 ===== array-dimension 569 607 <procedure>(array-dimension array)</procedure> 570 608 571 609 Shorthand for {{(interval-dimension (array-domain array))}}. It is an error to call this function if {{array}} is not an array. 572 610 611 ===== mutable-array? 573 612 <procedure>(mutable-array? obj)</procedure> 574 613 575 614 Returns {{#t}} if {{obj}} is a mutable array and {{#f}} otherwise. 576 615 616 ===== array-setter 577 617 <procedure>(array-setter array)</procedure> 578 618 … … 594 634 If {{bool}} is {{#t}} then the next call to {{specialized-array-default-mutable?}} will return {{#t}}; if {{bool}} is {{#f}} then the next call to {{specialized-array-default-mutable?}} will return {{#f}}; otherwise it is an error. 595 635 636 ===== make-specialized-array 596 637 <procedure>(make-specialized-array interval [ storage-class generic-storage-class ] [ safe? (specialized-array-default-safe?) ])</procedure> 597 638 … … 633 674 and then simply call, e.g., {{(make-u16-array (make-interval '#(3 3)))}}. 634 675 676 ===== specialized-array? 635 677 <procedure>(specialized-array? obj)</procedure> 636 678 637 679 Returns {{#t}} if {{obj}} is a specialized-array, and {{#f}} otherwise. A specialized-array is an array. 638 680 681 ===== array-storage-class 639 682 <procedure>(array-storage-class array)</procedure> 640 683 684 ===== array-indexer 641 685 <procedure>(array-indexer array)</procedure> 642 686 687 ===== array-body 643 688 <procedure>(array-body array)</procedure> 644 689 690 ===== array-safe? 645 691 <procedure>(array-safe? array)</procedure> 646 692 … … 655 701 It is an error to call any of these routines if {{array}} is not a specialized array. 656 702 703 ===== array-elements-in-order? 657 704 <procedure>(array-elements-in-order? A)</procedure> 658 705 … … 661 708 It is an error if {{A}} is not a specialized array. 662 709 710 ===== specialized-array-share 663 711 <procedure>(specialized-array-share array new-domain new-domain->old-domain)</procedure> 664 712 … … 710 758 This "shearing" operation cannot be achieved by combining the procedures {{array-extract}}, {{array-translate}}, {{array-permute}}, {{array-translate}}, {{array-curry}}, {{array-reverse}}, and {{array-sample}}. 711 759 760 ===== array-copy 712 761 <procedure>(array-copy array [ result-storage-class generic-storage-class ] [ new-domain #f ] [ mutable? (specialized-array-default-mutable?) ] [ safe? (specialized-array-default-safe?) ])</procedure> 713 762 … … 727 776 '''Note:''' If {{new-domain}} is not the same as {{(array-domain array)}}, one can think of the resulting array as a ''reshaped'' version of {{array}}. 728 777 778 ===== array-curry 729 779 <procedure>(array-curry array inner-dimension)</procedure> 730 780 … … 826 876 ((array-getter (curried-a_ 3)) 4) 827 877 => (3 4)</enscript> 878 ===== array-extract 828 879 <procedure>(array-extract array new-domain)</procedure> 829 880 … … 850 901 If {{array}} is a specialized array, the resulting array inherits its mutability and safety from {{array}}. 851 902 903 ===== array-tile 852 904 <procedure>(array-tile A S)</procedure> 853 905 … … 862 914 '''Note:''' The routines {{array-tile}} and {{array-curry}} both decompose an array into subarrays, but in different ways. For example, if {{A}} is defined as {{(make-array (make-interval '#(10 10)) list)}}, then {{(array-tile A '#(1 10))}} returns an array with domain {{(make-interval '#(10 1))}}, each element of which is an array with domain {{(make-interval '#(1 10))}} (i.e., a two-dimensional array whose elements are two-dimensional arrays), while {{(array-curry A 1)}} returns an array with domain {{(make-interval '#(10))}}, each element of which has domain {{(make-interval '#(10))}} (i.e., a one-dimensional array whose elements are one-dimensional arrays). 863 915 916 ===== array-translate 864 917 <procedure>(array-translate array translation)</procedure> 865 918 … … 910 963 It is an error if the arguments do not satisfy these conditions. 911 964 965 ===== array-permute 912 966 <procedure>(array-permute array permutation)</procedure> 913 967 … … 954 1008 It is an error to call {{array-permute}} if its arguments do not satisfy these conditions. 955 1009 1010 ===== array-rotate 956 1011 <procedure>(array-rotate array dim)</procedure> 957 1012 … … 960 1015 More precisely, {{(array-rotate array dim)}} assumes that {{array}} is an array and {{dim}} is an exact integer between 0 (inclusive) and {{(array-dimension array)}} (exclusive). It computes the permutation {{(vector dim ... (- (array-dimension array) 1) 0 ... (- dim 1))}} (unless {{dim}} is zero, in which case it constructs the identity permutation) and returns {{(array-permute array permutation)}}. It is an error if the arguments do not satisfy these conditions. 961 1016 1017 ===== array-reverse 962 1018 <procedure>(array-reverse array #!optional flip?)</procedure> 963 1019 … … 1042 1098 (palindrome? "abca") => #f 1043 1099 (palindrome? "abbc") => #f</enscript> 1100 ===== array-sample 1044 1101 <procedure>(array-sample array scales)</procedure> 1045 1102 … … 1081 1138 It is an error if {{array}} and {{scales}} don't satisfy these requirements. 1082 1139 1140 ===== array-outer-product 1083 1141 <procedure>(array-outer-product op array1 array2)</procedure> 1084 1142 … … 1098 1156 This implies that if {{(array-getter A)}} is expensive to compute (for example, if it's returning an array, as does {{array-curry}}) then the elements of {{A}} should be pre-computed if necessary and stored in a specialized array, typically using {{array-copy}}, before that specialized array is passed as an argument to {{array-outer-product}}. In the examples below, the code for Gaussian elimination applies {{array-outer-product}} to shared specialized arrays, which are of course themselves specialized arrays; the code for matrix multiplication and {{inner-product}} applies {{array-outer-product}} to curried arrays, so we apply {{array-copy}} to the arguments before passage to {{array-outer-product}}. 1099 1157 1158 ===== array-map 1100 1159 <procedure>(array-map f array . arrays)</procedure> 1101 1160 … … 1133 1192 (lambda (i) 1134 1193 (+ (a_ i) i))))</enscript> 1194 ===== array-for-each 1135 1195 <procedure>(array-for-each f array . arrays)</procedure> 1136 1196 … … 1159 1219 It is an error to call {{array-for-each}} if its arguments do not satisfy these conditions. 1160 1220 1221 ===== array-fold 1161 1222 <procedure>(array-fold kons knil array)</procedure> 1162 1223 … … 1173 1234 It is an error if {{array}} is not an array, or if {{kons}} is not a procedure. 1174 1235 1236 ===== array-fold-right 1175 1237 <procedure>(array-fold-right kons knil array)</procedure> 1176 1238 … … 1186 1248 It is an error if {{array}} is not an array, or if {{kons}} is not a procedure. 1187 1249 1250 ===== array-reduce 1188 1251 <procedure>(array-reduce op A)</procedure> 1189 1252 … … 1225 1288 Since $\pi^2/6\approx{}${{1.6449340668482264}}, we see using the first method that the difference $\pi^2/6-{}${{1.644934057834575}}${}\approx{}${{9.013651380840315e-9}} and with the second we have $\pi^2/6-{}${{1.6449340658482325}}${}\approx{}${{9.99993865491433e-10}}. The true difference should be between $\frac 1{1{,}000{,}000{,}001}\approx{}${{9.99999999e-10}} and $\frac 1{1{,}000{,}000{,}000}={}${{1e-9}}. The difference for the first method is about 10 times too big, and, in fact, will not change further because any further terms, when added to the partial sum, are too small to increase the sum after rounding-to-nearest in double-precision IEEE-754 floating-point arithmetic. 1226 1289 1290 ===== array-any 1227 1291 <procedure>(array-any pred array1 array2 ...)</procedure> 1228 1292 … … 1241 1305 It is an error if the arguments do not satisfy these assumptions. 1242 1306 1307 ===== array-every 1243 1308 <procedure>(array-every pred array1 array2 ...)</procedure> 1244 1309 … … 1257 1322 It is an error if the arguments do not satisfy these assumptions. 1258 1323 1324 ===== array->list 1259 1325 <procedure>(array->list array)</procedure> 1260 1326 … … 1263 1329 It is guaranteed that {{(array-getter array)}} is called precisely once for each multi-index in {{(array-domain array)}} in lexicographical order. 1264 1330 1331 ===== list->array 1265 1332 <procedure>(list->array l domain [ result-storage-class generic-storage-class ] [ mutable? (specialized-array-default-mutable?) ] [ safe? (specialized-array-default-safe?) ])</procedure> 1266 1333 … … 1271 1338 It is an error if the arguments do not satisfy these assumptions, or if any element of {{l}} cannot be stored in the body of {{result-storage-class}}, and this last error shall be detected and raised. 1272 1339 1340 ===== array-assign! 1273 1341 <procedure>(array-assign! destination source)</procedure> 1274 1342 … … 1285 1353 '''Note:''' If the domains of {{destination}} and {{source}} are not the same, one can think of {{destination}} as a ''reshaped'' copy of {{source}}. 1286 1354 1355 ===== array-ref 1287 1356 <procedure>(array-ref A i0 . i-tail)</procedure> 1288 1357 … … 1293 1362 It is an error if {{A}} is not an array, or if the number of arguments specified is not the correct number for {{(array-getter A)}}. 1294 1363 1364 ===== array-set! 1295 1365 <procedure>(array-set! A v i0 . i-tail)</procedure> 1296 1366 … … 1305 1375 '''Note:''' In the sample implementation, checking whether the multi-indices are exact integers and within the domain of the array, and checking whether the value is appropriate for storage into the array, is delegated to the underlying definition of the array argument. If the first argument is a safe specialized array, then these items are checked; if it is an unsafe specialized array, they are not. If it is a generalized array, it is up to the programmer whether to define the getter and setter of the array to check the correctness of the arguments. 1306 1376 1377 ===== specialized-array-reshape 1307 1378 <procedure>(specialized-array-reshape array new-domain [ copy-on-failure? #f ])</procedure> 1308 1379
Note: See TracChangeset
for help on using the changeset viewer.