Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved backend, union handling, tensor creation APIs #68

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

yxlao
Copy link
Owner

@yxlao yxlao commented Jul 9, 2024

Overview

This pull request introduces refactoring and enhancements to the camtools backend module, focusing on improved type handling, backend compatibility, and streamlined operations across NumPy and PyTorch. The changes aim to enhance maintainability, performance, and usability.

Key Changes

  • Renaming of Backend Decorators:

    • Renamed @tensor_to_auto_backend to @tensor_backend_auto to clarify its automatic backend selection functionality.
    • Renamed @tensor_to_numpy_backend to @tensor_backend_numpy and @tensor_to_torch_backend to @tensor_backend_torch, making their specific backend operations more explicit.
  • Enhanced Type Hints and Tensor Operations:

    • Updated the handling of tensor type hints to support Union types, allowing more versatile function signatures.
    • Introduced new utility functions such as create_array, create_ones, create_zeros, and create_empty. These functions standardize tensor creation across different backends and are explicitly tied to the specified backend literal.
  • Advanced Tensor Type and Shape Checks:

    • Improved _assert_tensor_hint to handle Union types effectively, enhancing the robustness of type and shape verifications.
    • Updated error handling to provide more specific ValueError exceptions related to tensor shapes and dtypes, standardizing error messages across the module.
  • Backend Handling Improvements:

    • Optimized @tensor_backend_auto decorator for more efficient backend determination and tensor conversion.
    • Added explicit backend specification via a Literal["numpy", "torch"] parameter to manage backend-dependent tensor operations better.
  • Documentation and Code Clean-Up:

    • Conducted a major clean-up in the backend module to remove deprecated functions related to direct backend management.
    • Enhanced docstrings for improved clarity and detailed usage information.
    • Revised internal utility functions for backend conversions to reduce redundancy and enhance performance.

Testing and Compatibility

  • Expanded the test suite in test_backend.py to cover new scenarios introduced by Union type hints and new tensor creation functions.
  • Adapted all existing tests to the refactored backend handling and type checks to ensure comprehensive coverage and reliability.

@yxlao yxlao merged commit ca82689 into flex-backend Jul 9, 2024
9 checks passed
@yxlao yxlao deleted the yixing/improved-backend branch July 9, 2024 14:27
yxlao added a commit that referenced this pull request Jul 9, 2024
This PR is a combination of:
* feat: automatic tensor backend and type checks (#64)
* perf: performance improvements for backend function wrappers (#66)
* feat: improved backend, union handling, tensor creation APIs (#68)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant