diff --git a/Project.toml b/Project.toml index d02f6b4..2f7a05d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "StridedViews" uuid = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143" authors = ["Lukas Devos ", "Jutho Haegeman "] -version = "0.3.2" +version = "0.3.3" [deps] CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" diff --git a/src/auxiliary.jl b/src/auxiliary.jl index 78a5be4..ccc95b3 100644 --- a/src/auxiliary.jl +++ b/src/auxiliary.jl @@ -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 diff --git a/src/stridedview.jl b/src/stridedview.jl index 03e2abc..2a5c3e5 100644 --- a/src/stridedview.jl +++ b/src/stridedview.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 5f3d284..c8d7791 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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