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

Method __init__

tensorflow/python/framework/sparse_tensor.py:115–143  ·  view source on GitHub ↗

Creates a `SparseTensor`. Args: indices: A 2-D int64 tensor of shape `[N, ndims]`. values: A 1-D tensor of any type and shape `[N]`. dense_shape: A 1-D int64 tensor of shape `[ndims]`.

(self, indices, values, dense_shape)

Source from the content-addressed store, hash-verified

113 dense_shape=sparse_tensor_value.dense_shape)
114
115 def __init__(self, indices, values, dense_shape):
116 """Creates a `SparseTensor`.
117
118 Args:
119 indices: A 2-D int64 tensor of shape `[N, ndims]`.
120 values: A 1-D tensor of any type and shape `[N]`.
121 dense_shape: A 1-D int64 tensor of shape `[ndims]`.
122 """
123 with ops.name_scope(None, "SparseTensor", [indices, values, dense_shape]):
124 indices = ops.convert_to_tensor(
125 indices, name="indices", dtype=dtypes.int64)
126 # TODO(touts): Consider adding mutable_values() when 'values'
127 # is a VariableOp and updating users of SparseTensor.
128 values = ops.internal_convert_to_tensor(values, name="values")
129 dense_shape = ops.convert_to_tensor(
130 dense_shape, name="dense_shape", dtype=dtypes.int64)
131 self._indices = indices
132 self._values = values
133 self._dense_shape = dense_shape
134
135 indices_shape = indices.shape.with_rank(2)
136 values_shape = values.shape.with_rank(1)
137 dense_shape_shape = dense_shape.shape.with_rank(1)
138
139 # Assert number of rows in indices match the number of elements in values.
140 indices_shape.dims[0].merge_with(values_shape.dims[0])
141 # Assert number of columns in indices matches the number of elements in
142 # dense_shape.
143 indices_shape.dims[1].merge_with(dense_shape_shape.dims[0])
144
145 def get_shape(self):
146 """Get the `TensorShape` representing the shape of the dense tensor.

Callers

nothing calls this directly

Calls 3

with_rankMethod · 0.80
name_scopeMethod · 0.45
merge_withMethod · 0.45

Tested by

no test coverage detected