1#ifndef FREE_TENSOR_LINEAR_H
2#define FREE_TENSOR_LINEAR_H
15template <
class T>
struct Scale {
32 std::unordered_set<std::string>
allNames()
const {
33 std::unordered_set<std::string> names;
34 for (
auto &&[k, a] :
coeff_) {
46 auto m =
lhs.coeff_.size(),
n =
rhs.coeff_.size();
48 for (
size_t p = 0, q = 0; p < m || q <
n;) {
50 (p < m &&
lhs.coeff_[p].a_->hash() <
rhs.coeff_[q].a_->hash())) {
52 }
else if (p == m || (q <
n &&
lhs.coeff_[p].a_->hash() >
53 rhs.coeff_[q].a_->hash())) {
59 ret.
coeff_.emplace_back(s);
70 auto m =
lhs.coeff_.size(),
n =
rhs.coeff_.size();
72 for (
size_t p = 0, q = 0; p < m || q <
n;) {
74 (p < m &&
lhs.coeff_[p].a_->hash() <
rhs.coeff_[q].a_->hash())) {
76 }
else if (p == m || (q <
n &&
lhs.coeff_[p].a_->hash() >
77 rhs.coeff_[q].a_->hash())) {
84 ret.
coeff_.emplace_back(s);
98 for (
auto &&item : lin.
coeff_) {
107 if (
lhs.coeff_.size() ==
rhs.coeff_.size()) {
108 for (
size_t i = 0, iEnd =
lhs.coeff_.size(); i < iEnd; i++) {
109 if (
lhs.coeff_[i].k_ !=
rhs.coeff_[i].k_) {
129 requires std::integral<T> || std::floating_point<T>
133 for (
auto &&item : lin.
coeff_) {
142 x =
makeIntConst(k * a.template as<IntConstNode>()->val_);
173 for (
auto &&[k, a] : lin.
coeff_) {
174 os << k <<
" * " << a <<
" + ";
virtual ASTNodeType nodeType() const =0
int64_t val_
Definition: expr.h:95
Ref< U > as() const
Definition: ref.h:83
Definition: allocator.h:9
auto && lhs
Definition: const_fold.cc:70
Expr makeMul(T &&lhs, U &&rhs, std::source_location loc=std::source_location::current())
Definition: expr.h:202
Expr makeAdd(T &&lhs, U &&rhs, std::source_location loc=std::source_location::current())
Definition: expr.h:174
UpperBound sub(const UpperBound &b1, const LowerBound &b2)
Definition: bounds.cc:200
Expr lin2expr(const LinearExpr< T > &lin)
Definition: linear.h:130
bool operator==(const Allocator< T > &lhs, const Allocator< T > &rhs)
Definition: allocator.h:100
Expr deepCopy(const Expr &op)
Definition: ast.cc:364
UpperBound mul(const UpperBound &b, int k)
Definition: bounds.cc:207
bool hasIdenticalCoeff(const LinearExpr< T > &lhs, const LinearExpr< T > &rhs)
Definition: linear.h:106
std::unordered_set< std::string > allNames(const AST &op, bool noRecurseIdx=false, bool noRecurseSubStmt=false)
Definition: all_uses.h:134
auto auto && rhs
Definition: const_fold.cc:70
UpperBound add(const UpperBound &b1, const UpperBound &b2)
Definition: bounds.cc:193
std::ostream & operator<<(std::ostream &os, const Dependence &dep)
Definition: deps.cc:1404
Expr makeIntConst(int64_t val, std::source_location loc=std::source_location::current())
Definition: expr.h:102
std::unordered_set< std::string > allNames() const
Definition: linear.h:32
T bias_
Definition: linear.h:28
bool isConst() const
Definition: linear.h:30
std::vector< Scale< T > > coeff_
Definition: linear.h:27
T k_
Definition: linear.h:16
Expr a_
Definition: linear.h:17