SGTHRZ/DGTHRZ/IGTHRZ/CGTHRZ/ZGTHRZ

Gather and zero sparse vector

Input

m

Number of interesting elements of y, 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

and

indx(i) ≠ indx( j), 1 i j m, where n is the length of y.

Outputx

y y(indx(i))

If m ≤ 0, then x is unchanged. Otherwise, the m interesting elements of y: x(j) = yi if indx(j) = i.

= 0, i = 1, 2, …, m.

Notes The result is unspecified if any element of indx is out of range, if any two elements of indx have the same value, 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 SGTHRZ (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))

Y(INDX(I)) = 0.0

10CONTINUE RETURN END

Example Gather y into x and reset y to zero, where y is a vector with nonzero elements y1, y4, y5, and y9 stored in a one-dimensional array Y of dimension 20, and x is 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 DGTHRZ (M,Y,X,INDX)

98HP MLIB User’s Guide