當前位置: 首頁>>代碼示例>>Python>>正文


Python math_ops._as_indexed_slices方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.math_ops._as_indexed_slices方法的典型用法代碼示例。如果您正苦於以下問題:Python math_ops._as_indexed_slices方法的具體用法?Python math_ops._as_indexed_slices怎麽用?Python math_ops._as_indexed_slices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.math_ops的用法示例。


在下文中一共展示了math_ops._as_indexed_slices方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _AddNextAndBackEdge

# 需要導入模塊: from tensorflow.python.ops import math_ops [as 別名]
# 或者: from tensorflow.python.ops.math_ops import _as_indexed_slices [as 別名]
def _AddNextAndBackEdge(m, v):
  """Add NextIteration and back edge from v to m."""
  if isinstance(m, ops.Tensor):
    v = ops.convert_to_tensor(v)
    v = _NextIteration(v)
    m.op._update_input(1, v)   # pylint: disable=protected-access
  elif isinstance(m, ops.IndexedSlices):
    # pylint: disable=protected-access
    v = math_ops._as_indexed_slices(v, optimize=False)
    v = _NextIteration(v)
    m.values.op._update_input(1, v.values)
    m.indices.op._update_input(1, v.indices)
    # pylint: enable=protected-access
    if m.dense_shape is not None:
      if v.dense_shape is None:
        raise ValueError("Must have dense shape: %s" % v.name)
      m.dense_shape.op._update_input(1, v.dense_shape)
  elif isinstance(m, sparse_tensor.SparseTensor):
    if not isinstance(v, sparse_tensor.SparseTensor):
      raise ValueError("Must be a sparse tensor: %s" % v.name)
    v = _NextIteration(v)
    # pylint: disable=protected-access
    m.values.op._update_input(1, v.values)
    m.indices.op._update_input(1, v.indices)
    m.dense_shape.op._update_input(1, v.dense_shape)
    # pylint: enable=protected-access
  else:
    raise TypeError("Type %s not supported" % type(m))
  return v 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:31,代碼來源:control_flow_ops.py

示例2: _AddNextAndBackEdge

# 需要導入模塊: from tensorflow.python.ops import math_ops [as 別名]
# 或者: from tensorflow.python.ops.math_ops import _as_indexed_slices [as 別名]
def _AddNextAndBackEdge(m, v):
  """Add NextIteration and back edge from v to m."""
  if isinstance(m, ops.Tensor):
    v = ops.convert_to_tensor(v)
    v = _NextIteration(v)
    m.op._update_input(1, v)   # pylint: disable=protected-access
  elif isinstance(m, ops.IndexedSlices):
    # pylint: disable=protected-access
    v = math_ops._as_indexed_slices(v, optimize=False)
    v = _NextIteration(v)
    m.values.op._update_input(1, v.values)
    m.indices.op._update_input(1, v.indices)
    # pylint: enable=protected-access
    if m.dense_shape is not None:
      if v.dense_shape is None:
        raise ValueError("Must have dense shape: %s" % v.name)
      m.dense_shape.op._update_input(1, v.dense_shape)
  elif isinstance(m, sparse_tensor.SparseTensor):
    if not isinstance(v, sparse_tensor.SparseTensor):
      raise ValueError("Must be a sparse tensor: %s" % v.name)
    v = _NextIteration(v)
    # pylint: disable=protected-access
    m.values.op._update_input(1, v.values)
    m.indices.op._update_input(1, v.indices)
    m.shape.op._update_input(1, v.shape)
    # pylint: enable=protected-access
  else:
    raise TypeError("Type %s not supported" % type(m))
  return v 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:31,代碼來源:control_flow_ops.py

示例3: testIndexedSlicesToTensor

# 需要導入模塊: from tensorflow.python.ops import math_ops [as 別名]
# 或者: from tensorflow.python.ops.math_ops import _as_indexed_slices [as 別名]
def testIndexedSlicesToTensor(self):
    with self.test_session():
      np_val = np.random.rand(4, 4, 4, 4).astype(np.float32)
      c = constant_op.constant(np_val)
      c_sparse = math_ops._as_indexed_slices(c)
      self.assertAllEqual(np_val.shape, c_sparse.dense_shape.eval())
      c_dense = math_ops.mul(c_sparse, 1.0)
      self.assertAllClose(np_val, c_dense.eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:10,代碼來源:gradients_test.py

示例4: testIndexedSlicesToTensorList

# 需要導入模塊: from tensorflow.python.ops import math_ops [as 別名]
# 或者: from tensorflow.python.ops.math_ops import _as_indexed_slices [as 別名]
def testIndexedSlicesToTensorList(self):
    with self.test_session():
      numpy_list = []
      dense_list = []
      sparse_list = []
      for _ in range(3):
        np_val = np.random.rand(4, 4, 4, 4).astype(np.float32)
        c = constant_op.constant(np_val)
        c_sparse = math_ops._as_indexed_slices(c)
        numpy_list.append(np_val)
        dense_list.append(c)
        sparse_list.append(c_sparse)
      packed_dense = array_ops.pack(dense_list)
      packed_sparse = array_ops.pack(sparse_list)
      self.assertAllClose(packed_dense.eval(), packed_sparse.eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:17,代碼來源:gradients_test.py

示例5: testInt64Indices

# 需要導入模塊: from tensorflow.python.ops import math_ops [as 別名]
# 或者: from tensorflow.python.ops.math_ops import _as_indexed_slices [as 別名]
def testInt64Indices(self):
    with self.test_session():
      np_val = np.random.rand(4, 4, 4, 4).astype(np.float32)
      c = constant_op.constant(np_val)
      c_sparse = math_ops._as_indexed_slices(c)
      c_sparse = ops.IndexedSlices(
          c_sparse.values, math_ops.cast(c_sparse.indices, dtypes.int64),
          c_sparse.dense_shape)
      self.assertAllEqual(np_val.shape, c_sparse.dense_shape.eval())
      c_dense = math_ops.mul(c_sparse, 1.0)
      self.assertAllClose(np_val, c_dense.eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:gradients_test.py


注:本文中的tensorflow.python.ops.math_ops._as_indexed_slices方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。