Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- VQA_model/DOVER/.eggs/README.txt +6 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/LICENSE.txt +910 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__config__.py +115 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.cython-30.pxd +1052 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.pxd +1017 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.py +439 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.pyi +0 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_distributor_init.py +10 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_globals.py +125 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_pytesttester.py +206 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_pytesttester.pyi +18 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_version.py +21 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/conftest.py +136 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/ctypeslib.py +547 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/ctypeslib.pyi +251 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/dual.py +83 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__init__.py +186 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__init__.pyi +43 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__main__.py +5 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__version__.py +1 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/auxfuncs.py +890 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/capi_maps.py +880 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/cb_rules.py +649 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/cfuncs.py +1522 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/common_rules.py +149 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/crackfortran.py +0 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/diagnose.py +154 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/f2py2e.py +704 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/f90mod_rules.py +264 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/func2subr.py +303 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/rules.py +1571 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/setup.py +71 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/symbolic.py +1510 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_array_from_pyobj.py +686 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_assumed_shape.py +49 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_callback.py +230 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_character.py +592 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_crackfortran.py +278 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_docs.py +55 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_f2cmap.py +15 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_parameter.py +112 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_return_logical.py +64 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/util.py +419 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/use_rules.py +113 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/matlib.py +378 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/py.typed +0 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/setup.py +32 -0
- VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/version.py +15 -0
- VQA_model/DOVER/dover/__pycache__/__init__.cpython-37.pyc +0 -0
- VQA_model/DOVER/dover/__pycache__/__init__.cpython-38.pyc +0 -0
VQA_model/DOVER/.eggs/README.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins.
|
| 2 |
+
|
| 3 |
+
This directory caches those eggs to prevent repeated downloads.
|
| 4 |
+
|
| 5 |
+
However, it is safe to delete this directory.
|
| 6 |
+
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/LICENSE.txt
ADDED
|
@@ -0,0 +1,910 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2005-2022, NumPy Developers.
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are
|
| 6 |
+
met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright
|
| 9 |
+
notice, this list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
* Redistributions in binary form must reproduce the above
|
| 12 |
+
copyright notice, this list of conditions and the following
|
| 13 |
+
disclaimer in the documentation and/or other materials provided
|
| 14 |
+
with the distribution.
|
| 15 |
+
|
| 16 |
+
* Neither the name of the NumPy Developers nor the names of any
|
| 17 |
+
contributors may be used to endorse or promote products derived
|
| 18 |
+
from this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 21 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 22 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 23 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 24 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 25 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 26 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 27 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 28 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 29 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 30 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 31 |
+
|
| 32 |
+
----
|
| 33 |
+
|
| 34 |
+
This binary distribution of NumPy also bundles the following software:
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Name: OpenBLAS
|
| 38 |
+
Files: .libs/libopenb*.so
|
| 39 |
+
Description: bundled as a dynamically linked library
|
| 40 |
+
Availability: https://github.com/xianyi/OpenBLAS/
|
| 41 |
+
License: 3-clause BSD
|
| 42 |
+
Copyright (c) 2011-2014, The OpenBLAS Project
|
| 43 |
+
All rights reserved.
|
| 44 |
+
|
| 45 |
+
Redistribution and use in source and binary forms, with or without
|
| 46 |
+
modification, are permitted provided that the following conditions are
|
| 47 |
+
met:
|
| 48 |
+
|
| 49 |
+
1. Redistributions of source code must retain the above copyright
|
| 50 |
+
notice, this list of conditions and the following disclaimer.
|
| 51 |
+
|
| 52 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 53 |
+
notice, this list of conditions and the following disclaimer in
|
| 54 |
+
the documentation and/or other materials provided with the
|
| 55 |
+
distribution.
|
| 56 |
+
3. Neither the name of the OpenBLAS project nor the names of
|
| 57 |
+
its contributors may be used to endorse or promote products
|
| 58 |
+
derived from this software without specific prior written
|
| 59 |
+
permission.
|
| 60 |
+
|
| 61 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 62 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 63 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 64 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
| 65 |
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 66 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 67 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 68 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 69 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
| 70 |
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Name: LAPACK
|
| 74 |
+
Files: .libs/libopenb*.so
|
| 75 |
+
Description: bundled in OpenBLAS
|
| 76 |
+
Availability: https://github.com/xianyi/OpenBLAS/
|
| 77 |
+
License 3-clause BSD
|
| 78 |
+
Copyright (c) 1992-2013 The University of Tennessee and The University
|
| 79 |
+
of Tennessee Research Foundation. All rights
|
| 80 |
+
reserved.
|
| 81 |
+
Copyright (c) 2000-2013 The University of California Berkeley. All
|
| 82 |
+
rights reserved.
|
| 83 |
+
Copyright (c) 2006-2013 The University of Colorado Denver. All rights
|
| 84 |
+
reserved.
|
| 85 |
+
|
| 86 |
+
$COPYRIGHT$
|
| 87 |
+
|
| 88 |
+
Additional copyrights may follow
|
| 89 |
+
|
| 90 |
+
$HEADER$
|
| 91 |
+
|
| 92 |
+
Redistribution and use in source and binary forms, with or without
|
| 93 |
+
modification, are permitted provided that the following conditions are
|
| 94 |
+
met:
|
| 95 |
+
|
| 96 |
+
- Redistributions of source code must retain the above copyright
|
| 97 |
+
notice, this list of conditions and the following disclaimer.
|
| 98 |
+
|
| 99 |
+
- Redistributions in binary form must reproduce the above copyright
|
| 100 |
+
notice, this list of conditions and the following disclaimer listed
|
| 101 |
+
in this license in the documentation and/or other materials
|
| 102 |
+
provided with the distribution.
|
| 103 |
+
|
| 104 |
+
- Neither the name of the copyright holders nor the names of its
|
| 105 |
+
contributors may be used to endorse or promote products derived from
|
| 106 |
+
this software without specific prior written permission.
|
| 107 |
+
|
| 108 |
+
The copyright holders provide no reassurances that the source code
|
| 109 |
+
provided does not infringe any patent, copyright, or any other
|
| 110 |
+
intellectual property rights of third parties. The copyright holders
|
| 111 |
+
disclaim any liability to any recipient for claims brought against
|
| 112 |
+
recipient by any third party for infringement of that parties
|
| 113 |
+
intellectual property rights.
|
| 114 |
+
|
| 115 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 116 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 117 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 118 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 119 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 120 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 121 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 122 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 123 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 124 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 125 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
Name: GCC runtime library
|
| 129 |
+
Files: .libs/libgfortran*.so
|
| 130 |
+
Description: dynamically linked to files compiled with gcc
|
| 131 |
+
Availability: https://gcc.gnu.org/viewcvs/gcc/
|
| 132 |
+
License: GPLv3 + runtime exception
|
| 133 |
+
Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
| 134 |
+
|
| 135 |
+
Libgfortran is free software; you can redistribute it and/or modify
|
| 136 |
+
it under the terms of the GNU General Public License as published by
|
| 137 |
+
the Free Software Foundation; either version 3, or (at your option)
|
| 138 |
+
any later version.
|
| 139 |
+
|
| 140 |
+
Libgfortran is distributed in the hope that it will be useful,
|
| 141 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 142 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 143 |
+
GNU General Public License for more details.
|
| 144 |
+
|
| 145 |
+
Under Section 7 of GPL version 3, you are granted additional
|
| 146 |
+
permissions described in the GCC Runtime Library Exception, version
|
| 147 |
+
3.1, as published by the Free Software Foundation.
|
| 148 |
+
|
| 149 |
+
You should have received a copy of the GNU General Public License and
|
| 150 |
+
a copy of the GCC Runtime Library Exception along with this program;
|
| 151 |
+
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
| 152 |
+
<http://www.gnu.org/licenses/>.
|
| 153 |
+
|
| 154 |
+
----
|
| 155 |
+
|
| 156 |
+
Full text of license texts referred to above follows (that they are
|
| 157 |
+
listed below does not necessarily imply the conditions apply to the
|
| 158 |
+
present binary release):
|
| 159 |
+
|
| 160 |
+
----
|
| 161 |
+
|
| 162 |
+
GCC RUNTIME LIBRARY EXCEPTION
|
| 163 |
+
|
| 164 |
+
Version 3.1, 31 March 2009
|
| 165 |
+
|
| 166 |
+
Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
|
| 167 |
+
|
| 168 |
+
Everyone is permitted to copy and distribute verbatim copies of this
|
| 169 |
+
license document, but changing it is not allowed.
|
| 170 |
+
|
| 171 |
+
This GCC Runtime Library Exception ("Exception") is an additional
|
| 172 |
+
permission under section 7 of the GNU General Public License, version
|
| 173 |
+
3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
|
| 174 |
+
bears a notice placed by the copyright holder of the file stating that
|
| 175 |
+
the file is governed by GPLv3 along with this Exception.
|
| 176 |
+
|
| 177 |
+
When you use GCC to compile a program, GCC may combine portions of
|
| 178 |
+
certain GCC header files and runtime libraries with the compiled
|
| 179 |
+
program. The purpose of this Exception is to allow compilation of
|
| 180 |
+
non-GPL (including proprietary) programs to use, in this way, the
|
| 181 |
+
header files and runtime libraries covered by this Exception.
|
| 182 |
+
|
| 183 |
+
0. Definitions.
|
| 184 |
+
|
| 185 |
+
A file is an "Independent Module" if it either requires the Runtime
|
| 186 |
+
Library for execution after a Compilation Process, or makes use of an
|
| 187 |
+
interface provided by the Runtime Library, but is not otherwise based
|
| 188 |
+
on the Runtime Library.
|
| 189 |
+
|
| 190 |
+
"GCC" means a version of the GNU Compiler Collection, with or without
|
| 191 |
+
modifications, governed by version 3 (or a specified later version) of
|
| 192 |
+
the GNU General Public License (GPL) with the option of using any
|
| 193 |
+
subsequent versions published by the FSF.
|
| 194 |
+
|
| 195 |
+
"GPL-compatible Software" is software whose conditions of propagation,
|
| 196 |
+
modification and use would permit combination with GCC in accord with
|
| 197 |
+
the license of GCC.
|
| 198 |
+
|
| 199 |
+
"Target Code" refers to output from any compiler for a real or virtual
|
| 200 |
+
target processor architecture, in executable form or suitable for
|
| 201 |
+
input to an assembler, loader, linker and/or execution
|
| 202 |
+
phase. Notwithstanding that, Target Code does not include data in any
|
| 203 |
+
format that is used as a compiler intermediate representation, or used
|
| 204 |
+
for producing a compiler intermediate representation.
|
| 205 |
+
|
| 206 |
+
The "Compilation Process" transforms code entirely represented in
|
| 207 |
+
non-intermediate languages designed for human-written code, and/or in
|
| 208 |
+
Java Virtual Machine byte code, into Target Code. Thus, for example,
|
| 209 |
+
use of source code generators and preprocessors need not be considered
|
| 210 |
+
part of the Compilation Process, since the Compilation Process can be
|
| 211 |
+
understood as starting with the output of the generators or
|
| 212 |
+
preprocessors.
|
| 213 |
+
|
| 214 |
+
A Compilation Process is "Eligible" if it is done using GCC, alone or
|
| 215 |
+
with other GPL-compatible software, or if it is done without using any
|
| 216 |
+
work based on GCC. For example, using non-GPL-compatible Software to
|
| 217 |
+
optimize any GCC intermediate representations would not qualify as an
|
| 218 |
+
Eligible Compilation Process.
|
| 219 |
+
|
| 220 |
+
1. Grant of Additional Permission.
|
| 221 |
+
|
| 222 |
+
You have permission to propagate a work of Target Code formed by
|
| 223 |
+
combining the Runtime Library with Independent Modules, even if such
|
| 224 |
+
propagation would otherwise violate the terms of GPLv3, provided that
|
| 225 |
+
all Target Code was generated by Eligible Compilation Processes. You
|
| 226 |
+
may then convey such a combination under terms of your choice,
|
| 227 |
+
consistent with the licensing of the Independent Modules.
|
| 228 |
+
|
| 229 |
+
2. No Weakening of GCC Copyleft.
|
| 230 |
+
|
| 231 |
+
The availability of this Exception does not imply any general
|
| 232 |
+
presumption that third-party software is unaffected by the copyleft
|
| 233 |
+
requirements of the license of GCC.
|
| 234 |
+
|
| 235 |
+
----
|
| 236 |
+
|
| 237 |
+
GNU GENERAL PUBLIC LICENSE
|
| 238 |
+
Version 3, 29 June 2007
|
| 239 |
+
|
| 240 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
| 241 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 242 |
+
of this license document, but changing it is not allowed.
|
| 243 |
+
|
| 244 |
+
Preamble
|
| 245 |
+
|
| 246 |
+
The GNU General Public License is a free, copyleft license for
|
| 247 |
+
software and other kinds of works.
|
| 248 |
+
|
| 249 |
+
The licenses for most software and other practical works are designed
|
| 250 |
+
to take away your freedom to share and change the works. By contrast,
|
| 251 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 252 |
+
share and change all versions of a program--to make sure it remains free
|
| 253 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 254 |
+
GNU General Public License for most of our software; it applies also to
|
| 255 |
+
any other work released this way by its authors. You can apply it to
|
| 256 |
+
your programs, too.
|
| 257 |
+
|
| 258 |
+
When we speak of free software, we are referring to freedom, not
|
| 259 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 260 |
+
have the freedom to distribute copies of free software (and charge for
|
| 261 |
+
them if you wish), that you receive source code or can get it if you
|
| 262 |
+
want it, that you can change the software or use pieces of it in new
|
| 263 |
+
free programs, and that you know you can do these things.
|
| 264 |
+
|
| 265 |
+
To protect your rights, we need to prevent others from denying you
|
| 266 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 267 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 268 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 269 |
+
|
| 270 |
+
For example, if you distribute copies of such a program, whether
|
| 271 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 272 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 273 |
+
or can get the source code. And you must show them these terms so they
|
| 274 |
+
know their rights.
|
| 275 |
+
|
| 276 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 277 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 278 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 279 |
+
|
| 280 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 281 |
+
that there is no warranty for this free software. For both users' and
|
| 282 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 283 |
+
changed, so that their problems will not be attributed erroneously to
|
| 284 |
+
authors of previous versions.
|
| 285 |
+
|
| 286 |
+
Some devices are designed to deny users access to install or run
|
| 287 |
+
modified versions of the software inside them, although the manufacturer
|
| 288 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 289 |
+
protecting users' freedom to change the software. The systematic
|
| 290 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 291 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 292 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 293 |
+
products. If such problems arise substantially in other domains, we
|
| 294 |
+
stand ready to extend this provision to those domains in future versions
|
| 295 |
+
of the GPL, as needed to protect the freedom of users.
|
| 296 |
+
|
| 297 |
+
Finally, every program is threatened constantly by software patents.
|
| 298 |
+
States should not allow patents to restrict development and use of
|
| 299 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 300 |
+
avoid the special danger that patents applied to a free program could
|
| 301 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 302 |
+
patents cannot be used to render the program non-free.
|
| 303 |
+
|
| 304 |
+
The precise terms and conditions for copying, distribution and
|
| 305 |
+
modification follow.
|
| 306 |
+
|
| 307 |
+
TERMS AND CONDITIONS
|
| 308 |
+
|
| 309 |
+
0. Definitions.
|
| 310 |
+
|
| 311 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 312 |
+
|
| 313 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 314 |
+
works, such as semiconductor masks.
|
| 315 |
+
|
| 316 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 317 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 318 |
+
"recipients" may be individuals or organizations.
|
| 319 |
+
|
| 320 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 321 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 322 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 323 |
+
earlier work or a work "based on" the earlier work.
|
| 324 |
+
|
| 325 |
+
A "covered work" means either the unmodified Program or a work based
|
| 326 |
+
on the Program.
|
| 327 |
+
|
| 328 |
+
To "propagate" a work means to do anything with it that, without
|
| 329 |
+
permission, would make you directly or secondarily liable for
|
| 330 |
+
infringement under applicable copyright law, except executing it on a
|
| 331 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 332 |
+
distribution (with or without modification), making available to the
|
| 333 |
+
public, and in some countries other activities as well.
|
| 334 |
+
|
| 335 |
+
To "convey" a work means any kind of propagation that enables other
|
| 336 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 337 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 338 |
+
|
| 339 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 340 |
+
to the extent that it includes a convenient and prominently visible
|
| 341 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 342 |
+
tells the user that there is no warranty for the work (except to the
|
| 343 |
+
extent that warranties are provided), that licensees may convey the
|
| 344 |
+
work under this License, and how to view a copy of this License. If
|
| 345 |
+
the interface presents a list of user commands or options, such as a
|
| 346 |
+
menu, a prominent item in the list meets this criterion.
|
| 347 |
+
|
| 348 |
+
1. Source Code.
|
| 349 |
+
|
| 350 |
+
The "source code" for a work means the preferred form of the work
|
| 351 |
+
for making modifications to it. "Object code" means any non-source
|
| 352 |
+
form of a work.
|
| 353 |
+
|
| 354 |
+
A "Standard Interface" means an interface that either is an official
|
| 355 |
+
standard defined by a recognized standards body, or, in the case of
|
| 356 |
+
interfaces specified for a particular programming language, one that
|
| 357 |
+
is widely used among developers working in that language.
|
| 358 |
+
|
| 359 |
+
The "System Libraries" of an executable work include anything, other
|
| 360 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 361 |
+
packaging a Major Component, but which is not part of that Major
|
| 362 |
+
Component, and (b) serves only to enable use of the work with that
|
| 363 |
+
Major Component, or to implement a Standard Interface for which an
|
| 364 |
+
implementation is available to the public in source code form. A
|
| 365 |
+
"Major Component", in this context, means a major essential component
|
| 366 |
+
(kernel, window system, and so on) of the specific operating system
|
| 367 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 368 |
+
produce the work, or an object code interpreter used to run it.
|
| 369 |
+
|
| 370 |
+
The "Corresponding Source" for a work in object code form means all
|
| 371 |
+
the source code needed to generate, install, and (for an executable
|
| 372 |
+
work) run the object code and to modify the work, including scripts to
|
| 373 |
+
control those activities. However, it does not include the work's
|
| 374 |
+
System Libraries, or general-purpose tools or generally available free
|
| 375 |
+
programs which are used unmodified in performing those activities but
|
| 376 |
+
which are not part of the work. For example, Corresponding Source
|
| 377 |
+
includes interface definition files associated with source files for
|
| 378 |
+
the work, and the source code for shared libraries and dynamically
|
| 379 |
+
linked subprograms that the work is specifically designed to require,
|
| 380 |
+
such as by intimate data communication or control flow between those
|
| 381 |
+
subprograms and other parts of the work.
|
| 382 |
+
|
| 383 |
+
The Corresponding Source need not include anything that users
|
| 384 |
+
can regenerate automatically from other parts of the Corresponding
|
| 385 |
+
Source.
|
| 386 |
+
|
| 387 |
+
The Corresponding Source for a work in source code form is that
|
| 388 |
+
same work.
|
| 389 |
+
|
| 390 |
+
2. Basic Permissions.
|
| 391 |
+
|
| 392 |
+
All rights granted under this License are granted for the term of
|
| 393 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 394 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 395 |
+
permission to run the unmodified Program. The output from running a
|
| 396 |
+
covered work is covered by this License only if the output, given its
|
| 397 |
+
content, constitutes a covered work. This License acknowledges your
|
| 398 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 399 |
+
|
| 400 |
+
You may make, run and propagate covered works that you do not
|
| 401 |
+
convey, without conditions so long as your license otherwise remains
|
| 402 |
+
in force. You may convey covered works to others for the sole purpose
|
| 403 |
+
of having them make modifications exclusively for you, or provide you
|
| 404 |
+
with facilities for running those works, provided that you comply with
|
| 405 |
+
the terms of this License in conveying all material for which you do
|
| 406 |
+
not control copyright. Those thus making or running the covered works
|
| 407 |
+
for you must do so exclusively on your behalf, under your direction
|
| 408 |
+
and control, on terms that prohibit them from making any copies of
|
| 409 |
+
your copyrighted material outside their relationship with you.
|
| 410 |
+
|
| 411 |
+
Conveying under any other circumstances is permitted solely under
|
| 412 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 413 |
+
makes it unnecessary.
|
| 414 |
+
|
| 415 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 416 |
+
|
| 417 |
+
No covered work shall be deemed part of an effective technological
|
| 418 |
+
measure under any applicable law fulfilling obligations under article
|
| 419 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 420 |
+
similar laws prohibiting or restricting circumvention of such
|
| 421 |
+
measures.
|
| 422 |
+
|
| 423 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 424 |
+
circumvention of technological measures to the extent such circumvention
|
| 425 |
+
is effected by exercising rights under this License with respect to
|
| 426 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 427 |
+
modification of the work as a means of enforcing, against the work's
|
| 428 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 429 |
+
technological measures.
|
| 430 |
+
|
| 431 |
+
4. Conveying Verbatim Copies.
|
| 432 |
+
|
| 433 |
+
You may convey verbatim copies of the Program's source code as you
|
| 434 |
+
receive it, in any medium, provided that you conspicuously and
|
| 435 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 436 |
+
keep intact all notices stating that this License and any
|
| 437 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 438 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 439 |
+
recipients a copy of this License along with the Program.
|
| 440 |
+
|
| 441 |
+
You may charge any price or no price for each copy that you convey,
|
| 442 |
+
and you may offer support or warranty protection for a fee.
|
| 443 |
+
|
| 444 |
+
5. Conveying Modified Source Versions.
|
| 445 |
+
|
| 446 |
+
You may convey a work based on the Program, or the modifications to
|
| 447 |
+
produce it from the Program, in the form of source code under the
|
| 448 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 449 |
+
|
| 450 |
+
a) The work must carry prominent notices stating that you modified
|
| 451 |
+
it, and giving a relevant date.
|
| 452 |
+
|
| 453 |
+
b) The work must carry prominent notices stating that it is
|
| 454 |
+
released under this License and any conditions added under section
|
| 455 |
+
7. This requirement modifies the requirement in section 4 to
|
| 456 |
+
"keep intact all notices".
|
| 457 |
+
|
| 458 |
+
c) You must license the entire work, as a whole, under this
|
| 459 |
+
License to anyone who comes into possession of a copy. This
|
| 460 |
+
License will therefore apply, along with any applicable section 7
|
| 461 |
+
additional terms, to the whole of the work, and all its parts,
|
| 462 |
+
regardless of how they are packaged. This License gives no
|
| 463 |
+
permission to license the work in any other way, but it does not
|
| 464 |
+
invalidate such permission if you have separately received it.
|
| 465 |
+
|
| 466 |
+
d) If the work has interactive user interfaces, each must display
|
| 467 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 468 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 469 |
+
work need not make them do so.
|
| 470 |
+
|
| 471 |
+
A compilation of a covered work with other separate and independent
|
| 472 |
+
works, which are not by their nature extensions of the covered work,
|
| 473 |
+
and which are not combined with it such as to form a larger program,
|
| 474 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 475 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 476 |
+
used to limit the access or legal rights of the compilation's users
|
| 477 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 478 |
+
in an aggregate does not cause this License to apply to the other
|
| 479 |
+
parts of the aggregate.
|
| 480 |
+
|
| 481 |
+
6. Conveying Non-Source Forms.
|
| 482 |
+
|
| 483 |
+
You may convey a covered work in object code form under the terms
|
| 484 |
+
of sections 4 and 5, provided that you also convey the
|
| 485 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 486 |
+
in one of these ways:
|
| 487 |
+
|
| 488 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 489 |
+
(including a physical distribution medium), accompanied by the
|
| 490 |
+
Corresponding Source fixed on a durable physical medium
|
| 491 |
+
customarily used for software interchange.
|
| 492 |
+
|
| 493 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 494 |
+
(including a physical distribution medium), accompanied by a
|
| 495 |
+
written offer, valid for at least three years and valid for as
|
| 496 |
+
long as you offer spare parts or customer support for that product
|
| 497 |
+
model, to give anyone who possesses the object code either (1) a
|
| 498 |
+
copy of the Corresponding Source for all the software in the
|
| 499 |
+
product that is covered by this License, on a durable physical
|
| 500 |
+
medium customarily used for software interchange, for a price no
|
| 501 |
+
more than your reasonable cost of physically performing this
|
| 502 |
+
conveying of source, or (2) access to copy the
|
| 503 |
+
Corresponding Source from a network server at no charge.
|
| 504 |
+
|
| 505 |
+
c) Convey individual copies of the object code with a copy of the
|
| 506 |
+
written offer to provide the Corresponding Source. This
|
| 507 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 508 |
+
only if you received the object code with such an offer, in accord
|
| 509 |
+
with subsection 6b.
|
| 510 |
+
|
| 511 |
+
d) Convey the object code by offering access from a designated
|
| 512 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 513 |
+
Corresponding Source in the same way through the same place at no
|
| 514 |
+
further charge. You need not require recipients to copy the
|
| 515 |
+
Corresponding Source along with the object code. If the place to
|
| 516 |
+
copy the object code is a network server, the Corresponding Source
|
| 517 |
+
may be on a different server (operated by you or a third party)
|
| 518 |
+
that supports equivalent copying facilities, provided you maintain
|
| 519 |
+
clear directions next to the object code saying where to find the
|
| 520 |
+
Corresponding Source. Regardless of what server hosts the
|
| 521 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 522 |
+
available for as long as needed to satisfy these requirements.
|
| 523 |
+
|
| 524 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 525 |
+
you inform other peers where the object code and Corresponding
|
| 526 |
+
Source of the work are being offered to the general public at no
|
| 527 |
+
charge under subsection 6d.
|
| 528 |
+
|
| 529 |
+
A separable portion of the object code, whose source code is excluded
|
| 530 |
+
from the Corresponding Source as a System Library, need not be
|
| 531 |
+
included in conveying the object code work.
|
| 532 |
+
|
| 533 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 534 |
+
tangible personal property which is normally used for personal, family,
|
| 535 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 536 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 537 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 538 |
+
product received by a particular user, "normally used" refers to a
|
| 539 |
+
typical or common use of that class of product, regardless of the status
|
| 540 |
+
of the particular user or of the way in which the particular user
|
| 541 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 542 |
+
is a consumer product regardless of whether the product has substantial
|
| 543 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 544 |
+
the only significant mode of use of the product.
|
| 545 |
+
|
| 546 |
+
"Installation Information" for a User Product means any methods,
|
| 547 |
+
procedures, authorization keys, or other information required to install
|
| 548 |
+
and execute modified versions of a covered work in that User Product from
|
| 549 |
+
a modified version of its Corresponding Source. The information must
|
| 550 |
+
suffice to ensure that the continued functioning of the modified object
|
| 551 |
+
code is in no case prevented or interfered with solely because
|
| 552 |
+
modification has been made.
|
| 553 |
+
|
| 554 |
+
If you convey an object code work under this section in, or with, or
|
| 555 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 556 |
+
part of a transaction in which the right of possession and use of the
|
| 557 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 558 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 559 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 560 |
+
by the Installation Information. But this requirement does not apply
|
| 561 |
+
if neither you nor any third party retains the ability to install
|
| 562 |
+
modified object code on the User Product (for example, the work has
|
| 563 |
+
been installed in ROM).
|
| 564 |
+
|
| 565 |
+
The requirement to provide Installation Information does not include a
|
| 566 |
+
requirement to continue to provide support service, warranty, or updates
|
| 567 |
+
for a work that has been modified or installed by the recipient, or for
|
| 568 |
+
the User Product in which it has been modified or installed. Access to a
|
| 569 |
+
network may be denied when the modification itself materially and
|
| 570 |
+
adversely affects the operation of the network or violates the rules and
|
| 571 |
+
protocols for communication across the network.
|
| 572 |
+
|
| 573 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 574 |
+
in accord with this section must be in a format that is publicly
|
| 575 |
+
documented (and with an implementation available to the public in
|
| 576 |
+
source code form), and must require no special password or key for
|
| 577 |
+
unpacking, reading or copying.
|
| 578 |
+
|
| 579 |
+
7. Additional Terms.
|
| 580 |
+
|
| 581 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 582 |
+
License by making exceptions from one or more of its conditions.
|
| 583 |
+
Additional permissions that are applicable to the entire Program shall
|
| 584 |
+
be treated as though they were included in this License, to the extent
|
| 585 |
+
that they are valid under applicable law. If additional permissions
|
| 586 |
+
apply only to part of the Program, that part may be used separately
|
| 587 |
+
under those permissions, but the entire Program remains governed by
|
| 588 |
+
this License without regard to the additional permissions.
|
| 589 |
+
|
| 590 |
+
When you convey a copy of a covered work, you may at your option
|
| 591 |
+
remove any additional permissions from that copy, or from any part of
|
| 592 |
+
it. (Additional permissions may be written to require their own
|
| 593 |
+
removal in certain cases when you modify the work.) You may place
|
| 594 |
+
additional permissions on material, added by you to a covered work,
|
| 595 |
+
for which you have or can give appropriate copyright permission.
|
| 596 |
+
|
| 597 |
+
Notwithstanding any other provision of this License, for material you
|
| 598 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 599 |
+
that material) supplement the terms of this License with terms:
|
| 600 |
+
|
| 601 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 602 |
+
terms of sections 15 and 16 of this License; or
|
| 603 |
+
|
| 604 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 605 |
+
author attributions in that material or in the Appropriate Legal
|
| 606 |
+
Notices displayed by works containing it; or
|
| 607 |
+
|
| 608 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 609 |
+
requiring that modified versions of such material be marked in
|
| 610 |
+
reasonable ways as different from the original version; or
|
| 611 |
+
|
| 612 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 613 |
+
authors of the material; or
|
| 614 |
+
|
| 615 |
+
e) Declining to grant rights under trademark law for use of some
|
| 616 |
+
trade names, trademarks, or service marks; or
|
| 617 |
+
|
| 618 |
+
f) Requiring indemnification of licensors and authors of that
|
| 619 |
+
material by anyone who conveys the material (or modified versions of
|
| 620 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 621 |
+
any liability that these contractual assumptions directly impose on
|
| 622 |
+
those licensors and authors.
|
| 623 |
+
|
| 624 |
+
All other non-permissive additional terms are considered "further
|
| 625 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 626 |
+
received it, or any part of it, contains a notice stating that it is
|
| 627 |
+
governed by this License along with a term that is a further
|
| 628 |
+
restriction, you may remove that term. If a license document contains
|
| 629 |
+
a further restriction but permits relicensing or conveying under this
|
| 630 |
+
License, you may add to a covered work material governed by the terms
|
| 631 |
+
of that license document, provided that the further restriction does
|
| 632 |
+
not survive such relicensing or conveying.
|
| 633 |
+
|
| 634 |
+
If you add terms to a covered work in accord with this section, you
|
| 635 |
+
must place, in the relevant source files, a statement of the
|
| 636 |
+
additional terms that apply to those files, or a notice indicating
|
| 637 |
+
where to find the applicable terms.
|
| 638 |
+
|
| 639 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 640 |
+
form of a separately written license, or stated as exceptions;
|
| 641 |
+
the above requirements apply either way.
|
| 642 |
+
|
| 643 |
+
8. Termination.
|
| 644 |
+
|
| 645 |
+
You may not propagate or modify a covered work except as expressly
|
| 646 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 647 |
+
modify it is void, and will automatically terminate your rights under
|
| 648 |
+
this License (including any patent licenses granted under the third
|
| 649 |
+
paragraph of section 11).
|
| 650 |
+
|
| 651 |
+
However, if you cease all violation of this License, then your
|
| 652 |
+
license from a particular copyright holder is reinstated (a)
|
| 653 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 654 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 655 |
+
holder fails to notify you of the violation by some reasonable means
|
| 656 |
+
prior to 60 days after the cessation.
|
| 657 |
+
|
| 658 |
+
Moreover, your license from a particular copyright holder is
|
| 659 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 660 |
+
violation by some reasonable means, this is the first time you have
|
| 661 |
+
received notice of violation of this License (for any work) from that
|
| 662 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 663 |
+
your receipt of the notice.
|
| 664 |
+
|
| 665 |
+
Termination of your rights under this section does not terminate the
|
| 666 |
+
licenses of parties who have received copies or rights from you under
|
| 667 |
+
this License. If your rights have been terminated and not permanently
|
| 668 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 669 |
+
material under section 10.
|
| 670 |
+
|
| 671 |
+
9. Acceptance Not Required for Having Copies.
|
| 672 |
+
|
| 673 |
+
You are not required to accept this License in order to receive or
|
| 674 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 675 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 676 |
+
to receive a copy likewise does not require acceptance. However,
|
| 677 |
+
nothing other than this License grants you permission to propagate or
|
| 678 |
+
modify any covered work. These actions infringe copyright if you do
|
| 679 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 680 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 681 |
+
|
| 682 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 683 |
+
|
| 684 |
+
Each time you convey a covered work, the recipient automatically
|
| 685 |
+
receives a license from the original licensors, to run, modify and
|
| 686 |
+
propagate that work, subject to this License. You are not responsible
|
| 687 |
+
for enforcing compliance by third parties with this License.
|
| 688 |
+
|
| 689 |
+
An "entity transaction" is a transaction transferring control of an
|
| 690 |
+
organization, or substantially all assets of one, or subdividing an
|
| 691 |
+
organization, or merging organizations. If propagation of a covered
|
| 692 |
+
work results from an entity transaction, each party to that
|
| 693 |
+
transaction who receives a copy of the work also receives whatever
|
| 694 |
+
licenses to the work the party's predecessor in interest had or could
|
| 695 |
+
give under the previous paragraph, plus a right to possession of the
|
| 696 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 697 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 698 |
+
|
| 699 |
+
You may not impose any further restrictions on the exercise of the
|
| 700 |
+
rights granted or affirmed under this License. For example, you may
|
| 701 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 702 |
+
rights granted under this License, and you may not initiate litigation
|
| 703 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 704 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 705 |
+
sale, or importing the Program or any portion of it.
|
| 706 |
+
|
| 707 |
+
11. Patents.
|
| 708 |
+
|
| 709 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 710 |
+
License of the Program or a work on which the Program is based. The
|
| 711 |
+
work thus licensed is called the contributor's "contributor version".
|
| 712 |
+
|
| 713 |
+
A contributor's "essential patent claims" are all patent claims
|
| 714 |
+
owned or controlled by the contributor, whether already acquired or
|
| 715 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 716 |
+
by this License, of making, using, or selling its contributor version,
|
| 717 |
+
but do not include claims that would be infringed only as a
|
| 718 |
+
consequence of further modification of the contributor version. For
|
| 719 |
+
purposes of this definition, "control" includes the right to grant
|
| 720 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 721 |
+
this License.
|
| 722 |
+
|
| 723 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 724 |
+
patent license under the contributor's essential patent claims, to
|
| 725 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 726 |
+
propagate the contents of its contributor version.
|
| 727 |
+
|
| 728 |
+
In the following three paragraphs, a "patent license" is any express
|
| 729 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 730 |
+
(such as an express permission to practice a patent or covenant not to
|
| 731 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 732 |
+
party means to make such an agreement or commitment not to enforce a
|
| 733 |
+
patent against the party.
|
| 734 |
+
|
| 735 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 736 |
+
and the Corresponding Source of the work is not available for anyone
|
| 737 |
+
to copy, free of charge and under the terms of this License, through a
|
| 738 |
+
publicly available network server or other readily accessible means,
|
| 739 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 740 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 741 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 742 |
+
consistent with the requirements of this License, to extend the patent
|
| 743 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 744 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 745 |
+
covered work in a country, or your recipient's use of the covered work
|
| 746 |
+
in a country, would infringe one or more identifiable patents in that
|
| 747 |
+
country that you have reason to believe are valid.
|
| 748 |
+
|
| 749 |
+
If, pursuant to or in connection with a single transaction or
|
| 750 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 751 |
+
covered work, and grant a patent license to some of the parties
|
| 752 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 753 |
+
or convey a specific copy of the covered work, then the patent license
|
| 754 |
+
you grant is automatically extended to all recipients of the covered
|
| 755 |
+
work and works based on it.
|
| 756 |
+
|
| 757 |
+
A patent license is "discriminatory" if it does not include within
|
| 758 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 759 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 760 |
+
specifically granted under this License. You may not convey a covered
|
| 761 |
+
work if you are a party to an arrangement with a third party that is
|
| 762 |
+
in the business of distributing software, under which you make payment
|
| 763 |
+
to the third party based on the extent of your activity of conveying
|
| 764 |
+
the work, and under which the third party grants, to any of the
|
| 765 |
+
parties who would receive the covered work from you, a discriminatory
|
| 766 |
+
patent license (a) in connection with copies of the covered work
|
| 767 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 768 |
+
for and in connection with specific products or compilations that
|
| 769 |
+
contain the covered work, unless you entered into that arrangement,
|
| 770 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 771 |
+
|
| 772 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 773 |
+
any implied license or other defenses to infringement that may
|
| 774 |
+
otherwise be available to you under applicable patent law.
|
| 775 |
+
|
| 776 |
+
12. No Surrender of Others' Freedom.
|
| 777 |
+
|
| 778 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 779 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 780 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 781 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 782 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 783 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 784 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 785 |
+
the Program, the only way you could satisfy both those terms and this
|
| 786 |
+
License would be to refrain entirely from conveying the Program.
|
| 787 |
+
|
| 788 |
+
13. Use with the GNU Affero General Public License.
|
| 789 |
+
|
| 790 |
+
Notwithstanding any other provision of this License, you have
|
| 791 |
+
permission to link or combine any covered work with a work licensed
|
| 792 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 793 |
+
combined work, and to convey the resulting work. The terms of this
|
| 794 |
+
License will continue to apply to the part which is the covered work,
|
| 795 |
+
but the special requirements of the GNU Affero General Public License,
|
| 796 |
+
section 13, concerning interaction through a network will apply to the
|
| 797 |
+
combination as such.
|
| 798 |
+
|
| 799 |
+
14. Revised Versions of this License.
|
| 800 |
+
|
| 801 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 802 |
+
the GNU General Public License from time to time. Such new versions will
|
| 803 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 804 |
+
address new problems or concerns.
|
| 805 |
+
|
| 806 |
+
Each version is given a distinguishing version number. If the
|
| 807 |
+
Program specifies that a certain numbered version of the GNU General
|
| 808 |
+
Public License "or any later version" applies to it, you have the
|
| 809 |
+
option of following the terms and conditions either of that numbered
|
| 810 |
+
version or of any later version published by the Free Software
|
| 811 |
+
Foundation. If the Program does not specify a version number of the
|
| 812 |
+
GNU General Public License, you may choose any version ever published
|
| 813 |
+
by the Free Software Foundation.
|
| 814 |
+
|
| 815 |
+
If the Program specifies that a proxy can decide which future
|
| 816 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 817 |
+
public statement of acceptance of a version permanently authorizes you
|
| 818 |
+
to choose that version for the Program.
|
| 819 |
+
|
| 820 |
+
Later license versions may give you additional or different
|
| 821 |
+
permissions. However, no additional obligations are imposed on any
|
| 822 |
+
author or copyright holder as a result of your choosing to follow a
|
| 823 |
+
later version.
|
| 824 |
+
|
| 825 |
+
15. Disclaimer of Warranty.
|
| 826 |
+
|
| 827 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 828 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 829 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 830 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 831 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 832 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 833 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 834 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 835 |
+
|
| 836 |
+
16. Limitation of Liability.
|
| 837 |
+
|
| 838 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 839 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 840 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 841 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 842 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 843 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 844 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 845 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 846 |
+
SUCH DAMAGES.
|
| 847 |
+
|
| 848 |
+
17. Interpretation of Sections 15 and 16.
|
| 849 |
+
|
| 850 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 851 |
+
above cannot be given local legal effect according to their terms,
|
| 852 |
+
reviewing courts shall apply local law that most closely approximates
|
| 853 |
+
an absolute waiver of all civil liability in connection with the
|
| 854 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 855 |
+
copy of the Program in return for a fee.
|
| 856 |
+
|
| 857 |
+
END OF TERMS AND CONDITIONS
|
| 858 |
+
|
| 859 |
+
How to Apply These Terms to Your New Programs
|
| 860 |
+
|
| 861 |
+
If you develop a new program, and you want it to be of the greatest
|
| 862 |
+
possible use to the public, the best way to achieve this is to make it
|
| 863 |
+
free software which everyone can redistribute and change under these terms.
|
| 864 |
+
|
| 865 |
+
To do so, attach the following notices to the program. It is safest
|
| 866 |
+
to attach them to the start of each source file to most effectively
|
| 867 |
+
state the exclusion of warranty; and each file should have at least
|
| 868 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 869 |
+
|
| 870 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 871 |
+
Copyright (C) <year> <name of author>
|
| 872 |
+
|
| 873 |
+
This program is free software: you can redistribute it and/or modify
|
| 874 |
+
it under the terms of the GNU General Public License as published by
|
| 875 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 876 |
+
(at your option) any later version.
|
| 877 |
+
|
| 878 |
+
This program is distributed in the hope that it will be useful,
|
| 879 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 880 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 881 |
+
GNU General Public License for more details.
|
| 882 |
+
|
| 883 |
+
You should have received a copy of the GNU General Public License
|
| 884 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 885 |
+
|
| 886 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 887 |
+
|
| 888 |
+
If the program does terminal interaction, make it output a short
|
| 889 |
+
notice like this when it starts in an interactive mode:
|
| 890 |
+
|
| 891 |
+
<program> Copyright (C) <year> <name of author>
|
| 892 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 893 |
+
This is free software, and you are welcome to redistribute it
|
| 894 |
+
under certain conditions; type `show c' for details.
|
| 895 |
+
|
| 896 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 897 |
+
parts of the General Public License. Of course, your program's commands
|
| 898 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 899 |
+
|
| 900 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 901 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 902 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 903 |
+
<http://www.gnu.org/licenses/>.
|
| 904 |
+
|
| 905 |
+
The GNU General Public License does not permit incorporating your program
|
| 906 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 907 |
+
may consider it more useful to permit linking proprietary applications with
|
| 908 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 909 |
+
Public License instead of this License. But first, please read
|
| 910 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__config__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is generated by numpy's setup.py
|
| 2 |
+
# It contains system_info results at the time of building this package.
|
| 3 |
+
__all__ = ["get_info","show"]
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
extra_dll_dir = os.path.join(os.path.dirname(__file__), '.libs')
|
| 10 |
+
|
| 11 |
+
if sys.platform == 'win32' and os.path.isdir(extra_dll_dir):
|
| 12 |
+
os.add_dll_directory(extra_dll_dir)
|
| 13 |
+
|
| 14 |
+
openblas64__info={'libraries': ['openblas64_', 'openblas64_'], 'library_dirs': ['/usr/local/lib'], 'language': 'c', 'define_macros': [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None)], 'runtime_library_dirs': ['/usr/local/lib']}
|
| 15 |
+
blas_ilp64_opt_info={'libraries': ['openblas64_', 'openblas64_'], 'library_dirs': ['/usr/local/lib'], 'language': 'c', 'define_macros': [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None)], 'runtime_library_dirs': ['/usr/local/lib']}
|
| 16 |
+
openblas64__lapack_info={'libraries': ['openblas64_', 'openblas64_'], 'library_dirs': ['/usr/local/lib'], 'language': 'c', 'define_macros': [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None), ('HAVE_LAPACKE', None)], 'runtime_library_dirs': ['/usr/local/lib']}
|
| 17 |
+
lapack_ilp64_opt_info={'libraries': ['openblas64_', 'openblas64_'], 'library_dirs': ['/usr/local/lib'], 'language': 'c', 'define_macros': [('HAVE_CBLAS', None), ('BLAS_SYMBOL_SUFFIX', '64_'), ('HAVE_BLAS_ILP64', None), ('HAVE_LAPACKE', None)], 'runtime_library_dirs': ['/usr/local/lib']}
|
| 18 |
+
|
| 19 |
+
def get_info(name):
|
| 20 |
+
g = globals()
|
| 21 |
+
return g.get(name, g.get(name + "_info", {}))
|
| 22 |
+
|
| 23 |
+
def show():
|
| 24 |
+
"""
|
| 25 |
+
Show libraries in the system on which NumPy was built.
|
| 26 |
+
|
| 27 |
+
Print information about various resources (libraries, library
|
| 28 |
+
directories, include directories, etc.) in the system on which
|
| 29 |
+
NumPy was built.
|
| 30 |
+
|
| 31 |
+
See Also
|
| 32 |
+
--------
|
| 33 |
+
get_include : Returns the directory containing NumPy C
|
| 34 |
+
header files.
|
| 35 |
+
|
| 36 |
+
Notes
|
| 37 |
+
-----
|
| 38 |
+
1. Classes specifying the information to be printed are defined
|
| 39 |
+
in the `numpy.distutils.system_info` module.
|
| 40 |
+
|
| 41 |
+
Information may include:
|
| 42 |
+
|
| 43 |
+
* ``language``: language used to write the libraries (mostly
|
| 44 |
+
C or f77)
|
| 45 |
+
* ``libraries``: names of libraries found in the system
|
| 46 |
+
* ``library_dirs``: directories containing the libraries
|
| 47 |
+
* ``include_dirs``: directories containing library header files
|
| 48 |
+
* ``src_dirs``: directories containing library source files
|
| 49 |
+
* ``define_macros``: preprocessor macros used by
|
| 50 |
+
``distutils.setup``
|
| 51 |
+
* ``baseline``: minimum CPU features required
|
| 52 |
+
* ``found``: dispatched features supported in the system
|
| 53 |
+
* ``not found``: dispatched features that are not supported
|
| 54 |
+
in the system
|
| 55 |
+
|
| 56 |
+
2. NumPy BLAS/LAPACK Installation Notes
|
| 57 |
+
|
| 58 |
+
Installing a numpy wheel (``pip install numpy`` or force it
|
| 59 |
+
via ``pip install numpy --only-binary :numpy: numpy``) includes
|
| 60 |
+
an OpenBLAS implementation of the BLAS and LAPACK linear algebra
|
| 61 |
+
APIs. In this case, ``library_dirs`` reports the original build
|
| 62 |
+
time configuration as compiled with gcc/gfortran; at run time
|
| 63 |
+
the OpenBLAS library is in
|
| 64 |
+
``site-packages/numpy.libs/`` (linux), or
|
| 65 |
+
``site-packages/numpy/.dylibs/`` (macOS), or
|
| 66 |
+
``site-packages/numpy/.libs/`` (windows).
|
| 67 |
+
|
| 68 |
+
Installing numpy from source
|
| 69 |
+
(``pip install numpy --no-binary numpy``) searches for BLAS and
|
| 70 |
+
LAPACK dynamic link libraries at build time as influenced by
|
| 71 |
+
environment variables NPY_BLAS_LIBS, NPY_CBLAS_LIBS, and
|
| 72 |
+
NPY_LAPACK_LIBS; or NPY_BLAS_ORDER and NPY_LAPACK_ORDER;
|
| 73 |
+
or the optional file ``~/.numpy-site.cfg``.
|
| 74 |
+
NumPy remembers those locations and expects to load the same
|
| 75 |
+
libraries at run-time.
|
| 76 |
+
In NumPy 1.21+ on macOS, 'accelerate' (Apple's Accelerate BLAS
|
| 77 |
+
library) is in the default build-time search order after
|
| 78 |
+
'openblas'.
|
| 79 |
+
|
| 80 |
+
Examples
|
| 81 |
+
--------
|
| 82 |
+
>>> import numpy as np
|
| 83 |
+
>>> np.show_config()
|
| 84 |
+
blas_opt_info:
|
| 85 |
+
language = c
|
| 86 |
+
define_macros = [('HAVE_CBLAS', None)]
|
| 87 |
+
libraries = ['openblas', 'openblas']
|
| 88 |
+
library_dirs = ['/usr/local/lib']
|
| 89 |
+
"""
|
| 90 |
+
from numpy.core._multiarray_umath import (
|
| 91 |
+
__cpu_features__, __cpu_baseline__, __cpu_dispatch__
|
| 92 |
+
)
|
| 93 |
+
for name,info_dict in globals().items():
|
| 94 |
+
if name[0] == "_" or type(info_dict) is not type({}): continue
|
| 95 |
+
print(name + ":")
|
| 96 |
+
if not info_dict:
|
| 97 |
+
print(" NOT AVAILABLE")
|
| 98 |
+
for k,v in info_dict.items():
|
| 99 |
+
v = str(v)
|
| 100 |
+
if k == "sources" and len(v) > 200:
|
| 101 |
+
v = v[:60] + " ...\n... " + v[-60:]
|
| 102 |
+
print(" %s = %s" % (k,v))
|
| 103 |
+
|
| 104 |
+
features_found, features_not_found = [], []
|
| 105 |
+
for feature in __cpu_dispatch__:
|
| 106 |
+
if __cpu_features__[feature]:
|
| 107 |
+
features_found.append(feature)
|
| 108 |
+
else:
|
| 109 |
+
features_not_found.append(feature)
|
| 110 |
+
|
| 111 |
+
print("Supported SIMD extensions in this NumPy install:")
|
| 112 |
+
print(" baseline = %s" % (','.join(__cpu_baseline__)))
|
| 113 |
+
print(" found = %s" % (','.join(features_found)))
|
| 114 |
+
print(" not found = %s" % (','.join(features_not_found)))
|
| 115 |
+
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.cython-30.pxd
ADDED
|
@@ -0,0 +1,1052 @@
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NumPy static imports for Cython >= 3.0
|
| 2 |
+
#
|
| 3 |
+
# If any of the PyArray_* functions are called, import_array must be
|
| 4 |
+
# called first. This is done automatically by Cython 3.0+ if a call
|
| 5 |
+
# is not detected inside of the module.
|
| 6 |
+
#
|
| 7 |
+
# Author: Dag Sverre Seljebotn
|
| 8 |
+
#
|
| 9 |
+
|
| 10 |
+
from cpython.ref cimport Py_INCREF
|
| 11 |
+
from cpython.object cimport PyObject, PyTypeObject, PyObject_TypeCheck
|
| 12 |
+
cimport libc.stdio as stdio
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
cdef extern from *:
|
| 16 |
+
# Leave a marker that the NumPy declarations came from NumPy itself and not from Cython.
|
| 17 |
+
# See https://github.com/cython/cython/issues/3573
|
| 18 |
+
"""
|
| 19 |
+
/* Using NumPy API declarations from "numpy/__init__.cython-30.pxd" */
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
cdef extern from "Python.h":
|
| 24 |
+
ctypedef Py_ssize_t Py_intptr_t
|
| 25 |
+
|
| 26 |
+
cdef extern from "numpy/arrayobject.h":
|
| 27 |
+
ctypedef Py_intptr_t npy_intp
|
| 28 |
+
ctypedef size_t npy_uintp
|
| 29 |
+
|
| 30 |
+
cdef enum NPY_TYPES:
|
| 31 |
+
NPY_BOOL
|
| 32 |
+
NPY_BYTE
|
| 33 |
+
NPY_UBYTE
|
| 34 |
+
NPY_SHORT
|
| 35 |
+
NPY_USHORT
|
| 36 |
+
NPY_INT
|
| 37 |
+
NPY_UINT
|
| 38 |
+
NPY_LONG
|
| 39 |
+
NPY_ULONG
|
| 40 |
+
NPY_LONGLONG
|
| 41 |
+
NPY_ULONGLONG
|
| 42 |
+
NPY_FLOAT
|
| 43 |
+
NPY_DOUBLE
|
| 44 |
+
NPY_LONGDOUBLE
|
| 45 |
+
NPY_CFLOAT
|
| 46 |
+
NPY_CDOUBLE
|
| 47 |
+
NPY_CLONGDOUBLE
|
| 48 |
+
NPY_OBJECT
|
| 49 |
+
NPY_STRING
|
| 50 |
+
NPY_UNICODE
|
| 51 |
+
NPY_VOID
|
| 52 |
+
NPY_DATETIME
|
| 53 |
+
NPY_TIMEDELTA
|
| 54 |
+
NPY_NTYPES
|
| 55 |
+
NPY_NOTYPE
|
| 56 |
+
|
| 57 |
+
NPY_INT8
|
| 58 |
+
NPY_INT16
|
| 59 |
+
NPY_INT32
|
| 60 |
+
NPY_INT64
|
| 61 |
+
NPY_INT128
|
| 62 |
+
NPY_INT256
|
| 63 |
+
NPY_UINT8
|
| 64 |
+
NPY_UINT16
|
| 65 |
+
NPY_UINT32
|
| 66 |
+
NPY_UINT64
|
| 67 |
+
NPY_UINT128
|
| 68 |
+
NPY_UINT256
|
| 69 |
+
NPY_FLOAT16
|
| 70 |
+
NPY_FLOAT32
|
| 71 |
+
NPY_FLOAT64
|
| 72 |
+
NPY_FLOAT80
|
| 73 |
+
NPY_FLOAT96
|
| 74 |
+
NPY_FLOAT128
|
| 75 |
+
NPY_FLOAT256
|
| 76 |
+
NPY_COMPLEX32
|
| 77 |
+
NPY_COMPLEX64
|
| 78 |
+
NPY_COMPLEX128
|
| 79 |
+
NPY_COMPLEX160
|
| 80 |
+
NPY_COMPLEX192
|
| 81 |
+
NPY_COMPLEX256
|
| 82 |
+
NPY_COMPLEX512
|
| 83 |
+
|
| 84 |
+
NPY_INTP
|
| 85 |
+
|
| 86 |
+
ctypedef enum NPY_ORDER:
|
| 87 |
+
NPY_ANYORDER
|
| 88 |
+
NPY_CORDER
|
| 89 |
+
NPY_FORTRANORDER
|
| 90 |
+
NPY_KEEPORDER
|
| 91 |
+
|
| 92 |
+
ctypedef enum NPY_CASTING:
|
| 93 |
+
NPY_NO_CASTING
|
| 94 |
+
NPY_EQUIV_CASTING
|
| 95 |
+
NPY_SAFE_CASTING
|
| 96 |
+
NPY_SAME_KIND_CASTING
|
| 97 |
+
NPY_UNSAFE_CASTING
|
| 98 |
+
|
| 99 |
+
ctypedef enum NPY_CLIPMODE:
|
| 100 |
+
NPY_CLIP
|
| 101 |
+
NPY_WRAP
|
| 102 |
+
NPY_RAISE
|
| 103 |
+
|
| 104 |
+
ctypedef enum NPY_SCALARKIND:
|
| 105 |
+
NPY_NOSCALAR,
|
| 106 |
+
NPY_BOOL_SCALAR,
|
| 107 |
+
NPY_INTPOS_SCALAR,
|
| 108 |
+
NPY_INTNEG_SCALAR,
|
| 109 |
+
NPY_FLOAT_SCALAR,
|
| 110 |
+
NPY_COMPLEX_SCALAR,
|
| 111 |
+
NPY_OBJECT_SCALAR
|
| 112 |
+
|
| 113 |
+
ctypedef enum NPY_SORTKIND:
|
| 114 |
+
NPY_QUICKSORT
|
| 115 |
+
NPY_HEAPSORT
|
| 116 |
+
NPY_MERGESORT
|
| 117 |
+
|
| 118 |
+
ctypedef enum NPY_SEARCHSIDE:
|
| 119 |
+
NPY_SEARCHLEFT
|
| 120 |
+
NPY_SEARCHRIGHT
|
| 121 |
+
|
| 122 |
+
enum:
|
| 123 |
+
# DEPRECATED since NumPy 1.7 ! Do not use in new code!
|
| 124 |
+
NPY_C_CONTIGUOUS
|
| 125 |
+
NPY_F_CONTIGUOUS
|
| 126 |
+
NPY_CONTIGUOUS
|
| 127 |
+
NPY_FORTRAN
|
| 128 |
+
NPY_OWNDATA
|
| 129 |
+
NPY_FORCECAST
|
| 130 |
+
NPY_ENSURECOPY
|
| 131 |
+
NPY_ENSUREARRAY
|
| 132 |
+
NPY_ELEMENTSTRIDES
|
| 133 |
+
NPY_ALIGNED
|
| 134 |
+
NPY_NOTSWAPPED
|
| 135 |
+
NPY_WRITEABLE
|
| 136 |
+
NPY_ARR_HAS_DESCR
|
| 137 |
+
|
| 138 |
+
NPY_BEHAVED
|
| 139 |
+
NPY_BEHAVED_NS
|
| 140 |
+
NPY_CARRAY
|
| 141 |
+
NPY_CARRAY_RO
|
| 142 |
+
NPY_FARRAY
|
| 143 |
+
NPY_FARRAY_RO
|
| 144 |
+
NPY_DEFAULT
|
| 145 |
+
|
| 146 |
+
NPY_IN_ARRAY
|
| 147 |
+
NPY_OUT_ARRAY
|
| 148 |
+
NPY_INOUT_ARRAY
|
| 149 |
+
NPY_IN_FARRAY
|
| 150 |
+
NPY_OUT_FARRAY
|
| 151 |
+
NPY_INOUT_FARRAY
|
| 152 |
+
|
| 153 |
+
NPY_UPDATE_ALL
|
| 154 |
+
|
| 155 |
+
enum:
|
| 156 |
+
# Added in NumPy 1.7 to replace the deprecated enums above.
|
| 157 |
+
NPY_ARRAY_C_CONTIGUOUS
|
| 158 |
+
NPY_ARRAY_F_CONTIGUOUS
|
| 159 |
+
NPY_ARRAY_OWNDATA
|
| 160 |
+
NPY_ARRAY_FORCECAST
|
| 161 |
+
NPY_ARRAY_ENSURECOPY
|
| 162 |
+
NPY_ARRAY_ENSUREARRAY
|
| 163 |
+
NPY_ARRAY_ELEMENTSTRIDES
|
| 164 |
+
NPY_ARRAY_ALIGNED
|
| 165 |
+
NPY_ARRAY_NOTSWAPPED
|
| 166 |
+
NPY_ARRAY_WRITEABLE
|
| 167 |
+
NPY_ARRAY_WRITEBACKIFCOPY
|
| 168 |
+
|
| 169 |
+
NPY_ARRAY_BEHAVED
|
| 170 |
+
NPY_ARRAY_BEHAVED_NS
|
| 171 |
+
NPY_ARRAY_CARRAY
|
| 172 |
+
NPY_ARRAY_CARRAY_RO
|
| 173 |
+
NPY_ARRAY_FARRAY
|
| 174 |
+
NPY_ARRAY_FARRAY_RO
|
| 175 |
+
NPY_ARRAY_DEFAULT
|
| 176 |
+
|
| 177 |
+
NPY_ARRAY_IN_ARRAY
|
| 178 |
+
NPY_ARRAY_OUT_ARRAY
|
| 179 |
+
NPY_ARRAY_INOUT_ARRAY
|
| 180 |
+
NPY_ARRAY_IN_FARRAY
|
| 181 |
+
NPY_ARRAY_OUT_FARRAY
|
| 182 |
+
NPY_ARRAY_INOUT_FARRAY
|
| 183 |
+
|
| 184 |
+
NPY_ARRAY_UPDATE_ALL
|
| 185 |
+
|
| 186 |
+
cdef enum:
|
| 187 |
+
NPY_MAXDIMS
|
| 188 |
+
|
| 189 |
+
npy_intp NPY_MAX_ELSIZE
|
| 190 |
+
|
| 191 |
+
ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, void *)
|
| 192 |
+
|
| 193 |
+
ctypedef struct PyArray_ArrayDescr:
|
| 194 |
+
# shape is a tuple, but Cython doesn't support "tuple shape"
|
| 195 |
+
# inside a non-PyObject declaration, so we have to declare it
|
| 196 |
+
# as just a PyObject*.
|
| 197 |
+
PyObject* shape
|
| 198 |
+
|
| 199 |
+
ctypedef struct PyArray_Descr:
|
| 200 |
+
pass
|
| 201 |
+
|
| 202 |
+
ctypedef class numpy.dtype [object PyArray_Descr, check_size ignore]:
|
| 203 |
+
# Use PyDataType_* macros when possible, however there are no macros
|
| 204 |
+
# for accessing some of the fields, so some are defined.
|
| 205 |
+
cdef PyTypeObject* typeobj
|
| 206 |
+
cdef char kind
|
| 207 |
+
cdef char type
|
| 208 |
+
# Numpy sometimes mutates this without warning (e.g. it'll
|
| 209 |
+
# sometimes change "|" to "<" in shared dtype objects on
|
| 210 |
+
# little-endian machines). If this matters to you, use
|
| 211 |
+
# PyArray_IsNativeByteOrder(dtype.byteorder) instead of
|
| 212 |
+
# directly accessing this field.
|
| 213 |
+
cdef char byteorder
|
| 214 |
+
cdef char flags
|
| 215 |
+
cdef int type_num
|
| 216 |
+
cdef int itemsize "elsize"
|
| 217 |
+
cdef int alignment
|
| 218 |
+
cdef object fields
|
| 219 |
+
cdef tuple names
|
| 220 |
+
# Use PyDataType_HASSUBARRAY to test whether this field is
|
| 221 |
+
# valid (the pointer can be NULL). Most users should access
|
| 222 |
+
# this field via the inline helper method PyDataType_SHAPE.
|
| 223 |
+
cdef PyArray_ArrayDescr* subarray
|
| 224 |
+
|
| 225 |
+
ctypedef class numpy.flatiter [object PyArrayIterObject, check_size ignore]:
|
| 226 |
+
# Use through macros
|
| 227 |
+
pass
|
| 228 |
+
|
| 229 |
+
ctypedef class numpy.broadcast [object PyArrayMultiIterObject, check_size ignore]:
|
| 230 |
+
# Use through macros
|
| 231 |
+
pass
|
| 232 |
+
|
| 233 |
+
ctypedef struct PyArrayObject:
|
| 234 |
+
# For use in situations where ndarray can't replace PyArrayObject*,
|
| 235 |
+
# like PyArrayObject**.
|
| 236 |
+
pass
|
| 237 |
+
|
| 238 |
+
ctypedef class numpy.ndarray [object PyArrayObject, check_size ignore]:
|
| 239 |
+
cdef __cythonbufferdefaults__ = {"mode": "strided"}
|
| 240 |
+
|
| 241 |
+
# NOTE: no field declarations since direct access is deprecated since NumPy 1.7
|
| 242 |
+
# Instead, we use properties that map to the corresponding C-API functions.
|
| 243 |
+
|
| 244 |
+
@property
|
| 245 |
+
cdef inline PyObject* base(self) nogil:
|
| 246 |
+
"""Returns a borrowed reference to the object owning the data/memory.
|
| 247 |
+
"""
|
| 248 |
+
return PyArray_BASE(self)
|
| 249 |
+
|
| 250 |
+
@property
|
| 251 |
+
cdef inline dtype descr(self):
|
| 252 |
+
"""Returns an owned reference to the dtype of the array.
|
| 253 |
+
"""
|
| 254 |
+
return <dtype>PyArray_DESCR(self)
|
| 255 |
+
|
| 256 |
+
@property
|
| 257 |
+
cdef inline int ndim(self) nogil:
|
| 258 |
+
"""Returns the number of dimensions in the array.
|
| 259 |
+
"""
|
| 260 |
+
return PyArray_NDIM(self)
|
| 261 |
+
|
| 262 |
+
@property
|
| 263 |
+
cdef inline npy_intp *shape(self) nogil:
|
| 264 |
+
"""Returns a pointer to the dimensions/shape of the array.
|
| 265 |
+
The number of elements matches the number of dimensions of the array (ndim).
|
| 266 |
+
Can return NULL for 0-dimensional arrays.
|
| 267 |
+
"""
|
| 268 |
+
return PyArray_DIMS(self)
|
| 269 |
+
|
| 270 |
+
@property
|
| 271 |
+
cdef inline npy_intp *strides(self) nogil:
|
| 272 |
+
"""Returns a pointer to the strides of the array.
|
| 273 |
+
The number of elements matches the number of dimensions of the array (ndim).
|
| 274 |
+
"""
|
| 275 |
+
return PyArray_STRIDES(self)
|
| 276 |
+
|
| 277 |
+
@property
|
| 278 |
+
cdef inline npy_intp size(self) nogil:
|
| 279 |
+
"""Returns the total size (in number of elements) of the array.
|
| 280 |
+
"""
|
| 281 |
+
return PyArray_SIZE(self)
|
| 282 |
+
|
| 283 |
+
@property
|
| 284 |
+
cdef inline char* data(self) nogil:
|
| 285 |
+
"""The pointer to the data buffer as a char*.
|
| 286 |
+
This is provided for legacy reasons to avoid direct struct field access.
|
| 287 |
+
For new code that needs this access, you probably want to cast the result
|
| 288 |
+
of `PyArray_DATA()` instead, which returns a 'void*'.
|
| 289 |
+
"""
|
| 290 |
+
return PyArray_BYTES(self)
|
| 291 |
+
|
| 292 |
+
ctypedef unsigned char npy_bool
|
| 293 |
+
|
| 294 |
+
ctypedef signed char npy_byte
|
| 295 |
+
ctypedef signed short npy_short
|
| 296 |
+
ctypedef signed int npy_int
|
| 297 |
+
ctypedef signed long npy_long
|
| 298 |
+
ctypedef signed long long npy_longlong
|
| 299 |
+
|
| 300 |
+
ctypedef unsigned char npy_ubyte
|
| 301 |
+
ctypedef unsigned short npy_ushort
|
| 302 |
+
ctypedef unsigned int npy_uint
|
| 303 |
+
ctypedef unsigned long npy_ulong
|
| 304 |
+
ctypedef unsigned long long npy_ulonglong
|
| 305 |
+
|
| 306 |
+
ctypedef float npy_float
|
| 307 |
+
ctypedef double npy_double
|
| 308 |
+
ctypedef long double npy_longdouble
|
| 309 |
+
|
| 310 |
+
ctypedef signed char npy_int8
|
| 311 |
+
ctypedef signed short npy_int16
|
| 312 |
+
ctypedef signed int npy_int32
|
| 313 |
+
ctypedef signed long long npy_int64
|
| 314 |
+
ctypedef signed long long npy_int96
|
| 315 |
+
ctypedef signed long long npy_int128
|
| 316 |
+
|
| 317 |
+
ctypedef unsigned char npy_uint8
|
| 318 |
+
ctypedef unsigned short npy_uint16
|
| 319 |
+
ctypedef unsigned int npy_uint32
|
| 320 |
+
ctypedef unsigned long long npy_uint64
|
| 321 |
+
ctypedef unsigned long long npy_uint96
|
| 322 |
+
ctypedef unsigned long long npy_uint128
|
| 323 |
+
|
| 324 |
+
ctypedef float npy_float32
|
| 325 |
+
ctypedef double npy_float64
|
| 326 |
+
ctypedef long double npy_float80
|
| 327 |
+
ctypedef long double npy_float96
|
| 328 |
+
ctypedef long double npy_float128
|
| 329 |
+
|
| 330 |
+
ctypedef struct npy_cfloat:
|
| 331 |
+
float real
|
| 332 |
+
float imag
|
| 333 |
+
|
| 334 |
+
ctypedef struct npy_cdouble:
|
| 335 |
+
double real
|
| 336 |
+
double imag
|
| 337 |
+
|
| 338 |
+
ctypedef struct npy_clongdouble:
|
| 339 |
+
long double real
|
| 340 |
+
long double imag
|
| 341 |
+
|
| 342 |
+
ctypedef struct npy_complex64:
|
| 343 |
+
float real
|
| 344 |
+
float imag
|
| 345 |
+
|
| 346 |
+
ctypedef struct npy_complex128:
|
| 347 |
+
double real
|
| 348 |
+
double imag
|
| 349 |
+
|
| 350 |
+
ctypedef struct npy_complex160:
|
| 351 |
+
long double real
|
| 352 |
+
long double imag
|
| 353 |
+
|
| 354 |
+
ctypedef struct npy_complex192:
|
| 355 |
+
long double real
|
| 356 |
+
long double imag
|
| 357 |
+
|
| 358 |
+
ctypedef struct npy_complex256:
|
| 359 |
+
long double real
|
| 360 |
+
long double imag
|
| 361 |
+
|
| 362 |
+
ctypedef struct PyArray_Dims:
|
| 363 |
+
npy_intp *ptr
|
| 364 |
+
int len
|
| 365 |
+
|
| 366 |
+
int _import_array() except -1
|
| 367 |
+
# A second definition so _import_array isn't marked as used when we use it here.
|
| 368 |
+
# Do not use - subject to change any time.
|
| 369 |
+
int __pyx_import_array "_import_array"() except -1
|
| 370 |
+
|
| 371 |
+
#
|
| 372 |
+
# Macros from ndarrayobject.h
|
| 373 |
+
#
|
| 374 |
+
bint PyArray_CHKFLAGS(ndarray m, int flags) nogil
|
| 375 |
+
bint PyArray_IS_C_CONTIGUOUS(ndarray arr) nogil
|
| 376 |
+
bint PyArray_IS_F_CONTIGUOUS(ndarray arr) nogil
|
| 377 |
+
bint PyArray_ISCONTIGUOUS(ndarray m) nogil
|
| 378 |
+
bint PyArray_ISWRITEABLE(ndarray m) nogil
|
| 379 |
+
bint PyArray_ISALIGNED(ndarray m) nogil
|
| 380 |
+
|
| 381 |
+
int PyArray_NDIM(ndarray) nogil
|
| 382 |
+
bint PyArray_ISONESEGMENT(ndarray) nogil
|
| 383 |
+
bint PyArray_ISFORTRAN(ndarray) nogil
|
| 384 |
+
int PyArray_FORTRANIF(ndarray) nogil
|
| 385 |
+
|
| 386 |
+
void* PyArray_DATA(ndarray) nogil
|
| 387 |
+
char* PyArray_BYTES(ndarray) nogil
|
| 388 |
+
|
| 389 |
+
npy_intp* PyArray_DIMS(ndarray) nogil
|
| 390 |
+
npy_intp* PyArray_STRIDES(ndarray) nogil
|
| 391 |
+
npy_intp PyArray_DIM(ndarray, size_t) nogil
|
| 392 |
+
npy_intp PyArray_STRIDE(ndarray, size_t) nogil
|
| 393 |
+
|
| 394 |
+
PyObject *PyArray_BASE(ndarray) nogil # returns borrowed reference!
|
| 395 |
+
PyArray_Descr *PyArray_DESCR(ndarray) nogil # returns borrowed reference to dtype!
|
| 396 |
+
PyArray_Descr *PyArray_DTYPE(ndarray) nogil # returns borrowed reference to dtype! NP 1.7+ alias for descr.
|
| 397 |
+
int PyArray_FLAGS(ndarray) nogil
|
| 398 |
+
void PyArray_CLEARFLAGS(ndarray, int flags) nogil # Added in NumPy 1.7
|
| 399 |
+
void PyArray_ENABLEFLAGS(ndarray, int flags) nogil # Added in NumPy 1.7
|
| 400 |
+
npy_intp PyArray_ITEMSIZE(ndarray) nogil
|
| 401 |
+
int PyArray_TYPE(ndarray arr) nogil
|
| 402 |
+
|
| 403 |
+
object PyArray_GETITEM(ndarray arr, void *itemptr)
|
| 404 |
+
int PyArray_SETITEM(ndarray arr, void *itemptr, object obj)
|
| 405 |
+
|
| 406 |
+
bint PyTypeNum_ISBOOL(int) nogil
|
| 407 |
+
bint PyTypeNum_ISUNSIGNED(int) nogil
|
| 408 |
+
bint PyTypeNum_ISSIGNED(int) nogil
|
| 409 |
+
bint PyTypeNum_ISINTEGER(int) nogil
|
| 410 |
+
bint PyTypeNum_ISFLOAT(int) nogil
|
| 411 |
+
bint PyTypeNum_ISNUMBER(int) nogil
|
| 412 |
+
bint PyTypeNum_ISSTRING(int) nogil
|
| 413 |
+
bint PyTypeNum_ISCOMPLEX(int) nogil
|
| 414 |
+
bint PyTypeNum_ISPYTHON(int) nogil
|
| 415 |
+
bint PyTypeNum_ISFLEXIBLE(int) nogil
|
| 416 |
+
bint PyTypeNum_ISUSERDEF(int) nogil
|
| 417 |
+
bint PyTypeNum_ISEXTENDED(int) nogil
|
| 418 |
+
bint PyTypeNum_ISOBJECT(int) nogil
|
| 419 |
+
|
| 420 |
+
bint PyDataType_ISBOOL(dtype) nogil
|
| 421 |
+
bint PyDataType_ISUNSIGNED(dtype) nogil
|
| 422 |
+
bint PyDataType_ISSIGNED(dtype) nogil
|
| 423 |
+
bint PyDataType_ISINTEGER(dtype) nogil
|
| 424 |
+
bint PyDataType_ISFLOAT(dtype) nogil
|
| 425 |
+
bint PyDataType_ISNUMBER(dtype) nogil
|
| 426 |
+
bint PyDataType_ISSTRING(dtype) nogil
|
| 427 |
+
bint PyDataType_ISCOMPLEX(dtype) nogil
|
| 428 |
+
bint PyDataType_ISPYTHON(dtype) nogil
|
| 429 |
+
bint PyDataType_ISFLEXIBLE(dtype) nogil
|
| 430 |
+
bint PyDataType_ISUSERDEF(dtype) nogil
|
| 431 |
+
bint PyDataType_ISEXTENDED(dtype) nogil
|
| 432 |
+
bint PyDataType_ISOBJECT(dtype) nogil
|
| 433 |
+
bint PyDataType_HASFIELDS(dtype) nogil
|
| 434 |
+
bint PyDataType_HASSUBARRAY(dtype) nogil
|
| 435 |
+
|
| 436 |
+
bint PyArray_ISBOOL(ndarray) nogil
|
| 437 |
+
bint PyArray_ISUNSIGNED(ndarray) nogil
|
| 438 |
+
bint PyArray_ISSIGNED(ndarray) nogil
|
| 439 |
+
bint PyArray_ISINTEGER(ndarray) nogil
|
| 440 |
+
bint PyArray_ISFLOAT(ndarray) nogil
|
| 441 |
+
bint PyArray_ISNUMBER(ndarray) nogil
|
| 442 |
+
bint PyArray_ISSTRING(ndarray) nogil
|
| 443 |
+
bint PyArray_ISCOMPLEX(ndarray) nogil
|
| 444 |
+
bint PyArray_ISPYTHON(ndarray) nogil
|
| 445 |
+
bint PyArray_ISFLEXIBLE(ndarray) nogil
|
| 446 |
+
bint PyArray_ISUSERDEF(ndarray) nogil
|
| 447 |
+
bint PyArray_ISEXTENDED(ndarray) nogil
|
| 448 |
+
bint PyArray_ISOBJECT(ndarray) nogil
|
| 449 |
+
bint PyArray_HASFIELDS(ndarray) nogil
|
| 450 |
+
|
| 451 |
+
bint PyArray_ISVARIABLE(ndarray) nogil
|
| 452 |
+
|
| 453 |
+
bint PyArray_SAFEALIGNEDCOPY(ndarray) nogil
|
| 454 |
+
bint PyArray_ISNBO(char) nogil # works on ndarray.byteorder
|
| 455 |
+
bint PyArray_IsNativeByteOrder(char) nogil # works on ndarray.byteorder
|
| 456 |
+
bint PyArray_ISNOTSWAPPED(ndarray) nogil
|
| 457 |
+
bint PyArray_ISBYTESWAPPED(ndarray) nogil
|
| 458 |
+
|
| 459 |
+
bint PyArray_FLAGSWAP(ndarray, int) nogil
|
| 460 |
+
|
| 461 |
+
bint PyArray_ISCARRAY(ndarray) nogil
|
| 462 |
+
bint PyArray_ISCARRAY_RO(ndarray) nogil
|
| 463 |
+
bint PyArray_ISFARRAY(ndarray) nogil
|
| 464 |
+
bint PyArray_ISFARRAY_RO(ndarray) nogil
|
| 465 |
+
bint PyArray_ISBEHAVED(ndarray) nogil
|
| 466 |
+
bint PyArray_ISBEHAVED_RO(ndarray) nogil
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
bint PyDataType_ISNOTSWAPPED(dtype) nogil
|
| 470 |
+
bint PyDataType_ISBYTESWAPPED(dtype) nogil
|
| 471 |
+
|
| 472 |
+
bint PyArray_DescrCheck(object)
|
| 473 |
+
|
| 474 |
+
bint PyArray_Check(object)
|
| 475 |
+
bint PyArray_CheckExact(object)
|
| 476 |
+
|
| 477 |
+
# Cannot be supported due to out arg:
|
| 478 |
+
# bint PyArray_HasArrayInterfaceType(object, dtype, object, object&)
|
| 479 |
+
# bint PyArray_HasArrayInterface(op, out)
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
bint PyArray_IsZeroDim(object)
|
| 483 |
+
# Cannot be supported due to ## ## in macro:
|
| 484 |
+
# bint PyArray_IsScalar(object, verbatim work)
|
| 485 |
+
bint PyArray_CheckScalar(object)
|
| 486 |
+
bint PyArray_IsPythonNumber(object)
|
| 487 |
+
bint PyArray_IsPythonScalar(object)
|
| 488 |
+
bint PyArray_IsAnyScalar(object)
|
| 489 |
+
bint PyArray_CheckAnyScalar(object)
|
| 490 |
+
|
| 491 |
+
ndarray PyArray_GETCONTIGUOUS(ndarray)
|
| 492 |
+
bint PyArray_SAMESHAPE(ndarray, ndarray) nogil
|
| 493 |
+
npy_intp PyArray_SIZE(ndarray) nogil
|
| 494 |
+
npy_intp PyArray_NBYTES(ndarray) nogil
|
| 495 |
+
|
| 496 |
+
object PyArray_FROM_O(object)
|
| 497 |
+
object PyArray_FROM_OF(object m, int flags)
|
| 498 |
+
object PyArray_FROM_OT(object m, int type)
|
| 499 |
+
object PyArray_FROM_OTF(object m, int type, int flags)
|
| 500 |
+
object PyArray_FROMANY(object m, int type, int min, int max, int flags)
|
| 501 |
+
object PyArray_ZEROS(int nd, npy_intp* dims, int type, int fortran)
|
| 502 |
+
object PyArray_EMPTY(int nd, npy_intp* dims, int type, int fortran)
|
| 503 |
+
void PyArray_FILLWBYTE(object, int val)
|
| 504 |
+
npy_intp PyArray_REFCOUNT(object)
|
| 505 |
+
object PyArray_ContiguousFromAny(op, int, int min_depth, int max_depth)
|
| 506 |
+
unsigned char PyArray_EquivArrTypes(ndarray a1, ndarray a2)
|
| 507 |
+
bint PyArray_EquivByteorders(int b1, int b2) nogil
|
| 508 |
+
object PyArray_SimpleNew(int nd, npy_intp* dims, int typenum)
|
| 509 |
+
object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data)
|
| 510 |
+
#object PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, dtype descr)
|
| 511 |
+
object PyArray_ToScalar(void* data, ndarray arr)
|
| 512 |
+
|
| 513 |
+
void* PyArray_GETPTR1(ndarray m, npy_intp i) nogil
|
| 514 |
+
void* PyArray_GETPTR2(ndarray m, npy_intp i, npy_intp j) nogil
|
| 515 |
+
void* PyArray_GETPTR3(ndarray m, npy_intp i, npy_intp j, npy_intp k) nogil
|
| 516 |
+
void* PyArray_GETPTR4(ndarray m, npy_intp i, npy_intp j, npy_intp k, npy_intp l) nogil
|
| 517 |
+
|
| 518 |
+
void PyArray_XDECREF_ERR(ndarray)
|
| 519 |
+
# Cannot be supported due to out arg
|
| 520 |
+
# void PyArray_DESCR_REPLACE(descr)
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
object PyArray_Copy(ndarray)
|
| 524 |
+
object PyArray_FromObject(object op, int type, int min_depth, int max_depth)
|
| 525 |
+
object PyArray_ContiguousFromObject(object op, int type, int min_depth, int max_depth)
|
| 526 |
+
object PyArray_CopyFromObject(object op, int type, int min_depth, int max_depth)
|
| 527 |
+
|
| 528 |
+
object PyArray_Cast(ndarray mp, int type_num)
|
| 529 |
+
object PyArray_Take(ndarray ap, object items, int axis)
|
| 530 |
+
object PyArray_Put(ndarray ap, object items, object values)
|
| 531 |
+
|
| 532 |
+
void PyArray_ITER_RESET(flatiter it) nogil
|
| 533 |
+
void PyArray_ITER_NEXT(flatiter it) nogil
|
| 534 |
+
void PyArray_ITER_GOTO(flatiter it, npy_intp* destination) nogil
|
| 535 |
+
void PyArray_ITER_GOTO1D(flatiter it, npy_intp ind) nogil
|
| 536 |
+
void* PyArray_ITER_DATA(flatiter it) nogil
|
| 537 |
+
bint PyArray_ITER_NOTDONE(flatiter it) nogil
|
| 538 |
+
|
| 539 |
+
void PyArray_MultiIter_RESET(broadcast multi) nogil
|
| 540 |
+
void PyArray_MultiIter_NEXT(broadcast multi) nogil
|
| 541 |
+
void PyArray_MultiIter_GOTO(broadcast multi, npy_intp dest) nogil
|
| 542 |
+
void PyArray_MultiIter_GOTO1D(broadcast multi, npy_intp ind) nogil
|
| 543 |
+
void* PyArray_MultiIter_DATA(broadcast multi, npy_intp i) nogil
|
| 544 |
+
void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil
|
| 545 |
+
bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil
|
| 546 |
+
|
| 547 |
+
# Functions from __multiarray_api.h
|
| 548 |
+
|
| 549 |
+
# Functions taking dtype and returning object/ndarray are disabled
|
| 550 |
+
# for now as they steal dtype references. I'm conservative and disable
|
| 551 |
+
# more than is probably needed until it can be checked further.
|
| 552 |
+
int PyArray_SetNumericOps (object)
|
| 553 |
+
object PyArray_GetNumericOps ()
|
| 554 |
+
int PyArray_INCREF (ndarray)
|
| 555 |
+
int PyArray_XDECREF (ndarray)
|
| 556 |
+
void PyArray_SetStringFunction (object, int)
|
| 557 |
+
dtype PyArray_DescrFromType (int)
|
| 558 |
+
object PyArray_TypeObjectFromType (int)
|
| 559 |
+
char * PyArray_Zero (ndarray)
|
| 560 |
+
char * PyArray_One (ndarray)
|
| 561 |
+
#object PyArray_CastToType (ndarray, dtype, int)
|
| 562 |
+
int PyArray_CastTo (ndarray, ndarray)
|
| 563 |
+
int PyArray_CastAnyTo (ndarray, ndarray)
|
| 564 |
+
int PyArray_CanCastSafely (int, int)
|
| 565 |
+
npy_bool PyArray_CanCastTo (dtype, dtype)
|
| 566 |
+
int PyArray_ObjectType (object, int)
|
| 567 |
+
dtype PyArray_DescrFromObject (object, dtype)
|
| 568 |
+
#ndarray* PyArray_ConvertToCommonType (object, int *)
|
| 569 |
+
dtype PyArray_DescrFromScalar (object)
|
| 570 |
+
dtype PyArray_DescrFromTypeObject (object)
|
| 571 |
+
npy_intp PyArray_Size (object)
|
| 572 |
+
#object PyArray_Scalar (void *, dtype, object)
|
| 573 |
+
#object PyArray_FromScalar (object, dtype)
|
| 574 |
+
void PyArray_ScalarAsCtype (object, void *)
|
| 575 |
+
#int PyArray_CastScalarToCtype (object, void *, dtype)
|
| 576 |
+
#int PyArray_CastScalarDirect (object, dtype, void *, int)
|
| 577 |
+
object PyArray_ScalarFromObject (object)
|
| 578 |
+
#PyArray_VectorUnaryFunc * PyArray_GetCastFunc (dtype, int)
|
| 579 |
+
object PyArray_FromDims (int, int *, int)
|
| 580 |
+
#object PyArray_FromDimsAndDataAndDescr (int, int *, dtype, char *)
|
| 581 |
+
#object PyArray_FromAny (object, dtype, int, int, int, object)
|
| 582 |
+
object PyArray_EnsureArray (object)
|
| 583 |
+
object PyArray_EnsureAnyArray (object)
|
| 584 |
+
#object PyArray_FromFile (stdio.FILE *, dtype, npy_intp, char *)
|
| 585 |
+
#object PyArray_FromString (char *, npy_intp, dtype, npy_intp, char *)
|
| 586 |
+
#object PyArray_FromBuffer (object, dtype, npy_intp, npy_intp)
|
| 587 |
+
#object PyArray_FromIter (object, dtype, npy_intp)
|
| 588 |
+
object PyArray_Return (ndarray)
|
| 589 |
+
#object PyArray_GetField (ndarray, dtype, int)
|
| 590 |
+
#int PyArray_SetField (ndarray, dtype, int, object)
|
| 591 |
+
object PyArray_Byteswap (ndarray, npy_bool)
|
| 592 |
+
object PyArray_Resize (ndarray, PyArray_Dims *, int, NPY_ORDER)
|
| 593 |
+
int PyArray_MoveInto (ndarray, ndarray)
|
| 594 |
+
int PyArray_CopyInto (ndarray, ndarray)
|
| 595 |
+
int PyArray_CopyAnyInto (ndarray, ndarray)
|
| 596 |
+
int PyArray_CopyObject (ndarray, object)
|
| 597 |
+
object PyArray_NewCopy (ndarray, NPY_ORDER)
|
| 598 |
+
object PyArray_ToList (ndarray)
|
| 599 |
+
object PyArray_ToString (ndarray, NPY_ORDER)
|
| 600 |
+
int PyArray_ToFile (ndarray, stdio.FILE *, char *, char *)
|
| 601 |
+
int PyArray_Dump (object, object, int)
|
| 602 |
+
object PyArray_Dumps (object, int)
|
| 603 |
+
int PyArray_ValidType (int)
|
| 604 |
+
void PyArray_UpdateFlags (ndarray, int)
|
| 605 |
+
object PyArray_New (type, int, npy_intp *, int, npy_intp *, void *, int, int, object)
|
| 606 |
+
#object PyArray_NewFromDescr (type, dtype, int, npy_intp *, npy_intp *, void *, int, object)
|
| 607 |
+
#dtype PyArray_DescrNew (dtype)
|
| 608 |
+
dtype PyArray_DescrNewFromType (int)
|
| 609 |
+
double PyArray_GetPriority (object, double)
|
| 610 |
+
object PyArray_IterNew (object)
|
| 611 |
+
object PyArray_MultiIterNew (int, ...)
|
| 612 |
+
|
| 613 |
+
int PyArray_PyIntAsInt (object)
|
| 614 |
+
npy_intp PyArray_PyIntAsIntp (object)
|
| 615 |
+
int PyArray_Broadcast (broadcast)
|
| 616 |
+
void PyArray_FillObjectArray (ndarray, object)
|
| 617 |
+
int PyArray_FillWithScalar (ndarray, object)
|
| 618 |
+
npy_bool PyArray_CheckStrides (int, int, npy_intp, npy_intp, npy_intp *, npy_intp *)
|
| 619 |
+
dtype PyArray_DescrNewByteorder (dtype, char)
|
| 620 |
+
object PyArray_IterAllButAxis (object, int *)
|
| 621 |
+
#object PyArray_CheckFromAny (object, dtype, int, int, int, object)
|
| 622 |
+
#object PyArray_FromArray (ndarray, dtype, int)
|
| 623 |
+
object PyArray_FromInterface (object)
|
| 624 |
+
object PyArray_FromStructInterface (object)
|
| 625 |
+
#object PyArray_FromArrayAttr (object, dtype, object)
|
| 626 |
+
#NPY_SCALARKIND PyArray_ScalarKind (int, ndarray*)
|
| 627 |
+
int PyArray_CanCoerceScalar (int, int, NPY_SCALARKIND)
|
| 628 |
+
object PyArray_NewFlagsObject (object)
|
| 629 |
+
npy_bool PyArray_CanCastScalar (type, type)
|
| 630 |
+
#int PyArray_CompareUCS4 (npy_ucs4 *, npy_ucs4 *, register size_t)
|
| 631 |
+
int PyArray_RemoveSmallest (broadcast)
|
| 632 |
+
int PyArray_ElementStrides (object)
|
| 633 |
+
void PyArray_Item_INCREF (char *, dtype)
|
| 634 |
+
void PyArray_Item_XDECREF (char *, dtype)
|
| 635 |
+
object PyArray_FieldNames (object)
|
| 636 |
+
object PyArray_Transpose (ndarray, PyArray_Dims *)
|
| 637 |
+
object PyArray_TakeFrom (ndarray, object, int, ndarray, NPY_CLIPMODE)
|
| 638 |
+
object PyArray_PutTo (ndarray, object, object, NPY_CLIPMODE)
|
| 639 |
+
object PyArray_PutMask (ndarray, object, object)
|
| 640 |
+
object PyArray_Repeat (ndarray, object, int)
|
| 641 |
+
object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
|
| 642 |
+
int PyArray_Sort (ndarray, int, NPY_SORTKIND)
|
| 643 |
+
object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
|
| 644 |
+
object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE, PyObject *)
|
| 645 |
+
object PyArray_ArgMax (ndarray, int, ndarray)
|
| 646 |
+
object PyArray_ArgMin (ndarray, int, ndarray)
|
| 647 |
+
object PyArray_Reshape (ndarray, object)
|
| 648 |
+
object PyArray_Newshape (ndarray, PyArray_Dims *, NPY_ORDER)
|
| 649 |
+
object PyArray_Squeeze (ndarray)
|
| 650 |
+
#object PyArray_View (ndarray, dtype, type)
|
| 651 |
+
object PyArray_SwapAxes (ndarray, int, int)
|
| 652 |
+
object PyArray_Max (ndarray, int, ndarray)
|
| 653 |
+
object PyArray_Min (ndarray, int, ndarray)
|
| 654 |
+
object PyArray_Ptp (ndarray, int, ndarray)
|
| 655 |
+
object PyArray_Mean (ndarray, int, int, ndarray)
|
| 656 |
+
object PyArray_Trace (ndarray, int, int, int, int, ndarray)
|
| 657 |
+
object PyArray_Diagonal (ndarray, int, int, int)
|
| 658 |
+
object PyArray_Clip (ndarray, object, object, ndarray)
|
| 659 |
+
object PyArray_Conjugate (ndarray, ndarray)
|
| 660 |
+
object PyArray_Nonzero (ndarray)
|
| 661 |
+
object PyArray_Std (ndarray, int, int, ndarray, int)
|
| 662 |
+
object PyArray_Sum (ndarray, int, int, ndarray)
|
| 663 |
+
object PyArray_CumSum (ndarray, int, int, ndarray)
|
| 664 |
+
object PyArray_Prod (ndarray, int, int, ndarray)
|
| 665 |
+
object PyArray_CumProd (ndarray, int, int, ndarray)
|
| 666 |
+
object PyArray_All (ndarray, int, ndarray)
|
| 667 |
+
object PyArray_Any (ndarray, int, ndarray)
|
| 668 |
+
object PyArray_Compress (ndarray, object, int, ndarray)
|
| 669 |
+
object PyArray_Flatten (ndarray, NPY_ORDER)
|
| 670 |
+
object PyArray_Ravel (ndarray, NPY_ORDER)
|
| 671 |
+
npy_intp PyArray_MultiplyList (npy_intp *, int)
|
| 672 |
+
int PyArray_MultiplyIntList (int *, int)
|
| 673 |
+
void * PyArray_GetPtr (ndarray, npy_intp*)
|
| 674 |
+
int PyArray_CompareLists (npy_intp *, npy_intp *, int)
|
| 675 |
+
#int PyArray_AsCArray (object*, void *, npy_intp *, int, dtype)
|
| 676 |
+
#int PyArray_As1D (object*, char **, int *, int)
|
| 677 |
+
#int PyArray_As2D (object*, char ***, int *, int *, int)
|
| 678 |
+
int PyArray_Free (object, void *)
|
| 679 |
+
#int PyArray_Converter (object, object*)
|
| 680 |
+
int PyArray_IntpFromSequence (object, npy_intp *, int)
|
| 681 |
+
object PyArray_Concatenate (object, int)
|
| 682 |
+
object PyArray_InnerProduct (object, object)
|
| 683 |
+
object PyArray_MatrixProduct (object, object)
|
| 684 |
+
object PyArray_CopyAndTranspose (object)
|
| 685 |
+
object PyArray_Correlate (object, object, int)
|
| 686 |
+
int PyArray_TypestrConvert (int, int)
|
| 687 |
+
#int PyArray_DescrConverter (object, dtype*)
|
| 688 |
+
#int PyArray_DescrConverter2 (object, dtype*)
|
| 689 |
+
int PyArray_IntpConverter (object, PyArray_Dims *)
|
| 690 |
+
#int PyArray_BufferConverter (object, chunk)
|
| 691 |
+
int PyArray_AxisConverter (object, int *)
|
| 692 |
+
int PyArray_BoolConverter (object, npy_bool *)
|
| 693 |
+
int PyArray_ByteorderConverter (object, char *)
|
| 694 |
+
int PyArray_OrderConverter (object, NPY_ORDER *)
|
| 695 |
+
unsigned char PyArray_EquivTypes (dtype, dtype)
|
| 696 |
+
#object PyArray_Zeros (int, npy_intp *, dtype, int)
|
| 697 |
+
#object PyArray_Empty (int, npy_intp *, dtype, int)
|
| 698 |
+
object PyArray_Where (object, object, object)
|
| 699 |
+
object PyArray_Arange (double, double, double, int)
|
| 700 |
+
#object PyArray_ArangeObj (object, object, object, dtype)
|
| 701 |
+
int PyArray_SortkindConverter (object, NPY_SORTKIND *)
|
| 702 |
+
object PyArray_LexSort (object, int)
|
| 703 |
+
object PyArray_Round (ndarray, int, ndarray)
|
| 704 |
+
unsigned char PyArray_EquivTypenums (int, int)
|
| 705 |
+
int PyArray_RegisterDataType (dtype)
|
| 706 |
+
int PyArray_RegisterCastFunc (dtype, int, PyArray_VectorUnaryFunc *)
|
| 707 |
+
int PyArray_RegisterCanCast (dtype, int, NPY_SCALARKIND)
|
| 708 |
+
#void PyArray_InitArrFuncs (PyArray_ArrFuncs *)
|
| 709 |
+
object PyArray_IntTupleFromIntp (int, npy_intp *)
|
| 710 |
+
int PyArray_TypeNumFromName (char *)
|
| 711 |
+
int PyArray_ClipmodeConverter (object, NPY_CLIPMODE *)
|
| 712 |
+
#int PyArray_OutputConverter (object, ndarray*)
|
| 713 |
+
object PyArray_BroadcastToShape (object, npy_intp *, int)
|
| 714 |
+
void _PyArray_SigintHandler (int)
|
| 715 |
+
void* _PyArray_GetSigintBuf ()
|
| 716 |
+
#int PyArray_DescrAlignConverter (object, dtype*)
|
| 717 |
+
#int PyArray_DescrAlignConverter2 (object, dtype*)
|
| 718 |
+
int PyArray_SearchsideConverter (object, void *)
|
| 719 |
+
object PyArray_CheckAxis (ndarray, int *, int)
|
| 720 |
+
npy_intp PyArray_OverflowMultiplyList (npy_intp *, int)
|
| 721 |
+
int PyArray_CompareString (char *, char *, size_t)
|
| 722 |
+
int PyArray_SetBaseObject(ndarray, base) # NOTE: steals a reference to base! Use "set_array_base()" instead.
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
# Typedefs that matches the runtime dtype objects in
|
| 726 |
+
# the numpy module.
|
| 727 |
+
|
| 728 |
+
# The ones that are commented out needs an IFDEF function
|
| 729 |
+
# in Cython to enable them only on the right systems.
|
| 730 |
+
|
| 731 |
+
ctypedef npy_int8 int8_t
|
| 732 |
+
ctypedef npy_int16 int16_t
|
| 733 |
+
ctypedef npy_int32 int32_t
|
| 734 |
+
ctypedef npy_int64 int64_t
|
| 735 |
+
#ctypedef npy_int96 int96_t
|
| 736 |
+
#ctypedef npy_int128 int128_t
|
| 737 |
+
|
| 738 |
+
ctypedef npy_uint8 uint8_t
|
| 739 |
+
ctypedef npy_uint16 uint16_t
|
| 740 |
+
ctypedef npy_uint32 uint32_t
|
| 741 |
+
ctypedef npy_uint64 uint64_t
|
| 742 |
+
#ctypedef npy_uint96 uint96_t
|
| 743 |
+
#ctypedef npy_uint128 uint128_t
|
| 744 |
+
|
| 745 |
+
ctypedef npy_float32 float32_t
|
| 746 |
+
ctypedef npy_float64 float64_t
|
| 747 |
+
#ctypedef npy_float80 float80_t
|
| 748 |
+
#ctypedef npy_float128 float128_t
|
| 749 |
+
|
| 750 |
+
ctypedef float complex complex64_t
|
| 751 |
+
ctypedef double complex complex128_t
|
| 752 |
+
|
| 753 |
+
# The int types are mapped a bit surprising --
|
| 754 |
+
# numpy.int corresponds to 'l' and numpy.long to 'q'
|
| 755 |
+
ctypedef npy_long int_t
|
| 756 |
+
ctypedef npy_longlong long_t
|
| 757 |
+
ctypedef npy_longlong longlong_t
|
| 758 |
+
|
| 759 |
+
ctypedef npy_ulong uint_t
|
| 760 |
+
ctypedef npy_ulonglong ulong_t
|
| 761 |
+
ctypedef npy_ulonglong ulonglong_t
|
| 762 |
+
|
| 763 |
+
ctypedef npy_intp intp_t
|
| 764 |
+
ctypedef npy_uintp uintp_t
|
| 765 |
+
|
| 766 |
+
ctypedef npy_double float_t
|
| 767 |
+
ctypedef npy_double double_t
|
| 768 |
+
ctypedef npy_longdouble longdouble_t
|
| 769 |
+
|
| 770 |
+
ctypedef npy_cfloat cfloat_t
|
| 771 |
+
ctypedef npy_cdouble cdouble_t
|
| 772 |
+
ctypedef npy_clongdouble clongdouble_t
|
| 773 |
+
|
| 774 |
+
ctypedef npy_cdouble complex_t
|
| 775 |
+
|
| 776 |
+
cdef inline object PyArray_MultiIterNew1(a):
|
| 777 |
+
return PyArray_MultiIterNew(1, <void*>a)
|
| 778 |
+
|
| 779 |
+
cdef inline object PyArray_MultiIterNew2(a, b):
|
| 780 |
+
return PyArray_MultiIterNew(2, <void*>a, <void*>b)
|
| 781 |
+
|
| 782 |
+
cdef inline object PyArray_MultiIterNew3(a, b, c):
|
| 783 |
+
return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
|
| 784 |
+
|
| 785 |
+
cdef inline object PyArray_MultiIterNew4(a, b, c, d):
|
| 786 |
+
return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
|
| 787 |
+
|
| 788 |
+
cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
|
| 789 |
+
return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
|
| 790 |
+
|
| 791 |
+
cdef inline tuple PyDataType_SHAPE(dtype d):
|
| 792 |
+
if PyDataType_HASSUBARRAY(d):
|
| 793 |
+
return <tuple>d.subarray.shape
|
| 794 |
+
else:
|
| 795 |
+
return ()
|
| 796 |
+
|
| 797 |
+
|
| 798 |
+
cdef extern from "numpy/ndarrayobject.h":
|
| 799 |
+
PyTypeObject PyTimedeltaArrType_Type
|
| 800 |
+
PyTypeObject PyDatetimeArrType_Type
|
| 801 |
+
ctypedef int64_t npy_timedelta
|
| 802 |
+
ctypedef int64_t npy_datetime
|
| 803 |
+
|
| 804 |
+
cdef extern from "numpy/ndarraytypes.h":
|
| 805 |
+
ctypedef struct PyArray_DatetimeMetaData:
|
| 806 |
+
NPY_DATETIMEUNIT base
|
| 807 |
+
int64_t num
|
| 808 |
+
|
| 809 |
+
cdef extern from "numpy/arrayscalars.h":
|
| 810 |
+
|
| 811 |
+
# abstract types
|
| 812 |
+
ctypedef class numpy.generic [object PyObject]:
|
| 813 |
+
pass
|
| 814 |
+
ctypedef class numpy.number [object PyObject]:
|
| 815 |
+
pass
|
| 816 |
+
ctypedef class numpy.integer [object PyObject]:
|
| 817 |
+
pass
|
| 818 |
+
ctypedef class numpy.signedinteger [object PyObject]:
|
| 819 |
+
pass
|
| 820 |
+
ctypedef class numpy.unsignedinteger [object PyObject]:
|
| 821 |
+
pass
|
| 822 |
+
ctypedef class numpy.inexact [object PyObject]:
|
| 823 |
+
pass
|
| 824 |
+
ctypedef class numpy.floating [object PyObject]:
|
| 825 |
+
pass
|
| 826 |
+
ctypedef class numpy.complexfloating [object PyObject]:
|
| 827 |
+
pass
|
| 828 |
+
ctypedef class numpy.flexible [object PyObject]:
|
| 829 |
+
pass
|
| 830 |
+
ctypedef class numpy.character [object PyObject]:
|
| 831 |
+
pass
|
| 832 |
+
|
| 833 |
+
ctypedef struct PyDatetimeScalarObject:
|
| 834 |
+
# PyObject_HEAD
|
| 835 |
+
npy_datetime obval
|
| 836 |
+
PyArray_DatetimeMetaData obmeta
|
| 837 |
+
|
| 838 |
+
ctypedef struct PyTimedeltaScalarObject:
|
| 839 |
+
# PyObject_HEAD
|
| 840 |
+
npy_timedelta obval
|
| 841 |
+
PyArray_DatetimeMetaData obmeta
|
| 842 |
+
|
| 843 |
+
ctypedef enum NPY_DATETIMEUNIT:
|
| 844 |
+
NPY_FR_Y
|
| 845 |
+
NPY_FR_M
|
| 846 |
+
NPY_FR_W
|
| 847 |
+
NPY_FR_D
|
| 848 |
+
NPY_FR_B
|
| 849 |
+
NPY_FR_h
|
| 850 |
+
NPY_FR_m
|
| 851 |
+
NPY_FR_s
|
| 852 |
+
NPY_FR_ms
|
| 853 |
+
NPY_FR_us
|
| 854 |
+
NPY_FR_ns
|
| 855 |
+
NPY_FR_ps
|
| 856 |
+
NPY_FR_fs
|
| 857 |
+
NPY_FR_as
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
#
|
| 861 |
+
# ufunc API
|
| 862 |
+
#
|
| 863 |
+
|
| 864 |
+
cdef extern from "numpy/ufuncobject.h":
|
| 865 |
+
|
| 866 |
+
ctypedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
|
| 867 |
+
|
| 868 |
+
ctypedef class numpy.ufunc [object PyUFuncObject, check_size ignore]:
|
| 869 |
+
cdef:
|
| 870 |
+
int nin, nout, nargs
|
| 871 |
+
int identity
|
| 872 |
+
PyUFuncGenericFunction *functions
|
| 873 |
+
void **data
|
| 874 |
+
int ntypes
|
| 875 |
+
int check_return
|
| 876 |
+
char *name
|
| 877 |
+
char *types
|
| 878 |
+
char *doc
|
| 879 |
+
void *ptr
|
| 880 |
+
PyObject *obj
|
| 881 |
+
PyObject *userloops
|
| 882 |
+
|
| 883 |
+
cdef enum:
|
| 884 |
+
PyUFunc_Zero
|
| 885 |
+
PyUFunc_One
|
| 886 |
+
PyUFunc_None
|
| 887 |
+
UFUNC_ERR_IGNORE
|
| 888 |
+
UFUNC_ERR_WARN
|
| 889 |
+
UFUNC_ERR_RAISE
|
| 890 |
+
UFUNC_ERR_CALL
|
| 891 |
+
UFUNC_ERR_PRINT
|
| 892 |
+
UFUNC_ERR_LOG
|
| 893 |
+
UFUNC_MASK_DIVIDEBYZERO
|
| 894 |
+
UFUNC_MASK_OVERFLOW
|
| 895 |
+
UFUNC_MASK_UNDERFLOW
|
| 896 |
+
UFUNC_MASK_INVALID
|
| 897 |
+
UFUNC_SHIFT_DIVIDEBYZERO
|
| 898 |
+
UFUNC_SHIFT_OVERFLOW
|
| 899 |
+
UFUNC_SHIFT_UNDERFLOW
|
| 900 |
+
UFUNC_SHIFT_INVALID
|
| 901 |
+
UFUNC_FPE_DIVIDEBYZERO
|
| 902 |
+
UFUNC_FPE_OVERFLOW
|
| 903 |
+
UFUNC_FPE_UNDERFLOW
|
| 904 |
+
UFUNC_FPE_INVALID
|
| 905 |
+
UFUNC_ERR_DEFAULT
|
| 906 |
+
UFUNC_ERR_DEFAULT2
|
| 907 |
+
|
| 908 |
+
object PyUFunc_FromFuncAndData(PyUFuncGenericFunction *,
|
| 909 |
+
void **, char *, int, int, int, int, char *, char *, int)
|
| 910 |
+
int PyUFunc_RegisterLoopForType(ufunc, int,
|
| 911 |
+
PyUFuncGenericFunction, int *, void *)
|
| 912 |
+
void PyUFunc_f_f_As_d_d \
|
| 913 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 914 |
+
void PyUFunc_d_d \
|
| 915 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 916 |
+
void PyUFunc_f_f \
|
| 917 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 918 |
+
void PyUFunc_g_g \
|
| 919 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 920 |
+
void PyUFunc_F_F_As_D_D \
|
| 921 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 922 |
+
void PyUFunc_F_F \
|
| 923 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 924 |
+
void PyUFunc_D_D \
|
| 925 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 926 |
+
void PyUFunc_G_G \
|
| 927 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 928 |
+
void PyUFunc_O_O \
|
| 929 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 930 |
+
void PyUFunc_ff_f_As_dd_d \
|
| 931 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 932 |
+
void PyUFunc_ff_f \
|
| 933 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 934 |
+
void PyUFunc_dd_d \
|
| 935 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 936 |
+
void PyUFunc_gg_g \
|
| 937 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 938 |
+
void PyUFunc_FF_F_As_DD_D \
|
| 939 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 940 |
+
void PyUFunc_DD_D \
|
| 941 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 942 |
+
void PyUFunc_FF_F \
|
| 943 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 944 |
+
void PyUFunc_GG_G \
|
| 945 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 946 |
+
void PyUFunc_OO_O \
|
| 947 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 948 |
+
void PyUFunc_O_O_method \
|
| 949 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 950 |
+
void PyUFunc_OO_O_method \
|
| 951 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 952 |
+
void PyUFunc_On_Om \
|
| 953 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 954 |
+
int PyUFunc_GetPyValues \
|
| 955 |
+
(char *, int *, int *, PyObject **)
|
| 956 |
+
int PyUFunc_checkfperr \
|
| 957 |
+
(int, PyObject *, int *)
|
| 958 |
+
void PyUFunc_clearfperr()
|
| 959 |
+
int PyUFunc_getfperr()
|
| 960 |
+
int PyUFunc_handlefperr \
|
| 961 |
+
(int, PyObject *, int, int *)
|
| 962 |
+
int PyUFunc_ReplaceLoopBySignature \
|
| 963 |
+
(ufunc, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)
|
| 964 |
+
object PyUFunc_FromFuncAndDataAndSignature \
|
| 965 |
+
(PyUFuncGenericFunction *, void **, char *, int, int, int,
|
| 966 |
+
int, char *, char *, int, char *)
|
| 967 |
+
|
| 968 |
+
int _import_umath() except -1
|
| 969 |
+
|
| 970 |
+
cdef inline void set_array_base(ndarray arr, object base):
|
| 971 |
+
Py_INCREF(base) # important to do this before stealing the reference below!
|
| 972 |
+
PyArray_SetBaseObject(arr, base)
|
| 973 |
+
|
| 974 |
+
cdef inline object get_array_base(ndarray arr):
|
| 975 |
+
base = PyArray_BASE(arr)
|
| 976 |
+
if base is NULL:
|
| 977 |
+
return None
|
| 978 |
+
return <object>base
|
| 979 |
+
|
| 980 |
+
# Versions of the import_* functions which are more suitable for
|
| 981 |
+
# Cython code.
|
| 982 |
+
cdef inline int import_array() except -1:
|
| 983 |
+
try:
|
| 984 |
+
__pyx_import_array()
|
| 985 |
+
except Exception:
|
| 986 |
+
raise ImportError("numpy.core.multiarray failed to import")
|
| 987 |
+
|
| 988 |
+
cdef inline int import_umath() except -1:
|
| 989 |
+
try:
|
| 990 |
+
_import_umath()
|
| 991 |
+
except Exception:
|
| 992 |
+
raise ImportError("numpy.core.umath failed to import")
|
| 993 |
+
|
| 994 |
+
cdef inline int import_ufunc() except -1:
|
| 995 |
+
try:
|
| 996 |
+
_import_umath()
|
| 997 |
+
except Exception:
|
| 998 |
+
raise ImportError("numpy.core.umath failed to import")
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
cdef inline bint is_timedelta64_object(object obj):
|
| 1002 |
+
"""
|
| 1003 |
+
Cython equivalent of `isinstance(obj, np.timedelta64)`
|
| 1004 |
+
|
| 1005 |
+
Parameters
|
| 1006 |
+
----------
|
| 1007 |
+
obj : object
|
| 1008 |
+
|
| 1009 |
+
Returns
|
| 1010 |
+
-------
|
| 1011 |
+
bool
|
| 1012 |
+
"""
|
| 1013 |
+
return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
cdef inline bint is_datetime64_object(object obj):
|
| 1017 |
+
"""
|
| 1018 |
+
Cython equivalent of `isinstance(obj, np.datetime64)`
|
| 1019 |
+
|
| 1020 |
+
Parameters
|
| 1021 |
+
----------
|
| 1022 |
+
obj : object
|
| 1023 |
+
|
| 1024 |
+
Returns
|
| 1025 |
+
-------
|
| 1026 |
+
bool
|
| 1027 |
+
"""
|
| 1028 |
+
return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
cdef inline npy_datetime get_datetime64_value(object obj) nogil:
|
| 1032 |
+
"""
|
| 1033 |
+
returns the int64 value underlying scalar numpy datetime64 object
|
| 1034 |
+
|
| 1035 |
+
Note that to interpret this as a datetime, the corresponding unit is
|
| 1036 |
+
also needed. That can be found using `get_datetime64_unit`.
|
| 1037 |
+
"""
|
| 1038 |
+
return (<PyDatetimeScalarObject*>obj).obval
|
| 1039 |
+
|
| 1040 |
+
|
| 1041 |
+
cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:
|
| 1042 |
+
"""
|
| 1043 |
+
returns the int64 value underlying scalar numpy timedelta64 object
|
| 1044 |
+
"""
|
| 1045 |
+
return (<PyTimedeltaScalarObject*>obj).obval
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:
|
| 1049 |
+
"""
|
| 1050 |
+
returns the unit part of the dtype for a numpy datetime64 object.
|
| 1051 |
+
"""
|
| 1052 |
+
return <NPY_DATETIMEUNIT>(<PyDatetimeScalarObject*>obj).obmeta.base
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.pxd
ADDED
|
@@ -0,0 +1,1017 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_format_string_len = 255
|
| 10 |
+
|
| 11 |
+
cimport cpython.buffer as pybuf
|
| 12 |
+
from cpython.ref cimport Py_INCREF
|
| 13 |
+
from cpython.mem cimport PyObject_Malloc, PyObject_Free
|
| 14 |
+
from cpython.object cimport PyObject, PyTypeObject
|
| 15 |
+
from cpython.buffer cimport PyObject_GetBuffer
|
| 16 |
+
from cpython.type cimport type
|
| 17 |
+
cimport libc.stdio as stdio
|
| 18 |
+
|
| 19 |
+
cdef extern from "Python.h":
|
| 20 |
+
ctypedef int Py_intptr_t
|
| 21 |
+
bint PyObject_TypeCheck(object obj, PyTypeObject* type)
|
| 22 |
+
|
| 23 |
+
cdef extern from "numpy/arrayobject.h":
|
| 24 |
+
ctypedef Py_intptr_t npy_intp
|
| 25 |
+
ctypedef size_t npy_uintp
|
| 26 |
+
|
| 27 |
+
cdef enum NPY_TYPES:
|
| 28 |
+
NPY_BOOL
|
| 29 |
+
NPY_BYTE
|
| 30 |
+
NPY_UBYTE
|
| 31 |
+
NPY_SHORT
|
| 32 |
+
NPY_USHORT
|
| 33 |
+
NPY_INT
|
| 34 |
+
NPY_UINT
|
| 35 |
+
NPY_LONG
|
| 36 |
+
NPY_ULONG
|
| 37 |
+
NPY_LONGLONG
|
| 38 |
+
NPY_ULONGLONG
|
| 39 |
+
NPY_FLOAT
|
| 40 |
+
NPY_DOUBLE
|
| 41 |
+
NPY_LONGDOUBLE
|
| 42 |
+
NPY_CFLOAT
|
| 43 |
+
NPY_CDOUBLE
|
| 44 |
+
NPY_CLONGDOUBLE
|
| 45 |
+
NPY_OBJECT
|
| 46 |
+
NPY_STRING
|
| 47 |
+
NPY_UNICODE
|
| 48 |
+
NPY_VOID
|
| 49 |
+
NPY_DATETIME
|
| 50 |
+
NPY_TIMEDELTA
|
| 51 |
+
NPY_NTYPES
|
| 52 |
+
NPY_NOTYPE
|
| 53 |
+
|
| 54 |
+
NPY_INT8
|
| 55 |
+
NPY_INT16
|
| 56 |
+
NPY_INT32
|
| 57 |
+
NPY_INT64
|
| 58 |
+
NPY_INT128
|
| 59 |
+
NPY_INT256
|
| 60 |
+
NPY_UINT8
|
| 61 |
+
NPY_UINT16
|
| 62 |
+
NPY_UINT32
|
| 63 |
+
NPY_UINT64
|
| 64 |
+
NPY_UINT128
|
| 65 |
+
NPY_UINT256
|
| 66 |
+
NPY_FLOAT16
|
| 67 |
+
NPY_FLOAT32
|
| 68 |
+
NPY_FLOAT64
|
| 69 |
+
NPY_FLOAT80
|
| 70 |
+
NPY_FLOAT96
|
| 71 |
+
NPY_FLOAT128
|
| 72 |
+
NPY_FLOAT256
|
| 73 |
+
NPY_COMPLEX32
|
| 74 |
+
NPY_COMPLEX64
|
| 75 |
+
NPY_COMPLEX128
|
| 76 |
+
NPY_COMPLEX160
|
| 77 |
+
NPY_COMPLEX192
|
| 78 |
+
NPY_COMPLEX256
|
| 79 |
+
NPY_COMPLEX512
|
| 80 |
+
|
| 81 |
+
NPY_INTP
|
| 82 |
+
|
| 83 |
+
ctypedef enum NPY_ORDER:
|
| 84 |
+
NPY_ANYORDER
|
| 85 |
+
NPY_CORDER
|
| 86 |
+
NPY_FORTRANORDER
|
| 87 |
+
NPY_KEEPORDER
|
| 88 |
+
|
| 89 |
+
ctypedef enum NPY_CASTING:
|
| 90 |
+
NPY_NO_CASTING
|
| 91 |
+
NPY_EQUIV_CASTING
|
| 92 |
+
NPY_SAFE_CASTING
|
| 93 |
+
NPY_SAME_KIND_CASTING
|
| 94 |
+
NPY_UNSAFE_CASTING
|
| 95 |
+
|
| 96 |
+
ctypedef enum NPY_CLIPMODE:
|
| 97 |
+
NPY_CLIP
|
| 98 |
+
NPY_WRAP
|
| 99 |
+
NPY_RAISE
|
| 100 |
+
|
| 101 |
+
ctypedef enum NPY_SCALARKIND:
|
| 102 |
+
NPY_NOSCALAR,
|
| 103 |
+
NPY_BOOL_SCALAR,
|
| 104 |
+
NPY_INTPOS_SCALAR,
|
| 105 |
+
NPY_INTNEG_SCALAR,
|
| 106 |
+
NPY_FLOAT_SCALAR,
|
| 107 |
+
NPY_COMPLEX_SCALAR,
|
| 108 |
+
NPY_OBJECT_SCALAR
|
| 109 |
+
|
| 110 |
+
ctypedef enum NPY_SORTKIND:
|
| 111 |
+
NPY_QUICKSORT
|
| 112 |
+
NPY_HEAPSORT
|
| 113 |
+
NPY_MERGESORT
|
| 114 |
+
|
| 115 |
+
ctypedef enum NPY_SEARCHSIDE:
|
| 116 |
+
NPY_SEARCHLEFT
|
| 117 |
+
NPY_SEARCHRIGHT
|
| 118 |
+
|
| 119 |
+
enum:
|
| 120 |
+
# DEPRECATED since NumPy 1.7 ! Do not use in new code!
|
| 121 |
+
NPY_C_CONTIGUOUS
|
| 122 |
+
NPY_F_CONTIGUOUS
|
| 123 |
+
NPY_CONTIGUOUS
|
| 124 |
+
NPY_FORTRAN
|
| 125 |
+
NPY_OWNDATA
|
| 126 |
+
NPY_FORCECAST
|
| 127 |
+
NPY_ENSURECOPY
|
| 128 |
+
NPY_ENSUREARRAY
|
| 129 |
+
NPY_ELEMENTSTRIDES
|
| 130 |
+
NPY_ALIGNED
|
| 131 |
+
NPY_NOTSWAPPED
|
| 132 |
+
NPY_WRITEABLE
|
| 133 |
+
NPY_ARR_HAS_DESCR
|
| 134 |
+
|
| 135 |
+
NPY_BEHAVED
|
| 136 |
+
NPY_BEHAVED_NS
|
| 137 |
+
NPY_CARRAY
|
| 138 |
+
NPY_CARRAY_RO
|
| 139 |
+
NPY_FARRAY
|
| 140 |
+
NPY_FARRAY_RO
|
| 141 |
+
NPY_DEFAULT
|
| 142 |
+
|
| 143 |
+
NPY_IN_ARRAY
|
| 144 |
+
NPY_OUT_ARRAY
|
| 145 |
+
NPY_INOUT_ARRAY
|
| 146 |
+
NPY_IN_FARRAY
|
| 147 |
+
NPY_OUT_FARRAY
|
| 148 |
+
NPY_INOUT_FARRAY
|
| 149 |
+
|
| 150 |
+
NPY_UPDATE_ALL
|
| 151 |
+
|
| 152 |
+
enum:
|
| 153 |
+
# Added in NumPy 1.7 to replace the deprecated enums above.
|
| 154 |
+
NPY_ARRAY_C_CONTIGUOUS
|
| 155 |
+
NPY_ARRAY_F_CONTIGUOUS
|
| 156 |
+
NPY_ARRAY_OWNDATA
|
| 157 |
+
NPY_ARRAY_FORCECAST
|
| 158 |
+
NPY_ARRAY_ENSURECOPY
|
| 159 |
+
NPY_ARRAY_ENSUREARRAY
|
| 160 |
+
NPY_ARRAY_ELEMENTSTRIDES
|
| 161 |
+
NPY_ARRAY_ALIGNED
|
| 162 |
+
NPY_ARRAY_NOTSWAPPED
|
| 163 |
+
NPY_ARRAY_WRITEABLE
|
| 164 |
+
NPY_ARRAY_WRITEBACKIFCOPY
|
| 165 |
+
|
| 166 |
+
NPY_ARRAY_BEHAVED
|
| 167 |
+
NPY_ARRAY_BEHAVED_NS
|
| 168 |
+
NPY_ARRAY_CARRAY
|
| 169 |
+
NPY_ARRAY_CARRAY_RO
|
| 170 |
+
NPY_ARRAY_FARRAY
|
| 171 |
+
NPY_ARRAY_FARRAY_RO
|
| 172 |
+
NPY_ARRAY_DEFAULT
|
| 173 |
+
|
| 174 |
+
NPY_ARRAY_IN_ARRAY
|
| 175 |
+
NPY_ARRAY_OUT_ARRAY
|
| 176 |
+
NPY_ARRAY_INOUT_ARRAY
|
| 177 |
+
NPY_ARRAY_IN_FARRAY
|
| 178 |
+
NPY_ARRAY_OUT_FARRAY
|
| 179 |
+
NPY_ARRAY_INOUT_FARRAY
|
| 180 |
+
|
| 181 |
+
NPY_ARRAY_UPDATE_ALL
|
| 182 |
+
|
| 183 |
+
cdef enum:
|
| 184 |
+
NPY_MAXDIMS
|
| 185 |
+
|
| 186 |
+
npy_intp NPY_MAX_ELSIZE
|
| 187 |
+
|
| 188 |
+
ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, void *)
|
| 189 |
+
|
| 190 |
+
ctypedef struct PyArray_ArrayDescr:
|
| 191 |
+
# shape is a tuple, but Cython doesn't support "tuple shape"
|
| 192 |
+
# inside a non-PyObject declaration, so we have to declare it
|
| 193 |
+
# as just a PyObject*.
|
| 194 |
+
PyObject* shape
|
| 195 |
+
|
| 196 |
+
ctypedef struct PyArray_Descr:
|
| 197 |
+
pass
|
| 198 |
+
|
| 199 |
+
ctypedef class numpy.dtype [object PyArray_Descr, check_size ignore]:
|
| 200 |
+
# Use PyDataType_* macros when possible, however there are no macros
|
| 201 |
+
# for accessing some of the fields, so some are defined.
|
| 202 |
+
cdef PyTypeObject* typeobj
|
| 203 |
+
cdef char kind
|
| 204 |
+
cdef char type
|
| 205 |
+
# Numpy sometimes mutates this without warning (e.g. it'll
|
| 206 |
+
# sometimes change "|" to "<" in shared dtype objects on
|
| 207 |
+
# little-endian machines). If this matters to you, use
|
| 208 |
+
# PyArray_IsNativeByteOrder(dtype.byteorder) instead of
|
| 209 |
+
# directly accessing this field.
|
| 210 |
+
cdef char byteorder
|
| 211 |
+
cdef char flags
|
| 212 |
+
cdef int type_num
|
| 213 |
+
cdef int itemsize "elsize"
|
| 214 |
+
cdef int alignment
|
| 215 |
+
cdef object fields
|
| 216 |
+
cdef tuple names
|
| 217 |
+
# Use PyDataType_HASSUBARRAY to test whether this field is
|
| 218 |
+
# valid (the pointer can be NULL). Most users should access
|
| 219 |
+
# this field via the inline helper method PyDataType_SHAPE.
|
| 220 |
+
cdef PyArray_ArrayDescr* subarray
|
| 221 |
+
|
| 222 |
+
ctypedef class numpy.flatiter [object PyArrayIterObject, check_size ignore]:
|
| 223 |
+
# Use through macros
|
| 224 |
+
pass
|
| 225 |
+
|
| 226 |
+
ctypedef class numpy.broadcast [object PyArrayMultiIterObject, check_size ignore]:
|
| 227 |
+
cdef int numiter
|
| 228 |
+
cdef npy_intp size, index
|
| 229 |
+
cdef int nd
|
| 230 |
+
cdef npy_intp *dimensions
|
| 231 |
+
cdef void **iters
|
| 232 |
+
|
| 233 |
+
ctypedef struct PyArrayObject:
|
| 234 |
+
# For use in situations where ndarray can't replace PyArrayObject*,
|
| 235 |
+
# like PyArrayObject**.
|
| 236 |
+
pass
|
| 237 |
+
|
| 238 |
+
ctypedef class numpy.ndarray [object PyArrayObject, check_size ignore]:
|
| 239 |
+
cdef __cythonbufferdefaults__ = {"mode": "strided"}
|
| 240 |
+
|
| 241 |
+
cdef:
|
| 242 |
+
# Only taking a few of the most commonly used and stable fields.
|
| 243 |
+
# One should use PyArray_* macros instead to access the C fields.
|
| 244 |
+
char *data
|
| 245 |
+
int ndim "nd"
|
| 246 |
+
npy_intp *shape "dimensions"
|
| 247 |
+
npy_intp *strides
|
| 248 |
+
dtype descr # deprecated since NumPy 1.7 !
|
| 249 |
+
PyObject* base # NOT PUBLIC, DO NOT USE !
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
ctypedef unsigned char npy_bool
|
| 254 |
+
|
| 255 |
+
ctypedef signed char npy_byte
|
| 256 |
+
ctypedef signed short npy_short
|
| 257 |
+
ctypedef signed int npy_int
|
| 258 |
+
ctypedef signed long npy_long
|
| 259 |
+
ctypedef signed long long npy_longlong
|
| 260 |
+
|
| 261 |
+
ctypedef unsigned char npy_ubyte
|
| 262 |
+
ctypedef unsigned short npy_ushort
|
| 263 |
+
ctypedef unsigned int npy_uint
|
| 264 |
+
ctypedef unsigned long npy_ulong
|
| 265 |
+
ctypedef unsigned long long npy_ulonglong
|
| 266 |
+
|
| 267 |
+
ctypedef float npy_float
|
| 268 |
+
ctypedef double npy_double
|
| 269 |
+
ctypedef long double npy_longdouble
|
| 270 |
+
|
| 271 |
+
ctypedef signed char npy_int8
|
| 272 |
+
ctypedef signed short npy_int16
|
| 273 |
+
ctypedef signed int npy_int32
|
| 274 |
+
ctypedef signed long long npy_int64
|
| 275 |
+
ctypedef signed long long npy_int96
|
| 276 |
+
ctypedef signed long long npy_int128
|
| 277 |
+
|
| 278 |
+
ctypedef unsigned char npy_uint8
|
| 279 |
+
ctypedef unsigned short npy_uint16
|
| 280 |
+
ctypedef unsigned int npy_uint32
|
| 281 |
+
ctypedef unsigned long long npy_uint64
|
| 282 |
+
ctypedef unsigned long long npy_uint96
|
| 283 |
+
ctypedef unsigned long long npy_uint128
|
| 284 |
+
|
| 285 |
+
ctypedef float npy_float32
|
| 286 |
+
ctypedef double npy_float64
|
| 287 |
+
ctypedef long double npy_float80
|
| 288 |
+
ctypedef long double npy_float96
|
| 289 |
+
ctypedef long double npy_float128
|
| 290 |
+
|
| 291 |
+
ctypedef struct npy_cfloat:
|
| 292 |
+
float real
|
| 293 |
+
float imag
|
| 294 |
+
|
| 295 |
+
ctypedef struct npy_cdouble:
|
| 296 |
+
double real
|
| 297 |
+
double imag
|
| 298 |
+
|
| 299 |
+
ctypedef struct npy_clongdouble:
|
| 300 |
+
long double real
|
| 301 |
+
long double imag
|
| 302 |
+
|
| 303 |
+
ctypedef struct npy_complex64:
|
| 304 |
+
float real
|
| 305 |
+
float imag
|
| 306 |
+
|
| 307 |
+
ctypedef struct npy_complex128:
|
| 308 |
+
double real
|
| 309 |
+
double imag
|
| 310 |
+
|
| 311 |
+
ctypedef struct npy_complex160:
|
| 312 |
+
long double real
|
| 313 |
+
long double imag
|
| 314 |
+
|
| 315 |
+
ctypedef struct npy_complex192:
|
| 316 |
+
long double real
|
| 317 |
+
long double imag
|
| 318 |
+
|
| 319 |
+
ctypedef struct npy_complex256:
|
| 320 |
+
long double real
|
| 321 |
+
long double imag
|
| 322 |
+
|
| 323 |
+
ctypedef struct PyArray_Dims:
|
| 324 |
+
npy_intp *ptr
|
| 325 |
+
int len
|
| 326 |
+
|
| 327 |
+
int _import_array() except -1
|
| 328 |
+
# A second definition so _import_array isn't marked as used when we use it here.
|
| 329 |
+
# Do not use - subject to change any time.
|
| 330 |
+
int __pyx_import_array "_import_array"() except -1
|
| 331 |
+
|
| 332 |
+
#
|
| 333 |
+
# Macros from ndarrayobject.h
|
| 334 |
+
#
|
| 335 |
+
bint PyArray_CHKFLAGS(ndarray m, int flags) nogil
|
| 336 |
+
bint PyArray_IS_C_CONTIGUOUS(ndarray arr) nogil
|
| 337 |
+
bint PyArray_IS_F_CONTIGUOUS(ndarray arr) nogil
|
| 338 |
+
bint PyArray_ISCONTIGUOUS(ndarray m) nogil
|
| 339 |
+
bint PyArray_ISWRITEABLE(ndarray m) nogil
|
| 340 |
+
bint PyArray_ISALIGNED(ndarray m) nogil
|
| 341 |
+
|
| 342 |
+
int PyArray_NDIM(ndarray) nogil
|
| 343 |
+
bint PyArray_ISONESEGMENT(ndarray) nogil
|
| 344 |
+
bint PyArray_ISFORTRAN(ndarray) nogil
|
| 345 |
+
int PyArray_FORTRANIF(ndarray) nogil
|
| 346 |
+
|
| 347 |
+
void* PyArray_DATA(ndarray) nogil
|
| 348 |
+
char* PyArray_BYTES(ndarray) nogil
|
| 349 |
+
|
| 350 |
+
npy_intp* PyArray_DIMS(ndarray) nogil
|
| 351 |
+
npy_intp* PyArray_STRIDES(ndarray) nogil
|
| 352 |
+
npy_intp PyArray_DIM(ndarray, size_t) nogil
|
| 353 |
+
npy_intp PyArray_STRIDE(ndarray, size_t) nogil
|
| 354 |
+
|
| 355 |
+
PyObject *PyArray_BASE(ndarray) nogil # returns borrowed reference!
|
| 356 |
+
PyArray_Descr *PyArray_DESCR(ndarray) nogil # returns borrowed reference to dtype!
|
| 357 |
+
int PyArray_FLAGS(ndarray) nogil
|
| 358 |
+
npy_intp PyArray_ITEMSIZE(ndarray) nogil
|
| 359 |
+
int PyArray_TYPE(ndarray arr) nogil
|
| 360 |
+
|
| 361 |
+
object PyArray_GETITEM(ndarray arr, void *itemptr)
|
| 362 |
+
int PyArray_SETITEM(ndarray arr, void *itemptr, object obj)
|
| 363 |
+
|
| 364 |
+
bint PyTypeNum_ISBOOL(int) nogil
|
| 365 |
+
bint PyTypeNum_ISUNSIGNED(int) nogil
|
| 366 |
+
bint PyTypeNum_ISSIGNED(int) nogil
|
| 367 |
+
bint PyTypeNum_ISINTEGER(int) nogil
|
| 368 |
+
bint PyTypeNum_ISFLOAT(int) nogil
|
| 369 |
+
bint PyTypeNum_ISNUMBER(int) nogil
|
| 370 |
+
bint PyTypeNum_ISSTRING(int) nogil
|
| 371 |
+
bint PyTypeNum_ISCOMPLEX(int) nogil
|
| 372 |
+
bint PyTypeNum_ISPYTHON(int) nogil
|
| 373 |
+
bint PyTypeNum_ISFLEXIBLE(int) nogil
|
| 374 |
+
bint PyTypeNum_ISUSERDEF(int) nogil
|
| 375 |
+
bint PyTypeNum_ISEXTENDED(int) nogil
|
| 376 |
+
bint PyTypeNum_ISOBJECT(int) nogil
|
| 377 |
+
|
| 378 |
+
bint PyDataType_ISBOOL(dtype) nogil
|
| 379 |
+
bint PyDataType_ISUNSIGNED(dtype) nogil
|
| 380 |
+
bint PyDataType_ISSIGNED(dtype) nogil
|
| 381 |
+
bint PyDataType_ISINTEGER(dtype) nogil
|
| 382 |
+
bint PyDataType_ISFLOAT(dtype) nogil
|
| 383 |
+
bint PyDataType_ISNUMBER(dtype) nogil
|
| 384 |
+
bint PyDataType_ISSTRING(dtype) nogil
|
| 385 |
+
bint PyDataType_ISCOMPLEX(dtype) nogil
|
| 386 |
+
bint PyDataType_ISPYTHON(dtype) nogil
|
| 387 |
+
bint PyDataType_ISFLEXIBLE(dtype) nogil
|
| 388 |
+
bint PyDataType_ISUSERDEF(dtype) nogil
|
| 389 |
+
bint PyDataType_ISEXTENDED(dtype) nogil
|
| 390 |
+
bint PyDataType_ISOBJECT(dtype) nogil
|
| 391 |
+
bint PyDataType_HASFIELDS(dtype) nogil
|
| 392 |
+
bint PyDataType_HASSUBARRAY(dtype) nogil
|
| 393 |
+
|
| 394 |
+
bint PyArray_ISBOOL(ndarray) nogil
|
| 395 |
+
bint PyArray_ISUNSIGNED(ndarray) nogil
|
| 396 |
+
bint PyArray_ISSIGNED(ndarray) nogil
|
| 397 |
+
bint PyArray_ISINTEGER(ndarray) nogil
|
| 398 |
+
bint PyArray_ISFLOAT(ndarray) nogil
|
| 399 |
+
bint PyArray_ISNUMBER(ndarray) nogil
|
| 400 |
+
bint PyArray_ISSTRING(ndarray) nogil
|
| 401 |
+
bint PyArray_ISCOMPLEX(ndarray) nogil
|
| 402 |
+
bint PyArray_ISPYTHON(ndarray) nogil
|
| 403 |
+
bint PyArray_ISFLEXIBLE(ndarray) nogil
|
| 404 |
+
bint PyArray_ISUSERDEF(ndarray) nogil
|
| 405 |
+
bint PyArray_ISEXTENDED(ndarray) nogil
|
| 406 |
+
bint PyArray_ISOBJECT(ndarray) nogil
|
| 407 |
+
bint PyArray_HASFIELDS(ndarray) nogil
|
| 408 |
+
|
| 409 |
+
bint PyArray_ISVARIABLE(ndarray) nogil
|
| 410 |
+
|
| 411 |
+
bint PyArray_SAFEALIGNEDCOPY(ndarray) nogil
|
| 412 |
+
bint PyArray_ISNBO(char) nogil # works on ndarray.byteorder
|
| 413 |
+
bint PyArray_IsNativeByteOrder(char) nogil # works on ndarray.byteorder
|
| 414 |
+
bint PyArray_ISNOTSWAPPED(ndarray) nogil
|
| 415 |
+
bint PyArray_ISBYTESWAPPED(ndarray) nogil
|
| 416 |
+
|
| 417 |
+
bint PyArray_FLAGSWAP(ndarray, int) nogil
|
| 418 |
+
|
| 419 |
+
bint PyArray_ISCARRAY(ndarray) nogil
|
| 420 |
+
bint PyArray_ISCARRAY_RO(ndarray) nogil
|
| 421 |
+
bint PyArray_ISFARRAY(ndarray) nogil
|
| 422 |
+
bint PyArray_ISFARRAY_RO(ndarray) nogil
|
| 423 |
+
bint PyArray_ISBEHAVED(ndarray) nogil
|
| 424 |
+
bint PyArray_ISBEHAVED_RO(ndarray) nogil
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
bint PyDataType_ISNOTSWAPPED(dtype) nogil
|
| 428 |
+
bint PyDataType_ISBYTESWAPPED(dtype) nogil
|
| 429 |
+
|
| 430 |
+
bint PyArray_DescrCheck(object)
|
| 431 |
+
|
| 432 |
+
bint PyArray_Check(object)
|
| 433 |
+
bint PyArray_CheckExact(object)
|
| 434 |
+
|
| 435 |
+
# Cannot be supported due to out arg:
|
| 436 |
+
# bint PyArray_HasArrayInterfaceType(object, dtype, object, object&)
|
| 437 |
+
# bint PyArray_HasArrayInterface(op, out)
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
bint PyArray_IsZeroDim(object)
|
| 441 |
+
# Cannot be supported due to ## ## in macro:
|
| 442 |
+
# bint PyArray_IsScalar(object, verbatim work)
|
| 443 |
+
bint PyArray_CheckScalar(object)
|
| 444 |
+
bint PyArray_IsPythonNumber(object)
|
| 445 |
+
bint PyArray_IsPythonScalar(object)
|
| 446 |
+
bint PyArray_IsAnyScalar(object)
|
| 447 |
+
bint PyArray_CheckAnyScalar(object)
|
| 448 |
+
|
| 449 |
+
ndarray PyArray_GETCONTIGUOUS(ndarray)
|
| 450 |
+
bint PyArray_SAMESHAPE(ndarray, ndarray) nogil
|
| 451 |
+
npy_intp PyArray_SIZE(ndarray) nogil
|
| 452 |
+
npy_intp PyArray_NBYTES(ndarray) nogil
|
| 453 |
+
|
| 454 |
+
object PyArray_FROM_O(object)
|
| 455 |
+
object PyArray_FROM_OF(object m, int flags)
|
| 456 |
+
object PyArray_FROM_OT(object m, int type)
|
| 457 |
+
object PyArray_FROM_OTF(object m, int type, int flags)
|
| 458 |
+
object PyArray_FROMANY(object m, int type, int min, int max, int flags)
|
| 459 |
+
object PyArray_ZEROS(int nd, npy_intp* dims, int type, int fortran)
|
| 460 |
+
object PyArray_EMPTY(int nd, npy_intp* dims, int type, int fortran)
|
| 461 |
+
void PyArray_FILLWBYTE(object, int val)
|
| 462 |
+
npy_intp PyArray_REFCOUNT(object)
|
| 463 |
+
object PyArray_ContiguousFromAny(op, int, int min_depth, int max_depth)
|
| 464 |
+
unsigned char PyArray_EquivArrTypes(ndarray a1, ndarray a2)
|
| 465 |
+
bint PyArray_EquivByteorders(int b1, int b2) nogil
|
| 466 |
+
object PyArray_SimpleNew(int nd, npy_intp* dims, int typenum)
|
| 467 |
+
object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data)
|
| 468 |
+
#object PyArray_SimpleNewFromDescr(int nd, npy_intp* dims, dtype descr)
|
| 469 |
+
object PyArray_ToScalar(void* data, ndarray arr)
|
| 470 |
+
|
| 471 |
+
void* PyArray_GETPTR1(ndarray m, npy_intp i) nogil
|
| 472 |
+
void* PyArray_GETPTR2(ndarray m, npy_intp i, npy_intp j) nogil
|
| 473 |
+
void* PyArray_GETPTR3(ndarray m, npy_intp i, npy_intp j, npy_intp k) nogil
|
| 474 |
+
void* PyArray_GETPTR4(ndarray m, npy_intp i, npy_intp j, npy_intp k, npy_intp l) nogil
|
| 475 |
+
|
| 476 |
+
void PyArray_XDECREF_ERR(ndarray)
|
| 477 |
+
# Cannot be supported due to out arg
|
| 478 |
+
# void PyArray_DESCR_REPLACE(descr)
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
object PyArray_Copy(ndarray)
|
| 482 |
+
object PyArray_FromObject(object op, int type, int min_depth, int max_depth)
|
| 483 |
+
object PyArray_ContiguousFromObject(object op, int type, int min_depth, int max_depth)
|
| 484 |
+
object PyArray_CopyFromObject(object op, int type, int min_depth, int max_depth)
|
| 485 |
+
|
| 486 |
+
object PyArray_Cast(ndarray mp, int type_num)
|
| 487 |
+
object PyArray_Take(ndarray ap, object items, int axis)
|
| 488 |
+
object PyArray_Put(ndarray ap, object items, object values)
|
| 489 |
+
|
| 490 |
+
void PyArray_ITER_RESET(flatiter it) nogil
|
| 491 |
+
void PyArray_ITER_NEXT(flatiter it) nogil
|
| 492 |
+
void PyArray_ITER_GOTO(flatiter it, npy_intp* destination) nogil
|
| 493 |
+
void PyArray_ITER_GOTO1D(flatiter it, npy_intp ind) nogil
|
| 494 |
+
void* PyArray_ITER_DATA(flatiter it) nogil
|
| 495 |
+
bint PyArray_ITER_NOTDONE(flatiter it) nogil
|
| 496 |
+
|
| 497 |
+
void PyArray_MultiIter_RESET(broadcast multi) nogil
|
| 498 |
+
void PyArray_MultiIter_NEXT(broadcast multi) nogil
|
| 499 |
+
void PyArray_MultiIter_GOTO(broadcast multi, npy_intp dest) nogil
|
| 500 |
+
void PyArray_MultiIter_GOTO1D(broadcast multi, npy_intp ind) nogil
|
| 501 |
+
void* PyArray_MultiIter_DATA(broadcast multi, npy_intp i) nogil
|
| 502 |
+
void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil
|
| 503 |
+
bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil
|
| 504 |
+
|
| 505 |
+
# Functions from __multiarray_api.h
|
| 506 |
+
|
| 507 |
+
# Functions taking dtype and returning object/ndarray are disabled
|
| 508 |
+
# for now as they steal dtype references. I'm conservative and disable
|
| 509 |
+
# more than is probably needed until it can be checked further.
|
| 510 |
+
int PyArray_SetNumericOps (object)
|
| 511 |
+
object PyArray_GetNumericOps ()
|
| 512 |
+
int PyArray_INCREF (ndarray)
|
| 513 |
+
int PyArray_XDECREF (ndarray)
|
| 514 |
+
void PyArray_SetStringFunction (object, int)
|
| 515 |
+
dtype PyArray_DescrFromType (int)
|
| 516 |
+
object PyArray_TypeObjectFromType (int)
|
| 517 |
+
char * PyArray_Zero (ndarray)
|
| 518 |
+
char * PyArray_One (ndarray)
|
| 519 |
+
#object PyArray_CastToType (ndarray, dtype, int)
|
| 520 |
+
int PyArray_CastTo (ndarray, ndarray)
|
| 521 |
+
int PyArray_CastAnyTo (ndarray, ndarray)
|
| 522 |
+
int PyArray_CanCastSafely (int, int)
|
| 523 |
+
npy_bool PyArray_CanCastTo (dtype, dtype)
|
| 524 |
+
int PyArray_ObjectType (object, int)
|
| 525 |
+
dtype PyArray_DescrFromObject (object, dtype)
|
| 526 |
+
#ndarray* PyArray_ConvertToCommonType (object, int *)
|
| 527 |
+
dtype PyArray_DescrFromScalar (object)
|
| 528 |
+
dtype PyArray_DescrFromTypeObject (object)
|
| 529 |
+
npy_intp PyArray_Size (object)
|
| 530 |
+
#object PyArray_Scalar (void *, dtype, object)
|
| 531 |
+
#object PyArray_FromScalar (object, dtype)
|
| 532 |
+
void PyArray_ScalarAsCtype (object, void *)
|
| 533 |
+
#int PyArray_CastScalarToCtype (object, void *, dtype)
|
| 534 |
+
#int PyArray_CastScalarDirect (object, dtype, void *, int)
|
| 535 |
+
object PyArray_ScalarFromObject (object)
|
| 536 |
+
#PyArray_VectorUnaryFunc * PyArray_GetCastFunc (dtype, int)
|
| 537 |
+
object PyArray_FromDims (int, int *, int)
|
| 538 |
+
#object PyArray_FromDimsAndDataAndDescr (int, int *, dtype, char *)
|
| 539 |
+
#object PyArray_FromAny (object, dtype, int, int, int, object)
|
| 540 |
+
object PyArray_EnsureArray (object)
|
| 541 |
+
object PyArray_EnsureAnyArray (object)
|
| 542 |
+
#object PyArray_FromFile (stdio.FILE *, dtype, npy_intp, char *)
|
| 543 |
+
#object PyArray_FromString (char *, npy_intp, dtype, npy_intp, char *)
|
| 544 |
+
#object PyArray_FromBuffer (object, dtype, npy_intp, npy_intp)
|
| 545 |
+
#object PyArray_FromIter (object, dtype, npy_intp)
|
| 546 |
+
object PyArray_Return (ndarray)
|
| 547 |
+
#object PyArray_GetField (ndarray, dtype, int)
|
| 548 |
+
#int PyArray_SetField (ndarray, dtype, int, object)
|
| 549 |
+
object PyArray_Byteswap (ndarray, npy_bool)
|
| 550 |
+
object PyArray_Resize (ndarray, PyArray_Dims *, int, NPY_ORDER)
|
| 551 |
+
int PyArray_MoveInto (ndarray, ndarray)
|
| 552 |
+
int PyArray_CopyInto (ndarray, ndarray)
|
| 553 |
+
int PyArray_CopyAnyInto (ndarray, ndarray)
|
| 554 |
+
int PyArray_CopyObject (ndarray, object)
|
| 555 |
+
object PyArray_NewCopy (ndarray, NPY_ORDER)
|
| 556 |
+
object PyArray_ToList (ndarray)
|
| 557 |
+
object PyArray_ToString (ndarray, NPY_ORDER)
|
| 558 |
+
int PyArray_ToFile (ndarray, stdio.FILE *, char *, char *)
|
| 559 |
+
int PyArray_Dump (object, object, int)
|
| 560 |
+
object PyArray_Dumps (object, int)
|
| 561 |
+
int PyArray_ValidType (int)
|
| 562 |
+
void PyArray_UpdateFlags (ndarray, int)
|
| 563 |
+
object PyArray_New (type, int, npy_intp *, int, npy_intp *, void *, int, int, object)
|
| 564 |
+
#object PyArray_NewFromDescr (type, dtype, int, npy_intp *, npy_intp *, void *, int, object)
|
| 565 |
+
#dtype PyArray_DescrNew (dtype)
|
| 566 |
+
dtype PyArray_DescrNewFromType (int)
|
| 567 |
+
double PyArray_GetPriority (object, double)
|
| 568 |
+
object PyArray_IterNew (object)
|
| 569 |
+
object PyArray_MultiIterNew (int, ...)
|
| 570 |
+
|
| 571 |
+
int PyArray_PyIntAsInt (object)
|
| 572 |
+
npy_intp PyArray_PyIntAsIntp (object)
|
| 573 |
+
int PyArray_Broadcast (broadcast)
|
| 574 |
+
void PyArray_FillObjectArray (ndarray, object)
|
| 575 |
+
int PyArray_FillWithScalar (ndarray, object)
|
| 576 |
+
npy_bool PyArray_CheckStrides (int, int, npy_intp, npy_intp, npy_intp *, npy_intp *)
|
| 577 |
+
dtype PyArray_DescrNewByteorder (dtype, char)
|
| 578 |
+
object PyArray_IterAllButAxis (object, int *)
|
| 579 |
+
#object PyArray_CheckFromAny (object, dtype, int, int, int, object)
|
| 580 |
+
#object PyArray_FromArray (ndarray, dtype, int)
|
| 581 |
+
object PyArray_FromInterface (object)
|
| 582 |
+
object PyArray_FromStructInterface (object)
|
| 583 |
+
#object PyArray_FromArrayAttr (object, dtype, object)
|
| 584 |
+
#NPY_SCALARKIND PyArray_ScalarKind (int, ndarray*)
|
| 585 |
+
int PyArray_CanCoerceScalar (int, int, NPY_SCALARKIND)
|
| 586 |
+
object PyArray_NewFlagsObject (object)
|
| 587 |
+
npy_bool PyArray_CanCastScalar (type, type)
|
| 588 |
+
#int PyArray_CompareUCS4 (npy_ucs4 *, npy_ucs4 *, register size_t)
|
| 589 |
+
int PyArray_RemoveSmallest (broadcast)
|
| 590 |
+
int PyArray_ElementStrides (object)
|
| 591 |
+
void PyArray_Item_INCREF (char *, dtype)
|
| 592 |
+
void PyArray_Item_XDECREF (char *, dtype)
|
| 593 |
+
object PyArray_FieldNames (object)
|
| 594 |
+
object PyArray_Transpose (ndarray, PyArray_Dims *)
|
| 595 |
+
object PyArray_TakeFrom (ndarray, object, int, ndarray, NPY_CLIPMODE)
|
| 596 |
+
object PyArray_PutTo (ndarray, object, object, NPY_CLIPMODE)
|
| 597 |
+
object PyArray_PutMask (ndarray, object, object)
|
| 598 |
+
object PyArray_Repeat (ndarray, object, int)
|
| 599 |
+
object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
|
| 600 |
+
int PyArray_Sort (ndarray, int, NPY_SORTKIND)
|
| 601 |
+
object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
|
| 602 |
+
object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE, PyObject *)
|
| 603 |
+
object PyArray_ArgMax (ndarray, int, ndarray)
|
| 604 |
+
object PyArray_ArgMin (ndarray, int, ndarray)
|
| 605 |
+
object PyArray_Reshape (ndarray, object)
|
| 606 |
+
object PyArray_Newshape (ndarray, PyArray_Dims *, NPY_ORDER)
|
| 607 |
+
object PyArray_Squeeze (ndarray)
|
| 608 |
+
#object PyArray_View (ndarray, dtype, type)
|
| 609 |
+
object PyArray_SwapAxes (ndarray, int, int)
|
| 610 |
+
object PyArray_Max (ndarray, int, ndarray)
|
| 611 |
+
object PyArray_Min (ndarray, int, ndarray)
|
| 612 |
+
object PyArray_Ptp (ndarray, int, ndarray)
|
| 613 |
+
object PyArray_Mean (ndarray, int, int, ndarray)
|
| 614 |
+
object PyArray_Trace (ndarray, int, int, int, int, ndarray)
|
| 615 |
+
object PyArray_Diagonal (ndarray, int, int, int)
|
| 616 |
+
object PyArray_Clip (ndarray, object, object, ndarray)
|
| 617 |
+
object PyArray_Conjugate (ndarray, ndarray)
|
| 618 |
+
object PyArray_Nonzero (ndarray)
|
| 619 |
+
object PyArray_Std (ndarray, int, int, ndarray, int)
|
| 620 |
+
object PyArray_Sum (ndarray, int, int, ndarray)
|
| 621 |
+
object PyArray_CumSum (ndarray, int, int, ndarray)
|
| 622 |
+
object PyArray_Prod (ndarray, int, int, ndarray)
|
| 623 |
+
object PyArray_CumProd (ndarray, int, int, ndarray)
|
| 624 |
+
object PyArray_All (ndarray, int, ndarray)
|
| 625 |
+
object PyArray_Any (ndarray, int, ndarray)
|
| 626 |
+
object PyArray_Compress (ndarray, object, int, ndarray)
|
| 627 |
+
object PyArray_Flatten (ndarray, NPY_ORDER)
|
| 628 |
+
object PyArray_Ravel (ndarray, NPY_ORDER)
|
| 629 |
+
npy_intp PyArray_MultiplyList (npy_intp *, int)
|
| 630 |
+
int PyArray_MultiplyIntList (int *, int)
|
| 631 |
+
void * PyArray_GetPtr (ndarray, npy_intp*)
|
| 632 |
+
int PyArray_CompareLists (npy_intp *, npy_intp *, int)
|
| 633 |
+
#int PyArray_AsCArray (object*, void *, npy_intp *, int, dtype)
|
| 634 |
+
#int PyArray_As1D (object*, char **, int *, int)
|
| 635 |
+
#int PyArray_As2D (object*, char ***, int *, int *, int)
|
| 636 |
+
int PyArray_Free (object, void *)
|
| 637 |
+
#int PyArray_Converter (object, object*)
|
| 638 |
+
int PyArray_IntpFromSequence (object, npy_intp *, int)
|
| 639 |
+
object PyArray_Concatenate (object, int)
|
| 640 |
+
object PyArray_InnerProduct (object, object)
|
| 641 |
+
object PyArray_MatrixProduct (object, object)
|
| 642 |
+
object PyArray_CopyAndTranspose (object)
|
| 643 |
+
object PyArray_Correlate (object, object, int)
|
| 644 |
+
int PyArray_TypestrConvert (int, int)
|
| 645 |
+
#int PyArray_DescrConverter (object, dtype*)
|
| 646 |
+
#int PyArray_DescrConverter2 (object, dtype*)
|
| 647 |
+
int PyArray_IntpConverter (object, PyArray_Dims *)
|
| 648 |
+
#int PyArray_BufferConverter (object, chunk)
|
| 649 |
+
int PyArray_AxisConverter (object, int *)
|
| 650 |
+
int PyArray_BoolConverter (object, npy_bool *)
|
| 651 |
+
int PyArray_ByteorderConverter (object, char *)
|
| 652 |
+
int PyArray_OrderConverter (object, NPY_ORDER *)
|
| 653 |
+
unsigned char PyArray_EquivTypes (dtype, dtype)
|
| 654 |
+
#object PyArray_Zeros (int, npy_intp *, dtype, int)
|
| 655 |
+
#object PyArray_Empty (int, npy_intp *, dtype, int)
|
| 656 |
+
object PyArray_Where (object, object, object)
|
| 657 |
+
object PyArray_Arange (double, double, double, int)
|
| 658 |
+
#object PyArray_ArangeObj (object, object, object, dtype)
|
| 659 |
+
int PyArray_SortkindConverter (object, NPY_SORTKIND *)
|
| 660 |
+
object PyArray_LexSort (object, int)
|
| 661 |
+
object PyArray_Round (ndarray, int, ndarray)
|
| 662 |
+
unsigned char PyArray_EquivTypenums (int, int)
|
| 663 |
+
int PyArray_RegisterDataType (dtype)
|
| 664 |
+
int PyArray_RegisterCastFunc (dtype, int, PyArray_VectorUnaryFunc *)
|
| 665 |
+
int PyArray_RegisterCanCast (dtype, int, NPY_SCALARKIND)
|
| 666 |
+
#void PyArray_InitArrFuncs (PyArray_ArrFuncs *)
|
| 667 |
+
object PyArray_IntTupleFromIntp (int, npy_intp *)
|
| 668 |
+
int PyArray_TypeNumFromName (char *)
|
| 669 |
+
int PyArray_ClipmodeConverter (object, NPY_CLIPMODE *)
|
| 670 |
+
#int PyArray_OutputConverter (object, ndarray*)
|
| 671 |
+
object PyArray_BroadcastToShape (object, npy_intp *, int)
|
| 672 |
+
void _PyArray_SigintHandler (int)
|
| 673 |
+
void* _PyArray_GetSigintBuf ()
|
| 674 |
+
#int PyArray_DescrAlignConverter (object, dtype*)
|
| 675 |
+
#int PyArray_DescrAlignConverter2 (object, dtype*)
|
| 676 |
+
int PyArray_SearchsideConverter (object, void *)
|
| 677 |
+
object PyArray_CheckAxis (ndarray, int *, int)
|
| 678 |
+
npy_intp PyArray_OverflowMultiplyList (npy_intp *, int)
|
| 679 |
+
int PyArray_CompareString (char *, char *, size_t)
|
| 680 |
+
int PyArray_SetBaseObject(ndarray, base) # NOTE: steals a reference to base! Use "set_array_base()" instead.
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
# Typedefs that matches the runtime dtype objects in
|
| 684 |
+
# the numpy module.
|
| 685 |
+
|
| 686 |
+
# The ones that are commented out needs an IFDEF function
|
| 687 |
+
# in Cython to enable them only on the right systems.
|
| 688 |
+
|
| 689 |
+
ctypedef npy_int8 int8_t
|
| 690 |
+
ctypedef npy_int16 int16_t
|
| 691 |
+
ctypedef npy_int32 int32_t
|
| 692 |
+
ctypedef npy_int64 int64_t
|
| 693 |
+
#ctypedef npy_int96 int96_t
|
| 694 |
+
#ctypedef npy_int128 int128_t
|
| 695 |
+
|
| 696 |
+
ctypedef npy_uint8 uint8_t
|
| 697 |
+
ctypedef npy_uint16 uint16_t
|
| 698 |
+
ctypedef npy_uint32 uint32_t
|
| 699 |
+
ctypedef npy_uint64 uint64_t
|
| 700 |
+
#ctypedef npy_uint96 uint96_t
|
| 701 |
+
#ctypedef npy_uint128 uint128_t
|
| 702 |
+
|
| 703 |
+
ctypedef npy_float32 float32_t
|
| 704 |
+
ctypedef npy_float64 float64_t
|
| 705 |
+
#ctypedef npy_float80 float80_t
|
| 706 |
+
#ctypedef npy_float128 float128_t
|
| 707 |
+
|
| 708 |
+
ctypedef float complex complex64_t
|
| 709 |
+
ctypedef double complex complex128_t
|
| 710 |
+
|
| 711 |
+
# The int types are mapped a bit surprising --
|
| 712 |
+
# numpy.int corresponds to 'l' and numpy.long to 'q'
|
| 713 |
+
ctypedef npy_long int_t
|
| 714 |
+
ctypedef npy_longlong long_t
|
| 715 |
+
ctypedef npy_longlong longlong_t
|
| 716 |
+
|
| 717 |
+
ctypedef npy_ulong uint_t
|
| 718 |
+
ctypedef npy_ulonglong ulong_t
|
| 719 |
+
ctypedef npy_ulonglong ulonglong_t
|
| 720 |
+
|
| 721 |
+
ctypedef npy_intp intp_t
|
| 722 |
+
ctypedef npy_uintp uintp_t
|
| 723 |
+
|
| 724 |
+
ctypedef npy_double float_t
|
| 725 |
+
ctypedef npy_double double_t
|
| 726 |
+
ctypedef npy_longdouble longdouble_t
|
| 727 |
+
|
| 728 |
+
ctypedef npy_cfloat cfloat_t
|
| 729 |
+
ctypedef npy_cdouble cdouble_t
|
| 730 |
+
ctypedef npy_clongdouble clongdouble_t
|
| 731 |
+
|
| 732 |
+
ctypedef npy_cdouble complex_t
|
| 733 |
+
|
| 734 |
+
cdef inline object PyArray_MultiIterNew1(a):
|
| 735 |
+
return PyArray_MultiIterNew(1, <void*>a)
|
| 736 |
+
|
| 737 |
+
cdef inline object PyArray_MultiIterNew2(a, b):
|
| 738 |
+
return PyArray_MultiIterNew(2, <void*>a, <void*>b)
|
| 739 |
+
|
| 740 |
+
cdef inline object PyArray_MultiIterNew3(a, b, c):
|
| 741 |
+
return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
|
| 742 |
+
|
| 743 |
+
cdef inline object PyArray_MultiIterNew4(a, b, c, d):
|
| 744 |
+
return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
|
| 745 |
+
|
| 746 |
+
cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
|
| 747 |
+
return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
|
| 748 |
+
|
| 749 |
+
cdef inline tuple PyDataType_SHAPE(dtype d):
|
| 750 |
+
if PyDataType_HASSUBARRAY(d):
|
| 751 |
+
return <tuple>d.subarray.shape
|
| 752 |
+
else:
|
| 753 |
+
return ()
|
| 754 |
+
|
| 755 |
+
|
| 756 |
+
cdef extern from "numpy/ndarrayobject.h":
|
| 757 |
+
PyTypeObject PyTimedeltaArrType_Type
|
| 758 |
+
PyTypeObject PyDatetimeArrType_Type
|
| 759 |
+
ctypedef int64_t npy_timedelta
|
| 760 |
+
ctypedef int64_t npy_datetime
|
| 761 |
+
|
| 762 |
+
cdef extern from "numpy/ndarraytypes.h":
|
| 763 |
+
ctypedef struct PyArray_DatetimeMetaData:
|
| 764 |
+
NPY_DATETIMEUNIT base
|
| 765 |
+
int64_t num
|
| 766 |
+
|
| 767 |
+
cdef extern from "numpy/arrayscalars.h":
|
| 768 |
+
|
| 769 |
+
# abstract types
|
| 770 |
+
ctypedef class numpy.generic [object PyObject]:
|
| 771 |
+
pass
|
| 772 |
+
ctypedef class numpy.number [object PyObject]:
|
| 773 |
+
pass
|
| 774 |
+
ctypedef class numpy.integer [object PyObject]:
|
| 775 |
+
pass
|
| 776 |
+
ctypedef class numpy.signedinteger [object PyObject]:
|
| 777 |
+
pass
|
| 778 |
+
ctypedef class numpy.unsignedinteger [object PyObject]:
|
| 779 |
+
pass
|
| 780 |
+
ctypedef class numpy.inexact [object PyObject]:
|
| 781 |
+
pass
|
| 782 |
+
ctypedef class numpy.floating [object PyObject]:
|
| 783 |
+
pass
|
| 784 |
+
ctypedef class numpy.complexfloating [object PyObject]:
|
| 785 |
+
pass
|
| 786 |
+
ctypedef class numpy.flexible [object PyObject]:
|
| 787 |
+
pass
|
| 788 |
+
ctypedef class numpy.character [object PyObject]:
|
| 789 |
+
pass
|
| 790 |
+
|
| 791 |
+
ctypedef struct PyDatetimeScalarObject:
|
| 792 |
+
# PyObject_HEAD
|
| 793 |
+
npy_datetime obval
|
| 794 |
+
PyArray_DatetimeMetaData obmeta
|
| 795 |
+
|
| 796 |
+
ctypedef struct PyTimedeltaScalarObject:
|
| 797 |
+
# PyObject_HEAD
|
| 798 |
+
npy_timedelta obval
|
| 799 |
+
PyArray_DatetimeMetaData obmeta
|
| 800 |
+
|
| 801 |
+
ctypedef enum NPY_DATETIMEUNIT:
|
| 802 |
+
NPY_FR_Y
|
| 803 |
+
NPY_FR_M
|
| 804 |
+
NPY_FR_W
|
| 805 |
+
NPY_FR_D
|
| 806 |
+
NPY_FR_B
|
| 807 |
+
NPY_FR_h
|
| 808 |
+
NPY_FR_m
|
| 809 |
+
NPY_FR_s
|
| 810 |
+
NPY_FR_ms
|
| 811 |
+
NPY_FR_us
|
| 812 |
+
NPY_FR_ns
|
| 813 |
+
NPY_FR_ps
|
| 814 |
+
NPY_FR_fs
|
| 815 |
+
NPY_FR_as
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
#
|
| 819 |
+
# ufunc API
|
| 820 |
+
#
|
| 821 |
+
|
| 822 |
+
cdef extern from "numpy/ufuncobject.h":
|
| 823 |
+
|
| 824 |
+
ctypedef void (*PyUFuncGenericFunction) (char **, npy_intp *, npy_intp *, void *)
|
| 825 |
+
|
| 826 |
+
ctypedef class numpy.ufunc [object PyUFuncObject, check_size ignore]:
|
| 827 |
+
cdef:
|
| 828 |
+
int nin, nout, nargs
|
| 829 |
+
int identity
|
| 830 |
+
PyUFuncGenericFunction *functions
|
| 831 |
+
void **data
|
| 832 |
+
int ntypes
|
| 833 |
+
int check_return
|
| 834 |
+
char *name
|
| 835 |
+
char *types
|
| 836 |
+
char *doc
|
| 837 |
+
void *ptr
|
| 838 |
+
PyObject *obj
|
| 839 |
+
PyObject *userloops
|
| 840 |
+
|
| 841 |
+
cdef enum:
|
| 842 |
+
PyUFunc_Zero
|
| 843 |
+
PyUFunc_One
|
| 844 |
+
PyUFunc_None
|
| 845 |
+
UFUNC_ERR_IGNORE
|
| 846 |
+
UFUNC_ERR_WARN
|
| 847 |
+
UFUNC_ERR_RAISE
|
| 848 |
+
UFUNC_ERR_CALL
|
| 849 |
+
UFUNC_ERR_PRINT
|
| 850 |
+
UFUNC_ERR_LOG
|
| 851 |
+
UFUNC_MASK_DIVIDEBYZERO
|
| 852 |
+
UFUNC_MASK_OVERFLOW
|
| 853 |
+
UFUNC_MASK_UNDERFLOW
|
| 854 |
+
UFUNC_MASK_INVALID
|
| 855 |
+
UFUNC_SHIFT_DIVIDEBYZERO
|
| 856 |
+
UFUNC_SHIFT_OVERFLOW
|
| 857 |
+
UFUNC_SHIFT_UNDERFLOW
|
| 858 |
+
UFUNC_SHIFT_INVALID
|
| 859 |
+
UFUNC_FPE_DIVIDEBYZERO
|
| 860 |
+
UFUNC_FPE_OVERFLOW
|
| 861 |
+
UFUNC_FPE_UNDERFLOW
|
| 862 |
+
UFUNC_FPE_INVALID
|
| 863 |
+
UFUNC_ERR_DEFAULT
|
| 864 |
+
UFUNC_ERR_DEFAULT2
|
| 865 |
+
|
| 866 |
+
object PyUFunc_FromFuncAndData(PyUFuncGenericFunction *,
|
| 867 |
+
void **, char *, int, int, int, int, char *, char *, int)
|
| 868 |
+
int PyUFunc_RegisterLoopForType(ufunc, int,
|
| 869 |
+
PyUFuncGenericFunction, int *, void *)
|
| 870 |
+
void PyUFunc_f_f_As_d_d \
|
| 871 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 872 |
+
void PyUFunc_d_d \
|
| 873 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 874 |
+
void PyUFunc_f_f \
|
| 875 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 876 |
+
void PyUFunc_g_g \
|
| 877 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 878 |
+
void PyUFunc_F_F_As_D_D \
|
| 879 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 880 |
+
void PyUFunc_F_F \
|
| 881 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 882 |
+
void PyUFunc_D_D \
|
| 883 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 884 |
+
void PyUFunc_G_G \
|
| 885 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 886 |
+
void PyUFunc_O_O \
|
| 887 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 888 |
+
void PyUFunc_ff_f_As_dd_d \
|
| 889 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 890 |
+
void PyUFunc_ff_f \
|
| 891 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 892 |
+
void PyUFunc_dd_d \
|
| 893 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 894 |
+
void PyUFunc_gg_g \
|
| 895 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 896 |
+
void PyUFunc_FF_F_As_DD_D \
|
| 897 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 898 |
+
void PyUFunc_DD_D \
|
| 899 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 900 |
+
void PyUFunc_FF_F \
|
| 901 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 902 |
+
void PyUFunc_GG_G \
|
| 903 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 904 |
+
void PyUFunc_OO_O \
|
| 905 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 906 |
+
void PyUFunc_O_O_method \
|
| 907 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 908 |
+
void PyUFunc_OO_O_method \
|
| 909 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 910 |
+
void PyUFunc_On_Om \
|
| 911 |
+
(char **, npy_intp *, npy_intp *, void *)
|
| 912 |
+
int PyUFunc_GetPyValues \
|
| 913 |
+
(char *, int *, int *, PyObject **)
|
| 914 |
+
int PyUFunc_checkfperr \
|
| 915 |
+
(int, PyObject *, int *)
|
| 916 |
+
void PyUFunc_clearfperr()
|
| 917 |
+
int PyUFunc_getfperr()
|
| 918 |
+
int PyUFunc_handlefperr \
|
| 919 |
+
(int, PyObject *, int, int *)
|
| 920 |
+
int PyUFunc_ReplaceLoopBySignature \
|
| 921 |
+
(ufunc, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)
|
| 922 |
+
object PyUFunc_FromFuncAndDataAndSignature \
|
| 923 |
+
(PyUFuncGenericFunction *, void **, char *, int, int, int,
|
| 924 |
+
int, char *, char *, int, char *)
|
| 925 |
+
|
| 926 |
+
int _import_umath() except -1
|
| 927 |
+
|
| 928 |
+
cdef inline void set_array_base(ndarray arr, object base):
|
| 929 |
+
Py_INCREF(base) # important to do this before stealing the reference below!
|
| 930 |
+
PyArray_SetBaseObject(arr, base)
|
| 931 |
+
|
| 932 |
+
cdef inline object get_array_base(ndarray arr):
|
| 933 |
+
base = PyArray_BASE(arr)
|
| 934 |
+
if base is NULL:
|
| 935 |
+
return None
|
| 936 |
+
return <object>base
|
| 937 |
+
|
| 938 |
+
# Versions of the import_* functions which are more suitable for
|
| 939 |
+
# Cython code.
|
| 940 |
+
cdef inline int import_array() except -1:
|
| 941 |
+
try:
|
| 942 |
+
__pyx_import_array()
|
| 943 |
+
except Exception:
|
| 944 |
+
raise ImportError("numpy.core.multiarray failed to import")
|
| 945 |
+
|
| 946 |
+
cdef inline int import_umath() except -1:
|
| 947 |
+
try:
|
| 948 |
+
_import_umath()
|
| 949 |
+
except Exception:
|
| 950 |
+
raise ImportError("numpy.core.umath failed to import")
|
| 951 |
+
|
| 952 |
+
cdef inline int import_ufunc() except -1:
|
| 953 |
+
try:
|
| 954 |
+
_import_umath()
|
| 955 |
+
except Exception:
|
| 956 |
+
raise ImportError("numpy.core.umath failed to import")
|
| 957 |
+
|
| 958 |
+
cdef extern from *:
|
| 959 |
+
# Leave a marker that the NumPy declarations came from this file
|
| 960 |
+
# See https://github.com/cython/cython/issues/3573
|
| 961 |
+
"""
|
| 962 |
+
/* NumPy API declarations from "numpy/__init__.pxd" */
|
| 963 |
+
"""
|
| 964 |
+
|
| 965 |
+
|
| 966 |
+
cdef inline bint is_timedelta64_object(object obj):
|
| 967 |
+
"""
|
| 968 |
+
Cython equivalent of `isinstance(obj, np.timedelta64)`
|
| 969 |
+
|
| 970 |
+
Parameters
|
| 971 |
+
----------
|
| 972 |
+
obj : object
|
| 973 |
+
|
| 974 |
+
Returns
|
| 975 |
+
-------
|
| 976 |
+
bool
|
| 977 |
+
"""
|
| 978 |
+
return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
cdef inline bint is_datetime64_object(object obj):
|
| 982 |
+
"""
|
| 983 |
+
Cython equivalent of `isinstance(obj, np.datetime64)`
|
| 984 |
+
|
| 985 |
+
Parameters
|
| 986 |
+
----------
|
| 987 |
+
obj : object
|
| 988 |
+
|
| 989 |
+
Returns
|
| 990 |
+
-------
|
| 991 |
+
bool
|
| 992 |
+
"""
|
| 993 |
+
return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)
|
| 994 |
+
|
| 995 |
+
|
| 996 |
+
cdef inline npy_datetime get_datetime64_value(object obj) nogil:
|
| 997 |
+
"""
|
| 998 |
+
returns the int64 value underlying scalar numpy datetime64 object
|
| 999 |
+
|
| 1000 |
+
Note that to interpret this as a datetime, the corresponding unit is
|
| 1001 |
+
also needed. That can be found using `get_datetime64_unit`.
|
| 1002 |
+
"""
|
| 1003 |
+
return (<PyDatetimeScalarObject*>obj).obval
|
| 1004 |
+
|
| 1005 |
+
|
| 1006 |
+
cdef inline npy_timedelta get_timedelta64_value(object obj) nogil:
|
| 1007 |
+
"""
|
| 1008 |
+
returns the int64 value underlying scalar numpy timedelta64 object
|
| 1009 |
+
"""
|
| 1010 |
+
return (<PyTimedeltaScalarObject*>obj).obval
|
| 1011 |
+
|
| 1012 |
+
|
| 1013 |
+
cdef inline NPY_DATETIMEUNIT get_datetime64_unit(object obj) nogil:
|
| 1014 |
+
"""
|
| 1015 |
+
returns the unit part of the dtype for a numpy datetime64 object.
|
| 1016 |
+
"""
|
| 1017 |
+
return <NPY_DATETIMEUNIT>(<PyDatetimeScalarObject*>obj).obmeta.base
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.py
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
NumPy
|
| 3 |
+
=====
|
| 4 |
+
|
| 5 |
+
Provides
|
| 6 |
+
1. An array object of arbitrary homogeneous items
|
| 7 |
+
2. Fast mathematical operations over arrays
|
| 8 |
+
3. Linear Algebra, Fourier Transforms, Random Number Generation
|
| 9 |
+
|
| 10 |
+
How to use the documentation
|
| 11 |
+
----------------------------
|
| 12 |
+
Documentation is available in two forms: docstrings provided
|
| 13 |
+
with the code, and a loose standing reference guide, available from
|
| 14 |
+
`the NumPy homepage <https://numpy.org>`_.
|
| 15 |
+
|
| 16 |
+
We recommend exploring the docstrings using
|
| 17 |
+
`IPython <https://ipython.org>`_, an advanced Python shell with
|
| 18 |
+
TAB-completion and introspection capabilities. See below for further
|
| 19 |
+
instructions.
|
| 20 |
+
|
| 21 |
+
The docstring examples assume that `numpy` has been imported as ``np``::
|
| 22 |
+
|
| 23 |
+
>>> import numpy as np
|
| 24 |
+
|
| 25 |
+
Code snippets are indicated by three greater-than signs::
|
| 26 |
+
|
| 27 |
+
>>> x = 42
|
| 28 |
+
>>> x = x + 1
|
| 29 |
+
|
| 30 |
+
Use the built-in ``help`` function to view a function's docstring::
|
| 31 |
+
|
| 32 |
+
>>> help(np.sort)
|
| 33 |
+
... # doctest: +SKIP
|
| 34 |
+
|
| 35 |
+
For some objects, ``np.info(obj)`` may provide additional help. This is
|
| 36 |
+
particularly true if you see the line "Help on ufunc object:" at the top
|
| 37 |
+
of the help() page. Ufuncs are implemented in C, not Python, for speed.
|
| 38 |
+
The native Python help() does not know how to view their help, but our
|
| 39 |
+
np.info() function does.
|
| 40 |
+
|
| 41 |
+
To search for documents containing a keyword, do::
|
| 42 |
+
|
| 43 |
+
>>> np.lookfor('keyword')
|
| 44 |
+
... # doctest: +SKIP
|
| 45 |
+
|
| 46 |
+
General-purpose documents like a glossary and help on the basic concepts
|
| 47 |
+
of numpy are available under the ``doc`` sub-module::
|
| 48 |
+
|
| 49 |
+
>>> from numpy import doc
|
| 50 |
+
>>> help(doc)
|
| 51 |
+
... # doctest: +SKIP
|
| 52 |
+
|
| 53 |
+
Available subpackages
|
| 54 |
+
---------------------
|
| 55 |
+
lib
|
| 56 |
+
Basic functions used by several sub-packages.
|
| 57 |
+
random
|
| 58 |
+
Core Random Tools
|
| 59 |
+
linalg
|
| 60 |
+
Core Linear Algebra Tools
|
| 61 |
+
fft
|
| 62 |
+
Core FFT routines
|
| 63 |
+
polynomial
|
| 64 |
+
Polynomial tools
|
| 65 |
+
testing
|
| 66 |
+
NumPy testing tools
|
| 67 |
+
distutils
|
| 68 |
+
Enhancements to distutils with support for
|
| 69 |
+
Fortran compilers support and more.
|
| 70 |
+
|
| 71 |
+
Utilities
|
| 72 |
+
---------
|
| 73 |
+
test
|
| 74 |
+
Run numpy unittests
|
| 75 |
+
show_config
|
| 76 |
+
Show numpy build configuration
|
| 77 |
+
dual
|
| 78 |
+
Overwrite certain functions with high-performance SciPy tools.
|
| 79 |
+
Note: `numpy.dual` is deprecated. Use the functions from NumPy or Scipy
|
| 80 |
+
directly instead of importing them from `numpy.dual`.
|
| 81 |
+
matlib
|
| 82 |
+
Make everything matrices.
|
| 83 |
+
__version__
|
| 84 |
+
NumPy version string
|
| 85 |
+
|
| 86 |
+
Viewing documentation using IPython
|
| 87 |
+
-----------------------------------
|
| 88 |
+
|
| 89 |
+
Start IPython and import `numpy` usually under the alias ``np``: `import
|
| 90 |
+
numpy as np`. Then, directly past or use the ``%cpaste`` magic to paste
|
| 91 |
+
examples into the shell. To see which functions are available in `numpy`,
|
| 92 |
+
type ``np.<TAB>`` (where ``<TAB>`` refers to the TAB key), or use
|
| 93 |
+
``np.*cos*?<ENTER>`` (where ``<ENTER>`` refers to the ENTER key) to narrow
|
| 94 |
+
down the list. To view the docstring for a function, use
|
| 95 |
+
``np.cos?<ENTER>`` (to view the docstring) and ``np.cos??<ENTER>`` (to view
|
| 96 |
+
the source code).
|
| 97 |
+
|
| 98 |
+
Copies vs. in-place operation
|
| 99 |
+
-----------------------------
|
| 100 |
+
Most of the functions in `numpy` return a copy of the array argument
|
| 101 |
+
(e.g., `np.sort`). In-place versions of these functions are often
|
| 102 |
+
available as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``.
|
| 103 |
+
Exceptions to this rule are documented.
|
| 104 |
+
|
| 105 |
+
"""
|
| 106 |
+
import sys
|
| 107 |
+
import warnings
|
| 108 |
+
|
| 109 |
+
from ._globals import (
|
| 110 |
+
ModuleDeprecationWarning, VisibleDeprecationWarning,
|
| 111 |
+
_NoValue, _CopyMode
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# We first need to detect if we're being called as part of the numpy setup
|
| 115 |
+
# procedure itself in a reliable manner.
|
| 116 |
+
try:
|
| 117 |
+
__NUMPY_SETUP__
|
| 118 |
+
except NameError:
|
| 119 |
+
__NUMPY_SETUP__ = False
|
| 120 |
+
|
| 121 |
+
if __NUMPY_SETUP__:
|
| 122 |
+
sys.stderr.write('Running from numpy source directory.\n')
|
| 123 |
+
else:
|
| 124 |
+
try:
|
| 125 |
+
from numpy.__config__ import show as show_config
|
| 126 |
+
except ImportError as e:
|
| 127 |
+
msg = """Error importing numpy: you should not try to import numpy from
|
| 128 |
+
its source directory; please exit the numpy source tree, and relaunch
|
| 129 |
+
your python interpreter from there."""
|
| 130 |
+
raise ImportError(msg) from e
|
| 131 |
+
|
| 132 |
+
__all__ = ['ModuleDeprecationWarning',
|
| 133 |
+
'VisibleDeprecationWarning']
|
| 134 |
+
|
| 135 |
+
# mapping of {name: (value, deprecation_msg)}
|
| 136 |
+
__deprecated_attrs__ = {}
|
| 137 |
+
|
| 138 |
+
# Allow distributors to run custom init code
|
| 139 |
+
from . import _distributor_init
|
| 140 |
+
|
| 141 |
+
from . import core
|
| 142 |
+
from .core import *
|
| 143 |
+
from . import compat
|
| 144 |
+
from . import lib
|
| 145 |
+
# NOTE: to be revisited following future namespace cleanup.
|
| 146 |
+
# See gh-14454 and gh-15672 for discussion.
|
| 147 |
+
from .lib import *
|
| 148 |
+
|
| 149 |
+
from . import linalg
|
| 150 |
+
from . import fft
|
| 151 |
+
from . import polynomial
|
| 152 |
+
from . import random
|
| 153 |
+
from . import ctypeslib
|
| 154 |
+
from . import ma
|
| 155 |
+
from . import matrixlib as _mat
|
| 156 |
+
from .matrixlib import *
|
| 157 |
+
|
| 158 |
+
# Deprecations introduced in NumPy 1.20.0, 2020-06-06
|
| 159 |
+
import builtins as _builtins
|
| 160 |
+
|
| 161 |
+
_msg = (
|
| 162 |
+
"module 'numpy' has no attribute '{n}'.\n"
|
| 163 |
+
"`np.{n}` was a deprecated alias for the builtin `{n}`. "
|
| 164 |
+
"To avoid this error in existing code, use `{n}` by itself. "
|
| 165 |
+
"Doing this will not modify any behavior and is safe. {extended_msg}\n"
|
| 166 |
+
"The aliases was originally deprecated in NumPy 1.20; for more "
|
| 167 |
+
"details and guidance see the original release note at:\n"
|
| 168 |
+
" https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations")
|
| 169 |
+
|
| 170 |
+
_specific_msg = (
|
| 171 |
+
"If you specifically wanted the numpy scalar type, use `np.{}` here.")
|
| 172 |
+
|
| 173 |
+
_int_extended_msg = (
|
| 174 |
+
"When replacing `np.{}`, you may wish to use e.g. `np.int64` "
|
| 175 |
+
"or `np.int32` to specify the precision. If you wish to review "
|
| 176 |
+
"your current use, check the release note link for "
|
| 177 |
+
"additional information.")
|
| 178 |
+
|
| 179 |
+
_type_info = [
|
| 180 |
+
("object", ""), # The NumPy scalar only exists by name.
|
| 181 |
+
("bool", _specific_msg.format("bool_")),
|
| 182 |
+
("float", _specific_msg.format("float64")),
|
| 183 |
+
("complex", _specific_msg.format("complex128")),
|
| 184 |
+
("str", _specific_msg.format("str_")),
|
| 185 |
+
("int", _int_extended_msg.format("int"))]
|
| 186 |
+
|
| 187 |
+
__former_attrs__ = {
|
| 188 |
+
n: _msg.format(n=n, extended_msg=extended_msg)
|
| 189 |
+
for n, extended_msg in _type_info
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
# Future warning introduced in NumPy 1.24.0, 2022-11-17
|
| 193 |
+
_msg = (
|
| 194 |
+
"`np.{n}` is a deprecated alias for `{an}`. (Deprecated NumPy 1.24)")
|
| 195 |
+
|
| 196 |
+
# Some of these are awkward (since `np.str` may be preferable in the long
|
| 197 |
+
# term), but overall the names ending in 0 seem undesireable
|
| 198 |
+
_type_info = [
|
| 199 |
+
("bool8", bool_, "np.bool_"),
|
| 200 |
+
("int0", intp, "np.intp"),
|
| 201 |
+
("uint0", uintp, "np.uintp"),
|
| 202 |
+
("str0", str_, "np.str_"),
|
| 203 |
+
("bytes0", bytes_, "np.bytes_"),
|
| 204 |
+
("void0", void, "np.void"),
|
| 205 |
+
("object0", object_,
|
| 206 |
+
"`np.object0` is a deprecated alias for `np.object_`. "
|
| 207 |
+
"`object` can be used instead. (Deprecated NumPy 1.24)")]
|
| 208 |
+
|
| 209 |
+
# Some of these could be defined right away, but most were aliases to
|
| 210 |
+
# the Python objects and only removed in NumPy 1.24. Defining them should
|
| 211 |
+
# probably wait for NumPy 1.26 or 2.0.
|
| 212 |
+
# When defined, these should possibly not be added to `__all__` to avoid
|
| 213 |
+
# import with `from numpy import *`.
|
| 214 |
+
__future_scalars__ = {"bool", "long", "ulong", "str", "bytes", "object"}
|
| 215 |
+
|
| 216 |
+
__deprecated_attrs__.update({
|
| 217 |
+
n: (alias, _msg.format(n=n, an=an)) for n, alias, an in _type_info})
|
| 218 |
+
|
| 219 |
+
del _msg, _type_info
|
| 220 |
+
|
| 221 |
+
from .core import round, abs, max, min
|
| 222 |
+
# now that numpy modules are imported, can initialize limits
|
| 223 |
+
core.getlimits._register_known_types()
|
| 224 |
+
|
| 225 |
+
__all__.extend(['__version__', 'show_config'])
|
| 226 |
+
__all__.extend(core.__all__)
|
| 227 |
+
__all__.extend(_mat.__all__)
|
| 228 |
+
__all__.extend(lib.__all__)
|
| 229 |
+
__all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
|
| 230 |
+
|
| 231 |
+
# Remove one of the two occurrences of `issubdtype`, which is exposed as
|
| 232 |
+
# both `numpy.core.issubdtype` and `numpy.lib.issubdtype`.
|
| 233 |
+
__all__.remove('issubdtype')
|
| 234 |
+
|
| 235 |
+
# These are exported by np.core, but are replaced by the builtins below
|
| 236 |
+
# remove them to ensure that we don't end up with `np.long == np.int_`,
|
| 237 |
+
# which would be a breaking change.
|
| 238 |
+
del long, unicode
|
| 239 |
+
__all__.remove('long')
|
| 240 |
+
__all__.remove('unicode')
|
| 241 |
+
|
| 242 |
+
# Remove things that are in the numpy.lib but not in the numpy namespace
|
| 243 |
+
# Note that there is a test (numpy/tests/test_public_api.py:test_numpy_namespace)
|
| 244 |
+
# that prevents adding more things to the main namespace by accident.
|
| 245 |
+
# The list below will grow until the `from .lib import *` fixme above is
|
| 246 |
+
# taken care of
|
| 247 |
+
__all__.remove('Arrayterator')
|
| 248 |
+
del Arrayterator
|
| 249 |
+
|
| 250 |
+
# These names were removed in NumPy 1.20. For at least one release,
|
| 251 |
+
# attempts to access these names in the numpy namespace will trigger
|
| 252 |
+
# a warning, and calling the function will raise an exception.
|
| 253 |
+
_financial_names = ['fv', 'ipmt', 'irr', 'mirr', 'nper', 'npv', 'pmt',
|
| 254 |
+
'ppmt', 'pv', 'rate']
|
| 255 |
+
__expired_functions__ = {
|
| 256 |
+
name: (f'In accordance with NEP 32, the function {name} was removed '
|
| 257 |
+
'from NumPy version 1.20. A replacement for this function '
|
| 258 |
+
'is available in the numpy_financial library: '
|
| 259 |
+
'https://pypi.org/project/numpy-financial')
|
| 260 |
+
for name in _financial_names}
|
| 261 |
+
|
| 262 |
+
# Filter out Cython harmless warnings
|
| 263 |
+
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
|
| 264 |
+
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
|
| 265 |
+
warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
|
| 266 |
+
|
| 267 |
+
# oldnumeric and numarray were removed in 1.9. In case some packages import
|
| 268 |
+
# but do not use them, we define them here for backward compatibility.
|
| 269 |
+
oldnumeric = 'removed'
|
| 270 |
+
numarray = 'removed'
|
| 271 |
+
|
| 272 |
+
def __getattr__(attr):
|
| 273 |
+
# Warn for expired attributes, and return a dummy function
|
| 274 |
+
# that always raises an exception.
|
| 275 |
+
import warnings
|
| 276 |
+
try:
|
| 277 |
+
msg = __expired_functions__[attr]
|
| 278 |
+
except KeyError:
|
| 279 |
+
pass
|
| 280 |
+
else:
|
| 281 |
+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
| 282 |
+
|
| 283 |
+
def _expired(*args, **kwds):
|
| 284 |
+
raise RuntimeError(msg)
|
| 285 |
+
|
| 286 |
+
return _expired
|
| 287 |
+
|
| 288 |
+
# Emit warnings for deprecated attributes
|
| 289 |
+
try:
|
| 290 |
+
val, msg = __deprecated_attrs__[attr]
|
| 291 |
+
except KeyError:
|
| 292 |
+
pass
|
| 293 |
+
else:
|
| 294 |
+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
| 295 |
+
return val
|
| 296 |
+
|
| 297 |
+
if attr in __future_scalars__:
|
| 298 |
+
# And future warnings for those that will change, but also give
|
| 299 |
+
# the AttributeError
|
| 300 |
+
warnings.warn(
|
| 301 |
+
f"In the future `np.{attr}` will be defined as the "
|
| 302 |
+
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
|
| 303 |
+
|
| 304 |
+
if attr in __former_attrs__:
|
| 305 |
+
raise AttributeError(__former_attrs__[attr])
|
| 306 |
+
|
| 307 |
+
# Importing Tester requires importing all of UnitTest which is not a
|
| 308 |
+
# cheap import Since it is mainly used in test suits, we lazy import it
|
| 309 |
+
# here to save on the order of 10 ms of import time for most users
|
| 310 |
+
#
|
| 311 |
+
# The previous way Tester was imported also had a side effect of adding
|
| 312 |
+
# the full `numpy.testing` namespace
|
| 313 |
+
if attr == 'testing':
|
| 314 |
+
import numpy.testing as testing
|
| 315 |
+
return testing
|
| 316 |
+
elif attr == 'Tester':
|
| 317 |
+
from .testing import Tester
|
| 318 |
+
return Tester
|
| 319 |
+
|
| 320 |
+
raise AttributeError("module {!r} has no attribute "
|
| 321 |
+
"{!r}".format(__name__, attr))
|
| 322 |
+
|
| 323 |
+
def __dir__():
|
| 324 |
+
public_symbols = globals().keys() | {'Tester', 'testing'}
|
| 325 |
+
public_symbols -= {
|
| 326 |
+
"core", "matrixlib",
|
| 327 |
+
}
|
| 328 |
+
return list(public_symbols)
|
| 329 |
+
|
| 330 |
+
# Pytest testing
|
| 331 |
+
from numpy._pytesttester import PytestTester
|
| 332 |
+
test = PytestTester(__name__)
|
| 333 |
+
del PytestTester
|
| 334 |
+
|
| 335 |
+
def _sanity_check():
|
| 336 |
+
"""
|
| 337 |
+
Quick sanity checks for common bugs caused by environment.
|
| 338 |
+
There are some cases e.g. with wrong BLAS ABI that cause wrong
|
| 339 |
+
results under specific runtime conditions that are not necessarily
|
| 340 |
+
achieved during test suite runs, and it is useful to catch those early.
|
| 341 |
+
|
| 342 |
+
See https://github.com/numpy/numpy/issues/8577 and other
|
| 343 |
+
similar bug reports.
|
| 344 |
+
|
| 345 |
+
"""
|
| 346 |
+
try:
|
| 347 |
+
x = ones(2, dtype=float32)
|
| 348 |
+
if not abs(x.dot(x) - float32(2.0)) < 1e-5:
|
| 349 |
+
raise AssertionError()
|
| 350 |
+
except AssertionError:
|
| 351 |
+
msg = ("The current Numpy installation ({!r}) fails to "
|
| 352 |
+
"pass simple sanity checks. This can be caused for example "
|
| 353 |
+
"by incorrect BLAS library being linked in, or by mixing "
|
| 354 |
+
"package managers (pip, conda, apt, ...). Search closed "
|
| 355 |
+
"numpy issues for similar problems.")
|
| 356 |
+
raise RuntimeError(msg.format(__file__)) from None
|
| 357 |
+
|
| 358 |
+
_sanity_check()
|
| 359 |
+
del _sanity_check
|
| 360 |
+
|
| 361 |
+
def _mac_os_check():
|
| 362 |
+
"""
|
| 363 |
+
Quick Sanity check for Mac OS look for accelerate build bugs.
|
| 364 |
+
Testing numpy polyfit calls init_dgelsd(LAPACK)
|
| 365 |
+
"""
|
| 366 |
+
try:
|
| 367 |
+
c = array([3., 2., 1.])
|
| 368 |
+
x = linspace(0, 2, 5)
|
| 369 |
+
y = polyval(c, x)
|
| 370 |
+
_ = polyfit(x, y, 2, cov=True)
|
| 371 |
+
except ValueError:
|
| 372 |
+
pass
|
| 373 |
+
|
| 374 |
+
if sys.platform == "darwin":
|
| 375 |
+
with warnings.catch_warnings(record=True) as w:
|
| 376 |
+
_mac_os_check()
|
| 377 |
+
# Throw runtime error, if the test failed Check for warning and error_message
|
| 378 |
+
error_message = ""
|
| 379 |
+
if len(w) > 0:
|
| 380 |
+
error_message = "{}: {}".format(w[-1].category.__name__, str(w[-1].message))
|
| 381 |
+
msg = (
|
| 382 |
+
"Polyfit sanity test emitted a warning, most likely due "
|
| 383 |
+
"to using a buggy Accelerate backend."
|
| 384 |
+
"\nIf you compiled yourself, more information is available at:"
|
| 385 |
+
"\nhttps://numpy.org/doc/stable/user/building.html#accelerated-blas-lapack-libraries"
|
| 386 |
+
"\nOtherwise report this to the vendor "
|
| 387 |
+
"that provided NumPy.\n{}\n".format(error_message))
|
| 388 |
+
raise RuntimeError(msg)
|
| 389 |
+
del _mac_os_check
|
| 390 |
+
|
| 391 |
+
# We usually use madvise hugepages support, but on some old kernels it
|
| 392 |
+
# is slow and thus better avoided.
|
| 393 |
+
# Specifically kernel version 4.6 had a bug fix which probably fixed this:
|
| 394 |
+
# https://github.com/torvalds/linux/commit/7cf91a98e607c2f935dbcc177d70011e95b8faff
|
| 395 |
+
import os
|
| 396 |
+
use_hugepage = os.environ.get("NUMPY_MADVISE_HUGEPAGE", None)
|
| 397 |
+
if sys.platform == "linux" and use_hugepage is None:
|
| 398 |
+
# If there is an issue with parsing the kernel version,
|
| 399 |
+
# set use_hugepages to 0. Usage of LooseVersion will handle
|
| 400 |
+
# the kernel version parsing better, but avoided since it
|
| 401 |
+
# will increase the import time. See: #16679 for related discussion.
|
| 402 |
+
try:
|
| 403 |
+
use_hugepage = 1
|
| 404 |
+
kernel_version = os.uname().release.split(".")[:2]
|
| 405 |
+
kernel_version = tuple(int(v) for v in kernel_version)
|
| 406 |
+
if kernel_version < (4, 6):
|
| 407 |
+
use_hugepage = 0
|
| 408 |
+
except ValueError:
|
| 409 |
+
use_hugepages = 0
|
| 410 |
+
elif use_hugepage is None:
|
| 411 |
+
# This is not Linux, so it should not matter, just enable anyway
|
| 412 |
+
use_hugepage = 1
|
| 413 |
+
else:
|
| 414 |
+
use_hugepage = int(use_hugepage)
|
| 415 |
+
|
| 416 |
+
# Note that this will currently only make a difference on Linux
|
| 417 |
+
core.multiarray._set_madvise_hugepage(use_hugepage)
|
| 418 |
+
|
| 419 |
+
# Give a warning if NumPy is reloaded or imported on a sub-interpreter
|
| 420 |
+
# We do this from python, since the C-module may not be reloaded and
|
| 421 |
+
# it is tidier organized.
|
| 422 |
+
core.multiarray._multiarray_umath._reload_guard()
|
| 423 |
+
|
| 424 |
+
core._set_promotion_state(os.environ.get("NPY_PROMOTION_STATE", "legacy"))
|
| 425 |
+
|
| 426 |
+
# Tell PyInstaller where to find hook-numpy.py
|
| 427 |
+
def _pyinstaller_hooks_dir():
|
| 428 |
+
from pathlib import Path
|
| 429 |
+
return [str(Path(__file__).with_name("_pyinstaller").resolve())]
|
| 430 |
+
|
| 431 |
+
# Remove symbols imported for internal use
|
| 432 |
+
del os
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
# get the version using versioneer
|
| 436 |
+
from .version import __version__, git_revision as __git_version__
|
| 437 |
+
|
| 438 |
+
# Remove symbols imported for internal use
|
| 439 |
+
del sys, warnings
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/__init__.pyi
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_distributor_init.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" Distributor init file
|
| 2 |
+
|
| 3 |
+
Distributors: you can add custom code here to support particular distributions
|
| 4 |
+
of numpy.
|
| 5 |
+
|
| 6 |
+
For example, this is a good place to put any checks for hardware requirements.
|
| 7 |
+
|
| 8 |
+
The numpy standard source distribution will not put code in this file, so you
|
| 9 |
+
can safely replace this file with your own version.
|
| 10 |
+
"""
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_globals.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Module defining global singleton classes.
|
| 3 |
+
|
| 4 |
+
This module raises a RuntimeError if an attempt to reload it is made. In that
|
| 5 |
+
way the identities of the classes defined here are fixed and will remain so
|
| 6 |
+
even if numpy itself is reloaded. In particular, a function like the following
|
| 7 |
+
will still work correctly after numpy is reloaded::
|
| 8 |
+
|
| 9 |
+
def foo(arg=np._NoValue):
|
| 10 |
+
if arg is np._NoValue:
|
| 11 |
+
...
|
| 12 |
+
|
| 13 |
+
That was not the case when the singleton classes were defined in the numpy
|
| 14 |
+
``__init__.py`` file. See gh-7844 for a discussion of the reload problem that
|
| 15 |
+
motivated this module.
|
| 16 |
+
|
| 17 |
+
"""
|
| 18 |
+
import enum
|
| 19 |
+
|
| 20 |
+
__ALL__ = [
|
| 21 |
+
'ModuleDeprecationWarning', 'VisibleDeprecationWarning',
|
| 22 |
+
'_NoValue', '_CopyMode'
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Disallow reloading this module so as to preserve the identities of the
|
| 27 |
+
# classes defined here.
|
| 28 |
+
if '_is_loaded' in globals():
|
| 29 |
+
raise RuntimeError('Reloading numpy._globals is not allowed')
|
| 30 |
+
_is_loaded = True
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class ModuleDeprecationWarning(DeprecationWarning):
|
| 34 |
+
"""Module deprecation warning.
|
| 35 |
+
|
| 36 |
+
The nose tester turns ordinary Deprecation warnings into test failures.
|
| 37 |
+
That makes it hard to deprecate whole modules, because they get
|
| 38 |
+
imported by default. So this is a special Deprecation warning that the
|
| 39 |
+
nose tester will let pass without making tests fail.
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
ModuleDeprecationWarning.__module__ = 'numpy'
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class VisibleDeprecationWarning(UserWarning):
|
| 48 |
+
"""Visible deprecation warning.
|
| 49 |
+
|
| 50 |
+
By default, python will not show deprecation warnings, so this class
|
| 51 |
+
can be used when a very visible warning is helpful, for example because
|
| 52 |
+
the usage is most likely a user bug.
|
| 53 |
+
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
VisibleDeprecationWarning.__module__ = 'numpy'
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class _NoValueType:
|
| 61 |
+
"""Special keyword value.
|
| 62 |
+
|
| 63 |
+
The instance of this class may be used as the default value assigned to a
|
| 64 |
+
keyword if no other obvious default (e.g., `None`) is suitable,
|
| 65 |
+
|
| 66 |
+
Common reasons for using this keyword are:
|
| 67 |
+
|
| 68 |
+
- A new keyword is added to a function, and that function forwards its
|
| 69 |
+
inputs to another function or method which can be defined outside of
|
| 70 |
+
NumPy. For example, ``np.std(x)`` calls ``x.std``, so when a ``keepdims``
|
| 71 |
+
keyword was added that could only be forwarded if the user explicitly
|
| 72 |
+
specified ``keepdims``; downstream array libraries may not have added
|
| 73 |
+
the same keyword, so adding ``x.std(..., keepdims=keepdims)``
|
| 74 |
+
unconditionally could have broken previously working code.
|
| 75 |
+
- A keyword is being deprecated, and a deprecation warning must only be
|
| 76 |
+
emitted when the keyword is used.
|
| 77 |
+
|
| 78 |
+
"""
|
| 79 |
+
__instance = None
|
| 80 |
+
def __new__(cls):
|
| 81 |
+
# ensure that only one instance exists
|
| 82 |
+
if not cls.__instance:
|
| 83 |
+
cls.__instance = super().__new__(cls)
|
| 84 |
+
return cls.__instance
|
| 85 |
+
|
| 86 |
+
def __repr__(self):
|
| 87 |
+
return "<no value>"
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
_NoValue = _NoValueType()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class _CopyMode(enum.Enum):
|
| 94 |
+
"""
|
| 95 |
+
An enumeration for the copy modes supported
|
| 96 |
+
by numpy.copy() and numpy.array(). The following three modes are supported,
|
| 97 |
+
|
| 98 |
+
- ALWAYS: This means that a deep copy of the input
|
| 99 |
+
array will always be taken.
|
| 100 |
+
- IF_NEEDED: This means that a deep copy of the input
|
| 101 |
+
array will be taken only if necessary.
|
| 102 |
+
- NEVER: This means that the deep copy will never be taken.
|
| 103 |
+
If a copy cannot be avoided then a `ValueError` will be
|
| 104 |
+
raised.
|
| 105 |
+
|
| 106 |
+
Note that the buffer-protocol could in theory do copies. NumPy currently
|
| 107 |
+
assumes an object exporting the buffer protocol will never do this.
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
ALWAYS = True
|
| 111 |
+
IF_NEEDED = False
|
| 112 |
+
NEVER = 2
|
| 113 |
+
|
| 114 |
+
def __bool__(self):
|
| 115 |
+
# For backwards compatibility
|
| 116 |
+
if self == _CopyMode.ALWAYS:
|
| 117 |
+
return True
|
| 118 |
+
|
| 119 |
+
if self == _CopyMode.IF_NEEDED:
|
| 120 |
+
return False
|
| 121 |
+
|
| 122 |
+
raise ValueError(f"{self} is neither True nor False.")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
_CopyMode.__module__ = 'numpy'
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_pytesttester.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Pytest test running.
|
| 3 |
+
|
| 4 |
+
This module implements the ``test()`` function for NumPy modules. The usual
|
| 5 |
+
boiler plate for doing that is to put the following in the module
|
| 6 |
+
``__init__.py`` file::
|
| 7 |
+
|
| 8 |
+
from numpy._pytesttester import PytestTester
|
| 9 |
+
test = PytestTester(__name__)
|
| 10 |
+
del PytestTester
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Warnings filtering and other runtime settings should be dealt with in the
|
| 14 |
+
``pytest.ini`` file in the numpy repo root. The behavior of the test depends on
|
| 15 |
+
whether or not that file is found as follows:
|
| 16 |
+
|
| 17 |
+
* ``pytest.ini`` is present (develop mode)
|
| 18 |
+
All warnings except those explicitly filtered out are raised as error.
|
| 19 |
+
* ``pytest.ini`` is absent (release mode)
|
| 20 |
+
DeprecationWarnings and PendingDeprecationWarnings are ignored, other
|
| 21 |
+
warnings are passed through.
|
| 22 |
+
|
| 23 |
+
In practice, tests run from the numpy repo are run in develop mode. That
|
| 24 |
+
includes the standard ``python runtests.py`` invocation.
|
| 25 |
+
|
| 26 |
+
This module is imported by every numpy subpackage, so lies at the top level to
|
| 27 |
+
simplify circular import issues. For the same reason, it contains no numpy
|
| 28 |
+
imports at module scope, instead importing numpy within function calls.
|
| 29 |
+
"""
|
| 30 |
+
import sys
|
| 31 |
+
import os
|
| 32 |
+
|
| 33 |
+
__all__ = ['PytestTester']
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _show_numpy_info():
|
| 37 |
+
import numpy as np
|
| 38 |
+
|
| 39 |
+
print("NumPy version %s" % np.__version__)
|
| 40 |
+
relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous
|
| 41 |
+
print("NumPy relaxed strides checking option:", relaxed_strides)
|
| 42 |
+
info = np.lib.utils._opt_info()
|
| 43 |
+
print("NumPy CPU features: ", (info if info else 'nothing enabled'))
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class PytestTester:
|
| 47 |
+
"""
|
| 48 |
+
Pytest test runner.
|
| 49 |
+
|
| 50 |
+
A test function is typically added to a package's __init__.py like so::
|
| 51 |
+
|
| 52 |
+
from numpy._pytesttester import PytestTester
|
| 53 |
+
test = PytestTester(__name__).test
|
| 54 |
+
del PytestTester
|
| 55 |
+
|
| 56 |
+
Calling this test function finds and runs all tests associated with the
|
| 57 |
+
module and all its sub-modules.
|
| 58 |
+
|
| 59 |
+
Attributes
|
| 60 |
+
----------
|
| 61 |
+
module_name : str
|
| 62 |
+
Full path to the package to test.
|
| 63 |
+
|
| 64 |
+
Parameters
|
| 65 |
+
----------
|
| 66 |
+
module_name : module name
|
| 67 |
+
The name of the module to test.
|
| 68 |
+
|
| 69 |
+
Notes
|
| 70 |
+
-----
|
| 71 |
+
Unlike the previous ``nose``-based implementation, this class is not
|
| 72 |
+
publicly exposed as it performs some ``numpy``-specific warning
|
| 73 |
+
suppression.
|
| 74 |
+
|
| 75 |
+
"""
|
| 76 |
+
def __init__(self, module_name):
|
| 77 |
+
self.module_name = module_name
|
| 78 |
+
|
| 79 |
+
def __call__(self, label='fast', verbose=1, extra_argv=None,
|
| 80 |
+
doctests=False, coverage=False, durations=-1, tests=None):
|
| 81 |
+
"""
|
| 82 |
+
Run tests for module using pytest.
|
| 83 |
+
|
| 84 |
+
Parameters
|
| 85 |
+
----------
|
| 86 |
+
label : {'fast', 'full'}, optional
|
| 87 |
+
Identifies the tests to run. When set to 'fast', tests decorated
|
| 88 |
+
with `pytest.mark.slow` are skipped, when 'full', the slow marker
|
| 89 |
+
is ignored.
|
| 90 |
+
verbose : int, optional
|
| 91 |
+
Verbosity value for test outputs, in the range 1-3. Default is 1.
|
| 92 |
+
extra_argv : list, optional
|
| 93 |
+
List with any extra arguments to pass to pytests.
|
| 94 |
+
doctests : bool, optional
|
| 95 |
+
.. note:: Not supported
|
| 96 |
+
coverage : bool, optional
|
| 97 |
+
If True, report coverage of NumPy code. Default is False.
|
| 98 |
+
Requires installation of (pip) pytest-cov.
|
| 99 |
+
durations : int, optional
|
| 100 |
+
If < 0, do nothing, If 0, report time of all tests, if > 0,
|
| 101 |
+
report the time of the slowest `timer` tests. Default is -1.
|
| 102 |
+
tests : test or list of tests
|
| 103 |
+
Tests to be executed with pytest '--pyargs'
|
| 104 |
+
|
| 105 |
+
Returns
|
| 106 |
+
-------
|
| 107 |
+
result : bool
|
| 108 |
+
Return True on success, false otherwise.
|
| 109 |
+
|
| 110 |
+
Notes
|
| 111 |
+
-----
|
| 112 |
+
Each NumPy module exposes `test` in its namespace to run all tests for
|
| 113 |
+
it. For example, to run all tests for numpy.lib:
|
| 114 |
+
|
| 115 |
+
>>> np.lib.test() #doctest: +SKIP
|
| 116 |
+
|
| 117 |
+
Examples
|
| 118 |
+
--------
|
| 119 |
+
>>> result = np.lib.test() #doctest: +SKIP
|
| 120 |
+
...
|
| 121 |
+
1023 passed, 2 skipped, 6 deselected, 1 xfailed in 10.39 seconds
|
| 122 |
+
>>> result
|
| 123 |
+
True
|
| 124 |
+
|
| 125 |
+
"""
|
| 126 |
+
import pytest
|
| 127 |
+
import warnings
|
| 128 |
+
|
| 129 |
+
module = sys.modules[self.module_name]
|
| 130 |
+
module_path = os.path.abspath(module.__path__[0])
|
| 131 |
+
|
| 132 |
+
# setup the pytest arguments
|
| 133 |
+
pytest_args = ["-l"]
|
| 134 |
+
|
| 135 |
+
# offset verbosity. The "-q" cancels a "-v".
|
| 136 |
+
pytest_args += ["-q"]
|
| 137 |
+
|
| 138 |
+
with warnings.catch_warnings():
|
| 139 |
+
warnings.simplefilter("always")
|
| 140 |
+
# Filter out distutils cpu warnings (could be localized to
|
| 141 |
+
# distutils tests). ASV has problems with top level import,
|
| 142 |
+
# so fetch module for suppression here.
|
| 143 |
+
from numpy.distutils import cpuinfo
|
| 144 |
+
|
| 145 |
+
with warnings.catch_warnings(record=True):
|
| 146 |
+
# Ignore the warning from importing the array_api submodule. This
|
| 147 |
+
# warning is done on import, so it would break pytest collection,
|
| 148 |
+
# but importing it early here prevents the warning from being
|
| 149 |
+
# issued when it imported again.
|
| 150 |
+
import numpy.array_api
|
| 151 |
+
|
| 152 |
+
# Filter out annoying import messages. Want these in both develop and
|
| 153 |
+
# release mode.
|
| 154 |
+
pytest_args += [
|
| 155 |
+
"-W ignore:Not importing directory",
|
| 156 |
+
"-W ignore:numpy.dtype size changed",
|
| 157 |
+
"-W ignore:numpy.ufunc size changed",
|
| 158 |
+
"-W ignore::UserWarning:cpuinfo",
|
| 159 |
+
]
|
| 160 |
+
|
| 161 |
+
# When testing matrices, ignore their PendingDeprecationWarnings
|
| 162 |
+
pytest_args += [
|
| 163 |
+
"-W ignore:the matrix subclass is not",
|
| 164 |
+
"-W ignore:Importing from numpy.matlib is",
|
| 165 |
+
]
|
| 166 |
+
|
| 167 |
+
if doctests:
|
| 168 |
+
pytest_args += ["--doctest-modules"]
|
| 169 |
+
|
| 170 |
+
if extra_argv:
|
| 171 |
+
pytest_args += list(extra_argv)
|
| 172 |
+
|
| 173 |
+
if verbose > 1:
|
| 174 |
+
pytest_args += ["-" + "v"*(verbose - 1)]
|
| 175 |
+
|
| 176 |
+
if coverage:
|
| 177 |
+
pytest_args += ["--cov=" + module_path]
|
| 178 |
+
|
| 179 |
+
if label == "fast":
|
| 180 |
+
# not importing at the top level to avoid circular import of module
|
| 181 |
+
from numpy.testing import IS_PYPY
|
| 182 |
+
if IS_PYPY:
|
| 183 |
+
pytest_args += ["-m", "not slow and not slow_pypy"]
|
| 184 |
+
else:
|
| 185 |
+
pytest_args += ["-m", "not slow"]
|
| 186 |
+
|
| 187 |
+
elif label != "full":
|
| 188 |
+
pytest_args += ["-m", label]
|
| 189 |
+
|
| 190 |
+
if durations >= 0:
|
| 191 |
+
pytest_args += ["--durations=%s" % durations]
|
| 192 |
+
|
| 193 |
+
if tests is None:
|
| 194 |
+
tests = [self.module_name]
|
| 195 |
+
|
| 196 |
+
pytest_args += ["--pyargs"] + list(tests)
|
| 197 |
+
|
| 198 |
+
# run tests.
|
| 199 |
+
_show_numpy_info()
|
| 200 |
+
|
| 201 |
+
try:
|
| 202 |
+
code = pytest.main(pytest_args)
|
| 203 |
+
except SystemExit as exc:
|
| 204 |
+
code = exc.code
|
| 205 |
+
|
| 206 |
+
return code == 0
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_pytesttester.pyi
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Iterable
|
| 2 |
+
from typing import Literal as L
|
| 3 |
+
|
| 4 |
+
__all__: list[str]
|
| 5 |
+
|
| 6 |
+
class PytestTester:
|
| 7 |
+
module_name: str
|
| 8 |
+
def __init__(self, module_name: str) -> None: ...
|
| 9 |
+
def __call__(
|
| 10 |
+
self,
|
| 11 |
+
label: L["fast", "full"] = ...,
|
| 12 |
+
verbose: int = ...,
|
| 13 |
+
extra_argv: None | Iterable[str] = ...,
|
| 14 |
+
doctests: L[False] = ...,
|
| 15 |
+
coverage: bool = ...,
|
| 16 |
+
durations: int = ...,
|
| 17 |
+
tests: None | Iterable[str] = ...,
|
| 18 |
+
) -> bool: ...
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/_version.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# This file was generated by 'versioneer.py' (0.26) from
|
| 3 |
+
# revision-control system data, or from the parent directory name of an
|
| 4 |
+
# unpacked source archive. Distribution tarballs contain a pre-generated copy
|
| 5 |
+
# of this file.
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
|
| 9 |
+
version_json = '''
|
| 10 |
+
{
|
| 11 |
+
"date": "2023-06-25T20:31:30-0600",
|
| 12 |
+
"dirty": false,
|
| 13 |
+
"error": null,
|
| 14 |
+
"full-revisionid": "9315a9072b2636f75c831b4eca9f42a5f67ca2fb",
|
| 15 |
+
"version": "1.24.4"
|
| 16 |
+
}
|
| 17 |
+
''' # END VERSION_JSON
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def get_versions():
|
| 21 |
+
return json.loads(version_json)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/conftest.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Pytest configuration and fixtures for the Numpy test suite.
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
import tempfile
|
| 6 |
+
|
| 7 |
+
import hypothesis
|
| 8 |
+
import pytest
|
| 9 |
+
import numpy
|
| 10 |
+
|
| 11 |
+
from numpy.core._multiarray_tests import get_fpu_mode
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
_old_fpu_mode = None
|
| 15 |
+
_collect_results = {}
|
| 16 |
+
|
| 17 |
+
# Use a known and persistent tmpdir for hypothesis' caches, which
|
| 18 |
+
# can be automatically cleared by the OS or user.
|
| 19 |
+
hypothesis.configuration.set_hypothesis_home_dir(
|
| 20 |
+
os.path.join(tempfile.gettempdir(), ".hypothesis")
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# We register two custom profiles for Numpy - for details see
|
| 24 |
+
# https://hypothesis.readthedocs.io/en/latest/settings.html
|
| 25 |
+
# The first is designed for our own CI runs; the latter also
|
| 26 |
+
# forces determinism and is designed for use via np.test()
|
| 27 |
+
hypothesis.settings.register_profile(
|
| 28 |
+
name="numpy-profile", deadline=None, print_blob=True,
|
| 29 |
+
)
|
| 30 |
+
hypothesis.settings.register_profile(
|
| 31 |
+
name="np.test() profile",
|
| 32 |
+
deadline=None, print_blob=True, database=None, derandomize=True,
|
| 33 |
+
suppress_health_check=list(hypothesis.HealthCheck),
|
| 34 |
+
)
|
| 35 |
+
# Note that the default profile is chosen based on the presence
|
| 36 |
+
# of pytest.ini, but can be overridden by passing the
|
| 37 |
+
# --hypothesis-profile=NAME argument to pytest.
|
| 38 |
+
_pytest_ini = os.path.join(os.path.dirname(__file__), "..", "pytest.ini")
|
| 39 |
+
hypothesis.settings.load_profile(
|
| 40 |
+
"numpy-profile" if os.path.isfile(_pytest_ini) else "np.test() profile"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def pytest_configure(config):
|
| 45 |
+
config.addinivalue_line("markers",
|
| 46 |
+
"valgrind_error: Tests that are known to error under valgrind.")
|
| 47 |
+
config.addinivalue_line("markers",
|
| 48 |
+
"leaks_references: Tests that are known to leak references.")
|
| 49 |
+
config.addinivalue_line("markers",
|
| 50 |
+
"slow: Tests that are very slow.")
|
| 51 |
+
config.addinivalue_line("markers",
|
| 52 |
+
"slow_pypy: Tests that are very slow on pypy.")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def pytest_addoption(parser):
|
| 56 |
+
parser.addoption("--available-memory", action="store", default=None,
|
| 57 |
+
help=("Set amount of memory available for running the "
|
| 58 |
+
"test suite. This can result to tests requiring "
|
| 59 |
+
"especially large amounts of memory to be skipped. "
|
| 60 |
+
"Equivalent to setting environment variable "
|
| 61 |
+
"NPY_AVAILABLE_MEM. Default: determined"
|
| 62 |
+
"automatically."))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def pytest_sessionstart(session):
|
| 66 |
+
available_mem = session.config.getoption('available_memory')
|
| 67 |
+
if available_mem is not None:
|
| 68 |
+
os.environ['NPY_AVAILABLE_MEM'] = available_mem
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
#FIXME when yield tests are gone.
|
| 72 |
+
@pytest.hookimpl()
|
| 73 |
+
def pytest_itemcollected(item):
|
| 74 |
+
"""
|
| 75 |
+
Check FPU precision mode was not changed during test collection.
|
| 76 |
+
|
| 77 |
+
The clumsy way we do it here is mainly necessary because numpy
|
| 78 |
+
still uses yield tests, which can execute code at test collection
|
| 79 |
+
time.
|
| 80 |
+
"""
|
| 81 |
+
global _old_fpu_mode
|
| 82 |
+
|
| 83 |
+
mode = get_fpu_mode()
|
| 84 |
+
|
| 85 |
+
if _old_fpu_mode is None:
|
| 86 |
+
_old_fpu_mode = mode
|
| 87 |
+
elif mode != _old_fpu_mode:
|
| 88 |
+
_collect_results[item] = (_old_fpu_mode, mode)
|
| 89 |
+
_old_fpu_mode = mode
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@pytest.fixture(scope="function", autouse=True)
|
| 93 |
+
def check_fpu_mode(request):
|
| 94 |
+
"""
|
| 95 |
+
Check FPU precision mode was not changed during the test.
|
| 96 |
+
"""
|
| 97 |
+
old_mode = get_fpu_mode()
|
| 98 |
+
yield
|
| 99 |
+
new_mode = get_fpu_mode()
|
| 100 |
+
|
| 101 |
+
if old_mode != new_mode:
|
| 102 |
+
raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"
|
| 103 |
+
" during the test".format(old_mode, new_mode))
|
| 104 |
+
|
| 105 |
+
collect_result = _collect_results.get(request.node)
|
| 106 |
+
if collect_result is not None:
|
| 107 |
+
old_mode, new_mode = collect_result
|
| 108 |
+
raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"
|
| 109 |
+
" when collecting the test".format(old_mode,
|
| 110 |
+
new_mode))
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@pytest.fixture(autouse=True)
|
| 114 |
+
def add_np(doctest_namespace):
|
| 115 |
+
doctest_namespace['np'] = numpy
|
| 116 |
+
|
| 117 |
+
@pytest.fixture(autouse=True)
|
| 118 |
+
def env_setup(monkeypatch):
|
| 119 |
+
monkeypatch.setenv('PYTHONHASHSEED', '0')
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@pytest.fixture(params=[True, False])
|
| 123 |
+
def weak_promotion(request):
|
| 124 |
+
"""
|
| 125 |
+
Fixture to ensure "legacy" promotion state or change it to use the new
|
| 126 |
+
weak promotion (plus warning). `old_promotion` should be used as a
|
| 127 |
+
parameter in the function.
|
| 128 |
+
"""
|
| 129 |
+
state = numpy._get_promotion_state()
|
| 130 |
+
if request.param:
|
| 131 |
+
numpy._set_promotion_state("weak_and_warn")
|
| 132 |
+
else:
|
| 133 |
+
numpy._set_promotion_state("legacy")
|
| 134 |
+
|
| 135 |
+
yield request.param
|
| 136 |
+
numpy._set_promotion_state(state)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/ctypeslib.py
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
============================
|
| 3 |
+
``ctypes`` Utility Functions
|
| 4 |
+
============================
|
| 5 |
+
|
| 6 |
+
See Also
|
| 7 |
+
--------
|
| 8 |
+
load_library : Load a C library.
|
| 9 |
+
ndpointer : Array restype/argtype with verification.
|
| 10 |
+
as_ctypes : Create a ctypes array from an ndarray.
|
| 11 |
+
as_array : Create an ndarray from a ctypes array.
|
| 12 |
+
|
| 13 |
+
References
|
| 14 |
+
----------
|
| 15 |
+
.. [1] "SciPy Cookbook: ctypes", https://scipy-cookbook.readthedocs.io/items/Ctypes.html
|
| 16 |
+
|
| 17 |
+
Examples
|
| 18 |
+
--------
|
| 19 |
+
Load the C library:
|
| 20 |
+
|
| 21 |
+
>>> _lib = np.ctypeslib.load_library('libmystuff', '.') #doctest: +SKIP
|
| 22 |
+
|
| 23 |
+
Our result type, an ndarray that must be of type double, be 1-dimensional
|
| 24 |
+
and is C-contiguous in memory:
|
| 25 |
+
|
| 26 |
+
>>> array_1d_double = np.ctypeslib.ndpointer(
|
| 27 |
+
... dtype=np.double,
|
| 28 |
+
... ndim=1, flags='CONTIGUOUS') #doctest: +SKIP
|
| 29 |
+
|
| 30 |
+
Our C-function typically takes an array and updates its values
|
| 31 |
+
in-place. For example::
|
| 32 |
+
|
| 33 |
+
void foo_func(double* x, int length)
|
| 34 |
+
{
|
| 35 |
+
int i;
|
| 36 |
+
for (i = 0; i < length; i++) {
|
| 37 |
+
x[i] = i*i;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
We wrap it using:
|
| 42 |
+
|
| 43 |
+
>>> _lib.foo_func.restype = None #doctest: +SKIP
|
| 44 |
+
>>> _lib.foo_func.argtypes = [array_1d_double, c_int] #doctest: +SKIP
|
| 45 |
+
|
| 46 |
+
Then, we're ready to call ``foo_func``:
|
| 47 |
+
|
| 48 |
+
>>> out = np.empty(15, dtype=np.double)
|
| 49 |
+
>>> _lib.foo_func(out, len(out)) #doctest: +SKIP
|
| 50 |
+
|
| 51 |
+
"""
|
| 52 |
+
__all__ = ['load_library', 'ndpointer', 'c_intp', 'as_ctypes', 'as_array',
|
| 53 |
+
'as_ctypes_type']
|
| 54 |
+
|
| 55 |
+
import os
|
| 56 |
+
from numpy import (
|
| 57 |
+
integer, ndarray, dtype as _dtype, asarray, frombuffer
|
| 58 |
+
)
|
| 59 |
+
from numpy.core.multiarray import _flagdict, flagsobj
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
import ctypes
|
| 63 |
+
except ImportError:
|
| 64 |
+
ctypes = None
|
| 65 |
+
|
| 66 |
+
if ctypes is None:
|
| 67 |
+
def _dummy(*args, **kwds):
|
| 68 |
+
"""
|
| 69 |
+
Dummy object that raises an ImportError if ctypes is not available.
|
| 70 |
+
|
| 71 |
+
Raises
|
| 72 |
+
------
|
| 73 |
+
ImportError
|
| 74 |
+
If ctypes is not available.
|
| 75 |
+
|
| 76 |
+
"""
|
| 77 |
+
raise ImportError("ctypes is not available.")
|
| 78 |
+
load_library = _dummy
|
| 79 |
+
as_ctypes = _dummy
|
| 80 |
+
as_array = _dummy
|
| 81 |
+
from numpy import intp as c_intp
|
| 82 |
+
_ndptr_base = object
|
| 83 |
+
else:
|
| 84 |
+
import numpy.core._internal as nic
|
| 85 |
+
c_intp = nic._getintp_ctype()
|
| 86 |
+
del nic
|
| 87 |
+
_ndptr_base = ctypes.c_void_p
|
| 88 |
+
|
| 89 |
+
# Adapted from Albert Strasheim
|
| 90 |
+
def load_library(libname, loader_path):
|
| 91 |
+
"""
|
| 92 |
+
It is possible to load a library using
|
| 93 |
+
|
| 94 |
+
>>> lib = ctypes.cdll[<full_path_name>] # doctest: +SKIP
|
| 95 |
+
|
| 96 |
+
But there are cross-platform considerations, such as library file extensions,
|
| 97 |
+
plus the fact Windows will just load the first library it finds with that name.
|
| 98 |
+
NumPy supplies the load_library function as a convenience.
|
| 99 |
+
|
| 100 |
+
.. versionchanged:: 1.20.0
|
| 101 |
+
Allow libname and loader_path to take any
|
| 102 |
+
:term:`python:path-like object`.
|
| 103 |
+
|
| 104 |
+
Parameters
|
| 105 |
+
----------
|
| 106 |
+
libname : path-like
|
| 107 |
+
Name of the library, which can have 'lib' as a prefix,
|
| 108 |
+
but without an extension.
|
| 109 |
+
loader_path : path-like
|
| 110 |
+
Where the library can be found.
|
| 111 |
+
|
| 112 |
+
Returns
|
| 113 |
+
-------
|
| 114 |
+
ctypes.cdll[libpath] : library object
|
| 115 |
+
A ctypes library object
|
| 116 |
+
|
| 117 |
+
Raises
|
| 118 |
+
------
|
| 119 |
+
OSError
|
| 120 |
+
If there is no library with the expected extension, or the
|
| 121 |
+
library is defective and cannot be loaded.
|
| 122 |
+
"""
|
| 123 |
+
if ctypes.__version__ < '1.0.1':
|
| 124 |
+
import warnings
|
| 125 |
+
warnings.warn("All features of ctypes interface may not work "
|
| 126 |
+
"with ctypes < 1.0.1", stacklevel=2)
|
| 127 |
+
|
| 128 |
+
# Convert path-like objects into strings
|
| 129 |
+
libname = os.fsdecode(libname)
|
| 130 |
+
loader_path = os.fsdecode(loader_path)
|
| 131 |
+
|
| 132 |
+
ext = os.path.splitext(libname)[1]
|
| 133 |
+
if not ext:
|
| 134 |
+
# Try to load library with platform-specific name, otherwise
|
| 135 |
+
# default to libname.[so|pyd]. Sometimes, these files are built
|
| 136 |
+
# erroneously on non-linux platforms.
|
| 137 |
+
from numpy.distutils.misc_util import get_shared_lib_extension
|
| 138 |
+
so_ext = get_shared_lib_extension()
|
| 139 |
+
libname_ext = [libname + so_ext]
|
| 140 |
+
# mac, windows and linux >= py3.2 shared library and loadable
|
| 141 |
+
# module have different extensions so try both
|
| 142 |
+
so_ext2 = get_shared_lib_extension(is_python_ext=True)
|
| 143 |
+
if not so_ext2 == so_ext:
|
| 144 |
+
libname_ext.insert(0, libname + so_ext2)
|
| 145 |
+
else:
|
| 146 |
+
libname_ext = [libname]
|
| 147 |
+
|
| 148 |
+
loader_path = os.path.abspath(loader_path)
|
| 149 |
+
if not os.path.isdir(loader_path):
|
| 150 |
+
libdir = os.path.dirname(loader_path)
|
| 151 |
+
else:
|
| 152 |
+
libdir = loader_path
|
| 153 |
+
|
| 154 |
+
for ln in libname_ext:
|
| 155 |
+
libpath = os.path.join(libdir, ln)
|
| 156 |
+
if os.path.exists(libpath):
|
| 157 |
+
try:
|
| 158 |
+
return ctypes.cdll[libpath]
|
| 159 |
+
except OSError:
|
| 160 |
+
## defective lib file
|
| 161 |
+
raise
|
| 162 |
+
## if no successful return in the libname_ext loop:
|
| 163 |
+
raise OSError("no file with expected extension")
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _num_fromflags(flaglist):
|
| 167 |
+
num = 0
|
| 168 |
+
for val in flaglist:
|
| 169 |
+
num += _flagdict[val]
|
| 170 |
+
return num
|
| 171 |
+
|
| 172 |
+
_flagnames = ['C_CONTIGUOUS', 'F_CONTIGUOUS', 'ALIGNED', 'WRITEABLE',
|
| 173 |
+
'OWNDATA', 'WRITEBACKIFCOPY']
|
| 174 |
+
def _flags_fromnum(num):
|
| 175 |
+
res = []
|
| 176 |
+
for key in _flagnames:
|
| 177 |
+
value = _flagdict[key]
|
| 178 |
+
if (num & value):
|
| 179 |
+
res.append(key)
|
| 180 |
+
return res
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class _ndptr(_ndptr_base):
|
| 184 |
+
@classmethod
|
| 185 |
+
def from_param(cls, obj):
|
| 186 |
+
if not isinstance(obj, ndarray):
|
| 187 |
+
raise TypeError("argument must be an ndarray")
|
| 188 |
+
if cls._dtype_ is not None \
|
| 189 |
+
and obj.dtype != cls._dtype_:
|
| 190 |
+
raise TypeError("array must have data type %s" % cls._dtype_)
|
| 191 |
+
if cls._ndim_ is not None \
|
| 192 |
+
and obj.ndim != cls._ndim_:
|
| 193 |
+
raise TypeError("array must have %d dimension(s)" % cls._ndim_)
|
| 194 |
+
if cls._shape_ is not None \
|
| 195 |
+
and obj.shape != cls._shape_:
|
| 196 |
+
raise TypeError("array must have shape %s" % str(cls._shape_))
|
| 197 |
+
if cls._flags_ is not None \
|
| 198 |
+
and ((obj.flags.num & cls._flags_) != cls._flags_):
|
| 199 |
+
raise TypeError("array must have flags %s" %
|
| 200 |
+
_flags_fromnum(cls._flags_))
|
| 201 |
+
return obj.ctypes
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
class _concrete_ndptr(_ndptr):
|
| 205 |
+
"""
|
| 206 |
+
Like _ndptr, but with `_shape_` and `_dtype_` specified.
|
| 207 |
+
|
| 208 |
+
Notably, this means the pointer has enough information to reconstruct
|
| 209 |
+
the array, which is not generally true.
|
| 210 |
+
"""
|
| 211 |
+
def _check_retval_(self):
|
| 212 |
+
"""
|
| 213 |
+
This method is called when this class is used as the .restype
|
| 214 |
+
attribute for a shared-library function, to automatically wrap the
|
| 215 |
+
pointer into an array.
|
| 216 |
+
"""
|
| 217 |
+
return self.contents
|
| 218 |
+
|
| 219 |
+
@property
|
| 220 |
+
def contents(self):
|
| 221 |
+
"""
|
| 222 |
+
Get an ndarray viewing the data pointed to by this pointer.
|
| 223 |
+
|
| 224 |
+
This mirrors the `contents` attribute of a normal ctypes pointer
|
| 225 |
+
"""
|
| 226 |
+
full_dtype = _dtype((self._dtype_, self._shape_))
|
| 227 |
+
full_ctype = ctypes.c_char * full_dtype.itemsize
|
| 228 |
+
buffer = ctypes.cast(self, ctypes.POINTER(full_ctype)).contents
|
| 229 |
+
return frombuffer(buffer, dtype=full_dtype).squeeze(axis=0)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
# Factory for an array-checking class with from_param defined for
|
| 233 |
+
# use with ctypes argtypes mechanism
|
| 234 |
+
_pointer_type_cache = {}
|
| 235 |
+
def ndpointer(dtype=None, ndim=None, shape=None, flags=None):
|
| 236 |
+
"""
|
| 237 |
+
Array-checking restype/argtypes.
|
| 238 |
+
|
| 239 |
+
An ndpointer instance is used to describe an ndarray in restypes
|
| 240 |
+
and argtypes specifications. This approach is more flexible than
|
| 241 |
+
using, for example, ``POINTER(c_double)``, since several restrictions
|
| 242 |
+
can be specified, which are verified upon calling the ctypes function.
|
| 243 |
+
These include data type, number of dimensions, shape and flags. If a
|
| 244 |
+
given array does not satisfy the specified restrictions,
|
| 245 |
+
a ``TypeError`` is raised.
|
| 246 |
+
|
| 247 |
+
Parameters
|
| 248 |
+
----------
|
| 249 |
+
dtype : data-type, optional
|
| 250 |
+
Array data-type.
|
| 251 |
+
ndim : int, optional
|
| 252 |
+
Number of array dimensions.
|
| 253 |
+
shape : tuple of ints, optional
|
| 254 |
+
Array shape.
|
| 255 |
+
flags : str or tuple of str
|
| 256 |
+
Array flags; may be one or more of:
|
| 257 |
+
|
| 258 |
+
- C_CONTIGUOUS / C / CONTIGUOUS
|
| 259 |
+
- F_CONTIGUOUS / F / FORTRAN
|
| 260 |
+
- OWNDATA / O
|
| 261 |
+
- WRITEABLE / W
|
| 262 |
+
- ALIGNED / A
|
| 263 |
+
- WRITEBACKIFCOPY / X
|
| 264 |
+
|
| 265 |
+
Returns
|
| 266 |
+
-------
|
| 267 |
+
klass : ndpointer type object
|
| 268 |
+
A type object, which is an ``_ndtpr`` instance containing
|
| 269 |
+
dtype, ndim, shape and flags information.
|
| 270 |
+
|
| 271 |
+
Raises
|
| 272 |
+
------
|
| 273 |
+
TypeError
|
| 274 |
+
If a given array does not satisfy the specified restrictions.
|
| 275 |
+
|
| 276 |
+
Examples
|
| 277 |
+
--------
|
| 278 |
+
>>> clib.somefunc.argtypes = [np.ctypeslib.ndpointer(dtype=np.float64,
|
| 279 |
+
... ndim=1,
|
| 280 |
+
... flags='C_CONTIGUOUS')]
|
| 281 |
+
... #doctest: +SKIP
|
| 282 |
+
>>> clib.somefunc(np.array([1, 2, 3], dtype=np.float64))
|
| 283 |
+
... #doctest: +SKIP
|
| 284 |
+
|
| 285 |
+
"""
|
| 286 |
+
|
| 287 |
+
# normalize dtype to an Optional[dtype]
|
| 288 |
+
if dtype is not None:
|
| 289 |
+
dtype = _dtype(dtype)
|
| 290 |
+
|
| 291 |
+
# normalize flags to an Optional[int]
|
| 292 |
+
num = None
|
| 293 |
+
if flags is not None:
|
| 294 |
+
if isinstance(flags, str):
|
| 295 |
+
flags = flags.split(',')
|
| 296 |
+
elif isinstance(flags, (int, integer)):
|
| 297 |
+
num = flags
|
| 298 |
+
flags = _flags_fromnum(num)
|
| 299 |
+
elif isinstance(flags, flagsobj):
|
| 300 |
+
num = flags.num
|
| 301 |
+
flags = _flags_fromnum(num)
|
| 302 |
+
if num is None:
|
| 303 |
+
try:
|
| 304 |
+
flags = [x.strip().upper() for x in flags]
|
| 305 |
+
except Exception as e:
|
| 306 |
+
raise TypeError("invalid flags specification") from e
|
| 307 |
+
num = _num_fromflags(flags)
|
| 308 |
+
|
| 309 |
+
# normalize shape to an Optional[tuple]
|
| 310 |
+
if shape is not None:
|
| 311 |
+
try:
|
| 312 |
+
shape = tuple(shape)
|
| 313 |
+
except TypeError:
|
| 314 |
+
# single integer -> 1-tuple
|
| 315 |
+
shape = (shape,)
|
| 316 |
+
|
| 317 |
+
cache_key = (dtype, ndim, shape, num)
|
| 318 |
+
|
| 319 |
+
try:
|
| 320 |
+
return _pointer_type_cache[cache_key]
|
| 321 |
+
except KeyError:
|
| 322 |
+
pass
|
| 323 |
+
|
| 324 |
+
# produce a name for the new type
|
| 325 |
+
if dtype is None:
|
| 326 |
+
name = 'any'
|
| 327 |
+
elif dtype.names is not None:
|
| 328 |
+
name = str(id(dtype))
|
| 329 |
+
else:
|
| 330 |
+
name = dtype.str
|
| 331 |
+
if ndim is not None:
|
| 332 |
+
name += "_%dd" % ndim
|
| 333 |
+
if shape is not None:
|
| 334 |
+
name += "_"+"x".join(str(x) for x in shape)
|
| 335 |
+
if flags is not None:
|
| 336 |
+
name += "_"+"_".join(flags)
|
| 337 |
+
|
| 338 |
+
if dtype is not None and shape is not None:
|
| 339 |
+
base = _concrete_ndptr
|
| 340 |
+
else:
|
| 341 |
+
base = _ndptr
|
| 342 |
+
|
| 343 |
+
klass = type("ndpointer_%s"%name, (base,),
|
| 344 |
+
{"_dtype_": dtype,
|
| 345 |
+
"_shape_" : shape,
|
| 346 |
+
"_ndim_" : ndim,
|
| 347 |
+
"_flags_" : num})
|
| 348 |
+
_pointer_type_cache[cache_key] = klass
|
| 349 |
+
return klass
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
if ctypes is not None:
|
| 353 |
+
def _ctype_ndarray(element_type, shape):
|
| 354 |
+
""" Create an ndarray of the given element type and shape """
|
| 355 |
+
for dim in shape[::-1]:
|
| 356 |
+
element_type = dim * element_type
|
| 357 |
+
# prevent the type name include np.ctypeslib
|
| 358 |
+
element_type.__module__ = None
|
| 359 |
+
return element_type
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
def _get_scalar_type_map():
|
| 363 |
+
"""
|
| 364 |
+
Return a dictionary mapping native endian scalar dtype to ctypes types
|
| 365 |
+
"""
|
| 366 |
+
ct = ctypes
|
| 367 |
+
simple_types = [
|
| 368 |
+
ct.c_byte, ct.c_short, ct.c_int, ct.c_long, ct.c_longlong,
|
| 369 |
+
ct.c_ubyte, ct.c_ushort, ct.c_uint, ct.c_ulong, ct.c_ulonglong,
|
| 370 |
+
ct.c_float, ct.c_double,
|
| 371 |
+
ct.c_bool,
|
| 372 |
+
]
|
| 373 |
+
return {_dtype(ctype): ctype for ctype in simple_types}
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
_scalar_type_map = _get_scalar_type_map()
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def _ctype_from_dtype_scalar(dtype):
|
| 380 |
+
# swapping twice ensure that `=` is promoted to <, >, or |
|
| 381 |
+
dtype_with_endian = dtype.newbyteorder('S').newbyteorder('S')
|
| 382 |
+
dtype_native = dtype.newbyteorder('=')
|
| 383 |
+
try:
|
| 384 |
+
ctype = _scalar_type_map[dtype_native]
|
| 385 |
+
except KeyError as e:
|
| 386 |
+
raise NotImplementedError(
|
| 387 |
+
"Converting {!r} to a ctypes type".format(dtype)
|
| 388 |
+
) from None
|
| 389 |
+
|
| 390 |
+
if dtype_with_endian.byteorder == '>':
|
| 391 |
+
ctype = ctype.__ctype_be__
|
| 392 |
+
elif dtype_with_endian.byteorder == '<':
|
| 393 |
+
ctype = ctype.__ctype_le__
|
| 394 |
+
|
| 395 |
+
return ctype
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def _ctype_from_dtype_subarray(dtype):
|
| 399 |
+
element_dtype, shape = dtype.subdtype
|
| 400 |
+
ctype = _ctype_from_dtype(element_dtype)
|
| 401 |
+
return _ctype_ndarray(ctype, shape)
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def _ctype_from_dtype_structured(dtype):
|
| 405 |
+
# extract offsets of each field
|
| 406 |
+
field_data = []
|
| 407 |
+
for name in dtype.names:
|
| 408 |
+
field_dtype, offset = dtype.fields[name][:2]
|
| 409 |
+
field_data.append((offset, name, _ctype_from_dtype(field_dtype)))
|
| 410 |
+
|
| 411 |
+
# ctypes doesn't care about field order
|
| 412 |
+
field_data = sorted(field_data, key=lambda f: f[0])
|
| 413 |
+
|
| 414 |
+
if len(field_data) > 1 and all(offset == 0 for offset, name, ctype in field_data):
|
| 415 |
+
# union, if multiple fields all at address 0
|
| 416 |
+
size = 0
|
| 417 |
+
_fields_ = []
|
| 418 |
+
for offset, name, ctype in field_data:
|
| 419 |
+
_fields_.append((name, ctype))
|
| 420 |
+
size = max(size, ctypes.sizeof(ctype))
|
| 421 |
+
|
| 422 |
+
# pad to the right size
|
| 423 |
+
if dtype.itemsize != size:
|
| 424 |
+
_fields_.append(('', ctypes.c_char * dtype.itemsize))
|
| 425 |
+
|
| 426 |
+
# we inserted manual padding, so always `_pack_`
|
| 427 |
+
return type('union', (ctypes.Union,), dict(
|
| 428 |
+
_fields_=_fields_,
|
| 429 |
+
_pack_=1,
|
| 430 |
+
__module__=None,
|
| 431 |
+
))
|
| 432 |
+
else:
|
| 433 |
+
last_offset = 0
|
| 434 |
+
_fields_ = []
|
| 435 |
+
for offset, name, ctype in field_data:
|
| 436 |
+
padding = offset - last_offset
|
| 437 |
+
if padding < 0:
|
| 438 |
+
raise NotImplementedError("Overlapping fields")
|
| 439 |
+
if padding > 0:
|
| 440 |
+
_fields_.append(('', ctypes.c_char * padding))
|
| 441 |
+
|
| 442 |
+
_fields_.append((name, ctype))
|
| 443 |
+
last_offset = offset + ctypes.sizeof(ctype)
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
padding = dtype.itemsize - last_offset
|
| 447 |
+
if padding > 0:
|
| 448 |
+
_fields_.append(('', ctypes.c_char * padding))
|
| 449 |
+
|
| 450 |
+
# we inserted manual padding, so always `_pack_`
|
| 451 |
+
return type('struct', (ctypes.Structure,), dict(
|
| 452 |
+
_fields_=_fields_,
|
| 453 |
+
_pack_=1,
|
| 454 |
+
__module__=None,
|
| 455 |
+
))
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def _ctype_from_dtype(dtype):
|
| 459 |
+
if dtype.fields is not None:
|
| 460 |
+
return _ctype_from_dtype_structured(dtype)
|
| 461 |
+
elif dtype.subdtype is not None:
|
| 462 |
+
return _ctype_from_dtype_subarray(dtype)
|
| 463 |
+
else:
|
| 464 |
+
return _ctype_from_dtype_scalar(dtype)
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
def as_ctypes_type(dtype):
|
| 468 |
+
r"""
|
| 469 |
+
Convert a dtype into a ctypes type.
|
| 470 |
+
|
| 471 |
+
Parameters
|
| 472 |
+
----------
|
| 473 |
+
dtype : dtype
|
| 474 |
+
The dtype to convert
|
| 475 |
+
|
| 476 |
+
Returns
|
| 477 |
+
-------
|
| 478 |
+
ctype
|
| 479 |
+
A ctype scalar, union, array, or struct
|
| 480 |
+
|
| 481 |
+
Raises
|
| 482 |
+
------
|
| 483 |
+
NotImplementedError
|
| 484 |
+
If the conversion is not possible
|
| 485 |
+
|
| 486 |
+
Notes
|
| 487 |
+
-----
|
| 488 |
+
This function does not losslessly round-trip in either direction.
|
| 489 |
+
|
| 490 |
+
``np.dtype(as_ctypes_type(dt))`` will:
|
| 491 |
+
|
| 492 |
+
- insert padding fields
|
| 493 |
+
- reorder fields to be sorted by offset
|
| 494 |
+
- discard field titles
|
| 495 |
+
|
| 496 |
+
``as_ctypes_type(np.dtype(ctype))`` will:
|
| 497 |
+
|
| 498 |
+
- discard the class names of `ctypes.Structure`\ s and
|
| 499 |
+
`ctypes.Union`\ s
|
| 500 |
+
- convert single-element `ctypes.Union`\ s into single-element
|
| 501 |
+
`ctypes.Structure`\ s
|
| 502 |
+
- insert padding fields
|
| 503 |
+
|
| 504 |
+
"""
|
| 505 |
+
return _ctype_from_dtype(_dtype(dtype))
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def as_array(obj, shape=None):
|
| 509 |
+
"""
|
| 510 |
+
Create a numpy array from a ctypes array or POINTER.
|
| 511 |
+
|
| 512 |
+
The numpy array shares the memory with the ctypes object.
|
| 513 |
+
|
| 514 |
+
The shape parameter must be given if converting from a ctypes POINTER.
|
| 515 |
+
The shape parameter is ignored if converting from a ctypes array
|
| 516 |
+
"""
|
| 517 |
+
if isinstance(obj, ctypes._Pointer):
|
| 518 |
+
# convert pointers to an array of the desired shape
|
| 519 |
+
if shape is None:
|
| 520 |
+
raise TypeError(
|
| 521 |
+
'as_array() requires a shape argument when called on a '
|
| 522 |
+
'pointer')
|
| 523 |
+
p_arr_type = ctypes.POINTER(_ctype_ndarray(obj._type_, shape))
|
| 524 |
+
obj = ctypes.cast(obj, p_arr_type).contents
|
| 525 |
+
|
| 526 |
+
return asarray(obj)
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
def as_ctypes(obj):
|
| 530 |
+
"""Create and return a ctypes object from a numpy array. Actually
|
| 531 |
+
anything that exposes the __array_interface__ is accepted."""
|
| 532 |
+
ai = obj.__array_interface__
|
| 533 |
+
if ai["strides"]:
|
| 534 |
+
raise TypeError("strided arrays not supported")
|
| 535 |
+
if ai["version"] != 3:
|
| 536 |
+
raise TypeError("only __array_interface__ version 3 supported")
|
| 537 |
+
addr, readonly = ai["data"]
|
| 538 |
+
if readonly:
|
| 539 |
+
raise TypeError("readonly arrays unsupported")
|
| 540 |
+
|
| 541 |
+
# can't use `_dtype((ai["typestr"], ai["shape"]))` here, as it overflows
|
| 542 |
+
# dtype.itemsize (gh-14214)
|
| 543 |
+
ctype_scalar = as_ctypes_type(ai["typestr"])
|
| 544 |
+
result_type = _ctype_ndarray(ctype_scalar, ai["shape"])
|
| 545 |
+
result = result_type.from_address(addr)
|
| 546 |
+
result.__keep = obj
|
| 547 |
+
return result
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/ctypeslib.pyi
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NOTE: Numpy's mypy plugin is used for importing the correct
|
| 2 |
+
# platform-specific `ctypes._SimpleCData[int]` sub-type
|
| 3 |
+
from ctypes import c_int64 as _c_intp
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import ctypes
|
| 8 |
+
from collections.abc import Iterable, Sequence
|
| 9 |
+
from typing import (
|
| 10 |
+
Literal as L,
|
| 11 |
+
Any,
|
| 12 |
+
Union,
|
| 13 |
+
TypeVar,
|
| 14 |
+
Generic,
|
| 15 |
+
overload,
|
| 16 |
+
ClassVar,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
from numpy import (
|
| 20 |
+
ndarray,
|
| 21 |
+
dtype,
|
| 22 |
+
generic,
|
| 23 |
+
bool_,
|
| 24 |
+
byte,
|
| 25 |
+
short,
|
| 26 |
+
intc,
|
| 27 |
+
int_,
|
| 28 |
+
longlong,
|
| 29 |
+
ubyte,
|
| 30 |
+
ushort,
|
| 31 |
+
uintc,
|
| 32 |
+
uint,
|
| 33 |
+
ulonglong,
|
| 34 |
+
single,
|
| 35 |
+
double,
|
| 36 |
+
longdouble,
|
| 37 |
+
void,
|
| 38 |
+
)
|
| 39 |
+
from numpy.core._internal import _ctypes
|
| 40 |
+
from numpy.core.multiarray import flagsobj
|
| 41 |
+
from numpy._typing import (
|
| 42 |
+
# Arrays
|
| 43 |
+
NDArray,
|
| 44 |
+
_ArrayLike,
|
| 45 |
+
|
| 46 |
+
# Shapes
|
| 47 |
+
_ShapeLike,
|
| 48 |
+
|
| 49 |
+
# DTypes
|
| 50 |
+
DTypeLike,
|
| 51 |
+
_DTypeLike,
|
| 52 |
+
_VoidDTypeLike,
|
| 53 |
+
_BoolCodes,
|
| 54 |
+
_UByteCodes,
|
| 55 |
+
_UShortCodes,
|
| 56 |
+
_UIntCCodes,
|
| 57 |
+
_UIntCodes,
|
| 58 |
+
_ULongLongCodes,
|
| 59 |
+
_ByteCodes,
|
| 60 |
+
_ShortCodes,
|
| 61 |
+
_IntCCodes,
|
| 62 |
+
_IntCodes,
|
| 63 |
+
_LongLongCodes,
|
| 64 |
+
_SingleCodes,
|
| 65 |
+
_DoubleCodes,
|
| 66 |
+
_LongDoubleCodes,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# TODO: Add a proper `_Shape` bound once we've got variadic typevars
|
| 70 |
+
_DType = TypeVar("_DType", bound=dtype[Any])
|
| 71 |
+
_DTypeOptional = TypeVar("_DTypeOptional", bound=None | dtype[Any])
|
| 72 |
+
_SCT = TypeVar("_SCT", bound=generic)
|
| 73 |
+
|
| 74 |
+
_FlagsKind = L[
|
| 75 |
+
'C_CONTIGUOUS', 'CONTIGUOUS', 'C',
|
| 76 |
+
'F_CONTIGUOUS', 'FORTRAN', 'F',
|
| 77 |
+
'ALIGNED', 'A',
|
| 78 |
+
'WRITEABLE', 'W',
|
| 79 |
+
'OWNDATA', 'O',
|
| 80 |
+
'WRITEBACKIFCOPY', 'X',
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
# TODO: Add a shape typevar once we have variadic typevars (PEP 646)
|
| 84 |
+
class _ndptr(ctypes.c_void_p, Generic[_DTypeOptional]):
|
| 85 |
+
# In practice these 4 classvars are defined in the dynamic class
|
| 86 |
+
# returned by `ndpointer`
|
| 87 |
+
_dtype_: ClassVar[_DTypeOptional]
|
| 88 |
+
_shape_: ClassVar[None]
|
| 89 |
+
_ndim_: ClassVar[None | int]
|
| 90 |
+
_flags_: ClassVar[None | list[_FlagsKind]]
|
| 91 |
+
|
| 92 |
+
@overload
|
| 93 |
+
@classmethod
|
| 94 |
+
def from_param(cls: type[_ndptr[None]], obj: ndarray[Any, Any]) -> _ctypes: ...
|
| 95 |
+
@overload
|
| 96 |
+
@classmethod
|
| 97 |
+
def from_param(cls: type[_ndptr[_DType]], obj: ndarray[Any, _DType]) -> _ctypes: ...
|
| 98 |
+
|
| 99 |
+
class _concrete_ndptr(_ndptr[_DType]):
|
| 100 |
+
_dtype_: ClassVar[_DType]
|
| 101 |
+
_shape_: ClassVar[tuple[int, ...]]
|
| 102 |
+
@property
|
| 103 |
+
def contents(self) -> ndarray[Any, _DType]: ...
|
| 104 |
+
|
| 105 |
+
def load_library(
|
| 106 |
+
libname: str | bytes | os.PathLike[str] | os.PathLike[bytes],
|
| 107 |
+
loader_path: str | bytes | os.PathLike[str] | os.PathLike[bytes],
|
| 108 |
+
) -> ctypes.CDLL: ...
|
| 109 |
+
|
| 110 |
+
__all__: list[str]
|
| 111 |
+
|
| 112 |
+
c_intp = _c_intp
|
| 113 |
+
|
| 114 |
+
@overload
|
| 115 |
+
def ndpointer(
|
| 116 |
+
dtype: None = ...,
|
| 117 |
+
ndim: int = ...,
|
| 118 |
+
shape: None | _ShapeLike = ...,
|
| 119 |
+
flags: None | _FlagsKind | Iterable[_FlagsKind] | int | flagsobj = ...,
|
| 120 |
+
) -> type[_ndptr[None]]: ...
|
| 121 |
+
@overload
|
| 122 |
+
def ndpointer(
|
| 123 |
+
dtype: _DTypeLike[_SCT],
|
| 124 |
+
ndim: int = ...,
|
| 125 |
+
*,
|
| 126 |
+
shape: _ShapeLike,
|
| 127 |
+
flags: None | _FlagsKind | Iterable[_FlagsKind] | int | flagsobj = ...,
|
| 128 |
+
) -> type[_concrete_ndptr[dtype[_SCT]]]: ...
|
| 129 |
+
@overload
|
| 130 |
+
def ndpointer(
|
| 131 |
+
dtype: DTypeLike,
|
| 132 |
+
ndim: int = ...,
|
| 133 |
+
*,
|
| 134 |
+
shape: _ShapeLike,
|
| 135 |
+
flags: None | _FlagsKind | Iterable[_FlagsKind] | int | flagsobj = ...,
|
| 136 |
+
) -> type[_concrete_ndptr[dtype[Any]]]: ...
|
| 137 |
+
@overload
|
| 138 |
+
def ndpointer(
|
| 139 |
+
dtype: _DTypeLike[_SCT],
|
| 140 |
+
ndim: int = ...,
|
| 141 |
+
shape: None = ...,
|
| 142 |
+
flags: None | _FlagsKind | Iterable[_FlagsKind] | int | flagsobj = ...,
|
| 143 |
+
) -> type[_ndptr[dtype[_SCT]]]: ...
|
| 144 |
+
@overload
|
| 145 |
+
def ndpointer(
|
| 146 |
+
dtype: DTypeLike,
|
| 147 |
+
ndim: int = ...,
|
| 148 |
+
shape: None = ...,
|
| 149 |
+
flags: None | _FlagsKind | Iterable[_FlagsKind] | int | flagsobj = ...,
|
| 150 |
+
) -> type[_ndptr[dtype[Any]]]: ...
|
| 151 |
+
|
| 152 |
+
@overload
|
| 153 |
+
def as_ctypes_type(dtype: _BoolCodes | _DTypeLike[bool_] | type[ctypes.c_bool]) -> type[ctypes.c_bool]: ...
|
| 154 |
+
@overload
|
| 155 |
+
def as_ctypes_type(dtype: _ByteCodes | _DTypeLike[byte] | type[ctypes.c_byte]) -> type[ctypes.c_byte]: ...
|
| 156 |
+
@overload
|
| 157 |
+
def as_ctypes_type(dtype: _ShortCodes | _DTypeLike[short] | type[ctypes.c_short]) -> type[ctypes.c_short]: ...
|
| 158 |
+
@overload
|
| 159 |
+
def as_ctypes_type(dtype: _IntCCodes | _DTypeLike[intc] | type[ctypes.c_int]) -> type[ctypes.c_int]: ...
|
| 160 |
+
@overload
|
| 161 |
+
def as_ctypes_type(dtype: _IntCodes | _DTypeLike[int_] | type[int | ctypes.c_long]) -> type[ctypes.c_long]: ...
|
| 162 |
+
@overload
|
| 163 |
+
def as_ctypes_type(dtype: _LongLongCodes | _DTypeLike[longlong] | type[ctypes.c_longlong]) -> type[ctypes.c_longlong]: ...
|
| 164 |
+
@overload
|
| 165 |
+
def as_ctypes_type(dtype: _UByteCodes | _DTypeLike[ubyte] | type[ctypes.c_ubyte]) -> type[ctypes.c_ubyte]: ...
|
| 166 |
+
@overload
|
| 167 |
+
def as_ctypes_type(dtype: _UShortCodes | _DTypeLike[ushort] | type[ctypes.c_ushort]) -> type[ctypes.c_ushort]: ...
|
| 168 |
+
@overload
|
| 169 |
+
def as_ctypes_type(dtype: _UIntCCodes | _DTypeLike[uintc] | type[ctypes.c_uint]) -> type[ctypes.c_uint]: ...
|
| 170 |
+
@overload
|
| 171 |
+
def as_ctypes_type(dtype: _UIntCodes | _DTypeLike[uint] | type[ctypes.c_ulong]) -> type[ctypes.c_ulong]: ...
|
| 172 |
+
@overload
|
| 173 |
+
def as_ctypes_type(dtype: _ULongLongCodes | _DTypeLike[ulonglong] | type[ctypes.c_ulonglong]) -> type[ctypes.c_ulonglong]: ...
|
| 174 |
+
@overload
|
| 175 |
+
def as_ctypes_type(dtype: _SingleCodes | _DTypeLike[single] | type[ctypes.c_float]) -> type[ctypes.c_float]: ...
|
| 176 |
+
@overload
|
| 177 |
+
def as_ctypes_type(dtype: _DoubleCodes | _DTypeLike[double] | type[float | ctypes.c_double]) -> type[ctypes.c_double]: ...
|
| 178 |
+
@overload
|
| 179 |
+
def as_ctypes_type(dtype: _LongDoubleCodes | _DTypeLike[longdouble] | type[ctypes.c_longdouble]) -> type[ctypes.c_longdouble]: ...
|
| 180 |
+
@overload
|
| 181 |
+
def as_ctypes_type(dtype: _VoidDTypeLike) -> type[Any]: ... # `ctypes.Union` or `ctypes.Structure`
|
| 182 |
+
@overload
|
| 183 |
+
def as_ctypes_type(dtype: str) -> type[Any]: ...
|
| 184 |
+
|
| 185 |
+
@overload
|
| 186 |
+
def as_array(obj: ctypes._PointerLike, shape: Sequence[int]) -> NDArray[Any]: ...
|
| 187 |
+
@overload
|
| 188 |
+
def as_array(obj: _ArrayLike[_SCT], shape: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
|
| 189 |
+
@overload
|
| 190 |
+
def as_array(obj: object, shape: None | _ShapeLike = ...) -> NDArray[Any]: ...
|
| 191 |
+
|
| 192 |
+
@overload
|
| 193 |
+
def as_ctypes(obj: bool_) -> ctypes.c_bool: ...
|
| 194 |
+
@overload
|
| 195 |
+
def as_ctypes(obj: byte) -> ctypes.c_byte: ...
|
| 196 |
+
@overload
|
| 197 |
+
def as_ctypes(obj: short) -> ctypes.c_short: ...
|
| 198 |
+
@overload
|
| 199 |
+
def as_ctypes(obj: intc) -> ctypes.c_int: ...
|
| 200 |
+
@overload
|
| 201 |
+
def as_ctypes(obj: int_) -> ctypes.c_long: ...
|
| 202 |
+
@overload
|
| 203 |
+
def as_ctypes(obj: longlong) -> ctypes.c_longlong: ...
|
| 204 |
+
@overload
|
| 205 |
+
def as_ctypes(obj: ubyte) -> ctypes.c_ubyte: ...
|
| 206 |
+
@overload
|
| 207 |
+
def as_ctypes(obj: ushort) -> ctypes.c_ushort: ...
|
| 208 |
+
@overload
|
| 209 |
+
def as_ctypes(obj: uintc) -> ctypes.c_uint: ...
|
| 210 |
+
@overload
|
| 211 |
+
def as_ctypes(obj: uint) -> ctypes.c_ulong: ...
|
| 212 |
+
@overload
|
| 213 |
+
def as_ctypes(obj: ulonglong) -> ctypes.c_ulonglong: ...
|
| 214 |
+
@overload
|
| 215 |
+
def as_ctypes(obj: single) -> ctypes.c_float: ...
|
| 216 |
+
@overload
|
| 217 |
+
def as_ctypes(obj: double) -> ctypes.c_double: ...
|
| 218 |
+
@overload
|
| 219 |
+
def as_ctypes(obj: longdouble) -> ctypes.c_longdouble: ...
|
| 220 |
+
@overload
|
| 221 |
+
def as_ctypes(obj: void) -> Any: ... # `ctypes.Union` or `ctypes.Structure`
|
| 222 |
+
@overload
|
| 223 |
+
def as_ctypes(obj: NDArray[bool_]) -> ctypes.Array[ctypes.c_bool]: ...
|
| 224 |
+
@overload
|
| 225 |
+
def as_ctypes(obj: NDArray[byte]) -> ctypes.Array[ctypes.c_byte]: ...
|
| 226 |
+
@overload
|
| 227 |
+
def as_ctypes(obj: NDArray[short]) -> ctypes.Array[ctypes.c_short]: ...
|
| 228 |
+
@overload
|
| 229 |
+
def as_ctypes(obj: NDArray[intc]) -> ctypes.Array[ctypes.c_int]: ...
|
| 230 |
+
@overload
|
| 231 |
+
def as_ctypes(obj: NDArray[int_]) -> ctypes.Array[ctypes.c_long]: ...
|
| 232 |
+
@overload
|
| 233 |
+
def as_ctypes(obj: NDArray[longlong]) -> ctypes.Array[ctypes.c_longlong]: ...
|
| 234 |
+
@overload
|
| 235 |
+
def as_ctypes(obj: NDArray[ubyte]) -> ctypes.Array[ctypes.c_ubyte]: ...
|
| 236 |
+
@overload
|
| 237 |
+
def as_ctypes(obj: NDArray[ushort]) -> ctypes.Array[ctypes.c_ushort]: ...
|
| 238 |
+
@overload
|
| 239 |
+
def as_ctypes(obj: NDArray[uintc]) -> ctypes.Array[ctypes.c_uint]: ...
|
| 240 |
+
@overload
|
| 241 |
+
def as_ctypes(obj: NDArray[uint]) -> ctypes.Array[ctypes.c_ulong]: ...
|
| 242 |
+
@overload
|
| 243 |
+
def as_ctypes(obj: NDArray[ulonglong]) -> ctypes.Array[ctypes.c_ulonglong]: ...
|
| 244 |
+
@overload
|
| 245 |
+
def as_ctypes(obj: NDArray[single]) -> ctypes.Array[ctypes.c_float]: ...
|
| 246 |
+
@overload
|
| 247 |
+
def as_ctypes(obj: NDArray[double]) -> ctypes.Array[ctypes.c_double]: ...
|
| 248 |
+
@overload
|
| 249 |
+
def as_ctypes(obj: NDArray[longdouble]) -> ctypes.Array[ctypes.c_longdouble]: ...
|
| 250 |
+
@overload
|
| 251 |
+
def as_ctypes(obj: NDArray[void]) -> ctypes.Array[Any]: ... # `ctypes.Union` or `ctypes.Structure`
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/dual.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
.. deprecated:: 1.20
|
| 3 |
+
|
| 4 |
+
*This module is deprecated. Instead of importing functions from*
|
| 5 |
+
``numpy.dual``, *the functions should be imported directly from NumPy
|
| 6 |
+
or SciPy*.
|
| 7 |
+
|
| 8 |
+
Aliases for functions which may be accelerated by SciPy.
|
| 9 |
+
|
| 10 |
+
SciPy_ can be built to use accelerated or otherwise improved libraries
|
| 11 |
+
for FFTs, linear algebra, and special functions. This module allows
|
| 12 |
+
developers to transparently support these accelerated functions when
|
| 13 |
+
SciPy is available but still support users who have only installed
|
| 14 |
+
NumPy.
|
| 15 |
+
|
| 16 |
+
.. _SciPy : https://www.scipy.org
|
| 17 |
+
|
| 18 |
+
"""
|
| 19 |
+
import warnings
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
warnings.warn('The module numpy.dual is deprecated. Instead of using dual, '
|
| 23 |
+
'use the functions directly from numpy or scipy.',
|
| 24 |
+
category=DeprecationWarning,
|
| 25 |
+
stacklevel=2)
|
| 26 |
+
|
| 27 |
+
# This module should be used for functions both in numpy and scipy if
|
| 28 |
+
# you want to use the numpy version if available but the scipy version
|
| 29 |
+
# otherwise.
|
| 30 |
+
# Usage --- from numpy.dual import fft, inv
|
| 31 |
+
|
| 32 |
+
__all__ = ['fft', 'ifft', 'fftn', 'ifftn', 'fft2', 'ifft2',
|
| 33 |
+
'norm', 'inv', 'svd', 'solve', 'det', 'eig', 'eigvals',
|
| 34 |
+
'eigh', 'eigvalsh', 'lstsq', 'pinv', 'cholesky', 'i0']
|
| 35 |
+
|
| 36 |
+
import numpy.linalg as linpkg
|
| 37 |
+
import numpy.fft as fftpkg
|
| 38 |
+
from numpy.lib import i0
|
| 39 |
+
import sys
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
fft = fftpkg.fft
|
| 43 |
+
ifft = fftpkg.ifft
|
| 44 |
+
fftn = fftpkg.fftn
|
| 45 |
+
ifftn = fftpkg.ifftn
|
| 46 |
+
fft2 = fftpkg.fft2
|
| 47 |
+
ifft2 = fftpkg.ifft2
|
| 48 |
+
|
| 49 |
+
norm = linpkg.norm
|
| 50 |
+
inv = linpkg.inv
|
| 51 |
+
svd = linpkg.svd
|
| 52 |
+
solve = linpkg.solve
|
| 53 |
+
det = linpkg.det
|
| 54 |
+
eig = linpkg.eig
|
| 55 |
+
eigvals = linpkg.eigvals
|
| 56 |
+
eigh = linpkg.eigh
|
| 57 |
+
eigvalsh = linpkg.eigvalsh
|
| 58 |
+
lstsq = linpkg.lstsq
|
| 59 |
+
pinv = linpkg.pinv
|
| 60 |
+
cholesky = linpkg.cholesky
|
| 61 |
+
|
| 62 |
+
_restore_dict = {}
|
| 63 |
+
|
| 64 |
+
def register_func(name, func):
|
| 65 |
+
if name not in __all__:
|
| 66 |
+
raise ValueError("{} not a dual function.".format(name))
|
| 67 |
+
f = sys._getframe(0).f_globals
|
| 68 |
+
_restore_dict[name] = f[name]
|
| 69 |
+
f[name] = func
|
| 70 |
+
|
| 71 |
+
def restore_func(name):
|
| 72 |
+
if name not in __all__:
|
| 73 |
+
raise ValueError("{} not a dual function.".format(name))
|
| 74 |
+
try:
|
| 75 |
+
val = _restore_dict[name]
|
| 76 |
+
except KeyError:
|
| 77 |
+
return
|
| 78 |
+
else:
|
| 79 |
+
sys._getframe(0).f_globals[name] = val
|
| 80 |
+
|
| 81 |
+
def restore_all():
|
| 82 |
+
for name in _restore_dict.keys():
|
| 83 |
+
restore_func(name)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__init__.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fortran to Python Interface Generator.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
__all__ = ['run_main', 'compile', 'get_include']
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import subprocess
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
from . import f2py2e
|
| 12 |
+
from . import diagnose
|
| 13 |
+
|
| 14 |
+
run_main = f2py2e.run_main
|
| 15 |
+
main = f2py2e.main
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def compile(source,
|
| 19 |
+
modulename='untitled',
|
| 20 |
+
extra_args='',
|
| 21 |
+
verbose=True,
|
| 22 |
+
source_fn=None,
|
| 23 |
+
extension='.f',
|
| 24 |
+
full_output=False
|
| 25 |
+
):
|
| 26 |
+
"""
|
| 27 |
+
Build extension module from a Fortran 77 source string with f2py.
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
source : str or bytes
|
| 32 |
+
Fortran source of module / subroutine to compile
|
| 33 |
+
|
| 34 |
+
.. versionchanged:: 1.16.0
|
| 35 |
+
Accept str as well as bytes
|
| 36 |
+
|
| 37 |
+
modulename : str, optional
|
| 38 |
+
The name of the compiled python module
|
| 39 |
+
extra_args : str or list, optional
|
| 40 |
+
Additional parameters passed to f2py
|
| 41 |
+
|
| 42 |
+
.. versionchanged:: 1.16.0
|
| 43 |
+
A list of args may also be provided.
|
| 44 |
+
|
| 45 |
+
verbose : bool, optional
|
| 46 |
+
Print f2py output to screen
|
| 47 |
+
source_fn : str, optional
|
| 48 |
+
Name of the file where the fortran source is written.
|
| 49 |
+
The default is to use a temporary file with the extension
|
| 50 |
+
provided by the ``extension`` parameter
|
| 51 |
+
extension : ``{'.f', '.f90'}``, optional
|
| 52 |
+
Filename extension if `source_fn` is not provided.
|
| 53 |
+
The extension tells which fortran standard is used.
|
| 54 |
+
The default is ``.f``, which implies F77 standard.
|
| 55 |
+
|
| 56 |
+
.. versionadded:: 1.11.0
|
| 57 |
+
|
| 58 |
+
full_output : bool, optional
|
| 59 |
+
If True, return a `subprocess.CompletedProcess` containing
|
| 60 |
+
the stdout and stderr of the compile process, instead of just
|
| 61 |
+
the status code.
|
| 62 |
+
|
| 63 |
+
.. versionadded:: 1.20.0
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Returns
|
| 67 |
+
-------
|
| 68 |
+
result : int or `subprocess.CompletedProcess`
|
| 69 |
+
0 on success, or a `subprocess.CompletedProcess` if
|
| 70 |
+
``full_output=True``
|
| 71 |
+
|
| 72 |
+
Examples
|
| 73 |
+
--------
|
| 74 |
+
.. literalinclude:: ../../source/f2py/code/results/compile_session.dat
|
| 75 |
+
:language: python
|
| 76 |
+
|
| 77 |
+
"""
|
| 78 |
+
import tempfile
|
| 79 |
+
import shlex
|
| 80 |
+
|
| 81 |
+
if source_fn is None:
|
| 82 |
+
f, fname = tempfile.mkstemp(suffix=extension)
|
| 83 |
+
# f is a file descriptor so need to close it
|
| 84 |
+
# carefully -- not with .close() directly
|
| 85 |
+
os.close(f)
|
| 86 |
+
else:
|
| 87 |
+
fname = source_fn
|
| 88 |
+
|
| 89 |
+
if not isinstance(source, str):
|
| 90 |
+
source = str(source, 'utf-8')
|
| 91 |
+
try:
|
| 92 |
+
with open(fname, 'w') as f:
|
| 93 |
+
f.write(source)
|
| 94 |
+
|
| 95 |
+
args = ['-c', '-m', modulename, f.name]
|
| 96 |
+
|
| 97 |
+
if isinstance(extra_args, str):
|
| 98 |
+
is_posix = (os.name == 'posix')
|
| 99 |
+
extra_args = shlex.split(extra_args, posix=is_posix)
|
| 100 |
+
|
| 101 |
+
args.extend(extra_args)
|
| 102 |
+
|
| 103 |
+
c = [sys.executable,
|
| 104 |
+
'-c',
|
| 105 |
+
'import numpy.f2py as f2py2e;f2py2e.main()'] + args
|
| 106 |
+
try:
|
| 107 |
+
cp = subprocess.run(c, capture_output=True)
|
| 108 |
+
except OSError:
|
| 109 |
+
# preserve historic status code used by exec_command()
|
| 110 |
+
cp = subprocess.CompletedProcess(c, 127, stdout=b'', stderr=b'')
|
| 111 |
+
else:
|
| 112 |
+
if verbose:
|
| 113 |
+
print(cp.stdout.decode())
|
| 114 |
+
finally:
|
| 115 |
+
if source_fn is None:
|
| 116 |
+
os.remove(fname)
|
| 117 |
+
|
| 118 |
+
if full_output:
|
| 119 |
+
return cp
|
| 120 |
+
else:
|
| 121 |
+
return cp.returncode
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def get_include():
|
| 125 |
+
"""
|
| 126 |
+
Return the directory that contains the ``fortranobject.c`` and ``.h`` files.
|
| 127 |
+
|
| 128 |
+
.. note::
|
| 129 |
+
|
| 130 |
+
This function is not needed when building an extension with
|
| 131 |
+
`numpy.distutils` directly from ``.f`` and/or ``.pyf`` files
|
| 132 |
+
in one go.
|
| 133 |
+
|
| 134 |
+
Python extension modules built with f2py-generated code need to use
|
| 135 |
+
``fortranobject.c`` as a source file, and include the ``fortranobject.h``
|
| 136 |
+
header. This function can be used to obtain the directory containing
|
| 137 |
+
both of these files.
|
| 138 |
+
|
| 139 |
+
Returns
|
| 140 |
+
-------
|
| 141 |
+
include_path : str
|
| 142 |
+
Absolute path to the directory containing ``fortranobject.c`` and
|
| 143 |
+
``fortranobject.h``.
|
| 144 |
+
|
| 145 |
+
Notes
|
| 146 |
+
-----
|
| 147 |
+
.. versionadded:: 1.21.1
|
| 148 |
+
|
| 149 |
+
Unless the build system you are using has specific support for f2py,
|
| 150 |
+
building a Python extension using a ``.pyf`` signature file is a two-step
|
| 151 |
+
process. For a module ``mymod``:
|
| 152 |
+
|
| 153 |
+
* Step 1: run ``python -m numpy.f2py mymod.pyf --quiet``. This
|
| 154 |
+
generates ``_mymodmodule.c`` and (if needed)
|
| 155 |
+
``_fblas-f2pywrappers.f`` files next to ``mymod.pyf``.
|
| 156 |
+
* Step 2: build your Python extension module. This requires the
|
| 157 |
+
following source files:
|
| 158 |
+
|
| 159 |
+
* ``_mymodmodule.c``
|
| 160 |
+
* ``_mymod-f2pywrappers.f`` (if it was generated in Step 1)
|
| 161 |
+
* ``fortranobject.c``
|
| 162 |
+
|
| 163 |
+
See Also
|
| 164 |
+
--------
|
| 165 |
+
numpy.get_include : function that returns the numpy include directory
|
| 166 |
+
|
| 167 |
+
"""
|
| 168 |
+
return os.path.join(os.path.dirname(__file__), 'src')
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def __getattr__(attr):
|
| 172 |
+
|
| 173 |
+
# Avoid importing things that aren't needed for building
|
| 174 |
+
# which might import the main numpy module
|
| 175 |
+
if attr == "test":
|
| 176 |
+
from numpy._pytesttester import PytestTester
|
| 177 |
+
test = PytestTester(__name__)
|
| 178 |
+
return test
|
| 179 |
+
|
| 180 |
+
else:
|
| 181 |
+
raise AttributeError("module {!r} has no attribute "
|
| 182 |
+
"{!r}".format(__name__, attr))
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def __dir__():
|
| 186 |
+
return list(globals().keys() | {"test"})
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__init__.pyi
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
from collections.abc import Iterable
|
| 4 |
+
from typing import Literal as L, Any, overload, TypedDict
|
| 5 |
+
|
| 6 |
+
from numpy._pytesttester import PytestTester
|
| 7 |
+
|
| 8 |
+
class _F2PyDictBase(TypedDict):
|
| 9 |
+
csrc: list[str]
|
| 10 |
+
h: list[str]
|
| 11 |
+
|
| 12 |
+
class _F2PyDict(_F2PyDictBase, total=False):
|
| 13 |
+
fsrc: list[str]
|
| 14 |
+
ltx: list[str]
|
| 15 |
+
|
| 16 |
+
__all__: list[str]
|
| 17 |
+
__path__: list[str]
|
| 18 |
+
test: PytestTester
|
| 19 |
+
|
| 20 |
+
def run_main(comline_list: Iterable[str]) -> dict[str, _F2PyDict]: ...
|
| 21 |
+
|
| 22 |
+
@overload
|
| 23 |
+
def compile( # type: ignore[misc]
|
| 24 |
+
source: str | bytes,
|
| 25 |
+
modulename: str = ...,
|
| 26 |
+
extra_args: str | list[str] = ...,
|
| 27 |
+
verbose: bool = ...,
|
| 28 |
+
source_fn: None | str | bytes | os.PathLike[Any] = ...,
|
| 29 |
+
extension: L[".f", ".f90"] = ...,
|
| 30 |
+
full_output: L[False] = ...,
|
| 31 |
+
) -> int: ...
|
| 32 |
+
@overload
|
| 33 |
+
def compile(
|
| 34 |
+
source: str | bytes,
|
| 35 |
+
modulename: str = ...,
|
| 36 |
+
extra_args: str | list[str] = ...,
|
| 37 |
+
verbose: bool = ...,
|
| 38 |
+
source_fn: None | str | bytes | os.PathLike[Any] = ...,
|
| 39 |
+
extension: L[".f", ".f90"] = ...,
|
| 40 |
+
full_output: L[True] = ...,
|
| 41 |
+
) -> subprocess.CompletedProcess[bytes]: ...
|
| 42 |
+
|
| 43 |
+
def get_include() -> str: ...
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__main__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See:
|
| 2 |
+
# https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e
|
| 3 |
+
from numpy.f2py.f2py2e import main
|
| 4 |
+
|
| 5 |
+
main()
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/__version__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from numpy.version import version
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/auxfuncs.py
ADDED
|
@@ -0,0 +1,890 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Auxiliary functions for f2py2e.
|
| 5 |
+
|
| 6 |
+
Copyright 1999,2000 Pearu Peterson all rights reserved,
|
| 7 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 8 |
+
Permission to use, modify, and distribute this software is given under the
|
| 9 |
+
terms of the NumPy (BSD style) LICENSE.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 13 |
+
$Date: 2005/07/24 19:01:55 $
|
| 14 |
+
Pearu Peterson
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
import pprint
|
| 18 |
+
import sys
|
| 19 |
+
import types
|
| 20 |
+
from functools import reduce
|
| 21 |
+
|
| 22 |
+
from . import __version__
|
| 23 |
+
from . import cfuncs
|
| 24 |
+
|
| 25 |
+
__all__ = [
|
| 26 |
+
'applyrules', 'debugcapi', 'dictappend', 'errmess', 'gentitle',
|
| 27 |
+
'getargs2', 'getcallprotoargument', 'getcallstatement',
|
| 28 |
+
'getfortranname', 'getpymethoddef', 'getrestdoc', 'getusercode',
|
| 29 |
+
'getusercode1', 'hasbody', 'hascallstatement', 'hascommon',
|
| 30 |
+
'hasexternals', 'hasinitvalue', 'hasnote', 'hasresultnote',
|
| 31 |
+
'isallocatable', 'isarray', 'isarrayofstrings',
|
| 32 |
+
'ischaracter', 'ischaracterarray', 'ischaracter_or_characterarray',
|
| 33 |
+
'iscomplex',
|
| 34 |
+
'iscomplexarray', 'iscomplexfunction', 'iscomplexfunction_warn',
|
| 35 |
+
'isdouble', 'isdummyroutine', 'isexternal', 'isfunction',
|
| 36 |
+
'isfunction_wrap', 'isint1', 'isint1array', 'isinteger', 'isintent_aux',
|
| 37 |
+
'isintent_c', 'isintent_callback', 'isintent_copy', 'isintent_dict',
|
| 38 |
+
'isintent_hide', 'isintent_in', 'isintent_inout', 'isintent_inplace',
|
| 39 |
+
'isintent_nothide', 'isintent_out', 'isintent_overwrite', 'islogical',
|
| 40 |
+
'islogicalfunction', 'islong_complex', 'islong_double',
|
| 41 |
+
'islong_doublefunction', 'islong_long', 'islong_longfunction',
|
| 42 |
+
'ismodule', 'ismoduleroutine', 'isoptional', 'isprivate', 'isrequired',
|
| 43 |
+
'isroutine', 'isscalar', 'issigned_long_longarray', 'isstring',
|
| 44 |
+
'isstringarray', 'isstring_or_stringarray', 'isstringfunction',
|
| 45 |
+
'issubroutine',
|
| 46 |
+
'issubroutine_wrap', 'isthreadsafe', 'isunsigned', 'isunsigned_char',
|
| 47 |
+
'isunsigned_chararray', 'isunsigned_long_long',
|
| 48 |
+
'isunsigned_long_longarray', 'isunsigned_short',
|
| 49 |
+
'isunsigned_shortarray', 'l_and', 'l_not', 'l_or', 'outmess',
|
| 50 |
+
'replace', 'show', 'stripcomma', 'throw_error', 'isattr_value'
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
f2py_version = __version__.version
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
errmess = sys.stderr.write
|
| 58 |
+
show = pprint.pprint
|
| 59 |
+
|
| 60 |
+
options = {}
|
| 61 |
+
debugoptions = []
|
| 62 |
+
wrapfuncs = 1
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def outmess(t):
|
| 66 |
+
if options.get('verbose', 1):
|
| 67 |
+
sys.stdout.write(t)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def debugcapi(var):
|
| 71 |
+
return 'capi' in debugoptions
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _ischaracter(var):
|
| 75 |
+
return 'typespec' in var and var['typespec'] == 'character' and \
|
| 76 |
+
not isexternal(var)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _isstring(var):
|
| 80 |
+
return 'typespec' in var and var['typespec'] == 'character' and \
|
| 81 |
+
not isexternal(var)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def ischaracter_or_characterarray(var):
|
| 85 |
+
return _ischaracter(var) and 'charselector' not in var
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def ischaracter(var):
|
| 89 |
+
return ischaracter_or_characterarray(var) and not isarray(var)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def ischaracterarray(var):
|
| 93 |
+
return ischaracter_or_characterarray(var) and isarray(var)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def isstring_or_stringarray(var):
|
| 97 |
+
return _ischaracter(var) and 'charselector' in var
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def isstring(var):
|
| 101 |
+
return isstring_or_stringarray(var) and not isarray(var)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def isstringarray(var):
|
| 105 |
+
return isstring_or_stringarray(var) and isarray(var)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def isarrayofstrings(var): # obsolete?
|
| 109 |
+
# leaving out '*' for now so that `character*(*) a(m)` and `character
|
| 110 |
+
# a(m,*)` are treated differently. Luckily `character**` is illegal.
|
| 111 |
+
return isstringarray(var) and var['dimension'][-1] == '(*)'
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def isarray(var):
|
| 115 |
+
return 'dimension' in var and not isexternal(var)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def isscalar(var):
|
| 119 |
+
return not (isarray(var) or isstring(var) or isexternal(var))
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def iscomplex(var):
|
| 123 |
+
return isscalar(var) and \
|
| 124 |
+
var.get('typespec') in ['complex', 'double complex']
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def islogical(var):
|
| 128 |
+
return isscalar(var) and var.get('typespec') == 'logical'
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def isinteger(var):
|
| 132 |
+
return isscalar(var) and var.get('typespec') == 'integer'
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def isreal(var):
|
| 136 |
+
return isscalar(var) and var.get('typespec') == 'real'
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def get_kind(var):
|
| 140 |
+
try:
|
| 141 |
+
return var['kindselector']['*']
|
| 142 |
+
except KeyError:
|
| 143 |
+
try:
|
| 144 |
+
return var['kindselector']['kind']
|
| 145 |
+
except KeyError:
|
| 146 |
+
pass
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def isint1(var):
|
| 150 |
+
return var.get('typespec') == 'integer' \
|
| 151 |
+
and get_kind(var) == '1' and not isarray(var)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def islong_long(var):
|
| 155 |
+
if not isscalar(var):
|
| 156 |
+
return 0
|
| 157 |
+
if var.get('typespec') not in ['integer', 'logical']:
|
| 158 |
+
return 0
|
| 159 |
+
return get_kind(var) == '8'
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def isunsigned_char(var):
|
| 163 |
+
if not isscalar(var):
|
| 164 |
+
return 0
|
| 165 |
+
if var.get('typespec') != 'integer':
|
| 166 |
+
return 0
|
| 167 |
+
return get_kind(var) == '-1'
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def isunsigned_short(var):
|
| 171 |
+
if not isscalar(var):
|
| 172 |
+
return 0
|
| 173 |
+
if var.get('typespec') != 'integer':
|
| 174 |
+
return 0
|
| 175 |
+
return get_kind(var) == '-2'
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def isunsigned(var):
|
| 179 |
+
if not isscalar(var):
|
| 180 |
+
return 0
|
| 181 |
+
if var.get('typespec') != 'integer':
|
| 182 |
+
return 0
|
| 183 |
+
return get_kind(var) == '-4'
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def isunsigned_long_long(var):
|
| 187 |
+
if not isscalar(var):
|
| 188 |
+
return 0
|
| 189 |
+
if var.get('typespec') != 'integer':
|
| 190 |
+
return 0
|
| 191 |
+
return get_kind(var) == '-8'
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def isdouble(var):
|
| 195 |
+
if not isscalar(var):
|
| 196 |
+
return 0
|
| 197 |
+
if not var.get('typespec') == 'real':
|
| 198 |
+
return 0
|
| 199 |
+
return get_kind(var) == '8'
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def islong_double(var):
|
| 203 |
+
if not isscalar(var):
|
| 204 |
+
return 0
|
| 205 |
+
if not var.get('typespec') == 'real':
|
| 206 |
+
return 0
|
| 207 |
+
return get_kind(var) == '16'
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def islong_complex(var):
|
| 211 |
+
if not iscomplex(var):
|
| 212 |
+
return 0
|
| 213 |
+
return get_kind(var) == '32'
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def iscomplexarray(var):
|
| 217 |
+
return isarray(var) and \
|
| 218 |
+
var.get('typespec') in ['complex', 'double complex']
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def isint1array(var):
|
| 222 |
+
return isarray(var) and var.get('typespec') == 'integer' \
|
| 223 |
+
and get_kind(var) == '1'
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def isunsigned_chararray(var):
|
| 227 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 228 |
+
and get_kind(var) == '-1'
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def isunsigned_shortarray(var):
|
| 232 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 233 |
+
and get_kind(var) == '-2'
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def isunsignedarray(var):
|
| 237 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 238 |
+
and get_kind(var) == '-4'
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def isunsigned_long_longarray(var):
|
| 242 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 243 |
+
and get_kind(var) == '-8'
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def issigned_chararray(var):
|
| 247 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 248 |
+
and get_kind(var) == '1'
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def issigned_shortarray(var):
|
| 252 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 253 |
+
and get_kind(var) == '2'
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def issigned_array(var):
|
| 257 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 258 |
+
and get_kind(var) == '4'
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def issigned_long_longarray(var):
|
| 262 |
+
return isarray(var) and var.get('typespec') in ['integer', 'logical']\
|
| 263 |
+
and get_kind(var) == '8'
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def isallocatable(var):
|
| 267 |
+
return 'attrspec' in var and 'allocatable' in var['attrspec']
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def ismutable(var):
|
| 271 |
+
return not ('dimension' not in var or isstring(var))
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def ismoduleroutine(rout):
|
| 275 |
+
return 'modulename' in rout
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def ismodule(rout):
|
| 279 |
+
return 'block' in rout and 'module' == rout['block']
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def isfunction(rout):
|
| 283 |
+
return 'block' in rout and 'function' == rout['block']
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def isfunction_wrap(rout):
|
| 287 |
+
if isintent_c(rout):
|
| 288 |
+
return 0
|
| 289 |
+
return wrapfuncs and isfunction(rout) and (not isexternal(rout))
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def issubroutine(rout):
|
| 293 |
+
return 'block' in rout and 'subroutine' == rout['block']
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def issubroutine_wrap(rout):
|
| 297 |
+
if isintent_c(rout):
|
| 298 |
+
return 0
|
| 299 |
+
return issubroutine(rout) and hasassumedshape(rout)
|
| 300 |
+
|
| 301 |
+
def isattr_value(var):
|
| 302 |
+
return 'value' in var.get('attrspec', [])
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def hasassumedshape(rout):
|
| 306 |
+
if rout.get('hasassumedshape'):
|
| 307 |
+
return True
|
| 308 |
+
for a in rout['args']:
|
| 309 |
+
for d in rout['vars'].get(a, {}).get('dimension', []):
|
| 310 |
+
if d == ':':
|
| 311 |
+
rout['hasassumedshape'] = True
|
| 312 |
+
return True
|
| 313 |
+
return False
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def requiresf90wrapper(rout):
|
| 317 |
+
return ismoduleroutine(rout) or hasassumedshape(rout)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def isroutine(rout):
|
| 321 |
+
return isfunction(rout) or issubroutine(rout)
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def islogicalfunction(rout):
|
| 325 |
+
if not isfunction(rout):
|
| 326 |
+
return 0
|
| 327 |
+
if 'result' in rout:
|
| 328 |
+
a = rout['result']
|
| 329 |
+
else:
|
| 330 |
+
a = rout['name']
|
| 331 |
+
if a in rout['vars']:
|
| 332 |
+
return islogical(rout['vars'][a])
|
| 333 |
+
return 0
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def islong_longfunction(rout):
|
| 337 |
+
if not isfunction(rout):
|
| 338 |
+
return 0
|
| 339 |
+
if 'result' in rout:
|
| 340 |
+
a = rout['result']
|
| 341 |
+
else:
|
| 342 |
+
a = rout['name']
|
| 343 |
+
if a in rout['vars']:
|
| 344 |
+
return islong_long(rout['vars'][a])
|
| 345 |
+
return 0
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def islong_doublefunction(rout):
|
| 349 |
+
if not isfunction(rout):
|
| 350 |
+
return 0
|
| 351 |
+
if 'result' in rout:
|
| 352 |
+
a = rout['result']
|
| 353 |
+
else:
|
| 354 |
+
a = rout['name']
|
| 355 |
+
if a in rout['vars']:
|
| 356 |
+
return islong_double(rout['vars'][a])
|
| 357 |
+
return 0
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
def iscomplexfunction(rout):
|
| 361 |
+
if not isfunction(rout):
|
| 362 |
+
return 0
|
| 363 |
+
if 'result' in rout:
|
| 364 |
+
a = rout['result']
|
| 365 |
+
else:
|
| 366 |
+
a = rout['name']
|
| 367 |
+
if a in rout['vars']:
|
| 368 |
+
return iscomplex(rout['vars'][a])
|
| 369 |
+
return 0
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def iscomplexfunction_warn(rout):
|
| 373 |
+
if iscomplexfunction(rout):
|
| 374 |
+
outmess("""\
|
| 375 |
+
**************************************************************
|
| 376 |
+
Warning: code with a function returning complex value
|
| 377 |
+
may not work correctly with your Fortran compiler.
|
| 378 |
+
When using GNU gcc/g77 compilers, codes should work
|
| 379 |
+
correctly for callbacks with:
|
| 380 |
+
f2py -c -DF2PY_CB_RETURNCOMPLEX
|
| 381 |
+
**************************************************************\n""")
|
| 382 |
+
return 1
|
| 383 |
+
return 0
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def isstringfunction(rout):
|
| 387 |
+
if not isfunction(rout):
|
| 388 |
+
return 0
|
| 389 |
+
if 'result' in rout:
|
| 390 |
+
a = rout['result']
|
| 391 |
+
else:
|
| 392 |
+
a = rout['name']
|
| 393 |
+
if a in rout['vars']:
|
| 394 |
+
return isstring(rout['vars'][a])
|
| 395 |
+
return 0
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def hasexternals(rout):
|
| 399 |
+
return 'externals' in rout and rout['externals']
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
def isthreadsafe(rout):
|
| 403 |
+
return 'f2pyenhancements' in rout and \
|
| 404 |
+
'threadsafe' in rout['f2pyenhancements']
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
def hasvariables(rout):
|
| 408 |
+
return 'vars' in rout and rout['vars']
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def isoptional(var):
|
| 412 |
+
return ('attrspec' in var and 'optional' in var['attrspec'] and
|
| 413 |
+
'required' not in var['attrspec']) and isintent_nothide(var)
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def isexternal(var):
|
| 417 |
+
return 'attrspec' in var and 'external' in var['attrspec']
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
def isrequired(var):
|
| 421 |
+
return not isoptional(var) and isintent_nothide(var)
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def isintent_in(var):
|
| 425 |
+
if 'intent' not in var:
|
| 426 |
+
return 1
|
| 427 |
+
if 'hide' in var['intent']:
|
| 428 |
+
return 0
|
| 429 |
+
if 'inplace' in var['intent']:
|
| 430 |
+
return 0
|
| 431 |
+
if 'in' in var['intent']:
|
| 432 |
+
return 1
|
| 433 |
+
if 'out' in var['intent']:
|
| 434 |
+
return 0
|
| 435 |
+
if 'inout' in var['intent']:
|
| 436 |
+
return 0
|
| 437 |
+
if 'outin' in var['intent']:
|
| 438 |
+
return 0
|
| 439 |
+
return 1
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def isintent_inout(var):
|
| 443 |
+
return ('intent' in var and ('inout' in var['intent'] or
|
| 444 |
+
'outin' in var['intent']) and 'in' not in var['intent'] and
|
| 445 |
+
'hide' not in var['intent'] and 'inplace' not in var['intent'])
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
def isintent_out(var):
|
| 449 |
+
return 'out' in var.get('intent', [])
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def isintent_hide(var):
|
| 453 |
+
return ('intent' in var and ('hide' in var['intent'] or
|
| 454 |
+
('out' in var['intent'] and 'in' not in var['intent'] and
|
| 455 |
+
(not l_or(isintent_inout, isintent_inplace)(var)))))
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def isintent_nothide(var):
|
| 459 |
+
return not isintent_hide(var)
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
def isintent_c(var):
|
| 463 |
+
return 'c' in var.get('intent', [])
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
def isintent_cache(var):
|
| 467 |
+
return 'cache' in var.get('intent', [])
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
def isintent_copy(var):
|
| 471 |
+
return 'copy' in var.get('intent', [])
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
def isintent_overwrite(var):
|
| 475 |
+
return 'overwrite' in var.get('intent', [])
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def isintent_callback(var):
|
| 479 |
+
return 'callback' in var.get('intent', [])
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
def isintent_inplace(var):
|
| 483 |
+
return 'inplace' in var.get('intent', [])
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
def isintent_aux(var):
|
| 487 |
+
return 'aux' in var.get('intent', [])
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def isintent_aligned4(var):
|
| 491 |
+
return 'aligned4' in var.get('intent', [])
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def isintent_aligned8(var):
|
| 495 |
+
return 'aligned8' in var.get('intent', [])
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
def isintent_aligned16(var):
|
| 499 |
+
return 'aligned16' in var.get('intent', [])
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
isintent_dict = {isintent_in: 'INTENT_IN', isintent_inout: 'INTENT_INOUT',
|
| 503 |
+
isintent_out: 'INTENT_OUT', isintent_hide: 'INTENT_HIDE',
|
| 504 |
+
isintent_cache: 'INTENT_CACHE',
|
| 505 |
+
isintent_c: 'INTENT_C', isoptional: 'OPTIONAL',
|
| 506 |
+
isintent_inplace: 'INTENT_INPLACE',
|
| 507 |
+
isintent_aligned4: 'INTENT_ALIGNED4',
|
| 508 |
+
isintent_aligned8: 'INTENT_ALIGNED8',
|
| 509 |
+
isintent_aligned16: 'INTENT_ALIGNED16',
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def isprivate(var):
|
| 514 |
+
return 'attrspec' in var and 'private' in var['attrspec']
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
def hasinitvalue(var):
|
| 518 |
+
return '=' in var
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
def hasinitvalueasstring(var):
|
| 522 |
+
if not hasinitvalue(var):
|
| 523 |
+
return 0
|
| 524 |
+
return var['='][0] in ['"', "'"]
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
def hasnote(var):
|
| 528 |
+
return 'note' in var
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
def hasresultnote(rout):
|
| 532 |
+
if not isfunction(rout):
|
| 533 |
+
return 0
|
| 534 |
+
if 'result' in rout:
|
| 535 |
+
a = rout['result']
|
| 536 |
+
else:
|
| 537 |
+
a = rout['name']
|
| 538 |
+
if a in rout['vars']:
|
| 539 |
+
return hasnote(rout['vars'][a])
|
| 540 |
+
return 0
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def hascommon(rout):
|
| 544 |
+
return 'common' in rout
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
def containscommon(rout):
|
| 548 |
+
if hascommon(rout):
|
| 549 |
+
return 1
|
| 550 |
+
if hasbody(rout):
|
| 551 |
+
for b in rout['body']:
|
| 552 |
+
if containscommon(b):
|
| 553 |
+
return 1
|
| 554 |
+
return 0
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
def containsmodule(block):
|
| 558 |
+
if ismodule(block):
|
| 559 |
+
return 1
|
| 560 |
+
if not hasbody(block):
|
| 561 |
+
return 0
|
| 562 |
+
for b in block['body']:
|
| 563 |
+
if containsmodule(b):
|
| 564 |
+
return 1
|
| 565 |
+
return 0
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def hasbody(rout):
|
| 569 |
+
return 'body' in rout
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
def hascallstatement(rout):
|
| 573 |
+
return getcallstatement(rout) is not None
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
def istrue(var):
|
| 577 |
+
return 1
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
def isfalse(var):
|
| 581 |
+
return 0
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
class F2PYError(Exception):
|
| 585 |
+
pass
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
class throw_error:
|
| 589 |
+
|
| 590 |
+
def __init__(self, mess):
|
| 591 |
+
self.mess = mess
|
| 592 |
+
|
| 593 |
+
def __call__(self, var):
|
| 594 |
+
mess = '\n\n var = %s\n Message: %s\n' % (var, self.mess)
|
| 595 |
+
raise F2PYError(mess)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def l_and(*f):
|
| 599 |
+
l1, l2 = 'lambda v', []
|
| 600 |
+
for i in range(len(f)):
|
| 601 |
+
l1 = '%s,f%d=f[%d]' % (l1, i, i)
|
| 602 |
+
l2.append('f%d(v)' % (i))
|
| 603 |
+
return eval('%s:%s' % (l1, ' and '.join(l2)))
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
def l_or(*f):
|
| 607 |
+
l1, l2 = 'lambda v', []
|
| 608 |
+
for i in range(len(f)):
|
| 609 |
+
l1 = '%s,f%d=f[%d]' % (l1, i, i)
|
| 610 |
+
l2.append('f%d(v)' % (i))
|
| 611 |
+
return eval('%s:%s' % (l1, ' or '.join(l2)))
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
def l_not(f):
|
| 615 |
+
return eval('lambda v,f=f:not f(v)')
|
| 616 |
+
|
| 617 |
+
|
| 618 |
+
def isdummyroutine(rout):
|
| 619 |
+
try:
|
| 620 |
+
return rout['f2pyenhancements']['fortranname'] == ''
|
| 621 |
+
except KeyError:
|
| 622 |
+
return 0
|
| 623 |
+
|
| 624 |
+
|
| 625 |
+
def getfortranname(rout):
|
| 626 |
+
try:
|
| 627 |
+
name = rout['f2pyenhancements']['fortranname']
|
| 628 |
+
if name == '':
|
| 629 |
+
raise KeyError
|
| 630 |
+
if not name:
|
| 631 |
+
errmess('Failed to use fortranname from %s\n' %
|
| 632 |
+
(rout['f2pyenhancements']))
|
| 633 |
+
raise KeyError
|
| 634 |
+
except KeyError:
|
| 635 |
+
name = rout['name']
|
| 636 |
+
return name
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
def getmultilineblock(rout, blockname, comment=1, counter=0):
|
| 640 |
+
try:
|
| 641 |
+
r = rout['f2pyenhancements'].get(blockname)
|
| 642 |
+
except KeyError:
|
| 643 |
+
return
|
| 644 |
+
if not r:
|
| 645 |
+
return
|
| 646 |
+
if counter > 0 and isinstance(r, str):
|
| 647 |
+
return
|
| 648 |
+
if isinstance(r, list):
|
| 649 |
+
if counter >= len(r):
|
| 650 |
+
return
|
| 651 |
+
r = r[counter]
|
| 652 |
+
if r[:3] == "'''":
|
| 653 |
+
if comment:
|
| 654 |
+
r = '\t/* start ' + blockname + \
|
| 655 |
+
' multiline (' + repr(counter) + ') */\n' + r[3:]
|
| 656 |
+
else:
|
| 657 |
+
r = r[3:]
|
| 658 |
+
if r[-3:] == "'''":
|
| 659 |
+
if comment:
|
| 660 |
+
r = r[:-3] + '\n\t/* end multiline (' + repr(counter) + ')*/'
|
| 661 |
+
else:
|
| 662 |
+
r = r[:-3]
|
| 663 |
+
else:
|
| 664 |
+
errmess("%s multiline block should end with `'''`: %s\n"
|
| 665 |
+
% (blockname, repr(r)))
|
| 666 |
+
return r
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
def getcallstatement(rout):
|
| 670 |
+
return getmultilineblock(rout, 'callstatement')
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
def getcallprotoargument(rout, cb_map={}):
|
| 674 |
+
r = getmultilineblock(rout, 'callprotoargument', comment=0)
|
| 675 |
+
if r:
|
| 676 |
+
return r
|
| 677 |
+
if hascallstatement(rout):
|
| 678 |
+
outmess(
|
| 679 |
+
'warning: callstatement is defined without callprotoargument\n')
|
| 680 |
+
return
|
| 681 |
+
from .capi_maps import getctype
|
| 682 |
+
arg_types, arg_types2 = [], []
|
| 683 |
+
if l_and(isstringfunction, l_not(isfunction_wrap))(rout):
|
| 684 |
+
arg_types.extend(['char*', 'size_t'])
|
| 685 |
+
for n in rout['args']:
|
| 686 |
+
var = rout['vars'][n]
|
| 687 |
+
if isintent_callback(var):
|
| 688 |
+
continue
|
| 689 |
+
if n in cb_map:
|
| 690 |
+
ctype = cb_map[n] + '_typedef'
|
| 691 |
+
else:
|
| 692 |
+
ctype = getctype(var)
|
| 693 |
+
if l_and(isintent_c, l_or(isscalar, iscomplex))(var):
|
| 694 |
+
pass
|
| 695 |
+
elif isstring(var):
|
| 696 |
+
pass
|
| 697 |
+
else:
|
| 698 |
+
if not isattr_value(var):
|
| 699 |
+
ctype = ctype + '*'
|
| 700 |
+
if ((isstring(var)
|
| 701 |
+
or isarrayofstrings(var) # obsolete?
|
| 702 |
+
or isstringarray(var))):
|
| 703 |
+
arg_types2.append('size_t')
|
| 704 |
+
arg_types.append(ctype)
|
| 705 |
+
|
| 706 |
+
proto_args = ','.join(arg_types + arg_types2)
|
| 707 |
+
if not proto_args:
|
| 708 |
+
proto_args = 'void'
|
| 709 |
+
return proto_args
|
| 710 |
+
|
| 711 |
+
|
| 712 |
+
def getusercode(rout):
|
| 713 |
+
return getmultilineblock(rout, 'usercode')
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
def getusercode1(rout):
|
| 717 |
+
return getmultilineblock(rout, 'usercode', counter=1)
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
def getpymethoddef(rout):
|
| 721 |
+
return getmultilineblock(rout, 'pymethoddef')
|
| 722 |
+
|
| 723 |
+
|
| 724 |
+
def getargs(rout):
|
| 725 |
+
sortargs, args = [], []
|
| 726 |
+
if 'args' in rout:
|
| 727 |
+
args = rout['args']
|
| 728 |
+
if 'sortvars' in rout:
|
| 729 |
+
for a in rout['sortvars']:
|
| 730 |
+
if a in args:
|
| 731 |
+
sortargs.append(a)
|
| 732 |
+
for a in args:
|
| 733 |
+
if a not in sortargs:
|
| 734 |
+
sortargs.append(a)
|
| 735 |
+
else:
|
| 736 |
+
sortargs = rout['args']
|
| 737 |
+
return args, sortargs
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
def getargs2(rout):
|
| 741 |
+
sortargs, args = [], rout.get('args', [])
|
| 742 |
+
auxvars = [a for a in rout['vars'].keys() if isintent_aux(rout['vars'][a])
|
| 743 |
+
and a not in args]
|
| 744 |
+
args = auxvars + args
|
| 745 |
+
if 'sortvars' in rout:
|
| 746 |
+
for a in rout['sortvars']:
|
| 747 |
+
if a in args:
|
| 748 |
+
sortargs.append(a)
|
| 749 |
+
for a in args:
|
| 750 |
+
if a not in sortargs:
|
| 751 |
+
sortargs.append(a)
|
| 752 |
+
else:
|
| 753 |
+
sortargs = auxvars + rout['args']
|
| 754 |
+
return args, sortargs
|
| 755 |
+
|
| 756 |
+
|
| 757 |
+
def getrestdoc(rout):
|
| 758 |
+
if 'f2pymultilines' not in rout:
|
| 759 |
+
return None
|
| 760 |
+
k = None
|
| 761 |
+
if rout['block'] == 'python module':
|
| 762 |
+
k = rout['block'], rout['name']
|
| 763 |
+
return rout['f2pymultilines'].get(k, None)
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
def gentitle(name):
|
| 767 |
+
ln = (80 - len(name) - 6) // 2
|
| 768 |
+
return '/*%s %s %s*/' % (ln * '*', name, ln * '*')
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
def flatlist(lst):
|
| 772 |
+
if isinstance(lst, list):
|
| 773 |
+
return reduce(lambda x, y, f=flatlist: x + f(y), lst, [])
|
| 774 |
+
return [lst]
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
def stripcomma(s):
|
| 778 |
+
if s and s[-1] == ',':
|
| 779 |
+
return s[:-1]
|
| 780 |
+
return s
|
| 781 |
+
|
| 782 |
+
|
| 783 |
+
def replace(str, d, defaultsep=''):
|
| 784 |
+
if isinstance(d, list):
|
| 785 |
+
return [replace(str, _m, defaultsep) for _m in d]
|
| 786 |
+
if isinstance(str, list):
|
| 787 |
+
return [replace(_m, d, defaultsep) for _m in str]
|
| 788 |
+
for k in 2 * list(d.keys()):
|
| 789 |
+
if k == 'separatorsfor':
|
| 790 |
+
continue
|
| 791 |
+
if 'separatorsfor' in d and k in d['separatorsfor']:
|
| 792 |
+
sep = d['separatorsfor'][k]
|
| 793 |
+
else:
|
| 794 |
+
sep = defaultsep
|
| 795 |
+
if isinstance(d[k], list):
|
| 796 |
+
str = str.replace('#%s#' % (k), sep.join(flatlist(d[k])))
|
| 797 |
+
else:
|
| 798 |
+
str = str.replace('#%s#' % (k), d[k])
|
| 799 |
+
return str
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
def dictappend(rd, ar):
|
| 803 |
+
if isinstance(ar, list):
|
| 804 |
+
for a in ar:
|
| 805 |
+
rd = dictappend(rd, a)
|
| 806 |
+
return rd
|
| 807 |
+
for k in ar.keys():
|
| 808 |
+
if k[0] == '_':
|
| 809 |
+
continue
|
| 810 |
+
if k in rd:
|
| 811 |
+
if isinstance(rd[k], str):
|
| 812 |
+
rd[k] = [rd[k]]
|
| 813 |
+
if isinstance(rd[k], list):
|
| 814 |
+
if isinstance(ar[k], list):
|
| 815 |
+
rd[k] = rd[k] + ar[k]
|
| 816 |
+
else:
|
| 817 |
+
rd[k].append(ar[k])
|
| 818 |
+
elif isinstance(rd[k], dict):
|
| 819 |
+
if isinstance(ar[k], dict):
|
| 820 |
+
if k == 'separatorsfor':
|
| 821 |
+
for k1 in ar[k].keys():
|
| 822 |
+
if k1 not in rd[k]:
|
| 823 |
+
rd[k][k1] = ar[k][k1]
|
| 824 |
+
else:
|
| 825 |
+
rd[k] = dictappend(rd[k], ar[k])
|
| 826 |
+
else:
|
| 827 |
+
rd[k] = ar[k]
|
| 828 |
+
return rd
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
def applyrules(rules, d, var={}):
|
| 832 |
+
ret = {}
|
| 833 |
+
if isinstance(rules, list):
|
| 834 |
+
for r in rules:
|
| 835 |
+
rr = applyrules(r, d, var)
|
| 836 |
+
ret = dictappend(ret, rr)
|
| 837 |
+
if '_break' in rr:
|
| 838 |
+
break
|
| 839 |
+
return ret
|
| 840 |
+
if '_check' in rules and (not rules['_check'](var)):
|
| 841 |
+
return ret
|
| 842 |
+
if 'need' in rules:
|
| 843 |
+
res = applyrules({'needs': rules['need']}, d, var)
|
| 844 |
+
if 'needs' in res:
|
| 845 |
+
cfuncs.append_needs(res['needs'])
|
| 846 |
+
|
| 847 |
+
for k in rules.keys():
|
| 848 |
+
if k == 'separatorsfor':
|
| 849 |
+
ret[k] = rules[k]
|
| 850 |
+
continue
|
| 851 |
+
if isinstance(rules[k], str):
|
| 852 |
+
ret[k] = replace(rules[k], d)
|
| 853 |
+
elif isinstance(rules[k], list):
|
| 854 |
+
ret[k] = []
|
| 855 |
+
for i in rules[k]:
|
| 856 |
+
ar = applyrules({k: i}, d, var)
|
| 857 |
+
if k in ar:
|
| 858 |
+
ret[k].append(ar[k])
|
| 859 |
+
elif k[0] == '_':
|
| 860 |
+
continue
|
| 861 |
+
elif isinstance(rules[k], dict):
|
| 862 |
+
ret[k] = []
|
| 863 |
+
for k1 in rules[k].keys():
|
| 864 |
+
if isinstance(k1, types.FunctionType) and k1(var):
|
| 865 |
+
if isinstance(rules[k][k1], list):
|
| 866 |
+
for i in rules[k][k1]:
|
| 867 |
+
if isinstance(i, dict):
|
| 868 |
+
res = applyrules({'supertext': i}, d, var)
|
| 869 |
+
if 'supertext' in res:
|
| 870 |
+
i = res['supertext']
|
| 871 |
+
else:
|
| 872 |
+
i = ''
|
| 873 |
+
ret[k].append(replace(i, d))
|
| 874 |
+
else:
|
| 875 |
+
i = rules[k][k1]
|
| 876 |
+
if isinstance(i, dict):
|
| 877 |
+
res = applyrules({'supertext': i}, d)
|
| 878 |
+
if 'supertext' in res:
|
| 879 |
+
i = res['supertext']
|
| 880 |
+
else:
|
| 881 |
+
i = ''
|
| 882 |
+
ret[k].append(replace(i, d))
|
| 883 |
+
else:
|
| 884 |
+
errmess('applyrules: ignoring rule %s.\n' % repr(rules[k]))
|
| 885 |
+
if isinstance(ret[k], list):
|
| 886 |
+
if len(ret[k]) == 1:
|
| 887 |
+
ret[k] = ret[k][0]
|
| 888 |
+
if ret[k] == []:
|
| 889 |
+
del ret[k]
|
| 890 |
+
return ret
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/capi_maps.py
ADDED
|
@@ -0,0 +1,880 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Copyright 1999,2000 Pearu Peterson all rights reserved,
|
| 5 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 6 |
+
Permission to use, modify, and distribute this software is given under the
|
| 7 |
+
terms of the NumPy License.
|
| 8 |
+
|
| 9 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 10 |
+
$Date: 2005/05/06 10:57:33 $
|
| 11 |
+
Pearu Peterson
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
from . import __version__
|
| 15 |
+
f2py_version = __version__.version
|
| 16 |
+
|
| 17 |
+
import copy
|
| 18 |
+
import re
|
| 19 |
+
import os
|
| 20 |
+
from .crackfortran import markoutercomma
|
| 21 |
+
from . import cb_rules
|
| 22 |
+
|
| 23 |
+
# The environment provided by auxfuncs.py is needed for some calls to eval.
|
| 24 |
+
# As the needed functions cannot be determined by static inspection of the
|
| 25 |
+
# code, it is safest to use import * pending a major refactoring of f2py.
|
| 26 |
+
from .auxfuncs import *
|
| 27 |
+
|
| 28 |
+
__all__ = [
|
| 29 |
+
'getctype', 'getstrlength', 'getarrdims', 'getpydocsign',
|
| 30 |
+
'getarrdocsign', 'getinit', 'sign2map', 'routsign2map', 'modsign2map',
|
| 31 |
+
'cb_sign2map', 'cb_routsign2map', 'common_sign2map'
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Numarray and Numeric users should set this False
|
| 36 |
+
using_newcore = True
|
| 37 |
+
|
| 38 |
+
depargs = []
|
| 39 |
+
lcb_map = {}
|
| 40 |
+
lcb2_map = {}
|
| 41 |
+
# forced casting: mainly caused by the fact that Python or Numeric
|
| 42 |
+
# C/APIs do not support the corresponding C types.
|
| 43 |
+
c2py_map = {'double': 'float',
|
| 44 |
+
'float': 'float', # forced casting
|
| 45 |
+
'long_double': 'float', # forced casting
|
| 46 |
+
'char': 'int', # forced casting
|
| 47 |
+
'signed_char': 'int', # forced casting
|
| 48 |
+
'unsigned_char': 'int', # forced casting
|
| 49 |
+
'short': 'int', # forced casting
|
| 50 |
+
'unsigned_short': 'int', # forced casting
|
| 51 |
+
'int': 'int', # forced casting
|
| 52 |
+
'long': 'int',
|
| 53 |
+
'long_long': 'long',
|
| 54 |
+
'unsigned': 'int', # forced casting
|
| 55 |
+
'complex_float': 'complex', # forced casting
|
| 56 |
+
'complex_double': 'complex',
|
| 57 |
+
'complex_long_double': 'complex', # forced casting
|
| 58 |
+
'string': 'string',
|
| 59 |
+
'character': 'bytes',
|
| 60 |
+
}
|
| 61 |
+
c2capi_map = {'double': 'NPY_DOUBLE',
|
| 62 |
+
'float': 'NPY_FLOAT',
|
| 63 |
+
'long_double': 'NPY_DOUBLE', # forced casting
|
| 64 |
+
'char': 'NPY_STRING',
|
| 65 |
+
'unsigned_char': 'NPY_UBYTE',
|
| 66 |
+
'signed_char': 'NPY_BYTE',
|
| 67 |
+
'short': 'NPY_SHORT',
|
| 68 |
+
'unsigned_short': 'NPY_USHORT',
|
| 69 |
+
'int': 'NPY_INT',
|
| 70 |
+
'unsigned': 'NPY_UINT',
|
| 71 |
+
'long': 'NPY_LONG',
|
| 72 |
+
'long_long': 'NPY_LONG', # forced casting
|
| 73 |
+
'complex_float': 'NPY_CFLOAT',
|
| 74 |
+
'complex_double': 'NPY_CDOUBLE',
|
| 75 |
+
'complex_long_double': 'NPY_CDOUBLE', # forced casting
|
| 76 |
+
'string': 'NPY_STRING',
|
| 77 |
+
'character': 'NPY_CHAR'}
|
| 78 |
+
|
| 79 |
+
# These new maps aren't used anywhere yet, but should be by default
|
| 80 |
+
# unless building numeric or numarray extensions.
|
| 81 |
+
if using_newcore:
|
| 82 |
+
c2capi_map = {'double': 'NPY_DOUBLE',
|
| 83 |
+
'float': 'NPY_FLOAT',
|
| 84 |
+
'long_double': 'NPY_LONGDOUBLE',
|
| 85 |
+
'char': 'NPY_BYTE',
|
| 86 |
+
'unsigned_char': 'NPY_UBYTE',
|
| 87 |
+
'signed_char': 'NPY_BYTE',
|
| 88 |
+
'short': 'NPY_SHORT',
|
| 89 |
+
'unsigned_short': 'NPY_USHORT',
|
| 90 |
+
'int': 'NPY_INT',
|
| 91 |
+
'unsigned': 'NPY_UINT',
|
| 92 |
+
'long': 'NPY_LONG',
|
| 93 |
+
'unsigned_long': 'NPY_ULONG',
|
| 94 |
+
'long_long': 'NPY_LONGLONG',
|
| 95 |
+
'unsigned_long_long': 'NPY_ULONGLONG',
|
| 96 |
+
'complex_float': 'NPY_CFLOAT',
|
| 97 |
+
'complex_double': 'NPY_CDOUBLE',
|
| 98 |
+
'complex_long_double': 'NPY_CDOUBLE',
|
| 99 |
+
'string': 'NPY_STRING',
|
| 100 |
+
'character': 'NPY_STRING'}
|
| 101 |
+
|
| 102 |
+
c2pycode_map = {'double': 'd',
|
| 103 |
+
'float': 'f',
|
| 104 |
+
'long_double': 'd', # forced casting
|
| 105 |
+
'char': '1',
|
| 106 |
+
'signed_char': '1',
|
| 107 |
+
'unsigned_char': 'b',
|
| 108 |
+
'short': 's',
|
| 109 |
+
'unsigned_short': 'w',
|
| 110 |
+
'int': 'i',
|
| 111 |
+
'unsigned': 'u',
|
| 112 |
+
'long': 'l',
|
| 113 |
+
'long_long': 'L',
|
| 114 |
+
'complex_float': 'F',
|
| 115 |
+
'complex_double': 'D',
|
| 116 |
+
'complex_long_double': 'D', # forced casting
|
| 117 |
+
'string': 'c',
|
| 118 |
+
'character': 'c'
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if using_newcore:
|
| 122 |
+
c2pycode_map = {'double': 'd',
|
| 123 |
+
'float': 'f',
|
| 124 |
+
'long_double': 'g',
|
| 125 |
+
'char': 'b',
|
| 126 |
+
'unsigned_char': 'B',
|
| 127 |
+
'signed_char': 'b',
|
| 128 |
+
'short': 'h',
|
| 129 |
+
'unsigned_short': 'H',
|
| 130 |
+
'int': 'i',
|
| 131 |
+
'unsigned': 'I',
|
| 132 |
+
'long': 'l',
|
| 133 |
+
'unsigned_long': 'L',
|
| 134 |
+
'long_long': 'q',
|
| 135 |
+
'unsigned_long_long': 'Q',
|
| 136 |
+
'complex_float': 'F',
|
| 137 |
+
'complex_double': 'D',
|
| 138 |
+
'complex_long_double': 'G',
|
| 139 |
+
'string': 'S',
|
| 140 |
+
'character': 'c'}
|
| 141 |
+
|
| 142 |
+
# https://docs.python.org/3/c-api/arg.html#building-values
|
| 143 |
+
# c2buildvalue_map is NumPy agnostic, so no need to bother with using_newcore
|
| 144 |
+
c2buildvalue_map = {'double': 'd',
|
| 145 |
+
'float': 'f',
|
| 146 |
+
'char': 'b',
|
| 147 |
+
'signed_char': 'b',
|
| 148 |
+
'short': 'h',
|
| 149 |
+
'int': 'i',
|
| 150 |
+
'long': 'l',
|
| 151 |
+
'long_long': 'L',
|
| 152 |
+
'complex_float': 'N',
|
| 153 |
+
'complex_double': 'N',
|
| 154 |
+
'complex_long_double': 'N',
|
| 155 |
+
'string': 'y',
|
| 156 |
+
'character': 'c'}
|
| 157 |
+
|
| 158 |
+
f2cmap_all = {'real': {'': 'float', '4': 'float', '8': 'double',
|
| 159 |
+
'12': 'long_double', '16': 'long_double'},
|
| 160 |
+
'integer': {'': 'int', '1': 'signed_char', '2': 'short',
|
| 161 |
+
'4': 'int', '8': 'long_long',
|
| 162 |
+
'-1': 'unsigned_char', '-2': 'unsigned_short',
|
| 163 |
+
'-4': 'unsigned', '-8': 'unsigned_long_long'},
|
| 164 |
+
'complex': {'': 'complex_float', '8': 'complex_float',
|
| 165 |
+
'16': 'complex_double', '24': 'complex_long_double',
|
| 166 |
+
'32': 'complex_long_double'},
|
| 167 |
+
'complexkind': {'': 'complex_float', '4': 'complex_float',
|
| 168 |
+
'8': 'complex_double', '12': 'complex_long_double',
|
| 169 |
+
'16': 'complex_long_double'},
|
| 170 |
+
'logical': {'': 'int', '1': 'char', '2': 'short', '4': 'int',
|
| 171 |
+
'8': 'long_long'},
|
| 172 |
+
'double complex': {'': 'complex_double'},
|
| 173 |
+
'double precision': {'': 'double'},
|
| 174 |
+
'byte': {'': 'char'},
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
f2cmap_default = copy.deepcopy(f2cmap_all)
|
| 178 |
+
|
| 179 |
+
f2cmap_mapped = []
|
| 180 |
+
|
| 181 |
+
def load_f2cmap_file(f2cmap_file):
|
| 182 |
+
global f2cmap_all
|
| 183 |
+
|
| 184 |
+
f2cmap_all = copy.deepcopy(f2cmap_default)
|
| 185 |
+
|
| 186 |
+
if f2cmap_file is None:
|
| 187 |
+
# Default value
|
| 188 |
+
f2cmap_file = '.f2py_f2cmap'
|
| 189 |
+
if not os.path.isfile(f2cmap_file):
|
| 190 |
+
return
|
| 191 |
+
|
| 192 |
+
# User defined additions to f2cmap_all.
|
| 193 |
+
# f2cmap_file must contain a dictionary of dictionaries, only. For
|
| 194 |
+
# example, {'real':{'low':'float'}} means that Fortran 'real(low)' is
|
| 195 |
+
# interpreted as C 'float'. This feature is useful for F90/95 users if
|
| 196 |
+
# they use PARAMETERS in type specifications.
|
| 197 |
+
try:
|
| 198 |
+
outmess('Reading f2cmap from {!r} ...\n'.format(f2cmap_file))
|
| 199 |
+
with open(f2cmap_file, 'r') as f:
|
| 200 |
+
d = eval(f.read().lower(), {}, {})
|
| 201 |
+
for k, d1 in d.items():
|
| 202 |
+
for k1 in d1.keys():
|
| 203 |
+
d1[k1.lower()] = d1[k1]
|
| 204 |
+
d[k.lower()] = d[k]
|
| 205 |
+
for k in d.keys():
|
| 206 |
+
if k not in f2cmap_all:
|
| 207 |
+
f2cmap_all[k] = {}
|
| 208 |
+
for k1 in d[k].keys():
|
| 209 |
+
if d[k][k1] in c2py_map:
|
| 210 |
+
if k1 in f2cmap_all[k]:
|
| 211 |
+
outmess(
|
| 212 |
+
"\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n" % (k, k1, f2cmap_all[k][k1], d[k][k1]))
|
| 213 |
+
f2cmap_all[k][k1] = d[k][k1]
|
| 214 |
+
outmess('\tMapping "%s(kind=%s)" to "%s"\n' %
|
| 215 |
+
(k, k1, d[k][k1]))
|
| 216 |
+
f2cmap_mapped.append(d[k][k1])
|
| 217 |
+
else:
|
| 218 |
+
errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n" % (
|
| 219 |
+
k, k1, d[k][k1], d[k][k1], list(c2py_map.keys())))
|
| 220 |
+
outmess('Successfully applied user defined f2cmap changes\n')
|
| 221 |
+
except Exception as msg:
|
| 222 |
+
errmess(
|
| 223 |
+
'Failed to apply user defined f2cmap changes: %s. Skipping.\n' % (msg))
|
| 224 |
+
|
| 225 |
+
cformat_map = {'double': '%g',
|
| 226 |
+
'float': '%g',
|
| 227 |
+
'long_double': '%Lg',
|
| 228 |
+
'char': '%d',
|
| 229 |
+
'signed_char': '%d',
|
| 230 |
+
'unsigned_char': '%hhu',
|
| 231 |
+
'short': '%hd',
|
| 232 |
+
'unsigned_short': '%hu',
|
| 233 |
+
'int': '%d',
|
| 234 |
+
'unsigned': '%u',
|
| 235 |
+
'long': '%ld',
|
| 236 |
+
'unsigned_long': '%lu',
|
| 237 |
+
'long_long': '%ld',
|
| 238 |
+
'complex_float': '(%g,%g)',
|
| 239 |
+
'complex_double': '(%g,%g)',
|
| 240 |
+
'complex_long_double': '(%Lg,%Lg)',
|
| 241 |
+
'string': '\\"%s\\"',
|
| 242 |
+
'character': "'%c'",
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
# Auxiliary functions
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def getctype(var):
|
| 249 |
+
"""
|
| 250 |
+
Determines C type
|
| 251 |
+
"""
|
| 252 |
+
ctype = 'void'
|
| 253 |
+
if isfunction(var):
|
| 254 |
+
if 'result' in var:
|
| 255 |
+
a = var['result']
|
| 256 |
+
else:
|
| 257 |
+
a = var['name']
|
| 258 |
+
if a in var['vars']:
|
| 259 |
+
return getctype(var['vars'][a])
|
| 260 |
+
else:
|
| 261 |
+
errmess('getctype: function %s has no return value?!\n' % a)
|
| 262 |
+
elif issubroutine(var):
|
| 263 |
+
return ctype
|
| 264 |
+
elif ischaracter_or_characterarray(var):
|
| 265 |
+
return 'character'
|
| 266 |
+
elif isstring_or_stringarray(var):
|
| 267 |
+
return 'string'
|
| 268 |
+
elif 'typespec' in var and var['typespec'].lower() in f2cmap_all:
|
| 269 |
+
typespec = var['typespec'].lower()
|
| 270 |
+
f2cmap = f2cmap_all[typespec]
|
| 271 |
+
ctype = f2cmap[''] # default type
|
| 272 |
+
if 'kindselector' in var:
|
| 273 |
+
if '*' in var['kindselector']:
|
| 274 |
+
try:
|
| 275 |
+
ctype = f2cmap[var['kindselector']['*']]
|
| 276 |
+
except KeyError:
|
| 277 |
+
errmess('getctype: "%s %s %s" not supported.\n' %
|
| 278 |
+
(var['typespec'], '*', var['kindselector']['*']))
|
| 279 |
+
elif 'kind' in var['kindselector']:
|
| 280 |
+
if typespec + 'kind' in f2cmap_all:
|
| 281 |
+
f2cmap = f2cmap_all[typespec + 'kind']
|
| 282 |
+
try:
|
| 283 |
+
ctype = f2cmap[var['kindselector']['kind']]
|
| 284 |
+
except KeyError:
|
| 285 |
+
if typespec in f2cmap_all:
|
| 286 |
+
f2cmap = f2cmap_all[typespec]
|
| 287 |
+
try:
|
| 288 |
+
ctype = f2cmap[str(var['kindselector']['kind'])]
|
| 289 |
+
except KeyError:
|
| 290 |
+
errmess('getctype: "%s(kind=%s)" is mapped to C "%s" (to override define dict(%s = dict(%s="<C typespec>")) in %s/.f2py_f2cmap file).\n'
|
| 291 |
+
% (typespec, var['kindselector']['kind'], ctype,
|
| 292 |
+
typespec, var['kindselector']['kind'], os.getcwd()))
|
| 293 |
+
else:
|
| 294 |
+
if not isexternal(var):
|
| 295 |
+
errmess('getctype: No C-type found in "%s", assuming void.\n' % var)
|
| 296 |
+
return ctype
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def f2cexpr(expr):
|
| 300 |
+
"""Rewrite Fortran expression as f2py supported C expression.
|
| 301 |
+
|
| 302 |
+
Due to the lack of a proper expression parser in f2py, this
|
| 303 |
+
function uses a heuristic approach that assumes that Fortran
|
| 304 |
+
arithmetic expressions are valid C arithmetic expressions when
|
| 305 |
+
mapping Fortran function calls to the corresponding C function/CPP
|
| 306 |
+
macros calls.
|
| 307 |
+
|
| 308 |
+
"""
|
| 309 |
+
# TODO: support Fortran `len` function with optional kind parameter
|
| 310 |
+
expr = re.sub(r'\blen\b', 'f2py_slen', expr)
|
| 311 |
+
return expr
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def getstrlength(var):
|
| 315 |
+
if isstringfunction(var):
|
| 316 |
+
if 'result' in var:
|
| 317 |
+
a = var['result']
|
| 318 |
+
else:
|
| 319 |
+
a = var['name']
|
| 320 |
+
if a in var['vars']:
|
| 321 |
+
return getstrlength(var['vars'][a])
|
| 322 |
+
else:
|
| 323 |
+
errmess('getstrlength: function %s has no return value?!\n' % a)
|
| 324 |
+
if not isstring(var):
|
| 325 |
+
errmess(
|
| 326 |
+
'getstrlength: expected a signature of a string but got: %s\n' % (repr(var)))
|
| 327 |
+
len = '1'
|
| 328 |
+
if 'charselector' in var:
|
| 329 |
+
a = var['charselector']
|
| 330 |
+
if '*' in a:
|
| 331 |
+
len = a['*']
|
| 332 |
+
elif 'len' in a:
|
| 333 |
+
len = f2cexpr(a['len'])
|
| 334 |
+
if re.match(r'\(\s*(\*|:)\s*\)', len) or re.match(r'(\*|:)', len):
|
| 335 |
+
if isintent_hide(var):
|
| 336 |
+
errmess('getstrlength:intent(hide): expected a string with defined length but got: %s\n' % (
|
| 337 |
+
repr(var)))
|
| 338 |
+
len = '-1'
|
| 339 |
+
return len
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def getarrdims(a, var, verbose=0):
|
| 343 |
+
ret = {}
|
| 344 |
+
if isstring(var) and not isarray(var):
|
| 345 |
+
ret['size'] = getstrlength(var)
|
| 346 |
+
ret['rank'] = '0'
|
| 347 |
+
ret['dims'] = ''
|
| 348 |
+
elif isscalar(var):
|
| 349 |
+
ret['size'] = '1'
|
| 350 |
+
ret['rank'] = '0'
|
| 351 |
+
ret['dims'] = ''
|
| 352 |
+
elif isarray(var):
|
| 353 |
+
dim = copy.copy(var['dimension'])
|
| 354 |
+
ret['size'] = '*'.join(dim)
|
| 355 |
+
try:
|
| 356 |
+
ret['size'] = repr(eval(ret['size']))
|
| 357 |
+
except Exception:
|
| 358 |
+
pass
|
| 359 |
+
ret['dims'] = ','.join(dim)
|
| 360 |
+
ret['rank'] = repr(len(dim))
|
| 361 |
+
ret['rank*[-1]'] = repr(len(dim) * [-1])[1:-1]
|
| 362 |
+
for i in range(len(dim)): # solve dim for dependencies
|
| 363 |
+
v = []
|
| 364 |
+
if dim[i] in depargs:
|
| 365 |
+
v = [dim[i]]
|
| 366 |
+
else:
|
| 367 |
+
for va in depargs:
|
| 368 |
+
if re.match(r'.*?\b%s\b.*' % va, dim[i]):
|
| 369 |
+
v.append(va)
|
| 370 |
+
for va in v:
|
| 371 |
+
if depargs.index(va) > depargs.index(a):
|
| 372 |
+
dim[i] = '*'
|
| 373 |
+
break
|
| 374 |
+
ret['setdims'], i = '', -1
|
| 375 |
+
for d in dim:
|
| 376 |
+
i = i + 1
|
| 377 |
+
if d not in ['*', ':', '(*)', '(:)']:
|
| 378 |
+
ret['setdims'] = '%s#varname#_Dims[%d]=%s,' % (
|
| 379 |
+
ret['setdims'], i, d)
|
| 380 |
+
if ret['setdims']:
|
| 381 |
+
ret['setdims'] = ret['setdims'][:-1]
|
| 382 |
+
ret['cbsetdims'], i = '', -1
|
| 383 |
+
for d in var['dimension']:
|
| 384 |
+
i = i + 1
|
| 385 |
+
if d not in ['*', ':', '(*)', '(:)']:
|
| 386 |
+
ret['cbsetdims'] = '%s#varname#_Dims[%d]=%s,' % (
|
| 387 |
+
ret['cbsetdims'], i, d)
|
| 388 |
+
elif isintent_in(var):
|
| 389 |
+
outmess('getarrdims:warning: assumed shape array, using 0 instead of %r\n'
|
| 390 |
+
% (d))
|
| 391 |
+
ret['cbsetdims'] = '%s#varname#_Dims[%d]=%s,' % (
|
| 392 |
+
ret['cbsetdims'], i, 0)
|
| 393 |
+
elif verbose:
|
| 394 |
+
errmess(
|
| 395 |
+
'getarrdims: If in call-back function: array argument %s must have bounded dimensions: got %s\n' % (repr(a), repr(d)))
|
| 396 |
+
if ret['cbsetdims']:
|
| 397 |
+
ret['cbsetdims'] = ret['cbsetdims'][:-1]
|
| 398 |
+
# if not isintent_c(var):
|
| 399 |
+
# var['dimension'].reverse()
|
| 400 |
+
return ret
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def getpydocsign(a, var):
|
| 404 |
+
global lcb_map
|
| 405 |
+
if isfunction(var):
|
| 406 |
+
if 'result' in var:
|
| 407 |
+
af = var['result']
|
| 408 |
+
else:
|
| 409 |
+
af = var['name']
|
| 410 |
+
if af in var['vars']:
|
| 411 |
+
return getpydocsign(af, var['vars'][af])
|
| 412 |
+
else:
|
| 413 |
+
errmess('getctype: function %s has no return value?!\n' % af)
|
| 414 |
+
return '', ''
|
| 415 |
+
sig, sigout = a, a
|
| 416 |
+
opt = ''
|
| 417 |
+
if isintent_in(var):
|
| 418 |
+
opt = 'input'
|
| 419 |
+
elif isintent_inout(var):
|
| 420 |
+
opt = 'in/output'
|
| 421 |
+
out_a = a
|
| 422 |
+
if isintent_out(var):
|
| 423 |
+
for k in var['intent']:
|
| 424 |
+
if k[:4] == 'out=':
|
| 425 |
+
out_a = k[4:]
|
| 426 |
+
break
|
| 427 |
+
init = ''
|
| 428 |
+
ctype = getctype(var)
|
| 429 |
+
|
| 430 |
+
if hasinitvalue(var):
|
| 431 |
+
init, showinit = getinit(a, var)
|
| 432 |
+
init = ', optional\\n Default: %s' % showinit
|
| 433 |
+
if isscalar(var):
|
| 434 |
+
if isintent_inout(var):
|
| 435 |
+
sig = '%s : %s rank-0 array(%s,\'%s\')%s' % (a, opt, c2py_map[ctype],
|
| 436 |
+
c2pycode_map[ctype], init)
|
| 437 |
+
else:
|
| 438 |
+
sig = '%s : %s %s%s' % (a, opt, c2py_map[ctype], init)
|
| 439 |
+
sigout = '%s : %s' % (out_a, c2py_map[ctype])
|
| 440 |
+
elif isstring(var):
|
| 441 |
+
if isintent_inout(var):
|
| 442 |
+
sig = '%s : %s rank-0 array(string(len=%s),\'c\')%s' % (
|
| 443 |
+
a, opt, getstrlength(var), init)
|
| 444 |
+
else:
|
| 445 |
+
sig = '%s : %s string(len=%s)%s' % (
|
| 446 |
+
a, opt, getstrlength(var), init)
|
| 447 |
+
sigout = '%s : string(len=%s)' % (out_a, getstrlength(var))
|
| 448 |
+
elif isarray(var):
|
| 449 |
+
dim = var['dimension']
|
| 450 |
+
rank = repr(len(dim))
|
| 451 |
+
sig = '%s : %s rank-%s array(\'%s\') with bounds (%s)%s' % (a, opt, rank,
|
| 452 |
+
c2pycode_map[
|
| 453 |
+
ctype],
|
| 454 |
+
','.join(dim), init)
|
| 455 |
+
if a == out_a:
|
| 456 |
+
sigout = '%s : rank-%s array(\'%s\') with bounds (%s)'\
|
| 457 |
+
% (a, rank, c2pycode_map[ctype], ','.join(dim))
|
| 458 |
+
else:
|
| 459 |
+
sigout = '%s : rank-%s array(\'%s\') with bounds (%s) and %s storage'\
|
| 460 |
+
% (out_a, rank, c2pycode_map[ctype], ','.join(dim), a)
|
| 461 |
+
elif isexternal(var):
|
| 462 |
+
ua = ''
|
| 463 |
+
if a in lcb_map and lcb_map[a] in lcb2_map and 'argname' in lcb2_map[lcb_map[a]]:
|
| 464 |
+
ua = lcb2_map[lcb_map[a]]['argname']
|
| 465 |
+
if not ua == a:
|
| 466 |
+
ua = ' => %s' % ua
|
| 467 |
+
else:
|
| 468 |
+
ua = ''
|
| 469 |
+
sig = '%s : call-back function%s' % (a, ua)
|
| 470 |
+
sigout = sig
|
| 471 |
+
else:
|
| 472 |
+
errmess(
|
| 473 |
+
'getpydocsign: Could not resolve docsignature for "%s".\n' % a)
|
| 474 |
+
return sig, sigout
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
def getarrdocsign(a, var):
|
| 478 |
+
ctype = getctype(var)
|
| 479 |
+
if isstring(var) and (not isarray(var)):
|
| 480 |
+
sig = '%s : rank-0 array(string(len=%s),\'c\')' % (a,
|
| 481 |
+
getstrlength(var))
|
| 482 |
+
elif isscalar(var):
|
| 483 |
+
sig = '%s : rank-0 array(%s,\'%s\')' % (a, c2py_map[ctype],
|
| 484 |
+
c2pycode_map[ctype],)
|
| 485 |
+
elif isarray(var):
|
| 486 |
+
dim = var['dimension']
|
| 487 |
+
rank = repr(len(dim))
|
| 488 |
+
sig = '%s : rank-%s array(\'%s\') with bounds (%s)' % (a, rank,
|
| 489 |
+
c2pycode_map[
|
| 490 |
+
ctype],
|
| 491 |
+
','.join(dim))
|
| 492 |
+
return sig
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
def getinit(a, var):
|
| 496 |
+
if isstring(var):
|
| 497 |
+
init, showinit = '""', "''"
|
| 498 |
+
else:
|
| 499 |
+
init, showinit = '', ''
|
| 500 |
+
if hasinitvalue(var):
|
| 501 |
+
init = var['=']
|
| 502 |
+
showinit = init
|
| 503 |
+
if iscomplex(var) or iscomplexarray(var):
|
| 504 |
+
ret = {}
|
| 505 |
+
|
| 506 |
+
try:
|
| 507 |
+
v = var["="]
|
| 508 |
+
if ',' in v:
|
| 509 |
+
ret['init.r'], ret['init.i'] = markoutercomma(
|
| 510 |
+
v[1:-1]).split('@,@')
|
| 511 |
+
else:
|
| 512 |
+
v = eval(v, {}, {})
|
| 513 |
+
ret['init.r'], ret['init.i'] = str(v.real), str(v.imag)
|
| 514 |
+
except Exception:
|
| 515 |
+
raise ValueError(
|
| 516 |
+
'getinit: expected complex number `(r,i)\' but got `%s\' as initial value of %r.' % (init, a))
|
| 517 |
+
if isarray(var):
|
| 518 |
+
init = '(capi_c.r=%s,capi_c.i=%s,capi_c)' % (
|
| 519 |
+
ret['init.r'], ret['init.i'])
|
| 520 |
+
elif isstring(var):
|
| 521 |
+
if not init:
|
| 522 |
+
init, showinit = '""', "''"
|
| 523 |
+
if init[0] == "'":
|
| 524 |
+
init = '"%s"' % (init[1:-1].replace('"', '\\"'))
|
| 525 |
+
if init[0] == '"':
|
| 526 |
+
showinit = "'%s'" % (init[1:-1])
|
| 527 |
+
return init, showinit
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
def get_elsize(var):
|
| 531 |
+
if isstring(var) or isstringarray(var):
|
| 532 |
+
elsize = getstrlength(var)
|
| 533 |
+
# override with user-specified length when available:
|
| 534 |
+
elsize = var['charselector'].get('f2py_len', elsize)
|
| 535 |
+
return elsize
|
| 536 |
+
if ischaracter(var) or ischaracterarray(var):
|
| 537 |
+
return '1'
|
| 538 |
+
# for numerical types, PyArray_New* functions ignore specified
|
| 539 |
+
# elsize, so we just return 1 and let elsize be determined at
|
| 540 |
+
# runtime, see fortranobject.c
|
| 541 |
+
return '1'
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
def sign2map(a, var):
|
| 545 |
+
"""
|
| 546 |
+
varname,ctype,atype
|
| 547 |
+
init,init.r,init.i,pytype
|
| 548 |
+
vardebuginfo,vardebugshowvalue,varshowvalue
|
| 549 |
+
varrformat
|
| 550 |
+
|
| 551 |
+
intent
|
| 552 |
+
"""
|
| 553 |
+
out_a = a
|
| 554 |
+
if isintent_out(var):
|
| 555 |
+
for k in var['intent']:
|
| 556 |
+
if k[:4] == 'out=':
|
| 557 |
+
out_a = k[4:]
|
| 558 |
+
break
|
| 559 |
+
ret = {'varname': a, 'outvarname': out_a, 'ctype': getctype(var)}
|
| 560 |
+
intent_flags = []
|
| 561 |
+
for f, s in isintent_dict.items():
|
| 562 |
+
if f(var):
|
| 563 |
+
intent_flags.append('F2PY_%s' % s)
|
| 564 |
+
if intent_flags:
|
| 565 |
+
# TODO: Evaluate intent_flags here.
|
| 566 |
+
ret['intent'] = '|'.join(intent_flags)
|
| 567 |
+
else:
|
| 568 |
+
ret['intent'] = 'F2PY_INTENT_IN'
|
| 569 |
+
if isarray(var):
|
| 570 |
+
ret['varrformat'] = 'N'
|
| 571 |
+
elif ret['ctype'] in c2buildvalue_map:
|
| 572 |
+
ret['varrformat'] = c2buildvalue_map[ret['ctype']]
|
| 573 |
+
else:
|
| 574 |
+
ret['varrformat'] = 'O'
|
| 575 |
+
ret['init'], ret['showinit'] = getinit(a, var)
|
| 576 |
+
if hasinitvalue(var) and iscomplex(var) and not isarray(var):
|
| 577 |
+
ret['init.r'], ret['init.i'] = markoutercomma(
|
| 578 |
+
ret['init'][1:-1]).split('@,@')
|
| 579 |
+
if isexternal(var):
|
| 580 |
+
ret['cbnamekey'] = a
|
| 581 |
+
if a in lcb_map:
|
| 582 |
+
ret['cbname'] = lcb_map[a]
|
| 583 |
+
ret['maxnofargs'] = lcb2_map[lcb_map[a]]['maxnofargs']
|
| 584 |
+
ret['nofoptargs'] = lcb2_map[lcb_map[a]]['nofoptargs']
|
| 585 |
+
ret['cbdocstr'] = lcb2_map[lcb_map[a]]['docstr']
|
| 586 |
+
ret['cblatexdocstr'] = lcb2_map[lcb_map[a]]['latexdocstr']
|
| 587 |
+
else:
|
| 588 |
+
ret['cbname'] = a
|
| 589 |
+
errmess('sign2map: Confused: external %s is not in lcb_map%s.\n' % (
|
| 590 |
+
a, list(lcb_map.keys())))
|
| 591 |
+
if isstring(var):
|
| 592 |
+
ret['length'] = getstrlength(var)
|
| 593 |
+
if isarray(var):
|
| 594 |
+
ret = dictappend(ret, getarrdims(a, var))
|
| 595 |
+
dim = copy.copy(var['dimension'])
|
| 596 |
+
if ret['ctype'] in c2capi_map:
|
| 597 |
+
ret['atype'] = c2capi_map[ret['ctype']]
|
| 598 |
+
ret['elsize'] = get_elsize(var)
|
| 599 |
+
# Debug info
|
| 600 |
+
if debugcapi(var):
|
| 601 |
+
il = [isintent_in, 'input', isintent_out, 'output',
|
| 602 |
+
isintent_inout, 'inoutput', isrequired, 'required',
|
| 603 |
+
isoptional, 'optional', isintent_hide, 'hidden',
|
| 604 |
+
iscomplex, 'complex scalar',
|
| 605 |
+
l_and(isscalar, l_not(iscomplex)), 'scalar',
|
| 606 |
+
isstring, 'string', isarray, 'array',
|
| 607 |
+
iscomplexarray, 'complex array', isstringarray, 'string array',
|
| 608 |
+
iscomplexfunction, 'complex function',
|
| 609 |
+
l_and(isfunction, l_not(iscomplexfunction)), 'function',
|
| 610 |
+
isexternal, 'callback',
|
| 611 |
+
isintent_callback, 'callback',
|
| 612 |
+
isintent_aux, 'auxiliary',
|
| 613 |
+
]
|
| 614 |
+
rl = []
|
| 615 |
+
for i in range(0, len(il), 2):
|
| 616 |
+
if il[i](var):
|
| 617 |
+
rl.append(il[i + 1])
|
| 618 |
+
if isstring(var):
|
| 619 |
+
rl.append('slen(%s)=%s' % (a, ret['length']))
|
| 620 |
+
if isarray(var):
|
| 621 |
+
ddim = ','.join(
|
| 622 |
+
map(lambda x, y: '%s|%s' % (x, y), var['dimension'], dim))
|
| 623 |
+
rl.append('dims(%s)' % ddim)
|
| 624 |
+
if isexternal(var):
|
| 625 |
+
ret['vardebuginfo'] = 'debug-capi:%s=>%s:%s' % (
|
| 626 |
+
a, ret['cbname'], ','.join(rl))
|
| 627 |
+
else:
|
| 628 |
+
ret['vardebuginfo'] = 'debug-capi:%s %s=%s:%s' % (
|
| 629 |
+
ret['ctype'], a, ret['showinit'], ','.join(rl))
|
| 630 |
+
if isscalar(var):
|
| 631 |
+
if ret['ctype'] in cformat_map:
|
| 632 |
+
ret['vardebugshowvalue'] = 'debug-capi:%s=%s' % (
|
| 633 |
+
a, cformat_map[ret['ctype']])
|
| 634 |
+
if isstring(var):
|
| 635 |
+
ret['vardebugshowvalue'] = 'debug-capi:slen(%s)=%%d %s=\\"%%s\\"' % (
|
| 636 |
+
a, a)
|
| 637 |
+
if isexternal(var):
|
| 638 |
+
ret['vardebugshowvalue'] = 'debug-capi:%s=%%p' % (a)
|
| 639 |
+
if ret['ctype'] in cformat_map:
|
| 640 |
+
ret['varshowvalue'] = '#name#:%s=%s' % (a, cformat_map[ret['ctype']])
|
| 641 |
+
ret['showvalueformat'] = '%s' % (cformat_map[ret['ctype']])
|
| 642 |
+
if isstring(var):
|
| 643 |
+
ret['varshowvalue'] = '#name#:slen(%s)=%%d %s=\\"%%s\\"' % (a, a)
|
| 644 |
+
ret['pydocsign'], ret['pydocsignout'] = getpydocsign(a, var)
|
| 645 |
+
if hasnote(var):
|
| 646 |
+
ret['note'] = var['note']
|
| 647 |
+
return ret
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def routsign2map(rout):
|
| 651 |
+
"""
|
| 652 |
+
name,NAME,begintitle,endtitle
|
| 653 |
+
rname,ctype,rformat
|
| 654 |
+
routdebugshowvalue
|
| 655 |
+
"""
|
| 656 |
+
global lcb_map
|
| 657 |
+
name = rout['name']
|
| 658 |
+
fname = getfortranname(rout)
|
| 659 |
+
ret = {'name': name,
|
| 660 |
+
'texname': name.replace('_', '\\_'),
|
| 661 |
+
'name_lower': name.lower(),
|
| 662 |
+
'NAME': name.upper(),
|
| 663 |
+
'begintitle': gentitle(name),
|
| 664 |
+
'endtitle': gentitle('end of %s' % name),
|
| 665 |
+
'fortranname': fname,
|
| 666 |
+
'FORTRANNAME': fname.upper(),
|
| 667 |
+
'callstatement': getcallstatement(rout) or '',
|
| 668 |
+
'usercode': getusercode(rout) or '',
|
| 669 |
+
'usercode1': getusercode1(rout) or '',
|
| 670 |
+
}
|
| 671 |
+
if '_' in fname:
|
| 672 |
+
ret['F_FUNC'] = 'F_FUNC_US'
|
| 673 |
+
else:
|
| 674 |
+
ret['F_FUNC'] = 'F_FUNC'
|
| 675 |
+
if '_' in name:
|
| 676 |
+
ret['F_WRAPPEDFUNC'] = 'F_WRAPPEDFUNC_US'
|
| 677 |
+
else:
|
| 678 |
+
ret['F_WRAPPEDFUNC'] = 'F_WRAPPEDFUNC'
|
| 679 |
+
lcb_map = {}
|
| 680 |
+
if 'use' in rout:
|
| 681 |
+
for u in rout['use'].keys():
|
| 682 |
+
if u in cb_rules.cb_map:
|
| 683 |
+
for un in cb_rules.cb_map[u]:
|
| 684 |
+
ln = un[0]
|
| 685 |
+
if 'map' in rout['use'][u]:
|
| 686 |
+
for k in rout['use'][u]['map'].keys():
|
| 687 |
+
if rout['use'][u]['map'][k] == un[0]:
|
| 688 |
+
ln = k
|
| 689 |
+
break
|
| 690 |
+
lcb_map[ln] = un[1]
|
| 691 |
+
elif 'externals' in rout and rout['externals']:
|
| 692 |
+
errmess('routsign2map: Confused: function %s has externals %s but no "use" statement.\n' % (
|
| 693 |
+
ret['name'], repr(rout['externals'])))
|
| 694 |
+
ret['callprotoargument'] = getcallprotoargument(rout, lcb_map) or ''
|
| 695 |
+
if isfunction(rout):
|
| 696 |
+
if 'result' in rout:
|
| 697 |
+
a = rout['result']
|
| 698 |
+
else:
|
| 699 |
+
a = rout['name']
|
| 700 |
+
ret['rname'] = a
|
| 701 |
+
ret['pydocsign'], ret['pydocsignout'] = getpydocsign(a, rout)
|
| 702 |
+
ret['ctype'] = getctype(rout['vars'][a])
|
| 703 |
+
if hasresultnote(rout):
|
| 704 |
+
ret['resultnote'] = rout['vars'][a]['note']
|
| 705 |
+
rout['vars'][a]['note'] = ['See elsewhere.']
|
| 706 |
+
if ret['ctype'] in c2buildvalue_map:
|
| 707 |
+
ret['rformat'] = c2buildvalue_map[ret['ctype']]
|
| 708 |
+
else:
|
| 709 |
+
ret['rformat'] = 'O'
|
| 710 |
+
errmess('routsign2map: no c2buildvalue key for type %s\n' %
|
| 711 |
+
(repr(ret['ctype'])))
|
| 712 |
+
if debugcapi(rout):
|
| 713 |
+
if ret['ctype'] in cformat_map:
|
| 714 |
+
ret['routdebugshowvalue'] = 'debug-capi:%s=%s' % (
|
| 715 |
+
a, cformat_map[ret['ctype']])
|
| 716 |
+
if isstringfunction(rout):
|
| 717 |
+
ret['routdebugshowvalue'] = 'debug-capi:slen(%s)=%%d %s=\\"%%s\\"' % (
|
| 718 |
+
a, a)
|
| 719 |
+
if isstringfunction(rout):
|
| 720 |
+
ret['rlength'] = getstrlength(rout['vars'][a])
|
| 721 |
+
if ret['rlength'] == '-1':
|
| 722 |
+
errmess('routsign2map: expected explicit specification of the length of the string returned by the fortran function %s; taking 10.\n' % (
|
| 723 |
+
repr(rout['name'])))
|
| 724 |
+
ret['rlength'] = '10'
|
| 725 |
+
if hasnote(rout):
|
| 726 |
+
ret['note'] = rout['note']
|
| 727 |
+
rout['note'] = ['See elsewhere.']
|
| 728 |
+
return ret
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
def modsign2map(m):
|
| 732 |
+
"""
|
| 733 |
+
modulename
|
| 734 |
+
"""
|
| 735 |
+
if ismodule(m):
|
| 736 |
+
ret = {'f90modulename': m['name'],
|
| 737 |
+
'F90MODULENAME': m['name'].upper(),
|
| 738 |
+
'texf90modulename': m['name'].replace('_', '\\_')}
|
| 739 |
+
else:
|
| 740 |
+
ret = {'modulename': m['name'],
|
| 741 |
+
'MODULENAME': m['name'].upper(),
|
| 742 |
+
'texmodulename': m['name'].replace('_', '\\_')}
|
| 743 |
+
ret['restdoc'] = getrestdoc(m) or []
|
| 744 |
+
if hasnote(m):
|
| 745 |
+
ret['note'] = m['note']
|
| 746 |
+
ret['usercode'] = getusercode(m) or ''
|
| 747 |
+
ret['usercode1'] = getusercode1(m) or ''
|
| 748 |
+
if m['body']:
|
| 749 |
+
ret['interface_usercode'] = getusercode(m['body'][0]) or ''
|
| 750 |
+
else:
|
| 751 |
+
ret['interface_usercode'] = ''
|
| 752 |
+
ret['pymethoddef'] = getpymethoddef(m) or ''
|
| 753 |
+
if 'coutput' in m:
|
| 754 |
+
ret['coutput'] = m['coutput']
|
| 755 |
+
if 'f2py_wrapper_output' in m:
|
| 756 |
+
ret['f2py_wrapper_output'] = m['f2py_wrapper_output']
|
| 757 |
+
return ret
|
| 758 |
+
|
| 759 |
+
|
| 760 |
+
def cb_sign2map(a, var, index=None):
|
| 761 |
+
ret = {'varname': a}
|
| 762 |
+
ret['varname_i'] = ret['varname']
|
| 763 |
+
ret['ctype'] = getctype(var)
|
| 764 |
+
if ret['ctype'] in c2capi_map:
|
| 765 |
+
ret['atype'] = c2capi_map[ret['ctype']]
|
| 766 |
+
ret['elsize'] = get_elsize(var)
|
| 767 |
+
if ret['ctype'] in cformat_map:
|
| 768 |
+
ret['showvalueformat'] = '%s' % (cformat_map[ret['ctype']])
|
| 769 |
+
if isarray(var):
|
| 770 |
+
ret = dictappend(ret, getarrdims(a, var))
|
| 771 |
+
ret['pydocsign'], ret['pydocsignout'] = getpydocsign(a, var)
|
| 772 |
+
if hasnote(var):
|
| 773 |
+
ret['note'] = var['note']
|
| 774 |
+
var['note'] = ['See elsewhere.']
|
| 775 |
+
return ret
|
| 776 |
+
|
| 777 |
+
|
| 778 |
+
def cb_routsign2map(rout, um):
|
| 779 |
+
"""
|
| 780 |
+
name,begintitle,endtitle,argname
|
| 781 |
+
ctype,rctype,maxnofargs,nofoptargs,returncptr
|
| 782 |
+
"""
|
| 783 |
+
ret = {'name': 'cb_%s_in_%s' % (rout['name'], um),
|
| 784 |
+
'returncptr': ''}
|
| 785 |
+
if isintent_callback(rout):
|
| 786 |
+
if '_' in rout['name']:
|
| 787 |
+
F_FUNC = 'F_FUNC_US'
|
| 788 |
+
else:
|
| 789 |
+
F_FUNC = 'F_FUNC'
|
| 790 |
+
ret['callbackname'] = '%s(%s,%s)' \
|
| 791 |
+
% (F_FUNC,
|
| 792 |
+
rout['name'].lower(),
|
| 793 |
+
rout['name'].upper(),
|
| 794 |
+
)
|
| 795 |
+
ret['static'] = 'extern'
|
| 796 |
+
else:
|
| 797 |
+
ret['callbackname'] = ret['name']
|
| 798 |
+
ret['static'] = 'static'
|
| 799 |
+
ret['argname'] = rout['name']
|
| 800 |
+
ret['begintitle'] = gentitle(ret['name'])
|
| 801 |
+
ret['endtitle'] = gentitle('end of %s' % ret['name'])
|
| 802 |
+
ret['ctype'] = getctype(rout)
|
| 803 |
+
ret['rctype'] = 'void'
|
| 804 |
+
if ret['ctype'] == 'string':
|
| 805 |
+
ret['rctype'] = 'void'
|
| 806 |
+
else:
|
| 807 |
+
ret['rctype'] = ret['ctype']
|
| 808 |
+
if ret['rctype'] != 'void':
|
| 809 |
+
if iscomplexfunction(rout):
|
| 810 |
+
ret['returncptr'] = """
|
| 811 |
+
#ifdef F2PY_CB_RETURNCOMPLEX
|
| 812 |
+
return_value=
|
| 813 |
+
#endif
|
| 814 |
+
"""
|
| 815 |
+
else:
|
| 816 |
+
ret['returncptr'] = 'return_value='
|
| 817 |
+
if ret['ctype'] in cformat_map:
|
| 818 |
+
ret['showvalueformat'] = '%s' % (cformat_map[ret['ctype']])
|
| 819 |
+
if isstringfunction(rout):
|
| 820 |
+
ret['strlength'] = getstrlength(rout)
|
| 821 |
+
if isfunction(rout):
|
| 822 |
+
if 'result' in rout:
|
| 823 |
+
a = rout['result']
|
| 824 |
+
else:
|
| 825 |
+
a = rout['name']
|
| 826 |
+
if hasnote(rout['vars'][a]):
|
| 827 |
+
ret['note'] = rout['vars'][a]['note']
|
| 828 |
+
rout['vars'][a]['note'] = ['See elsewhere.']
|
| 829 |
+
ret['rname'] = a
|
| 830 |
+
ret['pydocsign'], ret['pydocsignout'] = getpydocsign(a, rout)
|
| 831 |
+
if iscomplexfunction(rout):
|
| 832 |
+
ret['rctype'] = """
|
| 833 |
+
#ifdef F2PY_CB_RETURNCOMPLEX
|
| 834 |
+
#ctype#
|
| 835 |
+
#else
|
| 836 |
+
void
|
| 837 |
+
#endif
|
| 838 |
+
"""
|
| 839 |
+
else:
|
| 840 |
+
if hasnote(rout):
|
| 841 |
+
ret['note'] = rout['note']
|
| 842 |
+
rout['note'] = ['See elsewhere.']
|
| 843 |
+
nofargs = 0
|
| 844 |
+
nofoptargs = 0
|
| 845 |
+
if 'args' in rout and 'vars' in rout:
|
| 846 |
+
for a in rout['args']:
|
| 847 |
+
var = rout['vars'][a]
|
| 848 |
+
if l_or(isintent_in, isintent_inout)(var):
|
| 849 |
+
nofargs = nofargs + 1
|
| 850 |
+
if isoptional(var):
|
| 851 |
+
nofoptargs = nofoptargs + 1
|
| 852 |
+
ret['maxnofargs'] = repr(nofargs)
|
| 853 |
+
ret['nofoptargs'] = repr(nofoptargs)
|
| 854 |
+
if hasnote(rout) and isfunction(rout) and 'result' in rout:
|
| 855 |
+
ret['routnote'] = rout['note']
|
| 856 |
+
rout['note'] = ['See elsewhere.']
|
| 857 |
+
return ret
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
def common_sign2map(a, var): # obsolute
|
| 861 |
+
ret = {'varname': a, 'ctype': getctype(var)}
|
| 862 |
+
if isstringarray(var):
|
| 863 |
+
ret['ctype'] = 'char'
|
| 864 |
+
if ret['ctype'] in c2capi_map:
|
| 865 |
+
ret['atype'] = c2capi_map[ret['ctype']]
|
| 866 |
+
ret['elsize'] = get_elsize(var)
|
| 867 |
+
if ret['ctype'] in cformat_map:
|
| 868 |
+
ret['showvalueformat'] = '%s' % (cformat_map[ret['ctype']])
|
| 869 |
+
if isarray(var):
|
| 870 |
+
ret = dictappend(ret, getarrdims(a, var))
|
| 871 |
+
elif isstring(var):
|
| 872 |
+
ret['size'] = getstrlength(var)
|
| 873 |
+
ret['rank'] = '1'
|
| 874 |
+
ret['pydocsign'], ret['pydocsignout'] = getpydocsign(a, var)
|
| 875 |
+
if hasnote(var):
|
| 876 |
+
ret['note'] = var['note']
|
| 877 |
+
var['note'] = ['See elsewhere.']
|
| 878 |
+
# for strings this returns 0-rank but actually is 1-rank
|
| 879 |
+
ret['arrdocstr'] = getarrdocsign(a, var)
|
| 880 |
+
return ret
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/cb_rules.py
ADDED
|
@@ -0,0 +1,649 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Build call-back mechanism for f2py2e.
|
| 5 |
+
|
| 6 |
+
Copyright 2000 Pearu Peterson all rights reserved,
|
| 7 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 8 |
+
Permission to use, modify, and distribute this software is given under the
|
| 9 |
+
terms of the NumPy License.
|
| 10 |
+
|
| 11 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 12 |
+
$Date: 2005/07/20 11:27:58 $
|
| 13 |
+
Pearu Peterson
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
+
from . import __version__
|
| 17 |
+
from .auxfuncs import (
|
| 18 |
+
applyrules, debugcapi, dictappend, errmess, getargs, hasnote, isarray,
|
| 19 |
+
iscomplex, iscomplexarray, iscomplexfunction, isfunction, isintent_c,
|
| 20 |
+
isintent_hide, isintent_in, isintent_inout, isintent_nothide,
|
| 21 |
+
isintent_out, isoptional, isrequired, isscalar, isstring,
|
| 22 |
+
isstringfunction, issubroutine, l_and, l_not, l_or, outmess, replace,
|
| 23 |
+
stripcomma, throw_error
|
| 24 |
+
)
|
| 25 |
+
from . import cfuncs
|
| 26 |
+
|
| 27 |
+
f2py_version = __version__.version
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
################## Rules for callback function ##############
|
| 31 |
+
|
| 32 |
+
cb_routine_rules = {
|
| 33 |
+
'cbtypedefs': 'typedef #rctype#(*#name#_typedef)(#optargs_td##args_td##strarglens_td##noargs#);',
|
| 34 |
+
'body': """
|
| 35 |
+
#begintitle#
|
| 36 |
+
typedef struct {
|
| 37 |
+
PyObject *capi;
|
| 38 |
+
PyTupleObject *args_capi;
|
| 39 |
+
int nofargs;
|
| 40 |
+
jmp_buf jmpbuf;
|
| 41 |
+
} #name#_t;
|
| 42 |
+
|
| 43 |
+
#if defined(F2PY_THREAD_LOCAL_DECL) && !defined(F2PY_USE_PYTHON_TLS)
|
| 44 |
+
|
| 45 |
+
static F2PY_THREAD_LOCAL_DECL #name#_t *_active_#name# = NULL;
|
| 46 |
+
|
| 47 |
+
static #name#_t *swap_active_#name#(#name#_t *ptr) {
|
| 48 |
+
#name#_t *prev = _active_#name#;
|
| 49 |
+
_active_#name# = ptr;
|
| 50 |
+
return prev;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
static #name#_t *get_active_#name#(void) {
|
| 54 |
+
return _active_#name#;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
#else
|
| 58 |
+
|
| 59 |
+
static #name#_t *swap_active_#name#(#name#_t *ptr) {
|
| 60 |
+
char *key = "__f2py_cb_#name#";
|
| 61 |
+
return (#name#_t *)F2PySwapThreadLocalCallbackPtr(key, ptr);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
static #name#_t *get_active_#name#(void) {
|
| 65 |
+
char *key = "__f2py_cb_#name#";
|
| 66 |
+
return (#name#_t *)F2PyGetThreadLocalCallbackPtr(key);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
#endif
|
| 70 |
+
|
| 71 |
+
/*typedef #rctype#(*#name#_typedef)(#optargs_td##args_td##strarglens_td##noargs#);*/
|
| 72 |
+
#static# #rctype# #callbackname# (#optargs##args##strarglens##noargs#) {
|
| 73 |
+
#name#_t cb_local = { NULL, NULL, 0 };
|
| 74 |
+
#name#_t *cb = NULL;
|
| 75 |
+
PyTupleObject *capi_arglist = NULL;
|
| 76 |
+
PyObject *capi_return = NULL;
|
| 77 |
+
PyObject *capi_tmp = NULL;
|
| 78 |
+
PyObject *capi_arglist_list = NULL;
|
| 79 |
+
int capi_j,capi_i = 0;
|
| 80 |
+
int capi_longjmp_ok = 1;
|
| 81 |
+
#decl#
|
| 82 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 83 |
+
f2py_cb_start_clock();
|
| 84 |
+
#endif
|
| 85 |
+
cb = get_active_#name#();
|
| 86 |
+
if (cb == NULL) {
|
| 87 |
+
capi_longjmp_ok = 0;
|
| 88 |
+
cb = &cb_local;
|
| 89 |
+
}
|
| 90 |
+
capi_arglist = cb->args_capi;
|
| 91 |
+
CFUNCSMESS(\"cb:Call-back function #name# (maxnofargs=#maxnofargs#(-#nofoptargs#))\\n\");
|
| 92 |
+
CFUNCSMESSPY(\"cb:#name#_capi=\",cb->capi);
|
| 93 |
+
if (cb->capi==NULL) {
|
| 94 |
+
capi_longjmp_ok = 0;
|
| 95 |
+
cb->capi = PyObject_GetAttrString(#modulename#_module,\"#argname#\");
|
| 96 |
+
CFUNCSMESSPY(\"cb:#name#_capi=\",cb->capi);
|
| 97 |
+
}
|
| 98 |
+
if (cb->capi==NULL) {
|
| 99 |
+
PyErr_SetString(#modulename#_error,\"cb: Callback #argname# not defined (as an argument or module #modulename# attribute).\\n\");
|
| 100 |
+
goto capi_fail;
|
| 101 |
+
}
|
| 102 |
+
if (F2PyCapsule_Check(cb->capi)) {
|
| 103 |
+
#name#_typedef #name#_cptr;
|
| 104 |
+
#name#_cptr = F2PyCapsule_AsVoidPtr(cb->capi);
|
| 105 |
+
#returncptr#(*#name#_cptr)(#optargs_nm##args_nm##strarglens_nm#);
|
| 106 |
+
#return#
|
| 107 |
+
}
|
| 108 |
+
if (capi_arglist==NULL) {
|
| 109 |
+
capi_longjmp_ok = 0;
|
| 110 |
+
capi_tmp = PyObject_GetAttrString(#modulename#_module,\"#argname#_extra_args\");
|
| 111 |
+
if (capi_tmp) {
|
| 112 |
+
capi_arglist = (PyTupleObject *)PySequence_Tuple(capi_tmp);
|
| 113 |
+
Py_DECREF(capi_tmp);
|
| 114 |
+
if (capi_arglist==NULL) {
|
| 115 |
+
PyErr_SetString(#modulename#_error,\"Failed to convert #modulename#.#argname#_extra_args to tuple.\\n\");
|
| 116 |
+
goto capi_fail;
|
| 117 |
+
}
|
| 118 |
+
} else {
|
| 119 |
+
PyErr_Clear();
|
| 120 |
+
capi_arglist = (PyTupleObject *)Py_BuildValue(\"()\");
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
if (capi_arglist == NULL) {
|
| 124 |
+
PyErr_SetString(#modulename#_error,\"Callback #argname# argument list is not set.\\n\");
|
| 125 |
+
goto capi_fail;
|
| 126 |
+
}
|
| 127 |
+
#setdims#
|
| 128 |
+
#ifdef PYPY_VERSION
|
| 129 |
+
#define CAPI_ARGLIST_SETITEM(idx, value) PyList_SetItem((PyObject *)capi_arglist_list, idx, value)
|
| 130 |
+
capi_arglist_list = PySequence_List(capi_arglist);
|
| 131 |
+
if (capi_arglist_list == NULL) goto capi_fail;
|
| 132 |
+
#else
|
| 133 |
+
#define CAPI_ARGLIST_SETITEM(idx, value) PyTuple_SetItem((PyObject *)capi_arglist, idx, value)
|
| 134 |
+
#endif
|
| 135 |
+
#pyobjfrom#
|
| 136 |
+
#undef CAPI_ARGLIST_SETITEM
|
| 137 |
+
#ifdef PYPY_VERSION
|
| 138 |
+
CFUNCSMESSPY(\"cb:capi_arglist=\",capi_arglist_list);
|
| 139 |
+
#else
|
| 140 |
+
CFUNCSMESSPY(\"cb:capi_arglist=\",capi_arglist);
|
| 141 |
+
#endif
|
| 142 |
+
CFUNCSMESS(\"cb:Call-back calling Python function #argname#.\\n\");
|
| 143 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 144 |
+
f2py_cb_start_call_clock();
|
| 145 |
+
#endif
|
| 146 |
+
#ifdef PYPY_VERSION
|
| 147 |
+
capi_return = PyObject_CallObject(cb->capi,(PyObject *)capi_arglist_list);
|
| 148 |
+
Py_DECREF(capi_arglist_list);
|
| 149 |
+
capi_arglist_list = NULL;
|
| 150 |
+
#else
|
| 151 |
+
capi_return = PyObject_CallObject(cb->capi,(PyObject *)capi_arglist);
|
| 152 |
+
#endif
|
| 153 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 154 |
+
f2py_cb_stop_call_clock();
|
| 155 |
+
#endif
|
| 156 |
+
CFUNCSMESSPY(\"cb:capi_return=\",capi_return);
|
| 157 |
+
if (capi_return == NULL) {
|
| 158 |
+
fprintf(stderr,\"capi_return is NULL\\n\");
|
| 159 |
+
goto capi_fail;
|
| 160 |
+
}
|
| 161 |
+
if (capi_return == Py_None) {
|
| 162 |
+
Py_DECREF(capi_return);
|
| 163 |
+
capi_return = Py_BuildValue(\"()\");
|
| 164 |
+
}
|
| 165 |
+
else if (!PyTuple_Check(capi_return)) {
|
| 166 |
+
capi_return = Py_BuildValue(\"(N)\",capi_return);
|
| 167 |
+
}
|
| 168 |
+
capi_j = PyTuple_Size(capi_return);
|
| 169 |
+
capi_i = 0;
|
| 170 |
+
#frompyobj#
|
| 171 |
+
CFUNCSMESS(\"cb:#name#:successful\\n\");
|
| 172 |
+
Py_DECREF(capi_return);
|
| 173 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 174 |
+
f2py_cb_stop_clock();
|
| 175 |
+
#endif
|
| 176 |
+
goto capi_return_pt;
|
| 177 |
+
capi_fail:
|
| 178 |
+
fprintf(stderr,\"Call-back #name# failed.\\n\");
|
| 179 |
+
Py_XDECREF(capi_return);
|
| 180 |
+
Py_XDECREF(capi_arglist_list);
|
| 181 |
+
if (capi_longjmp_ok) {
|
| 182 |
+
longjmp(cb->jmpbuf,-1);
|
| 183 |
+
}
|
| 184 |
+
capi_return_pt:
|
| 185 |
+
;
|
| 186 |
+
#return#
|
| 187 |
+
}
|
| 188 |
+
#endtitle#
|
| 189 |
+
""",
|
| 190 |
+
'need': ['setjmp.h', 'CFUNCSMESS', 'F2PY_THREAD_LOCAL_DECL'],
|
| 191 |
+
'maxnofargs': '#maxnofargs#',
|
| 192 |
+
'nofoptargs': '#nofoptargs#',
|
| 193 |
+
'docstr': """\
|
| 194 |
+
def #argname#(#docsignature#): return #docreturn#\\n\\
|
| 195 |
+
#docstrsigns#""",
|
| 196 |
+
'latexdocstr': """
|
| 197 |
+
{{}\\verb@def #argname#(#latexdocsignature#): return #docreturn#@{}}
|
| 198 |
+
#routnote#
|
| 199 |
+
|
| 200 |
+
#latexdocstrsigns#""",
|
| 201 |
+
'docstrshort': 'def #argname#(#docsignature#): return #docreturn#'
|
| 202 |
+
}
|
| 203 |
+
cb_rout_rules = [
|
| 204 |
+
{ # Init
|
| 205 |
+
'separatorsfor': {'decl': '\n',
|
| 206 |
+
'args': ',', 'optargs': '', 'pyobjfrom': '\n', 'freemem': '\n',
|
| 207 |
+
'args_td': ',', 'optargs_td': '',
|
| 208 |
+
'args_nm': ',', 'optargs_nm': '',
|
| 209 |
+
'frompyobj': '\n', 'setdims': '\n',
|
| 210 |
+
'docstrsigns': '\\n"\n"',
|
| 211 |
+
'latexdocstrsigns': '\n',
|
| 212 |
+
'latexdocstrreq': '\n', 'latexdocstropt': '\n',
|
| 213 |
+
'latexdocstrout': '\n', 'latexdocstrcbs': '\n',
|
| 214 |
+
},
|
| 215 |
+
'decl': '/*decl*/', 'pyobjfrom': '/*pyobjfrom*/', 'frompyobj': '/*frompyobj*/',
|
| 216 |
+
'args': [], 'optargs': '', 'return': '', 'strarglens': '', 'freemem': '/*freemem*/',
|
| 217 |
+
'args_td': [], 'optargs_td': '', 'strarglens_td': '',
|
| 218 |
+
'args_nm': [], 'optargs_nm': '', 'strarglens_nm': '',
|
| 219 |
+
'noargs': '',
|
| 220 |
+
'setdims': '/*setdims*/',
|
| 221 |
+
'docstrsigns': '', 'latexdocstrsigns': '',
|
| 222 |
+
'docstrreq': ' Required arguments:',
|
| 223 |
+
'docstropt': ' Optional arguments:',
|
| 224 |
+
'docstrout': ' Return objects:',
|
| 225 |
+
'docstrcbs': ' Call-back functions:',
|
| 226 |
+
'docreturn': '', 'docsign': '', 'docsignopt': '',
|
| 227 |
+
'latexdocstrreq': '\\noindent Required arguments:',
|
| 228 |
+
'latexdocstropt': '\\noindent Optional arguments:',
|
| 229 |
+
'latexdocstrout': '\\noindent Return objects:',
|
| 230 |
+
'latexdocstrcbs': '\\noindent Call-back functions:',
|
| 231 |
+
'routnote': {hasnote: '--- #note#', l_not(hasnote): ''},
|
| 232 |
+
}, { # Function
|
| 233 |
+
'decl': ' #ctype# return_value = 0;',
|
| 234 |
+
'frompyobj': [
|
| 235 |
+
{debugcapi: ' CFUNCSMESS("cb:Getting return_value->");'},
|
| 236 |
+
'''\
|
| 237 |
+
if (capi_j>capi_i) {
|
| 238 |
+
GETSCALARFROMPYTUPLE(capi_return,capi_i++,&return_value,#ctype#,
|
| 239 |
+
"#ctype#_from_pyobj failed in converting return_value of"
|
| 240 |
+
" call-back function #name# to C #ctype#\\n");
|
| 241 |
+
} else {
|
| 242 |
+
fprintf(stderr,"Warning: call-back function #name# did not provide"
|
| 243 |
+
" return value (index=%d, type=#ctype#)\\n",capi_i);
|
| 244 |
+
}''',
|
| 245 |
+
{debugcapi:
|
| 246 |
+
' fprintf(stderr,"#showvalueformat#.\\n",return_value);'}
|
| 247 |
+
],
|
| 248 |
+
'need': ['#ctype#_from_pyobj', {debugcapi: 'CFUNCSMESS'}, 'GETSCALARFROMPYTUPLE'],
|
| 249 |
+
'return': ' return return_value;',
|
| 250 |
+
'_check': l_and(isfunction, l_not(isstringfunction), l_not(iscomplexfunction))
|
| 251 |
+
},
|
| 252 |
+
{ # String function
|
| 253 |
+
'pyobjfrom': {debugcapi: ' fprintf(stderr,"debug-capi:cb:#name#:%d:\\n",return_value_len);'},
|
| 254 |
+
'args': '#ctype# return_value,int return_value_len',
|
| 255 |
+
'args_nm': 'return_value,&return_value_len',
|
| 256 |
+
'args_td': '#ctype# ,int',
|
| 257 |
+
'frompyobj': [
|
| 258 |
+
{debugcapi: ' CFUNCSMESS("cb:Getting return_value->\\"");'},
|
| 259 |
+
"""\
|
| 260 |
+
if (capi_j>capi_i) {
|
| 261 |
+
GETSTRFROMPYTUPLE(capi_return,capi_i++,return_value,return_value_len);
|
| 262 |
+
} else {
|
| 263 |
+
fprintf(stderr,"Warning: call-back function #name# did not provide"
|
| 264 |
+
" return value (index=%d, type=#ctype#)\\n",capi_i);
|
| 265 |
+
}""",
|
| 266 |
+
{debugcapi:
|
| 267 |
+
' fprintf(stderr,"#showvalueformat#\\".\\n",return_value);'}
|
| 268 |
+
],
|
| 269 |
+
'need': ['#ctype#_from_pyobj', {debugcapi: 'CFUNCSMESS'},
|
| 270 |
+
'string.h', 'GETSTRFROMPYTUPLE'],
|
| 271 |
+
'return': 'return;',
|
| 272 |
+
'_check': isstringfunction
|
| 273 |
+
},
|
| 274 |
+
{ # Complex function
|
| 275 |
+
'optargs': """
|
| 276 |
+
#ifndef F2PY_CB_RETURNCOMPLEX
|
| 277 |
+
#ctype# *return_value
|
| 278 |
+
#endif
|
| 279 |
+
""",
|
| 280 |
+
'optargs_nm': """
|
| 281 |
+
#ifndef F2PY_CB_RETURNCOMPLEX
|
| 282 |
+
return_value
|
| 283 |
+
#endif
|
| 284 |
+
""",
|
| 285 |
+
'optargs_td': """
|
| 286 |
+
#ifndef F2PY_CB_RETURNCOMPLEX
|
| 287 |
+
#ctype# *
|
| 288 |
+
#endif
|
| 289 |
+
""",
|
| 290 |
+
'decl': """
|
| 291 |
+
#ifdef F2PY_CB_RETURNCOMPLEX
|
| 292 |
+
#ctype# return_value = {0, 0};
|
| 293 |
+
#endif
|
| 294 |
+
""",
|
| 295 |
+
'frompyobj': [
|
| 296 |
+
{debugcapi: ' CFUNCSMESS("cb:Getting return_value->");'},
|
| 297 |
+
"""\
|
| 298 |
+
if (capi_j>capi_i) {
|
| 299 |
+
#ifdef F2PY_CB_RETURNCOMPLEX
|
| 300 |
+
GETSCALARFROMPYTUPLE(capi_return,capi_i++,&return_value,#ctype#,
|
| 301 |
+
\"#ctype#_from_pyobj failed in converting return_value of call-back\"
|
| 302 |
+
\" function #name# to C #ctype#\\n\");
|
| 303 |
+
#else
|
| 304 |
+
GETSCALARFROMPYTUPLE(capi_return,capi_i++,return_value,#ctype#,
|
| 305 |
+
\"#ctype#_from_pyobj failed in converting return_value of call-back\"
|
| 306 |
+
\" function #name# to C #ctype#\\n\");
|
| 307 |
+
#endif
|
| 308 |
+
} else {
|
| 309 |
+
fprintf(stderr,
|
| 310 |
+
\"Warning: call-back function #name# did not provide\"
|
| 311 |
+
\" return value (index=%d, type=#ctype#)\\n\",capi_i);
|
| 312 |
+
}""",
|
| 313 |
+
{debugcapi: """\
|
| 314 |
+
#ifdef F2PY_CB_RETURNCOMPLEX
|
| 315 |
+
fprintf(stderr,\"#showvalueformat#.\\n\",(return_value).r,(return_value).i);
|
| 316 |
+
#else
|
| 317 |
+
fprintf(stderr,\"#showvalueformat#.\\n\",(*return_value).r,(*return_value).i);
|
| 318 |
+
#endif
|
| 319 |
+
"""}
|
| 320 |
+
],
|
| 321 |
+
'return': """
|
| 322 |
+
#ifdef F2PY_CB_RETURNCOMPLEX
|
| 323 |
+
return return_value;
|
| 324 |
+
#else
|
| 325 |
+
return;
|
| 326 |
+
#endif
|
| 327 |
+
""",
|
| 328 |
+
'need': ['#ctype#_from_pyobj', {debugcapi: 'CFUNCSMESS'},
|
| 329 |
+
'string.h', 'GETSCALARFROMPYTUPLE', '#ctype#'],
|
| 330 |
+
'_check': iscomplexfunction
|
| 331 |
+
},
|
| 332 |
+
{'docstrout': ' #pydocsignout#',
|
| 333 |
+
'latexdocstrout': ['\\item[]{{}\\verb@#pydocsignout#@{}}',
|
| 334 |
+
{hasnote: '--- #note#'}],
|
| 335 |
+
'docreturn': '#rname#,',
|
| 336 |
+
'_check': isfunction},
|
| 337 |
+
{'_check': issubroutine, 'return': 'return;'}
|
| 338 |
+
]
|
| 339 |
+
|
| 340 |
+
cb_arg_rules = [
|
| 341 |
+
{ # Doc
|
| 342 |
+
'docstropt': {l_and(isoptional, isintent_nothide): ' #pydocsign#'},
|
| 343 |
+
'docstrreq': {l_and(isrequired, isintent_nothide): ' #pydocsign#'},
|
| 344 |
+
'docstrout': {isintent_out: ' #pydocsignout#'},
|
| 345 |
+
'latexdocstropt': {l_and(isoptional, isintent_nothide): ['\\item[]{{}\\verb@#pydocsign#@{}}',
|
| 346 |
+
{hasnote: '--- #note#'}]},
|
| 347 |
+
'latexdocstrreq': {l_and(isrequired, isintent_nothide): ['\\item[]{{}\\verb@#pydocsign#@{}}',
|
| 348 |
+
{hasnote: '--- #note#'}]},
|
| 349 |
+
'latexdocstrout': {isintent_out: ['\\item[]{{}\\verb@#pydocsignout#@{}}',
|
| 350 |
+
{l_and(hasnote, isintent_hide): '--- #note#',
|
| 351 |
+
l_and(hasnote, isintent_nothide): '--- See above.'}]},
|
| 352 |
+
'docsign': {l_and(isrequired, isintent_nothide): '#varname#,'},
|
| 353 |
+
'docsignopt': {l_and(isoptional, isintent_nothide): '#varname#,'},
|
| 354 |
+
'depend': ''
|
| 355 |
+
},
|
| 356 |
+
{
|
| 357 |
+
'args': {
|
| 358 |
+
l_and(isscalar, isintent_c): '#ctype# #varname_i#',
|
| 359 |
+
l_and(isscalar, l_not(isintent_c)): '#ctype# *#varname_i#_cb_capi',
|
| 360 |
+
isarray: '#ctype# *#varname_i#',
|
| 361 |
+
isstring: '#ctype# #varname_i#'
|
| 362 |
+
},
|
| 363 |
+
'args_nm': {
|
| 364 |
+
l_and(isscalar, isintent_c): '#varname_i#',
|
| 365 |
+
l_and(isscalar, l_not(isintent_c)): '#varname_i#_cb_capi',
|
| 366 |
+
isarray: '#varname_i#',
|
| 367 |
+
isstring: '#varname_i#'
|
| 368 |
+
},
|
| 369 |
+
'args_td': {
|
| 370 |
+
l_and(isscalar, isintent_c): '#ctype#',
|
| 371 |
+
l_and(isscalar, l_not(isintent_c)): '#ctype# *',
|
| 372 |
+
isarray: '#ctype# *',
|
| 373 |
+
isstring: '#ctype#'
|
| 374 |
+
},
|
| 375 |
+
'need': {l_or(isscalar, isarray, isstring): '#ctype#'},
|
| 376 |
+
# untested with multiple args
|
| 377 |
+
'strarglens': {isstring: ',int #varname_i#_cb_len'},
|
| 378 |
+
'strarglens_td': {isstring: ',int'}, # untested with multiple args
|
| 379 |
+
# untested with multiple args
|
| 380 |
+
'strarglens_nm': {isstring: ',#varname_i#_cb_len'},
|
| 381 |
+
},
|
| 382 |
+
{ # Scalars
|
| 383 |
+
'decl': {l_not(isintent_c): ' #ctype# #varname_i#=(*#varname_i#_cb_capi);'},
|
| 384 |
+
'error': {l_and(isintent_c, isintent_out,
|
| 385 |
+
throw_error('intent(c,out) is forbidden for callback scalar arguments')):
|
| 386 |
+
''},
|
| 387 |
+
'frompyobj': [{debugcapi: ' CFUNCSMESS("cb:Getting #varname#->");'},
|
| 388 |
+
{isintent_out:
|
| 389 |
+
' if (capi_j>capi_i)\n GETSCALARFROMPYTUPLE(capi_return,capi_i++,#varname_i#_cb_capi,#ctype#,"#ctype#_from_pyobj failed in converting argument #varname# of call-back function #name# to C #ctype#\\n");'},
|
| 390 |
+
{l_and(debugcapi, l_and(l_not(iscomplex), isintent_c)):
|
| 391 |
+
' fprintf(stderr,"#showvalueformat#.\\n",#varname_i#);'},
|
| 392 |
+
{l_and(debugcapi, l_and(l_not(iscomplex), l_not( isintent_c))):
|
| 393 |
+
' fprintf(stderr,"#showvalueformat#.\\n",*#varname_i#_cb_capi);'},
|
| 394 |
+
{l_and(debugcapi, l_and(iscomplex, isintent_c)):
|
| 395 |
+
' fprintf(stderr,"#showvalueformat#.\\n",(#varname_i#).r,(#varname_i#).i);'},
|
| 396 |
+
{l_and(debugcapi, l_and(iscomplex, l_not( isintent_c))):
|
| 397 |
+
' fprintf(stderr,"#showvalueformat#.\\n",(*#varname_i#_cb_capi).r,(*#varname_i#_cb_capi).i);'},
|
| 398 |
+
],
|
| 399 |
+
'need': [{isintent_out: ['#ctype#_from_pyobj', 'GETSCALARFROMPYTUPLE']},
|
| 400 |
+
{debugcapi: 'CFUNCSMESS'}],
|
| 401 |
+
'_check': isscalar
|
| 402 |
+
}, {
|
| 403 |
+
'pyobjfrom': [{isintent_in: """\
|
| 404 |
+
if (cb->nofargs>capi_i)
|
| 405 |
+
if (CAPI_ARGLIST_SETITEM(capi_i++,pyobj_from_#ctype#1(#varname_i#)))
|
| 406 |
+
goto capi_fail;"""},
|
| 407 |
+
{isintent_inout: """\
|
| 408 |
+
if (cb->nofargs>capi_i)
|
| 409 |
+
if (CAPI_ARGLIST_SETITEM(capi_i++,pyarr_from_p_#ctype#1(#varname_i#_cb_capi)))
|
| 410 |
+
goto capi_fail;"""}],
|
| 411 |
+
'need': [{isintent_in: 'pyobj_from_#ctype#1'},
|
| 412 |
+
{isintent_inout: 'pyarr_from_p_#ctype#1'},
|
| 413 |
+
{iscomplex: '#ctype#'}],
|
| 414 |
+
'_check': l_and(isscalar, isintent_nothide),
|
| 415 |
+
'_optional': ''
|
| 416 |
+
}, { # String
|
| 417 |
+
'frompyobj': [{debugcapi: ' CFUNCSMESS("cb:Getting #varname#->\\"");'},
|
| 418 |
+
""" if (capi_j>capi_i)
|
| 419 |
+
GETSTRFROMPYTUPLE(capi_return,capi_i++,#varname_i#,#varname_i#_cb_len);""",
|
| 420 |
+
{debugcapi:
|
| 421 |
+
' fprintf(stderr,"#showvalueformat#\\":%d:.\\n",#varname_i#,#varname_i#_cb_len);'},
|
| 422 |
+
],
|
| 423 |
+
'need': ['#ctype#', 'GETSTRFROMPYTUPLE',
|
| 424 |
+
{debugcapi: 'CFUNCSMESS'}, 'string.h'],
|
| 425 |
+
'_check': l_and(isstring, isintent_out)
|
| 426 |
+
}, {
|
| 427 |
+
'pyobjfrom': [
|
| 428 |
+
{debugcapi:
|
| 429 |
+
(' fprintf(stderr,"debug-capi:cb:#varname#=#showvalueformat#:'
|
| 430 |
+
'%d:\\n",#varname_i#,#varname_i#_cb_len);')},
|
| 431 |
+
{isintent_in: """\
|
| 432 |
+
if (cb->nofargs>capi_i)
|
| 433 |
+
if (CAPI_ARGLIST_SETITEM(capi_i++,pyobj_from_#ctype#1size(#varname_i#,#varname_i#_cb_len)))
|
| 434 |
+
goto capi_fail;"""},
|
| 435 |
+
{isintent_inout: """\
|
| 436 |
+
if (cb->nofargs>capi_i) {
|
| 437 |
+
int #varname_i#_cb_dims[] = {#varname_i#_cb_len};
|
| 438 |
+
if (CAPI_ARGLIST_SETITEM(capi_i++,pyarr_from_p_#ctype#1(#varname_i#,#varname_i#_cb_dims)))
|
| 439 |
+
goto capi_fail;
|
| 440 |
+
}"""}],
|
| 441 |
+
'need': [{isintent_in: 'pyobj_from_#ctype#1size'},
|
| 442 |
+
{isintent_inout: 'pyarr_from_p_#ctype#1'}],
|
| 443 |
+
'_check': l_and(isstring, isintent_nothide),
|
| 444 |
+
'_optional': ''
|
| 445 |
+
},
|
| 446 |
+
# Array ...
|
| 447 |
+
{
|
| 448 |
+
'decl': ' npy_intp #varname_i#_Dims[#rank#] = {#rank*[-1]#};',
|
| 449 |
+
'setdims': ' #cbsetdims#;',
|
| 450 |
+
'_check': isarray,
|
| 451 |
+
'_depend': ''
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
'pyobjfrom': [{debugcapi: ' fprintf(stderr,"debug-capi:cb:#varname#\\n");'},
|
| 455 |
+
{isintent_c: """\
|
| 456 |
+
if (cb->nofargs>capi_i) {
|
| 457 |
+
/* tmp_arr will be inserted to capi_arglist_list that will be
|
| 458 |
+
destroyed when leaving callback function wrapper together
|
| 459 |
+
with tmp_arr. */
|
| 460 |
+
PyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,
|
| 461 |
+
#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,#elsize#,
|
| 462 |
+
NPY_ARRAY_CARRAY,NULL);
|
| 463 |
+
""",
|
| 464 |
+
l_not(isintent_c): """\
|
| 465 |
+
if (cb->nofargs>capi_i) {
|
| 466 |
+
/* tmp_arr will be inserted to capi_arglist_list that will be
|
| 467 |
+
destroyed when leaving callback function wrapper together
|
| 468 |
+
with tmp_arr. */
|
| 469 |
+
PyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,
|
| 470 |
+
#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,#elsize#,
|
| 471 |
+
NPY_ARRAY_FARRAY,NULL);
|
| 472 |
+
""",
|
| 473 |
+
},
|
| 474 |
+
"""
|
| 475 |
+
if (tmp_arr==NULL)
|
| 476 |
+
goto capi_fail;
|
| 477 |
+
if (CAPI_ARGLIST_SETITEM(capi_i++,(PyObject *)tmp_arr))
|
| 478 |
+
goto capi_fail;
|
| 479 |
+
}"""],
|
| 480 |
+
'_check': l_and(isarray, isintent_nothide, l_or(isintent_in, isintent_inout)),
|
| 481 |
+
'_optional': '',
|
| 482 |
+
}, {
|
| 483 |
+
'frompyobj': [{debugcapi: ' CFUNCSMESS("cb:Getting #varname#->");'},
|
| 484 |
+
""" if (capi_j>capi_i) {
|
| 485 |
+
PyArrayObject *rv_cb_arr = NULL;
|
| 486 |
+
if ((capi_tmp = PyTuple_GetItem(capi_return,capi_i++))==NULL) goto capi_fail;
|
| 487 |
+
rv_cb_arr = array_from_pyobj(#atype#,#varname_i#_Dims,#rank#,F2PY_INTENT_IN""",
|
| 488 |
+
{isintent_c: '|F2PY_INTENT_C'},
|
| 489 |
+
""",capi_tmp);
|
| 490 |
+
if (rv_cb_arr == NULL) {
|
| 491 |
+
fprintf(stderr,\"rv_cb_arr is NULL\\n\");
|
| 492 |
+
goto capi_fail;
|
| 493 |
+
}
|
| 494 |
+
MEMCOPY(#varname_i#,PyArray_DATA(rv_cb_arr),PyArray_NBYTES(rv_cb_arr));
|
| 495 |
+
if (capi_tmp != (PyObject *)rv_cb_arr) {
|
| 496 |
+
Py_DECREF(rv_cb_arr);
|
| 497 |
+
}
|
| 498 |
+
}""",
|
| 499 |
+
{debugcapi: ' fprintf(stderr,"<-.\\n");'},
|
| 500 |
+
],
|
| 501 |
+
'need': ['MEMCOPY', {iscomplexarray: '#ctype#'}],
|
| 502 |
+
'_check': l_and(isarray, isintent_out)
|
| 503 |
+
}, {
|
| 504 |
+
'docreturn': '#varname#,',
|
| 505 |
+
'_check': isintent_out
|
| 506 |
+
}
|
| 507 |
+
]
|
| 508 |
+
|
| 509 |
+
################## Build call-back module #############
|
| 510 |
+
cb_map = {}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def buildcallbacks(m):
|
| 514 |
+
cb_map[m['name']] = []
|
| 515 |
+
for bi in m['body']:
|
| 516 |
+
if bi['block'] == 'interface':
|
| 517 |
+
for b in bi['body']:
|
| 518 |
+
if b:
|
| 519 |
+
buildcallback(b, m['name'])
|
| 520 |
+
else:
|
| 521 |
+
errmess('warning: empty body for %s\n' % (m['name']))
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
def buildcallback(rout, um):
|
| 525 |
+
from . import capi_maps
|
| 526 |
+
|
| 527 |
+
outmess(' Constructing call-back function "cb_%s_in_%s"\n' %
|
| 528 |
+
(rout['name'], um))
|
| 529 |
+
args, depargs = getargs(rout)
|
| 530 |
+
capi_maps.depargs = depargs
|
| 531 |
+
var = rout['vars']
|
| 532 |
+
vrd = capi_maps.cb_routsign2map(rout, um)
|
| 533 |
+
rd = dictappend({}, vrd)
|
| 534 |
+
cb_map[um].append([rout['name'], rd['name']])
|
| 535 |
+
for r in cb_rout_rules:
|
| 536 |
+
if ('_check' in r and r['_check'](rout)) or ('_check' not in r):
|
| 537 |
+
ar = applyrules(r, vrd, rout)
|
| 538 |
+
rd = dictappend(rd, ar)
|
| 539 |
+
savevrd = {}
|
| 540 |
+
for i, a in enumerate(args):
|
| 541 |
+
vrd = capi_maps.cb_sign2map(a, var[a], index=i)
|
| 542 |
+
savevrd[a] = vrd
|
| 543 |
+
for r in cb_arg_rules:
|
| 544 |
+
if '_depend' in r:
|
| 545 |
+
continue
|
| 546 |
+
if '_optional' in r and isoptional(var[a]):
|
| 547 |
+
continue
|
| 548 |
+
if ('_check' in r and r['_check'](var[a])) or ('_check' not in r):
|
| 549 |
+
ar = applyrules(r, vrd, var[a])
|
| 550 |
+
rd = dictappend(rd, ar)
|
| 551 |
+
if '_break' in r:
|
| 552 |
+
break
|
| 553 |
+
for a in args:
|
| 554 |
+
vrd = savevrd[a]
|
| 555 |
+
for r in cb_arg_rules:
|
| 556 |
+
if '_depend' in r:
|
| 557 |
+
continue
|
| 558 |
+
if ('_optional' not in r) or ('_optional' in r and isrequired(var[a])):
|
| 559 |
+
continue
|
| 560 |
+
if ('_check' in r and r['_check'](var[a])) or ('_check' not in r):
|
| 561 |
+
ar = applyrules(r, vrd, var[a])
|
| 562 |
+
rd = dictappend(rd, ar)
|
| 563 |
+
if '_break' in r:
|
| 564 |
+
break
|
| 565 |
+
for a in depargs:
|
| 566 |
+
vrd = savevrd[a]
|
| 567 |
+
for r in cb_arg_rules:
|
| 568 |
+
if '_depend' not in r:
|
| 569 |
+
continue
|
| 570 |
+
if '_optional' in r:
|
| 571 |
+
continue
|
| 572 |
+
if ('_check' in r and r['_check'](var[a])) or ('_check' not in r):
|
| 573 |
+
ar = applyrules(r, vrd, var[a])
|
| 574 |
+
rd = dictappend(rd, ar)
|
| 575 |
+
if '_break' in r:
|
| 576 |
+
break
|
| 577 |
+
if 'args' in rd and 'optargs' in rd:
|
| 578 |
+
if isinstance(rd['optargs'], list):
|
| 579 |
+
rd['optargs'] = rd['optargs'] + ["""
|
| 580 |
+
#ifndef F2PY_CB_RETURNCOMPLEX
|
| 581 |
+
,
|
| 582 |
+
#endif
|
| 583 |
+
"""]
|
| 584 |
+
rd['optargs_nm'] = rd['optargs_nm'] + ["""
|
| 585 |
+
#ifndef F2PY_CB_RETURNCOMPLEX
|
| 586 |
+
,
|
| 587 |
+
#endif
|
| 588 |
+
"""]
|
| 589 |
+
rd['optargs_td'] = rd['optargs_td'] + ["""
|
| 590 |
+
#ifndef F2PY_CB_RETURNCOMPLEX
|
| 591 |
+
,
|
| 592 |
+
#endif
|
| 593 |
+
"""]
|
| 594 |
+
if isinstance(rd['docreturn'], list):
|
| 595 |
+
rd['docreturn'] = stripcomma(
|
| 596 |
+
replace('#docreturn#', {'docreturn': rd['docreturn']}))
|
| 597 |
+
optargs = stripcomma(replace('#docsignopt#',
|
| 598 |
+
{'docsignopt': rd['docsignopt']}
|
| 599 |
+
))
|
| 600 |
+
if optargs == '':
|
| 601 |
+
rd['docsignature'] = stripcomma(
|
| 602 |
+
replace('#docsign#', {'docsign': rd['docsign']}))
|
| 603 |
+
else:
|
| 604 |
+
rd['docsignature'] = replace('#docsign#[#docsignopt#]',
|
| 605 |
+
{'docsign': rd['docsign'],
|
| 606 |
+
'docsignopt': optargs,
|
| 607 |
+
})
|
| 608 |
+
rd['latexdocsignature'] = rd['docsignature'].replace('_', '\\_')
|
| 609 |
+
rd['latexdocsignature'] = rd['latexdocsignature'].replace(',', ', ')
|
| 610 |
+
rd['docstrsigns'] = []
|
| 611 |
+
rd['latexdocstrsigns'] = []
|
| 612 |
+
for k in ['docstrreq', 'docstropt', 'docstrout', 'docstrcbs']:
|
| 613 |
+
if k in rd and isinstance(rd[k], list):
|
| 614 |
+
rd['docstrsigns'] = rd['docstrsigns'] + rd[k]
|
| 615 |
+
k = 'latex' + k
|
| 616 |
+
if k in rd and isinstance(rd[k], list):
|
| 617 |
+
rd['latexdocstrsigns'] = rd['latexdocstrsigns'] + rd[k][0:1] +\
|
| 618 |
+
['\\begin{description}'] + rd[k][1:] +\
|
| 619 |
+
['\\end{description}']
|
| 620 |
+
if 'args' not in rd:
|
| 621 |
+
rd['args'] = ''
|
| 622 |
+
rd['args_td'] = ''
|
| 623 |
+
rd['args_nm'] = ''
|
| 624 |
+
if not (rd.get('args') or rd.get('optargs') or rd.get('strarglens')):
|
| 625 |
+
rd['noargs'] = 'void'
|
| 626 |
+
|
| 627 |
+
ar = applyrules(cb_routine_rules, rd)
|
| 628 |
+
cfuncs.callbacks[rd['name']] = ar['body']
|
| 629 |
+
if isinstance(ar['need'], str):
|
| 630 |
+
ar['need'] = [ar['need']]
|
| 631 |
+
|
| 632 |
+
if 'need' in rd:
|
| 633 |
+
for t in cfuncs.typedefs.keys():
|
| 634 |
+
if t in rd['need']:
|
| 635 |
+
ar['need'].append(t)
|
| 636 |
+
|
| 637 |
+
cfuncs.typedefs_generated[rd['name'] + '_typedef'] = ar['cbtypedefs']
|
| 638 |
+
ar['need'].append(rd['name'] + '_typedef')
|
| 639 |
+
cfuncs.needs[rd['name']] = ar['need']
|
| 640 |
+
|
| 641 |
+
capi_maps.lcb2_map[rd['name']] = {'maxnofargs': ar['maxnofargs'],
|
| 642 |
+
'nofoptargs': ar['nofoptargs'],
|
| 643 |
+
'docstr': ar['docstr'],
|
| 644 |
+
'latexdocstr': ar['latexdocstr'],
|
| 645 |
+
'argname': rd['argname']
|
| 646 |
+
}
|
| 647 |
+
outmess(' %s\n' % (ar['docstrshort']))
|
| 648 |
+
return
|
| 649 |
+
################## Build call-back function #############
|
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|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
C declarations, CPP macros, and C functions for f2py2e.
|
| 5 |
+
Only required declarations/macros/functions will be used.
|
| 6 |
+
|
| 7 |
+
Copyright 1999,2000 Pearu Peterson all rights reserved,
|
| 8 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 9 |
+
Permission to use, modify, and distribute this software is given under the
|
| 10 |
+
terms of the NumPy License.
|
| 11 |
+
|
| 12 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 13 |
+
$Date: 2005/05/06 11:42:34 $
|
| 14 |
+
Pearu Peterson
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
import sys
|
| 18 |
+
import copy
|
| 19 |
+
|
| 20 |
+
from . import __version__
|
| 21 |
+
|
| 22 |
+
f2py_version = __version__.version
|
| 23 |
+
errmess = sys.stderr.write
|
| 24 |
+
|
| 25 |
+
##################### Definitions ##################
|
| 26 |
+
|
| 27 |
+
outneeds = {'includes0': [], 'includes': [], 'typedefs': [], 'typedefs_generated': [],
|
| 28 |
+
'userincludes': [],
|
| 29 |
+
'cppmacros': [], 'cfuncs': [], 'callbacks': [], 'f90modhooks': [],
|
| 30 |
+
'commonhooks': []}
|
| 31 |
+
needs = {}
|
| 32 |
+
includes0 = {'includes0': '/*need_includes0*/'}
|
| 33 |
+
includes = {'includes': '/*need_includes*/'}
|
| 34 |
+
userincludes = {'userincludes': '/*need_userincludes*/'}
|
| 35 |
+
typedefs = {'typedefs': '/*need_typedefs*/'}
|
| 36 |
+
typedefs_generated = {'typedefs_generated': '/*need_typedefs_generated*/'}
|
| 37 |
+
cppmacros = {'cppmacros': '/*need_cppmacros*/'}
|
| 38 |
+
cfuncs = {'cfuncs': '/*need_cfuncs*/'}
|
| 39 |
+
callbacks = {'callbacks': '/*need_callbacks*/'}
|
| 40 |
+
f90modhooks = {'f90modhooks': '/*need_f90modhooks*/',
|
| 41 |
+
'initf90modhooksstatic': '/*initf90modhooksstatic*/',
|
| 42 |
+
'initf90modhooksdynamic': '/*initf90modhooksdynamic*/',
|
| 43 |
+
}
|
| 44 |
+
commonhooks = {'commonhooks': '/*need_commonhooks*/',
|
| 45 |
+
'initcommonhooks': '/*need_initcommonhooks*/',
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
############ Includes ###################
|
| 49 |
+
|
| 50 |
+
includes0['math.h'] = '#include <math.h>'
|
| 51 |
+
includes0['string.h'] = '#include <string.h>'
|
| 52 |
+
includes0['setjmp.h'] = '#include <setjmp.h>'
|
| 53 |
+
|
| 54 |
+
includes['arrayobject.h'] = '''#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
|
| 55 |
+
#include "arrayobject.h"'''
|
| 56 |
+
|
| 57 |
+
includes['arrayobject.h'] = '#include "fortranobject.h"'
|
| 58 |
+
includes['stdarg.h'] = '#include <stdarg.h>'
|
| 59 |
+
|
| 60 |
+
############# Type definitions ###############
|
| 61 |
+
|
| 62 |
+
typedefs['unsigned_char'] = 'typedef unsigned char unsigned_char;'
|
| 63 |
+
typedefs['unsigned_short'] = 'typedef unsigned short unsigned_short;'
|
| 64 |
+
typedefs['unsigned_long'] = 'typedef unsigned long unsigned_long;'
|
| 65 |
+
typedefs['signed_char'] = 'typedef signed char signed_char;'
|
| 66 |
+
typedefs['long_long'] = """\
|
| 67 |
+
#if defined(NPY_OS_WIN32)
|
| 68 |
+
typedef __int64 long_long;
|
| 69 |
+
#else
|
| 70 |
+
typedef long long long_long;
|
| 71 |
+
typedef unsigned long long unsigned_long_long;
|
| 72 |
+
#endif
|
| 73 |
+
"""
|
| 74 |
+
typedefs['unsigned_long_long'] = """\
|
| 75 |
+
#if defined(NPY_OS_WIN32)
|
| 76 |
+
typedef __uint64 long_long;
|
| 77 |
+
#else
|
| 78 |
+
typedef unsigned long long unsigned_long_long;
|
| 79 |
+
#endif
|
| 80 |
+
"""
|
| 81 |
+
typedefs['long_double'] = """\
|
| 82 |
+
#ifndef _LONG_DOUBLE
|
| 83 |
+
typedef long double long_double;
|
| 84 |
+
#endif
|
| 85 |
+
"""
|
| 86 |
+
typedefs[
|
| 87 |
+
'complex_long_double'] = 'typedef struct {long double r,i;} complex_long_double;'
|
| 88 |
+
typedefs['complex_float'] = 'typedef struct {float r,i;} complex_float;'
|
| 89 |
+
typedefs['complex_double'] = 'typedef struct {double r,i;} complex_double;'
|
| 90 |
+
typedefs['string'] = """typedef char * string;"""
|
| 91 |
+
typedefs['character'] = """typedef char character;"""
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
############### CPP macros ####################
|
| 95 |
+
cppmacros['CFUNCSMESS'] = """\
|
| 96 |
+
#ifdef DEBUGCFUNCS
|
| 97 |
+
#define CFUNCSMESS(mess) fprintf(stderr,\"debug-capi:\"mess);
|
| 98 |
+
#define CFUNCSMESSPY(mess,obj) CFUNCSMESS(mess) \\
|
| 99 |
+
PyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\\
|
| 100 |
+
fprintf(stderr,\"\\n\");
|
| 101 |
+
#else
|
| 102 |
+
#define CFUNCSMESS(mess)
|
| 103 |
+
#define CFUNCSMESSPY(mess,obj)
|
| 104 |
+
#endif
|
| 105 |
+
"""
|
| 106 |
+
cppmacros['F_FUNC'] = """\
|
| 107 |
+
#if defined(PREPEND_FORTRAN)
|
| 108 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 109 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 110 |
+
#define F_FUNC(f,F) _##F
|
| 111 |
+
#else
|
| 112 |
+
#define F_FUNC(f,F) _##f
|
| 113 |
+
#endif
|
| 114 |
+
#else
|
| 115 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 116 |
+
#define F_FUNC(f,F) _##F##_
|
| 117 |
+
#else
|
| 118 |
+
#define F_FUNC(f,F) _##f##_
|
| 119 |
+
#endif
|
| 120 |
+
#endif
|
| 121 |
+
#else
|
| 122 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 123 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 124 |
+
#define F_FUNC(f,F) F
|
| 125 |
+
#else
|
| 126 |
+
#define F_FUNC(f,F) f
|
| 127 |
+
#endif
|
| 128 |
+
#else
|
| 129 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 130 |
+
#define F_FUNC(f,F) F##_
|
| 131 |
+
#else
|
| 132 |
+
#define F_FUNC(f,F) f##_
|
| 133 |
+
#endif
|
| 134 |
+
#endif
|
| 135 |
+
#endif
|
| 136 |
+
#if defined(UNDERSCORE_G77)
|
| 137 |
+
#define F_FUNC_US(f,F) F_FUNC(f##_,F##_)
|
| 138 |
+
#else
|
| 139 |
+
#define F_FUNC_US(f,F) F_FUNC(f,F)
|
| 140 |
+
#endif
|
| 141 |
+
"""
|
| 142 |
+
cppmacros['F_WRAPPEDFUNC'] = """\
|
| 143 |
+
#if defined(PREPEND_FORTRAN)
|
| 144 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 145 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 146 |
+
#define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F
|
| 147 |
+
#else
|
| 148 |
+
#define F_WRAPPEDFUNC(f,F) _f2pywrap##f
|
| 149 |
+
#endif
|
| 150 |
+
#else
|
| 151 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 152 |
+
#define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F##_
|
| 153 |
+
#else
|
| 154 |
+
#define F_WRAPPEDFUNC(f,F) _f2pywrap##f##_
|
| 155 |
+
#endif
|
| 156 |
+
#endif
|
| 157 |
+
#else
|
| 158 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 159 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 160 |
+
#define F_WRAPPEDFUNC(f,F) F2PYWRAP##F
|
| 161 |
+
#else
|
| 162 |
+
#define F_WRAPPEDFUNC(f,F) f2pywrap##f
|
| 163 |
+
#endif
|
| 164 |
+
#else
|
| 165 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 166 |
+
#define F_WRAPPEDFUNC(f,F) F2PYWRAP##F##_
|
| 167 |
+
#else
|
| 168 |
+
#define F_WRAPPEDFUNC(f,F) f2pywrap##f##_
|
| 169 |
+
#endif
|
| 170 |
+
#endif
|
| 171 |
+
#endif
|
| 172 |
+
#if defined(UNDERSCORE_G77)
|
| 173 |
+
#define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f##_,F##_)
|
| 174 |
+
#else
|
| 175 |
+
#define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f,F)
|
| 176 |
+
#endif
|
| 177 |
+
"""
|
| 178 |
+
cppmacros['F_MODFUNC'] = """\
|
| 179 |
+
#if defined(F90MOD2CCONV1) /*E.g. Compaq Fortran */
|
| 180 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 181 |
+
#define F_MODFUNCNAME(m,f) $ ## m ## $ ## f
|
| 182 |
+
#else
|
| 183 |
+
#define F_MODFUNCNAME(m,f) $ ## m ## $ ## f ## _
|
| 184 |
+
#endif
|
| 185 |
+
#endif
|
| 186 |
+
|
| 187 |
+
#if defined(F90MOD2CCONV2) /*E.g. IBM XL Fortran, not tested though */
|
| 188 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 189 |
+
#define F_MODFUNCNAME(m,f) __ ## m ## _MOD_ ## f
|
| 190 |
+
#else
|
| 191 |
+
#define F_MODFUNCNAME(m,f) __ ## m ## _MOD_ ## f ## _
|
| 192 |
+
#endif
|
| 193 |
+
#endif
|
| 194 |
+
|
| 195 |
+
#if defined(F90MOD2CCONV3) /*E.g. MIPSPro Compilers */
|
| 196 |
+
#if defined(NO_APPEND_FORTRAN)
|
| 197 |
+
#define F_MODFUNCNAME(m,f) f ## .in. ## m
|
| 198 |
+
#else
|
| 199 |
+
#define F_MODFUNCNAME(m,f) f ## .in. ## m ## _
|
| 200 |
+
#endif
|
| 201 |
+
#endif
|
| 202 |
+
/*
|
| 203 |
+
#if defined(UPPERCASE_FORTRAN)
|
| 204 |
+
#define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(M,F)
|
| 205 |
+
#else
|
| 206 |
+
#define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(m,f)
|
| 207 |
+
#endif
|
| 208 |
+
*/
|
| 209 |
+
|
| 210 |
+
#define F_MODFUNC(m,f) (*(f2pymodstruct##m##.##f))
|
| 211 |
+
"""
|
| 212 |
+
cppmacros['SWAPUNSAFE'] = """\
|
| 213 |
+
#define SWAP(a,b) (size_t)(a) = ((size_t)(a) ^ (size_t)(b));\\
|
| 214 |
+
(size_t)(b) = ((size_t)(a) ^ (size_t)(b));\\
|
| 215 |
+
(size_t)(a) = ((size_t)(a) ^ (size_t)(b))
|
| 216 |
+
"""
|
| 217 |
+
cppmacros['SWAP'] = """\
|
| 218 |
+
#define SWAP(a,b,t) {\\
|
| 219 |
+
t *c;\\
|
| 220 |
+
c = a;\\
|
| 221 |
+
a = b;\\
|
| 222 |
+
b = c;}
|
| 223 |
+
"""
|
| 224 |
+
# cppmacros['ISCONTIGUOUS']='#define ISCONTIGUOUS(m) (PyArray_FLAGS(m) &
|
| 225 |
+
# NPY_ARRAY_C_CONTIGUOUS)'
|
| 226 |
+
cppmacros['PRINTPYOBJERR'] = """\
|
| 227 |
+
#define PRINTPYOBJERR(obj)\\
|
| 228 |
+
fprintf(stderr,\"#modulename#.error is related to \");\\
|
| 229 |
+
PyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\\
|
| 230 |
+
fprintf(stderr,\"\\n\");
|
| 231 |
+
"""
|
| 232 |
+
cppmacros['MINMAX'] = """\
|
| 233 |
+
#ifndef max
|
| 234 |
+
#define max(a,b) ((a > b) ? (a) : (b))
|
| 235 |
+
#endif
|
| 236 |
+
#ifndef min
|
| 237 |
+
#define min(a,b) ((a < b) ? (a) : (b))
|
| 238 |
+
#endif
|
| 239 |
+
#ifndef MAX
|
| 240 |
+
#define MAX(a,b) ((a > b) ? (a) : (b))
|
| 241 |
+
#endif
|
| 242 |
+
#ifndef MIN
|
| 243 |
+
#define MIN(a,b) ((a < b) ? (a) : (b))
|
| 244 |
+
#endif
|
| 245 |
+
"""
|
| 246 |
+
cppmacros['len..'] = """\
|
| 247 |
+
/* See fortranobject.h for definitions. The macros here are provided for BC. */
|
| 248 |
+
#define rank f2py_rank
|
| 249 |
+
#define shape f2py_shape
|
| 250 |
+
#define fshape f2py_shape
|
| 251 |
+
#define len f2py_len
|
| 252 |
+
#define flen f2py_flen
|
| 253 |
+
#define slen f2py_slen
|
| 254 |
+
#define size f2py_size
|
| 255 |
+
"""
|
| 256 |
+
cppmacros[
|
| 257 |
+
'pyobj_from_char1'] = '#define pyobj_from_char1(v) (PyLong_FromLong(v))'
|
| 258 |
+
cppmacros[
|
| 259 |
+
'pyobj_from_short1'] = '#define pyobj_from_short1(v) (PyLong_FromLong(v))'
|
| 260 |
+
needs['pyobj_from_int1'] = ['signed_char']
|
| 261 |
+
cppmacros['pyobj_from_int1'] = '#define pyobj_from_int1(v) (PyLong_FromLong(v))'
|
| 262 |
+
cppmacros[
|
| 263 |
+
'pyobj_from_long1'] = '#define pyobj_from_long1(v) (PyLong_FromLong(v))'
|
| 264 |
+
needs['pyobj_from_long_long1'] = ['long_long']
|
| 265 |
+
cppmacros['pyobj_from_long_long1'] = """\
|
| 266 |
+
#ifdef HAVE_LONG_LONG
|
| 267 |
+
#define pyobj_from_long_long1(v) (PyLong_FromLongLong(v))
|
| 268 |
+
#else
|
| 269 |
+
#warning HAVE_LONG_LONG is not available. Redefining pyobj_from_long_long.
|
| 270 |
+
#define pyobj_from_long_long1(v) (PyLong_FromLong(v))
|
| 271 |
+
#endif
|
| 272 |
+
"""
|
| 273 |
+
needs['pyobj_from_long_double1'] = ['long_double']
|
| 274 |
+
cppmacros[
|
| 275 |
+
'pyobj_from_long_double1'] = '#define pyobj_from_long_double1(v) (PyFloat_FromDouble(v))'
|
| 276 |
+
cppmacros[
|
| 277 |
+
'pyobj_from_double1'] = '#define pyobj_from_double1(v) (PyFloat_FromDouble(v))'
|
| 278 |
+
cppmacros[
|
| 279 |
+
'pyobj_from_float1'] = '#define pyobj_from_float1(v) (PyFloat_FromDouble(v))'
|
| 280 |
+
needs['pyobj_from_complex_long_double1'] = ['complex_long_double']
|
| 281 |
+
cppmacros[
|
| 282 |
+
'pyobj_from_complex_long_double1'] = '#define pyobj_from_complex_long_double1(v) (PyComplex_FromDoubles(v.r,v.i))'
|
| 283 |
+
needs['pyobj_from_complex_double1'] = ['complex_double']
|
| 284 |
+
cppmacros[
|
| 285 |
+
'pyobj_from_complex_double1'] = '#define pyobj_from_complex_double1(v) (PyComplex_FromDoubles(v.r,v.i))'
|
| 286 |
+
needs['pyobj_from_complex_float1'] = ['complex_float']
|
| 287 |
+
cppmacros[
|
| 288 |
+
'pyobj_from_complex_float1'] = '#define pyobj_from_complex_float1(v) (PyComplex_FromDoubles(v.r,v.i))'
|
| 289 |
+
needs['pyobj_from_string1'] = ['string']
|
| 290 |
+
cppmacros[
|
| 291 |
+
'pyobj_from_string1'] = '#define pyobj_from_string1(v) (PyUnicode_FromString((char *)v))'
|
| 292 |
+
needs['pyobj_from_string1size'] = ['string']
|
| 293 |
+
cppmacros[
|
| 294 |
+
'pyobj_from_string1size'] = '#define pyobj_from_string1size(v,len) (PyUnicode_FromStringAndSize((char *)v, len))'
|
| 295 |
+
needs['TRYPYARRAYTEMPLATE'] = ['PRINTPYOBJERR']
|
| 296 |
+
cppmacros['TRYPYARRAYTEMPLATE'] = """\
|
| 297 |
+
/* New SciPy */
|
| 298 |
+
#define TRYPYARRAYTEMPLATECHAR case NPY_STRING: *(char *)(PyArray_DATA(arr))=*v; break;
|
| 299 |
+
#define TRYPYARRAYTEMPLATELONG case NPY_LONG: *(long *)(PyArray_DATA(arr))=*v; break;
|
| 300 |
+
#define TRYPYARRAYTEMPLATEOBJECT case NPY_OBJECT: PyArray_SETITEM(arr,PyArray_DATA(arr),pyobj_from_ ## ctype ## 1(*v)); break;
|
| 301 |
+
|
| 302 |
+
#define TRYPYARRAYTEMPLATE(ctype,typecode) \\
|
| 303 |
+
PyArrayObject *arr = NULL;\\
|
| 304 |
+
if (!obj) return -2;\\
|
| 305 |
+
if (!PyArray_Check(obj)) return -1;\\
|
| 306 |
+
if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\"TRYPYARRAYTEMPLATE:\");PRINTPYOBJERR(obj);return 0;}\\
|
| 307 |
+
if (PyArray_DESCR(arr)->type==typecode) {*(ctype *)(PyArray_DATA(arr))=*v; return 1;}\\
|
| 308 |
+
switch (PyArray_TYPE(arr)) {\\
|
| 309 |
+
case NPY_DOUBLE: *(npy_double *)(PyArray_DATA(arr))=*v; break;\\
|
| 310 |
+
case NPY_INT: *(npy_int *)(PyArray_DATA(arr))=*v; break;\\
|
| 311 |
+
case NPY_LONG: *(npy_long *)(PyArray_DATA(arr))=*v; break;\\
|
| 312 |
+
case NPY_FLOAT: *(npy_float *)(PyArray_DATA(arr))=*v; break;\\
|
| 313 |
+
case NPY_CDOUBLE: *(npy_double *)(PyArray_DATA(arr))=*v; break;\\
|
| 314 |
+
case NPY_CFLOAT: *(npy_float *)(PyArray_DATA(arr))=*v; break;\\
|
| 315 |
+
case NPY_BOOL: *(npy_bool *)(PyArray_DATA(arr))=(*v!=0); break;\\
|
| 316 |
+
case NPY_UBYTE: *(npy_ubyte *)(PyArray_DATA(arr))=*v; break;\\
|
| 317 |
+
case NPY_BYTE: *(npy_byte *)(PyArray_DATA(arr))=*v; break;\\
|
| 318 |
+
case NPY_SHORT: *(npy_short *)(PyArray_DATA(arr))=*v; break;\\
|
| 319 |
+
case NPY_USHORT: *(npy_ushort *)(PyArray_DATA(arr))=*v; break;\\
|
| 320 |
+
case NPY_UINT: *(npy_uint *)(PyArray_DATA(arr))=*v; break;\\
|
| 321 |
+
case NPY_ULONG: *(npy_ulong *)(PyArray_DATA(arr))=*v; break;\\
|
| 322 |
+
case NPY_LONGLONG: *(npy_longlong *)(PyArray_DATA(arr))=*v; break;\\
|
| 323 |
+
case NPY_ULONGLONG: *(npy_ulonglong *)(PyArray_DATA(arr))=*v; break;\\
|
| 324 |
+
case NPY_LONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=*v; break;\\
|
| 325 |
+
case NPY_CLONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=*v; break;\\
|
| 326 |
+
case NPY_OBJECT: PyArray_SETITEM(arr, PyArray_DATA(arr), pyobj_from_ ## ctype ## 1(*v)); break;\\
|
| 327 |
+
default: return -2;\\
|
| 328 |
+
};\\
|
| 329 |
+
return 1
|
| 330 |
+
"""
|
| 331 |
+
|
| 332 |
+
needs['TRYCOMPLEXPYARRAYTEMPLATE'] = ['PRINTPYOBJERR']
|
| 333 |
+
cppmacros['TRYCOMPLEXPYARRAYTEMPLATE'] = """\
|
| 334 |
+
#define TRYCOMPLEXPYARRAYTEMPLATEOBJECT case NPY_OBJECT: PyArray_SETITEM(arr, PyArray_DATA(arr), pyobj_from_complex_ ## ctype ## 1((*v))); break;
|
| 335 |
+
#define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\\
|
| 336 |
+
PyArrayObject *arr = NULL;\\
|
| 337 |
+
if (!obj) return -2;\\
|
| 338 |
+
if (!PyArray_Check(obj)) return -1;\\
|
| 339 |
+
if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,\"TRYCOMPLEXPYARRAYTEMPLATE:\");PRINTPYOBJERR(obj);return 0;}\\
|
| 340 |
+
if (PyArray_DESCR(arr)->type==typecode) {\\
|
| 341 |
+
*(ctype *)(PyArray_DATA(arr))=(*v).r;\\
|
| 342 |
+
*(ctype *)(PyArray_DATA(arr)+sizeof(ctype))=(*v).i;\\
|
| 343 |
+
return 1;\\
|
| 344 |
+
}\\
|
| 345 |
+
switch (PyArray_TYPE(arr)) {\\
|
| 346 |
+
case NPY_CDOUBLE: *(npy_double *)(PyArray_DATA(arr))=(*v).r;\\
|
| 347 |
+
*(npy_double *)(PyArray_DATA(arr)+sizeof(npy_double))=(*v).i;\\
|
| 348 |
+
break;\\
|
| 349 |
+
case NPY_CFLOAT: *(npy_float *)(PyArray_DATA(arr))=(*v).r;\\
|
| 350 |
+
*(npy_float *)(PyArray_DATA(arr)+sizeof(npy_float))=(*v).i;\\
|
| 351 |
+
break;\\
|
| 352 |
+
case NPY_DOUBLE: *(npy_double *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 353 |
+
case NPY_LONG: *(npy_long *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 354 |
+
case NPY_FLOAT: *(npy_float *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 355 |
+
case NPY_INT: *(npy_int *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 356 |
+
case NPY_SHORT: *(npy_short *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 357 |
+
case NPY_UBYTE: *(npy_ubyte *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 358 |
+
case NPY_BYTE: *(npy_byte *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 359 |
+
case NPY_BOOL: *(npy_bool *)(PyArray_DATA(arr))=((*v).r!=0 && (*v).i!=0); break;\\
|
| 360 |
+
case NPY_USHORT: *(npy_ushort *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 361 |
+
case NPY_UINT: *(npy_uint *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 362 |
+
case NPY_ULONG: *(npy_ulong *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 363 |
+
case NPY_LONGLONG: *(npy_longlong *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 364 |
+
case NPY_ULONGLONG: *(npy_ulonglong *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 365 |
+
case NPY_LONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=(*v).r; break;\\
|
| 366 |
+
case NPY_CLONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=(*v).r;\\
|
| 367 |
+
*(npy_longdouble *)(PyArray_DATA(arr)+sizeof(npy_longdouble))=(*v).i;\\
|
| 368 |
+
break;\\
|
| 369 |
+
case NPY_OBJECT: PyArray_SETITEM(arr, PyArray_DATA(arr), pyobj_from_complex_ ## ctype ## 1((*v))); break;\\
|
| 370 |
+
default: return -2;\\
|
| 371 |
+
};\\
|
| 372 |
+
return -1;
|
| 373 |
+
"""
|
| 374 |
+
# cppmacros['NUMFROMARROBJ']="""\
|
| 375 |
+
# define NUMFROMARROBJ(typenum,ctype) \\
|
| 376 |
+
# if (PyArray_Check(obj)) arr = (PyArrayObject *)obj;\\
|
| 377 |
+
# else arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj,typenum,0,0);\\
|
| 378 |
+
# if (arr) {\\
|
| 379 |
+
# if (PyArray_TYPE(arr)==NPY_OBJECT) {\\
|
| 380 |
+
# if (!ctype ## _from_pyobj(v,(PyArray_DESCR(arr)->getitem)(PyArray_DATA(arr)),\"\"))\\
|
| 381 |
+
# goto capi_fail;\\
|
| 382 |
+
# } else {\\
|
| 383 |
+
# (PyArray_DESCR(arr)->cast[typenum])(PyArray_DATA(arr),1,(char*)v,1,1);\\
|
| 384 |
+
# }\\
|
| 385 |
+
# if ((PyObject *)arr != obj) { Py_DECREF(arr); }\\
|
| 386 |
+
# return 1;\\
|
| 387 |
+
# }
|
| 388 |
+
# """
|
| 389 |
+
# XXX: Note that CNUMFROMARROBJ is identical with NUMFROMARROBJ
|
| 390 |
+
# cppmacros['CNUMFROMARROBJ']="""\
|
| 391 |
+
# define CNUMFROMARROBJ(typenum,ctype) \\
|
| 392 |
+
# if (PyArray_Check(obj)) arr = (PyArrayObject *)obj;\\
|
| 393 |
+
# else arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj,typenum,0,0);\\
|
| 394 |
+
# if (arr) {\\
|
| 395 |
+
# if (PyArray_TYPE(arr)==NPY_OBJECT) {\\
|
| 396 |
+
# if (!ctype ## _from_pyobj(v,(PyArray_DESCR(arr)->getitem)(PyArray_DATA(arr)),\"\"))\\
|
| 397 |
+
# goto capi_fail;\\
|
| 398 |
+
# } else {\\
|
| 399 |
+
# (PyArray_DESCR(arr)->cast[typenum])((void *)(PyArray_DATA(arr)),1,(void *)(v),1,1);\\
|
| 400 |
+
# }\\
|
| 401 |
+
# if ((PyObject *)arr != obj) { Py_DECREF(arr); }\\
|
| 402 |
+
# return 1;\\
|
| 403 |
+
# }
|
| 404 |
+
# """
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
needs['GETSTRFROMPYTUPLE'] = ['STRINGCOPYN', 'PRINTPYOBJERR']
|
| 408 |
+
cppmacros['GETSTRFROMPYTUPLE'] = """\
|
| 409 |
+
#define GETSTRFROMPYTUPLE(tuple,index,str,len) {\\
|
| 410 |
+
PyObject *rv_cb_str = PyTuple_GetItem((tuple),(index));\\
|
| 411 |
+
if (rv_cb_str == NULL)\\
|
| 412 |
+
goto capi_fail;\\
|
| 413 |
+
if (PyBytes_Check(rv_cb_str)) {\\
|
| 414 |
+
str[len-1]='\\0';\\
|
| 415 |
+
STRINGCOPYN((str),PyBytes_AS_STRING((PyBytesObject*)rv_cb_str),(len));\\
|
| 416 |
+
} else {\\
|
| 417 |
+
PRINTPYOBJERR(rv_cb_str);\\
|
| 418 |
+
PyErr_SetString(#modulename#_error,\"string object expected\");\\
|
| 419 |
+
goto capi_fail;\\
|
| 420 |
+
}\\
|
| 421 |
+
}
|
| 422 |
+
"""
|
| 423 |
+
cppmacros['GETSCALARFROMPYTUPLE'] = """\
|
| 424 |
+
#define GETSCALARFROMPYTUPLE(tuple,index,var,ctype,mess) {\\
|
| 425 |
+
if ((capi_tmp = PyTuple_GetItem((tuple),(index)))==NULL) goto capi_fail;\\
|
| 426 |
+
if (!(ctype ## _from_pyobj((var),capi_tmp,mess)))\\
|
| 427 |
+
goto capi_fail;\\
|
| 428 |
+
}
|
| 429 |
+
"""
|
| 430 |
+
|
| 431 |
+
cppmacros['FAILNULL'] = """\\
|
| 432 |
+
#define FAILNULL(p) do { \\
|
| 433 |
+
if ((p) == NULL) { \\
|
| 434 |
+
PyErr_SetString(PyExc_MemoryError, "NULL pointer found"); \\
|
| 435 |
+
goto capi_fail; \\
|
| 436 |
+
} \\
|
| 437 |
+
} while (0)
|
| 438 |
+
"""
|
| 439 |
+
needs['MEMCOPY'] = ['string.h', 'FAILNULL']
|
| 440 |
+
cppmacros['MEMCOPY'] = """\
|
| 441 |
+
#define MEMCOPY(to,from,n)\\
|
| 442 |
+
do { FAILNULL(to); FAILNULL(from); (void)memcpy(to,from,n); } while (0)
|
| 443 |
+
"""
|
| 444 |
+
cppmacros['STRINGMALLOC'] = """\
|
| 445 |
+
#define STRINGMALLOC(str,len)\\
|
| 446 |
+
if ((str = (string)malloc(len+1)) == NULL) {\\
|
| 447 |
+
PyErr_SetString(PyExc_MemoryError, \"out of memory\");\\
|
| 448 |
+
goto capi_fail;\\
|
| 449 |
+
} else {\\
|
| 450 |
+
(str)[len] = '\\0';\\
|
| 451 |
+
}
|
| 452 |
+
"""
|
| 453 |
+
cppmacros['STRINGFREE'] = """\
|
| 454 |
+
#define STRINGFREE(str) do {if (!(str == NULL)) free(str);} while (0)
|
| 455 |
+
"""
|
| 456 |
+
needs['STRINGPADN'] = ['string.h']
|
| 457 |
+
cppmacros['STRINGPADN'] = """\
|
| 458 |
+
/*
|
| 459 |
+
STRINGPADN replaces null values with padding values from the right.
|
| 460 |
+
|
| 461 |
+
`to` must have size of at least N bytes.
|
| 462 |
+
|
| 463 |
+
If the `to[N-1]` has null value, then replace it and all the
|
| 464 |
+
preceding, nulls with the given padding.
|
| 465 |
+
|
| 466 |
+
STRINGPADN(to, N, PADDING, NULLVALUE) is an inverse operation.
|
| 467 |
+
*/
|
| 468 |
+
#define STRINGPADN(to, N, NULLVALUE, PADDING) \\
|
| 469 |
+
do { \\
|
| 470 |
+
int _m = (N); \\
|
| 471 |
+
char *_to = (to); \\
|
| 472 |
+
for (_m -= 1; _m >= 0 && _to[_m] == NULLVALUE; _m--) { \\
|
| 473 |
+
_to[_m] = PADDING; \\
|
| 474 |
+
} \\
|
| 475 |
+
} while (0)
|
| 476 |
+
"""
|
| 477 |
+
needs['STRINGCOPYN'] = ['string.h', 'FAILNULL']
|
| 478 |
+
cppmacros['STRINGCOPYN'] = """\
|
| 479 |
+
/*
|
| 480 |
+
STRINGCOPYN copies N bytes.
|
| 481 |
+
|
| 482 |
+
`to` and `from` buffers must have sizes of at least N bytes.
|
| 483 |
+
*/
|
| 484 |
+
#define STRINGCOPYN(to,from,N) \\
|
| 485 |
+
do { \\
|
| 486 |
+
int _m = (N); \\
|
| 487 |
+
char *_to = (to); \\
|
| 488 |
+
char *_from = (from); \\
|
| 489 |
+
FAILNULL(_to); FAILNULL(_from); \\
|
| 490 |
+
(void)strncpy(_to, _from, _m); \\
|
| 491 |
+
} while (0)
|
| 492 |
+
"""
|
| 493 |
+
needs['STRINGCOPY'] = ['string.h', 'FAILNULL']
|
| 494 |
+
cppmacros['STRINGCOPY'] = """\
|
| 495 |
+
#define STRINGCOPY(to,from)\\
|
| 496 |
+
do { FAILNULL(to); FAILNULL(from); (void)strcpy(to,from); } while (0)
|
| 497 |
+
"""
|
| 498 |
+
cppmacros['CHECKGENERIC'] = """\
|
| 499 |
+
#define CHECKGENERIC(check,tcheck,name) \\
|
| 500 |
+
if (!(check)) {\\
|
| 501 |
+
PyErr_SetString(#modulename#_error,\"(\"tcheck\") failed for \"name);\\
|
| 502 |
+
/*goto capi_fail;*/\\
|
| 503 |
+
} else """
|
| 504 |
+
cppmacros['CHECKARRAY'] = """\
|
| 505 |
+
#define CHECKARRAY(check,tcheck,name) \\
|
| 506 |
+
if (!(check)) {\\
|
| 507 |
+
PyErr_SetString(#modulename#_error,\"(\"tcheck\") failed for \"name);\\
|
| 508 |
+
/*goto capi_fail;*/\\
|
| 509 |
+
} else """
|
| 510 |
+
cppmacros['CHECKSTRING'] = """\
|
| 511 |
+
#define CHECKSTRING(check,tcheck,name,show,var)\\
|
| 512 |
+
if (!(check)) {\\
|
| 513 |
+
char errstring[256];\\
|
| 514 |
+
sprintf(errstring, \"%s: \"show, \"(\"tcheck\") failed for \"name, slen(var), var);\\
|
| 515 |
+
PyErr_SetString(#modulename#_error, errstring);\\
|
| 516 |
+
/*goto capi_fail;*/\\
|
| 517 |
+
} else """
|
| 518 |
+
cppmacros['CHECKSCALAR'] = """\
|
| 519 |
+
#define CHECKSCALAR(check,tcheck,name,show,var)\\
|
| 520 |
+
if (!(check)) {\\
|
| 521 |
+
char errstring[256];\\
|
| 522 |
+
sprintf(errstring, \"%s: \"show, \"(\"tcheck\") failed for \"name, var);\\
|
| 523 |
+
PyErr_SetString(#modulename#_error,errstring);\\
|
| 524 |
+
/*goto capi_fail;*/\\
|
| 525 |
+
} else """
|
| 526 |
+
# cppmacros['CHECKDIMS']="""\
|
| 527 |
+
# define CHECKDIMS(dims,rank) \\
|
| 528 |
+
# for (int i=0;i<(rank);i++)\\
|
| 529 |
+
# if (dims[i]<0) {\\
|
| 530 |
+
# fprintf(stderr,\"Unspecified array argument requires a complete dimension specification.\\n\");\\
|
| 531 |
+
# goto capi_fail;\\
|
| 532 |
+
# }
|
| 533 |
+
# """
|
| 534 |
+
cppmacros[
|
| 535 |
+
'ARRSIZE'] = '#define ARRSIZE(dims,rank) (_PyArray_multiply_list(dims,rank))'
|
| 536 |
+
cppmacros['OLDPYNUM'] = """\
|
| 537 |
+
#ifdef OLDPYNUM
|
| 538 |
+
#error You need to install NumPy version 0.13 or higher. See https://scipy.org/install.html
|
| 539 |
+
#endif
|
| 540 |
+
"""
|
| 541 |
+
cppmacros["F2PY_THREAD_LOCAL_DECL"] = """\
|
| 542 |
+
#ifndef F2PY_THREAD_LOCAL_DECL
|
| 543 |
+
#if defined(_MSC_VER)
|
| 544 |
+
#define F2PY_THREAD_LOCAL_DECL __declspec(thread)
|
| 545 |
+
#elif defined(NPY_OS_MINGW)
|
| 546 |
+
#define F2PY_THREAD_LOCAL_DECL __thread
|
| 547 |
+
#elif defined(__STDC_VERSION__) \\
|
| 548 |
+
&& (__STDC_VERSION__ >= 201112L) \\
|
| 549 |
+
&& !defined(__STDC_NO_THREADS__) \\
|
| 550 |
+
&& (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12)) \\
|
| 551 |
+
&& !defined(NPY_OS_OPENBSD) && !defined(NPY_OS_HAIKU)
|
| 552 |
+
/* __STDC_NO_THREADS__ was first defined in a maintenance release of glibc 2.12,
|
| 553 |
+
see https://lists.gnu.org/archive/html/commit-hurd/2012-07/msg00180.html,
|
| 554 |
+
so `!defined(__STDC_NO_THREADS__)` may give false positive for the existence
|
| 555 |
+
of `threads.h` when using an older release of glibc 2.12
|
| 556 |
+
See gh-19437 for details on OpenBSD */
|
| 557 |
+
#include <threads.h>
|
| 558 |
+
#define F2PY_THREAD_LOCAL_DECL thread_local
|
| 559 |
+
#elif defined(__GNUC__) \\
|
| 560 |
+
&& (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 4)))
|
| 561 |
+
#define F2PY_THREAD_LOCAL_DECL __thread
|
| 562 |
+
#endif
|
| 563 |
+
#endif
|
| 564 |
+
"""
|
| 565 |
+
################# C functions ###############
|
| 566 |
+
|
| 567 |
+
cfuncs['calcarrindex'] = """\
|
| 568 |
+
static int calcarrindex(int *i,PyArrayObject *arr) {
|
| 569 |
+
int k,ii = i[0];
|
| 570 |
+
for (k=1; k < PyArray_NDIM(arr); k++)
|
| 571 |
+
ii += (ii*(PyArray_DIM(arr,k) - 1)+i[k]); /* assuming contiguous arr */
|
| 572 |
+
return ii;
|
| 573 |
+
}"""
|
| 574 |
+
cfuncs['calcarrindextr'] = """\
|
| 575 |
+
static int calcarrindextr(int *i,PyArrayObject *arr) {
|
| 576 |
+
int k,ii = i[PyArray_NDIM(arr)-1];
|
| 577 |
+
for (k=1; k < PyArray_NDIM(arr); k++)
|
| 578 |
+
ii += (ii*(PyArray_DIM(arr,PyArray_NDIM(arr)-k-1) - 1)+i[PyArray_NDIM(arr)-k-1]); /* assuming contiguous arr */
|
| 579 |
+
return ii;
|
| 580 |
+
}"""
|
| 581 |
+
cfuncs['forcomb'] = """\
|
| 582 |
+
static struct { int nd;npy_intp *d;int *i,*i_tr,tr; } forcombcache;
|
| 583 |
+
static int initforcomb(npy_intp *dims,int nd,int tr) {
|
| 584 |
+
int k;
|
| 585 |
+
if (dims==NULL) return 0;
|
| 586 |
+
if (nd<0) return 0;
|
| 587 |
+
forcombcache.nd = nd;
|
| 588 |
+
forcombcache.d = dims;
|
| 589 |
+
forcombcache.tr = tr;
|
| 590 |
+
if ((forcombcache.i = (int *)malloc(sizeof(int)*nd))==NULL) return 0;
|
| 591 |
+
if ((forcombcache.i_tr = (int *)malloc(sizeof(int)*nd))==NULL) return 0;
|
| 592 |
+
for (k=1;k<nd;k++) {
|
| 593 |
+
forcombcache.i[k] = forcombcache.i_tr[nd-k-1] = 0;
|
| 594 |
+
}
|
| 595 |
+
forcombcache.i[0] = forcombcache.i_tr[nd-1] = -1;
|
| 596 |
+
return 1;
|
| 597 |
+
}
|
| 598 |
+
static int *nextforcomb(void) {
|
| 599 |
+
int j,*i,*i_tr,k;
|
| 600 |
+
int nd=forcombcache.nd;
|
| 601 |
+
if ((i=forcombcache.i) == NULL) return NULL;
|
| 602 |
+
if ((i_tr=forcombcache.i_tr) == NULL) return NULL;
|
| 603 |
+
if (forcombcache.d == NULL) return NULL;
|
| 604 |
+
i[0]++;
|
| 605 |
+
if (i[0]==forcombcache.d[0]) {
|
| 606 |
+
j=1;
|
| 607 |
+
while ((j<nd) && (i[j]==forcombcache.d[j]-1)) j++;
|
| 608 |
+
if (j==nd) {
|
| 609 |
+
free(i);
|
| 610 |
+
free(i_tr);
|
| 611 |
+
return NULL;
|
| 612 |
+
}
|
| 613 |
+
for (k=0;k<j;k++) i[k] = i_tr[nd-k-1] = 0;
|
| 614 |
+
i[j]++;
|
| 615 |
+
i_tr[nd-j-1]++;
|
| 616 |
+
} else
|
| 617 |
+
i_tr[nd-1]++;
|
| 618 |
+
if (forcombcache.tr) return i_tr;
|
| 619 |
+
return i;
|
| 620 |
+
}"""
|
| 621 |
+
needs['try_pyarr_from_string'] = ['STRINGCOPYN', 'PRINTPYOBJERR', 'string']
|
| 622 |
+
cfuncs['try_pyarr_from_string'] = """\
|
| 623 |
+
/*
|
| 624 |
+
try_pyarr_from_string copies str[:len(obj)] to the data of an `ndarray`.
|
| 625 |
+
|
| 626 |
+
If obj is an `ndarray`, it is assumed to be contiguous.
|
| 627 |
+
|
| 628 |
+
If the specified len==-1, str must be null-terminated.
|
| 629 |
+
*/
|
| 630 |
+
static int try_pyarr_from_string(PyObject *obj,
|
| 631 |
+
const string str, const int len) {
|
| 632 |
+
#ifdef DEBUGCFUNCS
|
| 633 |
+
fprintf(stderr, "try_pyarr_from_string(str='%s', len=%d, obj=%p)\\n",
|
| 634 |
+
(char*)str,len, obj);
|
| 635 |
+
#endif
|
| 636 |
+
if (PyArray_Check(obj)) {
|
| 637 |
+
PyArrayObject *arr = (PyArrayObject *)obj;
|
| 638 |
+
assert(ISCONTIGUOUS(arr));
|
| 639 |
+
string buf = PyArray_DATA(arr);
|
| 640 |
+
npy_intp n = len;
|
| 641 |
+
if (n == -1) {
|
| 642 |
+
/* Assuming null-terminated str. */
|
| 643 |
+
n = strlen(str);
|
| 644 |
+
}
|
| 645 |
+
if (n > PyArray_NBYTES(arr)) {
|
| 646 |
+
n = PyArray_NBYTES(arr);
|
| 647 |
+
}
|
| 648 |
+
STRINGCOPYN(buf, str, n);
|
| 649 |
+
return 1;
|
| 650 |
+
}
|
| 651 |
+
capi_fail:
|
| 652 |
+
PRINTPYOBJERR(obj);
|
| 653 |
+
PyErr_SetString(#modulename#_error, \"try_pyarr_from_string failed\");
|
| 654 |
+
return 0;
|
| 655 |
+
}
|
| 656 |
+
"""
|
| 657 |
+
needs['string_from_pyobj'] = ['string', 'STRINGMALLOC', 'STRINGCOPYN']
|
| 658 |
+
cfuncs['string_from_pyobj'] = """\
|
| 659 |
+
/*
|
| 660 |
+
Create a new string buffer `str` of at most length `len` from a
|
| 661 |
+
Python string-like object `obj`.
|
| 662 |
+
|
| 663 |
+
The string buffer has given size (len) or the size of inistr when len==-1.
|
| 664 |
+
|
| 665 |
+
The string buffer is padded with blanks: in Fortran, trailing blanks
|
| 666 |
+
are insignificant contrary to C nulls.
|
| 667 |
+
*/
|
| 668 |
+
static int
|
| 669 |
+
string_from_pyobj(string *str, int *len, const string inistr, PyObject *obj,
|
| 670 |
+
const char *errmess)
|
| 671 |
+
{
|
| 672 |
+
PyObject *tmp = NULL;
|
| 673 |
+
string buf = NULL;
|
| 674 |
+
npy_intp n = -1;
|
| 675 |
+
#ifdef DEBUGCFUNCS
|
| 676 |
+
fprintf(stderr,\"string_from_pyobj(str='%s',len=%d,inistr='%s',obj=%p)\\n\",
|
| 677 |
+
(char*)str, *len, (char *)inistr, obj);
|
| 678 |
+
#endif
|
| 679 |
+
if (obj == Py_None) {
|
| 680 |
+
n = strlen(inistr);
|
| 681 |
+
buf = inistr;
|
| 682 |
+
}
|
| 683 |
+
else if (PyArray_Check(obj)) {
|
| 684 |
+
PyArrayObject *arr = (PyArrayObject *)obj;
|
| 685 |
+
if (!ISCONTIGUOUS(arr)) {
|
| 686 |
+
PyErr_SetString(PyExc_ValueError,
|
| 687 |
+
\"array object is non-contiguous.\");
|
| 688 |
+
goto capi_fail;
|
| 689 |
+
}
|
| 690 |
+
n = PyArray_NBYTES(arr);
|
| 691 |
+
buf = PyArray_DATA(arr);
|
| 692 |
+
n = strnlen(buf, n);
|
| 693 |
+
}
|
| 694 |
+
else {
|
| 695 |
+
if (PyBytes_Check(obj)) {
|
| 696 |
+
tmp = obj;
|
| 697 |
+
Py_INCREF(tmp);
|
| 698 |
+
}
|
| 699 |
+
else if (PyUnicode_Check(obj)) {
|
| 700 |
+
tmp = PyUnicode_AsASCIIString(obj);
|
| 701 |
+
}
|
| 702 |
+
else {
|
| 703 |
+
PyObject *tmp2;
|
| 704 |
+
tmp2 = PyObject_Str(obj);
|
| 705 |
+
if (tmp2) {
|
| 706 |
+
tmp = PyUnicode_AsASCIIString(tmp2);
|
| 707 |
+
Py_DECREF(tmp2);
|
| 708 |
+
}
|
| 709 |
+
else {
|
| 710 |
+
tmp = NULL;
|
| 711 |
+
}
|
| 712 |
+
}
|
| 713 |
+
if (tmp == NULL) goto capi_fail;
|
| 714 |
+
n = PyBytes_GET_SIZE(tmp);
|
| 715 |
+
buf = PyBytes_AS_STRING(tmp);
|
| 716 |
+
}
|
| 717 |
+
if (*len == -1) {
|
| 718 |
+
/* TODO: change the type of `len` so that we can remove this */
|
| 719 |
+
if (n > NPY_MAX_INT) {
|
| 720 |
+
PyErr_SetString(PyExc_OverflowError,
|
| 721 |
+
"object too large for a 32-bit int");
|
| 722 |
+
goto capi_fail;
|
| 723 |
+
}
|
| 724 |
+
*len = n;
|
| 725 |
+
}
|
| 726 |
+
else if (*len < n) {
|
| 727 |
+
/* discard the last (len-n) bytes of input buf */
|
| 728 |
+
n = *len;
|
| 729 |
+
}
|
| 730 |
+
if (n < 0 || *len < 0 || buf == NULL) {
|
| 731 |
+
goto capi_fail;
|
| 732 |
+
}
|
| 733 |
+
STRINGMALLOC(*str, *len); // *str is allocated with size (*len + 1)
|
| 734 |
+
if (n < *len) {
|
| 735 |
+
/*
|
| 736 |
+
Pad fixed-width string with nulls. The caller will replace
|
| 737 |
+
nulls with blanks when the corresponding argument is not
|
| 738 |
+
intent(c).
|
| 739 |
+
*/
|
| 740 |
+
memset(*str + n, '\\0', *len - n);
|
| 741 |
+
}
|
| 742 |
+
STRINGCOPYN(*str, buf, n);
|
| 743 |
+
Py_XDECREF(tmp);
|
| 744 |
+
return 1;
|
| 745 |
+
capi_fail:
|
| 746 |
+
Py_XDECREF(tmp);
|
| 747 |
+
{
|
| 748 |
+
PyObject* err = PyErr_Occurred();
|
| 749 |
+
if (err == NULL) {
|
| 750 |
+
err = #modulename#_error;
|
| 751 |
+
}
|
| 752 |
+
PyErr_SetString(err, errmess);
|
| 753 |
+
}
|
| 754 |
+
return 0;
|
| 755 |
+
}
|
| 756 |
+
"""
|
| 757 |
+
|
| 758 |
+
cfuncs['character_from_pyobj'] = """\
|
| 759 |
+
static int
|
| 760 |
+
character_from_pyobj(character* v, PyObject *obj, const char *errmess) {
|
| 761 |
+
if (PyBytes_Check(obj)) {
|
| 762 |
+
/* empty bytes has trailing null, so dereferencing is always safe */
|
| 763 |
+
*v = PyBytes_AS_STRING(obj)[0];
|
| 764 |
+
return 1;
|
| 765 |
+
} else if (PyUnicode_Check(obj)) {
|
| 766 |
+
PyObject* tmp = PyUnicode_AsASCIIString(obj);
|
| 767 |
+
if (tmp != NULL) {
|
| 768 |
+
*v = PyBytes_AS_STRING(tmp)[0];
|
| 769 |
+
Py_DECREF(tmp);
|
| 770 |
+
return 1;
|
| 771 |
+
}
|
| 772 |
+
} else if (PyArray_Check(obj)) {
|
| 773 |
+
PyArrayObject* arr = (PyArrayObject*)obj;
|
| 774 |
+
if (F2PY_ARRAY_IS_CHARACTER_COMPATIBLE(arr)) {
|
| 775 |
+
*v = PyArray_BYTES(arr)[0];
|
| 776 |
+
return 1;
|
| 777 |
+
} else if (F2PY_IS_UNICODE_ARRAY(arr)) {
|
| 778 |
+
// TODO: update when numpy will support 1-byte and
|
| 779 |
+
// 2-byte unicode dtypes
|
| 780 |
+
PyObject* tmp = PyUnicode_FromKindAndData(
|
| 781 |
+
PyUnicode_4BYTE_KIND,
|
| 782 |
+
PyArray_BYTES(arr),
|
| 783 |
+
(PyArray_NBYTES(arr)>0?1:0));
|
| 784 |
+
if (tmp != NULL) {
|
| 785 |
+
if (character_from_pyobj(v, tmp, errmess)) {
|
| 786 |
+
Py_DECREF(tmp);
|
| 787 |
+
return 1;
|
| 788 |
+
}
|
| 789 |
+
Py_DECREF(tmp);
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
} else if (PySequence_Check(obj)) {
|
| 793 |
+
PyObject* tmp = PySequence_GetItem(obj,0);
|
| 794 |
+
if (tmp != NULL) {
|
| 795 |
+
if (character_from_pyobj(v, tmp, errmess)) {
|
| 796 |
+
Py_DECREF(tmp);
|
| 797 |
+
return 1;
|
| 798 |
+
}
|
| 799 |
+
Py_DECREF(tmp);
|
| 800 |
+
}
|
| 801 |
+
}
|
| 802 |
+
{
|
| 803 |
+
char mess[F2PY_MESSAGE_BUFFER_SIZE];
|
| 804 |
+
strcpy(mess, errmess);
|
| 805 |
+
PyObject* err = PyErr_Occurred();
|
| 806 |
+
if (err == NULL) {
|
| 807 |
+
err = PyExc_TypeError;
|
| 808 |
+
}
|
| 809 |
+
sprintf(mess + strlen(mess),
|
| 810 |
+
" -- expected str|bytes|sequence-of-str-or-bytes, got ");
|
| 811 |
+
f2py_describe(obj, mess + strlen(mess));
|
| 812 |
+
PyErr_SetString(err, mess);
|
| 813 |
+
}
|
| 814 |
+
return 0;
|
| 815 |
+
}
|
| 816 |
+
"""
|
| 817 |
+
|
| 818 |
+
needs['char_from_pyobj'] = ['int_from_pyobj']
|
| 819 |
+
cfuncs['char_from_pyobj'] = """\
|
| 820 |
+
static int
|
| 821 |
+
char_from_pyobj(char* v, PyObject *obj, const char *errmess) {
|
| 822 |
+
int i = 0;
|
| 823 |
+
if (int_from_pyobj(&i, obj, errmess)) {
|
| 824 |
+
*v = (char)i;
|
| 825 |
+
return 1;
|
| 826 |
+
}
|
| 827 |
+
return 0;
|
| 828 |
+
}
|
| 829 |
+
"""
|
| 830 |
+
|
| 831 |
+
|
| 832 |
+
needs['signed_char_from_pyobj'] = ['int_from_pyobj', 'signed_char']
|
| 833 |
+
cfuncs['signed_char_from_pyobj'] = """\
|
| 834 |
+
static int
|
| 835 |
+
signed_char_from_pyobj(signed_char* v, PyObject *obj, const char *errmess) {
|
| 836 |
+
int i = 0;
|
| 837 |
+
if (int_from_pyobj(&i, obj, errmess)) {
|
| 838 |
+
*v = (signed_char)i;
|
| 839 |
+
return 1;
|
| 840 |
+
}
|
| 841 |
+
return 0;
|
| 842 |
+
}
|
| 843 |
+
"""
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
needs['short_from_pyobj'] = ['int_from_pyobj']
|
| 847 |
+
cfuncs['short_from_pyobj'] = """\
|
| 848 |
+
static int
|
| 849 |
+
short_from_pyobj(short* v, PyObject *obj, const char *errmess) {
|
| 850 |
+
int i = 0;
|
| 851 |
+
if (int_from_pyobj(&i, obj, errmess)) {
|
| 852 |
+
*v = (short)i;
|
| 853 |
+
return 1;
|
| 854 |
+
}
|
| 855 |
+
return 0;
|
| 856 |
+
}
|
| 857 |
+
"""
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
cfuncs['int_from_pyobj'] = """\
|
| 861 |
+
static int
|
| 862 |
+
int_from_pyobj(int* v, PyObject *obj, const char *errmess)
|
| 863 |
+
{
|
| 864 |
+
PyObject* tmp = NULL;
|
| 865 |
+
|
| 866 |
+
if (PyLong_Check(obj)) {
|
| 867 |
+
*v = Npy__PyLong_AsInt(obj);
|
| 868 |
+
return !(*v == -1 && PyErr_Occurred());
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
tmp = PyNumber_Long(obj);
|
| 872 |
+
if (tmp) {
|
| 873 |
+
*v = Npy__PyLong_AsInt(tmp);
|
| 874 |
+
Py_DECREF(tmp);
|
| 875 |
+
return !(*v == -1 && PyErr_Occurred());
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
if (PyComplex_Check(obj)) {
|
| 879 |
+
PyErr_Clear();
|
| 880 |
+
tmp = PyObject_GetAttrString(obj,\"real\");
|
| 881 |
+
}
|
| 882 |
+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
|
| 883 |
+
/*pass*/;
|
| 884 |
+
}
|
| 885 |
+
else if (PySequence_Check(obj)) {
|
| 886 |
+
PyErr_Clear();
|
| 887 |
+
tmp = PySequence_GetItem(obj, 0);
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
if (tmp) {
|
| 891 |
+
if (int_from_pyobj(v, tmp, errmess)) {
|
| 892 |
+
Py_DECREF(tmp);
|
| 893 |
+
return 1;
|
| 894 |
+
}
|
| 895 |
+
Py_DECREF(tmp);
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
{
|
| 899 |
+
PyObject* err = PyErr_Occurred();
|
| 900 |
+
if (err == NULL) {
|
| 901 |
+
err = #modulename#_error;
|
| 902 |
+
}
|
| 903 |
+
PyErr_SetString(err, errmess);
|
| 904 |
+
}
|
| 905 |
+
return 0;
|
| 906 |
+
}
|
| 907 |
+
"""
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
cfuncs['long_from_pyobj'] = """\
|
| 911 |
+
static int
|
| 912 |
+
long_from_pyobj(long* v, PyObject *obj, const char *errmess) {
|
| 913 |
+
PyObject* tmp = NULL;
|
| 914 |
+
|
| 915 |
+
if (PyLong_Check(obj)) {
|
| 916 |
+
*v = PyLong_AsLong(obj);
|
| 917 |
+
return !(*v == -1 && PyErr_Occurred());
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
tmp = PyNumber_Long(obj);
|
| 921 |
+
if (tmp) {
|
| 922 |
+
*v = PyLong_AsLong(tmp);
|
| 923 |
+
Py_DECREF(tmp);
|
| 924 |
+
return !(*v == -1 && PyErr_Occurred());
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
if (PyComplex_Check(obj)) {
|
| 928 |
+
PyErr_Clear();
|
| 929 |
+
tmp = PyObject_GetAttrString(obj,\"real\");
|
| 930 |
+
}
|
| 931 |
+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
|
| 932 |
+
/*pass*/;
|
| 933 |
+
}
|
| 934 |
+
else if (PySequence_Check(obj)) {
|
| 935 |
+
PyErr_Clear();
|
| 936 |
+
tmp = PySequence_GetItem(obj, 0);
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
if (tmp) {
|
| 940 |
+
if (long_from_pyobj(v, tmp, errmess)) {
|
| 941 |
+
Py_DECREF(tmp);
|
| 942 |
+
return 1;
|
| 943 |
+
}
|
| 944 |
+
Py_DECREF(tmp);
|
| 945 |
+
}
|
| 946 |
+
{
|
| 947 |
+
PyObject* err = PyErr_Occurred();
|
| 948 |
+
if (err == NULL) {
|
| 949 |
+
err = #modulename#_error;
|
| 950 |
+
}
|
| 951 |
+
PyErr_SetString(err, errmess);
|
| 952 |
+
}
|
| 953 |
+
return 0;
|
| 954 |
+
}
|
| 955 |
+
"""
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
needs['long_long_from_pyobj'] = ['long_long']
|
| 959 |
+
cfuncs['long_long_from_pyobj'] = """\
|
| 960 |
+
static int
|
| 961 |
+
long_long_from_pyobj(long_long* v, PyObject *obj, const char *errmess)
|
| 962 |
+
{
|
| 963 |
+
PyObject* tmp = NULL;
|
| 964 |
+
|
| 965 |
+
if (PyLong_Check(obj)) {
|
| 966 |
+
*v = PyLong_AsLongLong(obj);
|
| 967 |
+
return !(*v == -1 && PyErr_Occurred());
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
tmp = PyNumber_Long(obj);
|
| 971 |
+
if (tmp) {
|
| 972 |
+
*v = PyLong_AsLongLong(tmp);
|
| 973 |
+
Py_DECREF(tmp);
|
| 974 |
+
return !(*v == -1 && PyErr_Occurred());
|
| 975 |
+
}
|
| 976 |
+
|
| 977 |
+
if (PyComplex_Check(obj)) {
|
| 978 |
+
PyErr_Clear();
|
| 979 |
+
tmp = PyObject_GetAttrString(obj,\"real\");
|
| 980 |
+
}
|
| 981 |
+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
|
| 982 |
+
/*pass*/;
|
| 983 |
+
}
|
| 984 |
+
else if (PySequence_Check(obj)) {
|
| 985 |
+
PyErr_Clear();
|
| 986 |
+
tmp = PySequence_GetItem(obj, 0);
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
if (tmp) {
|
| 990 |
+
if (long_long_from_pyobj(v, tmp, errmess)) {
|
| 991 |
+
Py_DECREF(tmp);
|
| 992 |
+
return 1;
|
| 993 |
+
}
|
| 994 |
+
Py_DECREF(tmp);
|
| 995 |
+
}
|
| 996 |
+
{
|
| 997 |
+
PyObject* err = PyErr_Occurred();
|
| 998 |
+
if (err == NULL) {
|
| 999 |
+
err = #modulename#_error;
|
| 1000 |
+
}
|
| 1001 |
+
PyErr_SetString(err,errmess);
|
| 1002 |
+
}
|
| 1003 |
+
return 0;
|
| 1004 |
+
}
|
| 1005 |
+
"""
|
| 1006 |
+
|
| 1007 |
+
|
| 1008 |
+
needs['long_double_from_pyobj'] = ['double_from_pyobj', 'long_double']
|
| 1009 |
+
cfuncs['long_double_from_pyobj'] = """\
|
| 1010 |
+
static int
|
| 1011 |
+
long_double_from_pyobj(long_double* v, PyObject *obj, const char *errmess)
|
| 1012 |
+
{
|
| 1013 |
+
double d=0;
|
| 1014 |
+
if (PyArray_CheckScalar(obj)){
|
| 1015 |
+
if PyArray_IsScalar(obj, LongDouble) {
|
| 1016 |
+
PyArray_ScalarAsCtype(obj, v);
|
| 1017 |
+
return 1;
|
| 1018 |
+
}
|
| 1019 |
+
else if (PyArray_Check(obj) && PyArray_TYPE(obj) == NPY_LONGDOUBLE) {
|
| 1020 |
+
(*v) = *((npy_longdouble *)PyArray_DATA(obj));
|
| 1021 |
+
return 1;
|
| 1022 |
+
}
|
| 1023 |
+
}
|
| 1024 |
+
if (double_from_pyobj(&d, obj, errmess)) {
|
| 1025 |
+
*v = (long_double)d;
|
| 1026 |
+
return 1;
|
| 1027 |
+
}
|
| 1028 |
+
return 0;
|
| 1029 |
+
}
|
| 1030 |
+
"""
|
| 1031 |
+
|
| 1032 |
+
|
| 1033 |
+
cfuncs['double_from_pyobj'] = """\
|
| 1034 |
+
static int
|
| 1035 |
+
double_from_pyobj(double* v, PyObject *obj, const char *errmess)
|
| 1036 |
+
{
|
| 1037 |
+
PyObject* tmp = NULL;
|
| 1038 |
+
if (PyFloat_Check(obj)) {
|
| 1039 |
+
*v = PyFloat_AsDouble(obj);
|
| 1040 |
+
return !(*v == -1.0 && PyErr_Occurred());
|
| 1041 |
+
}
|
| 1042 |
+
|
| 1043 |
+
tmp = PyNumber_Float(obj);
|
| 1044 |
+
if (tmp) {
|
| 1045 |
+
*v = PyFloat_AsDouble(tmp);
|
| 1046 |
+
Py_DECREF(tmp);
|
| 1047 |
+
return !(*v == -1.0 && PyErr_Occurred());
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
if (PyComplex_Check(obj)) {
|
| 1051 |
+
PyErr_Clear();
|
| 1052 |
+
tmp = PyObject_GetAttrString(obj,\"real\");
|
| 1053 |
+
}
|
| 1054 |
+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
|
| 1055 |
+
/*pass*/;
|
| 1056 |
+
}
|
| 1057 |
+
else if (PySequence_Check(obj)) {
|
| 1058 |
+
PyErr_Clear();
|
| 1059 |
+
tmp = PySequence_GetItem(obj, 0);
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
if (tmp) {
|
| 1063 |
+
if (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
|
| 1064 |
+
Py_DECREF(tmp);
|
| 1065 |
+
}
|
| 1066 |
+
{
|
| 1067 |
+
PyObject* err = PyErr_Occurred();
|
| 1068 |
+
if (err==NULL) err = #modulename#_error;
|
| 1069 |
+
PyErr_SetString(err,errmess);
|
| 1070 |
+
}
|
| 1071 |
+
return 0;
|
| 1072 |
+
}
|
| 1073 |
+
"""
|
| 1074 |
+
|
| 1075 |
+
|
| 1076 |
+
needs['float_from_pyobj'] = ['double_from_pyobj']
|
| 1077 |
+
cfuncs['float_from_pyobj'] = """\
|
| 1078 |
+
static int
|
| 1079 |
+
float_from_pyobj(float* v, PyObject *obj, const char *errmess)
|
| 1080 |
+
{
|
| 1081 |
+
double d=0.0;
|
| 1082 |
+
if (double_from_pyobj(&d,obj,errmess)) {
|
| 1083 |
+
*v = (float)d;
|
| 1084 |
+
return 1;
|
| 1085 |
+
}
|
| 1086 |
+
return 0;
|
| 1087 |
+
}
|
| 1088 |
+
"""
|
| 1089 |
+
|
| 1090 |
+
|
| 1091 |
+
needs['complex_long_double_from_pyobj'] = ['complex_long_double', 'long_double',
|
| 1092 |
+
'complex_double_from_pyobj']
|
| 1093 |
+
cfuncs['complex_long_double_from_pyobj'] = """\
|
| 1094 |
+
static int
|
| 1095 |
+
complex_long_double_from_pyobj(complex_long_double* v, PyObject *obj, const char *errmess)
|
| 1096 |
+
{
|
| 1097 |
+
complex_double cd = {0.0,0.0};
|
| 1098 |
+
if (PyArray_CheckScalar(obj)){
|
| 1099 |
+
if PyArray_IsScalar(obj, CLongDouble) {
|
| 1100 |
+
PyArray_ScalarAsCtype(obj, v);
|
| 1101 |
+
return 1;
|
| 1102 |
+
}
|
| 1103 |
+
else if (PyArray_Check(obj) && PyArray_TYPE(obj)==NPY_CLONGDOUBLE) {
|
| 1104 |
+
(*v).r = ((npy_clongdouble *)PyArray_DATA(obj))->real;
|
| 1105 |
+
(*v).i = ((npy_clongdouble *)PyArray_DATA(obj))->imag;
|
| 1106 |
+
return 1;
|
| 1107 |
+
}
|
| 1108 |
+
}
|
| 1109 |
+
if (complex_double_from_pyobj(&cd,obj,errmess)) {
|
| 1110 |
+
(*v).r = (long_double)cd.r;
|
| 1111 |
+
(*v).i = (long_double)cd.i;
|
| 1112 |
+
return 1;
|
| 1113 |
+
}
|
| 1114 |
+
return 0;
|
| 1115 |
+
}
|
| 1116 |
+
"""
|
| 1117 |
+
|
| 1118 |
+
|
| 1119 |
+
needs['complex_double_from_pyobj'] = ['complex_double']
|
| 1120 |
+
cfuncs['complex_double_from_pyobj'] = """\
|
| 1121 |
+
static int
|
| 1122 |
+
complex_double_from_pyobj(complex_double* v, PyObject *obj, const char *errmess) {
|
| 1123 |
+
Py_complex c;
|
| 1124 |
+
if (PyComplex_Check(obj)) {
|
| 1125 |
+
c = PyComplex_AsCComplex(obj);
|
| 1126 |
+
(*v).r = c.real;
|
| 1127 |
+
(*v).i = c.imag;
|
| 1128 |
+
return 1;
|
| 1129 |
+
}
|
| 1130 |
+
if (PyArray_IsScalar(obj, ComplexFloating)) {
|
| 1131 |
+
if (PyArray_IsScalar(obj, CFloat)) {
|
| 1132 |
+
npy_cfloat new;
|
| 1133 |
+
PyArray_ScalarAsCtype(obj, &new);
|
| 1134 |
+
(*v).r = (double)new.real;
|
| 1135 |
+
(*v).i = (double)new.imag;
|
| 1136 |
+
}
|
| 1137 |
+
else if (PyArray_IsScalar(obj, CLongDouble)) {
|
| 1138 |
+
npy_clongdouble new;
|
| 1139 |
+
PyArray_ScalarAsCtype(obj, &new);
|
| 1140 |
+
(*v).r = (double)new.real;
|
| 1141 |
+
(*v).i = (double)new.imag;
|
| 1142 |
+
}
|
| 1143 |
+
else { /* if (PyArray_IsScalar(obj, CDouble)) */
|
| 1144 |
+
PyArray_ScalarAsCtype(obj, v);
|
| 1145 |
+
}
|
| 1146 |
+
return 1;
|
| 1147 |
+
}
|
| 1148 |
+
if (PyArray_CheckScalar(obj)) { /* 0-dim array or still array scalar */
|
| 1149 |
+
PyArrayObject *arr;
|
| 1150 |
+
if (PyArray_Check(obj)) {
|
| 1151 |
+
arr = (PyArrayObject *)PyArray_Cast((PyArrayObject *)obj, NPY_CDOUBLE);
|
| 1152 |
+
}
|
| 1153 |
+
else {
|
| 1154 |
+
arr = (PyArrayObject *)PyArray_FromScalar(obj, PyArray_DescrFromType(NPY_CDOUBLE));
|
| 1155 |
+
}
|
| 1156 |
+
if (arr == NULL) {
|
| 1157 |
+
return 0;
|
| 1158 |
+
}
|
| 1159 |
+
(*v).r = ((npy_cdouble *)PyArray_DATA(arr))->real;
|
| 1160 |
+
(*v).i = ((npy_cdouble *)PyArray_DATA(arr))->imag;
|
| 1161 |
+
Py_DECREF(arr);
|
| 1162 |
+
return 1;
|
| 1163 |
+
}
|
| 1164 |
+
/* Python does not provide PyNumber_Complex function :-( */
|
| 1165 |
+
(*v).i = 0.0;
|
| 1166 |
+
if (PyFloat_Check(obj)) {
|
| 1167 |
+
(*v).r = PyFloat_AsDouble(obj);
|
| 1168 |
+
return !((*v).r == -1.0 && PyErr_Occurred());
|
| 1169 |
+
}
|
| 1170 |
+
if (PyLong_Check(obj)) {
|
| 1171 |
+
(*v).r = PyLong_AsDouble(obj);
|
| 1172 |
+
return !((*v).r == -1.0 && PyErr_Occurred());
|
| 1173 |
+
}
|
| 1174 |
+
if (PySequence_Check(obj) && !(PyBytes_Check(obj) || PyUnicode_Check(obj))) {
|
| 1175 |
+
PyObject *tmp = PySequence_GetItem(obj,0);
|
| 1176 |
+
if (tmp) {
|
| 1177 |
+
if (complex_double_from_pyobj(v,tmp,errmess)) {
|
| 1178 |
+
Py_DECREF(tmp);
|
| 1179 |
+
return 1;
|
| 1180 |
+
}
|
| 1181 |
+
Py_DECREF(tmp);
|
| 1182 |
+
}
|
| 1183 |
+
}
|
| 1184 |
+
{
|
| 1185 |
+
PyObject* err = PyErr_Occurred();
|
| 1186 |
+
if (err==NULL)
|
| 1187 |
+
err = PyExc_TypeError;
|
| 1188 |
+
PyErr_SetString(err,errmess);
|
| 1189 |
+
}
|
| 1190 |
+
return 0;
|
| 1191 |
+
}
|
| 1192 |
+
"""
|
| 1193 |
+
|
| 1194 |
+
|
| 1195 |
+
needs['complex_float_from_pyobj'] = [
|
| 1196 |
+
'complex_float', 'complex_double_from_pyobj']
|
| 1197 |
+
cfuncs['complex_float_from_pyobj'] = """\
|
| 1198 |
+
static int
|
| 1199 |
+
complex_float_from_pyobj(complex_float* v,PyObject *obj,const char *errmess)
|
| 1200 |
+
{
|
| 1201 |
+
complex_double cd={0.0,0.0};
|
| 1202 |
+
if (complex_double_from_pyobj(&cd,obj,errmess)) {
|
| 1203 |
+
(*v).r = (float)cd.r;
|
| 1204 |
+
(*v).i = (float)cd.i;
|
| 1205 |
+
return 1;
|
| 1206 |
+
}
|
| 1207 |
+
return 0;
|
| 1208 |
+
}
|
| 1209 |
+
"""
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
cfuncs['try_pyarr_from_character'] = """\
|
| 1213 |
+
static int try_pyarr_from_character(PyObject* obj, character* v) {
|
| 1214 |
+
PyArrayObject *arr = (PyArrayObject*)obj;
|
| 1215 |
+
if (!obj) return -2;
|
| 1216 |
+
if (PyArray_Check(obj)) {
|
| 1217 |
+
if (F2PY_ARRAY_IS_CHARACTER_COMPATIBLE(arr)) {
|
| 1218 |
+
*(character *)(PyArray_DATA(arr)) = *v;
|
| 1219 |
+
return 1;
|
| 1220 |
+
}
|
| 1221 |
+
}
|
| 1222 |
+
{
|
| 1223 |
+
char mess[F2PY_MESSAGE_BUFFER_SIZE];
|
| 1224 |
+
PyObject* err = PyErr_Occurred();
|
| 1225 |
+
if (err == NULL) {
|
| 1226 |
+
err = PyExc_ValueError;
|
| 1227 |
+
strcpy(mess, "try_pyarr_from_character failed"
|
| 1228 |
+
" -- expected bytes array-scalar|array, got ");
|
| 1229 |
+
f2py_describe(obj, mess + strlen(mess));
|
| 1230 |
+
}
|
| 1231 |
+
PyErr_SetString(err, mess);
|
| 1232 |
+
}
|
| 1233 |
+
return 0;
|
| 1234 |
+
}
|
| 1235 |
+
"""
|
| 1236 |
+
|
| 1237 |
+
needs['try_pyarr_from_char'] = ['pyobj_from_char1', 'TRYPYARRAYTEMPLATE']
|
| 1238 |
+
cfuncs[
|
| 1239 |
+
'try_pyarr_from_char'] = 'static int try_pyarr_from_char(PyObject* obj,char* v) {\n TRYPYARRAYTEMPLATE(char,\'c\');\n}\n'
|
| 1240 |
+
needs['try_pyarr_from_signed_char'] = ['TRYPYARRAYTEMPLATE', 'unsigned_char']
|
| 1241 |
+
cfuncs[
|
| 1242 |
+
'try_pyarr_from_unsigned_char'] = 'static int try_pyarr_from_unsigned_char(PyObject* obj,unsigned_char* v) {\n TRYPYARRAYTEMPLATE(unsigned_char,\'b\');\n}\n'
|
| 1243 |
+
needs['try_pyarr_from_signed_char'] = ['TRYPYARRAYTEMPLATE', 'signed_char']
|
| 1244 |
+
cfuncs[
|
| 1245 |
+
'try_pyarr_from_signed_char'] = 'static int try_pyarr_from_signed_char(PyObject* obj,signed_char* v) {\n TRYPYARRAYTEMPLATE(signed_char,\'1\');\n}\n'
|
| 1246 |
+
needs['try_pyarr_from_short'] = ['pyobj_from_short1', 'TRYPYARRAYTEMPLATE']
|
| 1247 |
+
cfuncs[
|
| 1248 |
+
'try_pyarr_from_short'] = 'static int try_pyarr_from_short(PyObject* obj,short* v) {\n TRYPYARRAYTEMPLATE(short,\'s\');\n}\n'
|
| 1249 |
+
needs['try_pyarr_from_int'] = ['pyobj_from_int1', 'TRYPYARRAYTEMPLATE']
|
| 1250 |
+
cfuncs[
|
| 1251 |
+
'try_pyarr_from_int'] = 'static int try_pyarr_from_int(PyObject* obj,int* v) {\n TRYPYARRAYTEMPLATE(int,\'i\');\n}\n'
|
| 1252 |
+
needs['try_pyarr_from_long'] = ['pyobj_from_long1', 'TRYPYARRAYTEMPLATE']
|
| 1253 |
+
cfuncs[
|
| 1254 |
+
'try_pyarr_from_long'] = 'static int try_pyarr_from_long(PyObject* obj,long* v) {\n TRYPYARRAYTEMPLATE(long,\'l\');\n}\n'
|
| 1255 |
+
needs['try_pyarr_from_long_long'] = [
|
| 1256 |
+
'pyobj_from_long_long1', 'TRYPYARRAYTEMPLATE', 'long_long']
|
| 1257 |
+
cfuncs[
|
| 1258 |
+
'try_pyarr_from_long_long'] = 'static int try_pyarr_from_long_long(PyObject* obj,long_long* v) {\n TRYPYARRAYTEMPLATE(long_long,\'L\');\n}\n'
|
| 1259 |
+
needs['try_pyarr_from_float'] = ['pyobj_from_float1', 'TRYPYARRAYTEMPLATE']
|
| 1260 |
+
cfuncs[
|
| 1261 |
+
'try_pyarr_from_float'] = 'static int try_pyarr_from_float(PyObject* obj,float* v) {\n TRYPYARRAYTEMPLATE(float,\'f\');\n}\n'
|
| 1262 |
+
needs['try_pyarr_from_double'] = ['pyobj_from_double1', 'TRYPYARRAYTEMPLATE']
|
| 1263 |
+
cfuncs[
|
| 1264 |
+
'try_pyarr_from_double'] = 'static int try_pyarr_from_double(PyObject* obj,double* v) {\n TRYPYARRAYTEMPLATE(double,\'d\');\n}\n'
|
| 1265 |
+
needs['try_pyarr_from_complex_float'] = [
|
| 1266 |
+
'pyobj_from_complex_float1', 'TRYCOMPLEXPYARRAYTEMPLATE', 'complex_float']
|
| 1267 |
+
cfuncs[
|
| 1268 |
+
'try_pyarr_from_complex_float'] = 'static int try_pyarr_from_complex_float(PyObject* obj,complex_float* v) {\n TRYCOMPLEXPYARRAYTEMPLATE(float,\'F\');\n}\n'
|
| 1269 |
+
needs['try_pyarr_from_complex_double'] = [
|
| 1270 |
+
'pyobj_from_complex_double1', 'TRYCOMPLEXPYARRAYTEMPLATE', 'complex_double']
|
| 1271 |
+
cfuncs[
|
| 1272 |
+
'try_pyarr_from_complex_double'] = 'static int try_pyarr_from_complex_double(PyObject* obj,complex_double* v) {\n TRYCOMPLEXPYARRAYTEMPLATE(double,\'D\');\n}\n'
|
| 1273 |
+
|
| 1274 |
+
|
| 1275 |
+
needs['create_cb_arglist'] = ['CFUNCSMESS', 'PRINTPYOBJERR', 'MINMAX']
|
| 1276 |
+
# create the list of arguments to be used when calling back to python
|
| 1277 |
+
cfuncs['create_cb_arglist'] = """\
|
| 1278 |
+
static int
|
| 1279 |
+
create_cb_arglist(PyObject* fun, PyTupleObject* xa , const int maxnofargs,
|
| 1280 |
+
const int nofoptargs, int *nofargs, PyTupleObject **args,
|
| 1281 |
+
const char *errmess)
|
| 1282 |
+
{
|
| 1283 |
+
PyObject *tmp = NULL;
|
| 1284 |
+
PyObject *tmp_fun = NULL;
|
| 1285 |
+
Py_ssize_t tot, opt, ext, siz, i, di = 0;
|
| 1286 |
+
CFUNCSMESS(\"create_cb_arglist\\n\");
|
| 1287 |
+
tot=opt=ext=siz=0;
|
| 1288 |
+
/* Get the total number of arguments */
|
| 1289 |
+
if (PyFunction_Check(fun)) {
|
| 1290 |
+
tmp_fun = fun;
|
| 1291 |
+
Py_INCREF(tmp_fun);
|
| 1292 |
+
}
|
| 1293 |
+
else {
|
| 1294 |
+
di = 1;
|
| 1295 |
+
if (PyObject_HasAttrString(fun,\"im_func\")) {
|
| 1296 |
+
tmp_fun = PyObject_GetAttrString(fun,\"im_func\");
|
| 1297 |
+
}
|
| 1298 |
+
else if (PyObject_HasAttrString(fun,\"__call__\")) {
|
| 1299 |
+
tmp = PyObject_GetAttrString(fun,\"__call__\");
|
| 1300 |
+
if (PyObject_HasAttrString(tmp,\"im_func\"))
|
| 1301 |
+
tmp_fun = PyObject_GetAttrString(tmp,\"im_func\");
|
| 1302 |
+
else {
|
| 1303 |
+
tmp_fun = fun; /* built-in function */
|
| 1304 |
+
Py_INCREF(tmp_fun);
|
| 1305 |
+
tot = maxnofargs;
|
| 1306 |
+
if (PyCFunction_Check(fun)) {
|
| 1307 |
+
/* In case the function has a co_argcount (like on PyPy) */
|
| 1308 |
+
di = 0;
|
| 1309 |
+
}
|
| 1310 |
+
if (xa != NULL)
|
| 1311 |
+
tot += PyTuple_Size((PyObject *)xa);
|
| 1312 |
+
}
|
| 1313 |
+
Py_XDECREF(tmp);
|
| 1314 |
+
}
|
| 1315 |
+
else if (PyFortran_Check(fun) || PyFortran_Check1(fun)) {
|
| 1316 |
+
tot = maxnofargs;
|
| 1317 |
+
if (xa != NULL)
|
| 1318 |
+
tot += PyTuple_Size((PyObject *)xa);
|
| 1319 |
+
tmp_fun = fun;
|
| 1320 |
+
Py_INCREF(tmp_fun);
|
| 1321 |
+
}
|
| 1322 |
+
else if (F2PyCapsule_Check(fun)) {
|
| 1323 |
+
tot = maxnofargs;
|
| 1324 |
+
if (xa != NULL)
|
| 1325 |
+
ext = PyTuple_Size((PyObject *)xa);
|
| 1326 |
+
if(ext>0) {
|
| 1327 |
+
fprintf(stderr,\"extra arguments tuple cannot be used with PyCapsule call-back\\n\");
|
| 1328 |
+
goto capi_fail;
|
| 1329 |
+
}
|
| 1330 |
+
tmp_fun = fun;
|
| 1331 |
+
Py_INCREF(tmp_fun);
|
| 1332 |
+
}
|
| 1333 |
+
}
|
| 1334 |
+
|
| 1335 |
+
if (tmp_fun == NULL) {
|
| 1336 |
+
fprintf(stderr,
|
| 1337 |
+
\"Call-back argument must be function|instance|instance.__call__|f2py-function \"
|
| 1338 |
+
\"but got %s.\\n\",
|
| 1339 |
+
((fun == NULL) ? \"NULL\" : Py_TYPE(fun)->tp_name));
|
| 1340 |
+
goto capi_fail;
|
| 1341 |
+
}
|
| 1342 |
+
|
| 1343 |
+
if (PyObject_HasAttrString(tmp_fun,\"__code__\")) {
|
| 1344 |
+
if (PyObject_HasAttrString(tmp = PyObject_GetAttrString(tmp_fun,\"__code__\"),\"co_argcount\")) {
|
| 1345 |
+
PyObject *tmp_argcount = PyObject_GetAttrString(tmp,\"co_argcount\");
|
| 1346 |
+
Py_DECREF(tmp);
|
| 1347 |
+
if (tmp_argcount == NULL) {
|
| 1348 |
+
goto capi_fail;
|
| 1349 |
+
}
|
| 1350 |
+
tot = PyLong_AsSsize_t(tmp_argcount) - di;
|
| 1351 |
+
Py_DECREF(tmp_argcount);
|
| 1352 |
+
}
|
| 1353 |
+
}
|
| 1354 |
+
/* Get the number of optional arguments */
|
| 1355 |
+
if (PyObject_HasAttrString(tmp_fun,\"__defaults__\")) {
|
| 1356 |
+
if (PyTuple_Check(tmp = PyObject_GetAttrString(tmp_fun,\"__defaults__\")))
|
| 1357 |
+
opt = PyTuple_Size(tmp);
|
| 1358 |
+
Py_XDECREF(tmp);
|
| 1359 |
+
}
|
| 1360 |
+
/* Get the number of extra arguments */
|
| 1361 |
+
if (xa != NULL)
|
| 1362 |
+
ext = PyTuple_Size((PyObject *)xa);
|
| 1363 |
+
/* Calculate the size of call-backs argument list */
|
| 1364 |
+
siz = MIN(maxnofargs+ext,tot);
|
| 1365 |
+
*nofargs = MAX(0,siz-ext);
|
| 1366 |
+
|
| 1367 |
+
#ifdef DEBUGCFUNCS
|
| 1368 |
+
fprintf(stderr,
|
| 1369 |
+
\"debug-capi:create_cb_arglist:maxnofargs(-nofoptargs),\"
|
| 1370 |
+
\"tot,opt,ext,siz,nofargs = %d(-%d), %zd, %zd, %zd, %zd, %d\\n\",
|
| 1371 |
+
maxnofargs, nofoptargs, tot, opt, ext, siz, *nofargs);
|
| 1372 |
+
#endif
|
| 1373 |
+
|
| 1374 |
+
if (siz < tot-opt) {
|
| 1375 |
+
fprintf(stderr,
|
| 1376 |
+
\"create_cb_arglist: Failed to build argument list \"
|
| 1377 |
+
\"(siz) with enough arguments (tot-opt) required by \"
|
| 1378 |
+
\"user-supplied function (siz,tot,opt=%zd, %zd, %zd).\\n\",
|
| 1379 |
+
siz, tot, opt);
|
| 1380 |
+
goto capi_fail;
|
| 1381 |
+
}
|
| 1382 |
+
|
| 1383 |
+
/* Initialize argument list */
|
| 1384 |
+
*args = (PyTupleObject *)PyTuple_New(siz);
|
| 1385 |
+
for (i=0;i<*nofargs;i++) {
|
| 1386 |
+
Py_INCREF(Py_None);
|
| 1387 |
+
PyTuple_SET_ITEM((PyObject *)(*args),i,Py_None);
|
| 1388 |
+
}
|
| 1389 |
+
if (xa != NULL)
|
| 1390 |
+
for (i=(*nofargs);i<siz;i++) {
|
| 1391 |
+
tmp = PyTuple_GetItem((PyObject *)xa,i-(*nofargs));
|
| 1392 |
+
Py_INCREF(tmp);
|
| 1393 |
+
PyTuple_SET_ITEM(*args,i,tmp);
|
| 1394 |
+
}
|
| 1395 |
+
CFUNCSMESS(\"create_cb_arglist-end\\n\");
|
| 1396 |
+
Py_DECREF(tmp_fun);
|
| 1397 |
+
return 1;
|
| 1398 |
+
|
| 1399 |
+
capi_fail:
|
| 1400 |
+
if (PyErr_Occurred() == NULL)
|
| 1401 |
+
PyErr_SetString(#modulename#_error, errmess);
|
| 1402 |
+
Py_XDECREF(tmp_fun);
|
| 1403 |
+
return 0;
|
| 1404 |
+
}
|
| 1405 |
+
"""
|
| 1406 |
+
|
| 1407 |
+
|
| 1408 |
+
def buildcfuncs():
|
| 1409 |
+
from .capi_maps import c2capi_map
|
| 1410 |
+
for k in c2capi_map.keys():
|
| 1411 |
+
m = 'pyarr_from_p_%s1' % k
|
| 1412 |
+
cppmacros[
|
| 1413 |
+
m] = '#define %s(v) (PyArray_SimpleNewFromData(0,NULL,%s,(char *)v))' % (m, c2capi_map[k])
|
| 1414 |
+
k = 'string'
|
| 1415 |
+
m = 'pyarr_from_p_%s1' % k
|
| 1416 |
+
# NPY_CHAR compatibility, NPY_STRING with itemsize 1
|
| 1417 |
+
cppmacros[
|
| 1418 |
+
m] = '#define %s(v,dims) (PyArray_New(&PyArray_Type, 1, dims, NPY_STRING, NULL, v, 1, NPY_ARRAY_CARRAY, NULL))' % (m)
|
| 1419 |
+
|
| 1420 |
+
|
| 1421 |
+
############ Auxiliary functions for sorting needs ###################
|
| 1422 |
+
|
| 1423 |
+
def append_needs(need, flag=1):
|
| 1424 |
+
# This function modifies the contents of the global `outneeds` dict.
|
| 1425 |
+
if isinstance(need, list):
|
| 1426 |
+
for n in need:
|
| 1427 |
+
append_needs(n, flag)
|
| 1428 |
+
elif isinstance(need, str):
|
| 1429 |
+
if not need:
|
| 1430 |
+
return
|
| 1431 |
+
if need in includes0:
|
| 1432 |
+
n = 'includes0'
|
| 1433 |
+
elif need in includes:
|
| 1434 |
+
n = 'includes'
|
| 1435 |
+
elif need in typedefs:
|
| 1436 |
+
n = 'typedefs'
|
| 1437 |
+
elif need in typedefs_generated:
|
| 1438 |
+
n = 'typedefs_generated'
|
| 1439 |
+
elif need in cppmacros:
|
| 1440 |
+
n = 'cppmacros'
|
| 1441 |
+
elif need in cfuncs:
|
| 1442 |
+
n = 'cfuncs'
|
| 1443 |
+
elif need in callbacks:
|
| 1444 |
+
n = 'callbacks'
|
| 1445 |
+
elif need in f90modhooks:
|
| 1446 |
+
n = 'f90modhooks'
|
| 1447 |
+
elif need in commonhooks:
|
| 1448 |
+
n = 'commonhooks'
|
| 1449 |
+
else:
|
| 1450 |
+
errmess('append_needs: unknown need %s\n' % (repr(need)))
|
| 1451 |
+
return
|
| 1452 |
+
if need in outneeds[n]:
|
| 1453 |
+
return
|
| 1454 |
+
if flag:
|
| 1455 |
+
tmp = {}
|
| 1456 |
+
if need in needs:
|
| 1457 |
+
for nn in needs[need]:
|
| 1458 |
+
t = append_needs(nn, 0)
|
| 1459 |
+
if isinstance(t, dict):
|
| 1460 |
+
for nnn in t.keys():
|
| 1461 |
+
if nnn in tmp:
|
| 1462 |
+
tmp[nnn] = tmp[nnn] + t[nnn]
|
| 1463 |
+
else:
|
| 1464 |
+
tmp[nnn] = t[nnn]
|
| 1465 |
+
for nn in tmp.keys():
|
| 1466 |
+
for nnn in tmp[nn]:
|
| 1467 |
+
if nnn not in outneeds[nn]:
|
| 1468 |
+
outneeds[nn] = [nnn] + outneeds[nn]
|
| 1469 |
+
outneeds[n].append(need)
|
| 1470 |
+
else:
|
| 1471 |
+
tmp = {}
|
| 1472 |
+
if need in needs:
|
| 1473 |
+
for nn in needs[need]:
|
| 1474 |
+
t = append_needs(nn, flag)
|
| 1475 |
+
if isinstance(t, dict):
|
| 1476 |
+
for nnn in t.keys():
|
| 1477 |
+
if nnn in tmp:
|
| 1478 |
+
tmp[nnn] = t[nnn] + tmp[nnn]
|
| 1479 |
+
else:
|
| 1480 |
+
tmp[nnn] = t[nnn]
|
| 1481 |
+
if n not in tmp:
|
| 1482 |
+
tmp[n] = []
|
| 1483 |
+
tmp[n].append(need)
|
| 1484 |
+
return tmp
|
| 1485 |
+
else:
|
| 1486 |
+
errmess('append_needs: expected list or string but got :%s\n' %
|
| 1487 |
+
(repr(need)))
|
| 1488 |
+
|
| 1489 |
+
|
| 1490 |
+
def get_needs():
|
| 1491 |
+
# This function modifies the contents of the global `outneeds` dict.
|
| 1492 |
+
res = {}
|
| 1493 |
+
for n in outneeds.keys():
|
| 1494 |
+
out = []
|
| 1495 |
+
saveout = copy.copy(outneeds[n])
|
| 1496 |
+
while len(outneeds[n]) > 0:
|
| 1497 |
+
if outneeds[n][0] not in needs:
|
| 1498 |
+
out.append(outneeds[n][0])
|
| 1499 |
+
del outneeds[n][0]
|
| 1500 |
+
else:
|
| 1501 |
+
flag = 0
|
| 1502 |
+
for k in outneeds[n][1:]:
|
| 1503 |
+
if k in needs[outneeds[n][0]]:
|
| 1504 |
+
flag = 1
|
| 1505 |
+
break
|
| 1506 |
+
if flag:
|
| 1507 |
+
outneeds[n] = outneeds[n][1:] + [outneeds[n][0]]
|
| 1508 |
+
else:
|
| 1509 |
+
out.append(outneeds[n][0])
|
| 1510 |
+
del outneeds[n][0]
|
| 1511 |
+
if saveout and (0 not in map(lambda x, y: x == y, saveout, outneeds[n])) \
|
| 1512 |
+
and outneeds[n] != []:
|
| 1513 |
+
print(n, saveout)
|
| 1514 |
+
errmess(
|
| 1515 |
+
'get_needs: no progress in sorting needs, probably circular dependence, skipping.\n')
|
| 1516 |
+
out = out + saveout
|
| 1517 |
+
break
|
| 1518 |
+
saveout = copy.copy(outneeds[n])
|
| 1519 |
+
if out == []:
|
| 1520 |
+
out = [n]
|
| 1521 |
+
res[n] = out
|
| 1522 |
+
return res
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/common_rules.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Build common block mechanism for f2py2e.
|
| 5 |
+
|
| 6 |
+
Copyright 2000 Pearu Peterson all rights reserved,
|
| 7 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 8 |
+
Permission to use, modify, and distribute this software is given under the
|
| 9 |
+
terms of the NumPy License
|
| 10 |
+
|
| 11 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 12 |
+
$Date: 2005/05/06 10:57:33 $
|
| 13 |
+
Pearu Peterson
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
+
from . import __version__
|
| 17 |
+
f2py_version = __version__.version
|
| 18 |
+
|
| 19 |
+
from .auxfuncs import (
|
| 20 |
+
hasbody, hascommon, hasnote, isintent_hide, outmess
|
| 21 |
+
)
|
| 22 |
+
from . import capi_maps
|
| 23 |
+
from . import func2subr
|
| 24 |
+
from .crackfortran import rmbadname
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def findcommonblocks(block, top=1):
|
| 28 |
+
ret = []
|
| 29 |
+
if hascommon(block):
|
| 30 |
+
for key, value in block['common'].items():
|
| 31 |
+
vars_ = {v: block['vars'][v] for v in value}
|
| 32 |
+
ret.append((key, value, vars_))
|
| 33 |
+
elif hasbody(block):
|
| 34 |
+
for b in block['body']:
|
| 35 |
+
ret = ret + findcommonblocks(b, 0)
|
| 36 |
+
if top:
|
| 37 |
+
tret = []
|
| 38 |
+
names = []
|
| 39 |
+
for t in ret:
|
| 40 |
+
if t[0] not in names:
|
| 41 |
+
names.append(t[0])
|
| 42 |
+
tret.append(t)
|
| 43 |
+
return tret
|
| 44 |
+
return ret
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def buildhooks(m):
|
| 48 |
+
ret = {'commonhooks': [], 'initcommonhooks': [],
|
| 49 |
+
'docs': ['"COMMON blocks:\\n"']}
|
| 50 |
+
fwrap = ['']
|
| 51 |
+
|
| 52 |
+
def fadd(line, s=fwrap):
|
| 53 |
+
s[0] = '%s\n %s' % (s[0], line)
|
| 54 |
+
chooks = ['']
|
| 55 |
+
|
| 56 |
+
def cadd(line, s=chooks):
|
| 57 |
+
s[0] = '%s\n%s' % (s[0], line)
|
| 58 |
+
ihooks = ['']
|
| 59 |
+
|
| 60 |
+
def iadd(line, s=ihooks):
|
| 61 |
+
s[0] = '%s\n%s' % (s[0], line)
|
| 62 |
+
doc = ['']
|
| 63 |
+
|
| 64 |
+
def dadd(line, s=doc):
|
| 65 |
+
s[0] = '%s\n%s' % (s[0], line)
|
| 66 |
+
for (name, vnames, vars) in findcommonblocks(m):
|
| 67 |
+
lower_name = name.lower()
|
| 68 |
+
hnames, inames = [], []
|
| 69 |
+
for n in vnames:
|
| 70 |
+
if isintent_hide(vars[n]):
|
| 71 |
+
hnames.append(n)
|
| 72 |
+
else:
|
| 73 |
+
inames.append(n)
|
| 74 |
+
if hnames:
|
| 75 |
+
outmess('\t\tConstructing COMMON block support for "%s"...\n\t\t %s\n\t\t Hidden: %s\n' % (
|
| 76 |
+
name, ','.join(inames), ','.join(hnames)))
|
| 77 |
+
else:
|
| 78 |
+
outmess('\t\tConstructing COMMON block support for "%s"...\n\t\t %s\n' % (
|
| 79 |
+
name, ','.join(inames)))
|
| 80 |
+
fadd('subroutine f2pyinit%s(setupfunc)' % name)
|
| 81 |
+
fadd('external setupfunc')
|
| 82 |
+
for n in vnames:
|
| 83 |
+
fadd(func2subr.var2fixfortran(vars, n))
|
| 84 |
+
if name == '_BLNK_':
|
| 85 |
+
fadd('common %s' % (','.join(vnames)))
|
| 86 |
+
else:
|
| 87 |
+
fadd('common /%s/ %s' % (name, ','.join(vnames)))
|
| 88 |
+
fadd('call setupfunc(%s)' % (','.join(inames)))
|
| 89 |
+
fadd('end\n')
|
| 90 |
+
cadd('static FortranDataDef f2py_%s_def[] = {' % (name))
|
| 91 |
+
idims = []
|
| 92 |
+
for n in inames:
|
| 93 |
+
ct = capi_maps.getctype(vars[n])
|
| 94 |
+
elsize = capi_maps.get_elsize(vars[n])
|
| 95 |
+
at = capi_maps.c2capi_map[ct]
|
| 96 |
+
dm = capi_maps.getarrdims(n, vars[n])
|
| 97 |
+
if dm['dims']:
|
| 98 |
+
idims.append('(%s)' % (dm['dims']))
|
| 99 |
+
else:
|
| 100 |
+
idims.append('')
|
| 101 |
+
dms = dm['dims'].strip()
|
| 102 |
+
if not dms:
|
| 103 |
+
dms = '-1'
|
| 104 |
+
cadd('\t{\"%s\",%s,{{%s}},%s, %s},'
|
| 105 |
+
% (n, dm['rank'], dms, at, elsize))
|
| 106 |
+
cadd('\t{NULL}\n};')
|
| 107 |
+
inames1 = rmbadname(inames)
|
| 108 |
+
inames1_tps = ','.join(['char *' + s for s in inames1])
|
| 109 |
+
cadd('static void f2py_setup_%s(%s) {' % (name, inames1_tps))
|
| 110 |
+
cadd('\tint i_f2py=0;')
|
| 111 |
+
for n in inames1:
|
| 112 |
+
cadd('\tf2py_%s_def[i_f2py++].data = %s;' % (name, n))
|
| 113 |
+
cadd('}')
|
| 114 |
+
if '_' in lower_name:
|
| 115 |
+
F_FUNC = 'F_FUNC_US'
|
| 116 |
+
else:
|
| 117 |
+
F_FUNC = 'F_FUNC'
|
| 118 |
+
cadd('extern void %s(f2pyinit%s,F2PYINIT%s)(void(*)(%s));'
|
| 119 |
+
% (F_FUNC, lower_name, name.upper(),
|
| 120 |
+
','.join(['char*'] * len(inames1))))
|
| 121 |
+
cadd('static void f2py_init_%s(void) {' % name)
|
| 122 |
+
cadd('\t%s(f2pyinit%s,F2PYINIT%s)(f2py_setup_%s);'
|
| 123 |
+
% (F_FUNC, lower_name, name.upper(), name))
|
| 124 |
+
cadd('}\n')
|
| 125 |
+
iadd('\ttmp = PyFortranObject_New(f2py_%s_def,f2py_init_%s);' % (name, name))
|
| 126 |
+
iadd('\tif (tmp == NULL) return NULL;')
|
| 127 |
+
iadd('\tif (F2PyDict_SetItemString(d, \"%s\", tmp) == -1) return NULL;'
|
| 128 |
+
% name)
|
| 129 |
+
iadd('\tPy_DECREF(tmp);')
|
| 130 |
+
tname = name.replace('_', '\\_')
|
| 131 |
+
dadd('\\subsection{Common block \\texttt{%s}}\n' % (tname))
|
| 132 |
+
dadd('\\begin{description}')
|
| 133 |
+
for n in inames:
|
| 134 |
+
dadd('\\item[]{{}\\verb@%s@{}}' %
|
| 135 |
+
(capi_maps.getarrdocsign(n, vars[n])))
|
| 136 |
+
if hasnote(vars[n]):
|
| 137 |
+
note = vars[n]['note']
|
| 138 |
+
if isinstance(note, list):
|
| 139 |
+
note = '\n'.join(note)
|
| 140 |
+
dadd('--- %s' % (note))
|
| 141 |
+
dadd('\\end{description}')
|
| 142 |
+
ret['docs'].append(
|
| 143 |
+
'"\t/%s/ %s\\n"' % (name, ','.join(map(lambda v, d: v + d, inames, idims))))
|
| 144 |
+
ret['commonhooks'] = chooks
|
| 145 |
+
ret['initcommonhooks'] = ihooks
|
| 146 |
+
ret['latexdoc'] = doc[0]
|
| 147 |
+
if len(ret['docs']) <= 1:
|
| 148 |
+
ret['docs'] = ''
|
| 149 |
+
return ret, fwrap[0]
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/crackfortran.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/diagnose.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def run_command(cmd):
|
| 8 |
+
print('Running %r:' % (cmd))
|
| 9 |
+
os.system(cmd)
|
| 10 |
+
print('------')
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def run():
|
| 14 |
+
_path = os.getcwd()
|
| 15 |
+
os.chdir(tempfile.gettempdir())
|
| 16 |
+
print('------')
|
| 17 |
+
print('os.name=%r' % (os.name))
|
| 18 |
+
print('------')
|
| 19 |
+
print('sys.platform=%r' % (sys.platform))
|
| 20 |
+
print('------')
|
| 21 |
+
print('sys.version:')
|
| 22 |
+
print(sys.version)
|
| 23 |
+
print('------')
|
| 24 |
+
print('sys.prefix:')
|
| 25 |
+
print(sys.prefix)
|
| 26 |
+
print('------')
|
| 27 |
+
print('sys.path=%r' % (':'.join(sys.path)))
|
| 28 |
+
print('------')
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
import numpy
|
| 32 |
+
has_newnumpy = 1
|
| 33 |
+
except ImportError:
|
| 34 |
+
print('Failed to import new numpy:', sys.exc_info()[1])
|
| 35 |
+
has_newnumpy = 0
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
from numpy.f2py import f2py2e
|
| 39 |
+
has_f2py2e = 1
|
| 40 |
+
except ImportError:
|
| 41 |
+
print('Failed to import f2py2e:', sys.exc_info()[1])
|
| 42 |
+
has_f2py2e = 0
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
import numpy.distutils
|
| 46 |
+
has_numpy_distutils = 2
|
| 47 |
+
except ImportError:
|
| 48 |
+
try:
|
| 49 |
+
import numpy_distutils
|
| 50 |
+
has_numpy_distutils = 1
|
| 51 |
+
except ImportError:
|
| 52 |
+
print('Failed to import numpy_distutils:', sys.exc_info()[1])
|
| 53 |
+
has_numpy_distutils = 0
|
| 54 |
+
|
| 55 |
+
if has_newnumpy:
|
| 56 |
+
try:
|
| 57 |
+
print('Found new numpy version %r in %s' %
|
| 58 |
+
(numpy.__version__, numpy.__file__))
|
| 59 |
+
except Exception as msg:
|
| 60 |
+
print('error:', msg)
|
| 61 |
+
print('------')
|
| 62 |
+
|
| 63 |
+
if has_f2py2e:
|
| 64 |
+
try:
|
| 65 |
+
print('Found f2py2e version %r in %s' %
|
| 66 |
+
(f2py2e.__version__.version, f2py2e.__file__))
|
| 67 |
+
except Exception as msg:
|
| 68 |
+
print('error:', msg)
|
| 69 |
+
print('------')
|
| 70 |
+
|
| 71 |
+
if has_numpy_distutils:
|
| 72 |
+
try:
|
| 73 |
+
if has_numpy_distutils == 2:
|
| 74 |
+
print('Found numpy.distutils version %r in %r' % (
|
| 75 |
+
numpy.distutils.__version__,
|
| 76 |
+
numpy.distutils.__file__))
|
| 77 |
+
else:
|
| 78 |
+
print('Found numpy_distutils version %r in %r' % (
|
| 79 |
+
numpy_distutils.numpy_distutils_version.numpy_distutils_version,
|
| 80 |
+
numpy_distutils.__file__))
|
| 81 |
+
print('------')
|
| 82 |
+
except Exception as msg:
|
| 83 |
+
print('error:', msg)
|
| 84 |
+
print('------')
|
| 85 |
+
try:
|
| 86 |
+
if has_numpy_distutils == 1:
|
| 87 |
+
print(
|
| 88 |
+
'Importing numpy_distutils.command.build_flib ...', end=' ')
|
| 89 |
+
import numpy_distutils.command.build_flib as build_flib
|
| 90 |
+
print('ok')
|
| 91 |
+
print('------')
|
| 92 |
+
try:
|
| 93 |
+
print(
|
| 94 |
+
'Checking availability of supported Fortran compilers:')
|
| 95 |
+
for compiler_class in build_flib.all_compilers:
|
| 96 |
+
compiler_class(verbose=1).is_available()
|
| 97 |
+
print('------')
|
| 98 |
+
except Exception as msg:
|
| 99 |
+
print('error:', msg)
|
| 100 |
+
print('------')
|
| 101 |
+
except Exception as msg:
|
| 102 |
+
print(
|
| 103 |
+
'error:', msg, '(ignore it, build_flib is obsolute for numpy.distutils 0.2.2 and up)')
|
| 104 |
+
print('------')
|
| 105 |
+
try:
|
| 106 |
+
if has_numpy_distutils == 2:
|
| 107 |
+
print('Importing numpy.distutils.fcompiler ...', end=' ')
|
| 108 |
+
import numpy.distutils.fcompiler as fcompiler
|
| 109 |
+
else:
|
| 110 |
+
print('Importing numpy_distutils.fcompiler ...', end=' ')
|
| 111 |
+
import numpy_distutils.fcompiler as fcompiler
|
| 112 |
+
print('ok')
|
| 113 |
+
print('------')
|
| 114 |
+
try:
|
| 115 |
+
print('Checking availability of supported Fortran compilers:')
|
| 116 |
+
fcompiler.show_fcompilers()
|
| 117 |
+
print('------')
|
| 118 |
+
except Exception as msg:
|
| 119 |
+
print('error:', msg)
|
| 120 |
+
print('------')
|
| 121 |
+
except Exception as msg:
|
| 122 |
+
print('error:', msg)
|
| 123 |
+
print('------')
|
| 124 |
+
try:
|
| 125 |
+
if has_numpy_distutils == 2:
|
| 126 |
+
print('Importing numpy.distutils.cpuinfo ...', end=' ')
|
| 127 |
+
from numpy.distutils.cpuinfo import cpuinfo
|
| 128 |
+
print('ok')
|
| 129 |
+
print('------')
|
| 130 |
+
else:
|
| 131 |
+
try:
|
| 132 |
+
print(
|
| 133 |
+
'Importing numpy_distutils.command.cpuinfo ...', end=' ')
|
| 134 |
+
from numpy_distutils.command.cpuinfo import cpuinfo
|
| 135 |
+
print('ok')
|
| 136 |
+
print('------')
|
| 137 |
+
except Exception as msg:
|
| 138 |
+
print('error:', msg, '(ignore it)')
|
| 139 |
+
print('Importing numpy_distutils.cpuinfo ...', end=' ')
|
| 140 |
+
from numpy_distutils.cpuinfo import cpuinfo
|
| 141 |
+
print('ok')
|
| 142 |
+
print('------')
|
| 143 |
+
cpu = cpuinfo()
|
| 144 |
+
print('CPU information:', end=' ')
|
| 145 |
+
for name in dir(cpuinfo):
|
| 146 |
+
if name[0] == '_' and name[1] != '_' and getattr(cpu, name[1:])():
|
| 147 |
+
print(name[1:], end=' ')
|
| 148 |
+
print('------')
|
| 149 |
+
except Exception as msg:
|
| 150 |
+
print('error:', msg)
|
| 151 |
+
print('------')
|
| 152 |
+
os.chdir(_path)
|
| 153 |
+
if __name__ == "__main__":
|
| 154 |
+
run()
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/f2py2e.py
ADDED
|
@@ -0,0 +1,704 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
f2py2e - Fortran to Python C/API generator. 2nd Edition.
|
| 5 |
+
See __usage__ below.
|
| 6 |
+
|
| 7 |
+
Copyright 1999--2011 Pearu Peterson all rights reserved,
|
| 8 |
+
Pearu Peterson <pearu@cens.ioc.ee>
|
| 9 |
+
Permission to use, modify, and distribute this software is given under the
|
| 10 |
+
terms of the NumPy License.
|
| 11 |
+
|
| 12 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 13 |
+
$Date: 2005/05/06 08:31:19 $
|
| 14 |
+
Pearu Peterson
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
import sys
|
| 18 |
+
import os
|
| 19 |
+
import pprint
|
| 20 |
+
import re
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
from . import crackfortran
|
| 24 |
+
from . import rules
|
| 25 |
+
from . import cb_rules
|
| 26 |
+
from . import auxfuncs
|
| 27 |
+
from . import cfuncs
|
| 28 |
+
from . import f90mod_rules
|
| 29 |
+
from . import __version__
|
| 30 |
+
from . import capi_maps
|
| 31 |
+
|
| 32 |
+
f2py_version = __version__.version
|
| 33 |
+
numpy_version = __version__.version
|
| 34 |
+
errmess = sys.stderr.write
|
| 35 |
+
# outmess=sys.stdout.write
|
| 36 |
+
show = pprint.pprint
|
| 37 |
+
outmess = auxfuncs.outmess
|
| 38 |
+
|
| 39 |
+
__usage__ =\
|
| 40 |
+
f"""Usage:
|
| 41 |
+
|
| 42 |
+
1) To construct extension module sources:
|
| 43 |
+
|
| 44 |
+
f2py [<options>] <fortran files> [[[only:]||[skip:]] \\
|
| 45 |
+
<fortran functions> ] \\
|
| 46 |
+
[: <fortran files> ...]
|
| 47 |
+
|
| 48 |
+
2) To compile fortran files and build extension modules:
|
| 49 |
+
|
| 50 |
+
f2py -c [<options>, <build_flib options>, <extra options>] <fortran files>
|
| 51 |
+
|
| 52 |
+
3) To generate signature files:
|
| 53 |
+
|
| 54 |
+
f2py -h <filename.pyf> ...< same options as in (1) >
|
| 55 |
+
|
| 56 |
+
Description: This program generates a Python C/API file (<modulename>module.c)
|
| 57 |
+
that contains wrappers for given fortran functions so that they
|
| 58 |
+
can be called from Python. With the -c option the corresponding
|
| 59 |
+
extension modules are built.
|
| 60 |
+
|
| 61 |
+
Options:
|
| 62 |
+
|
| 63 |
+
--2d-numpy Use numpy.f2py tool with NumPy support. [DEFAULT]
|
| 64 |
+
--2d-numeric Use f2py2e tool with Numeric support.
|
| 65 |
+
--2d-numarray Use f2py2e tool with Numarray support.
|
| 66 |
+
--g3-numpy Use 3rd generation f2py from the separate f2py package.
|
| 67 |
+
[NOT AVAILABLE YET]
|
| 68 |
+
|
| 69 |
+
-h <filename> Write signatures of the fortran routines to file <filename>
|
| 70 |
+
and exit. You can then edit <filename> and use it instead
|
| 71 |
+
of <fortran files>. If <filename>==stdout then the
|
| 72 |
+
signatures are printed to stdout.
|
| 73 |
+
<fortran functions> Names of fortran routines for which Python C/API
|
| 74 |
+
functions will be generated. Default is all that are found
|
| 75 |
+
in <fortran files>.
|
| 76 |
+
<fortran files> Paths to fortran/signature files that will be scanned for
|
| 77 |
+
<fortran functions> in order to determine their signatures.
|
| 78 |
+
skip: Ignore fortran functions that follow until `:'.
|
| 79 |
+
only: Use only fortran functions that follow until `:'.
|
| 80 |
+
: Get back to <fortran files> mode.
|
| 81 |
+
|
| 82 |
+
-m <modulename> Name of the module; f2py generates a Python/C API
|
| 83 |
+
file <modulename>module.c or extension module <modulename>.
|
| 84 |
+
Default is 'untitled'.
|
| 85 |
+
|
| 86 |
+
'-include<header>' Writes additional headers in the C wrapper, can be passed
|
| 87 |
+
multiple times, generates #include <header> each time.
|
| 88 |
+
|
| 89 |
+
--[no-]lower Do [not] lower the cases in <fortran files>. By default,
|
| 90 |
+
--lower is assumed with -h key, and --no-lower without -h key.
|
| 91 |
+
|
| 92 |
+
--build-dir <dirname> All f2py generated files are created in <dirname>.
|
| 93 |
+
Default is tempfile.mkdtemp().
|
| 94 |
+
|
| 95 |
+
--overwrite-signature Overwrite existing signature file.
|
| 96 |
+
|
| 97 |
+
--[no-]latex-doc Create (or not) <modulename>module.tex.
|
| 98 |
+
Default is --no-latex-doc.
|
| 99 |
+
--short-latex Create 'incomplete' LaTeX document (without commands
|
| 100 |
+
\\documentclass, \\tableofcontents, and \\begin{{document}},
|
| 101 |
+
\\end{{document}}).
|
| 102 |
+
|
| 103 |
+
--[no-]rest-doc Create (or not) <modulename>module.rst.
|
| 104 |
+
Default is --no-rest-doc.
|
| 105 |
+
|
| 106 |
+
--debug-capi Create C/API code that reports the state of the wrappers
|
| 107 |
+
during runtime. Useful for debugging.
|
| 108 |
+
|
| 109 |
+
--[no-]wrap-functions Create Fortran subroutine wrappers to Fortran 77
|
| 110 |
+
functions. --wrap-functions is default because it ensures
|
| 111 |
+
maximum portability/compiler independence.
|
| 112 |
+
|
| 113 |
+
--include-paths <path1>:<path2>:... Search include files from the given
|
| 114 |
+
directories.
|
| 115 |
+
|
| 116 |
+
--help-link [..] List system resources found by system_info.py. See also
|
| 117 |
+
--link-<resource> switch below. [..] is optional list
|
| 118 |
+
of resources names. E.g. try 'f2py --help-link lapack_opt'.
|
| 119 |
+
|
| 120 |
+
--f2cmap <filename> Load Fortran-to-Python KIND specification from the given
|
| 121 |
+
file. Default: .f2py_f2cmap in current directory.
|
| 122 |
+
|
| 123 |
+
--quiet Run quietly.
|
| 124 |
+
--verbose Run with extra verbosity.
|
| 125 |
+
--skip-empty-wrappers Only generate wrapper files when needed.
|
| 126 |
+
-v Print f2py version ID and exit.
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
numpy.distutils options (only effective with -c):
|
| 130 |
+
|
| 131 |
+
--fcompiler= Specify Fortran compiler type by vendor
|
| 132 |
+
--compiler= Specify C compiler type (as defined by distutils)
|
| 133 |
+
|
| 134 |
+
--help-fcompiler List available Fortran compilers and exit
|
| 135 |
+
--f77exec= Specify the path to F77 compiler
|
| 136 |
+
--f90exec= Specify the path to F90 compiler
|
| 137 |
+
--f77flags= Specify F77 compiler flags
|
| 138 |
+
--f90flags= Specify F90 compiler flags
|
| 139 |
+
--opt= Specify optimization flags
|
| 140 |
+
--arch= Specify architecture specific optimization flags
|
| 141 |
+
--noopt Compile without optimization
|
| 142 |
+
--noarch Compile without arch-dependent optimization
|
| 143 |
+
--debug Compile with debugging information
|
| 144 |
+
|
| 145 |
+
Extra options (only effective with -c):
|
| 146 |
+
|
| 147 |
+
--link-<resource> Link extension module with <resource> as defined
|
| 148 |
+
by numpy.distutils/system_info.py. E.g. to link
|
| 149 |
+
with optimized LAPACK libraries (vecLib on MacOSX,
|
| 150 |
+
ATLAS elsewhere), use --link-lapack_opt.
|
| 151 |
+
See also --help-link switch.
|
| 152 |
+
|
| 153 |
+
-L/path/to/lib/ -l<libname>
|
| 154 |
+
-D<define> -U<name>
|
| 155 |
+
-I/path/to/include/
|
| 156 |
+
<filename>.o <filename>.so <filename>.a
|
| 157 |
+
|
| 158 |
+
Using the following macros may be required with non-gcc Fortran
|
| 159 |
+
compilers:
|
| 160 |
+
-DPREPEND_FORTRAN -DNO_APPEND_FORTRAN -DUPPERCASE_FORTRAN
|
| 161 |
+
-DUNDERSCORE_G77
|
| 162 |
+
|
| 163 |
+
When using -DF2PY_REPORT_ATEXIT, a performance report of F2PY
|
| 164 |
+
interface is printed out at exit (platforms: Linux).
|
| 165 |
+
|
| 166 |
+
When using -DF2PY_REPORT_ON_ARRAY_COPY=<int>, a message is
|
| 167 |
+
sent to stderr whenever F2PY interface makes a copy of an
|
| 168 |
+
array. Integer <int> sets the threshold for array sizes when
|
| 169 |
+
a message should be shown.
|
| 170 |
+
|
| 171 |
+
Version: {f2py_version}
|
| 172 |
+
numpy Version: {numpy_version}
|
| 173 |
+
Requires: Python 3.5 or higher.
|
| 174 |
+
License: NumPy license (see LICENSE.txt in the NumPy source code)
|
| 175 |
+
Copyright 1999 - 2011 Pearu Peterson all rights reserved.
|
| 176 |
+
https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e"""
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def scaninputline(inputline):
|
| 180 |
+
files, skipfuncs, onlyfuncs, debug = [], [], [], []
|
| 181 |
+
f, f2, f3, f5, f6, f7, f8, f9, f10 = 1, 0, 0, 0, 0, 0, 0, 0, 0
|
| 182 |
+
verbose = 1
|
| 183 |
+
emptygen = True
|
| 184 |
+
dolc = -1
|
| 185 |
+
dolatexdoc = 0
|
| 186 |
+
dorestdoc = 0
|
| 187 |
+
wrapfuncs = 1
|
| 188 |
+
buildpath = '.'
|
| 189 |
+
include_paths = []
|
| 190 |
+
signsfile, modulename = None, None
|
| 191 |
+
options = {'buildpath': buildpath,
|
| 192 |
+
'coutput': None,
|
| 193 |
+
'f2py_wrapper_output': None}
|
| 194 |
+
for l in inputline:
|
| 195 |
+
if l == '':
|
| 196 |
+
pass
|
| 197 |
+
elif l == 'only:':
|
| 198 |
+
f = 0
|
| 199 |
+
elif l == 'skip:':
|
| 200 |
+
f = -1
|
| 201 |
+
elif l == ':':
|
| 202 |
+
f = 1
|
| 203 |
+
elif l[:8] == '--debug-':
|
| 204 |
+
debug.append(l[8:])
|
| 205 |
+
elif l == '--lower':
|
| 206 |
+
dolc = 1
|
| 207 |
+
elif l == '--build-dir':
|
| 208 |
+
f6 = 1
|
| 209 |
+
elif l == '--no-lower':
|
| 210 |
+
dolc = 0
|
| 211 |
+
elif l == '--quiet':
|
| 212 |
+
verbose = 0
|
| 213 |
+
elif l == '--verbose':
|
| 214 |
+
verbose += 1
|
| 215 |
+
elif l == '--latex-doc':
|
| 216 |
+
dolatexdoc = 1
|
| 217 |
+
elif l == '--no-latex-doc':
|
| 218 |
+
dolatexdoc = 0
|
| 219 |
+
elif l == '--rest-doc':
|
| 220 |
+
dorestdoc = 1
|
| 221 |
+
elif l == '--no-rest-doc':
|
| 222 |
+
dorestdoc = 0
|
| 223 |
+
elif l == '--wrap-functions':
|
| 224 |
+
wrapfuncs = 1
|
| 225 |
+
elif l == '--no-wrap-functions':
|
| 226 |
+
wrapfuncs = 0
|
| 227 |
+
elif l == '--short-latex':
|
| 228 |
+
options['shortlatex'] = 1
|
| 229 |
+
elif l == '--coutput':
|
| 230 |
+
f8 = 1
|
| 231 |
+
elif l == '--f2py-wrapper-output':
|
| 232 |
+
f9 = 1
|
| 233 |
+
elif l == '--f2cmap':
|
| 234 |
+
f10 = 1
|
| 235 |
+
elif l == '--overwrite-signature':
|
| 236 |
+
options['h-overwrite'] = 1
|
| 237 |
+
elif l == '-h':
|
| 238 |
+
f2 = 1
|
| 239 |
+
elif l == '-m':
|
| 240 |
+
f3 = 1
|
| 241 |
+
elif l[:2] == '-v':
|
| 242 |
+
print(f2py_version)
|
| 243 |
+
sys.exit()
|
| 244 |
+
elif l == '--show-compilers':
|
| 245 |
+
f5 = 1
|
| 246 |
+
elif l[:8] == '-include':
|
| 247 |
+
cfuncs.outneeds['userincludes'].append(l[9:-1])
|
| 248 |
+
cfuncs.userincludes[l[9:-1]] = '#include ' + l[8:]
|
| 249 |
+
elif l[:15] in '--include_paths':
|
| 250 |
+
outmess(
|
| 251 |
+
'f2py option --include_paths is deprecated, use --include-paths instead.\n')
|
| 252 |
+
f7 = 1
|
| 253 |
+
elif l[:15] in '--include-paths':
|
| 254 |
+
f7 = 1
|
| 255 |
+
elif l == '--skip-empty-wrappers':
|
| 256 |
+
emptygen = False
|
| 257 |
+
elif l[0] == '-':
|
| 258 |
+
errmess('Unknown option %s\n' % repr(l))
|
| 259 |
+
sys.exit()
|
| 260 |
+
elif f2:
|
| 261 |
+
f2 = 0
|
| 262 |
+
signsfile = l
|
| 263 |
+
elif f3:
|
| 264 |
+
f3 = 0
|
| 265 |
+
modulename = l
|
| 266 |
+
elif f6:
|
| 267 |
+
f6 = 0
|
| 268 |
+
buildpath = l
|
| 269 |
+
elif f7:
|
| 270 |
+
f7 = 0
|
| 271 |
+
include_paths.extend(l.split(os.pathsep))
|
| 272 |
+
elif f8:
|
| 273 |
+
f8 = 0
|
| 274 |
+
options["coutput"] = l
|
| 275 |
+
elif f9:
|
| 276 |
+
f9 = 0
|
| 277 |
+
options["f2py_wrapper_output"] = l
|
| 278 |
+
elif f10:
|
| 279 |
+
f10 = 0
|
| 280 |
+
options["f2cmap_file"] = l
|
| 281 |
+
elif f == 1:
|
| 282 |
+
try:
|
| 283 |
+
with open(l):
|
| 284 |
+
pass
|
| 285 |
+
files.append(l)
|
| 286 |
+
except OSError as detail:
|
| 287 |
+
errmess(f'OSError: {detail!s}. Skipping file "{l!s}".\n')
|
| 288 |
+
elif f == -1:
|
| 289 |
+
skipfuncs.append(l)
|
| 290 |
+
elif f == 0:
|
| 291 |
+
onlyfuncs.append(l)
|
| 292 |
+
if not f5 and not files and not modulename:
|
| 293 |
+
print(__usage__)
|
| 294 |
+
sys.exit()
|
| 295 |
+
if not os.path.isdir(buildpath):
|
| 296 |
+
if not verbose:
|
| 297 |
+
outmess('Creating build directory %s\n' % (buildpath))
|
| 298 |
+
os.mkdir(buildpath)
|
| 299 |
+
if signsfile:
|
| 300 |
+
signsfile = os.path.join(buildpath, signsfile)
|
| 301 |
+
if signsfile and os.path.isfile(signsfile) and 'h-overwrite' not in options:
|
| 302 |
+
errmess(
|
| 303 |
+
'Signature file "%s" exists!!! Use --overwrite-signature to overwrite.\n' % (signsfile))
|
| 304 |
+
sys.exit()
|
| 305 |
+
|
| 306 |
+
options['emptygen'] = emptygen
|
| 307 |
+
options['debug'] = debug
|
| 308 |
+
options['verbose'] = verbose
|
| 309 |
+
if dolc == -1 and not signsfile:
|
| 310 |
+
options['do-lower'] = 0
|
| 311 |
+
else:
|
| 312 |
+
options['do-lower'] = dolc
|
| 313 |
+
if modulename:
|
| 314 |
+
options['module'] = modulename
|
| 315 |
+
if signsfile:
|
| 316 |
+
options['signsfile'] = signsfile
|
| 317 |
+
if onlyfuncs:
|
| 318 |
+
options['onlyfuncs'] = onlyfuncs
|
| 319 |
+
if skipfuncs:
|
| 320 |
+
options['skipfuncs'] = skipfuncs
|
| 321 |
+
options['dolatexdoc'] = dolatexdoc
|
| 322 |
+
options['dorestdoc'] = dorestdoc
|
| 323 |
+
options['wrapfuncs'] = wrapfuncs
|
| 324 |
+
options['buildpath'] = buildpath
|
| 325 |
+
options['include_paths'] = include_paths
|
| 326 |
+
options.setdefault('f2cmap_file', None)
|
| 327 |
+
return files, options
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def callcrackfortran(files, options):
|
| 331 |
+
rules.options = options
|
| 332 |
+
crackfortran.debug = options['debug']
|
| 333 |
+
crackfortran.verbose = options['verbose']
|
| 334 |
+
if 'module' in options:
|
| 335 |
+
crackfortran.f77modulename = options['module']
|
| 336 |
+
if 'skipfuncs' in options:
|
| 337 |
+
crackfortran.skipfuncs = options['skipfuncs']
|
| 338 |
+
if 'onlyfuncs' in options:
|
| 339 |
+
crackfortran.onlyfuncs = options['onlyfuncs']
|
| 340 |
+
crackfortran.include_paths[:] = options['include_paths']
|
| 341 |
+
crackfortran.dolowercase = options['do-lower']
|
| 342 |
+
postlist = crackfortran.crackfortran(files)
|
| 343 |
+
if 'signsfile' in options:
|
| 344 |
+
outmess('Saving signatures to file "%s"\n' % (options['signsfile']))
|
| 345 |
+
pyf = crackfortran.crack2fortran(postlist)
|
| 346 |
+
if options['signsfile'][-6:] == 'stdout':
|
| 347 |
+
sys.stdout.write(pyf)
|
| 348 |
+
else:
|
| 349 |
+
with open(options['signsfile'], 'w') as f:
|
| 350 |
+
f.write(pyf)
|
| 351 |
+
if options["coutput"] is None:
|
| 352 |
+
for mod in postlist:
|
| 353 |
+
mod["coutput"] = "%smodule.c" % mod["name"]
|
| 354 |
+
else:
|
| 355 |
+
for mod in postlist:
|
| 356 |
+
mod["coutput"] = options["coutput"]
|
| 357 |
+
if options["f2py_wrapper_output"] is None:
|
| 358 |
+
for mod in postlist:
|
| 359 |
+
mod["f2py_wrapper_output"] = "%s-f2pywrappers.f" % mod["name"]
|
| 360 |
+
else:
|
| 361 |
+
for mod in postlist:
|
| 362 |
+
mod["f2py_wrapper_output"] = options["f2py_wrapper_output"]
|
| 363 |
+
return postlist
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def buildmodules(lst):
|
| 367 |
+
cfuncs.buildcfuncs()
|
| 368 |
+
outmess('Building modules...\n')
|
| 369 |
+
modules, mnames, isusedby = [], [], {}
|
| 370 |
+
for item in lst:
|
| 371 |
+
if '__user__' in item['name']:
|
| 372 |
+
cb_rules.buildcallbacks(item)
|
| 373 |
+
else:
|
| 374 |
+
if 'use' in item:
|
| 375 |
+
for u in item['use'].keys():
|
| 376 |
+
if u not in isusedby:
|
| 377 |
+
isusedby[u] = []
|
| 378 |
+
isusedby[u].append(item['name'])
|
| 379 |
+
modules.append(item)
|
| 380 |
+
mnames.append(item['name'])
|
| 381 |
+
ret = {}
|
| 382 |
+
for module, name in zip(modules, mnames):
|
| 383 |
+
if name in isusedby:
|
| 384 |
+
outmess('\tSkipping module "%s" which is used by %s.\n' % (
|
| 385 |
+
name, ','.join('"%s"' % s for s in isusedby[name])))
|
| 386 |
+
else:
|
| 387 |
+
um = []
|
| 388 |
+
if 'use' in module:
|
| 389 |
+
for u in module['use'].keys():
|
| 390 |
+
if u in isusedby and u in mnames:
|
| 391 |
+
um.append(modules[mnames.index(u)])
|
| 392 |
+
else:
|
| 393 |
+
outmess(
|
| 394 |
+
f'\tModule "{name}" uses nonexisting "{u}" '
|
| 395 |
+
'which will be ignored.\n')
|
| 396 |
+
ret[name] = {}
|
| 397 |
+
dict_append(ret[name], rules.buildmodule(module, um))
|
| 398 |
+
return ret
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def dict_append(d_out, d_in):
|
| 402 |
+
for (k, v) in d_in.items():
|
| 403 |
+
if k not in d_out:
|
| 404 |
+
d_out[k] = []
|
| 405 |
+
if isinstance(v, list):
|
| 406 |
+
d_out[k] = d_out[k] + v
|
| 407 |
+
else:
|
| 408 |
+
d_out[k].append(v)
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def run_main(comline_list):
|
| 412 |
+
"""
|
| 413 |
+
Equivalent to running::
|
| 414 |
+
|
| 415 |
+
f2py <args>
|
| 416 |
+
|
| 417 |
+
where ``<args>=string.join(<list>,' ')``, but in Python. Unless
|
| 418 |
+
``-h`` is used, this function returns a dictionary containing
|
| 419 |
+
information on generated modules and their dependencies on source
|
| 420 |
+
files.
|
| 421 |
+
|
| 422 |
+
You cannot build extension modules with this function, that is,
|
| 423 |
+
using ``-c`` is not allowed. Use the ``compile`` command instead.
|
| 424 |
+
|
| 425 |
+
Examples
|
| 426 |
+
--------
|
| 427 |
+
The command ``f2py -m scalar scalar.f`` can be executed from Python as
|
| 428 |
+
follows.
|
| 429 |
+
|
| 430 |
+
.. literalinclude:: ../../source/f2py/code/results/run_main_session.dat
|
| 431 |
+
:language: python
|
| 432 |
+
|
| 433 |
+
"""
|
| 434 |
+
crackfortran.reset_global_f2py_vars()
|
| 435 |
+
f2pydir = os.path.dirname(os.path.abspath(cfuncs.__file__))
|
| 436 |
+
fobjhsrc = os.path.join(f2pydir, 'src', 'fortranobject.h')
|
| 437 |
+
fobjcsrc = os.path.join(f2pydir, 'src', 'fortranobject.c')
|
| 438 |
+
files, options = scaninputline(comline_list)
|
| 439 |
+
auxfuncs.options = options
|
| 440 |
+
capi_maps.load_f2cmap_file(options['f2cmap_file'])
|
| 441 |
+
postlist = callcrackfortran(files, options)
|
| 442 |
+
isusedby = {}
|
| 443 |
+
for plist in postlist:
|
| 444 |
+
if 'use' in plist:
|
| 445 |
+
for u in plist['use'].keys():
|
| 446 |
+
if u not in isusedby:
|
| 447 |
+
isusedby[u] = []
|
| 448 |
+
isusedby[u].append(plist['name'])
|
| 449 |
+
for plist in postlist:
|
| 450 |
+
if plist['block'] == 'python module' and '__user__' in plist['name']:
|
| 451 |
+
if plist['name'] in isusedby:
|
| 452 |
+
# if not quiet:
|
| 453 |
+
outmess(
|
| 454 |
+
f'Skipping Makefile build for module "{plist["name"]}" '
|
| 455 |
+
'which is used by {}\n'.format(
|
| 456 |
+
','.join(f'"{s}"' for s in isusedby[plist['name']])))
|
| 457 |
+
if 'signsfile' in options:
|
| 458 |
+
if options['verbose'] > 1:
|
| 459 |
+
outmess(
|
| 460 |
+
'Stopping. Edit the signature file and then run f2py on the signature file: ')
|
| 461 |
+
outmess('%s %s\n' %
|
| 462 |
+
(os.path.basename(sys.argv[0]), options['signsfile']))
|
| 463 |
+
return
|
| 464 |
+
for plist in postlist:
|
| 465 |
+
if plist['block'] != 'python module':
|
| 466 |
+
if 'python module' not in options:
|
| 467 |
+
errmess(
|
| 468 |
+
'Tip: If your original code is Fortran source then you must use -m option.\n')
|
| 469 |
+
raise TypeError('All blocks must be python module blocks but got %s' % (
|
| 470 |
+
repr(plist['block'])))
|
| 471 |
+
auxfuncs.debugoptions = options['debug']
|
| 472 |
+
f90mod_rules.options = options
|
| 473 |
+
auxfuncs.wrapfuncs = options['wrapfuncs']
|
| 474 |
+
|
| 475 |
+
ret = buildmodules(postlist)
|
| 476 |
+
|
| 477 |
+
for mn in ret.keys():
|
| 478 |
+
dict_append(ret[mn], {'csrc': fobjcsrc, 'h': fobjhsrc})
|
| 479 |
+
return ret
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
def filter_files(prefix, suffix, files, remove_prefix=None):
|
| 483 |
+
"""
|
| 484 |
+
Filter files by prefix and suffix.
|
| 485 |
+
"""
|
| 486 |
+
filtered, rest = [], []
|
| 487 |
+
match = re.compile(prefix + r'.*' + suffix + r'\Z').match
|
| 488 |
+
if remove_prefix:
|
| 489 |
+
ind = len(prefix)
|
| 490 |
+
else:
|
| 491 |
+
ind = 0
|
| 492 |
+
for file in [x.strip() for x in files]:
|
| 493 |
+
if match(file):
|
| 494 |
+
filtered.append(file[ind:])
|
| 495 |
+
else:
|
| 496 |
+
rest.append(file)
|
| 497 |
+
return filtered, rest
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
def get_prefix(module):
|
| 501 |
+
p = os.path.dirname(os.path.dirname(module.__file__))
|
| 502 |
+
return p
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
def run_compile():
|
| 506 |
+
"""
|
| 507 |
+
Do it all in one call!
|
| 508 |
+
"""
|
| 509 |
+
import tempfile
|
| 510 |
+
|
| 511 |
+
i = sys.argv.index('-c')
|
| 512 |
+
del sys.argv[i]
|
| 513 |
+
|
| 514 |
+
remove_build_dir = 0
|
| 515 |
+
try:
|
| 516 |
+
i = sys.argv.index('--build-dir')
|
| 517 |
+
except ValueError:
|
| 518 |
+
i = None
|
| 519 |
+
if i is not None:
|
| 520 |
+
build_dir = sys.argv[i + 1]
|
| 521 |
+
del sys.argv[i + 1]
|
| 522 |
+
del sys.argv[i]
|
| 523 |
+
else:
|
| 524 |
+
remove_build_dir = 1
|
| 525 |
+
build_dir = tempfile.mkdtemp()
|
| 526 |
+
|
| 527 |
+
_reg1 = re.compile(r'--link-')
|
| 528 |
+
sysinfo_flags = [_m for _m in sys.argv[1:] if _reg1.match(_m)]
|
| 529 |
+
sys.argv = [_m for _m in sys.argv if _m not in sysinfo_flags]
|
| 530 |
+
if sysinfo_flags:
|
| 531 |
+
sysinfo_flags = [f[7:] for f in sysinfo_flags]
|
| 532 |
+
|
| 533 |
+
_reg2 = re.compile(
|
| 534 |
+
r'--((no-|)(wrap-functions|lower)|debug-capi|quiet|skip-empty-wrappers)|-include')
|
| 535 |
+
f2py_flags = [_m for _m in sys.argv[1:] if _reg2.match(_m)]
|
| 536 |
+
sys.argv = [_m for _m in sys.argv if _m not in f2py_flags]
|
| 537 |
+
f2py_flags2 = []
|
| 538 |
+
fl = 0
|
| 539 |
+
for a in sys.argv[1:]:
|
| 540 |
+
if a in ['only:', 'skip:']:
|
| 541 |
+
fl = 1
|
| 542 |
+
elif a == ':':
|
| 543 |
+
fl = 0
|
| 544 |
+
if fl or a == ':':
|
| 545 |
+
f2py_flags2.append(a)
|
| 546 |
+
if f2py_flags2 and f2py_flags2[-1] != ':':
|
| 547 |
+
f2py_flags2.append(':')
|
| 548 |
+
f2py_flags.extend(f2py_flags2)
|
| 549 |
+
|
| 550 |
+
sys.argv = [_m for _m in sys.argv if _m not in f2py_flags2]
|
| 551 |
+
_reg3 = re.compile(
|
| 552 |
+
r'--((f(90)?compiler(-exec|)|compiler)=|help-compiler)')
|
| 553 |
+
flib_flags = [_m for _m in sys.argv[1:] if _reg3.match(_m)]
|
| 554 |
+
sys.argv = [_m for _m in sys.argv if _m not in flib_flags]
|
| 555 |
+
_reg4 = re.compile(
|
| 556 |
+
r'--((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help-fcompiler))')
|
| 557 |
+
fc_flags = [_m for _m in sys.argv[1:] if _reg4.match(_m)]
|
| 558 |
+
sys.argv = [_m for _m in sys.argv if _m not in fc_flags]
|
| 559 |
+
|
| 560 |
+
del_list = []
|
| 561 |
+
for s in flib_flags:
|
| 562 |
+
v = '--fcompiler='
|
| 563 |
+
if s[:len(v)] == v:
|
| 564 |
+
from numpy.distutils import fcompiler
|
| 565 |
+
fcompiler.load_all_fcompiler_classes()
|
| 566 |
+
allowed_keys = list(fcompiler.fcompiler_class.keys())
|
| 567 |
+
nv = ov = s[len(v):].lower()
|
| 568 |
+
if ov not in allowed_keys:
|
| 569 |
+
vmap = {} # XXX
|
| 570 |
+
try:
|
| 571 |
+
nv = vmap[ov]
|
| 572 |
+
except KeyError:
|
| 573 |
+
if ov not in vmap.values():
|
| 574 |
+
print('Unknown vendor: "%s"' % (s[len(v):]))
|
| 575 |
+
nv = ov
|
| 576 |
+
i = flib_flags.index(s)
|
| 577 |
+
flib_flags[i] = '--fcompiler=' + nv
|
| 578 |
+
continue
|
| 579 |
+
for s in del_list:
|
| 580 |
+
i = flib_flags.index(s)
|
| 581 |
+
del flib_flags[i]
|
| 582 |
+
assert len(flib_flags) <= 2, repr(flib_flags)
|
| 583 |
+
|
| 584 |
+
_reg5 = re.compile(r'--(verbose)')
|
| 585 |
+
setup_flags = [_m for _m in sys.argv[1:] if _reg5.match(_m)]
|
| 586 |
+
sys.argv = [_m for _m in sys.argv if _m not in setup_flags]
|
| 587 |
+
|
| 588 |
+
if '--quiet' in f2py_flags:
|
| 589 |
+
setup_flags.append('--quiet')
|
| 590 |
+
|
| 591 |
+
modulename = 'untitled'
|
| 592 |
+
sources = sys.argv[1:]
|
| 593 |
+
|
| 594 |
+
for optname in ['--include_paths', '--include-paths', '--f2cmap']:
|
| 595 |
+
if optname in sys.argv:
|
| 596 |
+
i = sys.argv.index(optname)
|
| 597 |
+
f2py_flags.extend(sys.argv[i:i + 2])
|
| 598 |
+
del sys.argv[i + 1], sys.argv[i]
|
| 599 |
+
sources = sys.argv[1:]
|
| 600 |
+
|
| 601 |
+
if '-m' in sys.argv:
|
| 602 |
+
i = sys.argv.index('-m')
|
| 603 |
+
modulename = sys.argv[i + 1]
|
| 604 |
+
del sys.argv[i + 1], sys.argv[i]
|
| 605 |
+
sources = sys.argv[1:]
|
| 606 |
+
else:
|
| 607 |
+
from numpy.distutils.command.build_src import get_f2py_modulename
|
| 608 |
+
pyf_files, sources = filter_files('', '[.]pyf([.]src|)', sources)
|
| 609 |
+
sources = pyf_files + sources
|
| 610 |
+
for f in pyf_files:
|
| 611 |
+
modulename = get_f2py_modulename(f)
|
| 612 |
+
if modulename:
|
| 613 |
+
break
|
| 614 |
+
|
| 615 |
+
extra_objects, sources = filter_files('', '[.](o|a|so|dylib)', sources)
|
| 616 |
+
include_dirs, sources = filter_files('-I', '', sources, remove_prefix=1)
|
| 617 |
+
library_dirs, sources = filter_files('-L', '', sources, remove_prefix=1)
|
| 618 |
+
libraries, sources = filter_files('-l', '', sources, remove_prefix=1)
|
| 619 |
+
undef_macros, sources = filter_files('-U', '', sources, remove_prefix=1)
|
| 620 |
+
define_macros, sources = filter_files('-D', '', sources, remove_prefix=1)
|
| 621 |
+
for i in range(len(define_macros)):
|
| 622 |
+
name_value = define_macros[i].split('=', 1)
|
| 623 |
+
if len(name_value) == 1:
|
| 624 |
+
name_value.append(None)
|
| 625 |
+
if len(name_value) == 2:
|
| 626 |
+
define_macros[i] = tuple(name_value)
|
| 627 |
+
else:
|
| 628 |
+
print('Invalid use of -D:', name_value)
|
| 629 |
+
|
| 630 |
+
from numpy.distutils.system_info import get_info
|
| 631 |
+
|
| 632 |
+
num_info = {}
|
| 633 |
+
if num_info:
|
| 634 |
+
include_dirs.extend(num_info.get('include_dirs', []))
|
| 635 |
+
|
| 636 |
+
from numpy.distutils.core import setup, Extension
|
| 637 |
+
ext_args = {'name': modulename, 'sources': sources,
|
| 638 |
+
'include_dirs': include_dirs,
|
| 639 |
+
'library_dirs': library_dirs,
|
| 640 |
+
'libraries': libraries,
|
| 641 |
+
'define_macros': define_macros,
|
| 642 |
+
'undef_macros': undef_macros,
|
| 643 |
+
'extra_objects': extra_objects,
|
| 644 |
+
'f2py_options': f2py_flags,
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
if sysinfo_flags:
|
| 648 |
+
from numpy.distutils.misc_util import dict_append
|
| 649 |
+
for n in sysinfo_flags:
|
| 650 |
+
i = get_info(n)
|
| 651 |
+
if not i:
|
| 652 |
+
outmess('No %s resources found in system'
|
| 653 |
+
' (try `f2py --help-link`)\n' % (repr(n)))
|
| 654 |
+
dict_append(ext_args, **i)
|
| 655 |
+
|
| 656 |
+
ext = Extension(**ext_args)
|
| 657 |
+
sys.argv = [sys.argv[0]] + setup_flags
|
| 658 |
+
sys.argv.extend(['build',
|
| 659 |
+
'--build-temp', build_dir,
|
| 660 |
+
'--build-base', build_dir,
|
| 661 |
+
'--build-platlib', '.',
|
| 662 |
+
# disable CCompilerOpt
|
| 663 |
+
'--disable-optimization'])
|
| 664 |
+
if fc_flags:
|
| 665 |
+
sys.argv.extend(['config_fc'] + fc_flags)
|
| 666 |
+
if flib_flags:
|
| 667 |
+
sys.argv.extend(['build_ext'] + flib_flags)
|
| 668 |
+
|
| 669 |
+
setup(ext_modules=[ext])
|
| 670 |
+
|
| 671 |
+
if remove_build_dir and os.path.exists(build_dir):
|
| 672 |
+
import shutil
|
| 673 |
+
outmess('Removing build directory %s\n' % (build_dir))
|
| 674 |
+
shutil.rmtree(build_dir)
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
def main():
|
| 678 |
+
if '--help-link' in sys.argv[1:]:
|
| 679 |
+
sys.argv.remove('--help-link')
|
| 680 |
+
from numpy.distutils.system_info import show_all
|
| 681 |
+
show_all()
|
| 682 |
+
return
|
| 683 |
+
|
| 684 |
+
# Probably outdated options that were not working before 1.16
|
| 685 |
+
if '--g3-numpy' in sys.argv[1:]:
|
| 686 |
+
sys.stderr.write("G3 f2py support is not implemented, yet.\\n")
|
| 687 |
+
sys.exit(1)
|
| 688 |
+
elif '--2e-numeric' in sys.argv[1:]:
|
| 689 |
+
sys.argv.remove('--2e-numeric')
|
| 690 |
+
elif '--2e-numarray' in sys.argv[1:]:
|
| 691 |
+
# Note that this errors becaust the -DNUMARRAY argument is
|
| 692 |
+
# not recognized. Just here for back compatibility and the
|
| 693 |
+
# error message.
|
| 694 |
+
sys.argv.append("-DNUMARRAY")
|
| 695 |
+
sys.argv.remove('--2e-numarray')
|
| 696 |
+
elif '--2e-numpy' in sys.argv[1:]:
|
| 697 |
+
sys.argv.remove('--2e-numpy')
|
| 698 |
+
else:
|
| 699 |
+
pass
|
| 700 |
+
|
| 701 |
+
if '-c' in sys.argv[1:]:
|
| 702 |
+
run_compile()
|
| 703 |
+
else:
|
| 704 |
+
run_main(sys.argv[1:])
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/f90mod_rules.py
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Build F90 module support for f2py2e.
|
| 5 |
+
|
| 6 |
+
Copyright 2000 Pearu Peterson all rights reserved,
|
| 7 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 8 |
+
Permission to use, modify, and distribute this software is given under the
|
| 9 |
+
terms of the NumPy License.
|
| 10 |
+
|
| 11 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 12 |
+
$Date: 2005/02/03 19:30:23 $
|
| 13 |
+
Pearu Peterson
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
+
__version__ = "$Revision: 1.27 $"[10:-1]
|
| 17 |
+
|
| 18 |
+
f2py_version = 'See `f2py -v`'
|
| 19 |
+
|
| 20 |
+
import numpy as np
|
| 21 |
+
|
| 22 |
+
from . import capi_maps
|
| 23 |
+
from . import func2subr
|
| 24 |
+
from .crackfortran import undo_rmbadname, undo_rmbadname1
|
| 25 |
+
|
| 26 |
+
# The environment provided by auxfuncs.py is needed for some calls to eval.
|
| 27 |
+
# As the needed functions cannot be determined by static inspection of the
|
| 28 |
+
# code, it is safest to use import * pending a major refactoring of f2py.
|
| 29 |
+
from .auxfuncs import *
|
| 30 |
+
|
| 31 |
+
options = {}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def findf90modules(m):
|
| 35 |
+
if ismodule(m):
|
| 36 |
+
return [m]
|
| 37 |
+
if not hasbody(m):
|
| 38 |
+
return []
|
| 39 |
+
ret = []
|
| 40 |
+
for b in m['body']:
|
| 41 |
+
if ismodule(b):
|
| 42 |
+
ret.append(b)
|
| 43 |
+
else:
|
| 44 |
+
ret = ret + findf90modules(b)
|
| 45 |
+
return ret
|
| 46 |
+
|
| 47 |
+
fgetdims1 = """\
|
| 48 |
+
external f2pysetdata
|
| 49 |
+
logical ns
|
| 50 |
+
integer r,i
|
| 51 |
+
integer(%d) s(*)
|
| 52 |
+
ns = .FALSE.
|
| 53 |
+
if (allocated(d)) then
|
| 54 |
+
do i=1,r
|
| 55 |
+
if ((size(d,i).ne.s(i)).and.(s(i).ge.0)) then
|
| 56 |
+
ns = .TRUE.
|
| 57 |
+
end if
|
| 58 |
+
end do
|
| 59 |
+
if (ns) then
|
| 60 |
+
deallocate(d)
|
| 61 |
+
end if
|
| 62 |
+
end if
|
| 63 |
+
if ((.not.allocated(d)).and.(s(1).ge.1)) then""" % np.intp().itemsize
|
| 64 |
+
|
| 65 |
+
fgetdims2 = """\
|
| 66 |
+
end if
|
| 67 |
+
if (allocated(d)) then
|
| 68 |
+
do i=1,r
|
| 69 |
+
s(i) = size(d,i)
|
| 70 |
+
end do
|
| 71 |
+
end if
|
| 72 |
+
flag = 1
|
| 73 |
+
call f2pysetdata(d,allocated(d))"""
|
| 74 |
+
|
| 75 |
+
fgetdims2_sa = """\
|
| 76 |
+
end if
|
| 77 |
+
if (allocated(d)) then
|
| 78 |
+
do i=1,r
|
| 79 |
+
s(i) = size(d,i)
|
| 80 |
+
end do
|
| 81 |
+
!s(r) must be equal to len(d(1))
|
| 82 |
+
end if
|
| 83 |
+
flag = 2
|
| 84 |
+
call f2pysetdata(d,allocated(d))"""
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def buildhooks(pymod):
|
| 88 |
+
from . import rules
|
| 89 |
+
ret = {'f90modhooks': [], 'initf90modhooks': [], 'body': [],
|
| 90 |
+
'need': ['F_FUNC', 'arrayobject.h'],
|
| 91 |
+
'separatorsfor': {'includes0': '\n', 'includes': '\n'},
|
| 92 |
+
'docs': ['"Fortran 90/95 modules:\\n"'],
|
| 93 |
+
'latexdoc': []}
|
| 94 |
+
fhooks = ['']
|
| 95 |
+
|
| 96 |
+
def fadd(line, s=fhooks):
|
| 97 |
+
s[0] = '%s\n %s' % (s[0], line)
|
| 98 |
+
doc = ['']
|
| 99 |
+
|
| 100 |
+
def dadd(line, s=doc):
|
| 101 |
+
s[0] = '%s\n%s' % (s[0], line)
|
| 102 |
+
for m in findf90modules(pymod):
|
| 103 |
+
sargs, fargs, efargs, modobjs, notvars, onlyvars = [], [], [], [], [
|
| 104 |
+
m['name']], []
|
| 105 |
+
sargsp = []
|
| 106 |
+
ifargs = []
|
| 107 |
+
mfargs = []
|
| 108 |
+
if hasbody(m):
|
| 109 |
+
for b in m['body']:
|
| 110 |
+
notvars.append(b['name'])
|
| 111 |
+
for n in m['vars'].keys():
|
| 112 |
+
var = m['vars'][n]
|
| 113 |
+
if (n not in notvars) and (not l_or(isintent_hide, isprivate)(var)):
|
| 114 |
+
onlyvars.append(n)
|
| 115 |
+
mfargs.append(n)
|
| 116 |
+
outmess('\t\tConstructing F90 module support for "%s"...\n' %
|
| 117 |
+
(m['name']))
|
| 118 |
+
if onlyvars:
|
| 119 |
+
outmess('\t\t Variables: %s\n' % (' '.join(onlyvars)))
|
| 120 |
+
chooks = ['']
|
| 121 |
+
|
| 122 |
+
def cadd(line, s=chooks):
|
| 123 |
+
s[0] = '%s\n%s' % (s[0], line)
|
| 124 |
+
ihooks = ['']
|
| 125 |
+
|
| 126 |
+
def iadd(line, s=ihooks):
|
| 127 |
+
s[0] = '%s\n%s' % (s[0], line)
|
| 128 |
+
|
| 129 |
+
vrd = capi_maps.modsign2map(m)
|
| 130 |
+
cadd('static FortranDataDef f2py_%s_def[] = {' % (m['name']))
|
| 131 |
+
dadd('\\subsection{Fortran 90/95 module \\texttt{%s}}\n' % (m['name']))
|
| 132 |
+
if hasnote(m):
|
| 133 |
+
note = m['note']
|
| 134 |
+
if isinstance(note, list):
|
| 135 |
+
note = '\n'.join(note)
|
| 136 |
+
dadd(note)
|
| 137 |
+
if onlyvars:
|
| 138 |
+
dadd('\\begin{description}')
|
| 139 |
+
for n in onlyvars:
|
| 140 |
+
var = m['vars'][n]
|
| 141 |
+
modobjs.append(n)
|
| 142 |
+
ct = capi_maps.getctype(var)
|
| 143 |
+
at = capi_maps.c2capi_map[ct]
|
| 144 |
+
dm = capi_maps.getarrdims(n, var)
|
| 145 |
+
dms = dm['dims'].replace('*', '-1').strip()
|
| 146 |
+
dms = dms.replace(':', '-1').strip()
|
| 147 |
+
if not dms:
|
| 148 |
+
dms = '-1'
|
| 149 |
+
use_fgetdims2 = fgetdims2
|
| 150 |
+
cadd('\t{"%s",%s,{{%s}},%s, %s},' %
|
| 151 |
+
(undo_rmbadname1(n), dm['rank'], dms, at,
|
| 152 |
+
capi_maps.get_elsize(var)))
|
| 153 |
+
dadd('\\item[]{{}\\verb@%s@{}}' %
|
| 154 |
+
(capi_maps.getarrdocsign(n, var)))
|
| 155 |
+
if hasnote(var):
|
| 156 |
+
note = var['note']
|
| 157 |
+
if isinstance(note, list):
|
| 158 |
+
note = '\n'.join(note)
|
| 159 |
+
dadd('--- %s' % (note))
|
| 160 |
+
if isallocatable(var):
|
| 161 |
+
fargs.append('f2py_%s_getdims_%s' % (m['name'], n))
|
| 162 |
+
efargs.append(fargs[-1])
|
| 163 |
+
sargs.append(
|
| 164 |
+
'void (*%s)(int*,int*,void(*)(char*,int*),int*)' % (n))
|
| 165 |
+
sargsp.append('void (*)(int*,int*,void(*)(char*,int*),int*)')
|
| 166 |
+
iadd('\tf2py_%s_def[i_f2py++].func = %s;' % (m['name'], n))
|
| 167 |
+
fadd('subroutine %s(r,s,f2pysetdata,flag)' % (fargs[-1]))
|
| 168 |
+
fadd('use %s, only: d => %s\n' %
|
| 169 |
+
(m['name'], undo_rmbadname1(n)))
|
| 170 |
+
fadd('integer flag\n')
|
| 171 |
+
fhooks[0] = fhooks[0] + fgetdims1
|
| 172 |
+
dms = range(1, int(dm['rank']) + 1)
|
| 173 |
+
fadd(' allocate(d(%s))\n' %
|
| 174 |
+
(','.join(['s(%s)' % i for i in dms])))
|
| 175 |
+
fhooks[0] = fhooks[0] + use_fgetdims2
|
| 176 |
+
fadd('end subroutine %s' % (fargs[-1]))
|
| 177 |
+
else:
|
| 178 |
+
fargs.append(n)
|
| 179 |
+
sargs.append('char *%s' % (n))
|
| 180 |
+
sargsp.append('char*')
|
| 181 |
+
iadd('\tf2py_%s_def[i_f2py++].data = %s;' % (m['name'], n))
|
| 182 |
+
if onlyvars:
|
| 183 |
+
dadd('\\end{description}')
|
| 184 |
+
if hasbody(m):
|
| 185 |
+
for b in m['body']:
|
| 186 |
+
if not isroutine(b):
|
| 187 |
+
outmess("f90mod_rules.buildhooks:"
|
| 188 |
+
f" skipping {b['block']} {b['name']}\n")
|
| 189 |
+
continue
|
| 190 |
+
modobjs.append('%s()' % (b['name']))
|
| 191 |
+
b['modulename'] = m['name']
|
| 192 |
+
api, wrap = rules.buildapi(b)
|
| 193 |
+
if isfunction(b):
|
| 194 |
+
fhooks[0] = fhooks[0] + wrap
|
| 195 |
+
fargs.append('f2pywrap_%s_%s' % (m['name'], b['name']))
|
| 196 |
+
ifargs.append(func2subr.createfuncwrapper(b, signature=1))
|
| 197 |
+
else:
|
| 198 |
+
if wrap:
|
| 199 |
+
fhooks[0] = fhooks[0] + wrap
|
| 200 |
+
fargs.append('f2pywrap_%s_%s' % (m['name'], b['name']))
|
| 201 |
+
ifargs.append(
|
| 202 |
+
func2subr.createsubrwrapper(b, signature=1))
|
| 203 |
+
else:
|
| 204 |
+
fargs.append(b['name'])
|
| 205 |
+
mfargs.append(fargs[-1])
|
| 206 |
+
api['externroutines'] = []
|
| 207 |
+
ar = applyrules(api, vrd)
|
| 208 |
+
ar['docs'] = []
|
| 209 |
+
ar['docshort'] = []
|
| 210 |
+
ret = dictappend(ret, ar)
|
| 211 |
+
cadd(('\t{"%s",-1,{{-1}},0,0,NULL,(void *)'
|
| 212 |
+
'f2py_rout_#modulename#_%s_%s,'
|
| 213 |
+
'doc_f2py_rout_#modulename#_%s_%s},')
|
| 214 |
+
% (b['name'], m['name'], b['name'], m['name'], b['name']))
|
| 215 |
+
sargs.append('char *%s' % (b['name']))
|
| 216 |
+
sargsp.append('char *')
|
| 217 |
+
iadd('\tf2py_%s_def[i_f2py++].data = %s;' %
|
| 218 |
+
(m['name'], b['name']))
|
| 219 |
+
cadd('\t{NULL}\n};\n')
|
| 220 |
+
iadd('}')
|
| 221 |
+
ihooks[0] = 'static void f2py_setup_%s(%s) {\n\tint i_f2py=0;%s' % (
|
| 222 |
+
m['name'], ','.join(sargs), ihooks[0])
|
| 223 |
+
if '_' in m['name']:
|
| 224 |
+
F_FUNC = 'F_FUNC_US'
|
| 225 |
+
else:
|
| 226 |
+
F_FUNC = 'F_FUNC'
|
| 227 |
+
iadd('extern void %s(f2pyinit%s,F2PYINIT%s)(void (*)(%s));'
|
| 228 |
+
% (F_FUNC, m['name'], m['name'].upper(), ','.join(sargsp)))
|
| 229 |
+
iadd('static void f2py_init_%s(void) {' % (m['name']))
|
| 230 |
+
iadd('\t%s(f2pyinit%s,F2PYINIT%s)(f2py_setup_%s);'
|
| 231 |
+
% (F_FUNC, m['name'], m['name'].upper(), m['name']))
|
| 232 |
+
iadd('}\n')
|
| 233 |
+
ret['f90modhooks'] = ret['f90modhooks'] + chooks + ihooks
|
| 234 |
+
ret['initf90modhooks'] = ['\tPyDict_SetItemString(d, "%s", PyFortranObject_New(f2py_%s_def,f2py_init_%s));' % (
|
| 235 |
+
m['name'], m['name'], m['name'])] + ret['initf90modhooks']
|
| 236 |
+
fadd('')
|
| 237 |
+
fadd('subroutine f2pyinit%s(f2pysetupfunc)' % (m['name']))
|
| 238 |
+
if mfargs:
|
| 239 |
+
for a in undo_rmbadname(mfargs):
|
| 240 |
+
fadd('use %s, only : %s' % (m['name'], a))
|
| 241 |
+
if ifargs:
|
| 242 |
+
fadd(' '.join(['interface'] + ifargs))
|
| 243 |
+
fadd('end interface')
|
| 244 |
+
fadd('external f2pysetupfunc')
|
| 245 |
+
if efargs:
|
| 246 |
+
for a in undo_rmbadname(efargs):
|
| 247 |
+
fadd('external %s' % (a))
|
| 248 |
+
fadd('call f2pysetupfunc(%s)' % (','.join(undo_rmbadname(fargs))))
|
| 249 |
+
fadd('end subroutine f2pyinit%s\n' % (m['name']))
|
| 250 |
+
|
| 251 |
+
dadd('\n'.join(ret['latexdoc']).replace(
|
| 252 |
+
r'\subsection{', r'\subsubsection{'))
|
| 253 |
+
|
| 254 |
+
ret['latexdoc'] = []
|
| 255 |
+
ret['docs'].append('"\t%s --- %s"' % (m['name'],
|
| 256 |
+
','.join(undo_rmbadname(modobjs))))
|
| 257 |
+
|
| 258 |
+
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|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Rules for building C/API module with f2py2e.
|
| 5 |
+
|
| 6 |
+
Copyright 1999,2000 Pearu Peterson all rights reserved,
|
| 7 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 8 |
+
Permission to use, modify, and distribute this software is given under the
|
| 9 |
+
terms of the NumPy License.
|
| 10 |
+
|
| 11 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 12 |
+
$Date: 2004/11/26 11:13:06 $
|
| 13 |
+
Pearu Peterson
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
+
import copy
|
| 17 |
+
|
| 18 |
+
from .auxfuncs import (
|
| 19 |
+
getfortranname, isexternal, isfunction, isfunction_wrap, isintent_in,
|
| 20 |
+
isintent_out, islogicalfunction, ismoduleroutine, isscalar,
|
| 21 |
+
issubroutine, issubroutine_wrap, outmess, show
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def var2fixfortran(vars, a, fa=None, f90mode=None):
|
| 26 |
+
if fa is None:
|
| 27 |
+
fa = a
|
| 28 |
+
if a not in vars:
|
| 29 |
+
show(vars)
|
| 30 |
+
outmess('var2fixfortran: No definition for argument "%s".\n' % a)
|
| 31 |
+
return ''
|
| 32 |
+
if 'typespec' not in vars[a]:
|
| 33 |
+
show(vars[a])
|
| 34 |
+
outmess('var2fixfortran: No typespec for argument "%s".\n' % a)
|
| 35 |
+
return ''
|
| 36 |
+
vardef = vars[a]['typespec']
|
| 37 |
+
if vardef == 'type' and 'typename' in vars[a]:
|
| 38 |
+
vardef = '%s(%s)' % (vardef, vars[a]['typename'])
|
| 39 |
+
selector = {}
|
| 40 |
+
lk = ''
|
| 41 |
+
if 'kindselector' in vars[a]:
|
| 42 |
+
selector = vars[a]['kindselector']
|
| 43 |
+
lk = 'kind'
|
| 44 |
+
elif 'charselector' in vars[a]:
|
| 45 |
+
selector = vars[a]['charselector']
|
| 46 |
+
lk = 'len'
|
| 47 |
+
if '*' in selector:
|
| 48 |
+
if f90mode:
|
| 49 |
+
if selector['*'] in ['*', ':', '(*)']:
|
| 50 |
+
vardef = '%s(len=*)' % (vardef)
|
| 51 |
+
else:
|
| 52 |
+
vardef = '%s(%s=%s)' % (vardef, lk, selector['*'])
|
| 53 |
+
else:
|
| 54 |
+
if selector['*'] in ['*', ':']:
|
| 55 |
+
vardef = '%s*(%s)' % (vardef, selector['*'])
|
| 56 |
+
else:
|
| 57 |
+
vardef = '%s*%s' % (vardef, selector['*'])
|
| 58 |
+
else:
|
| 59 |
+
if 'len' in selector:
|
| 60 |
+
vardef = '%s(len=%s' % (vardef, selector['len'])
|
| 61 |
+
if 'kind' in selector:
|
| 62 |
+
vardef = '%s,kind=%s)' % (vardef, selector['kind'])
|
| 63 |
+
else:
|
| 64 |
+
vardef = '%s)' % (vardef)
|
| 65 |
+
elif 'kind' in selector:
|
| 66 |
+
vardef = '%s(kind=%s)' % (vardef, selector['kind'])
|
| 67 |
+
|
| 68 |
+
vardef = '%s %s' % (vardef, fa)
|
| 69 |
+
if 'dimension' in vars[a]:
|
| 70 |
+
vardef = '%s(%s)' % (vardef, ','.join(vars[a]['dimension']))
|
| 71 |
+
return vardef
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def createfuncwrapper(rout, signature=0):
|
| 75 |
+
assert isfunction(rout)
|
| 76 |
+
|
| 77 |
+
extra_args = []
|
| 78 |
+
vars = rout['vars']
|
| 79 |
+
for a in rout['args']:
|
| 80 |
+
v = rout['vars'][a]
|
| 81 |
+
for i, d in enumerate(v.get('dimension', [])):
|
| 82 |
+
if d == ':':
|
| 83 |
+
dn = 'f2py_%s_d%s' % (a, i)
|
| 84 |
+
dv = dict(typespec='integer', intent=['hide'])
|
| 85 |
+
dv['='] = 'shape(%s, %s)' % (a, i)
|
| 86 |
+
extra_args.append(dn)
|
| 87 |
+
vars[dn] = dv
|
| 88 |
+
v['dimension'][i] = dn
|
| 89 |
+
rout['args'].extend(extra_args)
|
| 90 |
+
need_interface = bool(extra_args)
|
| 91 |
+
|
| 92 |
+
ret = ['']
|
| 93 |
+
|
| 94 |
+
def add(line, ret=ret):
|
| 95 |
+
ret[0] = '%s\n %s' % (ret[0], line)
|
| 96 |
+
name = rout['name']
|
| 97 |
+
fortranname = getfortranname(rout)
|
| 98 |
+
f90mode = ismoduleroutine(rout)
|
| 99 |
+
newname = '%sf2pywrap' % (name)
|
| 100 |
+
|
| 101 |
+
if newname not in vars:
|
| 102 |
+
vars[newname] = vars[name]
|
| 103 |
+
args = [newname] + rout['args'][1:]
|
| 104 |
+
else:
|
| 105 |
+
args = [newname] + rout['args']
|
| 106 |
+
|
| 107 |
+
l_tmpl = var2fixfortran(vars, name, '@@@NAME@@@', f90mode)
|
| 108 |
+
if l_tmpl[:13] == 'character*(*)':
|
| 109 |
+
if f90mode:
|
| 110 |
+
l_tmpl = 'character(len=10)' + l_tmpl[13:]
|
| 111 |
+
else:
|
| 112 |
+
l_tmpl = 'character*10' + l_tmpl[13:]
|
| 113 |
+
charselect = vars[name]['charselector']
|
| 114 |
+
if charselect.get('*', '') == '(*)':
|
| 115 |
+
charselect['*'] = '10'
|
| 116 |
+
|
| 117 |
+
l1 = l_tmpl.replace('@@@NAME@@@', newname)
|
| 118 |
+
rl = None
|
| 119 |
+
|
| 120 |
+
sargs = ', '.join(args)
|
| 121 |
+
if f90mode:
|
| 122 |
+
add('subroutine f2pywrap_%s_%s (%s)' %
|
| 123 |
+
(rout['modulename'], name, sargs))
|
| 124 |
+
if not signature:
|
| 125 |
+
add('use %s, only : %s' % (rout['modulename'], fortranname))
|
| 126 |
+
else:
|
| 127 |
+
add('subroutine f2pywrap%s (%s)' % (name, sargs))
|
| 128 |
+
if not need_interface:
|
| 129 |
+
add('external %s' % (fortranname))
|
| 130 |
+
rl = l_tmpl.replace('@@@NAME@@@', '') + ' ' + fortranname
|
| 131 |
+
|
| 132 |
+
if need_interface:
|
| 133 |
+
for line in rout['saved_interface'].split('\n'):
|
| 134 |
+
if line.lstrip().startswith('use ') and '__user__' not in line:
|
| 135 |
+
add(line)
|
| 136 |
+
|
| 137 |
+
args = args[1:]
|
| 138 |
+
dumped_args = []
|
| 139 |
+
for a in args:
|
| 140 |
+
if isexternal(vars[a]):
|
| 141 |
+
add('external %s' % (a))
|
| 142 |
+
dumped_args.append(a)
|
| 143 |
+
for a in args:
|
| 144 |
+
if a in dumped_args:
|
| 145 |
+
continue
|
| 146 |
+
if isscalar(vars[a]):
|
| 147 |
+
add(var2fixfortran(vars, a, f90mode=f90mode))
|
| 148 |
+
dumped_args.append(a)
|
| 149 |
+
for a in args:
|
| 150 |
+
if a in dumped_args:
|
| 151 |
+
continue
|
| 152 |
+
if isintent_in(vars[a]):
|
| 153 |
+
add(var2fixfortran(vars, a, f90mode=f90mode))
|
| 154 |
+
dumped_args.append(a)
|
| 155 |
+
for a in args:
|
| 156 |
+
if a in dumped_args:
|
| 157 |
+
continue
|
| 158 |
+
add(var2fixfortran(vars, a, f90mode=f90mode))
|
| 159 |
+
|
| 160 |
+
add(l1)
|
| 161 |
+
if rl is not None:
|
| 162 |
+
add(rl)
|
| 163 |
+
|
| 164 |
+
if need_interface:
|
| 165 |
+
if f90mode:
|
| 166 |
+
# f90 module already defines needed interface
|
| 167 |
+
pass
|
| 168 |
+
else:
|
| 169 |
+
add('interface')
|
| 170 |
+
add(rout['saved_interface'].lstrip())
|
| 171 |
+
add('end interface')
|
| 172 |
+
|
| 173 |
+
sargs = ', '.join([a for a in args if a not in extra_args])
|
| 174 |
+
|
| 175 |
+
if not signature:
|
| 176 |
+
if islogicalfunction(rout):
|
| 177 |
+
add('%s = .not.(.not.%s(%s))' % (newname, fortranname, sargs))
|
| 178 |
+
else:
|
| 179 |
+
add('%s = %s(%s)' % (newname, fortranname, sargs))
|
| 180 |
+
if f90mode:
|
| 181 |
+
add('end subroutine f2pywrap_%s_%s' % (rout['modulename'], name))
|
| 182 |
+
else:
|
| 183 |
+
add('end')
|
| 184 |
+
return ret[0]
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def createsubrwrapper(rout, signature=0):
|
| 188 |
+
assert issubroutine(rout)
|
| 189 |
+
|
| 190 |
+
extra_args = []
|
| 191 |
+
vars = rout['vars']
|
| 192 |
+
for a in rout['args']:
|
| 193 |
+
v = rout['vars'][a]
|
| 194 |
+
for i, d in enumerate(v.get('dimension', [])):
|
| 195 |
+
if d == ':':
|
| 196 |
+
dn = 'f2py_%s_d%s' % (a, i)
|
| 197 |
+
dv = dict(typespec='integer', intent=['hide'])
|
| 198 |
+
dv['='] = 'shape(%s, %s)' % (a, i)
|
| 199 |
+
extra_args.append(dn)
|
| 200 |
+
vars[dn] = dv
|
| 201 |
+
v['dimension'][i] = dn
|
| 202 |
+
rout['args'].extend(extra_args)
|
| 203 |
+
need_interface = bool(extra_args)
|
| 204 |
+
|
| 205 |
+
ret = ['']
|
| 206 |
+
|
| 207 |
+
def add(line, ret=ret):
|
| 208 |
+
ret[0] = '%s\n %s' % (ret[0], line)
|
| 209 |
+
name = rout['name']
|
| 210 |
+
fortranname = getfortranname(rout)
|
| 211 |
+
f90mode = ismoduleroutine(rout)
|
| 212 |
+
|
| 213 |
+
args = rout['args']
|
| 214 |
+
|
| 215 |
+
sargs = ', '.join(args)
|
| 216 |
+
if f90mode:
|
| 217 |
+
add('subroutine f2pywrap_%s_%s (%s)' %
|
| 218 |
+
(rout['modulename'], name, sargs))
|
| 219 |
+
if not signature:
|
| 220 |
+
add('use %s, only : %s' % (rout['modulename'], fortranname))
|
| 221 |
+
else:
|
| 222 |
+
add('subroutine f2pywrap%s (%s)' % (name, sargs))
|
| 223 |
+
if not need_interface:
|
| 224 |
+
add('external %s' % (fortranname))
|
| 225 |
+
|
| 226 |
+
if need_interface:
|
| 227 |
+
for line in rout['saved_interface'].split('\n'):
|
| 228 |
+
if line.lstrip().startswith('use ') and '__user__' not in line:
|
| 229 |
+
add(line)
|
| 230 |
+
|
| 231 |
+
dumped_args = []
|
| 232 |
+
for a in args:
|
| 233 |
+
if isexternal(vars[a]):
|
| 234 |
+
add('external %s' % (a))
|
| 235 |
+
dumped_args.append(a)
|
| 236 |
+
for a in args:
|
| 237 |
+
if a in dumped_args:
|
| 238 |
+
continue
|
| 239 |
+
if isscalar(vars[a]):
|
| 240 |
+
add(var2fixfortran(vars, a, f90mode=f90mode))
|
| 241 |
+
dumped_args.append(a)
|
| 242 |
+
for a in args:
|
| 243 |
+
if a in dumped_args:
|
| 244 |
+
continue
|
| 245 |
+
add(var2fixfortran(vars, a, f90mode=f90mode))
|
| 246 |
+
|
| 247 |
+
if need_interface:
|
| 248 |
+
if f90mode:
|
| 249 |
+
# f90 module already defines needed interface
|
| 250 |
+
pass
|
| 251 |
+
else:
|
| 252 |
+
add('interface')
|
| 253 |
+
for line in rout['saved_interface'].split('\n'):
|
| 254 |
+
if line.lstrip().startswith('use ') and '__user__' in line:
|
| 255 |
+
continue
|
| 256 |
+
add(line)
|
| 257 |
+
add('end interface')
|
| 258 |
+
|
| 259 |
+
sargs = ', '.join([a for a in args if a not in extra_args])
|
| 260 |
+
|
| 261 |
+
if not signature:
|
| 262 |
+
add('call %s(%s)' % (fortranname, sargs))
|
| 263 |
+
if f90mode:
|
| 264 |
+
add('end subroutine f2pywrap_%s_%s' % (rout['modulename'], name))
|
| 265 |
+
else:
|
| 266 |
+
add('end')
|
| 267 |
+
return ret[0]
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def assubr(rout):
|
| 271 |
+
if isfunction_wrap(rout):
|
| 272 |
+
fortranname = getfortranname(rout)
|
| 273 |
+
name = rout['name']
|
| 274 |
+
outmess('\t\tCreating wrapper for Fortran function "%s"("%s")...\n' % (
|
| 275 |
+
name, fortranname))
|
| 276 |
+
rout = copy.copy(rout)
|
| 277 |
+
fname = name
|
| 278 |
+
rname = fname
|
| 279 |
+
if 'result' in rout:
|
| 280 |
+
rname = rout['result']
|
| 281 |
+
rout['vars'][fname] = rout['vars'][rname]
|
| 282 |
+
fvar = rout['vars'][fname]
|
| 283 |
+
if not isintent_out(fvar):
|
| 284 |
+
if 'intent' not in fvar:
|
| 285 |
+
fvar['intent'] = []
|
| 286 |
+
fvar['intent'].append('out')
|
| 287 |
+
flag = 1
|
| 288 |
+
for i in fvar['intent']:
|
| 289 |
+
if i.startswith('out='):
|
| 290 |
+
flag = 0
|
| 291 |
+
break
|
| 292 |
+
if flag:
|
| 293 |
+
fvar['intent'].append('out=%s' % (rname))
|
| 294 |
+
rout['args'][:] = [fname] + rout['args']
|
| 295 |
+
return rout, createfuncwrapper(rout)
|
| 296 |
+
if issubroutine_wrap(rout):
|
| 297 |
+
fortranname = getfortranname(rout)
|
| 298 |
+
name = rout['name']
|
| 299 |
+
outmess('\t\tCreating wrapper for Fortran subroutine "%s"("%s")...\n'
|
| 300 |
+
% (name, fortranname))
|
| 301 |
+
rout = copy.copy(rout)
|
| 302 |
+
return rout, createsubrwrapper(rout)
|
| 303 |
+
return rout, ''
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/rules.py
ADDED
|
@@ -0,0 +1,1571 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Rules for building C/API module with f2py2e.
|
| 5 |
+
|
| 6 |
+
Here is a skeleton of a new wrapper function (13Dec2001):
|
| 7 |
+
|
| 8 |
+
wrapper_function(args)
|
| 9 |
+
declarations
|
| 10 |
+
get_python_arguments, say, `a' and `b'
|
| 11 |
+
|
| 12 |
+
get_a_from_python
|
| 13 |
+
if (successful) {
|
| 14 |
+
|
| 15 |
+
get_b_from_python
|
| 16 |
+
if (successful) {
|
| 17 |
+
|
| 18 |
+
callfortran
|
| 19 |
+
if (successful) {
|
| 20 |
+
|
| 21 |
+
put_a_to_python
|
| 22 |
+
if (successful) {
|
| 23 |
+
|
| 24 |
+
put_b_to_python
|
| 25 |
+
if (successful) {
|
| 26 |
+
|
| 27 |
+
buildvalue = ...
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
}
|
| 36 |
+
cleanup_b
|
| 37 |
+
|
| 38 |
+
}
|
| 39 |
+
cleanup_a
|
| 40 |
+
|
| 41 |
+
return buildvalue
|
| 42 |
+
|
| 43 |
+
Copyright 1999,2000 Pearu Peterson all rights reserved,
|
| 44 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 45 |
+
Permission to use, modify, and distribute this software is given under the
|
| 46 |
+
terms of the NumPy License.
|
| 47 |
+
|
| 48 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 49 |
+
$Date: 2005/08/30 08:58:42 $
|
| 50 |
+
Pearu Peterson
|
| 51 |
+
|
| 52 |
+
"""
|
| 53 |
+
import os, sys
|
| 54 |
+
import time
|
| 55 |
+
import copy
|
| 56 |
+
from pathlib import Path
|
| 57 |
+
|
| 58 |
+
# __version__.version is now the same as the NumPy version
|
| 59 |
+
from . import __version__
|
| 60 |
+
|
| 61 |
+
from .auxfuncs import (
|
| 62 |
+
applyrules, debugcapi, dictappend, errmess, gentitle, getargs2,
|
| 63 |
+
hascallstatement, hasexternals, hasinitvalue, hasnote,
|
| 64 |
+
hasresultnote, isarray, isarrayofstrings, ischaracter,
|
| 65 |
+
ischaracterarray, ischaracter_or_characterarray, iscomplex,
|
| 66 |
+
iscomplexarray, iscomplexfunction, iscomplexfunction_warn,
|
| 67 |
+
isdummyroutine, isexternal, isfunction, isfunction_wrap, isint1,
|
| 68 |
+
isint1array, isintent_aux, isintent_c, isintent_callback,
|
| 69 |
+
isintent_copy, isintent_hide, isintent_inout, isintent_nothide,
|
| 70 |
+
isintent_out, isintent_overwrite, islogical, islong_complex,
|
| 71 |
+
islong_double, islong_doublefunction, islong_long,
|
| 72 |
+
islong_longfunction, ismoduleroutine, isoptional, isrequired,
|
| 73 |
+
isscalar, issigned_long_longarray, isstring, isstringarray,
|
| 74 |
+
isstringfunction, issubroutine, isattr_value,
|
| 75 |
+
issubroutine_wrap, isthreadsafe, isunsigned, isunsigned_char,
|
| 76 |
+
isunsigned_chararray, isunsigned_long_long,
|
| 77 |
+
isunsigned_long_longarray, isunsigned_short, isunsigned_shortarray,
|
| 78 |
+
l_and, l_not, l_or, outmess, replace, stripcomma, requiresf90wrapper
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
from . import capi_maps
|
| 82 |
+
from . import cfuncs
|
| 83 |
+
from . import common_rules
|
| 84 |
+
from . import use_rules
|
| 85 |
+
from . import f90mod_rules
|
| 86 |
+
from . import func2subr
|
| 87 |
+
|
| 88 |
+
f2py_version = __version__.version
|
| 89 |
+
numpy_version = __version__.version
|
| 90 |
+
|
| 91 |
+
options = {}
|
| 92 |
+
sepdict = {}
|
| 93 |
+
# for k in ['need_cfuncs']: sepdict[k]=','
|
| 94 |
+
for k in ['decl',
|
| 95 |
+
'frompyobj',
|
| 96 |
+
'cleanupfrompyobj',
|
| 97 |
+
'topyarr', 'method',
|
| 98 |
+
'pyobjfrom', 'closepyobjfrom',
|
| 99 |
+
'freemem',
|
| 100 |
+
'userincludes',
|
| 101 |
+
'includes0', 'includes', 'typedefs', 'typedefs_generated',
|
| 102 |
+
'cppmacros', 'cfuncs', 'callbacks',
|
| 103 |
+
'latexdoc',
|
| 104 |
+
'restdoc',
|
| 105 |
+
'routine_defs', 'externroutines',
|
| 106 |
+
'initf2pywraphooks',
|
| 107 |
+
'commonhooks', 'initcommonhooks',
|
| 108 |
+
'f90modhooks', 'initf90modhooks']:
|
| 109 |
+
sepdict[k] = '\n'
|
| 110 |
+
|
| 111 |
+
#################### Rules for C/API module #################
|
| 112 |
+
|
| 113 |
+
generationtime = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
|
| 114 |
+
module_rules = {
|
| 115 |
+
'modulebody': """\
|
| 116 |
+
/* File: #modulename#module.c
|
| 117 |
+
* This file is auto-generated with f2py (version:#f2py_version#).
|
| 118 |
+
* f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,
|
| 119 |
+
* written by Pearu Peterson <pearu@cens.ioc.ee>.
|
| 120 |
+
* Generation date: """ + time.asctime(time.gmtime(generationtime)) + """
|
| 121 |
+
* Do not edit this file directly unless you know what you are doing!!!
|
| 122 |
+
*/
|
| 123 |
+
|
| 124 |
+
#ifdef __cplusplus
|
| 125 |
+
extern \"C\" {
|
| 126 |
+
#endif
|
| 127 |
+
|
| 128 |
+
#ifndef PY_SSIZE_T_CLEAN
|
| 129 |
+
#define PY_SSIZE_T_CLEAN
|
| 130 |
+
#endif /* PY_SSIZE_T_CLEAN */
|
| 131 |
+
|
| 132 |
+
/* Unconditionally included */
|
| 133 |
+
#include <Python.h>
|
| 134 |
+
#include <numpy/npy_os.h>
|
| 135 |
+
|
| 136 |
+
""" + gentitle("See f2py2e/cfuncs.py: includes") + """
|
| 137 |
+
#includes#
|
| 138 |
+
#includes0#
|
| 139 |
+
|
| 140 |
+
""" + gentitle("See f2py2e/rules.py: mod_rules['modulebody']") + """
|
| 141 |
+
static PyObject *#modulename#_error;
|
| 142 |
+
static PyObject *#modulename#_module;
|
| 143 |
+
|
| 144 |
+
""" + gentitle("See f2py2e/cfuncs.py: typedefs") + """
|
| 145 |
+
#typedefs#
|
| 146 |
+
|
| 147 |
+
""" + gentitle("See f2py2e/cfuncs.py: typedefs_generated") + """
|
| 148 |
+
#typedefs_generated#
|
| 149 |
+
|
| 150 |
+
""" + gentitle("See f2py2e/cfuncs.py: cppmacros") + """
|
| 151 |
+
#cppmacros#
|
| 152 |
+
|
| 153 |
+
""" + gentitle("See f2py2e/cfuncs.py: cfuncs") + """
|
| 154 |
+
#cfuncs#
|
| 155 |
+
|
| 156 |
+
""" + gentitle("See f2py2e/cfuncs.py: userincludes") + """
|
| 157 |
+
#userincludes#
|
| 158 |
+
|
| 159 |
+
""" + gentitle("See f2py2e/capi_rules.py: usercode") + """
|
| 160 |
+
#usercode#
|
| 161 |
+
|
| 162 |
+
/* See f2py2e/rules.py */
|
| 163 |
+
#externroutines#
|
| 164 |
+
|
| 165 |
+
""" + gentitle("See f2py2e/capi_rules.py: usercode1") + """
|
| 166 |
+
#usercode1#
|
| 167 |
+
|
| 168 |
+
""" + gentitle("See f2py2e/cb_rules.py: buildcallback") + """
|
| 169 |
+
#callbacks#
|
| 170 |
+
|
| 171 |
+
""" + gentitle("See f2py2e/rules.py: buildapi") + """
|
| 172 |
+
#body#
|
| 173 |
+
|
| 174 |
+
""" + gentitle("See f2py2e/f90mod_rules.py: buildhooks") + """
|
| 175 |
+
#f90modhooks#
|
| 176 |
+
|
| 177 |
+
""" + gentitle("See f2py2e/rules.py: module_rules['modulebody']") + """
|
| 178 |
+
|
| 179 |
+
""" + gentitle("See f2py2e/common_rules.py: buildhooks") + """
|
| 180 |
+
#commonhooks#
|
| 181 |
+
|
| 182 |
+
""" + gentitle("See f2py2e/rules.py") + """
|
| 183 |
+
|
| 184 |
+
static FortranDataDef f2py_routine_defs[] = {
|
| 185 |
+
#routine_defs#
|
| 186 |
+
{NULL}
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
static PyMethodDef f2py_module_methods[] = {
|
| 190 |
+
#pymethoddef#
|
| 191 |
+
{NULL,NULL}
|
| 192 |
+
};
|
| 193 |
+
|
| 194 |
+
static struct PyModuleDef moduledef = {
|
| 195 |
+
PyModuleDef_HEAD_INIT,
|
| 196 |
+
"#modulename#",
|
| 197 |
+
NULL,
|
| 198 |
+
-1,
|
| 199 |
+
f2py_module_methods,
|
| 200 |
+
NULL,
|
| 201 |
+
NULL,
|
| 202 |
+
NULL,
|
| 203 |
+
NULL
|
| 204 |
+
};
|
| 205 |
+
|
| 206 |
+
PyMODINIT_FUNC PyInit_#modulename#(void) {
|
| 207 |
+
int i;
|
| 208 |
+
PyObject *m,*d, *s, *tmp;
|
| 209 |
+
m = #modulename#_module = PyModule_Create(&moduledef);
|
| 210 |
+
Py_SET_TYPE(&PyFortran_Type, &PyType_Type);
|
| 211 |
+
import_array();
|
| 212 |
+
if (PyErr_Occurred())
|
| 213 |
+
{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return m;}
|
| 214 |
+
d = PyModule_GetDict(m);
|
| 215 |
+
s = PyUnicode_FromString(\"#f2py_version#\");
|
| 216 |
+
PyDict_SetItemString(d, \"__version__\", s);
|
| 217 |
+
Py_DECREF(s);
|
| 218 |
+
s = PyUnicode_FromString(
|
| 219 |
+
\"This module '#modulename#' is auto-generated with f2py (version:#f2py_version#).\\nFunctions:\\n\"\n#docs#\".\");
|
| 220 |
+
PyDict_SetItemString(d, \"__doc__\", s);
|
| 221 |
+
Py_DECREF(s);
|
| 222 |
+
s = PyUnicode_FromString(\"""" + numpy_version + """\");
|
| 223 |
+
PyDict_SetItemString(d, \"__f2py_numpy_version__\", s);
|
| 224 |
+
Py_DECREF(s);
|
| 225 |
+
#modulename#_error = PyErr_NewException (\"#modulename#.error\", NULL, NULL);
|
| 226 |
+
/*
|
| 227 |
+
* Store the error object inside the dict, so that it could get deallocated.
|
| 228 |
+
* (in practice, this is a module, so it likely will not and cannot.)
|
| 229 |
+
*/
|
| 230 |
+
PyDict_SetItemString(d, \"_#modulename#_error\", #modulename#_error);
|
| 231 |
+
Py_DECREF(#modulename#_error);
|
| 232 |
+
for(i=0;f2py_routine_defs[i].name!=NULL;i++) {
|
| 233 |
+
tmp = PyFortranObject_NewAsAttr(&f2py_routine_defs[i]);
|
| 234 |
+
PyDict_SetItemString(d, f2py_routine_defs[i].name, tmp);
|
| 235 |
+
Py_DECREF(tmp);
|
| 236 |
+
}
|
| 237 |
+
#initf2pywraphooks#
|
| 238 |
+
#initf90modhooks#
|
| 239 |
+
#initcommonhooks#
|
| 240 |
+
#interface_usercode#
|
| 241 |
+
|
| 242 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 243 |
+
if (! PyErr_Occurred())
|
| 244 |
+
on_exit(f2py_report_on_exit,(void*)\"#modulename#\");
|
| 245 |
+
#endif
|
| 246 |
+
return m;
|
| 247 |
+
}
|
| 248 |
+
#ifdef __cplusplus
|
| 249 |
+
}
|
| 250 |
+
#endif
|
| 251 |
+
""",
|
| 252 |
+
'separatorsfor': {'latexdoc': '\n\n',
|
| 253 |
+
'restdoc': '\n\n'},
|
| 254 |
+
'latexdoc': ['\\section{Module \\texttt{#texmodulename#}}\n',
|
| 255 |
+
'#modnote#\n',
|
| 256 |
+
'#latexdoc#'],
|
| 257 |
+
'restdoc': ['Module #modulename#\n' + '=' * 80,
|
| 258 |
+
'\n#restdoc#']
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
defmod_rules = [
|
| 262 |
+
{'body': '/*eof body*/',
|
| 263 |
+
'method': '/*eof method*/',
|
| 264 |
+
'externroutines': '/*eof externroutines*/',
|
| 265 |
+
'routine_defs': '/*eof routine_defs*/',
|
| 266 |
+
'initf90modhooks': '/*eof initf90modhooks*/',
|
| 267 |
+
'initf2pywraphooks': '/*eof initf2pywraphooks*/',
|
| 268 |
+
'initcommonhooks': '/*eof initcommonhooks*/',
|
| 269 |
+
'latexdoc': '',
|
| 270 |
+
'restdoc': '',
|
| 271 |
+
'modnote': {hasnote: '#note#', l_not(hasnote): ''},
|
| 272 |
+
}
|
| 273 |
+
]
|
| 274 |
+
|
| 275 |
+
routine_rules = {
|
| 276 |
+
'separatorsfor': sepdict,
|
| 277 |
+
'body': """
|
| 278 |
+
#begintitle#
|
| 279 |
+
static char doc_#apiname#[] = \"\\\n#docreturn##name#(#docsignatureshort#)\\n\\nWrapper for ``#name#``.\\\n\\n#docstrsigns#\";
|
| 280 |
+
/* #declfortranroutine# */
|
| 281 |
+
static PyObject *#apiname#(const PyObject *capi_self,
|
| 282 |
+
PyObject *capi_args,
|
| 283 |
+
PyObject *capi_keywds,
|
| 284 |
+
#functype# (*f2py_func)(#callprotoargument#)) {
|
| 285 |
+
PyObject * volatile capi_buildvalue = NULL;
|
| 286 |
+
volatile int f2py_success = 1;
|
| 287 |
+
#decl#
|
| 288 |
+
static char *capi_kwlist[] = {#kwlist##kwlistopt##kwlistxa#NULL};
|
| 289 |
+
#usercode#
|
| 290 |
+
#routdebugenter#
|
| 291 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 292 |
+
f2py_start_clock();
|
| 293 |
+
#endif
|
| 294 |
+
if (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\\
|
| 295 |
+
\"#argformat#|#keyformat##xaformat#:#pyname#\",\\
|
| 296 |
+
capi_kwlist#args_capi##keys_capi##keys_xa#))\n return NULL;
|
| 297 |
+
#frompyobj#
|
| 298 |
+
/*end of frompyobj*/
|
| 299 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 300 |
+
f2py_start_call_clock();
|
| 301 |
+
#endif
|
| 302 |
+
#callfortranroutine#
|
| 303 |
+
if (PyErr_Occurred())
|
| 304 |
+
f2py_success = 0;
|
| 305 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 306 |
+
f2py_stop_call_clock();
|
| 307 |
+
#endif
|
| 308 |
+
/*end of callfortranroutine*/
|
| 309 |
+
if (f2py_success) {
|
| 310 |
+
#pyobjfrom#
|
| 311 |
+
/*end of pyobjfrom*/
|
| 312 |
+
CFUNCSMESS(\"Building return value.\\n\");
|
| 313 |
+
capi_buildvalue = Py_BuildValue(\"#returnformat#\"#return#);
|
| 314 |
+
/*closepyobjfrom*/
|
| 315 |
+
#closepyobjfrom#
|
| 316 |
+
} /*if (f2py_success) after callfortranroutine*/
|
| 317 |
+
/*cleanupfrompyobj*/
|
| 318 |
+
#cleanupfrompyobj#
|
| 319 |
+
if (capi_buildvalue == NULL) {
|
| 320 |
+
#routdebugfailure#
|
| 321 |
+
} else {
|
| 322 |
+
#routdebugleave#
|
| 323 |
+
}
|
| 324 |
+
CFUNCSMESS(\"Freeing memory.\\n\");
|
| 325 |
+
#freemem#
|
| 326 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 327 |
+
f2py_stop_clock();
|
| 328 |
+
#endif
|
| 329 |
+
return capi_buildvalue;
|
| 330 |
+
}
|
| 331 |
+
#endtitle#
|
| 332 |
+
""",
|
| 333 |
+
'routine_defs': '#routine_def#',
|
| 334 |
+
'initf2pywraphooks': '#initf2pywraphook#',
|
| 335 |
+
'externroutines': '#declfortranroutine#',
|
| 336 |
+
'doc': '#docreturn##name#(#docsignature#)',
|
| 337 |
+
'docshort': '#docreturn##name#(#docsignatureshort#)',
|
| 338 |
+
'docs': '" #docreturn##name#(#docsignature#)\\n"\n',
|
| 339 |
+
'need': ['arrayobject.h', 'CFUNCSMESS', 'MINMAX'],
|
| 340 |
+
'cppmacros': {debugcapi: '#define DEBUGCFUNCS'},
|
| 341 |
+
'latexdoc': ['\\subsection{Wrapper function \\texttt{#texname#}}\n',
|
| 342 |
+
"""
|
| 343 |
+
\\noindent{{}\\verb@#docreturn##name#@{}}\\texttt{(#latexdocsignatureshort#)}
|
| 344 |
+
#routnote#
|
| 345 |
+
|
| 346 |
+
#latexdocstrsigns#
|
| 347 |
+
"""],
|
| 348 |
+
'restdoc': ['Wrapped function ``#name#``\n' + '-' * 80,
|
| 349 |
+
|
| 350 |
+
]
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
################## Rules for C/API function ##############
|
| 354 |
+
|
| 355 |
+
rout_rules = [
|
| 356 |
+
{ # Init
|
| 357 |
+
'separatorsfor': {'callfortranroutine': '\n', 'routdebugenter': '\n', 'decl': '\n',
|
| 358 |
+
'routdebugleave': '\n', 'routdebugfailure': '\n',
|
| 359 |
+
'setjmpbuf': ' || ',
|
| 360 |
+
'docstrreq': '\n', 'docstropt': '\n', 'docstrout': '\n',
|
| 361 |
+
'docstrcbs': '\n', 'docstrsigns': '\\n"\n"',
|
| 362 |
+
'latexdocstrsigns': '\n',
|
| 363 |
+
'latexdocstrreq': '\n', 'latexdocstropt': '\n',
|
| 364 |
+
'latexdocstrout': '\n', 'latexdocstrcbs': '\n',
|
| 365 |
+
},
|
| 366 |
+
'kwlist': '', 'kwlistopt': '', 'callfortran': '', 'callfortranappend': '',
|
| 367 |
+
'docsign': '', 'docsignopt': '', 'decl': '/*decl*/',
|
| 368 |
+
'freemem': '/*freemem*/',
|
| 369 |
+
'docsignshort': '', 'docsignoptshort': '',
|
| 370 |
+
'docstrsigns': '', 'latexdocstrsigns': '',
|
| 371 |
+
'docstrreq': '\\nParameters\\n----------',
|
| 372 |
+
'docstropt': '\\nOther Parameters\\n----------------',
|
| 373 |
+
'docstrout': '\\nReturns\\n-------',
|
| 374 |
+
'docstrcbs': '\\nNotes\\n-----\\nCall-back functions::\\n',
|
| 375 |
+
'latexdocstrreq': '\\noindent Required arguments:',
|
| 376 |
+
'latexdocstropt': '\\noindent Optional arguments:',
|
| 377 |
+
'latexdocstrout': '\\noindent Return objects:',
|
| 378 |
+
'latexdocstrcbs': '\\noindent Call-back functions:',
|
| 379 |
+
'args_capi': '', 'keys_capi': '', 'functype': '',
|
| 380 |
+
'frompyobj': '/*frompyobj*/',
|
| 381 |
+
# this list will be reversed
|
| 382 |
+
'cleanupfrompyobj': ['/*end of cleanupfrompyobj*/'],
|
| 383 |
+
'pyobjfrom': '/*pyobjfrom*/',
|
| 384 |
+
# this list will be reversed
|
| 385 |
+
'closepyobjfrom': ['/*end of closepyobjfrom*/'],
|
| 386 |
+
'topyarr': '/*topyarr*/', 'routdebugleave': '/*routdebugleave*/',
|
| 387 |
+
'routdebugenter': '/*routdebugenter*/',
|
| 388 |
+
'routdebugfailure': '/*routdebugfailure*/',
|
| 389 |
+
'callfortranroutine': '/*callfortranroutine*/',
|
| 390 |
+
'argformat': '', 'keyformat': '', 'need_cfuncs': '',
|
| 391 |
+
'docreturn': '', 'return': '', 'returnformat': '', 'rformat': '',
|
| 392 |
+
'kwlistxa': '', 'keys_xa': '', 'xaformat': '', 'docsignxa': '', 'docsignxashort': '',
|
| 393 |
+
'initf2pywraphook': '',
|
| 394 |
+
'routnote': {hasnote: '--- #note#', l_not(hasnote): ''},
|
| 395 |
+
}, {
|
| 396 |
+
'apiname': 'f2py_rout_#modulename#_#name#',
|
| 397 |
+
'pyname': '#modulename#.#name#',
|
| 398 |
+
'decl': '',
|
| 399 |
+
'_check': l_not(ismoduleroutine)
|
| 400 |
+
}, {
|
| 401 |
+
'apiname': 'f2py_rout_#modulename#_#f90modulename#_#name#',
|
| 402 |
+
'pyname': '#modulename#.#f90modulename#.#name#',
|
| 403 |
+
'decl': '',
|
| 404 |
+
'_check': ismoduleroutine
|
| 405 |
+
}, { # Subroutine
|
| 406 |
+
'functype': 'void',
|
| 407 |
+
'declfortranroutine': {l_and(l_not(l_or(ismoduleroutine, isintent_c)), l_not(isdummyroutine)): 'extern void #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',
|
| 408 |
+
l_and(l_not(ismoduleroutine), isintent_c, l_not(isdummyroutine)): 'extern void #fortranname#(#callprotoargument#);',
|
| 409 |
+
ismoduleroutine: '',
|
| 410 |
+
isdummyroutine: ''
|
| 411 |
+
},
|
| 412 |
+
'routine_def': {
|
| 413 |
+
l_not(l_or(ismoduleroutine, isintent_c, isdummyroutine)):
|
| 414 |
+
' {\"#name#\",-1,{{-1}},0,0,(char *)'
|
| 415 |
+
' #F_FUNC#(#fortranname#,#FORTRANNAME#),'
|
| 416 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 417 |
+
l_and(l_not(ismoduleroutine), isintent_c, l_not(isdummyroutine)):
|
| 418 |
+
' {\"#name#\",-1,{{-1}},0,0,(char *)#fortranname#,'
|
| 419 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 420 |
+
l_and(l_not(ismoduleroutine), isdummyroutine):
|
| 421 |
+
' {\"#name#\",-1,{{-1}},0,0,NULL,'
|
| 422 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 423 |
+
},
|
| 424 |
+
'need': {l_and(l_not(l_or(ismoduleroutine, isintent_c)), l_not(isdummyroutine)): 'F_FUNC'},
|
| 425 |
+
'callfortranroutine': [
|
| 426 |
+
{debugcapi: [
|
| 427 |
+
""" fprintf(stderr,\"debug-capi:Fortran subroutine `#fortranname#(#callfortran#)\'\\n\");"""]},
|
| 428 |
+
{hasexternals: """\
|
| 429 |
+
if (#setjmpbuf#) {
|
| 430 |
+
f2py_success = 0;
|
| 431 |
+
} else {"""},
|
| 432 |
+
{isthreadsafe: ' Py_BEGIN_ALLOW_THREADS'},
|
| 433 |
+
{hascallstatement: ''' #callstatement#;
|
| 434 |
+
/*(*f2py_func)(#callfortran#);*/'''},
|
| 435 |
+
{l_not(l_or(hascallstatement, isdummyroutine))
|
| 436 |
+
: ' (*f2py_func)(#callfortran#);'},
|
| 437 |
+
{isthreadsafe: ' Py_END_ALLOW_THREADS'},
|
| 438 |
+
{hasexternals: """ }"""}
|
| 439 |
+
],
|
| 440 |
+
'_check': l_and(issubroutine, l_not(issubroutine_wrap)),
|
| 441 |
+
}, { # Wrapped function
|
| 442 |
+
'functype': 'void',
|
| 443 |
+
'declfortranroutine': {l_not(l_or(ismoduleroutine, isdummyroutine)): 'extern void #F_WRAPPEDFUNC#(#name_lower#,#NAME#)(#callprotoargument#);',
|
| 444 |
+
isdummyroutine: '',
|
| 445 |
+
},
|
| 446 |
+
|
| 447 |
+
'routine_def': {
|
| 448 |
+
l_not(l_or(ismoduleroutine, isdummyroutine)):
|
| 449 |
+
' {\"#name#\",-1,{{-1}},0,0,(char *)'
|
| 450 |
+
' #F_WRAPPEDFUNC#(#name_lower#,#NAME#),'
|
| 451 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 452 |
+
isdummyroutine:
|
| 453 |
+
' {\"#name#\",-1,{{-1}},0,0,NULL,'
|
| 454 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 455 |
+
},
|
| 456 |
+
'initf2pywraphook': {l_not(l_or(ismoduleroutine, isdummyroutine)): '''
|
| 457 |
+
{
|
| 458 |
+
extern #ctype# #F_FUNC#(#name_lower#,#NAME#)(void);
|
| 459 |
+
PyObject* o = PyDict_GetItemString(d,"#name#");
|
| 460 |
+
tmp = F2PyCapsule_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL);
|
| 461 |
+
PyObject_SetAttrString(o,"_cpointer", tmp);
|
| 462 |
+
Py_DECREF(tmp);
|
| 463 |
+
s = PyUnicode_FromString("#name#");
|
| 464 |
+
PyObject_SetAttrString(o,"__name__", s);
|
| 465 |
+
Py_DECREF(s);
|
| 466 |
+
}
|
| 467 |
+
'''},
|
| 468 |
+
'need': {l_not(l_or(ismoduleroutine, isdummyroutine)): ['F_WRAPPEDFUNC', 'F_FUNC']},
|
| 469 |
+
'callfortranroutine': [
|
| 470 |
+
{debugcapi: [
|
| 471 |
+
""" fprintf(stderr,\"debug-capi:Fortran subroutine `f2pywrap#name_lower#(#callfortran#)\'\\n\");"""]},
|
| 472 |
+
{hasexternals: """\
|
| 473 |
+
if (#setjmpbuf#) {
|
| 474 |
+
f2py_success = 0;
|
| 475 |
+
} else {"""},
|
| 476 |
+
{isthreadsafe: ' Py_BEGIN_ALLOW_THREADS'},
|
| 477 |
+
{l_not(l_or(hascallstatement, isdummyroutine))
|
| 478 |
+
: ' (*f2py_func)(#callfortran#);'},
|
| 479 |
+
{hascallstatement:
|
| 480 |
+
' #callstatement#;\n /*(*f2py_func)(#callfortran#);*/'},
|
| 481 |
+
{isthreadsafe: ' Py_END_ALLOW_THREADS'},
|
| 482 |
+
{hasexternals: ' }'}
|
| 483 |
+
],
|
| 484 |
+
'_check': isfunction_wrap,
|
| 485 |
+
}, { # Wrapped subroutine
|
| 486 |
+
'functype': 'void',
|
| 487 |
+
'declfortranroutine': {l_not(l_or(ismoduleroutine, isdummyroutine)): 'extern void #F_WRAPPEDFUNC#(#name_lower#,#NAME#)(#callprotoargument#);',
|
| 488 |
+
isdummyroutine: '',
|
| 489 |
+
},
|
| 490 |
+
|
| 491 |
+
'routine_def': {
|
| 492 |
+
l_not(l_or(ismoduleroutine, isdummyroutine)):
|
| 493 |
+
' {\"#name#\",-1,{{-1}},0,0,(char *)'
|
| 494 |
+
' #F_WRAPPEDFUNC#(#name_lower#,#NAME#),'
|
| 495 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 496 |
+
isdummyroutine:
|
| 497 |
+
' {\"#name#\",-1,{{-1}},0,0,NULL,'
|
| 498 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},',
|
| 499 |
+
},
|
| 500 |
+
'initf2pywraphook': {l_not(l_or(ismoduleroutine, isdummyroutine)): '''
|
| 501 |
+
{
|
| 502 |
+
extern void #F_FUNC#(#name_lower#,#NAME#)(void);
|
| 503 |
+
PyObject* o = PyDict_GetItemString(d,"#name#");
|
| 504 |
+
tmp = F2PyCapsule_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL);
|
| 505 |
+
PyObject_SetAttrString(o,"_cpointer", tmp);
|
| 506 |
+
Py_DECREF(tmp);
|
| 507 |
+
s = PyUnicode_FromString("#name#");
|
| 508 |
+
PyObject_SetAttrString(o,"__name__", s);
|
| 509 |
+
Py_DECREF(s);
|
| 510 |
+
}
|
| 511 |
+
'''},
|
| 512 |
+
'need': {l_not(l_or(ismoduleroutine, isdummyroutine)): ['F_WRAPPEDFUNC', 'F_FUNC']},
|
| 513 |
+
'callfortranroutine': [
|
| 514 |
+
{debugcapi: [
|
| 515 |
+
""" fprintf(stderr,\"debug-capi:Fortran subroutine `f2pywrap#name_lower#(#callfortran#)\'\\n\");"""]},
|
| 516 |
+
{hasexternals: """\
|
| 517 |
+
if (#setjmpbuf#) {
|
| 518 |
+
f2py_success = 0;
|
| 519 |
+
} else {"""},
|
| 520 |
+
{isthreadsafe: ' Py_BEGIN_ALLOW_THREADS'},
|
| 521 |
+
{l_not(l_or(hascallstatement, isdummyroutine))
|
| 522 |
+
: ' (*f2py_func)(#callfortran#);'},
|
| 523 |
+
{hascallstatement:
|
| 524 |
+
' #callstatement#;\n /*(*f2py_func)(#callfortran#);*/'},
|
| 525 |
+
{isthreadsafe: ' Py_END_ALLOW_THREADS'},
|
| 526 |
+
{hasexternals: ' }'}
|
| 527 |
+
],
|
| 528 |
+
'_check': issubroutine_wrap,
|
| 529 |
+
}, { # Function
|
| 530 |
+
'functype': '#ctype#',
|
| 531 |
+
'docreturn': {l_not(isintent_hide): '#rname#,'},
|
| 532 |
+
'docstrout': '#pydocsignout#',
|
| 533 |
+
'latexdocstrout': ['\\item[]{{}\\verb@#pydocsignout#@{}}',
|
| 534 |
+
{hasresultnote: '--- #resultnote#'}],
|
| 535 |
+
'callfortranroutine': [{l_and(debugcapi, isstringfunction): """\
|
| 536 |
+
#ifdef USESCOMPAQFORTRAN
|
| 537 |
+
fprintf(stderr,\"debug-capi:Fortran function #ctype# #fortranname#(#callcompaqfortran#)\\n\");
|
| 538 |
+
#else
|
| 539 |
+
fprintf(stderr,\"debug-capi:Fortran function #ctype# #fortranname#(#callfortran#)\\n\");
|
| 540 |
+
#endif
|
| 541 |
+
"""},
|
| 542 |
+
{l_and(debugcapi, l_not(isstringfunction)): """\
|
| 543 |
+
fprintf(stderr,\"debug-capi:Fortran function #ctype# #fortranname#(#callfortran#)\\n\");
|
| 544 |
+
"""}
|
| 545 |
+
],
|
| 546 |
+
'_check': l_and(isfunction, l_not(isfunction_wrap))
|
| 547 |
+
}, { # Scalar function
|
| 548 |
+
'declfortranroutine': {l_and(l_not(l_or(ismoduleroutine, isintent_c)), l_not(isdummyroutine)): 'extern #ctype# #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',
|
| 549 |
+
l_and(l_not(ismoduleroutine), isintent_c, l_not(isdummyroutine)): 'extern #ctype# #fortranname#(#callprotoargument#);',
|
| 550 |
+
isdummyroutine: ''
|
| 551 |
+
},
|
| 552 |
+
'routine_def': {
|
| 553 |
+
l_and(l_not(l_or(ismoduleroutine, isintent_c)),
|
| 554 |
+
l_not(isdummyroutine)):
|
| 555 |
+
(' {\"#name#\",-1,{{-1}},0,0,(char *)'
|
| 556 |
+
' #F_FUNC#(#fortranname#,#FORTRANNAME#),'
|
| 557 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},'),
|
| 558 |
+
l_and(l_not(ismoduleroutine), isintent_c, l_not(isdummyroutine)):
|
| 559 |
+
(' {\"#name#\",-1,{{-1}},0,0,(char *)#fortranname#,'
|
| 560 |
+
' (f2py_init_func)#apiname#,doc_#apiname#},'),
|
| 561 |
+
isdummyroutine:
|
| 562 |
+
' {\"#name#\",-1,{{-1}},0,0,NULL,'
|
| 563 |
+
'(f2py_init_func)#apiname#,doc_#apiname#},',
|
| 564 |
+
},
|
| 565 |
+
'decl': [{iscomplexfunction_warn: ' #ctype# #name#_return_value={0,0};',
|
| 566 |
+
l_not(iscomplexfunction): ' #ctype# #name#_return_value=0;'},
|
| 567 |
+
{iscomplexfunction:
|
| 568 |
+
' PyObject *#name#_return_value_capi = Py_None;'}
|
| 569 |
+
],
|
| 570 |
+
'callfortranroutine': [
|
| 571 |
+
{hasexternals: """\
|
| 572 |
+
if (#setjmpbuf#) {
|
| 573 |
+
f2py_success = 0;
|
| 574 |
+
} else {"""},
|
| 575 |
+
{isthreadsafe: ' Py_BEGIN_ALLOW_THREADS'},
|
| 576 |
+
{hascallstatement: ''' #callstatement#;
|
| 577 |
+
/* #name#_return_value = (*f2py_func)(#callfortran#);*/
|
| 578 |
+
'''},
|
| 579 |
+
{l_not(l_or(hascallstatement, isdummyroutine))
|
| 580 |
+
: ' #name#_return_value = (*f2py_func)(#callfortran#);'},
|
| 581 |
+
{isthreadsafe: ' Py_END_ALLOW_THREADS'},
|
| 582 |
+
{hasexternals: ' }'},
|
| 583 |
+
{l_and(debugcapi, iscomplexfunction)
|
| 584 |
+
: ' fprintf(stderr,"#routdebugshowvalue#\\n",#name#_return_value.r,#name#_return_value.i);'},
|
| 585 |
+
{l_and(debugcapi, l_not(iscomplexfunction)): ' fprintf(stderr,"#routdebugshowvalue#\\n",#name#_return_value);'}],
|
| 586 |
+
'pyobjfrom': {iscomplexfunction: ' #name#_return_value_capi = pyobj_from_#ctype#1(#name#_return_value);'},
|
| 587 |
+
'need': [{l_not(isdummyroutine): 'F_FUNC'},
|
| 588 |
+
{iscomplexfunction: 'pyobj_from_#ctype#1'},
|
| 589 |
+
{islong_longfunction: 'long_long'},
|
| 590 |
+
{islong_doublefunction: 'long_double'}],
|
| 591 |
+
'returnformat': {l_not(isintent_hide): '#rformat#'},
|
| 592 |
+
'return': {iscomplexfunction: ',#name#_return_value_capi',
|
| 593 |
+
l_not(l_or(iscomplexfunction, isintent_hide)): ',#name#_return_value'},
|
| 594 |
+
'_check': l_and(isfunction, l_not(isstringfunction), l_not(isfunction_wrap))
|
| 595 |
+
}, { # String function # in use for --no-wrap
|
| 596 |
+
'declfortranroutine': 'extern void #F_FUNC#(#fortranname#,#FORTRANNAME#)(#callprotoargument#);',
|
| 597 |
+
'routine_def': {l_not(l_or(ismoduleroutine, isintent_c)):
|
| 598 |
+
' {\"#name#\",-1,{{-1}},0,0,(char *)#F_FUNC#(#fortranname#,#FORTRANNAME#),(f2py_init_func)#apiname#,doc_#apiname#},',
|
| 599 |
+
l_and(l_not(ismoduleroutine), isintent_c):
|
| 600 |
+
' {\"#name#\",-1,{{-1}},0,0,(char *)#fortranname#,(f2py_init_func)#apiname#,doc_#apiname#},'
|
| 601 |
+
},
|
| 602 |
+
'decl': [' #ctype# #name#_return_value = NULL;',
|
| 603 |
+
' int #name#_return_value_len = 0;'],
|
| 604 |
+
'callfortran':'#name#_return_value,#name#_return_value_len,',
|
| 605 |
+
'callfortranroutine':[' #name#_return_value_len = #rlength#;',
|
| 606 |
+
' if ((#name#_return_value = (string)malloc('
|
| 607 |
+
+ '#name#_return_value_len+1) == NULL) {',
|
| 608 |
+
' PyErr_SetString(PyExc_MemoryError, \"out of memory\");',
|
| 609 |
+
' f2py_success = 0;',
|
| 610 |
+
' } else {',
|
| 611 |
+
" (#name#_return_value)[#name#_return_value_len] = '\\0';",
|
| 612 |
+
' }',
|
| 613 |
+
' if (f2py_success) {',
|
| 614 |
+
{hasexternals: """\
|
| 615 |
+
if (#setjmpbuf#) {
|
| 616 |
+
f2py_success = 0;
|
| 617 |
+
} else {"""},
|
| 618 |
+
{isthreadsafe: ' Py_BEGIN_ALLOW_THREADS'},
|
| 619 |
+
"""\
|
| 620 |
+
#ifdef USESCOMPAQFORTRAN
|
| 621 |
+
(*f2py_func)(#callcompaqfortran#);
|
| 622 |
+
#else
|
| 623 |
+
(*f2py_func)(#callfortran#);
|
| 624 |
+
#endif
|
| 625 |
+
""",
|
| 626 |
+
{isthreadsafe: ' Py_END_ALLOW_THREADS'},
|
| 627 |
+
{hasexternals: ' }'},
|
| 628 |
+
{debugcapi:
|
| 629 |
+
' fprintf(stderr,"#routdebugshowvalue#\\n",#name#_return_value_len,#name#_return_value);'},
|
| 630 |
+
' } /* if (f2py_success) after (string)malloc */',
|
| 631 |
+
],
|
| 632 |
+
'returnformat': '#rformat#',
|
| 633 |
+
'return': ',#name#_return_value',
|
| 634 |
+
'freemem': ' STRINGFREE(#name#_return_value);',
|
| 635 |
+
'need': ['F_FUNC', '#ctype#', 'STRINGFREE'],
|
| 636 |
+
'_check':l_and(isstringfunction, l_not(isfunction_wrap)) # ???obsolete
|
| 637 |
+
},
|
| 638 |
+
{ # Debugging
|
| 639 |
+
'routdebugenter': ' fprintf(stderr,"debug-capi:Python C/API function #modulename#.#name#(#docsignature#)\\n");',
|
| 640 |
+
'routdebugleave': ' fprintf(stderr,"debug-capi:Python C/API function #modulename#.#name#: successful.\\n");',
|
| 641 |
+
'routdebugfailure': ' fprintf(stderr,"debug-capi:Python C/API function #modulename#.#name#: failure.\\n");',
|
| 642 |
+
'_check': debugcapi
|
| 643 |
+
}
|
| 644 |
+
]
|
| 645 |
+
|
| 646 |
+
################ Rules for arguments ##################
|
| 647 |
+
|
| 648 |
+
typedef_need_dict = {islong_long: 'long_long',
|
| 649 |
+
islong_double: 'long_double',
|
| 650 |
+
islong_complex: 'complex_long_double',
|
| 651 |
+
isunsigned_char: 'unsigned_char',
|
| 652 |
+
isunsigned_short: 'unsigned_short',
|
| 653 |
+
isunsigned: 'unsigned',
|
| 654 |
+
isunsigned_long_long: 'unsigned_long_long',
|
| 655 |
+
isunsigned_chararray: 'unsigned_char',
|
| 656 |
+
isunsigned_shortarray: 'unsigned_short',
|
| 657 |
+
isunsigned_long_longarray: 'unsigned_long_long',
|
| 658 |
+
issigned_long_longarray: 'long_long',
|
| 659 |
+
isint1: 'signed_char',
|
| 660 |
+
ischaracter_or_characterarray: 'character',
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
aux_rules = [
|
| 664 |
+
{
|
| 665 |
+
'separatorsfor': sepdict
|
| 666 |
+
},
|
| 667 |
+
{ # Common
|
| 668 |
+
'frompyobj': [' /* Processing auxiliary variable #varname# */',
|
| 669 |
+
{debugcapi: ' fprintf(stderr,"#vardebuginfo#\\n");'}, ],
|
| 670 |
+
'cleanupfrompyobj': ' /* End of cleaning variable #varname# */',
|
| 671 |
+
'need': typedef_need_dict,
|
| 672 |
+
},
|
| 673 |
+
# Scalars (not complex)
|
| 674 |
+
{ # Common
|
| 675 |
+
'decl': ' #ctype# #varname# = 0;',
|
| 676 |
+
'need': {hasinitvalue: 'math.h'},
|
| 677 |
+
'frompyobj': {hasinitvalue: ' #varname# = #init#;'},
|
| 678 |
+
'_check': l_and(isscalar, l_not(iscomplex)),
|
| 679 |
+
},
|
| 680 |
+
{
|
| 681 |
+
'return': ',#varname#',
|
| 682 |
+
'docstrout': '#pydocsignout#',
|
| 683 |
+
'docreturn': '#outvarname#,',
|
| 684 |
+
'returnformat': '#varrformat#',
|
| 685 |
+
'_check': l_and(isscalar, l_not(iscomplex), isintent_out),
|
| 686 |
+
},
|
| 687 |
+
# Complex scalars
|
| 688 |
+
{ # Common
|
| 689 |
+
'decl': ' #ctype# #varname#;',
|
| 690 |
+
'frompyobj': {hasinitvalue: ' #varname#.r = #init.r#, #varname#.i = #init.i#;'},
|
| 691 |
+
'_check': iscomplex
|
| 692 |
+
},
|
| 693 |
+
# String
|
| 694 |
+
{ # Common
|
| 695 |
+
'decl': [' #ctype# #varname# = NULL;',
|
| 696 |
+
' int slen(#varname#);',
|
| 697 |
+
],
|
| 698 |
+
'need':['len..'],
|
| 699 |
+
'_check':isstring
|
| 700 |
+
},
|
| 701 |
+
# Array
|
| 702 |
+
{ # Common
|
| 703 |
+
'decl': [' #ctype# *#varname# = NULL;',
|
| 704 |
+
' npy_intp #varname#_Dims[#rank#] = {#rank*[-1]#};',
|
| 705 |
+
' const int #varname#_Rank = #rank#;',
|
| 706 |
+
],
|
| 707 |
+
'need':['len..', {hasinitvalue: 'forcomb'}, {hasinitvalue: 'CFUNCSMESS'}],
|
| 708 |
+
'_check': isarray
|
| 709 |
+
},
|
| 710 |
+
# Scalararray
|
| 711 |
+
{ # Common
|
| 712 |
+
'_check': l_and(isarray, l_not(iscomplexarray))
|
| 713 |
+
}, { # Not hidden
|
| 714 |
+
'_check': l_and(isarray, l_not(iscomplexarray), isintent_nothide)
|
| 715 |
+
},
|
| 716 |
+
# Integer*1 array
|
| 717 |
+
{'need': '#ctype#',
|
| 718 |
+
'_check': isint1array,
|
| 719 |
+
'_depend': ''
|
| 720 |
+
},
|
| 721 |
+
# Integer*-1 array
|
| 722 |
+
{'need': '#ctype#',
|
| 723 |
+
'_check': l_or(isunsigned_chararray, isunsigned_char),
|
| 724 |
+
'_depend': ''
|
| 725 |
+
},
|
| 726 |
+
# Integer*-2 array
|
| 727 |
+
{'need': '#ctype#',
|
| 728 |
+
'_check': isunsigned_shortarray,
|
| 729 |
+
'_depend': ''
|
| 730 |
+
},
|
| 731 |
+
# Integer*-8 array
|
| 732 |
+
{'need': '#ctype#',
|
| 733 |
+
'_check': isunsigned_long_longarray,
|
| 734 |
+
'_depend': ''
|
| 735 |
+
},
|
| 736 |
+
# Complexarray
|
| 737 |
+
{'need': '#ctype#',
|
| 738 |
+
'_check': iscomplexarray,
|
| 739 |
+
'_depend': ''
|
| 740 |
+
},
|
| 741 |
+
# Stringarray
|
| 742 |
+
{
|
| 743 |
+
'callfortranappend': {isarrayofstrings: 'flen(#varname#),'},
|
| 744 |
+
'need': 'string',
|
| 745 |
+
'_check': isstringarray
|
| 746 |
+
}
|
| 747 |
+
]
|
| 748 |
+
|
| 749 |
+
arg_rules = [
|
| 750 |
+
{
|
| 751 |
+
'separatorsfor': sepdict
|
| 752 |
+
},
|
| 753 |
+
{ # Common
|
| 754 |
+
'frompyobj': [' /* Processing variable #varname# */',
|
| 755 |
+
{debugcapi: ' fprintf(stderr,"#vardebuginfo#\\n");'}, ],
|
| 756 |
+
'cleanupfrompyobj': ' /* End of cleaning variable #varname# */',
|
| 757 |
+
'_depend': '',
|
| 758 |
+
'need': typedef_need_dict,
|
| 759 |
+
},
|
| 760 |
+
# Doc signatures
|
| 761 |
+
{
|
| 762 |
+
'docstropt': {l_and(isoptional, isintent_nothide): '#pydocsign#'},
|
| 763 |
+
'docstrreq': {l_and(isrequired, isintent_nothide): '#pydocsign#'},
|
| 764 |
+
'docstrout': {isintent_out: '#pydocsignout#'},
|
| 765 |
+
'latexdocstropt': {l_and(isoptional, isintent_nothide): ['\\item[]{{}\\verb@#pydocsign#@{}}',
|
| 766 |
+
{hasnote: '--- #note#'}]},
|
| 767 |
+
'latexdocstrreq': {l_and(isrequired, isintent_nothide): ['\\item[]{{}\\verb@#pydocsign#@{}}',
|
| 768 |
+
{hasnote: '--- #note#'}]},
|
| 769 |
+
'latexdocstrout': {isintent_out: ['\\item[]{{}\\verb@#pydocsignout#@{}}',
|
| 770 |
+
{l_and(hasnote, isintent_hide): '--- #note#',
|
| 771 |
+
l_and(hasnote, isintent_nothide): '--- See above.'}]},
|
| 772 |
+
'depend': ''
|
| 773 |
+
},
|
| 774 |
+
# Required/Optional arguments
|
| 775 |
+
{
|
| 776 |
+
'kwlist': '"#varname#",',
|
| 777 |
+
'docsign': '#varname#,',
|
| 778 |
+
'_check': l_and(isintent_nothide, l_not(isoptional))
|
| 779 |
+
},
|
| 780 |
+
{
|
| 781 |
+
'kwlistopt': '"#varname#",',
|
| 782 |
+
'docsignopt': '#varname#=#showinit#,',
|
| 783 |
+
'docsignoptshort': '#varname#,',
|
| 784 |
+
'_check': l_and(isintent_nothide, isoptional)
|
| 785 |
+
},
|
| 786 |
+
# Docstring/BuildValue
|
| 787 |
+
{
|
| 788 |
+
'docreturn': '#outvarname#,',
|
| 789 |
+
'returnformat': '#varrformat#',
|
| 790 |
+
'_check': isintent_out
|
| 791 |
+
},
|
| 792 |
+
# Externals (call-back functions)
|
| 793 |
+
{ # Common
|
| 794 |
+
'docsignxa': {isintent_nothide: '#varname#_extra_args=(),'},
|
| 795 |
+
'docsignxashort': {isintent_nothide: '#varname#_extra_args,'},
|
| 796 |
+
'docstropt': {isintent_nothide: '#varname#_extra_args : input tuple, optional\\n Default: ()'},
|
| 797 |
+
'docstrcbs': '#cbdocstr#',
|
| 798 |
+
'latexdocstrcbs': '\\item[] #cblatexdocstr#',
|
| 799 |
+
'latexdocstropt': {isintent_nothide: '\\item[]{{}\\verb@#varname#_extra_args := () input tuple@{}} --- Extra arguments for call-back function {{}\\verb@#varname#@{}}.'},
|
| 800 |
+
'decl': [' #cbname#_t #varname#_cb = { Py_None, NULL, 0 };',
|
| 801 |
+
' #cbname#_t *#varname#_cb_ptr = &#varname#_cb;',
|
| 802 |
+
' PyTupleObject *#varname#_xa_capi = NULL;',
|
| 803 |
+
{l_not(isintent_callback):
|
| 804 |
+
' #cbname#_typedef #varname#_cptr;'}
|
| 805 |
+
],
|
| 806 |
+
'kwlistxa': {isintent_nothide: '"#varname#_extra_args",'},
|
| 807 |
+
'argformat': {isrequired: 'O'},
|
| 808 |
+
'keyformat': {isoptional: 'O'},
|
| 809 |
+
'xaformat': {isintent_nothide: 'O!'},
|
| 810 |
+
'args_capi': {isrequired: ',&#varname#_cb.capi'},
|
| 811 |
+
'keys_capi': {isoptional: ',&#varname#_cb.capi'},
|
| 812 |
+
'keys_xa': ',&PyTuple_Type,&#varname#_xa_capi',
|
| 813 |
+
'setjmpbuf': '(setjmp(#varname#_cb.jmpbuf))',
|
| 814 |
+
'callfortran': {l_not(isintent_callback): '#varname#_cptr,'},
|
| 815 |
+
'need': ['#cbname#', 'setjmp.h'],
|
| 816 |
+
'_check':isexternal
|
| 817 |
+
},
|
| 818 |
+
{
|
| 819 |
+
'frompyobj': [{l_not(isintent_callback): """\
|
| 820 |
+
if(F2PyCapsule_Check(#varname#_cb.capi)) {
|
| 821 |
+
#varname#_cptr = F2PyCapsule_AsVoidPtr(#varname#_cb.capi);
|
| 822 |
+
} else {
|
| 823 |
+
#varname#_cptr = #cbname#;
|
| 824 |
+
}
|
| 825 |
+
"""}, {isintent_callback: """\
|
| 826 |
+
if (#varname#_cb.capi==Py_None) {
|
| 827 |
+
#varname#_cb.capi = PyObject_GetAttrString(#modulename#_module,\"#varname#\");
|
| 828 |
+
if (#varname#_cb.capi) {
|
| 829 |
+
if (#varname#_xa_capi==NULL) {
|
| 830 |
+
if (PyObject_HasAttrString(#modulename#_module,\"#varname#_extra_args\")) {
|
| 831 |
+
PyObject* capi_tmp = PyObject_GetAttrString(#modulename#_module,\"#varname#_extra_args\");
|
| 832 |
+
if (capi_tmp) {
|
| 833 |
+
#varname#_xa_capi = (PyTupleObject *)PySequence_Tuple(capi_tmp);
|
| 834 |
+
Py_DECREF(capi_tmp);
|
| 835 |
+
}
|
| 836 |
+
else {
|
| 837 |
+
#varname#_xa_capi = (PyTupleObject *)Py_BuildValue(\"()\");
|
| 838 |
+
}
|
| 839 |
+
if (#varname#_xa_capi==NULL) {
|
| 840 |
+
PyErr_SetString(#modulename#_error,\"Failed to convert #modulename#.#varname#_extra_args to tuple.\\n\");
|
| 841 |
+
return NULL;
|
| 842 |
+
}
|
| 843 |
+
}
|
| 844 |
+
}
|
| 845 |
+
}
|
| 846 |
+
if (#varname#_cb.capi==NULL) {
|
| 847 |
+
PyErr_SetString(#modulename#_error,\"Callback #varname# not defined (as an argument or module #modulename# attribute).\\n\");
|
| 848 |
+
return NULL;
|
| 849 |
+
}
|
| 850 |
+
}
|
| 851 |
+
"""},
|
| 852 |
+
"""\
|
| 853 |
+
if (create_cb_arglist(#varname#_cb.capi,#varname#_xa_capi,#maxnofargs#,#nofoptargs#,&#varname#_cb.nofargs,&#varname#_cb.args_capi,\"failed in processing argument list for call-back #varname#.\")) {
|
| 854 |
+
""",
|
| 855 |
+
{debugcapi: ["""\
|
| 856 |
+
fprintf(stderr,\"debug-capi:Assuming %d arguments; at most #maxnofargs#(-#nofoptargs#) is expected.\\n\",#varname#_cb.nofargs);
|
| 857 |
+
CFUNCSMESSPY(\"for #varname#=\",#varname#_cb.capi);""",
|
| 858 |
+
{l_not(isintent_callback): """ fprintf(stderr,\"#vardebugshowvalue# (call-back in C).\\n\",#cbname#);"""}]},
|
| 859 |
+
"""\
|
| 860 |
+
CFUNCSMESS(\"Saving callback variables for `#varname#`.\\n\");
|
| 861 |
+
#varname#_cb_ptr = swap_active_#cbname#(#varname#_cb_ptr);""",
|
| 862 |
+
],
|
| 863 |
+
'cleanupfrompyobj':
|
| 864 |
+
"""\
|
| 865 |
+
CFUNCSMESS(\"Restoring callback variables for `#varname#`.\\n\");
|
| 866 |
+
#varname#_cb_ptr = swap_active_#cbname#(#varname#_cb_ptr);
|
| 867 |
+
Py_DECREF(#varname#_cb.args_capi);
|
| 868 |
+
}""",
|
| 869 |
+
'need': ['SWAP', 'create_cb_arglist'],
|
| 870 |
+
'_check':isexternal,
|
| 871 |
+
'_depend':''
|
| 872 |
+
},
|
| 873 |
+
# Scalars (not complex)
|
| 874 |
+
{ # Common
|
| 875 |
+
'decl': ' #ctype# #varname# = 0;',
|
| 876 |
+
'pyobjfrom': {debugcapi: ' fprintf(stderr,"#vardebugshowvalue#\\n",#varname#);'},
|
| 877 |
+
'callfortran': {l_or(isintent_c, isattr_value): '#varname#,', l_not(l_or(isintent_c, isattr_value)): '&#varname#,'},
|
| 878 |
+
'return': {isintent_out: ',#varname#'},
|
| 879 |
+
'_check': l_and(isscalar, l_not(iscomplex))
|
| 880 |
+
}, {
|
| 881 |
+
'need': {hasinitvalue: 'math.h'},
|
| 882 |
+
'_check': l_and(isscalar, l_not(iscomplex)),
|
| 883 |
+
}, { # Not hidden
|
| 884 |
+
'decl': ' PyObject *#varname#_capi = Py_None;',
|
| 885 |
+
'argformat': {isrequired: 'O'},
|
| 886 |
+
'keyformat': {isoptional: 'O'},
|
| 887 |
+
'args_capi': {isrequired: ',&#varname#_capi'},
|
| 888 |
+
'keys_capi': {isoptional: ',&#varname#_capi'},
|
| 889 |
+
'pyobjfrom': {isintent_inout: """\
|
| 890 |
+
f2py_success = try_pyarr_from_#ctype#(#varname#_capi,&#varname#);
|
| 891 |
+
if (f2py_success) {"""},
|
| 892 |
+
'closepyobjfrom': {isintent_inout: " } /*if (f2py_success) of #varname# pyobjfrom*/"},
|
| 893 |
+
'need': {isintent_inout: 'try_pyarr_from_#ctype#'},
|
| 894 |
+
'_check': l_and(isscalar, l_not(iscomplex), l_not(isstring),
|
| 895 |
+
isintent_nothide)
|
| 896 |
+
}, {
|
| 897 |
+
'frompyobj': [
|
| 898 |
+
# hasinitvalue...
|
| 899 |
+
# if pyobj is None:
|
| 900 |
+
# varname = init
|
| 901 |
+
# else
|
| 902 |
+
# from_pyobj(varname)
|
| 903 |
+
#
|
| 904 |
+
# isoptional and noinitvalue...
|
| 905 |
+
# if pyobj is not None:
|
| 906 |
+
# from_pyobj(varname)
|
| 907 |
+
# else:
|
| 908 |
+
# varname is uninitialized
|
| 909 |
+
#
|
| 910 |
+
# ...
|
| 911 |
+
# from_pyobj(varname)
|
| 912 |
+
#
|
| 913 |
+
{hasinitvalue: ' if (#varname#_capi == Py_None) #varname# = #init#; else',
|
| 914 |
+
'_depend': ''},
|
| 915 |
+
{l_and(isoptional, l_not(hasinitvalue)): ' if (#varname#_capi != Py_None)',
|
| 916 |
+
'_depend': ''},
|
| 917 |
+
{l_not(islogical): '''\
|
| 918 |
+
f2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,"#pyname#() #nth# (#varname#) can\'t be converted to #ctype#");
|
| 919 |
+
if (f2py_success) {'''},
|
| 920 |
+
{islogical: '''\
|
| 921 |
+
#varname# = (#ctype#)PyObject_IsTrue(#varname#_capi);
|
| 922 |
+
f2py_success = 1;
|
| 923 |
+
if (f2py_success) {'''},
|
| 924 |
+
],
|
| 925 |
+
'cleanupfrompyobj': ' } /*if (f2py_success) of #varname#*/',
|
| 926 |
+
'need': {l_not(islogical): '#ctype#_from_pyobj'},
|
| 927 |
+
'_check': l_and(isscalar, l_not(iscomplex), isintent_nothide),
|
| 928 |
+
'_depend': ''
|
| 929 |
+
}, { # Hidden
|
| 930 |
+
'frompyobj': {hasinitvalue: ' #varname# = #init#;'},
|
| 931 |
+
'need': typedef_need_dict,
|
| 932 |
+
'_check': l_and(isscalar, l_not(iscomplex), isintent_hide),
|
| 933 |
+
'_depend': ''
|
| 934 |
+
}, { # Common
|
| 935 |
+
'frompyobj': {debugcapi: ' fprintf(stderr,"#vardebugshowvalue#\\n",#varname#);'},
|
| 936 |
+
'_check': l_and(isscalar, l_not(iscomplex)),
|
| 937 |
+
'_depend': ''
|
| 938 |
+
},
|
| 939 |
+
# Complex scalars
|
| 940 |
+
{ # Common
|
| 941 |
+
'decl': ' #ctype# #varname#;',
|
| 942 |
+
'callfortran': {isintent_c: '#varname#,', l_not(isintent_c): '&#varname#,'},
|
| 943 |
+
'pyobjfrom': {debugcapi: ' fprintf(stderr,"#vardebugshowvalue#\\n",#varname#.r,#varname#.i);'},
|
| 944 |
+
'return': {isintent_out: ',#varname#_capi'},
|
| 945 |
+
'_check': iscomplex
|
| 946 |
+
}, { # Not hidden
|
| 947 |
+
'decl': ' PyObject *#varname#_capi = Py_None;',
|
| 948 |
+
'argformat': {isrequired: 'O'},
|
| 949 |
+
'keyformat': {isoptional: 'O'},
|
| 950 |
+
'args_capi': {isrequired: ',&#varname#_capi'},
|
| 951 |
+
'keys_capi': {isoptional: ',&#varname#_capi'},
|
| 952 |
+
'need': {isintent_inout: 'try_pyarr_from_#ctype#'},
|
| 953 |
+
'pyobjfrom': {isintent_inout: """\
|
| 954 |
+
f2py_success = try_pyarr_from_#ctype#(#varname#_capi,&#varname#);
|
| 955 |
+
if (f2py_success) {"""},
|
| 956 |
+
'closepyobjfrom': {isintent_inout: " } /*if (f2py_success) of #varname# pyobjfrom*/"},
|
| 957 |
+
'_check': l_and(iscomplex, isintent_nothide)
|
| 958 |
+
}, {
|
| 959 |
+
'frompyobj': [{hasinitvalue: ' if (#varname#_capi==Py_None) {#varname#.r = #init.r#, #varname#.i = #init.i#;} else'},
|
| 960 |
+
{l_and(isoptional, l_not(hasinitvalue))
|
| 961 |
+
: ' if (#varname#_capi != Py_None)'},
|
| 962 |
+
' f2py_success = #ctype#_from_pyobj(&#varname#,#varname#_capi,"#pyname#() #nth# (#varname#) can\'t be converted to #ctype#");'
|
| 963 |
+
'\n if (f2py_success) {'],
|
| 964 |
+
'cleanupfrompyobj': ' } /*if (f2py_success) of #varname# frompyobj*/',
|
| 965 |
+
'need': ['#ctype#_from_pyobj'],
|
| 966 |
+
'_check': l_and(iscomplex, isintent_nothide),
|
| 967 |
+
'_depend': ''
|
| 968 |
+
}, { # Hidden
|
| 969 |
+
'decl': {isintent_out: ' PyObject *#varname#_capi = Py_None;'},
|
| 970 |
+
'_check': l_and(iscomplex, isintent_hide)
|
| 971 |
+
}, {
|
| 972 |
+
'frompyobj': {hasinitvalue: ' #varname#.r = #init.r#, #varname#.i = #init.i#;'},
|
| 973 |
+
'_check': l_and(iscomplex, isintent_hide),
|
| 974 |
+
'_depend': ''
|
| 975 |
+
}, { # Common
|
| 976 |
+
'pyobjfrom': {isintent_out: ' #varname#_capi = pyobj_from_#ctype#1(#varname#);'},
|
| 977 |
+
'need': ['pyobj_from_#ctype#1'],
|
| 978 |
+
'_check': iscomplex
|
| 979 |
+
}, {
|
| 980 |
+
'frompyobj': {debugcapi: ' fprintf(stderr,"#vardebugshowvalue#\\n",#varname#.r,#varname#.i);'},
|
| 981 |
+
'_check': iscomplex,
|
| 982 |
+
'_depend': ''
|
| 983 |
+
},
|
| 984 |
+
# String
|
| 985 |
+
{ # Common
|
| 986 |
+
'decl': [' #ctype# #varname# = NULL;',
|
| 987 |
+
' int slen(#varname#);',
|
| 988 |
+
' PyObject *#varname#_capi = Py_None;'],
|
| 989 |
+
'callfortran':'#varname#,',
|
| 990 |
+
'callfortranappend':'slen(#varname#),',
|
| 991 |
+
'pyobjfrom':[
|
| 992 |
+
{debugcapi:
|
| 993 |
+
' fprintf(stderr,'
|
| 994 |
+
'"#vardebugshowvalue#\\n",slen(#varname#),#varname#);'},
|
| 995 |
+
# The trailing null value for Fortran is blank.
|
| 996 |
+
{l_and(isintent_out, l_not(isintent_c)):
|
| 997 |
+
" STRINGPADN(#varname#, slen(#varname#), ' ', '\\0');"},
|
| 998 |
+
],
|
| 999 |
+
'return': {isintent_out: ',#varname#'},
|
| 1000 |
+
'need': ['len..',
|
| 1001 |
+
{l_and(isintent_out, l_not(isintent_c)): 'STRINGPADN'}],
|
| 1002 |
+
'_check': isstring
|
| 1003 |
+
}, { # Common
|
| 1004 |
+
'frompyobj': [
|
| 1005 |
+
"""\
|
| 1006 |
+
slen(#varname#) = #elsize#;
|
| 1007 |
+
f2py_success = #ctype#_from_pyobj(&#varname#,&slen(#varname#),#init#,"""
|
| 1008 |
+
"""#varname#_capi,\"#ctype#_from_pyobj failed in converting #nth#"""
|
| 1009 |
+
"""`#varname#\' of #pyname# to C #ctype#\");
|
| 1010 |
+
if (f2py_success) {""",
|
| 1011 |
+
# The trailing null value for Fortran is blank.
|
| 1012 |
+
{l_not(isintent_c):
|
| 1013 |
+
" STRINGPADN(#varname#, slen(#varname#), '\\0', ' ');"},
|
| 1014 |
+
],
|
| 1015 |
+
'cleanupfrompyobj': """\
|
| 1016 |
+
STRINGFREE(#varname#);
|
| 1017 |
+
} /*if (f2py_success) of #varname#*/""",
|
| 1018 |
+
'need': ['#ctype#_from_pyobj', 'len..', 'STRINGFREE',
|
| 1019 |
+
{l_not(isintent_c): 'STRINGPADN'}],
|
| 1020 |
+
'_check':isstring,
|
| 1021 |
+
'_depend':''
|
| 1022 |
+
}, { # Not hidden
|
| 1023 |
+
'argformat': {isrequired: 'O'},
|
| 1024 |
+
'keyformat': {isoptional: 'O'},
|
| 1025 |
+
'args_capi': {isrequired: ',&#varname#_capi'},
|
| 1026 |
+
'keys_capi': {isoptional: ',&#varname#_capi'},
|
| 1027 |
+
'pyobjfrom': [
|
| 1028 |
+
{l_and(isintent_inout, l_not(isintent_c)):
|
| 1029 |
+
" STRINGPADN(#varname#, slen(#varname#), ' ', '\\0');"},
|
| 1030 |
+
{isintent_inout: '''\
|
| 1031 |
+
f2py_success = try_pyarr_from_#ctype#(#varname#_capi, #varname#,
|
| 1032 |
+
slen(#varname#));
|
| 1033 |
+
if (f2py_success) {'''}],
|
| 1034 |
+
'closepyobjfrom': {isintent_inout: ' } /*if (f2py_success) of #varname# pyobjfrom*/'},
|
| 1035 |
+
'need': {isintent_inout: 'try_pyarr_from_#ctype#',
|
| 1036 |
+
l_and(isintent_inout, l_not(isintent_c)): 'STRINGPADN'},
|
| 1037 |
+
'_check': l_and(isstring, isintent_nothide)
|
| 1038 |
+
}, { # Hidden
|
| 1039 |
+
'_check': l_and(isstring, isintent_hide)
|
| 1040 |
+
}, {
|
| 1041 |
+
'frompyobj': {debugcapi: ' fprintf(stderr,"#vardebugshowvalue#\\n",slen(#varname#),#varname#);'},
|
| 1042 |
+
'_check': isstring,
|
| 1043 |
+
'_depend': ''
|
| 1044 |
+
},
|
| 1045 |
+
# Array
|
| 1046 |
+
{ # Common
|
| 1047 |
+
'decl': [' #ctype# *#varname# = NULL;',
|
| 1048 |
+
' npy_intp #varname#_Dims[#rank#] = {#rank*[-1]#};',
|
| 1049 |
+
' const int #varname#_Rank = #rank#;',
|
| 1050 |
+
' PyArrayObject *capi_#varname#_as_array = NULL;',
|
| 1051 |
+
' int capi_#varname#_intent = 0;',
|
| 1052 |
+
{isstringarray: ' int slen(#varname#) = 0;'},
|
| 1053 |
+
],
|
| 1054 |
+
'callfortran':'#varname#,',
|
| 1055 |
+
'callfortranappend': {isstringarray: 'slen(#varname#),'},
|
| 1056 |
+
'return': {isintent_out: ',capi_#varname#_as_array'},
|
| 1057 |
+
'need': 'len..',
|
| 1058 |
+
'_check': isarray
|
| 1059 |
+
}, { # intent(overwrite) array
|
| 1060 |
+
'decl': ' int capi_overwrite_#varname# = 1;',
|
| 1061 |
+
'kwlistxa': '"overwrite_#varname#",',
|
| 1062 |
+
'xaformat': 'i',
|
| 1063 |
+
'keys_xa': ',&capi_overwrite_#varname#',
|
| 1064 |
+
'docsignxa': 'overwrite_#varname#=1,',
|
| 1065 |
+
'docsignxashort': 'overwrite_#varname#,',
|
| 1066 |
+
'docstropt': 'overwrite_#varname# : input int, optional\\n Default: 1',
|
| 1067 |
+
'_check': l_and(isarray, isintent_overwrite),
|
| 1068 |
+
}, {
|
| 1069 |
+
'frompyobj': ' capi_#varname#_intent |= (capi_overwrite_#varname#?0:F2PY_INTENT_COPY);',
|
| 1070 |
+
'_check': l_and(isarray, isintent_overwrite),
|
| 1071 |
+
'_depend': '',
|
| 1072 |
+
},
|
| 1073 |
+
{ # intent(copy) array
|
| 1074 |
+
'decl': ' int capi_overwrite_#varname# = 0;',
|
| 1075 |
+
'kwlistxa': '"overwrite_#varname#",',
|
| 1076 |
+
'xaformat': 'i',
|
| 1077 |
+
'keys_xa': ',&capi_overwrite_#varname#',
|
| 1078 |
+
'docsignxa': 'overwrite_#varname#=0,',
|
| 1079 |
+
'docsignxashort': 'overwrite_#varname#,',
|
| 1080 |
+
'docstropt': 'overwrite_#varname# : input int, optional\\n Default: 0',
|
| 1081 |
+
'_check': l_and(isarray, isintent_copy),
|
| 1082 |
+
}, {
|
| 1083 |
+
'frompyobj': ' capi_#varname#_intent |= (capi_overwrite_#varname#?0:F2PY_INTENT_COPY);',
|
| 1084 |
+
'_check': l_and(isarray, isintent_copy),
|
| 1085 |
+
'_depend': '',
|
| 1086 |
+
}, {
|
| 1087 |
+
'need': [{hasinitvalue: 'forcomb'}, {hasinitvalue: 'CFUNCSMESS'}],
|
| 1088 |
+
'_check': isarray,
|
| 1089 |
+
'_depend': ''
|
| 1090 |
+
}, { # Not hidden
|
| 1091 |
+
'decl': ' PyObject *#varname#_capi = Py_None;',
|
| 1092 |
+
'argformat': {isrequired: 'O'},
|
| 1093 |
+
'keyformat': {isoptional: 'O'},
|
| 1094 |
+
'args_capi': {isrequired: ',&#varname#_capi'},
|
| 1095 |
+
'keys_capi': {isoptional: ',&#varname#_capi'},
|
| 1096 |
+
'_check': l_and(isarray, isintent_nothide)
|
| 1097 |
+
}, {
|
| 1098 |
+
'frompyobj': [
|
| 1099 |
+
' #setdims#;',
|
| 1100 |
+
' capi_#varname#_intent |= #intent#;',
|
| 1101 |
+
(' const char * capi_errmess = "#modulename#.#pyname#:'
|
| 1102 |
+
' failed to create array from the #nth# `#varname#`";'),
|
| 1103 |
+
{isintent_hide:
|
| 1104 |
+
' capi_#varname#_as_array = ndarray_from_pyobj('
|
| 1105 |
+
' #atype#,#elsize#,#varname#_Dims,#varname#_Rank,'
|
| 1106 |
+
' capi_#varname#_intent,Py_None,capi_errmess);'},
|
| 1107 |
+
{isintent_nothide:
|
| 1108 |
+
' capi_#varname#_as_array = ndarray_from_pyobj('
|
| 1109 |
+
' #atype#,#elsize#,#varname#_Dims,#varname#_Rank,'
|
| 1110 |
+
' capi_#varname#_intent,#varname#_capi,capi_errmess);'},
|
| 1111 |
+
"""\
|
| 1112 |
+
if (capi_#varname#_as_array == NULL) {
|
| 1113 |
+
PyObject* capi_err = PyErr_Occurred();
|
| 1114 |
+
if (capi_err == NULL) {
|
| 1115 |
+
capi_err = #modulename#_error;
|
| 1116 |
+
PyErr_SetString(capi_err, capi_errmess);
|
| 1117 |
+
}
|
| 1118 |
+
} else {
|
| 1119 |
+
#varname# = (#ctype# *)(PyArray_DATA(capi_#varname#_as_array));
|
| 1120 |
+
""",
|
| 1121 |
+
{isstringarray:
|
| 1122 |
+
' slen(#varname#) = f2py_itemsize(#varname#);'},
|
| 1123 |
+
{hasinitvalue: [
|
| 1124 |
+
{isintent_nothide:
|
| 1125 |
+
' if (#varname#_capi == Py_None) {'},
|
| 1126 |
+
{isintent_hide: ' {'},
|
| 1127 |
+
{iscomplexarray: ' #ctype# capi_c;'},
|
| 1128 |
+
"""\
|
| 1129 |
+
int *_i,capi_i=0;
|
| 1130 |
+
CFUNCSMESS(\"#name#: Initializing #varname#=#init#\\n\");
|
| 1131 |
+
if (initforcomb(PyArray_DIMS(capi_#varname#_as_array),
|
| 1132 |
+
PyArray_NDIM(capi_#varname#_as_array),1)) {
|
| 1133 |
+
while ((_i = nextforcomb()))
|
| 1134 |
+
#varname#[capi_i++] = #init#; /* fortran way */
|
| 1135 |
+
} else {
|
| 1136 |
+
PyObject *exc, *val, *tb;
|
| 1137 |
+
PyErr_Fetch(&exc, &val, &tb);
|
| 1138 |
+
PyErr_SetString(exc ? exc : #modulename#_error,
|
| 1139 |
+
\"Initialization of #nth# #varname# failed (initforcomb).\");
|
| 1140 |
+
npy_PyErr_ChainExceptionsCause(exc, val, tb);
|
| 1141 |
+
f2py_success = 0;
|
| 1142 |
+
}
|
| 1143 |
+
}
|
| 1144 |
+
if (f2py_success) {"""]},
|
| 1145 |
+
],
|
| 1146 |
+
'cleanupfrompyobj': [ # note that this list will be reversed
|
| 1147 |
+
' } '
|
| 1148 |
+
'/* if (capi_#varname#_as_array == NULL) ... else of #varname# */',
|
| 1149 |
+
{l_not(l_or(isintent_out, isintent_hide)): """\
|
| 1150 |
+
if((PyObject *)capi_#varname#_as_array!=#varname#_capi) {
|
| 1151 |
+
Py_XDECREF(capi_#varname#_as_array); }"""},
|
| 1152 |
+
{l_and(isintent_hide, l_not(isintent_out))
|
| 1153 |
+
: """ Py_XDECREF(capi_#varname#_as_array);"""},
|
| 1154 |
+
{hasinitvalue: ' } /*if (f2py_success) of #varname# init*/'},
|
| 1155 |
+
],
|
| 1156 |
+
'_check': isarray,
|
| 1157 |
+
'_depend': ''
|
| 1158 |
+
},
|
| 1159 |
+
# Scalararray
|
| 1160 |
+
{ # Common
|
| 1161 |
+
'_check': l_and(isarray, l_not(iscomplexarray))
|
| 1162 |
+
}, { # Not hidden
|
| 1163 |
+
'_check': l_and(isarray, l_not(iscomplexarray), isintent_nothide)
|
| 1164 |
+
},
|
| 1165 |
+
# Integer*1 array
|
| 1166 |
+
{'need': '#ctype#',
|
| 1167 |
+
'_check': isint1array,
|
| 1168 |
+
'_depend': ''
|
| 1169 |
+
},
|
| 1170 |
+
# Integer*-1 array
|
| 1171 |
+
{'need': '#ctype#',
|
| 1172 |
+
'_check': isunsigned_chararray,
|
| 1173 |
+
'_depend': ''
|
| 1174 |
+
},
|
| 1175 |
+
# Integer*-2 array
|
| 1176 |
+
{'need': '#ctype#',
|
| 1177 |
+
'_check': isunsigned_shortarray,
|
| 1178 |
+
'_depend': ''
|
| 1179 |
+
},
|
| 1180 |
+
# Integer*-8 array
|
| 1181 |
+
{'need': '#ctype#',
|
| 1182 |
+
'_check': isunsigned_long_longarray,
|
| 1183 |
+
'_depend': ''
|
| 1184 |
+
},
|
| 1185 |
+
# Complexarray
|
| 1186 |
+
{'need': '#ctype#',
|
| 1187 |
+
'_check': iscomplexarray,
|
| 1188 |
+
'_depend': ''
|
| 1189 |
+
},
|
| 1190 |
+
# Character
|
| 1191 |
+
{
|
| 1192 |
+
'need': 'string',
|
| 1193 |
+
'_check': ischaracter,
|
| 1194 |
+
},
|
| 1195 |
+
# Character array
|
| 1196 |
+
{
|
| 1197 |
+
'need': 'string',
|
| 1198 |
+
'_check': ischaracterarray,
|
| 1199 |
+
},
|
| 1200 |
+
# Stringarray
|
| 1201 |
+
{
|
| 1202 |
+
'callfortranappend': {isarrayofstrings: 'flen(#varname#),'},
|
| 1203 |
+
'need': 'string',
|
| 1204 |
+
'_check': isstringarray
|
| 1205 |
+
}
|
| 1206 |
+
]
|
| 1207 |
+
|
| 1208 |
+
################# Rules for checking ###############
|
| 1209 |
+
|
| 1210 |
+
check_rules = [
|
| 1211 |
+
{
|
| 1212 |
+
'frompyobj': {debugcapi: ' fprintf(stderr,\"debug-capi:Checking `#check#\'\\n\");'},
|
| 1213 |
+
'need': 'len..'
|
| 1214 |
+
}, {
|
| 1215 |
+
'frompyobj': ' CHECKSCALAR(#check#,\"#check#\",\"#nth# #varname#\",\"#varshowvalue#\",#varname#) {',
|
| 1216 |
+
'cleanupfrompyobj': ' } /*CHECKSCALAR(#check#)*/',
|
| 1217 |
+
'need': 'CHECKSCALAR',
|
| 1218 |
+
'_check': l_and(isscalar, l_not(iscomplex)),
|
| 1219 |
+
'_break': ''
|
| 1220 |
+
}, {
|
| 1221 |
+
'frompyobj': ' CHECKSTRING(#check#,\"#check#\",\"#nth# #varname#\",\"#varshowvalue#\",#varname#) {',
|
| 1222 |
+
'cleanupfrompyobj': ' } /*CHECKSTRING(#check#)*/',
|
| 1223 |
+
'need': 'CHECKSTRING',
|
| 1224 |
+
'_check': isstring,
|
| 1225 |
+
'_break': ''
|
| 1226 |
+
}, {
|
| 1227 |
+
'need': 'CHECKARRAY',
|
| 1228 |
+
'frompyobj': ' CHECKARRAY(#check#,\"#check#\",\"#nth# #varname#\") {',
|
| 1229 |
+
'cleanupfrompyobj': ' } /*CHECKARRAY(#check#)*/',
|
| 1230 |
+
'_check': isarray,
|
| 1231 |
+
'_break': ''
|
| 1232 |
+
}, {
|
| 1233 |
+
'need': 'CHECKGENERIC',
|
| 1234 |
+
'frompyobj': ' CHECKGENERIC(#check#,\"#check#\",\"#nth# #varname#\") {',
|
| 1235 |
+
'cleanupfrompyobj': ' } /*CHECKGENERIC(#check#)*/',
|
| 1236 |
+
}
|
| 1237 |
+
]
|
| 1238 |
+
|
| 1239 |
+
########## Applying the rules. No need to modify what follows #############
|
| 1240 |
+
|
| 1241 |
+
#################### Build C/API module #######################
|
| 1242 |
+
|
| 1243 |
+
|
| 1244 |
+
def buildmodule(m, um):
|
| 1245 |
+
"""
|
| 1246 |
+
Return
|
| 1247 |
+
"""
|
| 1248 |
+
outmess(' Building module "%s"...\n' % (m['name']))
|
| 1249 |
+
ret = {}
|
| 1250 |
+
mod_rules = defmod_rules[:]
|
| 1251 |
+
vrd = capi_maps.modsign2map(m)
|
| 1252 |
+
rd = dictappend({'f2py_version': f2py_version}, vrd)
|
| 1253 |
+
funcwrappers = []
|
| 1254 |
+
funcwrappers2 = [] # F90 codes
|
| 1255 |
+
for n in m['interfaced']:
|
| 1256 |
+
nb = None
|
| 1257 |
+
for bi in m['body']:
|
| 1258 |
+
if bi['block'] not in ['interface', 'abstract interface']:
|
| 1259 |
+
errmess('buildmodule: Expected interface block. Skipping.\n')
|
| 1260 |
+
continue
|
| 1261 |
+
for b in bi['body']:
|
| 1262 |
+
if b['name'] == n:
|
| 1263 |
+
nb = b
|
| 1264 |
+
break
|
| 1265 |
+
|
| 1266 |
+
if not nb:
|
| 1267 |
+
print(
|
| 1268 |
+
'buildmodule: Could not find the body of interfaced routine "%s". Skipping.\n' % (n), file=sys.stderr)
|
| 1269 |
+
continue
|
| 1270 |
+
nb_list = [nb]
|
| 1271 |
+
if 'entry' in nb:
|
| 1272 |
+
for k, a in nb['entry'].items():
|
| 1273 |
+
nb1 = copy.deepcopy(nb)
|
| 1274 |
+
del nb1['entry']
|
| 1275 |
+
nb1['name'] = k
|
| 1276 |
+
nb1['args'] = a
|
| 1277 |
+
nb_list.append(nb1)
|
| 1278 |
+
for nb in nb_list:
|
| 1279 |
+
# requiresf90wrapper must be called before buildapi as it
|
| 1280 |
+
# rewrites assumed shape arrays as automatic arrays.
|
| 1281 |
+
isf90 = requiresf90wrapper(nb)
|
| 1282 |
+
# options is in scope here
|
| 1283 |
+
if options['emptygen']:
|
| 1284 |
+
b_path = options['buildpath']
|
| 1285 |
+
m_name = vrd['modulename']
|
| 1286 |
+
outmess(' Generating possibly empty wrappers"\n')
|
| 1287 |
+
Path(f"{b_path}/{vrd['coutput']}").touch()
|
| 1288 |
+
if isf90:
|
| 1289 |
+
# f77 + f90 wrappers
|
| 1290 |
+
outmess(f' Maybe empty "{m_name}-f2pywrappers2.f90"\n')
|
| 1291 |
+
Path(f'{b_path}/{m_name}-f2pywrappers2.f90').touch()
|
| 1292 |
+
outmess(f' Maybe empty "{m_name}-f2pywrappers.f"\n')
|
| 1293 |
+
Path(f'{b_path}/{m_name}-f2pywrappers.f').touch()
|
| 1294 |
+
else:
|
| 1295 |
+
# only f77 wrappers
|
| 1296 |
+
outmess(f' Maybe empty "{m_name}-f2pywrappers.f"\n')
|
| 1297 |
+
Path(f'{b_path}/{m_name}-f2pywrappers.f').touch()
|
| 1298 |
+
api, wrap = buildapi(nb)
|
| 1299 |
+
if wrap:
|
| 1300 |
+
if isf90:
|
| 1301 |
+
funcwrappers2.append(wrap)
|
| 1302 |
+
else:
|
| 1303 |
+
funcwrappers.append(wrap)
|
| 1304 |
+
ar = applyrules(api, vrd)
|
| 1305 |
+
rd = dictappend(rd, ar)
|
| 1306 |
+
|
| 1307 |
+
# Construct COMMON block support
|
| 1308 |
+
cr, wrap = common_rules.buildhooks(m)
|
| 1309 |
+
if wrap:
|
| 1310 |
+
funcwrappers.append(wrap)
|
| 1311 |
+
ar = applyrules(cr, vrd)
|
| 1312 |
+
rd = dictappend(rd, ar)
|
| 1313 |
+
|
| 1314 |
+
# Construct F90 module support
|
| 1315 |
+
mr, wrap = f90mod_rules.buildhooks(m)
|
| 1316 |
+
if wrap:
|
| 1317 |
+
funcwrappers2.append(wrap)
|
| 1318 |
+
ar = applyrules(mr, vrd)
|
| 1319 |
+
rd = dictappend(rd, ar)
|
| 1320 |
+
|
| 1321 |
+
for u in um:
|
| 1322 |
+
ar = use_rules.buildusevars(u, m['use'][u['name']])
|
| 1323 |
+
rd = dictappend(rd, ar)
|
| 1324 |
+
|
| 1325 |
+
needs = cfuncs.get_needs()
|
| 1326 |
+
# Add mapped definitions
|
| 1327 |
+
needs['typedefs'] += [cvar for cvar in capi_maps.f2cmap_mapped #
|
| 1328 |
+
if cvar in typedef_need_dict.values()]
|
| 1329 |
+
code = {}
|
| 1330 |
+
for n in needs.keys():
|
| 1331 |
+
code[n] = []
|
| 1332 |
+
for k in needs[n]:
|
| 1333 |
+
c = ''
|
| 1334 |
+
if k in cfuncs.includes0:
|
| 1335 |
+
c = cfuncs.includes0[k]
|
| 1336 |
+
elif k in cfuncs.includes:
|
| 1337 |
+
c = cfuncs.includes[k]
|
| 1338 |
+
elif k in cfuncs.userincludes:
|
| 1339 |
+
c = cfuncs.userincludes[k]
|
| 1340 |
+
elif k in cfuncs.typedefs:
|
| 1341 |
+
c = cfuncs.typedefs[k]
|
| 1342 |
+
elif k in cfuncs.typedefs_generated:
|
| 1343 |
+
c = cfuncs.typedefs_generated[k]
|
| 1344 |
+
elif k in cfuncs.cppmacros:
|
| 1345 |
+
c = cfuncs.cppmacros[k]
|
| 1346 |
+
elif k in cfuncs.cfuncs:
|
| 1347 |
+
c = cfuncs.cfuncs[k]
|
| 1348 |
+
elif k in cfuncs.callbacks:
|
| 1349 |
+
c = cfuncs.callbacks[k]
|
| 1350 |
+
elif k in cfuncs.f90modhooks:
|
| 1351 |
+
c = cfuncs.f90modhooks[k]
|
| 1352 |
+
elif k in cfuncs.commonhooks:
|
| 1353 |
+
c = cfuncs.commonhooks[k]
|
| 1354 |
+
else:
|
| 1355 |
+
errmess('buildmodule: unknown need %s.\n' % (repr(k)))
|
| 1356 |
+
continue
|
| 1357 |
+
code[n].append(c)
|
| 1358 |
+
mod_rules.append(code)
|
| 1359 |
+
for r in mod_rules:
|
| 1360 |
+
if ('_check' in r and r['_check'](m)) or ('_check' not in r):
|
| 1361 |
+
ar = applyrules(r, vrd, m)
|
| 1362 |
+
rd = dictappend(rd, ar)
|
| 1363 |
+
ar = applyrules(module_rules, rd)
|
| 1364 |
+
|
| 1365 |
+
fn = os.path.join(options['buildpath'], vrd['coutput'])
|
| 1366 |
+
ret['csrc'] = fn
|
| 1367 |
+
with open(fn, 'w') as f:
|
| 1368 |
+
f.write(ar['modulebody'].replace('\t', 2 * ' '))
|
| 1369 |
+
outmess(' Wrote C/API module "%s" to file "%s"\n' % (m['name'], fn))
|
| 1370 |
+
|
| 1371 |
+
if options['dorestdoc']:
|
| 1372 |
+
fn = os.path.join(
|
| 1373 |
+
options['buildpath'], vrd['modulename'] + 'module.rest')
|
| 1374 |
+
with open(fn, 'w') as f:
|
| 1375 |
+
f.write('.. -*- rest -*-\n')
|
| 1376 |
+
f.write('\n'.join(ar['restdoc']))
|
| 1377 |
+
outmess(' ReST Documentation is saved to file "%s/%smodule.rest"\n' %
|
| 1378 |
+
(options['buildpath'], vrd['modulename']))
|
| 1379 |
+
if options['dolatexdoc']:
|
| 1380 |
+
fn = os.path.join(
|
| 1381 |
+
options['buildpath'], vrd['modulename'] + 'module.tex')
|
| 1382 |
+
ret['ltx'] = fn
|
| 1383 |
+
with open(fn, 'w') as f:
|
| 1384 |
+
f.write(
|
| 1385 |
+
'%% This file is auto-generated with f2py (version:%s)\n' % (f2py_version))
|
| 1386 |
+
if 'shortlatex' not in options:
|
| 1387 |
+
f.write(
|
| 1388 |
+
'\\documentclass{article}\n\\usepackage{a4wide}\n\\begin{document}\n\\tableofcontents\n\n')
|
| 1389 |
+
f.write('\n'.join(ar['latexdoc']))
|
| 1390 |
+
if 'shortlatex' not in options:
|
| 1391 |
+
f.write('\\end{document}')
|
| 1392 |
+
outmess(' Documentation is saved to file "%s/%smodule.tex"\n' %
|
| 1393 |
+
(options['buildpath'], vrd['modulename']))
|
| 1394 |
+
if funcwrappers:
|
| 1395 |
+
wn = os.path.join(options['buildpath'], vrd['f2py_wrapper_output'])
|
| 1396 |
+
ret['fsrc'] = wn
|
| 1397 |
+
with open(wn, 'w') as f:
|
| 1398 |
+
f.write('C -*- fortran -*-\n')
|
| 1399 |
+
f.write(
|
| 1400 |
+
'C This file is autogenerated with f2py (version:%s)\n' % (f2py_version))
|
| 1401 |
+
f.write(
|
| 1402 |
+
'C It contains Fortran 77 wrappers to fortran functions.\n')
|
| 1403 |
+
lines = []
|
| 1404 |
+
for l in ('\n\n'.join(funcwrappers) + '\n').split('\n'):
|
| 1405 |
+
if 0 <= l.find('!') < 66:
|
| 1406 |
+
# don't split comment lines
|
| 1407 |
+
lines.append(l + '\n')
|
| 1408 |
+
elif l and l[0] == ' ':
|
| 1409 |
+
while len(l) >= 66:
|
| 1410 |
+
lines.append(l[:66] + '\n &')
|
| 1411 |
+
l = l[66:]
|
| 1412 |
+
lines.append(l + '\n')
|
| 1413 |
+
else:
|
| 1414 |
+
lines.append(l + '\n')
|
| 1415 |
+
lines = ''.join(lines).replace('\n &\n', '\n')
|
| 1416 |
+
f.write(lines)
|
| 1417 |
+
outmess(' Fortran 77 wrappers are saved to "%s"\n' % (wn))
|
| 1418 |
+
if funcwrappers2:
|
| 1419 |
+
wn = os.path.join(
|
| 1420 |
+
options['buildpath'], '%s-f2pywrappers2.f90' % (vrd['modulename']))
|
| 1421 |
+
ret['fsrc'] = wn
|
| 1422 |
+
with open(wn, 'w') as f:
|
| 1423 |
+
f.write('! -*- f90 -*-\n')
|
| 1424 |
+
f.write(
|
| 1425 |
+
'! This file is autogenerated with f2py (version:%s)\n' % (f2py_version))
|
| 1426 |
+
f.write(
|
| 1427 |
+
'! It contains Fortran 90 wrappers to fortran functions.\n')
|
| 1428 |
+
lines = []
|
| 1429 |
+
for l in ('\n\n'.join(funcwrappers2) + '\n').split('\n'):
|
| 1430 |
+
if 0 <= l.find('!') < 72:
|
| 1431 |
+
# don't split comment lines
|
| 1432 |
+
lines.append(l + '\n')
|
| 1433 |
+
elif len(l) > 72 and l[0] == ' ':
|
| 1434 |
+
lines.append(l[:72] + '&\n &')
|
| 1435 |
+
l = l[72:]
|
| 1436 |
+
while len(l) > 66:
|
| 1437 |
+
lines.append(l[:66] + '&\n &')
|
| 1438 |
+
l = l[66:]
|
| 1439 |
+
lines.append(l + '\n')
|
| 1440 |
+
else:
|
| 1441 |
+
lines.append(l + '\n')
|
| 1442 |
+
lines = ''.join(lines).replace('\n &\n', '\n')
|
| 1443 |
+
f.write(lines)
|
| 1444 |
+
outmess(' Fortran 90 wrappers are saved to "%s"\n' % (wn))
|
| 1445 |
+
return ret
|
| 1446 |
+
|
| 1447 |
+
################## Build C/API function #############
|
| 1448 |
+
|
| 1449 |
+
stnd = {1: 'st', 2: 'nd', 3: 'rd', 4: 'th', 5: 'th',
|
| 1450 |
+
6: 'th', 7: 'th', 8: 'th', 9: 'th', 0: 'th'}
|
| 1451 |
+
|
| 1452 |
+
|
| 1453 |
+
def buildapi(rout):
|
| 1454 |
+
rout, wrap = func2subr.assubr(rout)
|
| 1455 |
+
args, depargs = getargs2(rout)
|
| 1456 |
+
capi_maps.depargs = depargs
|
| 1457 |
+
var = rout['vars']
|
| 1458 |
+
|
| 1459 |
+
if ismoduleroutine(rout):
|
| 1460 |
+
outmess(' Constructing wrapper function "%s.%s"...\n' %
|
| 1461 |
+
(rout['modulename'], rout['name']))
|
| 1462 |
+
else:
|
| 1463 |
+
outmess(' Constructing wrapper function "%s"...\n' % (rout['name']))
|
| 1464 |
+
# Routine
|
| 1465 |
+
vrd = capi_maps.routsign2map(rout)
|
| 1466 |
+
rd = dictappend({}, vrd)
|
| 1467 |
+
for r in rout_rules:
|
| 1468 |
+
if ('_check' in r and r['_check'](rout)) or ('_check' not in r):
|
| 1469 |
+
ar = applyrules(r, vrd, rout)
|
| 1470 |
+
rd = dictappend(rd, ar)
|
| 1471 |
+
|
| 1472 |
+
# Args
|
| 1473 |
+
nth, nthk = 0, 0
|
| 1474 |
+
savevrd = {}
|
| 1475 |
+
for a in args:
|
| 1476 |
+
vrd = capi_maps.sign2map(a, var[a])
|
| 1477 |
+
if isintent_aux(var[a]):
|
| 1478 |
+
_rules = aux_rules
|
| 1479 |
+
else:
|
| 1480 |
+
_rules = arg_rules
|
| 1481 |
+
if not isintent_hide(var[a]):
|
| 1482 |
+
if not isoptional(var[a]):
|
| 1483 |
+
nth = nth + 1
|
| 1484 |
+
vrd['nth'] = repr(nth) + stnd[nth % 10] + ' argument'
|
| 1485 |
+
else:
|
| 1486 |
+
nthk = nthk + 1
|
| 1487 |
+
vrd['nth'] = repr(nthk) + stnd[nthk % 10] + ' keyword'
|
| 1488 |
+
else:
|
| 1489 |
+
vrd['nth'] = 'hidden'
|
| 1490 |
+
savevrd[a] = vrd
|
| 1491 |
+
for r in _rules:
|
| 1492 |
+
if '_depend' in r:
|
| 1493 |
+
continue
|
| 1494 |
+
if ('_check' in r and r['_check'](var[a])) or ('_check' not in r):
|
| 1495 |
+
ar = applyrules(r, vrd, var[a])
|
| 1496 |
+
rd = dictappend(rd, ar)
|
| 1497 |
+
if '_break' in r:
|
| 1498 |
+
break
|
| 1499 |
+
for a in depargs:
|
| 1500 |
+
if isintent_aux(var[a]):
|
| 1501 |
+
_rules = aux_rules
|
| 1502 |
+
else:
|
| 1503 |
+
_rules = arg_rules
|
| 1504 |
+
vrd = savevrd[a]
|
| 1505 |
+
for r in _rules:
|
| 1506 |
+
if '_depend' not in r:
|
| 1507 |
+
continue
|
| 1508 |
+
if ('_check' in r and r['_check'](var[a])) or ('_check' not in r):
|
| 1509 |
+
ar = applyrules(r, vrd, var[a])
|
| 1510 |
+
rd = dictappend(rd, ar)
|
| 1511 |
+
if '_break' in r:
|
| 1512 |
+
break
|
| 1513 |
+
if 'check' in var[a]:
|
| 1514 |
+
for c in var[a]['check']:
|
| 1515 |
+
vrd['check'] = c
|
| 1516 |
+
ar = applyrules(check_rules, vrd, var[a])
|
| 1517 |
+
rd = dictappend(rd, ar)
|
| 1518 |
+
if isinstance(rd['cleanupfrompyobj'], list):
|
| 1519 |
+
rd['cleanupfrompyobj'].reverse()
|
| 1520 |
+
if isinstance(rd['closepyobjfrom'], list):
|
| 1521 |
+
rd['closepyobjfrom'].reverse()
|
| 1522 |
+
rd['docsignature'] = stripcomma(replace('#docsign##docsignopt##docsignxa#',
|
| 1523 |
+
{'docsign': rd['docsign'],
|
| 1524 |
+
'docsignopt': rd['docsignopt'],
|
| 1525 |
+
'docsignxa': rd['docsignxa']}))
|
| 1526 |
+
optargs = stripcomma(replace('#docsignopt##docsignxa#',
|
| 1527 |
+
{'docsignxa': rd['docsignxashort'],
|
| 1528 |
+
'docsignopt': rd['docsignoptshort']}
|
| 1529 |
+
))
|
| 1530 |
+
if optargs == '':
|
| 1531 |
+
rd['docsignatureshort'] = stripcomma(
|
| 1532 |
+
replace('#docsign#', {'docsign': rd['docsign']}))
|
| 1533 |
+
else:
|
| 1534 |
+
rd['docsignatureshort'] = replace('#docsign#[#docsignopt#]',
|
| 1535 |
+
{'docsign': rd['docsign'],
|
| 1536 |
+
'docsignopt': optargs,
|
| 1537 |
+
})
|
| 1538 |
+
rd['latexdocsignatureshort'] = rd['docsignatureshort'].replace('_', '\\_')
|
| 1539 |
+
rd['latexdocsignatureshort'] = rd[
|
| 1540 |
+
'latexdocsignatureshort'].replace(',', ', ')
|
| 1541 |
+
cfs = stripcomma(replace('#callfortran##callfortranappend#', {
|
| 1542 |
+
'callfortran': rd['callfortran'], 'callfortranappend': rd['callfortranappend']}))
|
| 1543 |
+
if len(rd['callfortranappend']) > 1:
|
| 1544 |
+
rd['callcompaqfortran'] = stripcomma(replace('#callfortran# 0,#callfortranappend#', {
|
| 1545 |
+
'callfortran': rd['callfortran'], 'callfortranappend': rd['callfortranappend']}))
|
| 1546 |
+
else:
|
| 1547 |
+
rd['callcompaqfortran'] = cfs
|
| 1548 |
+
rd['callfortran'] = cfs
|
| 1549 |
+
if isinstance(rd['docreturn'], list):
|
| 1550 |
+
rd['docreturn'] = stripcomma(
|
| 1551 |
+
replace('#docreturn#', {'docreturn': rd['docreturn']})) + ' = '
|
| 1552 |
+
rd['docstrsigns'] = []
|
| 1553 |
+
rd['latexdocstrsigns'] = []
|
| 1554 |
+
for k in ['docstrreq', 'docstropt', 'docstrout', 'docstrcbs']:
|
| 1555 |
+
if k in rd and isinstance(rd[k], list):
|
| 1556 |
+
rd['docstrsigns'] = rd['docstrsigns'] + rd[k]
|
| 1557 |
+
k = 'latex' + k
|
| 1558 |
+
if k in rd and isinstance(rd[k], list):
|
| 1559 |
+
rd['latexdocstrsigns'] = rd['latexdocstrsigns'] + rd[k][0:1] +\
|
| 1560 |
+
['\\begin{description}'] + rd[k][1:] +\
|
| 1561 |
+
['\\end{description}']
|
| 1562 |
+
|
| 1563 |
+
ar = applyrules(routine_rules, rd)
|
| 1564 |
+
if ismoduleroutine(rout):
|
| 1565 |
+
outmess(' %s\n' % (ar['docshort']))
|
| 1566 |
+
else:
|
| 1567 |
+
outmess(' %s\n' % (ar['docshort']))
|
| 1568 |
+
return ar, wrap
|
| 1569 |
+
|
| 1570 |
+
|
| 1571 |
+
#################### EOF rules.py #######################
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/setup.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
setup.py for installing F2PY
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
pip install .
|
| 7 |
+
|
| 8 |
+
Copyright 2001-2005 Pearu Peterson all rights reserved,
|
| 9 |
+
Pearu Peterson <pearu@cens.ioc.ee>
|
| 10 |
+
Permission to use, modify, and distribute this software is given under the
|
| 11 |
+
terms of the NumPy License.
|
| 12 |
+
|
| 13 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 14 |
+
$Revision: 1.32 $
|
| 15 |
+
$Date: 2005/01/30 17:22:14 $
|
| 16 |
+
Pearu Peterson
|
| 17 |
+
|
| 18 |
+
"""
|
| 19 |
+
from numpy.distutils.core import setup
|
| 20 |
+
from numpy.distutils.misc_util import Configuration
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
from __version__ import version
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def configuration(parent_package='', top_path=None):
|
| 27 |
+
config = Configuration('f2py', parent_package, top_path)
|
| 28 |
+
config.add_subpackage('tests')
|
| 29 |
+
config.add_data_dir('tests/src')
|
| 30 |
+
config.add_data_files(
|
| 31 |
+
'src/fortranobject.c',
|
| 32 |
+
'src/fortranobject.h')
|
| 33 |
+
config.add_data_files('*.pyi')
|
| 34 |
+
return config
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
|
| 39 |
+
config = configuration(top_path='')
|
| 40 |
+
config = config.todict()
|
| 41 |
+
|
| 42 |
+
config['classifiers'] = [
|
| 43 |
+
'Development Status :: 5 - Production/Stable',
|
| 44 |
+
'Intended Audience :: Developers',
|
| 45 |
+
'Intended Audience :: Science/Research',
|
| 46 |
+
'License :: OSI Approved :: NumPy License',
|
| 47 |
+
'Natural Language :: English',
|
| 48 |
+
'Operating System :: OS Independent',
|
| 49 |
+
'Programming Language :: C',
|
| 50 |
+
'Programming Language :: Fortran',
|
| 51 |
+
'Programming Language :: Python',
|
| 52 |
+
'Topic :: Scientific/Engineering',
|
| 53 |
+
'Topic :: Software Development :: Code Generators',
|
| 54 |
+
]
|
| 55 |
+
setup(version=version,
|
| 56 |
+
description="F2PY - Fortran to Python Interface Generator",
|
| 57 |
+
author="Pearu Peterson",
|
| 58 |
+
author_email="pearu@cens.ioc.ee",
|
| 59 |
+
maintainer="Pearu Peterson",
|
| 60 |
+
maintainer_email="pearu@cens.ioc.ee",
|
| 61 |
+
license="BSD",
|
| 62 |
+
platforms="Unix, Windows (mingw|cygwin), Mac OSX",
|
| 63 |
+
long_description="""\
|
| 64 |
+
The Fortran to Python Interface Generator, or F2PY for short, is a
|
| 65 |
+
command line tool (f2py) for generating Python C/API modules for
|
| 66 |
+
wrapping Fortran 77/90/95 subroutines, accessing common blocks from
|
| 67 |
+
Python, and calling Python functions from Fortran (call-backs).
|
| 68 |
+
Interfacing subroutines/data from Fortran 90/95 modules is supported.""",
|
| 69 |
+
url="https://numpy.org/doc/stable/f2py/",
|
| 70 |
+
keywords=['Fortran', 'f2py'],
|
| 71 |
+
**config)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/symbolic.py
ADDED
|
@@ -0,0 +1,1510 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fortran/C symbolic expressions
|
| 2 |
+
|
| 3 |
+
References:
|
| 4 |
+
- J3/21-007: Draft Fortran 202x. https://j3-fortran.org/doc/year/21/21-007.pdf
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
# To analyze Fortran expressions to solve dimensions specifications,
|
| 8 |
+
# for instances, we implement a minimal symbolic engine for parsing
|
| 9 |
+
# expressions into a tree of expression instances. As a first
|
| 10 |
+
# instance, we care only about arithmetic expressions involving
|
| 11 |
+
# integers and operations like addition (+), subtraction (-),
|
| 12 |
+
# multiplication (*), division (Fortran / is Python //, Fortran // is
|
| 13 |
+
# concatenate), and exponentiation (**). In addition, .pyf files may
|
| 14 |
+
# contain C expressions that support here is implemented as well.
|
| 15 |
+
#
|
| 16 |
+
# TODO: support logical constants (Op.BOOLEAN)
|
| 17 |
+
# TODO: support logical operators (.AND., ...)
|
| 18 |
+
# TODO: support defined operators (.MYOP., ...)
|
| 19 |
+
#
|
| 20 |
+
__all__ = ['Expr']
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
import re
|
| 24 |
+
import warnings
|
| 25 |
+
from enum import Enum
|
| 26 |
+
from math import gcd
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class Language(Enum):
|
| 30 |
+
"""
|
| 31 |
+
Used as Expr.tostring language argument.
|
| 32 |
+
"""
|
| 33 |
+
Python = 0
|
| 34 |
+
Fortran = 1
|
| 35 |
+
C = 2
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class Op(Enum):
|
| 39 |
+
"""
|
| 40 |
+
Used as Expr op attribute.
|
| 41 |
+
"""
|
| 42 |
+
INTEGER = 10
|
| 43 |
+
REAL = 12
|
| 44 |
+
COMPLEX = 15
|
| 45 |
+
STRING = 20
|
| 46 |
+
ARRAY = 30
|
| 47 |
+
SYMBOL = 40
|
| 48 |
+
TERNARY = 100
|
| 49 |
+
APPLY = 200
|
| 50 |
+
INDEXING = 210
|
| 51 |
+
CONCAT = 220
|
| 52 |
+
RELATIONAL = 300
|
| 53 |
+
TERMS = 1000
|
| 54 |
+
FACTORS = 2000
|
| 55 |
+
REF = 3000
|
| 56 |
+
DEREF = 3001
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class RelOp(Enum):
|
| 60 |
+
"""
|
| 61 |
+
Used in Op.RELATIONAL expression to specify the function part.
|
| 62 |
+
"""
|
| 63 |
+
EQ = 1
|
| 64 |
+
NE = 2
|
| 65 |
+
LT = 3
|
| 66 |
+
LE = 4
|
| 67 |
+
GT = 5
|
| 68 |
+
GE = 6
|
| 69 |
+
|
| 70 |
+
@classmethod
|
| 71 |
+
def fromstring(cls, s, language=Language.C):
|
| 72 |
+
if language is Language.Fortran:
|
| 73 |
+
return {'.eq.': RelOp.EQ, '.ne.': RelOp.NE,
|
| 74 |
+
'.lt.': RelOp.LT, '.le.': RelOp.LE,
|
| 75 |
+
'.gt.': RelOp.GT, '.ge.': RelOp.GE}[s.lower()]
|
| 76 |
+
return {'==': RelOp.EQ, '!=': RelOp.NE, '<': RelOp.LT,
|
| 77 |
+
'<=': RelOp.LE, '>': RelOp.GT, '>=': RelOp.GE}[s]
|
| 78 |
+
|
| 79 |
+
def tostring(self, language=Language.C):
|
| 80 |
+
if language is Language.Fortran:
|
| 81 |
+
return {RelOp.EQ: '.eq.', RelOp.NE: '.ne.',
|
| 82 |
+
RelOp.LT: '.lt.', RelOp.LE: '.le.',
|
| 83 |
+
RelOp.GT: '.gt.', RelOp.GE: '.ge.'}[self]
|
| 84 |
+
return {RelOp.EQ: '==', RelOp.NE: '!=',
|
| 85 |
+
RelOp.LT: '<', RelOp.LE: '<=',
|
| 86 |
+
RelOp.GT: '>', RelOp.GE: '>='}[self]
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class ArithOp(Enum):
|
| 90 |
+
"""
|
| 91 |
+
Used in Op.APPLY expression to specify the function part.
|
| 92 |
+
"""
|
| 93 |
+
POS = 1
|
| 94 |
+
NEG = 2
|
| 95 |
+
ADD = 3
|
| 96 |
+
SUB = 4
|
| 97 |
+
MUL = 5
|
| 98 |
+
DIV = 6
|
| 99 |
+
POW = 7
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class OpError(Exception):
|
| 103 |
+
pass
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class Precedence(Enum):
|
| 107 |
+
"""
|
| 108 |
+
Used as Expr.tostring precedence argument.
|
| 109 |
+
"""
|
| 110 |
+
ATOM = 0
|
| 111 |
+
POWER = 1
|
| 112 |
+
UNARY = 2
|
| 113 |
+
PRODUCT = 3
|
| 114 |
+
SUM = 4
|
| 115 |
+
LT = 6
|
| 116 |
+
EQ = 7
|
| 117 |
+
LAND = 11
|
| 118 |
+
LOR = 12
|
| 119 |
+
TERNARY = 13
|
| 120 |
+
ASSIGN = 14
|
| 121 |
+
TUPLE = 15
|
| 122 |
+
NONE = 100
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
integer_types = (int,)
|
| 126 |
+
number_types = (int, float)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _pairs_add(d, k, v):
|
| 130 |
+
# Internal utility method for updating terms and factors data.
|
| 131 |
+
c = d.get(k)
|
| 132 |
+
if c is None:
|
| 133 |
+
d[k] = v
|
| 134 |
+
else:
|
| 135 |
+
c = c + v
|
| 136 |
+
if c:
|
| 137 |
+
d[k] = c
|
| 138 |
+
else:
|
| 139 |
+
del d[k]
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class ExprWarning(UserWarning):
|
| 143 |
+
pass
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def ewarn(message):
|
| 147 |
+
warnings.warn(message, ExprWarning, stacklevel=2)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class Expr:
|
| 151 |
+
"""Represents a Fortran expression as a op-data pair.
|
| 152 |
+
|
| 153 |
+
Expr instances are hashable and sortable.
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
+
@staticmethod
|
| 157 |
+
def parse(s, language=Language.C):
|
| 158 |
+
"""Parse a Fortran expression to a Expr.
|
| 159 |
+
"""
|
| 160 |
+
return fromstring(s, language=language)
|
| 161 |
+
|
| 162 |
+
def __init__(self, op, data):
|
| 163 |
+
assert isinstance(op, Op)
|
| 164 |
+
|
| 165 |
+
# sanity checks
|
| 166 |
+
if op is Op.INTEGER:
|
| 167 |
+
# data is a 2-tuple of numeric object and a kind value
|
| 168 |
+
# (default is 4)
|
| 169 |
+
assert isinstance(data, tuple) and len(data) == 2
|
| 170 |
+
assert isinstance(data[0], int)
|
| 171 |
+
assert isinstance(data[1], (int, str)), data
|
| 172 |
+
elif op is Op.REAL:
|
| 173 |
+
# data is a 2-tuple of numeric object and a kind value
|
| 174 |
+
# (default is 4)
|
| 175 |
+
assert isinstance(data, tuple) and len(data) == 2
|
| 176 |
+
assert isinstance(data[0], float)
|
| 177 |
+
assert isinstance(data[1], (int, str)), data
|
| 178 |
+
elif op is Op.COMPLEX:
|
| 179 |
+
# data is a 2-tuple of constant expressions
|
| 180 |
+
assert isinstance(data, tuple) and len(data) == 2
|
| 181 |
+
elif op is Op.STRING:
|
| 182 |
+
# data is a 2-tuple of quoted string and a kind value
|
| 183 |
+
# (default is 1)
|
| 184 |
+
assert isinstance(data, tuple) and len(data) == 2
|
| 185 |
+
assert (isinstance(data[0], str)
|
| 186 |
+
and data[0][::len(data[0])-1] in ('""', "''", '@@'))
|
| 187 |
+
assert isinstance(data[1], (int, str)), data
|
| 188 |
+
elif op is Op.SYMBOL:
|
| 189 |
+
# data is any hashable object
|
| 190 |
+
assert hash(data) is not None
|
| 191 |
+
elif op in (Op.ARRAY, Op.CONCAT):
|
| 192 |
+
# data is a tuple of expressions
|
| 193 |
+
assert isinstance(data, tuple)
|
| 194 |
+
assert all(isinstance(item, Expr) for item in data), data
|
| 195 |
+
elif op in (Op.TERMS, Op.FACTORS):
|
| 196 |
+
# data is {<term|base>:<coeff|exponent>} where dict values
|
| 197 |
+
# are nonzero Python integers
|
| 198 |
+
assert isinstance(data, dict)
|
| 199 |
+
elif op is Op.APPLY:
|
| 200 |
+
# data is (<function>, <operands>, <kwoperands>) where
|
| 201 |
+
# operands are Expr instances
|
| 202 |
+
assert isinstance(data, tuple) and len(data) == 3
|
| 203 |
+
# function is any hashable object
|
| 204 |
+
assert hash(data[0]) is not None
|
| 205 |
+
assert isinstance(data[1], tuple)
|
| 206 |
+
assert isinstance(data[2], dict)
|
| 207 |
+
elif op is Op.INDEXING:
|
| 208 |
+
# data is (<object>, <indices>)
|
| 209 |
+
assert isinstance(data, tuple) and len(data) == 2
|
| 210 |
+
# function is any hashable object
|
| 211 |
+
assert hash(data[0]) is not None
|
| 212 |
+
elif op is Op.TERNARY:
|
| 213 |
+
# data is (<cond>, <expr1>, <expr2>)
|
| 214 |
+
assert isinstance(data, tuple) and len(data) == 3
|
| 215 |
+
elif op in (Op.REF, Op.DEREF):
|
| 216 |
+
# data is Expr instance
|
| 217 |
+
assert isinstance(data, Expr)
|
| 218 |
+
elif op is Op.RELATIONAL:
|
| 219 |
+
# data is (<relop>, <left>, <right>)
|
| 220 |
+
assert isinstance(data, tuple) and len(data) == 3
|
| 221 |
+
else:
|
| 222 |
+
raise NotImplementedError(
|
| 223 |
+
f'unknown op or missing sanity check: {op}')
|
| 224 |
+
|
| 225 |
+
self.op = op
|
| 226 |
+
self.data = data
|
| 227 |
+
|
| 228 |
+
def __eq__(self, other):
|
| 229 |
+
return (isinstance(other, Expr)
|
| 230 |
+
and self.op is other.op
|
| 231 |
+
and self.data == other.data)
|
| 232 |
+
|
| 233 |
+
def __hash__(self):
|
| 234 |
+
if self.op in (Op.TERMS, Op.FACTORS):
|
| 235 |
+
data = tuple(sorted(self.data.items()))
|
| 236 |
+
elif self.op is Op.APPLY:
|
| 237 |
+
data = self.data[:2] + tuple(sorted(self.data[2].items()))
|
| 238 |
+
else:
|
| 239 |
+
data = self.data
|
| 240 |
+
return hash((self.op, data))
|
| 241 |
+
|
| 242 |
+
def __lt__(self, other):
|
| 243 |
+
if isinstance(other, Expr):
|
| 244 |
+
if self.op is not other.op:
|
| 245 |
+
return self.op.value < other.op.value
|
| 246 |
+
if self.op in (Op.TERMS, Op.FACTORS):
|
| 247 |
+
return (tuple(sorted(self.data.items()))
|
| 248 |
+
< tuple(sorted(other.data.items())))
|
| 249 |
+
if self.op is Op.APPLY:
|
| 250 |
+
if self.data[:2] != other.data[:2]:
|
| 251 |
+
return self.data[:2] < other.data[:2]
|
| 252 |
+
return tuple(sorted(self.data[2].items())) < tuple(
|
| 253 |
+
sorted(other.data[2].items()))
|
| 254 |
+
return self.data < other.data
|
| 255 |
+
return NotImplemented
|
| 256 |
+
|
| 257 |
+
def __le__(self, other): return self == other or self < other
|
| 258 |
+
|
| 259 |
+
def __gt__(self, other): return not (self <= other)
|
| 260 |
+
|
| 261 |
+
def __ge__(self, other): return not (self < other)
|
| 262 |
+
|
| 263 |
+
def __repr__(self):
|
| 264 |
+
return f'{type(self).__name__}({self.op}, {self.data!r})'
|
| 265 |
+
|
| 266 |
+
def __str__(self):
|
| 267 |
+
return self.tostring()
|
| 268 |
+
|
| 269 |
+
def tostring(self, parent_precedence=Precedence.NONE,
|
| 270 |
+
language=Language.Fortran):
|
| 271 |
+
"""Return a string representation of Expr.
|
| 272 |
+
"""
|
| 273 |
+
if self.op in (Op.INTEGER, Op.REAL):
|
| 274 |
+
precedence = (Precedence.SUM if self.data[0] < 0
|
| 275 |
+
else Precedence.ATOM)
|
| 276 |
+
r = str(self.data[0]) + (f'_{self.data[1]}'
|
| 277 |
+
if self.data[1] != 4 else '')
|
| 278 |
+
elif self.op is Op.COMPLEX:
|
| 279 |
+
r = ', '.join(item.tostring(Precedence.TUPLE, language=language)
|
| 280 |
+
for item in self.data)
|
| 281 |
+
r = '(' + r + ')'
|
| 282 |
+
precedence = Precedence.ATOM
|
| 283 |
+
elif self.op is Op.SYMBOL:
|
| 284 |
+
precedence = Precedence.ATOM
|
| 285 |
+
r = str(self.data)
|
| 286 |
+
elif self.op is Op.STRING:
|
| 287 |
+
r = self.data[0]
|
| 288 |
+
if self.data[1] != 1:
|
| 289 |
+
r = self.data[1] + '_' + r
|
| 290 |
+
precedence = Precedence.ATOM
|
| 291 |
+
elif self.op is Op.ARRAY:
|
| 292 |
+
r = ', '.join(item.tostring(Precedence.TUPLE, language=language)
|
| 293 |
+
for item in self.data)
|
| 294 |
+
r = '[' + r + ']'
|
| 295 |
+
precedence = Precedence.ATOM
|
| 296 |
+
elif self.op is Op.TERMS:
|
| 297 |
+
terms = []
|
| 298 |
+
for term, coeff in sorted(self.data.items()):
|
| 299 |
+
if coeff < 0:
|
| 300 |
+
op = ' - '
|
| 301 |
+
coeff = -coeff
|
| 302 |
+
else:
|
| 303 |
+
op = ' + '
|
| 304 |
+
if coeff == 1:
|
| 305 |
+
term = term.tostring(Precedence.SUM, language=language)
|
| 306 |
+
else:
|
| 307 |
+
if term == as_number(1):
|
| 308 |
+
term = str(coeff)
|
| 309 |
+
else:
|
| 310 |
+
term = f'{coeff} * ' + term.tostring(
|
| 311 |
+
Precedence.PRODUCT, language=language)
|
| 312 |
+
if terms:
|
| 313 |
+
terms.append(op)
|
| 314 |
+
elif op == ' - ':
|
| 315 |
+
terms.append('-')
|
| 316 |
+
terms.append(term)
|
| 317 |
+
r = ''.join(terms) or '0'
|
| 318 |
+
precedence = Precedence.SUM if terms else Precedence.ATOM
|
| 319 |
+
elif self.op is Op.FACTORS:
|
| 320 |
+
factors = []
|
| 321 |
+
tail = []
|
| 322 |
+
for base, exp in sorted(self.data.items()):
|
| 323 |
+
op = ' * '
|
| 324 |
+
if exp == 1:
|
| 325 |
+
factor = base.tostring(Precedence.PRODUCT,
|
| 326 |
+
language=language)
|
| 327 |
+
elif language is Language.C:
|
| 328 |
+
if exp in range(2, 10):
|
| 329 |
+
factor = base.tostring(Precedence.PRODUCT,
|
| 330 |
+
language=language)
|
| 331 |
+
factor = ' * '.join([factor] * exp)
|
| 332 |
+
elif exp in range(-10, 0):
|
| 333 |
+
factor = base.tostring(Precedence.PRODUCT,
|
| 334 |
+
language=language)
|
| 335 |
+
tail += [factor] * -exp
|
| 336 |
+
continue
|
| 337 |
+
else:
|
| 338 |
+
factor = base.tostring(Precedence.TUPLE,
|
| 339 |
+
language=language)
|
| 340 |
+
factor = f'pow({factor}, {exp})'
|
| 341 |
+
else:
|
| 342 |
+
factor = base.tostring(Precedence.POWER,
|
| 343 |
+
language=language) + f' ** {exp}'
|
| 344 |
+
if factors:
|
| 345 |
+
factors.append(op)
|
| 346 |
+
factors.append(factor)
|
| 347 |
+
if tail:
|
| 348 |
+
if not factors:
|
| 349 |
+
factors += ['1']
|
| 350 |
+
factors += ['/', '(', ' * '.join(tail), ')']
|
| 351 |
+
r = ''.join(factors) or '1'
|
| 352 |
+
precedence = Precedence.PRODUCT if factors else Precedence.ATOM
|
| 353 |
+
elif self.op is Op.APPLY:
|
| 354 |
+
name, args, kwargs = self.data
|
| 355 |
+
if name is ArithOp.DIV and language is Language.C:
|
| 356 |
+
numer, denom = [arg.tostring(Precedence.PRODUCT,
|
| 357 |
+
language=language)
|
| 358 |
+
for arg in args]
|
| 359 |
+
r = f'{numer} / {denom}'
|
| 360 |
+
precedence = Precedence.PRODUCT
|
| 361 |
+
else:
|
| 362 |
+
args = [arg.tostring(Precedence.TUPLE, language=language)
|
| 363 |
+
for arg in args]
|
| 364 |
+
args += [k + '=' + v.tostring(Precedence.NONE)
|
| 365 |
+
for k, v in kwargs.items()]
|
| 366 |
+
r = f'{name}({", ".join(args)})'
|
| 367 |
+
precedence = Precedence.ATOM
|
| 368 |
+
elif self.op is Op.INDEXING:
|
| 369 |
+
name = self.data[0]
|
| 370 |
+
args = [arg.tostring(Precedence.TUPLE, language=language)
|
| 371 |
+
for arg in self.data[1:]]
|
| 372 |
+
r = f'{name}[{", ".join(args)}]'
|
| 373 |
+
precedence = Precedence.ATOM
|
| 374 |
+
elif self.op is Op.CONCAT:
|
| 375 |
+
args = [arg.tostring(Precedence.PRODUCT, language=language)
|
| 376 |
+
for arg in self.data]
|
| 377 |
+
r = " // ".join(args)
|
| 378 |
+
precedence = Precedence.PRODUCT
|
| 379 |
+
elif self.op is Op.TERNARY:
|
| 380 |
+
cond, expr1, expr2 = [a.tostring(Precedence.TUPLE,
|
| 381 |
+
language=language)
|
| 382 |
+
for a in self.data]
|
| 383 |
+
if language is Language.C:
|
| 384 |
+
r = f'({cond}?{expr1}:{expr2})'
|
| 385 |
+
elif language is Language.Python:
|
| 386 |
+
r = f'({expr1} if {cond} else {expr2})'
|
| 387 |
+
elif language is Language.Fortran:
|
| 388 |
+
r = f'merge({expr1}, {expr2}, {cond})'
|
| 389 |
+
else:
|
| 390 |
+
raise NotImplementedError(
|
| 391 |
+
f'tostring for {self.op} and {language}')
|
| 392 |
+
precedence = Precedence.ATOM
|
| 393 |
+
elif self.op is Op.REF:
|
| 394 |
+
r = '&' + self.data.tostring(Precedence.UNARY, language=language)
|
| 395 |
+
precedence = Precedence.UNARY
|
| 396 |
+
elif self.op is Op.DEREF:
|
| 397 |
+
r = '*' + self.data.tostring(Precedence.UNARY, language=language)
|
| 398 |
+
precedence = Precedence.UNARY
|
| 399 |
+
elif self.op is Op.RELATIONAL:
|
| 400 |
+
rop, left, right = self.data
|
| 401 |
+
precedence = (Precedence.EQ if rop in (RelOp.EQ, RelOp.NE)
|
| 402 |
+
else Precedence.LT)
|
| 403 |
+
left = left.tostring(precedence, language=language)
|
| 404 |
+
right = right.tostring(precedence, language=language)
|
| 405 |
+
rop = rop.tostring(language=language)
|
| 406 |
+
r = f'{left} {rop} {right}'
|
| 407 |
+
else:
|
| 408 |
+
raise NotImplementedError(f'tostring for op {self.op}')
|
| 409 |
+
if parent_precedence.value < precedence.value:
|
| 410 |
+
# If parent precedence is higher than operand precedence,
|
| 411 |
+
# operand will be enclosed in parenthesis.
|
| 412 |
+
return '(' + r + ')'
|
| 413 |
+
return r
|
| 414 |
+
|
| 415 |
+
def __pos__(self):
|
| 416 |
+
return self
|
| 417 |
+
|
| 418 |
+
def __neg__(self):
|
| 419 |
+
return self * -1
|
| 420 |
+
|
| 421 |
+
def __add__(self, other):
|
| 422 |
+
other = as_expr(other)
|
| 423 |
+
if isinstance(other, Expr):
|
| 424 |
+
if self.op is other.op:
|
| 425 |
+
if self.op in (Op.INTEGER, Op.REAL):
|
| 426 |
+
return as_number(
|
| 427 |
+
self.data[0] + other.data[0],
|
| 428 |
+
max(self.data[1], other.data[1]))
|
| 429 |
+
if self.op is Op.COMPLEX:
|
| 430 |
+
r1, i1 = self.data
|
| 431 |
+
r2, i2 = other.data
|
| 432 |
+
return as_complex(r1 + r2, i1 + i2)
|
| 433 |
+
if self.op is Op.TERMS:
|
| 434 |
+
r = Expr(self.op, dict(self.data))
|
| 435 |
+
for k, v in other.data.items():
|
| 436 |
+
_pairs_add(r.data, k, v)
|
| 437 |
+
return normalize(r)
|
| 438 |
+
if self.op is Op.COMPLEX and other.op in (Op.INTEGER, Op.REAL):
|
| 439 |
+
return self + as_complex(other)
|
| 440 |
+
elif self.op in (Op.INTEGER, Op.REAL) and other.op is Op.COMPLEX:
|
| 441 |
+
return as_complex(self) + other
|
| 442 |
+
elif self.op is Op.REAL and other.op is Op.INTEGER:
|
| 443 |
+
return self + as_real(other, kind=self.data[1])
|
| 444 |
+
elif self.op is Op.INTEGER and other.op is Op.REAL:
|
| 445 |
+
return as_real(self, kind=other.data[1]) + other
|
| 446 |
+
return as_terms(self) + as_terms(other)
|
| 447 |
+
return NotImplemented
|
| 448 |
+
|
| 449 |
+
def __radd__(self, other):
|
| 450 |
+
if isinstance(other, number_types):
|
| 451 |
+
return as_number(other) + self
|
| 452 |
+
return NotImplemented
|
| 453 |
+
|
| 454 |
+
def __sub__(self, other):
|
| 455 |
+
return self + (-other)
|
| 456 |
+
|
| 457 |
+
def __rsub__(self, other):
|
| 458 |
+
if isinstance(other, number_types):
|
| 459 |
+
return as_number(other) - self
|
| 460 |
+
return NotImplemented
|
| 461 |
+
|
| 462 |
+
def __mul__(self, other):
|
| 463 |
+
other = as_expr(other)
|
| 464 |
+
if isinstance(other, Expr):
|
| 465 |
+
if self.op is other.op:
|
| 466 |
+
if self.op in (Op.INTEGER, Op.REAL):
|
| 467 |
+
return as_number(self.data[0] * other.data[0],
|
| 468 |
+
max(self.data[1], other.data[1]))
|
| 469 |
+
elif self.op is Op.COMPLEX:
|
| 470 |
+
r1, i1 = self.data
|
| 471 |
+
r2, i2 = other.data
|
| 472 |
+
return as_complex(r1 * r2 - i1 * i2, r1 * i2 + r2 * i1)
|
| 473 |
+
|
| 474 |
+
if self.op is Op.FACTORS:
|
| 475 |
+
r = Expr(self.op, dict(self.data))
|
| 476 |
+
for k, v in other.data.items():
|
| 477 |
+
_pairs_add(r.data, k, v)
|
| 478 |
+
return normalize(r)
|
| 479 |
+
elif self.op is Op.TERMS:
|
| 480 |
+
r = Expr(self.op, {})
|
| 481 |
+
for t1, c1 in self.data.items():
|
| 482 |
+
for t2, c2 in other.data.items():
|
| 483 |
+
_pairs_add(r.data, t1 * t2, c1 * c2)
|
| 484 |
+
return normalize(r)
|
| 485 |
+
|
| 486 |
+
if self.op is Op.COMPLEX and other.op in (Op.INTEGER, Op.REAL):
|
| 487 |
+
return self * as_complex(other)
|
| 488 |
+
elif other.op is Op.COMPLEX and self.op in (Op.INTEGER, Op.REAL):
|
| 489 |
+
return as_complex(self) * other
|
| 490 |
+
elif self.op is Op.REAL and other.op is Op.INTEGER:
|
| 491 |
+
return self * as_real(other, kind=self.data[1])
|
| 492 |
+
elif self.op is Op.INTEGER and other.op is Op.REAL:
|
| 493 |
+
return as_real(self, kind=other.data[1]) * other
|
| 494 |
+
|
| 495 |
+
if self.op is Op.TERMS:
|
| 496 |
+
return self * as_terms(other)
|
| 497 |
+
elif other.op is Op.TERMS:
|
| 498 |
+
return as_terms(self) * other
|
| 499 |
+
|
| 500 |
+
return as_factors(self) * as_factors(other)
|
| 501 |
+
return NotImplemented
|
| 502 |
+
|
| 503 |
+
def __rmul__(self, other):
|
| 504 |
+
if isinstance(other, number_types):
|
| 505 |
+
return as_number(other) * self
|
| 506 |
+
return NotImplemented
|
| 507 |
+
|
| 508 |
+
def __pow__(self, other):
|
| 509 |
+
other = as_expr(other)
|
| 510 |
+
if isinstance(other, Expr):
|
| 511 |
+
if other.op is Op.INTEGER:
|
| 512 |
+
exponent = other.data[0]
|
| 513 |
+
# TODO: other kind not used
|
| 514 |
+
if exponent == 0:
|
| 515 |
+
return as_number(1)
|
| 516 |
+
if exponent == 1:
|
| 517 |
+
return self
|
| 518 |
+
if exponent > 0:
|
| 519 |
+
if self.op is Op.FACTORS:
|
| 520 |
+
r = Expr(self.op, {})
|
| 521 |
+
for k, v in self.data.items():
|
| 522 |
+
r.data[k] = v * exponent
|
| 523 |
+
return normalize(r)
|
| 524 |
+
return self * (self ** (exponent - 1))
|
| 525 |
+
elif exponent != -1:
|
| 526 |
+
return (self ** (-exponent)) ** -1
|
| 527 |
+
return Expr(Op.FACTORS, {self: exponent})
|
| 528 |
+
return as_apply(ArithOp.POW, self, other)
|
| 529 |
+
return NotImplemented
|
| 530 |
+
|
| 531 |
+
def __truediv__(self, other):
|
| 532 |
+
other = as_expr(other)
|
| 533 |
+
if isinstance(other, Expr):
|
| 534 |
+
# Fortran / is different from Python /:
|
| 535 |
+
# - `/` is a truncate operation for integer operands
|
| 536 |
+
return normalize(as_apply(ArithOp.DIV, self, other))
|
| 537 |
+
return NotImplemented
|
| 538 |
+
|
| 539 |
+
def __rtruediv__(self, other):
|
| 540 |
+
other = as_expr(other)
|
| 541 |
+
if isinstance(other, Expr):
|
| 542 |
+
return other / self
|
| 543 |
+
return NotImplemented
|
| 544 |
+
|
| 545 |
+
def __floordiv__(self, other):
|
| 546 |
+
other = as_expr(other)
|
| 547 |
+
if isinstance(other, Expr):
|
| 548 |
+
# Fortran // is different from Python //:
|
| 549 |
+
# - `//` is a concatenate operation for string operands
|
| 550 |
+
return normalize(Expr(Op.CONCAT, (self, other)))
|
| 551 |
+
return NotImplemented
|
| 552 |
+
|
| 553 |
+
def __rfloordiv__(self, other):
|
| 554 |
+
other = as_expr(other)
|
| 555 |
+
if isinstance(other, Expr):
|
| 556 |
+
return other // self
|
| 557 |
+
return NotImplemented
|
| 558 |
+
|
| 559 |
+
def __call__(self, *args, **kwargs):
|
| 560 |
+
# In Fortran, parenthesis () are use for both function call as
|
| 561 |
+
# well as indexing operations.
|
| 562 |
+
#
|
| 563 |
+
# TODO: implement a method for deciding when __call__ should
|
| 564 |
+
# return an INDEXING expression.
|
| 565 |
+
return as_apply(self, *map(as_expr, args),
|
| 566 |
+
**dict((k, as_expr(v)) for k, v in kwargs.items()))
|
| 567 |
+
|
| 568 |
+
def __getitem__(self, index):
|
| 569 |
+
# Provided to support C indexing operations that .pyf files
|
| 570 |
+
# may contain.
|
| 571 |
+
index = as_expr(index)
|
| 572 |
+
if not isinstance(index, tuple):
|
| 573 |
+
index = index,
|
| 574 |
+
if len(index) > 1:
|
| 575 |
+
ewarn(f'C-index should be a single expression but got `{index}`')
|
| 576 |
+
return Expr(Op.INDEXING, (self,) + index)
|
| 577 |
+
|
| 578 |
+
def substitute(self, symbols_map):
|
| 579 |
+
"""Recursively substitute symbols with values in symbols map.
|
| 580 |
+
|
| 581 |
+
Symbols map is a dictionary of symbol-expression pairs.
|
| 582 |
+
"""
|
| 583 |
+
if self.op is Op.SYMBOL:
|
| 584 |
+
value = symbols_map.get(self)
|
| 585 |
+
if value is None:
|
| 586 |
+
return self
|
| 587 |
+
m = re.match(r'\A(@__f2py_PARENTHESIS_(\w+)_\d+@)\Z', self.data)
|
| 588 |
+
if m:
|
| 589 |
+
# complement to fromstring method
|
| 590 |
+
items, paren = m.groups()
|
| 591 |
+
if paren in ['ROUNDDIV', 'SQUARE']:
|
| 592 |
+
return as_array(value)
|
| 593 |
+
assert paren == 'ROUND', (paren, value)
|
| 594 |
+
return value
|
| 595 |
+
if self.op in (Op.INTEGER, Op.REAL, Op.STRING):
|
| 596 |
+
return self
|
| 597 |
+
if self.op in (Op.ARRAY, Op.COMPLEX):
|
| 598 |
+
return Expr(self.op, tuple(item.substitute(symbols_map)
|
| 599 |
+
for item in self.data))
|
| 600 |
+
if self.op is Op.CONCAT:
|
| 601 |
+
return normalize(Expr(self.op, tuple(item.substitute(symbols_map)
|
| 602 |
+
for item in self.data)))
|
| 603 |
+
if self.op is Op.TERMS:
|
| 604 |
+
r = None
|
| 605 |
+
for term, coeff in self.data.items():
|
| 606 |
+
if r is None:
|
| 607 |
+
r = term.substitute(symbols_map) * coeff
|
| 608 |
+
else:
|
| 609 |
+
r += term.substitute(symbols_map) * coeff
|
| 610 |
+
if r is None:
|
| 611 |
+
ewarn('substitute: empty TERMS expression interpreted as'
|
| 612 |
+
' int-literal 0')
|
| 613 |
+
return as_number(0)
|
| 614 |
+
return r
|
| 615 |
+
if self.op is Op.FACTORS:
|
| 616 |
+
r = None
|
| 617 |
+
for base, exponent in self.data.items():
|
| 618 |
+
if r is None:
|
| 619 |
+
r = base.substitute(symbols_map) ** exponent
|
| 620 |
+
else:
|
| 621 |
+
r *= base.substitute(symbols_map) ** exponent
|
| 622 |
+
if r is None:
|
| 623 |
+
ewarn('substitute: empty FACTORS expression interpreted'
|
| 624 |
+
' as int-literal 1')
|
| 625 |
+
return as_number(1)
|
| 626 |
+
return r
|
| 627 |
+
if self.op is Op.APPLY:
|
| 628 |
+
target, args, kwargs = self.data
|
| 629 |
+
if isinstance(target, Expr):
|
| 630 |
+
target = target.substitute(symbols_map)
|
| 631 |
+
args = tuple(a.substitute(symbols_map) for a in args)
|
| 632 |
+
kwargs = dict((k, v.substitute(symbols_map))
|
| 633 |
+
for k, v in kwargs.items())
|
| 634 |
+
return normalize(Expr(self.op, (target, args, kwargs)))
|
| 635 |
+
if self.op is Op.INDEXING:
|
| 636 |
+
func = self.data[0]
|
| 637 |
+
if isinstance(func, Expr):
|
| 638 |
+
func = func.substitute(symbols_map)
|
| 639 |
+
args = tuple(a.substitute(symbols_map) for a in self.data[1:])
|
| 640 |
+
return normalize(Expr(self.op, (func,) + args))
|
| 641 |
+
if self.op is Op.TERNARY:
|
| 642 |
+
operands = tuple(a.substitute(symbols_map) for a in self.data)
|
| 643 |
+
return normalize(Expr(self.op, operands))
|
| 644 |
+
if self.op in (Op.REF, Op.DEREF):
|
| 645 |
+
return normalize(Expr(self.op, self.data.substitute(symbols_map)))
|
| 646 |
+
if self.op is Op.RELATIONAL:
|
| 647 |
+
rop, left, right = self.data
|
| 648 |
+
left = left.substitute(symbols_map)
|
| 649 |
+
right = right.substitute(symbols_map)
|
| 650 |
+
return normalize(Expr(self.op, (rop, left, right)))
|
| 651 |
+
raise NotImplementedError(f'substitute method for {self.op}: {self!r}')
|
| 652 |
+
|
| 653 |
+
def traverse(self, visit, *args, **kwargs):
|
| 654 |
+
"""Traverse expression tree with visit function.
|
| 655 |
+
|
| 656 |
+
The visit function is applied to an expression with given args
|
| 657 |
+
and kwargs.
|
| 658 |
+
|
| 659 |
+
Traverse call returns an expression returned by visit when not
|
| 660 |
+
None, otherwise return a new normalized expression with
|
| 661 |
+
traverse-visit sub-expressions.
|
| 662 |
+
"""
|
| 663 |
+
result = visit(self, *args, **kwargs)
|
| 664 |
+
if result is not None:
|
| 665 |
+
return result
|
| 666 |
+
|
| 667 |
+
if self.op in (Op.INTEGER, Op.REAL, Op.STRING, Op.SYMBOL):
|
| 668 |
+
return self
|
| 669 |
+
elif self.op in (Op.COMPLEX, Op.ARRAY, Op.CONCAT, Op.TERNARY):
|
| 670 |
+
return normalize(Expr(self.op, tuple(
|
| 671 |
+
item.traverse(visit, *args, **kwargs)
|
| 672 |
+
for item in self.data)))
|
| 673 |
+
elif self.op in (Op.TERMS, Op.FACTORS):
|
| 674 |
+
data = {}
|
| 675 |
+
for k, v in self.data.items():
|
| 676 |
+
k = k.traverse(visit, *args, **kwargs)
|
| 677 |
+
v = (v.traverse(visit, *args, **kwargs)
|
| 678 |
+
if isinstance(v, Expr) else v)
|
| 679 |
+
if k in data:
|
| 680 |
+
v = data[k] + v
|
| 681 |
+
data[k] = v
|
| 682 |
+
return normalize(Expr(self.op, data))
|
| 683 |
+
elif self.op is Op.APPLY:
|
| 684 |
+
obj = self.data[0]
|
| 685 |
+
func = (obj.traverse(visit, *args, **kwargs)
|
| 686 |
+
if isinstance(obj, Expr) else obj)
|
| 687 |
+
operands = tuple(operand.traverse(visit, *args, **kwargs)
|
| 688 |
+
for operand in self.data[1])
|
| 689 |
+
kwoperands = dict((k, v.traverse(visit, *args, **kwargs))
|
| 690 |
+
for k, v in self.data[2].items())
|
| 691 |
+
return normalize(Expr(self.op, (func, operands, kwoperands)))
|
| 692 |
+
elif self.op is Op.INDEXING:
|
| 693 |
+
obj = self.data[0]
|
| 694 |
+
obj = (obj.traverse(visit, *args, **kwargs)
|
| 695 |
+
if isinstance(obj, Expr) else obj)
|
| 696 |
+
indices = tuple(index.traverse(visit, *args, **kwargs)
|
| 697 |
+
for index in self.data[1:])
|
| 698 |
+
return normalize(Expr(self.op, (obj,) + indices))
|
| 699 |
+
elif self.op in (Op.REF, Op.DEREF):
|
| 700 |
+
return normalize(Expr(self.op,
|
| 701 |
+
self.data.traverse(visit, *args, **kwargs)))
|
| 702 |
+
elif self.op is Op.RELATIONAL:
|
| 703 |
+
rop, left, right = self.data
|
| 704 |
+
left = left.traverse(visit, *args, **kwargs)
|
| 705 |
+
right = right.traverse(visit, *args, **kwargs)
|
| 706 |
+
return normalize(Expr(self.op, (rop, left, right)))
|
| 707 |
+
raise NotImplementedError(f'traverse method for {self.op}')
|
| 708 |
+
|
| 709 |
+
def contains(self, other):
|
| 710 |
+
"""Check if self contains other.
|
| 711 |
+
"""
|
| 712 |
+
found = []
|
| 713 |
+
|
| 714 |
+
def visit(expr, found=found):
|
| 715 |
+
if found:
|
| 716 |
+
return expr
|
| 717 |
+
elif expr == other:
|
| 718 |
+
found.append(1)
|
| 719 |
+
return expr
|
| 720 |
+
|
| 721 |
+
self.traverse(visit)
|
| 722 |
+
|
| 723 |
+
return len(found) != 0
|
| 724 |
+
|
| 725 |
+
def symbols(self):
|
| 726 |
+
"""Return a set of symbols contained in self.
|
| 727 |
+
"""
|
| 728 |
+
found = set()
|
| 729 |
+
|
| 730 |
+
def visit(expr, found=found):
|
| 731 |
+
if expr.op is Op.SYMBOL:
|
| 732 |
+
found.add(expr)
|
| 733 |
+
|
| 734 |
+
self.traverse(visit)
|
| 735 |
+
|
| 736 |
+
return found
|
| 737 |
+
|
| 738 |
+
def polynomial_atoms(self):
|
| 739 |
+
"""Return a set of expressions used as atoms in polynomial self.
|
| 740 |
+
"""
|
| 741 |
+
found = set()
|
| 742 |
+
|
| 743 |
+
def visit(expr, found=found):
|
| 744 |
+
if expr.op is Op.FACTORS:
|
| 745 |
+
for b in expr.data:
|
| 746 |
+
b.traverse(visit)
|
| 747 |
+
return expr
|
| 748 |
+
if expr.op in (Op.TERMS, Op.COMPLEX):
|
| 749 |
+
return
|
| 750 |
+
if expr.op is Op.APPLY and isinstance(expr.data[0], ArithOp):
|
| 751 |
+
if expr.data[0] is ArithOp.POW:
|
| 752 |
+
expr.data[1][0].traverse(visit)
|
| 753 |
+
return expr
|
| 754 |
+
return
|
| 755 |
+
if expr.op in (Op.INTEGER, Op.REAL):
|
| 756 |
+
return expr
|
| 757 |
+
|
| 758 |
+
found.add(expr)
|
| 759 |
+
|
| 760 |
+
if expr.op in (Op.INDEXING, Op.APPLY):
|
| 761 |
+
return expr
|
| 762 |
+
|
| 763 |
+
self.traverse(visit)
|
| 764 |
+
|
| 765 |
+
return found
|
| 766 |
+
|
| 767 |
+
def linear_solve(self, symbol):
|
| 768 |
+
"""Return a, b such that a * symbol + b == self.
|
| 769 |
+
|
| 770 |
+
If self is not linear with respect to symbol, raise RuntimeError.
|
| 771 |
+
"""
|
| 772 |
+
b = self.substitute({symbol: as_number(0)})
|
| 773 |
+
ax = self - b
|
| 774 |
+
a = ax.substitute({symbol: as_number(1)})
|
| 775 |
+
|
| 776 |
+
zero, _ = as_numer_denom(a * symbol - ax)
|
| 777 |
+
|
| 778 |
+
if zero != as_number(0):
|
| 779 |
+
raise RuntimeError(f'not a {symbol}-linear equation:'
|
| 780 |
+
f' {a} * {symbol} + {b} == {self}')
|
| 781 |
+
return a, b
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
def normalize(obj):
|
| 785 |
+
"""Normalize Expr and apply basic evaluation methods.
|
| 786 |
+
"""
|
| 787 |
+
if not isinstance(obj, Expr):
|
| 788 |
+
return obj
|
| 789 |
+
|
| 790 |
+
if obj.op is Op.TERMS:
|
| 791 |
+
d = {}
|
| 792 |
+
for t, c in obj.data.items():
|
| 793 |
+
if c == 0:
|
| 794 |
+
continue
|
| 795 |
+
if t.op is Op.COMPLEX and c != 1:
|
| 796 |
+
t = t * c
|
| 797 |
+
c = 1
|
| 798 |
+
if t.op is Op.TERMS:
|
| 799 |
+
for t1, c1 in t.data.items():
|
| 800 |
+
_pairs_add(d, t1, c1 * c)
|
| 801 |
+
else:
|
| 802 |
+
_pairs_add(d, t, c)
|
| 803 |
+
if len(d) == 0:
|
| 804 |
+
# TODO: deterimine correct kind
|
| 805 |
+
return as_number(0)
|
| 806 |
+
elif len(d) == 1:
|
| 807 |
+
(t, c), = d.items()
|
| 808 |
+
if c == 1:
|
| 809 |
+
return t
|
| 810 |
+
return Expr(Op.TERMS, d)
|
| 811 |
+
|
| 812 |
+
if obj.op is Op.FACTORS:
|
| 813 |
+
coeff = 1
|
| 814 |
+
d = {}
|
| 815 |
+
for b, e in obj.data.items():
|
| 816 |
+
if e == 0:
|
| 817 |
+
continue
|
| 818 |
+
if b.op is Op.TERMS and isinstance(e, integer_types) and e > 1:
|
| 819 |
+
# expand integer powers of sums
|
| 820 |
+
b = b * (b ** (e - 1))
|
| 821 |
+
e = 1
|
| 822 |
+
|
| 823 |
+
if b.op in (Op.INTEGER, Op.REAL):
|
| 824 |
+
if e == 1:
|
| 825 |
+
coeff *= b.data[0]
|
| 826 |
+
elif e > 0:
|
| 827 |
+
coeff *= b.data[0] ** e
|
| 828 |
+
else:
|
| 829 |
+
_pairs_add(d, b, e)
|
| 830 |
+
elif b.op is Op.FACTORS:
|
| 831 |
+
if e > 0 and isinstance(e, integer_types):
|
| 832 |
+
for b1, e1 in b.data.items():
|
| 833 |
+
_pairs_add(d, b1, e1 * e)
|
| 834 |
+
else:
|
| 835 |
+
_pairs_add(d, b, e)
|
| 836 |
+
else:
|
| 837 |
+
_pairs_add(d, b, e)
|
| 838 |
+
if len(d) == 0 or coeff == 0:
|
| 839 |
+
# TODO: deterimine correct kind
|
| 840 |
+
assert isinstance(coeff, number_types)
|
| 841 |
+
return as_number(coeff)
|
| 842 |
+
elif len(d) == 1:
|
| 843 |
+
(b, e), = d.items()
|
| 844 |
+
if e == 1:
|
| 845 |
+
t = b
|
| 846 |
+
else:
|
| 847 |
+
t = Expr(Op.FACTORS, d)
|
| 848 |
+
if coeff == 1:
|
| 849 |
+
return t
|
| 850 |
+
return Expr(Op.TERMS, {t: coeff})
|
| 851 |
+
elif coeff == 1:
|
| 852 |
+
return Expr(Op.FACTORS, d)
|
| 853 |
+
else:
|
| 854 |
+
return Expr(Op.TERMS, {Expr(Op.FACTORS, d): coeff})
|
| 855 |
+
|
| 856 |
+
if obj.op is Op.APPLY and obj.data[0] is ArithOp.DIV:
|
| 857 |
+
dividend, divisor = obj.data[1]
|
| 858 |
+
t1, c1 = as_term_coeff(dividend)
|
| 859 |
+
t2, c2 = as_term_coeff(divisor)
|
| 860 |
+
if isinstance(c1, integer_types) and isinstance(c2, integer_types):
|
| 861 |
+
g = gcd(c1, c2)
|
| 862 |
+
c1, c2 = c1//g, c2//g
|
| 863 |
+
else:
|
| 864 |
+
c1, c2 = c1/c2, 1
|
| 865 |
+
|
| 866 |
+
if t1.op is Op.APPLY and t1.data[0] is ArithOp.DIV:
|
| 867 |
+
numer = t1.data[1][0] * c1
|
| 868 |
+
denom = t1.data[1][1] * t2 * c2
|
| 869 |
+
return as_apply(ArithOp.DIV, numer, denom)
|
| 870 |
+
|
| 871 |
+
if t2.op is Op.APPLY and t2.data[0] is ArithOp.DIV:
|
| 872 |
+
numer = t2.data[1][1] * t1 * c1
|
| 873 |
+
denom = t2.data[1][0] * c2
|
| 874 |
+
return as_apply(ArithOp.DIV, numer, denom)
|
| 875 |
+
|
| 876 |
+
d = dict(as_factors(t1).data)
|
| 877 |
+
for b, e in as_factors(t2).data.items():
|
| 878 |
+
_pairs_add(d, b, -e)
|
| 879 |
+
numer, denom = {}, {}
|
| 880 |
+
for b, e in d.items():
|
| 881 |
+
if e > 0:
|
| 882 |
+
numer[b] = e
|
| 883 |
+
else:
|
| 884 |
+
denom[b] = -e
|
| 885 |
+
numer = normalize(Expr(Op.FACTORS, numer)) * c1
|
| 886 |
+
denom = normalize(Expr(Op.FACTORS, denom)) * c2
|
| 887 |
+
|
| 888 |
+
if denom.op in (Op.INTEGER, Op.REAL) and denom.data[0] == 1:
|
| 889 |
+
# TODO: denom kind not used
|
| 890 |
+
return numer
|
| 891 |
+
return as_apply(ArithOp.DIV, numer, denom)
|
| 892 |
+
|
| 893 |
+
if obj.op is Op.CONCAT:
|
| 894 |
+
lst = [obj.data[0]]
|
| 895 |
+
for s in obj.data[1:]:
|
| 896 |
+
last = lst[-1]
|
| 897 |
+
if (
|
| 898 |
+
last.op is Op.STRING
|
| 899 |
+
and s.op is Op.STRING
|
| 900 |
+
and last.data[0][0] in '"\''
|
| 901 |
+
and s.data[0][0] == last.data[0][-1]
|
| 902 |
+
):
|
| 903 |
+
new_last = as_string(last.data[0][:-1] + s.data[0][1:],
|
| 904 |
+
max(last.data[1], s.data[1]))
|
| 905 |
+
lst[-1] = new_last
|
| 906 |
+
else:
|
| 907 |
+
lst.append(s)
|
| 908 |
+
if len(lst) == 1:
|
| 909 |
+
return lst[0]
|
| 910 |
+
return Expr(Op.CONCAT, tuple(lst))
|
| 911 |
+
|
| 912 |
+
if obj.op is Op.TERNARY:
|
| 913 |
+
cond, expr1, expr2 = map(normalize, obj.data)
|
| 914 |
+
if cond.op is Op.INTEGER:
|
| 915 |
+
return expr1 if cond.data[0] else expr2
|
| 916 |
+
return Expr(Op.TERNARY, (cond, expr1, expr2))
|
| 917 |
+
|
| 918 |
+
return obj
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
def as_expr(obj):
|
| 922 |
+
"""Convert non-Expr objects to Expr objects.
|
| 923 |
+
"""
|
| 924 |
+
if isinstance(obj, complex):
|
| 925 |
+
return as_complex(obj.real, obj.imag)
|
| 926 |
+
if isinstance(obj, number_types):
|
| 927 |
+
return as_number(obj)
|
| 928 |
+
if isinstance(obj, str):
|
| 929 |
+
# STRING expression holds string with boundary quotes, hence
|
| 930 |
+
# applying repr:
|
| 931 |
+
return as_string(repr(obj))
|
| 932 |
+
if isinstance(obj, tuple):
|
| 933 |
+
return tuple(map(as_expr, obj))
|
| 934 |
+
return obj
|
| 935 |
+
|
| 936 |
+
|
| 937 |
+
def as_symbol(obj):
|
| 938 |
+
"""Return object as SYMBOL expression (variable or unparsed expression).
|
| 939 |
+
"""
|
| 940 |
+
return Expr(Op.SYMBOL, obj)
|
| 941 |
+
|
| 942 |
+
|
| 943 |
+
def as_number(obj, kind=4):
|
| 944 |
+
"""Return object as INTEGER or REAL constant.
|
| 945 |
+
"""
|
| 946 |
+
if isinstance(obj, int):
|
| 947 |
+
return Expr(Op.INTEGER, (obj, kind))
|
| 948 |
+
if isinstance(obj, float):
|
| 949 |
+
return Expr(Op.REAL, (obj, kind))
|
| 950 |
+
if isinstance(obj, Expr):
|
| 951 |
+
if obj.op in (Op.INTEGER, Op.REAL):
|
| 952 |
+
return obj
|
| 953 |
+
raise OpError(f'cannot convert {obj} to INTEGER or REAL constant')
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
def as_integer(obj, kind=4):
|
| 957 |
+
"""Return object as INTEGER constant.
|
| 958 |
+
"""
|
| 959 |
+
if isinstance(obj, int):
|
| 960 |
+
return Expr(Op.INTEGER, (obj, kind))
|
| 961 |
+
if isinstance(obj, Expr):
|
| 962 |
+
if obj.op is Op.INTEGER:
|
| 963 |
+
return obj
|
| 964 |
+
raise OpError(f'cannot convert {obj} to INTEGER constant')
|
| 965 |
+
|
| 966 |
+
|
| 967 |
+
def as_real(obj, kind=4):
|
| 968 |
+
"""Return object as REAL constant.
|
| 969 |
+
"""
|
| 970 |
+
if isinstance(obj, int):
|
| 971 |
+
return Expr(Op.REAL, (float(obj), kind))
|
| 972 |
+
if isinstance(obj, float):
|
| 973 |
+
return Expr(Op.REAL, (obj, kind))
|
| 974 |
+
if isinstance(obj, Expr):
|
| 975 |
+
if obj.op is Op.REAL:
|
| 976 |
+
return obj
|
| 977 |
+
elif obj.op is Op.INTEGER:
|
| 978 |
+
return Expr(Op.REAL, (float(obj.data[0]), kind))
|
| 979 |
+
raise OpError(f'cannot convert {obj} to REAL constant')
|
| 980 |
+
|
| 981 |
+
|
| 982 |
+
def as_string(obj, kind=1):
|
| 983 |
+
"""Return object as STRING expression (string literal constant).
|
| 984 |
+
"""
|
| 985 |
+
return Expr(Op.STRING, (obj, kind))
|
| 986 |
+
|
| 987 |
+
|
| 988 |
+
def as_array(obj):
|
| 989 |
+
"""Return object as ARRAY expression (array constant).
|
| 990 |
+
"""
|
| 991 |
+
if isinstance(obj, Expr):
|
| 992 |
+
obj = obj,
|
| 993 |
+
return Expr(Op.ARRAY, obj)
|
| 994 |
+
|
| 995 |
+
|
| 996 |
+
def as_complex(real, imag=0):
|
| 997 |
+
"""Return object as COMPLEX expression (complex literal constant).
|
| 998 |
+
"""
|
| 999 |
+
return Expr(Op.COMPLEX, (as_expr(real), as_expr(imag)))
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
def as_apply(func, *args, **kwargs):
|
| 1003 |
+
"""Return object as APPLY expression (function call, constructor, etc.)
|
| 1004 |
+
"""
|
| 1005 |
+
return Expr(Op.APPLY,
|
| 1006 |
+
(func, tuple(map(as_expr, args)),
|
| 1007 |
+
dict((k, as_expr(v)) for k, v in kwargs.items())))
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
def as_ternary(cond, expr1, expr2):
|
| 1011 |
+
"""Return object as TERNARY expression (cond?expr1:expr2).
|
| 1012 |
+
"""
|
| 1013 |
+
return Expr(Op.TERNARY, (cond, expr1, expr2))
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
def as_ref(expr):
|
| 1017 |
+
"""Return object as referencing expression.
|
| 1018 |
+
"""
|
| 1019 |
+
return Expr(Op.REF, expr)
|
| 1020 |
+
|
| 1021 |
+
|
| 1022 |
+
def as_deref(expr):
|
| 1023 |
+
"""Return object as dereferencing expression.
|
| 1024 |
+
"""
|
| 1025 |
+
return Expr(Op.DEREF, expr)
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
def as_eq(left, right):
|
| 1029 |
+
return Expr(Op.RELATIONAL, (RelOp.EQ, left, right))
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
def as_ne(left, right):
|
| 1033 |
+
return Expr(Op.RELATIONAL, (RelOp.NE, left, right))
|
| 1034 |
+
|
| 1035 |
+
|
| 1036 |
+
def as_lt(left, right):
|
| 1037 |
+
return Expr(Op.RELATIONAL, (RelOp.LT, left, right))
|
| 1038 |
+
|
| 1039 |
+
|
| 1040 |
+
def as_le(left, right):
|
| 1041 |
+
return Expr(Op.RELATIONAL, (RelOp.LE, left, right))
|
| 1042 |
+
|
| 1043 |
+
|
| 1044 |
+
def as_gt(left, right):
|
| 1045 |
+
return Expr(Op.RELATIONAL, (RelOp.GT, left, right))
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
def as_ge(left, right):
|
| 1049 |
+
return Expr(Op.RELATIONAL, (RelOp.GE, left, right))
|
| 1050 |
+
|
| 1051 |
+
|
| 1052 |
+
def as_terms(obj):
|
| 1053 |
+
"""Return expression as TERMS expression.
|
| 1054 |
+
"""
|
| 1055 |
+
if isinstance(obj, Expr):
|
| 1056 |
+
obj = normalize(obj)
|
| 1057 |
+
if obj.op is Op.TERMS:
|
| 1058 |
+
return obj
|
| 1059 |
+
if obj.op is Op.INTEGER:
|
| 1060 |
+
return Expr(Op.TERMS, {as_integer(1, obj.data[1]): obj.data[0]})
|
| 1061 |
+
if obj.op is Op.REAL:
|
| 1062 |
+
return Expr(Op.TERMS, {as_real(1, obj.data[1]): obj.data[0]})
|
| 1063 |
+
return Expr(Op.TERMS, {obj: 1})
|
| 1064 |
+
raise OpError(f'cannot convert {type(obj)} to terms Expr')
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
def as_factors(obj):
|
| 1068 |
+
"""Return expression as FACTORS expression.
|
| 1069 |
+
"""
|
| 1070 |
+
if isinstance(obj, Expr):
|
| 1071 |
+
obj = normalize(obj)
|
| 1072 |
+
if obj.op is Op.FACTORS:
|
| 1073 |
+
return obj
|
| 1074 |
+
if obj.op is Op.TERMS:
|
| 1075 |
+
if len(obj.data) == 1:
|
| 1076 |
+
(term, coeff), = obj.data.items()
|
| 1077 |
+
if coeff == 1:
|
| 1078 |
+
return Expr(Op.FACTORS, {term: 1})
|
| 1079 |
+
return Expr(Op.FACTORS, {term: 1, Expr.number(coeff): 1})
|
| 1080 |
+
if ((obj.op is Op.APPLY
|
| 1081 |
+
and obj.data[0] is ArithOp.DIV
|
| 1082 |
+
and not obj.data[2])):
|
| 1083 |
+
return Expr(Op.FACTORS, {obj.data[1][0]: 1, obj.data[1][1]: -1})
|
| 1084 |
+
return Expr(Op.FACTORS, {obj: 1})
|
| 1085 |
+
raise OpError(f'cannot convert {type(obj)} to terms Expr')
|
| 1086 |
+
|
| 1087 |
+
|
| 1088 |
+
def as_term_coeff(obj):
|
| 1089 |
+
"""Return expression as term-coefficient pair.
|
| 1090 |
+
"""
|
| 1091 |
+
if isinstance(obj, Expr):
|
| 1092 |
+
obj = normalize(obj)
|
| 1093 |
+
if obj.op is Op.INTEGER:
|
| 1094 |
+
return as_integer(1, obj.data[1]), obj.data[0]
|
| 1095 |
+
if obj.op is Op.REAL:
|
| 1096 |
+
return as_real(1, obj.data[1]), obj.data[0]
|
| 1097 |
+
if obj.op is Op.TERMS:
|
| 1098 |
+
if len(obj.data) == 1:
|
| 1099 |
+
(term, coeff), = obj.data.items()
|
| 1100 |
+
return term, coeff
|
| 1101 |
+
# TODO: find common divisor of coefficients
|
| 1102 |
+
if obj.op is Op.APPLY and obj.data[0] is ArithOp.DIV:
|
| 1103 |
+
t, c = as_term_coeff(obj.data[1][0])
|
| 1104 |
+
return as_apply(ArithOp.DIV, t, obj.data[1][1]), c
|
| 1105 |
+
return obj, 1
|
| 1106 |
+
raise OpError(f'cannot convert {type(obj)} to term and coeff')
|
| 1107 |
+
|
| 1108 |
+
|
| 1109 |
+
def as_numer_denom(obj):
|
| 1110 |
+
"""Return expression as numer-denom pair.
|
| 1111 |
+
"""
|
| 1112 |
+
if isinstance(obj, Expr):
|
| 1113 |
+
obj = normalize(obj)
|
| 1114 |
+
if obj.op in (Op.INTEGER, Op.REAL, Op.COMPLEX, Op.SYMBOL,
|
| 1115 |
+
Op.INDEXING, Op.TERNARY):
|
| 1116 |
+
return obj, as_number(1)
|
| 1117 |
+
elif obj.op is Op.APPLY:
|
| 1118 |
+
if obj.data[0] is ArithOp.DIV and not obj.data[2]:
|
| 1119 |
+
numers, denoms = map(as_numer_denom, obj.data[1])
|
| 1120 |
+
return numers[0] * denoms[1], numers[1] * denoms[0]
|
| 1121 |
+
return obj, as_number(1)
|
| 1122 |
+
elif obj.op is Op.TERMS:
|
| 1123 |
+
numers, denoms = [], []
|
| 1124 |
+
for term, coeff in obj.data.items():
|
| 1125 |
+
n, d = as_numer_denom(term)
|
| 1126 |
+
n = n * coeff
|
| 1127 |
+
numers.append(n)
|
| 1128 |
+
denoms.append(d)
|
| 1129 |
+
numer, denom = as_number(0), as_number(1)
|
| 1130 |
+
for i in range(len(numers)):
|
| 1131 |
+
n = numers[i]
|
| 1132 |
+
for j in range(len(numers)):
|
| 1133 |
+
if i != j:
|
| 1134 |
+
n *= denoms[j]
|
| 1135 |
+
numer += n
|
| 1136 |
+
denom *= denoms[i]
|
| 1137 |
+
if denom.op in (Op.INTEGER, Op.REAL) and denom.data[0] < 0:
|
| 1138 |
+
numer, denom = -numer, -denom
|
| 1139 |
+
return numer, denom
|
| 1140 |
+
elif obj.op is Op.FACTORS:
|
| 1141 |
+
numer, denom = as_number(1), as_number(1)
|
| 1142 |
+
for b, e in obj.data.items():
|
| 1143 |
+
bnumer, bdenom = as_numer_denom(b)
|
| 1144 |
+
if e > 0:
|
| 1145 |
+
numer *= bnumer ** e
|
| 1146 |
+
denom *= bdenom ** e
|
| 1147 |
+
elif e < 0:
|
| 1148 |
+
numer *= bdenom ** (-e)
|
| 1149 |
+
denom *= bnumer ** (-e)
|
| 1150 |
+
return numer, denom
|
| 1151 |
+
raise OpError(f'cannot convert {type(obj)} to numer and denom')
|
| 1152 |
+
|
| 1153 |
+
|
| 1154 |
+
def _counter():
|
| 1155 |
+
# Used internally to generate unique dummy symbols
|
| 1156 |
+
counter = 0
|
| 1157 |
+
while True:
|
| 1158 |
+
counter += 1
|
| 1159 |
+
yield counter
|
| 1160 |
+
|
| 1161 |
+
|
| 1162 |
+
COUNTER = _counter()
|
| 1163 |
+
|
| 1164 |
+
|
| 1165 |
+
def eliminate_quotes(s):
|
| 1166 |
+
"""Replace quoted substrings of input string.
|
| 1167 |
+
|
| 1168 |
+
Return a new string and a mapping of replacements.
|
| 1169 |
+
"""
|
| 1170 |
+
d = {}
|
| 1171 |
+
|
| 1172 |
+
def repl(m):
|
| 1173 |
+
kind, value = m.groups()[:2]
|
| 1174 |
+
if kind:
|
| 1175 |
+
# remove trailing underscore
|
| 1176 |
+
kind = kind[:-1]
|
| 1177 |
+
p = {"'": "SINGLE", '"': "DOUBLE"}[value[0]]
|
| 1178 |
+
k = f'{kind}@__f2py_QUOTES_{p}_{COUNTER.__next__()}@'
|
| 1179 |
+
d[k] = value
|
| 1180 |
+
return k
|
| 1181 |
+
|
| 1182 |
+
new_s = re.sub(r'({kind}_|)({single_quoted}|{double_quoted})'.format(
|
| 1183 |
+
kind=r'\w[\w\d_]*',
|
| 1184 |
+
single_quoted=r"('([^'\\]|(\\.))*')",
|
| 1185 |
+
double_quoted=r'("([^"\\]|(\\.))*")'),
|
| 1186 |
+
repl, s)
|
| 1187 |
+
|
| 1188 |
+
assert '"' not in new_s
|
| 1189 |
+
assert "'" not in new_s
|
| 1190 |
+
|
| 1191 |
+
return new_s, d
|
| 1192 |
+
|
| 1193 |
+
|
| 1194 |
+
def insert_quotes(s, d):
|
| 1195 |
+
"""Inverse of eliminate_quotes.
|
| 1196 |
+
"""
|
| 1197 |
+
for k, v in d.items():
|
| 1198 |
+
kind = k[:k.find('@')]
|
| 1199 |
+
if kind:
|
| 1200 |
+
kind += '_'
|
| 1201 |
+
s = s.replace(k, kind + v)
|
| 1202 |
+
return s
|
| 1203 |
+
|
| 1204 |
+
|
| 1205 |
+
def replace_parenthesis(s):
|
| 1206 |
+
"""Replace substrings of input that are enclosed in parenthesis.
|
| 1207 |
+
|
| 1208 |
+
Return a new string and a mapping of replacements.
|
| 1209 |
+
"""
|
| 1210 |
+
# Find a parenthesis pair that appears first.
|
| 1211 |
+
|
| 1212 |
+
# Fortran deliminator are `(`, `)`, `[`, `]`, `(/', '/)`, `/`.
|
| 1213 |
+
# We don't handle `/` deliminator because it is not a part of an
|
| 1214 |
+
# expression.
|
| 1215 |
+
left, right = None, None
|
| 1216 |
+
mn_i = len(s)
|
| 1217 |
+
for left_, right_ in (('(/', '/)'),
|
| 1218 |
+
'()',
|
| 1219 |
+
'{}', # to support C literal structs
|
| 1220 |
+
'[]'):
|
| 1221 |
+
i = s.find(left_)
|
| 1222 |
+
if i == -1:
|
| 1223 |
+
continue
|
| 1224 |
+
if i < mn_i:
|
| 1225 |
+
mn_i = i
|
| 1226 |
+
left, right = left_, right_
|
| 1227 |
+
|
| 1228 |
+
if left is None:
|
| 1229 |
+
return s, {}
|
| 1230 |
+
|
| 1231 |
+
i = mn_i
|
| 1232 |
+
j = s.find(right, i)
|
| 1233 |
+
|
| 1234 |
+
while s.count(left, i + 1, j) != s.count(right, i + 1, j):
|
| 1235 |
+
j = s.find(right, j + 1)
|
| 1236 |
+
if j == -1:
|
| 1237 |
+
raise ValueError(f'Mismatch of {left+right} parenthesis in {s!r}')
|
| 1238 |
+
|
| 1239 |
+
p = {'(': 'ROUND', '[': 'SQUARE', '{': 'CURLY', '(/': 'ROUNDDIV'}[left]
|
| 1240 |
+
|
| 1241 |
+
k = f'@__f2py_PARENTHESIS_{p}_{COUNTER.__next__()}@'
|
| 1242 |
+
v = s[i+len(left):j]
|
| 1243 |
+
r, d = replace_parenthesis(s[j+len(right):])
|
| 1244 |
+
d[k] = v
|
| 1245 |
+
return s[:i] + k + r, d
|
| 1246 |
+
|
| 1247 |
+
|
| 1248 |
+
def _get_parenthesis_kind(s):
|
| 1249 |
+
assert s.startswith('@__f2py_PARENTHESIS_'), s
|
| 1250 |
+
return s.split('_')[4]
|
| 1251 |
+
|
| 1252 |
+
|
| 1253 |
+
def unreplace_parenthesis(s, d):
|
| 1254 |
+
"""Inverse of replace_parenthesis.
|
| 1255 |
+
"""
|
| 1256 |
+
for k, v in d.items():
|
| 1257 |
+
p = _get_parenthesis_kind(k)
|
| 1258 |
+
left = dict(ROUND='(', SQUARE='[', CURLY='{', ROUNDDIV='(/')[p]
|
| 1259 |
+
right = dict(ROUND=')', SQUARE=']', CURLY='}', ROUNDDIV='/)')[p]
|
| 1260 |
+
s = s.replace(k, left + v + right)
|
| 1261 |
+
return s
|
| 1262 |
+
|
| 1263 |
+
|
| 1264 |
+
def fromstring(s, language=Language.C):
|
| 1265 |
+
"""Create an expression from a string.
|
| 1266 |
+
|
| 1267 |
+
This is a "lazy" parser, that is, only arithmetic operations are
|
| 1268 |
+
resolved, non-arithmetic operations are treated as symbols.
|
| 1269 |
+
"""
|
| 1270 |
+
r = _FromStringWorker(language=language).parse(s)
|
| 1271 |
+
if isinstance(r, Expr):
|
| 1272 |
+
return r
|
| 1273 |
+
raise ValueError(f'failed to parse `{s}` to Expr instance: got `{r}`')
|
| 1274 |
+
|
| 1275 |
+
|
| 1276 |
+
class _Pair:
|
| 1277 |
+
# Internal class to represent a pair of expressions
|
| 1278 |
+
|
| 1279 |
+
def __init__(self, left, right):
|
| 1280 |
+
self.left = left
|
| 1281 |
+
self.right = right
|
| 1282 |
+
|
| 1283 |
+
def substitute(self, symbols_map):
|
| 1284 |
+
left, right = self.left, self.right
|
| 1285 |
+
if isinstance(left, Expr):
|
| 1286 |
+
left = left.substitute(symbols_map)
|
| 1287 |
+
if isinstance(right, Expr):
|
| 1288 |
+
right = right.substitute(symbols_map)
|
| 1289 |
+
return _Pair(left, right)
|
| 1290 |
+
|
| 1291 |
+
def __repr__(self):
|
| 1292 |
+
return f'{type(self).__name__}({self.left}, {self.right})'
|
| 1293 |
+
|
| 1294 |
+
|
| 1295 |
+
class _FromStringWorker:
|
| 1296 |
+
|
| 1297 |
+
def __init__(self, language=Language.C):
|
| 1298 |
+
self.original = None
|
| 1299 |
+
self.quotes_map = None
|
| 1300 |
+
self.language = language
|
| 1301 |
+
|
| 1302 |
+
def finalize_string(self, s):
|
| 1303 |
+
return insert_quotes(s, self.quotes_map)
|
| 1304 |
+
|
| 1305 |
+
def parse(self, inp):
|
| 1306 |
+
self.original = inp
|
| 1307 |
+
unquoted, self.quotes_map = eliminate_quotes(inp)
|
| 1308 |
+
return self.process(unquoted)
|
| 1309 |
+
|
| 1310 |
+
def process(self, s, context='expr'):
|
| 1311 |
+
"""Parse string within the given context.
|
| 1312 |
+
|
| 1313 |
+
The context may define the result in case of ambiguous
|
| 1314 |
+
expressions. For instance, consider expressions `f(x, y)` and
|
| 1315 |
+
`(x, y) + (a, b)` where `f` is a function and pair `(x, y)`
|
| 1316 |
+
denotes complex number. Specifying context as "args" or
|
| 1317 |
+
"expr", the subexpression `(x, y)` will be parse to an
|
| 1318 |
+
argument list or to a complex number, respectively.
|
| 1319 |
+
"""
|
| 1320 |
+
if isinstance(s, (list, tuple)):
|
| 1321 |
+
return type(s)(self.process(s_, context) for s_ in s)
|
| 1322 |
+
|
| 1323 |
+
assert isinstance(s, str), (type(s), s)
|
| 1324 |
+
|
| 1325 |
+
# replace subexpressions in parenthesis with f2py @-names
|
| 1326 |
+
r, raw_symbols_map = replace_parenthesis(s)
|
| 1327 |
+
r = r.strip()
|
| 1328 |
+
|
| 1329 |
+
def restore(r):
|
| 1330 |
+
# restores subexpressions marked with f2py @-names
|
| 1331 |
+
if isinstance(r, (list, tuple)):
|
| 1332 |
+
return type(r)(map(restore, r))
|
| 1333 |
+
return unreplace_parenthesis(r, raw_symbols_map)
|
| 1334 |
+
|
| 1335 |
+
# comma-separated tuple
|
| 1336 |
+
if ',' in r:
|
| 1337 |
+
operands = restore(r.split(','))
|
| 1338 |
+
if context == 'args':
|
| 1339 |
+
return tuple(self.process(operands))
|
| 1340 |
+
if context == 'expr':
|
| 1341 |
+
if len(operands) == 2:
|
| 1342 |
+
# complex number literal
|
| 1343 |
+
return as_complex(*self.process(operands))
|
| 1344 |
+
raise NotImplementedError(
|
| 1345 |
+
f'parsing comma-separated list (context={context}): {r}')
|
| 1346 |
+
|
| 1347 |
+
# ternary operation
|
| 1348 |
+
m = re.match(r'\A([^?]+)[?]([^:]+)[:](.+)\Z', r)
|
| 1349 |
+
if m:
|
| 1350 |
+
assert context == 'expr', context
|
| 1351 |
+
oper, expr1, expr2 = restore(m.groups())
|
| 1352 |
+
oper = self.process(oper)
|
| 1353 |
+
expr1 = self.process(expr1)
|
| 1354 |
+
expr2 = self.process(expr2)
|
| 1355 |
+
return as_ternary(oper, expr1, expr2)
|
| 1356 |
+
|
| 1357 |
+
# relational expression
|
| 1358 |
+
if self.language is Language.Fortran:
|
| 1359 |
+
m = re.match(
|
| 1360 |
+
r'\A(.+)\s*[.](eq|ne|lt|le|gt|ge)[.]\s*(.+)\Z', r, re.I)
|
| 1361 |
+
else:
|
| 1362 |
+
m = re.match(
|
| 1363 |
+
r'\A(.+)\s*([=][=]|[!][=]|[<][=]|[<]|[>][=]|[>])\s*(.+)\Z', r)
|
| 1364 |
+
if m:
|
| 1365 |
+
left, rop, right = m.groups()
|
| 1366 |
+
if self.language is Language.Fortran:
|
| 1367 |
+
rop = '.' + rop + '.'
|
| 1368 |
+
left, right = self.process(restore((left, right)))
|
| 1369 |
+
rop = RelOp.fromstring(rop, language=self.language)
|
| 1370 |
+
return Expr(Op.RELATIONAL, (rop, left, right))
|
| 1371 |
+
|
| 1372 |
+
# keyword argument
|
| 1373 |
+
m = re.match(r'\A(\w[\w\d_]*)\s*[=](.*)\Z', r)
|
| 1374 |
+
if m:
|
| 1375 |
+
keyname, value = m.groups()
|
| 1376 |
+
value = restore(value)
|
| 1377 |
+
return _Pair(keyname, self.process(value))
|
| 1378 |
+
|
| 1379 |
+
# addition/subtraction operations
|
| 1380 |
+
operands = re.split(r'((?<!\d[edED])[+-])', r)
|
| 1381 |
+
if len(operands) > 1:
|
| 1382 |
+
result = self.process(restore(operands[0] or '0'))
|
| 1383 |
+
for op, operand in zip(operands[1::2], operands[2::2]):
|
| 1384 |
+
operand = self.process(restore(operand))
|
| 1385 |
+
op = op.strip()
|
| 1386 |
+
if op == '+':
|
| 1387 |
+
result += operand
|
| 1388 |
+
else:
|
| 1389 |
+
assert op == '-'
|
| 1390 |
+
result -= operand
|
| 1391 |
+
return result
|
| 1392 |
+
|
| 1393 |
+
# string concatenate operation
|
| 1394 |
+
if self.language is Language.Fortran and '//' in r:
|
| 1395 |
+
operands = restore(r.split('//'))
|
| 1396 |
+
return Expr(Op.CONCAT,
|
| 1397 |
+
tuple(self.process(operands)))
|
| 1398 |
+
|
| 1399 |
+
# multiplication/division operations
|
| 1400 |
+
operands = re.split(r'(?<=[@\w\d_])\s*([*]|/)',
|
| 1401 |
+
(r if self.language is Language.C
|
| 1402 |
+
else r.replace('**', '@__f2py_DOUBLE_STAR@')))
|
| 1403 |
+
if len(operands) > 1:
|
| 1404 |
+
operands = restore(operands)
|
| 1405 |
+
if self.language is not Language.C:
|
| 1406 |
+
operands = [operand.replace('@__f2py_DOUBLE_STAR@', '**')
|
| 1407 |
+
for operand in operands]
|
| 1408 |
+
# Expression is an arithmetic product
|
| 1409 |
+
result = self.process(operands[0])
|
| 1410 |
+
for op, operand in zip(operands[1::2], operands[2::2]):
|
| 1411 |
+
operand = self.process(operand)
|
| 1412 |
+
op = op.strip()
|
| 1413 |
+
if op == '*':
|
| 1414 |
+
result *= operand
|
| 1415 |
+
else:
|
| 1416 |
+
assert op == '/'
|
| 1417 |
+
result /= operand
|
| 1418 |
+
return result
|
| 1419 |
+
|
| 1420 |
+
# referencing/dereferencing
|
| 1421 |
+
if r.startswith('*') or r.startswith('&'):
|
| 1422 |
+
op = {'*': Op.DEREF, '&': Op.REF}[r[0]]
|
| 1423 |
+
operand = self.process(restore(r[1:]))
|
| 1424 |
+
return Expr(op, operand)
|
| 1425 |
+
|
| 1426 |
+
# exponentiation operations
|
| 1427 |
+
if self.language is not Language.C and '**' in r:
|
| 1428 |
+
operands = list(reversed(restore(r.split('**'))))
|
| 1429 |
+
result = self.process(operands[0])
|
| 1430 |
+
for operand in operands[1:]:
|
| 1431 |
+
operand = self.process(operand)
|
| 1432 |
+
result = operand ** result
|
| 1433 |
+
return result
|
| 1434 |
+
|
| 1435 |
+
# int-literal-constant
|
| 1436 |
+
m = re.match(r'\A({digit_string})({kind}|)\Z'.format(
|
| 1437 |
+
digit_string=r'\d+',
|
| 1438 |
+
kind=r'_(\d+|\w[\w\d_]*)'), r)
|
| 1439 |
+
if m:
|
| 1440 |
+
value, _, kind = m.groups()
|
| 1441 |
+
if kind and kind.isdigit():
|
| 1442 |
+
kind = int(kind)
|
| 1443 |
+
return as_integer(int(value), kind or 4)
|
| 1444 |
+
|
| 1445 |
+
# real-literal-constant
|
| 1446 |
+
m = re.match(r'\A({significant}({exponent}|)|\d+{exponent})({kind}|)\Z'
|
| 1447 |
+
.format(
|
| 1448 |
+
significant=r'[.]\d+|\d+[.]\d*',
|
| 1449 |
+
exponent=r'[edED][+-]?\d+',
|
| 1450 |
+
kind=r'_(\d+|\w[\w\d_]*)'), r)
|
| 1451 |
+
if m:
|
| 1452 |
+
value, _, _, kind = m.groups()
|
| 1453 |
+
if kind and kind.isdigit():
|
| 1454 |
+
kind = int(kind)
|
| 1455 |
+
value = value.lower()
|
| 1456 |
+
if 'd' in value:
|
| 1457 |
+
return as_real(float(value.replace('d', 'e')), kind or 8)
|
| 1458 |
+
return as_real(float(value), kind or 4)
|
| 1459 |
+
|
| 1460 |
+
# string-literal-constant with kind parameter specification
|
| 1461 |
+
if r in self.quotes_map:
|
| 1462 |
+
kind = r[:r.find('@')]
|
| 1463 |
+
return as_string(self.quotes_map[r], kind or 1)
|
| 1464 |
+
|
| 1465 |
+
# array constructor or literal complex constant or
|
| 1466 |
+
# parenthesized expression
|
| 1467 |
+
if r in raw_symbols_map:
|
| 1468 |
+
paren = _get_parenthesis_kind(r)
|
| 1469 |
+
items = self.process(restore(raw_symbols_map[r]),
|
| 1470 |
+
'expr' if paren == 'ROUND' else 'args')
|
| 1471 |
+
if paren == 'ROUND':
|
| 1472 |
+
if isinstance(items, Expr):
|
| 1473 |
+
return items
|
| 1474 |
+
if paren in ['ROUNDDIV', 'SQUARE']:
|
| 1475 |
+
# Expression is a array constructor
|
| 1476 |
+
if isinstance(items, Expr):
|
| 1477 |
+
items = (items,)
|
| 1478 |
+
return as_array(items)
|
| 1479 |
+
|
| 1480 |
+
# function call/indexing
|
| 1481 |
+
m = re.match(r'\A(.+)\s*(@__f2py_PARENTHESIS_(ROUND|SQUARE)_\d+@)\Z',
|
| 1482 |
+
r)
|
| 1483 |
+
if m:
|
| 1484 |
+
target, args, paren = m.groups()
|
| 1485 |
+
target = self.process(restore(target))
|
| 1486 |
+
args = self.process(restore(args)[1:-1], 'args')
|
| 1487 |
+
if not isinstance(args, tuple):
|
| 1488 |
+
args = args,
|
| 1489 |
+
if paren == 'ROUND':
|
| 1490 |
+
kwargs = dict((a.left, a.right) for a in args
|
| 1491 |
+
if isinstance(a, _Pair))
|
| 1492 |
+
args = tuple(a for a in args if not isinstance(a, _Pair))
|
| 1493 |
+
# Warning: this could also be Fortran indexing operation..
|
| 1494 |
+
return as_apply(target, *args, **kwargs)
|
| 1495 |
+
else:
|
| 1496 |
+
# Expression is a C/Python indexing operation
|
| 1497 |
+
# (e.g. used in .pyf files)
|
| 1498 |
+
assert paren == 'SQUARE'
|
| 1499 |
+
return target[args]
|
| 1500 |
+
|
| 1501 |
+
# Fortran standard conforming identifier
|
| 1502 |
+
m = re.match(r'\A\w[\w\d_]*\Z', r)
|
| 1503 |
+
if m:
|
| 1504 |
+
return as_symbol(r)
|
| 1505 |
+
|
| 1506 |
+
# fall-back to symbol
|
| 1507 |
+
r = self.finalize_string(restore(r))
|
| 1508 |
+
ewarn(
|
| 1509 |
+
f'fromstring: treating {r!r} as symbol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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import copy
|
| 4 |
+
import platform
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
from numpy.testing import assert_, assert_equal
|
| 10 |
+
from numpy.core.multiarray import typeinfo as _typeinfo
|
| 11 |
+
from . import util
|
| 12 |
+
|
| 13 |
+
wrap = None
|
| 14 |
+
|
| 15 |
+
# Extend core typeinfo with CHARACTER to test dtype('c')
|
| 16 |
+
_ti = _typeinfo['STRING']
|
| 17 |
+
typeinfo = dict(
|
| 18 |
+
CHARACTER=type(_ti)(('c', _ti.num, 8, _ti.alignment, _ti.type)),
|
| 19 |
+
**_typeinfo)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def setup_module():
|
| 23 |
+
"""
|
| 24 |
+
Build the required testing extension module
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
global wrap
|
| 28 |
+
|
| 29 |
+
# Check compiler availability first
|
| 30 |
+
if not util.has_c_compiler():
|
| 31 |
+
pytest.skip("No C compiler available")
|
| 32 |
+
|
| 33 |
+
if wrap is None:
|
| 34 |
+
config_code = """
|
| 35 |
+
config.add_extension('test_array_from_pyobj_ext',
|
| 36 |
+
sources=['wrapmodule.c', 'fortranobject.c'],
|
| 37 |
+
define_macros=[])
|
| 38 |
+
"""
|
| 39 |
+
d = os.path.dirname(__file__)
|
| 40 |
+
src = [
|
| 41 |
+
util.getpath("tests", "src", "array_from_pyobj", "wrapmodule.c"),
|
| 42 |
+
util.getpath("src", "fortranobject.c"),
|
| 43 |
+
util.getpath("src", "fortranobject.h"),
|
| 44 |
+
]
|
| 45 |
+
wrap = util.build_module_distutils(src, config_code,
|
| 46 |
+
"test_array_from_pyobj_ext")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def flags_info(arr):
|
| 50 |
+
flags = wrap.array_attrs(arr)[6]
|
| 51 |
+
return flags2names(flags)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def flags2names(flags):
|
| 55 |
+
info = []
|
| 56 |
+
for flagname in [
|
| 57 |
+
"CONTIGUOUS",
|
| 58 |
+
"FORTRAN",
|
| 59 |
+
"OWNDATA",
|
| 60 |
+
"ENSURECOPY",
|
| 61 |
+
"ENSUREARRAY",
|
| 62 |
+
"ALIGNED",
|
| 63 |
+
"NOTSWAPPED",
|
| 64 |
+
"WRITEABLE",
|
| 65 |
+
"WRITEBACKIFCOPY",
|
| 66 |
+
"UPDATEIFCOPY",
|
| 67 |
+
"BEHAVED",
|
| 68 |
+
"BEHAVED_RO",
|
| 69 |
+
"CARRAY",
|
| 70 |
+
"FARRAY",
|
| 71 |
+
]:
|
| 72 |
+
if abs(flags) & getattr(wrap, flagname, 0):
|
| 73 |
+
info.append(flagname)
|
| 74 |
+
return info
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class Intent:
|
| 78 |
+
def __init__(self, intent_list=[]):
|
| 79 |
+
self.intent_list = intent_list[:]
|
| 80 |
+
flags = 0
|
| 81 |
+
for i in intent_list:
|
| 82 |
+
if i == "optional":
|
| 83 |
+
flags |= wrap.F2PY_OPTIONAL
|
| 84 |
+
else:
|
| 85 |
+
flags |= getattr(wrap, "F2PY_INTENT_" + i.upper())
|
| 86 |
+
self.flags = flags
|
| 87 |
+
|
| 88 |
+
def __getattr__(self, name):
|
| 89 |
+
name = name.lower()
|
| 90 |
+
if name == "in_":
|
| 91 |
+
name = "in"
|
| 92 |
+
return self.__class__(self.intent_list + [name])
|
| 93 |
+
|
| 94 |
+
def __str__(self):
|
| 95 |
+
return "intent(%s)" % (",".join(self.intent_list))
|
| 96 |
+
|
| 97 |
+
def __repr__(self):
|
| 98 |
+
return "Intent(%r)" % (self.intent_list)
|
| 99 |
+
|
| 100 |
+
def is_intent(self, *names):
|
| 101 |
+
for name in names:
|
| 102 |
+
if name not in self.intent_list:
|
| 103 |
+
return False
|
| 104 |
+
return True
|
| 105 |
+
|
| 106 |
+
def is_intent_exact(self, *names):
|
| 107 |
+
return len(self.intent_list) == len(names) and self.is_intent(*names)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
intent = Intent()
|
| 111 |
+
|
| 112 |
+
_type_names = [
|
| 113 |
+
"BOOL",
|
| 114 |
+
"BYTE",
|
| 115 |
+
"UBYTE",
|
| 116 |
+
"SHORT",
|
| 117 |
+
"USHORT",
|
| 118 |
+
"INT",
|
| 119 |
+
"UINT",
|
| 120 |
+
"LONG",
|
| 121 |
+
"ULONG",
|
| 122 |
+
"LONGLONG",
|
| 123 |
+
"ULONGLONG",
|
| 124 |
+
"FLOAT",
|
| 125 |
+
"DOUBLE",
|
| 126 |
+
"CFLOAT",
|
| 127 |
+
"STRING1",
|
| 128 |
+
"STRING5",
|
| 129 |
+
"CHARACTER",
|
| 130 |
+
]
|
| 131 |
+
|
| 132 |
+
_cast_dict = {"BOOL": ["BOOL"]}
|
| 133 |
+
_cast_dict["BYTE"] = _cast_dict["BOOL"] + ["BYTE"]
|
| 134 |
+
_cast_dict["UBYTE"] = _cast_dict["BOOL"] + ["UBYTE"]
|
| 135 |
+
_cast_dict["BYTE"] = ["BYTE"]
|
| 136 |
+
_cast_dict["UBYTE"] = ["UBYTE"]
|
| 137 |
+
_cast_dict["SHORT"] = _cast_dict["BYTE"] + ["UBYTE", "SHORT"]
|
| 138 |
+
_cast_dict["USHORT"] = _cast_dict["UBYTE"] + ["BYTE", "USHORT"]
|
| 139 |
+
_cast_dict["INT"] = _cast_dict["SHORT"] + ["USHORT", "INT"]
|
| 140 |
+
_cast_dict["UINT"] = _cast_dict["USHORT"] + ["SHORT", "UINT"]
|
| 141 |
+
|
| 142 |
+
_cast_dict["LONG"] = _cast_dict["INT"] + ["LONG"]
|
| 143 |
+
_cast_dict["ULONG"] = _cast_dict["UINT"] + ["ULONG"]
|
| 144 |
+
|
| 145 |
+
_cast_dict["LONGLONG"] = _cast_dict["LONG"] + ["LONGLONG"]
|
| 146 |
+
_cast_dict["ULONGLONG"] = _cast_dict["ULONG"] + ["ULONGLONG"]
|
| 147 |
+
|
| 148 |
+
_cast_dict["FLOAT"] = _cast_dict["SHORT"] + ["USHORT", "FLOAT"]
|
| 149 |
+
_cast_dict["DOUBLE"] = _cast_dict["INT"] + ["UINT", "FLOAT", "DOUBLE"]
|
| 150 |
+
|
| 151 |
+
_cast_dict["CFLOAT"] = _cast_dict["FLOAT"] + ["CFLOAT"]
|
| 152 |
+
|
| 153 |
+
_cast_dict['STRING1'] = ['STRING1']
|
| 154 |
+
_cast_dict['STRING5'] = ['STRING5']
|
| 155 |
+
_cast_dict['CHARACTER'] = ['CHARACTER']
|
| 156 |
+
|
| 157 |
+
# 32 bit system malloc typically does not provide the alignment required by
|
| 158 |
+
# 16 byte long double types this means the inout intent cannot be satisfied
|
| 159 |
+
# and several tests fail as the alignment flag can be randomly true or fals
|
| 160 |
+
# when numpy gains an aligned allocator the tests could be enabled again
|
| 161 |
+
#
|
| 162 |
+
# Furthermore, on macOS ARM64, LONGDOUBLE is an alias for DOUBLE.
|
| 163 |
+
if ((np.intp().dtype.itemsize != 4 or np.clongdouble().dtype.alignment <= 8)
|
| 164 |
+
and sys.platform != "win32"
|
| 165 |
+
and (platform.system(), platform.processor()) != ("Darwin", "arm")):
|
| 166 |
+
_type_names.extend(["LONGDOUBLE", "CDOUBLE", "CLONGDOUBLE"])
|
| 167 |
+
_cast_dict["LONGDOUBLE"] = _cast_dict["LONG"] + [
|
| 168 |
+
"ULONG",
|
| 169 |
+
"FLOAT",
|
| 170 |
+
"DOUBLE",
|
| 171 |
+
"LONGDOUBLE",
|
| 172 |
+
]
|
| 173 |
+
_cast_dict["CLONGDOUBLE"] = _cast_dict["LONGDOUBLE"] + [
|
| 174 |
+
"CFLOAT",
|
| 175 |
+
"CDOUBLE",
|
| 176 |
+
"CLONGDOUBLE",
|
| 177 |
+
]
|
| 178 |
+
_cast_dict["CDOUBLE"] = _cast_dict["DOUBLE"] + ["CFLOAT", "CDOUBLE"]
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class Type:
|
| 182 |
+
_type_cache = {}
|
| 183 |
+
|
| 184 |
+
def __new__(cls, name):
|
| 185 |
+
if isinstance(name, np.dtype):
|
| 186 |
+
dtype0 = name
|
| 187 |
+
name = None
|
| 188 |
+
for n, i in typeinfo.items():
|
| 189 |
+
if not isinstance(i, type) and dtype0.type is i.type:
|
| 190 |
+
name = n
|
| 191 |
+
break
|
| 192 |
+
obj = cls._type_cache.get(name.upper(), None)
|
| 193 |
+
if obj is not None:
|
| 194 |
+
return obj
|
| 195 |
+
obj = object.__new__(cls)
|
| 196 |
+
obj._init(name)
|
| 197 |
+
cls._type_cache[name.upper()] = obj
|
| 198 |
+
return obj
|
| 199 |
+
|
| 200 |
+
def _init(self, name):
|
| 201 |
+
self.NAME = name.upper()
|
| 202 |
+
|
| 203 |
+
if self.NAME == 'CHARACTER':
|
| 204 |
+
info = typeinfo[self.NAME]
|
| 205 |
+
self.type_num = getattr(wrap, 'NPY_STRING')
|
| 206 |
+
self.elsize = 1
|
| 207 |
+
self.dtype = np.dtype('c')
|
| 208 |
+
elif self.NAME.startswith('STRING'):
|
| 209 |
+
info = typeinfo[self.NAME[:6]]
|
| 210 |
+
self.type_num = getattr(wrap, 'NPY_STRING')
|
| 211 |
+
self.elsize = int(self.NAME[6:] or 0)
|
| 212 |
+
self.dtype = np.dtype(f'S{self.elsize}')
|
| 213 |
+
else:
|
| 214 |
+
info = typeinfo[self.NAME]
|
| 215 |
+
self.type_num = getattr(wrap, 'NPY_' + self.NAME)
|
| 216 |
+
self.elsize = info.bits // 8
|
| 217 |
+
self.dtype = np.dtype(info.type)
|
| 218 |
+
|
| 219 |
+
assert self.type_num == info.num
|
| 220 |
+
self.type = info.type
|
| 221 |
+
self.dtypechar = info.char
|
| 222 |
+
|
| 223 |
+
def __repr__(self):
|
| 224 |
+
return (f"Type({self.NAME})|type_num={self.type_num},"
|
| 225 |
+
f" dtype={self.dtype},"
|
| 226 |
+
f" type={self.type}, elsize={self.elsize},"
|
| 227 |
+
f" dtypechar={self.dtypechar}")
|
| 228 |
+
|
| 229 |
+
def cast_types(self):
|
| 230 |
+
return [self.__class__(_m) for _m in _cast_dict[self.NAME]]
|
| 231 |
+
|
| 232 |
+
def all_types(self):
|
| 233 |
+
return [self.__class__(_m) for _m in _type_names]
|
| 234 |
+
|
| 235 |
+
def smaller_types(self):
|
| 236 |
+
bits = typeinfo[self.NAME].alignment
|
| 237 |
+
types = []
|
| 238 |
+
for name in _type_names:
|
| 239 |
+
if typeinfo[name].alignment < bits:
|
| 240 |
+
types.append(Type(name))
|
| 241 |
+
return types
|
| 242 |
+
|
| 243 |
+
def equal_types(self):
|
| 244 |
+
bits = typeinfo[self.NAME].alignment
|
| 245 |
+
types = []
|
| 246 |
+
for name in _type_names:
|
| 247 |
+
if name == self.NAME:
|
| 248 |
+
continue
|
| 249 |
+
if typeinfo[name].alignment == bits:
|
| 250 |
+
types.append(Type(name))
|
| 251 |
+
return types
|
| 252 |
+
|
| 253 |
+
def larger_types(self):
|
| 254 |
+
bits = typeinfo[self.NAME].alignment
|
| 255 |
+
types = []
|
| 256 |
+
for name in _type_names:
|
| 257 |
+
if typeinfo[name].alignment > bits:
|
| 258 |
+
types.append(Type(name))
|
| 259 |
+
return types
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
class Array:
|
| 263 |
+
|
| 264 |
+
def __repr__(self):
|
| 265 |
+
return (f'Array({self.type}, {self.dims}, {self.intent},'
|
| 266 |
+
f' {self.obj})|arr={self.arr}')
|
| 267 |
+
|
| 268 |
+
def __init__(self, typ, dims, intent, obj):
|
| 269 |
+
self.type = typ
|
| 270 |
+
self.dims = dims
|
| 271 |
+
self.intent = intent
|
| 272 |
+
self.obj_copy = copy.deepcopy(obj)
|
| 273 |
+
self.obj = obj
|
| 274 |
+
|
| 275 |
+
# arr.dtypechar may be different from typ.dtypechar
|
| 276 |
+
self.arr = wrap.call(typ.type_num,
|
| 277 |
+
typ.elsize,
|
| 278 |
+
dims, intent.flags, obj)
|
| 279 |
+
|
| 280 |
+
assert isinstance(self.arr, np.ndarray)
|
| 281 |
+
|
| 282 |
+
self.arr_attr = wrap.array_attrs(self.arr)
|
| 283 |
+
|
| 284 |
+
if len(dims) > 1:
|
| 285 |
+
if self.intent.is_intent("c"):
|
| 286 |
+
assert (intent.flags & wrap.F2PY_INTENT_C)
|
| 287 |
+
assert not self.arr.flags["FORTRAN"]
|
| 288 |
+
assert self.arr.flags["CONTIGUOUS"]
|
| 289 |
+
assert (not self.arr_attr[6] & wrap.FORTRAN)
|
| 290 |
+
else:
|
| 291 |
+
assert (not intent.flags & wrap.F2PY_INTENT_C)
|
| 292 |
+
assert self.arr.flags["FORTRAN"]
|
| 293 |
+
assert not self.arr.flags["CONTIGUOUS"]
|
| 294 |
+
assert (self.arr_attr[6] & wrap.FORTRAN)
|
| 295 |
+
|
| 296 |
+
if obj is None:
|
| 297 |
+
self.pyarr = None
|
| 298 |
+
self.pyarr_attr = None
|
| 299 |
+
return
|
| 300 |
+
|
| 301 |
+
if intent.is_intent("cache"):
|
| 302 |
+
assert isinstance(obj, np.ndarray), repr(type(obj))
|
| 303 |
+
self.pyarr = np.array(obj).reshape(*dims).copy()
|
| 304 |
+
else:
|
| 305 |
+
self.pyarr = np.array(
|
| 306 |
+
np.array(obj, dtype=typ.dtypechar).reshape(*dims),
|
| 307 |
+
order=self.intent.is_intent("c") and "C" or "F",
|
| 308 |
+
)
|
| 309 |
+
assert self.pyarr.dtype == typ
|
| 310 |
+
self.pyarr.setflags(write=self.arr.flags["WRITEABLE"])
|
| 311 |
+
assert self.pyarr.flags["OWNDATA"], (obj, intent)
|
| 312 |
+
self.pyarr_attr = wrap.array_attrs(self.pyarr)
|
| 313 |
+
|
| 314 |
+
if len(dims) > 1:
|
| 315 |
+
if self.intent.is_intent("c"):
|
| 316 |
+
assert not self.pyarr.flags["FORTRAN"]
|
| 317 |
+
assert self.pyarr.flags["CONTIGUOUS"]
|
| 318 |
+
assert (not self.pyarr_attr[6] & wrap.FORTRAN)
|
| 319 |
+
else:
|
| 320 |
+
assert self.pyarr.flags["FORTRAN"]
|
| 321 |
+
assert not self.pyarr.flags["CONTIGUOUS"]
|
| 322 |
+
assert (self.pyarr_attr[6] & wrap.FORTRAN)
|
| 323 |
+
|
| 324 |
+
assert self.arr_attr[1] == self.pyarr_attr[1] # nd
|
| 325 |
+
assert self.arr_attr[2] == self.pyarr_attr[2] # dimensions
|
| 326 |
+
if self.arr_attr[1] <= 1:
|
| 327 |
+
assert self.arr_attr[3] == self.pyarr_attr[3], repr((
|
| 328 |
+
self.arr_attr[3],
|
| 329 |
+
self.pyarr_attr[3],
|
| 330 |
+
self.arr.tobytes(),
|
| 331 |
+
self.pyarr.tobytes(),
|
| 332 |
+
)) # strides
|
| 333 |
+
assert self.arr_attr[5][-2:] == self.pyarr_attr[5][-2:], repr((
|
| 334 |
+
self.arr_attr[5], self.pyarr_attr[5]
|
| 335 |
+
)) # descr
|
| 336 |
+
assert self.arr_attr[6] == self.pyarr_attr[6], repr((
|
| 337 |
+
self.arr_attr[6],
|
| 338 |
+
self.pyarr_attr[6],
|
| 339 |
+
flags2names(0 * self.arr_attr[6] - self.pyarr_attr[6]),
|
| 340 |
+
flags2names(self.arr_attr[6]),
|
| 341 |
+
intent,
|
| 342 |
+
)) # flags
|
| 343 |
+
|
| 344 |
+
if intent.is_intent("cache"):
|
| 345 |
+
assert self.arr_attr[5][3] >= self.type.elsize
|
| 346 |
+
else:
|
| 347 |
+
assert self.arr_attr[5][3] == self.type.elsize
|
| 348 |
+
assert (self.arr_equal(self.pyarr, self.arr))
|
| 349 |
+
|
| 350 |
+
if isinstance(self.obj, np.ndarray):
|
| 351 |
+
if typ.elsize == Type(obj.dtype).elsize:
|
| 352 |
+
if not intent.is_intent("copy") and self.arr_attr[1] <= 1:
|
| 353 |
+
assert self.has_shared_memory()
|
| 354 |
+
|
| 355 |
+
def arr_equal(self, arr1, arr2):
|
| 356 |
+
if arr1.shape != arr2.shape:
|
| 357 |
+
return False
|
| 358 |
+
return (arr1 == arr2).all()
|
| 359 |
+
|
| 360 |
+
def __str__(self):
|
| 361 |
+
return str(self.arr)
|
| 362 |
+
|
| 363 |
+
def has_shared_memory(self):
|
| 364 |
+
"""Check that created array shares data with input array."""
|
| 365 |
+
if self.obj is self.arr:
|
| 366 |
+
return True
|
| 367 |
+
if not isinstance(self.obj, np.ndarray):
|
| 368 |
+
return False
|
| 369 |
+
obj_attr = wrap.array_attrs(self.obj)
|
| 370 |
+
return obj_attr[0] == self.arr_attr[0]
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
class TestIntent:
|
| 374 |
+
def test_in_out(self):
|
| 375 |
+
assert str(intent.in_.out) == "intent(in,out)"
|
| 376 |
+
assert intent.in_.c.is_intent("c")
|
| 377 |
+
assert not intent.in_.c.is_intent_exact("c")
|
| 378 |
+
assert intent.in_.c.is_intent_exact("c", "in")
|
| 379 |
+
assert intent.in_.c.is_intent_exact("in", "c")
|
| 380 |
+
assert not intent.in_.is_intent("c")
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
class TestSharedMemory:
|
| 384 |
+
|
| 385 |
+
@pytest.fixture(autouse=True, scope="class", params=_type_names)
|
| 386 |
+
def setup_type(self, request):
|
| 387 |
+
request.cls.type = Type(request.param)
|
| 388 |
+
request.cls.array = lambda self, dims, intent, obj: Array(
|
| 389 |
+
Type(request.param), dims, intent, obj)
|
| 390 |
+
|
| 391 |
+
@property
|
| 392 |
+
def num2seq(self):
|
| 393 |
+
if self.type.NAME.startswith('STRING'):
|
| 394 |
+
elsize = self.type.elsize
|
| 395 |
+
return ['1' * elsize, '2' * elsize]
|
| 396 |
+
return [1, 2]
|
| 397 |
+
|
| 398 |
+
@property
|
| 399 |
+
def num23seq(self):
|
| 400 |
+
if self.type.NAME.startswith('STRING'):
|
| 401 |
+
elsize = self.type.elsize
|
| 402 |
+
return [['1' * elsize, '2' * elsize, '3' * elsize],
|
| 403 |
+
['4' * elsize, '5' * elsize, '6' * elsize]]
|
| 404 |
+
return [[1, 2, 3], [4, 5, 6]]
|
| 405 |
+
|
| 406 |
+
def test_in_from_2seq(self):
|
| 407 |
+
a = self.array([2], intent.in_, self.num2seq)
|
| 408 |
+
assert not a.has_shared_memory()
|
| 409 |
+
|
| 410 |
+
def test_in_from_2casttype(self):
|
| 411 |
+
for t in self.type.cast_types():
|
| 412 |
+
obj = np.array(self.num2seq, dtype=t.dtype)
|
| 413 |
+
a = self.array([len(self.num2seq)], intent.in_, obj)
|
| 414 |
+
if t.elsize == self.type.elsize:
|
| 415 |
+
assert a.has_shared_memory(), repr((self.type.dtype, t.dtype))
|
| 416 |
+
else:
|
| 417 |
+
assert not a.has_shared_memory()
|
| 418 |
+
|
| 419 |
+
@pytest.mark.parametrize("write", ["w", "ro"])
|
| 420 |
+
@pytest.mark.parametrize("order", ["C", "F"])
|
| 421 |
+
@pytest.mark.parametrize("inp", ["2seq", "23seq"])
|
| 422 |
+
def test_in_nocopy(self, write, order, inp):
|
| 423 |
+
"""Test if intent(in) array can be passed without copies"""
|
| 424 |
+
seq = getattr(self, "num" + inp)
|
| 425 |
+
obj = np.array(seq, dtype=self.type.dtype, order=order)
|
| 426 |
+
obj.setflags(write=(write == 'w'))
|
| 427 |
+
a = self.array(obj.shape,
|
| 428 |
+
((order == 'C' and intent.in_.c) or intent.in_), obj)
|
| 429 |
+
assert a.has_shared_memory()
|
| 430 |
+
|
| 431 |
+
def test_inout_2seq(self):
|
| 432 |
+
obj = np.array(self.num2seq, dtype=self.type.dtype)
|
| 433 |
+
a = self.array([len(self.num2seq)], intent.inout, obj)
|
| 434 |
+
assert a.has_shared_memory()
|
| 435 |
+
|
| 436 |
+
try:
|
| 437 |
+
a = self.array([2], intent.in_.inout, self.num2seq)
|
| 438 |
+
except TypeError as msg:
|
| 439 |
+
if not str(msg).startswith(
|
| 440 |
+
"failed to initialize intent(inout|inplace|cache) array"):
|
| 441 |
+
raise
|
| 442 |
+
else:
|
| 443 |
+
raise SystemError("intent(inout) should have failed on sequence")
|
| 444 |
+
|
| 445 |
+
def test_f_inout_23seq(self):
|
| 446 |
+
obj = np.array(self.num23seq, dtype=self.type.dtype, order="F")
|
| 447 |
+
shape = (len(self.num23seq), len(self.num23seq[0]))
|
| 448 |
+
a = self.array(shape, intent.in_.inout, obj)
|
| 449 |
+
assert a.has_shared_memory()
|
| 450 |
+
|
| 451 |
+
obj = np.array(self.num23seq, dtype=self.type.dtype, order="C")
|
| 452 |
+
shape = (len(self.num23seq), len(self.num23seq[0]))
|
| 453 |
+
try:
|
| 454 |
+
a = self.array(shape, intent.in_.inout, obj)
|
| 455 |
+
except ValueError as msg:
|
| 456 |
+
if not str(msg).startswith(
|
| 457 |
+
"failed to initialize intent(inout) array"):
|
| 458 |
+
raise
|
| 459 |
+
else:
|
| 460 |
+
raise SystemError(
|
| 461 |
+
"intent(inout) should have failed on improper array")
|
| 462 |
+
|
| 463 |
+
def test_c_inout_23seq(self):
|
| 464 |
+
obj = np.array(self.num23seq, dtype=self.type.dtype)
|
| 465 |
+
shape = (len(self.num23seq), len(self.num23seq[0]))
|
| 466 |
+
a = self.array(shape, intent.in_.c.inout, obj)
|
| 467 |
+
assert a.has_shared_memory()
|
| 468 |
+
|
| 469 |
+
def test_in_copy_from_2casttype(self):
|
| 470 |
+
for t in self.type.cast_types():
|
| 471 |
+
obj = np.array(self.num2seq, dtype=t.dtype)
|
| 472 |
+
a = self.array([len(self.num2seq)], intent.in_.copy, obj)
|
| 473 |
+
assert not a.has_shared_memory()
|
| 474 |
+
|
| 475 |
+
def test_c_in_from_23seq(self):
|
| 476 |
+
a = self.array(
|
| 477 |
+
[len(self.num23seq), len(self.num23seq[0])], intent.in_,
|
| 478 |
+
self.num23seq)
|
| 479 |
+
assert not a.has_shared_memory()
|
| 480 |
+
|
| 481 |
+
def test_in_from_23casttype(self):
|
| 482 |
+
for t in self.type.cast_types():
|
| 483 |
+
obj = np.array(self.num23seq, dtype=t.dtype)
|
| 484 |
+
a = self.array(
|
| 485 |
+
[len(self.num23seq), len(self.num23seq[0])], intent.in_, obj)
|
| 486 |
+
assert not a.has_shared_memory()
|
| 487 |
+
|
| 488 |
+
def test_f_in_from_23casttype(self):
|
| 489 |
+
for t in self.type.cast_types():
|
| 490 |
+
obj = np.array(self.num23seq, dtype=t.dtype, order="F")
|
| 491 |
+
a = self.array(
|
| 492 |
+
[len(self.num23seq), len(self.num23seq[0])], intent.in_, obj)
|
| 493 |
+
if t.elsize == self.type.elsize:
|
| 494 |
+
assert a.has_shared_memory()
|
| 495 |
+
else:
|
| 496 |
+
assert not a.has_shared_memory()
|
| 497 |
+
|
| 498 |
+
def test_c_in_from_23casttype(self):
|
| 499 |
+
for t in self.type.cast_types():
|
| 500 |
+
obj = np.array(self.num23seq, dtype=t.dtype)
|
| 501 |
+
a = self.array(
|
| 502 |
+
[len(self.num23seq), len(self.num23seq[0])], intent.in_.c, obj)
|
| 503 |
+
if t.elsize == self.type.elsize:
|
| 504 |
+
assert a.has_shared_memory()
|
| 505 |
+
else:
|
| 506 |
+
assert not a.has_shared_memory()
|
| 507 |
+
|
| 508 |
+
def test_f_copy_in_from_23casttype(self):
|
| 509 |
+
for t in self.type.cast_types():
|
| 510 |
+
obj = np.array(self.num23seq, dtype=t.dtype, order="F")
|
| 511 |
+
a = self.array(
|
| 512 |
+
[len(self.num23seq), len(self.num23seq[0])], intent.in_.copy,
|
| 513 |
+
obj)
|
| 514 |
+
assert not a.has_shared_memory()
|
| 515 |
+
|
| 516 |
+
def test_c_copy_in_from_23casttype(self):
|
| 517 |
+
for t in self.type.cast_types():
|
| 518 |
+
obj = np.array(self.num23seq, dtype=t.dtype)
|
| 519 |
+
a = self.array(
|
| 520 |
+
[len(self.num23seq), len(self.num23seq[0])], intent.in_.c.copy,
|
| 521 |
+
obj)
|
| 522 |
+
assert not a.has_shared_memory()
|
| 523 |
+
|
| 524 |
+
def test_in_cache_from_2casttype(self):
|
| 525 |
+
for t in self.type.all_types():
|
| 526 |
+
if t.elsize != self.type.elsize:
|
| 527 |
+
continue
|
| 528 |
+
obj = np.array(self.num2seq, dtype=t.dtype)
|
| 529 |
+
shape = (len(self.num2seq), )
|
| 530 |
+
a = self.array(shape, intent.in_.c.cache, obj)
|
| 531 |
+
assert a.has_shared_memory()
|
| 532 |
+
|
| 533 |
+
a = self.array(shape, intent.in_.cache, obj)
|
| 534 |
+
assert a.has_shared_memory()
|
| 535 |
+
|
| 536 |
+
obj = np.array(self.num2seq, dtype=t.dtype, order="F")
|
| 537 |
+
a = self.array(shape, intent.in_.c.cache, obj)
|
| 538 |
+
assert a.has_shared_memory()
|
| 539 |
+
|
| 540 |
+
a = self.array(shape, intent.in_.cache, obj)
|
| 541 |
+
assert a.has_shared_memory(), repr(t.dtype)
|
| 542 |
+
|
| 543 |
+
try:
|
| 544 |
+
a = self.array(shape, intent.in_.cache, obj[::-1])
|
| 545 |
+
except ValueError as msg:
|
| 546 |
+
if not str(msg).startswith(
|
| 547 |
+
"failed to initialize intent(cache) array"):
|
| 548 |
+
raise
|
| 549 |
+
else:
|
| 550 |
+
raise SystemError(
|
| 551 |
+
"intent(cache) should have failed on multisegmented array")
|
| 552 |
+
|
| 553 |
+
def test_in_cache_from_2casttype_failure(self):
|
| 554 |
+
for t in self.type.all_types():
|
| 555 |
+
if t.NAME == 'STRING':
|
| 556 |
+
# string elsize is 0, so skipping the test
|
| 557 |
+
continue
|
| 558 |
+
if t.elsize >= self.type.elsize:
|
| 559 |
+
continue
|
| 560 |
+
obj = np.array(self.num2seq, dtype=t.dtype)
|
| 561 |
+
shape = (len(self.num2seq), )
|
| 562 |
+
try:
|
| 563 |
+
self.array(shape, intent.in_.cache, obj) # Should succeed
|
| 564 |
+
except ValueError as msg:
|
| 565 |
+
if not str(msg).startswith(
|
| 566 |
+
"failed to initialize intent(cache) array"):
|
| 567 |
+
raise
|
| 568 |
+
else:
|
| 569 |
+
raise SystemError(
|
| 570 |
+
"intent(cache) should have failed on smaller array")
|
| 571 |
+
|
| 572 |
+
def test_cache_hidden(self):
|
| 573 |
+
shape = (2, )
|
| 574 |
+
a = self.array(shape, intent.cache.hide, None)
|
| 575 |
+
assert a.arr.shape == shape
|
| 576 |
+
|
| 577 |
+
shape = (2, 3)
|
| 578 |
+
a = self.array(shape, intent.cache.hide, None)
|
| 579 |
+
assert a.arr.shape == shape
|
| 580 |
+
|
| 581 |
+
shape = (-1, 3)
|
| 582 |
+
try:
|
| 583 |
+
a = self.array(shape, intent.cache.hide, None)
|
| 584 |
+
except ValueError as msg:
|
| 585 |
+
if not str(msg).startswith(
|
| 586 |
+
"failed to create intent(cache|hide)|optional array"):
|
| 587 |
+
raise
|
| 588 |
+
else:
|
| 589 |
+
raise SystemError(
|
| 590 |
+
"intent(cache) should have failed on undefined dimensions")
|
| 591 |
+
|
| 592 |
+
def test_hidden(self):
|
| 593 |
+
shape = (2, )
|
| 594 |
+
a = self.array(shape, intent.hide, None)
|
| 595 |
+
assert a.arr.shape == shape
|
| 596 |
+
assert a.arr_equal(a.arr, np.zeros(shape, dtype=self.type.dtype))
|
| 597 |
+
|
| 598 |
+
shape = (2, 3)
|
| 599 |
+
a = self.array(shape, intent.hide, None)
|
| 600 |
+
assert a.arr.shape == shape
|
| 601 |
+
assert a.arr_equal(a.arr, np.zeros(shape, dtype=self.type.dtype))
|
| 602 |
+
assert a.arr.flags["FORTRAN"] and not a.arr.flags["CONTIGUOUS"]
|
| 603 |
+
|
| 604 |
+
shape = (2, 3)
|
| 605 |
+
a = self.array(shape, intent.c.hide, None)
|
| 606 |
+
assert a.arr.shape == shape
|
| 607 |
+
assert a.arr_equal(a.arr, np.zeros(shape, dtype=self.type.dtype))
|
| 608 |
+
assert not a.arr.flags["FORTRAN"] and a.arr.flags["CONTIGUOUS"]
|
| 609 |
+
|
| 610 |
+
shape = (-1, 3)
|
| 611 |
+
try:
|
| 612 |
+
a = self.array(shape, intent.hide, None)
|
| 613 |
+
except ValueError as msg:
|
| 614 |
+
if not str(msg).startswith(
|
| 615 |
+
"failed to create intent(cache|hide)|optional array"):
|
| 616 |
+
raise
|
| 617 |
+
else:
|
| 618 |
+
raise SystemError(
|
| 619 |
+
"intent(hide) should have failed on undefined dimensions")
|
| 620 |
+
|
| 621 |
+
def test_optional_none(self):
|
| 622 |
+
shape = (2, )
|
| 623 |
+
a = self.array(shape, intent.optional, None)
|
| 624 |
+
assert a.arr.shape == shape
|
| 625 |
+
assert a.arr_equal(a.arr, np.zeros(shape, dtype=self.type.dtype))
|
| 626 |
+
|
| 627 |
+
shape = (2, 3)
|
| 628 |
+
a = self.array(shape, intent.optional, None)
|
| 629 |
+
assert a.arr.shape == shape
|
| 630 |
+
assert a.arr_equal(a.arr, np.zeros(shape, dtype=self.type.dtype))
|
| 631 |
+
assert a.arr.flags["FORTRAN"] and not a.arr.flags["CONTIGUOUS"]
|
| 632 |
+
|
| 633 |
+
shape = (2, 3)
|
| 634 |
+
a = self.array(shape, intent.c.optional, None)
|
| 635 |
+
assert a.arr.shape == shape
|
| 636 |
+
assert a.arr_equal(a.arr, np.zeros(shape, dtype=self.type.dtype))
|
| 637 |
+
assert not a.arr.flags["FORTRAN"] and a.arr.flags["CONTIGUOUS"]
|
| 638 |
+
|
| 639 |
+
def test_optional_from_2seq(self):
|
| 640 |
+
obj = self.num2seq
|
| 641 |
+
shape = (len(obj), )
|
| 642 |
+
a = self.array(shape, intent.optional, obj)
|
| 643 |
+
assert a.arr.shape == shape
|
| 644 |
+
assert not a.has_shared_memory()
|
| 645 |
+
|
| 646 |
+
def test_optional_from_23seq(self):
|
| 647 |
+
obj = self.num23seq
|
| 648 |
+
shape = (len(obj), len(obj[0]))
|
| 649 |
+
a = self.array(shape, intent.optional, obj)
|
| 650 |
+
assert a.arr.shape == shape
|
| 651 |
+
assert not a.has_shared_memory()
|
| 652 |
+
|
| 653 |
+
a = self.array(shape, intent.optional.c, obj)
|
| 654 |
+
assert a.arr.shape == shape
|
| 655 |
+
assert not a.has_shared_memory()
|
| 656 |
+
|
| 657 |
+
def test_inplace(self):
|
| 658 |
+
obj = np.array(self.num23seq, dtype=self.type.dtype)
|
| 659 |
+
assert not obj.flags["FORTRAN"] and obj.flags["CONTIGUOUS"]
|
| 660 |
+
shape = obj.shape
|
| 661 |
+
a = self.array(shape, intent.inplace, obj)
|
| 662 |
+
assert obj[1][2] == a.arr[1][2], repr((obj, a.arr))
|
| 663 |
+
a.arr[1][2] = 54
|
| 664 |
+
assert obj[1][2] == a.arr[1][2] == np.array(54, dtype=self.type.dtype)
|
| 665 |
+
assert a.arr is obj
|
| 666 |
+
assert obj.flags["FORTRAN"] # obj attributes are changed inplace!
|
| 667 |
+
assert not obj.flags["CONTIGUOUS"]
|
| 668 |
+
|
| 669 |
+
def test_inplace_from_casttype(self):
|
| 670 |
+
for t in self.type.cast_types():
|
| 671 |
+
if t is self.type:
|
| 672 |
+
continue
|
| 673 |
+
obj = np.array(self.num23seq, dtype=t.dtype)
|
| 674 |
+
assert obj.dtype.type == t.type
|
| 675 |
+
assert obj.dtype.type is not self.type.type
|
| 676 |
+
assert not obj.flags["FORTRAN"] and obj.flags["CONTIGUOUS"]
|
| 677 |
+
shape = obj.shape
|
| 678 |
+
a = self.array(shape, intent.inplace, obj)
|
| 679 |
+
assert obj[1][2] == a.arr[1][2], repr((obj, a.arr))
|
| 680 |
+
a.arr[1][2] = 54
|
| 681 |
+
assert obj[1][2] == a.arr[1][2] == np.array(54,
|
| 682 |
+
dtype=self.type.dtype)
|
| 683 |
+
assert a.arr is obj
|
| 684 |
+
assert obj.flags["FORTRAN"] # obj attributes changed inplace!
|
| 685 |
+
assert not obj.flags["CONTIGUOUS"]
|
| 686 |
+
assert obj.dtype.type is self.type.type # obj changed inplace!
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_assumed_shape.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
import tempfile
|
| 4 |
+
|
| 5 |
+
from . import util
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestAssumedShapeSumExample(util.F2PyTest):
|
| 9 |
+
sources = [
|
| 10 |
+
util.getpath("tests", "src", "assumed_shape", "foo_free.f90"),
|
| 11 |
+
util.getpath("tests", "src", "assumed_shape", "foo_use.f90"),
|
| 12 |
+
util.getpath("tests", "src", "assumed_shape", "precision.f90"),
|
| 13 |
+
util.getpath("tests", "src", "assumed_shape", "foo_mod.f90"),
|
| 14 |
+
util.getpath("tests", "src", "assumed_shape", ".f2py_f2cmap"),
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
@pytest.mark.slow
|
| 18 |
+
def test_all(self):
|
| 19 |
+
r = self.module.fsum([1, 2])
|
| 20 |
+
assert r == 3
|
| 21 |
+
r = self.module.sum([1, 2])
|
| 22 |
+
assert r == 3
|
| 23 |
+
r = self.module.sum_with_use([1, 2])
|
| 24 |
+
assert r == 3
|
| 25 |
+
|
| 26 |
+
r = self.module.mod.sum([1, 2])
|
| 27 |
+
assert r == 3
|
| 28 |
+
r = self.module.mod.fsum([1, 2])
|
| 29 |
+
assert r == 3
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class TestF2cmapOption(TestAssumedShapeSumExample):
|
| 33 |
+
def setup_method(self):
|
| 34 |
+
# Use a custom file name for .f2py_f2cmap
|
| 35 |
+
self.sources = list(self.sources)
|
| 36 |
+
f2cmap_src = self.sources.pop(-1)
|
| 37 |
+
|
| 38 |
+
self.f2cmap_file = tempfile.NamedTemporaryFile(delete=False)
|
| 39 |
+
with open(f2cmap_src, "rb") as f:
|
| 40 |
+
self.f2cmap_file.write(f.read())
|
| 41 |
+
self.f2cmap_file.close()
|
| 42 |
+
|
| 43 |
+
self.sources.append(self.f2cmap_file.name)
|
| 44 |
+
self.options = ["--f2cmap", self.f2cmap_file.name]
|
| 45 |
+
|
| 46 |
+
super().setup_method()
|
| 47 |
+
|
| 48 |
+
def teardown_method(self):
|
| 49 |
+
os.unlink(self.f2cmap_file.name)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_callback.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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S_PYPY
|
| 11 |
+
from . import util
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class TestF77Callback(util.F2PyTest):
|
| 15 |
+
sources = [util.getpath("tests", "src", "callback", "foo.f")]
|
| 16 |
+
|
| 17 |
+
@pytest.mark.parametrize("name", "t,t2".split(","))
|
| 18 |
+
def test_all(self, name):
|
| 19 |
+
self.check_function(name)
|
| 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 = t(fun,[fun_extra_args])
|
| 26 |
+
|
| 27 |
+
Wrapper for ``t``.
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
fun : call-back function
|
| 32 |
+
|
| 33 |
+
Other Parameters
|
| 34 |
+
----------------
|
| 35 |
+
fun_extra_args : input tuple, optional
|
| 36 |
+
Default: ()
|
| 37 |
+
|
| 38 |
+
Returns
|
| 39 |
+
-------
|
| 40 |
+
a : int
|
| 41 |
+
|
| 42 |
+
Notes
|
| 43 |
+
-----
|
| 44 |
+
Call-back functions::
|
| 45 |
+
|
| 46 |
+
def fun(): return a
|
| 47 |
+
Return objects:
|
| 48 |
+
a : int
|
| 49 |
+
""")
|
| 50 |
+
assert self.module.t.__doc__ == expected
|
| 51 |
+
|
| 52 |
+
def check_function(self, name):
|
| 53 |
+
t = getattr(self.module, name)
|
| 54 |
+
r = t(lambda: 4)
|
| 55 |
+
assert r == 4
|
| 56 |
+
r = t(lambda a: 5, fun_extra_args=(6, ))
|
| 57 |
+
assert r == 5
|
| 58 |
+
r = t(lambda a: a, fun_extra_args=(6, ))
|
| 59 |
+
assert r == 6
|
| 60 |
+
r = t(lambda a: 5 + a, fun_extra_args=(7, ))
|
| 61 |
+
assert r == 12
|
| 62 |
+
r = t(lambda a: math.degrees(a), fun_extra_args=(math.pi, ))
|
| 63 |
+
assert r == 180
|
| 64 |
+
r = t(math.degrees, fun_extra_args=(math.pi, ))
|
| 65 |
+
assert r == 180
|
| 66 |
+
|
| 67 |
+
r = t(self.module.func, fun_extra_args=(6, ))
|
| 68 |
+
assert r == 17
|
| 69 |
+
r = t(self.module.func0)
|
| 70 |
+
assert r == 11
|
| 71 |
+
r = t(self.module.func0._cpointer)
|
| 72 |
+
assert r == 11
|
| 73 |
+
|
| 74 |
+
class A:
|
| 75 |
+
def __call__(self):
|
| 76 |
+
return 7
|
| 77 |
+
|
| 78 |
+
def mth(self):
|
| 79 |
+
return 9
|
| 80 |
+
|
| 81 |
+
a = A()
|
| 82 |
+
r = t(a)
|
| 83 |
+
assert r == 7
|
| 84 |
+
r = t(a.mth)
|
| 85 |
+
assert r == 9
|
| 86 |
+
|
| 87 |
+
@pytest.mark.skipif(sys.platform == 'win32',
|
| 88 |
+
reason='Fails with MinGW64 Gfortran (Issue #9673)')
|
| 89 |
+
def test_string_callback(self):
|
| 90 |
+
def callback(code):
|
| 91 |
+
if code == "r":
|
| 92 |
+
return 0
|
| 93 |
+
else:
|
| 94 |
+
return 1
|
| 95 |
+
|
| 96 |
+
f = getattr(self.module, "string_callback")
|
| 97 |
+
r = f(callback)
|
| 98 |
+
assert r == 0
|
| 99 |
+
|
| 100 |
+
@pytest.mark.skipif(sys.platform == 'win32',
|
| 101 |
+
reason='Fails with MinGW64 Gfortran (Issue #9673)')
|
| 102 |
+
def test_string_callback_array(self):
|
| 103 |
+
# See gh-10027
|
| 104 |
+
cu1 = np.zeros((1, ), "S8")
|
| 105 |
+
cu2 = np.zeros((1, 8), "c")
|
| 106 |
+
cu3 = np.array([""], "S8")
|
| 107 |
+
|
| 108 |
+
def callback(cu, lencu):
|
| 109 |
+
if cu.shape != (lencu,):
|
| 110 |
+
return 1
|
| 111 |
+
if cu.dtype != "S8":
|
| 112 |
+
return 2
|
| 113 |
+
if not np.all(cu == b""):
|
| 114 |
+
return 3
|
| 115 |
+
return 0
|
| 116 |
+
|
| 117 |
+
f = getattr(self.module, "string_callback_array")
|
| 118 |
+
for cu in [cu1, cu2, cu3]:
|
| 119 |
+
res = f(callback, cu, cu.size)
|
| 120 |
+
assert res == 0
|
| 121 |
+
|
| 122 |
+
def test_threadsafety(self):
|
| 123 |
+
# Segfaults if the callback handling is not threadsafe
|
| 124 |
+
|
| 125 |
+
errors = []
|
| 126 |
+
|
| 127 |
+
def cb():
|
| 128 |
+
# Sleep here to make it more likely for another thread
|
| 129 |
+
# to call their callback at the same time.
|
| 130 |
+
time.sleep(1e-3)
|
| 131 |
+
|
| 132 |
+
# Check reentrancy
|
| 133 |
+
r = self.module.t(lambda: 123)
|
| 134 |
+
assert r == 123
|
| 135 |
+
|
| 136 |
+
return 42
|
| 137 |
+
|
| 138 |
+
def runner(name):
|
| 139 |
+
try:
|
| 140 |
+
for j in range(50):
|
| 141 |
+
r = self.module.t(cb)
|
| 142 |
+
assert r == 42
|
| 143 |
+
self.check_function(name)
|
| 144 |
+
except Exception:
|
| 145 |
+
errors.append(traceback.format_exc())
|
| 146 |
+
|
| 147 |
+
threads = [
|
| 148 |
+
threading.Thread(target=runner, args=(arg, ))
|
| 149 |
+
for arg in ("t", "t2") for n in range(20)
|
| 150 |
+
]
|
| 151 |
+
|
| 152 |
+
for t in threads:
|
| 153 |
+
t.start()
|
| 154 |
+
|
| 155 |
+
for t in threads:
|
| 156 |
+
t.join()
|
| 157 |
+
|
| 158 |
+
errors = "\n\n".join(errors)
|
| 159 |
+
if errors:
|
| 160 |
+
raise AssertionError(errors)
|
| 161 |
+
|
| 162 |
+
def test_hidden_callback(self):
|
| 163 |
+
try:
|
| 164 |
+
self.module.hidden_callback(2)
|
| 165 |
+
except Exception as msg:
|
| 166 |
+
assert str(msg).startswith("Callback global_f not defined")
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
self.module.hidden_callback2(2)
|
| 170 |
+
except Exception as msg:
|
| 171 |
+
assert str(msg).startswith("cb: Callback global_f not defined")
|
| 172 |
+
|
| 173 |
+
self.module.global_f = lambda x: x + 1
|
| 174 |
+
r = self.module.hidden_callback(2)
|
| 175 |
+
assert r == 3
|
| 176 |
+
|
| 177 |
+
self.module.global_f = lambda x: x + 2
|
| 178 |
+
r = self.module.hidden_callback(2)
|
| 179 |
+
assert r == 4
|
| 180 |
+
|
| 181 |
+
del self.module.global_f
|
| 182 |
+
try:
|
| 183 |
+
self.module.hidden_callback(2)
|
| 184 |
+
except Exception as msg:
|
| 185 |
+
assert str(msg).startswith("Callback global_f not defined")
|
| 186 |
+
|
| 187 |
+
self.module.global_f = lambda x=0: x + 3
|
| 188 |
+
r = self.module.hidden_callback(2)
|
| 189 |
+
assert r == 5
|
| 190 |
+
|
| 191 |
+
# reproducer of gh18341
|
| 192 |
+
r = self.module.hidden_callback2(2)
|
| 193 |
+
assert r == 3
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class TestF77CallbackPythonTLS(TestF77Callback):
|
| 197 |
+
"""
|
| 198 |
+
Callback tests using Python thread-local storage instead of
|
| 199 |
+
compiler-provided
|
| 200 |
+
"""
|
| 201 |
+
|
| 202 |
+
options = ["-DF2PY_USE_PYTHON_TLS"]
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
class TestF90Callback(util.F2PyTest):
|
| 206 |
+
sources = [util.getpath("tests", "src", "callback", "gh17797.f90")]
|
| 207 |
+
|
| 208 |
+
def test_gh17797(self):
|
| 209 |
+
def incr(x):
|
| 210 |
+
return x + 123
|
| 211 |
+
|
| 212 |
+
y = np.array([1, 2, 3], dtype=np.int64)
|
| 213 |
+
r = self.module.gh17797(incr, y)
|
| 214 |
+
assert r == 123 + 1 + 2 + 3
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class TestGH18335(util.F2PyTest):
|
| 218 |
+
"""The reproduction of the reported issue requires specific input that
|
| 219 |
+
extensions may break the issue conditions, so the reproducer is
|
| 220 |
+
implemented as a separate test class. Do not extend this test with
|
| 221 |
+
other tests!
|
| 222 |
+
"""
|
| 223 |
+
sources = [util.getpath("tests", "src", "callback", "gh18335.f90")]
|
| 224 |
+
|
| 225 |
+
def test_gh18335(self):
|
| 226 |
+
def foo(x):
|
| 227 |
+
x[0] += 1
|
| 228 |
+
|
| 229 |
+
r = self.module.gh18335(foo)
|
| 230 |
+
assert r == 123 + 1
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_character.py
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
import textwrap
|
| 3 |
+
from numpy.testing import assert_array_equal, assert_equal, assert_raises
|
| 4 |
+
import numpy as np
|
| 5 |
+
from numpy.f2py.tests import util
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestCharacterString(util.F2PyTest):
|
| 9 |
+
# options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py']
|
| 10 |
+
suffix = '.f90'
|
| 11 |
+
fprefix = 'test_character_string'
|
| 12 |
+
length_list = ['1', '3', 'star']
|
| 13 |
+
|
| 14 |
+
code = ''
|
| 15 |
+
for length in length_list:
|
| 16 |
+
fsuffix = length
|
| 17 |
+
clength = dict(star='(*)').get(length, length)
|
| 18 |
+
|
| 19 |
+
code += textwrap.dedent(f"""
|
| 20 |
+
|
| 21 |
+
subroutine {fprefix}_input_{fsuffix}(c, o, n)
|
| 22 |
+
character*{clength}, intent(in) :: c
|
| 23 |
+
integer n
|
| 24 |
+
!f2py integer, depend(c), intent(hide) :: n = slen(c)
|
| 25 |
+
integer*1, dimension(n) :: o
|
| 26 |
+
!f2py intent(out) o
|
| 27 |
+
o = transfer(c, o)
|
| 28 |
+
end subroutine {fprefix}_input_{fsuffix}
|
| 29 |
+
|
| 30 |
+
subroutine {fprefix}_output_{fsuffix}(c, o, n)
|
| 31 |
+
character*{clength}, intent(out) :: c
|
| 32 |
+
integer n
|
| 33 |
+
integer*1, dimension(n), intent(in) :: o
|
| 34 |
+
!f2py integer, depend(o), intent(hide) :: n = len(o)
|
| 35 |
+
c = transfer(o, c)
|
| 36 |
+
end subroutine {fprefix}_output_{fsuffix}
|
| 37 |
+
|
| 38 |
+
subroutine {fprefix}_array_input_{fsuffix}(c, o, m, n)
|
| 39 |
+
integer m, i, n
|
| 40 |
+
character*{clength}, intent(in), dimension(m) :: c
|
| 41 |
+
!f2py integer, depend(c), intent(hide) :: m = len(c)
|
| 42 |
+
!f2py integer, depend(c), intent(hide) :: n = f2py_itemsize(c)
|
| 43 |
+
integer*1, dimension(m, n), intent(out) :: o
|
| 44 |
+
do i=1,m
|
| 45 |
+
o(i, :) = transfer(c(i), o(i, :))
|
| 46 |
+
end do
|
| 47 |
+
end subroutine {fprefix}_array_input_{fsuffix}
|
| 48 |
+
|
| 49 |
+
subroutine {fprefix}_array_output_{fsuffix}(c, o, m, n)
|
| 50 |
+
character*{clength}, intent(out), dimension(m) :: c
|
| 51 |
+
integer n
|
| 52 |
+
integer*1, dimension(m, n), intent(in) :: o
|
| 53 |
+
!f2py character(f2py_len=n) :: c
|
| 54 |
+
!f2py integer, depend(o), intent(hide) :: m = len(o)
|
| 55 |
+
!f2py integer, depend(o), intent(hide) :: n = shape(o, 1)
|
| 56 |
+
do i=1,m
|
| 57 |
+
c(i) = transfer(o(i, :), c(i))
|
| 58 |
+
end do
|
| 59 |
+
end subroutine {fprefix}_array_output_{fsuffix}
|
| 60 |
+
|
| 61 |
+
subroutine {fprefix}_2d_array_input_{fsuffix}(c, o, m1, m2, n)
|
| 62 |
+
integer m1, m2, i, j, n
|
| 63 |
+
character*{clength}, intent(in), dimension(m1, m2) :: c
|
| 64 |
+
!f2py integer, depend(c), intent(hide) :: m1 = len(c)
|
| 65 |
+
!f2py integer, depend(c), intent(hide) :: m2 = shape(c, 1)
|
| 66 |
+
!f2py integer, depend(c), intent(hide) :: n = f2py_itemsize(c)
|
| 67 |
+
integer*1, dimension(m1, m2, n), intent(out) :: o
|
| 68 |
+
do i=1,m1
|
| 69 |
+
do j=1,m2
|
| 70 |
+
o(i, j, :) = transfer(c(i, j), o(i, j, :))
|
| 71 |
+
end do
|
| 72 |
+
end do
|
| 73 |
+
end subroutine {fprefix}_2d_array_input_{fsuffix}
|
| 74 |
+
""")
|
| 75 |
+
|
| 76 |
+
@pytest.mark.parametrize("length", length_list)
|
| 77 |
+
def test_input(self, length):
|
| 78 |
+
fsuffix = {'(*)': 'star'}.get(length, length)
|
| 79 |
+
f = getattr(self.module, self.fprefix + '_input_' + fsuffix)
|
| 80 |
+
|
| 81 |
+
a = {'1': 'a', '3': 'abc', 'star': 'abcde' * 3}[length]
|
| 82 |
+
|
| 83 |
+
assert_array_equal(f(a), np.array(list(map(ord, a)), dtype='u1'))
|
| 84 |
+
|
| 85 |
+
@pytest.mark.parametrize("length", length_list[:-1])
|
| 86 |
+
def test_output(self, length):
|
| 87 |
+
fsuffix = length
|
| 88 |
+
f = getattr(self.module, self.fprefix + '_output_' + fsuffix)
|
| 89 |
+
|
| 90 |
+
a = {'1': 'a', '3': 'abc'}[length]
|
| 91 |
+
|
| 92 |
+
assert_array_equal(f(np.array(list(map(ord, a)), dtype='u1')),
|
| 93 |
+
a.encode())
|
| 94 |
+
|
| 95 |
+
@pytest.mark.parametrize("length", length_list)
|
| 96 |
+
def test_array_input(self, length):
|
| 97 |
+
fsuffix = length
|
| 98 |
+
f = getattr(self.module, self.fprefix + '_array_input_' + fsuffix)
|
| 99 |
+
|
| 100 |
+
a = np.array([{'1': 'a', '3': 'abc', 'star': 'abcde' * 3}[length],
|
| 101 |
+
{'1': 'A', '3': 'ABC', 'star': 'ABCDE' * 3}[length],
|
| 102 |
+
], dtype='S')
|
| 103 |
+
|
| 104 |
+
expected = np.array([[c for c in s] for s in a], dtype='u1')
|
| 105 |
+
assert_array_equal(f(a), expected)
|
| 106 |
+
|
| 107 |
+
@pytest.mark.parametrize("length", length_list)
|
| 108 |
+
def test_array_output(self, length):
|
| 109 |
+
fsuffix = length
|
| 110 |
+
f = getattr(self.module, self.fprefix + '_array_output_' + fsuffix)
|
| 111 |
+
|
| 112 |
+
expected = np.array(
|
| 113 |
+
[{'1': 'a', '3': 'abc', 'star': 'abcde' * 3}[length],
|
| 114 |
+
{'1': 'A', '3': 'ABC', 'star': 'ABCDE' * 3}[length]], dtype='S')
|
| 115 |
+
|
| 116 |
+
a = np.array([[c for c in s] for s in expected], dtype='u1')
|
| 117 |
+
assert_array_equal(f(a), expected)
|
| 118 |
+
|
| 119 |
+
@pytest.mark.parametrize("length", length_list)
|
| 120 |
+
def test_2d_array_input(self, length):
|
| 121 |
+
fsuffix = length
|
| 122 |
+
f = getattr(self.module, self.fprefix + '_2d_array_input_' + fsuffix)
|
| 123 |
+
|
| 124 |
+
a = np.array([[{'1': 'a', '3': 'abc', 'star': 'abcde' * 3}[length],
|
| 125 |
+
{'1': 'A', '3': 'ABC', 'star': 'ABCDE' * 3}[length]],
|
| 126 |
+
[{'1': 'f', '3': 'fgh', 'star': 'fghij' * 3}[length],
|
| 127 |
+
{'1': 'F', '3': 'FGH', 'star': 'FGHIJ' * 3}[length]]],
|
| 128 |
+
dtype='S')
|
| 129 |
+
expected = np.array([[[c for c in item] for item in row] for row in a],
|
| 130 |
+
dtype='u1', order='F')
|
| 131 |
+
assert_array_equal(f(a), expected)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class TestCharacter(util.F2PyTest):
|
| 135 |
+
# options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py']
|
| 136 |
+
suffix = '.f90'
|
| 137 |
+
fprefix = 'test_character'
|
| 138 |
+
|
| 139 |
+
code = textwrap.dedent(f"""
|
| 140 |
+
subroutine {fprefix}_input(c, o)
|
| 141 |
+
character, intent(in) :: c
|
| 142 |
+
integer*1 o
|
| 143 |
+
!f2py intent(out) o
|
| 144 |
+
o = transfer(c, o)
|
| 145 |
+
end subroutine {fprefix}_input
|
| 146 |
+
|
| 147 |
+
subroutine {fprefix}_output(c, o)
|
| 148 |
+
character :: c
|
| 149 |
+
integer*1, intent(in) :: o
|
| 150 |
+
!f2py intent(out) c
|
| 151 |
+
c = transfer(o, c)
|
| 152 |
+
end subroutine {fprefix}_output
|
| 153 |
+
|
| 154 |
+
subroutine {fprefix}_input_output(c, o)
|
| 155 |
+
character, intent(in) :: c
|
| 156 |
+
character o
|
| 157 |
+
!f2py intent(out) o
|
| 158 |
+
o = c
|
| 159 |
+
end subroutine {fprefix}_input_output
|
| 160 |
+
|
| 161 |
+
subroutine {fprefix}_inout(c, n)
|
| 162 |
+
character :: c, n
|
| 163 |
+
!f2py intent(in) n
|
| 164 |
+
!f2py intent(inout) c
|
| 165 |
+
c = n
|
| 166 |
+
end subroutine {fprefix}_inout
|
| 167 |
+
|
| 168 |
+
function {fprefix}_return(o) result (c)
|
| 169 |
+
character :: c
|
| 170 |
+
character, intent(in) :: o
|
| 171 |
+
c = transfer(o, c)
|
| 172 |
+
end function {fprefix}_return
|
| 173 |
+
|
| 174 |
+
subroutine {fprefix}_array_input(c, o)
|
| 175 |
+
character, intent(in) :: c(3)
|
| 176 |
+
integer*1 o(3)
|
| 177 |
+
!f2py intent(out) o
|
| 178 |
+
integer i
|
| 179 |
+
do i=1,3
|
| 180 |
+
o(i) = transfer(c(i), o(i))
|
| 181 |
+
end do
|
| 182 |
+
end subroutine {fprefix}_array_input
|
| 183 |
+
|
| 184 |
+
subroutine {fprefix}_2d_array_input(c, o)
|
| 185 |
+
character, intent(in) :: c(2, 3)
|
| 186 |
+
integer*1 o(2, 3)
|
| 187 |
+
!f2py intent(out) o
|
| 188 |
+
integer i, j
|
| 189 |
+
do i=1,2
|
| 190 |
+
do j=1,3
|
| 191 |
+
o(i, j) = transfer(c(i, j), o(i, j))
|
| 192 |
+
end do
|
| 193 |
+
end do
|
| 194 |
+
end subroutine {fprefix}_2d_array_input
|
| 195 |
+
|
| 196 |
+
subroutine {fprefix}_array_output(c, o)
|
| 197 |
+
character :: c(3)
|
| 198 |
+
integer*1, intent(in) :: o(3)
|
| 199 |
+
!f2py intent(out) c
|
| 200 |
+
do i=1,3
|
| 201 |
+
c(i) = transfer(o(i), c(i))
|
| 202 |
+
end do
|
| 203 |
+
end subroutine {fprefix}_array_output
|
| 204 |
+
|
| 205 |
+
subroutine {fprefix}_array_inout(c, n)
|
| 206 |
+
character :: c(3), n(3)
|
| 207 |
+
!f2py intent(in) n(3)
|
| 208 |
+
!f2py intent(inout) c(3)
|
| 209 |
+
do i=1,3
|
| 210 |
+
c(i) = n(i)
|
| 211 |
+
end do
|
| 212 |
+
end subroutine {fprefix}_array_inout
|
| 213 |
+
|
| 214 |
+
subroutine {fprefix}_2d_array_inout(c, n)
|
| 215 |
+
character :: c(2, 3), n(2, 3)
|
| 216 |
+
!f2py intent(in) n(2, 3)
|
| 217 |
+
!f2py intent(inout) c(2. 3)
|
| 218 |
+
integer i, j
|
| 219 |
+
do i=1,2
|
| 220 |
+
do j=1,3
|
| 221 |
+
c(i, j) = n(i, j)
|
| 222 |
+
end do
|
| 223 |
+
end do
|
| 224 |
+
end subroutine {fprefix}_2d_array_inout
|
| 225 |
+
|
| 226 |
+
function {fprefix}_array_return(o) result (c)
|
| 227 |
+
character, dimension(3) :: c
|
| 228 |
+
character, intent(in) :: o(3)
|
| 229 |
+
do i=1,3
|
| 230 |
+
c(i) = o(i)
|
| 231 |
+
end do
|
| 232 |
+
end function {fprefix}_array_return
|
| 233 |
+
|
| 234 |
+
function {fprefix}_optional(o) result (c)
|
| 235 |
+
character, intent(in) :: o
|
| 236 |
+
!f2py character o = "a"
|
| 237 |
+
character :: c
|
| 238 |
+
c = o
|
| 239 |
+
end function {fprefix}_optional
|
| 240 |
+
""")
|
| 241 |
+
|
| 242 |
+
@pytest.mark.parametrize("dtype", ['c', 'S1'])
|
| 243 |
+
def test_input(self, dtype):
|
| 244 |
+
f = getattr(self.module, self.fprefix + '_input')
|
| 245 |
+
|
| 246 |
+
assert_equal(f(np.array('a', dtype=dtype)), ord('a'))
|
| 247 |
+
assert_equal(f(np.array(b'a', dtype=dtype)), ord('a'))
|
| 248 |
+
assert_equal(f(np.array(['a'], dtype=dtype)), ord('a'))
|
| 249 |
+
assert_equal(f(np.array('abc', dtype=dtype)), ord('a'))
|
| 250 |
+
assert_equal(f(np.array([['a']], dtype=dtype)), ord('a'))
|
| 251 |
+
|
| 252 |
+
def test_input_varia(self):
|
| 253 |
+
f = getattr(self.module, self.fprefix + '_input')
|
| 254 |
+
|
| 255 |
+
assert_equal(f('a'), ord('a'))
|
| 256 |
+
assert_equal(f(b'a'), ord(b'a'))
|
| 257 |
+
assert_equal(f(''), 0)
|
| 258 |
+
assert_equal(f(b''), 0)
|
| 259 |
+
assert_equal(f(b'\0'), 0)
|
| 260 |
+
assert_equal(f('ab'), ord('a'))
|
| 261 |
+
assert_equal(f(b'ab'), ord('a'))
|
| 262 |
+
assert_equal(f(['a']), ord('a'))
|
| 263 |
+
|
| 264 |
+
assert_equal(f(np.array(b'a')), ord('a'))
|
| 265 |
+
assert_equal(f(np.array([b'a'])), ord('a'))
|
| 266 |
+
a = np.array('a')
|
| 267 |
+
assert_equal(f(a), ord('a'))
|
| 268 |
+
a = np.array(['a'])
|
| 269 |
+
assert_equal(f(a), ord('a'))
|
| 270 |
+
|
| 271 |
+
try:
|
| 272 |
+
f([])
|
| 273 |
+
except IndexError as msg:
|
| 274 |
+
if not str(msg).endswith(' got 0-list'):
|
| 275 |
+
raise
|
| 276 |
+
else:
|
| 277 |
+
raise SystemError(f'{f.__name__} should have failed on empty list')
|
| 278 |
+
|
| 279 |
+
try:
|
| 280 |
+
f(97)
|
| 281 |
+
except TypeError as msg:
|
| 282 |
+
if not str(msg).endswith(' got int instance'):
|
| 283 |
+
raise
|
| 284 |
+
else:
|
| 285 |
+
raise SystemError(f'{f.__name__} should have failed on int value')
|
| 286 |
+
|
| 287 |
+
@pytest.mark.parametrize("dtype", ['c', 'S1', 'U1'])
|
| 288 |
+
def test_array_input(self, dtype):
|
| 289 |
+
f = getattr(self.module, self.fprefix + '_array_input')
|
| 290 |
+
|
| 291 |
+
assert_array_equal(f(np.array(['a', 'b', 'c'], dtype=dtype)),
|
| 292 |
+
np.array(list(map(ord, 'abc')), dtype='i1'))
|
| 293 |
+
assert_array_equal(f(np.array([b'a', b'b', b'c'], dtype=dtype)),
|
| 294 |
+
np.array(list(map(ord, 'abc')), dtype='i1'))
|
| 295 |
+
|
| 296 |
+
def test_array_input_varia(self):
|
| 297 |
+
f = getattr(self.module, self.fprefix + '_array_input')
|
| 298 |
+
assert_array_equal(f(['a', 'b', 'c']),
|
| 299 |
+
np.array(list(map(ord, 'abc')), dtype='i1'))
|
| 300 |
+
assert_array_equal(f([b'a', b'b', b'c']),
|
| 301 |
+
np.array(list(map(ord, 'abc')), dtype='i1'))
|
| 302 |
+
|
| 303 |
+
try:
|
| 304 |
+
f(['a', 'b', 'c', 'd'])
|
| 305 |
+
except ValueError as msg:
|
| 306 |
+
if not str(msg).endswith(
|
| 307 |
+
'th dimension must be fixed to 3 but got 4'):
|
| 308 |
+
raise
|
| 309 |
+
else:
|
| 310 |
+
raise SystemError(
|
| 311 |
+
f'{f.__name__} should have failed on wrong input')
|
| 312 |
+
|
| 313 |
+
@pytest.mark.parametrize("dtype", ['c', 'S1', 'U1'])
|
| 314 |
+
def test_2d_array_input(self, dtype):
|
| 315 |
+
f = getattr(self.module, self.fprefix + '_2d_array_input')
|
| 316 |
+
|
| 317 |
+
a = np.array([['a', 'b', 'c'],
|
| 318 |
+
['d', 'e', 'f']], dtype=dtype, order='F')
|
| 319 |
+
expected = a.view(np.uint32 if dtype == 'U1' else np.uint8)
|
| 320 |
+
assert_array_equal(f(a), expected)
|
| 321 |
+
|
| 322 |
+
def test_output(self):
|
| 323 |
+
f = getattr(self.module, self.fprefix + '_output')
|
| 324 |
+
|
| 325 |
+
assert_equal(f(ord(b'a')), b'a')
|
| 326 |
+
assert_equal(f(0), b'\0')
|
| 327 |
+
|
| 328 |
+
def test_array_output(self):
|
| 329 |
+
f = getattr(self.module, self.fprefix + '_array_output')
|
| 330 |
+
|
| 331 |
+
assert_array_equal(f(list(map(ord, 'abc'))),
|
| 332 |
+
np.array(list('abc'), dtype='S1'))
|
| 333 |
+
|
| 334 |
+
def test_input_output(self):
|
| 335 |
+
f = getattr(self.module, self.fprefix + '_input_output')
|
| 336 |
+
|
| 337 |
+
assert_equal(f(b'a'), b'a')
|
| 338 |
+
assert_equal(f('a'), b'a')
|
| 339 |
+
assert_equal(f(''), b'\0')
|
| 340 |
+
|
| 341 |
+
@pytest.mark.parametrize("dtype", ['c', 'S1'])
|
| 342 |
+
def test_inout(self, dtype):
|
| 343 |
+
f = getattr(self.module, self.fprefix + '_inout')
|
| 344 |
+
|
| 345 |
+
a = np.array(list('abc'), dtype=dtype)
|
| 346 |
+
f(a, 'A')
|
| 347 |
+
assert_array_equal(a, np.array(list('Abc'), dtype=a.dtype))
|
| 348 |
+
f(a[1:], 'B')
|
| 349 |
+
assert_array_equal(a, np.array(list('ABc'), dtype=a.dtype))
|
| 350 |
+
|
| 351 |
+
a = np.array(['abc'], dtype=dtype)
|
| 352 |
+
f(a, 'A')
|
| 353 |
+
assert_array_equal(a, np.array(['Abc'], dtype=a.dtype))
|
| 354 |
+
|
| 355 |
+
def test_inout_varia(self):
|
| 356 |
+
f = getattr(self.module, self.fprefix + '_inout')
|
| 357 |
+
a = np.array('abc', dtype='S3')
|
| 358 |
+
f(a, 'A')
|
| 359 |
+
assert_array_equal(a, np.array('Abc', dtype=a.dtype))
|
| 360 |
+
|
| 361 |
+
a = np.array(['abc'], dtype='S3')
|
| 362 |
+
f(a, 'A')
|
| 363 |
+
assert_array_equal(a, np.array(['Abc'], dtype=a.dtype))
|
| 364 |
+
|
| 365 |
+
try:
|
| 366 |
+
f('abc', 'A')
|
| 367 |
+
except ValueError as msg:
|
| 368 |
+
if not str(msg).endswith(' got 3-str'):
|
| 369 |
+
raise
|
| 370 |
+
else:
|
| 371 |
+
raise SystemError(f'{f.__name__} should have failed on str value')
|
| 372 |
+
|
| 373 |
+
@pytest.mark.parametrize("dtype", ['c', 'S1'])
|
| 374 |
+
def test_array_inout(self, dtype):
|
| 375 |
+
f = getattr(self.module, self.fprefix + '_array_inout')
|
| 376 |
+
n = np.array(['A', 'B', 'C'], dtype=dtype, order='F')
|
| 377 |
+
|
| 378 |
+
a = np.array(['a', 'b', 'c'], dtype=dtype, order='F')
|
| 379 |
+
f(a, n)
|
| 380 |
+
assert_array_equal(a, n)
|
| 381 |
+
|
| 382 |
+
a = np.array(['a', 'b', 'c', 'd'], dtype=dtype)
|
| 383 |
+
f(a[1:], n)
|
| 384 |
+
assert_array_equal(a, np.array(['a', 'A', 'B', 'C'], dtype=dtype))
|
| 385 |
+
|
| 386 |
+
a = np.array([['a', 'b', 'c']], dtype=dtype, order='F')
|
| 387 |
+
f(a, n)
|
| 388 |
+
assert_array_equal(a, np.array([['A', 'B', 'C']], dtype=dtype))
|
| 389 |
+
|
| 390 |
+
a = np.array(['a', 'b', 'c', 'd'], dtype=dtype, order='F')
|
| 391 |
+
try:
|
| 392 |
+
f(a, n)
|
| 393 |
+
except ValueError as msg:
|
| 394 |
+
if not str(msg).endswith(
|
| 395 |
+
'th dimension must be fixed to 3 but got 4'):
|
| 396 |
+
raise
|
| 397 |
+
else:
|
| 398 |
+
raise SystemError(
|
| 399 |
+
f'{f.__name__} should have failed on wrong input')
|
| 400 |
+
|
| 401 |
+
@pytest.mark.parametrize("dtype", ['c', 'S1'])
|
| 402 |
+
def test_2d_array_inout(self, dtype):
|
| 403 |
+
f = getattr(self.module, self.fprefix + '_2d_array_inout')
|
| 404 |
+
n = np.array([['A', 'B', 'C'],
|
| 405 |
+
['D', 'E', 'F']],
|
| 406 |
+
dtype=dtype, order='F')
|
| 407 |
+
a = np.array([['a', 'b', 'c'],
|
| 408 |
+
['d', 'e', 'f']],
|
| 409 |
+
dtype=dtype, order='F')
|
| 410 |
+
f(a, n)
|
| 411 |
+
assert_array_equal(a, n)
|
| 412 |
+
|
| 413 |
+
def test_return(self):
|
| 414 |
+
f = getattr(self.module, self.fprefix + '_return')
|
| 415 |
+
|
| 416 |
+
assert_equal(f('a'), b'a')
|
| 417 |
+
|
| 418 |
+
@pytest.mark.skip('fortran function returning array segfaults')
|
| 419 |
+
def test_array_return(self):
|
| 420 |
+
f = getattr(self.module, self.fprefix + '_array_return')
|
| 421 |
+
|
| 422 |
+
a = np.array(list('abc'), dtype='S1')
|
| 423 |
+
assert_array_equal(f(a), a)
|
| 424 |
+
|
| 425 |
+
def test_optional(self):
|
| 426 |
+
f = getattr(self.module, self.fprefix + '_optional')
|
| 427 |
+
|
| 428 |
+
assert_equal(f(), b"a")
|
| 429 |
+
assert_equal(f(b'B'), b"B")
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class TestMiscCharacter(util.F2PyTest):
|
| 433 |
+
# options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py']
|
| 434 |
+
suffix = '.f90'
|
| 435 |
+
fprefix = 'test_misc_character'
|
| 436 |
+
|
| 437 |
+
code = textwrap.dedent(f"""
|
| 438 |
+
subroutine {fprefix}_gh18684(x, y, m)
|
| 439 |
+
character(len=5), dimension(m), intent(in) :: x
|
| 440 |
+
character*5, dimension(m), intent(out) :: y
|
| 441 |
+
integer i, m
|
| 442 |
+
!f2py integer, intent(hide), depend(x) :: m = f2py_len(x)
|
| 443 |
+
do i=1,m
|
| 444 |
+
y(i) = x(i)
|
| 445 |
+
end do
|
| 446 |
+
end subroutine {fprefix}_gh18684
|
| 447 |
+
|
| 448 |
+
subroutine {fprefix}_gh6308(x, i)
|
| 449 |
+
integer i
|
| 450 |
+
!f2py check(i>=0 && i<12) i
|
| 451 |
+
character*5 name, x
|
| 452 |
+
common name(12)
|
| 453 |
+
name(i + 1) = x
|
| 454 |
+
end subroutine {fprefix}_gh6308
|
| 455 |
+
|
| 456 |
+
subroutine {fprefix}_gh4519(x)
|
| 457 |
+
character(len=*), intent(in) :: x(:)
|
| 458 |
+
!f2py intent(out) x
|
| 459 |
+
integer :: i
|
| 460 |
+
do i=1, size(x)
|
| 461 |
+
print*, "x(",i,")=", x(i)
|
| 462 |
+
end do
|
| 463 |
+
end subroutine {fprefix}_gh4519
|
| 464 |
+
|
| 465 |
+
pure function {fprefix}_gh3425(x) result (y)
|
| 466 |
+
character(len=*), intent(in) :: x
|
| 467 |
+
character(len=len(x)) :: y
|
| 468 |
+
integer :: i
|
| 469 |
+
do i = 1, len(x)
|
| 470 |
+
j = iachar(x(i:i))
|
| 471 |
+
if (j>=iachar("a") .and. j<=iachar("z") ) then
|
| 472 |
+
y(i:i) = achar(j-32)
|
| 473 |
+
else
|
| 474 |
+
y(i:i) = x(i:i)
|
| 475 |
+
endif
|
| 476 |
+
end do
|
| 477 |
+
end function {fprefix}_gh3425
|
| 478 |
+
|
| 479 |
+
subroutine {fprefix}_character_bc_new(x, y, z)
|
| 480 |
+
character, intent(in) :: x
|
| 481 |
+
character, intent(out) :: y
|
| 482 |
+
!f2py character, depend(x) :: y = x
|
| 483 |
+
!f2py character, dimension((x=='a'?1:2)), depend(x), intent(out) :: z
|
| 484 |
+
character, dimension(*) :: z
|
| 485 |
+
!f2py character, optional, check(x == 'a' || x == 'b') :: x = 'a'
|
| 486 |
+
!f2py callstatement (*f2py_func)(&x, &y, z)
|
| 487 |
+
!f2py callprotoargument character*, character*, character*
|
| 488 |
+
if (y.eq.x) then
|
| 489 |
+
y = x
|
| 490 |
+
else
|
| 491 |
+
y = 'e'
|
| 492 |
+
endif
|
| 493 |
+
z(1) = 'c'
|
| 494 |
+
end subroutine {fprefix}_character_bc_new
|
| 495 |
+
|
| 496 |
+
subroutine {fprefix}_character_bc_old(x, y, z)
|
| 497 |
+
character, intent(in) :: x
|
| 498 |
+
character, intent(out) :: y
|
| 499 |
+
!f2py character, depend(x) :: y = x[0]
|
| 500 |
+
!f2py character, dimension((*x=='a'?1:2)), depend(x), intent(out) :: z
|
| 501 |
+
character, dimension(*) :: z
|
| 502 |
+
!f2py character, optional, check(*x == 'a' || x[0] == 'b') :: x = 'a'
|
| 503 |
+
!f2py callstatement (*f2py_func)(x, y, z)
|
| 504 |
+
!f2py callprotoargument char*, char*, char*
|
| 505 |
+
if (y.eq.x) then
|
| 506 |
+
y = x
|
| 507 |
+
else
|
| 508 |
+
y = 'e'
|
| 509 |
+
endif
|
| 510 |
+
z(1) = 'c'
|
| 511 |
+
end subroutine {fprefix}_character_bc_old
|
| 512 |
+
""")
|
| 513 |
+
|
| 514 |
+
def test_gh18684(self):
|
| 515 |
+
# Test character(len=5) and character*5 usages
|
| 516 |
+
f = getattr(self.module, self.fprefix + '_gh18684')
|
| 517 |
+
x = np.array(["abcde", "fghij"], dtype='S5')
|
| 518 |
+
y = f(x)
|
| 519 |
+
|
| 520 |
+
assert_array_equal(x, y)
|
| 521 |
+
|
| 522 |
+
def test_gh6308(self):
|
| 523 |
+
# Test character string array in a common block
|
| 524 |
+
f = getattr(self.module, self.fprefix + '_gh6308')
|
| 525 |
+
|
| 526 |
+
assert_equal(self.module._BLNK_.name.dtype, np.dtype('S5'))
|
| 527 |
+
assert_equal(len(self.module._BLNK_.name), 12)
|
| 528 |
+
f("abcde", 0)
|
| 529 |
+
assert_equal(self.module._BLNK_.name[0], b"abcde")
|
| 530 |
+
f("12345", 5)
|
| 531 |
+
assert_equal(self.module._BLNK_.name[5], b"12345")
|
| 532 |
+
|
| 533 |
+
def test_gh4519(self):
|
| 534 |
+
# Test array of assumed length strings
|
| 535 |
+
f = getattr(self.module, self.fprefix + '_gh4519')
|
| 536 |
+
|
| 537 |
+
for x, expected in [
|
| 538 |
+
('a', dict(shape=(), dtype=np.dtype('S1'))),
|
| 539 |
+
('text', dict(shape=(), dtype=np.dtype('S4'))),
|
| 540 |
+
(np.array(['1', '2', '3'], dtype='S1'),
|
| 541 |
+
dict(shape=(3,), dtype=np.dtype('S1'))),
|
| 542 |
+
(['1', '2', '34'],
|
| 543 |
+
dict(shape=(3,), dtype=np.dtype('S2'))),
|
| 544 |
+
(['', ''], dict(shape=(2,), dtype=np.dtype('S1')))]:
|
| 545 |
+
r = f(x)
|
| 546 |
+
for k, v in expected.items():
|
| 547 |
+
assert_equal(getattr(r, k), v)
|
| 548 |
+
|
| 549 |
+
def test_gh3425(self):
|
| 550 |
+
# Test returning a copy of assumed length string
|
| 551 |
+
f = getattr(self.module, self.fprefix + '_gh3425')
|
| 552 |
+
# f is equivalent to bytes.upper
|
| 553 |
+
|
| 554 |
+
assert_equal(f('abC'), b'ABC')
|
| 555 |
+
assert_equal(f(''), b'')
|
| 556 |
+
assert_equal(f('abC12d'), b'ABC12D')
|
| 557 |
+
|
| 558 |
+
@pytest.mark.parametrize("state", ['new', 'old'])
|
| 559 |
+
def test_character_bc(self, state):
|
| 560 |
+
f = getattr(self.module, self.fprefix + '_character_bc_' + state)
|
| 561 |
+
|
| 562 |
+
c, a = f()
|
| 563 |
+
assert_equal(c, b'a')
|
| 564 |
+
assert_equal(len(a), 1)
|
| 565 |
+
|
| 566 |
+
c, a = f(b'b')
|
| 567 |
+
assert_equal(c, b'b')
|
| 568 |
+
assert_equal(len(a), 2)
|
| 569 |
+
|
| 570 |
+
assert_raises(Exception, lambda: f(b'c'))
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
class TestStringScalarArr(util.F2PyTest):
|
| 574 |
+
sources = [util.getpath("tests", "src", "string", "scalar_string.f90")]
|
| 575 |
+
|
| 576 |
+
@pytest.mark.slow
|
| 577 |
+
def test_char(self):
|
| 578 |
+
for out in (self.module.string_test.string,
|
| 579 |
+
self.module.string_test.string77):
|
| 580 |
+
expected = ()
|
| 581 |
+
assert out.shape == expected
|
| 582 |
+
expected = '|S8'
|
| 583 |
+
assert out.dtype == expected
|
| 584 |
+
|
| 585 |
+
@pytest.mark.slow
|
| 586 |
+
def test_char_arr(self):
|
| 587 |
+
for out in (self.module.string_test.strarr,
|
| 588 |
+
self.module.string_test.strarr77):
|
| 589 |
+
expected = (5,7)
|
| 590 |
+
assert out.shape == expected
|
| 591 |
+
expected = '|S12'
|
| 592 |
+
assert out.dtype == expected
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_crackfortran.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import codecs
|
| 3 |
+
import unicodedata
|
| 4 |
+
import pytest
|
| 5 |
+
import numpy as np
|
| 6 |
+
from numpy.f2py.crackfortran import markinnerspaces
|
| 7 |
+
from . import util
|
| 8 |
+
from numpy.f2py import crackfortran
|
| 9 |
+
import textwrap
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TestNoSpace(util.F2PyTest):
|
| 13 |
+
# issue gh-15035: add handling for endsubroutine, endfunction with no space
|
| 14 |
+
# between "end" and the block name
|
| 15 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh15035.f")]
|
| 16 |
+
|
| 17 |
+
def test_module(self):
|
| 18 |
+
k = np.array([1, 2, 3], dtype=np.float64)
|
| 19 |
+
w = np.array([1, 2, 3], dtype=np.float64)
|
| 20 |
+
self.module.subb(k)
|
| 21 |
+
assert np.allclose(k, w + 1)
|
| 22 |
+
self.module.subc([w, k])
|
| 23 |
+
assert np.allclose(k, w + 1)
|
| 24 |
+
assert self.module.t0("23") == b"2"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class TestPublicPrivate:
|
| 28 |
+
def test_defaultPrivate(self):
|
| 29 |
+
fpath = util.getpath("tests", "src", "crackfortran", "privatemod.f90")
|
| 30 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 31 |
+
assert len(mod) == 1
|
| 32 |
+
mod = mod[0]
|
| 33 |
+
assert "private" in mod["vars"]["a"]["attrspec"]
|
| 34 |
+
assert "public" not in mod["vars"]["a"]["attrspec"]
|
| 35 |
+
assert "private" in mod["vars"]["b"]["attrspec"]
|
| 36 |
+
assert "public" not in mod["vars"]["b"]["attrspec"]
|
| 37 |
+
assert "private" not in mod["vars"]["seta"]["attrspec"]
|
| 38 |
+
assert "public" in mod["vars"]["seta"]["attrspec"]
|
| 39 |
+
|
| 40 |
+
def test_defaultPublic(self, tmp_path):
|
| 41 |
+
fpath = util.getpath("tests", "src", "crackfortran", "publicmod.f90")
|
| 42 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 43 |
+
assert len(mod) == 1
|
| 44 |
+
mod = mod[0]
|
| 45 |
+
assert "private" in mod["vars"]["a"]["attrspec"]
|
| 46 |
+
assert "public" not in mod["vars"]["a"]["attrspec"]
|
| 47 |
+
assert "private" not in mod["vars"]["seta"]["attrspec"]
|
| 48 |
+
assert "public" in mod["vars"]["seta"]["attrspec"]
|
| 49 |
+
|
| 50 |
+
def test_access_type(self, tmp_path):
|
| 51 |
+
fpath = util.getpath("tests", "src", "crackfortran", "accesstype.f90")
|
| 52 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 53 |
+
assert len(mod) == 1
|
| 54 |
+
tt = mod[0]['vars']
|
| 55 |
+
assert set(tt['a']['attrspec']) == {'private', 'bind(c)'}
|
| 56 |
+
assert set(tt['b_']['attrspec']) == {'public', 'bind(c)'}
|
| 57 |
+
assert set(tt['c']['attrspec']) == {'public'}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class TestModuleProcedure():
|
| 61 |
+
def test_moduleOperators(self, tmp_path):
|
| 62 |
+
fpath = util.getpath("tests", "src", "crackfortran", "operators.f90")
|
| 63 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 64 |
+
assert len(mod) == 1
|
| 65 |
+
mod = mod[0]
|
| 66 |
+
assert "body" in mod and len(mod["body"]) == 9
|
| 67 |
+
assert mod["body"][1]["name"] == "operator(.item.)"
|
| 68 |
+
assert "implementedby" in mod["body"][1]
|
| 69 |
+
assert mod["body"][1]["implementedby"] == \
|
| 70 |
+
["item_int", "item_real"]
|
| 71 |
+
assert mod["body"][2]["name"] == "operator(==)"
|
| 72 |
+
assert "implementedby" in mod["body"][2]
|
| 73 |
+
assert mod["body"][2]["implementedby"] == ["items_are_equal"]
|
| 74 |
+
assert mod["body"][3]["name"] == "assignment(=)"
|
| 75 |
+
assert "implementedby" in mod["body"][3]
|
| 76 |
+
assert mod["body"][3]["implementedby"] == \
|
| 77 |
+
["get_int", "get_real"]
|
| 78 |
+
|
| 79 |
+
def test_notPublicPrivate(self, tmp_path):
|
| 80 |
+
fpath = util.getpath("tests", "src", "crackfortran", "pubprivmod.f90")
|
| 81 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 82 |
+
assert len(mod) == 1
|
| 83 |
+
mod = mod[0]
|
| 84 |
+
assert mod['vars']['a']['attrspec'] == ['private', ]
|
| 85 |
+
assert mod['vars']['b']['attrspec'] == ['public', ]
|
| 86 |
+
assert mod['vars']['seta']['attrspec'] == ['public', ]
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class TestExternal(util.F2PyTest):
|
| 90 |
+
# issue gh-17859: add external attribute support
|
| 91 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh17859.f")]
|
| 92 |
+
|
| 93 |
+
def test_external_as_statement(self):
|
| 94 |
+
def incr(x):
|
| 95 |
+
return x + 123
|
| 96 |
+
|
| 97 |
+
r = self.module.external_as_statement(incr)
|
| 98 |
+
assert r == 123
|
| 99 |
+
|
| 100 |
+
def test_external_as_attribute(self):
|
| 101 |
+
def incr(x):
|
| 102 |
+
return x + 123
|
| 103 |
+
|
| 104 |
+
r = self.module.external_as_attribute(incr)
|
| 105 |
+
assert r == 123
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class TestCrackFortran(util.F2PyTest):
|
| 109 |
+
# gh-2848: commented lines between parameters in subroutine parameter lists
|
| 110 |
+
sources = [util.getpath("tests", "src", "crackfortran", "gh2848.f90")]
|
| 111 |
+
|
| 112 |
+
def test_gh2848(self):
|
| 113 |
+
r = self.module.gh2848(1, 2)
|
| 114 |
+
assert r == (1, 2)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class TestMarkinnerspaces:
|
| 118 |
+
# gh-14118: markinnerspaces does not handle multiple quotations
|
| 119 |
+
|
| 120 |
+
def test_do_not_touch_normal_spaces(self):
|
| 121 |
+
test_list = ["a ", " a", "a b c", "'abcdefghij'"]
|
| 122 |
+
for i in test_list:
|
| 123 |
+
assert markinnerspaces(i) == i
|
| 124 |
+
|
| 125 |
+
def test_one_relevant_space(self):
|
| 126 |
+
assert markinnerspaces("a 'b c' \\' \\'") == "a 'b@_@c' \\' \\'"
|
| 127 |
+
assert markinnerspaces(r'a "b c" \" \"') == r'a "b@_@c" \" \"'
|
| 128 |
+
|
| 129 |
+
def test_ignore_inner_quotes(self):
|
| 130 |
+
assert markinnerspaces("a 'b c\" \" d' e") == "a 'b@_@c\"@_@\"@_@d' e"
|
| 131 |
+
assert markinnerspaces("a \"b c' ' d\" e") == "a \"b@_@c'@_@'@_@d\" e"
|
| 132 |
+
|
| 133 |
+
def test_multiple_relevant_spaces(self):
|
| 134 |
+
assert markinnerspaces("a 'b c' 'd e'") == "a 'b@_@c' 'd@_@e'"
|
| 135 |
+
assert markinnerspaces(r'a "b c" "d e"') == r'a "b@_@c" "d@_@e"'
|
| 136 |
+
|
| 137 |
+
class TestDimSpec(util.F2PyTest):
|
| 138 |
+
"""This test suite tests various expressions that are used as dimension
|
| 139 |
+
specifications.
|
| 140 |
+
|
| 141 |
+
There exists two usage cases where analyzing dimensions
|
| 142 |
+
specifications are important.
|
| 143 |
+
|
| 144 |
+
In the first case, the size of output arrays must be defined based
|
| 145 |
+
on the inputs to a Fortran function. Because Fortran supports
|
| 146 |
+
arbitrary bases for indexing, for instance, `arr(lower:upper)`,
|
| 147 |
+
f2py has to evaluate an expression `upper - lower + 1` where
|
| 148 |
+
`lower` and `upper` are arbitrary expressions of input parameters.
|
| 149 |
+
The evaluation is performed in C, so f2py has to translate Fortran
|
| 150 |
+
expressions to valid C expressions (an alternative approach is
|
| 151 |
+
that a developer specifies the corresponding C expressions in a
|
| 152 |
+
.pyf file).
|
| 153 |
+
|
| 154 |
+
In the second case, when user provides an input array with a given
|
| 155 |
+
size but some hidden parameters used in dimensions specifications
|
| 156 |
+
need to be determined based on the input array size. This is a
|
| 157 |
+
harder problem because f2py has to solve the inverse problem: find
|
| 158 |
+
a parameter `p` such that `upper(p) - lower(p) + 1` equals to the
|
| 159 |
+
size of input array. In the case when this equation cannot be
|
| 160 |
+
solved (e.g. because the input array size is wrong), raise an
|
| 161 |
+
error before calling the Fortran function (that otherwise would
|
| 162 |
+
likely crash Python process when the size of input arrays is
|
| 163 |
+
wrong). f2py currently supports this case only when the equation
|
| 164 |
+
is linear with respect to unknown parameter.
|
| 165 |
+
|
| 166 |
+
"""
|
| 167 |
+
|
| 168 |
+
suffix = ".f90"
|
| 169 |
+
|
| 170 |
+
code_template = textwrap.dedent("""
|
| 171 |
+
function get_arr_size_{count}(a, n) result (length)
|
| 172 |
+
integer, intent(in) :: n
|
| 173 |
+
integer, dimension({dimspec}), intent(out) :: a
|
| 174 |
+
integer length
|
| 175 |
+
length = size(a)
|
| 176 |
+
end function
|
| 177 |
+
|
| 178 |
+
subroutine get_inv_arr_size_{count}(a, n)
|
| 179 |
+
integer :: n
|
| 180 |
+
! the value of n is computed in f2py wrapper
|
| 181 |
+
!f2py intent(out) n
|
| 182 |
+
integer, dimension({dimspec}), intent(in) :: a
|
| 183 |
+
if (a({first}).gt.0) then
|
| 184 |
+
print*, "a=", a
|
| 185 |
+
endif
|
| 186 |
+
end subroutine
|
| 187 |
+
""")
|
| 188 |
+
|
| 189 |
+
linear_dimspecs = [
|
| 190 |
+
"n", "2*n", "2:n", "n/2", "5 - n/2", "3*n:20", "n*(n+1):n*(n+5)",
|
| 191 |
+
"2*n, n"
|
| 192 |
+
]
|
| 193 |
+
nonlinear_dimspecs = ["2*n:3*n*n+2*n"]
|
| 194 |
+
all_dimspecs = linear_dimspecs + nonlinear_dimspecs
|
| 195 |
+
|
| 196 |
+
code = ""
|
| 197 |
+
for count, dimspec in enumerate(all_dimspecs):
|
| 198 |
+
lst = [(d.split(":")[0] if ":" in d else "1") for d in dimspec.split(',')]
|
| 199 |
+
code += code_template.format(
|
| 200 |
+
count=count,
|
| 201 |
+
dimspec=dimspec,
|
| 202 |
+
first=", ".join(lst),
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
@pytest.mark.parametrize("dimspec", all_dimspecs)
|
| 206 |
+
def test_array_size(self, dimspec):
|
| 207 |
+
|
| 208 |
+
count = self.all_dimspecs.index(dimspec)
|
| 209 |
+
get_arr_size = getattr(self.module, f"get_arr_size_{count}")
|
| 210 |
+
|
| 211 |
+
for n in [1, 2, 3, 4, 5]:
|
| 212 |
+
sz, a = get_arr_size(n)
|
| 213 |
+
assert a.size == sz
|
| 214 |
+
|
| 215 |
+
@pytest.mark.parametrize("dimspec", all_dimspecs)
|
| 216 |
+
def test_inv_array_size(self, dimspec):
|
| 217 |
+
|
| 218 |
+
count = self.all_dimspecs.index(dimspec)
|
| 219 |
+
get_arr_size = getattr(self.module, f"get_arr_size_{count}")
|
| 220 |
+
get_inv_arr_size = getattr(self.module, f"get_inv_arr_size_{count}")
|
| 221 |
+
|
| 222 |
+
for n in [1, 2, 3, 4, 5]:
|
| 223 |
+
sz, a = get_arr_size(n)
|
| 224 |
+
if dimspec in self.nonlinear_dimspecs:
|
| 225 |
+
# one must specify n as input, the call we'll ensure
|
| 226 |
+
# that a and n are compatible:
|
| 227 |
+
n1 = get_inv_arr_size(a, n)
|
| 228 |
+
else:
|
| 229 |
+
# in case of linear dependence, n can be determined
|
| 230 |
+
# from the shape of a:
|
| 231 |
+
n1 = get_inv_arr_size(a)
|
| 232 |
+
# n1 may be different from n (for instance, when `a` size
|
| 233 |
+
# is a function of some `n` fraction) but it must produce
|
| 234 |
+
# the same sized array
|
| 235 |
+
sz1, _ = get_arr_size(n1)
|
| 236 |
+
assert sz == sz1, (n, n1, sz, sz1)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class TestModuleDeclaration:
|
| 240 |
+
def test_dependencies(self, tmp_path):
|
| 241 |
+
fpath = util.getpath("tests", "src", "crackfortran", "foo_deps.f90")
|
| 242 |
+
mod = crackfortran.crackfortran([str(fpath)])
|
| 243 |
+
assert len(mod) == 1
|
| 244 |
+
assert mod[0]["vars"]["abar"]["="] == "bar('abar')"
|
| 245 |
+
|
| 246 |
+
class TestEval(util.F2PyTest):
|
| 247 |
+
def test_eval_scalar(self):
|
| 248 |
+
eval_scalar = crackfortran._eval_scalar
|
| 249 |
+
|
| 250 |
+
assert eval_scalar('123', {}) == '123'
|
| 251 |
+
assert eval_scalar('12 + 3', {}) == '15'
|
| 252 |
+
assert eval_scalar('a + b', dict(a=1, b=2)) == '3'
|
| 253 |
+
assert eval_scalar('"123"', {}) == "'123'"
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class TestFortranReader(util.F2PyTest):
|
| 257 |
+
@pytest.mark.parametrize("encoding",
|
| 258 |
+
['ascii', 'utf-8', 'utf-16', 'utf-32'])
|
| 259 |
+
def test_input_encoding(self, tmp_path, encoding):
|
| 260 |
+
# gh-635
|
| 261 |
+
f_path = tmp_path / f"input_with_{encoding}_encoding.f90"
|
| 262 |
+
with f_path.open('w', encoding=encoding) as ff:
|
| 263 |
+
ff.write("""
|
| 264 |
+
subroutine foo()
|
| 265 |
+
end subroutine foo
|
| 266 |
+
""")
|
| 267 |
+
mod = crackfortran.crackfortran([str(f_path)])
|
| 268 |
+
assert mod[0]['name'] == 'foo'
|
| 269 |
+
|
| 270 |
+
class TestUnicodeComment(util.F2PyTest):
|
| 271 |
+
sources = [util.getpath("tests", "src", "crackfortran", "unicode_comment.f90")]
|
| 272 |
+
|
| 273 |
+
@pytest.mark.skipif(
|
| 274 |
+
(importlib.util.find_spec("charset_normalizer") is None),
|
| 275 |
+
reason="test requires charset_normalizer which is not installed",
|
| 276 |
+
)
|
| 277 |
+
def test_encoding_comment(self):
|
| 278 |
+
self.module.foo(3)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/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
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_f2cmap.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import util
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
class TestF2Cmap(util.F2PyTest):
|
| 5 |
+
sources = [
|
| 6 |
+
util.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90"),
|
| 7 |
+
util.getpath("tests", "src", "f2cmap", ".f2py_f2cmap")
|
| 8 |
+
]
|
| 9 |
+
|
| 10 |
+
# gh-15095
|
| 11 |
+
def test_long_long_map(self):
|
| 12 |
+
inp = np.ones(3)
|
| 13 |
+
out = self.module.func1(inp)
|
| 14 |
+
exp_out = 3
|
| 15 |
+
assert out == exp_out
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_parameter.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from . import util
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TestParameters(util.F2PyTest):
|
| 10 |
+
# Check that intent(in out) translates as intent(inout)
|
| 11 |
+
sources = [
|
| 12 |
+
util.getpath("tests", "src", "parameter", "constant_real.f90"),
|
| 13 |
+
util.getpath("tests", "src", "parameter", "constant_integer.f90"),
|
| 14 |
+
util.getpath("tests", "src", "parameter", "constant_both.f90"),
|
| 15 |
+
util.getpath("tests", "src", "parameter", "constant_compound.f90"),
|
| 16 |
+
util.getpath("tests", "src", "parameter", "constant_non_compound.f90"),
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
@pytest.mark.slow
|
| 20 |
+
def test_constant_real_single(self):
|
| 21 |
+
# non-contiguous should raise error
|
| 22 |
+
x = np.arange(6, dtype=np.float32)[::2]
|
| 23 |
+
pytest.raises(ValueError, self.module.foo_single, x)
|
| 24 |
+
|
| 25 |
+
# check values with contiguous array
|
| 26 |
+
x = np.arange(3, dtype=np.float32)
|
| 27 |
+
self.module.foo_single(x)
|
| 28 |
+
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2])
|
| 29 |
+
|
| 30 |
+
@pytest.mark.slow
|
| 31 |
+
def test_constant_real_double(self):
|
| 32 |
+
# non-contiguous should raise error
|
| 33 |
+
x = np.arange(6, dtype=np.float64)[::2]
|
| 34 |
+
pytest.raises(ValueError, self.module.foo_double, x)
|
| 35 |
+
|
| 36 |
+
# check values with contiguous array
|
| 37 |
+
x = np.arange(3, dtype=np.float64)
|
| 38 |
+
self.module.foo_double(x)
|
| 39 |
+
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2])
|
| 40 |
+
|
| 41 |
+
@pytest.mark.slow
|
| 42 |
+
def test_constant_compound_int(self):
|
| 43 |
+
# non-contiguous should raise error
|
| 44 |
+
x = np.arange(6, dtype=np.int32)[::2]
|
| 45 |
+
pytest.raises(ValueError, self.module.foo_compound_int, x)
|
| 46 |
+
|
| 47 |
+
# check values with contiguous array
|
| 48 |
+
x = np.arange(3, dtype=np.int32)
|
| 49 |
+
self.module.foo_compound_int(x)
|
| 50 |
+
assert np.allclose(x, [0 + 1 + 2 * 6, 1, 2])
|
| 51 |
+
|
| 52 |
+
@pytest.mark.slow
|
| 53 |
+
def test_constant_non_compound_int(self):
|
| 54 |
+
# check values
|
| 55 |
+
x = np.arange(4, dtype=np.int32)
|
| 56 |
+
self.module.foo_non_compound_int(x)
|
| 57 |
+
assert np.allclose(x, [0 + 1 + 2 + 3 * 4, 1, 2, 3])
|
| 58 |
+
|
| 59 |
+
@pytest.mark.slow
|
| 60 |
+
def test_constant_integer_int(self):
|
| 61 |
+
# non-contiguous should raise error
|
| 62 |
+
x = np.arange(6, dtype=np.int32)[::2]
|
| 63 |
+
pytest.raises(ValueError, self.module.foo_int, x)
|
| 64 |
+
|
| 65 |
+
# check values with contiguous array
|
| 66 |
+
x = np.arange(3, dtype=np.int32)
|
| 67 |
+
self.module.foo_int(x)
|
| 68 |
+
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2])
|
| 69 |
+
|
| 70 |
+
@pytest.mark.slow
|
| 71 |
+
def test_constant_integer_long(self):
|
| 72 |
+
# non-contiguous should raise error
|
| 73 |
+
x = np.arange(6, dtype=np.int64)[::2]
|
| 74 |
+
pytest.raises(ValueError, self.module.foo_long, x)
|
| 75 |
+
|
| 76 |
+
# check values with contiguous array
|
| 77 |
+
x = np.arange(3, dtype=np.int64)
|
| 78 |
+
self.module.foo_long(x)
|
| 79 |
+
assert np.allclose(x, [0 + 1 + 2 * 3, 1, 2])
|
| 80 |
+
|
| 81 |
+
@pytest.mark.slow
|
| 82 |
+
def test_constant_both(self):
|
| 83 |
+
# non-contiguous should raise error
|
| 84 |
+
x = np.arange(6, dtype=np.float64)[::2]
|
| 85 |
+
pytest.raises(ValueError, self.module.foo, x)
|
| 86 |
+
|
| 87 |
+
# check values with contiguous array
|
| 88 |
+
x = np.arange(3, dtype=np.float64)
|
| 89 |
+
self.module.foo(x)
|
| 90 |
+
assert np.allclose(x, [0 + 1 * 3 * 3 + 2 * 3 * 3, 1 * 3, 2 * 3])
|
| 91 |
+
|
| 92 |
+
@pytest.mark.slow
|
| 93 |
+
def test_constant_no(self):
|
| 94 |
+
# non-contiguous should raise error
|
| 95 |
+
x = np.arange(6, dtype=np.float64)[::2]
|
| 96 |
+
pytest.raises(ValueError, self.module.foo_no, x)
|
| 97 |
+
|
| 98 |
+
# check values with contiguous array
|
| 99 |
+
x = np.arange(3, dtype=np.float64)
|
| 100 |
+
self.module.foo_no(x)
|
| 101 |
+
assert np.allclose(x, [0 + 1 * 3 * 3 + 2 * 3 * 3, 1 * 3, 2 * 3])
|
| 102 |
+
|
| 103 |
+
@pytest.mark.slow
|
| 104 |
+
def test_constant_sum(self):
|
| 105 |
+
# non-contiguous should raise error
|
| 106 |
+
x = np.arange(6, dtype=np.float64)[::2]
|
| 107 |
+
pytest.raises(ValueError, self.module.foo_sum, x)
|
| 108 |
+
|
| 109 |
+
# check values with contiguous array
|
| 110 |
+
x = np.arange(3, dtype=np.float64)
|
| 111 |
+
self.module.foo_sum(x)
|
| 112 |
+
assert np.allclose(x, [0 + 1 * 3 * 3 + 2 * 3 * 3, 1 * 3, 2 * 3])
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/test_return_logical.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from numpy import array
|
| 4 |
+
from . import util
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestReturnLogical(util.F2PyTest):
|
| 8 |
+
def check_function(self, t):
|
| 9 |
+
assert t(True) == 1
|
| 10 |
+
assert t(False) == 0
|
| 11 |
+
assert t(0) == 0
|
| 12 |
+
assert t(None) == 0
|
| 13 |
+
assert t(0.0) == 0
|
| 14 |
+
assert t(0j) == 0
|
| 15 |
+
assert t(1j) == 1
|
| 16 |
+
assert t(234) == 1
|
| 17 |
+
assert t(234.6) == 1
|
| 18 |
+
assert t(234.6 + 3j) == 1
|
| 19 |
+
assert t("234") == 1
|
| 20 |
+
assert t("aaa") == 1
|
| 21 |
+
assert t("") == 0
|
| 22 |
+
assert t([]) == 0
|
| 23 |
+
assert t(()) == 0
|
| 24 |
+
assert t({}) == 0
|
| 25 |
+
assert t(t) == 1
|
| 26 |
+
assert t(-234) == 1
|
| 27 |
+
assert t(10**100) == 1
|
| 28 |
+
assert t([234]) == 1
|
| 29 |
+
assert t((234, )) == 1
|
| 30 |
+
assert t(array(234)) == 1
|
| 31 |
+
assert t(array([234])) == 1
|
| 32 |
+
assert t(array([[234]])) == 1
|
| 33 |
+
assert t(array([127], "b")) == 1
|
| 34 |
+
assert t(array([234], "h")) == 1
|
| 35 |
+
assert t(array([234], "i")) == 1
|
| 36 |
+
assert t(array([234], "l")) == 1
|
| 37 |
+
assert t(array([234], "f")) == 1
|
| 38 |
+
assert t(array([234], "d")) == 1
|
| 39 |
+
assert t(array([234 + 3j], "F")) == 1
|
| 40 |
+
assert t(array([234], "D")) == 1
|
| 41 |
+
assert t(array(0)) == 0
|
| 42 |
+
assert t(array([0])) == 0
|
| 43 |
+
assert t(array([[0]])) == 0
|
| 44 |
+
assert t(array([0j])) == 0
|
| 45 |
+
assert t(array([1])) == 1
|
| 46 |
+
pytest.raises(ValueError, t, array([0, 0]))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class TestFReturnLogical(TestReturnLogical):
|
| 50 |
+
sources = [
|
| 51 |
+
util.getpath("tests", "src", "return_logical", "foo77.f"),
|
| 52 |
+
util.getpath("tests", "src", "return_logical", "foo90.f90"),
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
@pytest.mark.slow
|
| 56 |
+
@pytest.mark.parametrize("name", "t0,t1,t2,t4,s0,s1,s2,s4".split(","))
|
| 57 |
+
def test_all_f77(self, name):
|
| 58 |
+
self.check_function(getattr(self.module, name))
|
| 59 |
+
|
| 60 |
+
@pytest.mark.slow
|
| 61 |
+
@pytest.mark.parametrize("name",
|
| 62 |
+
"t0,t1,t2,t4,t8,s0,s1,s2,s4,s8".split(","))
|
| 63 |
+
def test_all_f90(self, name):
|
| 64 |
+
self.check_function(getattr(self.module.f90_return_logical, name))
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/tests/util.py
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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are present
|
| 6 |
+
- determining paths to tests
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import subprocess
|
| 12 |
+
import tempfile
|
| 13 |
+
import shutil
|
| 14 |
+
import atexit
|
| 15 |
+
import textwrap
|
| 16 |
+
import re
|
| 17 |
+
import pytest
|
| 18 |
+
import contextlib
|
| 19 |
+
import numpy
|
| 20 |
+
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
from numpy.compat import asbytes, asstr
|
| 23 |
+
from numpy.testing import temppath, IS_WASM
|
| 24 |
+
from importlib import import_module
|
| 25 |
+
|
| 26 |
+
#
|
| 27 |
+
# Maintaining a temporary module directory
|
| 28 |
+
#
|
| 29 |
+
|
| 30 |
+
_module_dir = None
|
| 31 |
+
_module_num = 5403
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _cleanup():
|
| 35 |
+
global _module_dir
|
| 36 |
+
if _module_dir is not None:
|
| 37 |
+
try:
|
| 38 |
+
sys.path.remove(_module_dir)
|
| 39 |
+
except ValueError:
|
| 40 |
+
pass
|
| 41 |
+
try:
|
| 42 |
+
shutil.rmtree(_module_dir)
|
| 43 |
+
except OSError:
|
| 44 |
+
pass
|
| 45 |
+
_module_dir = None
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def get_module_dir():
|
| 49 |
+
global _module_dir
|
| 50 |
+
if _module_dir is None:
|
| 51 |
+
_module_dir = tempfile.mkdtemp()
|
| 52 |
+
atexit.register(_cleanup)
|
| 53 |
+
if _module_dir not in sys.path:
|
| 54 |
+
sys.path.insert(0, _module_dir)
|
| 55 |
+
return _module_dir
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def get_temp_module_name():
|
| 59 |
+
# Assume single-threaded, and the module dir usable only by this thread
|
| 60 |
+
global _module_num
|
| 61 |
+
get_module_dir()
|
| 62 |
+
name = "_test_ext_module_%d" % _module_num
|
| 63 |
+
_module_num += 1
|
| 64 |
+
if name in sys.modules:
|
| 65 |
+
# this should not be possible, but check anyway
|
| 66 |
+
raise RuntimeError("Temporary module name already in use.")
|
| 67 |
+
return name
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _memoize(func):
|
| 71 |
+
memo = {}
|
| 72 |
+
|
| 73 |
+
def wrapper(*a, **kw):
|
| 74 |
+
key = repr((a, kw))
|
| 75 |
+
if key not in memo:
|
| 76 |
+
try:
|
| 77 |
+
memo[key] = func(*a, **kw)
|
| 78 |
+
except Exception as e:
|
| 79 |
+
memo[key] = e
|
| 80 |
+
raise
|
| 81 |
+
ret = memo[key]
|
| 82 |
+
if isinstance(ret, Exception):
|
| 83 |
+
raise ret
|
| 84 |
+
return ret
|
| 85 |
+
|
| 86 |
+
wrapper.__name__ = func.__name__
|
| 87 |
+
return wrapper
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
#
|
| 91 |
+
# Building modules
|
| 92 |
+
#
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@_memoize
|
| 96 |
+
def build_module(source_files, options=[], skip=[], only=[], module_name=None):
|
| 97 |
+
"""
|
| 98 |
+
Compile and import a f2py module, built from the given files.
|
| 99 |
+
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
code = f"import sys; sys.path = {sys.path!r}; import numpy.f2py; numpy.f2py.main()"
|
| 103 |
+
|
| 104 |
+
d = get_module_dir()
|
| 105 |
+
|
| 106 |
+
# Copy files
|
| 107 |
+
dst_sources = []
|
| 108 |
+
f2py_sources = []
|
| 109 |
+
for fn in source_files:
|
| 110 |
+
if not os.path.isfile(fn):
|
| 111 |
+
raise RuntimeError("%s is not a file" % fn)
|
| 112 |
+
dst = os.path.join(d, os.path.basename(fn))
|
| 113 |
+
shutil.copyfile(fn, dst)
|
| 114 |
+
dst_sources.append(dst)
|
| 115 |
+
|
| 116 |
+
base, ext = os.path.splitext(dst)
|
| 117 |
+
if ext in (".f90", ".f", ".c", ".pyf"):
|
| 118 |
+
f2py_sources.append(dst)
|
| 119 |
+
|
| 120 |
+
assert f2py_sources
|
| 121 |
+
|
| 122 |
+
# Prepare options
|
| 123 |
+
if module_name is None:
|
| 124 |
+
module_name = get_temp_module_name()
|
| 125 |
+
f2py_opts = ["-c", "-m", module_name] + options + f2py_sources
|
| 126 |
+
if skip:
|
| 127 |
+
f2py_opts += ["skip:"] + skip
|
| 128 |
+
if only:
|
| 129 |
+
f2py_opts += ["only:"] + only
|
| 130 |
+
|
| 131 |
+
# Build
|
| 132 |
+
cwd = os.getcwd()
|
| 133 |
+
try:
|
| 134 |
+
os.chdir(d)
|
| 135 |
+
cmd = [sys.executable, "-c", code] + f2py_opts
|
| 136 |
+
p = subprocess.Popen(cmd,
|
| 137 |
+
stdout=subprocess.PIPE,
|
| 138 |
+
stderr=subprocess.STDOUT)
|
| 139 |
+
out, err = p.communicate()
|
| 140 |
+
if p.returncode != 0:
|
| 141 |
+
raise RuntimeError("Running f2py failed: %s\n%s" %
|
| 142 |
+
(cmd[4:], asstr(out)))
|
| 143 |
+
finally:
|
| 144 |
+
os.chdir(cwd)
|
| 145 |
+
|
| 146 |
+
# Partial cleanup
|
| 147 |
+
for fn in dst_sources:
|
| 148 |
+
os.unlink(fn)
|
| 149 |
+
|
| 150 |
+
# Import
|
| 151 |
+
return import_module(module_name)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@_memoize
|
| 155 |
+
def build_code(source_code,
|
| 156 |
+
options=[],
|
| 157 |
+
skip=[],
|
| 158 |
+
only=[],
|
| 159 |
+
suffix=None,
|
| 160 |
+
module_name=None):
|
| 161 |
+
"""
|
| 162 |
+
Compile and import Fortran code using f2py.
|
| 163 |
+
|
| 164 |
+
"""
|
| 165 |
+
if suffix is None:
|
| 166 |
+
suffix = ".f"
|
| 167 |
+
with temppath(suffix=suffix) as path:
|
| 168 |
+
with open(path, "w") as f:
|
| 169 |
+
f.write(source_code)
|
| 170 |
+
return build_module([path],
|
| 171 |
+
options=options,
|
| 172 |
+
skip=skip,
|
| 173 |
+
only=only,
|
| 174 |
+
module_name=module_name)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
#
|
| 178 |
+
# Check if compilers are available at all...
|
| 179 |
+
#
|
| 180 |
+
|
| 181 |
+
_compiler_status = None
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def _get_compiler_status():
|
| 185 |
+
global _compiler_status
|
| 186 |
+
if _compiler_status is not None:
|
| 187 |
+
return _compiler_status
|
| 188 |
+
|
| 189 |
+
_compiler_status = (False, False, False)
|
| 190 |
+
if IS_WASM:
|
| 191 |
+
# Can't run compiler from inside WASM.
|
| 192 |
+
return _compiler_status
|
| 193 |
+
|
| 194 |
+
# XXX: this is really ugly. But I don't know how to invoke Distutils
|
| 195 |
+
# in a safer way...
|
| 196 |
+
code = textwrap.dedent(f"""\
|
| 197 |
+
import os
|
| 198 |
+
import sys
|
| 199 |
+
sys.path = {repr(sys.path)}
|
| 200 |
+
|
| 201 |
+
def configuration(parent_name='',top_path=None):
|
| 202 |
+
global config
|
| 203 |
+
from numpy.distutils.misc_util import Configuration
|
| 204 |
+
config = Configuration('', parent_name, top_path)
|
| 205 |
+
return config
|
| 206 |
+
|
| 207 |
+
from numpy.distutils.core import setup
|
| 208 |
+
setup(configuration=configuration)
|
| 209 |
+
|
| 210 |
+
config_cmd = config.get_config_cmd()
|
| 211 |
+
have_c = config_cmd.try_compile('void foo() {{}}')
|
| 212 |
+
print('COMPILERS:%%d,%%d,%%d' %% (have_c,
|
| 213 |
+
config.have_f77c(),
|
| 214 |
+
config.have_f90c()))
|
| 215 |
+
sys.exit(99)
|
| 216 |
+
""")
|
| 217 |
+
code = code % dict(syspath=repr(sys.path))
|
| 218 |
+
|
| 219 |
+
tmpdir = tempfile.mkdtemp()
|
| 220 |
+
try:
|
| 221 |
+
script = os.path.join(tmpdir, "setup.py")
|
| 222 |
+
|
| 223 |
+
with open(script, "w") as f:
|
| 224 |
+
f.write(code)
|
| 225 |
+
|
| 226 |
+
cmd = [sys.executable, "setup.py", "config"]
|
| 227 |
+
p = subprocess.Popen(cmd,
|
| 228 |
+
stdout=subprocess.PIPE,
|
| 229 |
+
stderr=subprocess.STDOUT,
|
| 230 |
+
cwd=tmpdir)
|
| 231 |
+
out, err = p.communicate()
|
| 232 |
+
finally:
|
| 233 |
+
shutil.rmtree(tmpdir)
|
| 234 |
+
|
| 235 |
+
m = re.search(br"COMPILERS:(\d+),(\d+),(\d+)", out)
|
| 236 |
+
if m:
|
| 237 |
+
_compiler_status = (
|
| 238 |
+
bool(int(m.group(1))),
|
| 239 |
+
bool(int(m.group(2))),
|
| 240 |
+
bool(int(m.group(3))),
|
| 241 |
+
)
|
| 242 |
+
# Finished
|
| 243 |
+
return _compiler_status
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def has_c_compiler():
|
| 247 |
+
return _get_compiler_status()[0]
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def has_f77_compiler():
|
| 251 |
+
return _get_compiler_status()[1]
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def has_f90_compiler():
|
| 255 |
+
return _get_compiler_status()[2]
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
#
|
| 259 |
+
# Building with distutils
|
| 260 |
+
#
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
@_memoize
|
| 264 |
+
def build_module_distutils(source_files, config_code, module_name, **kw):
|
| 265 |
+
"""
|
| 266 |
+
Build a module via distutils and import it.
|
| 267 |
+
|
| 268 |
+
"""
|
| 269 |
+
d = get_module_dir()
|
| 270 |
+
|
| 271 |
+
# Copy files
|
| 272 |
+
dst_sources = []
|
| 273 |
+
for fn in source_files:
|
| 274 |
+
if not os.path.isfile(fn):
|
| 275 |
+
raise RuntimeError("%s is not a file" % fn)
|
| 276 |
+
dst = os.path.join(d, os.path.basename(fn))
|
| 277 |
+
shutil.copyfile(fn, dst)
|
| 278 |
+
dst_sources.append(dst)
|
| 279 |
+
|
| 280 |
+
# Build script
|
| 281 |
+
config_code = textwrap.dedent(config_code).replace("\n", "\n ")
|
| 282 |
+
|
| 283 |
+
code = fr"""
|
| 284 |
+
import os
|
| 285 |
+
import sys
|
| 286 |
+
sys.path = {repr(sys.path)}
|
| 287 |
+
|
| 288 |
+
def configuration(parent_name='',top_path=None):
|
| 289 |
+
from numpy.distutils.misc_util import Configuration
|
| 290 |
+
config = Configuration('', parent_name, top_path)
|
| 291 |
+
{config_code}
|
| 292 |
+
return config
|
| 293 |
+
|
| 294 |
+
if __name__ == "__main__":
|
| 295 |
+
from numpy.distutils.core import setup
|
| 296 |
+
setup(configuration=configuration)
|
| 297 |
+
"""
|
| 298 |
+
script = os.path.join(d, get_temp_module_name() + ".py")
|
| 299 |
+
dst_sources.append(script)
|
| 300 |
+
with open(script, "wb") as f:
|
| 301 |
+
f.write(asbytes(code))
|
| 302 |
+
|
| 303 |
+
# Build
|
| 304 |
+
cwd = os.getcwd()
|
| 305 |
+
try:
|
| 306 |
+
os.chdir(d)
|
| 307 |
+
cmd = [sys.executable, script, "build_ext", "-i"]
|
| 308 |
+
p = subprocess.Popen(cmd,
|
| 309 |
+
stdout=subprocess.PIPE,
|
| 310 |
+
stderr=subprocess.STDOUT)
|
| 311 |
+
out, err = p.communicate()
|
| 312 |
+
if p.returncode != 0:
|
| 313 |
+
raise RuntimeError("Running distutils build failed: %s\n%s" %
|
| 314 |
+
(cmd[4:], asstr(out)))
|
| 315 |
+
finally:
|
| 316 |
+
os.chdir(cwd)
|
| 317 |
+
|
| 318 |
+
# Partial cleanup
|
| 319 |
+
for fn in dst_sources:
|
| 320 |
+
os.unlink(fn)
|
| 321 |
+
|
| 322 |
+
# Import
|
| 323 |
+
__import__(module_name)
|
| 324 |
+
return sys.modules[module_name]
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
#
|
| 328 |
+
# Unittest convenience
|
| 329 |
+
#
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
class F2PyTest:
|
| 333 |
+
code = None
|
| 334 |
+
sources = None
|
| 335 |
+
options = []
|
| 336 |
+
skip = []
|
| 337 |
+
only = []
|
| 338 |
+
suffix = ".f"
|
| 339 |
+
module = None
|
| 340 |
+
|
| 341 |
+
@property
|
| 342 |
+
def module_name(self):
|
| 343 |
+
cls = type(self)
|
| 344 |
+
return f'_{cls.__module__.rsplit(".",1)[-1]}_{cls.__name__}_ext_module'
|
| 345 |
+
|
| 346 |
+
def setup_method(self):
|
| 347 |
+
if sys.platform == "win32":
|
| 348 |
+
pytest.skip("Fails with MinGW64 Gfortran (Issue #9673)")
|
| 349 |
+
|
| 350 |
+
if self.module is not None:
|
| 351 |
+
return
|
| 352 |
+
|
| 353 |
+
# Check compiler availability first
|
| 354 |
+
if not has_c_compiler():
|
| 355 |
+
pytest.skip("No C compiler available")
|
| 356 |
+
|
| 357 |
+
codes = []
|
| 358 |
+
if self.sources:
|
| 359 |
+
codes.extend(self.sources)
|
| 360 |
+
if self.code is not None:
|
| 361 |
+
codes.append(self.suffix)
|
| 362 |
+
|
| 363 |
+
needs_f77 = False
|
| 364 |
+
needs_f90 = False
|
| 365 |
+
needs_pyf = False
|
| 366 |
+
for fn in codes:
|
| 367 |
+
if str(fn).endswith(".f"):
|
| 368 |
+
needs_f77 = True
|
| 369 |
+
elif str(fn).endswith(".f90"):
|
| 370 |
+
needs_f90 = True
|
| 371 |
+
elif str(fn).endswith(".pyf"):
|
| 372 |
+
needs_pyf = True
|
| 373 |
+
if needs_f77 and not has_f77_compiler():
|
| 374 |
+
pytest.skip("No Fortran 77 compiler available")
|
| 375 |
+
if needs_f90 and not has_f90_compiler():
|
| 376 |
+
pytest.skip("No Fortran 90 compiler available")
|
| 377 |
+
if needs_pyf and not (has_f90_compiler() or has_f77_compiler()):
|
| 378 |
+
pytest.skip("No Fortran compiler available")
|
| 379 |
+
|
| 380 |
+
# Build the module
|
| 381 |
+
if self.code is not None:
|
| 382 |
+
self.module = build_code(
|
| 383 |
+
self.code,
|
| 384 |
+
options=self.options,
|
| 385 |
+
skip=self.skip,
|
| 386 |
+
only=self.only,
|
| 387 |
+
suffix=self.suffix,
|
| 388 |
+
module_name=self.module_name,
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
if self.sources is not None:
|
| 392 |
+
self.module = build_module(
|
| 393 |
+
self.sources,
|
| 394 |
+
options=self.options,
|
| 395 |
+
skip=self.skip,
|
| 396 |
+
only=self.only,
|
| 397 |
+
module_name=self.module_name,
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
#
|
| 402 |
+
# Helper functions
|
| 403 |
+
#
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def getpath(*a):
|
| 407 |
+
# Package root
|
| 408 |
+
d = Path(numpy.f2py.__file__).parent.resolve()
|
| 409 |
+
return d.joinpath(*a)
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
@contextlib.contextmanager
|
| 413 |
+
def switchdir(path):
|
| 414 |
+
curpath = Path.cwd()
|
| 415 |
+
os.chdir(path)
|
| 416 |
+
try:
|
| 417 |
+
yield
|
| 418 |
+
finally:
|
| 419 |
+
os.chdir(curpath)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/f2py/use_rules.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
Build 'use others module data' mechanism for f2py2e.
|
| 5 |
+
|
| 6 |
+
Unfinished.
|
| 7 |
+
|
| 8 |
+
Copyright 2000 Pearu Peterson all rights reserved,
|
| 9 |
+
Pearu Peterson <pearu@ioc.ee>
|
| 10 |
+
Permission to use, modify, and distribute this software is given under the
|
| 11 |
+
terms of the NumPy License.
|
| 12 |
+
|
| 13 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
| 14 |
+
$Date: 2000/09/10 12:35:43 $
|
| 15 |
+
Pearu Peterson
|
| 16 |
+
|
| 17 |
+
"""
|
| 18 |
+
__version__ = "$Revision: 1.3 $"[10:-1]
|
| 19 |
+
|
| 20 |
+
f2py_version = 'See `f2py -v`'
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
from .auxfuncs import (
|
| 24 |
+
applyrules, dictappend, gentitle, hasnote, outmess
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
usemodule_rules = {
|
| 29 |
+
'body': """
|
| 30 |
+
#begintitle#
|
| 31 |
+
static char doc_#apiname#[] = \"\\\nVariable wrapper signature:\\n\\
|
| 32 |
+
\t #name# = get_#name#()\\n\\
|
| 33 |
+
Arguments:\\n\\
|
| 34 |
+
#docstr#\";
|
| 35 |
+
extern F_MODFUNC(#usemodulename#,#USEMODULENAME#,#realname#,#REALNAME#);
|
| 36 |
+
static PyObject *#apiname#(PyObject *capi_self, PyObject *capi_args) {
|
| 37 |
+
/*#decl#*/
|
| 38 |
+
\tif (!PyArg_ParseTuple(capi_args, \"\")) goto capi_fail;
|
| 39 |
+
printf(\"c: %d\\n\",F_MODFUNC(#usemodulename#,#USEMODULENAME#,#realname#,#REALNAME#));
|
| 40 |
+
\treturn Py_BuildValue(\"\");
|
| 41 |
+
capi_fail:
|
| 42 |
+
\treturn NULL;
|
| 43 |
+
}
|
| 44 |
+
""",
|
| 45 |
+
'method': '\t{\"get_#name#\",#apiname#,METH_VARARGS|METH_KEYWORDS,doc_#apiname#},',
|
| 46 |
+
'need': ['F_MODFUNC']
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
################
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def buildusevars(m, r):
|
| 53 |
+
ret = {}
|
| 54 |
+
outmess(
|
| 55 |
+
'\t\tBuilding use variable hooks for module "%s" (feature only for F90/F95)...\n' % (m['name']))
|
| 56 |
+
varsmap = {}
|
| 57 |
+
revmap = {}
|
| 58 |
+
if 'map' in r:
|
| 59 |
+
for k in r['map'].keys():
|
| 60 |
+
if r['map'][k] in revmap:
|
| 61 |
+
outmess('\t\t\tVariable "%s<=%s" is already mapped by "%s". Skipping.\n' % (
|
| 62 |
+
r['map'][k], k, revmap[r['map'][k]]))
|
| 63 |
+
else:
|
| 64 |
+
revmap[r['map'][k]] = k
|
| 65 |
+
if 'only' in r and r['only']:
|
| 66 |
+
for v in r['map'].keys():
|
| 67 |
+
if r['map'][v] in m['vars']:
|
| 68 |
+
|
| 69 |
+
if revmap[r['map'][v]] == v:
|
| 70 |
+
varsmap[v] = r['map'][v]
|
| 71 |
+
else:
|
| 72 |
+
outmess('\t\t\tIgnoring map "%s=>%s". See above.\n' %
|
| 73 |
+
(v, r['map'][v]))
|
| 74 |
+
else:
|
| 75 |
+
outmess(
|
| 76 |
+
'\t\t\tNo definition for variable "%s=>%s". Skipping.\n' % (v, r['map'][v]))
|
| 77 |
+
else:
|
| 78 |
+
for v in m['vars'].keys():
|
| 79 |
+
if v in revmap:
|
| 80 |
+
varsmap[v] = revmap[v]
|
| 81 |
+
else:
|
| 82 |
+
varsmap[v] = v
|
| 83 |
+
for v in varsmap.keys():
|
| 84 |
+
ret = dictappend(ret, buildusevar(v, varsmap[v], m['vars'], m['name']))
|
| 85 |
+
return ret
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def buildusevar(name, realname, vars, usemodulename):
|
| 89 |
+
outmess('\t\t\tConstructing wrapper function for variable "%s=>%s"...\n' % (
|
| 90 |
+
name, realname))
|
| 91 |
+
ret = {}
|
| 92 |
+
vrd = {'name': name,
|
| 93 |
+
'realname': realname,
|
| 94 |
+
'REALNAME': realname.upper(),
|
| 95 |
+
'usemodulename': usemodulename,
|
| 96 |
+
'USEMODULENAME': usemodulename.upper(),
|
| 97 |
+
'texname': name.replace('_', '\\_'),
|
| 98 |
+
'begintitle': gentitle('%s=>%s' % (name, realname)),
|
| 99 |
+
'endtitle': gentitle('end of %s=>%s' % (name, realname)),
|
| 100 |
+
'apiname': '#modulename#_use_%s_from_%s' % (realname, usemodulename)
|
| 101 |
+
}
|
| 102 |
+
nummap = {0: 'Ro', 1: 'Ri', 2: 'Rii', 3: 'Riii', 4: 'Riv',
|
| 103 |
+
5: 'Rv', 6: 'Rvi', 7: 'Rvii', 8: 'Rviii', 9: 'Rix'}
|
| 104 |
+
vrd['texnamename'] = name
|
| 105 |
+
for i in nummap.keys():
|
| 106 |
+
vrd['texnamename'] = vrd['texnamename'].replace(repr(i), nummap[i])
|
| 107 |
+
if hasnote(vars[realname]):
|
| 108 |
+
vrd['note'] = vars[realname]['note']
|
| 109 |
+
rd = dictappend({}, vrd)
|
| 110 |
+
|
| 111 |
+
print(name, realname, vars[realname])
|
| 112 |
+
ret = applyrules(usemodule_rules, rd)
|
| 113 |
+
return ret
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
|
| 3 |
+
# 2018-05-29, PendingDeprecationWarning added to matrix.__new__
|
| 4 |
+
# 2020-01-23, numpy 1.19.0 PendingDeprecatonWarning
|
| 5 |
+
warnings.warn("Importing from numpy.matlib is deprecated since 1.19.0. "
|
| 6 |
+
"The matrix subclass is not the recommended way to represent "
|
| 7 |
+
"matrices or deal with linear algebra (see "
|
| 8 |
+
"https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). "
|
| 9 |
+
"Please adjust your code to use regular ndarray. ",
|
| 10 |
+
PendingDeprecationWarning, stacklevel=2)
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
from numpy.matrixlib.defmatrix import matrix, asmatrix
|
| 14 |
+
# Matlib.py contains all functions in the numpy namespace with a few
|
| 15 |
+
# replacements. See doc/source/reference/routines.matlib.rst for details.
|
| 16 |
+
# Need * as we're copying the numpy namespace.
|
| 17 |
+
from numpy import * # noqa: F403
|
| 18 |
+
|
| 19 |
+
__version__ = np.__version__
|
| 20 |
+
|
| 21 |
+
__all__ = np.__all__[:] # copy numpy namespace
|
| 22 |
+
__all__ += ['rand', 'randn', 'repmat']
|
| 23 |
+
|
| 24 |
+
def empty(shape, dtype=None, order='C'):
|
| 25 |
+
"""Return a new matrix of given shape and type, without initializing entries.
|
| 26 |
+
|
| 27 |
+
Parameters
|
| 28 |
+
----------
|
| 29 |
+
shape : int or tuple of int
|
| 30 |
+
Shape of the empty matrix.
|
| 31 |
+
dtype : data-type, optional
|
| 32 |
+
Desired output data-type.
|
| 33 |
+
order : {'C', 'F'}, optional
|
| 34 |
+
Whether to store multi-dimensional data in row-major
|
| 35 |
+
(C-style) or column-major (Fortran-style) order in
|
| 36 |
+
memory.
|
| 37 |
+
|
| 38 |
+
See Also
|
| 39 |
+
--------
|
| 40 |
+
empty_like, zeros
|
| 41 |
+
|
| 42 |
+
Notes
|
| 43 |
+
-----
|
| 44 |
+
`empty`, unlike `zeros`, does not set the matrix values to zero,
|
| 45 |
+
and may therefore be marginally faster. On the other hand, it requires
|
| 46 |
+
the user to manually set all the values in the array, and should be
|
| 47 |
+
used with caution.
|
| 48 |
+
|
| 49 |
+
Examples
|
| 50 |
+
--------
|
| 51 |
+
>>> import numpy.matlib
|
| 52 |
+
>>> np.matlib.empty((2, 2)) # filled with random data
|
| 53 |
+
matrix([[ 6.76425276e-320, 9.79033856e-307], # random
|
| 54 |
+
[ 7.39337286e-309, 3.22135945e-309]])
|
| 55 |
+
>>> np.matlib.empty((2, 2), dtype=int)
|
| 56 |
+
matrix([[ 6600475, 0], # random
|
| 57 |
+
[ 6586976, 22740995]])
|
| 58 |
+
|
| 59 |
+
"""
|
| 60 |
+
return ndarray.__new__(matrix, shape, dtype, order=order)
|
| 61 |
+
|
| 62 |
+
def ones(shape, dtype=None, order='C'):
|
| 63 |
+
"""
|
| 64 |
+
Matrix of ones.
|
| 65 |
+
|
| 66 |
+
Return a matrix of given shape and type, filled with ones.
|
| 67 |
+
|
| 68 |
+
Parameters
|
| 69 |
+
----------
|
| 70 |
+
shape : {sequence of ints, int}
|
| 71 |
+
Shape of the matrix
|
| 72 |
+
dtype : data-type, optional
|
| 73 |
+
The desired data-type for the matrix, default is np.float64.
|
| 74 |
+
order : {'C', 'F'}, optional
|
| 75 |
+
Whether to store matrix in C- or Fortran-contiguous order,
|
| 76 |
+
default is 'C'.
|
| 77 |
+
|
| 78 |
+
Returns
|
| 79 |
+
-------
|
| 80 |
+
out : matrix
|
| 81 |
+
Matrix of ones of given shape, dtype, and order.
|
| 82 |
+
|
| 83 |
+
See Also
|
| 84 |
+
--------
|
| 85 |
+
ones : Array of ones.
|
| 86 |
+
matlib.zeros : Zero matrix.
|
| 87 |
+
|
| 88 |
+
Notes
|
| 89 |
+
-----
|
| 90 |
+
If `shape` has length one i.e. ``(N,)``, or is a scalar ``N``,
|
| 91 |
+
`out` becomes a single row matrix of shape ``(1,N)``.
|
| 92 |
+
|
| 93 |
+
Examples
|
| 94 |
+
--------
|
| 95 |
+
>>> np.matlib.ones((2,3))
|
| 96 |
+
matrix([[1., 1., 1.],
|
| 97 |
+
[1., 1., 1.]])
|
| 98 |
+
|
| 99 |
+
>>> np.matlib.ones(2)
|
| 100 |
+
matrix([[1., 1.]])
|
| 101 |
+
|
| 102 |
+
"""
|
| 103 |
+
a = ndarray.__new__(matrix, shape, dtype, order=order)
|
| 104 |
+
a.fill(1)
|
| 105 |
+
return a
|
| 106 |
+
|
| 107 |
+
def zeros(shape, dtype=None, order='C'):
|
| 108 |
+
"""
|
| 109 |
+
Return a matrix of given shape and type, filled with zeros.
|
| 110 |
+
|
| 111 |
+
Parameters
|
| 112 |
+
----------
|
| 113 |
+
shape : int or sequence of ints
|
| 114 |
+
Shape of the matrix
|
| 115 |
+
dtype : data-type, optional
|
| 116 |
+
The desired data-type for the matrix, default is float.
|
| 117 |
+
order : {'C', 'F'}, optional
|
| 118 |
+
Whether to store the result in C- or Fortran-contiguous order,
|
| 119 |
+
default is 'C'.
|
| 120 |
+
|
| 121 |
+
Returns
|
| 122 |
+
-------
|
| 123 |
+
out : matrix
|
| 124 |
+
Zero matrix of given shape, dtype, and order.
|
| 125 |
+
|
| 126 |
+
See Also
|
| 127 |
+
--------
|
| 128 |
+
numpy.zeros : Equivalent array function.
|
| 129 |
+
matlib.ones : Return a matrix of ones.
|
| 130 |
+
|
| 131 |
+
Notes
|
| 132 |
+
-----
|
| 133 |
+
If `shape` has length one i.e. ``(N,)``, or is a scalar ``N``,
|
| 134 |
+
`out` becomes a single row matrix of shape ``(1,N)``.
|
| 135 |
+
|
| 136 |
+
Examples
|
| 137 |
+
--------
|
| 138 |
+
>>> import numpy.matlib
|
| 139 |
+
>>> np.matlib.zeros((2, 3))
|
| 140 |
+
matrix([[0., 0., 0.],
|
| 141 |
+
[0., 0., 0.]])
|
| 142 |
+
|
| 143 |
+
>>> np.matlib.zeros(2)
|
| 144 |
+
matrix([[0., 0.]])
|
| 145 |
+
|
| 146 |
+
"""
|
| 147 |
+
a = ndarray.__new__(matrix, shape, dtype, order=order)
|
| 148 |
+
a.fill(0)
|
| 149 |
+
return a
|
| 150 |
+
|
| 151 |
+
def identity(n,dtype=None):
|
| 152 |
+
"""
|
| 153 |
+
Returns the square identity matrix of given size.
|
| 154 |
+
|
| 155 |
+
Parameters
|
| 156 |
+
----------
|
| 157 |
+
n : int
|
| 158 |
+
Size of the returned identity matrix.
|
| 159 |
+
dtype : data-type, optional
|
| 160 |
+
Data-type of the output. Defaults to ``float``.
|
| 161 |
+
|
| 162 |
+
Returns
|
| 163 |
+
-------
|
| 164 |
+
out : matrix
|
| 165 |
+
`n` x `n` matrix with its main diagonal set to one,
|
| 166 |
+
and all other elements zero.
|
| 167 |
+
|
| 168 |
+
See Also
|
| 169 |
+
--------
|
| 170 |
+
numpy.identity : Equivalent array function.
|
| 171 |
+
matlib.eye : More general matrix identity function.
|
| 172 |
+
|
| 173 |
+
Examples
|
| 174 |
+
--------
|
| 175 |
+
>>> import numpy.matlib
|
| 176 |
+
>>> np.matlib.identity(3, dtype=int)
|
| 177 |
+
matrix([[1, 0, 0],
|
| 178 |
+
[0, 1, 0],
|
| 179 |
+
[0, 0, 1]])
|
| 180 |
+
|
| 181 |
+
"""
|
| 182 |
+
a = array([1]+n*[0], dtype=dtype)
|
| 183 |
+
b = empty((n, n), dtype=dtype)
|
| 184 |
+
b.flat = a
|
| 185 |
+
return b
|
| 186 |
+
|
| 187 |
+
def eye(n,M=None, k=0, dtype=float, order='C'):
|
| 188 |
+
"""
|
| 189 |
+
Return a matrix with ones on the diagonal and zeros elsewhere.
|
| 190 |
+
|
| 191 |
+
Parameters
|
| 192 |
+
----------
|
| 193 |
+
n : int
|
| 194 |
+
Number of rows in the output.
|
| 195 |
+
M : int, optional
|
| 196 |
+
Number of columns in the output, defaults to `n`.
|
| 197 |
+
k : int, optional
|
| 198 |
+
Index of the diagonal: 0 refers to the main diagonal,
|
| 199 |
+
a positive value refers to an upper diagonal,
|
| 200 |
+
and a negative value to a lower diagonal.
|
| 201 |
+
dtype : dtype, optional
|
| 202 |
+
Data-type of the returned matrix.
|
| 203 |
+
order : {'C', 'F'}, optional
|
| 204 |
+
Whether the output should be stored in row-major (C-style) or
|
| 205 |
+
column-major (Fortran-style) order in memory.
|
| 206 |
+
|
| 207 |
+
.. versionadded:: 1.14.0
|
| 208 |
+
|
| 209 |
+
Returns
|
| 210 |
+
-------
|
| 211 |
+
I : matrix
|
| 212 |
+
A `n` x `M` matrix where all elements are equal to zero,
|
| 213 |
+
except for the `k`-th diagonal, whose values are equal to one.
|
| 214 |
+
|
| 215 |
+
See Also
|
| 216 |
+
--------
|
| 217 |
+
numpy.eye : Equivalent array function.
|
| 218 |
+
identity : Square identity matrix.
|
| 219 |
+
|
| 220 |
+
Examples
|
| 221 |
+
--------
|
| 222 |
+
>>> import numpy.matlib
|
| 223 |
+
>>> np.matlib.eye(3, k=1, dtype=float)
|
| 224 |
+
matrix([[0., 1., 0.],
|
| 225 |
+
[0., 0., 1.],
|
| 226 |
+
[0., 0., 0.]])
|
| 227 |
+
|
| 228 |
+
"""
|
| 229 |
+
return asmatrix(np.eye(n, M=M, k=k, dtype=dtype, order=order))
|
| 230 |
+
|
| 231 |
+
def rand(*args):
|
| 232 |
+
"""
|
| 233 |
+
Return a matrix of random values with given shape.
|
| 234 |
+
|
| 235 |
+
Create a matrix of the given shape and propagate it with
|
| 236 |
+
random samples from a uniform distribution over ``[0, 1)``.
|
| 237 |
+
|
| 238 |
+
Parameters
|
| 239 |
+
----------
|
| 240 |
+
\\*args : Arguments
|
| 241 |
+
Shape of the output.
|
| 242 |
+
If given as N integers, each integer specifies the size of one
|
| 243 |
+
dimension.
|
| 244 |
+
If given as a tuple, this tuple gives the complete shape.
|
| 245 |
+
|
| 246 |
+
Returns
|
| 247 |
+
-------
|
| 248 |
+
out : ndarray
|
| 249 |
+
The matrix of random values with shape given by `\\*args`.
|
| 250 |
+
|
| 251 |
+
See Also
|
| 252 |
+
--------
|
| 253 |
+
randn, numpy.random.RandomState.rand
|
| 254 |
+
|
| 255 |
+
Examples
|
| 256 |
+
--------
|
| 257 |
+
>>> np.random.seed(123)
|
| 258 |
+
>>> import numpy.matlib
|
| 259 |
+
>>> np.matlib.rand(2, 3)
|
| 260 |
+
matrix([[0.69646919, 0.28613933, 0.22685145],
|
| 261 |
+
[0.55131477, 0.71946897, 0.42310646]])
|
| 262 |
+
>>> np.matlib.rand((2, 3))
|
| 263 |
+
matrix([[0.9807642 , 0.68482974, 0.4809319 ],
|
| 264 |
+
[0.39211752, 0.34317802, 0.72904971]])
|
| 265 |
+
|
| 266 |
+
If the first argument is a tuple, other arguments are ignored:
|
| 267 |
+
|
| 268 |
+
>>> np.matlib.rand((2, 3), 4)
|
| 269 |
+
matrix([[0.43857224, 0.0596779 , 0.39804426],
|
| 270 |
+
[0.73799541, 0.18249173, 0.17545176]])
|
| 271 |
+
|
| 272 |
+
"""
|
| 273 |
+
if isinstance(args[0], tuple):
|
| 274 |
+
args = args[0]
|
| 275 |
+
return asmatrix(np.random.rand(*args))
|
| 276 |
+
|
| 277 |
+
def randn(*args):
|
| 278 |
+
"""
|
| 279 |
+
Return a random matrix with data from the "standard normal" distribution.
|
| 280 |
+
|
| 281 |
+
`randn` generates a matrix filled with random floats sampled from a
|
| 282 |
+
univariate "normal" (Gaussian) distribution of mean 0 and variance 1.
|
| 283 |
+
|
| 284 |
+
Parameters
|
| 285 |
+
----------
|
| 286 |
+
\\*args : Arguments
|
| 287 |
+
Shape of the output.
|
| 288 |
+
If given as N integers, each integer specifies the size of one
|
| 289 |
+
dimension. If given as a tuple, this tuple gives the complete shape.
|
| 290 |
+
|
| 291 |
+
Returns
|
| 292 |
+
-------
|
| 293 |
+
Z : matrix of floats
|
| 294 |
+
A matrix of floating-point samples drawn from the standard normal
|
| 295 |
+
distribution.
|
| 296 |
+
|
| 297 |
+
See Also
|
| 298 |
+
--------
|
| 299 |
+
rand, numpy.random.RandomState.randn
|
| 300 |
+
|
| 301 |
+
Notes
|
| 302 |
+
-----
|
| 303 |
+
For random samples from the normal distribution with mean ``mu`` and
|
| 304 |
+
standard deviation ``sigma``, use::
|
| 305 |
+
|
| 306 |
+
sigma * np.matlib.randn(...) + mu
|
| 307 |
+
|
| 308 |
+
Examples
|
| 309 |
+
--------
|
| 310 |
+
>>> np.random.seed(123)
|
| 311 |
+
>>> import numpy.matlib
|
| 312 |
+
>>> np.matlib.randn(1)
|
| 313 |
+
matrix([[-1.0856306]])
|
| 314 |
+
>>> np.matlib.randn(1, 2, 3)
|
| 315 |
+
matrix([[ 0.99734545, 0.2829785 , -1.50629471],
|
| 316 |
+
[-0.57860025, 1.65143654, -2.42667924]])
|
| 317 |
+
|
| 318 |
+
Two-by-four matrix of samples from the normal distribution with
|
| 319 |
+
mean 3 and standard deviation 2.5:
|
| 320 |
+
|
| 321 |
+
>>> 2.5 * np.matlib.randn((2, 4)) + 3
|
| 322 |
+
matrix([[1.92771843, 6.16484065, 0.83314899, 1.30278462],
|
| 323 |
+
[2.76322758, 6.72847407, 1.40274501, 1.8900451 ]])
|
| 324 |
+
|
| 325 |
+
"""
|
| 326 |
+
if isinstance(args[0], tuple):
|
| 327 |
+
args = args[0]
|
| 328 |
+
return asmatrix(np.random.randn(*args))
|
| 329 |
+
|
| 330 |
+
def repmat(a, m, n):
|
| 331 |
+
"""
|
| 332 |
+
Repeat a 0-D to 2-D array or matrix MxN times.
|
| 333 |
+
|
| 334 |
+
Parameters
|
| 335 |
+
----------
|
| 336 |
+
a : array_like
|
| 337 |
+
The array or matrix to be repeated.
|
| 338 |
+
m, n : int
|
| 339 |
+
The number of times `a` is repeated along the first and second axes.
|
| 340 |
+
|
| 341 |
+
Returns
|
| 342 |
+
-------
|
| 343 |
+
out : ndarray
|
| 344 |
+
The result of repeating `a`.
|
| 345 |
+
|
| 346 |
+
Examples
|
| 347 |
+
--------
|
| 348 |
+
>>> import numpy.matlib
|
| 349 |
+
>>> a0 = np.array(1)
|
| 350 |
+
>>> np.matlib.repmat(a0, 2, 3)
|
| 351 |
+
array([[1, 1, 1],
|
| 352 |
+
[1, 1, 1]])
|
| 353 |
+
|
| 354 |
+
>>> a1 = np.arange(4)
|
| 355 |
+
>>> np.matlib.repmat(a1, 2, 2)
|
| 356 |
+
array([[0, 1, 2, 3, 0, 1, 2, 3],
|
| 357 |
+
[0, 1, 2, 3, 0, 1, 2, 3]])
|
| 358 |
+
|
| 359 |
+
>>> a2 = np.asmatrix(np.arange(6).reshape(2, 3))
|
| 360 |
+
>>> np.matlib.repmat(a2, 2, 3)
|
| 361 |
+
matrix([[0, 1, 2, 0, 1, 2, 0, 1, 2],
|
| 362 |
+
[3, 4, 5, 3, 4, 5, 3, 4, 5],
|
| 363 |
+
[0, 1, 2, 0, 1, 2, 0, 1, 2],
|
| 364 |
+
[3, 4, 5, 3, 4, 5, 3, 4, 5]])
|
| 365 |
+
|
| 366 |
+
"""
|
| 367 |
+
a = asanyarray(a)
|
| 368 |
+
ndim = a.ndim
|
| 369 |
+
if ndim == 0:
|
| 370 |
+
origrows, origcols = (1, 1)
|
| 371 |
+
elif ndim == 1:
|
| 372 |
+
origrows, origcols = (1, a.shape[0])
|
| 373 |
+
else:
|
| 374 |
+
origrows, origcols = a.shape
|
| 375 |
+
rows = origrows * m
|
| 376 |
+
cols = origcols * n
|
| 377 |
+
c = a.reshape(1, a.size).repeat(m, 0).reshape(rows, origcols).repeat(n, 0)
|
| 378 |
+
return c.reshape(rows, cols)
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/py.typed
ADDED
|
File without changes
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/setup.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
def configuration(parent_package='',top_path=None):
|
| 4 |
+
from numpy.distutils.misc_util import Configuration
|
| 5 |
+
config = Configuration('numpy', parent_package, top_path)
|
| 6 |
+
|
| 7 |
+
config.add_subpackage('array_api')
|
| 8 |
+
config.add_subpackage('compat')
|
| 9 |
+
config.add_subpackage('core')
|
| 10 |
+
config.add_subpackage('distutils')
|
| 11 |
+
config.add_subpackage('doc')
|
| 12 |
+
config.add_subpackage('f2py')
|
| 13 |
+
config.add_subpackage('fft')
|
| 14 |
+
config.add_subpackage('lib')
|
| 15 |
+
config.add_subpackage('linalg')
|
| 16 |
+
config.add_subpackage('ma')
|
| 17 |
+
config.add_subpackage('matrixlib')
|
| 18 |
+
config.add_subpackage('polynomial')
|
| 19 |
+
config.add_subpackage('random')
|
| 20 |
+
config.add_subpackage('testing')
|
| 21 |
+
config.add_subpackage('typing')
|
| 22 |
+
config.add_subpackage('_typing')
|
| 23 |
+
config.add_data_dir('doc')
|
| 24 |
+
config.add_data_files('py.typed')
|
| 25 |
+
config.add_data_files('*.pyi')
|
| 26 |
+
config.add_subpackage('tests')
|
| 27 |
+
config.add_subpackage('_pyinstaller')
|
| 28 |
+
config.make_config_py() # installs __config__.py
|
| 29 |
+
return config
|
| 30 |
+
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
print('This is the wrong setup.py file to run')
|
VQA_model/DOVER/.eggs/numpy-1.24.4-py3.8-linux-x86_64.egg/numpy/version.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._version import get_versions
|
| 4 |
+
|
| 5 |
+
__ALL__ = ['version', '__version__', 'full_version', 'git_revision', 'release']
|
| 6 |
+
|
| 7 |
+
vinfo: dict[str, str] = get_versions()
|
| 8 |
+
version = vinfo["version"]
|
| 9 |
+
__version__ = vinfo.get("closest-tag", vinfo["version"])
|
| 10 |
+
full_version = vinfo['version']
|
| 11 |
+
git_revision = vinfo['full-revisionid']
|
| 12 |
+
release = 'dev0' not in version and '+' not in version
|
| 13 |
+
short_version = vinfo['version'].split("+")[0]
|
| 14 |
+
|
| 15 |
+
del get_versions, vinfo
|
VQA_model/DOVER/dover/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (175 Bytes). View file
|
|
|
VQA_model/DOVER/dover/__pycache__/__init__.cpython-38.pyc
ADDED
|
Binary file (185 Bytes). View file
|
|
|