forked from mindspore-Ecosystem/mindspore
sparse promote
This commit is contained in:
parent
091bdb408c
commit
7d41b51d68
|
@ -37,7 +37,7 @@ mindspore.COOTensor
|
|||
返回:
|
||||
COOTensor。
|
||||
|
||||
.. py:method:: add(other, thresh)
|
||||
.. py:method:: add(other: COOTensor, thresh: Tensor)
|
||||
|
||||
与另一个COOTensor相加,并返回新的COOTensor。
|
||||
|
||||
|
@ -63,7 +63,7 @@ mindspore.COOTensor
|
|||
- **TypeError** - 如果操作数(本COOTensor)的shape数据类型不等于other的shape数据类型。
|
||||
- **TypeError** - 如果操作数(本COOTensor/other)的values的数据类型与thresh数据类型不匹配。
|
||||
|
||||
.. py:method:: astype(dtype)
|
||||
.. py:method:: astype(dtype: mstype)
|
||||
|
||||
返回指定数据类型的COOTensor。
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ mindspore.CSRTensor
|
|||
返回:
|
||||
CSRTensor。
|
||||
|
||||
.. py:method:: add(b, alpha, beta)
|
||||
.. py:method:: add(b: CSRTensor, alpha: Tensor, beta: Tensor)
|
||||
|
||||
两个CSRTensor求和:C = alpha * a + beta * b
|
||||
|
||||
|
@ -48,7 +48,7 @@ mindspore.CSRTensor
|
|||
返回:
|
||||
CSRTensor,求和。
|
||||
|
||||
.. py:method:: astype(dtype)
|
||||
.. py:method:: astype(dtype: mstype)
|
||||
|
||||
返回指定数据类型的CSRTensor。
|
||||
|
||||
|
@ -78,7 +78,7 @@ mindspore.CSRTensor
|
|||
|
||||
返回每个非零元素所占字节数。
|
||||
|
||||
.. py:method:: mm(dense_matrix)
|
||||
.. py:method:: mm(dense_matrix: Tensor)
|
||||
|
||||
返回CSRTensor右乘稠密矩阵的矩阵乘法运算结果。
|
||||
shape为 `[M, N]` 的CSRTensor,需要适配shape为 `[N, K]` 的稠密矩阵,得到结果为 `[M, K]` 的稠密矩阵。
|
||||
|
@ -92,7 +92,7 @@ mindspore.CSRTensor
|
|||
返回:
|
||||
Tensor。
|
||||
|
||||
.. py:method:: mv(dense_vector)
|
||||
.. py:method:: mv(dense_vector: Tensor)
|
||||
|
||||
返回CSRTensor右乘稠密矩阵的矩阵乘法运算结果。
|
||||
shape为 `[M, N]` 的CSRTensor,需要适配shape为 `[N, 1]` 的稠密向量,得到结果为 `[M, 1]` 的稠密向量。
|
||||
|
@ -121,7 +121,7 @@ mindspore.CSRTensor
|
|||
|
||||
返回稀疏矩阵非零元素值数量。
|
||||
|
||||
.. py:method:: sum(axis)
|
||||
.. py:method:: sum(axis: int)
|
||||
|
||||
对CSRTensor的某个轴求和。
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mindspore.ops.csr_add
|
||||
=================================
|
||||
|
||||
.. py:function:: mindspore.ops.csr_add(a, b, alpha, beta)
|
||||
.. py:function:: mindspore.ops.csr_add(a: CSRTensor, b: CSRTensor, alpha: Tensor, beta: Tensor)
|
||||
|
||||
返回alpha * csr_a + beta * csr_b的结果,其中csr_a和csr_b是CSRTensor,alpha和beta是Tensor。
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mindspore.ops.csr_softmax
|
||||
=================================
|
||||
|
||||
.. py:function:: mindspore.ops.csr_softmax(logits, dtype)
|
||||
.. py:function:: mindspore.ops.csr_softmax(logits: CSRTensor, dtype: mstype)
|
||||
|
||||
计算 CSRTensorMatrix 的 softmax 。
|
||||
|
||||
|
@ -16,4 +16,3 @@ mindspore.ops.csr_softmax
|
|||
- **indices** - 输入中所有非零值的列位置。
|
||||
- **values** - 稠密张量的非零值。
|
||||
- **shape** - csrtensor 的形状。
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
mindspore.ops.csr_to_coo
|
||||
========================
|
||||
|
||||
.. py:function:: mindspore.ops.csr_to_coo(tensor)
|
||||
.. py:function:: mindspore.ops.csr_to_coo(tensor: CSRTensor)
|
||||
|
||||
将一个CSRTensor转化成一个COOTensor。
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mindspore.ops.dense_to_sparse_coo
|
||||
=================================
|
||||
|
||||
.. py:function:: mindspore.ops.dense_to_sparse_coo(tensor)
|
||||
.. py:function:: mindspore.ops.dense_to_sparse_coo(tensor: Tensor)
|
||||
|
||||
将常规Tensor转为稀疏化的COOTensor。
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mindspore.ops.dense_to_sparse_csr
|
||||
=================================
|
||||
|
||||
.. py:function:: mindspore.ops.dense_to_sparse_csr(tensor)
|
||||
.. py:function:: mindspore.ops.dense_to_sparse_csr(tensor: Tensor)
|
||||
|
||||
将常规Tensor转为稀疏化的CSRTensor。
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mindspore.ops.sparse_add
|
||||
================================
|
||||
|
||||
.. py:function:: mindspore.ops.sparse_add(x1, x2, thresh)
|
||||
.. py:function:: mindspore.ops.sparse_add(x1: COOTensor, x2: COOTensor, thresh: Tensor)
|
||||
|
||||
两个COOTensor相加,根据相加的结果与thresh返回新的COOTensor。
|
||||
|
||||
|
|
|
@ -605,6 +605,7 @@ def sparse_add(x1: COOTensor, x2: COOTensor, thresh: Tensor) -> COOTensor:
|
|||
dtype=Int32, value=[3 1 4 2]))
|
||||
"""
|
||||
x1, x2 = promote_coo(x1, x2)
|
||||
thresh = thresh.astype(x1.dtype)
|
||||
x1_indices = x1.indices
|
||||
x1_values = x1.values
|
||||
x2_indices = x2.indices
|
||||
|
@ -717,6 +718,8 @@ def csr_add(a: CSRTensor, b: CSRTensor, alpha: Tensor, beta: Tensor) -> CSRTenso
|
|||
raise_type_error("For functional operator csr_add, both inputs alpha and beta must be Tensor.")
|
||||
csr_add_op = SparseMatrixAdd()
|
||||
a, b = promote_csr(a, b)
|
||||
alpha = alpha.astype(a.dtype)
|
||||
beta = beta.astype(a.dtype)
|
||||
a_batch_pointers = make_tensor([0, a.values.shape[0]], a.indptr.dtype)
|
||||
b_batch_pointers = make_tensor([0, b.values.shape[0]], b.indptr.dtype)
|
||||
a_shape = make_tensor(a.shape, a.indptr.dtype)
|
||||
|
|
Loading…
Reference in New Issue