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

Function set_difference

tensorflow/python/ops/sets_impl.py:206–280  ·  view source on GitHub ↗

Compute set difference 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 # Represent the following array of sets as a sparse tensor: # a = np.array([[{1, 2}, {3}]

(a, b, aminusb=True, validate_indices=True)

Source from the content-addressed store, hash-verified

204@tf_export(
205 "sets.difference", v1=["sets.difference", "sets.set_difference"])
206def set_difference(a, b, aminusb=True, validate_indices=True):
207 """Compute set difference of elements in last dimension of `a` and `b`.
208
209 All but the last dimension of `a` and `b` must match.
210
211 Example:
212
213 ```python
214 import tensorflow as tf
215 import collections
216
217 # Represent the following array of sets as a sparse tensor:
218 # a = np.array([[{1, 2}, {3}], [{4}, {5, 6}]])
219 a = collections.OrderedDict([
220 ((0, 0, 0), 1),
221 ((0, 0, 1), 2),
222 ((0, 1, 0), 3),
223 ((1, 0, 0), 4),
224 ((1, 1, 0), 5),
225 ((1, 1, 1), 6),
226 ])
227 a = tf.SparseTensor(list(a.keys()), list(a.values()), dense_shape=[2, 2, 2])
228
229 # np.array([[{1, 3}, {2}], [{4, 5}, {5, 6, 7, 8}]])
230 b = collections.OrderedDict([
231 ((0, 0, 0), 1),
232 ((0, 0, 1), 3),
233 ((0, 1, 0), 2),
234 ((1, 0, 0), 4),
235 ((1, 0, 1), 5),
236 ((1, 1, 0), 5),
237 ((1, 1, 1), 6),
238 ((1, 1, 2), 7),
239 ((1, 1, 3), 8),
240 ])
241 b = tf.SparseTensor(list(b.keys()), list(b.values()), dense_shape=[2, 2, 4])
242
243 # `set_difference` is applied to each aligned pair of sets.
244 tf.sets.difference(a, b)
245
246 # The result will be equivalent to either of:
247 #
248 # np.array([[{2}, {3}], [{}, {}]])
249 #
250 # collections.OrderedDict([
251 # ((0, 0, 0), 2),
252 # ((0, 1, 0), 3),
253 # ])
254 ```
255
256 Args:
257 a: `Tensor` or `SparseTensor` of the same type as `b`. If sparse, indices
258 must be sorted in row-major order.
259 b: `Tensor` or `SparseTensor` of the same type as `a`. If sparse, indices
260 must be sorted in row-major order.
261 aminusb: Whether to subtract `b` from `a`, vs vice versa.
262 validate_indices: Whether to validate the order and range of sparse indices
263 in `a` and `b`.

Callers 2

SparseTensorReduceHelperFunction · 0.85
ApplySetOperationMethod · 0.85

Calls 2

_set_operationFunction · 0.85

Tested by

no test coverage detected