Exemplo n.º 1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
unsigned int
ListControl::columnIndexAt(const Core::Vector2& p) const
{
    unsigned int ret = 0;
    for(unsigned i = 0; i < numberOfColumns()-1; ++i)
    {
        if( (p.x() >= long(columnWidths_[i])) && (p.x() < long(columnWidths_[i+1])) ) break;
        ret++;
    }
    if(ret >= numberOfColumns()) ret = numberOfColumns()-1;

    return ret;
}
Exemplo n.º 2
0
Vector Matrix::operator*(const Vector &vector) const {
	if (vector.isTransposed() && numberOfColumns() != 1) {
		throw std::runtime_error("operator*(const Vector &vector): Vector is not transposed correctly");
	} else if (numberOfColumns() != vector.getDimension()) {
		throw std::runtime_error("operator*(const Vector &vector): Dimensions of matrix and vector do not match");
	}

	Vector result(numberOfRows(), 0.0);

	parallelForNonZeroElementsInRowOrder([&](node i, node j, double value) {
		result[i] += value * vector[j];
	});

	return result;
}
Exemplo n.º 3
0
RMatrix&  RMatrix::attachRows (const RMatrix& A)
 {
    //! \todo zcopy_ verwenden
    const LongInt n  = numberOfColumns();
    const LongInt m1 = numberOfRows();
    const LongInt m2 = A.numberOfRows();
    const LongInt m  = m1+m2; 

    RMatrix temp((*this));

    setDimension(m,n);
     
    for(LongInt j=0; j<n; j++)
     {  
        LongInt i;
        for(i=0; i<m1; i++)
         {
            (*this)(i,j) = temp(i,j);
         }
        for(i=0; i<m2; i++)
         {
            (*this)(i+m1,j) = A(i,j);
         }
     }

   return (*this);
 }
Exemplo n.º 4
0
RMatrix& RMatrix::isInverseOf(const AMatrix& s, AMatrix& w)
 {
    const AMatrixType theMatrixS = s.type();
    const AMatrixType theMatrixW = w.type();
    
    if(theMatrixS==isRMatrix && theMatrixW==isRMatrix)
     {
        const RMatrix& S = (const RMatrix&)s;
        const RMatrix& W = (const RMatrix&)w;        

        (*this) = S; 

        integer m   = numberOfRows();
        integer n   = numberOfColumns();
        integer lda = MAX(1,m);
        integer dim = MIN(m,n);
        integer info = 0; 
        integer lwork = m*n;

        integer* ipiv = new integer[dim];

        // dgetrf (&m, &n, (LongReal*) &_pelm[0], &lda, ipiv, &info);
        // dgetri (&m, (LongReal*) &_pelm[0], &lda, ipiv, (LongReal*) &W(0,0), &lwork, &info);
        info = TensorCalculus::Lapack<double>::getrf (m, n, &_pelm[0], lda, ipiv);
        info = TensorCalculus::Lapack<double>::getri (m, &_pelm[0], lda, ipiv, &W(0,0), lwork);

        delete [] ipiv;
     }
    else
     {
        throw SimpleException(IString("Warning In RMatrix::isInverseOf(const AMatrix& s, const AMatrix& w), Bad Type!!!"));     
     }

   return (*this);
 }
