Skip to content
Merged
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 <lukas.devos@ugent.be>", "Jutho Haegeman <jutho.haegeman@ugent.be>"]
version = "0.3.2"
version = "0.4.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ subsequent dimensions `i` and `i+1` can only be joined if `stride(A,i+1) ==
size(A,i)*stride(A,i)`. Instead of overloading `reshape`, Strided.jl provides a separate
function `sreshape` which returns a `StridedView` over the same parent data, or throws a
runtime error if this is impossible.

### News

Since StridedViews v0.4.0, the `StridedView` type attempts to generate less specializations
by normalizing the parent array type. In particular, for `DenseArray` parents we attempt to
reshape the parent array to a vector, and for `Memory`-based arrays (Julia v1.11+) we unpack
the `Memory` object directly. This should improve compile times.
7 changes: 7 additions & 0 deletions src/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
return strides
end

# 'Normalize' the layout of a DenseArray, in order to reduce the number of required
# specializations in functions.
@static if isdefined(Core, :Memory)
@inline _normalizeparent(A::Array) = A.ref.mem

Check warning on line 51 in src/auxiliary.jl

View check run for this annotation

Codecov / codecov/patch

src/auxiliary.jl#L51

Added line #L51 was not covered by tests
end
@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