zero_matrix.cpp
1 #include <symengine/number.h>
2 #include <symengine/integer.h>
3 #include <symengine/matrices/zero_matrix.h>
4 
5 namespace SymEngine
6 {
7 
8 hash_t ZeroMatrix::__hash__() const
9 {
10  hash_t seed = SYMENGINE_ZEROMATRIX;
11  hash_combine<Basic>(seed, *m_);
12  hash_combine<Basic>(seed, *n_);
13  return seed;
14 }
15 
16 bool ZeroMatrix::__eq__(const Basic &o) const
17 {
18  return (is_a<ZeroMatrix>(o)
19  && m_->__eq__(*down_cast<const ZeroMatrix &>(o).m_)
20  && n_->__eq__(*down_cast<const ZeroMatrix &>(o).n_));
21 }
22 
23 int ZeroMatrix::compare(const Basic &o) const
24 {
25  SYMENGINE_ASSERT(is_a<ZeroMatrix>(o));
26 
27  const ZeroMatrix &other = down_cast<const ZeroMatrix &>(o);
28  auto temp = m_->compare(*(other.m_));
29  if (temp != 0) {
30  return temp;
31  } else {
32  return n_->compare(*(other.n_));
33  }
34 }
35 
37 {
38  return {m_, n_};
39 }
40 
41 bool ZeroMatrix::is_canonical(const RCP<const Basic> &m,
42  const RCP<const Basic> &n) const
43 {
44  if (is_a_Number(*m)) {
45  if (is_a<Integer>(*m)) {
46  if (down_cast<const Integer &>(*m).is_negative()) {
47  return false;
48  }
49  } else {
50  return false;
51  }
52  }
53  if (is_a_Number(*n)) {
54  if (is_a<Integer>(*n)) {
55  if (down_cast<const Integer &>(*n).is_negative()) {
56  return false;
57  }
58  } else {
59  return false;
60  }
61  }
62  return true;
63 }
64 
65 RCP<const MatrixExpr> zero_matrix(const RCP<const Basic> &m,
66  const RCP<const Basic> &n)
67 {
68  if (is_a_Number(*m)) {
69  if (is_a<Integer>(*m)) {
70  if (down_cast<const Integer &>(*m).is_negative()) {
71  throw DomainError(
72  "Dimension of ZeroMatrix must be nonnegative");
73  }
74  } else {
75  throw DomainError(
76  "Dimension of ZeroMatrix must be a nonnegative integer");
77  }
78  }
79  if (is_a_Number(*n)) {
80  if (is_a<Integer>(*n)) {
81  if (down_cast<const Integer &>(*n).is_negative()) {
82  throw DomainError(
83  "Dimension of ZeroMatrix must be nonnegative");
84  }
85  } else {
86  throw DomainError(
87  "Dimension of ZeroMatrix must be a nonnegative integer");
88  }
89  }
90 
91  return make_rcp<const ZeroMatrix>(m, n);
92 }
93 
94 } // namespace SymEngine
The lowest unit of symbolic representation.
Definition: basic.h:97
bool __eq__(const Basic &o) const override
Test equality.
Definition: zero_matrix.cpp:16
hash_t __hash__() const override
Definition: zero_matrix.cpp:8
int compare(const Basic &o) const override
Definition: zero_matrix.cpp:23
vec_basic get_args() const override
Returns the list of arguments.
Definition: zero_matrix.cpp:36
Main namespace for SymEngine package.
Definition: add.cpp:19
bool is_a_Number(const Basic &b)
Definition: number.h:130