MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FlattenHelper

Function FlattenHelper

tensorflow/python/util/util.cc:591–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591bool FlattenHelper(
592 PyObject* nested, PyObject* list,
593 const std::function<int(PyObject*)>& is_sequence_helper,
594 const std::function<ValueIteratorPtr(PyObject*)>& value_iterator_getter) {
595 // if nested is not a sequence, append itself and exit
596 int is_seq = is_sequence_helper(nested);
597 if (is_seq == -1) return false;
598 if (!is_seq) {
599 return PyList_Append(list, nested) != -1;
600 }
601
602 ValueIteratorPtr iter = value_iterator_getter(nested);
603 if (!iter->valid()) return false;
604
605 for (Safe_PyObjectPtr item = iter->next(); item; item = iter->next()) {
606 if (Py_EnterRecursiveCall(" in flatten")) {
607 return false;
608 }
609 const bool success = FlattenHelper(item.get(), list, is_sequence_helper,
610 value_iterator_getter);
611 Py_LeaveRecursiveCall();
612 if (!success) {
613 return false;
614 }
615 }
616 return true;
617}
618
619// Sets error using keys of 'dict1' and 'dict2'.
620// 'dict1' and 'dict2' are assumed to be Python dictionaries.

Callers 2

FlattenFunction · 0.85
FlattenForDataFunction · 0.85

Calls 3

validMethod · 0.45
nextMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected