forked from mindspore-Ecosystem/mindspore
!31124 Split test cases of bfgs method.
Merge pull request !31124 from hezhenhao1/fix_scipy
This commit is contained in:
commit
e14d0ca36b
|
@ -54,11 +54,114 @@ def matyas(np):
|
|||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('dtype', [onp.float32, onp.float64])
|
||||
@pytest.mark.parametrize('func_x0', [(rosenbrock, onp.zeros(2)),
|
||||
(himmelblau, onp.zeros(2)),
|
||||
(matyas, onp.ones(2))])
|
||||
def test_bfgs(dtype, func_x0):
|
||||
@pytest.mark.parametrize('dtype', [onp.float32])
|
||||
@pytest.mark.parametrize('func_x0', [(rosenbrock, onp.zeros(2))])
|
||||
def test_bfgs1(dtype, func_x0):
|
||||
"""
|
||||
Feature: ALL TO ALL
|
||||
Description: test cases for bfgs in PYNATIVE mode
|
||||
Expectation: the result match scipy
|
||||
"""
|
||||
func, x0 = func_x0
|
||||
x0 = x0.astype(dtype)
|
||||
x0_tensor = Tensor(x0)
|
||||
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
|
||||
options=dict(maxiter=None, gtol=1e-6))
|
||||
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
|
||||
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('dtype', [onp.float32])
|
||||
@pytest.mark.parametrize('func_x0', [(himmelblau, onp.zeros(2))])
|
||||
def test_bfgs2(dtype, func_x0):
|
||||
"""
|
||||
Feature: ALL TO ALL
|
||||
Description: test cases for bfgs in PYNATIVE mode
|
||||
Expectation: the result match scipy
|
||||
"""
|
||||
func, x0 = func_x0
|
||||
x0 = x0.astype(dtype)
|
||||
x0_tensor = Tensor(x0)
|
||||
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
|
||||
options=dict(maxiter=None, gtol=1e-6))
|
||||
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
|
||||
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('dtype', [onp.float32])
|
||||
@pytest.mark.parametrize('func_x0', [(matyas, onp.ones(2))])
|
||||
def test_bfgs3(dtype, func_x0):
|
||||
"""
|
||||
Feature: ALL TO ALL
|
||||
Description: test cases for bfgs in PYNATIVE mode
|
||||
Expectation: the result match scipy
|
||||
"""
|
||||
func, x0 = func_x0
|
||||
x0 = x0.astype(dtype)
|
||||
x0_tensor = Tensor(x0)
|
||||
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
|
||||
options=dict(maxiter=None, gtol=1e-6))
|
||||
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
|
||||
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('dtype', [onp.float64])
|
||||
@pytest.mark.parametrize('func_x0', [(rosenbrock, onp.zeros(2))])
|
||||
def test_bfgs4(dtype, func_x0):
|
||||
"""
|
||||
Feature: ALL TO ALL
|
||||
Description: test cases for bfgs in PYNATIVE mode
|
||||
Expectation: the result match scipy
|
||||
"""
|
||||
func, x0 = func_x0
|
||||
x0 = x0.astype(dtype)
|
||||
x0_tensor = Tensor(x0)
|
||||
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
|
||||
options=dict(maxiter=None, gtol=1e-6))
|
||||
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
|
||||
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('dtype', [onp.float64])
|
||||
@pytest.mark.parametrize('func_x0', [(himmelblau, onp.zeros(2))])
|
||||
def test_bfgs5(dtype, func_x0):
|
||||
"""
|
||||
Feature: ALL TO ALL
|
||||
Description: test cases for bfgs in PYNATIVE mode
|
||||
Expectation: the result match scipy
|
||||
"""
|
||||
func, x0 = func_x0
|
||||
x0 = x0.astype(dtype)
|
||||
x0_tensor = Tensor(x0)
|
||||
ms_res = msp.optimize.minimize(func(mnp), x0_tensor, method='BFGS',
|
||||
options=dict(maxiter=None, gtol=1e-6))
|
||||
scipy_res = osp.optimize.minimize(func(onp), x0, method='BFGS')
|
||||
match_array(ms_res.x.asnumpy(), scipy_res.x, error=5, err_msg=str(ms_res))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('dtype', [onp.float64])
|
||||
@pytest.mark.parametrize('func_x0', [(matyas, onp.ones(2))])
|
||||
def test_bfgs6(dtype, func_x0):
|
||||
"""
|
||||
Feature: ALL TO ALL
|
||||
Description: test cases for bfgs in PYNATIVE mode
|
||||
|
|
Loading…
Reference in New Issue