const Vector<T> TriDiagonalMatrix<T>::getColumn(const int column) const
{
  if(column < 0 || column >= numColumns())
  {
    throw std::invalid_argument("Column number is invalid");
  }

  Vector<T> columnVector(numColumns());

  for(int i = 0; i < columnVector.numTerms(); i++)
  {
    columnVector[i] = 0;
  }

  if(column == 0)
  {
    columnVector[0] = data[1][column];
    columnVector[1] = data[0][column];
  }
  else if(column == numColumns() - 1)
  {
    columnVector[column - 1] = data[2][column - 1];
    columnVector[column] = data[1][column];
  }
  else
  {
    columnVector[column - 1] = data[2][column - 1];
    columnVector[column] = data[1][column];
    columnVector[column + 1] = data[0][column];
  }
  return columnVector;
}
Exemple #2
0
void PlotMatrix::alignScaleBorder( int rowOrColumn, int axis )
{
    int startDist = 0;
    int endDist = 0;

    if ( axis == QwtPlot::yLeft )
    {
        QwtPlot *p = plotAt( rowOrColumn, 0 );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );

        for ( int col = 1; col < numColumns(); col++ )
        {
            QwtPlot *p = plotAt( rowOrColumn, col );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }
    }
    else if ( axis == QwtPlot::yRight )
    {
        QwtPlot *p = plotAt( rowOrColumn, numColumns() - 1 );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );

        for ( int col = 0; col < numColumns() - 1; col++ )
        {
            QwtPlot *p = plotAt( rowOrColumn, col );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }       
    }
    if ( axis == QwtPlot::xTop )
    {
        QwtPlot *p = plotAt( rowOrColumn, 0 );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
    
        for ( int row = 1; row < numRows(); row++ )
        {
            QwtPlot *p = plotAt( row, rowOrColumn );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }   
    }   
    else if ( axis == QwtPlot::xBottom )
    {       
        QwtPlot *p = plotAt( numRows() - 1, rowOrColumn );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
    
        for ( int row = 0; row < numRows() - 1; row++ )
        {
            QwtPlot *p = plotAt( row, rowOrColumn );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }
    }
}
Exemple #3
0
 void SimpleTable::addRow( const std::vector<double>& row) {
     if (row.size() == numColumns()) {
         for (size_t colIndex  = 0; colIndex < numColumns(); colIndex++) {
             auto& col = getColumn( colIndex );
             col.addValue( row[colIndex] );
         }
     } else
         throw std::invalid_argument("Size mismatch");
 }
