All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GeneralDescriptor Struct Reference

This class is only used when parsing Descriptors. More...

#include <nnet-descriptor.h>

Collaboration diagram for GeneralDescriptor:

Public Types

enum  DescriptorType {
  kAppend, kSum, kFailover, kIfDefined,
  kOffset, kSwitch, kRound, kReplaceIndex,
  kNodeName
}
 

Public Member Functions

 GeneralDescriptor (DescriptorType t, int32 value1=-1, int32 value2=-1)
 
 ~GeneralDescriptor ()
 
GeneralDescriptorGetNormalizedDescriptor () const
 
DescriptorConvertToDescriptor ()
 
void Print (const std::vector< std::string > &node_names, std::ostream &os)
 

Static Public Member Functions

static GeneralDescriptorParse (const std::vector< std::string > &node_names, const std::string **next_token)
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (GeneralDescriptor)
 
void ParseAppendOrSumOrSwitch (const std::vector< std::string > &node_names, const std::string **next_token)
 
void ParseIfDefined (const std::vector< std::string > &node_names, const std::string **next_token)
 
void ParseOffset (const std::vector< std::string > &node_names, const std::string **next_token)
 
void ParseSwitch (const std::vector< std::string > &node_names, const std::string **next_token)
 
void ParseFailover (const std::vector< std::string > &node_names, const std::string **next_token)
 
void ParseRound (const std::vector< std::string > &node_names, const std::string **next_token)
 
void ParseReplaceIndex (const std::vector< std::string > &node_names, const std::string **next_token)
 
int32 NumAppendTerms () const
 
GeneralDescriptorGetAppendTerm (int32 term) const
 
GeneralDescriptorNormalizeAppend () const
 
SumDescriptorConvertToSumDescriptor () const
 
ForwardingDescriptorConvertToForwardingDescriptor () const
 

Static Private Member Functions

static bool Normalize (GeneralDescriptor *ptr)
 

Private Attributes

DescriptorType descriptor_type_
 
int32 value1_
 
int32 value2_
 
std::vector< GeneralDescriptor * > descriptors_
 

Detailed Description

This class is only used when parsing Descriptors.

It is useful for normalizing descriptors that are structured in an invalid or redundant way, into a form that can be turned into a real Descriptor.

Definition at line 522 of file nnet-descriptor.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

~GeneralDescriptor ( )
inline

Definition at line 540 of file nnet-descriptor.h.

References kaldi::DeletePointers(), and GeneralDescriptor::descriptors_.

