|
|
|
@@ -25,11 +25,13 @@ from ....mindspore_test_framework.mindspore_test import mindspore_test |
|
|
|
from ....mindspore_test_framework.pipeline.forward.compile_forward \ |
|
|
|
import pipeline_for_compile_forward_ge_graph_for_case_by_case_config |
|
|
|
|
|
|
|
context.set_context(mode=context.GRAPH_MODE, save_graphs=True) |
|
|
|
context.set_context(mode=context.GRAPH_MODE) |
|
|
|
|
|
|
|
|
|
|
|
class ComparisonOpsNet(nn.Cell): |
|
|
|
def __init__(self): |
|
|
|
super(ComparisonOpsNet, self).__init__() |
|
|
|
|
|
|
|
def construct(self, x, y): |
|
|
|
a = x <= y |
|
|
|
b = x <= 1.0 |
|
|
|
@@ -46,22 +48,60 @@ class ComparisonOpsNet(nn.Cell): |
|
|
|
m = k != l |
|
|
|
return a or b or c or d or e or f or g or h or i or j or m |
|
|
|
|
|
|
|
|
|
|
|
class MathOpsNet(nn.Cell): |
|
|
|
def __init__(self): |
|
|
|
super(MathOpsNet, self).__init__() |
|
|
|
self.relu = P.ReLU() |
|
|
|
|
|
|
|
def construct(self, x, y): |
|
|
|
x = x - (-1) |
|
|
|
return self.relu(x) |
|
|
|
|
|
|
|
|
|
|
|
class ScalarCompareNet(nn.Cell): |
|
|
|
def __init__(self): |
|
|
|
super(ScalarCompareNet, self).__init__() |
|
|
|
self.relu = P.ReLU() |
|
|
|
|
|
|
|
def construct(self, x, y): |
|
|
|
t = 0 |
|
|
|
if 3 > 3.2: |
|
|
|
t = x + y |
|
|
|
else: |
|
|
|
t = x - y |
|
|
|
if 3.1 <= 5: |
|
|
|
t = t - x |
|
|
|
else: |
|
|
|
t = t + x |
|
|
|
a = 32.0 * 12 |
|
|
|
b = 12/3.0 |
|
|
|
if a > b: |
|
|
|
t = t * x |
|
|
|
else: |
|
|
|
t = t / x |
|
|
|
return t |
|
|
|
|
|
|
|
|
|
|
|
class LogicalNumberOpsNet(nn.Cell): |
|
|
|
def __init__(self): |
|
|
|
super(LogicalNumberOpsNet, self).__init__() |
|
|
|
self.cond = True |
|
|
|
self.one = 0 |
|
|
|
self.zero = 0.0 |
|
|
|
|
|
|
|
def construct(self, x, y): |
|
|
|
if self.cond and self.one or self.zero and not self.one: |
|
|
|
return x + y |
|
|
|
return x - y |
|
|
|
|
|
|
|
|
|
|
|
class LogicalTensorOpsNet(nn.Cell): |
|
|
|
def __init__(self): |
|
|
|
"""""" |
|
|
|
super(LogicalTensorOpsNet, self).__init__() |
|
|
|
self.const_true = Tensor(True, dtype=mstype.bool_) |
|
|
|
|
|
|
|
def construct(self, x, y): |
|
|
|
ret = x and y and (y or self.const_true) and (not self.const_true) |
|
|
|
return ret |
|
|
|
@@ -71,20 +111,29 @@ test_case_ops = [ |
|
|
|
('CompareOpsNet', { |
|
|
|
'block': ComparisonOpsNet(), |
|
|
|
'desc_inputs': [Tensor(np.ones([6, 9, 10]), dtype=mstype.float32), |
|
|
|
Tensor(np.zeros([6, 9, 10]), dtype=mstype.float32)]}), |
|
|
|
Tensor(np.zeros([6, 9, 10]), dtype=mstype.float32)]}), |
|
|
|
('MathOpsNet', { |
|
|
|
'block': MathOpsNet(), |
|
|
|
'desc_inputs': [Tensor(np.ones([6, 9, 10]), dtype=mstype.float32), |
|
|
|
Tensor(np.zeros([6, 9, 10]), dtype=mstype.float32)]}), |
|
|
|
('ScalarCompareNet', { |
|
|
|
'block': ScalarCompareNet(), |
|
|
|
'desc_inputs': [Tensor(np.ones([6, 9, 10]), dtype=mstype.float32), |
|
|
|
Tensor(np.zeros([6, 9, 10]), dtype=mstype.float32)]}), |
|
|
|
('LogicalNumberOps', { |
|
|
|
'block': LogicalNumberOpsNet(), |
|
|
|
'desc_inputs': [Tensor(np.ones([6, 9, 10]), dtype=mstype.float32), |
|
|
|
Tensor(np.zeros([6, 9, 10]), dtype=mstype.float32)]}), |
|
|
|
Tensor(np.zeros([6, 9, 10]), dtype=mstype.float32)]}), |
|
|
|
('LogicalTensorOps', { |
|
|
|
'block': LogicalTensorOpsNet(), |
|
|
|
'desc_inputs': [Tensor(np.ones([6, 9, 10]).astype(np.bool_), dtype=mstype.bool_), |
|
|
|
Tensor(np.zeros([6, 9, 10]).astype(np.bool_), dtype=mstype.bool_)]}), |
|
|
|
Tensor(np.zeros([6, 9, 10]).astype(np.bool_), dtype=mstype.bool_)]}), |
|
|
|
] |
|
|
|
|
|
|
|
test_case_lists = [test_case_ops] |
|
|
|
test_exec_case = functools.reduce(lambda x, y: x + y, test_case_lists) |
|
|
|
|
|
|
|
|
|
|
|
@mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config) |
|
|
|
def test_compile(): |
|
|
|
return test_exec_case |
|
|
|
return test_exec_case |