Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if inferred_namespace != curried_namespace:
missing = set(inferred_namespace) - set(curried_namespace)
if missing:
to_insert = sorted("%s," % f for f in missing)
raise AssertionError(
"There are missing functions in eth_utils.curried:\n"
+ "\n".join(to_insert)
)
extra = set(curried_namespace) - set(inferred_namespace)
if extra:
raise AssertionError(
"There are extra functions in eth_utils.curried:\n"
+ "\n".join(sorted(extra))
)
unequal = merge_with(list, inferred_namespace, curried_namespace)
unequal = valfilter(lambda x: x[0] != x[1], unequal)
to_curry = keyfilter(lambda x: should_curry(getattr(eth_utils, x)), unequal)
if to_curry:
to_curry_formatted = sorted("{0} = curry({0})".format(f) for f in to_curry)
raise AssertionError(
"There are missing functions to curry in eth_utils.curried:\n"
+ "\n".join(to_curry_formatted)
)
elif unequal:
not_to_curry_formatted = sorted(unequal)
raise AssertionError(
"Missing functions NOT to curry in eth_utils.curried:\n"
+ "\n".join(not_to_curry_formatted)
)
else:
raise AssertionError(
inner_inds |= tn_iix
# add tensors, reindexing if necessary
for tid, tsr in tn.tensor_map.items():
if b_ix and any(i in reind for i in tsr.inds):
tsr = tsr.reindex(reind, inplace=virtual)
self.add_tensor(tsr, virtual=virtual, tid=tid)
else: # directly add tensor/tag indexes
for tid, tsr in tn.tensor_map.items():
T = tsr if virtual else tsr.copy()
self.tensor_map[tid] = T
T.add_owner(self, tid)
self.tag_map = merge_with(set_union, self.tag_map, tn.tag_map)
self.ind_map = merge_with(set_union, self.ind_map, tn.ind_map)
else:
inner_inds |= tn_iix
# add tensors, reindexing if necessary
for tid, tsr in tn.tensor_map.items():
if b_ix and any(i in reind for i in tsr.inds):
tsr = tsr.reindex(reind, inplace=virtual)
self.add_tensor(tsr, virtual=virtual, tid=tid)
else: # directly add tensor/tag indexes
for tid, tsr in tn.tensor_map.items():
T = tsr if virtual else tsr.copy()
self.tensor_map[tid] = T
T.add_owner(self, tid)
self.tag_map = merge_with(set_union, self.tag_map, tn.tag_map)
self.ind_map = merge_with(set_union, self.ind_map, tn.ind_map)
inner_inds |= tn_iix
# add tensors, reindexing if necessary
for tid, tsr in tn.tensor_map.items():
if b_ix and any(i in reind for i in tsr.inds):
tsr = tsr.reindex(reind, inplace=virtual)
self.add_tensor(tsr, virtual=virtual, tid=tid)
else: # directly add tensor/tag indexes
for tid, tsr in tn.tensor_map.items():
T = tsr if virtual else tsr.copy()
self.tensor_map[tid] = T
T.add_owner(self, tid)
self.tag_map = merge_with(set_union, self.tag_map, tn.tag_map)
self.ind_map = merge_with(set_union, self.ind_map, tn.ind_map)
else:
inner_inds |= tn_iix
# add tensors, reindexing if necessary
for tid, tsr in tn.tensor_map.items():
if b_ix and any(i in reind for i in tsr.inds):
tsr = tsr.reindex(reind, inplace=virtual)
self.add_tensor(tsr, virtual=virtual, tid=tid)
else: # directly add tensor/tag indexes
for tid, tsr in tn.tensor_map.items():
T = tsr if virtual else tsr.copy()
self.tensor_map[tid] = T
T.add_owner(self, tid)
self.tag_map = merge_with(set_union, self.tag_map, tn.tag_map)
self.ind_map = merge_with(set_union, self.ind_map, tn.ind_map)
def union(self, other: Type['GeneSignature']) -> Type['GeneSignature']:
"""
Creates a new :class:`GeneSignature` instance which is the union of this signature and the other supplied
signature.
The weight associated with the genes in the intersection is the maximum of the weights in the composing signatures.
:param other: The other :class:`GeneSignature`.
:return: the new :class:`GeneSignature` instance.
"""
return self.copy(name="({} | {})".format(self.name, other.name) if self.name != other.name else self.name,
gene2weight=frozendict(merge_with(max, self.gene2weight, other.gene2weight)))
Returns:
BatchDataRecords, batch data records.
Example:
::
data_record_1 = ({"input_1": 1, "input_2": 2}, {"output_1": 3})
data_record_2 = ({"input_1": 2, "input_2": 4}, {"output_1": 6})
batch_data_records = (
{"input_1": arr([1, 2], "input_2": arr([2, 4])},
{"output_1": arr([3, 6])}
)
"""
batch_data_records = tuple(
cytoolz.merge_with(np.array, ii) for ii in zip(*data_records)
)
return batch_data_records # type: ignore