1*72257631SBarry Smith /*$Id: getcolv.c,v 1.11 2000/04/12 04:24:13 bsmith Exp bsmith $*/ 20925cdddSBarry Smith 30925cdddSBarry Smith #include "src/mat/matimpl.h" /*I "mat.h" I*/ 40925cdddSBarry Smith 50925cdddSBarry Smith #undef __FUNC__ 6b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"MatGetColumnVector" 70925cdddSBarry Smith /*@ 882bf6240SBarry Smith MatGetColumnVector - Gets the values from a given column of a matrix. 90925cdddSBarry Smith 10*72257631SBarry Smith Not Collective 11fee21e36SBarry Smith 1298a79cdbSBarry Smith Input Parameters: 1398a79cdbSBarry Smith + X - the matrix 1498a79cdbSBarry Smith . v - the vector 1598a79cdbSBarry Smith - c - the column requested 1698a79cdbSBarry Smith 1715091d37SBarry Smith Level: advanced 1815091d37SBarry Smith 1982bf6240SBarry Smith Contributed by: Denis Vanderstraeten 200925cdddSBarry Smith 2182bf6240SBarry Smith .keywords: matrix, column, get 220925cdddSBarry Smith 2315091d37SBarry Smith .seealso: MatGetRow(), MatGetDiagonal() 2415091d37SBarry Smith 250925cdddSBarry Smith @*/ 2682bf6240SBarry Smith int MatGetColumnVector(Mat A,Vec yy,int col) 270925cdddSBarry Smith { 2882bf6240SBarry Smith Scalar *y,*v,zero = 0.0; 2982bf6240SBarry Smith int ierr,i,j,nz,*idx,M,N,Mv,Rs,Re,rs,re; 300925cdddSBarry Smith 310925cdddSBarry Smith PetscFunctionBegin; 3282bf6240SBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE); 3382bf6240SBarry Smith PetscValidHeaderSpecific(yy,VEC_COOKIE); 340925cdddSBarry Smith 35596552b5SBarry Smith if (col < 0) SETERRQ1(1,1,"Requested negative column: %d",col); 3682bf6240SBarry Smith ierr = MatGetSize(A,&M,&N);CHKERRQ(ierr); 37596552b5SBarry Smith if (col >= N) SETERRQ2(1,1,"Requested column %d larger than number columns in matrix %d",col,N); 380925cdddSBarry Smith 3982bf6240SBarry Smith ierr = VecGetSize(yy,&Mv);CHKERRQ(ierr); 40*72257631SBarry Smith if (M != Mv) SETERRQ2(1,1,"Matrix does not have same number of rows %d as vector %d",M,Mv); 4182bf6240SBarry Smith 4282bf6240SBarry Smith ierr = MatGetOwnershipRange(A,&Rs,&Re);CHKERRQ(ierr); 4382bf6240SBarry Smith ierr = VecGetOwnershipRange(yy,&rs,&re);CHKERRQ(ierr); 44596552b5SBarry Smith if (Rs != rs || Re != re) SETERRQ4(1,1,"Matrix %d %d does not have same ownership range as vector %d %d",Rs,Re,rs,re); 4582bf6240SBarry Smith 4682bf6240SBarry Smith ierr = VecSet(&zero,yy);CHKERRQ(ierr); 4782bf6240SBarry Smith ierr = VecGetArray(yy,&y);CHKERRQ(ierr); 4882bf6240SBarry Smith 4982bf6240SBarry Smith for (i=Rs; i<Re; i++) { 5082bf6240SBarry Smith ierr = MatGetRow(A,i,&nz,&idx,&v);CHKERRQ(ierr); 5182bf6240SBarry Smith if (nz && idx[0] <= col) { 5282bf6240SBarry Smith /* 5382bf6240SBarry Smith Should use faster search here 5482bf6240SBarry Smith */ 5582bf6240SBarry Smith for (j=0; j<nz; j++) { 5682bf6240SBarry Smith if (idx[j] >= col) { 5782bf6240SBarry Smith if (idx[j] == col) y[i-rs] = v[j]; 5882bf6240SBarry Smith break; 590925cdddSBarry Smith } 600925cdddSBarry Smith } 610925cdddSBarry Smith } 6282bf6240SBarry Smith ierr = MatRestoreRow(A,i,&nz,&idx,&v);CHKERRQ(ierr); 630925cdddSBarry Smith } 640925cdddSBarry Smith 6582bf6240SBarry Smith ierr = VecRestoreArray(yy,&y);CHKERRQ(ierr); 660925cdddSBarry Smith PetscFunctionReturn(0); 670925cdddSBarry Smith } 68