Skip to content

Commit efe0cb2

Browse files
committed
Change Lisp_Tree_Expr classes names
* Remove the non camel case notation used in this classes to follow the PEP8 code convention
1 parent 4535bc5 commit efe0cb2

File tree

9 files changed

+98
-98
lines changed

9 files changed

+98
-98
lines changed

MLC/Common/Lisp_Tree_Expr/Lisp_Tree_Expr.py renamed to MLC/Common/LispTreeExpr/LispTreeExpr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import MLC.Log.log as lg
22
from MLC.mlc_parameters.mlc_parameters import Config
33
from MLC.Common.Operations import Operations
4-
from MLC.Common.Lisp_Tree_Expr.Tree_Nodes import Leaf_Node, Internal_Node
5-
from MLC.Common.Lisp_Tree_Expr.Operation_Nodes import Op_Node_Factory
4+
from MLC.Common.LispTreeExpr.TreeNodes import LeafNode, InternalNode
5+
from MLC.Common.LispTreeExpr.OperationNodes import OpNodeFactory
66

77

8-
class Lisp_Tree_Expr(object):
8+
class LispTreeExpr(object):
99

1010
def __init__(self, expr):
1111
self._nodes = []
@@ -126,7 +126,7 @@ def _generate_leaf_node(self, expr, parent_depth, expr_index):
126126
else:
127127
param_len = len(expr)
128128

129-
leaf = Leaf_Node(expr[:param_len])
129+
leaf = LeafNode(expr[:param_len])
130130
leaf.set_depth(parent_depth)
131131
leaf.set_expr_index(expr_index)
132132
leaf.set_subtreedepth(0)
@@ -142,7 +142,7 @@ def _generate_node(self, expr, is_root_expression=False, parent_depth=0, expr_in
142142
op = self._get_operation(expr, is_root_expression)
143143

144144
# Generate the arguments of the internal node as Child Nodes
145-
node = Op_Node_Factory.make(op["op"])
145+
node = OpNodeFactory.make(op["op"])
146146
node.set_depth(parent_depth + 1)
147147
node.set_expr_index(expr_index)
148148
expr_offset = 0

MLC/Common/Lisp_Tree_Expr/Operation_Nodes.py renamed to MLC/Common/LispTreeExpr/OperationNodes.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import numpy as np
77
import sys
88

9-
from MLC.Common.Lisp_Tree_Expr.Tree_Nodes import Tree_Node
10-
from MLC.Common.Lisp_Tree_Expr.Tree_Nodes import Leaf_Node
11-
from MLC.Common.Lisp_Tree_Expr.Tree_Nodes import Internal_Node
9+
from MLC.Common.LispTreeExpr.TreeNodes import TreeNode
10+
from MLC.Common.LispTreeExpr.TreeNodes import LeafNode
11+
from MLC.Common.LispTreeExpr.TreeNodes import InternalNode
1212
from MLC.mlc_parameters.mlc_parameters import Config
1313
from MLC.Common.Operations import Operations
1414

@@ -30,25 +30,25 @@ def execute_op_without_warnings(op, log_prefix, exception_msg, arg1, arg2=None):
3030
return result
3131

3232

33-
class Plus_Node(Internal_Node):
33+
class PlusNode(InternalNode):
3434

3535
def __init__(self):
36-
Internal_Node.__init__(self, "+", 1)
36+
InternalNode.__init__(self, "+", 1)
3737

3838
def formal(self):
3939
return "(" + self._nodes[0].formal() + " + " + self._nodes[1].formal() + ")"
4040

4141
def op_simplify(self):
4242
# If one of the arguments is zero, avoid the operation
4343
if self._node_arg_x_is_y(0, 0):
44-
return Leaf_Node(self._nodes[1].to_string())
44+
return LeafNode(self._nodes[1].to_string())
4545
elif self._node_arg_x_is_y(1, 0):
46-
return Leaf_Node(self._nodes[0].to_string())
46+
return LeafNode(self._nodes[0].to_string())
4747

4848
# Non of the arguments are zero. Make the operation if they are not sensors
4949
if not self._nodes[0].is_sensor() and not self._nodes[1].is_sensor():
5050
arg = float(self._nodes[0].to_string()) + float(self._nodes[1].to_string())
51-
return Leaf_Node(process_float(arg))
51+
return LeafNode(process_float(arg))
5252
else:
5353
return self
5454

@@ -63,23 +63,23 @@ def op_compute(self, arg_list):
6363
exception_msg=err)
6464

