HP MLIB User's Guide Vol. 1 7th Ed.
Chapter 2 Basic Vector Operations 95
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)=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
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)=y
i
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))
10 CONTINUE
RETURN
END
Example Gather y into x, where y is a vector with interesting elements y
1
, y
4
, y
5
, and y
9
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)