tesseract v5.3.3.20231005
tesseract::GENERIC_2D_ARRAY< T > Class Template Reference

#include <matrix.h>

Inheritance diagram for tesseract::GENERIC_2D_ARRAY< T >:
tesseract::BandTriMatrix< T >

Public Member Functions

 GENERIC_2D_ARRAY (int dim1, int dim2, const T &empty, T *array)
 
 GENERIC_2D_ARRAY (int dim1, int dim2, const T &empty)
 
 GENERIC_2D_ARRAY ()
 
 GENERIC_2D_ARRAY (const GENERIC_2D_ARRAY< T > &src)
 
virtual ~GENERIC_2D_ARRAY ()
 
void operator= (const GENERIC_2D_ARRAY< T > &src)
 
void ResizeNoInit (int size1, int size2, int pad=0)
 
void Resize (int size1, int size2, const T &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 T &thing)
 
void put (int column, int row, const T &thing)
 
get (ICOORD pos) const
 
get (int column, int row) const
 
const T & operator() (int column, int row) const
 
T & operator() (int column, int row)
 
T * operator[] (int column)
 
const T * operator[] (int column) const
 
void operator+= (const GENERIC_2D_ARRAY< T > &addend)
 
void operator-= (const GENERIC_2D_ARRAY< T > &minuend)
 
void operator+= (const T &addend)
 
void operator*= (const T &factor)
 
void Clip (const T &rangemin, const T &rangemax)
 
bool WithinBounds (const T &rangemin, const T &rangemax) const
 
double Normalize ()
 
Max () const
 
MaxAbs () const
 
void SumSquares (const GENERIC_2D_ARRAY< T > &src, const T &decay_factor)
 
void AdamUpdate (const GENERIC_2D_ARRAY< T > &sum, const GENERIC_2D_ARRAY< T > &sqsum, const T &epsilon)
 
void AssertFinite () const
 
void RotatingTranspose (const int *dims, int num_dims, int src_dim, int dest_dim, GENERIC_2D_ARRAY< T > *result) const
 
void delete_matrix_pointers ()
 

Protected Member Functions

bool SerializeSize (FILE *fp) const
 
bool SerializeSize (TFile *fp) const
 
bool DeSerializeSize (bool swap, FILE *fp)
 
bool DeSerializeSize (TFile *fp)
 

Protected Attributes

T * array_
 
empty_
 
int dim1_
 
int dim2_
 
int size_allocated_
 

Detailed Description

template<class T>
class tesseract::GENERIC_2D_ARRAY< T >

Definition at line 51 of file matrix.h.

Constructor & Destructor Documentation

◆ GENERIC_2D_ARRAY() [1/4]

template<class T >
tesseract::GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY ( int  dim1,
int  dim2,
const T &  empty,
T *  array 
)
inline

◆ GENERIC_2D_ARRAY() [2/4]

template<class T >
tesseract::GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY ( int  dim1,
int  dim2,
const T &  empty 
)
inline

Definition at line 63 of file matrix.h.

63 : empty_(empty), dim1_(dim1), dim2_(dim2) {
64 int new_size = dim1 * dim2;
65 array_ = new T[new_size];
66 size_allocated_ = new_size;
67 for (int i = 0; i < size_allocated_; ++i) {
68 array_[i] = empty_;
69 }
70 }

◆ GENERIC_2D_ARRAY() [3/4]

template<class T >
tesseract::GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY ( )
inline

Definition at line 72 of file matrix.h.

73 : array_(nullptr), empty_(static_cast<T>(0)), dim1_(0), dim2_(0), size_allocated_(0) {}

◆ GENERIC_2D_ARRAY() [4/4]

template<class T >
tesseract::GENERIC_2D_ARRAY< T >::GENERIC_2D_ARRAY ( const GENERIC_2D_ARRAY< T > &  src)
inline

Definition at line 74 of file matrix.h.

75 : array_(nullptr), empty_(static_cast<T>(0)), dim1_(0), dim2_(0), size_allocated_(0) {
76 *this = src;
77 }

◆ ~GENERIC_2D_ARRAY()

