forked from mindspore-Ecosystem/mindspore
32 lines
805 B
Python
32 lines
805 B
Python
import numpy as np
|
|
import pytest
|
|
import mindspore.common.dtype as mstype
|
|
import mindspore.nn as nn
|
|
from mindspore import Tensor
|
|
from mindspore import context
|
|
|
|
|
|
class Net(nn.Cell):
|
|
def construct(self, x):
|
|
return x.det()
|
|
|
|
|
|
@pytest.mark.level0
|
|
@pytest.mark.platform_x86_cpu
|
|
@pytest.mark.platform_arm_cpu
|
|
@pytest.mark.platform_x86_gpu_training
|
|
@pytest.mark.env_onecard
|
|
@pytest.mark.parametrize('mode', [context.GRAPH_MODE, context.PYNATIVE_MODE])
|
|
def test_det(mode):
|
|
"""
|
|
Feature: tensor.det()
|
|
Description: Verify the result of tensor.det()
|
|
Expectation: success
|
|
"""
|
|
context.set_context(mode=mode)
|
|
net = Net()
|
|
x = Tensor([[1.5, 2.0], [3, 4.6]], dtype=mstype.float32)
|
|
output = net(x)
|
|
expected = np.array(0.9)
|
|
assert np.allclose(output.asnumpy(), expected)
|