Esempio n. 1
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);
      }
    }
  }
Esempio n. 2
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.);
      }
    }
  }
Esempio n. 3
0
  void MultiVectorMatrix::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,
                         "%sMultiVectorMatrix \"%s\" with %d columns:\n",
                         prefix.c_str(), name.c_str(), NCols());

    for (Index i=0; i<NCols(); i++) {
      if (ConstVec(i)) {
        DBG_ASSERT(name.size()<200);
        char buffer[256];
        Snprintf(buffer, 255, "%s[%2d]", name.c_str(), i);
        std::string term_name = buffer;
        ConstVec(i)->Print(&jnlst, level, category, term_name,
                           indent+1, prefix);
      }
      else {
        jnlst.PrintfIndented(level, category, indent,
                             "%sVector in column %d is not yet set!\n",
                             prefix.c_str(), i);
      }
    }
  }
Esempio n. 4
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);
    }
  }
Esempio n. 5
0
 bool MultiVectorMatrix::HasValidNumbersImpl() const
 {
   for (Index i=0; i<NCols(); i++) {
     if (!ConstVec(i)->HasValidNumbers()) {
       return false;
     }
   }
   return true;
 }
 /** Get a Vector in a particular column as a const Vector */
 inline SmartPtr<const Vector> GetVector(Index i) const
 {
   return ConstVec(i);
 }