Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions source/adios2/toolkit/derived/DerivedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ struct DerivedData
Dims Count;
DataType Type;
};

struct ExprData
{
std::vector<DerivedData> Data;
std::vector<std::string> Const;
DataType OutType;
};
}
}
#endif
348 changes: 165 additions & 183 deletions source/adios2/toolkit/derived/Expression.cpp

Large diffs are not rendered by default.

75 changes: 25 additions & 50 deletions source/adios2/toolkit/derived/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,79 +37,54 @@ enum ExpressionOperator
namespace derived
{
/*
A Note on ExpressionTree:
- Sub expressions can include another operation node or a variable name
A Note on Expression:
- Sub expressions can include another operation nodes or variable names
- the third entry in the tuple distinguishes between variable and operation
- OpInfo contains information about the operation stoder in the node
- The type of the operation
- Indexing/Slicing: detail is indices (std::vector<std::tuple<size_t start, size_t end, size_t
stride>>, e.g. for each dimension start:end:stride
- Constant used to compute the operation [e.g. log_2]
- The type of the operation
- Constants are used to compute the operation [e.g. log_2, var + 2, etc.]
*/
struct OpInfo
{
adios2::detail::ExpressionOperator operation;
std::vector<std::tuple<size_t, size_t, size_t>> indices;
double constant;
};

class ExpressionTree
{
public:
std::vector<std::tuple<ExpressionTree, std::string, bool>> sub_exprs;
OpInfo detail;

ExpressionTree() : detail({adios2::detail::ExpressionOperator::OP_NULL, {}, 0}) {}
ExpressionTree(adios2::detail::ExpressionOperator o) : detail({o, {}, 0}) {}
ExpressionTree(adios2::detail::ExpressionOperator o, double c) : detail({o, {}, 0}) {}
ExpressionTree(std::vector<std::tuple<size_t, size_t, size_t>> indices)
: detail({adios2::detail::ExpressionOperator ::OP_INDEX, indices, 0})
{
}

void set_base(double c);
void set_indeces(std::vector<std::tuple<size_t, size_t, size_t>> index_list);

void add_child(ExpressionTree exp);
void add_child(std::string var);

std::vector<std::string> VariableNameList();
std::tuple<Dims, Dims, Dims>
GetDims(std::map<std::string, std::tuple<Dims, Dims, Dims>> NameToDims);
DataType GetType(std::map<std::string, DataType> NameToType);
std::vector<DerivedData>
ApplyExpression(const size_t numBlocks,
std::map<std::string, std::vector<DerivedData>> nameToData);
void print();
std::string toStringExpr();
};

class Expression
{
ExpressionTree m_Expr;
adios2::detail::ExpressionOperator m_Operator;
// the subexpressions can be other expressions or variables
std::vector<std::tuple<Expression, std::string, bool>> m_SubExprs;
// a set of constants attached to the operation
std::vector<std::string> m_Consts;

Dims m_Shape;
Dims m_Start;
Dims m_Count;

void Print();

public:
std::string m_ExprString;

Expression() = default;
Expression(std::string expression);

std::string ExprString;

Dims GetShape();
Dims GetStart();
Dims GetCount();
DataType GetType(std::map<std::string, DataType> NameToType);
std::string toStringExpr();
std::tuple<Dims, Dims, Dims>
GetDims(std::map<std::string, std::tuple<Dims, Dims, Dims>> NameToDims);
std::vector<std::tuple<Expression, std::string, bool>> GetChildren();
std::vector<std::string> GetConstants();

void SetDims(std::map<std::string, std::tuple<Dims, Dims, Dims>> NameToDims);
std::vector<std::string> VariableNameList();
void SetOperationType(adios2::detail::ExpressionOperator op);

std::vector<DerivedData>
ApplyExpression(const size_t numBlocks,
std::map<std::string, std::vector<DerivedData>> nameToData);

void AddExpChild(Expression exp);
void AddVarChild(std::string var);
void AddNumChild(std::string c);

std::string toStringExpr();
std::vector<std::string> VariableNameList();
};

}
Expand Down
Loading
Loading