template <>
void Matrix<double>::slid_window(int w, int h, double value)
{
	if(w<=0 || h<=0){
		throw std::invalid_argument("Size must be positive");
	}

	// determine overlap
    int min_h,min_w;
	min_h = h;
	min_w = w;
	if(min_h>height) {
		min_h = height;
	}
	if(min_w>width) {
		min_w = width;
	}

	// create matrix of size (w,h) and copy overlap region
	Matrix<double> tmpMatrix(w,h,value);
	for(int col=0;col<min_w;col++) 
 
	  memcpy(tmpMatrix.get() + col*h, pData + (col+1)*height, min_h*sizeof(double));

	// replace old matrix with new one
Example #2
0
//  Reduce the size of this, retaining data from the original array
//  for valid indices of the new array.
bool AMatrix_base::Shrink(const int NumRows, const int NumCols) {

    bool result = false;
    int i, j;

    if ((NumRows < m_NumRows) || (NumCols < m_NumCols)) {
        if (NumRows > 0 && NumCols > 0) {
            //  
            AMatrix_base tmpMatrix(NumRows, NumCols);
            for (i = 0; i < NumRows; ++i) {
                for (j = 0; j < NumCols; ++j) {
                    tmpMatrix.m_Array[i][j] = m_Array[i][j];
                    if (i == 0) {
                        tmpMatrix.m_ColumnFlags[j] = m_ColumnFlags[j];
                    }
                }
            }
            DeAllocate();
            Allocate(NumRows, NumCols);
            for (i = 0; i < NumRows; ++i) {
                for (j = 0; j < NumCols; ++j) {
                    m_Array[i][j] = tmpMatrix.m_Array[i][j];
                    if (i == 0) {
                        m_ColumnFlags[j] = tmpMatrix.m_ColumnFlags[j];
                    }
                }
            }
            result = true;
        }
    }
    return result;
}
Example #3
0
Matrix Matrix::operator+(const Matrix &rhs)
{
  Matrix tmpMatrix(height, width);
  tmpMatrix += *this;
  tmpMatrix += rhs;
  return tmpMatrix;
}
Example #4
0
void Matrix<elType>::resize(int w, int h, elType value)
{
	if (w==width && h==height)
		//Nothing to do
		return;
	if(w<=0 || h<=0){
		throw std::invalid_argument("Size must be positive");
	}

	// determine overlap
    int min_h,min_w;
	min_h = h;
	min_w = w;
	if(min_h>height) {
		min_h = height;
	}
	if(min_w>width) {
		min_w = width;
	}

	// create matrix of size (w,h) and copy overlap region
	// create matrix of size (w,h) and copy overlap region
	Matrix<elType> tmpMatrix(w,h,value);
	for(int col=0;col<min_w;col++) 
		memcpy(tmpMatrix.get() + col*h, pData + col*height, min_h*sizeof(elType));

	// replace old matrix with new one
	set(tmpMatrix);
}
Example #5
0
void MonolithicBlockMatrix::applyPreconditioner( const matrixPtr_Type prec, matrixPtr_Type& oper )
{
    matrix_Type tmpMatrix(prec->map(), 1);
    EpetraExt::MatrixMatrix::Multiply( *prec->matrixPtr(),
                                       false,
                                       *oper->matrixPtr(),
                                       false,
                                       *tmpMatrix.matrixPtr());
    oper->swapCrsMatrix(tmpMatrix);
}
void dComplemtaritySolver::dBodyState::UpdateInertia()
{
   dMatrix tmpMatrix (dGetZeroMatrix());
   tmpMatrix[0] = m_localInertia.CompProduct (dVector (m_matrix[0][0], m_matrix[1][0], m_matrix[2][0], 0.0f));
   tmpMatrix[1] = m_localInertia.CompProduct (dVector (m_matrix[0][1], m_matrix[1][1], m_matrix[2][1], 0.0f));
   tmpMatrix[2] = m_localInertia.CompProduct (dVector (m_matrix[0][2], m_matrix[1][2], m_matrix[2][2], 0.0f));
   m_inertia = tmpMatrix * m_matrix;
   tmpMatrix[0] = m_localInvInertia.CompProduct (dVector (m_matrix[0][0], m_matrix[1][0], m_matrix[2][0], 0.0f));
   tmpMatrix[1] = m_localInvInertia.CompProduct (dVector (m_matrix[0][1], m_matrix[1][1], m_matrix[2][1], 0.0f));
   tmpMatrix[2] = m_localInvInertia.CompProduct (dVector (m_matrix[0][2], m_matrix[1][2], m_matrix[2][2], 0.0f));
   m_invInertia = tmpMatrix * m_matrix;
}