Skip to content

Commit

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

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
CloseOpenIntervals = "fb6a15b2-703c-40df-9091-08a04967cfa9"
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
LayoutPointers = "10f19ff3-798f-405d-979b-55457f8fc047"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667"
SIMDTypes = "94e857df-77ce-4151-89e5-788b33177be4"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
Expand All @@ -19,6 +20,7 @@ ArrayInterface = "7"
CloseOpenIntervals = "0.1.2"
IfElse = "0.1"
LayoutPointers = "0.1.1"
LinearAlgebra = "1"
ManualMemory = "0.1.6"
SIMDTypes = "0.1"
Static = "0.7, 0.8"
Expand Down
22 changes: 22 additions & 0 deletions src/ptr_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,29 @@ const BitPtrVector1{R,S,X} = AbstractPtrArray{Bool,1,R,S,X,NTuple{1,One},Bit}
const BitPtrMatrix0{R,S,X} = AbstractPtrArray{Bool,2,R,S,X,NTuple{2,Zero},Bit}
const BitPtrMatrix1{R,S,X} = AbstractPtrArray{Bool,2,R,S,X,NTuple{2,One},Bit}

struct SquarePtrMatrix{T,R,S,X,O} <:
AbstractPtrStrideArray{T,2,R,Tuple{S,S},X,O}
ptr::Ptr{T}
size::S
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())
)
import LinearAlgebra
LinearAlgebra.checksquare(A::SquarePtrMatrix) = getfield(A, :size)

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

# function PtrArray(
# ptr::Ptr{T}, sizes::S, strides::X, offsets::O, ::Val{R}
Expand Down Expand Up @@ -489,6 +507,10 @@ end

@inline ArrayInterface.static_size(A::AbstractPtrStrideArray) =
getfield(A, :sizes)
@inline function ArrayInterface.static_size(A::SquarePtrMatrix)
s = getfield(A, :size)
(s, s)
end
@inline function ArrayInterface.static_strides(
A::AbstractPtrStrideArray{<:Any,<:Any,R}
) where {R}
Expand Down
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end

@testset "StrideArraysCore.jl" begin
# Currently StrideArraysCore commits piracy with zero_offsets(A::AbstractArray) and preserve_buffer(A::MemoryBuffer)
Aqua.test_all(StrideArraysCore; piracies=false)
Aqua.test_all(StrideArraysCore; piracies = false)

@testset "StrideArrays Basic" begin

Expand Down Expand Up @@ -442,4 +442,11 @@ end
@test C Ca

end
@testset "square" begin
A = rand(5, 5)
GC.@preserve A begin
B = StrideArraysCore.SquarePtrMatrix(pointer(A), 5)
@test A == B
end
end
end

2 comments on commit b53305e

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

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.3 -m "<description of version>" b53305e6d0992f978c08f2759b73d06510022bab
git push origin v0.5.3

Please sign in to comment.