Пример #1
0
 void
 DenseMatrix::CheckInvariants(int column) const
 {
     // make sure no used entries are outside of the bands
     int start, end;
     boost::tie(start, end) = UsedRowRange(column);
     assert(0 <= start && start <= end && end <= Rows());
     for (int i = 0; i < Rows(); i++)
     {
         if (!(start <= i && i < end))
         {
             assert ((*this)(i, column) == value_type());
         }
     }
 }
Пример #2
0
    //TODO : Get ride of "Tpetra"::OptimizeOption
    void fillComplete(const RCP<ParameterList> &params=null)
    {
        for (size_t r=0; r<Rows(); ++r)
        {
            for (size_t c=0; c<Cols(); ++c)
            {
                if(getMatrix(r,c)->isFillComplete() == false)
                    getMatrix(r,c)->fillComplete(getDomainMap(c),getRangeMap(r),params);
            }
        }

        // get full row map
        //fullrowmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), rangemaps_->getFullMap()->getNodeNumElements(), rangemaps_->getFullMap()->getNodeElementList(), rangemaps_->getFullMap()->getIndexBase(), rangemaps_->getFullMap()->getComm());//rangemaps_->FullMap(); //->Clone();
        fullrowmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), rangemaps_->getFullMap()->getGlobalNumElements(), rangemaps_->getFullMap()->getNodeElementList(), rangemaps_->getFullMap()->getIndexBase(), rangemaps_->getFullMap()->getComm());//rangemaps_->FullMap(); //->Clone();

        // TODO: check me, clean up, use only ArrayView instead of std::vector
        // build full col map
        if (fullcolmap_ == Teuchos::null)
        {
            std::vector<GlobalOrdinal> colmapentries;
            for (size_t c=0; c<Cols(); ++c)
            {
                std::set<GlobalOrdinal> colset;
                for (size_t r=0; r<Rows(); ++r)
                {
                    if(getMatrix(r,c) != Teuchos::null) {
                        Teuchos::RCP<const MapClass> colmap = getMatrix(r,c)->getColMap();
                        copy(colmap->getNodeElementList().getRawPtr(),
                             colmap->getNodeElementList().getRawPtr()+colmap->getNodeNumElements(),
                             inserter(colset,colset.begin()));
                    }
                }
                colmapentries.reserve(colmapentries.size()+colset.size());
                copy(colset.begin(), colset.end(), back_inserter(colmapentries));
                sort(colmapentries.begin(), colmapentries.end());
                typename std::vector<GlobalOrdinal>::iterator gendLocation;
                gendLocation = std::unique(colmapentries.begin(), colmapentries.end());
                colmapentries.erase(gendLocation,colmapentries.end());
            }

            // sum up number of local elements
            size_t numGlobalElements = 0;
            sumAll(rangemaps_->getFullMap()->getComm(), colmapentries.size(), numGlobalElements)

            const Teuchos::ArrayView<const GlobalOrdinal> aView = Teuchos::ArrayView<const GlobalOrdinal>(colmapentries);
            fullcolmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), numGlobalElements, aView, 0,rangemaps_->getFullMap()->getComm());
            //fullcolmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), domainmaps_->getFullMap()->getGlobalNumElements(), aView, 0,domainmaps_->getFullMap()->getComm());
        }
Пример #3
0
VOID Matrix2<T>::SetElement(SIZE_T i, SIZE_T j, T& V)
{
  Assert( i < Rows() );
	Assert( j < Columns() );

	m_M[i*Columns() + j] = V;
}
Пример #4
0
VOID Matrix2<T>::SetColumn(SIZE_T j, T& V)
{
  Assert( j < Columns() );

  for (SIZE_T i=0; i<Rows(); i++)
    (*this)(i,j) = V;
}
Пример #5
0
VOID Matrix2<T>::SetColumn(SIZE_T j, CONST Vector2<T>& V)
{
  Assert( j < Columns() );

  for (SIZE_T i=0; i<Rows(); i++)
    (*this)(i,j) = V(i);
}
Пример #6
0
VOID Matrix2<T>::SetRow(SIZE_T i, T& V)
{
  Assert( i < Rows() );

  for (SIZE_T j=0; j<Columns(); j++)
     (*this)(i,j) = V;
}
int main()
{
	int number,counter,i,firstrowsum;
	scanf("%d", &number);
	int square[999][999];
	for(counter = 0;counter < number; counter++)
	{
		for(i = 0; i < number; i++)
		{
		scanf("%d", &square[counter][i]);
		}
	}

	for(i = 0; i < number; i++)
	{
		firstrowsum=firstrowsum + square[0][i];
	}
	if((Rows(square, number, firstrowsum) == 1) && 
		(colons (square, number, firstrowsum) == 1)  && 
		(diagonals(square,number,firstrowsum) == 1))
	
		printf("MAGIC");
	
	else printf("NOT MAGIC");
}
Пример #8
0
Void Mat::MakeBlock(Real k)
{
    Int     i;

    for (i = 0; i < Rows(); i++)
        SELF[i].MakeBlock(k);
}
Пример #9
0
/**
 * Paint the window status
 */
