File: DMatZZpTest.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 (86 lines) | stat: -rw-r--r-- 1,800 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
#include <memory>
#include <gtest/gtest.h>

#include "DMatTest.hpp"
#include "aring-zzp.hpp"
#include "aring-glue.hpp"

TEST(DMatZZp, create)
{
  typedef M2::ARingZZp RingZZp;
  typedef DMat<M2::ARingZZp> MatZZp;

  RingZZp* R = new RingZZp(101);
  MatZZp M(*R, 5, 5);

  EXPECT_TRUE(&M.ring() == R);

  RingZZp::ElementType a, b;
  R->init(a);
  R->init(b);
  R->set_from_long(a, 13);
  R->set(M.entry(0, 2), a);

  R->set(b, M.entry(0, 2));
  EXPECT_TRUE(R->is_equal(a, b));
}

TEST(DMatZZp, submatrix)
{
  typedef M2::ARingZZp RingZZp;
  typedef DMat<M2::ARingZZp> MatZZp;

  RingZZp* R = new RingZZp(101);
  MatZZp M(*R, 5, 5);

  EXPECT_TRUE(&M.ring() == R);

  RingZZp::ElementType a, b;
  R->init(a);
  R->init(b);

  R->set_from_long(a, 13);
  R->set(M.entry(0, 2), a);

  R->set(b, M.entry(0, 2));
  EXPECT_TRUE(R->is_equal(a, b));

  // No check is done that there is no aliasing here...
  // Should there be
  submatrix(M, 0, 0, 1, 1) = submatrix(M, 0, 2, 1, 1);
  R->set(b, M.entry(0, 0));
  EXPECT_TRUE(R->is_equal(a, b));

  submatrix(M, 0, 0, 2, 2) = 0;
  EXPECT_FALSE(MatrixOps::isZero(M));

  submatrix(M, 0, 2, 2, 2) = 0;
  EXPECT_TRUE(MatrixOps::isZero(M));

  R->set(M.entry(4, 4), a);
  EXPECT_FALSE(MatrixOps::isZero(M));

  submatrix(M) = 0;
  EXPECT_TRUE(MatrixOps::isZero(M));

  MatZZp N(*R, 2, 2);
  R->set(N.entry(0, 0), a);
  displayMat(N);
  std::cout << std::endl;
  displayMat(M);
  std::cout << std::endl;
  submatrix(M, 0, 1, 2, 2) = submatrix(N);
  submatrix(M, 0, 0, 2, 2) += submatrix(N);
  submatrix(M, 0, 0, 2, 2) *= a;
  displayMat(M);
  std::cout << std::endl;
  EXPECT_FALSE(MatrixOps::isZero(M));

  R->clear(a);
  R->clear(b);
}

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