Re: Help on array multiplication



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

.



Relevant Pages

  • Re: Reshaping a vector into varying size lines
    ... Transpose your original character data stream so that the units ... Once you have the appropriately padded columns, reshape so that there ... transpose the result to get the display ...
    (comp.soft-sys.matlab)
  • Re: Quick problem: Matrix re-shaping
    ... I have a rotation matrix 'rot_mat' of dimensions 1122*3. ... I have tried to reshape the matrix using ... values in the first column of 'rot mat' and the second as values ...
    (comp.soft-sys.matlab)
  • Re: using cumsum
    ... thanks, however, the problem that I have is that reshape ... gives error since the dimensions are not compatible. ... I need to somehow add zeros to the original vector, ...
    (comp.soft-sys.matlab)
  • Re: Insert NaN to every line
    ... transpose / concat / reshape ... repmat / index ...
    (comp.soft-sys.matlab)
  • Re: import text file with hex values to matlab
    ... I know it sounds crazy but I tried that before and thid is the ... Product of known dimensions, 7, not divisible into total number of ... use %2X so that the matrix and reshape would work but than the result ...
    (comp.soft-sys.matlab)