From ad2d46cd6f21e278f9c289de5394c76c1d29089b Mon Sep 17 00:00:00 2001 From: panyifeng Date: Tue, 28 Jul 2020 17:12:57 +0800 Subject: [PATCH] fix sparse api doc --- mindspore/common/tensor.py | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/mindspore/common/tensor.py b/mindspore/common/tensor.py index e40fb8b23b..45ffc9fd8c 100644 --- a/mindspore/common/tensor.py +++ b/mindspore/common/tensor.py @@ -227,6 +227,8 @@ class IndexedSlices: IndexedSlices can only be used in `Cell`'s contruct method. + Pynative mode not supported at the moment. + Args: indices (Tensor): A 1-D integer Tensor of shape [D0]. values (Tensor): A Tensor of any dtype of shape [D0, D1, ..., Dn]. @@ -237,16 +239,17 @@ class IndexedSlices: IndexedSlices, composed of `indices`, `values`, `dense_shape`. Examples: - >>> # Create a IndexedSlices. - >>> indices = Tensor([1, 2]) - >>> values = Tensor([[0, 0], [1, 2]], dtype=ms.float32) - >>> dense_shape = (3, 2) - >>> indexed_slices = IndexedSlices(indices, values, dense_shape) + >>> class Net(nn.Cell): + >>> def __init__(self, dense_shape): + >>> super(Net, self).__init__() + >>> self.dense_shape = dense_shape + >>> def construct(self, indices, values): + >>> x = IndexedSlices(indices, values, self.dense_shape) + >>> return x.values(), x.indices(), x.dense_shape() >>> - >>> # Get atrr. - >>> indices = indexed_slices.indices() - >>> values = indexed_slices.values() - >>> dense_shape = indexed_slices.dense_shape() + >>> indices = Tensor([0]) + >>> values = Tensor([[1, 2]], dtype=ms.float32) + >>> Net((3, 2))(indices, values) """ def __init__(self, indices, values, dense_shape): raise NotImplementedError @@ -258,6 +261,8 @@ class SparseTensor: SparseTensor can only be used in `Cell`'s contruct method. + Pynative mode not supported at the moment. + For a tensor dense, its SparseTensor(indices, values, dense_shape) has `dense[indices[i]] = values[i]`. @@ -273,17 +278,18 @@ class SparseTensor: Returns: SparseTensor, composed of `indices`, `values`, `dense_shape`. - Examples: - >>> # Create a SparseTensor. + Examples: + >>> class Net(nn.Cell): + >>> def __init__(self, dense_shape): + >>> super(Net, self).__init__() + >>> self.dense_shape = dense_shape + >>> def construct(self, indices, values): + >>> x = SparseTensor(indices, values, self.dense_shape) + >>> return x.values(), x.indices(), x.dense_shape() + >>> >>> indices = Tensor([[0, 1], [1, 2]]) >>> values = Tensor([1, 2], dtype=ms.float32) - >>> dense_shape = (3, 4) - >>> sparse_tensor = SparseTensor(indices, values, dense_shape) - >>> - >>> # Get atrr. - >>> indices = sparse_tensor.indices() - >>> values = sparse_tensor.values() - >>> dense_shape = sparse_tensor.dense_shape() + >>> Net((3, 4))(indices, values) """ def __init__(self, indices, values, dense_shape): raise NotImplementedError