Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def converter_groups_to_input(group_for_inputs):
"""
Return fields for each axis and number of all groups.
Requires having axes for all the input fields.
Parameters
----------
group_for_inputs :
specified axes (groups) for each input
"""
input_for_axis = {}
ngr = 0
for inp, grs in group_for_inputs.items():
for gr in ensure_list(grs):
if gr in input_for_axis.keys():
input_for_axis[gr].append(inp)
else:
ngr += 1
input_for_axis[gr] = [inp]
return input_for_axis, ngr
def combine_final_groups(combiner, groups, groups_stack, keys):
"""Combine the final groups."""
input_for_groups, _ = converter_groups_to_input(groups)
combiner_all = []
for comb in combiner:
for gr in ensure_list(groups[comb]):
combiner_all += input_for_groups[gr]
combiner_all = list(set(combiner_all))
combiner_all.sort()
# groups that were removed (so not trying to remove twice)
grs_removed = []
groups_stack_final = deepcopy(groups_stack)
for comb in combiner:
grs = groups[comb]
for gr in ensure_list(grs):
if gr in groups_stack_final[-1]:
grs_removed.append(gr)
groups_stack_final[-1].remove(gr)
elif gr in grs_removed:
pass
else:
def map_splits(split_iter, inputs, cont_dim=None):
"""generate a dictionary of inputs prescribed by the splitter."""
if cont_dim is None:
cont_dim = {}
for split in split_iter:
yield {
k: list(flatten(ensure_list(inputs[k]), max_depth=cont_dim.get(k, None)))[v]
for k, v in split.items()
}
if token == ".":
if all(trm_str.values()):
if group_count is None:
group_count = 0
else:
group_count += 1
oldgroup = groups[terms["L"]] = groups[terms["R"]] = group_count
elif trm_str["R"]:
groups[terms["R"]] = oldgroups["L"]
oldgroup = oldgroups["L"]
elif trm_str["L"]:
groups[terms["L"]] = oldgroups["R"]
oldgroup = oldgroups["R"]
else:
if len(ensure_list(oldgroups["L"])) != len(
ensure_list(oldgroups["R"])
):
raise ValueError(
"Operands do not have same shape "
"(left one is {}d and right one is {}d.".format(
len(ensure_list(oldgroups["L"])),
len(ensure_list(oldgroups["R"])),
)
)
oldgroup = oldgroups["L"]
# dj: changing axes for Right part of the scalar op.
for k, v in groups.items():
if v in ensure_list(oldgroups["R"]):
groups[k] = ensure_list(oldgroups["L"])[
ensure_list(oldgroups["R"]).index(v)
]
else: # if token == "*":
def _command_shelltask_executable(self, field, state_ind, ind):
"""Returining position and value for executable ShellTask input"""
pos = 0 # executable should be the first el. of the command
value = self._field_value(field=field, state_ind=state_ind, ind=ind)
if value is None:
raise Exception("executable has to be set")
return pos, ensure_list(value, tuple2list=True)
def cache_locations(self):
"""Get the list of cache sources."""
return self._cache_locations + ensure_list(self._cache_dir)
def edges(self, edges):
"""Add edges to the graph (nodes should be already set)."""
if edges:
edges = ensure_list(edges)
for (nd_out, nd_in) in edges:
if nd_out not in self.nodes or nd_in not in self.nodes:
raise Exception(
f"edge {(nd_out, nd_in)} can't be added to the graph"
)
self._edges = edges
def cache_locations(self, locations):
if locations is not None:
self._cache_locations = [Path(loc) for loc in ensure_list(locations)]
else:
self._cache_locations = []
def add_nodes(self, new_nodes):
"""Insert new nodes and sort the new graph."""
self.nodes = self._nodes + ensure_list(new_nodes)
for nd in ensure_list(new_nodes):
self.predecessors[nd.name] = []
self.successors[nd.name] = []
if self._sorted_nodes is not None:
# starting from the previous sorted list, so is faster
self.sorting(presorted=self.sorted_nodes + ensure_list(new_nodes))