function kronecker,A,B ;+ ;C=kronecker(A,B) is the Kronecker product of A with B. Array ;C has size na*nb X ma*mb, where A is of size na X nb and B is ;of size nb X mb. C is formed by "tiling". Tile [i,j] of C is ;a[i,j]B. ;- sa=size(A) sb=size(B) ta=size(A,/type) tb=size(B,/type) IF sa[0] GT 2 OR sb[0] GT 2 THEN MESSAGE,'ARRAYS MUST HAVE 2 OR FEWER DIMENSIONS' ;Set up the dimension coefficients. Default to ;A and B are scalars. na=1 & ma=1 & nb=1 & mb=1 ;Figure out the array dimensions. Need to handle ;1D and 2D cases. IF sa[0] EQ 1 THEN BEGIN na=sa[1] & ma=1L ENDIF ELSE IF sa[0] EQ 2 THEN BEGIN na=sa[1] & ma=sa[2] ENDIF IF sb[0] EQ 1 THEN BEGIN nb=sb[1] & mb=1L ENDIF ELSE IF sb[0] EQ 2 THEN BEGIN nb=sb[1] & mb=sb[2] ENDIF ;Set up an index array whose values trace through ;the indexes for an array of size B embedded in the ;array of size na*nb x ma*mb ib=lindgen(nb,mb) ib=(ib/nb)*na*nb+(ib mod nb) ;Construct an empty array C of the higher type of ta or tb. C=Make_Array(na*nb,ma*mb,TYPE=(ta>tb)) ;Set up an array ia of index values for the corners of the ;B arrays when tiling C with B. ia=lindgen(na,ma) ia=(ia/na)*na*nb*mb+(ia mod na)*nb ;Run through the indexes of ia, writing the array B multiplied ;by the components of the array A at each tile location. FOR k=0,na*ma-1 DO C[ia[k]+ib]=A[k]*B RETURN,C END