コード例 #1
0
  void DenseGenMatrix::PrintImpl(const Journalist& jnlst,
                                 EJournalLevel level,
                                 EJournalCategory category,
                                 const std::string& name,
                                 Index indent,
                                 const std::string& prefix) const
  {
    jnlst.Printf(level, category, "\n");
    jnlst.PrintfIndented(level, category, indent,
                         "%sDenseGenMatrix \"%s\" with %d rows and %d columns:\n",
                         prefix.c_str(), name.c_str(), NRows(), NCols());

    if (initialized_) {
      for (Index j=0; j<NCols(); j++) {
        for (Index i=0; i<NRows(); i++) {
          jnlst.PrintfIndented(level, category, indent,
                               "%s%s[%5d,%5d]=%23.16e\n",
                               prefix.c_str(), name.c_str(), i, j, values_[i+NRows()*j]);
        }
      }
    }
    else {
      jnlst.PrintfIndented(level, category, indent,
                           "The matrix has not yet been initialized!\n");
    }
  }
コード例 #2
0
  void MultiVectorMatrix::LRMultVector(Number alpha, const Vector &x,
                                       Number beta, Vector &y) const
  {
    DBG_START_METH("MultiVectorMatrix::LRMultVector(",
                   dbg_verbosity);

    DBG_ASSERT(NRows()==x.Dim());
    DBG_ASSERT(NRows()==y.Dim());

    DBG_PRINT((1, "alpha = %e beta = %e\n", alpha, beta));
    DBG_PRINT_VECTOR(2, "x", x);

    if ( beta!=0.0 ) {
      y.Scal(beta);
    }
    else {
      y.Set(0.0);
    }

    DBG_PRINT_VECTOR(2, "beta*y", y);
    for (Index i=0; i<NCols(); i++) {
      DBG_PRINT_VECTOR(2, "ConstVec(i)", *ConstVec(i));
      y.AddOneVector(alpha*ConstVec(i)->Dot(x), *ConstVec(i), 1.);
      DBG_PRINT_VECTOR(2, "y mid", y);
    }
  }
コード例 #3
0
  void DenseSymMatrix::PrintImpl(const Journalist& jnlst,
                                 EJournalLevel level,
                                 EJournalCategory category,
                                 const std::string& name,
                                 Index indent,
                                 const std::string& prefix) const
  {
    jnlst.Printf(level, category, "\n");
    jnlst.PrintfIndented(level, category, indent,
                         "%sDenseSymMatrix \"%s\" of dimension %d (only lower triangular part printed):\n",
                         prefix.c_str(), name.c_str(), Dim());

    if (initialized_) {
      for (Index j=0; j<NCols(); j++) {
        for (Index i=j; i<NRows(); i++) {
          jnlst.PrintfIndented(level, category, indent,
                               "%s%s[%5d,%5d]=%23.16e\n",
                               prefix.c_str(), name.c_str(), i, j, values_[i+NRows()*j]);
        }
      }
    }
    else {
      jnlst.PrintfIndented(level, category, indent,
                           "The matrix has not yet been initialized!\n");
    }
  }
コード例 #4
0
  void DenseGenMatrix::Copy(const DenseGenMatrix& M)
  {
    DBG_ASSERT(NCols()==M.NCols());
    DBG_ASSERT(NRows()==M.NRows());

    IpBlasDcopy(NCols()*NRows(), M.Values(), 1, values_, 1);
    initialized_ = true;
    ObjectChanged();
  }
コード例 #5
0
  void DenseGenMatrix::CholeskySolveMatrix(DenseGenMatrix& B) const
  {
    DBG_ASSERT(NRows()==NCols());
    DBG_ASSERT(B.NRows()==NRows());
    DBG_ASSERT(initialized_);

    Number* Bvalues = B.Values();

    IpLapackDpotrs(NRows(), B.NCols(), values_, NRows(), Bvalues, B.NRows());
  }
コード例 #6
0
  void DenseGenMatrix::CholeskySolveVector(DenseVector& b) const
  {
    DBG_ASSERT(NRows()==NCols());
    DBG_ASSERT(b.Dim()==NRows());
    DBG_ASSERT(initialized_);

    Number* bvalues = b.Values();

    IpLapackDpotrs(NRows(), 1, values_, NRows(), bvalues, b.Dim());
  }
