OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::Expr Class Reference

Basic value-substitute enabling extraction of expression trees for code generation. More...

#include <expr.h>

+ Inheritance diagram for olb::Expr:
+ Collaboration diagram for olb::Expr:

Public Types

enum struct  Op : std::size_t {
  Add , Mul , Sub , Div ,
  Sqrt , Abs , Pow , Exp ,
  End
}
 

Public Member Functions

 Expr ()
 
 Expr (Expr &&rhs)
 
 Expr (const Expr &rhs)
 
 Expr (double v)
 
 Expr (std::string name)
 
 Expr (Expr lhs, Op op, Expr rhs)
 
 Expr (Op op, Expr rhs)
 
Exproperator= (const Expr &rhs)
 
Exproperator+= (Expr rhs)
 
Exproperator-= (Expr rhs)
 
Exproperator*= (Expr rhs)
 
Exproperator/= (Expr rhs)
 
void describe (std::stringstream &out) const
 Writes the serialized expression tree to out.
 
std::string describe () const
 Returns the serialized expression tree.
 
bool isSymbol (std::string name) const
 Helper function to quickly check if Expr is a specific symbol.
 
std::size_t size () const
 Returns expanded size of tree.
 

Static Public Member Functions

static void reset ()
 Resets FLOP counter.
 
static void increment (Op op)
 Increment FLOP counter.
 
static std::size_t count ()
 Return accumulated FLOPs.
 
static std::size_t count (Op op)
 Return accumulated FLOPs of type.
 

Detailed Description

Basic value-substitute enabling extraction of expression trees for code generation.

Definition at line 39 of file expr.h.

Member Enumeration Documentation

◆ Op

enum struct olb::Expr::Op : std::size_t
strong
Enumerator
Add 
Mul 
Sub 
Div 
Sqrt 
Abs 
Pow 
Exp 
End 

Definition at line 41 of file expr.h.

Constructor & Destructor Documentation

◆ Expr() [1/7]

olb::Expr::Expr ( )

Definition at line 94 of file expr.cpp.

94 :
95 _payload(Constant{}) { }

◆ Expr() [2/7]

olb::Expr::Expr ( Expr && rhs)

Definition at line 97 of file expr.cpp.

97 :
98 _payload(rhs._payload) { }

◆ Expr() [3/7]

olb::Expr::Expr ( const Expr & rhs)

Definition at line 100 of file expr.cpp.

100 :
101 _payload(rhs._payload) { }

◆ Expr() [4/7]

olb::Expr::Expr ( double v)

Definition at line 103 of file expr.cpp.

103 :
104 _payload(Constant{v}) { }

◆ Expr() [5/7]

olb::Expr::Expr ( std::string name)

Definition at line 106 of file expr.cpp.

106 :
107 _payload(Symbol{name}) { }
std::string name()
Returns name of FIELD for human consumption.
Definition fields.h:49

◆ Expr() [6/7]

olb::Expr::Expr ( Expr lhs,
Op op,
Expr rhs )

Definition at line 109 of file expr.cpp.

109 :
110 _payload(Binary(lhs, op, rhs)) { }

◆ Expr() [7/7]

olb::Expr::Expr ( Op op,
Expr rhs )

Definition at line 112 of file expr.cpp.

112 :
113 _payload(Unary(op, rhs)) { }

Member Function Documentation

◆ count() [1/2]

static std::size_t olb::Expr::count ( )
inlinestatic

Return accumulated FLOPs.

Definition at line 133 of file expr.h.

133 {
134 return std::accumulate(_stats.cbegin(), _stats.cend(), 0);
135 }
+ Here is the caller graph for this function:

◆ count() [2/2]

static std::size_t olb::Expr::count ( Op op)
inlinestatic

Return accumulated FLOPs of type.

Definition at line 138 of file expr.h.

138 {
139 return _stats[static_cast<std::size_t>(op)];
140 }

◆ describe() [1/2]

std::string olb::Expr::describe ( ) const

Returns the serialized expression tree.

Definition at line 150 of file expr.cpp.

150 {
151 std::stringstream out;
152 describe(out);
153 return out.str();
154};
std::string describe() const
Returns the serialized expression tree.
Definition expr.cpp:150

References describe().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ describe() [2/2]

void olb::Expr::describe ( std::stringstream & out) const

Writes the serialized expression tree to out.

Definition at line 144 of file expr.cpp.

144 {
145 std::visit([&out](auto& x) {
146 x.describe(out);
147 }, _payload);
148};

◆ increment()

static void olb::Expr::increment ( Op op)
inlinestatic

Increment FLOP counter.

Definition at line 128 of file expr.h.

128 {
129 ++_stats[static_cast<std::size_t>(op)];
130 }
+ Here is the caller graph for this function:

◆ isSymbol()

bool olb::Expr::isSymbol ( std::string name) const

Helper function to quickly check if Expr is a specific symbol.

Definition at line 156 of file expr.cpp.

156 {
157 if (auto symbol = std::get_if<Symbol>(&_payload)) {
158 return (*symbol).name == name;
159 }
160 return false;
161}

◆ operator*=()

Expr & olb::Expr::operator*= ( Expr rhs)

Definition at line 132 of file expr.cpp.

132 {
134 _payload = Binary(*this, Op::Mul, rhs);
135 return *this;
136}
static void increment(Op op)
Increment FLOP counter.
Definition expr.h:128

References increment(), and Mul.

+ Here is the call graph for this function:

◆ operator+=()

Expr & olb::Expr::operator+= ( Expr rhs)

Definition at line 120 of file expr.cpp.

120 {
122 _payload = Binary(*this, Op::Add, rhs);
123 return *this;
124}

References Add, and increment().

+ Here is the call graph for this function:

◆ operator-=()

Expr & olb::Expr::operator-= ( Expr rhs)

Definition at line 126 of file expr.cpp.

126 {
128 _payload = Binary(*this, Op::Sub, rhs);
129 return *this;
130}

References increment(), and Sub.

+ Here is the call graph for this function:

◆ operator/=()

Expr & olb::Expr::operator/= ( Expr rhs)

Definition at line 138 of file expr.cpp.

138 {
140 _payload = Binary(*this, Op::Div, rhs);
141 return *this;
142}

References Div, and increment().

+ Here is the call graph for this function:

◆ operator=()

Expr & olb::Expr::operator= ( const Expr & rhs)

Definition at line 115 of file expr.cpp.

115 {
116 _payload = rhs._payload;
117 return *this;
118}

◆ reset()

static void olb::Expr::reset ( )
inlinestatic

Resets FLOP counter.

Definition at line 123 of file expr.h.

123 {
124 _stats.fill(0);
125 }
+ Here is the caller graph for this function:

◆ size()

std::size_t olb::Expr::size ( ) const

Returns expanded size of tree.

Definition at line 163 of file expr.cpp.

163 {
164 std::size_t size{};
165 std::visit([&size](auto& x) {
166 size = x.size();
167 }, _payload);
168 return size;
169}
std::size_t size() const
Returns expanded size of tree.
Definition expr.cpp:163

References size().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: