tesseract v5.3.3.20231005
tesseract::MATRIX Class Reference

#include <matrix.h>

Inheritance diagram for tesseract::MATRIX:
tesseract::BandTriMatrix< BLOB_CHOICE_LIST * > tesseract::GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >

Public Member Functions

 MATRIX (int dimension, int bandwidth)
 
 ~MATRIX () override
 
bool Classified (int col, int row, int wildcard_id) const
 
void IncreaseBandSize (int bandwidth)
 
MATRIXConsumeAndMakeBigger (int ind)
 
MATRIXDeepCopy () const
 
void print (const UNICHARSET &unicharset) const
 
- Public Member Functions inherited from tesseract::BandTriMatrix< BLOB_CHOICE_LIST * >
 BandTriMatrix (int dim1, int dim2, const BLOB_CHOICE_LIST * &empty)
 
int dimension () const
 
int bandwidth () const
 
int index (int column, int row) const override
 
void AttachOnCorner (BandTriMatrix< BLOB_CHOICE_LIST * > *array2)
 
- Public Member Functions inherited from tesseract::GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
 GENERIC_2D_ARRAY (int dim1, int dim2, const BLOB_CHOICE_LIST * &empty, BLOB_CHOICE_LIST * *array)
 
 GENERIC_2D_ARRAY (int dim1, int dim2, const BLOB_CHOICE_LIST * &empty)
 
 GENERIC_2D_ARRAY ()
 
 GENERIC_2D_ARRAY (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &src)
 
virtual ~GENERIC_2D_ARRAY ()
 
void operator= (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &src)
 
void ResizeNoInit (int size1, int size2, int pad=0)
 
void Resize (int size1, int size2, const BLOB_CHOICE_LIST * &empty)
 
void ResizeWithCopy (int size1, int size2)
 
void Clear ()
 
bool Serialize (FILE *fp) const
 
bool Serialize (TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
int dim1 () const
 
int dim2 () const
 
virtual int num_elements () const
 
virtual int index (int column, int row) const
 
void put (ICOORD pos, const BLOB_CHOICE_LIST * &thing)
 
void put (int column, int row, const BLOB_CHOICE_LIST * &thing)
 
BLOB_CHOICE_LIST * get (ICOORD pos) const
 
BLOB_CHOICE_LIST * get (int column, int row) const
 
const BLOB_CHOICE_LIST * & operator() (int column, int row) const
 
BLOB_CHOICE_LIST * & operator() (int column, int row)
 
BLOB_CHOICE_LIST * * operator[] (int column)
 
const BLOB_CHOICE_LIST * * operator[] (int column) const
 
void operator+= (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &addend)
 
void operator+= (const BLOB_CHOICE_LIST * &addend)
 
void operator-= (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &minuend)
 
void operator*= (const BLOB_CHOICE_LIST * &factor)
 
void Clip (const BLOB_CHOICE_LIST * &rangemin, const BLOB_CHOICE_LIST * &rangemax)
 
bool WithinBounds (const BLOB_CHOICE_LIST * &rangemin, const BLOB_CHOICE_LIST * &rangemax) const
 
double Normalize ()
 
BLOB_CHOICE_LIST * Max () const
 
BLOB_CHOICE_LIST * MaxAbs () const
 
void SumSquares (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &src, const BLOB_CHOICE_LIST * &decay_factor)
 
void AdamUpdate (const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &sum, const GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > &sqsum, const BLOB_CHOICE_LIST * &epsilon)
 
void AssertFinite () const
 
void RotatingTranspose (const int *dims, int num_dims, int src_dim, int dest_dim, GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * > *result) const
 
void delete_matrix_pointers ()
 

Additional Inherited Members

- Protected Member Functions inherited from tesseract::GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
bool SerializeSize (FILE *fp) const
 
bool SerializeSize (TFile *fp) const
 
bool DeSerializeSize (bool swap, FILE *fp)
 
bool DeSerializeSize (TFile *fp)
 
- Protected Attributes inherited from tesseract::GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
BLOB_CHOICE_LIST * * array_
 
BLOB_CHOICE_LIST * empty_
 
int dim1_
 
int dim2_
 
int size_allocated_
 

Detailed Description

Definition at line 657 of file matrix.h.

Constructor & Destructor Documentation

◆ MATRIX()

tesseract::MATRIX::MATRIX ( int  dimension,
int  bandwidth 
)
inline

Definition at line 659 of file matrix.h.

660 : BandTriMatrix<BLOB_CHOICE_LIST *>(dimension, bandwidth, NOT_CLASSIFIED) {}
#define NOT_CLASSIFIED
Definition: matrix.h:45

◆ ~MATRIX()

tesseract::MATRIX::~MATRIX ( )
overridedefault

Member Function Documentation

◆ Classified()

bool tesseract::MATRIX::Classified ( int  col,
int  row,
int  wildcard_id 
) const

Definition at line 36 of file matrix.cpp.

36 {
37 if (get(col, row) == NOT_CLASSIFIED) {
38 return false;
39 }
40 BLOB_CHOICE_IT b_it(get(col, row));
41 for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
42 BLOB_CHOICE *choice = b_it.data();
43 if (choice->IsClassified()) {
44 return true;
45 }
46 }
47 return false;
48}
BLOB_CHOICE_LIST * get(ICOORD pos) const
Definition: matrix.h:268

