summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-01-28 18:38:16 -0700
committerGitHub <noreply@github.com>2017-01-28 18:38:16 -0700
commitaf506553cbeb7c376b5b687b78ac296f3140ecf8 (patch)
tree4d93a26edc88f19202aeb30d97b88bea3319db25 /numpy
parent42c7c31667d82157372698cb94cdd32163552738 (diff)
parent8613c8da4f8da7dbb90e866add49d5cb633fc85b (diff)
downloadnumpy-af506553cbeb7c376b5b687b78ac296f3140ecf8.tar.gz
Merge pull request #8494 from utke1/master
BUG: guard against replacing constants without '_' spec
Diffstat (limited to 'numpy')
-rwxr-xr-xnumpy/f2py/crackfortran.py3
-rw-r--r--numpy/f2py/tests/src/parameter/constant_compound.f9015
-rw-r--r--numpy/f2py/tests/src/parameter/constant_non_compound.f9023
-rw-r--r--numpy/f2py/tests/test_parameter.py20
4 files changed, 60 insertions, 1 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 2bdb21bb3..e38e8e3fe 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -2451,7 +2451,8 @@ def get_parameters(vars, global_params={}):
if not selected_kind_re.match(v):
v_ = v.split('_')
# In case there are additive parameters
- v = ''.join(v_[:-1]).lower().replace(v_[-1].lower(), '')
+ if len(v_) > 1:
+ v = ''.join(v_[:-1]).lower().replace(v_[-1].lower(), '')
# Currently this will not work for complex numbers.
# There is missing code for extracting a complex number,
diff --git a/numpy/f2py/tests/src/parameter/constant_compound.f90 b/numpy/f2py/tests/src/parameter/constant_compound.f90
new file mode 100644
index 000000000..e51f5e9b2
--- /dev/null
+++ b/numpy/f2py/tests/src/parameter/constant_compound.f90
@@ -0,0 +1,15 @@
+! Check that parameters are correct intercepted.
+! Constants with comma separations are commonly
+! used, for instance Pi = 3._dp
+subroutine foo_compound_int(x)
+ implicit none
+ integer, parameter :: ii = selected_int_kind(9)
+ integer(ii), intent(inout) :: x
+ dimension x(3)
+ integer(ii), parameter :: three = 3_ii
+ integer(ii), parameter :: two = 2_ii
+ integer(ii), parameter :: six = three * 1_ii * two
+
+ x(1) = x(1) + x(2) + x(3) * six
+ return
+end subroutine
diff --git a/numpy/f2py/tests/src/parameter/constant_non_compound.f90 b/numpy/f2py/tests/src/parameter/constant_non_compound.f90
new file mode 100644
index 000000000..62c9a5b94
--- /dev/null
+++ b/numpy/f2py/tests/src/parameter/constant_non_compound.f90
@@ -0,0 +1,23 @@
+! Check that parameters are correct intercepted.
+! Specifically that types of constants without
+! compound kind specs are correctly inferred
+! adapted Gibbs iteration code from pymc
+! for this test case
+subroutine foo_non_compound_int(x)
+ implicit none
+ integer, parameter :: ii = selected_int_kind(9)
+
+ integer(ii) maxiterates
+ parameter (maxiterates=2)
+
+ integer(ii) maxseries
+ parameter (maxseries=2)
+
+ integer(ii) wasize
+ parameter (wasize=maxiterates*maxseries)
+ integer(ii), intent(inout) :: x
+ dimension x(wasize)
+
+ x(1) = x(1) + x(2) + x(3) + x(4) * wasize
+ return
+end subroutine
diff --git a/numpy/f2py/tests/test_parameter.py b/numpy/f2py/tests/test_parameter.py
index f0168b2d5..b6891756d 100644
--- a/numpy/f2py/tests/test_parameter.py
+++ b/numpy/f2py/tests/test_parameter.py
@@ -18,6 +18,8 @@ class TestParameters(util.F2PyTest):
sources = [_path('src', 'parameter', 'constant_real.f90'),
_path('src', 'parameter', 'constant_integer.f90'),
_path('src', 'parameter', 'constant_both.f90'),
+ _path('src', 'parameter', 'constant_compound.f90'),
+ _path('src', 'parameter', 'constant_non_compound.f90'),
]
@dec.slow
@@ -43,6 +45,24 @@ class TestParameters(util.F2PyTest):
assert_equal(x, [0 + 1 + 2*3, 1, 2])
@dec.slow
+ def test_constant_compound_int(self):
+ # non-contiguous should raise error
+ x = np.arange(6, dtype=np.int32)[::2]
+ assert_raises(ValueError, self.module.foo_compound_int, x)
+
+ # check values with contiguous array
+ x = np.arange(3, dtype=np.int32)
+ self.module.foo_compound_int(x)
+ assert_equal(x, [0 + 1 + 2*6, 1, 2])
+
+ @dec.slow
+ def test_constant_non_compound_int(self):
+ # check values
+ x = np.arange(4, dtype=np.int32)
+ self.module.foo_non_compound_int(x)
+ assert_equal(x, [0 + 1 + 2 + 3*4, 1, 2, 3])
+
+ @dec.slow
def test_constant_integer_int(self):
# non-contiguous should raise error
x = np.arange(6, dtype=np.int32)[::2]