-
#include "tensorstore/box.h" -
template <DimensionIndex Rank = dynamic_rank>
class tensorstore::Box; Value type representing an n-dimensional hyperrectangle.
Hyperrectangles logically correspond to a cartesian product of
IndexIntervalobjects, and are represented as anoriginvector and ashapevector, which is equivalent to the “sized” index interval representation: the components of theoriginvector correspond toIndexInterval::inclusive_minvalues, while the components of theshapevector correspond to theIndexInterval::sizevalues (not toIndexInterval::exclusive_maxvalues).Several related class templates are provided:
Box<Rank>has value semantics (owns itsoriginandshapevectors) and is mutable. This type stores a hyperrectangle and manages the storage.BoxView<Rank>represents a const view that behaves similarly tostd::string_view: logically it points to existingoriginandshapevectors (of typetensorstore::span<const Index, Rank>). Likestd::string_view, assignment is shallow and merely reassigns itsoriginandshapepointers, but comparison is deep. This type is useful as an input parameter type for a function.MutableBoxView<Rank>(an alias forBoxView<Rank, true>) represents a mutable view: it points to existingoriginandshapevectors (of typetensorstore::span<Index, Rank>). LikeBoxView<Rank>, assignment is shallow but comparison is deep. TheBoxView::DeepAssignmethod may be used for deep assignment (modifies the contents of the referencedoriginandshapevectors). This type is useful as an output or input/output parameter type for a function.
These types are useful for specifying hyperrectangular sub-regions, and in particular can be used to represent the domains of arrays, index transforms, and tensor stores.
Note
Like other facilities within the TensorStore library, the rank of the index space may be specified either at compile time using the
Ranktemplate parameter, or at run time by specifying aRankofdynamic_rank.Example usage:
void Intersect(BoxView<> a, BoxView<> b, MutableBoxView<> out) { const DimensionIndex rank = a.rank(); assert(b.rank() == rank && out.rank() == rank); for (DimensionIndex i = 0; i < rank; ++i) { out[i] = Intersect(a[i], b[i]); } } const Index a_origin[] = {1, 2}; const Index a_shape[] = {3, 4}; auto b = Box({2,1}, {2, 2}); Index c_origin[2], c_shape[2]; // Assigns `c_origin` and `c_shape` to the intersection of // `(a_origin,a_shape)` and `b`. Intersect(BoxView(a_origin, a_shape), b, BoxView(c_origin, c_shape)); // Assigns `d` to the intersection of `(a_origin,a_shape)` and `b`. Box d(2); Intersect(BoxView(a_origin, a_shape), b, d);- Template Parameters:¶
- DimensionIndex Rank = dynamic_rank¶
If non-negative, specifies the number of dimensions at compile time. If equal to
dynamic_rank(inline_size), ordynamic_rank(equivalent to specifyinginline_size==0), the number of dimensions will be specified at run time. If the number of dimensions is not greater thaninline_size, no heap allocation is necessary.
Data members¶
-
constexpr const DimensionIndex static_rank = (Rank < 0) ? dynamic_rank
: Rank; Compile-time rank, or
dynamic_rankif the rank is specified at run time.
Types¶
- using RankType = StaticOrDynamicRank<Rank>;
Type that represents the static or dynamic rank.
Constructors¶
- Box();
Constructs a rank-0 box (if
static_rank == dynamic_rank), or otherwise an unbounded box of rankstatic_rank.
- explicit Box(OriginVec origin, ShapeVec shape);
- explicit Box(const Index (&origin)[N], const Index (&shape)[N]);
Constructs from an origin array and shape array.
- explicit Box(RankType rank, OriginT* origin, ShapeT* shape);
Constructs from a rank, an origin base pointer, and a shape base pointer.
- explicit Box(const ShapeVec& shape);
- explicit Box(const Index (&shape)[N]);
Constructs from a shape vector.
- explicit Box(unchecked_t, const BoxType& other);
Unchecked conversion.
- explicit Box(unchecked_t, Box&& other);
Unchecked conversion.
Methods¶
- IndexInterval operator[](DimensionIndex i) const;
- IndexIntervalRef operator[](DimensionIndex i);
Returns a copy/reference to the index interval for dimension
i.
- auto operator()(Transformable&& transformable) const;
Slices a type with an index domain a box.
Accessors¶
- span<const Index, static_rank> origin() const;
- span<Index, static_rank> origin();
Returns the origin array of length
rank().
- span<const Index, static_rank> shape() const;
- span<Index, static_rank> shape();
Returns the shape array of length
rank().
- Index num_elements() const;
Returns the product of the extents.
- bool is_empty() const;
Returns
trueifnum_elements() == 0.
Assignment¶
- void Fill(IndexInterval interval = {});
Fills
origin()withinterval.inclusive_min()andshapewithinterval.size().
Friend functions¶
Related Functions¶
- T tensorstore::ProductOfExtents(span<T, Extent> s);
Computes the product of the elements of the given span.
-
BoxView<RankConstraint::FromInlineRank(Rank)>
tensorstore::GetBoxDomainOf(const Box<Rank>& box); -
BoxView<Rank>
tensorstore::GetBoxDomainOf(const BoxView<Rank, Mutable>& box); Implements the
HasBoxDomainconcept forBoxandBoxView.
- bool tensorstore::IsFinite(const BoxType& box);
Returns
trueif all dimensions ofboxhave finite bounds.
-
bool tensorstore::Contains(const BoxType& box,
const Indices& indices); -
bool tensorstore::Contains(const BoxType& box,
const Index (&indices)[IndicesRank]); Returns
trueif the index vectorindicesis contained within the box, i.e. its length is equal to the rank of the box and each componentindices[i]is contained withinbox[i].
-
bool tensorstore::ContainsPartial(const BoxType& box,
const Indices& indices); -
bool tensorstore::ContainsPartial(
const BoxType& box,
const Index (&indices)[IndicesRank]); Returns
trueif the partial index vectorindicesis contained within the box, i.e. its length is less than or equal to the rank of the box and each componentindices[i]is contained withinbox[i].
-
BoxView<dynamic_rank, IsMutableBoxLike<BoxType>>
tensorstore::SubBoxView(BoxType&& box,
DimensionIndex begin = 0,
DimensionIndex end = -1); Returns a view of the sub-box corresponding to the specified dimension range.
Related Constants¶
- constexpr bool tensorstore::IsBoxLike<T>;
Metafunction that evaluates to
trueif, and only if,Tis an optionally cvref-qualified Box or BoxView instance.
- constexpr bool tensorstore::IsMutableBoxLike<T>;
Metafunction that evaluates to
trueif, and only if,Tis an optionally ref-qualified non-const Box or MutableBoxView instance.
-
constexpr bool
tensorstore::IsBoxLikeImplicitlyConvertibleToRank<T, Rank>; Metafunction that evaluates to
trueif, and only if,Tis a Box-like type withBox::static_rankimplicitly convertible toRank.
-
constexpr bool
tensorstore::IsBoxLikeExplicitlyConvertibleToRank<T, Rank>; Metafunction that evaluates to
trueif, and only if,Tis a Box-like type withBox::static_rankexplicitly convertible toRank.
- constexpr bool tensorstore::HasBoxDomain<T>;
Metafunction that is specialized to return
truefor typesTfor whichtensorstore::GetBoxDomainOfwhen called with a parameter of typeconst T&returns a Box-like type.
Related Types¶
- class tensorstore::BoxView<Rank, Mutable>;
Represents an unowned view of a
Rank-dimensional hyperrectangle.
- using tensorstore::MutableBoxView<Rank> = BoxView<Rank, true>;
Mutable view of a
Box.