~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to lib/atc/Matrix.h

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  virtual ~Matrix() {}
22
22
 
23
23
  //* stream output functions
24
 
  void print(std::ostream &o) const { o << to_string(); }
25
 
  void print(std::ostream &o, const std::string &name) const;
 
24
  void print(std::ostream &o, int p=myPrecision) const { o << this->to_string(p); }
 
25
  void print(std::ostream &o, const std::string &name, int p=myPrecision) const;
26
26
  friend std::ostream& operator<<(std::ostream &o, const Matrix<T> &m){m.print(o); return o;}
27
27
  void print() const;
28
 
  virtual void print(const std::string &name) const;
29
 
  virtual std::string to_string() const;
 
28
  virtual void print(const std::string &name, int p = myPrecision) const;
 
29
  virtual std::string to_string(int p) const;
 
30
  virtual std::string to_string() const { return to_string(myPrecision); }
30
31
 
31
32
  // element by element operations
32
33
  DenseMatrix<T> operator/(const Matrix<T>& B) const;
144
145
  virtual bool check_range(T min, T max) const;
145
146
 
146
147
protected:
147
 
  virtual void _set_equal(const Matrix<T> &r);
 
148
  virtual void _set_equal(const Matrix<T> &r) = 0;
148
149
};
149
150
 
150
151
//* Matrix operations 
286
287
//-----------------------------------------------------------------------------
287
288
//* output operator
288
289
template<typename T>
289
 
std::string Matrix<T>::to_string() const
 
290
std::string Matrix<T>::to_string(int p) const
290
291
{
291
292
  std::string s;
292
 
  for (INDEX i=0; i<nRows(); i++)
293
 
  {
 
293
  for (INDEX i=0; i<nRows(); i++) {
294
294
    if (i) s += '\n';
295
 
    for (INDEX j=0; j<nCols(); j++)
296
 
    {
297
 
      if (j) s+= '\t';
298
 
      s += ATC_Utility::to_string((*this)(i,j),myPrecision)+"   ";
 
295
    for (INDEX j=0; j<nCols(); j++) {
 
296
      //if (j) s+= '\t';
 
297
      s += ATC_Utility::to_string((*this)(i,j),p)+" ";
299
298
    }
300
299
  }
301
300
  return s;
303
302
//-----------------------------------------------------------------------------
304
303
//* output operator that wraps the matrix in a nice labeled box
305
304
template<typename T>
306
 
void Matrix<T>::print(std::ostream &o, const std::string &name) const
 
305
void Matrix<T>::print(std::ostream &o, const std::string &name, int p) const
307
306
{
308
307
  o << "------- Begin "<<name<<" -----------------\n";
309
 
  this->print(o);
 
308
  this->print(o,p);
310
309
  o << "\n------- End "<<name<<" -------------------\n";
311
310
}
312
311
//-----------------------------------------------------------------------------
319
318
//-----------------------------------------------------------------------------
320
319
//* named print operator, use cout by default
321
320
template<typename T>
322
 
void Matrix<T>::print(const std::string &name) const 
 
321
void Matrix<T>::print(const std::string &name, int p) const 
323
322
{
324
 
  print(std::cout, name); 
 
323
  print(std::cout, name, p); 
325
324
}
326
325
//-----------------------------------------------------------------------------
327
326
//* element by element division
648
647
  this->_set_equal(r);
649
648
  return *this;
650
649
}
651
 
//----------------------------------------------------------------------------
652
 
// general matrix assignment (for densely packed matrices)
653
 
//----------------------------------------------------------------------------
654
 
template<typename T>
655
 
void Matrix<T>::_set_equal(const Matrix<T> &r)
656
 
{
657
 
  this->resize(r.nRows(), r.nCols());
658
 
  const Matrix<T> *pr = &r;
659
 
  if (const SparseMatrix<T> *ps = sparse_cast(pr)) 
660
 
    copy_sparse_to_matrix(ps, *this);
661
 
  
662
 
  else if (diag_cast(pr))  // r is Diagonal?
663
 
  {
664
 
    this->zero();
665
 
    for (INDEX i=0; i<r.size(); i++) (*this)(i,i) = r[i];
666
 
  }
667
 
  else memcpy(this->ptr(), r.ptr(), r.size()*sizeof(T));
668
 
}
669
650
//-----------------------------------------------------------------------------
670
651
//* sets all elements to a constant
671
652
template<typename T>