-
#include "tensorstore/index_space/transformed_array.h"
-
template <typename ElementTagType,
DimensionIndex Rank,
ContainerKind LayoutCKind>
class tensorstore::TransformedArray; View through an index transform of an in-memory array.
Example of making a transformed array directly:
// Transform that extracts the diagonal. IndexTransform<> t = IndexTransformBuilder<>(1, 2) .output_single_input_dimension(0, 0) .output_single_input_dimension(1, 0) .Finalize() .value(); auto source_array = MakeArray<int>({1, 2, 3}, {4, 5, 6}, {7, 8, 9}); auto dest_array = AllocateArray<int>({3}); TENSORSTORE_ASSIGN_OR_RETURN(auto transformed_array, source_array | t); // Copy the diagonal of source_array to dest_array. IterateOverTransformedArrays([](const int* x, int* y) { *y = *x; }, /*constraints=*/{}, transformed_array, dest_array); // dest_array equals {1, 5, 9}.
Example of making a transformed array using
DimExpression
:TENSORSTORE_ASSIGN_OR_RETURN( auto transformed_array, tensorstore::MakeArray<int>({{1, 2, 3}, {4, 5, 6}}) | tensorstore::Dims(0).TranslateTo(10) | tensorstore::Dims(0, 1).IndexVectorArraySlice( tensorstore::MakeArray<Index>({10, 1}, {11, 1}, {11, 2})) | tensorstore::Dims(0).Label("a"));
Logically, a
TransformedArray
is represented by anElementPointer<ElementTagType>
and anIndexTransform<Rank, LayoutCKind>
. The originalStridedLayout
of the array is represented implicitly as part of theIndexTransform
.- Template Parameters:¶
- typename ElementTagType¶
Must satisfy
IsElementTag
. EitherT
orShared<T>
, whereT
satisfiesIsElementType<T>
.- DimensionIndex Rank¶
The static rank of the transformed array. May be
dynamic_rank
to allow the rank to be determined at run time.- ContainerKind LayoutCKind¶
Either
container
orview
. If equal tocontainer
, the transformed array owns the index transform. If equal toview
, an unowned reference to the index transform is stored.
Types¶
- using ElementTag = ElementTagType;
Element tag type of the array.
- using ElementPointer = ElementPointer<ElementTag>;
Element pointer type.
- using Pointer = typename ElementPointer::Pointer;
Data pointer type.
- using Transform = IndexTransform<Rank, dynamic_rank, LayoutCKind>;
Index transform type.
- using Element = typename ElementPointer::Element;
Element type.
- using RankType = StaticOrDynamicRank<static_rank>;
Static or dynamic rank representation type.
-
using RebindTransform<OtherTransform> =
TransformedArray<ElementTagType,
OtherTransform::static_input_rank>; Alias that evaluates to the
TransformedArray
type with the sameElementTag
but with theIndexTransform::static_input_rank
ofOtherTransform
, and a layout container kind ofcontainer
.
Data members¶
-
constexpr const DimensionIndex static_rank =
Transform::static_input_rank; Compile-time rank constraint, or
dynamic_rank
if the rank is determined at run time.
- constexpr const ContainerKind layout_container_kind = LayoutCKind;
Layout container kind.
Constructors¶
- TransformedArray();
Constructs an invalid transformed array.
- TransformedArray(P&& element_pointer, T&& transform);
Constructs a normalized transformed array from an element pointer and an index transform.
- TransformedArray(A&& array);
Constructs a transformed array from a regular strided
Array
.
- TransformedArray(Other&& other);
Copy or move constructs from another normalized transformed array.
- explicit TransformedArray(unchecked_t, Other&& other);
Unchecked conversion from an existing
TransformedArray
.
- explicit TransformedArray(unchecked_t, A&& array);
Unchecked conversion from an existing
Array
.
Methods¶
- TransformedArray& operator=(Other&& other) noexcept;
Copy or move assigns from another normalized transformed array.
- TransformedArray& operator=(A&& array) noexcept;
Copy or move assigns from another
Array
.
- IndexDomainView<static_rank> domain() const;
Returns the domain of the transformed array.
- span<const Index, static_rank> origin() const;
Returns the origin vector of the transformed array.
- span<const Index, static_rank> shape() const;
Returns the shape vector of the transformed array.
- span<const std::string, static_rank> labels() const;
Returns the dimension label vector.
- const ElementPointer& element_pointer() const&;
- ElementPointer& element_pointer() &;
- ElementPointer&& element_pointer() &&;
Returns the base element pointer.
- const Transform& transform() const&;
- Transform& transform() &;
- Transform&& transform() &&;
Returns the transform.
- ArrayView<ElementTag, dynamic_rank, offset_origin> base_array() const;
Returns a fake “base array” such that this transformed array is equivalent to applying
transform()
tobase_array()
.
-
Result<SharedArray<const Element, Rank, OriginKind>>
Materialize(TransformArrayConstraints constraints =
skip_repeated_elements) const; Materializes the transformed array as a strided array.
-
PipelineResultType<const TransformedArray&, Func>
operator|(Func&& func) const&; -
PipelineResultType<TransformedArray&&, Func>
operator|(Func&& func) &&; “Pipeline” operator.
Related Types¶
-
using tensorstore::TransformedArrayView<ElementTagType, Rank> =
TransformedArray<ElementTagType, Rank>; Alias for a
TransformedArray
where theIndexTransform
is stored by unowned reference.
-
using tensorstore::
TransformedSharedArray<Element, Rank, LayoutCKind> =
TransformedArray<Shared<Element>, Rank, LayoutCKind>; Alias for a
TransformedArray
where the data pointer is stored as anstd::shared_ptr
.
-
using tensorstore::TransformedSharedArrayView<Element, Rank> =
TransformedArray<Shared<Element>, Rank, view>; Alias for a
TransformedArray
where the data pointer is stored as anstd::shared_ptr
and theIndexTransform
is stored by unowned reference.
-
using tensorstore::TransformedArrayTypeFromArray<A> =
TransformedArray<typename A::ElementTag,
A::static_rank,
A::layout_container_kind>; Alias that evaluates to the transformed array type corresponding to a strided array type.
-
using tensorstore::TransformedArrayTypeFromArrayAndTransform<A, T> =
TransformedArray<typename A::ElementTag,
T::static_input_rank,
container>; Alias that evaluates to the transformed array type corresponding to the normalized combination of a strided array type and an index transform.
Related Constants¶
- constexpr bool tensorstore::IsTransformedArray<T>;
Bool-valued metafunction that evaluates to
true
ifT
is an instance ofTransformedArray
.
-
constexpr bool tensorstore::IsTransformedArrayLike<T> =
IsArray<T> || IsTransformedArray<T>; Bool-valued metafunction that evaluates to
true
ifT
satisfiesIsArray
orIsTransformedArray
.
- constexpr bool tensorstore::IsSharedArrayLike<ArrayLike>;
Bool-valued metafunction that evaluates to
true
ifIsTransformedArrayLike<ArrayLike>
and the associated element tag of the array satisfiesIsShared
.
Related Functions¶
-
TransformedArray<Shared<Element>, Rank, LayoutCKind>
tensorstore::UnownedToShared(
TransformedArray<Element, Rank, LayoutCKind> array); -
TransformedArray<Shared<Element>, Rank, LayoutCKind>
tensorstore::UnownedToShared(
const std::shared_ptr<T>& owned,
TransformedArray<Element, Rank, LayoutCKind> array); -
TransformedArray<Shared<Element>, Rank, LayoutCKind>
tensorstore::UnownedToShared(
TransformedArray<Shared<Element>, Rank, LayoutCKind> array); Converts an arbitrary
TransformedArray
to aTransformedSharedArray
.
-
BoxView<Rank> tensorstore::GetBoxDomainOf(
const TransformedArray<ElementTagType, Rank, LayoutCKind>& array); Implements the
HasBoxDomain
concept forTransformedArray
.
-
Result<IndexTransform<std::remove_cvref_t<T>::static_input_rank,
RankConstraint::FromInlineRank(R)>>
tensorstore::ComposeLayoutAndTransform(
const StridedLayout<R, O, AC>& layout,
T&& transform); Returns an index transform composed from a strided layout and an existing index transform.
-
Result<
TransformedArrayTypeFromArrayAndTransform<std::remove_cvref_t<A>,
std::remove_cvref_t<T>>>
tensorstore::MakeTransformedArray(A&& array, T&& transform); Returns a transformed array representing
transform
applied toarray
.
-
Result<SharedArray<std::remove_const_t<typename A::Element>,
A::static_rank,
OriginKind>>
tensorstore::MakeCopy(const A& transformed_array,
IterationConstraints constraints = {
c_order, include_repeated_elements}); Returns a copy of a transformed array as a strided array.
-
absl::Status
tensorstore::CopyTransformedArray(const SourceResult& source,
const DestResult& dest); Copies from one transformed array to another, possibly converting the data type.
- auto tensorstore::ApplyIndexTransform(Expr&& expr, T&& t);
Applies a function that operates on an
IndexTransform
to a transformed array. The result is always aTransformedArray
.
-
auto tensorstore::Materialize(
TransformArrayConstraints constraints = skip_repeated_elements); Materializes the transformed array as a strided array.
-
Result<Array<ElementTag, Rank, OriginKind>>
tensorstore::TryConvertToArray(
const TransformedArray<ElementTag, Rank, LayoutCKind>&
transformed_array); -
Result<Array<ElementTag, Rank, OriginKind>>
tensorstore::TryConvertToArray(
TransformedArray<ElementTag, Rank, LayoutCKind>&&
transformed_array); - auto tensorstore::TryConvertToArray();
Returns a view of the array as a regular strided
Array
.
-
Result<bool> tensorstore::IterateOverTransformedArrays(
Func&& func,
IterationConstraints constraints,
const Arrays&... arrays); Jointly iterates over one or more transformed arrays with compatible domains.