Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize parent array type #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StridedViews"
uuid = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143"
authors = ["Lukas Devos <[email protected]>", "Jutho Haegeman <[email protected]>"]
version = "0.3.2"
version = "0.3.3"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
4 changes: 4 additions & 0 deletions src/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function _normalizestrides(size::Dims{N}, strides::Dims{N}) where {N}
return strides
end

# 'Normalize' the layout of a DenseArray, in order to reduce the number of required
# specializations in functions.
@inline _normalizeparent(A::DenseArray) = reshape(A, length(A))

# Auxiliary methods for `sview`
#------------------------------
# Compute the new dimensions of a strided view given the original size and the view slicing
Expand Down
8 changes: 5 additions & 3 deletions src/stridedview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ end

# Constructors
#--------------
function StridedView(parent::A,
function StridedView(parent::DenseArray,
size::NTuple{N,Int}=size(parent),
strides::NTuple{N,Int}=strides(parent),
offset::Int=0,
op::F=identity) where {A<:DenseArray,N,F}
op::F=identity) where {N,F}
T = Base.promote_op(op, eltype(parent))
return StridedView{T,N,A,F}(parent, size, _normalizestrides(size, strides), offset, op)
parent′ = _normalizeparent(parent)
strides′ = _normalizestrides(size, strides)
return StridedView{T,N,typeof(parent′),F}(parent′, size, strides′, offset, op)
end

StridedView(a::StridedView) = a
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Random.seed!(1234)
@test isstrided(A1)
@test isstrided(B1)
@test C1 === B1
@test parent(B1) === A1
@test parent(B1) == reshape(A1, :)
@test Base.elsize(B1) == Base.elsize(A1)
for op1 in (identity, conj, transpose, adjoint)
if op1 == transpose || op1 == adjoint
Expand Down
Loading