tesseract v5.3.3.20231005
tesseract::StrideMap Class Reference

#include <stridemap.h>

Classes

class  Index
 

Public Member Functions

 StrideMap ()
 
void SetStride (const std::vector< std::pair< int, int > > &h_w_pairs)
 
void ScaleXY (int x_factor, int y_factor)
 
void ReduceWidthTo1 ()
 
void TransposeXY ()
 
int Size (FlexDimensions dimension) const
 
int Width () const
 

Detailed Description

Definition at line 41 of file stridemap.h.

Constructor & Destructor Documentation

◆ StrideMap()

tesseract::StrideMap::StrideMap ( )
inline

Definition at line 104 of file stridemap.h.

104 {
105 memset(shape_, 0, sizeof(shape_));
106 memset(t_increments_, 0, sizeof(t_increments_));
107 }

Member Function Documentation

◆ ReduceWidthTo1()

void tesseract::StrideMap::ReduceWidthTo1 ( )

Definition at line 166 of file stridemap.cpp.

166 {
167 widths_.assign(widths_.size(), 1);
168 shape_[FD_WIDTH] = 1;
169 ComputeTIncrements();
170}
@ FD_WIDTH
Definition: stridemap.h:35

◆ ScaleXY()

void tesseract::StrideMap::ScaleXY ( int  x_factor,
int  y_factor 
)

Definition at line 153 of file stridemap.cpp.

153 {
154 for (int &height : heights_) {
155 height /= y_factor;
156 }
157 for (int &width : widths_) {
158 width /= x_factor;
159 }
160 shape_[FD_HEIGHT] /= y_factor;
161 shape_[FD_WIDTH] /= x_factor;
162 ComputeTIncrements();
163}
@ FD_HEIGHT
Definition: stridemap.h:34

◆ SetStride()

void tesseract::StrideMap::SetStride ( const std::vector< std::pair< int, int > > &  h_w_pairs)

Definition at line 131 of file stridemap.cpp.

131 {
132 int max_height = 0;
133 int max_width = 0;
134 for (const std::pair<int, int> &hw : h_w_pairs) {
135 int height = hw.first;
136 int width = hw.second;
137 heights_.push_back(height);
138 widths_.push_back(width);
139 if (height > max_height) {
140 max_height = height;
141 }
142 if (width > max_width) {
143 max_width = width;
144 }
145 }
146 shape_[FD_BATCH] = heights_.size();
147 shape_[FD_HEIGHT] = max_height;
148 shape_[FD_WIDTH] = max_width;
149 ComputeTIncrements();
150}
@ FD_BATCH
Definition: stridemap.h:33

◆ Size()

int tesseract::StrideMap::Size ( FlexDimensions  dimension) const
inline

Definition at line 119 of file stridemap.h.

119 {
120 return shape_[dimension];
121 }

◆ TransposeXY()

void tesseract::StrideMap::TransposeXY ( )

Definition at line 173 of file stridemap.cpp.

173 {
174 std::swap(shape_[FD_HEIGHT], shape_[FD_WIDTH]);
175 std::swap(heights_, widths_);
176 ComputeTIncrements();
177}

◆ Width()

int tesseract::StrideMap::Width ( ) const
inline

Definition at line 123 of file stridemap.h.

123 {
124 return t_increments_[FD_BATCH] * shape_[FD_BATCH];
125 }

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