diagonal_matrix.cpp
1 #include <symengine/matrices/diagonal_matrix.h>
2 #include <symengine/matrices/zero_matrix.h>
3 #include <symengine/matrices/identity_matrix.h>
4 #include <symengine/integer.h>
5 
6 namespace SymEngine
7 {
8 
10 {
11  hash_t seed = SYMENGINE_DIAGONALMATRIX;
12  for (const auto &a : diag_)
13  hash_combine<Basic>(seed, *a);
14  return seed;
15 }
16 
17 bool DiagonalMatrix::__eq__(const Basic &o) const
18 {
19  if (is_a<DiagonalMatrix>(o)) {
20  const DiagonalMatrix &other = down_cast<const DiagonalMatrix &>(o);
21  return unified_eq(diag_, other.diag_);
22  }
23  return false;
24 }
25 
26 int DiagonalMatrix::compare(const Basic &o) const
27 {
28  SYMENGINE_ASSERT(is_a<DiagonalMatrix>(o));
29  const DiagonalMatrix &other = down_cast<const DiagonalMatrix &>(o);
30  return unified_compare(diag_, other.diag_);
31 }
32 
33 bool is_zero_vec(const vec_basic &container)
34 {
35  for (auto &e : container) {
36  if (!(is_a<Integer>(*e) && down_cast<const Integer &>(*e).is_zero())) {
37  return false;
38  }
39  }
40  return true;
41 }
42 
43 bool is_identity_vec(const vec_basic &container)
44 {
45  for (auto &e : container) {
46  if (!(is_a<Integer>(*e) && down_cast<const Integer &>(*e).is_one())) {
47  return false;
48  }
49  }
50  return true;
51 }
52 
53 bool DiagonalMatrix::is_canonical(const vec_basic &container) const
54 {
55  if (container.size() == 0) {
56  return false;
57  }
58  if (is_zero_vec(container)) {
59  return false;
60  }
61  if (is_identity_vec(container)) {
62  return false;
63  }
64  return true;
65 }
66 
67 RCP<const MatrixExpr> diagonal_matrix(const vec_basic &container)
68 {
69  if (is_zero_vec(container)) {
70  return make_rcp<const ZeroMatrix>(integer(container.size()),
71  integer(container.size()));
72  } else if (is_identity_vec(container)) {
73  return make_rcp<const IdentityMatrix>(integer(container.size()));
74  } else {
75  return make_rcp<const DiagonalMatrix>(container);
76  }
77 }
78 
79 } // namespace SymEngine
The lowest unit of symbolic representation.
Definition: basic.h:97
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
Main namespace for SymEngine package.
Definition: add.cpp:19
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
Definition: integer.h:197
int unified_compare(const T &a, const T &b)
Definition: dict.h:205