Skip to content

Refactor project to modularize Tensor code into separate files#16

Merged
PaytonWebber merged 7 commits intomainfrom
refactor/modularize
Jan 29, 2025
Merged

Refactor project to modularize Tensor code into separate files#16
PaytonWebber merged 7 commits intomainfrom
refactor/modularize

Conversation

@PaytonWebber
Copy link
Owner

Overview

This pull request reorganizes the existing Tensor library into multiple modules and files, making the codebase more maintainable and easier to navigate. Previously, most of the functionality was in one large file. Now, the project is broken out into logically separated modules under src/core/. The following modules were created: ops/, errors.rs, traits.rs, and utils.rs. This restructuring follows common Rust patterns and should make it simpler to develop, test, and maintain features going forward.

Changes

  1. Folder and File Structure
    • Created a new core folder under src/, containing:
      • mod.rs as the main entry point for the tensor module.
      • errors.rs, traits.rs, and utils.rs for their respective uses that their name implies.
      • An ops subfolder that holds separate files for binary, unary, movement, and reduction operations (binary.rs, unary.rs, movement.rs, reduce.rs). The broadcast.rs file is also held in the ops directory, and is only used in binary.rs. Learn more about broadcasting here.
  2. Moved Code
    • Moved broadcasting utilities (is_broadcastable, compute_broadcast_shape_and_strides, etc.) into broadcast.rs.
    • Extracted error handling into a dedicated errors.rs file.
    • Separated trait implementations (Add, Sub, etc.) into traits.rs.
    • Placed utility functions (e.g., unravel_index) into utils.rs.
    • Split out major operational logic (binary, unary, movement, reduce) into the ops folder.

Benefits

  • Improved Organization
  • Better Scalability
  • Clearer API

Testing & Verification

  • All existing tests pass, ensuring backward compatibility with previous functionality.
  • No breaking API changes were introduced; code only moved or was separated for clarity.

@PaytonWebber PaytonWebber merged commit 41b02fb into main Jan 29, 2025
1 check passed
@PaytonWebber PaytonWebber deleted the refactor/modularize branch January 29, 2025 04:18
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