|
import pytest |
|
|
|
import numpy as np |
|
|
|
from . import util |
|
|
|
|
|
class TestParameters(util.F2PyTest): |
|
|
|
sources = [ |
|
util.getpath("tests", "src", "parameter", "constant_real.f90"), |
|
util.getpath("tests", "src", "parameter", "constant_integer.f90"), |
|
util.getpath("tests", "src", "parameter", "constant_both.f90"), |
|
util.getpath("tests", "src", "parameter", "constant_compound.f90"), |
|
util.getpath("tests", "src", "parameter", "constant_non_compound.f90"), |
|
util.getpath("tests", "src", "parameter", "constant_array.f90"), |
|
] |
|
|
|
@pytest.mark.slow |
|
def test_constant_real_single(self): |
|
|
|
x = np.arange(6, dtype=np.float32)[::2] |
|
pytest.raises(ValueError, self.module.foo_single, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.float32) |
|
self.module.foo_single(x) |
|
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_real_double(self): |
|
|
|
x = np.arange(6, dtype=np.float64)[::2] |
|
pytest.raises(ValueError, self.module.foo_double, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.float64) |
|
self.module.foo_double(x) |
|
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_compound_int(self): |
|
|
|
x = np.arange(6, dtype=np.int32)[::2] |
|
pytest.raises(ValueError, self.module.foo_compound_int, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.int32) |
|
self.module.foo_compound_int(x) |
|
assert np.allclose(x, [0 + 1 + 2 * 6, 1, 2]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_non_compound_int(self): |
|
|
|
x = np.arange(4, dtype=np.int32) |
|
self.module.foo_non_compound_int(x) |
|
assert np.allclose(x, [0 + 1 + 2 + 3 * 4, 1, 2, 3]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_integer_int(self): |
|
|
|
x = np.arange(6, dtype=np.int32)[::2] |
|
pytest.raises(ValueError, self.module.foo_int, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.int32) |
|
self.module.foo_int(x) |
|
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_integer_long(self): |
|
|
|
x = np.arange(6, dtype=np.int64)[::2] |
|
pytest.raises(ValueError, self.module.foo_long, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.int64) |
|
self.module.foo_long(x) |
|
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_both(self): |
|
|
|
x = np.arange(6, dtype=np.float64)[::2] |
|
pytest.raises(ValueError, self.module.foo, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.float64) |
|
self.module.foo(x) |
|
assert np.allclose(x, [0 + 1 * 3 * 3 + 2 * 3 * 3, 1 * 3, 2 * 3]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_no(self): |
|
|
|
x = np.arange(6, dtype=np.float64)[::2] |
|
pytest.raises(ValueError, self.module.foo_no, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.float64) |
|
self.module.foo_no(x) |
|
assert np.allclose(x, [0 + 1 * 3 * 3 + 2 * 3 * 3, 1 * 3, 2 * 3]) |
|
|
|
@pytest.mark.slow |
|
def test_constant_sum(self): |
|
|
|
x = np.arange(6, dtype=np.float64)[::2] |
|
pytest.raises(ValueError, self.module.foo_sum, x) |
|
|
|
|
|
x = np.arange(3, dtype=np.float64) |
|
self.module.foo_sum(x) |
|
assert np.allclose(x, [0 + 1 * 3 * 3 + 2 * 3 * 3, 1 * 3, 2 * 3]) |
|
|
|
def test_constant_array(self): |
|
x = np.arange(3, dtype=np.float64) |
|
y = np.arange(5, dtype=np.float64) |
|
z = self.module.foo_array(x, y) |
|
assert np.allclose(x, [0.0, 1./10, 2./10]) |
|
assert np.allclose(y, [0.0, 1.*10, 2.*10, 3.*10, 4.*10]) |
|
assert np.allclose(z, 19.0) |
|
|
|
def test_constant_array_any_index(self): |
|
x = np.arange(6, dtype=np.float64) |
|
y = self.module.foo_array_any_index(x) |
|
assert np.allclose(y, x.reshape((2, 3), order='F')) |
|
|
|
def test_constant_array_delims(self): |
|
x = self.module.foo_array_delims() |
|
assert x == 9 |
|
|
|
|