File: StrictStairCaseMatrixTrans.hh

package info (click to toggle)
topcom 1.2.0~beta%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,596 kB
  • sloc: cpp: 40,956; sh: 4,663; makefile: 679; ansic: 55
file content (167 lines) | stat: -rw-r--r-- 6,251 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
////////////////////////////////////////////////////////////////////////////////
// 
// StairCaseMatrix.hh 
//
//    produced: 21/08/97 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef STRICTSTAIRCASEMATRIXTRANS_HH
#define STRICTSTAIRCASEMATRIXTRANS_HH

#include <assert.h>
#include <limits>

#include "CommandlineOptions.hh"

#include "Vector.hh"
#include "StairCaseMatrix.hh"

namespace topcom {

  class StrictStairCaseMatrixTrans : public StairCaseMatrix {
  private:

    // for each resulting column, we store the coefficients
    // of its representation as a linear combination
    // of original columns;
    // that is: the first coldim rows of the transformation matrix
    // times the original matrix
    // equals the resulting strict staircase matrix;
    // whenever the last column is transformed to zero,
    // its transformation contains an element of the kernel
    // of the original matrix
    // this happens no later than we have one more columns than rows;
    // thus, the transformation matrix needs at most as many rows
    // as the original matrix has rows plus one:
    Matrix _transformation;
  public:
    // constructors:
    inline StrictStairCaseMatrixTrans();
    inline StrictStairCaseMatrixTrans(const StrictStairCaseMatrixTrans&);
    inline StrictStairCaseMatrixTrans(StrictStairCaseMatrixTrans&&);
    inline StrictStairCaseMatrixTrans(const Vector&);
    inline StrictStairCaseMatrixTrans(const parameter_type, 
				      const parameter_type);

    // destructor:
    inline ~StrictStairCaseMatrixTrans();
    
    // assignment:
    inline StrictStairCaseMatrixTrans& operator=(const StrictStairCaseMatrixTrans&);
    inline StrictStairCaseMatrixTrans& operator=(StrictStairCaseMatrixTrans&&);

    // accessors:
    inline const Matrix& transformation() const;

    // in place operations:
    StrictStairCaseMatrixTrans& augment(const Vector&);
    StrictStairCaseMatrixTrans& augment(const Matrix&);

    // out of place operations:
    inline bool      has_full_rank() const;
    inline parameter_type rank         () const;
    const Field      valuation    (const Vector&) const; // determinant form induced by the first rowdim - 1 columns

    // stream input/output:
    std::ostream& pretty_print(std::ostream& ost) const;
    std::istream& read(std::istream&);
    friend inline std::istream& operator>>(std::istream& ist, StrictStairCaseMatrixTrans& matrix) {
      return matrix.read(ist);
    }
    std::ostream& write(std::ostream&) const;
    friend inline std::ostream& operator<<(std::ostream& ost, const StrictStairCaseMatrixTrans& matrix) {
      return matrix.write(ost);
    }
  private:
    // internal elimination step:
    void _eliminate(const parameter_type, const parameter_type, const parameter_type);

    // forbid in place operations if result is of type StairCaseMatrix:
    inline StrictStairCaseMatrixTrans& add(const StrictStairCaseMatrixTrans&) = delete;
    inline StrictStairCaseMatrixTrans& scale(const Field&) = delete;
    inline StrictStairCaseMatrixTrans& stack(const StrictStairCaseMatrixTrans&) = delete;
  };

  inline StrictStairCaseMatrixTrans::StrictStairCaseMatrixTrans() : 
    StairCaseMatrix(), _transformation() {
  }
  inline StrictStairCaseMatrixTrans::StrictStairCaseMatrixTrans(const StrictStairCaseMatrixTrans& matrix) : 
    StairCaseMatrix(matrix), _transformation(matrix._transformation) {
  }
  inline StrictStairCaseMatrixTrans::StrictStairCaseMatrixTrans(StrictStairCaseMatrixTrans&& matrix) : 
    StairCaseMatrix(std::move(matrix)), _transformation(std::move(matrix._transformation)) {
  }
  inline StrictStairCaseMatrixTrans::StrictStairCaseMatrixTrans(const Vector& vector) :

    // initialize with one column and the identity transformation
    // that this column equals FieldConstants::ONE times the first column plus
    // FieldConstants::ZERO times the remaining (not yet existing) columns:
    StairCaseMatrix(vector), _transformation(vector.dim() + 1, 1, FieldConstants::ZERO) {
    _transformation(0, 0) = FieldConstants::ONE;
  }
  inline StrictStairCaseMatrixTrans::StrictStairCaseMatrixTrans(const parameter_type init_rows, 
								const parameter_type init_cols) :

    // initialize with a matrix of init_cols columns with init_rows rows each
    // and a transformation matrix with the first init_cols columns of the
    // (init_rows + 1) x (init_rows + 1) identity matrix;
    // meaning: each column equals FieldConstants::ONE times itself plus
    // FieldConstants::ZERO times the remaining (maybe not yet existing) columns;
    // there will be never more than init_rows + 1 columns necessary
    // to generate a zero-column:
    StairCaseMatrix(init_rows, init_cols), _transformation(init_rows + 1, init_cols, FieldConstants::ZERO) {
    assert(init_cols <= init_rows);
    for (parameter_type j = 0; j < init_cols; ++j) {
      _transformation(j, j) = FieldConstants::ONE;
    }
  }

  // desctructor:
  inline StrictStairCaseMatrixTrans::~StrictStairCaseMatrixTrans() {
  }

  // assignment:
  inline StrictStairCaseMatrixTrans& StrictStairCaseMatrixTrans::operator=(const StrictStairCaseMatrixTrans& matrix) {
    if (matrix == *this) {
      return *this;
    }
    StairCaseMatrix::operator=(matrix);
    _transformation = matrix._transformation;
    return *this;
  }
  inline StrictStairCaseMatrixTrans& StrictStairCaseMatrixTrans::operator=(StrictStairCaseMatrixTrans&& matrix) {
    if (matrix == *this) {
      return *this;
    }
    StairCaseMatrix::operator=(std::move(matrix));
    _transformation = std::move(matrix._transformation);
    return *this;
  }

  // accessors:
  inline const Matrix& StrictStairCaseMatrixTrans::transformation() const {
    return _transformation;
  }

  inline bool StrictStairCaseMatrixTrans::has_full_rank() const {
    return StairCaseMatrix::has_no_zerocol();
  }

  inline parameter_type StrictStairCaseMatrixTrans::rank() const {
    parameter_type result(0);
    for (parameter_type colidx = 0; colidx < coldim(); ++colidx) {
      if (!(*this)[colidx].is_zero()) {
	++result;
      }
      else {
	break;
      }
    }
    return result;
  }

}; // namespace topcom

#endif

// eof StrictStairCaseMatrixTrans.hh