fix cell bprop

pull/4031/head
panyifeng 5 years ago
parent 76668bef16
commit 34e50e5d6e

@ -17,7 +17,7 @@
"""Resources for ast tree parse."""
import ast
import math
from mindspore import IndexedSlices, SparseTensor
from mindspore import RowTensor, SparseTensor
from mindspore.ops.composite import multitype_ops
from mindspore.ops import functional as F, composite as C
from . import standard_method as M
@ -140,6 +140,6 @@ convert_object_map = {
math.tan: NO_IMPLEMENT,
# user defined
IndexedSlices: F.make_indexed_slices,
RowTensor: F.make_row_tensor,
SparseTensor: F.make_sparse_tensor,
}

@ -120,7 +120,7 @@ void ProtoExporter::SetNodeOutputType(const TypePtr &type, const BaseShapePtr &s
type_proto->mutable_tensor_type()->mutable_shape()->add_dim()->set_size(elem);
}
}
} else if (type->isa<IndexedSlicesType>()) {
} else if (type->isa<RowTensorType>()) {
// Do Nothing
} else if (type->isa<UndeterminedType>()) {
// Do Nothing

@ -174,12 +174,11 @@ inline const PrimitivePtr kPrimVirtualDiv = std::make_shared<Primitive>("_Virtua
inline const PrimitivePtr kPrimVirtualDataset = std::make_shared<Primitive>("_VirtualDataset");
inline const PrimitivePtr kPrimAllReduce = std::make_shared<Primitive>("AllReduce");
// IndexedSlices
inline const PrimitivePtr kPrimMakeIndexedSlices = std::make_shared<Primitive>("MakeIndexedSlices");
inline const PrimitivePtr kPrimIndexedSlicesGetValues = std::make_shared<Primitive>("IndexedSlicesGetValues");
inline const PrimitivePtr kPrimIndexedSlicesGetIndices = std::make_shared<Primitive>("IndexedSlicesGetIndices");
inline const PrimitivePtr kPrimIndexedSlicesGetDenseShape = std::make_shared<Primitive>("IndexedSlicesGetDenseShape");
inline const PrimitivePtr kPrimIsIndexedSlices = std::make_shared<Primitive>("IsIndexedSlices");
// RowTensor
inline const PrimitivePtr kPrimMakeRowTensor = std::make_shared<Primitive>("MakeRowTensor");
inline const PrimitivePtr kPrimRowTensorGetValues = std::make_shared<Primitive>("RowTensorGetValues");
inline const PrimitivePtr kPrimRowTensorGetIndices = std::make_shared<Primitive>("RowTensorGetIndices");
inline const PrimitivePtr kPrimRowTensorGetDenseShape = std::make_shared<Primitive>("RowTensorGetDenseShape");
// SparseTensor
inline const PrimitivePtr kPrimMakeSparseTensor = std::make_shared<Primitive>("MakeSparseTensor");

@ -340,8 +340,8 @@ AbstractBasePtr InferImplControlDepend(const AnalysisEnginePtr &, const Primitiv
return std::make_shared<AbstractScalar>(kAnyValue, kBool);
}
AbstractBasePtr InferImplMakeIndexedSlices(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
AbstractBasePtr InferImplMakeRowTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
// Inputs: two tensors and a tuple.
const std::string op_name = primitive->name();
CheckArgsSize(op_name, args_spec_list, 3);
@ -393,41 +393,41 @@ AbstractBasePtr InferImplMakeIndexedSlices(const AnalysisEnginePtr &, const Prim
<< "th dimension of values " << values_shp[i] << ", but got " << dense_shape_vec[i];
}
}
auto ret = std::make_shared<AbstractIndexedSlices>(values->element()->BuildType(), dense_shape_vec);
auto ret = std::make_shared<AbstractRowTensor>(values->element()->BuildType(), dense_shape_vec);
ret->set_indices(indices);
ret->set_values(values);
ret->set_dense_shape(dense_shape);
return ret;
}
AbstractBasePtr InferImplIndexedSlicesGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
AbstractBasePtr InferImplRowTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
// Inputs: two tensors and a tuple.
const std::string op_name = primitive->name();
CheckArgsSize(op_name, args_spec_list, 1);
auto indexed_slices = CheckArg<AbstractIndexedSlices>(op_name, args_spec_list, 0);
MS_EXCEPTION_IF_NULL(indexed_slices->values());
return indexed_slices->values();
auto row_tensor = CheckArg<AbstractRowTensor>(op_name, args_spec_list, 0);
MS_EXCEPTION_IF_NULL(row_tensor->values());
return row_tensor->values();
}
AbstractBasePtr InferImplIndexedSlicesGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
AbstractBasePtr InferImplRowTensorGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
// Inputs: two tensors and a tuple.
const std::string op_name = primitive->name();
CheckArgsSize(op_name, args_spec_list, 1);
auto indexed_slices = CheckArg<AbstractIndexedSlices>(op_name, args_spec_list, 0);
MS_EXCEPTION_IF_NULL(indexed_slices->indices());
return indexed_slices->indices();
auto row_tensor = CheckArg<AbstractRowTensor>(op_name, args_spec_list, 0);
MS_EXCEPTION_IF_NULL(row_tensor->indices());
return row_tensor->indices();
}
AbstractBasePtr InferImplIndexedSlicesGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
AbstractBasePtr InferImplRowTensorGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
// Inputs: two tensors and a tuple.
const std::string op_name = primitive->name();
CheckArgsSize(op_name, args_spec_list, 1);
auto indexed_slices = CheckArg<AbstractIndexedSlices>(op_name, args_spec_list, 0);
MS_EXCEPTION_IF_NULL(indexed_slices->dense_shape());
return indexed_slices->dense_shape();
auto row_tensor = CheckArg<AbstractRowTensor>(op_name, args_spec_list, 0);
MS_EXCEPTION_IF_NULL(row_tensor->dense_shape());
return row_tensor->dense_shape();
}
AbstractBasePtr InferImplMakeSparseTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive,

