File: matrix-con.cpp

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (112 lines) | stat: -rw-r--r-- 3,246 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
#include "matrix-con.hpp"
#include "matrix.hpp"
#include "debug.hpp"

#include <iostream>

MatrixConstructor::MatrixConstructor()
    : R(0), rows(0), cols(0), cols_frozen(false), deg(0)
{
}

MatrixConstructor::MatrixConstructor(const FreeModule *target, int ncols)
    : R(target->get_ring()), rows(target), cols(0), cols_frozen(false), deg(0)
{
  cols = R->make_FreeModule(ncols);

  entries.reserve(ncols);
  for (int i = 0; i < ncols; i++) entries.push_back(0);

  deg = R->degree_monoid()->make_one();
}

MatrixConstructor::MatrixConstructor(const FreeModule *target,
                                     const FreeModule *source,
                                     const int *deg0)
    : R(target->get_ring()), rows(target), cols(source), cols_frozen(true)
{
  entries.reserve(source->rank());
  for (int i = 0; i < source->rank(); i++) entries.push_back(0);

  deg = (deg0 == 0 ? R->degree_monoid()->make_one()
                   : R->degree_monoid()->make_new(deg0));
}

void MatrixConstructor::append(vec v)
{
  assert(!cols_frozen);
  int *d = R->degree_monoid()->make_one();
  if (v != 0) R->vec_degree(rows, v, d);
  append(v, d);
  R->degree_monoid()->remove(d);
}
void MatrixConstructor::append(vec v, const int *deg0)
{
  if (cols_frozen)
    {
      INTERNAL_ERROR("trying to append to an immutable free module.");
    }
  entries.push_back(v);
  FreeModule *mutable_cols = const_cast<FreeModule *>(cols);
  mutable_cols->append(deg0);
}

void MatrixConstructor::set_entry(int r, int c, ring_elem a)
{
  R->set_entry(entries[c], r, a);
}
void MatrixConstructor::set_column(int c, vec v) { entries[c] = v; }
void MatrixConstructor::compute_column_degrees()
/* Takes into account the matrix degree */
{
  if (cols_frozen)
    {
      INTERNAL_ERROR("trying to append to an immutable free module.");
    }
  for (int i = 0; i < cols->rank(); i++) compute_column_degree(i);
}

void MatrixConstructor::set_column_degree(int i, const int *deg0)
{
  if (cols_frozen)
    {
      INTERNAL_ERROR("trying to append to an immutable free module.");
    }
  FreeModule *mutable_cols = const_cast<FreeModule *>(cols);
  mutable_cols->change_degree(i, deg0);
}

void MatrixConstructor::compute_column_degree(int i)
{
  if (cols_frozen)
    {
      INTERNAL_ERROR("trying to append to an immutable free module.");
    }
  int *d = R->degree_monoid()->make_one();
  const vec v = entries[i];
  if (v != 0) R->vec_degree(rows, v, d);
  FreeModule *mutable_cols = const_cast<FreeModule *>(cols);
  mutable_cols->change_degree(i, d);
  R->degree_monoid()->remove(d);
}

void MatrixConstructor::set_matrix_degree(const int *deg0) { deg = deg0; }
Matrix *MatrixConstructor::to_matrix()
{
  //  if (!will_be_mutable && !cols->is_frozen)
  //    cols->freeze(hashval);
  return new Matrix(rows, cols, deg, entries);
}

void MatrixConstructor::debugDisplay() const
{
  std::cout << "MatrixConstructor: ring = " << R << std::endl;
  std::cout << "MatrixConstructor: rows = " << rows << std::endl;
  std::cout << "MatrixConstructor: cols = " << cols << std::endl;
  std::cout << "Matrixconstructor: #entries = " << entries.size() << std::endl;
}

// Local Variables:
// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
// indent-tabs-mode: nil
// End: