Skip to content

Commit

Permalink
Add more SquarePtrMatrix constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Apr 15, 2024
1 parent b53305e commit 9e8d3f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StrideArraysCore"
uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da"
authors = ["Chris Elrod <[email protected]> and contributors"]
version = "0.5.3"
version = "0.5.4"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
20 changes: 13 additions & 7 deletions src/ptr_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,22 @@ struct SquarePtrMatrix{T,R,S,X,O} <:
strides::X
offsets::O
end
SquarePtrMatrix(p::Ptr{T}, s::S) where {T,S} =
SquarePtrMatrix{T,(1, 2),S,Tuple{Nothing,Nothing},Tuple{One,One}}(
p,
s,
(nothing, nothing),
(One(), One())
)
@inline SquarePtrMatrix(
p::Ptr{T},
s::S,
strides::Tuple{X0,X1} = (nothing, nothing),
offsets::Tuple{O0,O1} = (One(), One())
) where {T,S,X0,X1,O0,O1} =
SquarePtrMatrix{T,(1, 2),S,Tuple{X0,X1},Tuple{O0,O1}}(p, s, strides, offsets)
import LinearAlgebra
LinearAlgebra.checksquare(A::SquarePtrMatrix) = getfield(A, :size)

Base.@propagate_inbounds function square_view(A::PtrMatrix, 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))
end

@inline valisbit(::AbstractPtrArray{<:Any,<:Any,<:Any,<:Any,<:Any,<:Any,Bit}) =
Val(true)
@inline valisbit(
Expand Down

2 comments on commit 9e8d3f9

@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/104947

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.4 -m "<description of version>" 9e8d3f9c0cc4f454b7114c057c4766dd08085a9c
git push origin v0.5.4

Please sign in to comment.