source: sasview/realSpaceModeling/iqPy/libiqPy/tnt/tnt_sparse_matrix_csr.h @ cb463b4

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since cb463b4 was f2d6445, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

moving realSpaceModeling to trunk

  • Property mode set to 100644
File size: 2.8 KB
Line 
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
26namespace TNT
27{
28
29
30/**
31        Read-only view of a sparse matrix in compressed-row storage
32        format.  Neither array elements (nonzeros) nor sparsity
33        structure can be modified.  If modifications are required,
34        create a new view.
35
36        <p>
37        Index values begin at 0.
38
39        <p>
40        <b>Storage requirements:</b> An (m x n) matrix with
41        nz nonzeros requires no more than  ((T+I)*nz + M*I)
42        bytes, where T is the size of data elements and
43        I is the size of integers.
44       
45
46*/
47template <class T>
48class Sparse_Matrix_CompRow {
49
50private:
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 
58public:
59
60        Sparse_Matrix_CompRow(const Sparse_Matrix_CompRow &S);
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
75    Sparse_Matrix_CompRow& operator=(
76                                        const Sparse_Matrix_CompRow &R);
77
78
79
80};
81
82/**
83        Construct a read-only view of existing sparse matrix in
84        compressed-row storage format.
85
86        @param M the number of rows of sparse matrix
87        @param N the  number of columns of sparse matrix
88        @param nz the number of nonzeros
89        @param val a contiguous list of nonzero values
90        @param r row-pointers: r[i] denotes the begining position of row i
91                (i.e. the ith row begins at val[row[i]]).
92        @param c column-indices: c[i] denotes the column location of val[i]
93*/
94template <class T>
95Sparse_Matrix_CompRow<T>::Sparse_Matrix_CompRow(int M, int N, int nz,
96        const T *val, const int *r, const int *c) : val_(nz,val), 
97                rowptr_(M, r), colind_(nz, c), dim1_(M), dim2_(N) {}
98
99
100}
101// namespace TNT
102
103#endif
Note: See TracBrowser for help on using the repository browser.