-
#include "tensorstore/array.h"
-
template <typename Element,
DimensionIndex Rank = dynamic_rank,
ArrayOriginKind OriginKind = zero_origin,
ContainerKind LayoutContainerKind = container>
using tensorstore::SharedArray =
Array<Shared<Element>, Rank, OriginKind, LayoutContainerKind>; Convenience alias for an in-memory multi-dimensional array with an arbitrary strided layout with optional shared ownership semantics.
The element type may either be specified at compile time, or be left unspecified at compile time and be specified at run time. The rank may also either be specified at compile time, or be left unspecified at compile-time and be specified at run time.
This type is intended as a “vocabulary” type (like
std::function
, orstd::shared_ptr
) for storing arbitrary in-memory strided multi-dimensional arrays, and is very similar to the NumPy ndarray type. The shared ownership support, which is built on top ofstd::shared_ptr
, permits this type to safely interoperate with almost any strided multi-dimensional array library, regardless of how the underlying array storage is allocated.Conceptually,
SharedArray
combines aSharedElementPointer<Element>
, which represents either an unowned reference to the array data, or shared ownership of the array data, with aStridedLayout<Rank>
, which represents the layout (specifically theStridedLayout::shape
andStridedLayout::byte_strides
) with value semantics. Copying anArray
object copies the layout (such that any changes to the layout in one copy do not affect other copies) but does not copy the multi-dimensional array data (such that any changes to the array data made using oneArray
object will also be reflected in any other copies). TheCopyArray
function can be used to actually copy the array data.Example usage:
snippet tensorstore/array_test.cc SharedArray usage example
The related type
ArrayView
has unowned reference semantics for both the layout and the array data, and is useful as a function parameter type when a reference to neither the array data nor the layout is retained after the function returns.The related type
SharedArrayView
has unowned reference semantics for the layout but optional shared ownership of the array data, and is useful as a function parameter type when a reference to the array data, but not the layout, may be retained after the function returns.- Template Parameters:¶
- typename Element¶
Specifies the optionally const-qualified compile-time element type of the array. An
Element
parameter ofvoid
orconst void
indicates that the actual element type is determined at run time. Specifying a const-qualified type, includingconst void
, indicates that the multi-dimensional array is const.- DimensionIndex Rank = dynamic_rank¶
Specifies the compile-time rank. The special value
dynamic_rank
indicates that the rank is determined at run time. IfLayoutContainerKind == container
,dynamic_rank(n)
forn >= 0
may be specified to indicate a rank determined at run time and inline layout storage for ranks<= n
.- ArrayOriginKind OriginKind = zero_origin¶
Specifies whether the origin for each dimension is fixed at 0, or may be offset.
- ContainerKind LayoutContainerKind = container¶
Specifies whether the layout (shape, byte strides, and optional origin) is stored by value or by reference.