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

Function set_union

tensorflow/python/ops/sets_impl.py:285–357  ·  view source on GitHub ↗

Compute set union of elements in last dimension of `a` and `b`. All but the last dimension of `a` and `b` must match. Example: ```python import tensorflow as tf import collections # [[{1, 2}, {3}], [{4}, {5, 6}]] a = collections.OrderedDict([ ((0, 0, 0), 1),

(a, b, validate_indices=True)

Source from the content-addressed store, hash-verified

283@tf_export(
284 "sets.union", v1=["sets.union", "sets.set_union"])
285def set_union(a, b, validate_indices=True):
286 """Compute set union of elements in last dimension of `a` and `b`.
287
288 All but the last dimension of `a` and `b` must match.
289
290 Example:
291
292 ```python
293 import tensorflow as tf
294 import collections
295
296 # [[{1, 2}, {3}], [{4}, {5, 6}]]
297 a = collections.OrderedDict([
298 ((0, 0, 0), 1),
299 ((0, 0, 1), 2),
300 ((0, 1, 0), 3),
301 ((1, 0, 0), 4),
302 ((1, 1, 0), 5),
303 ((1, 1, 1), 6),
304 ])
305 a = tf.SparseTensor(list(a.keys()), list(a.values()), dense_shape=[2, 2, 2])
306
307 # [[{1, 3}, {2}], [{4, 5}, {5, 6, 7, 8}]]
308 b = collections.OrderedDict([
309 ((0, 0, 0), 1),
310 ((0, 0, 1), 3),
311 ((0, 1, 0), 2),
312 ((1, 0, 0), 4),
313 ((1, 0, 1), 5),
314 ((1, 1, 0), 5),
315 ((1, 1, 1), 6),
316 ((1, 1, 2), 7),
317 ((1, 1, 3), 8),
318 ])
319 b = tf.SparseTensor(list(b.keys()), list(b.values()), dense_shape=[2, 2, 4])
320
321 # `set_union` is applied to each aligned pair of sets.
322 tf.sets.union(a, b)
323
324 # The result will be a equivalent to either of:
325 #
326 # np.array([[{1, 2, 3}, {2, 3}], [{4, 5}, {5, 6, 7, 8}]])
327 #
328 # collections.OrderedDict([
329 # ((0, 0, 0), 1),
330 # ((0, 0, 1), 2),
331 # ((0, 0, 2), 3),
332 # ((0, 1, 0), 2),
333 # ((0, 1, 1), 3),
334 # ((1, 0, 0), 4),
335 # ((1, 0, 1), 5),
336 # ((1, 1, 0), 5),
337 # ((1, 1, 1), 6),
338 # ((1, 1, 2), 7),
339 # ((1, 1, 3), 8),
340 # ])
341 ```
342

Callers 1

ApplySetOperationMethod · 0.85

Calls 2

_set_operationFunction · 0.85

Tested by

no test coverage detected