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

addition transpose 2D #401

Merged
merged 1 commit into from
Oct 25, 2023
Merged

Conversation

chachaleo
Copy link
Contributor

Pull Request type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

In the implementation of tensor.transpose in https://github.com/gizatechxyz/orion/blob/main/src/operators/tensor/linalg/transpose.cairo, the implementation is very general and support any permutations. However, one of the most general use case, matrix transposition, could be done in a more optimized way. As it is used a lot in matrix theory and in linear algebra it can be important to have a more optimized implementation.

Issue Number: #394

What is the new behavior?

If the dimension of the input tensor is 2, the function transpose calls a sub-function transpose2D that computes the transposition of a 2D tensor. The 2D tensor transposition is a trivial permutation of axes and the corresponding retrieval of the element is therefore more straightforward.
It directly gets the data from the input and avoids the creation of temporary arrays to support the more general permutation of the ND tensor problem.

output_data.append(*(*self.data)[i * m + j]);

With this implementation, transposition of 2D tensor is consumes about one order of magnitude less of gas.

Copy link
Collaborator

@raphaelDkhn raphaelDkhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@raphaelDkhn raphaelDkhn merged commit eec864d into gizatechxyz:main Oct 25, 2023
1 check passed
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.

2 participants