2#include <symengine/matrices/matrix_expr.h>
3#include <symengine/matrices/trace.h>
36 RCP<const Basic> trace_;
40 throw DomainError(
"Trace is only valid for square matrices");
46 void bvisit(
const Basic &x){};
61 tribool
sq = is_square(x);
64 }
else if (is_false(
sq)) {
74 trace_ =
add(x.get_container());
79 if (x.nrows() != x.ncols()) {
83 for (
size_t i = 0; i < x.nrows(); i++) {
84 diag.push_back(x.get(i, i));
92 RCP<const Basic>
sum = zero;
93 for (
auto &
e : x.get_terms()) {
The base class for SymEngine.
The lowest unit of symbolic representation.
RCP< T > rcp_from_this()
Get RCP<T> pointer to self (it will cast the pointer to T)
hash_t __hash__() const override
bool __eq__(const Basic &o) const override
Test equality.
int compare(const Basic &o) const override
vec_basic get_args() const override
Returns the list of arguments.
Main namespace for SymEngine package.
void hash_combine(hash_t &seed, const T &v)
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).