20 #ifndef TESSERACT_LSTM_NETWORKSCRATCH_H_ 21 #define TESSERACT_LSTM_NETWORKSCRATCH_H_ 57 : int_mode_(scratch->int_mode_ && src.int_mode()),
58 scratch_space_(scratch) {
59 network_io_ = int_mode_ ? scratch_space_->int_stack_.Borrow()
60 : scratch_space_->float_stack_.Borrow();
64 IO() : int_mode_(false), network_io_(nullptr), scratch_space_(nullptr) {}
67 if (scratch_space_ ==
nullptr) {
69 }
else if (int_mode_) {
70 scratch_space_->int_stack_.Return(network_io_);
72 scratch_space_->float_stack_.Return(network_io_);
80 if (scratch_space_ ==
nullptr) {
81 int_mode_ = scratch->int_mode_ && src.
int_mode();
82 scratch_space_ = scratch;
83 network_io_ = int_mode_ ? scratch_space_->int_stack_.Borrow()
84 : scratch_space_->float_stack_.Borrow();
86 network_io_->
Resize(src, num_features);
89 void Resize2d(
bool int_mode,
int width,
int num_features,
91 if (scratch_space_ ==
nullptr) {
92 int_mode_ = scratch->int_mode_ && int_mode;
93 scratch_space_ = scratch;
94 network_io_ = int_mode_ ? scratch_space_->int_stack_.Borrow()
95 : scratch_space_->float_stack_.Borrow();
97 network_io_->
Resize2d(int_mode, width, num_features);
103 if (scratch_space_ ==
nullptr) {
105 scratch_space_ = scratch;
106 network_io_ = scratch_space_->float_stack_.Borrow();
140 : vec_(nullptr), scratch_space_(scratch) {
144 FloatVec() : vec_(nullptr), data_(nullptr), scratch_space_(nullptr) {}
146 if (scratch_space_ !=
nullptr) scratch_space_->vec_stack_.
Return(vec_);
150 if (scratch_space_ !=
nullptr && vec_ !=
nullptr)
151 scratch_space_->vec_stack_.
Return(vec_);
152 scratch_space_ = scratch;
153 vec_ = scratch_space_->vec_stack_.
Borrow();
160 operator double*()
const {
return data_; }
161 double*
get() {
return data_; }
181 if (scratch_space_ !=
nullptr) scratch_space_->array_stack_.Return(array_);
185 if (scratch_space_ !=
nullptr && array_ !=
nullptr)
186 scratch_space_->array_stack_.Return(array_);
187 scratch_space_ = scratch;
188 array_ = scratch_space_->array_stack_.Borrow();
189 array_->
Resize(size1, size2, 0.0);
216 if (stack_top_ == stack_.size()) {
217 stack_.push_back(
new T);
220 flags_[stack_top_] =
true;
221 return stack_[stack_top_++];
231 int index = stack_top_ - 1;
232 while (index >= 0 && stack_[index] != item) --index;
233 if (index >= 0) flags_[index] =
false;
234 while (stack_top_ > 0 && !flags_[stack_top_ - 1]) --stack_top_;
249 Stack<NetworkIO> int_stack_;
250 Stack<NetworkIO> float_stack_;
251 Stack<GenericVector<double> > vec_stack_;
252 Stack<TransposedArray> array_stack_;
257 #endif // TESSERACT_LSTM_NETWORKSCRATCH_H_ void Init(int size, NetworkScratch *scratch)
void resize_no_init(int size)
FloatVec(int size, NetworkScratch *scratch)
void Init(int size1, int size2, NetworkScratch *scratch)
void Resize2d(bool int_mode, int width, int num_features, NetworkScratch *scratch)
void ResizeFloat(const NetworkIO &src, int num_features, NetworkScratch *scratch)
void Resize(const NetworkIO &src, int num_features)
void Resize(const NetworkIO &src, int num_features, NetworkScratch *scratch)
IO(const NetworkIO &src, NetworkScratch *scratch)
const TransposedArray & operator*() const
void Resize(int size1, int size2, const T &empty)
~NetworkScratch()=default
void set_int_mode(bool int_mode)
void Resize2d(bool int_mode, int width, int num_features)
void ResizeFloat(const NetworkIO &src, int num_features)