void EditorWindow::PaintEditorStatus(void)
{
	char buf[256];
	int r = Rows() - 1;
	
	if (editor == NULL) return;

	UseFrameStyle();

	
	// Clear the space
	
	tcw->OutHorizontalLine(r, 1, 14);
	
	
	// Print the cursor location
	
	snprintf(buf, sizeof(buf), " %d:%d ", editor->DocumentCursorRow(),
			 editor->DocumentCursorColumn());
	tcw->OutText(r, 9 - digits(editor->DocumentCursorRow()), buf);
	
	
	// Print the flags
	
	if (editor->OverwriteMode()) tcw->OutChar(r, 2, 'O');
	if (editor->Document()->Modified()) tcw->OutChar(r, 3, '*');
}
Пример #10
0
void dng_matrix::SafeRound (real64 factor)
	{
	
	real64 invFactor = 1.0 / factor;
	
	for (uint32 j = 0; j < Rows (); j++)
		{
		
		// Round each row to the specified accuracy, but make sure the
		// a rounding does not affect the total of the elements in a row
		// more than necessary.
		
		real64 error = 0.0;
		
		for (uint32 k = 0; k < Cols (); k++)
			{
			
			fData [j] [k] += error;
			
			real64 rounded = Round_int32 (fData [j] [k] * factor) * invFactor;
			
			error = fData [j] [k] - rounded;
			
			fData [j] [k] = rounded;
			
			}
		
		}
		
	}
Пример #11
0
VOID Matrix2<T>::SetRow(SIZE_T i, CONST Vector2<T>& V)
{
  Assert( i < Rows() );

  for (SIZE_T j=0; j<Columns(); j++)
     (*this)(i,j) = V(j);
}
NumericMatrix<V, I, S> NumericMatrix<V, I, S>::operator * (const NumericMatrix<V, I, S>& m) const
{ // Multiply the matrix.
  // This function can be optimized by calculating the inner product ourselfs instead of 
  // using the InnerProduct function of Vector. This saves a couple of row and column copies.


	// Create new matrix with same row size of first matrix and column size of second matrix and same starting index as first matrix
	NumericMatrix<V, I, S> result(Rows(), m.Columns(), MinRowIndex(), MinColumnIndex());
	I r1, c2, rr, cr;

	// Element of resulting array is dot/inner product of corresponding row m1 and corresponding column m2
	for (I rr=result.MinRowIndex(); rr<=result.MaxRowIndex(); ++rr)
	{
		
		for (I cr = result.MinColumnIndex(); cr <= result.MaxColumnIndex(); ++cr) 
		{
			result(rr, cr) = 0.0;
			for (I k = result.MinColumnIndex(); k <= result.MaxColumnIndex(); ++k)
			{

					result(rr, cr) += (*this)(rr, k) * m(k,cr);
			}
			cout << "*" << rr << "," << cr << "," << result(rr, cr)<< endl;
		}
			
	}

	// Return the result
	return result;
}
Пример #13
0
T& Matrix2<T>::operator () (SIZE_T i, SIZE_T j)
{
	Assert( i < Rows() );
	Assert( j < Columns() );

	return m_M[i*Columns() + j];
}
Пример #14
0
Void Mat::MakeBlock()
{
    Int     i, j;

    for (i = 0; i < Rows(); i++)
        for (j = 0; j < Cols(); j++)
            Elt(i,j) = vl_one;
}
Пример #15
0
Void Mat::MakeDiag()
{
    Int     i, j;

    for (i = 0; i < Rows(); i++)
        for (j = 0; j < Cols(); j++)
            Elt(i,j) = (i == j) ? vl_one : vl_zero;
}
Пример #16
0
 std::string Table::Data(unsigned int row, unsigned int col) const
 {
     if (row < Rows() && col < Columns())
     {
         return m_data.at(Columns() * row + col);
     }
     return "";
 }