std::vector< GeneralDescriptor * > descriptors_
void DeletePointers(std::vector< A * > *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
Definition: stl-utils.h:186

Member Function Documentation

Descriptor * ConvertToDescriptor ( )

Definition at line 825 of file nnet-descriptor.cc.

References GeneralDescriptor::ConvertToSumDescriptor(), GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, GeneralDescriptor::GetNormalizedDescriptor(), rnnlm::i, and GeneralDescriptor::kAppend.

Referenced by kaldi::nnet3::NormalizeTextDescriptor(), Descriptor::Parse(), and kaldi::nnet3::UnitTestGeneralDescriptor().

825  {
827  std::vector<SumDescriptor*> sum_descriptors;
828  if (normalized->descriptor_type_ == kAppend) {
829  for (size_t i = 0; i < normalized->descriptors_.size(); i++)
830  sum_descriptors.push_back(
831  normalized->descriptors_[i]->ConvertToSumDescriptor());
832  } else {
833  sum_descriptors.push_back(normalized->ConvertToSumDescriptor());
834  }
835  Descriptor *ans = new Descriptor(sum_descriptors);
836  delete normalized;
837  return ans;
838 }
GeneralDescriptor(DescriptorType t, int32 value1=-1, int32 value2=-1)
GeneralDescriptor * GetNormalizedDescriptor() const
ForwardingDescriptor * ConvertToForwardingDescriptor ( ) const
private

Definition at line 866 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, rnnlm::i, KALDI_ASSERT, KALDI_ERR, GeneralDescriptor::kNodeName, GeneralDescriptor::kOffset, GeneralDescriptor::kReplaceIndex, GeneralDescriptor::kRound, GeneralDescriptor::kSwitch, ReplaceIndexForwardingDescriptor::kT, ReplaceIndexForwardingDescriptor::kX, GeneralDescriptor::value1_, and GeneralDescriptor::value2_.

Referenced by GeneralDescriptor::ConvertToSumDescriptor().

866  {
867  switch (this->descriptor_type_) {
868  case kNodeName: return new SimpleForwardingDescriptor(value1_);
869  case kOffset: {
870  KALDI_ASSERT(descriptors_.size() == 1 && "bad descriptor");
871  return new OffsetForwardingDescriptor(
873  Index(0, value1_, value2_));
874  }
875  case kSwitch: {
876  std::vector<ForwardingDescriptor*> descriptors;
877  for (size_t i = 0; i < descriptors_.size(); i++)
878  descriptors.push_back(descriptors_[i]->ConvertToForwardingDescriptor());
879  return new SwitchingForwardingDescriptor(descriptors);
880  }
881  case kRound: {
882  KALDI_ASSERT(descriptors_.size() == 1 && "bad descriptor");
883  return new RoundingForwardingDescriptor(
885  value1_);
886  }
887  case kReplaceIndex: {
888  KALDI_ASSERT(descriptors_.size() == 1 && "bad descriptor");
891  return new ReplaceIndexForwardingDescriptor(
896  value2_);
897  }
898  default:
899  KALDI_ERR << "Invalid descriptor type (failure in normalization?)";
900  return NULL;
901  }
902 }
std::vector< GeneralDescriptor * > descriptors_
#define KALDI_ERR
Definition: kaldi-error.h:127
ForwardingDescriptor * ConvertToForwardingDescriptor() const
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
SumDescriptor * ConvertToSumDescriptor ( ) const
private

Definition at line 840 of file nnet-descriptor.cc.

References GeneralDescriptor::ConvertToForwardingDescriptor(), GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, KALDI_ASSERT, KALDI_ERR, GeneralDescriptor::kAppend, BinarySumDescriptor::kFailover, GeneralDescriptor::kFailover, GeneralDescriptor::kIfDefined, BinarySumDescriptor::kSum, and GeneralDescriptor::kSum.

Referenced by GeneralDescriptor::ConvertToDescriptor().

840  {
842  "Badly normalized descriptor");
843  switch (descriptor_type_) {
844  case kAppend:
845  KALDI_ERR << "Badly normalized descriptor";
846  case kSum: case kFailover: {
847  KALDI_ASSERT(descriptors_.size() == 2 && "Bad descriptor");
848  return new BinarySumDescriptor(
853  }
854  case kIfDefined: {
855  KALDI_ASSERT(descriptors_.size() == 1 && "Bad descriptor");
856  return new OptionalSumDescriptor(
858  }
859  default: {
860  return new SimpleSumDescriptor(this->ConvertToForwardingDescriptor());
861  }
862  }
863 }
SumDescriptor * ConvertToSumDescriptor() const
std::vector< GeneralDescriptor * > descriptors_
#define KALDI_ERR
Definition: kaldi-error.h:127
ForwardingDescriptor * ConvertToForwardingDescriptor() const
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
GeneralDescriptor * GetAppendTerm ( int32  term) const
private

Definition at line 624 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, GeneralDescriptor::GeneralDescriptor(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, GeneralDescriptor::kAppend, GeneralDescriptor::kNodeName, GeneralDescriptor::value1_, and GeneralDescriptor::value2_.

Referenced by GeneralDescriptor::NormalizeAppend().

624  {
625  switch (descriptor_type_) {
626  case kNodeName:
627  KALDI_ASSERT(term == 0);
628  return new GeneralDescriptor(kNodeName, value1_);
629  case kAppend: {
630  int32 cur_term = term;
631  for (size_t i = 0; i < descriptors_.size(); i++) {
632  int32 this_num_terms = descriptors_[i]->NumAppendTerms();
633  if (cur_term < this_num_terms)
634  return descriptors_[i]->GetAppendTerm(cur_term);
635  else
636  cur_term -= this_num_terms;
637  }
638  KALDI_ERR << "Code error, getting append term.";
639  return NULL; // avoid compiler warning
640  }
641  default: {
643  value1_, value2_);
644  ans->descriptors_.resize(descriptors_.size());
645  for (size_t i = 0; i < descriptors_.size(); i++)
646  ans->descriptors_[i] = descriptors_[i]->GetAppendTerm(term);
647  return ans;
648  }
649  }
650 }
std::vector< GeneralDescriptor * > descriptors_
GeneralDescriptor(DescriptorType t, int32 value1=-1, int32 value2=-1)
#define KALDI_ERR
Definition: kaldi-error.h:127
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
GeneralDescriptor * GetNormalizedDescriptor ( ) const

Definition at line 772 of file nnet-descriptor.cc.

References GeneralDescriptor::Normalize(), and GeneralDescriptor::NormalizeAppend().

Referenced by GeneralDescriptor::ConvertToDescriptor().

772  {
774  while (Normalize(ans)); // keep normalizing as long as it changes.
775  return ans;
776 }
static bool Normalize(GeneralDescriptor *ptr)
GeneralDescriptor(DescriptorType t, int32 value1=-1, int32 value2=-1)
GeneralDescriptor * NormalizeAppend() const
KALDI_DISALLOW_COPY_AND_ASSIGN ( GeneralDescriptor  )
private
bool Normalize ( GeneralDescriptor ptr)
staticprivate

Definition at line 671 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, GeneralDescriptor::GeneralDescriptor(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, GeneralDescriptor::kAppend, GeneralDescriptor::kFailover, GeneralDescriptor::kIfDefined, GeneralDescriptor::kOffset, GeneralDescriptor::kReplaceIndex, GeneralDescriptor::kRound, GeneralDescriptor::kSum, GeneralDescriptor::kSwitch, GeneralDescriptor::value1_, and GeneralDescriptor::value2_.

Referenced by GeneralDescriptor::GetNormalizedDescriptor().

671  {
672  bool changed = false;
673  switch (parent->descriptor_type_) {
674  case kOffset: { // this block combines Offset(Offset(x, ..), ..).
675  KALDI_ASSERT(parent->descriptors_.size() == 1);
676  GeneralDescriptor *child = parent->descriptors_[0];
677  if (child->descriptor_type_ == kOffset) {
678  KALDI_ASSERT(child->descriptors_.size() == 1);
679  GeneralDescriptor *grandchild = child->descriptors_[0];
680  parent->value1_ += child->value1_;
681  parent->value2_ += child->value2_;
682  child->descriptors_.clear(); // avoid delete in destructor.
683  delete child;
684  parent->descriptors_[0] = grandchild;
685  changed = true;
686  } else if (parent->value1_ == 0 && parent->value2_ == 0) {
687  // remove redundant Offset expression like Offset(x, 0).
688  parent->descriptors_.swap(child->descriptors_);
689  parent->descriptor_type_ = child->descriptor_type_;
690  parent->value1_ = child->value1_;
691  parent->value2_ = child->value2_;
692  child->descriptors_.clear(); // avoid delete in destructor.
693  delete child;
694  changed = true;
695  break; // break from the switch ('parent' is no longer of type
696  // kOffset)', so we don't want to carry through.
697  }
698  }
699  // ... and continue through to the next case statement.
700  case kSwitch: case kRound: case kReplaceIndex: { // ..and kOffset:
701  KALDI_ASSERT(parent->descriptors_.size() >= 1);
702  GeneralDescriptor *child = parent->descriptors_[0];
703  KALDI_ASSERT(child->descriptor_type_ != kAppend); // would be code error
704  // (already did
705  // NormalizeAppend()).
706  if (child->descriptor_type_ == kSum ||
707  child->descriptor_type_ == kFailover ||
708  child->descriptor_type_ == kIfDefined) {
709  if (parent->descriptors_.size() > 1) {
710  KALDI_ASSERT(parent->descriptor_type_ == kSwitch);
711  KALDI_ERR << "Sum(), Failover() or IfDefined() expression inside Switch(), "
712  << "we can't currently normalize this.";
713  }
714  // this is a forbidden case of a sum descriptor inside a forwarding
715  // descriptor. we need to rearrange. E.g. Offset(Sum(x, y), 1) becomes
716  // Sum(Offset(x, 1), Offset(y, 1)).
717  for (size_t i = 0; i < child->descriptors_.size(); i++) {
718  GeneralDescriptor *grandchild = child->descriptors_[i];
719  GeneralDescriptor *modified_grandchild =
720  new GeneralDescriptor(parent->descriptor_type_,
721  parent->value1_,
722  parent->value2_);
723  // modified_grandchild takes ownership of grandchild.
724  modified_grandchild->descriptors_.push_back(grandchild);
725  child->descriptors_[i] = modified_grandchild;
726  }
727  // copy all members from child to parent.
728  parent->descriptor_type_ = child->descriptor_type_;
729  parent->value1_ = child->value1_;
730  parent->value2_ = child->value2_;
731  parent->descriptors_.swap(child->descriptors_);
732  child->descriptors_.clear(); // avoid delete in destructor of 'child'
733  delete child;
734  changed = true;
735  }
736  break;
737  }
738  case kSum: {
739  KALDI_ASSERT(!parent->descriptors_.empty());
740  if (parent->descriptors_.size() == 1) {
741  // convert Sum(x) to just x.
742  GeneralDescriptor *child = parent->descriptors_[0];
743  parent->descriptor_type_ = child->descriptor_type_;
744  parent->descriptors_.swap(child->descriptors_);
745  parent->value1_ = child->value1_;
746  parent->value2_ = child->value2_;
747  child->descriptors_.clear(); // avoid delete in destructor.
748  delete child;
749  changed = true;
750  } else if (parent->descriptors_.size() > 2) {
751  // convert Sum(a, b, c, ...) to Sum(a, Sum(b, c, ...)).
752  GeneralDescriptor *new_child = new GeneralDescriptor(kSum);
753  // assign b, c, .. to the descriptors of new_child.
754  new_child->descriptors_.insert(new_child->descriptors_.begin(),
755  parent->descriptors_.begin() + 1,
756  parent->descriptors_.end());
757  parent->descriptors_.erase(parent->descriptors_.begin() + 1,
758  parent->descriptors_.end());
759  parent->descriptors_.push_back(new_child);
760  changed = true;
761  }
762  break;
763  }
764  default: { } // empty statement.
765  }
766  // ... and recurse.
767  for (size_t i = 0; i < parent->descriptors_.size(); i++)
768  changed = changed || Normalize(parent->descriptors_[i]);
769  return changed;
770 }
static bool Normalize(GeneralDescriptor *ptr)
GeneralDescriptor(DescriptorType t, int32 value1=-1, int32 value2=-1)
#define KALDI_ERR
Definition: kaldi-error.h:127
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
GeneralDescriptor * NormalizeAppend ( ) const
private

Definition at line 654 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, GeneralDescriptor::GeneralDescriptor(), GeneralDescriptor::GetAppendTerm(), rnnlm::i, KALDI_ASSERT, GeneralDescriptor::kAppend, and GeneralDescriptor::NumAppendTerms().

Referenced by GeneralDescriptor::GetNormalizedDescriptor().

654  {
655  int32 num_terms = NumAppendTerms();
656  KALDI_ASSERT(num_terms > 0);
657  if (num_terms == 1) {
658  return GetAppendTerm(0);
659  } else {
661  ans->descriptors_.resize(num_terms);
662  for (size_t i = 0; i < num_terms; i++) {
663  ans->descriptors_[i] = GetAppendTerm(i);
664  }
665  return ans;
666  }
667 }
GeneralDescriptor * GetAppendTerm(int32 term) const
GeneralDescriptor(DescriptorType t, int32 value1=-1, int32 value2=-1)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
int32 NumAppendTerms ( ) const
private

Definition at line 606 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, rnnlm::i, KALDI_ASSERT, GeneralDescriptor::kAppend, and GeneralDescriptor::kNodeName.

Referenced by GeneralDescriptor::NormalizeAppend().

606  {
607  int32 ans = 0;
608  switch (descriptor_type_) {
609  case kNodeName: ans = 1; break;
610  case kAppend: {
611  for (size_t i = 0; i < descriptors_.size(); i++)
612  ans += descriptors_[i]->NumAppendTerms();
613  break;
614  }
615  default:
616  KALDI_ASSERT(descriptors_.size() > 0);
617  ans = descriptors_[0]->NumAppendTerms();
618  for (size_t i = 1; i < descriptors_.size(); i++)
620  }
621  return ans;
622 }
std::vector< GeneralDescriptor * > descriptors_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
GeneralDescriptor * Parse ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
static

Definition at line 474 of file nnet-descriptor.cc.

References kaldi::nnet3::ExpectToken(), GeneralDescriptor::GeneralDescriptor(), rnnlm::i, KALDI_ERR, GeneralDescriptor::kAppend, GeneralDescriptor::kFailover, GeneralDescriptor::kIfDefined, GeneralDescriptor::kNodeName, GeneralDescriptor::kOffset, GeneralDescriptor::kReplaceIndex, GeneralDescriptor::kRound, GeneralDescriptor::kSum, GeneralDescriptor::kSwitch, GeneralDescriptor::ParseAppendOrSumOrSwitch(), GeneralDescriptor::ParseFailover(), GeneralDescriptor::ParseIfDefined(), GeneralDescriptor::ParseOffset(), GeneralDescriptor::ParseReplaceIndex(), and GeneralDescriptor::ParseRound().

Referenced by kaldi::nnet3::NormalizeTextDescriptor(), Descriptor::Parse(), GeneralDescriptor::ParseAppendOrSumOrSwitch(), GeneralDescriptor::ParseFailover(), GeneralDescriptor::ParseIfDefined(), GeneralDescriptor::ParseOffset(), GeneralDescriptor::ParseReplaceIndex(), GeneralDescriptor::ParseRound(), and kaldi::nnet3::UnitTestGeneralDescriptor().

476  {
477 
478  DescriptorType t;
479  if (**next_token == "Append") {
480  t = kAppend;
481  } else if (**next_token == "Sum") {
482  t = kSum;
483  } else if (**next_token == "Failover") {
484  t = kFailover;
485  } else if (**next_token == "IfDefined") {
486  t = kIfDefined;
487  } else if (**next_token == "Offset") {
488  t = kOffset;
489  } else if (**next_token == "Switch") {
490  t = kSwitch;
491  } else if (**next_token == "Round") {
492  t = kRound;
493  } else if (**next_token == "ReplaceIndex") {
494  t = kReplaceIndex;
495  } else {
496  // what we read wasn't a reserved name like Offset, etc.
497  // We expect a node name in that case.
498  for (size_t i = 0; i < node_names.size(); i++) {
499  if (**next_token == node_names[i]) {
501  (*next_token)++;
502  return ans;
503  }
504  }
505  KALDI_ERR << "Expected a Descriptor, got instead "
506  << **next_token;
507  t = kNodeName; // suppress compiler warning.
508  }
509  (*next_token)++;
510  ExpectToken("(", "Descriptor", next_token);
511  GeneralDescriptor *ans = new GeneralDescriptor(t);
512  switch (t) {
513  case kAppend: case kSum: case kSwitch:
514  ans->ParseAppendOrSumOrSwitch(node_names, next_token); break;
515  case kFailover: ans->ParseFailover(node_names, next_token); break;
516  case kIfDefined: ans->ParseIfDefined(node_names, next_token); break;
517  case kOffset: ans->ParseOffset(node_names, next_token); break;
518  case kRound: ans->ParseRound(node_names, next_token); break;
519  case kReplaceIndex: ans->ParseReplaceIndex(node_names, next_token); break;
520  default:
521  KALDI_ERR << "Code error";
522  }
523  return ans;
524 }
GeneralDescriptor(DescriptorType t, int32 value1=-1, int32 value2=-1)
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:127
void ParseAppendOrSumOrSwitch ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private

Definition at line 526 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, KALDI_ERR, and GeneralDescriptor::Parse().

Referenced by GeneralDescriptor::Parse().

528  {
529  descriptors_.push_back(Parse(node_names, next_token));
530  while (true) {
531  if (**next_token == ")") {
532  (*next_token)++;
533  return;
534  } else if (**next_token == ",") {
535  (*next_token)++;
536  descriptors_.push_back(Parse(node_names, next_token));
537  } else {
538  KALDI_ERR << "Expected ',' or ')', got "
539  << **next_token;
540  }
541  }
542 }
std::vector< GeneralDescriptor * > descriptors_
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:127
void ParseFailover ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private

Definition at line 551 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, kaldi::nnet3::ExpectToken(), and GeneralDescriptor::Parse().

Referenced by GeneralDescriptor::Parse().

553  {
554  descriptors_.push_back(Parse(node_names, next_token));
555  ExpectToken(",", "Failover", next_token);
556  descriptors_.push_back(Parse(node_names, next_token));
557  ExpectToken(")", "Failover", next_token);
558 }
std::vector< GeneralDescriptor * > descriptors_
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
void ParseIfDefined ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private

Definition at line 544 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, kaldi::nnet3::ExpectToken(), and GeneralDescriptor::Parse().

Referenced by GeneralDescriptor::Parse().

546  {
547  descriptors_.push_back(Parse(node_names, next_token));
548  ExpectToken(")", "IfDefined", next_token);
549 }
std::vector< GeneralDescriptor * > descriptors_
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
void ParseOffset ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private

Definition at line 560 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, kaldi::nnet3::ExpectToken(), GeneralDescriptor::Parse(), kaldi::nnet3::ReadIntegerToken(), GeneralDescriptor::value1_, and GeneralDescriptor::value2_.

Referenced by GeneralDescriptor::Parse().

562  {
563  descriptors_.push_back(Parse(node_names, next_token));
564  ExpectToken(",", "Offset", next_token);
565  value1_ = ReadIntegerToken("Offset", next_token);
566  if (**next_token == ",") {
567  (*next_token)++;
568  value2_ = ReadIntegerToken("Offset", next_token);
569  } else {
570  value2_ = 0;
571  }
572  ExpectToken(")", "Offset", next_token);
573 }
static int32 ReadIntegerToken(const std::string &what_we_are_parsing, const std::string **next_token)
std::vector< GeneralDescriptor * > descriptors_
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
void ParseReplaceIndex ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private

Definition at line 586 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, kaldi::nnet3::ExpectToken(), KALDI_ERR, ReplaceIndexForwardingDescriptor::kT, ReplaceIndexForwardingDescriptor::kX, GeneralDescriptor::Parse(), kaldi::nnet3::ReadIntegerToken(), GeneralDescriptor::value1_, and GeneralDescriptor::value2_.

Referenced by GeneralDescriptor::Parse().

588  {
589  descriptors_.push_back(Parse(node_names, next_token));
590  ExpectToken(",", "ReplaceIndex", next_token);
591  if (**next_token == "t") {
593  (*next_token)++;
594  } else if (**next_token == "x") {
596  (*next_token)++;
597  } else {
598  KALDI_ERR << "Expected 't' or 'x', got " << **next_token;
599  }
600  ExpectToken(",", "ReplaceIndex", next_token);
601  value2_ = ReadIntegerToken("Replace", next_token);
602  ExpectToken(")", "ReplaceIndex", next_token);
603 }
static int32 ReadIntegerToken(const std::string &what_we_are_parsing, const std::string **next_token)
std::vector< GeneralDescriptor * > descriptors_
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:127
void ParseRound ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private

Definition at line 576 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptors_, kaldi::nnet3::ExpectToken(), GeneralDescriptor::Parse(), kaldi::nnet3::ReadIntegerToken(), and GeneralDescriptor::value1_.

Referenced by GeneralDescriptor::Parse().

578  {
579  descriptors_.push_back(Parse(node_names, next_token));
580  ExpectToken(",", "Round", next_token);
581  value1_ = ReadIntegerToken("Round", next_token);
582  ExpectToken(")", "Round", next_token);
583 }
static int32 ReadIntegerToken(const std::string &what_we_are_parsing, const std::string **next_token)
std::vector< GeneralDescriptor * > descriptors_
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
void ParseSwitch ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)
private
void Print ( const std::vector< std::string > &  node_names,
std::ostream &  os 
)

Definition at line 778 of file nnet-descriptor.cc.

References GeneralDescriptor::descriptor_type_, GeneralDescriptor::descriptors_, rnnlm::i, KALDI_ASSERT, GeneralDescriptor::kAppend, GeneralDescriptor::kFailover, GeneralDescriptor::kIfDefined, GeneralDescriptor::kNodeName, GeneralDescriptor::kOffset, GeneralDescriptor::kReplaceIndex, GeneralDescriptor::kRound, GeneralDescriptor::kSum, GeneralDescriptor::kSwitch, ReplaceIndexForwardingDescriptor::kT, ReplaceIndexForwardingDescriptor::kX, GeneralDescriptor::value1_, and GeneralDescriptor::value2_.

779  {
780  switch (descriptor_type_) {
781  // first handle all the expressions of the form "Operator(<desc1>, ... <descN>)".
782  case kAppend: os << "Append("; break;
783  case kSum: os << "Sum("; break;
784  case kFailover: os << "Failover("; break;
785  case kIfDefined: os << "IfDefined("; break;
786  case kSwitch: os << "Switch("; break;
787  // now handle the exceptions.
788  case kOffset: case kRound: {
789  os << "Offset(";
790  KALDI_ASSERT(descriptors_.size() == 1);
791  descriptors_[0]->Print(node_names, os);
792  os << ", " << value1_;
793  if (descriptor_type_ == kOffset && value2_ != 0) os << ", " << value2_;
794  os << ")";
795  return;
796  }
797  case kReplaceIndex: {
798  os << "ReplaceIndex(";
799  KALDI_ASSERT(descriptors_.size() == 1);
800  descriptors_[0]->Print(node_names, os);
802  value1_ == int32(ReplaceIndexForwardingDescriptor::kX));
803  if (value1_ == int32(ReplaceIndexForwardingDescriptor::kT)) {
804  os << ", t, ";
805  } else {
806  os << ", x, ";
807  }
808  os << value2_ << ")";
809  return;
810  }
811  case kNodeName: {
812  KALDI_ASSERT(static_cast<size_t>(value1_) < node_names.size());
813  os << node_names[value1_];
814  return;
815  }
816  }
817  for (size_t i = 0; i < descriptors_.size(); i++) {
818  if (i > 0) os << ", ";
819  descriptors_[i]->Print(node_names, os);
820  }
821  os << ")";
822 }
std::vector< GeneralDescriptor * > descriptors_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

Member Data Documentation


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