8000 BUG: Fix data stmt handling for complex values in f2py by HaoZeke · Pull Request #23282 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix data stmt handling for complex values in f2py #23282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TST: Add test for gh-23276
  • Loading branch information
HaoZeke committed Apr 15, 2023
commit 1d02e2ba1b780524b1fb9f9a2c1af9cd4df02312
18 changes: 18 additions & 0 deletions numpy/f2py/tests/src/crackfortran/data_stmts.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
! gh-23276
module cmplxdat
implicit none
integer :: i, j
real :: x, y
real, dimension(2) :: z
complex(kind=8), target :: medium_ref_index
complex(kind=8), target :: ref_index_one, ref_index_two
complex(kind=8), dimension(2) :: my_array
real(kind=8), dimension(3) :: my_real_array = (/1.0d0, 2.0d0, 3.0d0/)

data i, j / 2, 3 /
data x, y / 1.5, 2.0 /
data z / 3.5, 7.0 /
data medium_ref_index / (1.d0, 0.d0) /
data ref_index_one, ref_index_two / (13.0d0, 21.0d0), (-30.0d0, 43.0d0) /
data my_array / (1.0d0, 2.0d0), (-3.0d0, 4.0d0) /
end module cmplxdat
33 changes: 33 additions & 0 deletions numpy/f2py/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import pytest
import numpy as np

from . import util
from numpy.f2py.crackfortran import crackfortran


class TestData(util.F2PyTest):
sources = [util.getpath("tests", "src", "crackfortran", "data_stmts.f90")]

# For gh-23276
def test_data_stmts(self):
assert self.module.cmplxdat.i == 2
assert self.module.cmplxdat.j == 3
assert self.module.cmplxdat.x == 1.5
assert self.module.cmplxdat.y == 2.0
assert self.module.cmplxdat.medium_ref_index == np.array(1.+0.j)
assert np.all(self.module.cmplxdat.z == np.array([3.5, 7.0]))
assert np.all(self.module.cmplxdat.my_array == np.array([ 1.+2.j, -3.+4.j]))
assert np.all(self.module.cmplxdat.my_real_array == np.array([ 1., 2., 3.]))
assert np.all(self.module.cmplxdat.ref_index_one == np.array([13.0 + 21.0j]))
assert np.all(self.module.cmplxdat.ref_index_two == np.array([-30.0 + 43.0j]))

def test_crackedlines(self):
mod = crackfortran(self.sources)
assert mod[0]['vars']['x']['='] == '1.5'
assert mod[0]['vars']['y']['='] == '2.0'
assert mod[0]['vars']['my_real_array']['='] == '(/1.0d0, 2.0d0, 3.0d0/)'
assert mod[0]['vars']['ref_index_one']['='] == '(13.0d0, 21.0d0)'
assert mod[0]['vars']['ref_index_two']['='] == '(-30.0d0, 43.0d0)'
# assert mod[0]['vars']['my_array']['='] == '(1.0d0, 2.0d0), (-3.0d0, 4.0d0)'
# assert mod[0]['vars']['z']['='] == '(/ 3.5, 7.0 /)'
0