Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f6f6159
Initial plan
Copilot Dec 20, 2025
82f477a
Add libcpp_vector_as_np conversion provider with tests and documentation
Copilot Dec 20, 2025
8190984
Remove unused imports from test file
Copilot Dec 20, 2025
619b4d1
Implement libcpp_vector_as_np with proper type alias and memcpy optim…
Copilot Dec 20, 2025
8dc9147
Fix Cython types and add numpy to test dependencies
Copilot Dec 20, 2025
d1e3b72
Remove list support - only accept numpy arrays
Copilot Dec 20, 2025
e86964d
Fix type hint syntax - use ndim=N not numpy.ndim[N]
Copilot Dec 20, 2025
7cd6806
Initial plan
Copilot Dec 20, 2025
28ff854
Add generic array wrapper classes with buffer protocol support
Copilot Dec 20, 2025
29559b3
Integrate array wrappers with ConversionProvider and extend to all in…
Copilot Dec 20, 2025
ff85f31
Simplify array wrappers to use libcpp.vector directly without C++ layer
Copilot Dec 20, 2025
e63190d
Add implementation summary and documentation
Copilot Dec 20, 2025
280efc3
Make ArrayWrappers automatically compiled with every autowrap module
Copilot Dec 20, 2025
bb049ca
Fix buffer protocol implementation with malloc for shape/strides
Copilot Dec 20, 2025
9b50945
Inline ArrayWrapper classes into generated modules (WIP)
Copilot Dec 20, 2025
a77cb12
Fix array wrapper inlining and test numpy integration
Copilot Dec 20, 2025
7627af3
Remove standalone ArrayWrappers tests - functionality tested in conve…
Copilot Dec 21, 2025
b4f7cd4
Use readonly views for const reference returns instead of copies
Copilot Dec 21, 2025
8463acf
Simplify to use Cython memory views for reference returns, remove Arr…
Copilot Dec 21, 2025
ff620da
Remove unused ArrayView classes and factory functions
Copilot Dec 21, 2025
c64c6ef
Address code review feedback - improve readability and remove redunda…
Copilot Dec 21, 2025
bc8d36d
Clean up unnecessary files and add .base attribute tests
Copilot Dec 21, 2025
cda5918
Remove dead ArrayWrappers compilation code from Utils.py
Copilot Dec 21, 2025
b2e1d0c
Clarify .base attribute test comment for memory views
Copilot Dec 21, 2025
5872dda
Set .base to self for reference returns, verify in tests
Copilot Dec 21, 2025
586e2d5
Fix .base attribute for value returns - explicitly set wrapper as base
Copilot Dec 21, 2025
e9da9fb
Fix .base attribute setting - rely on Cython memory view automatic re…
Copilot Dec 21, 2025
cbb80d6
Remove PyArray_SetBaseObject calls and update tests for memoryview base
Copilot Dec 21, 2025
1d8fa4b
Use PyArray_SimpleNewFromData to properly set owner as .base
Copilot Dec 21, 2025
67ab2fa
Add test proving ArrayWrapper lifetime management works correctly
Copilot Dec 21, 2025
3e0a7a9
Enable test_mutable_ref_output_is_view and add .base verification
Copilot Dec 21, 2025
6aaf356
fix views to get data from pointer. add numpy to test reqs. fix gitig…
jpfeuffer Dec 21, 2025
a5c4bf1
Re-add shared_ptr_test.pyx as it's a hand-written fixture, not generated
jpfeuffer Dec 21, 2025
75af88a
make sure that generated filse go to generated directory that we can …
jpfeuffer Dec 21, 2025
e86cb75
Create generated/ directory structure with .gitkeep files
jpfeuffer Dec 21, 2025
4574a94
Restore addon fixture files B.pyx and C.pyx
jpfeuffer Dec 21, 2025
b89a9f2
Merge pull request #225 from OpenMS/copilot/add-owning-and-non-owning…
jpfeuffer Dec 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,15 @@ develop-eggs
#Mr Developer
.mr.developer.cfg

