Example #1
0
bool dng_matrix::IsDiagonal () const
	{
	
	if (IsEmpty ())
		{
		return false;
		}
	
	if (Rows () != Cols ())
		{
		return false;
		}
	
	for (uint32 j = 0; j < Rows (); j++)
		for (uint32 k = 0; k < Cols (); k++)
			{
			
			if (j != k)
				{
				
				if (fData [j] [k] != 0.0)
					{
					return false;
					}
				
				}
			
			}
			
	return true;
	
	}
Example #2
0
bool dng_matrix::operator== (const dng_matrix &m) const
	{
	
	if (Rows () != m.Rows () ||
	    Cols () != m.Cols ())
		{
		
		return false;
		
		}
	
	for (uint32 j = 0; j < Rows (); j++)	
		for (uint32 k = 0; k < Cols (); k++)
			{
			
			if (fData [j] [k] != m.fData [j] [k])
				{
				
				return false;
				
				}
			
			}
			
	return true;
	
	}
  //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
    fullcolmap_ = Teuchos::null; // delete old full column 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 Map> 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());
    }
Example #4
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;
			
			}
		
		}
		
	}
Example #5
0
	virtual SQLfieldMap& GetRowMap()
	{
		/* In an effort to reduce overhead we don't actually allocate the map
		 * until the first time it's needed...so...
		 */
		if(fieldmap)
		{
			fieldmap->clear();
		}
		else
		{
			fieldmap = new SQLfieldMap;
		}

		if (currentrow < rows)
		{
			for (int i = 0; i < Cols(); i++)
			{
				fieldmap->insert(std::make_pair(ColName(i), GetValue(currentrow, i)));
			}
			currentrow++;
		}

		return *fieldmap;
	}
Example #6
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;
}
Example #7
0
Void Mat::MakeBlock()
{
    Int     i, j;

    for (i = 0; i < Rows(); i++)
        for (j = 0; j < Cols(); j++)
            Elt(i,j) = vl_one;
}
Example #8
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;
}
Example #9
0
Void Mat::MakeZero()
{
#ifdef VL_USE_MEMCPY
    memset(data, 0, sizeof(Real) * Rows() * Cols());
#else
    Int     i;

    for (i = 0; i < Rows(); i++)
        SELF[i] = vl_zero;
#endif
}
Example #10
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);
}
Example #11
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;
}
Example #12
0
	virtual SQLfield GetValue(int row, int column)
	{
		if ((row >= 0) && (row < rows) && (column >= 0) && (column < Cols()))
		{
			return fieldlists[row][column];
		}

		throw SQLbadColName();

		/* XXX: We never actually get here because of the throw */
		return SQLfield("",true);
	}
Example #13
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;
			
			}
			
	}
Example #14
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;
			
			}
			
	}
Example #15
0
dng_matrix_4by3::dng_matrix_4by3 (const dng_matrix &m)

	:	dng_matrix (m)
	
	{
	
	if (Rows () != 4 ||
		Cols () != 3)
		{
		
		ThrowMatrixMath ();
		
		}
	
	}
Example #16
0
	virtual SQLfieldMap* GetRowMapPtr()
	{
		fieldmap = new SQLfieldMap();

		if (currentrow < rows)
		{
			for (int i = 0; i < Cols(); i++)
			{
				fieldmap->insert(std::make_pair(colnames[i],GetValue(currentrow, i)));
			}
			currentrow++;
		}

		return fieldmap;
	}
void BlockMap::ResetConnectivity() {
  for (int r = 0; r < Rows(); r++) {
    for (int c = 0; c < Cols(); c++) {
      Block& currBlock = m_BlockMatrix[r][c];

      // Set reachable neighbors
      currBlock.neighborOffsets.clear();
      Vector2 lOffset(0, -1);
      Vector2 rOffset(0, 1);
      Vector2 tOffset(-1, 0);
      Vector2 bOffset(1, 0);
      if (ValidCoord(currBlock.coord + lOffset)) currBlock.neighborOffsets.insert(lOffset);
      if (ValidCoord(currBlock.coord + rOffset)) currBlock.neighborOffsets.insert(rOffset);
      if (ValidCoord(currBlock.coord + tOffset)) currBlock.neighborOffsets.insert(tOffset);
      if (ValidCoord(currBlock.coord + bOffset)) currBlock.neighborOffsets.insert(bOffset);
    }
  }
}
Example #18
0
MENU *
new_menu(ITEM **items)
{
	MENU *m;

	if ((m = (MENU *) calloc(1, sizeof (MENU))) != (MENU *)0) {
		*m = *Dfl_Menu;
		Rows(m) = FRows(m);
		Cols(m) = FCols(m);
		if (items) {
			if (*items == (ITEM *)0 || !_connect(m, items)) {
				free(m);
				return ((MENU *)0);
			}
		}
		return (m);
	}
	return ((MENU *)0);
}
Example #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);
}
Example #20
0
real64 dng_matrix::MinEntry () const
	{
	
	if (IsEmpty ())
		{
		
		return 0.0;
		
		}
	
	real64 m = fData [0] [0];
	
	for (uint32 j = 0; j < Rows (); j++)
		for (uint32 k = 0; k < Cols (); k++)
			{
			
			m = Min_real64 (m, fData [j] [k]);
			
			}
			
	return m;
	
	}
