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