Build Status | Coverage | Quality assurance |
---|---|---|
StridedViews.jl exports a single struct type StridedView
for representing a strided view
over a contiguous parrent array, as represented by the abstract type DenseArray
.
See Strided.jl for more functionality.
The type StridedView
provides a view into a parent array of type DenseArray
such that
the resulting view is strided, i.e. any dimension has an associated stride, such that e.g.
getindex(A, i₁, i₂, i₃, ...) = A.op(A.parent[offset + 1 + (i₁-1)*s₁ + (i₂-1)*s₂ + (i₃-1)*s₃ + ...])
with sⱼ = stride(A, iⱼ)
. There are no further assumptions on the strides, e.g. they are
not assumed to be monotonously increasing or have s₁ == 1
. Furthermore, A.op
can be any
of the operations identity
, conj
, transpose
or adjoint
(the latter two are
equivalent to the former two if eltype(A) <: Number
). Since these operations are their own
inverse, they are also used in the corresponding setindex!
.
This definition enables a StridedView
to be lazy (i.e. returns just another StridedView
over the same parent data) under application of conj
, transpose
, adjoint
,
permutedims
and indexing (getindex
) with Union{Integer, Colon, AbstractRange{<:Integer}}
(a.k.a slicing). The function sview
is exported to directly
create a sliced (and thus strided) view over a given parent array.
Furthermore, the strided structure can be retained under certain reshape
operations, but
not all of them. Any dimension can always be split into smaller dimensions, but two
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.