Re: Help on array multiplication
- From: "shuisheng" <shuisheng75@xxxxxxxxx>
- Date: 13 Feb 2006 22:35:47 -0800
Thank you for your reply. Would you explain a little more about your
code?
nmat seems to be the number of dimensions.
a_evec seems to be a matrix (2-D)
v and r seem to be vectors
Are they right? You idea looks good. How to use it on my case?
Thanks again!
Tian
Ron Shepard 写道:
In article <1139870215.672032.141190@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"shuisheng" <shuisheng75@xxxxxxxxx> wrote:
Dear All,
I have a challenging problem need you help.
Given two arrays A and B: A is 3D with size NxNxN, B is 2D with size
NxN, looking for a fast method ot calculate three 3D arrays C, D, E.
Here C(:,:,k) is the matrix mulplication of A(:,:,k)*B for each k;
D(:,,j,:) is the matrix mulplication of A(:,,j,:)*B for each j;
E(i,:,:) is the matrix mulplication of A(i,:,:)*B for each i;
Any library (such as Lapack) can be used.
This is similar to doing tensor products. Below is some code I
wrote once to do this:
do i = nmat, 1, -1 ! loop over the individual matrices in
reverse order.
! The transpose in the following statements is equivalent
to a cyclic permutation o
f the indices.
v(:) = reshape( transpose( matmul( transpose(a_evec),
reshape( v, shape=ishape2 ) )
), shape=ishape1 )
r(:) = reshape( transpose( matmul( transpose(a_evec),
reshape( r, shape=ishape2 ) )
), shape=ishape1 )
enddo ! after nmat cycles, the indices are returned back to
the original order.
Your operations are similar to this. If you do things in the
straightforward way, you will get the right number of arithmetic
operations. The only reason to do the transpose is to get faster
performance for the dense matrix-matrix product operation, and this
will only occur for matrix dimensions above some threshold size.
Below this size, the straightforward way is best. I used the f90
intrinsic MATMUL() above, but on many machines a DGEMM() call would
be faster.
$.02 -Ron Shepard
.
- Follow-Ups:
- Re: Help on array multiplication
- From: Ron Shepard
- Re: Help on array multiplication
- References:
- Help on array multiplication
- From: shuisheng
- Re: Help on array multiplication
- From: Ron Shepard
- Help on array multiplication
- Prev by Date: Re: Help on array multiplication
- Next by Date: Re: Help on array multiplication
- Previous by thread: Re: Help on array multiplication
- Next by thread: Re: Help on array multiplication
- Index(es):
Relevant Pages
|