identity_matrix.cpp
1 #include <symengine/basic.h>
2 #include <symengine/number.h>
3 #include <symengine/integer.h>
4 #include <symengine/matrices/matrix_expr.h>
5 #include <symengine/matrices/identity_matrix.h>
6 
7 namespace SymEngine
8 {
9 
11 {
12  return n_->__hash__();
13 }
14 
15 bool IdentityMatrix::__eq__(const Basic &o) const
16 {
17  return (is_a<IdentityMatrix>(o)
18  && n_->__eq__(*down_cast<const IdentityMatrix &>(o).n_));
19 }
20 
21 int IdentityMatrix::compare(const Basic &o) const
22 {
23  SYMENGINE_ASSERT(is_a<IdentityMatrix>(o));
24 
25  return n_->compare(*down_cast<const IdentityMatrix &>(o).n_);
26 }
27 
29 {
30  return {n_};
31 }
32 
33 bool IdentityMatrix::is_canonical(const RCP<const Basic> &n) const
34 {
35  if (is_a_Number(*n)) {
36  if (is_a<Integer>(*n)) {
37  if (down_cast<const Integer &>(*n).is_negative()) {
38  return false;
39  }
40  } else {
41  return false;
42  }
43  }
44  return true;
45 }
46 
47 RCP<const MatrixExpr> identity_matrix(const RCP<const Basic> &n)
48 {
49  if (is_a_Number(*n)) {
50  if (is_a<Integer>(*n)) {
51  if (down_cast<const Integer &>(*n).is_negative()) {
52  throw DomainError(
53  "Dimension of IdentityMatrix must be nonnegative");
54  }
55  } else {
56  throw DomainError(
57  "Dimension of IdentityMatrix must be a nonnegative integer");
58  }
59  }
60  return make_rcp<const IdentityMatrix>(n);
61 }
62 
63 } // namespace SymEngine
The base class for SymEngine.
The lowest unit of symbolic representation.
Definition: basic.h:97
hash_t __hash__() const override
int compare(const Basic &o) const override
vec_basic get_args() const override
Returns the list of arguments.
bool __eq__(const Basic &o) const override
Test equality.
Main namespace for SymEngine package.
Definition: add.cpp:19
bool is_a_Number(const Basic &b)
Definition: number.h:130