Numpy: [BUG] C μ†ŒμŠ€κ°€ λ¨Όμ € μƒμ„±λ˜λ©΄ f2pyκ°€ ν™•μž₯ λͺ¨λ“ˆμ„ 컴파일 ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

에 λ§Œλ“  2019λ…„ 11μ›” 22일  Β·  7μ½”λ©˜νŠΈ  Β·  좜처: numpy/numpy

f2py의 λ¬Έμ„œ / μ‚¬μš©μž κ°€μ΄λ“œμ— 따라 ν™•μž₯ λͺ¨λ“ˆμ΄μžˆλŠ” .c νŒŒμΌμ„ μƒμ„±ν•˜λ €λ©΄ λ°˜λ“œμ‹œ μˆ˜ν–‰ν•΄μ•Όν•©λ‹ˆλ‹€.

$ f2py -m fib1 fib1.f

fib1module.c νŒŒμΌμ„ μƒμ„±ν•©λ‹ˆλ‹€. μž‘λ™ν•©λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ λ¬Έμ„œμ— λ”°λ₯΄λ©΄ Pythonμ—μ„œ κ°€μ Έμ˜¬ 수 μžˆλ„λ‘ ν™•μž₯ λͺ¨λ“ˆμ„ λΉŒλ“œν•˜λŠ” λ‹€μŒ λ‹¨κ³„λŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

$ f2py -c fib1module.c

κ·ΈλŸ¬λ‚˜ λ‹€μŒ λ©”μ‹œμ§€μ™€ ν•¨κ»˜ μ‹€νŒ¨ν•©λ‹ˆλ‹€.

