Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_sparse_direct_real_gen_matmul (f11mk)

Purpose

nag_sparse_direct_real_gen_matmul (f11mk) computes a matrix-matrix or transposed matrix-matrix product involving a real, square, sparse nonsymmetric matrix stored in compressed column (Harwell–Boeing) format.

Syntax

[c, ifail] = f11mk(trans, alpha, icolzp, irowix, a, b, beta, c, 'n', n, 'm', m)
[c, ifail] = nag_sparse_direct_real_gen_matmul(trans, alpha, icolzp, irowix, a, b, beta, c, 'n', n, 'm', m)

Description

nag_sparse_direct_real_gen_matmul (f11mk) computes either the matrix-matrix product CαAB + βC$C←\alpha AB+\beta C$, or the transposed matrix-matrix product CαATB + βC$C←\alpha {A}^{\mathrm{T}}B+\beta C$, according to the value of the parameter trans, where A$A$ is a real n$n$ by n$n$ sparse nonsymmetric matrix, of arbitrary sparsity pattern with nnz$\mathit{nnz}$ nonzero elements, B$B$ and C$C$ are n$n$ by m$m$ real dense matrices. The matrix A$A$ is stored in compressed column (Harwell–Boeing) storage format. The array a stores all nonzero elements of A$A$, while arrays icolzp and irowix store the compressed column indices and row indices of A$A$ respectively.

None.

Parameters

Compulsory Input Parameters

1:     trans – string (length ≥ 1)
Specifies whether or not the matrix A$A$ is transposed.
trans = 'N'${\mathbf{trans}}=\text{'N'}$
αAB + βC$\alpha AB+\beta C$ is computed.
trans = 'T'${\mathbf{trans}}=\text{'T'}$
αATB + βC$\alpha {A}^{\mathrm{T}}B+\beta C$ is computed.
Constraint: trans = 'N'${\mathbf{trans}}=\text{'N'}$ or 'T'$\text{'T'}$.
2:     alpha – double scalar
α$\alpha$, the scalar factor in the matrix multiplication.
3:     icolzp( : $:$) – int64int32nag_int array
Note: the dimension of the array icolzp must be at least n + 1${\mathbf{n}}+1$.
icolzp(i)${\mathbf{icolzp}}\left(i\right)$ contains the index in A$A$ of the start of a new column. See Section [Compressed column storage (CCS) format] in the F11 Chapter Introduction.
4:     irowix( : $:$) – int64int32nag_int array
Note: the dimension of the array irowix must be at least icolzp(n + 1)1${\mathbf{icolzp}}\left({\mathbf{n}}+1\right)-1$, the number of nonzeros of the sparse matrix A$A$.
The row index array of sparse matrix A$A$.
5:     a( : $:$) – double array
Note: the dimension of the array a must be at least icolzp(n + 1)1${\mathbf{icolzp}}\left({\mathbf{n}}+1\right)-1$, the number of nonzeros of the sparse matrix A$A$.
The array of nonzero values in the sparse matrix A$A$.
6:     b(ldb, : $:$) – double array
The first dimension of the array b must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The n$n$ by m$m$ matrix B$B$.
7:     beta – double scalar
The scalar factor β$\beta$.
8:     c(ldc, : $:$) – double array
The first dimension of the array c must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The n$n$ by m$m$ matrix C$C$.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the arrays b, c. (An error is raised if these dimensions are not equal.)
n$n$, the order of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     m – int64int32nag_int scalar
Default: The second dimension of the arrays b, c. (An error is raised if these dimensions are not equal.)
m$m$, the number of columns of matrices B$B$ and C$C$.
Constraint: m0${\mathbf{m}}\ge 0$.

ldb ldc

Output Parameters

1:     c(ldc, : $:$) – double array
The first dimension of the array c will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array will be max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
ldcmax (1,n)$\mathit{ldc}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
C$C$ stores αAB + βC$\alpha AB+\beta C$ or αATB + βC$\alpha {A}^{\mathrm{T}}B+\beta C$ depending on the value of trans.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, trans ≠ 'N'${\mathbf{trans}}\ne \text{'N'}$ or 'T'$\text{'T'}$, or n < 0${\mathbf{n}}<0$, or m < 0${\mathbf{m}}<0$, or ldb < max (1,n)$\mathit{ldb}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or ldc < max (1,n)$\mathit{ldc}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.

Not applicable.

None.

Example

function nag_sparse_direct_real_gen_matmul_example
alpha = 1;
beta = 0;
icolzp = [int64(1); 3; 5; 7; 9; 12];
irowix = [int64(1); 3; 1; 5; 2; 3; 2; 4; 3; 4; 5];
a = [2; 4; 1; -2; 1; 1; -1; 1; 1; 2; 3];
b = [0.7, 1.4;
0.16, 0.32;
0.52, 1.04;
0.77, 1.54;
0.28, 0.56];
c = [0, 0;
0, 0;
0, 0;
0, 0;
0, 0];

% Calculate matrix-matrix product
trans = 'N';
[c, ifail] = nag_sparse_direct_real_gen_matmul(trans, alpha, icolzp, irowix, a, b, beta, c);
fprintf('\nMatrix-matrix product:\n');
disp(c);

% Calculate transposed matrix-matrix product
trans = 'T';
[c, ifail] = nag_sparse_direct_real_gen_matmul(trans, alpha, icolzp, irowix, a, b, beta, c);
fprintf('\nTransposed matrix-matrix product:\n');
disp(c);

Matrix-matrix product:
1.5600    3.1200
-0.2500   -0.5000
3.6000    7.2000
1.3300    2.6600
0.5200    1.0400

Transposed matrix-matrix product:
3.4800    6.9600
0.1400    0.2800
0.6800    1.3600
0.6100    1.2200
2.9000    5.8000

function f11mk_example
alpha = 1;
beta = 0;
icolzp = [int64(1); 3; 5; 7; 9; 12];
irowix = [int64(1); 3; 1; 5; 2; 3; 2; 4; 3; 4; 5];
a = [2; 4; 1; -2; 1; 1; -1; 1; 1; 2; 3];
b = [0.7, 1.4;
0.16, 0.32;
0.52, 1.04;
0.77, 1.54;
0.28, 0.56];
c = [0, 0;
0, 0;
0, 0;
0, 0;
0, 0];

% Calculate matrix-matrix product
trans = 'N';
[c, ifail] = f11mk(trans, alpha, icolzp, irowix, a, b, beta, c);
fprintf('\nMatrix-matrix product:\n');
disp(c);

% Calculate transposed matrix-matrix product
trans = 'T';
[c, ifail] = f11mk(trans, alpha, icolzp, irowix, a, b, beta, c);
fprintf('\nTransposed matrix-matrix product:\n');
disp(c);

Matrix-matrix product:
1.5600    3.1200
-0.2500   -0.5000
3.6000    7.2000
1.3300    2.6600
0.5200    1.0400

Transposed matrix-matrix product:
3.4800    6.9600
0.1400    0.2800
0.6800    1.3600
0.6100    1.2200
2.9000    5.8000