support arange in functional.py

pull/9470/head
Bairong 4 years ago
parent 73c91e05b1
commit 2eeaec7512

@ -22,6 +22,12 @@ from .primitive import Primitive
from . import operations as P from . import operations as P
from .operations import _grad_ops from .operations import _grad_ops
def arange(start, limit=None, delta=1):
from mindspore.nn import Range
return Range(start, limit, delta)()
typeof = Primitive('typeof') typeof = Primitive('typeof')
hastype = Primitive('hastype') hastype = Primitive('hastype')
cast = P.Cast() cast = P.Cast()

@ -24,6 +24,7 @@ from mindspore import Tensor
from mindspore.common import dtype as mstype from mindspore.common import dtype as mstype
from mindspore.ops import composite as C from mindspore.ops import composite as C
from mindspore.ops import operations as P from mindspore.ops import operations as P
from mindspore.ops import functional as F
from mindspore.ops import prim_attr_register, PrimitiveWithInfer from mindspore.ops import prim_attr_register, PrimitiveWithInfer
from ..ut_filter import non_graph_engine from ..ut_filter import non_graph_engine
from ....mindspore_test_framework.mindspore_test import mindspore_test from ....mindspore_test_framework.mindspore_test import mindspore_test
@ -41,6 +42,7 @@ context.set_context(mode=context.GRAPH_MODE)
grad = C.GradOperation() grad = C.GradOperation()
def test_multiply(): def test_multiply():
""" test_multiply """ """ test_multiply """
input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]])) input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]))
@ -138,6 +140,13 @@ def test_eye():
assert np.all(eye_output.asnumpy() == expect) assert np.all(eye_output.asnumpy() == expect)
def test_arange():
""" test_arange """
F.arange(10)
F.arange(1, 5)
F.arange(1, 10, 2)
class VirtualLossGrad(PrimitiveWithInfer): class VirtualLossGrad(PrimitiveWithInfer):
""" VirtualLossGrad definition """ """ VirtualLossGrad definition """

Loading…
Cancel
Save