Exemple #4
0
void PlotMatrix::updateLayout()
{
    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plot( row, col );
            if ( p )
            {
                bool showAxis[QwtPlot::axisCnt];
                showAxis[QwtPlot::xBottom] =
                    axisEnabled( QwtPlot::xBottom ) && row == numRows() - 1;
                showAxis[QwtPlot::xTop] =
                    axisEnabled( QwtPlot::xTop ) && row == 0;
                showAxis[QwtPlot::yLeft] =
                    axisEnabled( QwtPlot::yLeft ) && col == 0;
                showAxis[QwtPlot::yRight] =
                    axisEnabled( QwtPlot::yRight ) && col == numColumns() - 1;

                for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
                {
                    if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
                        p->enableAxis( axis, showAxis[axis] );
                    else
                    {
                        p->enableAxis( axis, true );

                        QwtScaleDraw *sd = p->axisScaleDraw( axis );
                        sd->enableComponent(
                            QwtScaleDraw::Backbone, showAxis[axis] );
                        sd->enableComponent(
                            QwtScaleDraw::Ticks, showAxis[axis] );
                        sd->enableComponent(
                            QwtScaleDraw::Labels, showAxis[axis] );
                    }
                }
            }
        }
    }

    for ( int col = 0; col < numColumns(); col++ )
    {
        alignVAxes( col, QwtPlot::yLeft );
        alignVAxes( col, QwtPlot::yRight );
    }

    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plot( row, col );
            if ( p )
                p->replot();
        }
    }
}
Exemple #5
0
void PlotMatrix::updateLayout()
{
    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plotAt( row, col );
            if ( p )
            {
                bool showAxis[QwtPlot::axisCnt];
                showAxis[QwtPlot::xBottom] =
                    axisEnabled( QwtPlot::xBottom ) && row == numRows() - 1;
                showAxis[QwtPlot::xTop] =
                    axisEnabled( QwtPlot::xTop ) && row == 0;
                showAxis[QwtPlot::yLeft] =
                    axisEnabled( QwtPlot::yLeft ) && col == 0;
                showAxis[QwtPlot::yRight] =
                    axisEnabled( QwtPlot::yRight ) && col == numColumns() - 1;

                for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
                {
                    enablePlotAxis( p, axis, showAxis[axis] );
                }
            }
        }
    }

    for ( int row = 0; row < numRows(); row++ )
    {
        alignAxes( row, QwtPlot::xTop );
        alignAxes( row, QwtPlot::xBottom );

        alignScaleBorder( row, QwtPlot::yLeft );
        alignScaleBorder( row, QwtPlot::yRight );
    }

    for ( int col = 0; col < numColumns(); col++ )
    {
        alignAxes( col, QwtPlot::yLeft );
        alignAxes( col, QwtPlot::yRight );

        alignScaleBorder( col, QwtPlot::xBottom );
        alignScaleBorder( col, QwtPlot::xTop );
    }

    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plotAt( row, col );
            if ( p )
                p->replot();
        }
    }
}
Exemple #6
0
void SMat<CoeffRing>::addInPlace(const SMat<CoeffRing> &B)
// return this + B.  return NULL of sizes or types do not match.
{
  assert(&B.ring() == &ring());
  assert(B.numRows() == numRows());
  assert(B.numColumns() == numColumns());

  for (size_t c = 0; c < numColumns(); c++)
    {
      sparsevec *v = vec_copy(B.columns_[c]);
      vec_add_to(columns_[c], v);
    }
}
Exemple #7
0
bool SMat<CoeffRing>::is_equal(const SMat &B) const
{
  assert(&ring() == &B.ring());
  if (B.numRows() != numRows()) return false;
  if (B.numColumns() != numColumns()) return false;
  for (size_t c = 0; c < numColumns(); c++)
    {
      sparsevec *v = columns_[c];
      sparsevec *w = B.columns_[c];
      if (!vec_equals(v, w)) return false;
    }
  return true;
}
Exemple #8
0
void WTable::printDebug()
{
  std::cerr << "Table: "
	    << formName() << " " << numRows() << "x" << numColumns()
	    << std::endl;
  
  for (int i = 0; i < numRows(); ++i) {
    for (int j = 0; j < numColumns(); ++j) {
      std::cerr << "(" << i << "," << j << "): "
		<< itemAt(i, j).cell << std::endl;
    }
  }
}
Exemple #9
0
void SMat<CoeffRing>::subtractInPlace(const SMat<CoeffRing> &B)
// this -= B.
// assumption:the assert statements below:
{
  assert(&B.ring() == &ring());
  assert(B.numRows() == numRows());
  assert(B.numColumns() == numColumns());

  for (size_t c = 0; c < numColumns(); c++)
    {
      sparsevec *v = vec_copy(B.columns_[c]);
      vec_negate(v);
      vec_add_to(columns_[c], v);
    }
}
Exemple #10
0
unsigned SparseMatrix::copyCCS(long*& colptr, long*& index, double*& value) const {
	unsigned N = numNonZeros();
	colptr = (long int*) malloc((numColumns() + 1) * sizeof(long int));
	index  = (long int*) malloc(N * sizeof(long int));
	value  = (double*) malloc(N * sizeof(double));
	
	colptr[0] = 0;
	for (unsigned i = 0; i < numColumns(); ++i) {
        SparseArray col = getColumn(i);
		int offset = col.numNonZeros();
        col.copy( &(index[colptr[i]]), &(value[colptr[i]]) );
		colptr[i+1] = colptr[i] + offset;
	}
	return N;
}
Exemple #11
0
// ==========================================================================
// MODIFIERS
void Board::setTile(int i, int j, Tile* t) {
  assert (i >= 0 && i < numRows());
  assert (j >= 0 && j < numColumns());
  //assert (t != NULL);
  //assert (board[i][j] == NULL);
  board[i][j] = t;
}
Exemple #12
0
SparseMatrix SparseMatrix::multiply(const double b) const 
{
    SparseMatrix c(numRows(), numColumns());
    for (unsigned i=0; i<numRows(); ++i)
        c.setRow(i, getRow(i) * b);
    return c;    
}
Exemple #13
0
void WTable::expand(int row, int column, int rowSpan, int columnSpan)
{
  int newNumRows = row + rowSpan;
  int curNumColumns = numColumns();
  int newNumColumns = std::max(curNumColumns, column + columnSpan);

  if ((newNumRows > numRows())
      || (newNumColumns > curNumColumns)) {
    gridChanged_ = true;
    repaint();

    for (int row = numRows(); row < newNumRows; ++row) {
      rows_.push_back(new WTableRow(this, newNumColumns));
    }

    if (newNumColumns > curNumColumns) {
      for (int row = 0; row < numRows(); ++row) {
	WTableRow *tr = rows_[row];
	tr->expand(newNumColumns);
      }
    }
  }

  //printDebug();
}
Exemple #14
0
void SMat<CoeffRing>::negateInPlace()
// this = -this
{
  for (size_t c = 0; c < numColumns(); c++)
    for (sparsevec *p = columns_[c]; p != NULL; p = p->next)
      ring().negate(p->coeff, p->coeff);
}
Exemple #15
0
int ServerConfig::adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const
{
	if (screens()[idx].isNull())
		return -1;

	// if we're at the left or right end of the table, don't find results going further left or right
	if ((deltaColumn > 0 && (idx+1) % numColumns() == 0)
			|| (deltaColumn < 0 && idx % numColumns() == 0))
		return -1;

	int arrayPos = idx + deltaColumn + deltaRow * numColumns();

	if (arrayPos >= screens().size() || arrayPos < 0)
		return -1;

	return arrayPos;
}
Exemple #16
0
const QwtPlot* PlotMatrix::plot( int row, int column ) const
{
    const int index = row * numColumns() + column;
    if ( index < d_data->plotWidgets.size() )
        return d_data->plotWidgets[index];

    return NULL;
}
Exemple #17
0
    void fill(T const & value)
    {
      long nr = numRows(), nc = numColumns();

      for (long r = 0; r < nr; ++r)
      {
        T * scanline = static_cast<T *>(image->getScanLine(r));
        std::fill(scanline, scanline + nc, value);
      }
    }