$ f2py -c fib1module.c --verbose
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "untitled" sources
build_src: building npy-pkg config files
running build_ext
new_compiler returns <class 'distutils.unixccompiler.UnixCCompiler'>
customize UnixCCompiler
customize UnixCCompiler using build_ext
********************************************************************************
<class 'distutils.unixccompiler.UnixCCompiler'>
preprocessor  = ['gcc', '-pthread', '-B', '/opt/miniconda/envs/numpy-dev/compiler_compat', '-Wl,--sysroot=/', '-E']
compiler      = ['gcc', '-pthread', '-B', '/opt/miniconda/envs/numpy-dev/compiler_compat', '-Wl,--sysroot=/', '-Wsign-compare', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall', '-Wstrict-prototypes', '-std=c99']
compiler_so   = ['gcc', '-pthread', '-B', '/opt/miniconda/envs/numpy-dev/compiler_compat', '-Wl,--sysroot=/', '-Wsign-compare', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall', '-Wstrict-prototypes', '-fPIC', '-std=c99']
compiler_cxx  = ['g++', '-pthread', '-B', '/opt/miniconda/envs/numpy-dev/compiler_compat', '-Wl,--sysroot=/']
linker_so     = ['gcc', '-pthread', '-shared', '-B', '/opt/miniconda/envs/numpy-dev/compiler_compat', '-L/opt/miniconda/envs/numpy-dev/lib', '-Wl,-rpath=/opt/miniconda/envs/numpy-dev/lib', '-Wl,--no-as-needed', '-Wl,--sysroot=/']
linker_exe    = ['gcc', '-pthread', '-B', '/opt/miniconda/envs/numpy-dev/compiler_compat', '-Wl,--sysroot=/']
archiver      = ['ar', 'rc']
ranlib        = None
libraries     = []
library_dirs  = []
include_dirs  = ['/opt/miniconda/envs/numpy-dev/include/python3.6m']
********************************************************************************
building 'untitled' extension
compiling C sources
C compiler: gcc -pthread -B /opt/miniconda/envs/numpy-dev/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -std=c99

compile options: '-I/home/melissa/projects/numpy/numpy/core/include -I/opt/miniconda/envs/numpy-dev/include/python3.6m -c'
gcc: fib1module.c
fib1module.c:16:10: fatal error: fortranobject.h: Arquivo ou diretΓ³rio inexistente
   16 | #include "fortranobject.h"
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
error: Command "gcc -pthread -B /opt/miniconda/envs/numpy-dev/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -std=c99 -I/home/melissa/projects/numpy/numpy/core/include -I/opt/miniconda/envs/numpy-dev/include/python3.6m -c fib1module.c -o /tmp/tmpyjgu4iq5/fib1module.o -MMD -MF /tmp/tmpyjgu4iq5/fib1module.o.d" failed with exit status 1

ν•˜κΈ°

$ f2py -c fib1module.c -I/home/melissa/projects/numpy/numpy/f2py/src -m fib1module

μž‘λ™ν•˜λŠ” 것 κ°™μ§€λ§Œ (이것은 λ‚΄ fortranobject.h 파일의 μœ„μΉ˜μž…λ‹ˆλ‹€) λͺ¨λ“ˆμ„ κ°€μ Έμ˜¬ 수 μ—†μŠ΅λ‹ˆλ‹€.

>>> import fib1module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/melissa/projects/numpy/doc/source/f2py/fib1module.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyFortran_Type

TL; DR : 이것은 λ²„κ·Έμž…λ‹ˆκΉŒ, μ•„λ‹ˆλ©΄ μš°λ¦¬κ°€ν•΄μ„œλŠ” μ•ˆλ˜λŠ” μΌμž…λ‹ˆκΉŒ ( .c μ†ŒμŠ€λ₯Ό 생성 ν•œ λ‹€μŒ λ³„λ„μ˜ λ‹¨κ³„μ—μ„œ ν™•μž₯ λͺ¨λ“ˆμ„ λΉŒλ“œ)?

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.18.0.dev0+8d217b0 3.6.7 | packaged by conda-forge | (default, Jul  2 2019, 02:18:42) 
[GCC 7.3.0]
00 - Bug numpy.f2py

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μ–΄λ–€ λ¬Έμ„œκ°€ 이것을 λ§ν•˜λŠ”μ§€ 잘 λͺ¨λ₯΄κ² μ§€λ§Œ λ‹€μŒμ€ 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

$ f2py -c fib1module.c

f2py -c ... λŠ” κΈ°μ‘΄ .pyf 파일 (μ†ŒμŠ€ / 였브젝트 / 라이브러리 파일 포함)에 μ μš©ν•˜κ±°λ‚˜ -m <modulename> μ˜΅μ…˜ (μ†ŒμŠ€ / 였브젝트 / 라이브러리 파일 포함)을 μ§€μ •ν•΄μ•Όν•©λ‹ˆλ‹€. . f2py -c λŠ” 생성 된 C / API ν™•μž₯ λͺ¨λ“ˆμ„ 직접 μ»΄νŒŒμΌν•˜κΈ°μœ„ν•œ 것이 μ•„λ‹™λ‹ˆλ‹€ (μ μ ˆν•œ 포함 디렉토리 ν”Œλž˜κ·Έ 및 μ†ŒμŠ€ / 객체 파일 μž…λ ₯으둜이λ₯Ό μˆ˜ν–‰ ν•  수 있음).

λ‹€μŒ μ˜΅μ…˜ 쀑 ν•˜λ‚˜λ₯Ό μ‚¬μš©ν•˜μ‹­μ‹œμ˜€.

f2py -c -m fib1 fib1.f

λ˜λŠ”

f2py -m fib1 fib1.f -h fib1.pyf
f2py -c fib1.pyf fib1.f

μ΄λŸ¬ν•œ μ˜ˆλŠ” μœ„μ˜ f2py λͺ…λ Ή μ€„μ—μ„œ κ±΄λ„ˆ λ›°λŠ” 것이 있으면 μ‹€νŒ¨κ°€ μ˜ˆμƒλœλ‹€λŠ” μ μ—μ„œ μ΅œμ†Œν•œμ˜ κ²ƒμž…λ‹ˆλ‹€.

λͺ¨λ“  7 λŒ“κΈ€

@melissawm λ³΄κ³ μ„œμ— κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€. μš°λ¦¬λŠ”μ΄ νŽ˜μ΄μ§€μ— λŒ€ν•΄ λ§ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€ : https://numpy.org/devdocs/f2py/getting-started.html?

λ³΄κ³ μžˆλŠ” λ‚΄μš©μ„ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

$ f2py -m fib1 fib1.f
$ f2py -c fib1module.c
...
fib1module.c:16:10: fatal error: 'fortranobject.h' file not found
#include "fortranobject.h"

κ·ΈλŸ¬λ‚˜ λ¬Έμ„œ νŽ˜μ΄μ§€λŠ” λŒ€μ‹  $ f2py -c -m fib1 fib1.f 을 μˆ˜ν–‰ν•˜λ©° (μ½”λ“œλ₯Ό μƒμ„±ν•˜κ³  ν•œ λ²ˆμ— 컴파일) μ˜ˆμƒλŒ€λ‘œ μž‘λ™ν•©λ‹ˆλ‹€. -m 및 -c 이 μ§€μ›λ˜μ—ˆλŠ”μ§€ ν™•μ‹€ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ˜¬λ°”λ₯Έ 포함 경둜λ₯Ό μžλ™μœΌλ‘œ μΆ”κ°€ν•˜μ—¬ -c -만 μž‘λ™ν•˜λ„λ‘ λ§Œλ“€ 수 μžˆμŠ΅λ‹ˆλ‹€.-μ•„λ§ˆλ„ μ–΄λ ΅μ§€λŠ” μ•Šμ§€λ§Œ ν•„μš”ν•œμ§€ ν™•μ‹€ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

@pearu μ–΄λ–€ 생각?

μ–΄λ–€ λ¬Έμ„œκ°€ 이것을 λ§ν•˜λŠ”μ§€ 잘 λͺ¨λ₯΄κ² μ§€λ§Œ λ‹€μŒμ€ 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

$ f2py -c fib1module.c

f2py -c ... λŠ” κΈ°μ‘΄ .pyf 파일 (μ†ŒμŠ€ / 였브젝트 / 라이브러리 파일 포함)에 μ μš©ν•˜κ±°λ‚˜ -m <modulename> μ˜΅μ…˜ (μ†ŒμŠ€ / 였브젝트 / 라이브러리 파일 포함)을 μ§€μ •ν•΄μ•Όν•©λ‹ˆλ‹€. . f2py -c λŠ” 생성 된 C / API ν™•μž₯ λͺ¨λ“ˆμ„ 직접 μ»΄νŒŒμΌν•˜κΈ°μœ„ν•œ 것이 μ•„λ‹™λ‹ˆλ‹€ (μ μ ˆν•œ 포함 디렉토리 ν”Œλž˜κ·Έ 및 μ†ŒμŠ€ / 객체 파일 μž…λ ₯으둜이λ₯Ό μˆ˜ν–‰ ν•  수 있음).

λ‹€μŒ μ˜΅μ…˜ 쀑 ν•˜λ‚˜λ₯Ό μ‚¬μš©ν•˜μ‹­μ‹œμ˜€.

f2py -c -m fib1 fib1.f

λ˜λŠ”

f2py -m fib1 fib1.f -h fib1.pyf
f2py -c fib1.pyf fib1.f

μ΄λŸ¬ν•œ μ˜ˆλŠ” μœ„μ˜ f2py λͺ…λ Ή μ€„μ—μ„œ κ±΄λ„ˆ λ›°λŠ” 것이 있으면 μ‹€νŒ¨κ°€ μ˜ˆμƒλœλ‹€λŠ” μ μ—μ„œ μ΅œμ†Œν•œμ˜ κ²ƒμž…λ‹ˆλ‹€.

μ‹€μ œλ‘œμ΄ νŽ˜μ΄μ§€μ— λŒ€ν•΄ μ΄μ•ΌκΈ°ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€ : https://numpy.org/devdocs/f2py/usage.html

ν•­λͺ© 2와 3μ—λŠ” λ‹€μŒμ΄ μžˆμŠ΅λ‹ˆλ‹€. ν•­λͺ© 2λŠ” -m λ˜λŠ” -c μ˜΅μ…˜μ—†μ΄ f2py λ₯Ό μ‹€ν–‰ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. ν•­λͺ© 3은 λ§ν•œλ‹€

ν™•μž₯ λͺ¨λ“ˆμ„ λΉŒλ“œν•˜λ €λ©΄

f2py -c <options> <fortran files>       \
  [[ only: <fortran functions>  : ]     \
   [ skip: <fortran functions>  : ]]... \
  [ <fortran/c source files> ] [ <.o, .a, .so files> ]

<fortran files> 에 μ„œλͺ… 파일이 ν¬ν•¨λ˜μ–΄ 있으면 ν™•μž₯ λͺ¨λ“ˆμ˜ μ†ŒμŠ€κ°€ μƒμ„±λ©λ‹ˆλ‹€.
λͺ¨λ“  Fortran 및 C μ†ŒμŠ€κ°€ 컴파일되고 λ§ˆμ§€λ§‰μœΌλ‘œ λͺ¨λ“  개체 및 라이브러리 파일이
ν˜„μž¬ 디렉토리에 μ €μž₯λ˜λŠ” ν™•μž₯ λͺ¨λ“ˆ <modulename>.so .

<fortran files> 에 μ„œλͺ… 파일이 ν¬ν•¨λ˜μ–΄ μžˆμ§€ μ•ŠμœΌλ©΄ ν™•μž₯ λͺ¨λ“ˆμ€ λ‹€μŒκ³Ό 같이 κ΅¬μ„±λ©λ‹ˆλ‹€.
일상적인 μ„œλͺ…을 μœ„ν•΄ λͺ¨λ“  Fortran μ†ŒμŠ€ μ½”λ“œλ₯Ό μŠ€μΊ”ν•©λ‹ˆλ‹€.

당신이 λ§ν•œλŒ€λ‘œ, μš°λ¦¬κ°€ .c μ†ŒμŠ€λ₯Ό 직접 μ‚¬μš©ν•΄μ„œλŠ” μ•ˆλœλ‹€λŠ” 것을 μ΄ν•΄ν•©λ‹ˆλ‹€. .c νŒŒμΌμ„ μƒμ„±ν•˜λ©΄ λ‚˜μ€‘μ— μ‚¬μš©ν•  수 μ—†μŠ΅λ‹ˆκΉŒ?

μž…λ ₯ ν•΄ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€!

μ‹€μ œλ‘œμ΄ νŽ˜μ΄μ§€μ— λŒ€ν•΄ μ΄μ•ΌκΈ°ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€ : https://numpy.org/devdocs/f2py/usage.html

이 νŽ˜μ΄μ§€μ—μ„œλŠ” f2py λͺ…λ Ή 쀄 μ˜΅μ…˜κ³Ό λ‹€μ–‘ν•œ λͺ¨λ“œλ₯Ό μ„€λͺ…ν•©λ‹ˆλ‹€. Python ν™•μž₯ λͺ¨λ“ˆμ„ λΉŒλ“œν•˜λŠ” 방법을 μ΄ν•΄ν•˜κ³  μžˆλ‹€κ³  κ°€μ •ν•©λ‹ˆλ‹€ (예 : https://docs.python.org/3.8/extending/index.html μ°Έμ‘°).

f2pyλŠ” C ν•¨μˆ˜ ( .c νŒŒμΌμ— 포함)λ₯Ό λž˜ν•‘ν•˜λŠ” ν™•μž₯ λͺ¨λ“ˆμ„ λ§Œλ“œλŠ” 데 μ‚¬μš©ν•  수 μžˆμœΌλ―€λ‘œ "μš°λ¦¬λŠ” .c μ†ŒμŠ€λ₯Ό 직접 μ‚¬μš©ν•΄μ„œλŠ” μ•ˆλ©λ‹ˆλ‹€"λΌλŠ” λ¬Έμž₯은 μ •ν™•ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

ν•˜λ‚˜λŠ” κ΅¬λ³„ν•΄μ•Όν•œλ‹€ .c f2pyκ°€ λ°œμƒν•˜κ³  μžˆλ‹€λŠ” νŒŒμΌμ„ .c C ν•¨μˆ˜μ˜ μ‚¬μš©μž κ΅¬ν˜„μ„ ν¬ν•¨ν•˜λŠ” 파일. f2pyκ°€ μƒμ„±ν•˜λŠ” .c νŒŒμΌμ€ ν™•μž₯ λͺ¨λ“ˆμ΄ λΉŒλ“œλ˜λŠ” 방법 λ˜λŠ” f2pyλ₯Ό λ””λ²„κΉ…ν•˜λŠ” 방법을 μ™„μ „νžˆ μ œμ–΄ν•΄μ•Όν•˜λŠ” κ²½μš°μ—λ§Œ μœ μš©ν•©λ‹ˆλ‹€. λ‹€λ₯Έ λͺ¨λ“  κ²½μš°μ—λŠ” λΉŒλ“œ ν”„λ‘œμ„ΈμŠ€μ—μ„œ μžλ™μœΌλ‘œ μƒμ„±λ˜λ―€λ‘œ ν™•μž₯ λͺ¨λ“ˆμ„ 생성 ν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

λ‹€λ₯Έ 아이디어가 있으면 μ•Œλ €μ£Όμ„Έμš”. μœ„μ˜ @pearu 의 μ„€λͺ…을 λ¬Έμ„œμ— μΆ”κ°€ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. κ·€ν•˜μ˜ μ˜κ²¬μ— κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€!

문제λ₯Ό μ’…κ²°ν•΄λ„λ©λ‹ˆλ‹€ (λ˜λŠ” PR이 승인 된 후에 λ§Œν•΄μ•Όν•©λ‹ˆκΉŒ?).

이 문제λ₯Ό λ‹€λ£¨λŠ” PR이 수락되면 μ’…λ£Œν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

이 문제λ₯Ό λ‹€λ£¨λŠ” PR이 수락되면 μ’…λ£Œν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

+1

@melissawm 컀밋 λ©”μ‹œμ§€ 쀑 ν•˜λ‚˜μ— closes gh-14960 λ₯Ό μΆ”κ°€ ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. 그러면 PR이 λ³‘ν•©λ˜λ©΄ λ¬Έμ œκ°€ μžλ™μœΌλ‘œ λ‹«νž™λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