Macaulay2 Engine
Loading...
Searching...
No Matches
DMatZZpTest.cpp
Go to the documentation of this file.
1
27
28#include <memory>
29#include <gtest/gtest.h>
30
31#include "DMatTest.hpp"
32#include "aring-zzp.hpp"
33#include "aring-glue.hpp"
34
35TEST(DMatZZp, create)
36{
37 typedef M2::ARingZZp RingZZp;
38 typedef DMat<M2::ARingZZp> MatZZp;
39
40 RingZZp* R = new RingZZp(101);
41 MatZZp M(*R, 5, 5);
42
43 EXPECT_TRUE(&M.ring() == R);
44
45 RingZZp::ElementType a, b;
46 R->init(a);
47 R->init(b);
48 R->set_from_long(a, 13);
49 R->set(M.entry(0, 2), a);
50
51 R->set(b, M.entry(0, 2));
52 EXPECT_TRUE(R->is_equal(a, b));
53}
54
56{
57 typedef M2::ARingZZp RingZZp;
58 typedef DMat<M2::ARingZZp> MatZZp;
59
60 RingZZp* R = new RingZZp(101);
61 MatZZp M(*R, 5, 5);
62
63 EXPECT_TRUE(&M.ring() == R);
64
65 RingZZp::ElementType a, b;
66 R->init(a);
67 R->init(b);
68
69 R->set_from_long(a, 13);
70 R->set(M.entry(0, 2), a);
71
72 R->set(b, M.entry(0, 2));
73 EXPECT_TRUE(R->is_equal(a, b));
74
75 // No check is done that there is no aliasing here...
76 // Should there be
77 submatrix(M, 0, 0, 1, 1) = submatrix(M, 0, 2, 1, 1);
78 R->set(b, M.entry(0, 0));
79 EXPECT_TRUE(R->is_equal(a, b));
80
81 submatrix(M, 0, 0, 2, 2) = 0;
82 EXPECT_FALSE(MatrixOps::isZero(M));
83
84 submatrix(M, 0, 2, 2, 2) = 0;
85 EXPECT_TRUE(MatrixOps::isZero(M));
86
87 R->set(M.entry(4, 4), a);
88 EXPECT_FALSE(MatrixOps::isZero(M));
89
90 submatrix(M) = 0;
91 EXPECT_TRUE(MatrixOps::isZero(M));
92
93 MatZZp N(*R, 2, 2);
94 R->set(N.entry(0, 0), a);
95 displayMat(N);
96 std::cout << std::endl;
97 displayMat(M);
98 std::cout << std::endl;
99 submatrix(M, 0, 1, 2, 2) = submatrix(N);
100 submatrix(M, 0, 0, 2, 2) += submatrix(N);
101 submatrix(M, 0, 0, 2, 2) *= a;
102 displayMat(M);
103 std::cout << std::endl;
104 EXPECT_FALSE(MatrixOps::isZero(M));
105
106 R->clear(a);
107 R->clear(b);
108}
109
110// Local Variables:
111// compile-command: "make -C $M2BUILDDIR/Macaulay2/e/unit-tests check "
112// indent-tabs-mode: nil
113// End:
Convention placeholder header that pulls in dmat.hpp for the dense-matrix test suite.
TEST(DMatZZp, create)
ConcreteRing<RingType> — the templated bridge between aring and the legacy Ring API.
M2::ARingZZp — portable Z/p for small primes via log / exp tables.
Definition dmat.hpp:62
aring-style adapter for Z/p using a discrete-log (Zech) representation: every non-zero residue is its...
Definition aring-zzp.hpp:67
DMat< M2::ARingZZp > DMatZZp
SubMatrix< MatType > submatrix(MatType &m)
void displayMat(buffer &o, const Mat &A)
Definition mat-util.hpp:43
bool isZero(const DMat< RT > &A)