Exemple #18
0
// create table from single record
void SimpleTable::init(Opm::DeckItemConstPtr deckItem,
                       const std::vector<std::string> &columnNames)
{
    createColumns(columnNames);

    if ( (deckItem->size() % numColumns()) != 0)
        throw std::runtime_error("Number of columns in the data file is"
                                 "inconsistent with the ones specified");
    {
        size_t rows = deckItem->size() / numColumns();
        for (size_t rowIdx = 0; rowIdx < rows; rowIdx++) {
            for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) {
                size_t deckItemIdx = rowIdx*numColumns() + colIdx;
                m_columns[colIdx].push_back( deckItem->getSIDouble(deckItemIdx) );
                m_valueDefaulted[colIdx].push_back( deckItem->defaultApplied(deckItemIdx) );
            }
        }
    }
}
Vector<T> TriDiagonalMatrix<T>::getRow(int x) const
{
  Vector<T> vect(numColumns());

  if(x < 0 || x >= rows)
  {
    throw std::invalid_argument("TriDiagonal [] error: Out of bounds");
  }

  for(int i = 0; i < numColumns(); i++)
  {
    vect[i] = 0;
  }

  int numData = 3, startingDiag = 0, vectStartSpot = x - 1;
  if(x == 0)
  {
    numData = 2;
    startingDiag = 1;
    vectStartSpot = 0;
  }
  else if(x == 1)
  {
    vectStartSpot = 0;
  }
  else if(x == rows - 1)
  {
    numData = 2;
    startingDiag = 0;
    vectStartSpot = columns - 2;
  }

  vectStartSpot = vectStartSpot < 0 ? 0 : vectStartSpot;
  for(int i = 0; i < numData; i++)
  {
    vect[vectStartSpot] = data[startingDiag][startingDiag == 0 ? x - 1 : x];
    startingDiag++;
    vectStartSpot++;
  }

  return vect;
}
Exemple #20
0
void WTable::deleteRow(int row)
{
  for (int i = 0; i < numColumns(); ++i)
    delete rows_[row]->cells_[i].cell;

  delete rows_[row];
  rows_.erase(rows_.begin() + row);

  gridChanged_ = true;
  repaint();
}
Exemple #21
0
DomElement *WTable::createDomElement()
{
  //printDebug();

  DomElement *table = DomElement::createNew(DomElement::TABLE);
  table->setId(this);
  DomElement *tbody = DomElement::createNew(DomElement::TBODY);

  for (unsigned row = 0; row < (unsigned)numRows(); ++row)
    for (unsigned col = 0; col < (unsigned)numColumns(); ++col)
      itemAt(row, col).overSpanned = false;
  
  for (unsigned row = 0; row < (unsigned)numRows(); ++row) {
    DomElement *tr = DomElement::createNew(DomElement::TR);
    tr->setId(rows_[row]);
    
    for (unsigned col = 0; col < (unsigned)numColumns(); ++col) {
      WTableRow::TableData& d = itemAt(row, col);

      if (!d.overSpanned) {
	DomElement *td = d.cell->createSDomElement();
	tr->addChild(td);

	for (int i = 0; i < d.cell->rowSpan(); ++i)
	  for (int j = 0; j < d.cell->columnSpan(); ++j)
	    if (i + j > 0)
	      itemAt(row + i, col + j).overSpanned = true;
      }
    }

    tbody->addChild(tr);
  }

  table->addChild(tbody);

  updateDom(*table, true);

  gridChanged_ = false;

  return table;
}
Exemple #22
0
SparseMatrix SparseMatrix::getTranspose() const {
    SparseMatrix transpose(numColumns(), numRows());
    for (unsigned i=0; i<numRows(); ++i) {
        unsigned nnz = _row[i].numNonZeros();
        for (unsigned j=0; j<nnz; ++j) {
            int  index = _row[i].readIndex(j);
            double value = _row[i].readValue(j);
            transpose._row[index].insert(i, value);
        }
    }
    return transpose;
}
Exemple #23
0
    void SimpleTable::init( const DeckItem& deckItem ) {
        this->addColumns();

        if ( (deckItem.size() % numColumns()) != 0)
            throw std::runtime_error("Number of columns in the data file is"
                    "inconsistent with the ones specified");

        size_t rows = deckItem.size() / numColumns();
        for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) {
            auto& column = getColumn( colIdx );
            for (size_t rowIdx = 0; rowIdx < rows; rowIdx++) {
                size_t deckItemIdx = rowIdx*numColumns() + colIdx;
                if (deckItem.defaultApplied(deckItemIdx))
                    column.addDefault( );
                else
                    column.addValue( deckItem.getSIDouble(deckItemIdx) );
            }
            if (colIdx > 0)
                column.applyDefaults(getColumn( 0 ));
        }
    }
Exemple #24
0
void ServerConfig::init()
{
	switchCorners().clear();
	screens().clear();

	// m_NumSwitchCorners is used as a fixed size array. See Screen::init()
	for (int i = 0; i < NumSwitchCorners; i++)
		switchCorners() << false;

	// There must always be screen objects for each cell in the screens QList. Unused screens
	// are identified by having an empty name.
	for (int i = 0; i < numColumns() * numRows(); i++)
		addScreen(Screen());
}
Exemple #25
0
MainWindow::MainWindow():
    PlotMatrix(3, 4)
{
    enableAxis(QwtPlot::yLeft);
    enableAxis(QwtPlot::yRight);
    enableAxis(QwtPlot::xBottom);

    for ( int row = 0; row < numRows(); row++ )
    {
        const double v = qPow(10.0, row);
        setAxisScale(QwtPlot::yLeft, row, -v, v);
        setAxisScale(QwtPlot::yRight, row, -v, v);
    }

    for ( int col = 0; col < numColumns(); col++ )
    {
        const double v = qPow(10.0, col);
        setAxisScale(QwtPlot::xBottom, col, -v, v);
        setAxisScale(QwtPlot::xTop, col, -v, v);
    }

    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *plt = plot(row, col);
            plt->setCanvasBackground(QColor(Qt::darkBlue));

            QwtPlotGrid *grid = new QwtPlotGrid();
            grid->enableXMin(true);
            grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
            grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
            grid->attach(plt);
        }
    }
}
Exemple #26
0
// ==========================================================================
// PRINTING
void Board::Print() const {
  for (int b = 0; b < numRows(); b++) {
    for (int i = 0; i < GLOBAL_TILE_SIZE; i++) {
      for (int j = 0; j < numColumns(); j++) {
        if (board[b][j] != NULL) {
          board[b][j]->rotate(board[b][j]->getRotation()).printRow(std::cout,i);
        } else {
          std::cout << std::string(GLOBAL_TILE_SIZE,' ');
        }
      }
      std::cout << "\n";
    }
  }
  fflush(stdout);
}
Exemple #27
0
void ServerConfig::saveSettings()
{
	settings().beginGroup("internalConfig");
	settings().remove("");

	settings().setValue("numColumns", numColumns());
	settings().setValue("numRows", numRows());

	settings().setValue("hasHeartbeat", hasHeartbeat());
	settings().setValue("heartbeat", heartbeat());
	settings().setValue("relativeMouseMoves", relativeMouseMoves());
	settings().setValue("screenSaverSync", screenSaverSync());
	settings().setValue("win32KeepForeground", win32KeepForeground());
	settings().setValue("hasSwitchDelay", hasSwitchDelay());
	settings().setValue("switchDelay", switchDelay());
	settings().setValue("hasSwitchDoubleTap", hasSwitchDoubleTap());
	settings().setValue("switchDoubleTap", switchDoubleTap());
	settings().setValue("switchCornerSize", switchCornerSize());
	settings().setValue("ignoreAutoConnectClient", ignoreAutoConnectClient());

	writeSettings(settings(), switchCorners(), "switchCorner");

	settings().beginWriteArray("screens");
	for (int i = 0; i < screens().size(); i++)
	{
		settings().setArrayIndex(i);
		screens()[i].saveSettings(settings());
	}
	settings().endArray();

	settings().beginWriteArray("hotkeys");
	for (int i = 0; i < hotkeys().size(); i++)
	{
		settings().setArrayIndex(i);
		hotkeys()[i].saveSettings(settings());
	}
	settings().endArray();

	settings().endGroup();
}
Exemple #28
0
 sparsevec *column(size_t c)
 {
   assert(c < numColumns());
   return columns_[c];
 }