template<class T >
virtual tesseract::GENERIC_2D_ARRAY< T >::~GENERIC_2D_ARRAY ( )
inlinevirtual

Definition at line 78 of file matrix.h.

78 {
79 delete[] array_;
80 }

Member Function Documentation

◆ AdamUpdate()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::AdamUpdate ( const GENERIC_2D_ARRAY< T > &  sum,
const GENERIC_2D_ARRAY< T > &  sqsum,
const T &  epsilon 
)
inline

Definition at line 429 of file matrix.h.

430 {
431 int size = num_elements();
432 for (int i = 0; i < size; ++i) {
433 array_[i] += sum.array_[i] / (sqrt(sqsum.array_[i]) + epsilon);
434 }
435 }
virtual int num_elements() const
Definition: matrix.h:248

◆ AssertFinite()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::AssertFinite ( ) const
inline

Definition at line 437 of file matrix.h.

437 {
438 int size = num_elements();
439 for (int i = 0; i < size; ++i) {
440 ASSERT_HOST(isfinite(array_[i]));
441 }
442 }
#define ASSERT_HOST(x)
Definition: errcode.h:54

◆ Clear()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::Clear ( )
inline

Definition at line 141 of file matrix.h.

141 {
142 int total_size = num_elements();
143 for (int i = 0; i < total_size; ++i) {
144 array_[i] = empty_;
145 }
146 }

◆ Clip()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::Clip ( const T &  rangemin,
const T &  rangemax 
)
inline

Definition at line 337 of file matrix.h.

337 {
338 int size = num_elements();
339 for (int i = 0; i < size; ++i) {
340 array_[i] = ClipToRange(array_[i], rangemin, rangemax);
341 }
342 }
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:105

◆ delete_matrix_pointers()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::delete_matrix_pointers ( )
inline

Definition at line 515 of file matrix.h.

515 {
516 int size = num_elements();
517 for (int i = 0; i < size; ++i) {
518 T matrix_cell = array_[i];
519 if (matrix_cell != empty_) {
520 delete matrix_cell;
521 }
522 }
523 }

