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

Accept axes in Base.checkdims_perm #55403

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Aug 7, 2024

Since checkdims_perm only checks the axes of the arrays that are passed to it, this PR adds a method that accepts the axes as arguments instead of the arrays. This will avoid having to specialize on array types.
An example of an improvement:
On master

julia> using LinearAlgebra

julia> D = Diagonal(zeros(1));

julia> Dv = Diagonal(view(zeros(1),:));

julia> @time @eval permutedims(D, (2,1));
  0.016841 seconds (13.68 k allocations: 680.672 KiB, 51.37% compilation time)

julia> @time @eval permutedims(Dv, (2,1));
  0.009303 seconds (11.24 k allocations: 564.203 KiB, 97.79% compilation time)

This PR

julia> @time @eval permutedims(D, (2,1));
  0.016837 seconds (13.42 k allocations: 667.438 KiB, 51.05% compilation time)

julia> @time @eval permutedims(Dv, (2,1));
  0.009076 seconds (6.59 k allocations: 321.156 KiB, 97.46% compilation time)

The allocations are lower in the second call.

I've retained the original method as well, as some packages seem to be using it. This now forwards the axes to the new method.

@jishnub jishnub added the compiler:latency Compiler latency label Aug 7, 2024
Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

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

Nice find!

@dkarrasch dkarrasch added the arrays [a, r, r, a, y, s] label Aug 7, 2024
@jishnub jishnub merged commit bd582f7 into master Aug 7, 2024
9 checks passed
@jishnub jishnub deleted the jishnub/checkdims_perm_axes branch August 7, 2024 16:42
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Aug 17, 2024
Since `checkdims_perm` only checks the axes of the arrays that are
passed to it, this PR adds a method that accepts the axes as arguments
instead of the arrays. This will avoid having to specialize on array
types.
An example of an improvement:
On master
```julia
julia> using LinearAlgebra

julia> D = Diagonal(zeros(1));

julia> Dv = Diagonal(view(zeros(1),:));

julia> @time @eval permutedims(D, (2,1));
  0.016841 seconds (13.68 k allocations: 680.672 KiB, 51.37% compilation time)

julia> @time @eval permutedims(Dv, (2,1));
  0.009303 seconds (11.24 k allocations: 564.203 KiB, 97.79% compilation time)
```
This PR
```julia
julia> @time @eval permutedims(D, (2,1));
  0.016837 seconds (13.42 k allocations: 667.438 KiB, 51.05% compilation time)

julia> @time @eval permutedims(Dv, (2,1));
  0.009076 seconds (6.59 k allocations: 321.156 KiB, 97.46% compilation time)
```
The allocations are lower in the second call.

I've retained the original method as well, as some packages seem to be
using it. This now forwards the axes to the new method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] compiler:latency Compiler latency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants