SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SparseRowMatrix.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file SparseRowMatrix.h
33 ///@brief Sparse Row Matrices
34 ///
35 ///@author
36 /// Steven G. Parker
37 /// Department of Computer Science
38 /// University of Utah
39 ///@date November 1994
40 ///
41 ///@details See http://math.nist.gov/MatrixMarket/formats.html#MMformat
42 /// for more information about this sparse matrix format.
43 ///
44 
45 
46 #ifndef CORE_DATATYPES_SPARSEROWMATRIX_H
47 #define CORE_DATATYPES_SPARSEROWMATRIX_H 1
48 
49 #include <Core/Datatypes/Matrix.h>
50 
51 #include <Core/Math/MiscMath.h>
52 #include <Core/Util/Assert.h>
53 #include <Core/Util/FancyAssert.h>
54 #include <Core/Util/MemoryUtil.h>
55 
56 #include <boost/shared_array.hpp>
57 
58 #include <algorithm>
59 
60 #include <float.h>
61 #include <stdio.h>
62 #include <memory.h>
63 
64 #include <Core/Datatypes/share.h>
65 
66 namespace SCIRun {
67 
68 template <typename T>
69 class SparseRowMatrixGeneric : public Matrix<T>
70 {
71 public:
72  typedef boost::shared_array<index_type> Rows;
73  typedef boost::shared_array<index_type> Columns;
74  typedef boost::shared_array<T> Storage;
75 private:
76  SparseRowMatrixGeneric(); // This is only used by the maker function.
77 
78  Rows rows_;
79  Columns columns_;
80  size_type nnz_;
81  Storage data_;
82 
83  void clear_memory();
84 
85 public:
86  bool validate();
87  void order_columns();
88 
89  class Data
90  {
91  public:
92  Data(size_type rowSize, size_type columnSize, size_type dataSize) :
93  rows_(new index_type[rowSize]),
94  columns_(new index_type[columnSize]),
95  data_(new T[dataSize])
96  { }
97  Data(size_type rowSize, size_type columnAndDataSize) :
98  rows_(new index_type[rowSize]),
99  columns_(new index_type[columnAndDataSize]),
100  data_(new T[columnAndDataSize])
101  { }
102  Data(const std::vector<index_type>& rows, const std::vector<index_type>& columns, const std::vector<T>& data) :
103  rows_(make_deep_copy(rows)),
104  columns_(make_deep_copy(columns)),
105  data_(make_deep_copy(data))
106  { }
107  //shallow copy for Builder class
108  Data(const Rows& rows, const Columns& columns, const Storage& data) :
109  rows_(rows), columns_(columns), data_(data)
110  { }
111 
112  bool allocated() const { return rows_ && columns_ && data_; }
113 
114  const Rows& rows() const { return rows_; }
115  const Columns& columns() const { return columns_; }
116  const Storage& data() const { return data_; }
117 
118  private:
119  const Rows rows_;
120  const Columns columns_;
121  const Storage data_;
122  };
123 
124  class Builder : boost::noncopyable
125  {
126  public:
127  Builder() {}
128  const Rows& allocate_rows(size_type rowSize)
129  {
130  rows_.reset(new index_type[rowSize]);
131  return rows_;
132  }
134  {
135  columns_.reset(new index_type[colSize]);
136  return columns_;
137  }
138  const Storage& allocate_data(size_type dataSize)
139  {
140  data_.reset(new T[dataSize]);
141  return data_;
142  }
144  {
145  return Data(rows_, columns_, data_);
146  }
147  private:
148  Rows rows_;
149  Columns columns_;
150  Storage data_;
151  };
152 
153  /// Constructors
154  // Here's what the arguments for the constructor should be:
155  // r = number of rows
156  // c = number of columns
157  //
158  // rr = row accumulation buffer containing r+1 entries where
159  // rr[N+1]-rr[N] is the number of non-zero entries in row N
160  // The last entry contains the total number of non-zero entries.
161  //
162  // cc = column number for each nonzero data entry.
163  // Sorted by row/col order and corresponds with the spaces in the
164  // rr array.
165  //
166  // nnz = number of non zero entries.
167  //
168  // d = non zero data values.
169  //
170  // sort_columns = do we need to sort columns of the matrix
171  //
172  //SparseRowMatrixGeneric(size_type r, size_type c, index_type *rr, index_type *cc,
173  // size_type nnz, T *data, bool sort_columns = false);
174 
175  SparseRowMatrixGeneric(size_type r, size_type c, const Data& data,
176  size_type nnz, bool sort_columns = false);
177 
179 
180  virtual SparseRowMatrixGeneric* clone() const;
182 
183  /// Destructor
184  virtual ~SparseRowMatrixGeneric();
185 
186  virtual DenseMatrix *dense();
187  virtual SparseRowMatrixGeneric *sparse();
188  virtual ColumnMatrix *column();
189  virtual DenseColMajMatrix *dense_col_maj();
190 
191  virtual T* get_data_pointer() const;
192  virtual size_type get_data_size() const;
193 
195  size_type get_nnz() const { return nnz_; }
196 
197  T* get_vals() { return data_.get(); }
198  const T* get_vals() const { return data_.get(); }
199  index_type* get_rows() { return rows_.get(); }
200  index_type* get_cols() { return columns_.get(); }
201  const index_type* get_rows() const { return rows_.get(); }
202  const index_type* get_cols() const { return columns_.get(); }
203  index_type get_row(index_type i) const { return rows_[i]; }
204  index_type get_col(index_type i) const { return columns_[i]; }
205  T get_value(index_type i) const { return data_[i]; }
206  bool is_valid() const { return data_ && rows_ && columns_; }
207  virtual bool is_zero() const
208  {
209  return 0 == nnz_;
210  }
211 
213  {
214  throw "not implemented";
215  }
216 
217  inline const T& operator()(index_type r, index_type c) const
218  {
219  throw "not implemented";
220  }
221 
222  virtual void zero();
223  virtual T get(index_type, index_type) const;
224  virtual void put(index_type row, index_type col, T val);
225  virtual void add(index_type row, index_type col, T val);
226 
227  virtual T min();
228  virtual T max();
229  virtual int compute_checksum();
230 
231  virtual void getRowNonzerosNoCopy(index_type r, size_type &size,
232  size_type &stride,
233  index_type *&cols, T *&vals);
234 
235  virtual SparseRowMatrixGeneric *make_transpose() const;
236  virtual void mult(const ColumnMatrix& x, ColumnMatrix& b,
237  index_type beg=-1, index_type end=-1,
238  int spVec=0) const;
239  virtual void mult_transpose(const ColumnMatrix& x, ColumnMatrix& b,
240  index_type beg=-1, index_type end=-1,
241  int spVec=0) const;
242  virtual void scalar_multiply(T s);
243 
245  index_type r2, index_type c2);
246 
247 
249 
250  virtual void print(std::string&) const;
251 
252  /// Persistent representation...
253  virtual std::string dynamic_type_name() const { return type_id.type; }
254  virtual void io(Piostream&);
256 
258 };
259 
260 template <typename T>
261 Persistent*
263 {
264  return new SparseRowMatrixGeneric<T>;
265 }
266 
267 template <typename T>
268 PersistentTypeID SparseRowMatrixGeneric<T>::type_id("SparseRowMatrix", "Matrix",
270 
271 template <typename T>
272 int
274 {
275  int sum = 0;
276  sum += SCIRun::compute_checksum(rows_.get(), this->nrows_+1);
277  sum += SCIRun::compute_checksum(columns_.get(), nnz_);
278  sum += SCIRun::compute_checksum(data_.get(), nnz_);
279  return (sum);
280 }
281 
282 
283 template <typename T>
286 {
287  return new SparseRowMatrixGeneric(*this);
288 }
289 
290 template <typename T>
292 rows_(0),
293 columns_(0),
294 nnz_(0),
295 data_(0)
296 {
297  DEBUG_CONSTRUCTOR("SparseRowMatrix")
298 }
299 
300 template <typename T>
301 void SparseRowMatrixGeneric<T>::clear_memory()
302 {
303  data_.reset();
304  rows_.reset();
305  columns_.reset();
306 }
307 
308 class matrix_sort_type : public std::binary_function<index_type,index_type,bool>
309 {
310 public:
311  explicit matrix_sort_type(const index_type* cols) :
312  cols_(cols)
313  {}
314 
315  bool operator()(index_type i1, index_type i2) const
316  {
317  return(cols_[i1] < cols_[i2]);
318  }
319 
320 private:
321  const index_type* cols_;
322 };
323 
324 template <typename T>
325 void
327 {
328 
329  /// This code should reorder the columns of a sparse matrix so they are
330  /// in ascending order. This code will purge duplicates as well by merging
331  /// them together.
332 
333  /// Calculate the size of the buffer we need to reorder the data
334  /// This way we can use the stl sorting algorithm
335  size_type max_num_cols = 0;
336  for (index_type j = 0; j< this->nrows_; j++)
337  if (rows_[j+1]-rows_[j] > max_num_cols)
338  max_num_cols = rows_[j+1]- rows_[j];
339 
340  std::vector<index_type> order(max_num_cols);
341  std::vector<T> databuffer(max_num_cols);
342  std::vector<index_type> indexbuffer(max_num_cols);
343 
344  matrix_sort_type sortmatrix(columns_.get());
345 
346  index_type rr = rows_[0];
347 
348  /// Sorting columns and removing duplicates
349  for (index_type j = 0; j<this->nrows_; j++)
350  {
351  size_type num_cols = rows_[j+1]-rr;
352  order.resize(num_cols);
353  for (index_type p=rr; p<rows_[j+1]; p++) order[p-rr] = p;
354  std::sort(order.begin(),order.end(),sortmatrix);
355 
356  for (index_type q=0; q<num_cols; q++)
357  {
358  databuffer[q] = data_[order[q]];
359  indexbuffer[q] = columns_[order[q]];
360  }
361 
362  index_type p = rows_[j];
363  index_type q = 0;
364  if (q < num_cols)
365  {
366  data_[p] = databuffer[q];
367  columns_[p] = indexbuffer[q];
368  q++;
369  }
370 
371  while(q < num_cols)
372  {
373  if (columns_[p] == indexbuffer[q])
374  {
375  data_[p] += databuffer[q];
376  q++;
377  }
378  else
379  {
380  p++;
381  columns_[p] = indexbuffer[q];
382  data_[p] = databuffer[q];
383  q++;
384  }
385  }
386  p++;
387 
388  rr = rows_[j+1];
389  rows_[j+1] = p;
390  }
391 
392  nnz_ = rows_[this->nrows_];
393 }
394 
395 template <typename T>
397  const Data& data,
398  size_type nnz,
399  bool sort_columns) :
400 Matrix<T>(nnrows, nncols),
401 rows_(data.rows()),
402 columns_(data.columns()),
403 nnz_(nnz),
404 data_(data.data())
405 {
406  DEBUG_CONSTRUCTOR("SparseRowMatrix")
407  if (data_ == 0)
408  {
409  data_.reset(new T[nnz_]);
410  }
411  if (sort_columns) order_columns();
412 }
413 
414 template <typename T>
416 {
417  clear_memory();
418 
419  this->nrows_ = copy.nrows();
420  this->ncols_ = copy.ncols();
421  nnz_ = copy.nnz_;
422 
423  rows_ = make_deep_copy(copy.rows_, this->nrows_+1);
424  columns_ = make_deep_copy(copy.columns_, nnz_);
425  data_ = make_deep_copy(copy.data_, nnz_);
426 
427  return *this;
428 }
429 
430 template <typename T>
432 Matrix<T>(copy.nrows_, copy.ncols_),
433 nnz_(copy.nnz_)
434 {
435  DEBUG_CONSTRUCTOR("SparseRowMatrix")
436 
437  rows_ = make_deep_copy(copy.rows_, this->nrows_+1);
438  columns_ = make_deep_copy(copy.columns_, nnz_);
439  data_ = make_deep_copy(copy.data_, nnz_);
440 }
441 
442 template <typename T>
444 {
445  DEBUG_DESTRUCTOR("SparseRowMatrix")
446 }
447 
448 template <typename T>
449 bool
451 {
452  index_type i, j;
453 
454  ASSERTMSG(rows_[0] == 0, "Row start is nonzero.");
455  for (i = 0; i< this->nrows_; i++)
456  {
457  ASSERTMSG(rows_[i] <= rows_[i+1], "Malformed rows, not increasing.");
458  for (j = rows_[i]; j < rows_[i+1]; j++)
459  {
460  ASSERTMSG(columns_[j] >= 0 && columns_[j] < this->ncols_, "Column out of range.");
461  if (j != rows_[i])
462  {
463  ASSERTMSG(columns_[j-1] != columns_[j], "Column doubled.");
464  ASSERTMSG(columns_[j-1] < columns_[j], "Column out of order.");
465  }
466  }
467  }
468  ASSERTMSG(rows_[this->nrows_] == nnz_, "Row end is incorrect.");
469  return true;
470 }
471 
472 template <typename T>
473 T *
475 {
476  return data_.get();
477 }
478 
479 template <typename T>
480 size_type
482 {
483  return nnz_;
484 }
485 
486 template <typename T>
489 {
490  Data transposeData(this->ncols_+1, nnz_);
491  size_type t_nnz = nnz_;
492  size_type t_nncols = this->nrows_;
493  size_type t_nnrows = this->ncols_;
494  const SparseRowMatrix::Rows& t_rows = transposeData.rows();
495  const SparseRowMatrix::Columns& t_columns = transposeData.columns();
496  const SparseRowMatrix::Storage& t_a = transposeData.data();
497  std::vector<index_type> at(t_nnrows+1);
498  for (index_type i=0; i<t_nnz;i++)
499  {
500  at[columns_[i]+1]++;
501  }
502  t_rows[0] = 0;
503  for (index_type i=1; i<t_nnrows+1; i++)
504  {
505  at[i] += at[i-1];
506  t_rows[i] = at[i];
507  }
508  index_type c = 0;
509  for (index_type r=0; r<this->nrows_; r++)
510  {
511  for (; c<rows_[r+1]; c++)
512  {
513  index_type mcol = columns_[c];
514  t_columns[at[mcol]] = r;
515  t_a[at[mcol]] = data_[c];
516  at[mcol]++;
517  }
518  }
519  return new SparseRowMatrixGeneric(t_nnrows, t_nncols, transposeData, t_nnz);
520 }
521 
522 template <typename T>
525 {
526  index_type row_idx=rows_[i];
527  index_type next_idx=rows_[i+1];
528  index_type l=row_idx;
529  index_type h=next_idx-1;
530  for (;;)
531  {
532  if (h<l)
533  {
534  return -1;
535  }
536  index_type m=(l+h)/2;
537  if (j<columns_[m])
538  {
539  h=m-1;
540  }
541  else if (j>columns_[m])
542  {
543  l=m+1;
544  }
545  else
546  {
547  return m;
548  }
549  }
550 }
551 
552 template <typename T>
553 T
555 {
556  index_type row_idx=rows_[i];
557  index_type next_idx=rows_[i+1];
558  index_type l=row_idx;
559  index_type h=next_idx-1;
560  for (;;)
561  {
562  if (h<l)
563  {
564  return 0.0;
565  }
566  index_type m=(l+h)/2;
567  if (j<columns_[m])
568  {
569  h=m-1;
570  }
571  else if (j>columns_[m])
572  {
573  l=m+1;
574  }
575  else
576  {
577  return data_[m];
578  }
579  }
580 }
581 
582 template <typename T>
583 void
585 {
586  index_type row_idx=rows_[i];
587  index_type next_idx=rows_[i+1];
588  index_type l=row_idx;
589  index_type h=next_idx-1;
590  for (;;)
591  {
592  if (h<l)
593  {
594  ASSERTFAIL("SparseRowMatrix::put into invalid(dataless) location.");
595  return;
596  }
597  index_type m=(l+h)/2;
598  if (j<columns_[m])
599  {
600  h=m-1;
601  }
602  else if (j>columns_[m])
603  {
604  l=m+1;
605  }
606  else
607  {
608  data_[m] = d;
609  return;
610  }
611  }
612 }
613 
614 template <typename T>
615 void
617 {
618  index_type row_idx=rows_[i];
619  index_type next_idx=rows_[i+1];
620  index_type l=row_idx;
621  index_type h=next_idx-1;
622  for (;;)
623  {
624  if (h<l)
625  {
626  ASSERTFAIL("SparseRowMatrix::add into invalid(dataless) location.");
627  return;
628  }
629  index_type m=(l+h)/2;
630  if (j<columns_[m])
631  {
632  h=m-1;
633  }
634  else if (j>columns_[m])
635  {
636  l=m+1;
637  }
638  else
639  {
640  data_[m] += d;
641  return;
642  }
643  }
644 }
645 
646 template <typename T>
647 T
649 {
650  T min = DBL_MAX;
651  for (index_type k=0; k<nnz_; k++)
652  if (data_[k] < min) min = data_[k];
653  return (min);
654 }
655 
656 template <typename T>
657 T
659 {
660  T max = -DBL_MAX;
661  for (index_type k=0; k<nnz_; k++)
662  if (data_[k] > max) max = data_[k];
663  return (max);
664 }
665 
666 template <typename T>
667 void
669  index_type &stride,
670  index_type *&cols, T *&vals)
671 {
672  size = rows_[r+1] - rows_[r];
673  stride = 1;
674  cols = columns_.get() + rows_[r];
675  vals = data_.get() + rows_[r];
676 }
677 
678 template <typename T>
679 void
681 {
682  std::fill(data_.get(), data_.get() + nnz_, 0);
683 }
684 
685 template <typename T>
686 void SparseRowMatrixGeneric<T>::print(std::string &str) const
687 {
688  str.clear();
689  std::ostringstream oss;
690  oss.flags(std::ios::showpoint);
691  index_type index = 0;
692  oss << "nrows=" << this->nrows_ << " ncols=" << this->ncols_ << " nnz=" << nnz_ << std::endl;
693  for (index_type r = 0; r < this->nrows_; r++)
694  {
695  while(index < rows_[r+1])
696  {
697  oss << r << " " << columns_[index] << " " << data_[index] << std::endl;
698  ++index;
699  }
700  }
701  str = oss.str();
702 }
703 
704 
705 #define SPARSEROWMATRIX_VERSION 2
706 
707 template <typename T>
708 void
710 {
711  int version = stream.begin_class("SparseRowMatrix", SPARSEROWMATRIX_VERSION);
712  // Do the base class first...
713  Matrix<T>::io(stream);
714 
715  if (version <2)
716  {
717  int r = static_cast<int>(this->nrows_);
718  int c = static_cast<int>(this->ncols_);
719  int n = static_cast<int>(nnz_);
720  stream.io(r);
721  stream.io(c);
722  stream.io(n);
723  this->nrows_ = static_cast<size_type>(r);
724  this->ncols_ = static_cast<size_type>(c);
725  nnz_= static_cast<size_type>(n);
726  }
727  else
728  {
729  Pio_size(stream,this->nrows_);
730  Pio_size(stream,this->ncols_);
731  Pio_size(stream,nnz_);
732  }
733 
734  if (stream.reading())
735  {
736  data_.reset(new T[nnz_]);
737  columns_.reset(new index_type[nnz_]);
738  rows_.reset(new index_type[this->nrows_+1]);
739  }
740 
741  stream.begin_cheap_delim();
742  Pio_index(stream, rows_.get(), this->nrows_+1);
743  stream.end_cheap_delim();
744 
745  stream.begin_cheap_delim();
746  Pio_index(stream, columns_.get(), nnz_);
747  stream.end_cheap_delim();
748 
749  stream.begin_cheap_delim();
750  Pio(stream, data_.get(), nnz_);
751  stream.end_cheap_delim();
752 
753  stream.end_class();
754 }
755 
756 template <typename T>
759  index_type r2, index_type c2)
760 {
761  ASSERTRANGE(r1, 0, r2+1);
762  ASSERTRANGE(r2, r1, this->nrows_);
763  ASSERTRANGE(c1, 0, c2+1);
764  ASSERTRANGE(c2, c1, this->ncols_);
765 
766  index_type i, j;
767  std::vector<index_type> rs(r2-r1+2);
768  std::vector<index_type> csv;
769  std::vector<T> valsv;
770 
771  rs[0] = 0;
772  for (i = r1; i <= r2; i++)
773  {
774  rs[i-r1+1] = rs[i-r1];
775  for (j = rows_[i]; j < rows_[i+1]; j++)
776  {
777  if (columns_[j] >= c1 && columns_[j] <= c2)
778  {
779  csv.push_back(columns_[j] - c1);
780  valsv.push_back(data_[j]);
781  rs[i-r1+1]++;
782  }
783  }
784  }
785 
786  Data data(rs, csv, valsv);
787 
788  return new SparseRowMatrixGeneric(r2-r1+1, c2-c1+1, data,
789  static_cast<size_type>(valsv.size()));
790 }
791 
792 template <typename T>
795 {
796  Data data(size+1, size);
797  const Rows& r = data.rows();
798  const Columns& c = data.columns();
799  const Storage& d = data.data();
800 
801  index_type i;
802  for (i=0; i<size; i++)
803  {
804  c[i] = r[i] = i;
805  d[i] = 1.0;
806  }
807  r[i] = i;
808 
809  return new SparseRowMatrixGeneric(size, size, data, size);
810 }
811 
812 /// @todo: replace with for_each
813 template <typename T>
814 void
816 {
817  for (index_type i=0; i < this->nnz_; ++i)
818  {
819  data_[i] *= s;
820  }
821 }
822 
823 
824 } // End namespace SCIRun
825 
826 #endif
boost::shared_array< T > Storage
Definition: SparseRowMatrix.h:74
bool reading() const
Definition: Persistent.h:164
Definition: DenseMatrix.h:68
index_type * get_cols()
Definition: SparseRowMatrix.h:200
LockingHandle< Matrix< double > > MatrixHandle
Definition: MatrixFwd.h:55
Definition: SparseRowMatrix.h:89
virtual MatrixHandle submatrix(index_type r1, index_type c1, index_type r2, index_type c2)
Definition: SparseRowMatrix.h:758
#define ASSERTMSG(condition, message)
Definition: Exception.h:113
bool validate()
Definition: SparseRowMatrix.h:450
Definition: DenseColMajMatrix.h:73
virtual void put(index_type row, index_type col, T val)
Definition: SparseRowMatrix.h:584
virtual void io(bool &)
Definition: Persistent.cc:193
virtual void scalar_multiply(T s)
Definition: SparseRowMatrix.h:815
virtual T min()
Definition: SparseRowMatrix.h:648
Definition: Persistent.h:89
const Rows & allocate_rows(size_type rowSize)
Definition: SparseRowMatrix.h:128
virtual T max()
Definition: SparseRowMatrix.h:658
T get_value(index_type i) const
Definition: SparseRowMatrix.h:205
int compute_checksum(T *data, std::size_t length)
Definition: CheckSum.h:38
virtual SparseRowMatrixGeneric * clone() const
Make a duplicate, needed to support detach from LockingHandle.
Definition: SparseRowMatrix.h:285
T * get_vals()
Definition: SparseRowMatrix.h:197
Definition: Persistent.h:187
matrix_sort_type(const index_type *cols)
Definition: SparseRowMatrix.h:311
virtual T get(index_type, index_type) const
Definition: SparseRowMatrix.h:554
virtual void mult(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: SparseRowMatrixMultiplication.h:53
index_type get_row(index_type i) const
Definition: SparseRowMatrix.h:203
virtual void begin_cheap_delim()
Definition: Persistent.cc:183
Definition: Matrix.h:104
bool allocated() const
Definition: SparseRowMatrix.h:112
index_type get_col(index_type i) const
Definition: SparseRowMatrix.h:204
bool operator()(index_type i1, index_type i2) const
Definition: SparseRowMatrix.h:315
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
#define ASSERTRANGE(c, l, h)
Definition: Assert.h:99
const index_type * get_rows() const
Definition: SparseRowMatrix.h:201
T & operator()(index_type r, index_type c)
Definition: SparseRowMatrix.h:212
virtual void io(Piostream &)
Definition: SparseRowMatrix.h:709
Data(const Rows &rows, const Columns &columns, const Storage &data)
Definition: SparseRowMatrix.h:108
virtual void add(index_type row, index_type col, T val)
Definition: SparseRowMatrix.h:616
index_type * get_rows()
Definition: SparseRowMatrix.h:199
Definition: ParallelLinearAlgebraTests.cc:358
virtual DenseMatrix * dense()
Convert this matrix to the specified type.
Definition: MatrixTypeConverter.h:167
Definition: SparseRowMatrix.h:124
void Pio_index(Piostream &stream, index_type *data, size_type size)
Definition: Persistent.cc:606
long long size_type
Definition: Types.h:40
T * end() const
Definition: Matrix.h:141
static SparseRowMatrixGeneric * identity(size_type size)
Definition: SparseRowMatrix.h:794
SparseRowMatrixGeneric & operator=(const SparseRowMatrixGeneric &)
Definition: SparseRowMatrix.h:415
virtual T * get_data_pointer() const
Definition: SparseRowMatrix.h:474
dictionary data
Definition: eabLatVolData.py:11
Definition: ColumnMatrix.h:55
virtual void print(std::string &) const
Definition: SparseRowMatrix.h:686
virtual SparseRowMatrixGeneric * make_transpose() const
Definition: SparseRowMatrix.h:488
std::string type
Definition: Persistent.h:72
virtual size_type get_data_size() const
Definition: SparseRowMatrix.h:481
const Rows & rows() const
Definition: SparseRowMatrix.h:114
Definition: SparseRowMatrix.h:308
virtual void end_cheap_delim()
Definition: Persistent.cc:188
virtual std::string dynamic_type_name() const
Persistent representation...
Definition: SparseRowMatrix.h:253
virtual void zero()
Definition: SparseRowMatrix.h:680
Builder()
Definition: SparseRowMatrix.h:127
void order_columns()
Definition: SparseRowMatrix.h:326
const T & operator()(index_type r, index_type c) const
Definition: SparseRowMatrix.h:217
virtual SparseRowMatrixGeneric * sparse()
Definition: MatrixTypeConverter.h:159
virtual ColumnMatrix * column()
Definition: MatrixTypeConverter.h:210
size_type get_nnz() const
Definition: SparseRowMatrix.h:195
index_type getIdx(index_type, index_type)
Definition: SparseRowMatrix.h:524
#define ASSERTFAIL(string)
Definition: Assert.h:52
virtual void mult_transpose(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: SparseRowMatrixMultiplication.h:82
virtual DenseColMajMatrix * dense_col_maj()
Definition: MatrixTypeConverter.h:189
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
const Columns & columns() const
Definition: SparseRowMatrix.h:115
boost::shared_array< index_type > Rows
Definition: SparseRowMatrix.h:72
virtual void end_class()
Definition: Persistent.cc:178
long long index_type
Definition: Types.h:39
#define SPARSEROWMATRIX_VERSION
Definition: SparseRowMatrix.h:705
virtual bool is_zero() const
Definition: SparseRowMatrix.h:207
virtual int compute_checksum()
Definition: SparseRowMatrix.h:273
virtual void io(Piostream &)
Definition: Matrix.cc:58
boost::shared_array< T > make_deep_copy(const boost::shared_array< T > &arr, size_t length)
Definition: MemoryUtil.h:55
Data(size_type rowSize, size_type columnSize, size_type dataSize)
Definition: SparseRowMatrix.h:92
Data build()
Definition: SparseRowMatrix.h:143
Definition: Persistent.h:64
Data(size_type rowSize, size_type columnAndDataSize)
Definition: SparseRowMatrix.h:97
virtual void getRowNonzerosNoCopy(index_type r, size_type &size, size_type &stride, index_type *&cols, T *&vals)
Definition: SparseRowMatrix.h:668
int n
Definition: eab.py:9
const Storage & data() const
Definition: SparseRowMatrix.h:116
boost::shared_array< index_type > Columns
Definition: SparseRowMatrix.h:73
static Persistent * SparseRowMatrixGenericMaker()
Definition: SparseRowMatrix.h:262
const Storage & allocate_data(size_type dataSize)
Definition: SparseRowMatrix.h:138
Data(const std::vector< index_type > &rows, const std::vector< index_type > &columns, const std::vector< T > &data)
Definition: SparseRowMatrix.h:102
MatrixBase< double > Matrix
Definition: MatrixFwd.h:40
#define DEBUG_CONSTRUCTOR(type)
Definition: Debug.h:64
const T * get_vals() const
Definition: SparseRowMatrix.h:198
void Pio_size(Piostream &stream, Size &size)
Definition: Persistent.h:273
const Columns & allocate_columns(size_type colSize)
Definition: SparseRowMatrix.h:133
virtual ~SparseRowMatrixGeneric()
Destructor.
Definition: SparseRowMatrix.h:443
Definition: MatrixFwd.h:40
int size
Definition: eabLatVolData.py:2
static PersistentTypeID type_id
Definition: SparseRowMatrix.h:255
const index_type * get_cols() const
Definition: SparseRowMatrix.h:202
#define DEBUG_DESTRUCTOR(type)
Definition: Debug.h:65
bool is_valid() const
Definition: SparseRowMatrix.h:206