#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 an ElementPointer<ElementTagType> and an IndexTransform<Rank, LayoutCKind>. The original StridedLayout of the array is represented implicitly as part of the IndexTransform.

Template Parameters:
typename ElementTagType

Must satisfy IsElementTag. Either T or Shared<T>, where T satisfies IsElementType<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 or view. If equal to container, the transformed array owns the index transform. If equal to view, 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 DataType = dtype_t<Element>;

Data type representation.

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 same ElementTag but with the IndexTransform::static_input_rank of OtherTransform, and a layout container kind of container.

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_pointerT&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_tOther&other);

Unchecked conversion from an existing TransformedArray.

explicit TransformedArray(unchecked_tA&array);

Unchecked conversion from an existing Array.

Methods

TransformedArrayoperator=(Other&other) noexcept;

Copy or move assigns from another normalized transformed array.

TransformedArrayoperator=(A&array) noexcept;

Copy or move assigns from another Array.

RankType rank() const;

Returns the rank of the transformed 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.

DataType dtype() const;

Returns the element representation.

const ElementPointerelement_pointer() const&;
ElementPointerelement_pointer() &;
ElementPointer&element_pointer() &&;

Returns the base element pointer.

Elementdata() const;

Returns a raw pointer to the first element of the array.

const Transformtransform() const&;
Transformtransform() &;
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() to base_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.

using tensorstore::TransformedArrayView<ElementTagType, Rank> =
   
 TransformedArray<ElementTagType, Rank>;

Alias for a TransformedArray where the IndexTransform 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 an std::shared_ptr.

using tensorstore::TransformedSharedArrayView<Element, Rank> =
   
 TransformedArray<Shared<Element>, Rank, view>;

Alias for a TransformedArray where the data pointer is stored as an std::shared_ptr and the IndexTransform 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.

constexpr bool tensorstore::IsTransformedArray<T>;

Bool-valued metafunction that evaluates to true if T is an instance of TransformedArray.

constexpr bool tensorstore::IsTransformedArrayLike<T> =
   
 IsArray<T> || IsTransformedArray<T>;

Bool-valued metafunction that evaluates to true if T satisfies IsArray or IsTransformedArray.

constexpr bool tensorstore::IsSharedArrayLike<ArrayLike>;

Bool-valued metafunction that evaluates to true if IsTransformedArrayLike<ArrayLike> and the associated element tag of the array satisfies IsShared.

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 a TransformedSharedArray.

BoxView<Rank> tensorstore::GetBoxDomainOf(
    
const TransformedArray<ElementTagType, Rank, LayoutCKind>array);

Implements the HasBoxDomain concept for TransformedArray.

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&arrayT&transform);

Returns a transformed array representing transform applied to array.

Result<SharedArray<std::remove_const_t<typename A::Element>,
                  
 A::static_rank,
                  
 OriginKind>>
tensorstore::MakeCopy(const Atransformed_array,
                      
IterationConstraints constraints = {
                          
c_order, include_repeated_elements}
);

Returns a copy of a transformed array as a strided array.

absl::Status
tensorstore::CopyTransformedArray(const SourceResultsource,
                                  
const DestResultdest);

Copies from one transformed array to another, possibly converting the data type.

auto tensorstore::ApplyIndexTransform(Expr&exprT&t);

Applies a function that operates on an IndexTransform to a transformed array. The result is always a TransformedArray.

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.