Exemple #29
0
void SMat<CoeffRing>::scalarMultInPlace(const elem &f)
// this = f * this
{
  for (size_t c = 0; c < numColumns(); c++) vec_scale(columns_[c], f);
}
Exemple #30
0
void PlotMatrix::scaleDivChanged()
{
    if ( d_data->inScaleSync )
        return;

    d_data->inScaleSync = true;

    QwtPlot *plt = NULL;
    int axisId = -1;
    int rowOrColumn = -1;

    // find the changed axis
    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plot( row, col );
            if ( p )
            {
                for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
                {
                    if ( p->axisWidget( axis ) == sender() )
                    {
                        plt = p;
                        axisId = axis;
                        if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
                            rowOrColumn = col;
                        else
                            rowOrColumn = row;

                    }
                }
            }
        }
    }

    if ( plt )
    {

        // synchronize the axes
        if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
        {
            for ( int row = 0; row < numRows(); row++ )
            {
                QwtPlot *p = plot( row, rowOrColumn );
                if ( p != plt )
                    p->setAxisScaleDiv( axisId, plt->axisScaleDiv( axisId ) );
            }
        }
        else
        {
            for ( int col = 0; col < numColumns(); col++ )
            {
                QwtPlot *p = plot( rowOrColumn, col );
                if ( p != plt )
                    p->setAxisScaleDiv( axisId, plt->axisScaleDiv( axisId ) );
            }
        }

        updateLayout();
    }

    d_data->inScaleSync = false;
}