decodable-mapped.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // decoder/decodable-mapped.h
  2. // Copyright 2009-2011 Saarland University; Microsoft Corporation;
  3. // Lukas Burget
  4. // See ../../COPYING for clarification regarding multiple authors
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  14. // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  15. // MERCHANTABLITY OR NON-INFRINGEMENT.
  16. // See the Apache 2 License for the specific language governing permissions and
  17. // limitations under the License.
  18. #ifndef KALDI_DECODER_DECODABLE_MAPPED_H_
  19. #define KALDI_DECODER_DECODABLE_MAPPED_H_
  20. #include <vector>
  21. #include "base/kaldi-common.h"
  22. #include "itf/decodable-itf.h"
  23. namespace kaldi {
  24. // The DecodableMapped object is initialized by a normal decodable object,
  25. // and a vector that maps indices. The "pdf index" into this decodable object
  26. // is the index into the vector, and the value it finds there is used
  27. // to index into the base decodable object.
  28. class DecodableMapped: public DecodableInterface {
  29. public:
  30. DecodableMapped(const std::vector<int32> &index_map, DecodableInterface *d):
  31. index_map_(index_map), decodable_(d) { }
  32. // Note, frames are numbered from zero. But state_index is numbered
  33. // from one (this routine is called by FSTs).
  34. virtual BaseFloat LogLikelihood(int32 frame, int32 state_index) {
  35. KALDI_ASSERT(static_cast<size_t>(state_index) < index_map_.size());
  36. return decodable_->LogLikelihood(frame, index_map_[state_index]);
  37. }
  38. // note: indices are assumed to be numbered from one, so
  39. // NumIndices() will be the same as the largest index.
  40. virtual int32 NumIndices() const { return static_cast<int32>(index_map_.size()) - 1; }
  41. virtual bool IsLastFrame(int32 frame) const {
  42. // We require all the decodables have the same #frames. We don't check this though.
  43. return decodable_->IsLastFrame(frame);
  44. }
  45. private:
  46. std::vector<int32> index_map_;
  47. DecodableInterface *decodable_;
  48. KALDI_DISALLOW_COPY_AND_ASSIGN(DecodableMapped);
  49. };
  50. } // namespace kaldi
  51. #endif // KALDI_DECODER_DECODABLE_MAPPED_H_