From 7193109f4dcf42474161d052fddc09c6321554af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Wed, 12 Apr 2023 06:30:07 +0200 Subject: [PATCH] Package OpenBLAS and use OpenBLAS in scipy (#3331) --- .prettierignore | 2 +- Makefile.envs | 1 - docs/development/debugging.md | 3 +- docs/development/meta-yaml.md | 4 +- docs/development/new-packages.md | 2 +- docs/project/changelog.md | 2 + .../patches/0001-add-missing-import.patch | 42 --- .../patches/0003-lapack-install-make.patch | 31 -- .../patches/0007-Fix-xerbla-and-ilaenv.patch | 52 --- packages/gensim/meta.yaml | 9 + ...signature-mismatch-in-sdot-detection.patch | 45 +++ packages/{CLAPACK => libf2c}/make.inc | 0 packages/{CLAPACK => libf2c}/meta.yaml | 32 +- .../patches/0001-fix-arith.h.patch} | 2 +- .../patches/0002-fix-f2clibs-build.patch} | 2 +- .../0003-remove-redundant-symbols.patch} | 2 +- .../patches/0004-correct-return-types.patch} | 2 +- ...5-Remove-symbols-defined-in-OpenBLAS.patch | 27 ++ packages/openblas/meta.yaml | 44 +++ .../0001-Add-Wno-return-type-flag.patch | 29 ++ ...ray-signature-with-scipy-expectation.patch | 25 ++ packages/scipy/info.md | 58 ++-- packages/scipy/meta.yaml | 63 ++-- ...-Fix-dstevr-in-special-lapack_defs.h.patch | 6 +- ...-string.patch => 0002-int-to-string.patch} | 6 +- .../0002-loadDynamicLibrary-flapack.patch | 56 --- ...Add-lapack_extras-to-linalg-setup.py.patch | 25 -- ...ch => 0003-fix-fotran-files-minpack.patch} | 6 +- ...-const.patch => 0004-gemm_-no-const.patch} | 6 +- ...atch => 0005-make-int-return-values.patch} | 319 ++---------------- ...d_test.py-to-prevent-test-unvendori.patch} | 6 +- ... => 0007-skip-fortran-fails-to-link.patch} | 6 +- ...Change-qh_eachvoronoi_all-FILE-type.patch} | 6 +- ...h => 0009-Remove-meson-requirements.patch} | 6 +- .../0009-sasum-returns-double-not-float.patch | 25 -- ...x-fitpack.patch => 0010-Fix-fitpack.patch} | 6 +- ...laring-print_soln-give-it-the-correc.patch | 70 ++++ ...le-support-in-Boost-library-for-emsc.patch | 25 ++ packages/suitesparse/meta.yaml | 8 +- pyodide-build/pyodide_build/_f2c_fixes.py | 32 +- pyodide-build/pyodide_build/pywasmcross.py | 10 +- 41 files changed, 444 insertions(+), 659 deletions(-) delete mode 100644 packages/CLAPACK/patches/0001-add-missing-import.patch delete mode 100644 packages/CLAPACK/patches/0003-lapack-install-make.patch delete mode 100644 packages/CLAPACK/patches/0007-Fix-xerbla-and-ilaenv.patch create mode 100644 packages/gensim/patches/0001-Avoid-signature-mismatch-in-sdot-detection.patch rename packages/{CLAPACK => libf2c}/make.inc (100%) rename packages/{CLAPACK => libf2c}/meta.yaml (51%) rename packages/{CLAPACK/patches/0002-fix-arith.h.patch => libf2c/patches/0001-fix-arith.h.patch} (96%) rename packages/{CLAPACK/patches/0004-fix-f2clibs-build.patch => libf2c/patches/0002-fix-f2clibs-build.patch} (96%) rename packages/{CLAPACK/patches/0005-remove-redundant-symbols.patch => libf2c/patches/0003-remove-redundant-symbols.patch} (95%) rename packages/{CLAPACK/patches/0006-correct-return-types.patch => libf2c/patches/0004-correct-return-types.patch} (98%) create mode 100644 packages/libf2c/patches/0005-Remove-symbols-defined-in-OpenBLAS.patch create mode 100644 packages/openblas/meta.yaml create mode 100644 packages/openblas/patches/0001-Add-Wno-return-type-flag.patch create mode 100644 packages/openblas/patches/0002-Align-xerbla_array-signature-with-scipy-expectation.patch rename packages/scipy/patches/{0004-int-to-string.patch => 0002-int-to-string.patch} (90%) delete mode 100644 packages/scipy/patches/0002-loadDynamicLibrary-flapack.patch delete mode 100644 packages/scipy/patches/0003-Add-lapack_extras-to-linalg-setup.py.patch rename packages/scipy/patches/{0005-fix-fotran-files-minpack.patch => 0003-fix-fotran-files-minpack.patch} (98%) rename packages/scipy/patches/{0006-gemm_-no-const.patch => 0004-gemm_-no-const.patch} (97%) rename packages/scipy/patches/{0007-make-int-return-values.patch => 0005-make-int-return-values.patch} (58%) rename packages/scipy/patches/{0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch => 0006-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch} (92%) rename packages/scipy/patches/{0010-skip-fortran-fails-to-link.patch => 0007-skip-fortran-fails-to-link.patch} (93%) rename packages/scipy/patches/{0011-Change-qh_eachvoronoi_all-FILE-type.patch => 0008-Change-qh_eachvoronoi_all-FILE-type.patch} (93%) rename packages/scipy/patches/{0012-Remove-meson-requirements.patch => 0009-Remove-meson-requirements.patch} (85%) delete mode 100644 packages/scipy/patches/0009-sasum-returns-double-not-float.patch rename packages/scipy/patches/{0013-Fix-fitpack.patch => 0010-Fix-fitpack.patch} (97%) create mode 100644 packages/scipy/patches/0011-When-forward-declaring-print_soln-give-it-the-correc.patch create mode 100644 packages/scipy/patches/0012-Enable-long-double-support-in-Boost-library-for-emsc.patch diff --git a/.prettierignore b/.prettierignore index 2ac3d558943..90aaf11d276 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,4 +9,4 @@ cpython .vscode .pytest_cache .clang-format -packages/CLAPACK/make.inc +packages/libf2c/make.inc diff --git a/Makefile.envs b/Makefile.envs index d023781b378..f8fa86c7c7b 100644 --- a/Makefile.envs +++ b/Makefile.envs @@ -93,7 +93,6 @@ export LDFLAGS_BASE=\ $(DBGFLAGS) \ $(DBG_LDFLAGS) \ -s MODULARIZE=1 \ - -std=c++14 \ -s LZ4=1 \ -L $(CPYTHONROOT)/installs/python-$(PYVERSION)/lib/ \ -s WASM_BIGINT \ diff --git a/docs/development/debugging.md b/docs/development/debugging.md index 34f57535c43..4d5c4f87caf 100644 --- a/docs/development/debugging.md +++ b/docs/development/debugging.md @@ -141,7 +141,8 @@ callee because compiling with `-g3` increases the number of function pointers so the function pointer we are calling is in a different spot. I know of no way to determine the bad function pointer when compiling with `-g3`. -Sometimes (particularly with Scipy/CLAPACK) the issue will be a mismatch between +Sometimes (particularly with Scipy/OpenBLAS/libf2c) the issue will be a +mismatch between `(param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)` and `(param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)` diff --git a/docs/development/meta-yaml.md b/docs/development/meta-yaml.md index 0a65b53b5fd..4f0126ca03f 100644 --- a/docs/development/meta-yaml.md +++ b/docs/development/meta-yaml.md @@ -164,8 +164,8 @@ Files or folders in this folder will be packaged to make the Pyodide package. See the [zlib meta.yaml](https://github.com/pyodide/pyodide/blob/main/packages/zlib/meta.yaml) -for an example of a static library specification, and the [CLAPACK -meta.yaml](https://github.com/pyodide/pyodide/blob/main/packages/CLAPACK/meta.yaml) +for an example of a static library specification, and the [OpenBLAS +meta.yaml](https://github.com/pyodide/pyodide/blob/main/packages/openblas/meta.yaml) for an example of a shared library specification. ### `build/script` diff --git a/docs/development/new-packages.md b/docs/development/new-packages.md index d5d2ca6fd47..f77f96d3be4 100644 --- a/docs/development/new-packages.md +++ b/docs/development/new-packages.md @@ -348,7 +348,7 @@ as a starting point. After packaging a C library, it can be added as a dependency of a Python package like a normal dependency. See `lxml` and `libxml` for an example (and also -`scipy` and `CLAPACK`). +`scipy` and `OpenBLAS`). _Remark:_ Certain C libraries come as emscripten ports, and do not have to be built manually. They can be used by adding e.g. `-s USE_ZLIB` in the `cflags` of diff --git a/docs/project/changelog.md b/docs/project/changelog.md index b93b08bb42a..9f16e65e7d2 100644 --- a/docs/project/changelog.md +++ b/docs/project/changelog.md @@ -41,6 +41,8 @@ myst: ### Packages +- OpenBLAS has been added and scipy now uses OpenBLAS rather than CLAPACK + {pr}`3331`. - New packages: sourmash {pr}`3635`, screed {pr}`3635`, bitstring {pr}`3635`, deprecation {pr}`3635`, cachetools {pr}`3635`. - Upgraded libmpfr to 4.2.0 {pr}`3756`. diff --git a/packages/CLAPACK/patches/0001-add-missing-import.patch b/packages/CLAPACK/patches/0001-add-missing-import.patch deleted file mode 100644 index 9a78f11d5a5..00000000000 --- a/packages/CLAPACK/patches/0001-add-missing-import.patch +++ /dev/null @@ -1,42 +0,0 @@ -From c1c714f1217ab6fba5ae1ceb6d0c4a9469490093 Mon Sep 17 00:00:00 2001 -From: Michael Droettboom -Date: Fri, 18 Mar 2022 19:59:05 -0700 -Subject: [PATCH 1/7] add missing import - -The original source files are missing some imports. gcc assumes implicit -function declaration, so the code compiles fine, but emscripten sets - -Werror=implicit-function-declaration so it is a hard error. ---- - BLAS/SRC/xerbla.c | 2 ++ - INSTALL/tstiee.c | 2 ++ - 2 files changed, 4 insertions(+) - -diff --git a/BLAS/SRC/xerbla.c b/BLAS/SRC/xerbla.c -index 2d7baf5..da1d7fd 100644 ---- a/BLAS/SRC/xerbla.c -+++ b/BLAS/SRC/xerbla.c -@@ -10,6 +10,8 @@ - http://www.netlib.org/f2c/libf2c.zip - */ - -+#include -+ - #include "f2c.h" - #include "blaswrap.h" - -diff --git a/INSTALL/tstiee.c b/INSTALL/tstiee.c -index 2b5426f..89a41b8 100644 ---- a/INSTALL/tstiee.c -+++ b/INSTALL/tstiee.c -@@ -10,6 +10,8 @@ - http://www.netlib.org/f2c/libf2c.zip - */ - -+#include -+ - #include "f2c.h" - #include "blaswrap.h" - #include "string.h" --- -2.25.1 - diff --git a/packages/CLAPACK/patches/0003-lapack-install-make.patch b/packages/CLAPACK/patches/0003-lapack-install-make.patch deleted file mode 100644 index e3f1a103530..00000000000 --- a/packages/CLAPACK/patches/0003-lapack-install-make.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 7b263aed921afdf92525975befd268b0871b8dc4 Mon Sep 17 00:00:00 2001 -From: Michael Droettboom -Date: Fri, 18 Mar 2022 19:59:46 -0700 -Subject: [PATCH 3/7] lapack install make - -lapack_install requires f2clib (see INSTALL/Makefile). - -Don't run LAPACK_INSTALL tests since they won't actually run on x86 ---- - Makefile | 5 ++--- - 1 file changed, 2 insertions(+), 3 deletions(-) - -diff --git a/Makefile b/Makefile -index 36c6a0d..4e43b79 100644 ---- a/Makefile -+++ b/Makefile -@@ -15,9 +15,8 @@ lib: f2clib blaslib variants lapacklib tmglib - - clean: cleanlib cleantesting cleanblas_testing - --lapack_install: -- ( cd INSTALL; $(MAKE); ./testlsame; ./testslamch; \ -- ./testdlamch; ./testsecond; ./testdsecnd; ./testversion ) -+lapack_install: f2clib -+ ( cd INSTALL; $(MAKE) ) - - blaslib: - ( cd BLAS/SRC; $(MAKE) ) --- -2.25.1 - diff --git a/packages/CLAPACK/patches/0007-Fix-xerbla-and-ilaenv.patch b/packages/CLAPACK/patches/0007-Fix-xerbla-and-ilaenv.patch deleted file mode 100644 index 47863c73cdd..00000000000 --- a/packages/CLAPACK/patches/0007-Fix-xerbla-and-ilaenv.patch +++ /dev/null @@ -1,52 +0,0 @@ -From c0d2a69ac4e4b63c4f28fadb896581164a2e29d3 Mon Sep 17 00:00:00 2001 -From: Hood Chatham -Date: Fri, 18 Mar 2022 22:07:00 -0700 -Subject: [PATCH 7/7] Fix xerbla and ilaenv - -These functions take actual C strings as arguments. It is annoying -to patch fortran to pass C strings, so this adds a wrapper that -'converts' from a Fortran string. ---- - BLAS/SRC/xerbla.c | 6 +++++- - SRC/ilaenv.c | 6 ++++++ - 2 files changed, 11 insertions(+), 1 deletion(-) - -diff --git a/BLAS/SRC/xerbla.c b/BLAS/SRC/xerbla.c -index da1d7fd..a6b5ca4 100644 ---- a/BLAS/SRC/xerbla.c -+++ b/BLAS/SRC/xerbla.c -@@ -68,7 +68,7 @@ static integer c__1 = 1; - /* .. */ - /* .. Executable Statements .. */ - -- printf("** On entry to %6s, parameter number %2i had an illegal value\n", -+ printf("** On entry to %s, parameter number %2i had an illegal value\n", - srname, *info); - - -@@ -76,3 +76,7 @@ static integer c__1 = 1; - - return 0; - } /* xerbla_ */ -+ -+int xerblaf2py_(char *srname, integer *info, integer srnamelen){ -+ return xerbla_(srname, info); -+} -diff --git a/SRC/ilaenv.c b/SRC/ilaenv.c -index 9565433..b8d28a8 100644 ---- a/SRC/ilaenv.c -+++ b/SRC/ilaenv.c -@@ -652,3 +652,9 @@ L160: - /* End of ILAENV */ - - } /* ilaenv_ */ -+ -+integer ilaenvf2py_(integer *ispec, char *name__, char *opts, integer *n1, -+ integer *n2, integer *n3, integer *n4, int name_len, int opts_len) -+{ -+ return ilaenv_(ispec, name__, opts, n1, n2, n3, n4); -+} -\ No newline at end of file --- -2.25.1 - diff --git a/packages/gensim/meta.yaml b/packages/gensim/meta.yaml index 1783ca6b835..8529a9efbee 100644 --- a/packages/gensim/meta.yaml +++ b/packages/gensim/meta.yaml @@ -6,12 +6,21 @@ package: source: url: https://files.pythonhosted.org/packages/9a/3c/dd4351a2ef3a8fb19e26d6ccb928823fea53375de9d28b221f8cf0e53c8e/gensim-4.3.1.tar.gz sha256: 8b5f11c0e6a5308086b48e8f6841223a4fa1a37d513684612b7ee854b533015f + patches: + - patches/0001-Avoid-signature-mismatch-in-sdot-detection.patch + requirements: run: - numpy - scipy - six - smart_open +build: + script: | + # gensim apparently builds from .c files so need to cythonize the .pyx after + # patching + cython gensim/models/word2vec_inner.pyx + about: home: http://radimrehurek.com/gensim PyPI: https://pypi.org/project/gensim diff --git a/packages/gensim/patches/0001-Avoid-signature-mismatch-in-sdot-detection.patch b/packages/gensim/patches/0001-Avoid-signature-mismatch-in-sdot-detection.patch new file mode 100644 index 00000000000..384d9e4beba --- /dev/null +++ b/packages/gensim/patches/0001-Avoid-signature-mismatch-in-sdot-detection.patch @@ -0,0 +1,45 @@ +From 2c816f54d3a6b056f42b97ad646789e9fe31a670 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= +Date: Thu, 6 Apr 2023 17:52:34 +0200 +Subject: [PATCH] Avoid signature mismatch in sdot detection. + +In Pyodide, OpenBLAS sdot returns float so use it rather than trying +to adapt the somewhat tricky gensim logic. +--- + gensim/models/word2vec_inner.pyx | 20 +++----------------- + 1 file changed, 3 insertions(+), 17 deletions(-) + +diff --git a/gensim/models/word2vec_inner.pyx b/gensim/models/word2vec_inner.pyx +index 1c0807ee..3d4a6847 100755 +--- a/gensim/models/word2vec_inner.pyx ++++ b/gensim/models/word2vec_inner.pyx +@@ -939,23 +939,9 @@ def init(): + EXP_TABLE[i] = (EXP_TABLE[i] / (EXP_TABLE[i] + 1)) + LOG_TABLE[i] = log( EXP_TABLE[i] ) + +- # check whether sdot returns double or float +- d_res = dsdot(&size, x, &ONE, y, &ONE) +- p_res = &d_res +- if abs(d_res - expected) < 0.0001: +- our_dot = our_dot_double +- our_saxpy = saxpy +- return 0 # double +- elif abs(p_res[0] - expected) < 0.0001: +- our_dot = our_dot_float +- our_saxpy = saxpy +- return 1 # float +- else: +- # neither => use cython loops, no BLAS +- # actually, the BLAS is so messed up we'll probably have segfaulted above and never even reach here +- our_dot = our_dot_noblas +- our_saxpy = our_saxpy_noblas +- return 2 ++ our_dot = our_dot_float ++ our_saxpy = saxpy ++ return 1 # float + + FAST_VERSION = init() # initialize the module + MAX_WORDS_IN_BATCH = MAX_SENTENCE_LEN +-- +2.34.1 + diff --git a/packages/CLAPACK/make.inc b/packages/libf2c/make.inc similarity index 100% rename from packages/CLAPACK/make.inc rename to packages/libf2c/make.inc diff --git a/packages/CLAPACK/meta.yaml b/packages/libf2c/meta.yaml similarity index 51% rename from packages/CLAPACK/meta.yaml rename to packages/libf2c/meta.yaml index 14e05d2e5df..6197a386d84 100644 --- a/packages/CLAPACK/meta.yaml +++ b/packages/libf2c/meta.yaml @@ -1,24 +1,29 @@ +# We still download the full CLAPACK but we are only using the libf2c part of CLAPACK. +# libf2c part is needed for the f2ced Fortran files in scipy for example to +# define things like pow_dd, i_len, etc... +# +# Note f2clib package only creates f2clib.a, and f2clib.a symbols are added to +# libopenblas.so in the OpenBLAS meta.yaml. package: - name: CLAPACK - version: 3.2.1 + name: libf2c + version: CLAPACK-3.2.1 source: sha256: 6dc4c382164beec8aaed8fd2acc36ad24232c406eda6db462bd4c41d5e455fac url: http://www.netlib.org/clapack/clapack.tgz extract_dir: CLAPACK-3.2.1 patches: - - patches/0001-add-missing-import.patch - - patches/0002-fix-arith.h.patch - - patches/0003-lapack-install-make.patch - - patches/0004-fix-f2clibs-build.patch - - patches/0005-remove-redundant-symbols.patch - - patches/0006-correct-return-types.patch - - patches/0007-Fix-xerbla-and-ilaenv.patch + - patches/0001-fix-arith.h.patch + - patches/0002-fix-f2clibs-build.patch + - patches/0003-remove-redundant-symbols.patch + - patches/0004-correct-return-types.patch + - patches/0005-Remove-symbols-defined-in-OpenBLAS.patch + extras: - [make.inc, make.inc] build: - type: shared_library + type: static_library script: | # The archive's contents have default permission 0750. If we use docker # to build, then we will not own the contents in the host, which means @@ -32,8 +37,7 @@ build: sed -i 's/^ ar /^ $(ARCH)/' **/Makefile sed -i 's/^ ld /^ $(LD)/' **/Makefile - emmake make -j ${PYODIDE_JOBS:-3} blaslib lapacklib - emcc blas_WA.a lapack_WA.a F2CLIBS/libf2c.a ${SIDE_MODULE_LDFLAGS} -o ${DISTDIR}/clapack_all.so + emmake make -j ${PYODIDE_JOBS:-3} f2clib mkdir -p ${WASM_LIBRARY_DIR}/{lib,include} - cp -r INCLUDE/* ${WASM_LIBRARY_DIR}/include - cp ${DISTDIR}/clapack_all.so ${WASM_LIBRARY_DIR}/lib + cp INCLUDE/f2c.h ${WASM_LIBRARY_DIR}/include + cp F2CLIBS/libf2c.a ${WASM_LIBRARY_DIR}/lib diff --git a/packages/CLAPACK/patches/0002-fix-arith.h.patch b/packages/libf2c/patches/0001-fix-arith.h.patch similarity index 96% rename from packages/CLAPACK/patches/0002-fix-arith.h.patch rename to packages/libf2c/patches/0001-fix-arith.h.patch index 9ec143ed842..7773825ac46 100644 --- a/packages/CLAPACK/patches/0002-fix-arith.h.patch +++ b/packages/libf2c/patches/0001-fix-arith.h.patch @@ -1,7 +1,7 @@ From 01990867ee7a641078505efba367a413a97f7802 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 18 Mar 2022 19:59:25 -0700 -Subject: [PATCH 2/7] fix arith.h +Subject: [PATCH 1/5] fix arith.h arith.h is a file generated at build time by compiling and running a C program. Since we use emscripten to build throughout, the C program becomes a wasm file diff --git a/packages/CLAPACK/patches/0004-fix-f2clibs-build.patch b/packages/libf2c/patches/0002-fix-f2clibs-build.patch similarity index 96% rename from packages/CLAPACK/patches/0004-fix-f2clibs-build.patch rename to packages/libf2c/patches/0002-fix-f2clibs-build.patch index 1d1b1e5467a..89d94e5d6a2 100644 --- a/packages/CLAPACK/patches/0004-fix-f2clibs-build.patch +++ b/packages/libf2c/patches/0002-fix-f2clibs-build.patch @@ -1,7 +1,7 @@ From d88133066f9f6312145c1186116fdb6446d3f7a5 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 18 Mar 2022 20:00:51 -0700 -Subject: [PATCH 4/7] fix f2clibs build +Subject: [PATCH 2/5] fix f2clibs build emscripten produces LLVM bitcode here, not genuine object files, so it doesn't make sense to strip symbols. diff --git a/packages/CLAPACK/patches/0005-remove-redundant-symbols.patch b/packages/libf2c/patches/0003-remove-redundant-symbols.patch similarity index 95% rename from packages/CLAPACK/patches/0005-remove-redundant-symbols.patch rename to packages/libf2c/patches/0003-remove-redundant-symbols.patch index 25ccf8f4fdc..bfd7257f7ec 100644 --- a/packages/CLAPACK/patches/0005-remove-redundant-symbols.patch +++ b/packages/libf2c/patches/0003-remove-redundant-symbols.patch @@ -1,7 +1,7 @@ From 78ff0cec961d9eb4e94193995fe151e1ecdae9df Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Fri, 18 Mar 2022 20:01:39 -0700 -Subject: [PATCH 5/7] remove redundant symbols +Subject: [PATCH 3/5] remove redundant symbols Remove a few symbols from LAPACK that are redundantly defined with BLAS or are ported in scipy. It wouldn't be an issue if we were linking dynamically, but diff --git a/packages/CLAPACK/patches/0006-correct-return-types.patch b/packages/libf2c/patches/0004-correct-return-types.patch similarity index 98% rename from packages/CLAPACK/patches/0006-correct-return-types.patch rename to packages/libf2c/patches/0004-correct-return-types.patch index 726664c4c1d..5d95f7050b1 100644 --- a/packages/CLAPACK/patches/0006-correct-return-types.patch +++ b/packages/libf2c/patches/0004-correct-return-types.patch @@ -1,7 +1,7 @@ From 572a3e20ba040b4f29bbef97a9db6658c10077d3 Mon Sep 17 00:00:00 2001 From: Joe Marshall Date: Fri, 18 Mar 2022 20:02:42 -0700 -Subject: [PATCH 6/7] correct return types +Subject: [PATCH 4/5] correct return types Make return types to fortran subroutines consistently be int. Some functions are defined within clapack as variously void and int return. Normal C compilers don't care, but emscripten is strict about return values. diff --git a/packages/libf2c/patches/0005-Remove-symbols-defined-in-OpenBLAS.patch b/packages/libf2c/patches/0005-Remove-symbols-defined-in-OpenBLAS.patch new file mode 100644 index 00000000000..7dce211b0b3 --- /dev/null +++ b/packages/libf2c/patches/0005-Remove-symbols-defined-in-OpenBLAS.patch @@ -0,0 +1,27 @@ +From eaf5c5db6e956036869255cb51831e720474d01d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= +Date: Fri, 7 Apr 2023 15:20:18 +0200 +Subject: [PATCH 5/5] Remove symbols defined in OpenBLAS + +--- + F2CLIBS/libf2c/Makefile | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/F2CLIBS/libf2c/Makefile b/F2CLIBS/libf2c/Makefile +index 57eff0d..136050f 100644 +--- a/F2CLIBS/libf2c/Makefile ++++ b/F2CLIBS/libf2c/Makefile +@@ -31,8 +31,8 @@ MISC = f77vers.o i77vers.o main.o s_rnge.o abort_.o exit_.o getarg_.o iargc_.o\ + getenv_.o signal_.o s_stop.o s_paus.o system_.o cabs.o ctype.o\ + derf_.o derfc_.o erf_.o erfc_.o sig_die.o uninit.o + POW = pow_ci.o pow_dd.o pow_di.o pow_hh.o pow_ii.o pow_ri.o pow_zi.o pow_zz.o +-CX = c_abs.o c_cos.o c_div.o c_exp.o c_log.o c_sin.o c_sqrt.o +-DCX = z_abs.o z_cos.o z_div.o z_exp.o z_log.o z_sin.o z_sqrt.o ++CX = c_cos.o c_div.o c_exp.o c_log.o c_sin.o c_sqrt.o ++DCX = z_cos.o z_div.o z_exp.o z_log.o z_sin.o z_sqrt.o + REAL = r_abs.o r_acos.o r_asin.o r_atan.o r_atn2.o r_cnjg.o r_cos.o\ + r_cosh.o r_dim.o r_exp.o r_imag.o r_int.o\ + r_lg10.o r_log.o r_mod.o r_nint.o r_sign.o\ +-- +2.34.1 + diff --git a/packages/openblas/meta.yaml b/packages/openblas/meta.yaml new file mode 100644 index 00000000000..3b5dd6ae515 --- /dev/null +++ b/packages/openblas/meta.yaml @@ -0,0 +1,44 @@ +package: + name: openblas + version: 0.3.23 + +source: + sha256: 5d9491d07168a5d00116cdc068a40022c3455bf9293c7cb86a65b1054d7e5114 + url: https://github.com/xianyi/OpenBLAS/releases/download/v0.3.23/OpenBLAS-0.3.23.tar.gz + patches: + - patches/0001-Add-Wno-return-type-flag.patch + - patches/0002-Align-xerbla_array-signature-with-scipy-expectation.patch + +build: + type: shared_library + script: | + # seems like .zip does not maintain executable flags, need to reset these + chmod u+x c_check + chmod u+x f_check + chmod u+x exports/gensymbol + # Replace void returns by int returns + sed -ri 's/void(\s+)BLASFUNC/int\1BLASFUNC/g' common_interface.h + sed -ri 's/void(\s+)cblas_/int\1cblas_/g' cblas.h ctest/*.c + sed -ri 's/void(\s+)(C?NAME)/int\1\2/g' interface/*.c + sed -ri 's/((extern)?.+) void ([a-z0-9]+_)/\1\2 int \3/g' lapack-netlib/SRC/*.c \ + lapack-netlib/SRC/DEPRECATED/*.c + # For some functions (mostly handling complex I think) f2c actually + # generate a function that returns void so I need to revert the void to int + # change the previous line does. + sed -ri 's@int ([cz](dotc|dotu|ladiv))@void \1@g' lapack-netlib/SRC/*.c\ + lapack-netlib/SRC/DEPRECATED/*.c + + make libs shared CC=emcc HOSTCC=gcc TARGET=RISCV64_GENERIC NOFORTRAN=1 NO_LAPACKE=1 \ + USE_THREAD=0 LDFLAGS="${SIDE_MODULE_LDFLAGS}" + mkdir -p dist + # Add libf2c symbols to libopenblas.so + emcc ${WASM_LIBRARY_DIR}/lib/libf2c.a libopenblas.a ${SIDE_MODULE_LDFLAGS} \ + -o libopenblas.so + + cp libopenblas.so dist + mkdir -p ${WASM_LIBRARY_DIR}/lib + cp dist/libopenblas.so ${WASM_LIBRARY_DIR}/lib + +requirements: + host: + - libf2c diff --git a/packages/openblas/patches/0001-Add-Wno-return-type-flag.patch b/packages/openblas/patches/0001-Add-Wno-return-type-flag.patch new file mode 100644 index 00000000000..ae57a81af31 --- /dev/null +++ b/packages/openblas/patches/0001-Add-Wno-return-type-flag.patch @@ -0,0 +1,29 @@ +From 09fd1aa0aa6a98e1cebaa6e34fca1e424dab8f48 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= +Date: Fri, 9 Dec 2022 16:40:13 +0100 +Subject: [PATCH 1/2] Add -Wno-return-type flag + +This is needed because we are changing many signatures to return int instead of +void with some regex expressions but we are not modifying the returned value + which would potentially be a lot more tricky. + +--- + Makefile.rule | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile.rule b/Makefile.rule +index 5f787a9c..6890046a 100644 +--- a/Makefile.rule ++++ b/Makefile.rule +@@ -228,7 +228,7 @@ NO_AFFINITY = 1 + # Common Optimization Flag; + # The default -O2 is enough. + # Flags for POWER8 are defined in Makefile.power. Don't modify COMMON_OPT +-# COMMON_OPT = -O2 ++COMMON_OPT = -O2 -Wno-return-type + + # gfortran option for LAPACK to improve thread-safety + # It is enabled by default in Makefile.system for gfortran +-- +2.34.1 + diff --git a/packages/openblas/patches/0002-Align-xerbla_array-signature-with-scipy-expectation.patch b/packages/openblas/patches/0002-Align-xerbla_array-signature-with-scipy-expectation.patch new file mode 100644 index 00000000000..d7ba240d6c4 --- /dev/null +++ b/packages/openblas/patches/0002-Align-xerbla_array-signature-with-scipy-expectation.patch @@ -0,0 +1,25 @@ +From fb8f9ec54121a889783cce3d42ea841cc513a22e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= +Date: Fri, 7 Apr 2023 10:27:59 +0200 +Subject: [PATCH 2/2] Align xerbla_array signature with scipy expectation + +--- + lapack-netlib/SRC/xerbla_array.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lapack-netlib/SRC/xerbla_array.c b/lapack-netlib/SRC/xerbla_array.c +index fe7d6d898..74d3ca96a 100644 +--- a/lapack-netlib/SRC/xerbla_array.c ++++ b/lapack-netlib/SRC/xerbla_array.c +@@ -600,7 +600,7 @@ array.f"> */ + + /* ===================================================================== */ + /* Subroutine */ void xerbla_array_(char *srname_array__, integer * +- srname_len__, integer *info, integer srname_array_len) ++ srname_len__, integer *info) + { + /* System generated locals */ + integer i__1, i__2, i__3; +-- +2.34.1 + diff --git a/packages/scipy/info.md b/packages/scipy/info.md index a003415fcbb..97efdd05f8e 100644 --- a/packages/scipy/info.md +++ b/packages/scipy/info.md @@ -3,44 +3,13 @@ fortran to wasm compiler. Some version of flang classic might work. Instead of compiling from fortran directly, we rely on f2c to cross compile the code to C and then compile C to wasm. We rely on f2c both directly and via -CLAPACK which is f2c'd LAPACK. +OpenBLAS which has f2c'd its Fortran files and then modified the generated C +files by hand. -Unfortunately, f2c only handles fortran 77 code and it doesn't work perfectly -even on that. After LAPACK version 3.2 (released in 2008), LAPACK started -adding methods that use newer fortran features, so they cannot be f2c'd. Hence -it's unlikely that new versions of CLAPACK will be released and we can't use -any newer version of CLAPACK. - -Scipy is built based on a newer version of CLAPACK and I couldn't figure out -how to remove the newer functions. They cause dynamic linking errors when -scipy is imported. To find the list of problem functions I used: - -```sh -wasm-objdump clapack_all.so -d | sed -n 's/.*func.*<\(.*\)>:/\1/p' | sort -u > clapack_exports.txt -``` - -to list the symbols exported from our clapack and - -``` -wasm-objdump _flapack.so -d | sed -E -n 's/.*global.get [0-9]* <([a-z]*_?)>/\1/p' | sort -u > symbols.txt -``` - -to list the symbols that `_flapack.so` expects to see. There are 36 symbols in -this list. Conveniently, LAPACK defines one function per file, so I just -download a copy of LAPACK and cat these functions into -`scipy/linalg/src/lapack_deprecations/cgegv.f` which is chosen arbitrarily from -the `.f` source files that are linked into `_flapack.so` (there aren't that many -options though). Using an existing file allows us to avoid fiddling with build -scripts. Of the 36 missing symbol, 32 of them are written in Fortran 77 and work -fine. The remaining 4 need removing but I couldn't figure out how to take them -out in any sensible way (I can't understand all the layers of codegen that -happen in scipy), so I give them do-nothing definitions, and then in the build -script remove lines containing them with `sed`. - -Another big problem with f2c is that it cannot handle implicit casts of function +A big problem with f2c is that it cannot handle implicit casts of function arguments, because it tries to guess the types of the arguments of the function -being called based on the types of the arguments at the call site. There are two -distinct versions of this: +being called based on the types of the arguments at the call site. There are +two distinct versions of this: 1. casts between number types -- we deal with this automatically in `fix_inconsistent_decls` in `_f2c_fixes.py` @@ -93,3 +62,20 @@ int str_len = 14; int some_lapack_func(int *some_string, int *some_string_length, fortranlen some_string_length_again); some_lapack_func("a string here", &str_len, 14); ``` + +When changing `packages/scipy/meta.yaml`, rebuilding scipy takes time, it can +be convenient to only build a few sub-packages to reduce iteration time. You +can add something like this to `packages/scipy/meta.yaml`: + +```bash +# Define which sub-packages to keep +TO_KEEP='linalg|sparse|_lib|_build_utils' +# Update scipy/setup.py +perl -pi -e "s@(config.add_subpackage\(')(?!$TO_KEEP)@# \1\2@" scipy/setup.py +# delete unwanted folders to avoid unneeded cythonization +folders_to_delete=$(find scipy -mindepth 1 -maxdepth 1 -type d | grep -vP "$TO_KEEP") +rm -rf $folders_to_delete +``` + +Building only `scipy.(linalg|sparse|_lib|_build_utils)` takes ~4 minutes on my +machine compared to ~10-15 minutes for a full scipy build. diff --git a/packages/scipy/meta.yaml b/packages/scipy/meta.yaml index d344dd1a899..9a2c8df8bc0 100644 --- a/packages/scipy/meta.yaml +++ b/packages/scipy/meta.yaml @@ -22,18 +22,19 @@ source: patches: - patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch - - patches/0002-loadDynamicLibrary-flapack.patch - - patches/0003-Add-lapack_extras-to-linalg-setup.py.patch - - patches/0004-int-to-string.patch - - patches/0005-fix-fotran-files-minpack.patch - - patches/0006-gemm_-no-const.patch - - patches/0007-make-int-return-values.patch - - patches/0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch - - patches/0009-sasum-returns-double-not-float.patch - - patches/0010-skip-fortran-fails-to-link.patch - - patches/0011-Change-qh_eachvoronoi_all-FILE-type.patch - - patches/0012-Remove-meson-requirements.patch - - patches/0013-Fix-fitpack.patch + - patches/0002-int-to-string.patch + - patches/0003-fix-fotran-files-minpack.patch + - patches/0004-gemm_-no-const.patch + - patches/0005-make-int-return-values.patch + - patches/0006-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch + - patches/0007-skip-fortran-fails-to-link.patch + - patches/0008-Change-qh_eachvoronoi_all-FILE-type.patch + - patches/0009-Remove-meson-requirements.patch + - patches/0010-Fix-fitpack.patch + # TODO remove the next patch when we upgrade to scipy 1.11, since it has + # been fixed upstream in https://github.com/scipy/scipy/pull/18124 + - patches/0011-When-forward-declaring-print_soln-give-it-the-correc.patch + - patches/0012-Enable-long-double-support-in-Boost-library-for-emsc.patch build: cflags: | @@ -53,24 +54,9 @@ build: script: | set -x export PKG_CONFIG_LIBDIR=$WASM_PKG_CONFIG_PATH - export NPY_BLAS_LIBS="-I$WASM_LIBRARY_DIR/include $WASM_LIBRARY_DIR/lib/clapack_all.so" - export NPY_LAPACK_LIBS="-I$WASM_LIBRARY_DIR/include" + export NPY_BLAS_LIBS="-I$WASM_LIBRARY_DIR/include $WASM_LIBRARY_DIR/lib/libopenblas.so" + export NPY_LAPACK_LIBS="-I$WASM_LIBRARY_DIR/include $WASM_LIBRARY_DIR/lib/libopenblas.so" - # We get linker errors because the following 36 functions are missing - # Copying them from a more recent LAPACK seems to work fine. - wget https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.0.tar.gz - tar xzf v3.10.0.tar.gz - cd lapack-3.10.0/SRC - - cat \ - cgemqrt.f cgeqrfp.f cgeqrt.f clahqr.f csyconv.f csyconvf.f csyconvf_rook.f ctpmqrt.f ctpqrt.f cuncsd.f \ - dgemqrt.f dgeqrfp.f dgeqrt.f dlahqr.f dsyconv.f dsyconvf.f dsyconvf_rook.f dtpmqrt.f dtpqrt.f dorcsd.f \ - sgemqrt.f sgeqrfp.f sgeqrt.f slahqr.f ssyconv.f ssyconvf.f ssyconvf_rook.f stpmqrt.f stpqrt.f sorcsd.f \ - zgemqrt.f zgeqrfp.f zgeqrt.f zlahqr.f zsyconv.f zsyconvf.f zsyconvf_rook.f ztpmqrt.f ztpqrt.f zuncsd.f \ - >> ../../scipy/linalg/lapack_extras.f - cd ../.. - sed -i 's/CHARACTER/INTEGER/g' scipy/linalg/lapack_extras.f - sed -i 's/RECURSIVE//g' scipy/linalg/lapack_extras.f sed -i 's/recursive //g' scipy/integrate/quadpack/* scipy/interpolate/fitpack/* # Change many functions that return void into functions that return int @@ -86,6 +72,13 @@ build: sed -i 's/void/int/g' scipy/linalg/cython_blas_signatures.txt sed -i 's/^void/int/g' scipy/interpolate/src/_fitpackmodule.c + sed -i 's/extern void/extern int/g' scipy/sparse/linalg/_dsolve/SuperLU/SRC/*.{c,h} + sed -i 's/PUBLIC void/PUBLIC int/g' scipy/sparse/linalg/_dsolve/SuperLU/SRC/*.{c,h} + sed -i 's/^void/int/g' scipy/sparse/linalg/_dsolve/SuperLU/SRC/*.{c,h} + sed -i 's/^void/int/g' scipy/sparse/linalg/_dsolve/*.{c,h} + sed -i 's/void \(.\)print/int \1/g' scipy/sparse/linalg/_dsolve/SuperLU/SRC/*.{c,h} + sed -i 's/TYPE_GENERIC_FUNC(\(.*\), void)/TYPE_GENERIC_FUNC(\1, int)/g' scipy/sparse/linalg/_dsolve/_superluobject.h + sed -i 's/^void/int/g' scipy/optimize/_trlib/trlib_private.h sed -i 's/^void/int/g' scipy/optimize/_trlib/trlib/trlib_private.h sed -i 's/, int)/)/g' scipy/optimize/_trlib/trlib_private.h @@ -95,15 +88,9 @@ build: sed -i 's/, size_t)/)/g' scipy/spatial/qhull_misc.h sed -i 's/,1)/)/g' scipy/spatial/qhull_misc.h - - # Missing declaration from cython_lapack_signatures.txt - echo "void ilaenv(int *ispec, char *name, char *opts, int *n1, int *n2, int *n3, int *n4)" \ - >> scipy/linalg/cython_lapack_signatures.txt - - # sed -i 's/^void/int/g' scipy/linalg/cython_lapack_signatures.txt - # Input error causes "duplicate symbol" linker errors. Empty out the file. echo "" > scipy/sparse/linalg/_dsolve/SuperLU/SRC/input_error.c + cross-build-env: true cross-build-files: - scipy/linalg/cython_lapack.pxd @@ -112,11 +99,11 @@ build: requirements: host: - numpy - - CLAPACK + - openblas - boost-cpp run: - numpy - - CLAPACK + - openblas executable: - gfortran - f2c diff --git a/packages/scipy/patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch b/packages/scipy/patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch index b27aeca2e0d..2743c38b2db 100644 --- a/packages/scipy/patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch +++ b/packages/scipy/patches/0001-Fix-dstevr-in-special-lapack_defs.h.patch @@ -1,7 +1,7 @@ -From fe4c4b02c8d10a90c2429c7c810a70ee43599093 Mon Sep 17 00:00:00 2001 +From 84604f05776d4009a76f3b4374a2d6e7eaefc002 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Fri, 18 Mar 2022 16:25:39 -0700 -Subject: [PATCH 01/13] Fix dstevr in special/lapack_defs.h +Subject: [PATCH 01/11] Fix dstevr in special/lapack_defs.h --- scipy/special/lapack_defs.h | 5 ++--- @@ -28,5 +28,5 @@ index 0d20ba1ca..d4325f71f 100644 + w, z, ldz, isuppz, work, lwork, iwork, liwork, info); } -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0004-int-to-string.patch b/packages/scipy/patches/0002-int-to-string.patch similarity index 90% rename from packages/scipy/patches/0004-int-to-string.patch rename to packages/scipy/patches/0002-int-to-string.patch index 72523e7b5e4..f62bf5e1331 100644 --- a/packages/scipy/patches/0004-int-to-string.patch +++ b/packages/scipy/patches/0002-int-to-string.patch @@ -1,7 +1,7 @@ -From eddf5376081e252243c2a764da4d6fa60ca114f0 Mon Sep 17 00:00:00 2001 +From 5351793996e155d6896a778638620b18d0654bfe Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 25 Dec 2021 18:04:18 -0800 -Subject: [PATCH 04/13] int to string +Subject: [PATCH 02/11] int to string f2c does not handle implicit casts of function arguments correctly. The msg argument of `xerrwv` is defined to be an `int *`, and then implicitly cast @@ -25,5 +25,5 @@ index 7e180e4f8..b940bb702 100644 double precision r1, r2 dimension msg(nmes) -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0002-loadDynamicLibrary-flapack.patch b/packages/scipy/patches/0002-loadDynamicLibrary-flapack.patch deleted file mode 100644 index ddafaf31739..00000000000 --- a/packages/scipy/patches/0002-loadDynamicLibrary-flapack.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 5643097cd0f9cb0e0b9cd7e9d636a3ca04a09deb Mon Sep 17 00:00:00 2001 -From: Hood Chatham -Date: Sat, 2 Apr 2022 14:20:25 -0700 -Subject: [PATCH 02/13] loadDynamicLibrary flapack - -We are using CLAPACK for our LAPACK, but CLAPACK only supports -LAPACK v3.2 since starting in v3.3 LAPACK started adding fortran -code from Fortran standards more recent that 1990 and f2c only -supports Fortran '90. Scipy uses some functions that were added -in LAPACK v3.4, but all of these are Fortran 77 compliant and so -we *can* f2c them. In scipy/meta.yaml we inject these into -`lapack_extras.f` which gets built into `_flapack.so`. - -Why do we do it this way? It was the first thing I tried that -worked and I was so exhausted that I didn't have the energy to be -bothered by the hack. Ideally we would copy these into our CLAPACK -but CLAPACK is the result of hand modified f2c output. (In fact -this is how f2c was always intended to be used, the output is not -good C code by itself.) We are automating the patches that are -necessary in `_f2c_fixes.py`, but these don't get applied to CLAPACK. - -Anyways, the issue is that CLAPACK is loaded as a "shared library" -which means that we call `loadDynamicLibrary` on it so that all of -its symbols are globally scoped (as opposed to needing to manually -look them up with `dlsym`). Scipy is not loaded this way. But we -need the `lapack_extras.f` symbols to have this global visibility. -So we have to call loadDynamicLibrary on it, hence this patch. ---- - scipy/linalg/lapack.py | 11 +++++++++++ - 1 file changed, 11 insertions(+) - -diff --git a/scipy/linalg/lapack.py b/scipy/linalg/lapack.py -index d4427d044..05ba6aacd 100644 ---- a/scipy/linalg/lapack.py -+++ b/scipy/linalg/lapack.py -@@ -800,6 +800,17 @@ All functions - ilaver - - """ -+ -+import sysconfig -+import pyodide_js -+from site import getsitepackages -+ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") -+pyodide_js._module.loadDynamicLibrary(f'{getsitepackages()[0]}/scipy/linalg/_flapack{ext_suffix}') -+del getsitepackages -+del pyodide_js -+del sysconfig -+del ext_suffix -+ - # - # Author: Pearu Peterson, March 2002 - # --- -2.25.1 - diff --git a/packages/scipy/patches/0003-Add-lapack_extras-to-linalg-setup.py.patch b/packages/scipy/patches/0003-Add-lapack_extras-to-linalg-setup.py.patch deleted file mode 100644 index 20fd87ccb0f..00000000000 --- a/packages/scipy/patches/0003-Add-lapack_extras-to-linalg-setup.py.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 4ea72561b468d3e942e3a910edde2aba5aec69b0 Mon Sep 17 00:00:00 2001 -From: Hood Chatham -Date: Fri, 31 Dec 2021 22:27:07 -0800 -Subject: [PATCH 03/13] Add lapack_extras to linalg/setup.py - ---- - scipy/linalg/setup.py | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/scipy/linalg/setup.py b/scipy/linalg/setup.py -index b84085a7c..20192f4cf 100644 ---- a/scipy/linalg/setup.py -+++ b/scipy/linalg/setup.py -@@ -43,7 +43,7 @@ def configuration(parent_package='', top_path=None): - ext._pre_build_hook = blas_ilp64_pre_build_hook(lapack_ilp64_opt) - - # flapack: -- sources = ['flapack.pyf.src'] -+ sources = ['flapack.pyf.src', 'lapack_extras.f'] - sources += get_g77_abi_wrappers(lapack_opt) - depends = ['flapack_gen.pyf.src', - 'flapack_gen_banded.pyf.src', --- -2.25.1 - diff --git a/packages/scipy/patches/0005-fix-fotran-files-minpack.patch b/packages/scipy/patches/0003-fix-fotran-files-minpack.patch similarity index 98% rename from packages/scipy/patches/0005-fix-fotran-files-minpack.patch rename to packages/scipy/patches/0003-fix-fotran-files-minpack.patch index 988a5f5e180..5ea82305688 100644 --- a/packages/scipy/patches/0005-fix-fotran-files-minpack.patch +++ b/packages/scipy/patches/0003-fix-fotran-files-minpack.patch @@ -1,7 +1,7 @@ -From 03121dd29a0973ef05f9921ddf2c99cf14f3299a Mon Sep 17 00:00:00 2001 +From 6b2e65c86858f3534058b2200f12c6d7b840bf7f Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 6 Apr 2022 21:21:53 -0700 -Subject: [PATCH 05/13] fix fotran files minpack +Subject: [PATCH 03/11] fix fotran files minpack --- scipy/optimize/minpack/chkder.f | 3 +-- @@ -283,5 +283,5 @@ index 61a7928bb..05282b556 100644 double precision alpha double precision r(ldr,n),w(n),b(n),cos(n),sin(n) -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0006-gemm_-no-const.patch b/packages/scipy/patches/0004-gemm_-no-const.patch similarity index 97% rename from packages/scipy/patches/0006-gemm_-no-const.patch rename to packages/scipy/patches/0004-gemm_-no-const.patch index 625f92d2cf9..0f126d90d2d 100644 --- a/packages/scipy/patches/0006-gemm_-no-const.patch +++ b/packages/scipy/patches/0004-gemm_-no-const.patch @@ -1,7 +1,7 @@ -From a64ba2bc0b4e8ee505de52d08c5d597ed040ba0c Mon Sep 17 00:00:00 2001 +From 4e75c3153b266ae63d42a032cbc558d143bee3c9 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 18 Dec 2021 11:41:15 -0800 -Subject: [PATCH 06/13] gemm_ no const +Subject: [PATCH 04/11] gemm_ no const cgemm, dgemm, sgemm, and zgemm are declared with `const` in slu_cdefs.h, but other places don't have the cosnt causing compile errors. @@ -82,5 +82,5 @@ index abb7d937e..6c572ff2b 100644 doublecomplex*, int*); extern int ztrsm_(char*, char*, char*, char*, int*, int*, -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0007-make-int-return-values.patch b/packages/scipy/patches/0005-make-int-return-values.patch similarity index 58% rename from packages/scipy/patches/0007-make-int-return-values.patch rename to packages/scipy/patches/0005-make-int-return-values.patch index ed189f98542..0fa6e0850d6 100644 --- a/packages/scipy/patches/0007-make-int-return-values.patch +++ b/packages/scipy/patches/0005-make-int-return-values.patch @@ -1,7 +1,7 @@ -From 6e18c5b404f4c238890c1591d118f9cefd7d8c51 Mon Sep 17 00:00:00 2001 +From bf08421e892aa528c5f89fcb94f75fe7eb41f0c3 Mon Sep 17 00:00:00 2001 From: Joe Marshall Date: Wed, 6 Apr 2022 21:25:13 -0700 -Subject: [PATCH 07/13] make int return values +Subject: [PATCH 05/11] make int return values The return values of f2c functions are insignificant in most cases, so often it is treated as returning void, when it really should return int (values are @@ -21,34 +21,21 @@ emscripten is very strict about void vs int returns and function signatures, so we change everything to return int from subroutines, and signatures are altered to be consistent. --- - scipy/_build_utils/src/wrap_dummy_g77_abi.f | 16 ---- - scipy/integrate/_odepackmodule.c | 8 +- - scipy/linalg/fblas_l1.pyf.src | 78 +++++++++++++------ - scipy/linalg/setup.py | 1 + + scipy/_build_utils/src/wrap_dummy_g77_abi.f | 16 ----- + scipy/integrate/_odepackmodule.c | 8 +-- + scipy/linalg/fblas_l1.pyf.src | 62 ++++++++++++++----- scipy/odr/__odrpack.c | 2 +- scipy/optimize/_lsq/setup.py | 2 +- - .../linalg/_dsolve/SuperLU/SRC/cgsrfs.c | 7 -- - .../linalg/_dsolve/SuperLU/SRC/dgscon.c | 3 - - .../linalg/_dsolve/SuperLU/SRC/dgsrfs.c | 7 -- - .../_dsolve/SuperLU/SRC/ilu_ccopy_to_ucol.c | 2 - - .../_dsolve/SuperLU/SRC/ilu_cdrop_row.c | 9 --- - .../_dsolve/SuperLU/SRC/ilu_dcopy_to_ucol.c | 1 - - .../_dsolve/SuperLU/SRC/ilu_ddrop_row.c | 7 -- + .../_dsolve/SuperLU/SRC/ilu_cdrop_row.c | 8 +-- .../_dsolve/SuperLU/SRC/ilu_scopy_to_ucol.c | 2 +- - .../_dsolve/SuperLU/SRC/ilu_sdrop_row.c | 7 -- - .../_dsolve/SuperLU/SRC/ilu_zcopy_to_ucol.c | 1 - - .../_dsolve/SuperLU/SRC/ilu_zdrop_row.c | 9 --- - .../_dsolve/SuperLU/SRC/scipy_slu_config.h | 8 ++ - .../linalg/_dsolve/SuperLU/SRC/sgsrfs.c | 7 -- - .../linalg/_dsolve/SuperLU/SRC/sgssvx.c | 7 +- + .../_dsolve/SuperLU/SRC/scipy_slu_config.h | 3 + + .../linalg/_dsolve/SuperLU/SRC/sgssvx.c | 7 ++- .../linalg/_dsolve/SuperLU/SRC/slu_dcomplex.h | 5 +- .../linalg/_dsolve/SuperLU/SRC/slu_scomplex.h | 5 +- - .../linalg/_dsolve/SuperLU/SRC/slu_util.h | 1 - - .../linalg/_dsolve/SuperLU/SRC/zgsrfs.c | 7 -- scipy/sparse/linalg/_dsolve/_superlu_utils.c | 4 +- - .../linalg/_eigen/arpack/ARPACK/SRC/debug.h | 20 ++--- - .../linalg/_eigen/arpack/ARPACK/SRC/stat.h | 26 +++---- - 27 files changed, 108 insertions(+), 144 deletions(-) + .../linalg/_eigen/arpack/ARPACK/SRC/debug.h | 20 +++--- + .../linalg/_eigen/arpack/ARPACK/SRC/stat.h | 26 ++++---- + 14 files changed, 96 insertions(+), 74 deletions(-) diff --git a/scipy/_build_utils/src/wrap_dummy_g77_abi.f b/scipy/_build_utils/src/wrap_dummy_g77_abi.f index caf99ac63..73cdebd96 100644 @@ -119,10 +106,10 @@ index 2b2189f0b..17f3f9348 100644 { /* diff --git a/scipy/linalg/fblas_l1.pyf.src b/scipy/linalg/fblas_l1.pyf.src -index 89e50a990..0476e6a26 100644 +index 89e50a990..97095bdb2 100644 --- a/scipy/linalg/fblas_l1.pyf.src +++ b/scipy/linalg/fblas_l1.pyf.src -@@ -279,14 +279,16 @@ end subroutine axpy +@@ -279,10 +279,12 @@ end subroutine axpy function sdot(n,x,offx,incx,y,offy,incy) result (xy) ! Computes a vector-vector dot product. @@ -138,11 +125,6 @@ index 89e50a990..0476e6a26 100644 real dimension(*), intent(in) :: x real dimension(*), intent(in) :: y -- real sdot,xy -+ double precision sdot,xy - integer optional, intent(in),check(incx>0||incx<0) :: incx = 1 - integer optional, intent(in),check(incy>0||incy<0) :: incy = 1 - integer optional, intent(in),depend(x) :: offx=0 @@ -304,8 +306,12 @@ end function sdot function ddot(n,x,offx,incx,y,offy,incy) result (xy) ! Computes a vector-vector dot product. @@ -194,13 +176,9 @@ index 89e50a990..0476e6a26 100644 dimension(*),intent(in) :: x dimension(*),intent(in) :: y -@@ -379,10 +393,15 @@ end function dotc - - function nrm2(n,x,offx,incx) result(n2) +@@ -381,8 +395,12 @@ function nrm2(n,x,offx,incx) result(n2) -- nrm2, n2 -+ n2 -+ double precision nrm2 + nrm2, n2 - callstatement (*f2py_func)(&nrm2, &n,x+offx,&incx) - callprotoargument *,F_INT*,*,F_INT* @@ -213,30 +191,23 @@ index 89e50a990..0476e6a26 100644 dimension(*),intent(in) :: x -@@ -399,10 +418,14 @@ end function nrm2 - +@@ -400,9 +418,12 @@ end function nrm2 function nrm2(n,x,offx,incx) result(n2) -- nrm2, n2 + nrm2, n2 + callstatement nrm2_return_value=(*f2py_func)(&n,x+offx,&incx) + callprotoargument int*,*,int* - callstatement (*f2py_func)(&nrm2, &n,x+offx,&incx) - callprotoargument *,F_INT*,*,F_INT* -+ double precision nrm2 -+ n2 + fortranname F_FUNC(nrm2,NRM2) + ! This following line is to avoid Fortran wrappers - fix for CLAPACK + intent(c) nrm2 dimension(*),intent(in) :: x -@@ -417,14 +440,20 @@ function nrm2(n,x,offx,incx) result(n2) - end function nrm2 - - --function asum(n,x,offx,incx) result (s) -+function asum(n,x,offx,incx) result (d) +@@ -420,8 +441,12 @@ end function nrm2 + function asum(n,x,offx,incx) result (s) ! Computes the sum of magnitudes of the vector elements - callstatement (*f2py_func)(&asum,&n,x+offx,&incx) @@ -244,24 +215,14 @@ index 89e50a990..0476e6a26 100644 + callstatement asum_return_value=(*f2py_func)(&n,x+offx,&incx) + callprotoargument int*,*,int* + -+ double precision asum + fortranname F_FUNC(asum,ASUM) + ! This following line is to avoid Fortran wrappers - fix for CLAPACK + intent(c) asum dimension(*), intent(in) :: x -- asum,s -+ s -+ double precision asum - integer optional, intent(in), check(incx>0||incx<0) :: incx = 1 - integer optional, intent(in), depend(x) :: offx=0 - check(offx>=0 && offxasum(n,x,offx,incx) result (s) - end function asum - - --function asum(n,x,offx,incx) result (s) -+function asum(n,x,offx,incx) result (d) + asum,s +@@ -437,8 +462,13 @@ end function asum + function asum(n,x,offx,incx) result (s) ! Computes the sum of magnitudes of the vector elements - callstatement (*f2py_func)(&asum,&n,x+offx,&incx) @@ -276,18 +237,6 @@ index 89e50a990..0476e6a26 100644 dimension(*), intent(in) :: x asum,s -diff --git a/scipy/linalg/setup.py b/scipy/linalg/setup.py -index 20192f4cf..55a23ba7f 100644 ---- a/scipy/linalg/setup.py -+++ b/scipy/linalg/setup.py -@@ -45,6 +45,7 @@ def configuration(parent_package='', top_path=None): - # flapack: - sources = ['flapack.pyf.src', 'lapack_extras.f'] - sources += get_g77_abi_wrappers(lapack_opt) -+ - depends = ['flapack_gen.pyf.src', - 'flapack_gen_banded.pyf.src', - 'flapack_gen_tri.pyf.src', diff --git a/scipy/odr/__odrpack.c b/scipy/odr/__odrpack.c index c806e33fb..c4b822eb9 100644 --- a/scipy/odr/__odrpack.c @@ -314,120 +263,27 @@ index 7ce589c0c..6412886e0 100644 return config -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgsrfs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgsrfs.c -index a7dd2f8fd..3b2544d4f 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgsrfs.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgsrfs.c -@@ -171,13 +171,6 @@ cgsrfs(trans_t trans, SuperMatrix *A, SuperMatrix *L, SuperMatrix *U, - int isave[3]; - - extern int clacon2_(int *, complex *, complex *, float *, int *, int []); --#ifdef _CRAY -- extern int CCOPY(int *, complex *, int *, complex *, int *); -- extern int CSAXPY(int *, complex *, complex *, int *, complex *, int *); --#else -- extern int ccopy_(int *, complex *, int *, complex *, int *); -- extern int caxpy_(int *, complex *, complex *, int *, complex *, int *); --#endif - - Astore = A->Store; - Aval = Astore->nzval; -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgscon.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgscon.c -index d51f24c3b..b76dc7a78 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgscon.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgscon.c -@@ -92,10 +92,7 @@ dgscon(char *norm, SuperMatrix *L, SuperMatrix *U, - double *work; - int *iwork; - int isave[3]; -- extern int drscl_(int *, double *, double *, int *); -- - extern int dlacon2_(int *, double *, double *, int *, double *, int *, int []); -- - - /* Test the input parameters. */ - *info = 0; -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgsrfs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgsrfs.c -index d37226035..69f6bd8cf 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgsrfs.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgsrfs.c -@@ -171,13 +171,6 @@ dgsrfs(trans_t trans, SuperMatrix *A, SuperMatrix *L, SuperMatrix *U, - int isave[3]; - - extern int dlacon2_(int *, double *, double *, int *, double *, int *, int []); --#ifdef _CRAY -- extern int SCOPY(int *, double *, int *, double *, int *); -- extern int SSAXPY(int *, double *, double *, int *, double *, int *); --#else -- extern int dcopy_(int *, double *, int *, double *, int *); -- extern int daxpy_(int *, double *, double *, int *, double *, int *); --#endif - - Astore = A->Store; - Aval = Astore->nzval; -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ccopy_to_ucol.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ccopy_to_ucol.c -index 027b9260f..e1299bed2 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ccopy_to_ucol.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ccopy_to_ucol.c -@@ -26,8 +26,6 @@ at the top-level directory. - int num_drop_U; - #endif - --extern void ccopy_(int *, complex [], int *, complex [], int *); -- - #if 0 - static complex *A; /* used in _compare_ only */ - static int _compare_(const void *a, const void *b) diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_cdrop_row.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_cdrop_row.c -index 09b8a937d..fdd6064de 100644 +index 09b8a937d..5b725c825 100644 --- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_cdrop_row.c +++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_cdrop_row.c -@@ -23,15 +23,6 @@ at the top-level directory. +@@ -23,12 +23,12 @@ at the top-level directory. #include #include "slu_cdefs.h" -extern void cswap_(int *, complex [], int *, complex [], int *); -extern void caxpy_(int *, complex *, complex [], int *, complex [], int *); -extern void ccopy_(int *, complex [], int *, complex [], int *); --extern float scasum_(int *, complex *, int *); --extern float scnrm2_(int *, complex *, int *); ++extern int cswap_(int *, complex [], int *, complex [], int *); ++extern int caxpy_(int *, complex *, complex [], int *, complex [], int *); ++extern int ccopy_(int *, complex [], int *, complex [], int *); + extern float scasum_(int *, complex *, int *); + extern float scnrm2_(int *, complex *, int *); -extern void scopy_(int *, float [], int *, float [], int *); --extern double dnrm2_(int *, double [], int *); --extern int icamax_(int *, complex [], int *); -- - static float *A; /* used in _compare_ only */ - static int _compare_(const void *a, const void *b) - { -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_dcopy_to_ucol.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_dcopy_to_ucol.c -index 2bb889c39..658e7e71e 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_dcopy_to_ucol.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_dcopy_to_ucol.c -@@ -26,7 +26,6 @@ at the top-level directory. - int num_drop_U; - #endif - --extern void dcopy_(int *, double [], int *, double [], int *); ++extern int scopy_(int *, float [], int *, float [], int *); + extern double dnrm2_(int *, double [], int *); + extern int icamax_(int *, complex [], int *); - #if 0 - static double *A; /* used in _compare_ only */ -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ddrop_row.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ddrop_row.c -index f25b5085a..19afee76c 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ddrop_row.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_ddrop_row.c -@@ -23,13 +23,6 @@ at the top-level directory. - #include - #include "slu_ddefs.h" - --extern void dswap_(int *, double [], int *, double [], int *); --extern void daxpy_(int *, double *, double [], int *, double [], int *); --extern void dcopy_(int *, double [], int *, double [], int *); --extern double dasum_(int *, double *, int *); --extern double dnrm2_(int *, double *, int *); --extern double dnrm2_(int *, double [], int *); --extern int idamax_(int *, double [], int *); - - static double *A; /* used in _compare_ only */ - static int _compare_(const void *a, const void *b) diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_scopy_to_ucol.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_scopy_to_ucol.c index 6dc0460c1..994224c35 100644 --- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_scopy_to_ucol.c @@ -441,93 +297,20 @@ index 6dc0460c1..994224c35 100644 #if 0 static float *A; /* used in _compare_ only */ -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_sdrop_row.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_sdrop_row.c -index 836ee5450..8d1368838 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_sdrop_row.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_sdrop_row.c -@@ -23,13 +23,6 @@ at the top-level directory. - #include - #include "slu_sdefs.h" - --extern void sswap_(int *, float [], int *, float [], int *); --extern void saxpy_(int *, float *, float [], int *, float [], int *); --extern void scopy_(int *, float [], int *, float [], int *); --extern float sasum_(int *, float *, int *); --extern float snrm2_(int *, float *, int *); --extern double dnrm2_(int *, double [], int *); --extern int isamax_(int *, float [], int *); - - static float *A; /* used in _compare_ only */ - static int _compare_(const void *a, const void *b) -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zcopy_to_ucol.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zcopy_to_ucol.c -index e7847a37d..9c1f02e09 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zcopy_to_ucol.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zcopy_to_ucol.c -@@ -26,7 +26,6 @@ at the top-level directory. - int num_drop_U; - #endif - --extern void zcopy_(int *, doublecomplex [], int *, doublecomplex [], int *); - - #if 0 - static doublecomplex *A; /* used in _compare_ only */ -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zdrop_row.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zdrop_row.c -index 2de1226ef..362e18210 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zdrop_row.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/ilu_zdrop_row.c -@@ -23,15 +23,6 @@ at the top-level directory. - #include - #include "slu_zdefs.h" - --extern void zswap_(int *, doublecomplex [], int *, doublecomplex [], int *); --extern void zaxpy_(int *, doublecomplex *, doublecomplex [], int *, doublecomplex [], int *); --extern void zcopy_(int *, doublecomplex [], int *, doublecomplex [], int *); --extern double dzasum_(int *, doublecomplex *, int *); --extern double dznrm2_(int *, doublecomplex *, int *); --extern double dnrm2_(int *, double [], int *); --extern void dcopy_(int *, double [], int *, double [], int *); --extern int izamax_(int *, doublecomplex [], int *); -- - static double *A; /* used in _compare_ only */ - static int _compare_(const void *a, const void *b) - { diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/scipy_slu_config.h b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/scipy_slu_config.h -index 5afc93b5d..1a2c4ca36 100644 +index 5afc93b5d..7ac5f80fb 100644 --- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/scipy_slu_config.h +++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/scipy_slu_config.h -@@ -3,6 +3,14 @@ +@@ -3,6 +3,9 @@ #include -+#include"f2c.h" -+#define integer int -+#define logical int -+#include"clapack.h" -+#undef integer -+#undef logical ++#include "f2c.h" + + /* * Support routines */ -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgsrfs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgsrfs.c -index 5faab1dfb..7380eb6cc 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgsrfs.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgsrfs.c -@@ -171,13 +171,6 @@ sgsrfs(trans_t trans, SuperMatrix *A, SuperMatrix *L, SuperMatrix *U, - int isave[3]; - - extern int slacon2_(int *, float *, float *, int *, float *, int *, int []); --#ifdef _CRAY -- extern int SCOPY(int *, float *, int *, float *, int *); -- extern int SSAXPY(int *, float *, float *, int *, float *, int *); --#else -- extern int scopy_(int *, float *, int *, float *, int *); -- extern int saxpy_(int *, float *, float *, int *, float *, int *); --#endif - - Astore = A->Store; - Aval = Astore->nzval; diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgssvx.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgssvx.c index 7ee2e77ea..d13914e04 100644 --- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgssvx.c @@ -592,36 +375,6 @@ index 5c9aa7058..a10f9a52f 100644 /* Macro definitions */ -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slu_util.h b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slu_util.h -index 42bab985d..936db381d 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slu_util.h -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slu_util.h -@@ -398,7 +398,6 @@ extern int spcoletree (int *, int *, int *, int, int, int *); - extern int *TreePostorder (int, int *); - extern double SuperLU_timer_ (); - extern int sp_ienv (int); --extern int xerbla_ (char *, int *); - extern void ifill (int *, int, int); - extern void snode_profile (int, int *); - extern void super_stats (int, int *); -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgsrfs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgsrfs.c -index 02b63df30..71209b3b7 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgsrfs.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgsrfs.c -@@ -171,13 +171,6 @@ zgsrfs(trans_t trans, SuperMatrix *A, SuperMatrix *L, SuperMatrix *U, - int isave[3]; - - extern int zlacon2_(int *, doublecomplex *, doublecomplex *, double *, int *, int []); --#ifdef _CRAY -- extern int CCOPY(int *, doublecomplex *, int *, doublecomplex *, int *); -- extern int CSAXPY(int *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *); --#else -- extern int zcopy_(int *, doublecomplex *, int *, doublecomplex *, int *); -- extern int zaxpy_(int *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *); --#endif - - Astore = A->Store; - Aval = Astore->nzval; diff --git a/scipy/sparse/linalg/_dsolve/_superlu_utils.c b/scipy/sparse/linalg/_dsolve/_superlu_utils.c index 49b928a43..082268771 100644 --- a/scipy/sparse/linalg/_dsolve/_superlu_utils.c @@ -708,5 +461,5 @@ index 66a8e9f87..81d49c3bd 100644 +c & tcaupd, tcaup2, tcaitr, tceigh, tcgets, tcapps, tcconv, +c & tmvopx, tmvbx, tgetv0, titref, trvec -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch b/packages/scipy/patches/0006-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch similarity index 92% rename from packages/scipy/patches/0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch rename to packages/scipy/patches/0006-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch index 789334533f9..3d9a1385257 100644 --- a/packages/scipy/patches/0008-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch +++ b/packages/scipy/patches/0006-Rename-_page_trend_test.py-to-prevent-test-unvendori.patch @@ -1,7 +1,7 @@ -From 46026c40dc86c78c938da66e6671ed0d792d71c9 Mon Sep 17 00:00:00 2001 +From 1e579281a0aa97f19714f6b12c54bc3dc33d3fa5 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sun, 26 Dec 2021 07:34:40 -0800 -Subject: [PATCH 08/13] Rename _page_trend_test.py to prevent test unvendoring +Subject: [PATCH 06/11] Rename _page_trend_test.py to prevent test unvendoring unvendor_tests will unvendor any file that ends in _test.py. Prevent that by changing the name of this file. @@ -43,5 +43,5 @@ index dfac9e073..3c5cc673f 100644 '_relative_risk.py', '_resampling.py', -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0010-skip-fortran-fails-to-link.patch b/packages/scipy/patches/0007-skip-fortran-fails-to-link.patch similarity index 93% rename from packages/scipy/patches/0010-skip-fortran-fails-to-link.patch rename to packages/scipy/patches/0007-skip-fortran-fails-to-link.patch index 6f5a6ea8a1c..444ed7e4708 100644 --- a/packages/scipy/patches/0010-skip-fortran-fails-to-link.patch +++ b/packages/scipy/patches/0007-skip-fortran-fails-to-link.patch @@ -1,7 +1,7 @@ -From a9ade2b407968c0beea9a023189426f1d6e793ff Mon Sep 17 00:00:00 2001 +From 6f15df83c5945c9b2e65241bb38af8b71f57da52 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 25 Dec 2021 15:08:18 -0800 -Subject: [PATCH 10/13] skip fortran fails to link +Subject: [PATCH 07/11] skip fortran fails to link These are tests and they have both void vs int return value problems and implicit function argument cast problems. Not worth fixing for tests. @@ -42,5 +42,5 @@ index 0b936ceed..bf0c16d6c 100644 config.add_subpackage('matlab') config.add_subpackage('arff') -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0011-Change-qh_eachvoronoi_all-FILE-type.patch b/packages/scipy/patches/0008-Change-qh_eachvoronoi_all-FILE-type.patch similarity index 93% rename from packages/scipy/patches/0011-Change-qh_eachvoronoi_all-FILE-type.patch rename to packages/scipy/patches/0008-Change-qh_eachvoronoi_all-FILE-type.patch index 4df9a7ff01e..645c0830275 100644 --- a/packages/scipy/patches/0011-Change-qh_eachvoronoi_all-FILE-type.patch +++ b/packages/scipy/patches/0008-Change-qh_eachvoronoi_all-FILE-type.patch @@ -1,7 +1,7 @@ -From 0e75392a82b3b1ddc965895468e6c30ab973f6e9 Mon Sep 17 00:00:00 2001 +From 84d2f13dc36539f940785b11bd1a011a4f596bf6 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Mon, 29 Aug 2022 16:45:21 -0700 -Subject: [PATCH 11/13] Change qh_eachvoronoi_all FILE type +Subject: [PATCH 08/11] Change qh_eachvoronoi_all FILE type --- scipy/spatial/_qhull.pyx | 7 ++++--- @@ -47,5 +47,5 @@ index 8c9135adc..5726cc704 100644 cdef _Qhull qh = <_Qhull>ptr cdef int point_1, point_2, ix -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0012-Remove-meson-requirements.patch b/packages/scipy/patches/0009-Remove-meson-requirements.patch similarity index 85% rename from packages/scipy/patches/0012-Remove-meson-requirements.patch rename to packages/scipy/patches/0009-Remove-meson-requirements.patch index 63da4fed3d3..d869244a5ff 100644 --- a/packages/scipy/patches/0012-Remove-meson-requirements.patch +++ b/packages/scipy/patches/0009-Remove-meson-requirements.patch @@ -1,7 +1,7 @@ -From aa142aa7b08399ec6346f94a1a92b0e1b915b933 Mon Sep 17 00:00:00 2001 +From 08f0d9aa483d4edf5a86b2bc822af6686265c344 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 30 Aug 2022 10:58:25 -0700 -Subject: [PATCH 12/13] Remove meson requirements +Subject: [PATCH 09/11] Remove meson requirements --- pyproject.toml | 5 ++--- @@ -25,5 +25,5 @@ index 6dc1d4070..f09cd3138 100644 "pythran>=0.9.12,<0.13.0", # `wheel` is needed for non-isolated builds, given that `meson-python` -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0009-sasum-returns-double-not-float.patch b/packages/scipy/patches/0009-sasum-returns-double-not-float.patch deleted file mode 100644 index 88021927751..00000000000 --- a/packages/scipy/patches/0009-sasum-returns-double-not-float.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 751a1b0b2e5d1734eaf5d477a54a9a90b7944daa Mon Sep 17 00:00:00 2001 -From: Hood Chatham -Date: Sat, 18 Dec 2021 12:31:51 -0800 -Subject: [PATCH 09/13] sasum returns double not float - ---- - scipy/sparse/linalg/_dsolve/SuperLU/SRC/slacon2.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slacon2.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slacon2.c -index 50efe7849..c176fddb4 100644 ---- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slacon2.c -+++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/slacon2.c -@@ -104,7 +104,7 @@ slacon2_(int *n, float *v, float *x, int *isgn, float *est, int *kase, int isave - extern int SCOPY(int *, float *, int *, float *, int *); - #else - extern int isamax_(int *, float *, int *); -- extern float sasum_(int *, float *, int *); -+ extern double sasum_(int *, float *, int *); - extern int scopy_(int *, float *, int *, float *, int *); - #endif - #define d_sign(a, b) (b >= 0 ? fabs(a) : -fabs(a)) /* Copy sign */ --- -2.25.1 - diff --git a/packages/scipy/patches/0013-Fix-fitpack.patch b/packages/scipy/patches/0010-Fix-fitpack.patch similarity index 97% rename from packages/scipy/patches/0013-Fix-fitpack.patch rename to packages/scipy/patches/0010-Fix-fitpack.patch index 64555425a7c..9f7125dee17 100644 --- a/packages/scipy/patches/0013-Fix-fitpack.patch +++ b/packages/scipy/patches/0010-Fix-fitpack.patch @@ -1,7 +1,7 @@ -From 861d31484a840ebcf014906fe44b281790fc6a5c Mon Sep 17 00:00:00 2001 +From 39c94e7f760354d5d42e6a354ba4a184f618c31d Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 30 Aug 2022 11:51:53 -0700 -Subject: [PATCH 13/13] Fix fitpack +Subject: [PATCH 10/11] Fix fitpack --- scipy/interpolate/fitpack/dblint.f | 9 ++++----- @@ -108,5 +108,5 @@ index f038b931b..776b06b9e 100644 return end -- -2.25.1 +2.34.1 diff --git a/packages/scipy/patches/0011-When-forward-declaring-print_soln-give-it-the-correc.patch b/packages/scipy/patches/0011-When-forward-declaring-print_soln-give-it-the-correc.patch new file mode 100644 index 00000000000..c7a74d375dd --- /dev/null +++ b/packages/scipy/patches/0011-When-forward-declaring-print_soln-give-it-the-correc.patch @@ -0,0 +1,70 @@ +From bb4e0d92ee2ba91ac5defd36ca5781433de25688 Mon Sep 17 00:00:00 2001 +From: Hood Chatham +Date: Fri, 10 Mar 2023 14:47:00 +0000 +Subject: [PATCH 11/11] When forward declaring print_soln, give it the correct + signature + +--- + scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgstrs.c | 2 +- + scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgstrs.c | 2 +- + scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgstrs.c | 3 +-- + scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgstrs.c | 3 +-- + 4 files changed, 4 insertions(+), 6 deletions(-) + +diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgstrs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgstrs.c +index f0cc2fcc0..fd8614e40 100644 +--- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgstrs.c ++++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/cgstrs.c +@@ -120,7 +120,7 @@ cgstrs (trans_t trans, SuperMatrix *L, SuperMatrix *U, + int i, j, k, iptr, jcol, n, ldb, nrhs; + complex *work, *rhs_work, *soln; + flops_t solve_ops; +- void cprint_soln(); ++ void cprint_soln(int n, int nrhs, complex *soln); + + /* Test input parameters ... */ + *info = 0; +diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgstrs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgstrs.c +index 2d6525e92..b8f356c35 100644 +--- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgstrs.c ++++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/dgstrs.c +@@ -119,7 +119,7 @@ dgstrs (trans_t trans, SuperMatrix *L, SuperMatrix *U, + int i, j, k, iptr, jcol, n, ldb, nrhs; + double *work, *rhs_work, *soln; + flops_t solve_ops; +- void dprint_soln(); ++ void dprint_soln(int n, int nrhs, double *soln); + + /* Test input parameters ... */ + *info = 0; +diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgstrs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgstrs.c +index b67507363..6c730acb0 100644 +--- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgstrs.c ++++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/sgstrs.c +@@ -119,8 +119,7 @@ sgstrs (trans_t trans, SuperMatrix *L, SuperMatrix *U, + int i, j, k, iptr, jcol, n, ldb, nrhs; + float *work, *rhs_work, *soln; + flops_t solve_ops; +- void sprint_soln(); +- ++ void sprint_soln(int n, int nrhs, float *soln); + /* Test input parameters ... */ + *info = 0; + Bstore = B->Store; +diff --git a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgstrs.c b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgstrs.c +index df95d6fdc..7e032992d 100644 +--- a/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgstrs.c ++++ b/scipy/sparse/linalg/_dsolve/SuperLU/SRC/zgstrs.c +@@ -120,8 +120,7 @@ zgstrs (trans_t trans, SuperMatrix *L, SuperMatrix *U, + int i, j, k, iptr, jcol, n, ldb, nrhs; + doublecomplex *work, *rhs_work, *soln; + flops_t solve_ops; +- void zprint_soln(); +- ++ void zprint_soln(int n, int nrhs, doublecomplex *soln); + /* Test input parameters ... */ + *info = 0; + Bstore = B->Store; +-- +2.34.1 + diff --git a/packages/scipy/patches/0012-Enable-long-double-support-in-Boost-library-for-emsc.patch b/packages/scipy/patches/0012-Enable-long-double-support-in-Boost-library-for-emsc.patch new file mode 100644 index 00000000000..153dfc1028b --- /dev/null +++ b/packages/scipy/patches/0012-Enable-long-double-support-in-Boost-library-for-emsc.patch @@ -0,0 +1,25 @@ +From e9a7bd91516677716e33b16326ddea643be5aed5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= +Date: Thu, 6 Apr 2023 12:22:45 +0200 +Subject: [PATCH 12/12] Enable long double support in Boost library for emscripten + +--- + scipy/_lib/boost/boost/math/tools/config.hpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/scipy/_lib/boost/boost/math/tools/config.hpp b/scipy/_lib/boost/boost/math/tools/config.hpp +index 30db8ea5..f97a994a 100644 +--- a/scipy/_lib/boost/boost/math/tools/config.hpp ++++ b/scipy/_lib/boost/boost/math/tools/config.hpp +@@ -28,7 +28,7 @@ + + #include + +-#if (defined(__NetBSD__) || defined(__EMSCRIPTEN__)\ ++#if (defined(__NetBSD__) \ + || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \ + && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) + # define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +-- +2.34.1 + diff --git a/packages/suitesparse/meta.yaml b/packages/suitesparse/meta.yaml index 21e78ab7417..39b3ac2ce83 100644 --- a/packages/suitesparse/meta.yaml +++ b/packages/suitesparse/meta.yaml @@ -10,9 +10,9 @@ source: requirements: run: - - CLAPACK + - openblas host: - - CLAPACK + - openblas build: type: shared_library @@ -23,8 +23,8 @@ build: emmake make -j ${PYODIDE_JOBS:-3} install \ LDFLAGS="${SIDE_MODULE_LDFLAGS} -L${WASM_LIBRARY_DIR}/lib " \ - BLAS="${WASM_LIBRARY_DIR}/lib/clapack_all.so" \ - LAPACK="${WASM_LIBRARY_DIR}/lib/clapack_all.so" \ + BLAS="${WASM_LIBRARY_DIR}/lib/libopenblas.so" \ + LAPACK="${WASM_LIBRARY_DIR}/lib/libopenblas.so" \ INSTALL=${WASM_LIBRARY_DIR} cp ${WASM_LIBRARY_DIR}/lib/libsuitesparseconfig.so \ diff --git a/pyodide-build/pyodide_build/_f2c_fixes.py b/pyodide-build/pyodide_build/_f2c_fixes.py index 36f57b3b92f..4144ee38296 100644 --- a/pyodide-build/pyodide_build/_f2c_fixes.py +++ b/pyodide-build/pyodide_build/_f2c_fixes.py @@ -10,9 +10,9 @@ def prepare_doctest(x: str) -> list[str]: def fix_f2c_input(f2c_input_path: str) -> None: """ - CLAPACK has been manually modified to remove useless arguments generated by + OpenBLAS has been manually modified to remove useless arguments generated by f2c. But the mismatches between the f2c ABI and the human-curated sensible - ABI in CLAPACK cause us great pain. + ABI in OpenBLAS cause us great pain. This stuff applies to actual source files, but scipy also has multiple templating engines for Fortran, so these changes have to be applied @@ -25,7 +25,7 @@ def fix_f2c_input(f2c_input_path: str) -> None: Mostly the issues are related to 'character' types. Most LAPACK functions that take string arguments use them as enums and only care about the first character of the string. f2c generates a 'length' argument to indicate how - long the string is, but CLAPACK leaves these length arguments out because + long the string is, but OpenBLAS leaves these length arguments out because the strings are assumed to have length 1. So the goal is to cause f2c to generate no length argument. We can achieve @@ -48,7 +48,7 @@ def fix_f2c_input(f2c_input_path: str) -> None: This is perfect. Not sure why it does this, but it's very convenient for us. - chla_transtype is a special case. The CLAPACK version of chla_transtype takes + chla_transtype is a special case. The OpenBLAS version of chla_transtype takes a return argument, whereas f2c thinks it should return the value. """ @@ -96,23 +96,15 @@ def fix_f2c_input(f2c_input_path: str) -> None: def fix_string_args(line: str) -> str: """ - The two functions ilaenv and xerbla have real string args, f2c generates - inaccurate signatures for them. Instead of manually fixing the signatures - (xerbla happens a lot) we inject wrappers called `xerblaf2py` and - `ilaenvf2py` that have the signatures f2c expects and call these instead. - - Also, replace all single character strings in (the first line of) "call" + Replace all single character strings in (the first line of) "call" statements with their ascci codes. """ - line = re.sub("ilaenv", "ilaenvf2py", line, flags=re.I) if ( not re.search("call", line, re.I) and "SIGNST" not in line and "TRANST" not in line ): return line - if re.search("xerbla", line, re.I): - return re.sub("xerbla", "xerblaf2py", line, flags=re.I) else: return re.sub("'[A-Za-z0-9]'", lambda y: str(ord(y.group(0)[1])), line) @@ -283,6 +275,10 @@ def fix_line(line: str) -> str: for line in regrouped_lines ] + # Fix signature of c_abs to match the OpenBLAS one + if "REVCOM.c" in str(f2c_output): + lines = [line.replace("double c_abs(", "float c_abs(") for line in lines] + with open(f2c_output, "w") as f: f.writelines(lines) @@ -478,8 +474,14 @@ def scipy_fix_cfile(path: str) -> None: text = text.replace(",size_t", "") text = re.sub(r",slen\([a-z]*\)\)", ")", text) - if path.endswith("_fblasmodule.c"): - text = text.replace(" float (*f2py_func)", " double (*f2py_func)") + if path.endswith("stats/statlib/spearman.c"): + # in scipy/stats/statlib/swilk.f ALNORM is called with a double, and in + # scipy/stats/statlib/spearman.f with a real this generates + # inconsistent signature. Let's use double in both, I don't think this + # code path will work (but at least it will compile) since it needs + # "ALNORM = algorithm AS66", which I don't think we have with the f2c + # route + text = text.replace("extern real alnorm_", "extern doublereal alnorm_") source_path.write_text(text) diff --git a/pyodide-build/pyodide_build/pywasmcross.py b/pyodide-build/pyodide_build/pywasmcross.py index 871134db2f8..9c5b43335af 100755 --- a/pyodide-build/pyodide_build/pywasmcross.py +++ b/pyodide-build/pyodide_build/pywasmcross.py @@ -123,7 +123,15 @@ def replay_f2c(args: list[str], dryrun: bool = False) -> list[str] | None: ] ) filepath = filepath.with_suffix(".f") - subprocess.check_call(["f2c", filepath.name], cwd=filepath.parent) + # -R flag is important, it means that Fortran functions that + # return real e.g. sdot will be transformed into C functions + # that return float. For historic reasons, by default f2c + # transform them into functions that return a double. Using -R + # allows to match what OpenBLAS has done when they f2ced their + # Fortran files, see + # https://github.com/xianyi/OpenBLAS/pull/3539#issuecomment-1493897254 + # for more details + subprocess.check_call(["f2c", "-R", filepath.name], cwd=filepath.parent) fix_f2c_output(arg[:-2] + ".c") new_args.append(arg[:-2] + ".c") found_source = True