6565

66-
class Minus_Node(Internal_Node):
66+
class MinusNode(InternalNode):
6767

6868
def __init__(self):
69-
Internal_Node.__init__(self, "-", 1)
69+
InternalNode.__init__(self, "-", 1)
7070

7171
def formal(self):
7272
return "(" + self._nodes[0].formal() + " - " + self._nodes[1].formal() + ")"
7373

7474
def op_simplify(self):
7575
# If the second argument is zero, avoid the operation.
7676
if self._node_arg_x_is_y(1, 0):
77-
return Leaf_Node(self._nodes[0].to_string())
77+
return LeafNode(self._nodes[0].to_string())
7878

7979
# Non of the arguments are zero. Make the operation if they are not sensors
8080
if not self._nodes[0].is_sensor() and not self._nodes[1].is_sensor():
8181
arg = float(self._nodes[0].to_string()) - float(self._nodes[1].to_string())
82-
return Leaf_Node(process_float(arg))
82+
return LeafNode(process_float(arg))
8383
else:
8484
return self
8585

@@ -95,28 +95,28 @@ def op_compute(self, arg_list):
9595

9696

9797

98-
class Mult_Node(Internal_Node):
98+
class MultNode(InternalNode):
9999

100100
def __init__(self):
101-
Internal_Node.__init__(self, "*", 1)
101+
InternalNode.__init__(self, "*", 1)
102102

103103
def formal(self):
104104
return "(" + self._nodes[0].formal() + " .* " + self._nodes[1].formal() + ")"
105105

106106
def op_simplify(self):
107107
# If one or both of the arguments are zero, return zero
108108
if self._node_arg_x_is_y(0, 0) or self._node_arg_x_is_y(1, 0):
109-
return Leaf_Node(process_float(0))
109+
return LeafNode(process_float(0))
110110

111111
# If one of the arguments is zero, avoid the operation
112112
if self._node_arg_x_is_y(0, 1):
113-
return Leaf_Node(self._nodes[1].to_string())
113+
return LeafNode(self._nodes[1].to_string())
114114
elif self._node_arg_x_is_y(1, 1):
115-
return Leaf_Node(self._nodes[0].to_string())
115+
return LeafNode(self._nodes[0].to_string())
116116

117117
if not self._nodes[0].is_sensor() and not self._nodes[1].is_sensor():
118118
arg = float(self._nodes[0].to_string()) * float(self._nodes[1].to_string())
119-
return Leaf_Node(process_float(arg))
119+
return LeafNode(process_float(arg))
120120
else:
121121
return self
122122

@@ -131,42 +131,42 @@ def op_compute(self, arg_list):
131131
exception_msg=err)
132132

133133

134-
class Division_Node(Internal_Node):
134+
class DivisionNode(InternalNode):
135135
PROTECTION = 0.001
136136
SIMPLIFY_PROTECTION = 0.01
137137

138138
def __init__(self):
139-
Internal_Node.__init__(self, "/", 1)
139+
InternalNode.__init__(self, "/", 1)
140140

141141
def formal(self):
142142
return "(my_div(" + self._nodes[0].formal() + "," + self._nodes[1].formal() + "))"
143143