◆ ConsumeAndMakeBigger()

MATRIX * tesseract::MATRIX::ConsumeAndMakeBigger ( int  ind)

Definition at line 61 of file matrix.cpp.

61 {
62 int dim = dimension();
63 int band_width = bandwidth();
64 // Check to see if bandwidth needs expanding.
65 for (int col = ind; col >= 0 && col > ind - band_width; --col) {
66 if (array_[col * band_width + band_width - 1] != empty_) {
67 ++band_width;
68 break;
69 }
70 }
71 auto *result = new MATRIX(dim + 1, band_width);
72
73 for (int col = 0; col < dim; ++col) {
74 for (int row = col; row < dim && row < col + bandwidth(); ++row) {
75 MATRIX_COORD coord(col, row);
76 coord.MapForSplit(ind);
77 BLOB_CHOICE_LIST *choices = get(col, row);
78 if (choices != nullptr) {
79 // Correct matrix location on each choice.
80 BLOB_CHOICE_IT bc_it(choices);
81 for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) {
82 BLOB_CHOICE *choice = bc_it.data();
83 choice->set_matrix_cell(coord.col, coord.row);
84 }
85 ASSERT_HOST(coord.Valid(*result));
86 result->put(coord.col, coord.row, choices);
87 }
88 }
89 }
90 delete this;
91 return result;
92}
#define ASSERT_HOST(x)
Definition: errcode.h:54
MATRIX(int dimension, int bandwidth)
Definition: matrix.h:659

◆ DeepCopy()

MATRIX * tesseract::MATRIX::DeepCopy ( ) const

Definition at line 97 of file matrix.cpp.

97 {
98 int dim = dimension();
99 int band_width = bandwidth();
100 auto *result = new MATRIX(dim, band_width);
101 for (int col = 0; col < dim; ++col) {
102 for (int row = col; row < dim && row < col + band_width; ++row) {
103 BLOB_CHOICE_LIST *choices = get(col, row);
104 if (choices != nullptr) {
105 auto *copy_choices = new BLOB_CHOICE_LIST;
106 copy_choices->deep_copy(choices, &BLOB_CHOICE::deep_copy);
107 result->put(col, row, copy_choices);
108 }
109 }
110 }
111 return result;
112}
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:163

◆ IncreaseBandSize()

void tesseract::MATRIX::IncreaseBandSize ( int  bandwidth)

Definition at line 52 of file matrix.cpp.

52 {
54}
void ResizeWithCopy(int size1, int size2)
Definition: matrix.h:117

◆ print()

void tesseract::MATRIX::print ( const UNICHARSET unicharset) const

Definition at line 115 of file matrix.cpp.

115 {
116 tprintf("Ratings Matrix (top 3 choices)\n");
117 int dim = dimension();
118 int band_width = bandwidth();
119 int row, col;
120 for (col = 0; col < dim; ++col) {
121 for (row = col; row < dim && row < col + band_width; ++row) {
122 BLOB_CHOICE_LIST *rating = this->get(col, row);
123 if (rating == NOT_CLASSIFIED) {
124 continue;
125 }
126 BLOB_CHOICE_IT b_it(rating);
127 tprintf("col=%d row=%d ", col, row);
128 for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
129 tprintf("%s rat=%g cert=%g ", unicharset.id_to_unichar(b_it.data()->unichar_id()),
130 b_it.data()->rating(), b_it.data()->certainty());
131 }
132 tprintf("\n");
133 }
134 tprintf("\n");
135 }
136 tprintf("\n");
137 for (col = 0; col < dim; ++col) {
138 tprintf("\t%d", col);
139 }
140 tprintf("\n");
141 for (row = 0; row < dim; ++row) {
142 for (col = 0; col <= row; ++col) {
143 if (col == 0) {
144 tprintf("%d\t", row);
145 }
146 if (row >= col + band_width) {
147 tprintf(" \t");
148 continue;
149 }
150 BLOB_CHOICE_LIST *rating = this->get(col, row);
151 if (rating != NOT_CLASSIFIED) {
152 BLOB_CHOICE_IT b_it(rating);
153 int counter = 0;
154 for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
155 tprintf("%s ", unicharset.id_to_unichar(b_it.data()->unichar_id()));
156 ++counter;
157 if (counter == 3) {
158 break;
159 }
160 }
161 tprintf("\t");
162 } else {
163 tprintf(" \t");
164 }
165 }
166 tprintf("\n");
167 }
168}
void tprintf(const char *format,...)
Definition: tprintf.cpp:41

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