当前位置: 首页>>代码示例>>Python>>正文


Python sparse_ops.sparse_retain函数代码示例

本文整理汇总了Python中tensorflow.python.ops.sparse_ops.sparse_retain函数的典型用法代码示例。如果您正苦于以下问题:Python sparse_retain函数的具体用法?Python sparse_retain怎么用?Python sparse_retain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sparse_retain函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _prune_invalid_weights

def _prune_invalid_weights(sparse_ids, sparse_weights):
  """Prune invalid weights (< 0) from the input ids and weights."""
  if sparse_weights is not None:
    is_weights_valid = math_ops.greater(sparse_weights.values, 0)
    sparse_ids = sparse_ops.sparse_retain(sparse_ids, is_weights_valid)
    sparse_weights = sparse_ops.sparse_retain(sparse_weights, is_weights_valid)
  return sparse_ids, sparse_weights
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:7,代码来源:embedding_ops.py

示例2: _prune_invalid_ids

def _prune_invalid_ids(sparse_ids, sparse_weights):
    """Prune invalid IDs (< 0) from the input ids and weights."""
    is_id_valid = math_ops.greater_equal(sparse_ids.values, 0)
    if sparse_weights is not None:
        is_id_valid = math_ops.logical_and(is_id_valid, math_ops.greater(sparse_weights.values, 0))
    sparse_ids = sparse_ops.sparse_retain(sparse_ids, is_id_valid)
    if sparse_weights is not None:
        sparse_weights = sparse_ops.sparse_retain(sparse_weights, is_id_valid)
    return sparse_ids, sparse_weights
开发者ID:yuikns,项目名称:tensorflow,代码行数:9,代码来源:embedding_ops.py

示例3: sparse_boolean_mask

def sparse_boolean_mask(sparse_tensor, mask, name="sparse_boolean_mask"):
  """Boolean mask for `SparseTensor`s.

  Args:
    sparse_tensor: a `SparseTensor`.
    mask: a 1D boolean dense`Tensor` whose length is equal to the 0th dimension
      of `sparse_tensor`.
    name: optional name for this operation.
  Returns:
    A `SparseTensor` that contains row `k` of `sparse_tensor` iff `mask[k]` is
    `True`.
  """
  # TODO(jamieas): consider mask dimension > 1 for symmetry with `boolean_mask`.
  with ops.op_scope([sparse_tensor, mask], name):
    mask = ops.convert_to_tensor(mask)
    mask_rows = array_ops.where(mask)
    first_indices = array_ops.squeeze(array_ops.slice(sparse_tensor.indices,
                                                      [0, 0], [-1, 1]))

    # Identify indices corresponding to the rows identified by mask_rows.
    sparse_entry_matches = functional_ops.map_fn(
        lambda x: math_ops.equal(first_indices, x),
        mask_rows,
        dtype=dtypes.bool)
    # Combine the rows of index_matches to form a mask for the sparse indices
    # and values.
    to_retain = array_ops.reshape(
        functional_ops.foldl(math_ops.logical_or, sparse_entry_matches), [-1])

    return sparse_ops.sparse_retain(sparse_tensor, to_retain)
开发者ID:363158858,项目名称:tensorflow,代码行数:30,代码来源:boolean_mask.py

示例4: testRetainNone

  def testRetainNone(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensor_5x6()
      to_retain = np.zeros((6,), dtype=np.bool)
      sp_output = sparse_ops.sparse_retain(sp_input, to_retain)

      output = sess.run(sp_output)

      self.assertAllEqual(output.indices, np.array([]).reshape((0, 2)))
      self.assertAllEqual(output.values, [])
      self.assertAllEqual(output.shape, [5, 6])
开发者ID:govindap,项目名称:tensorflow,代码行数:11,代码来源:sparse_ops_test.py

示例5: testBasic

  def testBasic(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensor_5x6()
      to_retain = np.array([1, 0, 0, 1, 1, 0], dtype=np.bool)
      sp_output = sparse_ops.sparse_retain(sp_input, to_retain)

      output = sess.run(sp_output)

      self.assertAllEqual(output.indices, [[0, 0], [1, 4], [3, 2]])
      self.assertAllEqual(output.values, [0, 14, 32])
      self.assertAllEqual(output.shape, [5, 6])
开发者ID:govindap,项目名称:tensorflow,代码行数:11,代码来源:sparse_ops_test.py

示例6: testRetainNone

  def testRetainNone(self):
    with test_util.force_cpu():
      sp_input = self._SparseTensor_5x6()
      to_retain = np.zeros((6,), dtype=np.bool)
      sp_output = sparse_ops.sparse_retain(sp_input, to_retain)

      output = self.evaluate(sp_output)

      self.assertAllEqual(output.indices, np.array([]).reshape((0, 2)))
      self.assertAllEqual(output.values, [])
      self.assertAllEqual(output.dense_shape, [5, 6])
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:11,代码来源:sparse_ops_test.py

示例7: testBasic

  def testBasic(self):
    with test_util.force_cpu():
      for sp_input in (self._SparseTensorValue_5x6(), self._SparseTensor_5x6()):
        to_retain = np.array([1, 0, 0, 1, 1, 0], dtype=np.bool)
        sp_output = sparse_ops.sparse_retain(sp_input, to_retain)

        output = self.evaluate(sp_output)

        self.assertAllEqual(output.indices, [[0, 0], [1, 4], [3, 2]])
        self.assertAllEqual(output.values, [0, 14, 32])
        self.assertAllEqual(output.dense_shape, [5, 6])
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:11,代码来源:sparse_ops_test.py

示例8: testMismatchedRetainShape

 def testMismatchedRetainShape(self):
   with self.test_session(use_gpu=False):
     sp_input = self._SparseTensor_5x6()
     to_retain = np.array([1, 0, 0, 1, 0], dtype=np.bool)
     with self.assertRaises(ValueError):
       sparse_ops.sparse_retain(sp_input, to_retain)
开发者ID:govindap,项目名称:tensorflow,代码行数:6,代码来源:sparse_ops_test.py

示例9: testMismatchedRetainShape

 def testMismatchedRetainShape(self):
   with test_util.force_cpu():
     sp_input = self._SparseTensor_5x6()
     to_retain = np.array([1, 0, 0, 1, 0], dtype=np.bool)
     with self.assertRaises(ValueError):
       sparse_ops.sparse_retain(sp_input, to_retain)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:6,代码来源:sparse_ops_test.py


注:本文中的tensorflow.python.ops.sparse_ops.sparse_retain函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。