Пример #17
0
double Matrix::Sum() const
{
   int i, j;
   double sum = 0.0;
   for(i=0; i<Rows(); i++)
      for(j=0; j<Cols(); j++)
         sum += (*mRowVec[i])[j];
   return sum;
}
Пример #18
0
Mat &Mat::operator /= (Real s)
{
    Int     i;

    for (i = 0; i < Rows(); i++)
        SELF[i] /= s;

    return(SELF);
}
Пример #19
0
int
set_menu_format(MENU *m, int rows, int cols)
{
	if (rows < 0 || cols < 0) {
		return (E_BAD_ARGUMENT);
	}
	if (m) {
		if (Posted(m)) {
			return (E_POSTED);
		}
		if (rows == 0) {
			rows = FRows(m);
		}
		if (cols == 0) {
			cols = FCols(m);
		}

		/* The pattern buffer is allocated after items have been */
		/* connected */
		if (Pattern(m)) {
			IthPattern(m, 0) = '\0';
			Pindex(m) = 0;
		}

		FRows(m) = rows;
		FCols(m) = cols;
		Cols(m) = min(cols, Nitems(m));
		Rows(m) = (Nitems(m)-1) / cols + 1;
		Height(m) = min(rows, Rows(m));
		Top(m) = 0;
		Current(m) = IthItem(m, 0);
		SetLink(m);
		_scale(m);
	} else {
		if (rows > 0) {
			FRows(Dfl_Menu) = rows;
		}
		if (cols > 0) {
			FCols(Dfl_Menu) = cols;
		}
	}
	return (E_OK);
}
SideWinderMaze::SideWinderMaze(int x, int y)
  : Maze(x, y)
  , current_(2, 1)
  , i_(2)
  , j_(1)
{
  run_set_.push_back(start_.Down());

  for (int j = 1; j < Rows()-2; j++)
    OpenPassage(Point(1, j), Cell::Direction::RIGHT);
}
Пример #21
0
 /**
  * @brief Converts a GSL matrix to a TNT-based matrix
  *
  * Convenience method to convert to GSLMatrix type
  *
  * @param m GSL matrix to convert
  *
  * @return GSLUtility::GSLMatrix TNT-based matrix
  */
 GSLUtility::GSLMatrix GSLUtility::gslToGSL(const gsl_matrix *m) const {
   size_t nrows = Rows(m);
   size_t ncols = Columns(m);
   GSLMatrix Nm(nrows, ncols);
   for(size_t i = 0 ; i < nrows ; i++) {
     for(size_t j = 0 ; j < ncols ; j++) {
       Nm[i][j] = gsl_matrix_get(m, i, j);
     }
   }
   return (Nm);
 }
Пример #22
0
Mat &Mat::operator *= (const Mat &m)
{
    Assert(Cols() == m.Cols(), "(Mat::*=) matrix columns don't match");

    Int     i;

    for (i = 0; i < Rows(); i++)
        SELF[i] = SELF[i] * m;

    return(SELF);
}
Пример #23
0
Void Mat::MakeDiag(Real k)
{
    Int     i, j;

    for (i = 0; i < Rows(); i++)
        for (j = 0; j < Cols(); j++)
            if (i == j)
                Elt(i,j) = k;
            else
                Elt(i,j) = vl_zero;
}
Пример #24
0
Mat &Mat::Clamp(Real fuzz)
//  clamps all values of the matrix with a magnitude
//  smaller than fuzz to zero.
{
    Int i;

    for (i = 0; i < Rows(); i++)
        SELF[i].Clamp(fuzz);

    return(SELF);
}
Пример #25
0
Lookup_Size::Lookup_Size (int rows, int columns)
{
	row_range = NULL;
	row_size = 0;
	wrap_flag = true;
	min_size = 0;
	max_size = MIDNIGHT;

	Rows (rows);
	Columns (columns);
}
Пример #26
0
void dng_matrix::Scale (real64 factor)
	{
	
	for (uint32 j = 0; j < Rows (); j++)	
		for (uint32 k = 0; k < Cols (); k++)
			{
			
			fData [j] [k] *= factor;
			
			}
			
	}
Пример #27
0
void dng_matrix::Round (real64 factor)
	{
	
	real64 invFactor = 1.0 / factor;
	
	for (uint32 j = 0; j < Rows (); j++)	
		for (uint32 k = 0; k < Cols (); k++)
			{
			
			fData [j] [k] = Round_int32 (fData [j] [k] * factor) * invFactor;
			
			}
			
	}
Пример #28
0
	virtual SQLfieldList* GetRowPtr()
	{
		fieldlist = new SQLfieldList();

		if (currentrow < rows)
		{
			for (int i = 0; i < Rows(); i++)
			{
				fieldlist->push_back(fieldlists[currentrow][i]);
			}
			currentrow++;
		}
		return fieldlist;
	}
Пример #29
0
    /**
     * @brief Converts TNT-based matrix to GSL matrix
     *
     * Convenience method to convert TNT-based matrix to a GSL matrix.
     *
     * @param m TNT-based matrix to convert
     * @param gm Optional GSL matrix of same size to copy data to
     *
     * @return gsl_matrix* Pointer to GSL matrix copy
     */
    gsl_matrix *GSLUtility::GSLTogsl(const GSLUtility::GSLMatrix &m,
                                     gsl_matrix *gm) const {
      if(gm == 0) {
        gm = gsl_matrix_alloc(m.dim1(), m.dim2());
      }
      else if((Rows(gm) != (size_t) m.dim1()) &&
              (Columns(gm) != (size_t) m.dim2())) {
        ostringstream mess;
        mess << "Size of NL matrix (" << m.dim1() << "," << m.dim2()
             << ") not same as GSL matrix (" << Rows(gm) << "," << Columns(gm)
             << ")";
        throw IException(IException::Programmer,
                         mess.str().c_str(),
                         _FILEINFO_);
      }

      for(int i = 0 ; i < m.dim1() ; i++) {
        for(int j = 0 ; j < m.dim2() ; j++) {
          gsl_matrix_set(gm, i, j, m[i][j]);
        }
      }
      return (gm);
    }
Пример #30
0
dng_matrix_4by3::dng_matrix_4by3 (const dng_matrix &m)

	:	dng_matrix (m)
	
	{
	
	if (Rows () != 4 ||
		Cols () != 3)
		{
		
		ThrowMatrixMath ();
		
		}
	
	}