#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, or std::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 of std::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 a SharedElementPointer<Element>, which represents either an unowned reference to the array data, or shared ownership of the array data, with a StridedLayout<Rank>, which represents the layout (specifically the StridedLayout::shape and StridedLayout::byte_strides) with value semantics. Copying an Array 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 one Array object will also be reflected in any other copies). The CopyArray 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 of void or const void indicates that the actual element type is determined at run time. Specifying a const-qualified type, including const 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. If LayoutContainerKind == container, dynamic_rank(n) for n >= 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.