diff options
author | 2018-02-10 20:48:19 -0800 | |
---|---|---|
committer | 2018-02-10 20:52:01 -0800 | |
commit | 16ca0705376b6ba8952ac262569a5f3b162d3af6 (patch) | |
tree | 064e2f8e349a417a5fac15abc1eafa872348206e | |
parent | 45fae93d626e41c17fc988b88de0e2721771d222 (diff) |
Add support for kConditional to the module group scheduler.
PiperOrigin-RevId: 185279412
-rw-r--r-- | tensorflow/compiler/xla/map_util.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/map_util.h b/tensorflow/compiler/xla/map_util.h index 0ad0b91330..8db8c6f3de 100644 --- a/tensorflow/compiler/xla/map_util.h +++ b/tensorflow/compiler/xla/map_util.h @@ -65,6 +65,25 @@ MaybeFind(const Collection& collection, return {it->second}; } +// Returns a const reference to the value associated with the given key if it +// exists, otherwise returns a const reference to the provided default value. +// +// WARNING: If a temporary object is passed as the default "value," +// this function will return a reference to that temporary object, +// which will be destroyed at the end of the statement. A common +// example: if you have a map with string values, and you pass a char* +// as the default "value," either use the returned value immediately +// or store it in a string (not string&). +template <class Collection> +const typename Collection::value_type::second_type& FindOrDefault( + const Collection& collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + auto it = collection.find(key); + if (it != collection.end()) return it->second; + return value; +} + // Inserts the key-value pair into the collection. Dies if key was already // present. template <class Collection> |