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

Function IsSequenceHelper

tensorflow/python/util/util.cc:293–313  ·  view source on GitHub ↗

Returns 1 if `o` is considered a sequence for the purposes of Flatten(). Returns 0 otherwise. Returns -1 if an error occurred.

Source from the content-addressed store, hash-verified

291// Returns 0 otherwise.
292// Returns -1 if an error occurred.
293int IsSequenceHelper(PyObject* o) {
294 // We treat dicts and other mappings as special cases of sequences.
295 if (IsMappingHelper(o)) return true;
296 if (IsMappingViewHelper(o)) return true;
297 if (IsAttrsHelper(o)) return true;
298 if (PySet_Check(o) && !WarnedThatSetIsNotSequence) {
299 LOG(WARNING) << "Sets are not currently considered sequences, "
300 "but this may change in the future, "
301 "so consider avoiding using them.";
302 WarnedThatSetIsNotSequence = true;
303 }
304 static auto* const check_cache = new CachedTypeCheck([](PyObject* to_check) {
305 int is_instance = IsInstanceOfRegisteredType(to_check, "Sequence");
306
307 // Don't cache a failed is_instance check.
308 if (is_instance == -1) return -1;
309
310 return static_cast<int>(is_instance != 0 && !IsString(to_check));
311 });
312 return check_cache->CachedLookup(o);
313}
314
315// ValueIterator interface
316class ValueIterator {

Callers 3

IsSequenceForDataHelperFunction · 0.85
IsSequenceFunction · 0.85

Calls 6

IsMappingHelperFunction · 0.85
IsMappingViewHelperFunction · 0.85
IsAttrsHelperFunction · 0.85
IsStringFunction · 0.85
CachedLookupMethod · 0.80

Tested by

no test coverage detected