Skip to content

Commit

Permalink
Remove 'efficient' suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
tbittar committed Aug 27, 2024
1 parent 952bce4 commit 85f3953
Show file tree
Hide file tree
Showing 28 changed files with 579 additions and 729 deletions.
2 changes: 1 addition & 1 deletion src/andromede/expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ComparisonNode,
ComponentParameterNode,
DivisionNode,
ExpressionNodeEfficient,
ExpressionNode,
ExpressionRange,
InstancesTimeIndex,
LiteralNode,
Expand Down
12 changes: 3 additions & 9 deletions src/andromede/expression/context_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
from dataclasses import dataclass

from . import CopyVisitor
from .expression import (
ComponentParameterNode,
ExpressionNodeEfficient,
ParameterNode,
)
from .expression import ComponentParameterNode, ExpressionNode, ParameterNode
from .visitor import visit


Expand All @@ -30,13 +26,11 @@ class ContextAdder(CopyVisitor):

component_id: str

def parameter(self, node: ParameterNode) -> ExpressionNodeEfficient:
def parameter(self, node: ParameterNode) -> ExpressionNode:
return ComponentParameterNode(self.component_id, node.name)

# Nothing is done is a component parameter node is encountered as it may have been generated from port resolution


def add_component_context(
id: str, expression: ExpressionNodeEfficient
) -> ExpressionNodeEfficient:
def add_component_context(id: str, expression: ExpressionNode) -> ExpressionNode:
return visit(expression, ContextAdder(id))
28 changes: 13 additions & 15 deletions src/andromede/expression/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .expression import (
ComparisonNode,
ComponentParameterNode,
ExpressionNodeEfficient,
ExpressionNode,
ExpressionRange,
InstancesTimeIndex,
LiteralNode,
Expand All @@ -31,23 +31,23 @@


@dataclass(frozen=True)
class CopyVisitor(ExpressionVisitorOperations[ExpressionNodeEfficient]):
class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]):
"""
Simply copies the whole AST.
"""

def literal(self, node: LiteralNode) -> ExpressionNodeEfficient:
def literal(self, node: LiteralNode) -> ExpressionNode:
return LiteralNode(node.value)

def comparison(self, node: ComparisonNode) -> ExpressionNodeEfficient:
def comparison(self, node: ComparisonNode) -> ExpressionNode:
return ComparisonNode(
visit(node.left, self), visit(node.right, self), node.comparator
)

def parameter(self, node: ParameterNode) -> ExpressionNodeEfficient:
def parameter(self, node: ParameterNode) -> ExpressionNode:
return ParameterNode(node.name)

def comp_parameter(self, node: ComponentParameterNode) -> ExpressionNodeEfficient:
def comp_parameter(self, node: ComponentParameterNode) -> ExpressionNode:
return ComponentParameterNode(node.component_id, node.name)

def copy_expression_range(
Expand All @@ -70,32 +70,30 @@ def copy_instances_index(
if isinstance(expressions, ExpressionRange):
return InstancesTimeIndex(self.copy_expression_range(expressions))
if isinstance(expressions, list):
expressions_list = cast(List[ExpressionNodeEfficient], expressions)
expressions_list = cast(List[ExpressionNode], expressions)
copy = [visit(e, self) for e in expressions_list]
return InstancesTimeIndex(copy)
raise ValueError("Unexpected type in instances index")

def time_operator(self, node: TimeOperatorNode) -> ExpressionNodeEfficient:
def time_operator(self, node: TimeOperatorNode) -> ExpressionNode:
return TimeOperatorNode(
visit(node.operand, self),
node.name,
self.copy_instances_index(node.instances_index),
)

def time_aggregator(self, node: TimeAggregatorNode) -> ExpressionNodeEfficient:
def time_aggregator(self, node: TimeAggregatorNode) -> ExpressionNode:
return TimeAggregatorNode(visit(node.operand, self), node.name, node.stay_roll)

def scenario_operator(self, node: ScenarioOperatorNode) -> ExpressionNodeEfficient:
def scenario_operator(self, node: ScenarioOperatorNode) -> ExpressionNode:
return ScenarioOperatorNode(visit(node.operand, self), node.name)

def port_field(self, node: PortFieldNode) -> ExpressionNodeEfficient:
def port_field(self, node: PortFieldNode) -> ExpressionNode:
return PortFieldNode(node.port_name, node.field_name)

def port_field_aggregator(
self, node: PortFieldAggregatorNode
) -> ExpressionNodeEfficient:
def port_field_aggregator(self, node: PortFieldAggregatorNode) -> ExpressionNode:
return PortFieldAggregatorNode(visit(node.operand, self), node.aggregator)


def copy_expression(expression: ExpressionNodeEfficient) -> ExpressionNodeEfficient:
def copy_expression(expression: ExpressionNode) -> ExpressionNode:
return visit(expression, CopyVisitor())
12 changes: 5 additions & 7 deletions src/andromede/expression/equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ComparisonNode,
ComponentParameterNode,
DivisionNode,
ExpressionNodeEfficient,
ExpressionNode,
ExpressionRange,
InstancesTimeIndex,
LiteralNode,
Expand Down Expand Up @@ -51,9 +51,7 @@ def __post_init__(self) -> None:
f"Relative comparison tolerance must be >= 0, got {self.rel_tol}"
)

def visit(
self, left: ExpressionNodeEfficient, right: ExpressionNodeEfficient
) -> bool:
def visit(self, left: ExpressionNode, right: ExpressionNode) -> bool:
if left.__class__ != right.__class__:
return False
if isinstance(left, LiteralNode) and isinstance(right, LiteralNode):
Expand Down Expand Up @@ -187,8 +185,8 @@ def port_field_aggregator(


def expressions_equal(
left: ExpressionNodeEfficient,
right: ExpressionNodeEfficient,
left: ExpressionNode,
right: ExpressionNode,
abs_tol: float = 0,
rel_tol: float = 0,
) -> bool:
Expand All @@ -199,7 +197,7 @@ def expressions_equal(


def expressions_equal_if_present(
lhs: Optional[ExpressionNodeEfficient], rhs: Optional[ExpressionNodeEfficient]
lhs: Optional[ExpressionNode], rhs: Optional[ExpressionNode]
) -> bool:
if lhs is None and rhs is None:
return True
Expand Down
6 changes: 3 additions & 3 deletions src/andromede/expression/evaluate_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ComparisonNode,
ComponentParameterNode,
DivisionNode,
ExpressionNodeEfficient,
ExpressionNode,
ExpressionRange,
InstancesTimeIndex,
LiteralNode,
Expand Down Expand Up @@ -211,7 +211,7 @@ def check_resolved_expr(


def resolve_coefficient(
expression: ExpressionNodeEfficient, value_provider: ValueProvider, row_id: RowIndex
expression: ExpressionNode, value_provider: ValueProvider, row_id: RowIndex
) -> float:
result = visit(expression, ParameterEvaluationVisitor(value_provider, row_id))
check_resolved_expr(result, row_id)
Expand Down Expand Up @@ -261,7 +261,7 @@ def float_to_int(value: float) -> int:


def evaluate_time_id(
expr: ExpressionNodeEfficient, value_provider: ValueProvider, row_id: RowIndex
expr: ExpressionNode, value_provider: ValueProvider, row_id: RowIndex
) -> int:
float_time_id_in_list = visit(expr, InstancesIndexVisitor(value_provider, row_id))
check_resolved_expr(float_time_id_in_list, row_id)
Expand Down
Loading

0 comments on commit 85f3953

Please sign in to comment.