Add files using upload-large-folder tool
Browse files- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/char.f90 +29 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/fixed_string.f90 +34 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh24662.f90 +7 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh25286.f90 +14 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh25286.pyf +12 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh25286_bc.pyf +12 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/scalar_string.f90 +9 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/string.f +12 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_abstract_interface.py +25 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_crackfortran.py +350 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_docs.py +55 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_kind.py +47 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_mixed.py +33 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_pyf_src.py +44 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_regression.py +77 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_return_integer.py +53 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_size.py +45 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_string.py +100 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/util.py +440 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_2x8gpu_50ep_lr3e3_ema0p9999_elfopt_not5_bottleneck128_unfixed_norm_stateprobadd_selfcond_ce_fast_20260609_230848.log +0 -0
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/char.f90
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MODULE char_test
|
| 2 |
+
|
| 3 |
+
CONTAINS
|
| 4 |
+
|
| 5 |
+
SUBROUTINE change_strings(strings, n_strs, out_strings)
|
| 6 |
+
IMPLICIT NONE
|
| 7 |
+
|
| 8 |
+
! Inputs
|
| 9 |
+
INTEGER, INTENT(IN) :: n_strs
|
| 10 |
+
CHARACTER, INTENT(IN), DIMENSION(2,n_strs) :: strings
|
| 11 |
+
CHARACTER, INTENT(OUT), DIMENSION(2,n_strs) :: out_strings
|
| 12 |
+
|
| 13 |
+
!f2py INTEGER, INTENT(IN) :: n_strs
|
| 14 |
+
!f2py CHARACTER, INTENT(IN), DIMENSION(2,n_strs) :: strings
|
| 15 |
+
!f2py CHARACTER, INTENT(OUT), DIMENSION(2,n_strs) :: strings
|
| 16 |
+
|
| 17 |
+
! Misc.
|
| 18 |
+
INTEGER*4 :: j
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
DO j=1, n_strs
|
| 22 |
+
out_strings(1,j) = strings(1,j)
|
| 23 |
+
out_strings(2,j) = 'A'
|
| 24 |
+
END DO
|
| 25 |
+
|
| 26 |
+
END SUBROUTINE change_strings
|
| 27 |
+
|
| 28 |
+
END MODULE char_test
|
| 29 |
+
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/fixed_string.f90
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function sint(s) result(i)
|
| 2 |
+
implicit none
|
| 3 |
+
character(len=*) :: s
|
| 4 |
+
integer :: j, i
|
| 5 |
+
i = 0
|
| 6 |
+
do j=len(s), 1, -1
|
| 7 |
+
if (.not.((i.eq.0).and.(s(j:j).eq.' '))) then
|
| 8 |
+
i = i + ichar(s(j:j)) * 10 ** (j - 1)
|
| 9 |
+
endif
|
| 10 |
+
end do
|
| 11 |
+
return
|
| 12 |
+
end function sint
|
| 13 |
+
|
| 14 |
+
function test_in_bytes4(a) result (i)
|
| 15 |
+
implicit none
|
| 16 |
+
integer :: sint
|
| 17 |
+
character(len=4) :: a
|
| 18 |
+
integer :: i
|
| 19 |
+
i = sint(a)
|
| 20 |
+
a(1:1) = 'A'
|
| 21 |
+
return
|
| 22 |
+
end function test_in_bytes4
|
| 23 |
+
|
| 24 |
+
function test_inout_bytes4(a) result (i)
|
| 25 |
+
implicit none
|
| 26 |
+
integer :: sint
|
| 27 |
+
character(len=4), intent(inout) :: a
|
| 28 |
+
integer :: i
|
| 29 |
+
if (a(1:1).ne.' ') then
|
| 30 |
+
a(1:1) = 'E'
|
| 31 |
+
endif
|
| 32 |
+
i = sint(a)
|
| 33 |
+
return
|
| 34 |
+
end function test_inout_bytes4
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh24662.f90
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
subroutine string_inout_optional(output)
|
| 2 |
+
implicit none
|
| 3 |
+
character*(32), optional, intent(inout) :: output
|
| 4 |
+
if (present(output)) then
|
| 5 |
+
output="output string"
|
| 6 |
+
endif
|
| 7 |
+
end subroutine
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh25286.f90
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
subroutine charint(trans, info)
|
| 2 |
+
character, intent(in) :: trans
|
| 3 |
+
integer, intent(out) :: info
|
| 4 |
+
if (trans == 'N') then
|
| 5 |
+
info = 1
|
| 6 |
+
else if (trans == 'T') then
|
| 7 |
+
info = 2
|
| 8 |
+
else if (trans == 'C') then
|
| 9 |
+
info = 3
|
| 10 |
+
else
|
| 11 |
+
info = -1
|
| 12 |
+
end if
|
| 13 |
+
|
| 14 |
+
end subroutine charint
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh25286.pyf
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python module _char_handling_test
|
| 2 |
+
interface
|
| 3 |
+
subroutine charint(trans, info)
|
| 4 |
+
callstatement (*f2py_func)(&trans, &info)
|
| 5 |
+
callprotoargument char*, int*
|
| 6 |
+
|
| 7 |
+
character, intent(in), check(trans=='N'||trans=='T'||trans=='C') :: trans = 'N'
|
| 8 |
+
integer intent(out) :: info
|
| 9 |
+
|
| 10 |
+
end subroutine charint
|
| 11 |
+
end interface
|
| 12 |
+
end python module _char_handling_test
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/gh25286_bc.pyf
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python module _char_handling_test
|
| 2 |
+
interface
|
| 3 |
+
subroutine charint(trans, info)
|
| 4 |
+
callstatement (*f2py_func)(&trans, &info)
|
| 5 |
+
callprotoargument char*, int*
|
| 6 |
+
|
| 7 |
+
character, intent(in), check(*trans=='N'||*trans=='T'||*trans=='C') :: trans = 'N'
|
| 8 |
+
integer intent(out) :: info
|
| 9 |
+
|
| 10 |
+
end subroutine charint
|
| 11 |
+
end interface
|
| 12 |
+
end python module _char_handling_test
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/scalar_string.f90
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MODULE string_test
|
| 2 |
+
|
| 3 |
+
character(len=8) :: string
|
| 4 |
+
character string77 * 8
|
| 5 |
+
|
| 6 |
+
character(len=12), dimension(5,7) :: strarr
|
| 7 |
+
character strarr77(5,7) * 12
|
| 8 |
+
|
| 9 |
+
END MODULE string_test
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/src/string/string.f
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
C FILE: STRING.F
|
| 2 |
+
SUBROUTINE FOO(A,B,C,D)
|
| 3 |
+
CHARACTER*5 A, B
|
| 4 |
+
CHARACTER*(*) C,D
|
| 5 |
+
Cf2py intent(in) a,c
|
| 6 |
+
Cf2py intent(inout) b,d
|
| 7 |
+
A(1:1) = 'A'
|
| 8 |
+
B(1:1) = 'B'
|
| 9 |
+
C(1:1) = 'C'
|
| 10 |
+
D(1:1) = 'D'
|
| 11 |
+
END
|
| 12 |
+
C END OF FILE STRING.F
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_abstract_interface.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import pytest
|
| 3 |
+
import textwrap
|
| 4 |
+
from . import util
|
| 5 |
+
from numpy.f2py import crackfortran
|
| 6 |
+
from numpy.testing import IS_WASM
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess")
|
| 10 |
+
class TestAbstractInterface(util.F2PyTest):
|
| 11 |
+
sources = [util.getpath("tests", "src", "abstract_interface", "foo.f90")]
|
| 12 |
+
|
| 13 |
+
skip = ["add1", "add2"]
|
| 14 |
+
|
| 15 |
+
def test_abstract_interface(self):
|
| 16 |
+
assert self.module.ops_module.foo(3, 5) == (8, 13)
|
| 17 |
+
|
| 18 |
+
def test_parse_abstract_interface(self):
|
| 19 |
+
# Test gh18403
|
| 20 |
+
fpath = util.getpath("tests", "src", "abstract_interface",
|
| 21 |
+
"gh18403_mod.f90")
|
| 22 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 23 |
+
assert len(mod) == 1
|
| 24 |
+
assert len(mod[0]["body"]) == 1
|
| 25 |
+
assert mod[0]["body"][0]["block"] == "abstract interface"
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_crackfortran.py
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import codecs
|
| 3 |
+
import time
|
| 4 |
+
import unicodedata
|
| 5 |
+
import pytest
|
| 6 |
+
import numpy as np
|
| 7 |
+
from numpy.f2py.crackfortran import markinnerspaces, nameargspattern
|
| 8 |
+
from . import util
|
| 9 |
+
from numpy.f2py import crackfortran
|
| 10 |
+
import textwrap
|
| 11 |
+
import contextlib
|
| 12 |
+
import io
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestNoSpace(util.F2PyTest):
|
| 16 |
+
# issue gh-15035: add handling for endsubroutine, endfunction with no space
|
| 17 |
+
# between "end" and the block name
|
| 18 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh15035.f")]
|
| 19 |
+
|
| 20 |
+
def test_module(self):
|
| 21 |
+
k = np.array([1, 2, 3], dtype=np.float64)
|
| 22 |
+
w = np.array([1, 2, 3], dtype=np.float64)
|
| 23 |
+
self.module.subb(k)
|
| 24 |
+
assert np.allclose(k, w + 1)
|
| 25 |
+
self.module.subc([w, k])
|
| 26 |
+
assert np.allclose(k, w + 1)
|
| 27 |
+
assert self.module.t0("23") == b"2"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class TestPublicPrivate:
|
| 31 |
+
def test_defaultPrivate(self):
|
| 32 |
+
fpath = util.getpath("tests", "src", "crackfortran", "privatemod.f90")
|
| 33 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 34 |
+
assert len(mod) == 1
|
| 35 |
+
mod = mod[0]
|
| 36 |
+
assert "private" in mod["vars"]["a"]["attrspec"]
|
| 37 |
+
assert "public" not in mod["vars"]["a"]["attrspec"]
|
| 38 |
+
assert "private" in mod["vars"]["b"]["attrspec"]
|
| 39 |
+
assert "public" not in mod["vars"]["b"]["attrspec"]
|
| 40 |
+
assert "private" not in mod["vars"]["seta"]["attrspec"]
|
| 41 |
+
assert "public" in mod["vars"]["seta"]["attrspec"]
|
| 42 |
+
|
| 43 |
+
def test_defaultPublic(self, tmp_path):
|
| 44 |
+
fpath = util.getpath("tests", "src", "crackfortran", "publicmod.f90")
|
| 45 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 46 |
+
assert len(mod) == 1
|
| 47 |
+
mod = mod[0]
|
| 48 |
+
assert "private" in mod["vars"]["a"]["attrspec"]
|
| 49 |
+
assert "public" not in mod["vars"]["a"]["attrspec"]
|
| 50 |
+
assert "private" not in mod["vars"]["seta"]["attrspec"]
|
| 51 |
+
assert "public" in mod["vars"]["seta"]["attrspec"]
|
| 52 |
+
|
| 53 |
+
def test_access_type(self, tmp_path):
|
| 54 |
+
fpath = util.getpath("tests", "src", "crackfortran", "accesstype.f90")
|
| 55 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 56 |
+
assert len(mod) == 1
|
| 57 |
+
tt = mod[0]['vars']
|
| 58 |
+
assert set(tt['a']['attrspec']) == {'private', 'bind(c)'}
|
| 59 |
+
assert set(tt['b_']['attrspec']) == {'public', 'bind(c)'}
|
| 60 |
+
assert set(tt['c']['attrspec']) == {'public'}
|
| 61 |
+
|
| 62 |
+
def test_nowrap_private_proceedures(self, tmp_path):
|
| 63 |
+
fpath = util.getpath("tests", "src", "crackfortran", "gh23879.f90")
|
| 64 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 65 |
+
assert len(mod) == 1
|
| 66 |
+
pyf = crackfortran.crack2fortran(mod)
|
| 67 |
+
assert 'bar' not in pyf
|
| 68 |
+
|
| 69 |
+
class TestModuleProcedure():
|
| 70 |
+
def test_moduleOperators(self, tmp_path):
|
| 71 |
+
fpath = util.getpath("tests", "src", "crackfortran", "operators.f90")
|
| 72 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 73 |
+
assert len(mod) == 1
|
| 74 |
+
mod = mod[0]
|
| 75 |
+
assert "body" in mod and len(mod["body"]) == 9
|
| 76 |
+
assert mod["body"][1]["name"] == "operator(.item.)"
|
| 77 |
+
assert "implementedby" in mod["body"][1]
|
| 78 |
+
assert mod["body"][1]["implementedby"] == \
|
| 79 |
+
["item_int", "item_real"]
|
| 80 |
+
assert mod["body"][2]["name"] == "operator(==)"
|
| 81 |
+
assert "implementedby" in mod["body"][2]
|
| 82 |
+
assert mod["body"][2]["implementedby"] == ["items_are_equal"]
|
| 83 |
+
assert mod["body"][3]["name"] == "assignment(=)"
|
| 84 |
+
assert "implementedby" in mod["body"][3]
|
| 85 |
+
assert mod["body"][3]["implementedby"] == \
|
| 86 |
+
["get_int", "get_real"]
|
| 87 |
+
|
| 88 |
+
def test_notPublicPrivate(self, tmp_path):
|
| 89 |
+
fpath = util.getpath("tests", "src", "crackfortran", "pubprivmod.f90")
|
| 90 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 91 |
+
assert len(mod) == 1
|
| 92 |
+
mod = mod[0]
|
| 93 |
+
assert mod['vars']['a']['attrspec'] == ['private', ]
|
| 94 |
+
assert mod['vars']['b']['attrspec'] == ['public', ]
|
| 95 |
+
assert mod['vars']['seta']['attrspec'] == ['public', ]
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class TestExternal(util.F2PyTest):
|
| 99 |
+
# issue gh-17859: add external attribute support
|
| 100 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh17859.f")]
|
| 101 |
+
|
| 102 |
+
def test_external_as_statement(self):
|
| 103 |
+
def incr(x):
|
| 104 |
+
return x + 123
|
| 105 |
+
|
| 106 |
+
r = self.module.external_as_statement(incr)
|
| 107 |
+
assert r == 123
|
| 108 |
+
|
| 109 |
+
def test_external_as_attribute(self):
|
| 110 |
+
def incr(x):
|
| 111 |
+
return x + 123
|
| 112 |
+
|
| 113 |
+
r = self.module.external_as_attribute(incr)
|
| 114 |
+
assert r == 123
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class TestCrackFortran(util.F2PyTest):
|
| 118 |
+
# gh-2848: commented lines between parameters in subroutine parameter lists
|
| 119 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh2848.f90")]
|
| 120 |
+
|
| 121 |
+
def test_gh2848(self):
|
| 122 |
+
r = self.module.gh2848(1, 2)
|
| 123 |
+
assert r == (1, 2)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
class TestMarkinnerspaces:
|
| 127 |
+
# gh-14118: markinnerspaces does not handle multiple quotations
|
| 128 |
+
|
| 129 |
+
def test_do_not_touch_normal_spaces(self):
|
| 130 |
+
test_list = ["a ", " a", "a b c", "'abcdefghij'"]
|
| 131 |
+
for i in test_list:
|
| 132 |
+
assert markinnerspaces(i) == i
|
| 133 |
+
|
| 134 |
+
def test_one_relevant_space(self):
|
| 135 |
+
assert markinnerspaces("a 'b c' \\' \\'") == "a 'b@_@c' \\' \\'"
|
| 136 |
+
assert markinnerspaces(r'a "b c" \" \"') == r'a "b@_@c" \" \"'
|
| 137 |
+
|
| 138 |
+
def test_ignore_inner_quotes(self):
|
| 139 |
+
assert markinnerspaces("a 'b c\" \" d' e") == "a 'b@_@c\"@_@\"@_@d' e"
|
| 140 |
+
assert markinnerspaces("a \"b c' ' d\" e") == "a \"b@_@c'@_@'@_@d\" e"
|
| 141 |
+
|
| 142 |
+
def test_multiple_relevant_spaces(self):
|
| 143 |
+
assert markinnerspaces("a 'b c' 'd e'") == "a 'b@_@c' 'd@_@e'"
|
| 144 |
+
assert markinnerspaces(r'a "b c" "d e"') == r'a "b@_@c" "d@_@e"'
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class TestDimSpec(util.F2PyTest):
|
| 148 |
+
"""This test suite tests various expressions that are used as dimension
|
| 149 |
+
specifications.
|
| 150 |
+
|
| 151 |
+
There exists two usage cases where analyzing dimensions
|
| 152 |
+
specifications are important.
|
| 153 |
+
|
| 154 |
+
In the first case, the size of output arrays must be defined based
|
| 155 |
+
on the inputs to a Fortran function. Because Fortran supports
|
| 156 |
+
arbitrary bases for indexing, for instance, `arr(lower:upper)`,
|
| 157 |
+
f2py has to evaluate an expression `upper - lower + 1` where
|
| 158 |
+
`lower` and `upper` are arbitrary expressions of input parameters.
|
| 159 |
+
The evaluation is performed in C, so f2py has to translate Fortran
|
| 160 |
+
expressions to valid C expressions (an alternative approach is
|
| 161 |
+
that a developer specifies the corresponding C expressions in a
|
| 162 |
+
.pyf file).
|
| 163 |
+
|
| 164 |
+
In the second case, when user provides an input array with a given
|
| 165 |
+
size but some hidden parameters used in dimensions specifications
|
| 166 |
+
need to be determined based on the input array size. This is a
|
| 167 |
+
harder problem because f2py has to solve the inverse problem: find
|
| 168 |
+
a parameter `p` such that `upper(p) - lower(p) + 1` equals to the
|
| 169 |
+
size of input array. In the case when this equation cannot be
|
| 170 |
+
solved (e.g. because the input array size is wrong), raise an
|
| 171 |
+
error before calling the Fortran function (that otherwise would
|
| 172 |
+
likely crash Python process when the size of input arrays is
|
| 173 |
+
wrong). f2py currently supports this case only when the equation
|
| 174 |
+
is linear with respect to unknown parameter.
|
| 175 |
+
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
suffix = ".f90"
|
| 179 |
+
|
| 180 |
+
code_template = textwrap.dedent("""
|
| 181 |
+
function get_arr_size_{count}(a, n) result (length)
|
| 182 |
+
integer, intent(in) :: n
|
| 183 |
+
integer, dimension({dimspec}), intent(out) :: a
|
| 184 |
+
integer length
|
| 185 |
+
length = size(a)
|
| 186 |
+
end function
|
| 187 |
+
|
| 188 |
+
subroutine get_inv_arr_size_{count}(a, n)
|
| 189 |
+
integer :: n
|
| 190 |
+
! the value of n is computed in f2py wrapper
|
| 191 |
+
!f2py intent(out) n
|
| 192 |
+
integer, dimension({dimspec}), intent(in) :: a
|
| 193 |
+
end subroutine
|
| 194 |
+
""")
|
| 195 |
+
|
| 196 |
+
linear_dimspecs = [
|
| 197 |
+
"n", "2*n", "2:n", "n/2", "5 - n/2", "3*n:20", "n*(n+1):n*(n+5)",
|
| 198 |
+
"2*n, n"
|
| 199 |
+
]
|
| 200 |
+
nonlinear_dimspecs = ["2*n:3*n*n+2*n"]
|
| 201 |
+
all_dimspecs = linear_dimspecs + nonlinear_dimspecs
|
| 202 |
+
|
| 203 |
+
code = ""
|
| 204 |
+
for count, dimspec in enumerate(all_dimspecs):
|
| 205 |
+
lst = [(d.split(":")[0] if ":" in d else "1") for d in dimspec.split(',')]
|
| 206 |
+
code += code_template.format(
|
| 207 |
+
count=count,
|
| 208 |
+
dimspec=dimspec,
|
| 209 |
+
first=", ".join(lst),
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
@pytest.mark.parametrize("dimspec", all_dimspecs)
|
| 213 |
+
def test_array_size(self, dimspec):
|
| 214 |
+
|
| 215 |
+
count = self.all_dimspecs.index(dimspec)
|
| 216 |
+
get_arr_size = getattr(self.module, f"get_arr_size_{count}")
|
| 217 |
+
|
| 218 |
+
for n in [1, 2, 3, 4, 5]:
|
| 219 |
+
sz, a = get_arr_size(n)
|
| 220 |
+
assert a.size == sz
|
| 221 |
+
|
| 222 |
+
@pytest.mark.parametrize("dimspec", all_dimspecs)
|
| 223 |
+
def test_inv_array_size(self, dimspec):
|
| 224 |
+
|
| 225 |
+
count = self.all_dimspecs.index(dimspec)
|
| 226 |
+
get_arr_size = getattr(self.module, f"get_arr_size_{count}")
|
| 227 |
+
get_inv_arr_size = getattr(self.module, f"get_inv_arr_size_{count}")
|
| 228 |
+
|
| 229 |
+
for n in [1, 2, 3, 4, 5]:
|
| 230 |
+
sz, a = get_arr_size(n)
|
| 231 |
+
if dimspec in self.nonlinear_dimspecs:
|
| 232 |
+
# one must specify n as input, the call we'll ensure
|
| 233 |
+
# that a and n are compatible:
|
| 234 |
+
n1 = get_inv_arr_size(a, n)
|
| 235 |
+
else:
|
| 236 |
+
# in case of linear dependence, n can be determined
|
| 237 |
+
# from the shape of a:
|
| 238 |
+
n1 = get_inv_arr_size(a)
|
| 239 |
+
# n1 may be different from n (for instance, when `a` size
|
| 240 |
+
# is a function of some `n` fraction) but it must produce
|
| 241 |
+
# the same sized array
|
| 242 |
+
sz1, _ = get_arr_size(n1)
|
| 243 |
+
assert sz == sz1, (n, n1, sz, sz1)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class TestModuleDeclaration:
|
| 247 |
+
def test_dependencies(self, tmp_path):
|
| 248 |
+
fpath = util.getpath("tests", "src", "crackfortran", "foo_deps.f90")
|
| 249 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 250 |
+
assert len(mod) == 1
|
| 251 |
+
assert mod[0]["vars"]["abar"]["="] == "bar('abar')"
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
class TestEval(util.F2PyTest):
|
| 255 |
+
def test_eval_scalar(self):
|
| 256 |
+
eval_scalar = crackfortran._eval_scalar
|
| 257 |
+
|
| 258 |
+
assert eval_scalar('123', {}) == '123'
|
| 259 |
+
assert eval_scalar('12 + 3', {}) == '15'
|
| 260 |
+
assert eval_scalar('a + b', dict(a=1, b=2)) == '3'
|
| 261 |
+
assert eval_scalar('"123"', {}) == "'123'"
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
class TestFortranReader(util.F2PyTest):
|
| 265 |
+
@pytest.mark.parametrize("encoding",
|
| 266 |
+
['ascii', 'utf-8', 'utf-16', 'utf-32'])
|
| 267 |
+
def test_input_encoding(self, tmp_path, encoding):
|
| 268 |
+
# gh-635
|
| 269 |
+
f_path = tmp_path / f"input_with_{encoding}_encoding.f90"
|
| 270 |
+
with f_path.open('w', encoding=encoding) as ff:
|
| 271 |
+
ff.write("""
|
| 272 |
+
subroutine foo()
|
| 273 |
+
end subroutine foo
|
| 274 |
+
""")
|
| 275 |
+
mod = crackfortran.crackfortran([str(f_path)])
|
| 276 |
+
assert mod[0]['name'] == 'foo'
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
class TestUnicodeComment(util.F2PyTest):
|
| 280 |
+
sources = [util.getpath("tests", "src", "crackfortran", "unicode_comment.f90")]
|
| 281 |
+
|
| 282 |
+
@pytest.mark.skipif(
|
| 283 |
+
(importlib.util.find_spec("charset_normalizer") is None),
|
| 284 |
+
reason="test requires charset_normalizer which is not installed",
|
| 285 |
+
)
|
| 286 |
+
def test_encoding_comment(self):
|
| 287 |
+
self.module.foo(3)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class TestNameArgsPatternBacktracking:
|
| 291 |
+
@pytest.mark.parametrize(
|
| 292 |
+
['adversary'],
|
| 293 |
+
[
|
| 294 |
+
('@)@bind@(@',),
|
| 295 |
+
('@)@bind @(@',),
|
| 296 |
+
('@)@bind foo bar baz@(@',)
|
| 297 |
+
]
|
| 298 |
+
)
|
| 299 |
+
def test_nameargspattern_backtracking(self, adversary):
|
| 300 |
+
'''address ReDOS vulnerability:
|
| 301 |
+
https://github.com/numpy/numpy/issues/23338'''
|
| 302 |
+
trials_per_batch = 12
|
| 303 |
+
batches_per_regex = 4
|
| 304 |
+
start_reps, end_reps = 15, 25
|
| 305 |
+
for ii in range(start_reps, end_reps):
|
| 306 |
+
repeated_adversary = adversary * ii
|
| 307 |
+
# test times in small batches.
|
| 308 |
+
# this gives us more chances to catch a bad regex
|
| 309 |
+
# while still catching it before too long if it is bad
|
| 310 |
+
for _ in range(batches_per_regex):
|
| 311 |
+
times = []
|
| 312 |
+
for _ in range(trials_per_batch):
|
| 313 |
+
t0 = time.perf_counter()
|
| 314 |
+
mtch = nameargspattern.search(repeated_adversary)
|
| 315 |
+
times.append(time.perf_counter() - t0)
|
| 316 |
+
# our pattern should be much faster than 0.2s per search
|
| 317 |
+
# it's unlikely that a bad regex will pass even on fast CPUs
|
| 318 |
+
assert np.median(times) < 0.2
|
| 319 |
+
assert not mtch
|
| 320 |
+
# if the adversary is capped with @)@, it becomes acceptable
|
| 321 |
+
# according to the old version of the regex.
|
| 322 |
+
# that should still be true.
|
| 323 |
+
good_version_of_adversary = repeated_adversary + '@)@'
|
| 324 |
+
assert nameargspattern.search(good_version_of_adversary)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class TestFunctionReturn(util.F2PyTest):
|
| 328 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh23598.f90")]
|
| 329 |
+
|
| 330 |
+
def test_function_rettype(self):
|
| 331 |
+
# gh-23598
|
| 332 |
+
assert self.module.intproduct(3, 4) == 12
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
class TestFortranGroupCounters(util.F2PyTest):
|
| 336 |
+
def test_end_if_comment(self):
|
| 337 |
+
# gh-23533
|
| 338 |
+
fpath = util.getpath("tests", "src", "crackfortran", "gh23533.f")
|
| 339 |
+
try:
|
| 340 |
+
crackfortran.crackfortran([str(fpath)])
|
| 341 |
+
except Exception as exc:
|
| 342 |
+
assert False, f"'crackfortran.crackfortran' raised an exception {exc}"
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class TestF77CommonBlockReader():
|
| 346 |
+
def test_gh22648(self, tmp_path):
|
| 347 |
+
fpath = util.getpath("tests", "src", "crackfortran", "gh22648.pyf")
|
| 348 |
+
with contextlib.redirect_stdout(io.StringIO()) as stdout_f2py:
|
| 349 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 350 |
+
assert "Mismatch" not in stdout_f2py.getvalue()
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_docs.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
import numpy as np
|
| 4 |
+
from numpy.testing import assert_array_equal, assert_equal
|
| 5 |
+
from . import util
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_docdir():
|
| 9 |
+
# assuming that documentation tests are run from a source
|
| 10 |
+
# directory
|
| 11 |
+
return os.path.abspath(os.path.join(
|
| 12 |
+
os.path.dirname(__file__),
|
| 13 |
+
'..', '..', '..',
|
| 14 |
+
'doc', 'source', 'f2py', 'code'))
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
pytestmark = pytest.mark.skipif(
|
| 18 |
+
not os.path.isdir(get_docdir()),
|
| 19 |
+
reason=('Could not find f2py documentation sources'
|
| 20 |
+
f' ({get_docdir()} does not exists)'))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _path(*a):
|
| 24 |
+
return os.path.join(*((get_docdir(),) + a))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class TestDocAdvanced(util.F2PyTest):
|
| 28 |
+
# options = ['--debug-capi', '--build-dir', '/tmp/build-f2py']
|
| 29 |
+
sources = [_path('asterisk1.f90'), _path('asterisk2.f90'),
|
| 30 |
+
_path('ftype.f')]
|
| 31 |
+
|
| 32 |
+
def test_asterisk1(self):
|
| 33 |
+
foo = getattr(self.module, 'foo1')
|
| 34 |
+
assert_equal(foo(), b'123456789A12')
|
| 35 |
+
|
| 36 |
+
def test_asterisk2(self):
|
| 37 |
+
foo = getattr(self.module, 'foo2')
|
| 38 |
+
assert_equal(foo(2), b'12')
|
| 39 |
+
assert_equal(foo(12), b'123456789A12')
|
| 40 |
+
assert_equal(foo(24), b'123456789A123456789B')
|
| 41 |
+
|
| 42 |
+
def test_ftype(self):
|
| 43 |
+
ftype = self.module
|
| 44 |
+
ftype.foo()
|
| 45 |
+
assert_equal(ftype.data.a, 0)
|
| 46 |
+
ftype.data.a = 3
|
| 47 |
+
ftype.data.x = [1, 2, 3]
|
| 48 |
+
assert_equal(ftype.data.a, 3)
|
| 49 |
+
assert_array_equal(ftype.data.x,
|
| 50 |
+
np.array([1, 2, 3], dtype=np.float32))
|
| 51 |
+
ftype.data.x[1] = 45
|
| 52 |
+
assert_array_equal(ftype.data.x,
|
| 53 |
+
np.array([1, 45, 3], dtype=np.float32))
|
| 54 |
+
|
| 55 |
+
# TODO: implement test methods for other example Fortran codes
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_kind.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
import platform
|
| 4 |
+
|
| 5 |
+
from numpy.f2py.crackfortran import (
|
| 6 |
+
_selected_int_kind_func as selected_int_kind,
|
| 7 |
+
_selected_real_kind_func as selected_real_kind,
|
| 8 |
+
)
|
| 9 |
+
from . import util
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TestKind(util.F2PyTest):
|
| 13 |
+
sources = [util.getpath("tests", "src", "kind", "foo.f90")]
|
| 14 |
+
|
| 15 |
+
def test_int(self):
|
| 16 |
+
"""Test `int` kind_func for integers up to 10**40."""
|
| 17 |
+
selectedintkind = self.module.selectedintkind
|
| 18 |
+
|
| 19 |
+
for i in range(40):
|
| 20 |
+
assert selectedintkind(i) == selected_int_kind(
|
| 21 |
+
i
|
| 22 |
+
), f"selectedintkind({i}): expected {selected_int_kind(i)!r} but got {selectedintkind(i)!r}"
|
| 23 |
+
|
| 24 |
+
def test_real(self):
|
| 25 |
+
"""
|
| 26 |
+
Test (processor-dependent) `real` kind_func for real numbers
|
| 27 |
+
of up to 31 digits precision (extended/quadruple).
|
| 28 |
+
"""
|
| 29 |
+
selectedrealkind = self.module.selectedrealkind
|
| 30 |
+
|
| 31 |
+
for i in range(32):
|
| 32 |
+
assert selectedrealkind(i) == selected_real_kind(
|
| 33 |
+
i
|
| 34 |
+
), f"selectedrealkind({i}): expected {selected_real_kind(i)!r} but got {selectedrealkind(i)!r}"
|
| 35 |
+
|
| 36 |
+
@pytest.mark.xfail(platform.machine().lower().startswith("ppc"),
|
| 37 |
+
reason="Some PowerPC may not support full IEEE 754 precision")
|
| 38 |
+
def test_quad_precision(self):
|
| 39 |
+
"""
|
| 40 |
+
Test kind_func for quadruple precision [`real(16)`] of 32+ digits .
|
| 41 |
+
"""
|
| 42 |
+
selectedrealkind = self.module.selectedrealkind
|
| 43 |
+
|
| 44 |
+
for i in range(32, 40):
|
| 45 |
+
assert selectedrealkind(i) == selected_real_kind(
|
| 46 |
+
i
|
| 47 |
+
), f"selectedrealkind({i}): expected {selected_real_kind(i)!r} but got {selectedrealkind(i)!r}"
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_mixed.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import textwrap
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from numpy.testing import IS_PYPY
|
| 6 |
+
from . import util
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TestMixed(util.F2PyTest):
|
| 10 |
+
sources = [
|
| 11 |
+
util.getpath("tests", "src", "mixed", "foo.f"),
|
| 12 |
+
util.getpath("tests", "src", "mixed", "foo_fixed.f90"),
|
| 13 |
+
util.getpath("tests", "src", "mixed", "foo_free.f90"),
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
def test_all(self):
|
| 17 |
+
assert self.module.bar11() == 11
|
| 18 |
+
assert self.module.foo_fixed.bar12() == 12
|
| 19 |
+
assert self.module.foo_free.bar13() == 13
|
| 20 |
+
|
| 21 |
+
@pytest.mark.xfail(IS_PYPY,
|
| 22 |
+
reason="PyPy cannot modify tp_doc after PyType_Ready")
|
| 23 |
+
def test_docstring(self):
|
| 24 |
+
expected = textwrap.dedent("""\
|
| 25 |
+
a = bar11()
|
| 26 |
+
|
| 27 |
+
Wrapper for ``bar11``.
|
| 28 |
+
|
| 29 |
+
Returns
|
| 30 |
+
-------
|
| 31 |
+
a : int
|
| 32 |
+
""")
|
| 33 |
+
assert self.module.bar11.__doc__ == expected
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_pyf_src.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This test is ported from numpy.distutils
|
| 2 |
+
from numpy.f2py._src_pyf import process_str
|
| 3 |
+
from numpy.testing import assert_equal
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
pyf_src = """
|
| 7 |
+
python module foo
|
| 8 |
+
<_rd=real,double precision>
|
| 9 |
+
interface
|
| 10 |
+
subroutine <s,d>foosub(tol)
|
| 11 |
+
<_rd>, intent(in,out) :: tol
|
| 12 |
+
end subroutine <s,d>foosub
|
| 13 |
+
end interface
|
| 14 |
+
end python module foo
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
expected_pyf = """
|
| 18 |
+
python module foo
|
| 19 |
+
interface
|
| 20 |
+
subroutine sfoosub(tol)
|
| 21 |
+
real, intent(in,out) :: tol
|
| 22 |
+
end subroutine sfoosub
|
| 23 |
+
subroutine dfoosub(tol)
|
| 24 |
+
double precision, intent(in,out) :: tol
|
| 25 |
+
end subroutine dfoosub
|
| 26 |
+
end interface
|
| 27 |
+
end python module foo
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def normalize_whitespace(s):
|
| 32 |
+
"""
|
| 33 |
+
Remove leading and trailing whitespace, and convert internal
|
| 34 |
+
stretches of whitespace to a single space.
|
| 35 |
+
"""
|
| 36 |
+
return ' '.join(s.split())
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_from_template():
|
| 40 |
+
"""Regression test for gh-10712."""
|
| 41 |
+
pyf = process_str(pyf_src)
|
| 42 |
+
normalized_pyf = normalize_whitespace(pyf)
|
| 43 |
+
normalized_expected_pyf = normalize_whitespace(expected_pyf)
|
| 44 |
+
assert_equal(normalized_pyf, normalized_expected_pyf)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_regression.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from . import util
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TestIntentInOut(util.F2PyTest):
|
| 10 |
+
# Check that intent(in out) translates as intent(inout)
|
| 11 |
+
sources = [util.getpath("tests", "src", "regression", "inout.f90")]
|
| 12 |
+
|
| 13 |
+
@pytest.mark.slow
|
| 14 |
+
def test_inout(self):
|
| 15 |
+
# non-contiguous should raise error
|
| 16 |
+
x = np.arange(6, dtype=np.float32)[::2]
|
| 17 |
+
pytest.raises(ValueError, self.module.foo, x)
|
| 18 |
+
|
| 19 |
+
# check values with contiguous array
|
| 20 |
+
x = np.arange(3, dtype=np.float32)
|
| 21 |
+
self.module.foo(x)
|
| 22 |
+
assert np.allclose(x, [3, 1, 2])
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class TestNegativeBounds(util.F2PyTest):
|
| 26 |
+
# Check that negative bounds work correctly
|
| 27 |
+
sources = [util.getpath("tests", "src", "negative_bounds", "issue_20853.f90")]
|
| 28 |
+
|
| 29 |
+
@pytest.mark.slow
|
| 30 |
+
def test_negbound(self):
|
| 31 |
+
xvec = np.arange(12)
|
| 32 |
+
xlow = -6
|
| 33 |
+
xhigh = 4
|
| 34 |
+
# Calculate the upper bound,
|
| 35 |
+
# Keeping the 1 index in mind
|
| 36 |
+
def ubound(xl, xh):
|
| 37 |
+
return xh - xl + 1
|
| 38 |
+
rval = self.module.foo(is_=xlow, ie_=xhigh,
|
| 39 |
+
arr=xvec[:ubound(xlow, xhigh)])
|
| 40 |
+
expval = np.arange(11, dtype = np.float32)
|
| 41 |
+
assert np.allclose(rval, expval)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class TestNumpyVersionAttribute(util.F2PyTest):
|
| 45 |
+
# Check that th attribute __f2py_numpy_version__ is present
|
| 46 |
+
# in the compiled module and that has the value np.__version__.
|
| 47 |
+
sources = [util.getpath("tests", "src", "regression", "inout.f90")]
|
| 48 |
+
|
| 49 |
+
@pytest.mark.slow
|
| 50 |
+
def test_numpy_version_attribute(self):
|
| 51 |
+
|
| 52 |
+
# Check that self.module has an attribute named "__f2py_numpy_version__"
|
| 53 |
+
assert hasattr(self.module, "__f2py_numpy_version__")
|
| 54 |
+
|
| 55 |
+
# Check that the attribute __f2py_numpy_version__ is a string
|
| 56 |
+
assert isinstance(self.module.__f2py_numpy_version__, str)
|
| 57 |
+
|
| 58 |
+
# Check that __f2py_numpy_version__ has the value numpy.__version__
|
| 59 |
+
assert np.__version__ == self.module.__f2py_numpy_version__
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_include_path():
|
| 63 |
+
incdir = np.f2py.get_include()
|
| 64 |
+
fnames_in_dir = os.listdir(incdir)
|
| 65 |
+
for fname in ("fortranobject.c", "fortranobject.h"):
|
| 66 |
+
assert fname in fnames_in_dir
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class TestModuleAndSubroutine(util.F2PyTest):
|
| 70 |
+
module_name = "example"
|
| 71 |
+
sources = [util.getpath("tests", "src", "regression", "gh25337", "data.f90"),
|
| 72 |
+
util.getpath("tests", "src", "regression", "gh25337", "use_data.f90")]
|
| 73 |
+
|
| 74 |
+
@pytest.mark.slow
|
| 75 |
+
def test_gh25337(self):
|
| 76 |
+
self.module.data.set_shift(3)
|
| 77 |
+
assert "data" in dir(self.module)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_return_integer.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from numpy import array
|
| 4 |
+
from . import util
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestReturnInteger(util.F2PyTest):
|
| 8 |
+
def check_function(self, t, tname):
|
| 9 |
+
assert t(123) == 123
|
| 10 |
+
assert t(123.6) == 123
|
| 11 |
+
assert t("123") == 123
|
| 12 |
+
assert t(-123) == -123
|
| 13 |
+
assert t([123]) == 123
|
| 14 |
+
assert t((123, )) == 123
|
| 15 |
+
assert t(array(123)) == 123
|
| 16 |
+
assert t(array(123, "b")) == 123
|
| 17 |
+
assert t(array(123, "h")) == 123
|
| 18 |
+
assert t(array(123, "i")) == 123
|
| 19 |
+
assert t(array(123, "l")) == 123
|
| 20 |
+
assert t(array(123, "B")) == 123
|
| 21 |
+
assert t(array(123, "f")) == 123
|
| 22 |
+
assert t(array(123, "d")) == 123
|
| 23 |
+
|
| 24 |
+
# pytest.raises(ValueError, t, array([123],'S3'))
|
| 25 |
+
pytest.raises(ValueError, t, "abc")
|
| 26 |
+
|
| 27 |
+
pytest.raises(IndexError, t, [])
|
| 28 |
+
pytest.raises(IndexError, t, ())
|
| 29 |
+
|
| 30 |
+
pytest.raises(Exception, t, t)
|
| 31 |
+
pytest.raises(Exception, t, {})
|
| 32 |
+
|
| 33 |
+
if tname in ["t8", "s8"]:
|
| 34 |
+
pytest.raises(OverflowError, t, 100000000000000000000000)
|
| 35 |
+
pytest.raises(OverflowError, t, 10000000011111111111111.23)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class TestFReturnInteger(TestReturnInteger):
|
| 39 |
+
sources = [
|
| 40 |
+
util.getpath("tests", "src", "return_integer", "foo77.f"),
|
| 41 |
+
util.getpath("tests", "src", "return_integer", "foo90.f90"),
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
@pytest.mark.parametrize("name",
|
| 45 |
+
"t0,t1,t2,t4,t8,s0,s1,s2,s4,s8".split(","))
|
| 46 |
+
def test_all_f77(self, name):
|
| 47 |
+
self.check_function(getattr(self.module, name), name)
|
| 48 |
+
|
| 49 |
+
@pytest.mark.parametrize("name",
|
| 50 |
+
"t0,t1,t2,t4,t8,s0,s1,s2,s4,s8".split(","))
|
| 51 |
+
def test_all_f90(self, name):
|
| 52 |
+
self.check_function(getattr(self.module.f90_return_integer, name),
|
| 53 |
+
name)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_size.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from . import util
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestSizeSumExample(util.F2PyTest):
|
| 9 |
+
sources = [util.getpath("tests", "src", "size", "foo.f90")]
|
| 10 |
+
|
| 11 |
+
@pytest.mark.slow
|
| 12 |
+
def test_all(self):
|
| 13 |
+
r = self.module.foo([[]])
|
| 14 |
+
assert r == [0]
|
| 15 |
+
|
| 16 |
+
r = self.module.foo([[1, 2]])
|
| 17 |
+
assert r == [3]
|
| 18 |
+
|
| 19 |
+
r = self.module.foo([[1, 2], [3, 4]])
|
| 20 |
+
assert np.allclose(r, [3, 7])
|
| 21 |
+
|
| 22 |
+
r = self.module.foo([[1, 2], [3, 4], [5, 6]])
|
| 23 |
+
assert np.allclose(r, [3, 7, 11])
|
| 24 |
+
|
| 25 |
+
@pytest.mark.slow
|
| 26 |
+
def test_transpose(self):
|
| 27 |
+
r = self.module.trans([[]])
|
| 28 |
+
assert np.allclose(r.T, np.array([[]]))
|
| 29 |
+
|
| 30 |
+
r = self.module.trans([[1, 2]])
|
| 31 |
+
assert np.allclose(r, [[1.], [2.]])
|
| 32 |
+
|
| 33 |
+
r = self.module.trans([[1, 2, 3], [4, 5, 6]])
|
| 34 |
+
assert np.allclose(r, [[1, 4], [2, 5], [3, 6]])
|
| 35 |
+
|
| 36 |
+
@pytest.mark.slow
|
| 37 |
+
def test_flatten(self):
|
| 38 |
+
r = self.module.flatten([[]])
|
| 39 |
+
assert np.allclose(r, [])
|
| 40 |
+
|
| 41 |
+
r = self.module.flatten([[1, 2]])
|
| 42 |
+
assert np.allclose(r, [1, 2])
|
| 43 |
+
|
| 44 |
+
r = self.module.flatten([[1, 2, 3], [4, 5, 6]])
|
| 45 |
+
assert np.allclose(r, [1, 2, 3, 4, 5, 6])
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/test_string.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
import textwrap
|
| 4 |
+
import numpy as np
|
| 5 |
+
from . import util
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestString(util.F2PyTest):
|
| 9 |
+
sources = [util.getpath("tests", "src", "string", "char.f90")]
|
| 10 |
+
|
| 11 |
+
@pytest.mark.slow
|
| 12 |
+
def test_char(self):
|
| 13 |
+
strings = np.array(["ab", "cd", "ef"], dtype="c").T
|
| 14 |
+
inp, out = self.module.char_test.change_strings(
|
| 15 |
+
strings, strings.shape[1])
|
| 16 |
+
assert inp == pytest.approx(strings)
|
| 17 |
+
expected = strings.copy()
|
| 18 |
+
expected[1, :] = "AAA"
|
| 19 |
+
assert out == pytest.approx(expected)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TestDocStringArguments(util.F2PyTest):
|
| 23 |
+
sources = [util.getpath("tests", "src", "string", "string.f")]
|
| 24 |
+
|
| 25 |
+
def test_example(self):
|
| 26 |
+
a = np.array(b"123\0\0")
|
| 27 |
+
b = np.array(b"123\0\0")
|
| 28 |
+
c = np.array(b"123")
|
| 29 |
+
d = np.array(b"123")
|
| 30 |
+
|
| 31 |
+
self.module.foo(a, b, c, d)
|
| 32 |
+
|
| 33 |
+
assert a.tobytes() == b"123\0\0"
|
| 34 |
+
assert b.tobytes() == b"B23\0\0"
|
| 35 |
+
assert c.tobytes() == b"123"
|
| 36 |
+
assert d.tobytes() == b"D23"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class TestFixedString(util.F2PyTest):
|
| 40 |
+
sources = [util.getpath("tests", "src", "string", "fixed_string.f90")]
|
| 41 |
+
|
| 42 |
+
@staticmethod
|
| 43 |
+
def _sint(s, start=0, end=None):
|
| 44 |
+
"""Return the content of a string buffer as integer value.
|
| 45 |
+
|
| 46 |
+
For example:
|
| 47 |
+
_sint('1234') -> 4321
|
| 48 |
+
_sint('123A') -> 17321
|
| 49 |
+
"""
|
| 50 |
+
if isinstance(s, np.ndarray):
|
| 51 |
+
s = s.tobytes()
|
| 52 |
+
elif isinstance(s, str):
|
| 53 |
+
s = s.encode()
|
| 54 |
+
assert isinstance(s, bytes)
|
| 55 |
+
if end is None:
|
| 56 |
+
end = len(s)
|
| 57 |
+
i = 0
|
| 58 |
+
for j in range(start, min(end, len(s))):
|
| 59 |
+
i += s[j] * 10**j
|
| 60 |
+
return i
|
| 61 |
+
|
| 62 |
+
def _get_input(self, intent="in"):
|
| 63 |
+
if intent in ["in"]:
|
| 64 |
+
yield ""
|
| 65 |
+
yield "1"
|
| 66 |
+
yield "1234"
|
| 67 |
+
yield "12345"
|
| 68 |
+
yield b""
|
| 69 |
+
yield b"\0"
|
| 70 |
+
yield b"1"
|
| 71 |
+
yield b"\01"
|
| 72 |
+
yield b"1\0"
|
| 73 |
+
yield b"1234"
|
| 74 |
+
yield b"12345"
|
| 75 |
+
yield np.ndarray((), np.bytes_, buffer=b"") # array(b'', dtype='|S0')
|
| 76 |
+
yield np.array(b"") # array(b'', dtype='|S1')
|
| 77 |
+
yield np.array(b"\0")
|
| 78 |
+
yield np.array(b"1")
|
| 79 |
+
yield np.array(b"1\0")
|
| 80 |
+
yield np.array(b"\01")
|
| 81 |
+
yield np.array(b"1234")
|
| 82 |
+
yield np.array(b"123\0")
|
| 83 |
+
yield np.array(b"12345")
|
| 84 |
+
|
| 85 |
+
def test_intent_in(self):
|
| 86 |
+
for s in self._get_input():
|
| 87 |
+
r = self.module.test_in_bytes4(s)
|
| 88 |
+
# also checks that s is not changed inplace
|
| 89 |
+
expected = self._sint(s, end=4)
|
| 90 |
+
assert r == expected, s
|
| 91 |
+
|
| 92 |
+
def test_intent_inout(self):
|
| 93 |
+
for s in self._get_input(intent="inout"):
|
| 94 |
+
rest = self._sint(s, start=4)
|
| 95 |
+
r = self.module.test_inout_bytes4(s)
|
| 96 |
+
expected = self._sint(s, end=4)
|
| 97 |
+
assert r == expected
|
| 98 |
+
|
| 99 |
+
# check that the rest of input string is preserved
|
| 100 |
+
assert rest == self._sint(s, start=4)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/f2py/tests/util.py
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Utility functions for
|
| 3 |
+
|
| 4 |
+
- building and importing modules on test time, using a temporary location
|
| 5 |
+
- detecting if compilers are present
|
| 6 |
+
- determining paths to tests
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
import glob
|
| 10 |
+
import os
|
| 11 |
+
import sys
|
| 12 |
+
import subprocess
|
| 13 |
+
import tempfile
|
| 14 |
+
import shutil
|
| 15 |
+
import atexit
|
| 16 |
+
import textwrap
|
| 17 |
+
import re
|
| 18 |
+
import pytest
|
| 19 |
+
import contextlib
|
| 20 |
+
import numpy
|
| 21 |
+
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
from numpy.compat import asstr
|
| 24 |
+
from numpy._utils import asunicode
|
| 25 |
+
from numpy.testing import temppath, IS_WASM
|
| 26 |
+
from importlib import import_module
|
| 27 |
+
|
| 28 |
+
#
|
| 29 |
+
# Maintaining a temporary module directory
|
| 30 |
+
#
|
| 31 |
+
|
| 32 |
+
_module_dir = None
|
| 33 |
+
_module_num = 5403
|
| 34 |
+
|
| 35 |
+
if sys.platform == "cygwin":
|
| 36 |
+
NUMPY_INSTALL_ROOT = Path(__file__).parent.parent.parent
|
| 37 |
+
_module_list = list(NUMPY_INSTALL_ROOT.glob("**/*.dll"))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _cleanup():
|
| 41 |
+
global _module_dir
|
| 42 |
+
if _module_dir is not None:
|
| 43 |
+
try:
|
| 44 |
+
sys.path.remove(_module_dir)
|
| 45 |
+
except ValueError:
|
| 46 |
+
pass
|
| 47 |
+
try:
|
| 48 |
+
shutil.rmtree(_module_dir)
|
| 49 |
+
except OSError:
|
| 50 |
+
pass
|
| 51 |
+
_module_dir = None
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def get_module_dir():
|
| 55 |
+
global _module_dir
|
| 56 |
+
if _module_dir is None:
|
| 57 |
+
_module_dir = tempfile.mkdtemp()
|
| 58 |
+
atexit.register(_cleanup)
|
| 59 |
+
if _module_dir not in sys.path:
|
| 60 |
+
sys.path.insert(0, _module_dir)
|
| 61 |
+
return _module_dir
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def get_temp_module_name():
|
| 65 |
+
# Assume single-threaded, and the module dir usable only by this thread
|
| 66 |
+
global _module_num
|
| 67 |
+
get_module_dir()
|
| 68 |
+
name = "_test_ext_module_%d" % _module_num
|
| 69 |
+
_module_num += 1
|
| 70 |
+
if name in sys.modules:
|
| 71 |
+
# this should not be possible, but check anyway
|
| 72 |
+
raise RuntimeError("Temporary module name already in use.")
|
| 73 |
+
return name
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _memoize(func):
|
| 77 |
+
memo = {}
|
| 78 |
+
|
| 79 |
+
def wrapper(*a, **kw):
|
| 80 |
+
key = repr((a, kw))
|
| 81 |
+
if key not in memo:
|
| 82 |
+
try:
|
| 83 |
+
memo[key] = func(*a, **kw)
|
| 84 |
+
except Exception as e:
|
| 85 |
+
memo[key] = e
|
| 86 |
+
raise
|
| 87 |
+
ret = memo[key]
|
| 88 |
+
if isinstance(ret, Exception):
|
| 89 |
+
raise ret
|
| 90 |
+
return ret
|
| 91 |
+
|
| 92 |
+
wrapper.__name__ = func.__name__
|
| 93 |
+
return wrapper
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
#
|
| 97 |
+
# Building modules
|
| 98 |
+
#
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@_memoize
|
| 102 |
+
def build_module(source_files, options=[], skip=[], only=[], module_name=None):
|
| 103 |
+
"""
|
| 104 |
+
Compile and import a f2py module, built from the given files.
|
| 105 |
+
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
code = f"import sys; sys.path = {sys.path!r}; import numpy.f2py; numpy.f2py.main()"
|
| 109 |
+
|
| 110 |
+
d = get_module_dir()
|
| 111 |
+
|
| 112 |
+
# Copy files
|
| 113 |
+
dst_sources = []
|
| 114 |
+
f2py_sources = []
|
| 115 |
+
for fn in source_files:
|
| 116 |
+
if not os.path.isfile(fn):
|
| 117 |
+
raise RuntimeError("%s is not a file" % fn)
|
| 118 |
+
dst = os.path.join(d, os.path.basename(fn))
|
| 119 |
+
shutil.copyfile(fn, dst)
|
| 120 |
+
dst_sources.append(dst)
|
| 121 |
+
|
| 122 |
+
base, ext = os.path.splitext(dst)
|
| 123 |
+
if ext in (".f90", ".f", ".c", ".pyf"):
|
| 124 |
+
f2py_sources.append(dst)
|
| 125 |
+
|
| 126 |
+
assert f2py_sources
|
| 127 |
+
|
| 128 |
+
# Prepare options
|
| 129 |
+
if module_name is None:
|
| 130 |
+
module_name = get_temp_module_name()
|
| 131 |
+
f2py_opts = ["-c", "-m", module_name] + options + f2py_sources
|
| 132 |
+
if skip:
|
| 133 |
+
f2py_opts += ["skip:"] + skip
|
| 134 |
+
if only:
|
| 135 |
+
f2py_opts += ["only:"] + only
|
| 136 |
+
|
| 137 |
+
# Build
|
| 138 |
+
cwd = os.getcwd()
|
| 139 |
+
try:
|
| 140 |
+
os.chdir(d)
|
| 141 |
+
cmd = [sys.executable, "-c", code] + f2py_opts
|
| 142 |
+
p = subprocess.Popen(cmd,
|
| 143 |
+
stdout=subprocess.PIPE,
|
| 144 |
+
stderr=subprocess.STDOUT)
|
| 145 |
+
out, err = p.communicate()
|
| 146 |
+
if p.returncode != 0:
|
| 147 |
+
raise RuntimeError("Running f2py failed: %s\n%s" %
|
| 148 |
+
(cmd[4:], asunicode(out)))
|
| 149 |
+
finally:
|
| 150 |
+
os.chdir(cwd)
|
| 151 |
+
|
| 152 |
+
# Partial cleanup
|
| 153 |
+
for fn in dst_sources:
|
| 154 |
+
os.unlink(fn)
|
| 155 |
+
|
| 156 |
+
# Rebase (Cygwin-only)
|
| 157 |
+
if sys.platform == "cygwin":
|
| 158 |
+
# If someone starts deleting modules after import, this will
|
| 159 |
+
# need to change to record how big each module is, rather than
|
| 160 |
+
# relying on rebase being able to find that from the files.
|
| 161 |
+
_module_list.extend(
|
| 162 |
+
glob.glob(os.path.join(d, "{:s}*".format(module_name)))
|
| 163 |
+
)
|
| 164 |
+
subprocess.check_call(
|
| 165 |
+
["/usr/bin/rebase", "--database", "--oblivious", "--verbose"]
|
| 166 |
+
+ _module_list
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
# Import
|
| 172 |
+
return import_module(module_name)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
@_memoize
|
| 176 |
+
def build_code(source_code,
|
| 177 |
+
options=[],
|
| 178 |
+
skip=[],
|
| 179 |
+
only=[],
|
| 180 |
+
suffix=None,
|
| 181 |
+
module_name=None):
|
| 182 |
+
"""
|
| 183 |
+
Compile and import Fortran code using f2py.
|
| 184 |
+
|
| 185 |
+
"""
|
| 186 |
+
if suffix is None:
|
| 187 |
+
suffix = ".f"
|
| 188 |
+
with temppath(suffix=suffix) as path:
|
| 189 |
+
with open(path, "w") as f:
|
| 190 |
+
f.write(source_code)
|
| 191 |
+
return build_module([path],
|
| 192 |
+
options=options,
|
| 193 |
+
skip=skip,
|
| 194 |
+
only=only,
|
| 195 |
+
module_name=module_name)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
#
|
| 199 |
+
# Check if compilers are available at all...
|
| 200 |
+
#
|
| 201 |
+
|
| 202 |
+
_compiler_status = None
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def _get_compiler_status():
|
| 206 |
+
global _compiler_status
|
| 207 |
+
if _compiler_status is not None:
|
| 208 |
+
return _compiler_status
|
| 209 |
+
|
| 210 |
+
_compiler_status = (False, False, False)
|
| 211 |
+
if IS_WASM:
|
| 212 |
+
# Can't run compiler from inside WASM.
|
| 213 |
+
return _compiler_status
|
| 214 |
+
|
| 215 |
+
# XXX: this is really ugly. But I don't know how to invoke Distutils
|
| 216 |
+
# in a safer way...
|
| 217 |
+
code = textwrap.dedent(f"""\
|
| 218 |
+
import os
|
| 219 |
+
import sys
|
| 220 |
+
sys.path = {repr(sys.path)}
|
| 221 |
+
|
| 222 |
+
def configuration(parent_name='',top_path=None):
|
| 223 |
+
global config
|
| 224 |
+
from numpy.distutils.misc_util import Configuration
|
| 225 |
+
config = Configuration('', parent_name, top_path)
|
| 226 |
+
return config
|
| 227 |
+
|
| 228 |
+
from numpy.distutils.core import setup
|
| 229 |
+
setup(configuration=configuration)
|
| 230 |
+
|
| 231 |
+
config_cmd = config.get_config_cmd()
|
| 232 |
+
have_c = config_cmd.try_compile('void foo() {{}}')
|
| 233 |
+
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
|
| 234 |
+
config.have_f77c(),
|
| 235 |
+
config.have_f90c()))
|
| 236 |
+
sys.exit(99)
|
| 237 |
+
""")
|
| 238 |
+
code = code % dict(syspath=repr(sys.path))
|
| 239 |
+
|
| 240 |
+
tmpdir = tempfile.mkdtemp()
|
| 241 |
+
try:
|
| 242 |
+
script = os.path.join(tmpdir, "setup.py")
|
| 243 |
+
|
| 244 |
+
with open(script, "w") as f:
|
| 245 |
+
f.write(code)
|
| 246 |
+
|
| 247 |
+
cmd = [sys.executable, "setup.py", "config"]
|
| 248 |
+
p = subprocess.Popen(cmd,
|
| 249 |
+
stdout=subprocess.PIPE,
|
| 250 |
+
stderr=subprocess.STDOUT,
|
| 251 |
+
cwd=tmpdir)
|
| 252 |
+
out, err = p.communicate()
|
| 253 |
+
finally:
|
| 254 |
+
shutil.rmtree(tmpdir)
|
| 255 |
+
|
| 256 |
+
m = re.search(br"COMPILERS:(\d+),(\d+),(\d+)", out)
|
| 257 |
+
if m:
|
| 258 |
+
_compiler_status = (
|
| 259 |
+
bool(int(m.group(1))),
|
| 260 |
+
bool(int(m.group(2))),
|
| 261 |
+
bool(int(m.group(3))),
|
| 262 |
+
)
|
| 263 |
+
# Finished
|
| 264 |
+
return _compiler_status
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def has_c_compiler():
|
| 268 |
+
return _get_compiler_status()[0]
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def has_f77_compiler():
|
| 272 |
+
return _get_compiler_status()[1]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def has_f90_compiler():
|
| 276 |
+
return _get_compiler_status()[2]
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
#
|
| 280 |
+
# Building with distutils
|
| 281 |
+
#
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
@_memoize
|
| 285 |
+
def build_module_distutils(source_files, config_code, module_name, **kw):
|
| 286 |
+
"""
|
| 287 |
+
Build a module via distutils and import it.
|
| 288 |
+
|
| 289 |
+
"""
|
| 290 |
+
d = get_module_dir()
|
| 291 |
+
|
| 292 |
+
# Copy files
|
| 293 |
+
dst_sources = []
|
| 294 |
+
for fn in source_files:
|
| 295 |
+
if not os.path.isfile(fn):
|
| 296 |
+
raise RuntimeError("%s is not a file" % fn)
|
| 297 |
+
dst = os.path.join(d, os.path.basename(fn))
|
| 298 |
+
shutil.copyfile(fn, dst)
|
| 299 |
+
dst_sources.append(dst)
|
| 300 |
+
|
| 301 |
+
# Build script
|
| 302 |
+
config_code = textwrap.dedent(config_code).replace("\n", "\n ")
|
| 303 |
+
|
| 304 |
+
code = fr"""
|
| 305 |
+
import os
|
| 306 |
+
import sys
|
| 307 |
+
sys.path = {repr(sys.path)}
|
| 308 |
+
|
| 309 |
+
def configuration(parent_name='',top_path=None):
|
| 310 |
+
from numpy.distutils.misc_util import Configuration
|
| 311 |
+
config = Configuration('', parent_name, top_path)
|
| 312 |
+
{config_code}
|
| 313 |
+
return config
|
| 314 |
+
|
| 315 |
+
if __name__ == "__main__":
|
| 316 |
+
from numpy.distutils.core import setup
|
| 317 |
+
setup(configuration=configuration)
|
| 318 |
+
"""
|
| 319 |
+
script = os.path.join(d, get_temp_module_name() + ".py")
|
| 320 |
+
dst_sources.append(script)
|
| 321 |
+
with open(script, "wb") as f:
|
| 322 |
+
f.write(code.encode('latin1'))
|
| 323 |
+
|
| 324 |
+
# Build
|
| 325 |
+
cwd = os.getcwd()
|
| 326 |
+
try:
|
| 327 |
+
os.chdir(d)
|
| 328 |
+
cmd = [sys.executable, script, "build_ext", "-i"]
|
| 329 |
+
p = subprocess.Popen(cmd,
|
| 330 |
+
stdout=subprocess.PIPE,
|
| 331 |
+
stderr=subprocess.STDOUT)
|
| 332 |
+
out, err = p.communicate()
|
| 333 |
+
if p.returncode != 0:
|
| 334 |
+
raise RuntimeError("Running distutils build failed: %s\n%s" %
|
| 335 |
+
(cmd[4:], asstr(out)))
|
| 336 |
+
finally:
|
| 337 |
+
os.chdir(cwd)
|
| 338 |
+
|
| 339 |
+
# Partial cleanup
|
| 340 |
+
for fn in dst_sources:
|
| 341 |
+
os.unlink(fn)
|
| 342 |
+
|
| 343 |
+
# Import
|
| 344 |
+
__import__(module_name)
|
| 345 |
+
return sys.modules[module_name]
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
#
|
| 349 |
+
# Unittest convenience
|
| 350 |
+
#
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
class F2PyTest:
|
| 354 |
+
code = None
|
| 355 |
+
sources = None
|
| 356 |
+
options = []
|
| 357 |
+
skip = []
|
| 358 |
+
only = []
|
| 359 |
+
suffix = ".f"
|
| 360 |
+
module = None
|
| 361 |
+
|
| 362 |
+
@property
|
| 363 |
+
def module_name(self):
|
| 364 |
+
cls = type(self)
|
| 365 |
+
return f'_{cls.__module__.rsplit(".",1)[-1]}_{cls.__name__}_ext_module'
|
| 366 |
+
|
| 367 |
+
def setup_method(self):
|
| 368 |
+
if sys.platform == "win32":
|
| 369 |
+
pytest.skip("Fails with MinGW64 Gfortran (Issue #9673)")
|
| 370 |
+
|
| 371 |
+
if self.module is not None:
|
| 372 |
+
return
|
| 373 |
+
|
| 374 |
+
# Check compiler availability first
|
| 375 |
+
if not has_c_compiler():
|
| 376 |
+
pytest.skip("No C compiler available")
|
| 377 |
+
|
| 378 |
+
codes = []
|
| 379 |
+
if self.sources:
|
| 380 |
+
codes.extend(self.sources)
|
| 381 |
+
if self.code is not None:
|
| 382 |
+
codes.append(self.suffix)
|
| 383 |
+
|
| 384 |
+
needs_f77 = False
|
| 385 |
+
needs_f90 = False
|
| 386 |
+
needs_pyf = False
|
| 387 |
+
for fn in codes:
|
| 388 |
+
if str(fn).endswith(".f"):
|
| 389 |
+
needs_f77 = True
|
| 390 |
+
elif str(fn).endswith(".f90"):
|
| 391 |
+
needs_f90 = True
|
| 392 |
+
elif str(fn).endswith(".pyf"):
|
| 393 |
+
needs_pyf = True
|
| 394 |
+
if needs_f77 and not has_f77_compiler():
|
| 395 |
+
pytest.skip("No Fortran 77 compiler available")
|
| 396 |
+
if needs_f90 and not has_f90_compiler():
|
| 397 |
+
pytest.skip("No Fortran 90 compiler available")
|
| 398 |
+
if needs_pyf and not (has_f90_compiler() or has_f77_compiler()):
|
| 399 |
+
pytest.skip("No Fortran compiler available")
|
| 400 |
+
|
| 401 |
+
# Build the module
|
| 402 |
+
if self.code is not None:
|
| 403 |
+
self.module = build_code(
|
| 404 |
+
self.code,
|
| 405 |
+
options=self.options,
|
| 406 |
+
skip=self.skip,
|
| 407 |
+
only=self.only,
|
| 408 |
+
suffix=self.suffix,
|
| 409 |
+
module_name=self.module_name,
|
| 410 |
+
)
|
| 411 |
+
|
| 412 |
+
if self.sources is not None:
|
| 413 |
+
self.module = build_module(
|
| 414 |
+
self.sources,
|
| 415 |
+
options=self.options,
|
| 416 |
+
skip=self.skip,
|
| 417 |
+
only=self.only,
|
| 418 |
+
module_name=self.module_name,
|
| 419 |
+
)
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
#
|
| 423 |
+
# Helper functions
|
| 424 |
+
#
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def getpath(*a):
|
| 428 |
+
# Package root
|
| 429 |
+
d = Path(numpy.f2py.__file__).parent.resolve()
|
| 430 |
+
return d.joinpath(*a)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
@contextlib.contextmanager
|
| 434 |
+
def switchdir(path):
|
| 435 |
+
curpath = Path.cwd()
|
| 436 |
+
os.chdir(path)
|
| 437 |
+
try:
|
| 438 |
+
yield
|
| 439 |
+
finally:
|
| 440 |
+
os.chdir(curpath)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_2x8gpu_50ep_lr3e3_ema0p9999_elfopt_not5_bottleneck128_unfixed_norm_stateprobadd_selfcond_ce_fast_20260609_230848.log
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|