BufferedFTPrinter& BufferedFTPrinter::append(const endl input) {
  if (_lines.back() != (int)numberOfColumns() || _lines.back()==0) {
    _lines.push_back(0);
    _columnFormats.push_back(format::basic);
  }
  return *this;
}
Exemplo n.º 6
0
int CalculationController::indexFromCumulatedWidth(KDCoordinate offsetX) {
  int result = 0;
  int i = 0;
  while (result < offsetX && i < numberOfColumns()) {
    result += columnWidth(i++);
  }
  return (result < offsetX || offsetX == 0) ? i : i - 1;
}
Exemplo n.º 7
0
int TableViewDataSource::indexFromCumulatedWidth(KDCoordinate offsetX) {
  int result = 0;
  int i = 0;
  while (result < offsetX && i < numberOfColumns()) {
    result += columnWidth(i++);
  }
  return (result < offsetX || offsetX == 0) ? i : i - 1;
}
Exemplo n.º 8
0
double Matrix::operator()(const index &i, const index &j) const {
	if (i < 0 || i >= numberOfRows()) {
		throw std::out_of_range("Matrix(i,j): Row index out of range");
	} else if (j< 0 || j >= numberOfColumns()) {
		throw std::out_of_range("Matrix(i,j): Column index out of range");
	}

	return graph.weight(i,j);
}
Exemplo n.º 9
0
RMatrix& RMatrix::addMatrix (const AMatrix& A, const LongInt& rowIndex, const LongInt& colIndex)
 {
    const AMatrixType theMatrixA = A.type();

    LongInt m  = numberOfRows();
    LongInt n  = numberOfColumns();
    LongInt m1 = A.numberOfRows();
    LongInt n1 = A.numberOfColumns();
    
    if(theMatrixA==isRkRMatrix)
     {

        const RkRMatrix& R = (const RkRMatrix&)A;
        LongInt k = R.rank();

        LongInt mR = R.numberOfRows();
        LongInt nR = R.numberOfColumns(); 

        LongReal mike = 1.0;
      
	//  dgemm ( &notConjTrans, &conjTrans, &MIN(m,mR), &MIN(n,nR), &k, (LongReal*) &(Complex::complexUnit),
	//            (LongReal*) &(R.attr_A(rowIndex, 0)), &mR, 
        //         (LongReal*) &(R.attr_B(colIndex, 0)), &nR, (LongReal*) &(Complex::complexUnit),
	//             (LongReal*) &(*this)(0, 0), &m);
	TensorCalculus::Blas<double>::gemm (notConjTrans, conjTrans, MIN(m,mR), MIN(n,nR), k, 1.0,
	            &(R.attr_A(rowIndex, 0)), mR, 
                &(R.attr_B(colIndex, 0)), nR, 1.0,
	            &(*this)(0, 0), m);

     }
    else if(theMatrixA==isRMatrix)
     {
        const RMatrix& C = (const RMatrix&)A;        
        int ic = 1;
        for(LongInt i=0; i<n; i++)
         {
	   // daxpy (&m,  (LongReal*) &(Complex::complexUnit), (LongReal*) &C(rowIndex, colIndex+i), 
           //         &ic, (LongReal*) &(*this)(0, i), &ic);
           TensorCalculus::Blas<double>::axpy (m, 1.0, &C(rowIndex, colIndex+i), ic, &(*this)(0, i), ic);
          }
     }
    else if(theMatrixA==isHMatrixInterface)
     {    
        RMatrix C(m1, n1);

        C.isConversionOf(A);
        addMatrix(C, rowIndex, colIndex);
     }
    else
     {
        throw SimpleException(IString("Warning In RMatrix::addMatrix (const AMatrix& A, const LongInt& rowIndex, const LongInt& colIndex), Type Not Implemented !!!"));
     }    

   return (*this);
 }
Exemplo n.º 10
0
void Matrix::setValue(const index &i, const index &j, const double &value) {
	if (i < 0 || i >= numberOfRows()) {
		throw std::out_of_range("Matrix::setValue(const index &i, const index &j, const double &value): "
																						"Row index out of range");
	} else if (j< 0 || j >= numberOfColumns()) {
		throw std::out_of_range("Matrix::setValue(const index &i, const index &j, const double &value): "
																						"Column index out of range");
	}

	graph.setWeight(i, j, value);
}
Exemplo n.º 11
0
Matrix& Matrix::operator-=(const Matrix &other) {
	if (numberOfRows() != other.numberOfRows() || numberOfColumns() != other.numberOfColumns()) {
		throw std::runtime_error("Matrix::operator-=(const Matrix &other): Dimensions of matrices do not match");
	}

	other.parallelForNonZeroElementsInRowOrder([&](node i, node j, double value) {
		graph.increaseWeight(i, j, -value);
	});

	return *this;
}
Exemplo n.º 12
0
RMatrix&  RMatrix::addIdentityScaledBy (const LongReal& z)
 {
    const LongInt dim = MIN(numberOfRows(),numberOfColumns());
  
    for(LongInt i=0; i<dim; i++)
     {
        (*this)(i,i) += z;
     }

   return(*this);
 }