コード例 #7
0
ファイル: IpDenseGenMatrix.cpp プロジェクト: BRAINSia/calatk
  void DenseGenMatrix::LUSolveVector(DenseVector& b) const
  {
    DBG_ASSERT(NRows()==NCols());
    DBG_ASSERT(b.Dim()==NRows());
    DBG_ASSERT(initialized_);
    DBG_ASSERT(factorization_==LU);

    Number* bvalues = b.Values();

    IpLapackDgetrs(NRows(), 1, values_, NRows(), pivot_, bvalues, b.Dim());
  }
コード例 #8
0
  void DenseGenMatrix::ScaleColumns(const DenseVector& scal_vec)
  {
    DBG_ASSERT(scal_vec.Dim() == NCols());
    DBG_ASSERT(initialized_);

    const Number* scal_values = scal_vec.Values();

    for (Index j=0; j<NCols(); j++) {
      IpBlasDscal(NRows(), scal_values[j], &values_[j*NRows()], 1);
    }
    ObjectChanged();
  }
コード例 #9
0
  void DenseGenMatrix::CholeskyBackSolveMatrix(bool trans, Number alpha,
      DenseGenMatrix& B) const
  {
    DBG_ASSERT(NRows()==NCols());
    DBG_ASSERT(B.NRows()==NRows());
    DBG_ASSERT(initialized_);

    Number* Bvalues = B.Values();

    IpBlasDtrsm(trans, NRows(), B.NCols(), alpha,
                values_, NRows(), Bvalues, B.NRows());
  }
コード例 #10
0
ファイル: IpDenseGenMatrix.cpp プロジェクト: BRAINSia/calatk
  void DenseGenMatrix::LUSolveMatrix(DenseGenMatrix& B) const
  {
    DBG_ASSERT(NRows()==NCols());
    DBG_ASSERT(B.NRows()==NRows());
    DBG_ASSERT(initialized_);
    DBG_ASSERT(factorization_==LU);

    Number* Bvalues = B.Values();

    IpLapackDgetrs(NRows(), B.NCols(), values_, NRows(), pivot_, Bvalues,
                   B.NRows());
  }
コード例 #11
0
  void DenseGenMatrix::FillIdentity(Number factor /*=1.*/)
  {
    DBG_ASSERT(NCols()==NRows());

    const Number zero = 0.;
    IpBlasDcopy(NCols()*NRows(), &zero, 0, values_, 1);

    if (factor!=0.) {
      for (Index i=0; i<NRows(); i++) {
        values_[i + i*NRows()] = factor;
      }
    }
    ObjectChanged();
    initialized_ = true;
  }
コード例 #12
0
  bool DenseGenMatrix::ComputeEigenVectors(const DenseSymMatrix& M,
      DenseVector& Evalues)
  {
    Index dim = M.Dim();
    DBG_ASSERT(Evalues.Dim()==dim);
    DBG_ASSERT(NRows()==dim);
    DBG_ASSERT(NCols()==dim);

    // First we copy the content of the matrix into Q
    const Number* Mvalues = M.Values();
    for (Index j=0; j<dim; j++) {
      for (Index i=j; i<dim; i++) {
        values_[i+j*dim] = Mvalues[i+j*dim];
      }
    }

    bool compute_eigenvectors = true;
    Number* Evals = Evalues.Values();
    Index info;
    IpLapackDsyev(compute_eigenvectors, dim, values_,
                  dim, Evals, info);

    initialized_ = (info==0);
    ObjectChanged();
    return (info==0);
  }
コード例 #13
0
ファイル: IpDenseGenMatrix.cpp プロジェクト: BRAINSia/calatk
  void DenseGenMatrix::ComputeColAMaxImpl(Vector& cols_norms, bool init) const
  {
    //  A few sanity checks
    DBG_ASSERT(initialized_);

    DenseVector* dense_vec = static_cast<DenseVector*>(&cols_norms);
    DBG_ASSERT(dynamic_cast<DenseVector*>(&cols_norms));
    Number* vec_vals=dense_vec->Values();

    const double* vals = values_;
    for (Index jcol=0; jcol<NCols(); jcol++) {
      Index i = IpBlasIdamax(NRows(), vals, 1);
      vec_vals[jcol] = Max(vec_vals[jcol], fabs(vals[i]));
      vals += NRows();
    }
  }
