Skip to content

Commit

Permalink
square_view fallback method and adjoint&transpose support
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Apr 15, 2024
1 parent 9e8d3f9 commit fc656ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 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.4"
version = "0.5.5"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
21 changes: 11 additions & 10 deletions src/adjoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
q = Expr(
:block,
Expr(:meta, :inline),
:(sz = $getfield(A, :sizes)),
:(sx = $getfield(A, :strides)),
:(o = $getfield(A, :offsets))
)
sz_expr = Expr(:tuple)
squaretype = A <: SquarePtrMatrix
if squaretype
sz_expr = :($getfield(A, :size))
PA = SquarePtrMatrix
else
push!(q.args, :(sz = $getfield(A, :sizes)))
sz_expr = Expr(:tuple)
PA = AbstractPtrArray
end
sx_expr = Expr(:tuple)
o_expr = Expr(:tuple)
rv_expr = Expr(:tuple)
for n = 1:N
j = P[n]
push!(sz_expr.args, :($getfield(sz, $j)))
squaretype || push!(sz_expr.args, :($getfield(sz, $j)))
push!(sx_expr.args, :($getfield(sx, $j)))
push!(o_expr.args, :($getfield(o, $j)))
push!(rv_expr.args, R[j])
end
push!(
q.args,
:(AbstractPtrArray(
pointer(A),
$sz_expr,
$sx_expr,
$o_expr,
Val{$rv_expr}()
))
:($PA(pointer(A), $sz_expr, $sx_expr, $o_expr, Val{$rv_expr}()))
)
q
end
Expand Down
13 changes: 4 additions & 9 deletions src/ptr_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,13 @@ end
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)
offsets::Tuple{O0,O1} = (One(), One()),
::Val{R} = Val((1, 2))
) where {T,S,X0,X1,O0,O1,R} =
SquarePtrMatrix{T,R,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
12 changes: 12 additions & 0 deletions src/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,15 @@ 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)
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
# Base.@propagate_inbounds function square_view(A::AbstractMatrix, i)
# StrideArray(square_view(PtrArray(A), i), preserve_buffer(A))
# end
Base.@propagate_inbounds function square_view(A::AbstractMatrix, i)
@view(A[begin:begin-1+i, begin:begin-1+i])
end

2 comments on commit fc656ee

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

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.5 -m "<description of version>" fc656eeab950a9913dddc2d028bdaa5d1f01a6bc
git push origin v0.5.5

Please sign in to comment.