Exemplo n.º 13
0
Vector Matrix::row(const index &i) const {
	if (i < 0 || i >= numberOfRows()) {
		throw std::out_of_range("Matrix::row(const index &i): Row index out of range");
	}

	Vector row(numberOfColumns(), 0.0, true);
	graph.forEdgesOf(i, [&](node i, node j, double value) {
		row[j] = value;
	});

	return row;
}
Exemplo n.º 14
0
Vector Matrix::column(const index &j) const {
	if (j < 0 || j >= numberOfColumns()) {
		throw std::out_of_range("Matrix::column(const index &j): Column index out of range");
	}

	Vector column(numberOfRows());
#pragma omp parallel for
	for (node i = 0; i < numberOfRows(); ++i) {
		column[i] = graph.weight(i,j);
	}

	return column;
}
BufferedFTPrinter& BufferedFTPrinter::append(const double input) {
  _columns.push_back(FTPrinter::decimalNumberToStr(input, maxColumnWidth(_lines.back())));
  if (_lines.back() == (int)numberOfColumns()) {
    _lines.push_back(1);
    if (_columnFormats.size() == _columns.size() - 1)
      append(format::basic);
  }
  else {
    append(_columnFormats.back());
    ++(_lines.back());
  }
  return *this;
}
Exemplo n.º 16
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Window&
ListControl::resizeColumns()
{
    const float clientWidth = (size().x() - 2.0f);
    if(usingDefaultWidths_)
    {
        // set the default column widths
        const float defaultWidth = floorf(clientWidth / numberOfColumns());
        for(unsigned int i = 0; i < numberOfColumns()-1; ++i)
        {
            columnWidths_[i] = defaultWidth;
        }
        columnWidths_[numberOfColumns()-1] = 0.0f;
        columnWidths_[numberOfColumns()-1] = std::accumulate(columnWidths_.begin(), columnWidths_.end(), 0.0f);
    }
    else
    {
        const float totalWidth = std::accumulate(columnWidths_.begin(), columnWidths_.end(), 0.0f);
        columnWidths_[numberOfColumns()-1] = clientWidth - totalWidth;
    }

    return *this;
}
Exemplo n.º 17
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ListControl&
ListControl::setColumnWidths(const std::vector<float>& widths)
{
    ASSERT ( widths.size() == numberOfColumns() );

    std::vector<float>::const_iterator it;
    int index = 0;
    for(it = widths.begin(); it != widths.end(); ++it)
    {
        columnWidths_[index++] = *it;
    }

    usingDefaultWidths_ = false;

    return *this;
}
Exemplo n.º 18
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ListControl&
ListControl::addRow(const std::vector<std::string>& strings)
{
    ASSERT ( strings.size() <= numberOfColumns() );

    Row newRow(*this);
    for(unsigned i = 0; i < strings.size(); ++i)
    {
        newRow.setEntry(i, strings[i]);
    }

    rows_.push_back(newRow);

    onContentsChanged();

    return *this;
}
Exemplo n.º 19
0
bool RMatrix::partialEvaluateTransposeAt (const LongInt& i, RVector& w, const LongInt& j, const RVector& v) const
{
    bool value = true;

    integer incx = 1;
    integer n    = numberOfRows();
    integer m    = numberOfColumns();
    integer lda  = n;
    

    // dgemv (  &trans, &n, &m, (LongReal*) &(Complex::complexUnit), (LongReal*) (&_pelm[0]), 
    //          &lda, (LongReal*) &v(j), &incx, (LongReal*) &(Complex::complexUnit), 
    //         (LongReal*)&w(i), &incx
    //       );
    TensorCalculus::Blas<double>::gemv(trans, n, m, 1.0, (&_pelm[0]), lda, &v(j), incx, 1.0, &w(i), incx);

   return value;
 }
Exemplo n.º 20
0
bool RMatrix::operator () (const LongInt& i, RVector& w, const LongInt& j, const RVector& v)
 {
    bool value = true;

    integer incx = 1;
    integer m    = numberOfRows();
    integer n    = numberOfColumns();
    integer lda  = m;

    // dgemv (  correctChar(), &m, &n, (LongReal*) &(Complex::complexUnit), (LongReal*) (&_pelm[0]), 
    //         &lda, (LongReal*) &v(j), &incx, (LongReal*) &(Complex::complexUnit), 
    //         (LongReal*) &w(i), &incx
    //       );
    TensorCalculus::Blas<double>::gemv(*correctChar(), m, n, 1.0, &_pelm[0], 
            lda, &v(j), incx, 1.0, &w(i), incx);

    clearTranspose();
   return value;
 }
