tesseract  5.0.0-alpha-619-ge9db
MATRIX Class Reference

#include <matrix.h>

Inheritance diagram for MATRIX:
BandTriMatrix< BLOB_CHOICE_LIST * > 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 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 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 (tesseract::TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (tesseract::TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
int dim1 () const
 
int dim2 () const
 
virtual int num_elements () 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 GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >
bool SerializeSize (FILE *fp) const
 
bool SerializeSize (tesseract::TFile *fp) const
 
bool DeSerializeSize (bool swap, FILE *fp)
 
bool DeSerializeSize (tesseract::TFile *fp)
 
- Protected Attributes inherited from 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 574 of file matrix.h.

Constructor & Destructor Documentation

◆ MATRIX()

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

Definition at line 576 of file matrix.h.

576  :
577  MATRIX(int dimension, int bandwidth)

◆ ~MATRIX()

MATRIX::~MATRIX ( )
overridedefault

Member Function Documentation

◆ Classified()

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

Definition at line 34 of file matrix.cpp.

35  {
36  if (get(col, row) == NOT_CLASSIFIED) return false;
37  BLOB_CHOICE_IT b_it(get(col, row));
38  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
39  BLOB_CHOICE* choice = b_it.data();
40  if (choice->IsClassified())
41  return true;
42  }
43  return false;

◆ ConsumeAndMakeBigger()

MATRIX * MATRIX::ConsumeAndMakeBigger ( int  ind)

Definition at line 56 of file matrix.cpp.

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

◆ DeepCopy()

MATRIX * MATRIX::DeepCopy ( ) const

Definition at line 92 of file matrix.cpp.

93  {
94  int dim = dimension();
95  int band_width = bandwidth();
96  auto* result = new MATRIX(dim, band_width);
97  for (int col = 0; col < dim; ++col) {
98  for (int row = col; row < dim && row < col + band_width; ++row) {
99  BLOB_CHOICE_LIST* choices = get(col, row);
100  if (choices != nullptr) {
101  auto* copy_choices = new BLOB_CHOICE_LIST;
102  copy_choices->deep_copy(choices, &BLOB_CHOICE::deep_copy);
103  result->put(col, row, copy_choices);
104  }
105  }
106  }
107  return result;

◆ IncreaseBandSize()

void MATRIX::IncreaseBandSize ( int  bandwidth)

Definition at line 47 of file matrix.cpp.

◆ print()

void MATRIX::print ( const UNICHARSET unicharset) const

Definition at line 110 of file matrix.cpp.

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

The documentation for this class was generated from the following files:
MATRIX::MATRIX
MATRIX(int dimension, int bandwidth)
Definition: matrix.h:576
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >::array_
BLOB_CHOICE_LIST * * array_
Definition: matrix.h:504
BLOB_CHOICE::set_matrix_cell
void set_matrix_cell(int col, int row)
Definition: ratngs.h:151
GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >::ResizeWithCopy
void ResizeWithCopy(int size1, int size2)
Definition: matrix.h:111
NOT_CLASSIFIED
#define NOT_CLASSIFIED
Definition: matrix.h:40
GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >::get
BLOB_CHOICE_LIST * get(ICOORD pos) const
Definition: matrix.h:227
BLOB_CHOICE::deep_copy
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:158
BandTriMatrix< BLOB_CHOICE_LIST * >::bandwidth
int bandwidth() const
Definition: matrix.h:534
BLOB_CHOICE
Definition: ratngs.h:49
MATRIX_COORD
Definition: matrix.h:604
GENERIC_2D_ARRAY< BLOB_CHOICE_LIST * >::empty_
BLOB_CHOICE_LIST * empty_
Definition: matrix.h:505
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
UNICHARSET::id_to_unichar
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:290
BLOB_CHOICE::IsClassified
bool IsClassified() const
Definition: ratngs.h:133
BandTriMatrix< BLOB_CHOICE_LIST * >::dimension
int dimension() const
Definition: matrix.h:532