1 #include <symengine/matrices/immutable_dense_matrix.h>
2 #include <symengine/matrices/zero_matrix.h>
3 #include <symengine/matrices/identity_matrix.h>
4 #include <symengine/matrices/diagonal_matrix.h>
11 hash_t seed = SYMENGINE_IMMUTABLEDENSEMATRIX;
14 for (
const auto &a : values_) {
15 hash_combine<Basic>(seed, *a);
22 if (is_a<ImmutableDenseMatrix>(o)) {
24 = down_cast<const ImmutableDenseMatrix &>(o);
25 if (m_ != other.m_ || n_ != other.n_) {
28 return unified_eq(values_, other.values_);
35 SYMENGINE_ASSERT(is_a<ImmutableDenseMatrix>(o));
37 = down_cast<const ImmutableDenseMatrix &>(o);
40 }
else if (m_ > other.m_) {
45 }
else if (n_ > other.n_) {
51 bool is_identity_dense(
size_t n,
const vec_basic &container)
54 for (
size_t row = 0; row < n; row++) {
55 for (
size_t col = 0; col < n; col++) {
56 auto &e = container[i];
58 if (!(is_a<Integer>(*e)
59 && down_cast<const Integer &>(*e).is_one())) {
63 if (!(is_a<Integer>(*e)
64 && down_cast<const Integer &>(*e).is_zero())) {
74 bool is_diagonal_dense(
size_t n,
const vec_basic &container)
77 for (
size_t row = 0; row < n; row++) {
78 for (
size_t col = 0; col < n; col++) {
80 auto &e = container[i];
81 if (!(is_a<Integer>(*e)
82 && down_cast<const Integer &>(*e).is_zero())) {
92 vec_basic extract_diagonal(
size_t n,
const vec_basic &container)
96 for (
size_t row = 0; row < n; row++) {
97 for (
size_t col = 0; col < n; col++) {
99 auto &e = container[i];
108 bool ImmutableDenseMatrix::is_canonical(
size_t m,
size_t n,
109 const vec_basic &values)
const
111 if (m < 1 || n < 1 || values.size() == 0) {
114 if (m * n != values.size()) {
117 if (is_zero_vec(values)) {
120 if (m == n && is_identity_dense(m, values)) {
123 if (m == n && is_diagonal_dense(m, values)) {
129 RCP<const MatrixExpr> immutable_dense_matrix(
size_t m,
size_t n,
130 const vec_basic &container)
132 if (is_zero_vec(container)) {
134 }
else if (m == n && is_identity_dense(m, container)) {
135 return make_rcp<const IdentityMatrix>(
integer(m));
136 }
else if (m == n && is_diagonal_dense(m, container)) {
137 return make_rcp<const DiagonalMatrix>(extract_diagonal(m, container));
139 return make_rcp<const ImmutableDenseMatrix>(m, n, container);
The lowest unit of symbolic representation.
hash_t __hash__() const override
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
Main namespace for SymEngine package.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
void hash_combine(hash_t &seed, const T &v)
int unified_compare(const T &a, const T &b)