Skip to content

Commit 6f8900e

Browse files
authored
fix(framework): support for list of float, list of int, and list of string as operator input (#2340)
1 parent 3f5994b commit 6f8900e

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ def eval(self, pin=None):
816816
if output._pin == pin:
817817
return output()
818818

819-
def _find_outputs_corresponding_pins(self, type_names, inpt, pin, corresponding_pins):
819+
def _find_outputs_corresponding_pins(
820+
self, type_names, inpt, pin, corresponding_pins, input_type_name
821+
):
820822
from ansys.dpf.core.results import Result
821823

822824
for python_name in type_names:
@@ -827,7 +829,7 @@ def _find_outputs_corresponding_pins(self, type_names, inpt, pin, corresponding_
827829
python_name = "bool"
828830

829831
# Type match
830-
if type(inpt).__name__ == python_name:
832+
if input_type_name == python_name:
831833
corresponding_pins.append(pin)
832834
# if the inpt has multiple potential outputs, find which ones can match
833835
elif isinstance(inpt, (_Outputs, Operator, Result)):

src/ansys/dpf/core/inputs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def connect(self, inpt):
106106
inpt = inpt.value
107107

108108
input_type_name = type(inpt).__name__
109+
if input_type_name == "list":
110+
input_type_name = f"list[{type(inpt[0]).__name__}]"
109111
if not (input_type_name in self._python_expected_types or ["Outputs", "Output", "Any"]):
110112
for types in self._python_expected_types:
111113
print(types, end=" ")
@@ -114,7 +116,7 @@ def connect(self, inpt):
114116

115117
corresponding_pins = []
116118
self._operator()._find_outputs_corresponding_pins(
117-
self._python_expected_types, inpt, self._pin, corresponding_pins
119+
self._python_expected_types, inpt, self._pin, corresponding_pins, input_type_name
118120
)
119121
if len(corresponding_pins) > 1:
120122
err_str = "Pin connection is ambiguous, specify the input to connect to with:\n"
@@ -132,7 +134,7 @@ def connect(self, inpt):
132134

133135
if len(corresponding_pins) == 0:
134136
err_str = (
135-
f"The input operator for the {self._spec.name} pin must be "
137+
f"The input for the {self._spec.name} pin is of type {input_type_name} but must be "
136138
"one of the following types:\n"
137139
)
138140
err_str += "\n".join([f"- {py_type}" for py_type in self._python_expected_types])
@@ -260,12 +262,15 @@ def connect(self, inpt):
260262
inpt = inpt.value
261263

262264
input_type_name = type(inpt).__name__
265+
if input_type_name == "list":
266+
input_type_name = f"list[{type(inpt[0]).__name__}]"
263267
for input_pin in self._inputs:
264268
self._operator()._find_outputs_corresponding_pins(
265269
input_pin._python_expected_types,
266270
inpt,
267271
input_pin._pin,
268272
corresponding_pins,
273+
input_type_name,
269274
)
270275
if len(corresponding_pins) > 1:
271276
err_str = "Pin connection is ambiguous, specify the input to connect to with:\n"

src/ansys/dpf/core/mapping_types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ def __missing__(self, key):
7171
map_types_to_python = _smart_dict_snake()
7272
for k, v in map_types_to_cpp.items():
7373
map_types_to_python[v] = k
74-
map_types_to_python["vector<double>"] = "list"
74+
map_types_to_python["vector<bool>"] = "list[bool]"
75+
map_types_to_python["vector<int32>"] = "list[int]"
76+
map_types_to_python["vector<double>"] = "list[float]"
77+
map_types_to_python["vector<string>"] = "list[str]"
7578
map_types_to_python["b"] = "bool"

0 commit comments

Comments
 (0)