[QDP] Refactor encode() method into helper functions with tests
#814
+245
−235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Changes Made
Breaking Changes
Detailed Changes
Code Refactoring (
src/lib.rs)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 inputencode()method now acts as a router, delegating to appropriate handlersBenefits:
Test Improvements (
tests/test_bindings.py)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()- Testspathlib.Pathobject inputCode quality improvements:
TEST_DATA_1D,NUM_QUBITS,SAMPLE_SIZE)engine,engine_float64) to reduce duplicationTesting
Checklist