HP MLIB User's Guide Vol. 1 7th Ed.

98 HP MLIB User’s Guide
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)=y
i
. Only the
elements of y whose indices are included in indx are
accessed.
indx Array containing the indices {k
i
} of the interesting
elements of y. The indices must satisfy
and
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)=y
i
if indx(j)=i.
y
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
10 CONTINUE
RETURN
END
Example Gather y into x and reset y to zero, where y is a vector with nonzero elements y
1
,
y
4
, y
5
, and y
9
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)
1 indx i() n≤≤i 12 m,, ,=,
indx i() indx j() 1 i j m,,
yindxi()()0,= i 12 m.,, ,=