If one SparseTensor and one Tensor are passed in, returns a Tensor. If
both arguments are SparseTensors, this returns a SparseTensor. The order
of arguments does not matter. Use vanilla tf.add() for adding two dense
Tensors.
The shapes of the two operands must match: broadcasting is not supported.
The indices of any input SparseTensor are assumed ordered in standard
lexicographic order. If this is not the case, before this step run
SparseReorder to restore index ordering.
If both arguments are sparse, we perform "clipping" as follows. By default,
if two values sum to zero at some index, the output SparseTensor would still
include that particular location in its index, storing a zero in the
corresponding value slot. To override this, callers can specify thresh,
indicating that if the sum has a magnitude strictly smaller than thresh, its
corresponding value and index would then not be included. In particular,
thresh == 0.0 (default) means everything is kept and actual thresholding
happens only for a positive value.
For example, suppose the logical sum of two sparse operands is (densified):
[2][.10][6-.2]
Then,
thresh == 0 (the default): all 5 index/value pairs will be returned.
thresh == 0.11: only .1 and 0 will vanish, and the remaining three
index/value pairs will be returned.
thresh == 0.21: .1, 0, and -.2 will vanish.
Args
a
The first operand; SparseTensor or Tensor.
b
The second operand; SparseTensor or Tensor. At least one operand
must be sparse.
threshold
An optional 0-D Tensor (defaults to 0). The magnitude
threshold that determines if an output value/index pair takes space. Its
dtype should match that of the values if they are real; if the latter are
complex64/complex128, then the dtype should be float32/float64,
correspondingly.
thresh
Deprecated alias for threshold.
Returns
A SparseTensor or a Tensor, representing the sum.
Raises
TypeError
If both a and b are Tensors. Use tf.add() instead.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.sparse_add\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/sparse_ops.py#L460-L521) |\n\nAdds two tensors, at least one of each is a `SparseTensor`. (deprecated arguments)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.sparse.add`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/sparse_add)\n\n\u003cbr /\u003e\n\n tf.compat.v1.sparse_add(\n a, b, threshold=None, thresh=None\n )\n\n| **Deprecated:** SOME ARGUMENTS ARE DEPRECATED: `(thresh)`. They will be removed in a future version. Instructions for updating: thresh is deprecated, use threshold instead\n\nIf one `SparseTensor` and one `Tensor` are passed in, returns a `Tensor`. If\nboth arguments are `SparseTensor`s, this returns a `SparseTensor`. The order\nof arguments does not matter. Use vanilla [`tf.add()`](../../../tf/math/add) for adding two dense\n`Tensor`s.\n\nThe shapes of the two operands must match: broadcasting is not supported.\n\nThe indices of any input `SparseTensor` are assumed ordered in standard\nlexicographic order. If this is not the case, before this step run\n`SparseReorder` to restore index ordering.\n\nIf both arguments are sparse, we perform \"clipping\" as follows. By default,\nif two values sum to zero at some index, the output `SparseTensor` would still\ninclude that particular location in its index, storing a zero in the\ncorresponding value slot. To override this, callers can specify `thresh`,\nindicating that if the sum has a magnitude strictly smaller than `thresh`, its\ncorresponding value and index would then not be included. In particular,\n`thresh == 0.0` (default) means everything is kept and actual thresholding\nhappens only for a positive value.\n\nFor example, suppose the logical sum of two sparse operands is (densified): \n\n [ 2]\n [.1 0]\n [ 6 -.2]\n\nThen,\n\n- `thresh == 0` (the default): all 5 index/value pairs will be returned.\n- `thresh == 0.11`: only .1 and 0 will vanish, and the remaining three index/value pairs will be returned.\n- `thresh == 0.21`: .1, 0, and -.2 will vanish.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `a` | The first operand; `SparseTensor` or `Tensor`. |\n| `b` | The second operand; `SparseTensor` or `Tensor`. At least one operand must be sparse. |\n| `threshold` | An optional 0-D `Tensor` (defaults to `0`). The magnitude threshold that determines if an output value/index pair takes space. Its dtype should match that of the values if they are real; if the latter are complex64/complex128, then the dtype should be float32/float64, correspondingly. |\n| `thresh` | Deprecated alias for `threshold`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `SparseTensor` or a `Tensor`, representing the sum. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|------------------------------------------------------------------------------------|\n| `TypeError` | If both `a` and `b` are `Tensor`s. Use [`tf.add()`](../../../tf/math/add) instead. |\n\n\u003cbr /\u003e"]]