Code quality: renamed math_expression -> expression_tree

This commit is contained in:
Philippe Tillet
2015-12-19 02:55:24 -05:00
parent 5a035b91a2
commit d9eb51d04a
37 changed files with 557 additions and 565 deletions

View File

@@ -49,7 +49,7 @@ op_element::op_element() {}
op_element::op_element(operation_type_family const & _type_family, operation_type const & _type) : type_family(_type_family), type(_type){}
//
math_expression::math_expression(for_idx_t const &lhs, for_idx_t const &rhs, const op_element &op)
expression_tree::expression_tree(for_idx_t const &lhs, for_idx_t const &rhs, const op_element &op)
: tree_(1), root_(0), context_(NULL), dtype_(INVALID_NUMERIC_TYPE), shape_(1)
{
fill(tree_[0].lhs, lhs);
@@ -57,7 +57,7 @@ math_expression::math_expression(for_idx_t const &lhs, for_idx_t const &rhs, con
fill(tree_[0].rhs, rhs);
}
math_expression::math_expression(for_idx_t const &lhs, value_scalar const &rhs, const op_element &op, const numeric_type &dtype)
expression_tree::expression_tree(for_idx_t const &lhs, value_scalar const &rhs, const op_element &op, const numeric_type &dtype)
: tree_(1), root_(0), context_(NULL), dtype_(dtype), shape_(1)
{
fill(tree_[0].lhs, lhs);
@@ -65,7 +65,7 @@ math_expression::math_expression(for_idx_t const &lhs, value_scalar const &rhs,
fill(tree_[0].rhs, rhs);
}
math_expression::math_expression(value_scalar const &lhs, for_idx_t const &rhs, const op_element &op, const numeric_type &dtype)
expression_tree::expression_tree(value_scalar const &lhs, for_idx_t const &rhs, const op_element &op, const numeric_type &dtype)
: tree_(1), root_(0), context_(NULL), dtype_(dtype), shape_(1)
{
fill(tree_[0].lhs, lhs);
@@ -75,11 +75,11 @@ math_expression::math_expression(value_scalar const &lhs, for_idx_t const &rhs,
//math_expression(for_idx_t const &lhs, for_idx_t const &rhs, const op_element &op);
//math_expression(for_idx_t const &lhs, value_scalar const &rhs, const op_element &op, const numeric_type &dtype);
//expression_tree(for_idx_t const &lhs, for_idx_t const &rhs, const op_element &op);
//expression_tree(for_idx_t const &lhs, value_scalar const &rhs, const op_element &op, const numeric_type &dtype);
template<class LT, class RT>
math_expression::math_expression(LT const & lhs, RT const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape) :
expression_tree::expression_tree(LT const & lhs, RT const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape) :
tree_(1), root_(0), context_(&context), dtype_(dtype), shape_(shape)
{
fill(tree_[0].lhs, lhs);
@@ -88,7 +88,7 @@ math_expression::math_expression(LT const & lhs, RT const & rhs, op_element cons
}
template<class RT>
math_expression::math_expression(math_expression const & lhs, RT const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape) :
expression_tree::expression_tree(expression_tree const & lhs, RT const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape) :
tree_(lhs.tree_.size() + 1), root_(tree_.size()-1), context_(&context), dtype_(dtype), shape_(shape)
{
std::copy(lhs.tree_.begin(), lhs.tree_.end(), tree_.begin());
@@ -98,7 +98,7 @@ math_expression::math_expression(math_expression const & lhs, RT const & rhs, op
}
template<class LT>
math_expression::math_expression(LT const & lhs, math_expression const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape) :
expression_tree::expression_tree(LT const & lhs, expression_tree const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape) :
tree_(rhs.tree_.size() + 1), root_(tree_.size() - 1), context_(&context), dtype_(dtype), shape_(shape)
{
std::copy(rhs.tree_.begin(), rhs.tree_.end(), tree_.begin());
@@ -107,7 +107,7 @@ math_expression::math_expression(LT const & lhs, math_expression const & rhs, op
fill(tree_[root_].rhs, rhs.root_);
}
math_expression::math_expression(math_expression const & lhs, math_expression const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape):
expression_tree::expression_tree(expression_tree const & lhs, expression_tree const & rhs, op_element const & op, driver::Context const & context, numeric_type const & dtype, shape_t const & shape):
tree_(lhs.tree_.size() + rhs.tree_.size() + 1), root_(tree_.size()-1), context_(&context), dtype_(dtype), shape_(shape)
{
std::size_t lsize = lhs.tree_.size();
@@ -123,84 +123,77 @@ math_expression::math_expression(math_expression const & lhs, math_expression co
root_ = tree_.size() - 1;
}
template math_expression::math_expression(math_expression const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(math_expression const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(math_expression const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(math_expression const &, for_idx_t const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(expression_tree const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(expression_tree const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(expression_tree const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(expression_tree const &, for_idx_t const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(value_scalar const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(value_scalar const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(value_scalar const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(value_scalar const &, math_expression const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(value_scalar const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(value_scalar const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(value_scalar const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(value_scalar const &, expression_tree const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(invalid_node const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(invalid_node const &, math_expression const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(invalid_node const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(invalid_node const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(invalid_node const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(invalid_node const &, expression_tree const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(invalid_node const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(invalid_node const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(array_base const &, math_expression const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(array_base const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(array_base const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(array_base const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(array_base const &, for_idx_t const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(array_base const &, expression_tree const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(array_base const &, value_scalar const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(array_base const &, invalid_node const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(array_base const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(array_base const &, for_idx_t const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(for_idx_t const &, math_expression const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template math_expression::math_expression(for_idx_t const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(for_idx_t const &, expression_tree const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
template expression_tree::expression_tree(for_idx_t const &, array_base const &, op_element const &, driver::Context const &, numeric_type const &, shape_t const &);
math_expression::container_type & math_expression::tree()
expression_tree::container_type & expression_tree::tree()
{ return tree_; }
math_expression::container_type const & math_expression::tree() const
expression_tree::container_type const & expression_tree::tree() const
{ return tree_; }
std::size_t math_expression::root() const
std::size_t expression_tree::root() const
{ return root_; }
driver::Context const & math_expression::context() const
driver::Context const & expression_tree::context() const
{ return *context_; }
numeric_type const & math_expression::dtype() const
numeric_type const & expression_tree::dtype() const
{ return dtype_; }
shape_t math_expression::shape() const
shape_t expression_tree::shape() const
{ return shape_; }
int_t math_expression::dim() const
int_t expression_tree::dim() const
{ return (int_t)shape_.size(); }
//math_expression& math_expression::reshape(int_t size1, int_t size2)
//{
// assert(size1*size2==prod(shape_));
// shape_ = size4(size1, size2);
// return *this;
//}
expression_tree expression_tree::operator-()
{ return expression_tree(*this, invalid_node(), op_element(UNARY_TYPE_FAMILY, SUB_TYPE), *context_, dtype_, shape_); }
math_expression math_expression::operator-()
{ return math_expression(*this, invalid_node(), op_element(UNARY_TYPE_FAMILY, SUB_TYPE), *context_, dtype_, shape_); }
math_expression math_expression::operator!()
{ return math_expression(*this, invalid_node(), op_element(UNARY_TYPE_FAMILY, NEGATE_TYPE), *context_, INT_TYPE, shape_); }
expression_tree expression_tree::operator!()
{ return expression_tree(*this, invalid_node(), op_element(UNARY_TYPE_FAMILY, NEGATE_TYPE), *context_, INT_TYPE, shape_); }
//
math_expression::node const & lhs_most(math_expression::container_type const & array, math_expression::node const & init)
expression_tree::node const & lhs_most(expression_tree::container_type const & array, expression_tree::node const & init)
{
math_expression::node const * current = &init;
expression_tree::node const * current = &init;
while (current->lhs.subtype==COMPOSITE_OPERATOR_TYPE)
current = &array[current->lhs.node_index];
return *current;
}
math_expression::node const & lhs_most(math_expression::container_type const & array, size_t root)
expression_tree::node const & lhs_most(expression_tree::container_type const & array, size_t root)
{ return lhs_most(array, array[root]); }
//
math_expression for_idx_t::operator=(value_scalar const & r) const { return math_expression(*this, r, op_element(BINARY_TYPE_FAMILY,ASSIGN_TYPE), r.dtype()); }
math_expression for_idx_t::operator=(math_expression const & r) const { return math_expression(*this, r, op_element(BINARY_TYPE_FAMILY,ASSIGN_TYPE), r.context(), r.dtype(), r.shape()); }
expression_tree for_idx_t::operator=(value_scalar const & r) const { return expression_tree(*this, r, op_element(BINARY_TYPE_FAMILY,ASSIGN_TYPE), r.dtype()); }
expression_tree for_idx_t::operator=(expression_tree const & r) const { return expression_tree(*this, r, op_element(BINARY_TYPE_FAMILY,ASSIGN_TYPE), r.context(), r.dtype(), r.shape()); }
math_expression for_idx_t::operator+=(value_scalar const & r) const { return *this = *this + r; }
math_expression for_idx_t::operator-=(value_scalar const & r) const { return *this = *this - r; }
math_expression for_idx_t::operator*=(value_scalar const & r) const { return *this = *this * r; }
math_expression for_idx_t::operator/=(value_scalar const & r) const { return *this = *this / r; }
expression_tree for_idx_t::operator+=(value_scalar const & r) const { return *this = *this + r; }
expression_tree for_idx_t::operator-=(value_scalar const & r) const { return *this = *this - r; }
expression_tree for_idx_t::operator*=(value_scalar const & r) const { return *this = *this * r; }
expression_tree for_idx_t::operator/=(value_scalar const & r) const { return *this = *this / r; }
}