viiccwen opened a new pull request, #814: URL: https://github.com/apache/mahout/pull/814
### Purpose of PR Refactor `QdpEngine.encode()` method to improve code maintainability and readability by splitting the monolithic 150+ line method into smaller and focused helper methods. This PR also adds/refactors tests to ensure all adjust code paths are covered. ### Related Issues or PRs [comment](https://github.com/apache/mahout/pull/810#issuecomment-3739248962) ### Changes Made <!-- Please mark one with an "x" --> - [ ] Bug fix - [ ] New feature - [x] Refactoring - [ ] Documentation - [x] Test - [ ] CI/CD pipeline - [ ] Other ### Breaking Changes <!-- Does this PR introduce a breaking change? --> - [ ] Yes - [x] No ### Detailed Changes #### Code Refactoring (`src/lib.rs`) 1. **Split `encode()` method into focused helper methods:** - `encode_from_numpy()` - Handles NumPy array input (1D and 2D) - `encode_from_pytorch()` - Handles PyTorch tensor input (1D and 2D) - `encode_from_list()` - Handles Python list input - Main `encode()` method now acts as a router, delegating to appropriate handlers 2. **Benefits:** - Improved code readability (each method has a single responsibility) - Easier to maintain and modify individual input type handlers - Better testability (each helper method can be tested independently) - Reduced code duplication #### Test Improvements (`tests/test_bindings.py`) 1. **Added 3 tests for refactored paths:** - `test_encode_numpy_array()` - Tests NumPy array encoding (1D and 2D) - `test_encode_pytorch_tensor()` - Tests PyTorch tensor encoding (1D and 2D) - `test_encode_pathlib_path()` - Tests `pathlib.Path` object input 2. **Code quality improvements:** - Extracted test data constants (`TEST_DATA_1D`, `NUM_QUBITS`, `SAMPLE_SIZE`) - Added pytest fixtures (`engine`, `engine_float64`) to reduce duplication - Simplified test functions by using fixtures and constants ### Testing - [x] All existing tests pass - [x] New tests added for all refactored code paths - [x] Tests verify both 1D and 2D inputs for NumPy arrays and PyTorch tensors - [x] Tests verify pathlib.Path object handling ### Checklist <!-- Please mark each item with an "x" when complete --> <!-- If not all items are complete, please open this as a **Draft PR**. Once all requirements are met, mark as ready for review. --> - [x] Added or updated unit tests for all changes - [x] Added or updated documentation for all changes - [x] Successfully built and ran all unit tests or manual tests locally - [x] PR title follows "MAHOUT-XXX: Brief Description" format (if related to an issue) - [x] Code follows ASF guidelines -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