# generated py extensions
tests/test_files/gil_testing_wrapper.pyx
tests/test_files/libcpp_stl_test.pyx
tests/test_files/libcpp_utf8_string_test.pyx
tests/test_files/libcpp_utf8_output_string_test.pyx
tests/test_files/iteratorwrapper.pyx
tests/test_files/namespaces.pyx
tests/test_files/number_conv.pyx
tests/test_files/enums.pyx
tests/test_files/wrapped_container_wrapper.pyx
tests/test_files/wrap_len_wrapper.pyx

# generated typestubs
# generated py extensions and typestubs in tests
tests/test_files/generated/*
!tests/test_files/generated/.gitkeep
!tests/test_files/generated/numpy_vector/
tests/test_files/generated/numpy_vector/*
!tests/test_files/generated/numpy_vector/.gitkeep
!tests/test_files/generated/addons/
tests/test_files/generated/addons/*
!tests/test_files/generated/addons/.gitkeep
tests/test_files/*.pyi

_codeql_detected_source_root
47 changes: 46 additions & 1 deletion autowrap/CodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,7 @@ def create_default_cimports(self):
|from libcpp.string cimport string as libcpp_utf8_output_string
|from libcpp.set cimport set as libcpp_set
|from libcpp.vector cimport vector as libcpp_vector
|from libcpp.vector cimport vector as libcpp_vector_as_np
|from libcpp.pair cimport pair as libcpp_pair
|from libcpp.map cimport map as libcpp_map
|from libcpp.unordered_map cimport unordered_map as libcpp_unordered_map
Expand All @@ -2069,7 +2070,7 @@ def create_default_cimports(self):
|from libcpp.optional cimport optional as libcpp_optional
|from libcpp.string_view cimport string_view as libcpp_string_view
|from libcpp cimport bool
|from libc.string cimport const_char
|from libc.string cimport const_char, memcpy
|from cython.operator cimport dereference as deref,
+ preincrement as inc, address as address
"""
Expand All @@ -2095,6 +2096,7 @@ def create_default_cimports(self):
|import numpy as np
|cimport numpy as numpy
|import numpy as numpy
|from cpython.ref cimport Py_INCREF
"""
)

Expand All @@ -2107,7 +2109,50 @@ def create_std_cimports(self):
code.add(stmt)

self.top_level_code.append(code)

# If numpy is enabled, inline the ArrayWrapper/ArrayView classes
if self.include_numpy:
self.inline_array_wrappers()

return code

def inline_array_wrappers(self):
"""Inline ArrayWrapper class definitions for buffer protocol support.

ArrayWrapper classes are used for value returns where data is already copied.
For reference returns, Cython memory views are used instead (no wrapper needed).
"""
# Read the combined ArrayWrappers.pyx file (which has attributes already inline)
autowrap_dir = os.path.dirname(os.path.abspath(__file__))
array_wrappers_pyx = os.path.join(autowrap_dir, "data_files", "autowrap", "ArrayWrappers.pyx")

if not os.path.exists(array_wrappers_pyx):
L.warning("ArrayWrappers.pyx not found, skipping inline array wrappers")
return

with open(array_wrappers_pyx, 'r') as f:
pyx_content = f.read()

# Remove the first few lines (cython directives and module docstring)
# Keep everything from the first import onward
lines = pyx_content.split('\n')
start_idx = 0
for i, line in enumerate(lines):
if line.strip().startswith('from cpython.buffer'):
start_idx = i
break

wrapper_code_str = '\n'.join(lines[start_idx:])

code = Code()
code.add("""
|# Inlined ArrayWrapper classes for buffer protocol support (value returns)
|# Reference returns use Cython memory views instead
""")
# Add the wrapper code directly
code.add(wrapper_code_str)

self.top_level_code.append(code)

def create_includes(self):
code = Code()
Expand Down
Loading