Gather sparse vector

 

SGTHR/DGTHR/IGTHR/CGTHR/ZGTHR

 

INTEGER*8

m, indx(m)

 

COMPLEX*8

y(n), x(m)

 

CALL CGTHR(m, y, x, indx)

 

INTEGER*8

m, indx(m)

 

COMPLEX*16

y(n), x(m)

 

CALL ZGTHR(m, y, x, indx)

Input

m

Number of interesting elements, m n, where n is the

 

 

length of y. If m ≤ 0, the subprograms do not reference

 

 

x, indx, or y.

 

y

Array containing the elements of y, y(i) = yi. Only the

 

 

elements of y whose indices are included in indx are

 

 

accessed.

 

indx

Array containing the indices {ki} of the interesting

 

 

elements of y. The indices must satisfy

 

 

1 ≤ indx(i) ≤ n, i = 1, 2, ..., m,

 

 

where n is the length of y.

Output

x

If m ≤ 0, then x is unchanged. Otherwise, the m

 

 

interesting elements of y: x(j) = yi if indx(j) = i.

Notes

The result is unspecified if any element of indx is out of range or if x, indx, and

 

y overlap such that any element of y or any index shares a memory location

 

with any element of x.

Fortran Equivalent

SUBROUTINE SGTHR (M, Y, X,INDX) REAL*4 X(*),Y(*)

INTEGER*4 INDX(*)

IF ( M .LE. 0 ) RETURN DO 10 I = 1, M

X(I) = Y(INDX(I))

10CONTINUE RETURN END

Example Gather y into x, where y is a vector with interesting elements y1, y4, y5, and y9

stored in one-dimensional array Y of dimension 20, and x is a vector stored in compact form in a one-dimensional array X.

INTEGER*4

M,INDX(4)

REAL*8

Y(20),X(4)

DATA

INDX / 1, 4, 5, 9 /

M = 4

 

CALL DGTHR (M,Y,X,INDX)

Chapter 2 Basic Vector Operations 95