FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor-python/src/xtensor_python/__init__.py at master · maxstidbits/xtensor-python · GitHub
maxstidbits
xtensor-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
xtensor-python
/
src
/
xtensor_python
/
__init__.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
323 lines (259 loc) · 8.73 KB
Breadcrumbs
xtensor-python
/
src
/
xtensor_python
/
__init__.py
Copy path
File metadata and controls
323 lines (259 loc) · 8.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
"""xtensor-python: Python bindings for the xtensor C++ multi-dimensional array library.
This package provides Python bindings and build utilities for xtensor-python,
a header-only C++ library that enables seamless interoperability between
NumPy arrays and xtensor expressions.
Key Features:
- Header-only C++ library for NumPy/xtensor interoperability
- Build helpers for creating C++ extensions
- CMake integration utilities
- Version management and dependency checking
Basic Usage:
>>> import xtensor_python
>>> print(xtensor_python.__version__)
>>> include_dirs = xtensor_python.get_include_dirs()
>>> extension = xtensor_python.create_extension('my_module', ['src/my_module.cpp'])
For CMake projects:
>>> import xtensor_python.cmake_helpers as cmake
>>> cmake.print_cmake_info()
>>> cmake.generate_cmake_config('/path/to/cmake/config')
"""
# Import version information first
try
:
from
.
_version
import
(
__version__
,
__version_info__
,
version
,
version_info
,
get_version_info
,
get_version_string
,
VersionInfo
,
)
except
ImportError
as
e
:
# Fallback if version module fails to import
__version__
=
"unknown"
__version_info__
=
None
version
=
__version__
version_info
=
__version_info__
def
get_version_info
():
raise
ImportError
(
f"Version information unavailable:
{
e
}
"
)
def
get_version_string
():
return
__version__
VersionInfo
=
None
# Import build helpers
try
:
from
.
build_helpers
import
(
get_include_dirs
,
get_compiler_flags
,
get_numpy_flags
,
get_link_flags
,
get_define_macros
,
create_extension
,
BuildExtension
,
get_build_requirements
,
check_dependencies
,
print_build_info
,
)
except
ImportError
as
e
:
# Create stub functions if build helpers fail to import
def
get_include_dirs
():
raise
ImportError
(
f"Build helpers unavailable:
{
e
}
"
)
def
get_compiler_flags
():
raise
ImportError
(
f"Build helpers unavailable:
{
e
}
"
)
def
get_numpy_flags
():
raise
ImportError
(
f"Build helpers unavailable:
{
e
}
"
)
def
get_link_flags
():
raise
ImportError
(
f"Build helpers unavailable:
{
e
}
"
)
def
get_define_macros
():
raise
ImportError
(
f"Build helpers unavailable:
{
e
}
"
)
def
create_extension
(
*
args
,
**
kwargs
):
raise
ImportError
(
f"Build helpers unavailable:
{
e
}
"
)
BuildExtension
=
None
def
get_build_requirements
():
return
[
"numpy>=2.0"
,
"pybind11>=2.6.1,<4"
]
def
check_dependencies
():
return
{
"error"
:
str
(
e
)}
def
print_build_info
():
print
(
f"Build helpers unavailable:
{
e
}
"
)
# Import CMake helpers
try
:
from
.
cmake_helpers
import
(
get_cmake_dir
,
get_cmake_variables
,
generate_cmake_config
,
get_cmake_prefix_path
,
get_cmake_find_commands
,
print_cmake_info
,
create_cmake_example
,
)
except
ImportError
as
e
:
# Create stub functions if CMake helpers fail to import
def
get_cmake_dir
():
raise
ImportError
(
f"CMake helpers unavailable:
{
e
}
"
)
def
get_cmake_variables
():
raise
ImportError
(
f"CMake helpers unavailable:
{
e
}
"
)
def
generate_cmake_config
(
*
args
,
**
kwargs
):
raise
ImportError
(
f"CMake helpers unavailable:
{
e
}
"
)
def
get_cmake_prefix_path
():
raise
ImportError
(
f"CMake helpers unavailable:
{
e
}
"
)
def
get_cmake_find_commands
():
raise
ImportError
(
f"CMake helpers unavailable:
{
e
}
"
)
def
print_cmake_info
():
print
(
f"CMake helpers unavailable:
{
e
}
"
)
def
create_cmake_example
(
*
args
,
**
kwargs
):
raise
ImportError
(
f"CMake helpers unavailable:
{
e
}
"
)
# Package metadata
__author__
=
"Wolf Vollprecht, Johan Mabille, Sylvain Corlay"
__email__
=
"info@quantstack.net"
__license__
=
"BSD-3-Clause"
__url__
=
"https://github.com/xtensor-stack/xtensor-python"
__description__
=
"Python bindings for the xtensor C++ multi-dimensional array library"
# Backward compatibility aliases for common functions
# These maintain compatibility with existing usage patterns
def
get_include
():
"""Get the main xtensor-python include directory.
Returns:
Path to the xtensor-python include directory
Note:
This is a backward compatibility alias. Use get_include_dirs() for
all required include directories.
"""
import
os
from
pathlib
import
Path
package_dir
=
Path
(
__file__
).
parent
return
str
(
package_dir
/
"include"
)
def
get_cmake_include_dir
():
"""Get the CMake include directory.
Returns:
Path to the CMake configuration directory
Note:
This is a backward compatibility alias. Use get_cmake_dir() instead.
"""
return
get_cmake_dir
()
# Convenience functions for common operations
def
setup_extension
(
name
,
sources
,
**
kwargs
):
"""Convenience function to create a fully configured extension.
This is a high-level wrapper around create_extension() that provides
sensible defaults for most use cases.
Args:
name: Extension module name
sources: List of source file paths
**kwargs: Additional arguments passed to create_extension()
Returns:
Configured Extension object
"""
return
create_extension
(
name
,
sources
,
**
kwargs
)
def
get_all_include_dirs
():
"""Get all include directories needed for xtensor-python.
Returns:
List of all required include directory paths
Note:
This is an alias for get_include_dirs() for clarity.
"""
return
get_include_dirs
()
def
print_info
():
"""Print comprehensive information about xtensor-python installation.
This function prints version information, build configuration,
dependencies, and usage examples.
"""
print
(
"xtensor-python Package Information"
)
print
(
"="
*
50
)
# Version information
print
(
f"Version:
{
__version__
}
"
)
if
__version_info__
:
print
(
f"Version info:
{
__version_info__
}
"
)
# Package information
print
(
f"Author:
{
__author__
}
"
)
print
(
f"License:
{
__license__
}
"
)
print
(
f"URL:
{
__url__
}
"
)
# Include directory
try
:
include_dir
=
get_include
()
print
(
f"Include directory:
{
include_dir
}
"
)
except
Exception
as
e
:
print
(
f"Include directory: Error -
{
e
}
"
)
print
(
"
\n
"
+
"="
*
50
)
# Build information
try
:
print_build_info
()
except
Exception
as
e
:
print
(
f"Build info error:
{
e
}
"
)
print
(
"
\n
"
+
"="
*
50
)
# CMake information
try
:
print_cmake_info
()
except
Exception
as
e
:
print
(
f"CMake info error:
{
e
}
"
)
def
get_header_files
():
"""Get list of all C++ header files included in the package.
Returns:
List of header file paths
"""
from
pathlib
import
Path
package_dir
=
Path
(
__file__
).
parent
header_dir
=
package_dir
/
"include"
/
"xtensor-python"
if
not
header_dir
.
exists
():
return
[]
return
[
str
(
f
)
for
f
in
header_dir
.
glob
(
"*.hpp"
)]
# Module-level convenience imports for common use cases
# This allows users to do: from xtensor_python import get_include_dirs
__all__
=
[
# Version information
"__version__"
,
"__version_info__"
,
"version"
,
"version_info"
,
"get_version_info"
,
"get_version_string"
,
"VersionInfo"
,
# Build helpers
"get_include_dirs"
,
"get_compiler_flags"
,
"get_numpy_flags"
,
"get_link_flags"
,
"get_define_macros"
,
"create_extension"
,
"BuildExtension"
,
"get_build_requirements"
,
"check_dependencies"
,
"print_build_info"
,
# CMake helpers
"get_cmake_dir"
,
"get_cmake_variables"
,
"generate_cmake_config"
,
"get_cmake_prefix_path"
,
"get_cmake_find_commands"
,
"print_cmake_info"
,
"create_cmake_example"
,
# Backward compatibility
"get_include"
,
"get_cmake_include_dir"
,
# Convenience functions
"setup_extension"
,
"get_all_include_dirs"
,
"print_info"
,
"get_header_files"
,
# Package metadata
"__author__"
,
"__email__"
,
"__license__"
,
"__url__"
,
"__description__"
,
]
# Initialize package on import
def
_initialize_package
():
"""Initialize the package and perform any necessary setup."""
try
:
# Verify that header files are present
header_files
=
get_header_files
()
if
not
header_files
:
import
warnings
warnings
.
warn
(
"No C++ header files found. The package may not be properly installed."
,
UserWarning
,
stacklevel
=
2
)
except
Exception
:
# Silently ignore initialization errors
pass
# Run initialization
_initialize_package
()
Back
|
FazBrowse Home
|
New Git URL