Beispiel #1
0
//! compute transpose of matrix
void DenseMatrix::Transpose(DenseMatrix & C) const
{
	C.Resize(m_nCols,m_nRows);
	for ( unsigned int r = 0; r < m_nRows; ++r ) {
		for ( unsigned int c = 0; c < m_nCols; ++c ) {
			M_C(c,r) = M(r,c);
		}
	}
}
Beispiel #2
0
//! compute C = this*B;
bool DenseMatrix::Multiply(const DenseMatrix & B, DenseMatrix & C) const
{
	unsigned int nRowsA = Rows();
	unsigned int nColsA = Columns();
	unsigned int nRowsB = B.Rows();
	unsigned int nColsB = B.Columns();

	if ( nColsA != nRowsB )
		return false;			// matrices are incompatible

	C.Resize(nRowsA,nColsB);
	for ( unsigned int ra = 0; ra < nRowsA; ++ra ) {
		for ( unsigned int cb = 0; cb < nColsB; ++cb ) {

			double rcsum = 0;
			for ( unsigned int ca = 0; ca < nColsA; ++ca )
				rcsum += M(ra,ca) * M_B(ca,cb);

			M_C(ra,cb) = rcsum;
		}
	}

	return true;
}