Skip to content

Commit

Permalink
Fix square_view perf regression
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Apr 23, 2024
1 parent f42feb9 commit 520cf84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/ptr_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ ArrayInterface.device(
::Type{<:AbstractStrideArray{<:Any,<:Any,R,<:Any,X}}
) where {R,X}
i = findfirst(isone, R)
C = i === nothing ? -1 : (X.parameters[i] === Nothing ? i : -1)
C = i === nothing ? -1 : (((X.parameters[i] === Nothing) || (X.parameters[i] === One)) ? i : -1)
# C = i === nothing ? -1 : ((X.parameters[i] === Nothing) ? i : -1)
StaticInt{C}()
end
ArrayInterface.contiguous_batch_size(::Type{<:AbstractStrideArray}) =
Expand Down
8 changes: 5 additions & 3 deletions src/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ function rank_to_sortperm(R::NTuple{N,Int}) where {N}
sp
end
rank_to_sortperm(R) = sortperm(R)

Base.@propagate_inbounds function square_view(A::PtrMatrix, i)
_one_to_nothing(x::I) where {I} = StrideReset(x)
_one_to_nothing(::One) = nothing
Base.@propagate_inbounds function square_view(A::PtrMatrix{T,R,S,X,O}, i::I) where {T,R,S,X,O,I}
# sizes = size(A)
# @boundscheck i <= min(sizes[1], sizes[2]) || throw(BoundsError(A, (i, i)))
SquarePtrMatrix(pointer(A), i, static_strides(A), offsets(A))
x = map(_one_to_nothing, static_strides(A))
SquarePtrMatrix{T,R,I,typeof(x),O}(pointer(A), i, x, offsets(A))
end
# Base.@propagate_inbounds function square_view(A::AbstractMatrix, i)
# StrideArray(square_view(PtrArray(A), i), preserve_buffer(A))
Expand Down

2 comments on commit 520cf84

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/105468

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.6 -m "<description of version>" 520cf84477bec10c45e3249ffcccf796fe551b6f
git push origin v0.5.6

Please sign in to comment.