File: FlatMatrix.hpp

package info (click to toggle)
pbseqlib 5.3.5%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,020 kB
  • sloc: cpp: 77,250; python: 331; sh: 103; makefile: 41
file content (103 lines) | stat: -rw-r--r-- 1,998 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
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
#ifndef _BLASR_FLAT_MATRIX_HPP_
#define _BLASR_FLAT_MATRIX_HPP_

#define rc2index(r, c, rowSize) ((r) * (rowSize) + c)

#include <fstream>
#include <iosfwd>
#include <vector>

#include <pbdata/Types.h>  // UInt

template <typename T>
void CreateFlatMatrix(int rows, int cols, std::vector<T> &matrix);

template <typename T>
void PrintFlatMatrix(std::vector<T> &matrix, int rows, int cols, std::ostream &out, int width = 6);

template <typename T>
void PrintFlatMatrix(const T *matrix, int rows, int cols, std::ostream &out, int width = 6);

template <typename T>
class FlatMatrix2D
{
public:
    T *matrix;
    int nRows, nCols;
    int totalSize;
    int RC2Index(int row, int col);

    FlatMatrix2D();

    ~FlatMatrix2D();

    T *operator[](int row);

    T operator()(int row, int col);

    unsigned int Size();

    void Fill(T value) { std::fill(matrix, &matrix[totalSize], value); }

    void Resize(int _nRows, int _nCols) { Grow(_nRows, _nCols); }

    void Resize(unsigned int totalSize);

    FlatMatrix2D(int _nRows, int _nCols);

    void Clear()
    {
        if (matrix) {
            delete[] matrix;
        }
        matrix = NULL;
        nRows = nCols = 0;
        totalSize = 0;
    }

    void Grow(int _nRows, int _nCols);

    T Get(int r, int c);

    T Set(int r, int c, T v);

    int Index(int r, int c);

    void Print(std::ostream &out);

    void Allocate(UInt _nRows, UInt _nCols);

    void Initialize(T value);
};

template <typename T>
class FlatMatrix3D
{
public:
    T *matrix;
    //
    // For some reason it makes sense to go from rows,cols to x,y,z
    // for referencing coordinates.
    //
    int nx, ny, nz;
    int xy;
    int totalSize;

    FlatMatrix3D();

    FlatMatrix3D(int _nx, int _ny, int _nz);

    void Grow(int _nx, int _ny, int _nz);

    int Index(int x, int y, int z);

    T Get(int x, int y, int z);

    T Set(int x, int y, int z, T v);

    ~FlatMatrix3D();
};

#include "FlatMatrixImpl.hpp"

#endif  // _BLASR_FLAT_MATRIX_HPP_