144144
def _process_division(self, dividend, divisor):
145145
if type(divisor) == np.ndarray:
146-
new_divisor = [Division_Node.PROTECTION if np.abs(x) < Division_Node.PROTECTION else np.abs(x) for x in divisor]
146+
new_divisor = [DivisionNode.PROTECTION if np.abs(x) < DivisionNode.PROTECTION else np.abs(x) for x in divisor]
147147
return np.sign(divisor) * dividend / np.asarray(new_divisor)
148148
else:
149-
if abs(divisor) < Division_Node.PROTECTION:
150-
return np.sign(divisor) * dividend / Division_Node.PROTECTION
149+
if abs(divisor) < DivisionNode.PROTECTION:
150+
return np.sign(divisor) * dividend / DivisionNode.PROTECTION
151151

152152
return dividend / divisor
153153

154154
def op_simplify(self):
155155
# If the first argument is zero, return zero
156156
if self._node_arg_x_is_y(0, 0):
157-
return Leaf_Node(process_float(0))
157+
return LeafNode(process_float(0))
158158

159159
# If the second argument is one, return the first argument
160160
if self._node_arg_x_is_y(1, 1):
161-
return Leaf_Node(self._nodes[0].to_string())
161+
return LeafNode(self._nodes[0].to_string())
162162

163163
if not self._nodes[0].is_sensor() and not self._nodes[1].is_sensor():
164164
# FIXME: Harcoded number. Change it
165-
if abs(float(self._nodes[1].to_string())) < Division_Node.SIMPLIFY_PROTECTION:
166-
return Leaf_Node(process_float(0))
165+
if abs(float(self._nodes[1].to_string())) < DivisionNode.SIMPLIFY_PROTECTION:
166+
return LeafNode(process_float(0))
167167
else:
168168
arg = float(self._nodes[0].to_string()) / float(self._nodes[1].to_string())
169-
return Leaf_Node(process_float(arg))
169+
return LeafNode(process_float(arg))
170170
else:
171171
return self
172172

@@ -181,18 +181,18 @@ def op_compute(self, arg_list):
181181
exception_msg=err)
182182

183183

184-
class Sine_Node(Internal_Node):
184+
class SineNode(InternalNode):
185185

186186
def __init__(self):
187-
Internal_Node.__init__(self, "sin", 3)
187+
InternalNode.__init__(self, "sin", 3)
188188

189189
def formal(self):
190190
return "sin(" + self._nodes[0].formal() + ")"
191191

192192
def op_simplify(self):
193193
if not self._nodes[0].is_sensor():
194194
arg = np.sin(float(self._nodes[0].to_string()))
195-
return Leaf_Node(process_float(arg))
195+
return LeafNode(process_float(arg))
196196
else:
197197
return self
198198

@@ -206,18 +206,18 @@ def op_compute(self, arg_list):
206206
exception_msg=err)
207207

208208

209-
class Cosine_Node(Internal_Node):
209+
class CosineNode(InternalNode):
210210

211211
def __init__(self):
212-
Internal_Node.__init__(self, "cos", 3)
212+
InternalNode.__init__(self, "cos", 3)
213213

214214
def formal(self):
215215
return "cos(" + self._nodes[0].formal() + ")"
216216

217217
def op_simplify(self):
218218
if not self._nodes[0].is_sensor():
219219
arg = np.cos(float(self._nodes[0].to_string()))
220-
return Leaf_Node(process_float(arg))
220+
return LeafNode(process_float(arg))
221221
else:
222222
return self
223223

@@ -231,33 +231,33 @@ def op_compute(self, arg_list):
231231
exception_msg=err)
232232

233233

234-
class Logarithm_Node(Internal_Node):
234+
class LogarithmNode(InternalNode):
235235
PROTECTION = 0.00001
236236
SIMPLIFY_PROTECTION = 0.01
237237

238238
def __init__(self):
239-
Internal_Node.__init__(self, "log", 5)
239+
InternalNode.__init__(self, "log", 5)
240240