◆ DeSerialize() [1/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::DeSerialize ( bool  swap,
FILE *  fp 
)
inline

Definition at line 175 of file matrix.h.

175 {
176 if (!DeSerializeSize(swap, fp)) {
177 return false;
178 }
179 if (!tesseract::DeSerialize(fp, &empty_)) {
180 return false;
181 }
182 if (swap) {
183 ReverseN(&empty_, sizeof(empty_));
184 }
185 int size = num_elements();
186 if (!tesseract::DeSerialize(fp, &array_[0], size)) {
187 return false;
188 }
189 if (swap) {
190 for (int i = 0; i < size; ++i) {
191 ReverseN(&array_[i], sizeof(array_[i]));
192 }
193 }
194 return true;
195 }
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:184
bool DeSerialize(bool swap, FILE *fp, std::vector< T > &data)
Definition: helpers.h:205
bool DeSerializeSize(bool swap, FILE *fp)
Definition: matrix.h:545

◆ DeSerialize() [2/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::DeSerialize ( TFile fp)
inline

Definition at line 197 of file matrix.h.

197 {
198 return DeSerializeSize(fp) && fp->DeSerialize(&empty_) &&
199 fp->DeSerialize(&array_[0], num_elements());
200 }

◆ DeSerializeClasses()

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::DeSerializeClasses ( bool  swap,
FILE *  fp 
)
inline

Definition at line 223 of file matrix.h.

223 {
224 if (!DeSerializeSize(swap, fp)) {
225 return false;
226 }
227 if (!empty_.DeSerialize(swap, fp)) {
228 return false;
229 }
230 int size = num_elements();
231 for (int i = 0; i < size; ++i) {
232 if (!array_[i].DeSerialize(swap, fp)) {
233 return false;
234 }
235 }
236 return true;
237 }
bool DeSerialize(bool swap, FILE *fp)
Definition: matrix.h:175

◆ DeSerializeSize() [1/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::DeSerializeSize ( bool  swap,
FILE *  fp 
)
inlineprotected

Definition at line 545 of file matrix.h.

545 {
546 uint32_t size1, size2;
547 if (!tesseract::DeSerialize(fp, &size1)) {
548 return false;
549 }
550 if (!tesseract::DeSerialize(fp, &size2)) {
551 return false;
552 }
553 if (swap) {
554 ReverseN(&size1, sizeof(size1));
555 ReverseN(&size2, sizeof(size2));
556 }
557 // Arbitrarily limit the number of elements to protect against bad data.
558 if (size1 > UINT16_MAX) {
559 return false;
560 }
561 if (size2 > UINT16_MAX) {
562 return false;
563 }
564 Resize(size1, size2, empty_);
565 return true;
566 }
void Resize(int size1, int size2, const T &empty)
Definition: matrix.h:110

◆ DeSerializeSize() [2/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::DeSerializeSize ( TFile fp)
inlineprotected

Definition at line 567 of file matrix.h.

567 {
568 int32_t size1, size2;
569 if (!fp->DeSerialize(&size1)) {
570 return false;
571 }
572 if (!fp->DeSerialize(&size2)) {
573 return false;
574 }
575 // Arbitrarily limit the number of elements to protect against bad data.
576 if (size1 > UINT16_MAX) {
577 return false;
578 }
579 if (size2 > UINT16_MAX) {
580 return false;
581 }
582 Resize(size1, size2, empty_);
583 return true;
584 }

◆ dim1()

template<class T >
int tesseract::GENERIC_2D_ARRAY< T >::dim1 ( ) const
inline

Definition at line 240 of file matrix.h.

240 {
241 return dim1_;
242 }

◆ dim2()

template<class T >
int tesseract::GENERIC_2D_ARRAY< T >::dim2 ( ) const
inline

Definition at line 243 of file matrix.h.

243 {
244 return dim2_;
245 }

◆ get() [1/2]

template<class T >
T tesseract::GENERIC_2D_ARRAY< T >::get ( ICOORD  pos) const
inline

Definition at line 268 of file matrix.h.

268 {
269 return array_[this->index(pos.x(), pos.y())];
270 }
virtual int index(int column, int row) const
Definition: matrix.h:255

◆ get() [2/2]

template<class T >
T tesseract::GENERIC_2D_ARRAY< T >::get ( int  column,
int  row 
) const
inline

Definition at line 271 of file matrix.h.

271 {
272 return array_[this->index(column, row)];
273 }

◆ index()

template<class T >
virtual int tesseract::GENERIC_2D_ARRAY< T >::index ( int  column,
int  row 
) const
inlinevirtual

Reimplemented in tesseract::BandTriMatrix< T >, and tesseract::BandTriMatrix< BLOB_CHOICE_LIST * >.

Definition at line 255 of file matrix.h.

255 {
256 return (column * dim2_ + row);
257 }

◆ Max()

template<class T >
T tesseract::GENERIC_2D_ARRAY< T >::Max ( ) const
inline

Definition at line 385 of file matrix.h.

385 {
386 int size = num_elements();
387 if (size <= 0) {
388 return empty_;
389 }
390 // Compute the max.
391 T max_value = array_[0];
392 for (int i = 1; i < size; ++i) {
393 const T &value = array_[i];
394 if (value > max_value) {
395 max_value = value;
396 }
397 }
398 return max_value;
399 }
int value

◆ MaxAbs()

template<class T >
T tesseract::GENERIC_2D_ARRAY< T >::MaxAbs ( ) const
inline

Definition at line 402 of file matrix.h.

402 {
403 int size = num_elements();
404 if (size <= 0) {
405 return empty_;
406 }
407 // Compute the max.
408 T max_abs = static_cast<T>(0);
409 for (int i = 0; i < size; ++i) {
410 T value = static_cast<T>(fabs(array_[i]));
411 if (value > max_abs) {
412 max_abs = value;
413 }
414 }
415 return max_abs;
416 }

◆ Normalize()

template<class T >
double tesseract::GENERIC_2D_ARRAY< T >::Normalize ( )
inline

Definition at line 356 of file matrix.h.

356 {
357 int size = num_elements();
358 if (size <= 0) {
359 return 0.0;
360 }
361 // Compute the mean.
362 double mean = 0.0;
363 for (int i = 0; i < size; ++i) {
364 mean += array_[i];
365 }
366 mean /= size;
367 // Subtract the mean and compute the standard deviation.
368 double sd = 0.0;
369 for (int i = 0; i < size; ++i) {
370 double normed = array_[i] - mean;
371 array_[i] = normed;
372 sd += normed * normed;
373 }
374 sd = sqrt(sd / size);
375 if (sd > 0.0) {
376 // Divide by the sd.
377 for (int i = 0; i < size; ++i) {
378 array_[i] /= sd;
379 }
380 }
381 return sd;
382 }

◆ num_elements()

template<class T >
virtual int tesseract::GENERIC_2D_ARRAY< T >::num_elements ( ) const
inlinevirtual

Definition at line 248 of file matrix.h.

248 {
249 return dim1_ * dim2_;
250 }

◆ operator()() [1/2]

template<class T >
T & tesseract::GENERIC_2D_ARRAY< T >::operator() ( int  column,
int  row 
)
inline

Definition at line 278 of file matrix.h.

278 {
279 return array_[this->index(column, row)];
280 }

◆ operator()() [2/2]

template<class T >
const T & tesseract::GENERIC_2D_ARRAY< T >::operator() ( int  column,
int  row 
) const
inline

Definition at line 275 of file matrix.h.

275 {
276 return array_[this->index(column, row)];
277 }

◆ operator*=()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::operator*= ( const T &  factor)
inline

Definition at line 330 of file matrix.h.

330 {
331 int size = num_elements();
332 for (int i = 0; i < size; ++i) {
333 array_[i] *= factor;
334 }
335 }

◆ operator+=() [1/2]

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::operator+= ( const GENERIC_2D_ARRAY< T > &  addend)
inline

Definition at line 291 of file matrix.h.

291 {
292 if (dim2_ == addend.dim2_) {
293 // Faster if equal size in the major dimension.
294 int size = std::min(num_elements(), addend.num_elements());
295 for (int i = 0; i < size; ++i) {
296 array_[i] += addend.array_[i];
297 }
298 } else {
299 for (int x = 0; x < dim1_; x++) {
300 for (int y = 0; y < dim2_; y++) {
301 (*this)(x, y) += addend(x, y);
302 }
303 }
304 }
305 }
const double y

◆ operator+=() [2/2]

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::operator+= ( const T &  addend)
inline

Definition at line 323 of file matrix.h.

323 {
324 int size = num_elements();
325 for (int i = 0; i < size; ++i) {
326 array_[i] += addend;
327 }
328 }

◆ operator-=()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::operator-= ( const GENERIC_2D_ARRAY< T > &  minuend)
inline

Definition at line 307 of file matrix.h.

307 {
308 if (dim2_ == minuend.dim2_) {
309 // Faster if equal size in the major dimension.
310 int size = std::min(num_elements(), minuend.num_elements());
311 for (int i = 0; i < size; ++i) {
312 array_[i] -= minuend.array_[i];
313 }
314 } else {
315 for (int x = 0; x < dim1_; x++) {
316 for (int y = 0; y < dim2_; y++) {
317 (*this)(x, y) -= minuend(x, y);
318 }
319 }
320 }
321 }

◆ operator=()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::operator= ( const GENERIC_2D_ARRAY< T > &  src)
inline

Definition at line 82 of file matrix.h.

82 {
83 ResizeNoInit(src.dim1(), src.dim2());
84 int size = num_elements();
85 if (size > 0) {
86 memcpy(array_, src.array_, size * sizeof(array_[0]));
87 }
88 }
void ResizeNoInit(int size1, int size2, int pad=0)
Definition: matrix.h:94

◆ operator[]() [1/2]

template<class T >
T * tesseract::GENERIC_2D_ARRAY< T >::operator[] ( int  column)
inline

Definition at line 283 of file matrix.h.

283 {
284 return &array_[this->index(column, 0)];
285 }

◆ operator[]() [2/2]

template<class T >
const T * tesseract::GENERIC_2D_ARRAY< T >::operator[] ( int  column) const
inline

Definition at line 286 of file matrix.h.

286 {
287 return &array_[this->index(column, 0)];
288 }

◆ put() [1/2]

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::put ( ICOORD  pos,
const T &  thing 
)
inline

Definition at line 260 of file matrix.h.

260 {
261 array_[this->index(pos.x(), pos.y())] = thing;
262 }

◆ put() [2/2]

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::put ( int  column,
int  row,
const T &  thing 
)
inline

Definition at line 263 of file matrix.h.

263 {
264 array_[this->index(column, row)] = thing;
265 }

◆ Resize()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::Resize ( int  size1,
int  size2,
const T &  empty 
)
inline

Definition at line 110 of file matrix.h.

110 {
111 empty_ = empty;
112 ResizeNoInit(size1, size2);
113 Clear();
114 }

◆ ResizeNoInit()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::ResizeNoInit ( int  size1,
int  size2,
int  pad = 0 
)
inline

Definition at line 94 of file matrix.h.

94 {
95 int new_size = size1 * size2 + pad;
96 if (new_size > size_allocated_) {
97 delete[] array_;
98 array_ = new T[new_size];
99 size_allocated_ = new_size;
100 }
101 dim1_ = size1;
102 dim2_ = size2;
103 // Fill the padding data so it isn't uninitialized.
104 for (int i = size1 * size2; i < new_size; ++i) {
105 array_[i] = empty_;
106 }
107 }

◆ ResizeWithCopy()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::ResizeWithCopy ( int  size1,
int  size2 
)
inline

Definition at line 117 of file matrix.h.

117 {
118 if (size1 != dim1_ || size2 != dim2_) {
119 int new_size = size1 * size2;
120 T *new_array = new T[new_size];
121 for (int col = 0; col < size1; ++col) {
122 for (int row = 0; row < size2; ++row) {
123 int old_index = col * dim2() + row;
124 int new_index = col * size2 + row;
125 if (col < dim1_ && row < dim2_) {
126 new_array[new_index] = array_[old_index];
127 } else {
128 new_array[new_index] = empty_;
129 }
130 }
131 }
132 delete[] array_;
133 array_ = new_array;
134 dim1_ = size1;
135 dim2_ = size2;
136 size_allocated_ = new_size;
137 }
138 }

◆ RotatingTranspose()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::RotatingTranspose ( const int *  dims,
int  num_dims,
int  src_dim,
int  dest_dim,
GENERIC_2D_ARRAY< T > *  result 
) const
inline

Definition at line 468 of file matrix.h.

469 {
470 int max_d = std::max(src_dim, dest_dim);
471 int min_d = std::min(src_dim, dest_dim);
472 // In a tensor of shape [d0, d1... min_d, ... max_d, ... dn-2, dn-1], the
473 // ends outside of min_d and max_d are unaffected, with [max_d +1, dn-1]
474 // being contiguous blocks of data that will move together, and
475 // [d0, min_d -1] being replicas of the transpose operation.
476 // num_replicas represents the large dimensions unchanged by the operation.
477 // move_size represents the small dimensions unchanged by the operation.
478 // src_step represents the stride in the src between each adjacent group
479 // in the destination.
480 int num_replicas = 1, move_size = 1, src_step = 1;
481 for (int d = 0; d < min_d; ++d) {
482 num_replicas *= dims[d];
483 }
484 for (int d = max_d + 1; d < num_dims; ++d) {
485 move_size *= dims[d];
486 }
487 for (int d = src_dim + 1; d < num_dims; ++d) {
488 src_step *= dims[d];
489 }
490 if (src_dim > dest_dim) {
491 src_step *= dims[src_dim];
492 }
493 // wrap_size is the size of a single replica, being the amount that is
494 // handled num_replicas times.
495 int wrap_size = move_size;
496 for (int d = min_d; d <= max_d; ++d) {
497 wrap_size *= dims[d];
498 }
499 result->ResizeNoInit(dim1_, dim2_);
500 result->empty_ = empty_;
501 const T *src = array_;
502 T *dest = result->array_;
503 for (int replica = 0; replica < num_replicas; ++replica) {
504 for (int start = 0; start < src_step; start += move_size) {
505 for (int pos = start; pos < wrap_size; pos += src_step) {
506 memcpy(dest, src + pos, sizeof(*dest) * move_size);
507 dest += move_size;
508 }
509 }
510 src += wrap_size;
511 }
512 }
dest
Definition: upload.py:409

◆ Serialize() [1/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::Serialize ( FILE *  fp) const
inline

Definition at line 150 of file matrix.h.

150 {
151 if (!SerializeSize(fp)) {
152 return false;
153 }
154 if (!tesseract::Serialize(fp, &empty_)) {
155 return false;
156 }
157 int size = num_elements();
158 return tesseract::Serialize(fp, &array_[0], size);
159 }
bool Serialize(FILE *fp, const std::vector< T > &data)
Definition: helpers.h:236
bool SerializeSize(FILE *fp) const
Definition: matrix.h:527

◆ Serialize() [2/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::Serialize ( TFile fp) const
inline

Definition at line 161 of file matrix.h.

161 {
162 if (!SerializeSize(fp)) {
163 return false;
164 }
165 if (!fp->Serialize(&empty_)) {
166 return false;
167 }
168 int size = num_elements();
169 return fp->Serialize(&array_[0], size);
170 }

◆ SerializeClasses()

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::SerializeClasses ( FILE *  fp) const
inline

Definition at line 204 of file matrix.h.

204 {
205 if (!SerializeSize(fp)) {
206 return false;
207 }
208 if (!empty_.Serialize(fp)) {
209 return false;
210 }
211 int size = num_elements();
212 for (int i = 0; i < size; ++i) {
213 if (!array_[i].Serialize(fp)) {
214 return false;
215 }
216 }
217 return true;
218 }
bool Serialize(FILE *fp) const
Definition: matrix.h:150

◆ SerializeSize() [1/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::SerializeSize ( FILE *  fp) const
inlineprotected

Definition at line 527 of file matrix.h.

527 {
528 uint32_t size = dim1_;
529 if (!tesseract::Serialize(fp, &size)) {
530 return false;
531 }
532 size = dim2_;
533 return tesseract::Serialize(fp, &size);
534 }

◆ SerializeSize() [2/2]

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::SerializeSize ( TFile fp) const
inlineprotected

Definition at line 535 of file matrix.h.

535 {
536 uint32_t size = dim1_;
537 if (!fp->Serialize(&size)) {
538 return false;
539 }
540 size = dim2_;
541 return fp->Serialize(&size);
542 }

◆ SumSquares()

template<class T >
void tesseract::GENERIC_2D_ARRAY< T >::SumSquares ( const GENERIC_2D_ARRAY< T > &  src,
const T &  decay_factor 
)
inline

Definition at line 419 of file matrix.h.

419 {
420 T update_factor = 1 - decay_factor;
421 int size = num_elements();
422 for (int i = 0; i < size; ++i) {
423 array_[i] = array_[i] * decay_factor + update_factor * src.array_[i] * src.array_[i];
424 }
425 }

◆ WithinBounds()

template<class T >
bool tesseract::GENERIC_2D_ARRAY< T >::WithinBounds ( const T &  rangemin,
const T &  rangemax 
) const
inline

Definition at line 345 of file matrix.h.

345 {
346 int size = num_elements();
347 for (int i = 0; i < size; ++i) {
348 const T &value = array_[i];
349 if (value < rangemin || rangemax < value) {
350 return false;
351 }
352 }
353 return true;
354 }

Member Data Documentation

◆ array_

template<class T >
T* tesseract::GENERIC_2D_ARRAY< T >::array_
protected

Definition at line 586 of file matrix.h.

◆ dim1_

template<class T >
int tesseract::GENERIC_2D_ARRAY< T >::dim1_
protected

Definition at line 588 of file matrix.h.

◆ dim2_

template<class T >
int tesseract::GENERIC_2D_ARRAY< T >::dim2_
protected

Definition at line 589 of file matrix.h.

◆ empty_

template<class T >
T tesseract::GENERIC_2D_ARRAY< T >::empty_
protected

Definition at line 587 of file matrix.h.

◆ size_allocated_

template<class T >
int tesseract::GENERIC_2D_ARRAY< T >::size_allocated_
protected

Definition at line 593 of file matrix.h.


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