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_real_symm_sort (f11zb)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_sparse_real_symm_sort (f11zb) sorts the nonzero elements of a real sparse symmetric matrix, represented in symmetric coordinate storage format.

Syntax

[nz, a, irow, icol, istr, ifail] = f11zb(n, nz, a, irow, icol, dup, zer)
[nz, a, irow, icol, istr, ifail] = nag_sparse_real_symm_sort(n, nz, a, irow, icol, dup, zer)

Description

nag_sparse_real_symm_sort (f11zb) takes a symmetric coordinate storage (SCS) representation (see Symmetric coordinate storage (SCS) format in the F11 Chapter Introduction) of a real n by n sparse symmetric matrix A, and reorders the nonzero elements by increasing row index and increasing column index within each row. Entries with duplicate row and column indices may be removed, or the values may be summed. Any entries with zero values may optionally be removed.
nag_sparse_real_symm_sort (f11zb) also returns a pointer istr to the starting address of each row in A.

References

None.

Parameters

Compulsory Input Parameters

1:     n int64int32nag_int scalar
n, the order of the matrix A.
Constraint: n1.
2:     nz int64int32nag_int scalar
The number of nonzero elements in the lower triangular part of the matrix A.
Constraint: nz0.
3:     a: – double array
The dimension of the array a must be at least max1,nz
The nonzero elements of the lower triangular part of the real matrix A. These may be in any order and there may be multiple nonzero elements with the same row and column indices.
4:     irow: int64int32nag_int array
The dimension of the array irow must be at least max1,nz
The row indices corresponding to the nonzero elements supplied in the array a.
Constraint: 1irowin, for i=1,2,,nz.
5:     icol: int64int32nag_int array
The dimension of the array icol must be at least max1,nz
The column indices corresponding to the nonzero elements supplied in the array a.
Constraint: 1icoliirowi, for i=1,2,,nz.
6:     dup – string (length ≥ 1)
Indicates how any nonzero elements with duplicate row and column indices are to be treated.
dup='R'
The entries are removed.
dup='S'
The relevant values in a are summed.
Constraint: dup='R' or 'S'.
7:     zer – string (length ≥ 1)
Indicates how any elements with zero values in a are to be treated.
zer='R'
The entries are removed.
zer='K'
The entries are kept.
Constraint: zer='R' or 'K'.

Optional Input Parameters

None.

Output Parameters

1:     nz int64int32nag_int scalar
The number of lower triangular nonzero elements with unique row and column indices.
2:     a: – double array
The dimension of the array a will be max1,nz
The lower triangular nonzero elements ordered by increasing row index, and by increasing column index within each row. Each nonzero element has a unique row and column index.
3:     irow: int64int32nag_int array
The dimension of the array irow will be max1,nz
The first nz elements contain the row indices corresponding to the nonzero elements returned in the array a.
4:     icol: int64int32nag_int array
The dimension of the array icol will be max1,nz
The first nz elements contain the column indices corresponding to the nonzero elements returned in the array a.
5:     istrn+1 int64int32nag_int array
istri, for i=1,2,,n, is the starting address in the arrays a, irow and icol of row i of the matrix A. istrn+1 is the address of the last nonzero element in A plus one.
6:     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
On entry,n<1,
ornz<0,
ordup'R' or 'S'.
orzer'R' or 'K'.
   ifail=2
On entry, a nonzero element has been supplied which does not lie in the lower triangular part of A, i.e., one or more of the following constraints has been violated:
  • 1irowin,
  • 1icoliirowi,
for i=1,2,,nz
   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

The time taken for a call to nag_sparse_real_symm_sort (f11zb) is proportional to nz.
Note that the resulting matrix may have either rows or columns with no entries. If row i has no entries then istri=istri+1.

Example

This example reads the SCS representation of a real sparse symmetric matrix A, calls nag_sparse_real_symm_sort (f11zb) to reorder the nonzero elements, and outputs the original and the reordered representations.
function f11zb_example


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

n = int64(4);
nz = int64(9);
irow = zeros(nz,1,'int64');
icol = zeros(nz,1,'int64');

a(1:nz)    = [1; 0; 1; 3; 4; 6; 2; 1; 1];
irow(1:nz) = [3; 2; 3; 4; 1; 2; 3; 3; 3];
icol(1:nz) = [2; 1; 2; 4; 1; 2; 3; 2; 2];

fprintf('Number of elements in original sparse matrix: %5d\n',nz);
disp('Original matrix ordering:');
fprintf('   k   a(k)  i_k  j_k\n');
for j = 1:nz
  fprintf('%4d%6.1f%5d%5d\n',j,a(j),irow(j),icol(j));
end

% Sum duplicates and remove zeros
dup = 'S';
zero = 'R';

[nz, a, irow, icol, istr, ifail] = ...
f11zb( ...
       n, nz, a, irow, icol, dup, zero);

fprintf('\nNumber of elements in reordered sparse matrix: %5d\n',nz);
disp('New ordering:');
fprintf('   k   a(k)  i_k  j_k\n');
for j = 1:nz
  fprintf('%4d%6.1f%5d%5d\n',j,a(j),irow(j),icol(j));
end


f11zb example results

Number of elements in original sparse matrix:     9
Original matrix ordering:
   k   a(k)  i_k  j_k
   1   1.0    3    2
   2   0.0    2    1
   3   1.0    3    2
   4   3.0    4    4
   5   4.0    1    1
   6   6.0    2    2
   7   2.0    3    3
   8   1.0    3    2
   9   1.0    3    2

Number of elements in reordered sparse matrix:     5
New ordering:
   k   a(k)  i_k  j_k
   1   4.0    1    1
   2   6.0    2    2
   3   4.0    3    2
   4   2.0    3    3
   5   3.0    4    4

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