Exemplo n.º 21
0
RMatrix&  RMatrix::invert()
 {
    integer m   = numberOfRows();
    integer n   = numberOfColumns();
    integer lda = MAX(1,m);
    integer dim = MIN(m,n);
    integer info = 0; 

    integer* ipiv = new integer[dim];

    // dgetrf (&m, &n, (LongReal*) &_pelm[0], &lda, ipiv, &info);
    info = TensorCalculus::Lapack<double>::getrf(m, n, &_pelm[0], lda, ipiv);

    integer lwork = m*n;
    RVector work(lwork);

    // dgetri (&m, (LongReal*) &_pelm[0], &lda, ipiv, (LongReal*) &work(0), &lwork, &info);
    info = TensorCalculus::Lapack<double>::getri(m, &_pelm[0], lda, ipiv, &work(0), lwork);

    delete [] ipiv;
    
   return (*this);
 }
Exemplo n.º 22
0
RMatrix& RMatrix::attachColumns (const RMatrix& A)
 {
    const LongInt m  = numberOfRows();
    const LongInt n1 = numberOfColumns();
    const LongInt n2 = A.numberOfColumns();
    const LongInt n  = n1+n2;

    RMatrix temp((*this));
  
    setDimension(m, n);

    integer dim1 = m*n1;
    integer nx   = 1;

    // dcopy (&dim1, (LongReal*)(&temp._pelm[0]), &nx, (LongReal*)(&_pelm[0]), &nx);
    TensorCalculus::Blas<double>::copy (dim1, (&temp._pelm[0]), nx, (&_pelm[0]), nx);

    integer dim2 = m*n2;

    // dcopy (&dim2, (LongReal*)(&A._pelm[0]), &nx, (LongReal*)(&_pelm[dim1]), &nx);
    TensorCalculus::Blas<double>::copy (dim2, (&A._pelm[0]), nx, (&_pelm[dim1]), nx);

   return (*this);
 }
Exemplo n.º 23
0
Matrix Matrix::operator*(const Matrix &other) const {
	if (numberOfColumns() != other.numberOfRows()) {
		throw std::runtime_error("Matrix::operator*(const Matrix &other): Dimensions of matrices do not match");
	}

	Matrix result(numberOfRows(), other.numberOfColumns());
	SparseAccumulator spa(numberOfRows());
	for (index r = 0; r < numberOfRows(); ++r) {
		graph.forNeighborsOf(r, [&](node v, double w1){
			other.graph.forNeighborsOf(v, [&](node u, double w2){
				double value = w1 * w2;
				spa.scatter(value, u);
			});
		});

		spa.gather([&](node row, node column, double value){
			result.graph.addEdge(row, column, value);
		});

		spa.increaseRow();
	}

	return result;
}
size_t BufferedFTPrinter::maxTableWidth() const {
  size_t maxTableWidth = separator().size();
  for (size_t i = 0; i < numberOfColumns(); ++i)
    maxTableWidth += maxColumnWidth(i) + separator().size();
  return maxTableWidth;
}
Exemplo n.º 25
0
void
FWTestTableManager::implSort(int col, bool sortOrder)
{
    if(col >-1 && col < m_columns.size()) {
        std::vector<std::pair<std::string,unsigned int> > toSort;
        int nRows = numberOfRows();
        toSort.reserve(nRows);

        for(int row=0; row< nRows; ++row) {
            toSort.push_back( std::make_pair<std::string, unsigned int>(m_content[col+row*numberOfColumns()],row));
        }
        if(sortOrder) {
            std::sort(toSort.begin(),toSort.end(),std::greater<std::pair<std::string,unsigned int> >());
        } else {
            std::sort(toSort.begin(),toSort.end(),std::less<std::pair<std::string,unsigned int> >());
        }
        std::vector<unsigned int>::iterator itSort = m_sortOrder.begin();
        for(std::vector<std::pair<std::string,unsigned int> >::iterator it = toSort.begin(), itEnd=toSort.end();
                it != itEnd;
                ++it,++itSort) {
            *itSort = it->second;
        }
    }
}