Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from inference.core.workflows.core_steps.common.query_language.evaluation_engine.detection.geometry import (
is_point_in_zone,
)
from inference.core.workflows.core_steps.common.query_language.operations.core import (
build_operations_chain,
)

BINARY_OPERATORS = {
"==": lambda a, b: a == b,
Expand Down Expand Up @@ -116,23 +119,37 @@ def create_operand_builder(
definition: Union[StaticOperand, DynamicOperand],
execution_context: str,
) -> Callable[[Dict[str, T]], V]:
if isinstance(definition, StaticOperand):
return create_static_operand_builder(
definition, execution_context=execution_context
# Avoid repeated isinstance and call by using direct comparison and shared fast-path
# This is safe since DynamicOperand and StaticOperand are distinct types
cls = type(definition)
if cls is StaticOperand:
# Use fast path for StaticOperand
operations_fun = build_operations_chain(
operations=definition.operations,
execution_context=f"{execution_context}.operations",
)
return partial(
static_operand_builder,
static_value=definition.value,
operations_function=operations_fun,
)
else:
# Assume only StaticOperand and DynamicOperand ever used
operations_fun = build_operations_chain(
operations=definition.operations,
execution_context=f"{execution_context}.operations",
)
return partial(
dynamic_operand_builder,
operand_name=definition.operand_name,
operations_function=operations_fun,
)
return create_dynamic_operand_builder(
definition, execution_context=execution_context
)


def create_static_operand_builder(
definition: StaticOperand,
execution_context: str,
) -> Callable[[Dict[str, T]], V]:
# local import to avoid circular dependency of modules with operations and evaluation
from inference.core.workflows.core_steps.common.query_language.operations.core import (
build_operations_chain,
)

operations_fun = build_operations_chain(
operations=definition.operations,
Expand All @@ -157,10 +174,6 @@ def create_dynamic_operand_builder(
definition: DynamicOperand,
execution_context: str,
) -> Callable[[Dict[str, T]], V]:
# local import to avoid circular dependency of modules with operations and evaluation
from inference.core.workflows.core_steps.common.query_language.operations.core import (
build_operations_chain,
)

operations_fun = build_operations_chain(
operations=definition.operations,
Expand Down
Loading