Example #21
0
Void Mat::SetSize(Int nrows, Int ncols)
{
	UInt	elts = nrows * ncols;
	Assert(nrows > 0 && ncols > 0, "(Mat::SetSize) Illegal matrix size.");
	UInt	oldElts = Rows() * Cols();

	if (IsRef())
	{
		// Abort! We don't allow this operation on references.
		_Error("(Mat::SetSize) Trying to resize a matrix reference");
	}

	rows = nrows;
	cols = ncols;

	// Don't reallocate if we already have enough storage
	if (elts <= oldElts)
		return;

	// Otherwise, delete old storage and reallocate
	delete[] data;
	data = 0;
	data = new Real[elts]; // may throw an exception
}
Example #22
0
HTMLTextAreaElement::GetCols()
{
  return Cols();
}
CrsMatrix_SolverMap::NewTypeRef
CrsMatrix_SolverMap::
operator()( OriginalTypeRef orig )
{
  origObj_ = &orig;

  assert( !orig.IndicesAreGlobal() );

  //test if matrix has missing local columns in its col std::map
  const Epetra_Map & RowMap = orig.RowMap();
  const Epetra_Map & DomainMap = orig.DomainMap();
  const Epetra_Map & ColMap = orig.ColMap();
  const Epetra_Comm & Comm = RowMap.Comm();
  int NumMyRows = RowMap.NumMyElements();
  int NumCols = DomainMap.NumMyElements();
  int Match = 0;
  for( int i = 0; i < NumCols; ++i )
    if( DomainMap.GID(i) != ColMap.GID(i) )
    {
      Match = 1;
      break;
    }

  int MatchAll = 0;
  Comm.SumAll( &Match, &MatchAll, 1 );

  if( !MatchAll )
  {
    newObj_ = origObj_;
  }
  else
  {
    //create ColMap with all local rows included
    std::vector<int> Cols(NumCols);
    //fill Cols list with GIDs of all local columns 
    for( int i = 0; i < NumCols; ++i )
      Cols[i] = DomainMap.GID(i);

    //now append to Cols any ghost column entries
    int NumMyCols = ColMap.NumMyElements();
    for( int i = 0; i < NumMyCols; ++i )
      if( !DomainMap.MyGID( ColMap.GID(i) ) ) Cols.push_back( ColMap.GID(i) );
    
    int NewNumMyCols = Cols.size();
    int NewNumGlobalCols;
    Comm.SumAll( &NewNumMyCols, &NewNumGlobalCols, 1 );
    //create new column std::map
    NewColMap_ = new Epetra_Map( NewNumGlobalCols, NewNumMyCols,&Cols[0], DomainMap.IndexBase(), Comm );

    //New Graph
    std::vector<int> NumIndicesPerRow( NumMyRows );
    for( int i = 0; i < NumMyRows; ++i )
      NumIndicesPerRow[i] = orig.NumMyEntries(i);
    NewGraph_ = new Epetra_CrsGraph( Copy, RowMap, *NewColMap_, &NumIndicesPerRow[0] );

    int MaxNumEntries = orig.MaxNumEntries();
    int NumEntries;
    std::vector<int> Indices( MaxNumEntries );
    for( int i = 0; i < NumMyRows; ++i )
    {
      int RowGID = RowMap.GID(i);
      orig.Graph().ExtractGlobalRowCopy( RowGID, MaxNumEntries, NumEntries, &Indices[0] );
      NewGraph_->InsertGlobalIndices( RowGID, NumEntries, &Indices[0] );
    }
    const Epetra_Map & RangeMap = orig.RangeMap();
    NewGraph_->FillComplete(DomainMap,RangeMap);

    //intial construction of matrix 
    Epetra_CrsMatrix * NewMatrix = new Epetra_CrsMatrix( View, *NewGraph_ );

    //insert views of row values
    int * myIndices;
    double * myValues;
    int indicesCnt;
    int numMyRows = NewMatrix->NumMyRows();
    for( int i = 0; i < numMyRows; ++i )
    {
      orig.ExtractMyRowView( i, indicesCnt, myValues, myIndices );
      NewGraph_->ExtractMyRowView( i, indicesCnt, myIndices );

      NewMatrix->InsertMyValues( i, indicesCnt, myValues, myIndices );
    }

    NewMatrix->FillComplete(DomainMap,RangeMap);

    newObj_ = NewMatrix;
  }

  return *newObj_;
}
Example #24
0
int Hamiltonian::cols() const {
    return var::apply_visitor(Cols(), variant_matrix);
}