comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: kronecker product
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: kronecker product [message #78612 is a reply to message #78583] Tue, 06 December 2011 06:31 Go to previous messageGo to previous message
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Dec 6, 2:18 am, Ecaterina Coman <ecatc...@umbc.edu> wrote:
> Hey guys,
> I have two sparse arrays in IDL that I want to compute the kronecker
> product with. I've googled like a crazy person but can't find anything
> useful. Does IDL had any routines that I can use to get the krokecker
> product of these two sparse arrays?
> Thanks.

This straightforward implementation should work. It is probably
possible to optimize it.

function kroneckerProduct, A, B
;+
;
; Kronecker tensor product of A and B.
; Result is a large matrix formed by taking all
; possible products between the elements of A and those of B.
;
; Input: A - (a x b) matrix
; B - (c x d) matrix
;
; Output: C - (ac x bd) matrix
;
; C =
; A(0 , 0) B A( 0, 1) B ... A( 0, n-1) B
; A(1 , 0) B A( 1, 1) B ... A( 1, n-1) B
; : : : :
; A(m-1, 0) B A(m-1, 1) B ... A(m-1, n-1) B
;
; Written by Yngvar Larsen <yngvar.larsen@norut.no>
; 2004-07-01
;
; Fixed type bug. Let IDL do the type inference:
; Now returns array of type 'size(A[0]*B[0], /type)'.
; YL 2005-01-13
;-

sizeA = size(A, /dimensions)
sizeB = size(B, /dimensions)
if n_elements(sizeA) eq 1 then sizeA = [sizeA, 1]
if n_elements(sizeB) eq 1 then sizeB = [sizeB, 1]

C = make_array(sizeA[0]*sizeB[0], sizeA[1]*sizeB[1], $
type=size(A[0]*B[0], /type))

for x=0L,sizeA[0]-1 do begin
ix = x*sizeB[0]
for y=0L,sizeA[1]-1 do C[ix,y*sizeB[1]] = A[x,y]*B
endfor

return, C
end

--
Yngvar
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Plot
Next Topic: The best way to bin data to a grid? (may not be an IDL-specific question)

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Dec 03 00:14:52 PST 2025

Total time taken to generate the page: 0.00253 seconds