/* Library module: SelDelFR.GL */ /* Created: 11th September 1992 by FJR */ /* */ /* Last Modified: */ /* 15 Sep 92 FJR Minor changes in layout */ /* 19 May 93 FJR Added DeleteRC */ /* 14 Apr 97 FJR Changed "matrix" for v3.2 */ /* 21 Apr 97 FJR Added SelNoPR, DelNoPR */ /* */ /* Routines to supplant the standard routines DELIF/SELIF */ /* */ /* Exported: */ /* SelectR (inMatrix, boolVec) */ /* DeleteR (inMatrix, boolVec) */ /* DeleteRC (inMatrix, boolVecR, boolVecC) */ /* SelNoPR (inMatrix, boolVec) */ /* DelNoPR (inMatrix, boolVec) */ /* DelRCNoP (inMatrix, boolVecR, boolVecC) */ /* Last three do NOT use PACKR to remove rows - slower */ PROC (1) = SelectR (inMatrix, boolVec); /* Select the rows of a matrix corresponding to 'true' in */ /* the boolean vector; drop other rows */ /* In: */ /* inMatrix Matrix from which rows are to be selected */ /* boolVec Vector of 1s and 0s indicating rows to select */ /* Out: */ /* inMatrix Input inMatrix with selected rows only */ boolVec = (boolVec .== 0); /* convert to 1/0 only */ boolVec = MISS (boolVec, 1); inMatrix[.,1] = inMatrix[.,1] + boolVec; inMatrix = PACKR(inMatrix); RETP (inMatrix); ENDP; /* SelectR */ PROC (1) = DeleteR (inMatrix, boolVec); /* Delete the rows of a inMatrix corresponding to 'true' in */ /* the boolean vector; ignore other rows */ /* In: */ /* inMatrix Matrix from which rows are to be deleteed */ /* boolVec Vector of 1s and 0s indicating rows to delete */ /* Out: */ /* inMatrix Input inMatrix with deleteed rows only */ boolVec = (boolVec ./= 0); /* convert to 1/0 only */ /* NB comparison opposite to SelectR */ boolVec = MISS(boolVec, 1); inMatrix[.,1] = inMatrix[.,1] + boolVec; inMatrix = PACKR(inMatrix); RETP (inMatrix); ENDP; /* DeleteR */ PROC (1) = DeleteRC (inMatrix, boolVecR, boolVecC); /* Delete rows AND cols of inMatrix corresponding to 'true' */ /* in boolean vectors; ignore other rows */ /* In: */ /* inMatrix Matrix from which rows are to be deleted */ /* boolVecR Vector of 1s/0s indicating rows to delete */ /* boolVecC Vector of 1s/0s indicating cols to delete */ /* Out: */ /* inMatrix Input matrix with deleted rows/cols out */ /* NB This procedure is offered as an option to two calls */ /* DeleteR to economise on memory */ IF ISMISS(inMatrix); PRINT "Matrix contains missing data!"; ENDIF; boolVecR = (boolVecR ./= 0); /* convert to 1/0 only */ /* NB comparison opposite to SelectR */ boolVecR = MISS(boolVecR, 1); inMatrix[.,1] = inMatrix[.,1] + boolVecR; inMatrix = PACKR(inMatrix); boolVecC = (boolVecC ./= 0); /* convert to 1/0 only */ /* NB comparison opposite to SelectR */ boolVecC = MISS(boolVecC, 1); inMatrix[1,.] = inMatrix[1,.] + boolVecC'; inMatrix = PACKR(inMatrix')'; RETP (inMatrix); ENDP; /* DeleteRC */ PROC (1) = SelNoPR (inMatrix, boolVec); /* Select the rows of a matrix corresponding to 'true' in */ /* the boolean vector; drop other rows. PACKR not used */ /* In: */ /* inMatrix Matrix from which rows are to be selected */ /* boolVec Vector of 1s and 0s indicating rows to select */ /* Out: */ /* temp Input inMatrix with selected rows only */ LOCAL temp; LOCAL i; LOCAL j; LOCAL nRows; nRows = ROWS(inMatrix); temp = ZEROS(nRows, COLS(inMatrix)); i = 1; j = 0; DO WHILE i <= nRows; IF boolVec[i]; j = j +1; temp[j,.] = inMatrix[i]; ENDIF; i = i + 1; ENDO; IF j==0; temp= MISS(0,0); ELSE; temp = temp[1:j,.]; ENDIF; RETP (temp); ENDP; /* SelNoPR */ PROC (1) = DelNoPR (inMatrix, boolVec); /* Select the rows of a matrix corresponding to 'true' in */ /* the boolean vector; drop other rows. PACKR not used */ /* In: */ /* inMatrix Matrix from which rows are to be selected */ /* boolVec Vector of 1s and 0s indicating rows to select */ /* Out: */ /* temp Input inMatrix with selected rows only */ LOCAL temp; LOCAL i; LOCAL j; LOCAL nRows; nRows = ROWS(inMatrix); temp = ZEROS(nRows, COLS(inMatrix)); i = 1; j = 0; DO WHILE i <= nRows; IF NOT boolVec[i]; j = j +1; temp[j,.] = inMatrix[i,.]; ENDIF; i = i + 1; ENDO; IF j==0; temp= MISS(0,0); ELSE; temp = temp[1:j,.]; ENDIF; RETP (temp); ENDP; /* DelNoPR */ /***************************************************************** Originals: proc delif(x,e); retp( submat(x,submat(packr(seqa(1,1,rows(x))~miss(e,1)),0,1),0) ); endp; proc selif(x,e); retp( submat(x,submat(packr(seqa(1,1,rows(x))~miss(e,0)),0,1),0) ); endp; from \gauss\src\datatran.arc *****************************************************************/