hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_sparse_direct_real_gen_matmul (f11mk)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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, or the transposed matrix-matrix product CαATB + βC, according to the value of the argument trans, where A is a real n by n sparse nonsymmetric matrix, of arbitrary sparsity pattern with nnz nonzero elements, B and C are n by m real dense matrices. The matrix A is stored in compressed column (Harwell–Boeing) storage format. The array a stores all nonzero elements of A, while arrays icolzp and irowix store the compressed column indices and row indices of A respectively.

References

None.

Parameters

Compulsory Input Parameters

1:     trans – string (length ≥ 1)
Specifies whether or not the matrix A is transposed.
trans='N'
αAB+βC is computed.
trans='T'
αATB+βC is computed.
Constraint: trans='N' or 'T'.
2:     alpha – double scalar
α, the scalar factor in the matrix multiplication.
3:     icolzp: int64int32nag_int array
The dimension of the array icolzp must be at least n+1
icolzpi contains the index in A of the start of a new column. See Compressed column storage (CCS) format in the F11 Chapter Introduction.
4:     irowix: int64int32nag_int array
The dimension of the array irowix must be at least icolzpn+1-1, the number of nonzeros of the sparse matrix A
The row index array of sparse matrix A.
5:     a: – double array
The dimension of the array a must be at least icolzpn+1-1, the number of nonzeros of the sparse matrix A
The array of nonzero values in the sparse matrix A.
6:     bldb: – double array
The first dimension of the array b must be at least max1,n.
The second dimension of the array b must be at least max1,m.
The n by m matrix B.
7:     beta – double scalar
The scalar factor β.
8:     cldc: – double array
The first dimension of the array c must be at least max1,n.
The second dimension of the array c must be at least max1,m.
The n by m matrix 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, the order of the matrix A.
Constraint: n0.
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, the number of columns of matrices B and C.
Constraint: m0.

Output Parameters

1:     cldc: – double array
The first dimension of the array c will be max1,n.
The second dimension of the array c will be max1,m.
C stores αAB+βC or αATB +βC depending on the value of trans.
2:     ifail int64int32nag_int scalar
ifail=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
Constraint: ldbmax1,n.
Constraint: ldcmax1,n.
Constraint: m0.
Constraint: n0.
On entry, trans=_.
Constraint: trans='N' or 'T'.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

This example reads in a sparse matrix A and a dense matrix B. It then calls nag_sparse_direct_real_gen_matmul (f11mk) to compute the matrix-matrix product C=AB and the transposed matrix-matrix product C=ATB, where
A= 2.00 1.00 0 0 0 0 0 1.00 -1.00 0 4.00 0 1.00 0 1.00 0 0 0 1.00 2.00 0 -2.00 0 0 3.00   and  B= 0.70 1.40 0.16 0.32 0.52 1.04 0.77 1.54 0.28 0.56 .  
function f11mk_example


fprintf('f11mk example results\n\n');

% Form C = AB and C = A^TB, for sparse A.

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.70, 1.40;
     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];

alpha = 1;
beta  = 0;

% Calculate matrix-matrix product
trans = 'N';
[c, ifail] = f11mk( ...
                    trans, alpha, icolzp, irowix, a, b, beta, c);
fprintf('Matrix-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);


f11mk example results

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


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015