241241
def formal(self):
242242
return "my_log(" + self._nodes[0].formal() + ")"
243243

244244
def _process_arg(self, arg):
245245
if type(arg) == np.ndarray:
246-
return [Logarithm_Node.PROTECTION if np.abs(x) < Logarithm_Node.PROTECTION else np.abs(x) for x in arg]
246+
return [LogarithmNode.PROTECTION if np.abs(x) < LogarithmNode.PROTECTION else np.abs(x) for x in arg]
247247
else:
248-
if abs(arg) < Logarithm_Node.PROTECTION:
249-
return Logarithm_Node.PROTECTION
248+
if abs(arg) < LogarithmNode.PROTECTION:
249+
return LogarithmNode.PROTECTION
250250

251251
return abs(arg)
252252

253253
def op_simplify(self):
254254
if not self._nodes[0].is_sensor():
255-
if float(self._nodes[0].to_string()) < Logarithm_Node.SIMPLIFY_PROTECTION:
256-
arg = np.log(Logarithm_Node.SIMPLIFY_PROTECTION)
255+
if float(self._nodes[0].to_string()) < LogarithmNode.SIMPLIFY_PROTECTION:
256+
arg = np.log(LogarithmNode.SIMPLIFY_PROTECTION)
257257
else:
258258
arg = np.log(float(self._nodes[0].to_string()))
259259

260-
return Leaf_Node(process_float(arg))
260+
return LeafNode(process_float(arg))
261261
else:
262262
return self
263263

@@ -271,10 +271,10 @@ def op_compute(self, arg_list):
271271
exception_msg=err)
272272

273273

274-
class Exponential_Node(Internal_Node):
274+
class ExponentialNode(InternalNode):
275275

276276
def __init__(self):
277-
Internal_Node.__init__(self, "exp", 5)
277+
InternalNode.__init__(self, "exp", 5)
278278

279279
def formal(self):
280280
return "exp(" + self._nodes[0].formal() + ")"
@@ -287,9 +287,9 @@ def op_simplify(self):
287287
except OverflowError:
288288
# FIXME: See what to do with this expression, because there are problems when
289289
# an infinite value is the argument of a sinusoidal function
290-
return Leaf_Node(process_float(float("inf")))
290+
return LeafNode(process_float(float("inf")))
291291

292-
return Leaf_Node(process_float(arg))
292+
return LeafNode(process_float(arg))
293293
else:
294294
return self
295295

@@ -303,18 +303,18 @@ def op_compute(self, arg_list):
303303
exception_msg=err)
304304

305305

306-
class Tanh_Node(Internal_Node):
306+
class TanhNode(InternalNode):
307307

308308
def __init__(self):
309-
Internal_Node.__init__(self, "tanh", 5)
309+
InternalNode.__init__(self, "tanh", 5)
310310

311311
def formal(self):
312312
return "tanh(" + self._nodes[0].formal() + ")"
313313

314314
def op_simplify(self):
315315
if not self._nodes[0].is_sensor():
316316
arg = np.tanh(float(self._nodes[0].to_string()))
317-
return Leaf_Node(process_float(arg))
317+
return LeafNode(process_float(arg))
318318
else:
319319
return self
320320

@@ -328,10 +328,10 @@ def op_compute(self, arg_list):
328328
exception_msg=err)
329329

330330

331-
class RootNode(Internal_Node):
331+
class RootNode(InternalNode):
332332

333333
def __init__(self):
334-
Internal_Node.__init__(self, "", 0)
334+
InternalNode.__init__(self, "", 0)
335335

336336
def to_string(self):
337337
return " ".join([n.to_string() for n in self._nodes])
@@ -357,7 +357,7 @@ def accept(self, visitor):
357357
node.accept(visitor)
358358

359359

360-
class Op_Node_Factory:
360+
class OpNodeFactory:
361361

362362
@staticmethod
363363
def make(op):

0 commit comments

Comments
 (0)