File: SparseMatrix.hpp

package info (click to toggle)
consensuscore 1.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,384 kB
  • sloc: cpp: 38,940; python: 2,083; ansic: 542; sh: 184; makefile: 82; cs: 10
file content (68 lines) | stat: -rw-r--r-- 1,878 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
// Author: David Alexander

#pragma once

#include <xmmintrin.h>
#include <utility>
#include <vector>

#include <ConsensusCore/Interval.hpp>
#include <ConsensusCore/Matrix/AbstractMatrix.hpp>
#include <ConsensusCore/Matrix/SparseVector.hpp>
#include <ConsensusCore/Types.hpp>
#include <ConsensusCore/Utils.hpp>

namespace ConsensusCore {

class SparseMatrix : public AbstractMatrix
{
public:  // Constructor, destructor
    SparseMatrix(int rows, int cols);
    SparseMatrix(const SparseMatrix& other);
    ~SparseMatrix();

public:  // Nullability
    static const SparseMatrix& Null();
    bool IsNull() const;

public:  // Size information
    int Rows() const;
    int Columns() const;

public:  // Information about entries filled by column
    void StartEditingColumn(int j, int hintBegin, int hintEnd);
    void FinishEditingColumn(int j, int usedBegin, int usedEnd);
    Interval UsedRowRange(int j) const;
    bool IsColumnEmpty(int j) const;
    int UsedEntries() const;
    int AllocatedEntries() const;  // an entry may be allocated but not used

public:  // Accessors
    const float& operator()(int i, int j) const;
    bool IsAllocated(int i, int j) const;
    float Get(int i, int j) const;
    void Set(int i, int j, float v);
    void ClearColumn(int j);

public:  // SSE accessors, which access 4 successive entries in a column
    __m128 Get4(int i, int j) const;
    void Set4(int i, int j, __m128 v);

public:
    // Method SWIG clients can use to get a native matrix (e.g. Numpy)
    // mat must be filled as a ROW major matrix
    void ToHostMatrix(float** mat, int* rows, int* cols) const;

private:
    void CheckInvariants(int column) const;

private:
    std::vector<SparseVector*> columns_;
    int nCols_;
    int nRows_;
    int columnBeingEdited_;
    std::vector<Interval> usedRanges_;
};
}

#include <ConsensusCore/Matrix/SparseMatrix-inl.hpp>