Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tnt_sparse_matrix_csr.h « tnt « intern « smoke « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 90ef1e142ef53e8631bd33672ef8c345ad3a0b8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/** \file \ingroup smoke
 */
/*
*
* Template Numerical Toolkit (TNT)
*
* Mathematical and Computational Sciences Division
* National Institute of Technology,
* Gaithersburg, MD USA
*
*
* This software was developed at the National Institute of Standards and
* Technology (NIST) by employees of the Federal Government in the course
* of their official duties. Pursuant to title 17 Section 105 of the
* United States Code, this software is not subject to copyright protection
* and is in the public domain. NIST assumes no responsibility whatsoever for
* its use by other parties, and makes no guarantees, expressed or implied,
* about its quality, reliability, or any other characteristic.
*
*/


#ifndef TNT_SPARSE_MATRIX_CSR_H
#define TNT_SPARSE_MATRIX_CSR_H

#include "tnt_array1d.h"

namespace TNT
{


/**
	Read-only view of a sparse matrix in compressed-row storage
	format.  Neither array elements (nonzeros) nor sparsity
	structure can be modified.  If modifications are required,
	create a new view.

	<p>
	Index values begin at 0.

	<p>
	<b>Storage requirements:</b> An (m x n) matrix with
	nz nonzeros requires no more than  ((T+I)*nz + M*I)
	bytes, where T is the size of data elements and
	I is the size of integers.
	

*/
template <class T>
class Sparse_Matrix_CompRow {

private:
	Array1D<T>    val_;       // data values (nz_ elements)
    Array1D<int>  rowptr_;    // row_ptr (dim_[0]+1 elements)
    Array1D<int>  colind_;    // col_ind  (nz_ elements)

    int dim1_;        // number of rows
    int dim2_;        // number of cols
  
public:

	Sparse_Matrix_CompRow(const Sparse_Matrix_CompRow &S);
	Sparse_Matrix_CompRow(int M, int N, int nz, const T *val, 
						const int *r, const int *c);
    


    inline   const T&      val(int i) const { return val_[i]; }
    inline   const int&         row_ptr(int i) const { return rowptr_[i]; }
    inline   const int&         col_ind(int i) const { return colind_[i];}

    inline   int    dim1() const {return dim1_;}
    inline   int    dim2() const {return dim2_;}
       int          NumNonzeros() const {return val_.dim1();}


    Sparse_Matrix_CompRow& operator=(
					const Sparse_Matrix_CompRow &R);



};

/**
	Construct a read-only view of existing sparse matrix in
	compressed-row storage format.

	@param M the number of rows of sparse matrix
	@param N the  number of columns of sparse matrix
	@param nz the number of nonzeros
	@param val a contiguous list of nonzero values
	@param r row-pointers: r[i] denotes the begining position of row i
		(i.e. the ith row begins at val[row[i]]).
	@param c column-indices: c[i] denotes the column location of val[i]
*/
template <class T>
Sparse_Matrix_CompRow<T>::Sparse_Matrix_CompRow(int M, int N, int nz,
	const T *val, const int *r, const int *c) : val_(nz,val), 
		rowptr_(M, r), colind_(nz, c), dim1_(M), dim2_(N) {}


}
// namespace TNT

#endif