Essentia  2.1-beta6-dev
tnt_sparse_matrix_csr.h
Go to the documentation of this file.
1 /*
2 *
3 * Template Numerical Toolkit (TNT)
4 *
5 * Mathematical and Computational Sciences Division
6 * National Institute of Technology,
7 * Gaithersburg, MD USA
8 *
9 *
10 * This software was developed at the National Institute of Standards and
11 * Technology (NIST) by employees of the Federal Government in the course
12 * of their official duties. Pursuant to title 17 Section 105 of the
13 * United States Code, this software is not subject to copyright protection
14 * and is in the public domain. NIST assumes no responsibility whatsoever for
15 * its use by other parties, and makes no guarantees, expressed or implied,
16 * about its quality, reliability, or any other characteristic.
17 *
18 */
19 
20 
21 #ifndef TNT_SPARSE_MATRIX_CSR_H
22 #define TNT_SPARSE_MATRIX_CSR_H
23 
24 #include "tnt_array1d.h"
25 
26 namespace TNT
27 {
28 
29 
47 template <class T>
49 
50 private:
51  Array1D<T> val_; // data values (nz_ elements)
52  Array1D<int> rowptr_; // row_ptr (dim_[0]+1 elements)
53  Array1D<int> colind_; // col_ind (nz_ elements)
54 
55  int dim1_; // number of rows
56  int dim2_; // number of cols
57 
58 public:
59 
61  Sparse_Matrix_CompRow(int M, int N, int nz, const T *val,
62  const int *r, const int *c);
63 
64 
65 
66  inline const T& val(int i) const { return val_[i]; }
67  inline const int& row_ptr(int i) const { return rowptr_[i]; }
68  inline const int& col_ind(int i) const { return colind_[i];}
69 
70  inline int dim1() const {return dim1_;}
71  inline int dim2() const {return dim2_;}
72  int NumNonzeros() const {return val_.dim1();}
73 
74 
76  const Sparse_Matrix_CompRow &R);
77 
78 
79 
80 };
81 
94 template <class T>
96  const T *val, const int *r, const int *c) : val_(nz,val),
97  rowptr_(M, (int*)r), colind_(nz, (int*)c), dim1_(M), dim2_(N) {}
98 
99 
100 }
101 // namespace TNT
102 
103 #endif
Definition: tnt_array1d.h:40
Definition: tnt_sparse_matrix_csr.h:48
int dim1_
Definition: tnt_sparse_matrix_csr.h:55
const int & row_ptr(int i) const
Definition: tnt_sparse_matrix_csr.h:67
int dim1() const
Definition: tnt_sparse_matrix_csr.h:70
int NumNonzeros() const
Definition: tnt_sparse_matrix_csr.h:72
Array1D< T > val_
Definition: tnt_sparse_matrix_csr.h:51
const T & val(int i) const
Definition: tnt_sparse_matrix_csr.h:66
Sparse_Matrix_CompRow & operator=(const Sparse_Matrix_CompRow &R)
int dim2_
Definition: tnt_sparse_matrix_csr.h:56
int dim2() const
Definition: tnt_sparse_matrix_csr.h:71
Array1D< int > colind_
Definition: tnt_sparse_matrix_csr.h:53
Sparse_Matrix_CompRow(const Sparse_Matrix_CompRow &S)
const int & col_ind(int i) const
Definition: tnt_sparse_matrix_csr.h:68
Array1D< int > rowptr_
Definition: tnt_sparse_matrix_csr.h:52
Definition: tnt_array1d.h:36