Пример #1
0
void Householder<T>::mulLeft(NDArray<T>& matrix, const NDArray<T>& tail, const T coeff) {
	
	// if(matrix.rankOf() != 2)
	// 	throw "ops::helpers::Householder::mulLeft method: input array must be 2D matrix !";	

	if(matrix.sizeAt(0) == 1)   
    	matrix *= (T)1. - coeff;
  	
  	else if(coeff != (T)0.) {

  		NDArray<T>* bottomPart =  matrix.subarray({{1, matrix.sizeAt(0)}, {}});
		NDArray<T> bottomPartCopy = *bottomPart; 

		if(tail.isColumnVector()) {

			NDArray<T> column = tail;
			NDArray<T>* row = tail.transpose();						
    		NDArray<T> resultingRow = mmul(*row, bottomPartCopy);
    		NDArray<T>* fistRow = matrix.subarray({{0,1}, {}});
    		resultingRow += *fistRow;        	
    		*fistRow -= resultingRow * coeff;	
    		*bottomPart -= mmul(column, resultingRow) * coeff;    		

			delete row;
			delete fistRow;
		}
		else {
			
			NDArray<T> row = tail;
			NDArray<T>* column = tail.transpose();
    		NDArray<T> resultingRow = mmul(row, bottomPartCopy);
    		NDArray<T>* fistRow = matrix.subarray({{0,1}, {}});
    		resultingRow += *fistRow;        	
    		*fistRow -= resultingRow * coeff;
    		*bottomPart -= mmul(*column, resultingRow) * coeff;    	

			delete column;
			delete fistRow;
		}	    	    	
		delete bottomPart;
	}
}
Пример #2
0
void Householder<T>::mulRight(NDArray<T>& matrix, const NDArray<T>& tail, const T coeff) {

	// if(matrix.rankOf() != 2)
	// 	throw "ops::helpers::Householder::mulRight method: input array must be 2D matrix !";
	
	if(matrix.sizeAt(1) == 1)   
    	matrix *= (T)1. - coeff;
  	
  	else if(coeff != (T)0.) {

  		NDArray<T>* rightPart =  matrix.subarray({{}, {1, matrix.sizeAt(1)}});
		NDArray<T> rightPartCopy = *rightPart; 
		NDArray<T>* fistCol = matrix.subarray({{},{0,1}});

  		if(tail.isColumnVector()) {

			NDArray<T> column = tail;
			NDArray<T>* row = tail.transpose();						
    		NDArray<T> resultingCol = mmul(rightPartCopy, column);    		
    		resultingCol += *fistCol;        	
    		*fistCol -= resultingCol * coeff;	
    		*rightPart -= mmul(resultingCol, *row) * coeff;    		

			delete row;			
		}
		else {
			
			NDArray<T> row = tail;
			NDArray<T>* column = tail.transpose();
    		NDArray<T> resultingCol = mmul(rightPartCopy, *column);    		
    		resultingCol += *fistCol;        	
    		*fistCol -= resultingCol * coeff;
    		*rightPart -= mmul(resultingCol, row) * coeff;

			delete column;
			
		}	    	    	
  		delete rightPart;
  		delete fistCol;
	}
}