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

Function sparse_mask

tensorflow/python/ops/array_ops.py:1565–1604  ·  view source on GitHub ↗

Masks elements of `IndexedSlices`. Given an `IndexedSlices` instance `a`, returns another `IndexedSlices` that contains a subset of the slices of `a`. Only the slices at indices not specified in `mask_indices` are returned. This is useful when you need to extract a subset of slices in an

(a, mask_indices, name=None)

Source from the content-addressed store, hash-verified

1563@tf_export("sparse.mask", v1=["sparse.mask", "sparse_mask"])
1564@deprecation.deprecated_endpoints("sparse_mask")
1565def sparse_mask(a, mask_indices, name=None):
1566 """Masks elements of `IndexedSlices`.
1567
1568 Given an `IndexedSlices` instance `a`, returns another `IndexedSlices` that
1569 contains a subset of the slices of `a`. Only the slices at indices not
1570 specified in `mask_indices` are returned.
1571
1572 This is useful when you need to extract a subset of slices in an
1573 `IndexedSlices` object.
1574
1575 For example:
1576
1577 ```python
1578 # `a` contains slices at indices [12, 26, 37, 45] from a large tensor
1579 # with shape [1000, 10]
1580 a.indices # [12, 26, 37, 45]
1581 tf.shape(a.values) # [4, 10]
1582
1583 # `b` will be the subset of `a` slices at its second and third indices, so
1584 # we want to mask its first and last indices (which are at absolute
1585 # indices 12, 45)
1586 b = tf.sparse.mask(a, [12, 45])
1587
1588 b.indices # [26, 37]
1589 tf.shape(b.values) # [2, 10]
1590 ```
1591
1592 Args:
1593 a: An `IndexedSlices` instance.
1594 mask_indices: Indices of elements to mask.
1595 name: A name for the operation (optional).
1596
1597 Returns:
1598 The masked `IndexedSlices` instance.
1599 """
1600 with ops.name_scope(name, "sparse_mask", [a, mask_indices]) as name:
1601 indices = a.indices
1602 out_indices, to_gather = gen_array_ops.list_diff(indices, mask_indices)
1603 out_values = gather(a.values, to_gather, name=name)
1604 return ops.IndexedSlices(out_values, out_indices, a.dense_shape)
1605
1606
1607@tf_export("unique")

Callers

nothing calls this directly

Calls 2

gatherFunction · 0.70
name_scopeMethod · 0.45

Tested by

no test coverage detected