File: SparseMatrix.h

package info (click to toggle)
proda 1.0-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 584 kB
  • sloc: cpp: 8,549; xml: 163; makefile: 109; sh: 12
file content (74 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (4)
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
//////////////////////////////////////////////////////////////////////
// SparseMatrix.h
//
// Sparse matrix storage class for storing a set of two-dimensional
// arrays.
//////////////////////////////////////////////////////////////////////

#ifndef SPARSEMATRIX_H
#define SPARSEMATRIX_H

#include <stdio.h>
#include "Matrix.h"

//////////////////////////////////////////////////////////////////////
// Sparse matrix object
//////////////////////////////////////////////////////////////////////

class Matrix;

class SparseMatrix {
  friend class Matrix;

 public:
  struct SparseMatrixEntry {
    int column;
    float value;
  };
  
 private:  
  float threshold, missing;
  int layers;
  int rows;
  int cols;
  int numEntries;

  SparseMatrixEntry *data;
  int *rowSize;
  SparseMatrixEntry **rowPtrs;

  // default constructor (used for ComputeTranspose())
  SparseMatrix(){}
  
  // printing utility function
  void PrintVal (FILE *file, const float &value) const;

 public:

  // constructor and destructor
  SparseMatrix (const Matrix &matrix, const float &threshold, const float &missing);
  ~SparseMatrix ();

  // compute transpose
  SparseMatrix *ComputeTranspose() const;

  // row accessors
  const SparseMatrixEntry *GetRowPtr (int layer, int row) const;
  const int GetRowSize (int layer, int row) const;

  // matrix dimension accessors
  const int GetNumLayers() const;
  const int GetNumRows() const;
  const int GetNumCols() const;
  

  // printing functions
  void PrintLayer (FILE *file, int layer) const;
  void Print (FILE *file) const;

  // accessor
  const float &operator() (int layer, int row, int col) const;

};

#endif