[plt-scheme] build-vector avoids sharing problem + tensor algebras

From: Bill Richter (richter at math.northwestern.edu)
Date: Thu Feb 6 00:45:03 EST 2003

   From: "Richard C. Cobbe" <cobbe at ccs.neu.edu>
   
   However, you may not necessarily need to use side effects to
   initialize your arrays.  If you can write an expression that
   computes the value for location (i,j) from i and j, why not simply
   use this in a nested build-vector?  Something like the following:
   
   (build-vector 50 
                 (lambda (i) 
                   (build-vector 50
                                 (lambda (j)
                                   (compute-element i j)))))
   
   Here, compute-element may be your B(i,j); I didn't find the description
   above very clear on this point.
   
My B(i,j) will be the value of your (compute-element i j).

The problem is that (compute-element i j) needs to reference all
earlier elements of the 2-d array.  So if you had written

(define Big-Matrix   (build-vector 50 .... ))

Then (compute-element i j) needs to call

(vector-ref (vector-ref Big-Matrix a) b)

For b < j and also (a, b) = (i-1, j)

That is, (compute-element i j) needs the value of earlier
(compute-element a b).

-- 
Bill 
<http://www.math.nwu.edu/~richter>




Posted on the users mailing list.