Publishing 2019 R2 content (#223)
[platform/upstream/dldt.git] / inference-engine / src / vpu / graph_transformer / include / vpu / utils / simple_math.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <set>
8 #include <map>
9 #include <vector>
10 #include <functional>
11 #include <string>
12 #include <utility>
13
14 #include <vpu/utils/containers.hpp>
15
16 //
17 // Simple integer arithmetics to be used for the work sizes calculation.
18 // Supported operations : +,-,*,/,%,(,)
19 // no unary -,+
20 // Variables defined as single chars and should not include one of the ops, whitespaces or 0-9
21 //
22
23 namespace vpu {
24
25 class SimpleMathExpression final {
26 public:
27     void setVariables(const std::map<char, int>& vars) { _vars = vars; }
28
29     void parse(const std::string& expression);
30
31     int evaluate() const;
32
33 private:
34     struct Token final {
35         enum TokenType {
36             Value,
37             Operator,
38         };
39
40         TokenType type;
41         int value;
42         char op;
43
44         explicit Token(TokenType t = Value, int v = 0, char o = 0) : type(t), value(v), op(o) {}
45     };
46
47 private:
48     std::map<char, int> _vars;
49     SmallVector<Token> _parsedTokens;
50 };
51
52 }  // namespace vpu