コード例 #14
0
ファイル: IpDenseGenMatrix.cpp プロジェクト: BRAINSia/calatk
  bool DenseGenMatrix::ComputeLUFactorInPlace()
  {
    Index dim = NRows();
    DBG_ASSERT(dim==NCols());

    DBG_ASSERT(factorization_==NONE);

    ObjectChanged();

    // create pivot space
    delete [] pivot_;
    pivot_ = NULL; // set to NULL so that destructor will not try to
    // delete again if the new in following line fails
    pivot_ = new Index[dim];

    // call the lapack subroutine for the factorization (dgetrf )
    Index info;
    IpLapackDgetrf(dim, values_, pivot_, dim, info);

    DBG_ASSERT(info>=0);
    if (info!=0) {
      delete [] pivot_;
      pivot_ = NULL;
      initialized_ = false;
      return false;
    }
    else {
      initialized_ = true;
    }

    factorization_ = LU;
    return true;
  }
コード例 #15
0
ファイル: DataMat.cpp プロジェクト: karticsubr/FAS2016
const DataMat&  DataMat::operator *= (double d) 
{
    	for (int i(0); i<NRows(); i++)
		for(int j(0); j<NCols(); j++)
			_V[i][j] *= d ;
    return *this ;
}
コード例 #16
0
  void MultiVectorMatrix::TransMultVectorImpl(Number alpha, const Vector &x,
      Number beta, Vector &y) const
  {
    //  A few sanity checks
    DBG_ASSERT(NCols()==y.Dim());
    DBG_ASSERT(NRows()==x.Dim());

    // See if we can understand the data
    DenseVector* dense_y = static_cast<DenseVector*>(&y);
    DBG_ASSERT(dynamic_cast<DenseVector*>(&y));

    // Use the individual dot products to get the matrix (transpose)
    // vector product
    Number *yvals=dense_y->Values();
    if ( beta!=0.0 ) {
      for (Index i=0; i<NCols(); i++) {
        yvals[i] = alpha*ConstVec(i)->Dot(x) + beta*yvals[i];
      }
    }
    else {
      for (Index i=0; i<NCols(); i++) {
        yvals[i] = alpha*ConstVec(i)->Dot(x);
      }
    }
  }
コード例 #17
0
  void
  MultiVectorMatrix::AddRightMultMatrix(Number a,
                                        const MultiVectorMatrix& U,
                                        const Matrix& C,
                                        Number b)
  {
    DBG_ASSERT(NRows()==U.NRows());
    DBG_ASSERT(U.NCols()==C.NRows());
    DBG_ASSERT(NCols()==C.NCols());

    if (b==0.) {
      FillWithNewVectors();
    }

    // ToDo: For now, we simply use MatrixVector multiplications, but
    // we might be more efficient (at least in the non-parallel case)
    // if we used Level 3 Blas
    SmartPtr<const DenseVectorSpace> mydspace = new DenseVectorSpace(C.NRows());
    SmartPtr<DenseVector> mydvec = mydspace->MakeNewDenseVector();

    const DenseGenMatrix* dgm_C = static_cast<const DenseGenMatrix*>(&C);
    DBG_ASSERT(dynamic_cast<const DenseGenMatrix*>(&C));
    for (Index i=0; i<NCols(); i++) {
      const Number* CValues = dgm_C->Values();
      Number* myvalues = mydvec->Values();
      for (Index j=0; j<U.NCols(); j++) {
        myvalues[j] = CValues[i*C.NRows() + j];
      }
      U.MultVector(a, *mydvec, b, *Vec(i));
    }
    ObjectChanged();
  }
