GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
cmatm3.f
Go to the documentation of this file.
1 c Copyright (C) 2009-2021 The Octave Project Developers
2 c
3 c See the file COPYRIGHT.md in the top-level directory of this
4 c distribution or <https://octave.org/copyright/>.
5 c
6 c Octave is free software: you can redistribute it and/or modify it
7 c under the terms of the GNU General Public License as published by
8 c the Free Software Foundation, either version 3 of the License, or
9 c (at your option) any later version.
10 c
11 c Octave is distributed in the hope that it will be useful, but
12 c WITHOUT ANY WARRANTY; without even the implied warranty of
13 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 c GNU General Public License for more details.
15 c
16 c You should have received a copy of the GNU General Public License
17 c along with Octave; see the file COPYING. If not, see
18 c <https://www.gnu.org/licenses/>.
19 c
20  subroutine cmatm3(m,n,k,np,a,b,c)
21 c purpose: a 3-dimensional matrix product.
22 c given a (m,k,np) array a and (k,n,np) array b,
23 c calculates a (m,n,np) array c such that
24 c for i = 1:np
25 c c(:,:,i) = a(:,:,i) * b(:,:,i)
26 c
27 c arguments:
28 c m,n,k (in) the dimensions
29 c np (in) number of multiplications
30 c a (in) a complex input array, size (m,k,np)
31 c b (in) a complex input array, size (k,n,np)
32 c c (out) a complex output array, size (m,n,np)
33  integer m,n,k,np
34  complex a(m*k,np),b(k*n,np)
35  complex c(m*n,np)
36 
37  complex cdotu,one,zero
38  parameter(one = 1e0, zero = 0e0)
39  external cdotu,cgemv,cgemm
40  integer i
41 
42 c quick return if possible.
43  if (np <= 0) return
44 
45  if (m == 1) then
46  if (n == 1) then
47  do i = 1,np
48  c(1,i) = cdotu(k,a(1,i),1,b(1,i),1)
49  end do
50  else
51  do i = 1,np
52  call cgemv("T",k,n,one,b(1,i),k,a(1,i),1,zero,c(1,i),1)
53  end do
54  end if
55  else
56  if (n == 1) then
57  do i = 1,np
58  call cgemv("N",m,k,one,a(1,i),m,b(1,i),1,zero,c(1,i),1)
59  end do
60  else
61  do i = 1,np
62  call cgemm("N","N",m,n,k,
63  + one,a(1,i),m,b(1,i),k,zero,c(1,i),m)
64  end do
65  end if
66  end if
67 
68  end subroutine
subroutine cmatm3(m, n, k, np, a, b, c)
Definition: cmatm3.f:21