@ -32,9 +32,9 @@ namespace opt {
using mindspore::abstract::AbstractAttribute;
using mindspore::abstract::AbstractClass;
using mindspore::abstract::AbstractDictionary;
using mindspore::abstract::AbstractIndexedSlices;
using mindspore::abstract::AbstractJTagged;
using mindspore::abstract::AbstractList;
using mindspore::abstract::AbstractRowTensor;
using mindspore::abstract::AbstractScalar;
using mindspore::abstract::AbstractSparseTensor;
using mindspore::abstract::AbstractTuple;
@ -81,10 +81,10 @@ static AbstractBasePtr AdaptAbs(const AbstractBasePtr &t) {
return std::make_shared<AbstractTuple>(abstract_list);
}
if (t->isa<AbstractIndexedSlices>()) {
auto abs_indexed_slices = dyn_cast<AbstractIndexedSlices>(t);
std::vector<AbstractBasePtr> abstract_list{abs_indexed_slices->indices(), abs_indexed_slices->values(),
abs_indexed_slices->dense_shape()};
if (t->isa<AbstractRowTensor>()) {
auto abs_row_tensor = dyn_cast<AbstractRowTensor>(t);
std::vector<AbstractBasePtr> abstract_list{abs_row_tensor->indices(), abs_row_tensor->values(),
abs_row_tensor->dense_shape()};
return std::make_shared<AbstractTuple>(abstract_list);
}
@ -455,16 +455,16 @@ bool CleanAfterOptA(const FuncGraphPtr &root, const FuncGraphManagerPtr &manager
} else if (IsValueNode<ValueList>(node)) {
new_node = ConvertValueListNodeToValueTupleNode(node->cast<ValueNodePtr>());
} else if (IsPrimitiveCNode(node, prim::kPrimMakeSparseTensor) ||
IsPrimitiveCNode(node, prim::kPrimMakeIndexedSlices)) {
IsPrimitiveCNode(node, prim::kPrimMakeRowTensor)) {
new_node = ConvertMakeSparseToMakeTuple(cnode);
} else if (IsPrimitiveCNode(node, prim::kPrimSparseTensorGetIndices) ||
IsPrimitiveCNode(node, prim::kPrimIndexedSlicesGetIndices)) {
IsPrimitiveCNode(node, prim::kPrimRowTensorGetIndices)) {
new_node = ConvertSparseGetAttrToTupleGetItem(cnode, 0);
} else if (IsPrimitiveCNode(node, prim::kPrimSparseTensorGetValues) ||
IsPrimitiveCNode(node, prim::kPrimIndexedSlicesGetValues)) {
IsPrimitiveCNode(node, prim::kPrimRowTensorGetValues)) {
new_node = ConvertSparseGetAttrToTupleGetItem(cnode, 1);
} else if (IsPrimitiveCNode(node, prim::kPrimSparseTensorGetDenseShape) ||
IsPrimitiveCNode(node, prim::kPrimIndexedSlicesGetDenseShape)) {
IsPrimitiveCNode(node, prim::kPrimRowTensorGetDenseShape)) {
new_node = ConvertSparseGetAttrToTupleGetItem(cnode, 2);
}

@ -43,7 +43,7 @@
#include "frontend/optimizer/irpass/transpose_eliminate.h"
#include "frontend/optimizer/irpass/value_based_eliminate.h"
#include "frontend/optimizer/opt.h"
#include "frontend/optimizer/irpass/indexed_slices_eliminate.h"
#include "frontend/optimizer/irpass/row_tensor_eliminate.h"
#include "frontend/optimizer/irpass/sparse_tensor_eliminate.h"
namespace mindspore {
@ -157,10 +157,10 @@ OptimizeIRPassLib::OptimizeIRPassLib() {
mark_interface_fusion_ =
MakeSubstitution(std::make_shared<MarkInterfaceFusion>(), "mark_interface_fusion", prim::kPrimSelect);
// IndexedSlices Eliminate
indexed_slices_eliminate_ = MakeSubstitution(
std::make_shared<IndexedSlicesEliminater>(), "indexed_slices_eliminate",
{prim::kPrimIndexedSlicesGetIndices, prim::kPrimIndexedSlicesGetValues, prim::kPrimIndexedSlicesGetDenseShape});
// RowTensor Eliminate
row_tensor_eliminate_ = MakeSubstitution(
std::make_shared<RowTensorEliminater>(), "row_tensor_eliminate",
{prim::kPrimRowTensorGetIndices, prim::kPrimRowTensorGetValues, prim::kPrimRowTensorGetDenseShape});
// SparseTensor Eliminate
sparse_tensor_eliminate_ = MakeSubstitution(

@ -105,8 +105,8 @@ class OptimizeIRPassLib {
// Fusion
SubstitutionPtr mark_interface_fusion_;
// IndexedSlices Eliminate
SubstitutionPtr indexed_slices_eliminate_;
// RowTensor Eliminate
SubstitutionPtr row_tensor_eliminate_;
// SparseTensor Eliminate
SubstitutionPtr sparse_tensor_eliminate_;

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_INDEXED_SLICES_ELIMINATE_H_
#define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_INDEXED_SLICES_ELIMINATE_H_
#ifndef MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_ROW_TENSOR_ELIMINATE_H_
#define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_ROW_TENSOR_ELIMINATE_H_
#include <vector>
#include <algorithm>
@ -28,24 +28,24 @@
namespace mindspore {
namespace opt {
namespace irpass {
// {prim::kPrimIndexedSlicesGetIndices, {prim::kPrimMakeIndexedSlices, Xs}}
// {prim::kPrimIndexedSlicesGetValues, {prim::kPrimMakeIndexedSlices, Xs}}
// {prim::kPrimIndexedSlicesGetDenseShape, {prim::kPrimMakeIndexedSlices, Xs}}
class IndexedSlicesEliminater : public AnfVisitor {
// {prim::kPrimRowTensorGetIndices, {prim::kPrimMakeRowTensor, Xs}}
// {prim::kPrimRowTensorGetValues, {prim::kPrimMakeRowTensor, Xs}}
// {prim::kPrimRowTensorGetDenseShape, {prim::kPrimMakeRowTensor, Xs}}
class RowTensorEliminater : public AnfVisitor {
public:
AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override {
Reset();
AnfVisitor::Match(prim::kPrimIndexedSlicesGetIndices, {IsCNode})(node);
AnfVisitor::Match(prim::kPrimRowTensorGetIndices, {IsCNode})(node);
if (is_match_) {
return tuple_->input(1);
}
AnfVisitor::Match(prim::kPrimIndexedSlicesGetValues, {IsCNode})(node);
AnfVisitor::Match(prim::kPrimRowTensorGetValues, {IsCNode})(node);
if (is_match_) {
return tuple_->input(2);
}
AnfVisitor::Match(prim::kPrimIndexedSlicesGetDenseShape, {IsCNode})(node);
AnfVisitor::Match(prim::kPrimRowTensorGetDenseShape, {IsCNode})(node);
if (is_match_) {
return tuple_->input(3);
@ -54,7 +54,7 @@ class IndexedSlicesEliminater : public AnfVisitor {
}
void Visit(const CNodePtr &cnode) override {
if (IsPrimitiveCNode(cnode, prim::kPrimMakeIndexedSlices)) {
if (IsPrimitiveCNode(cnode, prim::kPrimMakeRowTensor)) {
tuple_ = cnode;
is_match_ = true;
}
@ -72,4 +72,4 @@ class IndexedSlicesEliminater : public AnfVisitor {
} // namespace irpass
} // namespace opt
} // namespace mindspore
#endif // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_INDEXED_SLICES_ELIMINATE_H_
#endif // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_ROW_TENSOR_ELIMINATE_H_

@ -170,7 +170,7 @@ OptPassGroupMap GetOptPassesB(const opt::irpass::OptimizeIRPassLib &irpass) {
irpass.replace_refkey_by_param_,
irpass.make_ref_eliminate_,
irpass.get_ref_param_eliminate_,
irpass.indexed_slices_eliminate_,
irpass.row_tensor_eliminate_,
});
OptPassGroupMap map({
{"b_1", b_1},

File diff suppressed because it is too large Load Diff

@ -132,11 +132,11 @@ PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap() {
{prim::kPrimControlDepend, {InferImplControlDepend, true}},
// Debug
{prim::kPrimDebug, {InferImplDebug, true}},
// IndexedSlices
{prim::kPrimMakeIndexedSlices, {InferImplMakeIndexedSlices, true}},
{prim::kPrimIndexedSlicesGetValues, {InferImplIndexedSlicesGetValues, true}},
{prim::kPrimIndexedSlicesGetIndices, {InferImplIndexedSlicesGetIndices, true}},
{prim::kPrimIndexedSlicesGetDenseShape, {InferImplIndexedSlicesGetDenseShape, true}},
// RowTensor
{prim::kPrimMakeRowTensor, {InferImplMakeRowTensor, true}},
{prim::kPrimRowTensorGetValues, {InferImplRowTensorGetValues, true}},
{prim::kPrimRowTensorGetIndices, {InferImplRowTensorGetIndices, true}},
{prim::kPrimRowTensorGetDenseShape, {InferImplRowTensorGetDenseShape, true}},
// SparseTensor
{prim::kPrimMakeSparseTensor, {InferImplMakeSparseTensor, true}},
{prim::kPrimSparseTensorGetValues, {InferImplSparseTensorGetValues, true}},
@ -402,8 +402,8 @@ py::dict ConvertAbstractToPython(const AbstractBasePtr &abs_base) {
}
dic["dtype"] = arg_tensor->BuildType();
dic["value"] = BuildValue(arg_tensor->BuildValue());
} else if (abs_base->isa<AbstractIndexedSlices>()) {
auto arg = dyn_cast<AbstractIndexedSlices>(abs_base);
} else if (abs_base->isa<AbstractRowTensor>()) {
auto arg = dyn_cast<AbstractRowTensor>(abs_base);
dic["shape"] = arg->shape()->shape();
dic["dtype"] = arg->BuildType();
dic["value"] = BuildValue(arg->BuildValue());

@ -348,14 +348,14 @@ AbstractBasePtr InferImplControlDepend(const AnalysisEnginePtr &, const Primitiv
AbstractBasePtr InferImplDebug(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplMakeIndexedSlices(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplIndexedSlicesGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
AbstractBasePtr InferImplMakeRowTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplRowTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplRowTensorGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplRowTensorGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplIndexedSlicesGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplIndexedSlicesGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplMakeSparseTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplSparseTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive,

@ -32,9 +32,9 @@ using mindspore::abstract::AbstractBase;
using mindspore::abstract::AbstractClass;
using mindspore::abstract::AbstractError;
using mindspore::abstract::AbstractFunction;
using mindspore::abstract::AbstractIndexedSlices;
using mindspore::abstract::AbstractJTagged;
using mindspore::abstract::AbstractList;
using mindspore::abstract::AbstractRowTensor;
using mindspore::abstract::AbstractScalar;
using mindspore::abstract::AbstractSparseTensor;
using mindspore::abstract::AbstractTensor;
@ -95,7 +95,7 @@ void ValidateAbstract(const AnfNodePtr &node) {
}
if (ptrBase->isa<AbstractType>() || ptrBase->isa<AbstractFunction>() || ptrBase->isa<AbstractTuple>() ||
ptrBase->isa<AbstractList>() || ptrBase->isa<AbstractTensor>() || ptrBase->isa<AbstractIndexedSlices>() ||
ptrBase->isa<AbstractList>() || ptrBase->isa<AbstractTensor>() || ptrBase->isa<AbstractRowTensor>() ||
ptrBase->isa<AbstractSparseTensor>() || ptrBase->isa<abstract::AbstractRefKey>()) {
return;
}

@ -136,8 +136,7 @@ REGISTER_PYBIND_DEFINE(
TensorType data(TypeIdToType(TypeId(static_cast<int>(t[0].cast<py::int_>()))));
return data;
}));
(void)py::class_<IndexedSlicesType, Type, std::shared_ptr<IndexedSlicesType>>(m_sub, "IndexedSlicesType")
.def(py::init());
(void)py::class_<RowTensorType, Type, std::shared_ptr<RowTensorType>>(m_sub, "RowTensorType").def(py::init());
(void)py::class_<SparseTensorType, Type, std::shared_ptr<SparseTensorType>>(m_sub, "SparseTensorType")
.def(py::init());
(void)py::class_<UndeterminedType, Type, std::shared_ptr<UndeterminedType>>(m_sub, "UndeterminedType")

@ -17,10 +17,10 @@ from . import dtype
from .api import ms_function
from .dtype import *
from .parameter import Parameter, ParameterTuple
from .tensor import MetaTensor, Tensor, IndexedSlices, SparseTensor
from .tensor import MetaTensor, Tensor, RowTensor, SparseTensor
__all__ = [
"MetaTensor", "Tensor", "IndexedSlices", "SparseTensor", # tensor
"MetaTensor", "Tensor", "RowTensor", "SparseTensor", # tensor
'ms_function', # api
'Parameter', 'ParameterTuple', # parameter
"dtype"

@ -99,7 +99,7 @@ slice_type = typing.Slice
ellipsis_type = typing.TypeEllipsis
list_type = typing.List
tuple_type = typing.Tuple
index_slices = typing.IndexedSlicesType()
index_slices = typing.RowTensorType()
sparse_tensor = typing.SparseTensorType()
undetermined = typing.UndeterminedType()

@ -21,7 +21,7 @@ from .._checkparam import check_type, check_typename
from . import dtype as mstype
from ._register_for_tensor import tensor_operator_registry
__all__ = ['Tensor', 'MetaTensor', 'IndexedSlices', 'SparseTensor']
__all__ = ['Tensor', 'MetaTensor', 'RowTensor', 'SparseTensor']
np_types = (np.int8, np.int16, np.int32, np.int64,
np.uint8, np.uint16, np.uint32, np.uint64, np.float16,
np.float32, np.float64, np.bool_)
@ -267,20 +267,20 @@ class Tensor(Tensor_):
return tensor_operator_registry.get('any')(keep_dims)(self, axis)
class IndexedSlices:
class RowTensor:
"""
A sparse representation of a set of tensor slices at given indices.
An IndexedSlices is typically used to represent a subset of a larger
An RowTensor is typically used to represent a subset of a larger
tensor dense of shape [L0, D1, .. , DN] where L0 >> D0.
The values in indices are the indices in the first dimension of the slices
that have been extracted from the larger tensor.
The dense tensor dense represented by an IndexedSlices slices has
The dense tensor dense represented by an RowTensor slices has
`dense[slices.indices[i], :, :, :, ...] = slices.values[i, :, :, :, ...]`.
IndexedSlices can only be used in the `Cell`'s construct method.
RowTensor can only be used in the `Cell`'s contruct method.
It is not supported in pynative mode at the moment.
@ -291,7 +291,7 @@ class IndexedSlices:
of the corresponding dense tensor.
Returns:
IndexedSlices, composed of `indices`, `values`, and `dense_shape`.
RowTensor, composed of `indices`, `values`, and `dense_shape`.
Examples:
>>> class Net(nn.Cell):
@ -299,8 +299,8 @@ class IndexedSlices:
>>> 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()
>>> x = RowTensor(indices, values, self.dense_shape)
>>> return x.values, x.indices, x.dense_shape
>>>
>>> indices = Tensor([0])
>>> values = Tensor([[1, 2]], dtype=ms.float32)
@ -308,17 +308,20 @@ class IndexedSlices:
"""
def __init__(self, indices, values, dense_shape):
"Init IndexedSlices"
"Init RowTensor"
self.__indices = indices
self.__values = values
self.__dense_shape = dense_shape
@property
def indices(self):
return self.__indices
@property
def values(self):
return self.__values
@property
def dense_shape(self):
return self.__dense_shape
@ -353,7 +356,7 @@ class SparseTensor:
>>> 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()
>>> return x.values, x.indices, x.dense_shape
>>>
>>> indices = Tensor([[0, 1], [1, 2]])
>>> values = Tensor([1, 2], dtype=ms.float32)
@ -366,11 +369,14 @@ class SparseTensor:
self.__values = values
self.__dense_shape = dense_shape
@property
def indices(self):
return self.__indices
@property
def values(self):
return self.__values
@property
def dense_shape(self):
return self.__dense_shape

@ -1050,16 +1050,16 @@ bool AbstractBasePtrListEqual::operator()(const AbstractBasePtrList &lhs, const
return AbstractBasePtrListDeepEqual(lhs, rhs);
}
// IndexedSlices
TypePtr AbstractIndexedSlices::BuildType() const {
// RowTensor
TypePtr AbstractRowTensor::BuildType() const {
MS_EXCEPTION_IF_NULL(element());
TypePtr element_type = element()->BuildType();
return std::make_shared<IndexedSlicesType>(element_type);
return std::make_shared<RowTensorType>(element_type);
}
AbstractBasePtr AbstractIndexedSlices::Clone() const {
AbstractBasePtr AbstractRowTensor::Clone() const {
MS_EXCEPTION_IF_NULL(element());
auto clone = std::make_shared<AbstractIndexedSlices>(element()->Clone());
auto clone = std::make_shared<AbstractRowTensor>(element()->Clone());
ShapePtr shp = shape();
clone->set_shape(shp->Clone());
clone->set_value(GetValueTrack());
@ -1069,9 +1069,9 @@ AbstractBasePtr AbstractIndexedSlices::Clone() const {
return clone;
}
AbstractBasePtr AbstractIndexedSlices::Broaden() const {
AbstractBasePtr AbstractRowTensor::Broaden() const {
MS_EXCEPTION_IF_NULL(element());
auto broaden = std::make_shared<AbstractIndexedSlices>(element()->Broaden());
auto broaden = std::make_shared<AbstractRowTensor>(element()->Broaden());
auto shp = shape();
broaden->set_shape(shp->Clone());
broaden->set_value(kAnyValue);
@ -1081,9 +1081,9 @@ AbstractBasePtr AbstractIndexedSlices::Broaden() const {
return broaden;
}
AbstractBasePtr AbstractIndexedSlices::BroadenWithShape() const {
AbstractBasePtr AbstractRowTensor::BroadenWithShape() const {
MS_EXCEPTION_IF_NULL(element());
auto broaden = std::make_shared<AbstractIndexedSlices>(element()->Broaden());
auto broaden = std::make_shared<AbstractRowTensor>(element()->Broaden());
auto shp = shape()->Clone();
shp->Broaden();
broaden->set_shape(shp);
@ -1094,7 +1094,7 @@ AbstractBasePtr AbstractIndexedSlices::BroadenWithShape() const {
return broaden;
}
std::string AbstractIndexedSlices::ToString() const {
std::string AbstractRowTensor::ToString() const {
std::ostringstream buffer;
BaseShapePtr shape_track = GetShapeTrack();
MS_EXCEPTION_IF_NULL(shape_track);

@ -593,15 +593,15 @@ struct AbstractBasePtrListEqual {
std::size_t AbstractBasePtrListHash(const AbstractBasePtrList &args_spec_list);
bool AbstractBasePtrListDeepEqual(const AbstractBasePtrList &lhs, const AbstractBasePtrList &rhs);
// IndexedSlices
class AbstractIndexedSlices : public AbstractUndetermined {
// RowTensor
class AbstractRowTensor : public AbstractUndetermined {
public:
explicit AbstractIndexedSlices(const AbstractBasePtr &element, const BaseShapePtr &shape = std::make_shared<Shape>())
explicit AbstractRowTensor(const AbstractBasePtr &element, const BaseShapePtr &shape = std::make_shared<Shape>())
: AbstractUndetermined(element, shape) {}
AbstractIndexedSlices(const TypePtr &element_type, const std::vector<int> &shape)
AbstractRowTensor(const TypePtr &element_type, const std::vector<int> &shape)
: AbstractUndetermined(element_type, shape) {}
~AbstractIndexedSlices() override = default;
MS_DECLARE_PARENT(AbstractIndexedSlices, AbstractUndetermined)
~AbstractRowTensor() override = default;
MS_DECLARE_PARENT(AbstractRowTensor, AbstractUndetermined)
const AbstractTensorPtr indices() const { return indices_; }
void set_indices(const AbstractTensorPtr &indices) { indices_ = indices; }

@ -66,7 +66,7 @@ ABSTRACT_REPORT_NAME_TRAITS(Function)
ABSTRACT_REPORT_NAME_TRAITS(Type)
ABSTRACT_REPORT_NAME_TRAITS(KeywordArg)
ABSTRACT_REPORT_NAME_TRAITS(Class)
ABSTRACT_REPORT_NAME_TRAITS(IndexedSlices)
ABSTRACT_REPORT_NAME_TRAITS(RowTensor)
ABSTRACT_REPORT_NAME_TRAITS(SparseTensor)
ABSTRACT_REPORT_NAME_TRAITS(Sequeue)

@ -179,40 +179,40 @@ bool TensorType::operator==(const Type &other) const {
return *element_type_ == *other_elem_type;
}
TypePtr IndexedSlicesType::DeepCopy() const {
TypePtr RowTensorType::DeepCopy() const {
MS_EXCEPTION_IF_NULL(element_type_);
if (IsGeneric()) {
return std::make_shared<IndexedSlicesType>();
return std::make_shared<RowTensorType>();
}
return std::make_shared<IndexedSlicesType>(element_type_->DeepCopy());
return std::make_shared<RowTensorType>(element_type_->DeepCopy());
}
std::string IndexedSlicesType::ToReprString() const {
std::string RowTensorType::ToReprString() const {
if (element_type_ == nullptr) {
return "IndexedSlices";
return "RowTensor";
}
return "IndexedSlices[" + element_type_->ToReprString() + "]";
return "RowTensor[" + element_type_->ToReprString() + "]";
}
std::string IndexedSlicesType::ToString() const {
std::string RowTensorType::ToString() const {
if (element_type_ == nullptr) {
return "IndexedSlices";
return "RowTensor";
}
return "IndexedSlices[" + element_type_->ToString() + "]";
return "RowTensor[" + element_type_->ToString() + "]";
}
std::string IndexedSlicesType::DumpText() const {
std::string RowTensorType::DumpText() const {
if (element_type_ == nullptr) {
return "IndexedSlices";
return "RowTensor";
}
return "IndexedSlices[" + element_type_->DumpText() + "]";
return "RowTensor[" + element_type_->DumpText() + "]";
}
bool IndexedSlicesType::operator==(const Type &other) const {
bool RowTensorType::operator==(const Type &other) const {
if (!IsSameObjectType(*this, other)) {
return false;
}
auto other_elem_type = static_cast<const IndexedSlicesType &>(other).element_type_;
auto other_elem_type = static_cast<const RowTensorType &>(other).element_type_;
if (element_type_ == nullptr && other_elem_type == nullptr) {
return true;
} else if (element_type_ == nullptr || other_elem_type == nullptr) {

@ -154,15 +154,15 @@ class TensorType : public Object {
};
using TensorTypePtr = std::shared_ptr<TensorType>;
class IndexedSlicesType : public Object {
class RowTensorType : public Object {
public:
IndexedSlicesType() : Object(kObjectTypeIndexedSlicesType, kObjectTypeUndeterminedType) {}
explicit IndexedSlicesType(const TypePtr &ele)
: Object(kObjectTypeIndexedSlicesType, kObjectTypeUndeterminedType, false), element_type_(ele) {}
~IndexedSlicesType() override = default;
MS_DECLARE_PARENT(IndexedSlicesType, Object)
RowTensorType() : Object(kObjectTypeRowTensorType, kObjectTypeUndeterminedType) {}
explicit RowTensorType(const TypePtr &ele)
: Object(kObjectTypeRowTensorType, kObjectTypeUndeterminedType, false), element_type_(ele) {}
~RowTensorType() override = default;
MS_DECLARE_PARENT(RowTensorType, Object)
TypeId generic_type_id() const override { return kObjectTypeIndexedSlicesType; }
TypeId generic_type_id() const override { return kObjectTypeRowTensorType; }
const TypePtr element() const { return element_type_; }
void set_element(const TypePtr &element_type) { element_type_ = element_type; }
@ -175,7 +175,7 @@ class IndexedSlicesType : public Object {
private:
TypePtr element_type_;
};
using IndexedSlicesTypePtr = std::shared_ptr<IndexedSlicesType>;
using RowTensorTypePtr = std::shared_ptr<RowTensorType>;
class SparseTensorType : public Object {
public:

@ -115,8 +115,8 @@ const char *ObjectIdLabel(const TypeId &v) {
return "kObjectTypeKeyword";
case kObjectTypeTensorType:
return "kObjectTypeTensorType";
case kObjectTypeIndexedSlicesType:
return "kObjectTypeIndexedSlicesType";
case kObjectTypeRowTensorType:
return "kObjectTypeRowTensorType";
case kObjectTypeSparseTensorType:
return "kObjectTypeSparseTensorType";
case kObjectTypeUndeterminedType:

@ -50,7 +50,7 @@ enum TypeId : int {
kObjectTypeSlice,
kObjectTypeKeyword,
kObjectTypeTensorType,
kObjectTypeIndexedSlicesType,
kObjectTypeRowTensorType,
kObjectTypeSparseTensorType,
kObjectTypeUndeterminedType,
kObjectTypeClass,

@ -190,9 +190,9 @@ TypePtr TensorStrToType(const std::string &type_name) {
return type;
}
TypePtr IndexedSlicesStrToType(const std::string &type_name) {
if (type_name == "IndexedSlices") {
return std::make_shared<IndexedSlicesType>();
TypePtr RowTensorStrToType(const std::string &type_name) {
if (type_name == "RowTensor") {
return std::make_shared<RowTensorType>();
}
auto start = type_name.find_first_of('[') + 1;
auto end = type_name.find_last_of(']');
@ -204,7 +204,7 @@ TypePtr IndexedSlicesStrToType(const std::string &type_name) {
if (element_type == nullptr) {
return nullptr;
}
return std::make_shared<IndexedSlicesType>(element_type);
return std::make_shared<RowTensorType>(element_type);
}
TypePtr SparseTensorStrToType(const std::string &type_name) {
@ -364,8 +364,8 @@ TypePtr StringToType(const std::string &type_name) {
type = TensorStrToType(type_name);
} else if (type_name.compare(0, strlen("Undetermined"), "Undetermined") == 0) {
type = UndeterminedStrToType(type_name);
} else if (type_name.compare(0, strlen("IndexedSlices"), "IndexedSlices") == 0) {
type = IndexedSlicesStrToType(type_name);
} else if (type_name.compare(0, strlen("RowTensor"), "RowTensor") == 0) {
type = RowTensorStrToType(type_name);
} else if (type_name.compare(0, strlen("SparseTensor"), "SparseTensor") == 0) {
type = SparseTensorStrToType(type_name);
} else if (type_name.compare(0, strlen("List"), "List") == 0) {
@ -446,7 +446,7 @@ const TypePtr kTypeExternal = std::make_shared<External>();
const TypePtr kTypeEnv = std::make_shared<EnvType>();
const TypePtr kTypeType = std::make_shared<TypeType>();
const TypePtr kTensorType = std::make_shared<TensorType>();
const TypePtr kIndexedSlicesType = std::make_shared<IndexedSlicesType>();
const TypePtr kRowTensorType = std::make_shared<RowTensorType>();
const TypePtr kSparseTensorType = std::make_shared<SparseTensorType>();
const TypePtr kUndeterminedType = std::make_shared<UndeterminedType>();
const TypePtr kString = std::make_shared<String>();

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save