Skip to content

Commit fe9a545

Browse files
committed
Updated util.cc
1 parent 0d36503 commit fe9a545

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎tensorflow/python/util/util.cc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ int IsInstanceOfRegisteredType(PyObject* obj, const char* type_name) {
213213
// Returns 1 if `o` is considered a mapping for the purposes of Flatten().
214214
// Returns 0 otherwise.
215215
// Returns -1 if an error occurred.
216+
int IsMappingHelper(PyObject* o) {
217+
static auto* const check_cache = new CachedTypeCheck([](PyObject* to_check) {
218+
return IsInstanceOfRegisteredType(to_check, "Mapping");
219+
});
220+
if (PyDict_Check(o)) return true;
221+
return check_cache->CachedLookup(o);
222+
}
223+
216224
int IsNestCompatibleMappingHelper(PyObject* o) {
217225
static auto* const check_cache = new CachedTypeCheck([](PyObject* to_check) {
218226
return IsInstanceOfRegisteredType(to_check, "MutableMapping");

0 commit comments

Comments
 (0)