Manual
Predefined Types
AbstractRNArray
AbstractRNArray
is a subtype of AbstractArray
with predefined size
by getsize
:
Base.size(A::AbstractRNArray)
: returngetsize(A)
,Base.size(A::AbstractRNArray, d)
: returngetsize(A, d)
for1 <= d <= ndims(A)
, and1
ford > ndims(A)
.
AbstractRDArray
AbstractRDArray
is a subtype of DenseArray
with some predefined methods:
Base.unsafe_convert(::Ptr{T}, A::AbstractRDArray) where {T}
: return `Base.unsafe_convert(Ptr{T}, parent(A)),Base.elsize(::Type{T}) where {T<:AbstractRDArray}
: returnBase.elsize(ArrayInterface.parent_type(A))
.
parent_type(::Type{<:AbstractRDArray})
must be a type with above methods.
Resizing Methods
sizehint!
This packages provide methods Base.sizehint!
for AbstractArray
. You can sizehint!
with the same arguments sizehint!(A, n)
as Base.sizehint!
, which suggest that A
reserve capacity for at least n
. Besides, for multi-dimensional arrays, sizehint!(A, sz::NTuple)
is also a convenient way which suggests that array A
reserve capacity for at least prod(sz)
elements.
resize!
resize!
is the core methods of this package, which provide ways to resizing multi-dimensional arrays. There are two form of resize!
:
resize!(A, sz::Tuple)
: ResizeA
to sizesz
, wheresz
can be a tuple accepted byto_indices
(Integer
,Colon
,AbstractVector
, etc.),resize!(A, d::Integer, I)
: Resized
th dimension ofA
toI
, whereA
can be (Integer
,Colon
,AbstractVector
).
There are many interface methods for resizing arrays, most of which depends on parent(A)
and related methods like parent_type
, resize_parent!
, etc.
Interfaces
To create a resizable array type, there are some methods required besides of the interface of AbstractArray
.
Parent
A resizable array type must contain a parent storing data. Thus, Base.parent(A::AbstractArray):
which returns the array storing data and ArrayInterface.parent_type(::Type{T})
which returns the type of parent must be defined. Resizing methods like sizehint!
and resize!
will effect though parent.
Size
Besides, there are also some methods to access and mutate the size of array. The most important methods are ResizingTools.getsize(A)
which returns the size of A
and ResizingTools.size_type(::Type{T})
, which returns the type of getsize(A)
and determine the default methods of setsize!
.
There are two available size types now:
Dims
:NTuple
ofInt
s, the normal size type array, and is the default methods. In this case thesetsize!
will not change anything,Size
: a mutable wrapper ofDims{N}
withsetindex!
andset!
. In this case,setsize!(A, sz)
will callset!(getsize(A), sz)
andsetsize(A, d, i)
will callgetsize(A)[d] = i
.
However, if the size of array is a mutable field of Dims
, setsize(::Type{S}, A::AbstractArray, sz::Dims{N})
and setsize(::Type{S}, A::AbstractArray, d::Int, i::Int)
where S <: Dims
must be defined to mutate the size of array.
Index transform
In some case, the index of A
can't be convert to index of its parent, such as A'
for which A[i, j]' == A'[j, i]
. Thus, in these cases, the index of A
must be transformed. Define ResizingTools.to_parentinds
to do this.
Example
See the implementation of SimpleRDArray
for more details.