You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idea: add a special conversion provider for autowrap that handles OpenMs Matrix #8538
Code in special_conversion_providers.py
Cython type should be a np.ndarray with dim 2 and the appropriate numpy dtype.
As usual, we need to support function inputs and return values.
Avoid copies at all costs and use raw pointers and/or buffer interface and/or memory views whenever possible.
Only copy when the input is not a ref. Only copy when output is value or const ref.
Wrap an existing function that uses matrix in the corresponding Pxd file if not yet done.
@timosachsenberg would be a bit more direct than having an intermediate Matrix object on the python side. But maybe has more issues with memory responsibility.
Create a special conversion provider in the autowrap system that automatically converts between OpenMS Matrix[ValueT] C++ types and 2D NumPy arrays, using zero-copy memory views when possible to avoid unnecessary data copying for improved performance.
Observations
Codebase Summary
The pyOpenMS project generates Python bindings for OpenMS C++ libraries using the autowrap tool with Cython. Type conversion providers in src/pyOpenMS/converters/special_autowrap_conversionproviders.py define how C++ types map to Python types during the binding generation process. The Matrix[ValueT] template class is already defined in src/pyOpenMS/pxds/Matrix.pxd with methods for data access (data(), rows(), cols()), memory layout inspection (rowMajor(), innerStride(), outerStride()), and manipulation (resize(), getValue(), setValue()). Currently, a MatrixDouble.pyx addon provides numpy integration for Matrix[double] through explicit methods, but functions using Matrix parameters still require intermediate Python Matrix objects rather than working directly with numpy arrays.
AssumptionsAssumption 1: Which Matrix[ValueT] template instantiations should be supported?
Options Considered:
Support only Matrix[double] initially, expanding later if needed
Support all commonly used numeric types (double, float, int, uint) from the start
Chosen Option: Support at least double and float types from the start
Rationale: These are the most common in scientific computing contexts found in the codebase exploration (e.g., BilinearInterpolation uses Matrix[ValueType], numerical solvers use Matrix[double]). The converter will extract the template argument and map it to appropriate numpy dtypes. This provides immediate value while following the existing pattern of supporting multiple types seen in other converters.
Assumption 2: Should zero-copy views always be created, or should we copy when memory layouts are incompatible?
Options Considered:
Always copy data to ensure compatibility, sacrificing performance for simplicity
Create zero-copy views when layouts match, copy when they don't, with automatic detection
Require users to provide contiguous arrays and reject incompatible layouts
Chosen Option: Use Cython's typed memory views which automatically handle memory address translation and create zero-copy views when possible, but be prepared to copy when necessary
Rationale: This balances the ticket's "avoid copies at all costs" directive with practical compatibility needs. Typed memoryviews both use and support the buffer protocol, so they do not copy memory unnecessarily, making them ideal for this use case.
Assumption 3: How should by-reference output parameters be handled after C++ function calls modify the Matrix?
Options Considered:
Create a temporary Matrix, call the function, then copy results back to a new numpy array
Wrap the numpy array in a Matrix view, allowing direct modification (risky if layouts don't match)
Create a Matrix from numpy array, call function, then write results back to original numpy array
Chosen Option: For non-const reference parameters, create a temporary Matrix object, pass it to the C++ function, then copy the modified data back to a new numpy array in the cleanup phase
Rationale: This ensures correctness while accepting that by-reference semantics require some copying. This follows the pattern seen in existing converters like OpenMSDPosition1 and OpenMSDPosition2 which use cleanup code to write modified values back to Python variables.
💡 User Tips
Regenerate the plan with different choices with @coderabbitai <feedback>.
Implementation Steps
Phase 1: Converter Class Structure and Type Detection
Create the foundational converter class that integrates with autowrap's type system and correctly identifies Matrix[ValueT] types in function signatures.
Task 1: Define OpenMSMatrixConverter Class
Implement the new converter class in src/pyOpenMS/converters/special_autowrap_conversionproviders.py following the established TypeConverterBase pattern.
Create OpenMSMatrixConverter class inheriting from TypeConverterBase
Define supported base types (Matrix) in get_base_types() method
Implement template argument detection using tuple unpacking: value_type, = cpp_type.template_args
Create type mapping dictionary from C++ types (double, float) to numpy dtypes (np.float64, np.float32)
Task 2: Implement Type Matching Logic
Define how the converter identifies applicable Matrix types in function signatures.
Implement matches(cpp_type) method checking for libcpp_matrix or Matrix base types with template arguments
Verify template argument is a supported numeric type (double, float)
Ensure converter only activates for Matrix[ValueT] template instantiations, not other template types
Task 3: Define Python Type Hints
Specify how Matrix types appear in generated Python signatures and type stubs.
Implement matching_python_type(cpp_type) to return "np.ndarray"
Implement matching_python_type_full(cpp_type) to return detailed type hint like "np.ndarray[np.float64, ndim=2]" based on the value type
Implement type_check_expression(cpp_type, argument_var) to generate runtime validation code ensuring 2D array with correct dtype
🤖 Prompt for AI agents
Implement the OpenMSMatrixConverter class in
special_autowrap_conversionproviders.py that identifies and registers
Matrix[ValueT] types for automatic conversion.
Create OpenMSMatrixConverter inheriting from TypeConverterBase
Implement get_base_types() returning Matrix base types
Add matches() method to detect Matrix[ValueT] with template arguments for double
and float
Create C++ type to numpy dtype mapping dictionary (double->np.float64,
float->np.float32)
Implement matching_python_type() returning "np.ndarray"
Implement matching_python_type_full() returning "np.ndarray[dtype, ndim=2]" with
appropriate dtype
Implement type_check_expression() generating validation code for 2D arrays with
correct dtype
Phase 2: Input Parameter Conversion (Python to C++)
Implement conversion logic for Matrix parameters in C++ function calls, optimizing for zero-copy when the parameter passing mode allows.
Task 1: By-Value Parameter Handling
Create conversion code for functions that take Matrix by value, requiring data copying.
Generate Cython code that allocates a new C++ Matrix object of appropriate dimensions
Handle mutable reference parameters that may be modified by C++ functions.
Check if parameter is non-const reference using cpp_type.is_ref and not cpp_type.is_const
Create temporary Matrix object and copy numpy array data into it (similar to by-value approach)
Pass Matrix by reference to C++ function
Generate cleanup code that creates a new numpy array from the modified Matrix data
In cleanup phase, copy Matrix contents back to Python variable: $argument_var = <numpy array from Matrix>
🤖 Prompt for AI agents
Implement input_conversion() method to generate Cython code converting numpy
arrays to Matrix[ValueT] objects based on parameter passing modes.
For by-value parameters:
Extract numpy array dimensions (rows, cols from shape)
Allocate new Matrix object and resize to match dimensions
Copy numpy data into Matrix using setValue() or bulk memory operations
For const reference parameters:
Create Cython typed memory views on numpy array data
Wrap numpy buffer in temporary Matrix using data pointer
Check memory layout compatibility with rowMajor()
Fall back to copying if layouts incompatible
For non-const reference parameters:
Create temporary Matrix and copy numpy data
Generate cleanup code to copy modified Matrix back to new numpy array
Replace original Python variable with result array
Phase 3: Return Value and Output Conversion (C++ to Python)
Implement conversion logic for Matrix return values and output parameters, creating numpy arrays from Matrix objects.
Task 1: By-Value Return Handling
Convert Matrix objects returned by value to numpy arrays with data copying.
In output_conversion() method, generate code to query Matrix dimensions: rows = $result.rows(), cols = $result.cols()
Allocate new numpy array with appropriate shape and dtype: np.empty((rows, cols), dtype=np_dtype)
Use typed memory views to access both Matrix and numpy array data
Generate loop copying Matrix data via getValue(i, j) into numpy array, or use data() pointer for bulk copy
Consider using numpy.lib.stride_tricks.as_strided() for efficient layout conversion if needed (as seen in MatrixDouble.pyx)
Return the newly created numpy array as the Python result
Handle Matrix objects passed as output parameters (non-const reference) that are populated by C++ functions.
For output parameters detected via cpp_type.is_ref and not cpp_type.is_const in function signatures
After C++ function call, extract modified Matrix data using the same approach as by-value returns
Create numpy array from Matrix dimensions and copy data using memory views or pointer access
Replace the original Python parameter binding with the numpy array result
🤖 Prompt for AI agents
Implement output_conversion() method to generate Cython code converting
Matrix[ValueT] return values and output parameters to numpy arrays.
For return values:
Query Matrix dimensions using rows() and cols()
Allocate numpy array with matching shape and appropriate dtype
Use typed memory views for efficient data access
Copy Matrix data using getValue() or bulk copy via data() pointer
Consider as_strided() for layout conversion if needed
Return newly created numpy array
For output parameters (non-const references):
Detect output parameters via is_ref and not is_const
Extract modified Matrix data after function call
Create numpy array from Matrix dimensions and copy data
Replace original Python parameter with numpy array result
Phase 4: Integration and Testing
Validate the converter with existing Matrix-using functions and ensure proper registration in the autowrap system.
Task 1: Register Converter
Integrate the new converter into the autowrap build system.
Add OpenMSMatrixConverter to the converter registry in src/pyOpenMS/converters/__init__.py
Ensure converter is instantiated and registered in the list passed to autowrap.Main.register_converters()
Verify converter priority/order relative to other converters (should run before generic converters)
Task 2: Wrap Test Functions
Expose existing Matrix-using C++ functions through pyOpenMS to validate converter behavior.
Choose test functions from exploration findings: BilinearInterpolation.getData() / setData() (simple getter/setter), NonNegativeLeastSquaresSolver.solve() (multiple Matrix parameters)
In the corresponding .pxd files (e.g., src/pyOpenMS/pxds/BilinearInterpolation.pxd), ensure Matrix methods are not marked with # wrap-ignore
Remove any existing # wrap-ignore comments if present on Matrix-related methods
Regenerate bindings to produce Python wrappers that use the new converter
Task 3: Create Unit Tests
Add tests validating correct conversion behavior for different parameter passing modes.
Create test file in src/pyOpenMS/tests/ directory testing Matrix conversion scenarios
Test input parameters: by-value (should copy), const-reference (should not copy), non-const reference (should copy back modifications)
Test return values: verify numpy array is returned with correct shape, dtype, and values
Test memory efficiency: verify zero-copy behavior where expected by checking if arrays share memory (using np.shares_memory() or comparing data pointers)
Test error cases: wrong dimensions, wrong dtype, non-contiguous arrays
Compare results against existing MatrixDouble methods to ensure consistency
🤖 Prompt for AI agents
Integrate the OpenMSMatrixConverter into the build system and validate with
comprehensive tests.
Register OpenMSMatrixConverter in src/pyOpenMS/converters/__init__.py
Add to converter list passed to autowrap.Main.register_converters()
Verify converter runs before generic converters
Expose test functions by removing wrap-ignore comments from Matrix methods in
.pxd files
Target BilinearInterpolation.getData()/setData() and
NonNegativeLeastSquaresSolver.solve()
Regenerate bindings
Create test file in src/pyOpenMS/tests/
Test by-value parameters (expect copy), const-reference (expect zero-copy),
non-const reference (expect copy-back)
Test return values for correct shape, dtype, and values
Verify zero-copy behavior using np.shares_memory()
Test error cases: wrong dimensions, dtype, non-contiguous arrays
Compare against existing MatrixDouble methods for consistency
🚀 Next Steps
🤖 All AI agent prompts combined
Task: 1
Implement the OpenMSMatrixConverter class in
special_autowrap_conversionproviders.py that identifies and registers
Matrix[ValueT] types for automatic conversion.
Create OpenMSMatrixConverter inheriting from TypeConverterBase
Implement get_base_types() returning Matrix base types
Add matches() method to detect Matrix[ValueT] with template arguments for double
and float
Create C++ type to numpy dtype mapping dictionary (double->np.float64,
float->np.float32)
Implement matching_python_type() returning "np.ndarray"
Implement matching_python_type_full() returning "np.ndarray[dtype, ndim=2]" with
appropriate dtype
Implement type_check_expression() generating validation code for 2D arrays with
correct dtype
===============================================================================
Task: 2
Implement input_conversion() method to generate Cython code converting numpy
arrays to Matrix[ValueT] objects based on parameter passing modes.
For by-value parameters:
Extract numpy array dimensions (rows, cols from shape)
Allocate new Matrix object and resize to match dimensions
Copy numpy data into Matrix using setValue() or bulk memory operations
For const reference parameters:
Create Cython typed memory views on numpy array data
Wrap numpy buffer in temporary Matrix using data pointer
Check memory layout compatibility with rowMajor()
Fall back to copying if layouts incompatible
For non-const reference parameters:
Create temporary Matrix and copy numpy data
Generate cleanup code to copy modified Matrix back to new numpy array
Replace original Python variable with result array
===============================================================================
Task: 3
Implement output_conversion() method to generate Cython code converting
Matrix[ValueT] return values and output parameters to numpy arrays.
For return values:
Query Matrix dimensions using rows() and cols()
Allocate numpy array with matching shape and appropriate dtype
Use typed memory views for efficient data access
Copy Matrix data using getValue() or bulk copy via data() pointer
Consider as_strided() for layout conversion if needed
Return newly created numpy array
For output parameters (non-const references):
Detect output parameters via is_ref and not is_const
Extract modified Matrix data after function call
Create numpy array from Matrix dimensions and copy data
Replace original Python parameter with numpy array result
===============================================================================
Task: 4
Integrate the OpenMSMatrixConverter into the build system and validate with
comprehensive tests.
Register OpenMSMatrixConverter in src/pyOpenMS/converters/__init__.py
Add to converter list passed to autowrap.Main.register_converters()
Verify converter runs before generic converters
Expose test functions by removing wrap-ignore comments from Matrix methods in
.pxd files
Target BilinearInterpolation.getData()/setData() and
NonNegativeLeastSquaresSolver.solve()
Regenerate bindings
Create test file in src/pyOpenMS/tests/
Test by-value parameters (expect copy), const-reference (expect zero-copy),
non-const reference (expect copy-back)
Test return values for correct shape, dtype, and values
Verify zero-copy behavior using np.shares_memory()
Test error cases: wrong dimensions, dtype, non-contiguous arrays
Compare against existing MatrixDouble methods for consistency
💡 Iterate on the plan with:
@coderabbitai <feedback>
Example Feedback
- @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2.
- @coderabbitai For assumption 1 go ahead with option 3 and replan.
Thanks for the detailed write-up — this looks like a really interesting extension to the autowrap system.
I’d be interested in working on a special conversion provider for OpenMS Matrix types. Before starting implementation, I plan to first explore existing conversion providers and understand current Matrix usage patterns in Python bindings, especially around ownership and copying.
@jpfeuffer does the proposed phased approach (type detection → input conversion → output conversion → tests) align with how you’d like this tackled, or are there design constraints I should be aware of upfront?
I agree it’s important to validate whether a special conversion provider is the right abstraction here before committing to a full implementation. As a first step, I can do a small investigation to:
review existing autowrap conversion providers and how complex types are handled today
look at current Matrix usage patterns in the OpenMS Python bindings
sketch 1–2 alternative approaches (e.g. direct wrapping vs. conversion provider) with tradeoffs around copying and ownership
@timosachsenberg Would it be useful if I reported back with a short summary of findings and a recommended direction before writing any code?
No, this would not be really helpful. We don't know if this is the way to go at this point.
What would help most is stuff we can't easily do with an AI, or we are too time constrained. e.g., stuff that requires a lot of back and forth between us and AI... if you are interested in this I could dig out some tasks that are in this spirit.
What we also always need are people that benchmark on real data and compare results to other existing tools. Or people that come up with smart ways to test the algorithms or enhance test coverage. Unfortunately, most of them require domain knowledge.
I understand the concern about focusing effort where it’s most useful, and I’m definitely interested in contributing in areas that require more human judgment and iteration rather than straightforward code generation.
Benchmarking on real data, comparing OpenMS results with other tools, and improving algorithm-level testing and test coverage all sound interesting to me. While I’m still building deeper domain knowledge, I’m very willing to invest time in learning the relevant workflows and datasets.
If you’re open to it, I’d really appreciate it if you could point me to a few concrete tasks or areas where additional help would be most valuable as a starting point.
@timosachsenberg Just a gentle follow‑up on this thread.
I’m still very interested in contributing on the kinds of tasks you mentioned (benchmarking on real data, comparing OpenMS against other tools, or improving algorithm‑level tests and coverage), and I’m happy to invest time in learning the necessary domain details.
If you have a chance, could you point me to one or two concrete tasks or areas where an extra pair of hands would currently be most useful? I’d like to get started in a way that’s aligned with your priorities
I’ve been following the discussion on improving the ergonomics of pyOpenMS. Given my background in quantitative research and C++/Python integration, I would like to contribute by implementing the conversion provider for OpenMS::Matrix.
My proposed approach for the implementation:
Conversion Layer: I plan to modify special_autowrap_conversionproviders.py to recognize Matrix and utilize Cython Typed Memoryviews.
Zero-Copy Logic: I will implement logic to check for C-contiguous layouts in NumPy arrays to allow direct memory sharing. For non-contiguous inputs, I'll ensure a safe fallback copy to prevent segmentation faults.
Memory Safety: I'll focus on ensuring that the C++ Matrix lifecycle is correctly managed when viewed from Python, particularly addressing the 'ownership' concerns mentioned in the idea phase.
Testing: I can also provide a test suite to verify that the bridging maintains data integrity and performance gains across the C++/Python boundary.
Is there a specific branch I should work against, or would you prefer a draft PR once I have a basic Proof of Concept (PoC) for Matrix?
I suppose it is still relevant but will require a different strategy. I suppose you did not add any special handling for openms matrix yet @timosachsenberg ?
Superseded by the nanobind migration on develop. OpenMS Matrix types now have zero-copy Eigen↔NumPy conversion via nanobind's built-in Eigen support, without needing an autowrap conversion provider.
Activity
coderabbitai commentedon Dec 20, 2025
📝 CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
✅ Successfully generated implementation plan.
💡 Use
@coderabbitai <feedback>to replanExamples
🔗 Similar Issues
Related Issues
👤 Suggested Assignees
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord or schedule a call!
coderabbitai commentedon Dec 20, 2025
Coding Plan
Approach
Ticket Summary
Create a special conversion provider in the autowrap system that automatically converts between OpenMS Matrix[ValueT] C++ types and 2D NumPy arrays, using zero-copy memory views when possible to avoid unnecessary data copying for improved performance.
Observations
Codebase Summary
The pyOpenMS project generates Python bindings for OpenMS C++ libraries using the autowrap tool with Cython. Type conversion providers in
src/pyOpenMS/converters/special_autowrap_conversionproviders.pydefine how C++ types map to Python types during the binding generation process. The Matrix[ValueT] template class is already defined insrc/pyOpenMS/pxds/Matrix.pxdwith methods for data access (data(),rows(),cols()), memory layout inspection (rowMajor(),innerStride(),outerStride()), and manipulation (resize(),getValue(),setValue()). Currently, aMatrixDouble.pyxaddon provides numpy integration for Matrix[double] through explicit methods, but functions using Matrix parameters still require intermediate Python Matrix objects rather than working directly with numpy arrays.Assumptions
Assumption 1: Which Matrix[ValueT] template instantiations should be supported?
Options Considered:
Chosen Option: Support at least double and float types from the start
Rationale: These are the most common in scientific computing contexts found in the codebase exploration (e.g., BilinearInterpolation uses Matrix[ValueType], numerical solvers use Matrix[double]). The converter will extract the template argument and map it to appropriate numpy dtypes. This provides immediate value while following the existing pattern of supporting multiple types seen in other converters.
Assumption 2: Should zero-copy views always be created, or should we copy when memory layouts are incompatible?
Options Considered:
Chosen Option: Use Cython's typed memory views which automatically handle memory address translation and create zero-copy views when possible, but be prepared to copy when necessary
Rationale: This balances the ticket's "avoid copies at all costs" directive with practical compatibility needs. Typed memoryviews both use and support the buffer protocol, so they do not copy memory unnecessarily, making them ideal for this use case.
Assumption 3: How should by-reference output parameters be handled after C++ function calls modify the Matrix?
Options Considered:
Chosen Option: For non-const reference parameters, create a temporary Matrix object, pass it to the C++ function, then copy the modified data back to a new numpy array in the cleanup phase
Rationale: This ensures correctness while accepting that by-reference semantics require some copying. This follows the pattern seen in existing converters like OpenMSDPosition1 and OpenMSDPosition2 which use cleanup code to write modified values back to Python variables.
💡 User Tips
Regenerate the plan with different choices with
@coderabbitai <feedback>.Implementation Steps
Phase 1: Converter Class Structure and Type Detection
Create the foundational converter class that integrates with autowrap's type system and correctly identifies Matrix[ValueT] types in function signatures.
Task 1: Define OpenMSMatrixConverter Class
Implement the new converter class in
src/pyOpenMS/converters/special_autowrap_conversionproviders.pyfollowing the established TypeConverterBase pattern.OpenMSMatrixConverterclass inheriting fromTypeConverterBaseget_base_types()methodvalue_type, = cpp_type.template_argsTask 2: Implement Type Matching Logic
Define how the converter identifies applicable Matrix types in function signatures.
matches(cpp_type)method checking forlibcpp_matrixorMatrixbase types with template argumentsTask 3: Define Python Type Hints
Specify how Matrix types appear in generated Python signatures and type stubs.
matching_python_type(cpp_type)to return"np.ndarray"matching_python_type_full(cpp_type)to return detailed type hint like"np.ndarray[np.float64, ndim=2]"based on the value typetype_check_expression(cpp_type, argument_var)to generate runtime validation code ensuring 2D array with correct dtype🤖 Prompt for AI agents
Phase 2: Input Parameter Conversion (Python to C++)
Implement conversion logic for Matrix parameters in C++ function calls, optimizing for zero-copy when the parameter passing mode allows.
Task 1: By-Value Parameter Handling
Create conversion code for functions that take Matrix by value, requiring data copying.
rows = $arg.shape[0],cols = $arg.shape[1]resize(rows, cols)on the Matrix objectsetValue(i, j, value)or bulk memory copy if contiguousTask 2: By-Reference Parameter Handling (Const Reference)
Implement zero-copy strategy for const reference parameters that won't be modified.
cdef double[:,:] view = $argMatrix.data()assignmentrowMajor()methodTask 3: By-Reference Parameter Handling (Non-Const Reference)
Handle mutable reference parameters that may be modified by C++ functions.
cpp_type.is_ref and not cpp_type.is_const$argument_var = <numpy array from Matrix>🤖 Prompt for AI agents
Phase 3: Return Value and Output Conversion (C++ to Python)
Implement conversion logic for Matrix return values and output parameters, creating numpy arrays from Matrix objects.
Task 1: By-Value Return Handling
Convert Matrix objects returned by value to numpy arrays with data copying.
output_conversion()method, generate code to query Matrix dimensions:rows = $result.rows(),cols = $result.cols()np.empty((rows, cols), dtype=np_dtype)getValue(i, j)into numpy array, or usedata()pointer for bulk copynumpy.lib.stride_tricks.as_strided()for efficient layout conversion if needed (as seen in MatrixDouble.pyx)Task 2: Output Parameter Handling (Reference Parameters)
Handle Matrix objects passed as output parameters (non-const reference) that are populated by C++ functions.
cpp_type.is_ref and not cpp_type.is_constin function signatures🤖 Prompt for AI agents
Phase 4: Integration and Testing
Validate the converter with existing Matrix-using functions and ensure proper registration in the autowrap system.
Task 1: Register Converter
Integrate the new converter into the autowrap build system.
OpenMSMatrixConverterto the converter registry insrc/pyOpenMS/converters/__init__.pyautowrap.Main.register_converters()Task 2: Wrap Test Functions
Expose existing Matrix-using C++ functions through pyOpenMS to validate converter behavior.
BilinearInterpolation.getData()/setData()(simple getter/setter),NonNegativeLeastSquaresSolver.solve()(multiple Matrix parameters).pxdfiles (e.g.,src/pyOpenMS/pxds/BilinearInterpolation.pxd), ensure Matrix methods are not marked with# wrap-ignore# wrap-ignorecomments if present on Matrix-related methodsTask 3: Create Unit Tests
Add tests validating correct conversion behavior for different parameter passing modes.
src/pyOpenMS/tests/directory testing Matrix conversion scenariosnp.shares_memory()or comparing data pointers)🤖 Prompt for AI agents
🚀 Next Steps
🤖 All AI agent prompts combined
💡 Iterate on the plan with:
@coderabbitai <feedback>💬 Have feedback or questions? Drop into our discord or schedule a call!
iamritikiit commentedon Dec 21, 2025
Thanks for the detailed write-up — this looks like a really interesting extension to the autowrap system.
I’d be interested in working on a special conversion provider for OpenMS Matrix types. Before starting implementation, I plan to first explore existing conversion providers and understand current Matrix usage patterns in Python bindings, especially around ownership and copying.
@jpfeuffer does the proposed phased approach (type detection → input conversion → output conversion → tests) align with how you’d like this tackled, or are there design constraints I should be aware of upfront?
timosachsenberg commentedon Dec 21, 2025
This could be a complex task and we are not 100% Sure this is the way to go
iamritikiit commentedon Dec 21, 2025
Thanks for the feedback — that makes sense.
I agree it’s important to validate whether a special conversion provider is the right abstraction here before committing to a full implementation. As a first step, I can do a small investigation to:
@timosachsenberg Would it be useful if I reported back with a short summary of findings and a recommended direction before writing any code?
timosachsenberg commentedon Dec 21, 2025
No, this would not be really helpful. We don't know if this is the way to go at this point.
What would help most is stuff we can't easily do with an AI, or we are too time constrained. e.g., stuff that requires a lot of back and forth between us and AI... if you are interested in this I could dig out some tasks that are in this spirit.
What we also always need are people that benchmark on real data and compare results to other existing tools. Or people that come up with smart ways to test the algorithms or enhance test coverage. Unfortunately, most of them require domain knowledge.
iamritikiit commentedon Dec 21, 2025
Thanks for the clarification — that makes sense.
I understand the concern about focusing effort where it’s most useful, and I’m definitely interested in contributing in areas that require more human judgment and iteration rather than straightforward code generation.
Benchmarking on real data, comparing OpenMS results with other tools, and improving algorithm-level testing and test coverage all sound interesting to me. While I’m still building deeper domain knowledge, I’m very willing to invest time in learning the relevant workflows and datasets.
If you’re open to it, I’d really appreciate it if you could point me to a few concrete tasks or areas where additional help would be most valuable as a starting point.
iamritikiit commentedon Dec 24, 2025
@timosachsenberg Just a gentle follow‑up on this thread.
I’m still very interested in contributing on the kinds of tasks you mentioned (benchmarking on real data, comparing OpenMS against other tools, or improving algorithm‑level tests and coverage), and I’m happy to invest time in learning the necessary domain details.
If you have a chance, could you point me to one or two concrete tasks or areas where an extra pair of hands would currently be most useful? I’d like to get started in a way that’s aligned with your priorities
satyam102006 commentedon Feb 23, 2026
Hi @jpfeuffer,
I’ve been following the discussion on improving the ergonomics of pyOpenMS. Given my background in quantitative research and C++/Python integration, I would like to contribute by implementing the conversion provider for OpenMS::Matrix.
My proposed approach for the implementation:
Conversion Layer: I plan to modify special_autowrap_conversionproviders.py to recognize Matrix and utilize Cython Typed Memoryviews.
Zero-Copy Logic: I will implement logic to check for C-contiguous layouts in NumPy arrays to allow direct memory sharing. For non-contiguous inputs, I'll ensure a safe fallback copy to prevent segmentation faults.
Memory Safety: I'll focus on ensuring that the C++ Matrix lifecycle is correctly managed when viewed from Python, particularly addressing the 'ownership' concerns mentioned in the idea phase.
Testing: I can also provide a test suite to verify that the bridging maintains data integrity and performance gains across the C++/Python boundary.
Is there a specific branch I should work against, or would you prefer a draft PR once I have a basic Proof of Concept (PoC) for Matrix?
timosachsenberg commentedon Feb 24, 2026
We are switching soon to nanobind so one would need to check if this is still relevant on the nano branch
jpfeuffer commentedon Feb 24, 2026
I suppose it is still relevant but will require a different strategy. I suppose you did not add any special handling for openms matrix yet @timosachsenberg ?
timosachsenberg commentedon Feb 24, 2026
they can be accessed as numpy view, set from numpy matrix, and converted to numpy matrix
see MatrixDouble in https://github.com/OpenMS/OpenMS/blob/nano/src/pyOpenMS/bindings/bind_datastructures.cpp
not sure why a conversion from row major to column major is needed
jpfeuffer commentedon Feb 24, 2026
yep that's AI slop. Zerocopy should be possible here. Play around with F vs C ordering, or switch the C++ layout to match numpy entirely.
Also, try to use nanobinds built-in wrapper for Eigen! https://nanobind.readthedocs.io/en/latest/eigen.html
feat(nanobind): Implement zero-copy Eigen mapping for MatrixDouble (#…
feat(nanobind): Implement zero-copy Eigen mapping for MatrixDouble (#…
feat(nanobind): Implement zero-copy Eigen mapping for MatrixDouble (#…
timosachsenberg commentedon Mar 10, 2026
Superseded by the nanobind migration on
develop. OpenMS Matrix types now have zero-copy Eigen↔NumPy conversion via nanobind's built-in Eigen support, without needing an autowrap conversion provider.