From 9e8d3f9c0cc4f454b7114c057c4766dd08085a9c Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Mon, 15 Apr 2024 11:27:22 -0400 Subject: [PATCH] Add more SquarePtrMatrix constructors --- Project.toml | 2 +- src/ptr_array.jl | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 92b1266..b07692d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "StrideArraysCore" uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da" authors = ["Chris Elrod and contributors"] -version = "0.5.3" +version = "0.5.4" [deps] ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" diff --git a/src/ptr_array.jl b/src/ptr_array.jl index 2b1a58e..8feffc4 100644 --- a/src/ptr_array.jl +++ b/src/ptr_array.jl @@ -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(