#include "tensorstore/chunk_layout.h"
template <Usage U>
struct tensorstore::ChunkLayout::ChunkElementsFor
   
 : public ChunkElementsBase;

Target number of elements in a chunk for the specified usage U.

This is used in conjunction with any explicit shape constraints and aspect ratio constraints to determine a chunk shape automatically.

Example:

tensorstore::ChunkLayout constraints;

// Sets a soft constraint on the target number of elements to 5000000
TENSORSTORE_RETURN_IF_ERROR(constraints.Set(
    tensorstore::ChunkLayout::ReadChunkElements{
        5000000, /*hard_constraint=*/false}));
EXPECT_EQ(5000000, constraints.read_chunk_elements());
EXPECT_EQ(false, constraints.read_chunk_elements().hard_constraint);

// Soft constraint ignored since it conflicts with existing value.
TENSORSTORE_RETURN_IF_ERROR(constraints.Set(
    tensorstore::ChunkLayout::ReadChunkElements{
        4000000, /*hard_constraint=*/false}));

// Target number of elements remains the same.
EXPECT_EQ(5000000, constraints.read_chunk_elements());
EXPECT_EQ(false, constraints.read_chunk_elements().hard_constraint);

// Sets a hard constraint on the target number of elements to 6000000,
// overrides previous soft constraint.
TENSORSTORE_RETURN_IF_ERROR(constraints.Set(
    tensorstore::ChunkLayout::ReadChunkElements{
        6000000, /*hard_constraint=*/false}));
EXPECT_EQ(6000000, constraints.read_chunk_elements());
EXPECT_EQ(true, constraints.read_chunk_elements().hard_constraint);

// Setting an incompatible hard constraint value is an error.
EXPECT_FALSE(constraints.Set(
    tensorstore::ChunkLayout::ReadChunkElements{
        7000000, /*hard_constraint=*/false}).ok());
EXPECT_EQ(6000000, constraints.read_chunk_elements());

Note:

For this property, a hard constraint still just constrains the target number of elements per chunk. Any explicit constraints on the shape still take precedence, as do any driver-specific constraints.