#include "tensorstore/array.h"
template <typename ElementTag,
         
 DimensionIndex Rank,
         
 ContainerKind CKind>
Result<Array<ElementTag, dynamic_rank, zero_origin>>
tensorstore::BroadcastArray(
    
const Array<ElementTag, Rank, zero_origin, CKind>source,
    
span<const Index> target_shape);
template <typename ElementTag,
         
 DimensionIndex Rank,
         
 ArrayOriginKind OriginKind,
         
 ContainerKind CKind>
Result<Array<ElementTag, dynamic_rank, offset_origin>>
tensorstore::BroadcastArray(
    
const Array<ElementTag, Rank, OriginKind, CKind>source,
    
BoxView<> target_domain);

Broadcasts source to target_shape.

For example:

EXPECT_THAT(
    BroadcastArray(MakeArray<int>({1, 2, 3}),
                   tensorstore::span<const Index>({2, 3})),
    MakeArray<int>({{1, 2, 3}, {1, 2, 3}}));

EXPECT_THAT(BroadcastArray(MakeArray<int>({{1}, {2}, {3}}),
                           tensorstore::span<const Index>({3, 2})),
            MakeArray<int>({{1, 1}, {2, 2}, {3, 3}}));
Parameters:
const Array<ElementTag, Rank, zero_origin, CKind> &source
const Array<ElementTag, Rank, OriginKind, CKind> &source

Source array to broadcast.

span<const Index> target_shape

Target shape to which source should be broadcast.

BoxView<> target_domain

Target domain to which source should be broadcast. The origin of source is translated to target_domain.origin().

Returns:

The broadcast array if successful.

Error absl::StatusCode::kInvalidArgument:

if the shapes are not compatible.