tesseract v5.3.3.20231005
tesseract::StrideMap::Index Class Reference

#include <stridemap.h>

Public Member Functions

 Index (const StrideMap &stride_map)
 
 Index (const StrideMap &stride_map, int batch, int y, int x)
 
int t () const
 
int index (FlexDimensions dimension) const
 
void InitToFirst ()
 
void InitToLast ()
 
bool IsValid () const
 
bool IsLast (FlexDimensions dimension) const
 
int MaxIndexOfDim (FlexDimensions dim) const
 
bool AddOffset (int offset, FlexDimensions dimension)
 
bool Increment ()
 
bool Decrement ()
 

Detailed Description

Definition at line 44 of file stridemap.h.

Constructor & Destructor Documentation

◆ Index() [1/2]

tesseract::StrideMap::Index::Index ( const StrideMap stride_map)
inlineexplicit

Definition at line 46 of file stridemap.h.

46 : stride_map_(&stride_map) {
48 }

◆ Index() [2/2]

tesseract::StrideMap::Index::Index ( const StrideMap stride_map,
int  batch,
int  y,
int  x 
)
inline

Definition at line 49 of file stridemap.h.

49 : stride_map_(&stride_map) {
50 indices_[FD_BATCH] = batch;
51 indices_[FD_HEIGHT] = y;
52 indices_[FD_WIDTH] = x;
53 SetTFromIndices();
54 }
const double y
@ FD_WIDTH
Definition: stridemap.h:35
@ FD_BATCH
Definition: stridemap.h:33
@ FD_HEIGHT
Definition: stridemap.h:34

Member Function Documentation

◆ AddOffset()

bool tesseract::StrideMap::Index::AddOffset ( int  offset,
FlexDimensions  dimension 
)

Definition at line 67 of file stridemap.cpp.

67 {
68 indices_[dimension] += offset;
69 SetTFromIndices();
70 return IsValid();
71}

◆ Decrement()

bool tesseract::StrideMap::Index::Decrement ( )

Definition at line 92 of file stridemap.cpp.

92 {
93 for (int d = FD_DIMSIZE - 1; d >= 0; --d) {
94 if (indices_[d] > 0) {
95 --indices_[d];
96 if (d == FD_BATCH) {
97 // The upper limits of the other dimensions may have changed as a result
98 // of a different batch index, so they have to be reset.
99 InitToLastOfBatch(indices_[FD_BATCH]);
100 } else {
101 t_ -= stride_map_->t_increments_[d];
102 }
103 return true;
104 }
105 indices_[d] = MaxIndexOfDim(static_cast<FlexDimensions>(d));
106 t_ += stride_map_->t_increments_[d] * indices_[d];
107 // Now borrow from the next dimension.
108 }
109 return false;
110}
FlexDimensions
Definition: stridemap.h:32
@ FD_DIMSIZE
Definition: stridemap.h:36
int MaxIndexOfDim(FlexDimensions dim) const
Definition: stridemap.cpp:46

◆ Increment()

bool tesseract::StrideMap::Index::Increment ( )

Definition at line 75 of file stridemap.cpp.

75 {
76 for (int d = FD_DIMSIZE - 1; d >= 0; --d) {
77 if (!IsLast(static_cast<FlexDimensions>(d))) {
78 t_ += stride_map_->t_increments_[d];
79 ++indices_[d];
80 return true;
81 }
82 t_ -= stride_map_->t_increments_[d] * indices_[d];
83 indices_[d] = 0;
84 // Now carry to the next dimension.
85 }
86 return false;
87}
bool IsLast(FlexDimensions dimension) const
Definition: stridemap.cpp:40

◆ index()

int tesseract::StrideMap::Index::index ( FlexDimensions  dimension) const
inline

Definition at line 59 of file stridemap.h.

59 {
60 return indices_[dimension];
61 }

◆ InitToFirst()

void tesseract::StrideMap::Index::InitToFirst ( )
inline

Definition at line 63 of file stridemap.h.

63 {
64 memset(indices_, 0, sizeof(indices_));
65 t_ = 0;
66 }

◆ InitToLast()

void tesseract::StrideMap::Index::InitToLast ( )
inline

Definition at line 68 of file stridemap.h.

68 {
69 InitToLastOfBatch(MaxIndexOfDim(FD_BATCH));
70 }

◆ IsLast()

bool tesseract::StrideMap::Index::IsLast ( FlexDimensions  dimension) const

Definition at line 40 of file stridemap.cpp.

40 {
41 return MaxIndexOfDim(dimension) == indices_[dimension];
42}

◆ IsValid()

bool tesseract::StrideMap::Index::IsValid ( ) const

Definition at line 24 of file stridemap.cpp.

24 {
25 // Cheap check first.
26 for (int index : indices_) {
27 if (index < 0) {
28 return false;
29 }
30 }
31 for (int d = 0; d < FD_DIMSIZE; ++d) {
32 if (indices_[d] > MaxIndexOfDim(static_cast<FlexDimensions>(d))) {
33 return false;
34 }
35 }
36 return true;
37}
int index(FlexDimensions dimension) const
Definition: stridemap.h:59

◆ MaxIndexOfDim()

int tesseract::StrideMap::Index::MaxIndexOfDim ( FlexDimensions  dim) const

Definition at line 46 of file stridemap.cpp.

46 {
47 int max_index = stride_map_->shape_[dim] - 1;
48 if (dim == FD_BATCH) {
49 return max_index;
50 }
51 assert(0 <= indices_[FD_BATCH]);
52 const size_t batch = indices_[FD_BATCH];
53 if (dim == FD_HEIGHT) {
54 if (batch >= stride_map_->heights_.size() || stride_map_->heights_[batch] > max_index) {
55 return max_index;
56 }
57 return stride_map_->heights_[batch] - 1;
58 }
59 if (batch >= stride_map_->widths_.size() || stride_map_->widths_[batch] > max_index) {
60 return max_index;
61 }
62 return stride_map_->widths_[batch] - 1;
63}

◆ t()

int tesseract::StrideMap::Index::t ( ) const
inline

Definition at line 56 of file stridemap.h.

56 {
57 return t_;
58 }

The documentation for this class was generated from the following files: