Exemplo n.º 1
0
void SymTMatrix::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, "%sSymTMatrix \"%s\" of dimension %d with %d nonzero elements:\n",
      prefix.c_str(), name.c_str(), Dim(), 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], Jcols()[i], values_[i], i);
      }
   }
   else
   {
      jnlst.PrintfIndented(level, category, indent, "%sUninitialized!\n", prefix.c_str());
   }
}
Exemplo n.º 2
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++;
   }
}
Exemplo n.º 3
0
 void SymTMatrix::FillStruct(ipfint* Irn, ipfint* Jcn) const
 {
   DBG_ASSERT(initialized_);
   for(Index i=0; i<Nonzeros(); i++) {
     Irn[i] = Irows()[i];
     Jcn[i] = Jcols()[i];
   }
 }
Exemplo n.º 4
0
  void SymTMatrix::MultVectorImpl(Number alpha, const Vector &x, Number beta,
                                  Vector &y) const
  {
    //  A few sanity checks
    DBG_ASSERT(Dim()==x.Dim());
    DBG_ASSERT(Dim()==y.Dim());

    // Take care of the y part of the addition
    DBG_ASSERT(initialized_);
    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 = dynamic_cast<const DenseVector*>(&x);
    DBG_ASSERT(dense_x); /* ToDo: Implement others */
    DenseVector* dense_y = dynamic_cast<DenseVector*>(&y);
    DBG_ASSERT(dense_y); /* ToDo: Implement others */

    if (dense_x && dense_y) {
      const Index*  irn=Irows();
      const Index*  jcn=Jcols();
      const Number* val=values_;
      Number* yvals=dense_y->Values();

      if (dense_x->IsHomogeneous()) {
        Number as = alpha *  dense_x->Scalar();
        for(Index i=0; i<Nonzeros(); i++) {
          yvals[*irn-1] += as * (*val);
          if (*irn!=*jcn) {
            // this is not a diagonal element
            yvals[*jcn-1] += as * (*val);
          }
          val++;
          irn++;
          jcn++;
        }
      }
      else {
        const Number* xvals=dense_x->Values();
        for(Index i=0; i<Nonzeros(); i++) {
          yvals[*irn-1] += alpha* (*val) * xvals[*jcn-1];
          if (*irn!=*jcn) {
            // this is not a diagonal element
            yvals[*jcn-1] += alpha* (*val) * xvals[*irn-1];
          }
          val++;
          irn++;
          jcn++;
        }
      }
    }
  }
Exemplo n.º 5
0
  void GenTMatrix::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());

    // Take care of the y part of the addition
    DBG_ASSERT(initialized_);
    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));
    DenseVector* dense_y = static_cast<DenseVector*>(&y);
    DBG_ASSERT(dynamic_cast<DenseVector*>(&y));

    if (dense_x && dense_y) {
      const Index*  irows=Irows();
      const Index*  jcols=Jcols();
      const Number* val=values_;
      Number* yvals=dense_y->Values();
      yvals--;

      if (dense_x->IsHomogeneous()) {
        Number as = alpha * dense_x->Scalar();
        for (Index i=0; i<Nonzeros(); i++) {
          yvals[*jcols] += as * (*val);
          val++;
          jcols++;
        }
      }
      else {
        const Number* xvals=dense_x->Values();
        xvals--;
        for (Index i=0; i<Nonzeros(); i++) {
          yvals[*jcols] += alpha* (*val) * xvals[*irows];
          val++;
          irows++;
          jcols++;
        }
      }
    }
  }
Exemplo n.º 6
0
  void GenTMatrix::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* irows=Irows();
    const Number* val=values_;
    Number* vec_vals=dense_vec->Values();
    vec_vals--;

    for (Index i=0; i<Nonzeros(); i++) {
      vec_vals[irows[i]] = Max(vec_vals[irows[i]], fabs(val[i]));
    }
  }