RecyclingVector Class Reference

This class serves as a storage for feature vectors with an option to limit the memory usage by removing old elements. More...

#include <online-feature.h>

Collaboration diagram for RecyclingVector:

Public Member Functions

 RecyclingVector (int items_to_hold=-1)
 By default it does not remove any elements. More...
 
Vector< BaseFloat > * At (int index) const
 The ownership is being retained by this collection - do not delete the item. More...
 
void PushBack (Vector< BaseFloat > *item)
 The ownership of the item is passed to this collection - do not delete the item. More...
 
int Size () const
 This method returns the size as if no "recycling" had happened, i.e. More...
 
 ~RecyclingVector ()
 

Private Attributes

std::deque< Vector< BaseFloat > * > items_
 
int items_to_hold_
 
int first_available_index_
 

Detailed Description

This class serves as a storage for feature vectors with an option to limit the memory usage by removing old elements.

The deleted frames indices are "remembered" so that regardless of the MAX_ITEMS setting, the user always provides the indices as if no deletion was being performed. This is useful when processing very long recordings which would otherwise cause the memory to eventually blow up when the features are not being removed.

Definition at line 50 of file online-feature.h.

Constructor & Destructor Documentation

◆ RecyclingVector()

RecyclingVector ( int  items_to_hold = -1)

By default it does not remove any elements.

Definition at line 27 of file online-feature.cc.

27  :
28  items_to_hold_(items_to_hold == 0 ? -1 : items_to_hold),
30 }

◆ ~RecyclingVector()

Definition at line 32 of file online-feature.cc.

References RecyclingVector::items_.

32  {
33  for (auto *item : items_) {
34  delete item;
35  }
36 }
std::deque< Vector< BaseFloat > * > items_

Member Function Documentation

◆ At()

Vector< BaseFloat > * At ( int  index) const

The ownership is being retained by this collection - do not delete the item.

Definition at line 38 of file online-feature.cc.

References RecyclingVector::first_available_index_, RecyclingVector::items_, KALDI_ERR, and RecyclingVector::Size().

Referenced by kaldi::TestRecyclingVector().

38  {
39  if (index < first_available_index_) {
40  KALDI_ERR << "Attempted to retrieve feature vector that was "
41  "already removed by the RecyclingVector (index = "
42  << index << "; "
43  << "first_available_index = " << first_available_index_ << "; "
44  << "size = " << Size() << ")";
45  }
46  // 'at' does size checking.
47  return items_.at(index - first_available_index_);
48 }
int Size() const
This method returns the size as if no "recycling" had happened, i.e.
#define KALDI_ERR
Definition: kaldi-error.h:147
std::deque< Vector< BaseFloat > * > items_

◆ PushBack()

void PushBack ( Vector< BaseFloat > *  item)

The ownership of the item is passed to this collection - do not delete the item.

Definition at line 50 of file online-feature.cc.

References RecyclingVector::first_available_index_, RecyclingVector::items_, and RecyclingVector::items_to_hold_.

Referenced by OnlineGenericBaseFeature< C >::ComputeFeatures(), and kaldi::TestRecyclingVector().

50  {
51  if (items_.size() == items_to_hold_) {
52  delete items_.front();
53  items_.pop_front();
55  }
56  items_.push_back(item);
57 }
std::deque< Vector< BaseFloat > * > items_

◆ Size()

int Size ( ) const

This method returns the size as if no "recycling" had happened, i.e.

equivalent to the number of times the PushBack method has been called.

Definition at line 59 of file online-feature.cc.

References RecyclingVector::first_available_index_, and RecyclingVector::items_.

Referenced by RecyclingVector::At(), OnlineGenericBaseFeature< C >::ComputeFeatures(), and kaldi::TestRecyclingVector().

59  {
60  return first_available_index_ + items_.size();
61 }
std::deque< Vector< BaseFloat > * > items_

Member Data Documentation

◆ first_available_index_

int first_available_index_
private

◆ items_

◆ items_to_hold_

int items_to_hold_
private

Definition at line 69 of file online-feature.h.

Referenced by RecyclingVector::PushBack().


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