public static void extract(DenseMatrix64F src, int srcY0, int srcX0, DenseMatrix64F dst, int dstY0, int dstX0, int numRows, int numCols) { for( int y = 0; y < numRows; y++ ) { int indexSrc = src.getIndex(y+srcY0,srcX0); int indexDst = dst.getIndex(y+dstY0,dstX0); System.arraycopy(src.data,indexSrc,dst.data,indexDst, numCols); } } }
public static void extract(DenseMatrix64F src, int srcY0, int srcX0, DenseMatrix64F dst, int dstY0, int dstX0, int numRows, int numCols) { for( int y = 0; y < numRows; y++ ) { int indexSrc = src.getIndex(y+srcY0,srcX0); int indexDst = dst.getIndex(y+dstY0,dstX0); System.arraycopy(src.data,indexSrc,dst.data,indexDst, numCols); } } }
public static void extract(DenseMatrix64F src, int srcY0, int srcX0, DenseMatrix64F dst, int dstY0, int dstX0, int numRows, int numCols) { for( int y = 0; y < numRows; y++ ) { int indexSrc = src.getIndex(y+srcY0,srcX0); int indexDst = dst.getIndex(y+dstY0,dstX0); System.arraycopy(src.data,indexSrc,dst.data,indexDst, numCols); } } }
public static double multMatrixRowVector(DenseMatrix64F a, int row, DenseMatrix64F b) { if (a.numCols != b.numRows) throw new RuntimeException("a.numCols should be equal to b.numRows"); if (b.numCols != 1) throw new RuntimeException("b should be a column vector"); int rowHeadIndex = a.getIndex(row, 0); double total = 0; for (int i = 0; i < a.numCols; i++) { total += a.get(rowHeadIndex + i) * b.get(i); } return total; }
public static double multMatrixRowVector(DenseMatrix64F a, int row, DenseMatrix64F b) { if (a.numCols != b.numRows) throw new RuntimeException("a.numCols should be equal to b.numRows"); if (b.numCols != 1) throw new RuntimeException("b should be a column vector"); int rowHeadIndex = a.getIndex(row, 0); double total = 0; for (int i = 0; i < a.numCols; i++) { total += a.get(rowHeadIndex + i) * b.get(i); } return total; }
/** * Extracts the row from a matrix. * @param a Input matrix * @param row Which row is to be extracted * @param out output. Storage for the extracted row. If null then a new vector will be returned. * @return The extracted row. */ public static DenseMatrix64F extractRow( DenseMatrix64F a , int row , DenseMatrix64F out ) { if( out == null) out = new DenseMatrix64F(1,a.numCols); else if( !MatrixFeatures.isVector(out) || out.getNumElements() != a.numCols ) throw new IllegalArgumentException("Output must be a vector of length "+a.numCols); System.arraycopy(a.data,a.getIndex(row,0),out.data,0,a.numCols); return out; }
public void multTransB(DenseMatrix64F b, DenseMatrix64F c) { for(int i=0;i<blockSizes.length;i++) { for(int crow=blockStarts[i];crow<blockStarts[i+1];crow++) { int aIndex0=this.getIndex(crow,blockStarts[i]); for(int ccol=0; ccol<c.numCols;ccol++) { double val = 0.0; int aIndex=aIndex0; int bIndex=b.getIndex(ccol,blockStarts[i]); int bEnd = bIndex + blockSizes[i]; while(bIndex < bEnd) val+=this.data[aIndex++]*b.data[bIndex++]; c.set(crow, ccol,val); } /* tmpMatrix[i].reshape(blockSizes[i] , blockSizes[i]); packBlock(tmpMatrix[i], i, 0, 0); multTempB.reshape(b.numRows, blockSizes[i]); multTempC.reshape(blockSizes[i], c.numCols); CommonOps.extract(b, 0, b.numRows, blockStarts[i], blockStarts[i+1], multTempB, 0, 0); CommonOps.multTransB(tmpMatrix[i], multTempB, multTempC); CommonOps.insert(multTempC, c, blockStarts[i], 0); */ } } }
public void multTransB(DenseMatrix64F b, DenseMatrix64F c) { for(int i=0;i<blockSizes.length;i++) { for(int crow=blockStarts[i];crow<blockStarts[i+1];crow++) { int aIndex0=this.getIndex(crow,blockStarts[i]); for(int ccol=0; ccol<c.numCols;ccol++) { double val = 0.0; int aIndex=aIndex0; int bIndex=b.getIndex(ccol,blockStarts[i]); int bEnd = bIndex + blockSizes[i]; while(bIndex < bEnd) val+=this.data[aIndex++]*b.data[bIndex++]; c.set(crow, ccol,val); } /* tmpMatrix[i].reshape(blockSizes[i] , blockSizes[i]); packBlock(tmpMatrix[i], i, 0, 0); multTempB.reshape(b.numRows, blockSizes[i]); multTempC.reshape(blockSizes[i], c.numCols); CommonOps.extract(b, 0, b.numRows, blockStarts[i], blockStarts[i+1], multTempB, 0, 0); CommonOps.multTransB(tmpMatrix[i], multTempB, multTempC); CommonOps.insert(multTempC, c, blockStarts[i], 0); */ } } }