# Changeset 39532 in project

Ignore:
Timestamp:
01/27/21 05:44:35 (5 weeks ago)
Message:

 r39531 ==== Procedures ===== translation? (translation? object) Returns {{#t}} if {{object}} is a translation, and {{#f}} otherwise. ===== permutation? (permutation? object) ==== Procedures ===== make-interval (make-interval arg1 #!optional arg2) for $0\leq i<{}${{(vector-length lower-bounds)}}. It is an error if {{lower-bounds}} and {{upper-bounds}} do not satisfy these conditions. ===== interval? (interval? obj) Returns {{#t}} if {{obj}} is an interval, and {{#f}} otherwise. ===== interval-dimension (interval-dimension interval) then {{interval-dimension}} returns {{(vector-length lower-bounds)}}. It is an error to call {{interval-dimension}} if {{interval}} is not an interval. ===== interval-lower-bound (interval-lower-bound interval i) ===== interval-upper-bound (interval-upper-bound interval i) 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. ===== interval-lower-bounds->list (interval-lower-bounds->list interval) ===== interval-upper-bounds->list (interval-upper-bounds->list interval) 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. ===== interval-lower-bounds->vector (interval-lower-bounds->vector interval) ===== interval-upper-bounds->vector (interval-upper-bounds->vector interval) 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. ===== interval-volume (interval-volume interval) It is an error to call {{interval-volume}} if {{interval}} does not satisfy this condition. ===== interval= (interval= interval1 interval2) It is an error to call {{interval=}} if {{interval1}} or {{interval2}} do not satisfy this condition. ===== interval-subset? (interval-subset? interval1 interval2) for all $0\leq j(interval-contains-multi-index? interval index-0 index-1 ...) It is an error to call {{interval-contains-multi-index?}} if {{interval}} and {{index-0}},..., do not satisfy this condition. ===== interval-projections (interval-projections interval right-dimension) It is an error to call {{interval-projections}} if its arguments do not satisfy these conditions. ===== interval-for-each (interval-for-each f interval) {{interval-for-each}} calls {{f}} with each multi-index of {{interval}} as arguments, all in lexicographical order. ===== interval-dilate (interval-dilate interval lower-diffs upper-diffs) (make-interval '#(100 100)) '#(0 0) '#(-500 -50)) => error ===== interval-intersect (interval-intersect interval-1 interval-2 ...) It is an error if the arguments are not all intervals with the same dimension. ===== interval-translate (interval-translate interval translation) One could define {{(interval-translate interval translation)}} by {{(interval-dilate interval translation translation)}}. ===== interval-permute (interval-permute interval permutation) 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)$. ===== interval-rotate (interval-rotate interval dim) 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. ===== interval-scale (interval-scale interval scales) It is an error if {{interval}} and {{scales}} do not satisfy this condition. ===== interval-cartesian-product (interval-cartesian-product interval . intervals) ==== Procedures ===== make-storage-class (make-storage-class getter setter checker maker copier length default) Note that we assume that {{getter}} and {{setter}} generally take ''O''(1) time to execute. ===== storage-class? (storage-class? m) Returns {{#t}} if {{m}} is a storage class, and {{#f}} otherwise. ===== storage-class-getter (storage-class-getter m) ===== storage-class-setter (storage-class-setter m) ===== storage-class-checker (storage-class-checker m) ===== storage-class-maker (storage-class-maker m) ===== storage-class-copier (storage-class-copier m) ===== storage-class-length (storage-class-length m) ===== storage-class-default (storage-class-default m) ==== Procedures ===== make-array (make-array interval getter [ setter ]) (a_ 12345 6789) => 0. (a_ 0 0) => 1. ===== array? (array? obj) Returns {{#t}} if {{obj}} is an array and {{#f}} otherwise. ===== array-domain (array-domain array) ===== array-getter (array-getter array) (a_ 2 3) => 0 (a_ 11 0) => is an error ===== array-dimension (array-dimension array) Shorthand for {{(interval-dimension (array-domain array))}}. It is an error to call this function if {{array}} is not an array. ===== mutable-array? (mutable-array? obj) Returns {{#t}} if {{obj}} is a mutable array and {{#f}} otherwise. ===== array-setter (array-setter array) 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. ===== make-specialized-array (make-specialized-array interval [ storage-class generic-storage-class ] [ safe? (specialized-array-default-safe?) ]) and then simply call, e.g., {{(make-u16-array (make-interval '#(3 3)))}}. ===== specialized-array? (specialized-array? obj) Returns {{#t}} if {{obj}} is a specialized-array, and {{#f}} otherwise. A specialized-array is an array. ===== array-storage-class (array-storage-class array) ===== array-indexer (array-indexer array) ===== array-body (array-body array) ===== array-safe? (array-safe? array) It is an error to call any of these routines if {{array}} is not a specialized array. ===== array-elements-in-order? (array-elements-in-order? A) It is an error if {{A}} is not a specialized array. ===== specialized-array-share (specialized-array-share array new-domain new-domain->old-domain) 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}}. ===== array-copy (array-copy array [ result-storage-class generic-storage-class ] [ new-domain #f ] [ mutable? (specialized-array-default-mutable?) ] [ safe? (specialized-array-default-safe?) ]) '''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}}. ===== array-curry (array-curry array inner-dimension) ((array-getter (curried-a_ 3)) 4) => (3 4) ===== array-extract (array-extract array new-domain) If {{array}} is a specialized array, the resulting array inherits its mutability and safety from {{array}}. ===== array-tile (array-tile A S) '''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). ===== array-translate (array-translate array translation) It is an error if the arguments do not satisfy these conditions. ===== array-permute (array-permute array permutation) It is an error to call {{array-permute}} if its arguments do not satisfy these conditions. ===== array-rotate (array-rotate array dim) 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. ===== array-reverse (array-reverse array #!optional flip?) (palindrome? "abca") => #f (palindrome? "abbc") => #f ===== array-sample (array-sample array scales) It is an error if {{array}} and {{scales}} don't satisfy these requirements. ===== array-outer-product (array-outer-product op array1 array2) 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}}. ===== array-map (array-map f array . arrays) (lambda (i) (+ (a_ i) i)))) ===== array-for-each (array-for-each f array . arrays) It is an error to call {{array-for-each}} if its arguments do not satisfy these conditions. ===== array-fold (array-fold kons knil array) It is an error if {{array}} is not an array, or if {{kons}} is not a procedure. ===== array-fold-right (array-fold-right kons knil array) It is an error if {{array}} is not an array, or if {{kons}} is not a procedure. ===== array-reduce (array-reduce op A) 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. ===== array-any (array-any pred array1 array2 ...) It is an error if the arguments do not satisfy these assumptions. ===== array-every (array-every pred array1 array2 ...) It is an error if the arguments do not satisfy these assumptions. ===== array->list (array->list array) It is guaranteed that {{(array-getter array)}} is called precisely once for each multi-index in {{(array-domain array)}} in lexicographical order. ===== list->array (list->array l domain [ result-storage-class generic-storage-class ] [ mutable? (specialized-array-default-mutable?) ] [ safe? (specialized-array-default-safe?) ]) 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. ===== array-assign! (array-assign! destination source) '''Note:''' If the domains of {{destination}} and {{source}} are not the same, one can think of {{destination}} as a ''reshaped'' copy of {{source}}. ===== array-ref (array-ref A i0 . i-tail) 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)}}. ===== array-set! (array-set! A v i0 . i-tail) '''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. ===== specialized-array-reshape (specialized-array-reshape array new-domain [ copy-on-failure? #f ])