-
Notifications
You must be signed in to change notification settings - Fork 14
Broadcasting for Tensor matmul operation on 3D and 4D matrices. #45
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
Conversation
Merge branch `test` into `main`
[Doc] : Update README to reflect GSoC 2025 implementation status
[Refactor] : Iris classification demo into sine wave regression
[Doc] : Update README with new sine wave example
…g support to Tensor_matmul
|
@AZ9tumas, please squash your commits |
|
@AZ9tumas thanks for your first pr to cTensor! Could you change the test file structure? github workflow We built an automatic test here for each operators, checking all the valid operators in the operators.c. Now the workflow has a problem, can you merge the broadcast function into the matmul function itself? So that we don't need to put an extra function in the operators.c, which causes the workflow fails. |
|
Sure, I can integrate the broadcast function into the matmul function but what about slices? There is a function that takes a matrix and returns the 2D matrix based on batch and group. It's a helper function, anywhere else I can place this function so that operator.c can access it? |
|
You can put it in utils.c, as same as Tensor_mul does. broadcast for Tensor_mul |
|
@AZ9tumas The function Tensor_batch_slice defined in utils.c, where is it been used? |
|
I have kept the function there as you had suggested earlier but decided not to use it in the end because of efficiency. |
|
You should remove it if the helper function is not used by anyone.
|
|
Alright I will be adding a final commit removing the function entirely. I hope that this gets merged after that. Thank you for your assistance and guidance. |
Broadcasting Implementation for Matrix Multiplication
The cTensor library has been enhanced with extensive broadcasting support for matrix multiplication operations, bringing it closer to the functionality offered by major tensor libraries like PyTorch and NumPy. This advancement significantly improves the library's flexibility by allowing matrix operations between tensors of different but compatible shapes.
Comprehensive Test Coverage Added
The test suite now includes thorough validation for various broadcasting scenarios:
4D × 4D Broadcasting: Tests matrix multiplication between 4-dimensional tensors with different shapes that are broadcastable, such as
{1,2,2,3} @ {2,1,3,2} -> {2,2,2,2}3D × 4D Broadcasting: Validates operations between 3D and 4D tensors, like
{1,2,3} @ {2,1,3,2} -> {2,1,2,2}, ensuring proper dimension expansion and contraction3D × 3D Broadcasting: Covers scenarios such as
{2,1,3} @ {1,3,2} -> {2,1,2}where broadcasting occurs across batch dimensionsThe test cases verify that:
This implementation ensures that existing functionality remains intact while adding powerful new capabilities for handling tensors with mismatched but compatible dimensions, making cTensor more versatile for real-world applications requiring flexible tensor operations.