コード例 #18
0
  void MultiVectorMatrix::MultVectorImpl(Number alpha, const Vector &x,
                                         Number beta, Vector &y) const
  {
    //  A few sanity checks
    DBG_ASSERT(NCols()==x.Dim());
    DBG_ASSERT(NRows()==y.Dim());

    // Take care of the y part of the addition
    if ( beta!=0.0 ) {
      y.Scal(beta);
    }
    else {
      y.Set(0.0);  // In case y hasn't been initialized yet
    }

    // See if we can understand the data
    const DenseVector* dense_x = static_cast<const DenseVector*>(&x);
    DBG_ASSERT(dynamic_cast<const DenseVector*>(&x));

    // We simply add all the Vectors one after the other
    if (dense_x->IsHomogeneous()) {
      Number val = dense_x->Scalar();
      for (Index i=0; i<NCols(); i++) {
        y.AddOneVector(alpha*val, *ConstVec(i), 1.);
      }
    }
    else {
      const Number* values = dense_x->Values();
      for (Index i=0; i<NCols(); i++) {
        y.AddOneVector(alpha*values[i], *ConstVec(i), 1.);
      }
    }
  }
コード例 #19
0
 void GenTMatrix::PrintImplOffset(const Journalist& jnlst,
                                  EJournalLevel level,
                                  EJournalCategory category,
                                  const std::string& name,
                                  Index indent,
                                  const std::string& prefix,
                                  Index offset) const
 {
   jnlst.Printf(level, category, "\n");
   jnlst.PrintfIndented(level, category, indent,
                        "%sGenTMatrix \"%s\" of dimension %d by %d with %d nonzero elements:\n",
                        prefix.c_str(), name.c_str(), NRows(), NCols(), Nonzeros());
   if (initialized_) {
     for (Index i=0; i<Nonzeros(); i++) {
       jnlst.PrintfIndented(level, category, indent,
                            "%s%s[%5d,%5d]=%23.16e  (%d)\n",
                            prefix.c_str(), name.c_str(), Irows()[i]+offset,
                            Jcols()[i], values_[i], i);
     }
   }
   else {
     jnlst.PrintfIndented(level, category, indent,
                          "%sUninitialized!\n", prefix.c_str());
   }
 }
コード例 #20
0
void SymTMatrix::ComputeRowAMaxImpl(
   Vector& rows_norms,
   bool    init
   ) const
{
   DBG_ASSERT(initialized_);

   DenseVector* dense_vec = static_cast<DenseVector*>(&rows_norms);
   DBG_ASSERT(dynamic_cast<DenseVector*>(&rows_norms));

   const Index* irn = Irows();
   const Index* jcn = Jcols();
   const Number* val = values_;
   Number* vec_vals = dense_vec->Values();
   vec_vals--;

   const Number zero = 0.;
   IpBlasDcopy(NRows(), &zero, 0, vec_vals, 1);

   for( Index i = 0; i < Nonzeros(); i++ )
   {
      const double f = fabs(*val);
      vec_vals[*irn] = Max(vec_vals[*irn], f);
      vec_vals[*jcn] = Max(vec_vals[*jcn], f);
      val++;
      irn++;
      jcn++;
   }
}
コード例 #21
0
ファイル: IpCompoundMatrix.cpp プロジェクト: MengbinZhu/pfldp
  bool CompoundMatrixSpace::DimensionsSet() const
  {
    DBG_START_METH("CompoundMatrixSpace::DimensionsSet", 0);
    Index total_nrows = 0;
    Index total_ncols = 0;
    bool valid = true;
    for (Index i=0; i<ncomps_rows_; i++) {
      if (block_rows_[i] == -1) {
        valid = false;
        break;
      }
      total_nrows += block_rows_[i];
    }
    if (valid) {
      for (Index j=0; j<ncomps_cols_; j++) {
        if (block_cols_[j] == -1) {
          valid = false;
          break;
        }
        total_ncols += block_cols_[j];
      }
    }

    if (valid) {
      DBG_ASSERT(total_nrows == NRows() && total_ncols == NCols());
    }

    return valid;
  }
コード例 #22
0
 // empties all rows' infos
 void ClearRowInfo(void) const
 {
     for (unsigned int r=0; r<NRows(); ++r) {
         rowDoubles[r] = 0.0;
         rowStrings[r].erase();
     }
 }
コード例 #23
0
 DenseSymMatrix::DenseSymMatrix(const DenseSymMatrixSpace* owner_space)
     :
     SymMatrix(owner_space),
     owner_space_(owner_space),
     values_(new Number[NCols()*NRows()]),
     initialized_(false)
 {}
コード例 #24
0
  void DenseSymMatrix::MultVectorImpl(Number alpha, const Vector &x,
                                      Number beta, Vector &y) const
  {
    //  A few sanity checks
    DBG_ASSERT(NCols()==x.Dim());
    DBG_ASSERT(NRows()==y.Dim());
    DBG_ASSERT(initialized_);

    // See if we can understand the data
    const DenseVector* dense_x = static_cast<const DenseVector*>(&x);
    DBG_ASSERT(dynamic_cast<const DenseVector*>(&x));
    DenseVector* dense_y = static_cast<DenseVector*>(&y);
    DBG_ASSERT(dynamic_cast<DenseVector*>(&y));

    IpBlasDsymv(Dim(), alpha, values_, NRows(),
                dense_x->Values(), 1, beta, dense_y->Values(), 1);
  }
コード例 #25
0
ファイル: DataMat.cpp プロジェクト: karticsubr/FAS2016
const DataMat&  DataMat::Assign (const DataMat& D, double d) 
{
	int minNR(min(NRows(), D.NRows())), minNC(min(NCols(), D.NCols())) ;        
	for (int i(0); i<minNR; i++)
		for(int j(0); j<minNC; j++)
			_V[i][j] = d*D._V[i][j] ;

	return *this ;
}
コード例 #26
0
ファイル: IpDenseGenMatrix.cpp プロジェクト: BRAINSia/calatk
 DenseGenMatrix::DenseGenMatrix(const DenseGenMatrixSpace* owner_space)
     :
     Matrix(owner_space),
     owner_space_(owner_space),
     values_(new Number[NCols()*NRows()]),
     initialized_(false),
     factorization_(NONE),
     pivot_(NULL)
 {}
コード例 #27
0
ファイル: DataMat.cpp プロジェクト: karticsubr/FAS2016
const DataMat&  DataMat::operator -= (const DataMat& D) 
{
	int minNR(min(NRows(), D.NRows())), minNC(min(NCols(), D.NCols())) ;
	for (int i(0); i<minNR; i++)
		for(int j(0); j<minNC; j++)
			_V[i][j] -= D._V[i][j] ;

	return *this ;
}
コード例 #28
0
  void MultiVectorMatrix::ScaleRows(const Vector& scal_vec)
  {
    // Santiy checks
    DBG_ASSERT(scal_vec.Dim() == NRows());

    for (Index i=0; i<NCols(); i++) {
      Vec(i)->ElementWiseMultiply(scal_vec);
    }
    ObjectChanged();
  }
コード例 #29
0
ファイル: IpZeroMatrix.cpp プロジェクト: BRAINSia/calatk
 void ZeroMatrix::PrintImpl(const Journalist& jnlst,
                            EJournalLevel level,
                            EJournalCategory category,
                            const std::string& name,
                            Index indent,
                            const std::string& prefix) const
 {
   jnlst.Printf(level, category, "\n");
   jnlst.PrintfIndented(level, category, indent,
                        "%sZeroMatrix \"%s\" with %d row and %d column components:\n",
                        prefix.c_str(), name.c_str(), NRows(), NCols());
 }
コード例 #30
0
  void DenseGenMatrix::HighRankUpdateTranspose(Number alpha,
      const MultiVectorMatrix& V1,
      const MultiVectorMatrix& V2,
      Number beta)
  {
    DBG_ASSERT(NRows()==V1.NCols());
    DBG_ASSERT(NCols()==V2.NCols());
    DBG_ASSERT(beta==0. || initialized_);

    if (beta==0.) {
      for (Index j=0; j<NCols(); j++) {
        for (Index i=0; i<NRows(); i++) {
          values_[i+j*NRows()] = alpha*V1.GetVector(i)->Dot(*V2.GetVector(j));
        }
      }
    }
    else {
      for (Index j=0; j<NCols(); j++) {
        for (Index i=0; i<NRows(); i++) {
          values_[i+j*NRows()] = alpha*V1.GetVector(i)->Dot(*V2.GetVector(j))
                                 + beta*values_[i+j*NRows()];
        }
      }
    }
    initialized_ = true;
    ObjectChanged();
  }